Move usage() to be with run() in x.c
[st.git] / st.c
diff --git a/st.c b/st.c
index d7bd32a..6338510 100644 (file)
--- a/st.c
+++ b/st.c
@@ -28,8 +28,6 @@
 #include <X11/cursorfont.h>
 #include <X11/Xft/Xft.h>
 
-char *argv0;
-
 #define Glyph Glyph_
 #define Font Font_
 
@@ -60,7 +58,7 @@ char *argv0;
 #define ISDELIM(u)             (utf8strchr(worddelimiters, u) != NULL)
 
 /* constants */
-#define ISO14755CMD            "dmenu -w %lu -p codepoint: </dev/null"
+#define ISO14755CMD            "dmenu -w \"$WINDOWID\" -p codepoint: </dev/null"
 
 enum cursor_movement {
        CURSOR_SAVE,
@@ -386,6 +384,13 @@ static const char base64_digits[] = {
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 };
 
+char
+base64dec_getc(const char **src)
+{
+       while (**src && !isprint(**src)) (*src)++;
+       return *((*src)++);
+}
+
 char *
 base64dec(const char *src)
 {
@@ -393,13 +398,13 @@ base64dec(const char *src)
        char *result, *dst;
 
        if (in_len % 4)
-               return NULL;
+               in_len += 4 - (in_len % 4);
        result = dst = xmalloc(in_len / 4 * 3 + 1);
        while (*src) {
-               int a = base64_digits[(unsigned char) *src++];
-               int b = base64_digits[(unsigned char) *src++];
-               int c = base64_digits[(unsigned char) *src++];
-               int d = base64_digits[(unsigned char) *src++];
+               int a = base64_digits[(unsigned char) base64dec_getc(&src)];
+               int b = base64_digits[(unsigned char) base64dec_getc(&src)];
+               int c = base64_digits[(unsigned char) base64dec_getc(&src)];
+               int d = base64_digits[(unsigned char) base64dec_getc(&src)];
 
                *dst++ = (a << 2) | ((b & 0x30) >> 4);
                if (c == -1)
@@ -699,7 +704,6 @@ execsh(void)
        setenv("SHELL", sh, 1);
        setenv("HOME", pw->pw_dir, 1);
        setenv("TERM", termname, 1);
-       xsetenv();
 
        signal(SIGCHLD, SIG_DFL);
        signal(SIGHUP, SIG_DFL);
@@ -1986,14 +1990,11 @@ tprinter(char *s, size_t len)
 void
 iso14755(const Arg *arg)
 {
-       unsigned long id = xwinid();
-       char cmd[sizeof(ISO14755CMD) + NUMMAXLEN(id)];
        FILE *p;
        char *us, *e, codepoint[9], uc[UTF_SIZ];
        unsigned long utf32;
 
-       snprintf(cmd, sizeof(cmd), ISO14755CMD, id);
-       if (!(p = popen(cmd, "r")))
+       if (!(p = popen(ISO14755CMD, "r")))
                return;
 
        us = fgets(codepoint, sizeof(codepoint), p);
@@ -2537,7 +2538,7 @@ tresize(int col, int row)
        }
 
        /* allocate any new rows */
-       for (/* i == minrow */; i < row; i++) {
+       for (/* i = minrow */; i < row; i++) {
                term.line[i] = xmalloc(col * sizeof(Glyph));
                term.alt[i] = xmalloc(col * sizeof(Glyph));
        }
@@ -2684,16 +2685,3 @@ cresize(int width, int height)
        tresize(col, row);
        xresize(col, row);
 }
-
-void
-usage(void)
-{
-       die("usage: %s [-aiv] [-c class] [-f font] [-g geometry]"
-           " [-n name] [-o file]\n"
-           "          [-T title] [-t title] [-w windowid]"
-           " [[-e] command [args ...]]\n"
-           "       %s [-aiv] [-c class] [-f font] [-g geometry]"
-           " [-n name] [-o file]\n"
-           "          [-T title] [-t title] [-w windowid] -l line"
-           " [stty_args ...]\n", argv0, argv0);
-}