1 /* -*- Mode: C; fill-column: 79 -*- *******************************************
2 *******************************************************************************
3 pclock -- a simple analog clock program for the X Window System
4 Copyright (C) 1998 Alexander Kourakos
5 Time-stamp: <1998-05-28 20:48:08 awk@oxygene.vnet.net>
7 This program is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free Software
9 Foundation; either version 2 of the License, or (at your option) any later
12 This program is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc.,
18 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 Author: Alexander Kourakos <Alexander@Kourakos.com>
21 Web: http://www.kourakos.com/~awk/pclock/
22 *******************************************************************************
23 ******************************************************************************/
35 /*****************************************************************************/
38 static char program_path
[STRING_LENGTH
];
40 /*****************************************************************************/
42 static void Version(void);
43 static void Usage(void);
44 static void SetOptions(int, char *[]);
45 static void StringCopy(char *, const char *);
47 /*****************************************************************************/
50 main(int argc
, char *argv
[])
55 StringCopy(program_path
, argv
[0]);
56 SetOptions(argc
, argv
);
58 CreateWindow(argc
, argv
);
63 gettimeofday(&tv
, NULL
);
64 usleep(PERIOD
- tv
.tv_usec
%PERIOD
);
72 /*****************************************************************************/
77 printf("This is " NAME
" " VERSION
"\n");
78 printf("Copyright (C) 1999-2000 Alexander Kourakos\n");
81 /*****************************************************************************/
90 printf("Usage: %s [OPTIONS]\n", program_path
);
91 printf("OPTIONS may be zero or more of the following options.\n");
95 printf(" -B, --background=PIXMAP "
96 "use the given pixmap as the clock background\n"
98 "(size must be %dx%d)\n", SIZE
, SIZE
);
100 printf(" -H, --hands-color=COLOR "
101 "draw the hour and minute hands (and the second\n"
103 "hand, if -S is not also specified) in the\n"
105 "specified color\n");
107 printf(" --hands-width=INT "
108 "draw the hour and minute hands with the\n"
110 "specified width\n");
112 printf(" -h, --help "
113 "display this help and exit\n");
115 printf(" --hour-hand-length=INT "
116 "draw the hour hand with the specified length\n");
118 printf(" --minute-hand-length=INT "
119 "draw the minute hand with the specified length\n");
121 printf(" -S, --second-hand-color=COLOR "
122 "draw the second hand in the specified color\n");
124 printf(" --second-hand-length=INT "
125 "draw the second hand with the specified length\n");
127 printf(" --second-hand-width=INT "
128 "draw the second hand with the specified width\n");
130 printf(" -s, --second-hand "
131 "%sdisplay the second hand\n",
132 SHOW_SECONDS
? "don't " : "");
134 printf(" -v, --version "
135 "display the version and exit\n");
137 printf(" -w, --withdrawn "
138 "%sstart up in a withdrawn state\n",
139 UNDER_WINDOWMAKER
? "don't " : "");
143 printf("Author: Alexander Kourakos <Alexander@Kourakos.com>\n");
144 printf(" Web: http://www.kourakos.com/~awk/pclock/\n");
147 /*****************************************************************************/
150 SetOptions(int ac
, char *av
[])
152 #define OPT_HANDS_WIDTH 0x100
153 #define OPT_SECOND_HAND_WIDTH 0x101
154 #define OPT_HOUR_HAND_LENGTH 0x102
155 #define OPT_MINUTE_HAND_LENGTH 0x103
156 #define OPT_SECOND_HAND_LENGTH 0x104
158 int opt_index
= 0, o
;
159 static char *short_opts
= "B:H:hS:svw";
160 static struct option long_opts
[] =
162 {"background", 1, 0, 'B'},
163 {"hands-color", 1, 0, 'H'},
164 {"hands-width", 1, 0, OPT_HANDS_WIDTH
},
166 {"hour-hand-length", 1, 0, OPT_HOUR_HAND_LENGTH
},
167 {"minute-hand-length", 1, 0, OPT_MINUTE_HAND_LENGTH
},
168 {"second-hand-color", 1, 0, 'S'},
169 {"second-hand-length", 1, 0, OPT_SECOND_HAND_LENGTH
},
170 {"second-hand-width", 1, 0, OPT_SECOND_HAND_WIDTH
},
171 {"second-hand", 0, 0, 's'},
172 {"version", 0, 0, 'v'},
173 {"withdrawn", 0, 0, 'w'},
178 * Begin by setting the default options (defined in Defaults.h).
181 option
.under_windowmaker
= UNDER_WINDOWMAKER
;
182 option
.show_seconds
= SHOW_SECONDS
;
183 option
.hand_width
= HAND_WIDTH
;
184 option
.second_hand_width
= SECOND_HAND_WIDTH
;
185 option
.hour_hand_length
= HOUR_HAND_LENGTH
;
186 option
.minute_hand_length
= MINUTE_HAND_LENGTH
;
187 option
.second_hand_length
= SECOND_HAND_LENGTH
;
188 StringCopy(option
.hand_color
, HAND_COLOR
);
189 StringCopy(option
.second_hand_color
, SECOND_HAND_COLOR
);
190 option
.background_pixmap
[0] = '\0';
193 * Loop through the user-provided options.
196 while ((o
= getopt_long(ac
, av
, short_opts
, long_opts
, &opt_index
)) != EOF
) {
199 StringCopy(option
.background_pixmap
, optarg
);
203 StringCopy(option
.hand_color
, optarg
);
204 StringCopy(option
.second_hand_color
, optarg
);
207 case OPT_HANDS_WIDTH
:
208 option
.hand_width
= atoi(optarg
);
216 case OPT_HOUR_HAND_LENGTH
:
217 option
.hour_hand_length
= atoi(optarg
);
220 case OPT_MINUTE_HAND_LENGTH
:
221 option
.minute_hand_length
= atoi(optarg
);
225 StringCopy(option
.second_hand_color
, optarg
);
228 case OPT_SECOND_HAND_LENGTH
:
229 option
.second_hand_length
= atoi(optarg
);
232 case OPT_SECOND_HAND_WIDTH
:
233 option
.second_hand_width
= atoi(optarg
);
237 option
.show_seconds
= !SHOW_SECONDS
;
246 option
.under_windowmaker
= !UNDER_WINDOWMAKER
;
255 * There should be nothing left on the command line.
259 fprintf(stderr
, "ERR: extra command line arguments ignored\n");
262 /*****************************************************************************/
265 StringCopy(char *destination
, const char *source
)
267 strncpy(destination
, source
, STRING_LENGTH
);
268 destination
[STRING_LENGTH
- 1] = '\0';
271 /******************************************************************************
272 *******************************************************************************
274 *******************************************************************************
275 ******************************************************************************/