summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2018-05-03 22:53:01 +0100
committerKatolaZ <katolaz@freaknet.org>2018-05-03 22:53:01 +0100
commite5fc4ed9fb277d92ee24cd8e1bf5e305eb8e18f4 (patch)
tree582130f556849a086e696bb9eec282daa8889d9f /main.c
parentf6d4aa13577c2f7d8c18458123f83ea6de9712d7 (diff)
implemented REGEXP match on addresses
Diffstat (limited to 'main.c')
-rw-r--r--main.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/main.c b/main.c
index 1718a5b..5b58011 100644
--- a/main.c
+++ b/main.c
@@ -4,7 +4,8 @@
#include "buff.h"
#include <ctype.h>
-
+#define FW 0
+#define BW 1
line_t *b_start = NULL;
line_t *b_end = NULL;
@@ -26,7 +27,7 @@ const char* skip_blank(const char **c){
int get_addr(const char **cmd){
int addr, n, got;
- char sign = 0, comma = 0, semic = 0;
+ char sign = 0, comma = 0, semic = 0, DIR = FW;
const char *c;
addr1 = addr2 = -1;
@@ -76,6 +77,20 @@ int get_addr(const char **cmd){
return -1;
}
break;
+ case '?': DIR = BW;
+ case '/':
+ c++;
+ addr = match((char**) &c, DIR);
+ DIR = FW;
+ if (addr == -1){
+ return -1;
+ }
+ if (addr1 == -1)
+ addr1 = addr;
+ else
+ addr2 = addr1, addr1 = addr;
+ fprintf(stderr, " match (%d): addr1: %d addr2: %d pos: %d\n", DIR, addr1, addr2, pos);
+ break;
default:
goto check;
}
@@ -231,13 +246,19 @@ void main_loop(){
else
E;
break;
+ case '\0':
case '\n':
- if (addr1 > -1 && addr1 <=pos)
- move_to_line(addr1, 1);
- else if (addr2 <=pos)
- print_cur_line(p);
- else
+ fprintf(stderr, ">>>> void command\n");
+ if (ret < -1 )
E;
+ else {
+ if (addr1 > -1 && addr1 <=num)
+ move_to_line(addr1, 1);
+ else if (addr2 <=pos)
+ print_cur_line(p);
+ else
+ E;
+ }
break;
case 'q':
goto cleanup;
@@ -280,11 +301,8 @@ int main(int argc, char *argv[]){
if (argc > 1){
fname = malloc((strlen(argv[1])+1) * sizeof(char));
memcpy(fname, argv[1], strlen(argv[1]) + 1);
- if (!read_file())
- fclose(fin);
- else{
+ if (read_file())
perror(fname);
- }
}
main_loop();
addr1 = pos, addr2 = 1;