Use MAX as macro suffix

This commit is contained in:
Arun Prakash Jana 2018-12-04 18:21:01 +05:30
parent 21a491e660
commit c101fcd769
No known key found for this signature in database
GPG Key ID: A75979F35C080412
1 changed files with 35 additions and 35 deletions

View File

@ -165,7 +165,7 @@ disabledbg()
#define ISODD(x) ((x) & 1) #define ISODD(x) ((x) & 1)
#define TOUPPER(ch) \ #define TOUPPER(ch) \
(((ch) >= 'a' && (ch) <= 'z') ? ((ch) - 'a' + 'A') : (ch)) (((ch) >= 'a' && (ch) <= 'z') ? ((ch) - 'a' + 'A') : (ch))
#define MAX_CMD_LEN 5120 #define CMD_LEN_MAX 5120
#define CURSR " > " #define CURSR " > "
#define EMPTY " " #define EMPTY " "
#define CURSYM(flag) ((flag) ? CURSR : EMPTY) #define CURSYM(flag) ((flag) ? CURSR : EMPTY)
@ -178,8 +178,8 @@ disabledbg()
#define _ALIGNMENT 0x10 /* 16-byte alignment */ #define _ALIGNMENT 0x10 /* 16-byte alignment */
#define _ALIGNMENT_MASK 0xF #define _ALIGNMENT_MASK 0xF
#define SYMLINK_TO_DIR 0x1 #define SYMLINK_TO_DIR 0x1
#define MAX_HOME_LEN 64 #define HOME_LEN_MAX 64
#define MAX_CTX 4 #define CTX_MAX 4
#define DOT_FILTER_LEN 7 #define DOT_FILTER_LEN 7
/* Macros to define process spawn behaviour as flags */ /* Macros to define process spawn behaviour as flags */
@ -283,7 +283,7 @@ typedef struct {
/* Configuration, contexts */ /* Configuration, contexts */
static settings cfg = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0}; static settings cfg = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0};
static context g_ctx[MAX_CTX] __attribute__ ((aligned)); static context g_ctx[CTX_MAX] __attribute__ ((aligned));
static struct entry *dents; static struct entry *dents;
static char *pnamebuf, *pcopybuf; static char *pnamebuf, *pcopybuf;
@ -307,13 +307,13 @@ static uchar BLK_SHIFT = 9;
static uchar crc8table[CRC8_TABLE_LEN] __attribute__ ((aligned)); static uchar crc8table[CRC8_TABLE_LEN] __attribute__ ((aligned));
/* For use in functions which are isolated and don't return the buffer */ /* For use in functions which are isolated and don't return the buffer */
static char g_buf[MAX_CMD_LEN] __attribute__ ((aligned)); static char g_buf[CMD_LEN_MAX] __attribute__ ((aligned));
/* Buffer for file path copy file */ /* Buffer for file path copy file */
static char g_cppath[PATH_MAX] __attribute__ ((aligned)); static char g_cppath[PATH_MAX] __attribute__ ((aligned));
/* Buffer to store tmp file path */ /* Buffer to store tmp file path */
static char g_tmpfpath[MAX_HOME_LEN] __attribute__ ((aligned)); static char g_tmpfpath[HOME_LEN_MAX] __attribute__ ((aligned));
#ifdef LINUX_INOTIFY #ifdef LINUX_INOTIFY
static int inotify_fd, inotify_wd = -1; static int inotify_fd, inotify_wd = -1;
@ -756,7 +756,7 @@ static bool showcplist()
return FALSE; return FALSE;
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", HOME_LEN_MAX - g_tmpfplen);
else { else {
printmsg(messages[STR_NOHOME_ID]); printmsg(messages[STR_NOHOME_ID]);
return -1; return -1;
@ -1880,7 +1880,7 @@ static int show_stats(char *fpath, char *fname, struct stat *sb)
char *p, *begin = g_buf; char *p, *begin = g_buf;
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", HOME_LEN_MAX - g_tmpfplen);
else { else {
printmsg(messages[STR_NOHOME_ID]); printmsg(messages[STR_NOHOME_ID]);
return -1; return -1;
@ -1895,8 +1895,8 @@ static int show_stats(char *fpath, char *fname, struct stat *sb)
/* Show file name or 'symlink' -> 'target' */ /* Show file name or 'symlink' -> 'target' */
if (perms[0] == 'l') { if (perms[0] == 'l') {
/* Note that MAX_CMD_LEN > PATH_MAX */ /* Note that CMD_LEN_MAX > PATH_MAX */
ssize_t len = readlink(fpath, g_buf, MAX_CMD_LEN); ssize_t len = readlink(fpath, g_buf, CMD_LEN_MAX);
if (len != -1) { if (len != -1) {
struct stat tgtsb; struct stat tgtsb;
@ -1955,7 +1955,7 @@ static int show_stats(char *fpath, char *fname, struct stat *sb)
if (S_ISREG(sb->st_mode)) { if (S_ISREG(sb->st_mode)) {
/* Show file(1) output */ /* Show file(1) output */
p = get_output(g_buf, MAX_CMD_LEN, "file", "-b", fpath, FALSE); p = get_output(g_buf, CMD_LEN_MAX, "file", "-b", fpath, FALSE);
if (p) { if (p) {
dprintf(fd, "\n\n "); dprintf(fd, "\n\n ");
while (*p) { while (*p) {
@ -1998,7 +1998,7 @@ static size_t get_fs_info(const char *path, bool type)
static int show_mediainfo(char *fpath, char *arg) static int show_mediainfo(char *fpath, char *arg)
{ {
if (!get_output(g_buf, MAX_CMD_LEN, "which", utils[cfg.metaviewer], NULL, FALSE)) if (!get_output(g_buf, CMD_LEN_MAX, "which", utils[cfg.metaviewer], NULL, FALSE))
return -1; return -1;
exitcurses(); exitcurses();
@ -2009,7 +2009,7 @@ static int show_mediainfo(char *fpath, char *arg)
static int handle_archive(char *fpath, char *arg, char *dir) static int handle_archive(char *fpath, char *arg, char *dir)
{ {
if (!get_output(g_buf, MAX_CMD_LEN, "which", utils[ATOOL], NULL, FALSE)) if (!get_output(g_buf, CMD_LEN_MAX, "which", utils[ATOOL], NULL, FALSE))
return -1; return -1;
if (arg[1] == 'x') if (arg[1] == 'x')
@ -2034,7 +2034,7 @@ static int handle_archive(char *fpath, char *arg, char *dir)
static int show_help(char *path) static int 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", HOME_LEN_MAX - g_tmpfplen);
else { else {
printmsg(messages[STR_NOHOME_ID]); printmsg(messages[STR_NOHOME_ID]);
return -1; return -1;
@ -2447,7 +2447,7 @@ static void redraw(char *path)
ncols = PATH_MAX; ncols = PATH_MAX;
printw("["); printw("[");
for (i = 0; i < MAX_CTX; ++i) { for (i = 0; i < CTX_MAX; ++i) {
/* Print current context in reverse */ /* Print current context in reverse */
if (cfg.curctx == i) { if (cfg.curctx == i) {
if (cfg.showcolor) if (cfg.showcolor)
@ -2723,7 +2723,7 @@ nochange:
/* If NNN_USE_EDITOR is set, open text in EDITOR */ /* If NNN_USE_EDITOR is set, open text in EDITOR */
if (cfg.useeditor) if (cfg.useeditor)
if (getmime(dents[cur].name) || if (getmime(dents[cur].name) ||
(get_output(g_buf, MAX_CMD_LEN, "file", FILE_OPTS, newpath, FALSE) && (get_output(g_buf, CMD_LEN_MAX, "file", FILE_OPTS, newpath, FALSE) &&
strstr(g_buf, "text/") == g_buf)) { strstr(g_buf, "text/") == g_buf)) {
spawn(editor, newpath, editor_arg, path, F_NORMAL); spawn(editor, newpath, editor_arg, path, F_NORMAL);
continue; continue;
@ -2834,11 +2834,11 @@ nochange:
r = cfg.curctx; r = cfg.curctx;
if (fd == '>' || fd == '.') if (fd == '>' || fd == '.')
do do
(r == MAX_CTX - 1) ? (r = 0) : ++r; (r == CTX_MAX - 1) ? (r = 0) : ++r;
while (!g_ctx[r].c_cfg.ctxactive); while (!g_ctx[r].c_cfg.ctxactive);
else else
do do
(r == 0) ? (r = MAX_CTX - 1) : --r; (r == 0) ? (r = CTX_MAX - 1) : --r;
while (!g_ctx[r].c_cfg.ctxactive); // fallthrough while (!g_ctx[r].c_cfg.ctxactive); // fallthrough
fd = '1' + r; // fallthrough fd = '1' + r; // fallthrough
case '1': // fallthrough case '1': // fallthrough
@ -2848,7 +2848,7 @@ nochange:
r = fd - '1'; /* Save the next context id */ r = fd - '1'; /* Save the next context id */
if (cfg.curctx == r) { if (cfg.curctx == r) {
if (sel == SEL_CYCLE) { if (sel == SEL_CYCLE) {
(r == MAX_CTX - 1) ? (r = 0) : ++r; (r == CTX_MAX - 1) ? (r = 0) : ++r;
snprintf(newpath, PATH_MAX, "Create context %d? ('Enter' confirms)", r + 1); snprintf(newpath, PATH_MAX, "Create context %d? ('Enter' confirms)", r + 1);
fd = get_input(newpath); fd = get_input(newpath);
if (fd != '\r') if (fd != '\r')
@ -3175,7 +3175,7 @@ nochange:
char force = confirm_force(); char force = confirm_force();
if (sel == SEL_CP) { if (sel == SEL_CP) {
snprintf(g_buf, MAX_CMD_LEN, snprintf(g_buf, CMD_LEN_MAX,
#ifdef __linux__ #ifdef __linux__
"xargs -0 -a %s -%c src cp -%cRp src .", "xargs -0 -a %s -%c src cp -%cRp src .",
#else #else
@ -3183,7 +3183,7 @@ nochange:
#endif #endif
g_cppath, REPLACE_STR, force); g_cppath, REPLACE_STR, force);
} else if (sel == SEL_MV) { } else if (sel == SEL_MV) {
snprintf(g_buf, MAX_CMD_LEN, snprintf(g_buf, CMD_LEN_MAX,
#ifdef __linux__ #ifdef __linux__
"xargs -0 -a %s -%c src mv -%c src .", "xargs -0 -a %s -%c src mv -%c src .",
#else #else
@ -3191,7 +3191,7 @@ nochange:
#endif #endif
g_cppath, REPLACE_STR, force); g_cppath, REPLACE_STR, force);
} else { /* SEL_RMMUL */ } else { /* SEL_RMMUL */
snprintf(g_buf, MAX_CMD_LEN, snprintf(g_buf, CMD_LEN_MAX,
#ifdef __linux__ #ifdef __linux__
"xargs -0 -a %s rm -%cr", "xargs -0 -a %s rm -%cr",
#else #else
@ -3383,7 +3383,7 @@ nochange:
xstrlcpy(lastname, tmp, NAME_MAX + 1); xstrlcpy(lastname, tmp, NAME_MAX + 1);
goto begin; goto begin;
case SEL_RENAMEALL: case SEL_RENAMEALL:
if (!get_output(g_buf, MAX_CMD_LEN, "which", utils[VIDIR], NULL, FALSE)) { if (!get_output(g_buf, CMD_LEN_MAX, "which", utils[VIDIR], NULL, FALSE)) {
printmsg("vidir missing"); printmsg("vidir missing");
goto nochange; goto nochange;
} }
@ -3449,13 +3449,13 @@ nochange:
break; break;
case SEL_QUITCD: // fallthrough case SEL_QUITCD: // fallthrough
case SEL_QUIT: case SEL_QUIT:
for (r = 0; r < MAX_CTX; ++r) for (r = 0; r < CTX_MAX; ++r)
if (r != cfg.curctx && g_ctx[r].c_cfg.ctxactive) { if (r != cfg.curctx && g_ctx[r].c_cfg.ctxactive) {
r = get_input("Quit all contexts? ('Enter' confirms)"); r = get_input("Quit all contexts? ('Enter' confirms)");
break; break;
} }
if (!(r == MAX_CTX || r == '\r')) if (!(r == CTX_MAX || r == '\r'))
break; break;
if (sel == SEL_QUITCD) { if (sel == SEL_QUITCD) {
@ -3488,8 +3488,8 @@ nochange:
if (sel == SEL_QUITCTX) { if (sel == SEL_QUITCTX) {
uint iter = 1; uint iter = 1;
r = cfg.curctx; r = cfg.curctx;
while (iter < MAX_CTX) { while (iter < CTX_MAX) {
(r == MAX_CTX - 1) ? (r = 0) : ++r; (r == CTX_MAX - 1) ? (r = 0) : ++r;
if (g_ctx[r].c_cfg.ctxactive) { if (g_ctx[r].c_cfg.ctxactive) {
g_ctx[cfg.curctx].c_cfg.ctxactive = 0; g_ctx[cfg.curctx].c_cfg.ctxactive = 0;
@ -3608,7 +3608,7 @@ int main(int argc, char *argv[])
copier = getenv("NNN_CONTEXT_COLORS"); copier = getenv("NNN_CONTEXT_COLORS");
if (copier) { if (copier) {
opt = 0; opt = 0;
while (*copier && opt < MAX_CTX) { while (*copier && opt < CTX_MAX) {
if (*copier < '0' || *copier > '7') { if (*copier < '0' || *copier > '7') {
fprintf(stderr, "invalid color code\n"); fprintf(stderr, "invalid color code\n");
exit(1); exit(1);
@ -3619,12 +3619,12 @@ int main(int argc, char *argv[])
++opt; ++opt;
} }
while (opt != MAX_CTX) { while (opt != CTX_MAX) {
g_ctx[opt].color = 4; g_ctx[opt].color = 4;
++opt; ++opt;
} }
} else } else
for (opt = 0; opt < MAX_CTX; ++opt) for (opt = 0; opt < CTX_MAX; ++opt)
g_ctx[opt].color = 4; /* Default color is blue */ g_ctx[opt].color = 4; /* Default color is blue */
} }
@ -3702,15 +3702,15 @@ int main(int argc, char *argv[])
copier = getenv("NNN_COPIER"); copier = getenv("NNN_COPIER");
if (getenv("HOME")) if (getenv("HOME"))
g_tmpfplen = xstrlcpy(g_tmpfpath, getenv("HOME"), MAX_HOME_LEN); g_tmpfplen = xstrlcpy(g_tmpfpath, getenv("HOME"), HOME_LEN_MAX);
else if (getenv("TMPDIR")) else if (getenv("TMPDIR"))
g_tmpfplen = xstrlcpy(g_tmpfpath, getenv("TMPDIR"), MAX_HOME_LEN); g_tmpfplen = xstrlcpy(g_tmpfpath, getenv("TMPDIR"), HOME_LEN_MAX);
else if (xdiraccess("/tmp")) else if (xdiraccess("/tmp"))
g_tmpfplen = xstrlcpy(g_tmpfpath, "/tmp", MAX_HOME_LEN); g_tmpfplen = xstrlcpy(g_tmpfpath, "/tmp", HOME_LEN_MAX);
if (!cfg.picker && g_tmpfplen) { if (!cfg.picker && g_tmpfplen) {
xstrlcpy(g_cppath, g_tmpfpath, MAX_HOME_LEN); xstrlcpy(g_cppath, g_tmpfpath, HOME_LEN_MAX);
xstrlcpy(g_cppath + g_tmpfplen - 1, "/.nnncp", MAX_HOME_LEN - g_tmpfplen); xstrlcpy(g_cppath + g_tmpfplen - 1, "/.nnncp", HOME_LEN_MAX - g_tmpfplen);
} }
/* Disable auto-select if opted */ /* Disable auto-select if opted */