ref: feeab3fe530af252f3e7062b9bc638fa72c4b348
parent: 4ca30bfbe8de3aa2727a4e32d7d32a54d4d29438
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sat Feb 20 15:30:34 EST 2016
search
--- a/zuke.c
+++ b/zuke.c
@@ -238,8 +238,9 @@
if(s[0] != '#' || s[1] != ' ' || !isdigit(s[2]) || strtol(s+2, &e, 10) != i)
sysfatal("invalid record");
+ s[-1] = 0;
sz = strtol(e, &s, 10);
- s++; /* skip '\n' */
+ *s++ = 0; /* skip '\n' */
if(s+sz > plraw+plrawsize)
sysfatal("truncated playlist");
s[sz-1] = 0; /* '\n'→'\0' to mark the end of the record */
@@ -274,13 +275,51 @@
else if(s[0] == Pdate) m->date = e;
else if(s[0] == Ptrack) m->track = e;
else sysfatal("unknown tag type %c", s[0]);
- s = e + tagsz+1;
+ s = e + tagsz + 1;
}
+ s[-1] = 0;
}
}
}
static void
+search(char d)
+{
+ char *s, *snext;
+ static char buf[48];
+ static int sz;
+ int inc;
+
+ inc = (d == '/' || d == 'n') ? 1 : -1;
+ if(d == '/' || d == '?')
+ sz = eenter(inc > 0 ? "forward:" : "backward:", buf, sizeof(buf), nil);
+ if(sz < 1 || (inc > 0 && pcur >= plnum-1) || (inc < 0 && pcur < 1))
+ return;
+
+ s = pl[pcur + (inc > 0 ? 0 : -1)].path;
+ s += strlen(s) + 1;
+ for(; s > plraw && s < plraw+plrawsize-sz; s += inc){
+ if(cistrncmp(s, buf, sz) != 0)
+ continue;
+ snext = s;
+ for(; s != plraw && *s; s--);
+ if(s == plraw || (s[1] != Partist && s[1] != Palbum && s[1] != Ptitle && s[1] != Pdate)){
+ if(inc > 0)
+ s = snext;
+ continue;
+ }
+ for(s--; s != plraw; s--){
+ if(memcmp(s, "\0# ", 3) == 0 && isdigit(s[3])){
+ pcur = atoi(s+3);
+ redraw(screen, 1);
+ return;
+ }
+ }
+ break;
+ }
+}
+
+static void
usage(void)
{
fprint(2, "usage: zuke [-b]\n");
@@ -392,6 +431,8 @@
player = nil;
}else if(e.kbdc == 'p'){
toggle(player);
+ }else if(e.kbdc == '/' || e.kbdc == '?' || e.kbdc == 'n' || e.kbdc == 'N'){
+ search(e.kbdc);
}
}