Fix for a crash which happened when a document couldn't be opened.
[AROS-Contrib.git] / arospdf / xpdf / arospdf.cc
blob414b8f57fc1c472696ff898f9db117ad4247681a
1 //========================================================================
2 //
3 // AROSpdf.cc
4 //
5 // Copyright 2003 Glyph & Cog, LLC
6 // Copyright 2005 Vijay Kumar B. <vijaykumar@bravegnu.org>
7 //
8 //========================================================================
10 #include <aconf.h>
11 #include <stdio.h>
13 #include "parseargs.h"
14 #include "gmem.h"
15 #include "GString.h"
16 #include "GlobalParams.h"
17 #include "Object.h"
18 #include "Splash.h"
19 #include "AROSPDFApp.h"
20 #include "config.h"
21 #define ARG_TEMPLATE "FILE"
24 static char enableT1libStr[16] = "";
25 static char enableFreeTypeStr[16] = "";
26 static char antialiasStr[16] = "";
27 static char ownerPassword[33] = "";
28 static char userPassword[33] = "";
29 static GBool quiet = gFalse;
30 static char cfgFileName[256] = "";
31 static GBool printVersion = gFalse;
32 static GBool printHelp = gFalse;
34 static ArgDesc argDesc[] = {
35 #if HAVE_T1LIB_H
36 {"-t1lib", argString, enableT1libStr, sizeof(enableT1libStr),
37 "enable t1lib font rasterizer: yes, no"},
38 #endif
39 #if HAVE_FREETYPE_FREETYPE_H | HAVE_FREETYPE_H
40 {"-freetype", argString, enableFreeTypeStr, sizeof(enableFreeTypeStr),
41 "enable FreeType font rasterizer: yes, no"},
42 #endif
43 {"-aa", argString, antialiasStr, sizeof(antialiasStr),
44 "enable font anti-aliasing: yes, no"},
45 {"-opw", argString, ownerPassword, sizeof(ownerPassword),
46 "owner password (for encrypted files)"},
47 {"-upw", argString, userPassword, sizeof(userPassword),
48 "user password (for encrypted files)"},
49 {"-q", argFlag, &quiet, 0,
50 "don't print any messages or errors"},
51 {"-cfg", argString, cfgFileName, sizeof(cfgFileName),
52 "configuration file to use in place of .xpdfrc"},
53 {"-v", argFlag, &printVersion, 0,
54 "print copyright and version info"},
55 {"-h", argFlag, &printHelp, 0,
56 "print usage information"},
57 {"-help", argFlag, &printHelp, 0,
58 "print usage information"},
59 {"--help", argFlag, &printHelp, 0,
60 "print usage information"},
61 {"-?", argFlag, &printHelp, 0,
62 "print usage information"},
63 {NULL}
66 int main(int argc, char *argv[]) {
67 AROSPDFApp *app;
68 GString *fileName;
69 GString *ownerPW, *userPW;
70 GBool ok;
71 BPTR cd=NULL;
72 int exitCode;
74 exitCode = 99;
75 fileName=NULL;
76 if (argc>1) {
77 // parse args
78 ok = parseArgs(argDesc, &argc, argv);
79 if (!ok || printVersion || printHelp) {
80 fprintf(stderr, "AROSpdf version %s\n", xpdfVersion);
81 fprintf(stderr, "%s\n", xpdfCopyright);
82 if (!printVersion) {
83 printUsage("AROSpdf", "<PDF-file>", argDesc);
85 goto err0;
87 if (argc==2)
88 fileName = new GString(argv[1]);
89 else
90 fileName=NULL;
93 if (argc==0) {
94 fileName=NULL;
95 struct WBStartup *startup = NULL;
96 startup = (struct WBStartup *) argv;
97 if (startup != NULL) {
98 if (startup->sm_NumArgs >1)
100 /* FIXME: all arguments but the first are ignored */
101 cd = CurrentDir(startup->sm_ArgList[1].wa_Lock);
102 fileName = new GString(startup->sm_ArgList[1].wa_Name);
108 // read config file
109 globalParams = new GlobalParams(cfgFileName);
110 globalParams->setupBaseFonts(NULL);
111 if (enableT1libStr[0]) {
112 if (!globalParams->setEnableT1lib(enableT1libStr)) {
113 fprintf(stderr, "Bad '-t1lib' value on command line\n");
116 if (enableFreeTypeStr[0]) {
117 if (!globalParams->setEnableFreeType(enableFreeTypeStr)) {
118 fprintf(stderr, "Bad '-freetype' value on command line\n");
121 if (antialiasStr[0]) {
122 if (!globalParams->setAntialias(antialiasStr)) {
123 fprintf(stderr, "Bad '-aa' value on command line\n");
126 if (quiet) {
127 globalParams->setErrQuiet(quiet);
130 // open PDF file
131 if (ownerPassword[0]) {
132 ownerPW = new GString(ownerPassword);
133 } else {
134 ownerPW = NULL;
136 if (userPassword[0]) {
137 userPW = new GString(userPassword);
138 } else {
139 userPW = NULL;
142 if (fileName != NULL)
143 app = new AROSPDFApp(fileName, ownerPW, userPW);
144 else
145 app = new AROSPDFApp();
146 exitCode = app->run();
147 app->quit();
148 delete app;
149 delete globalParams;
150 err0:
151 // check for memory leaks
152 xObject::memCheck(stderr);
153 gMemReport(stderr);
154 if (cd != NULL)
155 CurrentDir(cd);
156 return exitCode;