My build of nnn with minor changes
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

936 Zeilen
15 KiB

  1. #include <sys/stat.h>
  2. #include <sys/types.h>
  3. #include <sys/wait.h>
  4. #include <curses.h>
  5. #include <dirent.h>
  6. #include <errno.h>
  7. #include <fcntl.h>
  8. #include <libgen.h>
  9. #include <limits.h>
  10. #include <locale.h>
  11. #include <regex.h>
  12. #include <signal.h>
  13. #include <stdarg.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <unistd.h>
  18. #include "util.h"
  19. #ifdef DEBUG
  20. #define DEBUG_FD 8
  21. #define DPRINTF_D(x) dprintf(DEBUG_FD, #x "=%d\n", x)
  22. #define DPRINTF_U(x) dprintf(DEBUG_FD, #x "=%u\n", x)
  23. #define DPRINTF_S(x) dprintf(DEBUG_FD, #x "=%s\n", x)
  24. #define DPRINTF_P(x) dprintf(DEBUG_FD, #x "=0x%p\n", x)
  25. #else
  26. #define DPRINTF_D(x)
  27. #define DPRINTF_U(x)
  28. #define DPRINTF_S(x)
  29. #define DPRINTF_P(x)
  30. #endif /* DEBUG */
  31. #define LEN(x) (sizeof(x) / sizeof(*(x)))
  32. #undef MIN
  33. #define MIN(x, y) ((x) < (y) ? (x) : (y))
  34. #define ISODD(x) ((x) & 1)
  35. #define CONTROL(c) ((c) ^ 0x40)
  36. struct assoc {
  37. char *regex; /* Regex to match on filename */
  38. char *bin; /* Program */
  39. };
  40. /* Supported actions */
  41. enum action {
  42. SEL_QUIT = 1,
  43. SEL_BACK,
  44. SEL_GOIN,
  45. SEL_FLTR,
  46. SEL_TYPE,
  47. SEL_NEXT,
  48. SEL_PREV,
  49. SEL_PGDN,
  50. SEL_PGUP,
  51. SEL_HOME,
  52. SEL_END,
  53. SEL_CD,
  54. SEL_MTIME,
  55. SEL_REDRAW,
  56. SEL_RUN,
  57. SEL_RUNARG,
  58. };
  59. struct key {
  60. int sym; /* Key pressed */
  61. enum action act; /* Action */
  62. char *run; /* Program to run */
  63. };
  64. #include "config.h"
  65. struct entry {
  66. char *name;
  67. mode_t mode;
  68. time_t t;
  69. };
  70. /* Global context */
  71. struct entry *dents;
  72. int n, cur;
  73. char *path, *oldpath;
  74. char *fltr;
  75. int idle;
  76. /*
  77. * Layout:
  78. * .---------
  79. * | cwd: /mnt/path
  80. * |
  81. * | file0
  82. * | file1
  83. * | > file2
  84. * | file3
  85. * | file4
  86. * ...
  87. * | filen
  88. * |
  89. * | Permission denied
  90. * '------
  91. */
  92. void printmsg(char *msg);
  93. void printwarn(void);
  94. void printerr(int ret, char *prefix);
  95. char *makepath(char *dir, char *name);
  96. #undef dprintf
  97. int
  98. dprintf(int fd, const char *fmt, ...)
  99. {
  100. char buf[BUFSIZ];
  101. int r;
  102. va_list ap;
  103. va_start(ap, fmt);
  104. r = vsnprintf(buf, sizeof(buf), fmt, ap);
  105. if (r > 0)
  106. write(fd, buf, r);
  107. va_end(ap);
  108. return r;
  109. }
  110. void *
  111. xmalloc(size_t size)
  112. {
  113. void *p;
  114. p = malloc(size);
  115. if (p == NULL)
  116. printerr(1, "malloc");
  117. return p;
  118. }
  119. void *
  120. xrealloc(void *p, size_t size)
  121. {
  122. p = realloc(p, size);
  123. if (p == NULL)
  124. printerr(1, "realloc");
  125. return p;
  126. }
  127. char *
  128. xstrdup(const char *s)
  129. {
  130. char *p;
  131. p = strdup(s);
  132. if (p == NULL)
  133. printerr(1, "strdup");
  134. return p;
  135. }
  136. char *
  137. xdirname(const char *path)
  138. {
  139. char *p, *tmp;
  140. /* Some implementations of dirname(3) may modify `path' and some
  141. * return a pointer inside `path' and we cannot free(3) the
  142. * original string if we lose track of it. */
  143. tmp = xstrdup(path);
  144. p = dirname(tmp);
  145. if (p == NULL) {
  146. free(tmp);
  147. printerr(1, "dirname");
  148. }
  149. /* Make sure this is a malloc(3)-ed string */
  150. p = xstrdup(p);
  151. free(tmp);
  152. return p;
  153. }
  154. void
  155. spawn(const char *file, const char *arg, const char *dir)
  156. {
  157. pid_t pid;
  158. int status;
  159. pid = fork();
  160. if (pid == 0) {
  161. if (dir != NULL)
  162. chdir(dir);
  163. execlp(file, file, arg, NULL);
  164. _exit(1);
  165. } else {
  166. /* Ignore interruptions */
  167. while (waitpid(pid, &status, 0) == -1)
  168. DPRINTF_D(status);
  169. DPRINTF_D(pid);
  170. }
  171. }
  172. char *
  173. openwith(char *file)
  174. {
  175. regex_t regex;
  176. char *bin = NULL;
  177. int i;
  178. for (i = 0; i < LEN(assocs); i++) {
  179. if (regcomp(&regex, assocs[i].regex,
  180. REG_NOSUB | REG_EXTENDED | REG_ICASE) != 0)
  181. continue;
  182. if (regexec(&regex, file, 0, NULL, 0) == 0) {
  183. bin = assocs[i].bin;
  184. break;
  185. }
  186. }
  187. DPRINTF_S(bin);
  188. return bin;
  189. }
  190. int
  191. setfilter(regex_t *regex, char *filter)
  192. {
  193. char *errbuf;
  194. int r;
  195. r = regcomp(regex, filter, REG_NOSUB | REG_EXTENDED | REG_ICASE);
  196. if (r != 0) {
  197. errbuf = xmalloc(COLS * sizeof(char));
  198. regerror(r, regex, errbuf, COLS * sizeof(char));
  199. printmsg(errbuf);
  200. free(errbuf);
  201. }
  202. return r;
  203. }
  204. int
  205. visible(regex_t *regex, char *file)
  206. {
  207. return regexec(regex, file, 0, NULL, 0) == 0;
  208. }
  209. int
  210. entrycmp(const void *va, const void *vb)
  211. {
  212. const struct entry *a, *b;
  213. a = (struct entry *)va;
  214. b = (struct entry *)vb;
  215. if (mtimeorder)
  216. return b->t - a->t;
  217. return strcmp(a->name, b->name);
  218. }
  219. void
  220. initcurses(void)
  221. {
  222. initscr();
  223. cbreak();
  224. noecho();
  225. nonl();
  226. intrflush(stdscr, FALSE);
  227. keypad(stdscr, TRUE);
  228. curs_set(FALSE); /* Hide cursor */
  229. timeout(1000); /* One second */
  230. }
  231. void
  232. exitcurses(void)
  233. {
  234. endwin(); /* Restore terminal */
  235. }
  236. /* Messages show up at the bottom */
  237. void
  238. printmsg(char *msg)
  239. {
  240. move(LINES - 1, 0);
  241. printw("%s\n", msg);
  242. }
  243. /* Display warning as a message */
  244. void
  245. printwarn(void)
  246. {
  247. printmsg(strerror(errno));
  248. }
  249. /* Kill curses and display error before exiting */
  250. void
  251. printerr(int ret, char *prefix)
  252. {
  253. exitcurses();
  254. fprintf(stderr, "%s: %s\n", prefix, strerror(errno));
  255. exit(ret);
  256. }
  257. /* Clear the last line */
  258. void
  259. clearprompt(void)
  260. {
  261. printmsg("");
  262. }
  263. /* Print prompt on the last line */
  264. void
  265. printprompt(char *str)
  266. {
  267. clearprompt();
  268. printw(str);
  269. }
  270. /* Returns SEL_* if key is bound and 0 otherwise
  271. Also modifies the run pointer (used on SEL_{RUN,RUNARG}) */
  272. int
  273. nextsel(char **run)
  274. {
  275. int c, i;
  276. c = getch();
  277. if (c == -1)
  278. idle++;
  279. else
  280. idle = 0;
  281. for (i = 0; i < LEN(bindings); i++)
  282. if (c == bindings[i].sym) {
  283. *run = bindings[i].run;
  284. return bindings[i].act;
  285. }
  286. return 0;
  287. }
  288. char *
  289. readln(void)
  290. {
  291. int c;
  292. int i = 0;
  293. char *ln = NULL;
  294. int y, x, x0;
  295. echo();
  296. curs_set(TRUE);
  297. /* Starting point */
  298. getyx(stdscr, y, x);
  299. x0 = x;
  300. while ((c = getch()) != ERR) {
  301. if (c == KEY_ENTER || c == '\r')
  302. break;
  303. if (c == KEY_BACKSPACE || c == CONTROL('H')) {
  304. getyx(stdscr, y, x);
  305. if (x >= x0) {
  306. i--;
  307. if (i > 0) {
  308. ln = xrealloc(ln, i * sizeof(*ln));
  309. } else {
  310. free(ln);
  311. ln = NULL;
  312. }
  313. move(y, x);
  314. printw("%c", ' ');
  315. move(y, x);
  316. } else {
  317. move(y, x0);
  318. }
  319. continue;
  320. }
  321. ln = xrealloc(ln, (i + 1) * sizeof(*ln));
  322. ln[i] = c;
  323. i++;
  324. }
  325. if (ln != NULL) {
  326. ln = xrealloc(ln, (i + 1) * sizeof(*ln));
  327. ln[i] = '\0';
  328. }
  329. curs_set(FALSE);
  330. noecho();
  331. return ln;
  332. }
  333. /*
  334. * Read one key and modify the provided string accordingly.
  335. * Returns 0 when more input is expected and 1 on completion.
  336. */
  337. int
  338. readmore(char **str)
  339. {
  340. int c, ret = 0;
  341. int i;
  342. char *ln = *str;
  343. if (ln != NULL)
  344. i = strlen(ln);
  345. else
  346. i = 0;
  347. DPRINTF_D(i);
  348. curs_set(TRUE);
  349. c = getch();
  350. switch (c) {
  351. case KEY_ENTER:
  352. case '\r':
  353. ret = 1;
  354. break;
  355. case KEY_BACKSPACE:
  356. case CONTROL('H'):
  357. i--;
  358. if (i > 0) {
  359. ln = xrealloc(ln, (i + 1) * sizeof(*ln));
  360. ln[i] = '\0';
  361. } else {
  362. free(ln);
  363. ln = NULL;
  364. }
  365. break;
  366. default:
  367. i++;
  368. ln = xrealloc(ln, (i + 1) * sizeof(*ln));
  369. ln[i - 1] = c;
  370. ln[i] = '\0';
  371. }
  372. curs_set(FALSE);
  373. *str = ln;
  374. return ret;
  375. }
  376. int
  377. canopendir(char *path)
  378. {
  379. DIR *dirp;
  380. dirp = opendir(path);
  381. if (dirp == NULL)
  382. return 0;
  383. closedir(dirp);
  384. return 1;
  385. }
  386. void
  387. printent(struct entry *ent, int active)
  388. {
  389. char *name;
  390. unsigned int maxlen = COLS - strlen(CURSR) - 1;
  391. char cm = 0;
  392. /* Copy name locally */
  393. name = xstrdup(ent->name);
  394. if (S_ISDIR(ent->mode)) {
  395. cm = '/';
  396. maxlen--;
  397. } else if (S_ISLNK(ent->mode)) {
  398. cm = '@';
  399. maxlen--;
  400. } else if (S_ISSOCK(ent->mode)) {
  401. cm = '=';
  402. maxlen--;
  403. } else if (S_ISFIFO(ent->mode)) {
  404. cm = '|';
  405. maxlen--;
  406. } else if (ent->mode & S_IXUSR) {
  407. cm = '*';
  408. maxlen--;
  409. }
  410. /* No text wrapping in entries */
  411. if (strlen(name) > maxlen)
  412. name[maxlen] = '\0';
  413. if (cm == 0)
  414. printw("%s%s\n", active ? CURSR : EMPTY, name);
  415. else
  416. printw("%s%s%c\n", active ? CURSR : EMPTY, name, cm);
  417. free(name);
  418. }
  419. int
  420. dentfill(char *path, struct entry **dents,
  421. int (*filter)(regex_t *, char *), regex_t *re)
  422. {
  423. DIR *dirp;
  424. struct dirent *dp;
  425. struct stat sb;
  426. char *newpath;
  427. int r, n = 0;
  428. dirp = opendir(path);
  429. if (dirp == NULL)
  430. return 0;
  431. while ((dp = readdir(dirp)) != NULL) {
  432. /* Skip self and parent */
  433. if (strcmp(dp->d_name, ".") == 0
  434. || strcmp(dp->d_name, "..") == 0)
  435. continue;
  436. if (filter(re, dp->d_name) == 0)
  437. continue;
  438. *dents = xrealloc(*dents, (n + 1) * sizeof(**dents));
  439. (*dents)[n].name = xstrdup(dp->d_name);
  440. /* Get mode flags */
  441. newpath = makepath(path, dp->d_name);
  442. r = lstat(newpath, &sb);
  443. if (r == -1)
  444. printerr(1, "lstat");
  445. (*dents)[n].mode = sb.st_mode;
  446. (*dents)[n].t = sb.st_mtime;
  447. n++;
  448. }
  449. /* Should never be null */
  450. r = closedir(dirp);
  451. if (r == -1)
  452. printerr(1, "closedir");
  453. return n;
  454. }
  455. void
  456. dentfree(struct entry *dents, int n)
  457. {
  458. int i;
  459. for (i = 0; i < n; i++)
  460. free(dents[i].name);
  461. free(dents);
  462. }
  463. char *
  464. makepath(char *dir, char *name)
  465. {
  466. char path[PATH_MAX];
  467. /* Handle absolute path */
  468. if (name[0] == '/') {
  469. strlcpy(path, name, sizeof(path));
  470. } else {
  471. /* Handle root case */
  472. if (strcmp(dir, "/") == 0) {
  473. strlcpy(path, "/", sizeof(path));
  474. strlcat(path, name, sizeof(path));
  475. } else {
  476. strlcpy(path, dir, sizeof(path));
  477. strlcat(path, "/", sizeof(path));
  478. strlcat(path, name, sizeof(path));
  479. }
  480. }
  481. return xstrdup(path);
  482. }
  483. /* Return the position of the matching entry or 0 otherwise */
  484. int
  485. dentfind(struct entry *dents, int n, char *cwd, char *path)
  486. {
  487. int i;
  488. char *tmp;
  489. if (path == NULL)
  490. return 0;
  491. for (i = 0; i < n; i++) {
  492. tmp = makepath(cwd, dents[i].name);
  493. DPRINTF_S(path);
  494. DPRINTF_S(tmp);
  495. if (strcmp(tmp, path) == 0) {
  496. free(tmp);
  497. return i;
  498. }
  499. free(tmp);
  500. }
  501. return 0;
  502. }
  503. int
  504. populate(void)
  505. {
  506. regex_t re;
  507. int r;
  508. /* Can fail when permissions change while browsing */
  509. if (canopendir(path) == 0)
  510. return -1;
  511. /* Search filter */
  512. r = setfilter(&re, fltr);
  513. if (r != 0)
  514. return -1;
  515. dentfree(dents, n);
  516. n = 0;
  517. dents = NULL;
  518. n = dentfill(path, &dents, visible, &re);
  519. qsort(dents, n, sizeof(*dents), entrycmp);
  520. /* Find cur from history */
  521. cur = dentfind(dents, n, path, oldpath);
  522. free(oldpath);
  523. oldpath = NULL;
  524. return 0;
  525. }
  526. void
  527. redraw(void)
  528. {
  529. int nlines, odd;
  530. char *cwd;
  531. int i;
  532. nlines = MIN(LINES - 4, n);
  533. /* Clean screen */
  534. erase();
  535. /* Strip trailing slashes */
  536. for (i = strlen(path) - 1; i > 0; i--)
  537. if (path[i] == '/')
  538. path[i] = '\0';
  539. else
  540. break;
  541. DPRINTF_D(cur);
  542. DPRINTF_S(path);
  543. /* No text wrapping in cwd line */
  544. cwd = xmalloc(COLS * sizeof(char));
  545. strlcpy(cwd, path, COLS * sizeof(char));
  546. cwd[COLS - strlen(CWD) - 1] = '\0';
  547. printw(CWD "%s\n\n", cwd);
  548. /* Print listing */
  549. odd = ISODD(nlines);
  550. if (cur < nlines / 2) {
  551. for (i = 0; i < nlines; i++)
  552. printent(&dents[i], i == cur);
  553. } else if (cur >= n - nlines / 2) {
  554. for (i = n - nlines; i < n; i++)
  555. printent(&dents[i], i == cur);
  556. } else {
  557. for (i = cur - nlines / 2;
  558. i < cur + nlines / 2 + odd; i++)
  559. printent(&dents[i], i == cur);
  560. }
  561. }
  562. void
  563. browse(const char *ipath, const char *ifilter)
  564. {
  565. int r, fd;
  566. regex_t re;
  567. char *newpath;
  568. struct stat sb;
  569. char *name, *bin, *dir, *tmp, *run;
  570. int nowtyping = 0;
  571. oldpath = NULL;
  572. path = xstrdup(ipath);
  573. fltr = xstrdup(ifilter);
  574. begin:
  575. /* Path and filter should be malloc(3)-ed strings at all times */
  576. r = populate();
  577. if (r == -1) {
  578. if (!nowtyping) {
  579. printwarn();
  580. goto nochange;
  581. }
  582. }
  583. for (;;) {
  584. redraw();
  585. /* Handle filter-as-you-type mode */
  586. if (nowtyping)
  587. goto moretyping;
  588. nochange:
  589. switch (nextsel(&run)) {
  590. case SEL_QUIT:
  591. free(path);
  592. free(fltr);
  593. dentfree(dents, n);
  594. return;
  595. case SEL_BACK:
  596. /* There is no going back */
  597. if (strcmp(path, "/") == 0 ||
  598. strcmp(path, ".") == 0 ||
  599. strchr(path, '/') == NULL)
  600. goto nochange;
  601. dir = xdirname(path);
  602. if (canopendir(dir) == 0) {
  603. free(dir);
  604. printwarn();
  605. goto nochange;
  606. }
  607. /* Save history */
  608. oldpath = path;
  609. path = dir;
  610. /* Reset filter */
  611. free(fltr);
  612. fltr = xstrdup(ifilter);
  613. goto begin;
  614. case SEL_GOIN:
  615. /* Cannot descend in empty directories */
  616. if (n == 0)
  617. goto nochange;
  618. name = dents[cur].name;
  619. newpath = makepath(path, name);
  620. DPRINTF_S(newpath);
  621. /* Get path info */
  622. fd = open(newpath, O_RDONLY | O_NONBLOCK);
  623. if (fd == -1) {
  624. printwarn();
  625. free(newpath);
  626. goto nochange;
  627. }
  628. r = fstat(fd, &sb);
  629. if (r == -1) {
  630. printwarn();
  631. close(fd);
  632. free(newpath);
  633. goto nochange;
  634. }
  635. close(fd);
  636. DPRINTF_U(sb.st_mode);
  637. switch (sb.st_mode & S_IFMT) {
  638. case S_IFDIR:
  639. if (canopendir(newpath) == 0) {
  640. printwarn();
  641. free(newpath);
  642. goto nochange;
  643. }
  644. free(path);
  645. path = newpath;
  646. /* Reset filter */
  647. free(fltr);
  648. fltr = xstrdup(ifilter);
  649. goto begin;
  650. case S_IFREG:
  651. bin = openwith(newpath);
  652. if (bin == NULL) {
  653. printmsg("No association");
  654. free(newpath);
  655. goto nochange;
  656. }
  657. exitcurses();
  658. spawn(bin, newpath, NULL);
  659. initcurses();
  660. free(newpath);
  661. continue;
  662. default:
  663. printmsg("Unsupported file");
  664. goto nochange;
  665. }
  666. case SEL_FLTR:
  667. /* Read filter */
  668. printprompt("filter: ");
  669. tmp = readln();
  670. if (tmp == NULL)
  671. tmp = xstrdup(ifilter);
  672. /* Check and report regex errors */
  673. r = setfilter(&re, tmp);
  674. if (r != 0) {
  675. free(tmp);
  676. goto nochange;
  677. }
  678. free(fltr);
  679. fltr = tmp;
  680. DPRINTF_S(fltr);
  681. /* Save current */
  682. if (n > 0)
  683. oldpath = makepath(path, dents[cur].name);
  684. goto begin;
  685. case SEL_TYPE:
  686. nowtyping = 1;
  687. tmp = NULL;
  688. moretyping:
  689. printprompt("type: ");
  690. if (tmp != NULL)
  691. printw("%s", tmp);
  692. r = readmore(&tmp);
  693. DPRINTF_D(r);
  694. DPRINTF_S(tmp);
  695. if (r == 1)
  696. nowtyping = 0;
  697. /* Check regex errors */
  698. if (tmp != NULL) {
  699. r = setfilter(&re, tmp);
  700. if (r != 0)
  701. if (nowtyping) {
  702. goto moretyping;
  703. } else {
  704. free(tmp);
  705. goto nochange;
  706. }
  707. }
  708. /* Copy or reset filter */
  709. free(fltr);
  710. if (tmp != NULL)
  711. fltr = xstrdup(tmp);
  712. else
  713. fltr = xstrdup(ifilter);
  714. /* Save current */
  715. if (n > 0)
  716. oldpath = makepath(path, dents[cur].name);
  717. if (!nowtyping)
  718. free(tmp);
  719. goto begin;
  720. case SEL_NEXT:
  721. if (cur < n - 1)
  722. cur++;
  723. break;
  724. case SEL_PREV:
  725. if (cur > 0)
  726. cur--;
  727. break;
  728. case SEL_PGDN:
  729. if (cur < n - 1)
  730. cur += MIN((LINES - 4) / 2, n - 1 - cur);
  731. break;
  732. case SEL_PGUP:
  733. if (cur > 0)
  734. cur -= MIN((LINES - 4) / 2, cur);
  735. break;
  736. case SEL_HOME:
  737. cur = 0;
  738. break;
  739. case SEL_END:
  740. cur = n - 1;
  741. break;
  742. case SEL_CD:
  743. /* Read target dir */
  744. printprompt("chdir: ");
  745. tmp = readln();
  746. if (tmp == NULL) {
  747. clearprompt();
  748. goto nochange;
  749. }
  750. newpath = makepath(path, tmp);
  751. free(tmp);
  752. if (canopendir(newpath) == 0) {
  753. free(newpath);
  754. printwarn();
  755. goto nochange;
  756. }
  757. free(path);
  758. path = newpath;
  759. free(fltr);
  760. fltr = xstrdup(ifilter); /* Reset filter */
  761. DPRINTF_S(path);
  762. goto begin;
  763. case SEL_MTIME:
  764. mtimeorder = !mtimeorder;
  765. /* Save current */
  766. if (n > 0)
  767. oldpath = makepath(path, dents[cur].name);
  768. goto begin;
  769. case SEL_REDRAW:
  770. /* Save current */
  771. if (n > 0)
  772. oldpath = makepath(path, dents[cur].name);
  773. goto begin;
  774. case SEL_RUN:
  775. exitcurses();
  776. spawn(run, NULL, path);
  777. initcurses();
  778. break;
  779. case SEL_RUNARG:
  780. name = dents[cur].name;
  781. exitcurses();
  782. spawn(run, name, path);
  783. initcurses();
  784. break;
  785. }
  786. /* Screensaver */
  787. if (idletimeout != 0 && idle == idletimeout) {
  788. idle = 0;
  789. exitcurses();
  790. spawn(idlecmd, NULL, NULL);
  791. initcurses();
  792. }
  793. }
  794. }
  795. int
  796. main(int argc, char *argv[])
  797. {
  798. char cwd[PATH_MAX], *ipath;
  799. char *ifilter;
  800. /* Confirm we are in a terminal */
  801. if (!isatty(STDIN_FILENO))
  802. printerr(1, "isatty");
  803. if (getuid() == 0)
  804. ifilter = ".";
  805. else
  806. ifilter = "^[^.]"; /* Hide dotfiles */
  807. if (argv[1] != NULL) {
  808. ipath = argv[1];
  809. } else {
  810. ipath = getcwd(cwd, sizeof(cwd));
  811. if (ipath == NULL)
  812. ipath = "/";
  813. }
  814. /* Test initial path */
  815. if (canopendir(ipath) == 0)
  816. printerr(1, ipath);
  817. /* Set locale before curses setup */
  818. setlocale(LC_ALL, "");
  819. initcurses();
  820. browse(ipath, ifilter);
  821. exitcurses();
  822. return 0;
  823. }