diff options
author | Steven Rostedt <srostedt@redhat.com> | 2010-02-17 10:48:23 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2010-02-17 10:48:23 -0500 |
commit | fba106f1736ec0accd04aaaa1ce731801e67812f (patch) | |
tree | 643239440909a7fd9a406f3141e11b59666765c1 | |
parent | a5f716419f133132dfc6e1813aff7eb87344f526 (diff) |
parse-events: Move strim() to util.h
Add a util.h file to hold small functions that may be useful
for other files.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | parse-filter.c | 26 | ||||
-rw-r--r-- | util.h | 50 |
2 files changed, 51 insertions, 25 deletions
diff --git a/parse-filter.c b/parse-filter.c index c047560..52b8497 100644 --- a/parse-filter.c +++ b/parse-filter.c | |||
@@ -22,11 +22,11 @@ | |||
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <string.h> | 23 | #include <string.h> |
24 | #include <stdarg.h> | 24 | #include <stdarg.h> |
25 | #include <ctype.h> | ||
26 | #include <errno.h> | 25 | #include <errno.h> |
27 | #include <sys/types.h> | 26 | #include <sys/types.h> |
28 | 27 | ||
29 | #include "parse-events.h" | 28 | #include "parse-events.h" |
29 | #include "util.h" | ||
30 | 30 | ||
31 | struct event_list { | 31 | struct event_list { |
32 | struct event_list *next; | 32 | struct event_list *next; |
@@ -49,30 +49,6 @@ static void show_error(char **error_str, const char *fmt, ...) | |||
49 | va_end(ap); | 49 | va_end(ap); |
50 | } | 50 | } |
51 | 51 | ||
52 | static char *strim(char *string) | ||
53 | { | ||
54 | char *ret; | ||
55 | |||
56 | if (!string) | ||
57 | return NULL; | ||
58 | while (*string) { | ||
59 | if (!isspace(*string)) | ||
60 | break; | ||
61 | string++; | ||
62 | } | ||
63 | ret = string; | ||
64 | |||
65 | string = ret + strlen(ret) - 1; | ||
66 | while (string > ret) { | ||
67 | if (!isspace(*string)) | ||
68 | break; | ||
69 | string--; | ||
70 | } | ||
71 | string[1] = 0; | ||
72 | |||
73 | return ret; | ||
74 | } | ||
75 | |||
76 | static void free_token(char *token) | 52 | static void free_token(char *token) |
77 | { | 53 | { |
78 | pevent_free_token(token); | 54 | pevent_free_token(token); |
@@ -0,0 +1,50 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> | ||
3 | * | ||
4 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
5 | * This program is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU Lesser General Public | ||
7 | * License as published by the Free Software Foundation; | ||
8 | * version 2.1 of the License (not later!) | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Lesser General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Lesser General Public | ||
16 | * License along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | * | ||
19 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
20 | */ | ||
21 | #ifndef __UTIL_H | ||
22 | #define __UTIL_H | ||
23 | |||
24 | #include <ctype.h> | ||
25 | |||
26 | static inline char *strim(char *string) | ||
27 | { | ||
28 | char *ret; | ||
29 | |||
30 | if (!string) | ||
31 | return NULL; | ||
32 | while (*string) { | ||
33 | if (!isspace(*string)) | ||
34 | break; | ||
35 | string++; | ||
36 | } | ||
37 | ret = string; | ||
38 | |||
39 | string = ret + strlen(ret) - 1; | ||
40 | while (string > ret) { | ||
41 | if (!isspace(*string)) | ||
42 | break; | ||
43 | string--; | ||
44 | } | ||
45 | string[1] = 0; | ||
46 | |||
47 | return ret; | ||
48 | } | ||
49 | |||
50 | #endif | ||