Back to index

tetex-bin  3.0
Defines | Functions | Variables
pcterm.c File Reference
#include <pc.h>
#include <keys.h>
#include <conio.h>
#include "variables.h"
#include <limits.h>
#include "signals.h"
#include "session.h"

Go to the source code of this file.

Defines

#define PATH_MAX   512
#define SIGUSR1   0
#define SIGQUIT   0

Functions

static unsigned const char * find_sequence (int)
static void pc_begin_inverse (void)
static void pc_end_inverse (void)
static void pc_up_line (void)
static void pc_down_line (void)
static void pc_clear_screen (void)
static void pc_clear_to_eol (void)
static void pc_get_screen_size (void)
static void pc_goto_xy (int x, int y)
static void pc_put_text (char *string)
static void pc_ring_bell (void)
static void pc_write_chars (char *string, int nchars)
static void pc_scroll_terminal (int start, int end, int amount)
static void pc_prep_terminal (void)
static void pc_unprep_terminal (void)
static void pc_initialize_terminal (char *term_name)
int kill (pid_t pid, int sig)
void tputs (char *a, int b, int(*c)())
char * tgoto (char *a, int b, int c)
int tgetnum (char *a)
int tgetflag (char *a)
char * tgetstr (char *a, char **b)
int tgetent (char *a, char *b)
int tcgetattr (int fildes, struct termios *termios_p)
int tcsetattr (int fd, int opt_actions, const struct termios *termios_p)

Variables

int speech_friendly
static struct text_info
static unsigned char norm_attr
static unsigned char inv_attr

Define Documentation

#define PATH_MAX   512

Definition at line 648 of file pcterm.c.

#define SIGQUIT   0

Definition at line 658 of file pcterm.c.

#define SIGUSR1   0

Definition at line 655 of file pcterm.c.


Function Documentation

static unsigned const char* find_sequence ( int  ) [static]

Here is the caller graph for this function:

int kill ( pid_t  pid,
int  sig 
)

Definition at line 662 of file pcterm.c.

{
  static char interrupted_msg[] = "Interrupted\r\n";
  static char stopped_msg[] = "Stopped.  Type `exit RET' to return.\r\n";
  char cwd[PATH_MAX + 1];

  if (pid == getpid ()
      || pid == 0
      || pid == -1
      || pid == -getpid ())
    {
      switch (sig)
       {
       RETSIGTYPE (*old_INT)(int), (*old_QUIT)(int);

       case SIGINT:
#ifdef __DJGPP__
         /* If SIGINT was generated by a readable key, we want to remove
            it from the PC keyboard buffer, so that DOS and other
            programs never see it.  DJGPP signal-handling mechanism
            doesn't remove the INT key from the keyboard buffer.  */
         if (!kbd_buffer_empty ())
           getxkey ();
#endif
         pc_write_chars (interrupted_msg, sizeof (interrupted_msg) - 1);
         xexit (1);
       case SIGUSR1:
         /* Simulate SIGTSTP by invoking a subsidiary shell.  */
         pc_goto_xy (0, outside_info.screenheight - 1);
         pc_clear_to_eol ();
         pc_write_chars (stopped_msg, sizeof (stopped_msg) - 1);

         /* The child shell can change the working directory, so
            we need to save and restore it, since it is global.  */
         if (!getcwd (cwd, PATH_MAX)) /* should never happen */
           cwd[0] = '\0';

         /* We don't want to get fatal signals while the subshell runs.  */
         old_INT = signal (SIGINT, SIG_IGN);
         old_QUIT = signal (SIGQUIT, SIG_IGN);
         system ("");
         if (*cwd)
           chdir (cwd);
         signal (SIGINT, old_INT);
         signal (SIGQUIT, old_QUIT);
         break;
       default:
         if (sig)
           raise (sig);
         break;
       }
      return 0;
    }
  else
    return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void pc_begin_inverse ( void  ) [static]

Definition at line 53 of file pcterm.c.

{
  textattr (inv_attr);
}

Here is the caller graph for this function:

static void pc_clear_screen ( void  ) [static]

Definition at line 85 of file pcterm.c.

{
  ScreenClear ();
}

Here is the caller graph for this function:

static void pc_clear_to_eol ( void  ) [static]

Definition at line 92 of file pcterm.c.

{
  clreol (); /* perhaps to be replaced by a loop */
}

Here is the caller graph for this function:

static void pc_down_line ( void  ) [static]

Definition at line 76 of file pcterm.c.

{
  int x, y;
  ScreenGetCursor (&y, &x);
  ScreenSetCursor (MIN (screenheight-1, y+1), x);
}

Here is the caller graph for this function:

static void pc_end_inverse ( void  ) [static]

Definition at line 60 of file pcterm.c.

{
  textattr (norm_attr);
}

Here is the caller graph for this function:

static void pc_get_screen_size ( void  ) [static]

Definition at line 99 of file pcterm.c.

{
  /* Current screen dimensions are the default.  */
  if (!outside_info.screenheight)  /* paranoia */
    gettextinfo (&outside_info);
  screenwidth  = outside_info.screenwidth;
  screenheight = outside_info.screenheight;

  /* Environment variable "LINES" overrides the default.  */
  if (getenv ("LINES") != NULL)
    screenheight = atoi (getenv ("LINES"));

  /* Environment variable "INFO_LINES" overrides "LINES".  */
  if (getenv ("INFO_LINES") != NULL)
    screenheight = atoi (getenv ("INFO_LINES"));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void pc_goto_xy ( int  x,
int  y 
) [static]

Definition at line 118 of file pcterm.c.

{
  ScreenSetCursor (y, x); /* yes, pc.h says ScreenSetCursor (row, column) !! */
}

Here is the caller graph for this function:

static void pc_initialize_terminal ( char *  term_name) [static]

Definition at line 250 of file pcterm.c.

{
  char *info_colors;

  if (!term_name)
    {
      term_name = getenv ("TERM");
      if (!term_name)
       term_name = "pc-dos";       /* ``what's in a name?'' */
    }

  /* Get current video information, to be restored later.  */
  if (outside_info.screenwidth == 0)
    gettextinfo (&outside_info);

  /* Current screen colors are the default.  */
  norm_attr    = outside_info.normattr;
  inv_attr     = (((outside_info.normattr &    7) << 4) |
                  ((outside_info.normattr & 0x7f) >> 4));

  /* Does the user want non-default colors?  */
  info_colors = getenv ("INFO_COLORS");
  if ((info_colors != (char *)0) && !speech_friendly)
    {
      /* Decode a color from a string descriptor.
        The descriptor string is a sequence of color specifiers separated
        by a non-numeric character.  Each color specifier should represent
        a small integer which fits into an unsigned char, and can be given
        in any base supported by strtoul.  Examples of valid descriptors:

              "10 31"
              "0x13/0x45"
              "007.077"

       The separator between two color specifiers can be any character which
       cannot be used in a printed representation of an integer number.  */
      char *endp;
      unsigned long color_desc = strtoul (info_colors, &endp, 0);

      if (color_desc <= UCHAR_MAX)
       {
         norm_attr = (unsigned char)color_desc;
         color_desc = strtoul (endp + 1, &endp, 0);
         if (color_desc <= UCHAR_MAX)
           inv_attr = (unsigned char)color_desc;
       }
    }

  /* We can scroll.  */
  terminal_can_scroll = 1;

  /* We know how to produce a visible bell, if somebody's looking...  */
  if (!speech_friendly)
    terminal_has_visible_bell_p = 1;

  /* We have a Meta key.  */
  terminal_has_meta_p = 1;

  /* We are *certainly* NOT dumb!  */
  terminal_is_dumb_p = 0;

  pc_get_screen_size ();

  /* Store the arrow keys.  */
  term_ku = (char *)find_sequence (K_Up);
  term_kd = (char *)find_sequence (K_Down);
  term_kr = (char *)find_sequence (K_Right);
  term_kl = (char *)find_sequence (K_Left);

  term_kP = (char *)find_sequence (K_PageUp);
  term_kN = (char *)find_sequence (K_PageDown);

#if defined(INFOKEY)
  term_kh = (char *)find_sequence (K_Home);
  term_ke = (char *)find_sequence (K_End);
  term_ki = (char *)find_sequence (K_Insert);
  term_kx = (char *)find_sequence (K_Delete);
#endif

  /* Set all the hooks to our PC-specific functions.  */
  terminal_begin_inverse_hook       = pc_begin_inverse;
  terminal_end_inverse_hook         = pc_end_inverse;
  terminal_prep_terminal_hook       = pc_prep_terminal;
  terminal_unprep_terminal_hook     = pc_unprep_terminal;
  terminal_up_line_hook             = pc_up_line;
  terminal_down_line_hook           = pc_down_line;
  terminal_clear_screen_hook        = pc_clear_screen;
  terminal_clear_to_eol_hook        = pc_clear_to_eol;
  terminal_get_screen_size_hook     = pc_get_screen_size;
  terminal_goto_xy_hook             = pc_goto_xy;
  terminal_put_text_hook            = pc_put_text;
  terminal_ring_bell_hook           = pc_ring_bell;
  terminal_write_chars_hook         = pc_write_chars;
  terminal_scroll_terminal_hook     = pc_scroll_terminal;
}

Here is the call graph for this function:

static void pc_prep_terminal ( void  ) [static]

Definition at line 191 of file pcterm.c.

{
  int tty;

  /* Do not set screen height if we already have it, because
     doing so erases the screen.  */
  if (screenheight != ScreenRows ())
    _set_screen_lines (screenheight);

  /* Don't fail if they asked for screen dimensions that their
     hardware cannot support.  */
  screenheight = ScreenRows ();
  screenwidth  = ScreenCols ();

  /* Try setting the colors user asked for.  */
  textattr (norm_attr);
  ScreenClear ();

  /* Switch console reads to binary mode.  */
  tty = fileno (stdin);
#ifdef __DJGPP__
  setmode (tty, O_BINARY);
  __djgpp_set_ctrl_c (1);   /* re-enable SIGINT generation by Ctrl-C */
#endif
}

Here is the caller graph for this function:

static void pc_put_text ( char *  string) [static]

Definition at line 126 of file pcterm.c.

{
  if (speech_friendly)
    fputs (string, stdout);
  else
    cputs (string);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void pc_ring_bell ( void  ) [static]

Definition at line 138 of file pcterm.c.

{
  if (terminal_has_visible_bell_p && terminal_use_visible_bell_p)
    ScreenVisualBell ();
  else
    {
      printf ("%c",'\a');
      fflush (stdout);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void pc_scroll_terminal ( int  start,
int  end,
int  amount 
) [static]

Definition at line 170 of file pcterm.c.

{
  int line_to_clear = amount > 0 ? start : end + amount;

  /* Move the text.  Note that `movetext' expects 1-based coordinates.  */
  movetext (1, start + 1, ScreenCols (), end, 1, start + amount + 1);

  /* Now clear the lines which were left unoccupied.  */
  if (amount < 0)
    amount = -amount;
  while (amount--)
    {
      ScreenSetCursor (line_to_clear++, 0);
      clreol ();
    }
}

Here is the caller graph for this function:

static void pc_unprep_terminal ( void  ) [static]

Definition at line 220 of file pcterm.c.

{
  int tty;

  textattr (outside_info.normattr);

  /* Do not set screen height if we already have it, because
     doing so erases the screen.  */
  if (outside_info.screenheight != ScreenRows ())
    {
      _set_screen_lines (outside_info.screenheight);
      textmode (LASTMODE);
    }
  else
    pc_clear_to_eol ();     /* for text attributes to really take effect */

  /* Switch back to text mode on stdin.  */
  tty = fileno (stdin);
#ifdef __DJGPP__
  setmode (tty, O_TEXT);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void pc_up_line ( void  ) [static]

Definition at line 67 of file pcterm.c.

{
  int x, y;
  ScreenGetCursor (&y, &x);
  ScreenSetCursor (MAX (y-1, 0), x);
}

Here is the caller graph for this function:

static void pc_write_chars ( char *  string,
int  nchars 
) [static]

Definition at line 151 of file pcterm.c.

{
  if (!nchars)
    return;

  if (speech_friendly)
    printf ("%.*s",nchars, string);
  else
    cprintf ("%..*s",nchars, string);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int tcgetattr ( int  fildes,
struct termios *  termios_p 
)

Definition at line 751 of file pcterm.c.

{
  perror ("tcgetattr"); return 0;
}

Here is the caller graph for this function:

int tcsetattr ( int  fd,
int  opt_actions,
const struct termios *  termios_p 
)

Definition at line 756 of file pcterm.c.

{
  perror ("tcsetattr"); return 0;
}

Here is the caller graph for this function:

int tgetent ( char *  a,
char *  b 
)

Definition at line 746 of file pcterm.c.

{
  perror ("tgetent"); return 0;
}
int tgetflag ( char *  a)

Definition at line 736 of file pcterm.c.

{
  perror ("tgetflag"); return 0;
}
int tgetnum ( char *  a)

Definition at line 731 of file pcterm.c.

{
  perror ("tgetnum"); return 0;
}
char* tgetstr ( char *  a,
char **  b 
)

Definition at line 741 of file pcterm.c.

{
  perror ("tgetstr"); return 0;
}
char* tgoto ( char *  a,
int  b,
int  c 
)

Definition at line 726 of file pcterm.c.

{
  perror ("tgoto"); return 0; /* here and below, added dummy retvals */
}
void tputs ( char *  a,
int  b,
int(*)()  c 
)

Definition at line 721 of file pcterm.c.

{
  perror ("tputs");
}

Variable Documentation

unsigned char inv_attr [static]

Definition at line 47 of file pcterm.c.

unsigned char norm_attr [static]

Definition at line 47 of file pcterm.c.

struct text_info [static]

Definition at line 46 of file pcterm.c.