Changes in the directory structure
[rice.git] / examples / simpleec / simpleec.c
blob9c5d342fea2bc5973c1e809f9447411760e88558
1 /*
2 File: simpleec.c
3 Author: Rene' Jager
4 Update: December 11 1992
5 Info: simple example for RICE
6 */
9 /* standard include files */
11 #include <conio.h>
12 #include <stdio.h>
13 #include <ctype.h>
15 /* include riceeasy.h */
17 #include <riceeasy.h>
20 /* application specific user i/o functions */
22 void ask(int kb, int argc, char *argv[], float *grade)
24 char c, ans[10];
25 int i;
27 printf("%s ", argv[0]);
28 if(argc > 1) printf("(");
29 for(i = 1; i < argc - 1; i++) printf("%s, ", argv[i]);
30 if(argc > 1) printf("%s) ", argv[argc - 1]);
31 printf("? ");
33 do {
34 scanf("%5s", ans);
35 if(sscanf(ans, "%g", grade) != 1)
37 sscanf(ans, "%c", &c);
38 if(c == 'Y' || c == 'y')
39 *grade = RICE_TRUE;
40 else
41 if(c == 'N' || c == 'n')
42 *grade = RICE_FALSE;
44 } while(*grade != UNKNOWN && (*grade < FALSE || TRUE < *grade));
47 void inform(int kb, int argc, char *argv[], float *grade)
49 int i;
51 printf("%s ", argv[0]);
52 if(argc > 1) printf("(");
53 for(i = 1; i < argc - 1; i++) printf("%s, ", argv[i]);
54 if(argc > 1) printf("%s) ", argv[argc - 1]);
55 if(*grade == TRUE)
56 printf("!\n");
57 else
58 printf("! %g\n", *grade);
61 void report(int kb, int type, char *msg)
63 switch(type)
65 case ERROR: printf("ERROR: "); break;
66 case WARNING: printf("WARNING: "); break;
67 case MESSAGE: printf("MESSAGE: "); break;
70 printf("%s\n", msg);
74 /* get file name from user */
76 char *get_name(int command, char *filename)
78 switch(command)
80 case '1': printf("File to compile from: "); break;
81 case '2': printf("File to load from : "); break;
82 case '3': printf("File to save to : "); break;
83 case '4': printf("File to rebuild to : "); break;
86 scanf("%s", filename);
87 return filename;
91 /* to prevent possible stack overflow... */
93 #ifdef __BORLANDC__
94 extern unsigned _stklen = 10000U;
95 #endif
98 /* linking facts with C-code */
100 Linker(linker)
102 Link("beep", printf("\x7"));
105 LINKER linkerPointer[] = {linker};
108 /* main function */
110 int main(void)
112 int command, theES;
113 char filename[13];
115 /* create es */
116 theES = CreateES();
118 /* redirect i/o to user i/o functions (see above) */
119 RedirectAsk(theES, ask);
120 RedirectInform(theES, inform);
121 RedirectReport(theES, report);
123 /* link linker to es */
124 UseLinker(theES, 1, linkerPointer);
126 /* do loop while not exit command or error */
129 printf("\n1 : compile\n");
130 printf("2 : load\n");
131 printf("3 : save\n");
132 printf("4 : rebuild\n");
133 printf("5 : infer\n");
134 printf("6 : clear\n");
135 printf("7 : destroy\n\n");
136 printf("0 : exit\n");
138 command = getch();
140 switch(command)
142 case '1': CompileKB(theES, get_name(command, filename)); break;
143 case '2': LoadKB(theES, get_name(command, filename)); break;
144 case '3': SaveKB(theES, get_name(command, filename)); break;
145 case '4': RebuildKB(theES, get_name(command, filename)); break;
146 case '5': InferKB(theES); break;
147 case '6': ClearKB(theES); break;
148 case '7': DestroyKB(theES); break;
150 default:
151 command = 0;
154 while(command);
156 return 0;