summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO.org8
-rw-r--r--buff.c18
-rw-r--r--buff.h1
-rw-r--r--main.c14
-rw-r--r--obf.ed9
-rw-r--r--tests/test_exec.ed5
-rw-r--r--tests/test_mark.ed4
-rw-r--r--tests/testlist.txt1
8 files changed, 48 insertions, 12 deletions
diff --git a/TODO.org b/TODO.org
index 7ef8233..59e4d6f 100644
--- a/TODO.org
+++ b/TODO.org
@@ -2,7 +2,7 @@
* IN-PROGRESS FIXME
-** TODO Implement check on file modified
+** DONE Implement check on file modified
** TODO Check for marks in delete_lines
** DONE Reimplement delete_lines
** DONE Re-check insert/append (test_insapp failing with a double-free)
@@ -11,19 +11,19 @@
** DONE Change read_lines to use __get_lines (let fin point to the file to read from...)
-* IN-PROGRESS Commands [11/24]
+* IN-PROGRESS Commands [12/24]
** DONE e
** IN-PROGRESS !
** TODO e !
** TODO E !
-** IN-PROGRESS W
+** DONE W
** TODO w !
** TODO j
** TODO r
** TODO s
** IN-PROGRESS k [0/1]
*** TODO Check clear marks upon delete, change, move lines
-** TODO g,G,v,V
+** TODO (?) g,G,v,V
** TODO h
** TODO H
** TODO r !
diff --git a/buff.c b/buff.c
index fde4448..b5922a5 100644
--- a/buff.c
+++ b/buff.c
@@ -297,7 +297,7 @@ int write_lines(char app){
l = l->next;
}
fclose(fout);
- printf("%d\n", tot);
+ fprintf(stderr, "%d\n", tot);
return 0;
}
@@ -389,3 +389,19 @@ void transfer_lines(int addr, char move){
move_to_line(addr+n,0);
mod = 1;
}
+
+
+void exec_command(char *s, FILE *fout){
+
+ char buff[4096];
+ FILE *fin;
+
+ fin = popen(s, "r");
+ while(feof(fin) == 0){
+ if (!fgets(buff, 4095, fin)) break;
+ fputs(buff, fout);
+ }
+ pclose(fin);
+ printf("!\n");
+
+}
diff --git a/buff.h b/buff.h
index 257db0c..2ad6e6b 100644
--- a/buff.h
+++ b/buff.h
@@ -41,6 +41,7 @@ int match(char **, char);
int mark(char *c);
int get_lineno(line_t*);
void transfer_lines(int, char);
+void exec_command(char*, FILE*);
#endif /* __BUFF_H__ */
diff --git a/main.c b/main.c
index 8567596..00294cf 100644
--- a/main.c
+++ b/main.c
@@ -27,7 +27,7 @@ const char* skip_blank(const char **c){
int get_addr(const char **cmd){
- int addr, n, got;
+ int addr, n, got, d;
char sign = 1, comma = 0, semic = 0, DIR = FW;
const char *c;
line_t *p;
@@ -86,6 +86,11 @@ int get_addr(const char **cmd){
case '\'': /* mark */
fprintf(stderr, " >>>> address is a mark!!!\n");
c++;
+ d = *c - 'a';
+ if (d < 0 || d > 26){
+ E;
+ return -1;
+ }
p = marks[*c - 'a'];
if (!p)
E;
@@ -347,7 +352,10 @@ void main_loop(){
break;
case '!':
cmd += 1;
- //exec_command();
+ system(cmd);
+ printf("!\n");
+ /* exec_command(cmd, stdout); */
+ break;
case '=':
if (addr1 == -1)
addr1 = num;
@@ -385,7 +393,7 @@ int main(int argc, char *argv[]){
}
main_loop();
addr1 = num, addr2 = 1;
- delete_lines();
+ if (num>0) delete_lines();
free(fname);
}
diff --git a/obf.ed b/obf.ed
index 937b3f2..6d59658 100644
--- a/obf.ed
+++ b/obf.ed
@@ -26,10 +26,13 @@ H
1,$s/fprintf.*//g
1,$s/printf/P/g
1,$s/num_alloc/na/g
-1,$s/ -> /->/g
+1,$s/\ ->\ /->/g
1,$s/; */;/g
-1,$s/ = /=/g
-1,$s/ == /==/g
+1,$s/\ =\ /=/g
+1,$s/\ ==\ /==/g
+1,$s/\ <=\ /<=/g
1,$s/sizeof/S/g
+1,$s/malloc/M/g
+1,$s/\ +/\ /g
,p
Q
diff --git a/tests/test_exec.ed b/tests/test_exec.ed
new file mode 100644
index 0000000..935bd78
--- /dev/null
+++ b/tests/test_exec.ed
@@ -0,0 +1,5 @@
+!ls
+!ls -l
+! head pippo.c
+q
+q
diff --git a/tests/test_mark.ed b/tests/test_mark.ed
index df53f50..478bc3a 100644
--- a/tests/test_mark.ed
+++ b/tests/test_mark.ed
@@ -4,8 +4,10 @@
40kd
'a,'bn
'b,'dp
-'c','bn
+'c,'bn
'a+3
'b-4
'c++--
+'c'
+''a,'b'n
Q
diff --git a/tests/testlist.txt b/tests/testlist.txt
index 73a345c..d5f6d2a 100644
--- a/tests/testlist.txt
+++ b/tests/testlist.txt
@@ -7,3 +7,4 @@ test_tm.ed pippo.c
test_ew.ed pippo.c
test_comment.ed pippo.c
test_mark.ed pippo.c
+test_exec.ed pippo.c