summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO.org31
-rw-r--r--buff.c29
-rw-r--r--buff.h4
-rw-r--r--main.c63
4 files changed, 109 insertions, 18 deletions
diff --git a/TODO.org b/TODO.org
index b4fcbbf..1600c0c 100644
--- a/TODO.org
+++ b/TODO.org
@@ -6,17 +6,20 @@
** DONE Change read_lines to use __get_lines (let fin point to the file to read from...)
-* IN-PROGRESS Commands [3/21]
-** IN-PROGRESS e
+* IN-PROGRESS Commands [5/23]
+** DONE e
+** TODO e !
** TODO W
** TODO E
+** TODO E !
** TODO j
-** TODO r
-** TODO #
** TODO t
** TODO m
+** TODO r
+** TODO #
** TODO s
-** TODO k
+** DONE k [1/1]
+*** DONE Check clear marks upon delete, change, move lines
** TODO g,G,v,V
** IN-PROGRESS q -- check for changes
** TODO h
@@ -24,14 +27,22 @@
** TODO Q
** TODO !
** TODO r !
-** TODO w !
+** TODO w
** DONE c
** DONE w
** DONE f
-* IN-PROGRESS Addresses [7/9]
-** TODO Test , extensively
+* IN-PROGRESS Addresses [11/14]
+** TODO Probably rethink (and rewrite) addressing
+** TODO Test "," extensively
+** DONE Reimplement offsets [3/3]
+*** DONE "," does not work as expected in "1,+10n"
+*** DONE addresses like "+1,+2" do not work properly
+*** DONE "+10n" does not work
+** DONE marks -- check "'ap" (it does not seem to work)
+** DONE address like '10n' does not seem to work
+** DONE marks ('a, 'b, etc...)
** DONE ?RE?
** DONE /RE/
*** DONE FIXME: it does not work if the second separator is missing
@@ -40,4 +51,6 @@
** DONE $
** DONE .
** DONE ;
-** TODO Offsets (+-)
+** IN-PROGRESS Offsets (+-) [0/2]
+*** TODO Test offsets like 1+10+10
+*** TODO test offsets like 10+-++--10
diff --git a/buff.c b/buff.c
index aa66a67..78bee0a 100644
--- a/buff.c
+++ b/buff.c
@@ -1,5 +1,6 @@
#include "buff.h"
#include <regex.h>
+#include <ctype.h>
line_t* __search_pos(int addr){
@@ -11,6 +12,20 @@ line_t* __search_pos(int addr){
return cur;
}
+int get_lineno(line_t *l){
+
+ line_t *t = b_start;
+ int i = 1;
+ while (t && t != l)
+ t = t->next, i+=1;
+ if (!l)
+ return -1;
+ else
+ return i;
+
+}
+
+
int __get_lines(FILE *fin, line_t **first, line_t **last, int *tot){
char buff[4096];
@@ -49,6 +64,7 @@ int __get_lines(FILE *fin, line_t **first, line_t **last, int *tot){
return n;
}
+
int read_file(){
FILE *fin;
@@ -96,11 +112,12 @@ void print_lines(char lineno){
for (i=1; i<addr2; i++) p = p->next;
pos = i;
cur = p;
- while(pos++ < addr1){
+ while(pos < addr1){
if (lineno)
printf("%d\t", pos);
printf("%s", cur->c);
cur = cur->next;
+ pos ++;
}
if (lineno)
printf("%d\t", pos);
@@ -365,4 +382,14 @@ int match(char **c, char bw){
}
+int mark(char *c){
+
+ fprintf (stderr, " >>>> mark: label: '%c'\n", *c);
+ if (!islower(*c))
+ return -1;
+ if (*(c+1) != '\n')
+ return -1;
+ marks[*c - 'a'] = __search_pos(addr1);
+ return 0;
+}
diff --git a/buff.h b/buff.h
index 2602434..5d58ef4 100644
--- a/buff.h
+++ b/buff.h
@@ -24,6 +24,7 @@ extern int num;
extern int pos;
extern int addr1, addr2;
extern char *fname;
+extern line_t *marks[26];
int read_lines(FILE *);
@@ -37,6 +38,9 @@ void delete_lines();
int write_lines();
int read_file();
int match(char **, char);
+int mark(char *c);
+int get_lineno(line_t*);
+
#endif /* __BUFF_H__ */
diff --git a/main.c b/main.c
index 5b58011..cc4289c 100644
--- a/main.c
+++ b/main.c
@@ -15,6 +15,7 @@ int pos = 0;
/* addr1 is the last address, while addr2 is the previous one */
int addr1, addr2;
char *fname;
+line_t* marks[26] = {NULL};
const char* skip_blank(const char **c){
@@ -27,8 +28,9 @@ const char* skip_blank(const char **c){
int get_addr(const char **cmd){
int addr, n, got;
- char sign = 0, comma = 0, semic = 0, DIR = FW;
+ char sign = 1, comma = 0, semic = 0, DIR = FW;
const char *c;
+ line_t *p;
addr1 = addr2 = -1;
c = *cmd;
@@ -49,17 +51,18 @@ int get_addr(const char **cmd){
}
else {
switch(*c){
- case '.':
+ case '.': /* cur line*/
if (addr1 > -1)
addr2 = addr1;
addr1 = pos;
break;
- case '$':
+ case '$': /* last line */
if (addr1 > -1)
addr2 = addr1;
addr1 = num;
break;
- case ',':
+ case ',': /* range 1 */
+ fprintf(stderr, " >>>> comma: addr1: %d addr2: %d pos: %d\n", addr1, addr2, pos);
comma = 1;
if (addr1 ==-1)
addr2 = 1, addr1=num;
@@ -68,7 +71,7 @@ int get_addr(const char **cmd){
return -1;
}
break;
- case ';':
+ case ';': /* range 2*/
semic = 1;
if (addr1 == -1)
addr2 = pos, addr1=num;
@@ -78,7 +81,7 @@ int get_addr(const char **cmd){
}
break;
case '?': DIR = BW;
- case '/':
+ case '/': /* match */
c++;
addr = match((char**) &c, DIR);
DIR = FW;
@@ -91,6 +94,41 @@ int get_addr(const char **cmd){
addr2 = addr1, addr1 = addr;
fprintf(stderr, " match (%d): addr1: %d addr2: %d pos: %d\n", DIR, addr1, addr2, pos);
break;
+ case '\'': /* mark */
+ fprintf(stderr, " >>>> address is a mark!!!\n");
+ c++;
+ p = marks[*c - 'a'];
+ if (!p)
+ E;
+ else
+ addr = get_lineno(p);
+ if (addr < 0)
+ marks[*c - 'a'] = NULL;
+ if (addr1 > -1)
+ addr2 = addr1;
+ addr1 = addr;
+ break;
+ case '-': sign = -1;
+ case '+':
+ fprintf(stderr, " >>>> +/-: addr1: %d addr2: %d pos: %d\n", addr1, addr2, pos);
+ addr2 = addr1;
+ addr1 = pos;
+ c ++;
+ c = skip_blank(&c);
+ if (! isdigit(*c)){
+ addr1 += sign;
+ }
+ else{
+ n = 0;
+ while(isdigit(*c)){
+ n = 10 * n + *c - '0', c++;
+ }
+ addr1 += sign * n;
+ }
+ c--;
+ fprintf(stderr, " >>>>AT_EXIT +/-: addr1: %d addr2: %d pos: %d\n", addr1, addr2, pos);
+ sign = +1;
+ break;
default:
goto check;
}
@@ -227,14 +265,23 @@ void main_loop(){
move_to_line(addr1, 0);
insert_lines();
break;
+ case 'k':
+ if (addr1 < 0)
+ addr1 = pos;
+ cmd ++;
+ if (mark(cmd))
+ E;
+ break;
case 'n': p = 1;
case 'p':
if (ret == 2){
CHECKADDR;
print_lines(p);
}
- else if (ret == 1)
- move_to_line(addr2, 1);
+ else if (ret == 1){
+ move_to_line(addr1, 0);
+ print_cur_line(p);
+ }
else if (ret == 0)
print_cur_line(p);
else if (ret == -1){