1 /*
2 * Copyright (C) 2002-2015 Tommy Scheunemann <net@arrishq.net>
3 *
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <stdio.h>
21 #include <strings.h>
22
23 #include "wmconfig.h"
24 #include "prototypes.h"
25 #include "package.h"
26
27 extern unsigned int flags;
28
29 /* Fvwm requires submenus defined before they are used - Wmconfig uses a "reverse" output */
output_fvwm(struct group * root,const char * use_term)30 void output_fvwm(struct group *root, const char *use_term)
31 {
32 struct item *item;
33 if (root == (struct group *)NULL) {
34 return;
35 }
36 item = root->items;
37 while (item->type != 0) {
38 if (item->type == ITEM_MENU) {
39 output_fvwm(item->data, use_term);
40 }
41 item++;
42 }
43
44 item = root->items;
45
46 /* Here we finally create menus */
47 printf("PopUp \"%s\"\n Title \"%s\"\n", root->name, root->name);
48 while (item->type != 0) {
49 if (item->type == ITEM_MENU) {
50 struct group *tmp;
51 tmp = (struct group *)item->data;
52 printf(" PopUp \"%s\" %s\n", tmp->name, tmp->name);
53 } else if (item->type == ITEM_APP) {
54 /* Here we create the menu items */
55 struct package *app;
56 app = (struct package *)item->data;
57 if (app->restart) {
58 if (strncasecmp(app->restart, "restart", 7) == 0) {
59 /* restart pseudo item */
60 printf(" Restart \"%s\" fvwm\n", app->name);
61 } else if (strncasecmp(app->restart, "quit", 4) == 0) {
62 /* quit pseudo item */
63 printf(" Quit \"%s\"\n", app->name);
64 } else {
65 /* restart another WM */
66 printf(" Restart \"%s\" %s\n", app->name, app->restart);
67 }
68 } else {
69 if (app->name && app->exec && app->terminal) {
70 /* Terminal required */
71 printf(" Exec \"%s\" exec %s -e %s\n", app->name, use_term, app->exec);
72 } else if (app->name && app->exec) {
73 /* Normal menu item */
74 printf(" Exec \"%s\" exec %s\n", app->name, app->exec);
75 }
76 }
77 }
78 item++;
79 }
80 printf("EndPopup\n\n");
81 return;
82 }
83