Remove unnecessary indentation

This commit is contained in:
Arun Prakash Jana 2018-10-22 19:55:45 +05:30
parent 1562939325
commit 9731942946
No known key found for this signature in database
GPG key ID: A75979F35C080412

185
nnn.c
View file

@ -351,7 +351,8 @@ static const char messages[][16] = {
/* Forward declarations */ /* Forward declarations */
static void redraw(char *path); static void redraw(char *path);
static char * get_output(char *buf, size_t bytes, char *file, char *arg1, char *arg2, int pager); static char *get_output(char *buf, size_t bytes, char *file, char *arg1, char *arg2, int pager);
int (*nftw_fn) (const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf);
/* Functions */ /* Functions */
@ -359,8 +360,7 @@ static char * get_output(char *buf, size_t bytes, char *file, char *arg1, char *
* CRC8 source: * CRC8 source:
* https://barrgroup.com/Embedded-Systems/How-To/CRC-Calculation-C-Code * https://barrgroup.com/Embedded-Systems/How-To/CRC-Calculation-C-Code
*/ */
static void static void crc8init()
crc8init()
{ {
uchar remainder, bit; uchar remainder, bit;
uint dividend; uint dividend;
@ -384,8 +384,7 @@ crc8init()
} }
} }
static uchar static uchar crc8fast(uchar const message[], size_t n)
crc8fast(uchar const message[], size_t n)
{ {
static uchar data, remainder; static uchar data, remainder;
static size_t byte; static size_t byte;
@ -401,15 +400,13 @@ crc8fast(uchar const message[], size_t n)
} }
/* Messages show up at the bottom */ /* Messages show up at the bottom */
static void static void printmsg(const char *msg)
printmsg(const char *msg)
{ {
mvprintw(LINES - 1, 0, "%s\n", msg); mvprintw(LINES - 1, 0, "%s\n", msg);
} }
/* Kill curses and display error before exiting */ /* Kill curses and display error before exiting */
static void static void printerr(int linenum)
printerr(int linenum)
{ {
exitcurses(); exitcurses();
fprintf(stderr, "line %d: (%d) %s\n", linenum, errno, strerror(errno)); fprintf(stderr, "line %d: (%d) %s\n", linenum, errno, strerror(errno));
@ -419,16 +416,14 @@ printerr(int linenum)
} }
/* Print prompt on the last line */ /* Print prompt on the last line */
static void static void printprompt(char *str)
printprompt(char *str)
{ {
clearprompt(); clearprompt();
printw(str); printw(str);
} }
/* Increase the limit on open file descriptors, if possible */ /* Increase the limit on open file descriptors, if possible */
static rlim_t static rlim_t max_openfds()
max_openfds()
{ {
struct rlimit rl; struct rlimit rl;
rlim_t limit = getrlimit(RLIMIT_NOFILE, &rl); rlim_t limit = getrlimit(RLIMIT_NOFILE, &rl);
@ -460,8 +455,7 @@ max_openfds()
* Ubuntu: http://manpages.ubuntu.com/manpages/xenial/man3/malloc.3.html * Ubuntu: http://manpages.ubuntu.com/manpages/xenial/man3/malloc.3.html
* OS X: https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/malloc.3.html * OS X: https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/malloc.3.html
*/ */
static void * static void *xrealloc(void *pcur, size_t len)
xrealloc(void *pcur, size_t len)
{ {
static void *pmem; static void *pmem;
@ -477,8 +471,7 @@ xrealloc(void *pcur, size_t len)
* Always null ('\0') terminates if both src and dest are valid pointers. * Always null ('\0') terminates if both src and dest are valid pointers.
* Returns the number of bytes copied including terminating null byte. * Returns the number of bytes copied including terminating null byte.
*/ */
static size_t static size_t xstrlcpy(char *dest, const char *src, size_t n)
xstrlcpy(char *dest, const char *src, size_t n)
{ {
static ulong *s, *d; static ulong *s, *d;
static size_t len, blocks; static size_t len, blocks;
@ -536,8 +529,7 @@ xstrlcpy(char *dest, const char *src, size_t n)
* And we are NOT expecting a '/' at the end. * And we are NOT expecting a '/' at the end.
* Ideally 0 < n <= strlen(s). * Ideally 0 < n <= strlen(s).
*/ */
static void * static void *xmemrchr(uchar *s, uchar ch, size_t n)
xmemrchr(uchar *s, uchar ch, size_t n)
{ {
static uchar *ptr; static uchar *ptr;
@ -562,8 +554,7 @@ xmemrchr(uchar *s, uchar ch, size_t n)
* *
* Modified from the glibc (GNU LGPL) version. * Modified from the glibc (GNU LGPL) version.
*/ */
static char * static char *xdirname(const char *path)
xdirname(const char *path)
{ {
static char * const buf = g_buf, *last_slash, *runp; static char * const buf = g_buf, *last_slash, *runp;
@ -617,8 +608,7 @@ xdirname(const char *path)
return buf; return buf;
} }
static char * static char *xbasename(char *path)
xbasename(char *path)
{ {
static char *base; static char *base;
@ -627,8 +617,7 @@ xbasename(char *path)
} }
/* Writes buflen char(s) from buf to a file */ /* Writes buflen char(s) from buf to a file */
static void static void writecp(const char *buf, const size_t buflen)
writecp(const char *buf, const size_t buflen)
{ {
if (!g_cppath[0]) if (!g_cppath[0])
return; return;
@ -642,8 +631,7 @@ writecp(const char *buf, const size_t buflen)
printwarn(); printwarn();
} }
static bool static bool appendfpath(const char *path, const size_t len)
appendfpath(const char *path, const size_t len)
{ {
if ((copybufpos >= copybuflen) || ((len + 3) > (copybuflen - copybufpos))) { if ((copybufpos >= copybuflen) || ((len + 3) > (copybuflen - copybufpos))) {
copybuflen += PATH_MAX; copybuflen += PATH_MAX;
@ -675,8 +663,7 @@ appendfpath(const char *path, const size_t len)
return TRUE; return TRUE;
} }
static bool static bool showcplist()
showcplist()
{ {
ssize_t len; ssize_t len;
@ -708,8 +695,7 @@ showcplist()
/* /*
* Return number of dots if all chars in a string are dots, else 0 * Return number of dots if all chars in a string are dots, else 0
*/ */
static int static int all_dots(const char *path)
all_dots(const char *path)
{ {
int count = 0; int count = 0;
@ -726,8 +712,7 @@ all_dots(const char *path)
} }
/* Initialize curses mode */ /* Initialize curses mode */
static void static void initcurses(void)
initcurses(void)
{ {
if (initscr() == NULL) { if (initscr() == NULL) {
char *term = getenv("TERM"); char *term = getenv("TERM");
@ -756,8 +741,7 @@ initcurses(void)
* Spawns a child process. Behaviour can be controlled using flag. * Spawns a child process. Behaviour can be controlled using flag.
* Limited to 2 arguments to a program, flag works on bit set. * Limited to 2 arguments to a program, flag works on bit set.
*/ */
static void static void spawn(const char *file, const char *arg1, const char *arg2, const char *dir, uchar flag)
spawn(const char *file, const char *arg1, const char *arg2, const char *dir, uchar flag)
{ {
static char *shlvl; static char *shlvl;
static pid_t pid; static pid_t pid;
@ -811,8 +795,7 @@ spawn(const char *file, const char *arg1, const char *arg2, const char *dir, uch
} }
/* Get program name from env var, else return fallback program */ /* Get program name from env var, else return fallback program */
static char * static char *xgetenv(const char *name, char *fallback)
xgetenv(const char *name, char *fallback)
{ {
static char *value; static char *value;
@ -825,8 +808,7 @@ xgetenv(const char *name, char *fallback)
} }
/* Check if a dir exists, IS a dir and is readable */ /* Check if a dir exists, IS a dir and is readable */
static bool static bool xdiraccess(const char *path)
xdiraccess(const char *path)
{ {
static DIR *dirp; static DIR *dirp;
@ -848,8 +830,7 @@ xdiraccess(const char *path)
* *
* If the absolute numeric values are same, we fallback to alphasort. * If the absolute numeric values are same, we fallback to alphasort.
*/ */
static int static int xstricmp(const char * const s1, const char * const s2)
xstricmp(const char * const s1, const char * const s2)
{ {
static const char *c1, *c2; static const char *c1, *c2;
@ -896,8 +877,7 @@ xstricmp(const char * const s1, const char * const s2)
} }
/* Return the integer value of a char representing HEX */ /* Return the integer value of a char representing HEX */
static char static char xchartohex(char c)
xchartohex(char c)
{ {
if (c >= '0' && c <= '9') if (c >= '0' && c <= '9')
return c - '0'; return c - '0';
@ -909,8 +889,7 @@ xchartohex(char c)
return c; return c;
} }
static char * static char *getmime(const char *file)
getmime(const char *file)
{ {
static regex_t regex; static regex_t regex;
static uint i; static uint i;
@ -930,8 +909,7 @@ getmime(const char *file)
return NULL; return NULL;
} }
static int static int setfilter(regex_t *regex, char *filter)
setfilter(regex_t *regex, char *filter)
{ {
static size_t len; static size_t len;
static int r; static int r;
@ -948,20 +926,17 @@ setfilter(regex_t *regex, char *filter)
return r; return r;
} }
static void static void initfilter(int dot, char **ifilter)
initfilter(int dot, char **ifilter)
{ {
*ifilter = dot ? "." : "^[^.]"; *ifilter = dot ? "." : "^[^.]";
} }
static int static int visible(regex_t *regex, char *file)
visible(regex_t *regex, char *file)
{ {
return regexec(regex, file, 0, NULL, 0) == 0; return regexec(regex, file, 0, NULL, 0) == 0;
} }
static int static int entrycmp(const void *va, const void *vb)
entrycmp(const void *va, const void *vb)
{ {
static pEntry pa, pb; static pEntry pa, pb;
@ -1000,8 +975,7 @@ entrycmp(const void *va, const void *vb)
* Also modifies the run and env pointers (used on SEL_{RUN,RUNARG}). * Also modifies the run and env pointers (used on SEL_{RUN,RUNARG}).
* The next keyboard input can be simulated by presel. * The next keyboard input can be simulated by presel.
*/ */
static int static int nextsel(char **run, char **env, int *presel)
nextsel(char **run, char **env, int *presel)
{ {
static int c; static int c;
static uint i; static uint i;
@ -1063,8 +1037,7 @@ nextsel(char **run, char **env, int *presel)
/* /*
* Move non-matching entries to the end * Move non-matching entries to the end
*/ */
static int static int fill(struct entry **dents, int (*filter)(regex_t *, char *), regex_t *re)
fill(struct entry **dents, int (*filter)(regex_t *, char *), regex_t *re)
{ {
static int count; static int count;
static struct entry _dent, *pdent1, *pdent2; static struct entry _dent, *pdent1, *pdent2;
@ -1088,8 +1061,7 @@ fill(struct entry **dents, int (*filter)(regex_t *, char *), regex_t *re)
return ndents; return ndents;
} }
static int static int matches(char *fltr)
matches(char *fltr)
{ {
static regex_t re; static regex_t re;
@ -1107,8 +1079,7 @@ matches(char *fltr)
return 0; return 0;
} }
static int static int filterentries(char *path)
filterentries(char *path)
{ {
static char ln[REGEX_MAX] __attribute__ ((aligned)); static char ln[REGEX_MAX] __attribute__ ((aligned));
static wchar_t wln[REGEX_MAX] __attribute__ ((aligned)); static wchar_t wln[REGEX_MAX] __attribute__ ((aligned));
@ -1224,8 +1195,7 @@ end:
} }
/* Show a prompt with input string and return the changes */ /* Show a prompt with input string and return the changes */
static char * static char *xreadline(char *fname, char *prompt)
xreadline(char *fname, char *prompt)
{ {
int old_curs = curs_set(1); int old_curs = curs_set(1);
size_t len, pos; size_t len, pos;
@ -1344,8 +1314,7 @@ END:
* Updates out with "dir/name or "/name" * Updates out with "dir/name or "/name"
* Returns the number of bytes copied including the terminating NULL byte * Returns the number of bytes copied including the terminating NULL byte
*/ */
static size_t static size_t mkpath(char *dir, char *name, char *out, size_t n)
mkpath(char *dir, char *name, char *out, size_t n)
{ {
static size_t len; static size_t len;
@ -1363,8 +1332,7 @@ mkpath(char *dir, char *name, char *out, size_t n)
return (xstrlcpy(out + len, name, n - len) + len); return (xstrlcpy(out + len, name, n - len) + len);
} }
static void static void parsebmstr()
parsebmstr()
{ {
int i = 0; int i = 0;
char *bms = getenv("NNN_BMS"); char *bms = getenv("NNN_BMS");
@ -1410,8 +1378,7 @@ parsebmstr()
* NULL is returned in case of no match, path resolution failure etc. * NULL is returned in case of no match, path resolution failure etc.
* buf would be modified, so check return value before access * buf would be modified, so check return value before access
*/ */
static char * static char *get_bm_loc(char *key, char *buf)
get_bm_loc(char *key, char *buf)
{ {
int r; int r;
@ -1440,8 +1407,7 @@ get_bm_loc(char *key, char *buf)
return NULL; return NULL;
} }
static void static void resetdircolor(mode_t mode)
resetdircolor(mode_t mode)
{ {
if (cfg.dircolor && !S_ISDIR(mode)) { if (cfg.dircolor && !S_ISDIR(mode)) {
attroff(COLOR_PAIR(1) | A_BOLD); attroff(COLOR_PAIR(1) | A_BOLD);
@ -1461,8 +1427,7 @@ resetdircolor(mode_t mode)
* it doesn't touch str anymore). Only after that it starts modifying * it doesn't touch str anymore). Only after that it starts modifying
* g_buf. This is a phased operation. * g_buf. This is a phased operation.
*/ */
static char * static char *unescape(const char *str, uint maxcols)
unescape(const char *str, uint maxcols)
{ {
static wchar_t wbuf[PATH_MAX] __attribute__ ((aligned)); static wchar_t wbuf[PATH_MAX] __attribute__ ((aligned));
static wchar_t *buf; static wchar_t *buf;
@ -1493,8 +1458,7 @@ unescape(const char *str, uint maxcols)
return g_buf; return g_buf;
} }
static char * static char *coolsize(off_t size)
coolsize(off_t size)
{ {
static const char * const U = "BKMGTPEZY"; static const char * const U = "BKMGTPEZY";
static char size_buf[12]; /* Buffer to hold human readable size */ static char size_buf[12]; /* Buffer to hold human readable size */
@ -1554,8 +1518,7 @@ coolsize(off_t size)
return size_buf; return size_buf;
} }
static char * static char *get_file_sym(mode_t mode)
get_file_sym(mode_t mode)
{ {
static char ind[2] = "\0\0"; static char ind[2] = "\0\0";
@ -1575,8 +1538,7 @@ get_file_sym(mode_t mode)
return ind; return ind;
} }
static void static void printent(struct entry *ent, int sel, uint namecols)
printent(struct entry *ent, int sel, uint namecols)
{ {
static char *pname; static char *pname;
@ -1588,8 +1550,7 @@ printent(struct entry *ent, int sel, uint namecols)
printw("%s%s%s\n", CURSYM(sel), pname, get_file_sym(ent->mode)); printw("%s%s%s\n", CURSYM(sel), pname, get_file_sym(ent->mode));
} }
static void static void printent_long(struct entry *ent, int sel, uint namecols)
printent_long(struct entry *ent, int sel, uint namecols)
{ {
static char buf[18], *pname; static char buf[18], *pname;
@ -1638,8 +1599,7 @@ printent_long(struct entry *ent, int sel, uint namecols)
static void (*printptr)(struct entry *ent, int sel, uint namecols) = &printent_long; static void (*printptr)(struct entry *ent, int sel, uint namecols) = &printent_long;
static char static char get_fileind(mode_t mode, char *desc)
get_fileind(mode_t mode, char *desc)
{ {
static char c; static char c;
@ -1688,8 +1648,7 @@ get_fileind(mode_t mode, char *desc)
} }
/* Convert a mode field into "ls -l" type perms field. */ /* Convert a mode field into "ls -l" type perms field. */
static char * static char *get_lsperms(mode_t mode, char *desc)
get_lsperms(mode_t mode, char *desc)
{ {
static const char * const rwx[] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"}; static const char * const rwx[] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"};
static char bits[11] = {'\0'}; static char bits[11] = {'\0'};
@ -1715,8 +1674,7 @@ get_lsperms(mode_t mode, char *desc)
* *
* If pager is valid, returns NULL * If pager is valid, returns NULL
*/ */
static char * static char *get_output(char *buf, size_t bytes, char *file, char *arg1, char *arg2, int pager)
get_output(char *buf, size_t bytes, char *file, char *arg1, char *arg2, int pager)
{ {
pid_t pid; pid_t pid;
int pipefd[2]; int pipefd[2];
@ -1780,8 +1738,7 @@ get_output(char *buf, size_t bytes, char *file, char *arg1, char *arg2, int page
return NULL; return NULL;
} }
static char * static char *xgetpwuid(uid_t uid)
xgetpwuid(uid_t uid)
{ {
struct passwd *pwd = getpwuid(uid); struct passwd *pwd = getpwuid(uid);
@ -1791,8 +1748,7 @@ xgetpwuid(uid_t uid)
return pwd->pw_name; return pwd->pw_name;
} }
static char * static char *xgetgrgid(gid_t gid)
xgetgrgid(gid_t gid)
{ {
struct group *grp = getgrgid(gid); struct group *grp = getgrgid(gid);
@ -1805,8 +1761,7 @@ xgetgrgid(gid_t gid)
/* /*
* Follows the stat(1) output closely * Follows the stat(1) output closely
*/ */
static int static int show_stats(char *fpath, char *fname, struct stat *sb)
show_stats(char *fpath, char *fname, struct stat *sb)
{ {
char desc[DESCRIPTOR_LEN]; char desc[DESCRIPTOR_LEN];
char *perms = get_lsperms(sb->st_mode, desc); char *perms = get_lsperms(sb->st_mode, desc);
@ -1916,8 +1871,7 @@ show_stats(char *fpath, char *fname, struct stat *sb)
return 0; return 0;
} }
static size_t static size_t get_fs_info(const char *path, bool type)
get_fs_info(const char *path, bool type)
{ {
static struct statvfs svb; static struct statvfs svb;
@ -1930,8 +1884,7 @@ get_fs_info(const char *path, bool type)
return svb.f_bavail << ffs(svb.f_frsize >> 1); return svb.f_bavail << ffs(svb.f_frsize >> 1);
} }
static int static int show_mediainfo(char *fpath, char *arg)
show_mediainfo(char *fpath, char *arg)
{ {
if (!get_output(g_buf, MAX_CMD_LEN, "which", utils[cfg.metaviewer], NULL, 0)) if (!get_output(g_buf, MAX_CMD_LEN, "which", utils[cfg.metaviewer], NULL, 0))
return -1; return -1;
@ -1942,8 +1895,7 @@ show_mediainfo(char *fpath, char *arg)
return 0; return 0;
} }
static int static int handle_archive(char *fpath, char *arg, char *dir)
handle_archive(char *fpath, char *arg, char *dir)
{ {
if (!get_output(g_buf, MAX_CMD_LEN, "which", utils[ATOOL], NULL, 0)) if (!get_output(g_buf, MAX_CMD_LEN, "which", utils[ATOOL], NULL, 0))
return -1; return -1;
@ -1967,8 +1919,7 @@ handle_archive(char *fpath, char *arg, char *dir)
* 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 int static int show_help(char *path)
show_help(char *path)
{ {
if (g_tmpfpath[0]) if (g_tmpfpath[0])
xstrlcpy(g_tmpfpath + g_tmpfplen - 1, "/.nnnXXXXXX", MAX_HOME_LEN - g_tmpfplen); xstrlcpy(g_tmpfpath + g_tmpfplen - 1, "/.nnnXXXXXX", MAX_HOME_LEN - g_tmpfplen);
@ -2103,10 +2054,7 @@ show_help(char *path)
return 0; return 0;
} }
int (*nftw_fn) (const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf); static int sum_bsizes(const char *fpath, const struct stat *sb,
static int
sum_bsizes(const char *fpath, const struct stat *sb,
int typeflag, struct FTW *ftwbuf) int typeflag, struct FTW *ftwbuf)
{ {
if (sb->st_blocks && (typeflag == FTW_F || typeflag == FTW_D)) if (sb->st_blocks && (typeflag == FTW_F || typeflag == FTW_D))
@ -2116,8 +2064,7 @@ sum_bsizes(const char *fpath, const struct stat *sb,
return 0; return 0;
} }
static int static int sum_sizes(const char *fpath, const struct stat *sb,
sum_sizes(const char *fpath, const struct stat *sb,
int typeflag, struct FTW *ftwbuf) int typeflag, struct FTW *ftwbuf)
{ {
if (sb->st_size && (typeflag == FTW_F || typeflag == FTW_D)) if (sb->st_size && (typeflag == FTW_F || typeflag == FTW_D))
@ -2127,8 +2074,7 @@ sum_sizes(const char *fpath, const struct stat *sb,
return 0; return 0;
} }
static int static int dentfill(char *path, struct entry **dents,
dentfill(char *path, struct entry **dents,
int (*filter)(regex_t *, char *), regex_t *re) int (*filter)(regex_t *, char *), regex_t *re)
{ {
static DIR *dirp; static DIR *dirp;
@ -2296,16 +2242,14 @@ dentfill(char *path, struct entry **dents,
return n; return n;
} }
static void static void dentfree(struct entry *dents)
dentfree(struct entry *dents)
{ {
free(pnamebuf); free(pnamebuf);
free(dents); free(dents);
} }
/* Return the position of the matching entry or 0 otherwise */ /* Return the position of the matching entry or 0 otherwise */
static int static int dentfind(struct entry *dents, const char *fname, int n)
dentfind(struct entry *dents, const char *fname, int n)
{ {
static int i; static int i;
@ -2321,8 +2265,7 @@ dentfind(struct entry *dents, const char *fname, int n)
return 0; return 0;
} }
static int static int populate(char *path, char *oldname, char *fltr)
populate(char *path, char *oldname, char *fltr)
{ {
static regex_t re; static regex_t re;
@ -2364,8 +2307,7 @@ populate(char *path, char *oldname, char *fltr)
return 0; return 0;
} }
static void static void redraw(char *path)
redraw(char *path)
{ {
static char buf[NAME_MAX + 65] __attribute__ ((aligned)); static char buf[NAME_MAX + 65] __attribute__ ((aligned));
static size_t ncols; static size_t ncols;
@ -2493,8 +2435,7 @@ redraw(char *path)
} }
} }
static void static void browse(char *ipath, char *ifilter)
browse(char *ipath, char *ifilter)
{ {
static char path[PATH_MAX] __attribute__ ((aligned)); static char path[PATH_MAX] __attribute__ ((aligned));
static char newpath[PATH_MAX] __attribute__ ((aligned)); static char newpath[PATH_MAX] __attribute__ ((aligned));
@ -3386,8 +3327,7 @@ nochange:
} }
} }
static void static void usage(void)
usage(void)
{ {
fprintf(stdout, fprintf(stdout,
"usage: nnn [-b key] [-c N] [-e] [-i] [-l]\n" "usage: nnn [-b key] [-c N] [-e] [-i] [-l]\n"
@ -3409,8 +3349,7 @@ usage(void)
exit(0); exit(0);
} }
int int main(int argc, char *argv[])
main(int argc, char *argv[])
{ {
static char cwd[PATH_MAX] __attribute__ ((aligned)); static char cwd[PATH_MAX] __attribute__ ((aligned));
char *ipath = NULL, *ifilter; char *ipath = NULL, *ifilter;