1 /*
2 main.c
3
4 part of the cptutils package
5
6 This program is free software; you can redistribute it
7 and/or modify it under the terms of the GNU General
8 Public License as published by the Free Software
9 Foundation; either version 2 of the License, or (at your
10 option) any later version.
11
12 This program is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the
14 implied warranty of MERCHANTABILITY or FITNESS FOR A
15 PARTICULAR PURIGHTE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public
19 License along with this program; if not, write to the
20 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301 USA
22 */
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include <unistd.h>
29
30 #include <btrace.h>
31
32 #include "options.h"
33 #include "pssvg.h"
34
main(int argc,char ** argv)35 int main(int argc, char** argv)
36 {
37 struct gengetopt_args_info info;
38 pssvg_opt_t opt = {0};
39 char *infile, *outfile;
40
41 /* gengetopt */
42
43 if (options(argc, argv, &info) != 0)
44 {
45 fprintf(stderr, "failed to parse command line\n");
46 return EXIT_FAILURE;
47 }
48
49 /* check arguments & transfer to opt structure */
50
51 opt.verbose = info.verbose_flag;
52
53 /* title format string */
54
55 opt.title = (info.title_given ? info.title_arg : NULL);
56
57 /* fore/background */
58
59 if (parse_rgb(info.background_arg, &(opt.bg)) != 0)
60 {
61 fprintf(stderr,"bad background %s\n",info.background_arg);
62 return EXIT_FAILURE;
63 }
64
65 if (parse_rgb(info.foreground_arg, &(opt.fg)) != 0)
66 {
67 fprintf(stderr,"bad foreground %s\n",info.foreground_arg);
68 return EXIT_FAILURE;
69 }
70
71 /* null outfile for stdout */
72
73 outfile = (info.output_given ? info.output_arg : NULL);
74
75 /* null infile for stdin */
76
77 switch (info.inputs_num)
78 {
79 case 0:
80 infile = NULL;
81 break;
82 case 1:
83 infile = info.inputs[0];
84 break;
85 default:
86 fprintf(stderr,
87 "Exactly one Photoshop gradient file must be specified!\n");
88 options_print_help();
89 return EXIT_FAILURE;
90 }
91
92 opt.file.input = infile;
93 opt.file.output = outfile;
94
95 /*
96 we write the translation of the svg gradient <name> to stdout
97 if <name> is specified, so then we suppress verbosity
98 */
99
100 if (!outfile && opt.verbose)
101 {
102 fprintf(stderr, "verbosity suppressed (<stdout> for results)\n");
103 opt.verbose = 0;
104 }
105
106 /* say hello */
107
108 if (opt.verbose)
109 {
110 printf("This is pssvg (version %s)\n", VERSION);
111 if (opt.title)
112 printf("with title format '%s'\n", opt.title);
113 printf("background %3i/%3i/%3i\n",
114 opt.bg.red, opt.bg.green, opt.bg.blue);
115 printf("foreground %3i/%3i/%3i\n",
116 opt.fg.red, opt.fg.green, opt.fg.blue);
117 }
118
119 btrace_enable("pssvg");
120
121 int err = pssvg(opt);
122
123 if (err)
124 {
125 btrace("failed (error %i)", err);
126 btrace_print_stream(stderr, BTRACE_PLAIN);
127
128 if (info.backtrace_file_given)
129 {
130 int format = BTRACE_XML;
131 if (info.backtrace_format_given)
132 {
133 format = btrace_format(info.backtrace_format_arg);
134 if (format == BTRACE_ERROR)
135 {
136 fprintf(stderr, "no such backtrace format %s\n",
137 info.backtrace_format_arg);
138 return EXIT_FAILURE;
139 }
140 }
141 btrace_print(info.backtrace_file_arg, format);
142 }
143 }
144
145 btrace_reset();
146 btrace_disable();
147
148 if (opt.verbose)
149 printf("done.\n");
150
151 options_free(&info);
152
153 return (err ? EXIT_FAILURE : EXIT_SUCCESS);
154 }
155
156
157
158
159
160
161
162
163
164
165
166
167