summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2018-05-22 14:50:59 +0100
committerKatolaZ <katolaz@freaknet.org>2018-05-22 14:50:59 +0100
commit3a10703698af22f44a44d0a1bdd5fda28e4a4712 (patch)
treedb583ce30df1d0f9d4ebc953f02911ed84bfd01d /main.c
parente5fc4ed9fb277d92ee24cd8e1bf5e305eb8e18f4 (diff)
fixed several issues in offsets -- still incomplete
Diffstat (limited to 'main.c')
-rw-r--r--main.c63
1 files changed, 55 insertions, 8 deletions
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){