Bladeren bron

Add pushhist(), pophist() and forgethist()

master
sin 10 jaren geleden
bovenliggende
commit
aedec0ddf3
1 gewijzigde bestanden met toevoegingen van 50 en 26 verwijderingen
  1. +50
    -26
      noice.c

+ 50
- 26
noice.c Bestand weergeven

@@ -482,6 +482,47 @@ dentfree(struct entry *dents, int n)
free(dents); free(dents);
} }


void
pushhist(int pos)
{
struct history *hist;

hist = xmalloc(sizeof(*hist));
hist->pos = pos;
SLIST_INSERT_HEAD(&histhead, hist, entry);
}

int
pophist(void)
{
struct history *hist;
int pos;

/* Recall history */
hist = SLIST_FIRST(&histhead);
if (hist != NULL) {
pos = hist->pos;
SLIST_REMOVE_HEAD(&histhead, entry);
free(hist);
} else {
pos = 0;
}

return pos;
}

void
forgethist(void)
{
struct history *hist;

while (!SLIST_EMPTY(&histhead)) {
hist = SLIST_FIRST(&histhead);
SLIST_REMOVE_HEAD(&histhead, entry);
free(hist);
}
}

void void
browse(const char *ipath, const char *ifilter) browse(const char *ipath, const char *ifilter)
{ {
@@ -530,7 +571,6 @@ begin:
char *dir; char *dir;
char *tmp; char *tmp;
regex_t re; regex_t re;
struct history *hist;


redraw: redraw:
nlines = MIN(LINES - 4, n); nlines = MIN(LINES - 4, n);
@@ -569,11 +609,7 @@ nochange:
free(path); free(path);
free(filter); free(filter);
/* Forget history */ /* Forget history */
while (!SLIST_EMPTY(&histhead)) { forgethist();
hist = SLIST_FIRST(&histhead);
SLIST_REMOVE_HEAD(&histhead, entry);
free(hist);
}
return; return;
case SEL_BACK: case SEL_BACK:
/* There is no going back */ /* There is no going back */
@@ -582,18 +618,11 @@ nochange:
dir = xdirname(path); dir = xdirname(path);
free(path); free(path);
path = dir; path = dir;
/* Reset filter */
free(filter); free(filter);
filter = xstrdup(ifilter); /* Reset filter */ filter = xstrdup(ifilter);
/* Recall history */ /* Recall history */
hist = SLIST_FIRST(&histhead); cur = pophist();
if (hist != NULL) {
cur = hist->pos;
DPRINTF_D(hist->pos);
SLIST_REMOVE_HEAD(&histhead, entry);
free(hist);
} else {
cur = 0;
}
goto out; goto out;
case SEL_GOIN: case SEL_GOIN:
/* Cannot descend in empty directories */ /* Cannot descend in empty directories */
@@ -615,12 +644,11 @@ nochange:
case S_IFDIR: case S_IFDIR:
free(path); free(path);
path = xrealpath(name); path = xrealpath(name);
/* Reset filter */
free(filter); free(filter);
filter = xstrdup(ifilter); /* Reset filter */ filter = xstrdup(ifilter);
/* Save history */ /* Remember history */
hist = xmalloc(sizeof(struct history)); pushhist(cur);
hist->pos = cur;
SLIST_INSERT_HEAD(&histhead, hist, entry);
cur = 0; cur = 0;
goto out; goto out;
case S_IFREG: case S_IFREG:
@@ -679,11 +707,7 @@ nochange:
free(filter); free(filter);
filter = xstrdup(ifilter); /* Reset filter */ filter = xstrdup(ifilter); /* Reset filter */
/* Forget history */ /* Forget history */
while (!SLIST_EMPTY(&histhead)) { forgethist();
hist = SLIST_FIRST(&histhead);
SLIST_REMOVE_HEAD(&histhead, entry);
free(hist);
}
DPRINTF_S(path); DPRINTF_S(path);
cur = 0; cur = 0;
goto out; goto out;


||||||
x
 
000:0
Laden…
Annuleren
Opslaan