Fix bug #131 - Missing escape handling for # in config files.
Added support for escaping stuff in the configuration file parser.
This commit is contained in:
@@ -400,3 +400,51 @@ const char* get_timestamp(time_t now)
|
||||
sprintf(ts, "[%02d:%02d]", t->tm_hour, t->tm_min);
|
||||
return ts;
|
||||
}
|
||||
|
||||
void strip_off_ini_line_comments(char* line, int line_count)
|
||||
{
|
||||
char* p = line;
|
||||
char* out = line;
|
||||
int backslash = 0;
|
||||
|
||||
if (!*line)
|
||||
return;
|
||||
|
||||
for (; *p; p++)
|
||||
{
|
||||
if (!backslash)
|
||||
{
|
||||
if (*p == '\\')
|
||||
{
|
||||
backslash = 1;
|
||||
}
|
||||
else if (*p == '#')
|
||||
{
|
||||
*out = '\0';
|
||||
out++;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
*out = *p;
|
||||
out++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*p == '\\' || *p == '#' || *p == '\"')
|
||||
{
|
||||
*out = *p;
|
||||
out++;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARN("Invalid backslash escape on line %d", line_count);
|
||||
*out = *p;
|
||||
out++;
|
||||
}
|
||||
backslash = 0;
|
||||
}
|
||||
}
|
||||
*out = '\0';
|
||||
}
|
||||
|
||||
@@ -33,10 +33,12 @@ extern int is_valid_base32_char(char c);
|
||||
extern void base32_encode(const unsigned char* buffer, size_t len, char* result);
|
||||
extern void base32_decode(const char* src, unsigned char* dst, size_t len);
|
||||
extern char* strip_white_space(char* string);
|
||||
extern void strip_off_ini_line_comments(char* line, int line_count);
|
||||
|
||||
extern int file_read_lines(const char* file, void* data, file_line_handler_t handler);
|
||||
|
||||
|
||||
|
||||
extern const char* uhub_itoa(int val);
|
||||
extern const char* uhub_ulltoa(uint64_t val);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user