diff options
author | Adrian Johnson <ajohnson@redneon.com> | 2011-10-17 20:33:03 +1030 |
---|---|---|
committer | Adrian Johnson <ajohnson@redneon.com> | 2011-10-17 21:14:55 +1030 |
commit | 40b56994dda79653c902977423f349efa55cf21e (patch) | |
tree | 0f8fa6d0c1eb683b87cda3e4f0f681c080a54e9e /utils | |
parent | 4bb34757dbbff780baba053371274c05b29771e1 (diff) |
utils: Add GooString arg to parseargs and use for paths in pdftocairo
<sys/param.h> and MAXPATHLEN is not available on windows. Avoid the
need to know the max path length by using GooString for the path.
Diffstat (limited to 'utils')
-rw-r--r-- | utils/parseargs.cc | 12 | ||||
-rw-r--r-- | utils/parseargs.h | 2 | ||||
-rw-r--r-- | utils/pdftocairo.cc | 17 |
3 files changed, 22 insertions, 9 deletions
diff --git a/utils/parseargs.cc b/utils/parseargs.cc index c5f3007e..ef971a5c 100644 --- a/utils/parseargs.cc +++ b/utils/parseargs.cc @@ -30,6 +30,7 @@ #include "parseargs.h" #include "goo/gstrtod.h" +#include "goo/GooString.h" static const ArgDesc *findArg(const ArgDesc *args, char *arg); static GBool grabArg(const ArgDesc *arg, int i, int *argc, char *argv[]); @@ -87,6 +88,7 @@ void printUsage(char *program, char *otherArgs, const ArgDesc *args) { break; case argString: case argStringDummy: + case argGooString: typ = " <string>"; break; case argFlag: @@ -152,6 +154,16 @@ static GBool grabArg(const ArgDesc *arg, int i, int *argc, char *argv[]) { n = 1; } break; + case argGooString: + if (i + 1 < *argc) { + ((GooString*)arg->val)->Set(argv[i+1], arg->size - 1); + ((GooString*)arg->val)->append('\0'); + n = 2; + } else { + ok = gFalse; + n = 1; + } + break; default: fprintf(stderr, "Internal error in arg table\n"); n = 1; diff --git a/utils/parseargs.h b/utils/parseargs.h index 410dcc46..a2ec1d76 100644 --- a/utils/parseargs.h +++ b/utils/parseargs.h @@ -41,6 +41,8 @@ typedef enum { /* [val: double *] */ argString, /* string arg */ /* [val: char *] */ + argGooString, /* string arg */ + /* [val: GooString *] */ /* dummy entries -- these show up in the usage listing only; */ /* useful for X args, for example */ argFlagDummy, diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc index fb3ca307..e458ee5c 100644 --- a/utils/pdftocairo.cc +++ b/utils/pdftocairo.cc @@ -32,7 +32,6 @@ #include "config.h" #include <poppler-config.h> -#include <sys/param.h> // for MAXPATHLEN #include <stdio.h> #include <math.h> #include <string.h> @@ -91,7 +90,7 @@ static GBool useCropBox = gFalse; static GBool mono = gFalse; static GBool gray = gFalse; static GBool transp = gFalse; -static char icc[MAXPATHLEN] = ""; +static GooString icc; static GBool level2 = gFalse; static GBool level3 = gFalse; @@ -179,7 +178,7 @@ static const ArgDesc argDesc[] = { {"-transp", argFlag, &transp, 0, "use a transparent background instead of white (PNG)"}, #if USE_CMS - {"-icc", argString, &icc, sizeof(icc), + {"-icc", argGooString, &icc, 0, "ICC color profile to use"}, #endif @@ -756,7 +755,7 @@ int main(int argc, char *argv[]) { checkInvalidPrintOption(mono, "-mono"); checkInvalidPrintOption(gray, "-gray"); checkInvalidPrintOption(transp, "-transp"); - checkInvalidPrintOption(icc[0], "-icc"); + checkInvalidPrintOption(icc.getCString()[0], "-icc"); checkInvalidPrintOption(singleFile, "-singlefile"); } else { checkInvalidImageOption(level2, "-level2"); @@ -772,7 +771,7 @@ int main(int argc, char *argv[]) { checkInvalidImageOption(duplex, "-duplex"); } - if (icc[0] && !png) { + if (icc.getCString()[0] && !png) { fprintf(stderr, "Error: -icc may only be used with png output.\n"); exit(99); } @@ -842,10 +841,10 @@ int main(int argc, char *argv[]) { #if USE_CMS icc_data = NULL; - if (icc[0]) { - FILE *file = fopen(icc, "rb"); + if (icc.getCString()[0]) { + FILE *file = fopen(icc.getCString(), "rb"); if (!file) { - fprintf(stderr, "Error: unable to open icc profile %s\n", icc); + fprintf(stderr, "Error: unable to open icc profile %s\n", icc.getCString()); exit(4); } fseek (file, 0, SEEK_END); @@ -853,7 +852,7 @@ int main(int argc, char *argv[]) { fseek (file, 0, SEEK_SET); icc_data = (unsigned char*)gmalloc(icc_data_size); if (fread(icc_data, icc_data_size, 1, file) != 1) { - fprintf(stderr, "Error: unable to read icc profile %s\n", icc); + fprintf(stderr, "Error: unable to read icc profile %s\n", icc.getCString()); exit(4); } fclose(file); |