2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
6 chtabgen - character table generator
8 Author: Erik Baalbergen (..tjalk!erikb)
9 Many mods by Ceriel Jacobs
15 static char *RcsId = "$Id: tabgen.c,v 1.7 1997/05/15 12:03:05 ceriel Exp $";
23 int InputForm = 'c'; /* default input format (and, currently, only one) */
24 char OutputForm[MAXBUF] = "%s,\n";
25 /* format for spitting out a string */
27 char *ProgCall; /* callname of this program */
28 int TabSize = 128; /* default size of generated table */
29 char *InitialValue; /* initial value of all table entries */
31 extern char *malloc(), *strcpy();
40 if (**argv == COMCOM) {
44 if (! process(*argv++, InputForm)) {
57 char *ns = malloc((unsigned)strlen(s) + 1);
63 fprintf(stderr, "%s: out of memory\n", ProgCall);
72 /* note that *str indicates the source of the option:
73 either COMCOM (from command line) or FILECOM (from a file).
77 case ' ': /* command */
81 case 'I': /* for future extension */
84 case 'f': /* input from file ... */
86 fprintf(stderr, "%s: -f: name expected\n", ProgCall);
91 case 'F': /* new output format string */
92 sprintf(OutputForm, "%s\n", ++str);
94 case 'T': /* insert text literally */
95 printf("%s\n", ++str);
97 case 'p': /* print table */
100 case 'C': /* clear table */
101 InitTable((char *)0);
103 case 'i': /* initialize table with given value */
104 if (*++str == '\0') {
105 InitTable((char *)0);
113 if (i <= 0 || i > MAXTAB) {
114 fprintf(stderr, "%s: size would exceed maximum\n",
123 fprintf(stderr, "%s: bad option -%s\n", ProgCall, str);
132 for (i = 0; i < TabSize; i++) {
137 InitialValue = Salloc(ival);
145 for (i = 0; i < TabSize; i++) {
147 printf(OutputForm, Table[i]);
149 else if (InitialValue) {
150 printf(OutputForm, InitialValue);
153 printf(OutputForm, "0");
163 char *Name = cstr; /* overwrite original string! */
165 /* strip of the entry name
167 while (*str && *str != ':') {
175 fprintf(stderr, "%s: bad specification: \"%s\", ignored\n",
185 return c_proc(str, Name);
187 fprintf(stderr, "%s: bad input format\n", ProgCall);
198 char *name = Salloc(Name);
208 if (*++str == '\\') {
212 if (ch2 = (*str++ & 0377));
216 fprintf(stderr, "%s: bad range\n", ProgCall);
220 if (! setval(ch, name)) return 0;
225 if (! setval(ch, name)) return 0;
235 char **p = &Table[ch];
237 if (ch < 0 || ch >= TabSize) {
238 fprintf(stderr, "Illegal index: %d\n", ch);
241 if (*(p = &Table[ch])) {
242 fprintf(stderr, "Warning: redefinition of index %d\n", ch);
256 if ((*++str >= '0') && (*str <= '9')) {
258 for (i = 0; i < 3; i++) {
259 ch = 8 * ch + (*str - '0');
260 if (*++str < '0' || *str > '9')
325 if ((fp = fopen(name, "r")) == NULL) {
326 fprintf(stderr, "%s: cannot read file %s\n", ProgCall, name);
329 while (_getline(text, BUFSIZE, fp) != NULL) {
330 if (text[0] == FILECOM) {
334 if (! process(text, InputForm)) {