Imported from antiword-0.30.tar.gz.
[antiword.git] / main_u.c
blob6f40ef7e89940b3f883efa12d1a13eff805c8d89
1 /*
2 * main_u.c
4 * Released under GPL
6 * Copyright (C) 1998,1999 A.J. van Os
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * Description:
23 * The main program of 'antiword' (Unix version)
26 #include <stdio.h>
27 #include <string.h>
28 #include "version.h"
29 #include "antiword.h"
31 /* The name of this program */
32 static char *szTask = NULL;
35 static void
36 vUsage(void)
38 fprintf(stderr, "\tName: %s\n", szTask);
39 fprintf(stderr, "\tPurpose: "PURPOSESTRING"\n");
40 fprintf(stderr, "\tAuthor: "AUTHORSTRING"\n");
41 fprintf(stderr, "\tVersion: "VERSIONSTRING"\n");
42 fprintf(stderr, "\tStatus: "STATUSSTRING"\n");
43 fprintf(stderr,
44 "\tUsage: %s [switches] wordfile1 [wordfile2 ...]\n", szTask);
45 fprintf(stderr, "\tSwitches: [-t|-p papersize][-w #][-c|-g][-s]\n");
46 fprintf(stderr, "\t\t-t ASCII text output (default)\n");
47 fprintf(stderr, "\t\t-p <papersize> PostScript output\n");
48 fprintf(stderr, "\t\t-w <width> in characters of ASCII text output\n");
49 fprintf(stderr, "\t\t-g grayscale (PostScript only)\n");
50 fprintf(stderr, "\t\t-c colour (default, PostScript only)\n");
51 fprintf(stderr, "\t\t-s Show hidden (by Word) text\n");
52 } /* end of vUsage */
54 static void
55 vProcessFile(const char *szFilename, BOOL bLastFile)
57 diagram_type *pDiag;
59 fail(szFilename == NULL || szFilename[0] == '\0');
61 DBG_MSG(szFilename);
63 if (!bIsSupportedWordFile(szFilename)) {
64 if (bIsRtfFile(szFilename)) {
65 werr(0, "%s is not a Word Document."
66 " It is probably a Rich Text Format file",
67 szFilename);
68 } else if (bIsWord245File(szFilename)) {
69 werr(0, "%s is not in a supported Word format."
70 " It is probably from 'Word2, 4 or 5'",
71 szFilename);
72 } else {
73 werr(0, "%s is not a Word Document.", szFilename);
75 return;
77 pDiag = pCreateDiagram(szTask, szFilename);
78 if (pDiag != NULL) {
79 vWord2Text(pDiag, szFilename);
80 vDestroyDiagram(pDiag, bLastFile);
82 } /* end of vProcessFile */
84 int
85 main(int argc, char **argv)
87 options_type tOptions;
88 char *szWordfile;
89 int iFirst, iIndex;
90 BOOL bUsage, bMultiple, bUsePlainText;
92 if (argc <= 0) {
93 return 1;
96 szTask = strrchr(argv[0], '/');
97 if (szTask == NULL) {
98 szTask = argv[0];
99 } else {
100 szTask++;
103 if (argc <= 1) {
104 iFirst = 1;
105 bUsage = TRUE;
106 } else {
107 iFirst = iReadOptions(argc, argv);
108 bUsage = iFirst <= 0;
110 if (bUsage) {
111 vUsage();
112 return iFirst < 0 ? 1 : 0;
115 vGetOptions(&tOptions);
117 bMultiple = argc - iFirst > 1;
118 bUsePlainText = !tOptions.bUseOutlineFonts;
120 for (iIndex = iFirst; iIndex < argc; iIndex++) {
121 if (bMultiple && bUsePlainText) {
122 szWordfile = strrchr(argv[iIndex], '/');
123 if (szWordfile == NULL) {
124 szWordfile = argv[iIndex];
125 } else {
126 szWordfile++;
128 fprintf(stdout, "::::::::::::::\n");
129 fprintf(stdout, "%s\n", szWordfile);
130 fprintf(stdout, "::::::::::::::\n");
132 vProcessFile(argv[iIndex], iIndex + 1 >= argc);
134 return 0;
135 } /* end of main */