Path: sokai!inet-gw!cae-gw!ntt-twins!nttlab!tutgw!hamamatsu-pc.ac.jp!dclsic!wnoc-tyo-news!astemgw!icspub!taeko!ouskn1!nishioka From: nishioka@sanken.osaka-u.ac.jp (Shingo NISHIOKA) Newsgroups: fj.sources Subject: dserver/Electronic Book Dictionary server & clients (1/2) Message-ID: Date: 3 Sep 91 10:14:59 GMT Sender: news@ouskn1.sanken.osaka-u.ac.jp Distribution: fj Organization: The Institute of Scientific and Industrial Research, Osaka University. Lines: 2253 #!/bin/sh # This is a shell archive (produced by shar 3.49) # To extract the files from this archive, save it to a file, remove # everything above the "!/bin/sh" line above, and type "sh file_name". # # made 09/03/1991 09:57 UTC by nishioka@ouskn1 # Source directory /usr/u/nishioka/src # # existing files will NOT be overwritten unless -c is specified # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 1413 -rw-r--r-- dict/doc/protocol # 228 -rw-r--r-- dict/eiwa/Makefile # 6686 -rw-r--r-- dict/eiwa/eiwa.c # 5492 -rw-r--r-- dict/eiwa/eiwa.c.nowild # 141 -rw-r--r-- dict/waei/Makefile # 6663 -rw-r--r-- dict/waei/waei.c # 579 -rw-r--r-- dict/server/Makefile # 221 -rw-r--r-- dict/server/README # 6270 -rw-r--r-- dict/server/daemon.c # 10017 -rw-r--r-- dict/server/util.c # 852 -rw-r--r-- dict/server/main.c # 282 -rw-r--r-- dict/server/cdrom.h # 337 -rw-r--r-- dict/server/ndtp.h # 1806 -rw-r--r-- dict/INSTALL # 56 -rw-r--r-- dict/Makefile # 247 -rw-r--r-- dict/kojien/Makefile # 7173 -rw-r--r-- dict/kojien/kojien.c # 1071 -rw-r--r-- dict/kojien/convtest.c # 887 -rw-r--r-- dict/DIST # 469 -rw-r--r-- dict/README # 2089 -rw-r--r-- dict/client/client.c # 181 -rw-r--r-- dict/client/Makefile # 22396 -rw-r--r-- dict/client/diclookup.el # 5068 -rw-r--r-- dict/client/README # 1772 -rw-r--r-- dict/client/dsstat.c # # ============= dict/doc/protocol ============== if test ! -d 'dict'; then echo 'x - creating directory dict' mkdir 'dict' fi if test ! -d 'dict/doc'; then echo 'x - creating directory dict/doc' mkdir 'dict/doc' fi if test -f 'dict/doc/protocol' -a X"$1" != X"-c"; then echo 'x - skipping dict/doc/protocol (File already exists)' else echo 'x - extracting dict/doc/protocol (Text)' sed 's/^X//' << 'SHAR_EOF' > 'dict/doc/protocol' && client->server X SYNOPSIS DESCRIPTION L 辞書の切替え p パターンをサーチする(含ワイルドカードサーチ) r 正規表現によるパターンサーチ (not implemented) Q 終了 A 使用許可を得る u 今使っているユーザのリストを表示する X NOTE: A,u,Q は, A を一度もしていなくても使うことができる. Xそれ以外のコマンドは, A を実行した後でないと使えない. は JIS-code か EUC-code でなければならない. は次のような形式にすることが推奨される @[:] X例えば, nishioka@sp4, mat@sun3:ttyp2 など. X X server->client X SYNOPSIS DESCRIPTION $A 使用許可を得るのに成功 $N 使用許可を得るのに失敗, もしくは使用許可がない $0 検索結果の始まり $1 次の単語の始まり $$ 検索結果の終り $? コマンドに誤まりがある $! 単語が見つからなかった $U$$ ユーザの一覧 (が含まれることがある) $* 辞書切替え成功 $& 辞書切替え失敗 X NOTE: Xパターン検索に対するサーバからの返答は次のいずれかの形式である. X {$0$1}$$ $$ $! $A $N X Xここに, X ::= {^J を含まない文字列. X SHAR_EOF chmod 0644 dict/doc/protocol || echo 'restore of dict/doc/protocol failed' Wc_c="`wc -c < 'dict/doc/protocol'`" test 1413 -eq "$Wc_c" || echo 'dict/doc/protocol: original size 1413, current size' "$Wc_c" fi # ============= dict/eiwa/Makefile ============== if test ! -d 'dict/eiwa'; then echo 'x - creating directory dict/eiwa' mkdir 'dict/eiwa' fi if test -f 'dict/eiwa/Makefile' -a X"$1" != X"-c"; then echo 'x - skipping dict/eiwa/Makefile (File already exists)' else echo 'x - extracting dict/eiwa/Makefile (Text)' sed 's/^X//' << 'SHAR_EOF' > 'dict/eiwa/Makefile' && CFLAGS=-g all: eiwa.o eiwa.o: clean: X rm -f debug *.o *‾ debug: eiwa.c ../server/util.c X cc -o debug -DDEBUG -DALONE eiwa.c ../server/util.c rdebug: reiwa.c ../server/util.c X cc -o debug -DDEBUG -DALONE reiwa.c ../server/util.c SHAR_EOF chmod 0644 dict/eiwa/Makefile || echo 'restore of dict/eiwa/Makefile failed' Wc_c="`wc -c < 'dict/eiwa/Makefile'`" test 228 -eq "$Wc_c" || echo 'dict/eiwa/Makefile: original size 228, current size' "$Wc_c" fi # ============= dict/eiwa/eiwa.c ============== if test -f 'dict/eiwa/eiwa.c' -a X"$1" != X"-c"; then echo 'x - skipping dict/eiwa/eiwa.c (File already exists)' else echo 'x - extracting dict/eiwa/eiwa.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'dict/eiwa/eiwa.c' && /* X * Copyright (C) Shingo NISHIOKA, 1991 X * nishioka@sanken.osaka-u.ac.jp X */ X #include #include "../server/cdrom.h" X #define IOBUFSZ 128 X #define TRUE 1 #define FALSE 0 X #ifdef ALONE int debug=2; #endif X #ifdef DEBUG extern int debug; #endif X /* the follwings are application specific constants */ X #define DICT "/usr/local/dict/e/eiwa/start." X #define STARTFRAME 6 X /* end */ X #ifdef ALONE main(argc,argv) int argc; char *argv[]; { #ifdef DEBUG X if(debug>=2) { X if(argc==3 && !strcmp(argv[1],"-x")) { X sscanf(argv[2],"%d",&debug); X } X } #endif X eiwa_init(); X eiwa_set_currout(0); X for(;;) { X char *p; X char buf[IOBUFSZ]; X printf("key="); X fgets(buf,IOBUFSZ,stdin); X if(buf[0]=='¥n') { X break; X } X else { X for(p=buf; *p&&*p!='¥n'; p++) ; X *p = '¥0'; X eiwa_process_entry(buf); X } X } X printf("bye.¥n"); } #endif X static int current_stream; static FILE *dic; X eiwa_init() { X X if(!(dic=fopen(DICT,"r"))) { X fprintf(stderr,"Cannot open file %s¥n",DICT); X exit(1); X } } X eiwa_process_entry(k) char *k; { X char buf[IOBUFSZ]; X char key[IOBUFSZ*2]; X #ifdef DEBUG X if(debug>=2) { X printf("given key=%s¥n",k); X } #endif X strncpy(buf,k,IOBUFSZ-1); X buf[IOBUFSZ-1]='¥0'; X nstringupcase(buf); #ifdef DEBUG X if(debug>=2) { X printf("buf=%s¥n",k); X } #endif X han2zen(buf,key); #ifdef DEBUG X if(debug>=2) { X printf("converted key=¥033$@%s¥033(J¥n",key); X } #endif X if(masterindex(dic,key)) { X write(current_stream,"$!¥n",3); X } X else { X write(current_stream,"$$¥n",3); X } } X eiwa_set_currout(out) int out; { X current_stream=out; } X typedef int fourbytes; typedef short int twobytes; X static masterindex(dic,key) FILE *dic; char *key; { X struct _master_key { X char key[48]; X fourbytes pad; X fourbytes ptr; X }; X struct _master_key master_key; X twobytes pad,count; X int i; X #ifdef DEBUG X if(debug>=2) { X seekframe(dic,STARTFRAME); X fread(&pad,sizeof(twobytes),1,dic); X fread(&count,sizeof(twobytes),1,dic); X count--; X printf("%d¥n",count); X for(i=0; i=2) { X seekframe(dic,frame); X fread(&pad,sizeof(twobytes),1,dic); X fread(&count,sizeof(twobytes),1,dic); X printf("%d¥n",count); X for(i=0; i=2) { X seekframe(dic,frame); X fread(&pad,sizeof(twobytes),1,dic); X fread(&count,sizeof(twobytes),1,dic); X printf("%d¥n",count); X for(i=0; i=0) { X frame++; X goto CONT; X } X X return status; } X static print_entry(dic,key) FILE *dic; struct _third_key *key; { X int hi,lo; X int c; X #ifdef DEBUG X if(debug>=2) { X printf("Spell:%08x,%04x¥n",key->spell_ptr,key->spell_offs); X printf("Descr:%08x,%04x¥n",key->desc_ptr,key->desc_offs); X } #endif X write(current_stream,"$0",2); X seekframe(dic,key->spell_ptr); X fseek(dic,key->spell_offs,1); X do { X hi = getc(dic); X lo = getc(dic); X } while(hi==0x1f); X do { X if(hi!=0x1f) { X puteucz2h(current_stream,hi,lo); X } X hi = getc(dic); X lo = getc(dic); X } while(!(hi==0x1f && lo==0x0a)); X write(current_stream,"¥n",1); X X write(current_stream,"$1",2); X seekframe(dic,key->desc_ptr); X fseek(dic,key->desc_offs,1); X X do { X hi = getc(dic); X lo = getc(dic); X } while(!(hi==0x00 && lo==0x00)); X X do { X if(hi!=0x1f) { X puteucz2h(current_stream,hi,lo); X } X hi = getc(dic); X lo = getc(dic); X } while(!(hi==0x00 && lo==0x00)); X X write(current_stream,"¥n",1); } X #define WHOLE 1 /* zentai ga match */ #define SHORT 2 /* mizikai hou no nagasade nstrcmp suru */ X reg_jisstrsub(s,t,r) unsigned char *s, *t; int r; { X unsigned int ss,tt; X X for(; ; s+=2,t+=2) { X ss = (*s&0x7f<<8)|(*(s+1)&0x7f); X tt = (*t&0x7f<<8)|(*(t+1)&0x7f); X X if(r==2 && (ss=='*' || ss=='?')) { X return 0; X } X if(r==1 && (ss=='*')) { X return 0; X } X if(!ss || !tt) break; X if(r==1 && (ss=='?')) { X continue; X } X if(ss!=tt) break; X } X return ss-tt; } SHAR_EOF chmod 0644 dict/eiwa/eiwa.c || echo 'restore of dict/eiwa/eiwa.c failed' Wc_c="`wc -c < 'dict/eiwa/eiwa.c'`" test 6686 -eq "$Wc_c" || echo 'dict/eiwa/eiwa.c: original size 6686, current size' "$Wc_c" fi # ============= dict/eiwa/eiwa.c.nowild ============== if test -f 'dict/eiwa/eiwa.c.nowild' -a X"$1" != X"-c"; then echo 'x - skipping dict/eiwa/eiwa.c.nowild (File already exists)' else echo 'x - extracting dict/eiwa/eiwa.c.nowild (Text)' sed 's/^X//' << 'SHAR_EOF' > 'dict/eiwa/eiwa.c.nowild' && /* X * Copyright (C) Shingo NISHIOKA, 1991 X * nishioka@sanken.osaka-u.ac.jp X */ X #include #include "../server/cdrom.h" X #define IOBUFSZ 128 X #define TRUE 1 #define FALSE 0 X #ifdef DEBUG extern int debug; #endif X /* the follwings are application specific constants */ X #define DICT "/usr/local/dict/e/eiwa/start." X #define STARTFRAME 6 X /* end */ X static int current_stream; static FILE *dic; X eiwa_init() { X X if(!(dic=fopen(DICT,"r"))) { X fprintf(stderr,"Cannot open file %s¥n",DICT); X exit(1); X } } X eiwa_process_entry(k) char *k; { X char buf[IOBUFSZ]; X char key[IOBUFSZ*2]; X X strncpy(buf,k,IOBUFSZ-1); X buf[IOBUFSZ-1]='¥0'; X nstringupcase(buf); X han2zen(buf,key); #ifdef DEBUG X if(debug>=2) { X printf("given key=¥033$@%s¥033(J¥n",key); X } #endif X if(masterindex(dic,key)) { X write(current_stream,"$!¥n",3); X } X else { X write(current_stream,"$$¥n",3); X } } X eiwa_set_currout(out) int out; { X current_stream=out; } X typedef int fourbytes; typedef short int twobytes; X static masterindex(dic,key) FILE *dic; char *key; { X struct _master_key { X char key[48]; X fourbytes pad; X fourbytes ptr; X }; X struct _master_key master_key; X twobytes pad,count; X int i; X #ifdef DEBUG X if(debug>=2) { X seekframe(dic,STARTFRAME); X fread(&pad,sizeof(twobytes),1,dic); X fread(&count,sizeof(twobytes),1,dic); X count--; X printf("%d¥n",count); X for(i=0; i=2) { X seekframe(dic,frame); X fread(&pad,sizeof(twobytes),1,dic); X fread(&count,sizeof(twobytes),1,dic); X printf("%d¥n",count); X for(i=0; i=2) { X seekframe(dic,frame); X fread(&pad,sizeof(twobytes),1,dic); X fread(&count,sizeof(twobytes),1,dic); X printf("%d¥n",count); X for(i=0; i=2) { X printf("Spell:%08x,%04x¥n",key->spell_ptr,key->spell_offs); X printf("Descr:%08x,%04x¥n",key->desc_ptr,key->desc_offs); X } #endif X write(current_stream,"$0",2); X seekframe(dic,key->spell_ptr); X fseek(dic,key->spell_offs,1); X do { X hi = getc(dic); X lo = getc(dic); X } while(hi==0x1f); X do { X if(hi!=0x1f) { X puteucz2h(current_stream,hi,lo); X } X hi = getc(dic); X lo = getc(dic); X } while(!(hi==0x1f && lo==0x0a)); X write(current_stream,"¥n",1); X X write(current_stream,"$1",2); X seekframe(dic,key->desc_ptr); X fseek(dic,key->desc_offs,1); X X do { X hi = getc(dic); X lo = getc(dic); X } while(!(hi==0x00 && lo==0x00)); X X do { X if(hi!=0x1f) { X puteucz2h(current_stream,hi,lo); X } X hi = getc(dic); X lo = getc(dic); X } while(!(hi==0x00 && lo==0x00)); X X write(current_stream,"¥n",1); } SHAR_EOF chmod 0644 dict/eiwa/eiwa.c.nowild || echo 'restore of dict/eiwa/eiwa.c.nowild failed' Wc_c="`wc -c < 'dict/eiwa/eiwa.c.nowild'`" test 5492 -eq "$Wc_c" || echo 'dict/eiwa/eiwa.c.nowild: original size 5492, current size' "$Wc_c" fi # ============= dict/waei/Makefile ============== if test ! -d 'dict/waei'; then echo 'x - creating directory dict/waei' mkdir 'dict/waei' fi if test -f 'dict/waei/Makefile' -a X"$1" != X"-c"; then echo 'x - skipping dict/waei/Makefile (File already exists)' else echo 'x - extracting dict/waei/Makefile (Text)' sed 's/^X//' << 'SHAR_EOF' > 'dict/waei/Makefile' && CFLAGS=-g all: waei.o waei.o: clean: X rm -f debug *.o *‾ debug: waei.c ../server/util.c X cc -o debug -DDEBUG -DALONE waei.c ../server/util.c SHAR_EOF chmod 0644 dict/waei/Makefile || echo 'restore of dict/waei/Makefile failed' Wc_c="`wc -c < 'dict/waei/Makefile'`" test 141 -eq "$Wc_c" || echo 'dict/waei/Makefile: original size 141, current size' "$Wc_c" fi # ============= dict/waei/waei.c ============== if test -f 'dict/waei/waei.c' -a X"$1" != X"-c"; then echo 'x - skipping dict/waei/waei.c (File already exists)' else echo 'x - extracting dict/waei/waei.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'dict/waei/waei.c' && /* X * Copyright (C) Shingo NISHIOKA, 1991 X * nishioka@sanken.osaka-u.ac.jp X */ X #include #include "../server/cdrom.h" X #define IOBUFSZ 128 X #define TRUE 1 #define FALSE 0 X #ifdef DEBUG extern int debug; #endif X /* the follwings are application specific constants */ X #define DICT "/usr/local/dict/e/waei/start." X #define STARTFRAME 6 X /* end */ X static int current_stream; static FILE *dic; X waei_init() { X X if(!(dic=fopen(DICT,"r"))) { X fprintf(stderr,"Cannot open file %s¥n",DICT); X exit(1); X } } X waei_process_entry(k) char *k; { X char buf[IOBUFSZ]; X char key[IOBUFSZ*2]; X char realkey[IOBUFSZ*2]; X int len; X X strncpy(buf,k,IOBUFSZ-1); X buf[IOBUFSZ-1]='¥0'; X neuc2jis(buf); X X strcpy(key,buf); X strcpy(realkey,buf); X X len = strlen(key); X key[len]='¥0'; X key[len+1]='¥0'; X realkey[len]='¥0'; X realkey[len+1]='¥0'; X X njisnormalize(key); X #ifdef DEBUG X if(debug>=2) { X printf("given key=¥033$@%s*¥033(J¥n",realkey); X printf("converted key=¥033$@%s¥033(J*¥n",key); X } #endif X if(masterindex(dic,key,realkey)) { X write(current_stream,"$!¥n",3); X } X else { X write(current_stream,"$$¥n",3); X } } X waei_set_currout(out) int out; { X current_stream=out; } X typedef int fourbytes; typedef short int twobytes; X static masterindex(dic,key,realkey) FILE *dic; char *key,*realkey; { X struct _master_key { X char key[30]; X fourbytes ptr; X }; X struct _master_key master_key; X twobytes pad,count; X int i; X X seekframe(dic,STARTFRAME); X fread(&pad,sizeof(twobytes),1,dic); X fread(&count,sizeof(twobytes),1,dic); X count--; /* the master_index's bug? */ X for(i=0; i=2) { X for(j=0; j<48; j+=2) { X puteuc(master_key.key[j],master_key.key[j+1]); X } X printf("* %08x¥n",master_key.ptr); X } #endif X X if(jisstrsub(key,master_key.key)<=0) break; X } X if(i=2) { X printf("Next Frame = %08x¥n",master_key.ptr); X } #endif X return secondaryindex(dic,key,realkey,master_key.ptr); X } X else { X return -1; X } } X static secondaryindex(dic,key,realkey,frame) FILE *dic; char *key,*realkey; int frame; { X struct _second_key { X char key[30]; X fourbytes ptr; X }; X struct _second_key second_key; X twobytes pad,count; X int i; X X seekframe(dic,frame); X fread(&pad,sizeof(twobytes),1,dic); X fread(&count,sizeof(twobytes),1,dic); X for(i=0; i=2) { X for(j=0; j<48; j+=2) { X puteuc(second_key.key[j],second_key.key[j+1]); X } X printf("%08x¥n",second_key.ptr); X } #endif X if(jisstrsub(key,second_key.key)<=0) break; X } X if(i=2) { X printf("Next Frame = %08x¥n",second_key.ptr); X } #endif X return thirdindex(dic,key,realkey,second_key.ptr); X } X else { X return -1; X } } X struct _third_key { X char key1[128]; X char key2[128]; X fourbytes desc_ptr; X twobytes desc_offs; X fourbytes spell_ptr; X twobytes spell_offs; }; X static thirdindex(dic,key,realkey,frame) FILE *dic; char *key,*realkey; int frame; { X struct _third_key third_key; X twobytes count; X twobytes pad2; X unsigned char pad1; X int i; X unsigned char leng; X int status; X int curr_frame_type; X X status = -1; X seekframe(dic,frame); X fread(&pad1,sizeof(char),1,dic); X curr_frame_type = pad1; X fread(&pad1,sizeof(char),1,dic); X fread(&count,sizeof(twobytes),1,dic); #ifdef DEBUG X if(debug>=2) { X printf("Count=%d¥n",count); X } #endif X for(i=0; i=2) { X printf("*"); X for(j=0; ; j+=2) { X if(key[j]==0 && key[j+1]==0) break; X puteuc(key[j]&0x7f,key[j+1]&0x7f); X } X printf("*"); X for(j=0; j=2) { X printf("Spell:%08x,%04x¥n",key->spell_ptr,key->spell_offs); X printf("Descr:%08x,%04x¥n",key->desc_ptr,key->desc_offs); X } #endif X write(current_stream,"$0",2); X seekframe(dic,key->spell_ptr); X fseek(dic,key->spell_offs,1); X do { X hi = getc(dic); X lo = getc(dic); X } while(hi==0x1f); X do { X if(hi!=0x1f) { X puteucz2h(current_stream,hi,lo); X } X hi = getc(dic); X lo = getc(dic); X } while(!(hi==0x1f && lo==0x0a)); X write(current_stream,"¥n",1); X X write(current_stream,"$1",2); X seekframe(dic,key->desc_ptr); X fseek(dic,key->desc_offs,1); X X do { X hi = getc(dic); X lo = getc(dic); X } while(!(hi==0x00 && lo==0x00)); X X do { X if(hi!=0x1f) { X puteucz2h(current_stream,hi,lo); X } X hi = getc(dic); X lo = getc(dic); X } while(!(hi==0x00 && lo==0x00)); X X write(current_stream,"¥n",1); } SHAR_EOF chmod 0644 dict/waei/waei.c || echo 'restore of dict/waei/waei.c failed' Wc_c="`wc -c < 'dict/waei/waei.c'`" test 6663 -eq "$Wc_c" || echo 'dict/waei/waei.c: original size 6663, current size' "$Wc_c" fi # ============= dict/server/Makefile ============== if test ! -d 'dict/server'; then echo 'x - creating directory dict/server' mkdir 'dict/server' fi if test -f 'dict/server/Makefile' -a X"$1" != X"-c"; then echo 'x - skipping dict/server/Makefile (File already exists)' else echo 'x - extracting dict/server/Makefile (Text)' sed 's/^X//' << 'SHAR_EOF' > 'dict/server/Makefile' && #CFLAGS=-Dsparc -g -DDEBUG -DLOGGING CFLAGS=-Dsparc -g -DLOGGING #CFLAGS=-Dsparc -g OBJ=main.o daemon.o util.o EIWA= ../eiwa/eiwa.o WAEI= ../waei/waei.o KOJI= ../kojien/kojien.o all: dserver dserver: $(OBJ) $(EIWA) $(WAEI) $(KOJI) X cc $(CFLAGS) -o dserver $(OBJ) $(WAEI) $(EIWA) $(KOJI) $(OBJ): $(EIWA): X cd ../eiwa; make all "CFLAGS=$(CFLAGS)" $(WAEI): X cd ../waei; make all "CFLAGS=$(CFLAGS)" $(KOJI): X cd ../kojien; make all "CFLAGS=$(CFLAGS)" clean: X rm -f *.o core dserver *‾ X cd ../eiwa; make clean X cd ../waei; make clean X cd ../kojien; make clean lint: X lint -Dsparc *.c SHAR_EOF chmod 0644 dict/server/Makefile || echo 'restore of dict/server/Makefile failed' Wc_c="`wc -c < 'dict/server/Makefile'`" test 579 -eq "$Wc_c" || echo 'dict/server/Makefile: original size 579, current size' "$Wc_c" fi # ============= dict/server/README ============== if test -f 'dict/server/README' -a X"$1" != X"-c"; then echo 'x - skipping dict/server/README (File already exists)' else echo 'x - extracting dict/server/README (Text)' sed 's/^X//' << 'SHAR_EOF' > 'dict/server/README' && DEBUG オプションをつけてコンパイルし, -x 1 で起動するとデバッグモードデーモンが立ち上がる. -x 2 とすると, デーモンにならない. サーバは標準出力に X できる限りのデバッグ表示を行なう. SHAR_EOF chmod 0644 dict/server/README || echo 'restore of dict/server/README failed' Wc_c="`wc -c < 'dict/server/README'`" test 221 -eq "$Wc_c" || echo 'dict/server/README: original size 221, current size' "$Wc_c" fi # ============= dict/server/daemon.c ============== if test -f 'dict/server/daemon.c' -a X"$1" != X"-c"; then echo 'x - skipping dict/server/daemon.c (File already exists)' else echo 'x - extracting dict/server/daemon.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'dict/server/daemon.c' && /* X * Copyright (C) Shingo NISHIOKA, 1991 X * nishioka@sanken.osaka-u.ac.jp X * Everyone is permitted to do anything on this program X * including copying, transplanting, debugging, and modifying. X */ X #include #include #include #include #include #include #ifdef LOGGING #include #endif X #include "ndtp.h" X #ifdef DEBUG extern int debug; #endif X static int ls; /* listen socket */ X iserver_init() { X int s; X struct servent *sp; X struct sockaddr_in myaddr_in; X X bzero((char *)&myaddr_in, sizeof(struct sockaddr_in)); X X myaddr_in.sin_family = AF_INET; X myaddr_in.sin_addr.s_addr = INADDR_ANY; X X sp = getservbyname(SERVICE, "tcp"); X if(sp == NULL) { X perror("Service not found in /etc/services¥n"); X exit(1); X } X myaddr_in.sin_port = sp->s_port; X X ls = socket(AF_INET, SOCK_STREAM, 0); X if(ls == -1) { X perror("Unable to create a socket /iserver_init¥n"); X exit(1); X } X X if( bind(ls, &myaddr_in, sizeof(struct sockaddr_in)) == -1) { X perror("Unable to bind address /iserver_init¥n"); X exit(1); X } X X if(listen(ls, 5) == -1) { X perror("Unable to listen on socket /iserver_init¥n"); X exit(1); X } #ifdef DEBUG X if(debug>=2) { X printf("Listen socket=%d¥n",ls); X } #endif } X static iserver_accept() { X int s, addrlen; X struct sockaddr_in peeraddr_in; X X addrlen = sizeof(struct sockaddr_in); X bzero((char *)&peeraddr_in, addrlen); X X s = accept(ls, &peeraddr_in, &addrlen); X if(s==-1) { X perror("Unable to accept /iserver_accept¥n"); X return -1; X } X return s; } X #define CLNUM 64 X typedef struct _env { X int d; X int authority; X char name[32]; X int dict; X int conv; } ENV; X static ENV env[CLNUM]; static int clnum; X command_loop() { X int width; X fd_set readfds, writefds, exceptfds; X int c; X #ifdef LOGGING X openlog("dserver", LOG_CONS|LOG_NOWAIT, LOG_USER); #endif X clnum=0; X width = getdtablesize(); X for(;;) { X FD_ZERO(&readfds); X FD_ZERO(&writefds); X FD_ZERO(&exceptfds); X FD_SET(ls,&readfds); X for(c=0; c=2) { X printf("%d¥n",new_client); X } #endif X for(c=0; c=2) { X printf("client %d(%d) wants to talk¥n", c,env[c].d); X } #endif X isclosed=process_a_client(&env[c]); X if(isclosed) { #ifdef DEBUG X if(debug>=2) { X printf("Client %d connection closed¥n",c); X } #endif #ifdef LOGGING #ifdef DEBUG X if(debug>=2) { X printf("close connection %s¥n",env[c].name); X } #endif X if(env[c].authority) { X syslog(LOG_ALERT, X "user=%s, stat=Closed connection, conv=%d", X env[c].name, env[c].conv); X } #endif X close(env[c].d); X env[c].d = -1; X strcpy(env[c].name,""); X env[c].authority=0; X } } X #define BUFSIZE 4096 X static process_a_client(p) ENV *p; { X static char buf[BUFSIZE]; X int len; X int s; X X (p->conv)++; X X s = p->d; X len = read(s,buf,BUFSIZE); X buf[len] = '¥0'; #ifdef DEBUG X if(debug>=2) { X printf("%s¥n",buf); X } #endif X if(len==0) return 1; X X /* A, Q and u can be used without authority */ X X switch(buf[0]) { X int i; /* A */ X int c; /* u */ X static char outbuf[128]; /* u */ X case 'A': X p->authority=1; X p->dict = -1; X for(i=0; i<31&&buf[i]!='¥n'; i++) ; X buf[i]='¥0'; X strcpy(p->name,buf+1); X write(s,"$A¥n",3); X #ifdef LOGGING #ifdef DEBUG X if(debug>=2) { X printf("new user %s¥n",p->name); X } #endif X syslog(LOG_ALERT,"user=%s, stat=New connection",p->name); #endif X return 0; X case 'Q': X return 1; X case 'u': X strcpy(outbuf,"$U¥n"); X write(s,outbuf,strlen(outbuf)); X for(c=0; cauthority==0) { X write(s,"$N¥n",3); X return 0; X } X X switch(buf[0]) { X case 'L': X { X char *tmp; X int newdic; #ifdef DEBUG X if(debug>=2) { X fprintf(stderr,"Select dictionary "); X fflush(stderr); X } #endif X for(tmp=buf+1; *tmp && *tmp!='¥n'; tmp++) ; X *tmp = '¥0'; #ifdef DEBUG X if(debug>=2) { X fprintf(stderr,"<%s>¥n",buf+1); X fflush(stderr); X } #endif X if((newdic = select_dict(buf+1))>=0) { X p->dict = newdic; X write(s,"$*¥n",3); X } X else { X write(s,"$&¥n",3); X } X } X break; X case 'p': X if(p->dict==-1) { X write(s,"$<¥n",3); X } X else { X search_pattern(buf+1,s,p->dict); X } X break; X default: X write(s,"$?¥n",3); X break; X } X return 0; } X struct _dict_set { X char *name; X int (*init)(); X int (*set_out)(); X int (*proc_ent)(); }; X int eiwa_init(); int eiwa_set_currout(); int eiwa_process_entry(); int waei_init(); int waei_set_currout(); int waei_process_entry(); int kojien_init(); int kojien_set_currout(); int kojien_process_entry(); X struct _dict_set dict_set[] = { {"eiwa", eiwa_init, X eiwa_set_currout, X eiwa_process_entry}, {"waei", waei_init, X waei_set_currout, X waei_process_entry}, {"kojien", kojien_init, X kojien_set_currout, X kojien_process_entry}}; X dic_inits() { X int i; X for(i=0; i=2) { X fprintf(stderr,"(%d)¥n",i); X fflush(stderr); X } #endif X if(!strcmp(dict_set[i].name,name)) { X return i; X } X } X return -1; } X search_pattern(pattern,s,d) char *pattern; int s,d; { X char *p; X X for(p=pattern; *p && *p!='¥n'; p++) ; X *p = '¥0'; X (*(dict_set[d].set_out))(s); X (*(dict_set[d].proc_ent))(pattern); } SHAR_EOF chmod 0644 dict/server/daemon.c || echo 'restore of dict/server/daemon.c failed' Wc_c="`wc -c < 'dict/server/daemon.c'`" test 6270 -eq "$Wc_c" || echo 'dict/server/daemon.c: original size 6270, current size' "$Wc_c" fi # ============= dict/server/util.c ============== if test -f 'dict/server/util.c' -a X"$1" != X"-c"; then echo 'x - skipping dict/server/util.c (File already exists)' else echo 'x - extracting dict/server/util.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'dict/server/util.c' && /* X * Copyright (C) Shingo NISHIOKA, 1991 X * nishioka@sanken.osaka-u.ac.jp X * Everyone is permitted to do anything on this program X * including copying, transplanting, debugging, and modifying. X */ X #include #include "cdrom.h" X #ifdef DEBUG extern int debug; #endif X seekframe(dic,frame) FILE *dic; int frame; { X X fseek(dic,(frame-1)*FRAMESIZE,0); } X puteucz2h(stream,hi,lo) int stream; unsigned int hi,lo; { X static char buf[32]; X X if(hi==0x23 && X 0x21<=lo && lo<0x7f && X lo!='#') { /* zenkaku mozi -> hankaku mozi */ X sprintf(buf,"%c",lo&0x7f); X } X else if(hi==0x21 && X 0x21<=lo && lo<0x7f) { X switch(lo) { X case 0x21: X strcpy(buf," "); X break; X case 0x47: X strcpy(buf,"'"); X break; X case 0x4a: X strcpy(buf,"("); X break; X case 0x4b: X strcpy(buf,")"); X break; X case 0x4e: X strcpy(buf,"["); X break; X case 0x4f: X strcpy(buf,"]"); X break; X default: X sprintf(buf,"%c%c",hi&0x7f|0x80,lo&0x7f|0x80); X break; X } X } X else if(0x21<=hi && hi<0x7f && X 0x21<=lo && lo<0x7f) { /* JIS kanji mozi */ X sprintf(buf,"%c%c",hi&0x7f|0x80,lo&0x7f|0x80); X } X else if(hi==0xa1) { /* KAIGYOU or character-style control */ X switch(lo) { X case 0x21: X strcpy(buf," "); X break; X case 0x22: /* [ (for eiwa) */ X strcpy(buf," {"); X break; X case 0x23: /* [ (for eiwa) */ X strcpy(buf,"} "); X break; X case 0x25: /* e no hikkuri kaetta yatu (ability)*/ X strcpy(buf,"#e"); X break; X case 0x26: X strcpy(buf,":"); X break; X case 0x27: /* c no gyaku (cotton) */ X strcpy(buf,"#o"); X break; X case 0x28: /* e + r no katamuita yatu (art) */ X strcpy(buf,"#/er/"); X break; X case 0x2a: /* hige no nai a (alms) */ X strcpy(buf,"#a"); X break; X case 0x29: /* ae (ask) */ X strcpy(buf,"#/ae(:)/"); X break; X case 0x30: /* ae (hat) */ X strcpy(buf,"#/ae/"); X break; X case 0x2b: /* s no nagai yatu (ship) */ X strcpy(buf,"#s"); X break; X case 0x2c: /* v no hikkuri kaetta yatu (up) */ X strcpy(buf,"#v"); X break; X case 0x2d: /* measure */ X strcpy(buf,"#g"); X break; X case 0x2e: /* ng */ X strcpy(buf,"#/ng/"); X break; X case 0x2f: /* (think) */ X strcpy(buf,"#t"); X break; X case 0x31: /* (this) */ X strcpy(buf,"#d"); X break; X case 0x35: /* following character has accent */ X strcpy(buf,"#'"); X break; X case 0x36: /* following character has week accent */ X strcpy(buf,"#`"); X break; X case 0x42: X strcpy(buf,"(C)"); X case 0x43: X strcpy(buf,"(U)"); X break; X default: X if(lo>=0x6b) { X /* currently beleived as X 1. beginning of kanji-midasi (waei) X 2. beginning of pronunciation (eiwa) X just ignore. */ X strcpy(buf,""); X } X else { X sprintf(buf,"#x%02x#x%02x",hi,lo); X } X break; X } #ifdef DEBUG X if(debug>=1) { X sprintf(buf,"#x%02x#x%02x",hi,lo); X } #endif X } X else if(hi==0xa2) { /* special control */ X switch(lo) { X case 0x2c: /* ??? (eiwa) */ X strcpy(buf," "); X break; X case 0x2d: /* ??? (eiwa) */ X strcpy(buf," "); X break; X case 0x2e: /* ??? (eiwa) */ X strcpy(buf," "); X break; X X case 0x27: X strcpy(buf,"¥015¥005"); X break; X case 0x28: X strcpy(buf," "); X break; X default: X strcpy(buf,""); #ifdef DEBUG X sprintf(buf,"#x%02x#x%02x",hi,lo); #endif X break; X } #ifdef DEBUG X if(debug>=1) { X sprintf(buf,"#x%02x#x%02x",hi,lo); X } #endif X } X else if(hi==0xa4) { X switch (lo) { X case ';': /* [ */ X sprintf(buf,"%c%c",0x21|0x80,0x58|0x80); X break; X case '<': /* ] */ X sprintf(buf,"%c%c",0x21|0x80,0x59|0x80); X break; X case '>': /* => */ X sprintf(buf,"%c%c",0x22|0x80,0x4d|0x80); X break; X case '&': /* repeat char */ X sprintf(buf,"%c%c",0x21|0x80,0x35|0x80); X break; X case '$': /* repeat1 char */ X sprintf(buf,"%c%c",0x21|0x80,0x39|0x80); X break; X case '#': /* repeat2 char */ X sprintf(buf,"%c%c",0x21|0x80,0x39|0x80); X break; X case 'U': /* bonzi U */ X case 'J': /* ? */ X case '"': X case '*': X case '/': X case '!': X case 'X': X case '6': X case 'C': X sprintf(buf,"%c%c",0x22|0x80,0x23|0x80); X break; X default: X sprintf(buf,"#xa4#x%02x",lo); X break; X } #ifdef DEBUG X if(debug>=1) { X sprintf(buf,"#x%02x#x%02x",hi,lo); X } #endif X } X else if(hi==0x00) { X switch(lo) { X case 0x00: /* begin midasi */ X case 0x01: /* end entry */ X strcpy(buf,""); X break; X case 0x02: /* begin body */ X strcpy(buf,"¥015¥005"); X break; X case 0x05: /* next-paragraph (kojien) */ X strcpy(buf,"¥015¥005"); X break; X default: X strcpy(buf,""); #ifdef DEBUG X sprintf(buf,"#x%02x#x%02x",hi,lo); #endif X break; X } #ifdef DEBUG X if(debug>=1) { X sprintf(buf,"#x%02x#x%02x",hi,lo); X } #endif X } X else if(hi==0x01) { /* special contorl? just ignore, now */ X switch(lo) { X case 0x30: /* begin hiragana midasi (kojien) */ X strcpy(buf,""); X break; X default: X strcpy(buf,""); #ifdef DEBUG X sprintf(buf,"#x%02x#x%02x",hi,lo); #endif #ifdef DEBUG X if(debug>=1) { X sprintf(buf,"#x%02x#x%02x",hi,lo); X } #endif X } X } X else if(hi==0x02) { /* special contorl? just ignore, now */ X switch(lo) { X case 0x60: /* begin midasi (kojien) */ X strcpy(buf,""); X break; X default: X strcpy(buf,""); #ifdef DEBUG X sprintf(buf,"#x%02x#x%02x",hi,lo); #endif X break; X } #ifdef DEBUG X if(debug>=1) { X sprintf(buf,"#x%02x#x%02x",hi,lo); X } #endif X } X else { X sprintf(buf,"#x%02x#x%02x",hi,lo); X } X write(stream,buf,strlen(buf)); } X jisstrsub(s,t) unsigned char *s, *t; { X unsigned int ss,tt; X for(; ; s+=2,t+=2) { X ss = (*s&0x7f<<8)|(*(s+1)&0x7f); X tt = (*t&0x7f<<8)|(*(t+1)&0x7f); X /* We must exit only here, X as ss & tt must be are calculated in every case. */ X if(!ss || !tt || ss!=tt) break; X } X return ss-tt; } X han2zen(h,z) char *h,*z; { X for(; *h; h++) { X if('A'<=*h && *h<='Z' || X '0'<=*h && *h<='9') { X *z++ = 0x23; X *z++ = *h; X } X else if(*h=='*' || *h=='?') { X *z++ = '¥0'; X *z++ = *h; X } X } X *z++='¥0'; X *z++='¥0'; } X nstringupcase(s) char *s; { X for(; *s; s++) { X if('a'<=*s && *s<='z') { X *s = *s-'a'+'A'; X } X } } X neuc2jis(s) char *s; { X for(; *s; s++) { X *s &= 0x7f; X } } X struct _conv_tbl { X int oldhi,oldlo; X int newhi,newlo; }; X struct _conv_tbl conv_tbl[] = { {0x24,0x21, 0x24,0x22}, /* a */ {0x24,0x23, 0x24,0x24}, /* i */ {0x24,0x25, 0x24,0x26}, /* u */ {0x24,0x27, 0x24,0x28}, /* e */ {0x24,0x29, 0x24,0x2a}, /* o */ {0x24,0x43, 0x24,0x44}, /* tu */ {0x24,0x63, 0x24,0x64}, /* ya */ {0x24,0x65, 0x24,0x66}, /* yu */ {0x24,0x67, 0x24,0x68}, /* yo */ {0x24,0x6e, 0x24,0x6f}, /* wa */ X {0x24,0x2c, 0x24,0x2b}, /* ga */ {0x24,0x2e, 0x24,0x2d}, /* gi */ {0x24,0x30, 0x24,0x2f}, /* gu */ {0x24,0x32, 0x24,0x31}, /* ge */ {0x24,0x34, 0x24,0x33}, /* go */ X {0x24,0x36, 0x24,0x35}, /* za */ {0x24,0x38, 0x24,0x37}, /* zi */ {0x24,0x3a, 0x24,0x39}, /* zu */ {0x24,0x3c, 0x24,0x3b}, /* ze */ {0x24,0x3e, 0x24,0x3d}, /* zo */ X {0x24,0x40, 0x24,0x3f}, /* da */ {0x24,0x42, 0x24,0x41}, /* di */ {0x24,0x45, 0x24,0x44}, /* du */ {0x24,0x47, 0x24,0x46}, /* de */ {0x24,0x49, 0x24,0x48}, /* do */ X {0x24,0x50, 0x24,0x4f}, /* ba */ {0x24,0x53, 0x24,0x52}, /* bi */ {0x24,0x56, 0x24,0x55}, /* bu */ {0x24,0x59, 0x24,0x58}, /* be */ {0x24,0x5c, 0x24,0x5b}, /* bo */ X {0x24,0x51, 0x24,0x4f}, /* pa */ {0x24,0x54, 0x24,0x52}, /* pi */ {0x24,0x57, 0x24,0x55}, /* pu */ {0x24,0x5a, 0x24,0x58}, /* pe */ {0x24,0x5d, 0x24,0x5b}, /* po */ }; X njisnormalize(s) unsigned char *s; { X for(; *s||*(s+1); s+=2) { X unsigned int hi,lo; X int i; X X hi = *s&0x7f, lo = *(s+1)&0x7f; X if(hi==0x25) { /* first, katakana->hirakana */ X if(lo==0x75) { /* ka */ X *s = 0x24, *(s+1)=0x2b; X } X else if(lo==0x76) { /* ke */ X *s = 0x24, *(s+1)=0x31; X } X else { /* katakana->hirakana */ X *s = 0x24; X } X } X X /* next, try small hirakana->normal hirakana */ X /* this operation must follow the katakana->hirakana */ X /* as the previous operation may generate small hirakana */ X hi = *s&0x7f, lo = *(s+1)&0x7f; X for(i=0; i 'dict/server/main.c' && /* X * Copyright (C) Shingo NISHIOKA, 1991 X * nishioka@sanken.osaka-u.ac.jp X * Everyone is permitted to do anything on this program X * including copying, transplanting, debugging, and modifying. X */ X #include #include #include X #ifdef DEBUG int debug; #endif X main(argc,argv) int argc; char *argv[]; { X char *dfile, *ifile; X char *com; X int tmpttyfd; X #ifdef DEBUG X if(argc!=2) { X fprintf(stderr,"Usage: %s [0-2]¥n",argv[0]); X exit(1); X } X X debug = atoi(argv[1]); X fprintf(stderr,"Debug Level: %d¥n",debug); #endif X #ifdef DEBUG X if(debug>=2) { #endif X setuid(geteuid()); X if ((tmpttyfd = open("/dev/tty", O_RDWR)) >= 0) { X ioctl(tmpttyfd, TIOCNOTTY, 0); X close(tmpttyfd); X } #ifdef DEBUG X } #endif X X iserver_init(); X dic_inits(); X command_loop(); } SHAR_EOF chmod 0644 dict/server/main.c || echo 'restore of dict/server/main.c failed' Wc_c="`wc -c < 'dict/server/main.c'`" test 852 -eq "$Wc_c" || echo 'dict/server/main.c: original size 852, current size' "$Wc_c" fi # ============= dict/server/cdrom.h ============== if test -f 'dict/server/cdrom.h' -a X"$1" != X"-c"; then echo 'x - skipping dict/server/cdrom.h (File already exists)' else echo 'x - extracting dict/server/cdrom.h (Text)' sed 's/^X//' << 'SHAR_EOF' > 'dict/server/cdrom.h' && /* X * Copyright (C) Shingo NISHIOKA, 1991 X * nishioka@sanken.osaka-u.ac.jp X * Everyone is permitted to do anything on this program X * including copying, transplanting, debugging, and modifying. X */ X #define FRAMESIZE 2048 SHAR_EOF chmod 0644 dict/server/cdrom.h || echo 'restore of dict/server/cdrom.h failed' Wc_c="`wc -c < 'dict/server/cdrom.h'`" test 282 -eq "$Wc_c" || echo 'dict/server/cdrom.h: original size 282, current size' "$Wc_c" fi # ============= dict/server/ndtp.h ============== if test -f 'dict/server/ndtp.h' -a X"$1" != X"-c"; then echo 'x - skipping dict/server/ndtp.h (File already exists)' else echo 'x - extracting dict/server/ndtp.h (Text)' sed 's/^X//' << 'SHAR_EOF' > 'dict/server/ndtp.h' && /* X * Copyright (C) Shingo NISHIOKA, 1991 X * nishioka@sanken.osaka-u.ac.jp X * Everyone is permitted to do anything on this program X * including copying, transplanting, debugging, and modifying. X */ X #ifdef DEBUG #define SERVICE "ndtp-debug" #else #define SERVICE "ndtp" #endif SHAR_EOF chmod 0644 dict/server/ndtp.h || echo 'restore of dict/server/ndtp.h failed' Wc_c="`wc -c < 'dict/server/ndtp.h'`" test 337 -eq "$Wc_c" || echo 'dict/server/ndtp.h: original size 337, current size' "$Wc_c" fi true || echo 'restore of dict/INSTALL failed' echo End of part 1, continue with part 2 exit 0 -- 西岡@産研.大阪大学 nishioka@ei.sanken.osaka-u.ac.jp