[tex-k] header special extension proposal
Akira Kakuto
kakuto at fsci.fuk.kindai.ac.jp
Wed Aug 17 05:54:18 CEST 2005
Hi Karl, Hendri
> Many thanks for the simplification.
> In the previous example, Hendri cannot use braces
> in pre code and post code. In the next example, he can use "balanced"
> braces:
The patch I have sent just before (as well as my original ones)
has some security problems when the special does not satisfy
Hendri's rule. Please replace with the following:
--- dospecial.c.orig Wed Aug 17 07:45:56 2005
+++ dospecial.c Wed Aug 17 12:38:12 2005
@@ -393,7 +393,7 @@
while ((*p <= ' ' || *p == '=' || *p == '(') && *p != 0)
p++;
q = p ;
- while (*p != '}')
+ while (*p != '}' && *p != 0)
p++;
r = p-1 ;
while ((*r <= ' ' || *r == ')') && r >= q)
@@ -403,15 +403,19 @@
while ((*p <= ' ' || *p == '=' || *p == '(') && *p != 0)
p++ ;
if(strncmp(p, "pre", 3) == 0) {
- while(*p != '{')
+ int bracecount = 1, numbytes = 0, j ;
+ while(*p != '{' && *p != 0)
p++ ;
p++;
- r = p;
- while(*r != '}')
- r++ ;
- pre = (char *)malloc(r-p+1);
+ for(r = p; *r != 0; r++) {
+ if (*r == '{') bracecount++ ;
+ else if (*r == '}') bracecount-- ;
+ if (bracecount == 0) break ;
+ numbytes++ ;
+ }
+ pre = (char *)malloc(numbytes+1);
r = pre ;
- while(*p != '}')
+ for (j=0; j < numbytes; j++)
*r++ = *p++;
*r = 0;
p++;
@@ -419,15 +423,19 @@
while ((*p <= ' ' || *p == '=' || *p == '(') && *p != 0)
p++ ;
if(strncmp(p, "post", 4) == 0) {
- while(*p != '{')
+ int bracecount = 1, numbytes = 0, j ;
+ while(*p != '{' && *p != 0)
p++ ;
p++;
- r = p;
- while(*r != '}')
- r++ ;
- post = (char *)malloc(r-p+1);
+ for(r = p; *r != 0; r++) {
+ if (*r == '{') bracecount++ ;
+ else if (*r == '}') bracecount-- ;
+ if (bracecount == 0) break ;
+ numbytes++ ;
+ }
+ post = (char *)malloc(numbytes+1);
r = post ;
- while(*p != '}')
+ for (j=0; j < numbytes; j++)
*r++ = *p++;
*r = 0;
}
More information about the tex-k
mailing list