1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
/*----------------------------------------------------------------------*/
/* menudep.c */
/* Copyright (c) 2002 Tim Edwards, Johns Hopkins University */
/*----------------------------------------------------------------------*/
/* Parse file menus.h and create file of definitions for use by */
/* "NameToWidget" to find the menu in the widget menu tree. */
/*----------------------------------------------------------------------*/
/* */
/* example: For menustruct Fonts[], */
/* #define FontsButton 1 */
/* */
/* Name is the menustruct name appended with the word "Button". */
/* The Widget itself will be placed in the WidgetList "menuwidgets" */
/* */
/* NAMING CONVENTIONS: */
/* Cascade Widget: name of menustruct + "Button" */
/* Button Widgets: name of menustruct + modified name of button */
/* + "Button" */
/* */
/* "modified name" means that only alphanumeric characters are */
/* used and the macro (if any) in parentheses is removed. */
/*----------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xutil.h>
#include "xcircuit.h"
#define _MENUDEP
#include "menus.h"
int menucount;
FILE *mp;
/*----------------------------------------------------------------------*/
char *normalize(char *textin)
{
char *tptr = textin;
char *sptr;
char *newptr = (char *)malloc((strlen(textin) + 1) * sizeof(char));
sptr = newptr;
while (*tptr != '\0') {
switch(*tptr) {
case ' ': case ':': case '/': case '!': case '_': case '-':
case '&': case '.': case '<': case '>':
break;
case '(':
while (*tptr != '\0' && *tptr != ')') tptr++;
if (*tptr == '\0') {
printf("Open parenthesis in menu.h: %s\n", textin);
exit(1);
}
break;
default:
*sptr++ = *tptr;
break;
}
tptr++;
}
*sptr = '\0';
return newptr;
}
/*----------------------------------------------------------------------*/
void log_entry(char *menuname, char *buttonname)
{
char *n1, *n2;
n1 = normalize(menuname);
n2 = normalize(buttonname);
if (strlen(n2) == 0)
menucount++;
else
fprintf(mp, "#define %s%sButton (menuwidgets[%d])\n",
n1, n2, menucount++);
free(n1);
free(n2);
}
/*----------------------------------------------------------------------*/
void toolbar_entry(char *buttonname)
{
char *n1;
n1 = normalize(buttonname);
fprintf(mp, "#define %sToolButton (menuwidgets[%d])\n", n1, menucount++);
free(n1);
}
/*----------------------------------------------------------------------*/
void searchsubmenu(char *menuname, menuptr buttonmenu, int arraysize)
{
menuptr p;
for (p = buttonmenu; p < buttonmenu + arraysize; p++) {
if (p->submenu != NULL)
searchsubmenu(p->name, p->submenu, p->size);
else if (p->name[0] != ' ') /* anything but a separator */
log_entry(menuname, p->name);
}
}
/*----------------------------------------------------------------------*/
int main()
{
short i;
menucount = 0;
if ((mp = fopen("menudep.h", "w")) == NULL) {
printf("Unable to open menudep.h for output\n");
exit(1);
}
fprintf(mp, "/*-------------------------------------------------------*/\n");
fprintf(mp, "/* menudep.h generated automatically by program menudep */\n");
fprintf(mp, "/* from file menus.h. Do not edit. */\n");
fprintf(mp, "/*-------------------------------------------------------*/\n\n");
/* run the same routine as "createmenus()" in xcircuit.c so that the */
/* ordering will be the same. */
for (i = 0; i < maxbuttons; i++)
searchsubmenu(TopButtons[i].name, TopButtons[i].submenu,
TopButtons[i].size);
for (i = 0; i < toolbuttons; i++)
toolbar_entry(ToolBar[i].name);
fprintf(mp, "#define MaxMenuWidgets %d\n", menucount);
fprintf(mp, "\n/*-------------------------------------------------------*/\n\n");
fclose(mp);
exit(0);
}
|