home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / pcomm / part03 / data_log.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-17  |  1.8 KB  |  80 lines

  1. /*
  2.  * Open a window to prompt for a path name to be used for the data logging
  3.  * feature.  Turns on the data logging by killing the input routine and
  4.  * restarting it.  A return code of 1 means we need to restart the input
  5.  * routine.
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <curses.h>
  10. #include "misc.h"
  11. #include "param.h"
  12. #include "status.h"
  13.  
  14. int
  15. data_logging(fd)
  16. int fd;
  17. {
  18.     int ret_code;
  19.     WINDOW *dl_win, *newwin();
  20.     char *ans, *path, *expand(), *get_str(), *strdup();
  21.     void input_off(), free_ptr();
  22.     extern char *null_ptr;
  23.  
  24.     dl_win = newwin(6, 70, 5, 5);
  25.  
  26.     mvwprintw(dl_win, 2, 4, "Default log file: %s", param->logfile);
  27.     mvwaddstr(dl_win, 3, 4, "New log file: ");
  28.     box(dl_win, '|', '-');
  29.  
  30.     mvwattrstr(dl_win, 0, 3, A_BOLD, " Start Data Logging ");
  31.     wmove(dl_win, 3, 18);
  32.     wrefresh(dl_win);
  33.                     /* get the path */
  34.     ret_code = 0;
  35.     path = null_ptr;
  36.     while ((ans = get_str(dl_win, 60, NULL, "     ")) != NULL) {
  37.                     /* give 'em the default */
  38.         if (*ans == NULL)
  39.             path = strdup(param->logfile);
  40.         else
  41.             path = expand(ans);
  42.  
  43.                     /* test write permission */
  44.         if (can_write(path)) {
  45.             ret_code++;
  46.             break;
  47.         }
  48.  
  49.         beep();
  50.         mvwattrstr(dl_win, 4, 24, A_BOLD, "No write permission");
  51.         wrefresh(dl_win);
  52.         wait_key(dl_win, 3);
  53.                     /* cleanup the mess */
  54.         clear_line(dl_win, 3, 18, 1);
  55.         clear_line(dl_win, 4, 24, 1);
  56.         wmove(dl_win, 3, 18);
  57.         wrefresh(dl_win);
  58.     }
  59.     if (ret_code) {
  60.         /*
  61.          * Killing and then restarting the input routine is the
  62.          * only way to change the name of the file that the input
  63.          * routines uses.  It also assures that the 'status->log'
  64.          * flag is in sync with the flag in the input routine.
  65.          */
  66.         input_off();
  67.         status->log = 1;
  68.         free_ptr(status->log_path);
  69.         status->log_path = strdup(path);
  70.     }
  71.     if (fd == -1) {
  72.         werase(dl_win);
  73.         wrefresh(dl_win);
  74.     }
  75.     delwin(dl_win);
  76.  
  77.     free_ptr(path);
  78.     return(ret_code);
  79. }
  80.