// recursive parsing of menu file static Menu* ParseMenu(struct menu_src *src, const char *title, const char *IDString) { char line[4000]; char data[4000]; char buffer[4000]; char command[40]; char label[MAX_PATH]; Menu *pMenu, *pSub; MenuItem *pItem; int f, e_cmd; const char *p_label, *p_data, *cp, *p_cmd; pMenu = NULL; for(;;) { p_label = NULL; p_data = data; if (0 == src->level) { // read default menu from string NextToken(line, &src->default_menu, "\n"); } else { f = ReadNextCommand(src->fp[src->level-1], line, sizeof(line)); if (!f) { if (src->level > 1) { dec_inc_level(src); continue; // continue from included file } e_cmd = e_no_end; goto skip; } } cp = replace_environment_strings(line, sizeof line); //dbg_printf("Menu %08x line:%s", pMenu, line); // get the command if (false == get_string_within(command, sizeof command, &cp, "[]")) continue; // search the command e_cmd = get_string_index(command, menu_cmds); if (get_string_within(label, sizeof label, &cp, "()")) p_label = label; if (false == get_string_within(data, sizeof data, &cp, "{}")) p_data = label; skip: if (NULL == pMenu) { if (e_begin == e_cmd) { // If the line contains [begin] we create the menu // If no menu title has been defined, display Blackbox version... #ifdef BBXMENU if (src->default_menu) strcpy(label, "bbXMenu"); else #endif if (0 == label[0] && src->default_menu) p_label = GetBBVersion(); pMenu = MakeNamedMenu(p_label, IDString, src->popup); continue; } if (NULL == title) title = NLS0("missing [begin]"); pMenu = MakeNamedMenu(title, IDString, src->popup); } pItem = NULL; switch (e_cmd) { //==================== // [begin] is like [submenu] when within the menu case e_begin: case e_submenu: sprintf(buffer, "%s_%s", IDString, label); strlwr(buffer + strlen(IDString)); pSub = ParseMenu(src, p_data, buffer); if (pSub) pItem = MakeSubmenu(pMenu, pSub, label); else pItem = MakeMenuNOP(pMenu, label); break; //==================== case e_no_end: MakeMenuNOP(pMenu, NLS0("missing [end]")); case e_end: MenuOption(pMenu, BBMENU_ISDROPTARGET); return pMenu; //==================== case e_include: { char dir[MAX_PATH]; file_directory(dir, src->path[src->level-1]); replace_shellfolders_from_base(buffer, p_data, false, dir); if (false == add_inc_level(src, buffer)) { replace_shellfolders(buffer, p_data, false); if (false == add_inc_level(src, buffer)) MakeMenuNOP(pMenu, NLS0("[include] failed")); } continue; } //==================== // a [nop] item will insert an inactive item with optional text case e_nop: pItem = MakeMenuNOP(pMenu, label); break; // a insert separator, we treat [sep] like [nop] with no label case e_sep1: case e_sep2: pItem = MakeMenuNOP(pMenu, NULL); break; //==================== // a [path] item is pointing to a dynamic folder... case e_path: p_cmd = get_special_command(&p_data, buffer, sizeof buffer); pItem = MakeMenuItemPath(pMenu, label, p_data, p_cmd); break; // a [insertpath] item will insert items from a folder... case e_insertpath: p_cmd = get_special_command(&p_data, buffer, sizeof buffer); pItem = MakeMenuItemPath(pMenu, NULL, p_data, p_cmd); break; // a [stylemenu] item is pointing to a dynamic style folder... case e_stylesmenu: pItem = MakeMenuItemPath(pMenu, label, p_data, MM_STYLE_BROAM); break; // a [styledir] item will insert styles from a folder... case e_stylesdir: pItem = MakeMenuItemPath(pMenu, NULL, p_data, MM_STYLE_BROAM); break; // a [rcmenu] item is pointing to a dynamic rc files folder... case e_rcmenu: pItem = MakeMenuItemPath(pMenu, label, p_data, MM_EDIT_BROAM); break; case e_themesmenu: pItem = MakeMenuItemPath(pMenu, label, p_data, MM_THEME_BROAM); break; //==================== // special items... case e_workspaces: pItem = MakeSubmenu(pMenu, MakeDesktopMenu(0, src->popup), p_label); break; case e_icons: pItem = MakeSubmenu(pMenu, MakeDesktopMenu(1, src->popup), p_label); break; case e_tasks: pItem = MakeSubmenu(pMenu, MakeDesktopMenu(2, src->popup), p_label); break; case e_config: pItem = MakeSubmenu(pMenu, MakeConfigMenu(src->popup), p_label); break; //==================== case e_exec: if ('@' == data[0]) { pItem = MakeMenuItem(pMenu, label, data, false); MenuItemOption(pItem, BBMENUITEM_UPDCHECK); } else { goto core_broam; } break; //==================== case e_other: f = get_workspace_number(command); // check for 'workspace1..' if (-1 != f) { pItem = MakeSubmenu(pMenu, MakeTaskFolder(f, src->popup), p_label); } else { p_data = data; goto core_broam; } break; //==================== // everything else is converted to a '@BBCore.xxx' broam core_broam: f = sprintf(buffer, "@bbCore.%s", command); strlwr(buffer+8); if (p_data[0]) sprintf(buffer + f, " %s", p_data); pItem = MakeMenuItem(pMenu, label[0]?label:command, buffer, false); break; } //#ifdef BBOPT_MENUICONS if ( Settings_menu.iconSize ) { if (pItem && get_string_within(label, sizeof label, &cp, "<>")) MenuItemOption(pItem, BBMENUITEM_SETICON, label); } //#endif } }
//============================================================================ void slit_info::loadPlugins(FILE *fp) { char rc_key[256]; LONG L = 0; sprintf(rc_key, "%s.plugin:", this->rc_key); for (;;) { const char *plug_path; char line[MAX_PATH]; if (fp) { if (false == ReadNextCommand(fp, line, sizeof line)) break; if (line[0] != '&') continue; plug_path = line; while (' ' == *++plug_path); } else { plug_path = ReadValue(rcpath, rc_key, &L); if (NULL == plug_path) break; } //dbg_printf("%d loading %s", L, plug_path); ModuleInfo *m = (ModuleInfo*)m_alloc(sizeof(struct ModuleInfo)); memset(m, 0, sizeof *m); const char *name = plug_path; const char *p1 = strrchr (plug_path, '\\'); const char *p2 = strrchr (plug_path, '/'); if (p2 > p1) p1 = p2; if (p1) name = p1 + 1; strcpy(m->name, name); char *p3 = strrchr(m->name, '.'); if (p3) *p3 = 0; m->args[0] = 0; const char *errormsg = NULL; HMODULE hMO = LoadLibrary(plug_path); if (NULL == hMO) { errormsg = "This plugin you are trying to load" " does not exist or cannot be loaded."; } else { *(FARPROC*)&m->beginPluginEx = GetProcAddress(hMO, "beginPluginEx"); *(FARPROC*)&m->beginSlitPlugin = GetProcAddress(hMO, "beginSlitPlugin"); *(FARPROC*)&m->endPlugin = GetProcAddress(hMO, "endPlugin"); if (NULL == m->beginSlitPlugin && NULL == m->beginPluginEx) { errormsg = "This plugin doesn't have an 'beginSlitPlugin'." "\nProbably it is not designed for the slit."; } else if (NULL == m->endPlugin) { errormsg = "This plugin doesn't have an 'endPlugin'." "\nProbably it is not a plugin designed for bb4win."; } else { #ifdef _MSC_VER _try { #endif int result; if (m->beginPluginEx) result = m->beginPluginEx(hMO, this->hwnd); else result = m->beginSlitPlugin(hMO, this->hwnd); if (BEGINPLUGIN_OK != result) { errormsg = "This plugin you are trying to load" " failed to initialize."; } #ifdef _MSC_VER } _except(EXCEPTION_EXECUTE_HANDLER) { errormsg = "This plugin caused a general protection fault on loading."; } #endif } } if (NULL == errormsg) { m->hMO = hMO; m->next = m_pMO; m_pMO = m; continue; } if (hMO) FreeLibrary(hMO); m_free(m); BBP_messagebox(this, MB_OK, "%s\n%s", plug_path, errormsg); } }
bool make_exclusion_list(void) { struct elist { struct elist *next; int flen; int option; char buff[1]; } *p0 = NULL, **pp = &p0, *p; int t_len = 0; int t_count = 0; char exclusionspath[MAX_PATH]; // first read all strings into a list and calculate the size... FILE *fp = FileOpen(set_my_path(exclusionspath, "exclusions.rc")); if (fp) for (;;) { char *line, line_buffer[256]; if (false == ReadNextCommand(fp, line_buffer, sizeof line_buffer)) { FileClose(fp); break; } strlwr(line = line_buffer); int option = 0; if (0 == memicmp (line, "hook-early:", 11)) { option = 1; line += 10; while (' ' == *++line); } int line_len = strlen(line); char *cp = strchr(line, ':'); if (cp) *cp++ = 0; else *(cp = line + line_len++) = 0; p = (struct elist *)malloc(line_len + sizeof(struct elist)); memcpy(p->buff, line, ++line_len); p->flen = cp - line; p->option = option; *(pp = &(*pp = p)->next) = NULL; t_len += line_len-2; t_count++; } t_len += sizeof(struct exclusion_info) + (t_count-1) * sizeof(struct exclusion_item); // ... then create the shared mem, which is supposed to succeed,... if (FALSE == CreateSharedMem(offset_exInfo + t_len)) return false; // ... and finally copy the list into it, free items by the way. struct exclusion_info *pExclInfo = &lpvMem->exInfo; pExclInfo->size = t_len; pExclInfo->count = t_count; struct exclusion_item *ei = pExclInfo->ei; while (p0) { p = p0; p0 = p0->next; char *cp = ei->buff; ei->flen = 1+strlen(strcpy(cp, p->buff)); ei->clen = 1+strlen(strcpy(cp+ei->flen, p->buff+p->flen)); ei->option = p->option; //dbg_printf("added \"%s:%s\"", p->buff, p->p_class); free(p); ei = (struct exclusion_item *)(ei->buff + ei->flen + ei->clen); } return true; }