2 Copyright 1996-2003 Victor Wagner
3 Copyright 2003 Alex Ott
4 This file is released under the GPL. Details can be
5 found in the file COPYING accompanying this distribution.
21 int signature_check = 1;
22 int forced_charset = 0; /* Flag which disallow rtf parser override charset*/
23 int wrap_margin = WRAP_MARGIN;
24 int (*get_unicode_char)(FILE *f,long *offset,long fileend) =NULL;
26 char *input_buffer, *output_buffer;
28 /* watcom doesn't provide way to access program args via global variable */
29 /* so we would hack it ourselves in Borland-compatible way*/
33 /**************************************************************/
35 /* Processes options, reads charsets files and substitution */
36 /* maps and passes all remaining args to processfile */
37 /**************************************************************/
38 int main(int argc, char **argv) {
42 short int *tmp_charset;
43 int stdin_processed=0;
48 read_config_file(SYSTEMRC);
50 tempname=find_file(strdup(USERRC),getenv("HOME"));
52 read_config_file(tempname);
59 while ((c=getopt(argc,argv,"Vls:d:f:taubxv8wm:"))!=-1) {
62 check_charset(&source_csname,optarg);
66 check_charset(&dest_csname,optarg);
69 format_name=strdup(optarg);
72 format_name=strdup("tex");
75 format_name=strdup("ascii");
78 get_unicode_char = get_word8_char;
81 get_unicode_char = get_8bit_char;
87 wrap_margin=0; /* No wrap */
91 wrap_margin = strtol(optarg,&endptr,0);
93 fprintf(stderr,"Invalid wrap margin value `%s'\n",optarg);
98 case 'l': list_charsets(); exit(0);
99 case 'b': signature_check =0; break;
100 case 'x': unknown_as_hex = 1; break;
101 case 'V': printf("Catdoc Version %s\n",CATDOC_VERSION);
108 input_buffer=malloc(FILE_BUFFER);
110 fprintf(stderr,"Input buffer not allocated\n");
112 source_charset = read_charset(source_csname);
113 if (!source_charset) exit(1);
114 if (strncmp(dest_csname,"utf-8",6)) {
115 tmp_charset = read_charset(dest_csname);
116 if (!tmp_charset) exit(1);
117 target_charset= make_reverse_map(tmp_charset);
120 target_charset = NULL;
122 spec_chars=read_substmap(stradd(format_name,SPEC_EXT));
124 fprintf(stderr,"Cannot read substitution map %s%s\n",format_name,
128 replacements=read_substmap(stradd(format_name,REPL_EXT));
130 fprintf(stderr,"Cannot read replacement map %s%s\n",format_name,
135 if (LINE_BUF_SIZE-longest_sequence<=wrap_margin) {
136 fprintf(stderr,"wrap margin is too large. cannot proceed\n");
139 if (!isatty(fileno(stdout))) {
140 output_buffer=malloc(FILE_BUFFER);
142 if (setvbuf(stdout,output_buffer,_IOFBF,FILE_BUFFER)) {
146 fprintf(stderr,"output buffer not allocated\n");
150 if (optind == argc) {
151 if (isatty(fileno(stdin))) {
155 if (input_buffer) setvbuf(stdin,input_buffer,_IOFBF,FILE_BUFFER);
156 return analyze_format(stdin);
159 for (i=optind;i<argc;i++) {
160 if (!strcmp(argv[i],"-")) {
161 if (stdin_processed) {
162 fprintf(stderr,"Cannot process stdin twice\n");
165 if (input_buffer) setvbuf(stdin,input_buffer,_IOFBF,FILE_BUFFER);
166 analyze_format(stdin);
169 f=fopen(argv[i],"rb");
176 if (setvbuf(f,input_buffer,_IOFBF,FILE_BUFFER)) {
186 /************************************************************************/
187 /* Displays help message */
188 /************************************************************************/
190 printf("Usage:\n catdoc [-vu8btawxlV] [-m number] [-s charset] "
191 "[-d charset] [ -f format] files\n");