1: /***************************************************************************
   2:  * This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne.  JOVE *
   3:  * is provided to you without charge, and with no warranty.  You may give  *
   4:  * away copies of JOVE, including sources, provided that this notice is    *
   5:  * included in all the files.                                              *
   6:  ***************************************************************************/
   7: 
   8: #define TXT_TO_C    1   /* must be a number for MAC compiler */
   9: 
  10: #include "funcdefs.c"
  11: 
  12: #ifdef MAC
  13: #include "vars.c"
  14: #endif
  15: 
  16: #undef putchar  /* From jove.h via funcdefs.c, conflicts with STDIO */
  17: #undef putc
  18: #undef getc
  19: #undef EOF
  20: #undef FILE
  21: #undef BUFSIZ
  22: #undef NULL
  23: #include <stdio.h>
  24: 
  25: matchcmd(choices, what)
  26: register struct cmd choices[];
  27: register char   *what;
  28: {
  29:     register int    len;
  30:     int i,
  31:         found = 0,
  32:         save,
  33:         exactmatch = -1;
  34: 
  35:     len = strlen(what);
  36:     for (i = 0; choices[i].Name != 0; i++) {
  37:         if (*what != *choices[i].Name)
  38:             continue;
  39: #ifdef MAC /* see "left-margin" and "left-margin-here" */
  40:         if (strcmp(what, choices[i].Name) == 0)
  41: #else
  42:         if (strncmp(what, choices[i].Name, len) == 0)
  43: #endif
  44:         return i;
  45:     }
  46:     return -1;
  47: }
  48: 
  49: #ifdef MAC
  50: matchvar(choices, what)
  51: register struct variable choices[];
  52: register char   *what;
  53: {
  54:     register int    len;
  55:     int i,
  56:         found = 0,
  57:         save,
  58:         exactmatch = -1;
  59: 
  60:     len = strlen(what);
  61:     for (i = 0; choices[i].Name != 0; i++) {
  62:         if (*what != *choices[i].Name)
  63:             continue;
  64:         if (strcmp(what, choices[i].Name) == 0)
  65:             return i;
  66:     }
  67:     return -1;
  68: }
  69: #endif
  70: 
  71: char *
  72: PPchar(c)
  73: int c;
  74: {
  75:     static char str[16];
  76:     char    *cp = str;
  77: 
  78:     if (c & 0200) {
  79:         c &= ~0200;
  80:         strcpy(cp, "M-");
  81:         cp += 2;
  82:     }
  83:     if (c == '\033')
  84:         strcpy(cp, "ESC");
  85: #ifdef IBMPC
  86:     else if (c == '\377')
  87:             strcpy(cp, "M");
  88: #endif /* IBMPC */
  89:     else if (c < ' ')
  90:         (void) sprintf(cp, "C-%c", c + '@');
  91:     else if (c == '\177')
  92:         strcpy(cp, "^?");
  93:     else
  94:         (void) sprintf(cp, "%c", c);
  95:     return str;
  96: }
  97: 
  98: void
  99: extract(into, from)
 100: char    *into,
 101:     *from;
 102: {
 103:     from += 2;  /* Past tab and first double quote. */
 104:     while ((*into = *from++) != '"')
 105:         into += 1;
 106:     *into = 0;
 107: }
 108: 
 109: 
 110: void
 111: 
 112: #ifdef MAC
 113: _main()     /* for Mac, so we can use redirection */
 114: #else
 115: main()
 116: #endif
 117: {
 118:     FILE    *ifile,
 119:         *of;
 120:     char    line[100],
 121: #ifdef MAC
 122:         *which,
 123: #endif
 124:         comname[70];
 125:     int comnum,
 126:         ch,
 127: #ifdef MAC
 128:         inmenu = 0,
 129: #endif
 130:         savech = -1,
 131:         errors = 0;
 132: 
 133:     ifile = stdin;
 134:     of = stdout;
 135:     if (ifile == NULL || of == NULL) {
 136:         printf("Cannot read input or write output.\n");
 137:         exit(1);
 138:     }
 139:     while (fgets(line, sizeof line, ifile) != NULL) {
 140:         if (strncmp(line, "#if", 3) == 0) {
 141:             savech = ch;
 142:             fprintf(of, line);
 143:             continue;
 144:         } else if (strncmp(line, "#else", 5) == 0) {
 145:             if (savech == -1)
 146:                 fprintf(stderr, "WARNING: ifdef/endif mismatch!\n");
 147:             else
 148:                 ch = savech;
 149:             fprintf(of, line);
 150:             continue;
 151:         } else if (strncmp(line, "#endif", 6) == 0) {
 152:             savech = -1;
 153:             fprintf(of, line);
 154:             continue;
 155: #ifdef MAC
 156:         } else if (strncmp(line, "#MENU", 5) == 0) {
 157:             inmenu = 1;
 158:             continue;
 159: #endif
 160:         } else if (strncmp(line, "\t\"", 2) != 0) {
 161:             fprintf(of, line);
 162:             ch = 0;
 163:             continue;
 164:         }
 165:         extract(comname, line);
 166:         if (strcmp(comname, "unbound") == 0)
 167:             comnum = 12345;
 168:         else {
 169: #ifdef MAC
 170:             which = "commands";
 171: #endif
 172:             comnum = matchcmd(commands, comname);
 173: #ifdef MAC
 174:             if (comnum < 0 && inmenu) {
 175:                 comnum = matchvar(variables, comname);
 176:                 which = "variables";
 177:             }
 178: #endif
 179:             if (comnum < 0) {
 180: #ifdef MAC
 181:                 fprintf(stderr, "Warning: cannot find item \"%s\".\n", comname);
 182: #else
 183:                 fprintf(stderr, "Warning: cannot find command \"%s\".\n", comname);
 184: #endif
 185:                 errors += 1;
 186:                 comnum = 12345;
 187:             }
 188:         }
 189: #ifdef MAC
 190:         if(inmenu) {
 191:             if (comnum == 12345)
 192:                 fprintf(of, "	(data_obj *) 0,\n");
 193:             else
 194:                 fprintf(of, "	(data_obj *) &%s[%d],\n",which, comnum);
 195:         }
 196:         else {
 197: #endif
 198:         if (comnum == 12345)
 199:             fprintf(of, "	(data_obj *) 0,                 /* %s */\n", PPchar(ch++));
 200:         else
 201:             fprintf(of, "	(data_obj *) &commands[%d],	/* %s */\n", comnum, PPchar(ch++));
 202:     }
 203: #ifdef MAC
 204:     }
 205: #endif
 206:     fclose(of);
 207:     fclose(ifile);
 208:     exit(errors);
 209: }

Defined functions

PPchar defined in line 71; used 2 times
_main defined in line 110; never used
extract defined in line 98; used 1 times
main defined in line 110; used 2 times
matchcmd defined in line 25; used 1 times
matchvar defined in line 50; used 1 times

Defined macros

TXT_TO_C defined in line 8; never used
Last modified: 1988-03-15
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2455
Valid CSS Valid XHTML 1.0 Strict