2 #include <libchimara/glk.h>
4 static winid_t mainwin = NULL;
8 fprintf(stderr, "I'm the interrupt handler!\n");
13 /* Open the main window. */
14 mainwin = glk_window_open(0, 0, 0, wintype_TextBuffer, 1);
16 /* It's possible that the main window failed to open. There's
17 nothing we can do without it, so exit. */
23 for(i = 0; i < 512; i++) {
24 buffer[i * 2] = i + 33;
25 buffer[i * 2 + 1] = 32;
28 /* frefid_t f = glk_fileref_create_temp(fileusage_BinaryMode, 0);
31 strid_t s = glk_stream_open_file(f, filemode_ReadWrite, 0);*/
33 strid_t s = glk_stream_open_memory_uni(membuf, 512, filemode_ReadWrite, 0);
34 glk_stream_set_current(s);
36 glk_put_char_uni('X');
37 glk_put_string("Philip en Marijn zijn vet goed.\n");
38 glk_put_buffer_uni(buffer, 1024);
40 glk_stream_set_position(s, 0, seekmode_Start);
41 glk_set_window(mainwin);
42 glk_put_char_uni( glk_get_char_stream_uni(s) );
44 g_printerr( "Line read: %d\n", glk_get_line_stream_uni(s, buffer, 1024) );
45 g_printerr("string[5] = %X\n", buffer[5]);
46 glk_put_string_uni(buffer);
47 int count = glk_get_buffer_stream_uni(s, buffer, 1024);
48 g_printerr("Buffer read: %d\n", count);
49 glk_put_string("\n---SOME CHARACTERS---\n");
50 glk_put_buffer_uni(buffer, count);
51 glk_put_string("\n---THE SAME CHARACTERS IN UPPERCASE---\n");
52 int newcount = glk_buffer_to_upper_case_uni(buffer, 1024, 1024);
53 glk_put_buffer_uni(buffer, newcount);
55 stream_result_t result;
56 glk_stream_close(s, &result);
58 g_printerr("Read count: %d\nWrite count: %d\n", result.readcount, result.writecount);
59 /* glk_fileref_destroy(f);
62 glk_set_interrupt_handler(&sayit);
66 glk_put_string("\nprompt> ");
67 glk_request_line_event_uni(mainwin, buffer, 1024, 0);
71 printf("Received event:\n");
72 printf("Type: %d\n", ev.type);
73 printf("Win: %d\n", glk_window_get_rock(ev.win) );
74 printf("Var1: %d\n", ev.val1);
75 printf("Var2: %d\n", ev.val2);