#define SCROLLOFF 5
#define LONG_SIZE sizeof(ulong)
+/* Program return codes */
+#define _SUCCESS 0
+#define _FAILURE !_SUCCESS
+
/* Entry flags */
#define DIR_OR_LINK_TO_DIR 0x1
#define FILE_COPIED 0x10
if (fd == -1) {
xerror();
- return 1;
+ return _FAILURE;
}
close(fd);
break;
case 'v':
fprintf(stdout, "%s\n", VERSION);
- return 0;
+ return _SUCCESS;
case 'w':
cfg.wild = 1;
break;
case 'h':
usage();
- return 0;
+ return _SUCCESS;
default:
usage();
- return 1;
+ return _FAILURE;
}
}
if (*copier) {
if (*copier < '0' || *copier > '7') {
fprintf(stderr, "0 <= code <= 7\n");
- return 1;
+ return _FAILURE;
}
g_ctx[opt].color = *copier - '0';
home = getenv("HOME");
if (!home) {
fprintf(stderr, "set HOME\n");
- return 1;
+ return _FAILURE;
}
DPRINTF_S(home);
if (!setup_config())
- return 1;
+ return _FAILURE;
/* Get custom opener, if set */
opener = xgetenv(env_cfg[NNN_OPENER], utils[OPENER]);
/* Parse bookmarks string */
if (!parsebmstr()) {
fprintf(stderr, "%s\n", env_cfg[NNN_BMS]);
- return 1;
+ return _FAILURE;
}
if (arg) { /* Open a bookmark directly */
if (arg[1] || (initpath = get_bm_loc(NULL, *arg)) == NULL) {
fprintf(stderr, "%s\n", messages[STR_INVBM_KEY]);
- return 1;
+ return _FAILURE;
}
} else if (argc == optind) {
/* Start in the current directory */
DPRINTF_S(initpath);
if (!initpath) {
xerror();
- return 1;
+ return _FAILURE;
}
/*
if (stat(initpath, &sb) == -1) {
xerror();
- return 1;
+ return _FAILURE;
}
if (S_ISREG(sb.st_mode)) {
execlp(opener, opener, arg, NULL);
- return 0;
+ return _SUCCESS;
}
}
inotify_fd = inotify_init1(IN_NONBLOCK);
if (inotify_fd < 0) {
xerror();
- return 1;
+ return _FAILURE;
}
#elif defined(BSD_KQUEUE)
kq = kqueue();
if (kq < 0) {
xerror();
- return 1;
+ return _FAILURE;
}
#endif
/* Prefix for temporary files */
if (!set_tmp_path())
- return 1;
+ return _FAILURE;
/* Get the clipboard copier, if set */
copier = getenv(env_cfg[NNN_COPIER]);
if (sigaction(SIGINT, &act, NULL) < 0) {
xerror();
- return 1;
+ return _FAILURE;
}
signal(SIGQUIT, SIG_IGN);
/* Test initial path */
if (!xdiraccess(initpath)) {
xerror();
- return 1;
+ return _FAILURE;
}
/* Set locale */
#endif
if (!initcurses())
- return 1;
+ return _FAILURE;
browse(initpath);
exitcurses();
close(kq);
#endif
- return 0;
+ return _SUCCESS;
}