FreeCalypso > hg > ueda-linux
annotate pads2gpcb/main.c @ 49:b3b7013d9228
pads2gpcb.c/decals.c: allow underscores in written decal file names
| author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
|---|---|
| date | Sat, 30 Jan 2016 17:38:47 +0000 |
| parents | 8fa304e2b7e1 |
| children | f2bcf69fce63 |
| rev | line source |
|---|---|
|
38
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 #include <stdio.h> |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 #include <stdlib.h> |
|
47
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
3 #include <unistd.h> |
|
38
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 #include <ctype.h> |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <string.h> |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <strings.h> |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include "globals.h" |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 |
|
39
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
9 static |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
10 parse_header_line() |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
11 { |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
12 char *cp; |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
13 |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
14 if (strncmp(input_line_buf, "!PADS-POWERPCB-", 15)) |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
15 return(-1); |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
16 cp = input_line_buf + 15; |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
17 while (isalnum(*cp) || *cp == '.') |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
18 cp++; |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
19 if (*cp++ != '-') |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
20 return(-1); |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
21 if (!strncmp(cp, "BASIC", 5)) |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
22 input_units_global = 'B'; |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
23 else if (!strncmp(cp, "MILS", 4)) |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
24 input_units_global = 'I'; |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
25 else if (!strncmp(cp, "METRIC", 6)) |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
26 input_units_global = 'M'; |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
27 else |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
28 return(-1); |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
29 return(0); |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
30 } |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
31 |
|
47
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
32 static void |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
33 process_write_option() |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
34 { |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
35 extern char *optarg; |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
36 |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
37 if (strlen(optarg) != 1) { |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
38 inv: fprintf(stderr, "usage error: invalid -w option\n"); |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
39 exit(1); |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
40 } |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
41 switch (optarg[0]) { |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
42 case 'd': |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
43 write_decal_files = 1; |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
44 return; |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
45 case 'p': |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
46 write_parttype_files = 1; |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
47 return; |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
48 case 'e': |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
49 write_final_elements = 1; |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
50 return; |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
51 default: |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
52 goto inv; |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
53 } |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
54 } |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
55 |
|
38
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 main(argc, argv) |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 char **argv; |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 { |
|
47
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
59 int c; |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
60 extern int optind; |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
61 |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
62 while ((c = getopt(argc, argv, "w:")) != EOF) |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
63 switch (c) { |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
64 case 'w': |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
65 process_write_option(); |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
66 continue; |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
67 default: |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
68 usage: |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
69 fprintf(stderr, "usage: %s [options] pads-file.asc\n", |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
70 argv[0]); |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
71 exit(1); |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
72 } |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
73 if (argc != optind + 1) |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
74 goto usage; |
|
8fa304e2b7e1
pads2gpcb: parsing of -w options implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
42
diff
changeset
|
75 input_filename = argv[optind]; |
|
38
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 open_input_file(); |
|
39
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
77 |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
78 /* parse the header line with the units specification */ |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
79 if (!get_input_line()) { |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
80 invheader: fprintf(stderr, |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
81 "error: %s does not begin with a recognized header line\n", |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
82 input_filename); |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
83 exit(1); |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
84 } |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
85 if (parse_header_line() < 0) |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
86 goto invheader; |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
87 |
|
242f73e61ef0
pads2gpcb: implemented parsing of the header line with units spec
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
38
diff
changeset
|
88 /* process the body of the monster! */ |
|
38
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 while (get_input_line()) { |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 if (input_line_buf[0] != '*') |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 continue; |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 parse_starline(); |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 loop: if (!strcmp(input_line_starkw, "PARTDECAL")) { |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
94 process_partdecal_section(); |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
95 goto loop; |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 } |
|
42
43ba91b137e2
pads2gpcb: starting to grok decal definitions
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
39
diff
changeset
|
97 #if 0 |
|
38
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
98 if (!strcmp(input_line_starkw, "PARTTYPE")) { |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 process_parttype_section(); |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
100 goto loop; |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
101 } |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
102 if (!strcmp(input_line_starkw, "PART")) { |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
103 process_part_section(); |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
104 goto loop; |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
105 } |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
106 #endif |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
107 } |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
108 exit(0); |
|
aa0539cc3d41
pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
109 } |
