本文整理汇总了C++中wstrdup函数的典型用法代码示例。如果您正苦于以下问题:C++ wstrdup函数的具体用法?C++ wstrdup怎么用?C++ wstrdup使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wstrdup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addWMMenuEntryCallback
/* 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);
}
示例2: xdg_to_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;
}
示例3: secure_getenv
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;
}
示例4: getMenuHierarchyFor
/* 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);
}
示例5: wFetchName
/* 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;
}
}
示例6: createWindow
/*--------------------------------------
* 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;
}
示例7: wmc_to_wm
/* 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;
}
示例8: wstrdup
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;
}
示例9: wstrdup
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;
}
示例10: storeData
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);
}
示例11: install
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++;
}
示例12: WMSetMenuItemShortcut
void WMSetMenuItemShortcut(WMMenuItem * item, const char *shortcut)
{
if (item->shortcutKey)
wfree(item->shortcutKey);
item->shortcutKey = wstrdup(shortcut);
}
示例13: hash
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;
}
示例14: browseForFile
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);
}
示例15: registerWindowClass
/*--------------------------------------
* 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);
}