1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
|
/* misc.c */
/************************************************************************
Part of the dvipng distribution
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program. If not, see
<http://www.gnu.org/licenses/>.
Copyright (C) 2002-2015 Jan-ke Larsson
************************************************************************/
#include "dvipng.h"
#ifdef HAVE_LIBGEN_H
# include <libgen.h>
#else
#define basename xbasename
#endif
#include <fcntl.h> /* open/close */
#ifdef HAVE_MMAP
#include <sys/mman.h>
#endif
#include <sys/stat.h>
static char *programname;
/*-->DecodeArgs*/
/*********************************************************************/
/***************************** DecodeArgs ****************************/
/*********************************************************************/
bool DecodeArgs(int argc, char ** argv)
{
int i; /* argument index for options */
bool ppused=false; /* Flag when -pp is used */
int32_t number; /* Temporary storage for numeric parameter */
char *dviname=NULL; /* Name of dvi file */
char *outname=NULL; /* Name of output file */
if (argv[0]) {
#ifdef HAVE_GDIMAGEGIF
programname=strrchr(argv[0],'/');
if (programname!=NULL)
programname++;
else
programname=argv[0];
if (strncmp(programname,"dvigif",6)==0)
option_flags |= GIF_OUTPUT;
#endif
programname=argv[0];
Message(BE_NONQUIET,"This is %s",programname);
if (strcmp(basename(programname),PACKAGE_NAME)!=0)
Message(BE_NONQUIET," (%s)", PACKAGE_NAME);
Message(BE_NONQUIET," %s Copyright 2002-2015 Jan-Ake Larsson\n",
PACKAGE_VERSION);
}
for (i=1; i<argc; i++) {
if (*argv[i]=='-') {
char *p=argv[i]+2 ;
char c=argv[i][1] ;
if (c=='-') {
p++;
c=argv[i][2];
}
switch (c) {
case 'd': /* selects Debug output */
if (*p>'9' && *p!='-') {
if (strncmp(p,"vinum",5)==0) {
if (p[5] != '0') {
option_flags |= DVI_PAGENUM;
Message(PARSE_STDIN,"DVI page number output on\n",p);
} else {
option_flags &= ~DVI_PAGENUM;
Message(PARSE_STDIN,"DVI page number output off\n");
}
break;
} else if (strncmp(p,"epth",4)==0) { /* Depth reporting */
if (p[4] != '0') {
option_flags |= REPORT_DEPTH;
Message(PARSE_STDIN,"Depth reporting on\n",p);
} else {
option_flags &= ~REPORT_DEPTH;
Message(PARSE_STDIN,"Depth reporting off\n");
}
break;
}
goto DEFAULT;
} else {
#ifdef DEBUG
if (*p == 0 && argv[i+1])
p = argv[i+1];
debug = atoi(p);
if (debug > 0) {
if (p == argv[i+1]) i++;
} else
debug = DEBUG_DEFAULT;
Message(PARSE_STDIN,"Debug output enabled\n");
#ifdef HAVE_LIBKPATHSEA
kpathsea_debug = debug / LASTDEBUG / 2 ;
#endif
#else
Warning("This instance of %s was compiled without the debug (-d) option",
programname);
#endif
break;
}
case 'o': /* Output file is specified */
if (*p == 0 && argv[i+1])
p = argv[++i] ;
outname=p;
/* remove .png extension */
Message(PARSE_STDIN,"Output file: %s\n",
outname);
break;
#ifdef MAKETEXPK
case 'M':
/* -M, -M1 => don't make font; -M0 => do. */
makeTexPK = (*p == '0');
#ifdef HAVE_LIBKPATHSEA
kpse_set_program_enabled (kpse_pk_format, makeTexPK, kpse_src_cmdline);
#endif
if (makeTexPK)
Message(PARSE_STDIN,"MakeTeXPK enabled\n");
else
Message(PARSE_STDIN,"MakeTeXPK disabled\n");
break;
#endif /* MAKETEXPK */
case 'm':
if (strcmp(p,"ode") == 0 ) {
if (argv[i+1])
user_mfmode = argv[++i] ;
Message(PARSE_STDIN,"MetaFont mode: %s\n",user_mfmode);
break;
}
goto DEFAULT;
case 'h':
if (strcmp(p,"elp") == 0 ) {
break;
} else if (strncmp(p,"eight",5) == 0 ) { /* Height reporting */
if (p[5] != '0') {
option_flags |= REPORT_HEIGHT;
Message(PARSE_STDIN,"Height reporting on\n",p);
} else {
option_flags &= ~REPORT_HEIGHT;
Message(PARSE_STDIN,"Height reporting off\n");
}
break;
}
goto DEFAULT;
case 'O' : /* Offset */
if (*p == 0 && argv[i+1])
p = argv[++i] ;
handlepapersize(p, &x_offset_def, &y_offset_def) ;
Message(PARSE_STDIN,"Offset: (%d,%d)\n",x_offset_def,y_offset_def);
break ;
case 'e':
if (strncmp(p,"xpand-bbox",10) == 0 ) {
if (p[10] != '0') {
option_flags |= EXPAND_BBOX;
Message(PARSE_STDIN,"BBox expansion on\n",p);
} else {
option_flags &= ~EXPAND_BBOX;
Message(PARSE_STDIN,"BBox expansion off\n");
}
break;
}
goto DEFAULT;
case 'T' :
if (*p == 0 && argv[i+1])
p = argv[++i];
if (strcmp(p,"bbox")==0) {
x_width_def=0;
y_width_def=0;
Message(PARSE_STDIN,"Pagesize: (bbox)\n");
} else if (strcmp(p,"tight")==0) {
x_width_def=-1;
y_width_def=-1;
Message(PARSE_STDIN,"Pagesize: (tight bbox)\n");
} else {
handlepapersize(p, &x_width_def, &y_width_def) ;
Message(PARSE_STDIN,"Pagesize: (%d,%d)\n",
x_width_def,y_width_def);
}
break ;
case 't': /* specify paper format, only for cropmarks */
#ifdef HAVE_GDIMAGECREATETRUECOLOR
/* Truecolor */
if (strncmp(p,"ruecolor",8)==0) {
if (p[8] != '0') {
option_flags |= FORCE_TRUECOLOR;
Message(PARSE_STDIN,"Truecolor mode on\n",p);
} else {
option_flags &= ~FORCE_TRUECOLOR;
Message(PARSE_STDIN,"Truecolor mode off\n");
}
} else
#endif
{ /* cropmarks not implemented yet */
if (*p == 0 && argv[i+1])
p = argv[++i] ;
if (strcmp(p,"a4")==0) {
handlepapersize("210mm,297mm",&x_pwidth,&y_pwidth);
} else if (strcmp(p,"letter")==0) {
handlepapersize("8.5in,11in",&x_pwidth,&y_pwidth);
} else if (strcmp(p,"legal")==0) {
handlepapersize("8.5in,14in",&x_pwidth,&y_pwidth);
} else if (strcmp(p,"executive")==0) {
handlepapersize("7.25in,10.5in",&x_pwidth,&y_pwidth);
} else
Fatal("papersize %s is not implemented",p);
Message(PARSE_STDIN,"Papersize: %s\n",p);
}
break;
/* case 'c': */
/* if (strncmp(p,"acheimages",10)==0) { */
/* if (p[10] != '0') { */
/* option_flags |= CACHE_IMAGES; */
/* Message(PARSE_STDIN,"Caching images\n",p); */
/* } else { */
/* option_flags &= ~CACHE_IMAGES; */
/* Message(PARSE_STDIN,"Not caching images\n"); */
/* } */
/* break; */
/* } */
/* goto DEFAULT; */
case 'b':
if ( *p == 'g' ) { /* -bg background color */
p++;
if (*p == 0 && argv[i+1])
p = argv[++i] ;
if (strncmp(p,"Transparent",11) == 0 )
option_flags |= BG_TRANSPARENT_ALPHA;
else if (strncmp(p,"transparent",11) == 0 )
option_flags |= BG_TRANSPARENT;
else
background(p);
if (option_flags & BG_TRANSPARENT)
Message(PARSE_STDIN,"Transp. background (fallback rgb %d,%d,%d)\n",
cstack[0].red,cstack[0].green,cstack[0].blue);
else
Message(PARSE_STDIN,"Background: rgb %d,%d,%d\n",
cstack[0].red,cstack[0].green,cstack[0].blue);
break;
} else if (strcmp(p, "dpi")==0) {
p+=3;
if (*p == 0 && argv[i+1])
p = argv[++i];
number = atoi(p);
if (number < 10 || number > 10000)
Warning("Bad --bdpi parameter, ignored");
else {
user_bdpi=number;
Message(PARSE_STDIN,"Bdpi: %d\n",user_bdpi);
}
break;
} else if ( *p == 'd' ) { /* -bd border width */
int tmpi;
char* tmps;
p++;
if (*p == 0 && argv[i+1])
p = argv[++i] ;
tmpi = strtol(p, &tmps, 10);
if (p<tmps) {
borderwidth=tmpi;
Message(PARSE_STDIN,"Transp. border: %d dots\n",borderwidth);
}
if (*tmps) {
stringrgb(tmps, &bordercolor.red, &bordercolor.green, &bordercolor.blue);
userbordercolor=TRUE;
if (borderwidth==0) {
borderwidth=1;
Message(PARSE_STDIN,"Transp. border: %d dots\n",borderwidth);
}
Message(PARSE_STDIN,"Transp. border: rgb %d,%d,%d\n",
bordercolor.red, bordercolor.green, bordercolor.blue);
}
break;
}
goto DEFAULT;
case 'f':
if ( *p == 'g' ) { /* -fg foreground color */
p++;
if (*p == 0 && argv[i+1])
p = argv[++i] ;
resetcolorstack(p);
Message(PARSE_STDIN,"Foreground: rgb %d,%d,%d\n",
cstack[1].red,cstack[1].green,cstack[1].blue);
break;
#ifdef HAVE_FT2
} else if ( strncmp(p,"reetype",7) == 0 ) { /* -freetype activation */
if (p[7] != '0') {
option_flags |= USE_FREETYPE;
Message(PARSE_STDIN,"FreeType rendering on\n",p);
} else {
option_flags &= ~USE_FREETYPE;
Message(PARSE_STDIN,"FreeType rendering off\n");
}
break;
#endif
} else if (strcmp(p,"ollow") == 0 ) {
if (DVIFollowToggle())
Message(PARSE_STDIN,"Follow mode on\n");
else
Message(PARSE_STDIN,"Follow mode off\n");
break;
}
goto DEFAULT;
case 'x' : case 'y' :
if (*p == 0 && argv[i+1])
p = argv[++i] ;
number = atoi(p);
if (number < 1 || number > 1000000)
Warning("Bad magnification parameter (-x or -y), ignored");
else {
usermag=number;
Message(PARSE_STDIN,"Magstep: %d\n",usermag);
/*overridemag = (c == 'x' ? 1 : -1) ;*/
}
break ;
case 'g' :
if (strncmp(p,"amma",4)==0) { /* --gamma correction */
double gamma=0.0;
p+=4;
if (*p == 0 && argv[i+1])
p = argv[++i];
if (p!=NULL)
gamma=atof(p);
if (gamma==0.0) {
Warning("Bad gamma value, default is %f",DEFAULT_GAMMA);
gamma=DEFAULT_GAMMA;
}
Gamma(gamma);
Message(PARSE_STDIN,"Gamma value is %s\n", gamma);
break;
#ifdef HAVE_GDIMAGEGIF
} else if (strncmp(p,"if",2)==0) { /* --gif output */
option_flags |= GIF_OUTPUT;
Message(PARSE_STDIN,"GIF output\n");
break;
#endif
}
goto DEFAULT;
case 'p' :
if (*p == 'p') { /* a -pp specifier for a page list */
ppused=true;
p++ ;
if (*p == 0 && argv[i+1])
p = argv[++i];
Message(PARSE_STDIN,"Page list: %s\n",p);
if (ParsePages(p))
Fatal("bad page list specifier (-pp)");
} else if (strncmp(p,"ng",2)==0) { /* --png output */
option_flags &= ~GIF_OUTPUT;
Message(PARSE_STDIN,"PNG output\n");
} else if (strncmp(p,"icky",4)==0) {
if (p[4] != '0') {
option_flags |= MODE_PICKY;
Message(PARSE_STDIN,"No images output for pages with warnings\n",p);
} else {
option_flags &= ~MODE_PICKY;
Message(PARSE_STDIN,"Images output even for pages with warnings\n");
}
} else if (strncmp(p,"alette",6)==0) {
if (p[6] != '0') {
option_flags |= FORCE_PALETTE;
Message(PARSE_STDIN,"Forcing 256-color PNG output\n",p);
} else {
option_flags &= ~FORCE_PALETTE;
Message(PARSE_STDIN,"Allows truecolor PNG output\n");
}
} else { /* a -p specifier for first page */
int32_t firstpage;
bool abspage=false;
if (*p == 0 && argv[i+1])
p = argv[++i] ;
if (*p == '=') {
abspage=true;
p++ ;
}
if ((*p>='0'&&*p<='9') || (*p=='-' && *(p+1)>='0' && *(p+1)<='9')) {
firstpage = atoi(p);
FirstPage(firstpage,abspage);
Message(PARSE_STDIN,"First page: %d\n",firstpage);
} else
Warning("Bad firstpage (-p) parameter, ignored");
}
break ;
case 's' :
if (strncmp(p,"trict",5)==0) {
if (p[5] != '0') {
option_flags |= MODE_STRICT;
Message(PARSE_STDIN,"Warnings are fatal\n",p);
} else {
option_flags &= ~MODE_STRICT;
Message(PARSE_STDIN,"Warnings are not fatal\n");
}
} else
goto DEFAULT;
break ;
case 'n' :
if (strncmp(p,"oghostscript",12)==0) {
if (p[12] != '0') {
option_flags |= NO_GHOSTSCRIPT;
Message(PARSE_STDIN,"No GhostScript calls\n",p);
} else {
option_flags &= ~NO_GHOSTSCRIPT;
Message(PARSE_STDIN,"GhostScript calls made\n");
}
} else if (strncmp(p,"ogssafer",8)==0) {
if (p[8] != '0') {
option_flags |= NO_GSSAFER;
Message(PARSE_STDIN,"GhostScript calls does not use -dSAFER\n",p);
} else {
option_flags &= ~NO_GSSAFER;
Message(PARSE_STDIN,"GhostScript calls use -dSAFER\n");
}
} else if (strncmp(p,"ogs",3)==0) {
if (p[3] != '0') {
option_flags |= NO_GHOSTSCRIPT;
Message(PARSE_STDIN,"No GhostScript calls\n",p);
} else {
option_flags &= ~NO_GHOSTSCRIPT;
Message(PARSE_STDIN,"GhostScript calls made\n");
}
} else if (strncmp(p,"orawps",6)==0) {
if (p[6] != '0') {
option_flags |= NO_RAW_PS;
Message(PARSE_STDIN,"Conversion of raw PostScript will not be attempted\n",p);
} else {
option_flags &= ~NO_RAW_PS;
Message(PARSE_STDIN,"Conversion of raw PostScript will be attempted\n",p);
}
} else
goto DEFAULT;
break ;
case 'l':
{
int32_t lastpage;
bool abspage=false;
if (*p == 0 && argv[i+1])
p = argv[++i] ;
if (*p == '=') {
abspage=true;
p++ ;
}
if ((*p>='0'&&*p<='9') || (*p=='-' && *(p+1)>='0' && *(p+1)<='9')) {
lastpage = atoi(p);
LastPage(lastpage,abspage);
Message(PARSE_STDIN,"Last page: %d\n",lastpage);
} else
Warning("Bad lastpage (-l) parameter, ignored");
}
break ;
case 'q': /* quiet operation */
if (*p != '0')
option_flags &= (~BE_NONQUIET & ~BE_VERBOSE);
else
option_flags |= BE_NONQUIET;
break;
case 'r': /* process pages in reverse order */
if (*p != '0') {
Message(PARSE_STDIN,"Reverse order\n");
Reverse(true);
} else {
Message(PARSE_STDIN,"Normal order\n");
Reverse(false);
}
break;
case 'v': /* verbatim mode */
if (strcmp(p, "ersion")==0) {
if (strcmp(basename(programname),PACKAGE_NAME)!=0)
printf("%s (%s) %s\n",basename(programname),
PACKAGE_NAME,PACKAGE_VERSION);
else
puts(PACKAGE_STRING);
#ifdef HAVE_LIBKPATHSEA
puts (KPSEVERSION);
#endif
#ifdef HAVE_FT2
printf("Compiled with Freetype %d.%d.%d\n",
FREETYPE_MAJOR, FREETYPE_MINOR, FREETYPE_PATCH);
# ifdef HAVE_FT_LIBRARY_VERSION
if (FT_Init_FreeType( &libfreetype ))
Warning("the Freetype library seems unusable");
else {
FT_Int amajor, aminor, apatch;
FT_Library_Version( libfreetype, &amajor, &aminor, &apatch );
printf("Using libft %d.%d.%d\n",amajor, aminor, apatch);
FT_Done_FreeType(libfreetype);
}
# endif
#endif
puts ("Copyright (C) 2002-2015 Jan-Ake Larsson.\n\
There is NO warranty. You may redistribute this software\n\
under the terms of the GNU Lesser General Public License\n\
version 3, see the COPYING file in the dvipng distribution\n\
or <http://www.gnu.org/licenses/>.");
exit (EXIT_SUCCESS);
}
if (*p != '0')
option_flags |= BE_NONQUIET | BE_VERBOSE;
else
option_flags &= ~BE_VERBOSE;
break;
case 'D' :
if (*p == 0 && argv[i+1])
p = argv[++i] ;
number = atoi(p);
if (number < 10 || number > 10000)
Warning("Bad resolution (-D) parameter, ignored") ;
else {
dpi=number;
Message(PARSE_STDIN,"Dpi: %d\n",dpi);
}
break;
case 'Q': /* quality (= shrinkfactor) */
if (*p == 0 && argv[i+1])
p = argv[++i];
if (*p>='0'&&*p<='9') {
shrinkfactor = atoi(p);
Message(PARSE_STDIN,"Quality: %d\n",shrinkfactor);
} else {
Warning("Non-numeric quality (-Q) value, ignored");
}
break;
case 'w':
if (strncmp(p,"idth",4) == 0 ) { /* Width reporting */
if (p[4] != '0') {
option_flags |= REPORT_WIDTH;
Message(PARSE_STDIN,"Width reporting on\n",p);
} else {
option_flags &= ~REPORT_WIDTH;
Message(PARSE_STDIN,"Width reporting off\n");
}
break;
}
goto DEFAULT;
#ifdef HAVE_GDIMAGEPNGEX
case 'z':
if (*p == 0 && argv[i+1])
p = argv[++i];
number = atoi(p);
if (number<1 || number>9)
Warning("Bad compression (-z) value, ignored");
else {
compression=number;
Message(PARSE_STDIN,"Compression: %d\n",shrinkfactor);
}
break;
#endif
case '\0':
option_flags |= PARSE_STDIN;
break;
DEFAULT: default:
Warning("%s is not a valid option", argv[i]);
}
} else {
dviname=argv[i];
}
}
if (dviname != NULL) {
if (dvi != NULL && dvi->filep != NULL)
DVIClose(dvi);
dvi=DVIOpen(dviname,outname);
}
if (dvi==NULL) {
fprintf(stdout,"\nUsage: %s [OPTION]... FILENAME[.dvi]\n", programname);
fprintf(stdout,"Options are chosen to be similar to dvips' options where possible:\n");
#ifdef DEBUG
fprintf(stdout," -d # Debug (# is the debug bitmap, 1 if not given)\n");
#endif
fprintf(stdout," -D # Output resolution\n");
fprintf(stdout," -l # Last page to be output\n");
fprintf(stdout," -o f Output file, '%%d' is pagenumber\n");
fprintf(stdout," -O c Image offset\n");
fprintf(stdout," -p # First page to be output\n");
fprintf(stdout," -pp #,#.. Page list to be output\n");
fprintf(stdout," -q* Quiet operation\n");
fprintf(stdout," -T c Image size (also accepts '-T bbox' and '-T tight')\n");
fprintf(stdout," -v* Verbose operation\n");
fprintf(stdout," - Interactive query of options\n");
fprintf(stdout,"\nThese do not correspond to dvips options:\n");
fprintf(stdout," -bd # Transparent border width in dots\n");
fprintf(stdout," -bd s Transparent border fallback color (TeX-style color)\n");
fprintf(stdout," -bg s Background color (TeX-style color or 'Transparent')\n");
fprintf(stdout," --depth* Output the image depth on stdout\n");
fprintf(stdout," --dvinum* Use TeX page numbers in output filenames\n");
fprintf(stdout," -fg s Foreground color (TeX-style color)\n");
fprintf(stdout," --follow* Wait for data at end-of-file\n");
#ifdef HAVE_FT2
fprintf(stdout," --freetype* FreeType font rendering (preferred, default on)\n");
#endif
fprintf(stdout," --gamma # Control color interpolation\n");
#ifdef HAVE_GDIMAGEGIF
fprintf(stdout," --gif Output GIF images (dvigif default)\n");
#endif
fprintf(stdout," --height* Output the image height on stdout\n");
fprintf(stdout," --nogs* Don't use ghostscript for PostScript specials\n");
fprintf(stdout," --nogssafer* Don't use -dSAFER in ghostscript calls\n");
fprintf(stdout," --norawps* Don't convert raw PostScript specials\n");
#ifdef HAVE_GDIMAGECREATETRUECOLOR
fprintf(stdout," --palette* Force palette output\n");
#endif
fprintf(stdout," --picky When a warning occurs, don't output image\n");
#ifdef HAVE_GDIMAGEGIF
fprintf(stdout," --png Output PNG images (dvipng default)\n");
#endif
fprintf(stdout," --strict When a warning occurs, exit\n");
#ifdef HAVE_GDIMAGECREATETRUECOLOR
fprintf(stdout," --truecolor* Truecolor output\n");
#endif
fprintf(stdout," -Q # Quality (PK subsampling)\n");
fprintf(stdout," --width* Output the image width on stdout\n");
#ifdef HAVE_GDIMAGEPNGEX
fprintf(stdout," -z # PNG compression level\n");
#endif
fprintf(stdout,"\n # = number f = file s = string * = suffix, '0' to turn off\n");
fprintf(stdout," c = comma-separated dimension pair (e.g., 3.2in,-32.1cm)\n\n");
/*#ifdef HAVE_LIBKPATHSEA
{
extern DllImport char *kpse_bug_address;
putc ('\n', stdout);
fputs (kpse_bug_address, stdout);
}
#endif*/
if ((option_flags & PARSE_STDIN) == 0) {
exit(EXIT_SUCCESS);
}
}
if ((option_flags & PARSE_STDIN) == 0 && (!ppused))
ParsePages("-");
return((option_flags & PARSE_STDIN) != 0);
}
void DecodeString(char *string)
{
#define PARSEARGS 10
char *strv[PARSEARGS];
int strc=1;
strv[0]=NULL; /* No program name */
while (*string==' ' || *string=='\t' || *string=='\r' || *string=='\n')
string++;
while (*string!='\0') {
strv[strc++]=string;
if (*string!='\'') {
/* Normal split at whitespace */
while (*string!=' ' && *string!='\t' \
&& *string!='\n' && *string!='\r' && *string!='\0')
string++;
} else {
/* String delimiter found , so search for next */
strv[strc-1]=++string;
while (*string!='\'' && *string!='\0')
string++;
}
if (*string!='\0')
*string++='\0';
while (*string==' ' || *string=='\t' || *string=='\r' || *string=='\n')
string++;
}
if (strc>1) /* Nonempty */
(void) DecodeArgs(strc,strv);
}
uint32_t UNumRead(unsigned char* current, register int n)
{
uint32_t x = (unsigned char) *(current)++; /* number being constructed */
while(--n)
x = (x << 8) | *(current)++;
return(x);
}
int32_t SNumRead(unsigned char* current, register int n)
{
int32_t x = (signed char) *(current)++; /* number being constructed */
while(--n)
x = (x << 8) | *(current)++;
return(x);
}
/**********************************************************************/
/****************************** Fatal *******************************/
/**********************************************************************/
void Fatal (const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
fflush(stdout);
fprintf(stderr, "\n");
fprintf(stderr, "%s: Fatal error, ", programname);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n\n");
va_end(args);
ClearFonts();
#ifdef HAVE_FT2
if (libfreetype)
(void) FT_Done_FreeType(libfreetype); /* at this point, ignore error */
#endif
exit(EXIT_FATAL);
}
/*-->Warning*/
/**********************************************************************/
/***************************** Warning ******************************/
/**********************************************************************/
void Warning(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
if ( option_flags & BE_NONQUIET ) {
fflush(stdout);
fprintf(stderr, "%s warning: ", programname);
vfprintf(stderr, fmt, args);
fprintf(stderr, " ");
}
va_end(args);
}
/*-->Message*/
/**********************************************************************/
/***************************** Message ******************************/
/**********************************************************************/
void Message(int activeflags, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
if ( option_flags & activeflags ) {
vfprintf(stdout, fmt, args);
}
va_end(args);
}
bool MmapFile (char *filename,struct filemmap *fmmap)
{
#ifndef WIN32
struct stat stat;
#endif
DEBUG_PRINT(DEBUG_DVI,("\n OPEN FILE:\t'%s'", filename));
fmmap->data=NULL;
#ifndef WIN32
if ((fmmap->fd = open(filename,O_RDONLY)) == -1) {
Warning("cannot open file <%s>", filename);
return(true);
}
fstat(fmmap->fd,&stat);
fmmap->size=stat.st_size;
# ifdef HAVE_MMAP
fmmap->data = mmap(NULL,fmmap->size, PROT_READ, MAP_SHARED,fmmap->fd,0);
if (fmmap->data == (char*)-1) {
Warning("cannot mmap file <%s>",filename);
fmmap->data=NULL;
close(fmmap->fd);
return(true);
}
# else /* HAVE_MMAP */
if ((fmmap->data = malloc(fmmap->size+1)) == NULL) {
Warning("cannot malloc space for <%s>",filename);
close(fmmap->fd);
return(true);
}
if (read(fmmap->fd,fmmap->data,fmmap->size)<fmmap->size) {
Warning("too little data in <%s>",filename);
free(fmmap->data);
fmmap->data=NULL;
close(fmmap->fd);
return(true);
}
close(fmmap->fd);
# endif /* HAVE_MMAP */
#else /* WIN32 */
fmmap->hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, 0,
OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, 0);
if (fmmap->hFile == INVALID_HANDLE_VALUE) {
Warning("cannot open file <%s>", filename);
return(true);
}
fmmap->size = GetFileSize(fmmap->hFile, 0);
fmmap->hMap = CreateFileMapping(fmmap->hFile, 0, PAGE_READONLY, 0, 0, 0);
if (fmmap->hMap == 0) {
CloseHandle (fmmap->hFile);
Warning("cannot CreateFileMapping() file <%s>", filename);
return(true);
}
fmmap->data = MapViewOfFile(fmmap->hMap, FILE_MAP_READ, 0, 0, 0);
if (fmmap->data == NULL) {
Warning("cannot MapViewOfFile() file <%s>", filename);
CloseHandle (fmmap->hMap);
CloseHandle (fmmap->hFile);
return(true);
}
#endif /* WIN32 */
return(false);
}
void UnMmapFile(struct filemmap* fmmap)
{
if (fmmap->data!=NULL) {
#ifndef WIN32
# ifdef HAVE_MMAP
if (munmap(fmmap->data,fmmap->size))
Warning("cannot munmap file at 0x%X",fmmap->data);
if (close(fmmap->fd))
Warning("cannot close file descriptor %d",fmmap->fd);
# else /* HAVE_MMAP */
free(fmmap->data);
# endif /* HAVE_MMAP */
#else /* WIN32 */
UnmapViewOfFile (fmmap->data);
CloseHandle (fmmap->hMap);
CloseHandle (fmmap->hFile);
#endif /* WIN32 */
}
fmmap->data=NULL;
}
|