1 /*----------------------------------------------------------------------*/
3 /* Copyright (c) 2002 Tim Edwards, Johns Hopkins University */
4 /*----------------------------------------------------------------------*/
5 /* Parse file menus.h and create file of definitions for use by */
6 /* "NameToWidget" to find the menu in the widget menu tree. */
7 /*----------------------------------------------------------------------*/
9 /* example: For menustruct Fonts[], */
10 /* #define FontsButton 1 */
12 /* Name is the menustruct name appended with the word "Button". */
13 /* The Widget itself will be placed in the WidgetList "menuwidgets" */
15 /* NAMING CONVENTIONS: */
16 /* Cascade Widget: name of menustruct + "Button" */
17 /* Button Widgets: name of menustruct + modified name of button */
20 /* "modified name" means that only alphanumeric characters are */
21 /* used and the macro (if any) in parentheses is removed. */
22 /*----------------------------------------------------------------------*/
31 #include <X11/Intrinsic.h>
32 #include <X11/StringDefs.h>
33 #include <X11/Xutil.h>
44 /*----------------------------------------------------------------------*/
46 char *normalize(char *textin
)
50 char *newptr
= (char *)malloc((strlen(textin
) + 1) * sizeof(char));
53 while (*tptr
!= '\0') {
55 case ' ': case ':': case '/': case '!': case '_': case '-':
56 case '&': case '.': case '<': case '>':
59 while (*tptr
!= '\0' && *tptr
!= ')') tptr
++;
61 printf("Open parenthesis in menu.h: %s\n", textin
);
75 /*----------------------------------------------------------------------*/
77 void log_entry(char *menuname
, char *buttonname
)
80 n1
= normalize(menuname
);
81 n2
= normalize(buttonname
);
85 fprintf(mp
, "#define %s%sButton (menuwidgets[%d])\n",
91 /*----------------------------------------------------------------------*/
93 void toolbar_entry(char *buttonname
)
96 n1
= normalize(buttonname
);
97 fprintf(mp
, "#define %sToolButton (menuwidgets[%d])\n", n1
, menucount
++);
101 /*----------------------------------------------------------------------*/
103 void searchsubmenu(char *menuname
, menuptr buttonmenu
, int arraysize
)
107 for (p
= buttonmenu
; p
< buttonmenu
+ arraysize
; p
++) {
108 if (p
->submenu
!= NULL
)
109 searchsubmenu(p
->name
, p
->submenu
, p
->size
);
110 else if (p
->name
[0] != ' ') /* anything but a separator */
111 log_entry(menuname
, p
->name
);
115 /*----------------------------------------------------------------------*/
123 if ((mp
= fopen("menudep.h", "w")) == NULL
) {
124 printf("Unable to open menudep.h for output\n");
128 fprintf(mp
, "/*-------------------------------------------------------*/\n");
129 fprintf(mp
, "/* menudep.h generated automatically by program menudep */\n");
130 fprintf(mp
, "/* from file menus.h. Do not edit. */\n");
131 fprintf(mp
, "/*-------------------------------------------------------*/\n\n");
133 /* run the same routine as "createmenus()" in xcircuit.c so that the */
134 /* ordering will be the same. */
136 for (i
= 0; i
< maxbuttons
; i
++)
137 searchsubmenu(TopButtons
[i
].name
, TopButtons
[i
].submenu
,
141 for (i
= 0; i
< toolbuttons
; i
++)
142 toolbar_entry(ToolBar
[i
].name
);
145 fprintf(mp
, "#define MaxMenuWidgets %d\n", menucount
);
146 fprintf(mp
, "\n/*-------------------------------------------------------*/\n\n");
158 /* create empty file menudep.h */
159 FILE *fid
= fopen("menudep.h", "w");
164 #endif /* TCL_WRAPPER */