1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
/*=============================================================================
GNU UnRTF, a command-line program to convert RTF documents to other formats.
Copyright (C) 2000,2001 Zachary Thayer Smith
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The author is reachable by electronic mail at tuorfa@yahoo.com.
=============================================================================*/
/*----------------------------------------------------------------------
* Module name: main.c
* Author name: Zach Smith
* Create date: 01 Sep 00
* Purpose: main() routine with file open/close.
*----------------------------------------------------------------------
* Changes:
* 14 Oct 00, tuorfa@yahoo.com: added -nopict option
* 15 Oct 00, tuorfa@yahoo.com: added verify_file_type()
* 08 Apr 01, tuorfa@yahoo.com: more GNU-like switches implemented
* 24 Jul 01, tuorfa@yahoo.com: removed verify_file_type()
* 03 Aug 01, tuorfa@yahoo.com: added --inline switch
* 08 Sep 01, tuorfa@yahoo.com: added use of PROGRAM_NAME
* 19 Sep 01, tuorfa@yahoo.com: addition of output personalities
* 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks
* 23 Sep 01, tuorfa@yahoo.com: added wpml switch
*--------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include "defs.h"
#include "error.h"
#include "word.h"
#include "convert.h"
#include "parse.h"
#include "hash.h"
#include "malloc.h"
#include "output.h"
#include "html.h"
#include "text.h"
#include "vt.h"
#include "ps.h"
#include "latex.h"
#include "wpml.h"
int nopict_mode; /* TRUE => do not write \pict's to files */
int dump_mode; /* TRUE => output a dump of the word tree */
int debug_mode; /* TRUE => output comments within HTML */
int lineno; /* used for error reporting */
int simple_mode; /* TRUE => output HTML without SPAN/DIV tags */
int inline_mode; /* TRUE => output HTML without HTML/BODY/HEAD */
OutputPersonality *op;
enum {
OP_HTML, OP_TEXT, OP_LATEX, OP_PS, OP_VT, OP_WPML
};
/*========================================================================
* Name: main
* Purpose: Main control function.
* Args: Args.
* Returns: Exit code.
*=======================================================================*/
int
main (int argc, char **argv)
{
FILE *f;
Word * word;
char *path=NULL;
int i;
int output_format = OP_HTML;
nopict_mode = debug_mode = dump_mode = inline_mode = FALSE;
if (argc<2 || argc>7) usage();
for (i=1; i<argc; i++) {
if (!strcmp("--dump",argv[i])) dump_mode=TRUE;
else if (!strcmp("-d",argv[i])) dump_mode=TRUE;
else if (!strcmp("--debug",argv[i])) debug_mode=TRUE;
else if (!strcmp("--simple",argv[i])) simple_mode=TRUE;
else if (!strcmp("--html",argv[i])) output_format=OP_HTML;
else if (!strcmp("--text",argv[i])) output_format=OP_TEXT;
else if (!strcmp("--vt",argv[i])) output_format=OP_VT;
else if (!strcmp("--ps",argv[i])) output_format=OP_PS;
else if (!strcmp("--latex",argv[i])) output_format=OP_LATEX;
else if (!strcmp("--wpml",argv[i])) output_format=OP_WPML;
else if (!strcmp("-t",argv[i])) {
if ((i+1)<argc && *argv[i+1]!='-') {
i++;
if (!strcmp ("html", argv[i]))
output_format=OP_HTML;
else if (!strcmp ("vt", argv[i]))
output_format=OP_VT;
else if (!strcmp ("text", argv[i]))
output_format=OP_TEXT;
else if (!strcmp ("ps", argv[i]))
output_format=OP_PS;
else if (!strcmp ("latex", argv[i]))
output_format=OP_LATEX;
else if (!strcmp ("wpml", argv[i]))
output_format=OP_WPML;
}
}
else if (!strcmp("--inline",argv[i])) inline_mode=TRUE;
else if (!strcmp("--help",argv[i])) {
usage();
exit (0);
}
else if (!strcmp("--version",argv[i])) {
fprintf (stderr, "%s\n", PROGRAM_VERSION);
exit (0);
}
else if (!strcmp("--nopict",argv[i])) nopict_mode=TRUE;
else if (!strcmp("-n",argv[i])) nopict_mode=TRUE;
else {
if (*argv[i]=='-') usage();
if(path)
usage();
else
path=argv[i];
}
}
if (!path) usage();
switch (output_format) {
case OP_TEXT:
op = text_init();
break;
case OP_VT:
op = vt_init();
break;
case OP_HTML:
op = html_init();
break;
case OP_PS:
op = ps_init();
break;
case OP_LATEX:
op = latex_init();
break;
case OP_WPML:
op = wpml_init();
break;
default:
error_handler ("unknown output format");
}
hash_init();
fprintf (stderr, "This is %s, ", PROGRAM_NAME);
fprintf (stderr, "version %s\n", PROGRAM_VERSION);
fprintf (stderr, "By Zach T. Smith\n");
if (debug_mode) fprintf (stderr, "Debug mode.\n");
if (dump_mode) fprintf (stderr, "Dump mode.\n");
f = fopen (path, "r");
if (!f) {
char path2[200];
strcpy(path2,path); strcat(path2,".rtf");
f = fopen(path2, "r");
if(!f)
error_handler ("cannot open input file");
}
fprintf(stderr,"Processing %s...\n", path);
lineno=0;
word = word_read (f);
if (dump_mode) {
word_dump (word);
printf ("\n");
} else {
word_print (word);
}
fclose(f);
fprintf(stderr,"Done.\n");
hash_stats();
if (debug_mode) {
fprintf (stderr, "Total memory allocated %ld bytes.\n",
total_malloced());
}
/* May as well */
word_free (word);
return 0;
}
|