[tex-live] Patches for dvidvi

Norbert Preining preining at logic.at
Mon Jul 2 13:42:06 CEST 2007


Hi Lionel,

On Mon, 02 Jul 2007, Lionel Elie Mamane wrote:
> I am the maintainer of the Debian package of dvidvi. As you probably
> know, Debian recently switched to TeXLive from teTeX, and TeXLive

Thanks for contacting us. To be honest I had it on my TODO list since a
long time to get into contact with you because of this duplication. I
wanted to leave out dvidvi from the DEBIAN TeX Live packages and instead
depend on your packages, but then I saw what you mentioned, that TL has
version 1.1, accepts other command line switches etc.

(putting TeX Live Developer hat on)
I don't know about the maintainer status of dvidvi, is it actively
maintained, and if yes, where? If yes best would be to merge the patches
from Debian to upstream dvidvi from where they will come back to TeX
Live and Debian (and as DD I could leave this part out of Debian TL).

All the patches you mentioned:
>  * Integrate patch by Benjamin Bayart to take into account PostScript
>    inclusion \special's in the first page even if the first page is
>    not kept in the final result. Fixes handling of dvi files making
>    use of PStricks or colour or other advanced PostScript features.
> 
>  * dvidvi.c (stringdvibuf): Fix "unexpected eof" error on some big
>    files; thanks to Benjamin BAYART for the patch.  Closes: #231275.
> 
>  * Make the C code warning-free.
> 
> The Debian package also contains a Unix version of a5booklet, which
> TeXLive seems to be missing. The code changes in Debian are naturally
> untested on non-Unix (or non-modern Unix) platforms.

sound like reasonable and good extensions/inclusions. So it should be
not too difficult to make this work.

> and my try at merging the changes in TeXLive (wrt 1.0) and in Debian at
> http://people.debian.org/~lmamane/dvidvi/dvidvi.merged.c .

I attach here for review a diff between the current version of dvidvi.c
in the TL depot and your file.

Best wishes, and thanks a lot for contacting us

Norbert

-------------------------------------------------------------------------------
Dr. Norbert Preining <preining at logic.at>        Vienna University of Technology
Debian Developer <preining at debian.org>                         Debian TeX Group
gpg DSA: 0x09C5B094      fp: 14DF 2E6C 0307 BE6D AD76  A9C0 D2BF 4AA3 09C5 B094
-------------------------------------------------------------------------------
SEATTLE (vb.)
To make a noise like a train going along.
			--- Douglas Adams, The Meaning of Liff
-------------- next part --------------
--- /src/TeX/texlive-svn/Build/source/texk/dvidvi/dvidvi.c	2006-01-17 22:41:51.000000000 +0100
+++ dvidvi.merged.c	2007-07-02 12:45:22.000000000 +0200
@@ -44,9 +44,12 @@
 #endif
 void error(char *);
 
+#include "dvidvi.h"
 #ifndef VMS
+#include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 #else /* VMS */
 #include "sys$library:stdio.h"       /* AKT: added sys$library: */
 #include <alloc.h>
@@ -84,12 +87,13 @@
 #define READBIN         "rb"    /* VMS must use binary mode */
 #define WRITEBIN        "wb"
 #define PATHSEP         ','
-#define IS_DIR_SEP      ((c) == ':')
+#define IS_DIR_SEP(c)   ((c) == ':')
 #else
 #define READBIN         "r"     /* UNIX doesn't care */
 #define WRITEBIN        "w"
 #define PATHSEP         ':'
-#define IS_DIR_SEP      ((c) == '/')
+#define IS_DIR_SEP(c)   ((c) == '/')
+#define SET_BINARY(f)
 #endif
 #endif /* not KPATHSEA */
 
@@ -175,6 +179,12 @@
 integer *pagenumbers ;
 int prettycolumn ;       /* the column we are at when running pretty */
 
+// To handle xxx1 for headers
+// Lets suppose there will be less than 256 of those.
+char *headers[256];
+integer ln_headers[256];
+integer nb_headers = 0L;
+
 /*
  *   This array holds values that indicate the length of a command, if
  *   we aren't concerned with that command (which is most of them) or
@@ -328,14 +338,18 @@
 void stringdvibuf(p,n)
 integer p,n;
 {
+  char *s = temp;
   fseek(infile,p,SEEK_SET);
   while ( n-- > 0 )
-    *temp++ = dvibyte();
+    *s++ = dvibyte();
 }
 
 /*
  *   Print a usage error messsage, and quit.
  */
+#ifdef __GNUC__
+__attribute__((noreturn))
+#endif
 void usage() {
    (void)fprintf(stderr,banner);
    (void)fprintf(stderr,"Usage:  dvidvi [options] input[.dvi] [output]\n");
@@ -357,8 +371,7 @@
 /*
  *   Print an error message, and exit if it is fatal.
  */
-void error(s)
-char *s ;
+void error(char *s)
 {
    (void)fprintf(stderr, "%s\n", s) ;    /* AKT: was dvidvi: %s */
    if (*s == '!')
@@ -579,11 +592,12 @@
  *   Parse the arguments to the routine, and stuff everything away
  *   into those globals above.
  */
-void processargs(argc, argv)
+void
+processargs(argc, argv)
 int argc ;
 char *argv[] ;
 {
-   char *p, *q ;
+   char *q ;
    int i, pageno, lastext = -1 ;
    long hoffset, voffset ;
    int reversed ;
@@ -613,9 +627,9 @@
 	       p++; firsttransf = 1 ;
 	       }
 #ifdef SHORTINT
-            if(sscanf(p, "%ld", &firstpage)==0)
-#else   /* ~SHORTINT */
             if(sscanf(p, "%d", &firstpage)==0)
+#else   /* ~SHORTINT */
+            if(sscanf(p, "%ld", &firstpage)==0)
 #endif  /* ~SHORTINT */
 	       error("! Bad first page option (-f).") ;
             break ;
@@ -661,9 +675,9 @@
 	       p++; lasttransf = 1 ;
 	       }
 #ifdef SHORTINT
-            if(sscanf(p, "%ld", &lastpage)==0)
-#else   /* ~SHORTINT */
             if(sscanf(p, "%d", &lastpage)==0)
+#else   /* ~SHORTINT */
+            if(sscanf(p, "%ld", &lastpage)==0)
 #endif  /* ~SHORTINT */
                error("! Bad last page option (-l).") ;
             break ;
@@ -671,9 +685,9 @@
             if (*p == 0 && argv[i+1])
                p = argv[++i] ;
 #ifdef SHORTINT
-            if (sscanf(p, "%ld", &pagemodulo)==0)
-#else   /* ~SHORTINT */
             if (sscanf(p, "%d", &pagemodulo)==0)
+#else   /* ~SHORTINT */
+            if (sscanf(p, "%ld", &pagemodulo)==0)
 #endif  /* ~SHORTINT */
                error("! Bad pagemodulo option (-p).") ;
             break ;
@@ -735,9 +749,9 @@
             if (*p == 0 && argv[i+1])
                p = argv[++i] ;
 #ifdef SHORTINT
-            if (sscanf(p, "%ld", &maxpages)==0)
-#else   /* ~SHORTINT */
             if (sscanf(p, "%d", &maxpages)==0)
+#else   /* ~SHORTINT */
+            if (sscanf(p, "%ld", &maxpages)==0)
 #endif  /* ~SHORTINT */
                error("! Bad number of pages option (-n).") ;
             break ;
@@ -892,6 +906,7 @@
    (void)dvibuf(p);
    pagenumbers[num]=signedquad();
 }
+
 /*
  *   This routine simply reads the entire dvi file, and then initializes
  *   some values about it.
@@ -966,6 +981,7 @@
  */
 
    p = pageloc[0L] + 45 ;
+nextcmd:
    c=dvibuf(p);
    while (comlen[c]) {
       p += comlen[c] ;
@@ -977,12 +993,36 @@
         landscape = p ;
         rem0special = 1 ;
       }
+      stringdvibuf(p+2L,6L);
+      if (strncmp(temp, "header", 6)==0) {
+	char l1;
+	l1 = dvibuf(p+1);
+	stringdvibuf(p+2,l1);
+	if ( nb_headers == 256 ) {
+	   fprintf(stderr,"\n"
+			  "There are more than 256 PS headers in your DVI file.\n"
+			  "Please ask a wizzard to enlarge me :-)\n");
+	}
+	ln_headers[nb_headers] = l1;
+	headers[nb_headers++] = strdup(temp);
+	/*
+	 * Seek at the end of the xxx1, then goto reading next commands.
+	 * In a normal DVI file, as produced by LaTeX, all of those special
+	 * commands (xxx1 with PS headers) are outputed on the very first
+	 * page, all together. So a simple loop might be enough. Just in
+	 * case we have a strange file we accept that there might be some
+	 * typesetting commandes between those xxx1.
+	 */
+	p = p + l1 + 2;
+	goto nextcmd;
+      }
    }
 }
 /*
  *   Output a single byte, keeping track of where we are.
  */
-void outdvibyte(c)
+void
+outdvibyte(c)
 unsigned char c ;
 {
    fputc(c, stdout) ;
@@ -991,7 +1031,8 @@
 /*
  *   Send out two bytes.
  */
-void outdvi2(v)
+void
+outdvi2(v)
 integer v ;
 {
    outdvibyte((unsigned char)(v >> 8)) ;
@@ -1000,7 +1041,8 @@
 /*
  *   Send out a longword.
  */
-void outdviquad(v)
+void
+outdviquad(v)
 integer v ;
 {
    outdvi2(v >> 16) ;
@@ -1010,7 +1052,8 @@
  *   This routine just copies some stuff from the buffer on out.
  *   Suppose the file is positioned correctly before
  */
-void putbuf(length)
+void
+putbuf(length)
 integer length ;
 {
    while ( length-- > 0 )
@@ -1019,7 +1062,8 @@
 /*
  *   This routine outputs a string, terminated by null.
  */
-void putstr(s)
+void
+putstr(s)
 register unsigned char *s ;
 {
    while (*s)
@@ -1028,7 +1072,8 @@
 /*
  *   Here we write the preamble to the dvi file.
  */
-void writepreamble() {
+void
+writepreamble() {
 /*   just copy the first 14 bytes of the file */
    fseek(infile,0L,SEEK_SET);
    putbuf(14L) ;
@@ -1038,7 +1083,8 @@
 /*
  *   This routine writes out a font definition.
  */
-void putfontdef(f)
+void
+putfontdef(f)
 int f ;
 {
    integer p,q ;
@@ -1051,7 +1097,8 @@
 /*
  *   The postamble is next.
  */
-void writepostamble() {
+void
+writepostamble() {
    int i ;
    integer p ;
 
@@ -1076,7 +1123,8 @@
 /*
  *   This routine starts a page, by writing out a bop command.
  */
-void beginpage() {
+void
+beginpage() {
    int i ;
    integer p ;
 
@@ -1092,10 +1140,11 @@
  *   This routine sends out a page.  We need to handle the
  *   landscape special, though.
  */
-void dopage(num)
+void
+dopage(num)
 integer num ;
 {
-   register integer p,q ;
+   register integer p ;
    register int len ;
    integer v, oldp ;
    unsigned char c;
@@ -1120,15 +1169,40 @@
       }
       prettycolumn += i + 1 ;
 #ifdef SHORTINT
-      (void)fprintf(stderr, "[%ld", num+1) ;
-#else  /* ~SHORTINT */
       (void)fprintf(stderr, "[%d", num+1) ;
+#else  /* ~SHORTINT */
+      (void)fprintf(stderr, "[%ld", num+1) ;
 #endif /* ~SHORTINT */
       (void)fflush(stderr) ;
    }
    p = pageloc[num] + 45 ;
    c=dvibuf(p);
    while (c != 140) {
+      if ( nb_headers ) {
+	 integer i;
+	 /*
+	  * Need to output the 'nb_headers' headers that we collected.
+	  * If we are outputing the real first page of the previous
+	  * DVI file, then the headers will be doubled, which is not
+	  * troublesome: dvips will keep only one of those.
+	  */
+	 for ( i=0; i<nb_headers; i++ ) {
+	    outdvibyte(239);
+	    outdvibyte(ln_headers[i]);
+	    putstr(headers[i]);
+	    if ( !quiet ) {
+	       fprintf(stderr,"<%s>",headers[i]+7);
+	       prettycolumn += ln_headers[i]+2-7;
+	    }
+	 }
+	 /*
+	  * We will output the headers only one time. That is possible that
+	  * those headers are not usefull (the pages where they are used might
+	  * not be kept in the out file, but there is no simple way to avoid
+	  * it.
+	  */
+         nb_headers = 0;
+      }
       if ((len=comlen[c]) > 0) {    /* most commands are simple */
          outdvibyte(c);
          putbuf((long)len-1) ;
@@ -1193,7 +1267,8 @@
 /*
  *   Here we end a page.  Simple enough.
  */
-void endpage() {
+void
+endpage() {
    outputpages++ ;
    outdvibyte(140) ;
 }
@@ -1201,12 +1276,12 @@
  *   This is our main routine for output, which runs through all the
  *   pages we need to output.
  */
-void writedvifile() {
+void
+writedvifile() {
    integer pagenum ;
    int ppp ;
    integer actualpageno, lastpageno ;
    struct pagespec *ps ;
-   integer p ;
    Boolean beginp ;
 
    writepreamble() ;
@@ -1259,13 +1334,17 @@
    }
    writepostamble() ;
 }
-int main(argc, argv)
+int
+main(argc, argv)
 int argc ;
 char *argv[] ;
 {
    processargs(argc, argv) ;
    readdvifile() ;
    writedvifile() ;
-   return 0 ;
+   if (!quiet) {
+      fprintf(stderr,"\n");
+   }
+   return 0;
 }
 


More information about the tex-live mailing list