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

Annotation of /psiconv/trunk/program/extra/rewrite.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 165 - (hide annotations)
Sun Nov 23 18:48:55 2003 UTC (20 years, 11 months ago) by frodo
File MIME type: text/plain
File size: 1970 byte(s)
(Frodo) Explain rewrite syntax

1 frodo 75 /*
2     rewrite.c - Part of psiconv, a PSION 5 file formats converter
3     Copyright (c) 1999 Frodo Looijaard <frodol@dds.nl>
4    
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    
23     #include <stdio.h>
24    
25     int main(int argc, char *argv[])
26     {
27     FILE *fp;
28     psiconv_buffer buf;
29     psiconv_file psionfile;
30    
31 frodo 80 /* psiconv_verbosity = PSICONV_VERB_DEBUG; */
32    
33 frodo 75 if (argc < 3) {
34     fprintf(stderr,"Not enough arguments\n");
35 frodo 165 fprintf(stderr,"Syntax: INFILE OUTFILE\n");
36 frodo 75 exit(1);
37     }
38     if (!(fp = fopen(argv[1],"r"))) {
39     perror("Can't open file");
40     exit(1);
41     }
42 frodo 80 if (!(buf=psiconv_buffer_new())) {
43 frodo 75 perror("Can't allocate buf");
44     exit(1);
45     }
46 frodo 79 if ((psiconv_buffer_fread_all(buf,fp))) {
47 frodo 75 perror("Can't fread file");
48     exit(1);
49     }
50     fclose(fp);
51     if ((psiconv_parse(buf,&psionfile))) {
52     fprintf(stderr,"Parse error\n");
53     exit(1);
54     }
55 frodo 80
56 frodo 79 psiconv_buffer_free(buf);
57 frodo 75 buf = NULL;
58     if (psiconv_write(&buf,psionfile)) {
59 frodo 80 fprintf(stderr,"Generate error\n");
60 frodo 75 exit(1);
61     }
62 frodo 142 psiconv_free_file(psionfile);
63 frodo 75 if (!(fp = fopen(argv[2],"w"))) {
64     perror("Can't open file");
65     exit(1);
66     }
67 frodo 79 if ((psiconv_buffer_fwrite_all(buf,fp))) {
68 frodo 75 perror("Can't fwrite file");
69     exit(1);
70     }
71 frodo 144 fclose(fp);
72 frodo 142 psiconv_buffer_free(buf);
73 frodo 75 exit(0);
74     }

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