aboutsummaryrefslogtreecommitdiff
path: root/read_config_file.c
diff options
context:
space:
mode:
authorIan Wienand <ianw@ieee.org>2006-02-20 22:48:07 +0100
committerIan Wienand <ianw@debian.org>2006-02-20 22:48:07 +0100
commit2d45b1a8e26a36a9f85dc49e721c4390ca93dc40 (patch)
tree4e4f7ef60ae723e64af6495888730f2bc4468b19 /read_config_file.c
parent9a2ad351a1c3215dc596ff3e2e3fd4bc24445a6b (diff)
downloadltrace-2d45b1a8e26a36a9f85dc49e721c4390ca93dc40.tar.gz
run Lindent over source to get everything looking about the same
Diffstat (limited to 'read_config_file.c')
-rw-r--r--read_config_file.c132
1 files changed, 71 insertions, 61 deletions
diff --git a/read_config_file.c b/read_config_file.c
index bdceef5..2c54f44 100644
--- a/read_config_file.c
+++ b/read_config_file.c
@@ -24,50 +24,51 @@
* "addr" ARGTYPE_ADDR
*/
-struct function * list_of_functions = NULL;
+struct function *list_of_functions = NULL;
static struct list_of_pt_t {
- char * name;
+ char *name;
enum arg_type pt;
} list_of_pt[] = {
- { "void", ARGTYPE_VOID },
- { "int", ARGTYPE_INT },
- { "uint", ARGTYPE_UINT },
- { "long", ARGTYPE_LONG },
- { "ulong", ARGTYPE_ULONG },
- { "octal", ARGTYPE_OCTAL },
- { "char", ARGTYPE_CHAR },
- { "addr", ARGTYPE_ADDR },
- { "file", ARGTYPE_FILE },
- { "format", ARGTYPE_FORMAT },
- { "string", ARGTYPE_STRING },
- { "string0",ARGTYPE_STRING0 },
- { "string1",ARGTYPE_STRING1 },
- { "string2",ARGTYPE_STRING2 },
- { "string3",ARGTYPE_STRING3 },
- { "string4",ARGTYPE_STRING4 },
- { "string5",ARGTYPE_STRING5 },
- { NULL, ARGTYPE_UNKNOWN } /* Must finish with NULL */
+ {
+ "void", ARGTYPE_VOID}, {
+ "int", ARGTYPE_INT}, {
+ "uint", ARGTYPE_UINT}, {
+ "long", ARGTYPE_LONG}, {
+ "ulong", ARGTYPE_ULONG}, {
+ "octal", ARGTYPE_OCTAL}, {
+ "char", ARGTYPE_CHAR}, {
+ "addr", ARGTYPE_ADDR}, {
+ "file", ARGTYPE_FILE}, {
+ "format", ARGTYPE_FORMAT}, {
+ "string", ARGTYPE_STRING}, {
+ "string0", ARGTYPE_STRING0}, {
+ "string1", ARGTYPE_STRING1}, {
+ "string2", ARGTYPE_STRING2}, {
+ "string3", ARGTYPE_STRING3}, {
+ "string4", ARGTYPE_STRING4}, {
+ "string5", ARGTYPE_STRING5}, {
+ NULL, ARGTYPE_UNKNOWN} /* Must finish with NULL */
};
-static enum arg_type
-str2type(char ** str) {
- struct list_of_pt_t * tmp = &list_of_pt[0];
+static enum arg_type str2type(char **str)
+{
+ struct list_of_pt_t *tmp = &list_of_pt[0];
- while(tmp->name) {
+ while (tmp->name) {
if (!strncmp(*str, tmp->name, strlen(tmp->name))
- && index(" ,)#", *(*str+strlen(tmp->name)))) {
- *str += strlen(tmp->name);
- return tmp->pt;
+ && index(" ,)#", *(*str + strlen(tmp->name)))) {
+ *str += strlen(tmp->name);
+ return tmp->pt;
}
tmp++;
}
return ARGTYPE_UNKNOWN;
}
-static void
-eat_spaces(char ** str) {
- while(**str==' ') {
+static void eat_spaces(char **str)
+{
+ while (**str == ' ') {
(*str)++;
}
}
@@ -76,22 +77,28 @@ eat_spaces(char ** str) {
Returns position in string at the left parenthesis which starts the
function's argument signature. Returns NULL on error.
*/
-static char *
-start_of_arg_sig(char * str) {
- char * pos;
+static char *start_of_arg_sig(char *str)
+{
+ char *pos;
int stacked = 0;
- if (!strlen(str)) return NULL;
+ if (!strlen(str))
+ return NULL;
pos = &str[strlen(str)];
do {
pos--;
- if (pos < str) return NULL;
- while ((pos > str) && (*pos != ')') && (*pos != '(')) pos--;
-
- if (*pos == ')') stacked++;
- else if (*pos == '(') stacked--;
- else return NULL;
+ if (pos < str)
+ return NULL;
+ while ((pos > str) && (*pos != ')') && (*pos != '('))
+ pos--;
+
+ if (*pos == ')')
+ stacked++;
+ else if (*pos == '(')
+ stacked--;
+ else
+ return NULL;
} while (stacked > 0);
@@ -99,21 +106,21 @@ start_of_arg_sig(char * str) {
}
static int line_no;
-static char * filename;
+static char *filename;
-static struct function *
-process_line (char * buf) {
+static struct function *process_line(char *buf)
+{
struct function fun;
- struct function * fun_p;
- char * str = buf;
- char * tmp;
+ struct function *fun_p;
+ char *str = buf;
+ char *tmp;
int i;
line_no++;
debug(3, "Reading line %d of `%s'", line_no, filename);
eat_spaces(&str);
fun.return_type = str2type(&str);
- if (fun.return_type==ARGTYPE_UNKNOWN) {
+ if (fun.return_type == ARGTYPE_UNKNOWN) {
debug(3, " Skipping line %d", line_no);
return NULL;
}
@@ -121,38 +128,41 @@ process_line (char * buf) {
eat_spaces(&str);
tmp = start_of_arg_sig(str);
if (!tmp) {
- output_line(0, "Syntax error in `%s', line %d", filename, line_no);
+ output_line(0, "Syntax error in `%s', line %d", filename,
+ line_no);
return NULL;
}
*tmp = '\0';
fun.name = strdup(str);
- str = tmp+1;
+ str = tmp + 1;
debug(3, " name = %s", fun.name);
fun.params_right = 0;
- for(i=0; i<MAX_ARGS; i++) {
+ for (i = 0; i < MAX_ARGS; i++) {
eat_spaces(&str);
if (*str == ')') {
break;
}
- if (str[0]=='+') {
+ if (str[0] == '+') {
fun.params_right++;
str++;
} else if (fun.params_right) {
fun.params_right++;
}
fun.arg_types[i] = str2type(&str);
- if (fun.return_type==ARGTYPE_UNKNOWN) {
- output_line(0, "Syntax error in `%s', line %d", filename, line_no);
+ if (fun.return_type == ARGTYPE_UNKNOWN) {
+ output_line(0, "Syntax error in `%s', line %d",
+ filename, line_no);
return NULL;
}
eat_spaces(&str);
- if (*str==',') {
+ if (*str == ',') {
str++;
continue;
- } else if (*str==')') {
+ } else if (*str == ')') {
continue;
} else {
- output_line(0, "Syntax error in `%s', line %d", filename, line_no);
+ output_line(0, "Syntax error in `%s', line %d",
+ filename, line_no);
return NULL;
}
}
@@ -162,9 +172,9 @@ process_line (char * buf) {
return fun_p;
}
-void
-read_config_file(char * file) {
- FILE * stream;
+void read_config_file(char *file)
+{
+ FILE *stream;
char buf[1024];
filename = file;
@@ -175,9 +185,9 @@ read_config_file(char * file) {
if (!stream) {
return;
}
- line_no=0;
+ line_no = 0;
while (fgets(buf, 1024, stream)) {
- struct function * tmp = process_line(buf);
+ struct function *tmp = process_line(buf);
if (tmp) {
debug(2, "New function: `%s'", tmp->name);