+ char *t;
+
+ if ((t = strdup(s)) == NULL)
+ err(1, "strdup");
+ return t;
+}
+
+/* parse position string from -p, put results on config.posx, config.posy, and config.monitor */
+static void
+parseposition(char *optarg)
+{
+ long n;
+ char *s = optarg;
+ char *endp;
+
+ n = strtol(s, &endp, 10);
+ if (errno == ERANGE || n > INT_MAX || n < 0 || endp == s || *endp != 'x')
+ goto error;
+ config.posx = n;
+ s = endp+1;
+ n = strtol(s, &endp, 10);
+ if (errno == ERANGE || n > INT_MAX || n < 0 || endp == s)
+ goto error;
+ config.posy = n;
+ if (*endp == ':') {
+ s = endp+1;
+ mflag = 1;
+ if (strncasecmp(s, "CUR", 3) == 0) {
+ config.monitor = -1;
+ endp = s+3;
+ } else {
+ n = strtol(s, &endp, 10);
+ if (errno == ERANGE || n > INT_MAX || n < 0 || endp == s || *endp != '\0')
+ goto error;
+ config.monitor = n;
+ }
+ } else if (*endp != '\0') {
+ goto error;
+ }
+
+ return;
+
+error:
+ errx(1, "improper position: %s", optarg);
+}
+
+/* get configuration from X resources */
+static void
+getresources(void)
+{
+ char *type;
+ XrmValue xval;
+
+ if (xrm == NULL || xdb == NULL)
+ return;
+
+ if (XrmGetResource(xdb, "xmenu.borderWidth", "*", &type, &xval) == True)
+ GETNUM(config.border_pixels, xval.addr)
+ if (XrmGetResource(xdb, "xmenu.separatorWidth", "*", &type, &xval) == True)
+ GETNUM(config.separator_pixels, xval.addr)
+ if (XrmGetResource(xdb, "xmenu.height", "*", &type, &xval) == True)
+ GETNUM(config.height_pixels, xval.addr)
+ if (XrmGetResource(xdb, "xmenu.width", "*", &type, &xval) == True)
+ GETNUM(config.width_pixels, xval.addr)
+ if (XrmGetResource(xdb, "xmenu.gap", "*", &type, &xval) == True)
+ GETNUM(config.gap_pixels, xval.addr)
+ if (XrmGetResource(xdb, "xmenu.maxItems", "*", &type, &xval) == True)
+ GETNUM(config.max_items, xval.addr)
+ if (XrmGetResource(xdb, "xmenu.background", "*", &type, &xval) == True)
+ config.background_color = xval.addr;
+ if (XrmGetResource(xdb, "xmenu.foreground", "*", &type, &xval) == True)
+ config.foreground_color = xval.addr;
+ if (XrmGetResource(xdb, "xmenu.selbackground", "*", &type, &xval) == True)
+ config.selbackground_color = xval.addr;
+ if (XrmGetResource(xdb, "xmenu.selforeground", "*", &type, &xval) == True)
+ config.selforeground_color = xval.addr;
+ if (XrmGetResource(xdb, "xmenu.separator", "*", &type, &xval) == True)
+ config.separator_color = xval.addr;
+ if (XrmGetResource(xdb, "xmenu.border", "*", &type, &xval) == True)
+ config.border_color = xval.addr;
+ if (XrmGetResource(xdb, "xmenu.font", "*", &type, &xval) == True)
+ config.font = xval.addr;
+ if (XrmGetResource(xdb, "xmenu.alignment", "*", &type, &xval) == True) {
+ if (strcasecmp(xval.addr, "center") == 0)
+ config.alignment = CenterAlignment;
+ else if (strcasecmp(xval.addr, "left") == 0)
+ config.alignment = LeftAlignment;
+ else if (strcasecmp(xval.addr, "right") == 0)
+ config.alignment = RightAlignment;
+ }
+}
+
+/* set button global variable */
+static void
+setbutton(char *s)
+{
+ size_t len;
+
+ if ((len = strlen(s)) < 1)
+ return;
+ switch (s[len-1]) {
+ case '1': button = Button1; break;
+ case '2': button = Button2; break;
+ case '3': button = Button3; break;
+ default: button = atoi(&s[len-1]); break;
+ }
+}
+
+/* set modifier global variable */
+static void
+setmodifier(char *s)
+{
+ size_t len;
+
+ if ((len = strlen(s)) < 1)
+ return;
+ switch (s[len-1]) {
+ case '1': modifier = Mod1Mask; break;
+ case '2': modifier = Mod2Mask; break;
+ case '3': modifier = Mod3Mask; break;
+ case '4': modifier = Mod4Mask; break;
+ case '5': modifier = Mod5Mask; break;
+ default:
+ if (strcasecmp(s, "Alt") == 0) {
+ modifier = Mod1Mask;
+ } else if (strcasecmp(s, "Super") == 0) {
+ modifier = Mod4Mask;
+ }
+ break;
+ }
+}
+
+/* parse icon path string */
+static void
+parseiconpaths(char *s)
+{
+ if (s == NULL)
+ return;
+ free(iconstring);
+ iconstring = estrdup(s);
+ niconpaths = 0;
+ for (s = strtok(iconstring, ":"); s != NULL; s = strtok(NULL, ":")) {
+ if (niconpaths < MAXPATHS) {
+ iconpaths[niconpaths++] = s;
+ }
+ }
+}