/[public]/psiconv/trunk/program/psiconv/psiconv.c
ViewVC logotype

Diff of /psiconv/trunk/program/psiconv/psiconv.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 58 Revision 109
43 43
44static void print_help(void); 44static void print_help(void);
45static void print_version(void); 45static void print_version(void);
46static void strtoupper(char *str); 46static void strtoupper(char *str);
47 47
48int psiconv_verbosity = PSICONV_VERB_WARN;
49
50void print_help(void) 48void print_help(void)
51{ 49{
52 psiconv_fileformat ff; 50 psiconv_fileformat ff;
53 int i,j; 51 int i,j;
54 52
55 puts("Syntax: psiconv [OPTIONS..] [FILE]"); 53 puts("Syntax: psiconv [OPTIONS..] [FILE]");
56 puts("Convert the psion Word file FILE to a HTML file"); 54 puts("Convert the psion Word file FILE to a HTML file");
57 puts("If FILE is not specified, use stdin"); 55 puts("If FILE is not specified, use stdin");
58 puts(" -d, --debug Show debug information on stderr"); 56 puts(" -d, --debug Show debug information on stderr");
59 puts(" -e, --exact Quit on any parse errors or warnings");
60 puts(" -h, --help Display this help and exit"); 57 puts(" -h, --help Display this help and exit");
61 puts(" -o, --outputfile Output to file instead of stdout"); 58 puts(" -o, --outputfile Output to file instead of stdout");
62 puts(" -s, --silent Do not even show warnings on stderr"); 59 puts(" -s, --silent Do not even show warnings on stderr");
63 puts(" -T, --type=FILETYPE Output type"); 60 puts(" -T, --type=FILETYPE Output type");
64 puts(" -V, --version Display the program version and exit"); 61 puts(" -V, --version Display the program version and exit");
95 {"verbose",no_argument,NULL,'v'}, 92 {"verbose",no_argument,NULL,'v'},
96 {"debug",no_argument,NULL,'d'}, 93 {"debug",no_argument,NULL,'d'},
97 {"silent",no_argument,NULL,'s'}, 94 {"silent",no_argument,NULL,'s'},
98 {"outputfile",required_argument,NULL,'o'}, 95 {"outputfile",required_argument,NULL,'o'},
99 {"type",required_argument,NULL,'T'}, 96 {"type",required_argument,NULL,'T'},
100 {"exact",no_argument,NULL,'e'},
101 {0,0,0,0} 97 {0,0,0,0}
102 }; 98 };
103 const char* short_options = "hVvsdo:eT:"; 99 const char* short_options = "hVvsdo:eT:";
104 int option_index; 100 int option_index;
105 FILE * f; 101 FILE * f;
106 struct stat fbuf; 102 struct stat fbuf;
107 103
108 const char *inputfilename = ""; 104 const char *inputfilename = "";
109 const char *outputfilename = ""; 105 const char *outputfilename = "";
110 char *type = strdup("HTML3"); 106 char *type = strdup("HTML3");
111 int exact=0;
112 107
113 int c,i,res; 108 int c,i,res;
114 psiconv_buffer buf; 109 psiconv_buffer buf;
115 psiconv_file file; 110 psiconv_file file;
116 psiconv_fileformat ff; 111 psiconv_fileformat ff;
117 112
113 psiconv_verbosity = PSICONV_VERB_WARN;
114
118 fileformat_list = psiconv_list_new(sizeof(struct psiconv_fileformat_s)); 115 fileformat_list = psiconv_list_new(sizeof(struct psiconv_fileformat_s));
119 init_txt(); 116 init_txt();
120 init_html(); 117 init_html();
121 init_html4(); 118 init_html4();
119 init_latex();
122 init_rtf(); 120 init_rtf();
123 init_image(); 121 init_image();
124 122
125 while(1) { 123 while(1) {
126 c = getopt_long(argc,argv,short_options, long_options, &option_index); 124 c = getopt_long(argc,argv,short_options, long_options, &option_index);
131 case 'V': print_version(); exit(0); 129 case 'V': print_version(); exit(0);
132 case 'v': if (psiconv_verbosity < PSICONV_VERB_PROGRESS) 130 case 'v': if (psiconv_verbosity < PSICONV_VERB_PROGRESS)
133 psiconv_verbosity = PSICONV_VERB_PROGRESS; 131 psiconv_verbosity = PSICONV_VERB_PROGRESS;
134 break; 132 break;
135 case 'd': psiconv_verbosity = PSICONV_VERB_DEBUG; break; 133 case 'd': psiconv_verbosity = PSICONV_VERB_DEBUG; break;
136 case 's': psiconv_verbosity = PSICONV_VERB_SILENT; break; 134 case 's': psiconv_verbosity = PSICONV_VERB_FATAL; break;
137 case 'e': exact = 1; break;
138 case 'o': outputfilename = strdup(optarg); break; 135 case 'o': outputfilename = strdup(optarg); break;
139 case 'T': type = strdup(optarg); break; 136 case 'T': type = strdup(optarg); break;
140 case '?': case ':': fputs("Try `-h' for more information\n",stderr); 137 case '?': case ':': fputs("Try `-h' for more information\n",stderr);
141 exit(1); 138 exit(1);
142 default: fprintf(stderr,"Internal error: getopt_long returned character " 139 default: fprintf(stderr,"Internal error: getopt_long returned character "
149 "Try `-h' for more information\n",stderr); 146 "Try `-h' for more information\n",stderr);
150 exit(1); 147 exit(1);
151 } else if (optind == argc-1) 148 } else if (optind == argc-1)
152 inputfilename = strdup(argv[optind]); 149 inputfilename = strdup(argv[optind]);
153 150
151
154 /* Open inputfile for reading */ 152 /* Open inputfile for reading */
155 153
156 if (strlen(inputfilename) != 0) { 154 if (strlen(inputfilename) != 0) {
157 if(stat(inputfilename,&fbuf) < 0) { 155 if(stat(inputfilename,&fbuf) < 0) {
158 perror(inputfilename); 156 perror(inputfilename);
164 exit(1); 162 exit(1);
165 } 163 }
166 } else 164 } else
167 f = stdin; 165 f = stdin;
168 166
169 buf = psiconv_list_new(sizeof(psiconv_u8)); 167 buf = psiconv_buffer_new();
170 while (! feof(f)) 168 psiconv_buffer_fread_all(buf,f);
171 psiconv_list_fread(buf,1024,f);
172 169
173 if (strlen(inputfilename) != 0) 170 if (strlen(inputfilename) != 0)
174 if (fclose(f)) { 171 if (fclose(f)) {
175 perror(inputfilename); 172 perror(inputfilename);
176 exit(1); 173 exit(1);
177 } 174 }
178 175
179 if (psiconv_parse(buf,&file)) 176 if (psiconv_parse(buf,&file) || (file->type == psiconv_unknown_file))
180 if(exact) 177 {
178 fprintf(stderr,"Parse error\n");
181 exit(1); 179 exit(1);
180 }
182 181
183 /* Set correct output file */ 182 /* Set correct output file */
184 if (strlen(outputfilename) == 0) 183 if (strlen(outputfilename) == 0)
185 outputfilename = "/dev/stdout"; 184 outputfilename = "/dev/stdout";
186 185

Legend:
Removed from v.58  
changed lines
  Added in v.109

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26