diff options
author | KatolaZ <katolaz@freaknet.org> | 2019-08-09 07:08:35 +0100 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2019-08-09 07:08:35 +0100 |
commit | 62267b8424170f9b136892248a77dbed3fdcbbba (patch) | |
tree | dd741fdfa323382be5f6431ae6a63993aff6c13f | |
parent | 3ba178677800de55393f8ec80752ffe72660931a (diff) |
add read-at-point function
-rw-r--r-- | TODO | 7 | ||||
-rw-r--r-- | draw.c | 2 | ||||
-rw-r--r-- | files.c | 47 | ||||
-rw-r--r-- | gramscii.c | 5 | ||||
-rw-r--r-- | gramscii.h | 8 | ||||
-rw-r--r-- | screen.c | 2 |
6 files changed, 68 insertions, 3 deletions
@@ -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 @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 2 + #include <stdlib.h> #include <string.h> @@ -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); + } +} @@ -20,6 +20,8 @@ * */ +#define _POSIX_C_SOURCE 2 + #include <stdio.h> #include <stdlib.h> #include <signal.h> @@ -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': @@ -1,6 +1,8 @@ #ifndef __GRAMSCII_H__ #define __GRAMSCII_H__ +#define _POSIX_C_SOURCE 2 + #include <stdio.h> #include <termios.h> #include <unistd.h> @@ -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 **/ @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 2 + #include <stdio.h> #include <stdlib.h> #include <string.h> |