Back to index

lightning-sunbird  0.9+nobinonly
Defines | Typedefs | Functions
lineterm.h File Reference
#include "unistring.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define LTERM_TLOG_MODULE   1
#define LTERM_STREAMDATA_CODE   0x0001U /* Stream mode */
#define LTERM_SCREENDATA_CODE   0x0002U /* Screen mode */
#define LTERM_LINEDATA_CODE   0x0004U /* Line mode */
#define LTERM_BELL_CODE   0x0008U /* Ring bell */
#define LTERM_CLEAR_CODE   0x0010U /* Clear screen */
#define LTERM_INSERT_CODE   0x0020U /* Insert lines above current line */
#define LTERM_DELETE_CODE   0x0040U /* Delete lines below current line */
#define LTERM_SCROLL_CODE   0x0080U /* Define scrolling region */
#define LTERM_INPUT_CODE   0x0100U /* Contains STDIN at end of line */
#define LTERM_PROMPT_CODE   0x0200U /* Contains prompt at beginning */
#define LTERM_OUTPUT_CODE   0x0400U /* Contains STDOUT/STDERR/ALTOUT */
#define LTERM_META_CODE   0x0800U /* Meta input */
#define LTERM_COMPLETION_CODE   0x1000U /* Completion requested */
#define LTERM_NEWLINE_CODE   0x2000U /* Complete (new) line */
#define LTERM_HIDE_CODE   0x4000U /* Hide output */
#define LTERM_ERROR_CODE   0x8000U /* Error in output */
#define LTERM_COOKIESTR_CODE   0x10000U /* Stream prefixed with cookie */
#define LTERM_DOCSTREAM_CODE   0x20000U /* Stream contains complete document */
#define LTERM_XMLSTREAM_CODE   0x40000U /* Stream contains XML, not HTML */
#define LTERM_JSSTREAM_CODE   0x80000U /* Stream contains Javascript */
#define LTERM_WINSTREAM_CODE   0x100000U /* Display stream in entire window */
#define LTERM_PROMPT_STYLE   0x0001UL /* prompt string */
#define LTERM_STDIN_STYLE   0x0002UL /* standard input */
#define LTERM_STDOUT_STYLE   0x0004UL /* standard output */
#define LTERM_STDERR_STYLE   0x0008UL /* standard error */
#define LTERM_ALTOUT_STYLE   0x0010UL /* alternate output */
#define LTERM_URI_STYLE   0x0020UL /* URI markup */
#define LTERM_HTML_STYLE   0x0040UL /* HTML markup */
#define LTERM_XML_STYLE   0x0080UL /* XML markup */
#define LTERM_BOLD_STYLE   0x0100UL /* boldface */
#define LTERM_ULINE_STYLE   0x0200UL /* underline */
#define LTERM_BLINK_STYLE   0x0400UL /* blink */
#define LTERM_INVERSE_STYLE   0x0800UL /* inverse video */
#define LTERM_NOCANONICAL_FLAG   0x0001U
#define LTERM_NOEDIT_FLAG   0x0002U
#define LTERM_NOCOMPLETION_FLAG   0x0004U
#define LTERM_NOMETA_FLAG   0x0008U
#define LTERM_NOECHO_FLAG   0x0010U
#define LTERM_NOMARKUP_FLAG   0x0020U
#define LTERM_NOPTY_FLAG   0x0040U
#define LTERM_NONUL_FLAG   0x0080U
#define LTERM_NOLINEWRAP_FLAG   0x0100U
#define LTERM_NOEXPORT_FLAG   0x0200U
#define LTERM_STDERR_FLAG   0x0400U
#define LTERM_PARTLINE_FLAG   0x0800U
#define LTERM_DETERMINE_PROCESS   -1 /* Determine process type from name */
#define LTERM_UNKNOWN_PROCESS   0 /* Unknown process type */
#define LTERM_SH_PROCESS   1 /* Bourne shell */
#define LTERM_KSH_PROCESS   2 /* Korn shell */
#define LTERM_BASH_PROCESS   3 /* Bourne Again shell */
#define LTERM_CSH_PROCESS   4 /* C shell */
#define LTERM_TCSH_PROCESS   5 /* TC shell */
#define LTERM_WRITE_PLAIN_INPUT   0 /* Plain text user input */
#define LTERM_WRITE_XML_INPUT   1 /* XML element user input */
#define LTERM_WRITE_PLAIN_OUTPUT   2 /* Plain text server output */
#define LTERM_WRITE_CLOSE_MESSAGE   3 /* End of file message */

Typedefs

typedef voidlterm_callback_func_t
typedef UNICHAR UNISTYLE

Functions

int lterm_init (int messageLevel)
 Initializes all LTERM operations; needs to be called before any calls to lterm_new.
int lterm_new ()
 Creates a new LTERM object and returns its descriptor index but does not open it for I/O (documented in the LTERM interface)
int lterm_open (int lterm, char *const argv[], const char *cookie, const char *init_command, const UNICHAR *prompt_regexp, int options, int process_type, int rows, int cols, int x_pixels, int y_pixels, lterm_callback_func_t callback_func, void *callback_data)
 Opens line terminal indexed by LTERM for input/output and creates a process attached to it to execute the command line contained in string array ARGV.
int lterm_close (int lterm)
 Closes line terminal indexed by LTERM.
int lterm_delete (int lterm)
 Deletes an LTERM object, closing it if necessary.
void lterm_close_all (void)
 Closes all LTERMs, but does not delete them.
int lterm_setecho (int lterm, int echo_flag)
 Set input echo flag for line terminal indexed by LTERM.
int lterm_resize (int lterm, int rows, int cols)
 Resizes the line terminal indexed by LTERM to new row/column count.
int lterm_setcursor (int lterm, int row, int col)
 Sets cursor position in line terminal indexed by LTERM.
int lterm_write (int lterm, const UNICHAR *buf, int count, int dataType)
 Writes supplied to Unicode string in BUF of length COUNT to line terminal indexed by LTERM.
int lterm_metacomplete (int lterm, const UNICHAR *buf, int count)
 Completes meta input in line terminal indexed by LTERM with the supplied to Unicode string in BUF of length COUNT.
int lterm_read (int lterm, int timeout, UNICHAR *buf, int count, UNISTYLE *style, int *opcodes, int *opvals, int *buf_row, int *buf_col, int *cursor_row, int *cursor_col)
 reads upto COUNT Unicode characters from a single line of output from line terminal indexed by LTERM into BUF.

Define Documentation

#define LTERM_ALTOUT_STYLE   0x0010UL /* alternate output */

Definition at line 368 of file lineterm.h.

#define LTERM_BASH_PROCESS   3 /* Bourne Again shell */

Definition at line 398 of file lineterm.h.

#define LTERM_BELL_CODE   0x0008U /* Ring bell */

Definition at line 336 of file lineterm.h.

#define LTERM_BLINK_STYLE   0x0400UL /* blink */

Definition at line 376 of file lineterm.h.

#define LTERM_BOLD_STYLE   0x0100UL /* boldface */

Definition at line 374 of file lineterm.h.

#define LTERM_CLEAR_CODE   0x0010U /* Clear screen */

Definition at line 337 of file lineterm.h.

#define LTERM_COMPLETION_CODE   0x1000U /* Completion requested */

Definition at line 345 of file lineterm.h.

#define LTERM_COOKIESTR_CODE   0x10000U /* Stream prefixed with cookie */

Definition at line 350 of file lineterm.h.

#define LTERM_CSH_PROCESS   4 /* C shell */

Definition at line 399 of file lineterm.h.

#define LTERM_DELETE_CODE   0x0040U /* Delete lines below current line */

Definition at line 339 of file lineterm.h.

#define LTERM_DETERMINE_PROCESS   -1 /* Determine process type from name */

Definition at line 394 of file lineterm.h.

#define LTERM_DOCSTREAM_CODE   0x20000U /* Stream contains complete document */

Definition at line 351 of file lineterm.h.

#define LTERM_ERROR_CODE   0x8000U /* Error in output */

Definition at line 348 of file lineterm.h.

#define LTERM_HIDE_CODE   0x4000U /* Hide output */

Definition at line 347 of file lineterm.h.

#define LTERM_HTML_STYLE   0x0040UL /* HTML markup */

Definition at line 371 of file lineterm.h.

#define LTERM_INPUT_CODE   0x0100U /* Contains STDIN at end of line */

Definition at line 341 of file lineterm.h.

#define LTERM_INSERT_CODE   0x0020U /* Insert lines above current line */

Definition at line 338 of file lineterm.h.

#define LTERM_INVERSE_STYLE   0x0800UL /* inverse video */

Definition at line 377 of file lineterm.h.

#define LTERM_JSSTREAM_CODE   0x80000U /* Stream contains Javascript */

Definition at line 353 of file lineterm.h.

#define LTERM_KSH_PROCESS   2 /* Korn shell */

Definition at line 397 of file lineterm.h.

#define LTERM_LINEDATA_CODE   0x0004U /* Line mode */

Definition at line 335 of file lineterm.h.

#define LTERM_META_CODE   0x0800U /* Meta input */

Definition at line 344 of file lineterm.h.

#define LTERM_NEWLINE_CODE   0x2000U /* Complete (new) line */

Definition at line 346 of file lineterm.h.

Definition at line 380 of file lineterm.h.

Definition at line 382 of file lineterm.h.

#define LTERM_NOECHO_FLAG   0x0010U

Definition at line 384 of file lineterm.h.

#define LTERM_NOEDIT_FLAG   0x0002U

Definition at line 381 of file lineterm.h.

#define LTERM_NOEXPORT_FLAG   0x0200U

Definition at line 389 of file lineterm.h.

Definition at line 388 of file lineterm.h.

#define LTERM_NOMARKUP_FLAG   0x0020U

Definition at line 385 of file lineterm.h.

#define LTERM_NOMETA_FLAG   0x0008U

Definition at line 383 of file lineterm.h.

#define LTERM_NONUL_FLAG   0x0080U

Definition at line 387 of file lineterm.h.

#define LTERM_NOPTY_FLAG   0x0040U

Definition at line 386 of file lineterm.h.

#define LTERM_OUTPUT_CODE   0x0400U /* Contains STDOUT/STDERR/ALTOUT */

Definition at line 343 of file lineterm.h.

#define LTERM_PARTLINE_FLAG   0x0800U

Definition at line 391 of file lineterm.h.

#define LTERM_PROMPT_CODE   0x0200U /* Contains prompt at beginning */

Definition at line 342 of file lineterm.h.

#define LTERM_PROMPT_STYLE   0x0001UL /* prompt string */

Definition at line 364 of file lineterm.h.

#define LTERM_SCREENDATA_CODE   0x0002U /* Screen mode */

Definition at line 334 of file lineterm.h.

#define LTERM_SCROLL_CODE   0x0080U /* Define scrolling region */

Definition at line 340 of file lineterm.h.

#define LTERM_SH_PROCESS   1 /* Bourne shell */

Definition at line 396 of file lineterm.h.

#define LTERM_STDERR_FLAG   0x0400U

Definition at line 390 of file lineterm.h.

#define LTERM_STDERR_STYLE   0x0008UL /* standard error */

Definition at line 367 of file lineterm.h.

#define LTERM_STDIN_STYLE   0x0002UL /* standard input */

Definition at line 365 of file lineterm.h.

#define LTERM_STDOUT_STYLE   0x0004UL /* standard output */

Definition at line 366 of file lineterm.h.

#define LTERM_STREAMDATA_CODE   0x0001U /* Stream mode */

Definition at line 333 of file lineterm.h.

#define LTERM_TCSH_PROCESS   5 /* TC shell */

Definition at line 400 of file lineterm.h.

Definition at line 66 of file lineterm.h.

#define LTERM_ULINE_STYLE   0x0200UL /* underline */

Definition at line 375 of file lineterm.h.

Definition at line 395 of file lineterm.h.

#define LTERM_URI_STYLE   0x0020UL /* URI markup */

Definition at line 370 of file lineterm.h.

#define LTERM_WINSTREAM_CODE   0x100000U /* Display stream in entire window */

Definition at line 354 of file lineterm.h.

Definition at line 406 of file lineterm.h.

Definition at line 403 of file lineterm.h.

#define LTERM_WRITE_PLAIN_OUTPUT   2 /* Plain text server output */

Definition at line 405 of file lineterm.h.

#define LTERM_WRITE_XML_INPUT   1 /* XML element user input */

Definition at line 404 of file lineterm.h.

#define LTERM_XML_STYLE   0x0080UL /* XML markup */

Definition at line 372 of file lineterm.h.

#define LTERM_XMLSTREAM_CODE   0x40000U /* Stream contains XML, not HTML */

Definition at line 352 of file lineterm.h.


Typedef Documentation

Definition at line 53 of file lineterm.h.

typedef UNICHAR UNISTYLE

Definition at line 57 of file lineterm.h.


Function Documentation

int lterm_close ( int  lterm)

Closes line terminal indexed by LTERM.

The default action is to block until active calls to lterm_write and lterm_read to complete. Called from the administrative/output thread of LTERM.

Returns:
0 on success, or -1 on error.

Closes line terminal indexed by LTERM.

Returns:
0 on success, or -1 on error.

Definition at line 749 of file ltermManager.c.

{
  struct lterms *lts;
  int returnCode;

  CHECK_IF_VALID_LTERM_NUMBER(lterm_close,lterm)

  LTERM_LOG(lterm_close,10,("Closing LTERM %d\n", lterm));

  GLOBAL_LOCK;

  lts = ltermGlobal.termList[lterm];

  if (lts == NULL) {
    /* Forgiving return for non-existent LTERM */
    GLOBAL_UNLOCK;
    return 0;
  }

  if (!lts->opened) {
    LTERM_WARNING("lterm_close: Error - LTERM %d not opened\n", lterm);
    GLOBAL_UNLOCK;
    return -1;
  }

  SWITCH_GLOBAL_TO_UNILOCK(lterm_close,adminMutex,adminMutexLocked)

  returnCode = ltermClose(lts);

  RELEASE_UNILOCK(adminMutex,adminMutexLocked)

  return returnCode;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Closes all LTERMs, but does not delete them.

This may be used to free any resources associated with LTERMs for clean up. The closed LTERMs should still be deleted, if possible.

Definition at line 832 of file ltermManager.c.

{
  int lterm;
  struct lterms *lts;

  LTERM_LOG(lterm_close_all,10,("\n"));

  GLOBAL_LOCK;

  for (lterm=0; lterm < MAXTERM; lterm++) {
    lts = ltermGlobal.termList[lterm];

    if ((lts != NULL) && lts->opened) {
      /* Opened LTERM; close it, disregarding return code */
      lts->adminMutexLocked = 1;
      MUTEX_LOCK(lts->adminMutex);

      /* NOTE,10, ("lterm_close_all:\n"******** This call is being made from within a global lock;
       *                POTENTIAL FOR DEADLOCK?
       */
      ltermClose(lts);

      lts->adminMutexLocked = 0;
      MUTEX_UNLOCK(lts->adminMutex);
    }
  }

  GLOBAL_UNLOCK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int lterm_delete ( int  lterm)

Deletes an LTERM object, closing it if necessary.

Returns:
0 on success, or -1 on error.

Deletes an LTERM object, closing it if necessary.

Returns:
0 on success, or -1 on error.

Definition at line 788 of file ltermManager.c.

{
  struct lterms *lts;
  int returnCode;

  CHECK_IF_VALID_LTERM_NUMBER(lterm_delete,lterm)

  LTERM_LOG(lterm_delete,10,("Closing LTERM %d\n", lterm));

  GLOBAL_LOCK;

  lts = ltermGlobal.termList[lterm];

  if (lts == NULL) {
    /* Forgiving return for non-existent LTERM */
    GLOBAL_UNLOCK;
    return 0;
  }

  /* Remove LTERM structure from list */
  ltermGlobal.termList[lterm] = NULL;

  SWITCH_GLOBAL_TO_UNILOCK(lterm_open,adminMutex,adminMutexLocked)

  returnCode = 0;
  if (lts->opened) {
    /* Opened LTERM; close it */
    returnCode = ltermClose(lts);
  }

  RELEASE_UNILOCK(adminMutex,adminMutexLocked)

  MUTEX_DESTROY(lts->adminMutex);

  /* Free memory for LTERMS structure */
  FREE(lts);

  LTERM_LOG(lterm_delete,11,("LTERM deleted\n"));

  return returnCode;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int lterm_init ( int  messageLevel)

Initializes all LTERM operations; needs to be called before any calls to lterm_new.

Returns:
0 on success, or -1 on error.

MESSAGELEVEL specifies the diagnostic message display level: 0 => (normal) only fatal errors cause diagnostic messages to be printed. -1 => (silent) no diagnostic messages are printed, even for fatal errors. 1 => (warning) print non-fatal warning messages as well as error messages. >9 and <= 99 (debugging) print debugging messages at selected procedure levels/sublevels (See tracelog.h for more information on messageLevel)

Returns 0 on successful initialization, -1 otherwise.

Initializes all LTERM operations; needs to be called before any calls to lterm_new.

Returns:
0 on success, or -1 on error.

Definition at line 95 of file ltermManager.c.

{
  if (!ltermGlobal.initialized) {
    int result, j;
    /* Assert that INTs have at least 32-bit precision.
     * This assumption underlies the choice of various bit codes.
     */
    assert(sizeof(int) >= 4);

    if (sizeof(UNICHAR) == 2) {
      /* Assert that the maximum column count fits into an UNICHAR.
       * This assumption is used for input buffer pipe I/O by lterm_write
       * and ltermWrite, but could be relaxed by using different buffer record
       * structure.
       */
      assert(MAXCOL <= 0x7FFF);
    }

    /* Initialize lock for accessing LTERMs array */
    if (MUTEX_INITIALIZE(ltermGlobal.listMutex) != 0)
      return -1;

    /* Initialize trace/log module for STDERR;
     * this could perhaps be eliminated, if TLOG_PRINT is redefined to PR_LOG
     * and so on, with the USE_NSPR_IO option enabled.
     */
    tlog_init(stderr);
    result = tlog_set_level(LTERM_TLOG_MODULE, messageLevel, NULL);

    /* Meta input delimiter */
    ltermGlobal.metaDelimiter = U_COLON;

    /* String of five ASCII characters escaped in XML;
     * only the first four characters are escaped in HTML;
     * it is sufficient to escape just the first three characters, "&<>"
     * when inserting plain text (outside markup) in XML/HTML fragments
     */
    ltermGlobal.escapeChars[LTERM_AMP_ESCAPE]  = '&';
    ltermGlobal.escapeChars[LTERM_LT_ESCAPE]   = '<';
    ltermGlobal.escapeChars[LTERM_GT_ESCAPE]   = '>';
    ltermGlobal.escapeChars[LTERM_QUOT_ESCAPE] = '\"';
    ltermGlobal.escapeChars[LTERM_APOS_ESCAPE] = '\'';
    ltermGlobal.escapeChars[LTERM_XML_ESCAPES] = 0;

    /* List of XML character escape sequences (Unicode) */
    ucscopy(ltermGlobal.escapeSeq[LTERM_AMP_ESCAPE],  "&amp;",
              LTERM_MAXCHAR_ESCAPE+1);
    ucscopy(ltermGlobal.escapeSeq[LTERM_LT_ESCAPE],   "&lt;",
              LTERM_MAXCHAR_ESCAPE+1);
    ucscopy(ltermGlobal.escapeSeq[LTERM_GT_ESCAPE],   "&gt;",
              LTERM_MAXCHAR_ESCAPE+1);
    ucscopy(ltermGlobal.escapeSeq[LTERM_QUOT_ESCAPE], "&quot;",
              LTERM_MAXCHAR_ESCAPE+1);
    ucscopy(ltermGlobal.escapeSeq[LTERM_APOS_ESCAPE], "&apos;",
              LTERM_MAXCHAR_ESCAPE+1);

    /* Escape sequence lengths (including delimiters) */
    for (j=0; j<LTERM_XML_ESCAPES; j++) {
      ltermGlobal.escapeLen[j] = ucslen(ltermGlobal.escapeSeq[j]);
      assert(ltermGlobal.escapeLen[j] <= LTERM_MAXCHAR_ESCAPE);
    }

    /* LTERM global initialization flag */
    ltermGlobal.initialized = 1;

  } else {
    LTERM_WARNING("lterm_init: Warning - already initialized\n");
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int lterm_metacomplete ( int  lterm,
const UNICHAR buf,
int  count 
)

Completes meta input in line terminal indexed by LTERM with the supplied to Unicode string in BUF of length COUNT.

Called from the output thread of the LTERM.

Returns:
0 on success, or -1 on error.

Creates a new LTERM object and returns its descriptor index but does not open it for I/O (documented in the LTERM interface)

Returns:
lterm descriptor index (>= 0) on success, or -1 on error

Definition at line 174 of file ltermManager.c.

{
  int lterm;
  struct lterms *lts;

  if (!ltermGlobal.initialized) {
    LTERM_ERROR("lterm_new: Error - call lterm_init() to initialize LTERM library\n");
    return -1;
  }

  LTERM_LOG(lterm_new,10,("Creating LTERM ...\n"));

  /* Allocate memory for new LTERMS structure: needs clean-up */
  lts = (struct lterms *) MALLOC(sizeof(struct lterms));

  if (lts == NULL) {
    LTERM_ERROR("lterm_new: Error - failed to allocate memory for LTERM\n");
    return -1;
  }

  GLOBAL_LOCK;

  for (lterm=0; lterm < MAXTERM; lterm++) {
    if (ltermGlobal.termList[lterm] == NULL)
      break;
  }

  if (lterm == MAXTERM) {
    LTERM_ERROR( "lterm_new: Error - too many LTERMS; recompile with increased MAXTERM\n");
    FREE(lts);  /* Clean up memory allocation for LTERMS structure */
    GLOBAL_UNLOCK;
    return -1;
  }
  
  /* Insert LTERM pointer in list of LTERMs */
  ltermGlobal.termList[lterm] = lts;

  MUTEX_INITIALIZE(lts->adminMutex);

  /* Administrative thread inactive */
  lts->adminMutexLocked = 0;

  /* LTERM not yet opened for I/O */
  lts->opened = 0;

  GLOBAL_UNLOCK;

  LTERM_LOG(lterm_new,11,("created lterm = %d\n", lterm));

  return lterm;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int lterm_open ( int  lterm,
char *const  argv[],
const char *  cookie,
const char *  init_command,
const UNICHAR prompt_regexp,
int  options,
int  process_type,
int  rows,
int  cols,
int  x_pixels,
int  y_pixels,
lterm_callback_func_t  callback_func,
void callback_data 
)

Opens line terminal indexed by LTERM for input/output and creates a process attached to it to execute the command line contained in string array ARGV.

Called from the adminstrative/output thread of LTERM.

Returns:
0 on success, or -1 on error.

COOKIE contains a cookie string used for stream security. If it is null, or a null string, all streams are considered insecure. (only MAXCOOKIESTR-1 characters of the cookie string are used for checking)

INIT_COMMAND contains an initialization command string, if any (not echoed)

PROMPT_REGEXP contains a REGEXP string describing the command prompt. (NOTE For the moment, only a list of prompt delimiters is accepted; a typical list of prompt delimiters would be "#$%>?")

OPTIONS is a bitmask controlling the following options: LTERM_NOCANONICAL_FLAG disable TTY canonical mode LTERM_NOEDIT_FLAG disable input line editing LTERM_NOCOMPLETION_FLAG disable command line completion LTERM_NOMETA_FLAG disable meta input LTERM_NOMARKUP_FLAG disable HTML/XML element processing in command line LTERM_NOECHO_FLAG disable TTY echo LTERM_NOPTY_FLAG do not use pseudo-TTY LTERM_NONUL_FLAG do not process any NUL characters (discard them) LTERM_NOLINEWRAP_FLAG disable line wrapping LTERM_NOEXPORT_FLAG disable export of current environment to new process LTERM_STDERR_FLAG enable use of separate STDERR LTERM_PARTLINE_FLAG enable returning of partial line output

Notes: -LTERM_STDERR_FLAG, although implemented, does not work properly at all -LTERM_PARTLINE_FLAG is not yet implemented

PROCESS_TYPE specifies the subordinate process type, if set to one of the following: LTERM_DETERMINE_PROCESS LTERM_UNKNOWN_PROCESS LTERM_SH_PROCESS LTERM_KSH_PROCESS LTERM_BASH_PROCESS LTERM_CSH_PROCESS LTERM_TCSH_PROCESS If it is set to LTERM_DETERMINE_PROCESS, the process type is determined from the path name.

ROWS, COLS contain the initial no. of rows/columns. X_PIXELS, Y_PIXELS contain the initial screen size in pixels (may be set to zero if screen size is unknown).

CALLBACK_FUNC is a pointer to a GTK-style callback function, or NULL for no callback. The function is called whenever there is data available for LTERM_READ to process, with CALLBACK_DATA as the data argument. The callback function should call LTERM_READ immediately; otherwise the callback function will be called repeatedly. (The type LTERM_CALLBACK_FUNC_T is defined at the top of this include file)

In canonical mode, no input line editing is permitted. In editing mode, EMACS-style keyboard line editing commands are allowed. In completion mode, incomplete command/file names are transmitted to the subordinate process for complettion, as in TCSH. Meta input refers to input lines that begin with a colon, or with a "protocol" name followed by a colon, such as "http: ...". Meta input lines are not sent to the subordinate process, but simply echoed as LTERM output through LTERM_READ for further processing. If command line completion is not disabled, incomplete meta input may also be echoed for completion. In this case, the completed meta input should be supplied to the LTERM through a call to LTERM_WRITE as if the user had entered it.

Opens line terminal indexed by LTERM for input/output and creates a process attached to it to execute the command line contained in string array ARGV.

Returns:
0 on success, or -1 on error

Definition at line 239 of file ltermManager.c.

{
  int nostderr, noPTY, j;
  struct ptys ptyStruc;
  struct lterms *lts;
  struct LtermInput *lti;
  struct LtermOutput *lto;
  struct LtermProcess *ltp;
  char *const *cargv;
  char *defaultArgs[3];

  if (!ltermGlobal.initialized) {
    LTERM_ERROR("lterm_open: Error - call lterm_init() to initialize LTERM library\n");
    return -1;
  }

  CHECK_IF_VALID_LTERM_NUMBER(lterm_open,lterm)

  LTERM_LOG(lterm_open,10,("Opening LTERM %d\n", lterm));

  GLOBAL_LOCK;

  lts = ltermGlobal.termList[lterm];

  if (lts == NULL) {
    LTERM_ERROR("lterm_open: Error - LTERM %d not created using lterm_new\n",
                lterm);
    GLOBAL_UNLOCK;
    return -1;
  }

  if (lts->opened) {
    LTERM_ERROR("lterm_open: Error - LTERM %d is already open\n",
                lterm);
    GLOBAL_UNLOCK;
    return -1;
  }

  SWITCH_GLOBAL_TO_UNILOCK(lterm_open,adminMutex,adminMutexLocked)

  /* Pointers to LTERM process/input/output structures */
  ltp = &(lts->ltermProcess);
  lti = &(lts->ltermInput);
  lto = &(lts->ltermOutput);

  /* Initialize flags/pointers/file descriptors that need to be cleaned up */
  lts->suspended = 0;
  lts->ptyMode   = 0;

  /* Initialize TTY control characters */
  assert(TTYWERASE < MAXTTYCONTROL);
  lts->control[TTYINTERRUPT] = U_CTL_C;
  lts->control[TTYERASE]     = U_DEL;
  lts->control[TTYKILL]      = U_CTL_U;
  lts->control[TTYEOF]       = U_CTL_D;
  lts->control[TTYSUSPEND]   = U_CTL_Z;
  lts->control[TTYREPRINT]   = U_CTL_R;
  lts->control[TTYDISCARD]   = U_CTL_O;
  lts->control[TTYWERASE]    = U_CTL_W;

  lts->writeBUFFER =  NULL_FILEDESC;
  lts->readBUFFER =   NULL_FILEDESC;

  /* Clear input line break flag */
  lts->inputLineBreak = 0;

  /* Clear input buffer */
  lti->inputBufBytes = 0;
  lts->inputBufRecord = 0;

  /* Clear styleMask */
  lto->styleMask = 0;

  /* Clear incomplete raw output buffers */
  lto->rawOUTBytes = 0;
  lto->rawERRBytes = 0;

  /* Clear decoded output buffer */
  lto->decodedChars = 0;
  lto->incompleteEscapeSequence = 0;

  /* Set initial screen size */
  lts->nRows = rows;
  lts->nCols = cols;
  lts->xPixels = y_pixels;
  lts->yPixels = x_pixels;

  /* Clear screen buffer */
  lto->screenChar  = NULL;
  lto->screenStyle = NULL;

  lts->outputMutexLocked = 0;

  MUTEX_INITIALIZE(lts->outputMutex);

  /* AT THIS POINT, LTERMCLOSE MAY BE CALLED FOR CLEAN-UP */

  /* Create input buffer pipe; needs clean-up */
  if (ltermCreatePipe(&(lts->writeBUFFER), &(lts->readBUFFER)) != 0) {
    LTERM_OPEN_ERROR_RETURN(lterm,lts,
                "lterm_open: Error - input buffer pipe creation failed\n")
  }

  LTERM_LOG(lterm_open,11,("Created input buffer pipe\n", lterm));

  defaultArgs[0] = NULL;
  defaultArgs[1] = "-i";
  defaultArgs[2] = NULL;

  if (argv != NULL) {
    /* Use supplied command arguments */
    cargv= argv;

  } else {
    /* Default command arguments */
    defaultArgs[0] = (char *) getenv("SHELL");
    if (defaultArgs[0] == NULL)
      defaultArgs[0] = "/bin/sh";
    cargv= defaultArgs;
  }

  if (process_type >= 0) {
    /* Specified process type code */
    lts->processType = process_type;

  } else {
    /* Determine process type code from path name */
    char *lastSlash;
    char *tailStr;

    /* Find the last occurrence of slash */
    lastSlash = (char *) strrchr(cargv[0], '/');
    if (lastSlash == NULL) {
      tailStr = cargv[0];
    } else {
      tailStr = lastSlash + 1;
    }

    if (strcmp(tailStr,"sh") == 0) {
      lts->processType = LTERM_SH_PROCESS;

    } else if (strcmp(tailStr,"ksh") == 0) {
      lts->processType = LTERM_KSH_PROCESS;

    } else if (strcmp(tailStr,"bash") == 0) {
      lts->processType = LTERM_BASH_PROCESS;

    } else if (strcmp(tailStr,"csh") == 0) {
      lts->processType = LTERM_CSH_PROCESS;

    } else if (strcmp(tailStr,"tcsh") == 0) {
      lts->processType = LTERM_TCSH_PROCESS;

    } else {
      lts->processType = LTERM_UNKNOWN_PROCESS;
    }
  }

  LTERM_LOG(lterm_open,11,("process type code = %d\n", lts->processType));

  /* TTY options */
  lts->options = options;
  lts->noTTYEcho = (options & LTERM_NOECHO_FLAG) != 0;
  lts->disabledInputEcho = 1;
  lts->restoreInputEcho = 1;

  nostderr = (options & LTERM_STDERR_FLAG) == 0;

#if defined(NO_PTY) || defined(USE_NSPR_IO)
  /* Current implementation of pseudo-TTY is incompatible with the NSPR I/O
     option; set the USE_NSPR_IO option only on platforms where
     PTYSTREAM is not implemented.
     Reason for incompatibility: cannot combine the UNIX-style integral
     PTY file descriptor and NSPR's PRFileDesc in the same poll function
     call.
  */
  noPTY = 1;
#else
  noPTY = (options & LTERM_NOPTY_FLAG);
#endif

  if (noPTY) {
    /* Create pipe process: needs clean-up */
    if (ltermCreateProcess(ltp, cargv, nostderr, 0) == -1) {

      LTERM_OPEN_ERROR_RETURN(lterm,lts,
            "lterm_open: Pipe process creation failed\n")
    }

  } else {
    /* Create pseudo-TTY with blocking I/O: needs clean-up */
    int noblock = 1;
    int noexport = 0;
    int debugPTY = (tlogGlobal.messageLevel[LTERM_TLOG_MODULE] > 1);
    int errfd = nostderr?-1:-2;

    LTERM_LOG(lterm_open,11,
              ("errfd=%d, noecho=%d, noblock=%d, noexport=%d, debugPTY=%d\n",
               errfd, lts->noTTYEcho, noblock, noexport, debugPTY));
#ifndef NO_PTY
    if (pty_create(&ptyStruc, cargv,
                   lts->nRows, lts->nCols, lts->xPixels, lts->yPixels,
                   errfd, noblock, lts->noTTYEcho, noexport, debugPTY) == -1) {
      LTERM_OPEN_ERROR_RETURN(lterm,lts,
            "lterm_open: Error - PTY creation failed\n")
    }
#endif  /* !NO_PTY */

    /* Copy PTY structure */
    lts->pty = ptyStruc;
    lts->ptyMode = 1;
  }

  /* Set up LtermOutput polling structure */
  lto->pollFD[POLL_INPUTBUF].fd = lts->readBUFFER;
  lto->pollFD[POLL_INPUTBUF].POLL_EVENTS = POLL_READ;

  if (lts->ptyMode) {
#ifndef USE_NSPR_IO
    lto->pollFD[POLL_STDOUT].fd = lts->pty.ptyFD;
    lto->pollFD[POLL_STDOUT].POLL_EVENTS = POLL_READ;

    if (VALID_FILEDESC(lts->pty.errpipeFD)) {
      lto->pollFD[POLL_STDERR].fd = lts->pty.errpipeFD;
      lto->pollFD[POLL_STDERR].POLL_EVENTS = POLL_READ;
      lto->nfds = POLL_COUNT;
    } else {
        lto->nfds = POLL_COUNT-1;
    }
#else
    /* Current implementation of pseudo-TTY incompatible with USE_NSPR_IO */
    LTERM_OPEN_ERROR_RETURN(lterm,lts,
           "lterm_open: Error - pseudo-TTY incompatible with USE_NSPR_IO\n")
#endif

  } else {
    lto->pollFD[POLL_STDOUT].fd = ltp->processOUT;
    lto->pollFD[POLL_STDOUT].POLL_EVENTS = POLL_READ;

    if (VALID_FILEDESC(ltp->processERR)) {
      lto->pollFD[POLL_STDERR].fd = ltp->processERR;
      lto->pollFD[POLL_STDERR].POLL_EVENTS = POLL_READ;
      lto->nfds = POLL_COUNT;
    } else {
      lto->nfds = POLL_COUNT-1;
    }
  }

  /* No callbacks initially associated with this LTERM */
  for (j=0; j<lto->nfds; j++)
    lto->callbackTag[j] = 0;

  /* Determine whether STDERR should be read before STDOUT */
  if (lts->processType == LTERM_TCSH_PROCESS) {
    lts->readERRfirst = 0;
  } else {
    lts->readERRfirst = 1;
  }

  /* Determine whether STDERR and STDOUT should be interleaved */
  lts->interleave = 1;

  /* Determine maximum value for input mode */
  if (options & LTERM_NOCANONICAL_FLAG)
    lts->maxInputMode = LTERM0_RAW_MODE;

  else if (options & LTERM_NOEDIT_FLAG)
    lts->maxInputMode = LTERM1_CANONICAL_MODE;

  else if ((options & LTERM_NOCOMPLETION_FLAG) ||
           lts->noTTYEcho)
    lts->maxInputMode = LTERM2_EDIT_MODE;

  else {
    if ((lts->processType == LTERM_BASH_PROCESS) ||
        (lts->processType == LTERM_TCSH_PROCESS))
      lts->maxInputMode = LTERM3_COMPLETION_MODE;
    else
      lts->maxInputMode = LTERM2_EDIT_MODE;
  }

  LTERM_LOG(lterm_open,11,("options=0x%x, processType=%d, readERRfirst=%d, maxInputMode=%d\n",
                lts->options, lts->processType, lts->readERRfirst, lts->maxInputMode));
  LTERM_LOGUNICODE(lterm_open,11,(prompt_regexp, (int) ucslen(prompt_regexp) ));

  if (cookie != NULL) {
    /* Copy cookie string (no more than MAXCOOKIESTR-1 characters) */
    if (strlen(cookie) > MAXCOOKIESTR-1) {
      LTERM_WARNING("lterm_open: Warning - cookie string truncated\n");
    }
    strncpy(lts->cookie, cookie, MAXCOOKIESTR-1);
    lts->cookie[MAXCOOKIESTR-1] = '\0';
  } else {
    /* No cookie */
    lts->cookie[0] = '\0';
  }

  LTERM_LOG(lterm_open,11,("cookie='%s'\n",lts->cookie));

  /* Shell initialization commands have not been sent yet */
  lts->shellInitCommands = 0;

  /* NOTE: Shell init commands are stored in reverse order of execution */

  if (init_command != NULL) {
    /* User supplied shell init command */

    if (strlen(init_command) <= MAXSHELLINITSTR-1) {
      int cmd = lts->shellInitCommands++;
      assert(cmd < MAXSHELLINITCMD);

      (void) strncpy(lts->shellInitStr[cmd], init_command, MAXSHELLINITSTR-1);
      lts->shellInitStr[cmd][MAXSHELLINITSTR-1] = '\0';

    } else {
      LTERM_WARNING("lterm_open: Warning - user init command too long\n");
    }
  }

  if (lts->processType != LTERM_UNKNOWN_PROCESS) {
    /* Process dependent shell init command */
    int result;
    char* shellInitFormat;

    if ((lts->processType == LTERM_CSH_PROCESS) ||
      (lts->processType == LTERM_TCSH_PROCESS)) {
      /* C-shell family */
      shellInitFormat = "setenv LTERM_COOKIE '%s'\n";

    } else {
      /* Bourne-shell family */
      shellInitFormat = "LTERM_COOKIE='%s'; export LTERM_COOKIE\n";
    }

    /* **** WATCH OUT FOR BUFFER OVERFLOW!!! *** */
    if (strlen(shellInitFormat)-4+strlen(lts->cookie) <= MAXSHELLINITSTR-1) {

      int cmd = lts->shellInitCommands++;
      assert(cmd < MAXSHELLINITCMD);

      sprintf(lts->shellInitStr[cmd], shellInitFormat, lts->cookie);
      lts->shellInitStr[cmd][MAXSHELLINITSTR-1] = '\0';

    } else {
      LTERM_WARNING("lterm_open: Warning - process init command too long\n");
    }
  }

  for (j=lts->shellInitCommands-1; j>0; j--) {
    LTERM_LOG(lterm_open,11,("shellInitStr%d='%s'\n",j,lts->shellInitStr[j]));
  }

  /* Initialize regular expression string matching command prompt */
  if ((ucslen(prompt_regexp) == 0) ||
      (ucslen(prompt_regexp) > MAXPROMPT-1)) {
    LTERM_OPEN_ERROR_RETURN(lterm,lts,
         "lterm_open: Error - prompt_regexp string too short/long\n")
  }

  ucsncpy( lts->promptRegexp, prompt_regexp, MAXPROMPT);

  /* Command number counter */
  lts->lastCommandNum = 0;

  /* Command completion request code */
  lts->completionRequest = LTERM_NO_COMPLETION;

  /* Clear output line buffer and switch to line output mode */
  ltermClearOutputLine(lts);
  lto->outputMode = LTERM2_LINE_MODE;
  lto->styleMask = 0;

  /* Reset terminal modes */
  lto->insertMode = 0;
  lto->automaticNewline = 0;

  /* Clear input line buffer */
  ltermClearInputLine(lts);

  /* Clear input line flag not yet set */
  lti->clearInputLine = 0;

  /* Reset input opcodes */
  lti->inputOpcodes = 0;

  /* Open LTERM */
  lts->opened = 1;

  /* Initialize any callbacks associated with this LTERM */
  if (callback_func != NULL) {
#if !defined(USE_NSPR_IO) && defined(USE_GTK_WIDGETS)
    LTERM_LOG(lterm_open,11,("Initializing %d callbacks for LTERM %d\n",
                               lto->nfds, lterm));

    for (j=0; j<lto->nfds; j++) {
      lto->callbackTag[j] = gdk_input_add(lto->pollFD[j].fd,
                                          GDK_INPUT_READ,
                                          callback_func,
                                          (gpointer) callback_data);
      if (lto->callbackTag[j] == 0) {
        LTERM_OPEN_ERROR_RETURN(lterm,lts,
                    "lterm_open: Error - unable to add callback\n")
      }
    }
#else
    LTERM_OPEN_ERROR_RETURN(lterm,lts,
      "lterm_open: Error - callbacks not implemented for this configuration\n")
#endif
  }


  RELEASE_UNILOCK(adminMutex,adminMutexLocked)

  LTERM_LOG(lterm_open,11,
      ("outputMode=%d, inputMode=%d, maxInputMode=%d\n",
      lto->outputMode, lti->inputMode,lts->maxInputMode ));

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int lterm_read ( int  lterm,
int  timeout,
UNICHAR buf,
int  count,
UNISTYLE style,
int opcodes,
int opvals,
int buf_row,
int buf_col,
int cursor_row,
int cursor_col 
)

reads upto COUNT Unicode characters from a single line of output from line terminal indexed by LTERM into BUF.

Called from the output thread of the LTERM. Returns the number of characters read (>=0) on a successful read. Returns -1 if an error occurred while reading, -2 if pseudo-TTY has been closed, -3 if more than COUNT characters are present in the line (in this case the first COUNT characters are returned in BUF, and the rest are discarded). If the return value is -1, any further operations on the LTERM, other than LTERM_CLOSE, will always fail with an error return value. (If return value is -2, it means that the subordinate process has closed the pseudo-TTY. In this case, the LTERM still needs to be explicitly closed by calling LTERM_CLOSE for proper clean-up.)

TIMEOUT is the number of platform-dependent time units (usually milliseconds on Unix) to wait to read data. A zero value implies no waiting. A negative TIMEOUT value implies infinite timeout, i.e., a blocking read. Non-zero values of TIMEOUT should be used only when the output thread is allowed to block.

STYLE should be an array of same length as BUF, and contains the style bits associated with each character on return (see below).

OPCODES contains a bit mask describing the type of output (see below). Using Extended Backus-Naur Form notation:

OPCODES ::= STREAMDATA NEWLINE? ERROR? COOKIESTR? DOCSTREAM? XMLSTREAM? JSSTREAM? WINSTREAM? if StreamMode data is being returned. (NEWLINE, if set, denotes that the stream has terminated; if ERROR is also set, it means that the stream has terminated abnormally.)

OPCODES ::= SCREENDATA BELL? ( OUTPUT | CLEAR | INSERT | DELETE | SCROLL )? if ScreenMode data is being returned. If none of the flags OUTPUT ... SCROLL are set in screen mode, do nothing but position the cursor (and ring the bell, if need be).

OPCODES ::= LINEDATA BELL? ( CLEAR | ( PROMPT | OUTPUT)? INPUT ( NEWLINE HIDE? )? | PROMPT? INPUT META ( COMPLETION | NEWLINE HIDE? ) | PROMPT? OUTPUT NEWLINE? ) if LineMode data is being returned.

If OPCODES == 0, then it means that no data has been read.

If the returned OPCODES has META and COMPLETION bits set, then the completed version of the meta input should be supplied through a call to LTERM_WRITE, with an input data type, as if the user had typed it.

BUF_ROW and BUF_COL denote the row and starting column at which to display the data in BUF. (BUF_ROW and BUF_COL are not used for CLEAR option in screen/line mode) In ScreenMode or LineMode, CURSOR_ROW and CURSOR_COL denote the final cursor position after any data in BUF is displayed.

The bottom left corner of the screen corresponds to row 0, column 0. BUF_COL, CURSOR_COL are always >= 0, with 0 denoting the leftmost column. (BUF_COL is always zero if NOPARTLINE flag is set for LTERM.) (CURRENT IMPLEMENTATION: BUF_COL is always zero.) BUF_ROW, CURSOR_ROW are always set to -1 when LTERM is in line mode, BUF_ROW, CURSOR_ROW are always >=0 when LTERM is in screen mode, with 0 denoting the bottom row.

In ScreenMode:

  • OUTPUT denotes that a modifed row of data is being returned.
  • OPVALS contains the no. of lines to be inserted/deleted, for INSERT/DELETE/SCROLL operations

Definition at line 1126 of file ltermManager.c.

{
  struct lterms *lts;
  int returnCode, temCode;
  struct LtermRead ltrStruc;

  CHECK_IF_VALID_LTERM_NUMBER(lterm_read,lterm)

  LTERM_LOG(lterm_read,10,("Reading from LTERM %d\n", lterm));

  GLOBAL_LOCK;

  lts = ltermGlobal.termList[lterm];

  if (lts == NULL || !lts->opened || lts->suspended) {
    /* LTERM is deleted/closed/suspended */
    if (lts == NULL)
      LTERM_WARNING("lterm_read: Warning - LTERM %d not active\n", lterm);

    *opcodes = 0;
    *opvals = 0;
    *buf_row = 0;
    *buf_col = 0;
    *cursor_row = 0;
    *cursor_col = 0;

    GLOBAL_UNLOCK;
    return -2;
  }

  SWITCH_GLOBAL_TO_UNILOCK(lterm_read,outputMutex,outputMutexLocked)

  /* Copy "input" parameters to LtermRead structure */
  ltrStruc.buf = buf;
  ltrStruc.style = style;
  ltrStruc.max_count = count;

  /* Call auxiliary function to read data */
  temCode = ltermRead(lts, &ltrStruc, timeout);

  if (temCode == 0) {
    /* Return count of characters read */
    returnCode = ltrStruc.read_count;
  } else {
    /* Error return */
    returnCode = temCode;
  }

  /* Copy "output" parameters from LtermRead structure */
  *opcodes = ltrStruc.opcodes;
  *opvals = ltrStruc.opvals;
  *buf_row = ltrStruc.buf_row;
  *buf_col = ltrStruc.buf_col;
  *cursor_row = ltrStruc.cursor_row;
  *cursor_col = ltrStruc.cursor_col;

  if (returnCode == -1) {
    /* Error return code; suspend TTY */
    LTERM_WARNING("lterm_read: Warning - LTERM %d suspended due to error\n", lterm);
    lts->suspended = 1;
  }

  RELEASE_UNILOCK(outputMutex,outputMutexLocked)

  GLOBAL_LOCK;
  if ((*opcodes != 0) && (lts->shellInitCommands > 0)) {
    /* send shell initialization string */
    if (ltermShellInit(lts,0) != 0) {
      GLOBAL_UNLOCK;
      return -1;
    }
  }
  GLOBAL_UNLOCK;

  LTERM_LOG(lterm_read,11,("return code = %d, opcodes=0x%x, opvals=%d\n",
                           returnCode, *opcodes, *opvals));

  return returnCode;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int lterm_resize ( int  lterm,
int  rows,
int  cols 
)

Resizes the line terminal indexed by LTERM to new row/column count.

Called from the output thread of LTERM.

Returns:
0 on success, or -1 on error.

Definition at line 906 of file ltermManager.c.

{
  struct lterms *lts;
  struct LtermOutput *lto;

  CHECK_IF_VALID_LTERM_NUMBER(lterm_resize,lterm)

  LTERM_LOG(lterm_resize,10,("Resizing LTERM=%d, rows=%d, cols=%d\n",
                             lterm, rows, cols));

  if ((rows <= 0)  || (cols <= 0))
    return -1;

  GLOBAL_LOCK;

  lts = ltermGlobal.termList[lterm];

  if (lts == NULL || !lts->opened || lts->suspended) {
    /* LTERM is deleted/closed/suspended */
    if (lts == NULL)
      LTERM_WARNING("lterm_resize: Warning - LTERM %d not active\n", lterm);
    GLOBAL_UNLOCK;
    return -2;
  }

  if ((rows == lts->nRows) && (cols == lts->nCols)) {
    /* Nothing to do */
    GLOBAL_UNLOCK;
    return 0;
  }

  lto = &(lts->ltermOutput);

  LTERM_LOG(lterm_resize,12,("lto->outputMode=%d\n",
                             lto->outputMode));

  /* Free full screen buffers */
  if (lto->screenChar != NULL)
    FREE(lto->screenChar);

  if (lto->screenStyle != NULL)
    FREE(lto->screenStyle);

  lto->screenChar  = NULL;
  lto->screenStyle = NULL;

  /* Resize screen */
  lts->nRows = rows;
  lts->nCols = cols;

  if (lto->outputMode == LTERM1_SCREEN_MODE) {
    /* Clear screen */
    if (ltermClearOutputScreen(lts) != 0)
      return -1;
  }

  if (lts->ptyMode) {
    /* Resize PTY */
#ifndef NO_PTY
    if (pty_resize(&(lts->pty), lts->nRows, lts->nCols, 0, 0) != 0) {
      GLOBAL_UNLOCK;
      return -1;
    }
#endif  /* !NO_PTY */
  }

  GLOBAL_UNLOCK;

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int lterm_setcursor ( int  lterm,
int  row,
int  col 
)

Sets cursor position in line terminal indexed by LTERM.

NOT YET IMPLEMENTED Row numbers increase upward, starting from 0. Column numbers increase rightward, starting from 0. Called from the output thread of LTERM.

Returns:
0 on success, or -1 on error.

Definition at line 986 of file ltermManager.c.

{
  struct lterms *lts;

  CHECK_IF_VALID_LTERM_NUMBER(lterm_setcursor,lterm)

  LTERM_LOG(lterm_setcursor,10,
            ("Setting cursor, LTERM=%d row=%d, col=%d (NOT YET IMPLEMENTED)\n",
             lterm, row, col));

  GLOBAL_LOCK;

  lts = ltermGlobal.termList[lterm];

  if (lts == NULL || !lts->opened || lts->suspended) {
    /* LTERM is deleted/closed/suspended */
    if (lts == NULL)
      LTERM_WARNING("lterm_setcursor: Warning - LTERM %d not active\n", lterm);
    GLOBAL_UNLOCK;
    return -2;
  }

  GLOBAL_UNLOCK;

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int lterm_setecho ( int  lterm,
int  echo_flag 
)

Set input echo flag for line terminal indexed by LTERM.

Called from the output thread of LTERM.

Returns:
0 on success, or -1 on error.

Definition at line 864 of file ltermManager.c.

{
  struct lterms *lts;

  CHECK_IF_VALID_LTERM_NUMBER(lterm_setecho,lterm)

  LTERM_LOG(lterm_setecho,10,("LTERM=%d, echo_flag=%d\n", lterm, echo_flag));

  GLOBAL_LOCK;

  lts = ltermGlobal.termList[lterm];

  if (lts == NULL || !lts->opened || lts->suspended) {
    /* LTERM is deleted/closed/suspended */
    if (lts == NULL)
      LTERM_WARNING("lterm_setecho: Warning - LTERM %d not active\n", lterm);
    GLOBAL_UNLOCK;
    return -2;
  }

  if (lts->shellInitCommands > 0) {
    /* send shell initialization string */
    if (ltermShellInit(lts,1) != 0) {
      GLOBAL_UNLOCK;
      return -1;
    }
  }

  lts->disabledInputEcho = !echo_flag;
  lts->restoreInputEcho = 0;

  GLOBAL_UNLOCK;

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int lterm_write ( int  lterm,
const UNICHAR buf,
int  count,
int  dataType 
)

Writes supplied to Unicode string in BUF of length COUNT to line terminal indexed by LTERM.

(May be called from any thread, since it uses a pipe to communicate with the output thread.) DATATYPE may be set to one of the following values: LTERM_WRITE_PLAIN_INPUT Plain text user input LTERM_WRITE_XML_INPUT XML element user input LTERM_WRITE_PLAIN_OUTPUT Plain text server output LTERM_WRITE_CLOSE_MESSAGE End of file message NOTE: This is a non-blocking call Returns the number of characters written. Returns -1 on error, and -2 if pseudo-TTY has been closed. If the return value is less than COUNT, it usually indicates an error. If the return value is -1, any further operations on the LTERM, other than LTERM_CLOSE, will always fail with an error return value.

Definition at line 1015 of file ltermManager.c.

{
  struct lterms *lts;
  FILEDESC writeBUFFER;
  int byteCount, sentCount, packetCount, j;
  UNICHAR temLine[PIPEHEADER+MAXCOL], uch;

  CHECK_IF_VALID_LTERM_NUMBER(lterm_write,lterm)

  LTERM_LOG(lterm_write,10,("Writing to LTERM %d\n", lterm));

  GLOBAL_LOCK;

  lts = ltermGlobal.termList[lterm];

  if (lts == NULL || !lts->opened || lts->suspended) {
    /* LTERM is deleted/closed/suspended */
    if (lts == NULL)
      LTERM_WARNING("lterm_write: Warning - LTERM %d not active\n", lterm);
    GLOBAL_UNLOCK;
    return -2;
  }

  assert(VALID_FILEDESC(lts->writeBUFFER));

  /* Save copy of input buffer file descriptor */
  writeBUFFER = lts->writeBUFFER;

  if (lts->restoreInputEcho == 1) {
    /* Restore TTY echo on input */
    lts->restoreInputEcho = 0;
    lts->disabledInputEcho = 0;
  }

  if (lts->shellInitCommands > 0) {
    /* send shell initialization string */
    if (ltermShellInit(lts,1) != 0) {
      GLOBAL_UNLOCK;
      return -1;
    }
  }

  GLOBAL_UNLOCK;

  assert(count >= 0);

  sentCount = 0;
  while (sentCount < count) {
    packetCount = count - sentCount;  /* always > 0 */

    if (packetCount > MAXCOLM1)
      packetCount = MAXCOLM1;

    if ( (dataType == LTERM_WRITE_PLAIN_INPUT) ||
         (dataType == LTERM_WRITE_PLAIN_OUTPUT) ) {
      /* Plain text data; break at control characters,
       * but break at ESCape character only if not the first character;
       * this ensures that escape sequences fit into one record
       */

      for (j=0; j<packetCount; j++) {
        uch = buf[j+sentCount];
        temLine[j+PIPEHEADER] = uch;

        if ((uch < (UNICHAR)U_SPACE) &&
            ((uch != (UNICHAR)U_ESCAPE) || (j > 0)))
          break;
      }

      if (j<packetCount)
        packetCount = j+1;

      if ( (packetCount > 1) &&
           (temLine[PIPEHEADER+packetCount-1] == U_ESCAPE) ) {
        /* Save any terminal ESCape character for next packet, unless alone */
        packetCount--;
      }

    } else {
      /* XML element data (must represent complete element) */
      for (j=0; j<packetCount; j++)
        temLine[j+PIPEHEADER] = buf[j+sentCount];
    }

    byteCount = (PIPEHEADER+packetCount)*sizeof(UNICHAR);

    /* Header contains packet character count and data type */
    temLine[0]         = (UNICHAR) packetCount;
    temLine[PHDR_TYPE] = (UNICHAR) dataType;

    LTERM_LOGUNICODE(lterm_write,12,(&temLine[PIPEHEADER], packetCount));

    if (WRITE(lts->writeBUFFER,temLine,(SIZE_T)byteCount) != byteCount) {
      LTERM_ERROR("lterm_write: Error in writing to input pipe buffer\n");
      return -1;
    }

    LTERM_LOG(lterm_write,11,
              ("wrote %d characters of type %d data to input buffer pipe\n",
               packetCount, dataType));

    sentCount += packetCount;
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function: