home *** CD-ROM | disk | FTP | other *** search
- /*
- * Open a window to prompt for a path name to be used for the data logging
- * feature. Turns on the data logging by killing the input routine and
- * restarting it. A return code of 1 means we need to restart the input
- * routine.
- */
-
- #include <stdio.h>
- #include <curses.h>
- #include "misc.h"
- #include "param.h"
- #include "status.h"
-
- int
- data_logging(fd)
- int fd;
- {
- int ret_code;
- WINDOW *dl_win, *newwin();
- char *ans, *path, *expand(), *get_str(), *strdup();
- void input_off(), free_ptr();
- extern char *null_ptr;
-
- dl_win = newwin(6, 70, 5, 5);
-
- mvwprintw(dl_win, 2, 4, "Default log file: %s", param->logfile);
- mvwaddstr(dl_win, 3, 4, "New log file: ");
- box(dl_win, '|', '-');
-
- mvwattrstr(dl_win, 0, 3, A_BOLD, " Start Data Logging ");
- wmove(dl_win, 3, 18);
- wrefresh(dl_win);
- /* get the path */
- ret_code = 0;
- path = null_ptr;
- while ((ans = get_str(dl_win, 60, NULL, " ")) != NULL) {
- /* give 'em the default */
- if (*ans == NULL)
- path = strdup(param->logfile);
- else
- path = expand(ans);
-
- /* test write permission */
- if (can_write(path)) {
- ret_code++;
- break;
- }
-
- beep();
- mvwattrstr(dl_win, 4, 24, A_BOLD, "No write permission");
- wrefresh(dl_win);
- wait_key(dl_win, 3);
- /* cleanup the mess */
- clear_line(dl_win, 3, 18, 1);
- clear_line(dl_win, 4, 24, 1);
- wmove(dl_win, 3, 18);
- wrefresh(dl_win);
- }
- if (ret_code) {
- /*
- * Killing and then restarting the input routine is the
- * only way to change the name of the file that the input
- * routines uses. It also assures that the 'status->log'
- * flag is in sync with the flag in the input routine.
- */
- input_off();
- status->log = 1;
- free_ptr(status->log_path);
- status->log_path = strdup(path);
- }
- if (fd == -1) {
- werase(dl_win);
- wrefresh(dl_win);
- }
- delwin(dl_win);
-
- free_ptr(path);
- return(ret_code);
- }
-