summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatolaZ <[email protected]>2018-05-24 11:07:17 +0100
committerKatolaZ <[email protected]>2018-05-24 11:07:17 +0100
commit8a4e57da301445ae4ad7bf06a7ce18c3091ac9df (patch)
tree36ae4e6ea486c704410ec970824968302b6c4fcc
parentd95e611ed47253c7cf2b170537d5aa400ffc8093 (diff)
refactored address and ','
-rw-r--r--main.c64
1 files changed, 12 insertions, 52 deletions
diff --git a/main.c b/main.c
index fe26675..20e52d0 100644
--- a/main.c
+++ b/main.c
@@ -44,41 +44,25 @@ int get_addr(const char **cmd){
n = n * 10 + *c - '0', c++;
}
if (got){
- if (addr1 > -1 )
- addr2 = addr1;
addr1 = n;
}
}
else {
switch(*c){
case '.': /* cur line*/
- if (addr1 > -1)
- addr2 = addr1;
addr1 = pos;
break;
case '$': /* last line */
- if (addr1 > -1)
- addr2 = addr1;
addr1 = num;
break;
case ',': /* range 1 */ /* refactor to set addr2 = addr1 */
fprintf(stderr, " >>>> comma: addr1: %d addr2: %d pos: %d\n", addr1, addr2, pos);
comma = 1;
- if (addr1 ==-1)
- addr2 = 1, addr1=num;
- else if (addr1 < addr2){
- *cmd = c++;
- return -1;
- }
+ addr2 = addr1;
break;
case ';': /* range 2*/
semic = 1;
- if (addr1 == -1)
- addr2 = pos, addr1=num;
- else if (addr1 < addr2){
- *cmd = c++;
- return -1;
- }
+ addr2 = addr1;
break;
case '?': DIR = BW;
case '/': /* match */
@@ -88,10 +72,7 @@ int get_addr(const char **cmd){
if (addr == -1){
return -1;
}
- if (addr1 == -1)
- addr1 = addr;
- else
- addr2 = addr1, addr1 = addr;
+ addr1 = addr;
fprintf(stderr, " match (%d): addr1: %d addr2: %d pos: %d\n", DIR, addr1, addr2, pos);
break;
case '\'': /* mark */
@@ -104,14 +85,11 @@ int get_addr(const char **cmd){
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;
/* the assignment below breaks stuff like 1++++ */
if (addr1 < 0)
addr1 = pos;
@@ -146,7 +124,7 @@ int get_addr(const char **cmd){
if (addr1 > num || addr2 > num)
return -2;
- if (addr1 == -1){
+ if (addr2 == -1){
if (comma){
addr1 = num;
addr2 = 1;
@@ -155,17 +133,11 @@ int get_addr(const char **cmd){
if (semic){
addr1 = num;
addr2 = pos;
- return 2;
}
- addr1 = addr2 = pos;
- return 0;
+ return 2;
}
- if (addr2 == -1){
- if (comma || semic){
- addr2 = addr1;
- return 2;
- }
- addr2 = pos;
+ if (addr1 == -1){
+ addr1 = addr2 = pos;
return 1;
}
return 2;
@@ -224,15 +196,11 @@ void main_loop(){
addr1 = addr2 = pos;
append_lines();
case 'd':
- if (ret == -1){
+ if (ret < 0){
E;
break;
}
- if (ret == 2){
- CHECKADDR;
- }
- if (ret == 1)
- addr2 = addr1;
+ CHECKADDR;
delete_lines();
break;
case 'e':
@@ -268,9 +236,9 @@ void main_loop(){
insert_lines();
break;
case 'k':
- if (addr1 < 0)
- addr1 = pos;
cmd ++;
+ if (addr1==-1)
+ addr1 = pos;
if (mark(cmd))
E;
break;
@@ -284,14 +252,6 @@ void main_loop(){
move_to_line(addr1, 0);
print_cur_line(p);
}
- else if (ret == 0)
- print_cur_line(p);
- else if (ret == -1){
- addr1 = num;
- addr2 = 1;
- move_to_line(addr2,0);
- print_lines(p);
- }
else
E;
break;
@@ -301,7 +261,7 @@ void main_loop(){
if (ret < -1 )
E;
else {
- if (addr1 > -1 && addr1 <=num)
+ if (addr1 <=num)
move_to_line(addr1, 1);
else if (addr2 <=pos)
print_cur_line(p);