mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Get rid of the LIFO history, an oldpath is enough
This commit is contained in:
parent
4b1b156a3b
commit
24567ce6f5
71
noice.c
71
noice.c
|
@ -16,7 +16,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "queue.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -50,13 +49,6 @@ struct entry {
|
||||||
mode_t mode;
|
mode_t mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct history {
|
|
||||||
char *path;
|
|
||||||
SLIST_ENTRY(history) entry;
|
|
||||||
};
|
|
||||||
|
|
||||||
SLIST_HEAD(histhead, history) histhead = SLIST_HEAD_INITIALIZER(histhead);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Layout:
|
* Layout:
|
||||||
* .---------
|
* .---------
|
||||||
|
@ -528,48 +520,6 @@ dentfind(struct entry *dents, int n, char *cwd, char *path)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
pushhist(char *path)
|
|
||||||
{
|
|
||||||
struct history *hist;
|
|
||||||
|
|
||||||
hist = xmalloc(sizeof(*hist));
|
|
||||||
hist->path = xstrdup(path);
|
|
||||||
SLIST_INSERT_HEAD(&histhead, hist, entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
pophist(void)
|
|
||||||
{
|
|
||||||
struct history *hist;
|
|
||||||
char *path;
|
|
||||||
|
|
||||||
/* Recall history */
|
|
||||||
hist = SLIST_FIRST(&histhead);
|
|
||||||
if (hist != NULL) {
|
|
||||||
path = hist->path;
|
|
||||||
SLIST_REMOVE_HEAD(&histhead, entry);
|
|
||||||
free(hist);
|
|
||||||
} else {
|
|
||||||
path = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
forgethist(void)
|
|
||||||
{
|
|
||||||
struct history *hist;
|
|
||||||
|
|
||||||
while (SLIST_EMPTY(&histhead) == 0) {
|
|
||||||
hist = SLIST_FIRST(&histhead);
|
|
||||||
SLIST_REMOVE_HEAD(&histhead, entry);
|
|
||||||
free(hist->path);
|
|
||||||
free(hist);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
browse(const char *ipath, const char *ifilter)
|
browse(const char *ipath, const char *ifilter)
|
||||||
{
|
{
|
||||||
|
@ -582,10 +532,10 @@ browse(const char *ipath, const char *ifilter)
|
||||||
regex_t filter_re;
|
regex_t filter_re;
|
||||||
char *cwd, *newpath;
|
char *cwd, *newpath;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
char *hpath;
|
char *oldpath;
|
||||||
|
|
||||||
cur = 0;
|
cur = 0;
|
||||||
hpath = NULL;
|
oldpath = NULL;
|
||||||
begin:
|
begin:
|
||||||
/* Path and filter should be malloc(3)-ed strings at all times */
|
/* Path and filter should be malloc(3)-ed strings at all times */
|
||||||
n = 0;
|
n = 0;
|
||||||
|
@ -607,10 +557,10 @@ begin:
|
||||||
qsort(dents, n, sizeof(*dents), entrycmp);
|
qsort(dents, n, sizeof(*dents), entrycmp);
|
||||||
|
|
||||||
/* Find cur from history */
|
/* Find cur from history */
|
||||||
cur = dentfind(dents, n, path, hpath);
|
cur = dentfind(dents, n, path, oldpath);
|
||||||
if (hpath != NULL) {
|
if (oldpath != NULL) {
|
||||||
free(hpath);
|
free(oldpath);
|
||||||
hpath = NULL;
|
oldpath = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -658,7 +608,6 @@ nochange:
|
||||||
case SEL_QUIT:
|
case SEL_QUIT:
|
||||||
free(path);
|
free(path);
|
||||||
free(filter);
|
free(filter);
|
||||||
forgethist();
|
|
||||||
dentfree(dents, n);
|
dentfree(dents, n);
|
||||||
return;
|
return;
|
||||||
case SEL_BACK:
|
case SEL_BACK:
|
||||||
|
@ -672,13 +621,12 @@ nochange:
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
dir = xdirname(path);
|
dir = xdirname(path);
|
||||||
free(path);
|
/* Save history */
|
||||||
|
oldpath = path;
|
||||||
path = dir;
|
path = dir;
|
||||||
/* Reset filter */
|
/* Reset filter */
|
||||||
free(filter);
|
free(filter);
|
||||||
filter = xstrdup(ifilter);
|
filter = xstrdup(ifilter);
|
||||||
/* Recall history */
|
|
||||||
hpath = pophist();
|
|
||||||
goto out;
|
goto out;
|
||||||
case SEL_GOIN:
|
case SEL_GOIN:
|
||||||
/* Cannot descend in empty directories */
|
/* Cannot descend in empty directories */
|
||||||
|
@ -718,8 +666,6 @@ nochange:
|
||||||
/* Reset filter */
|
/* Reset filter */
|
||||||
free(filter);
|
free(filter);
|
||||||
filter = xstrdup(ifilter);
|
filter = xstrdup(ifilter);
|
||||||
/* Remember history */
|
|
||||||
pushhist(path);
|
|
||||||
cur = 0;
|
cur = 0;
|
||||||
goto out;
|
goto out;
|
||||||
case S_IFREG:
|
case S_IFREG:
|
||||||
|
@ -781,7 +727,6 @@ nochange:
|
||||||
path = newpath;
|
path = newpath;
|
||||||
free(filter);
|
free(filter);
|
||||||
filter = xstrdup(ifilter); /* Reset filter */
|
filter = xstrdup(ifilter); /* Reset filter */
|
||||||
forgethist();
|
|
||||||
DPRINTF_S(path);
|
DPRINTF_S(path);
|
||||||
cur = 0;
|
cur = 0;
|
||||||
goto out;
|
goto out;
|
||||||
|
|
Loading…
Reference in a new issue