home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FreeWare Collection 2
/
FreeSoftwareCollection2pd199x-jp.img
/
ms_dos
/
xscrfm51
/
xsetup.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-06-14
|
4KB
|
164 lines
/*
* xsetup
* Customize 'xscript' key assignment
* for xscript 1.4 FM version 2.0 or later
* using MSC compiler 4.0
* Copyright (C) SHU 1989-1990
* Ver 1.1 on Dec.18,1989
* using MSC compiler 5.1
* getkeycode()内にキー入力バッファのクリアを追加
* Ver 1.2 on Mar.7,1990
* using LSIC-86 試食版
*/
#define LINT_ARGS
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <io.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include <dos.h>
#define VERSIONSTR "Transcript service Ver 1.4"
#define HEADERSIZE 32
#define KEYS 4
char *keyinmessage1[] = {
"\r\n前回位置での起動キー[現在:", /* current key */
"\r\n最終位置での起動キー[現在:", /* bottom key */
"\r\nペースト機能キー[現在:", /* paste key */
"\r\nON/OFFキー[現在:" /* disable key */
};
char *errormessage[] = {
"", /* 0 : no error */
"Usage: xsetup <filename>", /* 1 : wrong arg count */
"Could not open the file", /* 2 : open error */
"Could not read the file", /* 3 : read error */
"Wrong file version. Use FM Ver 2.0 or later.", /* 4 : version error */
"Could not modify the file" /* 5 : write error */
};
char *keycodetable[] = {
"", "ESC", "1", "2", "3", "4", "5", "6", /* 00h - 07h */
"7", "8", "9", "0", "-", "^", "\\", "後退", /* 08h - 0Fh */
"TAB", "Q", "W", "E", "R", "T", "Y", "U", /* 10h - 17h */
"I", "O", "P", "", "[", "RET", "A", "S", /* 18h - 1Fh */
"D", "F", "G", "H", "J", "K", "L", ";", /* 20h - 27h */
":", "]", "Z", "X", "C", "V", "B", "N", /* 28h - 2Fh */
"M", ",", ".", "/", "`", "SPACE", "TEN*", "TEN/",
/* 30h - 37h */
"TEN+", "TEN-", "TEN7", "TEN8", "TEN9", "TEN=", "TEN4", "TEN5",
/* 38h - 3Fh */
"TEN6", "TEN.", "TEN1", "TEN2", "TEN3", "TENRET", "TEN0", "TEN000",
/* 40h - 47h */
"挿入", "", "", "削除", "", "上矢印", "HOME", "左矢印",
/* 48h - 4Fh */
"下矢印", "右矢印", "CTRL", "SHIFT", "", "CAP", "", "無変換",
/* 50h - 57h */
"変換", "かな漢字", "カタカナ", "PF12", "", "PF1", "PF2", "PF3",
/* 58h - 5Fh */
"PF4", "PF5", "PF6", "PF7", "PF8", "PF9", "PF10", "",
/* 60h - 67h */
"", "PF11", "英字", "漢字辞書", "単語抹消", "単語登録", "前行", "英小文字",
/* 68h - 6Fh */
"次行", "半角/全角", "取消", "実行", "PF13", "PF14", "PF15", "PF16",
/* 70h - 77h */
"PF17", "PF18", "PF19", "PF20", "BREAK", "COPY", "", ""
/* 78h - 7Fh */
};
void
main(argc, argv)
int argc;
char *argv[];
{
int fh; /* file handle */
int cnt; /* i/o bytes counter */
int i, c;
char ch;
char buf[HEADERSIZE + KEYS]; /* i/o buffer */
char keybuf[KEYS];
void error(int);
int getkeycode(void);
/* Show opening message */
puts("XSETUP : xscript setup tool ver 1.2 Copyright (C) SHU 1989");
/* Check 1st argument */
if (argc != 2)
error(1);
/* Check file existence */
if ((fh = open(argv[1], O_RDWR)) == -1) /* binaryモード */
error(2);
/* Check version */
if ((cnt = read(fh, buf, HEADERSIZE + KEYS)) != HEADERSIZE + KEYS)
error(3);
if (strncmp(VERSIONSTR, buf + 3, strlen(VERSIONSTR)))
error(4);
if (((ch = buf[3 + strlen(VERSIONSTR)]) < '2') || (ch > '9'))
error(4);
/* Input key */
puts("\nxscript を起動するために、CTRLキーと同時に押すキーを指定してください");
puts("\t(CTRLキーは押す必要はありません)");
for (i = 0; i < KEYS; i++) {
cputs(keyinmessage1[i]);
cputs(keycodetable[buf[HEADERSIZE + i]]);
cputs("]===>");
keybuf[i] = (char)getkeycode();
cputs(keycodetable[keybuf[i]]);
}
/* Verify change */
do {
printf("\n%s を書き換えてもよろしいですか (Y or N)", argv[1]);
c = getch();
c = toupper(c);
} while ((c != 'Y') && (c != 'N'));
if (c == 'N') {
puts("\n中断しました");
close(fh);
exit(0);
}
/* Modify file */
lseek(fh, (long)HEADERSIZE, 0);
if (write(fh, keybuf, KEYS) != KEYS)
error(5);
close(fh);
puts("\n変更しました");
exit(0);
}
void
error(code)
int code;
{
puts(errormessage[code]);
exit(1);
}
int
getkeycode()
{
unsigned int key;
union REGS inregs, outregs;
inregs.h.ah = 9; /* 文字の読み込み */
inregs.h.al = 0; /* 入力待ち */
int86(0x90, &inregs, &outregs);
key = outregs.h.bh;
inregs.h.ah = 6; /* バッファのクリア */
inregs.h.al = 0;
int86(0x90, &inregs, &outregs);
return(key);
}