2008-01-11 11:57:08 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 1991-1994 Sony Corporation
|
2026-06-19 01:49:53 +09:00
|
|
|
*
|
2008-01-11 11:57:08 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
|
* the following conditions:
|
2026-06-19 01:49:53 +09:00
|
|
|
*
|
2008-01-11 11:57:08 +00:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2026-06-19 01:49:53 +09:00
|
|
|
*
|
2008-01-11 11:57:08 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
|
* IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
|
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
|
|
|
|
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2026-06-19 01:49:53 +09:00
|
|
|
*
|
2008-01-11 11:57:08 +00:00
|
|
|
* Except as contained in this notice, the name of Sony Corporation
|
|
|
|
|
* shall not be used in advertising or otherwise to promote the sale, use
|
|
|
|
|
* or other dealings in this Software without prior written authorization
|
|
|
|
|
* from Sony Corporation.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
2026-06-19 01:49:53 +09:00
|
|
|
* $SonyRCSfile: readline.c,v $
|
|
|
|
|
* $SonyRevision: 1.1 $
|
2008-01-11 11:57:08 +00:00
|
|
|
* $SonyDate: 1994/06/03 08:00:44 $
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "sj_euc.h"
|
|
|
|
|
#include "sj3_dict_const.h"
|
|
|
|
|
|
|
|
|
|
#include "sj3mkdic.h"
|
|
|
|
|
|
2026-06-19 01:49:53 +09:00
|
|
|
static int yomi[MAXYOMILENGTH + 1];
|
|
|
|
|
static int kanji[MAXKANJILENGTH + 1];
|
|
|
|
|
static int hinsi[MAXHINSINUMBER + 1];
|
|
|
|
|
static int atr[MAXATRNUMBER + 1];
|
2008-01-11 11:57:08 +00:00
|
|
|
|
2026-06-19 01:49:53 +09:00
|
|
|
#define Isblank(c) ((c) == 0x20 || (c) == 0x09 || (c) == 0xa1a1)
|
|
|
|
|
#define Isillegal(c) ((c) < 0x20)
|
2008-01-11 11:57:08 +00:00
|
|
|
|
|
|
|
|
static void
|
2026-06-19 01:49:53 +09:00
|
|
|
error(char* s) {
|
|
|
|
|
if(s)
|
2008-01-11 11:57:08 +00:00
|
|
|
fprintf(stderr, "%s\n", s);
|
|
|
|
|
mark_file(stderr);
|
|
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2026-06-19 01:49:53 +09:00
|
|
|
readchar() {
|
|
|
|
|
int c1;
|
|
|
|
|
int c2;
|
2008-01-11 11:57:08 +00:00
|
|
|
|
|
|
|
|
c1 = getch();
|
2026-06-19 01:49:53 +09:00
|
|
|
if(c1 == EOF)
|
2008-01-11 11:57:08 +00:00
|
|
|
return EOF;
|
|
|
|
|
|
2026-06-19 01:49:53 +09:00
|
|
|
if(c1 != SS3) {
|
|
|
|
|
if(c1 & 0x80) {
|
2008-01-11 11:57:08 +00:00
|
|
|
c2 = getch();
|
2026-06-19 01:49:53 +09:00
|
|
|
if(c2 == EOF)
|
2008-01-11 11:57:08 +00:00
|
|
|
error(NULL);
|
|
|
|
|
c1 = ((c1 & 0xff) << 8) + (c2 & 0xff);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
c2 = getch();
|
2026-06-19 01:49:53 +09:00
|
|
|
if(c2 == EOF)
|
2008-01-11 11:57:08 +00:00
|
|
|
error(NULL);
|
|
|
|
|
c1 = ((c1 & 0xff) << 8) + (c2 & 0xff);
|
|
|
|
|
c2 = getch();
|
2026-06-19 01:49:53 +09:00
|
|
|
if(c2 == EOF)
|
2008-01-11 11:57:08 +00:00
|
|
|
error(NULL);
|
|
|
|
|
c1 = ((c1 & 0xffff) << 8) + (c2 & 0xff);
|
|
|
|
|
}
|
|
|
|
|
return c1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2026-06-19 01:49:53 +09:00
|
|
|
skip_blank() {
|
|
|
|
|
int c;
|
2008-01-11 11:57:08 +00:00
|
|
|
|
|
|
|
|
c = readchar();
|
2026-06-19 01:49:53 +09:00
|
|
|
while(Isblank(c))
|
2008-01-11 11:57:08 +00:00
|
|
|
c = readchar();
|
|
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2026-06-19 01:49:53 +09:00
|
|
|
readhinsi() {
|
|
|
|
|
static int c = 0;
|
|
|
|
|
int i;
|
|
|
|
|
unsigned char hinsi[128];
|
2008-01-11 11:57:08 +00:00
|
|
|
|
|
|
|
|
retry:
|
2026-06-19 01:49:53 +09:00
|
|
|
if(c == '\n') {
|
2008-01-11 11:57:08 +00:00
|
|
|
c = 0;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c = skip_blank();
|
2026-06-19 01:49:53 +09:00
|
|
|
if(c == '\n') {
|
2008-01-11 11:57:08 +00:00
|
|
|
c = 0;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-19 01:49:53 +09:00
|
|
|
for(i = 0; !Isblank(c);) {
|
|
|
|
|
if(c == '\n' || c == ':')
|
2008-01-11 11:57:08 +00:00
|
|
|
break;
|
2026-06-19 01:49:53 +09:00
|
|
|
if(Isillegal(c))
|
2008-01-11 11:57:08 +00:00
|
|
|
error(ILLEGALFORMAT);
|
2026-06-19 01:49:53 +09:00
|
|
|
if(c > 0xffffff) {
|
|
|
|
|
if(i >= 126)
|
2008-01-11 11:57:08 +00:00
|
|
|
error(TOOLONGHINSI);
|
|
|
|
|
hinsi[i++] = ((c >> 24) & 0xff);
|
2026-06-19 01:49:53 +09:00
|
|
|
if(i >= 126)
|
2008-01-11 11:57:08 +00:00
|
|
|
error(TOOLONGHINSI);
|
|
|
|
|
hinsi[i++] = ((c >> 16) & 0xff);
|
2026-06-19 01:49:53 +09:00
|
|
|
if(i >= 126)
|
2008-01-11 11:57:08 +00:00
|
|
|
error(TOOLONGHINSI);
|
|
|
|
|
hinsi[i++] = ((c >> 8) & 0xff);
|
2026-06-19 01:49:53 +09:00
|
|
|
} else if(c > 0xffff) {
|
|
|
|
|
if(i >= 126)
|
2008-01-11 11:57:08 +00:00
|
|
|
error(TOOLONGHINSI);
|
|
|
|
|
hinsi[i++] = ((c >> 16) & 0xff);
|
2026-06-19 01:49:53 +09:00
|
|
|
if(i >= 126)
|
2008-01-11 11:57:08 +00:00
|
|
|
error(TOOLONGHINSI);
|
|
|
|
|
hinsi[i++] = ((c >> 8) & 0xff);
|
2026-06-19 01:49:53 +09:00
|
|
|
} else if(c > 0xff) {
|
|
|
|
|
if(i >= 126)
|
2008-01-11 11:57:08 +00:00
|
|
|
error(TOOLONGHINSI);
|
|
|
|
|
hinsi[i++] = ((c >> 8) & 0xff);
|
|
|
|
|
}
|
2026-06-19 01:49:53 +09:00
|
|
|
if(i >= 127)
|
2008-01-11 11:57:08 +00:00
|
|
|
error(TOOLONGHINSI);
|
|
|
|
|
hinsi[i++] = (c & 0xff);
|
2026-06-19 01:49:53 +09:00
|
|
|
c = readchar();
|
2008-01-11 11:57:08 +00:00
|
|
|
}
|
|
|
|
|
|
2026-06-19 01:49:53 +09:00
|
|
|
if(i == 0)
|
2008-01-11 11:57:08 +00:00
|
|
|
return 0;
|
|
|
|
|
|
2026-06-19 01:49:53 +09:00
|
|
|
if(hinsi[0] == '[' && hinsi[i - 1] == ']') {
|
2008-01-11 11:57:08 +00:00
|
|
|
hinsi[i - 1] = 0;
|
2026-06-19 01:49:53 +09:00
|
|
|
i = cnvhinsi(hinsi + 1);
|
|
|
|
|
if(i > 0) {
|
2008-01-11 11:57:08 +00:00
|
|
|
fprintf(stderr, "\311\312\273\354 \"%s\" \244\313\263\347\270\314\244\254\244\304\244\244\244\306\244\244\244\353\n",
|
|
|
|
|
hinsi + 1);
|
2026-06-19 01:49:53 +09:00
|
|
|
} else if(!i) {
|
2008-01-11 11:57:08 +00:00
|
|
|
fprintf(stderr, "\"%s\" \244\254\245\263\241\274\245\311\262\275\244\307\244\255\244\336\244\273\244\363\n",
|
|
|
|
|
hinsi + 1);
|
|
|
|
|
goto retry;
|
|
|
|
|
}
|
2026-06-19 01:49:53 +09:00
|
|
|
} else {
|
2008-01-11 11:57:08 +00:00
|
|
|
hinsi[i] = 0;
|
2026-06-19 01:49:53 +09:00
|
|
|
i = cnvhinsi(hinsi);
|
|
|
|
|
if(!i) {
|
2008-01-11 11:57:08 +00:00
|
|
|
fprintf(stderr, "\"%s\" \244\254\245\263\241\274\245\311\262\275\244\307\244\255\244\336\244\273\244\363\n", hinsi);
|
|
|
|
|
goto retry;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-19 01:49:53 +09:00
|
|
|
int* readline() {
|
|
|
|
|
int c;
|
|
|
|
|
int i;
|
|
|
|
|
int j;
|
2008-01-11 11:57:08 +00:00
|
|
|
|
2026-06-19 01:49:53 +09:00
|
|
|
for(;;) {
|
2008-01-11 11:57:08 +00:00
|
|
|
mark_file(NULL);
|
|
|
|
|
|
|
|
|
|
c = skip_blank();
|
|
|
|
|
|
2026-06-19 01:49:53 +09:00
|
|
|
if(c == '#') {
|
|
|
|
|
while(c != '\n')
|
2008-01-11 11:57:08 +00:00
|
|
|
c = skip_blank();
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-19 01:49:53 +09:00
|
|
|
if(c == EOF)
|
2008-01-11 11:57:08 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
2026-06-19 01:49:53 +09:00
|
|
|
if(c != '\n')
|
2008-01-11 11:57:08 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-19 01:49:53 +09:00
|
|
|
for(i = 0; !Isblank(c);) {
|
|
|
|
|
if(Isillegal(c))
|
2008-01-11 11:57:08 +00:00
|
|
|
error(ILLEGALFORMAT);
|
2026-06-19 01:49:53 +09:00
|
|
|
if(i >= MAXYOMILENGTH)
|
2008-01-11 11:57:08 +00:00
|
|
|
error(TOOLONGYOMI);
|
|
|
|
|
yomi[i++] = c;
|
2026-06-19 01:49:53 +09:00
|
|
|
c = readchar();
|
2008-01-11 11:57:08 +00:00
|
|
|
}
|
|
|
|
|
yomi[i] = 0;
|
2026-06-19 01:49:53 +09:00
|
|
|
if(i == 0)
|
2008-01-11 11:57:08 +00:00
|
|
|
error(NOYOMISTRING);
|
|
|
|
|
|
|
|
|
|
c = skip_blank();
|
|
|
|
|
|
2026-06-19 01:49:53 +09:00
|
|
|
if(c != '"') {
|
|
|
|
|
for(i = 0; !Isblank(c);) {
|
|
|
|
|
if(Isillegal(c))
|
2008-01-11 11:57:08 +00:00
|
|
|
error(ILLEGALFORMAT);
|
2026-06-19 01:49:53 +09:00
|
|
|
if(i >= MAXKANJILENGTH)
|
2008-01-11 11:57:08 +00:00
|
|
|
error(TOOLONGKANJI);
|
|
|
|
|
kanji[i++] = c;
|
2026-06-19 01:49:53 +09:00
|
|
|
c = readchar();
|
2008-01-11 11:57:08 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
c = readchar();
|
2026-06-19 01:49:53 +09:00
|
|
|
for(i = 0; c != '"';) {
|
|
|
|
|
if(Isillegal(c))
|
2008-01-11 11:57:08 +00:00
|
|
|
error(ILLEGALFORMAT);
|
2026-06-19 01:49:53 +09:00
|
|
|
if(i >= MAXKANJILENGTH)
|
2008-01-11 11:57:08 +00:00
|
|
|
error(TOOLONGKANJI);
|
|
|
|
|
kanji[i++] = c;
|
2026-06-19 01:49:53 +09:00
|
|
|
c = readchar();
|
2008-01-11 11:57:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
kanji[i] = 0;
|
2026-06-19 01:49:53 +09:00
|
|
|
if(i == 0)
|
2008-01-11 11:57:08 +00:00
|
|
|
error(NOKANJISTRING);
|
|
|
|
|
|
|
|
|
|
i = j = 0;
|
2026-06-19 01:49:53 +09:00
|
|
|
while(c = readhinsi()) {
|
|
|
|
|
if(c < 0) {
|
|
|
|
|
if(i >= MAXATRNUMBER)
|
2008-01-11 11:57:08 +00:00
|
|
|
error(TOOMANYATR);
|
|
|
|
|
atr[i++] = -c;
|
2026-06-19 01:49:53 +09:00
|
|
|
} else {
|
|
|
|
|
if(j >= MAXHINSINUMBER)
|
2008-01-11 11:57:08 +00:00
|
|
|
error(TOOMANYHINSI);
|
|
|
|
|
hinsi[j++] = c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
atr[i] = 0;
|
2026-06-19 01:49:53 +09:00
|
|
|
if(j == 0)
|
2008-01-11 11:57:08 +00:00
|
|
|
hinsi[j++] = HINSITANKAN;
|
|
|
|
|
hinsi[j] = 0;
|
|
|
|
|
|
|
|
|
|
return yomi;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-19 01:49:53 +09:00
|
|
|
void setline(void (*func)(int*, int*, int, int*)) {
|
|
|
|
|
int i;
|
2008-01-11 11:57:08 +00:00
|
|
|
|
2026-06-19 01:49:53 +09:00
|
|
|
for(i = 0; hinsi[i]; i++)
|
2008-01-11 11:57:08 +00:00
|
|
|
(*func)(yomi, kanji, hinsi[i], atr);
|
|
|
|
|
}
|