зеркало из https://github.com/mozilla/pjs.git
Initial import of XMLterm extension; not part of default SeaMonkey build
This commit is contained in:
Родитель
dcfd9fd8a9
Коммит
611390ef85
|
@ -0,0 +1 @@
|
|||
Makefile
|
|
@ -0,0 +1,170 @@
|
|||
INSTALL: Installation instructions for XMLterm source code
|
||||
----------------------------------------------------------
|
||||
|
||||
*NOTE* This is work in progress. User beware!
|
||||
|
||||
*NOTE* Check the XMLterm web site <http://xmlterm.org> for updates.
|
||||
|
||||
29 Nov 1999
|
||||
|
||||
In the following discussion, file and directory names are relative
|
||||
to the main ("mozilla/extensions/xmlterm") directory. See the end of the
|
||||
README file for a brief description of the subdirectories.
|
||||
|
||||
|
||||
1. Source tree (skip this step if XMLterm is already in the source tree)
|
||||
------------------------------------------------------------------------
|
||||
|
||||
The XMLterm source code is distributed as a tarball, xmlterm.tar.gz
|
||||
|
||||
This tar file needs to be untarred in the "mozilla/extensions" directory,
|
||||
or any any other "mozilla/dir" directory one level below the top-level.
|
||||
A subdirectory called "xmlterm" will be created there.
|
||||
("mozilla" denotes the root directory of the Mozilla source tree)
|
||||
|
||||
If you have already untarred it elsewhere, simply move the "xmlterm" directory
|
||||
to the right place.
|
||||
|
||||
|
||||
2. Configuration
|
||||
----------------
|
||||
|
||||
To recursively create all Makefiles from Makefile.in files, type the following:
|
||||
|
||||
makemake -r
|
||||
|
||||
The file "config/xmlterm_config.mk" contains XMLterm specific configuration
|
||||
information that is needed in addition to any Mozilla configuration
|
||||
information. It has already been hand-configured for Linux2.0/Linux2.2, and
|
||||
Solaris2.6 platforms. It may need to be modified slightly to compile XMLterm
|
||||
on other platforms.
|
||||
|
||||
At present XMLterm has been tested only on Linux (RedHat6.0) and Solaris2.6
|
||||
platforms, using the M11 release as the base version of Mozilla.
|
||||
|
||||
XMLterm typically uses the UNIX pseudo-TTY interface to communicate with the
|
||||
shell. At present, this interface is implemented only for Linux and Solaris
|
||||
platforms.
|
||||
|
||||
XMLterm may compile on other Unix platforms, but it will use NSPR pipes,
|
||||
rather than a pseudo-TTY, for process communication; this means that the
|
||||
terminal control characters, such as Control-C for interrupting jobs, will not
|
||||
work on those platforms. (See the file doc/PORTABILITY for a discussion of
|
||||
portability issues)
|
||||
|
||||
|
||||
3. Creating the dynamically loaded XPCOM/XPCONNECT component
|
||||
------------------------------------------------------------
|
||||
|
||||
To create the dynamically loaded XPCOM library, type the following in the main
|
||||
directory
|
||||
|
||||
make all
|
||||
|
||||
This creates the self-registering library "libxmlterm.so" and installs it in
|
||||
the "mozilla/dist/bin/components" directory, along with some chrome
|
||||
files. After this step, the following interfaces become accessible in Mozilla
|
||||
through XPCOM/XPCONNECT:
|
||||
|
||||
mozIXMLTermShell (interface to XMLterm)
|
||||
mozILineTerm (interface to the stand-alone LINETERM)
|
||||
|
||||
To clean up completely, type
|
||||
|
||||
make clean
|
||||
|
||||
|
||||
4. Using the lightweight "xmlterm" stand-alone program
|
||||
----------------------------------------------------
|
||||
|
||||
Step 3 creates an executable called "xmlterm" in the "mozilla/dist/bin"
|
||||
directory. This is a lightweight program implementing XMLterm using the Gecko
|
||||
layout engine only, without the added baggage of the full browser. Executing
|
||||
"xmlterm" will create an XMLterm window. Click on this window to give it focus
|
||||
before typing Unix commands.
|
||||
|
||||
The command line can be edited using EMACS-style key bindings.
|
||||
Command completion should also work with TCSH and BASH, as should history
|
||||
recall.
|
||||
|
||||
**NOTE**
|
||||
The command prompt is assumed to be terminated by one of the characters
|
||||
"#$%>?", followed by a space. If this is not the case, many features will not
|
||||
work. This restriction will be relaxed in the future.
|
||||
|
||||
By default, blue coloring is used to indicate clickable display elements.
|
||||
Note that the prompt and the input command line are clickable.
|
||||
(Of course, the appearance of XMLterm is completely configurable
|
||||
using the CSS stylesheet chrome://xmlterm/skin/default/xmlterm.css)
|
||||
|
||||
After typing one or two commands, click on the prompt string of any previous
|
||||
command to see what happens! Then click again on the same prompt string.
|
||||
Also click on "Hide all output" button at the top of the document.
|
||||
|
||||
Clicking on a previous command line (to the right of the prompt) re-executes
|
||||
the command.
|
||||
|
||||
The sample Perl script "xls", the iconic/hypertext version of the Unix "ls"
|
||||
command, is in the "tests" directory. Copy it to some directory in your path
|
||||
to use it.
|
||||
|
||||
Note: At present, xmlterm only works with the GTK front end.
|
||||
|
||||
|
||||
5. Creating an XMLterm window using the browser
|
||||
-----------------------------------------------
|
||||
|
||||
At this time, XMLterm cannot be accessed through the menu bar. Instead, load
|
||||
the URL "chrome://xmlterm/content/xmlterm.html" in the browser, either at the
|
||||
command line or by typing it in the URL box. Then click on the browser window
|
||||
with the mouse to shift focus and then start typing UNIX commands.
|
||||
|
||||
|
||||
6. Stand-alone mode (optional)
|
||||
------------------------------
|
||||
|
||||
Although XMLterm resides in the Mozilla source tree, portions of it are
|
||||
capable of being compiled and linked completely independent of Mozilla. You
|
||||
may want to do this for testing purposes. The "config" directory contains
|
||||
make files that are used for this stand-alone mode. There is even a dumb
|
||||
script called "makemake" which can be used to re-create make files, if the
|
||||
corresponding Makefile.in files have been changed.
|
||||
|
||||
*NOTE* The executable "lterm" requires the NCURSES include file "curses.h"
|
||||
|
||||
To create the stand-alone executables, type
|
||||
|
||||
make STAND_ALONE=1 all
|
||||
|
||||
(To clean up stand-alone modules, type "make STAND_ALONE=1 clean")
|
||||
|
||||
This creates the stand-alone library in "base/lib" and some stand-alone
|
||||
executables in the "linetest/lib" directory, in particular, one called
|
||||
"lterm".
|
||||
|
||||
The executable "lterm" implements a line terminal (LINETERM), i.e., a
|
||||
non-graphical version of XMLterm. In the future, this may be implemented using
|
||||
NCURSES for full screen operation. At present, it only provides line-at-a-time
|
||||
functionality and is used only for testing.
|
||||
|
||||
LINETERM acts as an "engine" for XMLterm, carrying out all the non-graphical
|
||||
tasks, completely independent of Mozilla. It is written in C and is licensed
|
||||
under both MPL and GPL. It provides functionality similar to the EMACS shell
|
||||
mode or the GNU readline package.
|
||||
|
||||
LINETERM has various options where trace output may be redirected to a
|
||||
different TTY device, for debugging purposes. LINETERM may be used like the
|
||||
shell command "sh", e.g.,
|
||||
|
||||
prompt% lterm
|
||||
prompt% ls
|
||||
<listing>
|
||||
prompt% exit
|
||||
|
||||
The "tests/escape" program can be used to generate terminal escape sequences
|
||||
to test the XMLterm API. In particular, the following command enables
|
||||
extensive trace output, if executed within an XMLterm or LINETERM:
|
||||
|
||||
tests/escape 1 98 D
|
||||
|
||||
-----------------------------------------------------------------------------
|
|
@ -0,0 +1,78 @@
|
|||
#!gmake
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# makefile for xmlterm root directory
|
||||
|
||||
ifdef STAND_ALONE
|
||||
DEPTH = .
|
||||
topsrcdir = .
|
||||
srcdir = .
|
||||
include $(topsrcdir)/config/autoconf.mk
|
||||
else
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
endif
|
||||
|
||||
|
||||
# Debug option
|
||||
DEBUG = 1
|
||||
|
||||
|
||||
ifdef STAND_ALONE
|
||||
|
||||
DIRS = base tests linetest
|
||||
|
||||
else # not STAND_ALONE
|
||||
|
||||
DIRS = base ui geckoterm tests
|
||||
|
||||
LIBRARY_NAME =
|
||||
|
||||
# Exported header files
|
||||
EXPORTS =
|
||||
|
||||
# Defines
|
||||
DEFINES =
|
||||
|
||||
# C++ Sources
|
||||
CPPSRCS =
|
||||
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include config/xmlterm_config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,63 @@
|
|||
xmlterm --- A graphical command line interface
|
||||
==============================================
|
||||
|
||||
An early prototype of XMLterm, an XTERM-like terminal program implemented
|
||||
using the open source Mozilla layout engine, is now available to tinker
|
||||
with. XMLterm aims to add graphical and hypertext capabilities to the XTERM
|
||||
command line interface, while maintaining backwards compatibility.
|
||||
|
||||
The basic design philosophy of XMLterm is that the user interface is a dynamic
|
||||
XML document. The user and the computer interact by taking turns at appending
|
||||
to this XML document. The plain text content of the XML document, i.e.,
|
||||
excluding any markup, corresponds to the plain text that would be displayed by
|
||||
a plain XTERM. The markup in the XML document is used to add graphical and
|
||||
hypertext features. XMLterm uses the Mozilla layout engine to display the XML
|
||||
document.
|
||||
|
||||
XMLterm is an open source project in its early stages. Comments and
|
||||
contributions are welcome!
|
||||
|
||||
R. Saravanan <svn@xmlterm.org>
|
||||
28 Nov 1999
|
||||
===========
|
||||
|
||||
NOTES:
|
||||
|
||||
1. See the INSTALL file for configuration/installation instructions.
|
||||
|
||||
2. See the file doc/INSTALL.xmlterm for binary installation instructions.
|
||||
|
||||
3. Check the XMLterm web site <http://xmlterm.org> for updates.
|
||||
|
||||
===========================================================================
|
||||
DOCUMENTATION
|
||||
|
||||
a. There is a README file in each directory that provides some basic
|
||||
information.
|
||||
|
||||
b. The file "base/README" provides a brief overview of the XMLterm code
|
||||
architecture.
|
||||
|
||||
c. The header files (*.idl, *.h) have comments describing class methods
|
||||
and member variables in JAVADOC format. Look at them before delving
|
||||
into the *.cpp files
|
||||
|
||||
===========================================================================
|
||||
FILES:
|
||||
|
||||
INSTALL installation instructions
|
||||
README this file
|
||||
UUID.txt list of UUIDs used by XMLterm
|
||||
|
||||
The main subdirectories of the "xmlterm" directory are:
|
||||
|
||||
base/ base source code for XMLterm libraries
|
||||
config/ make rules for stand-alone mode
|
||||
dist/ holds include and library file for stand-alone LineTerm only
|
||||
doc/ some documentation
|
||||
geckoterm/ lightweight XMLterm executable
|
||||
linetest/ stand-alone line terminal testing executables
|
||||
tests/ XMLterm test programs and scripts, including "pagelets"
|
||||
ui/* user interface/chrome files
|
||||
|
||||
--
|
|
@ -0,0 +1,28 @@
|
|||
UUID.txt: UUIDs used by XMLTerm
|
||||
-------------------------------
|
||||
|
||||
2 Dec 1999
|
||||
|
||||
A block of 256 UUIDs was generated by running uuidgen,
|
||||
ranging from
|
||||
/* 0eb82b00-43a2-11d3-8e76-006008948af5 */
|
||||
to
|
||||
/* 0eb82bff-43a2-11d3-8e76-006008948af5 */
|
||||
with the 7th and 8th hex digits varying from 00 to ff.
|
||||
|
||||
Of these, the following UUIDs are being used as IIDs and CIDs:
|
||||
|
||||
mozILineTerm IID "0eb82b00-43a2-11d3-8e76-006008948af5"
|
||||
mozLineTerm CID "0eb82b01-43a2-11d3-8e76-006008948af5"
|
||||
mozILineTermAux IID "0eb82b10-43a2-11d3-8e76-006008948af5"
|
||||
mozIXMLTerminal IID "0eb82b20-43a2-11d3-8e76-006008948af5"
|
||||
mozXMLTerminal CID "0eb82b21-43a2-11d3-8e76-006008948af5"
|
||||
mozIXMLTermShell IID "0eb82b30-43a2-11d3-8e76-006008948af5"
|
||||
mozXMLTermShell CID "0eb82b31-43a2-11d3-8e76-006008948af5"
|
||||
mozIXMLTermStream IID "0eb82b40-43a2-11d3-8e76-006008948af5"
|
||||
mozXMLTermStream CID "0eb82b41-43a2-11d3-8e76-006008948af5"
|
||||
|
||||
mozISimpleContainer IID "0eb82bF0-43a2-11d3-8e76-006008948af5"
|
||||
mozSimpleContainer CID "0eb82bF1-43a2-11d3-8e76-006008948af5"
|
||||
|
||||
--
|
|
@ -0,0 +1,120 @@
|
|||
#!gmake
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# makefile for xmlterm/base directory
|
||||
|
||||
ifdef STAND_ALONE
|
||||
DEPTH = ..
|
||||
topsrcdir = ..
|
||||
srcdir = .
|
||||
include $(topsrcdir)/config/autoconf.mk
|
||||
else
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
endif
|
||||
|
||||
|
||||
# Debug option
|
||||
DEBUG = 1
|
||||
|
||||
# Library name
|
||||
LIBRARY_NAME = xmlterm
|
||||
|
||||
# C Sources
|
||||
ifdef NO_PTY
|
||||
CSRCS = ltermManager.c ltermIO.c ltermInput.c ltermOutput.c ltermEscape.c \
|
||||
tracelog.c unistring.c
|
||||
else
|
||||
CSRCS = ltermManager.c ltermIO.c ltermInput.c ltermOutput.c ltermEscape.c \
|
||||
tracelog.c unistring.c ptystream.c
|
||||
endif
|
||||
|
||||
ifdef STAND_ALONE
|
||||
# Defines
|
||||
DEFINES +=
|
||||
|
||||
# Exported header files
|
||||
EXPORTS = lineterm.h tracelog.h unistring.h ptystream.h
|
||||
|
||||
# C++ Sources
|
||||
CPPSRCS =
|
||||
|
||||
else # not STAND_ALONE
|
||||
# Defines
|
||||
DEFINES += $(TK_CFLAGS)
|
||||
|
||||
# Exported header files (excluding XPCONNECT interfaces)
|
||||
EXPORTS = lineterm.h tracelog.h unistring.h ptystream.h mozXMLT.h mozXMLTermUtils.h mozIXMLTerminal.h mozIXMLTermStream.h
|
||||
|
||||
# C++ Sources
|
||||
CPPSRCS = \
|
||||
mozLineTerm.cpp \
|
||||
mozXMLTermUtils.cpp \
|
||||
mozXMLTerminal.cpp \
|
||||
mozXMLTermSession.cpp \
|
||||
mozXMLTermListeners.cpp \
|
||||
mozXMLTermShell.cpp \
|
||||
mozXMLTermFactory.cpp \
|
||||
$(NULL)
|
||||
|
||||
MODULE = xmlterm
|
||||
IS_COMPONENT = 1
|
||||
|
||||
EXTRA_DSO_LDOPTS = $(TK_LIBS) \
|
||||
-L$(DIST)/bin $(NSPR_LIBS) \
|
||||
-L$(DIST)/bin -lxpcom
|
||||
|
||||
XPIDLSRCS = \
|
||||
mozILineTerm.idl \
|
||||
mozIXMLTermShell.idl \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
# Also create static library libxmlterm.a
|
||||
override NO_STATIC_LIB=
|
||||
|
||||
REQUIRES =
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include ../config/xmlterm_config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
ifndef STAND_ALONE
|
||||
ifeq ($(OS_ARCH),Linux)
|
||||
OS_CFLAGS += -ansi
|
||||
endif
|
||||
endif
|
|
@ -0,0 +1,127 @@
|
|||
base --- core source code for XMLterm and LineTerm
|
||||
|
||||
XMLterm control-flow/layering hierarchy
|
||||
=======================================
|
||||
|
||||
mozilla-executable xmlterm-executable
|
||||
| |
|
||||
../ui/content/xmlterm.html |
|
||||
| |
|
||||
mozXMLTermShell ../geckoterm/mozGeckoTerm
|
||||
| | |
|
||||
+--------------+---------------+ |
|
||||
| mozSimpleContainer
|
||||
mozXMLTerminal
|
||||
|
|
||||
+-------------------+--------------------+
|
||||
| | |
|
||||
mozXMLTermSession mozLineTermAux mozXMLTermListeners
|
||||
| | |
|
||||
| | |
|
||||
mozXMLTermStream... (LineTerm) (user input)
|
||||
(rendering ...) (pseudo-TTY/shell)
|
||||
|
||||
|
||||
XMLterm may be invoked one of two ways:
|
||||
1. By loading the URL chrome://xmlterm/content/xmlterm.html in mozilla, or
|
||||
2. By running the stand-alone executable "../geckoterm/xmlterm".
|
||||
The diagram above shows the control-flow/layering hierarchy for both ways
|
||||
of invoking XMLterm.
|
||||
|
||||
28 Nov 1999
|
||||
===========================================================================
|
||||
FILES:
|
||||
|
||||
The core source code for XMLterm in this directory consists of two distinct
|
||||
families of files, those with names that begin with the prefix "moz" and all
|
||||
the other files. The former are the Mozilla-specific portions of XMLterm,
|
||||
written in C++. The remaining files constitute the Mozilla-independent portion
|
||||
of XMLterm, referred to as "LineTerm".
|
||||
|
||||
============================================================================
|
||||
LINETERM:
|
||||
|
||||
LineTerm is a line-oriented terminal program, in some respects similar in
|
||||
functionality to the GNU Readline package. It is completely independent of the
|
||||
Mozilla source code, is written in plain C, and dually licensed under GPL and
|
||||
MPL.
|
||||
|
||||
============================================================================
|
||||
INTERFACES:
|
||||
|
||||
lineterm.h Plain C interface to LineTerm
|
||||
(used by mozLineTerm)
|
||||
|
||||
mozILineTerm.idl Scriptable XPCOM/XPCONNECT interface to LineTerm
|
||||
(not used at the moment)
|
||||
|
||||
mozILineTermAux.h XPCOM interface to LineTerm, with extra features
|
||||
(used by mozXMLTerminal)
|
||||
|
||||
mozIXMLTermShell.h Scriptable XPCOM/XPCONNECT interface to XMLterm
|
||||
(used by the Javascript glue code in the XMLterm
|
||||
start page at ../ui/content/xmlterm.html)
|
||||
|
||||
mozIXMLTerminal.h XPCOM interface to XMLterm
|
||||
(used by mozXMLTermShell, ../geckoterm/mozGeckoterm)
|
||||
|
||||
mozIXMLTermStream.h XPCOM interface for displaying HTML/XML streams in
|
||||
IFRAMES (used by mozXMLTermSession)
|
||||
|
||||
|
||||
IMPLEMENTATIONS:
|
||||
|
||||
|
||||
mozLineTerm.h/cpp Implementation of mozILineTerm, mozILineTermAux
|
||||
Uses LineTerm to access shell
|
||||
|
||||
mozXMLTermShell.h/cpp Implementation of mozIXMLTermShell
|
||||
Uses mozIXMLTerminal to create XMLterm
|
||||
|
||||
mozXMLTerminal.h/cpp Implementation of mozIXMLTerminal,
|
||||
nsIDocumentLoaderObserver, and
|
||||
nsIObserver
|
||||
Uses mozILineTermAux to create LineTerm
|
||||
Uses mozXMLTermListeners to capture user input
|
||||
Uses mozXMLTermSession to display input/output
|
||||
|
||||
mozXMLTermListeners.h/cpp Implementations of nsIDOMKeyListener,
|
||||
nsIDOMTextListener,
|
||||
nsIDOMMouseListener,
|
||||
nsIDOMDragListener
|
||||
|
||||
mozXMLTermStream.h/cpp Implementation of mozIXMLTermStream
|
||||
|
||||
|
||||
CLASSES:
|
||||
|
||||
|
||||
mozXMLTermSession.h/cpp Class to manage session input/output display
|
||||
(used by mozXMLTerminal)
|
||||
Uses mozIXMLTermStream to display streams
|
||||
|
||||
mozXMLTermUtils.h/cpp Abstract class for static utility functions
|
||||
(for use by all classes)
|
||||
|
||||
============================================================================
|
||||
The following are dually licensed under MPL and GPL:
|
||||
|
||||
LineTerm package:
|
||||
|
||||
lineterm.h Public interface to LineTerm
|
||||
|
||||
ltermPrivate.h Private common header file
|
||||
|
||||
ltermManager.c LineTerm manager
|
||||
ltermIO.c Overlapping I/O functions
|
||||
ltermInput.c Input handler
|
||||
ltermOutput.c Output handler
|
||||
ltermEscape.c Escape sequence handler
|
||||
|
||||
Low-level packages:
|
||||
|
||||
ptystream.h/c Stream-like interface to Unix pseudo-TTY
|
||||
tracelog.h/c Simple tracing/logging diagnostic library
|
||||
unistring.h/c Simple Unicode manipulation library
|
||||
|
||||
============================================================================
|
|
@ -0,0 +1,387 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* lineterm.h: Line terminal (LTERM) public interface header file
|
||||
* LINETERM provides a "stream" interface to an XTERM-like terminal,
|
||||
* using line-oriented input/output.
|
||||
*/
|
||||
|
||||
#ifndef _LINETERM_H
|
||||
|
||||
#define _LINETERM_H 1
|
||||
|
||||
#ifndef _UNISTRING_H
|
||||
#include "unistring.h"
|
||||
#endif
|
||||
|
||||
/* Define LTERM read callback function type */
|
||||
#ifdef USE_GTK_WIDGETS
|
||||
#include <gtk/gtk.h>
|
||||
typedef void (*lterm_callback_func_t)(gpointer, gint, GdkInputCondition);
|
||||
#else
|
||||
typedef void* lterm_callback_func_t;
|
||||
#endif
|
||||
|
||||
/* Unicode character style information (same type as UNICHAR) */
|
||||
typedef UNICHAR UNISTYLE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* lineterm functions */
|
||||
|
||||
/* LTERM module number (used for trace/log operations) */
|
||||
#define LTERM_TLOG_MODULE 1
|
||||
|
||||
/* Initializes all LTERM operations;
|
||||
* needs to be called before any calls to lterm_new.
|
||||
* @return 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.
|
||||
*/
|
||||
|
||||
int lterm_init(int messageLevel);
|
||||
|
||||
|
||||
/** Creates a new LTERM object and returns its descriptor index but
|
||||
* does not open it for I/O
|
||||
* (documented in the LTERM interface)
|
||||
* @return lterm descriptor index (>= 0) on success, or
|
||||
* -1 on error
|
||||
*/
|
||||
|
||||
int lterm_new();
|
||||
|
||||
/* 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.
|
||||
* @return 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)
|
||||
*
|
||||
* 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_NOPARTLINE_FLAG disable returning of partial line output
|
||||
* 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_NOSTDERR_FLAG do not use separate STDERR
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
int lterm_open(int lterm, char *const argv[], const char* cookie,
|
||||
const UNICHAR* prompt_regexp, int options, int process_type,
|
||||
lterm_callback_func_t callback_func, void *callback_data);
|
||||
|
||||
|
||||
/* 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.
|
||||
* @return 0 on success, or -1 on error.
|
||||
*/
|
||||
int lterm_close(int lterm);
|
||||
|
||||
|
||||
/** Deletes an LTERM object, closing it if necessary.
|
||||
* @return 0 on success, or -1 on error.
|
||||
*/
|
||||
|
||||
int lterm_delete(int lterm);
|
||||
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
void lterm_close_all(void);
|
||||
|
||||
|
||||
/* Set input echo flag for line terminal indexed by LTERM.
|
||||
* Called from the output thread of LTERM.
|
||||
* @return 0 on success, or -1 on error.
|
||||
*/
|
||||
|
||||
int lterm_setecho(int lterm, int echo_flag);
|
||||
|
||||
|
||||
/* Resizes the line terminal indexed by LTERM.
|
||||
* Called from the output thread of LTERM.
|
||||
* @return 0 on success, or -1 on error.
|
||||
*/
|
||||
|
||||
int lterm_resize(int lterm, int rows, int cols,
|
||||
int xpix, int ypix);
|
||||
|
||||
|
||||
/* Sets cursor position in line terminal indexed by LTERM.
|
||||
* Called from the output thread of LTERM.
|
||||
* @return 0 on success, or -1 on error.
|
||||
*/
|
||||
|
||||
int lterm_setcursor(int lterm, int row, int col);
|
||||
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
int lterm_write(int lterm, const UNICHAR *buf, int count, int dataType);
|
||||
|
||||
|
||||
/* 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.
|
||||
* @return 0 on success, or -1 on error.
|
||||
*/
|
||||
|
||||
int lterm_metacomplete(int lterm, const UNICHAR *buf, int count);
|
||||
|
||||
|
||||
/* 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? COOKIESTR? XMLSTREAM? DOCSTREAM? WINSTREAM?
|
||||
* if StreamMode data is being returned.
|
||||
*
|
||||
* OPCODES ::= SCREENDATA BELL? ( CLEAR
|
||||
* | INSERT MOVEDOWN?
|
||||
* | DELETE MOVEDOWN?
|
||||
* | OUTPUT )
|
||||
* if ScreenMode data is being returned.
|
||||
*
|
||||
* OPCODES ::= LINEDATA BELL? ( CLEAR
|
||||
* | ( PROMPT | OUTPUT)? INPUT ( NEWLINE HIDE? )?
|
||||
* | PROMPT? INPUT META ( COMPLETION | NEWLINE HIDE? )
|
||||
* | 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.
|
||||
* (If character count returned by lterm_read is zero, implying there is no
|
||||
* data in BUF, then values of BUF_ROW and BUF_COL should be ignored.)
|
||||
* 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.
|
||||
*/
|
||||
|
||||
int lterm_read(int lterm, int timeout, UNICHAR *buf, int count,
|
||||
UNISTYLE *style, int *opcodes,
|
||||
int *buf_row, int *buf_col, int *cursor_row, int *cursor_col);
|
||||
|
||||
/* opcodes describing terminal operations:
|
||||
*/
|
||||
#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 row at cursor */
|
||||
#define LTERM_DELETE_CODE 0x0040U /* Delete row at cursor */
|
||||
#define LTERM_MOVEDOWN_CODE 0x0080U /* Move text down on insert/delete */
|
||||
#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_COOKIESTR_CODE 0x8000U /* Stream prefixed with cookie */
|
||||
#define LTERM_XMLSTREAM_CODE 0x10000U /* Stream contains XML, not HTML */
|
||||
#define LTERM_DOCSTREAM_CODE 0x20000U /* Stream contains complete document */
|
||||
#define LTERM_WINSTREAM_CODE 0x40000U /* Display stream in entire window */
|
||||
|
||||
|
||||
/* LTERM/XTERM 16-bit style mask:
|
||||
* PROMPT, STDIN, STDOUT, STDERR, ALTOUT are mutually exclusive.
|
||||
* The markup styles apply to STDIN/STDOUT/ALTOUT data.
|
||||
* The highlighting styles only apply to STDOUT data.
|
||||
* The VT100 foreground and background styles are not implemented.
|
||||
*/
|
||||
|
||||
#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_DIM_STYLE 0x0800UL /* inverse video */
|
||||
|
||||
/* LTERM option flags */
|
||||
#define LTERM_NOCANONICAL_FLAG 0x0001U
|
||||
#define LTERM_NOEDIT_FLAG 0x0002U
|
||||
#define LTERM_NOCOMPLETION_FLAG 0x0004U
|
||||
#define LTERM_NOMETA_FLAG 0x0008U
|
||||
#define LTERM_NOPARTLINE_FLAG 0x0010U
|
||||
#define LTERM_NOECHO_FLAG 0x0020U
|
||||
#define LTERM_NOMARKUP_FLAG 0x0040U
|
||||
#define LTERM_NOPTY_FLAG 0x0080U
|
||||
#define LTERM_NOSTDERR_FLAG 0x0100U
|
||||
#define LTERM_NONUL_FLAG 0x0200U
|
||||
#define LTERM_NOLINEWRAP_FLAG 0x0400U
|
||||
#define LTERM_NOEXPORT_FLAG 0x0800U
|
||||
|
||||
/* Process type codes */
|
||||
#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 */
|
||||
|
||||
/* lterm_write data type codes (XML server output not permitted) */
|
||||
#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 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LINETERM_H */
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,829 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* ltermInput.c: LTERM PTY input data processing
|
||||
*/
|
||||
|
||||
/* public declarations */
|
||||
#include "lineterm.h"
|
||||
|
||||
/* private declarations */
|
||||
#include "ltermPrivate.h"
|
||||
|
||||
|
||||
static int ltermLineInput(struct lterms *lts, const UNICHAR *buf, int count,
|
||||
int *opcodes);
|
||||
static int ltermMetaInput(struct lterms *lts);
|
||||
static int ltermRequestCompletion(struct lterms *lts, UNICHAR uch);
|
||||
|
||||
|
||||
/** Processes plain text input data and returns
|
||||
* OPCODES ::= LINEDATA ( INPUT ( NEWLINE HIDE? )?
|
||||
* | INPUT META ( COMPLETION | NEWLINE HIDE? ) )
|
||||
* if echoable input data was processed.
|
||||
* (OPCODES is set to zero if raw input data was processed)
|
||||
* Called from ltermWrite
|
||||
* @return 0 on success,
|
||||
* -1 on error, and
|
||||
* -2 if pseudo-TTY has been closed.
|
||||
*/
|
||||
int ltermPlainTextInput(struct lterms *lts,
|
||||
const UNICHAR *buf, int count, int *opcodes)
|
||||
{
|
||||
struct LtermInput *lti = &(lts->ltermInput);
|
||||
int returnCode;
|
||||
|
||||
LTERM_LOG(ltermPlainTextInput,20,
|
||||
("start lti->inputMode=%d\n", lti->inputMode));
|
||||
|
||||
if (lti->inputMode == LTERM0_RAW_MODE) {
|
||||
/* Transmit characters immediately to child process; no buffering */
|
||||
|
||||
LTERM_LOG(ltermPlainTextInput,29,
|
||||
("Raw mode, transmitting %d characters\n",
|
||||
count));
|
||||
|
||||
if (ltermSendData(lts, buf, count) != 0)
|
||||
return -1;
|
||||
|
||||
*opcodes = 0;
|
||||
|
||||
} else {
|
||||
/* Not raw input mode; process line mode input */
|
||||
int processTrailingTab = 0;
|
||||
|
||||
LTERM_LOG(ltermPlainTextInput,21,
|
||||
("Line mode, lts->commandNumber=%d, inputMode=%d\n",
|
||||
lts->commandNumber, lti->inputMode));
|
||||
|
||||
if ((lti->inputMode >= LTERM3_COMPLETION_MODE) &&
|
||||
(lts->commandNumber == 0)) {
|
||||
/* Downgrade input mode */
|
||||
lti->inputMode = LTERM2_EDIT_MODE;
|
||||
|
||||
LTERM_LOG(ltermPlainTextInput,21,
|
||||
("------------ Downgraded input mode=%d\n\n",
|
||||
lti->inputMode));
|
||||
|
||||
} else if ((lti->inputMode < lts->maxInputMode) &&
|
||||
(lts->commandNumber != 0)) {
|
||||
/* Upgrade input mode */
|
||||
int priorInputMode = lti->inputMode;
|
||||
|
||||
/* Set input mode (possibly allowing completion) */
|
||||
lti->inputMode = lts->maxInputMode;
|
||||
|
||||
/* Do not allow command completion without TTY echo */
|
||||
if ( (lts->disabledInputEcho || lts->noTTYEcho) &&
|
||||
(lti->inputMode > LTERM2_EDIT_MODE) )
|
||||
lti->inputMode = LTERM2_EDIT_MODE;
|
||||
|
||||
if ((lti->inputChars > 0) &&
|
||||
(priorInputMode < LTERM3_COMPLETION_MODE) &&
|
||||
(lti->inputMode >= LTERM3_COMPLETION_MODE)) {
|
||||
/* Process prior input TABs before switching to completion mode */
|
||||
int j;
|
||||
|
||||
if ((count == 0) &&
|
||||
(lti->inputCursorGlyph == lti->inputGlyphs) &&
|
||||
(lti->inputGlyphColIndex[lti->inputGlyphs] == lti->inputCols) &&
|
||||
(lti->inputColCharIndex[lti->inputCols] == lti->inputChars) &&
|
||||
(lti->inputLine[lti->inputChars] == U_TAB)) {
|
||||
/* Trailing TAB in prior input; delete it, and process it later */
|
||||
if (ltermDeleteGlyphs(lti, 1) != 0)
|
||||
return -1;
|
||||
processTrailingTab = 1;
|
||||
}
|
||||
|
||||
/* Replace all input TABs with spaces */
|
||||
for (j=0; j < lti->inputChars; j++) {
|
||||
if (lti->inputLine[j] == U_TAB)
|
||||
lti->inputLine[j] = U_SPACE;
|
||||
}
|
||||
}
|
||||
|
||||
LTERM_LOG(ltermPlainTextInput,21,
|
||||
("------------ Upgraded input mode=%d, trailingTab=%d\n\n",
|
||||
lti->inputMode, processTrailingTab));
|
||||
|
||||
}
|
||||
|
||||
if (processTrailingTab) {
|
||||
/* Re-process trailing TAB */
|
||||
UNICHAR uch = U_TAB;
|
||||
|
||||
assert(count == 0);
|
||||
|
||||
LTERM_LOG(ltermPlainTextInput,21,("Reprocessing trailing TAB\n"));
|
||||
|
||||
returnCode= ltermLineInput(lts, &uch, 1, opcodes);
|
||||
if (returnCode < 0)
|
||||
return returnCode;
|
||||
|
||||
} else {
|
||||
/* Process new input characters */
|
||||
returnCode = ltermLineInput(lts, buf, count, opcodes) != 0;
|
||||
if (returnCode < 0)
|
||||
return returnCode;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/** Cancels a prior command line completion request
|
||||
* @return 0 on success,
|
||||
* -1 on error
|
||||
*/
|
||||
int ltermCancelCompletion(struct lterms *lts)
|
||||
{
|
||||
|
||||
LTERM_LOG(ltermCancelCompletion,40,
|
||||
("++++++++++++ CANCELED COMPLETION REQUEST\n\n"));
|
||||
|
||||
if (lts->completionRequest != LTERM_NO_COMPLETION) {
|
||||
|
||||
/* Kill input line transmitted to process */
|
||||
if (ltermSendData(lts, lts->control+TTYKILL, 1) != 0)
|
||||
return -1;
|
||||
|
||||
lts->completionRequest = LTERM_NO_COMPLETION;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/** Inserts plain text character UCH as a single-column glyph at the
|
||||
* current input cursor location, translating to escape sequence if needed.
|
||||
* @return 0 on success, -1 on error.
|
||||
*/
|
||||
int ltermInsertChar(struct LtermInput *lti, UNICHAR uch)
|
||||
{
|
||||
UNICHAR* escapeSequence;
|
||||
int insChars, insertColIndex, insertCharIndex, j;
|
||||
|
||||
LTERM_LOG(ltermInsertChar,40,("inserting character 0x%x at glyph %d\n",
|
||||
uch, lti->inputCursorGlyph));
|
||||
|
||||
/* Ignore null character */
|
||||
if (uch == 0)
|
||||
return 0;
|
||||
|
||||
escapeSequence = NULL;
|
||||
insChars = 1;
|
||||
|
||||
#if 0
|
||||
/* COMMENTED OUT: Plain text not escaped; use code later in HTML insert */
|
||||
/* Check if plain text character needs to be escaped for XML/HTML */
|
||||
for (j=0; j<LTERM_PLAIN_ESCAPES; j++) {
|
||||
|
||||
if (uch == ltermGlobal.escapeChars[j]) {
|
||||
/* Insert escape sequence rather than character */
|
||||
escapeSequence = ltermGlobal.escapeSeq[j];
|
||||
insChars = ltermGlobal.escapeLen[j];
|
||||
LTERM_LOG(ltermInsertChar,42,("escape index=%d\n", j));
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* 0 */
|
||||
|
||||
if (lti->inputChars+insChars > MAXCOLM1) {
|
||||
/* Input buffer overflow; ignore insert character */
|
||||
LTERM_WARNING("ltermInsertChar: Warning - input line buffer overflow\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
assert(lti->inputChars >= 0);
|
||||
assert(lti->inputCols >= 0);
|
||||
assert(lti->inputGlyphs >= 0);
|
||||
assert(lti->inputCursorGlyph >= 0);
|
||||
|
||||
assert(lti->inputCols <= lti->inputChars);
|
||||
assert(lti->inputGlyphs <= lti->inputCols);
|
||||
|
||||
insertColIndex = lti->inputGlyphColIndex[lti->inputCursorGlyph];
|
||||
insertCharIndex = lti->inputColCharIndex[insertColIndex];
|
||||
|
||||
LTERM_LOG(ltermInsertChar,41,("insertColIndex=%d, insertCharIndex=%d, insChars=%d\n",
|
||||
insertColIndex, insertCharIndex, insChars));
|
||||
|
||||
/* Shift portion of input line to the right;
|
||||
remember that the column/glyph index arrays have an extra element */
|
||||
for (j=lti->inputChars - 1; j >= insertCharIndex; j--)
|
||||
lti->inputLine[j+insChars] = lti->inputLine[j];
|
||||
|
||||
for (j=lti->inputCols; j >= insertColIndex; j--)
|
||||
lti->inputColCharIndex[j+1] = lti->inputColCharIndex[j]+insChars;
|
||||
|
||||
for (j=lti->inputGlyphs; j >= lti->inputCursorGlyph; j--) {
|
||||
lti->inputGlyphCharIndex[j+1] = lti->inputGlyphCharIndex[j]+insChars;
|
||||
lti->inputGlyphColIndex[j+1] = lti->inputGlyphColIndex[j]+1;
|
||||
}
|
||||
|
||||
/* Insert character(s) in input line */
|
||||
if (escapeSequence == NULL) {
|
||||
lti->inputLine[insertCharIndex] = uch;
|
||||
} else {
|
||||
for (j=0; j < insChars; j++)
|
||||
lti->inputLine[j+insertCharIndex] = escapeSequence[j];
|
||||
}
|
||||
|
||||
/* Insert column/glyph */
|
||||
lti->inputColCharIndex[insertColIndex] = insertCharIndex;
|
||||
|
||||
lti->inputGlyphCharIndex[lti->inputCursorGlyph] = insertCharIndex;
|
||||
lti->inputGlyphColIndex[lti->inputCursorGlyph] = insertColIndex;
|
||||
|
||||
lti->inputChars += insChars; /* Increment character count */
|
||||
|
||||
lti->inputCols++; /* Increment column count */
|
||||
|
||||
lti->inputGlyphs++; /* Increment glyph count */
|
||||
|
||||
lti->inputCursorGlyph++; /* Reposition cursor */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/** switches to raw input mode */
|
||||
void ltermSwitchToRawMode(struct lterms *lts)
|
||||
{
|
||||
struct LtermInput *lti = &(lts->ltermInput);
|
||||
|
||||
LTERM_LOG(ltermSwitchToRawMode,40,("\n"));
|
||||
|
||||
if (lti->inputMode != LTERM0_RAW_MODE) {
|
||||
/* Do other things ... */
|
||||
lti->inputMode = LTERM0_RAW_MODE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** clears input line buffer and switches to regular input mode */
|
||||
void ltermClearInputLine(struct lterms *lts)
|
||||
{
|
||||
struct LtermInput *lti = &(lts->ltermInput);
|
||||
|
||||
LTERM_LOG(ltermClearInputLine,40,("\n"));
|
||||
|
||||
lti->inputChars = 0;
|
||||
|
||||
lti->inputCols = 0;
|
||||
lti->inputColCharIndex[0] = 0;
|
||||
|
||||
lti->inputGlyphs = 0;
|
||||
lti->inputGlyphCharIndex[0] = 0;
|
||||
lti->inputGlyphColIndex[0] = 0;
|
||||
|
||||
lti->inputCursorGlyph = 0;
|
||||
|
||||
if (lts->maxInputMode >= LTERM2_EDIT_MODE)
|
||||
lti->inputMode = LTERM2_EDIT_MODE;
|
||||
else
|
||||
lti->inputMode = lts->maxInputMode;
|
||||
|
||||
lti->escapeFlag = 0;
|
||||
lti->escapeCSIFlag = 0;
|
||||
lti->escapeCSIArg = 0;
|
||||
}
|
||||
|
||||
|
||||
/** Processes an input string in canonical or higher mode and returns
|
||||
* OPCODES ::= LINEDATA ( INPUT (NEWLINE HIDE?)?
|
||||
* | INPUT META (COMPLETION|NEWLINE HIDE?) )
|
||||
* if echoable input data was processed.
|
||||
* (OPCODES is set to zero if raw input data was processed)
|
||||
* Called from ltermPlainTextInput
|
||||
* @return 0 on success,
|
||||
* -1 on error, and
|
||||
* -2 if pseudo-TTY has been closed.
|
||||
*/
|
||||
static int ltermLineInput(struct lterms *lts,
|
||||
const UNICHAR *buf, int count, int *opcodes)
|
||||
{
|
||||
struct LtermInput *lti = &(lts->ltermInput);
|
||||
UNICHAR uch;
|
||||
int charIndex, metaInput;
|
||||
|
||||
/* Default returned opcodes (maybe overridden) */
|
||||
*opcodes = LTERM_LINEDATA_CODE | LTERM_INPUT_CODE;
|
||||
|
||||
charIndex = 0;
|
||||
|
||||
LTERM_LOG(ltermLineInput,30,
|
||||
("lti->inputMode=%d, inputCursorGlyph=%d\n",
|
||||
lti->inputMode, lti->inputCursorGlyph));
|
||||
LTERM_LOGUNICODE(ltermLineInput,31,(buf, count));
|
||||
LTERM_LOG(ltermLineInput,31,("Glyphs=%d,Cols=%d,Chars=%d\n",
|
||||
lti->inputGlyphs, lti->inputCols, lti->inputChars));
|
||||
|
||||
while (charIndex < count) {
|
||||
uch = buf[charIndex];
|
||||
|
||||
if (uch == U_ESCAPE) {
|
||||
/* Escape */
|
||||
lti->escapeFlag = 1;
|
||||
uch = U_NUL;
|
||||
|
||||
} else if (lti->escapeFlag) {
|
||||
/* Escaped character */
|
||||
lti->escapeFlag = 0;
|
||||
|
||||
switch (uch) {
|
||||
|
||||
case U_LBRACKET:
|
||||
/* Start of escape code sequence */
|
||||
lti->escapeCSIFlag = 1;
|
||||
lti->escapeCSIArg = 0;
|
||||
uch = U_NUL;
|
||||
break;
|
||||
|
||||
default:
|
||||
uch = U_NUL;
|
||||
}
|
||||
|
||||
} else if (lti->escapeCSIFlag) {
|
||||
/* Character part of escape code sequence */
|
||||
|
||||
if ((uch >= U_ZERO && uch <= U_NINE)) {
|
||||
/* Process numerical argument to escape code sequence */
|
||||
lti->escapeCSIArg = lti->escapeCSIArg*10 + (uch - U_ZERO);
|
||||
uch = U_NUL;
|
||||
|
||||
} else {
|
||||
/* End of escape code sequence */
|
||||
lti->escapeCSIFlag = 0;
|
||||
|
||||
/* SUN arrow key bindings */
|
||||
switch (uch) {
|
||||
case U_A_CHAR:
|
||||
uch = U_CTL_P;
|
||||
break;
|
||||
case U_B_CHAR:
|
||||
uch = U_CTL_N;
|
||||
break;
|
||||
case U_C_CHAR:
|
||||
uch = U_CTL_F;
|
||||
break;
|
||||
case U_D_CHAR:
|
||||
uch = U_CTL_B;
|
||||
break;
|
||||
default:
|
||||
uch = U_NUL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ((uch >= U_SPACE) && (uch != U_DEL)) ||
|
||||
((uch == U_TAB) && (lti->inputMode <= LTERM2_EDIT_MODE)) ) {
|
||||
/* printable character or non-completion mode TAB; insert in buffer */
|
||||
/* (NEED TO UPDATE THIS CHECK FOR UNICODE PRINTABILITY) */
|
||||
|
||||
LTERM_LOG(ltermLineInput,39,("inserting printable character - %c\n",
|
||||
(char) uch));
|
||||
|
||||
/* Insert character */
|
||||
if (ltermInsertChar(lti, uch) != 0)
|
||||
return -1;
|
||||
|
||||
} else {
|
||||
/* Control character */
|
||||
|
||||
/* Line break control characters */
|
||||
if ( (uch == U_LINEFEED) ||
|
||||
(uch == lts->control[TTYDISCARD]) ||
|
||||
(uch == lts->control[TTYSUSPEND]) ||
|
||||
(uch == lts->control[TTYINTERRUPT])) {
|
||||
/* Newline/TTYdiscard/TTYsuspend/TTYinterrupt character */
|
||||
|
||||
/* Assert that linebreak character occurs at end of buffer;
|
||||
* enforced by lterm_write.
|
||||
*/
|
||||
assert(charIndex == count-1);
|
||||
|
||||
/* Check if meta input line */
|
||||
metaInput = ltermMetaInput(lts);
|
||||
|
||||
if ((uch == lts->control[TTYDISCARD]) && !metaInput
|
||||
&& (lts->commandNumber == 0)) {
|
||||
/* Not meta/command line; simply transmit discard character */
|
||||
if (ltermSendData(lts, lts->control+TTYDISCARD, 1) != 0)
|
||||
return -1;
|
||||
|
||||
} else {
|
||||
/* Newline behaviour, with hide option */
|
||||
LTERM_LOG(ltermLineInput,31,("------------ NEWLINE (0x%x)\n\n",
|
||||
uch));
|
||||
LTERM_LOGUNICODE(ltermLineInput,31,( lti->inputLine,
|
||||
lti->inputChars));
|
||||
|
||||
/* The NEWLINE code tells ltermReturnInputLine to clear
|
||||
* the input line buffer after copying it
|
||||
*/
|
||||
*opcodes = LTERM_LINEDATA_CODE | LTERM_INPUT_CODE
|
||||
| LTERM_NEWLINE_CODE;
|
||||
|
||||
if (uch == lts->control[TTYDISCARD]) {
|
||||
*opcodes |= LTERM_HIDE_CODE;
|
||||
uch = U_LINEFEED; /* essentially newline behaviour otherwise */
|
||||
}
|
||||
|
||||
if (metaInput) {
|
||||
/* meta input; do not send line */
|
||||
*opcodes |= LTERM_META_CODE;
|
||||
} else {
|
||||
/* Send line and copy to echo buffer */
|
||||
if (ltermSendLine(lts, uch, (uch != U_LINEFEED),
|
||||
LTERM_NO_COMPLETION) != 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else if (uch == lts->control[TTYKILL]) {
|
||||
/* kill line */
|
||||
ltermClearInputLine(lts);
|
||||
|
||||
LTERM_LOG(ltermLineInput,31,("TTYKILL\n"));
|
||||
|
||||
} else if ((uch == U_BACKSPACE) ||
|
||||
(uch == lts->control[TTYERASE])) {
|
||||
/* erase glyph */
|
||||
if (ltermDeleteGlyphs(lti, 1) != 0)
|
||||
return -1;
|
||||
|
||||
LTERM_LOG(ltermLineInput,39,("TTYERASE\n"));
|
||||
|
||||
} else {
|
||||
/* other control characters */
|
||||
if (lti->inputMode >= LTERM2_EDIT_MODE) {
|
||||
switch (uch) {
|
||||
|
||||
case U_NUL: /* Null character; ignore */
|
||||
break;
|
||||
|
||||
case U_CTL_B: /* move cursor backward */
|
||||
LTERM_LOG(ltermLineInput,32,("^B\n"));
|
||||
if (lti->inputCursorGlyph > 0) {
|
||||
lti->inputCursorGlyph--;
|
||||
}
|
||||
break;
|
||||
|
||||
case U_CTL_F: /* move cursor forward */
|
||||
LTERM_LOG(ltermLineInput,32,("^F\n"));
|
||||
if (lti->inputCursorGlyph < lti->inputGlyphs) {
|
||||
lti->inputCursorGlyph++;
|
||||
}
|
||||
break;
|
||||
|
||||
case U_CTL_A: /* position cursor at beginning of line */
|
||||
LTERM_LOG(ltermLineInput,32,("^A\n"));
|
||||
lti->inputCursorGlyph = 0;
|
||||
break;
|
||||
|
||||
case U_CTL_E: /* position cursor at end of line */
|
||||
LTERM_LOG(ltermLineInput,32,("^E\n"));
|
||||
lti->inputCursorGlyph = lti->inputGlyphs;
|
||||
break;
|
||||
|
||||
case U_CTL_K: /* delete to end of line */
|
||||
LTERM_LOG(ltermLineInput,32,("^K\n"));
|
||||
if (ltermDeleteGlyphs(lti,-(lti->inputGlyphs-lti->inputCursorGlyph))
|
||||
!= 0)
|
||||
return -1;
|
||||
break;
|
||||
|
||||
case U_CTL_L: /* form feed */
|
||||
case U_CTL_R: /* redisplay */
|
||||
LTERM_LOG(ltermLineInput,32,("^%c\n", uch+U_ATSIGN));
|
||||
break;
|
||||
|
||||
case U_CTL_D: /* ^D */
|
||||
case U_CTL_N: /* dowN history */
|
||||
case U_CTL_P: /* uP history */
|
||||
case U_CTL_Y: /* yank */
|
||||
case U_TAB: /* command completion */
|
||||
|
||||
/* Assert that completion character occurs at end of buffer;
|
||||
* enforced by lterm_write.
|
||||
*/
|
||||
assert(charIndex == count-1);
|
||||
|
||||
metaInput = ltermMetaInput(lts);
|
||||
|
||||
if (metaInput) {
|
||||
/* Meta input command completion */
|
||||
LTERM_LOG(ltermLineInput,40,
|
||||
("++++++++++++ meta COMPLETION uch=0x%X\n\n", uch));
|
||||
if (uch == U_TAB) {
|
||||
*opcodes = LTERM_LINEDATA_CODE | LTERM_INPUT_CODE
|
||||
| LTERM_META_CODE
|
||||
| LTERM_COMPLETION_CODE;
|
||||
} else {
|
||||
LTERM_WARNING("ltermLineInput: Warning - meta command completion not yet implemented for uch=0x%x\n", uch);
|
||||
}
|
||||
|
||||
} else if (lti->inputMode >= LTERM3_COMPLETION_MODE) {
|
||||
/* Completion mode; non-completion TABs already processed */
|
||||
|
||||
if (ltermRequestCompletion(lts, uch) != 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Increment character index */
|
||||
charIndex++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/** Check if input line contains a meta delimiter;
|
||||
* @return 1 if it does, 0 otherwise.
|
||||
*/
|
||||
static int ltermMetaInput(struct lterms *lts)
|
||||
{
|
||||
struct LtermInput *lti = &(lts->ltermInput);
|
||||
UNICHAR *delimLoc, *ustr, *ustr2;
|
||||
|
||||
LTERM_LOG(ltermMetaInput,40,("\n"));
|
||||
|
||||
if (lts->options & LTERM_NOMETA_FLAG)
|
||||
return 0;
|
||||
|
||||
/* Assert that there is at least one free character position in the buffer */
|
||||
assert(lti->inputChars < MAXCOL);
|
||||
|
||||
/* Insert null character at the end of the input buffer */
|
||||
lti->inputLine[lti->inputChars] = U_NUL;
|
||||
|
||||
/* Locate first occurrence of meta delimiter in input line */
|
||||
delimLoc = ucschr(lti->inputLine, ltermGlobal.metaDelimiter);
|
||||
|
||||
if (delimLoc == NULL)
|
||||
return 0;
|
||||
|
||||
for (ustr=lti->inputLine; ustr<delimLoc; ustr++) /* skip spaces/TABs */
|
||||
if ((*ustr != U_SPACE) && (*ustr != U_TAB)) break;
|
||||
|
||||
if (ustr == delimLoc) {
|
||||
/* Nameless meta command */
|
||||
LTERM_LOG(ltermMetaInput,41,("Nameless meta command\n"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!IS_ASCII_LETTER(*ustr)) /* meta command must start with a letter */
|
||||
return 0;
|
||||
|
||||
for (ustr2=ustr+1; ustr2<delimLoc; ustr2++)
|
||||
if (!IS_ASCII_LETTER(*ustr2) && !IS_ASCII_DIGIT(*ustr2))
|
||||
return 0;
|
||||
|
||||
LTERM_LOG(ltermMetaInput,41,("Named meta command\n"));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/** Requests command line completion from process corresponding to
|
||||
* control character UCH.
|
||||
* @return 0 on success,
|
||||
* -1 on error
|
||||
*/
|
||||
static int ltermRequestCompletion(struct lterms *lts, UNICHAR uch)
|
||||
{
|
||||
LTERM_LOG(ltermRequestCompletion,40,
|
||||
("++++++++++++ COMPLETION REQUEST uch=0x%X\n\n", uch));
|
||||
|
||||
if ((uch == U_CTL_D) &&
|
||||
!(lts->processType == LTERM_TCSH_PROCESS)){
|
||||
/* If ^D and not TCSH, simply transmit character */
|
||||
if (ltermSendData(lts, &uch, 1) != 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (uch) {
|
||||
case U_TAB:
|
||||
/* Send line and copy to echo buffer */
|
||||
if (ltermSendLine(lts, uch, 0, LTERM_TAB_COMPLETION) != 0)
|
||||
return -1;
|
||||
break;
|
||||
case U_CTL_P:
|
||||
case U_CTL_N:
|
||||
/* Send line and copy to echo buffer */
|
||||
if (ltermSendLine(lts, uch, 0, LTERM_HISTORY_COMPLETION) != 0)
|
||||
return -1;
|
||||
break;
|
||||
default:
|
||||
LTERM_WARNING("ltermCompletionRequest: Warning - command completion not yet implemented for uch=0x%x\n", uch);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/** Deletes glyphs from the input line.
|
||||
* If COUNT > 0, glyphs are deleted to the left of the cursor.
|
||||
* If COUNT < 0, glyphs are deleted to the right of the cursor.
|
||||
* Called from ltermLineInput.
|
||||
* @return 0 on success, -1 on error.
|
||||
*/
|
||||
int ltermDeleteGlyphs(struct LtermInput *lti, int count)
|
||||
{
|
||||
int leftGlyph, leftColIndex, leftCharIndex;
|
||||
int rightGlyph, rightColIndex, rightCharIndex;
|
||||
int deleteGlyphs, deleteCols, deleteChars, j;
|
||||
|
||||
LTERM_LOG(ltermDeleteGlyphs,40,("deleting %d glyphs from glyph %d\n",
|
||||
count, lti->inputCursorGlyph));
|
||||
|
||||
if (count >= 0) {
|
||||
/* Delete to the left */
|
||||
deleteGlyphs = count;
|
||||
|
||||
/* Limit the number of glyphs deleted to that present to the left */
|
||||
if (deleteGlyphs > lti->inputCursorGlyph)
|
||||
deleteGlyphs = lti->inputCursorGlyph;
|
||||
|
||||
rightGlyph = lti->inputCursorGlyph;
|
||||
leftGlyph = rightGlyph - deleteGlyphs;
|
||||
|
||||
} else {
|
||||
/* Delete to the right */
|
||||
deleteGlyphs = -count;
|
||||
|
||||
/* Limit the number of glyphs deleted to that present to the right */
|
||||
if (deleteGlyphs > (lti->inputGlyphs - lti->inputCursorGlyph))
|
||||
deleteGlyphs = lti->inputGlyphs - lti->inputCursorGlyph;
|
||||
|
||||
leftGlyph = lti->inputCursorGlyph;
|
||||
rightGlyph = leftGlyph + deleteGlyphs;
|
||||
}
|
||||
|
||||
leftColIndex = lti->inputGlyphColIndex[leftGlyph];
|
||||
leftCharIndex = lti->inputGlyphCharIndex[leftGlyph];
|
||||
|
||||
rightColIndex = lti->inputGlyphColIndex[rightGlyph];
|
||||
rightCharIndex = lti->inputGlyphCharIndex[rightGlyph];
|
||||
|
||||
deleteCols = rightColIndex - leftColIndex;
|
||||
deleteChars = rightCharIndex - leftCharIndex;
|
||||
|
||||
LTERM_LOG(ltermDeleteGlyphs,41,("deleteCols=%d, deleteChars=%d\n",
|
||||
deleteCols, deleteChars));
|
||||
|
||||
LTERM_LOG(ltermDeleteGlyphs,42,("leftGlyph=%d, leftCol=%d, leftChar=%d\n",
|
||||
leftGlyph, leftColIndex, leftCharIndex));
|
||||
|
||||
LTERM_LOG(ltermDeleteGlyphs,42,("rightGlyph=%d, rightCol=%d, rightChar=%d\n",
|
||||
rightGlyph, rightColIndex, rightCharIndex));
|
||||
|
||||
/* Shift portion of input line to the left;
|
||||
remember that the column/glyph index arrays have an extra element */
|
||||
for (j = leftCharIndex; j < lti->inputChars-deleteChars; j++)
|
||||
lti->inputLine[j] = lti->inputLine[j+deleteChars];
|
||||
|
||||
for (j = leftColIndex; j <= lti->inputCols-deleteCols; j++)
|
||||
lti->inputColCharIndex[j] = lti->inputColCharIndex[j+deleteCols]
|
||||
- deleteChars;
|
||||
|
||||
for (j = leftGlyph; j <= lti->inputGlyphs-deleteGlyphs; j++)
|
||||
lti->inputGlyphColIndex[j] = lti->inputGlyphColIndex[j+deleteGlyphs]
|
||||
- deleteCols;
|
||||
|
||||
lti->inputChars -= deleteChars; /* Decrement character count */
|
||||
|
||||
lti->inputCols -= deleteCols; /* Decrement column count */
|
||||
|
||||
lti->inputGlyphs -= deleteGlyphs; /* Decrement glyph count */
|
||||
|
||||
if (count > 0)
|
||||
lti->inputCursorGlyph -= deleteGlyphs; /* Reposition glyph cursor */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/** Transmits COUNT Unicode characters from BUF to child process
|
||||
* after translating Unicode to UTF8 or Latin1, as appropriate.
|
||||
* The data is transmitted in smallish chunks so as not to overflow the
|
||||
* PTY input buffer.
|
||||
* @return 0 on successful write, -1 on error.
|
||||
*/
|
||||
int ltermSendData(struct lterms *lts, const UNICHAR *buf, int count)
|
||||
{
|
||||
char ch, ptyBuf[MAXPTYIN];
|
||||
int remainingChars, chunkSize, success;
|
||||
|
||||
assert(lts != NULL);
|
||||
assert(count >= 0);
|
||||
|
||||
LTERM_LOG(ltermSendData,40,("count=%d\n", count));
|
||||
LTERM_LOGUNICODE(ltermSendData,41,(buf, count));
|
||||
|
||||
if ((count == 1) && (*buf < 0x80)) {
|
||||
/* Optimized code to transmit single ASCII character */
|
||||
ch = (char) *buf;
|
||||
|
||||
if (lts->ptyMode)
|
||||
#ifndef USE_NSPR_IO
|
||||
success = (write(lts->pty.ptyFD, &ch, 1) == 1);
|
||||
#else
|
||||
assert(0);
|
||||
#endif
|
||||
else
|
||||
success = (WRITE(lts->ltermProcess.processIN, &ch, 1) == 1);
|
||||
|
||||
if (!success) {
|
||||
#if defined(DEBUG) && !defined(USE_NSPR_IO)
|
||||
int errcode = errno;
|
||||
perror("ltermSendData");
|
||||
#else
|
||||
int errcode = 0;
|
||||
#endif
|
||||
LTERM_ERROR("ltermSendData: Error %d in writing to child STDIN\n",
|
||||
errcode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
remainingChars = count;
|
||||
while (remainingChars > 0) {
|
||||
/* Convert Unicode to UTF8 */
|
||||
ucstoutf8(&buf[count-remainingChars], remainingChars,
|
||||
ptyBuf, MAXPTYIN,
|
||||
&remainingChars, &chunkSize);
|
||||
|
||||
assert(chunkSize > 0);
|
||||
|
||||
LTERM_LOG(ltermSendData,42,("remainingChars=%d, chunkSize=%d\n",
|
||||
remainingChars, chunkSize));
|
||||
|
||||
/* Send UTF8 to process */
|
||||
if (lts->ptyMode)
|
||||
#ifndef USE_NSPR_IO
|
||||
success = (write(lts->pty.ptyFD, &ptyBuf,
|
||||
(SIZE_T) chunkSize) == chunkSize);
|
||||
#else
|
||||
assert(0);
|
||||
#endif
|
||||
else
|
||||
success = (WRITE(lts->ltermProcess.processIN, &ptyBuf,
|
||||
(SIZE_T) chunkSize) == chunkSize);
|
||||
|
||||
if (!success) {
|
||||
#if defined(DEBUG) && !defined(USE_NSPR_IO)
|
||||
int errcode = errno;
|
||||
perror("ltermSendData");
|
||||
#else
|
||||
int errcode = 0;
|
||||
#endif
|
||||
LTERM_ERROR("ltermSendData: Error %d in writing to child STDIN\n",
|
||||
errcode);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,895 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* ltermOutput.c: LTERM PTY output processing
|
||||
*/
|
||||
|
||||
/* public declarations */
|
||||
#include "lineterm.h"
|
||||
|
||||
/* private declarations */
|
||||
#include "ltermPrivate.h"
|
||||
|
||||
|
||||
static int ltermAppendOutput(struct lterms *lts, const char *cbuf, int count,
|
||||
UNISTYLE style, int interleaveCheck,
|
||||
int *interleavedBytes, int rawIncompleteMax,
|
||||
int *rawIncompleteBytes, char *rawIncompleteBuf);
|
||||
static int ltermDecode(const char *rawBuf, int n_total,
|
||||
UNICHAR* decodedBuf, int decodeMax,
|
||||
int decodeNUL,
|
||||
int *rawIncompleteBytes);
|
||||
static int ltermPromptLocate(struct lterms *lts);
|
||||
|
||||
|
||||
/** Processes output from decoded output buffer and returns *opcodes:
|
||||
* OPCODES ::= SCREENDATA BELL? ( CLEAR
|
||||
* | INSERT MOVEDOWN?
|
||||
* | DELETE MOVEDOWN?
|
||||
* | OUTPUT )
|
||||
* if ScreenMode data is being returned.
|
||||
* OPCODES ::= LINEDATA BELL? ( CLEAR
|
||||
* | OUTPUT NEWLINE?)
|
||||
* if LineMode data is being returned.
|
||||
* @return 0 on success and -1 on error.
|
||||
*/
|
||||
int ltermProcessOutput(struct lterms *lts, int *opcodes)
|
||||
{
|
||||
struct LtermOutput *lto = &(lts->ltermOutput);
|
||||
UNICHAR uch;
|
||||
UNISTYLE ustyle;
|
||||
int charIndex, returnCode, consumedChars, remainingChars, j;
|
||||
int bellFlag;
|
||||
|
||||
LTERM_LOG(ltermProcessOutput,30,("lto->outputMode=%d, cursorChar=%d, Chars=%d\n",
|
||||
lto->outputMode, lto->outputCursorChar, lto->outputChars));
|
||||
|
||||
LTERM_LOG(ltermProcessOutput,32, ("lts->commandNumber=%d\n",
|
||||
lts->commandNumber));
|
||||
|
||||
*opcodes = 0;
|
||||
charIndex = 0;
|
||||
bellFlag = 0;
|
||||
|
||||
while ((*opcodes == 0) && (charIndex < lto->decodedChars)) {
|
||||
uch = lto->decodedOutput[charIndex];
|
||||
ustyle = lto->decodedStyle[charIndex] | lto->styleMask;
|
||||
|
||||
consumedChars = 1;
|
||||
|
||||
if (uch == U_ESCAPE) {
|
||||
/* Process escape sequence */
|
||||
int savedOutputMode = lto->outputMode;
|
||||
|
||||
LTERM_LOG(ltermProcessOutput,31,("ESCAPE sequence\n"));
|
||||
|
||||
returnCode = ltermProcessEscape(lts, lto->decodedOutput+charIndex,
|
||||
lto->decodedChars-charIndex,
|
||||
lto->decodedStyle+charIndex,
|
||||
&consumedChars, opcodes);
|
||||
if (returnCode < 0)
|
||||
return -1;
|
||||
|
||||
if (returnCode == 1) {
|
||||
/* Incomplete escape sequence */
|
||||
lto->incompleteEscapeSequence = 1;
|
||||
if (lto->outputMode == LTERM1_SCREEN_MODE)
|
||||
*opcodes = LTERM_SCREENDATA_CODE | LTERM_OUTPUT_CODE;
|
||||
else
|
||||
*opcodes = LTERM_LINEDATA_CODE | LTERM_OUTPUT_CODE;
|
||||
}
|
||||
|
||||
/* Assert that change in output mode is a loop terminating condition */
|
||||
if (lto->outputMode != savedOutputMode)
|
||||
assert(*opcodes != 0);
|
||||
|
||||
} else if (lto->outputMode == LTERM1_SCREEN_MODE) {
|
||||
/* Screen mode processing */
|
||||
|
||||
if ((uch >= U_SPACE) && (uch != U_DEL)) {
|
||||
/* Printable non-TAB character */
|
||||
|
||||
LTERM_LOG(ltermProcessOutput,39,("Screen mode, printable char - %c\n",
|
||||
(char) uch));
|
||||
|
||||
if (lto->insertMode) {
|
||||
/* Insert blank character at cursor position */
|
||||
if (ltermInsDelEraseChar(lts, 1, LTERM_INSERT_CHAR) != 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Mark column as being modified */
|
||||
if ((lto->modifiedCol[lto->cursorRow] == -1) ||
|
||||
(lto->modifiedCol[lto->cursorRow] > lto->cursorCol))
|
||||
lto->modifiedCol[lto->cursorRow] = lto->cursorCol;
|
||||
|
||||
/* Replace character and style info at current cursor location */
|
||||
j = lto->cursorRow*lts->nCols + lto->cursorCol;
|
||||
|
||||
assert(j < lts->screenSize);
|
||||
|
||||
lto->screenChar[j] = uch;
|
||||
lto->screenStyle[j] = ustyle;
|
||||
|
||||
if (lto->cursorCol < lts->nCols-1) {
|
||||
/* Move cursor right */
|
||||
lto->cursorCol++;
|
||||
|
||||
/* Increase row column count, if necessary */
|
||||
if (lto->rowCols[lto->cursorRow] < lto->cursorCol)
|
||||
lto->rowCols[lto->cursorRow] = lto->cursorCol;
|
||||
|
||||
} else {
|
||||
/* Set row column count to maximum value */
|
||||
lto->rowCols[lto->cursorRow] = lts->nCols;
|
||||
}
|
||||
|
||||
} else {
|
||||
/* Control character */
|
||||
|
||||
switch (uch) {
|
||||
case U_BACKSPACE: /* Backspace */
|
||||
LTERM_LOG(ltermProcessOutput,32,("Screen mode, BACKSPACE\n"));
|
||||
if (lto->cursorCol > 0)
|
||||
lto->cursorCol--;
|
||||
break;
|
||||
|
||||
case U_BEL: /* Bell */
|
||||
LTERM_LOG(ltermProcessOutput,32,("************ Screen mode, BELL\n"));
|
||||
bellFlag = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Ignore other control characters (including NULs) */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
/* Line mode processing */
|
||||
|
||||
if ( ((uch >= U_SPACE) && (uch != U_DEL)) ||
|
||||
(uch == U_TAB)) {
|
||||
/* Printable/TAB character; replace/insert at current cursor location
|
||||
or append to end of line */
|
||||
|
||||
LTERM_LOG(ltermProcessOutput,39,("Line mode, printable char - %c\n",
|
||||
(char) uch));
|
||||
|
||||
if (lto->outputCursorChar == lto->outputChars) {
|
||||
/* Append single character to end of line */
|
||||
|
||||
if (lto->outputChars+1 > MAXCOLM1) {
|
||||
/* Output buffer overflow; ignore character */
|
||||
LTERM_WARNING("ltermProcessOutput: Warning - output line buffer overflow\n");
|
||||
}
|
||||
|
||||
lto->outputLine[lto->outputChars] = uch;
|
||||
lto->outputStyle[lto->outputChars] = ustyle;
|
||||
lto->outputChars++; /* Insert character in output line */
|
||||
|
||||
lto->outputCursorChar++; /* Reposition cursor */
|
||||
|
||||
} else {
|
||||
/* Replace/insert single character in the middle of line */
|
||||
|
||||
if (lto->insertMode) {
|
||||
/* Insert blank character at cursor position */
|
||||
if (ltermInsDelEraseChar(lts, 1, LTERM_INSERT_CHAR) != 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Overwrite single character in the middle of line */
|
||||
lto->outputLine[lto->outputCursorChar] = uch;
|
||||
lto->outputStyle[lto->outputCursorChar] = ustyle;
|
||||
|
||||
/* Note modifications */
|
||||
if (lto->outputCursorChar < lto->outputModifiedChar)
|
||||
lto->outputModifiedChar = lto->outputCursorChar;
|
||||
|
||||
lto->outputCursorChar++; /* Reposition cursor */
|
||||
}
|
||||
|
||||
} else {
|
||||
/* Control character */
|
||||
|
||||
switch (uch) {
|
||||
case U_BACKSPACE: /* Backspace */
|
||||
LTERM_LOG(ltermProcessOutput,32,("Line mode, BACKSPACE\n"));
|
||||
if (lto->outputCursorChar > 0)
|
||||
lto->outputCursorChar--;
|
||||
break;
|
||||
|
||||
case U_CRETURN: /* Carriage return */
|
||||
LTERM_LOG(ltermProcessOutput,32,("Line mode, CRETURN\n"));
|
||||
lto->outputCursorChar = 0;
|
||||
break;
|
||||
|
||||
case U_BEL: /* Bell */
|
||||
LTERM_LOG(ltermProcessOutput,32,("************ Line mode, BELL\n"));
|
||||
bellFlag = 1;
|
||||
break;
|
||||
|
||||
case U_CTL_L: /* Formfeed; clear line and return */
|
||||
LTERM_LOG(ltermProcessOutput,32,("************ Line mode, FORMFEED\n\n"));
|
||||
|
||||
ltermClearOutputLine(lts);
|
||||
*opcodes = LTERM_LINEDATA_CODE | LTERM_CLEAR_CODE;
|
||||
break;
|
||||
|
||||
case U_LINEFEED: /* Newline; return complete line */
|
||||
LTERM_LOG(ltermProcessOutput,32,("************ Line mode, NEWLINE\n\n"));
|
||||
|
||||
*opcodes = LTERM_LINEDATA_CODE
|
||||
| LTERM_OUTPUT_CODE
|
||||
| LTERM_NEWLINE_CODE;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Ignore other control characters (including NULs) */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Increment character index */
|
||||
charIndex += consumedChars;
|
||||
}
|
||||
|
||||
/* Determine count of unprocessed characters */
|
||||
remainingChars = lto->decodedChars - charIndex;
|
||||
|
||||
if (remainingChars > 0) {
|
||||
/* Move unprocessed output to beginning of decode buffer */
|
||||
|
||||
LTERM_LOG(ltermProcessOutput,32,("Moved %d chars to beginning of decodedOutput\n", remainingChars));
|
||||
for (j=0; j<remainingChars; j++) {
|
||||
lto->decodedOutput[j] = lto->decodedOutput[j+charIndex];
|
||||
lto->decodedStyle[j] = lto->decodedStyle[j+charIndex];
|
||||
}
|
||||
}
|
||||
|
||||
/* Update remaining decoded character count */
|
||||
lto->decodedChars = remainingChars;
|
||||
|
||||
if (*opcodes == 0) {
|
||||
/* All output processed; without any special terminating condition */
|
||||
if (lto->outputMode == LTERM1_SCREEN_MODE) {
|
||||
/* Full screen mode */
|
||||
*opcodes = LTERM_SCREENDATA_CODE | LTERM_OUTPUT_CODE;
|
||||
|
||||
} else {
|
||||
/* Line mode */
|
||||
*opcodes = LTERM_LINEDATA_CODE | LTERM_OUTPUT_CODE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set bell code */
|
||||
if (bellFlag)
|
||||
*opcodes |= LTERM_BELL_CODE;
|
||||
|
||||
if (*opcodes & LTERM_LINEDATA_CODE) {
|
||||
/* Returning line mode data; check for prompt */
|
||||
|
||||
if ((lts->commandNumber == 0) ||
|
||||
(lto->outputModifiedChar < lto->promptChars)) {
|
||||
/* If not command line or if "prompt string" may have been modified,
|
||||
* search for prompt
|
||||
*/
|
||||
int promptLen;
|
||||
|
||||
LTERM_LOG(ltermProcessOutput,39,("Prompt? modifiedChar=%d, promptChars=%d\n",
|
||||
lto->outputModifiedChar, lto->promptChars));
|
||||
|
||||
/* Reset modification marker */
|
||||
lto->outputModifiedChar = lto->outputChars;
|
||||
|
||||
/* Check if prompt string is present in output */
|
||||
promptLen = ltermPromptLocate(lts);
|
||||
|
||||
if (promptLen > 0) {
|
||||
/* Prompt string found */
|
||||
lto->promptChars = promptLen;
|
||||
|
||||
if (lts->commandNumber == 0) {
|
||||
/* Set command number */
|
||||
|
||||
/* New command number */
|
||||
if (lts->lastCommandNum == 0xFFFF)
|
||||
lts->lastCommandNum = 0;
|
||||
lts->lastCommandNum++;
|
||||
|
||||
lts->commandNumber = lts->lastCommandNum;
|
||||
|
||||
LTERM_LOG(ltermProcessOutput,32,
|
||||
("************ Prompt found; commandNumber=%d\n\n",
|
||||
lts->commandNumber));
|
||||
}
|
||||
|
||||
} else {
|
||||
/* No prompt string */
|
||||
if (lts->commandNumber != 0) {
|
||||
/* Unset command number and prompt columns */
|
||||
UNICHAR temLine[2] = {0, LTERM_WRITE_PLAIN_INPUT};
|
||||
|
||||
lts->commandNumber = 0;
|
||||
lto->promptChars = 0;
|
||||
|
||||
/* Notify "input thread" by writing null input record */
|
||||
WRITE(lts->writeBUFFER, temLine, 2*sizeof(UNICHAR));
|
||||
|
||||
LTERM_LOG(ltermProcessOutput,32,
|
||||
("************ No prompt found; not command line\n\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LTERM_LOG(ltermProcessOutput,31,("returned opcodes=0x%X\n", *opcodes));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/** Clears output line buffer */
|
||||
void ltermClearOutputLine(struct lterms *lts)
|
||||
{
|
||||
struct LtermOutput *lto = &(lts->ltermOutput);
|
||||
|
||||
LTERM_LOG(ltermClearOutputLine,40,("\n"));
|
||||
|
||||
lto->outputChars = 0;
|
||||
lto->outputCursorChar = 0;
|
||||
lto->outputModifiedChar = 0;
|
||||
lto->promptChars = 0;
|
||||
|
||||
lts->commandNumber = 0;
|
||||
}
|
||||
|
||||
|
||||
/** Clears output screen buffer (allocating memory, if first time) */
|
||||
int ltermClearOutputScreen(struct lterms *lts)
|
||||
{
|
||||
struct LtermOutput *lto = &(lts->ltermOutput);
|
||||
int j;
|
||||
|
||||
LTERM_LOG(ltermClearOutputScreen,40,("\n"));
|
||||
|
||||
if (lto->screenChar == NULL) {
|
||||
/* Allocate memory for full screen */
|
||||
lto->screenChar = (UNICHAR *) MALLOC(lts->screenSize * sizeof(UNICHAR));
|
||||
|
||||
if (lto->screenChar == NULL) {
|
||||
LTERM_ERROR("ltermClearOutputScreen: Error - failed to allocate memory for chars\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
assert(lto->screenStyle == NULL);
|
||||
lto->screenStyle = (UNISTYLE *) MALLOC(lts->screenSize * sizeof(UNISTYLE));
|
||||
|
||||
if (lto->screenStyle == NULL) {
|
||||
LTERM_ERROR("ltermClearOutputScreen: Error - failed to allocate memory for style\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
lto->cursorRow = lts->nRows - 1;
|
||||
lto->cursorCol = 0;
|
||||
|
||||
for (j=0; j<lts->nRows; j++) {
|
||||
lto->rowCols[j] = 0;
|
||||
lto->modifiedCol[j] = -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/** Saves current output mode value and switches to stream output mode,
|
||||
* with specified opcodes and terminator string.
|
||||
* @return 0 on success and -1 on error.
|
||||
*/
|
||||
int ltermSwitchToStreamMode(struct lterms *lts, int streamOpcodes,
|
||||
const UNICHAR *streamTerminator)
|
||||
{
|
||||
struct LtermOutput *lto = &(lts->ltermOutput);
|
||||
int strLength;
|
||||
|
||||
LTERM_LOG(ltermSwitchToStreamMode,40,("streamOpcodes=0x%s\n",streamOpcodes));
|
||||
|
||||
if (streamTerminator != NULL) {
|
||||
/* Save terminator string (may be null) */
|
||||
strLength = ucslen(streamTerminator);
|
||||
ucsncpy( lto->streamTerminator, streamTerminator, MAXSTREAMTERM);
|
||||
|
||||
LTERM_LOGUNICODE(ltermSwitchToStreamMode,41,(streamTerminator,
|
||||
(int) strLength));
|
||||
} else {
|
||||
/* Null terminator */
|
||||
strLength = 0;
|
||||
lto->streamTerminator[0] = U_NUL;
|
||||
}
|
||||
|
||||
if (strLength > MAXSTREAMTERM-1) {
|
||||
LTERM_ERROR("ltermSwitchToStreamMode: Error - terminator string too long\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (lts->options & LTERM_NONUL_FLAG) {
|
||||
/* No decoding of NUL characters */
|
||||
if (strLength == 0) {
|
||||
LTERM_ERROR("ltermSwitchToStreamMode: Error - null terminator string not allowed\n");
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
/* Decoding NUL characters */
|
||||
if (strLength > 0) {
|
||||
LTERM_ERROR("ltermSwitchToStreamMode: Error - terminator string must be NUL\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
lto->savedOutputMode = lto->outputMode;
|
||||
lto->outputMode = LTERM0_STREAM_MODE;
|
||||
lto->streamOpcodes = streamOpcodes;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/** Switches to screen output mode.
|
||||
* @return 0 on success and -1 on error.
|
||||
*/
|
||||
int ltermSwitchToScreenMode(struct lterms *lts)
|
||||
{
|
||||
struct LtermOutput *lto = &(lts->ltermOutput);
|
||||
|
||||
LTERM_LOG(ltermSwitchToScreenMode,40,("\n"));
|
||||
|
||||
if (lto->outputMode == LTERM1_SCREEN_MODE) {
|
||||
/* Switching from line mode to screen mode */
|
||||
|
||||
if (ltermClearOutputScreen(lts) != 0)
|
||||
return -1;
|
||||
|
||||
/* Clear styleMask */
|
||||
lto->styleMask = 0;
|
||||
}
|
||||
|
||||
lto->outputMode = LTERM1_SCREEN_MODE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/** Switches to line output mode.
|
||||
* @return 0 on success and -1 on error.
|
||||
*/
|
||||
int ltermSwitchToLineMode(struct lterms *lts)
|
||||
{
|
||||
struct LtermOutput *lto = &(lts->ltermOutput);
|
||||
int j;
|
||||
|
||||
LTERM_LOG(ltermSwitchToLineMode,40,("\n"));
|
||||
|
||||
if (lto->outputMode == LTERM1_SCREEN_MODE) {
|
||||
/* Switching from screen mode to line mode */
|
||||
ltermClearOutputLine(lts);
|
||||
|
||||
/* Copy bottom line to line output buffer */
|
||||
lto->outputChars = lto->rowCols[0];
|
||||
|
||||
assert(lto->rowCols[0] < MAXCOL);
|
||||
|
||||
for (j=0; j<lto->rowCols[0]; j++) {
|
||||
lto->outputLine[j] = lto->screenChar[j];
|
||||
lto->outputStyle[j] = lto->screenStyle[j];
|
||||
}
|
||||
|
||||
/* Clear styleMask */
|
||||
lto->styleMask = 0;
|
||||
|
||||
}
|
||||
|
||||
lto->outputMode = LTERM2_LINE_MODE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/** Reads data from process STDOUT and/or STDERR using file descriptors
|
||||
* from the LTERM POLL structure, and converts to Unicode, saving
|
||||
* incomplete character encodings in corresponding incomplete raw buffers.
|
||||
* Decoded characters are appended to the decodedOutput buffer,
|
||||
* with appropriate style settings.
|
||||
* If READERR is false, STDERR is never read.
|
||||
* @return the number of decoded characters appended (>=0) if successful,
|
||||
* -1 if an error occurred during processing, or
|
||||
* -2 if pseudo-TTY has been closed.
|
||||
*/
|
||||
int ltermReceiveData(struct lterms *lts, int readERR)
|
||||
{
|
||||
struct LtermOutput *lto = &(lts->ltermOutput);
|
||||
char temERRBuf[MAXCOL], temOUTBuf[MAXCOL];
|
||||
int readERRMax, readOUTMax;
|
||||
int nReadERR, nTotalERR, nReadOUT, nTotalOUT;
|
||||
int interleavedBytes, n_decoded, n_decoded_tot, j;
|
||||
|
||||
LTERM_LOG(ltermReceiveData,30,("\n"));
|
||||
|
||||
nTotalERR = 0;
|
||||
if (readERR && (lto->pollFD[POLL_STDERR].POLL_REVENTS != 0)) {
|
||||
/* Read data from STDERR */
|
||||
|
||||
/* Read maximum number of bytes that will all fit into decodedOutput
|
||||
when decoded, assuming number of decoded characters will not exceed
|
||||
the number of encoded bytes */
|
||||
|
||||
readERRMax = MAXCOLM1 - lto->decodedChars - lto->rawERRBytes;
|
||||
|
||||
/* Reduce by half to leave some space for STDOUT data */
|
||||
readERRMax = readERRMax / 2;
|
||||
|
||||
if (readERRMax <= 0) {
|
||||
/* Decoded buffer overflow */
|
||||
LTERM_WARNING("ltermReceiveData: Warning - decoded buffer overflow\n");
|
||||
|
||||
/* Non-fatal error recovery; return without reading */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Copy any incomplete raw output to beginning of buffer */
|
||||
for (j=0; j<lto->rawERRBytes; j++)
|
||||
temERRBuf[j] = lto->rawERRBuf[j];
|
||||
|
||||
/* Read STDERRdata (blocking mode) */
|
||||
nReadERR = READ(lto->pollFD[POLL_STDERR].fd,
|
||||
temERRBuf + lto->rawERRBytes, (SIZE_T) readERRMax);
|
||||
|
||||
if (nReadERR < 0) {
|
||||
#if defined(DEBUG) && !defined(USE_NSPR_IO)
|
||||
int errcode = errno;
|
||||
/* perror("ltermReceiveData"); */
|
||||
#else
|
||||
int errcode = 0;
|
||||
#endif
|
||||
LTERM_ERROR( "ltermReceiveData: Error %d in reading from process STDERR\n",
|
||||
errcode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nReadERR == 0) {
|
||||
/* End of file => pseudo-TTY has been closed */
|
||||
LTERM_LOG(ltermReceiveData,31,("pseudo-TTY has been closed\n"));
|
||||
|
||||
/* Suspend LTERM */
|
||||
lts->suspended = 1;
|
||||
|
||||
return -2;
|
||||
}
|
||||
|
||||
|
||||
LTERM_LOG(ltermReceiveData,32,("Read %d raw bytes from STDERR\n", nReadERR));
|
||||
nTotalERR = nReadERR + lto->rawERRBytes;
|
||||
}
|
||||
|
||||
nTotalOUT = 0;
|
||||
if (lto->pollFD[POLL_STDOUT].POLL_REVENTS != 0) {
|
||||
/* Read data from STDOUT */
|
||||
|
||||
/* Read maximum number of bytes that will all fit into decodedOutput
|
||||
when decoded, assuming number of decoded characters will not exceed
|
||||
the number of encoded bytes */
|
||||
readOUTMax = MAXCOLM1 - lto->decodedChars - lto->rawOUTBytes - nTotalERR;
|
||||
|
||||
if (readOUTMax <= 0) {
|
||||
/* Decoded buffer overflow */
|
||||
LTERM_WARNING("ltermReceiveData: Warning - decoded buffer overflow\n");
|
||||
|
||||
/* Non-fatal error recovery; return without reading */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Copy any incomplete raw output to beginning of buffer */
|
||||
for (j=0; j<lto->rawOUTBytes; j++)
|
||||
temOUTBuf[j] = lto->rawOUTBuf[j];
|
||||
|
||||
/* Read STDOUTdata (blocking mode) */
|
||||
nReadOUT = READ(lto->pollFD[POLL_STDOUT].fd,
|
||||
temOUTBuf + lto->rawOUTBytes, (SIZE_T) readOUTMax);
|
||||
|
||||
if (nReadOUT < 0) {
|
||||
#if defined(DEBUG) && !defined(USE_NSPR_IO)
|
||||
int errcode = errno;
|
||||
/* perror("ltermReceiveData"); */
|
||||
#else
|
||||
int errcode = 0;
|
||||
#endif
|
||||
LTERM_ERROR( "ltermReceiveData: Error %d in reading from process STDOUT\n",
|
||||
errcode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nReadOUT == 0) {
|
||||
/* End of file => pseudo-TTY has been closed */
|
||||
LTERM_LOG(ltermReceiveData,31,("pseudo-TTY has been closed\n"));
|
||||
|
||||
/* Suspend LTERM */
|
||||
lts->suspended = 1;
|
||||
|
||||
return -2;
|
||||
}
|
||||
|
||||
LTERM_LOG(ltermReceiveData,32,("Read %d raw bytes from STDOUT\n", nReadOUT));
|
||||
|
||||
nTotalOUT = nReadOUT + lto->rawOUTBytes;
|
||||
}
|
||||
|
||||
n_decoded_tot = 0;
|
||||
|
||||
if (lts->readERRfirst) {
|
||||
/* Decode STDERR data first */
|
||||
interleavedBytes = 0;
|
||||
n_decoded = ltermAppendOutput(lts, temERRBuf, nTotalERR,
|
||||
LTERM_STDERR_STYLE,
|
||||
lts->interleave, &interleavedBytes,
|
||||
MAXRAWINCOMPLETE,
|
||||
&(lto->rawERRBytes), lto->rawERRBuf);
|
||||
if (n_decoded < 0)
|
||||
return -1;
|
||||
n_decoded_tot += n_decoded;
|
||||
|
||||
/* Decode STDOUT data next */
|
||||
n_decoded = ltermAppendOutput(lts, temOUTBuf, nTotalOUT,
|
||||
LTERM_STDOUT_STYLE,
|
||||
0, NULL,
|
||||
MAXRAWINCOMPLETE,
|
||||
&(lto->rawOUTBytes), lto->rawOUTBuf);
|
||||
if (n_decoded < 0)
|
||||
return -1;
|
||||
n_decoded_tot += n_decoded;
|
||||
|
||||
if (interleavedBytes > 0) {
|
||||
/* Decode remaining STDERR data */
|
||||
n_decoded = ltermAppendOutput(lts, temERRBuf+interleavedBytes,
|
||||
nTotalERR-interleavedBytes,
|
||||
LTERM_STDERR_STYLE,
|
||||
0, NULL,
|
||||
MAXRAWINCOMPLETE,
|
||||
&(lto->rawERRBytes), lto->rawERRBuf);
|
||||
if (n_decoded < 0)
|
||||
return -1;
|
||||
n_decoded_tot += n_decoded;
|
||||
}
|
||||
|
||||
} else {
|
||||
/* Decode STDOUT data first */
|
||||
interleavedBytes = 0;
|
||||
n_decoded = ltermAppendOutput(lts, temOUTBuf, nTotalOUT,
|
||||
LTERM_STDOUT_STYLE,
|
||||
lts->interleave, &interleavedBytes,
|
||||
MAXRAWINCOMPLETE,
|
||||
&(lto->rawOUTBytes), lto->rawOUTBuf);
|
||||
if (n_decoded < 0)
|
||||
return -1;
|
||||
n_decoded_tot += n_decoded;
|
||||
|
||||
/* Decode STDERR data next */
|
||||
n_decoded = ltermAppendOutput(lts, temERRBuf, nTotalERR,
|
||||
LTERM_STDERR_STYLE,
|
||||
0, NULL,
|
||||
MAXRAWINCOMPLETE,
|
||||
&(lto->rawERRBytes), lto->rawERRBuf);
|
||||
if (n_decoded < 0)
|
||||
return -1;
|
||||
n_decoded_tot += n_decoded;
|
||||
|
||||
if (interleavedBytes > 0) {
|
||||
/* Decode remaining STDOUT data */
|
||||
n_decoded = ltermAppendOutput(lts, temOUTBuf+interleavedBytes,
|
||||
nTotalOUT-interleavedBytes,
|
||||
LTERM_STDOUT_STYLE,
|
||||
0, NULL,
|
||||
MAXRAWINCOMPLETE,
|
||||
&(lto->rawOUTBytes), lto->rawOUTBuf);
|
||||
if (n_decoded < 0)
|
||||
return -1;
|
||||
n_decoded_tot += n_decoded;
|
||||
}
|
||||
}
|
||||
|
||||
if (n_decoded_tot > 0) {
|
||||
/* New characters have been decoded; no longer incomplete escape seq. */
|
||||
lto->incompleteEscapeSequence = 0;
|
||||
}
|
||||
|
||||
return n_decoded_tot;
|
||||
}
|
||||
|
||||
|
||||
/** Process COUNT bytes raw data from CBUF, converting complete
|
||||
* character encodings to Unicode, saving RAWINCOMPLETEBYTES in
|
||||
* RAWINCOMPLETEBUF, whose maximum size is specified by RAWINCOMPLETEMAX.
|
||||
* If INTERLEAVECHECK, check for starting NEWLINE and other interleavable
|
||||
* characters, and if found "decode" just those characters and set
|
||||
* INTERLEAVEDBYTES to the number of bytes consumed on return;
|
||||
* otherwise INTERLEAVEDBYTES is set to 0.
|
||||
* The decoded characters are appended to the decodedOutput buffer,
|
||||
* with style STYLE.
|
||||
* @return the number of characters appended (>=0) if successful,
|
||||
* -1 if an error occurred during processing, or
|
||||
* -2 if pseudo-TTY has been closed.
|
||||
*/
|
||||
static int ltermAppendOutput(struct lterms *lts, const char *cbuf, int count,
|
||||
UNISTYLE style, int interleaveCheck,
|
||||
int *interleavedBytes, int rawIncompleteMax,
|
||||
int *rawIncompleteBytes, char *rawIncompleteBuf)
|
||||
{
|
||||
struct LtermOutput *lto = &(lts->ltermOutput);
|
||||
int decodeMax, n_decoded, decodeNUL, j;
|
||||
|
||||
LTERM_LOG(ltermAppendOutput,30,("count=%d, style=0x%X, iCheck=%d, rawIncMax=%d\n",
|
||||
count, style, interleaveCheck, rawIncompleteMax));
|
||||
|
||||
if (interleaveCheck && (count > 0) && (cbuf[0] == '\n')) {
|
||||
/* Raw buffer starts with NEWLINE character; interleave */
|
||||
|
||||
assert(lto->decodedChars < MAXCOLM1);
|
||||
|
||||
/* "Decode" just the NEWLINE character */
|
||||
lto->decodedOutput[lto->decodedChars] = U_LINEFEED;
|
||||
lto->decodedStyle[lto->decodedChars] = LTERM_STDOUT_STYLE;
|
||||
|
||||
lto->decodedChars++;
|
||||
|
||||
*interleavedBytes = 1;
|
||||
|
||||
LTERM_LOG(ltermAppendOutput,32,("INTERLEAVED %d bytes\n",
|
||||
*interleavedBytes));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (interleavedBytes != NULL)
|
||||
*interleavedBytes = 0;
|
||||
|
||||
if (count == 0)
|
||||
return 0;
|
||||
|
||||
/* Decode all complete encoded character sequences */
|
||||
decodeMax = MAXCOLM1 - lto->decodedChars;
|
||||
decodeNUL = (lts->options & LTERM_NONUL_FLAG) == 0;
|
||||
n_decoded = ltermDecode(cbuf, count,
|
||||
lto->decodedOutput+lto->decodedChars,
|
||||
decodeMax, decodeNUL,
|
||||
rawIncompleteBytes);
|
||||
|
||||
if (n_decoded < 0)
|
||||
return -1;
|
||||
|
||||
/* Save any incomplete raw byte encodings */
|
||||
if (*rawIncompleteBytes > rawIncompleteMax) {
|
||||
LTERM_ERROR("ltermAppendOutput: Error - too many incomplete raw characters\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (j=0; j<*rawIncompleteBytes; j++)
|
||||
rawIncompleteBuf[j] = cbuf[j+count-*rawIncompleteBytes];
|
||||
|
||||
/* Set decoded character styles */
|
||||
for (j=lto->decodedChars; j<lto->decodedChars+n_decoded; j++)
|
||||
lto->decodedStyle[j] = style;
|
||||
|
||||
/* Increment decoded character count */
|
||||
lto->decodedChars += n_decoded;
|
||||
|
||||
LTERM_LOG(ltermAppendOutput,32,("Appended %d bytes\n", n_decoded));
|
||||
|
||||
return n_decoded;
|
||||
}
|
||||
|
||||
|
||||
/** Decodes N_TOTAL bytes in RAWBUF, returning upto DECODEMAX Unicode
|
||||
* characters in DECODEDBUF, leaving *RAWINCOMPLETEBYTES at the end of
|
||||
* RAWBUF undecoded.
|
||||
* Any NUL (zero) characters in RAWBUF are skipped, unless
|
||||
* decodeNUL is true.
|
||||
* If there is not enough space in DECODEDBUF for all characters to be
|
||||
* decoded, an error is returned.
|
||||
* @return the number of Unicoded characters decoded (>=0) or -1 on error.
|
||||
*/
|
||||
static int ltermDecode(const char *rawBuf, int n_total,
|
||||
UNICHAR* decodedBuf, int decodeMax,
|
||||
int decodeNUL,
|
||||
int *rawIncompleteBytes)
|
||||
{
|
||||
int n_decoded, result;
|
||||
|
||||
LTERM_LOG(ltermDecode,40,("\n"));
|
||||
|
||||
if (decodeMax < n_total) {
|
||||
LTERM_ERROR("ltermDecode: Error - decode buffer overflow\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = utf8toucs(rawBuf, n_total, decodedBuf, decodeMax,
|
||||
!decodeNUL, rawIncompleteBytes, &n_decoded);
|
||||
|
||||
if (result != 0) {
|
||||
LTERM_WARNING("ltermDecode: Warning - Invalid UTF8 data encountered\n");
|
||||
}
|
||||
|
||||
LTERM_LOG(ltermDecode,41,("result=%d, incomplete=%d, n_decoded=%d\n",
|
||||
result, rawIncompleteBytes, n_decoded));
|
||||
LTERM_LOGUNICODE(ltermDecode,42,(decodedBuf, n_decoded));
|
||||
|
||||
return n_decoded;
|
||||
}
|
||||
|
||||
|
||||
/** Search for prompt string in the output line buffer.
|
||||
* TEMPORARY implementation: assume promptRegexp is just a list of delimiters
|
||||
* @return the length of the matching prompt string, or
|
||||
* 0 if there is no match.
|
||||
*/
|
||||
static int ltermPromptLocate(struct lterms *lts)
|
||||
{
|
||||
struct LtermOutput *lto = &(lts->ltermOutput);
|
||||
int prefixCount, promptLen;
|
||||
|
||||
LTERM_LOG(ltermPromptLocate,49,("lto->outputChars=%d\n",
|
||||
lto->outputChars));
|
||||
|
||||
/* Assert that there is at least one free character in the buffer */
|
||||
assert(lto->outputChars < MAXCOL);
|
||||
|
||||
if (lto->outputChars == 0)
|
||||
return 0;
|
||||
|
||||
/* Insert null character at the end of the output buffer */
|
||||
lto->outputLine[lto->outputChars] = U_NUL;
|
||||
|
||||
/* Determine length of initial non-delimiter prefix */
|
||||
prefixCount = ucscspn(lto->outputLine, lts->promptRegexp);
|
||||
|
||||
if (prefixCount+1 >= lto->outputChars) {
|
||||
promptLen = 0;
|
||||
|
||||
} else {
|
||||
/* Skip any spaces following the delimiter */
|
||||
const UNICHAR spaceStr[2] = {U_SPACE, U_NUL};
|
||||
int spaceCount = ucsspn(lto->outputLine+prefixCount+1, spaceStr);
|
||||
|
||||
promptLen = prefixCount + 1 + spaceCount;
|
||||
|
||||
LTERM_LOGUNICODE(ltermPromptLocate,41,(lto->outputLine, promptLen));
|
||||
}
|
||||
|
||||
return promptLen;
|
||||
}
|
|
@ -0,0 +1,560 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* ltermPrivate.h: Line terminal (LTERM) private header file
|
||||
* LTERM provides a "stream" interface to an XTERM-like terminal,
|
||||
* using line input/output.
|
||||
* CPP options:
|
||||
* LINUX: for Linux2.0/glibc
|
||||
* SOLARIS: for Solaris2.6
|
||||
* DEBUG: to enable some debugging output
|
||||
* NO_PTY: force use of pipes rather than PTY for process
|
||||
* communication
|
||||
* MOZILLA_CLIENT: set if embedded in Mozilla
|
||||
* USE_NSPR_BASE: use basic NSPR API (excluding I/O and process creation)
|
||||
* USE_NSPR_LOCK: use NSPR lock API instead of Unix mutex API
|
||||
* USE_NSPR_IO: use NSPR I/O and process API instead of Unix API
|
||||
* (current implementation of pseudo-TTY is incompatible with
|
||||
* the NSPR I/O API; set the USE_NSPR_IO option only on platforms
|
||||
* where PTYSTREAM is not implemented)
|
||||
*/
|
||||
|
||||
#ifndef _LTERMPRIVATE_H
|
||||
|
||||
#define _LTERMPRIVATE_H 1
|
||||
|
||||
/* Standard C header files */
|
||||
#ifndef _STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
/* public declarations */
|
||||
#include "lineterm.h"
|
||||
#include "tracelog.h"
|
||||
|
||||
/* private declarations */
|
||||
|
||||
/* Force use of basic NSPR API if MOZILLA_CLIENT or USE_NSPR_IO are defined */
|
||||
#if defined(MOZILLA_CLIENT) || defined(USE_NSPR_IO)
|
||||
#define USE_NSPR_BASE 1
|
||||
#endif
|
||||
|
||||
/* pseudo-TTY stream interface */
|
||||
#ifndef _PTYSTREAM_H
|
||||
#include "ptystream.h"
|
||||
#endif
|
||||
|
||||
#define LTERM_ERROR TLOG_ERROR
|
||||
#define LTERM_WARNING TLOG_WARNING
|
||||
#define LTERM_LOG(procname,level,args) TLOG_PRINT(LTERM_TLOG_MODULE,procname,level,args)
|
||||
#define LTERM_LOGUNICODE(procname,level,args) TLOG_UNICHAR(LTERM_TLOG_MODULE,procname,level,args)
|
||||
|
||||
#ifdef USE_NSPR_BASE /* Use basic NSPR API (excluding I/O) */
|
||||
|
||||
#include "nspr.h"
|
||||
|
||||
#define assert PR_ASSERT
|
||||
|
||||
#define int32 PRInt32
|
||||
|
||||
#define getenv PR_GetEnv
|
||||
|
||||
#define MALLOC(x) PR_Malloc(x)
|
||||
#define REALLOC(x,y) PR_Realloc((x),(y))
|
||||
#define CALLOC(x,y) PR_Calloc((x),(y))
|
||||
#define FREE(x) PR_Free(x)
|
||||
|
||||
#else /* not USE_NSPR_BASE */
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#define int32 long
|
||||
|
||||
#define MALLOC(x) malloc(x)
|
||||
#define REALLOC(x,y) realloc((x),(y))
|
||||
#define CALLOC(x,y) calloc((x),(y))
|
||||
#define FREE(x) free(x)
|
||||
|
||||
#endif /* not USE_NSPR_BASE */
|
||||
|
||||
|
||||
#ifdef USE_NSPR_IO /* Use NSPR I/O API (no PTY implementation) */
|
||||
|
||||
#ifdef LINUX
|
||||
#include <sys/poll.h>
|
||||
#endif
|
||||
|
||||
typedef PRFileDesc *FILEDESC;
|
||||
#define NULL_FILEDESC 0
|
||||
#define VALID_FILEDESC(x) (x != 0)
|
||||
|
||||
typedef PRFileDesc FILESTREAM;
|
||||
|
||||
#define SIZE_T PRInt32
|
||||
#define WRITE PR_Write
|
||||
#define READ PR_Read
|
||||
#define CLOSE(x) (PR_Close(x) != PR_SUCCESS)
|
||||
#define PIPE(x) (PR_CreatePipe((x),(x)+1) != PR_SUCCESS)
|
||||
|
||||
#define POLL(x,y,z) PR_Poll((x),(y),(z))
|
||||
#define POLLFD PRPollDesc
|
||||
#define POLL_EVENTS in_flags
|
||||
#define POLL_REVENTS out_flags
|
||||
#define POLL_READ PR_POLL_READ
|
||||
|
||||
#define PROCESS PRProcess *
|
||||
#define NULL_PROCESS 0
|
||||
#define VALID_PROCESS(x) (x != 0)
|
||||
|
||||
#else /* not USE_NSPR_IO */
|
||||
|
||||
/* system header files */
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
/* Diagnostic/debugging files */
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#if defined(SOLARIS)
|
||||
#include <poll.h>
|
||||
#elif defined(LINUX)
|
||||
#include <sys/poll.h>
|
||||
#endif
|
||||
|
||||
typedef int FILEDESC;
|
||||
#define NULL_FILEDESC -1
|
||||
#define VALID_FILEDESC(x) (x >= 0)
|
||||
|
||||
typedef FILE FILESTREAM;
|
||||
|
||||
#define SIZE_T size_t
|
||||
#define WRITE write
|
||||
#define READ read
|
||||
#define CLOSE(x) close(x)
|
||||
#define PIPE(x) pipe(x)
|
||||
|
||||
#define POLL(x,y,z) poll((x),(y),(z))
|
||||
#define POLLFD pollfd
|
||||
#define POLL_EVENTS events
|
||||
#define POLL_REVENTS revents
|
||||
#define POLL_READ POLLIN
|
||||
|
||||
#define PROCESS long
|
||||
#define NULL_PROCESS 0
|
||||
#define VALID_PROCESS(x) (x > 0)
|
||||
|
||||
#endif /* not USE_NSPR_IO */
|
||||
|
||||
|
||||
#ifdef USE_NSPR_LOCK /* Use NSPR lock API */
|
||||
|
||||
#define MUTEX_DECLARE(x) PRLock *x
|
||||
#define MUTEX_INITIALIZE(x) ((x=PR_NewLock()) == NULL)
|
||||
#define MUTEX_LOCK(x) PR_Lock(x)
|
||||
#define MUTEX_UNLOCK(x) PR_Unlock(x)
|
||||
#define MUTEX_DESTROY(x) PR_DestroyLock(x)
|
||||
|
||||
#define THREAD_DECLARE(x) PRThread *x
|
||||
#define THREAD_CREATE ((x=PR_CreateThread(PR_USER_THREAD, (y), (z), \
|
||||
PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, \
|
||||
PR_JOINABLE_THREAD, 0)) == NULL)
|
||||
#define THREAD_SELF PR_GetCurrentThread
|
||||
#define THREAD_EQUAL(x,y) ((x) == (y))
|
||||
#define THREAD_JOIN(x) (PR_JoinThread(x) != PR_SUCCESS)
|
||||
|
||||
#else /* not USE_NSPR_LOCK */
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#define MUTEX_DECLARE(x) pthread_mutex_t x
|
||||
#define MUTEX_INITIALIZE(x) pthread_mutex_init(&(x), NULL)
|
||||
#define MUTEX_LOCK(x) pthread_mutex_lock(&(x))
|
||||
#define MUTEX_UNLOCK(x) pthread_mutex_unlock(&(x))
|
||||
#define MUTEX_DESTROY(x) pthread_mutex_destroy(&(x))
|
||||
|
||||
#define THREAD_DECLARE(x) pthread_t x
|
||||
#define THREAD_CREATE(x,y,z) pthread_create(&(x),NULL,(y),(z))
|
||||
#define THREAD_SELF pthread_self
|
||||
#define THREAD_EQUAL(x,y) pthread_equal(x,y)
|
||||
#define THREAD_JOIN(x) pthread_join((x),NULL)
|
||||
|
||||
#endif /* not USE_NSPR_LOCK */
|
||||
|
||||
|
||||
#define MAXTERM 256 /* Maximum number of LTERMs;
|
||||
* affects static memory "footprint"
|
||||
*/
|
||||
|
||||
#define MAXCOL 4096 /* Maximum columns in line buffer;
|
||||
* affects static memory "footprint";
|
||||
* the only limitation on this value is that
|
||||
* it must fit into a UNICHAR, because of the
|
||||
* way lterm_write and ltermWrite implement
|
||||
* the input buffer pipe.
|
||||
*/
|
||||
|
||||
#define MAXROW 1024 /* Maximum rows in screen;
|
||||
* primarily affects dynamically allocated
|
||||
* memory
|
||||
*/
|
||||
|
||||
/* The only obvious limitation on the following is that they should be
|
||||
* significantly less than MAXCOL
|
||||
*/
|
||||
#define MAXPROMPT 256 /* Maximum length of prompt regexp+1 */
|
||||
#define MAXRAWINCOMPLETE 5 /* Maximum incomplete raw buffer size */
|
||||
#define MAXSTREAMTERM 11 /* Maximum stream terminator buffer size */
|
||||
#define MAXCOOKIESTR 64 /* Maximum length of cookie string+1 */
|
||||
#define MAXESCAPEPARAMS 16 /* Maximum no. of numeric ESCAPE parameters */
|
||||
#define MAXSTRINGPARAM 512 /* Maximum length of string ESCAPE parameters */
|
||||
|
||||
#define MAXPTYIN 128 /* 1/2 POSIX minimum MAX_INPUT for PTY */
|
||||
|
||||
#define MAXCOLM1 (MAXCOL-1) /* Maximum columns in line buffer - 1 */
|
||||
|
||||
#define MAXTTYCONTROL 8 /* Maximum TTY control character list */
|
||||
#define TTYINTERRUPT 0
|
||||
#define TTYERASE 1
|
||||
#define TTYKILL 2
|
||||
#define TTYEOF 3
|
||||
#define TTYSUSPEND 4
|
||||
#define TTYREPRINT 5
|
||||
#define TTYDISCARD 6
|
||||
#define TTYWERASE 7
|
||||
|
||||
/* input modes */
|
||||
#define LTERM0_RAW_MODE 0
|
||||
#define LTERM1_CANONICAL_MODE 1
|
||||
#define LTERM2_EDIT_MODE 2
|
||||
#define LTERM3_COMPLETION_MODE 3
|
||||
|
||||
/* completion request codes */
|
||||
#define LTERM_NO_COMPLETION 0
|
||||
#define LTERM_TAB_COMPLETION 1
|
||||
#define LTERM_HISTORY_COMPLETION 2
|
||||
|
||||
/* output modes */
|
||||
#define LTERM0_STREAM_MODE 0
|
||||
#define LTERM1_SCREEN_MODE 1
|
||||
#define LTERM2_LINE_MODE 2
|
||||
|
||||
/* character operation codes */
|
||||
#define LTERM_INSERT_CHAR 0
|
||||
#define LTERM_DELETE_CHAR 1
|
||||
#define LTERM_ERASE_CHAR 2
|
||||
|
||||
/* List of characters escaped in XML */
|
||||
#define LTERM_AMP_ESCAPE 0
|
||||
#define LTERM_LT_ESCAPE 1
|
||||
#define LTERM_GT_ESCAPE 2
|
||||
#define LTERM_QUOT_ESCAPE 3
|
||||
#define LTERM_APOS_ESCAPE 4
|
||||
|
||||
#define LTERM_XML_ESCAPES 5
|
||||
#define LTERM_PLAIN_ESCAPES 3
|
||||
|
||||
/* input buffer pipe header "character" count */
|
||||
#define PIPEHEADER 2
|
||||
|
||||
/* input buffer pipe header components */
|
||||
#define PHDR_CHARS 0
|
||||
#define PHDR_TYPE 1
|
||||
|
||||
/* LTERM read in/out parameter structure */
|
||||
struct LtermRead {
|
||||
UNICHAR *buf; /* Pointer to Unicode character buffer (IN param) */
|
||||
UNISTYLE *style; /* Pointer to character style buffer (IN param) */
|
||||
int max_count; /* max. number of characters in buffers (IN param) */
|
||||
int read_count; /* actual number of characters in buffers */
|
||||
int opcodes; /* Returned opcodes */
|
||||
int buf_row; /* row at which to display buffer data */
|
||||
int buf_col; /* starting column at which to display buffer data */
|
||||
int cursor_row; /* final cursor row position */
|
||||
int cursor_col; /* final cursor column position */
|
||||
};
|
||||
|
||||
/* LTERM input structure: managed by lterm_write */
|
||||
struct LtermInput {
|
||||
|
||||
UNICHAR inputBuf[PIPEHEADER+MAXCOL]; /* holds data read from input buffer
|
||||
* pipe
|
||||
*/
|
||||
int inputBufBytes; /* Count of bytes already read in */
|
||||
|
||||
int inputMode; /* input mode:
|
||||
* 0 = raw mode
|
||||
* 1 = canonical mode
|
||||
* 2 = edit + canonical mode
|
||||
* 3 = completion + edit + canonical mode
|
||||
*/
|
||||
|
||||
int escapeFlag; /* processing ESCAPE in line mode */
|
||||
int escapeCSIFlag; /* processing ESCAPE Code Sequence Introducer */
|
||||
int escapeCSIArg; /* ESCAPE Code Sequence Argument value */
|
||||
|
||||
int inputOpcodes; /* input opcodes */
|
||||
|
||||
int clearInputLine; /* true if input line buffer needs to be
|
||||
* cleared (after echoing) */
|
||||
|
||||
UNICHAR inputLine[MAXCOL]; /* input line buffer:
|
||||
only MAXCOL-1 characters should actually
|
||||
be inserted in the buffer, to allow
|
||||
one character padding if necessary */
|
||||
|
||||
int inputChars; /* length of input line (characters);
|
||||
* should never exceed MAXCOL-1,
|
||||
* to allow for null termination
|
||||
*/
|
||||
int inputCols; /* number of displayed columns in input line;
|
||||
* a column corresponds to a single
|
||||
* plain text character transmitted to the
|
||||
* subordinate process, although it may occupy
|
||||
* multiple character positions, e.g.,
|
||||
* e.g., < represents "<"
|
||||
*/
|
||||
int inputGlyphs; /* number of displayed glyphs in input line;
|
||||
* a glyph corresponds to a logical column
|
||||
* on the layout, i.e., a single Unicode
|
||||
* character or an XML element, such as an
|
||||
* iconic representiion of an URI.
|
||||
*/
|
||||
|
||||
unsigned short inputColCharIndex[MAXCOL]; /* starting character index of
|
||||
* each column, including the
|
||||
* cursor column at end of line.
|
||||
* (inputCols+1 values should be
|
||||
* defined)
|
||||
*/
|
||||
|
||||
unsigned short inputGlyphCharIndex[MAXCOL]; /* starting character index
|
||||
* of each glyph, including
|
||||
* empty glyph at the end of
|
||||
* the line.
|
||||
* (inputGlyphs+1 values
|
||||
* should be defined)
|
||||
*/
|
||||
unsigned short inputGlyphColIndex[MAXCOL]; /* starting column index of
|
||||
* each glyph
|
||||
* (inputGlyphs+1 values)
|
||||
*/
|
||||
|
||||
int inputCursorGlyph; /* current input cursor glyph number (>=0) */
|
||||
};
|
||||
|
||||
/* LtermOutput poll structure index count and values */
|
||||
#define POLL_COUNT 3
|
||||
#define POLL_INPUTBUF 0
|
||||
#define POLL_STDOUT 1
|
||||
#define POLL_STDERR 2
|
||||
|
||||
/* LTERM output structure: managed by lterm_read */
|
||||
struct LtermOutput {
|
||||
struct POLLFD pollFD[POLL_COUNT]; /* output polling structure */
|
||||
long callbackTag[POLL_COUNT]; /* GTK callback tag for each FD (0 if none) */
|
||||
int nfds; /* count of "files" to be polled */
|
||||
int outputMode; /* output mode:
|
||||
* 0 = full screen mode
|
||||
* 1 = line mode
|
||||
* 2 = command line mode
|
||||
*/
|
||||
|
||||
UNICHAR streamTerminator[MAXSTREAMTERM]; /* stream terminator buffer */
|
||||
int streamOpcodes; /* Stream opcodes */
|
||||
int savedOutputMode; /* saved output mode (prior to stream mode) */
|
||||
|
||||
int insertMode; /* character insert mode */
|
||||
int automaticNewline; /* automatic newline mode */
|
||||
|
||||
UNISTYLE styleMask; /* current output style mask */
|
||||
|
||||
char rawOUTBuf[MAXRAWINCOMPLETE]; /* incomplete raw STDOUT buffer */
|
||||
int rawOUTBytes; /* incomplete raw STDOUT byte count */
|
||||
|
||||
char rawERRBuf[MAXRAWINCOMPLETE]; /* incomplete raw STDERR buffer */
|
||||
int rawERRBytes; /* incomplete raw STDERR byte count */
|
||||
|
||||
UNICHAR decodedOutput[MAXCOL]; /* decoded output buffer:
|
||||
only MAXCOL-1 characters should actually
|
||||
be inserted in the buffer, to allow
|
||||
one character padding if necessary */
|
||||
UNISTYLE decodedStyle[MAXCOL]; /* decoded output style buffer */
|
||||
int decodedChars; /* decoded character count;
|
||||
should never exceed MAXCOL-1 */
|
||||
int incompleteEscapeSequence; /* Incomplete ESCAPE sequence flag */
|
||||
|
||||
UNICHAR outputLine[MAXCOL]; /* output line buffer (processed);
|
||||
only MAXCOL-1 characters should actually
|
||||
be inserted in the buffer, to allow
|
||||
one character padding if necessary */
|
||||
UNISTYLE outputStyle[MAXCOL]; /* output style buffer for each character */
|
||||
|
||||
int outputChars; /* length of output line (characters)
|
||||
should never exceed MAXCOL-1 */
|
||||
int outputCursorChar; /* output cursor character position (>=0) */
|
||||
int promptChars; /* prompt character count */
|
||||
int outputModifiedChar; /* leftmost modified character in output line */
|
||||
|
||||
int cursorRow, cursorCol; /* screen cursor row and column */
|
||||
|
||||
int rowCols[MAXROW]; /* count of columns in each row (>=0) */
|
||||
|
||||
int modifiedCol[MAXROW]; /* first modified column in each row;
|
||||
-1 if no column has been modified */
|
||||
|
||||
UNICHAR *screenChar; /* Screen character array (screenSize long) */
|
||||
UNISTYLE *screenStyle; /* Screen style array (screenSize long) */
|
||||
};
|
||||
|
||||
/* LTERM process structure: managed by lterm_create, lterm_close */
|
||||
struct LtermProcess {
|
||||
PROCESS processID; /* process ID */
|
||||
FILEDESC processIN; /* process input pipe */
|
||||
FILEDESC processOUT; /* process output pipe */
|
||||
FILEDESC processERR; /* process error pipe */
|
||||
};
|
||||
|
||||
/* line terminal (LTERM) structure: managed by lterm_open, lterm_close */
|
||||
struct lterms {
|
||||
int opened; /* LTERM opened status flag */
|
||||
int suspended; /* LTERM suspended flag:
|
||||
* an LTERM is suspended when an error
|
||||
* occurs, to prevent further I/O operations
|
||||
* which have unpredictable results.
|
||||
* The LTERM still needs to be closed to
|
||||
* release any resources used by it.
|
||||
* (a suspended LTERM is still open)
|
||||
*/
|
||||
|
||||
MUTEX_DECLARE(adminMutex); /* LTERM administrative mutex */
|
||||
MUTEX_DECLARE(outputMutex); /* LTERM output thread mutex */
|
||||
|
||||
int adminMutexLocked; /* administrative mutex lock status */
|
||||
int outputMutexLocked; /* output mutex lock status */
|
||||
|
||||
FILEDESC writeBUFFER, readBUFFER; /* input character BUFFER pipe */
|
||||
|
||||
int options; /* TTY options */
|
||||
int ptyMode; /* pseudo-TTY mode flag */
|
||||
int noTTYEcho; /* no TTY echo flag */
|
||||
int disabledInputEcho; /* disabled input echo flag */
|
||||
|
||||
int processType; /* Process type code */
|
||||
int maxInputMode; /* maximum allowed input mode value */
|
||||
int readERRfirst; /* Read STDERR before STDOUT */
|
||||
int interleave; /* interleave STDERR/STDOUT flag */
|
||||
UNICHAR control[MAXTTYCONTROL]; /* TTY control characters */
|
||||
|
||||
int commandNumber; /* output command number
|
||||
* (0 if not command line)
|
||||
*/
|
||||
unsigned short lastCommandNum; /* last command number */
|
||||
int completionRequest; /* command completion request code:
|
||||
* LTERM_NO_COMPLETION, or
|
||||
* LTERM_TAB_COMPLETION, or
|
||||
* LTERM_HISTORY_COMPLETION
|
||||
*/
|
||||
int completionChars; /* command completion insert count */
|
||||
|
||||
int inputBufRecord; /* True if input buffer contains record */
|
||||
|
||||
int inputLineBreak; /* True if input line was transmitted
|
||||
* and plain text copy saved in echo buffer
|
||||
*/
|
||||
UNICHAR echoLine[MAXCOL]; /* Plain text of echo line */
|
||||
int echoChars; /* Count of echo characters */
|
||||
|
||||
int nRows; /* Number of rows */
|
||||
int nCols; /* Number of columns */
|
||||
long screenSize; /* Screen size, in characters
|
||||
= nRows*nCols */
|
||||
|
||||
UNICHAR promptRegexp[MAXPROMPT]; /* prompt regular expression
|
||||
JUST A LIST OF DELIMITERS AT PRESENT */
|
||||
|
||||
char cookie[MAXCOOKIESTR]; /* cookie string */
|
||||
|
||||
struct ptys pty; /* pseudo-tty (PTY) stream info for LTERM */
|
||||
struct LtermProcess ltermProcess; /* LTERM process structure */
|
||||
struct LtermInput ltermInput; /* LTERM input structure */
|
||||
struct LtermOutput ltermOutput; /* LTERM output structure */
|
||||
};
|
||||
|
||||
/* LTERM global variables */
|
||||
typedef struct {
|
||||
int initialized; /* Initialization flag */
|
||||
struct lterms *termList[MAXTERM]; /* List of LTERMS */
|
||||
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 */
|
||||
int escapeLen[LTERM_XML_ESCAPES]; /* XML char. escape sequence lengths */
|
||||
} LtermGlobal;
|
||||
|
||||
extern LtermGlobal ltermGlobal;
|
||||
|
||||
|
||||
/* Visible prototypes */
|
||||
|
||||
/* ltermIO.c */
|
||||
int ltermSendLine(struct lterms *lts, UNICHAR uch,
|
||||
int echoControl, int completionCode);
|
||||
int ltermRead(struct lterms *lts, struct LtermRead *ltr, int timeout);
|
||||
|
||||
/* ltermInput.c */
|
||||
int ltermPlainTextInput(struct lterms *lts,
|
||||
const UNICHAR *buf, int count, int *opcodes);
|
||||
int ltermCancelCompletion(struct lterms *lts);
|
||||
int ltermInsertChar(struct LtermInput *lti, UNICHAR uch);
|
||||
void ltermSwitchToRawMode(struct lterms *lts);
|
||||
void ltermClearInputLine(struct lterms *lts);
|
||||
int ltermDeleteGlyphs(struct LtermInput *lti, int count);
|
||||
int ltermSendData(struct lterms *lts, const UNICHAR *buf, int count);
|
||||
|
||||
/* ltermOutput.c */
|
||||
int ltermProcessOutput(struct lterms *lts, int *opcodes);
|
||||
int ltermReceiveData(struct lterms *lts, int readERR);
|
||||
void ltermClearOutputLine(struct lterms *lts);
|
||||
int ltermClearOutputScreen(struct lterms *lts);
|
||||
int ltermSwitchToStreamMode(struct lterms *lts, int streamOpcodes,
|
||||
const UNICHAR *streamTerminator);
|
||||
int ltermSwitchToScreenMode(struct lterms *lts);
|
||||
int ltermSwitchToLineMode(struct lterms *lts);
|
||||
|
||||
/* ltermEscape.c */
|
||||
int ltermProcessEscape(struct lterms *lts, const UNICHAR *buf,
|
||||
int count, const UNISTYLE *style, int *consumed, int *opcodes);
|
||||
int ltermInsDelEraseChar(struct lterms *lts, int count, int action);
|
||||
|
||||
#endif /* _LTERMPRIVATE_H */
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
/* mozILineTerm.idl: Javascript-accessible interface to LineTerm
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "domstubs.idl"
|
||||
|
||||
%{C++
|
||||
class nsIDOMDocument;
|
||||
%}
|
||||
|
||||
[scriptable, uuid(0eb82b00-43a2-11d3-8e76-006008948af5)]
|
||||
|
||||
interface mozILineTerm : nsISupports
|
||||
{
|
||||
attribute long cursorRow;
|
||||
attribute long cursorColumn;
|
||||
attribute boolean echoFlag;
|
||||
|
||||
/** Opens LineTerm, a line-oriented terminal interface (without graphics)
|
||||
* @param command name of command to be executed; usually a shell,
|
||||
* e.g., "/bin/sh"; if set to null string, the command name is
|
||||
* determined from the environment variable SHELL
|
||||
* @param promptRegexp command prompt regular expression (for future use);
|
||||
* at the moment, any string terminated by one of the characters
|
||||
* "#$%>?", followed by a space, is assumed to be a prompt
|
||||
* @param options LineTerm option bits (usually 0; see lineterm.h)
|
||||
* @param processType command shell type; if set to -1, type is determined
|
||||
* from the command name
|
||||
* @param domDoc DOM document object associated with the LineTerm
|
||||
* (document.cookie will be defined for this document on return)
|
||||
*/
|
||||
void Open(in wstring command, in wstring promptRegexp,
|
||||
in PRInt32 options, in PRInt32 processType,
|
||||
in nsIDOMDocument domDoc);
|
||||
|
||||
/** Closes LineTerm
|
||||
* @param aCookie document.cookie string for authentication
|
||||
*/
|
||||
void Close(in wstring aCookie);
|
||||
|
||||
/** Writes string to LineTerm as if the user had typed it (command input)
|
||||
* @param buf string to be transmitted to LineTerm
|
||||
* @param aCookie document.cookie string for authentication
|
||||
*/
|
||||
void Write(in wstring buf, in wstring aCookie);
|
||||
|
||||
/** Read output data string and parameters from LineTerm (command output)
|
||||
* @param opcodes (output) output data descriptor bits (see lineterm.h)
|
||||
* @param buf_row (output) row number (>=-1)
|
||||
(-1 denotes line mode and 0 represents bottom row)
|
||||
* @param buf_col (output) column number (>=0)
|
||||
* @param aCookie document.cookie string for authentication
|
||||
* @return output data string from LineTerm
|
||||
*/
|
||||
wstring Read(out PRInt32 opcodes, out PRInt32 buf_row,
|
||||
out PRInt32 buf_col, in wstring aCookie);
|
||||
};
|
||||
|
||||
|
||||
%{ C++
|
||||
#define MOZLINETERM_CID \
|
||||
{ /* 0eb82b01-43a2-11d3-8e76-006008948af5 */ \
|
||||
0x0eb82b01, 0x43a2, 0x11d3, \
|
||||
{0x8e, 0x76, 0x00, 0x60, 0x08, 0x94, 0x8a, 0xf5} }
|
||||
|
||||
extern nsresult
|
||||
NS_NewLineTerm(mozILineTerm** aLineTerm);
|
||||
%}
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozILineTermAux.h: auxiliary interface for LineTerm (not XPCONNECTed)
|
||||
// This adds some XPCOM-only methods to the XPCOM/XPCONNECT interface
|
||||
// mozILineTerm (unregistered)
|
||||
|
||||
#ifndef mozILineTermAux_h___
|
||||
#define mozILineTermAux_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
#include "nsIObserver.h"
|
||||
#include "mozILineTerm.h"
|
||||
|
||||
/* {0eb82b10-43a2-11d3-8e76-006008948af5} */
|
||||
#define MOZILINETERMAUX_IID_STR "0eb82b10-43a2-11d3-8e76-006008948af5"
|
||||
#define MOZILINETERMAUX_IID \
|
||||
{0x0eb82b10, 0x43a2, 0x11d3, \
|
||||
{ 0x8e, 0x76, 0x00, 0x60, 0x08, 0x94, 0x8a, 0xf5 }}
|
||||
|
||||
class mozILineTermAux : public mozILineTerm {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(MOZILINETERMAUX_IID)
|
||||
|
||||
// mozILineTerm interface
|
||||
NS_IMETHOD GetCursorRow(PRInt32 *aCursorRow) = 0;
|
||||
NS_IMETHOD SetCursorRow(PRInt32 aCursorRow) = 0;
|
||||
|
||||
NS_IMETHOD GetCursorColumn(PRInt32 *aCursorColumn) = 0;
|
||||
NS_IMETHOD SetCursorColumn(PRInt32 aCursorColumn) = 0;
|
||||
|
||||
NS_IMETHOD Open(const PRUnichar *command,
|
||||
const PRUnichar *promptRegexp,
|
||||
PRInt32 options, PRInt32 processType,
|
||||
nsIDOMDocument *domDoc) = 0;
|
||||
|
||||
NS_IMETHOD Close(const PRUnichar* aCookie) = 0;
|
||||
|
||||
NS_IMETHOD Write(const PRUnichar *buf, const PRUnichar* aCookie) = 0;
|
||||
|
||||
NS_IMETHOD Read(PRInt32 *opcodes,
|
||||
PRInt32 *buf_row, PRInt32 *buf_col,
|
||||
const PRUnichar* aCookie,
|
||||
PRUnichar **_retval) = 0;
|
||||
|
||||
// mozILineTermAux interface add ons
|
||||
// (not scriptable, no authentication cookie required)
|
||||
|
||||
/** Opens LineTerm, a line-oriented terminal interface (without graphics)
|
||||
* @param command name of command to be executed; usually a shell,
|
||||
* e.g., "/bin/sh"; if set to null string, the command name is
|
||||
* determined from the environment variable SHELL
|
||||
* @param promptRegexp command prompt regular expression (for future use);
|
||||
* at the moment, any string terminated by one of the characters
|
||||
* "#$%>?", followed by a space, is assumed to be a prompt
|
||||
* @param options LineTerm option bits (usually 0; see lineterm.h)
|
||||
* @param processType command shell type; if set to -1, type is determined
|
||||
* from the command name
|
||||
* @param domDoc DOM document object associated with the LineTerm
|
||||
* (document.cookie will be defined for this document on return)
|
||||
* @param aCookie (output) cookie associated with LineTerm
|
||||
*/
|
||||
NS_IMETHOD OpenAux(const PRUnichar *command,
|
||||
const PRUnichar *promptRegexp,
|
||||
PRInt32 options, PRInt32 processType,
|
||||
nsIDOMDocument *domDoc,
|
||||
nsIObserver* anObserver,
|
||||
nsString& aCookie) = 0;
|
||||
|
||||
/** Suspend/restores LineTerm operation
|
||||
* @param aSuspend suspension state flag
|
||||
*/
|
||||
NS_IMETHOD SuspendAux(PRBool aSuspend) = 0;
|
||||
|
||||
/** Closes LineTerm
|
||||
*/
|
||||
NS_IMETHOD CloseAux(void) = 0;
|
||||
|
||||
/** Close all LineTerms, not just this one
|
||||
*/
|
||||
NS_IMETHOD CloseAllAux(void) = 0;
|
||||
|
||||
/** Read output data and style strings and parameters from LineTerm
|
||||
* @param opcodes (output) output data descriptor bits (see lineterm.h)
|
||||
* @param buf_row (output) row number (>=-1)
|
||||
(-1 denotes line mode and 0 represents bottom row)
|
||||
* @param buf_col (output) column number (>=0)
|
||||
* @param _retval (output) success code
|
||||
* @param retstyle (output) output style string
|
||||
* @return output data string from LineTerm
|
||||
*/
|
||||
NS_IMETHOD ReadAux(PRInt32 *opcodes,
|
||||
PRInt32 *buf_row, PRInt32 *buf_col,
|
||||
PRUnichar **_retval, PRUnichar **retstyle) = 0;
|
||||
};
|
||||
|
||||
// Factory for mozILineTermAux
|
||||
|
||||
extern nsresult
|
||||
NS_NewLineTermAux(mozILineTermAux** aLineTermAux);
|
||||
|
||||
#endif /* mozILineTermAux_h___ */
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
/* mozIXMLTermShell.idl: Javascript-accessible wrapper for mozIXMLTerminal
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "domstubs.idl"
|
||||
#include "mozILineTerm.idl"
|
||||
|
||||
%{C++
|
||||
class nsILineTerm;
|
||||
class nsIDOMWindow;
|
||||
%}
|
||||
|
||||
[scriptable, uuid(0eb82b30-43a2-11d3-8e76-006008948af5)]
|
||||
|
||||
interface mozIXMLTermShell : nsISupports
|
||||
{
|
||||
readonly attribute long currentEntryNumber; /* current entry (command) no. */
|
||||
attribute long history; /* command history buffer count */
|
||||
attribute wstring prompt; /* HTML prompt string */
|
||||
|
||||
/** Initializes XMLterm in specified window
|
||||
* @param contentWin content window object
|
||||
* @param URL URL of document to be loaded in the window
|
||||
* (set to null string if document is already loaded in window)
|
||||
* @param args argument string to be passed to XMLterm
|
||||
* (at the moment this just contains any initial input data)
|
||||
*/
|
||||
void Init(in nsIDOMWindow contentWin, in wstring URL, in wstring args);
|
||||
|
||||
/** Finalizes (closes) XMLterm
|
||||
*/
|
||||
void Finalize();
|
||||
|
||||
/** Polls for readable data from XMLterm
|
||||
*/
|
||||
void Poll();
|
||||
|
||||
/** Writes string to terminal as if the user had typed it (command input)
|
||||
* @param buf string to be transmitted to terminal
|
||||
* @param aCookie document.cookie string for authentication
|
||||
*/
|
||||
void SendText(in wstring buf, in wstring cookie);
|
||||
|
||||
/** Opens new XMLterm window with specified args (not yet implemented)
|
||||
* @param args argument string to be passed to XMLterm
|
||||
* (at the moment this just contains any initial input data)
|
||||
*/
|
||||
void NewXMLTermWindow(in wstring args);
|
||||
|
||||
/** Exit browser, closing all windows (not yet implemented)
|
||||
*/
|
||||
void Exit();
|
||||
};
|
||||
|
||||
|
||||
%{C++
|
||||
|
||||
#define MOZXMLTERMSHELL_CID \
|
||||
{ /* 0eb82b31-43a2-11d3-8e76-006008948af5 */ \
|
||||
0x0eb82b31, 0x43a2, 0x11d3, \
|
||||
{0x8e, 0x76, 0x00, 0x60, 0x08, 0x94, 0x8a, 0xf5} }
|
||||
|
||||
extern nsresult
|
||||
NS_NewXMLTermShell(mozIXMLTermShell** aXMLTermShell);
|
||||
%}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozIXMLTermStream.h: interface to display HTML/XML streams as documents
|
||||
// (unregistered)
|
||||
|
||||
#ifndef mozIXMLTermStream_h___
|
||||
#define mozIXMLTermStream_h___
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIInputStream.h"
|
||||
|
||||
/* {0eb82b40-43a2-11d3-8e76-006008948af5} */
|
||||
#define MOZIXMLTERMSTREAM_IID_STR "0eb82b40-43a2-11d3-8e76-006008948af5"
|
||||
#define MOZIXMLTERMSTREAM_IID \
|
||||
{0x0eb82b40, 0x43a2, 0x11d3, \
|
||||
{ 0x8e, 0x76, 0x00, 0x60, 0x08, 0x94, 0x8a, 0xf5 }}
|
||||
|
||||
class mozIXMLTermStream : public nsIInputStream
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(MOZIXMLTERMSTREAM_IID);
|
||||
|
||||
// mozIXMLTermStream interface
|
||||
|
||||
/** Open stream in specified frame, or in current frame if frameName is null
|
||||
* @param aDOMWindow parent window
|
||||
* @param frameName name of child frame in which to display stream, or null
|
||||
* to display in parent window
|
||||
* @param contentURL URL of stream content
|
||||
* @param contentType MIME type of stream content
|
||||
* @param maxResizeHeight maximum resize height (0=> do not resize)
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
NS_IMETHOD Open(nsIDOMWindow* aDOMWindow,
|
||||
const char* frameName,
|
||||
const char* contentURL,
|
||||
const char* contentType,
|
||||
PRInt32 maxResizeHeight) = 0;
|
||||
|
||||
/** Write Unicode string to stream (blocks until write is completed)
|
||||
* @param buf string to write
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
NS_IMETHOD Write(const PRUnichar* buf) = 0;
|
||||
};
|
||||
|
||||
#define MOZXMLTERMSTREAM_CID \
|
||||
{ /* 0eb82b41-43a2-11d3-8e76-006008948af5 */ \
|
||||
0x0eb82b41, 0x43a2, 0x11d3, \
|
||||
{0x8e, 0x76, 0x00, 0x60, 0x08, 0x94, 0x8a, 0xf5} }
|
||||
extern nsresult
|
||||
NS_NewXMLTermStream(mozIXMLTermStream** aXMLTermStream);
|
||||
|
||||
#endif /* mozIXMLTermStream_h___ */
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozIXMLTerminal.h: primary interface for XMLterm operations
|
||||
// (unregistered)
|
||||
|
||||
#ifndef mozIXMLTerminal_h___
|
||||
#define mozIXMLTerminal_h___
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIScriptContext.h"
|
||||
|
||||
#include "mozIXMLTermShell.h"
|
||||
|
||||
/* {0eb82b20-43a2-11d3-8e76-006008948af5} */
|
||||
#define MOZIXMLTERMINAL_IID_STR "0eb82b20-43a2-11d3-8e76-006008948af5"
|
||||
#define MOZIXMLTERMINAL_IID \
|
||||
{0x0eb82b20, 0x43a2, 0x11d3, \
|
||||
{ 0x8e, 0x76, 0x00, 0x60, 0x08, 0x94, 0x8a, 0xf5 }}
|
||||
|
||||
class mozIXMLTerminal : public nsISupports {
|
||||
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(MOZIXMLTERMINAL_IID)
|
||||
|
||||
/** Initializes XMLterm in specified web shell
|
||||
* @param aWebShell web shell in which to embed XMLterm
|
||||
* @param aXMLTermShell scriptable wrapper shell for XMLterm
|
||||
* @param URL URL of document to be loaded in the window
|
||||
* (set to null string if document is already loaded in window)
|
||||
* @param args argument string to be passed to XMLterm
|
||||
* (at the moment this just contains any initial input data)
|
||||
*/
|
||||
NS_IMETHOD Init(nsIWebShell* aWebShell,
|
||||
mozIXMLTermShell* aXMLTermShell,
|
||||
const PRUnichar* aURL,
|
||||
const PRUnichar* args) = 0;
|
||||
|
||||
/** Finalizes (closes) XMLterm
|
||||
*/
|
||||
NS_IMETHOD Finalize(void) = 0;
|
||||
|
||||
/** Polls for readable data from XMLterm
|
||||
*/
|
||||
NS_IMETHOD Poll(void) = 0;
|
||||
|
||||
/** Gets current entry (command) number
|
||||
* @param aNumber (output) current entry number
|
||||
*/
|
||||
NS_IMETHOD GetCurrentEntryNumber(PRInt32 *aNumber) = 0;
|
||||
|
||||
/** Gets command history buffer count
|
||||
* @param aHistory (output) history buffer count
|
||||
*/
|
||||
NS_IMETHOD GetHistory(PRInt32 *aHistory) = 0;
|
||||
|
||||
/** Sets command history buffer count
|
||||
* @param aHistory history buffer count
|
||||
*/
|
||||
NS_IMETHOD SetHistory(PRInt32 aHistory) = 0;
|
||||
|
||||
/** Gets prompt string
|
||||
* @param aPrompt (output) prompt string
|
||||
*/
|
||||
NS_IMETHOD GetPrompt(PRUnichar **aPrompt) = 0;
|
||||
|
||||
/** Sets prompt string
|
||||
* @param aPrompt prompt string
|
||||
*/
|
||||
NS_IMETHOD SetPrompt(const PRUnichar* aPrompt) = 0;
|
||||
|
||||
/** Writes string to terminal as if the user had typed it (without authenitcation)
|
||||
* @param aString string to be transmitted to terminal
|
||||
*/
|
||||
NS_IMETHOD SendTextAux(const nsString& aString) = 0;
|
||||
|
||||
/** Writes string to terminal as if the user had typed it (command input)
|
||||
* @param aString string to be transmitted to terminal
|
||||
* @param aCookie document.cookie string for authentication
|
||||
*/
|
||||
NS_IMETHOD SendText(const nsString& aString, const PRUnichar* aCookie) = 0;
|
||||
|
||||
/** Paste data from clipboard into XMLterm at current input line cursor location
|
||||
*/
|
||||
NS_IMETHOD Paste() = 0;
|
||||
|
||||
/** Gets document associated with XMLterm
|
||||
* @param aDoc (output) DOM document
|
||||
*/
|
||||
NS_IMETHOD GetDocument(nsIDOMDocument** aDoc) = 0;
|
||||
|
||||
/** Gets presentation shell with XMLterm
|
||||
* @param aPresShell (output) presentation shell
|
||||
*/
|
||||
NS_IMETHOD GetPresShell(nsIPresShell** aPresShell) = 0;
|
||||
};
|
||||
|
||||
#define MOZXMLTERMINAL_CID \
|
||||
{ /* 0eb82b21-43a2-11d3-8e76-006008948af5 */ \
|
||||
0x0eb82b21, 0x43a2, 0x11d3, \
|
||||
{0x8e, 0x76, 0x00, 0x60, 0x08, 0x94, 0x8a, 0xf5} }
|
||||
extern nsresult
|
||||
NS_NewXMLTerminal(mozIXMLTerminal** aXMLTerminal);
|
||||
|
||||
#endif /* mozIXMLTerminal_h___ */
|
|
@ -0,0 +1,681 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozLineTerm.cpp: class implementing mozILineTerm/mozILineTermAux interfaces,
|
||||
// providing an XPCOM/XPCONNECT wrapper for the LINETERM module
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nscore.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "prlog.h"
|
||||
#include "nsIAllocator.h"
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIPrincipal.h"
|
||||
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMHTMLDocument.h"
|
||||
|
||||
#include "mozXMLT.h"
|
||||
#include "mozXMLTermUtils.h"
|
||||
#include "mozLineTerm.h"
|
||||
#include "lineterm.h"
|
||||
|
||||
#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_IID(kILineTermIID, MOZILINETERM_IID);
|
||||
static NS_DEFINE_IID(kILineTermAuxIID, MOZILINETERMAUX_IID);
|
||||
|
||||
static NS_DEFINE_IID(kLineTermCID, MOZLINETERM_CID);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// mozLineTerm, mozLineTermAux factories
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewLineTerm(mozILineTerm** aLineTerm)
|
||||
{
|
||||
NS_PRECONDITION(aLineTerm != nsnull, "null ptr");
|
||||
if (! aLineTerm)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aLineTerm = new mozLineTerm();
|
||||
if (! *aLineTerm)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aLineTerm);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewLineTermAux(mozILineTermAux** aLineTermAux)
|
||||
{
|
||||
NS_PRECONDITION(aLineTermAux != nsnull, "null ptr");
|
||||
if (! aLineTermAux)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aLineTermAux = new mozLineTerm();
|
||||
if (! *aLineTermAux)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aLineTermAux);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// mozLineTerm implementaion
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
PRBool mozLineTerm::mLoggingEnabled = false;
|
||||
|
||||
mozLineTerm::mozLineTerm() :
|
||||
mCursorRow(0),
|
||||
mCursorColumn(0),
|
||||
mSuspended(false),
|
||||
mEchoFlag(true),
|
||||
mObserver(nsnull),
|
||||
mCookie(""),
|
||||
mLastTime(LL_ZERO)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mLTerm = lterm_new();
|
||||
}
|
||||
|
||||
|
||||
mozLineTerm::~mozLineTerm()
|
||||
{
|
||||
lterm_delete(mLTerm);
|
||||
mObserver = nsnull;
|
||||
}
|
||||
|
||||
|
||||
// Implement AddRef and Release
|
||||
NS_IMPL_ADDREF(mozLineTerm)
|
||||
NS_IMPL_RELEASE(mozLineTerm)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozLineTerm::QueryInterface(REFNSIID aIID,void** aInstancePtr)
|
||||
{
|
||||
if (aInstancePtr == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
//XMLT_LOG(mozLineTerm::QueryInterface,30,("0x%x\n",aIID));
|
||||
|
||||
if ( aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsISupports*,
|
||||
NS_STATIC_CAST(mozILineTermAux*,this));
|
||||
|
||||
} else if ( aIID.Equals(mozILineTerm::GetIID()) ) {
|
||||
*aInstancePtr = NS_STATIC_CAST(mozILineTerm*,
|
||||
NS_STATIC_CAST(mozILineTermAux*,this));
|
||||
|
||||
} else if ( aIID.Equals(mozILineTermAux::GetIID()) ) {
|
||||
*aInstancePtr = NS_STATIC_CAST(mozILineTermAux*,this);
|
||||
|
||||
} else {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Checks if preference settings are secure for LineTerm creation and use
|
||||
*/
|
||||
NS_IMETHODIMP mozLineTerm::ArePrefsSecure(PRBool *_retval)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
XMLT_LOG(mozLineTerm::ArePrefsSecure,30,("\n"));
|
||||
|
||||
if (!_retval)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*_retval = false;
|
||||
|
||||
nsIPref* prefService;
|
||||
nsServiceManager::GetService(kPrefServiceCID, NS_GET_IID(nsIPref),
|
||||
(nsISupports**) &prefService);
|
||||
if (!prefService)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Check if Components JS object is secure
|
||||
PRBool checkXPC;
|
||||
result = prefService->GetBoolPref("security.checkxpconnect", &checkXPC);
|
||||
if (NS_FAILED(result))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (!checkXPC) {
|
||||
XMLT_ERROR("mozLineTerm::ArePrefsSecure: Error - Please add the line\n"
|
||||
" pref(\"security.checkxpcconnect\",true);\n"
|
||||
"to your preferences file (.mozilla/prefs.js)\n");
|
||||
*_retval = false;
|
||||
#if 0 // Temporarily comented out
|
||||
return NS_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
nsCAutoString secString ("security.policy.");
|
||||
/* Get global policy name. */
|
||||
char *policyStr;
|
||||
|
||||
result = prefService->CopyCharPref("javascript.security_policy", &policyStr);
|
||||
if (NS_SUCCEEDED(result) && policyStr) {
|
||||
secString.Append(policyStr);
|
||||
nsAllocator::Free(policyStr);
|
||||
} else {
|
||||
secString.Append("default");
|
||||
}
|
||||
|
||||
secString.Append(".htmldocument.cookie");
|
||||
|
||||
char* prefStr = secString.ToNewCString();
|
||||
XMLT_LOG(mozLineTerm::ArePrefsSecure,32, ("prefStr=%s\n", prefStr));
|
||||
|
||||
char *secLevelString;
|
||||
result = prefService->CopyCharPref(prefStr, &secLevelString);
|
||||
nsAllocator::Free(prefStr);
|
||||
|
||||
if (NS_FAILED(result) || !secLevelString)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
XMLT_LOG(mozLineTerm::ArePrefsSecure,32,
|
||||
("secLevelString=%s\n", secLevelString));
|
||||
|
||||
*_retval = (PL_strcmp(secLevelString, "sameOrigin") == 0);
|
||||
nsAllocator::Free(secLevelString);
|
||||
|
||||
if (!(*_retval)) {
|
||||
XMLT_ERROR("mozLineTerm::ArePrefsSecure: Error - Please add the line\n"
|
||||
" pref(\"security.policy.default.htmldocument.cookie\",\"sameOrigin\");\n"
|
||||
"to your preferences file (.mozilla/prefs.js)\n");
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Checks document principal to ensure it has LineTerm creation privileges.
|
||||
* Returns the principal string if the principal is secure,
|
||||
* and a (zero length) null string if the principal is insecure.
|
||||
*/
|
||||
NS_IMETHODIMP mozLineTerm::GetSecurePrincipal(nsIDOMDocument *domDoc,
|
||||
char** aPrincipalStr)
|
||||
{
|
||||
XMLT_LOG(mozLineTerm::GetSecurePrincipal,30,("\n"));
|
||||
|
||||
if (!aPrincipalStr)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*aPrincipalStr = nsnull;
|
||||
|
||||
// Get principal string
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
||||
if (!doc)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIPrincipal> principal=dont_AddRef(doc->GetDocumentPrincipal());
|
||||
|
||||
#if 0 // Temporarily comented out, because ToString is not immplemented
|
||||
result = principal->ToString(aPrincipalStr);
|
||||
if (NS_FAILED(result) || !*aPrincipalStr)
|
||||
return NS_ERROR_FAILURE;
|
||||
#else
|
||||
const char temStr[] = "unknown";
|
||||
PRInt32 temLen = strlen(temStr);
|
||||
*aPrincipalStr = strncpy((char*) nsAllocator::Alloc(temLen+1),
|
||||
temStr, temLen+1);
|
||||
#endif
|
||||
|
||||
XMLT_LOG(mozLineTerm::GetSecurePrincipal,32,("aPrincipalStr=%s\n",
|
||||
*aPrincipalStr));
|
||||
|
||||
// Check if principal is secure
|
||||
PRBool insecure = false;
|
||||
if (insecure) {
|
||||
// Return null string
|
||||
XMLT_ERROR("mozLineTerm::GetSecurePrincipal: Error - "
|
||||
"Insecure document principal %s\n", *aPrincipalStr);
|
||||
nsAllocator::Free(*aPrincipalStr);
|
||||
*aPrincipalStr = (char*) nsAllocator::Alloc(1);
|
||||
**aPrincipalStr = '\0';
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Open LineTerm without callback
|
||||
*/
|
||||
NS_IMETHODIMP mozLineTerm::Open(const PRUnichar *command,
|
||||
const PRUnichar *promptRegexp,
|
||||
PRInt32 options, PRInt32 processType,
|
||||
nsIDOMDocument *domDoc)
|
||||
{
|
||||
if (mSuspended) {
|
||||
XMLT_ERROR("mozLineTerm::Open: Error - LineTerm %d is suspended\n",
|
||||
mLTerm);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsAutoString aCookie;
|
||||
return OpenAux(command, promptRegexp, options, processType, domDoc,
|
||||
nsnull, aCookie);
|
||||
}
|
||||
|
||||
|
||||
/** Open LineTerm, with an Observer for callback to process new input/output
|
||||
*/
|
||||
NS_IMETHODIMP mozLineTerm::OpenAux(const PRUnichar *command,
|
||||
const PRUnichar *promptRegexp,
|
||||
PRInt32 options, PRInt32 processType,
|
||||
nsIDOMDocument *domDoc,
|
||||
nsIObserver* anObserver,
|
||||
nsString& aCookie)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
XMLT_LOG(mozLineTerm::Open,20,("\n"));
|
||||
|
||||
// Ensure that preferences are secure for LineTerm creation and use
|
||||
PRBool arePrefsSecure;
|
||||
result = ArePrefsSecure(&arePrefsSecure);
|
||||
#if 0 // Temporarily comented out
|
||||
if (NS_FAILED(result) || !arePrefsSecure)
|
||||
return NS_ERROR_FAILURE;
|
||||
#endif
|
||||
|
||||
// Ensure that document principal is secure for LineTerm creation
|
||||
char* securePrincipal;
|
||||
result = GetSecurePrincipal(domDoc, &securePrincipal);
|
||||
if (NS_FAILED(result))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (strlen(securePrincipal) == 0) {
|
||||
nsAllocator::Free(securePrincipal);
|
||||
XMLT_ERROR("mozLineTerm::OpenAux: Error - "
|
||||
"Failed to create LineTerm for insecure document principal\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLDocument> domHTMLDoc = do_QueryInterface(domDoc);
|
||||
if (!domHTMLDoc)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Ensure that cookie attribute of document is defined
|
||||
nsAutoString cookiePrefix ( "xmlterm=" );
|
||||
nsAutoString cookieStr;
|
||||
result = domHTMLDoc->GetCookie(cookieStr);
|
||||
|
||||
if (NS_SUCCEEDED(result) &&
|
||||
(cookieStr.Length() > cookiePrefix.Length()) &&
|
||||
(cookieStr.Find(cookiePrefix) == 0)) {
|
||||
// Cookie value already defined for document; simply copy it
|
||||
mCookie = cookieStr;
|
||||
|
||||
} else {
|
||||
// Create random session cookie
|
||||
nsAutoString cookieValue;
|
||||
result = mozXMLTermUtils::RandomCookie(cookieValue);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
mCookie = cookiePrefix;
|
||||
mCookie += cookieValue;
|
||||
|
||||
// Set new cookie value
|
||||
result = domHTMLDoc->SetCookie(mCookie);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
}
|
||||
|
||||
// Return copy of cookie to caller
|
||||
aCookie = mCookie;
|
||||
|
||||
mObserver = anObserver; // non-owning reference
|
||||
|
||||
// Convert cookie to CString
|
||||
char* cookieCStr = mCookie.ToNewCString();
|
||||
XMLT_LOG(mozLineTerm::Open,22, ("mCookie=%s\n", cookieCStr));
|
||||
|
||||
if (anObserver != nsnull) {
|
||||
result = lterm_open(mLTerm, NULL, cookieCStr, L"#$%>?", options,
|
||||
processType, mozLineTerm::Callback, (void *) this);
|
||||
} else {
|
||||
result = lterm_open(mLTerm, NULL, cookieCStr, L"#$%>?", options,
|
||||
processType, NULL, NULL);
|
||||
}
|
||||
|
||||
// Free cookie CString
|
||||
nsAllocator::Free(cookieCStr);
|
||||
|
||||
if (mLoggingEnabled) {
|
||||
// Log time stamp for LineTerm open operation
|
||||
nsAutoString timeStamp;
|
||||
result = mozXMLTermUtils::TimeStamp(0, mLastTime, timeStamp);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
char* temStr = timeStamp.ToNewCString();
|
||||
fprintf(stderr, "<TS %s> LineTerm %d opened by principal %s\n",
|
||||
temStr, mLTerm, securePrincipal);
|
||||
nsAllocator::Free(temStr);
|
||||
}
|
||||
}
|
||||
|
||||
if (result == 0) {
|
||||
return NS_OK;
|
||||
} else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** GTK-style callback funtion for mozLineTerm object
|
||||
*/
|
||||
void mozLineTerm::Callback(gpointer data,
|
||||
gint source,
|
||||
GdkInputCondition condition)
|
||||
{
|
||||
mozLineTerm* lineTerm = (mozLineTerm*) data;
|
||||
|
||||
//XMLT_LOG(mozLineTerm::Callback,50,("\n"));
|
||||
|
||||
PR_ASSERT(lineTerm != nsnull);
|
||||
PR_ASSERT(lineTerm->mObserver != nsnull);
|
||||
|
||||
lineTerm->mObserver->Observe((nsISupports*) lineTerm, nsnull, nsnull);
|
||||
return;
|
||||
}
|
||||
|
||||
/** Suspends (or restores) LineTerm activity depending upon aSuspend
|
||||
*/
|
||||
NS_IMETHODIMP mozLineTerm::SuspendAux(PRBool aSuspend)
|
||||
{
|
||||
mSuspended = aSuspend;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Close LineTerm (a Finalize method)
|
||||
*/
|
||||
NS_IMETHODIMP mozLineTerm::Close(const PRUnichar* aCookie)
|
||||
{
|
||||
if (!mCookie.Equals(aCookie)) {
|
||||
XMLT_ERROR("mozLineTerm::Close: Error - Cookie mismatch\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (mSuspended) {
|
||||
XMLT_ERROR("mozLineTerm::Close: Error - LineTerm %d is suspended\n",
|
||||
mLTerm);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (lterm_close(mLTerm) == 0) {
|
||||
return NS_OK;
|
||||
} else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
mObserver = nsnull;
|
||||
}
|
||||
|
||||
|
||||
/** Close LineTerm (a Finalize method)
|
||||
*/
|
||||
NS_IMETHODIMP mozLineTerm::CloseAux(void)
|
||||
{
|
||||
if (lterm_close(mLTerm) == 0) {
|
||||
return NS_OK;
|
||||
} else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
mObserver = nsnull;
|
||||
}
|
||||
|
||||
|
||||
/** Close all LineTerm instances
|
||||
*/
|
||||
NS_IMETHODIMP mozLineTerm::CloseAllAux(void)
|
||||
{
|
||||
lterm_close_all();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Writes a string to LTERM
|
||||
*/
|
||||
NS_IMETHODIMP mozLineTerm::Write(const PRUnichar *buf,
|
||||
const PRUnichar* aCookie)
|
||||
{
|
||||
if (!mCookie.Equals(aCookie)) {
|
||||
XMLT_ERROR("mozLineTerm::Write: Error - Cookie mismatch\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (mSuspended) {
|
||||
XMLT_ERROR("mozLineTerm::Write: Error - LineTerm %d is suspended\n",
|
||||
mLTerm);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
XMLT_LOG(mozLineTerm::Write,30,("\n"));
|
||||
|
||||
nsresult result;
|
||||
UNICHAR ubuf[MAXCOL];
|
||||
int jLen, retCode;
|
||||
PRBool newline = false;
|
||||
|
||||
jLen = 0;
|
||||
while ((jLen < MAXCOL-1) && (buf[jLen] != 0)) {
|
||||
if (buf[jLen] == U_LINEFEED)
|
||||
newline = true;
|
||||
|
||||
ubuf[jLen++] = (UNICHAR) buf[jLen];
|
||||
}
|
||||
|
||||
if (jLen >= MAXCOL-1) {
|
||||
XMLT_ERROR("mozLineTerm::Write: Error - Buffer overflow\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (mLoggingEnabled && (jLen > 0)) {
|
||||
/* Log all input to STDERR */
|
||||
ucsprint(stderr, ubuf, jLen);
|
||||
|
||||
nsAutoString timeStamp;
|
||||
result = mozXMLTermUtils::TimeStamp(60, mLastTime, timeStamp);
|
||||
|
||||
if (NS_SUCCEEDED(result) && (timeStamp.Length() > 0)) {
|
||||
char* temStr = timeStamp.ToNewCString();
|
||||
fprintf(stderr, "<TS %s>\n", temStr);
|
||||
nsAllocator::Free(temStr);
|
||||
|
||||
} else if (newline) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
retCode = lterm_write(mLTerm, ubuf, jLen, LTERM_WRITE_PLAIN_INPUT);
|
||||
if (retCode < 0)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozLineTerm::Read(PRInt32 *opcodes,
|
||||
PRInt32 *buf_row, PRInt32 *buf_col,
|
||||
const PRUnichar* aCookie,
|
||||
PRUnichar **_retval)
|
||||
{
|
||||
if (!mCookie.Equals(aCookie)) {
|
||||
XMLT_ERROR("mozLineTerm::Read: Error - Cookie mismatch\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (mSuspended) {
|
||||
XMLT_ERROR("mozLineTerm::Read: Error - LineTerm %d is suspended\n",
|
||||
mLTerm);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return ReadAux(opcodes, buf_row, buf_col, _retval, nsnull);
|
||||
}
|
||||
|
||||
|
||||
/** Reads a line from LTERM and returns it as a string (may be null string)
|
||||
*/
|
||||
NS_IMETHODIMP mozLineTerm::ReadAux(PRInt32 *opcodes,
|
||||
PRInt32 *buf_row, PRInt32 *buf_col,
|
||||
PRUnichar **_retval, PRUnichar **retstyle)
|
||||
{
|
||||
UNICHAR ubuf[MAXCOL];
|
||||
UNISTYLE ustyle[MAXCOL];
|
||||
int cursor_row, cursor_col;
|
||||
int retCode, j;
|
||||
|
||||
XMLT_LOG(mozLineTerm::ReadAux,30,("\n"));
|
||||
|
||||
retCode = lterm_read(mLTerm, 0, ubuf, MAXCOL-1,
|
||||
ustyle, opcodes,
|
||||
buf_row, buf_col, &cursor_row, &cursor_col);
|
||||
if (retCode < 0)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (*opcodes == 0) {
|
||||
// Return null pointer(s)
|
||||
*_retval = nsnull;
|
||||
|
||||
if (retstyle != nsnull)
|
||||
*retstyle = nsnull;
|
||||
|
||||
} else {
|
||||
// Return output string
|
||||
mCursorRow = cursor_row;
|
||||
mCursorColumn = cursor_col;
|
||||
|
||||
XMLT_LOG(mozLineTerm::Read,72,("cursor_col=%d\n", cursor_col));
|
||||
|
||||
int allocBytes = sizeof(PRUnichar)*(retCode + 1);
|
||||
*_retval = (PRUnichar*) nsAllocator::Alloc(allocBytes);
|
||||
|
||||
for (j=0; j<retCode; j++)
|
||||
(*_retval)[j] = (PRUnichar) ubuf[j];
|
||||
|
||||
// Insert null string terminator
|
||||
(*_retval)[retCode] = 0;
|
||||
|
||||
if (retstyle != nsnull) {
|
||||
// Return style array as well
|
||||
*retstyle = (PRUnichar*) nsAllocator::Alloc(allocBytes);
|
||||
|
||||
for (j=0; j<retCode; j++)
|
||||
(*retstyle)[j] = (PRUnichar) ustyle[j];
|
||||
|
||||
// Insert null string terminator
|
||||
(*retstyle)[retCode] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozLineTerm::GetCursorRow(PRInt32 *aCursorRow)
|
||||
{
|
||||
*aCursorRow = mCursorRow;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozLineTerm::SetCursorRow(PRInt32 aCursorRow)
|
||||
{
|
||||
if (mSuspended) {
|
||||
XMLT_ERROR("mozLineTerm::SetCursorRow: Error - LineTerm %d is suspended\n",
|
||||
mLTerm);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK; // Do nothing for the moment
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozLineTerm::GetCursorColumn(PRInt32 *aCursorColumn)
|
||||
{
|
||||
*aCursorColumn = mCursorColumn;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozLineTerm::SetCursorColumn(PRInt32 aCursorColumn)
|
||||
{
|
||||
if (mSuspended) {
|
||||
XMLT_ERROR("mozLineTerm::SetCursorColumn: Error - LineTerm %d is suspended\n",
|
||||
mLTerm);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK; // Do nothing for the moment
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozLineTerm::GetEchoFlag(PRBool *aEchoFlag)
|
||||
{
|
||||
*aEchoFlag = mEchoFlag;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozLineTerm::SetEchoFlag(PRBool aEchoFlag)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (mSuspended) {
|
||||
XMLT_ERROR("mozLineTerm::SetEchoFlag: Error - LineTerm %d is suspended\n",
|
||||
mLTerm);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (aEchoFlag) {
|
||||
result = lterm_setecho(mLTerm, 1);
|
||||
} else {
|
||||
result = lterm_setecho(mLTerm, 0);
|
||||
}
|
||||
|
||||
if (result != 0)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mEchoFlag = aEchoFlag;
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozLineTerm.h: Declaration of mozLineTerm class
|
||||
// which implements the LineTerm and LineTermAux interfaces.
|
||||
// and provides an XPCOM/XPCONNECT wrapper to the LINETERM module
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nscore.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMHTMLDocument.h"
|
||||
|
||||
#include "mozILineTermAux.h"
|
||||
|
||||
#define MAXCOL 4096 // Maximum columns in line buffer
|
||||
|
||||
class mozLineTerm : public mozILineTermAux
|
||||
{
|
||||
public:
|
||||
mozLineTerm();
|
||||
virtual ~mozLineTerm();
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// mozILineTerm interface
|
||||
NS_IMETHOD GetCursorRow(PRInt32 *aCursorRow);
|
||||
NS_IMETHOD SetCursorRow(PRInt32 aCursorRow);
|
||||
|
||||
NS_IMETHOD GetCursorColumn(PRInt32 *aCursorColumn);
|
||||
NS_IMETHOD SetCursorColumn(PRInt32 aCursorColumn);
|
||||
|
||||
NS_IMETHOD GetEchoFlag(PRBool *aEchoFlag);
|
||||
NS_IMETHOD SetEchoFlag(PRBool aEchoFlag);
|
||||
|
||||
NS_IMETHOD Open(const PRUnichar *command,
|
||||
const PRUnichar *promptRegexp,
|
||||
PRInt32 options, PRInt32 processType,
|
||||
nsIDOMDocument *domDoc);
|
||||
|
||||
NS_IMETHOD Close(const PRUnichar* aCookie);
|
||||
|
||||
NS_IMETHOD Write(const PRUnichar *buf, const PRUnichar* aCookie);
|
||||
|
||||
NS_IMETHOD Read(PRInt32 *opcodes,
|
||||
PRInt32 *buf_row, PRInt32 *buf_col,
|
||||
const PRUnichar* aCookie,
|
||||
PRUnichar **_retval);
|
||||
|
||||
// mozILineTermAux interface add ons
|
||||
// (not scriptable, no authentication cookie required)
|
||||
NS_IMETHOD OpenAux(const PRUnichar *command,
|
||||
const PRUnichar *promptRegexp,
|
||||
PRInt32 options, PRInt32 processType,
|
||||
nsIDOMDocument *domDoc,
|
||||
nsIObserver* anObserver,
|
||||
nsString& aCookie);
|
||||
|
||||
NS_IMETHOD SuspendAux(PRBool aSuspend);
|
||||
|
||||
NS_IMETHOD CloseAux(void);
|
||||
|
||||
NS_IMETHOD CloseAllAux(void);
|
||||
|
||||
NS_IMETHOD ReadAux(PRInt32 *opcodes,
|
||||
PRInt32 *buf_row, PRInt32 *buf_col,
|
||||
PRUnichar **_retval, PRUnichar **retstyle);
|
||||
// others
|
||||
|
||||
/** GTK event callback function
|
||||
*/
|
||||
static void Callback(gpointer data,
|
||||
gint source,
|
||||
GdkInputCondition condition);
|
||||
|
||||
/** Flag controlling logging of user input to STDERR */
|
||||
static PRBool mLoggingEnabled;
|
||||
|
||||
protected:
|
||||
/** Checks if Mozilla preference settings are secure
|
||||
* @param _retval (output) true if settings are secure
|
||||
*/
|
||||
NS_IMETHOD ArePrefsSecure(PRBool *_retval);
|
||||
|
||||
/** Checks if document principal is secure and returns principal string
|
||||
* @param domDOC DOM document object
|
||||
* @param aPrincipalStr (output) document principal string
|
||||
*/
|
||||
NS_IMETHOD GetSecurePrincipal(nsIDOMDocument *domDoc,
|
||||
char** aPrincipalStr);
|
||||
|
||||
/** lineterm descriptor index returned by lterm_new (>= 0) */
|
||||
int mLTerm;
|
||||
|
||||
/** current cursor row position */
|
||||
int mCursorRow;
|
||||
|
||||
/** current cursor column position */
|
||||
int mCursorColumn;
|
||||
|
||||
/** flag controlling whether is LineTerm is suspended */
|
||||
PRBool mSuspended;
|
||||
|
||||
/** flag controlling input echo in LineTerm */
|
||||
PRBool mEchoFlag;
|
||||
|
||||
/** non-owning reference to Observer to be notified when data is available
|
||||
* for reading from LineTerm
|
||||
*/
|
||||
nsIObserver* mObserver;
|
||||
|
||||
/** cookie string used for authentication (stored in document.cookie) */
|
||||
nsString mCookie;
|
||||
|
||||
/** record of last time when timestamp was displayed in user input log */
|
||||
PRTime mLastTime;
|
||||
|
||||
};
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozXMLT.h: XMLTerm common header
|
||||
|
||||
#ifndef _MOZXMLT_H
|
||||
|
||||
#define _MOZXMLT_H 1
|
||||
|
||||
// Standard C header files
|
||||
#ifndef _STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
// public declarations
|
||||
#include "lineterm.h"
|
||||
#include "tracelog.h"
|
||||
|
||||
// private declarations
|
||||
|
||||
#define XMLT_TLOG_MODULE 2
|
||||
#define XMLT_ERROR TLOG_ERROR
|
||||
#define XMLT_WARNING TLOG_WARNING
|
||||
#define XMLT_LOG(procname,level,args) TLOG_PRINT(XMLT_TLOG_MODULE,procname,level,args)
|
||||
|
||||
// Tracing versions of NS_IMPL_ADDREF and NS_IMPL_RELEASE
|
||||
|
||||
#define XMLT_IMPL_ADDREF(_class) \
|
||||
NS_IMETHODIMP_(nsrefcnt) _class::AddRef(void) \
|
||||
{ \
|
||||
NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt"); \
|
||||
++mRefCnt; \
|
||||
XMLT_WARNING(#_class ":AddRef, mRefCnt=%d\n", mRefCnt); \
|
||||
return mRefCnt; \
|
||||
}
|
||||
|
||||
#define XMLT_IMPL_RELEASE(_class) \
|
||||
NS_IMETHODIMP_(nsrefcnt) _class::Release(void) \
|
||||
{ \
|
||||
NS_PRECONDITION(0 != mRefCnt, "dup release"); \
|
||||
--mRefCnt; \
|
||||
XMLT_WARNING(#_class ":Release, mRefCnt=%d\n", mRefCnt); \
|
||||
if (mRefCnt == 0) { \
|
||||
NS_DELETEXPCOM(this); \
|
||||
return 0; \
|
||||
} \
|
||||
return mRefCnt; \
|
||||
}
|
||||
|
||||
#endif /* _MOZXMLT_H */
|
|
@ -0,0 +1,298 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozXMLTermFactory.cpp: XPCOM factory for mozIXMLTermShell, mozILineTerm
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nscore.h"
|
||||
#include "nspr.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsXPComFactory.h"
|
||||
|
||||
#include "mozXMLT.h"
|
||||
#include "mozLineTerm.h"
|
||||
#include "mozIXMLTermShell.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||
static NS_DEFINE_CID(kXMLTermShellCID, MOZXMLTERMSHELL_CID);
|
||||
static NS_DEFINE_CID(kLineTermCID, MOZLINETERM_CID);
|
||||
|
||||
class XMLTermFactory : public nsIFactory
|
||||
{
|
||||
public:
|
||||
XMLTermFactory(const nsCID &aClass, const char* className, const char* progID);
|
||||
|
||||
// nsISupports methods
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFactory methods
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
protected:
|
||||
virtual ~XMLTermFactory();
|
||||
|
||||
protected:
|
||||
nsCID mClassID;
|
||||
const char* mClassName;
|
||||
const char* mProgID;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// mozXMLTermFactory implementation
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Globals, useful to check if safe to unload module
|
||||
static PRInt32 gLockCnt = 0;
|
||||
static PRInt32 gInstanceCnt = 0;
|
||||
|
||||
XMLTermFactory::XMLTermFactory(const nsCID &aClass,
|
||||
const char* className,
|
||||
const char* progID):
|
||||
mClassID(aClass),
|
||||
mClassName(className),
|
||||
mProgID(progID)
|
||||
{
|
||||
// Zero reference counter
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&gInstanceCnt);
|
||||
}
|
||||
|
||||
|
||||
XMLTermFactory::~XMLTermFactory()
|
||||
{
|
||||
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
|
||||
PR_AtomicDecrement(&gInstanceCnt);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
XMLTermFactory::QueryInterface(const nsIID &aIID, void **aResult)
|
||||
{
|
||||
if (!aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aResult = nsnull;
|
||||
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aResult = NS_STATIC_CAST(nsISupports*, this);
|
||||
|
||||
} else if (aIID.Equals(kIFactoryIID)) {
|
||||
*aResult = NS_STATIC_CAST(nsIFactory*, this);
|
||||
|
||||
} else {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(XMLTermFactory);
|
||||
NS_IMPL_RELEASE(XMLTermFactory);
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
XMLTermFactory::CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (!aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
*aResult = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
nsISupports *inst = nsnull;
|
||||
if (mClassID.Equals(kXMLTermShellCID)) {
|
||||
if (NS_FAILED(rv = NS_NewXMLTermShell((mozIXMLTermShell**) &inst)))
|
||||
return rv;
|
||||
|
||||
} else if (mClassID.Equals(kLineTermCID)) {
|
||||
if (NS_FAILED(rv = NS_NewLineTerm((mozILineTerm**) &inst)))
|
||||
return rv;
|
||||
|
||||
} else {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
if (! inst)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (NS_FAILED(rv = inst->QueryInterface(aIID, aResult))) {
|
||||
// We didn't get the right interface.
|
||||
NS_ERROR("didn't support the interface you wanted");
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(inst);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
XMLTermFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
if (aLock) {
|
||||
PR_AtomicIncrement(&gLockCnt);
|
||||
} else {
|
||||
PR_AtomicDecrement(&gLockCnt);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Exported functions for loading, registering, unregistering, and unloading
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Return approptiate factory to the caller
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSGetFactory(nsISupports* aServMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory)
|
||||
{
|
||||
static PRBool ltermInitialized = false;
|
||||
static PRBool xmltermInitialized = false;
|
||||
|
||||
if (!ltermInitialized) {
|
||||
// Initialize all LINETERM operations
|
||||
// (This initialization needs to be done at factory creation time;
|
||||
// trying to do it earlier, i.e., at registration time,
|
||||
// does not work ... something to do with loading of static global
|
||||
// variables.)
|
||||
|
||||
int messageLevel = 8;
|
||||
char* debugStr = (char*) PR_GetEnv("LTERM_DEBUG");
|
||||
|
||||
if (debugStr && (strlen(debugStr) == 1)) {
|
||||
messageLevel = 98;
|
||||
debugStr = nsnull;
|
||||
}
|
||||
|
||||
int result = lterm_init(0);
|
||||
if (result == 0) {
|
||||
tlog_set_level(LTERM_TLOG_MODULE, messageLevel, debugStr);
|
||||
}
|
||||
ltermInitialized = true;
|
||||
|
||||
char* logStr = (char*) PR_GetEnv("LTERM_LOG");
|
||||
if (logStr && (strlen(logStr) > 0)) {
|
||||
// Enable LineTerm logging
|
||||
mozLineTerm::mLoggingEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (aClass.Equals(kXMLTermShellCID) && !xmltermInitialized) {
|
||||
// Set initial debugging message level for XMLterm
|
||||
int messageLevel = 8;
|
||||
char* debugStr = (char*) PR_GetEnv("XMLT_DEBUG");
|
||||
|
||||
if (debugStr && (strlen(debugStr) == 1)) {
|
||||
messageLevel = 98;
|
||||
debugStr = nsnull;
|
||||
}
|
||||
|
||||
tlog_set_level(XMLT_TLOG_MODULE, messageLevel, debugStr);
|
||||
xmltermInitialized = true;
|
||||
}
|
||||
|
||||
if (!aFactory)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aFactory = nsnull;
|
||||
|
||||
XMLTermFactory* factory = new XMLTermFactory(aClass, aClassName,
|
||||
aProgID);
|
||||
if (factory == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(factory);
|
||||
*aFactory = factory;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &result));
|
||||
if (NS_FAILED(result)) return result;
|
||||
|
||||
NS_WITH_SERVICE(nsIComponentManager, compMgr, kComponentManagerCID, &result);
|
||||
if (NS_FAILED(result)) return result;
|
||||
|
||||
printf("Registering lineterm interface\n");
|
||||
|
||||
result = compMgr->RegisterComponent(kLineTermCID,
|
||||
"LineTerm Component",
|
||||
"component://mozilla/xmlterm/lineterm",
|
||||
aPath, PR_TRUE, PR_TRUE);
|
||||
|
||||
if (NS_FAILED(result)) return result;
|
||||
|
||||
printf("Registering xmlterm shell interface\n");
|
||||
|
||||
result = compMgr->RegisterComponent(kXMLTermShellCID,
|
||||
"XMLTerm Shell Component",
|
||||
"component://mozilla/xmlterm/xmltermshell",
|
||||
aPath, PR_TRUE, PR_TRUE);
|
||||
|
||||
if (NS_FAILED(result)) return result;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &result));
|
||||
if (NS_FAILED(result)) return result;
|
||||
|
||||
NS_WITH_SERVICE(nsIComponentManager, compMgr, kComponentManagerCID, &result);
|
||||
if (NS_FAILED(result)) return result;
|
||||
|
||||
result = compMgr->UnregisterComponent(kLineTermCID, aPath);
|
||||
if (NS_FAILED(result)) return result;
|
||||
|
||||
result = compMgr->UnregisterComponent(kXMLTermShellCID, aPath);
|
||||
if (NS_FAILED(result)) return result;
|
||||
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,604 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozXMLTermListeners.cpp: implementation of classes in mozXMLTermListeners.h
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "mozXMLT.h"
|
||||
#include "mozXMLTermListeners.h"
|
||||
|
||||
#include "nsIDOMKeyEvent.h"
|
||||
#include "nsIDOMMouseEvent.h"
|
||||
#include "nsIDOMNSUIEvent.h"
|
||||
#include "nsIPrivateTextEvent.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// mozXMLTermKeyListener factory
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewXMLTermKeyListener(nsIDOMEventListener ** aInstancePtrResult,
|
||||
mozIXMLTerminal *aXMLTerminal)
|
||||
{
|
||||
mozXMLTermKeyListener* listener = new mozXMLTermKeyListener();
|
||||
if (listener == nsnull) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// Save non-owning reference to embedding XMLTerminal object
|
||||
listener->SetXMLTerminal(aXMLTerminal);
|
||||
|
||||
return listener->QueryInterface(nsIDOMEventListener::GetIID(),
|
||||
(void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewXMLTermTextListener(nsIDOMEventListener ** aInstancePtrResult,
|
||||
mozIXMLTerminal *aXMLTerminal)
|
||||
{
|
||||
mozXMLTermTextListener* listener = new mozXMLTermTextListener();
|
||||
if (listener == nsnull) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// Save non-owning reference to embedding XMLTerminal object
|
||||
listener->SetXMLTerminal(aXMLTerminal);
|
||||
|
||||
return listener->QueryInterface(nsIDOMEventListener::GetIID(),
|
||||
(void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewXMLTermMouseListener(nsIDOMEventListener ** aInstancePtrResult,
|
||||
mozIXMLTerminal *aXMLTerminal)
|
||||
{
|
||||
mozXMLTermMouseListener* listener = new mozXMLTermMouseListener();
|
||||
if (listener == nsnull) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// Save non-owning reference to embedding XMLTerminal object
|
||||
listener->SetXMLTerminal(aXMLTerminal);
|
||||
|
||||
return listener->QueryInterface(nsIDOMEventListener::GetIID(),
|
||||
(void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewXMLTermDragListener(nsIDOMEventListener ** aInstancePtrResult,
|
||||
mozIXMLTerminal *aXMLTerminal)
|
||||
{
|
||||
mozXMLTermDragListener* listener = new mozXMLTermDragListener();
|
||||
if (listener == nsnull) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// Save non-owning reference to embedding XMLTerminal object
|
||||
listener->SetXMLTerminal(aXMLTerminal);
|
||||
|
||||
return listener->QueryInterface(nsIDOMEventListener::GetIID(),
|
||||
(void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// mozXMLTermKeyListener implementation
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
mozXMLTermKeyListener::mozXMLTermKeyListener()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
|
||||
mozXMLTermKeyListener::~mozXMLTermKeyListener()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(mozXMLTermKeyListener)
|
||||
|
||||
NS_IMPL_RELEASE(mozXMLTermKeyListener)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermKeyListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (aInstancePtr == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsISupports*,
|
||||
NS_STATIC_CAST(nsIDOMKeyListener*,this));
|
||||
|
||||
} else if (aIID.Equals(nsIDOMEventListener::GetIID())) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIDOMEventListener*,this);
|
||||
|
||||
} else if (aIID.Equals(nsIDOMKeyListener::GetIID())) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIDOMKeyListener*,this);
|
||||
|
||||
} else {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// Individual key handlers return NS_OK to indicate NOT consumed
|
||||
// by default, an error is returned indicating event is consumed
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermKeyListener::HandleEvent(nsIDOMEvent* aEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// Process KeyDown events (handles control/alt modified key events)
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermKeyListener::KeyDown(nsIDOMEvent* aKeyEvent)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
nsCOMPtr<nsIDOMKeyEvent> keyEvent;
|
||||
keyEvent = do_QueryInterface(aKeyEvent);
|
||||
if (!keyEvent) {
|
||||
// Non-key event passed to keydown, do not consume it
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool isShift, ctrlKey, altKey;
|
||||
PRUint32 keyCode;
|
||||
|
||||
XMLT_LOG(mozXMLTermKeyListener::KeyDown,50,("\n"));
|
||||
|
||||
if (NS_SUCCEEDED(keyEvent->GetKeyCode(&keyCode)) &&
|
||||
NS_SUCCEEDED(keyEvent->GetShiftKey(&isShift)) &&
|
||||
NS_SUCCEEDED(keyEvent->GetCtrlKey(&ctrlKey)) &&
|
||||
NS_SUCCEEDED(keyEvent->GetAltKey(&altKey)) ) {
|
||||
|
||||
XMLT_LOG(mozXMLTermKeyListener::KeyDown,52,
|
||||
("keyCode=0x%x, ctrlKey=%d, altKey=%d\n", keyCode, ctrlKey, altKey));
|
||||
|
||||
PRUint32 keyChar = 0;
|
||||
|
||||
if (!ctrlKey && !altKey) {
|
||||
// Not control/alt key event
|
||||
switch (keyCode) {
|
||||
case nsIDOMKeyEvent::DOM_VK_LEFT:
|
||||
keyChar = U_CTL_B;
|
||||
break;
|
||||
case nsIDOMKeyEvent::DOM_VK_RIGHT:
|
||||
keyChar = U_CTL_F;
|
||||
break;
|
||||
case nsIDOMKeyEvent::DOM_VK_UP:
|
||||
keyChar = U_CTL_P;
|
||||
break;
|
||||
case nsIDOMKeyEvent::DOM_VK_DOWN:
|
||||
keyChar = U_CTL_N;
|
||||
break;
|
||||
case nsIDOMKeyEvent::DOM_VK_TAB: // Consume TAB to avoid scroll problems
|
||||
keyChar = 0;
|
||||
break;
|
||||
default: // ignore event without consuming
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} else if (ctrlKey == PR_TRUE) {
|
||||
keyChar = keyCode - 0x40U; // Is this portable?
|
||||
}
|
||||
|
||||
XMLT_LOG(mozXMLTermKeyListener::KeyDown,52,("keyChar=0x%x\n", keyChar));
|
||||
|
||||
if ((keyChar > 0) && (keyChar < U_SPACE)) {
|
||||
// Transmit valid non-null control character
|
||||
const PRUnichar temUString[] = {keyChar,0};
|
||||
nsAutoString keyString(temUString);
|
||||
result = mXMLTerminal->SendTextAux(keyString);
|
||||
}
|
||||
}
|
||||
|
||||
// Consume key down event
|
||||
return NS_ERROR_BASE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermKeyListener::KeyUp(nsIDOMEvent* aKeyEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// Handle KeyPress events (non control/alt modified key events)
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
XMLT_LOG(mozXMLTermKeyListener::KeyPress,50,("\n"));
|
||||
|
||||
nsCOMPtr<nsIDOMKeyEvent> keyEvent;
|
||||
keyEvent = do_QueryInterface(aKeyEvent);
|
||||
if (!keyEvent) {
|
||||
// Non-key event passed to keydown, do not consume it
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRUint32 keyCode;
|
||||
PRBool isShift, ctrlKey, altKey;
|
||||
if (NS_SUCCEEDED(keyEvent->GetKeyCode(&keyCode)) &&
|
||||
NS_SUCCEEDED(keyEvent->GetShiftKey(&isShift)) &&
|
||||
NS_SUCCEEDED(keyEvent->GetCtrlKey(&ctrlKey)) &&
|
||||
NS_SUCCEEDED(keyEvent->GetAltKey(&altKey)) ) {
|
||||
|
||||
PRUint32 keyChar = 0;
|
||||
result = keyEvent->GetCharCode(&keyChar);
|
||||
|
||||
XMLT_LOG(mozXMLTermKeyListener::KeyPress,52,
|
||||
("keyChar=0x%x, ctrlKey=%d, altKey=%d\n", keyChar, ctrlKey, altKey));
|
||||
|
||||
if (ctrlKey == PR_TRUE) {
|
||||
// Do nothing for Ctrl-Alt key events; just consume then
|
||||
|
||||
if (altKey == PR_FALSE) {
|
||||
// Control character, without Alt
|
||||
|
||||
if ((keyChar > 0) && (keyChar < U_SPACE)) {
|
||||
// Transmit valid non-null control character
|
||||
const PRUnichar temUString[] = {keyChar,0};
|
||||
nsAutoString keyString(temUString);
|
||||
result = mXMLTerminal->SendTextAux(keyString);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Unmodified key event (including TAB/BACKSPACE/RETURN/LINEFEED)
|
||||
|
||||
if (keyChar == 0) {
|
||||
// Key that hasn't been mapped to a character code
|
||||
switch (keyCode) {
|
||||
case nsIDOMKeyEvent::DOM_VK_BACK_SPACE:
|
||||
case nsIDOMKeyEvent::DOM_VK_DELETE:
|
||||
keyChar = U_BACKSPACE;
|
||||
break;
|
||||
case nsIDOMKeyEvent::DOM_VK_TAB:
|
||||
keyChar = U_TAB;
|
||||
break;
|
||||
case nsIDOMKeyEvent::DOM_VK_RETURN:
|
||||
keyChar = U_LINEFEED;
|
||||
break;
|
||||
default: // ignore event without consuming
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// Translate Carriage Return to LineFeed (may not be portable??)
|
||||
if (keyChar == U_CRETURN) keyChar = U_LINEFEED;
|
||||
|
||||
if ((keyChar > 0) && (keyChar <= 0xFFFDU)) {
|
||||
// Transmit valid non-null Unicode character
|
||||
const PRUnichar temUString[] = {keyChar,0};
|
||||
nsAutoString keyString(temUString);
|
||||
result = mXMLTerminal->SendTextAux(keyString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Consume key press event
|
||||
return NS_ERROR_BASE;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// mozXMLTermTextListener implementation
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
mozXMLTermTextListener::mozXMLTermTextListener()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
|
||||
mozXMLTermTextListener::~mozXMLTermTextListener()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(mozXMLTermTextListener)
|
||||
|
||||
NS_IMPL_RELEASE(mozXMLTermTextListener)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermTextListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (aInstancePtr == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsISupports*,
|
||||
NS_STATIC_CAST(nsIDOMTextListener*,this));
|
||||
|
||||
} else if (aIID.Equals(nsIDOMEventListener::GetIID())) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIDOMEventListener*,this);
|
||||
|
||||
} else if (aIID.Equals(nsIDOMTextListener::GetIID())) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIDOMTextListener*,this);
|
||||
|
||||
} else {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermTextListener::HandleEvent(nsIDOMEvent* aEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermTextListener::HandleText(nsIDOMEvent* aTextEvent)
|
||||
{
|
||||
nsCOMPtr<nsIPrivateTextEvent> textEvent (do_QueryInterface(aTextEvent));
|
||||
if (!textEvent) {
|
||||
// Soft failure
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
XMLT_LOG(mozXMLTermTextListener::HandleText,50,("\n"));
|
||||
|
||||
nsAutoString textStr;
|
||||
textEvent->GetText(textStr);
|
||||
|
||||
// Transmit text to terminal
|
||||
mXMLTerminal->SendTextAux(textStr);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// mozXMLTermMouseListener implementation
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
mozXMLTermMouseListener::mozXMLTermMouseListener()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
|
||||
mozXMLTermMouseListener::~mozXMLTermMouseListener()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(mozXMLTermMouseListener)
|
||||
|
||||
NS_IMPL_RELEASE(mozXMLTermMouseListener)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermMouseListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (aInstancePtr == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsISupports*,
|
||||
NS_STATIC_CAST(nsIDOMMouseListener*,this));
|
||||
|
||||
} else if (aIID.Equals(nsIDOMEventListener::GetIID())) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIDOMEventListener*,this);
|
||||
|
||||
} else if (aIID.Equals(nsIDOMMouseListener::GetIID())) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIDOMMouseListener*,this);
|
||||
|
||||
} else {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermMouseListener::HandleEvent(nsIDOMEvent* aEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
if (!aMouseEvent)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
|
||||
mouseEvent = do_QueryInterface(aMouseEvent);
|
||||
if (!mouseEvent) {
|
||||
// Non-mouse event passed; do not consume it
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRUint16 buttonCode = 0;
|
||||
mouseEvent->GetButton(&buttonCode);
|
||||
|
||||
XMLT_LOG(mozXMLTermMouseListener::MouseDown,50,("buttonCode=%d\n",
|
||||
buttonCode));
|
||||
|
||||
if (buttonCode == 2) {
|
||||
// Middle-mouse button pressed; initiate paste
|
||||
mXMLTerminal->Paste();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermMouseListener::MouseUp(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermMouseListener::MouseClick(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermMouseListener::MouseDblClick(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermMouseListener::MouseOver(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermMouseListener::MouseOut(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// mozXMLTermDragListener implementation
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
mozXMLTermDragListener::mozXMLTermDragListener()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
|
||||
mozXMLTermDragListener::~mozXMLTermDragListener()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(mozXMLTermDragListener)
|
||||
|
||||
NS_IMPL_RELEASE(mozXMLTermDragListener)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermDragListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (aInstancePtr == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsISupports*,
|
||||
NS_STATIC_CAST(nsIDOMDragListener*,this));
|
||||
|
||||
} else if (aIID.Equals(nsIDOMEventListener::GetIID())) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIDOMEventListener*,this);
|
||||
|
||||
} else if (aIID.Equals(nsIDOMDragListener::GetIID())) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIDOMDragListener*,this);
|
||||
|
||||
} else {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermDragListener::HandleEvent(nsIDOMEvent* aEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermDragListener::DragEnter(nsIDOMEvent* aDragEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermDragListener::DragOver(nsIDOMEvent* aDragEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermDragListener::DragExit(nsIDOMEvent* aDragEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermDragListener::DragDrop(nsIDOMEvent* aDragEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermDragListener::DragGesture(nsIDOMEvent* aDragEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,172 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozXMLTermListeners.h: classes for key/text/mouse/drag event listeners
|
||||
// used by mozXMLTerminal:
|
||||
// mozXMLTermKeyListener
|
||||
// mozXMLTermTextListener
|
||||
// mozXMLTermMouseListener
|
||||
// mozXMLTermDragListener
|
||||
|
||||
|
||||
#ifndef mozXMLTermListeners_h__
|
||||
#define mozXMLTermListeners_h__
|
||||
|
||||
#include "nsIDOMEvent.h"
|
||||
#include "nsIDOMKeyListener.h"
|
||||
#include "nsIDOMTextListener.h"
|
||||
#include "nsIDOMMouseListener.h"
|
||||
#include "nsIDOMDragListener.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "mozIXMLTerminal.h"
|
||||
|
||||
/* XMLTerm Key Listener */
|
||||
class mozXMLTermKeyListener : public nsIDOMKeyListener {
|
||||
public:
|
||||
mozXMLTermKeyListener();
|
||||
virtual ~mozXMLTermKeyListener();
|
||||
|
||||
/** Save non-owning reference to containing XMLTerminal object
|
||||
* @param aXMLTerminal the XMLTerm instance
|
||||
*/
|
||||
void SetXMLTerminal(mozIXMLTerminal *aXMLTerminal)
|
||||
{mXMLTerminal = aXMLTerminal;}
|
||||
|
||||
// Interfaces for addref and release and queryinterface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDOMEventListener interface
|
||||
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
|
||||
|
||||
// nsIDOMKeyListener interface
|
||||
virtual nsresult KeyDown(nsIDOMEvent* aKeyEvent);
|
||||
virtual nsresult KeyUp(nsIDOMEvent* aKeyEvent);
|
||||
virtual nsresult KeyPress(nsIDOMEvent* aKeyEvent);
|
||||
|
||||
protected:
|
||||
/** non-owning reference to containing XMLTerminal object (for callback) */
|
||||
mozIXMLTerminal* mXMLTerminal;
|
||||
};
|
||||
|
||||
|
||||
/* XMLTerm Text Listener */
|
||||
class mozXMLTermTextListener : public nsIDOMTextListener {
|
||||
public:
|
||||
mozXMLTermTextListener();
|
||||
virtual ~mozXMLTermTextListener();
|
||||
|
||||
/** Save non-owning reference to containing XMLTerminal object
|
||||
* @param aXMLTerminal the XMLTerm instance
|
||||
*/
|
||||
void SetXMLTerminal(mozIXMLTerminal *aXMLTerminal)
|
||||
{mXMLTerminal = aXMLTerminal;}
|
||||
|
||||
// Interfaces for addref and release and queryinterface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDOMEventListener interface
|
||||
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
|
||||
|
||||
// nsIDOMTextListener interface
|
||||
virtual nsresult HandleText(nsIDOMEvent* aTextEvent);
|
||||
|
||||
protected:
|
||||
/** non-owning reference to containing XMLTerminal object (for callback) */
|
||||
mozIXMLTerminal* mXMLTerminal;
|
||||
};
|
||||
|
||||
|
||||
/* XMLTerm Mouse Listener */
|
||||
class mozXMLTermMouseListener : public nsIDOMMouseListener {
|
||||
public:
|
||||
mozXMLTermMouseListener();
|
||||
virtual ~mozXMLTermMouseListener();
|
||||
|
||||
/** Save non-owning reference to containing XMLTerminal object
|
||||
* @param aXMLTerminal the XMLTerm instance
|
||||
*/
|
||||
void SetXMLTerminal(mozIXMLTerminal *aXMLTerminal)
|
||||
{mXMLTerminal = aXMLTerminal;}
|
||||
|
||||
// Interfaces for addref and release and queryinterface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDOMEventListener interface
|
||||
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
|
||||
|
||||
// nsIDOMMouseListener interface
|
||||
virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent);
|
||||
virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent);
|
||||
virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent);
|
||||
virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent);
|
||||
virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent);
|
||||
virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent);
|
||||
|
||||
protected:
|
||||
/** non-owning reference to containing XMLTerminal object (for callback) */
|
||||
mozIXMLTerminal* mXMLTerminal;
|
||||
};
|
||||
|
||||
|
||||
/* XMLTerm Drag Listener */
|
||||
class mozXMLTermDragListener : public nsIDOMDragListener {
|
||||
public:
|
||||
mozXMLTermDragListener();
|
||||
virtual ~mozXMLTermDragListener();
|
||||
|
||||
/** Save non-owning reference to containing XMLTerminal object
|
||||
* @param aXMLTerminal the XMLTerm instance
|
||||
*/
|
||||
void SetXMLTerminal(mozIXMLTerminal *aXMLTerminal)
|
||||
{mXMLTerminal = aXMLTerminal;}
|
||||
|
||||
// Interfaces for addref and release and queryinterface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDOMEventListener interface
|
||||
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
|
||||
|
||||
// nsIDOMDragListener interface
|
||||
virtual nsresult DragEnter(nsIDOMEvent* aDragEvent);
|
||||
virtual nsresult DragOver(nsIDOMEvent* aDragEvent);
|
||||
virtual nsresult DragExit(nsIDOMEvent* aDragEvent);
|
||||
virtual nsresult DragDrop(nsIDOMEvent* aDragEvent);
|
||||
virtual nsresult DragGesture(nsIDOMEvent* aDragEvent);
|
||||
|
||||
protected:
|
||||
/** non-owning reference to containing XMLTerminal object (for callback) */
|
||||
mozIXMLTerminal* mXMLTerminal;
|
||||
};
|
||||
|
||||
|
||||
// Factory for XMLTermKeyListener
|
||||
extern nsresult NS_NewXMLTermKeyListener(nsIDOMEventListener** aInstancePtrResult, mozIXMLTerminal *aXMLTerminal);
|
||||
|
||||
// Factory for XMLTermTextListener
|
||||
extern nsresult NS_NewXMLTermTextListener(nsIDOMEventListener** aInstancePtrResult, mozIXMLTerminal *aXMLTerminal);
|
||||
|
||||
// Factory for XMLTermMouseListener
|
||||
extern nsresult NS_NewXMLTermMouseListener(nsIDOMEventListener** aInstancePtrResult, mozIXMLTerminal *aXMLTerminal);
|
||||
|
||||
// Factory for XMLTermDragListener
|
||||
extern nsresult NS_NewXMLTermDragListener(nsIDOMEventListener** aInstancePtrResult, mozIXMLTerminal *aXMLTerminal);
|
||||
|
||||
#endif //mozXMLTermListeners_h__
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,537 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozXMLTermSession.h: class to manage session input/output display
|
||||
// NOTE: This class is getting too unwieldy. It should be modularized,
|
||||
// using a separate class for entries, for example, once the dust
|
||||
// settles.
|
||||
|
||||
#include "nscore.h"
|
||||
#include "prlog.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
|
||||
#include "nsIContent.h"
|
||||
|
||||
#include "mozXMLT.h"
|
||||
#include "mozILineTermAux.h"
|
||||
#include "mozIXMLTerminal.h"
|
||||
|
||||
|
||||
class mozXMLTermSession
|
||||
{
|
||||
public:
|
||||
|
||||
mozXMLTermSession();
|
||||
virtual ~mozXMLTermSession();
|
||||
|
||||
/** Initializes XMLterm session
|
||||
* @param aXMLTerminal containing XMLTerminal object
|
||||
* @param aPresShell presentation shell associated with XMLterm
|
||||
* @param aDOMDocument DOM document associated with XMLterm
|
||||
*/
|
||||
NS_IMETHOD Init(mozIXMLTerminal* aXMLTerminal,
|
||||
nsIPresShell* aPresShell,
|
||||
nsIDOMDocument* aDOMDocument);
|
||||
|
||||
/** Finalizes (closes) session
|
||||
*/
|
||||
NS_IMETHOD Finalize(void);
|
||||
|
||||
/** Preprocesses user input before it is transmitted to LineTerm
|
||||
* @param aString (inout) input data to be preprocessed
|
||||
* @param consumed (output) true if input data has been consumed
|
||||
*/
|
||||
NS_IMETHOD Preprocess(const nsString& aString, PRBool& consumed);
|
||||
|
||||
/** Reads all available data from LineTerm and displays it;
|
||||
* returns when no more data is available.
|
||||
* @param lineTermAux LineTermAux object to read data from
|
||||
*/
|
||||
NS_IMETHOD ReadAll(mozILineTermAux* lineTermAux);
|
||||
|
||||
/** Gets current entry (command) number
|
||||
* @param aNumber (output) current entry number
|
||||
*/
|
||||
NS_IMETHOD GetCurrentEntryNumber(PRInt32 *aNumber);
|
||||
|
||||
/** Gets command history buffer count
|
||||
* @param aHistory (output) history buffer count
|
||||
*/
|
||||
NS_IMETHOD GetHistory(PRInt32 *aHistory);
|
||||
|
||||
/** Sets command history buffer count
|
||||
* @param aHistory history buffer count
|
||||
*/
|
||||
NS_IMETHOD SetHistory(PRInt32 aHistory);
|
||||
|
||||
/** Gets prompt string
|
||||
* @param aPrompt (output) prompt string
|
||||
*/
|
||||
NS_IMETHOD GetPrompt(PRUnichar **aPrompt);
|
||||
|
||||
/** Sets prompt string
|
||||
* @param aPrompt prompt string
|
||||
*/
|
||||
NS_IMETHOD SetPrompt(const PRUnichar* aPrompt);
|
||||
|
||||
protected:
|
||||
|
||||
/** ShellML element type (see ShellML documentation),
|
||||
* implemented as CLASS attribute of HTML elements
|
||||
*/
|
||||
enum SessionElementType {
|
||||
SESSION_ELEMENT = 0,
|
||||
ENTRY_ELEMENT,
|
||||
INPUT_ELEMENT,
|
||||
OUTPUT_ELEMENT,
|
||||
PROMPT_ELEMENT,
|
||||
COMMAND_ELEMENT,
|
||||
STDIN_ELEMENT,
|
||||
STDOUT_ELEMENT,
|
||||
STDERR_ELEMENT,
|
||||
SESSION_ELEMENT_TYPES
|
||||
};
|
||||
|
||||
/** user-generated input event type */
|
||||
enum SessionEventType {
|
||||
CLICK_EVENT = 0,
|
||||
DBLCLICK_EVENT,
|
||||
SESSION_EVENT_TYPES
|
||||
};
|
||||
|
||||
/** display style of output */
|
||||
enum OutputDisplayType {
|
||||
NO_NODE = 0,
|
||||
PRE_STDOUT_NODE,
|
||||
PRE_STDERR_NODE,
|
||||
SPAN_STDOUT_NODE,
|
||||
SPAN_STDERR_NODE,
|
||||
SPAN_MIXED_NODE,
|
||||
OUTPUT_DISPLAY_TYPES
|
||||
};
|
||||
|
||||
/** markup style of output */
|
||||
enum OutputMarkupType {
|
||||
PLAIN_TEXT = 0,
|
||||
HTML_FRAGMENT,
|
||||
HTML_DOCUMENT,
|
||||
XML_DOCUMENT
|
||||
};
|
||||
|
||||
/** settings for automatic markup detection */
|
||||
enum AutoDetectOption {
|
||||
NO_MARKUP = 0,
|
||||
FIRST_LINE,
|
||||
ANY_LINE
|
||||
};
|
||||
|
||||
/** type of output flush action */
|
||||
enum FlushActionType {
|
||||
DISPLAY_INCOMPLETE_FLUSH = 0,
|
||||
SPLIT_INCOMPLETE_FLUSH,
|
||||
CLEAR_INCOMPLETE_FLUSH,
|
||||
CLOSE_INCOMPLETE_FLUSH
|
||||
};
|
||||
|
||||
/** type of currently active meta command */
|
||||
enum MetaCommandType {
|
||||
NO_META_COMMAND = 0,
|
||||
STREAM_META_COMMAND,
|
||||
HTTP_META_COMMAND,
|
||||
LS_META_COMMAND,
|
||||
TREE_META_COMMAND,
|
||||
META_COMMAND_TYPES
|
||||
};
|
||||
|
||||
/** file type for directory display (TEMPORARY) */
|
||||
enum FileType {
|
||||
PLAIN_FILE = 0,
|
||||
DIRECTORY_FILE,
|
||||
EXECUTABLE_FILE,
|
||||
FILE_TYPES
|
||||
};
|
||||
|
||||
/** action code for navigating XMLterm DOM document */
|
||||
enum TreeActionCode {
|
||||
TREE_MOVE_UP = 1,
|
||||
TREE_MOVE_DOWN = 2,
|
||||
TREE_MOVE_LEFT = 3,
|
||||
TREE_MOVE_RIGHT = 4,
|
||||
TREE_PRINT_ATTS = 5,
|
||||
TREE_PRINT_HTML = 6,
|
||||
TREE_ACTION_CODES = 7
|
||||
};
|
||||
|
||||
/** Displays ("echoes") input text string with style and positions cursor
|
||||
* @param aString string to be displayed
|
||||
* @param aStyle style values for string (see lineterm.h)
|
||||
* @param cursorCol cursor column
|
||||
*/
|
||||
NS_IMETHOD DisplayInput(const nsString& aString,
|
||||
const nsString& aStyle,
|
||||
PRInt32 cursorCol);
|
||||
|
||||
/** Autodetects markup in current output line
|
||||
* @param aString string to be displayed
|
||||
* @param aStyle style values for string (see lineterm.h)
|
||||
* @param firstOutputLine true if this is the first output line
|
||||
*/
|
||||
NS_IMETHOD AutoDetectMarkup(const nsString& aString,
|
||||
const nsString& aStyle,
|
||||
PRBool firstOutputLine);
|
||||
|
||||
/** Initializes display of stream output with specified markup type
|
||||
* @param streamURL effective URL of stream output
|
||||
* @param streamMarkupType stream markup stype
|
||||
*/
|
||||
NS_IMETHOD InitStream(const nsString& streamURL,
|
||||
OutputMarkupType streamMarkupType);
|
||||
|
||||
/** Breaks output display by flushing and deleting incomplete lines */
|
||||
NS_IMETHOD BreakOutput(void);
|
||||
|
||||
/** Processes output string with specified style
|
||||
* @param aString string to be processed
|
||||
* @param aStyle style values for string (see lineterm.h)
|
||||
* (if it is a null string, STDOUT style is assumed)
|
||||
* @param newline true if this is a complete line of output
|
||||
* @param streamOutput true if string represents stream output
|
||||
*/
|
||||
NS_IMETHOD ProcessOutput(const nsString& aString,
|
||||
const nsString& aStyle,
|
||||
PRBool newline,
|
||||
PRBool streamOutput);
|
||||
|
||||
/** Appends text string to output buffer
|
||||
* (appended text may need to be flushed for it to be actually displayed)
|
||||
* @param aString string to be processed
|
||||
* @param aStyle style values for string (see lineterm.h)
|
||||
* (if it is a null string, STDOUT style is assumed)
|
||||
* @param newline true if this is a complete line of output
|
||||
*/
|
||||
NS_IMETHOD AppendOutput(const nsString& aString,
|
||||
const nsString& aStyle,
|
||||
PRBool newline);
|
||||
|
||||
/** Adds markup to LS output (TEMPORARY)
|
||||
* @param aString string to be processed
|
||||
* @param aStyle style values for string (see lineterm.h)
|
||||
* (if it is a null string, STDOUT style is assumed)
|
||||
*/
|
||||
NS_IMETHOD AppendLineLS(const nsString& aString,
|
||||
const nsString& aStyle);
|
||||
|
||||
/** Inserts HTML fragment string as child of parentNode, before specified
|
||||
* child node, or after the last child node
|
||||
* @param aString HTML fragment string to be inserted
|
||||
* @param parentNode parent node for HTML fragment
|
||||
* @param entryNumber entry number (default value = -1)
|
||||
* (if entryNumber >= 0, all '#' characters in aString
|
||||
* are substituted by entryNumber)
|
||||
* @param beforeNode child node before which to insert fragment;
|
||||
* if null, insert after last child node
|
||||
* (default value is null)
|
||||
* @param replace if true, replace beforeNode with inserted fragment
|
||||
* (default value is false)
|
||||
*/
|
||||
NS_IMETHOD InsertFragment(const nsString& aString,
|
||||
nsCOMPtr<nsIDOMNode>& parentNode,
|
||||
PRInt32 entryNumber = -1,
|
||||
nsIDOMNode* beforeNode = nsnull,
|
||||
PRBool replace = false);
|
||||
|
||||
/** Deep refresh of selected attributes for DOM elements
|
||||
* (WORKAROUND for inserting HTML fragments properly)
|
||||
* @param domNode DOM node of branch to be refreshed
|
||||
* @param entryNumber entry number (default value = -1)
|
||||
* (if entryNumber >= 0, all '#' characters in event
|
||||
* handler scripts are substituted by entryNumber)
|
||||
*/
|
||||
NS_IMETHOD DeepRefreshAttributes(nsCOMPtr<nsIDOMNode>& domNode,
|
||||
PRInt32 entryNumber = -1);
|
||||
|
||||
/** Forces display of data in output buffer
|
||||
* @param flushAction type of flush action: display, split-off, clear, or
|
||||
* close incomplete lines
|
||||
*/
|
||||
NS_IMETHOD FlushOutput(FlushActionType flushAction);
|
||||
|
||||
/** Scrolls document to align bottom and left margin with screen */
|
||||
NS_IMETHOD ScrollBottomLeft(void);
|
||||
|
||||
/** Create a DIV element with attributes NAME="preface", CLASS="preface",
|
||||
* and ID="preface0", containing an empty text node, and append it as a
|
||||
* child of the main BODY element. Also make it the current display element.
|
||||
*/
|
||||
NS_IMETHOD NewPreface(void);
|
||||
|
||||
/** Create and append a new DIV element with attributes NAME="entry",
|
||||
* CLASS="entry", and ID="entry#" as the last child of the main BODY element,
|
||||
* where "#" denotes the new entry number obtained by incrementing the
|
||||
* current entry number.
|
||||
* Inside the entry element, create a DIV element with attributes
|
||||
* NAME="input", CLASS="input", and ID="input#" containing two elements,
|
||||
* named "prompt" and "command", each containing a text node.
|
||||
* Insert the supplied prompt string into the prompt element's text node.
|
||||
* @param aPrompt prompt string to be inserted into prompt element
|
||||
*/
|
||||
NS_IMETHOD NewEntry(const nsString& aPrompt);
|
||||
|
||||
/** Append a BR element as the next child of specified parent.
|
||||
* @param parentNode parent node for BR element
|
||||
*/
|
||||
NS_IMETHOD NewBreak(nsIDOMNode* parentNode);
|
||||
|
||||
/** Creates an empty block element with tag name tagName with attributes
|
||||
* NAME="name", CLASS="name", and ID="name#", and appends it as a child of
|
||||
* the specified parent. ("#" denotes the specified number)
|
||||
* Also create an empty text node inside the new block element.
|
||||
* @param tagName tag name of element
|
||||
* @param name name and class of element
|
||||
* (If zero-length string, then no attributes are set)
|
||||
* @param number numeric suffix for element ID
|
||||
* (If < 0, no ID attribute is defined)
|
||||
* @param parentNode parent node for element
|
||||
* @param blockNode (output) block-level DOM node for created element
|
||||
* @param textNode (output) child text DOM node of element
|
||||
*/
|
||||
NS_IMETHOD NewElementWithText(const nsString& tagName,
|
||||
const nsString& name, PRInt32 number,
|
||||
nsIDOMNode* parentNode,
|
||||
nsCOMPtr<nsIDOMNode>& blockNode,
|
||||
nsCOMPtr<nsIDOMNode>& textNode);
|
||||
|
||||
/** Creates an empty anchor (A) element with tag name tagName with attributes
|
||||
* CLASS="classAttribute", and ID="classAttribute#", and appends it as a
|
||||
* child of the specified parent. ("#" denotes the specified number)
|
||||
* @param classAttribute class attribute of anchor element
|
||||
* (If zero-length string, then no attributes are set)
|
||||
* @param number numeric suffix for element ID
|
||||
* (If < 0, no ID attribute is defined)
|
||||
* @param parentNode parent node for element
|
||||
* @param anchorNode (output) DOM node for created anchor element
|
||||
*/
|
||||
NS_IMETHOD NewAnchor(const nsString& classAttribute,
|
||||
PRInt32 number,
|
||||
nsIDOMNode* parentNode,
|
||||
nsCOMPtr<nsIDOMNode>& anchorNode);
|
||||
|
||||
/** Creates an empty block element with tag name tagName with attributes
|
||||
* NAME="name", CLASS="name", and ID="name#", and appends it as a child of
|
||||
* the specified parent. ("#" denotes the specified number)
|
||||
* @param tagName tag name of element
|
||||
* @param name name and class of element
|
||||
* (If zero-length string, then no attributes are set)
|
||||
* @param number numeric suffix for element ID
|
||||
* (If < 0, no ID attribute is defined)
|
||||
* @param parentNode parent node for element
|
||||
* @param blockNode (output) block-level DOM node for created element
|
||||
*/
|
||||
NS_IMETHOD NewElement(const nsString& tagName,
|
||||
const nsString& name, PRInt32 number,
|
||||
nsIDOMNode* parentNode,
|
||||
nsCOMPtr<nsIDOMNode>& blockNode);
|
||||
|
||||
/** Creates a new DOM text node, and appends it as a child of the
|
||||
* specified parent.
|
||||
* @param parentNode parent node for element
|
||||
* @param textNode (output) created text DOM node
|
||||
*/
|
||||
NS_IMETHOD NewTextNode( nsIDOMNode* parentNode,
|
||||
nsCOMPtr<nsIDOMNode>& textNode);
|
||||
|
||||
/** Add event attributes (onclick, ondblclick, ...) to DOM node
|
||||
* @param name name of DOM node (supplied as argument to the event handler)
|
||||
* @param number entry number (supplied as argument to the event handler)
|
||||
* @param domNode DOM node to be modified
|
||||
*/
|
||||
NS_IMETHOD SetEventAttributes(const nsString& name,
|
||||
PRInt32 number,
|
||||
nsCOMPtr<nsIDOMNode>& domNode);
|
||||
|
||||
/** Sets text content of a DOM node to supplied string
|
||||
* @param textNode DOM text node to be modified
|
||||
* @param aString string to be inserted
|
||||
*/
|
||||
NS_IMETHOD SetDOMText(nsCOMPtr<nsIDOMNode>& textNode,
|
||||
const nsString& aString);
|
||||
|
||||
/** Checks if node is a text node
|
||||
* @param aNode DOM node to be checked
|
||||
* @return true if node is a text node
|
||||
*/
|
||||
PRBool IsTextNode(nsIDOMNode *aNode);
|
||||
|
||||
/** Checks if node is a text, span, or anchor node
|
||||
* (i.e., allowed inside a PRE element)
|
||||
* @param aNode DOM node to be checked
|
||||
* @return true if node is a text, span or anchor node
|
||||
*/
|
||||
PRBool IsPREInlineNode(nsIDOMNode* aNode);
|
||||
|
||||
/** Serializes DOM node and its content as an HTML fragment string
|
||||
* @param aNode DOM node to be serialized
|
||||
* @param indentString indentation prefix string
|
||||
* @param htmlString (output) serialized HTML fragment
|
||||
* @param deepContent if true, serialize children of node as well
|
||||
* (defaults to false)
|
||||
* @param insidePREnode set to true if aNode is embedded inside a PRE node
|
||||
* control formatting
|
||||
* (defaults to false)
|
||||
*/
|
||||
NS_IMETHOD ToHTMLString(nsIDOMNode* aNode,
|
||||
nsString& indentString,
|
||||
nsString& htmlString,
|
||||
PRBool deepContent = false,
|
||||
PRBool insidePRENode = false);
|
||||
|
||||
/** Implements the "tree:" meta command to traverse DOM tree
|
||||
* @param fileStream file stream for displaying tree traversal output
|
||||
* @param rootNode root node of DOM tree
|
||||
* @param currentNode current node for traversal
|
||||
* @param treeActionCode traversal action type
|
||||
*/
|
||||
void TraverseDOMTree(FILE* fileStream,
|
||||
nsIDOMNode* rootNode,
|
||||
nsCOMPtr<nsIDOMNode>& currentNode,
|
||||
TreeActionCode treeActionCode);
|
||||
|
||||
/** names of session elements */
|
||||
static const char* const sessionElementNames[SESSION_ELEMENT_TYPES];
|
||||
|
||||
/** names of session events */
|
||||
static const char* const sessionEventNames[SESSION_EVENT_TYPES];
|
||||
|
||||
/** names of meta commands */
|
||||
static const char* const metaCommandNames[META_COMMAND_TYPES];
|
||||
|
||||
/** names of file types (TEMPORARY) */
|
||||
static const char* const fileTypeNames[FILE_TYPES];
|
||||
|
||||
/** names of tree traversal action types */
|
||||
static const char* const treeActionNames[TREE_ACTION_CODES];
|
||||
|
||||
/** object initialization flag */
|
||||
PRBool mInitialized;
|
||||
|
||||
|
||||
/** non-owning reference to containing XMLTerminal object */
|
||||
mozIXMLTerminal* mXMLTerminal; // non-owning reference
|
||||
|
||||
/** non-owning reference to presentation shell associated with XMLterm */
|
||||
nsIPresShell* mPresShell; // non-owning reference (??)
|
||||
|
||||
/** non-owning reference to DOM document containing XMLterm */
|
||||
nsIDOMDocument* mDOMDocument; // non-owning reference (??)
|
||||
|
||||
|
||||
/** BODY node of document containing XMLterm */
|
||||
nsCOMPtr<nsIDOMNode> mBodyNode;
|
||||
|
||||
/** XMLterm session node */
|
||||
nsCOMPtr<nsIDOMNode> mSessionNode;
|
||||
|
||||
/** current debug node (TEMPORARY; used for tree traversal) */
|
||||
nsCOMPtr<nsIDOMNode> mCurrentDebugNode;
|
||||
|
||||
|
||||
/** starting entry node in the history list */
|
||||
nsCOMPtr<nsIDOMNode> mStartEntryNode;
|
||||
|
||||
/** current (and last) entry node in the history list */
|
||||
nsCOMPtr<nsIDOMNode> mCurrentEntryNode;
|
||||
|
||||
/** maximum number of commands allowed to be saved in history list */
|
||||
PRInt32 mMaxHistory;
|
||||
|
||||
/** entry number of first entry in history list */
|
||||
PRInt32 mStartEntryNumber;
|
||||
|
||||
/** entry number of current entry */
|
||||
PRInt32 mCurrentEntryNumber;
|
||||
|
||||
/** flag indicating whether current entry has output data */
|
||||
PRBool mEntryHasOutput;
|
||||
|
||||
/** span node for current command prompt (is this necessary?) */
|
||||
nsCOMPtr<nsIDOMNode> mPromptSpanNode;
|
||||
|
||||
/** span node for current command input (is this necessary?) */
|
||||
nsCOMPtr<nsIDOMNode> mCommandSpanNode;
|
||||
|
||||
/** text node for current command input (is this necessary?) */
|
||||
nsCOMPtr<nsIDOMNode> mInputTextNode;
|
||||
|
||||
|
||||
/** block-level node for current command output */
|
||||
nsCOMPtr<nsIDOMNode> mOutputBlockNode;
|
||||
|
||||
/** current display element node for command output */
|
||||
nsCOMPtr<nsIDOMNode> mOutputDisplayNode;
|
||||
|
||||
/** current text node for command output */
|
||||
nsCOMPtr<nsIDOMNode> mOutputTextNode;
|
||||
|
||||
|
||||
/** currently active meta command (if any) */
|
||||
MetaCommandType mMetaCommandType;
|
||||
|
||||
|
||||
/** currently active display style of output */
|
||||
OutputDisplayType mOutputDisplayType;
|
||||
|
||||
|
||||
/** currently active markup style of output */
|
||||
OutputMarkupType mOutputMarkupType;
|
||||
|
||||
/** currently active setting for automatic markup detection */
|
||||
AutoDetectOption mAutoDetect;
|
||||
|
||||
|
||||
/** flag indicating whether a line break needs to be output */
|
||||
PRBool mLineBreakNeeded;
|
||||
|
||||
/** flag marking the first line of output */
|
||||
PRBool mFirstOutputLine;
|
||||
|
||||
|
||||
/** buffer for incomplete line of PRE text */
|
||||
nsString mPreTextIncomplete;
|
||||
|
||||
/** buffer for complete lines of PRE text */
|
||||
nsString mPreTextBuffered;
|
||||
|
||||
/** copy of PRE text already displayed */
|
||||
nsString mPreTextDisplayed;
|
||||
|
||||
|
||||
/** prompt string (HTML) */
|
||||
nsString mPromptHTML;
|
||||
|
||||
/** buffer for HTML/XML fragment streams */
|
||||
nsString mFragmentBuffer;
|
||||
|
||||
};
|
|
@ -0,0 +1,326 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozXMLTermShell.cpp: implementation of mozIXMLTermShell
|
||||
// providing an XPCONNECT wrapper to the XMLTerminal interface,
|
||||
// thus allowing easy (and controlled) access from scripts
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIDocument.h"
|
||||
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIWebShellWindow.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "nsIAppShellService.h"
|
||||
#include "nsAppShellCIDs.h"
|
||||
#include "nsAppCoresCIDs.h"
|
||||
|
||||
#include "nsIDOMToolkitCore.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMSelection.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
|
||||
#include "mozXMLT.h"
|
||||
#include "mozXMLTermShell.h"
|
||||
|
||||
// Define Class IDs
|
||||
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
|
||||
static NS_DEFINE_CID(kToolkitCoreCID, NS_TOOLKITCORE_CID);
|
||||
|
||||
// Define Interface IDs
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// mozXMLTermShell factory
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewXMLTermShell(mozIXMLTermShell** aXMLTermShell)
|
||||
{
|
||||
NS_PRECONDITION(aXMLTermShell != nsnull, "null ptr");
|
||||
if (! aXMLTermShell)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aXMLTermShell = new mozXMLTermShell();
|
||||
if (! *aXMLTermShell)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aXMLTermShell);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// mozXMLTermShell implementation
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
mozXMLTermShell::mozXMLTermShell() :
|
||||
mInitialized(PR_FALSE),
|
||||
mContentWindow(nsnull),
|
||||
mContentAreaWebShell(nsnull),
|
||||
mXMLTerminal(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
mozXMLTermShell::~mozXMLTermShell()
|
||||
{
|
||||
if (mInitialized) {
|
||||
Finalize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Implement AddRef and Release
|
||||
NS_IMPL_ADDREF(mozXMLTermShell)
|
||||
NS_IMPL_RELEASE(mozXMLTermShell)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermShell::QueryInterface(REFNSIID aIID,void** aInstancePtr)
|
||||
{
|
||||
if (aInstancePtr == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
if ( aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsISupports*,
|
||||
NS_STATIC_CAST(mozIXMLTermShell*,this));
|
||||
|
||||
} else if ( aIID.Equals(mozIXMLTermShell::GetIID()) ) {
|
||||
*aInstancePtr = NS_STATIC_CAST(mozIXMLTermShell*,this);
|
||||
|
||||
} else {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozXMLTermShell::GetCurrentEntryNumber(PRInt32 *aNumber)
|
||||
{
|
||||
if (mXMLTerminal) {
|
||||
return mXMLTerminal->GetCurrentEntryNumber(aNumber);
|
||||
} else {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozXMLTermShell::GetHistory(PRInt32 *aHistory)
|
||||
{
|
||||
if (mXMLTerminal) {
|
||||
return mXMLTerminal->GetHistory(aHistory);
|
||||
} else {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozXMLTermShell::SetHistory(PRInt32 aHistory)
|
||||
{
|
||||
if (mXMLTerminal) {
|
||||
return mXMLTerminal->SetHistory(aHistory);
|
||||
} else {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozXMLTermShell::GetPrompt(PRUnichar **aPrompt)
|
||||
{
|
||||
if (mXMLTerminal) {
|
||||
return mXMLTerminal->GetPrompt(aPrompt);
|
||||
} else {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozXMLTermShell::SetPrompt(const PRUnichar* aPrompt)
|
||||
{
|
||||
if (mXMLTerminal) {
|
||||
return mXMLTerminal->SetPrompt(aPrompt);
|
||||
} else {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Initialize XMLTermShell
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermShell::Init(nsIDOMWindow* aContentWin,
|
||||
const PRUnichar* URL,
|
||||
const PRUnichar* args)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
XMLT_LOG(mozXMLTermShell::Init,10,("\n"));
|
||||
|
||||
if (mInitialized)
|
||||
return NS_ERROR_ALREADY_INITIALIZED;
|
||||
|
||||
if (!aContentWin)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
mContentWindow = aContentWin; // no addref
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObj = do_QueryInterface(mContentWindow,
|
||||
&result);
|
||||
if (NS_FAILED(result) || !globalObj)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell;
|
||||
globalObj->GetWebShell(getter_AddRefs(webShell));
|
||||
if (!webShell)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mContentAreaWebShell = webShell; // SVN: does this assignment addref?
|
||||
|
||||
// Create XMLTerminal
|
||||
nsCOMPtr<mozIXMLTerminal> newXMLTerminal;
|
||||
result = NS_NewXMLTerminal(getter_AddRefs(newXMLTerminal));
|
||||
|
||||
if(!newXMLTerminal)
|
||||
result = NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
// Initialize XMLTerminal with non-owning reference to us
|
||||
result = newXMLTerminal->Init(mContentAreaWebShell, this, URL, args);
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
mXMLTerminal = newXMLTerminal;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// De-initialize XMLTermShell and free resources
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermShell::Finalize(void)
|
||||
{
|
||||
XMLT_LOG(mozXMLTermShell::Finalize,10,("\n"));
|
||||
|
||||
if (mXMLTerminal) {
|
||||
// Finalize and release reference to XMLTerm object owned by us
|
||||
mXMLTerminal->Finalize();
|
||||
mXMLTerminal = nsnull;
|
||||
}
|
||||
|
||||
mContentAreaWebShell = nsnull;
|
||||
mContentWindow = nsnull;
|
||||
|
||||
mInitialized = PR_FALSE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// Poll for readable data from XMLTerminal
|
||||
NS_IMETHODIMP mozXMLTermShell::Poll(void)
|
||||
{
|
||||
if (!mXMLTerminal)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
return mXMLTerminal->Poll();
|
||||
}
|
||||
|
||||
|
||||
// Send string to LineTerm as if the user had typed it
|
||||
NS_IMETHODIMP mozXMLTermShell::SendText(const PRUnichar* buf,
|
||||
const PRUnichar* cookie)
|
||||
{
|
||||
if (!mXMLTerminal)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsAutoString sendStr (buf);
|
||||
|
||||
XMLT_LOG(mozXMLTermShell::SendText,10,("length=%d\n", sendStr.Length()));
|
||||
|
||||
return mXMLTerminal->SendText(sendStr, cookie);
|
||||
}
|
||||
|
||||
|
||||
// Create new XMLTerm window with specified argument string
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermShell::NewXMLTermWindow(const PRUnichar* args)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
|
||||
XMLT_LOG(mozXMLTermShell::NewXMLTermWindow,10,("\n"));
|
||||
|
||||
// Create the toolkit core instance...
|
||||
nsIDOMToolkitCore* toolkit = nsnull;
|
||||
result = nsServiceManager::GetService(kToolkitCoreCID,
|
||||
nsIDOMToolkitCore::GetIID(),
|
||||
(nsISupports**)&toolkit);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
nsAutoString argStr (args);
|
||||
toolkit->ShowWindowWithArgs( "chrome://xmlterm/content/XMLTermFrame.xul",
|
||||
nsnull, argStr );
|
||||
|
||||
/* Release the toolkit... */
|
||||
if (nsnull != toolkit) {
|
||||
nsServiceManager::ReleaseService(kToolkitCoreCID, toolkit);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Exit XMLTerm window
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermShell::Exit()
|
||||
{
|
||||
nsIAppShellService* appShell = nsnull;
|
||||
|
||||
XMLT_LOG(mozXMLTermShell::Exit,10,("\n"));
|
||||
|
||||
// Create the Application Shell instance...
|
||||
nsresult result = nsServiceManager::GetService(kAppShellServiceCID,
|
||||
nsIAppShellService::GetIID(),
|
||||
(nsISupports**)&appShell);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
appShell->Shutdown();
|
||||
nsServiceManager::ReleaseService(kAppShellServiceCID, appShell);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozXMLTermShell.h: declaration of mozXMLTermShell
|
||||
// which implements mozIXMLTermShell, providing an XPCONNECT wrapper
|
||||
// to the XMLTerminal interface, thus allowing easy (and controlled)
|
||||
// access from scripts
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nspr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "mozXMLT.h"
|
||||
#include "mozIXMLTerminal.h"
|
||||
#include "mozIXMLTermShell.h"
|
||||
|
||||
|
||||
class mozXMLTermShell : public mozIXMLTermShell {
|
||||
public:
|
||||
|
||||
mozXMLTermShell();
|
||||
virtual ~mozXMLTermShell();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// mozIXMLTermShell interface
|
||||
|
||||
NS_IMETHOD GetCurrentEntryNumber(PRInt32 *aNumber);
|
||||
|
||||
NS_IMETHOD GetHistory(PRInt32 *aHistory);
|
||||
NS_IMETHOD SetHistory(PRInt32 aHistory);
|
||||
NS_IMETHOD GetPrompt(PRUnichar **aPrompt);
|
||||
NS_IMETHOD SetPrompt(const PRUnichar* aPrompt);
|
||||
|
||||
NS_IMETHOD Init(nsIDOMWindow* aContentWin,
|
||||
const PRUnichar* URL,
|
||||
const PRUnichar* args);
|
||||
|
||||
NS_IMETHOD Finalize(void);
|
||||
NS_IMETHOD Poll(void);
|
||||
|
||||
NS_IMETHOD SendText(const PRUnichar* buf, const PRUnichar* cookie);
|
||||
|
||||
NS_IMETHOD NewXMLTermWindow(const PRUnichar* args);
|
||||
|
||||
NS_IMETHOD Exit(void);
|
||||
|
||||
protected:
|
||||
|
||||
/** object initialization flag */
|
||||
PRBool mInitialized;
|
||||
|
||||
/** non-owning reference to content window for XMLterm */
|
||||
nsIDOMWindow* mContentWindow;
|
||||
|
||||
/** non-owning reference (??) to web shell for content window */
|
||||
nsIWebShell* mContentAreaWebShell;
|
||||
|
||||
/** owning reference to XMLTerminal object created by us */
|
||||
nsCOMPtr<mozIXMLTerminal> mXMLTerminal;
|
||||
};
|
|
@ -0,0 +1,568 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozXMLTermStream.cpp: implementation of mozIXMLTermStream
|
||||
// to display HTML/XML streams as documents
|
||||
|
||||
#include "nscore.h"
|
||||
#include "prlog.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsIAllocator.h"
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsIDocumentLoader.h"
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIPresShell.h"
|
||||
|
||||
#include "nsIViewManager.h"
|
||||
#include "nsIScrollableView.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsIFrame.h"
|
||||
|
||||
#include "nsIScriptContextOwner.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIDOMWindowCollection.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMHTMLDocument.h"
|
||||
#include "nsIDocument.h"
|
||||
|
||||
#include "nsIURL.h"
|
||||
#include "nsNeckoUtil.h"
|
||||
|
||||
#include "mozXMLT.h"
|
||||
#include "mozXMLTermUtils.h"
|
||||
#include "mozXMLTermStream.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// mozXMLTermStream factory
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewXMLTermStream(mozIXMLTermStream** aXMLTermStream)
|
||||
{
|
||||
NS_PRECONDITION(aXMLTermStream != nsnull, "null ptr");
|
||||
if (!aXMLTermStream)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aXMLTermStream = new mozXMLTermStream();
|
||||
if (! *aXMLTermStream)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aXMLTermStream);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// mozXMLTermStream implementation
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
|
||||
mozXMLTermStream::mozXMLTermStream() :
|
||||
mUTF8Buffer(""),
|
||||
mUTF8Offset(0),
|
||||
mMaxResizeHeight(0),
|
||||
mDOMWindow( nsnull ),
|
||||
mDOMIFrameElement( nsnull ),
|
||||
mContext( nsnull ),
|
||||
mLoadGroup( nsnull ),
|
||||
mChannel( nsnull ),
|
||||
mStreamListener( nsnull )
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
|
||||
mozXMLTermStream::~mozXMLTermStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Implement AddRef and Release
|
||||
NS_IMPL_ADDREF(mozXMLTermStream)
|
||||
NS_IMPL_RELEASE(mozXMLTermStream)
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTermStream::QueryInterface(REFNSIID aIID,void** aInstancePtr)
|
||||
{
|
||||
if (aInstancePtr == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
if ( aIID.Equals(NS_GET_IID(nsISupports))) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsISupports*,
|
||||
NS_STATIC_CAST(mozIXMLTermStream*,this));
|
||||
|
||||
} else if(aIID.Equals(NS_GET_IID(nsIBaseStream))) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIBaseStream*,this);
|
||||
|
||||
} else if(aIID.Equals(NS_GET_IID(nsIInputStream))) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIInputStream*,this);
|
||||
|
||||
} else if(aIID.Equals(NS_GET_IID(mozIXMLTermStream))) {
|
||||
*aInstancePtr = NS_STATIC_CAST(mozIXMLTermStream*,this);
|
||||
|
||||
} else {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
XMLT_LOG(mozXMLTermStream::QueryInterface,20,("mRefCnt = %d\n", mRefCnt));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// mozIXMLTermStream interface
|
||||
|
||||
/** Open stream in specified frame, or in current frame if frameName is null
|
||||
* @param aDOMWindow parent window
|
||||
* @param frameName name of child frame in which to display stream, or null
|
||||
* to display in parent window
|
||||
* @param contentURL URL of stream content
|
||||
* @param contentType MIME type of stream content
|
||||
* @param maxResizeHeight maximum resize height (0=> do not resize)
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
NS_IMETHODIMP mozXMLTermStream::Open(nsIDOMWindow* aDOMWindow,
|
||||
const char* frameName,
|
||||
const char* contentURL,
|
||||
const char* contentType,
|
||||
PRInt32 maxResizeHeight)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
XMLT_LOG(mozXMLTermStream::Open,20,("contentURL=%s, contentType=%s\n",
|
||||
contentURL, contentType));
|
||||
|
||||
mMaxResizeHeight = maxResizeHeight;
|
||||
|
||||
if (frameName && (strlen(frameName) > 0)) {
|
||||
// Open stream in named subframe of current frame
|
||||
XMLT_LOG(mozXMLTermStream::Open,22,("frameName=%s\n", frameName));
|
||||
|
||||
nsAutoString innerFrameName = frameName;
|
||||
|
||||
// Get DOM IFRAME element
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
result = aDOMWindow->GetDocument(getter_AddRefs(domDoc));
|
||||
if (NS_FAILED(result) || !domDoc)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLDocument> domHTMLDoc = do_QueryInterface(domDoc);
|
||||
if (!domHTMLDoc)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMNodeList> nodeList;
|
||||
result = domHTMLDoc->GetElementsByName(innerFrameName,
|
||||
getter_AddRefs(nodeList));
|
||||
if (NS_FAILED(result) || !nodeList)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PRUint32 count;
|
||||
nodeList->GetLength(&count);
|
||||
PR_ASSERT(count==1);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> domNode;
|
||||
result = nodeList->Item(0, getter_AddRefs(domNode));
|
||||
if (NS_FAILED(result) || !domNode)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mDOMIFrameElement = do_QueryInterface(domNode);
|
||||
if (!mDOMIFrameElement)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Ensure that it is indeed an IFRAME element
|
||||
nsAutoString tagName;
|
||||
result = mDOMIFrameElement->GetTagName(tagName);
|
||||
if (NS_FAILED(result))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (!tagName.EqualsIgnoreCase("iframe"))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (mMaxResizeHeight > 0) {
|
||||
// Set initial IFRAME size to be as wide as the window, but very short
|
||||
nsAutoString attWidth = "width";
|
||||
nsAutoString valWidth = "100%";
|
||||
mDOMIFrameElement->SetAttribute(attWidth,valWidth);
|
||||
|
||||
nsAutoString attHeight = "height";
|
||||
nsAutoString valHeight = "10";
|
||||
mDOMIFrameElement->SetAttribute(attHeight,valHeight);
|
||||
}
|
||||
|
||||
// Get inner DOM window by looking up the frames list
|
||||
nsCOMPtr<nsIDOMWindow> innerDOMWindow;
|
||||
result = mozXMLTermUtils::GetInnerDOMWindow(aDOMWindow, innerFrameName,
|
||||
getter_AddRefs(innerDOMWindow));
|
||||
if (NS_FAILED(result) || !innerDOMWindow)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mDOMWindow = innerDOMWindow;
|
||||
|
||||
} else {
|
||||
// Open stream in current frame
|
||||
mDOMIFrameElement = nsnull;
|
||||
mDOMWindow = aDOMWindow;
|
||||
}
|
||||
|
||||
// Get webshell for DOM window
|
||||
nsCOMPtr<nsIWebShell> webShell;
|
||||
result = mozXMLTermUtils::ConvertDOMWindowToWebShell(mDOMWindow,
|
||||
getter_AddRefs(webShell));
|
||||
if (NS_FAILED(result) || !webShell)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
NS_WITH_SERVICE(nsIIOService, ioService, kIOServiceCID, &result);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
nsCOMPtr<nsIInputStream> inputStream = this;
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
result = NS_NewURI(getter_AddRefs(uri), contentURL, nsnull);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
result = NS_NewLoadGroup(nsnull, nsnull, nsnull, getter_AddRefs(mLoadGroup));
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
PRInt32 contentLength = 1024; // ??? What's this length
|
||||
result = ioService->NewInputStreamChannel(uri, contentType, contentLength,
|
||||
inputStream, mLoadGroup, nsnull,
|
||||
getter_AddRefs(mChannel));
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
// Determine Class ID for viewing specified mimetype
|
||||
nsCID classID;
|
||||
static const char command[] = "view";
|
||||
nsCAutoString progID = NS_DOCUMENT_LOADER_FACTORY_PROGID_PREFIX;
|
||||
progID += command;
|
||||
progID += "/";
|
||||
progID += contentType;
|
||||
|
||||
result = nsComponentManager::ProgIDToCLSID(progID.GetBuffer(),
|
||||
&classID);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory;
|
||||
result = nsComponentManager::CreateInstance(classID, nsnull,
|
||||
NS_GET_IID(nsIDocumentLoaderFactory),
|
||||
getter_AddRefs(docLoaderFactory));
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
nsCOMPtr<nsIContentViewer> contentViewer;
|
||||
result = docLoaderFactory->CreateInstance(command,
|
||||
mChannel,
|
||||
mLoadGroup,
|
||||
contentType,
|
||||
webShell,
|
||||
nsnull,
|
||||
getter_AddRefs(mStreamListener),
|
||||
getter_AddRefs(contentViewer) );
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
nsCOMPtr<nsIContentViewerContainer> contViewContainer =
|
||||
do_QueryInterface(webShell);
|
||||
result = contentViewer->SetContainer(contViewContainer);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
result = webShell->Embed(contentViewer, command, (nsISupports*) nsnull);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
result = mStreamListener->OnStartRequest(mChannel, mContext);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
XMLT_LOG(mozXMLTermStream::Open,21,("returning\n"));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// nsIBaseStream interface
|
||||
NS_IMETHODIMP mozXMLTermStream::Close(void)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
XMLT_LOG(mozXMLTermStream::Close,20,("\n"));
|
||||
|
||||
mUTF8Buffer = "";
|
||||
mUTF8Offset = 0;
|
||||
|
||||
PRUint32 sourceOffset = 0;
|
||||
PRUint32 count = 0;
|
||||
result = mStreamListener->OnDataAvailable(mChannel, mContext,
|
||||
this, sourceOffset, count);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
nsresult status = NS_OK;
|
||||
nsAutoString errorMsg = "";
|
||||
result = mStreamListener->OnStopRequest(mChannel, mContext,
|
||||
status, errorMsg.GetUnicode());
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
if (mMaxResizeHeight && mDOMIFrameElement) {
|
||||
// Size frame to content
|
||||
result = SizeToContentHeight(mMaxResizeHeight);
|
||||
}
|
||||
mMaxResizeHeight = 0;
|
||||
|
||||
// Release interfaces etc
|
||||
mDOMWindow = nsnull;
|
||||
mDOMIFrameElement = nsnull;
|
||||
mContext = nsnull;
|
||||
mLoadGroup = nsnull;
|
||||
mChannel = nsnull;
|
||||
mStreamListener = nsnull;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Adjusts height of frame displaying stream to fit content
|
||||
* @param maxHeight maximum height of resized frame (pixels)
|
||||
* (zero value implies no maximum)
|
||||
*/
|
||||
NS_IMETHODIMP mozXMLTermStream::SizeToContentHeight(PRInt32 maxHeight)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
// Get webshell
|
||||
nsCOMPtr<nsIWebShell> webShell;
|
||||
result = mozXMLTermUtils::ConvertDOMWindowToWebShell(mDOMWindow,
|
||||
getter_AddRefs(webShell));
|
||||
if (NS_FAILED(result) || !webShell)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Get pres context
|
||||
nsCOMPtr<nsIPresContext> presContext;
|
||||
result = mozXMLTermUtils::GetWebShellPresContext(webShell,
|
||||
getter_AddRefs(presContext));
|
||||
if (NS_FAILED(result) || !presContext)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Get scrollable view
|
||||
nsCOMPtr<nsIScrollableView> scrollableView;
|
||||
result = mozXMLTermUtils::GetPresContextScrollableView(presContext,
|
||||
getter_AddRefs(scrollableView));
|
||||
if (NS_FAILED(result) || !scrollableView)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Get device context
|
||||
nsCOMPtr<nsIDeviceContext> deviceContext;
|
||||
result = mozXMLTermUtils::GetPresContextDeviceContext(presContext,
|
||||
getter_AddRefs(deviceContext));
|
||||
if (NS_FAILED(result) || !deviceContext)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Determine twips to pixels conversion factor
|
||||
float pixelScale;
|
||||
presContext->GetTwipsToPixels(&pixelScale);
|
||||
|
||||
// Get scrollbar dimensions in pixels
|
||||
float sbWidth, sbHeight;
|
||||
deviceContext->GetScrollBarDimensions(sbWidth, sbHeight);
|
||||
PRInt32 scrollBarWidth = PRInt32(sbWidth*pixelScale);
|
||||
PRInt32 scrollBarHeight = PRInt32(sbHeight*pixelScale);
|
||||
|
||||
// Determine webshell size in pixels
|
||||
PRInt32 shellX, shellY, shellWidth, shellHeight;
|
||||
result = webShell->GetBounds(shellX, shellY, shellWidth, shellHeight);
|
||||
|
||||
// Determine page size in pixels
|
||||
nscoord contX, contY;
|
||||
scrollableView->GetContainerSize(&contX, &contY);
|
||||
|
||||
PRInt32 pageWidth, pageHeight;
|
||||
pageWidth = PRInt32((float)contX*pixelScale);
|
||||
pageHeight = PRInt32((float)contY*pixelScale);
|
||||
|
||||
printf("mozXMLTermStream::SizeToContentHeight: scrollbar %d, %d\n",
|
||||
scrollBarWidth, scrollBarHeight);
|
||||
|
||||
printf("mozXMLTermStream::SizeToContentHeight: shell %d, %d\n",
|
||||
shellWidth, shellHeight);
|
||||
|
||||
printf("mozXMLTermStream::SizeToContentHeight: page %d, %d, %e\n",
|
||||
pageWidth, pageHeight, pixelScale);
|
||||
|
||||
if ((pageHeight > shellHeight) || (pageWidth > shellWidth)) {
|
||||
// Page larger than webshell
|
||||
nsAutoString attHeight = "height";
|
||||
nsAutoString attWidth = "width";
|
||||
nsAutoString attValue = "";
|
||||
|
||||
PRInt32 newPageHeight = pageHeight;
|
||||
PRInt32 excessWidth = (pageWidth+scrollBarWidth - shellWidth);
|
||||
|
||||
printf("mozXMLTermStream::SizeToContentHeight: excessWidth %d\n",
|
||||
excessWidth);
|
||||
|
||||
if (excessWidth > 0) {
|
||||
// Widen IFRAME beyond page width by scrollbar width
|
||||
attValue = "";
|
||||
attValue.Append(shellWidth+scrollBarWidth);
|
||||
mDOMIFrameElement->SetAttribute(attWidth,attValue);
|
||||
|
||||
// Recompute page dimensions
|
||||
scrollableView->GetContainerSize(&contX, &contY);
|
||||
pageWidth = PRInt32((float)contX*pixelScale);
|
||||
pageHeight = PRInt32((float)contY*pixelScale);
|
||||
|
||||
newPageHeight = pageHeight;
|
||||
if (excessWidth > scrollBarWidth)
|
||||
newPageHeight += scrollBarHeight;
|
||||
|
||||
printf("mozXMLTermStream::SizeToContentHeight: page2 %d, %d, %d\n",
|
||||
pageWidth, pageHeight, newPageHeight);
|
||||
|
||||
// Reset IFRAME width
|
||||
attValue = "";
|
||||
attValue.Append(shellWidth);
|
||||
mDOMIFrameElement->SetAttribute(attWidth,attValue);
|
||||
}
|
||||
|
||||
// Resize IFRAME height to match page height (subject to a maximum)
|
||||
if (newPageHeight > maxHeight) newPageHeight = maxHeight;
|
||||
attValue = "";
|
||||
attValue.Append(newPageHeight);
|
||||
mDOMIFrameElement->SetAttribute(attHeight,attValue);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// nsIInputStream interface
|
||||
NS_IMETHODIMP mozXMLTermStream::Available(PRUint32 *_retval)
|
||||
{
|
||||
if (!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*_retval = mUTF8Buffer.Length() - mUTF8Offset;
|
||||
|
||||
XMLT_LOG(mozXMLTermStream::Available,60,("retval=%d\n", *_retval));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozXMLTermStream::Read(char* buf, PRUint32 count,
|
||||
PRUint32* _retval)
|
||||
{
|
||||
XMLT_LOG(mozXMLTermStream::Read,60,("count=%d\n", count));
|
||||
|
||||
if (!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
PR_ASSERT(mUTF8Buffer.Length() >= mUTF8Offset);
|
||||
|
||||
PRUint32 remCount = mUTF8Buffer.Length() - mUTF8Offset;
|
||||
|
||||
if (remCount == 0) {
|
||||
// Empty buffer
|
||||
*_retval = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (count >= remCount) {
|
||||
// Return entire remaining buffer
|
||||
*_retval = remCount;
|
||||
|
||||
} else {
|
||||
// Return only portion of buffer
|
||||
*_retval = count;
|
||||
}
|
||||
|
||||
// Copy portion of string
|
||||
mUTF8Buffer.ToCString(buf, *_retval, mUTF8Offset);
|
||||
|
||||
mUTF8Offset += *_retval;
|
||||
|
||||
XMLT_LOG(mozXMLTermStream::Read,61,("*retval=%d\n", *_retval));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Write Unicode string to stream (blocks until write is completed)
|
||||
* @param buf string to write
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
NS_IMETHODIMP mozXMLTermStream::Write(const PRUnichar* buf)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
XMLT_LOG(mozXMLTermStream::Write,50,("\n"));
|
||||
|
||||
if (!buf)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsAutoString strBuf ( buf );
|
||||
|
||||
// Convert Unicode string to UTF8 and store in buffer
|
||||
char* utf8Str = strBuf.ToNewUTF8String();
|
||||
mUTF8Buffer = utf8Str;
|
||||
nsAllocator::Free(utf8Str);
|
||||
|
||||
mUTF8Offset = 0;
|
||||
|
||||
PRUint32 sourceOffset = 0;
|
||||
|
||||
while (mUTF8Offset < mUTF8Buffer.Length()) {
|
||||
PRUint32 remCount = mUTF8Buffer.Length() - mUTF8Offset;
|
||||
result = mStreamListener->OnDataAvailable(mChannel, mContext,
|
||||
this, sourceOffset, remCount);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
}
|
||||
|
||||
XMLT_LOG(mozXMLTermStream::Write,51,("returning mUTF8Offset=%d\n",
|
||||
mUTF8Offset));
|
||||
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozXMLTermStream.h: declaration of mozXMLTermStream
|
||||
// which implements the mozIXMLTermStream interface
|
||||
// to display HTML/XML streams as documents
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nspr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "mozXMLT.h"
|
||||
#include "mozIXMLTermStream.h"
|
||||
|
||||
class mozXMLTermStream : public mozIXMLTermStream
|
||||
{
|
||||
public:
|
||||
|
||||
mozXMLTermStream();
|
||||
virtual ~mozXMLTermStream();
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIInputStream interface
|
||||
NS_IMETHOD Close(void);
|
||||
|
||||
NS_IMETHOD Available(PRUint32 *_retval);
|
||||
NS_IMETHOD Read(char * buf, PRUint32 count, PRUint32 *_retval);
|
||||
|
||||
// mozIXMLTermStream interface
|
||||
|
||||
// Open stream in specified frame, or in current frame if frameName is null
|
||||
NS_IMETHOD Open(nsIDOMWindow* aDOMWindow,
|
||||
const char* frameName,
|
||||
const char* contentURL,
|
||||
const char* contentType,
|
||||
PRInt32 maxResizeHeight);
|
||||
|
||||
// Write Unicode string to stream
|
||||
NS_IMETHOD Write(const PRUnichar* buf);
|
||||
|
||||
protected:
|
||||
|
||||
/** Adjusts height of frame displaying stream to fit content
|
||||
* @param maxHeight maximum height of resized frame (pixels)
|
||||
* (zero value implies no maximum)
|
||||
*/
|
||||
NS_IMETHOD SizeToContentHeight(PRInt32 maxHeight);
|
||||
|
||||
/** UTF8 data buffer to hold to be read by rendering engine */
|
||||
nsCString mUTF8Buffer;
|
||||
|
||||
/** offset at which to start reading the UTF8 data buffer */
|
||||
PRInt32 mUTF8Offset;
|
||||
|
||||
/** maximum frame height for resizing */
|
||||
PRInt32 mMaxResizeHeight;
|
||||
|
||||
/** DOM window in which to display stream */
|
||||
nsCOMPtr<nsIDOMWindow> mDOMWindow;
|
||||
|
||||
/** Frame element in which to display stream */
|
||||
nsCOMPtr<nsIDOMElement> mDOMIFrameElement;
|
||||
|
||||
/** Context for stream display (what's this??) */
|
||||
nsCOMPtr<nsISupports> mContext;
|
||||
|
||||
/** Load group for stream display (what's this??) */
|
||||
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
||||
|
||||
/** Channel for stream display (what's this??) */
|
||||
nsCOMPtr<nsIChannel> mChannel;
|
||||
|
||||
/** Stream listener object */
|
||||
nsCOMPtr<nsIStreamListener> mStreamListener;
|
||||
};
|
||||
|
|
@ -0,0 +1,454 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozXMLTermUtils.cpp: XMLTerm utilities implementation
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nspr.h"
|
||||
#include "prlog.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIScriptContextOwner.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIDOMWindowCollection.h"
|
||||
#include "nsIDocument.h"
|
||||
|
||||
#include "mozXMLT.h"
|
||||
#include "mozXMLTermUtils.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Gets presentation context for web shell
|
||||
* @param aWebShell web shell
|
||||
* @param aPresContext returned presentation context
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
NS_EXPORT nsresult
|
||||
mozXMLTermUtils::GetWebShellPresContext(nsIWebShell* aWebShell,
|
||||
nsIPresContext** aPresContext)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
XMLT_LOG(mozXMLTermUtils::GetWebShellPresContext,30,("\n"));
|
||||
|
||||
if (!aPresContext)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*aPresContext = nsnull;
|
||||
|
||||
nsCOMPtr<nsIContentViewer> contViewer;
|
||||
result = aWebShell->GetContentViewer(getter_AddRefs(contViewer));
|
||||
if (NS_FAILED(result) || !contViewer)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDocumentViewer> docViewer;
|
||||
result = contViewer->QueryInterface(NS_GET_IID(nsIDocumentViewer),
|
||||
(void**)getter_AddRefs(docViewer));
|
||||
if (NS_FAILED(result) || !docViewer)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIPresContext> presContext;
|
||||
result = docViewer->GetPresContext(*getter_AddRefs(presContext));
|
||||
if (NS_FAILED(result) || !presContext)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*aPresContext = presContext.get();
|
||||
NS_ADDREF(*aPresContext);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Gets DOM document for web shell
|
||||
* @param aWebShell web shell
|
||||
* @param aDOMDocument returned DOM document
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
NS_EXPORT nsresult
|
||||
mozXMLTermUtils::GetWebShellDOMDocument(nsIWebShell* aWebShell,
|
||||
nsIDOMDocument** aDOMDocument)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
XMLT_LOG(mozXMLTermUtils::GetWebShellDOMDocument,30,("\n"));
|
||||
|
||||
if (!aDOMDocument)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*aDOMDocument = nsnull;
|
||||
|
||||
nsCOMPtr<nsIContentViewer> contViewer;
|
||||
result = aWebShell->GetContentViewer(getter_AddRefs(contViewer));
|
||||
if (NS_FAILED(result) || !contViewer)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDocumentViewer> docViewer;
|
||||
result = contViewer->QueryInterface(NS_GET_IID(nsIDocumentViewer),
|
||||
(void**)getter_AddRefs(docViewer));
|
||||
if (NS_FAILED(result) || !docViewer)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
result = docViewer->GetDocument(*getter_AddRefs(document));
|
||||
|
||||
if (NS_FAILED(result) || !document)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> domDocument = do_QueryInterface(document);
|
||||
if (!domDocument)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*aDOMDocument = domDocument.get();
|
||||
NS_ADDREF(*aDOMDocument);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Gets DOM window for web shell
|
||||
* @param aWebShell web shell
|
||||
* @param aDOMWindow returned DOM window (frame)
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
NS_EXPORT nsresult
|
||||
mozXMLTermUtils::ConvertWebShellToDOMWindow(nsIWebShell* aWebShell,
|
||||
nsIDOMWindow** aDOMWindow)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
XMLT_LOG(mozXMLTermUtils::ConvertWebShellToDOMWindow,30,("\n"));
|
||||
|
||||
if (!aDOMWindow)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*aDOMWindow = nsnull;
|
||||
|
||||
nsCOMPtr<nsIScriptContextOwner> scriptContextOwner =
|
||||
do_QueryInterface(aWebShell);
|
||||
if (!scriptContextOwner)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
|
||||
result = scriptContextOwner->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject));
|
||||
|
||||
if (NS_FAILED(result) || !scriptGlobalObject)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(scriptGlobalObject);
|
||||
if (!domWindow)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*aDOMWindow = domWindow.get();
|
||||
NS_ADDREF(*aDOMWindow);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Gets web shell for DOM window
|
||||
* @param aDOMWindow DOM window (frame)
|
||||
* @param aWebShell returned web shell
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
NS_EXPORT nsresult
|
||||
mozXMLTermUtils::ConvertDOMWindowToWebShell(nsIDOMWindow* aDOMWindow,
|
||||
nsIWebShell** aWebShell)
|
||||
{
|
||||
XMLT_LOG(mozXMLTermUtils::ConvertDOMWindowToWebShell,30,("\n"));
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObject = do_QueryInterface(aDOMWindow);
|
||||
if (!globalObject)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
globalObject->GetWebShell(aWebShell);
|
||||
|
||||
if (!*aWebShell)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Locates named inner DOM window (frame) inside outer DOM window
|
||||
* @param outerDOMWindow outer DOM window (frame)
|
||||
* @param innerFrameName name of inner frame to be returned
|
||||
* @param innerDOMWindow returned inner DOM window (frame)
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
NS_EXPORT nsresult
|
||||
mozXMLTermUtils::GetInnerDOMWindow(nsIDOMWindow* outerDOMWindow,
|
||||
const nsString& innerFrameName,
|
||||
nsIDOMWindow** innerDOMWindow)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
XMLT_LOG(mozXMLTermUtils::GetInnerDOMWindow,30,("\n"));
|
||||
|
||||
nsCOMPtr<nsIDOMWindowCollection> innerDOMWindowList;
|
||||
result = outerDOMWindow->GetFrames(getter_AddRefs(innerDOMWindowList));
|
||||
if (NS_FAILED(result) || !innerDOMWindowList)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PRUint32 frameCount = 0;
|
||||
result = innerDOMWindowList->GetLength(&frameCount);
|
||||
XMLT_LOG(mozXMLTermUtils::GetInnerDOMWindow,31,("frameCount=%d\n",
|
||||
frameCount));
|
||||
|
||||
result = innerDOMWindowList->NamedItem(innerFrameName, innerDOMWindow);
|
||||
if (NS_FAILED(result) || !*innerDOMWindow)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Gets the scrollable view for presentation context
|
||||
* @param aPresContext presentation context
|
||||
* @param aScrollableView returned scrollable view
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
NS_EXPORT nsresult
|
||||
mozXMLTermUtils::GetPresContextScrollableView(nsIPresContext* aPresContext,
|
||||
nsIScrollableView** aScrollableView)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
XMLT_LOG(mozXMLTermUtils::GetPresContextScrollableView,30,("\n"));
|
||||
|
||||
if (!aScrollableView)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*aScrollableView = nsnull;
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
result = aPresContext->GetShell(getter_AddRefs(presShell));
|
||||
if (NS_FAILED(result) || !presShell)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIViewManager> viewManager;
|
||||
result = presShell->GetViewManager(getter_AddRefs(viewManager));
|
||||
if (NS_FAILED(result) || !viewManager)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return viewManager->GetRootScrollableView(aScrollableView);
|
||||
}
|
||||
|
||||
|
||||
/** Gets the device context for presentation context
|
||||
* @param aPresContext presentation context
|
||||
* @param aDeviceContext returned device context
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
NS_EXPORT nsresult
|
||||
mozXMLTermUtils::GetPresContextDeviceContext(nsIPresContext* aPresContext,
|
||||
nsIDeviceContext** aDeviceContext)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
XMLT_LOG(mozXMLTermUtils::GetPresContextScrollableView,30,("\n"));
|
||||
|
||||
if (!aDeviceContext)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*aDeviceContext = nsnull;
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
result = aPresContext->GetShell(getter_AddRefs(presShell));
|
||||
if (NS_FAILED(result) || !presShell)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIViewManager> viewManager;
|
||||
result = presShell->GetViewManager(getter_AddRefs(viewManager));
|
||||
if (NS_FAILED(result) || !viewManager)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDeviceContext> deviceContext;
|
||||
result = viewManager->GetDeviceContext(*getter_AddRefs(deviceContext));
|
||||
if (NS_FAILED(result) || !deviceContext)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*aDeviceContext = deviceContext.get();
|
||||
NS_ADDREF(*aDeviceContext);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Gets the script context for document
|
||||
* @param aDOMDocument document providing context
|
||||
* @param aScriptContext returned script context
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
NS_EXPORT nsresult
|
||||
mozXMLTermUtils::GetScriptContext(nsIDOMDocument* aDOMDocument,
|
||||
nsIScriptContext** aScriptContext)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
XMLT_LOG(mozXMLTermUtils::GetScriptContext,20,("\n"));
|
||||
|
||||
nsCOMPtr<nsIDocument> doc ( do_QueryInterface(aDOMDocument) );
|
||||
if (!doc)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
|
||||
result = doc->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject));
|
||||
|
||||
if (NS_FAILED(result) || !scriptGlobalObject)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return scriptGlobalObject->GetContext(aScriptContext);
|
||||
}
|
||||
|
||||
|
||||
/** Executes script in specified document's context.
|
||||
* @param aDOMDocument document providing context for script execution
|
||||
* @param aScript string to be executed
|
||||
* @param aOutput output string produced by script execution
|
||||
* @return NS_OK if script was valid and got executed properly
|
||||
*/
|
||||
NS_EXPORT nsresult
|
||||
mozXMLTermUtils::ExecuteScript(nsIDOMDocument* aDOMDocument,
|
||||
const nsString& aScript,
|
||||
nsString& aOutput)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
XMLT_LOG(mozXMLTermUtils::ExecuteScript,20,("\n"));
|
||||
|
||||
// Get document principal
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDOMDocument);
|
||||
if (!doc)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIPrincipal> docPrincipal=dont_AddRef(doc->GetDocumentPrincipal());
|
||||
|
||||
// Get document script context
|
||||
nsCOMPtr<nsIScriptContext> scriptContext;
|
||||
result = GetScriptContext(aDOMDocument, getter_AddRefs(scriptContext));
|
||||
if (NS_FAILED(result) || !scriptContext)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Execute script
|
||||
PRBool isUndefined = PR_FALSE;
|
||||
nsString outputString = "";
|
||||
const char* URL = "";
|
||||
const char* version = "";
|
||||
result = scriptContext-> EvaluateString(aScript, (void *) nsnull,
|
||||
docPrincipal, URL, 0, version,
|
||||
aOutput, &isUndefined);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/** Returns a timestamp string containing the local time, if at least
|
||||
* deltaSec seconds have elapsed since the last timestamp. Otherwise,
|
||||
* a null string is returned.
|
||||
* @param deltaSec minimum elapsed seconds since last timestamp (>=0)
|
||||
* @param lastTime in/out parameter containing time of last timestamp
|
||||
* @param aTimeStamp returned timestamp string
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
NS_IMETHODIMP mozXMLTermUtils::TimeStamp(PRInt32 deltaSec, PRTime& lastTime,
|
||||
nsString& aTimeStamp)
|
||||
{
|
||||
static const PRInt32 DATE_LEN = 19;
|
||||
PRTime deltaTime ;
|
||||
char dateStr[DATE_LEN+1];
|
||||
PRTime curTime, difTime;
|
||||
|
||||
curTime = PR_Now();
|
||||
LL_SUB(difTime, curTime, lastTime);
|
||||
|
||||
LL_I2L(deltaTime, deltaSec*1000000);
|
||||
if (LL_CMP(difTime, <, deltaTime)) {
|
||||
// Not enough time has elapsed for a new time stamp
|
||||
aTimeStamp = "";
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
lastTime = curTime;
|
||||
|
||||
// Current local time
|
||||
PRExplodedTime localTime;
|
||||
PR_ExplodeTime(curTime, PR_LocalTimeParameters, &localTime);
|
||||
|
||||
PRInt32 nWritten = PR_snprintf(dateStr, DATE_LEN+1,
|
||||
"%02d:%02d:%02d %02d/%02d/%04d",
|
||||
localTime.tm_hour, localTime.tm_min, localTime.tm_sec,
|
||||
localTime.tm_mday, localTime.tm_month+1, localTime.tm_year);
|
||||
|
||||
if (nWritten != DATE_LEN)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
XMLT_LOG(mozXMLTermUtils::LocalTime,99,("localTime=%s\n", dateStr));
|
||||
|
||||
aTimeStamp = dateStr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Returns a string containing a 11-digit random cookie based upon the
|
||||
* current local time and the elapsed execution of the program.
|
||||
* @param aCookie returned cookie string
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
NS_IMETHODIMP mozXMLTermUtils::RandomCookie(nsString& aCookie)
|
||||
{
|
||||
// Current local time
|
||||
PRExplodedTime localTime;
|
||||
PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &localTime);
|
||||
|
||||
PRInt32 randomNumberA = localTime.tm_sec*1000000+localTime.tm_usec;
|
||||
PRIntervalTime randomNumberB = PR_IntervalNow();
|
||||
|
||||
XMLT_LOG(mozXMLTermUtils::RandomCookie,30,("ranA=0x%x, ranB=0x%x\n",
|
||||
randomNumberA, randomNumberB));
|
||||
PR_ASSERT(randomNumberA >= 0);
|
||||
PR_ASSERT(randomNumberB >= 0);
|
||||
|
||||
static const char cookieDigits[17] = "0123456789abcdef";
|
||||
char cookie[12];
|
||||
int j;
|
||||
|
||||
for (j=0; j<6; j++) {
|
||||
cookie[j] = cookieDigits[randomNumberA%16];
|
||||
randomNumberA = randomNumberA/16;
|
||||
}
|
||||
for (j=6; j<11; j++) {
|
||||
cookie[j] = cookieDigits[randomNumberB%16];
|
||||
randomNumberB = randomNumberB/16;
|
||||
}
|
||||
cookie[11] = '\0';
|
||||
|
||||
aCookie = cookie;
|
||||
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozXMLTermUtils.h: XMLTerm utilities header
|
||||
|
||||
#ifndef _MOZXMLTERMUTILS_H
|
||||
|
||||
#define _MOZXMLTERMUTILS_H 1
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
|
||||
class mozXMLTermUtils
|
||||
{
|
||||
public:
|
||||
/** Gets presentation context for web shell
|
||||
* @param aWebShell web shell
|
||||
* @param aPresContext returned presentation context
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
static NS_EXPORT nsresult
|
||||
GetWebShellPresContext(nsIWebShell* aWebShell,
|
||||
nsIPresContext** aPresContext);
|
||||
|
||||
/** Gets DOM document for web shell
|
||||
* @param aWebShell web shell
|
||||
* @param aDOMDocument returned DOM document
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
static NS_EXPORT nsresult
|
||||
GetWebShellDOMDocument(nsIWebShell* aWebShell,
|
||||
nsIDOMDocument** aDOMDocument);
|
||||
|
||||
/** Gets DOM window for web shell
|
||||
* @param aWebShell web shell
|
||||
* @param aDOMWindow returned DOM window (frame)
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
static NS_EXPORT nsresult
|
||||
ConvertWebShellToDOMWindow(nsIWebShell* aWebShell,
|
||||
nsIDOMWindow** aDOMWindow);
|
||||
|
||||
/** Gets web shell for DOM window
|
||||
* @param aDOMWindow DOM window (frame)
|
||||
* @param aWebShell returned web shell
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
static NS_EXPORT nsresult
|
||||
ConvertDOMWindowToWebShell(nsIDOMWindow* aDOMWindow,
|
||||
nsIWebShell** aWebShell);
|
||||
|
||||
/** Locates named inner DOM window (frame) inside outer DOM window
|
||||
* @param outerDOMWindow outer DOM window (frame)
|
||||
* @param innerFrameName name of inner frame to be returned
|
||||
* @param innerDOMWindow returned inner DOM window (frame)
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
static NS_EXPORT nsresult
|
||||
GetInnerDOMWindow(nsIDOMWindow* outerDOMWindow,
|
||||
const nsString& innerFrameName,
|
||||
nsIDOMWindow** innerDOMWindow);
|
||||
|
||||
/** Gets the scrollable view for presentation context
|
||||
* @param aPresContext presentation context
|
||||
* @param aScrollableView returned scrollable view
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
static NS_EXPORT nsresult
|
||||
GetPresContextScrollableView(nsIPresContext* aPresContext,
|
||||
nsIScrollableView** aScrollableView);
|
||||
|
||||
/** Gets the device context for presentation context
|
||||
* @param aPresContext presentation context
|
||||
* @param aDeviceContext returned device context
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
static NS_EXPORT nsresult
|
||||
GetPresContextDeviceContext(nsIPresContext* aPresContext,
|
||||
nsIDeviceContext** aDeviceContext);
|
||||
|
||||
/** Gets the script context for document
|
||||
* @param aDOMDocument document providing context
|
||||
* @param aScriptContext returned script context
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
static NS_EXPORT nsresult
|
||||
GetScriptContext(nsIDOMDocument* aDOMDocument,
|
||||
nsIScriptContext** aScriptContext);
|
||||
|
||||
/** Executes script in specified document's context.
|
||||
* @param aDOMDocument document providing context for script execution
|
||||
* @param aScript string to be executed
|
||||
* @param aOutput output string produced by script execution
|
||||
* @return NS_OK if script was valid and got executed properly
|
||||
*/
|
||||
static NS_EXPORT nsresult
|
||||
ExecuteScript(nsIDOMDocument* aDOMDocument,
|
||||
const nsString& aScript,
|
||||
nsString& aOutput);
|
||||
|
||||
/** Returns a timestamp string containing the local time, if at least
|
||||
* deltaSec seconds have elapsed since the last timestamp. Otherwise,
|
||||
* a null string is returned.
|
||||
* @param deltaSec minimum elapsed seconds since last timestamp (>=0)
|
||||
* @param lastTime in/out parameter containing time of last timestamp
|
||||
* @param aTimeStamp returned timestamp string
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
static NS_EXPORT nsresult
|
||||
TimeStamp(PRInt32 deltaSec, PRTime& lastTime,
|
||||
nsString& aTimeStamp);
|
||||
|
||||
/** Returns a string containing a 11-digit random cookie based upon the
|
||||
* current local time and the elapsed execution of the program.
|
||||
* @param aCookie returned cookie string
|
||||
* @return NS_OK on success
|
||||
*/
|
||||
static NS_EXPORT nsresult
|
||||
RandomCookie(nsString& aCookie);
|
||||
|
||||
};
|
||||
|
||||
#endif /* _MOZXMLTERMUTILS_H */
|
|
@ -0,0 +1,770 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozXMLTerminal.cpp: implementation of mozIXMLTerminal interface
|
||||
// to manage all XMLTerm operations.
|
||||
// Creates a new mozXMLTermSession object to manage session input/output.
|
||||
// Creates a mozLineTermAux object to access LineTerm operations.
|
||||
// Creates key/text/mouse/drag listener objects to handle user events.
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nspr.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMHTMLDocument.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIDocumentLoaderObserver.h"
|
||||
#include "nsIObserver.h"
|
||||
|
||||
#include "nsIPresContext.h"
|
||||
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsIClipboard.h"
|
||||
#include "nsITransferable.h"
|
||||
|
||||
#include "mozXMLT.h"
|
||||
#include "mozXMLTermUtils.h"
|
||||
#include "mozXMLTerminal.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
static NS_DEFINE_IID(kIXMLTerminalIID, MOZIXMLTERMINAL_IID);
|
||||
static NS_DEFINE_IID(kXMLTerminalCID, MOZXMLTERMINAL_CID);
|
||||
|
||||
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
|
||||
static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// mozXMLTerminal factory
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewXMLTerminal(mozIXMLTerminal** aXMLTerminal)
|
||||
{
|
||||
NS_PRECONDITION(aXMLTerminal != nsnull, "null ptr");
|
||||
if (!aXMLTerminal)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aXMLTerminal = new mozXMLTerminal();
|
||||
if (! *aXMLTerminal)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aXMLTerminal);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// mozXMLTerminal implementation
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
mozXMLTerminal::mozXMLTerminal() :
|
||||
mInitialized(PR_FALSE),
|
||||
|
||||
mCookie(""),
|
||||
|
||||
mCommand(""),
|
||||
mPromptExpr(""),
|
||||
mFirstInput(""),
|
||||
|
||||
mXMLTermShell(nsnull),
|
||||
mWebShell(nsnull),
|
||||
mPresShell(nsnull),
|
||||
mDOMDocument(nsnull),
|
||||
|
||||
mXMLTermSession(nsnull),
|
||||
|
||||
mLineTermAux(nsnull),
|
||||
|
||||
mKeyListener(nsnull),
|
||||
mTextListener(nsnull),
|
||||
mMouseListener(nsnull),
|
||||
mDragListener(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
|
||||
mozXMLTerminal::~mozXMLTerminal()
|
||||
{
|
||||
if (mInitialized) {
|
||||
Finalize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Implement AddRef and Release
|
||||
NS_IMPL_ADDREF(mozXMLTerminal)
|
||||
NS_IMPL_RELEASE(mozXMLTerminal)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTerminal::QueryInterface(REFNSIID aIID,void** aInstancePtr)
|
||||
{
|
||||
if (aInstancePtr == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
if ( aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsISupports*,
|
||||
NS_STATIC_CAST(mozIXMLTerminal*,this));
|
||||
|
||||
} else if ( aIID.Equals(mozIXMLTerminal::GetIID()) ) {
|
||||
*aInstancePtr = NS_STATIC_CAST(mozIXMLTerminal*,this);
|
||||
|
||||
} else if (aIID.Equals(nsIDocumentLoaderObserver::GetIID())) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIDocumentLoaderObserver*,this);
|
||||
|
||||
} else if (aIID.Equals(nsIObserver::GetIID())) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIObserver*,this);
|
||||
|
||||
} else {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
XMLT_LOG(mozXMLTerminal::QueryInterface,20,("mRefCnt = %d\n", mRefCnt));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozXMLTerminal::GetCurrentEntryNumber(PRInt32 *aNumber)
|
||||
{
|
||||
if (mXMLTermSession) {
|
||||
return mXMLTermSession->GetCurrentEntryNumber(aNumber);
|
||||
} else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozXMLTerminal::GetHistory(PRInt32 *aHistory)
|
||||
{
|
||||
if (mXMLTermSession) {
|
||||
return mXMLTermSession->GetHistory(aHistory);
|
||||
} else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozXMLTerminal::SetHistory(PRInt32 aHistory)
|
||||
{
|
||||
if (mXMLTermSession) {
|
||||
return mXMLTermSession->SetHistory(aHistory);
|
||||
} else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozXMLTerminal::GetPrompt(PRUnichar **aPrompt)
|
||||
{
|
||||
if (mXMLTermSession) {
|
||||
return mXMLTermSession->GetPrompt(aPrompt);
|
||||
} else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozXMLTerminal::SetPrompt(const PRUnichar* aPrompt)
|
||||
{
|
||||
if (mXMLTermSession) {
|
||||
return mXMLTermSession->SetPrompt(aPrompt);
|
||||
} else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Initialize by starting load of Init page for XMLTerm
|
||||
NS_IMETHODIMP mozXMLTerminal::Init(nsIWebShell* aWebShell,
|
||||
mozIXMLTermShell* aXMLTermShell,
|
||||
const PRUnichar* aURL,
|
||||
const PRUnichar* args)
|
||||
{
|
||||
XMLT_LOG(mozXMLTerminal::Init,20,("\n"));
|
||||
|
||||
if (!aWebShell)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (mWebShell)
|
||||
return NS_ERROR_ALREADY_INITIALIZED;
|
||||
|
||||
mWebShell = aWebShell; // containing webshell; no addref
|
||||
|
||||
mXMLTermShell = aXMLTermShell; // containing xmlterm shell; no addref
|
||||
|
||||
nsresult result = NS_OK;
|
||||
|
||||
// NOTE: Need to parse args string!!!
|
||||
mCommand = "";
|
||||
mPromptExpr = "";
|
||||
mFirstInput = args;
|
||||
|
||||
// Initialization completed
|
||||
mInitialized = PR_TRUE;
|
||||
|
||||
if ((aURL != nsnull) && (*aURL != 0)) {
|
||||
// Load URL and activate XMLTerm after loading
|
||||
XMLT_LOG(mozXMLTerminal::Init,22,("setting DocLoaderObs\n"));
|
||||
|
||||
// About to create owning reference to this
|
||||
result = mWebShell->SetDocLoaderObserver((nsIDocumentLoaderObserver*)this);
|
||||
if (NS_FAILED(result))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
XMLT_LOG(mozXMLTerminal::Init,22,("done setting DocLoaderObs\n"));
|
||||
|
||||
// Load initial XMLterm background document
|
||||
nsAutoString urlString(aURL);
|
||||
|
||||
result = mWebShell->LoadURL(urlString.GetUnicode());
|
||||
if (NS_FAILED(result))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
} else {
|
||||
// Document already loaded; activate XMLTerm
|
||||
result = Activate();
|
||||
if (NS_FAILED(result))
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
XMLT_LOG(mozXMLTerminal::Init,21,("exiting\n"));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// De-initialize XMLTerminal
|
||||
NS_IMETHODIMP mozXMLTerminal::Finalize(void)
|
||||
{
|
||||
if (mXMLTermSession) {
|
||||
// Finalize XMLTermSession object and delete it (it is not ref. counted)
|
||||
mXMLTermSession->Finalize();
|
||||
delete mXMLTermSession;
|
||||
mXMLTermSession = nsnull;
|
||||
}
|
||||
|
||||
if (mDOMDocument) {
|
||||
// Release any event listeners for the document
|
||||
nsCOMPtr<nsIDOMEventReceiver> eventReceiver;
|
||||
nsresult result = mDOMDocument->QueryInterface(nsIDOMEventReceiver::GetIID(), getter_AddRefs(eventReceiver));
|
||||
|
||||
if (NS_SUCCEEDED(result) && eventReceiver) {
|
||||
if (mKeyListener) {
|
||||
eventReceiver->RemoveEventListenerByIID(mKeyListener,
|
||||
nsIDOMKeyListener::GetIID());
|
||||
mKeyListener = nsnull;
|
||||
}
|
||||
|
||||
if (mTextListener) {
|
||||
eventReceiver->RemoveEventListenerByIID(mTextListener,
|
||||
nsIDOMTextListener::GetIID());
|
||||
mTextListener = nsnull;
|
||||
}
|
||||
|
||||
if (mMouseListener) {
|
||||
eventReceiver->RemoveEventListenerByIID(mMouseListener,
|
||||
nsIDOMMouseListener::GetIID());
|
||||
mMouseListener = nsnull;
|
||||
}
|
||||
|
||||
if (mDragListener) {
|
||||
eventReceiver->RemoveEventListenerByIID(mDragListener,
|
||||
nsIDOMDragListener::GetIID());
|
||||
mDragListener = nsnull;
|
||||
}
|
||||
}
|
||||
mDOMDocument = nsnull;
|
||||
}
|
||||
|
||||
if (mLineTermAux) {
|
||||
// Finalize and release reference to LineTerm object owned by us
|
||||
mLineTermAux->CloseAux();
|
||||
mLineTermAux = nsnull;
|
||||
}
|
||||
|
||||
if (mWebShell) {
|
||||
// Stop observing document loading
|
||||
mWebShell->SetDocLoaderObserver((nsIDocumentLoaderObserver *)nsnull);
|
||||
mWebShell = nsnull;
|
||||
}
|
||||
|
||||
mPresShell = nsnull;
|
||||
mXMLTermShell = nsnull;
|
||||
|
||||
mInitialized = PR_FALSE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Activates XMLterm and instantiates LineTerm;
|
||||
* called at the the end of Init page loading.
|
||||
*/
|
||||
NS_IMETHODIMP mozXMLTerminal::Activate(void)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
|
||||
#if 0
|
||||
// TEMPORARY: Testing mozIXMLTermStream
|
||||
nsAutoString streamData = "<HTML><HEAD><TITLE>Stream Title</TITLE>"
|
||||
"<SCRIPT language='JavaScript'>"
|
||||
"function clik(){ dump('click\\n');return(false);}"
|
||||
"</SCRIPT></HEAD>"
|
||||
"<BODY><B>Stream Body "
|
||||
"<SPAN STYLE='color: blue' onClick='return clik();'>Clik</SPAN></B><BR>"
|
||||
"<TABLE WIDTH=720><TR><TD WIDTH=700 BGCOLOR=maroon> </TABLE>"
|
||||
"<BR>ABCD<BR>EFGH<BR>JKLM<BR>"
|
||||
"</BODY></HTML>";
|
||||
|
||||
nsCOMPtr<mozIXMLTermStream> stream;
|
||||
result = NS_NewXMLTermStream(getter_AddRefs(stream));
|
||||
if (NS_FAILED(result)) {
|
||||
fprintf(stderr, "mozXMLTerminal::Activate: Failed to create stream\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> outerDOMWindow;
|
||||
result = mozXMLTermUtils::ConvertWebShellToDOMWindow(mWebShell,
|
||||
getter_AddRefs(outerDOMWindow));
|
||||
|
||||
if (NS_FAILED(result) || !outerDOMWindow)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
result = stream->Open(outerDOMWindow, "iframe1", "chrome://dummy",
|
||||
"text/html", 800);
|
||||
if (NS_FAILED(result)) {
|
||||
fprintf(stderr, "mozXMLTerminal::Activate: Failed to open stream\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
result = stream->Write(streamData.GetUnicode());
|
||||
if (NS_FAILED(result)) {
|
||||
fprintf(stderr, "mozXMLTerminal::Activate: Failed to write to stream\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
result = stream->Close();
|
||||
if (NS_FAILED(result)) {
|
||||
fprintf(stderr, "mozXMLTerminal::Activate: Failed to close stream\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
XMLT_LOG(mozXMLTerminal::Activate,20,("\n"));
|
||||
|
||||
if (!mInitialized)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
PR_ASSERT(mWebShell != nsnull);
|
||||
|
||||
if ((mDOMDocument != nsnull) || (mPresShell != nsnull))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Get reference to DOMDocument
|
||||
nsCOMPtr<nsIDOMDocument> domDocument;
|
||||
result = mozXMLTermUtils::GetWebShellDOMDocument(mWebShell,
|
||||
getter_AddRefs(domDocument));
|
||||
|
||||
if (NS_FAILED(result) || !domDocument)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Get reference to presentation shell
|
||||
if (mPresShell != nsnull)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIPresContext> presContext;
|
||||
result = mozXMLTermUtils::GetWebShellPresContext(mWebShell,
|
||||
getter_AddRefs(presContext));
|
||||
if (NS_FAILED(result) || !presContext)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
result = presContext->GetShell(getter_AddRefs(presShell));
|
||||
|
||||
if (NS_FAILED(result) || !presShell)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Save references to DOMDocument and presentation shell
|
||||
// (SVN: Should these be addref'ed and released in the destructor?)
|
||||
mDOMDocument = domDocument; // no addref
|
||||
mPresShell = presShell; // no addref
|
||||
|
||||
// Instantiate and initialize XMLTermSession object
|
||||
mXMLTermSession = new mozXMLTermSession();
|
||||
|
||||
if (!mXMLTermSession) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
result = mXMLTermSession->Init(this, mPresShell, mDOMDocument);
|
||||
if (NS_FAILED(result)) {
|
||||
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to initialize XMLTermSession\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
// Instantiate LineTerm
|
||||
XMLT_LOG(mozXMLTerminal::Activate,22,("instantiating lineterm\n"));
|
||||
result = NS_NewLineTermAux(getter_AddRefs(mLineTermAux));
|
||||
if (NS_FAILED(result)) {
|
||||
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to instantiate LineTermAux\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
// Open LineTerm to execute command
|
||||
// Non-owning reference to this; delete LineTerm before deleting self
|
||||
PRInt32 options = LTERM_NOSTDERR_FLAG;
|
||||
|
||||
XMLT_LOG(mozXMLTerminal::Activate,22,("Opening LineTerm\n"));
|
||||
nsCOMPtr<nsIObserver> anObserver = this;
|
||||
#ifdef NO_CALLBACK
|
||||
anObserver = nsnull;
|
||||
#endif
|
||||
nsAutoString cookie;
|
||||
result = mLineTermAux->OpenAux(mCommand.GetUnicode(),
|
||||
mPromptExpr.GetUnicode(),
|
||||
options, LTERM_DETERMINE_PROCESS,
|
||||
mDOMDocument, anObserver, cookie);
|
||||
|
||||
if (NS_FAILED(result)) {
|
||||
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to open LineTermAux\n");
|
||||
return result;
|
||||
}
|
||||
XMLT_LOG(mozXMLTerminal::Activate,22,("Opened LineTerm\n"));
|
||||
|
||||
// Save cookie
|
||||
mCookie = cookie;
|
||||
|
||||
if (mFirstInput.Length() > 0) {
|
||||
// Send first input command line
|
||||
result = SendTextAux(mFirstInput);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
}
|
||||
|
||||
// Get the DOM event receiver for document
|
||||
nsCOMPtr<nsIDOMEventReceiver> eventReceiver;
|
||||
result = mDOMDocument->QueryInterface(nsIDOMEventReceiver::GetIID(),
|
||||
getter_AddRefs(eventReceiver));
|
||||
if (NS_FAILED(result)) {
|
||||
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to get DOM receiver\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
// Create a key listener
|
||||
result = NS_NewXMLTermKeyListener(getter_AddRefs(mKeyListener), this);
|
||||
if (NS_OK != result) {
|
||||
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to get key listener\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
// Register the key listener with the DOM event receiver
|
||||
result = eventReceiver->AddEventListenerByIID(mKeyListener,
|
||||
nsIDOMKeyListener::GetIID());
|
||||
|
||||
if (NS_FAILED(result)) {
|
||||
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to register key listener\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
// Create a text listener
|
||||
result = NS_NewXMLTermTextListener(getter_AddRefs(mTextListener), this);
|
||||
if (NS_OK != result) {
|
||||
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to get text listener\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
// Register the text listener with the DOM event receiver
|
||||
result = eventReceiver->AddEventListenerByIID(mTextListener,
|
||||
nsIDOMTextListener::GetIID());
|
||||
if (NS_FAILED(result)) {
|
||||
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to register text listener\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
// Create a mouse listener
|
||||
result = NS_NewXMLTermMouseListener(getter_AddRefs(mMouseListener), this);
|
||||
if (NS_OK != result) {
|
||||
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to get mouse listener\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
// Register the mouse listener with the DOM event receiver
|
||||
result = eventReceiver->AddEventListenerByIID(mMouseListener,
|
||||
nsIDOMMouseListener::GetIID());
|
||||
if (NS_FAILED(result)) {
|
||||
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to register mouse listener\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
// Create a drag listener
|
||||
result = NS_NewXMLTermDragListener(getter_AddRefs(mDragListener), this);
|
||||
if (NS_OK != result) {
|
||||
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to get drag listener\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
// Register the drag listener with the DOM event receiver
|
||||
result = eventReceiver->AddEventListenerByIID(mDragListener,
|
||||
nsIDOMDragListener::GetIID());
|
||||
if (NS_FAILED(result)) {
|
||||
XMLT_WARNING("mozXMLTerminal::Activate: Warning - Failed to register drag listener\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// Transmit string to LineTerm (use saved cookie)
|
||||
NS_IMETHODIMP mozXMLTerminal::SendTextAux(const nsString& aString)
|
||||
{
|
||||
return SendText(aString, mCookie.GetUnicode());
|
||||
}
|
||||
|
||||
|
||||
// Transmit string to LineTerm
|
||||
NS_IMETHODIMP mozXMLTerminal::SendText(const nsString& aString,
|
||||
const PRUnichar* aCookie)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
if (!mLineTermAux)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Preprocess string and check if it is to be consumed
|
||||
PRBool consumed = false;
|
||||
result = mXMLTermSession->Preprocess(aString, consumed);
|
||||
|
||||
if (!consumed) {
|
||||
result = mLineTermAux->Write(aString.GetUnicode(), aCookie);
|
||||
if (NS_FAILED(result)) {
|
||||
// Close LineTerm
|
||||
mLineTermAux->Close(aCookie);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// Paste data from clipboard to terminal
|
||||
NS_IMETHODIMP mozXMLTerminal::Paste()
|
||||
{
|
||||
nsresult result;
|
||||
nsAutoString pasteString;
|
||||
|
||||
XMLT_LOG(mozXMLTerminal::Paste,20,("\n"));
|
||||
|
||||
// Get Clipboard service
|
||||
NS_WITH_SERVICE (nsIClipboard, clipboard, kCClipboardCID, &result);
|
||||
if ( NS_FAILED(result) )
|
||||
return result;
|
||||
|
||||
// Generic transferable for getting clipboard data
|
||||
nsCOMPtr<nsITransferable> trans;
|
||||
result = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,
|
||||
nsITransferable::GetIID(),
|
||||
(void**) getter_AddRefs(trans));
|
||||
|
||||
if (NS_FAILED(result) || !trans)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// DataFlavors to get out of transferable
|
||||
trans->AddDataFlavor(kHTMLMime);
|
||||
trans->AddDataFlavor(kTextMime);
|
||||
|
||||
// Get data from clipboard
|
||||
result = clipboard->GetData(trans);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
char* bestFlavor = nsnull;
|
||||
nsCOMPtr<nsISupports> genericDataObj;
|
||||
PRUint32 objLen = 0;
|
||||
result = trans->GetAnyTransferData(&bestFlavor,
|
||||
getter_AddRefs(genericDataObj), &objLen);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
nsAutoString flavor ( bestFlavor );
|
||||
|
||||
char* temCStr = flavor.ToNewCString();
|
||||
XMLT_LOG(mozXMLTerminal::Paste,20,("flavour=%s\n", temCStr));
|
||||
nsAllocator::Free(temCStr);
|
||||
|
||||
if (flavor.Equals(kHTMLMime)) {
|
||||
nsCOMPtr<nsISupportsWString> textDataObj ( do_QueryInterface(genericDataObj) );
|
||||
if (textDataObj && objLen > 0) {
|
||||
PRUnichar* text = nsnull;
|
||||
textDataObj->ToString ( &text );
|
||||
pasteString.SetString ( text, objLen / 2 );
|
||||
result = SendTextAux(pasteString);
|
||||
}
|
||||
|
||||
} else if (flavor.Equals(kTextMime)) {
|
||||
nsCOMPtr<nsISupportsString> textDataObj ( do_QueryInterface(genericDataObj) );
|
||||
if (textDataObj && objLen > 0) {
|
||||
char* text = nsnull;
|
||||
textDataObj->ToString ( &text );
|
||||
pasteString.SetString ( text, objLen );
|
||||
result = SendTextAux(pasteString);
|
||||
}
|
||||
}
|
||||
|
||||
nsAllocator::Free(bestFlavor);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// Poll for readable data from LineTerm
|
||||
NS_IMETHODIMP mozXMLTerminal::Poll(void)
|
||||
{
|
||||
if (!mLineTermAux)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
XMLT_LOG(mozXMLTerminal::Poll,20,("\n"));
|
||||
|
||||
return mXMLTermSession->ReadAll(mLineTermAux);
|
||||
}
|
||||
|
||||
|
||||
// Handle callback from LineTerm when new input/output needs to be displayed
|
||||
NS_IMETHODIMP mozXMLTerminal::Observe(nsISupports *aSubject,
|
||||
const PRUnichar *aTopic,
|
||||
const PRUnichar *someData)
|
||||
{
|
||||
nsCOMPtr<mozILineTermAux> lineTermAux = do_QueryInterface(aSubject);
|
||||
PR_ASSERT(lineTermAux != nsnull);
|
||||
|
||||
return mXMLTermSession->ReadAll(lineTermAux);
|
||||
}
|
||||
|
||||
|
||||
// Returns document associated with XMLTerminal
|
||||
NS_IMETHODIMP mozXMLTerminal::GetDocument(nsIDOMDocument** aDoc)
|
||||
{
|
||||
if (!aDoc)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
*aDoc = nsnull;
|
||||
|
||||
NS_PRECONDITION(mDOMDocument, "bad state, null mDOMDocument");
|
||||
if (!mDOMDocument)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
return mDOMDocument->QueryInterface(nsIDOMDocument::GetIID(),
|
||||
(void **)aDoc);
|
||||
}
|
||||
|
||||
|
||||
// Returns presentation shell associated with XMLTerm
|
||||
NS_IMETHODIMP mozXMLTerminal::GetPresShell(nsIPresShell** aPresShell)
|
||||
{
|
||||
if (!aPresShell)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
*aPresShell = nsnull;
|
||||
|
||||
NS_PRECONDITION(mPresShell, "bad state, null mPresShell");
|
||||
if (!mPresShell)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
return mPresShell->QueryInterface(nsIPresShell::GetIID(),
|
||||
(void **)aPresShell);
|
||||
}
|
||||
|
||||
// nsIDocumentLoaderObserver methods
|
||||
NS_IMETHODIMP
|
||||
mozXMLTerminal::OnStartDocumentLoad(nsIDocumentLoader* loader, nsIURI* aURL,
|
||||
const char* aCommand)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTerminal::OnEndDocumentLoad(nsIDocumentLoader* loader, nsIChannel* channel,
|
||||
nsresult aStatus,
|
||||
nsIDocumentLoaderObserver * aObserver)
|
||||
{
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTerminal::OnStartURLLoad(nsIDocumentLoader* loader,
|
||||
nsIChannel* channel,
|
||||
nsIContentViewer* aViewer)
|
||||
{
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTerminal::OnProgressURLLoad(nsIDocumentLoader* loader,
|
||||
nsIChannel* channel, PRUint32 aProgress,
|
||||
PRUint32 aProgressMax)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTerminal::OnStatusURLLoad(nsIDocumentLoader* loader,
|
||||
nsIChannel* channel, nsString& aMsg)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTerminal::OnEndURLLoad(nsIDocumentLoader* loader,
|
||||
nsIChannel* channel, nsresult aStatus)
|
||||
{
|
||||
XMLT_LOG(mozXMLTerminal::OnEndURLLoad,20,("\n"));
|
||||
|
||||
// Activate XMLTerm
|
||||
Activate();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozXMLTerminal::HandleUnknownContentType(nsIDocumentLoader* loader,
|
||||
nsIChannel* channel,
|
||||
const char *aContentType,
|
||||
const char *aCommand )
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozXMLTerminal.h: declaration of mozXMLTerminal
|
||||
// which implements the mozIXMLTerminal interface
|
||||
// to manage all XMLterm operations.
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nspr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "mozXMLT.h"
|
||||
|
||||
#include "mozILineTermAux.h"
|
||||
#include "mozIXMLTerminal.h"
|
||||
#include "mozXMLTermSession.h"
|
||||
#include "mozXMLTermListeners.h"
|
||||
#include "mozIXMLTermStream.h"
|
||||
|
||||
|
||||
class mozXMLTerminal : public mozIXMLTerminal,
|
||||
public nsIDocumentLoaderObserver,
|
||||
public nsIObserver
|
||||
{
|
||||
public:
|
||||
|
||||
mozXMLTerminal();
|
||||
virtual ~mozXMLTerminal();
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// mozIXMLTerminal interface
|
||||
|
||||
NS_IMETHOD Init(nsIWebShell* aWebShell,
|
||||
mozIXMLTermShell* aXMLTermShell,
|
||||
const PRUnichar* aURL,
|
||||
const PRUnichar* args);
|
||||
|
||||
NS_IMETHOD Finalize(void);
|
||||
NS_IMETHOD Poll(void);
|
||||
|
||||
NS_IMETHOD GetCurrentEntryNumber(PRInt32 *aNumber);
|
||||
|
||||
NS_IMETHOD GetHistory(PRInt32 *aHistory);
|
||||
NS_IMETHOD SetHistory(PRInt32 aHistory);
|
||||
NS_IMETHOD GetPrompt(PRUnichar **aPrompt);
|
||||
NS_IMETHOD SetPrompt(const PRUnichar* aPrompt);
|
||||
|
||||
NS_IMETHOD SendTextAux(const nsString& aString);
|
||||
NS_IMETHOD SendText(const nsString& aString, const PRUnichar* aCookie);
|
||||
|
||||
NS_IMETHOD Paste();
|
||||
|
||||
NS_IMETHOD GetDocument(nsIDOMDocument** aDoc);
|
||||
|
||||
NS_IMETHOD GetPresShell(nsIPresShell** aPresShell);
|
||||
|
||||
// nsIDocumentLoaderObserver interface
|
||||
NS_IMETHOD OnStartDocumentLoad(nsIDocumentLoader* loader, nsIURI* aURL,
|
||||
const char* aCommand);
|
||||
|
||||
NS_IMETHOD OnEndDocumentLoad(nsIDocumentLoader* loader, nsIChannel* channel,
|
||||
nsresult aStatus,
|
||||
nsIDocumentLoaderObserver * aObserver);
|
||||
|
||||
NS_IMETHOD OnStartURLLoad(nsIDocumentLoader* loader, nsIChannel* channel,
|
||||
nsIContentViewer* aViewer);
|
||||
|
||||
NS_IMETHOD OnProgressURLLoad(nsIDocumentLoader* loader, nsIChannel* channel, PRUint32 aProgress,
|
||||
PRUint32 aProgressMax);
|
||||
|
||||
NS_IMETHOD OnStatusURLLoad(nsIDocumentLoader* loader, nsIChannel* channel,
|
||||
nsString& aMsg);
|
||||
|
||||
NS_IMETHOD OnEndURLLoad(nsIDocumentLoader* loader, nsIChannel* channel,
|
||||
nsresult aStatus);
|
||||
|
||||
NS_IMETHOD HandleUnknownContentType(nsIDocumentLoader* loader,
|
||||
nsIChannel* channel,
|
||||
const char *aContentType,
|
||||
const char *aCommand );
|
||||
|
||||
// nsIObserver interface
|
||||
NS_IMETHOD Observe(nsISupports *aSubject, const PRUnichar *aTopic,
|
||||
const PRUnichar *someData);
|
||||
|
||||
// Others
|
||||
NS_IMETHOD Activate(void);
|
||||
|
||||
protected:
|
||||
|
||||
/** object initialization flag */
|
||||
PRBool mInitialized;
|
||||
|
||||
/** cookie string used for authentication (stored in document.cookie) */
|
||||
nsString mCookie;
|
||||
|
||||
nsString mCommand;
|
||||
nsString mPromptExpr;
|
||||
|
||||
/** initial input string to be sent to LineTerm */
|
||||
nsString mFirstInput;
|
||||
|
||||
/** non-owning reference to containing XMLTermShell object */
|
||||
mozIXMLTermShell* mXMLTermShell;
|
||||
|
||||
/** non-owning reference to containing web shell */
|
||||
nsIWebShell* mWebShell;
|
||||
|
||||
/** non-owning (??) reference to presentation shell for XMLterm */
|
||||
nsIPresShell* mPresShell;
|
||||
|
||||
/** non-owning (??) reference to DOM document containing XMLterm */
|
||||
nsIDOMDocument* mDOMDocument;
|
||||
|
||||
/** XMLTermSession object created by us (not reference counted) */
|
||||
mozXMLTermSession* mXMLTermSession;
|
||||
|
||||
/** owning reference to LineTermAux object created by us */
|
||||
nsCOMPtr<mozILineTermAux> mLineTermAux;
|
||||
|
||||
/** owning referencing to key listener object created by us */
|
||||
nsCOMPtr<nsIDOMEventListener> mKeyListener;
|
||||
|
||||
/** owning referencing to text listener object created by us */
|
||||
nsCOMPtr<nsIDOMEventListener> mTextListener;
|
||||
|
||||
/** owning referencing to mouse listener object created by us */
|
||||
nsCOMPtr<nsIDOMEventListener> mMouseListener;
|
||||
|
||||
/** owning referencing to drag listener object created by us */
|
||||
nsCOMPtr<nsIDOMEventListener> mDragListener;
|
||||
|
||||
};
|
|
@ -0,0 +1,512 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* ptystream.c: pseudo-TTY stream implementation
|
||||
* CPP options:
|
||||
* LINUX: for Linux2.0/glibc
|
||||
* SOLARIS: for Solaris2.6
|
||||
* NOERRMSG: for suppressing all error messages
|
||||
* DEBUG: for printing some debugging output to STDERR
|
||||
*/
|
||||
|
||||
/* system header files */
|
||||
|
||||
|
||||
#include <termios.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/fcntl.h>
|
||||
|
||||
#ifdef LINUX
|
||||
#define __USE_BSD 1
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
/* public declarations */
|
||||
#include "ptystream.h"
|
||||
|
||||
/* private declarations */
|
||||
static int openPTY(struct ptys *ptyp, int noblock);
|
||||
static int attachToTTY(struct ptys *ptyp, int errfd, int noecho);
|
||||
static int setTTYAttr(int ttyFD, int noecho);
|
||||
static void pty_error(const char *errmsg, const char *errmsg2);
|
||||
|
||||
/* parameters */
|
||||
#define C_CTL_C '\003' /* ^C */
|
||||
#define C_CTL_D '\004' /* ^D */
|
||||
#define C_CTL_H '\010' /* ^H */
|
||||
#define C_CTL_O '\017' /* ^O */
|
||||
#define C_CTL_Q '\021' /* ^Q */
|
||||
#define C_CTL_R '\022' /* ^R */
|
||||
#define C_CTL_S '\023' /* ^S */
|
||||
#define C_CTL_U '\025' /* ^U */
|
||||
#define C_CTL_V '\026' /* ^V */
|
||||
#define C_CTL_W '\027' /* ^W */
|
||||
#define C_CTL_Y '\031' /* ^Y */
|
||||
#define C_CTL_Z '\032' /* ^Z */
|
||||
#define C_CTL_BSL '\034' /* ^\ */
|
||||
|
||||
/* Disable special character functions */
|
||||
#ifdef _POSIX_VDISABLE
|
||||
#define VDISABLE _POSIX_VDISABLE
|
||||
#else
|
||||
#define VDISABLE 255
|
||||
#endif
|
||||
|
||||
#define PTYCHAR1 "pqrstuvwxyzPQRSTUVWXYZ"
|
||||
#define PTYCHAR2 "0123456789abcdef"
|
||||
|
||||
|
||||
/* creates a new pseudo-TTY */
|
||||
int pty_create(struct ptys *ptyp, char *const argv[],
|
||||
int errfd, int noblock, int noecho, int noexport, int debug)
|
||||
{
|
||||
pid_t child_pid;
|
||||
int errfd2;
|
||||
|
||||
if (!ptyp) {
|
||||
pty_error("pty_create: NULL value for PTY structure", NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Set debug flag */
|
||||
ptyp->debug = debug;
|
||||
|
||||
#ifdef DEBUG
|
||||
if (ptyp->debug)
|
||||
fprintf(stderr, "00-pty_create: errfd=%d, noblock=%d, noecho=%d, noexport=%d\n",
|
||||
errfd, noblock, noecho, noexport);
|
||||
#endif
|
||||
|
||||
/* Open PTY */
|
||||
if (openPTY(ptyp, noblock) == -1) return -1;
|
||||
|
||||
/* Set default TTY size */
|
||||
if (pty_resize(ptyp, 24, 80, 0, 0) != 0)
|
||||
return -1;
|
||||
|
||||
if (errfd >= -1) {
|
||||
/* No STDERR pipe */
|
||||
ptyp->errpipeFD = -1;
|
||||
errfd2 = errfd;
|
||||
|
||||
} else {
|
||||
/* Create pipe to handle STDERR output */
|
||||
int pipeFD[2];
|
||||
|
||||
if (pipe(pipeFD) == -1) {
|
||||
pty_error("pty_create: STDERR pipe creation failed", NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Copy pipe file descriptors */
|
||||
ptyp->errpipeFD = pipeFD[0];
|
||||
errfd2 = pipeFD[1];
|
||||
}
|
||||
|
||||
/* Fork a child process (VFORK) */
|
||||
child_pid = vfork();
|
||||
if (child_pid < 0) {
|
||||
pty_error("pty_create: vfork failed", NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ptyp->pid = child_pid;
|
||||
|
||||
#ifdef DEBUG
|
||||
if (ptyp->debug)
|
||||
fprintf(stderr, "00-pty_create: Fork child pid = %d, initially attached to %s\n",
|
||||
child_pid, ttyname(0));
|
||||
#endif
|
||||
|
||||
if (child_pid == 0) {
|
||||
/* Child process */
|
||||
|
||||
/* Attach child to slave TTY */
|
||||
if (attachToTTY(ptyp, errfd2, noecho) == -1) return -1;
|
||||
|
||||
/* Set default signal handling */
|
||||
signal(SIGINT, SIG_DFL);
|
||||
signal(SIGQUIT, SIG_DFL);
|
||||
signal(SIGCHLD, SIG_DFL);
|
||||
|
||||
/* Set ignore signal handling */
|
||||
signal(SIGTSTP, SIG_IGN);
|
||||
signal(SIGTTIN, SIG_IGN);
|
||||
signal(SIGTTOU, SIG_IGN);
|
||||
|
||||
if (argv != NULL) {
|
||||
/* Execute specified command with arguments */
|
||||
if (noexport)
|
||||
execve(argv[0], argv, NULL);
|
||||
else
|
||||
execvp(argv[0], argv);
|
||||
|
||||
pty_error("Error in executing command ", argv[0]);
|
||||
return -1;
|
||||
|
||||
} else {
|
||||
/* Execute $SHELL or /bin/sh by default */
|
||||
char *shell = (char *) getenv("SHELL");
|
||||
|
||||
if ((shell == NULL) || (*shell == '\0'))
|
||||
shell = "/bin/sh";
|
||||
|
||||
if (noexport)
|
||||
execle(shell, shell, NULL, NULL);
|
||||
else
|
||||
execlp(shell, shell, NULL);
|
||||
|
||||
pty_error("pty_create: Error in executing command ", shell);
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (errfd < -1) {
|
||||
/* Close write end of STDERR pipe in parent process */
|
||||
close(errfd2);
|
||||
}
|
||||
|
||||
/* Return from parent */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* closes a pseudo-TTY */
|
||||
int pty_close(struct ptys *ptyp)
|
||||
{
|
||||
if (!ptyp) {
|
||||
pty_error("pty_close: NULL value for PTY structure", NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
kill(ptyp->pid, SIGKILL);
|
||||
ptyp->pid = 0;
|
||||
|
||||
close(ptyp->ptyFD);
|
||||
ptyp->ptyFD = -1;
|
||||
|
||||
if (ptyp->errpipeFD >= 0) {
|
||||
close(ptyp->errpipeFD);
|
||||
ptyp->errpipeFD = -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* resizes a pseudo-TTY */
|
||||
int pty_resize(struct ptys *ptyp, int rows, int cols,
|
||||
int xpix, int ypix)
|
||||
{
|
||||
struct winsize wsize;
|
||||
|
||||
if (!ptyp) {
|
||||
pty_error("pty_resize: NULL value for PTY structure", NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ioctl(ptyp->ptyFD, TIOCGWINSZ, &wsize ) == -1) {
|
||||
pty_error("pty_resize: Failed to get TTY window size", NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Set TTY window size */
|
||||
wsize.ws_row = (unsigned short) rows;
|
||||
wsize.ws_col = (unsigned short) cols;
|
||||
wsize.ws_xpixel = (unsigned short) xpix;
|
||||
wsize.ws_ypixel = (unsigned short) ypix;
|
||||
|
||||
if (ioctl(ptyp->ptyFD, TIOCSWINSZ, &wsize ) == -1) {
|
||||
pty_error("pty_resize: Failed to set TTY window size", NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int openPTY(struct ptys *ptyp, int noblock)
|
||||
{
|
||||
char ptyName[PTYNAMELEN+1], ttyName[PTYNAMELEN+1];
|
||||
|
||||
int plen, tlen, ptyFD, letIndex, devIndex;
|
||||
|
||||
(void) strncpy(ptyName, "/dev/pty??", PTYNAMELEN+1);
|
||||
(void) strncpy(ttyName, "/dev/tty??", PTYNAMELEN+1);
|
||||
|
||||
plen = strlen(ptyName);
|
||||
tlen = strlen(ttyName);
|
||||
|
||||
assert(ptyp != NULL);
|
||||
assert(plen <= PTYNAMELEN);
|
||||
assert(tlen <= PTYNAMELEN);
|
||||
|
||||
ptyFD = -1;
|
||||
letIndex = 0;
|
||||
while (PTYCHAR1[letIndex] && (ptyFD == -1)) {
|
||||
ttyName[tlen - 2] =
|
||||
ptyName[plen - 2] = PTYCHAR1 [letIndex];
|
||||
|
||||
devIndex = 0;
|
||||
while (PTYCHAR2[devIndex] && (ptyFD == -1)) {
|
||||
ttyName [tlen - 1] =
|
||||
ptyName [plen - 1] = PTYCHAR2 [devIndex];
|
||||
|
||||
if ((ptyFD = open(ptyName, O_RDWR)) >= 0) {
|
||||
if (access(ttyName, R_OK | W_OK) != 0) {
|
||||
close(ptyFD);
|
||||
ptyFD = -1;
|
||||
}
|
||||
}
|
||||
devIndex++;
|
||||
}
|
||||
|
||||
letIndex++;
|
||||
}
|
||||
|
||||
if (ptyFD == -1) {
|
||||
pty_error("openPTY: Unable to open pseudo-tty", NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (noblock) {
|
||||
/* Set non-blocking mode */
|
||||
fcntl(ptyFD, F_SETFL, O_NDELAY);
|
||||
}
|
||||
|
||||
strncpy(ptyp->ptydev, ptyName, PTYNAMELEN+1);
|
||||
strncpy(ptyp->ttydev, ttyName, PTYNAMELEN+1);
|
||||
|
||||
ptyp->ptyFD = ptyFD;
|
||||
|
||||
#ifdef DEBUG
|
||||
if (ptyp->debug)
|
||||
fprintf(stderr, "00-openPTY: Opened pty %s on fd %d\n", ptyName, ptyFD);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* attaches new process to slave TTY */
|
||||
static int attachToTTY(struct ptys *ptyp, int errfd, int noecho)
|
||||
{
|
||||
int ttyFD, fd, fdMax;
|
||||
pid_t sid;
|
||||
gid_t gid;
|
||||
unsigned int ttyMode = 0622;
|
||||
|
||||
assert(ptyp != NULL);
|
||||
|
||||
/* Create new session */
|
||||
sid = setsid();
|
||||
|
||||
#ifdef DEBUG
|
||||
if (ptyp->debug)
|
||||
fprintf(stderr, "00-attachToTTY: Returned %d from setsid\n", sid);
|
||||
#endif
|
||||
|
||||
if (sid < 0) {
|
||||
#ifndef NOERRMSG
|
||||
perror("attachToTTY");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((ttyFD = open(ptyp->ttydev, O_RDWR)) < 0) {
|
||||
pty_error("attachToTTY: Unable to open slave tty ", ptyp->ttydev );
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (ptyp->debug)
|
||||
fprintf(stderr,"00-attachToTTY: Attaching process %d to TTY %s on fd %d\n",
|
||||
getpid(), ptyp->ttydev, ttyFD);
|
||||
#endif
|
||||
|
||||
/* Change TTY ownership and permissions*/
|
||||
gid = getgid();
|
||||
|
||||
fchown(ttyFD, getuid(), gid);
|
||||
fchmod(ttyFD, ttyMode);
|
||||
|
||||
/* Set TTY attributes (this actually seems to be harmful; so commented out!)
|
||||
*/
|
||||
/* if (setTTYAttr(ttyFD, noecho) == -1) return -1; */
|
||||
|
||||
/* Redirect to specified descriptor or to PTY */
|
||||
if (errfd >= 0) {
|
||||
/* Redirect STDERR to specified file descriptor */
|
||||
if (dup2(errfd, 2) == -1) {
|
||||
pty_error("attachToTTY: Failed dup2 for specified stderr", NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
} else {
|
||||
/* Redirect STDERR to PTY */
|
||||
if (dup2(ttyFD, 2) == -1) {
|
||||
pty_error("attachToTTY: Failed dup2 for default stderr", NULL);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Redirect STDIN and STDOUT to PTY */
|
||||
if (dup2(ttyFD, 0) == -1) {
|
||||
pty_error("attachToTTY: Failed dup2 for stdin", NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dup2(ttyFD, 1) == -1) {
|
||||
pty_error("attachToTTY: Failed dup2 for stdout", NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Close all other file descriptors in child process */
|
||||
fdMax = sysconf(_SC_OPEN_MAX);
|
||||
for (fd = 3; fd < fdMax; fd++)
|
||||
close(fd);
|
||||
|
||||
/* Set process group */
|
||||
tcsetpgrp(0, sid);
|
||||
|
||||
/* close(open(ptyp->ttydev, O_RDWR, 0)); */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* sets slave TTY attributes (NOT USED) */
|
||||
static int setTTYAttr(int ttyFD, int noecho)
|
||||
{
|
||||
struct termios tios;
|
||||
|
||||
/* Get TTY attributes */
|
||||
if (tcgetattr(ttyFD, &tios ) == -1) {
|
||||
#ifndef NOERRMSG
|
||||
perror("setTTYAttr");
|
||||
#endif
|
||||
pty_error("setTTYattr: Failed to get TTY attributes", NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* TERMIOS settings for TTY */
|
||||
tios.c_cc[VINTR] = C_CTL_C;
|
||||
tios.c_cc[VQUIT] = C_CTL_BSL;
|
||||
tios.c_cc[VERASE] = C_CTL_H;
|
||||
tios.c_cc[VKILL] = C_CTL_U;
|
||||
tios.c_cc[VEOF] = C_CTL_D;
|
||||
tios.c_cc[VEOL] = VDISABLE;
|
||||
tios.c_cc[VEOL2] = VDISABLE;
|
||||
#ifdef SOLARIS
|
||||
tios.c_cc[VSWTCH] = VDISABLE;
|
||||
#endif
|
||||
tios.c_cc[VSTART] = C_CTL_Q;
|
||||
tios.c_cc[VSTOP] = C_CTL_S;
|
||||
tios.c_cc[VSUSP] = C_CTL_Z;
|
||||
tios.c_cc[VREPRINT] = C_CTL_R;
|
||||
tios.c_cc[VDISCARD] = C_CTL_O;
|
||||
tios.c_cc[VWERASE] = C_CTL_W;
|
||||
tios.c_cc[VLNEXT] = C_CTL_V;
|
||||
|
||||
tios.c_cc[VMIN] = 1; /* Wait for at least 1 char of input */
|
||||
tios.c_cc[VTIME] = 0; /* Wait indefinitely (block) */
|
||||
|
||||
/* Input modes */
|
||||
tios.c_iflag &= ~IUCLC; /* Disable map of upper case input to lower*/
|
||||
tios.c_iflag &= ~IGNBRK; /* Do not ignore break */
|
||||
tios.c_iflag &= ~BRKINT; /* Do not signal interrupt on break either */
|
||||
|
||||
/* Output modes */
|
||||
tios.c_oflag &= ~OPOST; /* Disable output postprocessing */
|
||||
tios.c_oflag &= ~ONLCR; /* Disable mapping of NL to CR-NL on output */
|
||||
tios.c_oflag &= ~OLCUC; /* Disable map of lower case output to upper */
|
||||
/* No output delays */
|
||||
tios.c_oflag &= ~(NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
|
||||
|
||||
/* control modes */
|
||||
tios.c_cflag |= (CS8 | CREAD);
|
||||
|
||||
/* line discipline modes */
|
||||
if (noecho)
|
||||
tios.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHOKE | ECHONL | ECHOPRT |
|
||||
ECHOCTL); /* Disable echo */
|
||||
else
|
||||
tios.c_lflag |= (ECHO | ECHOE | ECHOK | ECHOKE | ECHONL | ECHOPRT |
|
||||
ECHOCTL); /* Enable echo */
|
||||
|
||||
tios.c_lflag |= ISIG; /* Enable signals */
|
||||
tios.c_lflag |= ICANON; /* Enable erase/kill and eof processing */
|
||||
|
||||
/* NOTE: tcsh does not echo to be turned off if TERM=xterm;
|
||||
setting TERM=dumb allows echo to be turned off,
|
||||
but command completion is turned off as well */
|
||||
|
||||
/* Set TTY attributes */
|
||||
cfsetospeed (&tios, B38400);
|
||||
cfsetispeed (&tios, B38400);
|
||||
|
||||
if (tcsetattr(ttyFD, TCSADRAIN, &tios ) == -1) {
|
||||
#ifndef NOERRMSG
|
||||
perror("setTTYAttr");
|
||||
#endif
|
||||
pty_error("setTTYattr: Failed to set TTY attributes", NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* displays an error message, optionally concatenated with another */
|
||||
static void pty_error(const char *errmsg, const char *errmsg2) {
|
||||
|
||||
#ifndef NOERRMSG
|
||||
if (errmsg != NULL) {
|
||||
if (errmsg2 != NULL) {
|
||||
fprintf(stderr, "%s%s\n", errmsg, errmsg2);
|
||||
} else {
|
||||
fprintf(stderr, "%s\n", errmsg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* ptystream.h: pseudo-TTY stream header
|
||||
* (used by ltermPrivate.h)
|
||||
*/
|
||||
|
||||
#ifndef _PTYSTREAM_H
|
||||
|
||||
#define _PTYSTREAM_H 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PTYNAMELEN 10 /* Length of PTY/TTY device name: /dev/pty?? */
|
||||
|
||||
struct ptys { /* PTY structure */
|
||||
|
||||
int ptyFD; /* PTY file descriptor (bi-directional) */
|
||||
int errpipeFD; /* stderr pipe file descriptor (-1, if none) */
|
||||
|
||||
long pid; /* PTY child PID */
|
||||
|
||||
int debug; /* Debugging flag */
|
||||
|
||||
char ptydev[PTYNAMELEN+1]; /* PTY (master) name */
|
||||
char ttydev[PTYNAMELEN+1]; /* TTY (slave) name */
|
||||
};
|
||||
|
||||
/* creates a new pseudo-TTY (PTY) and also a new process attached to
|
||||
* it to execute the command line contained in array ARGV.
|
||||
* The PTY details are stored in the PTY structure PTYP.
|
||||
* ERRFD is the file descriptor to which the STDERR output of the
|
||||
* child process is directed.
|
||||
* If ERRFD == -1, then the STDERR output is redirected to STDOUT.
|
||||
* If ERRFD == -2, then a new pipe is created and STDERR is redirected
|
||||
* through it.
|
||||
* If NOBLOCK is true, enable non-blocking I/O on PTY.
|
||||
* If NOECHO is true, tty echoing is turned off.
|
||||
* If NOEXPORT is true, then the current environment is not exported
|
||||
* to the new process.
|
||||
* If DEBUG is true, debugging messages are printed to STDERR.
|
||||
* Returns 0 on success and -1 on error.
|
||||
*/
|
||||
int pty_create(struct ptys *ptyp, char *const argv[],
|
||||
int errfd, int noblock, int noecho, int noexport, int debug);
|
||||
|
||||
/* resizes the PTY, returning 0 on success and -1 on error */
|
||||
int pty_resize(struct ptys *ptyp, int rows, int cols,
|
||||
int xpix, int ypix);
|
||||
|
||||
/* closes the PTY and kills the associated child process, if still alive.
|
||||
* Also close STDERR pipe, if open.
|
||||
* Returns 0 on success and -1 on error.
|
||||
*/
|
||||
int pty_close(struct ptys *ptyp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _PTYSTREAM_H */
|
|
@ -0,0 +1,186 @@
|
|||
/*
|
||||
* 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 < U_SPACE) {
|
||||
/* ASCII control character */
|
||||
fprintf(stream, "^%c", (char) uch+U_ATSIGN);
|
||||
|
||||
} else if (uch == U_CARET) {
|
||||
/* Caret */
|
||||
fprintf(stream, "^^");
|
||||
|
||||
} else if (uch < 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,277 @@
|
|||
/*
|
||||
* 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.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
|
||||
*/
|
||||
|
||||
#ifndef _UNISTRING_H
|
||||
|
||||
#define _UNISTRING_H 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _WCHAR_H
|
||||
#include "wchar.h"
|
||||
#endif
|
||||
|
||||
#ifndef _STDIO_H
|
||||
#include "stdio.h"
|
||||
#endif
|
||||
|
||||
/* Unicode character type:
|
||||
* Uses the wchar_t implementation for moment.
|
||||
* Later we might implement a 16-bit UNICHAR type to save space
|
||||
*/
|
||||
|
||||
typedef wchar_t UNICHAR;
|
||||
|
||||
/* Unicode string functions:
|
||||
* use the wchar_t implementation for moment
|
||||
*/
|
||||
|
||||
/** 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);
|
||||
|
||||
/** 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);
|
||||
|
||||
/** 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);
|
||||
|
||||
#define ucscpy wcscpy
|
||||
#define ucsncpy wcsncpy
|
||||
|
||||
#define ucscat wcscat
|
||||
#define ucsncat wcsncat
|
||||
|
||||
#define ucscmp wcscmp
|
||||
#define ucsncmp wcsncmp
|
||||
|
||||
#define ucschr wcschr
|
||||
#define ucsrchr wcsrchr
|
||||
|
||||
#define ucsspn wcsspn
|
||||
#define ucscspn wcscspn
|
||||
|
||||
#define ucspbrk wcspbrk
|
||||
|
||||
#ifdef HAVE_WCSWCS
|
||||
#define ucsucs wcswcs
|
||||
#else
|
||||
#ifdef HAVE_WCSSTR
|
||||
#define ucsucs wcsstr
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define ucslen wcslen
|
||||
|
||||
#define ucstok wcstok
|
||||
|
||||
|
||||
/* unsigned short constants */
|
||||
|
||||
#define U_NUL 0x00U
|
||||
|
||||
#define U_CTL_A 0x01U
|
||||
#define U_CTL_B 0x02U
|
||||
#define U_CTL_C 0x03U
|
||||
#define U_CTL_D 0x04U
|
||||
#define U_CTL_E 0x05U
|
||||
#define U_CTL_F 0x06U
|
||||
|
||||
#define U_BEL 0x07U /* ^G */
|
||||
#define U_BACKSPACE 0x08U /* ^H */
|
||||
#define U_TAB 0x09U /* ^I */
|
||||
#define U_LINEFEED 0x0AU /* ^J */
|
||||
|
||||
#define U_CTL_K 0x0BU
|
||||
#define U_CTL_L 0x0CU
|
||||
|
||||
#define U_CRETURN 0x0DU /* ^M */
|
||||
|
||||
#define U_CTL_N 0x0EU
|
||||
#define U_CTL_O 0x0FU
|
||||
#define U_CTL_P 0x10U
|
||||
#define U_CTL_Q 0x11U
|
||||
#define U_CTL_R 0x12U
|
||||
#define U_CTL_S 0x13U
|
||||
#define U_CTL_T 0x14U
|
||||
#define U_CTL_U 0x15U
|
||||
#define U_CTL_V 0x16U
|
||||
#define U_CTL_W 0x17U
|
||||
#define U_CTL_X 0x18U
|
||||
#define U_CTL_Y 0x19U
|
||||
#define U_CTL_Z 0x1AU
|
||||
|
||||
#define U_ESCAPE 0x1BU /* escape */
|
||||
|
||||
#define U_SPACE 0x20U /* space */
|
||||
#define U_EXCLAMATION 0x21U /* ! */
|
||||
#define U_DBLQUOTE 0x22U /* " */
|
||||
#define U_NUMBER 0x23U /* # */
|
||||
#define U_DOLLAR 0x24U /* $ */
|
||||
#define U_PERCENT 0x25U /* % */
|
||||
#define U_AMPERSAND 0x26U /* & */
|
||||
#define U_SNGLQUOTE 0x27U /* ' */
|
||||
#define U_LPAREN 0x28U /* ( */
|
||||
#define U_RPAREN 0x29U /* ) */
|
||||
|
||||
#define U_STAR 0x2AU /* * */
|
||||
#define U_PLUS 0x2BU /* + */
|
||||
#define U_COMMA 0x2CU /* , */
|
||||
#define U_DASH 0x2DU /* - */
|
||||
#define U_PERIOD 0x2EU /* . */
|
||||
#define U_SLASH 0x2FU /* / */
|
||||
|
||||
#define U_ZERO 0x30U /* 0 */
|
||||
#define U_ONE 0x31U /* 1 */
|
||||
#define U_TWO 0x32U /* 2 */
|
||||
#define U_THREE 0x33U /* 3 */
|
||||
#define U_FOUR 0x34U /* 4 */
|
||||
#define U_FIVE 0x35U /* 5 */
|
||||
#define U_SIX 0x36U /* 6 */
|
||||
#define U_SEVEN 0x37U /* 7 */
|
||||
#define U_EIGHT 0x38U /* 8 */
|
||||
#define U_NINE 0x39U /* 9 */
|
||||
|
||||
#define U_COLON 0x3AU /* : */
|
||||
#define U_SEMICOLON 0x3BU /* ; */
|
||||
#define U_LESSTHAN 0x3CU /* < */
|
||||
#define U_EQUALS 0x3DU /* = */
|
||||
#define U_GREATERTHAN 0x3EU /* > */
|
||||
#define U_QUERYMARK 0x3FU /* ? */
|
||||
|
||||
#define U_ATSIGN 0x40U /* @ */
|
||||
|
||||
#define U_A_CHAR 0x41U /* A */
|
||||
#define U_B_CHAR 0x42U /* B */
|
||||
#define U_C_CHAR 0x43U /* C */
|
||||
#define U_D_CHAR 0x44U /* D */
|
||||
#define U_E_CHAR 0x45U /* E */
|
||||
#define U_F_CHAR 0x46U /* F */
|
||||
#define U_G_CHAR 0x47U /* G */
|
||||
#define U_H_CHAR 0x48U /* H */
|
||||
#define U_I_CHAR 0x49U /* I */
|
||||
#define U_J_CHAR 0x4AU /* J */
|
||||
#define U_K_CHAR 0x4BU /* K */
|
||||
#define U_L_CHAR 0x4CU /* L */
|
||||
#define U_M_CHAR 0x4DU /* M */
|
||||
#define U_N_CHAR 0x4EU /* N */
|
||||
#define U_O_CHAR 0x4FU /* O */
|
||||
#define U_P_CHAR 0x50U /* P */
|
||||
#define U_Q_CHAR 0x51U /* Q */
|
||||
#define U_R_CHAR 0x52U /* R */
|
||||
#define U_S_CHAR 0x53U /* S */
|
||||
#define U_T_CHAR 0x54U /* T */
|
||||
#define U_U_CHAR 0x55U /* U */
|
||||
#define U_V_CHAR 0x56U /* V */
|
||||
#define U_W_CHAR 0x57U /* W */
|
||||
#define U_X_CHAR 0x58U /* X */
|
||||
#define U_Y_CHAR 0x59U /* Y */
|
||||
#define U_Z_CHAR 0x5AU /* Z */
|
||||
|
||||
#define U_LBRACKET 0x5BU /* [ */
|
||||
#define U_BACKSLASH 0x5CU /* \ */
|
||||
#define U_RBRACKET 0x5DU /* ] */
|
||||
|
||||
#define U_CARET 0x5EU /* ^ */
|
||||
#define U_UNDERSCORE 0x5FU /* _ */
|
||||
#define U_BACKQUOTE 0x60U /* ` */
|
||||
|
||||
#define U_a_CHAR 0x61U /* a */
|
||||
#define U_b_CHAR 0x62U /* b */
|
||||
#define U_c_CHAR 0x63U /* c */
|
||||
#define U_d_CHAR 0x64U /* d */
|
||||
#define U_e_CHAR 0x65U /* e */
|
||||
#define U_f_CHAR 0x66U /* f */
|
||||
#define U_g_CHAR 0x67U /* g */
|
||||
#define U_h_CHAR 0x68U /* h */
|
||||
#define U_i_CHAR 0x69U /* i */
|
||||
#define U_j_CHAR 0x6AU /* j */
|
||||
#define U_k_CHAR 0x6BU /* k */
|
||||
#define U_l_CHAR 0x6CU /* l */
|
||||
#define U_m_CHAR 0x6DU /* m */
|
||||
#define U_n_CHAR 0x6EU /* n */
|
||||
#define U_o_CHAR 0x6FU /* o */
|
||||
#define U_p_CHAR 0x70U /* p */
|
||||
#define U_q_CHAR 0x71U /* q */
|
||||
#define U_r_CHAR 0x72U /* r */
|
||||
#define U_s_CHAR 0x73U /* s */
|
||||
#define U_t_CHAR 0x74U /* t */
|
||||
#define U_u_CHAR 0x75U /* u */
|
||||
#define U_v_CHAR 0x76U /* v */
|
||||
#define U_w_CHAR 0x77U /* w */
|
||||
#define U_x_CHAR 0x78U /* x */
|
||||
#define U_y_CHAR 0x79U /* y */
|
||||
#define U_z_CHAR 0x7AU /* z */
|
||||
|
||||
#define U_LCURLY 0x7BU /* { */
|
||||
#define U_VERTBAR 0x7CU /* | */
|
||||
#define U_RCURLY 0x7DU /* } */
|
||||
|
||||
#define U_TILDE 0x7EU /* ~ */
|
||||
#define U_DEL 0x7FU /* delete */
|
||||
|
||||
#define U_LATIN1LO 0xA0U /* lowest Latin1 extension character */
|
||||
#define U_NOBRKSPACE 0xA0U /* no-break space */
|
||||
#define U_LATIN1HI 0xFFU /* highest Latin1 extension character */
|
||||
|
||||
#define IS_ASCII_LETTER(x) ( (((x) >= U_A_CHAR) && ((x) <= U_Z_CHAR)) || \
|
||||
(((x) >= U_a_CHAR) && ((x) <= U_z_CHAR)) )
|
||||
|
||||
#define IS_ASCII_DIGIT(x) ( ((x) >= U_ZERO) && ((x) <= U_NINE) )
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _UNISTRING_H */
|
|
@ -0,0 +1,47 @@
|
|||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# autoconf.mk: autoconf info for stand-alone LineTerm only
|
||||
|
||||
# C compiler
|
||||
CC = gcc
|
||||
|
||||
# C++ compiler
|
||||
CXX = c++
|
||||
|
||||
# Library archive creation command
|
||||
AR = ar cr $@
|
||||
|
||||
OS_INCLUDES =
|
||||
OS_CFLAGS =
|
||||
OS_CXXFLAGS =
|
||||
OS_LDFLAGS =
|
|
@ -0,0 +1,93 @@
|
|||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# config.mk: config info for stand-alone LineTerm only
|
||||
|
||||
# Options
|
||||
# DEBUG: debug option
|
||||
|
||||
# OS details
|
||||
OS_ARCH := $(subst /,_,$(shell uname -s))
|
||||
OS_RELEASE := $(shell uname -r)
|
||||
|
||||
ifneq (,$(filter Linux SunOS,$(OS_ARCH)))
|
||||
OS_VERS := $(suffix $(OS_RELEASE))
|
||||
OS_RELEASE := $(basename $(OS_RELEASE))
|
||||
endif
|
||||
|
||||
OS_CONFIG := $(OS_ARCH)$(OS_RELEASE)
|
||||
|
||||
ifeq ($(OS_ARCH),Linux)
|
||||
LIB_SUFFIX = a
|
||||
RANLIB = /usr/bin/ranlib
|
||||
endif
|
||||
|
||||
ifeq ($(OS_CONFIG),SunOS5)
|
||||
LIB_SUFFIX = a
|
||||
RANLIB = /bin/true
|
||||
endif
|
||||
|
||||
# C++ compiler
|
||||
CCC = $(CXX)
|
||||
|
||||
# OS flags
|
||||
OS_CFLAGS += $(PLATFORM_FLAGS)
|
||||
OS_CXXFLAGS += $(PLATFORM_FLAGS)
|
||||
OS_LDFLAGS +=
|
||||
|
||||
# Object directory
|
||||
OBJDIR = lib
|
||||
|
||||
# Library directory
|
||||
LIBS_DIR = -L$(topsrcdir)/dist/$(OBJDIR)
|
||||
|
||||
# Distribution includes
|
||||
LOCAL_INCLUDES += -I$(topsrcdir)/dist/include
|
||||
|
||||
# NSPR libraries
|
||||
NSPR_LIBS = -lnspr3
|
||||
|
||||
#
|
||||
# Debug option
|
||||
#
|
||||
ifdef DEBUG
|
||||
OPTIMIZER = -g
|
||||
DEFINES += -DDEBUG
|
||||
else
|
||||
OPTIMIZER =
|
||||
endif
|
||||
|
||||
INCLUDES = $(LOCAL_INCLUDES) $(OS_INCLUDES)
|
||||
|
||||
CFLAGS = $(OPTIMIZER) $(OS_CFLAGS) $(DEFINES) $(INCLUDES)
|
||||
CXXFLAGS = $(OPTIMIZER) $(OS_CXXFLAGS) $(DEFINES) $(INCLUDES)
|
||||
LDFLAGS = $(OS_LDFLAGS)
|
|
@ -0,0 +1,157 @@
|
|||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# rules.mk: Make rules for stand-alone LineTerm only
|
||||
|
||||
# CAUTION: Dependency checking is very limited.
|
||||
# For compilation, the only dependencies are on *.h files in the current
|
||||
# directory and in the distribution include directory.
|
||||
# When creating executables, there is additional dependency on
|
||||
# all *.a files in the distribution object directory.
|
||||
|
||||
ifndef LIBRARY
|
||||
ifdef LIBRARY_NAME
|
||||
LIBRARY := lib$(LIBRARY_NAME).$(LIB_SUFFIX)
|
||||
endif # LIBRARY_NAME
|
||||
endif # LIBRARY
|
||||
|
||||
ifdef PROGRAM
|
||||
PROGRAM := $(addprefix $(OBJDIR)/, $(PROGRAM))
|
||||
endif
|
||||
|
||||
ifdef SIMPLE_PROGRAMS
|
||||
SIMPLE_PROGRAMS := $(addprefix $(OBJDIR)/, $(SIMPLE_PROGRAMS))
|
||||
endif
|
||||
|
||||
ifdef LIBRARY
|
||||
LIBRARY := $(addprefix $(OBJDIR)/, $(LIBRARY))
|
||||
endif
|
||||
|
||||
ifndef OBJS
|
||||
OBJS = $(CSRCS:.c=.o) $(CPPSRCS:.cpp=.o)
|
||||
endif
|
||||
|
||||
OBJS := $(addprefix $(OBJDIR)/, $(OBJS))
|
||||
|
||||
ifdef DIRS
|
||||
LOOP_OVER_DIRS = \
|
||||
@for d in $(DIRS); do \
|
||||
if test -f $$d/Makefile; then \
|
||||
set -e; \
|
||||
echo "cd $$d; $(MAKE) $@"; \
|
||||
oldDir=`pwd`; \
|
||||
cd $$d; $(MAKE) $@; cd $$oldDir; \
|
||||
set +e; \
|
||||
else \
|
||||
echo "Skipping non-directory $$d..."; \
|
||||
fi; \
|
||||
done
|
||||
endif
|
||||
|
||||
ifndef PROGOBJS
|
||||
PROGOBJS = $(OBJS)
|
||||
endif
|
||||
|
||||
# Targets
|
||||
all: export libs progs
|
||||
|
||||
export: $(EXPORTS)
|
||||
ifneq (,$(EXPORTS))
|
||||
+for x in $^; do \
|
||||
rm $(topsrcdir)/dist/include/$$x; \
|
||||
echo ln -s `pwd`/$$x $(topsrcdir)/dist/include/$$x; \
|
||||
ln -s `pwd`/$$x $(topsrcdir)/dist/include/$$x; \
|
||||
done
|
||||
endif
|
||||
+$(LOOP_OVER_DIRS)
|
||||
|
||||
libs: $(LIBRARY)
|
||||
+$(LOOP_OVER_DIRS)
|
||||
|
||||
progs: $(SIMPLE_PROGRAMS)
|
||||
+$(LOOP_OVER_DIRS)
|
||||
|
||||
clean:
|
||||
-rm $(OBJDIR)/*
|
||||
+$(LOOP_OVER_DIRS)
|
||||
|
||||
#
|
||||
# Turn on C++ linking if we have any .cpp files
|
||||
#
|
||||
ifdef CPPSRCS
|
||||
CPP_PROG_LINK = 1
|
||||
endif
|
||||
|
||||
# Create single executable program (with limited dependency checking)
|
||||
$(PROGRAM): $(PROGOBJS) $(wildcard $(topsrcdir)/dist/$(OBJDIR)/*.a)
|
||||
ifeq ($(CPP_PROG_LINK),1)
|
||||
$(CCC) -o $@ $(PROGOBJS) $(LDFLAGS) $(LIBS_DIR) $(LIBS))
|
||||
else
|
||||
$(CC) -o $@ $(PROGOBJS) $(LDFLAGS) $(LIBS_DIR) $(LIBS)
|
||||
endif
|
||||
|
||||
# Create multiple simple executable programs (with limited dependency checking)
|
||||
$(SIMPLE_PROGRAMS): $(OBJDIR)/%: $(OBJDIR)/%.o \
|
||||
$(wildcard $(topsrcdir)/dist/$(OBJDIR)/*.a)
|
||||
ifeq ($(CPP_PROG_LINK),1)
|
||||
$(CCC) -o $@ $< $(LDFLAGS) $(LIBS_DIR) $(LIBS))
|
||||
else
|
||||
$(CC) -o $@ $< $(LDFLAGS) $(LIBS_DIR) $(LIBS)
|
||||
endif
|
||||
|
||||
# Create library and export it
|
||||
$(LIBRARY): $(OBJS)
|
||||
$(AR) $(OBJS)
|
||||
$(RANLIB) $@
|
||||
-rm $(topsrcdir)/dist/$@
|
||||
ln -s `pwd`/$@ $(topsrcdir)/dist/$@
|
||||
|
||||
|
||||
# Compilation rules (with limited dependency checking)
|
||||
$(OBJDIR)/%.o: %.c $(wildcard *.h) $(wildcard $(topsrcdir)/dist/include/*.h)
|
||||
$(CC) -o $@ -c $(CFLAGS) $<
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp $(wildcard *.h) $(wildcard $(topsrcdir)/dist/include/*.h)
|
||||
$(CCC) -o $@ -c $(CXXFLAGS) $<
|
||||
|
||||
|
||||
# Recognized suffixes
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .a .o .c .cpp .h .pl .class .java .html .mk .in
|
||||
|
||||
# Always recognized targets
|
||||
.PHONY: all clean clobber clobber_all export install libs
|
||||
|
||||
# OS configuration
|
||||
os_config:
|
||||
@echo "OS_ARCH = $(OS_ARCH), OS_CONFIG=$(OS_CONFIG)"
|
||||
@echo "OS_RELEASE=$(OS_RELEASE), OS_VERS=$(OS_VERS)"
|
|
@ -0,0 +1,102 @@
|
|||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# xmlterm_config.mk: XMLTERM-specific configuration options
|
||||
|
||||
# Options
|
||||
# STAND_ALONE: compile outside Mozilla/NSPR environment
|
||||
# DEBUG: debug option
|
||||
# NO_WORKAROUND: disables workarounds to expose bugs
|
||||
# USE_GTK_WIDGETS use GTK widget library
|
||||
# USE_NSPR_BASE: use basic NSPR API (excluding I/O and process creation)
|
||||
# USE_NSPR_IO: use NSPR I/O and process API instead of Unix API
|
||||
# NO_PTY: force use of pipes rather than PTY for process communication
|
||||
# NO_CALLBACK: do not use GTK callbacks to handle LineTerm output
|
||||
# (use polling instead)
|
||||
|
||||
ifdef NO_WORKAROUND
|
||||
DEFINES += -DNO_WORKAROUND
|
||||
endif
|
||||
|
||||
#
|
||||
# OS dependent options
|
||||
#
|
||||
ifneq (,$(filter-out Linux2.0 Linux2.2 SunOS5,$(OS_CONFIG)))
|
||||
# Unsupported platform for PTY; use pipes for process communication
|
||||
NO_PTY = 1
|
||||
endif
|
||||
|
||||
ifeq ($(OS_ARCH),Linux)
|
||||
DEFINES += -DLINUX -DHAVE_WCSSTR
|
||||
endif
|
||||
|
||||
ifeq ($(OS_CONFIG),SunOS5)
|
||||
DEFINES += -DSOLARIS -DHAVE_WCSWCS
|
||||
endif
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),gtk)
|
||||
USE_GTK_WIDGETS = 1
|
||||
endif
|
||||
|
||||
#
|
||||
# Netscape Portable Runtime options
|
||||
#
|
||||
ifndef STAND_ALONE
|
||||
# Use NSPR base
|
||||
USE_NSPR_BASE = 1
|
||||
endif
|
||||
|
||||
ifdef USE_GTK_WIDGETS
|
||||
DEFINES += -DUSE_GTK_WIDGETS
|
||||
else
|
||||
# No callback
|
||||
NO_CALLBACK = 1
|
||||
endif
|
||||
|
||||
ifdef USE_NSPR_IO
|
||||
DEFINES += -DUSE_NSPR_IO
|
||||
USE_NSPR_BASE = 1
|
||||
NO_CALLBACK = 1
|
||||
endif
|
||||
|
||||
ifdef USE_NSPR_BASE
|
||||
DEFINES += -DUSE_NSPR_BASE
|
||||
LIBS += $(NSPR_LIBS)
|
||||
endif
|
||||
|
||||
ifdef NO_PTY
|
||||
DEFINES += -DNO_PTY
|
||||
endif
|
||||
|
||||
ifdef NO_CALLBACK
|
||||
DEFINES += -DNO_CALLBACK
|
||||
endif
|
|
@ -0,0 +1,9 @@
|
|||
Known bugs
|
||||
----------
|
||||
|
||||
10 Nov 1999
|
||||
|
||||
|
||||
1. Command line completion output duplicates command line
|
||||
|
||||
2. Early use of "xls -i" does not scroll properly
|
|
@ -0,0 +1,60 @@
|
|||
XMLterm installation instructions for Linux binaries
|
||||
----------------------------------------------------
|
||||
|
||||
*NOTE* This work in progress. User beware!
|
||||
|
||||
*NOTE* Check the XMLterm web site <http://xmlterm.org> for updates.
|
||||
|
||||
19 Nov 1999
|
||||
|
||||
1. First obtain the Mozilla Linux binary tar file
|
||||
ftp://ftp.mozilla.org/pub/mozilla/releases/m11/mozilla-i686-pc-linux-gnu-M11.tar.gz"
|
||||
and untar it in any convenient location. This will create a
|
||||
directory named "package" containing the binaries.
|
||||
|
||||
2. Untar the XMLterm binary tar file "xmlterm-i686-pc-linux-gnu-M11.tar.gz"
|
||||
in the "package" directory created above.
|
||||
|
||||
3. Type the following command in the "package" directory:
|
||||
|
||||
./mozilla chrome://xmlterm/content/xmlterm.html
|
||||
|
||||
This should create an XMLTerm in the browser window. Then click on
|
||||
that window with the mouse to shift focus and start typing UNIX
|
||||
commands.
|
||||
|
||||
**NOTE**
|
||||
The command prompt is assumed to be terminated by one of the characters
|
||||
"#$%>?", followed by a space. If this is not the case, many features will
|
||||
not work. This restriction will be relaxed in the future.
|
||||
|
||||
4. To use the stand-alone XMLterm executable called "xmlterm",
|
||||
type the following command in the "package" directory:
|
||||
|
||||
./run-mozilla.sh xmlterm
|
||||
|
||||
(The Mozilla component registry may need to be updated by running the
|
||||
full browser using step 3 at least once before running "xmlterm".)
|
||||
|
||||
5. The command line can be edited using EMACS-style key bindings.
|
||||
Command completion should also work with TCSH and BASH, as should history
|
||||
recall.
|
||||
|
||||
6. By default, blue coloring is used to indicate clickable display elements.
|
||||
Note that the prompt and the input command line are clickable.
|
||||
(Of course, the appearance of XMLterm is completely configurable
|
||||
using the CSS stylesheet chrome://xmlterm/skin/default/xmlterm.css)
|
||||
|
||||
After typing one or two commands, click on the prompt string of any previous
|
||||
command to see what happens! Then click again on the same prompt string.
|
||||
Also click on "Hide all output" button at the top of the document.
|
||||
|
||||
Clicking on a previous command line (to the right of the prompt) re-executes
|
||||
the command.
|
||||
|
||||
7. The sample Perl script "xls", the iconic/hypertext version of the Unix
|
||||
"ls" command, is also installed in the "package" directory. Adding
|
||||
the "package" directory to your path should enable you to use the "xls"
|
||||
command.
|
||||
|
||||
--
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
|
@ -0,0 +1,109 @@
|
|||
#!gmake
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# makefile for xmlterm/geckoterm directory (stand alone XMLterm)
|
||||
|
||||
ifdef STAND_ALONE
|
||||
DEPTH = ..
|
||||
topsrcdir = ..
|
||||
srcdir = .
|
||||
include $(topsrcdir)/config/autoconf.mk
|
||||
else
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
endif
|
||||
|
||||
|
||||
# Debug option
|
||||
DEBUG = 1
|
||||
|
||||
# Program
|
||||
PROGRAM = xmlterm
|
||||
|
||||
# Exported header files
|
||||
EXPORTS = mozISimpleContainer.h
|
||||
|
||||
# Defines
|
||||
DEFINES = $(TK_CFLAGS)
|
||||
|
||||
# C++ source files
|
||||
CPPSRCS = nsSetupRegistry.cpp \
|
||||
mozSimpleContainer.cpp \
|
||||
mozGeckoTerm.cpp \
|
||||
nsTimer.cpp \
|
||||
$(NULL)
|
||||
|
||||
# Libraries to be linked
|
||||
GTK_GLUE = -lgtksuperwin
|
||||
|
||||
XP_DIST_LIBS = \
|
||||
-lraptorgfx \
|
||||
-lmozjs \
|
||||
-lxpcom \
|
||||
$(JSJ_LIB) \
|
||||
$(NULL)
|
||||
|
||||
XP_NS_UNDERBAR_CRAP = \
|
||||
$(MOZ_NECKO_UTIL_LIBS) \
|
||||
$(MOZ_TIMER_LIBS) \
|
||||
$(MOZ_WIDGET_SUPPORT_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
XP_LIBS = \
|
||||
$(XP_NS_UNDERBAR_CRAP) \
|
||||
$(XP_DIST_LIBS) \
|
||||
$(NSPR_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
ifdef DYNAMIC_LINK
|
||||
# NOTE: a soft link needs to be created for libxmlterm.so in dist/bin
|
||||
XMLTERM_LIBS = -lxmlterm
|
||||
else
|
||||
# Statically link the entire XMLTERM library
|
||||
XMLTERM_LIBS = ../base/libxmlterm.a
|
||||
endif
|
||||
|
||||
LIBS = \
|
||||
$(GTK_GLUE) \
|
||||
$(XP_LIBS) \
|
||||
$(TK_LIBS) \
|
||||
$(XMLTERM_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include ../config/xmlterm_config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,337 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozGeckoTerm.cpp: Stand-alone implementation of XMLterm using GTK
|
||||
// and the Mozilla Layout engine
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#if 0 // USE_SUPERWIN
|
||||
#include "gtkmozarea.h"
|
||||
#include "gdksuperwin.h"
|
||||
#endif // USE_SUPERWIN
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsRepository.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsIPref.h"
|
||||
|
||||
#include "mozXMLTermUtils.h"
|
||||
#include "mozISimpleContainer.h"
|
||||
#include "mozIXMLTerminal.h"
|
||||
#include "mozIXMLTermStream.h"
|
||||
|
||||
#define XMLTERM_DLL "libxmlterm"MOZ_DLL_SUFFIX
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID);
|
||||
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
static NS_DEFINE_IID(kIPrefIID, NS_IPREF_IID);
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
||||
static NS_DEFINE_IID(kLineTermCID, MOZLINETERM_CID);
|
||||
static NS_DEFINE_IID(kXMLTermShellCID, MOZXMLTERMSHELL_CID);
|
||||
|
||||
extern "C" void NS_SetupRegistry();
|
||||
|
||||
nsCOMPtr<mozISimpleContainer> gSimpleContainer = nsnull;
|
||||
nsCOMPtr<mozIXMLTerminal> gXMLTerminal = nsnull;
|
||||
|
||||
/** Processes thread events */
|
||||
static void event_processor_callback(gpointer data,
|
||||
gint source,
|
||||
GdkInputCondition condition)
|
||||
{
|
||||
nsIEventQueue *eventQueue = (nsIEventQueue*)data;
|
||||
eventQueue->ProcessPendingEvents();
|
||||
//fprintf(stderr, "event_processor_callback:\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static void event_processor_configure(GtkWidget *window,
|
||||
GdkEvent *event,
|
||||
GtkWidget *termWidget)
|
||||
{
|
||||
GtkAllocation *alloc = >K_WIDGET(termWidget)->allocation;
|
||||
|
||||
//fprintf(stderr, "event_processor_configure:\n");
|
||||
|
||||
// Resize web shell window
|
||||
gSimpleContainer->Resize(alloc->width, alloc->height);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/** Cleans up and exits */
|
||||
static gint event_processor_quit(gpointer data,
|
||||
gint source,
|
||||
GdkInputCondition condition)
|
||||
{
|
||||
fprintf(stderr, "event_processor_quit:\n");
|
||||
|
||||
if (gXMLTerminal) {
|
||||
// Finalize XMLTerm and release owning reference to it
|
||||
gXMLTerminal->Finalize();
|
||||
gXMLTerminal = nsnull;
|
||||
}
|
||||
|
||||
// Delete reference to container
|
||||
gSimpleContainer = nsnull;
|
||||
|
||||
gtk_main_quit();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
GtkWidget *mainWin = NULL;
|
||||
GtkWidget *vertBox = NULL;
|
||||
GtkWidget *horBox = NULL;
|
||||
GtkWidget *testButton = NULL;
|
||||
#if 0 // USE_SUPERWIN
|
||||
GdkSuperWin *termWidget = NULL;
|
||||
GtkWidget *mozArea;
|
||||
#else // USE_SUPERWIN
|
||||
GtkWidget *termWidget = NULL;
|
||||
#endif // !USE_SUPERWIN
|
||||
|
||||
nsIEventQueue *mEventQueue = nsnull;
|
||||
|
||||
nsresult result = NS_OK;
|
||||
|
||||
// Set up registry
|
||||
NS_SetupRegistry();
|
||||
|
||||
// Register XMLTermShell and LineTerm interfaces
|
||||
result = nsComponentManager::RegisterComponentLib(kLineTermCID,NULL,NULL,
|
||||
XMLTERM_DLL, PR_FALSE, PR_FALSE);
|
||||
printf("mozGeckoTerm: registered LineTerm, result=0x%x\n", result);
|
||||
|
||||
result = nsComponentManager::RegisterComponentLib(kXMLTermShellCID,NULL,NULL,
|
||||
XMLTERM_DLL, PR_FALSE, PR_FALSE);
|
||||
printf("mozGeckoTerm: registered XMLTermShell, result=0x%x\n", result);
|
||||
|
||||
// Get the event queue service
|
||||
NS_WITH_SERVICE(nsIEventQueueService, eventQService,
|
||||
kEventQueueServiceCID, &result);
|
||||
if (NS_FAILED(result)) {
|
||||
NS_ASSERTION("Could not obtain event queue service", PR_FALSE);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Get the event queue for the thread.
|
||||
result = eventQService->GetThreadEventQueue(PR_GetCurrentThread(),
|
||||
&mEventQueue);
|
||||
|
||||
if (!mEventQueue) {
|
||||
// Create the event queue for the thread
|
||||
result = eventQService->CreateThreadEventQueue();
|
||||
if (NS_FAILED(result)) {
|
||||
NS_ASSERTION("Could not create the thread event queue", PR_FALSE);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Get the event queue for the thread
|
||||
result = eventQService->GetThreadEventQueue(PR_GetCurrentThread(), &mEventQueue);
|
||||
if (NS_FAILED(result)) {
|
||||
NS_ASSERTION("Could not obtain the thread event queue", PR_FALSE);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// Creat pref object
|
||||
nsCOMPtr<nsIPref> mPref = nsnull;
|
||||
result = nsComponentManager::CreateInstance(kPrefCID, NULL,
|
||||
kIPrefIID, getter_AddRefs(mPref));
|
||||
if (NS_FAILED(result)) {
|
||||
NS_ASSERTION("Failed to create nsIPref object", PR_FALSE);
|
||||
return result;
|
||||
}
|
||||
|
||||
mPref->StartUp();
|
||||
mPref->ReadUserPrefs();
|
||||
|
||||
// Initialize GTK library
|
||||
gtk_set_locale();
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
gdk_rgb_init();
|
||||
|
||||
mainWin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_default_size( GTK_WINDOW(mainWin), 600, 400);
|
||||
gtk_window_set_title(GTK_WINDOW(mainWin), "XMLterm");
|
||||
|
||||
// VBox top level
|
||||
vertBox = gtk_vbox_new(FALSE, 0);
|
||||
gtk_container_add(GTK_CONTAINER(mainWin), vertBox);
|
||||
gtk_widget_show(vertBox);
|
||||
|
||||
// HBox for toolbar
|
||||
horBox = gtk_hbox_new(FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(vertBox), horBox, FALSE, FALSE, 0);
|
||||
|
||||
testButton = gtk_button_new_with_label("Test");
|
||||
gtk_box_pack_start (GTK_BOX (horBox), testButton, FALSE, FALSE, 0);
|
||||
gtk_widget_show(testButton);
|
||||
|
||||
gtk_widget_show(horBox);
|
||||
|
||||
#if 0 // USE_SUPERWIN
|
||||
gtk_window_set_policy(GTK_WINDOW(mainWin), PR_TRUE, PR_TRUE, PR_FALSE);
|
||||
mozArea = gtk_mozarea_new();
|
||||
gtk_container_add(GTK_CONTAINER(mainWin), mozArea);
|
||||
gtk_widget_realize(GTK_WIDGET(mozArea));
|
||||
termWidget = GTK_MOZAREA(mozArea)->superwin;
|
||||
|
||||
#else // USE_SUPERWIN
|
||||
|
||||
// XMLterm layout widget
|
||||
termWidget = gtk_layout_new(NULL, NULL);
|
||||
GTK_WIDGET_SET_FLAGS(termWidget, GTK_CAN_FOCUS);
|
||||
gtk_widget_set_app_paintable(termWidget, TRUE);
|
||||
|
||||
gtk_box_pack_start(GTK_BOX(vertBox), termWidget, TRUE, TRUE, 0);
|
||||
gtk_widget_show_all(termWidget);
|
||||
|
||||
gtk_widget_show(mainWin);
|
||||
#endif // !USE_SUPERWIN
|
||||
|
||||
// Configure event handler
|
||||
gtk_signal_connect_after( GTK_OBJECT(mainWin), "configure_event",
|
||||
GTK_SIGNAL_FUNC(event_processor_configure),
|
||||
termWidget);
|
||||
|
||||
// Cleanup and exit when window is deleted
|
||||
gtk_signal_connect( GTK_OBJECT(mainWin), "delete_event",
|
||||
GTK_SIGNAL_FUNC(event_processor_quit),
|
||||
NULL);
|
||||
|
||||
// Check for input in the events queue file descriptor
|
||||
gdk_input_add(mEventQueue->GetEventQueueSelectFD(),
|
||||
GDK_INPUT_READ,
|
||||
event_processor_callback,
|
||||
mEventQueue);
|
||||
|
||||
// Create simple container
|
||||
result = NS_NewSimpleContainer(getter_AddRefs(gSimpleContainer));
|
||||
|
||||
if (NS_FAILED(result) || !gSimpleContainer) {
|
||||
return result; // Exit main program
|
||||
}
|
||||
|
||||
// Determine window dimensions
|
||||
GtkAllocation *alloc = >K_WIDGET(termWidget)->allocation;
|
||||
|
||||
// Initialize container to hold a web shell
|
||||
result = gSimpleContainer->Init((nsNativeWidget *) termWidget,
|
||||
alloc->width, alloc->height, mPref);
|
||||
|
||||
if (NS_FAILED(result)) {
|
||||
return result; // Exit main program
|
||||
}
|
||||
|
||||
// Get reference to web shell embedded in a simple container
|
||||
nsCOMPtr<nsIWebShell> webShell;
|
||||
result = gSimpleContainer->GetWebShell(*getter_AddRefs(webShell));
|
||||
|
||||
if (NS_FAILED(result) || !webShell) {
|
||||
return result; // Exit main program
|
||||
}
|
||||
|
||||
#if 0
|
||||
// TEMPORARY: Testing mozIXMLTermStream
|
||||
nsAutoString streamData = "<HTML><HEAD><TITLE>Stream Title</TITLE>"
|
||||
"<SCRIPT language='JavaScript'>"
|
||||
"function clik(){ dump('click\\n');return(false);}"
|
||||
"</SCRIPT></HEAD>"
|
||||
"<BODY><B>Stream Body "
|
||||
"<SPAN STYLE='color: blue' onClick='return clik();'>Clik</SPAN></B>"
|
||||
"</BODY></HTML>";
|
||||
|
||||
nsCOMPtr<mozIXMLTermStream> stream;
|
||||
result = NS_NewXMLTermStream(getter_AddRefs(stream));
|
||||
if (NS_FAILED(result)) {
|
||||
fprintf(stderr, "mozGeckoTerm: Failed to create stream\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> outerDOMWindow;
|
||||
result = mozXMLTermUtils::ConvertWebShellToDOMWindow(webShell,
|
||||
getter_AddRefs(outerDOMWindow));
|
||||
|
||||
if (NS_FAILED(result) || !outerDOMWindow)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
result = stream->Open(outerDOMWindow, nsnull, "chrome://dummy", "text/html",
|
||||
0);
|
||||
if (NS_FAILED(result)) {
|
||||
fprintf(stderr, "mozGeckoTerm: Failed to open stream\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
result = stream->Write(streamData.GetUnicode());
|
||||
if (NS_FAILED(result)) {
|
||||
fprintf(stderr, "mozGeckoTerm: Failed to write to stream\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
result = stream->Close();
|
||||
if (NS_FAILED(result)) {
|
||||
fprintf(stderr, "mozGeckoTerm: Failed to close stream\n");
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
// Load initial XMLterm document
|
||||
result = gSimpleContainer->LoadURL(
|
||||
"chrome://xmlterm/content/xmlterm.html");
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// Create an XMLTERM and attach to web shell
|
||||
result = NS_NewXMLTerminal(getter_AddRefs(gXMLTerminal));
|
||||
|
||||
if(!gXMLTerminal)
|
||||
result = NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = gXMLTerminal->Init(webShell, nsnull, nsnull);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Discard reference to web shell
|
||||
webShell = nsnull;
|
||||
|
||||
// GTK event loop
|
||||
gtk_main();
|
||||
|
||||
NS_IF_RELEASE(mEventQueue);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozISimpleContainer.h: a simple WebShell container interface
|
||||
// for use in simple programs using the layout engine
|
||||
// (unregistered interface)
|
||||
|
||||
#ifndef mozISimpleContainer_h___
|
||||
#define mozISimpleContainer_h___
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
|
||||
/* starting interface: mozISimpleContainer */
|
||||
|
||||
/* {0eb82bF0-43a2-11d3-8e76-006008948af5} */
|
||||
#define MOZISIMPLE_CONTAINER_IID_STR "0eb82bF0-43a2-11d3-8e76-006008948af5"
|
||||
#define MOZISIMPLE_CONTAINER_IID \
|
||||
{0x0eb82bF0, 0x43a2, 0x11d3, \
|
||||
{ 0x8e, 0x76, 0x00, 0x60, 0x08, 0x94, 0x8a, 0xf5 }}
|
||||
|
||||
class mozISimpleContainer : public nsIWebShellContainer {
|
||||
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(MOZISIMPLE_CONTAINER_IID)
|
||||
|
||||
// nsIWebShellContainer interface
|
||||
NS_IMETHOD WillLoadURL(nsIWebShell* aShell,
|
||||
const PRUnichar* aURL,
|
||||
nsLoadType aReason) = 0;
|
||||
|
||||
NS_IMETHOD BeginLoadURL(nsIWebShell* aShell,
|
||||
const PRUnichar* aURL) = 0;
|
||||
|
||||
|
||||
NS_IMETHOD ProgressLoadURL(nsIWebShell* aShell,
|
||||
const PRUnichar* aURL,
|
||||
PRInt32 aProgress,
|
||||
PRInt32 aProgressMax) = 0;
|
||||
|
||||
NS_IMETHOD EndLoadURL(nsIWebShell* aShell,
|
||||
const PRUnichar* aURL,
|
||||
nsresult aStatus) = 0;
|
||||
|
||||
NS_IMETHOD NewWebShell(PRUint32 aChromeMask,
|
||||
PRBool aVisible,
|
||||
nsIWebShell *&aNewWebShell) = 0;
|
||||
|
||||
NS_IMETHOD FindWebShellWithName(const PRUnichar* aName,
|
||||
nsIWebShell*& aResult) = 0;
|
||||
|
||||
NS_IMETHOD ContentShellAdded(nsIWebShell* aChildShell,
|
||||
nsIContent* frameNode) = 0;
|
||||
|
||||
NS_IMETHOD CreatePopup(nsIDOMElement* aElement,
|
||||
nsIDOMElement* aPopupContent,
|
||||
PRInt32 aXPos, PRInt32 aYPos,
|
||||
const nsString& aPopupType,
|
||||
const nsString& anAnchorAlignment,
|
||||
const nsString& aPopupAlignment,
|
||||
nsIDOMWindow* aWindow, nsIDOMWindow** outPopup) = 0;
|
||||
|
||||
NS_IMETHOD FocusAvailable(nsIWebShell* aFocusedWebShell,
|
||||
PRBool& aFocusTaken) = 0;
|
||||
|
||||
// other
|
||||
|
||||
/** Initializes simple container for native window widget
|
||||
* @param aNativeWidget native window widget (e.g., GtkWidget)
|
||||
* @param width window width (pixels)
|
||||
* @param height window height (pixels)
|
||||
* @param aPref preferences object
|
||||
*/
|
||||
NS_IMETHOD Init(nsNativeWidget aNativeWidget,
|
||||
PRInt32 width, PRInt32 height,
|
||||
nsIPref* aPref) = 0;
|
||||
|
||||
/** Resizes container to new dimensions
|
||||
* @param width new window width (pixels)
|
||||
* @param height new window height (pixels)
|
||||
*/
|
||||
NS_IMETHOD Resize(PRInt32 aWidth, PRInt32 aHeight) = 0;
|
||||
|
||||
/** Loads specified URL into container
|
||||
* @param aURL URL string
|
||||
*/
|
||||
NS_IMETHOD LoadURL(const char* aURL) = 0;
|
||||
|
||||
/** Gets web shell in container
|
||||
* @param aWebShell (output) web shell object
|
||||
*/
|
||||
NS_IMETHOD GetWebShell(nsIWebShell*& aWebShell) = 0;
|
||||
|
||||
/** Gets DOM document in container
|
||||
* @param aDocument (output) DOM document
|
||||
*/
|
||||
NS_IMETHOD GetDocument(nsIDOMDocument*& aDocument) = 0;
|
||||
|
||||
/** Gets presentation shell associated with container
|
||||
* @param aPresShell (output) presentation shell
|
||||
*/
|
||||
NS_IMETHOD GetPresShell(nsIPresShell*& aPresShell) = 0;
|
||||
};
|
||||
|
||||
#define MOZSIMPLE_CONTAINER_CID \
|
||||
{ /* 0eb82bF1-43a2-11d3-8e76-006008948af5 */ \
|
||||
0x0eb82bF1, 0x43a2, 0x11d3, \
|
||||
{0x8e, 0x76, 0x00, 0x60, 0x08, 0x94, 0x8a, 0xf5} }
|
||||
extern nsresult
|
||||
NS_NewSimpleContainer(mozISimpleContainer** aSimpleContainer);
|
||||
|
||||
#endif /* mozISimpleContainer_h___ */
|
|
@ -0,0 +1,396 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozSimpleContainer.cpp: Implements mozISimpleContainer
|
||||
// which provides a WebShell container for use in simple programs
|
||||
// using the layout engine
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsRepository.h"
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIDocument.h"
|
||||
|
||||
#include "mozSimpleContainer.h"
|
||||
|
||||
|
||||
// Define Class IDs
|
||||
static NS_DEFINE_IID(kWebShellCID, NS_WEB_SHELL_CID);
|
||||
|
||||
// Define Interface IDs
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
|
||||
static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID);
|
||||
static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// mozSimpleContainer factory
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewSimpleContainer(mozISimpleContainer** aSimpleContainer)
|
||||
{
|
||||
NS_PRECONDITION(aSimpleContainer != nsnull, "null ptr");
|
||||
if (!aSimpleContainer)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aSimpleContainer = new mozSimpleContainer();
|
||||
if (! *aSimpleContainer)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aSimpleContainer);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// mozSimpleContainer implementation
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
mozSimpleContainer::mozSimpleContainer() :
|
||||
mWebShell(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
|
||||
mozSimpleContainer::~mozSimpleContainer()
|
||||
{
|
||||
mWebShell = nsnull;
|
||||
}
|
||||
|
||||
#define NS_IMPL_ADDREF_TRACE(_class) \
|
||||
NS_IMETHODIMP_(nsrefcnt) _class::AddRef(void) \
|
||||
{ \
|
||||
NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt"); \
|
||||
++mRefCnt; \
|
||||
fprintf(stderr, "mozSimpleContainer:AddRef, mRefCnt=%d\n", mRefCnt); \
|
||||
return mRefCnt; \
|
||||
}
|
||||
|
||||
#define NS_IMPL_RELEASE_TRACE(_class) \
|
||||
NS_IMETHODIMP_(nsrefcnt) _class::Release(void) \
|
||||
{ \
|
||||
NS_PRECONDITION(0 != mRefCnt, "dup release"); \
|
||||
--mRefCnt; \
|
||||
fprintf(stderr, "mozSimpleContainer:Release, mRefCnt=%d\n", mRefCnt); \
|
||||
if (mRefCnt == 0) { \
|
||||
NS_DELETEXPCOM(this); \
|
||||
return 0; \
|
||||
} \
|
||||
return mRefCnt; \
|
||||
}
|
||||
|
||||
// Implement AddRef and Release
|
||||
NS_IMPL_ADDREF(mozSimpleContainer)
|
||||
NS_IMPL_RELEASE(mozSimpleContainer)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSimpleContainer::QueryInterface(REFNSIID aIID,void** aInstancePtr)
|
||||
{
|
||||
if (aInstancePtr == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
if ( aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsISupports*,
|
||||
NS_STATIC_CAST(mozISimpleContainer*,this));
|
||||
|
||||
} else if ( aIID.Equals(mozISimpleContainer::GetIID()) ) {
|
||||
*aInstancePtr = NS_STATIC_CAST(mozISimpleContainer*,this);
|
||||
|
||||
} else if ( aIID.Equals(nsIWebShellContainer::GetIID()) ) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIWebShellContainer*,this);
|
||||
|
||||
} else {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
fprintf(stderr, "mozSimpleContainer::QueryInterface, mRefCnt = %d\n", mRefCnt);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Initializes simple container for native window widget
|
||||
* @param aNativeWidget native window widget (e.g., GtkWidget)
|
||||
* @param width window width (pixels)
|
||||
* @param height window height (pixels)
|
||||
* @param aPref preferences object
|
||||
*/
|
||||
NS_IMETHODIMP mozSimpleContainer::Init(nsNativeWidget aNativeWidget,
|
||||
PRInt32 width, PRInt32 height,
|
||||
nsIPref* aPref)
|
||||
{
|
||||
// Create web shell and show it
|
||||
nsresult result = nsRepository::CreateInstance(kWebShellCID, nsnull,
|
||||
kIWebShellIID,
|
||||
getter_AddRefs(mWebShell));
|
||||
|
||||
if (NS_FAILED(result) || !mWebShell) {
|
||||
fprintf(stderr, "Failed to create create web shell\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
mWebShell->Init(aNativeWidget, 0, 0, width, height);
|
||||
|
||||
mWebShell->SetContainer(this);
|
||||
if (aPref) {
|
||||
mWebShell->SetPrefs(aPref);
|
||||
}
|
||||
mWebShell->Show();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozSimpleContainer::WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsLoadType aReason)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozSimpleContainer::BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozSimpleContainer::ProgressLoadURL(nsIWebShell* aShell,
|
||||
const PRUnichar* aURL, PRInt32 aProgress, PRInt32 aProgressMax)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozSimpleContainer::EndLoadURL(nsIWebShell* aShell,
|
||||
const PRUnichar* aURL,
|
||||
nsresult aStatus)
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
nsresult result;
|
||||
|
||||
if (aShell == mWebShell.get()) {
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
|
||||
result = GetDocument(*getter_AddRefs(domDoc));
|
||||
if (NS_FAILED(result) || !domDoc) return result;
|
||||
|
||||
result = GetPresShell(*getter_AddRefs(presShell));
|
||||
if (NS_FAILED(result) || !presShell) return result;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozSimpleContainer::NewWebShell(PRUint32 aChromeMask,
|
||||
PRBool aVisible,
|
||||
nsIWebShell*& aNewWebShell)
|
||||
{
|
||||
aNewWebShell = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP mozSimpleContainer::FindWebShellWithName(const PRUnichar* aName,
|
||||
nsIWebShell*& aResult)
|
||||
{
|
||||
aResult = nsnull;
|
||||
nsString aNameStr(aName);
|
||||
|
||||
nsIWebShell *aWebShell;
|
||||
|
||||
if (NS_OK == GetWebShell(aWebShell)) {
|
||||
const PRUnichar *name;
|
||||
if (NS_OK == aWebShell->GetName(&name)) {
|
||||
if (aNameStr.Equals(name)) {
|
||||
aResult = aWebShell;
|
||||
NS_ADDREF(aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_OK == aWebShell->FindChildWithName(aName, aResult)) {
|
||||
if (nsnull != aResult) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSimpleContainer::ContentShellAdded(nsIWebShell* aChildShell,
|
||||
nsIContent* frameNode)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSimpleContainer::CreatePopup(nsIDOMElement* aElement,
|
||||
nsIDOMElement* aPopupContent,
|
||||
PRInt32 aXPos, PRInt32 aYPos,
|
||||
const nsString& aPopupType,
|
||||
const nsString& anAnchorAlignment,
|
||||
const nsString& aPopupAlignment,
|
||||
nsIDOMWindow* aWindow, nsIDOMWindow** outPopup)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSimpleContainer::FocusAvailable(nsIWebShell* aFocusedWebShell,
|
||||
PRBool& aFocusTaken)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Resizes container to new dimensions
|
||||
* @param width new window width (pixels)
|
||||
* @param height new window height (pixels)
|
||||
*/
|
||||
NS_IMETHODIMP mozSimpleContainer::Resize(PRInt32 aWidth, PRInt32 aHeight)
|
||||
{
|
||||
if (!mWebShell) return NS_ERROR_FAILURE;
|
||||
|
||||
mWebShell->SetBounds(0, 0, aWidth, aHeight);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Loads specified URL into container
|
||||
* @param aURL URL string
|
||||
*/
|
||||
NS_IMETHODIMP mozSimpleContainer::LoadURL(const char* aURL)
|
||||
{
|
||||
if (!mWebShell) return NS_ERROR_FAILURE;
|
||||
|
||||
nsString aStr(aURL);
|
||||
mWebShell->LoadURL(aStr.GetUnicode());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Gets web shell in container
|
||||
* @param aWebShell (output) web shell object
|
||||
*/
|
||||
NS_IMETHODIMP mozSimpleContainer::GetWebShell(nsIWebShell*& aWebShell)
|
||||
{
|
||||
aWebShell = mWebShell.get();
|
||||
NS_IF_ADDREF(aWebShell); // Add ref'ed; needs to be released
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Gets DOM document in container
|
||||
* @param aDocument (output) DOM document
|
||||
*/
|
||||
NS_IMETHODIMP mozSimpleContainer::GetDocument(nsIDOMDocument*& aDocument)
|
||||
{
|
||||
|
||||
aDocument = nsnull;
|
||||
|
||||
if (mWebShell) {
|
||||
nsIContentViewer* contViewer;
|
||||
mWebShell->GetContentViewer(&contViewer);
|
||||
|
||||
if (nsnull != contViewer) {
|
||||
nsIDocumentViewer* docViewer;
|
||||
if (NS_OK == contViewer->QueryInterface(kIDocumentViewerIID,
|
||||
(void**) &docViewer))
|
||||
{
|
||||
nsIDocument* vDoc;
|
||||
docViewer->GetDocument(vDoc);
|
||||
|
||||
if (nsnull != vDoc) {
|
||||
nsIDOMDocument* vDOMDoc;
|
||||
if (NS_OK == vDoc->QueryInterface(kIDOMDocumentIID,
|
||||
(void**) &vDOMDoc))
|
||||
{
|
||||
aDocument = vDOMDoc; // Add ref'ed; needs to be released
|
||||
}
|
||||
NS_RELEASE(vDoc);
|
||||
}
|
||||
|
||||
NS_RELEASE(docViewer);
|
||||
}
|
||||
|
||||
NS_RELEASE(contViewer);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Gets presentation shell associated with container
|
||||
* @param aPresShell (output) presentation shell
|
||||
*/
|
||||
NS_IMETHODIMP mozSimpleContainer::GetPresShell(nsIPresShell*& aPresShell)
|
||||
{
|
||||
aPresShell = nsnull;
|
||||
|
||||
nsIPresShell* presShell = nsnull;
|
||||
|
||||
if (mWebShell) {
|
||||
nsIContentViewer* contViewer = nsnull;
|
||||
mWebShell->GetContentViewer(&contViewer);
|
||||
|
||||
if (nsnull != contViewer) {
|
||||
nsIDocumentViewer* docViewer = nsnull;
|
||||
contViewer->QueryInterface(kIDocumentViewerIID, (void**) &docViewer);
|
||||
|
||||
if (nsnull != docViewer) {
|
||||
nsIPresContext* presContext;
|
||||
docViewer->GetPresContext(presContext);
|
||||
|
||||
if (nsnull != presContext) {
|
||||
presContext->GetShell(&presShell); // Add ref'ed
|
||||
aPresShell = presShell;
|
||||
NS_RELEASE(presContext);
|
||||
}
|
||||
|
||||
NS_RELEASE(docViewer);
|
||||
}
|
||||
|
||||
NS_RELEASE(contViewer);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* 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 XMLterm.
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
// mozSimpleContainer.h: declaration of mozSimpleContainer class
|
||||
// implementing mozISimpleContainer,
|
||||
// which provides a WebShell container for use in simple programs
|
||||
// using the layout engine
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "mozISimpleContainer.h"
|
||||
|
||||
class mozSimpleContainer : public mozISimpleContainer {
|
||||
|
||||
public:
|
||||
|
||||
mozSimpleContainer();
|
||||
virtual ~mozSimpleContainer();
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIWebShellContainer interface
|
||||
NS_IMETHOD WillLoadURL(nsIWebShell* aShell,
|
||||
const PRUnichar* aURL,
|
||||
nsLoadType aReason);
|
||||
|
||||
NS_IMETHOD BeginLoadURL(nsIWebShell* aShell,
|
||||
const PRUnichar* aURL);
|
||||
|
||||
|
||||
NS_IMETHOD ProgressLoadURL(nsIWebShell* aShell,
|
||||
const PRUnichar* aURL,
|
||||
PRInt32 aProgress,
|
||||
PRInt32 aProgressMax);
|
||||
|
||||
NS_IMETHOD EndLoadURL(nsIWebShell* aShell,
|
||||
const PRUnichar* aURL,
|
||||
nsresult aStatus);
|
||||
|
||||
NS_IMETHOD NewWebShell(PRUint32 aChromeMask,
|
||||
PRBool aVisible,
|
||||
nsIWebShell *&aNewWebShell);
|
||||
|
||||
NS_IMETHOD FindWebShellWithName(const PRUnichar* aName,
|
||||
nsIWebShell*& aResult);
|
||||
|
||||
NS_IMETHOD ContentShellAdded(nsIWebShell* aChildShell,
|
||||
nsIContent* frameNode);
|
||||
|
||||
NS_IMETHOD CreatePopup(nsIDOMElement* aElement,
|
||||
nsIDOMElement* aPopupContent,
|
||||
PRInt32 aXPos, PRInt32 aYPos,
|
||||
const nsString& aPopupType,
|
||||
const nsString& anAnchorAlignment,
|
||||
const nsString& aPopupAlignment,
|
||||
nsIDOMWindow* aWindow, nsIDOMWindow** outPopup);
|
||||
|
||||
NS_IMETHOD FocusAvailable(nsIWebShell* aFocusedWebShell,
|
||||
PRBool& aFocusTaken);
|
||||
|
||||
// other
|
||||
NS_IMETHOD Init(nsNativeWidget aNativeWidget,
|
||||
PRInt32 width, PRInt32 height,
|
||||
nsIPref* aPref);
|
||||
|
||||
NS_IMETHOD Resize(PRInt32 aWidth, PRInt32 aHeight);
|
||||
|
||||
NS_IMETHOD LoadURL(const char* aURL);
|
||||
|
||||
NS_IMETHOD GetWebShell(nsIWebShell*& aWebShell);
|
||||
|
||||
NS_IMETHOD GetDocument(nsIDOMDocument*& aDocument);
|
||||
|
||||
NS_IMETHOD GetPresShell(nsIPresShell*& aPresShell);
|
||||
|
||||
protected:
|
||||
|
||||
/** owning reference to web shell created by us */
|
||||
nsCOMPtr<nsIWebShell> mWebShell;
|
||||
|
||||
};
|
|
@ -0,0 +1,65 @@
|
|||
#!gmake
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# makefile for xmlterm/linetest directory
|
||||
|
||||
ifdef STAND_ALONE
|
||||
DEPTH = ..
|
||||
topsrcdir = ..
|
||||
srcdir = .
|
||||
include $(topsrcdir)/config/autoconf.mk
|
||||
else
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
endif
|
||||
|
||||
|
||||
# Debug option
|
||||
DEBUG = 1
|
||||
|
||||
# Program
|
||||
SIMPLE_PROGRAMS = lterm ptytest testunistr
|
||||
|
||||
# Defines
|
||||
DEFINES =
|
||||
|
||||
# Libraries to be linked
|
||||
LIBS = -lncurses -lxmlterm -lpthread
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include ../config/xmlterm_config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,557 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* lterm.c: Test driver for LINETERM using NCURSES
|
||||
* CPP options:
|
||||
* LINUX: for Linux2.0/glibc
|
||||
* SOLARIS: for Solaris2.6
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
#define _REENTRANT
|
||||
#include <pthread.h>
|
||||
|
||||
#ifdef SOLARIS
|
||||
#include <stropts.h>
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
#ifdef LINUX
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/poll.h>
|
||||
typedef unsigned int nfds_t;
|
||||
#endif
|
||||
|
||||
#include "lineterm.h"
|
||||
#include "tracelog.h"
|
||||
|
||||
#define MAXPROMPT 256 /* Maximum length of prompt regexp */
|
||||
#define MAXCOL 4096 /* Maximum columns in line buffer */
|
||||
|
||||
/* (0,0) is upper lefthand corner of window */
|
||||
|
||||
/* Character attributes
|
||||
A_NORMAL Normal display (no highlight)
|
||||
A_STANDOUT Best highlighting mode of the terminal.
|
||||
A_UNDERLINE Underlining
|
||||
A_REVERSE Reverse video
|
||||
A_BLINK Blinking
|
||||
A_DIM Half bright
|
||||
A_BOLD Extra bright or bold
|
||||
A_PROTECT Protected mode
|
||||
A_INVIS Invisible or blank mode
|
||||
A_ALTCHARSET Alternate character set
|
||||
A_CHARTEXT Bit-mask to extract a character
|
||||
COLOR_PAIR(n) Color-pair number n
|
||||
*/
|
||||
|
||||
/* GLOBAL VARIABLES */
|
||||
static int lineFlag = 0;
|
||||
static int ptyFlag = 1;
|
||||
static int debugFlag = 0;
|
||||
static int ltermNumber = -1;
|
||||
static SCREEN *termScreen = NULL;
|
||||
static char *ttyDevice;
|
||||
static char *errDevice;
|
||||
|
||||
static struct termios tios; /* TERMIOS structure */
|
||||
|
||||
static void finish(int sig);
|
||||
static pthread_t output_handler_thread_ID;
|
||||
|
||||
static void *output_handler(void *arg);
|
||||
|
||||
static void input_handler(int *plterm);
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
FILE *inFile, *outFile;
|
||||
UNICHAR uregexp[MAXPROMPT+1];
|
||||
int argNo, options, processType, retValue;
|
||||
int remaining, decoded;
|
||||
int messageLevel;
|
||||
char *promptStr;
|
||||
char **commandArgs;
|
||||
char *defaultCommand[] = {(char *)getenv("SHELL"), "-i", NULL};
|
||||
|
||||
/* Process command line arguments */
|
||||
lineFlag = 0;
|
||||
ptyFlag = 1;
|
||||
debugFlag = 0;
|
||||
processType = LTERM_DETERMINE_PROCESS;
|
||||
ttyDevice = NULL;
|
||||
errDevice = NULL;
|
||||
promptStr = "#$%>?"; /* JUST A LIST OF DELIMITERS AT PRESENT */
|
||||
|
||||
lineFlag = 1; /* Temporary */
|
||||
|
||||
argNo = 1;
|
||||
while (argNo < argc) {
|
||||
|
||||
if ((strcmp(argv[argNo],"-h") == 0)||(strcmp(argv[argNo],"-help") == 0)) {
|
||||
fprintf(stderr, "Usage: %s [-help] [-line] [-nopty] [-debug] [-tcsh / -bash] [-tty /dev/ttyname] [-err /dev/ttyname] [-prompt <prompt>] <command> ...\n", argv[0]);
|
||||
exit(0);
|
||||
|
||||
} else if (strcmp(argv[argNo],"-line") == 0) {
|
||||
lineFlag = 1;
|
||||
argNo++;
|
||||
|
||||
} else if (strcmp(argv[argNo],"-nopty") == 0) {
|
||||
ptyFlag = 0;
|
||||
argNo++;
|
||||
|
||||
} else if (strcmp(argv[argNo],"-debug") == 0) {
|
||||
debugFlag = 1;
|
||||
argNo++;
|
||||
|
||||
} else if (strcmp(argv[argNo],"-bash") == 0) {
|
||||
processType = LTERM_BASH_PROCESS;
|
||||
argNo++;
|
||||
|
||||
} else if (strcmp(argv[argNo],"-tcsh") == 0) {
|
||||
processType = LTERM_TCSH_PROCESS;
|
||||
argNo++;
|
||||
|
||||
} else if (strcmp(argv[argNo],"-tty") == 0) {
|
||||
argNo++;
|
||||
if (argNo < argc) {
|
||||
ttyDevice = argv[argNo];
|
||||
argNo++;
|
||||
}
|
||||
|
||||
} else if (strcmp(argv[argNo],"-err") == 0) {
|
||||
argNo++;
|
||||
if (argNo < argc) {
|
||||
errDevice = argv[argNo];
|
||||
argNo++;
|
||||
}
|
||||
|
||||
} else if (strcmp(argv[argNo],"-prompt") == 0) {
|
||||
argNo++;
|
||||
if (argNo < argc) {
|
||||
promptStr = argv[argNo];
|
||||
argNo++;
|
||||
}
|
||||
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
if (argNo < argc) {
|
||||
/* Execute specified command */
|
||||
commandArgs = argv + argNo;
|
||||
} else {
|
||||
/* Execute default shell */
|
||||
commandArgs = defaultCommand;
|
||||
}
|
||||
|
||||
/* Convert prompt string to Unicode */
|
||||
retValue = utf8toucs(promptStr, strlen(promptStr), uregexp, MAXPROMPT,
|
||||
0, &remaining, &decoded);
|
||||
if ((retValue < 0) || (remaining > 0)) {
|
||||
fprintf(stderr, "lterm: Error in decoding prompt string\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
assert(decoded <= MAXPROMPT);
|
||||
uregexp[decoded] = U_NUL;
|
||||
|
||||
if (debugFlag) {
|
||||
messageLevel = 98;
|
||||
} else {
|
||||
messageLevel = 1;
|
||||
}
|
||||
|
||||
if (errDevice != NULL) {
|
||||
/* Redirect debug STDERR output to specified device */
|
||||
int errfd = -1;
|
||||
if ( (errfd = open(errDevice, O_WRONLY)) == -1)
|
||||
perror("lterm");
|
||||
|
||||
if (dup2(errfd, 2) == -1) {
|
||||
fprintf(stderr, "lterm: Failed dup2 for specified stderr\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
fprintf(stderr, "\n\nlterm: Echoing %s output to %s\n",
|
||||
argv[0], errDevice);
|
||||
}
|
||||
|
||||
signal(SIGINT, finish); /* Interrupt handler */
|
||||
|
||||
if (lineFlag) {
|
||||
/* Line mode */
|
||||
|
||||
/* Get terminal attributes */
|
||||
if (tcgetattr(0, &tios) == -1) {
|
||||
fprintf(stderr, "lterm: Failed to get TTY attributes\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/* Disable signals, canonical mode processing, and echo */
|
||||
tios.c_lflag &= ~(ISIG | ICANON | ECHO );
|
||||
|
||||
/* set MIN=1 and TIME=0 */
|
||||
tios.c_cc[VMIN] = 1;
|
||||
tios.c_cc[VTIME] = 0;
|
||||
|
||||
/* Set terminal attributes */
|
||||
if (tcsetattr(0, TCSAFLUSH, &tios) == -1) {
|
||||
fprintf(stderr, "lterm: Failed to set TTY attributes\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
} else {
|
||||
/* Screen mode */
|
||||
if (ttyDevice == NULL) {
|
||||
/* Initialize screen on controlling TTY */
|
||||
initscr();
|
||||
|
||||
} else {
|
||||
/* Initialize screen on specified TTY */
|
||||
if (errDevice != NULL)
|
||||
fprintf(stderr, "lterm-00: Opening xterm %s\n", ttyDevice);
|
||||
inFile = fopen( ttyDevice, "r");
|
||||
outFile = fopen( ttyDevice, "w");
|
||||
termScreen = newterm("xterm", outFile, inFile);
|
||||
set_term(termScreen);
|
||||
}
|
||||
|
||||
/* NCURSES screen settings */
|
||||
cbreak(); /* set terminal to raw (non-canonical) mode */
|
||||
noecho(); /* Disable terminal echo */
|
||||
nonl(); /* Do not translate newline */
|
||||
intrflush(stdscr, FALSE); /* Flush input on interrupt */
|
||||
keypad(stdscr, TRUE); /* Enable user keypad */
|
||||
|
||||
#ifdef NCURSES_MOUSE_VERSION
|
||||
mousemask(BUTTON1_CLICKED, NULL); /* Capture Button1 click events */
|
||||
#endif
|
||||
|
||||
clear(); /* Clear screen */
|
||||
}
|
||||
|
||||
/* Initialize LTERM operations */
|
||||
lterm_init(messageLevel);
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
if (errDevice != NULL)
|
||||
fprintf(stderr, "lintest-00: Opening LTERM to execute %s\n", commandArgs[0]);
|
||||
|
||||
options = 0;
|
||||
if (!ptyFlag) options |= LTERM_NOPTY_FLAG;
|
||||
|
||||
// options |= LTERM_NOSTDERR_FLAG;
|
||||
|
||||
ltermNumber = lterm_new();
|
||||
retValue = lterm_open(ltermNumber, commandArgs, NULL, uregexp,
|
||||
options, processType, NULL, NULL);
|
||||
if (retValue < 0) {
|
||||
fprintf(stderr, "lterm: Error %d in opening LTERM\n", retValue);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Create output handler thread */
|
||||
retValue = pthread_create(&output_handler_thread_ID, NULL,
|
||||
output_handler, (void *) <ermNumber);
|
||||
if (retValue != 0) {
|
||||
fprintf(stderr, "lterm: Error %d in creating OUTPUT_HANDLER thread\n",
|
||||
retValue);
|
||||
finish(0);
|
||||
}
|
||||
|
||||
if (errDevice != NULL)
|
||||
fprintf(stderr, "lterm-00: Created OUTPUT_HANDLER thread\n");
|
||||
|
||||
/* Process input */
|
||||
input_handler(<ermNumber);
|
||||
|
||||
/* Join output handler thread */
|
||||
if (errDevice != NULL)
|
||||
fprintf(stderr, "lterm-00: Joining OUTPUT_HANDLER thread\n");
|
||||
|
||||
retValue = pthread_join(output_handler_thread_ID, NULL);
|
||||
if (retValue != 0) {
|
||||
fprintf(stderr, "lterm: Error %d in joining OUTPUT_HANDLER thread\n",
|
||||
retValue);
|
||||
finish(0);
|
||||
}
|
||||
|
||||
finish(0);
|
||||
}
|
||||
|
||||
void finish(int sig)
|
||||
{
|
||||
if (!lineFlag) {
|
||||
endwin(); /* Close window */
|
||||
if (termScreen != NULL)
|
||||
delscreen(termScreen);
|
||||
}
|
||||
|
||||
if (ltermNumber >= 0) {
|
||||
/* Close and delete LTERM */
|
||||
lterm_delete(ltermNumber);
|
||||
}
|
||||
|
||||
if (errDevice != NULL)
|
||||
fprintf(stderr, "finished-00: Finished\n");
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/** Output an Unicode message to specified file descriptor. */
|
||||
void writeUnicode(int fd, const UNICHAR *buf, int count)
|
||||
{
|
||||
char str[MAXCOL];
|
||||
int j, k;
|
||||
|
||||
k = 0;
|
||||
for (j=0; j<count; j++) {
|
||||
|
||||
if (k >= MAXCOL-4) {
|
||||
if (MAXCOL >= 4) {
|
||||
str[MAXCOL-4] = '.';
|
||||
str[MAXCOL-3] = '.';
|
||||
str[MAXCOL-2] = '.';
|
||||
}
|
||||
k = MAXCOL-1;
|
||||
break;
|
||||
}
|
||||
|
||||
/* TEMPORARY IMPLEMENTATION: just truncate Unicode to byte characters */
|
||||
str[k++] = buf[j];
|
||||
}
|
||||
|
||||
if (k == 0) return;
|
||||
|
||||
if (write(fd, str, k) != k) {
|
||||
fprintf(stderr, "writeUnicode: Error in writing to FD %d\n", fd);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Output an Unicode message to specified output stream
|
||||
* if NOCONTROL is true, control characters are converted to printable
|
||||
* characters before output
|
||||
*/
|
||||
void printUnicode(FILE *outStream, const UNICHAR *buf, int count, int noControl)
|
||||
{
|
||||
char str[MAXCOL];
|
||||
int j, k;
|
||||
|
||||
k = 0;
|
||||
for (j=0; j<count; j++) {
|
||||
|
||||
if (k >= MAXCOL-4) {
|
||||
if (MAXCOL >= 4) {
|
||||
str[MAXCOL-4] = '.';
|
||||
str[MAXCOL-3] = '.';
|
||||
str[MAXCOL-2] = '.';
|
||||
}
|
||||
k = MAXCOL-1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!noControl && ((buf[j] < U_SPACE) || (buf[j] == U_DEL)) ) {
|
||||
/* Control character */
|
||||
str[k++] = U_CARET;
|
||||
str[k++] = buf[j]+U_ATSIGN;
|
||||
} else {
|
||||
/* Printable character */
|
||||
/* TEMPORARY IMPLEMENTATION: just truncate Unicode to byte characters */
|
||||
str[k++] = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
/* Insert terminating null character and display string */
|
||||
str[k++] = '\0';
|
||||
fprintf(outStream, "%s\n", str);
|
||||
}
|
||||
|
||||
|
||||
void input_handler(int *plterm)
|
||||
{
|
||||
char ch;
|
||||
UNICHAR uch;
|
||||
int n_written;
|
||||
|
||||
if (lineFlag) {
|
||||
|
||||
for (;;) {
|
||||
/* Read a character from TTY (raw mode) */
|
||||
ch = getchar();
|
||||
|
||||
if (ch == 0) {
|
||||
fprintf(stderr, "input_handler-00: NUL character read; terminating\n");
|
||||
break;
|
||||
}
|
||||
|
||||
uch = (UNICHAR) ch;
|
||||
n_written = lterm_write(*plterm, &uch, 1, LTERM_WRITE_PLAIN_INPUT);
|
||||
|
||||
/* Exit loop if TTY has been closed */
|
||||
if (n_written == -2) {
|
||||
if (errDevice != NULL)
|
||||
fprintf(stderr, "input_handler-00: pseudo-TTY has been closed\n", *plterm);
|
||||
break;
|
||||
}
|
||||
|
||||
if (n_written < 0) {
|
||||
fprintf(stderr, "input_handler: Error %d return from lterm_write\n",
|
||||
n_written);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Close LTERM */
|
||||
if (errDevice != NULL)
|
||||
fprintf(stderr, "input_handler-00: Closing LTERM %d\n", *plterm);
|
||||
|
||||
/* Close and delete LTERM */
|
||||
lterm_delete(*plterm);
|
||||
*plterm = -1;
|
||||
}
|
||||
|
||||
void *output_handler(void *arg)
|
||||
{
|
||||
int *plterm = (int *) arg;
|
||||
int timeout = -1;
|
||||
UNICHAR buf[MAXCOL];
|
||||
UNISTYLE style[MAXCOL];
|
||||
int n_read, opcodes, buf_row, buf_col, cursor_row, cursor_col;
|
||||
int xmax, ymax, x, y, c;
|
||||
MEVENT mev;
|
||||
|
||||
if (errDevice != NULL)
|
||||
fprintf(stderr, "output_handler-00: thread ID = %d, LTERM=%d\n",
|
||||
pthread_self(), *plterm);
|
||||
|
||||
if (!lineFlag) {
|
||||
/* Get screen size */
|
||||
getmaxyx(stdscr, ymax, xmax);
|
||||
|
||||
if (errDevice != NULL)
|
||||
fprintf(stderr, "output_handler-00: screen xmax = %d, ymax = %d\n",
|
||||
xmax,ymax);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
n_read = lterm_read(*plterm, timeout, buf, MAXCOL,
|
||||
style, &opcodes,
|
||||
&buf_row, &buf_col, &cursor_row, &cursor_col);
|
||||
|
||||
if (n_read == -1) {
|
||||
fprintf(stderr, "output_handler: Error %d return from lterm_read\n",
|
||||
n_read);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Exit loop if TTY has been closed;
|
||||
* leave it to input handler to close the LTERM.
|
||||
*/
|
||||
if (n_read == -2) {
|
||||
if (errDevice != NULL)
|
||||
fprintf(stderr, "output_handler: pseudo-TTY has been closed\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (debugFlag) {
|
||||
fprintf(stderr, "output_handler-00: n_read=%d, opcodes=%x, buf_row/col=%d/%d, cursor_row/col=%d/%d\n",
|
||||
n_read, opcodes, buf_row, buf_col, cursor_row, cursor_col);
|
||||
fprintf(stderr, "output_handler-00: U(%d): ", n_read);
|
||||
printUnicode(stderr, buf, n_read, 1);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
if (opcodes & LTERM_STREAMDATA_CODE) {
|
||||
/* Stream data */
|
||||
if (debugFlag)
|
||||
fprintf(stderr, "output_handler-00: STREAMDATA\n");
|
||||
|
||||
} else if (opcodes & LTERM_SCREENDATA_CODE) {
|
||||
/* Screen data */
|
||||
if (debugFlag)
|
||||
fprintf(stderr, "output_handler-00: SCREENDATA\n");
|
||||
|
||||
} else if (opcodes & LTERM_LINEDATA_CODE) {
|
||||
/* Line data */
|
||||
if (debugFlag)
|
||||
fprintf(stderr, "output_handler-00: LINEDATA\n");
|
||||
|
||||
if (lineFlag) {
|
||||
int j;
|
||||
write(1, "\033[2K", 4);
|
||||
write(1, "\r", 1);
|
||||
|
||||
if (opcodes & LTERM_META_CODE)
|
||||
write(1, "META", 4);
|
||||
|
||||
writeUnicode(1, buf, n_read);
|
||||
|
||||
for (j=0; j< (n_read-cursor_col); j++)
|
||||
write(1, "\033[D", 3);
|
||||
|
||||
if (opcodes & LTERM_BELL_CODE)
|
||||
write(1, "\007", 1);
|
||||
|
||||
if (opcodes & LTERM_CLEAR_CODE)
|
||||
write(1, "\033[H\033[2J", 7);
|
||||
|
||||
if (opcodes & LTERM_NEWLINE_CODE)
|
||||
write(1, "\n", 1);
|
||||
}
|
||||
|
||||
} else if (opcodes != 0) {
|
||||
fprintf(stderr, "output_handler: invalid opcodes %x\n", opcodes);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
|
@ -0,0 +1,366 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* ptytest.c: Test driver for ptystream.c
|
||||
* CPP options:
|
||||
* LINUX: for Linux2.0/glibc
|
||||
* SOLARIS: for Solaris2.6
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef SOLARIS
|
||||
#include <stropts.h>
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
#ifdef LINUX
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/poll.h>
|
||||
typedef unsigned int nfds_t;
|
||||
#endif
|
||||
|
||||
#include "ptystream.h"
|
||||
|
||||
static struct termios tios; /* TERMIOS structure */
|
||||
|
||||
void pipeTest(int argc, char *argv[]);
|
||||
void ptyTest(int argc, char *argv[]);
|
||||
|
||||
int echofd = -1;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
if (argc < 4) {
|
||||
fprintf(stderr, "Usage: %s pty|pipe <echo-tty-name>|'' <shell-path> ...\n",
|
||||
argv[0]);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/* Get terminal attributes */
|
||||
if (tcgetattr(0, &tios) == -1) {
|
||||
fprintf(stderr, "Failed to get TTY attributes\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/* Disable signals, canonical mode processing, and echo */
|
||||
tios.c_lflag &= ~(ISIG | ICANON | ECHO );
|
||||
|
||||
/* set MIN=1 and TIME=0 */
|
||||
tios.c_cc[VMIN] = 1;
|
||||
tios.c_cc[VTIME] = 0;
|
||||
|
||||
/* Set terminal attributes */
|
||||
if (tcsetattr(0, TCSAFLUSH, &tios) == -1) {
|
||||
fprintf(stderr, "Failed to set TTY attributes\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (strlen(argv[2]) > 0) {
|
||||
/* Open TTY for echoing */
|
||||
if ( (echofd = open(argv[2], O_WRONLY)) == -1)
|
||||
perror("ptytest");
|
||||
fprintf(stderr, "Echoing %s output to %s\n", argv[1], argv[2]);
|
||||
write( echofd, "Echoing PTYTEST output ...\n", 27);
|
||||
}
|
||||
|
||||
fprintf(stderr, "Type Control-@ (NUL) to terminate input\n");
|
||||
|
||||
if (strcmp(argv[1],"pipe") == 0) {
|
||||
pipeTest(argc-3, argv+3);
|
||||
} else {
|
||||
ptyTest(argc-3, argv+3);
|
||||
}
|
||||
|
||||
if (echofd >= 0) close(echofd);
|
||||
exit(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* sends raw terminal input/output to a shell through a pseudo-TTY */
|
||||
void ptyTest(int argc, char *argv[])
|
||||
{
|
||||
struct pollfd pollFD[2];
|
||||
nfds_t nfds = 2;
|
||||
struct ptys ptyStruc;
|
||||
|
||||
unsigned char ch;
|
||||
int ptyFD, pollCode;
|
||||
ssize_t n_read, n_written;
|
||||
|
||||
char temstr[3] = "^@";
|
||||
|
||||
/* Create a PTY */
|
||||
if (pty_create(&ptyStruc,argv,-1,0,0,0,1) == -1) {
|
||||
fprintf(stderr, "PTY creation failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
ptyFD = ptyStruc.ptyFD;
|
||||
|
||||
/* fprintf(stderr, "Polling for input on fd=0 (%s) and fd=%d\n",
|
||||
ttyname(0), ptyFD ); */
|
||||
|
||||
/* Set up polling to read from parent STDIN and child STDOUT */
|
||||
pollFD[0].fd = 0;
|
||||
pollFD[0].events = POLLIN;
|
||||
pollFD[1].fd = ptyFD;
|
||||
pollFD[1].events = POLLIN;
|
||||
|
||||
while ( (pollCode=poll(pollFD,nfds,-1)) >= 0) {
|
||||
if (pollCode == 0) continue;
|
||||
pollCode = 0;
|
||||
|
||||
if (pollFD[0].revents != 0) {
|
||||
/* Read character from parent STDIN and write to child STDIN */
|
||||
ch = getchar();
|
||||
|
||||
/* Exit poll loop if a null (Control-@) is read */
|
||||
if (ch == 0) break;
|
||||
|
||||
if (write(ptyFD, &ch, 1) != 1) {
|
||||
fprintf(stderr, "Error in writing to child STDIN\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (pollFD[1].revents != 0) {
|
||||
/* Read character from child STDOUT and write to parent STDOUT */
|
||||
|
||||
if ( (n_read=read(ptyFD, &ch, 1)) < 0) {
|
||||
fprintf(stderr, "Error in reading from child STDOUT\n");
|
||||
if (echofd >= 0) close(echofd);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (n_read == 0) { /* End of file */
|
||||
if (echofd >= 0) close(echofd);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (echofd >= 0) {
|
||||
/* Echo output to another TTY */
|
||||
if (ch == 0x7F) {
|
||||
write(echofd, "\\DEL", 4);
|
||||
} else if (ch == 0x1B) {
|
||||
write(echofd, "\\ESC", 4);
|
||||
} else if (ch < 0x20) {
|
||||
temstr[1]= ch+'@';
|
||||
write(echofd, temstr, 2);
|
||||
} else {
|
||||
write(echofd, &ch, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (write(1, &ch, 1) != 1) {
|
||||
fprintf(stderr, "Error in writing to parent STDOUT\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
if (ioctl(1, I_FLUSH, FLUSHRW) == -1) {
|
||||
fprintf(stderr, "Error return from ioctl\n");
|
||||
exit(-1);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (pollCode != 0) {
|
||||
fprintf(stderr, "Error return from poll\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/* Close PTY */
|
||||
pty_close(&ptyStruc);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* sends raw terminal input/output to a shell through a pipe */
|
||||
void pipeTest(int argc, char *argv[])
|
||||
{
|
||||
struct pollfd pollFD[2];
|
||||
nfds_t nfds = 2;
|
||||
pid_t child_pid = -1; /* child process id */
|
||||
|
||||
unsigned char ch;
|
||||
int pipeFD[2], pipeIN, pipeOUT, procIN, procOUT;
|
||||
int pollCode;
|
||||
ssize_t n_read, n_written;
|
||||
|
||||
char temstr[3] = "^@";
|
||||
|
||||
/* Create process input pipe (assumed unidirectional) */
|
||||
if (pipe(pipeFD) == -1) {
|
||||
fprintf(stderr, "Input pipe creation failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"Created input pipe: %d %d\n", pipeFD[0], pipeFD[1]);
|
||||
#endif
|
||||
procIN = pipeFD[0];
|
||||
pipeIN = pipeFD[1];
|
||||
|
||||
/* Create process output pipe (assumed unidirectional) */
|
||||
if (pipe(pipeFD) == -1) {
|
||||
fprintf(stderr, "Output pipe creation failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"Created output pipe: %d %d\n", pipeFD[0], pipeFD[1]);
|
||||
#endif
|
||||
pipeOUT = pipeFD[0];
|
||||
procOUT = pipeFD[1];
|
||||
|
||||
/* Fork a child process */
|
||||
child_pid = fork();
|
||||
if (child_pid < 0) {
|
||||
fprintf(stderr, "Fork failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Fork child process %d\n", child_pid);
|
||||
#endif
|
||||
|
||||
if (child_pid == 0) {
|
||||
/* Child process */
|
||||
|
||||
if (dup2(procIN, 0) == -1) {
|
||||
fprintf(stderr, "Dup2 failed for stdin of child\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (dup2(procOUT, 1) == -1) {
|
||||
fprintf(stderr, "Dup2 failed for stdout of child\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
execvp(argv[0], argv);
|
||||
fprintf(stderr, "Exec failed for command %s\n", argv[0]);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/* Set up polling to read from parent STDIN and child STDOUT */
|
||||
pollFD[0].fd = 0;
|
||||
pollFD[0].events = POLLIN;
|
||||
pollFD[1].fd = pipeOUT;
|
||||
pollFD[1].events = POLLIN;
|
||||
|
||||
while ( (pollCode=poll(pollFD,nfds,-1)) >= 0) {
|
||||
|
||||
if (pollFD[0].revents != 0) {
|
||||
/* Read character from parent STDIN and write to child STDIN */
|
||||
ch = getchar();
|
||||
|
||||
/* Exit poll loop if a null (Control-@) is read */
|
||||
if (ch == 0) break;
|
||||
|
||||
if (write(pipeIN, &ch, 1) != 1) {
|
||||
fprintf(stderr, "Error in writing to child STDIN\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (pollFD[1].revents != 0) {
|
||||
/* Read character from child STDOUT and write to parent STDOUT */
|
||||
|
||||
if ( (n_read=read(pipeOUT, &ch, 1)) < 0) {
|
||||
fprintf(stderr, "Error in reading from child STDOUT\n");
|
||||
if (echofd >= 0) close(echofd);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (n_read == 0) { /* End of file */
|
||||
if (echofd >= 0) close(echofd);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (echofd >= 0) {
|
||||
/* Echo output to another TTY */
|
||||
if (ch == 0x7F) {
|
||||
write(echofd, "\\DEL", 4);
|
||||
} else if (ch == 0x1B) {
|
||||
write(echofd, "\\ESC", 4);
|
||||
} else if (ch < 0x20) {
|
||||
temstr[1]= ch+'@';
|
||||
write(echofd, temstr, 2);
|
||||
} else {
|
||||
write(echofd, &ch, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (write(1, &ch, 1) != 1) {
|
||||
fprintf(stderr, "Error in writing to parent STDOUT\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
if (ioctl(1, I_FLUSH, FLUSHRW) == -1) {
|
||||
fprintf(stderr, "Error return from ioctl\n");
|
||||
exit(-1);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (kill(child_pid, SIGKILL) == -1) {
|
||||
fprintf(stderr, "Error return from kill\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (pollCode != 0) {
|
||||
fprintf(stderr, "Error return from poll\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/* Close pipes (assumed unidirectional) */
|
||||
close(pipeIN);
|
||||
close(pipeOUT);
|
||||
close(procIN);
|
||||
close(procOUT);
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
#!/bin/csh
|
||||
# makemake: Dumb script to make Makefile from Makefile.in
|
||||
# (recursively, if -r is specified)
|
||||
# Usage: makemake [-r]
|
||||
|
||||
if ($# == 0) then
|
||||
set makelist = (./Makefile.in)
|
||||
else
|
||||
set makelist = (`find . -name Makefile.in -print`)
|
||||
endif
|
||||
|
||||
foreach makefile ($makelist)
|
||||
set dir=${makefile:h}
|
||||
pushd $dir
|
||||
|
||||
set wd=`pwd`
|
||||
echo $wd
|
||||
|
||||
set top_srcdir = ""
|
||||
while (${wd:t} != "mozilla")
|
||||
if ("$top_srcdir" == "") then
|
||||
set top_srcdir = ".."
|
||||
else
|
||||
set top_srcdir = "../$top_srcdir"
|
||||
endif
|
||||
set wd=${wd:h}
|
||||
end
|
||||
|
||||
/bin/cp Makefile.in Makefile
|
||||
globsub @srcdir@ @srcdir@ . Makefile
|
||||
globsub @top_srcdir@ @top_srcdir@ $top_srcdir Makefile
|
||||
|
||||
popd
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
Makefile
|
|
@ -0,0 +1,45 @@
|
|||
/* DocStream.c: Display complete HTML document using IFRAME */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char ch;
|
||||
|
||||
/* XMLTerm escape sequence signalling start of a HTML document */
|
||||
printf("\033{0;1S\007");
|
||||
|
||||
printf(" <HTML><BODY> \
|
||||
<FORM> \
|
||||
<IMG align=center src='chrome://navigator/skin/animthrob_single.gif'> \
|
||||
<B>Please click a button</B> <BR> \
|
||||
<INPUT ID='button-b#' TYPE=button VALUE='Bold' \
|
||||
onClick=\"return clickXMLTerm('sendln','#','b')\"> \
|
||||
<INPUT ID='button-e#' TYPE=button VALUE='Emphasis' \
|
||||
onClick=\"return clickXMLTerm('sendln',#,'e')\"> \
|
||||
<INPUT ID='button-q#' TYPE=button VALUE='Quit' \
|
||||
onClick=\"return clickXMLTerm('sendln',#,'q')\"> \
|
||||
<BR></FORM> \
|
||||
</BODY></HTML>");
|
||||
|
||||
/* XMLTerm escape sequence signalling end of stream */
|
||||
printf("%c", '\0');
|
||||
|
||||
while((ch = getchar())){ /* Poll for data generated by button click events */
|
||||
switch (ch) {
|
||||
case 'b':
|
||||
printf("\033{S\007<B>Hello World!</B><BR> %c", '\0');
|
||||
break;
|
||||
case 'e':
|
||||
printf("\033{S\007<EM>Hello World!</EM><BR> %c", '\0');
|
||||
break;
|
||||
case 'q':
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/* HelloWorld.c: Simple demo program for "pagelets" */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char ch;
|
||||
printf("\033{S\007"); /* XMLTerm escape sequence signalling start of HTML */
|
||||
|
||||
printf("<FORM> \
|
||||
<IMG align=center src='chrome://navigator/skin/animthrob_single.gif'> \
|
||||
<B>Please click a button</B> <BR> \
|
||||
<INPUT ID='button-b#' TYPE=button VALUE='Bold' \
|
||||
onClick=\"return clickXMLTerm('sendln','#','b')\"> \
|
||||
<INPUT ID='button-e#' TYPE=button VALUE='Emphasis' \
|
||||
onClick=\"return clickXMLTerm('sendln',#,'e')\"> \
|
||||
<INPUT ID='button-q#' TYPE=button VALUE='Quit' \
|
||||
onClick=\"return clickXMLTerm('sendln',#,'q')\"> \
|
||||
<BR></FORM>");
|
||||
|
||||
printf("%c", '\0'); /* XMLTerm escape sequence signalling end of HTML */
|
||||
|
||||
while((ch = getchar())){ /* Poll for data generated by button click events */
|
||||
switch (ch) {
|
||||
case 'b':
|
||||
printf("\033{S\007<B>Hello World!</B><BR> %c", '\0');
|
||||
break;
|
||||
case 'e':
|
||||
printf("\033{S\007<EM>Hello World!</EM><BR> %c", '\0');
|
||||
break;
|
||||
case 'q':
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
#!gmake
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# makefile for xmlterm/tests directory
|
||||
|
||||
ifdef STAND_ALONE
|
||||
DEPTH = ..
|
||||
topsrcdir = ..
|
||||
srcdir = .
|
||||
include $(topsrcdir)/config/autoconf.mk
|
||||
else
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
endif
|
||||
|
||||
# Debug option
|
||||
DEBUG = 1
|
||||
|
||||
# C Sources
|
||||
CSRCS = escape.c teststream.c HelloWorld.c DocStream.c
|
||||
|
||||
# Program
|
||||
SIMPLE_PROGRAMS = escape teststream HelloWorld DocStream
|
||||
|
||||
# Defines
|
||||
DEFINES =
|
||||
|
||||
# Libraries to be linked
|
||||
LIBS =
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include ../config/xmlterm_config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,56 @@
|
|||
/* escape.c: Generates XMLterm/LineTerm escape sequences */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int nparam, j;
|
||||
char *param1, *param2, *param3, *code, *sparam;
|
||||
|
||||
param1 = NULL;
|
||||
param2 = NULL;
|
||||
param3 = NULL;
|
||||
code = NULL;
|
||||
sparam = "";
|
||||
nparam = 0;
|
||||
|
||||
for (j=1; j<argc; j++) {
|
||||
if ((*argv[j] >= '0') && (*argv[j] <= '9')) {
|
||||
if (j == 1) {
|
||||
param1 = argv[j];
|
||||
nparam = 1;
|
||||
} else if (j == 2) {
|
||||
param2 = argv[j];
|
||||
nparam = 2;
|
||||
} else if (j == 3) {
|
||||
param3 = argv[j];
|
||||
nparam = 3;
|
||||
}
|
||||
} else if (code == NULL) {
|
||||
code = argv[j];
|
||||
} else {
|
||||
sparam = argv[j];
|
||||
}
|
||||
}
|
||||
|
||||
if (code == NULL) {
|
||||
fprintf(stderr, "Usage: %s [<param1> [<param2> [<param3>]]] <code-character> [<string-param>] \n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (nparam == 0) {
|
||||
fprintf(stderr, "ESC{%s%sBEL\n", code, sparam);
|
||||
fprintf(stdout, "\033{%s%s\007", code, sparam);
|
||||
} else if (nparam == 1) {
|
||||
fprintf(stderr, "ESC{%s%s%sBEL\n", param1, code, sparam);
|
||||
fprintf(stdout, "\033{%s%s%s\007", param1, code, sparam);
|
||||
} else if (nparam == 2) {
|
||||
fprintf(stderr, "ESC{%s;%s%s%sBEL\n", param1, param2, code, sparam);
|
||||
fprintf(stdout, "\033{%s;%s%s%s\007", param1, param2, code, sparam);
|
||||
} else {
|
||||
fprintf(stderr, "ESC{%s;%s;%s%s%sBEL\n", param1, param2, param3, code, sparam);
|
||||
fprintf(stdout, "\033{%s;%s;%s%s%s\007", param1, param2, param3, code, sparam);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/* teststream.c: Test driver to generate escaped stream data */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage: %s <data-string> [<terminator-string>]\n",argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (argc > 2) {
|
||||
/* fprintf(stderr, "{ESCS%sBEL%s%s", argv[2], argv[1], argv[2]); */
|
||||
fprintf(stdout, "\033{S%s\007%s%s", argv[2], argv[1], argv[2]);
|
||||
|
||||
} else {
|
||||
fprintf(stdout, "\033{S\007%s%c", argv[1], '\0');
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
#!/usr/bin/perl
|
||||
# xls: an XMLterm wrapper for the UNIX "ls" command
|
||||
# Usage: xls [-c|--cols] [-h|help] [-i||--iconic] [-w|--window]
|
||||
|
||||
use Cwd;
|
||||
use Getopt::Long;
|
||||
|
||||
Getopt::Long::config('bundling');
|
||||
|
||||
$options = "@ARGV";
|
||||
|
||||
&GetOptions("cols|c=i", "help|h!", "iconic|i!", "window|w!");
|
||||
|
||||
if ($opt_help) {
|
||||
print "Usage: xls [-c|--cols] [-i|--iconic] [-w|--window]\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
# Icon details
|
||||
#$imgdir="chrome://xmlterm/skin/default/images"
|
||||
$imgdir = "file:/usr/share/pixmaps/mc";
|
||||
|
||||
($img{'directory'}, $img{'executable'}, $img{'plainfile'}) =
|
||||
('i-directory.png', 'i-executable.png', 'i-regular.png');
|
||||
|
||||
$ncols = 5;
|
||||
$ncols = $opt_cols if ($opt_cols);
|
||||
|
||||
print "\e{S\a"; # HTML stream escape sequence
|
||||
print "<TABLE FRAME=none BORDER=0>";
|
||||
print "<COLGROUP COLSPAN=$ncols WIDTH=1*>";
|
||||
|
||||
$dir = cwd();
|
||||
$rowimg = "";
|
||||
$rowtxt = "";
|
||||
$nfile = 0;
|
||||
foreach $file (glob("$dir/*")) { # for each file in current directory
|
||||
if (-d $file) { # directory
|
||||
$filetype = "directory";
|
||||
$sendtxt = "cd $file; xls $options";
|
||||
$sendimg = "file:/usr/share/pixmaps/mc/i-directory.png";
|
||||
|
||||
} elsif (-x $file) { # executable
|
||||
$filetype = "executable";
|
||||
$sendtxt = "$file";
|
||||
|
||||
} else { # plain file
|
||||
$filetype = "plainfile";
|
||||
$sendtxt = "";
|
||||
}
|
||||
|
||||
@comps = split(m./.,$file);
|
||||
$tail = $comps[$#comps]; # file name
|
||||
|
||||
if ($opt_window) {
|
||||
$sendcmd = "createln";
|
||||
} else {
|
||||
$sendcmd = "sendln";
|
||||
}
|
||||
|
||||
$clickcmd = qq%onclick="return clickXMLTerm('$sendcmd',-1,'$sendtxt')"%;
|
||||
|
||||
$rowimg .= "<TD><IMG SRC='$imgdir/$img{$filetype}' $clickcmd>";
|
||||
$rowtxt .= "<TD><SPAN CLASS='$filetype' $clickcmd>";
|
||||
$rowtxt .= "$tail</SPAN>";
|
||||
$nfile++;
|
||||
|
||||
if (($nfile % $ncols) == 0) { # print complete table row
|
||||
print "<TR>$rowimg" if ($opt_iconic) ;
|
||||
print "<TR>$rowtxt";
|
||||
$rowimg = "";
|
||||
$rowtxt = "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (length($rowtxt) != 0) {
|
||||
print "<TR>$rowimg" if ($opt_iconic) ;
|
||||
print "<TR>$rowtxt";
|
||||
}
|
||||
|
||||
print "</TABLE>";
|
||||
print "\000"; # Terminate HTML stream
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
#!/bin/csh
|
||||
# xls.csh: a C-shell XMLterm wrapper for the UNIX "ls" command
|
||||
# Usage: xls.csh [-i] [-x]
|
||||
|
||||
set files=(`/bin/ls -d $cwd/*`)
|
||||
set ncols=4
|
||||
|
||||
##set echocmd="/usr/bin/echo"
|
||||
set echocmd="/bin/echo -e"
|
||||
|
||||
set iconic=0
|
||||
set create=0
|
||||
|
||||
set options=""
|
||||
foreach arg ($*)
|
||||
switch ($arg)
|
||||
case "-i":
|
||||
set iconic=1
|
||||
set options=($options $arg)
|
||||
breaksw
|
||||
case "-c":
|
||||
set create=1
|
||||
set options=($options $arg)
|
||||
breaksw
|
||||
endsw
|
||||
end
|
||||
|
||||
$echocmd '\033{S\007\c'
|
||||
$echocmd '<TABLE FRAME=none BORDER=0>'
|
||||
$echocmd "<COLGROUP COLSPAN=$ncols WIDTH=1*>"
|
||||
|
||||
set rowimg=""
|
||||
set rowtxt=""
|
||||
set nfile=0
|
||||
foreach file ($files)
|
||||
if (-d $file) then #directory
|
||||
set filetype="directory"
|
||||
set sendtxt="cd $file; xls $options"
|
||||
set sendimg="file:/usr/share/pixmaps/mc/i-directory.png"
|
||||
# set sendimg="chrome://xmlterm/skin/default/images/ficon3.gif"
|
||||
else if (-x $file) then #executable
|
||||
set filetype="executable"
|
||||
set sendtxt="$file"
|
||||
set sendimg="file:/usr/share/pixmaps/mc/i-executable.png"
|
||||
else #plain file
|
||||
set filetype="plainfile"
|
||||
set sendtxt=""
|
||||
set sendimg="file:/usr/share/pixmaps/mc/i-regular.png"
|
||||
endif
|
||||
|
||||
set tail=${file:t}
|
||||
|
||||
if ($create) then
|
||||
set cmd="createln"
|
||||
else
|
||||
set cmd="sendln"
|
||||
endif
|
||||
set clickcmd="onclick="'"'"return clickXMLTerm('$cmd',-1,'$sendtxt')"'"'
|
||||
|
||||
set rowimg="${rowimg}<TD><IMG SRC='$sendimg' $clickcmd>"
|
||||
set rowtxt="${rowtxt}<TD><SPAN CLASS='$filetype' $clickcmd>"
|
||||
set rowtxt="${rowtxt}$tail<SPAN/>"
|
||||
@ nfile++
|
||||
|
||||
if (($nfile % $ncols) == 0) then
|
||||
if ($iconic) $echocmd "<TR>$rowimg"
|
||||
$echocmd "<TR>$rowtxt"
|
||||
set rowimg=""
|
||||
set rowtxt=""
|
||||
endif
|
||||
|
||||
end
|
||||
|
||||
if ("$rowtxt" != "") then
|
||||
if ($iconic) $echocmd "<TR>$rowimg"
|
||||
$echocmd "<TR>$rowtxt"
|
||||
endif
|
||||
|
||||
$echocmd '</TABLE>'
|
||||
$echocmd '\000\c'
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
#!gmake
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# makefile for xmlterm/ui directory
|
||||
|
||||
ifdef STAND_ALONE
|
||||
DEPTH = .
|
||||
topsrcdir = .
|
||||
VPATH = .
|
||||
srcdir = .
|
||||
include $(topsrcdir)/config/autoconf.mk
|
||||
else
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
srcdir = @srcdir@
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
endif
|
||||
|
||||
DIRS = content skin
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include ../config/xmlterm_config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
@ -0,0 +1 @@
|
|||
ui --- User Interface stuff for XMLterm
|
|
@ -0,0 +1,61 @@
|
|||
#!gmake
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# makefile for xmlterm/ui/content directory
|
||||
|
||||
ifdef STAND_ALONE
|
||||
DEPTH = .
|
||||
topsrcdir = .
|
||||
VPATH = .
|
||||
srcdir = .
|
||||
include $(topsrcdir)/config/autoconf.mk
|
||||
else
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
srcdir = @srcdir@
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include ../../config/xmlterm_config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
EXPORT_RESOURCE_CONTENT = \
|
||||
$(srcdir)/xmlterm.html \
|
||||
$(NULL)
|
||||
|
||||
install::
|
||||
$(INSTALL) $(EXPORT_RESOURCE_CONTENT) $(DIST)/bin/chrome/xmlterm/content/default
|
|
@ -0,0 +1,5 @@
|
|||
content --- XUL, Javascript, and HTML for user interface
|
||||
|
||||
xmlterm.html XMLterm startup file containing HTML and Javascript
|
||||
Uses mozIXMLTermShell to create XMLterm
|
||||
Uses ../skin/xmlterm.css for stylesheets
|
|
@ -0,0 +1,239 @@
|
|||
<!-- xmlterm.html: XMLterm startup page -->
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>XMLterm Test Page</TITLE>
|
||||
|
||||
<LINK TITLE="DefaultStyle" REL="stylesheet" TYPE="text/css"
|
||||
HREF="chrome://xmlterm/skin/xmlterm.css">
|
||||
|
||||
<SCRIPT language="JavaScript">
|
||||
|
||||
// Control display of all output elements
|
||||
function DisplayAllOutput(flag) {
|
||||
var outputElements = document.getElementsByName("output");
|
||||
for (i=0; i<outputElements.length; i++) {
|
||||
var outputElement = outputElements[i];
|
||||
outputElement.style.display = (flag) ? "block" : "none";
|
||||
}
|
||||
|
||||
var promptElements = document.getElementsByName("prompt");
|
||||
for (i=0; i<promptElements.length; i++) {
|
||||
promptElement = promptElements[i];
|
||||
promptElement.style.setProperty("text-decoration",
|
||||
(flag) ? "none" : "underline", "")
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
// Click handler
|
||||
function clickXMLTerm(name, number, arg) {
|
||||
dump("clickXMLTerm("+name+","+number+","+arg+")\n");
|
||||
//dump("clickXMLTerm:document.cookie="+document.cookie+"\n");
|
||||
|
||||
if (name === "prompt") {
|
||||
var outputElement = document.getElementById("output"+number);
|
||||
var promptElement = document.getElementById("prompt"+number);
|
||||
//dump(promptElement.style.getPropertyValue("text-decoration"));
|
||||
|
||||
if (outputElement.style.display == "none") {
|
||||
outputElement.style.display = "block";
|
||||
promptElement.style.setProperty("text-decoration","none","");
|
||||
} else {
|
||||
outputElement.style.display = "none";
|
||||
promptElement.style.setProperty("text-decoration","underline","");
|
||||
}
|
||||
|
||||
} else if (name === "command") {
|
||||
var commandElement = document.getElementById(name+number);
|
||||
var command = commandElement.firstChild.data;
|
||||
dump("command = "+command+"\n\n");
|
||||
window.xmltermshell.SendText("\025"+command+"\n", document.cookie);
|
||||
|
||||
} else {
|
||||
|
||||
if ((number >= 0) &&
|
||||
(window.xmltermshell.currentEntryNumber != number)) {
|
||||
dump("NOT CURRENT COMMAND\n");
|
||||
return (false);
|
||||
}
|
||||
|
||||
|
||||
if (name == "directory") {
|
||||
var command = "ls: "+arg;
|
||||
dump("command = "+command+"\n\n");
|
||||
window.xmltermshell.SendText("\025"+command+"\n", document.cookie);
|
||||
|
||||
} else if (name == "executable") {
|
||||
var command = arg;
|
||||
dump("command = "+command+"\n\n");
|
||||
window.xmltermshell.SendText("\025"+command+"\n", document.cookie);
|
||||
|
||||
} else if (name == "send") {
|
||||
dump("send = "+arg+"\n");
|
||||
window.xmltermshell.SendText(arg, document.cookie);
|
||||
|
||||
} else if (name == "sendln") {
|
||||
dump("sendln = "+arg+"\n\n");
|
||||
window.xmltermshell.SendText("\025"+arg+"\n", document.cookie);
|
||||
|
||||
} else if (name == "createln") {
|
||||
dump("createln = "+arg+"\n\n");
|
||||
xmltermshell.NewXMLTermWindow(arg+"\n");
|
||||
}
|
||||
}
|
||||
|
||||
return (false);
|
||||
}
|
||||
|
||||
// Double Click handler
|
||||
function dblclickXMLTerm(name, number, arg) {
|
||||
dump("dblclickXMLTerm("+name+","+number+","+arg+")\n");
|
||||
return (false);
|
||||
}
|
||||
|
||||
// Set history buffer size
|
||||
function SetHistory() {
|
||||
var field = document.getElementById('HistoryValue');
|
||||
dump("SetHistory "+field.value+"\n");
|
||||
xmltermshell.history = field.value;
|
||||
field.value = xmltermshell.history;
|
||||
return (false);
|
||||
}
|
||||
|
||||
// Set prompt
|
||||
function SetPrompt() {
|
||||
var field = document.getElementById('PromptValue');
|
||||
dump("SetPrompt "+field.value+"\n");
|
||||
xmltermshell.prompt = field.value;
|
||||
return (false);
|
||||
}
|
||||
|
||||
// Create new XMLTerm window
|
||||
function CreateXMLTermWindow(firstcommand) {
|
||||
xmltermshell.NewXMLTermWindow(firstcommand);
|
||||
return (false);
|
||||
}
|
||||
|
||||
// onLoad event handler
|
||||
function LoadHandler() {
|
||||
dump("xmlterm: LoadHandler ... "+window.xmltermshell+"\n");
|
||||
|
||||
if (window.xmltermshell) {
|
||||
// XMLTerm already initialized
|
||||
return (false);
|
||||
}
|
||||
|
||||
dump("Trying to make an XMLTerm Shell through the component manager...\n");
|
||||
|
||||
var xmltshell = Components.classes["component://mozilla/xmlterm/xmltermshell"].createInstance();
|
||||
|
||||
dump("Interface xmltshell1 = " + xmltshell + "\n");
|
||||
|
||||
xmltshell = xmltshell.QueryInterface(Components.interfaces.mozIXMLTermShell);
|
||||
dump("Interface xmltshell2 = " + xmltshell + "\n");
|
||||
|
||||
if (!xmltshell) {
|
||||
dump("Failed to create XMLTerm shell\n");
|
||||
window.close();
|
||||
return;
|
||||
}
|
||||
|
||||
// Store the XMLTerm shell in the window
|
||||
window.xmltermshell = xmltshell;
|
||||
|
||||
// Content window same as current window
|
||||
var contentWindow = window;
|
||||
|
||||
// Initialize XMLTerm shell in content window with argvals
|
||||
window.xmltermshell.Init(contentWindow, "", "");
|
||||
|
||||
//dump("LoadHandler:"+document.cookie+"\n");
|
||||
|
||||
dump("contentWindow="+contentWindow+"\n");
|
||||
dump("document="+document+"\n");
|
||||
dump("documentElement="+document.documentElement+"\n");
|
||||
|
||||
// Set focus to appropriate frame
|
||||
contentWindow.focus();
|
||||
|
||||
//contentWindow.xmltermshell = xmltermshell;
|
||||
|
||||
//dump(contentWindow.xmltermshell);
|
||||
|
||||
return (false);
|
||||
|
||||
dump("[Main] "+window+"\n");
|
||||
dump(window.screenX+", "+window.screenY+"\n");
|
||||
dump(window.scrollX+", "+window.scrollY+"\n");
|
||||
dump(window.pageXOffset+", "+window.pageYOffset+"\n");
|
||||
|
||||
dump("IFRAME checks\n");
|
||||
var iframe = document.getElementById('iframe1');
|
||||
|
||||
dump("iframe="+iframe+"\n");
|
||||
|
||||
frames=document.frames;
|
||||
dump("frames="+frames+"\n");
|
||||
dump("frames.length="+frames.length+"\n");
|
||||
|
||||
framewin = frames[0];
|
||||
|
||||
dump("framewin="+framewin+"\n");
|
||||
dump("framewin.document="+framewin.document+"\n");
|
||||
|
||||
dump(framewin.screenX+", "+framewin.screenY+"\n");
|
||||
dump(framewin.scrollX+", "+framewin.scrollY+"\n");
|
||||
dump(framewin.pageXOffset+", "+framewin.pageYOffset+"\n");
|
||||
|
||||
var body = framewin.document.getElementsByTagName("BODY")[0];
|
||||
dump("body="+body+"\n");
|
||||
|
||||
var height= body.scrollHeight;
|
||||
dump("height="+height+"\n");
|
||||
|
||||
// iframe.height = 800;
|
||||
// iframe.width = 700;
|
||||
|
||||
// framewin.sizeToContent();
|
||||
|
||||
framewin.xmltshell = xmltshell;
|
||||
dump(framewin.xmltshell+"\n");
|
||||
|
||||
dump("xmlterm: LoadHandler completed\n");
|
||||
return (false);
|
||||
}
|
||||
|
||||
</SCRIPT>
|
||||
|
||||
</HEAD>
|
||||
|
||||
<BODY onLoad="return LoadHandler();">
|
||||
|
||||
<TABLE FRAME=none BORDER=0>
|
||||
<TBODY>
|
||||
<TR><TD ALIGN=center>
|
||||
<FORM NAME="XMLTERM form">
|
||||
<INPUT TYPE="button" VALUE="Show all output"
|
||||
onClick="return DisplayAllOutput(true);">
|
||||
<INPUT TYPE="button" VALUE="Hide all output"
|
||||
onClick="return DisplayAllOutput(false);">
|
||||
<INPUT TYPE="button" VALUE="New XMLterm"
|
||||
onClick="return CreateXMLTermWindow('');">
|
||||
<BR>
|
||||
History Buffer Size:
|
||||
<INPUT TYPE="text" ID="HistoryValue" VALUE="">
|
||||
<INPUT TYPE="button" VALUE="Set" onClick="return SetHistory();">
|
||||
</FORM>
|
||||
</TABLE>
|
||||
|
||||
<!--
|
||||
<IFRAME NAME="iframe1" SRC="file:///home/svn/xmlterm/doc/web/tem2.html"
|
||||
FRAMEBORDER=0 WIDTH="20" HEIGHT=60>
|
||||
</IFRAME>
|
||||
-->
|
||||
|
||||
<DIV CLASS="session" ID="session">
|
||||
</DIV>
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
|
@ -0,0 +1,66 @@
|
|||
#!gmake
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# makefile for xmlterm/ui/skin directory
|
||||
|
||||
ifdef STAND_ALONE
|
||||
DEPTH = .
|
||||
topsrcdir = .
|
||||
VPATH = .
|
||||
srcdir = .
|
||||
include $(topsrcdir)/config/autoconf.mk
|
||||
else
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
srcdir = @srcdir@
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include ../../config/xmlterm_config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
EXPORT_RESOURCE_SKIN = \
|
||||
$(srcdir)/xmlterm.css \
|
||||
$(NULL)
|
||||
|
||||
EXPORT_RESOURCE_TOOLBAR = \
|
||||
$(srcdir)/images/ficon.gif \
|
||||
$(NULL)
|
||||
|
||||
install::
|
||||
$(INSTALL) $(EXPORT_RESOURCE_SKIN) $(DIST)/bin/chrome/xmlterm/skin/default
|
||||
$(INSTALL) $(EXPORT_RESOURCE_TOOLBAR) $(DIST)/bin/chrome/xmlterm/skin/default/images
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче