Back to index

tetex-bin  3.0
misc.c
Go to the documentation of this file.
00001 /* misc.c */
00002 
00003 /************************************************************************
00004 
00005   Part of the dvipng distribution
00006 
00007   This program is free software; you can redistribute it and/or modify
00008   it under the terms of the GNU General Public License as published by
00009   the Free Software Foundation; either version 2 of the License, or
00010   (at your option) any later version.
00011 
00012   This program is distributed in the hope that it will be useful, but
00013   WITHOUT ANY WARRANTY; without even the implied warranty of
00014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015   General Public License for more details.
00016 
00017   You should have received a copy of the GNU General Public License
00018   along with this program; if not, write to the Free Software
00019   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00020   02111-1307, USA.
00021 
00022   Copyright (C) 2002-2005 Jan-Åke Larsson
00023 
00024 ************************************************************************/
00025 
00026 #include "dvipng.h"
00027 #ifdef HAVE_LIBGEN_H
00028 # include <libgen.h>
00029 #else
00030 #define basename xbasename
00031 #endif
00032 #include <fcntl.h> /* open/close */
00033 #include <sys/mman.h>
00034 #include <sys/stat.h>
00035 
00036 static char *programname;
00037 
00038 /*-->DecodeArgs*/
00039 /*********************************************************************/
00040 /***************************** DecodeArgs ****************************/
00041 /*********************************************************************/
00042 bool DecodeArgs(int argc, char ** argv)
00043 {
00044   int     i;                 /* argument index for options     */
00045   bool ppused=false;        /* Flag when -pp is used          */
00046   char *dviname=NULL;        /* Name of dvi file               */
00047   char *outname=NULL;        /* Name of output file            */
00048 
00049   if (argv[0]) {
00050 #ifdef HAVE_GDIMAGEGIF
00051     programname=strrchr(argv[0],'/');
00052     if (programname!=NULL)
00053       programname++;
00054     else
00055       programname=argv[0];
00056     if (strncmp(programname,"dvigif",6)==0)
00057       flags |= GIF_OUTPUT;
00058 #endif
00059     programname=argv[0];
00060     Message(BE_NONQUIET,"This is %s",programname);
00061     if (strcmp(basename(programname),PACKAGE_NAME)!=0)
00062       Message(BE_NONQUIET," (%s)", PACKAGE_NAME);
00063     Message(BE_NONQUIET," %s Copyright 2002-2005 Jan-Åke Larsson\n",
00064            PACKAGE_VERSION);
00065   }
00066 
00067   for (i=1; i<argc; i++) {
00068     if (*argv[i]=='-') {
00069       char *p=argv[i]+2 ;
00070       char c=argv[i][1] ;
00071       if (c=='-') {
00072        p++;
00073        c=argv[i][2];
00074       }
00075       switch (c) {
00076       case 'd':       /* selects Debug output */
00077        if (*p>'9' && *p!='-') {
00078          if (strncmp(p,"vinum",5)==0) { 
00079            if (p[5] != '0') {
00080              flags |= DVI_PAGENUM;
00081              Message(PARSE_STDIN,"DVI page number output on\n",p);
00082            } else {
00083              flags &= ~DVI_PAGENUM;
00084              Message(PARSE_STDIN,"DVI page number output off\n");
00085            }
00086            break;
00087          } else if (strncmp(p,"epth",4)==0) { /* Depth reporting */ 
00088            if (p[4] != '0') {
00089              flags |= REPORT_DEPTH;
00090              Message(PARSE_STDIN,"Depth reporting on\n",p);
00091            } else {
00092              flags &= ~REPORT_DEPTH;
00093              Message(PARSE_STDIN,"Depth reporting off\n");
00094            }
00095            break;
00096          }
00097          goto DEFAULT;
00098        } else { 
00099 #ifdef DEBUG
00100          if (*p == 0 && argv[i+1])
00101            p = argv[i+1];
00102          debug = atoi(p);
00103          if (debug > 0) {
00104            if (p == argv[i+1]) i++;
00105          } else 
00106            debug = DEBUG_DEFAULT;
00107          Message(PARSE_STDIN,"Debug output enabled\n");
00108 #ifdef HAVE_LIBKPATHSEA
00109          kpathsea_debug = debug / LASTDEBUG / 2 ;
00110 #endif
00111 #else
00112          Warning("This instance of %s was compiled without the debug (-d) option",
00113                 programname);
00114 #endif
00115          break;
00116        }
00117       case 'o':       /* Output file is specified */
00118        if (*p == 0 && argv[i+1])
00119          p = argv[++i] ;
00120         outname=p;
00121         /* remove .png extension */
00122        Message(PARSE_STDIN,"Output file: %s\n",
00123               outname);
00124         break;
00125 #ifdef MAKETEXPK
00126       case 'M':
00127         /* -M, -M1 => don't make font; -M0 => do.  */
00128         makeTexPK = (*p == '0');
00129 #ifdef HAVE_LIBKPATHSEA
00130         kpse_set_program_enabled (kpse_pk_format, makeTexPK, kpse_src_cmdline);
00131 #endif 
00132        if (makeTexPK)
00133          Message(PARSE_STDIN,"MakeTeXPK enabled\n");
00134        else
00135          Message(PARSE_STDIN,"MakeTeXPK disabled\n");
00136         break;
00137       case 'm':
00138        if (strcmp(p,"ode") == 0 ) {
00139          if (argv[i+1])
00140            user_mfmode = argv[++i] ;
00141          Message(PARSE_STDIN,"MetaFont mode: %s\n",user_mfmode);
00142          break;
00143        }
00144        goto DEFAULT;
00145       case 'h':
00146        if (strcmp(p,"elp") == 0 ) {
00147          break;
00148        } else if (strncmp(p,"eight",5) == 0 ) { /* Height reporting */ 
00149          if (p[5] != '0') {
00150            flags |= REPORT_HEIGHT;
00151            Message(PARSE_STDIN,"Height reporting on\n",p);
00152          } else {
00153            flags &= ~REPORT_HEIGHT;
00154            Message(PARSE_STDIN,"Height reporting off\n");
00155          }
00156          break;
00157        }
00158        goto DEFAULT;
00159 #endif /* MAKETEXPK */
00160       case 'O' : /* Offset */
00161        if (*p == 0 && argv[i+1])
00162          p = argv[++i] ;
00163        handlepapersize(p, &x_offset_def, &y_offset_def) ;
00164        Message(PARSE_STDIN,"Offset: (%d,%d)\n",x_offset_def,y_offset_def);
00165         break ;
00166       case 'e':
00167        if (strncmp(p,"xpand-bbox",10) == 0 ) {   
00168          if (p[10] != '0') {
00169            flags |= EXPAND_BBOX;
00170            Message(PARSE_STDIN,"BBox expansion on\n",p);
00171          } else {
00172            flags &= ~EXPAND_BBOX;
00173            Message(PARSE_STDIN,"BBox expansion off\n");
00174          }
00175          break;
00176        }
00177        goto DEFAULT;
00178       case 'T' :
00179        if (*p == 0 && argv[i+1])
00180          p = argv[++i];
00181        if (strcmp(p,"bbox")==0) {
00182          x_width_def=0;
00183          y_width_def=0;
00184          Message(PARSE_STDIN,"Pagesize: (bbox)\n");
00185        } else if (strcmp(p,"tight")==0) {
00186          x_width_def=-1;
00187          y_width_def=-1;
00188          Message(PARSE_STDIN,"Pagesize: (tight bbox)\n");
00189        } else {
00190          handlepapersize(p, &x_width_def, &y_width_def) ;
00191          Message(PARSE_STDIN,"Pagesize: (%d,%d)\n",
00192                 x_width_def,y_width_def);
00193        }
00194        break ;
00195       case 't':       /* specify paper format, only for cropmarks */
00196 #if HAVE_GDIMAGECREATETRUECOLOR
00197        /* Truecolor */
00198        if (strncmp(p,"ruecolor",8)==0) { 
00199          if (p[8] != '0') {
00200            flags |= RENDER_TRUECOLOR; 
00201            Message(PARSE_STDIN,"Truecolor mode on\n",p);
00202          } else { 
00203            flags &= ~RENDER_TRUECOLOR; 
00204            Message(PARSE_STDIN,"Truecolor mode off\n");
00205          }
00206        } else 
00207 #endif
00208 #ifdef HAVE_LIBT1
00209        if ( strncmp(p,"1lib",4) == 0 ) { /* -t1lib activation */
00210          if (p[4] != '0') {
00211            flags |= USE_LIBT1;
00212            Message(PARSE_STDIN,"t1lib rendering on\n",p);
00213          } else { 
00214            flags &= ~USE_LIBT1;
00215            Message(PARSE_STDIN,"t1lib rendering off\n");
00216          } 
00217         } else
00218 #endif
00219 
00220          { /* cropmarks not implemented yet */
00221            if (*p == 0 && argv[i+1])
00222              p = argv[++i] ;
00223            if (strcmp(p,"a4")==0) {
00224              handlepapersize("210mm,297mm",&x_pwidth,&y_pwidth);
00225            } else if (strcmp(p,"letter")==0) {
00226              handlepapersize("8.5in,11in",&x_pwidth,&y_pwidth);
00227            } else if (strcmp(p,"legal")==0) {
00228              handlepapersize("8.5in,14in",&x_pwidth,&y_pwidth);
00229            } else if (strcmp(p,"executive")==0) {
00230              handlepapersize("7.25in,10.5in",&x_pwidth,&y_pwidth);
00231            } else
00232              Fatal("The papersize %s is not implemented, sorry.\n",p);
00233            Message(PARSE_STDIN,"Papersize: %s\n",p);
00234          }
00235        break;
00236       case 'c':
00237        if (strncmp(p,"acheimages",10)==0) { 
00238          if (p[10] != '0') {
00239            flags |= CACHE_IMAGES;
00240            Message(PARSE_STDIN,"Caching images\n",p);
00241          } else { 
00242            flags &= ~CACHE_IMAGES;
00243            Message(PARSE_STDIN,"Not caching images\n");
00244          }
00245          break;
00246        }
00247        goto DEFAULT;
00248       case 'b':
00249        if ( *p == 'g' ) { /* -bg background color */
00250          p++;
00251          if (*p == 0 && argv[i+1])
00252            p = argv[++i] ;
00253          if (strncmp(p,"Transparent",11) == 0 ) 
00254            flags |= BG_TRANSPARENT;
00255          else
00256            background(p);
00257          if (flags & BG_TRANSPARENT) 
00258            Message(PARSE_STDIN,"Transp. background (fallback rgb %d,%d,%d)\n",
00259                   cstack[0].red,cstack[0].green,cstack[0].blue);
00260          else 
00261            Message(PARSE_STDIN,"Background: rgb %d,%d,%d\n",
00262                   cstack[0].red,cstack[0].green,cstack[0].blue);
00263          break;
00264        } else if (strcmp(p, "dpi")==0) {
00265          p+=3;
00266          if (*p == 0 && argv[i+1])
00267            p = argv[++i] ;
00268          user_bdpi = atoi(p);
00269          if (user_bdpi < 10 || user_bdpi > 10000)
00270            Fatal("bad --bdpi parameter (-D).") ;
00271          Message(PARSE_STDIN,"Bdpi: %d\n",user_bdpi);
00272          break;
00273        } else if ( *p == 'd' ) { /* -bd border width */
00274          int tmpi;
00275          char* tmps;
00276          p++;
00277          if (*p == 0 && argv[i+1])
00278            p = argv[++i] ;
00279          tmpi = strtol(p, &tmps, 10);
00280          if (p<tmps) {
00281            borderwidth=tmpi;
00282            Message(PARSE_STDIN,"Transp. border: %d dots\n",borderwidth);
00283          }
00284          if (*tmps) {
00285            stringrgb(tmps, &bordercolor.red, &bordercolor.green, &bordercolor.blue);
00286            userbordercolor=TRUE;
00287            if (borderwidth==0) {
00288              borderwidth=1;
00289              Message(PARSE_STDIN,"Transp. border: %d dots\n",borderwidth);
00290            }
00291            Message(PARSE_STDIN,"Transp. border: rgb %d,%d,%d\n",
00292                   bordercolor.red, bordercolor.green, bordercolor.blue);
00293          }
00294          break;
00295        } 
00296        goto DEFAULT;
00297       case 'f':
00298        if ( *p == 'g' ) { /* -fg foreground color */
00299          p++;
00300          if (*p == 0 && argv[i+1])
00301            p = argv[++i] ;
00302          resetcolorstack(p);
00303          Message(PARSE_STDIN,"Foreground: rgb %d,%d,%d\n",
00304                 cstack[1].red,cstack[1].green,cstack[1].blue);
00305          break;
00306 #ifdef HAVE_FT2
00307        } else if ( strncmp(p,"reetype",7) == 0 ) { /* -freetype activation */
00308          if (p[7] != '0') {
00309            flags |= USE_FREETYPE;
00310            Message(PARSE_STDIN,"FreeType rendering on\n",p);
00311          } else { 
00312            flags &= ~USE_FREETYPE;
00313            Message(PARSE_STDIN,"FreeType rendering off\n");
00314          }
00315          break;
00316 #endif
00317        } else if (strcmp(p,"ollow") == 0 ) {
00318          if (DVIFollowToggle())
00319            Message(PARSE_STDIN,"Follow mode on\n");
00320          else
00321            Message(PARSE_STDIN,"Follow mode off\n");
00322          break;
00323        }
00324        goto DEFAULT;
00325       case 'x' : case 'y' :
00326        if (*p == 0 && argv[i+1])
00327          p = argv[++i] ;
00328        usermag = atoi(p);
00329        if (usermag < 1 || usermag > 1000000)
00330          Fatal("Bad magnification parameter (-x or -y).") ;
00331        Message(PARSE_STDIN,"Magstep: %d\n",usermag);
00332        /*overridemag = (c == 'x' ? 1 : -1) ;*/
00333        break ;
00334       case 'g' :
00335        if (strncmp(p,"amma",4)==0) { /* --gamma correction */ 
00336          double gamma=0.0;
00337 
00338          p+=4;
00339          if (*p == 0 && argv[i+1])
00340            p = argv[++i];
00341          if (p!=NULL)
00342            gamma=atof(p);
00343          if (gamma==0.0) {
00344            Warning("Bad gamma value, default is %f",DEFAULT_GAMMA);
00345            gamma=DEFAULT_GAMMA;
00346          }
00347          Gamma(gamma);
00348          Message(PARSE_STDIN,"Gamma value is %s\n", gamma);
00349          break;
00350 #ifdef HAVE_GDIMAGEGIF
00351        } else if (strncmp(p,"if",2)==0) { /* --gif output */ 
00352          flags |= GIF_OUTPUT;
00353          Message(PARSE_STDIN,"GIF output\n");
00354          break;
00355 #endif
00356        }
00357        goto DEFAULT;
00358       case 'p' :
00359        if (*p == 'p') {  /* a -pp specifier for a page list */
00360          ppused=true;
00361          p++ ;
00362          if (*p == 0 && argv[i+1])
00363            p = argv[++i];
00364          Message(PARSE_STDIN,"Page list: %s\n",p);
00365          if (ParsePages(p))
00366            Fatal("bad page list specifier (-pp).");
00367        } else if (strncmp(p,"ng",2)==0) { /* --png output */ 
00368          flags &= ~GIF_OUTPUT;
00369          Message(PARSE_STDIN,"PNG output\n");
00370        } else if (strncmp(p,"icky",4)==0) { 
00371          if (p[4] != '0') {
00372            flags |= MODE_PICKY;
00373            Message(PARSE_STDIN,"No images output for pages with warnings\n",p);
00374          } else {
00375            flags &= ~MODE_PICKY;
00376            Message(PARSE_STDIN,"Images output even for pages with warnings\n");
00377          }
00378        } else {   /* a -p specifier for first page */
00379          int32_t firstpage;
00380          bool abspage=false;
00381 
00382          if (*p == 0 && argv[i+1])
00383            p = argv[++i] ;
00384          if (*p == '=') {
00385            abspage=true;
00386            p++ ;
00387          }
00388          firstpage = atoi(p);
00389          FirstPage(firstpage,abspage);
00390          Message(PARSE_STDIN,"First page: %d\n",firstpage);
00391        }
00392        break ;
00393       case 's' :
00394        if (strncmp(p,"trict",5)==0) { 
00395          if (p[5] != '0') {
00396            flags |= MODE_STRICT;
00397            Message(PARSE_STDIN,"Warnings are fatal\n",p);
00398          } else {
00399            flags &= ~MODE_STRICT;
00400            Message(PARSE_STDIN,"Warnings are not fatal\n");
00401          }
00402        } else
00403          goto DEFAULT;
00404        break ;
00405       case 'n' :
00406        if (strncmp(p,"oghostscript",12)==0) { 
00407          if (p[12] != '0') {
00408            flags |= NO_GHOSTSCRIPT;
00409            Message(PARSE_STDIN,"No GhostScript calls\n",p);
00410          } else {
00411            flags &= ~NO_GHOSTSCRIPT;
00412            Message(PARSE_STDIN,"GhostScript calls made\n");
00413          }
00414        } else if (strncmp(p,"ogssafer",8)==0) { 
00415          if (p[8] != '0') {
00416            flags |= NO_GSSAFER;
00417            Message(PARSE_STDIN,"GhostScript calls does not use -dSAFER\n",p);
00418          } else {
00419            flags &= ~NO_GSSAFER;
00420            Message(PARSE_STDIN,"GhostScript calls use -dSAFER\n");
00421          }
00422        } else
00423          goto DEFAULT;
00424        break ;
00425       case 'l':
00426        {
00427          int32_t lastpage;
00428          bool abspage=false;
00429 
00430          if (*p == 0 && argv[i+1])
00431            p = argv[++i] ;
00432          if (*p == '=') {
00433            abspage=true;
00434            p++ ;
00435          } 
00436          lastpage = atoi(p);
00437          LastPage(lastpage,abspage);
00438          Message(PARSE_STDIN,"Last page: %d\n",lastpage);
00439        }
00440        break ;
00441       case 'q':       /* quiet operation */
00442        if (*p != '0')
00443          flags &= (~BE_NONQUIET & ~BE_VERBOSE);
00444         else
00445          flags |= BE_NONQUIET;
00446        break;
00447       case 'r':       /* process pages in reverse order */
00448        if (*p != '0') {
00449          Message(PARSE_STDIN,"Reverse order\n");
00450          Reverse(true);
00451        } else {
00452          Message(PARSE_STDIN,"Normal order\n");
00453          Reverse(false);
00454        }
00455         break;
00456       case 'v':    /* verbatim mode */
00457        if (strcmp(p, "ersion")==0) {
00458          if (strcmp(basename(programname),PACKAGE_NAME)!=0)
00459            printf("%s (%s) %s\n",basename(programname),
00460                  PACKAGE_NAME,PACKAGE_VERSION);
00461          else
00462            puts(PACKAGE_STRING);
00463 #ifdef HAVE_LIBKPATHSEA
00464          puts (KPSEVERSION);
00465 #endif
00466          puts ("Copyright (C) 2002-2005 Jan-Åke Larsson.\n\
00467 There is NO warranty.  You may redistribute this software\n\
00468 under the terms of the GNU General Public License.\n\
00469 For more information about these matters, see the files\n\
00470 named COPYING and dvipng.c.");
00471          exit (EXIT_SUCCESS); 
00472        }
00473        if (*p != '0')
00474          flags |= BE_NONQUIET | BE_VERBOSE;
00475        else
00476          flags &= ~BE_VERBOSE;
00477         break;
00478       case 'D' :
00479        if (*p == 0 && argv[i+1])
00480          p = argv[++i] ;
00481        dpi = atoi(p);
00482        if (dpi < 10 || dpi > 10000)
00483          Fatal("bad -D parameter.") ;
00484        Message(PARSE_STDIN,"Dpi: %d\n",dpi);
00485        break;
00486       case 'Q':       /* quality (= shrinkfactor) */
00487        if (*p == 0 && argv[i+1])
00488          p = argv[++i] ;
00489         shrinkfactor = atoi(p);
00490        Message(PARSE_STDIN,"Quality: %d\n",shrinkfactor);
00491        break;
00492 #ifdef HAVE_GDIMAGEPNGEX
00493       case 'z':
00494        if (*p == 0 && argv[i+1])
00495          p = argv[++i];
00496        compression = atoi(p);
00497        break;
00498 #endif
00499       case '\0':
00500        flags |= PARSE_STDIN;
00501        break;
00502       DEFAULT: default:
00503        Warning("%s is not a valid option", argv[i]);
00504       }
00505     } else {
00506       dviname=argv[i];
00507     }
00508   }
00509   if (dviname != NULL) {
00510     if (dvi != NULL && dvi->filep != NULL) 
00511       DVIClose(dvi);
00512     dvi=DVIOpen(dviname,outname);  
00513   }
00514 
00515   if (dvi==NULL) {
00516     fprintf(stdout,"\nUsage: %s [OPTION]... FILENAME[.dvi]\n", programname);
00517     fprintf(stdout,"Options are chosen to be similar to dvips' options where possible:\n");
00518 #ifdef DEBUG
00519     fprintf(stdout,"  -d #         Debug (# is the debug bitmap, 1 if not given)\n");
00520 #endif
00521     fprintf(stdout,"  -D #         Output resolution\n");
00522     fprintf(stdout,"  -l #         Last page to be output\n");
00523     fprintf(stdout,"  --mode s     MetaFont mode (default 'cx')\n");
00524     fprintf(stdout,"  -M*          Don't make PK fonts\n");
00525     fprintf(stdout,"  -o f         Output file, '%%d' is pagenumber\n");
00526     fprintf(stdout,"  -O c         Image offset\n");
00527     fprintf(stdout,"  -p #         First page to be output\n");
00528     fprintf(stdout,"  -pp #,#..    Page list to be output\n");
00529     fprintf(stdout,"  -q*          Quiet operation\n");
00530     fprintf(stdout,"  -r*          Reverse order of pages\n");
00531     /*    fprintf(stdout,"  -t c         Paper format (also accepts e.g., '-t a4')\n");*/
00532     fprintf(stdout,"  -T c         Image size (also accepts '-T bbox' and '-T tight')\n");
00533     fprintf(stdout,"  -v*          Verbose operation\n");
00534     fprintf(stdout,"  -x #         Override dvi magnification\n");
00535     fprintf(stdout,"  -            Interactive query of options\n");
00536     fprintf(stdout,"\nThese do not correspond to dvips options:\n");
00537     fprintf(stdout,"  -bd #        Transparent border width in dots\n");
00538     fprintf(stdout,"  -bd s        Transparent border fallback color (TeX-style color)\n");
00539     fprintf(stdout,"  --bdpi #     Set the base (Metafont) resolution\n");
00540     fprintf(stdout,"  -bg s        Background color (TeX-style color)\n");
00541     fprintf(stdout,"  --depth*     Output the image depth on stdout\n");
00542     fprintf(stdout,"  --dvinum*    Use TeX page numbers in output filenames\n");
00543     fprintf(stdout,"  -fg s        Foreground color (TeX-style color)\n");
00544     fprintf(stdout,"  --follow*    Follow mode\n");
00545 #ifdef HAVE_FT2
00546     fprintf(stdout,"  --freetype*  FreeType font rendering (default on)\n");
00547 #endif
00548     fprintf(stdout,"  --gamma #    Control color interpolation\n");
00549 #ifdef HAVE_GDIMAGEGIF
00550     fprintf(stdout,"  --gif        Output GIF images (dvigif default)\n");
00551 #endif
00552     fprintf(stdout,"  --height*    Output the image height on stdout\n");
00553     fprintf(stdout,"  --noghostscript*  Don't use ghostscript for PostScript specials\n");
00554     fprintf(stdout,"  --nogssafer* Don't use -dSAFER in ghostscript calls\n");
00555     fprintf(stdout,"  --picky      When a warning occurs, don't output image\n");
00556 #ifdef HAVE_GDIMAGEGIF
00557     fprintf(stdout,"  --png        Output PNG images (dvipng default)\n");
00558 #endif
00559     fprintf(stdout,"  --strict     When a warning occurs, exit\n");
00560 #ifdef HAVE_LIBT1
00561     fprintf(stdout,"  --t1lib*     T1lib font rendering (default on)\n");
00562 #endif
00563 #ifdef HAVE_GDIMAGECREATETRUECOLOR
00564     fprintf(stdout,"  --truecolor* Truecolor output\n");
00565 #endif
00566     fprintf(stdout,"  -Q #         Quality (T1lib and PK subsampling)\n");
00567 #ifdef HAVE_GDIMAGEPNGEX
00568     fprintf(stdout,"  -z #         PNG compression level\n");
00569 #endif
00570     
00571     fprintf(stdout,"\n   # = number   f = file   s = string  * = suffix, '0' to turn off\n");
00572     fprintf(stdout,"       c = comma-separated dimension pair (e.g., 3.2in,-32.1cm)\n\n");
00573     /*#ifdef HAVE_LIBKPATHSEA
00574       {
00575       extern DllImport char *kpse_bug_address;
00576       putc ('\n', stdout);
00577       fputs (kpse_bug_address, stdout);
00578       }
00579       #endif*/
00580     if ((flags & PARSE_STDIN) == 0) {
00581       exit(EXIT_SUCCESS);
00582     }
00583   }
00584   if ((flags & PARSE_STDIN) == 0 && (!ppused)) 
00585     ParsePages("-");
00586   return((flags & PARSE_STDIN) != 0);
00587 }
00588 
00589 void DecodeString(char *string)
00590 {
00591 #define PARSEARGS 10
00592   char    *strv[PARSEARGS];
00593   int     strc=1;
00594   strv[0]=NULL;                       /* No program name */
00595 
00596   while (*string==' ' || *string=='\t' || *string=='\n') 
00597     string++;
00598   while (*string!='\0') {
00599     strv[strc++]=string;
00600     if (*string!='\'') {
00601       /* Normal split at whitespace */
00602       while (*string!=' ' && *string!='\t' && *string!='\n' && *string!='\0') 
00603        string++;
00604     } else {
00605       /* String delimiter found , so search for next */
00606       strv[strc-1]=++string;
00607       while (*string!='\'' && *string!='\0') 
00608        string++;
00609     }
00610     if (*string!='\0')
00611       *string++='\0';
00612     while (*string==' ' || *string=='\t' || *string=='\n') 
00613       string++;
00614   }
00615   if (strc>1) /* Nonempty */
00616     (void) DecodeArgs(strc,strv);
00617 }
00618 
00619 
00620 
00621 uint32_t UNumRead(unsigned char* current, register int n)
00622 {
00623   uint32_t x = (unsigned char) *(current)++; /* number being constructed */
00624   while(--n) 
00625     x = (x << 8) | *(current)++;
00626   return(x);
00627 }
00628 
00629 int32_t SNumRead(unsigned char* current, register int n)
00630 {
00631   int32_t x = (signed char) *(current)++; /* number being constructed */
00632   while(--n)
00633     x = (x << 8) | *(current)++;
00634   return(x);
00635 }
00636 
00637 
00638 /**********************************************************************/
00639 /******************************  Fatal  *******************************/
00640 /**********************************************************************/
00641 void Fatal (char *fmt, ...)
00642 {
00643   va_list args;
00644 
00645   va_start(args, fmt);
00646   fflush(stdout);
00647   fprintf(stderr, "\n");
00648   fprintf(stderr, "%s: Fatal error, ", programname);
00649   vfprintf(stderr, fmt, args);
00650   
00651   fprintf(stderr, "\n\n");
00652   va_end(args);
00653 
00654   ClearFonts();
00655 #ifdef HAVE_FT2
00656   if (libfreetype)
00657     (void) FT_Done_FreeType(libfreetype); /* at this point, ignore error */
00658 #endif  
00659 #ifdef HAVE_LIBT1
00660   if (libt1)
00661     (void) T1_CloseLib(); /* at this point, ignore error */
00662 #endif  
00663   exit(EXIT_FATAL);
00664 }
00665 
00666 /*-->Warning*/
00667 /**********************************************************************/
00668 /*****************************  Warning  ******************************/
00669 /**********************************************************************/
00670 void Warning(char *fmt, ...)
00671 {
00672   va_list args;
00673 
00674   va_start(args, fmt);
00675 
00676   if ( flags & BE_NONQUIET ) {
00677     fflush(stdout);
00678     fprintf(stderr, "%s warning: ", programname);
00679     vfprintf(stderr, fmt, args);
00680     fprintf(stderr, "\n");
00681     va_end(args);
00682   }
00683 }
00684 
00685 /*-->Message*/
00686 /**********************************************************************/
00687 /*****************************  Message  ******************************/
00688 /**********************************************************************/
00689 void Message(int activeflags, char *fmt, ...)
00690 {
00691   va_list args;
00692 
00693   va_start(args, fmt);
00694   if ( flags & activeflags ) {
00695     vfprintf(stdout, fmt, args);
00696   }
00697   va_end(args);
00698 }
00699 
00700 
00701 bool MmapFile (char *filename,struct filemmap *fmmap)
00702 {
00703 #ifndef MIKTEX
00704   struct stat stat;
00705 #endif
00706 
00707   DEBUG_PRINT(DEBUG_DVI,("\n  OPEN FILE:\t'%s'", filename));
00708   fmmap->mmap=NULL;
00709 #ifndef MIKTEX
00710   if ((fmmap->fd = open(filename,O_RDONLY)) == -1) {
00711     Warning("cannot open file <%s>", filename);
00712     return(true);
00713   }
00714   fstat(fmmap->fd,&stat);
00715   fmmap->size=stat.st_size;
00716 # ifdef HAVE_MMAP
00717   fmmap->mmap = mmap(NULL,fmmap->size, PROT_READ, MAP_SHARED,fmmap->fd,0);
00718   if (fmmap->mmap == (char*)-1) {
00719     Warning("cannot mmap file <%s>",filename);
00720     fmmap->mmap=NULL;
00721     close(fmmap->fd);
00722     return(true);
00723   }
00724 # else /* HAVE_MMAP */
00725   fmmap->mmap = malloc(fmmap->size);
00726   if (read(fmmap->fd,fmmap->mmap,fmmap->size)<fmmap->size) {
00727     Warning("too little data in <%s>",filename);
00728     free(fmmap->mmap);
00729     fmmap->mmap=NULL;
00730     close(fmmap->fd);
00731     return(true);
00732   }
00733   close(fmmap->fd);
00734 # endif /* HAVE_MMAP */
00735 #else /* MIKTEX */
00736   fmmap->hFile = CreateFile(filename, GENERIC_READ, 0, 0, OPEN_EXISTING,
00737                          FILE_FLAG_RANDOM_ACCESS, 0);
00738   if (fmmap->hFile == INVALID_HANDLE_VALUE) {
00739     Warning("cannot open file <%s>", filename);
00740     return(true);
00741   }
00742   fmmap->size = GetFileSize(hFile, 0);
00743   fmmap->hMap = CreateFileMapping(hFile, 0, PAGE_READONLY, 0, 0, 0);
00744   if (fmmap->hMap == 0) {
00745     CloseHandle (fmmap->hFile);
00746     Warning("cannot CreateFileMapping() file <%s>", filename);
00747     return(true);
00748   }
00749   fmmap->mmap = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0);
00750   if (fmmap->mmap == NULL) {
00751     Warning("cannot MapViewOfFile() file <%s>", filename);
00752     CloseHandle (fmmap->hMap);
00753     CloseHandle (fmmap->hFile);
00754     return(true);
00755   }
00756 #endif  /* MIKTEX */
00757   return(false);
00758 }
00759 
00760 void UnMmapFile(struct filemmap* fmmap)
00761 {
00762   if (fmmap->mmap!=NULL) {
00763 #ifndef MIKTEX
00764 # ifdef HAVE_MMAP
00765     if (munmap(fmmap->mmap,fmmap->size))
00766       Warning("cannot munmap file at 0x%X",fmmap->mmap);
00767     if (close(fmmap->fd))
00768       Warning("cannot close file descriptor %d",fmmap->fd);
00769 # else /* HAVE_MMAP */
00770     free(fmmap->mmap);
00771 # endif /* HAVE_MMAP */
00772 #else  /* MIKTEX */
00773     UnmapViewOfFile (fmmap->mmap);
00774     CloseHandle (fmmap->hMap);
00775     CloseHandle (fmmap->hFile);
00776 #endif /* MIKTEX */
00777   }
00778   fmmap->mmap=NULL;
00779 }