From a9e05811d1d1a04b467aac0678e8f3fdbb2c7ab1 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 12 Jun 2016 18:19:07 +0000 Subject: \pdflastmatch: more checks if no preceding match, from pdftex r759 git-svn-id: svn://tug.org/texlive/trunk@41418 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/web2c/pdftexdir/utils.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'Build/source/texk/web2c/pdftexdir/utils.c') diff --git a/Build/source/texk/web2c/pdftexdir/utils.c b/Build/source/texk/web2c/pdftexdir/utils.c index 88b8f09e11c..67ff8e9db46 100644 --- a/Build/source/texk/web2c/pdftexdir/utils.c +++ b/Build/source/texk/web2c/pdftexdir/utils.c @@ -817,12 +817,16 @@ void printmoddate(void) pdf_printf("/ModDate (%s)\n", start_time_str); } + #define DEFAULT_SUB_MATCH_COUNT 10 static int sub_match_count = DEFAULT_SUB_MATCH_COUNT; static regmatch_t *pmatch = NULL; static char *match_string = NULL; +static int last_match_succeeded = 0; -void matchstrings(strnumber s, strnumber t, int subcount, boolean icase) +/* Implements \pdfmatch */ +void +matchstrings(strnumber s, strnumber t, int subcount, boolean icase) { regex_t preg; int cflags = REG_EXTENDED; @@ -857,20 +861,31 @@ void matchstrings(strnumber s, strnumber t, int subcount, boolean icase) pmatch = xtalloc(sub_match_count, regmatch_t); } ret = regexec(&preg, str, sub_match_count, pmatch, eflags); + xfree(match_string); - match_string = xstrdup(str); - strpool[poolptr++] = ((ret == 0) ? '1' : '0'); + match_string = xstrdup(str); /* save searched-in string, used below */ + last_match_succeeded = ret == 0; /* save whether match succeeded */ + strpool[poolptr++] = ((ret == 0) ? '1' : '0'); /* in string pool too */ } regfree(&preg); } -void getmatch(int i) +/* Implements \pdflastmatch */ + +void +getmatch(int i) { - int size, len = 0; /* to avoid warning about uninitialized use of len */ + int size; + int len = 0; /* avoid spurious uninitialized warning */ - boolean found = i < sub_match_count - && match_string != NULL && pmatch[i].rm_so >= 0 && i >= 0; + boolean found + = i >= 0 /* should always be so due to pdftex.web */ + && i < sub_match_count /* if >subcount, not found by definition */ + && match_string != NULL /* first call, and just in case */ + && last_match_succeeded /* if no match, not found */ + && pmatch[i].rm_so >= 0 /* if no starting position, not found */ + && pmatch[i].rm_eo >= pmatch[i].rm_so; /* just in case */ if (found) { len = pmatch[i].rm_eo - pmatch[i].rm_so; @@ -903,6 +918,7 @@ void getmatch(int i) strpool[poolptr++] = '>'; } + /* function strips trailing zeros in string with numbers; */ /* leading zeros are not stripped (as in real life) */ char *stripzeros(char *a) -- cgit v1.2.3