/***************************************************************************** * Change Log * Date | Change *-----------+----------------------------------------------------------------- * 23-Nov-85 | [1.93] Created * 24-Dec-85 | [1.231] check_diag now calls ce_panel * 24-Dec-85 | [1.235] Display_on not static * 24-Jan-86 | [1.325] Handle off-by-one on check_diag * 27-Jan-86 | [1.350] message_length again signed, cast in malloc call * 30-Jul-86 | [1.403] Added log_console_event * 6-Aug-86 | [1.410] Make sure event is a char * to log_console event * 18-Aug-86 | [1.414] screen.h -> bscreen.h * 10-Nov-91 | [1.428] converted to Microsoft C 6.0 * 24-Nov-91 | [1.472] _oserr => errno, use strerror as well *****************************************************************************/ #include "stdio.h" #include "stdlib.h" #include "string.h" #include "time.h" #include "errno.h" #include "btypes.h" #include "scdspmsg.h" #include "hercules.h" /* #include "graph.h" */ #include "disp.h" #include "boolean.h" #include "color.h" #include "1401.h" #include "hercules.h" #include "select.h" #include "display.h" #include "panel.h" #include "pr.h" #include "printers.h" #define message_cache_size 3 #define message_length 79 char diag_buffer[512]; extern char version[]; extern boolean color_printer; extern boolean slow; extern boolean mousing; static char * message_roll[message_cache_size]; static FILE * message_file; boolean diagnostics_on = false; boolean display_on = false; static boolean file_initialized = false; static char * debugfn = "ce.log"; void debuglog(char * S); void tellmsg(char * S); /**************************************************************************** * diag_init * Effect: * Initializes the diagnostics message cache and other such things ****************************************************************************/ void diag_init() { int i; for (i=0; i< message_cache_size; i++) { /* create empty messages */ message_roll[i] = (char *) malloc((unsigned) (message_length+1)); *message_roll[i] = '\0'; } /* create empty messages */ message_file = NULL; diagnostics_on = display_on = false; } /**************************************************************************** * mark_diag * Inputs: * int display_mode: Display mode to use * Effect: * Highlights the diagnostic mode according to the indicated mode ****************************************************************************/ void mark_diag(unsigned char display_mode) { scdspmsg(diag_key_Y+1,diag_key_X+1,display_mode,0,"D"); } /**************************************************************************** * scroll_window * Effect: * Scrolls the message window ****************************************************************************/ void scroll_window() { if(!display_on) return; scscroll(1,H_REVERSE,diag_Y,diag_X, diag_Y+message_cache_size, diag_X+message_length,SCR_UP); /* scroll upwards */ } /***************************************************************************** * nextline * * Inputs: None * * Effects: * Scroll the status area. Simulate scrolling in message retention * area. *****************************************************************************/ static void nextline() { char * t; int i; if(display_on) { scroll_window(); } t = message_roll[message_cache_size - 1]; for(i=message_cache_size-1;i>0;i--) { message_roll[i+1] = message_roll[i]; } message_roll[0] = t; } /**************************************************************************** * store_message * Inputs: * char * S: Message to store * * Effect: * Stores the message (at least the first max_message_length characters) * in the message_roll[message_cache_size] buffer. If the buffer * pointer is NULL, allocate it. ****************************************************************************/ static void store_message(char * S) { strncpy(message_roll[0],S,message_length+1); message_roll[message_length+1] = '\0'; } /***************************************************************************** * tellmsg * Inputs: * char * S: The message to display * * Effects: * Displays the message on the topmost debug scrolling window line * Stores the message in the message buffer[0] *****************************************************************************/ static void tellmsg(char * S) { store_message(S); debuglog(S); if(display_on) scdspmsg(diag_Y+message_cache_size,diag_X, H_REVERSE, 0 , S); } /***************************************************************************** * tell * Inputs: * char * S: Message to display on floating reporting line * * Side effects: * Window is scrolled down to make room for the message * Message is displayed *****************************************************************************/ void tell(char * S) { nextline(); tellmsg(S); } /***************************************************************************** * debuglog * Inputs: * char * S: String to add to debug log * * Global State: * boolean file_initialized: false if file is initialized * true if file is initialized * * Effects: * Opens the log file, for output if file_initialized false and * for append if file_initialized true. Writes the string to the * file and closes the file (this is so the log is intact in case of * program abort via ^C * *****************************************************************************/ void debuglog(char * S) { char * mode; FILE * logfile; if(file_initialized) mode = "aa"; /* if initialized, use append mode */ else mode = "wa"; /* if not initialized, use write mode */ logfile = fopen(debugfn,mode); if(logfile==NULL) { /* no log */ int err; err = errno; printf("Failure to open log file, errcode = %d (%s), mode %s\n",err, strerror(err), mode ); return; } /* no log */ if(!file_initialized) { char date[80]; time_t timeval; time(&timeval); fprintf(logfile,"CE Diagnostic file\n"); fprintf(logfile," Simulator version %s\n",version); if(ismono()) fprintf(logfile," Monochrome display\n"); else fprintf(logfile," Color display\n"); if(color_printer) fprintf(logfile," -color\n"); if(slow) fprintf(logfile," -slow\n"); if(!mousing) fprintf(logfile," -nomouse\n"); fprintf(logfile," -printer %s\n",current_printer->lpt); strftime(date,sizeof(date),"Recorded on %A, %d-%b-%y at %X", localtime(&timeval)); fprintf(logfile," %s\n",date); } fprintf(logfile,"%s\n",S); fclose(logfile); file_initialized = true; return; } /**************************************************************************** * redraw_messages * Effect: * Redraws any saved messages ****************************************************************************/ void redraw_messages() { int i; if(!display_on) return; for(i=0;i>> %s <<<",event); tell(diag_buffer); }