|
|
1.1 ! root 1: /* "mkti4" produces a C file, ti4.c, which contains the */ ! 2: /* proper string definitions found in "caps", the source of */ ! 3: /* curses structure element definitions. */ ! 4: ! 5: #include <stdio.h> ! 6: ! 7: /* @(#) mkti4.c: 1.1 10/15/83 (1.3 12/16/83) */ ! 8: ! 9: #define TRUE 1 ! 10: #define FALSE 0 ! 11: #define FAILURE (-1) ! 12: ! 13: #define CAPS "caps" ! 14: ! 15: char *part1[] = ! 16: { ! 17: "/*\n", ! 18: " * ti4 [term]\n", ! 19: " * dummy program to test termlib.\n", ! 20: " * gets entry, counts it, and prints it.\n", ! 21: " */\n", ! 22: "#include <stdio.h>\n", ! 23: "#include \"curses.h\"\n", ! 24: "#include \"term.h\"\n", ! 25: "\n", ! 26: "#define prb(name)\tif (name) printf(\"name\\n\")\n", ! 27: "#define prn(name)\tif (name != -1) printf(\"name = %d\\n\", \ ! 28: name)\n", ! 29: "#define prs(name)\tif (name) {printf(\"name = '\"); pr(name); \ ! 30: printf(\"'\\n\");}\n", ! 31: "\n", ! 32: "char buf[1024];\n", ! 33: "char *getenv();\n", ! 34: "\n", ! 35: "main(argc, argv) char **argv; {\n", ! 36: "\tchar *p;\n", ! 37: "\tint rc;\n", ! 38: "\n", ! 39: "\tif (argc < 2)\n", ! 40: "\t\tp = getenv(\"TERM\");\n", ! 41: "\telse\n", ! 42: "\t\tp = argv[1];\n", ! 43: "\tprintf(\"Terminal type %s\\n\", p);\n", ! 44: "\tsetupterm(p,1,0);\n", ! 45: "\n", ! 46: "\tprintf(\"flags\\n\");\n", ! 47: "\n",0 ! 48: } ; ! 49: char *part2[] = ! 50: { ! 51: "\n", ! 52: "\tprintf(\"\\nnumbers\\n\");\n", ! 53: "\n",0 ! 54: } ; ! 55: char *part3[] = ! 56: { ! 57: "\n", ! 58: "\tprintf(\"\\nstrings\\n\");\n", ! 59: "\n",0 ! 60: } ; ! 61: char *part4[] = ! 62: { ! 63: "\n", ! 64: "\tprintf(\"end of strings\\n\");\n", ! 65: "\treset_shell_mode();\n", ! 66: "\texit(0);\n", ! 67: "}\n", ! 68: "\n", ! 69: "pr(p)\n", ! 70: "register char *p;\n", ! 71: "{\n", ! 72: "\tchar *rdchar();\n", ! 73: "\n", ! 74: "\tfor (; *p; p++)\n", ! 75: "\t\tprintf(\"%s\", rdchar(*p));\n", ! 76: "}\n", ! 77: "\n", ! 78: "/*\n", ! 79: " * rdchar: returns a readable representation of an ASCII char, \ ! 80: using ^ notation.\n", ! 81: " */\n", ! 82: "#include <ctype.h>\n", ! 83: "char *rdchar(c)\n", ! 84: "char c;\n", ! 85: "{\n", ! 86: "\tstatic char ret[4];\n", ! 87: "\tregister char *p;\n", ! 88: "\n", ! 89: "\t/*\n", ! 90: "\t * Due to a bug in isprint, this prints spaces as ^`, but \ ! 91: this is OK\n", ! 92: "\t * because we want something to show up on the screen.\n", ! 93: "\t */\n", ! 94: "\tret[0] = ((c&0377) > 0177) ? '\\'' : ' ';\n", ! 95: "\tc &= 0177;\n", ! 96: "\tret[1] = isprint(c) ? ' ' : '^';\n", ! 97: "\tret[2] = isprint(c) ? c : c^0100;\n", ! 98: "\tret[3] = 0;\n", ! 99: "\tfor (p=ret; *p==' '; p++)\n", ! 100: "\t\t;\n", ! 101: "\treturn (p);\n", ! 102: "}\n", ! 103: 0 ! 104: } ; ! 105: ! 106: main(argc,argv) ! 107: ! 108: int argc ; ! 109: char **argv ; ! 110: ! 111: { ! 112: register char **section ; ! 113: register char *ptr ; ! 114: register int i ; ! 115: char line[256],word[120] ; ! 116: FILE *fp ; ! 117: ! 118: if (--argc <= 0) ptr = CAPS ; ! 119: else ptr = *++argv ; ! 120: ! 121: if ((fp = fopen(ptr,"r")) == (FILE*)NULL) ! 122: { ! 123: perror(ptr) ; ! 124: exit(1) ; ! 125: } ! 126: ! 127: /* Print out the first section of the program. */ ! 128: ! 129: for (section= &part1[0]; *section ;) fputs(*section++,stdout) ; ! 130: ! 131: /* Look for "--- begin bool" in "caps" file. */ ! 132: ! 133: while (ptr = fgets(&line[0],sizeof(line),fp)) ! 134: { ! 135: if (strncmp(ptr,"--- begin bool",sizeof("--- begin bool")-1) ! 136: == 0) break ; ! 137: } ! 138: if (ptr == (char*)NULL) ! 139: { ! 140: fprintf(stderr,"Unable to find \"--- begin bool\"\n") ; ! 141: exit(1) ; ! 142: } ! 143: ! 144: while (ptr = fgets(&line[0],sizeof(line),fp)) ! 145: { ! 146: if (*ptr == '#') continue ; ! 147: if (strncmp(ptr,"--- end bool",sizeof("--- end bool")-1) ! 148: == 0) break ; ! 149: ! 150: if (sscanf(ptr,"%s",&word[0]) == 1) ! 151: { ! 152: /* Remove the comma after the word. */ ! 153: ! 154: word[strlen(&word[0])-1] = '\0' ; ! 155: fprintf(stdout,"\t prb(%s) ;\n",&word[0]) ; ! 156: } ! 157: } ! 158: if (ptr == (char*)NULL) ! 159: { ! 160: fprintf(stderr,"Premature termination during bools\n") ; ! 161: exit(1) ; ! 162: } ! 163: ! 164: /* Print out the second section of the program. */ ! 165: ! 166: for (section= &part2[0]; *section ;) fputs(*section++,stdout) ; ! 167: ! 168: /* Look for "--- begin num" in "caps" file. */ ! 169: ! 170: while (ptr = fgets(&line[0],sizeof(line),fp)) ! 171: { ! 172: if (*ptr == '#') continue ; ! 173: if (strncmp(ptr,"--- begin num",sizeof("--- begin num")-1) ! 174: == 0) break ; ! 175: } ! 176: if (ptr == (char*)NULL) ! 177: { ! 178: fprintf(stderr,"Unable to find \"--- begin num\"\n") ; ! 179: exit(1) ; ! 180: } ! 181: ! 182: while (ptr = fgets(&line[0],sizeof(line),fp)) ! 183: { ! 184: if (*ptr == '#') continue ; ! 185: if (strncmp(ptr,"--- end num",sizeof("--- end num")-1) ! 186: == 0) break ; ! 187: ! 188: if (sscanf(ptr,"%s",&word[0]) == 1) ! 189: { ! 190: /* Remove the comma after the word. */ ! 191: ! 192: word[strlen(&word[0])-1] = '\0' ; ! 193: fprintf(stdout,"\t prn(%s) ;\n",&word[0]) ; ! 194: } ! 195: } ! 196: if (ptr == (char*)NULL) ! 197: { ! 198: fprintf(stderr,"Premature termination during nums\n") ; ! 199: exit(1) ; ! 200: } ! 201: ! 202: /* Print out the third section of the program. */ ! 203: ! 204: for (section= &part3[0]; *section ;) fputs(*section++,stdout) ; ! 205: ! 206: /* Look for "--- begin str" in "caps" file. */ ! 207: ! 208: while (ptr = fgets(&line[0],sizeof(line),fp)) ! 209: { ! 210: if (*ptr == '#') continue ; ! 211: if (strncmp(ptr,"--- begin str",sizeof("--- begin str")-1) ! 212: == 0) break ; ! 213: } ! 214: if (ptr == (char*)NULL) ! 215: { ! 216: fprintf(stderr,"Unable to find \"--- begin str\"\n") ; ! 217: exit(1) ; ! 218: } ! 219: ! 220: while (ptr = fgets(&line[0],sizeof(line),fp)) ! 221: { ! 222: if (*ptr == '#') continue ; ! 223: if (strncmp(ptr,"--- end str",sizeof("--- end str")-1) ! 224: == 0) break ; ! 225: ! 226: if (sscanf(ptr,"%s",&word[0]) == 1) ! 227: { ! 228: /* Remove the comma after the word. */ ! 229: ! 230: word[strlen(&word[0])-1] = '\0' ; ! 231: fprintf(stdout,"\t prs(%s) ;\n",&word[0]) ; ! 232: } ! 233: } ! 234: if (ptr == (char*)NULL) ! 235: { ! 236: fprintf(stderr,"Premature termination during strs\n") ; ! 237: exit(1) ; ! 238: } ! 239: ! 240: /* Print out final section of program. */ ! 241: ! 242: for (section= &part4[0]; *section ;) fputs(*section++,stdout) ; ! 243: exit(0) ; ! 244: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.