diff options
Diffstat (limited to 'Build/source')
-rw-r--r-- | Build/source/texk/makejvf/ChangeLog | 9 | ||||
-rw-r--r-- | Build/source/texk/makejvf/Makefile.am | 3 | ||||
-rw-r--r-- | Build/source/texk/makejvf/Makefile.in | 9 | ||||
-rw-r--r-- | Build/source/texk/makejvf/main.c | 44 | ||||
-rw-r--r-- | Build/source/texk/makejvf/makejvf.h | 4 | ||||
-rw-r--r-- | Build/source/texk/makejvf/uniblock.c | 46 | ||||
-rw-r--r-- | Build/source/texk/makejvf/uniblock.h | 5 | ||||
-rw-r--r-- | Build/source/texk/makejvf/usrtable.c | 125 | ||||
-rw-r--r-- | Build/source/texk/makejvf/usrtable.h | 23 | ||||
-rw-r--r-- | Build/source/texk/makejvf/version.h | 2 | ||||
-rw-r--r-- | Build/source/texk/makejvf/write.c | 47 |
11 files changed, 273 insertions, 44 deletions
diff --git a/Build/source/texk/makejvf/ChangeLog b/Build/source/texk/makejvf/ChangeLog index 1f663f8cefe..00a0e846ea4 100644 --- a/Build/source/texk/makejvf/ChangeLog +++ b/Build/source/texk/makejvf/ChangeLog @@ -1,3 +1,12 @@ +2017-08-28 TANAKA Takuji <ttk@t-lab.opal.ne.jp> + + makejvf version 20170828. + Largely contributed by H. Yamashita-san. + * usrtable.[ch]: New files to support a configuration file. + * main.c, write.c, uniblock.[ch], makejvf.h: Support a configuration file. + * Makefile.{am,in}: Add usrtable.[ch]. + * version.h: Bump version. + 2017-08-01 Hironobu Yamashita <h.y.acetaminophen@gmail.com> makejvf version 20170801. diff --git a/Build/source/texk/makejvf/Makefile.am b/Build/source/texk/makejvf/Makefile.am index 27826b46b6f..ad23d348e11 100644 --- a/Build/source/texk/makejvf/Makefile.am +++ b/Build/source/texk/makejvf/Makefile.am @@ -10,7 +10,8 @@ AM_CFLAGS = $(WARNING_CFLAGS) bin_PROGRAMS = makejvf makejvf_SOURCES = \ - main.c makejvf.h tfmread.c tool.c uniblock.c uniblock.h version.h write.c + main.c makejvf.h tfmread.c tool.c \ + uniblock.c uniblock.h usrtable.c usrtable.h version.h write.c $(makejvf_OBJECTS): $(KPATHSEA_DEPEND) $(PTEXENC_DEPEND) diff --git a/Build/source/texk/makejvf/Makefile.in b/Build/source/texk/makejvf/Makefile.in index 33f3d6f89f5..659c044455b 100644 --- a/Build/source/texk/makejvf/Makefile.in +++ b/Build/source/texk/makejvf/Makefile.in @@ -113,8 +113,9 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)" PROGRAMS = $(bin_PROGRAMS) -am_makejvf_OBJECTS = main.$(OBJEXT) tfmread.$(OBJEXT) tool.$(OBJEXT) \ - uniblock.$(OBJEXT) write.$(OBJEXT) +am_makejvf_OBJECTS = main.$(OBJEXT) tfmread.$(OBJEXT) \ + tool.$(OBJEXT) uniblock.$(OBJEXT) usrtable.$(OBJEXT) \ + write.$(OBJEXT) makejvf_OBJECTS = $(am_makejvf_OBJECTS) makejvf_LDADD = $(LDADD) am__DEPENDENCIES_1 = @@ -549,7 +550,8 @@ top_srcdir = @top_srcdir@ AM_CPPFLAGS = $(PTEXENC_INCLUDES) $(KPATHSEA_INCLUDES) AM_CFLAGS = $(WARNING_CFLAGS) makejvf_SOURCES = \ - main.c makejvf.h tfmread.c tool.c uniblock.c uniblock.h version.h write.c + main.c makejvf.h tfmread.c tool.c \ + uniblock.c uniblock.h usrtable.c usrtable.h version.h write.c LDADD = $(PTEXENC_LIBS) $(KPATHSEA_LIBS) EXTRA_DIST = COPYRIGHT COPYRIGHT.jis Changes.txt README.txt \ @@ -676,6 +678,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tfmread.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tool.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uniblock.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/usrtable.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/write.Po@am__quote@ .c.o: diff --git a/Build/source/texk/makejvf/main.c b/Build/source/texk/makejvf/main.c index 4d3c3f63516..14ff442aba4 100644 --- a/Build/source/texk/makejvf/main.c +++ b/Build/source/texk/makejvf/main.c @@ -3,27 +3,28 @@ #include "version.h" #include "makejvf.h" #include "uniblock.h" +#include "usrtable.h" #include <stdio.h> #include <stdlib.h> #include <string.h> FILE *vfp,*afp=NULL; -char *atfmname,*vtfmname,*afmname,*vfname,*kanatfm,*jistfm,*ucsqtfm; +char *atfmname,*vtfmname,*afmname,*vfname,*kanatfm,*jistfm,*ucsqtfm,*usertable; int kanatume=-1,chotai=0,baseshift=0,minute=0,useset3=0,hankana=0,fidzero=0,enhanced=0; int pstfm_nt; long ucs=0; int main(int argc, char ** argv) { - int i,j,ib; + int i,j; int c; - long ch; + long ch,ch_max; kpse_set_program_name(argv[0], "makejvf"); set_enc_string("sjis", "euc"); - while ((c = getopt (argc, argv, "k:K:Ca:b:mu:3J:U:Hie")) != -1) + while ((c = getopt (argc, argv, "k:K:Ca:b:mu:3J:U:Hiet:")) != -1) switch (c) { @@ -67,8 +68,10 @@ int main(int argc, char ** argv) ucs = ENTRY_J; else if (!strcmp(optarg, "ks")) ucs = ENTRY_K; + else if (!strcmp(optarg, "custom")) + ucs = ENTRY_CUSTOM; else { - fprintf(stderr,"Charset is not set\n"); + fprintf(stderr,"[Warning] Charset is not set.\n"); ucs = ENTRY_NO; } break; @@ -90,6 +93,9 @@ int main(int argc, char ** argv) case 'e': enhanced=1; break; + case 't': + usertable = xstrdup(optarg); + break; default: usage(); exit(0); @@ -125,17 +131,30 @@ int main(int argc, char ** argv) tfmget(atfmname); + if (usertable) { + get_usertable(usertable); + } + if (ucs!=ENTRY_CUSTOM && usertable_charset_max>0) { + fprintf(stderr, + "[Warning] Custom charset is defined in usertable\n" + "[Warning] but it will be ignored.\n"); + } + if (ucs==ENTRY_CUSTOM && usertable_charset_max<1) { + fprintf(stderr,"No custom charset definition in usertable.\n"); + exit(101); + } + vfp = vfopen(vfname); pstfm_nt=1; /* initialize */ if (ucs) { - ib=0; - for (i=0;i<(useset3*2+1);i++) - for (j=0;j<65536;j++) { - ch=i*65536+j; - if (search_cjk_entry(&ib,ch,ucs)) - writevfu(ch,vfp); - } + if (ucs==ENTRY_CUSTOM) ch_max=usertable_charset[usertable_charset_max-1].max; + else if (useset3) ch_max=0x2FFFF; + else ch_max=0xFFFF; + for (ch=0;ch<=ch_max;ch++) { + if (search_cjk_entry(ch,ucs)) + writevfu(ch,vfp); + } } else { for (i=0;i<94;i++) for (j=0;j<94;j++) @@ -196,5 +215,6 @@ void usage(void) fputs2("-i font ID from No.0\n", stderr); fputs2("-e enhanced mode; the horizontal shift amount is determined\n", stderr); fputs2(" from the glue/kern table of <TFMfile> input\n", stderr); + fputs2("-t <CNFfile> use <CNFfile> as a configuration file\n", stderr); fprintf(stderr, "Email bug reports to %s.\n", BUG_ADDRESS); } diff --git a/Build/source/texk/makejvf/makejvf.h b/Build/source/texk/makejvf/makejvf.h index 62b3b94fef8..040860b37d0 100644 --- a/Build/source/texk/makejvf/makejvf.h +++ b/Build/source/texk/makejvf/makejvf.h @@ -1,6 +1,4 @@ - - -extern char *vtfmname,*kanatfm,*jistfm,*ucsqtfm; +extern char *vtfmname,*kanatfm,*jistfm,*ucsqtfm,*usertable; extern int unit,zh,zw,jfm_id,rightamount; extern int kanatume,chotai,baseshift,minute,hankana,fidzero,enhanced; extern int pstfm_nt; diff --git a/Build/source/texk/makejvf/uniblock.c b/Build/source/texk/makejvf/uniblock.c index 6aa14b1301e..ef35d236d7e 100644 --- a/Build/source/texk/makejvf/uniblock.c +++ b/Build/source/texk/makejvf/uniblock.c @@ -1,10 +1,12 @@ +#include "uniblock.h" +#include "usrtable.h" #ifdef DEBUG #include <stdio.h> +int usertable_charset_max=0; +struct USERTABLE_CHARSET usertable_charset[MAX_CHAR_TABLE]; #endif -#include "uniblock.h" - int uniblock_iskanji; struct ublock { long min, max, cjk; @@ -306,34 +308,48 @@ static struct ublock ublock_data[] = { }; -int search_cjk_entry(int *ib, long ch, long cjk) { +int search_cjk_entry(long ch, long cjk) { + static int ib = 0, ic = 0; uniblock_iskanji = 0; /* initialize */ - if (cjk==ENTRY_NO) return 1; if (cjk==ENTRY_JQ) return (ch==U_OPEN_SQUOTE || ch==U_CLOSE_SQUOTE || ch==U_OPEN_DQUOTE || ch==U_CLOSE_DQUOTE); - while(ublock_data[*ib].max<ch) (*ib)++; - if (ublock_data[*ib].min<=ch && ch<=ublock_data[*ib].max) { - uniblock_iskanji = ublock_data[*ib].kanji; - return ublock_data[*ib].cjk & cjk; + while(ublock_data[ib].max<ch) ib++; + if (ublock_data[ib].min<=ch && ch<=ublock_data[ib].max) + uniblock_iskanji = ublock_data[ib].kanji; + if (cjk==ENTRY_NO) { + return 1; + } else if (cjk==ENTRY_CUSTOM) { + while(usertable_charset[ic].max<ch) ic++; + return (usertable_charset[ic].min<=ch && ch<=usertable_charset[ic].max); + } else if (ublock_data[ib].min<=ch && ch<=ublock_data[ib].max) { + return ublock_data[ib].cjk & cjk; } else { return 0; } } +/* for unit test */ +/* ex. $ gcc -g -o uniblock.test uniblock.c -DDEBUG */ #ifdef DEBUG int main() { long ch; - int ib; - ib=0; + /* trial inputs */ + usertable_charset_max=2; + usertable_charset[0].min=0xFFF0; + usertable_charset[0].max=0xFFF3; + usertable_charset[1].min=0xFFF8; + usertable_charset[1].max=0xFFFB; + for (ch=0x0;ch<0x10000;ch++) { - printf(" %05x %2d %2d %2d %2d %2d\n", ch, ib, - search_cjk_entry(&ib,ch,ENTRY_G), - search_cjk_entry(&ib,ch,ENTRY_C), - search_cjk_entry(&ib,ch,ENTRY_J), - search_cjk_entry(&ib,ch,ENTRY_K)); + printf(" %05x %1d G:%2d C:%2d J:%2d K:%2d custom:%2d\n", ch, uniblock_iskanji, + search_cjk_entry(ch,ENTRY_G), + search_cjk_entry(ch,ENTRY_C), + search_cjk_entry(ch,ENTRY_J), + search_cjk_entry(ch,ENTRY_K), + search_cjk_entry(ch,ENTRY_CUSTOM)); } } diff --git a/Build/source/texk/makejvf/uniblock.h b/Build/source/texk/makejvf/uniblock.h index a92fb2a0f2a..c327d2bff8c 100644 --- a/Build/source/texk/makejvf/uniblock.h +++ b/Build/source/texk/makejvf/uniblock.h @@ -1,8 +1,9 @@ #define ENTRY_NO 0x01 +#define ENTRY_CUSTOM 0x10000 /* for JIS, quote only */ -/* for GB, CNS, JIS, KS */ #define ENTRY_JQ 0x1000 +/* for GB, CNS, JIS, KS */ #define ENTRY_G 0x02 #define ENTRY_C 0x04 #define ENTRY_J 0x08 @@ -19,7 +20,7 @@ #define ENTRY_CJK ENTRY_C|ENTRY_J|ENTRY_K #define ENTRY_GCJK ENTRY_G|ENTRY_C|ENTRY_J|ENTRY_K -extern int search_cjk_entry(int *ib, long ch, long cjk); +extern int search_cjk_entry(long ch, long cjk); extern int uniblock_iskanji; #define U_OPEN_SQUOTE 0x2018 diff --git a/Build/source/texk/makejvf/usrtable.c b/Build/source/texk/makejvf/usrtable.c new file mode 100644 index 00000000000..1b9c070a499 --- /dev/null +++ b/Build/source/texk/makejvf/usrtable.c @@ -0,0 +1,125 @@ +#ifndef DEBUG +#include <kpathsea/config.h> +#include "makejvf.h" +#endif + +#include "usrtable.h" + +#include <stdio.h> +#include <stdlib.h> +#ifdef DEBUG +#include <string.h> +#endif + +int usertable_replace_max=0,usertable_move_max=0,usertable_charset_max=0; +struct USERTABLE_REPLACE usertable_replace[MAX_TABLE]; +struct USERTABLE_MOVE usertable_move[MAX_TABLE]; +struct USERTABLE_CHARSET usertable_charset[MAX_CHAR_TABLE]; + +void get_usertable(char *name) +{ + FILE *fp; + char *tok,*endptr,buf[BUF_SIZE],str0[8],str1[8]; + int charset_mode=0,l; + long char_max=-2,ch0,ch1; + + fp = fopen(name,"r"); + if (fp == NULL) { + fprintf(stderr,"Cannot find %s!\n",name); + exit(1); + } + for (l = 0; fgets(buf, BUF_SIZE, fp) != NULL; l++) { + if (endptr=strchr(buf, '%')) strcpy(endptr,"\n"); /* ignore after '%' */ + if (!strncmp(buf, "\n", 1)) continue; /* ignore empty line */ + tok = strtok(buf, "\t"); + if (!strcmp(tok, "REPLACE")) { + if (usertable_replace_max >= MAX_TABLE) goto buferr; + usertable_replace[usertable_replace_max].codepoint = strtol(strtok(NULL, "\t\n"), &endptr, 16); + if (*endptr != '\0') goto taberr; + usertable_replace[usertable_replace_max].newcodepoint = strtol(strtok(NULL, "\t\n"), &endptr, 16); + if (*endptr != '\0') goto taberr; + if (strtok(NULL, "\t\n") != NULL) goto taberr; + usertable_replace_max++; + continue; + } + if (!strcmp(tok, "MOVE")) { + if (usertable_move_max >= MAX_TABLE) goto buferr; + usertable_move[usertable_move_max].codepoint = strtol(strtok(NULL, "\t\n"), &endptr, 16); + if (*endptr != '\0') goto taberr; + usertable_move[usertable_move_max].moveright = strtod(strtok(NULL, "\t\n"), &endptr); + if (*endptr != '\0') goto taberr; + usertable_move[usertable_move_max].movedown = strtod(strtok(NULL, "\t\n"), &endptr); + if (*endptr != '\0') goto taberr; + if (strtok(NULL, "\t\n") != NULL) goto taberr; + usertable_move_max++; + continue; + } + if ((!strcmp(tok, "+") && charset_mode) || !strcmp(tok, "CHARSET")) { + charset_mode = 1; + while (tok=strtok(NULL, ",\t\n")) { + if (endptr=strstr(tok,"..")) { + *endptr = '\0'; + if (sscanf(tok, "%7s",str0) != 1) goto taberr; + if (sscanf(endptr+2,"%7s",str1) != 1) goto taberr; + ch0 = strtol(str0, &endptr, 16); + if (*endptr != '\0' || ch0<=char_max) goto taberr; + ch1 = strtol(str1, &endptr, 16); + if (*endptr != '\0' || ch1<=ch0) goto taberr; + } else { + if (sscanf(tok,"%7s",str0) != 1) goto taberr; + ch0 = strtol(str0, &endptr, 16); + if (*endptr != '\0' || ch0<=char_max) goto taberr; + ch1 = ch0; + } + if (char_max==ch0-1) { + usertable_charset[usertable_charset_max-1].max = ch1; + } else { + if (usertable_charset_max >= MAX_CHAR_TABLE) goto buferr; + usertable_charset[usertable_charset_max].min = ch0; + usertable_charset[usertable_charset_max].max = ch1; + usertable_charset_max++; + } + char_max = ch1; + } + continue; + } + fprintf(stderr, "Unknown setting %s found in %s (line %d)!\n", tok, name, l+1); + exit(1); + } + fclose(fp); + return; +taberr: + fprintf(stderr, "Error in user-defined table file %s (line %d)!\n", name, l+1); + exit(1); +buferr: + fprintf(stderr, "User-defined table in %s is too large!\n", name); + exit(1); +} + + +/* for unit test */ +/* ex. $ gcc -g -o usrtable.test usrtable.c -DDEBUG */ +#ifdef DEBUG +int main() { + int i; + long ch0,ch1; + char name[]="test_user_table"; + get_usertable(name); + + if (usertable_replace_max>0) { + printf("REPLACE::\n"); + for(i=0;i<usertable_replace_max;i++) + printf("%6d: %06x -> %06x\n", i, usertable_replace[i].codepoint, usertable_replace[i].newcodepoint); + } + if (usertable_move_max>0) { + printf("MOVE::\n"); + for(i=0;i<usertable_move_max;i++) + printf("%6d: %06x | %lf, %lf\n", i, usertable_move[i].codepoint, usertable_move[i].moveright, usertable_move[i].movedown); + } + if (usertable_charset_max>0) { + printf("CHARSET::\n"); + for(i=0;i<usertable_charset_max;i++) + printf("%6d: %06x .. %06x\n", i, usertable_charset[i].min, usertable_charset[i].max); + } +} +#endif diff --git a/Build/source/texk/makejvf/usrtable.h b/Build/source/texk/makejvf/usrtable.h new file mode 100644 index 00000000000..61343ff8040 --- /dev/null +++ b/Build/source/texk/makejvf/usrtable.h @@ -0,0 +1,23 @@ +#define BUF_SIZE 1024 +#define MAX_TABLE 1024 +#define MAX_CHAR_TABLE 32768 +extern int usertable_replace_max,usertable_move_max,usertable_charset_max; + +struct USERTABLE_REPLACE { + int codepoint; + int newcodepoint; +}; +extern struct USERTABLE_REPLACE usertable_replace[]; +struct USERTABLE_MOVE { + int codepoint; + double moveright; + double movedown; +}; +extern struct USERTABLE_MOVE usertable_move[]; +struct USERTABLE_CHARSET { + long min, max; +}; +extern struct USERTABLE_CHARSET usertable_charset[]; + +/* usrtable.c */ +void get_usertable(char *name); diff --git a/Build/source/texk/makejvf/version.h b/Build/source/texk/makejvf/version.h index fee2a5685d6..7c88826cc8d 100644 --- a/Build/source/texk/makejvf/version.h +++ b/Build/source/texk/makejvf/version.h @@ -1,2 +1,2 @@ -#define VERSION "20170801" +#define VERSION "20170828" #define BUG_ADDRESS "issue@texjp.org" diff --git a/Build/source/texk/makejvf/write.c b/Build/source/texk/makejvf/write.c index 5d41b26c6f5..dae91045ec6 100644 --- a/Build/source/texk/makejvf/write.c +++ b/Build/source/texk/makejvf/write.c @@ -1,6 +1,7 @@ #include <kpathsea/config.h> #include "makejvf.h" #include "uniblock.h" +#include "usrtable.h" #include <stdio.h> #include <stdlib.h> @@ -85,7 +86,8 @@ void writevf(int code, FILE *fp) { int cc,cc2,cc3,cc4,w,skip=0,skip2=0,height=1000; char buf[256],buf2[256]; - int fidshift=0; + int fidshift=0,l; + int outcode=code; if (fidzero) fidshift=-1; @@ -306,6 +308,19 @@ void writevf(int code, FILE *fp) break; } + for (l = 0; l < usertable_replace_max; l++) { + if (code == usertable_replace[l].codepoint) { + outcode = usertable_replace[l].newcodepoint; + break; + } + } + for (l = 0; l < usertable_move_max; l++) { + if (code == usertable_move[l].codepoint) { + skip = usertable_move[l].moveright * zw; + skip2 = usertable_move[l].movedown * zh; + goto outputj; + } + } if (skip != -rightamount && enhanced) { fprintf(stderr, "[Warning] Conflicting MOVERIGHT value for code %x,\n" @@ -314,6 +329,8 @@ void writevf(int code, FILE *fp) code, skip, -rightamount); skip=-rightamount; } + +outputj: if (kanatfm) cc=4; else @@ -340,14 +357,15 @@ void writevf(int code, FILE *fp) fputc(172+fidshift,fp); /* FONT_NUM_1 */ } fputc(129,fp); /* SET2 */ - fputnum(code,2,fp); /* char code */ + fputnum(outcode,2,fp); /* char code */ } void writevfu(int code, FILE *fp) { int cc,cc2,cc3,cc4,w,skip=0,skip2=0,height=1000; char buf[256],buf2[256]; - int fidshift=0; + int fidshift=0,l; + int outcode=code; if (fidzero) fidshift=-1; @@ -691,6 +709,19 @@ void writevfu(int code, FILE *fp) break; } + for (l = 0; l < usertable_replace_max; l++) { + if (code == usertable_replace[l].codepoint) { + outcode = usertable_replace[l].newcodepoint; + break; + } + } + for (l = 0; l < usertable_move_max; l++) { + if (code == usertable_move[l].codepoint) { + skip = usertable_move[l].moveright * zw; + skip2 = usertable_move[l].movedown * zh; + goto outputu; + } + } if (skip != -rightamount && enhanced) { fprintf(stderr, "[Warning] Conflicting MOVERIGHT value for code %x,\n" @@ -699,11 +730,13 @@ void writevfu(int code, FILE *fp) code, skip, -rightamount); skip=-rightamount; } + +outputu: if (kanatfm) cc=4; else cc=3; - if (code>=0x10000) + if (outcode>=0x10000) cc+=1; if (skip) cc+=numcount(skip)+1; @@ -726,12 +759,12 @@ void writevfu(int code, FILE *fp) else fputc(172+fidshift,fp); /* FONT_NUM_1 */ } - if (code>=0x10000) { + if (outcode>=0x10000) { fputc(130,fp); /* SET3 */ - fputnum(code,3,fp); /* char code */ + fputnum(outcode,3,fp); /* char code */ } else { fputc(129,fp); /* SET2 */ - fputnum(code,2,fp); /* char code */ + fputnum(outcode,2,fp); /* char code */ } } |