From 62267b8424170f9b136892248a77dbed3fdcbbba Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Fri, 9 Aug 2019 07:08:35 +0100 Subject: add read-at-point function --- files.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'files.c') diff --git a/files.c b/files.c index dfeb3b2..37aac48 100644 --- a/files.c +++ b/files.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 2 + #include #include #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