1 |
frodo |
75 |
/* |
2 |
|
|
rewrite.c - Part of psiconv, a PSION 5 file formats converter |
3 |
frodo |
351 |
Copyright (c) 1999-2014 Frodo Looijaard <frodo@frodo.looijaard.name> |
4 |
frodo |
75 |
|
5 |
|
|
This program is free software; you can redistribute it and/or modify |
6 |
|
|
it under the terms of the GNU General Public License as published by |
7 |
|
|
the Free Software Foundation; either version 2 of the License, or |
8 |
|
|
(at your option) any later version. |
9 |
|
|
|
10 |
|
|
This program is distributed in the hope that it will be useful, |
11 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
|
|
GNU General Public License for more details. |
14 |
|
|
|
15 |
|
|
You should have received a copy of the GNU General Public License |
16 |
|
|
along with this program; if not, write to the Free Software |
17 |
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
18 |
|
|
*/ |
19 |
|
|
|
20 |
|
|
#include <psiconv/parse.h> |
21 |
|
|
#include <psiconv/generate.h> |
22 |
frodo |
168 |
#include <psiconv/configuration.h> |
23 |
frodo |
75 |
|
24 |
frodo |
168 |
#include <stdlib.h> |
25 |
frodo |
75 |
#include <stdio.h> |
26 |
|
|
|
27 |
|
|
int main(int argc, char *argv[]) |
28 |
|
|
{ |
29 |
|
|
FILE *fp; |
30 |
|
|
psiconv_buffer buf; |
31 |
|
|
psiconv_file psionfile; |
32 |
frodo |
168 |
psiconv_config config; |
33 |
frodo |
75 |
|
34 |
frodo |
80 |
/* psiconv_verbosity = PSICONV_VERB_DEBUG; */ |
35 |
|
|
|
36 |
frodo |
75 |
if (argc < 3) { |
37 |
|
|
fprintf(stderr,"Not enough arguments\n"); |
38 |
frodo |
165 |
fprintf(stderr,"Syntax: INFILE OUTFILE\n"); |
39 |
frodo |
75 |
exit(1); |
40 |
|
|
} |
41 |
frodo |
180 |
|
42 |
|
|
config = psiconv_config_default(); |
43 |
|
|
psiconv_config_read(NULL,&config); |
44 |
|
|
|
45 |
frodo |
75 |
if (!(fp = fopen(argv[1],"r"))) { |
46 |
|
|
perror("Can't open file"); |
47 |
|
|
exit(1); |
48 |
|
|
} |
49 |
frodo |
80 |
if (!(buf=psiconv_buffer_new())) { |
50 |
frodo |
75 |
perror("Can't allocate buf"); |
51 |
|
|
exit(1); |
52 |
|
|
} |
53 |
frodo |
79 |
if ((psiconv_buffer_fread_all(buf,fp))) { |
54 |
frodo |
75 |
perror("Can't fread file"); |
55 |
|
|
exit(1); |
56 |
|
|
} |
57 |
|
|
fclose(fp); |
58 |
frodo |
168 |
if ((psiconv_parse(config,buf,&psionfile))) { |
59 |
frodo |
75 |
fprintf(stderr,"Parse error\n"); |
60 |
|
|
exit(1); |
61 |
|
|
} |
62 |
frodo |
80 |
|
63 |
frodo |
79 |
psiconv_buffer_free(buf); |
64 |
frodo |
75 |
buf = NULL; |
65 |
frodo |
168 |
if (psiconv_write(config,&buf,psionfile)) { |
66 |
frodo |
80 |
fprintf(stderr,"Generate error\n"); |
67 |
frodo |
75 |
exit(1); |
68 |
|
|
} |
69 |
frodo |
142 |
psiconv_free_file(psionfile); |
70 |
frodo |
75 |
if (!(fp = fopen(argv[2],"w"))) { |
71 |
|
|
perror("Can't open file"); |
72 |
|
|
exit(1); |
73 |
|
|
} |
74 |
frodo |
79 |
if ((psiconv_buffer_fwrite_all(buf,fp))) { |
75 |
frodo |
75 |
perror("Can't fwrite file"); |
76 |
|
|
exit(1); |
77 |
|
|
} |
78 |
frodo |
144 |
fclose(fp); |
79 |
frodo |
142 |
psiconv_buffer_free(buf); |
80 |
frodo |
208 |
psiconv_config_free(config); |
81 |
frodo |
75 |
exit(0); |
82 |
|
|
} |