[tex-k] header special extension proposal

Akira Kakuto kakuto at fsci.fuk.kindai.ac.jp
Tue Aug 16 09:31:01 CEST 2005


> A simple extension of the header special could bring the solution here.

I don't understand the problem, but the header sepcial extension
may be realized by the following quick and dirty ones:

diff -u oldorigdvips/dospecial.c neworigdvips/dospecial.c
--- oldorigdvips/dospecial.c	Fri Mar 12 00:29:34 2004
+++ neworigdvips/dospecial.c	Tue Aug 16 01:10:16 2005
@@ -384,17 +384,64 @@
 
 case 'h':
    if (strncmp(p, "header", 6)==0) {
-      char *q ;
+      char *q, *r, *pre = NULL, *post = NULL ;
       p += 6 ;
       while ((*p <= ' ' || *p == '=' || *p == '(') && *p != 0)
          p++ ;
-      q = p ;  /* we will remove enclosing parentheses */
-      p = p + strlen(p) - 1 ;
-      while ((*p <= ' ' || *p == ')') && p >= q)
-         p-- ;
-      p[1] = 0 ;
-      if (p >= q)
-         (void)add_header(q) ;
+      if(*p == '{') {
+	 p++;
+	 while ((*p <= ' ' || *p == '=' || *p == '(') && *p != 0)
+	    p++;
+	 q = p ;
+	 while (*p != '}')
+	    p++;
+	 r = p-1 ;
+	 while ((*r <= ' ' || *r == ')') && r >= q)
+	    r-- ;
+	 r[1] = 0 ; /* q is the file name */
+	 p++;
+	 while ((*p <= ' ' || *p == '=' || *p == '(') && *p != 0)
+	    p++ ;
+	 if(strncmp(p, "pre", 3) == 0) {
+	    while(*p != '{')
+	       p++ ;
+	    p++;
+	    r = p;
+	    while(*r != '}')
+	       r++ ;
+	    pre = (char *)malloc(r-p+1);
+	    r = pre ;
+	    while(*p != '}')
+	       *r++ = *p++;
+	    *r = 0;
+	    p++;
+	 }
+	 while ((*p <= ' ' || *p == '=' || *p == '(') && *p != 0)
+	    p++ ;
+	 if(strncmp(p, "post", 4) == 0) {
+	    while(*p != '{')
+	       p++ ;
+	    p++;
+	    r = p;
+	    while(*r != '}')
+	       r++ ;
+	    post = (char *)malloc(r-p+1);
+	    r = post ;
+	    while(*p != '}')
+	       *r++ = *p++;
+	    *r = 0;
+	 }
+	 if (strlen(q) > 0)
+	    (void)add_header(q, pre, post) ;
+      } else {
+	 q = p ;  /* we will remove enclosing parentheses */
+	 p = p + strlen(p) - 1 ;
+	 while ((*p <= ' ' || *p == ')') && p >= q)
+	    p-- ;
+	 p[1] = 0 ;
+	 if (p >= q)
+	    (void)add_header(q, NULL, NULL) ;
+      }
    }
    break ;
 /* IBM: color - added section here for color header and color history */
diff -u oldorigdvips/dvips.c neworigdvips/dvips.c
--- oldorigdvips/dvips.c	Mon Jul 25 22:14:56 2005
+++ neworigdvips/dvips.c	Tue Aug 16 01:13:26 2005
@@ -730,7 +730,7 @@
                if (strcmp(p, "-") == 0)
                   headers_off = 1 ;
                else
-                  (void)add_header(p) ;
+                  (void)add_header(p, NULL, NULL) ;
                break ;
 case 'i':
                sepfiles = (*p != '0') ;
@@ -1207,7 +1207,7 @@
       error(warningmsg) ;
    headersready = 1 ;
    headerfile = (char *) (compressed? CHEADERFILE : HEADERFILE) ;
-   (void)add_header(headerfile) ;
+   (void)add_header(headerfile, NULL, NULL) ;
    if (*iname != 0) {
       fulliname = nextstring ;
 #ifndef IGNORE_CWD
@@ -1282,16 +1282,16 @@
    }
 #endif
    if (includesfonts)
-      (void)add_header(IFONTHEADER) ;
+      (void)add_header(IFONTHEADER, NULL, NULL) ;
    if (usesPSfonts)
-      (void)add_header(PSFONTHEADER) ;
+      (void)add_header(PSFONTHEADER, NULL, NULL) ;
    if (usesspecial)
-      (void)add_header(SPECIALHEADER) ;
+      (void)add_header(SPECIALHEADER, NULL, NULL) ;
    if (usescolor)  /* IBM: color */
-      (void)add_header(COLORHEADER) ;
+      (void)add_header(COLORHEADER, NULL, NULL) ;
 #ifdef HPS
    if (HPS_FLAG)
-      (void)add_header(HPSHEADER) ;
+      (void)add_header(HPSHEADER, NULL, NULL) ;
 #endif
    sects = sections ;
    totalpages *= collatedcopies ;
diff -u oldorigdvips/dvips.h neworigdvips/dvips.h
--- oldorigdvips/dvips.h	Mon Jan 31 06:57:32 2005
+++ neworigdvips/dvips.h	Tue Aug 16 01:14:13 2005
@@ -242,6 +242,8 @@
 struct header_list {
    struct header_list *next ;
    char *Hname ;
+   char *precode ;
+   char *postcode ;
    char name[1] ;
 } ;
 /*
diff -u oldorigdvips/finclude.c neworigdvips/finclude.c
--- oldorigdvips/finclude.c	Sun Jan 16 14:54:10 2005
+++ neworigdvips/finclude.c	Tue Aug 16 01:15:47 2005
@@ -273,7 +273,7 @@
      pe = strchr(p,' ');
      if(pe != NULL) *pe = '\0';
 
-     i = add_name(p,&ps_fonts_used);
+     i = add_name(p,&ps_fonts_used,NULL,NULL);
 
      if (1) {
 #ifdef DEBUG
@@ -287,7 +287,7 @@
        if(re != NULL) {
          if (re->sent != 2) {
             if (re->Fontfile) {
-               add_header(re->Fontfile) ;
+               add_header(re->Fontfile, NULL, NULL) ;
             } else if (re->downloadheader) {
 	/* this code borrowed from residentfont() in resident.c */
 	      char *cp = re->downloadheader ;
@@ -300,10 +300,10 @@
                   cp++ ;
   	        if (*cp) {
                   *cp = 0 ;
-                  add_header(q) ;
+                  add_header(q, NULL, NULL) ;
                   *cp++ = ' ' ;
 	        } else {
-                  add_header(q) ;
+                  add_header(q, NULL, NULL) ;
                   break ;
 	        }
 	        infont = 0 ;
diff -u oldorigdvips/header.c neworigdvips/header.c
--- oldorigdvips/header.c	Fri Mar 12 00:29:38 2004
+++ neworigdvips/header.c	Tue Aug 16 01:20:45 2005
@@ -22,6 +22,7 @@
 #ifndef KPATHSEA
 extern char *headerpath ;
 #endif
+extern FILE *bitfile ;
 extern char *infont ;
 extern int headersready ;
 #ifdef DEBUG
@@ -36,7 +37,7 @@
  *   names.
  */
 int
-add_name P2C(char *, s, struct header_list **, what)
+add_name P4C(char *, s, struct header_list **, what, char *, pre, char *, post)
 {
    struct header_list *p, *q ;
 
@@ -47,6 +48,8 @@
                                           + strlen(s))) ;
    q->Hname = infont ;
    q->next = NULL ;
+   q->precode = pre ;
+   q->postcode = post ;
    strcpy(q->name, s) ;
    if (*what == NULL)
       *what = q ;
@@ -106,11 +109,11 @@
  *   use that; otherwise, we use the length of the file.
  */
 int
-add_header P1C(char *, s)
+add_header P3C(char *, s, char *, pre, char *, post)
 {
    int r ;
 
-   r = add_name(s, &header_head) ;
+   r = add_name(s, &header_head, pre, post) ;
    if (r) {
       if (headersready == 1) {
          struct header_list *p = header_head ;
@@ -129,12 +132,14 @@
 /*
  *   This routine runs down a list, returning each in order.
  */
+static struct header_list *CUR_head = NULL ;
 char *
 get_name P1C(struct header_list **, what)
 {
    if (what && *what) {
       char *p = (*what)->name ;
       infont = (*what)->Hname ;
+      CUR_head = *what ;
       *what =  (*what)->next ;
       return p ;
    } else
@@ -146,7 +151,7 @@
 void
 send_headers P1H(void) {
    struct header_list *p = header_head ;
-   char *q ;
+   char *q, *r ;
 
    while (0 != (q=get_name(&p))) {
 #ifdef DEBUG
@@ -158,7 +163,27 @@
  	     if (strcmp(q,"target.dct")==0) noprocset = 1 ;
        }
 #endif
+      if(CUR_head && CUR_head->precode) {
+	 r = CUR_head->precode ;
+	 while(*r) {
+	    putc(*r, bitfile) ;
+	    r++ ;
+	 }
+	 putc('\n', bitfile) ;
+	 free(CUR_head->precode) ;
+	 CUR_head->precode = NULL ;
+      }
       copyfile(q) ;
+      if(CUR_head && CUR_head->postcode) {
+	 r = CUR_head->postcode ;
+	 while(*r) {
+	    putc(*r, bitfile) ;
+	    r++ ;
+	 }
+	 putc('\n', bitfile) ;
+	 free(CUR_head->postcode) ;
+	 CUR_head->postcode = NULL ;
+      }
    }
    infont = 0 ;
 }
diff -u oldorigdvips/protos.h neworigdvips/protos.h
--- oldorigdvips/protos.h	Sun Jan 23 15:56:48 2005
+++ neworigdvips/protos.h	Tue Aug 16 01:21:45 2005
@@ -145,9 +145,9 @@
 extern int skipnop P1H(void);
 
 /* prototypes for functions from header.c */
-extern int add_name P2H(char *s, struct header_list **what );
+extern int add_name P4H(char *s, struct header_list **what, char *pre, char *post);
 extern void checkhmem P1H(char *s);
-extern int add_header P1H(char *s);
+extern int add_header P3H(char *s, char *pre, char *post);
 extern char *get_name P1H(struct header_list **what );
 extern void send_headers P1H(void);
 
diff -u oldorigdvips/resident.c neworigdvips/resident.c
--- oldorigdvips/resident.c	Mon Jul 25 22:15:12 2005
+++ neworigdvips/resident.c	Tue Aug 16 01:23:59 2005
@@ -240,7 +240,7 @@
       curfnt->chardesc[i].flags = 0 ;
       curfnt->chardesc[i].flags2 = 0 ;
    }
-   add_name(p->PSname, &ps_fonts_used) ;
+   add_name(p->PSname, &ps_fonts_used, NULL, NULL) ;
 /*
  *   We include the font here.  But we only should need to include the
  *   font if we have a stupid spooler; smart spoolers should be able
@@ -257,14 +257,14 @@
             cp++ ;
          if (*cp) {
             *cp = 0 ;
-            add_header(q) ;
+            add_header(q, NULL, NULL) ;
             *cp++ = ' ' ;
          } else {
 /*          if (strstr(q,".pfa")||strstr(q,".pfb")||
                 strstr(q,".PFA")||strstr(q,".PFB"))
                break ;
             else */ {
-              add_header(q) ;
+            add_header(q, NULL, NULL) ;
               break;
             }
          }
@@ -782,7 +782,7 @@
 case 'h' : 
          if (sscanf(was_inline+1, "%s", PSname) != 1)
            bad_config("missing arg to h") ;
-         else (void)add_header(PSname) ;
+         else (void)add_header(PSname, NULL, NULL) ;
          break ;
 case 'i' :
          if (sscanf(was_inline+1, "%d", &maxsecsize) != 1)



More information about the tex-k mailing list