diff --git a/include/h.h b/include/h.h index 021c01589..97fe4b942 100644 --- a/include/h.h +++ b/include/h.h @@ -99,6 +99,7 @@ extern void module_loadall(void); extern long set_usermode(char *umode); extern char *get_usermode_string_raw(long umodes); extern ConfigFile *config_parse(char *filename, char *confdata); +extern ConfigFile *config_parse_with_offset(char *filename, char *confdata, unsigned int line_offset); extern void config_error(FORMAT_STRING(const char *format), ...) __attribute__((format(printf,1,2))); extern void config_warn(FORMAT_STRING(const char *format), ...) __attribute__((format(printf,1,2))); extern void config_error_missing(const char *filename, int line, const char *entry); diff --git a/src/conf.c b/src/conf.c index 2502147d8..bfaa6b4bd 100644 --- a/src/conf.c +++ b/src/conf.c @@ -196,6 +196,7 @@ long config_checkval(char *value, unsigned short flags); ConfigFile *config_load(char *filename, char *displayname); void config_free(ConfigFile *cfptr); +ConfigFile *config_parse_with_offset(char *filename, char *confdata, unsigned int line_offset); ConfigFile *config_parse(char *filename, char *confdata); ConfigEntry *config_find_entry(ConfigEntry *ce, char *name); @@ -886,14 +887,18 @@ char *unreal_add_quotes(char *str) return qbuf; } +ConfigFile *config_parse(char *filename, char *confdata){ + return config_parse_with_offset(filename, confdata, 0); +} + /* This is the internal parser, made by Chris Behrens & Fred Jacobs <2005. * Enhanced (or mutilated) by Bram Matthys over the years (2015-2019). */ -ConfigFile *config_parse(char *filename, char *confdata) +ConfigFile *config_parse_with_offset(char *filename, char *confdata, unsigned int line_offset) { char *ptr; char *start; - int linenumber = 1; + int linenumber = 1+line_offset; int errors = 0; int n; ConfigEntry *curce; diff --git a/src/modulemanager.c b/src/modulemanager.c index 0aea7a987..0e664f7a9 100644 --- a/src/modulemanager.c +++ b/src/modulemanager.c @@ -429,12 +429,12 @@ int mm_module_file_config(ManagedModule *m, ConfigEntry *ce) #undef CheckNull -int mm_parse_module_file(ManagedModule *m, char *buf) +int mm_parse_module_file(ManagedModule *m, char *buf, unsigned int line_offset) { ConfigFile *cf; ConfigEntry *ce; - cf = config_parse(m->name, buf); + cf = config_parse_with_offset(m->name, buf, line_offset); if (!cf) return 0; /* eg: parse errors */ @@ -462,7 +462,7 @@ ManagedModule *mm_parse_module_c_file(char *modulename, char *fname) ParseModuleHeaderStage parse_module_header = PMH_STAGE_LOOKING; ParseModuleConfigStage parse_module_config = PMC_STAGE_LOOKING; char *moduleconfig = NULL; - int linenr = 0; + int linenr = 0, module_config_start_line = 0; char module_header_name[128]; char module_header_version[64]; char module_header_description[256]; @@ -526,8 +526,10 @@ ManagedModule *mm_parse_module_c_file(char *modulename, char *fname) switch (parse_module_config) { case PMC_STAGE_LOOKING: - if (strstr(buf, "<<>>")) + if (strstr(buf, "<<>>")){ + module_config_start_line = linenr; parse_module_config = PMC_STAGE_STARTED; + } break; case PMC_STAGE_STARTED: if (!strstr(buf, "<<>>")) @@ -577,12 +579,12 @@ ManagedModule *mm_parse_module_c_file(char *modulename, char *fname) safe_strdup(m->description, module_header_description); safe_strdup(m->author, module_header_author); - if (!mm_parse_module_file(m, moduleconfig)) + if (!mm_parse_module_file(m, moduleconfig, module_config_start_line)) { fprintf(stderr, "ERROR: Unable to parse module manager data in the %s module.\n" "-- configuration block within %s --\n" "%s\n" - "-- end of configiguration within %s --\n" + "-- end of configuration within %s --\n" "You are suggested to contact the module author and paste the above to him/her\n", m->name, m->name,