}
/* Initialize curses mode */
-static void initcurses(void)
+static bool initcurses(void)
{
if (initscr() == NULL) {
char *term = getenv("TERM");
fprintf(stderr, "error opening TERM: %s\n", term);
else
fprintf(stderr, "initscr() failed\n");
- exit(1);
+ return FALSE;
}
cbreak();
init_pair(4, g_ctx[3].color, -1);
}
settimeout(); /* One second */
+ return TRUE;
}
/*
return (xstrlcpy(out + len, name, n - len) + len);
}
-static int parsebmstr()
+static bool parsebmstr()
{
int i = 0;
char *bms = getenv("NNN_BMS");
if (!bms)
- return 0;
+ return TRUE;
while (*bms && i < BM_MAX) {
bookmark[i].key = *bms;
}
if (*bms != ':')
- return -1; /* We support single char keys only */
+ return FALSE; /* We support single char keys only */
bookmark[i].loc = ++bms;
if (bookmark[i].loc[0] == '\0' || bookmark[i].loc[0] == ';') {
++i;
}
- return 0;
+ return TRUE;
}
/*
/*
* Follows the stat(1) output closely
*/
-static int show_stats(char *fpath, char *fname, struct stat *sb)
+static bool show_stats(char *fpath, char *fname, struct stat *sb)
{
char desc[DESCRIPTOR_LEN];
char *perms = get_lsperms(sb->st_mode, desc);
xstrlcpy(g_tmpfpath + g_tmpfplen - 1, "/.nnnXXXXXX", HOME_LEN_MAX - g_tmpfplen);
else {
printmsg(messages[STR_NOHOME_ID]);
- return -1;
+ return FALSE;
}
int fd = mkstemp(g_tmpfpath);
if (fd == -1)
- return -1;
+ return FALSE;
dprintf(fd, " File: '%s'", unescape(fname, 0));
get_output(NULL, 0, "cat", g_tmpfpath, NULL, TRUE);
unlink(g_tmpfpath);
refresh();
- return 0;
+ return TRUE;
}
static size_t get_fs_info(const char *path, bool type)
return 0;
}
-static int populate(char *path, char *lastname)
+static bool populate(char *path, char *lastname)
{
/* Can fail when permissions change while browsing.
* It's assumed that path IS a directory when we are here.
*/
if (access(path, R_OK) == -1)
- return -1;
+ return FALSE;
if (cfg.blkorder) {
printmsg("calculating...");
ndents = dentfill(path, &dents);
if (!ndents)
- return 0;
+ return TRUE;
qsort(dents, ndents, sizeof(*dents), entrycmp);
/* Find cur from history */
cur = dentfind(dents, lastname, ndents);
- return 0;
+ return TRUE;
}
static void redraw(char *path)
}
#endif
- if (populate(path, lastname) == -1) {
+ if (!populate(path, lastname)) {
printwarn();
goto nochange;
}
errexit();
}
- if (show_stats(newpath, dents[cur].name, &sb) < 0) {
+ if (!show_stats(newpath, dents[cur].name, &sb)) {
printwarn();
goto nochange;
}
/* Confirm we are in a terminal */
if (!isatty(0) || !isatty(1)) {
fprintf(stderr, "stdin or stdout is not a tty\n");
- exit(1);
+ return 1;
}
while ((opt = getopt(argc, argv, "Slib:Cep:vh")) != -1) {
copier = realpath(optarg, g_cppath);
if (!g_cppath[0]) {
fprintf(stderr, "%s\n", strerror(errno));
- exit(1);
+ return 1;
}
}
break;
return 0;
default:
usage();
- exit(1);
+ return 1;
}
}
while (*copier && opt < CTX_MAX) {
if (*copier < '0' || *copier > '7') {
fprintf(stderr, "invalid color code\n");
- exit(1);
+ return 1;
} else
g_ctx[opt].color = *copier - '0';
}
/* Parse bookmarks string */
- if (parsebmstr() < 0) {
+ if (!parsebmstr()) {
fprintf(stderr, "NNN_BMS: single-char keys only\n");
- exit(1);
+ return 1;
}
if (ipath) { /* Open a bookmark directly */
if (ipath[1] || get_bm_loc(*ipath, cwd) == NULL) {
fprintf(stderr, "%s\n", messages[STR_INVBM_KEY]);
- exit(1);
+ return 1;
}
ipath = cwd;
ipath = realpath(argv[optind], cwd);
if (!ipath) {
fprintf(stderr, "%s: no such dir\n", argv[optind]);
- exit(1);
+ return 1;
}
}
inotify_fd = inotify_init1(IN_NONBLOCK);
if (inotify_fd < 0) {
fprintf(stderr, "inotify init! %s\n", strerror(errno));
- exit(1);
+ return 1;
}
#elif defined(BSD_KQUEUE)
kq = kqueue();
if (kq < 0) {
fprintf(stderr, "kqueue init! %s\n", strerror(errno));
- exit(1);
+ return 1;
}
#endif
/* Test initial path */
if (!xdiraccess(ipath)) {
fprintf(stderr, "%s: %s\n", ipath, strerror(errno));
- exit(1);
+ return 1;
}
/* Set locale */
#ifdef DEBUGMODE
enabledbg();
#endif
- initcurses();
+ if (!initcurses())
+ return 1;
+
browse(ipath);
exitcurses();
#ifdef DEBUGMODE
disabledbg();
#endif
- exit(0);
+ return 0;
}