mirror of
https://github.com/leahneukirchen/mblaze
synced 2024-11-09 19:10:32 +00:00
next: add offset, also negative
This commit is contained in:
parent
663dc56d8f
commit
9418394d14
3
Makefile
3
Makefile
@ -1,6 +1,6 @@
|
||||
CFLAGS=-g -O1 -Wall -Wno-switch -Wextra -Wwrite-strings -fstack-protector-strong -D_FORTIFY_SOURCE=2
|
||||
|
||||
ALL = scan thread hdr show list
|
||||
ALL = scan thread hdr show list next
|
||||
|
||||
all: $(ALL)
|
||||
|
||||
@ -9,6 +9,7 @@ thread: blaze822.o thread.o
|
||||
hdr: blaze822.o hdr.o
|
||||
show: blaze822.o show.o
|
||||
list: list.o
|
||||
next: next.o
|
||||
|
||||
clean: FRC
|
||||
-rm -f $(ALL) *.o
|
||||
|
28
next.c
28
next.c
@ -24,21 +24,37 @@ main(int argc, char *argv[])
|
||||
exit(102);
|
||||
|
||||
char *s = strstr(map, argv[1]);
|
||||
int a = 1;
|
||||
if (argc > 2)
|
||||
a = atoi(argv[2]);
|
||||
|
||||
if (!argv[1][0] || !s) {
|
||||
// default to first line
|
||||
s = map;
|
||||
} else {
|
||||
while (*s && *s != '\n')
|
||||
s++;
|
||||
s++;
|
||||
if (a > 0) {
|
||||
while (a-- > 0) {
|
||||
while (*s && *s != '\n')
|
||||
s++;
|
||||
s++;
|
||||
}
|
||||
} else {
|
||||
while (a++ <= 0 && map < s) {
|
||||
s--;
|
||||
while (map < s && *s != '\n')
|
||||
s--;
|
||||
}
|
||||
if (map < s && *s == '\n')
|
||||
s++;
|
||||
}
|
||||
}
|
||||
char *t = s;
|
||||
while (*t && *t != '\n')
|
||||
t++;
|
||||
if (!*t)
|
||||
exit(1);
|
||||
return 1;
|
||||
t++;
|
||||
write(1, s, t-s);
|
||||
|
||||
if (write(1, s, t-s) <= 0)
|
||||
return 2;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user