diff --git a/ccc.c b/ccc.c index 256ec79..9d71753 100644 --- a/ccc.c +++ b/ccc.c @@ -139,7 +139,7 @@ void list_cwd_files() exit(EXIT_FAILURE); } // can't be strncmp as that filter out dotfiles - if (strcmp(filename, ".") && strcmp(ep->d_name, "..")) + if (strcmp(filename, ".") && strcmp(filename, "..")) { add_file(filename); mvwprintw(windows[0].window, count + 1, 1, "%s", filename); @@ -159,15 +159,15 @@ void list_cwd_files() */ void highlight_current_line() { - for (int i = 0; i < files_len(); i++) + for (long i = 0; i < files_len(); i++) { if (i == current_selection) { wattron(windows[0].window, A_REVERSE); wattron(windows[0].window, COLOR_PAIR(1)); } - - mvwprintw(windows[0].window, i + 1, 1, "%s", get_filename(i)); // print actual file name + char *name = get_filename(i); + mvwprintw(windows[0].window, i + 1, 1, "%s", name); // print actual file name wattroff(windows[0].window, A_REVERSE); wattroff(windows[0].window, COLOR_PAIR(1)); } @@ -181,7 +181,7 @@ void highlight_current_line() */ void show_file_content() { - FILE *file = fopen(get_filename(current_selection), "rb"); + FILE *file = fopen(get_filename((long) current_selection), "rb"); if (file) { fseek(file, 0, SEEK_END); diff --git a/file.c b/file.c index 2924009..90b99ab 100644 --- a/file.c +++ b/file.c @@ -4,7 +4,7 @@ // files in a link list data structure typedef struct file { - char *filename; + char *name; // put some more useful stat here struct file *next; } file; @@ -35,7 +35,7 @@ long add_file(char *filename) { perror("ccc"); } - new_file->filename = buf; + new_file->name = buf; new_file->next = NULL; if (current == NULL) { @@ -73,9 +73,14 @@ file *get_file(long index) char *get_filename(long index) { file *file = get_file(index); - if (!file) + if (file != NULL) { - return file->filename; + char *name = strdup(file->name); + if (!name) + { + perror("ccc"); + } + return name; } else { diff --git a/file.h b/file.h index 79e4142..a3c1716 100644 --- a/file.h +++ b/file.h @@ -2,7 +2,7 @@ #define FILE_H_ typedef struct file { - char *filename; + char *name; // put some more useful stat here struct file *next; } file;