summaryrefslogtreecommitdiff
path: root/Build/source
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source')
-rw-r--r--Build/source/texk/mendexk/ChangeLog17
-rw-r--r--Build/source/texk/mendexk/exvar.h2
-rw-r--r--Build/source/texk/mendexk/fread.c65
-rw-r--r--Build/source/texk/mendexk/fwrite.c52
-rw-r--r--Build/source/texk/mendexk/mendex.h4
-rw-r--r--Build/source/texk/mendexk/sort.c119
-rwxr-xr-xBuild/source/texk/mendexk/tests/mendex.test16
-rw-r--r--Build/source/texk/mendexk/tests/range.idx126
-rw-r--r--Build/source/texk/mendexk/tests/range1.ind25
-rw-r--r--Build/source/texk/mendexk/tests/range1.ist3
-rw-r--r--Build/source/texk/mendexk/tests/range2.ind26
-rw-r--r--Build/source/texk/mendexk/tests/range2.ist4
-rw-r--r--Build/source/texk/mendexk/tests/range3.ind25
-rw-r--r--Build/source/texk/mendexk/tests/range3.ist4
-rw-r--r--Build/source/texk/mendexk/tests/rangetwo.idx2
-rw-r--r--Build/source/texk/mendexk/tests/rangetwo.ind5
-rw-r--r--Build/source/texk/mendexk/tests/rangetwo.ist2
-rw-r--r--Build/source/texk/mendexk/var.h2
-rw-r--r--Build/source/texk/mendexk/version.h2
19 files changed, 399 insertions, 102 deletions
diff --git a/Build/source/texk/mendexk/ChangeLog b/Build/source/texk/mendexk/ChangeLog
index aa76092bbc1..b443138bec0 100644
--- a/Build/source/texk/mendexk/ChangeLog
+++ b/Build/source/texk/mendexk/ChangeLog
@@ -1,7 +1,22 @@
+2021-09-18 TANAKA Takuji <ttk@t-lab.opal.ne.jp>
+
+ * fread.c, fwrite.c, sort.c, mendex.h, {,ex}var.h:
+ Extend levels of page numbers from 3 to 10
+ for compatibility with makeindex.
+ Fix a bug of page ranges with multi-level page numbers.
+ * fread.c:
+ Strict check for "page_precedence" and "page_compositor" in style file.
+ * fwrite.c:
+ Do not break lines before "delim_n".
+ * tests/mendex.test, tests/range.idx, tests/range[123].{ist,ind},
+ removed tests/rangetwo.*:
+ Update tests.
+ * version.h: Date [18-Sep-2021]
+
2021-09-04 TANAKA Takuji <ttk@t-lab.opal.ne.jp>
* configure.ac, version.h:
- Version 3.6 [6-Jun-2021].
+ Version 3.6 [4-Sep-2021].
* styfile.c, sort.c, fwrite.c, mendex.h, {,ex}var.h:
Support output order of symbols and numbers separately
when "symbol_flag" is 2 in style file.
diff --git a/Build/source/texk/mendexk/exvar.h b/Build/source/texk/mendexk/exvar.h
index 8d5925443ce..7d3aa7a1349 100644
--- a/Build/source/texk/mendexk/exvar.h
+++ b/Build/source/texk/mendexk/exvar.h
@@ -2,7 +2,7 @@ extern FILE *efp;
extern int lines,idxcount,acc,reject;
extern int prange,fsti,lorder,bcomp,force,fpage,gflg,verb,debug;
-extern int warn,scount,pattr[3];
+extern int warn,scount,pattr[];
extern struct index *ind;
diff --git a/Build/source/texk/mendexk/fread.c b/Build/source/texk/mendexk/fread.c
index 793bc4c593f..855920f4cf6 100644
--- a/Build/source/texk/mendexk/fread.c
+++ b/Build/source/texk/mendexk/fread.c
@@ -456,25 +456,54 @@ static void copy_multibyte_char(char *buff1, char *buff2, int *i, int *j)
static void chkpageattr(struct page *p)
{
- int i,j,cc=0;
+ int i,j,cc=0,cnt,pplen,pclen;
+ char buff[16],*pcpos,*page0;
+ pplen=strlen(page_precedence);
+ pclen=strlen(page_compositor);
for (i=0;i<strlen(p->page);i++) {
- if (strncmp(page_compositor,&p->page[i],strlen(page_compositor))==0) {
+ page0=&p->page[i];
+ if (strncmp(page_compositor,page0,pclen)==0) {
p->attr[cc]=pattr[cc];
cc++;
- i+=strlen(page_compositor)-1;
+ i+=pclen-1;
+ if (cc>=PAGE_COMPOSIT_DEPTH) {
+ if (pclen>0)
+ verb_printf(efp, "\nToo many fields of page number \"%s\".\n", p->page);
+ else
+ verb_printf(efp, "\nIllegular page_comositor specification.\n");
+ exit(253);
+ }
}
else {
-ATTRLOOP:
- if (!((p->page[i]>='0' && p->page[i]<='9') || (p->page[i]>='A' && p->page[i]<='Z') || (p->page[i]>='a' && p->page[i]<='z'))) {
+ cnt=0;
+ if (!((*page0>='0' && *page0<='9') || (*page0>='A' && *page0<='Z') || (*page0>='a' && *page0<='z'))) {
p->attr[cc]= -1;
if (cc<2) p->attr[++cc]= -1;
return;
}
+ pcpos=strstr(page0,page_compositor);
+ j=pcpos ? pcpos-page0 : strlen(page0);
+ if (j>15) {
+ verb_printf(efp, "\nToo long page number string \"%s\".\n", page0);
+ exit(253);
+ }
+ strncpy(buff,page0,j);
+ buff[j]='\0';
+ATTRLOOP:
+ cnt++;
+ if (cnt>pplen) {
+ verb_printf(efp, "\nFailed to find page type for page \"%s\" in page_precedence specification (%s).\n",
+ page0, page_precedence);
+ exit(253);
+ }
+
switch(page_precedence[pattr[cc]]) {
case 'r':
- if (strchr("ivxlcdm",p->page[i])==NULL) {
- if (pattr[cc]<strlen(page_precedence)-1)
+ if (strchr("ivxlcdm",*page0)==NULL ||
+ (strchr("lcdm",*page0) && strchr(page_precedence,'a') && strlen(buff)==1 && pcpos)) {
+ /* heuristic detection as alphabet since L=50, C=100, D=100, M=1000 are quite large */
+ if (pattr[cc]<pplen-1)
pattr[cc]++;
else pattr[cc]=0;
for (j=cc+1;j<3;j++) pattr[j]=0;
@@ -482,8 +511,10 @@ ATTRLOOP:
}
break;
case 'R':
- if (strchr("IVXLCDM",p->page[i])==NULL) {
- if (pattr[cc]<strlen(page_precedence)-1)
+ if (strchr("IVXLCDM",*page0)==NULL ||
+ (strchr("LCDM",*page0) && strchr(page_precedence,'A') && strlen(buff)==1 && pcpos)) {
+ /* heuristic detection as alphabet since L=50, C=100, D=100, M=1000 are quite large */
+ if (pattr[cc]<pplen-1)
pattr[cc]++;
else pattr[cc]=0;
for (j=cc+1;j<3;j++) pattr[j]=0;
@@ -491,8 +522,8 @@ ATTRLOOP:
}
break;
case 'n':
- if (p->page[i]<'0' || p->page[i]>'9') {
- if (pattr[cc]<strlen(page_precedence)-1)
+ if (*page0<'0' || *page0>'9') {
+ if (pattr[cc]<pplen-1)
pattr[cc]++;
else pattr[cc]=0;
for (j=cc+1;j<3;j++) pattr[j]=0;
@@ -500,8 +531,8 @@ ATTRLOOP:
}
break;
case 'a':
- if (p->page[i]<'a' || p->page[i]>'z') {
- if (pattr[cc]<strlen(page_precedence)-1)
+ if (*page0<'a' || *page0>'z' || strlen(buff)>1) {
+ if (pattr[cc]<pplen-1)
pattr[cc]++;
else pattr[cc]=0;
for (j=cc+1;j<3;j++) pattr[j]=0;
@@ -509,8 +540,8 @@ ATTRLOOP:
}
break;
case 'A':
- if (p->page[i]<'A' || p->page[i]>'Z') {
- if (pattr[cc]<strlen(page_precedence)-1)
+ if (*page0<'A' || *page0>'Z' || strlen(buff)>1) {
+ if (pattr[cc]<pplen-1)
pattr[cc]++;
else pattr[cc]=0;
for (j=cc+1;j<3;j++) pattr[j]=0;
@@ -518,7 +549,9 @@ ATTRLOOP:
}
break;
default:
- break;
+ verb_printf(efp, "\nUnknown page type '%c' in page_precedence specification (%s).\n",
+ page_precedence[pattr[cc]], page_precedence);
+ exit(253);
}
}
}
diff --git a/Build/source/texk/mendexk/fwrite.c b/Build/source/texk/mendexk/fwrite.c
index 4ae17228e2a..ef97d0c87a3 100644
--- a/Build/source/texk/mendexk/fwrite.c
+++ b/Build/source/texk/mendexk/fwrite.c
@@ -14,7 +14,7 @@ int line_length=0;
static void printpage(struct index *ind, FILE *fp, int num, char *lbuff);
static int range_check(struct index ind, int count, char *lbuff);
-static void linecheck(char *lbuff, char *tmpbuff);
+static void linecheck(char *lbuff, char *tmpbuff, int force);
static void crcheck(char *lbuff, FILE *fp);
/* All buffers have size BUFFERLEN. */
@@ -115,6 +115,22 @@ void verb_printf(FILE *fp, const char *format, ...)
if (fp!=stderr) fputs(print_buff, fp);
}
+static int pnumconv2(struct page *p)
+{
+ int j,k,cc,pclen;
+
+ pclen=strlen(page_compositor);
+ for (j=k=cc=0;j<strlen(p->page);j++) {
+ if (strncmp(p->page+j,page_compositor,pclen)==0) {
+ j+=pclen;
+ k=j;
+ cc++;
+ continue;
+ }
+ }
+ return pnumconv(p->page+k,p->attr[cc]);
+}
+
/* write ind file */
void indwrite(char *filename, struct index *ind, int pagenum)
@@ -348,10 +364,8 @@ static void printpage(struct index *ind, FILE *fp, int num, char *lbuff)
for(j=0;j<ind[num].num;j++) {
cc=range_check(ind[num],j,lbuff);
if (cc>j) {
- int epage = pnumconv(ind[num].p[cc].page,
- ind[num].p[cc].attr[0]);
- int bpage = pnumconv(ind[num].p[j].page,
- ind[num].p[j].attr[0]);
+ int epage = pnumconv2(&ind[num].p[cc]);
+ int bpage = pnumconv2(&ind[num].p[j]);
if (epage==bpage) {
j=cc-1;
continue;
@@ -365,13 +379,13 @@ static void printpage(struct index *ind, FILE *fp, int num, char *lbuff)
}
/* print beginning of range */
SAPPENDF(buff,"%s",ind[num].p[j].page);
- if (strlen(suffix_3p)>0 && (epage-bpage)==2) {
+ if (strlen(suffix_3p)>0 && epage-bpage==2) {
SAPPENDF(buff,"%s",suffix_3p);
}
- else if (strlen(suffix_mp)>0 && (epage-bpage)>=2) {
+ else if (strlen(suffix_mp)>0 && epage-bpage>=2) {
SAPPENDF(buff,"%s",suffix_mp);
}
- else if (strlen(suffix_2p)>0 && (epage-bpage)==1) {
+ else if (strlen(suffix_2p)>0 && epage-bpage==1) {
SAPPENDF(buff,"%s",suffix_2p);
}
else {
@@ -383,14 +397,14 @@ static void printpage(struct index *ind, FILE *fp, int num, char *lbuff)
if (strlen(ind[num].p[j].enc)>0) {
SAPPENDF(tmpbuff,"%s",encap_suffix);
}
- linecheck(lbuff,tmpbuff);
+ linecheck(lbuff,tmpbuff, FALSE);
j=cc;
if (j==ind[num].num) {
goto PRINT;
}
else {
SAPPENDF(tmpbuff,"%s",delim_n);
- linecheck(lbuff,tmpbuff);
+ linecheck(lbuff,tmpbuff, TRUE);
}
}
else if (strlen(ind[num].p[j].enc)>0) {
@@ -411,19 +425,19 @@ static void printpage(struct index *ind, FILE *fp, int num, char *lbuff)
SAPPENDF(tmpbuff,"%s",ind[num].p[j].page);
SAPPENDF(tmpbuff,"%s",encap_suffix);
SAPPENDF(tmpbuff,"%s",delim_n);
- linecheck(lbuff,tmpbuff);
+ linecheck(lbuff,tmpbuff, FALSE);
}
else {
SAPPENDF(tmpbuff,"%s",ind[num].p[j].page);
SAPPENDF(tmpbuff,"%s",delim_n);
- linecheck(lbuff,tmpbuff);
+ linecheck(lbuff,tmpbuff, FALSE);
}
}
else {
/* no encap */
SAPPENDF(tmpbuff,"%s",ind[num].p[j].page);
SAPPENDF(tmpbuff,"%s",delim_n);
- linecheck(lbuff,tmpbuff);
+ linecheck(lbuff,tmpbuff, FALSE);
}
}
@@ -455,7 +469,7 @@ static void printpage(struct index *ind, FILE *fp, int num, char *lbuff)
else {
SAPPENDF(tmpbuff,"%s",ind[num].p[j].page);
}
- linecheck(lbuff,tmpbuff);
+ linecheck(lbuff,tmpbuff, FALSE);
PRINT:
fputs(lbuff,fp);
@@ -499,7 +513,7 @@ static int range_check(struct index ind, int count, char *lbuff)
if (strlen(ind.p[j].enc)>0) {
SPRINTF(tmpbuff,"%s%s%s%s%s%s",encap_prefix,ind.p[j].enc,encap_infix
,ind.p[j].page,encap_suffix,delim_n);
- linecheck(lbuff,tmpbuff);
+ linecheck(lbuff,tmpbuff, FALSE);
}
}
}
@@ -528,8 +542,8 @@ static int range_check(struct index ind, int count, char *lbuff)
break;
}
}
- cc1=pnumconv(ind.p[i-1].page,ind.p[i-1].attr[0]);
- cc2=pnumconv(ind.p[count].page,ind.p[count].attr[0]);
+ cc1=pnumconv2(&ind.p[i-1]);
+ cc2=pnumconv2(&ind.p[count]);
if (cc1>=cc2+2 || (cc1>=cc2+1 && strlen(suffix_2p)) || force) {
return i-1;
}
@@ -537,9 +551,9 @@ static int range_check(struct index ind, int count, char *lbuff)
}
/* check line length */
-static void linecheck(char *lbuff, char *tmpbuff)
+static void linecheck(char *lbuff, char *tmpbuff, int force)
{
- if (line_length+strlen(tmpbuff)>line_max) {
+ if (line_length+strlen(tmpbuff)>line_max && !force) {
SAPPENDF(lbuff,"\n");
SAPPENDF(lbuff,"%s",indent_space);
SAPPENDF(lbuff,"%s",tmpbuff);
diff --git a/Build/source/texk/mendexk/mendex.h b/Build/source/texk/mendexk/mendex.h
index 1c0190c2822..6244c24fd12 100644
--- a/Build/source/texk/mendexk/mendex.h
+++ b/Build/source/texk/mendexk/mendex.h
@@ -11,10 +11,12 @@
#define nkf_close(fp) {clear_infile_enc(fp); fclose(fp);}
#endif
+#define PAGE_COMPOSIT_DEPTH 10
+
struct page {
char *page;
char *enc;
- int attr[3];
+ int attr[PAGE_COMPOSIT_DEPTH];
};
struct index {
diff --git a/Build/source/texk/mendexk/sort.c b/Build/source/texk/mendexk/sort.c
index 6ab458ee02c..19e04298fc4 100644
--- a/Build/source/texk/mendexk/sort.c
+++ b/Build/source/texk/mendexk/sort.c
@@ -62,6 +62,8 @@ static int wcomp(const void *p, const void *q)
{
int i, j, prechar = 0;
const struct index *index1 = p, *index2 = q;
+ char ch1, ch2;
+ char *str1, *str2;
scount++;
@@ -73,49 +75,54 @@ static int wcomp(const void *p, const void *q)
for(i=0;;i++) {
+ str1=&((*index1).dic[j][i]);
+ str2=&((*index2).dic[j][i]);
+ ch1=(*index1).dic[j][i];
+ ch2=(*index2).dic[j][i];
+
/* even */
- if (((*index1).dic[j][i]=='\0')&&((*index2).dic[j][i]=='\0')) break;
+ if ((ch1=='\0')&&(ch2=='\0')) break;
/* index1 is shorter */
- if ((*index1).dic[j][i]=='\0') return -1;
+ if (ch1=='\0') return -1;
/* index2 is shorter */
- if ((*index2).dic[j][i]=='\0') return 1;
+ if (ch2=='\0') return 1;
/* priority */
if ((priority!=0)&&(i>0)) {
if (prechar==0) {
- if ((japanese(&(*index1).dic[j][i]))
- &&(!japanese(&(*index2).dic[j][i])))
+ if ((japanese(str1))
+ &&(!japanese(str2)))
return -1;
- if ((japanese(&(*index2).dic[j][i]))
- &&(!japanese(&(*index1).dic[j][i])))
+ if ((japanese(str2))
+ &&(!japanese(str1)))
return 1;
}
else {
- if ((japanese(&(*index1).dic[j][i]))
- &&(!japanese(&(*index2).dic[j][i])))
+ if ((japanese(str1))
+ &&(!japanese(str2)))
return 1;
- if ((japanese(&(*index2).dic[j][i]))
- &&(!japanese(&(*index1).dic[j][i])))
+ if ((japanese(str2))
+ &&(!japanese(str1)))
return -1;
}
}
/* compare group */
- if (ordering(&(*index1).dic[j][i])<ordering(&(*index2).dic[j][i]))
+ if (ordering(str1)<ordering(str2))
return -1;
- if (ordering(&(*index1).dic[j][i])>ordering(&(*index2).dic[j][i]))
+ if (ordering(str1)>ordering(str2))
return 1;
/* symbol pattern */
- if ((!numeric(&(*index1).dic[j][i]))&&(numeric(&(*index2).dic[j][i])))
+ if ((!numeric(str1))&&(numeric(str2)))
return -1;
- if ((!numeric(&(*index2).dic[j][i]))&&(numeric(&(*index1).dic[j][i])))
+ if ((!numeric(str2))&&(numeric(str1)))
return 1;
/* simple compare */
@@ -169,12 +176,12 @@ void pagesort(struct index *ind, int num)
static int pcomp(const void *p, const void *q)
{
int i,j,cc=0,num1,num2;
- char buff[16];
+ char buff[16],*p0,*p1;
const struct page *page1 = p, *page2 = q;
scount++;
- for (i=0;i<3;i++) {
+ for (i=0;i<PAGE_COMPOSIT_DEPTH;i++) {
if ((page1->attr[i]<0)&&(page2->attr[i]<0)) return 0;
else if ((page1->attr[i]<0)&&(page2->attr[i]>=0)) return -1;
else if ((page2->attr[i]<0)&&(page1->attr[i]>=0)) return 1;
@@ -182,18 +189,18 @@ static int pcomp(const void *p, const void *q)
if (page1->attr[i]>page2->attr[i]) return 1;
if (page1->attr[i]<page2->attr[i]) return -1;
- for (j=cc;j<strlen(page1->page);j++) {
- if (strncmp(&page1->page[j],page_compositor,strlen(page_compositor))==0) break;
- }
- strncpy(buff,&page1->page[cc],j-cc);
- buff[j-cc]='\0';
+ p0=&page1->page[cc];
+ p1=strstr(p0, page_compositor);
+ j=p1 ? p1-p0 : strlen(p0);
+ strncpy(buff,p0,j);
+ buff[j]='\0';
num1=pnumconv(buff,page1->attr[i]);
- for (j=cc;j<strlen(page2->page);j++) {
- if (strncmp(&page2->page[j],page_compositor,strlen(page_compositor))==0) break;
- }
- strncpy(buff,&page2->page[cc],j-cc);
- buff[j-cc]='\0';
+ p0=&page2->page[cc];
+ p1=strstr(p0, page_compositor);
+ j=p1 ? p1-p0 : strlen(p0);
+ strncpy(buff,p0,j);
+ buff[j]='\0';
num2=pnumconv(buff,page2->attr[i]);
if (num1>num2) return 1;
@@ -202,7 +209,8 @@ static int pcomp(const void *p, const void *q)
if (page1->enc[0]=='(' || page2->enc[0]==')') return -1;
if (page1->enc[0]==')' || page2->enc[0]=='(') return 1;
- cc=j+strlen(page_compositor);
+ if (p1) cc+=j+strlen(page_compositor);
+ else return 0;
}
return 0;
@@ -248,35 +256,48 @@ int japanese(char *buff)
int chkcontinue(struct page *p, int num)
{
- int i,j,cc=0,num1,num2;
- char buff[16];
+ int i,j,cc=0,num1,num2,k1,k2;
+ char buff1[16],buff2[16],*p0,*p1;
- for (i=0;i<3;i++) {
+ for (i=0;i<PAGE_COMPOSIT_DEPTH;i++) {
if ((p[num].attr[i]<0)&&(p[num+1].attr[i]<0)) return 1;
else if (p[num].attr[i]!=p[num+1].attr[i]) return 0;
- for (j=cc;j<strlen(p[num].page);j++) {
- if (strncmp(&p[num].page[j],page_compositor,strlen(page_compositor))==0) break;
+ p0=&p[num].page[cc];
+ p1=strstr(p0, page_compositor);
+ if (p1) {
+ j=p1-p0;
+ k1=j;
+ } else {
+ j=strlen(p0);
+ k1=0;
}
- strncpy(buff,&p[num].page[cc],j);
- buff[j]='\0';
- num1=pnumconv(buff,p[num].attr[i]);
-
- for (j=cc;j<strlen(p[num+1].page);j++) {
- if (strncmp(&p[num+1].page[j],page_compositor,strlen(page_compositor))==0) break;
+ strncpy(buff1,p0,j);
+ buff1[j]='\0';
+ num1=pnumconv(buff1,p[num].attr[i]);
+
+ p0=&p[num+1].page[cc];
+ p1=strstr(p0, page_compositor);
+ if (p1) {
+ j=p1-p0;
+ k2=j;
+ } else {
+ j=strlen(p0);
+ k2=0;
}
- strncpy(buff,&p[num+1].page[cc],j);
- buff[j]='\0';
- num2=pnumconv(buff,p[num+1].attr[i]);
-
- if (num1==num2 || num1+1==num2) {
- if (i==2) return 1;
- if ((p[num].attr[i+1]<0)&&(p[num+1].attr[i+1]<0)) return 1;
- else return 0;
+ strncpy(buff2,p0,j);
+ buff2[j]='\0';
+ num2=pnumconv(buff2,p[num+1].attr[i]);
+
+ if (k1>0 || k2>0) {
+ if (k1!=k2) return 0;
+ if (strcmp(buff1,buff2)) return 0;
+ cc+=k1+strlen(page_compositor);
+ continue;
}
- else if (num1!=num2) return 0;
- cc=j+strlen(page_compositor);
+ if (num1==num2 || num1+1==num2) return 1;
+ else return 0;
}
return 1;
diff --git a/Build/source/texk/mendexk/tests/mendex.test b/Build/source/texk/mendexk/tests/mendex.test
index 1641ee898b8..e4b36caa8af 100755
--- a/Build/source/texk/mendexk/tests/mendex.test
+++ b/Build/source/texk/mendexk/tests/mendex.test
@@ -28,10 +28,18 @@ cat $srcdir/tests/uni.idx | \
$srcdir/tests/uni.idx -o uni.ind3 -t uni.ilg3 \
&& diff $srcdir/tests/uni.ind uni.ind3 || exit 1
-# test for two-element range suffix_2p
-./mendex -s $srcdir/tests/rangetwo.ist $srcdir/tests/rangetwo.idx \
- -o rangetwo.ind1 -t rangetwo.ilg \
- && diff $srcdir/tests/rangetwo.ind rangetwo.ind1 || exit 1
+# test for range suffix_2p, suffix_3p, suffix_mp
+./mendex -s $srcdir/tests/range1.ist $srcdir/tests/range.idx \
+ -o range1.ind1 -t range1.ilg \
+ && diff $srcdir/tests/range1.ind range1.ind1 || exit 1
+
+./mendex -s $srcdir/tests/range2.ist $srcdir/tests/range.idx \
+ -o range2.ind1 -t range2.ilg \
+ && diff $srcdir/tests/range2.ind range2.ind1 || exit 1
+
+./mendex -s $srcdir/tests/range3.ist $srcdir/tests/range.idx \
+ -o range3.ind1 -t range3.ilg \
+ && diff $srcdir/tests/range3.ind range3.ind1 || exit 1
# test for page_precedence and suffix_3p
./mendex -s $srcdir/tests/pprec0.ist $srcdir/tests/pprecA.idx \
diff --git a/Build/source/texk/mendexk/tests/range.idx b/Build/source/texk/mendexk/tests/range.idx
new file mode 100644
index 00000000000..e77882010c6
--- /dev/null
+++ b/Build/source/texk/mendexk/tests/range.idx
@@ -0,0 +1,126 @@
+\indexentry{entryA}{1}
+\indexentry{entryA}{2}
+\indexentry{entryA}{iii}
+\indexentry{entryA}{iv}
+\indexentry{entryA}{IX}
+\indexentry{entryA}{X}
+
+\indexentry{entryB}{1}
+\indexentry{entryB}{2}
+\indexentry{entryB}{3}
+\indexentry{entryB}{iii}
+\indexentry{entryB}{iv}
+\indexentry{entryB}{v}
+\indexentry{entryB}{IX}
+\indexentry{entryB}{X}
+\indexentry{entryB}{XI}
+
+\indexentry{entryC}{1}
+\indexentry{entryC}{2}
+\indexentry{entryC}{3}
+\indexentry{entryC}{4}
+\indexentry{entryC|bold}{iii}
+\indexentry{entryC|bold}{iv}
+\indexentry{entryC|bold}{v}
+\indexentry{entryC|bold}{vi}
+\indexentry{entryC}{IX}
+\indexentry{entryC|bold}{X}
+\indexentry{entryC}{XI}
+\indexentry{entryC}{XII}
+
+\indexentry{entryD}{c-1}
+\indexentry{entryD}{c-2}
+\indexentry{entryD}{i-iii}
+\indexentry{entryD}{i-iv}
+\indexentry{entryD}{d-IX}
+\indexentry{entryD}{d-X}
+
+\indexentry{entryE}{c-1}
+\indexentry{entryE}{c-2}
+\indexentry{entryE}{c-3}
+\indexentry{entryE}{i-iii}
+\indexentry{entryE}{i-iv}
+\indexentry{entryE}{i-v}
+\indexentry{entryE}{d-IX}
+\indexentry{entryE}{d-X}
+\indexentry{entryE}{d-XI}
+
+\indexentry{entryF}{C-I}
+\indexentry{entryF}{C-II}
+\indexentry{entryF}{C-III}
+\indexentry{entryF}{C-IV}
+\indexentry{entryF}{V-LIII}
+\indexentry{entryF}{V-LIV}
+\indexentry{entryF}{V-LV}
+\indexentry{entryF}{V-LVI}
+\indexentry{entryF}{D-DI}
+\indexentry{entryF}{D-DII}
+\indexentry{entryF}{D-DIII}
+\indexentry{entryF}{D-DIV}
+
+\indexentry{entryP}{A-a-1-I-iii}
+\indexentry{entryP}{A-a-2-I-iii}
+\indexentry{entryP}{A-a-3-I-iii}
+\indexentry{entryP}{A-a-1-II-iii}
+\indexentry{entryP}{A-a-1-III-iii}
+\indexentry{entryP}{A-a-1-I-iv}
+\indexentry{entryP}{A-a-1-I-v}
+
+\indexentry{entryQ}{1-2-3-4-5-6-7-8-9-10}
+\indexentry{entryQ}{1-2-3-4-5-6-7-8-9-11}
+\indexentry{entryQ}{1-2-3-4-5-6-7-8-9-14}
+\indexentry{entryQ}{1-2-3-4-5-6-7-8-9-15}
+\indexentry{entryQ}{1-2-3-4-5-6-7-8-9-16}
+\indexentry{entryQ}{1-2-3-4-5-6-7-8-9-22}
+\indexentry{entryQ}{1-2-3-4-5-6-7-8-9-23}
+\indexentry{entryQ}{1-2-3-4-5-6-7-8-9-24}
+\indexentry{entryQ}{1-2-3-4-5-6-7-8-9-25}
+\indexentry{entryQ}{1-2-3-4-5-6-7-8-9-i}
+\indexentry{entryQ}{1-2-3-4-5-6-7-8-9-ii}
+\indexentry{entryQ}{1-2-3-4-5-6-7-8-9-iii}
+\indexentry{entryQ}{1-2-3-4-5-6-7-8-9-iv}
+\indexentry{entryQ}{1-2-3-4-5-6-7-8-9-v}
+
+\indexentry{entryA1|(}{1}
+\indexentry{entryA1|)}{2}
+\indexentry{entryA1|(}{iii}
+\indexentry{entryA1|)}{iv}
+\indexentry{entryA1|(}{IX}
+\indexentry{entryA1|)}{X}
+
+\indexentry{entryB1|(}{1}
+\indexentry{entryB1|)}{3}
+\indexentry{entryB1|(}{iii}
+\indexentry{entryB1|)}{v}
+\indexentry{entryB1|(}{IX}
+\indexentry{entryB1|)}{XI}
+
+\indexentry{entryC1|(}{1}
+\indexentry{entryC1|)}{4}
+\indexentry{entryC1|(bold}{iii}
+\indexentry{entryC1|)}{vi}
+\indexentry{entryC1|(}{IX}
+\indexentry{entryC1|bold}{X}
+\indexentry{entryC1|)}{XII}
+
+\indexentry{entryD1|(}{c-1}
+\indexentry{entryD1|)}{c-2}
+\indexentry{entryD1|(}{i-iii}
+\indexentry{entryD1|)}{i-iv}
+\indexentry{entryD1|(}{d-IX}
+\indexentry{entryD1|)}{d-X}
+
+\indexentry{entryE1|(}{c-1}
+\indexentry{entryE1|)}{c-3}
+\indexentry{entryE1|(}{i-iii}
+\indexentry{entryE1|)}{i-v}
+\indexentry{entryE1|(}{d-IX}
+\indexentry{entryE1|)}{d-XI}
+
+\indexentry{entryF1|(}{C-I}
+\indexentry{entryF1|)}{C-IV}
+\indexentry{entryF1|(}{V-LIII}
+\indexentry{entryF1|)}{V-LVI}
+\indexentry{entryF1|(}{D-DI}
+\indexentry{entryF1|bold}{D-DII}
+\indexentry{entryF1|)}{D-DIV}
diff --git a/Build/source/texk/mendexk/tests/range1.ind b/Build/source/texk/mendexk/tests/range1.ind
new file mode 100644
index 00000000000..0dc1d842a9f
--- /dev/null
+++ b/Build/source/texk/mendexk/tests/range1.ind
@@ -0,0 +1,25 @@
+\begin{theindex}
+
+ \item entryA, 1[[sfx 2p]], iii[[sfx 2p]], IX[[sfx 2p]]
+ \item entryA1, 1[[sfx 2p]], iii[[sfx 2p]], IX[[sfx 2p]]
+ \item entryB, 1[[sfx mp]], iii[[sfx mp]], IX[[sfx mp]]
+ \item entryB1, 1[[sfx mp]], iii[[sfx mp]], IX[[sfx mp]]
+ \item entryC, 1[[sfx mp]], \bold{iii[[sfx mp]]}, IX, \bold{X},
+ XI[[sfx 2p]]
+ \item entryC1, 1[[sfx mp]], \bold{iii[[sfx mp]]}, \bold{X},
+ IX[[sfx mp]]
+ \item entryD, c-1[[sfx 2p]], d-IX[[sfx 2p]], i-iii[[sfx 2p]]
+ \item entryD1, c-1[[sfx 2p]], d-IX[[sfx 2p]], i-iii[[sfx 2p]]
+ \item entryE, c-1[[sfx mp]], d-IX[[sfx mp]], i-iii[[sfx mp]]
+ \item entryE1, c-1[[sfx mp]], d-IX[[sfx mp]], i-iii[[sfx mp]]
+ \item entryF, C-I[[sfx mp]], D-DI[[sfx mp]], V-LIII[[sfx mp]]
+ \item entryF1, C-I[[sfx mp]], \bold{D-DII}, D-DI[[sfx mp]],
+ V-LIII[[sfx mp]]
+ \item entryP, A-a-1-I-iii[[sfx mp]], A-a-1-II-iii, A-a-1-III-iii,
+ A-a-2-I-iii, A-a-3-I-iii
+ \item entryQ, 1-2-3-4-5-6-7-8-9-10[[sfx 2p]],
+ 1-2-3-4-5-6-7-8-9-14[[sfx mp]],
+ 1-2-3-4-5-6-7-8-9-22[[sfx mp]],
+ 1-2-3-4-5-6-7-8-9-i[[sfx mp]]
+
+\end{theindex}
diff --git a/Build/source/texk/mendexk/tests/range1.ist b/Build/source/texk/mendexk/tests/range1.ist
new file mode 100644
index 00000000000..116c2d8713b
--- /dev/null
+++ b/Build/source/texk/mendexk/tests/range1.ist
@@ -0,0 +1,3 @@
+page_precedence "nrRaA"
+suffix_2p "[[sfx 2p]]"
+suffix_mp "[[sfx mp]]"
diff --git a/Build/source/texk/mendexk/tests/range2.ind b/Build/source/texk/mendexk/tests/range2.ind
new file mode 100644
index 00000000000..9e0bd8ce5e3
--- /dev/null
+++ b/Build/source/texk/mendexk/tests/range2.ind
@@ -0,0 +1,26 @@
+\begin{theindex}
+
+ \item entryA, 1[[sfx 2p]], iii[[sfx 2p]], IX[[sfx 2p]]
+ \item entryA1, 1[[sfx 2p]], iii[[sfx 2p]], IX[[sfx 2p]]
+ \item entryB, 1[[sfx 3p]], iii[[sfx 3p]], IX[[sfx 3p]]
+ \item entryB1, 1[[sfx 3p]], iii[[sfx 3p]], IX[[sfx 3p]]
+ \item entryC, 1[[delim r]]4, \bold{iii[[delim r]]vi}, IX, \bold{X},
+ XI[[sfx 2p]]
+ \item entryC1, 1[[delim r]]4, \bold{iii[[delim r]]vi}, \bold{X},
+ IX[[delim r]]XII
+ \item entryD, c-1[[sfx 2p]], d-IX[[sfx 2p]], i-iii[[sfx 2p]]
+ \item entryD1, c-1[[sfx 2p]], d-IX[[sfx 2p]], i-iii[[sfx 2p]]
+ \item entryE, c-1[[sfx 3p]], d-IX[[sfx 3p]], i-iii[[sfx 3p]]
+ \item entryE1, c-1[[sfx 3p]], d-IX[[sfx 3p]], i-iii[[sfx 3p]]
+ \item entryF, C-I[[delim r]]C-IV, D-DI[[delim r]]D-DIV,
+ V-LIII[[delim r]]V-LVI
+ \item entryF1, C-I[[delim r]]C-IV, \bold{D-DII}, D-DI[[delim r]]D-DIV,
+ V-LIII[[delim r]]V-LVI
+ \item entryP, A-a-1-I-iii[[sfx 3p]], A-a-1-II-iii, A-a-1-III-iii,
+ A-a-2-I-iii, A-a-3-I-iii
+ \item entryQ, 1-2-3-4-5-6-7-8-9-10[[sfx 2p]],
+ 1-2-3-4-5-6-7-8-9-14[[sfx 3p]],
+ 1-2-3-4-5-6-7-8-9-22[[delim r]]1-2-3-4-5-6-7-8-9-25,
+ 1-2-3-4-5-6-7-8-9-i[[delim r]]1-2-3-4-5-6-7-8-9-v
+
+\end{theindex}
diff --git a/Build/source/texk/mendexk/tests/range2.ist b/Build/source/texk/mendexk/tests/range2.ist
new file mode 100644
index 00000000000..552e5fb6748
--- /dev/null
+++ b/Build/source/texk/mendexk/tests/range2.ist
@@ -0,0 +1,4 @@
+page_precedence "nrRaA"
+delim_r "[[delim r]]"
+suffix_2p "[[sfx 2p]]"
+suffix_3p "[[sfx 3p]]"
diff --git a/Build/source/texk/mendexk/tests/range3.ind b/Build/source/texk/mendexk/tests/range3.ind
new file mode 100644
index 00000000000..f5b5f5268ff
--- /dev/null
+++ b/Build/source/texk/mendexk/tests/range3.ind
@@ -0,0 +1,25 @@
+\begin{theindex}
+
+ \item entryA, 1[[sfx 2p]], iii[[sfx 2p]], IX[[sfx 2p]]
+ \item entryA1, 1[[sfx 2p]], iii[[sfx 2p]], IX[[sfx 2p]]
+ \item entryB, 1[[sfx 3p]], iii[[sfx 3p]], IX[[sfx 3p]]
+ \item entryB1, 1[[sfx 3p]], iii[[sfx 3p]], IX[[sfx 3p]]
+ \item entryC, 1[[sfx mp]], \bold{iii[[sfx mp]]}, IX, \bold{X},
+ XI[[sfx 2p]]
+ \item entryC1, 1[[sfx mp]], \bold{iii[[sfx mp]]}, \bold{X},
+ IX[[sfx mp]]
+ \item entryD, c-1[[sfx 2p]], d-IX[[sfx 2p]], i-iii[[sfx 2p]]
+ \item entryD1, c-1[[sfx 2p]], d-IX[[sfx 2p]], i-iii[[sfx 2p]]
+ \item entryE, c-1[[sfx 3p]], d-IX[[sfx 3p]], i-iii[[sfx 3p]]
+ \item entryE1, c-1[[sfx 3p]], d-IX[[sfx 3p]], i-iii[[sfx 3p]]
+ \item entryF, C-I[[sfx mp]], D-DI[[sfx mp]], V-LIII[[sfx mp]]
+ \item entryF1, C-I[[sfx mp]], \bold{D-DII}, D-DI[[sfx mp]],
+ V-LIII[[sfx mp]]
+ \item entryP, A-a-1-I-iii[[sfx 3p]], A-a-1-II-iii, A-a-1-III-iii,
+ A-a-2-I-iii, A-a-3-I-iii
+ \item entryQ, 1-2-3-4-5-6-7-8-9-10[[sfx 2p]],
+ 1-2-3-4-5-6-7-8-9-14[[sfx 3p]],
+ 1-2-3-4-5-6-7-8-9-22[[sfx mp]],
+ 1-2-3-4-5-6-7-8-9-i[[sfx mp]]
+
+\end{theindex}
diff --git a/Build/source/texk/mendexk/tests/range3.ist b/Build/source/texk/mendexk/tests/range3.ist
new file mode 100644
index 00000000000..b751471b432
--- /dev/null
+++ b/Build/source/texk/mendexk/tests/range3.ist
@@ -0,0 +1,4 @@
+page_precedence "nrRaA"
+suffix_2p "[[sfx 2p]]"
+suffix_3p "[[sfx 3p]]"
+suffix_mp "[[sfx mp]]"
diff --git a/Build/source/texk/mendexk/tests/rangetwo.idx b/Build/source/texk/mendexk/tests/rangetwo.idx
deleted file mode 100644
index d941f7e8315..00000000000
--- a/Build/source/texk/mendexk/tests/rangetwo.idx
+++ /dev/null
@@ -1,2 +0,0 @@
-\indexentry{entryA}{1}
-\indexentry{entryA}{2}
diff --git a/Build/source/texk/mendexk/tests/rangetwo.ind b/Build/source/texk/mendexk/tests/rangetwo.ind
deleted file mode 100644
index 1119d2fa8e9..00000000000
--- a/Build/source/texk/mendexk/tests/rangetwo.ind
+++ /dev/null
@@ -1,5 +0,0 @@
-\begin{theindex}
-
- \item entryA, 1[[sfx2p]]
-
-\end{theindex}
diff --git a/Build/source/texk/mendexk/tests/rangetwo.ist b/Build/source/texk/mendexk/tests/rangetwo.ist
deleted file mode 100644
index 3e986c8935d..00000000000
--- a/Build/source/texk/mendexk/tests/rangetwo.ist
+++ /dev/null
@@ -1,2 +0,0 @@
-suffix_2p "[[sfx2p]]"
-
diff --git a/Build/source/texk/mendexk/var.h b/Build/source/texk/mendexk/var.h
index b538988c9e2..d99218f43a1 100644
--- a/Build/source/texk/mendexk/var.h
+++ b/Build/source/texk/mendexk/var.h
@@ -4,7 +4,7 @@ FILE *efp;
int lines,idxcount,acc=0,reject=0;
int prange=1,fsti=0,lorder=0,bcomp=0,force=0,fpage=0,gflg=0,verb=1,debug=0;
-int warn=0,scount=0,pattr[3]={0,0,0};
+int warn=0,scount=0,pattr[PAGE_COMPOSIT_DEPTH]={0};
/* static char roman[]={"ivxlcdm"},Roman[]={"IVXLCDM"}; */
struct index *ind;
diff --git a/Build/source/texk/mendexk/version.h b/Build/source/texk/mendexk/version.h
index b3fe113f399..20204067866 100644
--- a/Build/source/texk/mendexk/version.h
+++ b/Build/source/texk/mendexk/version.h
@@ -1,2 +1,2 @@
-#define VERSION "version " PACKAGE_VERSION " [4-Sep-2021]"
+#define VERSION "version " PACKAGE_VERSION " [18-Sep-2021]"
#define BUG_ADDRESS "issue@texjp.org"