4 * Generate AOF file containing date strings
6 * © 1994-1998 Straylight
9 /*----- Licensing note ----------------------------------------------------*
11 * This file is part of Straylight's core utilities (coreutils).
13 * Coreutils is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * Coreutils is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with coreutils. If not, write to the Free Software Foundation,
25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 /*----- Header files ------------------------------------------------------*/
39 #include "aof/chunk.h"
43 /*----- Main code ---------------------------------------------------------*/
45 static aof_file setdate_aof;
47 static int cistrcmp(const char *s1,const char *s2)
63 fprintf(stderr,"setdate: not enough memory.\n");
67 static void setdate_addSymbol(char *ident,char *format)
75 /* --- Get the current date --- */
78 _kernel_osword(14,osword);
83 if (_kernel_swi(OS_ConvertDateAndTime,&r,&r)!=0)
85 fprintf(stderr,"setdate: invalid date format.\n");
89 /* --- Translate our own magic control characters in the string --- */
117 /* --- Add the string to the AREA and give it a symbol --- */
120 aof_string(string,setdate_aof.area),
126 int main(int argc,char *argv[])
135 aof_chunkinfo obj_area={0};
136 aof_chunkinfo obj_symt={0};
137 aof_chunkinfo obj_strt={0};
138 aof_chunkinfo reloc={0};
139 aof_chunkinfo obj_head={0};
140 aof_chunkinfo obj_idfn={0};
142 pname=strrchr(argv[0],'.');
151 "Usage: %s <outfile> <identifier>[=<dateformat>]...\n",
155 else if (!cistrcmp(argv[1],"-help"))
159 "%s version 1.00 [%s]\n"
161 " © 1994 Straylight\n"
163 "Syntax: %s <outfile> <identifier>[=<dateformat>]...\n"
165 "dateformat contains literal characters and format specifiers. Format\n"
166 "specifiers consist of a '%%' sign, an optional 'z' (indicating\n"
167 "suppression of leading zero) and a two character format string, as\n"
175 " 12 12-hour style hours\n"
176 " 24 14-hour style hours\n"
177 "am/pm 'am' or 'pm' as appropriate\n"
178 " we full weekday name\n"
179 " w3 abbreviated weekday name\n"
180 " wn weekday number\n"
181 " dy day of the month\n"
182 " st suffix for day (e.g. 'st', 'nd', 'th' etc.)\n"
183 " mo full month name\n"
184 " m3 abbreviated month name\n"
186 " ce century number\n"
187 " yr year number within century\n"
188 " wk number of week in the year\n"
189 " dn number of day in the year\n"
190 " tz current time zone name\n"
191 " %% insert a literal '%%' sign\n"
193 "If no dateformat is specifed, a default of '%%zdy %%mo %%ce%%yr' is\n"
202 if (fp=fopen(argv[1],"wb"),!fp)
204 fprintf(stderr,"setdate: couldn't open output file.\n");
208 setdate_aof.area=&obj_area;
209 setdate_aof.symt=&obj_symt;
210 setdate_aof.strt=&obj_strt;
211 setdate_aof.reloc=&reloc;
213 /* --- Set up module identification --- */
215 aof_string("Straylight setdate utility 1.00",
219 /* --- Add in the AREA name --- */
221 aof_int(0,&obj_strt);
222 aof_string("SetDate$$Data",&obj_strt);
224 /* --- Create the date information in the AREA section --- */
228 format="%zDY %MO %CE%YR";
229 for (p=argv[i];*p;p++)
237 setdate_addSymbol(argv[i],format);
241 /* --- Build AOF header information --- */
243 aof_int((int)aof_RELOC,&obj_head);
244 aof_int(200,&obj_head);
245 aof_int(1,&obj_head);
246 aof_int(obj_symt.next/sizeof(aof_symbol),&obj_head);
247 aof_int(0,&obj_head);
248 aof_int(0,&obj_head);
250 aof_int(4,&obj_head);
251 aof_int(0x00002202,&obj_head);
252 aof_int(obj_area.next,&obj_head);
253 aof_int(reloc.next/8,&obj_head);
254 aof_int(0,&obj_head);
256 /* --- Add relocation stuff to AREA chunk --- */
258 aof_addBlock(reloc.p,reloc.next,&obj_area);
260 /* --- Complete string table by adding length word --- */
262 aof_fill(obj_strt.next,0,&obj_strt);
265 /* --- Write completed AOF file out to disk */
268 char _buf[sizeof(chunk_fixedHeader)+5*sizeof(chunk_tableEntry)];
269 chunk_header *h=(chunk_header *)&_buf;
271 h->hdr.id=chunk_MAGIC;
272 h->hdr.maxChunks=h->hdr.numChunks=5;
274 memcpy(h->table[0].chunkName,"OBJ_IDFN",8);
275 memcpy(h->table[1].chunkName,"OBJ_HEAD",8);
276 memcpy(h->table[2].chunkName,"OBJ_AREA",8);
277 memcpy(h->table[3].chunkName,"OBJ_SYMT",8);
278 memcpy(h->table[4].chunkName,"OBJ_STRT",8);
280 o=sizeof(chunk_fixedHeader)+5*sizeof(chunk_tableEntry);
282 h->table[0].offset=o;
283 h->table[0].size=obj_idfn.next;
286 h->table[1].offset=o;
287 h->table[1].size=obj_head.next;
290 h->table[2].offset=o;
291 h->table[2].size=obj_area.next;
294 h->table[3].offset=o;
295 h->table[3].size=obj_symt.next;
298 h->table[4].offset=o;
299 h->table[4].size=obj_strt.next;
302 fwrite(h,sizeof(chunk_fixedHeader)+5*sizeof(chunk_tableEntry),1,fp);
303 fwrite(obj_idfn.p,obj_idfn.next,1,fp);
304 fwrite(obj_head.p,obj_head.next,1,fp);
305 fwrite(obj_area.p,obj_area.next,1,fp);
306 fwrite(obj_symt.p,obj_symt.next,1,fp);
307 fwrite(obj_strt.p,obj_strt.next,1,fp);