comparison helpers/str2ind-ver.c @ 9:1fb47f5b597a

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