1 //========================================================================
5 // Copyright 1996-2003 Glyph & Cog, LLC
7 //========================================================================
12 #include "parseargs.h"
15 #include "GlobalParams.h"
20 //------------------------------------------------------------------------
21 // command line options
22 //------------------------------------------------------------------------
24 static char t1libControlStr[16] = "";
25 static char freetypeControlStr[16] = "";
26 static char psFileArg[256];
27 static char paperSize[15] = "";
28 static int paperWidth = 0;
29 static int paperHeight = 0;
30 static GBool level1 = gFalse;
31 static char textEncName[128] = "";
32 static char textEOL[16] = "";
33 static char ownerPassword[33] = "";
34 static char userPassword[33] = "";
35 static GBool fullScreen = gFalse;
36 static char remoteName[100] = "xpdf_";
37 static GBool doRemoteReload = gFalse;
38 static GBool doRemoteRaise = gFalse;
39 static GBool doRemoteQuit = gFalse;
40 static GBool printCommands = gFalse;
41 static GBool quiet = gFalse;
42 static char cfgFileName[256] = "";
43 static GBool printVersion = gFalse;
44 static GBool printHelp = gFalse;
46 static ArgDesc argDesc[] = {
47 {"-g", argStringDummy, NULL, 0,
48 "initial window geometry"},
49 {"-geometry", argStringDummy, NULL, 0,
50 "initial window geometry"},
51 {"-title", argStringDummy, NULL, 0,
53 {"-cmap", argFlagDummy, NULL, 0,
54 "install a private colormap"},
55 {"-rgb", argIntDummy, NULL, 0,
56 "biggest RGB cube to allocate (default is 5)"},
57 {"-rv", argFlagDummy, NULL, 0,
59 {"-papercolor", argStringDummy, NULL, 0,
60 "color of paper background"},
61 {"-z", argStringDummy, NULL, 0,
62 "initial zoom level (-5..5, page, width)"},
64 {"-t1lib", argString, t1libControlStr, sizeof(t1libControlStr),
65 "t1lib font rasterizer control: none, plain, low, high"},
67 #if HAVE_FREETYPE_FREETYPE_H | HAVE_FREETYPE_H
68 {"-freetype", argString, freetypeControlStr, sizeof(freetypeControlStr),
69 "FreeType font rasterizer control: none, plain, low, high"},
71 {"-ps", argString, psFileArg, sizeof(psFileArg),
72 "default PostScript file name or command"},
73 {"-paper", argString, paperSize, sizeof(paperSize),
74 "paper size (letter, legal, A4, A3, match)"},
75 {"-paperw", argInt, &paperWidth, 0,
76 "paper width, in points"},
77 {"-paperh", argInt, &paperHeight, 0,
78 "paper height, in points"},
79 {"-level1", argFlag, &level1, 0,
80 "generate Level 1 PostScript"},
81 {"-enc", argString, textEncName, sizeof(textEncName),
82 "output text encoding name"},
83 {"-eol", argString, textEOL, sizeof(textEOL),
84 "output end-of-line convention (unix, dos, or mac)"},
85 {"-opw", argString, ownerPassword, sizeof(ownerPassword),
86 "owner password (for encrypted files)"},
87 {"-upw", argString, userPassword, sizeof(userPassword),
88 "user password (for encrypted files)"},
89 {"-fullscreen", argFlag, &fullScreen, 0,
90 "run in full-screen (presentation) mode"},
91 {"-remote", argString, remoteName + 5, sizeof(remoteName) - 5,
92 "start/contact xpdf remote server with specified name"},
93 {"-reload", argFlag, &doRemoteReload, 0,
94 "reload xpdf remove server window (with -remote only)"},
95 {"-raise", argFlag, &doRemoteRaise, 0,
96 "raise xpdf remote server window (with -remote only)"},
97 {"-quit", argFlag, &doRemoteQuit, 0,
98 "kill xpdf remote server (with -remote only)"},
99 {"-cmd", argFlag, &printCommands, 0,
100 "print commands as they're executed"},
101 {"-q", argFlag, &quiet, 0,
102 "don't print any messages or errors"},
103 {"-cfg", argString, cfgFileName, sizeof(cfgFileName),
104 "configuration file to use in place of .xpdfrc"},
105 {"-v", argFlag, &printVersion, 0,
106 "print copyright and version info"},
107 {"-h", argFlag, &printHelp, 0,
108 "print usage information"},
109 {"-help", argFlag, &printHelp, 0,
110 "print usage information"},
111 {"--help", argFlag, &printHelp, 0,
112 "print usage information"},
113 {"-?", argFlag, &printHelp, 0,
114 "print usage information"},
118 //------------------------------------------------------------------------
120 int main(int argc, char *argv[]) {
125 GString *userPasswordStr, *ownerPasswordStr;
130 userPasswordStr = ownerPasswordStr = NULL;
133 ok = parseArgs(argDesc, &argc, argv);
136 globalParams = new GlobalParams(cfgFileName);
138 globalParams->setPSFile(psFileArg);
141 if (!globalParams->setPSPaperSize(paperSize)) {
142 fprintf(stderr, "Invalid paper size\n");
146 globalParams->setPSPaperWidth(paperWidth);
149 globalParams->setPSPaperHeight(paperHeight);
153 globalParams->setPSLevel(psLevel1);
155 if (textEncName[0]) {
156 globalParams->setTextEncoding(textEncName);
159 if (!globalParams->setTextEOL(textEOL)) {
160 fprintf(stderr, "Bad '-eol' value on command line\n");
163 if (t1libControlStr[0]) {
164 if (!globalParams->setT1libControl(t1libControlStr)) {
165 fprintf(stderr, "Bad '-t1lib' value on command line\n");
168 if (freetypeControlStr[0]) {
169 if (!globalParams->setFreeTypeControl(freetypeControlStr)) {
170 fprintf(stderr, "Bad '-freetype' value on command line\n");
174 globalParams->setPrintCommands(printCommands);
177 globalParams->setErrQuiet(quiet);
180 // create the XPDFApp object
181 app = new XPDFApp(&argc, argv);
183 // the initialZoom parameter can be set in either the config file or
184 // as an X resource (or command line arg)
185 if (app->getInitialZoom()) {
186 globalParams->setInitialZoom(app->getInitialZoom()->getCString());
189 // check command line
190 ok = ok && argc >= 1 && argc <= 3;
191 if (doRemoteReload) {
192 ok = ok && remoteName[5] && !doRemoteQuit && argc == 1;
195 ok = ok && remoteName[5] && !doRemoteQuit;
198 ok = ok && remoteName[5] && argc == 1;
200 if (!ok || printVersion || printHelp) {
201 fprintf(stderr, "xpdf version %s\n", xpdfVersion);
202 fprintf(stderr, "%s\n", xpdfCopyright);
204 printUsage("xpdf", "[<PDF-file> [<page> | +<dest>]]", argDesc);
210 fileName = new GString(argv[1]);
217 if (argv[2][0] == '+') {
218 destName = new GString(&argv[2][1]);
224 // handle remote server stuff
226 app->setRemoteName(remoteName);
227 if (app->remoteServerRunning()) {
230 app->remoteOpenAtDest(fileName, destName, doRemoteRaise);
232 app->remoteOpen(fileName, pg, doRemoteRaise);
234 } else if (doRemoteReload) {
235 app->remoteReload(doRemoteRaise);
236 } else if (doRemoteRaise) {
238 } else if (doRemoteQuit) {
249 app->setFullScreen(fullScreen);
251 // check for password string(s)
252 ownerPasswordStr = ownerPassword[0] ? new GString(ownerPassword)
254 userPasswordStr = userPassword[0] ? new GString(userPassword)
257 // open the file and run the main loop
259 if (!app->openAtDest(fileName, destName,
260 ownerPasswordStr, userPasswordStr)) {
265 if (!app->open(fileName, pg, ownerPasswordStr, userPasswordStr)) {
276 if (userPasswordStr) {
277 delete userPasswordStr;
279 if (ownerPasswordStr) {
280 delete ownerPasswordStr;
292 // check for memory leaks
293 Object::memCheck(stderr);