diff --git a/inc/proto.h b/inc/proto.h index 75368fa..ce04e38 100755 --- a/inc/proto.h +++ b/inc/proto.h @@ -356,6 +356,7 @@ void diff(); void dircor(); void dispatchevent1(); void dispatchevent2(); +void dispatchevent3(int *nerr); void dispatchevents(); void dispid(); void disppk(); @@ -476,7 +477,7 @@ void flushbuffer2(); #if MISSING_FUNC_FMAX double fmin(double a, double b); #endif -#if MISSING_FUNC_LROUND +#if MISSING_FUNC_LROUND || !defined(lround) long int lround(double z); #endif diff --git a/inc/select.h b/inc/select.h index 4dee2a1..f70db6b 100644 --- a/inc/select.h +++ b/inc/select.h @@ -4,7 +4,13 @@ #define __sun__ #endif /* SOLARIS */ #include -#include + +#ifdef READLINE +# include +//# include +#else + typedef void VFunction(); +#endif #define SAC_HISTORY_FILE ".sac_history" diff --git a/src/co/select.c b/src/co/select.c index 578360b..ec204ab 100644 --- a/src/co/select.c +++ b/src/co/select.c @@ -1,5 +1,3 @@ - - #include #include #include @@ -15,7 +13,6 @@ #ifdef SOLARIS #define __sun__ #endif /* SOLARIS */ -#include #include #include "complex.h" @@ -25,59 +22,6 @@ #include "gd3.x11.h" #include "gdm.h" -#define SAC_HISTORY_MAX 1024 - -static int sac_history_size = SAC_HISTORY_MAX; - -void -history_size_set(int value) { - if (value <= 0) { - sac_history_size = INT_MAX; - } else { - sac_history_size = value; - } - return; -} - -int -history_size() { - return sac_history_size; -} - -int -select_loop_message(char *p, int len) { - int i; - static char *str = NULL; - - if(len <= 0) { - if(str) { - free(str); - str = NULL; - } - str = strdup(p); - return(strlen(str)); - } - - len = len - 2; /* 1 for \0 and 1 for a space */ - len = (strlen(str) > len) ? len : strlen(str); - - strncpy(p, str, len); - p[len++] = ' '; /* Space */ - p[len++] = '\0'; /* String Teminator */ - - return(len); -} - - -int -select_loop_continue(int w) { - static int flag; - if(w == SELECT_ON || w == SELECT_OFF) { - flag = w; - } - return(flag); -} - int CheckByteOrder() { static int byte_order = ENDIAN_UNKNOWN; @@ -142,8 +86,62 @@ show_prompt_without_tty() { return flag; } +#ifdef READLINE + +#define SAC_HISTORY_MAX 1024 +static int sac_history_size = SAC_HISTORY_MAX; + +/* Name of file to store SAC command history */ static char *sac_history_filename = NULL; -static int sac_history_loaded = FALSE; +/* Whether the command history has been loaded */ +int sac_history_loaded = FALSE; + +void +history_size_set(int value) { + if (value <= 0) { + sac_history_size = INT_MAX; + } else { + sac_history_size = value; + } + return; +} + +int +history_size() { + return sac_history_size; +} + +int +select_loop_message(char *p, int len) { + static char *str = NULL; + + if(len <= 0) { + if(str) { + free(str); + str = NULL; + } + str = strdup(p); + return(strlen(str)); + } + + len = len - 2; /* 1 for \0 and 1 for a space */ + len = (strlen(str) > len) ? len : strlen(str); + + strncpy(p, str, len); + p[len++] = ' '; /* Space */ + p[len++] = '\0'; /* String Teminator */ + + return(len); +} + +int +select_loop_continue(int w) { + static int flag; + if(w == SELECT_ON || w == SELECT_OFF) { + flag = w; + } + return(flag); +} void sac_history_file_set(char *name) { @@ -181,11 +179,9 @@ sac_history_file() { void sac_history_load(char *where) { - int n; stifle_history( history_size() ); - if(where) { + if (where) read_history(where); - } sac_history_loaded = TRUE; } @@ -200,8 +196,7 @@ select_loop(char *prmt, long prmtlen, int retval; fd_set fd; int max_fd, stdin_fd, x11_fd; - long int nerr; - char *c; + int nerr; char kprmt[128]; if(!sac_history_loaded) @@ -297,4 +292,5 @@ select_loop(char *prmt, long prmtlen, select_loop_continue(SELECT_OFF); return(0); } +#endif diff --git a/src/co/zgpmsg.c b/src/co/zgpmsg.c index c57eca2..962ef53 100755 --- a/src/co/zgpmsg.c +++ b/src/co/zgpmsg.c @@ -42,21 +42,25 @@ CDOC CEND */ -#include "stdu.h" -#include -#include #include -#include "config.h" -#include "../../inc/mach.h" -#include "../../inc/gd3.x11.h" -#include "../../inc/gdm.h" #include +#include #include +#include +#include +#include + +#include "config.h" +#include "stdu.h" +#include "mach.h" +#include "gd3.x11.h" +#include "gdm.h" + static int global_msglen; static int global_before_newline; static char global_string[MCMSG+1]; -#if !defined(READLINE) && !defined(USE_X11_DOUBLE_BUFFER) +#if !defined(READLINE) zgpmsg(prmt,prmtlen,msg,msglen) char *prmt; /* pointer to prompt message */ @@ -72,11 +76,11 @@ long msglen; /* length of msg array */ for (i=0;i<(int)msglen;++i) /* prefill with NULLs */ *(psave++) = '\0'; - while (*prmt != '$') + if (use_tty()) { + while (*prmt != '$') putchar (*(prmt++)); /* print prompt */ - - - fflush(stdout); + fflush(stdout); + } /* A control-d sets the message response to quit */ if ( getfline (stdin,msg,(short)msglen) == -1) @@ -90,10 +94,7 @@ long msglen; /* length of msg array */ #define __sun__ #endif /* SOLARIS */ -#include -#include "../../inc/select.h" - - +#include "select.h" static void process_line(char *p) { @@ -124,7 +125,24 @@ long prmtlen; /* length of prmt array */ char *msg; /* pointer to character array to receive input */ long msglen; /* length of msg array */ { - select_loop(prmt, prmtlen, msg, msglen, NULL, process_line); + char *line; + + if (use_tty()) { + select_loop(prmt, prmtlen, msg, msglen, NULL, process_line); + } else { + int i; /* index for prefilling string w/ NULLs */ + char *psave = msg; /* save msg */ + + /* prefill with NULLs */ + for (i = 0; i < (int)msglen; ++i) + *(psave++) = '\0'; + + /* CTRL-D is pressed */ + if (getfline(stdin, msg, (short)msglen) == -1) { + assert(msglen >= 5); + strcpy(msg, "quit"); + } + } } #endif /* !READLINE */ diff --git a/src/co/zquit.c b/src/co/zquit.c index 3a73141..e658898 100755 --- a/src/co/zquit.c +++ b/src/co/zquit.c @@ -37,7 +37,8 @@ */ void zquit() { - char *sachistory; + char *sachistory; + extern int sac_history_loaded; long int nerr; /* - Close and dispose of any output files. */ @@ -64,12 +65,9 @@ zquit() { #ifdef READLINE /* Cleanup Command Line Editing Tools */ - { - sachistory = sac_history_file(); - if(sachistory) { - write_history(sachistory); - } - } + sachistory = sac_history_file(); + if (sachistory && sac_history_loaded && use_tty()) + write_history(sachistory); rl_callback_handler_remove(); #endif /* READLINE */ diff --git a/src/exm/xabout.c b/src/exm/xabout.c index 05886e9..02abd68 100755 --- a/src/exm/xabout.c +++ b/src/exm/xabout.c @@ -67,13 +67,11 @@ use_database(int getset) { void xabout ( ) { char kvdate[200]; - /* char fmt[] = "SEISMIC ANALYSIS CODE [%s (Version 00.59.49)]"; */ char fmt[] = "SEISMIC ANALYSIS CODE [%s (Version %s)]"; char kcopyr[] = "Copyright 1995 Regents of the University of California\n" ; - if(! display_copyright(OPTION_GET)) { + if(!display_copyright(OPTION_GET) || !use_tty()) return; - } sprintf( kvdate, fmt, BUILD_DATE, PACKAGE_VERSION ); setmsg( "OUTPUT", 99 ); apcmsg( kvdate, strlen ( kvdate ) + 1 ); diff --git a/src/exm/xtranscript.c b/src/exm/xtranscript.c index 91ab636..13a08b2 100755 --- a/src/exm/xtranscript.c +++ b/src/exm/xtranscript.c @@ -93,10 +93,12 @@ long int *nerr; cmexm.imodetranscript = 6; } +#ifdef READLINE /* -- "HISTORY": Set up command line history */ else if( lckey( "HIST#ORY$",10 ) ){ cmexm.imodetranscript = 7; } +#endif /* -- "FILE filename": Set name of transcript file. */ else if( lkchar( "FILE$",6, MCPFN, kname,MCPFN+1, &nchar ) ){ @@ -311,8 +313,8 @@ L_2000: } } +#ifdef READLINE /* - Check that if history, only file name given or default used. */ - else if( cmexm.imodetranscript == 7 ){ if (lnewcontents) { *nerr = 1107; @@ -342,6 +344,7 @@ L_2000: */ ; *nerr = 0; } +#endif L_8888: return; diff --git a/src/gd3.x11/dispatcheve3.c b/src/gd3.x11/dispatcheve3.c index fed1e66..09edc16 100755 --- a/src/gd3.x11/dispatcheve3.c +++ b/src/gd3.x11/dispatcheve3.c @@ -86,6 +86,7 @@ use_large_crosshairs(int getset) { return use_xhairs; } +void dispatchevent3(nerr) int *nerr; { @@ -459,18 +460,13 @@ dispatchevent3(nerr) } break; - } -/* Reset window flags */ - + /* Reset window flags */ is_basew = 0; is_plotw = 0; is_titlew = 0; - } - } - } diff --git a/src/top/initsac.c b/src/top/initsac.c index 78344b3..5958c88 100755 --- a/src/top/initsac.c +++ b/src/top/initsac.c @@ -130,17 +130,17 @@ void /*FUNCTION*/ initsac() * rc(); */ - /* - Say hello. */ - +#ifdef READLINE sac_history_file_set(NULL); +#endif + + setup_pager(); if (ifirst){ ifirst = 0; xabout () ; } - setup_pager(); - L_8888: return;