| … | |
… | |
| 26 | { |
26 | { |
| 27 | FILE *fp; |
27 | FILE *fp; |
| 28 | psiconv_buffer buf; |
28 | psiconv_buffer buf; |
| 29 | psiconv_file psionfile; |
29 | psiconv_file psionfile; |
| 30 | |
30 | |
|
|
31 | /* psiconv_verbosity = PSICONV_VERB_DEBUG; */ |
|
|
32 | |
| 31 | if (argc < 3) { |
33 | if (argc < 3) { |
| 32 | fprintf(stderr,"Not enough arguments\n"); |
34 | fprintf(stderr,"Not enough arguments\n"); |
|
|
35 | fprintf(stderr,"Syntax: INFILE OUTFILE\n"); |
| 33 | exit(1); |
36 | exit(1); |
| 34 | } |
37 | } |
| 35 | if (!(fp = fopen(argv[1],"r"))) { |
38 | if (!(fp = fopen(argv[1],"r"))) { |
| 36 | perror("Can't open file"); |
39 | perror("Can't open file"); |
| 37 | exit(1); |
40 | exit(1); |
| 38 | } |
41 | } |
| 39 | if (!(buf=psiconv_new_buffer())) { |
42 | if (!(buf=psiconv_buffer_new())) { |
| 40 | perror("Can't allocate buf"); |
43 | perror("Can't allocate buf"); |
| 41 | exit(1); |
44 | exit(1); |
| 42 | } |
45 | } |
| 43 | if ((psiconv_list_fread_all(buf,fp))) { |
46 | if ((psiconv_buffer_fread_all(buf,fp))) { |
| 44 | perror("Can't fread file"); |
47 | perror("Can't fread file"); |
| 45 | exit(1); |
48 | exit(1); |
| 46 | } |
49 | } |
| 47 | fclose(fp); |
50 | fclose(fp); |
| 48 | if ((psiconv_parse(buf,&psionfile))) { |
51 | if ((psiconv_parse(buf,&psionfile))) { |
| 49 | fprintf(stderr,"Parse error\n"); |
52 | fprintf(stderr,"Parse error\n"); |
| 50 | exit(1); |
53 | exit(1); |
| 51 | } |
54 | } |
|
|
55 | |
| 52 | psiconv_free_buffer(buf); |
56 | psiconv_buffer_free(buf); |
| 53 | buf = NULL; |
57 | buf = NULL; |
| 54 | if (psiconv_write(&buf,psionfile)) { |
58 | if (psiconv_write(&buf,psionfile)) { |
| 55 | fprintf(stderr,"Parse error\n"); |
59 | fprintf(stderr,"Generate error\n"); |
| 56 | exit(1); |
60 | exit(1); |
| 57 | } |
61 | } |
|
|
62 | psiconv_free_file(psionfile); |
| 58 | if (!(fp = fopen(argv[2],"w"))) { |
63 | if (!(fp = fopen(argv[2],"w"))) { |
| 59 | perror("Can't open file"); |
64 | perror("Can't open file"); |
| 60 | exit(1); |
65 | exit(1); |
| 61 | } |
66 | } |
| 62 | if ((psiconv_list_fwrite_all(buf,fp))) { |
67 | if ((psiconv_buffer_fwrite_all(buf,fp))) { |
| 63 | perror("Can't fwrite file"); |
68 | perror("Can't fwrite file"); |
| 64 | exit(1); |
69 | exit(1); |
| 65 | } |
70 | } |
|
|
71 | fclose(fp); |
|
|
72 | psiconv_buffer_free(buf); |
| 66 | exit(0); |
73 | exit(0); |
| 67 | } |
74 | } |