commit 094b94845f3e1c62c22c5ae376ec7725bf116bab
parent a1b37155abe7449ae6205c3b1dda43dfb0c94802
Author: Ed van Bruggen <ed@edryd.org>
Date: Fri, 29 Sep 2017 23:49:21 -0700
Remove strconcat()
Simple enough to implement directly in main()
Diffstat:
3 files changed, 8 insertions(+), 27 deletions(-)
diff --git a/nt.c b/nt.c
@@ -321,9 +321,14 @@ main(int argc, char *argv[])
if (argc <= 0 && neednt)
fgets(sub, MAX_SUB, stdin);
- else if (argc > 0)
- sub = strconcat(argv, argc);
- strtrim(sub);
+ else if (argc > 0) {
+ while (*argv) {
+ strcat(sub, *argv);
+ if (*(++argv))
+ strcat(sub, " ");
+ }
+ }
+ strtrim(sub); /* TODO replace by stopping newline from stdin */
mode();
diff --git a/str.c b/str.c
@@ -6,29 +6,6 @@
#include "util.h"
-/* compress array of strings to single string */
-char *
-strconcat(char **s, int c)
-{
- if (!s) die("strconcat: given null pointer");
-
- int len, i;
- char *ret;
-
- for (i = 0; i < c; i++)
- len += strlen(s[i]) + 1;
- ret = ecalloc(len, sizeof(char));
-
- strcpy(ret, s[0]);
- strcat(ret, " ");
- for (i = 1; i < c; i++) {
- strcat(ret, s[i]);
- strcat(ret, " ");
- }
-
- return ret;
-}
-
/* remove tailing or leading white space from s */
char *
strtrim(char *s)
diff --git a/str.h b/str.h
@@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
-char *strconcat(char **s, int c);
char *strtrim(char *s);
int strinlist(char *str, char **list, int listc);