3cfd15ea63051fa542a1142599149cc8f15b19f4
[rodin/chimara.git] / tests / styletest.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <assert.h>
5 #include <libchimara/glk.h>
6
7 void print_help();
8 void do_style_test();
9 void do_link_test();
10
11 winid_t mainwin;
12
13 void glk_main(void)
14 {
15     event_t ev;
16     mainwin = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
17     if(!mainwin)
18         return;
19     
20     glk_set_window(mainwin);
21     
22     char *buffer = calloc(256, sizeof(char));
23     assert(buffer);
24     
25     glk_put_string("Welcome to the style test\n");
26
27     glk_request_line_event(mainwin, buffer, 255, 0);
28     while(strncmp(buffer, "quit", 4)) 
29     {
30         glk_select(&ev);
31         if(ev.type == evtype_LineInput)
32         {
33                         if( !strncmp(buffer, "help", 4) ) {
34                                 print_help();
35                         }
36                         else if( !strncmp(buffer, "style", 4) ) {
37                                 do_style_test();
38                         }
39                         else if( !strncmp(buffer, "link", 4) ) {
40                                 do_link_test();
41                         }
42                         else {
43                                 glk_put_string("Huh?\n");
44                         }
45                 glk_request_line_event(mainwin, buffer, 255, 0);
46         }
47                 else if(ev.type == evtype_Hyperlink)
48                 {
49                         glk_cancel_line_event(mainwin, NULL);
50                         if(ev.val1 == 1)
51                                 glk_put_string("Link 1 was clicked\n");
52                         if(ev.val1 == 2)
53                                 glk_put_string("Link 2 was clicked\n");
54                 glk_request_line_event(mainwin, buffer, 255, 0);
55                 }
56     }
57
58     glk_cancel_line_event(mainwin, NULL);
59     glk_window_clear(mainwin);
60     free(buffer);
61 }
62
63 void
64 do_style_test() {
65         glk_set_style(style_Normal);
66         glk_put_string("Normal\n");
67
68         glk_set_style(style_Emphasized);
69         glk_put_string("Emphasized\n");
70
71         glk_set_style(style_Preformatted);
72         glk_put_string("Preformatted\n");
73
74         glk_set_style(style_Header);
75         glk_put_string("Header\n");
76
77         glk_set_style(style_Subheader);
78         glk_put_string("Subheader\n");
79
80         glk_set_style(style_Alert);
81         glk_put_string("Alert\n");
82
83         glk_set_style(style_Note);
84         glk_put_string("Note\n");
85
86         glk_set_style(style_BlockQuote);
87         glk_put_string("BlockQuote\n");
88
89         glk_set_style(style_Input);
90         glk_put_string("Input\n");
91
92         glk_set_style(style_User1);
93         glk_put_string("User1\n");
94
95         glk_set_style(style_User2);
96         glk_put_string("User2\n");
97
98         glk_set_style(style_Normal);
99 }
100
101 void
102 do_link_test() {
103         glk_set_hyperlink(1);
104         glk_put_string("This is link 1\n");
105         glk_set_hyperlink(2);
106         glk_put_string("This is link 2\n");
107         glk_set_hyperlink(0);
108         glk_request_hyperlink_event(mainwin);
109 }
110
111 void
112 print_help() {
113         glk_put_string("The following commands are supported:\n - help (this help text)\n - style (perform style test)\n - link (perform hyperlink test)\n - quit (quit the program)\n");
114 }