📄 exv_olwm.c
字号:
args[0] = '\0'; format = ( *p == '"' ) ? qformat : nqformat; if ( sscanf( p, format, label, prog, args ) < 2 ) { fprintf(stderr, "parseMenu: syntax error in menu file %s, line %d\n", filename, *lineno); return(MENU_FATAL); } if ( strcmp(prog, "END") == 0 ) { /* currently allocated button is last for this menu */ currentButton->isLast = True; if (currentMenu->label != NULL && strcmp(label, currentMenu->label) != 0) { fprintf(stderr, "parseMenu: menu label mismatch in file %s, line %d\n", filename, *lineno); return(MENU_FATAL); } if ( strcmp(args, "PIN") == 0 ) return(MENU_PINNABLE); else return(MENU_OK); } if ( strcmp(prog, "TITLE") == 0 ) { currentMenu->title = MemNewString( label ); /* we don't need to set up the next button, since * the TITLE line didn't use up a button */ continue; } currentButton->name = MemNewString( label ); if ( strcmp(prog, "DEFAULT") == 0) { char *t; char *u; currentButton->isDefault = True; /* * Pull the first token from args into prog. */ t = strtok(args, " \t"); if ( t == NULL ) { fprintf(stderr, "parseMenu: error in menu file %s, line %d\n", filename, *lineno); fputs("missing item after DEFAULT keyword.\n", stderr); return(MENU_FATAL); } strcpy(prog, t); t = strtok(NULL, ""); /* get remainder of args */ if (t == NULL) args[0] = '\0'; else { u = args; /* can't use strcpy because they overlap */ while ( *u++ = *t++ ) ; } } if ( strcmp(prog, "MENU") == 0 ) { int rval; initMenu( (menudata **)&(currentButton->submenu) ); saveMenu = currentMenu; currentMenu = (menudata *)currentButton->submenu; currentMenu->label = MemNewString(label); if (args[0] == '\0') { /* we haven't incremented lineno for this * read loop yet, so we need to do it now. * when END is read, parseMenu returns without * incrementing lineno, so the count will be * ok when this loop increments it before * reading the next line of the file. */ (*lineno)++; if ( (rval = parseMenu(filename, stream, currentMenu, lineno)) < 0 ) { freeMenuData( currentMenu ); return(MENU_FATAL); } else fillMenuStruct( currentMenu ); } else { rval = menuFromFile(args, currentMenu, True); if (rval <= MENU_NOTFOUND) return(MENU_FATAL); } if ( rval == MENU_PINNABLE ) currentMenu->pinnable = True; currentMenu = saveMenu; /* if submenu not found, reuse button */ if ( rval != MENU_NOTFOUND ) { initButton( (buttondata **)&(currentButton->next) ); currentButton = currentButton->next; } continue; } done = False; while ( !done ) { switch ( lookupToken( prog, &(currentButton->func) ) ) { case UsrToken: /* if UsrToken, that means that "prog" was just * the first word of the command to be executed, */ strcpy( localBuf, prog ); APPEND_STRING( localBuf, " " ); APPEND_STRING( localBuf, args ); /* copy current contents of localBuf back into * args array so that PshToken code can be used */ strcpy( args, localBuf ); localBuf[0] = '\0'; /* fall through */ case PshToken: if (continuation) strcpy( localBuf, args ); else currentButton->exec = MemNewString( args ); done = True; break; case PinToken: fprintf( stderr, "parseMenu: format error in menu file %s, line %d\n", filename, *lineno ); fputs("menu title and END required before PIN keyword.\n", stderr); return(MENU_FATAL); break; default: /* some other valid token found and returned */ done = True; break; } } if ( !continuation ) { initButton( (buttondata **)&(currentButton->next) ); currentButton = currentButton->next; } } /* never used the last button created */ currentButton->isLast = True; return(MENU_OK);}/* * fillMenuStruct - Once the menu structures have been filled out using * information in the menu description file (via parseMenu()), the * nbuttons and idefault elements need to be set. */static voidfillMenuStruct( mptr )menudata *mptr;{ buttondata *bptr; int buttonIndex = 0; bptr = mptr->bfirst; if ( bptr->isLast == True ) { MemFree( bptr ); bptr = mptr->bfirst = NULL; } for ( ; bptr != NULL && bptr->isLast == False ; bptr = bptr->next ) { if ( bptr->isDefault == True ) mptr->idefault = buttonIndex; if ( (bptr->next)->isLast == True ) { MemFree( bptr->next); bptr->next = NULL; } buttonIndex++; } /* buttonIndex is one past end, but started at 0, so = number buttons */ mptr->nbuttons = buttonIndex;}/* * Allowed menu keywords ("Token") */struct _svctoken { char *token; FuncPtr func; TokenType toktype;} svctokenlookup[] = {/* { "REFRESH", RefreshFunc, ServiceToken },*//* { "CLIPBOARD", ClipboardFunc, ServiceToken },*//* { "PRINT_SCREEN", PrintScreenFunc, ServiceToken },*//* { "EXIT", ExitFunc, ServiceToken },*//* { "WMEXIT", ExitOLWM, ServiceToken },*//* { "PROPERTIES", PropertiesFunc, ServiceToken },*//* { "NOP", NopFunc, ServiceToken },*/ { "DEFAULT", NULL, DefaultToken }, { "MENU", NULL, MenuToken }, { "END", NULL, EndToken }, { "PIN", NULL, PinToken }, { "TITLE", NULL, TitleToken },/* { "WINDOW_CONTROLS", WindowCtlFunc, ServiceToken },*//* { "FLIPDRAG", FlipDragFunc, ServiceToken },*//* { "SAVE_WORKSPACE", SaveWorkspaceFunc, ServiceToken },*//* { "POSTSCRIPT", PshFunc, PshToken },*//* { "RESTART", RestartOLWM, ServiceToken },*//* { "FLIPFOCUS", FlipFocusFunc, ServiceToken },*/};#define NSERVICES (sizeof(svctokenlookup)/sizeof(struct _svctoken))/* lookupToken -- look up a token in the list of tokens * given a supposed keyword or service name. If the name doesn't * match any existing token, return the user-defined token. */static TokenTypelookupToken(nm,ppf)char *nm;FuncPtr *ppf;{ int ii; for (ii=0; ii<NSERVICES; ii++) { if (!strcmp(nm,svctokenlookup[ii].token)) { if (ppf != (FuncPtr *)0) *ppf = svctokenlookup[ii].func; return svctokenlookup[ii].toktype; } }/* deleted - js if (ppf != (FuncPtr *)0) *ppf = AppMenuFunc;*/ return UsrToken;}/* * initMenu - */static voidinitMenu( newmenu )menudata **newmenu;{ *newmenu = MemNew(menudata); (*newmenu)->title = NULL; (*newmenu)->label = NULL; (*newmenu)->idefault = -1; (*newmenu)->nbuttons = 0; (*newmenu)->pinnable = False; (*newmenu)->bfirst = (buttondata *)0;}/* * initButton - */static voidinitButton( newButton )buttondata **newButton;{ *newButton = MemNew(buttondata); (*newButton)->next = NULL; (*newButton)->name = NULL; (*newButton)->isDefault = False; (*newButton)->isLast = False; (*newButton)->func = (FuncPtr)0; (*newButton)->exec = NULL; (*newButton)->submenu = NULL;}/* * freeMenuData - free any possibly allocated memory for this menudata * structure (and its buttons), since it's not going to be used */static voidfreeMenuData( unusedMenu )menudata *unusedMenu;{ buttondata *unusedButton; /* isLast probably isn't set, since this menu had an error */ if ( ( unusedButton = unusedMenu->bfirst ) != (buttondata *)0 ) freeButtonData( unusedButton ); MemFree( unusedMenu->title ); MemFree( unusedMenu->label ); MemFree( unusedMenu ); unusedMenu = NULL;}/* * freeButtonData - free any possibly allocated memory for this buttondata * structure, since it's not going to be used */static voidfreeButtonData( unusedButton )buttondata *unusedButton;{ if ( unusedButton->next != NULL ) freeButtonData( unusedButton->next ); MemFree( unusedButton->name ); MemFree( unusedButton->exec ); if ( unusedButton->submenu != NULL ) freeMenuData( unusedButton->submenu ); MemFree( unusedButton ); unusedButton = NULL;}/* * Safe memory allocation/free routines - front-ends the C library functions * */void *MemAlloc(sz)unsigned int sz;{#ifdef __STDC__ void *p;#else char *p;#endif if ((p = malloc(sz)) == NULL) { (void) fprintf(stderr, "Memory allocation failure.\n"); exit(1); } memset((char *)p, 0, (int)sz); return p;}voidMemFree(p)void *p;{ if (p != NULL) free(p);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -