Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Commit

Permalink
mendex: improve multi-levels of page numbers
Browse files Browse the repository at this point in the history
git-svn-id: svn://tug.org/texlive/trunk/Build/source@60534 c570f23f-e606-0410-a88d-b1316a301751
  • Loading branch information
takuji committed Sep 18, 2021
1 parent 73c520f commit fd35c8c
Show file tree
Hide file tree
Showing 19 changed files with 399 additions and 102 deletions.
17 changes: 16 additions & 1 deletion 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.
Expand Down
2 changes: 1 addition & 1 deletion texk/mendexk/exvar.h
Expand Up @@ -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;

Expand Down
65 changes: 49 additions & 16 deletions texk/mendexk/fread.c
Expand Up @@ -456,69 +456,102 @@ 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;
goto 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;
goto 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;
goto 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;
goto 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;
goto 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);
}
}
}
Expand Down
52 changes: 33 additions & 19 deletions texk/mendexk/fwrite.c
Expand Up @@ -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. */
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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) {
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -528,18 +542,18 @@ 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;
}
else return count;
}

/* 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);
Expand Down
4 changes: 3 additions & 1 deletion texk/mendexk/mendex.h
Expand Up @@ -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 {
Expand Down

0 comments on commit fd35c8c

Please sign in to comment.