#include "emul_state.h"
#define LINE_LIMIT 1024
-#define TOKEN_LIMIT 128
+#define TOKEN_LIMIT 1024
#define OPTION_LIMIT 256
struct variable {
var->name = name;
var->value = value;
+
QTAILQ_INSERT_TAIL(&variables, var, entry);
}
int i = 0;
int start_index = -1;
int end_index = -1;
- char *str = g_strdup(src);
+ char *str;
+
+ // strip ""
+ int len = strlen(src);
+ if (src[0] == '"' && src[len - 1] == '"') {
+ src[len - 1] = '\0';
+ str = g_strdup(src + 1);
+ } else {
+ str = g_strdup(src);
+ }
for (i = 0; str[i]; ++i) {
if(str[i] == '$' && str[i + 1] && str[i + 1] == '{') {
bool load_profile_default(const char * const conf, const char * const profile)
{
- int classification = 0;
+ int classification = -1;
char str[LINE_LIMIT];
char *filename;
FILE *file = NULL;
do {
if (!str[i] ||
- (!in_quote &&
- (str[i] == ' ' || str[i] == '\t' || str[i] == '#'
- || str[i] == '\r' || str[i] == '\n')) ||
- (in_quote && str[i] == '"')) {
+ (!in_quote &&
+ (str[i] == ' ' || str[i] == '\t' || str[i] == '#'
+ || str[i] == '\r' || str[i] == '\n'))) {
if (start_index != -1) {
- g_strlcpy(token, str + start_index,
- i - start_index + 1);
+ int len = i - start_index + 1;
+ if (len < TOKEN_LIMIT) {
+ g_strlcpy(token, str + start_index, len);
+ }
+ else {
+ // TODO: error handling...
+ }
}
}
+ else if (str[i] == '"') {
+ in_quote = in_quote ? false : true;
+ }
else {
if (start_index < 0) {
- if (str[i] == '"') {
- in_quote = true;
- ++i;
- }
start_index = i;
}
}
// process line
switch (classification) {
+ case -1: // error
+ fprintf(stderr, "conf file error !!!\n");
+ // TODO: assert ??
+ break;
case 0: // default variables
{
gchar **splitted = g_strsplit(token, "=", 2);