/* * * fwindex.c * * 14 Feb. 1997 by E.Terakawa * */ /* This file is part of VFlib * * Copyright (C) 1995 Hirotsugu KAKUGAWA. All rights reserved. * * VFlib is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY. No author or distributor accepts responsibility * to anyone for the consequences of using it or for whether it serves any * particular purpose or works at all, unless he says so in writing. Refer * to the GNU General Public License for full details. * * Everyone is granted permission to copy, modify and redistribute * VFlib, but only under the conditions described in the GNU * General Public License. A copy of this license is supposed to have been * given to you along with VFlib so you can know your rights and * responsibilities. It should be in a file named COPYING. Among other * things, the copyright notice and this notice must be preserved on all * copies. */ #include #include #include #include "fwindex.h" #ifndef SEEK_SET # define SEEK_SET 0 #endif #ifndef SEEK_END # define SEEK_END 2 #endif #define BUFSIZE (16*1024) unsigned char buf[BUFSIZE+4],buf2[4],tategaki[(0x5e*(0x26-0x21+1)+7)/8]; int address_table[10000],first_byte[10000]; int first_byte_count[256],first_byte_table2[256]; void set_word(unsigned char *p,int b,unsigned int d){ p[b]=d & 0xff; p[b+1]=(d>>8)& 0xff; } void set_dword(unsigned char *p,int b,unsigned long d){ p[b]=d & 0xff; p[b+1]=(d>>8)& 0xff; p[b+2]=(d>>16)& 0xff; p[b+3]=d>>24; } int issjis1(unsigned char c){ if(((0x81<=c)&&(c<=0x9f))||((0xe0<=c)&&(c<=0xef)))return -1; else return 0; } int issjis2(unsigned char c){ if((0x40<=c)&&(c<=0xfc)&&(c!=0x7f))return -1; else return 0; } unsigned int sjistojis(unsigned int s){ int b1,b2; b1=(s>>8)& 0xff; b2=s & 0xff; if(!issjis1(b1)||!issjis2(b2))return 0; if(b1>=0xe0)b1-=0x40; b1-=0x71; b1*=2; b1++; if(b2<=0x9e){ if(b2>=0x80)b2--; b2-=0x1f; }else{ b2-=0x7e; b1++; } return b1*0x100+b2; } int iskana(unsigned char c){ if((0xa1<=c)&&(c<=0xdf))return 1; else return 0; } void convsjistoeuc(unsigned char *sjis,unsigned char *euc){ int i,j,len,code; len=strlen(sjis); j=0; for(i=0;i> 8)&0xff)|0x80; euc[j++]=(code & 0xff)|0x80; i++; }else{ if(iskana(sjis[i])) euc[j++]=0x8e; euc[j++]=sjis[i]; } } euc[j++]=0; } int main(int argc,char *argv[]){ FILE *infile,*outfile; unsigned char filename[256],szbuf[256],fontname[256]; char *p; int argcount,count; int infilesize; int startpoint,endpoint,seekpoint,bufhead; int len,jis,font_data_start,table2_start; int i,j,tmp,flag; int OptionDebug,OptionList; if(argc<2){ printf("USAGE: fwindex filename[.fws]\n"); exit(-1); } argcount=1; OptionDebug=OptionList=0; while(argcount>8; first_byte_count[jis>>8]++; /*縦書き用が別に用意されている文字のテーブルを作る*/ if((jis>=0x2121)&&(jis<0x2600)&&(jis & 0x80)){ int tmp; tmp= ((jis >> 8) - 0x21)*0x5e + (jis & 0x7f) - 0x21; tategaki[tmp / 8]|=(1 << (tmp & 7)); } seekpoint=endpoint-4; /* printf("startpoint: %08X(%d)\n",startpoint,startpoint);*/ } } } /* 一番最初の文字データの先頭を探す */ bufhead=((startpoint-2)/BUFSIZE)*BUFSIZE; fseek(infile,bufhead,SEEK_SET); fread(buf,1,BUFSIZE,infile); endpoint=startpoint-bufhead; if(buf[endpoint-1]!=0xf){ printf("ERROR: Cannot handle this format!\n"); exit(-1); } seekpoint=endpoint-2; while(1){ seekpoint--; if(seekpoint<0){ int i; bufhead-=BUFSIZE; if(bufhead<0){ startpoint=-1; break; } for(i=0;i<4;i++)buf[BUFSIZE+i]=buf[i]; fseek(infile,bufhead,SEEK_SET); fread(buf,1,BUFSIZE,infile); seekpoint+=BUFSIZE; endpoint+=BUFSIZE; printf("bufhead: %08X(%d)\n",bufhead,bufhead); } len=buf[seekpoint]+buf[seekpoint+1]*256; /* printf("seek:%04X len:%04X\n",seekpoint,len);*/ if(seekpoint+len==endpoint){ startpoint=bufhead+seekpoint-2; j=0; flag=0; do{ fseek(infile,startpoint-5*j-4,SEEK_SET); fread(buf2,1,4,infile); tmp=buf2[0]+buf2[1]*0x100+buf2[2]*0x10000+buf2[3]*0x1000000; if(tmp!=0){ flag=1; break; } j++; }while(j0x400){ strcpy(filename,argv[argcount]); if((p=strstr(filename,".fws"))==NULL) strcat(filename,".tex"); else strcpy(p,".tex"); if((outfile=fopen(filename,"wb"))==NULL){ printf("%s :Cannot Open File!\n",filename); exit(-1); } p=strstr(filename,".tex"); *p=0; i=strlen(filename)-1; while(i>=0){ if(filename[i]=='/'){ i++; break; } i--; } if(i<0)i=0; p=&filename[i]; fseek(infile,table2_start - count * 0x22,SEEK_SET); fprintf(outfile,"\\documentstyle[12pt,a4j]{jarticle}\n"); fprintf(outfile,"\\font\\twty%s=%s at 20pt\n",p,p); fprintf(outfile,"\\begin{document}\n"); fprintf(outfile,"\\twtymin %s \\\\\n",fontname); for(i=0;i