source: buchla-68k/orig/DOC/NEWVER.TXT@ 0170798

Last change on this file since 0170798 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 20.4 KB
Line 
1
2
3 1988-10-28 20:08:06 -- Page 1: NEWVER.C
4
5
6 1 /*
7 2 =============================================================================
8 3 newver.c -- read and update a GEMDOS version message object file
9 4 Version 1 -- 1988-10-28 -- D.N. Lynx Crowe
10 5 (c) Copyright 1988 -- D.N. Lynx Crowe -- All rights reserved
11 6
12 7 Compiled and linked with the GEMDOS Alcyon C developer's package.
13 8
14 9 NOTE: Because we use the Alcyon GEMDOS object file format,
15 10 which is specific to the Atari, this code is NON-PORTABLE.
16 11
17 12 The idea, however, is adaptable to a wide variety of systems
18 13 and object file formats.
19 14
20 15 Note also that the fopen() function in the Alcyon C library does not
21 16 support the "r+" option, making it necessary to close the file and
22 17 then open it again before writing. This is a serious shortcoming of
23 18 the Alcyon C library, as it makes updating files only possible by a
24 19 series of questionable maneuvers, (e.g. opening, closing, and reopening
25 20 the file, or using open(), then fdopen(), etc.).
26 21 =============================================================================
27 22 */
28 23
29 24 #include "stdio.h" /* Atari GEMDOS standard I/O definitions */
30 25 #include "stddefs.h" /* some usefull standard C definitions */
31 26 #include "objdefs.h" /* GEMDOS object file definitions */
32 27
33 28 #define VERFILE "verdate.o" /* version message file */
34 29
35 30 extern int errno; /* system error code */
36 31
37 32 extern char *now(); /* get formatted system date and time */
38 33
39 34 FILE *fp; /* VERFILE file pointer */
40 35
41 36 /* 000000000011111111112 */
42 37 /* 012345678901234567890 */
43 38 char dtg[22]; /* yyyy-mm-dd hh:mm:ss zero terminated string */
44 39
45 40 /* 000000000011 */
46 41 /* 012345678901 */
47 42 char verstr[12]; /* yyyymmdd.vv zero terminated string */
48 43
49 44 struct vb { /* VERFILE buffer (66 bytes) */
50 45
51 46 struct EXFILE hdr;
52 47 char ver[12];
53 48 struct SYMBOL sym;
54 49 char rem[12];
55 50
56 51 } verbuf;
57 52
58 53 /*
59
60
61 1988-10-28 20:08:06 -- Page 2: NEWVER.C
62
63
64 54
65 55 */
66 56
67 57 /*
68 58 =============================================================================
69 59 read and update an Alcyon/GEMDOS format version message object file
70 60 =============================================================================
71 61 */
72 62
73 63 main()
74 64 {
75 65 short len, rc, vn, vp1, vp2;
76 66
77 67 len = sizeof verbuf;
78 68
79 69 /* first, read the old version message object file */
80 70
81 71 if ((FILE *)NULL EQ (fp = fopenb(VERFILE, "r"))) {
82 72
83 73 printf("ERROR -- Unable to open \"%s\" for reading (errno = %d)\n",
84 74 VERFILE, errno);
85 75
86 76 exit(1);
87 77 }
88 78
89 79 rewind(fp);
90 80
91 81 if (1 NE (rc = fread(&verbuf, len, 1, fp))) {
92 82
93 83 printf("ERROR -- Unable to read \"%s\" (rc = %d, errno = %d)\n",
94 84 VERFILE, rc, errno);
95 85
96 86 if (ferror(fp))
97 87 printf(" File system ERROR.\n");
98 88 else if (feof(fp))
99 89 printf(" Premature EOF.\n");
100 90 else
101 91 printf(" Neither ERROR or EOF set -- very odd\n");
102 92
103 93 fclose(fp);
104 94 exit(1);
105 95 }
106 96
107 97 fclose(fp);
108 98 /*
109
110
111 1988-10-28 20:08:06 -- Page 3: NEWVER.C
112
113
114 99
115 100 */
116 101
117 102 /* next, set the date and version */
118 103
119 104 now(dtg); /* set date and time */
120 105
121 106 memcpy(&verstr[0], &dtg[0], 4);
122 107 memcpy(&verstr[4], &dtg[5], 2);
123 108 memcpy(&verstr[6], &dtg[8], 2);
124 109 strcpy(&verstr[8], ".01");
125 110
126 111 if (memcmp(verbuf.ver, verstr, 8)) { /* if date is different ... */
127 112
128 113 strcpy(verbuf.ver, verstr); /* ... it's today's 1st version */
129 114
130 115 } else { /* ... otherwise, it's today's next version */
131 116
132 117 vn = ((verbuf.ver[ 9] - '0') * 10) +
133 118 (verbuf.ver[10] - '0') + 1;
134 119
135 120 if (vn GE 100) { /* too many versions today ? */
136 121
137 122 printf("WARNING -- version number rolled over to 00.\n");
138 123 vn = 0;
139 124 }
140 125
141 126 vp1 = vn / 10;
142 127 vp2 = vn - (vp1 * 10);
143 128
144 129 verbuf.ver[ 9] = vp1 + '0';
145 130 verbuf.ver[10] = vp2 + '0';
146 131 }
147 132
148 133 /*
149
150
151 1988-10-28 20:08:06 -- Page 4: NEWVER.C
152
153
154 134
155 135 */
156 136 /* finally, re-write the version message object file */
157 137
158 138 if ((FILE *)NULL EQ (fp = fopenb(VERFILE, "w"))) {
159 139
160 140 printf("ERROR -- Unable to open \"%s\" for writing (errno = %d)\n",
161 141 VERFILE, errno);
162 142
163 143 exit(1);
164 144 }
165 145
166 146 rewind(fp);
167 147
168 148 if (1 NE (rc = fwrite(&verbuf, len, 1, fp))) {
169 149
170 150 printf("ERROR -- Unable to write to \"%s\" (rc = %d, errno = %d)\n",
171 151 VERFILE, rc, errno);
172 152
173 153 if (ferror(fp))
174 154 printf(" File system ERROR.\n");
175 155 else if (feof(fp))
176 156 printf(" Premature EOF.\n");
177 157 else
178 158 printf(" Neither ERROR or EOF set -- very odd\n");
179 159
180 160 fclose(fp);
181 161 exit(1);
182 162 }
183 163
184 164 fclose(fp);
185 165 printf("Current version: %s\n", verbuf.ver);
186 166 exit(0);
187 167 }
188
189
190
191 1988-10-28 20:08:42 -- Page 1: NOW.C
192
193
194 1 /*
195 2 =============================================================================
196 3 now.c -- return the date and time as a string
197 4 Version 2 -- 1988-10-28 -- D.N. Lynx Crowe
198 5 (c) Copyright 1987, 1988 -- D.N. Lynx Crowe
199 6 =============================================================================
200 7 */
201 8
202 9 #define TESTER 0 /* define non-zero to get a test program */
203 10
204 11 #include "osbind.h"
205 12
206 13 /*
207 14 =============================================================================
208 15 now(p) -- return the date and time as a string in 'p'
209 16
210 17 Returns a pointer to the string provided, which must be at least
211 18 21 bytes long. The string will be filled with the date and time
212 19 in the format:
213 20
214 21 yyyy-mm-dd hh:mm:ss
215 22
216 23 with a trailing zero byte.
217 24 =============================================================================
218 25 */
219 26
220 27 char *
221 28 now(p)
222 29 char *p;
223 30 {
224 31 register long t;
225 32 short yr, mn, dy, hh, mm, ss;
226 33
227 34 t = Gettime();
228 35
229 36 yr = ((short)(t >> 25) & 0x007F) + 1980;
230 37 mn = (short)(t >> 21) & 0x000F;
231 38 dy = (short)(t >> 16) & 0x001F;
232 39
233 40 hh = (short)(t >> 11) & 0x001F;
234 41 mm = (short)(t >> 5) & 0x003F;
235 42 ss = ((short)t & 0x001F) << 1;
236 43
237 44 sprintf(p, "%4d-%02d-%02d %02d:%02d:%02d", yr, mn, dy, hh, mm, ss);
238 45
239 46 return(p);
240 47 }
241 48
242 49 /*
243
244
245 1988-10-28 20:08:42 -- Page 2: NOW.C
246
247
248 50
249 51 */
250 52
251 53 #if TESTER
252 54
253 55 char x[22]; /* buffer for the returned string */
254 56
255 57 /* simple test program for the now() function */
256 58
257 59 main()
258 60 {
259 61 printf("Date/Time = %s\n", now(x));
260 62 exit(0);
261 63 }
262 64
263 65 #endif
264
265
266{c}AS68 -s c:\bin\ -l -p verdate.s
267
268C P / M 6 8 0 0 0 A s s e m b l e r Revision 04.03 Page 1
269Source File: VERDATE.S
270
271 1 * ------------------------------------------------------------------------------
272 2 * verdate.s -- date and version ID message string
273 3 * Version 1 -- 1988-10-28 -- D.N. Lynx Crowe
274 4 * (c) Copyright 1988 -- D.N. Lynx Crowe -- All rights reserved
275 5 * ------------------------------------------------------------------------------
276 6 *
277 7 * Version message string. Updated by 'newver.c' in object form to:
278 8 *
279 9 * 1. Automatically set the correct date and version
280 10 * 2. Avoid the need for a compile or assembly
281 11 *
282 12 * 12 bytes -- 11 ASCII characters and a terminating zero byte
283 13 *
284 14 * char VerDate = "yyyymmdd.vv";
285 15 * 0 byte
286 16 * 0 1
287 17 * 012345678901
288 18 *
289 19 * Use &VerDate[2] for yymmdd.vv format.
290 20 *
291 21 00000000 .data
292 22 *
293 23 .xdef _VerDate
294 24 *
295 25 00000000 3139383831303237 _VerDate: dc.b '19881027.01' * Date and version number
296 25 00000008 2E3031
297 26 0000000B 00 dc.b 0
298 27 *
299 28 0000000C .end
300
301C P / M 6 8 0 0 0 A s s e m b l e r Revision 04.03 Page 2
302Source File: VERDATE.S
303
304S y m b o l T a b l e
305
306_VerDate 00000000 DATA
307
308
309
310 1988-10-28 20:11:32 -- Page 1: STDDEFS.H
311
312
313 1 /*
314 2 ============================================================================
315 3 stddefs.h -- Standard definitions for C programs
316 4 Version 12 -- 1987-12-15 -- D.N. Lynx Crowe
317 5
318 6 Must follow stdio.h if stdio.h is used as both define:
319 7
320 8 NULL, EOF.
321 9
322 10 Must follow define.h on the Atari if define.h is used as both define:
323 11
324 12 NULL, EOF, FOREVER, TRUE, FALSE, FAILURE, SUCCESS,
325 13 YES, NO, EOS, NIL.
326 14
327 15 Released to Public Domain - 1987-06 - D.N. Lynx Crowe
328 16 ============================================================================
329 17 */
330 18
331 19 #ifndef STD_DEFS /* so we only define these once */
332 20
333 21 #define STD_DEFS 1
334 22
335 23 /* relational operators */
336 24
337 25 #define EQ ==
338 26 #define NE !=
339 27 #define GE >=
340 28 #define LE <=
341 29 #define GT >
342 30 #define LT <
343 31
344 32 /* logical operators */
345 33
346 34 #define NOT !
347 35 #define AND &&
348 36 #define OR ||
349 37
350 38 /* infinite loop constructs */
351 39
352 40 #ifndef FOREVER
353 41 #define FOREVER for(;;)
354 42 #endif
355 43
356 44 #ifndef REPEAT
357 45 #define REPEAT for(;;)
358 46 #endif
359 47
360 48 /*
361
362
363 1988-10-28 20:11:32 -- Page 2: STDDEFS.H
364
365
366 49
367 50 */
368 51
369 52 /* various terminators */
370 53
371 54 #ifndef EOF
372 55 #define EOF (-1)
373 56 #endif
374 57
375 58 #ifndef EOS
376 59 #define EOS '\0'
377 60 #endif
378 61
379 62 #ifndef NIL
380 63 #define NIL 0
381 64 #endif
382 65
383 66 /* manifest constants for function return and flag values */
384 67
385 68 #ifndef NULL
386 69 #define NULL 0
387 70 #endif
388 71
389 72 #ifndef YES
390 73 #define YES 1
391 74 #endif
392 75
393 76 #ifndef NO
394 77 #define NO 0
395 78 #endif
396 79
397 80 #ifndef FALSE
398 81 #define FALSE 0
399 82 #endif
400 83
401 84 #ifndef TRUE
402 85 #define TRUE 1
403 86 #endif
404 87
405 88 #ifndef SUCCESS
406 89 #define SUCCESS 0
407 90 #endif
408 91
409 92 #ifndef FAILURE
410 93 #define FAILURE (-1)
411 94 #endif
412 95
413 96 /* BOOL type definition for flag variables */
414 97
415 98 typedef char BOOL;
416 99
417 100 #endif
418
419
420
421 1988-10-28 20:11:32 -- Page 1: OBJDEFS.H
422
423
424 1 /*
425 2 ============================================================================
426 3 objdefs.h -- Object file format for as68 (Atari 1040ST TOS objects)
427 4 Version 7 -- 1987-12-30 -- D.N. Lynx Crowe
428 5 ============================================================================
429 6 */
430 7
431 8 struct EXFILE { /* executable file header */
432 9
433 10 unsigned F_Magic; /* File type magic */
434 11 long F_Text; /* SIze of text segment */
435 12 long F_Data; /* Size of data segment */
436 13 long F_BSS; /* Size of BSS segment */
437 14 long F_Symtab; /* Size of symbol table */
438 15 long F_Res1; /* Reserved area #1 */
439 16 long F_Res2; /* Reserved area #2 -- text origin */
440 17 unsigned F_Res3; /* Reserved area #3 -- flag word */
441 18
442 19 /* data origin - long */
443 20 /* bss origin - long */
444 21 };
445 22
446 23 #define F_R_C 0x601A /* Magic for contiguous file */
447 24 #define F_R_D 0x601B /* Magic for discontiguous file */
448 25
449 26 struct SYMBOL { /* Symbol table entry -- 14 bytes */
450 27
451 28 char symname[8]; /* Symbol name (LJZF) */
452 29 unsigned symtype; /* Symbol type flags */
453 30 long symvalue; /* Symbol value */
454 31 };
455 32
456 33 #define S_Def 0x8000 /* Defined */
457 34 #define S_Equ 0x4000 /* Equated */
458 35 #define S_Glb 0x2000 /* Global */
459 36 #define S_Reg 0x1000 /* Equated register */
460 37 #define S_Ext 0x0800 /* External reference */
461 38 #define S_Data 0x0400 /* Data based relocatable */
462 39 #define S_Text 0x0200 /* Text based relocatable */
463 40 #define S_BSS 0x0100 /* BSS based relocatable */
464
465
466Directory of C:\CPROGS
467
468VERDATE.O 10/28/88 20:10:12 000 66
469Done.
470
471================================================================================
472
473Dump of: verdate.o
474
4750000 00 (000000): 601A 0000 0000 0000 000C 0000 0000 0000 *`...............*
4760000 10 (000010): 000E 0000 0000 0000 0000 0000 3139 3838 *............1988*
4770000 20 (000020): 3130 3237 2E30 3100 5F56 6572 4461 7465 *1027.01._VerDate*
4780000 30 (000030): A400 0000 0000 0000 0000 0000 0000 0000 *$...............*
4790000 40 (000040): 0000 0000 0000 0000 0000 0000 0000 0000 *................*
480
481*** E O F ***
482
483================================================================================
484
485Sample C program usage:
486-----------------------
487
488 #define PGMID "test" /* program name, since argv[0] isn't */
489
490 extern char now(); /* get system date and time as a string */
491
492 extern char VerDate[]; /* program date and version string */
493
494 char dtg[22]; /* today's date and time */
495
496 main(argc, argv)
497 int argc;
498 char *argv[];
499 {
500 /* identify the program and version */
501
502 printf("%s -- Version %s\n",
503 PGMID, VerDate);
504
505 /* log the run date and time */
506
507 printf("Run date and time: %s\n",
508 now(dtg));
509
510 /* ***** program goes here ***** */
511
512 exit(0);
513 }
514
515
Note: See TracBrowser for help on using the repository browser.