comparison srogue/makevers.c @ 36:2128c7dc8a40

Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
author elwin
date Thu, 25 Nov 2010 12:21:41 +0000
parents
children
comparison
equal deleted inserted replaced
35:05018c63a721 36:2128c7dc8a40
1 /*
2 * Change the version number of rogue
3 *
4 * The version must be in the file in the format of:
5 *
6 * " * @(#)filename\tVERSION\t ..."
7 *
8 * Where VERSION is a 3 character string, i.e., "8.2"
9 *
10 * Super-Rogue
11 * Copyright (C) 1984 Robert D. Kindelberger
12 * All rights reserved.
13 *
14 * See the file LICENSE.TXT for full copyright and licensing information.
15 */
16
17 #include <stdio.h>
18 #include <time.h>
19
20 long clock;
21 struct tm *tp;
22 char who[100];
23
24 char *strrchr(), *strchr(), *fgets();
25
26 main(argc, argv)
27 int argc;
28 char **argv;
29 {
30 register int i;
31 register char *ptr;
32 char ts[30];
33 FILE *fp;
34
35 strcpy(who, argv[0]);
36 if (argc < 3) {
37 fprintf(stderr,"Usage: %s VERSION c_files\n", who);
38 exit(1);
39 }
40 if (strlen(argv[1]) != 3) {
41 fprintf(stderr,"%s: VERSION must be length 3\n", who);
42 exit(1);
43 }
44 time(&clock);
45 tp = localtime(&clock);
46 sprintf(ts,"%2d/%2d/%2d",tp->tm_mon + 1,tp->tm_mday,tp->tm_year);
47 for (i = 2; i < argc; i++) {
48 ptr = strrchr(argv[i], '.');
49 /*
50 * make sure that files end in ".c" or ".h"
51 */
52 if (ptr != NULL) {
53 ++ptr;
54 if (*ptr == 'c' || *ptr == 'h')
55 updvers(argv[1], argv[i]);
56 }
57 }
58 /*
59 * now install new "version.c" file
60 */
61 fp = fopen("vers.c", "w");
62 if (fp == NULL) {
63 fprintf(stderr,"%s: cant write version.c file\n",who);
64 exit(1);
65 }
66 fprintf(fp, "/*\n * version number.\n */\n");
67 fprintf(fp, "char version[] = ");
68 fprintf(fp, "%c@(#)vers.c\t%3s\t(rdk)\t%s%c;\n", '"',
69 argv[1], ts, '"');
70 fprintf(fp, "char *release = \"%s (%s)\";\n", argv[1],ts);
71 fclose(fp);
72 exit(0);
73 }
74
75 #define LINESIZ 132
76
77 updvers(vers, fname)
78 char *fname;
79 char *vers;
80 {
81 register FILE *fp;
82 register char *ptr, *c;
83 char line[LINESIZ];
84
85 if ((fp = fopen(fname, "r+")) == NULL) {
86 fprintf(stderr,"%s: Not able to update %s\n", who, fname);
87 return;
88 }
89 while ((c = fgets(line, LINESIZ, fp)) != NULL) {
90 if (line[1] == '*' && line[3] == '@' && line[5] == '#') {
91 ptr = strchr(line, '\t');
92 if (ptr != NULL) {
93 fseek(fp, -strlen(line), 1);
94 sprintf(ptr, "\t%3s\t(rdk)\t%2d/%2d/%2d\n", vers,
95 tp->tm_mon + 1, tp->tm_mday, tp->tm_year);
96 fprintf(fp, "%s", line);
97 break;
98 }
99 }
100 }
101 fclose(fp);
102 }