-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkfix.c
193 lines (183 loc) · 5.12 KB
/
mkfix.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <stdio.h>
#include <stdlib.h>
#ifndef SEEK_CUR
#include <unistd.h>
#endif
#include <time.h>
#include "romcal.h"
int main(argc, argv)
int argc;
char *argv[];
{
/*----------------------------------------------------------------------*
*
* @(#)ROMCAL mkfix.c 6.2 03/01/06 16:19:11
*
* Copyright (C) 1993,1995,1999,2003 Kenneth G. Bath
* Permission to use and modify this software and its
* documentation for any purpose other than its incorporation
* into a commercial product is hereby granted without fee.
*
* Permission to copy and distribute this software and its
* documentation only for non-commercial use is also granted
* without fee, provided, however, that the above copyright
* notice appear in all copies, that both that copyright
* notice and this permission notice appear in supporting
* documentation. The author makes no representations about
* the suitability of this software for any purpose. It is
* provided "as is" without express or implied warranty.
*
*-------------------- Software Unit Description -----------------------*
*
* This program generates the fixed.h include file from the
* fixed.dat data file.
*
*---------------------- Software Unit History -------------------------*
*
* 14Mar93 : created, kgb
* 16Mar93 : added season, kgb
* 17Mar93 : added exit status for Suns, kgb
* 18Feb95 : removed "usage.h"; added "version.h", kgb
* 08Feb02 : removed "version.h", kgb
*
*----------------------------------------------------------------------*/
#define WHITESPACE " \t"
long clock;
FILE *fpi,
*fpo;
char line[256];
char *strtok();
char *m,
*d,
*r,
*c,
*l;
/*----------------------------------------------------------------------*
* begin code *
*----------------------------------------------------------------------*/
/*
* Open the input file.
*/
fpi = fopen("fixed.dat", "r");
if (fpi == NULL) {
perror("fixed.dat");
exit(1);
}
/*
* Open the output file.
*/
fpo = fopen("fixed.h", "w");
if (fpo == NULL) {
perror("fixed.h");
exit(2);
}
/*
* Get the current time.
*/
time(&clock);
/*
* Print out the header.
*/
fprintf(fpo,
"/*----------------------------------------------------------------------*\n"
" *\n"
" * Copyright (C) 1993,1995 Kenneth G. Bath\n"
" * Permission to use and modify this software and its\n"
" * documentation for any purpose other than its incorporation\n"
" * into a commercial product is hereby granted without fee.\n"
" *\n"
" * Permission to copy and distribute this software and its\n"
" * documentation only for non-commercial use is also granted\n"
" * without fee, provided, however, that the above copyright\n"
" * notice appear in all copies, that both that copyright\n"
" * notice and this permission notice appear in supporting\n"
" * documentation. The author makes no representations about\n"
" * the suitability of this software for any purpose. It is\n"
" * provided \"as is\" without express or implied warranty.\n"
" *\n"
" *-------------------- Software Unit Description -----------------------*\n"
" *\n"
" * WARNING: THIS INCLUDE FILE WAS CREATED USING %s!!!\n"
" * This include file contains the fixed dates of the Roman\n"
" * Calendar.\n"
" *\n"
" *---------------------- Software Unit History -------------------------*\n"
" *\n"
" * Created by tool at %s"
" *\n"
" *----------------------------------------------------------------------*/\n",
argv[0],ctime(&clock));
/*
* Open the structure definition.
*/
fprintf(fpo, "\n");
fprintf(fpo, "static struct Cal fixed[] = {\n");
/*
* Read in the data file and create a structure.
*/
while (fgets(line, sizeof(line), fpi)) {
if (line[0] != '#') {
m = strtok(line, WHITESPACE); /* Month */
d = strtok(NULL, WHITESPACE); /* Day */
r = strtok(NULL, WHITESPACE); /* Rank */
c = strtok(NULL, WHITESPACE); /* Color */
l = strtok(NULL, "\n"); /* Celebration */
if (m && d && r && c && l) {
/*
* Write month and day.
*/
fprintf(fpo, " { %s, %s, ", m, d);
/*
* Write color.
*/
if (*c == 'G')
fprintf(fpo, "GREEN, ");
if (*c == 'R')
fprintf(fpo, "RED, ");
if (*c == 'W')
fprintf(fpo, "WHITE, ");
if (*c == 'P')
fprintf(fpo, "PURPLE, ");
if (*c == '-')
fprintf(fpo, "NOCOLOR, ");
/*
* Write rank.
*/
if (*r == 'O')
fprintf(fpo, "OPTIONAL, ");
if (*r == 'M')
fprintf(fpo, "MEMORIAL, ");
if (*r == 'F')
fprintf(fpo, "FEAST, ");
if (*r == 'L')
fprintf(fpo, "LORD, ");
if (*r == 'S')
fprintf(fpo, "SOLEMNITY, ");
/*
* Assume the season is Ordinary Time. This will be
* overwritten when necessary.
*/
fprintf(fpo, "ORDINARY, ");
/*
* Write a null for the invitatory (temp. code).
*/
fprintf(fpo, "\n \"%s\", NULL },\n", l);
}
}
}
/*
* Seek backwards two characters to overwrite the comma following the last
* entry.
*/
fseek(fpo, -2, SEEK_CUR);
/*
* Close the structure definition.
*/
fprintf(fpo, "\n};\n");
/*
* Close the files.
*/
fclose(fpi);
fclose(fpo);
return 0;
}