comparison helpers/str2ind-ver.c @ 60:f4eeab478bfe

str2ind-ver helper written
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 01 Oct 2016 00:54:04 +0000
parents
children
comparison
equal deleted inserted replaced
59:b67077cf6b1b 60:f4eeab478bfe
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 }