summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatolaZ <[email protected]>2018-05-31 14:36:27 +0100
committerKatolaZ <[email protected]>2018-05-31 14:36:27 +0100
commit973479aa7fc254b887aed5fe6a57935648ee883c (patch)
tree791036edaccb2be9ed73514cf534bb41765ea344
parent00d893c8f8e742acc15e6675dec20c946dfb6fd7 (diff)
Check on modified files 'q'.Implemented 'W'.more tests.minor fixes
-rw-r--r--TODO.org25
-rw-r--r--buff.c23
-rw-r--r--buff.h4
-rw-r--r--main.c58
-rw-r--r--tests/test_comment.ed6
-rw-r--r--tests/test_ew.ed11
-rw-r--r--tests/test_incr.ed3
-rw-r--r--tests/test_mark.ed11
-rw-r--r--tests/test_tm.ed3
-rw-r--r--tests/testlist.txt3
10 files changed, 113 insertions, 34 deletions
diff --git a/TODO.org b/TODO.org
index 8a09683..7ef8233 100644
--- a/TODO.org
+++ b/TODO.org
@@ -11,28 +11,29 @@
** DONE Change read_lines to use __get_lines (let fin point to the file to read from...)
-* IN-PROGRESS Commands [7/23]
+* IN-PROGRESS Commands [11/24]
** DONE e
+** IN-PROGRESS !
** TODO e !
-** TODO W
-** TODO E
** TODO E !
+** IN-PROGRESS W
+** TODO w !
** TODO j
-** DONE t
-** DONE m
** TODO r
-** TODO #
** TODO s
-** DONE k [1/1]
-*** DONE Check clear marks upon delete, change, move lines
+** IN-PROGRESS k [0/1]
+*** TODO Check clear marks upon delete, change, move lines
** TODO g,G,v,V
-** IN-PROGRESS q -- check for changes
** TODO h
** TODO H
-** TODO Q
-** TODO !
** TODO r !
-** TODO w
+** DONE E
+** DONE #
+** DONE q -- check for changes
+** DONE Q
+** DONE w
+** DONE t
+** DONE m
** DONE c
** DONE w
** DONE f
diff --git a/buff.c b/buff.c
index c9d6800..fde4448 100644
--- a/buff.c
+++ b/buff.c
@@ -138,6 +138,7 @@ int read_file(){
cur = b_end;
fclose(fin);
fprintf(stderr, "%d\n", tot);
+ mod = 0;
return 0;
}
@@ -207,7 +208,7 @@ void append_lines(){
first = last = NULL;
n = __get_lines(stdin, &first, &last, &tot);
__append_lines(addr1, n, first, last);
-
+ mod = 1;
}
void insert_lines(){
@@ -221,7 +222,7 @@ void insert_lines(){
__append_lines(addr1, n, first, last);
else
__append_lines(addr1-1, n, first, last);
-
+ mod = 1;
}
@@ -264,7 +265,8 @@ void delete_lines(){
pos = addr2 - 1;
cur = prev;
}
- num -= addr1 - addr2 + 1;
+ num -= addr1 - addr2 + 1;
+ mod = 1;
}
@@ -276,15 +278,19 @@ void change_lines(){
-int write_lines(){
+int write_lines(char app){
FILE *fout;
line_t *l;
int tot=0;
-
- if (! (fout = fopen(fname, "w+"))){
- return -1;
- }
+ if (!app)
+ fout = fopen(fname, "w+");
+ else
+ fout = fopen(fname, "a");
+
+ if (!fout)
+ return -1;
+
l = b_start;
while(l){
tot += fprintf(fout, "%s", l->c);
@@ -381,4 +387,5 @@ void transfer_lines(int addr, char move){
}
__append_lines(addr, n, first, last);
move_to_line(addr+n,0);
+ mod = 1;
}
diff --git a/buff.h b/buff.h
index c23bebe..257db0c 100644
--- a/buff.h
+++ b/buff.h
@@ -23,7 +23,7 @@ extern line_t *cur;
extern int num;
extern int pos;
extern int addr1, addr2;
-extern char *fname;
+extern char *fname, mod;
extern line_t *marks[26];
@@ -35,7 +35,7 @@ void print_lineno();
void append_lines();
void insert_lines();
void delete_lines();
-int write_lines();
+int write_lines(char);
int read_file();
int match(char **, char);
int mark(char *c);
diff --git a/main.c b/main.c
index eb3b5ad..8567596 100644
--- a/main.c
+++ b/main.c
@@ -14,7 +14,7 @@ int num = 0;
int pos = 0;
/* addr1 is the last address, while addr2 is the previous one */
int addr1, addr2;
-char *fname;
+char *fname, mod=0, lc;
line_t* marks[26] = {NULL};
@@ -141,12 +141,12 @@ int get_addr(const char **cmd){
if (semic){
addr1 = num;
addr2 = pos;
- return 2;
+ return 2;
+ }
+ if (addr1 == -1){
+ addr1 = addr2 = pos;
+ return -1;
}
- return 1;
- }
- if (addr1 == -1){
- addr1 = addr2 = pos;
return 1;
}
return 2;
@@ -176,13 +176,13 @@ void main_loop(){
char *cmd, *c;
int ret, addr, tmp1, tmp2;
- char p, move;
+ char p, move, app;
cmd = malloc(256 * sizeof(char));
c = cmd;
while(1){
- p = 0; move = 0;
+ p = 0; move = 0, app = 0;
fgets(cmd, 255, stdin);
ret = get_addr((const char **) &cmd);
@@ -192,6 +192,7 @@ void main_loop(){
fprintf(stderr, ">>> *** addr1: %d, addr2= %d***\n", addr1, addr2);
}
+
switch(cmd[0]){
case 'a':
if (addr1 > -1)
@@ -208,7 +209,7 @@ void main_loop(){
addr1 = addr2 = pos;
append_lines();
case 'd':
- if (ret ==-1 )
+ if (ret == -1 )
addr2 = 1, addr1=num;
CHECKADDR;
if (addr1 == 0){
@@ -216,7 +217,14 @@ void main_loop(){
}
delete_lines();
break;
+ case 'E': mod = 0;
case 'e':
+ if (mod){
+ if (lc != 'e'){
+ E;
+ break;
+ }
+ }
cmd++;
skip_blank((const char**)&cmd);
if (cmd[0] == '!')
@@ -278,8 +286,14 @@ void main_loop(){
case '\0':
case '\n':
fprintf(stderr, ">>>> void command\n");
- if (ret < -1 )
- E;
+ if (ret == -1 ){
+ if (cur -> next){
+ cur = cur -> next, pos += 1;
+ print_cur_line(0);
+ }
+ else
+ E;
+ }
else {
if (addr1 <=num)
move_to_line(addr1, 1);
@@ -289,7 +303,17 @@ void main_loop(){
E;
}
break;
+ case 'Q': mod = 0;
case 'q':
+ fprintf(stderr, " >>>> q: mod: %d lc: %c\n", mod, lc);
+ if (mod){
+ if (lc == 'q')
+ goto cleanup;
+ else {
+ E;
+ break;
+ }
+ }
goto cleanup;
break;
case 'm': move = 1;
@@ -308,28 +332,38 @@ void main_loop(){
E;
move = 0;
break;
+ case 'W': app = 1;
case 'w':
cmd += 1;
get_fname(&cmd);
if (!fname)
E;
else{
- if (write_lines()){
+ if (write_lines(app)){
perror(fname);
E;
}
}
break;
+ case '!':
+ cmd += 1;
+ //exec_command();
case '=':
if (addr1 == -1)
addr1 = num;
print_lineno();
break;
+ case 'h': /* not impl. */
+ case 'H': /* not impl. */
+ case '#':
+ break;
default:
if (cmd[0])
fprintf(stderr, ">>> **** unknown command: '%c'****\n", cmd[0]);
E;
}
+ lc = cmd[0];
+ cmd = c;
}
cleanup:
free(c);
diff --git a/tests/test_comment.ed b/tests/test_comment.ed
new file mode 100644
index 0000000..238d026
--- /dev/null
+++ b/tests/test_comment.ed
@@ -0,0 +1,6 @@
+# an example of a comment
+1
+## another comment
+## and another
+10
+Q
diff --git a/tests/test_ew.ed b/tests/test_ew.ed
new file mode 100644
index 0000000..0b16d18
--- /dev/null
+++ b/tests/test_ew.ed
@@ -0,0 +1,11 @@
+4t1
+4m1
+e pippo.c
+e pippo.c
+5m3
+E pippo.c
+w pippo.c
+f pippo2.c
+W pippo2.c
+q
+q
diff --git a/tests/test_incr.ed b/tests/test_incr.ed
index 7e7df29..e1408c0 100644
--- a/tests/test_incr.ed
+++ b/tests/test_incr.ed
@@ -14,5 +14,8 @@
1++++++n
31+10+10
110+-++--10
+
+
+
q
q
diff --git a/tests/test_mark.ed b/tests/test_mark.ed
new file mode 100644
index 0000000..df53f50
--- /dev/null
+++ b/tests/test_mark.ed
@@ -0,0 +1,11 @@
+10ka
+20kb
+30kc
+40kd
+'a,'bn
+'b,'dp
+'c','bn
+'a+3
+'b-4
+'c++--
+Q
diff --git a/tests/test_tm.ed b/tests/test_tm.ed
index 29603c5..a7d7061 100644
--- a/tests/test_tm.ed
+++ b/tests/test_tm.ed
@@ -5,10 +5,13 @@
.=
1,25n
22m10
+.=
1,30n
130,135m10
+.=
2,50n
$m0
+.=
,n
5,7m31,2
q
diff --git a/tests/testlist.txt b/tests/testlist.txt
index 0756905..73a345c 100644
--- a/tests/testlist.txt
+++ b/tests/testlist.txt
@@ -4,3 +4,6 @@ test_incr.ed pippo.c
test_insapp.ed pippo.c
test_del.ed pippo.c
test_tm.ed pippo.c
+test_ew.ed pippo.c
+test_comment.ed pippo.c
+test_mark.ed pippo.c