home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / UE311C.ZIP / CMDFIX.C < prev    next >
C/C++ Source or Header  |  1990-08-16  |  5KB  |  261 lines

  1. /*    CMDFIX.C:    Translate pre 3.10 command and startup
  2.             files to 3.10 files
  3.             (C)Copyright 1988 by Daniel Lawrence
  4.             All Rights reserved
  5.  
  6.     The names of function key command strings have been changed to
  7.     help make these names machine independant.  This program translates
  8.     old files to new.
  9.  
  10. */
  11.  
  12. #include <stdio.h>
  13. #include "estruct.h"
  14.  
  15. pascal fix();
  16.  
  17. /*    Table of command key name changes */
  18.  
  19. char *trans[][2] = {
  20.     "FN ",    "A-D",
  21.     "FN!",    "A-F",
  22.     "FN#",    "A-H",
  23.     "FN$",    "A-J",
  24.     "FN%",    "A-K",
  25.     "FN&",    "A-L",
  26.     "FN,",    "A-Z",
  27.     "FN-",    "A-X",
  28.     "FN.",    "A-C",
  29.     "FN/",    "A-V",
  30.     "FN0",    "A-B",
  31.     "FN1",    "A-N",
  32.     "FN2",    "A-M",
  33.     "FN;",    "FN1",
  34.     "FN<",    "FN2",
  35.     "FN=",    "FN3",
  36.     "FN>",    "FN4",
  37.     "FN?",    "FN5",
  38.     "FN@",    "FN6",
  39.     "FNA",    "FN7",
  40.     "FNB",    "FN8",
  41.     "FNC",    "FN9",
  42.     "FND",    "FN0",
  43.     "FNG",    "FN<",
  44.     "FNH",    "FNP",
  45.     "FNI",    "FNZ",
  46.     "FNK",    "FNB",
  47.     "FNM",    "FNF",
  48.     "FNO",    "FN>",
  49.     "FNP",    "FNN",
  50.     "FNQ",    "FNV",
  51.     "FNR",    "FNC",
  52.     "FNS",    "FND",
  53.     "FNT",    "S-FN1",
  54.     "FNU",    "S-FN2",
  55.     "FNV",    "S-FN3",
  56.     "FNW",    "S-FN4",
  57.     "FNX",    "S-FN5",
  58.     "FNY",    "S-FN6",
  59.     "FNZ",    "S-FN7",
  60.     "FN[",    "S-FN8",
  61.     "FN\"",    "A-G",
  62.     "FN\\",    "S-FN9",
  63.     "FN]",    "S-FN0",
  64.     "FN^",    "FN^1",
  65.     "FN_",    "FN^2",
  66.     "FN`",    "FN^3",
  67.     "FNa",    "FN^4",
  68.     "FNb",    "FN^5",
  69.     "FNc",    "FN^6",
  70.     "FNd",    "FN^7",
  71.     "FNe",    "FN^8",
  72.     "FNf",    "FN^9",
  73.     "FNg",    "FN^0",
  74.     "FNh",    "A-FN1",
  75.     "FNi",    "A-FN2",
  76.     "FNj",    "A-FN3",
  77.     "FNk",    "A-FN4",
  78.     "FNl",    "A-FN5",
  79.     "FNm",    "A-FN6",
  80.     "FNn",    "A-FN7",
  81.     "FNo",    "A-FN8",
  82.     "FNp",    "A-FN9",
  83.     "FNq",    "A-FN0",
  84.     "FNs",    "FN^B",
  85.     "FNt",    "FN^F",
  86.     "FNu",    "FN^>",
  87.     "FNv",    "FN^V",
  88.     "FNw",    "FN^<",
  89.     "FNä",    "FN^Z",
  90. };
  91.  
  92. #define NUMTRAN    70
  93.  
  94. char *trans1[][2] = {
  95.     "FN^P",    "A-Q",
  96.     "FN^Q",    "A-W",
  97.     "FN^R",    "A-E",
  98.     "FN^S",    "A-R",
  99.     "FN^T",    "A-T",
  100.     "FN^U",    "A-Y",
  101.     "FN^V",    "A-U",
  102.     "FN^W",    "A-I",
  103.     "FN^X",    "A-O",
  104.     "FN^Y",    "A-P",
  105.     "FN^^",    "A-A",
  106.     "FN^_",    "A-S",
  107. };
  108.  
  109. #define NUMTRAN1    13
  110.  
  111. /* some other globals */
  112.  
  113. FILE *infile;    /* current input file handle */
  114. FILE *outfile;    /* current output file handle */
  115.  
  116. main(argc, argv)
  117.  
  118. int argc;    /* number of command line arguments */
  119. char *argv[];    /* text of command line arguments */
  120.  
  121. {
  122.     register carg;    /* current command line argument */
  123.  
  124.     puts("CMDFIX:    Startup and Command file updater");
  125.     printf("        for MicroEMACS version %s\n", VERSION);
  126.  
  127.     /* help people out! */
  128.     if (argc < 2) {
  129.         puts("Converts MicroEMACS 3.9n and earlier keybindings to");
  130.         puts("version 3.10 keybindings.");
  131.         puts("\nUsage:    cmdfix <file list>");
  132.         exit(-1);
  133.     }
  134.  
  135.     /* loop through each input file and convert it */
  136.     carg = 1;
  137.     while (carg < argc) {
  138.         fix(argv[carg]);
  139.         ++carg;
  140.     }
  141.     exit(0);
  142. }
  143.  
  144. pascal fix(fname)
  145.  
  146. char *fname;    /* file to fix */
  147.  
  148. {
  149.     register int inp;
  150.     register int index;
  151.     int nseq;    /* number of fixed function sequences */
  152.     int buf[4];    /* buffer for characters going through */
  153.  
  154.     printf("Fixing %s\n", fname);
  155.  
  156.     /***    FIRST PASS   ***/
  157.     /* first open the input file */
  158.     infile = fopen(fname, "r");
  159.     if (infile == NULL) {
  160.         printf("%%No such file as %s\n", fname);
  161.         return;
  162.     }
  163.  
  164.     /* open the temporary output file */
  165.     outfile = fopen("tempfile", "w");
  166.     if (outfile == NULL) {
  167.         puts("%Can not open output file");
  168.         fclose(infile);
  169.         return;
  170.     }
  171.  
  172.  
  173.     /* scan through the file... holding on FN sequences */
  174.     inp = 0;
  175.     buf[0] = 0;
  176.     while (buf[0] != EOF) {
  177.         if (inp == 4) {
  178.             /* try to translate */
  179.             if ((buf[0] == 'F') && (buf[1] == 'N') && (buf[2] == 0x5e)) {
  180.                 for (index = 0; index < NUMTRAN1; index++)
  181.                     if (trans1[index][0][3] == buf[3]) {
  182.                         fprintf(outfile, "%s", trans1[index][1]);
  183.                         inp = 0;
  184.                         buf[0] = 0;
  185.                         break;
  186.                     }
  187.             }
  188.         }
  189.         if (inp == 4) {
  190.             /* cycle a character */
  191.             putc(buf[0], outfile);
  192.             buf[0] = buf[1];
  193.             buf[1] = buf[2];
  194.             buf[2] = buf[3];
  195.             if (buf[3] != EOF)
  196.                 buf[3] = getc(infile);
  197.         } else {
  198.             buf[inp++] = getc(infile);
  199.         }
  200.     }
  201.  
  202.     /* close the files */
  203.     fclose(infile);
  204.     fclose(outfile);
  205.  
  206.     /***    Second PASS   ***/
  207.     /* first open the temporary input file */
  208.     infile = fopen("tempfile", "r");
  209.     if (infile == NULL) {
  210.         printf("%%No such file as %s\n", fname);
  211.         return;
  212.     }
  213.  
  214.     /* open the output file */
  215.     outfile = fopen(fname, "w");
  216.     if (outfile == NULL) {
  217.         puts("%Can not open output file");
  218.         fclose(infile);
  219.         return;
  220.     }
  221.  
  222.     /* scan through the file... holding on FN sequences */
  223.     inp = 0;
  224.     nseq = 0;
  225.     buf[0] = 0;
  226.     while (buf[0] != EOF) {
  227.         if (inp == 3) {
  228.             /* try to translate */
  229.             if (buf[0] == 'F' && buf[1] == 'N') {
  230.                 for (index = 0; index < NUMTRAN; index++)
  231.                     if (trans[index][0][2] == buf[2]) {
  232.                         fprintf(outfile, "%s", trans[index][1]);
  233.                         inp = 0;
  234.                         buf[0] = 0;
  235.                         ++nseq;
  236.                         break;
  237.                     }
  238.             }
  239.         }
  240.         if (inp == 3) {
  241.             /* cycle a character */
  242.             putc(buf[0], outfile);
  243.             buf[0] = buf[1];
  244.             buf[1] = buf[2];
  245.             if (buf[2] != EOF)
  246.                 buf[2] = getc(infile);
  247.         } else {
  248.             buf[inp++] = getc(infile);
  249.         }
  250.     }
  251.  
  252.     /* close the files */
  253.     fclose(infile);
  254.     fclose(outfile);
  255.     unlink("tempfile");
  256.  
  257.     /* and report */
  258.     printf("[%u keys fixed in %s]\n", nseq, fname);
  259.     return;
  260. }
  261.