git ssb

1+

cel / pngspark



Commit a18e2f94c5c1c202b703482e5aabdaa261c3d95a

Require filename argument

Charles Lehner committed on 2/10/2015, 2:23:51 PM
Parent: 1954e349b19978c7e219c6610f4b143d6658af82

Files changed

main.cchanged
main.cView
@@ -13,30 +13,35 @@
1313 ['5'] = 1, ['6'] = 1, ['7'] = 1, ['8'] = 1, ['9'] = 1,
1414 ['.'] = 1, ['-'] = 1, ['e'] = 1, ['E'] = 1, 0
1515 };
1616
17 +void usage(const char *progname)
18 +{
19 + errx(1, "Usage: %s output.png [-h height] "
20 + "[-c color] [-s scaling]", progname);
21 +}
22 +
1723 int main(int argc, char *argv[])
1824 {
1925 struct pngspark ps;
2026 const char *color = "#000000";
21- const char *filename = "pngspark.png";
27 + const char *filename = NULL;
2228 double scaling = 0.8;
2329 int height = 10;
2430
2531 for (int i = 1; i < argc; i++) {
26- if (argv[i][0] != '-') continue;
27- if (argv[i][1] == '-') {
28- if (!strcmp("help", argv[i]+2)) {
29- errx(1, "Usage: %s [--help] [-h height] "
30- "[-o output.png] [-c color] [-s scale_min]", argv[0]);
32 + if (argv[i][0] != '-') {
33 + if (filename) {
34 + usage(argv[0]);
35 + } else {
36 + filename = argv[i];
3137 }
32- } else if (!argv[i][2]) switch (argv[i][1]) {
38 + } else if (argv[i][2]) {
39 + errx(1, "extra argument: %s", argv[i]);
40 + } else switch (argv[i][1]) {
3341 case 'c':
3442 if (++i < argc) color = argv[i];
3543 break;
36- case 'o':
37- if (++i < argc) filename = argv[i];
38- break;
3944 case 'h':
4045 if (++i < argc) height = atoi(argv[i]);
4146 break;
4247 case 's':
@@ -44,8 +49,12 @@
4449 break;
4550 }
4651 }
4752
53 + if (!filename) {
54 + usage(argv[0]);
55 + }
56 +
4857 FILE *file = fopen(filename, "w");
4958 if (!file) err(1, "unable to open file %s", filename);
5059
5160 if (pngspark_init(&ps, height, color, scaling) < 0)

Built with git-ssb-web