#define USAGE "Usage: %s [OPTION]... PSFILE [PNGFILE]\n" \ "Converts a PostScript file to PNG using GhostScript (gs).\n" \ "\n" \ "\n" \ " -h, --help Prints this usage information\n" \ " -H, --description Prints a description of the program\n" \ " -d, -D, -s, -S Defines names or strings within gs\n" \ " -r RES Specifies image resolution\n" \ " -g SIZE Specifies image size\n" \ " -I DIR Specifies search directories\n" \ "\n" \ "This program executes %s with the options -dBATCH,\n" \ "-dNOPAUSE, -dEPSCrop, -sDEVICE=pngalpha, and -sOutputFile=PNGFILE,\n" \ "with any other options passed directly on to GhostScript. Of\n" \ "particular note: the default resolution is 72 pixels per \"inch\";\n" \ "this can be changed with the -rRES or -rXRESxYRES option.\n" \ "\n" #include #include #include #include #include #define CMD "/usr/bin/gs" /* GhostScript command (full path) */ #define ARGV0 "gs" /* GhostScript command (name only) */ #define ARGV1 "-dBATCH" /* GhostScript argument */ #define ARGV2 "-dNOPAUSE" /* GhostScript argument */ #define ARGV3 "-dEPSCrop" /* GhostScript argument */ #define ARGV4 "-sDEVICE=pngalpha" /* GhostScript argument */ #define ARGV5 "-sOutputFile=" /* GhostScript destination stub */ int main( int argc, char **argv ) { int i; /* index over argument list */ char **argv_new; /* argv array for new argument list */ /* Check input arguments. */ if ( argc < 3 ) { fprintf( stderr, USAGE, argv[0], CMD ); return -1; } /* Assign new argv array. */ if ( !( argv_new = (char **)malloc( ( argc + 5 )*sizeof(char *) ) ) || !( argv_new[5] = (char *) malloc( strlen( argv[argc-1] ) + strlen( ARGV5 ) + 1 ) ) ) { fprintf( stderr, "%s: memory error\n", argv[0] ); return -2; } argv_new[0] = ARGV0; argv_new[1] = ARGV1; argv_new[2] = ARGV2; argv_new[3] = ARGV3; argv_new[4] = ARGV4; sprintf( argv_new[5], "%s%s", ARGV5, argv[argc-1] ); for ( i = 1; i < argc - 2; i++ ) argv_new[i+5] = argv[i]; argv_new[argc+3] = argv[argc-2]; argv_new[argc+4] = NULL; /* Execute GhostScript. */ execvp( CMD, argv_new ); fprintf( stderr, "%s: execvp() failed with errno=%i\n", argv[0], errno ); return -3; }