diff options
author | Takuji Tanaka <ttk@t-lab.opal.ne.jp> | 2022-05-22 12:54:19 +0000 |
---|---|---|
committer | Takuji Tanaka <ttk@t-lab.opal.ne.jp> | 2022-05-22 12:54:19 +0000 |
commit | ca18c962f63ce9d55873266c577f8bc909088174 (patch) | |
tree | 67dbec68820e2b9cfdfd31871290ed7b2498bb71 /Build/source/texk/makeindexk/scanid.c | |
parent | 63bbba4973d4a37fe7b9e0665e11456802d80aaf (diff) |
makeindex: Improve heuristic detection of page number types
git-svn-id: svn://tug.org/texlive/trunk@63361 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/makeindexk/scanid.c')
-rw-r--r-- | Build/source/texk/makeindexk/scanid.c | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/Build/source/texk/makeindexk/scanid.c b/Build/source/texk/makeindexk/scanid.c index aea5272d47e..cda14868147 100644 --- a/Build/source/texk/makeindexk/scanid.c +++ b/Build/source/texk/makeindexk/scanid.c @@ -418,6 +418,39 @@ static int scan_no(char no[], int npg[], short *count, short *type) { int i = 1; + static int type_guess[PAGEFIELD_MAX] = + {EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY}; + + /* heuristic detection if a letter is Roman or Alpha :: + "IVX" as roman number since I=1, V=5, X=10 are quite small + "LCDM" as alphabet since L=50, C=100, D=100, M=1000 are quite large */ + if (isdigit((unsigned char)no[0])) { + type_guess[*count] = ARAB; + } else if (IS_ROMAN_LOWER(no[0]) && IS_ALPHA_LOWER(no[0]) + && strchr(page_prec,ROMAN_LOWER) && strchr(page_prec,ALPHA_LOWER)) { + if (strspn(no,"ivxlcdm")==1 /* ambiguous */ + && type_guess[*count] != ROML && type_guess[*count] != ALPL) { + type_guess[*count] = strspn(no,"ivx")==1 ? ROML : ALPL; + } + if (strspn(no,"ivxlcdm")>1) type_guess[*count] = ROML; + } else if (IS_ROMAN_UPPER(no[0]) && IS_ALPHA_UPPER(no[0]) + && strchr(page_prec,ROMAN_LOWER) && strchr(page_prec,ALPHA_LOWER)) { + if (strspn(no,"IVXLCDM")==1 /* ambiguous */ + && type_guess[*count] != ROMU && type_guess[*count] != ALPU) { + type_guess[*count] = strspn(no,"IVX")==1 ? ROMU : ALPU; + } + if (strspn(no,"IVXLCDM")>1) type_guess[*count] = ROMU; + } else if (IS_ROMAN_LOWER(no[0]) && strchr(page_prec,ROMAN_LOWER)) { + type_guess[*count] = ROML; + } else if (IS_ROMAN_UPPER(no[0]) && strchr(page_prec,ROMAN_UPPER)) { + type_guess[*count] = ROMU; + } else if (IS_ALPHA_LOWER(no[0]) && strchr(page_prec,ALPHA_LOWER)) { + type_guess[*count] = ALPL; + } else if (IS_ALPHA_UPPER(no[0]) && strchr(page_prec,ALPHA_UPPER)) { + type_guess[*count] = ALPU; + } else { + type_guess[*count] = EMPTY; + } if (isdigit((unsigned char)no[0])) { *type = ARAB; @@ -425,13 +458,13 @@ scan_no(char no[], int npg[], short *count, short *type) return (FALSE); /* simple heuristic to determine if a letter is Roman or Alpha */ } else if (IS_ROMAN_LOWER(no[0]) && strchr(page_prec,ROMAN_LOWER) && - (!strchr(page_prec,ALPHA_LOWER) || (!IS_COMPOSITOR))) { + (!strchr(page_prec,ALPHA_LOWER) || type_guess[*count] == ROML) ) { *type = ROML; if (!scan_roman_lower(no, npg, count)) return (FALSE); /* simple heuristic to determine if a letter is Roman or Alpha */ } else if (IS_ROMAN_UPPER(no[0]) && strchr(page_prec,ROMAN_UPPER) && - (!strchr(page_prec,ALPHA_UPPER) || (!IS_COMPOSITOR))) { + (!strchr(page_prec,ALPHA_UPPER) || type_guess[*count] == ROMU) ) { *type = ROMU; if (!scan_roman_upper(no, npg, count)) return (FALSE); |