1 /*
2  * astime is an analogue clock utility for X Windows.
3  *
4  * Copyright (c) 1998-2000  Albert Dorofeev <albert@tigr.net>
5  * Copyright (c) 1999 William Kostis <kostis@ee.cornell.edu>
6  *
7  * For the updates see http://www.tigr.net/afterstep/as-apps/
8  *
9  * This software is distributed under GPL. For details see LICENSE file.
10  */
11 
12 #include <stdio.h>
13 #include <string.h>
14 #include <stdlib.h>
15 #include <unistd.h>
16 #include "safecopy.h"
17 
18 #include "astime_x.h"
19 #include "state.h"
20 
21 extern struct astime_state state;
22 
23 /*
24  * default check and update intervals in microseconds
25  *      x11 events - every 1/100 th of a second (in mks)
26  *      update dial - every second (in sec)
27  */
28 
29 #define X11_INTERVAL    10000L
30 #define CHK_INTERVAL    1
31 
32 /*
33    #define DEBUG
34    #define P_MAPPING
35    #define P_CRON
36  */
37 
38 int withdrawn = 0;
39 int iconic = 0;
40 int pushed_in = 1;
41 int no_border = 0;
42 
43 char display_name[MAX_OPT_LEN];
44 char mainGeometry[MAX_OPT_LEN];
45 char window_name[MAX_OPT_LEN];
46 
47 int thickspec = 0;
48 int fancyhands = 0;
49 int outlinedhands = 0;
50 
51 FILE *rcf;
52 char rcfname[255];
53 char *hname;
54 
55 void parsercfile(FILE * ifp);
56 void handprops();
57 
defaults()58 void defaults()
59 {
60 	int i, j;
61 
62 	state.update_interval = CHK_INTERVAL;
63 	state.draw_seconds = 1;
64 	state.tprop = 1;
65 	state.float_seconds = 0;
66 	state.thin_seconds = 0;
67 	state.draw_date = 1;
68 	state.draw_ampm = 1;
69 	state.shift = 0;
70 	withdrawn = 0;
71 	iconic = 0;
72 	pushed_in = 1;
73 	no_border = 0;
74 
75 	state.total_size.x = state.total_size.y = 54;
76 	safecopy(window_name, "astime", MAX_OPT_LEN);
77 	safecopy(display_name, "", MAX_OPT_LEN);
78 	safecopy(mainGeometry, "", MAX_OPT_LEN);
79 	safecopy(state.bgcolor, "#385971", MAX_OPT_LEN);
80 	safecopy(state.fgcolor, "#ffffff", MAX_OPT_LEN);
81 
82 	safecopy(state.seccolor, "#efc669", MAX_OPT_LEN);
83 	safecopy(state.mincolor, "#ff3030", MAX_OPT_LEN);
84 	safecopy(state.hourcolor, "#ef3838", MAX_OPT_LEN);
85 
86 	safecopy(state.secocolor, "<>", MAX_OPT_LEN);
87 	safecopy(state.minocolor, "<>", MAX_OPT_LEN);
88 	safecopy(state.hourocolor, "<>", MAX_OPT_LEN);
89 
90 	safecopy(state.secfillcolor, "<>", MAX_OPT_LEN);
91 	safecopy(state.minfillcolor, "<>", MAX_OPT_LEN);
92 	safecopy(state.hourfillcolor, "<>", MAX_OPT_LEN);
93 
94 	safecopy(state.daycolor, "#a0a0a0", MAX_OPT_LEN);
95 	safecopy(state.ampmcolor, "#a0a0a0", MAX_OPT_LEN);
96 	safecopy(state.datecolor, "#a0a0a0", MAX_OPT_LEN);
97 
98 	/* label options */
99 	state.show_label = 0;
100 	state.label_top = 0;
101 	safecopy(state.label, "astime", 256);
102 	safecopy(state.font_name,
103 			"-*-helvetica-medium-r-*-*-9-240-*-*-*-*-*-*", 256);
104 	safecopy(state.label_color, "#a0a0a0", MAX_OPT_LEN);
105 
106 	/* clear hand rendering options */
107 	for (i = 0; i < 3; i++) {
108 		for (j = 0; j < 3; j++)
109 			state.hprop[i][j] = 0;
110 	}
111 	state.hthick = 1;
112 	state.othick = 1;
113 	state.neon = 0;
114 	state.run_program = 0;
115 	state.cron_program = 0;
116 	safecopy(state.program_name, "echo astime: No program specified.", 255);
117 
118 	state.nprogs = 0;
119 	/* state.PInf = (PInfo *) malloc(sizeof(*(state.PInf))); */
120 	state.PInf = (PInfo *) NULL;
121 }
122 
123 /* print the usage for the tool */
usage()124 void usage()
125 {
126 	printf("Usage : astime [options ...]\n\n");
127 	printf("-V               print version and exit\n");
128 	printf("-h -H -help      print this message\n");
129 	printf("-rc <filename>   resource file name\n");
130 	printf("-u <secs>        the update interval in seconds\n");
131 	printf("-exe <prog>      the program to start when clicked on\n");
132 	printf("-display <name>  the name of the display to use\n");
133 	printf("-geometry <xywh> position/size on the screen (X geometry)\n");
134 	printf("-withdrawn       start in withdrawn shape (for WindowMaker)\n");
135 	printf("-iconic          start iconized\n");
136 	printf("-standout        standing out rather than being pushed in\n");
137 	printf("-noborder        no shaded border at all, thank you very much\n");
138 	printf("-shift <hrs>     show the time with the given shift in hours\n");
139 	printf("-title <name>    set the window/icon title to this name\n");
140 	printf("-bg <color>      background color\n");
141 	printf("-fg <color>      dial foreground color\n");
142 	printf("-sec <color>     second pointer color\n");
143 	printf("-min <color>     minute pointer color\n");
144 	printf("-hour <color>    hour pointer color\n");
145 	printf("-day <color>     day of the week display color\n");
146 	printf("-ampm <color>    AM/PM display color\n");
147 	printf("-date <color>    date display color\n");
148 	printf("-ns              no second hand\n");
149 	printf("-nd              no date/day of the week\n");
150 	printf("-nap             no AM/PM indicator\n");
151 	printf("-nt              draw no ticks\n");
152 	printf("-at              draw all ticks\n");
153 	printf("-fs              use a floating second indicator\n");
154 	printf("-ts              use a thin second hand/indicator\n");
155 	printf("-fh              render fancy hands\n");
156 	printf("-nh              neon hands (nice with -fh)\n");
157 	printf("-ht <0-200>      hand thickness\n");
158 	printf("-ot <0-200>      hand outline thickness (with -fh)\n");
159 	printf("-nf              no foreground (-nd -nap -nt)\n");
160 	printf("-label <text>    show the label <text> on the clock\n");
161 	printf("-fn <name>       use the font name for the label\n");
162 	printf("-lcol <color>    color to use for the label\n");
163 	printf("-ltop            the label should go on top\n");
164 	printf("\n");
165 	exit(0);
166 }
167 
168 /* print the version of the tool */
version()169 void version()
170 {
171 	printf("astime : AfterStep analog clock version 2.8\n");
172 }
173 
174 /* parse the rc file */
parsercfile(FILE * ifp)175 void parsercfile(FILE * ifp)
176 {
177 	int i, j, ind;
178 	int tval;
179 	char *res;
180 	char line[200];
181 	char param[2][100];
182 	char *wptr;
183 	char *eptr;
184 	char sstr[8] = " \t\n";
185 
186 	while ((res = fgets(line, 200, ifp)) != NULL) {
187 
188 		if ((line[0] != '#') && (line[0] != '\n')) {
189 #ifdef DEBUG
190 			fprintf(stderr, "parsercfile: <%s>\n", line);
191 #endif
192 			wptr = strtok(line, sstr);
193 
194 			for (i = 0; i < 2; i++) {
195 				if (wptr) {
196 					if (!strcmp(wptr, "\n"))
197 						fprintf(stderr, "Warning: newline\n");
198 #ifdef DEBUG
199 					fprintf(stderr, "param[%d] will get Token (%s)\n", i, wptr);
200 #endif
201 					strcpy(param[i], wptr);
202 				} else {
203 					fprintf(stderr, "parsercfile: missing param[%d]\n", i);
204 				}
205 
206 				if ((i == 0) && !strcmp(param[0], "execProg"))
207 					wptr += 9;
208 				else if ((i == 0) && !strcmp(param[0], "at"))
209 					break;
210 				else
211 					wptr = strtok(NULL, sstr);
212 			}
213 
214 #ifdef P_MAPPING
215 			if (strcmp(param[0], "at")) {
216 				if (strlen(param[0]) > 8)
217 					fprintf(stderr, "map (%s) \t<- (%s)\n", param[0], param[1]);
218 				else
219 					fprintf(stderr, "map (%s) \t\t<- (%s)\n", param[0], param[1]);
220 			}
221 #endif
222 
223 			if (!strcmp(param[0], "geometry")) {
224 				safecopy(mainGeometry, param[1], MAX_OPT_LEN);
225 			} else if (!strcmp(param[0], "background")) {
226 				safecopy(state.bgcolor, param[1], MAX_OPT_LEN);
227 			} else if (!strcmp(param[0], "foreground")) {
228 				safecopy(state.fgcolor, param[1], MAX_OPT_LEN);
229 			} else if (!strcmp(param[0], "secondColor")) {
230 				safecopy(state.seccolor, param[1], MAX_OPT_LEN);
231 			} else if (!strcmp(param[0], "minuteColor")) {
232 				safecopy(state.mincolor, param[1], MAX_OPT_LEN);
233 			} else if (!strcmp(param[0], "hourColor")) {
234 				safecopy(state.hourcolor, param[1], MAX_OPT_LEN);
235 			} else if (!strcmp(param[0], "secondOutColor")) {
236 				safecopy(state.secocolor, param[1], MAX_OPT_LEN);
237 			} else if (!strcmp(param[0], "minuteOutColor")) {
238 				safecopy(state.minocolor, param[1], MAX_OPT_LEN);
239 			} else if (!strcmp(param[0], "hourOutColor")) {
240 				safecopy(state.hourocolor, param[1], MAX_OPT_LEN);
241 			} else if (!strcmp(param[0], "secondFillColor")) {
242 				safecopy(state.secfillcolor, param[1], MAX_OPT_LEN);
243 			} else if (!strcmp(param[0], "minuteFillColor")) {
244 				safecopy(state.minfillcolor, param[1], MAX_OPT_LEN);
245 			} else if (!strcmp(param[0], "hourFillColor")) {
246 				safecopy(state.hourfillcolor, param[1], MAX_OPT_LEN);
247 			} else if (!strcmp(param[0], "dayColor")) {
248 				safecopy(state.daycolor, param[1], MAX_OPT_LEN);
249 			} else if (!strcmp(param[0], "AMPMColor")) {
250 				safecopy(state.ampmcolor, param[1], MAX_OPT_LEN);
251 			} else if (!strcmp(param[0], "dateColor")) {
252 				safecopy(state.datecolor, param[1], MAX_OPT_LEN);
253 			} else if (!strcmp(param[0], "Label")) {
254 				state.show_label = 1;
255 				safecopy(state.label, param[1], 256);
256 			} else if (!strcmp(param[0], "Font")) {
257 				safecopy(state.font_name, param[1], 256);
258 			} else if (!strcmp(param[0], "LabelColor")) {
259 				safecopy(state.label_color, param[1], MAX_OPT_LEN);
260 			} else if (!strcmp(param[0], "LabelTop")) {
261 				tval = atoi(param[1]);
262 				if (tval == 0)
263 					state.label_top = 0;
264 				else
265 					state.label_top = 1;
266 			} else if (!strcmp(param[0], "drawSecondHand")) {
267 				tval = atoi(param[1]);
268 				if (tval == 0)
269 					state.draw_seconds = 0;
270 				else
271 					state.draw_seconds = 1;
272 			} else if (!strcmp(param[0], "drawDayDate")) {
273 				tval = atoi(param[1]);
274 				if (tval == 0)
275 					state.draw_date = 0;
276 			} else if (!strcmp(param[0], "drawAMPM")) {
277 				tval = atoi(param[1]);
278 				if (tval == 0)
279 					state.draw_ampm = 0;
280 			} else if (!strcmp(param[0], "drawTicks")) {
281 				tval = atoi(param[1]);
282 				if (tval == 0)
283 					state.tprop = 0;
284 			} else if (!strcmp(param[0], "drawAllTicks")) {
285 				tval = atoi(param[1]);
286 				if ((state.tprop) && (tval == 1))
287 					state.tprop = 2;
288 			} else if (!strcmp(param[0], "drawForeground")) {
289 				tval = atoi(param[1]);
290 				if (tval == 0) {
291 					state.draw_date = 0;
292 					state.draw_ampm = 0;
293 					state.tprop = 0;
294 				}
295 			} else if (!strcmp(param[0], "floatSeconds")) {
296 				tval = atoi(param[1]);
297 				if (tval)
298 					state.float_seconds = atoi(param[1]);
299 			} else if (!strcmp(param[0], "thinSeconds")) {
300 				tval = atoi(param[1]);
301 				if (tval)
302 					state.thin_seconds = atoi(param[1]);
303 			} else if (!strcmp(param[0], "handThickness")) {
304 				state.hthick = atoi(param[1]);
305 				thickspec = 1;
306 			} else if (!strcmp(param[0], "outThickness")) {
307 				state.othick = atoi(param[1]);
308 			} else if (!strcmp(param[0], "fancyHands")) {
309 				tval = atoi(param[1]);
310 				if (tval) {
311 					fancyhands = 1;
312 					if (!thickspec)
313 						state.hthick = 5;
314 				}
315 			} else if (!strcmp(param[0], "outlinedHands")) {
316 				tval = atoi(param[1]);
317 				if (tval)
318 					outlinedhands = 1;
319 			} else if (!strcmp(param[0], "neonHands")) {
320 				tval = atoi(param[1]);
321 				if (tval)
322 					state.neon = 1;
323 			} else if (!strcmp(param[0], "execProg")) {
324 				eptr = strchr(param[1], '"');
325 				if (eptr != NULL) {
326 					eptr += 1;
327 					safecopy(state.program_name, eptr, strlen(eptr) - 1);
328 					state.run_program = 1;
329 #ifdef P_MAPPING
330 					fprintf(stderr, "exec : <%s>\n", state.program_name);
331 #endif
332 				} else
333 					fprintf(stderr, "astime: executables must be double-quoted in astimerc file, ignoring...\n");
334 			} else if (!strcmp(param[0], "at")) {
335 				ind = state.nprogs;
336 				state.nprogs += 1;
337 				state.PInf = (PInfo *) realloc(state.PInf, state.nprogs * sizeof(*(state.PInf)));
338 				if (state.PInf == NULL) {
339 					fprintf(stderr, "astime: memory reallocation error, exiting\n");
340 					exit(1);
341 				}
342 				state.PInf[ind] = (PInfo) malloc(sizeof(**(state.PInf)));
343 				if (state.PInf[ind] == NULL) {
344 					fprintf(stderr, "astime: memory reallocation error, exiting\n");
345 					exit(1);
346 				}
347 				for (j = 0; j < 3; j++) {
348 					wptr = strtok(NULL, " :");
349 					tval = atoi(wptr);
350 #ifdef DEBUG
351 					fprintf(stderr, "map (state.PInf[%d]->time[%d]) <- %d <%s>\n", ind, j, tval, wptr);
352 #endif
353 					state.PInf[ind]->time[j] = tval;
354 				}
355 
356 				wptr += 3;
357 				eptr = strchr(wptr, '"');
358 
359 				if (eptr != NULL) {
360 					eptr += 1;
361 					safecopy(state.PInf[ind]->name, eptr, strlen(eptr) - 1);
362 					state.PInf[ind]->done = 0;
363 					state.cron_program = 1;
364 #ifdef P_CRON
365 					fprintf(stderr, "cron[%d] : %02d:%02d:%02d : <%s>\n",
366 						ind, state.PInf[ind]->time[0], state.PInf[ind]->time[1],
367 						state.PInf[ind]->time[2], state.PInf[ind]->name);
368 #endif
369 				} else
370 					fprintf(stderr, "astime: executables must be double-quoted in astimerc file, ignoring...\n");
371 			} else if (!strcmp(param[0], "withdrawn")) {
372 				tval = atoi(param[1]);
373 				if (tval)
374 					withdrawn = 1;
375 			} else if (!strcmp(param[0], "iconic")) {
376 				tval = atoi(param[1]);
377 				if (tval)
378 					iconic = 1;
379 			} else if (!strcmp(param[0], "standout")) {
380 				tval = atoi(param[1]);
381 				if (tval)
382 					pushed_in = 0;
383 			} else if (!strcmp(param[0], "noborder")) {
384 				tval = atoi(param[1]);
385 				if (tval)
386 					no_border = 1;
387 			} else if (!strcmp(param[0], "shift")) {
388 				state.shift = atoi(param[1]);
389 				if ((state.shift > 23) || (state.shift < -23))
390 					state.shift = 0;
391 			} else if (!strcmp(param[0], "title")) {
392 				safecopy(window_name, param[1], MAX_OPT_LEN);
393 			} else {
394 				fprintf(stderr, "astime: error in astimerc file, ignoring...\n");
395 			}
396 		}
397 	}
398 }
399 
parsecmdline(int argc,char * argv[])400 void parsecmdline(int argc, char *argv[])
401 {
402 	char *argument;
403 	int i;
404 
405 	/* parse the command line */
406 	for (i = 1; i < argc; i++) {
407 		argument = argv[i];
408 		if (argument[0] == '-') {
409 			if (!strncmp(argument, "-rc", 3)) {
410 				// just skip it
411 				if (++i >= argc)
412 					usage();
413 			} else if (!strncmp(argument, "-withdrawn", 10)) {
414 				withdrawn = 1;
415 			} else if (!strncmp(argument, "-iconic", 7)) {
416 				iconic = 1;
417 			} else if (!strncmp(argument, "-standout", 9)) {
418 				pushed_in = 0;
419 			} else if (!strncmp(argument, "-noborder", 9)) {
420 				no_border = 1;
421 			} else if (!strncmp(argument, "-u", 2)) {
422 				if (++i >= argc)
423 					usage();
424 				state.update_interval = atoi(argv[i]);
425 				if (state.update_interval < 1)
426 					state.update_interval = CHK_INTERVAL;
427 			} else if (!strncmp(argument, "-shift", 6)) {
428 				if (++i >= argc)
429 					usage();
430 				state.shift = atoi(argv[i]);
431 				if ((state.shift > 23) || (state.shift < -23))
432 					state.shift = 0;
433 			} else if (!strncmp(argument, "-ns", 3)) {
434 				state.draw_seconds = 0;
435 			} else if (!strncmp(argument, "-nd", 3)) {
436 				state.draw_date = 0;
437 			} else if (!strncmp(argument, "-nap", 4)) {
438 				state.draw_ampm = 0;
439 			} else if (!strncmp(argument, "-geometry", 9)) {
440 				if (++i >= argc)
441 					usage();
442 				safecopy(mainGeometry, argv[i], MAX_OPT_LEN);
443 			} else if (!strncmp(argument, "-title", 6)) {
444 				if (++i >= argc)
445 					usage();
446 				safecopy(window_name, argv[i], MAX_OPT_LEN);
447 			} else if (!strncmp(argument, "-display", 8)) {
448 				if (++i >= argc)
449 					usage();
450 				safecopy(display_name, argv[i], MAX_OPT_LEN);
451 			} else if (!strncmp(argument, "-bg", 3)) {
452 				if (++i >= argc)
453 					usage();
454 				safecopy(state.bgcolor, argv[i], MAX_OPT_LEN);
455 			} else if (!strncmp(argument, "-fg", 3)) {
456 				if (++i >= argc)
457 					usage();
458 				safecopy(state.fgcolor, argv[i], MAX_OPT_LEN);
459 			} else if (!strncmp(argument, "-label", 6)) {
460 				if (++i >= argc)
461 					usage();
462 				state.show_label = 1;
463 				safecopy(state.label, argv[i], 256);
464 			} else if (!strncmp(argument, "-fn", 3)) {
465 				if (++i >= argc)
466 					usage();
467 				safecopy(state.font_name, argv[i], 256);
468 			} else if (!strncmp(argument, "-lcolor", 3)) {
469 				if (++i >= argc)
470 					usage();
471 				safecopy(state.label_color, argv[i], MAX_OPT_LEN);
472 			} else if (!strncmp(argument, "-ltop", 4)) {
473 				state.label_top = 1;
474 			} else if (!strncmp(argument, "-sec", 4)) {
475 				if (++i >= argc)
476 					usage();
477 				safecopy(state.seccolor, argv[i], MAX_OPT_LEN);
478 			} else if (!strncmp(argument, "-min", 4)) {
479 				if (++i >= argc)
480 					usage();
481 				safecopy(state.mincolor, argv[i], MAX_OPT_LEN);
482 			} else if (!strncmp(argument, "-hour", 5)) {
483 				if (++i >= argc)
484 					usage();
485 				safecopy(state.hourcolor, argv[i], MAX_OPT_LEN);
486 			} else if (!strncmp(argument, "-day", 4)) {
487 				if (++i >= argc)
488 					usage();
489 				safecopy(state.daycolor, argv[i], MAX_OPT_LEN);
490 			} else if (!strncmp(argument, "-ampm", 5)) {
491 				if (++i >= argc)
492 					usage();
493 				safecopy(state.ampmcolor, argv[i], MAX_OPT_LEN);
494 			} else if (!strncmp(argument, "-date", 5)) {
495 				if (++i >= argc)
496 					usage();
497 				safecopy(state.datecolor, argv[i], MAX_OPT_LEN);
498 			} else if (!strncmp(argument, "-exe", 4)) {
499 				if (++i >= argc)
500 					usage();
501 				safecopy(state.program_name, argv[i], 255);
502 				state.run_program = 1;
503 			} else if (!strncmp(argument, "-at", 3)) {
504 				state.tprop = 2;
505 			} else if (!strncmp(argument, "-nt", 3)) {
506 				state.tprop = 0;
507 			} else if (!strncmp(argument, "-fs", 3)) {
508 				state.float_seconds = 1;
509 			} else if (!strncmp(argument, "-ts", 3)) {
510 				state.thin_seconds = 1;
511 			} else if (!strncmp(argument, "-ht", 3)) {
512 				if (++i >= argc)
513 					usage();
514 				state.hthick = atoi(argv[i]);
515 				thickspec = 1;
516 			} else if (!strncmp(argument, "-ot", 3)) {
517 				if (++i >= argc)
518 					usage();
519 				state.othick = atoi(argv[i]);
520 			} else if (!strncmp(argument, "-fh", 3)) {
521 				fancyhands = 1;
522 				if (!thickspec)
523 					state.hthick = 5;
524 			} else if (!strncmp(argument, "-oh", 3)) {
525 				outlinedhands = 1;
526 			} else if (!strncmp(argument, "-nh", 3)) {
527 				state.neon = 1;
528 			} else if (!strncmp(argument, "-nf", 3)) {
529 				state.draw_date = 0;
530 				state.draw_ampm = 0;
531 				state.tprop = 0;
532 			} else if (!strncmp(argument, "-V", 2)) {
533 				version();
534 				exit(0);
535 			} else if (!strncmp(argument, "-H", 2)) {
536 				version();
537 				usage();
538 			} else if (!strncmp(argument, "-h", 2)) {
539 				version();
540 				usage();
541 			} else {
542 				version();
543 				usage();
544 			}
545 		} else {
546 			version();
547 			usage();
548 		}
549 	}
550 }
551 
552 
handprops()553 void handprops()
554 {
555 	/* set hand rendering options */
556 	if (outlinedhands) {
557 		state.hprop[PSEC][HOLINE] = 1;
558 		state.hprop[PMIN][HOLINE] = 1;
559 		state.hprop[PHOUR][HOLINE] = 1;
560 	} else if (fancyhands) {
561 		state.hprop[PSEC][HOLINE] = 1;
562 		state.hprop[PSEC][HFILL] = 1;
563 		state.hprop[PMIN][HOLINE] = 1;
564 		state.hprop[PMIN][HFILL] = 1;
565 		state.hprop[PHOUR][HOLINE] = 1;
566 		state.hprop[PHOUR][HFILL] = 1;
567 	} else {
568 		state.hprop[PSEC][HCLINE] = 1;
569 		state.hprop[PMIN][HCLINE] = 1;
570 		state.hprop[PHOUR][HCLINE] = 1;
571 	}
572 
573 	if (state.thin_seconds) {
574 		state.hprop[PSEC][HOLINE] = 0;
575 		state.hprop[PSEC][HFILL] = 0;
576 		state.hprop[PSEC][HCLINE] = 1;
577 	}
578 }
579 
580 
main(int argc,char ** argv)581 int main(int argc, char **argv)
582 {
583 	int i;
584 	int rcfound;
585 
586 	defaults();
587 
588 	/*
589 	 * Check if there is a resource file name
590 	 * specified on the command line. That file
591 	 * takes precedence over ~/.astimerc
592 	 */
593 	rcfound = 0;
594 	for (i=1; i<argc; i++) {
595 		if ( !strncmp(argv[i], "-rc", 3) ) {
596 			if (++i >= argc)
597 				usage();
598 			safecopy(rcfname, argv[i], 255);
599 			rcfound = 1;
600 		}
601 	}
602 	if ( ! rcfound ) {
603 		hname = getenv("HOME");
604 		strcpy(rcfname, hname);
605 		if (rcfname[strlen(rcfname) - 1] != '/')
606 			strcat(rcfname, "/");
607 
608 		strcat(rcfname, ".astimerc");
609 #ifdef DEBUG
610 		fprintf(stderr, "hname is %s\n", hname);
611 		fprintf(stderr, "rcfname is %s\n", rcfname);
612 #endif
613 	}
614 
615 	rcf = fopen(rcfname, "r");
616 	if (rcf != NULL) {
617 		parsercfile(rcf);
618 		fclose(rcf);
619 	} else {
620 		if ( rcfound )
621 			fprintf(stderr, "astime: could not open %s ...\n",
622 					rcfname);
623 	}
624 
625 	parsecmdline(argc, argv);
626 
627 	handprops();
628 
629 	initialize(argc, argv,
630 		   window_name,
631 		   display_name,
632 		   mainGeometry,
633 		   withdrawn,
634 		   iconic,
635 		   pushed_in,
636 		   no_border);
637 	while (1) {
638 		update();
639 		usleep(X11_INTERVAL);
640 	}
641 	return (0);
642 }
643