зеркало из https://github.com/mozilla/pjs.git
xmlterm changes only;
Removed all wchar dependence by recoding the primitive Unicode string functions used by lineterm. (FreeBSD doesn't have a wchar implementation!)
This commit is contained in:
Родитель
bd79d0b0ac
Коммит
623cda76fb
|
@ -68,8 +68,8 @@ DIRS = base tests linetest
|
||||||
|
|
||||||
else # not STAND_ALONE
|
else # not STAND_ALONE
|
||||||
|
|
||||||
# XMLterm currently works on Linux and SunOS only
|
# XMLterm currently works on Linux and SunOS only (testing on BSD family)
|
||||||
ifneq (,$(filter Linux SunOS,$(OS_ARCH)))
|
ifneq (,$(filter Linux SunOS BSD,$(OS_ARCH)))
|
||||||
DIRS = base ui scripts doc tests
|
DIRS = base ui scripts doc tests
|
||||||
else # XMLterm not yet been ported to this platform; do nothing
|
else # XMLterm not yet been ported to this platform; do nothing
|
||||||
DIRS =
|
DIRS =
|
||||||
|
|
|
@ -39,9 +39,7 @@
|
||||||
|
|
||||||
#define _LINETERM_H 1
|
#define _LINETERM_H 1
|
||||||
|
|
||||||
#ifndef _UNISTRING_H
|
|
||||||
#include "unistring.h"
|
#include "unistring.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define LTERM read callback function type */
|
/* Define LTERM read callback function type */
|
||||||
#ifdef USE_GTK_WIDGETS
|
#ifdef USE_GTK_WIDGETS
|
||||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -133,15 +133,22 @@ int lterm_init(int messageLevel)
|
||||||
ltermGlobal.escapeChars[LTERM_XML_ESCAPES] = 0;
|
ltermGlobal.escapeChars[LTERM_XML_ESCAPES] = 0;
|
||||||
|
|
||||||
/* List of XML character escape sequences (Unicode) */
|
/* List of XML character escape sequences (Unicode) */
|
||||||
ltermGlobal.escapeSeq[LTERM_AMP_ESCAPE] = L"&";
|
ucscopy(ltermGlobal.escapeSeq[LTERM_AMP_ESCAPE], "&",
|
||||||
ltermGlobal.escapeSeq[LTERM_LT_ESCAPE] = L"<";
|
LTERM_MAXCHAR_ESCAPE+1);
|
||||||
ltermGlobal.escapeSeq[LTERM_GT_ESCAPE] = L">";
|
ucscopy(ltermGlobal.escapeSeq[LTERM_LT_ESCAPE], "<",
|
||||||
ltermGlobal.escapeSeq[LTERM_QUOT_ESCAPE] = L""";
|
LTERM_MAXCHAR_ESCAPE+1);
|
||||||
ltermGlobal.escapeSeq[LTERM_APOS_ESCAPE] = L"'";
|
ucscopy(ltermGlobal.escapeSeq[LTERM_GT_ESCAPE], ">",
|
||||||
|
LTERM_MAXCHAR_ESCAPE+1);
|
||||||
|
ucscopy(ltermGlobal.escapeSeq[LTERM_QUOT_ESCAPE], """,
|
||||||
|
LTERM_MAXCHAR_ESCAPE+1);
|
||||||
|
ucscopy(ltermGlobal.escapeSeq[LTERM_APOS_ESCAPE], "'",
|
||||||
|
LTERM_MAXCHAR_ESCAPE+1);
|
||||||
|
|
||||||
/* Escape sequence lengths (including delimiters) */
|
/* Escape sequence lengths (including delimiters) */
|
||||||
for (j=0; j<LTERM_XML_ESCAPES; j++)
|
for (j=0; j<LTERM_XML_ESCAPES; j++) {
|
||||||
ltermGlobal.escapeLen[j] = ucslen(ltermGlobal.escapeSeq[j]);
|
ltermGlobal.escapeLen[j] = ucslen(ltermGlobal.escapeSeq[j]);
|
||||||
|
assert(ltermGlobal.escapeLen[j] <= LTERM_MAXCHAR_ESCAPE);
|
||||||
|
}
|
||||||
|
|
||||||
/* LTERM global initialization flag */
|
/* LTERM global initialization flag */
|
||||||
ltermGlobal.initialized = 1;
|
ltermGlobal.initialized = 1;
|
||||||
|
|
|
@ -53,9 +53,7 @@
|
||||||
#define _LTERMPRIVATE_H 1
|
#define _LTERMPRIVATE_H 1
|
||||||
|
|
||||||
/* Standard C header files */
|
/* Standard C header files */
|
||||||
#ifndef _STRING_H
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
/* public declarations */
|
/* public declarations */
|
||||||
#include "lineterm.h"
|
#include "lineterm.h"
|
||||||
|
@ -69,9 +67,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* pseudo-TTY stream interface */
|
/* pseudo-TTY stream interface */
|
||||||
#ifndef _PTYSTREAM_H
|
|
||||||
#include "ptystream.h"
|
#include "ptystream.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
#define LTERM_ERROR TLOG_ERROR
|
#define LTERM_ERROR TLOG_ERROR
|
||||||
#define LTERM_WARNING TLOG_WARNING
|
#define LTERM_WARNING TLOG_WARNING
|
||||||
|
@ -285,6 +281,9 @@ typedef FILE FILESTREAM;
|
||||||
#define LTERM_XML_ESCAPES 5
|
#define LTERM_XML_ESCAPES 5
|
||||||
#define LTERM_PLAIN_ESCAPES 3
|
#define LTERM_PLAIN_ESCAPES 3
|
||||||
|
|
||||||
|
/* Maximum no. of characters in an XML escape sequence (excluding NUL) */
|
||||||
|
#define LTERM_MAXCHAR_ESCAPE 6
|
||||||
|
|
||||||
/* input buffer pipe header "character" count */
|
/* input buffer pipe header "character" count */
|
||||||
#define PIPEHEADER 2
|
#define PIPEHEADER 2
|
||||||
|
|
||||||
|
@ -525,7 +524,8 @@ typedef struct {
|
||||||
MUTEX_DECLARE(listMutex); /* Thread lock to access to LTERM list */
|
MUTEX_DECLARE(listMutex); /* Thread lock to access to LTERM list */
|
||||||
UNICHAR metaDelimiter; /* Meta command delimiter (usually :) */
|
UNICHAR metaDelimiter; /* Meta command delimiter (usually :) */
|
||||||
char escapeChars[LTERM_XML_ESCAPES+1]; /* String of chars escaped in XML */
|
char escapeChars[LTERM_XML_ESCAPES+1]; /* String of chars escaped in XML */
|
||||||
UNICHAR* escapeSeq[LTERM_XML_ESCAPES]; /* XML character escape sequences */
|
UNICHAR escapeSeq[LTERM_XML_ESCAPES][LTERM_MAXCHAR_ESCAPE+1];
|
||||||
|
/* XML character escape sequences */
|
||||||
int escapeLen[LTERM_XML_ESCAPES]; /* XML char. escape sequence lengths */
|
int escapeLen[LTERM_XML_ESCAPES]; /* XML char. escape sequence lengths */
|
||||||
} LtermGlobal;
|
} LtermGlobal;
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
#define MAXCOL 4096 // Maximum columns in line buffer
|
#define MAXCOL 4096 // Maximum columns in line buffer
|
||||||
|
|
||||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||||
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
||||||
|
|
||||||
static NS_DEFINE_IID(kILineTermIID, MOZILINETERM_IID);
|
static NS_DEFINE_IID(kILineTermIID, MOZILINETERM_IID);
|
||||||
static NS_DEFINE_IID(kILineTermAuxIID, MOZILINETERMAUX_IID);
|
static NS_DEFINE_IID(kILineTermAuxIID, MOZILINETERMAUX_IID);
|
||||||
|
@ -381,13 +381,19 @@ NS_IMETHODIMP mozLineTerm::OpenAux(const PRUnichar *command,
|
||||||
nsCAutoString initCStr (initInput);
|
nsCAutoString initCStr (initInput);
|
||||||
XMLT_LOG(mozLineTerm::Open,22, ("initInput=%s\n", initCStr.GetBuffer()));
|
XMLT_LOG(mozLineTerm::Open,22, ("initInput=%s\n", initCStr.GetBuffer()));
|
||||||
|
|
||||||
|
// List of prompt delimiters
|
||||||
|
static const PRInt32 PROMPT_DELIMS = 5;
|
||||||
|
UNICHAR prompt_regexp[PROMPT_DELIMS+1];
|
||||||
|
ucscopy(prompt_regexp, "#$%>?", PROMPT_DELIMS+1);
|
||||||
|
PR_ASSERT(ucslen(prompt_regexp) == PROMPT_DELIMS);
|
||||||
|
|
||||||
if (anObserver != nsnull) {
|
if (anObserver != nsnull) {
|
||||||
result = lterm_open(mLTerm, NULL, cookieCStr, initCStr.GetBuffer(),
|
result = lterm_open(mLTerm, NULL, cookieCStr, initCStr.GetBuffer(),
|
||||||
L"#$%>?", options,
|
prompt_regexp, options,
|
||||||
processType, mozLineTerm::Callback, (void *) this);
|
processType, mozLineTerm::Callback, (void *) this);
|
||||||
} else {
|
} else {
|
||||||
result = lterm_open(mLTerm, NULL, cookieCStr, initCStr.GetBuffer(),
|
result = lterm_open(mLTerm, NULL, cookieCStr, initCStr.GetBuffer(),
|
||||||
L"#$%>?", options,
|
prompt_regexp, options,
|
||||||
processType, NULL, NULL);
|
processType, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2802,7 +2802,7 @@ void mozXMLTermSession::PositionOutputCursor(mozILineTermAux* lineTermAux)
|
||||||
PRInt32 cursorCol = 0;
|
PRInt32 cursorCol = 0;
|
||||||
lineTermAux->GetCursorColumn(&cursorCol);
|
lineTermAux->GetCursorColumn(&cursorCol);
|
||||||
textOffset = cursorCol - mOutputTextOffset;
|
textOffset = cursorCol - mOutputTextOffset;
|
||||||
if (textOffset > text.Length())
|
if (textOffset > (PRInt32)text.Length())
|
||||||
textOffset = text.Length();
|
textOffset = text.Length();
|
||||||
}
|
}
|
||||||
result = selection->Collapse(mOutputTextNode, textOffset);
|
result = selection->Collapse(mOutputTextNode, textOffset);
|
||||||
|
@ -3340,7 +3340,7 @@ NS_IMETHODIMP mozXMLTermSession::PositionScreenCursor(PRInt32 aRow,
|
||||||
|
|
||||||
XMLT_LOG(mozXMLTermSession::GetScreenText,60,("prevCols=%d\n",prevCols));
|
XMLT_LOG(mozXMLTermSession::GetScreenText,60,("prevCols=%d\n",prevCols));
|
||||||
|
|
||||||
if (prevCols+text.Length() >= aCol) {
|
if (prevCols+(PRInt32)text.Length() >= aCol) {
|
||||||
// Determine offset in current text element
|
// Determine offset in current text element
|
||||||
textOffset = aCol - prevCols;
|
textOffset = aCol - prevCols;
|
||||||
textNode = childNode;
|
textNode = childNode;
|
||||||
|
|
|
@ -1,186 +0,0 @@
|
||||||
/*
|
|
||||||
* The contents of this file are subject to the Mozilla Public
|
|
||||||
* License Version 1.1 (the "MPL"); you may not use this file
|
|
||||||
* except in compliance with the MPL. You may obtain a copy of
|
|
||||||
* the MPL at http://www.mozilla.org/MPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the MPL is distributed on an "AS
|
|
||||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
* implied. See the MPL for the specific language governing
|
|
||||||
* rights and limitations under the MPL.
|
|
||||||
*
|
|
||||||
* The Original Code is lineterm.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Ramalingam Saravanan.
|
|
||||||
* Portions created by Ramalingam Saravanan <svn@xmlterm.org> are
|
|
||||||
* Copyright (C) 1999 Ramalingam Saravanan. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*
|
|
||||||
* Alternatively, the contents of this file may be used under the
|
|
||||||
* terms of the GNU General Public License (the "GPL"), in which case
|
|
||||||
* the provisions of the GPL are applicable instead of
|
|
||||||
* those above. If you wish to allow use of your version of this
|
|
||||||
* file only under the terms of the GPL and not to allow
|
|
||||||
* others to use your version of this file under the MPL, indicate
|
|
||||||
* your decision by deleting the provisions above and replace them
|
|
||||||
* with the notice and other provisions required by the GPL.
|
|
||||||
* If you do not delete the provisions above, a recipient
|
|
||||||
* may use your version of this file under either the MPL or the
|
|
||||||
* GPL.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* unistring.c: Unicode string operations implementation */
|
|
||||||
|
|
||||||
/* public declarations */
|
|
||||||
#include "unistring.h"
|
|
||||||
|
|
||||||
/* private declarations */
|
|
||||||
|
|
||||||
/** Encodes Unicode string US with NUS characters into UTF8 string S with
|
|
||||||
* upto NS characters, returning the number of REMAINING Unicode characters
|
|
||||||
* and the number of ENCODED Utf8 characters
|
|
||||||
*/
|
|
||||||
void ucstoutf8(const UNICHAR* us, int nus, char* s, int ns,
|
|
||||||
int* remaining, int* encoded)
|
|
||||||
{
|
|
||||||
int j, k;
|
|
||||||
|
|
||||||
j = 0;
|
|
||||||
k = 0;
|
|
||||||
while ((j < ns) && (k < nus)) {
|
|
||||||
UNICHAR uch = us[k++];
|
|
||||||
|
|
||||||
if (uch < 0x0080) {
|
|
||||||
s[j++] = uch;
|
|
||||||
|
|
||||||
} else if (uch < 0x0800) {
|
|
||||||
if (j >= ns-1) break;
|
|
||||||
s[j++] = ((uch & 0x07C0) >> 6) | 0xC0;
|
|
||||||
s[j++] = (uch & 0x003F) | 0x80;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (j >= ns-2) break;
|
|
||||||
s[j++] = ((uch & 0xF000) >> 12) | 0xE0;
|
|
||||||
s[j++] = ((uch & 0x0FC0) >> 6) | 0x80;
|
|
||||||
s[j++] = (uch & 0x003F) | 0x80;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (remaining)
|
|
||||||
*remaining = nus - k;
|
|
||||||
|
|
||||||
if (encoded)
|
|
||||||
*encoded = j;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** Decodes UTF8 string S with NS characters to Unicode string US with
|
|
||||||
* upto NUS characters, returning the number of REMAINING Utf8 characters
|
|
||||||
* and the number of DECODED Unicode characters.
|
|
||||||
* If skipNUL is non-zero, NUL input characters are skipped.
|
|
||||||
* returns 0 if successful,
|
|
||||||
* -1 if an error occurred during decoding
|
|
||||||
*/
|
|
||||||
int utf8toucs(const char* s, int ns, UNICHAR* us, int nus,
|
|
||||||
int skipNUL, int* remaining, int* decoded)
|
|
||||||
{
|
|
||||||
int j, k;
|
|
||||||
int retcode = 0;
|
|
||||||
|
|
||||||
j = 0;
|
|
||||||
k = 0;
|
|
||||||
while ((j < ns) && (k < nus)) {
|
|
||||||
char ch = s[j];
|
|
||||||
|
|
||||||
if (0x80 & ch) {
|
|
||||||
if (0x40 & ch) {
|
|
||||||
if (0x20 & ch) {
|
|
||||||
/* consume 3 */
|
|
||||||
if (j >= ns-2) break;
|
|
||||||
|
|
||||||
if ( (s[j+1] & 0x40) || !(s[j+1] & 0x80) ||
|
|
||||||
(s[j+2] & 0x40) || !(s[j+2] & 0x80) ) {
|
|
||||||
retcode = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
us[k++] = ((ch & 0x0F) << 12)
|
|
||||||
| ((s[j+1] & 0x3F) << 6)
|
|
||||||
| ( s[j+2] & 0x3F);
|
|
||||||
|
|
||||||
j += 3;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
/* consume 2 */
|
|
||||||
if (j >= ns-1) break;
|
|
||||||
|
|
||||||
if ( (s[j+1] & 0x40) || !(s[j+1] & 0x80) ) {
|
|
||||||
retcode = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
us[k++] = ((ch & 0x1F) << 6)
|
|
||||||
| ( s[j+1] & 0x3F);
|
|
||||||
j += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
/* consume 1 (error) */
|
|
||||||
retcode = -1;
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
/* consume 1 */
|
|
||||||
if (ch || !skipNUL) {
|
|
||||||
us[k++] = ch;
|
|
||||||
}
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (remaining)
|
|
||||||
*remaining = ns - j;
|
|
||||||
|
|
||||||
if (decoded)
|
|
||||||
*decoded = k;
|
|
||||||
|
|
||||||
return retcode;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** Prints Unicode string US with NUS characters to file stream STREAM,
|
|
||||||
* escaping non-printable ASCII characters and all non-ASCII characters
|
|
||||||
*/
|
|
||||||
void ucsprint(FILE* stream, const UNICHAR* us, int nus)
|
|
||||||
{
|
|
||||||
static const char hexDigits[17] = "0123456789abcdef";
|
|
||||||
UNICHAR uch;
|
|
||||||
int k;
|
|
||||||
|
|
||||||
for (k=0; k<nus; k++) {
|
|
||||||
uch = us[k];
|
|
||||||
|
|
||||||
if (uch < (UNICHAR)U_SPACE) {
|
|
||||||
/* ASCII control character */
|
|
||||||
fprintf(stream, "^%c", (char) uch+U_ATSIGN);
|
|
||||||
|
|
||||||
} else if (uch == (UNICHAR)U_CARET) {
|
|
||||||
/* Caret */
|
|
||||||
fprintf(stream, "^^");
|
|
||||||
|
|
||||||
} else if (uch < (UNICHAR)U_DEL) {
|
|
||||||
/* Printable ASCII character */
|
|
||||||
fprintf(stream, "%c", (char) uch);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
/* DEL or non-ASCII character */
|
|
||||||
char esc_str[8]="�";
|
|
||||||
int j;
|
|
||||||
for (j=5; j>1; j--) {
|
|
||||||
esc_str[j] = hexDigits[uch%16];
|
|
||||||
uch = uch / 16;
|
|
||||||
}
|
|
||||||
fprintf(stream, "%s", esc_str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -33,8 +33,8 @@
|
||||||
/* unistring.h: Unicode string operations header
|
/* unistring.h: Unicode string operations header
|
||||||
* (used by lineterm.h)
|
* (used by lineterm.h)
|
||||||
* CPP options:
|
* CPP options:
|
||||||
* HAVE_WCSWCS: define is function wcswcs is available
|
* USE_WCHAR: use system wchar implementation, rather than unsigned short
|
||||||
* HAVE_WCSSTR: define is function wcsstr is available
|
* HAVE_WCSSTR: use wcsstr rather than wcswcs (used for wchar only)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _UNISTRING_H
|
#ifndef _UNISTRING_H
|
||||||
|
@ -45,20 +45,19 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _WCHAR_H
|
/* Standard C header files */
|
||||||
#include "wchar.h"
|
#include <stdio.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _STDIO_H
|
|
||||||
#include "stdio.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Unicode character type:
|
/* Unicode character type:
|
||||||
* Uses the wchar_t implementation for moment.
|
* Use either the wchar_t implementation or unsigned short
|
||||||
* Later we might implement a 16-bit UNICHAR type to save space
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef USE_WCHAR
|
||||||
|
#include <wchar.h>
|
||||||
typedef wchar_t UNICHAR;
|
typedef wchar_t UNICHAR;
|
||||||
|
#else /* !USE_WCHAR */
|
||||||
|
typedef unsigned short UNICHAR;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Unicode string functions:
|
/* Unicode string functions:
|
||||||
* use the wchar_t implementation for moment
|
* use the wchar_t implementation for moment
|
||||||
|
@ -86,6 +85,14 @@ int utf8toucs(const char* s, int ns, UNICHAR* us, int nus,
|
||||||
*/
|
*/
|
||||||
void ucsprint(FILE* stream, const UNICHAR* us, int nus);
|
void ucsprint(FILE* stream, const UNICHAR* us, int nus);
|
||||||
|
|
||||||
|
/** Copy exactly n characters from plain character source string to UNICHAR
|
||||||
|
* destination string, ignoring source characters past a null character and
|
||||||
|
* padding the destination with null characters if necessary.
|
||||||
|
*/
|
||||||
|
UNICHAR* ucscopy(UNICHAR* dest, const char* srcplain, size_t n);
|
||||||
|
|
||||||
|
#ifdef USE_WCHAR
|
||||||
|
|
||||||
#define ucscpy wcscpy
|
#define ucscpy wcscpy
|
||||||
#define ucsncpy wcsncpy
|
#define ucsncpy wcsncpy
|
||||||
|
|
||||||
|
@ -103,21 +110,74 @@ void ucsprint(FILE* stream, const UNICHAR* us, int nus);
|
||||||
|
|
||||||
#define ucspbrk wcspbrk
|
#define ucspbrk wcspbrk
|
||||||
|
|
||||||
#ifdef HAVE_WCSWCS
|
|
||||||
#define ucsucs wcswcs
|
|
||||||
#else
|
|
||||||
#ifdef HAVE_WCSSTR
|
#ifdef HAVE_WCSSTR
|
||||||
#define ucsucs wcsstr
|
#define ucsstr wcsstr
|
||||||
#endif
|
#else
|
||||||
|
#define ucsstr wcswcs
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ucslen wcslen
|
#define ucslen wcslen
|
||||||
|
|
||||||
#define ucstok wcstok
|
#define ucstok wcstok
|
||||||
|
|
||||||
|
#else /* !USE_WCHAR */
|
||||||
|
/** Locates first occurrence of character within string and returns pointer
|
||||||
|
* to it if found, else returning null pointer. (character may be NUL)
|
||||||
|
*/
|
||||||
|
UNICHAR* ucschr(const UNICHAR* str, const UNICHAR chr);
|
||||||
|
|
||||||
|
/** Locates last occurrence of character within string and returns pointer
|
||||||
|
* to it if found, else returning null pointer. (character may be NUL)
|
||||||
|
*/
|
||||||
|
UNICHAR* ucsrchr(const UNICHAR* str, const UNICHAR chr);
|
||||||
|
|
||||||
|
/** Compare all characters between string1 and string2, returning
|
||||||
|
* a zero value if all characters are equal, or returning
|
||||||
|
* character1 - character2 for the first character that is different
|
||||||
|
* between the two strings.
|
||||||
|
* (Characters following a null character are not compared.)
|
||||||
|
*/
|
||||||
|
int ucscmp(register const UNICHAR* str1, register const UNICHAR* str2);
|
||||||
|
|
||||||
|
/** Compare upto n characters between string1 and string2, returning
|
||||||
|
* a zero value if all compared characters are equal, or returning
|
||||||
|
* character1 - character2 for the first character that is different
|
||||||
|
* between the two strings.
|
||||||
|
* (Characters following a null character are not compared.)
|
||||||
|
*/
|
||||||
|
int ucsncmp(const UNICHAR* str1, const UNICHAR* str2,
|
||||||
|
size_t n);
|
||||||
|
|
||||||
|
/** Copy exactly n characters from source to destination, ignoring source
|
||||||
|
* characters past a null character and padding the destination with null
|
||||||
|
* characters if necessary.
|
||||||
|
*/
|
||||||
|
UNICHAR* ucsncpy(UNICHAR* dest, const UNICHAR* src,
|
||||||
|
size_t n);
|
||||||
|
|
||||||
|
/** Returns string length
|
||||||
|
*/
|
||||||
|
size_t ucslen(const UNICHAR* str);
|
||||||
|
|
||||||
|
/** Locates substring within string and returns pointer to it if found,
|
||||||
|
* else returning null pointer. If substring has zero length, then full
|
||||||
|
* string is returned.
|
||||||
|
*/
|
||||||
|
UNICHAR* ucsstr(const UNICHAR* str, const UNICHAR* substr);
|
||||||
|
|
||||||
|
/** Returns length of longest initial segment of string that contains
|
||||||
|
* only the specified characters.
|
||||||
|
*/
|
||||||
|
size_t ucsspn(const UNICHAR* str, const UNICHAR* chars);
|
||||||
|
|
||||||
|
/** Returns length of longest initial segment of string that does not
|
||||||
|
* contain any of the specified characters.
|
||||||
|
*/
|
||||||
|
size_t ucscspn(const UNICHAR* str, const UNICHAR* chars);
|
||||||
|
|
||||||
|
#endif /* !USE_WCHAR */
|
||||||
|
|
||||||
/* unsigned short constants */
|
/* unsigned short constants */
|
||||||
|
|
||||||
#define U_NUL 0x00U
|
#define U_NUL 0x00U
|
||||||
|
|
||||||
#define U_CTL_A 0x01U
|
#define U_CTL_A 0x01U
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
# Options
|
# Options
|
||||||
# STAND_ALONE: compile outside Mozilla/NSPR environment
|
# STAND_ALONE: compile outside Mozilla/NSPR environment
|
||||||
|
# USE_NCURSES: use NCURSES (for stand-alone mode only)
|
||||||
# DEBUG: debug option
|
# DEBUG: debug option
|
||||||
# NO_WORKAROUND: disables workarounds to expose bugs
|
# NO_WORKAROUND: disables workarounds to expose bugs
|
||||||
# USE_GTK_WIDGETS use GTK widget library
|
# USE_GTK_WIDGETS use GTK widget library
|
||||||
|
@ -60,7 +61,7 @@ DEFINES += -DLINUX -DHAVE_WCSSTR
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(OS_CONFIG),SunOS5)
|
ifeq ($(OS_CONFIG),SunOS5)
|
||||||
DEFINES += -DSOLARIS -DHAVE_WCSWCS
|
DEFINES += -DSOLARIS
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(MOZ_WIDGET_TOOLKIT),gtk)
|
ifeq ($(MOZ_WIDGET_TOOLKIT),gtk)
|
||||||
|
@ -70,7 +71,11 @@ endif
|
||||||
#
|
#
|
||||||
# Netscape Portable Runtime options
|
# Netscape Portable Runtime options
|
||||||
#
|
#
|
||||||
ifndef STAND_ALONE
|
ifdef STAND_ALONE
|
||||||
|
ifdef USE_NCURSES
|
||||||
|
DEFINES += -DUSE_NCURSES
|
||||||
|
endif
|
||||||
|
else
|
||||||
# Use NSPR base
|
# Use NSPR base
|
||||||
USE_NSPR_BASE = 1
|
USE_NSPR_BASE = 1
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -50,13 +50,17 @@ endif
|
||||||
DEBUG = 1
|
DEBUG = 1
|
||||||
|
|
||||||
# Program
|
# Program
|
||||||
SIMPLE_PROGRAMS = lterm ptytest testunistr
|
SIMPLE_PROGRAMS = lterm ptytest unitest utf8conv
|
||||||
|
|
||||||
# Defines
|
# Defines
|
||||||
DEFINES =
|
DEFINES =
|
||||||
|
|
||||||
# Libraries to be linked
|
# Libraries to be linked
|
||||||
|
ifdef USE_NCURSES
|
||||||
LIBS = -lncurses -lxmlterm -lpthread
|
LIBS = -lncurses -lxmlterm -lpthread
|
||||||
|
else
|
||||||
|
LIBS = -lxmlterm -lpthread
|
||||||
|
endif
|
||||||
|
|
||||||
include $(topsrcdir)/config/config.mk
|
include $(topsrcdir)/config/config.mk
|
||||||
|
|
||||||
|
|
|
@ -30,10 +30,12 @@
|
||||||
* GPL.
|
* GPL.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* lterm.c: Test driver for LINETERM using NCURSES
|
/* lterm.c: Test driver for LINETERM
|
||||||
* CPP options:
|
* CPP options:
|
||||||
* LINUX: for Linux2.0/glibc
|
* USE_NCURSES: Enable NCURSES as a screen display option
|
||||||
* SOLARIS: for Solaris2.6
|
* NCURSES_MOUSE_VERSION: Enable NCURSES mouse operations
|
||||||
|
* LINUX: for Linux2.0/glibc
|
||||||
|
* SOLARIS: for Solaris2.6
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -46,7 +48,9 @@
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "curses.h"
|
#ifdef USE_NCURSES
|
||||||
|
#include <ncurses.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define _REENTRANT
|
#define _REENTRANT
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
@ -90,7 +94,7 @@ static int ncursesFlag = 0;
|
||||||
static int ptyFlag = 1;
|
static int ptyFlag = 1;
|
||||||
static int debugFlag = 0;
|
static int debugFlag = 0;
|
||||||
static int ltermNumber = -1;
|
static int ltermNumber = -1;
|
||||||
static SCREEN *termScreen = NULL;
|
static char *debugFunction;
|
||||||
static char *ttyDevice;
|
static char *ttyDevice;
|
||||||
static char *errDevice;
|
static char *errDevice;
|
||||||
|
|
||||||
|
@ -106,6 +110,10 @@ static void *output_handler(void *arg);
|
||||||
|
|
||||||
static void input_handler(int *plterm);
|
static void input_handler(int *plterm);
|
||||||
|
|
||||||
|
#ifdef USE_NCURSES
|
||||||
|
static SCREEN *termScreen = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
FILE *inFile, *outFile;
|
FILE *inFile, *outFile;
|
||||||
UNICHAR uregexp[MAXPROMPT+1];
|
UNICHAR uregexp[MAXPROMPT+1];
|
||||||
|
@ -121,6 +129,7 @@ int main(int argc, char *argv[]) {
|
||||||
ptyFlag = 1;
|
ptyFlag = 1;
|
||||||
debugFlag = 0;
|
debugFlag = 0;
|
||||||
processType = LTERM_DETERMINE_PROCESS;
|
processType = LTERM_DETERMINE_PROCESS;
|
||||||
|
debugFunction = NULL;
|
||||||
ttyDevice = NULL;
|
ttyDevice = NULL;
|
||||||
errDevice = NULL;
|
errDevice = NULL;
|
||||||
promptStr = "#$%>?"; /* JUST A LIST OF DELIMITERS AT PRESENT */
|
promptStr = "#$%>?"; /* JUST A LIST OF DELIMITERS AT PRESENT */
|
||||||
|
@ -129,7 +138,7 @@ int main(int argc, char *argv[]) {
|
||||||
while (argNo < argc) {
|
while (argNo < argc) {
|
||||||
|
|
||||||
if ((strcmp(argv[argNo],"-h") == 0)||(strcmp(argv[argNo],"-help") == 0)) {
|
if ((strcmp(argv[argNo],"-h") == 0)||(strcmp(argv[argNo],"-help") == 0)) {
|
||||||
fprintf(stderr, "Usage: %s [-help] [-ncurses] [-nopty] [-debug] [-tcsh / -bash] [-tty /dev/ttyname] [-err /dev/ttyname] [-prompt <prompt>] <command> ...\n", argv[0]);
|
fprintf(stderr, "Usage: %s [-help] [-ncurses] [-nopty] [-debug] [-tcsh / -bash] [-function debug_fun] [-tty /dev/ttyname] [-err /dev/ttyname] [-prompt <prompt>] <command> ...\n", argv[0]);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
} else if (strcmp(argv[argNo],"-ncurses") == 0) {
|
} else if (strcmp(argv[argNo],"-ncurses") == 0) {
|
||||||
|
@ -152,25 +161,28 @@ int main(int argc, char *argv[]) {
|
||||||
processType = LTERM_TCSH_PROCESS;
|
processType = LTERM_TCSH_PROCESS;
|
||||||
argNo++;
|
argNo++;
|
||||||
|
|
||||||
|
} else if (strcmp(argv[argNo],"-function") == 0) {
|
||||||
|
argNo++;
|
||||||
|
if (argNo < argc) {
|
||||||
|
debugFunction = argv[argNo++];
|
||||||
|
}
|
||||||
|
|
||||||
} else if (strcmp(argv[argNo],"-tty") == 0) {
|
} else if (strcmp(argv[argNo],"-tty") == 0) {
|
||||||
argNo++;
|
argNo++;
|
||||||
if (argNo < argc) {
|
if (argNo < argc) {
|
||||||
ttyDevice = argv[argNo];
|
ttyDevice = argv[argNo++];
|
||||||
argNo++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (strcmp(argv[argNo],"-err") == 0) {
|
} else if (strcmp(argv[argNo],"-err") == 0) {
|
||||||
argNo++;
|
argNo++;
|
||||||
if (argNo < argc) {
|
if (argNo < argc) {
|
||||||
errDevice = argv[argNo];
|
errDevice = argv[argNo++];
|
||||||
argNo++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (strcmp(argv[argNo],"-prompt") == 0) {
|
} else if (strcmp(argv[argNo],"-prompt") == 0) {
|
||||||
argNo++;
|
argNo++;
|
||||||
if (argNo < argc) {
|
if (argNo < argc) {
|
||||||
promptStr = argv[argNo];
|
promptStr = argv[argNo++];
|
||||||
argNo++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else
|
} else
|
||||||
|
@ -221,6 +233,8 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
if (ncursesFlag) {
|
if (ncursesFlag) {
|
||||||
/* NCURSES mode */
|
/* NCURSES mode */
|
||||||
|
|
||||||
|
#ifdef USE_NCURSES
|
||||||
if (ttyDevice == NULL) {
|
if (ttyDevice == NULL) {
|
||||||
/* Initialize screen on controlling TTY */
|
/* Initialize screen on controlling TTY */
|
||||||
initscr();
|
initscr();
|
||||||
|
@ -247,6 +261,7 @@ int main(int argc, char *argv[]) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
clear(); /* Clear screen */
|
clear(); /* Clear screen */
|
||||||
|
#endif /* USE_NCURSES */
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* XTERM mode */
|
/* XTERM mode */
|
||||||
|
@ -273,13 +288,14 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize LTERM operations */
|
/* Initialize LTERM operations */
|
||||||
lterm_init(messageLevel);
|
lterm_init(0);
|
||||||
|
|
||||||
if (errDevice != NULL) {
|
if (errDevice != NULL) {
|
||||||
tlog_message("lterm-00: Testing tlog_message\n");
|
tlog_message("lterm-00: Testing tlog_message\n");
|
||||||
tlog_warning("lterm-00: Testing tlog_warning\n");
|
tlog_warning("lterm-00: Testing tlog_warning\n");
|
||||||
fprintf(stderr, "lterm-00: ");
|
fprintf(stderr, "lterm-00: ");
|
||||||
tlog_unichar(uregexp, ucslen(uregexp));
|
tlog_unichar(uregexp, ucslen(uregexp));
|
||||||
|
tlog_set_level(LTERM_TLOG_MODULE, messageLevel, debugFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errDevice != NULL)
|
if (errDevice != NULL)
|
||||||
|
@ -328,9 +344,11 @@ int main(int argc, char *argv[]) {
|
||||||
void finish(int sig)
|
void finish(int sig)
|
||||||
{
|
{
|
||||||
if (ncursesFlag) {
|
if (ncursesFlag) {
|
||||||
|
#ifdef USE_NCURSES
|
||||||
endwin(); /* Close window */
|
endwin(); /* Close window */
|
||||||
if (termScreen != NULL)
|
if (termScreen != NULL)
|
||||||
delscreen(termScreen);
|
delscreen(termScreen);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ltermNumber >= 0) {
|
if (ltermNumber >= 0) {
|
||||||
|
@ -377,7 +395,9 @@ void writeUnicode(int fd, const UNICHAR *buf, int count)
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
#ifdef USE_NCURSES
|
||||||
addnstr(str, k);
|
addnstr(str, k);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,9 +450,11 @@ void input_handler(int *plterm)
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* Read a character from TTY (raw mode) */
|
/* Read a character from TTY (raw mode) */
|
||||||
if (ncursesFlag) {
|
if (ncursesFlag) {
|
||||||
|
#ifdef USE_NCURSES
|
||||||
ch = getch();
|
ch = getch();
|
||||||
if (ch == '\r')
|
if (ch == '\r')
|
||||||
ch = '\n';
|
ch = '\n';
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
ch = getchar();
|
ch = getchar();
|
||||||
}
|
}
|
||||||
|
@ -478,7 +500,9 @@ void *output_handler(void *arg)
|
||||||
UNISTYLE style[MAXCOL];
|
UNISTYLE style[MAXCOL];
|
||||||
int n_read, opcodes, opvals, buf_row, buf_col, cursor_row, cursor_col;
|
int n_read, opcodes, opvals, buf_row, buf_col, cursor_row, cursor_col;
|
||||||
int xmax, ymax, x, y, c;
|
int xmax, ymax, x, y, c;
|
||||||
|
#ifdef USE_NCURSES
|
||||||
MEVENT mev;
|
MEVENT mev;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (errDevice != NULL)
|
if (errDevice != NULL)
|
||||||
fprintf(stderr, "output_handler-00: thread ID = %d, LTERM=%d\n",
|
fprintf(stderr, "output_handler-00: thread ID = %d, LTERM=%d\n",
|
||||||
|
@ -486,7 +510,9 @@ void *output_handler(void *arg)
|
||||||
|
|
||||||
/* Get screen size */
|
/* Get screen size */
|
||||||
if (ncursesFlag) {
|
if (ncursesFlag) {
|
||||||
|
#ifdef USE_NCURSES
|
||||||
getmaxyx(stdscr, ymax, xmax);
|
getmaxyx(stdscr, ymax, xmax);
|
||||||
|
#endif
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ymax = 24;
|
ymax = 24;
|
||||||
|
@ -546,6 +572,7 @@ void *output_handler(void *arg)
|
||||||
if (ncursesFlag) {
|
if (ncursesFlag) {
|
||||||
/* NCURSES mode */
|
/* NCURSES mode */
|
||||||
|
|
||||||
|
#ifdef USE_NCURSES
|
||||||
if (opcodes & LTERM_CLEAR_CODE) {
|
if (opcodes & LTERM_CLEAR_CODE) {
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
|
@ -592,6 +619,7 @@ void *output_handler(void *arg)
|
||||||
move(ymax-1-cursor_row, cursor_col);
|
move(ymax-1-cursor_row, cursor_col);
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
|
#endif /* USE_NCURSES */
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* XTERM MODE */
|
/* XTERM MODE */
|
||||||
|
@ -653,6 +681,7 @@ void *output_handler(void *arg)
|
||||||
if (ncursesFlag) {
|
if (ncursesFlag) {
|
||||||
/* NCURSES mode */
|
/* NCURSES mode */
|
||||||
|
|
||||||
|
#ifdef USE_NCURSES
|
||||||
/* Move cursor to bottom of screen, clear line and display line */
|
/* Move cursor to bottom of screen, clear line and display line */
|
||||||
move(ymax-1,0);
|
move(ymax-1,0);
|
||||||
clrtoeol();
|
clrtoeol();
|
||||||
|
@ -667,6 +696,7 @@ void *output_handler(void *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
|
#endif /* USE_NCURSES */
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* Screen mode */
|
/* Screen mode */
|
||||||
|
|
Загрузка…
Ссылка в новой задаче