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 --- TODO | 7 ++++--- draw.c | 2 ++ files.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ gramscii.c | 5 +++++ gramscii.h | 8 ++++++++ screen.c | 2 ++ 6 files changed, 68 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index 579ff78..d7e1535 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,7 @@ + optimize redraws (redraw only the modified rectangle) -- fir bug in reading commands from files +- fix bug in visual crop +- fix bug in reading commands from files - add screen geometry option (-g 25x80?) -- read file at point - - read output of command (!) - maybe move "text" mode to "t" - implement ellipse - (?) filled box (B) @@ -17,6 +16,8 @@ - allow scrolling (both vertical and horizontal) - catch SIGWINCH and react appropriately (after scrolling is enabled) +* read file at point + * read output of command (!) * fix bug with 'g' commands in arrow mode * undo (by storing lines changed across insert/remove operations) * re-organise undo-ring management diff --git a/draw.c b/draw.c index 8c30d56..49fad1b 100644 --- a/draw.c +++ b/draw.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 2 + #include #include 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 #include #include @@ -124,6 +126,9 @@ void commands(FILE *fc){ case 'U': redo_change(); break; + case 'r': + read_file_at(fc, x, y); + break; case 'q': check_modified(fc);/** FALLTHROUGH **/ case 'Q': diff --git a/gramscii.h b/gramscii.h index 2ec7088..6419961 100644 --- a/gramscii.h +++ b/gramscii.h @@ -1,6 +1,8 @@ #ifndef __GRAMSCII_H__ #define __GRAMSCII_H__ +#define _POSIX_C_SOURCE 2 + #include #include #include @@ -58,6 +60,10 @@ #define NEW_STATE 0x02 /**/ +/* file types */ +#define FFILE 0x01 +#define FPIPE 0x02 + /** types **/ typedef struct{ @@ -157,6 +163,7 @@ void go_to(int where); void crop_to_nonblank(); void crop_to_rect(); void erase_blank_lines(int y1, int y2); +int _isblank(int c); /**/ /** drawing-related functions **/ @@ -176,6 +183,7 @@ void write_file(FILE *fc); void check_modified(FILE *fc); void load_file(FILE *fc); void new_file(FILE *fc); +void read_file_at(FILE *fc, int xl, int yl); /**/ /** line-related functions **/ diff --git a/screen.c b/screen.c index 3c69541..5b2adc6 100644 --- a/screen.c +++ b/screen.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 2 + #include #include #include -- cgit v1.2.3