/* upon fully deducing one particular menu entry, parsers call back to this * function to have said menu entry added to the wm menu. initializes wm menu * with a root element if needed. */ static void addWMMenuEntryCallback(WMMenuEntry *aEntry) { WMMenuEntry *wm; WMTreeNode *at; wm = (WMMenuEntry *)wmalloc(sizeof(WMMenuEntry)); /* this entry */ at = (WMTreeNode *)NULL; /* will be a child of this entry */ if (!menu) { WMMenuEntry *root; root = (WMMenuEntry *)wmalloc(sizeof(WMMenuEntry)); root->Name = "Applications"; root->CmdLine = NULL; root->SubMenu = NULL; root->Flags = 0; menu = WMCreateTreeNode(root); } if (aEntry->SubMenu) at = findPositionInMenu(aEntry->SubMenu); if (!at) at = menu; wm->Flags = aEntry->Flags; wm->Name = wstrdup(aEntry->Name); wm->CmdLine = wstrdup(aEntry->CmdLine); wm->SubMenu = NULL; WMAddItemToTree(at, wm); }
/* coerce an xdg entry type into a wm entry type */ static Bool xdg_to_wm(XDGMenuEntry **xdg, WMMenuEntry **wm) { char *p; /* Exec or TryExec is mandatory */ if (!((*xdg)->Exec || (*xdg)->TryExec)) return False; /* if there's no Name, use the first word of Exec or TryExec */ if ((*xdg)->Name) { (*wm)->Name = (*xdg)->Name; } else { if ((*xdg)->Exec) (*wm)->Name = wstrdup((*xdg)->Exec); else /* (*xdg)->TryExec */ (*wm)->Name = wstrdup((*xdg)->TryExec); p = strchr((*wm)->Name, ' '); if (p) *p = '\0'; } if ((*xdg)->Exec) (*wm)->CmdLine = (*xdg)->Exec; else /* (*xdg)->TryExec */ (*wm)->CmdLine = (*xdg)->TryExec; (*wm)->SubMenu = (*xdg)->Category; (*wm)->Flags = (*xdg)->Flags; return True; }
char *wgethomedir() { static char *home = NULL; char *tmp; struct passwd *user; if (home) return home; #ifdef HAVE_SECURE_GETENV tmp = secure_getenv("HOME"); #else tmp = getenv("HOME"); #endif if (tmp) { home = wstrdup(tmp); return home; } user = getpwuid(getuid()); if (!user) { werror(_("could not get password entry for UID %i"), getuid()); home = "/"; return home; } if (!user->pw_dir) home = "/"; else home = wstrdup(user->pw_dir); return home; }
/* get the (first) xdg main category from a list of categories */ static void getMenuHierarchyFor(char **xdgmenuspec) { char *category, *p; char buf[1024]; if (!*xdgmenuspec || !**xdgmenuspec) return; category = wstrdup(*xdgmenuspec); wfree(*xdgmenuspec); memset(buf, 0, sizeof(buf)); p = strtok(category, ";"); while (p) { /* get a known category */ if (strcmp(p, "AudioVideo") == 0) { snprintf(buf, sizeof(buf), "%s", _("Audio & Video")); break; } else if (strcmp(p, "Audio") == 0) { snprintf(buf, sizeof(buf), "%s", _("Audio")); break; } else if (strcmp(p, "Video") == 0) { snprintf(buf, sizeof(buf), "%s", _("Video")); break; } else if (strcmp(p, "Development") == 0) { snprintf(buf, sizeof(buf), "%s", _("Development")); break; } else if (strcmp(p, "Education") == 0) { snprintf(buf, sizeof(buf), "%s", _("Education")); break; } else if (strcmp(p, "Game") == 0) { snprintf(buf, sizeof(buf), "%s", _("Game")); break; } else if (strcmp(p, "Graphics") == 0) { snprintf(buf, sizeof(buf), "%s", _("Graphics")); break; } else if (strcmp(p, "Network") == 0) { snprintf(buf, sizeof(buf), "%s", _("Network")); break; } else if (strcmp(p, "Office") == 0) { snprintf(buf, sizeof(buf), "%s", _("Office")); break; } else if (strcmp(p, "Settings") == 0) { snprintf(buf, sizeof(buf), "%s", _("Settings")); break; } else if (strcmp(p, "System") == 0) { snprintf(buf, sizeof(buf), "%s", _("System")); break; } else if (strcmp(p, "Utility") == 0) { snprintf(buf, sizeof(buf), "%s", _("Utility")); break; } p = strtok(NULL, ";"); } if (!*buf) /* come up with something if nothing found */ snprintf(buf, sizeof(buf), "%s", _("Applications")); *xdgmenuspec = wstrdup(buf); }
/* XFetchName Wrapper */ Bool wFetchName(Display *dpy, Window win, char **winname) { XTextProperty text_prop; char **list; int num; if (XGetWMName(dpy, win, &text_prop)) { if (text_prop.value && text_prop.nitems > 0) { if (text_prop.encoding == XA_STRING) { *winname = wstrdup((char *)text_prop.value); XFree(text_prop.value); } else { text_prop.nitems = strlen((char *)text_prop.value); if (XmbTextPropertyToTextList(dpy, &text_prop, &list, &num) >= Success && num > 0 && *list) { XFree(text_prop.value); *winname = wstrdup(*list); XFreeStringList(list); } else { *winname = wstrdup((char *)text_prop.value); XFree(text_prop.value); } } } else { /* the title is set, but it was set to none */ *winname = wstrdup(""); } return True; } else { /* the hint is probably not set */ *winname = NULL; return False; } }
/*-------------------------------------- * Function: createWindow(title, width, height) *------------------------------------*/ static void createWindow(const string* title, int width, int height) { RECT window_rect = { 0 }; window_rect.right = width; window_rect.bottom = height; AdjustWindowRectEx(&window_rect, WindowStyle, FALSE, WindowStyleEx); int window_width = window_rect.right - window_rect.left; int window_height = window_rect.bottom - window_rect.top; registerWindowClass(); window = malloc(sizeof(windowT)); wchar_t* class_name = wstrdup(ClassName); wchar_t* window_name = wstrdup(title); window->hwnd = CreateWindowExW(WindowStyleEx, class_name, window_name, WindowStyle, CW_USEDEFAULT, CW_USEDEFAULT, window_width, window_height, HWND_DESKTOP, NULL, GetModuleHandleW(NULL), NULL); free(class_name); free(window_name); assert(window->hwnd != NULL); RECT desktop_rect; GetClientRect(GetDesktopWindow(), &desktop_rect); MoveWindow(window->hwnd, (desktop_rect.right - desktop_rect.left - window_width ) / 2, (desktop_rect.bottom - desktop_rect.top - window_height) / 2, window_width, window_height, FALSE); ShowWindow(window->hwnd, SW_SHOW); window->hdc = GetDC(window->hwnd); //assert(window->hdc != NULL); window->width = width; window->height = height; }
/* normalize and convert one wmconfig-format entry to wm format */ static Bool wmc_to_wm(WMConfigMenuEntry **wmc, WMMenuEntry **wm) { char *p; size_t slen; /* only Exec is mandatory, and it's better exist in a known place */ if (!((*wmc)->Exec && *(*wmc)->Exec && fileInPath((*wmc)->Exec))) return False; /* normalize Exec: wmconfig tends to stick an ampersand * at the end of everything, which we don't need */ slen = strlen((*wmc)->Exec) - 1; p = (*wmc)->Exec; while (slen > 0 && (isspace(*(p + slen)) || *(p + slen) == '&')) *(p + slen--) = '\0'; /* if there's no Name, use the first word of Exec; still better * than nothing. i realize it's highly arguable whether `xterm' from * `xterm -e "ssh dev push-to-prod"' is helpful or not, but since * the alternative is to completely lose the entry, i opt for this. * you could just fix the descriptor file to have a label <G> */ if (!(*wmc)->Name) { (*wmc)->Name = wstrdup((*wmc)->Exec); p = strchr((*wmc)->Name, ' '); if (p) *p = '\0'; } /* if there's no Category, use "Applications"; apparently "no category" * can manifest both as no `group' descriptor at all, or a group * descriptor of "" */ if (!(*wmc)->Category || !*(*wmc)->Category) (*wmc)->Category = wstrdup("Applications"); /* the `restart' type is used for restart, restart other * wm and quit current wm too. separate these cases. */ if ((*wmc)->Restart) { if (strcmp((*wmc)->Restart, "restart") == 0) (*wmc)->Flags |= F_RESTART_SELF; else if (strcmp((*wmc)->Restart, "quit") == 0) (*wmc)->Flags |= F_QUIT; else (*wmc)->Flags |= F_RESTART_OTHER; } (*wm)->Name = (*wmc)->Name; (*wm)->CmdLine = (*wmc)->Exec; (*wm)->SubMenu = (*wmc)->Category; (*wm)->Flags = (*wmc)->Flags; return True; }
char *GetShortcutString(const char *shortcut) { char *buffer = NULL; char *k; int control = 0; char *tmp, *text; tmp = text = wstrdup(shortcut); /* get modifiers */ while ((k = strchr(text, '+')) != NULL) { int mod; *k = 0; mod = wXModifierFromKey(text); if (mod < 0) { return wstrdup("bug"); } if (strcasecmp(text, "Meta") == 0) { buffer = wstrappend(buffer, "M+"); } else if (strcasecmp(text, "Alt") == 0) { buffer = wstrappend(buffer, "A+"); } else if (strcasecmp(text, "Shift") == 0) { buffer = wstrappend(buffer, "Sh+"); } else if (strcasecmp(text, "Mod1") == 0) { buffer = wstrappend(buffer, "M1+"); } else if (strcasecmp(text, "Mod2") == 0) { buffer = wstrappend(buffer, "M2+"); } else if (strcasecmp(text, "Mod3") == 0) { buffer = wstrappend(buffer, "M3+"); } else if (strcasecmp(text, "Mod4") == 0) { buffer = wstrappend(buffer, "M4+"); } else if (strcasecmp(text, "Mod5") == 0) { buffer = wstrappend(buffer, "M5+"); } else if (strcasecmp(text, "Control") == 0) { control = 1; } else { buffer = wstrappend(buffer, text); } text = k + 1; } if (control) { buffer = wstrappend(buffer, "^"); } buffer = wstrappend(buffer, text); wfree(tmp); return buffer; }
Panel *InitMouseSettings(WMWidget *parent) { _Panel *panel; modifierNames[0] = wstrdup(_("Shift")); modifierNames[1] = wstrdup(_("Lock")); modifierNames[2] = wstrdup(_("Control")); modifierNames[3] = wstrdup(_("Mod1")); modifierNames[4] = wstrdup(_("Mod2")); modifierNames[5] = wstrdup(_("Mod3")); modifierNames[6] = wstrdup(_("Mod4")); modifierNames[7] = wstrdup(_("Mod5")); panel = wmalloc(sizeof(_Panel)); panel->sectionName = _("Mouse Preferences"); panel->description = _("Mouse speed/acceleration, double click delay,\n" "mouse button bindings etc."); panel->parent = parent; panel->callbacks.createWidgets = createPanel; panel->callbacks.updateDomain = storeData; AddSection(panel, ICON_FILE); return panel; }
WAppIcon* wAppIconCreate(WWindow *leader_win) { WAppIcon *aicon; WScreen *scr = leader_win->screen_ptr; aicon = wmalloc(sizeof(WAppIcon)); wretain(aicon); memset(aicon, 0, sizeof(WAppIcon)); aicon->yindex = -1; aicon->xindex = -1; aicon->prev = NULL; aicon->next = scr->app_icon_list; if (scr->app_icon_list) { scr->app_icon_list->prev = aicon; } scr->app_icon_list = aicon; if (leader_win->wm_class) aicon->wm_class = wstrdup(leader_win->wm_class); if (leader_win->wm_instance) aicon->wm_instance = wstrdup(leader_win->wm_instance); aicon->icon = wIconCreate(leader_win); #ifdef DEMATERIALIZE_ICON { XSetWindowAttributes attribs; attribs.save_under = True; XChangeWindowAttributes(dpy, aicon->icon->core->window, CWSaveUnder, &attribs); } #endif #ifdef XDND wXDNDMakeAwareness(aicon->icon->core->window); #endif /* will be overriden if docked */ aicon->icon->core->descriptor.handle_mousedown = appIconMouseDown; aicon->icon->core->descriptor.handle_expose = iconExpose; aicon->icon->core->descriptor.parent_type = WCLASS_APPICON; aicon->icon->core->descriptor.parent = aicon; AddToStackList(aicon->icon->core); aicon->icon->show_title = 0; wIconUpdate(aicon->icon); return aicon; }
static void storeData(_Panel * panel) { char buffer[64]; int i; char *tmp, *p; WMUserDefaults *udb = WMGetStandardUserDefaults(); if (!WMGetUDBoolForKey(udb, "NoXSetStuff")) { tmp = WMGetTextFieldText(panel->threT); if (strlen(tmp) == 0) { wfree(tmp); tmp = wstrdup("4"); } sprintf(buffer, XSET " m %i/%i %s\n", (int)(panel->acceleration * 10), 10, tmp); storeCommandInScript(XSET " m", buffer); wfree(tmp); } tmp = WMGetTextFieldText(panel->ddelaT); if (sscanf(tmp, "%i", &i) == 1 && i > 0) SetIntegerForKey(i, "DoubleClickTime"); wfree(tmp); SetBoolForKey(WMGetButtonSelected(panel->disaB), "DisableWSMouseActions"); for (i = 0; i < wlengthof(button_list); i++) { const char *db_value; int action; action = WMGetPopUpButtonSelectedItem(panel->mouse_action[i].popup); if (button_list[i].type == T_BUTTON) db_value = button_actions[action].db_value; else db_value = wheel_actions[action].db_value; SetStringForKey(db_value, button_list[i].db_key); } tmp = WMGetPopUpButtonItem(panel->grabP, WMGetPopUpButtonSelectedItem(panel->grabP)); tmp = wstrdup(tmp); p = strchr(tmp, ' '); if (p != NULL) *p = '\0'; SetStringForKey(tmp, "ModifierKey"); wfree(tmp); }
void install(wchar_t *nam, wchar_t *val, int mode) { struct nlist *np; wchar_t *cp; int l; if (mode == PUSH) (void) lookup(nam); /* lookup sets hshval */ else while (undef(nam)) /* undef calls lookup */ ; np = xcalloc(1, sizeof (*np)); np->name = wstrdup(nam); np->next = hshtab[hshval]; hshtab[hshval] = np; cp = xcalloc((l = wcslen(val))+1, sizeof (*val)); np->def = cp; cp = &cp[l]; while (*val) *--cp = *val++; }
void WMSetMenuItemShortcut(WMMenuItem * item, const char *shortcut) { if (item->shortcutKey) wfree(item->shortcutKey); item->shortcutKey = wstrdup(shortcut); }
static Dict *install(char *name, uint versions, uint model, Parser *parser, CheckAttribs *chkattrs) { Dict *np; unsigned hashval; if ((np = lookup(name)) == null) { np = (Dict *)MemAlloc(sizeof(*np)); if (np == null || (np->name = wstrdup(name)) == null) return null; hashval = hash(name); np->next = hashtab[hashval]; np->model = 0; hashtab[hashval] = np; } np->versions = versions; np->model |= model; np->parser = parser; np->chkattrs = chkattrs; return np; }
static void browseForFile(WMWidget * self, void *clientData) { _Panel *panel = (_Panel *) clientData; WMFilePanel *filePanel; char *text, *oldprog, *newprog; filePanel = WMGetOpenPanel(WMWidgetScreen(self)); text = WMGetTextFieldText(panel->commandT); oldprog = wtrimspace(text); wfree(text); if (oldprog[0] == 0 || oldprog[0] != '/') { wfree(oldprog); oldprog = wstrdup("/"); } else { char *ptr = oldprog; while (*ptr && !isspace(*ptr)) ptr++; *ptr = 0; } WMSetFilePanelCanChooseDirectories(filePanel, False); if (WMRunModalFilePanelForDirectory(filePanel, panel->parent, oldprog, _("Select Program"), NULL) == True) { newprog = WMGetFilePanelFileName(filePanel); WMSetTextFieldText(panel->commandT, newprog); updateMenuItem(panel, panel->currentItem, panel->commandT); wfree(newprog); } wfree(oldprog); }
/*-------------------------------------- * Function: registerWindowClass() *------------------------------------*/ static void registerWindowClass(void) { WNDCLASSEXW wcx = { 0 }; wchar_t* class_name = wstrdup(ClassName); wcx.cbSize = sizeof(WNDCLASSEXW); wcx.style = CS_HREDRAW | CS_VREDRAW; wcx.lpfnWndProc = WindowProc; wcx.cbClsExtra = 0; wcx.cbWndExtra = 0; wcx.hInstance = GetModuleHandleW(NULL); wcx.hIcon = LoadIconW(NULL, IDI_APPLICATION); wcx.hCursor = LoadCursorW(NULL, IDC_ARROW); wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcx.lpszMenuName = NULL; wcx.lpszClassName = class_name; wcx.hIconSm = NULL; if (!RegisterClassExW(&wcx)) { free(class_name); error("could not register window class"); } free(class_name); }
/* returns the leaf an entry with the submenu spec `submenu' attaches to. * creates `submenu' path (anchored to the root) along the way. */ static WMTreeNode *findPositionInMenu(const char *submenu) { char *q; WMMenuEntry *wm; WMTreeNode *node, *pnode; char buf[1024]; /* qualify submenu with "Applications/" (the root node) */ memset(buf, 0, sizeof(buf)); snprintf(buf, sizeof(buf), "Applications/%s", submenu); /* start at the root */ node = menu; q = strtok(buf, "/"); while (q) { pnode = node; node = WMFindInTreeWithDepthLimit(pnode, nodeFindSubMenuByNameFunc, q, 1); if (!node) { wm = (WMMenuEntry *)wmalloc(sizeof(WMMenuEntry)); wm->Flags = 0; wm->Name = wstrdup(q); wm->CmdLine = NULL; wm->SubMenu = NULL; node = WMAddNodeToTree(pnode, WMCreateTreeNode(wm)); } q = strtok(NULL, "/"); } return node; }
/* an example to illustrate validateFilename. * with wmconfig, no special handling is needed */ Bool wmconfig_validate_file(const char *filename, const struct stat *st, int tflags, struct FTW *ftw) { (void)filename; (void)st; (void)tflags; (void)ftw; return True; #if 0 /* not dead code, example */ /* or we could have gone intro extremes */ char *base_name; Bool ret; (void)tflags; base_name = wstrdup(filename + ftw->base); ret = True; if (!S_ISREG(st->st_mode) || /* not a regular file */ (st->st_uid != 0 && st->st_uid != getuid()) || /* bad guy injected this file */ strpbrk(base_name, ".") || /* wmconfig typically has no extension */ st->st_size >= 128 * 131072 || /* noone writes wmconfig files > 128K */ st->st_size == 0 || /* nor empty ones */ ftw->level > 16) /* how did we get this deep? */ ret = False; wfree(base_name); return ret; #endif }
char *wfindfileinarray(WMPropList *array, const char *file) { int i; char *path; int len, flen; char *fullpath; if (!file) return NULL; if (*file == '/' || *file == '~' || !array) { if (access(file, F_OK) < 0) { fullpath = wexpandpath(file); if (!fullpath) return NULL; if (access(fullpath, F_OK) < 0) { wfree(fullpath); return NULL; } else { return fullpath; } } else { return wstrdup(file); } } flen = strlen(file); for (i = 0; i < WMGetPropListItemCount(array); i++) { WMPropList *prop; char *p; prop = WMGetFromPLArray(array, i); if (!prop) continue; p = WMGetFromPLString(prop); len = strlen(p); path = wmalloc(len + flen + 2); path = memcpy(path, p, len); path[len] = 0; if (wstrlcat(path, "/", len + flen + 2) >= len + flen + 2 || wstrlcat(path, file, len + flen + 2) >= len + flen + 2) { wfree(path); return NULL; } /* expand tilde */ fullpath = wexpandpath(path); wfree(path); if (fullpath) { /* check if file exists */ if (access(fullpath, F_OK) == 0) { return fullpath; } wfree(fullpath); } } return NULL; }
/* get a localized string value from line. allocates target, which must be wfreed later. * matching is dependent on the current value of target as well as on the * level the current value is matched on. guts matching algorithm is in * compare_matchlevel(). */ static void getLocalizedStringValue(char **target, const char *line, int *match_level) { const char *p; char *locale; int kstart; int sqbstart, sqbend; p = line; kstart = 0; sqbstart = 0; sqbend = 0; locale = NULL; /* skip until after '=', mark if '[' and ']' is found */ while (*(p + kstart) && *(p + kstart) != '=') { switch (*(p + kstart)) { case '[': sqbstart = kstart + 1;break; case ']': sqbend = kstart; break; default : break; } kstart++; } kstart++; /* skip whitespace */ while (isspace(*(p + kstart))) kstart++; if (sqbstart > 0 && sqbend > sqbstart) locale = wstrndup(p + sqbstart, sqbend - sqbstart); /* if there is no value yet and this is the default key, return */ if (!*target && !locale) { *match_level = MATCH_DEFAULT; *target = wstrdup(p + kstart); return; } if (compare_matchlevel(match_level, locale)) { wfree(locale); *target = wstrdup(p + kstart); return; } return; }
char *WDMGetHostAddr(struct sockaddr *from) { char ipbuf[128]; /* FIXME: I don't like fixed size buffers */ inet_ntop(from->sa_family, WDMSockaddrGetAddr(from, NULL), ipbuf, sizeof(ipbuf)); return wstrdup(ipbuf); }
/*-------------------------------------- * Function: registerWindowClass() *------------------------------------*/ static void unregisterWindowClass(void) { wchar_t* class_name = wstrdup(ClassName); if (!UnregisterClassW(class_name, GetModuleHandleW(NULL))) warn("could not unregister window class"); free(class_name); }
/* HTS_strdup: wrapper for strdup */ char *HTS_strdup(const char *string) { #ifdef FESTIVAL return (wstrdup(string)); #else char *buff = (char *) HTS_calloc(strlen(string) + 1, sizeof(char)); strcpy(buff, string); return buff; #endif /* FESTIVAL */ }
void wWorkspaceRename(WScreen *scr, int workspace, const char *name) { char buf[MAX_WORKSPACENAME_WIDTH + 1]; char *tmp; if (workspace >= w_global.workspace.count) return; /* trim white spaces */ tmp = wtrimspace(name); if (strlen(tmp) == 0) { snprintf(buf, sizeof(buf), _("Workspace %i"), workspace + 1); } else { strncpy(buf, tmp, MAX_WORKSPACENAME_WIDTH); } buf[MAX_WORKSPACENAME_WIDTH] = 0; wfree(tmp); /* update workspace */ wfree(w_global.workspace.array[workspace]->name); w_global.workspace.array[workspace]->name = wstrdup(buf); if (w_global.clip.ws_menu) { if (strcmp(w_global.clip.ws_menu->entries[workspace + MC_WORKSPACE1]->text, buf) != 0) { wfree(w_global.clip.ws_menu->entries[workspace + MC_WORKSPACE1]->text); w_global.clip.ws_menu->entries[workspace + MC_WORKSPACE1]->text = wstrdup(buf); wMenuRealize(w_global.clip.ws_menu); } } if (w_global.workspace.menu) { if (strcmp(w_global.workspace.menu->entries[workspace + MC_WORKSPACE1]->text, buf) != 0) { wfree(w_global.workspace.menu->entries[workspace + MC_WORKSPACE1]->text); w_global.workspace.menu->entries[workspace + MC_WORKSPACE1]->text = wstrdup(buf); wMenuRealize(w_global.workspace.menu); } } if (w_global.clip.icon) wClipIconPaint(); WMPostNotificationName(WMNWorkspaceNameChanged, scr, (void *)(uintptr_t) workspace); }
void WMSetMenuItemTitle(WMMenuItem * item, const char *title) { if (item->title) wfree(item->title); if (title) item->title = wstrdup(title); else item->title = NULL; }
/* *---------------------------------------------------------------------- * findfile-- * Finds a file in a : separated list of paths. ~ expansion is also * done. * * Returns: * The complete path for the file (in a newly allocated string) or * NULL if the file was not found. * * Side effects: * A new string is allocated. It must be freed later. * *---------------------------------------------------------------------- */ char* wfindfile(char *paths, char *file) { char *path; char *tmp, *tmp2; int len, flen; char *fullpath; if (!file) return NULL; if (*file=='/' || *file=='~' || *file=='$' || !paths || *paths==0) { if (access(file, F_OK)<0) { fullpath = wexpandpath(file); if (!fullpath) return NULL; if (access(fullpath, F_OK)<0) { wfree(fullpath); return NULL; } else { return fullpath; } } else { return wstrdup(file); } } flen = strlen(file); tmp = paths; while (*tmp) { tmp = skipchar(tmp, ':'); if (*tmp==0) break; tmp2 = nextchar(tmp, ':'); len = tmp2 - tmp; path = wmalloc(len+flen+2); path = memcpy(path, tmp, len); path[len]=0; if (path[len-1] != '/') strcat(path, "/"); strcat(path, file); fullpath = wexpandpath(path); wfree(path); if (fullpath) { if (access(fullpath, F_OK)==0) { return fullpath; } wfree(fullpath); } tmp = tmp2; } return NULL; }
WMFont* WMCreateFont(WMScreen *scrPtr, char *fontName) { WMFont *font; Display *display = scrPtr->display; char *fname, *ptr; /* This is for back-compat (to allow reading of old xlfd descriptions) */ if (fontName[0]=='-' && (ptr = strchr(fontName, ','))) { // warn for deprecation fname = wmalloc(ptr - fontName + 1); strncpy(fname, fontName, ptr - fontName); fname[ptr - fontName] = 0; } else { fname = wstrdup(fontName); } font = WMHashGet(scrPtr->fontCache, fname); if (font) { WMRetainFont(font); wfree(fname); return font; } font = wmalloc(sizeof(WMFont)); memset(font, 0, sizeof(WMFont)); font->screen = scrPtr; // remove printf("WMCreateFont: %s\n", fname); if (fname[0] == '-') { // Backward compat thing. Remove in a later version font->font = XftFontOpenXlfd(display, scrPtr->screen, fname); } else { font->font = XftFontOpenName(display, scrPtr->screen, fname); } if (!font->font) { wfree(font); wfree(fname); return NULL; } font->height = font->font->ascent+font->font->descent; font->y = font->font->ascent; font->refCount = 1; font->name = fname; assert(WMHashInsert(scrPtr->fontCache, font->name, font)==NULL); return font; }
WCHAR* wcstoupper(const WCHAR *s) { WCHAR* u = NULL; WCHAR* p = NULL; for(u = p = wstrdup(s); *p; ++p) { *p=towupper(*p); } return u; }
WCHAR* wcstolower(const WCHAR *s) { WCHAR* l = NULL; WCHAR* p = NULL; for(l = p = wstrdup(s); *p; ++p) { *p=towlower(*p); } return l; }
char *WDMGetHostName(struct sockaddr *from) { struct hostent *he; void *addr; int len; addr = WDMSockaddrGetAddr(from, &len); if ((he = gethostbyaddr(addr, len, from->sa_family)) == NULL) return NULL; return wstrdup(he->h_name); }