1 /* Input:
2 * 1. Everything up to the last tab on a line is skipped over.
3 * 2. The sequence \# indicates the rest of the line is numeric mode.
4 * 3. In text mode, all C escapes are accepted, and ^c
5 * stands for the code (c+1-'A').
6 * 4. In numeric mode, c/C/S/I/L/F/D is used to give sufficient
7 * type/size information to properly convert input.
8 */
9
10 #include <stdio.h>
11 #include <ctype.h>
12 #include "string.h"
13 #include "viz.h"
14 #include "version.h"
15 #include "translate.h"
16
17 char *prog;
18
19 void inviz_text();
20 void inviz_num();
21
main(argc,argv)22 main(argc, argv)
23 int argc;
24 char **argv;
25 {
26
27 int i=1;
28
29 prog = argv[0];
30
31 if (argc == 1) {
32 (void) inviz();
33 } else {
34 do {
35 if (freopen(argv[i], "r", stdin) == (FILE *) NULL) {
36 (void) fprintf(stderr, "%s: failed to open %s: ",prog, argv[i]);
37 perror("");
38 } else {
39 clearerr(stdin);
40 (void) inviz();
41 }
42
43 } while (++i < argc);
44 }
45
46 return 0;
47 }
inviz()48 inviz()
49 {
50 char *s;
51 char inbuf[BUFFERSIZE];
52 char outbuf[BUFFERSIZE];
53 int line, n;
54
55 for (line = 1; fgets(inbuf, BUFFERSIZE, stdin) != NULL; line++) {
56 n = strlen(inbuf);
57 /* Remove newline left on by fgets */
58 if (inbuf[n-1] == '\n')
59 inbuf[n-1] = '\0';
60
61 /* Discard everything up to the last tab */
62 s = strrchr(inbuf, '\t');
63 if (s)
64 s++;
65 else
66 s = inbuf;
67
68
69 /* Determine mode and call appropriate processing function */
70 if (strncmp(s, "\\#", 2) == 0)
71 inviz_num(s + 2, line);
72 else
73 inviz_text(s, 'a', outbuf);
74 }
75 }
76