Changed build system to Automake. Split Glk code off into a GTK widget.
[projects/chimara/chimara.git] / src / model.c
1 #include "glk.h"
2
3 static winid_t mainwin = NULL;
4
5 void sayit(void)
6 {
7         fprintf(stderr, "I'm the interrupt handler!\n");
8 }
9
10 void glk_main(void)
11 {
12     /* Open the main window. */
13     mainwin = glk_window_open(0, 0, 0, wintype_TextBuffer, 1);
14     if (!mainwin) {
15         /* It's possible that the main window failed to open. There's
16             nothing we can do without it, so exit. */
17         return; 
18     }
19     
20         
21 /*    char buffer[256];
22     int i;
23     for(i = 0; i < 256; i++)
24         buffer[i] = (char)glk_char_to_upper(i);
25     
26     frefid_t f = glk_fileref_create_temp(fileusage_BinaryMode, 0);
27     if(f) 
28     {
29     
30         strid_t s = glk_stream_open_file(f, 
31                 filemode_ReadWrite, 0);
32         glk_stream_set_current(s);
33         
34         glk_put_char('X');
35         glk_put_string("Philip en Marijn zijn vet goed.\n");
36         glk_put_buffer(buffer, 256);
37
38         glk_stream_set_position(s, 0, seekmode_Start);
39         glk_set_window(mainwin);
40         glk_put_char( glk_get_char_stream(s) );
41         glk_put_char('\n');
42         g_printerr("Line read: %d\n", glk_get_line_stream(s, buffer, 256));
43         glk_put_string(buffer);
44         int count = glk_get_buffer_stream(s, buffer, 256);
45         g_printerr("Buffer read: %d\n", count);
46         glk_put_buffer(buffer, count);          
47         
48         stream_result_t result;
49         glk_stream_close(s, &result);
50         
51         g_printerr("Read count: %d\nWrite count: %d\n", result.readcount,
52                 result.writecount);
53                 glk_fileref_destroy(f);
54         }
55         */
56
57         glk_set_window(mainwin);
58
59         glk_set_interrupt_handler(&sayit);
60
61         gchar buffer[256];
62         event_t ev;
63         while(1) {
64                 glk_put_string("prompt> ");
65                 glk_request_line_event(mainwin, buffer, 256, 0);
66                 glk_select(&ev);
67                 switch(ev.type) {
68                         default:
69                                 printf("Received event:\n");
70                                 printf("Type: %d\n", ev.type);
71                                 printf("Win: %d\n", glk_window_get_rock(ev.win));
72                                 printf("Var1: %d\n", ev.val1);
73                                 printf("Var2: %d\n", ev.val2);
74                 }
75         }
76         
77         /* Bye bye */
78         glk_exit();
79 }