… | |
… | |
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"); |
33 | exit(1); |
35 | exit(1); |
34 | } |
36 | } |
35 | if (!(fp = fopen(argv[1],"r"))) { |
37 | if (!(fp = fopen(argv[1],"r"))) { |
36 | perror("Can't open file"); |
38 | perror("Can't open file"); |
37 | exit(1); |
39 | exit(1); |
38 | } |
40 | } |
39 | if (!(buf=psiconv_buffer_new(0))) { |
41 | if (!(buf=psiconv_buffer_new())) { |
40 | perror("Can't allocate buf"); |
42 | perror("Can't allocate buf"); |
41 | exit(1); |
43 | exit(1); |
42 | } |
44 | } |
43 | if ((psiconv_buffer_fread_all(buf,fp))) { |
45 | if ((psiconv_buffer_fread_all(buf,fp))) { |
44 | perror("Can't fread file"); |
46 | perror("Can't fread file"); |
… | |
… | |
47 | fclose(fp); |
49 | fclose(fp); |
48 | if ((psiconv_parse(buf,&psionfile))) { |
50 | if ((psiconv_parse(buf,&psionfile))) { |
49 | fprintf(stderr,"Parse error\n"); |
51 | fprintf(stderr,"Parse error\n"); |
50 | exit(1); |
52 | exit(1); |
51 | } |
53 | } |
|
|
54 | |
52 | psiconv_buffer_free(buf); |
55 | psiconv_buffer_free(buf); |
53 | buf = NULL; |
56 | buf = NULL; |
54 | if (psiconv_write(&buf,psionfile)) { |
57 | if (psiconv_write(&buf,psionfile)) { |
55 | fprintf(stderr,"Parse error\n"); |
58 | fprintf(stderr,"Generate error\n"); |
56 | exit(1); |
59 | exit(1); |
57 | } |
60 | } |
|
|
61 | psiconv_free_file(psionfile); |
58 | if (!(fp = fopen(argv[2],"w"))) { |
62 | if (!(fp = fopen(argv[2],"w"))) { |
59 | perror("Can't open file"); |
63 | perror("Can't open file"); |
60 | exit(1); |
64 | exit(1); |
61 | } |
65 | } |
62 | if ((psiconv_buffer_fwrite_all(buf,fp))) { |
66 | if ((psiconv_buffer_fwrite_all(buf,fp))) { |
63 | perror("Can't fwrite file"); |
67 | perror("Can't fwrite file"); |
64 | exit(1); |
68 | exit(1); |
65 | } |
69 | } |
|
|
70 | fclose(fp); |
|
|
71 | psiconv_buffer_free(buf); |
66 | exit(0); |
72 | exit(0); |
67 | } |
73 | } |