FreeCalypso > hg > fc-tourmaline
annotate helpers/str2ind-ver.c @ 44:1821e301a65b
R2D: new Tourmaline driver selection
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 17 Oct 2020 19:45:18 +0000 |
parents | 1fb47f5b597a |
children |
rev | line source |
---|---|
9
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This utility extracts the timestamp from a str2ind.tab file |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * and emits the corresponding char *str2ind_version C line. |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdlib.h> |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <strings.h> |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 main(argc, argv) |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 char **argv; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 FILE *inf; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 char buf[32], *cp; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 if (argc != 2) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 fprintf(stderr, "usage: %s str2ind.tab\n", argv[0]); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 exit(1); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 inf = fopen(argv[1], "r"); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 if (!inf) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 perror(argv[1]); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 exit(1); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 if (!fgets(buf, sizeof buf, inf)) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 inv: fprintf(stderr, |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 "Error: %s does not have the expected first line\n", |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 argv[1]); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 exit(1); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 cp = index(buf, '\n'); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 if (!cp || cp == buf) |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 goto inv; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 *cp = '\0'; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 if (cp[-1] == '\r') |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 *--cp = '\0'; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (cp != buf + 10) |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 goto inv; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 printf("char *str2ind_version = \"&%s\";\n", buf); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 exit(0); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |