wmusic: Use "player-status" property instead of "status".
[dockapps.git] / pclock / src / Main.c
blobebdc439fb23f5a0a83e57d35c39e99eab7475680
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
10 version.
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 ******************************************************************************/
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <getopt.h>
29 #include <sys/time.h>
31 #include "PClock.h"
32 #include "Defaults.h"
33 #include "Version.h"
35 /*****************************************************************************/
37 options option;
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 /*****************************************************************************/
49 int
50 main(int argc, char *argv[])
52 int done = FALSE;
53 struct timeval tv;
55 StringCopy(program_path, argv[0]);
56 SetOptions(argc, argv);
58 CreateWindow(argc, argv);
60 while (!done) {
61 UpdateClock();
62 HandleEvents(&done);
63 gettimeofday(&tv, NULL);
64 usleep(PERIOD - tv.tv_usec%PERIOD);
67 DestroyWindow();
69 return EXIT_SUCCESS;
72 /*****************************************************************************/
74 static void
75 Version(void)
77 printf("This is " NAME " " VERSION "\n");
78 printf("Copyright (C) 1999-2000 Alexander Kourakos\n");
81 /*****************************************************************************/
83 static void
84 Usage(void)
86 Version();
88 printf("\n");
90 printf("Usage: %s [OPTIONS]\n", program_path);
91 printf("OPTIONS may be zero or more of the following options.\n");
93 printf("\n");
95 printf(" -B, --background=PIXMAP "
96 "use the given pixmap as the clock background\n"
97 " "
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 " : "");
141 printf("\n");
143 printf("Author: Alexander Kourakos <Alexander@Kourakos.com>\n");
144 printf(" Web: http://www.kourakos.com/~awk/pclock/\n");
147 /*****************************************************************************/
149 static void
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},
165 {"help", 0, 0, 'h'},
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'},
174 {NULL, 0, 0, 0}
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) {
197 switch (o) {
198 case 'B':
199 StringCopy(option.background_pixmap, optarg);
200 break;
202 case 'H':
203 StringCopy(option.hand_color, optarg);
204 StringCopy(option.second_hand_color, optarg);
205 break;
207 case OPT_HANDS_WIDTH:
208 option.hand_width = atoi(optarg);
209 break;
211 case 'h':
212 Usage();
213 exit(EXIT_SUCCESS);
214 break;
216 case OPT_HOUR_HAND_LENGTH:
217 option.hour_hand_length = atoi(optarg);
218 break;
220 case OPT_MINUTE_HAND_LENGTH:
221 option.minute_hand_length = atoi(optarg);
222 break;
224 case 'S':
225 StringCopy(option.second_hand_color, optarg);
226 break;
228 case OPT_SECOND_HAND_LENGTH:
229 option.second_hand_length = atoi(optarg);
230 break;
232 case OPT_SECOND_HAND_WIDTH:
233 option.second_hand_width = atoi(optarg);
234 break;
236 case 's':
237 option.show_seconds = !SHOW_SECONDS;
238 break;
240 case 'v':
241 Version();
242 exit(EXIT_SUCCESS);
243 break;
245 case 'w':
246 option.under_windowmaker = !UNDER_WINDOWMAKER;
247 break;
249 default:
250 exit(EXIT_FAILURE);
255 * There should be nothing left on the command line.
258 if (optind < ac)
259 fprintf(stderr, "ERR: extra command line arguments ignored\n");
262 /*****************************************************************************/
264 static void
265 StringCopy(char *destination, const char *source)
267 strncpy(destination, source, STRING_LENGTH);
268 destination[STRING_LENGTH - 1] = '\0';
271 /******************************************************************************
272 *******************************************************************************
273 END OF FILE
274 *******************************************************************************
275 ******************************************************************************/