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