These are three versions of the same function. Unify this
by making use of skip_whitespace() only.
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/ifaces.c | 10 +---------
src/ipfilter.c | 2 +-
src/iptraf-ng-compat.h | 4 ++--
src/parseproto.c | 12 ++----------
src/tui/input.c | 10 ----------
src/tui/labels.h | 1 -
6 files changed, 6 insertions(+), 33 deletions(-)
diff --git a/src/ifaces.c b/src/ifaces.c
index e13d39b..f5ff4e2 100644
--- a/src/ifaces.c
+++ b/src/ifaces.c
@@ -21,14 +21,6 @@ details.
#include "error.h"
-char *ltrim(char *buf)
-{
- while ((*buf == ' ') || (*buf == '\t'))
- buf++;
-
- return buf;
-}
-
/*
* Open /proc/net/dev and move file pointer past the two table header lines
* at the top of the file.
@@ -67,7 +59,7 @@ int get_next_iface(FILE * fd, char *ifname, int n)
fgets(buf, 160, fd);
if (strcmp(buf, "") != 0) {
memset(ifname, 0, n);
- strncpy(ifname, ltrim(strtok(buf, ":")), n);
+ strncpy(ifname, skip_whitespace(strtok(buf, ":")), n);
if (ifname[n - 1] != '\0')
strcpy(ifname, "");
return 1;
diff --git a/src/ipfilter.c b/src/ipfilter.c
index cffc81d..c688d20 100644
--- a/src/ipfilter.c
+++ b/src/ipfilter.c
@@ -121,7 +121,7 @@ void gethostparams(struct hostparams *data, char *init_saddr, char
*init_smask,
tx_addfield(&fields, 1, 12, 10, (data->filters[F_IPSEC_AH]) ? "Y" :
"");
tx_addfield(&fields, 1, 12, 23, (data->filters[F_IPSEC_ESP]) ? "Y" :
"");
- cptr = tx_ltrim(data->protolist);
+ cptr = skip_whitespace(data->protolist);
tx_addfield(&fields, 54, 15, 1, cptr);
tx_addfield(&fields, 1, 17, 1, initinex);
tx_addfield(&fields, 1, 17, 32, initmatchop);
diff --git a/src/iptraf-ng-compat.h b/src/iptraf-ng-compat.h
index 1289eb8..9fa6dff 100644
--- a/src/iptraf-ng-compat.h
+++ b/src/iptraf-ng-compat.h
@@ -123,12 +123,12 @@ extern void die(const char *err, ...);
extern void die_errno(const char *err) __noreturn;
extern void error(const char *err, ...);
-static inline char *skip_whitespace(const char *str)
+static inline char *skip_whitespace(char *str)
{
while (isspace(*str))
++str;
- return (char *) str;
+ return str;
}
#endif /* IPTRAF_NG_COMPAT_H */
diff --git a/src/parseproto.c b/src/parseproto.c
index 2c8d726..d0c0ede 100644
--- a/src/parseproto.c
+++ b/src/parseproto.c
@@ -15,9 +15,7 @@
* details.
*/
-#include <string.h>
-#include <ctype.h>
-#include <stdlib.h>
+#include "iptraf-ng-compat.h"
#include "parseproto.h"
@@ -31,13 +29,7 @@ static char *get_next_token(char **cptr)
i = 0;
-
- /*
- * Skip over leading whitespace
- */
-
- while (isspace(**cptr))
- (*cptr)++;
+ skip_whitespace(*cptr);
if (**cptr == ',' || **cptr == '-') {
rtoken[0] = **cptr;
diff --git a/src/tui/input.c b/src/tui/input.c
index 3206ddf..1620589 100644
--- a/src/tui/input.c
+++ b/src/tui/input.c
@@ -196,13 +196,3 @@ void tx_destroyfields(struct FIELDLIST *list)
del_panel(list->fieldpanel);
delwin(list->fieldwin);
}
-
-char *tx_ltrim(char *str)
-{
- char *cptr = str;
-
- while (isspace(*cptr))
- cptr++;
-
- return cptr;
-}
diff --git a/src/tui/labels.h b/src/tui/labels.h
index fb688e8..3073763 100644
--- a/src/tui/labels.h
+++ b/src/tui/labels.h
@@ -7,6 +7,5 @@ void tx_printkeyhelp(char *keytext, char *desc, WINDOW * win, int
highattr,
int textattr);
void tx_menukeyhelp(int textattr, int highattr);
void tx_listkeyhelp(int textattr, int highattr);
-char *tx_ltrim(char *str);
#endif /* IPTRAF_NG_TUI_LABELS_H */
--
1.7.8.4