summaryrefslogtreecommitdiff
path: root/app/xterm/xstrings.c
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu@cvs.openbsd.org>2013-03-09 14:45:40 +0000
committerMatthieu Herrb <matthieu@cvs.openbsd.org>2013-03-09 14:45:40 +0000
commit5b3e1cd121a50c5c3b76c34d6c0e0c6430cefe93 (patch)
treebdbf56fc5e747e21dad1aabcf4c3275e8f62ce61 /app/xterm/xstrings.c
parente18c4ea24ad92ea4dd3afea7e9a3a583f143cacd (diff)
Update to xterm 291. Tested by many.
Diffstat (limited to 'app/xterm/xstrings.c')
-rw-r--r--app/xterm/xstrings.c117
1 files changed, 72 insertions, 45 deletions
diff --git a/app/xterm/xstrings.c b/app/xterm/xstrings.c
index 395def5ab..9b0e1a868 100644
--- a/app/xterm/xstrings.c
+++ b/app/xterm/xstrings.c
@@ -1,7 +1,7 @@
-/* $XTermId: xstrings.c,v 1.50 2012/03/30 10:54:12 tom Exp $ */
+/* $XTermId: xstrings.c,v 1.57 2013/02/03 22:11:25 tom Exp $ */
/*
- * Copyright 2000-2011,2012 by Thomas E. Dickey
+ * Copyright 2000-2012,2013 by Thomas E. Dickey
*
* All Rights Reserved
*
@@ -64,10 +64,6 @@ x_basename(char *name)
char *cp;
cp = strrchr(name, '/');
-#ifdef __UNIXOS2__
- if (cp == 0)
- cp = strrchr(name, '\\');
-#endif
return (cp ? cp + 1 : name);
}
@@ -168,6 +164,7 @@ login_alias(char *login_name, uid_t uid, struct passwd *in_out)
/* use the other passwd-data including shell */
alloc_pw(in_out, &pw2);
} else {
+ free(login_name);
login_name = NULL;
}
}
@@ -188,6 +185,7 @@ x_getlogin(uid_t uid, struct passwd *in_out)
login_name = login_alias(x_getenv("LOGNAME"), uid, in_out);
if (IsEmpty(login_name)) {
+ free(login_name);
login_name = login_alias(x_getenv("USER"), uid, in_out);
}
#ifdef HAVE_GETLOGIN
@@ -199,14 +197,15 @@ x_getlogin(uid_t uid, struct passwd *in_out)
*/
if (IsEmpty(login_name)) {
TRACE2(("...try getlogin\n"));
- login_name = login_alias(getlogin(), uid, in_out);
+ free(login_name);
+ login_name = login_alias(x_strdup(getlogin()), uid, in_out);
}
#endif
- if (IsEmpty(login_name))
- login_name = in_out->pw_name;
- if (!IsEmpty(login_name))
- login_name = x_strdup(login_name);
+ if (IsEmpty(login_name)) {
+ free(login_name);
+ login_name = x_strdup(in_out->pw_name);
+ }
TRACE2(("x_getloginid ->%s\n", NonNull(login_name)));
return login_name;
@@ -303,6 +302,14 @@ x_skip_nonblanks(String s)
return s;
}
+static const char *
+skip_blanks(const char *s)
+{
+ while (isspace(CharOf(*s)))
+ ++s;
+ return s;
+}
+
/*
* Split a command-string into an argv[]-style array.
*/
@@ -312,38 +319,43 @@ x_splitargs(const char *command)
char **result = 0;
if (command != 0) {
- char *blob = x_strdup(command);
+ const char *first = skip_blanks(command);
+ char *blob = x_strdup(first);
size_t count;
size_t n;
int state;
int pass;
- for (pass = 0; pass < 2; ++pass) {
- for (n = count = 0, state = 0; command[n] != '\0'; ++n) {
- switch (state) {
- case 0:
- if (!isspace(CharOf(command[n]))) {
- state = 1;
- if (pass)
- result[count] = blob + n;
- ++count;
- } else {
- blob[n] = '\0';
+ if (blob != 0) {
+ for (pass = 0; pass < 2; ++pass) {
+ for (n = count = 0, state = 0; first[n] != '\0'; ++n) {
+ switch (state) {
+ case 0:
+ if (!isspace(CharOf(first[n]))) {
+ state = 1;
+ if (pass)
+ result[count] = blob + n;
+ ++count;
+ } else {
+ blob[n] = '\0';
+ }
+ break;
+ case 1:
+ if (isspace(CharOf(first[n]))) {
+ blob[n] = '\0';
+ state = 0;
+ }
+ break;
}
- break;
- case 1:
- if (isspace(CharOf(command[n]))) {
- blob[n] = '\0';
- state = 0;
+ }
+ if (!pass) {
+ result = TypeCallocN(char *, count + 1);
+ if (!result) {
+ free(blob);
+ break;
}
- break;
}
}
- if (!pass) {
- result = TypeCallocN(char *, count + 1);
- if (!result)
- break;
- }
}
} else {
result = TypeCalloc(char *);
@@ -351,6 +363,19 @@ x_splitargs(const char *command)
return result;
}
+/*
+ * Free storage allocated by x_splitargs().
+ */
+void
+x_freeargs(char **argv)
+{
+ if (argv != 0) {
+ if (*argv != 0)
+ free(*argv);
+ free(argv);
+ }
+}
+
int
x_strcasecmp(const char *s1, const char *s2)
{
@@ -426,17 +451,19 @@ x_strtrim(const char *source)
if (source != 0 && *source != '\0') {
char *t = x_strdup(source);
- s = t;
- d = s;
- while (isspace(CharOf(*s)))
- ++s;
- while ((*d++ = *s++) != '\0') {
- ;
- }
- if (*t != '\0') {
- s = t + strlen(t);
- while (s != t && isspace(CharOf(s[-1]))) {
- *--s = '\0';
+ if (t != 0) {
+ s = t;
+ d = s;
+ while (isspace(CharOf(*s)))
+ ++s;
+ while ((*d++ = *s++) != '\0') {
+ ;
+ }
+ if (*t != '\0') {
+ s = t + strlen(t);
+ while (s != t && isspace(CharOf(s[-1]))) {
+ *--s = '\0';
+ }
}
}
result = t;