diff options
Diffstat (limited to 'files.c')
-rw-r--r-- | files.c | 47 |
1 files changed, 47 insertions, 0 deletions
@@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 2 + #include <stdio.h> #include <string.h> #include "gramscii.h" @@ -37,6 +39,7 @@ void write_file(FILE *fc){ fclose(fout); modified = 0; get_key(fc, "File saved."); + redraw(); } void check_modified(FILE *fc){ @@ -83,3 +86,47 @@ void new_file(FILE *fc){ modified=0; } +void read_file_at(FILE *fc, int xl, int yl){ + + char nfname[512], tmp[512], *fptr, *tptr; + FILE *fin; + int i, j; + char ftype; + + get_string(fc, "Read file: ", nfname, 511); + fptr = nfname; + while(*fptr && _isblank(*fptr)) + fptr ++; + if (*fptr == '!'){ + fin = popen(++fptr, "r"); + ftype = FPIPE; + } + else { + fin = fopen(fptr, "r"); + ftype = FFILE; + } + if (fin != NULL){ + copy_lines_to_ring(0, HEIGHT-1, PRV_STATE); + i = yl; + while((fgets(tmp, WIDTH+1, fin)) != NULL && i<HEIGHT){ + j = xl; + tptr = tmp; + if (strlen(tmp)) + tmp[strlen(tmp) - 1] = '\0'; + ensure_line_length(& (screen.l[i]), xl + strlen(tmp) + 1); + while (*tptr && j < WIDTH){ + set_xy(j, i, *tptr); + j++; + tptr ++; + } + i++; + } + if (ftype == FFILE) + fclose(fin); + else + pclose(fin); + modified = 1; + redraw(); + copy_lines_to_ring(yl, i-1, NEW_STATE); + } +} |