Changes in the directory structure
[rice.git] / examples / simple3x / simple3x.c
blob87ac16003e0a9d8d9c001da6b8d6feb96b87aab5
1 /*
2 File: simple3x.c
3 Author: Rene' Jager
4 Update: December 11, 1992
5 Info: simple upgrade example RICE 3.x application, see file rice3x.doc
6 */
9 /* standard include files */
11 #include <conio.h>
12 #include <stdio.h>
13 #include <stdio.h>
14 #include <ctype.h>
17 /* include rice.c so it will always be compiled along with this file... */
19 #include <rice.c>
22 /* application specific user i/o functions */
24 void ask(char *fact, float *grade)
26 char c, ans[10];
27 printf("%s ? ", fact);
28 do {
29 scanf("%5s", ans);
30 if(sscanf(ans, "%g", grade) != 1)
32 sscanf(ans, "%c", &c);
33 if(c == 'Y' || c == 'y')
34 *grade = 1.0;
35 else
36 if(c == 'N' || c == 'n')
37 *grade = 0.0;
39 } while(*grade != -1.0 && (*grade < 0.0 || 1.0 < *grade));
42 void inform(char *fact, float *grade)
44 printf("%s ", fact);
45 if(*grade == 1.0)
46 printf("!\n");
47 else
48 printf("! %g\n", *grade);
51 void report(int type, char *msg, void *data)
53 switch(type)
55 case 1: printf("ERROR: "); break;
56 case 2: printf("WARNING: "); break;
57 case 3: printf("MESSAGE: "); break;
60 printf("%s", msg);
61 if(data) printf(" (%s)", (char *) data);
62 printf("\n");
66 /* get file name from user */
68 char *get_name(int command, char *filename)
70 switch(command)
72 case '1': printf("File to compile from: "); break;
73 case '2': printf("File to load from : "); break;
74 case '3': printf("File to save to : "); break;
75 case '4': printf("File to rebuild to : "); break;
78 scanf("%s", filename);
79 return filename;
83 /* in this example not really possible to have stack overflow... */
85 #ifdef __BORLANDC__
86 extern unsigned _stklen = 10000U;
87 #endif
90 /* main function */
92 int main(void)
94 int command;
95 char filename[13];
97 /* redirect i/o to user i/o functions (see above) */
99 RedirectAsk(ask);
100 RedirectInform(inform);
101 RedirectReport(report);
103 /* do loop while not exit command or error */
107 printf("\n1 : compile\n");
108 printf("2 : load\n");
109 printf("3 : save\n");
110 printf("4 : rebuild\n");
111 printf("5 : infer\n");
112 printf("6 : clear\n");
113 printf("7 : destroy\n\n");
114 printf("0 : exit\n");
116 command = getch();
118 switch(command)
120 case '1': CompileKB(get_name(command, filename)); break;
121 case '2': LoadKB(get_name(command, filename)); break;
122 case '3': SaveKB(get_name(command, filename)); break;
123 case '4': RebuildKB(get_name(command, filename)); break;
124 case '5': InferKB(); break;
125 case '6': ClearKB(); break;
126 case '7': DestroyKB(); break;
128 default:
129 command = 0;
132 while(command);
134 return 0;