|
|
1.1 ! root 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 <stdio.h> ! 11: ! 12: #include "funcdefs.c" ! 13: ! 14: #ifdef MAC ! 15: #include "vars.c" ! 16: #endif ! 17: ! 18: private int ! 19: matchcmd(choices, what) ! 20: register const struct cmd choices[]; ! 21: register char *what; ! 22: { ! 23: register int i; ! 24: #ifndef MAC ! 25: size_t len = strlen(what); ! 26: #endif ! 27: ! 28: for (i = 0; choices[i].Name != 0; i++) { ! 29: if (*what != *choices[i].Name) ! 30: continue; ! 31: #ifdef MAC /* see "left-margin" and "left-margin-here" */ ! 32: if (strcmp(what, choices[i].Name) == 0) ! 33: #else ! 34: if (strncmp(what, choices[i].Name, len) == 0) ! 35: #endif ! 36: return i; ! 37: } ! 38: return -1; ! 39: } ! 40: ! 41: #ifdef MAC ! 42: matchvar(choices, what) ! 43: register struct variable choices[]; ! 44: register char *what; ! 45: { ! 46: register int len; ! 47: int i; ! 48: ! 49: len = strlen(what); ! 50: for (i = 0; choices[i].Name != 0; i++) { ! 51: if (*what != *choices[i].Name) ! 52: continue; ! 53: if (strcmp(what, choices[i].Name) == 0) ! 54: return i; ! 55: } ! 56: return -1; ! 57: } ! 58: #endif ! 59: ! 60: private char * ! 61: PPchar(c) ! 62: int c; ! 63: { ! 64: static char str[16]; ! 65: char *cp = str; ! 66: ! 67: if (c & 0200) { ! 68: c &= ~0200; ! 69: strcpy(cp, "M-"); ! 70: cp += 2; ! 71: } ! 72: if (c == '\033') ! 73: strcpy(cp, "ESC"); ! 74: #ifdef IBMPC ! 75: else if (c == '\377') ! 76: strcpy(cp, "M"); ! 77: #endif /* IBMPC */ ! 78: else if (c < ' ') ! 79: (void) sprintf(cp, "C-%c", c + '@'); ! 80: else if (c == '\177') ! 81: strcpy(cp, "^?"); ! 82: else ! 83: (void) sprintf(cp, "%c", c); ! 84: return str; ! 85: } ! 86: ! 87: private void ! 88: extract(into, from) ! 89: char *into, ! 90: *from; ! 91: { ! 92: from += 2; /* Past tab and first double quote. */ ! 93: while ((*into = *from++) != '"') ! 94: into += 1; ! 95: *into = 0; ! 96: } ! 97: ! 98: ! 99: void ! 100: ! 101: #ifdef MAC ! 102: _main() /* for Mac, so we can use redirection */ ! 103: #else ! 104: main(argc, argv) ! 105: int argc; ! 106: char *argv[]; ! 107: #endif ! 108: { ! 109: FILE *ifile, ! 110: *of; ! 111: char line[100], ! 112: #ifdef MAC ! 113: *which, ! 114: #endif ! 115: comname[70]; ! 116: int comnum, ! 117: ch = 0, ! 118: #ifdef MAC ! 119: inmenu = 0, ! 120: #endif ! 121: savech = -1, ! 122: errors = 0; ! 123: ! 124: ifile = stdin; ! 125: of = stdout; ! 126: if (ifile == NULL || of == NULL) { ! 127: printf("Cannot read input or write output.\n"); ! 128: exit(1); ! 129: } ! 130: while (fgets(line, sizeof line, ifile) != NULL) { ! 131: if (strncmp(line, "#if", (size_t) 3) == 0) { ! 132: savech = ch; ! 133: fprintf(of, line); ! 134: continue; ! 135: } else if (strncmp(line, "#else", (size_t) 5) == 0) { ! 136: if (savech == -1) ! 137: fprintf(stderr, "WARNING: ifdef/endif mismatch!\n"); ! 138: else ! 139: ch = savech; ! 140: fprintf(of, line); ! 141: continue; ! 142: } else if (strncmp(line, "#endif", (size_t) 6) == 0) { ! 143: savech = -1; ! 144: fprintf(of, line); ! 145: continue; ! 146: #ifdef MAC ! 147: } else if (strncmp(line, "#MENU", (size_t) 5) == 0) { ! 148: inmenu = 1; ! 149: continue; ! 150: #endif ! 151: } else if (strncmp(line, "\t\"", (size_t) 2) != 0) { ! 152: fprintf(of, line); ! 153: ch = 0; ! 154: continue; ! 155: } ! 156: extract(comname, line); ! 157: if (strcmp(comname, "unbound") == 0) ! 158: comnum = 12345; ! 159: else { ! 160: #ifdef MAC ! 161: which = "commands"; ! 162: #endif ! 163: comnum = matchcmd(commands, comname); ! 164: #ifdef MAC ! 165: if (comnum < 0 && inmenu) { ! 166: comnum = matchvar(variables, comname); ! 167: which = "variables"; ! 168: } ! 169: #endif ! 170: if (comnum < 0) { ! 171: #ifdef MAC ! 172: fprintf(stderr, "Warning: cannot find item \"%s\".\n", comname); ! 173: #else ! 174: fprintf(stderr, "Warning: cannot find command \"%s\".\n", comname); ! 175: #endif ! 176: errors += 1; ! 177: comnum = 12345; ! 178: } ! 179: } ! 180: #ifdef MAC ! 181: if(inmenu) { ! 182: if (comnum == 12345) ! 183: fprintf(of, " (data_obj *) 0,\n"); ! 184: else ! 185: fprintf(of, " (data_obj *) &%s[%d],\n",which, comnum); ! 186: } ! 187: else { ! 188: #endif ! 189: if (comnum == 12345) ! 190: fprintf(of, " (data_obj *) 0, /* %s */\n", PPchar(ch++)); ! 191: else ! 192: fprintf(of, " (data_obj *) &commands[%d], /* %s */\n", comnum, PPchar(ch++)); ! 193: } ! 194: #ifdef MAC ! 195: } ! 196: #endif ! 197: fclose(of); ! 198: fclose(ifile); ! 199: exit(errors); ! 200: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.