summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2019-08-09 07:08:35 +0100
committerKatolaZ <katolaz@freaknet.org>2019-08-09 07:08:35 +0100
commit62267b8424170f9b136892248a77dbed3fdcbbba (patch)
treedd741fdfa323382be5f6431ae6a63993aff6c13f
parent3ba178677800de55393f8ec80752ffe72660931a (diff)
add read-at-point function
-rw-r--r--TODO7
-rw-r--r--draw.c2
-rw-r--r--files.c47
-rw-r--r--gramscii.c5
-rw-r--r--gramscii.h8
-rw-r--r--screen.c2
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 <stdlib.h>
#include <string.h>
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 <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);
+ }
+}
diff --git a/gramscii.c b/gramscii.c
index 6dee819..8b84ec3 100644
--- a/gramscii.c
+++ b/gramscii.c
@@ -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':
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 <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 **/
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 <stdio.h>
#include <stdlib.h>
#include <string.h>