Corrected the .gitignore file.
[xcircuit.git] / menudep.c
blob5d83545c564186e0d16fb62562171ae82c6e46c6
1 /*----------------------------------------------------------------------*/
2 /* menudep.c */
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 /*----------------------------------------------------------------------*/
8 /* */
9 /* example: For menustruct Fonts[], */
10 /* #define FontsButton 1 */
11 /* */
12 /* Name is the menustruct name appended with the word "Button". */
13 /* The Widget itself will be placed in the WidgetList "menuwidgets" */
14 /* */
15 /* NAMING CONVENTIONS: */
16 /* Cascade Widget: name of menustruct + "Button" */
17 /* Button Widgets: name of menustruct + modified name of button */
18 /* + "Button" */
19 /* */
20 /* "modified name" means that only alphanumeric characters are */
21 /* used and the macro (if any) in parentheses is removed. */
22 /*----------------------------------------------------------------------*/
24 #ifndef TCL_WRAPPER
26 #include <stdio.h>
27 #include <string.h>
28 #include <stdlib.h>
30 #ifndef XC_WIN32
31 #include <X11/Intrinsic.h>
32 #include <X11/StringDefs.h>
33 #include <X11/Xutil.h>
34 #endif
36 #include "xcircuit.h"
38 #define _MENUDEP
39 #include "menus.h"
41 int menucount;
42 FILE *mp;
44 /*----------------------------------------------------------------------*/
46 char *normalize(char *textin)
48 char *tptr = textin;
49 char *sptr;
50 char *newptr = (char *)malloc((strlen(textin) + 1) * sizeof(char));
51 sptr = newptr;
53 while (*tptr != '\0') {
54 switch(*tptr) {
55 case ' ': case ':': case '/': case '!': case '_': case '-':
56 case '&': case '.': case '<': case '>':
57 break;
58 case '(':
59 while (*tptr != '\0' && *tptr != ')') tptr++;
60 if (*tptr == '\0') {
61 printf("Open parenthesis in menu.h: %s\n", textin);
62 exit(1);
64 break;
65 default:
66 *sptr++ = *tptr;
67 break;
69 tptr++;
71 *sptr = '\0';
72 return newptr;
75 /*----------------------------------------------------------------------*/
77 void log_entry(char *menuname, char *buttonname)
79 char *n1, *n2;
80 n1 = normalize(menuname);
81 n2 = normalize(buttonname);
82 if (strlen(n2) == 0)
83 menucount++;
84 else
85 fprintf(mp, "#define %s%sButton (menuwidgets[%d])\n",
86 n1, n2, menucount++);
87 free(n1);
88 free(n2);
91 /*----------------------------------------------------------------------*/
93 void toolbar_entry(char *buttonname)
95 char *n1;
96 n1 = normalize(buttonname);
97 fprintf(mp, "#define %sToolButton (menuwidgets[%d])\n", n1, menucount++);
98 free(n1);
101 /*----------------------------------------------------------------------*/
103 void searchsubmenu(char *menuname, menuptr buttonmenu, int arraysize)
105 menuptr p;
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 /*----------------------------------------------------------------------*/
117 int main()
119 short i;
121 menucount = 0;
123 if ((mp = fopen("menudep.h", "w")) == NULL) {
124 printf("Unable to open menudep.h for output\n");
125 exit(1);
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,
138 TopButtons[i].size);
140 #ifdef HAVE_XPM
141 for (i = 0; i < toolbuttons; i++)
142 toolbar_entry(ToolBar[i].name);
143 #endif
145 fprintf(mp, "#define MaxMenuWidgets %d\n", menucount);
146 fprintf(mp, "\n/*-------------------------------------------------------*/\n\n");
148 fclose(mp);
149 exit(0);
152 #else
154 #include <stdio.h>
156 int main()
158 /* create empty file menudep.h */
159 FILE *fid = fopen("menudep.h", "w");
160 fclose(fid);
161 return 0;
164 #endif /* TCL_WRAPPER */