From caa7e6ebfba7442387c542dc5b49cd3264e8b6b5 Mon Sep 17 00:00:00 2001 From: "svn%xmlterm.org" Date: Fri, 31 Mar 2000 04:14:39 +0000 Subject: [PATCH] xmlterm changes only; Removed all wchar dependence by recoding the primitive Unicode string functions used by lineterm. (FreeBSD doesn't have a wchar implementation!) git-svn-id: svn://10.0.0.236/trunk@64693 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/extensions/xmlterm/Makefile.in | 4 +- mozilla/extensions/xmlterm/base/lineterm.h | 2 - mozilla/extensions/xmlterm/base/ltermIO.c | 21 +- .../extensions/xmlterm/base/ltermManager.c | 19 +- .../extensions/xmlterm/base/ltermPrivate.h | 10 +- .../extensions/xmlterm/base/mozLineTerm.cpp | 12 +- .../xmlterm/base/mozXMLTermSession.cpp | 4 +- mozilla/extensions/xmlterm/base/unistring.c | 223 ++++++++++++++++++ mozilla/extensions/xmlterm/base/unistring.h | 94 ++++++-- .../xmlterm/config/xmlterm_config.mk | 9 +- .../extensions/xmlterm/linetest/Makefile.in | 6 +- mozilla/extensions/xmlterm/linetest/lterm.c | 56 ++++- mozilla/extensions/xmlterm/linetest/unitest.c | 211 +++++++++++++++++ .../linetest/{testunistr.c => utf8conv.c} | 4 +- 14 files changed, 614 insertions(+), 61 deletions(-) create mode 100644 mozilla/extensions/xmlterm/linetest/unitest.c rename mozilla/extensions/xmlterm/linetest/{testunistr.c => utf8conv.c} (96%) diff --git a/mozilla/extensions/xmlterm/Makefile.in b/mozilla/extensions/xmlterm/Makefile.in index d58a415c9e6..1a8e8cd983a 100644 --- a/mozilla/extensions/xmlterm/Makefile.in +++ b/mozilla/extensions/xmlterm/Makefile.in @@ -68,8 +68,8 @@ DIRS = base tests linetest else # not STAND_ALONE -# XMLterm currently works on Linux and SunOS only -ifneq (,$(filter Linux SunOS,$(OS_ARCH))) +# XMLterm currently works on Linux and SunOS only (testing on BSD family) +ifneq (,$(filter Linux SunOS BSD,$(OS_ARCH))) DIRS = base ui scripts doc tests else # XMLterm not yet been ported to this platform; do nothing DIRS = diff --git a/mozilla/extensions/xmlterm/base/lineterm.h b/mozilla/extensions/xmlterm/base/lineterm.h index 579c1ae79f8..24c628290d1 100644 --- a/mozilla/extensions/xmlterm/base/lineterm.h +++ b/mozilla/extensions/xmlterm/base/lineterm.h @@ -39,9 +39,7 @@ #define _LINETERM_H 1 -#ifndef _UNISTRING_H #include "unistring.h" -#endif /* Define LTERM read callback function type */ #ifdef USE_GTK_WIDGETS diff --git a/mozilla/extensions/xmlterm/base/ltermIO.c b/mozilla/extensions/xmlterm/base/ltermIO.c index eacb1da2c28..50c9e86dc06 100644 --- a/mozilla/extensions/xmlterm/base/ltermIO.c +++ b/mozilla/extensions/xmlterm/base/ltermIO.c @@ -885,7 +885,7 @@ static int ltermReturnStreamData(struct lterms *lts, struct LtermRead *ltr) assert((int)ucslen(lto->decodedOutput) == lto->decodedChars); /* Search for stream terminator string in decoded output */ - locTerminator = ucsucs(lto->decodedOutput, lto->streamTerminator); + locTerminator = ucsstr(lto->decodedOutput, lto->streamTerminator); } /* Stream termination flag */ @@ -1091,11 +1091,20 @@ static int ltermReturnInputLine(struct lterms *lts, struct LtermRead *ltr, /* Prefix with prompt output data */ ltr->opcodes = LTERM_LINEDATA_CODE; - if (completionRequested) { - outChars = lto->promptChars; - } else { - /* Hack to handle misidentified prompts */ - outChars = lto->outputChars; + outChars = lto->promptChars; + + if (!completionRequested) { + /* Hack to handle misidentified prompts; + * if output characters following the prompt differ from input line, + * display them. + */ + for (j=0; jinputChars; j++) { + if (((j+outChars) < lto->outputChars) && + (lto->outputLine[j+outChars] != lti->inputLine[j])) { + outChars = lto->outputChars; + break; + } + } } if (outChars > ltr->max_count) diff --git a/mozilla/extensions/xmlterm/base/ltermManager.c b/mozilla/extensions/xmlterm/base/ltermManager.c index 43a0c0463d1..03b8a861b31 100644 --- a/mozilla/extensions/xmlterm/base/ltermManager.c +++ b/mozilla/extensions/xmlterm/base/ltermManager.c @@ -133,15 +133,22 @@ int lterm_init(int messageLevel) ltermGlobal.escapeChars[LTERM_XML_ESCAPES] = 0; /* List of XML character escape sequences (Unicode) */ - ltermGlobal.escapeSeq[LTERM_AMP_ESCAPE] = L"&"; - ltermGlobal.escapeSeq[LTERM_LT_ESCAPE] = L"<"; - ltermGlobal.escapeSeq[LTERM_GT_ESCAPE] = L">"; - ltermGlobal.escapeSeq[LTERM_QUOT_ESCAPE] = L"""; - ltermGlobal.escapeSeq[LTERM_APOS_ESCAPE] = L"'"; + ucscopy(ltermGlobal.escapeSeq[LTERM_AMP_ESCAPE], "&", + LTERM_MAXCHAR_ESCAPE+1); + ucscopy(ltermGlobal.escapeSeq[LTERM_LT_ESCAPE], "<", + LTERM_MAXCHAR_ESCAPE+1); + 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) */ - for (j=0; j -#endif /* public declarations */ #include "lineterm.h" @@ -69,9 +67,7 @@ #endif /* pseudo-TTY stream interface */ -#ifndef _PTYSTREAM_H #include "ptystream.h" -#endif #define LTERM_ERROR TLOG_ERROR #define LTERM_WARNING TLOG_WARNING @@ -285,6 +281,9 @@ typedef FILE FILESTREAM; #define LTERM_XML_ESCAPES 5 #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 */ #define PIPEHEADER 2 @@ -525,7 +524,8 @@ typedef struct { MUTEX_DECLARE(listMutex); /* Thread lock to access to LTERM list */ UNICHAR metaDelimiter; /* Meta command delimiter (usually :) */ 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 */ } LtermGlobal; diff --git a/mozilla/extensions/xmlterm/base/mozLineTerm.cpp b/mozilla/extensions/xmlterm/base/mozLineTerm.cpp index 979f90230b4..4d445eaf5f1 100644 --- a/mozilla/extensions/xmlterm/base/mozLineTerm.cpp +++ b/mozilla/extensions/xmlterm/base/mozLineTerm.cpp @@ -46,7 +46,7 @@ #define MAXCOL 4096 // Maximum columns in line buffer 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(kILineTermAuxIID, MOZILINETERMAUX_IID); @@ -381,13 +381,19 @@ NS_IMETHODIMP mozLineTerm::OpenAux(const PRUnichar *command, nsCAutoString initCStr (initInput); 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) { result = lterm_open(mLTerm, NULL, cookieCStr, initCStr.GetBuffer(), - L"#$%>?", options, + prompt_regexp, options, processType, mozLineTerm::Callback, (void *) this); } else { result = lterm_open(mLTerm, NULL, cookieCStr, initCStr.GetBuffer(), - L"#$%>?", options, + prompt_regexp, options, processType, NULL, NULL); } diff --git a/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp b/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp index 60573298aae..0ff1a760209 100644 --- a/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp +++ b/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp @@ -2802,7 +2802,7 @@ void mozXMLTermSession::PositionOutputCursor(mozILineTermAux* lineTermAux) PRInt32 cursorCol = 0; lineTermAux->GetCursorColumn(&cursorCol); textOffset = cursorCol - mOutputTextOffset; - if (textOffset > text.Length()) + if (textOffset > (PRInt32)text.Length()) textOffset = text.Length(); } result = selection->Collapse(mOutputTextNode, textOffset); @@ -3340,7 +3340,7 @@ NS_IMETHODIMP mozXMLTermSession::PositionScreenCursor(PRInt32 aRow, 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 textOffset = aCol - prevCols; textNode = childNode; diff --git a/mozilla/extensions/xmlterm/base/unistring.c b/mozilla/extensions/xmlterm/base/unistring.c index 9846969ed28..7bb2a230e41 100644 --- a/mozilla/extensions/xmlterm/base/unistring.c +++ b/mozilla/extensions/xmlterm/base/unistring.c @@ -184,3 +184,226 @@ 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(register UNICHAR* dest, register const char* srcplain, + size_t n) +{ + register UNICHAR ch; + register const UNICHAR* destmx = dest + n; + + /* Copy characters from source to destination, stopping at NUL */ + while (dest < destmx) { + *dest++ = (ch = *srcplain++); + if (ch == U_NUL) + break; + } + + /* Pad with NULs, if necessary */ + while (dest < destmx) + *dest++ = U_NUL; + + return dest; +} + + +#ifndef 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(register const UNICHAR* str, register const UNICHAR chr) +{ + do { + if (*str == chr) + return (UNICHAR*) str; + } while (*str++ != U_NUL); + + return NULL; +} + + +/** Locates last occurrence of character within string and returns pointer + * to it if found, else returning null pointer. (character may be NUL) + */ +UNICHAR* ucsrchr(register const UNICHAR* str, register const UNICHAR chr) +{ + const UNICHAR* retstr = NULL; + do { + if (*str == chr) + retstr = str; + } while (*str++ != U_NUL); + + return (UNICHAR*) retstr; +} + + +/** 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) +{ + register UNICHAR ch1, ch2; + + do { + if ((ch1 = *str1++) != (ch2 = *str2++)) + return ch1 - ch2; + + } while (ch1 != U_NUL); + + return 0; +} + + +/** 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(register const UNICHAR* str1, register const UNICHAR* str2, + size_t n) +{ + register UNICHAR ch1, ch2; + register const UNICHAR* str1mx = str1 + n; + + while (str1 < str1mx) { + if ((ch1 = *str1++) != (ch2 = *str2++)) + return ch1 - ch2; + + if (ch1 == U_NUL) + break; + } + + return 0; +} + + +/** 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(register UNICHAR* dest, register const UNICHAR* src, + size_t n) +{ + register UNICHAR ch; + register const UNICHAR* destmx = dest + n; + + /* Copy characters from source to destination, stopping at NUL */ + while (dest < destmx) { + *dest++ = (ch = *src++); + if (ch == U_NUL) + break; + } + + /* Pad with NULs, if necessary */ + while (dest < destmx) + *dest++ = U_NUL; + + return dest; +} + + +/** Returns string length + */ +size_t ucslen(const UNICHAR* str) +{ + register const UNICHAR* strcp = str; + + while (*strcp++ != U_NUL); + + return strcp - str - 1; +} + + +/** 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(register const UNICHAR* str, const UNICHAR* substr) +{ + register UNICHAR subch1, ch; + + /* If null substring, return string */ + if (*substr == U_NUL) + return (UNICHAR*) str; + + /* First character of non-null substring */ + subch1 = *substr; + + if ((ch = *str) == U_NUL) + return NULL; + + do { + + if (ch == subch1) { + /* First character matches; check if rest of substring matches */ + register const UNICHAR* strcp = str; + register const UNICHAR* substrcp = substr; + do { + substrcp++; + strcp++; + if (*substrcp == U_NUL) + return (UNICHAR*) str; + } while (*substrcp == *strcp); + } + + } while ((ch = *(++str)) != U_NUL); + + return NULL; +} + + +/** Returns length of longest initial segment of string that contains + * only the specified characters. + */ +size_t ucsspn(const UNICHAR* str, const UNICHAR* chars) +{ + register UNICHAR strch, ch; + register const UNICHAR* charscp; + register const UNICHAR* strcp = str; + + while ((strch = *strcp++) != U_NUL) { + charscp = chars; + + /* Check that it is one of the specified characters */ + while ((ch = *charscp++) != U_NUL) { + if (strch == ch) + break; + } + if (ch == U_NUL) + return (size_t) (strcp - str - 1); + } + + return (size_t) (strcp - str - 1); +} + + +/** 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) +{ + register UNICHAR strch, ch; + register const UNICHAR* charscp; + register const UNICHAR* strcp = str; + + while ((strch = *strcp++) != U_NUL) { + charscp = chars; + + /* Check that it is not one of the specified characters */ + while ((ch = *charscp++) != U_NUL) { + if (strch == ch) + return (size_t) (strcp - str - 1); + } + } + + return (size_t) (strcp - str - 1); +} +#endif /* !USE_WCHAR */ diff --git a/mozilla/extensions/xmlterm/base/unistring.h b/mozilla/extensions/xmlterm/base/unistring.h index 630dd220a5c..2f82ed099c2 100644 --- a/mozilla/extensions/xmlterm/base/unistring.h +++ b/mozilla/extensions/xmlterm/base/unistring.h @@ -33,8 +33,8 @@ /* unistring.h: Unicode string operations header * (used by lineterm.h) * CPP options: - * HAVE_WCSWCS: define is function wcswcs is available - * HAVE_WCSSTR: define is function wcsstr is available + * USE_WCHAR: use system wchar implementation, rather than unsigned short + * HAVE_WCSSTR: use wcsstr rather than wcswcs (used for wchar only) */ #ifndef _UNISTRING_H @@ -45,20 +45,19 @@ extern "C" { #endif -#ifndef _WCHAR_H -#include "wchar.h" -#endif - -#ifndef _STDIO_H -#include "stdio.h" -#endif +/* Standard C header files */ +#include /* Unicode character type: - * Uses the wchar_t implementation for moment. - * Later we might implement a 16-bit UNICHAR type to save space + * Use either the wchar_t implementation or unsigned short */ +#ifdef USE_WCHAR +#include typedef wchar_t UNICHAR; +#else /* !USE_WCHAR */ +typedef unsigned short UNICHAR; +#endif /* Unicode string functions: * 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); +/** 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 ucsncpy wcsncpy @@ -103,21 +110,74 @@ void ucsprint(FILE* stream, const UNICHAR* us, int nus); #define ucspbrk wcspbrk -#ifdef HAVE_WCSWCS -#define ucsucs wcswcs -#else #ifdef HAVE_WCSSTR -#define ucsucs wcsstr -#endif +#define ucsstr wcsstr +#else +#define ucsstr wcswcs #endif #define ucslen wcslen #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 */ - #define U_NUL 0x00U #define U_CTL_A 0x01U diff --git a/mozilla/extensions/xmlterm/config/xmlterm_config.mk b/mozilla/extensions/xmlterm/config/xmlterm_config.mk index 51623ccfed1..8778024c3e2 100644 --- a/mozilla/extensions/xmlterm/config/xmlterm_config.mk +++ b/mozilla/extensions/xmlterm/config/xmlterm_config.mk @@ -34,6 +34,7 @@ # Options # STAND_ALONE: compile outside Mozilla/NSPR environment +# USE_NCURSES: use NCURSES (for stand-alone mode only) # DEBUG: debug option # NO_WORKAROUND: disables workarounds to expose bugs # USE_GTK_WIDGETS use GTK widget library @@ -60,7 +61,7 @@ DEFINES += -DLINUX -DHAVE_WCSSTR endif ifeq ($(OS_CONFIG),SunOS5) -DEFINES += -DSOLARIS -DHAVE_WCSWCS +DEFINES += -DSOLARIS endif ifeq ($(MOZ_WIDGET_TOOLKIT),gtk) @@ -70,7 +71,11 @@ endif # # Netscape Portable Runtime options # -ifndef STAND_ALONE +ifdef STAND_ALONE +ifdef USE_NCURSES +DEFINES += -DUSE_NCURSES +endif +else # Use NSPR base USE_NSPR_BASE = 1 endif diff --git a/mozilla/extensions/xmlterm/linetest/Makefile.in b/mozilla/extensions/xmlterm/linetest/Makefile.in index 0483fe2f3f2..a3dd43c2014 100644 --- a/mozilla/extensions/xmlterm/linetest/Makefile.in +++ b/mozilla/extensions/xmlterm/linetest/Makefile.in @@ -50,13 +50,17 @@ endif DEBUG = 1 # Program -SIMPLE_PROGRAMS = lterm ptytest testunistr +SIMPLE_PROGRAMS = lterm ptytest unitest utf8conv # Defines DEFINES = # Libraries to be linked +ifdef USE_NCURSES LIBS = -lncurses -lxmlterm -lpthread +else +LIBS = -lxmlterm -lpthread +endif include $(topsrcdir)/config/config.mk diff --git a/mozilla/extensions/xmlterm/linetest/lterm.c b/mozilla/extensions/xmlterm/linetest/lterm.c index fa0df115ed5..ebef0a33d04 100644 --- a/mozilla/extensions/xmlterm/linetest/lterm.c +++ b/mozilla/extensions/xmlterm/linetest/lterm.c @@ -30,10 +30,12 @@ * GPL. */ -/* lterm.c: Test driver for LINETERM using NCURSES +/* lterm.c: Test driver for LINETERM * CPP options: - * LINUX: for Linux2.0/glibc - * SOLARIS: for Solaris2.6 + * USE_NCURSES: Enable NCURSES as a screen display option + * NCURSES_MOUSE_VERSION: Enable NCURSES mouse operations + * LINUX: for Linux2.0/glibc + * SOLARIS: for Solaris2.6 */ #include @@ -46,7 +48,9 @@ #include -#include "curses.h" +#ifdef USE_NCURSES +#include +#endif #define _REENTRANT #include @@ -90,7 +94,7 @@ static int ncursesFlag = 0; static int ptyFlag = 1; static int debugFlag = 0; static int ltermNumber = -1; -static SCREEN *termScreen = NULL; +static char *debugFunction; static char *ttyDevice; static char *errDevice; @@ -106,6 +110,10 @@ static void *output_handler(void *arg); static void input_handler(int *plterm); +#ifdef USE_NCURSES +static SCREEN *termScreen = NULL; +#endif + int main(int argc, char *argv[]) { FILE *inFile, *outFile; UNICHAR uregexp[MAXPROMPT+1]; @@ -121,6 +129,7 @@ int main(int argc, char *argv[]) { ptyFlag = 1; debugFlag = 0; processType = LTERM_DETERMINE_PROCESS; + debugFunction = NULL; ttyDevice = NULL; errDevice = NULL; promptStr = "#$%>?"; /* JUST A LIST OF DELIMITERS AT PRESENT */ @@ -129,7 +138,7 @@ int main(int argc, char *argv[]) { while (argNo < argc) { 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 ] ...\n", argv[0]); + fprintf(stderr, "Usage: %s [-help] [-ncurses] [-nopty] [-debug] [-tcsh / -bash] [-function debug_fun] [-tty /dev/ttyname] [-err /dev/ttyname] [-prompt ] ...\n", argv[0]); exit(0); } else if (strcmp(argv[argNo],"-ncurses") == 0) { @@ -152,25 +161,28 @@ int main(int argc, char *argv[]) { processType = LTERM_TCSH_PROCESS; argNo++; + } else if (strcmp(argv[argNo],"-function") == 0) { + argNo++; + if (argNo < argc) { + debugFunction = argv[argNo++]; + } + } else if (strcmp(argv[argNo],"-tty") == 0) { argNo++; if (argNo < argc) { - ttyDevice = argv[argNo]; - argNo++; + ttyDevice = argv[argNo++]; } } else if (strcmp(argv[argNo],"-err") == 0) { argNo++; if (argNo < argc) { - errDevice = argv[argNo]; - argNo++; + errDevice = argv[argNo++]; } } else if (strcmp(argv[argNo],"-prompt") == 0) { argNo++; if (argNo < argc) { - promptStr = argv[argNo]; - argNo++; + promptStr = argv[argNo++]; } } else @@ -221,6 +233,8 @@ int main(int argc, char *argv[]) { if (ncursesFlag) { /* NCURSES mode */ + +#ifdef USE_NCURSES if (ttyDevice == NULL) { /* Initialize screen on controlling TTY */ initscr(); @@ -247,6 +261,7 @@ int main(int argc, char *argv[]) { #endif clear(); /* Clear screen */ +#endif /* USE_NCURSES */ } else { /* XTERM mode */ @@ -273,13 +288,14 @@ int main(int argc, char *argv[]) { } /* Initialize LTERM operations */ - lterm_init(messageLevel); + lterm_init(0); if (errDevice != NULL) { tlog_message("lterm-00: Testing tlog_message\n"); tlog_warning("lterm-00: Testing tlog_warning\n"); fprintf(stderr, "lterm-00: "); tlog_unichar(uregexp, ucslen(uregexp)); + tlog_set_level(LTERM_TLOG_MODULE, messageLevel, debugFunction); } if (errDevice != NULL) @@ -328,9 +344,11 @@ int main(int argc, char *argv[]) { void finish(int sig) { if (ncursesFlag) { +#ifdef USE_NCURSES endwin(); /* Close window */ if (termScreen != NULL) delscreen(termScreen); +#endif } if (ltermNumber >= 0) { @@ -377,7 +395,9 @@ void writeUnicode(int fd, const UNICHAR *buf, int count) exit(-1); } } else { +#ifdef USE_NCURSES addnstr(str, k); +#endif } } @@ -430,9 +450,11 @@ void input_handler(int *plterm) for (;;) { /* Read a character from TTY (raw mode) */ if (ncursesFlag) { +#ifdef USE_NCURSES ch = getch(); if (ch == '\r') ch = '\n'; +#endif } else { ch = getchar(); } @@ -478,7 +500,9 @@ void *output_handler(void *arg) UNISTYLE style[MAXCOL]; int n_read, opcodes, opvals, buf_row, buf_col, cursor_row, cursor_col; int xmax, ymax, x, y, c; +#ifdef USE_NCURSES MEVENT mev; +#endif if (errDevice != NULL) fprintf(stderr, "output_handler-00: thread ID = %d, LTERM=%d\n", @@ -486,7 +510,9 @@ void *output_handler(void *arg) /* Get screen size */ if (ncursesFlag) { +#ifdef USE_NCURSES getmaxyx(stdscr, ymax, xmax); +#endif } else { ymax = 24; @@ -546,6 +572,7 @@ void *output_handler(void *arg) if (ncursesFlag) { /* NCURSES mode */ +#ifdef USE_NCURSES if (opcodes & LTERM_CLEAR_CODE) { clear(); @@ -592,6 +619,7 @@ void *output_handler(void *arg) move(ymax-1-cursor_row, cursor_col); refresh(); +#endif /* USE_NCURSES */ } else { /* XTERM MODE */ @@ -653,6 +681,7 @@ void *output_handler(void *arg) if (ncursesFlag) { /* NCURSES mode */ +#ifdef USE_NCURSES /* Move cursor to bottom of screen, clear line and display line */ move(ymax-1,0); clrtoeol(); @@ -667,6 +696,7 @@ void *output_handler(void *arg) } refresh(); +#endif /* USE_NCURSES */ } else { /* Screen mode */ diff --git a/mozilla/extensions/xmlterm/linetest/unitest.c b/mozilla/extensions/xmlterm/linetest/unitest.c new file mode 100644 index 00000000000..c60de08511c --- /dev/null +++ b/mozilla/extensions/xmlterm/linetest/unitest.c @@ -0,0 +1,211 @@ +/* unitest.c: Test driver for Unicode strings module unistring.c */ + +/* public declarations */ +#include "unistring.h" + +#include + +int main(int argc, char *argv[]) +{ + UNICHAR dest[6], dest2[6]; + + printf("\nTesting ucscopy and ucslen ...\n"); + + ucscopy(dest, "abcdef", 0); + printf("ucscopy(dest, \"abcdef\", 0)\n"); + + ucscopy(dest, "abcdef", 6); + printf("ucscopy(dest, \"abcdef\", 6): dest="); + ucsprint(stdout, dest, 6); + printf(" (abcdef)\n"); + + ucscopy(dest, "", 6); + printf("ucscopy(dest, \"\", 6): dest="); + ucsprint(stdout, dest, 6); + printf(" (^@^@^@^@^@^@)\n"); + + printf("ucslen(dest) = %d (0)\n", ucslen(dest)); + + ucscopy(dest, "babc", 6); + printf("ucscopy(dest, \"babc\", 6): dest="); + ucsprint(stdout, dest, 6); + printf(" (babc^@^@)\n"); + + printf("ucslen(dest) = %d (4)\n", ucslen(dest)); + + printf("\nTesting ucschr ...\n"); + + printf("*ucschr(\"babc\", U_NUL) = '%c',%d ('',4)\n", + (char) *ucschr(dest, U_NUL), ucschr(dest, U_NUL)-dest); + + printf("*ucschr(\"babc\", U_b_CHAR) = '%c',%d ('b',0)\n", + (char) *ucschr(dest, U_b_CHAR), ucschr(dest, U_b_CHAR)-dest); + + printf("*ucschr(\"babc\", U_a_CHAR) = '%c',%d ('a',1)\n", + (char) *ucschr(dest, U_a_CHAR), ucschr(dest, U_a_CHAR)-dest); + + printf("*ucschr(\"babc\", U_c_CHAR) = '%c',%d ('c',3)\n", + (char) *ucschr(dest, U_c_CHAR), ucschr(dest, U_c_CHAR)-dest); + + printf("ucschr(\"babc\", U_d_CHAR) = 0x%x (0x0)\n", ucschr(dest, U_d_CHAR)); + + printf("\nTesting ucsrchr ...\n"); + + printf("*ucsrchr(\"babc\", U_NUL) = '%c',%d ('',4)\n", + (char) *ucsrchr(dest, U_NUL), ucsrchr(dest, U_NUL)-dest); + + printf("*ucsrchr(\"babc\", U_b_CHAR) = '%c',%d ('b',2)\n", + (char) *ucsrchr(dest, U_b_CHAR), ucsrchr(dest, U_b_CHAR)-dest); + + printf("*ucsrchr(\"babc\", U_a_CHAR) = '%c', %d ('a',1)\n", + (char) *ucsrchr(dest, U_a_CHAR), ucsrchr(dest, U_a_CHAR)-dest); + + printf("*ucschr(\"babc\", U_c_CHAR) = '%c',%d ('c',3)\n", + (char) *ucschr(dest, U_c_CHAR), ucschr(dest, U_c_CHAR)-dest); + + printf("ucsrchr(\"babc\", U_d_CHAR) = 0x%x (0x0)\n", ucsrchr(dest, U_d_CHAR)); + + printf("\nTesting ucscmp ...\n"); + ucscopy(dest, "", 6); + ucscopy(dest2, "", 6); + printf("ucscmp(\"\",\"\") = %d (0)\n", ucscmp(dest,dest)); + + ucscopy(dest, "abc", 6); + printf("ucscmp(\"abc\",\"\") = %d (97)\n", ucscmp(dest,dest2)); + printf("ucscmp(\"\",\"abc\") = %d (-97)\n", ucscmp(dest2,dest)); + + ucscopy(dest2, "abe", 6); + printf("ucscmp(\"abc\",\"abc\") = %d (0)\n", ucscmp(dest,dest)); + printf("ucscmp(\"abc\",\"abe\") = %d (-2)\n", ucscmp(dest,dest2)); + printf("ucscmp(\"abe\",\"abc\") = %d (2)\n", ucscmp(dest2,dest)); + + ucscopy(dest2, "abcd", 6); + printf("ucscmp(\"abc\",\"abcd\") = %d (-100)\n", ucscmp(dest,dest2)); + printf("ucscmp(\"abcd\",\"abc\") = %d (100)\n", ucscmp(dest2,dest)); + + printf("\nTesting ucsncmp ...\n"); + ucscopy(dest, "", 6); + ucscopy(dest2, "", 6); + printf("ucsncmp(\"\",\"\",6) = %d (0)\n", ucsncmp(dest,dest,6)); + + ucscopy(dest, "abc", 6); + printf("ucsncmp(\"abc\",\"\",6) = %d (97)\n", ucsncmp(dest,dest2,6)); + printf("ucsncmp(\"\",\"abc\",6) = %d (-97)\n", ucsncmp(dest2,dest,6)); + + ucscopy(dest2, "abe", 6); + printf("ucsncmp(\"abc\",\"abc\",4) = %d (0)\n", ucsncmp(dest,dest,4)); + printf("ucsncmp(\"abc\",\"abc\",3) = %d (0)\n", ucsncmp(dest,dest,3)); + + printf("ucsncmp(\"abc\",\"abe\",5) = %d (-2)\n", ucsncmp(dest,dest2,5)); + printf("ucsncmp(\"abc\",\"abe\",4) = %d (-2)\n", ucsncmp(dest,dest2,4)); + printf("ucsncmp(\"abc\",\"abe\",3) = %d (-2)\n", ucsncmp(dest,dest2,3)); + printf("ucsncmp(\"abc\",\"abe\",2) = %d (0)\n", ucsncmp(dest,dest2,2)); + printf("ucsncmp(\"abc\",\"abe\",1) = %d (0)\n", ucsncmp(dest,dest2,1)); + printf("ucsncmp(\"abc\",\"abe\",0) = %d (0)\n", ucsncmp(dest,dest2,0)); + + printf("ucsncmp(\"abe\",\"abc\",4) = %d (2)\n", ucsncmp(dest2,dest,4)); + printf("ucsncmp(\"abe\",\"abc\",3) = %d (2)\n", ucsncmp(dest2,dest,3)); + + ucscopy(dest, "abcde", 6); + printf("ucsncmp(\"abcde\",\"abe\",2) = %d (0)\n", ucsncmp(dest,dest2,2)); + printf("ucsncmp(\"abcde\",\"abe\",3) = %d (-2)\n", ucsncmp(dest,dest2,3)); + printf("ucsncmp(\"abcde\",\"abe\",4) = %d (-2)\n", ucsncmp(dest,dest2,4)); + printf("ucsncmp(\"abe\",\"abcde\",2) = %d (0)\n", ucsncmp(dest2,dest,2)); + printf("ucsncmp(\"abe\",\"abcde\",6) = %d (2)\n", ucsncmp(dest2,dest,6)); + + printf("\nTesting ucsncpy ...\n"); + ucscopy(dest2, "abcde", 5); + + ucsncpy(dest, dest2, 0); + printf("ucsncpy(dest, \"abcde\", 0)\n"); + + ucsncpy(dest, dest2, 5); + printf("ucsncpy(dest, \"abcde\", 5): dest="); + ucsprint(stdout, dest, 5); + printf(" (abcde)\n"); + + ucscopy(dest2, "", 6); + ucsncpy(dest, dest2, 5); + printf("ucsncpy(dest, \"\", 5): dest="); + ucsprint(stdout, dest, 5); + printf(" (^@^@^@^@^@)\n"); + + ucscopy(dest2, "bab", 6); + ucsncpy(dest, dest2, 5); + printf("ucsncpy(dest, \"bab\", 5): dest="); + ucsprint(stdout, dest, 5); + printf(" (bab^@^@)\n"); + + printf("\nTesting ucsstr ...\n"); + ucscopy(dest, "abc", 6); + ucscopy(dest2, "", 6); + printf("ucsstr(\"abc\",\"\") = %d (0)\n", ucsstr(dest, dest2)-dest); + ucscopy(dest2, "a", 6); + printf("ucsstr(\"abc\",\"a\") = %d (0)\n", ucsstr(dest, dest2)-dest); + ucscopy(dest2, "ab", 6); + printf("ucsstr(\"abc\",\"ab\") = %d (0)\n", ucsstr(dest, dest2)-dest); + ucscopy(dest2, "abc", 6); + printf("ucsstr(\"abc\",\"abc\") = %d (0)\n", ucsstr(dest, dest2)-dest); + ucscopy(dest2, "bc", 6); + printf("ucsstr(\"abc\",\"bc\") = %d (1)\n", ucsstr(dest, dest2)-dest); + ucscopy(dest2, "c", 6); + printf("ucsstr(\"abc\",\"c\") = %d (2)\n", ucsstr(dest, dest2)-dest); + ucscopy(dest2, "d", 6); + printf("ucsstr(\"abc\",\"d\") = 0x%x (0x0)\n", ucsstr(dest, dest2)); + ucscopy(dest2, "ac", 6); + printf("ucsstr(\"abc\",\"ac\") = 0x%x (0x0)\n", ucsstr(dest, dest2)); + ucscopy(dest2, "acb", 6); + printf("ucsstr(\"abc\",\"acb\") = 0x%x (0x0)\n", ucsstr(dest, dest2)); + ucscopy(dest2, "abcd", 6); + printf("ucsstr(\"abc\",\"abcd\") = 0x%x (0x0)\n", ucsstr(dest, dest2)); + + printf("\nTesting ucsspn ...\n"); + ucscopy(dest, "babc", 6); + ucscopy(dest2, "", 6); + printf("ucsspn(\"babc\",\"\") = %d (0)\n", ucsspn(dest, dest2)); + ucscopy(dest2, "b", 6); + printf("ucsspn(\"babc\",\"b\") = %d (1)\n", ucsspn(dest, dest2)); + ucscopy(dest2, "ab", 6); + printf("ucsspn(\"babc\",\"ab\") = %d (3)\n", ucsspn(dest, dest2)); + ucscopy(dest2, "abc", 6); + printf("ucsspn(\"babc\",\"abc\") = %d (4)\n", ucsspn(dest, dest2)); + ucscopy(dest2, "cba", 6); + printf("ucsspn(\"babc\",\"cba\") = %d (4)\n", ucsspn(dest, dest2)); + ucscopy(dest2, "abcd", 6); + printf("ucsspn(\"babc\",\"abcd\") = %d (4)\n", ucsspn(dest, dest2)); + ucscopy(dest2, "abcde", 6); + printf("ucsspn(\"babc\",\"abcde\") = %d (4)\n", ucsspn(dest, dest2)); + ucscopy(dest2, "c", 6); + printf("ucsspn(\"babc\",\"c\") = %d (0)\n", ucsspn(dest, dest2)); + ucscopy(dest2, "d", 6); + printf("ucsspn(\"babc\",\"d\") = %d (0)\n", ucsspn(dest, dest2)); + ucscopy(dest2, "cd", 6); + printf("ucsspn(\"babc\",\"cd\") = %d (0)\n", ucsspn(dest, dest2)); + + printf("\nTesting ucscspn ...\n"); + ucscopy(dest, "babc", 6); + ucscopy(dest2, "", 6); + printf("ucscspn(\"babc\",\"\") = %d (4)\n", ucscspn(dest, dest2)); + ucscopy(dest2, "b", 6); + printf("ucscspn(\"babc\",\"b\") = %d (0)\n", ucscspn(dest, dest2)); + ucscopy(dest2, "ab", 6); + printf("ucscspn(\"babc\",\"ab\") = %d (0)\n", ucscspn(dest, dest2)); + ucscopy(dest2, "abc", 6); + printf("ucscspn(\"babc\",\"abc\") = %d (0)\n", ucscspn(dest, dest2)); + ucscopy(dest2, "cba", 6); + printf("ucscspn(\"babc\",\"cba\") = %d (0)\n", ucscspn(dest, dest2)); + ucscopy(dest2, "abcd", 6); + printf("ucscspn(\"babc\",\"abcd\") = %d (0)\n", ucscspn(dest, dest2)); + ucscopy(dest2, "abcde", 6); + printf("ucscspn(\"babc\",\"abcde\") = %d (0)\n", ucscspn(dest, dest2)); + ucscopy(dest2, "a", 6); + printf("ucscspn(\"babc\",\"a\") = %d (1)\n", ucscspn(dest, dest2)); + ucscopy(dest2, "c", 6); + printf("ucscspn(\"babc\",\"c\") = %d (3)\n", ucscspn(dest, dest2)); + ucscopy(dest2, "cd", 6); + printf("ucscspn(\"babc\",\"cd\") = %d (3)\n", ucscspn(dest, dest2)); + ucscopy(dest2, "d", 6); + printf("ucscspn(\"babc\",\"d\") = %d (4)\n", ucscspn(dest, dest2)); + + return; +} diff --git a/mozilla/extensions/xmlterm/linetest/testunistr.c b/mozilla/extensions/xmlterm/linetest/utf8conv.c similarity index 96% rename from mozilla/extensions/xmlterm/linetest/testunistr.c rename to mozilla/extensions/xmlterm/linetest/utf8conv.c index afe996e1048..9d6c1a474d6 100644 --- a/mozilla/extensions/xmlterm/linetest/testunistr.c +++ b/mozilla/extensions/xmlterm/linetest/utf8conv.c @@ -1,9 +1,9 @@ -/* testunistr.c: Test driver for Unicode strings module unistring.c */ +/* utf8conv.c: Test driver for UTF8 conversions in unistring.c */ /* public declarations */ #include "unistring.h" -#include "assert.h" +#include int main(int argc, char *argv[]) {