|
|
1.1 ! root 1: /* ! 2: * This program builds the emacs' comtab.c and bind.doc ! 3: */ ! 4: #include <stdio.h> ! 5: #include <ed.h> ! 6: /* ! 7: * Table of function names and comments. ! 8: */ ! 9: static char *nameCom[] = { ! 10: #if EXKEYS ! 11: "ignore", " Ignore this function ", ! 12: #endif ! 13: ! 14: "ctrlg", " Abort out of things ", ! 15: "quit", " Quit ", ! 16: "ctlxlp", " Begin macro ", ! 17: "ctlxrp", " End macro ", ! 18: "ctlxe", " Execute macro ", ! 19: "fileread", " Get a file, read only ", ! 20: "filevisit", " Get a file, read write ", ! 21: "*", " Also F2 ", ! 22: "filewrite", " Write a file ", ! 23: "*", " Also F2 ", ! 24: "filesave", " Save current file ", ! 25: "filename", " Adjust file name ", ! 26: "gotobol", " Move to start of line ", ! 27: "*", " Also HOME KEY ", ! 28: "forwchar", " Move forward by characters ", ! 29: "*", " Also RIGHT ARROW ", ! 30: "gotoeol", " Move to end of line ", ! 31: "*", " Also END KEY ", ! 32: "backchar", " Move backward by characters ", ! 33: "*", " Also LEFT ARROW ", ! 34: "forwline", " Move forward by lines ", ! 35: "*", " Also DOWN ARROW ", ! 36: "backline", " Move backward by lines ", ! 37: "*", " Also UP ARROW ", ! 38: "forwpage", " Move forward by pages ", ! 39: "*", " Also PAGE DOWN ", ! 40: "backpage", " Move backward by pages ", ! 41: "*", " Also PAGE UP ", ! 42: "gotobob", " Move to start of buffer ", ! 43: "gotoeob", " Move to end of buffer ", ! 44: "setfillcol", " Set fill column to current col ", ! 45: "*", " ctl-u n set fill col to n ", ! 46: "*", " ctl-u 0 turn off word wrap ", ! 47: "fillregion", " apply fillcol to a region", ! 48: "setmark", " Set mark ", ! 49: "swapmark", " Swap '.' and mark ", ! 50: "forwsearch", " Search forward ", ! 51: "*", " Also F3 ", ! 52: "*", " ALT F3 is continue search ", ! 53: "forwisearch", " forward incremental search ", ! 54: "backisearch", " backward incremental search ", ! 55: "queryrepl", " query/replace ", ! 56: "*", " Also F5 ", ! 57: "searchagain", " find next occurrance ", ! 58: "backsearch", " Search backwards ", ! 59: "*", " Also F4 ", ! 60: "showcpos", " Show the cursor position ", ! 61: "nextwind", " Move to the next window ", ! 62: "*", " Also F6 ", ! 63: "prevwind", " Move to the previous window ", ! 64: "onlywind", " Make current window only one ", ! 65: "*", " Also F10 ", ! 66: "splitwind", " Split current window ", ! 67: "*", " Also ALT F1 ", ! 68: "mvdnwind", " Move window down ", ! 69: "mvupwind", " Move window up ", ! 70: "enlargewind", " Enlarge display window. ", ! 71: "shrinkwind", " Shrink window. ", ! 72: "listbuffers", " Display list of buffers ", ! 73: "usebuffer", " Switch a window to a buffer ", ! 74: "killbuffer", " Make a buffer go away. ", ! 75: "reposition", " Reposition dot to line ctl-u ", ! 76: "*", " if ctl-u 0 center ", ! 77: "*", " if ctl-u < 0 repos from bottom ", ! 78: "refresh", " Refresh the screen ", ! 79: "*", " with ctl-u recenter ", ! 80: "twiddle", " Twiddle characters ", ! 81: "tab", " Insert tab ", ! 82: "*", " ctl-u n use n spaces per tab ", ! 83: "*", " ctl-u -n tab is n spaces ", ! 84: "newline", " Insert CR-LF ", ! 85: "*", " Same as ctl-j in autoindent mode ", ! 86: "indent", " Insert CR-LF, then indent ", ! 87: "openline", " Open up a blank line ", ! 88: "deblank", " Delete blank lines ", ! 89: "quote", " Insert literal ", ! 90: "quoteval", " Insert decimal literal ", ! 91: "backword", " Backup by words ", ! 92: "forwword", " Advance by words ", ! 93: "forwdel", " Forward delete ", ! 94: "*", " Also DELETE KEY ", ! 95: "backdel", " Backward delete ", ! 96: "kill", " Kill forward from dot ", ! 97: "*", " if ctl-u 0 or less backward ", ! 98: "yank", " Yank back from killbuffer. ", ! 99: "loadBinds", " Load flexable bindings from file. ", ! 100: "nameMac", " Bind current macro to binding. ", ! 101: "initMac", " Bind current macro to initial macro ", ! 102: "setPrefix", " Set prefix codes ", ! 103: "bindFun", " Bind function to old function. ", ! 104: "storBinds", " Store flexable bindings on a file. ", ! 105: "upperword", " Upper case word. ", ! 106: "lowerword", " Lower case word. ", ! 107: "upperregion", " Upper case region. ", ! 108: "lowerregion", " Lower case region. ", ! 109: "capword", " Initial capitalize word. ", ! 110: "delfword", " Delete forward word. ", ! 111: "delbword", " Delete backward word. ", ! 112: "killregion", " Kill region. ", ! 113: "copyregion", " Copy region to kill buffer. ", ! 114: "spawncli", " Run CLI in a subjob. ", ! 115: "spawn", " Run a command in a subjob. ", ! 116: "quickexit", " low keystroke style exit. ", ! 117: "gotoline", " goto line given as arg ", ! 118: "gotofline", " goto line in file. ", ! 119: "setfold", " set case-fold on search flag ", ! 120: "displaymod", " toggle display mode switch ", ! 121: "autoind", " toggle autoindent flag ", ! 122: "*", " Also ALT F10 ", ! 123: "nexterr", " Seek the next error ", ! 124: "preverr", " Seek the previous error ", ! 125: "bracketsearch", " seek matching bracket char ", ! 126: "bracketsw", " toggle bracket mode ", ! 127: #if LIBHELP ! 128: "lookupword", " Lookup a word... ", ! 129: "*", " Also F1 ", ! 130: "promptlook", " Prompt for a word to look up ", ! 131: "zaphelp", " Zap help window ", ! 132: "hlpindex", " Help index generator ", ! 133: #endif ! 134: "zapwind", " Zap current window ", ! 135: #if GEM ! 136: "grabmem", " Grab memory ", ! 137: #endif ! 138: NULL, NULL ! 139: }; ! 140: ! 141: /* ! 142: * Table of control characters and function names. ! 143: */ ! 144: typedef struct control control; ! 145: struct control { ! 146: int key; ! 147: char *keyn; ! 148: char *fun; ! 149: }; ! 150: control ctlName[] = { ! 151: CTRL|'@', "CTRL|'@'", "setmark", ! 152: CTRL|'A', "CTRL|'A'", "gotobol", ! 153: CTRL|'B', "CTRL|'B'", "backchar", ! 154: CTRL|'C', "CTRL|'C'", "spawncli", ! 155: CTRL|'D', "CTRL|'D'", "forwdel", ! 156: CTRL|'E', "CTRL|'E'", "gotoeol", ! 157: CTRL|'F', "CTRL|'F'", "forwchar", ! 158: CTRL|'G', "CTRL|'G'", "ctrlg", ! 159: CTRL|'H', "CTRL|'H'", "backdel", ! 160: CTRL|'I', "CTRL|'I'", "tab", ! 161: CTRL|'J', "CTRL|'J'", "indent", ! 162: CTRL|'K', "CTRL|'K'", "kill", ! 163: CTRL|'L', "CTRL|'L'", "refresh", ! 164: CTRL|'M', "CTRL|'M'", "newline", ! 165: CTRL|'N', "CTRL|'N'", "forwline", ! 166: CTRL|'O', "CTRL|'O'", "openline", ! 167: CTRL|'P', "CTRL|'P'", "backline", ! 168: CTRL|'Q', "CTRL|'Q'", "quote", ! 169: CTRL|'R', "CTRL|'R'", "backisearch", ! 170: CTRL|'S', "CTRL|'S'", "forwisearch", ! 171: CTRL|'T', "CTRL|'T'", "twiddle", ! 172: CTRL|'V', "CTRL|'V'", "forwpage", ! 173: CTRL|'W', "CTRL|'W'", "killregion", ! 174: CTRL|'Y', "CTRL|'Y'", "yank", ! 175: CTRL|'Z', "CTRL|'Z'", "quickexit", ! 176: PFX1|CTRL|'B', "PFX1|CTRL|'B'", "listbuffers", ! 177: PFX1|CTRL|'C', "PFX1|CTRL|'C'", "quit", ! 178: PFX1|CTRL|'F', "PFX1|CTRL|'F'", "filename", ! 179: PFX1|CTRL|'L', "PFX1|CTRL|'L'", "lowerregion", ! 180: PFX1|CTRL|'O', "PFX1|CTRL|'O'", "deblank", ! 181: PFX1|CTRL|'N', "PFX1|CTRL|'N'", "mvdnwind", ! 182: PFX1|CTRL|'P', "PFX1|CTRL|'P'", "mvupwind", ! 183: PFX1|CTRL|'R', "PFX1|CTRL|'R'", "fileread", ! 184: PFX1|CTRL|'S', "PFX1|CTRL|'S'", "filesave", ! 185: PFX1|CTRL|'U', "PFX1|CTRL|'U'", "upperregion", ! 186: PFX1|CTRL|'V', "PFX1|CTRL|'V'", "filevisit", ! 187: PFX1|CTRL|'W', "PFX1|CTRL|'W'", "filewrite", ! 188: PFX1|CTRL|'X', "PFX1|CTRL|'X'", "swapmark", ! 189: PFX1|CTRL|'Z', "PFX1|CTRL|'Z'", "shrinkwind", ! 190: PFX1|'!', "PFX1|'!'", "spawn", ! 191: PFX1|'<', "PFX1|'<'", "preverr", ! 192: PFX1|'=', "PFX1|'='", "showcpos", ! 193: PFX1|'>', "PFX1|'>'", "nexterr", ! 194: PFX1|'(', "PFX1|'('", "ctlxlp", ! 195: PFX1|')', "PFX1|')'", "ctlxrp", ! 196: PFX1|'1', "PFX1|'1'", "onlywind", ! 197: PFX1|'2', "PFX1|'2'", "splitwind", ! 198: #if LIBHELP ! 199: PFX1|'?', "PFX1|'?'", "promptlook", ! 200: #endif ! 201: PFX1|'B', "PFX1|'B'", "usebuffer", ! 202: PFX1|'E', "PFX1|'E'", "ctlxe", ! 203: PFX1|'F', "PFX1|'F'", "setfillcol", ! 204: PFX1|'G', "PFX1|'G'", "gotoline", ! 205: PFX1|'H', "PFX1|'H'", "fillregion", ! 206: PFX1|'K', "PFX1|'K'", "killbuffer", ! 207: PFX1|'I', "PFX1|'I'", "initMac", ! 208: PFX1|'L', "PFX1|'L'", "loadBinds", ! 209: PFX1|'M', "PFX1|'M'", "nameMac", ! 210: PFX1|'N', "PFX1|'N'", "nextwind", ! 211: PFX1|'P', "PFX1|'P'", "prevwind", ! 212: PFX1|'R', "PFX1|'R'", "bindFun", ! 213: PFX1|'S', "PFX1|'S'", "storBinds", ! 214: PFX1|'X', "PFX1|'X'", "setPrefix", ! 215: PFX1|'Z', "PFX1|'Z'", "enlargewind", ! 216: PFX1|'[', "PFX1|'['", "bracketsearch", ! 217: PFX1|']', "PFX1|']'", "bracketsw", ! 218: #ifdef VT52KEYS ! 219: META|CTRL|'B', "META|CTRL|'B'", "backword", ! 220: META|CTRL|'C', "META|CTRL|'C'", "capword", ! 221: META|CTRL|'D', "META|CTRL|'D'", "delfword", ! 222: #endif ! 223: META|CTRL|'H', "META|CTRL|'H'", "delbword", ! 224: META|CTRL|'R', "META|CTRL|'R'", "queryrepl", ! 225: #if LIBHELP ! 226: META|CTRL|']', "META|CTRL|']'", "hlpindex", ! 227: #endif ! 228: META|'!', "META|'!'", "reposition", ! 229: META|'.', "META|'.'", "setmark", ! 230: META|'1', "META|'1'", "zapwind", ! 231: META|'2', "META|'2'", "zaphelp", ! 232: #if GEM ! 233: META|'+', "META|'+'", "grabmem", ! 234: #endif ! 235: META|'>', "META|'>'", "gotoeob", ! 236: META|'<', "META|'<'", "gotobob", ! 237: META|'%', "META|'%'", "queryrepl", ! 238: META|'/', "META|'/'", "searchagain", ! 239: #if LIBHELP ! 240: META|'?', "META|'?'", "lookupword", ! 241: #endif ! 242: META|'@', "META|'@'", "setfold", ! 243: #ifdef VT52KEYS ! 244: META|'A', "META|'A'", "backline", ! 245: META|'B', "META|'B'", "forwline", ! 246: META|'C', "META|'C'", "backchar", ! 247: META|'D', "META|'D'", "forwchar", ! 248: #else ! 249: META|'B', "META|'B'", "backword", ! 250: META|'C', "META|'C'", "capword", ! 251: META|'D', "META|'D'", "delfword", ! 252: #endif ! 253: META|'F', "META|'F'", "forwword", ! 254: META|'G', "META|'G'", "gotofline", ! 255: META|'J', "META|'J'", "autoind", ! 256: META|'L', "META|'L'", "lowerword", ! 257: META|'Q', "META|'Q'", "quoteval", ! 258: META|'R', "META|'R'", "backsearch", ! 259: META|'S', "META|'S'", "forwsearch", ! 260: META|'T', "META|'T'", "displaymod", ! 261: META|'U', "META|'U'", "upperword", ! 262: META|'V', "META|'V'", "backpage", ! 263: META|'W', "META|'W'", "copyregion", ! 264: META|0x7F, "META|0x7F", "delbword", ! 265: 0x7F, "0x7F", "backdel" ! 266: #if EXKEYS ! 267: ,FN0, "FN0", "ignore", ! 268: FN1, "FN1", "ignore", ! 269: FN2, "FN2", "ignore", ! 270: FN3, "FN3", "ignore", ! 271: FN4, "FN4", "ignore", ! 272: FN5, "FN5", "ignore", ! 273: FN6, "FN6", "ignore", ! 274: FN7, "FN7", "ignore", ! 275: FN8, "FN8", "ignore", ! 276: FN9, "FN9", "ignore", ! 277: FNA, "FNA", "ignore", ! 278: FNB, "FNB", "ignore", ! 279: FNC, "FNC", "ignore", ! 280: FND, "FND", "ignore", ! 281: FNE, "FNE", "ignore", ! 282: FNF, "FNF", "ignore", ! 283: FN10, "FN10", "ignore", ! 284: FN11, "FN11", "ignore", ! 285: FN12, "FN12", "ignore", ! 286: FN13, "FN13", "ignore", ! 287: FN14, "FN14", "ignore", ! 288: FN15, "FN15", "ignore", ! 289: FN16, "FN16", "ignore", ! 290: FN17, "FN17", "ignore", ! 291: FN18, "FN18", "ignore", ! 292: FN19, "FN19", "ignore", ! 293: FN10, "FN10", "ignore", ! 294: FN11, "FN11", "ignore", ! 295: FN12, "FN12", "ignore" ! 296: #endif ! 297: }; ! 298: ! 299: #define CTSIZE (sizeof(ctlName) / sizeof(control)) ! 300: ! 301: static FILE *doc; ! 302: KEYTAB keytab[CTSIZE + HASHP]; ! 303: int error = 0; ! 304: ! 305: /* ! 306: * put data to stdout. ! 307: */ ! 308: pf(s) ! 309: char *s; ! 310: { ! 311: printf("%r\n", &s); ! 312: } ! 313: ! 314: /* ! 315: * Lookup function name and return number. ! 316: */ ! 317: funNo(name) ! 318: register char *name; ! 319: { ! 320: register char *p; ! 321: register int no; ! 322: ! 323: for (no = 0; NULL != (p = nameCom[no]); no += 2) { ! 324: if (!strcmp(p, name)) { ! 325: *(nameCom[no + 1]) = '*'; ! 326: return (no / 2); ! 327: } ! 328: } ! 329: fprintf(stderr, "Cannot find %s\n", name); ! 330: error = 1; ! 331: } ! 332: ! 333: /* ! 334: * Adjust number to account for commentary lines. ! 335: */ ! 336: trueNo(n) ! 337: { ! 338: register int i, j; ! 339: ! 340: n *= 2; ! 341: for (i = j = 0; i < n; i += 2) ! 342: if ('*' == *nameCom[i]) ! 343: j++; ! 344: return ((i / 2) - j); ! 345: } ! 346: ! 347: /* ! 348: * Build hashed key table. ! 349: */ ! 350: buildTab() ! 351: { ! 352: register KEYTAB *k; ! 353: register control *p; ! 354: int n, i, f, l; ! 355: ! 356: /* init hash table */ ! 357: for (k = keytab; k < (keytab + CTSIZE + HASHP); k++) ! 358: k->k_code = k->k_synonym = -1; ! 359: ! 360: fprintf(doc, "PFX1 is initially bound to ctl-x\n"); ! 361: fprintf(doc, "PFX2 and PFX3 are initially unbound\n\n\n"); ! 362: fprintf(doc, "%-16s%-16s%s\n", "key binding", "function", "command"); ! 363: /* load hash table */ ! 364: l = HASHP; ! 365: for (i = 0; i < CTSIZE; i++) { ! 366: p = ctlName + i; ! 367: k = keytab + (p->key % HASHP); ! 368: n = (f = funNo(p->fun)) * 2; ! 369: fprintf(doc, "%-16s%-16s%s\n", p->keyn, nameCom[n], ! 370: nameCom[1 + n] + 1); ! 371: while ((NULL != nameCom[n += 2]) && ('*' == *nameCom[n])) ! 372: fprintf(doc, "\t\t\t\t%-16s\n", nameCom[n + 1] + 1); ! 373: if (-1 != k->k_code) { ! 374: /* to end of chain */ ! 375: for (;; k = keytab + k->k_synonym) { ! 376: if (i == k->k_code) { ! 377: fprintf(stderr, "Duplucate code for %s\n", p->keyn); ! 378: error = 1; ! 379: } ! 380: if (-1 == k->k_synonym) ! 381: break; ! 382: } ! 383: k = keytab + (k->k_synonym = l++); ! 384: } ! 385: k->k_code = i; ! 386: k->k_fun = f; ! 387: } ! 388: ! 389: /* output hash table */ ! 390: pf("KEYTAB keytab[] = {"); ! 391: for (i = 0; i < l; i++) { ! 392: if (-1 == (k = keytab + i)->k_code) ! 393: pf("{\t-1, 0, -1},\t/* hole in table */"); ! 394: else { ! 395: p = ctlName + k->k_code; ! 396: pf("{%16s, %3d, %3d },\t/* %-16s %d */", ! 397: p->keyn, trueNo(k->k_fun), ! 398: k->k_synonym, p->fun, i); ! 399: } ! 400: } ! 401: pf("};"); ! 402: } ! 403: ! 404: main() ! 405: { ! 406: register char **p; ! 407: int i = 0; ! 408: ! 409: if (NULL == (doc = fopen("bind.doc", "w"))) ! 410: exit(1); ! 411: ! 412: pf("/*"); ! 413: pf(" * Emacs command tables."); ! 414: pf(" * Generated by ext.c"); ! 415: pf(" * Make any changes by changing ext.c"); ! 416: pf(" */\n"); ! 417: pf("#include \"stdio.h\""); ! 418: pf("#include \"ed.h\"\n"); ! 419: for (p = nameCom; NULL != *p; p += 2) ! 420: if (**p != '*') ! 421: pf("extern %16s();\t/*%s*/", p[0], p[1]); ! 422: else ! 423: pf("\t\t\t\t/*%s*/", p[1]); ! 424: ! 425: pf("\nFUNTAB funtab[] = {"); ! 426: for (p = nameCom; NULL != *p; p += 2) ! 427: if (**p != '*') ! 428: pf("%16s,\t/* %d */", p[0], i++); ! 429: pf("};"); ! 430: ! 431: buildTab(); ! 432: for (p = nameCom; NULL != p[0]; p += 2) ! 433: if (('*' != *p[0]) && ('*' != *p[1])) { ! 434: fprintf(stderr, "unused name %s\n", p[0]); ! 435: error = 1; ! 436: } ! 437: exit(error); /* zero if no errors else 1 */ ! 438: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.