|
|
/*
|
/*
|
** This module contains functions to support i/o in the TUI
|
** This module contains functions to support i/o in the TUI
|
*/
|
*/
|
|
|
|
|
#include <stdio.h>
|
#include <stdio.h>
|
#include "defs.h"
|
#include "defs.h"
|
#include "terminal.h"
|
#include "terminal.h"
|
#include "tui.h"
|
#include "tui.h"
|
#include "tuiData.h"
|
#include "tuiData.h"
|
#include "tuiIO.h"
|
#include "tuiIO.h"
|
#include "tuiCommand.h"
|
#include "tuiCommand.h"
|
#include "tuiWin.h"
|
#include "tuiWin.h"
|
|
|
#ifdef ANSI_PROTOTYPES
|
#ifdef ANSI_PROTOTYPES
|
#include <stdarg.h>
|
#include <stdarg.h>
|
#else
|
#else
|
#include <varargs.h>
|
#include <varargs.h>
|
#endif
|
#endif
|
|
|
/* The Solaris header files seem to provide no declaration for this at
|
/* The Solaris header files seem to provide no declaration for this at
|
all when __STDC__ is defined. This shouldn't conflict with
|
all when __STDC__ is defined. This shouldn't conflict with
|
anything. */
|
anything. */
|
extern char *tgoto ();
|
extern char *tgoto ();
|
|
|
int insert_mode = 0;
|
int insert_mode = 0;
|
|
|
/********************************************
|
/********************************************
|
** LOCAL STATIC FORWARD DECLS **
|
** LOCAL STATIC FORWARD DECLS **
|
********************************************/
|
********************************************/
|
static void _updateCommandInfo PARAMS ((int));
|
static void _updateCommandInfo PARAMS ((int));
|
static unsigned int _tuiHandleResizeDuringIO PARAMS ((unsigned int));
|
static unsigned int _tuiHandleResizeDuringIO PARAMS ((unsigned int));
|
|
|
|
|
/*********************************************************************************
|
/*********************************************************************************
|
** PUBLIC FUNCTIONS **
|
** PUBLIC FUNCTIONS **
|
*********************************************************************************/
|
*********************************************************************************/
|
|
|
/*
|
/*
|
** tuiPuts_unfiltered().
|
** tuiPuts_unfiltered().
|
** Function to put a string to the command window
|
** Function to put a string to the command window
|
** When running in TUI mode, this is the "hook"
|
** When running in TUI mode, this is the "hook"
|
** for fputs_unfiltered(). That is, all debugger
|
** for fputs_unfiltered(). That is, all debugger
|
** output eventually makes it's way to the bottom-level
|
** output eventually makes it's way to the bottom-level
|
** routine fputs_unfiltered (main.c), which (in TUI
|
** routine fputs_unfiltered (main.c), which (in TUI
|
** mode), calls tuiPuts_unfiltered().
|
** mode), calls tuiPuts_unfiltered().
|
*/
|
*/
|
void
|
void
|
#ifdef __STDC__
|
#ifdef __STDC__
|
tuiPuts_unfiltered (
|
tuiPuts_unfiltered (
|
const char *string,
|
const char *string,
|
struct ui_file * stream)
|
struct ui_file * stream)
|
#else
|
#else
|
tuiPuts_unfiltered (string, stream)
|
tuiPuts_unfiltered (string, stream)
|
char *string;
|
char *string;
|
struct ui_file *stream;
|
struct ui_file *stream;
|
#endif
|
#endif
|
{
|
{
|
int len = strlen (string);
|
int len = strlen (string);
|
int i, linech;
|
int i, linech;
|
|
|
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
{
|
{
|
if (string[i] == '\n' || string[i] == '\r')
|
if (string[i] == '\n' || string[i] == '\r')
|
m_tuiStartNewLine;
|
m_tuiStartNewLine;
|
else
|
else
|
{
|
{
|
if ((cmdWin->detail.commandInfo.curch + 1) > cmdWin->generic.width)
|
if ((cmdWin->detail.commandInfo.curch + 1) > cmdWin->generic.width)
|
m_tuiStartNewLine;
|
m_tuiStartNewLine;
|
|
|
if (insert_mode)
|
if (insert_mode)
|
{
|
{
|
mvwinsch (cmdWin->generic.handle,
|
mvwinsch (cmdWin->generic.handle,
|
cmdWin->detail.commandInfo.curLine,
|
cmdWin->detail.commandInfo.curLine,
|
cmdWin->detail.commandInfo.curch++,
|
cmdWin->detail.commandInfo.curch++,
|
string[i]);
|
string[i]);
|
wmove (cmdWin->generic.handle,
|
wmove (cmdWin->generic.handle,
|
cmdWin->detail.commandInfo.curLine,
|
cmdWin->detail.commandInfo.curLine,
|
cmdWin->detail.commandInfo.curch);
|
cmdWin->detail.commandInfo.curch);
|
}
|
}
|
else
|
else
|
mvwaddch (cmdWin->generic.handle,
|
mvwaddch (cmdWin->generic.handle,
|
cmdWin->detail.commandInfo.curLine,
|
cmdWin->detail.commandInfo.curLine,
|
cmdWin->detail.commandInfo.curch++,
|
cmdWin->detail.commandInfo.curch++,
|
string[i]);
|
string[i]);
|
}
|
}
|
}
|
}
|
tuiRefreshWin (&cmdWin->generic);
|
tuiRefreshWin (&cmdWin->generic);
|
|
|
return;
|
return;
|
} /* tuiPuts_unfiltered */
|
} /* tuiPuts_unfiltered */
|
|
|
/* A cover routine for tputs().
|
/* A cover routine for tputs().
|
* tputs() is called from the readline package to put
|
* tputs() is called from the readline package to put
|
* out strings representing cursor positioning.
|
* out strings representing cursor positioning.
|
* In TUI mode (non-XDB-style), tui_tputs() is called instead.
|
* In TUI mode (non-XDB-style), tui_tputs() is called instead.
|
*
|
*
|
* The reason we need to hook tputs() is:
|
* The reason we need to hook tputs() is:
|
* Since the output is going to curses and not to
|
* Since the output is going to curses and not to
|
* a raw terminal, we need to intercept these special
|
* a raw terminal, we need to intercept these special
|
* sequences, and handle them them here.
|
* sequences, and handle them them here.
|
*
|
*
|
* This function seems to be correctly handling all sequences
|
* This function seems to be correctly handling all sequences
|
* aimed at hpterm's, but there is additional work to do
|
* aimed at hpterm's, but there is additional work to do
|
* for xterm's and dtterm's. I abandoned further work on this
|
* for xterm's and dtterm's. I abandoned further work on this
|
* in favor of "XDB style". In "XDB style", the command region
|
* in favor of "XDB style". In "XDB style", the command region
|
* looks like terminal, not a curses window, and this routine
|
* looks like terminal, not a curses window, and this routine
|
* is not called. - RT
|
* is not called. - RT
|
*/
|
*/
|
void
|
void
|
tui_tputs (str, affcnt, putfunc)
|
tui_tputs (str, affcnt, putfunc)
|
char *str;
|
char *str;
|
int affcnt;
|
int affcnt;
|
int (*putfunc) PARAMS ((int));
|
int (*putfunc) PARAMS ((int));
|
{
|
{
|
extern char *rl_prompt; /* the prompt string */
|
extern char *rl_prompt; /* the prompt string */
|
|
|
/* This set of globals are defined and initialized
|
/* This set of globals are defined and initialized
|
* by the readline package.
|
* by the readline package.
|
*
|
*
|
* Note we're assuming tui_tputs() is being called
|
* Note we're assuming tui_tputs() is being called
|
* by the readline package. That's because we're recognizing
|
* by the readline package. That's because we're recognizing
|
* that a given string is being passed by
|
* that a given string is being passed by
|
* matching the string address against readline's
|
* matching the string address against readline's
|
* term_<whatever> global. To make this more general,
|
* term_<whatever> global. To make this more general,
|
* we'd have to actually recognize the termcap sequence
|
* we'd have to actually recognize the termcap sequence
|
* inside the string (more work than I want to do). - RT
|
* inside the string (more work than I want to do). - RT
|
*
|
*
|
* We don't see or need to handle every one of these here;
|
* We don't see or need to handle every one of these here;
|
* this is just the full list defined in readline/readline.c
|
* this is just the full list defined in readline/readline.c
|
*/
|
*/
|
extern char *term_backspace;
|
extern char *term_backspace;
|
extern char *term_clreol;
|
extern char *term_clreol;
|
extern char *term_clrpag;
|
extern char *term_clrpag;
|
extern char *term_cr;
|
extern char *term_cr;
|
extern char *term_dc;
|
extern char *term_dc;
|
extern char *term_ei;
|
extern char *term_ei;
|
extern char *term_goto;
|
extern char *term_goto;
|
extern char *term_ic;
|
extern char *term_ic;
|
extern char *term_im;
|
extern char *term_im;
|
extern char *term_mm;
|
extern char *term_mm;
|
extern char *term_mo;
|
extern char *term_mo;
|
extern char *term_up;
|
extern char *term_up;
|
extern char *term_scroll_region;
|
extern char *term_scroll_region;
|
extern char *term_memory_lock;
|
extern char *term_memory_lock;
|
extern char *term_memory_unlock;
|
extern char *term_memory_unlock;
|
extern char *term_cursor_move;
|
extern char *term_cursor_move;
|
extern char *visible_bell;
|
extern char *visible_bell;
|
|
|
/* Sanity check - if not TUI, just call tputs() */
|
/* Sanity check - if not TUI, just call tputs() */
|
if (!tui_version)
|
if (!tui_version)
|
tputs (str, affcnt, putfunc);
|
tputs (str, affcnt, putfunc);
|
|
|
/* The strings we special-case are handled first */
|
/* The strings we special-case are handled first */
|
|
|
if (str == term_backspace)
|
if (str == term_backspace)
|
{
|
{
|
/* Backspace. */
|
/* Backspace. */
|
|
|
/* We see this on an emacs control-B.
|
/* We see this on an emacs control-B.
|
* I.e., it's like the left-arrow key (not like the backspace key).
|
* I.e., it's like the left-arrow key (not like the backspace key).
|
* The effect that readline wants when it transmits this
|
* The effect that readline wants when it transmits this
|
* character to us is simply to back up one character
|
* character to us is simply to back up one character
|
* (but not to write a space over the old character).
|
* (but not to write a space over the old character).
|
*/
|
*/
|
|
|
_updateCommandInfo (-1);
|
_updateCommandInfo (-1);
|
wmove (cmdWin->generic.handle,
|
wmove (cmdWin->generic.handle,
|
cmdWin->detail.commandInfo.curLine,
|
cmdWin->detail.commandInfo.curLine,
|
cmdWin->detail.commandInfo.curch);
|
cmdWin->detail.commandInfo.curch);
|
wrefresh (cmdWin->generic.handle);
|
wrefresh (cmdWin->generic.handle);
|
|
|
}
|
}
|
else if (str == term_clreol)
|
else if (str == term_clreol)
|
{
|
{
|
|
|
/* Clear to end of line. */
|
/* Clear to end of line. */
|
wclrtoeol (cmdWin->generic.handle);
|
wclrtoeol (cmdWin->generic.handle);
|
wrefresh (cmdWin->generic.handle);
|
wrefresh (cmdWin->generic.handle);
|
|
|
}
|
}
|
else if (str == term_cr)
|
else if (str == term_cr)
|
{
|
{
|
|
|
/* Carriage return */
|
/* Carriage return */
|
_updateCommandInfo (-cmdWin->detail.commandInfo.curch);
|
_updateCommandInfo (-cmdWin->detail.commandInfo.curch);
|
wmove (cmdWin->generic.handle,
|
wmove (cmdWin->generic.handle,
|
cmdWin->detail.commandInfo.curLine,
|
cmdWin->detail.commandInfo.curLine,
|
0 /* readline will rewrite the prompt from 0 */ );
|
0 /* readline will rewrite the prompt from 0 */ );
|
wrefresh (cmdWin->generic.handle);
|
wrefresh (cmdWin->generic.handle);
|
|
|
}
|
}
|
else if (str == term_goto)
|
else if (str == term_goto)
|
{
|
{
|
|
|
/* This is actually a tgoto() specifying a character position,
|
/* This is actually a tgoto() specifying a character position,
|
* followed by either a term_IC/term_DC which [I think] means
|
* followed by either a term_IC/term_DC which [I think] means
|
* insert/delete one character at that position.
|
* insert/delete one character at that position.
|
* There are complications with this one - need to either
|
* There are complications with this one - need to either
|
* extract the position from the string, or have a backdoor
|
* extract the position from the string, or have a backdoor
|
* means of communicating it from ../readline/display.c.
|
* means of communicating it from ../readline/display.c.
|
* So this one is not yet implemented.
|
* So this one is not yet implemented.
|
* Not doing it seems to have no ill effects on command-line-editing
|
* Not doing it seems to have no ill effects on command-line-editing
|
* that I've noticed so far. - RT
|
* that I've noticed so far. - RT
|
*/
|
*/
|
|
|
}
|
}
|
else if (str == term_dc)
|
else if (str == term_dc)
|
{
|
{
|
|
|
/* Delete character at current cursor position */
|
/* Delete character at current cursor position */
|
wdelch (cmdWin->generic.handle);
|
wdelch (cmdWin->generic.handle);
|
wrefresh (cmdWin->generic.handle);
|
wrefresh (cmdWin->generic.handle);
|
|
|
}
|
}
|
else if (str == term_im)
|
else if (str == term_im)
|
{
|
{
|
|
|
/* Turn on insert mode. */
|
/* Turn on insert mode. */
|
insert_mode = 1;
|
insert_mode = 1;
|
|
|
}
|
}
|
else if (str == term_ei)
|
else if (str == term_ei)
|
{
|
{
|
|
|
/* Turn off insert mode. */
|
/* Turn off insert mode. */
|
insert_mode = 0;
|
insert_mode = 0;
|
|
|
/* Strings we know about but don't handle
|
/* Strings we know about but don't handle
|
* specially here are just passed along to tputs().
|
* specially here are just passed along to tputs().
|
*
|
*
|
* These are not handled because (as far as I can tell)
|
* These are not handled because (as far as I can tell)
|
* they are not actually emitted by the readline package
|
* they are not actually emitted by the readline package
|
* in the course of doing command-line editing. Some of them
|
* in the course of doing command-line editing. Some of them
|
* theoretically could be used in the future, in which case we'd
|
* theoretically could be used in the future, in which case we'd
|
* need to handle them.
|
* need to handle them.
|
*/
|
*/
|
}
|
}
|
else if (str == term_ic || /* insert character */
|
else if (str == term_ic || /* insert character */
|
str == term_cursor_move || /* cursor move */
|
str == term_cursor_move || /* cursor move */
|
str == term_clrpag || /* clear page */
|
str == term_clrpag || /* clear page */
|
str == term_mm || /* turn on meta key */
|
str == term_mm || /* turn on meta key */
|
str == term_mo || /* turn off meta key */
|
str == term_mo || /* turn off meta key */
|
str == term_up || /* up one line (not expected) */
|
str == term_up || /* up one line (not expected) */
|
str == term_scroll_region || /* set scroll region */
|
str == term_scroll_region || /* set scroll region */
|
str == term_memory_lock || /* lock screen above cursor */
|
str == term_memory_lock || /* lock screen above cursor */
|
str == term_memory_unlock || /* unlock screen above cursor */
|
str == term_memory_unlock || /* unlock screen above cursor */
|
str == visible_bell)
|
str == visible_bell)
|
{ /* flash screen */
|
{ /* flash screen */
|
tputs (str, affcnt, putfunc);
|
tputs (str, affcnt, putfunc);
|
}
|
}
|
else
|
else
|
{ /* something else */
|
{ /* something else */
|
tputs (str, affcnt, putfunc);
|
tputs (str, affcnt, putfunc);
|
}
|
}
|
} /* tui_tputs */
|
} /* tui_tputs */
|
|
|
|
|
/*
|
/*
|
** tui_vwgetch()
|
** tui_vwgetch()
|
** Wrapper around wgetch with the window in a va_list
|
** Wrapper around wgetch with the window in a va_list
|
*/
|
*/
|
unsigned int
|
unsigned int
|
#ifdef __STDC__
|
#ifdef __STDC__
|
tui_vwgetch (va_list args)
|
tui_vwgetch (va_list args)
|
#else
|
#else
|
tui_vwgetch (args)
|
tui_vwgetch (args)
|
va_list args;
|
va_list args;
|
#endif
|
#endif
|
{
|
{
|
unsigned int ch;
|
unsigned int ch;
|
WINDOW *window;
|
WINDOW *window;
|
|
|
window = va_arg (args, WINDOW *);
|
window = va_arg (args, WINDOW *);
|
|
|
return ((unsigned int) wgetch (window));
|
return ((unsigned int) wgetch (window));
|
} /* tui_vwgetch */
|
} /* tui_vwgetch */
|
|
|
|
|
/*
|
/*
|
** tui_vread()
|
** tui_vread()
|
** Wrapper around read() with paramets in a va_list
|
** Wrapper around read() with paramets in a va_list
|
*/
|
*/
|
unsigned int
|
unsigned int
|
#ifdef __STDC__
|
#ifdef __STDC__
|
tui_vread (va_list args)
|
tui_vread (va_list args)
|
#else
|
#else
|
tui_vread (args)
|
tui_vread (args)
|
va_list args;
|
va_list args;
|
#endif
|
#endif
|
{
|
{
|
int result = 0;
|
int result = 0;
|
int filedes = va_arg (args, int);
|
int filedes = va_arg (args, int);
|
char *buf = va_arg (args, char *);
|
char *buf = va_arg (args, char *);
|
int nbytes = va_arg (args, int);
|
int nbytes = va_arg (args, int);
|
|
|
result = read (filedes, buf, nbytes);
|
result = read (filedes, buf, nbytes);
|
|
|
return result;
|
return result;
|
} /* tui_vread() */
|
} /* tui_vread() */
|
|
|
/*
|
/*
|
** tuiRead()
|
** tuiRead()
|
** Function to perform a read() catching resize events
|
** Function to perform a read() catching resize events
|
*/
|
*/
|
int
|
int
|
#ifdef __STDC__
|
#ifdef __STDC__
|
tuiRead (
|
tuiRead (
|
int filedes,
|
int filedes,
|
char *buf,
|
char *buf,
|
int nbytes)
|
int nbytes)
|
#else
|
#else
|
tuiRead (filedes, buf, nbytes)
|
tuiRead (filedes, buf, nbytes)
|
int filedes;
|
int filedes;
|
char *buf;
|
char *buf;
|
int nbytes;
|
int nbytes;
|
#endif
|
#endif
|
{
|
{
|
int result = 0;
|
int result = 0;
|
|
|
result = (int) vcatch_errors ((OpaqueFuncPtr) tui_vread, filedes, buf, nbytes);
|
result = (int) vcatch_errors ((OpaqueFuncPtr) tui_vread, filedes, buf, nbytes);
|
*buf = _tuiHandleResizeDuringIO (*buf);
|
*buf = _tuiHandleResizeDuringIO (*buf);
|
|
|
return result;
|
return result;
|
} /* tuiRead */
|
} /* tuiRead */
|
|
|
|
|
/*
|
/*
|
** tuiGetc().
|
** tuiGetc().
|
** Get a character from the command window.
|
** Get a character from the command window.
|
** This is called from the readline package,
|
** This is called from the readline package,
|
** that is, we have:
|
** that is, we have:
|
** tuiGetc() [here], called from
|
** tuiGetc() [here], called from
|
** readline code [in ../readline/], called from
|
** readline code [in ../readline/], called from
|
** command_line_input() in top.c
|
** command_line_input() in top.c
|
*/
|
*/
|
unsigned int
|
unsigned int
|
#ifdef __STDC__
|
#ifdef __STDC__
|
tuiGetc (void)
|
tuiGetc (void)
|
#else
|
#else
|
tuiGetc ()
|
tuiGetc ()
|
#endif
|
#endif
|
{
|
{
|
unsigned int ch;
|
unsigned int ch;
|
extern char *rl_prompt;
|
extern char *rl_prompt;
|
extern char *rl_line_buffer;
|
extern char *rl_line_buffer;
|
extern int rl_point;
|
extern int rl_point;
|
|
|
/* Call the curses routine that reads one character */
|
/* Call the curses routine that reads one character */
|
#ifndef COMMENT
|
#ifndef COMMENT
|
ch = (unsigned int) vcatch_errors ((OpaqueFuncPtr) tui_vwgetch,
|
ch = (unsigned int) vcatch_errors ((OpaqueFuncPtr) tui_vwgetch,
|
cmdWin->generic.handle);
|
cmdWin->generic.handle);
|
#else
|
#else
|
ch = wgetch (cmdWin->generic.handle);
|
ch = wgetch (cmdWin->generic.handle);
|
#endif
|
#endif
|
ch = _tuiHandleResizeDuringIO (ch);
|
ch = _tuiHandleResizeDuringIO (ch);
|
|
|
if (m_isCommandChar (ch))
|
if (m_isCommandChar (ch))
|
{ /* Handle prev/next/up/down here */
|
{ /* Handle prev/next/up/down here */
|
tuiTermSetup (0);
|
tuiTermSetup (0);
|
ch = tuiDispatchCtrlChar (ch);
|
ch = tuiDispatchCtrlChar (ch);
|
cmdWin->detail.commandInfo.curch = strlen (rl_prompt) + rl_point;
|
cmdWin->detail.commandInfo.curch = strlen (rl_prompt) + rl_point;
|
tuiTermUnsetup (0, cmdWin->detail.commandInfo.curch);
|
tuiTermUnsetup (0, cmdWin->detail.commandInfo.curch);
|
}
|
}
|
if (ch == '\n' || ch == '\r' || ch == '\f')
|
if (ch == '\n' || ch == '\r' || ch == '\f')
|
cmdWin->detail.commandInfo.curch = 0;
|
cmdWin->detail.commandInfo.curch = 0;
|
else
|
else
|
tuiIncrCommandCharCountBy (1);
|
tuiIncrCommandCharCountBy (1);
|
|
|
return ch;
|
return ch;
|
} /* tuiGetc */
|
} /* tuiGetc */
|
|
|
|
|
/*
|
/*
|
** tuiBufferGetc().
|
** tuiBufferGetc().
|
*/
|
*/
|
/*elz: this function reads a line of input from the user and
|
/*elz: this function reads a line of input from the user and
|
puts it in a static buffer. Subsequent calls to this same function
|
puts it in a static buffer. Subsequent calls to this same function
|
obtain one char at the time, providing the caller with a behavior
|
obtain one char at the time, providing the caller with a behavior
|
similar to fgetc. When the input is buffered, the backspaces have
|
similar to fgetc. When the input is buffered, the backspaces have
|
the needed effect, i.e. ignore the last char active in the buffer */
|
the needed effect, i.e. ignore the last char active in the buffer */
|
/* so far this function is called only from the query function in
|
/* so far this function is called only from the query function in
|
utils.c */
|
utils.c */
|
|
|
unsigned int
|
unsigned int
|
#ifdef __STDC__
|
#ifdef __STDC__
|
tuiBufferGetc (void)
|
tuiBufferGetc (void)
|
#else
|
#else
|
tuiBufferGetc ()
|
tuiBufferGetc ()
|
#endif
|
#endif
|
{
|
{
|
unsigned int ch;
|
unsigned int ch;
|
static unsigned char _ibuffer[512];
|
static unsigned char _ibuffer[512];
|
static int index_read = -1;
|
static int index_read = -1;
|
static int length_of_answer = -1;
|
static int length_of_answer = -1;
|
int pos = 0;
|
int pos = 0;
|
|
|
if (length_of_answer == -1)
|
if (length_of_answer == -1)
|
{
|
{
|
/* this is the first time through, need to read the answer */
|
/* this is the first time through, need to read the answer */
|
do
|
do
|
{
|
{
|
/* Call the curses routine that reads one character */
|
/* Call the curses routine that reads one character */
|
ch = (unsigned int) wgetch (cmdWin->generic.handle);
|
ch = (unsigned int) wgetch (cmdWin->generic.handle);
|
if (ch != '\b')
|
if (ch != '\b')
|
{
|
{
|
_ibuffer[pos] = ch;
|
_ibuffer[pos] = ch;
|
pos++;
|
pos++;
|
}
|
}
|
else
|
else
|
pos--;
|
pos--;
|
}
|
}
|
while (ch != '\r' && ch != '\n');
|
while (ch != '\r' && ch != '\n');
|
|
|
length_of_answer = pos;
|
length_of_answer = pos;
|
index_read = 0;
|
index_read = 0;
|
}
|
}
|
|
|
ch = _ibuffer[index_read];
|
ch = _ibuffer[index_read];
|
index_read++;
|
index_read++;
|
|
|
if (index_read == length_of_answer)
|
if (index_read == length_of_answer)
|
{
|
{
|
/*this is the last time through, reset for next query */
|
/*this is the last time through, reset for next query */
|
index_read = -1;
|
index_read = -1;
|
length_of_answer = -1;
|
length_of_answer = -1;
|
}
|
}
|
|
|
wrefresh (cmdWin->generic.handle);
|
wrefresh (cmdWin->generic.handle);
|
|
|
return (ch);
|
return (ch);
|
} /* tuiBufferGetc */
|
} /* tuiBufferGetc */
|
|
|
|
|
/*
|
/*
|
** tuiStartNewLines().
|
** tuiStartNewLines().
|
*/
|
*/
|
void
|
void
|
#ifdef __STDC__
|
#ifdef __STDC__
|
tuiStartNewLines (
|
tuiStartNewLines (
|
int numLines)
|
int numLines)
|
#else
|
#else
|
tuiStartNewLines (numLines)
|
tuiStartNewLines (numLines)
|
int numLines;
|
int numLines;
|
#endif
|
#endif
|
{
|
{
|
if (numLines > 0)
|
if (numLines > 0)
|
{
|
{
|
if (cmdWin->generic.viewportHeight > 1 &&
|
if (cmdWin->generic.viewportHeight > 1 &&
|
cmdWin->detail.commandInfo.curLine < cmdWin->generic.viewportHeight)
|
cmdWin->detail.commandInfo.curLine < cmdWin->generic.viewportHeight)
|
cmdWin->detail.commandInfo.curLine += numLines;
|
cmdWin->detail.commandInfo.curLine += numLines;
|
else
|
else
|
scroll (cmdWin->generic.handle);
|
scroll (cmdWin->generic.handle);
|
cmdWin->detail.commandInfo.curch = 0;
|
cmdWin->detail.commandInfo.curch = 0;
|
wmove (cmdWin->generic.handle,
|
wmove (cmdWin->generic.handle,
|
cmdWin->detail.commandInfo.curLine,
|
cmdWin->detail.commandInfo.curLine,
|
cmdWin->detail.commandInfo.curch);
|
cmdWin->detail.commandInfo.curch);
|
tuiRefreshWin (&cmdWin->generic);
|
tuiRefreshWin (&cmdWin->generic);
|
}
|
}
|
|
|
return;
|
return;
|
} /* tuiStartNewLines */
|
} /* tuiStartNewLines */
|
|
|
|
|
/*
|
/*
|
** tui_vStartNewLines().
|
** tui_vStartNewLines().
|
** With numLines in a va_list
|
** With numLines in a va_list
|
*/
|
*/
|
void
|
void
|
#ifdef __STDC__
|
#ifdef __STDC__
|
tui_vStartNewLines (
|
tui_vStartNewLines (
|
va_list args)
|
va_list args)
|
#else
|
#else
|
tui_vStartNewLines (args)
|
tui_vStartNewLines (args)
|
va_list args;
|
va_list args;
|
#endif
|
#endif
|
{
|
{
|
int numLines = va_arg (args, int);
|
int numLines = va_arg (args, int);
|
|
|
tuiStartNewLines (numLines);
|
tuiStartNewLines (numLines);
|
|
|
return;
|
return;
|
} /* tui_vStartNewLines */
|
} /* tui_vStartNewLines */
|
|
|
|
|
/****************************************************************************
|
/****************************************************************************
|
** LOCAL STATIC FUNCTIONS **
|
** LOCAL STATIC FUNCTIONS **
|
*****************************************************************************/
|
*****************************************************************************/
|
|
|
|
|
/*
|
/*
|
** _tuiHandleResizeDuringIO
|
** _tuiHandleResizeDuringIO
|
** This function manages the cleanup when a resize has occured
|
** This function manages the cleanup when a resize has occured
|
** From within a call to getch() or read. Returns the character
|
** From within a call to getch() or read. Returns the character
|
** to return from getc or read.
|
** to return from getc or read.
|
*/
|
*/
|
static unsigned int
|
static unsigned int
|
#ifdef __STDC__
|
#ifdef __STDC__
|
_tuiHandleResizeDuringIO (
|
_tuiHandleResizeDuringIO (
|
unsigned int originalCh) /* the char just read */
|
unsigned int originalCh) /* the char just read */
|
#else
|
#else
|
_tuiHandleResizeDuringIO (originalCh)
|
_tuiHandleResizeDuringIO (originalCh)
|
unsigned int originalCh;
|
unsigned int originalCh;
|
#endif
|
#endif
|
{
|
{
|
if (tuiWinResized ())
|
if (tuiWinResized ())
|
{
|
{
|
tuiDo ((TuiOpaqueFuncPtr) tuiRefreshAll);
|
tuiDo ((TuiOpaqueFuncPtr) tuiRefreshAll);
|
dont_repeat ();
|
dont_repeat ();
|
tuiSetWinResizedTo (FALSE);
|
tuiSetWinResizedTo (FALSE);
|
rl_reset ();
|
rl_reset ();
|
return '\n';
|
return '\n';
|
}
|
}
|
else
|
else
|
return originalCh;
|
return originalCh;
|
} /* _tuiHandleResizeDuringIO */
|
} /* _tuiHandleResizeDuringIO */
|
|
|
|
|
/*
|
/*
|
** _updateCommandInfo().
|
** _updateCommandInfo().
|
** Function to update the command window information.
|
** Function to update the command window information.
|
*/
|
*/
|
static void
|
static void
|
#ifdef __STDC__
|
#ifdef __STDC__
|
_updateCommandInfo (
|
_updateCommandInfo (
|
int sizeOfString)
|
int sizeOfString)
|
#else
|
#else
|
_updateCommandInfo (sizeOfString)
|
_updateCommandInfo (sizeOfString)
|
int sizeOfString;
|
int sizeOfString;
|
#endif
|
#endif
|
{
|
{
|
|
|
if ((sizeOfString +
|
if ((sizeOfString +
|
cmdWin->detail.commandInfo.curch) > cmdWin->generic.width)
|
cmdWin->detail.commandInfo.curch) > cmdWin->generic.width)
|
{
|
{
|
int newCurch = sizeOfString + cmdWin->detail.commandInfo.curch;
|
int newCurch = sizeOfString + cmdWin->detail.commandInfo.curch;
|
|
|
tuiStartNewLines (1);
|
tuiStartNewLines (1);
|
cmdWin->detail.commandInfo.curch = newCurch - cmdWin->generic.width;
|
cmdWin->detail.commandInfo.curch = newCurch - cmdWin->generic.width;
|
}
|
}
|
else
|
else
|
cmdWin->detail.commandInfo.curch += sizeOfString;
|
cmdWin->detail.commandInfo.curch += sizeOfString;
|
|
|
return;
|
return;
|
} /* _updateCommandInfo */
|
} /* _updateCommandInfo */
|
|
|
|
|
/* Looked at in main.c, fputs_unfiltered(), to decide
|
/* Looked at in main.c, fputs_unfiltered(), to decide
|
* if it's safe to do standard output to the command window.
|
* if it's safe to do standard output to the command window.
|
*/
|
*/
|
int tui_owns_terminal = 0;
|
int tui_owns_terminal = 0;
|
|
|
/* Called to set up the terminal for TUI (curses) I/O.
|
/* Called to set up the terminal for TUI (curses) I/O.
|
* We do this either on our way "in" to GDB after target
|
* We do this either on our way "in" to GDB after target
|
* program execution, or else within tuiDo just before
|
* program execution, or else within tuiDo just before
|
* going off to TUI routines.
|
* going off to TUI routines.
|
*/
|
*/
|
|
|
void
|
void
|
#ifdef __STDC__
|
#ifdef __STDC__
|
tuiTermSetup (
|
tuiTermSetup (
|
int turn_off_echo)
|
int turn_off_echo)
|
#else
|
#else
|
tuiTermSetup (turn_off_echo)
|
tuiTermSetup (turn_off_echo)
|
int turn_off_echo;
|
int turn_off_echo;
|
#endif
|
#endif
|
{
|
{
|
char *buffer;
|
char *buffer;
|
int start;
|
int start;
|
int end;
|
int end;
|
int endcol;
|
int endcol;
|
extern char *term_scroll_region;
|
extern char *term_scroll_region;
|
extern char *term_cursor_move;
|
extern char *term_cursor_move;
|
extern char *term_memory_lock;
|
extern char *term_memory_lock;
|
extern char *term_memory_unlock;
|
extern char *term_memory_unlock;
|
|
|
/* Turn off echoing, since the TUI does not
|
/* Turn off echoing, since the TUI does not
|
* expect echoing. Below I only put in the TERMIOS
|
* expect echoing. Below I only put in the TERMIOS
|
* case, since that is what applies on HP-UX. turn_off_echo
|
* case, since that is what applies on HP-UX. turn_off_echo
|
* is 1 except for the case where we're being called
|
* is 1 except for the case where we're being called
|
* on a "quit", in which case we want to leave echo on.
|
* on a "quit", in which case we want to leave echo on.
|
*/
|
*/
|
if (turn_off_echo)
|
if (turn_off_echo)
|
{
|
{
|
#ifdef HAVE_TERMIOS
|
#ifdef HAVE_TERMIOS
|
struct termios tio;
|
struct termios tio;
|
tcgetattr (0, &tio);
|
tcgetattr (0, &tio);
|
tio.c_lflag &= ~(ECHO);
|
tio.c_lflag &= ~(ECHO);
|
tcsetattr (0, TCSANOW, &tio);
|
tcsetattr (0, TCSANOW, &tio);
|
#endif
|
#endif
|
}
|
}
|
|
|
/* Compute the start and end lines of the command
|
/* Compute the start and end lines of the command
|
* region. (Actually we only use end here)
|
* region. (Actually we only use end here)
|
*/
|
*/
|
start = winList[CMD_WIN]->generic.origin.y;
|
start = winList[CMD_WIN]->generic.origin.y;
|
end = start + winList[CMD_WIN]->generic.height - 1;
|
end = start + winList[CMD_WIN]->generic.height - 1;
|
endcol = winList[CMD_WIN]->generic.width - 1;
|
endcol = winList[CMD_WIN]->generic.width - 1;
|
|
|
if (term_memory_unlock)
|
if (term_memory_unlock)
|
{
|
{
|
|
|
/* Un-do the effect of the memory lock in terminal_inferior() */
|
/* Un-do the effect of the memory lock in terminal_inferior() */
|
tputs (term_memory_unlock, 1, (int (*)PARAMS ((int))) putchar);
|
tputs (term_memory_unlock, 1, (int (*)PARAMS ((int))) putchar);
|
fflush (stdout);
|
fflush (stdout);
|
|
|
}
|
}
|
else if (term_scroll_region)
|
else if (term_scroll_region)
|
{
|
{
|
|
|
/* Un-do the effect of setting scroll region in terminal_inferior() */
|
/* Un-do the effect of setting scroll region in terminal_inferior() */
|
/* I'm actually not sure how to do this (we don't know for
|
/* I'm actually not sure how to do this (we don't know for
|
* sure what the scroll region was *before* we changed it),
|
* sure what the scroll region was *before* we changed it),
|
* but I'll guess that setting it to the whole screen is
|
* but I'll guess that setting it to the whole screen is
|
* the right thing. So, ...
|
* the right thing. So, ...
|
*/
|
*/
|
|
|
/* Set scroll region to be 0..end */
|
/* Set scroll region to be 0..end */
|
buffer = (char *) tgoto (term_scroll_region, end, 0);
|
buffer = (char *) tgoto (term_scroll_region, end, 0);
|
tputs (buffer, 1, (int (*)PARAMS ((int))) putchar);
|
tputs (buffer, 1, (int (*)PARAMS ((int))) putchar);
|
|
|
} /* else we're out of luck */
|
} /* else we're out of luck */
|
|
|
/* This is an attempt to keep the logical & physical
|
/* This is an attempt to keep the logical & physical
|
* cursor in synch, going into curses. Without this,
|
* cursor in synch, going into curses. Without this,
|
* curses seems to be confused by the fact that
|
* curses seems to be confused by the fact that
|
* GDB has physically moved the curser on it. One
|
* GDB has physically moved the curser on it. One
|
* visible effect of removing this code is that the
|
* visible effect of removing this code is that the
|
* locator window fails to get updated and the line
|
* locator window fails to get updated and the line
|
* of text that *should* go into the locator window
|
* of text that *should* go into the locator window
|
* often goes to the wrong place.
|
* often goes to the wrong place.
|
*/
|
*/
|
/* What's done here is to tell curses to write a ' '
|
/* What's done here is to tell curses to write a ' '
|
* at the bottom right corner of the screen.
|
* at the bottom right corner of the screen.
|
* The idea is to wind up with the cursor in a known
|
* The idea is to wind up with the cursor in a known
|
* place.
|
* place.
|
* Note I'm relying on refresh()
|
* Note I'm relying on refresh()
|
* only writing what changed (the space),
|
* only writing what changed (the space),
|
* not the whole screen.
|
* not the whole screen.
|
*/
|
*/
|
standend ();
|
standend ();
|
move (end, endcol - 1);
|
move (end, endcol - 1);
|
addch (' ');
|
addch (' ');
|
refresh ();
|
refresh ();
|
|
|
tui_owns_terminal = 1;
|
tui_owns_terminal = 1;
|
} /* tuiTermSetup */
|
} /* tuiTermSetup */
|
|
|
|
|
/* Called to set up the terminal for target program I/O, meaning I/O
|
/* Called to set up the terminal for target program I/O, meaning I/O
|
* is confined to the command-window area. We also call this on our
|
* is confined to the command-window area. We also call this on our
|
* way out of tuiDo, thus setting up the terminal this way for
|
* way out of tuiDo, thus setting up the terminal this way for
|
* debugger command I/O. */
|
* debugger command I/O. */
|
void
|
void
|
#ifdef __STDC__
|
#ifdef __STDC__
|
tuiTermUnsetup (
|
tuiTermUnsetup (
|
int turn_on_echo,
|
int turn_on_echo,
|
int to_column)
|
int to_column)
|
#else
|
#else
|
tuiTermUnsetup (turn_on_echo, to_column)
|
tuiTermUnsetup (turn_on_echo, to_column)
|
int turn_on_echo;
|
int turn_on_echo;
|
int to_column;
|
int to_column;
|
#endif
|
#endif
|
{
|
{
|
int start;
|
int start;
|
int end;
|
int end;
|
int curline;
|
int curline;
|
char *buffer;
|
char *buffer;
|
/* The next bunch of things are from readline */
|
/* The next bunch of things are from readline */
|
extern char *term_scroll_region;
|
extern char *term_scroll_region;
|
extern char *term_cursor_move;
|
extern char *term_cursor_move;
|
extern char *term_memory_lock;
|
extern char *term_memory_lock;
|
extern char *term_memory_unlock;
|
extern char *term_memory_unlock;
|
extern char *term_se;
|
extern char *term_se;
|
|
|
/* We need to turn on echoing, since the TUI turns it off */
|
/* We need to turn on echoing, since the TUI turns it off */
|
/* Below I only put in the TERMIOS case, since that
|
/* Below I only put in the TERMIOS case, since that
|
* is what applies on HP-UX.
|
* is what applies on HP-UX.
|
*/
|
*/
|
if (turn_on_echo)
|
if (turn_on_echo)
|
{
|
{
|
#ifdef HAVE_TERMIOS
|
#ifdef HAVE_TERMIOS
|
struct termios tio;
|
struct termios tio;
|
tcgetattr (0, &tio);
|
tcgetattr (0, &tio);
|
tio.c_lflag |= (ECHO);
|
tio.c_lflag |= (ECHO);
|
tcsetattr (0, TCSANOW, &tio);
|
tcsetattr (0, TCSANOW, &tio);
|
#endif
|
#endif
|
}
|
}
|
|
|
/* Compute the start and end lines of the command
|
/* Compute the start and end lines of the command
|
* region, as well as the last "real" line of
|
* region, as well as the last "real" line of
|
* the region (normally same as end, except when
|
* the region (normally same as end, except when
|
* we're first populating the region)
|
* we're first populating the region)
|
*/
|
*/
|
start = winList[CMD_WIN]->generic.origin.y;
|
start = winList[CMD_WIN]->generic.origin.y;
|
end = start + winList[CMD_WIN]->generic.height - 1;
|
end = start + winList[CMD_WIN]->generic.height - 1;
|
curline = start + winList[CMD_WIN]->detail.commandInfo.curLine;
|
curline = start + winList[CMD_WIN]->detail.commandInfo.curLine;
|
|
|
/* We want to confine target I/O to the command region.
|
/* We want to confine target I/O to the command region.
|
* In order to do so, we must either have "memory lock"
|
* In order to do so, we must either have "memory lock"
|
* (hpterm's) or "scroll regions" (xterm's).
|
* (hpterm's) or "scroll regions" (xterm's).
|
*/
|
*/
|
if (term_cursor_move && term_memory_lock)
|
if (term_cursor_move && term_memory_lock)
|
{
|
{
|
|
|
/* Memory lock means lock region above cursor.
|
/* Memory lock means lock region above cursor.
|
* So first position the cursor, then call memory lock.
|
* So first position the cursor, then call memory lock.
|
*/
|
*/
|
buffer = tgoto (term_cursor_move, 0, start);
|
buffer = tgoto (term_cursor_move, 0, start);
|
tputs (buffer, 1, (int (*)PARAMS ((int))) putchar);
|
tputs (buffer, 1, (int (*)PARAMS ((int))) putchar);
|
tputs (term_memory_lock, 1, (int (*)PARAMS ((int))) putchar);
|
tputs (term_memory_lock, 1, (int (*)PARAMS ((int))) putchar);
|
|
|
}
|
}
|
else if (term_scroll_region)
|
else if (term_scroll_region)
|
{
|
{
|
|
|
/* Set the scroll region to the command window */
|
/* Set the scroll region to the command window */
|
buffer = tgoto (term_scroll_region, end, start);
|
buffer = tgoto (term_scroll_region, end, start);
|
tputs (buffer, 1, (int (*)PARAMS ((int))) putchar);
|
tputs (buffer, 1, (int (*)PARAMS ((int))) putchar);
|
|
|
} /* else we can't do anything about target I/O */
|
} /* else we can't do anything about target I/O */
|
|
|
/* Also turn off standout mode, in case it is on */
|
/* Also turn off standout mode, in case it is on */
|
if (term_se != NULL)
|
if (term_se != NULL)
|
tputs (term_se, 1, (int (*)PARAMS ((int))) putchar);
|
tputs (term_se, 1, (int (*)PARAMS ((int))) putchar);
|
|
|
/* Now go to the appropriate spot on the end line */
|
/* Now go to the appropriate spot on the end line */
|
buffer = tgoto (term_cursor_move, to_column, end);
|
buffer = tgoto (term_cursor_move, to_column, end);
|
tputs (buffer, 1, (int (*)PARAMS ((int))) putchar);
|
tputs (buffer, 1, (int (*)PARAMS ((int))) putchar);
|
fflush (stdout);
|
fflush (stdout);
|
|
|
tui_owns_terminal = 0;
|
tui_owns_terminal = 0;
|
} /* tuiTermUnsetup */
|
} /* tuiTermUnsetup */
|
|
|