Commit 40b56994 authored by Adrian Johnson's avatar Adrian Johnson
Browse files

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.
parent 4bb34757
......@@ -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;
......
......@@ -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,
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment