diff options
-rw-r--r-- | entry.c | 17 | ||||
-rw-r--r-- | entry.o | bin | 3520 -> 4064 bytes | |||
-rw-r--r-- | read_cfg.c | 31 | ||||
-rw-r--r-- | read_cfg.o | bin | 5760 -> 6320 bytes |
4 files changed, 35 insertions, 13 deletions
@@ -22,17 +22,28 @@ char *get_epath(ENTRY *e); ENTRY *create_entry(char *new_name, char *new_path){ ENTRY *new; + char adjusted_path[BUF_LEN]; //double check if file exists if(access(new_path, F_OK) == -1){ - printf("Error: Invalid File Name \"%s\"\n", new_path); - return NULL; + //try to adjust the path, in case of lingering quotes + strcpy(adjusted_path, &new_path[1]); + adjusted_path[strlen(adjusted_path)-1] = '\0'; + + if(access(adjusted_path, F_OK) == -1){ + printf("Error: Invalid File Name \"%s\"\n", new_path); + return NULL; + } } + else strcpy(adjusted_path, new_path); + new = malloc(sizeof(ENTRY)); strcpy(new->name, new_name); - strcpy(new->path, new_path); + strcpy(new->path, adjusted_path); + printf("1 DEBUG: %s\n", adjusted_path); + printf("2 DEBUG: %s\n", adjusted_path); new->next = NULL; return new; Binary files differ@@ -61,14 +61,14 @@ void cfg_interp(){ void check_line(char *buffer){ char *delims = " \t\n"; char *tok = strtok(buffer, delims); - char *args[MAX_ARGS]; + char args[MAX_ARGS][BUF_LEN]; GROUP **g; int g_count; int i; - //initialize args to NULL + //initialize args to 0 for(i = 0; i < MAX_ARGS; i++){ - args[i] = NULL; + args[i][0] = '\0'; } i = 0; @@ -78,7 +78,16 @@ void check_line(char *buffer){ printf("Error: too many arguments\n"); return; } - args[i] = tok; + strcpy(args[i], tok); + //handle if an argument has spaces and is wrapped in quotes + if(tok[0] == '"'){ + while(tok[strlen(tok)-1] != '"'){ + tok = strtok(NULL, delims); + strcat(args[i], " "); + strcat(args[i], tok); + } + } + tok = strtok(NULL, delims); i++; } @@ -164,16 +173,18 @@ void handle_fname(char *path, char *group){ //directory is not real, report error to the user else printf("Error: \"%s\" bad path\n", dirname); } - } - //file name is okay - else{ - new = create_entry(path, path); - if(new != NULL){ - group_add(group, new); + //file name is okay + else{ + new = create_entry(path, path); + if(new != NULL){ + group_add(group, new); + } } } + else printf("Error: \"%s\" bad path\n", path); + return; } |