~ubuntu-branches/ubuntu/precise/ghc/precise

« back to all changes in this revision

Viewing changes to libraries/haskeline/examples/export/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Joachim Breitner
  • Date: 2011-01-17 12:49:24 UTC
  • Revision ID: james.westby@ubuntu.com-20110117124924-do1pym1jlf5o636m
Tags: upstream-7.0.1
ImportĀ upstreamĀ versionĀ 7.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <signal.h>
 
4
#include "HsFFI.h"
 
5
 
 
6
#include "HaskelineExport_stub.h"
 
7
 
 
8
extern void __stginit_HaskelineExport();
 
9
 
 
10
void *hdata;
 
11
 
 
12
void catch_signal(int signo) {
 
13
    cancel_input(hdata);
 
14
    hs_exit();
 
15
    exit(0);
 
16
}
 
17
 
 
18
int main(int argc, char *argv[]) {
 
19
    hs_init(&argc, &argv);
 
20
    hs_add_root(__stginit_HaskelineExport);
 
21
 
 
22
    // TODO: block signals at certain points of this program 
 
23
    // in order to avoid race conditions.
 
24
    hdata = initialize_input();
 
25
 
 
26
    signal(SIGINT, catch_signal);
 
27
 
 
28
    char* str1 = get_input_line(hdata,"first:");
 
29
    char* str2 = get_input_line(hdata,"second:");
 
30
 
 
31
    if (str1!=NULL && str2 != NULL) {
 
32
        printf("The strings were:\n%s\n%s\n",str1,str2);
 
33
    }
 
34
 
 
35
    close_input(hdata);
 
36
 
 
37
    hs_exit();
 
38
    return 0;
 
39
}