1 | /*
|
---|
2 | =============================================================================
|
---|
3 | newver.c -- read and update a GEMDOS version message object file
|
---|
4 | Version 1 -- 1988-10-28 -- D.N. Lynx Crowe
|
---|
5 | (c) Copyright 1988 -- D.N. Lynx Crowe -- All rights reserved
|
---|
6 |
|
---|
7 | Compiled and linked with the GEMDOS Alcyon C developer's package.
|
---|
8 |
|
---|
9 | NOTE: Because we use the Alcyon GEMDOS object file format,
|
---|
10 | which is specific to the Atari, this code is NON-PORTABLE.
|
---|
11 |
|
---|
12 | The idea, however, is adaptable to a wide variety of systems
|
---|
13 | and object file formats.
|
---|
14 |
|
---|
15 | Note also that the fopen() function in the Alcyon C library does not
|
---|
16 | support the "r+" option, making it necessary to close the file and
|
---|
17 | then open it again before writing. This is a serious shortcoming of
|
---|
18 | the Alcyon C library, as it makes updating files only possible by a
|
---|
19 | series of questionable maneuvers, (e.g. opening, closing, and reopening
|
---|
20 | the file, or using open(), then fdopen(), etc.).
|
---|
21 | =============================================================================
|
---|
22 | */
|
---|
23 |
|
---|
24 | #include "stdio.h" /* Atari GEMDOS standard I/O definitions */
|
---|
25 | #include "stddefs.h" /* some usefull standard C definitions */
|
---|
26 | #include "objdefs.h" /* GEMDOS object file definitions */
|
---|
27 |
|
---|
28 | #define VERFILE "verdate.o" /* version message file */
|
---|
29 |
|
---|
30 | extern int errno; /* system error code */
|
---|
31 |
|
---|
32 | extern char *now(); /* get formatted system date and time */
|
---|
33 |
|
---|
34 | FILE *fp; /* VERFILE file pointer */
|
---|
35 |
|
---|
36 | /* 000000000011111111112 */
|
---|
37 | /* 012345678901234567890 */
|
---|
38 | char dtg[22]; /* yyyy-mm-dd hh:mm:ss zero terminated string */
|
---|
39 |
|
---|
40 | /* 000000000011 */
|
---|
41 | /* 012345678901 */
|
---|
42 | char verstr[12]; /* yyyymmdd.vv zero terminated string */
|
---|
43 |
|
---|
44 | struct vb { /* VERFILE buffer (66 bytes) */
|
---|
45 |
|
---|
46 | struct EXFILE hdr;
|
---|
47 | char ver[12];
|
---|
48 | struct SYMBOL sym;
|
---|
49 | char rem[12];
|
---|
50 |
|
---|
51 | } verbuf;
|
---|
52 |
|
---|
53 | /* |
---|
54 |
|
---|
55 | */
|
---|
56 |
|
---|
57 | /*
|
---|
58 | =============================================================================
|
---|
59 | read and update an Alcyon/GEMDOS format version message object file
|
---|
60 | =============================================================================
|
---|
61 | */
|
---|
62 |
|
---|
63 | main()
|
---|
64 | {
|
---|
65 | short len, rc, vn, vp1, vp2;
|
---|
66 |
|
---|
67 | len = sizeof verbuf;
|
---|
68 |
|
---|
69 | /* first, read the old version message object file */
|
---|
70 |
|
---|
71 | if ((FILE *)NULL EQ (fp = fopenb(VERFILE, "r"))) {
|
---|
72 |
|
---|
73 | printf("ERROR -- Unable to open \"%s\" for reading (errno = %d)\n",
|
---|
74 | VERFILE, errno);
|
---|
75 |
|
---|
76 | exit(1);
|
---|
77 | }
|
---|
78 |
|
---|
79 | rewind(fp);
|
---|
80 |
|
---|
81 | if (1 NE (rc = fread(&verbuf, len, 1, fp))) {
|
---|
82 |
|
---|
83 | printf("ERROR -- Unable to read \"%s\" (rc = %d, errno = %d)\n",
|
---|
84 | VERFILE, rc, errno);
|
---|
85 |
|
---|
86 | if (ferror(fp))
|
---|
87 | printf(" File system ERROR.\n");
|
---|
88 | else if (feof(fp))
|
---|
89 | printf(" Premature EOF.\n");
|
---|
90 | else
|
---|
91 | printf(" Neither ERROR or EOF set -- very odd\n");
|
---|
92 |
|
---|
93 | fclose(fp);
|
---|
94 | exit(1);
|
---|
95 | }
|
---|
96 |
|
---|
97 | fclose(fp);
|
---|
98 | /* |
---|
99 |
|
---|
100 | */
|
---|
101 |
|
---|
102 | /* next, set the date and version */
|
---|
103 |
|
---|
104 | now(dtg); /* set date and time */
|
---|
105 |
|
---|
106 | memcpy(&verstr[0], &dtg[0], 4);
|
---|
107 | memcpy(&verstr[4], &dtg[5], 2);
|
---|
108 | memcpy(&verstr[6], &dtg[8], 2);
|
---|
109 | strcpy(&verstr[8], ".01");
|
---|
110 |
|
---|
111 | if (memcmp(verbuf.ver, verstr, 8)) { /* if date is different ... */
|
---|
112 |
|
---|
113 | strcpy(verbuf.ver, verstr); /* ... it's today's 1st version */
|
---|
114 |
|
---|
115 | } else { /* ... otherwise, it's today's next version */
|
---|
116 |
|
---|
117 | vn = ((verbuf.ver[ 9] - '0') * 10) +
|
---|
118 | (verbuf.ver[10] - '0') + 1;
|
---|
119 |
|
---|
120 | if (vn GE 100) { /* too many versions today ? */
|
---|
121 |
|
---|
122 | printf("WARNING -- version number rolled over to 00.\n");
|
---|
123 | vn = 0;
|
---|
124 | }
|
---|
125 |
|
---|
126 | vp1 = vn / 10;
|
---|
127 | vp2 = vn - (vp1 * 10);
|
---|
128 |
|
---|
129 | verbuf.ver[ 9] = vp1 + '0';
|
---|
130 | verbuf.ver[10] = vp2 + '0';
|
---|
131 | }
|
---|
132 |
|
---|
133 | /* |
---|
134 |
|
---|
135 | */
|
---|
136 | /* finally, re-write the version message object file */
|
---|
137 |
|
---|
138 | if ((FILE *)NULL EQ (fp = fopenb(VERFILE, "w"))) {
|
---|
139 |
|
---|
140 | printf("ERROR -- Unable to open \"%s\" for writing (errno = %d)\n",
|
---|
141 | VERFILE, errno);
|
---|
142 |
|
---|
143 | exit(1);
|
---|
144 | }
|
---|
145 |
|
---|
146 | rewind(fp);
|
---|
147 |
|
---|
148 | if (1 NE (rc = fwrite(&verbuf, len, 1, fp))) {
|
---|
149 |
|
---|
150 | printf("ERROR -- Unable to write to \"%s\" (rc = %d, errno = %d)\n",
|
---|
151 | VERFILE, rc, errno);
|
---|
152 |
|
---|
153 | if (ferror(fp))
|
---|
154 | printf(" File system ERROR.\n");
|
---|
155 | else if (feof(fp))
|
---|
156 | printf(" Premature EOF.\n");
|
---|
157 | else
|
---|
158 | printf(" Neither ERROR or EOF set -- very odd\n");
|
---|
159 |
|
---|
160 | fclose(fp);
|
---|
161 | exit(1);
|
---|
162 | }
|
---|
163 |
|
---|
164 | fclose(fp);
|
---|
165 | printf("Current version: %s\n", verbuf.ver);
|
---|
166 | exit(0);
|
---|
167 | }
|
---|