home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume16 / pcomm2 / part04 / list_dir.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-09-14  |  1.5 KB  |  80 lines

  1. /*
  2.  * Do a shell escape with an "ls" command
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <curses.h>
  7. #include "config.h"
  8. #include "misc.h"
  9.  
  10. void
  11. list_dir()
  12. {
  13.     extern int fd;
  14.     WINDOW *ls_win, *newwin();
  15.     FILE *pfp, *n_popen();
  16.     int lines, oops;
  17.     char *ans, *cwd, *getcwd(), buf[200], *get_str();
  18.  
  19.     ls_win = newwin(6, 70, 8, 5);
  20.  
  21.     cwd = getcwd(buf, 200);
  22.  
  23.     mvwprintw(ls_win, 2, 4, "Current directory: %s", cwd);
  24.     mvwaddstr(ls_win, 3, 4, "File spec (wildcards allowed): ");
  25.     box(ls_win, VERT, HORZ);
  26.  
  27.     mvwattrstr(ls_win, 0, 3, A_BOLD, " List Directory ");
  28.     wmove(ls_win, 3, 35);
  29.     wrefresh(ls_win);
  30.  
  31.     if ((ans = get_str(ls_win, 60, "", "")) == NULL) {
  32.         if (fd == -1) {
  33.             werase(ls_win);
  34.             wrefresh(ls_win);
  35.         }
  36.         delwin(ls_win);
  37.         return;
  38.     }
  39.                     /* popen() an ls */
  40.     sprintf(buf, "ls -aC %s", ans);
  41.     pfp = n_popen(buf, "r");
  42.                     /* make a bigger window */
  43.     werase(ls_win);
  44.     wrefresh(ls_win);
  45.     delwin(ls_win);
  46.     ls_win = newwin(LINES-1, COLS, 0, 0);
  47.     touchwin(ls_win);
  48.  
  49.     oops = 0;
  50.     lines = 0;
  51.     while (fgets(buf, BUFSIZ, pfp) != NULL) {
  52.         waddstr(ls_win, buf);
  53.         lines++;
  54.         if (lines == LINES-2) {
  55.             lines = 0;
  56.             mvwaddstr(ls_win, LINES-2, 28, "Press any key for more");
  57.             wrefresh(ls_win);
  58.             if (wgetch(ls_win) == ESC) {
  59.                 oops++;
  60.                 break;
  61.             }
  62.             werase(ls_win);
  63.             wrefresh(ls_win);
  64.         }
  65.     }
  66.     n_pclose(pfp);
  67.  
  68.     if (!oops) {
  69.         mvwaddstr(ls_win, LINES-2, 25, "Press any key to continue");
  70.         wrefresh(ls_win);
  71.         wgetch(ls_win);
  72.     }
  73.     if (fd == -1) {
  74.         werase(ls_win);
  75.         wrefresh(ls_win);
  76.     }
  77.     delwin(ls_win);
  78.     return;
  79. }
  80.