Skip to content

Commit

Permalink
mendex: Improved compatibility with makeindex (texjporg#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
h20y6m committed Feb 4, 2025
1 parent c20cad0 commit f3ba2d6
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 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,40 @@ 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++;
}
}
else {
estr[i]=buff[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. */
quo=0;
if (esc==0) {
if (buff[i]==escape) {
esc=1;
} else if (buff[i]==quote) {
i++;
quo=1;
}
} else {
esc=0;
}
if (nest==0 && buff[i]==arg_close) {
estr[i]='\0';
return i;

if (quo==0) {
if (nest==0 && buff[i]==arg_close) {
estr[j]='\0';
return i;
}
if (buff[i]==arg_open) nest++;
else if (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 (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

0 comments on commit f3ba2d6

Please sign in to comment.