diff options
| author | Steven Rostedt <srostedt@redhat.com> | 2010-02-12 15:54:00 -0500 |
|---|---|---|
| committer | Steven Rostedt <rostedt@goodmis.org> | 2010-02-12 15:54:00 -0500 |
| commit | 307d6dfc196e321073ffb8087319e685cf77bad6 (patch) | |
| tree | 51205c936e5f289f73d7916f0bf946035fae48eb | |
| parent | f641b1a3f9010ff2d4cf572d4e92e7e43cc34bbb (diff) | |
trace-cmd: Move functions into separate routine
Move the function like macros __print_symbolic() and friends into
their own routine. This will allow adding parsing to other types
of functions easier.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
| -rw-r--r-- | parse-events.c | 93 |
1 files changed, 51 insertions, 42 deletions
diff --git a/parse-events.c b/parse-events.c index 627f4a1..7b3b440 100644 --- a/parse-events.c +++ b/parse-events.c | |||
| @@ -1923,9 +1923,6 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok) | |||
| 1923 | memset(arg, 0, sizeof(*arg)); | 1923 | memset(arg, 0, sizeof(*arg)); |
| 1924 | arg->type = PRINT_FLAGS; | 1924 | arg->type = PRINT_FLAGS; |
| 1925 | 1925 | ||
| 1926 | if (read_expected_item(EVENT_DELIM, "(") < 0) | ||
| 1927 | goto out_err; | ||
| 1928 | |||
| 1929 | field = alloc_arg(); | 1926 | field = alloc_arg(); |
| 1930 | 1927 | ||
| 1931 | type = process_arg(event, field, &token); | 1928 | type = process_arg(event, field, &token); |
| @@ -1954,7 +1951,6 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok) | |||
| 1954 | 1951 | ||
| 1955 | out_free: | 1952 | out_free: |
| 1956 | free_token(token); | 1953 | free_token(token); |
| 1957 | out_err: | ||
| 1958 | *tok = NULL; | 1954 | *tok = NULL; |
| 1959 | return EVENT_ERROR; | 1955 | return EVENT_ERROR; |
| 1960 | } | 1956 | } |
| @@ -1969,9 +1965,6 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok) | |||
| 1969 | memset(arg, 0, sizeof(*arg)); | 1965 | memset(arg, 0, sizeof(*arg)); |
| 1970 | arg->type = PRINT_SYMBOL; | 1966 | arg->type = PRINT_SYMBOL; |
| 1971 | 1967 | ||
| 1972 | if (read_expected_item(EVENT_DELIM, "(") < 0) | ||
| 1973 | goto out_err; | ||
| 1974 | |||
| 1975 | field = alloc_arg(); | 1968 | field = alloc_arg(); |
| 1976 | 1969 | ||
| 1977 | type = process_arg(event, field, &token); | 1970 | type = process_arg(event, field, &token); |
| @@ -1990,7 +1983,6 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok) | |||
| 1990 | 1983 | ||
| 1991 | out_free: | 1984 | out_free: |
| 1992 | free_token(token); | 1985 | free_token(token); |
| 1993 | out_err: | ||
| 1994 | *tok = NULL; | 1986 | *tok = NULL; |
| 1995 | return EVENT_ERROR; | 1987 | return EVENT_ERROR; |
| 1996 | } | 1988 | } |
| @@ -2005,9 +1997,6 @@ process_dynamic_array(struct event_format *event, struct print_arg *arg, char ** | |||
| 2005 | memset(arg, 0, sizeof(*arg)); | 1997 | memset(arg, 0, sizeof(*arg)); |
| 2006 | arg->type = PRINT_DYNAMIC_ARRAY; | 1998 | arg->type = PRINT_DYNAMIC_ARRAY; |
| 2007 | 1999 | ||
| 2008 | if (read_expected_item(EVENT_DELIM, "(") < 0) | ||
| 2009 | goto out_err; | ||
| 2010 | |||
| 2011 | /* | 2000 | /* |
| 2012 | * The item within the parenthesis is another field that holds | 2001 | * The item within the parenthesis is another field that holds |
| 2013 | * the index into where the array starts. | 2002 | * the index into where the array starts. |
| @@ -2050,7 +2039,6 @@ process_dynamic_array(struct event_format *event, struct print_arg *arg, char ** | |||
| 2050 | out_free: | 2039 | out_free: |
| 2051 | free(arg); | 2040 | free(arg); |
| 2052 | free_token(token); | 2041 | free_token(token); |
| 2053 | out_err: | ||
| 2054 | *tok = NULL; | 2042 | *tok = NULL; |
| 2055 | return EVENT_ERROR; | 2043 | return EVENT_ERROR; |
| 2056 | } | 2044 | } |
| @@ -2117,9 +2105,6 @@ process_str(struct event_format *event __unused, struct print_arg *arg, char **t | |||
| 2117 | enum event_type type; | 2105 | enum event_type type; |
| 2118 | char *token; | 2106 | char *token; |
| 2119 | 2107 | ||
| 2120 | if (read_expected(EVENT_DELIM, "(") < 0) | ||
| 2121 | goto out_err; | ||
| 2122 | |||
| 2123 | if (read_expect_type(EVENT_ITEM, &token) < 0) | 2108 | if (read_expect_type(EVENT_ITEM, &token) < 0) |
| 2124 | goto out_free; | 2109 | goto out_free; |
| 2125 | 2110 | ||
| @@ -2143,6 +2128,32 @@ process_str(struct event_format *event __unused, struct print_arg *arg, char **t | |||
| 2143 | } | 2128 | } |
| 2144 | 2129 | ||
| 2145 | static enum event_type | 2130 | static enum event_type |
| 2131 | process_function(struct event_format *event, struct print_arg *arg, | ||
| 2132 | char *token, char **tok) | ||
| 2133 | { | ||
| 2134 | if (strcmp(token, "__print_flags") == 0) { | ||
| 2135 | free_token(token); | ||
| 2136 | return process_flags(event, arg, tok); | ||
| 2137 | } | ||
| 2138 | if (strcmp(token, "__print_symbolic") == 0) { | ||
| 2139 | free_token(token); | ||
| 2140 | return process_symbols(event, arg, tok); | ||
| 2141 | } | ||
| 2142 | if (strcmp(token, "__get_str") == 0) { | ||
| 2143 | free_token(token); | ||
| 2144 | return process_str(event, arg, tok); | ||
| 2145 | } | ||
| 2146 | if (strcmp(token, "__get_dynamic_array") == 0) { | ||
| 2147 | free_token(token); | ||
| 2148 | return process_dynamic_array(event, arg, tok); | ||
| 2149 | } | ||
| 2150 | |||
| 2151 | warning("function %s not defined", token); | ||
| 2152 | free_token(token); | ||
| 2153 | return EVENT_ERROR; | ||
| 2154 | } | ||
| 2155 | |||
| 2156 | static enum event_type | ||
| 2146 | process_arg_token(struct event_format *event, struct print_arg *arg, | 2157 | process_arg_token(struct event_format *event, struct print_arg *arg, |
| 2147 | char **tok, enum event_type type) | 2158 | char **tok, enum event_type type) |
| 2148 | { | 2159 | { |
| @@ -2156,38 +2167,36 @@ process_arg_token(struct event_format *event, struct print_arg *arg, | |||
| 2156 | if (strcmp(token, "REC") == 0) { | 2167 | if (strcmp(token, "REC") == 0) { |
| 2157 | free_token(token); | 2168 | free_token(token); |
| 2158 | type = process_entry(event, arg, &token); | 2169 | type = process_entry(event, arg, &token); |
| 2159 | } else if (strcmp(token, "__print_flags") == 0) { | 2170 | break; |
| 2160 | free_token(token); | 2171 | } |
| 2161 | type = process_flags(event, arg, &token); | 2172 | atom = token; |
| 2162 | } else if (strcmp(token, "__print_symbolic") == 0) { | 2173 | /* test the next token */ |
| 2163 | free_token(token); | 2174 | type = read_token_item(&token); |
| 2164 | type = process_symbols(event, arg, &token); | 2175 | |
| 2165 | } else if (strcmp(token, "__get_str") == 0) { | 2176 | /* |
| 2177 | * If the next token is a parenthesis, then this | ||
| 2178 | * is a function. | ||
| 2179 | */ | ||
| 2180 | if (type == EVENT_DELIM && strcmp(token, "(") == 0) { | ||
| 2166 | free_token(token); | 2181 | free_token(token); |
| 2167 | type = process_str(event, arg, &token); | 2182 | token = NULL; |
| 2168 | } else if (strcmp(token, "__get_dynamic_array") == 0) { | 2183 | /* this will free atom. */ |
| 2184 | type = process_function(event, arg, atom, &token); | ||
| 2185 | break; | ||
| 2186 | } | ||
| 2187 | /* atoms can be more than one token long */ | ||
| 2188 | while (type == EVENT_ITEM) { | ||
| 2189 | atom = realloc(atom, strlen(atom) + strlen(token) + 2); | ||
| 2190 | strcat(atom, " "); | ||
| 2191 | strcat(atom, token); | ||
| 2169 | free_token(token); | 2192 | free_token(token); |
| 2170 | type = process_dynamic_array(event, arg, &token); | ||
| 2171 | } else { | ||
| 2172 | atom = token; | ||
| 2173 | /* test the next token */ | ||
| 2174 | type = read_token_item(&token); | 2193 | type = read_token_item(&token); |
| 2175 | |||
| 2176 | /* atoms can be more than one token long */ | ||
| 2177 | while (type == EVENT_ITEM) { | ||
| 2178 | atom = realloc(atom, strlen(atom) + strlen(token) + 2); | ||
| 2179 | strcat(atom, " "); | ||
| 2180 | strcat(atom, token); | ||
| 2181 | free_token(token); | ||
| 2182 | type = read_token_item(&token); | ||
| 2183 | } | ||
| 2184 | |||
| 2185 | /* todo, test for function */ | ||
| 2186 | |||
| 2187 | arg->type = PRINT_ATOM; | ||
| 2188 | arg->atom.atom = atom; | ||
| 2189 | } | 2194 | } |
| 2195 | |||
| 2196 | arg->type = PRINT_ATOM; | ||
| 2197 | arg->atom.atom = atom; | ||
| 2190 | break; | 2198 | break; |
| 2199 | |||
| 2191 | case EVENT_DQUOTE: | 2200 | case EVENT_DQUOTE: |
| 2192 | case EVENT_SQUOTE: | 2201 | case EVENT_SQUOTE: |
| 2193 | arg->type = PRINT_ATOM; | 2202 | arg->type = PRINT_ATOM; |
