Browse Source

Code refactor

master
Arun Prakash Jana 5 years ago
parent
commit
67c33a5e80
No known key found for this signature in database GPG Key ID: A75979F35C080412
2 changed files with 18 additions and 22 deletions
  1. +3
    -3
      README.md
  2. +15
    -19
      src/nnn.c

+ 3
- 3
README.md View File

@@ -173,9 +173,9 @@ optional args:
-H show hidden files -H show hidden files
-i nav-as-you-type mode -i nav-as-you-type mode
-n version sort -n version sort
-o press Enter to open files
-p file selection file (stdout if '-')
-r show cp, mv progress on Linux
-o open files on Enter
-p file selection file [stdout if '-']
-r use advcpmv patched cp, mv
-s string filters [default: regex] -s string filters [default: regex]
-S du mode -S du mode
-t disable dir auto-select -t disable dir auto-select


+ 15
- 19
src/nnn.c View File

@@ -391,8 +391,8 @@ static const char * const messages[] = {
"invalid key", "invalid key",
"%F %T %z", "%F %T %z",
"/.nnnXXXXXX", "/.nnnXXXXXX",
"empty selection",
"utility missing",
"0 selected",
"missing dep",
}; };


/* Supported configuration environment variables */ /* Supported configuration environment variables */
@@ -775,7 +775,12 @@ static char *xbasename(char *path)
static int create_tmp_file() static int create_tmp_file()
{ {
xstrlcpy(g_tmpfpath + g_tmpfplen - 1, messages[STR_TMPFILE], TMP_LEN_MAX - g_tmpfplen); xstrlcpy(g_tmpfpath + g_tmpfplen - 1, messages[STR_TMPFILE], TMP_LEN_MAX - g_tmpfplen);
return mkstemp(g_tmpfpath);

int fd = mkstemp(g_tmpfpath);
if (fd == -1) {
DPRINTF_S(strerror(errno));
}
return fd;
} }


/* Writes buflen char(s) from buf to a file */ /* Writes buflen char(s) from buf to a file */
@@ -854,10 +859,8 @@ static bool listselbuf(void)
return FALSE; return FALSE;


fd = create_tmp_file(); fd = create_tmp_file();
if (fd == -1) {
DPRINTF_S("mkstemp failed!");
if (fd == -1)
return FALSE; return FALSE;
}


pos = seltofile(fd, NULL); pos = seltofile(fd, NULL);


@@ -2849,7 +2852,7 @@ static void printkv(kv *kvarr, int fd, uchar max)
* the binary size by around a hundred bytes. This would only * the binary size by around a hundred bytes. This would only
* have increased as we keep adding new options. * have increased as we keep adding new options.
*/ */
static bool show_help(const char *path)
static void show_help(const char *path)
{ {
int i, fd; int i, fd;
const char *start, *end; const char *start, *end;
@@ -2889,7 +2892,7 @@ static bool show_help(const char *path)


fd = create_tmp_file(); fd = create_tmp_file();
if (fd == -1) if (fd == -1)
return FALSE;
return;


start = end = helpstr; start = end = helpstr;
while (*end) { while (*end) {
@@ -2931,7 +2934,6 @@ static bool show_help(const char *path)


spawn(pager, g_tmpfpath, NULL, NULL, F_CLI); spawn(pager, g_tmpfpath, NULL, NULL, F_CLI);
unlink(g_tmpfpath); unlink(g_tmpfpath);
return TRUE;
} }


static int sum_bsizes(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) static int sum_bsizes(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
@@ -4015,7 +4017,6 @@ nochange:
{ {
if (ndents) if (ndents)
mkpath(path, dents[cur].name, newpath); mkpath(path, dents[cur].name, newpath);
r = TRUE;


switch (sel) { switch (sel) {
case SEL_ARCHIVELS: case SEL_ARCHIVELS:
@@ -4037,7 +4038,7 @@ nochange:
} }
break; break;
case SEL_HELP: case SEL_HELP:
r = show_help(path);
show_help(path);
break; break;
case SEL_RUNEDIT: case SEL_RUNEDIT:
spawn(editor, dents[cur].name, NULL, path, F_CLI); spawn(editor, dents[cur].name, NULL, path, F_CLI);
@@ -4050,11 +4051,6 @@ nochange:
break; break;
} }


if (!r) {
printwait(messages[UTIL_MISSING], &presel);
goto nochange;
}

/* In case of successful operation, reload contents */ /* In case of successful operation, reload contents */


/* Continue in navigate-as-you-type mode, if enabled */ /* Continue in navigate-as-you-type mode, if enabled */
@@ -4617,9 +4613,9 @@ static void usage(void)
" -H show hidden files\n" " -H show hidden files\n"
" -i nav-as-you-type mode\n" " -i nav-as-you-type mode\n"
" -n version sort\n" " -n version sort\n"
" -o press Enter to open files\n"
" -p file selection file (stdout if '-')\n"
" -r show cp, mv progress on Linux\n"
" -o open files on Enter\n"
" -p file selection file [stdout if '-']\n"
" -r use advcpmv patched cp, mv\n"
" -s string filters [default: regex]\n" " -s string filters [default: regex]\n"
" -S du mode\n" " -S du mode\n"
" -t disable dir auto-select\n" " -t disable dir auto-select\n"


Loading…
Cancel
Save