|
|
@ -359,8 +359,14 @@ void drawBar (char *s) |
|
|
|
/* Open a file and put it into a buffer line by line */ |
|
|
|
/* Open a file and put it into a buffer line by line */ |
|
|
|
void fileOpen (char *filename) |
|
|
|
void fileOpen (char *filename) |
|
|
|
{ |
|
|
|
{ |
|
|
|
FILE *fp = fopen(filename, "r"); |
|
|
|
FILE *fd = fopen(filename, "a+"); |
|
|
|
if (fp == NULL) die("Cannot open file", BAD_FILE); |
|
|
|
if (fd == NULL) die("Cannot open file", BAD_FILE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Check if the file is empty first */ |
|
|
|
|
|
|
|
fseek (fd, 0, SEEK_END); |
|
|
|
|
|
|
|
int size = ftell(fd); |
|
|
|
|
|
|
|
if (size) { |
|
|
|
|
|
|
|
rewind(fd); |
|
|
|
|
|
|
|
|
|
|
|
/* Init the linebuffer */ |
|
|
|
/* Init the linebuffer */ |
|
|
|
char *line = NULL; |
|
|
|
char *line = NULL; |
|
|
@ -370,15 +376,18 @@ void fileOpen (char *filename) |
|
|
|
ssize_t linelen; |
|
|
|
ssize_t linelen; |
|
|
|
|
|
|
|
|
|
|
|
/* getline returns -1 if no new line is present */ |
|
|
|
/* getline returns -1 if no new line is present */ |
|
|
|
while ((linelen = getline(&line, &linecap, fp)) != -1) { |
|
|
|
while ((linelen = getline(&line, &linecap, fd)) != -1) { |
|
|
|
while (linelen > 0 && (line[linelen - 1] == '\n' || line[linelen - 1] == '\r')) |
|
|
|
while (linelen > 0 && (line[linelen - 1] == '\n' || line[linelen - 1] == '\r')) |
|
|
|
linelen--; |
|
|
|
linelen--; |
|
|
|
rowAddLast(&rows, line, linelen); |
|
|
|
rowAddLast(&rows, line, linelen); |
|
|
|
} |
|
|
|
} |
|
|
|
/* free the line buffer */ |
|
|
|
/* free the line buffer */ |
|
|
|
free(line); |
|
|
|
free(line); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
rowAddLast(&rows, " ", 1); |
|
|
|
|
|
|
|
} |
|
|
|
/* close the file */ |
|
|
|
/* close the file */ |
|
|
|
fclose(fp); |
|
|
|
fclose(fd); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*------------------------------------- file operations ----------------------------------*/ |
|
|
|
/*------------------------------------- file operations ----------------------------------*/ |
|
|
@ -581,7 +590,7 @@ void updateInfo (void) |
|
|
|
|
|
|
|
|
|
|
|
getmaxyx(stdscr, t.dim.y, t.dim.x); |
|
|
|
getmaxyx(stdscr, t.dim.y, t.dim.x); |
|
|
|
t.dim.y -= 1; |
|
|
|
t.dim.y -= 1; |
|
|
|
t.pad = decimalSize(rows.rownum - 1); |
|
|
|
t.pad = decimalSize(rows.rownum > 1 ? rows.rownum - 1 : 2); |
|
|
|
t.dim.x -= t.pad + 1; |
|
|
|
t.dim.x -= t.pad + 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|