Constify WMMatchDataProc and fix fallout
[wmaker-crm.git] / util / wmgenmenu.c
blob934ccca79f13eaba39dbe9e067e82ecf46816d1a
1 /* Copyright (C) 2010 Carlos R. Mafra */
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <locale.h>
7 #include <libintl.h>
8 #define _(text) gettext(text)
10 #include <WINGs/WUtil.h>
12 #define MAX_NR_APPS 50 /* Maximum number of entries in each apps list */
13 #define MAX_WMS 10 /* Maximum number of other window managers to check */
14 #include "wmgenmenu.h"
16 static void find_and_write(char **list);
17 static inline void workspaces(void);
18 static inline void lock_screen(void);
19 static inline void wmaker_config(void);
20 static inline void run_command(void);
21 static void other_window_managers(char **other_wm);
22 static inline void wm_visual(void);
23 static inline void write_first_line(int count);
25 char *path;
27 int main(int argc, char *argv[])
29 int fd;
30 char *locale;
31 extern char *path;
33 path = getenv("PATH");
34 locale = getenv("LANG");
35 setlocale(LC_ALL, "");
37 if (getenv("NLSPATH"))
38 bindtextdomain("wmgenmenu", getenv("NLSPATH"));
39 else
40 bindtextdomain("wmgenmenu", LOCALEDIR);
42 bind_textdomain_codeset("wmgenmenu", "UTF-8");
43 textdomain("wmgenmenu");
45 printf("\(\"Window Maker\",\n");
47 printf(" \(\"");
48 printf(_("Applications"));
49 printf("\",\n");
51 /* This "first" printf is different from the others! */
52 printf(" \(\"");
53 printf(_("Terminals"));
54 printf("\"");
55 find_and_write(terminals);
57 printf("\n ),\n \(\"");
58 printf(_("Internet"));
59 printf("\"");
60 find_and_write(internet);
62 printf("\n ),\n \(\"");
63 printf(_("Email"));
64 printf("\"");
65 find_and_write(email);
67 printf("\n ),\n \(\"");
68 printf(_("Mathematics"));
69 printf("\"");
70 find_and_write(Mathematiks);
72 printf("\n ),\n \(\"");
73 printf(_("File Managers"));
74 printf("\"");
75 find_and_write(file_managers);
77 printf("\n ),\n \(\"");
78 printf(_("Graphics"));
79 printf("\"");
80 find_and_write(Graphics);
82 printf("\n ),\n \(\"");
83 printf(_("Multimedia"));
84 printf("\"");
85 find_and_write(Multimedia);
87 printf("\n ),\n \(\"");
88 printf(_("Editors"));
89 printf("\"");
90 find_and_write(Editors);
92 printf("\n ),\n \(\"");
93 printf(_("Development"));
94 printf("\"");
95 find_and_write(development);
97 printf("\n ),\n \(\"");
98 printf(_("Window Maker"));
99 printf("\"");
100 find_and_write(WindowMaker);
102 printf("\n ),\n \(\"");
103 printf(_("Office"));
104 printf("\"");
105 find_and_write(Office);
107 printf("\n ),\n \(\"");
108 printf(_("Astronomy"));
109 printf("\"");
110 find_and_write(Astronomie);
112 printf("\n ),\n \(\"");
113 printf(_("Sound"));
114 printf("\"");
115 find_and_write(Sound);
117 printf("\n ),\n \(\"");
118 printf(_("Comics"));
119 printf("\"");
120 find_and_write(Comics);
122 printf("\n ),\n \(\"");
123 printf(_("Viewers"));
124 printf("\"");
125 find_and_write(Viewers);
127 printf("\n ),\n \(\"");
128 printf(_("Utilities"));
129 printf("\"");
130 find_and_write(Utilities);
132 printf("\n ),\n \(\"");
133 printf(_("System"));
134 printf("\"");
135 find_and_write(System);
137 printf("\n ),\n \(\"");
138 printf(_("Video"));
139 printf("\"");
140 find_and_write(Video);
142 printf("\n ),\n \(\"");
143 printf(_("Chat and Talk"));
144 printf("\"");
145 find_and_write(Chat);
147 printf("\n ),\n \(\"");
148 printf(_("P2P-Network"));
149 printf("\"");
150 find_and_write(P2P);
152 printf("\n ),\n \(\"");
153 printf(_("Games"));
154 printf("\"");
155 find_and_write(Games);
157 printf("\n ),\n \(\"");
158 printf(_("OpenSUSE"));
159 printf("\"");
160 find_and_write(OpenSUSE);
162 printf("\n ),\n \(\"");
163 printf(_("Mandriva"));
164 printf("\"");
165 find_and_write(Mandriva);
167 /* This must be after the last entry */
168 printf("\n )\n");
169 printf(" ),\n");
171 run_command();
172 wm_visual();
173 workspaces();
174 wmaker_config();
176 printf("(\"");
177 printf(_("Info Panel"));
178 printf("\", INFO_PANEL),\n");
180 printf("(\"");
181 printf(_("Restart"));
182 printf("\", RESTART),\n");
184 other_window_managers(other_wm);
185 lock_screen();
187 printf("(\"");
188 printf(_("Exit..."));
189 printf("\", EXIT)\n");
191 /* Final closing parenthesis */
192 printf(")\n");
194 exit(EXIT_SUCCESS);
197 static void find_and_write(char **list)
199 int i, argc;
200 char *location, **argv;
201 extern char *path;
203 for (i = 0; i <= MAX_NR_APPS; i++) {
204 if (list[i]) {
205 /* Before checking if app exists, split its options */
206 wtokensplit(list[i], &argv, &argc);
207 location = wfindfile(path, argv[0]);
208 if (location) {
209 /* check whether it is to be executed in a terminal */
210 if (strcmp("!", argv[argc - 1]) < 0)
211 printf(",\n \(\"%s\", EXEC, \"%s\")", argv[0], list[i]);
212 else {
213 char comm[50], *ptr[1];
215 strcpy(comm, list[i]);
216 /* ugly hack to delete character ! from list[i] */
217 ptr[0] = strchr(comm,'!');
218 *ptr[0] = ' ';
219 printf(",\n \(\"%s\", EXEC, \"xterm -e %s\")", argv[0], comm);
226 static inline void wmaker_config(void)
228 char *location = wfindfile(path, "WPrefs");
230 if (location) {
231 printf("(\"");
232 printf(_("Config wmaker..."));
233 printf("\", EXEC, \"WPrefs\"),\n");
237 static inline void workspaces(void)
239 printf("(\"");
240 printf(_("Workspaces"));
241 printf("\", WORKSPACE_MENU),\n");
243 printf(" (\"");
244 printf(_("Workspace"));
245 printf("\",\n");
247 printf(" (\"");
248 printf(_("Hide others"));
249 printf("\", HIDE_OTHERS),\n");
251 printf(" (\"");
252 printf(_("Show all"));
253 printf("\", SHOW_ALL),\n");
255 printf(" (\"");
256 printf(_("Arrange Icons"));
257 printf("\", ARRANGE_ICONS),\n");
259 printf(" (\"");
260 printf(_("Refresh"));
261 printf("\", REFRESH),\n");
263 printf(" (\"");
264 printf(_("Save Session"));
265 printf("\", SAVE_SESSION),\n");
267 printf(" (\"");
268 printf(_("Clear Session"));
269 printf("\", CLEAR_SESSION)\n");
271 printf(" ),\n");
274 static inline void lock_screen(void)
276 char *location;
278 location = wfindfile(path, "xlock");
279 if (location) {
280 printf("(\"");
281 printf(_("Lock Screen"));
282 printf("\", EXEC, \"xlock -allowroot -usefirst -mode matrix\"),\n");
286 static void other_window_managers(char **other_wm)
288 int count = 0;
289 char *location;
290 int i;
292 printf("(\"");
293 printf(_("Other Window Managers"));
294 printf("\",\n");
296 for (i = 0; i <= MAX_WMS; i++) {
297 if (other_wm[i]) {
298 location = wfindfile(path, other_wm[i]);
299 if (location) {
300 write_first_line(count);
301 printf(_("Start %s"), other_wm[i]);
302 printf("\", RESTART, \"%s\")", other_wm[i]);
303 count++;
307 printf("\n),\n");
310 static void wm_visual(void)
312 /* TODO: add more pre-defined dirs to Themes etc */
313 printf("(\"");
314 printf(_("Workspace Appearance"));
315 printf("\",\n");
317 printf("(\"");
318 printf(_("Themes"));
319 printf("\", OPEN_MENU, \"-noext $HOME/GNUstep/Library/WindowMaker/Themes WITH setstyle\"),\n");
321 printf("(\"");
322 printf(_("Styles"));
323 printf("\", OPEN_MENU, \"-noext $HOME/GNUstep/Library/WindowMaker/Styles WITH setstyle\"),\n");
325 printf("(\"");
326 printf(_("Icons"));
327 printf("\", OPEN_MENU, \"-noext $HOME/GNUstep/Library/WindowMaker/IconSets WITH seticons\"),\n");
329 printf("(\"");
330 printf(_("Background"));
331 printf("\", OPEN_MENU, \"-noext $HOME/GNUstep/Library/WindowMaker/Backgrounds WITH wmsetbg -u -t\"),\n");
333 printf("(\"");
334 printf(_("Save Theme"));
335 printf("\", SHEXEC, \"getstyle -t $HOME/GNUstep/Library/WindowMaker/Themes/\\\"%%a(Theme name)\\\"\"),\n");
337 printf("(\"");
338 printf(_("Save Icons"));
339 printf("\", SHEXEC, \"geticonset $HOME/GNUstep/Library/WindowMaker/IconSets/\\\"%%a(IconSet name)\\\"\")\n");
340 printf("),\n");
344 static inline void run_command(void)
347 * %A below requires Voinov's "Add dialog history" (which
348 * is included in wmaker-crm), otherwise it should be %a
350 printf("\(\"");
351 printf(_("Run..."));
352 printf("\", SHEXEC, \"%%A(");
353 printf(_("Run, Type command:"));
354 printf(")\"),\n");
357 static inline void write_first_line(int count)
359 /* All lines inside a menu must end with a comma, except for
360 * the last one. To cope with this let's check if there is a
361 * previous entry before writing the "start of the line", and
362 * write the trailing comma if there is.
364 if (count == 0)
365 printf(" (\"");
366 else {
367 printf(",\n (\"");