Skip to content

Commit

Permalink
Merge branch 'issue173' #173
Browse files Browse the repository at this point in the history
  • Loading branch information
t-tk committed Feb 9, 2025
2 parents e9fb850 + bab4174 commit c293950
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 42 deletions.
53 changes: 32 additions & 21 deletions source/texk/mendexk/fread.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ int idxread(char *filename, int start)
continue;
}

if (quo==0 && buff[j]==escape) {
if (esc==1 && buff[j]==escape) {
esc=0;
} else if (quo==0 && buff[j]==escape) {
esc=1;
}

Expand Down Expand Up @@ -150,7 +152,7 @@ int idxread(char *filename, int start)
if (buff[j]==encap) {
j++;
cc=getestr(&buff[j],estr);
if (cc<0 || strchr(estr,encap)) {
if (cc<0) {
fprintf(efp,"\nError: Bad encap string in %s, line %d.",filename,ind[i].lnum);
if (efp!=stderr) fprintf(stderr,"\nError: Bad encap string in %s, line %d.",filename,ind[i].lnum);
eflg++;
Expand Down Expand Up @@ -417,28 +419,37 @@ int idxread(char *filename, int start)
/* pic up encap string */
static int getestr(char *buff, char *estr)
{
int i,nest=0;

for (i=0;i<strlen(buff);i++) {
if (buff[i]==encap) {
if (i>0) {
if ((unsigned char)buff[i-1]<0x80) {
estr[i]=buff[i];
i++;
}
int i,j,nest=0,esc=0,quo=0;

for (i=0,j=0;i<strlen(buff);i++,j++) {
/* If a "quote" character is found, it is removed and the
following character is not treated as a special character.
If a "quote" character follows an odd number of
consecutive "escape" characters, it is not treated as a
special character and is left as is.
Note that the "escape" characters are not removed. */
esc=0; quo=0;
if (buff[i]==escape) {
estr[j]=buff[i];
i++; j++;
esc=1;
} else if (buff[i]==quote) {
i++;
quo=1;
}
if (quo==0) {
if (nest==0 && esc==0 && buff[i]==arg_close) {
estr[j]='\0';
return i;
}
else {
estr[i]=buff[i];
i++;
if (esc==0 && buff[i]==arg_open) nest++;
else if (esc==0 && buff[i]==arg_close) nest--;
else if (buff[i]==level || buff[i]==actual || buff[i]==encap) {
fprintf(efp, "\nError: Extra `%c\' at position %d in encap string.",buff[i],i);
return -1;
}
}
if (nest==0 && buff[i]==arg_close) {
estr[i]='\0';
return i;
}
if (buff[i]==arg_open) nest++;
else if (buff[i]==arg_close) nest--;
copy_multibyte_char(buff, estr, &i, NULL);
copy_multibyte_char(buff, estr, &i, &j);
}

return -1;
Expand Down
6 changes: 6 additions & 0 deletions source/texk/mendexk/styfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ static void convline(char *buff1, int start, char *buff2)
else if (buff1[i]=='t') buff2[j]='\t';
else if (buff1[i]=='r') buff2[j]='\r';
else if (buff1[i]=='\"') buff2[j]='\"';
else {
/* Otherwise, the '\' is simply ignored here and the
following character is copied as is in the next loop. */
i--;
continue;
}
}
else buff2[j]=buff1[i];
j++;
Expand Down
3 changes: 3 additions & 0 deletions source/texk/mendexk/tests/head1.ist
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
headings_flag 1
heading_prefix "aaa\tbbb\|ccc\\ddd\n\[\{\(\"\'"
heading_suffix "\'\"\)\}\]\naaa\tbbb\|ccc\\ddd"
6 changes: 6 additions & 0 deletions source/texk/mendexk/tests/mendex.test
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,11 @@ $_mendex $srcdir/tests/tort.idx -o tort.ind1 -t tort.ilg1 \
$_mendex $srcdir/tests/tortW.idx -o tortW.ind1 -t tortW.ilg1 \
&& diff $srcdir/tests/ok-tort.ind tortW.ind1 || :

$_mendex $srcdir/tests/tort.idx -s $srcdir/tests/head1.ist -o tort2.ind1 -t tort2.ilg1 \
&& diff $srcdir/tests/ok-tort2.ind tort2.ind1 || :

$_mendex $srcdir/tests/tortW.idx -s $srcdir/tests/head1.ist -o tortW2.ind1 -t tortW2.ilg1 \
&& diff $srcdir/tests/ok-tort2.ind tortW2.ind1 || :


exit $rc
5 changes: 5 additions & 0 deletions source/texk/mendexk/tests/ok-tort.ind
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

\indexspace

\item encap-escape1 aaa@bbb|ccc!ddd"eee{fff}, \ppp{11}, 10--12
\item encap-escape2, \aaa@bbb|ccc!ddd"eee{fff}{20--22}

\indexspace

\item implicit-range, 10--12
\item incons-encaps, \ii{6}, 5--7
\item incons-encaps2, \ii{5}, 5
Expand Down
39 changes: 39 additions & 0 deletions source/texk/mendexk/tests/ok-tort2.ind
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
\begin{theindex}
aaa bbb|ccc\ddd
[{("'B'")}]
aaa bbb|ccc\ddd
\item bad-encaps, \ii{5--7}

\indexspace
aaa bbb|ccc\ddd
[{("'E'")}]
aaa bbb|ccc\ddd
\item encap-escape1 aaa@bbb|ccc!ddd"eee{fff}, \ppp{11}, 10--12
\item encap-escape2, \aaa@bbb|ccc!ddd"eee{fff}{20--22}

\indexspace
aaa bbb|ccc\ddd
[{("'I'")}]
aaa bbb|ccc\ddd
\item implicit-range, 10--12
\item incons-encaps, \ii{6}, 5--7
\item incons-encaps2, \ii{5}, 5
\item incons-entries, 6, \xx{6}

\indexspace
aaa bbb|ccc\ddd
[{("'M'")}]
aaa bbb|ccc\ddd
\item missing(, 6
\item missing), 6
\item mixed-range, i, 6
\item mixed-range1, i--iv, 3--6
\item mixed-range2, \xx{ii}, i--ii, \yy{3--6}

\indexspace
aaa bbb|ccc\ddd
[{("'O'")}]
aaa bbb|ccc\ddd
\item ok-encaps, \ii{5--7}

\end{theindex}
8 changes: 8 additions & 0 deletions source/texk/mendexk/tests/tort.idx
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@
\indexentry{mixed-range2|xx}{ii}
\indexentry{mixed-range2|yy}{3}
\indexentry{mixed-range2|)}{6}

\indexentry{encap-escape1 aaa"@bbb"|ccc"!ddd""eee"{fff"}|(}{10}
\indexentry{encap-escape1 aaa"@bbb"|ccc"!ddd""eee"{fff"}|ppp}{11}
\indexentry{encap-escape1 aaa"@bbb"|ccc"!ddd""eee"{fff"}|)}{12}

\indexentry{encap-escape2|(aaa"@bbb"|ccc"!ddd""eee"{fff"}}{20}
\indexentry{encap-escape2|aaa"@bbb"|ccc"!ddd""eee"{fff"}}{21}
\indexentry{encap-escape2|)}{22}
8 changes: 8 additions & 0 deletions source/texk/mendexk/tests/tortW.idx
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@
\indexentry{mixed-range2|xx}{ii}
\indexentry{mixed-range2|yy}{3}
\indexentry{mixed-range2|)}{6}

\indexentry{encap-escape1 aaa"@bbb"|ccc"!ddd""eee"{fff"}|(}{10}
\indexentry{encap-escape1 aaa"@bbb"|ccc"!ddd""eee"{fff"}|ppp}{11}
\indexentry{encap-escape1 aaa"@bbb"|ccc"!ddd""eee"{fff"}|)}{12}

\indexentry{encap-escape2|(aaa"@bbb"|ccc"!ddd""eee"{fff"}}{20}
\indexentry{encap-escape2|aaa"@bbb"|ccc"!ddd""eee"{fff"}}{21}
\indexentry{encap-escape2|)}{22}
53 changes: 32 additions & 21 deletions source/texk/upmendex/fread.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ int idxread(char *filename, int start)
continue;
}

if (quo==0 && buff[j]==escape) {
if (esc==1 && buff[j]==escape) {
esc=0;
} else if (quo==0 && buff[j]==escape) {
esc=1;
}

Expand Down Expand Up @@ -150,7 +152,7 @@ int idxread(char *filename, int start)
if (buff[j]==encap) {
j++;
cc=getestr(&buff[j],estr);
if (cc<0 || strchr(estr,encap)) {
if (cc<0) {
fprintf(efp,"\nError: Bad encap string in %s, line %d.",filename,ind[i].lnum);
if (efp!=stderr) fprintf(stderr,"\nError: Bad encap string in %s, line %d.",filename,ind[i].lnum);
eflg++;
Expand Down Expand Up @@ -422,28 +424,37 @@ int idxread(char *filename, int start)
/* pic up encap string */
static int getestr(char *buff, char *estr)
{
int i,nest=0;

for (i=0;i<strlen(buff);i++) {
if (buff[i]==encap) {
if (i>0) {
if ((unsigned char)buff[i-1]<0x80) {
estr[i]=buff[i];
i++;
}
int i,j,nest=0,esc=0,quo=0;

for (i=0,j=0;i<strlen(buff);i++,j++) {
/* If a "quote" character is found, it is removed and the
following character is not treated as a special character.
If a "quote" character follows an odd number of
consecutive "escape" characters, it is not treated as a
special character and is left as is.
Note that the "escape" characters are not removed. */
esc=0; quo=0;
if (buff[i]==escape) {
estr[j]=buff[i];
i++; j++;
esc=1;
} else if (buff[i]==quote) {
i++;
quo=1;
}
if (quo==0) {
if (nest==0 && esc==0 && buff[i]==arg_close) {
estr[j]='\0';
return i;
}
else {
estr[i]=buff[i];
i++;
if (esc==0 && buff[i]==arg_open) nest++;
else if (esc==0 && buff[i]==arg_close) nest--;
else if (buff[i]==level || buff[i]==actual || buff[i]==encap) {
fprintf(efp, "\nError: Extra `%c\' at position %d in encap string.",buff[i],i);
return -1;
}
}
if (nest==0 && buff[i]==arg_close) {
estr[i]='\0';
return i;
}
if (buff[i]==arg_open) nest++;
else if (buff[i]==arg_close) nest--;
copy_multibyte_char(buff, estr, &i, NULL);
copy_multibyte_char(buff, estr, &i, &j);
}

return -1;
Expand Down
6 changes: 6 additions & 0 deletions source/texk/upmendex/styfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ static void convline(char *buff1, int start, char *buff2)
else if (buff1[i]=='t') buff2[j]='\t';
else if (buff1[i]=='r') buff2[j]='\r';
else if (buff1[i]=='\"') buff2[j]='\"';
else {
/* Otherwise, the '\' is simply ignored here and the
following character is copied as is in the next loop. */
i--;
continue;
}
}
else buff2[j]=buff1[i];
j++;
Expand Down
3 changes: 3 additions & 0 deletions source/texk/upmendex/tests/head1.ist
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
headings_flag 1
heading_prefix "aaa\tbbb\|ccc\\ddd\n\[\{\(\"\'"
heading_suffix "\'\"\)\}\]\naaa\tbbb\|ccc\\ddd"
5 changes: 5 additions & 0 deletions source/texk/upmendex/tests/ok-tort.ind
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

\indexspace

\item encap-escape1 aaa@bbb|ccc!ddd"eee{fff}, \ppp{11}, 10--12
\item encap-escape2, \aaa@bbb|ccc!ddd"eee{fff}{20--22}

\indexspace

\item implicit-range, 10--12
\item incons-encaps, \ii{6}, 5--7
\item incons-encaps2, \ii{5}, 5
Expand Down
39 changes: 39 additions & 0 deletions source/texk/upmendex/tests/ok-tort2.ind
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
\begin{theindex}
aaa bbb|ccc\ddd
[{("'B'")}]
aaa bbb|ccc\ddd
\item bad-encaps, \ii{5--7}

\indexspace
aaa bbb|ccc\ddd
[{("'E'")}]
aaa bbb|ccc\ddd
\item encap-escape1 aaa@bbb|ccc!ddd"eee{fff}, \ppp{11}, 10--12
\item encap-escape2, \aaa@bbb|ccc!ddd"eee{fff}{20--22}

\indexspace
aaa bbb|ccc\ddd
[{("'I'")}]
aaa bbb|ccc\ddd
\item implicit-range, 10--12
\item incons-encaps, \ii{6}, 5--7
\item incons-encaps2, \ii{5}, 5
\item incons-entries, 6, \xx{6}

\indexspace
aaa bbb|ccc\ddd
[{("'M'")}]
aaa bbb|ccc\ddd
\item missing(, 6
\item missing), 6
\item mixed-range, i, 6
\item mixed-range1, i--iv, 3--6
\item mixed-range2, \xx{ii}, i--ii, \yy{3--6}

\indexspace
aaa bbb|ccc\ddd
[{("'O'")}]
aaa bbb|ccc\ddd
\item ok-encaps, \ii{5--7}

\end{theindex}
8 changes: 8 additions & 0 deletions source/texk/upmendex/tests/tort.idx
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@
\indexentry{mixed-range2|xx}{ii}
\indexentry{mixed-range2|yy}{3}
\indexentry{mixed-range2|)}{6}

\indexentry{encap-escape1 aaa"@bbb"|ccc"!ddd""eee"{fff"}|(}{10}
\indexentry{encap-escape1 aaa"@bbb"|ccc"!ddd""eee"{fff"}|ppp}{11}
\indexentry{encap-escape1 aaa"@bbb"|ccc"!ddd""eee"{fff"}|)}{12}

\indexentry{encap-escape2|(aaa"@bbb"|ccc"!ddd""eee"{fff"}}{20}
\indexentry{encap-escape2|aaa"@bbb"|ccc"!ddd""eee"{fff"}}{21}
\indexentry{encap-escape2|)}{22}
8 changes: 8 additions & 0 deletions source/texk/upmendex/tests/tortW.idx
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@
\indexentry{mixed-range2|xx}{ii}
\indexentry{mixed-range2|yy}{3}
\indexentry{mixed-range2|)}{6}

\indexentry{encap-escape1 aaa"@bbb"|ccc"!ddd""eee"{fff"}|(}{10}
\indexentry{encap-escape1 aaa"@bbb"|ccc"!ddd""eee"{fff"}|ppp}{11}
\indexentry{encap-escape1 aaa"@bbb"|ccc"!ddd""eee"{fff"}|)}{12}

\indexentry{encap-escape2|(aaa"@bbb"|ccc"!ddd""eee"{fff"}}{20}
\indexentry{encap-escape2|aaa"@bbb"|ccc"!ddd""eee"{fff"}}{21}
\indexentry{encap-escape2|)}{22}
6 changes: 6 additions & 0 deletions source/texk/upmendex/tests/upmendex.test
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,11 @@ $_upmendex $srcdir/tests/tort.idx -o tort.ind1 -t tort.ilg1 \
$_upmendex $srcdir/tests/tortW.idx -o tortW.ind1 -t tortW.ilg1 \
&& diff $srcdir/tests/ok-tort.ind tortW.ind1 || :

$_upmendex $srcdir/tests/tort.idx -s $srcdir/tests/head1.ist -o tort2.ind1 -t tort2.ilg1 \
&& diff $srcdir/tests/ok-tort2.ind tort2.ind1 || :

$_upmendex $srcdir/tests/tortW.idx -s $srcdir/tests/head1.ist -o tortW2.ind1 -t tortW2.ilg1 \
&& diff $srcdir/tests/ok-tort2.ind tortW2.ind1 || :


exit $rc

0 comments on commit c293950

Please sign in to comment.