home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume16 / pcomm2 / part03 / data_log.c < prev    next >
C/C++ Source or Header  |  1988-09-14  |  2KB  |  82 lines

  1. /*
  2.  * Open a window to prompt for a path name to be used for the data logging
  3.  * feature.  Also turns on the data logging.  A return code of 1 means we
  4.  * need to restart the input routine.
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <curses.h>
  9. #include "config.h"
  10. #include "misc.h"
  11. #include "param.h"
  12. #include "status.h"
  13.  
  14. int
  15. data_logging()
  16. {
  17.     extern int fd;
  18.     extern char *null_ptr;
  19.     int ret_code;
  20.     WINDOW *dl_win, *newwin();
  21.     char *ans, *path, *expand(), *get_str(), *strdup(), *strcpy();
  22.     void input_off(), free_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, VERT, HORZ);
  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) {
  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.                     /* clean up 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.         strcpy(status->log_path, path);
  61.         status->log = 1;
  62.         /*
  63.          * Without shared memory, killing and restarting the input
  64.          * routine is the only way to change the name of the file
  65.          * that the input routines uses.
  66.          */
  67. #ifdef SHAREDMEM
  68.         ret_code = 0;
  69. #else /* SHAREDMEM */
  70.         input_off();
  71. #endif /* SHAREDMEM */
  72.     }
  73.     if (fd == -1) {
  74.         werase(dl_win);
  75.         wrefresh(dl_win);
  76.     }
  77.     delwin(dl_win);
  78.  
  79.     free_ptr(path);
  80.     return(ret_code);
  81. }
  82.