1 /*
2 Compile using
3
4 gcc demo.c ../out/library.a \
5 ../../string/out/library.a \
6 ../../new/out/library.a \
7 ../../message/out/library.a \
8 ../../root/out/library.a
9 */
10
11 #include <stdio.h>
12 #include <string.h>
13 #include <stdlib.h>
14
15 #include "../../root/root.h"
16 #include "../../message/message.h"
17 #include "../subst.h"
18
19 char buffer[80];
20
main(int argc,char ** argv)21 int main(int argc, char **argv)
22 {
23 Subst subst;
24
25 message_setseverity(MSG_NOTICE | MSG_ERR);
26
27 subst_construct(&subst); /* construct the Subst object */
28
29 subst_insert(&subst, "DEMO", "one", "ONE SUBST");
30 subst_insert(&subst, "DEMO", "one", "TWO SUBST");
31 subst_insert(&subst, "DEMO", "\\'e", "é");
32
33 while (true)
34 {
35 char *cp;
36 puts("Enter text: ");
37 if (!fgets(buffer, 80, stdin) || buffer[0] == '\n')
38 break;
39
40 for (cp = buffer; *cp && *cp != '\n'; cp++)
41 {
42 printf("Inspecting char `%c': ", *cp);
43 if (subst_find(&subst, *cp))
44 printf("found. Swallowed by subst\n");
45 else
46 {
47 char *txt = new_str(subst_text(&subst));
48 printf("Not found. Next returned: `%c(`%s')\n",
49 subst_get(&subst), txt ? txt : "");
50 free(txt);
51 }
52 }
53 }
54 }
55