fix get_file returning null
This commit is contained in:
parent
dca031c1f3
commit
30c70e119e
3 changed files with 15 additions and 10 deletions
10
ccc.c
10
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);
|
||||
|
|
13
file.c
13
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
|
||||
{
|
||||
|
|
2
file.h
2
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;
|
||||
|
|
Loading…
Reference in a new issue