/[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 66
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;
112
113 psiconv_verbosity = PSICONV_VERB_WARN;
117 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();
131 case 'V': print_version(); exit(0); 128 case 'V': print_version(); exit(0);
132 case 'v': if (psiconv_verbosity < PSICONV_VERB_PROGRESS) 129 case 'v': if (psiconv_verbosity < PSICONV_VERB_PROGRESS)
133 psiconv_verbosity = PSICONV_VERB_PROGRESS; 130 psiconv_verbosity = PSICONV_VERB_PROGRESS;
134 break; 131 break;
135 case 'd': psiconv_verbosity = PSICONV_VERB_DEBUG; break; 132 case 'd': psiconv_verbosity = PSICONV_VERB_DEBUG; break;
136 case 's': psiconv_verbosity = PSICONV_VERB_SILENT; break; 133 case 's': psiconv_verbosity = PSICONV_VERB_FATAL; break;
137 case 'e': exact = 1; break;
138 case 'o': outputfilename = strdup(optarg); break; 134 case 'o': outputfilename = strdup(optarg); break;
139 case 'T': type = strdup(optarg); break; 135 case 'T': type = strdup(optarg); break;
140 case '?': case ':': fputs("Try `-h' for more information\n",stderr); 136 case '?': case ':': fputs("Try `-h' for more information\n",stderr);
141 exit(1); 137 exit(1);
142 default: fprintf(stderr,"Internal error: getopt_long returned character " 138 default: fprintf(stderr,"Internal error: getopt_long returned character "
149 "Try `-h' for more information\n",stderr); 145 "Try `-h' for more information\n",stderr);
150 exit(1); 146 exit(1);
151 } else if (optind == argc-1) 147 } else if (optind == argc-1)
152 inputfilename = strdup(argv[optind]); 148 inputfilename = strdup(argv[optind]);
153 149
150
154 /* Open inputfile for reading */ 151 /* Open inputfile for reading */
155 152
156 if (strlen(inputfilename) != 0) { 153 if (strlen(inputfilename) != 0) {
157 if(stat(inputfilename,&fbuf) < 0) { 154 if(stat(inputfilename,&fbuf) < 0) {
158 perror(inputfilename); 155 perror(inputfilename);
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.66

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