r759 - in branches/stable: doc/manual source/src/texk/web2c/lib source/src/texk/web2c/pdftexdir tests tests/02-pdfmatch

karl at freefriends.org karl at freefriends.org
Sun Jun 12 20:11:29 CEST 2016


Author: karl
Date: 2016-06-12 18:11:28 +0000 (Sun, 12 Jun 2016)
New Revision: 759

Added:
   branches/stable/tests/02-pdfmatch/
   branches/stable/tests/02-pdfmatch/Makefile
   branches/stable/tests/02-pdfmatch/test-pdfmatch.tex
Modified:
   branches/stable/doc/manual/ChangeLog
   branches/stable/doc/manual/pdftex-t.tex
   branches/stable/source/src/texk/web2c/lib/ChangeLog
   branches/stable/source/src/texk/web2c/pdftexdir/ChangeLog
   branches/stable/source/src/texk/web2c/pdftexdir/NEWS
   branches/stable/source/src/texk/web2c/pdftexdir/utils.c
Log:
\pdflastmatch: more checks if no preceding match

Modified: branches/stable/doc/manual/ChangeLog
===================================================================
--- branches/stable/doc/manual/ChangeLog	2016-06-12 16:54:10 UTC (rev 758)
+++ branches/stable/doc/manual/ChangeLog	2016-06-12 18:11:28 UTC (rev 759)
@@ -1,3 +1,15 @@
+2016-06-12  Karl Berry  <karl at freefriends.org>
+
+	* pdftex-t.tex (\pdfmatch): mention default subcount 10; wording.
+	(\pdflastmatch): clarify match position, wording;
+	
+	* pdftex-t.tex (Invoking \PDFTEX): new name FORCE_SOURCE_DATE for
+	SOURCE_DATE_EPOCH_TEX_PRIMITIVES.
+
+2016-05-20  Karl Berry  <karl at tug.org>
+
+	* TeX Live 2016 release.
+
 2016-05-05  Karl Berry  <karl at tug.org>
 
 	* pdftex-t.tex: missed \

Modified: branches/stable/doc/manual/pdftex-t.tex
===================================================================
--- branches/stable/doc/manual/pdftex-t.tex	2016-06-12 16:54:10 UTC (rev 758)
+++ branches/stable/doc/manual/pdftex-t.tex	2016-06-12 18:11:28 UTC (rev 759)
@@ -4025,23 +4025,29 @@
 \bookmark{\tex{pdfmatch}}
 
 This command implements pattern matching (using the syntax of \POSIX\
-regular expressions). The first \Something{general text} is a pattern,
-the second is a string, and the command expands to \type{-1} if the
-pattern is invalid, to \type{0} if no match is found, and to \type{1} if
-a match is found. With the \type{icase} option, the matching is
-case-insensitive.  The \type{subcount} option sets the size of the table
-storing found (sub)patterns.  \introduced{1.30.0}
+extended regular expressions). The first \Something{general text} is a
+pattern and the second is a string.  The command expands to \type{-1} if
+the pattern is invalid, to \type{0} if no match is found, and to
+\type{1} if a match is found. With the \type{icase} option, the matching
+is case-insensitive.  The \type{subcount} option sets the size of the
+table storing the found (sub)patterns; its default is 10.
+\introduced{1.30.0}
 
 \pdftexprimitive{\Syntax{\Tex{\pdflastmatch} \Something{integer}
   \Whatever{expandable}}}
 \bookmark{\tex{pdflastmatch}}
 
-The matches found with \type{\pdfmatch} are stored in a table. This command
-returns the entry \Something{integer}. Entry~0 contains the match, and
-the following entries contain submatches corresponding to the subpatterns
-(up to \type{subcount-1}); all matches are preceded by their positions,
-separated by \type{->}. If the position is \type{-1} and the match is
-empty, it means that the subpattern corresponding to that entry wasn't found.
+The matches found with \type{\pdfmatch} are stored in a table. This
+command returns the entry for \Something{integer}, in the format
+\Something{position}\type{->}\Something{string}; \Something{position} is
+the position of the match (starting at zero) or \type{-1} if no match
+was found, and \Something{string} is the matched substring.
+
+Entry~0 contains the match as a whole; the subsequent entries contain
+submatches corresponding to the subpatterns, up to \type{subcount-1}.
+
+If \Something{integer} is less than zero, an error is given.
+
 For instance:
 
 \starttyping
@@ -4053,7 +4059,7 @@
 \stoptyping
 
 Entry~1 is empty because no match was found for \type{cd}, and entry~3
-is empty because it exceeds the table's size, as set by \type{subcount}.
+is empty because it exceeds the table's size as set by \type{subcount}.
 \introduced{1.30.0}
 
 %***********************************************************************

Modified: branches/stable/source/src/texk/web2c/lib/ChangeLog
===================================================================
--- branches/stable/source/src/texk/web2c/lib/ChangeLog	2016-06-12 16:54:10 UTC (rev 758)
+++ branches/stable/source/src/texk/web2c/lib/ChangeLog	2016-06-12 18:11:28 UTC (rev 759)
@@ -5,6 +5,10 @@
 	http://tug.org/pipermail/tex-k/2016-June/002722.html
 	(and surrounding thread, starting in May)
 
+2016-05-20  Karl Berry  <karl at tug.org>
+
+	* TeX Live 2016 release.
+
 2016-05-06  Akira Kakuto  <kakuto at fuk.kinidai.ac.jp>
 
 	* texmfmp.c: Avoid crash for too large a value of SOURCE_DATE_EPOCH.

Modified: branches/stable/source/src/texk/web2c/pdftexdir/ChangeLog
===================================================================
--- branches/stable/source/src/texk/web2c/pdftexdir/ChangeLog	2016-06-12 16:54:10 UTC (rev 758)
+++ branches/stable/source/src/texk/web2c/pdftexdir/ChangeLog	2016-06-12 18:11:28 UTC (rev 759)
@@ -1,3 +1,17 @@
+2016-06-12  Karl Berry  <karl at freefriends.org>
+        and Akira Kakuto  <kakuto at fuk.kindai.ac.jp>
+
+	* utils.c (last_match_succeeded): new static boolean.
+	(matchstrings): set it.
+	(getmatch): use it, plus check for non-NULL match_string sooner,
+	plus check that rm_eo >= rm_so.
+	Original bug report from David Carlisle,
+        http://tug.org/pipermail/tex-live/2016-June/038664.html
+
+2016-05-20  Karl Berry  <karl at tug.org>
+
+	* TeX Live 2016 release.
+
 2016-04-06  Karl Berry  <karl at tug.org>
 
 	* pdftexextra.h (COPYRIGHT_HOLDER): don't specifically mention peb

Modified: branches/stable/source/src/texk/web2c/pdftexdir/NEWS
===================================================================
--- branches/stable/source/src/texk/web2c/pdftexdir/NEWS	2016-06-12 16:54:10 UTC (rev 758)
+++ branches/stable/source/src/texk/web2c/pdftexdir/NEWS	2016-06-12 18:11:28 UTC (rev 759)
@@ -1,8 +1,11 @@
 - changes:
   - rename envvar SOURCE_DATE_EPOCH_TEX_PRIMITIVES to FORCE_SOURCE_DATE;
     no changes in functionality.
+
+- bugfixes:
+  - \pdflastmatch more reliable when there was no preceding match.
 ---------------------------------------------------
-pdfTeX 3.14159265-2.6-1.40.17 (TeX Live 2016)
+pdfTeX 3.14159265-2.6-1.40.17 (TeX Live 2016)  (May 20, 2016)
 - changes:
   - if the environment variable SOURCE_DATE_EPOCH is set, use its value for
     the PDF CreationDate and ModDate values, and to seed the trailer /ID.

Modified: branches/stable/source/src/texk/web2c/pdftexdir/utils.c
===================================================================
--- branches/stable/source/src/texk/web2c/pdftexdir/utils.c	2016-06-12 16:54:10 UTC (rev 758)
+++ branches/stable/source/src/texk/web2c/pdftexdir/utils.c	2016-06-12 18:11:28 UTC (rev 759)
@@ -817,12 +817,16 @@
     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 @@
             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 @@
     strpool[poolptr++] = '>';
 }
 
+

 /* function strips trailing zeros in string with numbers; */
 /* leading zeros are not stripped (as in real life) */
 char *stripzeros(char *a)

Added: branches/stable/tests/02-pdfmatch/Makefile
===================================================================
--- branches/stable/tests/02-pdfmatch/Makefile	                        (rev 0)
+++ branches/stable/tests/02-pdfmatch/Makefile	2016-06-12 18:11:28 UTC (rev 759)
@@ -0,0 +1,8 @@
+# $Id: Makefile 758 2016-06-12 16:54:10Z karl $
+# Public domain.
+
+include ../Common.mak
+
+testpdfmatch:
+	$(prog) test-pdfmatch.tex
+


Property changes on: branches/stable/tests/02-pdfmatch/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: branches/stable/tests/02-pdfmatch/test-pdfmatch.tex
===================================================================
--- branches/stable/tests/02-pdfmatch/test-pdfmatch.tex	                        (rev 0)
+++ branches/stable/tests/02-pdfmatch/test-pdfmatch.tex	2016-06-12 18:11:28 UTC (rev 759)
@@ -0,0 +1,22 @@
+% $Id$
+% This file public domain.  Bug report of \pdflastmatch crash:
+% http://tug.org/pipermail/tex-live/2016-June/038664.html
+%
+\catcode`\{=1 \catcode`\}=2 \catcode`^=7 \newlinechar=`^^J
+%
+\message{^^Jpdflastmatch0 before any match: \pdflastmatch0}
+\message{^^J}%
+%
+\message{^^Jmatch a to b: \pdfmatch{a}{b}}
+\message{^^J}%
+\message{pdflastmatch0: \pdflastmatch0}
+\message{^^J}%
+%
+\message{^^Jmatch example: \pdfmatch subcount 3 {ab(cd)*ef(gh)(ij)}{abefghij}}
+\message{^^J}%
+\message{pdflastmatch0 (0->abefghij): \pdflastmatch0 ^^J}
+\message{pdflastmatch1 (-1->): \pdflastmatch1 ^^J}
+\message{pdflastmatch2 (4->gh): \pdflastmatch2 ^^J}
+\message{pdflastmatch3 (-1->): \pdflastmatch3}
+\message{^^J}%
+\end


Property changes on: branches/stable/tests/02-pdfmatch/test-pdfmatch.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Date Author Id
\ No newline at end of property


More information about the pdftex-commits mailing list