Skip to content

Commit

Permalink
[upmendex] accept multiple style files by -s option (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-tk committed May 30, 2021
1 parent ea21683 commit c092fe7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
34 changes: 21 additions & 13 deletions source/texk/upmendex/main.c
Expand Up @@ -9,7 +9,7 @@

#include "kp.h"

char *styfile,*idxfile[256],*indfile,*dicfile,*logfile;
char *styfile[64],*idxfile[256],*indfile,*dicfile,*logfile;

/* default paths */
#ifndef DEFAULT_INDEXSTYLES
Expand All @@ -22,7 +22,7 @@ KpathseaSupportInfo kp_ist,kp_dict;

int main(int argc, char **argv)
{
int i,j,cc=0,startpagenum=-1,ecount=0,chkopt=1;
int i,j,k,cc=0,startpagenum=-1,ecount=0,chkopt=1;
const char *envbuff;
UVersionInfo icuVersion;
char icu_version[U_MAX_VERSION_STRING_LENGTH] = "";
Expand Down Expand Up @@ -54,7 +54,7 @@ int main(int argc, char **argv)

/* check options */

for (i=1,j=0;i<argc && j<256;i++) {
for (i=1,j=k=0;i<argc && j<256;i++) {
if ((argv[i][0]=='-')&&(strlen(argv[i])>=2)&&chkopt) {
switch (argv[i][1]) {
case 'c':
Expand Down Expand Up @@ -135,12 +135,17 @@ int main(int argc, char **argv)
break;

case 's':
if (k==64) {
fprintf (stderr, "Too many style files.\n");
exit(255);
}
if ((argv[i][2]=='\0')&&(i+1<argc)) {
styfile=xstrdup(argv[++i]);
styfile[k]=xstrdup(argv[++i]);
}
else {
styfile=xstrdup(&argv[i][2]);
styfile[k]=xstrdup(&argv[i][2]);
}
k++;
break;

case 'v':
Expand Down Expand Up @@ -190,10 +195,10 @@ int main(int argc, char **argv)

if (idxcount==0) idxcount=fsti=1;

if (styfile==NULL) {
if (styfile[0]==NULL) {
envbuff=kpse_var_value("INDEXDEFAULTSTYLE");
if (envbuff!=NULL) {
styfile=xstrdup(envbuff);
styfile[0]=xstrdup(envbuff);
}
}

Expand Down Expand Up @@ -227,12 +232,6 @@ int main(int argc, char **argv)
logfile=xstrdup("stderr");
}

/* init hangul tumunja table */
u_strcpy(tumunja,GANADA);
if (styfile!=NULL) styread(styfile);

set_icu_attributes();

if (strcmp(argv[0],"makeindex")==0) {
verb_printf(efp,"This is Not `MAKEINDEX\', But `UPMENDEX\' %s (%s).\n",
VERSION, TL_VERSION);
Expand All @@ -246,6 +245,15 @@ int main(int argc, char **argv)

initkanatable();

/* init hangul tumunja table */
u_strcpy(tumunja,GANADA);

for (k=0;styfile[k]!=NULL;k++) {
styread(styfile[k]);
}

set_icu_attributes();

/* read dictionary */

ecount+=dicread(dicfile);
Expand Down
3 changes: 3 additions & 0 deletions source/texk/upmendex/styfile.c
Expand Up @@ -49,6 +49,7 @@ void styread(const char *filename)
fprintf(stderr,"%s does not exist.\n",filename);
exit(0);
}
verb_printf(efp,"Scanning style file %s.",filename);

for (i=0;;i++) {
if (fgets(buff,4095,fp)==NULL) break;
Expand Down Expand Up @@ -157,6 +158,8 @@ void styread(const char *filename)
if (getparam(buff,"icu_attributes", icu_attr_str )) continue;
}
fclose(fp);

verb_printf(efp,"...done.\n");
}

/* analize string parameter of style file */
Expand Down
6 changes: 6 additions & 0 deletions source/texk/upmendex/tests/uni1.ist
@@ -0,0 +1,6 @@
% -*- coding: utf-8 -*-

delim_0 "\\leaders\\hbox{$\\cdot$}\\hfill "
delim_1 "\\leaders\\hbox{$\\cdot$}\\hfill "
delim_2 "\\leaders\\hbox{$\\cdot$}\\hfill "

6 changes: 6 additions & 0 deletions source/texk/upmendex/tests/uni2.ist
@@ -0,0 +1,6 @@
% -*- coding: utf-8 -*-

lethead_flag 1
lethead_prefix "\n\\centerline{\\bfseries ◆◆◆ "
lethead_suffix " ◆◆◆}\\par\\nobreak"

4 changes: 4 additions & 0 deletions source/texk/upmendex/tests/upmendex.test
Expand Up @@ -24,6 +24,10 @@ cat $srcdir/tests/uni.idx | \
>uni.ind2 2>uni.ilg2 \
&& diff $srcdir/tests/uni.ind uni.ind2 || exit 1

./upmendex -d $srcdir/tests/uni.dict -s $srcdir/tests/uni1.ist -s $srcdir/tests/uni2.ist \
$srcdir/tests/uni.idx -o uni.ind3 -t uni.ilg3 \
&& diff $srcdir/tests/uni.ind uni.ind3 || exit 1

# test for page_precedence
./upmendex -s $srcdir/tests/pprec0.ist $srcdir/tests/pprecA.idx -o pprecA-0.ind1 -t pprecA-0.ilg \
&& diff $srcdir/tests/pprecA-0.ind pprecA-0.ind1 || exit 1
Expand Down

0 comments on commit c092fe7

Please sign in to comment.