diff options
author | Peter Breitenlohner <peb@mppmu.mpg.de> | 2012-09-18 17:17:57 +0000 |
---|---|---|
committer | Peter Breitenlohner <peb@mppmu.mpg.de> | 2012-09-18 17:17:57 +0000 |
commit | ca86fb03187e2e7822b78e50cd39b8583bacd0e2 (patch) | |
tree | e87eb946f580799d1162335b73b4122a235605b3 /Build/source/texk/makejvf/main.c | |
parent | e819cecc04df73c709499de7352d79a6384e00d6 (diff) |
makejvf: Remove W32TeX/TL diffs (from Akira)
Use xmalloc() and xstrdup()
Use getopt() to parse options, avoiding segmentation fault for missing parameters
git-svn-id: svn://tug.org/texlive/trunk@27695 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/makejvf/main.c')
-rw-r--r-- | Build/source/texk/makejvf/main.c | 112 |
1 files changed, 42 insertions, 70 deletions
diff --git a/Build/source/texk/makejvf/main.c b/Build/source/texk/makejvf/main.c index baa96c39798..5a38a0bf907 100644 --- a/Build/source/texk/makejvf/main.c +++ b/Build/source/texk/makejvf/main.c @@ -2,7 +2,7 @@ #include <stdlib.h> #include <string.h> -#include <kpathsea/config.h> +#include <kpathsea/kpathsea.h> #include <ptexenc/ptexenc.h> #include "makejvf.h" #include "uniblock.h" @@ -15,71 +15,55 @@ long ucs=0; int main(int argc, char ** argv) { int i,j,ib; + int c; long ch; - set_enc_string(NULL, "EUC"); - if (argc < 3) { - usage(); - exit(0); - } + kpse_set_program_name(argv[0], "makejvf"); + set_enc_string("sjis", "euc"); + + while ((c = getopt (argc, argv, "k:K:Ca:b:mu:3J:U:Hi")) != -1) + switch (c) { - argv++; - for (;**argv=='-';argv++) { - switch ((*argv)[1]) { case 'k': - if ((*argv)[2]!='\0') { - kanatume = atoi(&(*argv)[2]); - } - else { - kanatume = atoi(*(++argv)); - } + kanatume = atoi(optarg); break; case 'K': - if ((*argv)[2]!='\0') { - kanatfm = strdup(&(*argv)[2]); - } - else { - kanatfm = strdup(*(++argv)); - } + kanatfm = xstrdup(optarg); break; case 'C': chotai=1; break; case 'a': - if ((*argv)[2]!='\0') { - afmname = strdup(&(*argv)[2]); - } - else { - afmname = strdup(*(++argv)); + afmname = xstrdup(optarg); + { + char *fpath = kpse_find_file(afmname, kpse_afm_format, 0); + if (fpath) { + afp = fopen(fpath, "r"); + free(fpath); + } } - if ((afp = fopen(afmname,"r"))==NULL) { + if (!afp) { fprintf(stderr,"no AFM file, %s.\n",afmname); exit(100); } break; case 'b': - if ((*argv)[2]!='\0') { - baseshift = atoi(&(*argv)[2]); - } - else { - baseshift = atoi(*(++argv)); - } + baseshift = atoi(optarg); break; case 'm': minute=1; break; case 'u': - argv++; - if (!strcmp(*argv,"gb")) + if (!strcmp(optarg, "gb")) ucs = ENTRY_G; - else if (!strcmp(*argv,"cns")) + else if (!strcmp(optarg, "cns")) ucs = ENTRY_C; - else if (!strcmp(*argv,"jisq")) + else if (!strcmp(optarg, "jisq")) ucs = ENTRY_JQ; - else if (!strcmp(*argv,"jis")) + else if (!strcmp(optarg, "jis")) ucs = ENTRY_J; - else if (!strcmp(*argv,"ks")) + else if (!strcmp(optarg, "ks")) ucs = ENTRY_K; else { fprintf(stderr,"Charset is not set\n"); @@ -90,21 +74,10 @@ int main(int argc, char ** argv) useset3=1; break; case 'J': - if ((*argv)[2]!='\0') { - jistfm = strdup(&(*argv)[2]); - } - else { - jistfm = strdup(*(++argv)); - } + jistfm = xstrdup(optarg); break; case 'U': - if ((*argv)[2]!='\0') { - ucsqtfm = strdup(&(*argv)[2]); - } - else { - ucsqtfm = strdup(*(++argv)); - } - break; + ucsqtfm = xstrdup(optarg); case 'H': hankana=1; break; @@ -115,33 +88,32 @@ int main(int argc, char ** argv) usage(); exit(0); } - } if (kanatume>=0 && !afp) { fprintf(stderr,"No AFM file for kanatume.\n"); exit(100); } - atfmname = malloc(strlen(*argv)+4); - strcpy(atfmname,*argv); + if (argc - optind != 2) { + usage(); + exit(0); + } - vfname = malloc(strlen(*argv)+4); - strcpy(vfname,*argv); - for (i = strlen(vfname)-1 ; i >= 0 ; i--) { - if (vfname[i] == '/') { - vfname = &vfname[i+1]; - break; - } + atfmname = xmalloc(strlen(argv[optind])+4); + strcpy(atfmname, argv[optind]); + + { + const char *p = xbasename(argv[optind]); + vfname = xmalloc(strlen(p)+4); + strcpy(vfname, p); } - if (!strcmp(&vfname[strlen(vfname)-4],".tfm")) { + if (FILESTRCASEEQ(&vfname[strlen(vfname)-4], ".tfm")) { vfname[strlen(vfname)-4] = '\0'; } strcat(vfname,".vf"); - argv++; - - vtfmname = strdup(*argv); - if (!strcmp(&vtfmname[strlen(vtfmname)-4],".tfm")) { + vtfmname = xstrdup(argv[optind+1]); + if (FILESTRCASEEQ(&vtfmname[strlen(vtfmname)-4], ".tfm")) { vtfmname[strlen(vtfmname)-4] = '\0'; } @@ -150,21 +122,21 @@ int main(int argc, char ** argv) maketfm(vtfmname); if (kanatfm) { - if (!strcmp(&kanatfm[strlen(kanatfm)-4],".tfm")) { + if (FILESTRCASEEQ(&kanatfm[strlen(kanatfm)-4], ".tfm")) { kanatfm[strlen(kanatfm)-4] = '\0'; } maketfm(kanatfm); } if (jistfm) { - if (!strcmp(&jistfm[strlen(jistfm)-4],".tfm")) { + if (FILESTRCASEEQ(&jistfm[strlen(jistfm)-4], ".tfm")) { jistfm[strlen(jistfm)-4] = '\0'; } maketfm(jistfm); } if (ucsqtfm) { - if (!strcmp(&ucsqtfm[strlen(ucsqtfm)-4],".tfm")) { + if (FILESTRCASEEQ(&ucsqtfm[strlen(ucsqtfm)-4], ".tfm")) { ucsqtfm[strlen(ucsqtfm)-4] = '\0'; } maketfm(ucsqtfm); |