home *** CD-ROM | disk | FTP | other *** search
/ FreeWare Collection 2 / FreeSoftwareCollection2pd199x-jp.img / ms_dos / xscrfm51 / xsetup.c < prev    next >
C/C++ Source or Header  |  1990-06-14  |  4KB  |  164 lines

  1. /*
  2.  * xsetup
  3.  *    Customize 'xscript' key assignment
  4.  *        for xscript 1.4 FM version 2.0 or later
  5.  *        using MSC compiler 4.0
  6.  *        Copyright (C) SHU 1989-1990
  7.  *    Ver 1.1 on Dec.18,1989
  8.  *        using MSC compiler 5.1
  9.  *        getkeycode()内にキー入力バッファのクリアを追加
  10.  *    Ver 1.2 on Mar.7,1990
  11.  *        using LSIC-86 試食版
  12.  */
  13.  
  14. #define        LINT_ARGS
  15. #include    <stdio.h>
  16. #include    <stdlib.h>
  17. #include    <fcntl.h>
  18. #include    <io.h>
  19. #include    <conio.h>
  20. #include    <string.h>
  21. #include    <ctype.h>
  22. #include    <dos.h>
  23.  
  24. #define        VERSIONSTR    "Transcript service Ver 1.4"
  25. #define        HEADERSIZE    32
  26. #define        KEYS        4
  27.  
  28. char    *keyinmessage1[] = {
  29.         "\r\n前回位置での起動キー[現在:",    /* current key */
  30.         "\r\n最終位置での起動キー[現在:",    /* bottom key */
  31.         "\r\nペースト機能キー[現在:",        /* paste key */
  32.         "\r\nON/OFFキー[現在:"        /* disable key */
  33. };
  34.  
  35. char    *errormessage[] = {
  36.         "",                /* 0 : no error */
  37.         "Usage: xsetup <filename>",    /* 1 : wrong arg count */
  38.         "Could not open the file",    /* 2 : open error */
  39.         "Could not read the file",    /* 3 : read error */
  40.         "Wrong file version. Use FM Ver 2.0 or later.",    /* 4 : version error */
  41.         "Could not modify the file"    /* 5 : write error */
  42. };
  43.  
  44. char    *keycodetable[] = {
  45.     "", "ESC", "1", "2", "3", "4", "5", "6",    /* 00h - 07h */
  46.     "7", "8", "9", "0", "-", "^", "\\", "後退",    /* 08h - 0Fh */
  47.     "TAB", "Q", "W", "E", "R", "T", "Y", "U",    /* 10h - 17h */
  48.     "I", "O", "P", "", "[", "RET", "A", "S",    /* 18h - 1Fh */
  49.     "D", "F", "G", "H", "J", "K", "L", ";",        /* 20h - 27h */
  50.     ":", "]", "Z", "X", "C", "V", "B", "N",        /* 28h - 2Fh */
  51.     "M", ",", ".", "/", "`", "SPACE", "TEN*", "TEN/",
  52.                             /* 30h - 37h */
  53.      "TEN+", "TEN-", "TEN7", "TEN8", "TEN9", "TEN=", "TEN4", "TEN5",
  54.                              /* 38h - 3Fh */
  55.     "TEN6", "TEN.", "TEN1", "TEN2", "TEN3", "TENRET", "TEN0", "TEN000",
  56.                             /* 40h - 47h */
  57.     "挿入", "", "", "削除", "", "上矢印", "HOME", "左矢印",
  58.                             /* 48h - 4Fh */
  59.      "下矢印", "右矢印", "CTRL", "SHIFT", "", "CAP", "", "無変換",
  60.                              /* 50h - 57h */
  61.     "変換", "かな漢字", "カタカナ", "PF12", "", "PF1", "PF2", "PF3",
  62.                             /* 58h - 5Fh */
  63.      "PF4", "PF5", "PF6", "PF7", "PF8", "PF9", "PF10", "",
  64.                               /* 60h - 67h */
  65.      "", "PF11", "英字", "漢字辞書", "単語抹消", "単語登録", "前行", "英小文字",
  66.                              /* 68h - 6Fh */
  67.     "次行", "半角/全角", "取消", "実行", "PF13", "PF14", "PF15", "PF16",
  68.                             /* 70h - 77h */
  69.     "PF17", "PF18", "PF19", "PF20", "BREAK", "COPY", "", ""
  70.                             /* 78h - 7Fh */
  71. };
  72.  
  73. void
  74. main(argc, argv)
  75. int    argc;
  76. char    *argv[];
  77. {
  78.     int    fh;        /* file handle */
  79.     int    cnt;        /* i/o bytes counter */
  80.     int    i, c;
  81.     char    ch;
  82.     char    buf[HEADERSIZE + KEYS];    /* i/o buffer */
  83.     char    keybuf[KEYS];
  84.     void    error(int);
  85.     int    getkeycode(void);
  86.     
  87.     /* Show opening message */
  88.     puts("XSETUP : xscript setup tool ver 1.2   Copyright (C) SHU 1989");
  89.     
  90.     /* Check 1st argument */
  91.     if (argc != 2)
  92.         error(1);
  93.     
  94.     /* Check file existence */
  95.     if ((fh = open(argv[1], O_RDWR)) == -1)        /* binaryモード */
  96.         error(2);
  97.     
  98.     /* Check version */
  99.     if ((cnt = read(fh, buf, HEADERSIZE + KEYS)) != HEADERSIZE + KEYS)
  100.         error(3);
  101.     if (strncmp(VERSIONSTR, buf + 3, strlen(VERSIONSTR)))
  102.         error(4);
  103.     if (((ch = buf[3 + strlen(VERSIONSTR)]) < '2') || (ch > '9'))
  104.         error(4);
  105.     
  106.     /* Input key */
  107.     puts("\nxscript を起動するために、CTRLキーと同時に押すキーを指定してください");
  108.     puts("\t(CTRLキーは押す必要はありません)");
  109.     for (i = 0; i < KEYS; i++) {
  110.         cputs(keyinmessage1[i]);
  111.         cputs(keycodetable[buf[HEADERSIZE + i]]);
  112.         cputs("]===>");
  113.         keybuf[i] = (char)getkeycode();
  114.         cputs(keycodetable[keybuf[i]]);
  115.     }
  116.     
  117.     /* Verify change */
  118.     do {
  119.         printf("\n%s を書き換えてもよろしいですか (Y or N)", argv[1]);
  120.         c = getch();
  121.         c = toupper(c);
  122.     } while ((c != 'Y') && (c != 'N'));
  123.     
  124.     if (c == 'N') {
  125.         puts("\n中断しました");
  126.         close(fh);
  127.         exit(0);
  128.     }
  129.     
  130.     /* Modify file */
  131.     lseek(fh, (long)HEADERSIZE, 0);
  132.     if (write(fh, keybuf, KEYS) != KEYS)
  133.         error(5);
  134.     close(fh);
  135.     puts("\n変更しました");
  136.     
  137.     exit(0);
  138. }
  139.  
  140. void
  141. error(code)
  142. int    code;
  143. {
  144.     puts(errormessage[code]);
  145.     exit(1);
  146. }
  147.  
  148. int
  149. getkeycode()
  150. {
  151.     unsigned int    key;
  152.     union REGS    inregs, outregs;
  153.     
  154.     inregs.h.ah = 9;            /* 文字の読み込み */
  155.     inregs.h.al = 0;            /* 入力待ち */
  156.     int86(0x90, &inregs, &outregs);
  157.     key = outregs.h.bh;
  158.     
  159.     inregs.h.ah = 6;            /* バッファのクリア */
  160.     inregs.h.al = 0;
  161.     int86(0x90, &inregs, &outregs);
  162.  
  163.     return(key);
  164. }