My build of nnn with minor changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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