#if HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include "ltrace.h" #include "read_config_file.h" #include "output.h" #include "debug.h" /* * "void" ARGTYPE_VOID * "int" ARGTYPE_INT * "uint" ARGTYPE_UINT * "long" ARGTYPE_LONG * "ulong" ARGTYPE_ULONG * "octal" ARGTYPE_OCTAL * "char" ARGTYPE_CHAR * "string" ARGTYPE_STRING * "format" ARGTYPE_FORMAT * "addr" ARGTYPE_ADDR */ struct function * list_of_functions = NULL; static struct list_of_pt_t { 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 */ }; static enum arg_type str2type(char ** str) { struct list_of_pt_t * tmp = &list_of_pt[0]; while(tmp->name) { if (!strncmp(*str, tmp->name, strlen(tmp->name)) && index(" ,)#", *(*str+strlen(tmp->name)))) { *str += strlen(tmp->name); return tmp->pt; } tmp++; } return ARGTYPE_UNKNOWN; } static void eat_spaces(char ** str) { while(**str==' ') { (*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; int stacked = 0; 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; } while (stacked > 0); return (stacked == 0) ? pos : NULL; } static int line_no; static char * filename; static struct function * process_line (char * buf) { struct function fun; 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) { debug(3, " Skipping line %d", line_no); return NULL; } debug(4, " return_type = %d", fun.return_type); eat_spaces(&str); tmp = start_of_arg_sig(str); if (!tmp) { output_line(0, "Syntax error in `%s', line %d", filename, line_no); return NULL; } *tmp = '\0'; fun.name = strdup(str); str = tmp+1; debug(3, " name = %s", fun.name); fun.params_right = 0; for(i=0; iname); tmp->next = list_of_functions; list_of_functions = tmp; } } fclose(stream); }