Verbeterd interrupt mechanisme en afbreken van het Glk programma
[rodin/chimara.git] / src / model.c
index d3edd5ca38f223217865c5a547a0bfe8d203091c..b89dbc958bcf8f40f93da00bdf26712f64d6e76e 100644 (file)
@@ -1,38 +1,12 @@
 #include "glk.h"
 
-/* model.c: Model program for Glk API, version 0.5.
-    Designed by Andrew Plotkin <erkyrath@eblong.com>
-    http://www.eblong.com/zarf/glk/index.html
-    This program is in the public domain.
-*/
-
-/* This is a simple model of a text adventure which uses the Glk API.
-    It shows how to input a line of text, display results, maintain a
-    status window, write to a transcript file, and so on. */
-
-/* This is the cleanest possible form of a Glk program. It includes only
-    "glk.h", and doesn't call any functions outside Glk at all. We even
-    define our own str_eq() and str_len(), rather than relying on the
-    standard libraries. */
-
-/* We also define our own TRUE and FALSE and NULL. */
-#ifndef TRUE
-#define TRUE 1
-#endif
-#ifndef FALSE
-#define FALSE 0
-#endif
-#ifndef NULL
-#define NULL 0
-#endif
-
 static winid_t mainwin = NULL;
 
-/* Forward declarations */
-void glk_main(void);
+void sayit(void)
+{
+       g_printerr("I'm the interrupt handler!\n");
+}
 
-/* The glk_main() function is called by the Glk system; it's the main entry
-    point for your program. */
 void glk_main(void)
 {
     /* Open the main window. */
@@ -43,11 +17,64 @@ void glk_main(void)
         return; 
     }
     
-    /* Set the current output stream to print to it. */
-    glk_set_window(mainwin);
+       /*
+    char buffer[256];
+    int i;
+    for(i = 0; i < 256; i++)
+       buffer[i] = (char)glk_char_to_upper(i);
+    
+       */
+       /*
+    frefid_t f = glk_fileref_create_by_prompt(fileusage_BinaryMode, filemode_ReadWrite, 0);
+    if(f) 
+    {
     
-    glk_put_string("Philip en Marijn zijn vet goed.\n");
+       strid_t s = glk_stream_open_file(f, 
+               filemode_ReadWrite, 0);
+       glk_stream_set_current(s);
+       glk_put_char('X');
+       glk_put_string("Philip en Marijn zijn vet goed.\n");
+       glk_put_buffer(buffer, 256);
+
+       glk_stream_set_position(s, 0, seekmode_Start);
+       glk_set_window(mainwin);
+       glk_put_char( glk_get_char_stream(s) );
+       glk_put_char('\n');
+       g_printerr("Line read: %d\n", glk_get_line_stream(s, buffer, 256));
+       glk_put_string(buffer);
+       int count = glk_get_buffer_stream(s, buffer, 256);
+       g_printerr("Buffer read: %d\n", count);
+       glk_put_buffer(buffer, count);          
+       
+       stream_result_t result;
+       glk_stream_close(s, &result);
+       
+       g_printerr("Read count: %d\nWrite count: %d\n", result.readcount,
+               result.writecount);
+               glk_fileref_destroy(f);
+       }
+       */
+
+       glk_set_window(mainwin);
+
+       glk_set_interrupt_handler(&sayit);
 
+       gchar buffer[256];
+       event_t ev;
+       while(1) {
+               glk_put_string("prompt> ");
+               glk_request_line_event(mainwin, buffer, 256, 0);
+               glk_select(&ev);
+               switch(ev.type) {
+                       default:
+                               printf("Received event:\n");
+                               printf("Type: %d\n", ev.type);
+                               printf("Win: %d\n", glk_window_get_rock(ev.win));
+                               printf("Var1: %d\n", ev.val1);
+                               printf("Var2: %d\n", ev.val2);
+               }
+       }
+       
        /* Bye bye */
        glk_exit();
 }