Skip to content

Instantly share code, notes, and snippets.

@aminophen
Last active July 20, 2017 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aminophen/8d29344483fe0804106ecec69d317609 to your computer and use it in GitHub Desktop.
Save aminophen/8d29344483fe0804106ecec69d317609 to your computer and use it in GitHub Desktop.
makejvf を制御する入力ファイルを指定する「-t オプション」の追加パッチ
Index: Build/source/texk/makejvf/Makefile.am
===================================================================
--- Build/source/texk/makejvf/Makefile.am (revision 44851)
+++ Build/source/texk/makejvf/Makefile.am (working copy)
@@ -10,7 +10,8 @@
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 tableread.c tfmread.c tool.c \
+ uniblock.c uniblock.h version.h write.c
$(makejvf_OBJECTS): $(KPATHSEA_DEPEND) $(PTEXENC_DEPEND)
Index: Build/source/texk/makejvf/Makefile.in
===================================================================
--- Build/source/texk/makejvf/Makefile.in (revision 44851)
+++ Build/source/texk/makejvf/Makefile.in (working copy)
@@ -113,8 +113,9 @@
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) tableread.$(OBJEXT) \
+ tfmread.$(OBJEXT) tool.$(OBJEXT) uniblock.$(OBJEXT) \
+ write.$(OBJEXT)
makejvf_OBJECTS = $(am_makejvf_OBJECTS)
makejvf_LDADD = $(LDADD)
am__DEPENDENCIES_1 =
@@ -549,7 +550,8 @@
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 tableread.c tfmread.c tool.c \
+ uniblock.c uniblock.h version.h write.c
LDADD = $(PTEXENC_LIBS) $(KPATHSEA_LIBS)
EXTRA_DIST = COPYRIGHT COPYRIGHT.jis Changes.txt README.txt \
@@ -673,6 +675,7 @@
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tableread.Po@am__quote@
@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@
Index: Build/source/texk/makejvf/main.c
===================================================================
--- Build/source/texk/makejvf/main.c (revision 44851)
+++ Build/source/texk/makejvf/main.c (working copy)
@@ -9,7 +9,7 @@
#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;
@@ -23,7 +23,7 @@
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) {
@@ -90,6 +90,9 @@
case 'e':
enhanced=1;
break;
+ case 't':
+ usertable = xstrdup(optarg);
+ break;
default:
usage();
exit(0);
@@ -125,6 +128,10 @@
tfmget(atfmname);
+ if (usertable) {
+ get_usertable(usertable);
+ }
+
vfp = vfopen(vfname);
pstfm_nt=1; /* initialize */
@@ -196,5 +203,6 @@
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);
}
Index: Build/source/texk/makejvf/makejvf.h
===================================================================
--- Build/source/texk/makejvf/makejvf.h (revision 44851)
+++ Build/source/texk/makejvf/makejvf.h (working copy)
@@ -1,11 +1,24 @@
-
+#define BUF_SIZE 1024
+#define MAX_TABLE 1024
#define MAX_LIG_STEPS 32510
-extern char *vtfmname,*kanatfm,*jistfm,*ucsqtfm;
+extern char *vtfmname,*kanatfm,*jistfm,*ucsqtfm,*usertable;
extern int unit,zh,zw,jfm_id,rightamount;
+extern int usertable_replace_max,usertable_move_max;
extern int kanatume,chotai,baseshift,minute,hankana,fidzero,enhanced;
extern int pstfm_nt;
extern FILE *afp;
extern long ucs;
+struct USERTABLE_REPLACE {
+ int codepoint;
+ int newcodepoint;
+};
+extern struct USERTABLE_REPLACE usertable_replace[1024];
+struct USERTABLE_MOVE {
+ int codepoint;
+ double moveright;
+ double movedown;
+};
+extern struct USERTABLE_MOVE usertable_move[1024];
/* main.c */
void usage(void);
@@ -32,3 +45,6 @@
void writevfu(int code, FILE *fp);
void vfclose(FILE *fp);
void maketfm(char *name);
+
+/* tableread.c */
+void get_usertable(char *name);
Index: Build/source/texk/makejvf/tableread.c
===================================================================
--- Build/source/texk/makejvf/tableread.c (nonexistent)
+++ Build/source/texk/makejvf/tableread.c (working copy)
@@ -0,0 +1,59 @@
+#include <kpathsea/config.h>
+#include "makejvf.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int usertable_replace_max,usertable_move_max;
+struct USERTABLE_REPLACE usertable_replace[1024];
+struct USERTABLE_MOVE usertable_move[1024];
+
+void get_usertable(char *name)
+{
+ FILE *fp;
+ char *tok,*endptr,buf[BUF_SIZE];
+
+ usertable_replace_max = 0;
+ usertable_move_max = 0;
+ fp = fopen(name,"r");
+ if (fp == NULL) {
+ fprintf(stderr,"Cannot find %s!\n",name);
+ exit(1);
+ }
+ for (int l = 0; l < MAX_TABLE;) {
+ if (fgets(buf, BUF_SIZE, fp) == NULL) break;
+ char *tok = strtok(buf, "\t");
+ if (!strcmp(tok, "REPLACE")) {
+ 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++;
+ goto rep;
+ }
+ if (!strcmp(tok, "MOVE")) {
+ 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++;
+ goto rep;
+ }
+ fprintf(stderr, "Unknown setting %s found in %s (line %d)!\n", tok, name, l+1);
+ exit(1);
+taberr:
+ fprintf(stderr, "Error in user-defined table file %s (line %d)!\n", name, l+1);
+ exit(1);
+rep:
+ l++;
+ }
+ if (fgets(buf, BUF_SIZE, fp) != NULL) {
+ fprintf(stderr, "User-defined table in %s is too large!\n", name);
+ exit(1);
+ }
+ fclose(fp);
+}
Property changes on: Build/source/texk/makejvf/tableread.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Index: Build/source/texk/makejvf/write.c
===================================================================
--- Build/source/texk/makejvf/write.c (revision 44851)
+++ Build/source/texk/makejvf/write.c (working copy)
@@ -86,6 +86,7 @@
int cc,cc2,cc3,cc4,w,skip=0,skip2=0,height=1000;
char buf[256],buf2[256];
int fidshift=0;
+ int outcode=code;
if (fidzero) fidshift=-1;
@@ -306,6 +307,21 @@
break;
}
+ for (int l = 0; l < usertable_replace_max;) {
+ if (code == usertable_replace[l].codepoint) {
+ outcode = usertable_replace[l].newcodepoint;
+ break;
+ }
+ l++;
+ }
+ for (int l = 0; l < usertable_move_max;) {
+ if (code == usertable_move[l].codepoint) {
+ skip = usertable_move[l].moveright * zw;
+ skip2 = usertable_move[l].movedown * zh;
+ goto outputj;
+ }
+ l++;
+ }
if (skip != -rightamount && enhanced) {
fprintf(stderr,
"[Warning] Conflicting MOVERIGHT value for code %x,\n"
@@ -314,6 +330,8 @@
code, skip, -rightamount);
skip=-rightamount;
}
+
+outputj:
if (kanatfm)
cc=4;
else
@@ -340,7 +358,7 @@
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)
@@ -348,6 +366,7 @@
int cc,cc2,cc3,cc4,w,skip=0,skip2=0,height=1000;
char buf[256],buf2[256];
int fidshift=0;
+ int outcode=code;
if (fidzero) fidshift=-1;
@@ -695,6 +714,21 @@
break;
}
+ for (int l = 0; l < usertable_replace_max;) {
+ if (code == usertable_replace[l].codepoint) {
+ outcode = usertable_replace[l].newcodepoint;
+ break;
+ }
+ l++;
+ }
+ for (int l = 0; l < usertable_move_max;) {
+ if (code == usertable_move[l].codepoint) {
+ skip = usertable_move[l].moveright * zw;
+ skip2 = usertable_move[l].movedown * zh;
+ goto outputu;
+ }
+ l++;
+ }
if (skip != -rightamount && enhanced) {
fprintf(stderr,
"[Warning] Conflicting MOVERIGHT value for code %x,\n"
@@ -703,11 +737,13 @@
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;
@@ -730,12 +766,12 @@
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 */
}
}
@aminophen
Copy link
Author

aminophen commented Jul 19, 2017

しばらくこちらでいろいろ試していたが, texjporg/tex-jp-build#18 を実装すべく,新しく Gist を作り直すことにした。

2017/07/19 現在,20170719-makejvf-usertable-2319.patch は r44844 ベースで,

REPLACE <code> <newcode>
MOVE <code> <right> <down>

だけ解釈できる。他に CHARSET, KANJI を実装したい。また -t オプションが複数回使われた場合の挙動,-m オプションとの併用時など,これらの命令をどう扱うか(どちらを優先するか)は要検討。

設定ファイルのパース仕方に関する TODO:

  • 設定ファイルの文法が不正(値が足りない場合,タブの連続,etc.)な場合のエラーハンドル
  • 各要素の間はタブ区切り限定としてあるが,スペースも認めるか?
  • コメント行(%# で始まる行?),途中の空行の扱い

修正:20170719-makejvf-usertable.patch は数カ所バグがあったので 20170719-makejvf-usertable-2319.patch に更新。

@aminophen
Copy link
Author

r44850, r44851 で別の不具合を修正したので,r44851 ベースの 20170720-makejvf-usertable.patch に更新。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment