Compare commits
47 Commits
tags/XPCOM
...
N2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
233427693e | ||
|
|
8a5d6cea8a | ||
|
|
060c6b2ea2 | ||
|
|
09b0cb9dac | ||
|
|
edba634cae | ||
|
|
a7365899d1 | ||
|
|
c3389b3323 | ||
|
|
718ec18100 | ||
|
|
7d190a8dd4 | ||
|
|
e1ebb3e092 | ||
|
|
59705f110a | ||
|
|
10d067c837 | ||
|
|
0995f00878 | ||
|
|
44c6ee7bd0 | ||
|
|
6b475c2062 | ||
|
|
6445d6fc19 | ||
|
|
504987c7f8 | ||
|
|
3c3c9de879 | ||
|
|
4fb4cdbaf9 | ||
|
|
6c56d63c2b | ||
|
|
6360bf628f | ||
|
|
17afc12ff5 | ||
|
|
d2c8923434 | ||
|
|
d962f6c931 | ||
|
|
c467d95fcc | ||
|
|
7d6ab18c04 | ||
|
|
2267821c34 | ||
|
|
f652521f1f | ||
|
|
4df60ddcca | ||
|
|
2a952c444d | ||
|
|
b1d8f9e682 | ||
|
|
d2229d1d13 | ||
|
|
1165868b3c | ||
|
|
f74ec1b6ec | ||
|
|
2946bb22b6 | ||
|
|
071e3adc48 | ||
|
|
46e56a76cd | ||
|
|
7a5a6134fc | ||
|
|
57dafff70d | ||
|
|
34420a2e9d | ||
|
|
81aeb86448 | ||
|
|
5586abebc4 | ||
|
|
76c32f445f | ||
|
|
ca07152e56 | ||
|
|
aa16a83c74 | ||
|
|
df7795dbf4 | ||
|
|
74ce2dfd5d |
@@ -26,44 +26,45 @@ include $(DEPTH)/config/autoconf.mk
|
||||
# nglayout test program. The order is important.
|
||||
DIRS = \
|
||||
config \
|
||||
build \
|
||||
dbm \
|
||||
nsprpub \
|
||||
$(NULL)
|
||||
|
||||
ifndef MOZ_NATIVE_NSPR
|
||||
DIRS += $(topsrcdir)/nsprpub
|
||||
ifndef MOZ_NATIVE_JPEG
|
||||
DIRS += \
|
||||
jpeg \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
DIRS += \
|
||||
dbm \
|
||||
modules/libreg \
|
||||
xpcom \
|
||||
$(NULL)
|
||||
|
||||
ifndef MOZ_NATIVE_ZLIB
|
||||
DIRS += modules/zlib
|
||||
endif
|
||||
|
||||
ifndef MOZ_NATIVE_JPEG
|
||||
DIRS += jpeg
|
||||
DIRS += \
|
||||
modules/zlib \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
DIRS += \
|
||||
modules/libutil \
|
||||
base \
|
||||
intl \
|
||||
sun-java \
|
||||
nav-java \
|
||||
js \
|
||||
modules/security/freenav \
|
||||
modules/libpref \
|
||||
modules/libimg \
|
||||
modules/oji \
|
||||
modules/oji \
|
||||
modules/plugin \
|
||||
modules/libjar \
|
||||
base \
|
||||
caps \
|
||||
lib/xp \
|
||||
lib/libpwcac \
|
||||
network \
|
||||
lib/liblayer/include \
|
||||
htmlparser \
|
||||
expat \
|
||||
gfx \
|
||||
dom \
|
||||
view \
|
||||
@@ -72,19 +73,12 @@ DIRS += \
|
||||
rdf \
|
||||
webshell \
|
||||
editor \
|
||||
silentdl \
|
||||
xpinstall \
|
||||
sun-java \
|
||||
profile \
|
||||
$(NULL)
|
||||
silentdl
|
||||
|
||||
ifdef MOZ_BUILD_XPFE
|
||||
DIRS += xpfe extensions
|
||||
endif
|
||||
|
||||
ifdef MOZ_MAIL_NEWS
|
||||
DIRS += mailnews
|
||||
endif
|
||||
DIRS += xpfe
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
@@ -99,3 +93,4 @@ real_install: install
|
||||
real_clobber: clobber
|
||||
|
||||
real_depend: depend
|
||||
|
||||
|
||||
5
mozilla/aclocal.m4
vendored
5
mozilla/aclocal.m4
vendored
@@ -3,8 +3,5 @@ dnl Local autoconf macros used with mozilla
|
||||
dnl The contents of this file are under the Public Domain.
|
||||
dnl
|
||||
|
||||
builtin(include, build/autoconf/glib.m4)dnl
|
||||
builtin(include, build/autoconf/gtk.m4)dnl
|
||||
builtin(include, build/autoconf/libIDL.m4)dnl
|
||||
builtin(include, build/autoconf/altoptions.m4)dnl
|
||||
builtin(include, gtk.m4)dnl
|
||||
|
||||
|
||||
@@ -1,451 +0,0 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1999 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
|
||||
# allmakefiles.sh - List of all makefiles.
|
||||
# Appends the list of makefiles to the variable, MAKEFILES.
|
||||
# There is no need to rerun autoconf after adding makefiles.
|
||||
# You only need to run configure.
|
||||
#
|
||||
# Unused makefiles may be commented out with '#'.
|
||||
# ('#' must be the first character on the line).
|
||||
|
||||
# add_makefiles - Shell function to add makefiles to MAKEFILES
|
||||
add_makefiles() {
|
||||
while read line; do
|
||||
case $line in
|
||||
\#*|dnl*) ;;
|
||||
*) MAKEFILES="$MAKEFILES $line" ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
if [ -z "${srcdir}" ]; then
|
||||
srcdir=.
|
||||
fi
|
||||
|
||||
add_makefiles <<END_NGMAKEFILES
|
||||
Makefile
|
||||
base/Makefile
|
||||
base/public/Makefile
|
||||
base/src/Makefile
|
||||
base/src/gtk/Makefile
|
||||
base/src/motif/Makefile
|
||||
base/src/photon/Makefile
|
||||
base/src/rhapsody/Makefile
|
||||
base/src/xlib/Makefile
|
||||
base/tests/Makefile
|
||||
build/Makefile
|
||||
build/unix/Makefile
|
||||
build/unix/nspr_my_config.mk
|
||||
build/unix/nspr_my_overrides.mk
|
||||
build/package/rpm/mozilla.spec
|
||||
build/package/rpm/nspr-pthreads.spec
|
||||
config/Makefile
|
||||
config/autoconf.mk
|
||||
config/mkdepend/Makefile
|
||||
config/mkdetect/Makefile
|
||||
dbm/Makefile
|
||||
dbm/include/Makefile
|
||||
dbm/src/Makefile
|
||||
dbm/tests/Makefile
|
||||
dom/Makefile
|
||||
dom/public/Makefile
|
||||
dom/public/base/Makefile
|
||||
dom/public/coreDom/Makefile
|
||||
dom/public/coreEvents/Makefile
|
||||
dom/public/css/Makefile
|
||||
dom/public/events/Makefile
|
||||
dom/public/range/Makefile
|
||||
dom/public/html/Makefile
|
||||
dom/src/Makefile
|
||||
dom/src/base/Makefile
|
||||
dom/src/build/Makefile
|
||||
dom/src/coreDOM/Makefile
|
||||
dom/src/css/Makefile
|
||||
dom/src/events/Makefile
|
||||
dom/src/range/Makefile
|
||||
dom/src/html/Makefile
|
||||
dom/src/jsurl/Makefile
|
||||
dom/tools/Makefile
|
||||
editor/Makefile
|
||||
editor/public/Makefile
|
||||
expat/Makefile
|
||||
expat/xmlparse/Makefile
|
||||
expat/xmltok/Makefile
|
||||
extensions/Makefile
|
||||
extensions/wallet/Makefile
|
||||
extensions/wallet/public/Makefile
|
||||
extensions/wallet/src/Makefile
|
||||
# extensions/wallet/module/Makefile
|
||||
extensions/pics/Makefile
|
||||
extensions/pics/public/Makefile
|
||||
extensions/pics/src/Makefile
|
||||
extensions/pics/tests/Makefile
|
||||
gfx/Makefile
|
||||
gfx/public/Makefile
|
||||
gfx/src/Makefile
|
||||
gfx/src/gtk/Makefile
|
||||
gfx/src/ps/Makefile
|
||||
gfx/src/motif/Makefile
|
||||
gfx/src/photon/Makefile
|
||||
gfx/src/rhapsody/Makefile
|
||||
gfx/src/xlib/Makefile
|
||||
gfx/tests/Makefile
|
||||
htmlparser/Makefile
|
||||
htmlparser/robot/Makefile
|
||||
htmlparser/src/Makefile
|
||||
htmlparser/tests/Makefile
|
||||
htmlparser/tests/grabpage/Makefile
|
||||
htmlparser/tests/logparse/Makefile
|
||||
include/Makefile
|
||||
intl/Makefile
|
||||
intl/chardet/Makefile
|
||||
intl/chardet/public/Makefile
|
||||
intl/chardet/src/Makefile
|
||||
intl/uconv/Makefile
|
||||
intl/uconv/public/Makefile
|
||||
intl/uconv/src/Makefile
|
||||
intl/uconv/tests/Makefile
|
||||
intl/uconv/ucvja/Makefile
|
||||
intl/uconv/ucvlatin/Makefile
|
||||
intl/uconv/ucvja2/Makefile
|
||||
intl/uconv/ucvcn/Makefile
|
||||
intl/locale/Makefile
|
||||
intl/locale/public/Makefile
|
||||
intl/locale/src/Makefile
|
||||
intl/locale/src/unix/Makefile
|
||||
intl/locale/tests/Makefile
|
||||
intl/lwbrk/Makefile
|
||||
intl/lwbrk/src/Makefile
|
||||
intl/lwbrk/public/Makefile
|
||||
intl/lwbrk/tests/Makefile
|
||||
intl/unicharutil/Makefile
|
||||
intl/unicharutil/src/Makefile
|
||||
intl/unicharutil/public/Makefile
|
||||
intl/unicharutil/tests/Makefile
|
||||
intl/unicharutil/tools/Makefile
|
||||
intl/strres/Makefile
|
||||
intl/strres/public/Makefile
|
||||
intl/strres/src/Makefile
|
||||
intl/strres/tests/Makefile
|
||||
jpeg/Makefile
|
||||
js/Makefile
|
||||
#js/jsd/Makefile
|
||||
#js/jsd/classes/Makefile
|
||||
js/src/Makefile
|
||||
js/src/fdlibm/Makefile
|
||||
js/src/liveconnect/Makefile
|
||||
js/src/liveconnect/classes/Makefile
|
||||
# js/src/xpcom/Makefile
|
||||
js/src/xpconnect/Makefile
|
||||
js/src/xpconnect/public/Makefile
|
||||
js/src/xpconnect/idl/Makefile
|
||||
js/src/xpconnect/shell/Makefile
|
||||
js/src/xpconnect/src/Makefile
|
||||
js/src/xpconnect/tests/Makefile
|
||||
js/src/xpconnect/tests/components/Makefile
|
||||
js/src/xpconnect/shell/Makefile
|
||||
# js/src/xpconnect/md/Makefile
|
||||
# js/src/xpconnect/md/unix/Makefile
|
||||
# js/src/xpconnect/test/Makefile
|
||||
layout/Makefile
|
||||
layout/base/Makefile
|
||||
layout/base/public/Makefile
|
||||
layout/base/src/Makefile
|
||||
layout/base/tests/Makefile
|
||||
layout/build/Makefile
|
||||
layout/events/Makefile
|
||||
layout/events/public/Makefile
|
||||
layout/events/src/Makefile
|
||||
layout/html/Makefile
|
||||
layout/html/base/Makefile
|
||||
layout/html/base/src/Makefile
|
||||
layout/html/content/Makefile
|
||||
layout/html/content/public/Makefile
|
||||
layout/html/content/src/Makefile
|
||||
layout/html/document/Makefile
|
||||
layout/html/document/public/Makefile
|
||||
layout/html/document/src/Makefile
|
||||
layout/html/forms/Makefile
|
||||
layout/html/forms/public/Makefile
|
||||
layout/html/forms/src/Makefile
|
||||
layout/html/style/Makefile
|
||||
layout/html/style/public/Makefile
|
||||
layout/html/style/src/Makefile
|
||||
layout/html/table/Makefile
|
||||
layout/html/table/public/Makefile
|
||||
layout/html/table/src/Makefile
|
||||
layout/html/tests/Makefile
|
||||
layout/tools/Makefile
|
||||
layout/xml/Makefile
|
||||
layout/xml/content/Makefile
|
||||
layout/xml/content/public/Makefile
|
||||
layout/xml/content/src/Makefile
|
||||
layout/xml/document/Makefile
|
||||
layout/xml/document/public/Makefile
|
||||
layout/xml/document/src/Makefile
|
||||
layout/xul/Makefile
|
||||
layout/xul/base/Makefile
|
||||
layout/xul/base/src/Makefile
|
||||
layout/xul/content/Makefile
|
||||
layout/xul/content/src/Makefile
|
||||
# lib/liblayer/Makefile
|
||||
# lib/liblayer/include/Makefile
|
||||
# lib/liblayer/src/Makefile
|
||||
lib/libpwcac/Makefile
|
||||
lib/xp/Makefile
|
||||
modules/libimg/Makefile
|
||||
# modules/libimg/classes/Makefile
|
||||
# modules/libimg/classes/netscape/Makefile
|
||||
# modules/libimg/classes/netscape/libimg/Makefile
|
||||
modules/libimg/png/Makefile
|
||||
modules/libimg/public/Makefile
|
||||
modules/libimg/public_com/Makefile
|
||||
modules/libimg/src/Makefile
|
||||
modules/libimg/gifcom/Makefile
|
||||
modules/libimg/jpgcom/Makefile
|
||||
modules/libimg/pngcom/Makefile
|
||||
modules/libjar/Makefile
|
||||
modules/libpref/Makefile
|
||||
modules/libpref/admin/Makefile
|
||||
modules/libpref/l10n/Makefile
|
||||
modules/libpref/public/Makefile
|
||||
modules/libpref/src/Makefile
|
||||
modules/libreg/Makefile
|
||||
modules/libreg/include/Makefile
|
||||
modules/libreg/src/Makefile
|
||||
modules/libutil/Makefile
|
||||
modules/libutil/public/Makefile
|
||||
modules/libutil/src/Makefile
|
||||
modules/oji/Makefile
|
||||
modules/oji/public/Makefile
|
||||
modules/oji/src/Makefile
|
||||
modules/plugin/Makefile
|
||||
modules/plugin/nglsrc/Makefile
|
||||
modules/plugin/public/Makefile
|
||||
modules/plugin/src/Makefile
|
||||
modules/plugin/test/Makefile
|
||||
modules/security/freenav/Makefile
|
||||
modules/zlib/Makefile
|
||||
modules/zlib/src/Makefile
|
||||
nav-java/Makefile
|
||||
nav-java/stubs/Makefile
|
||||
nav-java/stubs/include/Makefile
|
||||
nav-java/stubs/jri/Makefile
|
||||
nav-java/stubs/src/Makefile
|
||||
network/Makefile
|
||||
network/cache/Makefile
|
||||
network/cache/nu/Makefile
|
||||
network/cache/nu/include/Makefile
|
||||
network/cache/nu/public/Makefile
|
||||
network/cache/nu/src/Makefile
|
||||
network/cache/nu/tests/Makefile
|
||||
network/cache/nu/tests/fftest/Makefile
|
||||
network/client/Makefile
|
||||
network/cnvts/Makefile
|
||||
network/cstream/Makefile
|
||||
network/main/Makefile
|
||||
network/mimetype/Makefile
|
||||
network/public/Makefile
|
||||
network/module/Makefile
|
||||
network/module/tests/Makefile
|
||||
network/protocol/Makefile
|
||||
network/protocol/about/Makefile
|
||||
network/protocol/callback/Makefile
|
||||
network/protocol/dataurl/Makefile
|
||||
network/protocol/file/Makefile
|
||||
network/protocol/ftp/Makefile
|
||||
network/protocol/gopher/Makefile
|
||||
network/protocol/http/Makefile
|
||||
network/protocol/js/Makefile
|
||||
network/protocol/ldap/Makefile
|
||||
network/protocol/marimba/Makefile
|
||||
network/protocol/remote/Makefile
|
||||
network/protocol/sockstub/Makefile
|
||||
network/util/Makefile
|
||||
profile/Makefile
|
||||
profile/src/Makefile
|
||||
profile/public/Makefile
|
||||
profile/resources/Makefile
|
||||
rdf/Makefile
|
||||
rdf/base/Makefile
|
||||
rdf/base/idl/Makefile
|
||||
rdf/base/public/Makefile
|
||||
rdf/base/src/Makefile
|
||||
rdf/brprof/Makefile
|
||||
rdf/brprof/public/Makefile
|
||||
rdf/brprof/src/Makefile
|
||||
rdf/brprof/build/Makefile
|
||||
rdf/chrome/Makefile
|
||||
rdf/chrome/build/Makefile
|
||||
rdf/chrome/public/Makefile
|
||||
rdf/chrome/src/Makefile
|
||||
rdf/util/Makefile
|
||||
rdf/util/public/Makefile
|
||||
rdf/util/src/Makefile
|
||||
rdf/resources/Makefile
|
||||
rdf/build/Makefile
|
||||
rdf/content/Makefile
|
||||
rdf/content/public/Makefile
|
||||
rdf/content/src/Makefile
|
||||
rdf/datasource/Makefile
|
||||
rdf/datasource/public/Makefile
|
||||
rdf/datasource/src/Makefile
|
||||
rdf/tests/Makefile
|
||||
rdf/tests/localfile/Makefile
|
||||
rdf/tests/rdfsink/Makefile
|
||||
rdf/tests/rdfcat/Makefile
|
||||
rdf/tests/rdfpoll/Makefile
|
||||
sun-java/Makefile
|
||||
sun-java/stubs/Makefile
|
||||
sun-java/stubs/include/Makefile
|
||||
sun-java/stubs/jri/Makefile
|
||||
sun-java/stubs/src/Makefile
|
||||
caps/Makefile
|
||||
caps/include/Makefile
|
||||
caps/public/Makefile
|
||||
caps/src/Makefile
|
||||
view/Makefile
|
||||
view/public/Makefile
|
||||
view/src/Makefile
|
||||
webshell/Makefile
|
||||
webshell/public/Makefile
|
||||
webshell/src/Makefile
|
||||
webshell/tests/Makefile
|
||||
webshell/tests/viewer/Makefile
|
||||
webshell/tests/viewer/public/Makefile
|
||||
widget/Makefile
|
||||
widget/public/Makefile
|
||||
widget/src/Makefile
|
||||
widget/src/build/Makefile
|
||||
widget/src/gtk/Makefile
|
||||
widget/src/motif/Makefile
|
||||
widget/src/photon/Makefile
|
||||
widget/src/rhapsody/Makefile
|
||||
widget/src/xlib/Makefile
|
||||
widget/src/xpwidgets/Makefile
|
||||
widget/tests/Makefile
|
||||
widget/tests/scribble/Makefile
|
||||
widget/tests/widget/Makefile
|
||||
xpcom/Makefile
|
||||
xpcom/public/Makefile
|
||||
xpcom/src/Makefile
|
||||
xpcom/sample/Makefile
|
||||
xpcom/tests/Makefile
|
||||
xpcom/tests/dynamic/Makefile
|
||||
xpcom/tools/Makefile
|
||||
xpcom/tools/xpidl/Makefile
|
||||
xpcom/tools/registry/Makefile
|
||||
xpcom/libxpt/Makefile
|
||||
xpcom/libxpt/public/Makefile
|
||||
xpcom/libxpt/src/Makefile
|
||||
xpcom/libxpt/tests/Makefile
|
||||
xpcom/libxpt/tools/Makefile
|
||||
xpcom/libxpt/xptcall/Makefile
|
||||
xpcom/libxpt/xptcall/public/Makefile
|
||||
xpcom/libxpt/xptcall/src/Makefile
|
||||
xpcom/libxpt/xptcall/src/md/Makefile
|
||||
xpcom/libxpt/xptcall/src/md/unix/Makefile
|
||||
xpcom/libxpt/xptcall/src/md/test/Makefile
|
||||
xpcom/libxpt/xptcall/tests/Makefile
|
||||
xpcom/libxpt/xptinfo/Makefile
|
||||
xpcom/libxpt/xptinfo/public/Makefile
|
||||
xpcom/libxpt/xptinfo/src/Makefile
|
||||
xpcom/libxpt/xptinfo/tests/Makefile
|
||||
xpcom/idl/Makefile
|
||||
xpcom/proxy/Makefile
|
||||
xpcom/proxy/public/Makefile
|
||||
xpcom/proxy/src/Makefile
|
||||
xpcom/proxy/tests/Makefile
|
||||
silentdl/Makefile
|
||||
xpinstall/Makefile
|
||||
xpinstall/public/Makefile
|
||||
xpinstall/src/Makefile
|
||||
xpfe/Makefile
|
||||
xpfe/AppCores/Makefile
|
||||
xpfe/AppCores/public/Makefile
|
||||
xpfe/AppCores/src/Makefile
|
||||
xpfe/AppCores/xul/Makefile
|
||||
xpfe/AppCores/idl/Makefile
|
||||
xpfe/browser/Makefile
|
||||
xpfe/browser/public/Makefile
|
||||
xpfe/browser/src/Makefile
|
||||
xpfe/browser/samples/Makefile
|
||||
xpfe/browser/samples/sampleimages/Makefile
|
||||
xpfe/components/Makefile
|
||||
xpfe/components/public/Makefile
|
||||
xpfe/components/sample/Makefile
|
||||
xpfe/components/sample/public/Makefile
|
||||
xpfe/components/sample/src/Makefile
|
||||
xpfe/components/sample/resources/Makefile
|
||||
xpfe/components/find/Makefile
|
||||
xpfe/components/find/public/Makefile
|
||||
xpfe/components/find/src/Makefile
|
||||
xpfe/components/find/resources/Makefile
|
||||
xpfe/components/history/Makefile
|
||||
xpfe/components/history/src/Makefile
|
||||
xpfe/components/history/public/Makefile
|
||||
xpfe/components/history/resources/Makefile
|
||||
xpfe/components/xfer/Makefile
|
||||
xpfe/components/xfer/public/Makefile
|
||||
xpfe/components/xfer/src/Makefile
|
||||
xpfe/components/xfer/resources/Makefile
|
||||
xpfe/components/ucth/Makefile
|
||||
xpfe/components/ucth/public/Makefile
|
||||
xpfe/components/ucth/src/Makefile
|
||||
xpfe/components/ucth/resources/Makefile
|
||||
xpfe/appshell/Makefile
|
||||
xpfe/appshell/src/Makefile
|
||||
xpfe/appshell/public/Makefile
|
||||
xpfe/bootstrap/Makefile
|
||||
xpfe/browser/Makefile
|
||||
xpfe/browser/src/Makefile
|
||||
# xpfe/browser/public/Makefile
|
||||
END_NGMAKEFILES
|
||||
|
||||
if [ "$MOZ_EDITOR" ]; then
|
||||
add_makefiles <<END_EDITOR_MAKEFILES
|
||||
editor/base/Makefile
|
||||
editor/txmgr/Makefile
|
||||
editor/txmgr/public/Makefile
|
||||
editor/txmgr/src/Makefile
|
||||
editor/txmgr/tests/Makefile
|
||||
editor/txtsvc/Makefile
|
||||
editor/txtsvc/public/Makefile
|
||||
editor/txtsvc/src/Makefile
|
||||
editor/guimgr/Makefile
|
||||
editor/guimgr/src/Makefile
|
||||
editor/guimgr/public/Makefile
|
||||
editor/ui/Makefile
|
||||
editor/ui/composer/Makefile
|
||||
editor/ui/composer/content/Makefile
|
||||
editor/ui/composer/skin/Makefile
|
||||
editor/ui/dialogs/Makefile
|
||||
editor/ui/dialogs/content/Makefile
|
||||
editor/ui/dialogs/skin/Makefile
|
||||
|
||||
END_EDITOR_MAKEFILES
|
||||
fi
|
||||
|
||||
if [ "$MOZ_MAIL_NEWS" ]; then
|
||||
add_makefiles < ${srcdir}/mailnews/makefiles
|
||||
fi
|
||||
|
||||
if [ -d ${srcdir}/netwerk ]; then
|
||||
add_makefiles < ${srcdir}/netwerk/makefiles
|
||||
fi
|
||||
@@ -22,11 +22,9 @@ srcdir = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = public src
|
||||
DIRS = public src
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
DIRS += tests
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#define _IMPL_NS_BASE 1
|
||||
|
||||
#include "MacPrefix_debug.h"
|
||||
@@ -1,21 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#define _IMPL_NS_BASE 1
|
||||
|
||||
#include "MacPrefix.h"
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -2,7 +2,6 @@
|
||||
mozilla/base/src/mac/nsTimerMac.cpp
|
||||
mozilla/base/src/nsArena.cpp
|
||||
mozilla/base/src/nsAtomTable.cpp
|
||||
mozilla/base/src/nsBaseDLL.cpp
|
||||
mozilla/base/src/nsBTree.cpp
|
||||
mozilla/base/src/nsByteBuffer.cpp
|
||||
mozilla/base/src/nsCRT.cpp
|
||||
@@ -11,7 +10,6 @@ mozilla/base/src/nsEscape.cpp
|
||||
mozilla/base/src/nsFileSpec.cpp
|
||||
mozilla/base/src/nsFileStream.cpp
|
||||
mozilla/base/src/nsRBTree.cpp
|
||||
mozilla/base/src/nsProperties.cpp
|
||||
mozilla/base/src/nsSizeOfHandler.cpp
|
||||
mozilla/base/src/nsString.cpp
|
||||
mozilla/base/src/nsUnicharBuffer.cpp
|
||||
|
||||
@@ -2,25 +2,7 @@
|
||||
# This is a list of local files which get copied to the mozilla:dist:base directory
|
||||
#
|
||||
|
||||
nsAutoLock.h
|
||||
nsISizeOfHandler.h
|
||||
nsFileStream.h
|
||||
nsIFileStream.h
|
||||
nsIString.h
|
||||
nsIStringStream.h
|
||||
nsFileSpec.h
|
||||
nsFileSpecStreaming.h
|
||||
nsRepeater.h
|
||||
nsIProperties.h
|
||||
nsIScriptable.h
|
||||
nsIVariant.h
|
||||
nsCaretProperties.h
|
||||
nsSpecialSystemDirectory.h
|
||||
nsIObserverService.h
|
||||
nsIObserverList.h
|
||||
nsIObserver.h
|
||||
nsEscape.h
|
||||
nsStdFileStream.h
|
||||
nsQuickSort.h
|
||||
nsIThread.h
|
||||
nsIByteBufferInputStream.h
|
||||
nsRepeater.h
|
||||
@@ -25,28 +25,10 @@ include $(DEPTH)/config/autoconf.mk
|
||||
DEFINES += -D_IMPL_NS_BASE
|
||||
|
||||
EXPORTS = \
|
||||
nsAutoLock.h \
|
||||
nsIProperties.h \
|
||||
nsIScriptable.h \
|
||||
nsIVariant.h \
|
||||
nsISizeOfHandler.h \
|
||||
nsIString.h \
|
||||
nsCaretProperties.h \
|
||||
nsEscape.h \
|
||||
nsFileSpec.h \
|
||||
nsFileStream.h \
|
||||
nsIFileStream.h \
|
||||
nsIStringStream.h \
|
||||
nsFileSpecStreaming.h \
|
||||
nsSpecialSystemDirectory.h \
|
||||
nsIObserverService.h \
|
||||
nsIObserverList.h \
|
||||
nsIObserver.h \
|
||||
nsQuickSort.h \
|
||||
nsIPageManager.h \
|
||||
nsIBuffer.h \
|
||||
nsIByteBufferInputStream.h \
|
||||
nsIThread.h \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
@@ -20,30 +20,12 @@ IGNORE_MANIFEST=1
|
||||
|
||||
DEFINES = -D_IMPL_NS_BASE
|
||||
|
||||
EXPORTS = \
|
||||
nsAutoLock.h \
|
||||
nsCaretProperties.h \
|
||||
nsIProperties.h \
|
||||
nsIScriptable.h \
|
||||
nsIVariant.h \
|
||||
nsISizeOfHandler.h \
|
||||
nsEscape.h \
|
||||
nsFileSpec.h \
|
||||
nsFileSpecStreaming.h \
|
||||
nsFileStream.h \
|
||||
nsIFileStream.h \
|
||||
nsIString.h \
|
||||
nsIStringStream.h \
|
||||
nsIThread.h \
|
||||
nsSpecialSystemDirectory.h \
|
||||
nsIByteBufferInputStream.h \
|
||||
nsIObserverService.h \
|
||||
nsIObserverList.h \
|
||||
nsIObserver.h \
|
||||
nsQuickSort.h \
|
||||
nsIPageManager.h \
|
||||
nsIBuffer.h \
|
||||
$(NULL)
|
||||
EXPORTS = \
|
||||
nsIProperties.h \
|
||||
nsISizeOfHandler.h \
|
||||
nsFileSpec.h \
|
||||
nsFileStream.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = raptor
|
||||
|
||||
|
||||
@@ -1,179 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
|
||||
A stack-based lock object that makes using PRLock a bit more
|
||||
convenient. It acquires the monitor when constructed, and releases
|
||||
it when it goes out of scope.
|
||||
|
||||
For example,
|
||||
|
||||
class Foo {
|
||||
private:
|
||||
PRLock* mLock;
|
||||
|
||||
public:
|
||||
Foo(void) {
|
||||
mLock = PR_NewLock();
|
||||
}
|
||||
|
||||
virtual ~Foo(void) {
|
||||
PR_DestroyLock(mLock);
|
||||
}
|
||||
|
||||
void ThreadSafeMethod(void) {
|
||||
// we're don't hold the lock yet...
|
||||
|
||||
nsAutoLock lock(mLock);
|
||||
// ...but now we do.
|
||||
|
||||
// we even can do wacky stuff like return from arbitrary places w/o
|
||||
// worrying about forgetting to release the lock
|
||||
if (some_weird_condition)
|
||||
return;
|
||||
|
||||
// otherwise do some other stuff
|
||||
}
|
||||
|
||||
void ThreadSafeBlockScope(void) {
|
||||
// we're not in the lock here...
|
||||
|
||||
{
|
||||
nsAutoLock lock(mLock);
|
||||
// but we are now, at least until the block scope closes
|
||||
}
|
||||
|
||||
// ...now we're not in the lock anymore
|
||||
}
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
#ifndef nsAutoLock_h__
|
||||
#define nsAutoLock_h__
|
||||
|
||||
#include "nscore.h"
|
||||
#include "prlock.h"
|
||||
#include "prlog.h"
|
||||
|
||||
// If you ever decide that you need to add a non-inline method to this
|
||||
// class, be sure to change the class declaration to "class NS_BASE
|
||||
// nsAutoLock".
|
||||
|
||||
class nsAutoLock {
|
||||
private:
|
||||
PRLock* mLock;
|
||||
|
||||
// Not meant to be implemented. This makes it a compiler error to
|
||||
// construct or assign an nsAutoLock object incorrectly.
|
||||
nsAutoLock(void) {}
|
||||
nsAutoLock(nsAutoLock& aLock) {}
|
||||
nsAutoLock& operator =(nsAutoLock& aLock) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Not meant to be implemented. This makes it a compiler error to
|
||||
// attempt to create an nsAutoLock object on the heap.
|
||||
static void* operator new(size_t size) {
|
||||
return nsnull;
|
||||
}
|
||||
static void operator delete(void* memory) {}
|
||||
|
||||
public:
|
||||
nsAutoLock(PRLock* aLock) : mLock(aLock) {
|
||||
PR_ASSERT(mLock);
|
||||
|
||||
// This will assert deep in the bowels of NSPR if you attempt
|
||||
// to re-enter the lock.
|
||||
PR_Lock(mLock);
|
||||
}
|
||||
|
||||
~nsAutoLock(void) {
|
||||
PR_Unlock(mLock);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Same sort of shit here. Imagine if you will:
|
||||
//
|
||||
// nsresult MyClass::MyMethod(...) {
|
||||
// nsAutoMonitor mon(this); // or some random object as a monitor
|
||||
// ...
|
||||
// // go ahead and do deeply nested returns...
|
||||
// return NS_ERROR_FAILURE;
|
||||
// ...
|
||||
// // or call Wait or Notify...
|
||||
// mon.Wait();
|
||||
// ...
|
||||
// // cleanup is automatic
|
||||
// }
|
||||
|
||||
#include "prcmon.h"
|
||||
#include "nsError.h"
|
||||
|
||||
class nsAutoMonitor {
|
||||
public:
|
||||
nsAutoMonitor(void* lockObject)
|
||||
: mLockObject(lockObject)
|
||||
{
|
||||
NS_ASSERTION(lockObject, "null lock object");
|
||||
PR_CEnterMonitor(mLockObject);
|
||||
}
|
||||
|
||||
~nsAutoMonitor() {
|
||||
PR_CExitMonitor(mLockObject);
|
||||
}
|
||||
|
||||
nsresult Wait(PRIntervalTime interval = PR_INTERVAL_NO_TIMEOUT) {
|
||||
return PR_CWait(mLockObject, interval) == PR_SUCCESS
|
||||
? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult Notify() {
|
||||
return PR_CNotify(mLockObject) == PR_SUCCESS
|
||||
? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult NotifyAll() {
|
||||
return PR_CNotifyAll(mLockObject) == PR_SUCCESS
|
||||
? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
private:
|
||||
void* mLockObject;
|
||||
|
||||
// Not meant to be implemented. This makes it a compiler error to
|
||||
// construct or assign an nsAutoLock object incorrectly.
|
||||
nsAutoMonitor(void) {}
|
||||
nsAutoMonitor(nsAutoMonitor& aMon) {}
|
||||
nsAutoMonitor& operator =(nsAutoMonitor& aMon) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Not meant to be implemented. This makes it a compiler error to
|
||||
// attempt to create an nsAutoLock object on the heap.
|
||||
static void* operator new(size_t size) {
|
||||
return nsnull;
|
||||
}
|
||||
static void operator delete(void* memory) {}
|
||||
};
|
||||
|
||||
#endif // nsAutoLock_h__
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
// this class is used to gather caret properties from the OS. It
|
||||
// must be implemented by each platform that wants more than
|
||||
// the generic caret properties.
|
||||
|
||||
class nsCaretProperties
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
nsCaretProperties();
|
||||
virtual ~nsCaretProperties() {}
|
||||
|
||||
virtual PRInt32 GetCaretWidth() { return mCaretWidth; }
|
||||
virtual PRUint32 GetCaretBlinkRate() { return mBlinkRate; }
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// have value for no blinking
|
||||
|
||||
enum {
|
||||
eDefaulBlinkRate = 500, // twice a second
|
||||
eDefaultCaretWidth = 20 // 20 twips = 1 pixel
|
||||
};
|
||||
|
||||
|
||||
PRInt32 mCaretWidth; // caret width in twips
|
||||
PRUint32 mBlinkRate; // blink rate in milliseconds
|
||||
|
||||
|
||||
// members for vertical placement & size?
|
||||
|
||||
};
|
||||
|
||||
NS_BASE nsCaretProperties* NewCaretProperties();
|
||||
@@ -22,7 +22,6 @@
|
||||
#define _ESCAPE_H_
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
|
||||
/* valid mask values for NET_Escape() and NET_EscapedSize(). */
|
||||
typedef enum {
|
||||
@@ -34,31 +33,24 @@ typedef enum {
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
NS_BASE char * nsEscape(const char * str, nsEscapeMask mask);
|
||||
char * nsEscape(const char * str, nsEscapeMask mask);
|
||||
/* Caller must use delete [] on the result */
|
||||
|
||||
NS_BASE char * nsUnescape(char * str);
|
||||
char * nsUnescape(char * str);
|
||||
/* decode % escaped hex codes into character values,
|
||||
* modifies the parameter, returns the same buffer
|
||||
*/
|
||||
|
||||
NS_BASE char * nsEscapeCount(const char * str, PRInt32 len, nsEscapeMask mask, PRInt32* out_len);
|
||||
char * nsEscapeCount(const char * str, PRInt32 len, nsEscapeMask mask, PRInt32* out_len);
|
||||
/* Like nsEscape, but if out_len is non-null, return result string length
|
||||
* in *out_len, and uses len instead of NUL termination.
|
||||
* Caller must use delete [] on the result.
|
||||
*/
|
||||
NS_BASE PRInt32 nsUnescapeCount (char * str);
|
||||
PRInt32 nsUnescapeCount (char * str);
|
||||
/* decode % escaped hex codes into character values,
|
||||
* modifies the parameter buffer, returns the length of the result
|
||||
* (result may contain \0's).
|
||||
*/
|
||||
|
||||
NS_BASE char *
|
||||
nsEscapeHTML(const char * string);
|
||||
/*
|
||||
* Escape problem char's for HTML display
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -24,17 +24,7 @@
|
||||
//
|
||||
// Classes defined:
|
||||
//
|
||||
// nsFilePath, nsFileURL, nsFileSpec, nsPersistentFileDescriptor
|
||||
// nsDirectoryIterator. Oh, and a convenience class nsAutoCString.
|
||||
//
|
||||
// Q. How should I represent files at run time?
|
||||
// A. Use nsFileSpec. Using char* will lose information on some platforms.
|
||||
//
|
||||
// Q. Then what are nsFilePath and nsFileURL for?
|
||||
// A. Only when you need a char* parameter for legacy code.
|
||||
//
|
||||
// Q. How should I represent files in a persistent way (eg, in a disk file)?
|
||||
// A. Use nsPersistentFileDescriptor. Convert to and from nsFileSpec at run time.
|
||||
// nsFilePath, nsFileURL, nsNativeFileSpec.
|
||||
//
|
||||
// This suite provides the following services:
|
||||
//
|
||||
@@ -53,7 +43,7 @@
|
||||
//
|
||||
// nsFilePath myPath("/Development/iotest.txt");
|
||||
//
|
||||
// nsOutputFileStream testStream(nsFileSpec(myPath));
|
||||
// nsOutputFileStream testStream(myPath);
|
||||
// testStream << "Hello World" << nsEndl;
|
||||
//
|
||||
// 4. Handy methods for manipulating file specifiers safely, e.g. MakeUnique(),
|
||||
@@ -63,35 +53,35 @@
|
||||
//
|
||||
// Examples:
|
||||
//
|
||||
// Initialize a URL from a string
|
||||
// Initialize a URL from a string without suffix
|
||||
//
|
||||
// nsFileURL fileURL("file:///Development/MPW/MPW%20Shell");
|
||||
//
|
||||
// Initialize a Unix-style path from a URL
|
||||
// Initialize a Unix path from a URL
|
||||
//
|
||||
// nsFilePath filePath(fileURL);
|
||||
//
|
||||
// Initialize a file spec from a URL
|
||||
// Initialize a native file spec from a URL
|
||||
//
|
||||
// nsFileSpec fileSpec(fileURL);
|
||||
// nsNativeFileSpec fileSpec(fileURL);
|
||||
//
|
||||
// Make the spec unique.
|
||||
// Make the spec unique (this one has no suffix).
|
||||
//
|
||||
// fileSpec.MakeUnique();
|
||||
//
|
||||
// Assign the spec to a URL (causing conversion)
|
||||
// Assign the spec to a URL
|
||||
//
|
||||
// fileURL = fileSpec;
|
||||
//
|
||||
// Assign a unix path using a string
|
||||
// Assign a unix path using a string with a suffix.
|
||||
//
|
||||
// filePath = "/Development/MPW/SysErrs.err";
|
||||
//
|
||||
// Assign to a file spec using a unix path (causing conversion).
|
||||
// Assign to a file spec using a unix path.
|
||||
//
|
||||
// fileSpec = filePath;
|
||||
//
|
||||
// Make this unique.
|
||||
// Make this unique (this one has a suffix).
|
||||
//
|
||||
// fileSpec.MakeUnique();
|
||||
//
|
||||
@@ -103,15 +93,16 @@
|
||||
// is solved by holding a "private" native file spec inside the
|
||||
// nsFilePath and nsFileURL classes, which is used when appropriate.
|
||||
//
|
||||
// Not yet done:
|
||||
//
|
||||
// Equality operators... much more.
|
||||
//
|
||||
//========================================================================================
|
||||
|
||||
#ifndef _FILESPEC_H_
|
||||
#define _FILESPEC_H_
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsError.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
//========================================================================================
|
||||
// Compiler-specific macros, as needed
|
||||
@@ -125,13 +116,11 @@
|
||||
#define NS_NAMESPACE_PROTOTYPE
|
||||
#define NS_NAMESPACE namespace
|
||||
#define NS_NAMESPACE_END
|
||||
#define NS_EXPLICIT explicit
|
||||
#else
|
||||
|
||||
#define NS_NAMESPACE_PROTOTYPE static
|
||||
#define NS_NAMESPACE struct
|
||||
#define NS_NAMESPACE_END ;
|
||||
#define NS_EXPLICIT
|
||||
|
||||
#endif
|
||||
//=========================== End Compiler-specific macros ===============================
|
||||
@@ -140,7 +129,7 @@
|
||||
#include <Files.h>
|
||||
#elif defined(XP_UNIX) || defined (XP_OS2)
|
||||
#include <dirent.h>
|
||||
#elif defined(XP_PC)
|
||||
#elif XP_PC
|
||||
#include "prio.h"
|
||||
#endif
|
||||
|
||||
@@ -148,252 +137,88 @@
|
||||
// Here are the allowable ways to describe a file.
|
||||
//========================================================================================
|
||||
|
||||
class nsFileSpec; // Preferred. For i/o use nsInputFileStream, nsOutputFileStream
|
||||
class nsFilePath;
|
||||
class nsFilePath; // This can be passed to NSPR file I/O routines.
|
||||
class nsFileURL;
|
||||
class nsNSPRPath; // This can be passed to NSPR file I/O routines, if you must.
|
||||
class nsPersistentFileDescriptor; // Used for storage across program launches.
|
||||
class nsNativeFileSpec;
|
||||
|
||||
#define kFileURLPrefix "file://"
|
||||
#define kFileURLPrefixLength (7)
|
||||
|
||||
class nsOutputStream;
|
||||
class nsInputStream;
|
||||
class nsIOutputStream;
|
||||
class nsIInputStream;
|
||||
class nsOutputFileStream;
|
||||
class nsInputFileStream;
|
||||
class nsOutputConsoleStream;
|
||||
|
||||
class nsString;
|
||||
class nsBasicOutStream;
|
||||
|
||||
//========================================================================================
|
||||
// Conversion of native file errors to nsresult values. These are really only for use
|
||||
// in the file module, clients of this interface shouldn't really need them.
|
||||
// Error results returned from this interface have, in the low-order 16 bits,
|
||||
// native errors that are masked to 16 bits. Assumption: a native error of 0 is success
|
||||
// on all platforms. Note the way we define this using an inline function. This
|
||||
// avoids multiple evaluation if people go NS_FILE_RESULT(function_call()).
|
||||
#define NS_FILE_RESULT(x) ns_file_convert_result((PRInt32)x)
|
||||
nsresult ns_file_convert_result(PRInt32 nativeErr);
|
||||
#define NS_FILE_FAILURE NS_FILE_RESULT(-1)
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsAutoCString
|
||||
//
|
||||
// This should be in nsString.h, but the owner would not reply to my proposal. After four
|
||||
// weeks, I decided to put it in here.
|
||||
//
|
||||
// This is a quiet little class that acts as a sort of autoptr for
|
||||
// a const char*. If you used to call nsString::ToNewCString(), just
|
||||
// to pass the result a parameter list, it was a nuisance having to
|
||||
// call delete [] on the result after the call. Now you can say
|
||||
// nsString myStr;
|
||||
// ...
|
||||
// f(nsAutoCString(myStr));
|
||||
// where f is declared as void f(const char*); This call will
|
||||
// make a temporary char* pointer on the stack and delete[] it
|
||||
// when the function returns.
|
||||
//========================================================================================
|
||||
{
|
||||
public:
|
||||
NS_EXPLICIT nsAutoCString(const nsString& other) : mCString(other.ToNewCString()) {}
|
||||
virtual ~nsAutoCString();
|
||||
operator const char*() const { return mCString; }
|
||||
|
||||
// operator const char*() { return mCString; }
|
||||
// don't need this, since |operator const char*() const| can
|
||||
// serve for both |const| and non-|const| callers
|
||||
protected:
|
||||
const char* mCString;
|
||||
}; // class nsAutoCString
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsSimpleCharString
|
||||
// An envelope for char*: reference counted. Used internally by all the nsFileSpec
|
||||
// classes below.
|
||||
//========================================================================================
|
||||
{
|
||||
public:
|
||||
nsSimpleCharString();
|
||||
nsSimpleCharString(const char*);
|
||||
nsSimpleCharString(const nsString&);
|
||||
nsSimpleCharString(const nsSimpleCharString&);
|
||||
nsSimpleCharString(const char* inData, PRUint32 inLength);
|
||||
|
||||
~nsSimpleCharString();
|
||||
|
||||
void operator = (const char*);
|
||||
void operator = (const nsString&);
|
||||
void operator = (const nsSimpleCharString&);
|
||||
|
||||
operator const char*() const { return mData ? mData->mString : 0; }
|
||||
operator char* ()
|
||||
{
|
||||
ReallocData(Length()); // requires detaching if shared...
|
||||
return mData ? mData->mString : 0;
|
||||
}
|
||||
PRBool operator == (const char*);
|
||||
PRBool operator == (const nsString&);
|
||||
PRBool operator == (const nsSimpleCharString&);
|
||||
|
||||
void operator += (const char* inString);
|
||||
nsSimpleCharString operator + (const char* inString) const;
|
||||
|
||||
char operator [](int i) const { return mData ? mData->mString[i] : 0; }
|
||||
char& operator [](int i)
|
||||
{
|
||||
if (i >= (int)Length())
|
||||
ReallocData((PRUint32)i + 1);
|
||||
return mData->mString[i]; // caveat appelator
|
||||
}
|
||||
char& operator [](unsigned int i) { return (*this)[(int)i]; }
|
||||
|
||||
void Catenate(const char* inString1, const char* inString2);
|
||||
|
||||
void SetToEmpty();
|
||||
PRBool IsEmpty() const { return Length() == 0; }
|
||||
|
||||
PRUint32 Length() const { return mData ? mData->mLength : 0; }
|
||||
void SetLength(PRUint32 inLength) { ReallocData(inLength); }
|
||||
void CopyFrom(const char* inData, PRUint32 inLength);
|
||||
void LeafReplace(char inSeparator, const char* inLeafName);
|
||||
char* GetLeaf(char inSeparator) const; // use PR_Free()
|
||||
void Unescape();
|
||||
|
||||
protected:
|
||||
|
||||
void AddRefData();
|
||||
void ReleaseData();
|
||||
void ReallocData(PRUint32 inLength);
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
protected:
|
||||
|
||||
struct Data {
|
||||
int mRefCount;
|
||||
PRUint32 mLength;
|
||||
char mString[1];
|
||||
};
|
||||
Data* mData;
|
||||
}; // class nsSimpleCharString
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsFileSpec
|
||||
class NS_BASE nsNativeFileSpec
|
||||
// This is whatever each platform really prefers to describe files as. Declared first
|
||||
// because the other two types have an embedded nsFileSpec object.
|
||||
// because the other two types have an embeded nsNativeFileSpec object.
|
||||
//========================================================================================
|
||||
{
|
||||
public:
|
||||
nsFileSpec();
|
||||
|
||||
// These two meathods take *native* file paths.
|
||||
NS_EXPLICIT nsFileSpec(const char* inNativePath, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFileSpec(const nsString& inNativePath, PRBool inCreateDirs = PR_FALSE);
|
||||
|
||||
|
||||
NS_EXPLICIT nsFileSpec(const nsFilePath& inPath);
|
||||
NS_EXPLICIT nsFileSpec(const nsFileURL& inURL);
|
||||
NS_EXPLICIT nsFileSpec(const nsPersistentFileDescriptor& inURL);
|
||||
nsFileSpec(const nsFileSpec& inPath);
|
||||
virtual ~nsFileSpec();
|
||||
|
||||
// These two operands take *native* file paths.
|
||||
void operator = (const char* inNativePath);
|
||||
void operator = (const nsString& inNativePath)
|
||||
{
|
||||
const nsAutoCString path(inNativePath);
|
||||
*this = path;
|
||||
}
|
||||
nsNativeFileSpec();
|
||||
explicit nsNativeFileSpec(const char* inString, bool inCreateDirs = false);
|
||||
explicit nsNativeFileSpec(const nsFilePath& inPath);
|
||||
explicit nsNativeFileSpec(const nsFileURL& inURL);
|
||||
nsNativeFileSpec(const nsNativeFileSpec& inPath);
|
||||
virtual ~nsNativeFileSpec();
|
||||
|
||||
void operator = (const char* inPath);
|
||||
void operator = (const nsFilePath& inPath);
|
||||
void operator = (const nsFileURL& inURL);
|
||||
void operator = (const nsFileSpec& inOther);
|
||||
void operator = (const nsPersistentFileDescriptor& inOther);
|
||||
void operator = (const nsNativeFileSpec& inOther);
|
||||
|
||||
PRBool operator ==(const nsFileSpec& inOther) const;
|
||||
PRBool operator !=(const nsFileSpec& inOther) const;
|
||||
|
||||
operator const char* () const { return GetCString(); }
|
||||
// Same as GetCString (please read the comments).
|
||||
// Do not try to free this!
|
||||
const char* GetNativePathCString() const { return GetCString(); }
|
||||
// Same as GetCString (please read the comments).
|
||||
// Do not try to free this!
|
||||
const char* GetCString() const;
|
||||
// Returns a native path, and allows the
|
||||
// path to be "passed" to legacy code. This practice
|
||||
// is VERY EVIL and should only be used to support legacy
|
||||
// code. Using it guarantees bugs on Macintosh.
|
||||
// The path is cached and freed by the nsFileSpec destructor
|
||||
// so do not delete (or free) it. See also nsNSPRPath below,
|
||||
// if you really must pass a string to PR_OpenFile().
|
||||
// Doing so will introduce two automatic bugs.
|
||||
#ifndef XP_MAC
|
||||
operator const char* () const { return mPath; }
|
||||
// This is the only automatic conversion to const char*
|
||||
// that is provided, and it allows the
|
||||
// path to be "passed" to NSPR file routines.
|
||||
#endif
|
||||
|
||||
#ifdef XP_MAC
|
||||
// For Macintosh people, this is meant to be useful in its own right as a C++ version
|
||||
// of the FSSpec struct.
|
||||
nsFileSpec(
|
||||
nsNativeFileSpec(
|
||||
short vRefNum,
|
||||
long parID,
|
||||
ConstStr255Param name);
|
||||
nsFileSpec(const FSSpec& inSpec)
|
||||
: mSpec(inSpec), mError(NS_OK) {}
|
||||
void operator = (const FSSpec& inSpec)
|
||||
{ mSpec = inSpec; mError = NS_OK; }
|
||||
nsNativeFileSpec(const FSSpec& inSpec)
|
||||
: mSpec(inSpec), mError(noErr) {}
|
||||
|
||||
operator FSSpec* () { return &mSpec; }
|
||||
operator const FSSpec* const () { return &mSpec; }
|
||||
operator FSSpec& () { return mSpec; }
|
||||
operator const FSSpec& () const { return mSpec; }
|
||||
|
||||
const FSSpec& GetFSSpec() const { return mSpec; }
|
||||
FSSpec& GetFSSpec() { return mSpec; }
|
||||
ConstFSSpecPtr GetFSSpecPtr() const { return &mSpec; }
|
||||
FSSpecPtr GetFSSpecPtr() { return &mSpec; }
|
||||
OSErr Error() const { return mError; }
|
||||
void MakeAliasSafe();
|
||||
// Called for the spec of an alias. Copies the alias to
|
||||
// a secret temp directory and modifies the spec to point
|
||||
// to it. Sets mError.
|
||||
void ResolveAlias(PRBool& wasAliased);
|
||||
void ResolveAlias(bool& wasAliased);
|
||||
// Called for the spec of an alias. Modifies the spec to
|
||||
// point to the original. Sets mError.
|
||||
void MakeUnique(ConstStr255Param inSuggestedLeafName);
|
||||
StringPtr GetLeafPName() { return mSpec.name; }
|
||||
ConstStr255Param GetLeafPName() const { return mSpec.name; }
|
||||
|
||||
OSErr GetCatInfo(CInfoPBRec& outInfo) const;
|
||||
|
||||
#endif // end of Macintosh utility methods.
|
||||
|
||||
PRBool Valid() const { return NS_SUCCEEDED(Error()); }
|
||||
nsresult Error() const
|
||||
{
|
||||
#ifndef XP_MAC
|
||||
if (mPath.IsEmpty() && NS_SUCCEEDED(mError))
|
||||
((nsFileSpec*)this)->mError = NS_ERROR_NOT_INITIALIZED;
|
||||
#endif
|
||||
return mError;
|
||||
}
|
||||
PRBool Failed() const { return (PRBool)NS_FAILED(Error()); }
|
||||
#ifdef XP_MAC
|
||||
bool Valid() const { return mError == noErr; }
|
||||
#else
|
||||
bool Valid() const { return true; } // Fixme.
|
||||
#endif // XP_MAC
|
||||
|
||||
//--------------------------------------------------
|
||||
// Queries and path algebra. These do not modify the disk.
|
||||
//--------------------------------------------------
|
||||
friend NS_BASE nsBasicOutStream& operator << (
|
||||
nsBasicOutStream& s,
|
||||
const nsNativeFileSpec& spec);
|
||||
|
||||
char* GetLeafName() const; // Allocated. Use nsCRT::free().
|
||||
//--------------------------------------------------
|
||||
// Queries and path algebra. These do not modify the disk.
|
||||
//--------------------------------------------------
|
||||
|
||||
char* GetLeafName() const; // Allocated. Use delete [].
|
||||
void SetLeafName(const char* inLeafName);
|
||||
// inLeafName can be a relative path, so this allows
|
||||
// one kind of concatenation of "paths".
|
||||
void SetLeafName(const nsString& inLeafName)
|
||||
{
|
||||
const nsAutoCString leafName(inLeafName);
|
||||
SetLeafName(leafName);
|
||||
}
|
||||
void GetParent(nsFileSpec& outSpec) const;
|
||||
|
||||
void GetParent(nsNativeFileSpec& outSpec) const;
|
||||
// Return the filespec of the parent directory. Used
|
||||
// in conjunction with GetLeafName(), this lets you
|
||||
// parse a path into a list of node names. Beware,
|
||||
@@ -401,35 +226,8 @@ class NS_BASE nsFileSpec
|
||||
// but a spec. Volumes on Macintosh can have identical
|
||||
// names. Perhaps could be used for an operator --() ?
|
||||
|
||||
typedef PRUint32 TimeStamp; // ie nsFileSpec::TimeStamp. This is 32 bits now,
|
||||
// but might change, eg, to a 64-bit class. So use the
|
||||
// typedef, and use a streaming operator to convert
|
||||
// to a string, so that your code won't break. It's
|
||||
// none of your business what the number means. Don't
|
||||
// rely on the implementation.
|
||||
void GetModDate(TimeStamp& outStamp) const;
|
||||
// This will return different values on different
|
||||
// platforms, even for the same file (eg, on a server).
|
||||
// But if the platform is constant, it will increase after
|
||||
// every file modification.
|
||||
PRBool ModDateChanged(const TimeStamp& oldStamp) const
|
||||
{
|
||||
TimeStamp newStamp;
|
||||
GetModDate(newStamp);
|
||||
return newStamp != oldStamp;
|
||||
}
|
||||
|
||||
PRUint32 GetFileSize() const;
|
||||
PRUint32 GetDiskSpaceAvailable() const;
|
||||
|
||||
nsFileSpec operator + (const char* inRelativeUnixPath) const;
|
||||
nsFileSpec operator + (const nsString& inRelativeUnixPath) const
|
||||
{
|
||||
const nsAutoCString
|
||||
relativePath(inRelativeUnixPath);
|
||||
return *this + relativePath;
|
||||
}
|
||||
void operator += (const char* inRelativeUnixPath);
|
||||
nsNativeFileSpec operator + (const char* inRelativePath) const;
|
||||
void operator += (const char* inRelativePath);
|
||||
// Concatenate the relative path to this directory.
|
||||
// Used for constructing the filespec of a descendant.
|
||||
// This must be a directory for this to work. This differs
|
||||
@@ -438,67 +236,36 @@ class NS_BASE nsFileSpec
|
||||
// away its leaf information, whereas this one assumes
|
||||
// this is a directory, and the relative path starts
|
||||
// "below" this.
|
||||
void operator += (const nsString& inRelativeUnixPath)
|
||||
{
|
||||
const nsAutoCString relativePath(inRelativeUnixPath);
|
||||
*this += relativePath;
|
||||
}
|
||||
|
||||
void MakeUnique();
|
||||
void MakeUnique(const char* inSuggestedLeafName);
|
||||
void MakeUnique(const nsString& inSuggestedLeafName)
|
||||
{
|
||||
const nsAutoCString suggestedLeafName(inSuggestedLeafName);
|
||||
MakeUnique(suggestedLeafName);
|
||||
}
|
||||
|
||||
PRBool IsDirectory() const;
|
||||
bool IsDirectory() const;
|
||||
// More stringent than Exists()
|
||||
PRBool IsFile() const;
|
||||
bool IsFile() const;
|
||||
// More stringent than Exists()
|
||||
PRBool Exists() const;
|
||||
bool Exists() const;
|
||||
|
||||
//--------------------------------------------------
|
||||
// Creation and deletion of objects. These can modify the disk.
|
||||
//--------------------------------------------------
|
||||
//--------------------------------------------------
|
||||
// Creation and deletion of objects. These can modify the disk.
|
||||
//--------------------------------------------------
|
||||
|
||||
void CreateDirectory(int mode = 0700 /* for unix */);
|
||||
void CreateDir(int mode = 0700) { CreateDirectory(mode); }
|
||||
// workaround for yet another VC++ bug with long identifiers.
|
||||
void Delete(PRBool inRecursive) const;
|
||||
void Delete(bool inRecursive);
|
||||
|
||||
nsresult Rename(const char* inNewName); // not const: gets updated
|
||||
nsresult Rename(const nsString& inNewName)
|
||||
{
|
||||
const nsAutoCString newName(inNewName);
|
||||
return Rename(newName);
|
||||
}
|
||||
nsresult Copy(const nsFileSpec& inNewParentDirectory) const;
|
||||
nsresult Move(const nsFileSpec& inNewParentDirectory);
|
||||
nsresult Execute(const char* args) const;
|
||||
nsresult Execute(const nsString& args) const
|
||||
{
|
||||
const nsAutoCString argsString(args);
|
||||
return Execute(argsString);
|
||||
}
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
protected:
|
||||
private:
|
||||
friend class nsFilePath;
|
||||
friend class nsFileURL;
|
||||
friend class nsDirectoryIterator;
|
||||
#ifdef XP_MAC
|
||||
FSSpec mSpec;
|
||||
OSErr mError;
|
||||
#else
|
||||
char* mPath;
|
||||
#endif
|
||||
nsSimpleCharString mPath;
|
||||
nsresult mError;
|
||||
}; // class nsFileSpec
|
||||
|
||||
// FOR HISTORICAL REASONS:
|
||||
|
||||
typedef nsFileSpec nsNativeFileSpec;
|
||||
}; // class nsNativeFileSpec
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsFileURL
|
||||
@@ -509,10 +276,9 @@ class NS_BASE nsFileURL
|
||||
{
|
||||
public:
|
||||
nsFileURL(const nsFileURL& inURL);
|
||||
NS_EXPLICIT nsFileURL(const char* inURLString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFileURL(const nsString& inURLString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFileURL(const nsFilePath& inPath);
|
||||
NS_EXPLICIT nsFileURL(const nsFileSpec& inPath);
|
||||
explicit nsFileURL(const char* inString, bool inCreateDirs = false);
|
||||
explicit nsFileURL(const nsFilePath& inPath);
|
||||
explicit nsFileURL(const nsNativeFileSpec& inPath);
|
||||
virtual ~nsFileURL();
|
||||
|
||||
// nsString GetString() const { return mPath; }
|
||||
@@ -520,158 +286,90 @@ class NS_BASE nsFileURL
|
||||
// but should not provide a conversion constructor.
|
||||
|
||||
void operator = (const nsFileURL& inURL);
|
||||
void operator = (const char* inURLString);
|
||||
void operator = (const nsString& inURLString)
|
||||
{
|
||||
const nsAutoCString string(inURLString);
|
||||
*this = string;
|
||||
}
|
||||
void operator = (const char* inString);
|
||||
void operator = (const nsFilePath& inOther);
|
||||
void operator = (const nsFileSpec& inOther);
|
||||
void operator = (const nsNativeFileSpec& inOther);
|
||||
|
||||
void operator +=(const char* inRelativeUnixPath);
|
||||
nsFileURL operator +(const char* inRelativeUnixPath) const;
|
||||
operator const char* () const { return (const char*)mURL; } // deprecated.
|
||||
const char* GetURLString() const { return (const char*)mURL; }
|
||||
// Not allocated, so don't free it.
|
||||
const char* GetAsString() const { return (const char*)mURL; }
|
||||
// Not allocated, so don't free it.
|
||||
friend NS_BASE nsBasicOutStream& operator << (
|
||||
nsBasicOutStream& s, const nsFileURL& spec);
|
||||
|
||||
#ifdef XP_MAC
|
||||
// Accessor to allow quick assignment to a mFileSpec
|
||||
const nsFileSpec& GetFileSpec() const { return mFileSpec; }
|
||||
// Accessor to allow quick assignment to a mNativeFileSpec
|
||||
const nsNativeFileSpec& GetNativeSpec() const { return mNativeFileSpec; }
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
protected:
|
||||
private:
|
||||
// Should not be defined (only nsFilePath is to be treated as strings.
|
||||
operator char* ();
|
||||
operator const char* const ();
|
||||
private:
|
||||
friend class nsFilePath; // to allow construction of nsFilePath
|
||||
nsSimpleCharString mURL;
|
||||
|
||||
char* mURL;
|
||||
#ifdef XP_MAC
|
||||
// Since the path on the macintosh does not uniquely specify a file (volumes
|
||||
// can have the same name), stash the secret nsFileSpec, too.
|
||||
nsFileSpec mFileSpec;
|
||||
// can have the same name), stash the secret nsNativeFileSpec, too.
|
||||
nsNativeFileSpec mNativeFileSpec;
|
||||
#endif
|
||||
}; // class nsFileURL
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsFilePath
|
||||
// This is a string that looks like "/foo/bar/mumble fish". Same as nsFileURL, but
|
||||
// without the "file:// prefix", and NOT %20 ENCODED! Strings passed in must be
|
||||
// valid unix-style paths in this format.
|
||||
// This is a string that looks like "/foo/bar/mumble%20fish". Same as nsFileURL, but
|
||||
// without the "file:// prefix".
|
||||
//========================================================================================
|
||||
{
|
||||
public:
|
||||
nsFilePath(const nsFilePath& inPath);
|
||||
NS_EXPLICIT nsFilePath(const char* inUnixPathString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFilePath(const nsString& inUnixPathString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFilePath(const nsFileURL& inURL);
|
||||
NS_EXPLICIT nsFilePath(const nsFileSpec& inPath);
|
||||
explicit nsFilePath(const char* inString, bool inCreateDirs = false);
|
||||
explicit nsFilePath(const nsFileURL& inURL);
|
||||
explicit nsFilePath(const nsNativeFileSpec& inPath);
|
||||
virtual ~nsFilePath();
|
||||
|
||||
|
||||
operator const char* () const { return mPath; }
|
||||
// This will return a UNIX string. If you
|
||||
// need a string that can be passed into
|
||||
// NSPR, take a look at the nsNSPRPath class.
|
||||
// This is the only automatic conversion to const char*
|
||||
// that is provided, and it allows the
|
||||
// path to be "passed" to NSPR file routines.
|
||||
operator char* () { return mPath; }
|
||||
// This is the only automatic conversion to string
|
||||
// that is provided, because a naked string should
|
||||
// only mean a standard file path.
|
||||
|
||||
void operator = (const nsFilePath& inPath);
|
||||
void operator = (const char* inUnixPathString);
|
||||
void operator = (const nsString& inUnixPathString)
|
||||
{
|
||||
const nsAutoCString string(inUnixPathString);
|
||||
*this = string;
|
||||
}
|
||||
void operator = (const char* inString);
|
||||
void operator = (const nsFileURL& inURL);
|
||||
void operator = (const nsFileSpec& inOther);
|
||||
|
||||
void operator +=(const char* inRelativeUnixPath);
|
||||
nsFilePath operator +(const char* inRelativeUnixPath) const;
|
||||
void operator = (const nsNativeFileSpec& inOther);
|
||||
|
||||
#ifdef XP_MAC
|
||||
public:
|
||||
// Accessor to allow quick assignment to a mFileSpec
|
||||
const nsFileSpec& GetFileSpec() const { return mFileSpec; }
|
||||
// Accessor to allow quick assignment to a mNativeFileSpec
|
||||
const nsNativeFileSpec& GetNativeSpec() const { return mNativeFileSpec; }
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
nsSimpleCharString mPath;
|
||||
char* mPath;
|
||||
#ifdef XP_MAC
|
||||
// Since the path on the macintosh does not uniquely specify a file (volumes
|
||||
// can have the same name), stash the secret nsFileSpec, too.
|
||||
nsFileSpec mFileSpec;
|
||||
// can have the same name), stash the secret nsNativeFileSpec, too.
|
||||
nsNativeFileSpec mNativeFileSpec;
|
||||
#endif
|
||||
}; // class nsFilePath
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsPersistentFileDescriptor
|
||||
// To save information about a file's location in another file, initialize
|
||||
// one of these from your nsFileSpec, and then write this out to your output stream.
|
||||
// To retrieve the info, create one of these, read its value from an input stream.
|
||||
// and then make an nsFileSpec from it.
|
||||
//========================================================================================
|
||||
{
|
||||
public:
|
||||
nsPersistentFileDescriptor() {}
|
||||
// For use prior to reading in from a stream
|
||||
nsPersistentFileDescriptor(const nsPersistentFileDescriptor& inPath);
|
||||
virtual ~nsPersistentFileDescriptor();
|
||||
void operator = (const nsPersistentFileDescriptor& inPath);
|
||||
|
||||
// Conversions
|
||||
NS_EXPLICIT nsPersistentFileDescriptor(const nsFileSpec& inPath);
|
||||
void operator = (const nsFileSpec& inPath);
|
||||
|
||||
// The following four functions are declared here (as friends). Their implementations
|
||||
// are in mozilla/base/src/nsFileSpecStreaming.cpp.
|
||||
|
||||
friend nsresult Read(nsIInputStream* aStream, nsPersistentFileDescriptor&);
|
||||
friend nsresult Write(nsIOutputStream* aStream, const nsPersistentFileDescriptor&);
|
||||
// writes the data to a file
|
||||
friend NS_BASE nsInputStream& operator >> (nsInputStream&, nsPersistentFileDescriptor&);
|
||||
// reads the data from a file
|
||||
friend NS_BASE nsOutputStream& operator << (nsOutputStream&, const nsPersistentFileDescriptor&);
|
||||
// writes the data to a file
|
||||
friend class nsFileSpec;
|
||||
|
||||
void GetData(nsSimpleCharString& outData) const;
|
||||
void SetData(const nsSimpleCharString& inData);
|
||||
void GetData(nsSimpleCharString& outData, PRInt32& outSize) const;
|
||||
void SetData(const nsSimpleCharString& inData, PRInt32 inSize);
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
protected:
|
||||
|
||||
nsSimpleCharString mDescriptorString;
|
||||
|
||||
}; // class nsPersistentFileDescriptor
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsDirectoryIterator
|
||||
// Example:
|
||||
//
|
||||
// nsFileSpec parentDir(...); // directory over whose children we shall iterate
|
||||
// for (nsDirectoryIterator i(parentDir); i.Exists(); i++)
|
||||
// nsNativeFileSpec parentDir(...); // directory over whose children we shall iterate
|
||||
// for (nsDirectoryIterator i(parentDir); i; i++)
|
||||
// {
|
||||
// // do something with i.Spec()
|
||||
// // do something with (const nsNativeFileSpec&)i
|
||||
// }
|
||||
//
|
||||
// or:
|
||||
//
|
||||
// for (nsDirectoryIterator i(parentDir, -1); i.Exists(); i--)
|
||||
// for (nsDirectoryIterator i(parentDir, false); i; i--)
|
||||
// {
|
||||
// // do something with i.Spec()
|
||||
// // do something with (const nsNativeFileSpec&)i
|
||||
// }
|
||||
//
|
||||
// Currently, the only platform on which backwards iteration actually goes backwards
|
||||
@@ -680,77 +378,31 @@ class NS_BASE nsDirectoryIterator
|
||||
{
|
||||
public:
|
||||
nsDirectoryIterator(
|
||||
const nsFileSpec& parent,
|
||||
const nsNativeFileSpec& parent,
|
||||
int iterateDirection = +1);
|
||||
#ifndef XP_MAC
|
||||
// Macintosh currently doesn't allocate, so needn't clean up.
|
||||
virtual ~nsDirectoryIterator();
|
||||
#endif
|
||||
PRBool Exists() const { return mExists; }
|
||||
operator bool() const { return mExists; }
|
||||
nsDirectoryIterator& operator ++(); // moves to the next item, if any.
|
||||
nsDirectoryIterator& operator ++(int) { return ++(*this); } // post-increment.
|
||||
nsDirectoryIterator& operator --(); // moves to the previous item, if any.
|
||||
nsDirectoryIterator& operator --(int) { return --(*this); } // post-decrement.
|
||||
operator nsFileSpec&() { return mCurrent; }
|
||||
|
||||
nsFileSpec& Spec() { return mCurrent; }
|
||||
|
||||
operator nsNativeFileSpec&() { return mCurrent; }
|
||||
private:
|
||||
|
||||
#if defined(XP_MAC)
|
||||
OSErr SetToIndex();
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
nsFileSpec mCurrent;
|
||||
PRBool mExists;
|
||||
nsNativeFileSpec mCurrent;
|
||||
bool mExists;
|
||||
|
||||
#if defined(XP_UNIX)
|
||||
DIR* mDir;
|
||||
#elif defined(XP_PC)
|
||||
PRDir* mDir; // XXX why not use PRDir for Unix too?
|
||||
PRDir* mDir; // XXX why not use PRDir for Unix & Mac, too?
|
||||
#elif defined(XP_MAC)
|
||||
OSErr SetToIndex();
|
||||
short mIndex;
|
||||
short mMaxIndex;
|
||||
#endif
|
||||
}; // class nsDirectoryIterator
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsNSPRPath
|
||||
// This class will allow you to pass any one of the nsFile* classes directly into NSPR
|
||||
// without the need to worry about whether you have the right kind of filepath or not.
|
||||
// It will also take care of cleaning up any allocated memory.
|
||||
//========================================================================================
|
||||
{
|
||||
public:
|
||||
NS_EXPLICIT nsNSPRPath(const nsFileSpec& inSpec)
|
||||
: mFilePath(inSpec), modifiedNSPRPath(nsnull) {}
|
||||
NS_EXPLICIT nsNSPRPath(const nsFileURL& inURL)
|
||||
: mFilePath(inURL), modifiedNSPRPath(nsnull) {}
|
||||
NS_EXPLICIT nsNSPRPath(const nsFilePath& inUnixPath)
|
||||
: mFilePath(inUnixPath), modifiedNSPRPath(nsnull) {}
|
||||
|
||||
virtual ~nsNSPRPath();
|
||||
|
||||
operator const char*() const;
|
||||
// Returns the path
|
||||
// that NSPR file routines expect on each platform.
|
||||
// Concerning constness, this can modify
|
||||
// modifiedNSPRPath, but it's really just "mutable".
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
nsFilePath mFilePath;
|
||||
char* modifiedNSPRPath; // Currently used only on XP_PC
|
||||
}; // class nsNSPRPath
|
||||
|
||||
#endif // _FILESPEC_H_
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
// Functions for nsPersistentFileDescriptor that depend on streams, and so
|
||||
// cannot be made independent of base.
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsError.h"
|
||||
|
||||
class nsPersistentFileDescriptor;
|
||||
class nsInputStream;
|
||||
class nsOutputStream;
|
||||
class nsIInputStream;
|
||||
class nsIOutputStream;
|
||||
class nsFileURL;
|
||||
class nsFileSpec;
|
||||
|
||||
NS_BASE nsOutputStream& operator << (nsOutputStream& s, const nsFileURL& spec);
|
||||
NS_BASE nsresult ReadDescriptor(
|
||||
nsIInputStream* aStream, nsPersistentFileDescriptor&);
|
||||
NS_BASE nsresult WriteDescriptor(
|
||||
nsIOutputStream* aStream,
|
||||
const nsPersistentFileDescriptor&);
|
||||
// writes the data to a file
|
||||
NS_BASE nsInputStream& operator >> (
|
||||
nsInputStream&,
|
||||
nsPersistentFileDescriptor&);
|
||||
// reads the data from a stream (file or string)
|
||||
NS_BASE nsOutputStream& operator << (
|
||||
nsOutputStream&,
|
||||
const nsPersistentFileDescriptor&);
|
||||
// writes the data to a stream (file or string)
|
||||
@@ -19,26 +19,14 @@
|
||||
// First checked in on 98/11/20 by John R. McMullen in the wrong directory.
|
||||
// Checked in again 98/12/04.
|
||||
// Polished version 98/12/08.
|
||||
// Completely rewritten to integrate with nsIInputStream and nsIOutputStream (the
|
||||
// xpcom stream objects.
|
||||
|
||||
//========================================================================================
|
||||
//
|
||||
// Classes defined:
|
||||
//
|
||||
// nsInputStream, nsOutputStream
|
||||
// These are the lightweight STATICALLY LINKED wrappers for
|
||||
// the xpcom objects nsIInputStream and nsIOutputstream.
|
||||
// Possible uses:
|
||||
// If you are implementing a function that accepts one of these xpcom
|
||||
// streams, just make one of these little jobbies on the stack, and
|
||||
// the handy << or >> notation can be yours.
|
||||
//
|
||||
// single-byte char:
|
||||
//
|
||||
// nsInputFileStream, nsOutputFileStream
|
||||
// These are the STATICALLY LINKED wrappers for the file-related
|
||||
// versions of the above.
|
||||
// nsIOFileStream
|
||||
// An input and output file stream attached to the same file.
|
||||
//
|
||||
// This suite provide the following services:
|
||||
//
|
||||
@@ -53,13 +41,13 @@
|
||||
//
|
||||
// Basic example:
|
||||
//
|
||||
// nsFileSpec myPath("/Development/iotest.txt");
|
||||
// nsFilePath myPath("/Development/iotest.txt");
|
||||
//
|
||||
// nsOutputFileStream testStream(myPath);
|
||||
// testStream << "Hello World" << nsEndl;
|
||||
//
|
||||
// 4. Requires streams to be constructed using typesafe nsFileSpec specifier
|
||||
// (not the notorious and bug prone const char*), namely nsFileSpec. See
|
||||
// 4. Requires streams to be constructed using typesafe nsFilePath specifier
|
||||
// (not the notorious and bug prone const char*), namely nsFilePath. See
|
||||
// nsFileSpec.h for more details.
|
||||
//
|
||||
// 5. Fixes a bug that have been there for a long time, and
|
||||
@@ -85,15 +73,7 @@
|
||||
#else
|
||||
#include "prio.h"
|
||||
#endif
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIFileStream.h"
|
||||
|
||||
// Defined elsewhere
|
||||
class nsFileSpec;
|
||||
class nsString;
|
||||
class nsIInputStream;
|
||||
class nsIOutputStream;
|
||||
#include "nsFileSpec.h"
|
||||
|
||||
//========================================================================================
|
||||
// Compiler-specific macros, as needed
|
||||
@@ -153,591 +133,200 @@ using std::ostream;
|
||||
//=========================== End Compiler-specific macros ===============================
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsInputStream
|
||||
// This is a convenience class, for use on the STACK ("new" junkies: get detoxed first).
|
||||
// Given a COM-style stream, this allows you to use the >> operators. It also acquires and
|
||||
// reference counts its stream.
|
||||
// Please read the comments at the top of this file
|
||||
class NS_BASE nsBasicFileStream
|
||||
//========================================================================================
|
||||
{
|
||||
public:
|
||||
nsInputStream(nsIInputStream* inStream)
|
||||
: mInputStream(do_QueryInterface(inStream))
|
||||
, mEOF(PR_FALSE)
|
||||
{}
|
||||
virtual ~nsInputStream();
|
||||
|
||||
nsCOMPtr<nsIInputStream> GetIStream() const
|
||||
{
|
||||
return mInputStream;
|
||||
}
|
||||
PRBool eof() const { return get_at_eof(); }
|
||||
char get();
|
||||
void close()
|
||||
{
|
||||
mInputStream->Close();
|
||||
}
|
||||
PRInt32 read(void* s, PRInt32 n);
|
||||
nsBasicFileStream();
|
||||
nsBasicFileStream(PRFileDesc* desc, int nsprMode);
|
||||
nsBasicFileStream(
|
||||
const nsFilePath& inFile,
|
||||
int nsprMode,
|
||||
PRIntn accessMode);
|
||||
virtual ~nsBasicFileStream();
|
||||
|
||||
// Input streamers. Add more as needed (int&, unsigned int& etc). (but you have to
|
||||
// add delegators to the derived classes, too, because these operators don't inherit).
|
||||
nsInputStream& operator >> (char& ch);
|
||||
|
||||
// Support manipulators
|
||||
nsInputStream& operator >> (nsInputStream& (*pf)(nsInputStream&))
|
||||
inline PRBool is_open() const { return mFileDesc != 0; }
|
||||
void open(
|
||||
const nsFilePath& inFile,
|
||||
int nsprMode,
|
||||
PRIntn accessMode);
|
||||
void close();
|
||||
PRIntn tell() const;
|
||||
void seek(PRInt32 offset) { seek(PR_SEEK_SET, offset); }
|
||||
void seek(PRSeekWhence whence, PRInt32 offset);
|
||||
PRBool eof() const { return mEOF; }
|
||||
PRBool failed() const { return mFailed; }
|
||||
// call PR_GetError() for details
|
||||
protected:
|
||||
|
||||
PRFileDesc* GetFileDescriptor() const { return mFileDesc; }
|
||||
|
||||
protected:
|
||||
|
||||
friend class nsBasicInStream;
|
||||
friend class nsBasicOutStream;
|
||||
|
||||
PRFileDesc* mFileDesc;
|
||||
int mNSPRMode;
|
||||
PRBool mFailed;
|
||||
PRBool mEOF;
|
||||
}; // class nsBasicFileStream
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsBasicInStream
|
||||
//========================================================================================
|
||||
{
|
||||
protected:
|
||||
nsBasicInStream(nsBasicFileStream& inStream, istream* stream);
|
||||
|
||||
public:
|
||||
|
||||
nsBasicInStream& operator >> (nsBasicInStream& (*pf)(nsBasicInStream&))
|
||||
{
|
||||
return pf(*this);
|
||||
}
|
||||
}
|
||||
void get(char& c);
|
||||
PRInt32 read(void* s, PRInt32 n);
|
||||
PRBool readline(char* s, PRInt32 n);
|
||||
// Result always null-terminated
|
||||
// false result indicates line was truncated
|
||||
// to fit buffer, or an error occurred.
|
||||
|
||||
// Input streamers. Add more as needed
|
||||
nsBasicInStream& operator >> (char& ch);
|
||||
|
||||
istream* GetStandardStream() const { return mStdStream; }
|
||||
|
||||
protected:
|
||||
|
||||
// These certainly need to be overridden, they give the best shot we can at detecting
|
||||
// eof in a simple nsIInputStream.
|
||||
virtual void set_at_eof(PRBool atEnd)
|
||||
{
|
||||
mEOF = atEnd;
|
||||
}
|
||||
virtual PRBool get_at_eof() const
|
||||
{
|
||||
return mEOF;
|
||||
}
|
||||
private:
|
||||
|
||||
nsInputStream& operator >> (char* buf); // TOO DANGEROUS. DON'T DEFINE.
|
||||
|
||||
// DATA
|
||||
protected:
|
||||
nsCOMPtr<nsIInputStream> mInputStream;
|
||||
PRBool mEOF;
|
||||
}; // class nsInputStream
|
||||
|
||||
typedef nsInputStream nsBasicInStream; // historic support for this name
|
||||
nsBasicFileStream& mBase;
|
||||
istream* mStdStream;
|
||||
}; // class nsBasicInStream
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsOutputStream
|
||||
// This is a convenience class, for use on the STACK ("new" junkies, get detoxed first).
|
||||
// Given a COM-style stream, this allows you to use the << operators. It also acquires and
|
||||
// reference counts its stream.
|
||||
// Please read the comments at the top of this file
|
||||
class NS_BASE nsBasicOutStream
|
||||
//========================================================================================
|
||||
{
|
||||
protected:
|
||||
|
||||
nsBasicOutStream(nsBasicFileStream& inStream, ostream* stream);
|
||||
|
||||
public:
|
||||
nsOutputStream() {}
|
||||
nsOutputStream(nsIOutputStream* inStream)
|
||||
: mOutputStream(do_QueryInterface(inStream))
|
||||
{}
|
||||
|
||||
virtual ~nsOutputStream();
|
||||
|
||||
nsCOMPtr<nsIOutputStream> GetIStream() const
|
||||
nsBasicOutStream& operator << (nsBasicOutStream& (*pf)(nsBasicOutStream&))
|
||||
{
|
||||
return mOutputStream;
|
||||
}
|
||||
void close()
|
||||
{
|
||||
mOutputStream->Close();
|
||||
return pf(*this);
|
||||
}
|
||||
void put(char c);
|
||||
PRInt32 write(const void* s, PRInt32 n);
|
||||
virtual void flush();
|
||||
|
||||
// Output streamers. Add more as needed (but you have to add delegators to the derived
|
||||
// classes, too, because these operators don't inherit).
|
||||
nsOutputStream& operator << (const char* buf);
|
||||
nsOutputStream& operator << (char ch);
|
||||
nsOutputStream& operator << (short val);
|
||||
nsOutputStream& operator << (unsigned short val);
|
||||
nsOutputStream& operator << (long val);
|
||||
nsOutputStream& operator << (unsigned long val);
|
||||
nsOutputStream& operator << (int val);
|
||||
nsOutputStream& operator << (unsigned int val);
|
||||
|
||||
// Support manipulators
|
||||
nsOutputStream& operator << (nsOutputStream& (*pf)(nsOutputStream&))
|
||||
{
|
||||
return pf(*this);
|
||||
}
|
||||
|
||||
// DATA
|
||||
protected:
|
||||
nsCOMPtr<nsIOutputStream> mOutputStream;
|
||||
}; // class nsOutputStream
|
||||
|
||||
typedef nsOutputStream nsBasicOutStream; // Historic support for this name
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsErrorProne
|
||||
// Common (virtual) base class for remembering errors on demand
|
||||
//========================================================================================
|
||||
{
|
||||
public:
|
||||
nsErrorProne() // for delayed opening
|
||||
: mResult(NS_OK)
|
||||
{
|
||||
}
|
||||
PRBool failed() const
|
||||
{
|
||||
return NS_FAILED(mResult);
|
||||
}
|
||||
|
||||
// DATA
|
||||
protected:
|
||||
nsresult mResult;
|
||||
}; // class nsErrorProne
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsFileClient
|
||||
// Because COM does not allow us to write functions which return a boolean value etc,
|
||||
// this class is here to take care of the tedious "declare variable then call with
|
||||
// the address of the variable" chores.
|
||||
//========================================================================================
|
||||
: public virtual nsErrorProne
|
||||
{
|
||||
public:
|
||||
nsFileClient(const nsCOMPtr<nsIFile>& inFile)
|
||||
: mFile(do_QueryInterface(inFile))
|
||||
{
|
||||
}
|
||||
virtual ~nsFileClient() {}
|
||||
|
||||
void open(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode,
|
||||
PRIntn accessMode)
|
||||
{
|
||||
if (mFile)
|
||||
mResult = mFile->Open(inFile, nsprMode, accessMode);
|
||||
}
|
||||
PRBool is_open() const
|
||||
{
|
||||
PRBool result = PR_FALSE;
|
||||
if (mFile)
|
||||
mFile->GetIsOpen(&result);
|
||||
return result;
|
||||
}
|
||||
PRBool is_file() const
|
||||
{
|
||||
return mFile ? PR_TRUE : PR_FALSE;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
nsFileClient() // for delayed opening
|
||||
{
|
||||
}
|
||||
// DATA
|
||||
protected:
|
||||
nsCOMPtr<nsIFile> mFile;
|
||||
}; // class nsFileClient
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsRandomAccessStoreClient
|
||||
// Because COM does not allow us to write functions which return a boolean value etc,
|
||||
// this class is here to take care of the tedious "declare variable then call with
|
||||
// the address of the variable" chores.
|
||||
//========================================================================================
|
||||
: public virtual nsErrorProne
|
||||
{
|
||||
public:
|
||||
nsRandomAccessStoreClient() // for delayed opening
|
||||
{
|
||||
}
|
||||
nsRandomAccessStoreClient(const nsCOMPtr<nsIRandomAccessStore>& inStore)
|
||||
: mStore(do_QueryInterface(inStore))
|
||||
{
|
||||
}
|
||||
virtual ~nsRandomAccessStoreClient() {}
|
||||
void flush();
|
||||
|
||||
void seek(PRInt32 offset)
|
||||
{
|
||||
seek(PR_SEEK_SET, offset);
|
||||
}
|
||||
// Output streamers. Add more as needed
|
||||
nsBasicOutStream& operator << (const char* buf);
|
||||
nsBasicOutStream& operator << (char ch);
|
||||
nsBasicOutStream& operator << (short val);
|
||||
nsBasicOutStream& operator << (unsigned short val);
|
||||
nsBasicOutStream& operator << (long val);
|
||||
nsBasicOutStream& operator << (unsigned long val);
|
||||
|
||||
void seek(PRSeekWhence whence, PRInt32 offset)
|
||||
{
|
||||
set_at_eof(PR_FALSE);
|
||||
if (mStore)
|
||||
mResult = mStore->Seek(whence, offset);
|
||||
}
|
||||
PRIntn tell()
|
||||
{
|
||||
PRIntn result = -1;
|
||||
if (mStore)
|
||||
mResult = mStore->Tell(&result);
|
||||
return result;
|
||||
}
|
||||
ostream* GetStandardStream() const { return mStdStream; }
|
||||
|
||||
protected:
|
||||
|
||||
virtual PRBool get_at_eof() const
|
||||
{
|
||||
PRBool result = PR_TRUE;
|
||||
if (mStore)
|
||||
mStore->GetAtEOF(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual void set_at_eof(PRBool atEnd)
|
||||
{
|
||||
if (mStore)
|
||||
mStore->SetAtEOF(atEnd);
|
||||
}
|
||||
|
||||
// DATA
|
||||
protected:
|
||||
nsCOMPtr<nsIRandomAccessStore> mStore;
|
||||
}; // class nsRandomAccessStoreClient
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsRandomAccessInputStream
|
||||
// Please read the comments at the top of this file
|
||||
//========================================================================================
|
||||
: public nsRandomAccessStoreClient
|
||||
, public nsInputStream
|
||||
{
|
||||
public:
|
||||
nsRandomAccessInputStream(nsIInputStream* inStream)
|
||||
: nsRandomAccessStoreClient(do_QueryInterface(inStream))
|
||||
, nsInputStream(inStream)
|
||||
{
|
||||
}
|
||||
PRBool readline(char* s, PRInt32 n);
|
||||
// Result always null-terminated.
|
||||
// Check eof() before each call.
|
||||
// CAUTION: false result only indicates line was truncated
|
||||
// to fit buffer, or an error occurred (OTHER THAN eof).
|
||||
|
||||
// Input streamers. Unfortunately, they don't inherit!
|
||||
nsInputStream& operator >> (char& ch)
|
||||
{ return nsInputStream::operator >>(ch); }
|
||||
nsInputStream& operator >> (nsInputStream& (*pf)(nsInputStream&))
|
||||
{ return nsInputStream::operator >>(pf); }
|
||||
|
||||
protected:
|
||||
nsRandomAccessInputStream()
|
||||
: nsInputStream(nsnull)
|
||||
{
|
||||
}
|
||||
|
||||
virtual PRBool get_at_eof() const
|
||||
{
|
||||
return nsRandomAccessStoreClient::get_at_eof();
|
||||
}
|
||||
|
||||
virtual void set_at_eof(PRBool atEnd)
|
||||
{
|
||||
nsRandomAccessStoreClient::set_at_eof(atEnd);
|
||||
}
|
||||
|
||||
}; // class nsRandomAccessInputStream
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsInputStringStream
|
||||
//========================================================================================
|
||||
: public nsRandomAccessInputStream
|
||||
{
|
||||
public:
|
||||
nsInputStringStream(const char* stringToRead);
|
||||
nsInputStringStream(const nsString& stringToRead);
|
||||
|
||||
// Input streamers. Unfortunately, they don't inherit!
|
||||
nsInputStream& operator >> (char& ch)
|
||||
{ return nsInputStream::operator >>(ch); }
|
||||
nsInputStream& operator >> (nsInputStream& (*pf)(nsInputStream&))
|
||||
{ return nsInputStream::operator >>(pf); }
|
||||
|
||||
}; // class nsInputStringStream
|
||||
nsBasicFileStream& mBase;
|
||||
ostream* mStdStream;
|
||||
}; // class nsBasicOutStream
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsInputFileStream
|
||||
// Please read the comments at the top of this file
|
||||
//========================================================================================
|
||||
: public nsRandomAccessInputStream
|
||||
, public nsFileClient
|
||||
: public nsBasicFileStream
|
||||
, public nsBasicInStream
|
||||
{
|
||||
public:
|
||||
enum { kDefaultMode = PR_RDONLY };
|
||||
nsInputFileStream(nsIInputStream* inStream)
|
||||
: nsRandomAccessInputStream(inStream)
|
||||
, nsFileClient(do_QueryInterface(inStream))
|
||||
, mFileInputStream(do_QueryInterface(inStream))
|
||||
{
|
||||
}
|
||||
nsInputFileStream(istream* stream = CONSOLE_IN);
|
||||
nsInputFileStream(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode = kDefaultMode,
|
||||
PRIntn accessMode = 00700); // <- OCTAL
|
||||
|
||||
void Open(
|
||||
const nsFileSpec& inFile,
|
||||
const nsFilePath& inFile,
|
||||
int nsprMode = kDefaultMode,
|
||||
PRIntn accessMode = 00700) // <- OCTAL
|
||||
: nsBasicFileStream(inFile, nsprMode, accessMode)
|
||||
, nsBasicInStream(*this, 0)
|
||||
{}
|
||||
|
||||
void open(
|
||||
const nsFilePath& inFile,
|
||||
int nsprMode = kDefaultMode,
|
||||
PRIntn accessMode = 00700) // <- OCTAL
|
||||
{
|
||||
if (mFile)
|
||||
mFile->Open(inFile, nsprMode, accessMode);
|
||||
nsBasicFileStream::open(inFile, nsprMode, accessMode);
|
||||
}
|
||||
private:
|
||||
|
||||
// Input streamers. Unfortunately, they don't inherit!
|
||||
nsInputStream& operator >> (char& ch)
|
||||
{ return nsInputStream::operator >>(ch); }
|
||||
nsInputStream& operator >> (nsInputStream& (*pf)(nsInputStream&))
|
||||
{ return nsInputStream::operator >>(pf); }
|
||||
nsInputFileStream& operator >> (char* buf); // TOO DANGEROUS. DON'T DEFINE.
|
||||
|
||||
// DATA
|
||||
protected:
|
||||
nsCOMPtr<nsIFileInputStream> mFileInputStream;
|
||||
}; // class nsInputFileStream
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsRandomAccessOutputStream
|
||||
// Please read the comments at the top of this file
|
||||
//========================================================================================
|
||||
: public nsRandomAccessStoreClient
|
||||
, public nsOutputStream
|
||||
{
|
||||
public:
|
||||
nsRandomAccessOutputStream(nsIOutputStream* inStream)
|
||||
: nsRandomAccessStoreClient(do_QueryInterface(inStream))
|
||||
, nsOutputStream(inStream)
|
||||
{
|
||||
}
|
||||
|
||||
// Output streamers. Unfortunately, they don't inherit!
|
||||
nsOutputStream& operator << (const char* buf)
|
||||
{ return nsOutputStream::operator << (buf); }
|
||||
nsOutputStream& operator << (char ch)
|
||||
{ return nsOutputStream::operator << (ch); }
|
||||
nsOutputStream& operator << (short val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned short val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (long val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned long val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (int val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned int val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (nsOutputStream& (*pf)(nsOutputStream&))
|
||||
{ return nsOutputStream::operator << (pf); }
|
||||
|
||||
protected:
|
||||
nsRandomAccessOutputStream()
|
||||
: nsOutputStream(nsnull)
|
||||
{
|
||||
}
|
||||
}; // class nsRandomAccessOutputStream
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsOutputStringStream
|
||||
//========================================================================================
|
||||
: public nsRandomAccessOutputStream
|
||||
{
|
||||
public:
|
||||
nsOutputStringStream(char*& stringToChange);
|
||||
nsOutputStringStream(nsString& stringToChange);
|
||||
|
||||
// Output streamers. Unfortunately, they don't inherit!
|
||||
nsOutputStream& operator << (const char* buf)
|
||||
{ return nsOutputStream::operator << (buf); }
|
||||
nsOutputStream& operator << (char ch)
|
||||
{ return nsOutputStream::operator << (ch); }
|
||||
nsOutputStream& operator << (short val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned short val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (long val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned long val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (int val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned int val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (nsOutputStream& (*pf)(nsOutputStream&))
|
||||
{ return nsOutputStream::operator << (pf); }
|
||||
|
||||
}; // class nsOutputStringStream
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsOutputFileStream
|
||||
// Please read the comments at the top of this file
|
||||
//========================================================================================
|
||||
: public nsRandomAccessOutputStream
|
||||
, public nsFileClient
|
||||
: public nsBasicFileStream
|
||||
, public nsBasicOutStream
|
||||
{
|
||||
public:
|
||||
enum { kDefaultMode = (PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE) };
|
||||
|
||||
nsOutputFileStream() {}
|
||||
nsOutputFileStream(ostream* stream = CONSOLE_OUT);
|
||||
nsOutputFileStream(
|
||||
const nsFileSpec& inFile,
|
||||
const nsFilePath& inFile,
|
||||
int nsprMode = kDefaultMode,
|
||||
PRIntn accessMode = 00700) // <- OCTAL
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewIOFileStream(
|
||||
&stream,
|
||||
inFile, nsprMode, accessMode)))
|
||||
return;
|
||||
mFile = nsQueryInterface(stream);
|
||||
mOutputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
mFileOutputStream = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
}
|
||||
: nsBasicFileStream(inFile, nsprMode, accessMode)
|
||||
, nsBasicOutStream(*this, 0)
|
||||
{}
|
||||
|
||||
virtual void flush();
|
||||
|
||||
// Output streamers. Unfortunately, they don't inherit!
|
||||
nsOutputStream& operator << (const char* buf)
|
||||
{ return nsOutputStream::operator << (buf); }
|
||||
nsOutputStream& operator << (char ch)
|
||||
{ return nsOutputStream::operator << (ch); }
|
||||
nsOutputStream& operator << (short val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned short val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (long val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned long val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (int val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned int val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (nsOutputStream& (*pf)(nsOutputStream&))
|
||||
{ return nsOutputStream::operator << (pf); }
|
||||
|
||||
// DATA
|
||||
protected:
|
||||
nsCOMPtr<nsIFileOutputStream> mFileOutputStream;
|
||||
inline void open(
|
||||
const nsFilePath& inFile,
|
||||
int nsprMode = kDefaultMode,
|
||||
PRIntn accessMode = 00700) // <- OCTAL
|
||||
{
|
||||
nsBasicFileStream::open(inFile, nsprMode, accessMode);
|
||||
}
|
||||
}; // class nsOutputFileStream
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsOutputConsoleStream
|
||||
// Please read the comments at the top of this file
|
||||
//========================================================================================
|
||||
: public nsOutputFileStream
|
||||
{
|
||||
public:
|
||||
|
||||
nsOutputConsoleStream()
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewOutputConsoleStream(&stream)))
|
||||
return;
|
||||
mFile = nsQueryInterface(stream);
|
||||
mOutputStream = nsQueryInterface(stream);
|
||||
mFileOutputStream = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
}
|
||||
|
||||
// Output streamers. Unfortunately, they don't inherit!
|
||||
nsOutputStream& operator << (const char* buf)
|
||||
{ return nsOutputStream::operator << (buf); }
|
||||
nsOutputStream& operator << (char ch)
|
||||
{ return nsOutputStream::operator << (ch); }
|
||||
nsOutputStream& operator << (short val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned short val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (long val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned long val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (int val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned int val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (nsOutputStream& (*pf)(nsOutputStream&))
|
||||
{ return nsOutputStream::operator << (pf); }
|
||||
|
||||
}; // class nsOutputConsoleStream
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsIOFileStream
|
||||
// Please read the comments at the top of this file
|
||||
//========================================================================================
|
||||
: public nsInputFileStream
|
||||
, public nsOutputStream
|
||||
: public nsBasicFileStream
|
||||
, public nsBasicOutStream
|
||||
, public nsBasicInStream
|
||||
{
|
||||
public:
|
||||
enum { kDefaultMode = (PR_RDWR | PR_CREATE_FILE) };
|
||||
|
||||
nsIOFileStream(
|
||||
nsIInputStream* inInputStream
|
||||
, nsIOutputStream* inOutputStream)
|
||||
: nsInputFileStream(inInputStream)
|
||||
, nsOutputStream(inOutputStream)
|
||||
, mFileOutputStream(do_QueryInterface(inOutputStream))
|
||||
{
|
||||
}
|
||||
nsIOFileStream(
|
||||
const nsFileSpec& inFile,
|
||||
const nsFilePath& inFile,
|
||||
int nsprMode = kDefaultMode,
|
||||
PRIntn accessMode = 00700) // <- OCTAL
|
||||
: nsInputFileStream(nsnull)
|
||||
, nsOutputStream(nsnull)
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewIOFileStream(
|
||||
&stream,
|
||||
inFile, nsprMode, accessMode)))
|
||||
return;
|
||||
mFile = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
mInputStream = nsQueryInterface(stream);
|
||||
mOutputStream = nsQueryInterface(stream);
|
||||
mFileInputStream = nsQueryInterface(stream);
|
||||
mFileOutputStream = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
}
|
||||
: nsBasicFileStream(inFile, nsprMode, accessMode)
|
||||
, nsBasicInStream(*this, 0)
|
||||
, nsBasicOutStream(*this, 0)
|
||||
{}
|
||||
|
||||
virtual void close()
|
||||
inline void open(
|
||||
const nsFilePath& inFile,
|
||||
int nsprMode = kDefaultMode,
|
||||
PRIntn accessMode = 00700) // <- OCTAL
|
||||
{
|
||||
// Doesn't matter which of the two we close:
|
||||
// they're hooked up to the same file.
|
||||
nsInputFileStream::close();
|
||||
nsBasicFileStream::open(inFile, nsprMode, accessMode);
|
||||
}
|
||||
|
||||
// Output streamers. Unfortunately, they don't inherit!
|
||||
nsOutputStream& operator << (const char* buf)
|
||||
{ return nsOutputStream::operator << (buf); }
|
||||
nsOutputStream& operator << (char ch)
|
||||
{ return nsOutputStream::operator << (ch); }
|
||||
nsOutputStream& operator << (short val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned short val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (long val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned long val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (int val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned int val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (nsOutputStream& (*pf)(nsOutputStream&))
|
||||
{ return nsOutputStream::operator << (pf); }
|
||||
|
||||
// Input streamers. Unfortunately, they don't inherit!
|
||||
nsInputStream& operator >> (char& ch)
|
||||
{ return nsInputStream::operator >>(ch); }
|
||||
nsInputStream& operator >> (nsInputStream& (*pf)(nsInputStream&))
|
||||
{ return nsInputStream::operator >>(pf); }
|
||||
|
||||
// DATA
|
||||
protected:
|
||||
nsCOMPtr<nsIFileOutputStream> mFileOutputStream;
|
||||
}; // class nsIOFileStream
|
||||
|
||||
|
||||
//========================================================================================
|
||||
// Manipulators
|
||||
//========================================================================================
|
||||
|
||||
NS_BASE nsOutputStream& nsEndl(nsOutputStream& os); // outputs and FLUSHES.
|
||||
|
||||
NS_BASE nsBasicOutStream& nsEndl(nsBasicOutStream& os);
|
||||
|
||||
|
||||
#endif /* _FILESTREAM_H_ */
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIBuffer_h___
|
||||
#define nsIBuffer_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nscore.h"
|
||||
|
||||
class nsIInputStream;
|
||||
class nsIAllocator;
|
||||
class nsIInputStream;
|
||||
class nsIOutputStream;
|
||||
|
||||
#define NS_IBUFFER_IID \
|
||||
{ /* 1eebb300-fb8b-11d2-9324-00104ba0fd40 */ \
|
||||
0x1eebb300, \
|
||||
0xfb8b, \
|
||||
0x11d2, \
|
||||
{0x93, 0x24, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
|
||||
}
|
||||
|
||||
#define NS_BUFFER_CID \
|
||||
{ /* 5dbe4de0-fbab-11d2-9324-00104ba0fd40 */ \
|
||||
0x5dbe4de0, \
|
||||
0xfbab, \
|
||||
0x11d2, \
|
||||
{0x93, 0x24, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
|
||||
}
|
||||
|
||||
class nsIBuffer : public nsISupports {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IBUFFER_IID);
|
||||
|
||||
NS_IMETHOD Init(PRUint32 growBySize, PRUint32 maxSize,
|
||||
nsIAllocator* allocator) = 0;
|
||||
|
||||
NS_IMETHOD Read(char* toBuf, PRUint32 bufLen, PRUint32 *readCount) = 0;
|
||||
NS_IMETHOD GetReadBuffer(PRUint32 *readBufferLength, char* *result) = 0;
|
||||
|
||||
NS_IMETHOD Write(const char* fromBuf, PRUint32 bufLen, PRUint32 *writeCount) = 0;
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *writeCount) = 0;
|
||||
NS_IMETHOD GetWriteBuffer(PRUint32 *writeBufferLength, char* *result) = 0;
|
||||
NS_IMETHOD SetEOF() = 0;
|
||||
};
|
||||
|
||||
extern NS_BASE nsresult
|
||||
NS_NewBuffer(nsIBuffer* *result,
|
||||
PRUint32 growBySize, PRUint32 maxSize);
|
||||
|
||||
extern NS_BASE nsresult
|
||||
NS_NewPageBuffer(nsIBuffer* *result,
|
||||
PRUint32 growBySize, PRUint32 maxSize);
|
||||
|
||||
extern NS_BASE nsresult
|
||||
NS_NewBufferInputStream(nsIInputStream* *result,
|
||||
nsIBuffer* buffer, PRBool blocking = PR_FALSE);
|
||||
|
||||
extern NS_BASE nsresult
|
||||
NS_NewBufferOutputStream(nsIOutputStream* *result,
|
||||
nsIBuffer* buffer, PRBool blocking = PR_FALSE);
|
||||
|
||||
extern NS_BASE nsresult
|
||||
NS_NewPipe2(nsIInputStream* *inStrResult,
|
||||
nsIOutputStream* *outStrResult,
|
||||
PRUint32 growBySize, PRUint32 maxSize);
|
||||
|
||||
#endif // nsIBuffer_h___
|
||||
@@ -1,58 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIByteBufferInputStream_h___
|
||||
#define nsIByteBufferInputStream_h___
|
||||
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIOutputStream.h"
|
||||
|
||||
#define NS_IBYTEBUFFERINPUTSTREAM_IID \
|
||||
{ /* 40767100-eb9c-11d2-931c-00104ba0fd40 */ \
|
||||
0x40767100, \
|
||||
0xeb9c, \
|
||||
0x11d2, \
|
||||
{0x93, 0x1c, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
|
||||
}
|
||||
|
||||
class nsIByteBufferInputStream : public nsIInputStream {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IBYTEBUFFERINPUTSTREAM_IID);
|
||||
|
||||
NS_IMETHOD Fill(nsIInputStream* stream, PRUint32 *aWriteCount) = 0;
|
||||
|
||||
NS_IMETHOD Fill(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount) = 0;
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern NS_BASE nsresult
|
||||
NS_NewByteBufferInputStream(nsIByteBufferInputStream* *result,
|
||||
PRBool blocking = PR_FALSE,
|
||||
PRUint32 size = 4096);
|
||||
|
||||
extern NS_BASE nsresult
|
||||
NS_NewPipe(nsIInputStream* *inStrResult,
|
||||
nsIOutputStream* *outStrResult,
|
||||
PRBool blocking = PR_TRUE,
|
||||
PRUint32 bufferSize = 4096);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif /* nsByteBufferInputStream_h___ */
|
||||
@@ -1,145 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsIFileStream_h___
|
||||
#define nsIFileStream_h___
|
||||
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "prio.h"
|
||||
|
||||
class nsFileSpec;
|
||||
|
||||
/* a6cf90e8-15b3-11d2-932e-00805f8add32 */
|
||||
#define NS_IFILE_IID \
|
||||
{ 0xa6cf90e8, 0x15b3, 0x11d2, \
|
||||
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
|
||||
|
||||
//========================================================================================
|
||||
class nsIFile
|
||||
// Represents a file, and supports Open.
|
||||
//========================================================================================
|
||||
: public nsISupports
|
||||
{
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IFILE_IID; return iid; }
|
||||
NS_IMETHOD Open(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode,
|
||||
PRIntn accessMode) = 0;
|
||||
// Note: Open() is only needed after
|
||||
// an explicit Close(). All file streams
|
||||
// are automatically opened on construction.
|
||||
NS_IMETHOD GetIsOpen(PRBool* outOpen) = 0;
|
||||
|
||||
}; // class nsIFile
|
||||
|
||||
/* a6cf90e8-15b3-11d2-932e-00805f8add32 */
|
||||
#define NS_IRANDOMACCESS_IID \
|
||||
{ 0xa6cf90eb, 0x15b3, 0x11d2, \
|
||||
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
|
||||
|
||||
//========================================================================================
|
||||
class nsIRandomAccessStore
|
||||
// Supports Seek, Tell etc.
|
||||
//========================================================================================
|
||||
: public nsISupports
|
||||
{
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IRANDOMACCESS_IID; return iid; }
|
||||
NS_IMETHOD Seek(PRSeekWhence whence, PRInt32 offset) = 0;
|
||||
NS_IMETHOD Tell(PRIntn* outWhere) = 0;
|
||||
|
||||
/* "PROTECTED" */
|
||||
NS_IMETHOD GetAtEOF(PRBool* outAtEOF) = 0;
|
||||
NS_IMETHOD SetAtEOF(PRBool inAtEOF) = 0;
|
||||
}; // class nsIRandomAccessStore
|
||||
|
||||
/* a6cf90e6-15b3-11d2-932e-00805f8add32 */
|
||||
#define NS_IFILEINPUTSTREAM_IID \
|
||||
{ 0xa6cf90e6, 0x15b3, 0x11d2, \
|
||||
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
|
||||
|
||||
//========================================================================================
|
||||
class nsIFileInputStream
|
||||
// These are additional file-specific methods that files have, above what
|
||||
// nsIInputStream supports. The current implementation supports both
|
||||
// interfaces.
|
||||
//========================================================================================
|
||||
: public nsIInputStream
|
||||
{
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IFILEINPUTSTREAM_IID; return iid; }
|
||||
}; // class nsIFileInputStream
|
||||
|
||||
/* a6cf90e7-15b3-11d2-932e-00805f8add32 */
|
||||
#define NS_IFILEOUTPUTSTREAM_IID \
|
||||
{ 0xa6cf90e7, 0x15b3, 0x11d2, \
|
||||
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
|
||||
|
||||
//========================================================================================
|
||||
class nsIFileOutputStream
|
||||
// These are additional file-specific methods that files have, above what
|
||||
// nsIOutputStream supports. The current implementation supports both
|
||||
// interfaces.
|
||||
//========================================================================================
|
||||
: public nsIOutputStream
|
||||
{
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IFILEOUTPUTSTREAM_IID; return iid; }
|
||||
}; // class nsIFileOutputStream
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
extern "C" NS_BASE nsresult NS_NewTypicalInputFileStream(
|
||||
nsISupports** aStreamResult,
|
||||
const nsFileSpec& inFile
|
||||
/*Default nsprMode == PR_RDONLY*/
|
||||
/*Default accessmode = 0700 (octal)*/);
|
||||
// Factory method to get an nsInputStream from a file, using most common options
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
extern "C" NS_BASE nsresult NS_NewOutputConsoleStream(
|
||||
nsISupports** aStreamResult);
|
||||
// Factory method to get an nsOutputStream to the console.
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
extern "C" NS_BASE nsresult NS_NewTypicalOutputFileStream(
|
||||
nsISupports** aStreamResult, // will implement all the above interfaces
|
||||
const nsFileSpec& inFile
|
||||
/*default nsprMode= (PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE)*/
|
||||
/*Default accessMode= 0700 (octal)*/);
|
||||
// Factory method to get an nsOutputStream to a file - most common case.
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
extern "C" NS_BASE nsresult NS_NewTypicalIOFileStream(
|
||||
nsISupports** aStreamResult, // will implement all the above interfaces
|
||||
const nsFileSpec& inFile
|
||||
/*default nsprMode = (PR_RDWR | PR_CREATE_FILE)*/
|
||||
/*Default accessMode = 0700 (octal)*/);
|
||||
// Factory method to get an object that implements both nsIInputStream
|
||||
// and nsIOutputStream, associated with a single file.
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
extern "C" NS_BASE nsresult NS_NewIOFileStream(
|
||||
nsISupports** aStreamResult, // will implement all the above interfaces
|
||||
const nsFileSpec& inFile,
|
||||
PRInt32 nsprMode,
|
||||
PRInt32 accessMode);
|
||||
// Factory method to get an object that implements both nsIInputStream
|
||||
// and nsIOutputStream, associated with a single file.
|
||||
|
||||
#endif /* nsIFileStream_h___ */
|
||||
@@ -1,45 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIObserver_h__
|
||||
#define nsIObserver_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nscore.h"
|
||||
|
||||
|
||||
// {DB242E01-E4D9-11d2-9DDE-000064657374}
|
||||
#define NS_IOBSERVER_IID \
|
||||
{ 0xdb242e01, 0xe4d9, 0x11d2, { 0x9d, 0xde, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
|
||||
|
||||
|
||||
// {DB242E03-E4D9-11d2-9DDE-000064657374}
|
||||
#define NS_OBSERVER_CID \
|
||||
{ 0xdb242e03, 0xe4d9, 0x11d2, { 0x9d, 0xde, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
|
||||
|
||||
class nsIObserver : public nsISupports {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IOBSERVER_IID; return iid; }
|
||||
NS_IMETHOD Notify(nsISupports** result) = 0;
|
||||
};
|
||||
|
||||
extern NS_BASE nsresult NS_NewObserver(nsIObserver** anObserver);
|
||||
|
||||
#define NS_OBSERVER_PROGID "component:||netscape|Observer"
|
||||
|
||||
#endif /* nsIObserver_h__ */
|
||||
@@ -1,48 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIObserverList_h__
|
||||
#define nsIObserverList_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIEnumerator.h"
|
||||
#include "nscore.h"
|
||||
|
||||
|
||||
// {E777D482-E6E3-11d2-8ACD-00105A1B8860}
|
||||
#define NS_IOBSERVERLIST_IID \
|
||||
{ 0xe777d482, 0xe6e3, 0x11d2, { 0x8a, 0xcd, 0x0, 0x10, 0x5a, 0x1b, 0x88, 0x60 } }
|
||||
|
||||
// {E777D484-E6E3-11d2-8ACD-00105A1B8860}
|
||||
#define NS_OBSERVERLIST_CID \
|
||||
{ 0xe777d484, 0xe6e3, 0x11d2, { 0x8a, 0xcd, 0x0, 0x10, 0x5a, 0x1b, 0x88, 0x60 } }
|
||||
|
||||
class nsIObserverList : public nsISupports {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IOBSERVERLIST_IID; return iid; }
|
||||
|
||||
NS_IMETHOD AddObserver(nsIObserver** anObserver) = 0;
|
||||
NS_IMETHOD RemoveObserver(nsIObserver** anObserver) = 0;
|
||||
NS_IMETHOD EnumerateObserverList(nsIEnumerator** anEnumerator) = 0;
|
||||
|
||||
};
|
||||
|
||||
extern NS_BASE nsresult NS_NewObserverList(nsIObserverList** anObserverList);
|
||||
|
||||
#endif /* nsIObserverList_h__ */
|
||||
@@ -1,51 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIObserverService_h__
|
||||
#define nsIObserverService_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIObserverList.h"
|
||||
#include "nsString.h"
|
||||
|
||||
|
||||
// {D07F5192-E3D1-11d2-8ACD-00105A1B8860}
|
||||
#define NS_IOBSERVERSERVICE_IID \
|
||||
{ 0xd07f5192, 0xe3d1, 0x11d2, { 0x8a, 0xcd, 0x0, 0x10, 0x5a, 0x1b, 0x88, 0x60 } }
|
||||
|
||||
|
||||
// {D07F5195-E3D1-11d2-8ACD-00105A1B8860}
|
||||
#define NS_OBSERVERSERVICE_CID \
|
||||
{ 0xd07f5195, 0xe3d1, 0x11d2, { 0x8a, 0xcd, 0x0, 0x10, 0x5a, 0x1b, 0x88, 0x60 } }
|
||||
|
||||
|
||||
class nsIObserverService : public nsISupports {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IOBSERVERSERVICE_IID; return iid; }
|
||||
|
||||
NS_IMETHOD AddObserver(nsIObserver** anObserver, nsString* aTopic) = 0;
|
||||
NS_IMETHOD RemoveObserver(nsIObserver** anObserver, nsString* aTopic) = 0;
|
||||
NS_IMETHOD EnumerateObserverList(nsIEnumerator** anEnumerator, nsString* aTopic) = 0;
|
||||
};
|
||||
|
||||
extern NS_BASE nsresult NS_NewObserverService(nsIObserverService** anObserverService);
|
||||
|
||||
#define NS_OBSERVERSERVICE_PROGID "component:||netscape|ObserverService"
|
||||
|
||||
|
||||
#endif /* nsIObserverService_h__ */
|
||||
@@ -1,55 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIPageManager_h__
|
||||
#define nsIPageManager_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
#define NS_PAGEMGR_PAGE_BITS 12 // 4k pages
|
||||
#define NS_PAGEMGR_PAGE_SIZE (1 << NS_PAGEMGR_PAGE_BITS)
|
||||
#define NS_PAGEMGR_PAGE_MASK (NS_PAGEMGR_PAGE_SIZE - 1)
|
||||
#define NS_PAGEMGR_PAGE_COUNT(bytes) (((bytes) + NS_PAGEMGR_PAGE_MASK) >> NS_PAGEMGR_PAGE_BITS)
|
||||
|
||||
#define NS_IPAGEMANAGER_IID \
|
||||
{ /* bea98210-fb7b-11d2-9324-00104ba0fd40 */ \
|
||||
0xbea98210, \
|
||||
0xfb7b, \
|
||||
0x11d2, \
|
||||
{0x93, 0x24, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
|
||||
}
|
||||
|
||||
#define NS_PAGEMANAGER_CID \
|
||||
{ /* cac907e0-fb7b-11d2-9324-00104ba0fd40 */ \
|
||||
0xcac907e0, \
|
||||
0xfb7b, \
|
||||
0x11d2, \
|
||||
{0x93, 0x24, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
|
||||
}
|
||||
|
||||
class nsIPageManager : public nsISupports {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPAGEMANAGER_IID);
|
||||
|
||||
NS_IMETHOD AllocPages(PRUint32 pageCount, void* *result) = 0;
|
||||
|
||||
NS_IMETHOD DeallocPages(PRUint32 pageCount, void* pages) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsIPageManager_h__
|
||||
@@ -19,89 +19,30 @@
|
||||
#ifndef nsIProperties_h___
|
||||
#define nsIProperties_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
#define NS_IPROPERTIES_IID \
|
||||
{ /* f42bc870-dc17-11d2-9311-00e09805570f */ \
|
||||
0xf42bc870, \
|
||||
0xdc17, \
|
||||
0x11d2, \
|
||||
{0x93, 0x11, 0x00, 0xe0, 0x98, 0x05, 0x57, 0x0f} \
|
||||
}
|
||||
|
||||
class nsIProperties : public nsISupports {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IPROPERTIES_IID; return iid; }
|
||||
|
||||
/**
|
||||
* Defines a new property.
|
||||
* @return NS_ERROR_FAILURE if a property is already defined.
|
||||
*/
|
||||
NS_IMETHOD DefineProperty(const char* prop, nsISupports* initialValue) = 0;
|
||||
|
||||
/**
|
||||
* Undefines a property.
|
||||
* @return NS_ERROR_FAILURE if a property is not already defined.
|
||||
*/
|
||||
NS_IMETHOD UndefineProperty(const char* prop) = 0;
|
||||
|
||||
/**
|
||||
* Gets a property.
|
||||
* @return NS_ERROR_FAILURE if a property is not already defined.
|
||||
*/
|
||||
NS_IMETHOD GetProperty(const char* prop, nsISupports* *result) = 0;
|
||||
|
||||
/**
|
||||
* Sets a property.
|
||||
* @return NS_ERROR_FAILURE if a property is not already defined.
|
||||
*/
|
||||
NS_IMETHOD SetProperty(const char* prop, nsISupports* value) = 0;
|
||||
|
||||
/**
|
||||
* @return NS_OK if the property exists with the specified value
|
||||
* @return NS_COMFALSE if the property does not exist, or doesn't have
|
||||
* the specified value (values are compared with ==)
|
||||
*/
|
||||
NS_IMETHOD HasProperty(const char* prop, nsISupports* value) = 0;
|
||||
|
||||
};
|
||||
|
||||
// Returns a default implementation of an nsIProperties object.
|
||||
extern nsresult
|
||||
NS_NewIProperties(nsIProperties* *result);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "nsID.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsString.h"
|
||||
|
||||
// {1A180F60-93B2-11d2-9B8B-00805F8A16D9}
|
||||
#define NS_IPERSISTENTPROPERTIES_IID \
|
||||
#define NS_IPROPERTIES_IID \
|
||||
{ 0x1a180f60, 0x93b2, 0x11d2, \
|
||||
{ 0x9b, 0x8b, 0x0, 0x80, 0x5f, 0x8a, 0x16, 0xd9 } }
|
||||
|
||||
// {2245E573-9464-11d2-9B8B-00805F8A16D9}
|
||||
NS_DECLARE_ID(kPersistentPropertiesCID,
|
||||
NS_DECLARE_ID(kPropertiesCID,
|
||||
0x2245e573, 0x9464, 0x11d2, 0x9b, 0x8b, 0x0, 0x80, 0x5f, 0x8a, 0x16, 0xd9);
|
||||
|
||||
class nsIPersistentProperties : public nsIProperties
|
||||
class nsIProperties : public nsISupports
|
||||
{
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IPERSISTENTPROPERTIES_IID; return iid; }
|
||||
|
||||
NS_IMETHOD Load(nsIInputStream* aIn) = 0;
|
||||
NS_IMETHOD Save(nsIOutputStream* aOut, const nsString& aHeader) = 0;
|
||||
NS_IMETHOD Subclass(nsIPersistentProperties* aSubclass) = 0;
|
||||
|
||||
// XXX these 2 methods will be subsumed by the ones from
|
||||
// nsIProperties once we figure this all out
|
||||
NS_IMETHOD GetProperty(const nsString& aKey, nsString& aValue) = 0;
|
||||
NS_IMETHOD SetProperty(const nsString& aKey, nsString& aNewValue,
|
||||
nsString& aOldValue) = 0;
|
||||
NS_IMETHOD Save(nsIOutputStream* aOut, const nsString& aHeader) = 0;
|
||||
NS_IMETHOD Subclass(nsIProperties* aSubclass) = 0;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // nsIProperties_h___
|
||||
#endif /* nsIProperties_h___ */
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIScriptable_h___
|
||||
#define nsIScriptable_h___
|
||||
|
||||
#include "nsIProperties.h"
|
||||
#include "nsISupportsArray.h"
|
||||
|
||||
#define NS_ISCRIPTABLE_IID \
|
||||
{ /* db941bf0-dc17-11d2-9311-00e09805570f */ \
|
||||
0xdb941bf0, \
|
||||
0xdc17, \
|
||||
0x11d2, \
|
||||
{0x93, 0x11, 0x00, 0xe0, 0x98, 0x05, 0x57, 0x0f} \
|
||||
}
|
||||
|
||||
class nsIScriptable : public nsIProperties {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_ISCRIPTABLE_IID; return iid; }
|
||||
|
||||
NS_IMETHOD Call(const char* command,
|
||||
nsISupportsArray* arguments,
|
||||
nsISupports* *result) = 0;
|
||||
};
|
||||
|
||||
// Returns an implementation of an nsIScriptable that accesses attributes
|
||||
// and invokes methods of the interface specified by aIID on the specified object.
|
||||
extern nsresult
|
||||
NS_NewIScriptable(REFNSIID aIID, nsISupports* object, nsIScriptable* *result);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif /* nsIScriptable_h___ */
|
||||
@@ -1,74 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
|
||||
A reference-counted XPCOM wrapper for the nsStr structure. Allows for
|
||||
efficient passing of string objects through multiple layers.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef nsIString_h__
|
||||
#define nsIString_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsStr.h" // need to include it for eCharSize
|
||||
|
||||
// {4C541410-E0B9-11d2-BDB3-000064657374}
|
||||
#define NS_ISTRING_IID \
|
||||
{ 0x4c541410, 0xe0b9, 0x11d2, { 0xbd, 0xb3, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
|
||||
|
||||
class nsIString : public nsISupports
|
||||
{
|
||||
public:
|
||||
static const nsID& GetIID() { static nsIID iid = NS_ISTRING_IID; return iid; }
|
||||
|
||||
/**
|
||||
* Set the character size to something other than the default character
|
||||
* size. By default, nsIString objects will have kDefaultCharSize (as defined
|
||||
* in nsStr.h) as the default char size for their representation.
|
||||
*/
|
||||
NS_IMETHOD Init(eCharSize aCharSize) = 0;
|
||||
|
||||
/**
|
||||
* Copy the caller's nsStr into the object's internal nsStr by performing an
|
||||
* assignment operation.
|
||||
*/
|
||||
NS_IMETHOD SetStr(nsStr* aStr) = 0;
|
||||
|
||||
/**
|
||||
* Copy the object's internal nsStr into the caller's nsStr struct by performing
|
||||
* an assignment operation.
|
||||
*/
|
||||
NS_IMETHOD GetStr(nsStr* aStr) = 0;
|
||||
|
||||
/**
|
||||
* Return a pointer to the nsIString object's _actual_ string buffer. The caller
|
||||
* must treat this struct as an immutable object (hence the "const" qualifier).
|
||||
* The pointer will become invalid as soon as the nsIString interface is released.
|
||||
*/
|
||||
NS_IMETHOD GetImmutableStr(const nsStr** aStr) = 0;
|
||||
};
|
||||
|
||||
|
||||
PR_EXTERN(nsresult)
|
||||
NS_NewString(nsIString** aString);
|
||||
|
||||
#endif // nsIString_h__
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsIStringStream_h___
|
||||
#define nsIStringStream_h___
|
||||
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsString.h"
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
extern "C" NS_BASE nsresult NS_NewStringInputStream(
|
||||
nsISupports** aStreamResult,
|
||||
const nsString& aStringToRead);
|
||||
// Factory method to get an nsInputStream from a string. Result will implement all the
|
||||
// file stream interfaces in nsIFileStream.h
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
extern "C" NS_BASE nsresult NS_NewStringOutputStream(
|
||||
nsISupports** aStreamResult,
|
||||
nsString& aStringToChange);
|
||||
// Factory method to get an nsOutputStream from a string. Result will implement all the
|
||||
// file stream interfaces in nsIFileStream.h
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
extern "C" NS_BASE nsresult NS_NewCharInputStream(
|
||||
nsISupports** aStreamResult,
|
||||
const char* aStringToRead);
|
||||
// Factory method to get an nsInputStream from a string. Result will implement all the
|
||||
// file stream interfaces in nsIFileStream.h
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
extern "C" NS_BASE nsresult NS_NewCharOutputStream(
|
||||
nsISupports** aStreamResult,
|
||||
char** aStringToChange);
|
||||
// Factory method to get an nsOutputStream to a string. Result will implement all the
|
||||
// file stream interfaces in nsIFileStream.h
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
extern "C" NS_BASE nsresult NS_NewStringIOStream(
|
||||
nsISupports** aStreamResult,
|
||||
nsString& aStringToChange);
|
||||
// Factory method to get an nsOutputStream to a string. Result will implement all the
|
||||
// file stream interfaces in nsIFileStream.h
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
extern "C" NS_BASE nsresult NS_NewCharIOStream(
|
||||
nsISupports** aStreamResult,
|
||||
char** aStringToChange);
|
||||
// Factory method to get an nsOutputStream to a string. Result will implement all the
|
||||
// file stream interfaces in nsIFileStream.h
|
||||
|
||||
#endif /* nsIStringStream_h___ */
|
||||
@@ -1,126 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIThread_h__
|
||||
#define nsIThread_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "prthread.h"
|
||||
#include "nscore.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// XXX regenerate:
|
||||
#define NS_IRUNNABLE_IID \
|
||||
{ /* 677d9a90-93ee-11d2-816a-006008119d7a */ \
|
||||
0x677d9a90, \
|
||||
0x93ee, \
|
||||
0x11d2, \
|
||||
{0x81, 0x6a, 0x00, 0x60, 0x19, 0x11, 0x9d, 0x7a} \
|
||||
}
|
||||
|
||||
class nsIRunnable : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IRUNNABLE_IID);
|
||||
|
||||
NS_IMETHOD Run() = 0;
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// XXX regenerate:
|
||||
#define NS_ITHREAD_IID \
|
||||
{ /* 677d9a90-93ee-11d2-816a-006008119d7a */ \
|
||||
0x677d9a90, \
|
||||
0x93ee, \
|
||||
0x11d2, \
|
||||
{0x81, 0x6a, 0x00, 0x60, 0x29, 0x11, 0x9d, 0x7a} \
|
||||
}
|
||||
|
||||
class nsIThread : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITHREAD_IID);
|
||||
|
||||
// returns the nsIThread for the current thread:
|
||||
static NS_BASE nsresult GetCurrent(nsIThread* *result);
|
||||
|
||||
// returns the nsIThread for an arbitrary PRThread:
|
||||
static NS_BASE nsresult GetIThread(PRThread* prthread, nsIThread* *result);
|
||||
|
||||
NS_IMETHOD Join() = 0;
|
||||
|
||||
NS_IMETHOD GetPriority(PRThreadPriority *result) = 0;
|
||||
NS_IMETHOD SetPriority(PRThreadPriority value) = 0;
|
||||
|
||||
NS_IMETHOD Interrupt() = 0;
|
||||
|
||||
NS_IMETHOD GetScope(PRThreadScope *result) = 0;
|
||||
NS_IMETHOD GetState(PRThreadState *result) = 0;
|
||||
|
||||
NS_IMETHOD GetPRThread(PRThread* *result) = 0;
|
||||
};
|
||||
|
||||
extern NS_BASE nsresult
|
||||
NS_NewThread(nsIThread* *result,
|
||||
nsIRunnable* runnable,
|
||||
PRUint32 stackSize = 0,
|
||||
PRThreadPriority priority = PR_PRIORITY_NORMAL,
|
||||
PRThreadScope scope = PR_GLOBAL_THREAD,
|
||||
PRThreadState state = PR_JOINABLE_THREAD);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// XXX regenerate:
|
||||
#define NS_ITHREADPOOL_IID \
|
||||
{ /* 677d9a90-93ee-11d2-816a-006008119d7a */ \
|
||||
0x677d9a90, \
|
||||
0x93ee, \
|
||||
0x11d2, \
|
||||
{0x81, 0x6a, 0x00, 0x60, 0x39, 0x11, 0x9d, 0x7a} \
|
||||
}
|
||||
|
||||
/**
|
||||
* A thread pool is used to create a group of worker threads that
|
||||
* share in the servicing of requests. Requests are run in the
|
||||
* context of the worker thread.
|
||||
*/
|
||||
class nsIThreadPool : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITHREADPOOL_IID);
|
||||
|
||||
NS_IMETHOD DispatchRequest(nsIRunnable* runnable) = 0;
|
||||
|
||||
NS_IMETHOD ProcessPendingRequests() = 0;
|
||||
|
||||
NS_IMETHOD Shutdown() = 0;
|
||||
};
|
||||
|
||||
extern NS_BASE nsresult
|
||||
NS_NewThreadPool(nsIThreadPool* *result,
|
||||
PRUint32 minThreads, PRUint32 maxThreads,
|
||||
PRUint32 stackSize = 0,
|
||||
PRThreadPriority priority = PR_PRIORITY_NORMAL,
|
||||
PRThreadScope scope = PR_GLOBAL_THREAD);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // nsIThread_h__
|
||||
@@ -1,149 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIVariant_h___
|
||||
#define nsIVariant_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nscore.h"
|
||||
#include "prtime.h"
|
||||
|
||||
enum nsVariantType {
|
||||
// primitive values
|
||||
nsVariantType_PRBool,
|
||||
nsVariantType_PRInt16,
|
||||
nsVariantType_PRUint16,
|
||||
nsVariantType_PRInt32,
|
||||
nsVariantType_PRUint32,
|
||||
nsVariantType_PRInt64,
|
||||
nsVariantType_PRUint64,
|
||||
nsVariantType_float,
|
||||
nsVariantType_PRFloat64,
|
||||
nsVariantType_PRTime,
|
||||
// only pointers after this point -- these will be deleted
|
||||
// when the variant is deleted
|
||||
nsVariantType_voidPtr,
|
||||
nsVariantType_charPtr,
|
||||
nsVariantType_PRUnicharPtr
|
||||
};
|
||||
|
||||
class nsVariantValue {
|
||||
public:
|
||||
nsVariantValue() {}
|
||||
|
||||
// nsVariantValue(PRBool value) { mUnion._PRBool = value; }
|
||||
nsVariantValue(PRInt16 value) { mUnion._PRInt16 = value; }
|
||||
nsVariantValue(PRUint16 value) { mUnion._PRUint16 = value; }
|
||||
nsVariantValue(PRInt32 value) { mUnion._PRInt32 = value; }
|
||||
nsVariantValue(PRUint32 value) { mUnion._PRUint32 = value; }
|
||||
nsVariantValue(PRInt64 value) { mUnion._PRInt64 = value; }
|
||||
nsVariantValue(PRUint64 value) { mUnion._PRUint64 = value; }
|
||||
nsVariantValue(float value) { mUnion._float = value; }
|
||||
nsVariantValue(PRFloat64 value) { mUnion._PRFloat64 = value; }
|
||||
// nsVariantValue(PRTime value) { mUnion._PRTime = value; }
|
||||
nsVariantValue(void* value) { mUnion._voidPtr = value; }
|
||||
nsVariantValue(char* value) { mUnion._charPtr = value; }
|
||||
nsVariantValue(PRUnichar* value) { mUnion._PRUnicharPtr = value; }
|
||||
|
||||
// operator PRBool() { return mUnion._PRBool; }
|
||||
operator PRInt16() { return mUnion._PRInt16; }
|
||||
operator PRUint16() { return mUnion._PRUint16; }
|
||||
operator PRInt32() { return mUnion._PRInt32; }
|
||||
operator PRUint32() { return mUnion._PRUint32; }
|
||||
operator PRInt64() { return mUnion._PRInt64; }
|
||||
operator PRUint64() { return mUnion._PRUint64; }
|
||||
operator float() { return mUnion._float; }
|
||||
operator PRFloat64() { return mUnion._PRFloat64; }
|
||||
// operator PRTime() { return mUnion._PRTime; }
|
||||
operator void*() { return mUnion._voidPtr; }
|
||||
operator const char*() { return mUnion._charPtr; }
|
||||
operator const PRUnichar*() { return mUnion._PRUnicharPtr; }
|
||||
|
||||
friend class nsVariant;
|
||||
protected:
|
||||
union nsVariantValueUnion {
|
||||
PRBool _PRBool;
|
||||
PRInt16 _PRInt16;
|
||||
PRUint16 _PRUint16;
|
||||
PRInt32 _PRInt32;
|
||||
PRUint32 _PRUint32;
|
||||
PRInt64 _PRInt64;
|
||||
PRUint64 _PRUint64;
|
||||
float _float;
|
||||
PRFloat64 _PRFloat64;
|
||||
PRTime _PRTime;
|
||||
void* _voidPtr;
|
||||
char* _charPtr;
|
||||
PRUnichar* _PRUnicharPtr;
|
||||
};
|
||||
|
||||
nsVariantValueUnion mUnion;
|
||||
};
|
||||
|
||||
#define NS_IVARIANT_IID \
|
||||
{ /* 3b5799d0-dc28-11d2-9311-00e09805570f */ \
|
||||
0x3b5799d0, \
|
||||
0xdc28, \
|
||||
0x11d2, \
|
||||
{0x93, 0x11, 0x00, 0xe0, 0x98, 0x05, 0x57, 0x0f} \
|
||||
}
|
||||
|
||||
class nsIVariant : public nsISupports {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IVARIANT_IID; return iid; }
|
||||
|
||||
/**
|
||||
* Gets the type and value of a Variant.
|
||||
* When the value is a pointer type, the pointer points into the variant's
|
||||
* internal storage. It is the caller's responsibility to copy.
|
||||
*/
|
||||
NS_IMETHOD GetValue(nsVariantType *type, nsVariantValue *value) = 0;
|
||||
|
||||
/**
|
||||
* Gets the value of a Variant.
|
||||
* @return NS_ERROR_FAILURE if the value is not of the expected type.
|
||||
* When the value is a pointer type, the pointer points into the variant's
|
||||
* internal storage. It is the caller's responsibility to copy.
|
||||
*/
|
||||
NS_IMETHOD GetValue(nsVariantType expectedType, nsVariantValue *value) = 0;
|
||||
|
||||
/**
|
||||
* Sets the type and value of a Variant.
|
||||
* When the value is a pointer type, the variant takes ownership of the
|
||||
* pointer. When the variant is released, the pointer will be deleted.
|
||||
*/
|
||||
NS_IMETHOD SetValue(nsVariantType type, nsVariantValue& value) = 0;
|
||||
|
||||
/**
|
||||
* Determines whether two variants have the same internal type and value.
|
||||
* @return NS_OK if they are equal
|
||||
* @return NS_COMFALSE if not, or if the other parameter is not an nsIVariant
|
||||
*/
|
||||
NS_IMETHOD Equals(nsISupports* other) = 0;
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
NS_IMETHOD GetDescription(char* *result) = 0;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
extern NS_BASE nsresult
|
||||
NS_NewIVariant(nsVariantType initialType, nsVariantValue& initialValue,
|
||||
nsIVariant* *result);
|
||||
|
||||
#endif // nsIVariant_h___
|
||||
@@ -1,41 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
/* We need this because Solaris' version of qsort is broken and
|
||||
* causes array bounds reads.
|
||||
*/
|
||||
|
||||
#ifndef nsQuickSort_h___
|
||||
#define nsQuickSort_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "prtypes.h"
|
||||
/* Had to pull the following define out of xp_core.h
|
||||
* to avoid including xp_core.h.
|
||||
* That brought in too many header file dependencies.
|
||||
*/
|
||||
NS_BEGIN_EXTERN_C
|
||||
|
||||
PR_EXTERN(void) NS_QuickSort(void *, unsigned int, unsigned int,
|
||||
int (*)(const void *, const void *, void *),
|
||||
void *);
|
||||
|
||||
NS_END_EXTERN_C
|
||||
|
||||
#endif /* nsQuickSort_h___ */
|
||||
@@ -19,11 +19,9 @@
|
||||
#ifndef nsRepeater_h___
|
||||
#define nsRepeater_h___
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
class EventRecord;
|
||||
|
||||
class NS_BASE Repeater {
|
||||
class Repeater {
|
||||
public:
|
||||
|
||||
Repeater();
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _NSSPECIALSYSTEMDIRECTORY_H_
|
||||
#define _NSSPECIALSYSTEMDIRECTORY_H_
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsFileSpec.h"
|
||||
|
||||
#ifdef XP_MAC
|
||||
#include <Types.h>
|
||||
#endif
|
||||
|
||||
// SEE ALSO:
|
||||
// mozilla/xpfe/appshell/public/nsFileLocations.h
|
||||
|
||||
class NS_BASE nsSpecialSystemDirectory : public nsFileSpec
|
||||
{
|
||||
|
||||
public:
|
||||
enum SystemDirectories
|
||||
{
|
||||
OS_DriveDirectory = 1
|
||||
, OS_TemporaryDirectory = 2
|
||||
, OS_CurrentProcessDirectory= 3
|
||||
, OS_CurrentWorkingDirectory= 4
|
||||
|
||||
, Mac_SystemDirectory = 101
|
||||
, Mac_DesktopDirectory = 102
|
||||
, Mac_TrashDirectory = 103
|
||||
, Mac_StartupDirectory = 104
|
||||
, Mac_ShutdownDirectory = 105
|
||||
, Mac_AppleMenuDirectory = 106
|
||||
, Mac_ControlPanelDirectory = 107
|
||||
, Mac_ExtensionDirectory = 108
|
||||
, Mac_FontsDirectory = 109
|
||||
, Mac_PreferencesDirectory = 110
|
||||
, Mac_DocumentsDirectory = 111
|
||||
|
||||
, Win_SystemDirectory = 201
|
||||
, Win_WindowsDirectory = 202
|
||||
|
||||
, Win_HomeDirectory = 203
|
||||
, Win_Desktop = 204
|
||||
, Win_Programs = 205
|
||||
, Win_Controls = 206
|
||||
, Win_Printers = 207
|
||||
, Win_Personal = 208
|
||||
, Win_Favorites = 209
|
||||
, Win_Startup = 210
|
||||
, Win_Recent = 211
|
||||
, Win_Sendto = 212
|
||||
, Win_Bitbucket = 213
|
||||
, Win_Startmenu = 214
|
||||
, Win_Desktopdirectory = 215
|
||||
, Win_Drives = 216
|
||||
, Win_Network = 217
|
||||
, Win_Nethood = 218
|
||||
, Win_Fonts = 219
|
||||
, Win_Templates = 220
|
||||
, Win_Common_Startmenu = 221
|
||||
, Win_Common_Programs = 222
|
||||
, Win_Common_Startup = 223
|
||||
, Win_Common_Desktopdirectory = 224
|
||||
, Win_Appdata = 225
|
||||
, Win_Printhood = 226
|
||||
|
||||
, Unix_LocalDirectory = 301
|
||||
, Unix_LibDirectory = 302
|
||||
, Unix_HomeDirectory = 303
|
||||
};
|
||||
|
||||
//nsSpecialSystemDirectory();
|
||||
nsSpecialSystemDirectory(SystemDirectories aSystemSystemDirectory);
|
||||
|
||||
virtual ~nsSpecialSystemDirectory();
|
||||
|
||||
void operator = (SystemDirectories aSystemSystemDirectory);
|
||||
|
||||
#ifdef XP_MAC
|
||||
void operator = (OSType folderType);
|
||||
nsSpecialSystemDirectory(OSType folderType);
|
||||
#endif
|
||||
|
||||
private:
|
||||
void operator = (const char* inPath) { *(nsFileSpec*)this = inPath; }
|
||||
|
||||
}; // class NS_BASE nsSpecialSystemDirectory
|
||||
|
||||
#endif
|
||||
@@ -14,9 +14,7 @@ nsITimerCallback.h
|
||||
nsIUnicharBuffer.h
|
||||
nsRBTree.h
|
||||
nsIUnicharInputStream.h
|
||||
nsStr.h
|
||||
nsString.h
|
||||
nsString2.h
|
||||
nsVoidArray.h
|
||||
nsUnitConversion.h
|
||||
nsIBaseStream.h
|
||||
@@ -24,5 +22,3 @@ nsIInputStream.h
|
||||
nsIOutputStream.h
|
||||
nsInt64.h
|
||||
nsTime.h
|
||||
nsStr.h
|
||||
nsString2.h
|
||||
|
||||
@@ -24,8 +24,6 @@ include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DEFINES +=-D_IMPL_NS_BASE
|
||||
|
||||
LOCAL_INCLUDES += -I$(topsrcdir)/base/public
|
||||
|
||||
DIRS = $(MOZ_TOOLKIT)
|
||||
|
||||
LIBRARY_NAME = raptorbase
|
||||
@@ -33,37 +31,19 @@ LIBRARY_NAME = raptorbase
|
||||
CPPSRCS = \
|
||||
nsArena.cpp \
|
||||
nsAtomTable.cpp \
|
||||
nsBaseDLL.cpp \
|
||||
nsBTree.cpp \
|
||||
nsByteBuffer.cpp \
|
||||
nsCRT.cpp \
|
||||
nsDeque.cpp \
|
||||
nsEscape.cpp \
|
||||
nsFileSpec.cpp \
|
||||
nsFileSpecStreaming.cpp \
|
||||
nsFileStream.cpp \
|
||||
nsIFileStream.cpp \
|
||||
nsIStringStream.cpp \
|
||||
nsProperties.cpp \
|
||||
nsVariant.cpp \
|
||||
nsRBTree.cpp \
|
||||
nsSizeOfHandler.cpp \
|
||||
nsStr.cpp \
|
||||
nsString.cpp \
|
||||
nsString2.cpp \
|
||||
nsUnicharBuffer.cpp \
|
||||
nsUnicharInputStream.cpp \
|
||||
nsVoidArray.cpp \
|
||||
nsSpecialSystemDirectory.cpp\
|
||||
nsObserverService.cpp \
|
||||
nsObserverList.cpp \
|
||||
nsObserver.cpp \
|
||||
nsQuickSort.cpp \
|
||||
nsPageMgr.cpp \
|
||||
nsBuffer.cpp \
|
||||
nsByteBufferInputStream.cpp \
|
||||
nsThread.cpp \
|
||||
nsPipe.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
@@ -83,9 +63,7 @@ EXPORTS = \
|
||||
nsIUnicharInputStream.h \
|
||||
nsInt64.h \
|
||||
nsRBTree.h \
|
||||
nsStr.h \
|
||||
nsString.h \
|
||||
nsString2.h \
|
||||
nsTime.h \
|
||||
nsVoidArray.h \
|
||||
nsUnitConversion.h \
|
||||
@@ -103,3 +81,5 @@ TARGET = $(LIBARY)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
test:
|
||||
@echo OS_ARCH = $(OS_ARCH)
|
||||
|
||||
@@ -1,894 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/******************************************************************************************
|
||||
MODULE NOTES:
|
||||
|
||||
This file contains the workhorse copy and shift functions used in nsStrStruct.
|
||||
Ultimately, I plan to make the function pointers in this system available for
|
||||
use by external modules. They'll be able to install their own "handlers".
|
||||
Not so, today though.
|
||||
|
||||
*******************************************************************************************/
|
||||
|
||||
#ifndef _BUFFERROUTINES_H
|
||||
#define _BUFFERROUTINES_H
|
||||
|
||||
#include "nsCRT.h"
|
||||
|
||||
#ifndef RICKG_TESTBED
|
||||
#include "nsUnicharUtilCIID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICaseConversion.h"
|
||||
#endif
|
||||
|
||||
|
||||
inline PRUnichar GetUnicharAt(const char* aString,PRUint32 anIndex) {
|
||||
return ((PRUnichar*)aString)[anIndex];
|
||||
}
|
||||
|
||||
inline PRUnichar GetCharAt(const char* aString,PRUint32 anIndex) {
|
||||
return (PRUnichar)aString[anIndex];
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//
|
||||
// This set of methods is used to shift the contents of a char buffer.
|
||||
// The functions are differentiated by shift direction and the underlying charsize.
|
||||
//
|
||||
|
||||
/**
|
||||
* This method shifts single byte characters left by a given amount from an given offset.
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is a ptr to a cstring where left-shift is to be performed
|
||||
* @param aLength is the known length of aDest
|
||||
* @param anOffset is the index into aDest where shifting shall begin
|
||||
* @param aCount is the number of chars to be "cut"
|
||||
*/
|
||||
void ShiftCharsLeft(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCount) {
|
||||
PRUint32 theMax=aLength-anOffset;
|
||||
PRUint32 theLength=(theMax<aCount) ? theMax : aCount;
|
||||
|
||||
char* first= aDest+anOffset+aCount;
|
||||
char* last = aDest+aLength;
|
||||
char* to = aDest+anOffset;
|
||||
|
||||
//now loop over characters, shifting them left...
|
||||
while(first<=last) {
|
||||
*to=*first;
|
||||
to++;
|
||||
first++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method shifts single byte characters right by a given amount from an given offset.
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is a ptr to a cstring where the shift is to be performed
|
||||
* @param aLength is the known length of aDest
|
||||
* @param anOffset is the index into aDest where shifting shall begin
|
||||
* @param aCount is the number of chars to be "inserted"
|
||||
*/
|
||||
void ShiftCharsRight(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCount) {
|
||||
char* last = aDest+aLength;
|
||||
char* first= aDest+anOffset-1;
|
||||
char* to = aDest+aLength+aCount;
|
||||
|
||||
//Copy rightmost chars, up to offset+theDelta...
|
||||
while(first<=last) {
|
||||
*to=*last;
|
||||
to--;
|
||||
last--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method shifts unicode characters by a given amount from an given offset.
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is a ptr to a cstring where the shift is to be performed
|
||||
* @param aLength is the known length of aDest
|
||||
* @param anOffset is the index into aDest where shifting shall begin
|
||||
* @param aCount is the number of chars to be "cut"
|
||||
*/
|
||||
void ShiftDoubleCharsLeft(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCount) {
|
||||
PRUint32 theMax=aLength-anOffset;
|
||||
PRUint32 theLength=(theMax<aCount) ? theMax : aCount;
|
||||
|
||||
PRUnichar* theBuf=(PRUnichar*)aDest;
|
||||
PRUnichar* first= theBuf+anOffset+aCount;
|
||||
PRUnichar* last = theBuf+aLength;
|
||||
PRUnichar* to = theBuf+anOffset;
|
||||
|
||||
//now loop over characters, shifting them left...
|
||||
while(first<=last) {
|
||||
*to=*first;
|
||||
to++;
|
||||
first++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method shifts unicode characters by a given amount from an given offset.
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is a ptr to a cstring where the shift is to be performed
|
||||
* @param aLength is the known length of aDest
|
||||
* @param anOffset is the index into aDest where shifting shall begin
|
||||
* @param aCount is the number of chars to be "inserted"
|
||||
*/
|
||||
void ShiftDoubleCharsRight(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCount) {
|
||||
PRUnichar* theBuf=(PRUnichar*)aDest;
|
||||
PRUnichar* last = theBuf+aLength;
|
||||
PRUnichar* first= theBuf+anOffset-1;
|
||||
PRUnichar* to = theBuf+aLength+aCount;
|
||||
|
||||
//Copy rightmost chars, up to offset+theDelta...
|
||||
while(first<=last) {
|
||||
*to=*last;
|
||||
to--;
|
||||
last--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
typedef void (*ShiftChars)(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCount);
|
||||
ShiftChars gShiftChars[2][2]= {
|
||||
{&ShiftCharsLeft,&ShiftCharsRight},
|
||||
{&ShiftDoubleCharsLeft,&ShiftDoubleCharsRight}
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//
|
||||
// This set of methods is used to copy one buffer onto another.
|
||||
// The functions are differentiated by the size of source and dest character sizes.
|
||||
// WARNING: Your destination buffer MUST be big enough to hold all the source bytes.
|
||||
// We don't validate these ranges here (this should be done in higher level routines).
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* Going 1 to 1 is easy, since we assume ascii. No conversions are necessary.
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the destination buffer
|
||||
* @param aDestOffset is the pos to start copy to in the dest buffer
|
||||
* @param aSource is the source buffer
|
||||
* @param anOffset is the offset to start copying from in the source buffer
|
||||
* @param aCount is the (max) number of chars to copy
|
||||
*/
|
||||
void CopyChars1To1(char* aDest,PRInt32 anDestOffset,const char* aSource,PRUint32 anOffset,PRUint32 aCount) {
|
||||
|
||||
char* to = aDest+anDestOffset;
|
||||
const char* first= aSource+anOffset;
|
||||
const char* last = first+aCount;
|
||||
|
||||
//now loop over characters, shifting them left...
|
||||
while(first<last) {
|
||||
*to=*first;
|
||||
to++;
|
||||
first++;
|
||||
}
|
||||
*to=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Going 1 to 2 requires a conversion from ascii to unicode. This can be expensive.
|
||||
* @param aDest is the destination buffer
|
||||
* @param aDestOffset is the pos to start copy to in the dest buffer
|
||||
* @param aSource is the source buffer
|
||||
* @param anOffset is the offset to start copying from in the source buffer
|
||||
* @param aCount is the (max) number of chars to copy
|
||||
*/
|
||||
void CopyChars1To2(char* aDest,PRInt32 anDestOffset,const char* aSource,PRUint32 anOffset,PRUint32 aCount) {
|
||||
|
||||
PRUnichar* theDest=(PRUnichar*)aDest;
|
||||
PRUnichar* to = theDest+anDestOffset;
|
||||
const char* first= aSource+anOffset;
|
||||
const char* last = first+aCount;
|
||||
|
||||
//now loop over characters, shifting them left...
|
||||
while(first<last) {
|
||||
*to=kIsoLatin1ToUCS2[*first];
|
||||
to++;
|
||||
first++;
|
||||
}
|
||||
*to=0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Going 2 to 1 requires a conversion from unicode down to ascii. This can be lossy.
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the destination buffer
|
||||
* @param aDestOffset is the pos to start copy to in the dest buffer
|
||||
* @param aSource is the source buffer
|
||||
* @param anOffset is the offset to start copying from in the source buffer
|
||||
* @param aCount is the (max) number of chars to copy
|
||||
*/
|
||||
void CopyChars2To1(char* aDest,PRInt32 anDestOffset,const char* aSource,PRUint32 anOffset,PRUint32 aCount) {
|
||||
char* to = aDest+anDestOffset;
|
||||
PRUnichar* theSource=(PRUnichar*)aSource;
|
||||
const PRUnichar* first= theSource+anOffset;
|
||||
const PRUnichar* last = first+aCount;
|
||||
|
||||
//now loop over characters, shifting them left...
|
||||
while(first<last) {
|
||||
if(*first<255)
|
||||
*to=(char)*first;
|
||||
else *to='.';
|
||||
to++;
|
||||
first++;
|
||||
}
|
||||
*to=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Going 2 to 2 is fast and efficient.
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the destination buffer
|
||||
* @param aDestOffset is the pos to start copy to in the dest buffer
|
||||
* @param aSource is the source buffer
|
||||
* @param anOffset is the offset to start copying from in the source buffer
|
||||
* @param aCount is the (max) number of chars to copy
|
||||
*/
|
||||
void CopyChars2To2(char* aDest,PRInt32 anDestOffset,const char* aSource,PRUint32 anOffset,PRUint32 aCount) {
|
||||
PRUnichar* theDest=(PRUnichar*)aDest;
|
||||
PRUnichar* to = theDest+anDestOffset;
|
||||
PRUnichar* theSource=(PRUnichar*)aSource;
|
||||
PRUnichar* from= theSource+anOffset;
|
||||
|
||||
memcpy((void*)to,(void*)from,aCount*2);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
typedef void (*CopyChars)(char* aDest,PRInt32 anDestOffset,const char* aSource,PRUint32 anOffset,PRUint32 aCount);
|
||||
|
||||
CopyChars gCopyChars[2][2]={
|
||||
{&CopyChars1To1,&CopyChars1To2},
|
||||
{&CopyChars2To1,&CopyChars2To2}
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//
|
||||
// This set of methods is used to search a buffer looking for a char.
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* This methods cans the given buffer for the given char
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aDest is the buffer to be searched
|
||||
* @param aLength is the size (in char-units, not bytes) of the buffer
|
||||
* @param anOffset is the start pos to begin searching
|
||||
* @param aChar is the target character we're looking for
|
||||
* @param aIgnorecase tells us whether to use a case sensitive search
|
||||
* @return index of pos if found, else -1 (kNotFound)
|
||||
*/
|
||||
inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=anOffset;theIndex<aLength;theIndex++){
|
||||
PRUnichar theChar=GetCharAt(aDest,theIndex);
|
||||
if(aIgnoreCase)
|
||||
theChar=nsCRT::ToUpper(theChar);
|
||||
if(theChar==theCmpChar)
|
||||
return theIndex;
|
||||
}
|
||||
return kNotFound;
|
||||
}
|
||||
|
||||
/**
|
||||
* This methods cans the given buffer for the given char
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aDest is the buffer to be searched
|
||||
* @param aLength is the size (in char-units, not bytes) of the buffer
|
||||
* @param anOffset is the start pos to begin searching
|
||||
* @param aChar is the target character we're looking for
|
||||
* @param aIgnorecase tells us whether to use a case sensitive search
|
||||
* @return index of pos if found, else -1 (kNotFound)
|
||||
*/
|
||||
inline PRInt32 FindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=anOffset;theIndex<aLength;theIndex++){
|
||||
PRUnichar theChar=GetUnicharAt(aDest,theIndex);
|
||||
if(aIgnoreCase)
|
||||
theChar=nsCRT::ToUpper(theChar);
|
||||
if(theChar==theCmpChar)
|
||||
return theIndex;
|
||||
}
|
||||
return kNotFound;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This methods cans the given buffer (in reverse) for the given char
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aDest is the buffer to be searched
|
||||
* @param aLength is the size (in char-units, not bytes) of the buffer
|
||||
* @param anOffset is the start pos to begin searching
|
||||
* @param aChar is the target character we're looking for
|
||||
* @param aIgnorecase tells us whether to use a case sensitive search
|
||||
* @return index of pos if found, else -1 (kNotFound)
|
||||
*/
|
||||
inline PRInt32 RFindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=aLength-1;theIndex>=0;theIndex--){
|
||||
PRUnichar theChar=GetCharAt(aDest,theIndex);
|
||||
if(aIgnoreCase)
|
||||
theChar=nsCRT::ToUpper(theChar);
|
||||
if(theChar==theCmpChar)
|
||||
return theIndex;
|
||||
}
|
||||
return kNotFound;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This methods cans the given buffer for the given char
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aDest is the buffer to be searched
|
||||
* @param aLength is the size (in char-units, not bytes) of the buffer
|
||||
* @param anOffset is the start pos to begin searching
|
||||
* @param aChar is the target character we're looking for
|
||||
* @param aIgnorecase tells us whether to use a case sensitive search
|
||||
* @return index of pos if found, else -1 (kNotFound)
|
||||
*/
|
||||
inline PRInt32 RFindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=aLength-1;theIndex>=0;theIndex--){
|
||||
PRUnichar theChar=GetUnicharAt(aDest,theIndex);
|
||||
if(aIgnoreCase)
|
||||
theChar=nsCRT::ToUpper(theChar);
|
||||
if(theChar==theCmpChar)
|
||||
return theIndex;
|
||||
}
|
||||
return kNotFound;
|
||||
}
|
||||
|
||||
typedef PRInt32 (*FindChars)(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase);
|
||||
FindChars gFindChars[]={&FindChar1,&FindChar2};
|
||||
FindChars gRFindChars[]={&RFindChar1,&RFindChar2};
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//
|
||||
// This set of methods is used to compare one buffer onto another.
|
||||
// The functions are differentiated by the size of source and dest character sizes.
|
||||
// WARNING: Your destination buffer MUST be big enough to hold all the source bytes.
|
||||
// We don't validate these ranges here (this should be done in higher level routines).
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* This method compares the data in one buffer with another
|
||||
* @update gess 01/04/99
|
||||
* @param aStr1 is the first buffer to be compared
|
||||
* @param aStr2 is the 2nd buffer to be compared
|
||||
* @param aCount is the number of chars to compare
|
||||
* @param aIgnorecase tells us whether to use a case-sensitive comparison
|
||||
* @return -1,0,1 depending on <,==,>
|
||||
*/
|
||||
PRInt32 Compare1To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
|
||||
PRInt32 result=0;
|
||||
if(aIgnoreCase)
|
||||
result=nsCRT::strncasecmp(aStr1,aStr2,aCount);
|
||||
else result=strncmp(aStr1,aStr2,aCount);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method compares the data in one buffer with another
|
||||
* @update gess 01/04/99
|
||||
* @param aStr1 is the first buffer to be compared
|
||||
* @param aStr2 is the 2nd buffer to be compared
|
||||
* @param aCount is the number of chars to compare
|
||||
* @param aIgnorecase tells us whether to use a case-sensitive comparison
|
||||
* @return -1,0,1 depending on <,==,>
|
||||
*/
|
||||
PRInt32 Compare2To2(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
|
||||
PRInt32 result=0;
|
||||
if(aIgnoreCase)
|
||||
result=nsCRT::strncasecmp((PRUnichar*)aStr1,(PRUnichar*)aStr2,aCount);
|
||||
else result=nsCRT::strncmp((PRUnichar*)aStr1,(PRUnichar*)aStr2,aCount);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method compares the data in one buffer with another
|
||||
* @update gess 01/04/99
|
||||
* @param aStr1 is the first buffer to be compared
|
||||
* @param aStr2 is the 2nd buffer to be compared
|
||||
* @param aCount is the number of chars to compare
|
||||
* @param aIgnorecase tells us whether to use a case-sensitive comparison
|
||||
* @return -1,0,1 depending on <,==,>
|
||||
*/
|
||||
PRInt32 Compare2To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
|
||||
PRInt32 result;
|
||||
if(aIgnoreCase)
|
||||
result=nsCRT::strncasecmp((PRUnichar*)aStr1,aStr2,aCount);
|
||||
else result=nsCRT::strncmp((PRUnichar*)aStr1,aStr2,aCount);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method compares the data in one buffer with another
|
||||
* @update gess 01/04/99
|
||||
* @param aStr1 is the first buffer to be compared
|
||||
* @param aStr2 is the 2nd buffer to be compared
|
||||
* @param aCount is the number of chars to compare
|
||||
* @param aIgnorecase tells us whether to use a case-sensitive comparison
|
||||
* @return -1,0,1 depending on <,==,>
|
||||
*/
|
||||
PRInt32 Compare1To2(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
|
||||
PRInt32 result;
|
||||
if(aIgnoreCase)
|
||||
result=nsCRT::strncasecmp((PRUnichar*)aStr2,aStr1,aCount)*-1;
|
||||
else result=nsCRT::strncasecmp((PRUnichar*)aStr2,aStr1,aCount)*-1;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
typedef PRInt32 (*CompareChars)(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
|
||||
CompareChars gCompare[2][2]={
|
||||
{&Compare1To1,&Compare1To2},
|
||||
{&Compare2To1,&Compare2To2},
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//
|
||||
// This set of methods is used to convert the case of strings...
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* This method performs a case conversion the data in the given buffer
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the buffer to be case shifted
|
||||
* @param aCount is the number of chars to compare
|
||||
* @param aToUpper tells us whether to convert to upper or lower
|
||||
* @return 0
|
||||
*/
|
||||
PRInt32 ConvertCase1(char* aString,PRUint32 aCount,PRBool aToUpper){
|
||||
PRInt32 result=0;
|
||||
|
||||
typedef char chartype;
|
||||
chartype* cp = (chartype*)aString;
|
||||
chartype* end = cp + aCount-1;
|
||||
while (cp <= end) {
|
||||
chartype ch = *cp;
|
||||
if(aToUpper) {
|
||||
if ((ch >= 'a') && (ch <= 'z')) {
|
||||
*cp = 'A' + (ch - 'a');
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ((ch >= 'A') && (ch <= 'Z')) {
|
||||
*cp = 'a' + (ch - 'A');
|
||||
}
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef RICKG_TESTBED
|
||||
class HandleCaseConversionShutdown3 : public nsIShutdownListener {
|
||||
public :
|
||||
NS_IMETHOD OnShutdown(const nsCID& cid, nsISupports* service);
|
||||
HandleCaseConversionShutdown3(void) { NS_INIT_REFCNT(); }
|
||||
virtual ~HandleCaseConversionShutdown3(void) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
};
|
||||
|
||||
static NS_DEFINE_CID(kUnicharUtilCID, NS_UNICHARUTIL_CID);
|
||||
static NS_DEFINE_IID(kICaseConversionIID, NS_ICASECONVERSION_IID);
|
||||
static NS_DEFINE_IID(kIShutdownListenerIID, NS_ISHUTDOWNLISTENER_IID);
|
||||
static nsICaseConversion * gCaseConv = 0;
|
||||
|
||||
NS_IMPL_ISUPPORTS(HandleCaseConversionShutdown3, kIShutdownListenerIID);
|
||||
|
||||
nsresult HandleCaseConversionShutdown3::OnShutdown(const nsCID& cid, nsISupports* service) {
|
||||
if (cid.Equals(kUnicharUtilCID)) {
|
||||
NS_ASSERTION(service == gCaseConv, "wrong service!");
|
||||
if(gCaseConv){
|
||||
gCaseConv->Release();
|
||||
gCaseConv = 0;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
class CCaseConversionServiceInitializer {
|
||||
public:
|
||||
CCaseConversionServiceInitializer(){
|
||||
mListener = new HandleCaseConversionShutdown3();
|
||||
if(mListener){
|
||||
mListener->AddRef();
|
||||
nsresult result=nsServiceManager::GetService(kUnicharUtilCID, kICaseConversionIID,(nsISupports**) &gCaseConv, mListener);
|
||||
}
|
||||
}
|
||||
protected:
|
||||
HandleCaseConversionShutdown3* mListener;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* This method performs a case conversion the data in the given buffer
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the buffer to be case shifted
|
||||
* @param aCount is the number of chars to compare
|
||||
* @param aToUpper tells us whether to convert to upper or lower
|
||||
* @return 0
|
||||
*/
|
||||
PRInt32 ConvertCase2(char* aString,PRUint32 aCount,PRBool aToUpper){
|
||||
PRUnichar* cp = (PRUnichar*)aString;
|
||||
PRUnichar* end = cp + aCount-1;
|
||||
PRInt32 result=0;
|
||||
|
||||
#ifndef RICKG_TESTBED
|
||||
static CCaseConversionServiceInitializer gCaseConversionServiceInitializer;
|
||||
|
||||
// I18N code begin
|
||||
if(gCaseConv) {
|
||||
nsresult err=(aToUpper) ? gCaseConv->ToUpper(cp, cp, aCount) : gCaseConv->ToLower(cp, cp, aCount);
|
||||
if(NS_SUCCEEDED(err))
|
||||
return 0;
|
||||
}
|
||||
// I18N code end
|
||||
#endif
|
||||
|
||||
|
||||
while (cp <= end) {
|
||||
PRUnichar ch = *cp;
|
||||
if(aToUpper) {
|
||||
if ((ch >= 'a') && (ch <= 'z')) {
|
||||
*cp = 'A' + (ch - 'a');
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ((ch >= 'A') && (ch <= 'Z')) {
|
||||
*cp = 'a' + (ch - 'A');
|
||||
}
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
typedef PRInt32 (*CaseConverters)(char*,PRUint32,PRBool);
|
||||
CaseConverters gCaseConverters[]={&ConvertCase1,&ConvertCase2};
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//
|
||||
// This set of methods is used strip chars from a given buffer...
|
||||
//
|
||||
|
||||
/**
|
||||
* This method removes chars (given in aSet) from the given buffer
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the buffer to be manipulated
|
||||
* @param anOffset is starting pos in buffer for manipulation
|
||||
* @param aCount is the number of chars to compare
|
||||
* @param aSet tells us which chars to remove from given buffer
|
||||
* @return the new length of the given buffer
|
||||
*/
|
||||
PRInt32 StripChars1(char* aString,PRUint32 anOffset,PRUint32 aCount,const char* aSet){
|
||||
PRInt32 result=0;
|
||||
|
||||
typedef char chartype;
|
||||
chartype* from = (chartype*)&aString[anOffset];
|
||||
chartype* end = (chartype*)from + aCount-1;
|
||||
chartype* to = from;
|
||||
|
||||
if(aSet){
|
||||
PRUint32 aSetLen=strlen(aSet);
|
||||
while (from <= end) {
|
||||
chartype ch = *from;
|
||||
if(kNotFound==FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
|
||||
*to++=*from;
|
||||
}
|
||||
from++;
|
||||
}
|
||||
*to = 0;
|
||||
}
|
||||
return to - (chartype*)aString;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method removes chars (given in aSet) from the given buffer
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the buffer to be manipulated
|
||||
* @param anOffset is starting pos in buffer for manipulation
|
||||
* @param aCount is the number of chars to compare
|
||||
* @param aSet tells us which chars to remove from given buffer
|
||||
* @return the new length of the given buffer
|
||||
*/
|
||||
PRInt32 StripChars2(char* aString,PRUint32 anOffset,PRUint32 aCount,const char* aSet){
|
||||
PRInt32 result=0;
|
||||
|
||||
typedef PRUnichar chartype;
|
||||
chartype* from = (chartype*)&aString[anOffset];
|
||||
chartype* end = (chartype*)from + aCount-1;
|
||||
chartype* to = from;
|
||||
|
||||
if(aSet){
|
||||
PRUint32 aSetLen=strlen(aSet);
|
||||
while (from <= end) {
|
||||
chartype ch = *from;
|
||||
if(kNotFound==FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
|
||||
*to++=*from;
|
||||
}
|
||||
from++;
|
||||
}
|
||||
*to = 0;
|
||||
}
|
||||
return to - (chartype*)aString;
|
||||
}
|
||||
|
||||
typedef PRInt32 (*StripChars)(char* aString,PRUint32 aDestOffset,PRUint32 aCount,const char* aSet);
|
||||
StripChars gStripChars[]={&StripChars1,&StripChars2};
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//
|
||||
// This set of methods is used trim chars from the edges of a buffer...
|
||||
//
|
||||
|
||||
/**
|
||||
* This method trims chars (given in aSet) from the edges of given buffer
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the buffer to be manipulated
|
||||
* @param aLength is the length of the buffer
|
||||
* @param aSet tells us which chars to remove from given buffer
|
||||
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
|
||||
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
|
||||
* @return the new length of the given buffer
|
||||
*/
|
||||
PRInt32 TrimChars1(char* aString,PRUint32 aLength,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
PRInt32 result=0;
|
||||
|
||||
typedef char chartype;
|
||||
chartype* from = (chartype*)aString;
|
||||
chartype* end = from + aLength -1;
|
||||
chartype* to = from;
|
||||
|
||||
if(aSet) {
|
||||
PRUint32 aSetLen=strlen(aSet);
|
||||
//begin by find the first char not in aTrimSet
|
||||
if(aEliminateLeading) {
|
||||
while (from <= end) {
|
||||
chartype ch = *from;
|
||||
if(kNotFound==FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
|
||||
break;
|
||||
}
|
||||
from++;
|
||||
}
|
||||
}
|
||||
//Now, find last char not in aTrimSet
|
||||
if(aEliminateTrailing) {
|
||||
while(from<=end) {
|
||||
chartype ch = *end;
|
||||
if(kNotFound==FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
|
||||
break;
|
||||
}
|
||||
end--;
|
||||
}
|
||||
}
|
||||
//now rewrite your string without unwanted
|
||||
//leading or trailing characters.
|
||||
if (from != to) {
|
||||
while (from <= end) {
|
||||
*to++ = *from++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
to = ++end;
|
||||
}
|
||||
|
||||
*to = 0;
|
||||
}
|
||||
return to - (chartype*)aString;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method trims chars (given in aSet) from the edges of given buffer
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the buffer to be manipulated
|
||||
* @param aLength is the length of the buffer
|
||||
* @param aSet tells us which chars to remove from given buffer
|
||||
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
|
||||
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
|
||||
* @return the new length of the given buffer
|
||||
*/
|
||||
PRInt32 TrimChars2(char* aString,PRUint32 aLength,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
PRInt32 result=0;
|
||||
|
||||
typedef PRUnichar chartype;
|
||||
chartype* from = (chartype*)aString;
|
||||
chartype* end = from + aLength -1;
|
||||
chartype* to = from;
|
||||
|
||||
if(aSet) {
|
||||
PRUint32 aSetLen=strlen(aSet);
|
||||
//begin by find the first char not in aTrimSet
|
||||
if(aEliminateLeading) {
|
||||
while (from <= end) {
|
||||
chartype ch = *from;
|
||||
if(kNotFound==FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
|
||||
break;
|
||||
}
|
||||
from++;
|
||||
}
|
||||
}
|
||||
//Now, find last char not in aTrimSet
|
||||
if(aEliminateTrailing) {
|
||||
while(from<=end) {
|
||||
chartype ch = *end;
|
||||
if(kNotFound==FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
|
||||
break;
|
||||
}
|
||||
end--;
|
||||
}
|
||||
}
|
||||
//now rewrite your string without unwanted
|
||||
//leading or trailing characters.
|
||||
if (from != to) {
|
||||
while (from <= end) {
|
||||
*to++ = *from++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
to = ++end;
|
||||
}
|
||||
|
||||
*to = 0;
|
||||
}
|
||||
return to - (chartype*)aString;
|
||||
}
|
||||
|
||||
typedef PRInt32 (*TrimChars)(char* aString,PRUint32 aCount,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing);
|
||||
TrimChars gTrimChars[]={&TrimChars1,&TrimChars2};
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//
|
||||
// This set of methods is used compress char sequences in a buffer...
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* This method compresses duplicate runs of a given char from the given buffer
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the buffer to be manipulated
|
||||
* @param aLength is the length of the buffer
|
||||
* @param aSet tells us which chars to compress from given buffer
|
||||
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
|
||||
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
|
||||
* @return the new length of the given buffer
|
||||
*/
|
||||
PRInt32 CompressChars1(char* aString,PRUint32 aLength,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
PRInt32 result=0;
|
||||
|
||||
TrimChars1(aString,aLength,aSet,aEliminateLeading,aEliminateTrailing);
|
||||
|
||||
typedef char chartype;
|
||||
chartype* from = aString;
|
||||
chartype* end = aString + aLength-1;
|
||||
chartype* to = from;
|
||||
|
||||
//this code converts /n, /t, /r into normal space ' ';
|
||||
//it also compresses runs of whitespace down to a single char...
|
||||
if(aSet){
|
||||
PRUint32 aSetLen=strlen(aSet);
|
||||
while (from <= end) {
|
||||
chartype ch = *from++;
|
||||
if(kNotFound!=FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
|
||||
*to++ = ' ';
|
||||
while (from <= end) {
|
||||
ch = *from++;
|
||||
if(kNotFound==FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
|
||||
*to++ = ch;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
*to++ = ch;
|
||||
}
|
||||
}
|
||||
*to = 0;
|
||||
}
|
||||
return to - (chartype*)aString;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method compresses duplicate runs of a given char from the given buffer
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the buffer to be manipulated
|
||||
* @param aLength is the length of the buffer
|
||||
* @param aSet tells us which chars to compress from given buffer
|
||||
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
|
||||
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
|
||||
* @return the new length of the given buffer
|
||||
*/
|
||||
PRInt32 CompressChars2(char* aString,PRUint32 aLength,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
PRInt32 result=0;
|
||||
|
||||
TrimChars2(aString,aLength,aSet,aEliminateLeading,aEliminateTrailing);
|
||||
|
||||
typedef PRUnichar chartype;
|
||||
chartype* from = (chartype*)aString;
|
||||
chartype* end = from + aLength-1;
|
||||
chartype* to = from;
|
||||
|
||||
//this code converts /n, /t, /r into normal space ' ';
|
||||
//it also compresses runs of whitespace down to a single char...
|
||||
if(aSet){
|
||||
PRUint32 aSetLen=strlen(aSet);
|
||||
while (from <= end) {
|
||||
chartype ch = *from++;
|
||||
if(kNotFound!=FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
|
||||
*to++ = ' ';
|
||||
while (from <= end) {
|
||||
ch = *from++;
|
||||
if(kNotFound==FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
|
||||
*to++ = ch;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
*to++ = ch;
|
||||
}
|
||||
}
|
||||
*to = 0;
|
||||
}
|
||||
return to - (chartype*)aString;
|
||||
}
|
||||
|
||||
typedef PRInt32 (*CompressChars)(char* aString,PRUint32 aCount,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing);
|
||||
CompressChars gCompressChars[]={&CompressChars1,&CompressChars2};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -30,13 +30,10 @@ REQUIRES = xpcom raptor
|
||||
|
||||
DEFINES += -D_IMPL_NS_WIDGET
|
||||
|
||||
CPPSRCS = \
|
||||
nsTimer.cpp \
|
||||
nsCaretProperties.cpp \
|
||||
$(NULL)
|
||||
CPPSRCS = nsTimer.cpp
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
CXXFLAGS += $(TK_CFLAGS)
|
||||
CFLAGS += $(TK_CFLAGS)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
#include "nsCaretProperties.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
nsCaretProperties::nsCaretProperties()
|
||||
: mCaretWidth(eDefaultCaretWidth)
|
||||
, mBlinkRate(eDefaulBlinkRate)
|
||||
{
|
||||
// in your platform-specific class, get data from the OS in your constructor
|
||||
|
||||
//mBlinkRate = 0; // don't blink the caret
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
nsCaretProperties* NewCaretProperties()
|
||||
{
|
||||
return new nsCaretProperties();
|
||||
}
|
||||
@@ -131,7 +131,6 @@ TimerImpl::Init(nsITimerCallback *aCallback,
|
||||
{
|
||||
//printf("TimerImpl::Init called with callback only for %p\n", this);
|
||||
mCallback = aCallback;
|
||||
NS_ADDREF(mCallback);
|
||||
// mRepeat = aRepeat;
|
||||
if ((aDelay > 10000) || (aDelay < 0)) {
|
||||
printf("Timer::Init() called with bogus value \"%d\"! Not enabling timer.\n",
|
||||
@@ -150,7 +149,7 @@ TimerImpl::Init(PRUint32 aDelay)
|
||||
//printf("TimerImpl::Init called with delay %d only for %p\n", aDelay, this);
|
||||
|
||||
mDelay = aDelay;
|
||||
// NS_ADDREF(this);
|
||||
NS_ADDREF(this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include <Events.h>
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
#include "nsCaretProperties.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
nsCaretProperties::nsCaretProperties()
|
||||
: mCaretWidth(eDefaultCaretWidth)
|
||||
, mBlinkRate(eDefaulBlinkRate)
|
||||
{
|
||||
// in your platform-specific class, get data from the OS in your constructor
|
||||
|
||||
// MacOS calls
|
||||
|
||||
mBlinkRate = ::GetCaretTime() * 1000 / 60;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
nsCaretProperties* NewCaretProperties()
|
||||
{
|
||||
return new nsCaretProperties();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -39,16 +39,12 @@ class TimerImpl : public nsITimer
|
||||
// TimerImpl implements nsITimer API
|
||||
//========================================================================================
|
||||
{
|
||||
friend class TimerPeriodical;
|
||||
|
||||
private:
|
||||
nsTimerCallbackFunc mCallbackFunc;
|
||||
nsITimerCallback * mCallbackObject;
|
||||
void * mClosure;
|
||||
PRUint32 mDelay;
|
||||
PRUint32 mFireTime; // Timer should fire when TickCount >= this number
|
||||
TimerImpl * mPrev;
|
||||
TimerImpl * mNext;
|
||||
|
||||
public:
|
||||
|
||||
@@ -107,10 +103,10 @@ class TimerPeriodical : public Repeater
|
||||
// TimerPeriodical is a singleton Repeater subclass that fires
|
||||
// off TimerImpl. The firing is done on idle.
|
||||
//========================================================================================
|
||||
{
|
||||
{
|
||||
static TimerPeriodical * gPeriodical;
|
||||
|
||||
TimerImpl* mTimers;
|
||||
list<TimerImpl*> mTimers;
|
||||
|
||||
public:
|
||||
// Returns the singleton instance
|
||||
@@ -133,7 +129,8 @@ class TimerPeriodical : public Repeater
|
||||
// TimerImpl implementation
|
||||
//========================================================================================
|
||||
|
||||
NS_IMPL_ISUPPORTS(TimerImpl, nsITimer::GetIID())
|
||||
static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID);
|
||||
NS_IMPL_ISUPPORTS(TimerImpl, kITimerIID)
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TimerImpl::TimerImpl()
|
||||
@@ -143,8 +140,6 @@ TimerImpl::TimerImpl()
|
||||
, mClosure(nsnull)
|
||||
, mDelay(0)
|
||||
, mFireTime(0)
|
||||
, mPrev(nsnull)
|
||||
, mNext(nsnull)
|
||||
#if DEBUG
|
||||
, mSignature(eGoodTimerSignature)
|
||||
#endif
|
||||
@@ -190,6 +185,7 @@ nsresult TimerImpl::Init(nsITimerCallback *aCallback,
|
||||
void TimerImpl::Cancel()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
|
||||
TimerPeriodical::GetPeriodical()->RemoveTimer(this);
|
||||
}
|
||||
|
||||
@@ -219,11 +215,18 @@ void TimerImpl::Fire()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
NS_PRECONDITION(mRefCnt > 0, "Firing a disposed Timer!");
|
||||
if (mCallbackFunc != NULL) {
|
||||
if (mCallbackFunc != NULL)
|
||||
{
|
||||
(*mCallbackFunc)(this, mClosure);
|
||||
}
|
||||
else if (mCallbackObject != NULL) {
|
||||
mCallbackObject->Notify(this); // Fire the timer
|
||||
else if (mCallbackObject != NULL)
|
||||
{
|
||||
nsITimerCallback* object = mCallbackObject;
|
||||
mCallbackObject = nsnull;
|
||||
// because the Notify call will release it.
|
||||
// We will release again it in the destructor if
|
||||
// it is not null when we go away!
|
||||
object->Notify(this); // Fire the timer
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,70 +251,26 @@ TimerPeriodical * TimerPeriodical::GetPeriodical()
|
||||
|
||||
TimerPeriodical::TimerPeriodical()
|
||||
{
|
||||
mTimers = nsnull;
|
||||
}
|
||||
|
||||
TimerPeriodical::~TimerPeriodical()
|
||||
{
|
||||
PR_ASSERT(mTimers == 0);
|
||||
PR_ASSERT(mTimers.size() == 0);
|
||||
}
|
||||
|
||||
nsresult TimerPeriodical::AddTimer( TimerImpl * aTimer)
|
||||
{
|
||||
// make sure it's not already there
|
||||
RemoveTimer(aTimer);
|
||||
// keep list sorted by fire time
|
||||
if (mTimers)
|
||||
{
|
||||
if (aTimer->GetFireTime() < mTimers->GetFireTime())
|
||||
{
|
||||
mTimers->mPrev = aTimer;
|
||||
aTimer->mNext = mTimers;
|
||||
mTimers = aTimer;
|
||||
}
|
||||
else
|
||||
{
|
||||
TimerImpl *t = mTimers;
|
||||
TimerImpl *prevt;
|
||||
// we know we will enter the while loop at least the first
|
||||
// time, and thus prevt will be initialized
|
||||
while (t && (t->GetFireTime() <= aTimer->GetFireTime()))
|
||||
{
|
||||
prevt = t;
|
||||
t = t->mNext;
|
||||
}
|
||||
aTimer->mPrev = prevt;
|
||||
aTimer->mNext = prevt->mNext;
|
||||
prevt->mNext = aTimer;
|
||||
if (aTimer->mNext) aTimer->mNext->mPrev = aTimer;
|
||||
}
|
||||
}
|
||||
else mTimers = aTimer;
|
||||
|
||||
mTimers.remove(aTimer);
|
||||
mTimers.push_back(aTimer);
|
||||
StartRepeating();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult TimerPeriodical::RemoveTimer( TimerImpl * aTimer)
|
||||
{
|
||||
TimerImpl* t = mTimers;
|
||||
TimerImpl* next_t = nsnull;
|
||||
if (t) next_t = t->mNext;
|
||||
while (t)
|
||||
{
|
||||
if (t == aTimer)
|
||||
{
|
||||
if (mTimers == t) mTimers = t->mNext;
|
||||
if (t->mPrev) t->mPrev->mNext = t->mNext;
|
||||
if (t->mNext) t->mNext->mPrev = t->mPrev;
|
||||
t->mNext = nsnull;
|
||||
t->mPrev = nsnull;
|
||||
}
|
||||
t = next_t;
|
||||
if (t) next_t = t->mNext;
|
||||
}
|
||||
|
||||
if ( mTimers == nsnull )
|
||||
mTimers.remove(aTimer);
|
||||
if ( mTimers.size() == 0 )
|
||||
StopRepeating();
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -321,23 +280,33 @@ nsresult TimerPeriodical::RemoveTimer( TimerImpl * aTimer)
|
||||
// fires off the appropriate ones
|
||||
void TimerPeriodical::RepeatAction( const EventRecord &inMacEvent)
|
||||
{
|
||||
PRBool done = false;
|
||||
while (!done)
|
||||
list<TimerImpl*>::iterator iter = mTimers.begin();
|
||||
list<TimerImpl*> fireList;
|
||||
|
||||
while (iter != mTimers.end())
|
||||
{
|
||||
TimerImpl* t = mTimers;
|
||||
while (t)
|
||||
{
|
||||
NS_ASSERTION(t->IsGoodTimer(), "Bad timer!");
|
||||
TimerImpl* timer = *iter;
|
||||
|
||||
if (t->GetFireTime() <= inMacEvent.when)
|
||||
{
|
||||
RemoveTimer(t);
|
||||
t->Fire();
|
||||
break;
|
||||
}
|
||||
t = t->mNext;
|
||||
NS_ASSERTION(timer->IsGoodTimer(), "Bad timer!");
|
||||
|
||||
if (timer->GetFireTime() <= inMacEvent.when)
|
||||
{
|
||||
mTimers.erase(iter++);
|
||||
NS_ADDREF(timer);
|
||||
fireList.push_back(timer);
|
||||
}
|
||||
done = true;
|
||||
else
|
||||
{
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
if ( mTimers.size() == 0 )
|
||||
StopRepeating();
|
||||
|
||||
for (iter=fireList.begin(); iter!=fireList.end(); iter++)
|
||||
{
|
||||
(*iter)->Fire();
|
||||
NS_RELEASE(*iter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,5 +322,5 @@ NS_BASE nsresult NS_NewTimer(nsITimer** aInstancePtrResult)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return timer->QueryInterface(nsITimer::GetIID(), (void **) aInstancePtrResult);
|
||||
return timer->QueryInterface(kITimerIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
@@ -29,33 +29,17 @@ CPPSRCS = \
|
||||
nsBaseDLL.cpp \
|
||||
nsBTree.cpp \
|
||||
nsByteBuffer.cpp \
|
||||
nsByteBufferInputStream.cpp \
|
||||
nsCRT.cpp \
|
||||
nsDeque.cpp \
|
||||
nsProperties.cpp \
|
||||
nsVariant.cpp \
|
||||
nsRBTree.cpp \
|
||||
nsSizeOfHandler.cpp \
|
||||
nsStr.cpp \
|
||||
nsString.cpp \
|
||||
nsString2.cpp \
|
||||
nsUnicharBuffer.cpp \
|
||||
nsUnicharInputStream.cpp \
|
||||
nsVoidArray.cpp \
|
||||
nsFileSpec.cpp \
|
||||
nsFileStream.cpp \
|
||||
nsStringStream.cpp \
|
||||
nsEscape.cpp \
|
||||
nsIFileStream.cpp \
|
||||
nsThread.cpp \
|
||||
nsSpecialSystemDirectory.cpp \
|
||||
nsObserverService.cpp \
|
||||
nsObserverList.cpp \
|
||||
nsObserver.cpp \
|
||||
nsQuickSort.cpp \
|
||||
nsPageMgr.cpp \
|
||||
nsBuffer.cpp \
|
||||
nsPipe.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS = \
|
||||
@@ -64,56 +48,39 @@ CPP_OBJS = \
|
||||
.\$(OBJDIR)\nsBaseDLL.obj \
|
||||
.\$(OBJDIR)\nsBTree.obj \
|
||||
.\$(OBJDIR)\nsByteBuffer.obj \
|
||||
.\$(OBJDIR)\nsByteBufferInputStream.obj \
|
||||
.\$(OBJDIR)\nsCRT.obj \
|
||||
.\$(OBJDIR)\nsDeque.obj \
|
||||
.\$(OBJDIR)\nsProperties.obj \
|
||||
.\$(OBJDIR)\nsVariant.obj \
|
||||
.\$(OBJDIR)\nsRBTree.obj \
|
||||
.\$(OBJDIR)\nsSizeOfHandler.obj \
|
||||
.\$(OBJDIR)\nsStr.obj \
|
||||
.\$(OBJDIR)\nsString.obj \
|
||||
.\$(OBJDIR)\nsString2.obj \
|
||||
.\$(OBJDIR)\nsUnicharBuffer.obj \
|
||||
.\$(OBJDIR)\nsUnicharInputStream.obj \
|
||||
.\$(OBJDIR)\nsVoidArray.obj \
|
||||
.\$(OBJDIR)\nsFileSpec.obj \
|
||||
.\$(OBJDIR)\nsFileSpecStreaming.obj \
|
||||
.\$(OBJDIR)\nsFileStream.obj \
|
||||
.\$(OBJDIR)\nsEscape.obj \
|
||||
.\$(OBJDIR)\nsIFileStream.obj \
|
||||
.\$(OBJDIR)\nsThread.obj \
|
||||
.\$(OBJDIR)\nsIStringStream.obj \
|
||||
.\$(OBJDIR)\nsSpecialSystemDirectory.obj \
|
||||
.\$(OBJDIR)\nsObserverService.obj \
|
||||
.\$(OBJDIR)\nsObserverList.obj \
|
||||
.\$(OBJDIR)\nsObserver.obj \
|
||||
.\$(OBJDIR)\nsQuickSort.obj \
|
||||
.\$(OBJDIR)\nsPageMgr.obj \
|
||||
.\$(OBJDIR)\nsBuffer.obj \
|
||||
.\$(OBJDIR)\nsPipe.obj \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS=nscore.h nsIArena.h nsIAtom.h nsIByteBuffer.h \
|
||||
nsBTree.h nsCRT.h nsDeque.h nsITimer.h \
|
||||
nsITimerCallback.h nsIUnicharBuffer.h nsRBTree.h \
|
||||
nsIUnicharInputStream.h nsString.h nsVoidArray.h \
|
||||
nsStr.h nsString2.h nsUnitConversion.h \
|
||||
nsUnitConversion.h \
|
||||
nsIBaseStream.h nsIInputStream.h nsIOutputStream.h \
|
||||
nsInt64.h nsTime.h
|
||||
|
||||
MODULE=raptor
|
||||
|
||||
REQUIRES=xpcom netlib raptor uconv
|
||||
REQUIRES=xpcom netlib raptor
|
||||
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\netlib \
|
||||
-I$(PUBLIC)\raptor -I$(PUBLIC)\uconv -I$(PUBLIC)\unicharutil
|
||||
-I$(PUBLIC)\raptor
|
||||
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
DLLNAME = raptorbase
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
OBJS = $(OBJS) .\$(OBJDIR)\nsTimer.obj .\$(OBJDIR)\nsCaretProperties.obj
|
||||
OBJS = $(OBJS) .\$(OBJDIR)\nsTimer.obj
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
@@ -121,11 +88,10 @@ LCFLAGS = \
|
||||
$(NULL)
|
||||
|
||||
# These are the libraries we need to link with to create the dll
|
||||
LLIBS= \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\plc3.lib \
|
||||
shell32.lib \
|
||||
$(LIBNSPR)
|
||||
LLIBS= \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\libplc21.lib \
|
||||
$(LIBNSPR)
|
||||
!if "$(MOZ_BITS)"=="32" && defined(MOZ_DEBUG) && defined(GLOWCODE)
|
||||
LLIBS=$(LLIBS) $(GLOWDIR)\glowcode.lib
|
||||
!endif
|
||||
|
||||
@@ -30,10 +30,7 @@ REQUIRES = xpcom raptor
|
||||
|
||||
DEFINES += -D_IMPL_NS_WIDGET
|
||||
|
||||
CPPSRCS = \
|
||||
nsTimer.cpp \
|
||||
nsCaretProperties.cpp \
|
||||
$(NULL)
|
||||
CPPSRCS = nsTimer.cpp
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
#include "nsCaretProperties.h"
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
nsCaretProperties::nsCaretProperties()
|
||||
: mCaretWidth(eDefaultCaretWidth)
|
||||
, mBlinkRate(eDefaulBlinkRate)
|
||||
{
|
||||
// in your platform-specific class, get data from the OS in your constructor
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
nsCaretProperties* NewCaretProperties()
|
||||
{
|
||||
return new nsCaretProperties();
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
virtual void* Alloc(PRInt32 aSize);
|
||||
|
||||
protected:
|
||||
virtual ~ArenaImpl();
|
||||
~ArenaImpl();
|
||||
|
||||
PLArenaPool mPool;
|
||||
PRInt32 mBlockSize;
|
||||
|
||||
@@ -30,16 +30,12 @@ static struct PLHashTable* gAtomHashTable;
|
||||
class AtomImpl : public nsIAtom {
|
||||
public:
|
||||
AtomImpl();
|
||||
virtual ~AtomImpl();
|
||||
~AtomImpl();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
void* operator new(size_t size, const PRUnichar* us, PRInt32 uslen);
|
||||
|
||||
void operator delete(void* ptr) {
|
||||
::operator delete(ptr);
|
||||
}
|
||||
|
||||
virtual void ToString(nsString& aBuf) const;
|
||||
|
||||
virtual const PRUnichar* GetUnicode() const;
|
||||
@@ -79,7 +75,7 @@ NS_IMPL_ISUPPORTS(AtomImpl, kIAtomIID);
|
||||
void* AtomImpl::operator new(size_t size, const PRUnichar* us, PRInt32 uslen)
|
||||
{
|
||||
size = size + uslen * sizeof(PRUnichar);
|
||||
AtomImpl* ii = (AtomImpl*) ::operator new(size);
|
||||
AtomImpl* ii = (AtomImpl*) new char[size];
|
||||
nsCRT::memcpy(ii->mString, us, uslen * sizeof(PRUnichar));
|
||||
ii->mString[uslen] = 0;
|
||||
return ii;
|
||||
@@ -134,7 +130,7 @@ NS_BASE nsIAtom* NS_NewAtom(const PRUnichar* us)
|
||||
(PLHashComparator) nsnull,
|
||||
nsnull, nsnull);
|
||||
}
|
||||
PRUint32 uslen;
|
||||
PRInt32 uslen;
|
||||
PRUint32 hashCode = nsCRT::HashValue(us, &uslen);
|
||||
PLHashEntry** hep = PL_HashTableRawLookup(gAtomHashTable, hashCode, us);
|
||||
PLHashEntry* he = *hep;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
@@ -20,249 +20,61 @@
|
||||
#include "nscore.h"
|
||||
#include "nsIProperties.h"
|
||||
#include "nsProperties.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsObserverService.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsObserver.h"
|
||||
#include "nsProperties.h"
|
||||
#include "nsPageMgr.h"
|
||||
#include "pratom.h"
|
||||
#include "nsBuffer.h"
|
||||
#include "nsRepository.h"
|
||||
|
||||
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||
static NS_DEFINE_CID(kPageManagerCID, NS_PAGEMANAGER_CID);
|
||||
static NS_DEFINE_CID(kObserverServiceCID, NS_OBSERVERSERVICE_CID);
|
||||
static NS_DEFINE_CID(kObserverCID, NS_OBSERVER_CID);
|
||||
static NS_DEFINE_CID(kBufferCID, NS_BUFFER_CID);
|
||||
extern "C" PRInt32 gLockCount = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsBaseFactory : public nsIFactory
|
||||
{
|
||||
public:
|
||||
// nsISupports methods
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsBaseFactory(const nsCID &aClass);
|
||||
|
||||
// nsIFactory methods
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter, const nsIID &aIID, void **aResult);
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
protected:
|
||||
virtual ~nsBaseFactory();
|
||||
|
||||
static PRInt32 gLockCount;
|
||||
|
||||
nsCID mClassID;
|
||||
};
|
||||
|
||||
PRInt32 nsBaseFactory::gLockCount = 0;
|
||||
|
||||
nsBaseFactory::nsBaseFactory(const nsCID &aClass)
|
||||
: mClassID(aClass)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsBaseFactory::~nsBaseFactory()
|
||||
{
|
||||
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBaseFactory::QueryInterface(const nsIID &aIID, void **aResult)
|
||||
{
|
||||
if (aResult == nsnull)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aResult = nsnull;
|
||||
|
||||
if (aIID.Equals(nsIFactory::GetIID()) ||
|
||||
aIID.Equals(nsISupports::GetIID())) {
|
||||
*aResult = (void *)(nsIFactory*)this;
|
||||
}
|
||||
if (*aResult == nsnull)
|
||||
return NS_NOINTERFACE;
|
||||
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsBaseFactory)
|
||||
NS_IMPL_RELEASE(nsBaseFactory)
|
||||
|
||||
nsresult
|
||||
nsBaseFactory::CreateInstance(nsISupports *aOuter, const nsIID &aIID, void **aResult)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (aOuter) {
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
if (aResult == nsnull) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aResult = nsnull;
|
||||
|
||||
if (mClassID.Equals(kPersistentPropertiesCID)) {
|
||||
nsPersistentProperties* props = new nsPersistentProperties();
|
||||
if (props == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
rv = props->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete props;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (mClassID.Equals(kObserverServiceCID)) {
|
||||
return NS_NewObserverService((nsIObserverService**)aResult);
|
||||
}
|
||||
|
||||
if (mClassID.Equals(kObserverCID)) {
|
||||
return NS_NewObserver((nsIObserver**)aResult);
|
||||
}
|
||||
#ifdef XP_PC // XXX for now until i fix the build
|
||||
if (mClassID.Equals(kPageManagerCID)) {
|
||||
nsPageMgr* pageMgr = new nsPageMgr();
|
||||
if (pageMgr == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
rv = pageMgr->Init();
|
||||
if (NS_FAILED(rv)) {
|
||||
delete pageMgr;
|
||||
return rv;
|
||||
}
|
||||
rv = pageMgr->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete pageMgr;
|
||||
return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (mClassID.Equals(kBufferCID)) {
|
||||
nsBuffer* buffer = new nsBuffer();
|
||||
if (buffer == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
rv = buffer->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete buffer;
|
||||
return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
nsresult nsBaseFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
if (aLock) {
|
||||
PR_AtomicIncrement(&gLockCount);
|
||||
} else {
|
||||
PR_AtomicDecrement(&gLockCount);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSRegisterSelf(nsISupports* aServMgr, const char* path)
|
||||
NSRegisterSelf(const char* path)
|
||||
{
|
||||
nsresult rv;
|
||||
nsresult ret;
|
||||
|
||||
NS_WITH_SERVICE1(nsIComponentManager, compMgr,
|
||||
aServMgr, kComponentManagerCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
ret = nsRepository::RegisterFactory(kPropertiesCID, path, PR_TRUE,
|
||||
PR_TRUE);
|
||||
if (NS_FAILED(ret)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
rv = compMgr->RegisterComponent(kPersistentPropertiesCID,
|
||||
"Persistent Properties", NULL,
|
||||
path, PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = compMgr->RegisterComponent(kObserverServiceCID,
|
||||
"ObserverService",
|
||||
NS_OBSERVERSERVICE_PROGID,
|
||||
path, PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = compMgr->RegisterComponent(kObserverCID,
|
||||
"Observer",
|
||||
NS_OBSERVER_PROGID,
|
||||
path, PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = compMgr->RegisterComponent(kPageManagerCID,
|
||||
"Page Manager", NULL,
|
||||
path, PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = compMgr->RegisterComponent(kBufferCID,
|
||||
"Buffer", NULL,
|
||||
path, PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return rv;
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSUnregisterSelf(nsISupports* aServMgr, const char* path)
|
||||
NSUnregisterSelf(const char* path)
|
||||
{
|
||||
nsresult rv;
|
||||
nsresult ret;
|
||||
|
||||
NS_WITH_SERVICE1(nsIComponentManager, compMgr,
|
||||
aServMgr, kComponentManagerCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
ret = nsRepository::UnregisterFactory(kPropertiesCID, path);
|
||||
if (NS_FAILED(ret)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
rv = compMgr->UnregisterComponent(kPersistentPropertiesCID, path);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = compMgr->UnregisterComponent(kObserverServiceCID, path);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = compMgr->UnregisterComponent(kObserverCID, path);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = compMgr->UnregisterComponent(kPageManagerCID, path);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = compMgr->UnregisterComponent(kBufferCID, path);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return rv;
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSGetFactory(nsISupports* aServMgr,
|
||||
const nsCID& aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory** aFactory)
|
||||
NSGetFactory(const nsCID& aClass, nsISupports* aServMgr, nsIFactory** aFactory)
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
if (!aFactory) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
nsBaseFactory* factory = new nsBaseFactory(aClass);
|
||||
if (factory == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(factory);
|
||||
*aFactory = factory;
|
||||
return NS_OK;
|
||||
if (aClass.Equals(kPropertiesCID)) {
|
||||
nsPropertiesFactory *propsFactory = new nsPropertiesFactory();
|
||||
if (!propsFactory) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
res = propsFactory->QueryInterface(kIFactoryIID, (void**) aFactory);
|
||||
if (NS_FAILED(res)) {
|
||||
*aFactory = nsnull;
|
||||
delete propsFactory;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT PRBool
|
||||
NSCanUnload(nsISupports* serviceMgr)
|
||||
{
|
||||
return PR_FALSE; // XXX can we unload this?
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -21,6 +21,6 @@
|
||||
|
||||
#include "prtypes.h"
|
||||
|
||||
extern PRInt32 gLockCount;
|
||||
extern "C" PRInt32 gLockCount;
|
||||
|
||||
#endif /* nsBaseDLL_h___ */
|
||||
|
||||
@@ -1,367 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsBuffer.h"
|
||||
#include "nsAutoLock.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPageManager.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsBuffer::nsBuffer()
|
||||
: mGrowBySize(0),
|
||||
mMaxSize(0),
|
||||
mAllocator(nsnull),
|
||||
mBufferSize(0),
|
||||
mReadSegment(nsnull),
|
||||
mReadCursor(0),
|
||||
mWriteSegment(nsnull),
|
||||
mWriteCursor(0),
|
||||
mEOF(PR_FALSE)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
PR_INIT_CLIST(&mSegments);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBuffer::Init(PRUint32 growBySize, PRUint32 maxSize,
|
||||
nsIAllocator* allocator)
|
||||
{
|
||||
mGrowBySize = growBySize;
|
||||
mMaxSize = maxSize;
|
||||
mAllocator = allocator;
|
||||
NS_ADDREF(mAllocator);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsBuffer::~nsBuffer()
|
||||
{
|
||||
NS_IF_RELEASE(mAllocator);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsBuffer, nsIBuffer::GetIID());
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
nsBuffer::PushWriteSegment()
|
||||
{
|
||||
nsAutoMonitor mon(this); // protect mSegments
|
||||
|
||||
if (mBufferSize >= mMaxSize) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// allocate a new segment to write into
|
||||
char* seg;
|
||||
PRCList* header;
|
||||
|
||||
seg = (char*)mAllocator->Alloc(mGrowBySize);
|
||||
if (seg == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
mBufferSize += mGrowBySize;
|
||||
|
||||
header = (PRCList*)seg;
|
||||
PR_INSERT_BEFORE(header, &mSegments); // insert at end
|
||||
|
||||
// initialize the write segment
|
||||
mWriteSegment = seg;
|
||||
mWriteSegmentEnd = mWriteSegment + mGrowBySize;
|
||||
mWriteCursor = mWriteSegment + sizeof(PRCList);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBuffer::PopReadSegment()
|
||||
{
|
||||
nsresult rv;
|
||||
nsAutoMonitor mon(this); // protect mSegments
|
||||
|
||||
PRCList* header = (PRCList*)mSegments.next;
|
||||
char* segment = (char*)header;
|
||||
|
||||
NS_ASSERTION(mReadSegment == segment, "wrong segment");
|
||||
|
||||
// make sure that the writer isn't still in this segment (that the
|
||||
// reader is removing)
|
||||
NS_ASSERTION(!(segment <= mWriteCursor && mWriteCursor < segment + mGrowBySize),
|
||||
"removing writer's segment");
|
||||
|
||||
PR_REMOVE_LINK(header); // unlink from mSegments
|
||||
|
||||
mBufferSize -= mGrowBySize;
|
||||
|
||||
rv = mAllocator->Free(segment);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// initialize the read segment
|
||||
if (PR_CLIST_IS_EMPTY(&mSegments)) {
|
||||
mReadSegment = nsnull;
|
||||
mReadSegmentEnd = nsnull;
|
||||
mReadCursor = nsnull;
|
||||
}
|
||||
else {
|
||||
mReadSegment = (char*)mSegments.next;
|
||||
mReadSegmentEnd = mReadSegment + mGrowBySize;
|
||||
mReadCursor = mReadSegment + sizeof(PRCList);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIBuffer methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBuffer::Read(char* toBuf, PRUint32 bufLen, PRUint32 *readCount)
|
||||
{
|
||||
nsresult rv;
|
||||
PRUint32 readBufferLen;
|
||||
char* readBuffer;
|
||||
|
||||
*readCount = 0;
|
||||
while (bufLen > 0) {
|
||||
rv = GetReadBuffer(&readBufferLen, &readBuffer);
|
||||
if (rv == NS_BASE_STREAM_EOF) // all we're going to get
|
||||
return *readCount > 0 ? NS_OK : NS_BASE_STREAM_EOF;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (readBufferLen == 0)
|
||||
return mEOF && *readCount == 0 ? NS_BASE_STREAM_EOF : NS_OK;
|
||||
|
||||
PRUint32 count = PR_MIN(bufLen, readBufferLen);
|
||||
nsCRT::memcpy(toBuf, readBuffer, count);
|
||||
*readCount += count;
|
||||
toBuf += count;
|
||||
bufLen -= count;
|
||||
|
||||
if (mReadCursor + count == mReadSegmentEnd) {
|
||||
rv = PopReadSegment();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
mReadCursor += count;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBuffer::GetReadBuffer(PRUint32 *readBufferLength, char* *result)
|
||||
{
|
||||
if (mReadSegment == nsnull) {
|
||||
if (PR_CLIST_IS_EMPTY(&mSegments)) {
|
||||
*readBufferLength = 0;
|
||||
*result = nsnull;
|
||||
return mEOF ? NS_BASE_STREAM_EOF : NS_OK;
|
||||
}
|
||||
else {
|
||||
mReadSegment = (char*)mSegments.next;
|
||||
mReadSegmentEnd = mReadSegment + mGrowBySize;
|
||||
mReadCursor = mReadSegment + sizeof(PRCList);
|
||||
}
|
||||
}
|
||||
|
||||
// snapshot the write cursor into a local variable -- this allows
|
||||
// a writer to freely change it while we're reading while avoiding
|
||||
// using a lock
|
||||
char* snapshotWriteCursor = mWriteCursor; // atomic
|
||||
|
||||
// next check if the write cursor is in our segment
|
||||
if (mReadCursor <= snapshotWriteCursor &&
|
||||
snapshotWriteCursor < mReadSegmentEnd) {
|
||||
// same segment -- read up to the snapshotWriteCursor
|
||||
*readBufferLength = snapshotWriteCursor - mReadCursor;
|
||||
}
|
||||
else {
|
||||
// otherwise, read up to the end of this segment
|
||||
*readBufferLength = mReadSegmentEnd - mReadCursor;
|
||||
}
|
||||
*result = mReadCursor;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBuffer::Write(const char* fromBuf, PRUint32 bufLen, PRUint32 *writeCount)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (mEOF)
|
||||
return NS_BASE_STREAM_EOF;
|
||||
|
||||
*writeCount = 0;
|
||||
while (bufLen > 0) {
|
||||
PRUint32 writeBufLen;
|
||||
char* writeBuf;
|
||||
rv = GetWriteBuffer(&writeBufLen, &writeBuf);
|
||||
if (NS_FAILED(rv)) {
|
||||
// if we failed to allocate a new segment, we're probably out
|
||||
// of memory, but we don't care -- just report what we were
|
||||
// able to write so far
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRUint32 count = PR_MIN(writeBufLen, bufLen);
|
||||
nsCRT::memcpy(writeBuf, fromBuf, count);
|
||||
bufLen -= count;
|
||||
*writeCount += count;
|
||||
// set the write cursor after the data is valid
|
||||
if (mWriteCursor + count == mWriteSegmentEnd) {
|
||||
mWriteSegment = nsnull; // allocate a new segment next time around
|
||||
mWriteSegmentEnd = nsnull;
|
||||
mWriteCursor = nsnull;
|
||||
}
|
||||
else
|
||||
mWriteCursor += count;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBuffer::Write(nsIInputStream* fromStream, PRUint32 *writeCount)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (mEOF)
|
||||
return NS_BASE_STREAM_EOF;
|
||||
|
||||
*writeCount = 0;
|
||||
while (PR_TRUE) {
|
||||
PRUint32 writeBufLen;
|
||||
char* writeBuf;
|
||||
rv = GetWriteBuffer(&writeBufLen, &writeBuf);
|
||||
if (NS_FAILED(rv)) {
|
||||
// if we failed to allocate a new segment, we're probably out
|
||||
// of memory, but we don't care -- just report what we were
|
||||
// able to write so far
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRUint32 readCount;
|
||||
rv = fromStream->Read(writeBuf, writeBufLen, &readCount);
|
||||
if (NS_FAILED(rv)) {
|
||||
// if we failed to read just report what we were
|
||||
// able to write so far
|
||||
return NS_OK;
|
||||
}
|
||||
*writeCount += readCount;
|
||||
// set the write cursor after the data is valid
|
||||
if (mWriteCursor + readCount == mWriteSegmentEnd) {
|
||||
mWriteSegment = nsnull; // allocate a new segment next time around
|
||||
mWriteSegmentEnd = nsnull;
|
||||
mWriteCursor = nsnull;
|
||||
}
|
||||
else
|
||||
mWriteCursor += readCount;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBuffer::GetWriteBuffer(PRUint32 *writeBufferLength, char* *result)
|
||||
{
|
||||
if (mEOF)
|
||||
return NS_BASE_STREAM_EOF;
|
||||
|
||||
nsresult rv;
|
||||
if (mWriteSegment == nsnull) {
|
||||
if (mBufferSize >= mMaxSize)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
rv = PushWriteSegment();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_ASSERTION(mWriteSegment != nsnull, "failed to allocate segment");
|
||||
}
|
||||
|
||||
*writeBufferLength = mWriteSegmentEnd - mWriteCursor;
|
||||
*result = mWriteCursor;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBuffer::SetEOF()
|
||||
{
|
||||
if (mEOF)
|
||||
return NS_BASE_STREAM_EOF;
|
||||
|
||||
mEOF = PR_TRUE;
|
||||
mWriteSegment = nsnull; // allows reader to free last segment w/o asserting
|
||||
mWriteSegmentEnd = nsnull;
|
||||
// don't reset mWriteCursor here -- we need it for the EOF point in the buffer
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_CID(kAllocatorCID, NS_ALLOCATOR_CID);
|
||||
|
||||
NS_BASE nsresult
|
||||
NS_NewBuffer(nsIBuffer* *result,
|
||||
PRUint32 growBySize, PRUint32 maxSize)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIAllocator, alloc, kAllocatorCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsBuffer* buf = new nsBuffer();
|
||||
if (buf == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = buf->Init(growBySize, maxSize, alloc);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete buf;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_ADDREF(buf);
|
||||
*result = buf;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static NS_DEFINE_CID(kPageManagerCID, NS_PAGEMANAGER_CID);
|
||||
|
||||
NS_BASE nsresult
|
||||
NS_NewPageBuffer(nsIBuffer* *result,
|
||||
PRUint32 growBySize, PRUint32 maxSize)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIAllocator, alloc, kPageManagerCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsBuffer* buf = new nsBuffer();
|
||||
if (buf == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = buf->Init(growBySize, maxSize, alloc);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete buf;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_ADDREF(buf);
|
||||
*result = buf;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -1,68 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsBuffer_h___
|
||||
#define nsBuffer_h___
|
||||
|
||||
#include "nsIBuffer.h"
|
||||
#include "nscore.h"
|
||||
#include "prclist.h"
|
||||
#include "nsIAllocator.h"
|
||||
|
||||
class nsBuffer : public nsIBuffer {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIBuffer methods:
|
||||
NS_IMETHOD Init(PRUint32 growBySize, PRUint32 maxSize,
|
||||
nsIAllocator* allocator);
|
||||
NS_IMETHOD Read(char* toBuf, PRUint32 bufLen, PRUint32 *readCount);
|
||||
NS_IMETHOD GetReadBuffer(PRUint32 *readBufferLength, char* *result);
|
||||
|
||||
NS_IMETHOD Write(const char* fromBuf, PRUint32 bufLen, PRUint32 *writeCount);
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *writeCount);
|
||||
NS_IMETHOD GetWriteBuffer(PRUint32 *writeBufferLength, char* *result);
|
||||
NS_IMETHOD SetEOF();
|
||||
|
||||
// nsBuffer methods:
|
||||
nsBuffer();
|
||||
virtual ~nsBuffer();
|
||||
|
||||
nsresult PushWriteSegment();
|
||||
nsresult PopReadSegment();
|
||||
|
||||
protected:
|
||||
PRUint32 mGrowBySize;
|
||||
PRUint32 mMaxSize;
|
||||
nsIAllocator* mAllocator;
|
||||
|
||||
PRCList mSegments;
|
||||
PRUint32 mBufferSize;
|
||||
|
||||
char* mReadSegment;
|
||||
char* mReadSegmentEnd;
|
||||
char* mReadCursor;
|
||||
|
||||
char* mWriteSegment;
|
||||
char* mWriteSegmentEnd;
|
||||
char* mWriteCursor;
|
||||
|
||||
PRBool mEOF;
|
||||
};
|
||||
|
||||
#endif // nsBuffer_h___
|
||||
@@ -24,15 +24,15 @@
|
||||
class ByteBufferImpl : public nsIByteBuffer {
|
||||
public:
|
||||
ByteBufferImpl(PRUint32 aBufferSize);
|
||||
virtual ~ByteBufferImpl();
|
||||
~ByteBufferImpl();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_IMETHOD_(PRUint32) GetLength(void) const;
|
||||
NS_IMETHOD_(PRUint32) GetBufferSize(void) const;
|
||||
NS_IMETHOD_(char*) GetBuffer() const;
|
||||
NS_IMETHOD_(PRBool) Grow(PRUint32 aNewSize);
|
||||
NS_IMETHOD_(PRInt32) Fill(nsresult* aErrorCode, nsIInputStream* aStream,
|
||||
PRUint32 aKeep);
|
||||
virtual PRUint32 GetLength(void) const;
|
||||
virtual PRUint32 GetBufferSize(void) const;
|
||||
virtual char* GetBuffer() const;
|
||||
virtual PRBool Grow(PRUint32 aNewSize);
|
||||
virtual PRInt32 Fill(nsresult* aErrorCode, nsIInputStream* aStream,
|
||||
PRUint32 aKeep);
|
||||
|
||||
char* mBuffer;
|
||||
PRUint32 mSpace;
|
||||
@@ -56,32 +56,28 @@ NS_IMPL_ISUPPORTS(ByteBufferImpl,kByteBufferIID)
|
||||
ByteBufferImpl::~ByteBufferImpl()
|
||||
{
|
||||
if (nsnull != mBuffer) {
|
||||
delete[] mBuffer;
|
||||
delete mBuffer;
|
||||
mBuffer = nsnull;
|
||||
}
|
||||
mLength = 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRUint32)
|
||||
ByteBufferImpl::GetLength(void) const
|
||||
PRUint32 ByteBufferImpl::GetLength(void) const
|
||||
{
|
||||
return mLength;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRUint32)
|
||||
ByteBufferImpl::GetBufferSize(void) const
|
||||
PRUint32 ByteBufferImpl::GetBufferSize(void) const
|
||||
{
|
||||
return mSpace;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(char*)
|
||||
ByteBufferImpl::GetBuffer(void) const
|
||||
char* ByteBufferImpl::GetBuffer(void) const
|
||||
{
|
||||
return mBuffer;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
ByteBufferImpl::Grow(PRUint32 aNewSize)
|
||||
PRBool ByteBufferImpl::Grow(PRUint32 aNewSize)
|
||||
{
|
||||
if (aNewSize < MIN_BUFFER_SIZE) {
|
||||
aNewSize = MIN_BUFFER_SIZE;
|
||||
@@ -91,16 +87,15 @@ ByteBufferImpl::Grow(PRUint32 aNewSize)
|
||||
if (0 != mLength) {
|
||||
nsCRT::memcpy(newbuf, mBuffer, mLength);
|
||||
}
|
||||
delete[] mBuffer;
|
||||
delete mBuffer;
|
||||
mBuffer = newbuf;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRInt32)
|
||||
ByteBufferImpl::Fill(nsresult* aErrorCode, nsIInputStream* aStream,
|
||||
PRUint32 aKeep)
|
||||
PRInt32 ByteBufferImpl::Fill(nsresult* aErrorCode, nsIInputStream* aStream,
|
||||
PRUint32 aKeep)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aStream, "null stream");
|
||||
NS_PRECONDITION(aKeep <= mLength, "illegal keep count");
|
||||
@@ -117,8 +112,9 @@ ByteBufferImpl::Fill(nsresult* aErrorCode, nsIInputStream* aStream,
|
||||
|
||||
// Read in some new data
|
||||
mLength = aKeep;
|
||||
PRUint32 amount = mSpace - aKeep;
|
||||
PRUint32 nb;
|
||||
*aErrorCode = aStream->Read(mBuffer + aKeep, mSpace - aKeep, &nb);
|
||||
*aErrorCode = aStream->Read(mBuffer, aKeep, amount, &nb);
|
||||
if (NS_SUCCEEDED(*aErrorCode)) {
|
||||
mLength += nb;
|
||||
}
|
||||
|
||||
@@ -1,575 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsIByteBufferInputStream.h"
|
||||
#include "nsCRT.h"
|
||||
#include "prcmon.h"
|
||||
|
||||
class nsByteBufferInputStream;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsByteBufferOutputStream : public nsIOutputStream
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIBaseStream methods:
|
||||
NS_IMETHOD Close(void);
|
||||
|
||||
// nsIOutputStream methods:
|
||||
NS_IMETHOD Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount);
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount);
|
||||
NS_IMETHOD Flush(void);
|
||||
|
||||
// nsByteBufferOutputStream methods:
|
||||
nsByteBufferOutputStream(nsByteBufferInputStream* in);
|
||||
virtual ~nsByteBufferOutputStream();
|
||||
|
||||
protected:
|
||||
nsByteBufferInputStream* mInputStream;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsByteBufferInputStream : public nsIByteBufferInputStream
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIBaseStream methods:
|
||||
NS_IMETHOD Close(void);
|
||||
|
||||
// nsIInputStream methods:
|
||||
NS_IMETHOD GetLength(PRUint32 *aLength);
|
||||
NS_IMETHOD Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount);
|
||||
|
||||
// nsIByteBufferInputStream methods:
|
||||
NS_IMETHOD Fill(nsIInputStream* stream, PRUint32 *aWriteCount);
|
||||
NS_IMETHOD Fill(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount);
|
||||
|
||||
// nsByteBufferInputStream methods:
|
||||
nsByteBufferInputStream(PRBool blocking, PRUint32 size);
|
||||
virtual ~nsByteBufferInputStream();
|
||||
|
||||
friend class nsByteBufferOutputStream;
|
||||
|
||||
nsresult Init(void);
|
||||
nsresult SetEOF(void);
|
||||
nsresult Drain(void);
|
||||
|
||||
PRBool AtEOF() { return mEOF && (mReadCursor == mWriteCursor) && !mFull; }
|
||||
|
||||
PRUint32 ReadableAmount() {
|
||||
if (mReadCursor < mWriteCursor)
|
||||
return mWriteCursor - mReadCursor;
|
||||
else if (mReadCursor == mWriteCursor && !mFull)
|
||||
return 0;
|
||||
else
|
||||
return (mLength - mReadCursor) + mWriteCursor;
|
||||
}
|
||||
|
||||
PRUint32 WritableAmount() {
|
||||
if (mWriteCursor < mReadCursor)
|
||||
return mWriteCursor - mReadCursor;
|
||||
else if (mReadCursor == mWriteCursor && mFull)
|
||||
return 0;
|
||||
else
|
||||
return (mLength - mWriteCursor) + mReadCursor;
|
||||
}
|
||||
|
||||
void ReadChunk(char* toBuf, PRUint32 max,
|
||||
PRUint32 end, PRUint32 *totalRef)
|
||||
{
|
||||
NS_ASSERTION(mReadCursor <= end, "bad range");
|
||||
PRUint32 diff = end - mReadCursor;
|
||||
PRInt32 amt = PR_MIN(max, diff);
|
||||
if (amt > 0) {
|
||||
nsCRT::memcpy(toBuf, &mBuffer[mReadCursor], amt);
|
||||
#ifdef DEBUG_warren
|
||||
// nsCRT::memset(&mBuffer[mReadCursor], 0xDD, amt);
|
||||
#endif
|
||||
mReadCursor += amt;
|
||||
*totalRef += amt;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult WriteChunk(nsIInputStream* in,
|
||||
PRUint32 end, PRUint32 *totalRef)
|
||||
{
|
||||
NS_ASSERTION(mWriteCursor <= end, "bad range");
|
||||
PRUint32 amt = end - mWriteCursor;
|
||||
if (amt > 0) {
|
||||
PRUint32 readAmt;
|
||||
nsresult rv = in->Read(&mBuffer[mWriteCursor], amt, &readAmt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mWriteCursor += readAmt;
|
||||
*totalRef += readAmt;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
protected:
|
||||
char* mBuffer;
|
||||
PRUint32 mLength;
|
||||
PRUint32 mReadCursor;
|
||||
PRUint32 mWriteCursor;
|
||||
PRBool mFull;
|
||||
PRBool mClosed;
|
||||
PRBool mEOF;
|
||||
PRBool mBlocking;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsDummyBufferStream : public nsIInputStream
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIBaseStream methods:
|
||||
NS_IMETHOD Close(void) {
|
||||
NS_NOTREACHED("nsDummyBufferStream::Close");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// nsIInputStream methods:
|
||||
NS_IMETHOD GetLength(PRUint32 *aLength) {
|
||||
*aLength = mLength;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount) {
|
||||
PRUint32 amt = PR_MIN(aCount, mLength);
|
||||
if (amt > 0) {
|
||||
nsCRT::memcpy(aBuf, mBuffer, amt);
|
||||
mBuffer += amt;
|
||||
mLength -= amt;
|
||||
}
|
||||
*aReadCount = amt;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsDummyBufferStream methods:
|
||||
nsDummyBufferStream(const char* buffer, PRUint32 length)
|
||||
: mBuffer(buffer), mLength(length) {}
|
||||
virtual ~nsDummyBufferStream() {}
|
||||
|
||||
protected:
|
||||
const char* mBuffer;
|
||||
PRUint32 mLength;
|
||||
};
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDummyBufferStream::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
NS_NOTREACHED("nsDummyBufferStream::QueryInterface");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt)
|
||||
nsDummyBufferStream::AddRef(void)
|
||||
{
|
||||
NS_NOTREACHED("nsDummyBufferStream::AddRef");
|
||||
return 1;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt)
|
||||
nsDummyBufferStream::Release(void)
|
||||
{
|
||||
NS_NOTREACHED("nsDummyBufferStream::Release");
|
||||
return 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsByteBufferInputStream methods:
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsByteBufferInputStream::nsByteBufferInputStream(PRBool blocking, PRUint32 size)
|
||||
: mBuffer(nsnull), mLength(size), mReadCursor(0), mWriteCursor(0),
|
||||
mFull(PR_FALSE), mClosed(PR_FALSE), mEOF(PR_FALSE), mBlocking(blocking)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsByteBufferInputStream::Init(void)
|
||||
{
|
||||
mBuffer = new char[mLength];
|
||||
if (mBuffer == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsByteBufferInputStream::~nsByteBufferInputStream()
|
||||
{
|
||||
(void)Close();
|
||||
if (mBuffer) delete mBuffer;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsByteBufferInputStream);
|
||||
NS_IMPL_RELEASE(nsByteBufferInputStream);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsByteBufferInputStream::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (aInstancePtr == nsnull)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (aIID.Equals(nsIByteBufferInputStream::GetIID()) ||
|
||||
aIID.Equals(nsIInputStream::GetIID()) ||
|
||||
aIID.Equals(nsIBaseStream::GetIID()) ||
|
||||
aIID.Equals(nsISupports::GetIID())) {
|
||||
*aInstancePtr = this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsByteBufferInputStream::Close(void)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (mBlocking)
|
||||
PR_CEnterMonitor(this);
|
||||
mClosed = PR_TRUE;
|
||||
if (mBlocking) {
|
||||
PRStatus status = PR_CNotify(this); // wake up the writer
|
||||
if (status != PR_SUCCESS)
|
||||
rv = NS_ERROR_FAILURE;
|
||||
PR_CExitMonitor(this);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsByteBufferInputStream::GetLength(PRUint32 *aLength)
|
||||
{
|
||||
if (mClosed)
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
|
||||
if (mBlocking)
|
||||
PR_CEnterMonitor(this);
|
||||
*aLength = ReadableAmount();
|
||||
if (mBlocking)
|
||||
PR_CExitMonitor(this);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsByteBufferInputStream::Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (mClosed)
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
|
||||
if (AtEOF())
|
||||
return NS_BASE_STREAM_EOF;
|
||||
|
||||
if (mBlocking)
|
||||
PR_CEnterMonitor(this);
|
||||
*aReadCount = 0;
|
||||
|
||||
/*while (aCount > 0)*/ {
|
||||
if (ReadableAmount() == 0) {
|
||||
if (mBlocking) {
|
||||
PRStatus status = PR_CWait(this, PR_INTERVAL_NO_TIMEOUT);
|
||||
if (status != PR_SUCCESS) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if (mEOF) {
|
||||
rv = NS_BASE_STREAM_EOF;
|
||||
goto done;
|
||||
}
|
||||
else if (!mBlocking) {
|
||||
rv = NS_BASE_STREAM_WOULD_BLOCK;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
// wrap-around buffer:
|
||||
PRUint32 amt = 0;
|
||||
if (mReadCursor >= mWriteCursor || mFull) {
|
||||
ReadChunk(aBuf, aCount, mLength, &amt);
|
||||
*aReadCount += amt;
|
||||
aBuf += amt;
|
||||
aCount -= amt;
|
||||
if (mReadCursor == mLength) {
|
||||
mReadCursor = 0;
|
||||
amt = 0;
|
||||
ReadChunk(aBuf, aCount, mWriteCursor, &amt);
|
||||
*aReadCount += amt;
|
||||
aBuf += amt;
|
||||
aCount -= amt;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ReadChunk(aBuf, aCount, mWriteCursor, &amt);
|
||||
*aReadCount += amt;
|
||||
aBuf += amt;
|
||||
aCount -= amt;
|
||||
}
|
||||
if (*aReadCount)
|
||||
mFull = PR_FALSE;
|
||||
|
||||
if (mBlocking) {
|
||||
PRStatus status = PR_CNotify(this); // tell the writer there's space
|
||||
if (status != PR_SUCCESS)
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
done:
|
||||
if (mBlocking)
|
||||
PR_CExitMonitor(this);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsByteBufferInputStream::Fill(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount)
|
||||
{
|
||||
nsDummyBufferStream in(aBuf, aCount);
|
||||
return Fill(&in, aWriteCount);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsByteBufferInputStream::Fill(nsIInputStream* stream, PRUint32 *aWriteCount)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (mClosed || mEOF)
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
|
||||
*aWriteCount = 0;
|
||||
PRUint32 aCount;
|
||||
rv = stream->GetLength(&aCount);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (mBlocking)
|
||||
PR_CEnterMonitor(this);
|
||||
|
||||
while (aCount > 0) {
|
||||
if (WritableAmount() == 0) {
|
||||
if (mBlocking) {
|
||||
PRStatus status = PR_CWait(this, PR_INTERVAL_NO_TIMEOUT);
|
||||
if (status != PR_SUCCESS) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if (mClosed) {
|
||||
rv = NS_BASE_STREAM_CLOSED;
|
||||
goto done;
|
||||
}
|
||||
else if (!mBlocking) {
|
||||
rv = NS_BASE_STREAM_WOULD_BLOCK;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
// wrap-around buffer:
|
||||
PRUint32 amt = 0;
|
||||
if (mReadCursor <= mWriteCursor && !mFull) {
|
||||
rv = WriteChunk(stream, mLength, &amt);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
*aWriteCount += amt;
|
||||
aCount -= amt;
|
||||
if (mWriteCursor == mLength) {
|
||||
mWriteCursor = 0;
|
||||
amt = 0;
|
||||
rv = WriteChunk(stream, mReadCursor, &amt);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
*aWriteCount += amt;
|
||||
aCount -= amt;
|
||||
}
|
||||
}
|
||||
else {
|
||||
rv = WriteChunk(stream, mReadCursor, &amt);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
*aWriteCount += amt;
|
||||
aCount -= amt;
|
||||
}
|
||||
if (mWriteCursor == mReadCursor)
|
||||
mFull = PR_TRUE;
|
||||
|
||||
if (mBlocking) {
|
||||
PRStatus status = PR_CNotify(this); // tell the reader there's more
|
||||
if (status != PR_SUCCESS)
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
done:
|
||||
if (mBlocking)
|
||||
PR_CExitMonitor(this);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsByteBufferInputStream::SetEOF()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (mBlocking)
|
||||
PR_CEnterMonitor(this);
|
||||
mEOF = PR_TRUE;
|
||||
if (mBlocking) {
|
||||
PRStatus status = PR_CNotify(this); // wake up the reader
|
||||
if (status != PR_SUCCESS)
|
||||
rv = NS_ERROR_FAILURE;
|
||||
PR_CExitMonitor(this);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsByteBufferInputStream::Drain()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (mBlocking) {
|
||||
PR_CEnterMonitor(this);
|
||||
while (ReadableAmount() != 0) {
|
||||
PRStatus status = PR_CNotify(this); // wake up the reader
|
||||
if (status != PR_SUCCESS) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
// wait for the reader to take all the data
|
||||
status = PR_CWait(this, PR_INTERVAL_NO_TIMEOUT);
|
||||
if (status != PR_SUCCESS) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
PR_CExitMonitor(this);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsByteBufferOutputStream methods:
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsByteBufferOutputStream::nsByteBufferOutputStream(nsByteBufferInputStream* in)
|
||||
: mInputStream(in)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF(mInputStream);
|
||||
}
|
||||
|
||||
nsByteBufferOutputStream::~nsByteBufferOutputStream()
|
||||
{
|
||||
(void)Close();
|
||||
NS_IF_RELEASE(mInputStream);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsByteBufferOutputStream);
|
||||
NS_IMPL_RELEASE(nsByteBufferOutputStream);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsByteBufferOutputStream::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (aInstancePtr == nsnull)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (aIID.Equals(nsIOutputStream::GetIID()) ||
|
||||
aIID.Equals(nsIBaseStream::GetIID()) ||
|
||||
aIID.Equals(nsISupports::GetIID())) {
|
||||
*aInstancePtr = this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsByteBufferOutputStream::Close(void)
|
||||
{
|
||||
mInputStream->SetEOF();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsByteBufferOutputStream::Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount)
|
||||
{
|
||||
return mInputStream->Fill(aBuf, aCount, aWriteCount);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsByteBufferOutputStream::Write(nsIInputStream* fromStream, PRUint32 *aWriteCount)
|
||||
{
|
||||
return mInputStream->Fill(fromStream, aWriteCount);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsByteBufferOutputStream::Flush(void)
|
||||
{
|
||||
return mInputStream->Drain();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_BASE nsresult
|
||||
NS_NewByteBufferInputStream(nsIByteBufferInputStream* *result,
|
||||
PRBool blocking, PRUint32 size)
|
||||
{
|
||||
nsresult rv;
|
||||
nsByteBufferInputStream* inStr = nsnull;
|
||||
|
||||
inStr = new nsByteBufferInputStream(blocking, size);
|
||||
if (inStr == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
rv = inStr->Init();
|
||||
if (NS_FAILED(rv)) {
|
||||
delete inStr;
|
||||
return rv;
|
||||
}
|
||||
NS_ADDREF(inStr);
|
||||
*result = inStr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_BASE nsresult
|
||||
NS_NewPipe(nsIInputStream* *inStrResult,
|
||||
nsIOutputStream* *outStrResult,
|
||||
PRBool blocking, PRUint32 size)
|
||||
{
|
||||
nsresult rv;
|
||||
nsIByteBufferInputStream* in;
|
||||
nsByteBufferInputStream* inStr;
|
||||
nsByteBufferOutputStream* outStr;
|
||||
|
||||
rv = NS_NewByteBufferInputStream(&in, blocking, size);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
// this cast is safe, because we know how NS_NewByteBufferInputStream works:
|
||||
inStr = NS_STATIC_CAST(nsByteBufferInputStream*, in);
|
||||
|
||||
outStr = new nsByteBufferOutputStream(inStr);
|
||||
if (outStr == nsnull) {
|
||||
NS_RELEASE(inStr);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ADDREF(outStr);
|
||||
|
||||
*inStrResult = inStr;
|
||||
*outStrResult = outStr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -33,10 +33,6 @@
|
||||
|
||||
|
||||
#include "nsCRT.h"
|
||||
#include "nsUnicharUtilCIID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICaseConversion.h"
|
||||
|
||||
|
||||
// XXX Bug: These tables don't lowercase the upper 128 characters properly
|
||||
|
||||
@@ -91,7 +87,7 @@ static const unsigned char kLower2Upper[256] = {
|
||||
};
|
||||
|
||||
// XXX bug: this doesn't map 0x80 to 0x9f properly
|
||||
const PRUnichar kIsoLatin1ToUCS2[256] = {
|
||||
static const PRUnichar kIsoLatin1ToUCS2[256] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
||||
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
||||
@@ -113,78 +109,21 @@ static const unsigned char kLower2Upper[256] = {
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
#define TOLOWER(_ucs2) \
|
||||
(((_ucs2) < 128) ? PRUnichar(kUpper2Lower[_ucs2]) : _ToLower(_ucs2))
|
||||
(((_ucs2) < 256) ? PRUnichar(kUpper2Lower[_ucs2]) : _ToLower(_ucs2))
|
||||
|
||||
#define TOUPPER(_ucs2) \
|
||||
(((_ucs2) < 128) ? PRUnichar(kLower2Upper[_ucs2]) : _ToUpper(_ucs2))
|
||||
|
||||
class HandleCaseConversionShutdown : public nsIShutdownListener {
|
||||
public :
|
||||
NS_IMETHOD OnShutdown(const nsCID& cid, nsISupports* service);
|
||||
HandleCaseConversionShutdown(void) { NS_INIT_REFCNT(); }
|
||||
virtual ~HandleCaseConversionShutdown(void) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
};
|
||||
static NS_DEFINE_CID(kUnicharUtilCID, NS_UNICHARUTIL_CID);
|
||||
static NS_DEFINE_IID(kICaseConversionIID, NS_ICASECONVERSION_IID);
|
||||
|
||||
static nsICaseConversion * gCaseConv = NULL;
|
||||
|
||||
static NS_DEFINE_IID(kIShutdownListenerIID, NS_ISHUTDOWNLISTENER_IID);
|
||||
NS_IMPL_ISUPPORTS(HandleCaseConversionShutdown, kIShutdownListenerIID);
|
||||
|
||||
nsresult
|
||||
HandleCaseConversionShutdown::OnShutdown(const nsCID& cid,
|
||||
nsISupports* aService)
|
||||
{
|
||||
if (cid.Equals(kUnicharUtilCID)) {
|
||||
NS_ASSERTION(aService == gCaseConv, "wrong service!");
|
||||
gCaseConv->Release();
|
||||
gCaseConv = NULL;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static HandleCaseConversionShutdown* gListener = NULL;
|
||||
|
||||
static void StartUpCaseConversion()
|
||||
{
|
||||
nsresult err;
|
||||
|
||||
if ( NULL == gListener )
|
||||
{
|
||||
gListener = new HandleCaseConversionShutdown();
|
||||
gListener->AddRef();
|
||||
}
|
||||
err = nsServiceManager::GetService(kUnicharUtilCID, kICaseConversionIID,
|
||||
(nsISupports**) &gCaseConv, gListener);
|
||||
}
|
||||
static void CheckCaseConversion()
|
||||
{
|
||||
if(NULL == gCaseConv )
|
||||
StartUpCaseConversion();
|
||||
|
||||
NS_ASSERTION( gCaseConv != NULL , "cannot obtain UnicharUtil");
|
||||
|
||||
}
|
||||
(((_ucs2) < 256) ? PRUnichar(kLower2Upper[_ucs2]) : _ToUpper(_ucs2))
|
||||
|
||||
static PRUnichar _ToLower(PRUnichar aChar)
|
||||
{
|
||||
PRUnichar oLower;
|
||||
CheckCaseConversion();
|
||||
nsresult err = gCaseConv->ToLower(aChar, &oLower);
|
||||
NS_ASSERTION( NS_SUCCEEDED(err), "failed to communicate to UnicharUtil");
|
||||
return ( NS_SUCCEEDED(err) ) ? oLower : aChar ;
|
||||
// XXX need i18n code here
|
||||
return aChar;
|
||||
}
|
||||
|
||||
static PRUnichar _ToUpper(PRUnichar aChar)
|
||||
{
|
||||
nsresult err;
|
||||
PRUnichar oUpper;
|
||||
CheckCaseConversion();
|
||||
err = gCaseConv->ToUpper(aChar, &oUpper);
|
||||
NS_ASSERTION( NS_SUCCEEDED(err), "failed to communicate to UnicharUtil");
|
||||
return ( NS_SUCCEEDED(err) ) ? oUpper : aChar ;
|
||||
// XXX need i18n code here
|
||||
return aChar;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
@@ -199,63 +138,9 @@ PRUnichar nsCRT::ToLower(PRUnichar aChar)
|
||||
return TOLOWER(aChar);
|
||||
}
|
||||
|
||||
PRBool nsCRT::IsUpper(PRUnichar aChar)
|
||||
PRInt32 nsCRT::strlen(const PRUnichar* s)
|
||||
{
|
||||
return aChar != nsCRT::ToLower(aChar);
|
||||
}
|
||||
|
||||
PRBool nsCRT::IsLower(PRUnichar aChar)
|
||||
{
|
||||
return aChar != nsCRT::ToUpper(aChar);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// My lovely strtok routine
|
||||
|
||||
#define IS_DELIM(m, c) ((m)[(c) >> 3] & (1 << ((c) & 7)))
|
||||
#define SET_DELIM(m, c) ((m)[(c) >> 3] |= (1 << ((c) & 7)))
|
||||
#define DELIM_TABLE_SIZE 32
|
||||
|
||||
char* nsCRT::strtok(char* str, const char* delims, char* *newStr)
|
||||
{
|
||||
NS_ASSERTION(str, "Unlike regular strtok, the first argument cannot be null.");
|
||||
|
||||
char delimTable[DELIM_TABLE_SIZE];
|
||||
PRUint32 i;
|
||||
char* result;
|
||||
|
||||
for (i = 0; i < DELIM_TABLE_SIZE; i++)
|
||||
delimTable[i] = '\0';
|
||||
|
||||
for (i = 0; i < DELIM_TABLE_SIZE && delims[i]; i++) {
|
||||
SET_DELIM(delimTable, delims[i]);
|
||||
}
|
||||
NS_ASSERTION(delims[i] == '\0', "too many delimiters");
|
||||
|
||||
// skip to beginning
|
||||
while (*str && IS_DELIM(delimTable, *str)) {
|
||||
str++;
|
||||
}
|
||||
result = str;
|
||||
|
||||
// fix up the end of the token
|
||||
while (*str) {
|
||||
if (IS_DELIM(delimTable, *str)) {
|
||||
*str++ = '\0';
|
||||
break;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
*newStr = str;
|
||||
|
||||
return str == result ? NULL : result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PRUint32 nsCRT::strlen(const PRUnichar* s)
|
||||
{
|
||||
PRUint32 len = 0;
|
||||
PRInt32 len = 0;
|
||||
if(s) {
|
||||
while (*s++ != 0) {
|
||||
len++;
|
||||
@@ -295,11 +180,11 @@ PRInt32 nsCRT::strcmp(const PRUnichar* s1, const PRUnichar* s2)
|
||||
* @param s1 and s2 both point to unichar strings
|
||||
* @return 0 if they match, -1 if s1<s2; 1 if s1>s2
|
||||
*/
|
||||
PRInt32 nsCRT::strncmp(const PRUnichar* s1, const PRUnichar* s2, PRUint32 n)
|
||||
PRInt32 nsCRT::strncmp(const PRUnichar* s1, const PRUnichar* s2, PRInt32 n)
|
||||
{
|
||||
if(s1 && s2) {
|
||||
if(n != 0) {
|
||||
do {
|
||||
if(0<n) {
|
||||
while (--n >= 0) {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = *s2++;
|
||||
if (c1 != c2) {
|
||||
@@ -307,7 +192,7 @@ PRInt32 nsCRT::strncmp(const PRUnichar* s1, const PRUnichar* s2, PRUint32 n)
|
||||
return 1;
|
||||
}
|
||||
if ((0==c1) || (0==c2)) break;
|
||||
} while (--n != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -349,11 +234,11 @@ PRInt32 nsCRT::strcasecmp(const PRUnichar* s1, const PRUnichar* s2)
|
||||
* @param s1 and s2 both point to unichar strings
|
||||
* @return 0 if they match, -1 if s1<s2; 1 if s1>s2
|
||||
*/
|
||||
PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const PRUnichar* s2, PRUint32 n)
|
||||
PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const PRUnichar* s2, PRInt32 n)
|
||||
{
|
||||
if(s1 && s2) {
|
||||
if(n != 0){
|
||||
do {
|
||||
if(0<n){
|
||||
while (--n >= 0) {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = *s2++;
|
||||
if (c1 != c2) {
|
||||
@@ -365,7 +250,7 @@ PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const PRUnichar* s2, PRUint32 n)
|
||||
}
|
||||
}
|
||||
if ((0==c1) || (0==c2)) break;
|
||||
} while (--n != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -405,11 +290,11 @@ PRInt32 nsCRT::strcmp(const PRUnichar* s1, const char* s2)
|
||||
* @param s2 points to cstring
|
||||
* @return 0 if they match, -1 if s1<s2; 1 if s1>s2
|
||||
*/
|
||||
PRInt32 nsCRT::strncmp(const PRUnichar* s1, const char* s2, PRUint32 n)
|
||||
PRInt32 nsCRT::strncmp(const PRUnichar* s1, const char* s2, PRInt32 n)
|
||||
{
|
||||
if(s1 && s2) {
|
||||
if(n != 0){
|
||||
do {
|
||||
if(0<n){
|
||||
while (--n >= 0) {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
|
||||
if (c1 != c2) {
|
||||
@@ -417,7 +302,7 @@ PRInt32 nsCRT::strncmp(const PRUnichar* s1, const char* s2, PRUint32 n)
|
||||
return 1;
|
||||
}
|
||||
if ((0==c1) || (0==c2)) break;
|
||||
} while (--n != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -459,11 +344,11 @@ PRInt32 nsCRT::strcasecmp(const PRUnichar* s1, const char* s2)
|
||||
* @param s2 points to cstring
|
||||
* @return 0 if they match, -1 if s1<s2; 1 if s1>s2
|
||||
*/
|
||||
PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const char* s2, PRUint32 n)
|
||||
PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const char* s2, PRInt32 n)
|
||||
{
|
||||
if(s1 && s2){
|
||||
if(n != 0){
|
||||
do {
|
||||
if(0<n){
|
||||
while (--n >= 0) {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
|
||||
if (c1 != c2) {
|
||||
@@ -475,7 +360,7 @@ PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const char* s2, PRUint32 n)
|
||||
}
|
||||
}
|
||||
if (c1 == 0) break;
|
||||
} while (--n != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -483,7 +368,7 @@ PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const char* s2, PRUint32 n)
|
||||
|
||||
PRUnichar* nsCRT::strdup(const PRUnichar* str)
|
||||
{
|
||||
PRUint32 len = nsCRT::strlen(str) + 1; // add one for null
|
||||
PRInt32 len = nsCRT::strlen(str) + 1; // add one for null
|
||||
PRUnichar* rslt = new PRUnichar[len];
|
||||
if (rslt == NULL) return NULL;
|
||||
nsCRT::memcpy(rslt, str, len * sizeof(PRUnichar));
|
||||
@@ -503,10 +388,10 @@ PRUint32 nsCRT::HashValue(const PRUnichar* us)
|
||||
return rv;
|
||||
}
|
||||
|
||||
PRUint32 nsCRT::HashValue(const PRUnichar* us, PRUint32* uslenp)
|
||||
PRUint32 nsCRT::HashValue(const PRUnichar* us, PRInt32* uslenp)
|
||||
{
|
||||
PRUint32 rv = 0;
|
||||
PRUint32 len = 0;
|
||||
PRInt32 len = 0;
|
||||
PRUnichar ch;
|
||||
while ((ch = *us++) != 0) {
|
||||
// FYI: rv = rv*37 + ch
|
||||
|
||||
@@ -22,74 +22,29 @@
|
||||
#include <string.h>
|
||||
#include "plstr.h"
|
||||
#include "nscore.h"
|
||||
#include "prtypes.h"
|
||||
|
||||
#define CR '\015'
|
||||
#define LF '\012'
|
||||
#define VTAB '\013'
|
||||
#define FF '\014'
|
||||
#define TAB '\011'
|
||||
#define CRLF "\015\012" /* A CR LF equivalent string */
|
||||
|
||||
|
||||
extern const PRUnichar kIsoLatin1ToUCS2[256];
|
||||
|
||||
|
||||
// This macro can be used in a class declaration for classes that want
|
||||
// to ensure that their instance memory is zeroed.
|
||||
#define NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW \
|
||||
void* operator new(size_t sz) { \
|
||||
void* rv = ::operator new(sz); \
|
||||
if (rv) { \
|
||||
nsCRT::zero(rv, sz); \
|
||||
} \
|
||||
return rv; \
|
||||
} \
|
||||
void operator delete(void* ptr) { \
|
||||
::operator delete(ptr); \
|
||||
}
|
||||
|
||||
// This macro works with the next macro to declare a non-inlined
|
||||
// version of the above.
|
||||
#define NS_DECL_ZEROING_OPERATOR_NEW \
|
||||
void* operator new(size_t sz); \
|
||||
void operator delete(void* ptr);
|
||||
|
||||
#define NS_IMPL_ZEROING_OPERATOR_NEW(_class) \
|
||||
void* _class::operator new(size_t sz) { \
|
||||
void* rv = ::operator new(sz); \
|
||||
if (rv) { \
|
||||
nsCRT::zero(rv, sz); \
|
||||
} \
|
||||
return rv; \
|
||||
} \
|
||||
void _class::operator delete(void* ptr) { \
|
||||
::operator delete(ptr); \
|
||||
}
|
||||
|
||||
/// This is a wrapper class around all the C runtime functions.
|
||||
|
||||
class NS_BASE nsCRT {
|
||||
public:
|
||||
|
||||
/** Copy bytes from aSrc to aDest.
|
||||
@param aDest the destination address
|
||||
@param aSrc the source address
|
||||
@param aCount the number of bytes to copy
|
||||
*/
|
||||
static void memcpy(void* aDest, const void* aSrc, PRUint32 aCount) {
|
||||
static void memcpy(void* aDest, const void* aSrc, PRInt32 aCount) {
|
||||
::memcpy(aDest, aSrc, (size_t)aCount);
|
||||
}
|
||||
|
||||
static void memmove(void* aDest, const void* aSrc, PRUint32 aCount) {
|
||||
static void memmove(void* aDest, const void* aSrc, PRInt32 aCount) {
|
||||
::memmove(aDest, aSrc, (size_t)aCount);
|
||||
}
|
||||
|
||||
static void memset(void* aDest, PRUint8 aByte, PRUint32 aCount) {
|
||||
static void memset(void* aDest, PRUint8 aByte, PRInt32 aCount) {
|
||||
::memset(aDest, aByte, aCount);
|
||||
}
|
||||
|
||||
static void zero(void* aDest, PRUint32 aCount) {
|
||||
static void zero(void* aDest, PRInt32 aCount) {
|
||||
::memset(aDest, 0, (size_t)aCount);
|
||||
}
|
||||
|
||||
@@ -97,18 +52,13 @@ public:
|
||||
@param s the string in question
|
||||
@return the length of s
|
||||
*/
|
||||
static PRUint32 strlen(const char* s) {
|
||||
return PRUint32(::strlen(s));
|
||||
static PRInt32 strlen(const char* s) {
|
||||
return PRInt32(::strlen(s));
|
||||
}
|
||||
|
||||
/// Compare s1 and s2.
|
||||
static PRInt32 strcmp(const char* s1, const char* s2) {
|
||||
return PRUint32(PL_strcmp(s1, s2));
|
||||
}
|
||||
|
||||
static PRUint32 strncmp(const char* s1, const char* s2,
|
||||
PRUint32 aMaxLen) {
|
||||
return PRInt32(PL_strncmp(s1, s2, aMaxLen));
|
||||
return PRInt32(PL_strcmp(s1, s2));
|
||||
}
|
||||
|
||||
/// Case-insensitive string comparison.
|
||||
@@ -117,83 +67,50 @@ public:
|
||||
}
|
||||
|
||||
/// Case-insensitive string comparison with length
|
||||
static PRInt32 strncasecmp(const char* s1, const char* s2, PRUint32 aMaxLen) {
|
||||
static PRInt32 strncasecmp(const char* s1, const char* s2, PRInt32 aMaxLen) {
|
||||
return PRInt32(PL_strncasecmp(s1, s2, aMaxLen));
|
||||
}
|
||||
|
||||
static PRInt32 strncmp(const char* s1, const char* s2, PRInt32 aMaxLen) {
|
||||
return PRInt32(PL_strncmp(s1,s2,aMaxLen));
|
||||
}
|
||||
|
||||
static char* strdup(const char* str) {
|
||||
return PL_strdup(str);
|
||||
}
|
||||
|
||||
static void free(char* str) {
|
||||
PL_strfree(str);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
How to use this fancy (thread-safe) version of strtok:
|
||||
|
||||
void main( void ) {
|
||||
printf( "%s\n\nTokens:\n", string );
|
||||
// Establish string and get the first token:
|
||||
char* newStr;
|
||||
token = nsCRT::strtok( string, seps, &newStr );
|
||||
while( token != NULL ) {
|
||||
// While there are tokens in "string"
|
||||
printf( " %s\n", token );
|
||||
// Get next token:
|
||||
token = nsCRT::strtok( newStr, seps, &newStr );
|
||||
}
|
||||
}
|
||||
* WARNING - STRTOK WHACKS str THE FIRST TIME IT IS CALLED *
|
||||
* MAKE A COPY OF str IF YOU NEED TO USE IT AFTER strtok() *
|
||||
*/
|
||||
static char* strtok(char* str, const char* delims, char* *newStr);
|
||||
|
||||
/// Like strlen except for ucs2 strings
|
||||
static PRUint32 strlen(const PRUnichar* s);
|
||||
static PRInt32 strlen(const PRUnichar* s);
|
||||
|
||||
/// Like strcmp except for ucs2 strings
|
||||
static PRInt32 strcmp(const PRUnichar* s1, const PRUnichar* s2);
|
||||
/// Like strcmp except for ucs2 strings
|
||||
static PRInt32 strncmp(const PRUnichar* s1, const PRUnichar* s2,
|
||||
PRUint32 aMaxLen);
|
||||
PRInt32 aMaxLen);
|
||||
|
||||
/// Like strcasecmp except for ucs2 strings
|
||||
static PRInt32 strcasecmp(const PRUnichar* s1, const PRUnichar* s2);
|
||||
/// Like strncasecmp except for ucs2 strings
|
||||
static PRInt32 strncasecmp(const PRUnichar* s1, const PRUnichar* s2,
|
||||
PRUint32 aMaxLen);
|
||||
PRInt32 aMaxLen);
|
||||
|
||||
/// Like strcmp with a char* and a ucs2 string
|
||||
static PRInt32 strcmp(const PRUnichar* s1, const char* s2);
|
||||
/// Like strncmp with a char* and a ucs2 string
|
||||
static PRInt32 strncmp(const PRUnichar* s1, const char* s2,
|
||||
PRUint32 aMaxLen);
|
||||
PRInt32 aMaxLen);
|
||||
|
||||
/// Like strcasecmp with a char* and a ucs2 string
|
||||
static PRInt32 strcasecmp(const PRUnichar* s1, const char* s2);
|
||||
/// Like strncasecmp with a char* and a ucs2 string
|
||||
static PRInt32 strncasecmp(const PRUnichar* s1, const char* s2,
|
||||
PRUint32 aMaxLen);
|
||||
PRInt32 aMaxLen);
|
||||
|
||||
// Note: uses new[] to allocate memory, so you must use delete[] to
|
||||
// free the memory
|
||||
static PRUnichar* strdup(const PRUnichar* str);
|
||||
|
||||
static void free(PRUnichar* str) {
|
||||
delete[] str;
|
||||
}
|
||||
|
||||
/// Compute a hashcode for a ucs2 string
|
||||
static PRUint32 HashValue(const PRUnichar* s1);
|
||||
|
||||
/// Same as above except that we return the length in s1len
|
||||
static PRUint32 HashValue(const PRUnichar* s1, PRUint32* s1len);
|
||||
static PRUint32 HashValue(const PRUnichar* s1, PRInt32* s1len);
|
||||
|
||||
/// String to integer.
|
||||
static PRInt32 atoi( const PRUnichar *string );
|
||||
@@ -201,10 +118,6 @@ public:
|
||||
static PRUnichar ToUpper(PRUnichar aChar);
|
||||
|
||||
static PRUnichar ToLower(PRUnichar aChar);
|
||||
|
||||
static PRBool IsUpper(PRUnichar aChar);
|
||||
|
||||
static PRBool IsLower(PRUnichar aChar);
|
||||
};
|
||||
|
||||
#endif /* nsCRT_h___ */
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
* @update gess4/18/98
|
||||
* @return new deque
|
||||
*/
|
||||
nsDeque::nsDeque(nsDequeFunctor* aDeallocator) {
|
||||
mDeallocator=aDeallocator;
|
||||
nsDeque::nsDeque(nsDequeFunctor& aMemDestroyer) : mMemDestroyer(aMemDestroyer) {
|
||||
mMemDestroyer=aMemDestroyer;
|
||||
mCapacity=eGrowthDelta;
|
||||
mOrigin=mSize=0;
|
||||
mData=new void*[mCapacity];
|
||||
@@ -44,10 +44,6 @@ nsDeque::~nsDeque() {
|
||||
Erase();
|
||||
delete [] mData;
|
||||
mData=0;
|
||||
if(mDeallocator) {
|
||||
delete mDeallocator;
|
||||
}
|
||||
mDeallocator=0;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,13 +59,6 @@ PRInt32 nsDeque::GetSize(void) const {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
void nsDeque::SetDeallocator(nsDequeFunctor* aDeallocator){
|
||||
if(mDeallocator) {
|
||||
delete mDeallocator;
|
||||
}
|
||||
mDeallocator=aDeallocator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all items from container without destroying them.
|
||||
*
|
||||
@@ -78,9 +67,7 @@ void nsDeque::SetDeallocator(nsDequeFunctor* aDeallocator){
|
||||
* @return
|
||||
*/
|
||||
nsDeque& nsDeque::Empty() {
|
||||
if((0<mCapacity) && (mData)) {
|
||||
nsCRT::zero(mData,mCapacity*sizeof(mData));
|
||||
}
|
||||
nsCRT::zero(mData,mCapacity*sizeof(mData));
|
||||
mSize=0;
|
||||
mOrigin=0;
|
||||
return *this;
|
||||
@@ -93,42 +80,11 @@ nsDeque& nsDeque::Empty() {
|
||||
* @return this
|
||||
*/
|
||||
nsDeque& nsDeque::Erase() {
|
||||
if(mDeallocator) {
|
||||
ForEach(*mDeallocator);
|
||||
}
|
||||
ForEach(mMemDestroyer);
|
||||
return Empty();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method adds an item to the end of the deque.
|
||||
* This operation has the potential to cause the
|
||||
* underlying buffer to resize.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param anItem: new item to be added to deque
|
||||
* @return nada
|
||||
*/
|
||||
nsDeque& nsDeque::GrowCapacity(void) {
|
||||
void** temp=new void*[mCapacity+eGrowthDelta];
|
||||
|
||||
//Here's the interesting part: You can't just move the elements
|
||||
//directy (in situ) from the old buffer to the new one.
|
||||
//Since capacity has changed, the old origin doesn't make
|
||||
//sense anymore. It's better to resequence the elements now.
|
||||
|
||||
int tempi=0;
|
||||
int i=0;
|
||||
int j=0;
|
||||
for(i=mOrigin;i<mCapacity;i++) temp[tempi++]=mData[i]; //copy the leading elements...
|
||||
for(j=0;j<mOrigin;j++) temp[tempi++]=mData[j]; //copy the trailing elements...
|
||||
mCapacity+=eGrowthDelta;
|
||||
mOrigin=0; //now realign the origin...
|
||||
delete[]mData;
|
||||
mData=temp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method adds an item to the end of the deque.
|
||||
* This operation has the potential to cause the
|
||||
@@ -140,7 +96,22 @@ nsDeque& nsDeque::GrowCapacity(void) {
|
||||
*/
|
||||
nsDeque& nsDeque::Push(void* anItem) {
|
||||
if(mSize==mCapacity) {
|
||||
GrowCapacity();
|
||||
void** temp=new void*[mCapacity+eGrowthDelta];
|
||||
|
||||
//Here's the interesting part: You can't just move the elements
|
||||
//directy (in situ) from the old buffer to the new one.
|
||||
//Since capacity has changed, the old origin doesn't make
|
||||
//sense anymore. It's better to resequence the elements now.
|
||||
|
||||
int tempi=0;
|
||||
int i=0;
|
||||
int j=0;
|
||||
for(i=mOrigin;i<mCapacity;i++) temp[tempi++]=mData[i]; //copy the leading elements...
|
||||
for(j=0;j<mOrigin;j++) temp[tempi++]=mData[j]; //copy the trailing elements...
|
||||
mCapacity+=eGrowthDelta;
|
||||
mOrigin=0; //now realign the origin...
|
||||
delete[]mData;
|
||||
mData=temp;
|
||||
}
|
||||
int offset=mOrigin+mSize;
|
||||
if(offset<mCapacity)
|
||||
@@ -150,6 +121,7 @@ nsDeque& nsDeque::Push(void* anItem) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method adds an item to the front of the deque.
|
||||
* This operation has the potential to cause the
|
||||
@@ -160,18 +132,15 @@ nsDeque& nsDeque::Push(void* anItem) {
|
||||
* @return nada
|
||||
*/
|
||||
nsDeque& nsDeque::PushFront(void* anItem) {
|
||||
if(mSize==mCapacity) {
|
||||
GrowCapacity();
|
||||
}
|
||||
if(0==mOrigin){ //case1: [xxx..]
|
||||
//mOrigin=mCapacity-1-mSize++;
|
||||
mOrigin=mCapacity-1;
|
||||
if(mOrigin>0) {
|
||||
mOrigin-=1;
|
||||
mData[mOrigin]=anItem;
|
||||
mSize++;
|
||||
}
|
||||
else {// if(mCapacity==(mOrigin+mSize-1)){ //case2: [..xxx] and case3: [.xxx.]
|
||||
mData[--mOrigin]=anItem;
|
||||
else {
|
||||
Push(anItem);
|
||||
mOrigin=mSize-1;
|
||||
}
|
||||
mSize++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ public:
|
||||
class NS_BASE nsDeque {
|
||||
friend class nsDequeIterator;
|
||||
public:
|
||||
nsDeque(nsDequeFunctor* aDeallocator);
|
||||
nsDeque(nsDequeFunctor& aMemDestroyer);
|
||||
~nsDeque();
|
||||
|
||||
/**
|
||||
@@ -201,8 +201,6 @@ friend class nsDequeIterator;
|
||||
*/
|
||||
const void* FirstThat(nsDequeFunctor& aFunctor) const;
|
||||
|
||||
void SetDeallocator(nsDequeFunctor* aDeallocator);
|
||||
|
||||
/**
|
||||
* Perform automated selftest on the deque
|
||||
*
|
||||
@@ -217,7 +215,7 @@ protected:
|
||||
PRInt32 mSize;
|
||||
PRInt32 mCapacity;
|
||||
PRInt32 mOrigin;
|
||||
nsDequeFunctor* mDeallocator;
|
||||
nsDequeFunctor& mMemDestroyer;
|
||||
void** mData;
|
||||
|
||||
|
||||
@@ -252,8 +250,6 @@ private:
|
||||
*/
|
||||
nsDeque& operator=(const nsDeque& anOther);
|
||||
|
||||
nsDeque& GrowCapacity(void);
|
||||
|
||||
};
|
||||
|
||||
/******************************************************
|
||||
@@ -402,7 +398,6 @@ public:
|
||||
const void* FirstThat(nsDequeFunctor& aFunctor) const;
|
||||
|
||||
protected:
|
||||
|
||||
PRInt32 mIndex;
|
||||
const nsDeque& mDeque;
|
||||
};
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "nsEscape.h"
|
||||
|
||||
#include "plstr.h"
|
||||
#include "prmem.h"
|
||||
|
||||
const int netCharType[256] =
|
||||
/* Bit 0 xalpha -- the alphas
|
||||
@@ -54,7 +53,7 @@ const int netCharType[256] =
|
||||
#define HEX_ESCAPE '%'
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_BASE char* nsEscape(const char * str, nsEscapeMask mask)
|
||||
char* nsEscape(const char * str, nsEscapeMask mask)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if(!str)
|
||||
@@ -63,64 +62,45 @@ NS_BASE char* nsEscape(const char * str, nsEscapeMask mask)
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_BASE char* nsEscapeCount(
|
||||
const char * str,
|
||||
PRInt32 len,
|
||||
nsEscapeMask mask,
|
||||
PRInt32* out_len)
|
||||
char* nsEscapeCount(const char * str, PRInt32 len, nsEscapeMask mask, PRInt32 * out_len)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!str)
|
||||
return 0;
|
||||
int32 i, extra = 0;
|
||||
char *hexChars = "0123456789ABCDEF";
|
||||
|
||||
int i, extra = 0;
|
||||
char* hexChars = "0123456789ABCDEF";
|
||||
if(!str)
|
||||
return(0);
|
||||
|
||||
register const unsigned char* src = (const unsigned char *) str;
|
||||
register const unsigned char* src = (unsigned char *) str;
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (!IS_OK(*src++))
|
||||
extra += 2; /* the escape, plus an extra byte for each nibble */
|
||||
}
|
||||
{
|
||||
if (!IS_OK(src[i]))
|
||||
extra+=2; /* the escape, plus an extra byte for each nibble */
|
||||
}
|
||||
|
||||
char* result = new char[len + extra + 1];
|
||||
if (!result)
|
||||
return 0;
|
||||
return(0);
|
||||
|
||||
register unsigned char* dst = (unsigned char *) result;
|
||||
src = (const unsigned char *) str;
|
||||
if (mask == url_XPAlphas)
|
||||
{
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
unsigned char c = *src++;
|
||||
if (IS_OK(c))
|
||||
*dst++ = c;
|
||||
else if (c == ' ')
|
||||
*dst++ = '+'; /* convert spaces to pluses */
|
||||
else
|
||||
{
|
||||
*dst++ = HEX_ESCAPE;
|
||||
*dst++ = hexChars[c >> 4]; /* high nibble */
|
||||
*dst++ = hexChars[c & 0x0f]; /* low nibble */
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
unsigned char c = *src++;
|
||||
if (IS_OK(c))
|
||||
*dst++ = c;
|
||||
else
|
||||
{
|
||||
*dst++ = HEX_ESCAPE;
|
||||
*dst++ = hexChars[c >> 4]; /* high nibble */
|
||||
*dst++ = hexChars[c & 0x0f]; /* low nibble */
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
unsigned char c = src[i];
|
||||
if (IS_OK(c))
|
||||
{
|
||||
*dst++ = c;
|
||||
}
|
||||
else if (mask == url_XPAlphas && c == ' ')
|
||||
{
|
||||
*dst++ = '+'; /* convert spaces to pluses */
|
||||
}
|
||||
else
|
||||
{
|
||||
*dst++ = HEX_ESCAPE;
|
||||
*dst++ = hexChars[c >> 4]; /* high nibble */
|
||||
*dst++ = hexChars[c & 0x0f]; /* low nibble */
|
||||
}
|
||||
}
|
||||
|
||||
*dst = '\0'; /* tack on eos */
|
||||
if(out_len)
|
||||
@@ -129,7 +109,7 @@ NS_BASE char* nsEscapeCount(
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_BASE char* nsUnescape(char * str)
|
||||
char* nsUnescape(char * str)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsUnescapeCount(str);
|
||||
@@ -137,7 +117,7 @@ NS_BASE char* nsUnescape(char * str)
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_BASE PRInt32 nsUnescapeCount(char * str)
|
||||
PRInt32 nsUnescapeCount(char * str)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
register char *src = str;
|
||||
@@ -145,70 +125,28 @@ NS_BASE PRInt32 nsUnescapeCount(char * str)
|
||||
|
||||
while (*src)
|
||||
if (*src != HEX_ESCAPE)
|
||||
{
|
||||
*dst++ = *src++;
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
src++; /* walk over escape */
|
||||
if (*src)
|
||||
{
|
||||
{
|
||||
*dst = UNHEX(*src) << 4;
|
||||
src++;
|
||||
}
|
||||
}
|
||||
if (*src)
|
||||
{
|
||||
{
|
||||
*dst = (*dst + UNHEX(*src));
|
||||
src++;
|
||||
}
|
||||
}
|
||||
dst++;
|
||||
}
|
||||
}
|
||||
|
||||
*dst = 0;
|
||||
|
||||
return (int)(dst - str);
|
||||
|
||||
} /* NET_UnEscapeCnt */
|
||||
|
||||
|
||||
NS_BASE char *
|
||||
nsEscapeHTML(const char * string)
|
||||
{
|
||||
char *rv = (char *) PR_Malloc(PL_strlen(string)*4 + 1); /* The +1 is for
|
||||
the trailing
|
||||
null! */
|
||||
char *ptr = rv;
|
||||
|
||||
if(rv)
|
||||
{
|
||||
for(; *string != '\0'; string++)
|
||||
{
|
||||
if(*string == '<')
|
||||
{
|
||||
*ptr++ = '&';
|
||||
*ptr++ = 'l';
|
||||
*ptr++ = 't';
|
||||
*ptr++ = ';';
|
||||
}
|
||||
else if(*string == '>')
|
||||
{
|
||||
*ptr++ = '&';
|
||||
*ptr++ = 'g';
|
||||
*ptr++ = 't';
|
||||
*ptr++ = ';';
|
||||
}
|
||||
else if(*string == '&')
|
||||
{
|
||||
*ptr++ = '&';
|
||||
*ptr++ = 'a';
|
||||
*ptr++ = 'm';
|
||||
*ptr++ = 'p';
|
||||
*ptr++ = ';';
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr++ = *string;
|
||||
}
|
||||
}
|
||||
*ptr = '\0';
|
||||
}
|
||||
|
||||
return(rv);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,82 +0,0 @@
|
||||
#include "nsFileSpecStreaming.h"
|
||||
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsFileStream.h"
|
||||
#include "nsFileSpec.h"
|
||||
|
||||
#define MAX_PERSISTENT_DATA_SIZE 1000
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream& operator << (nsOutputStream& s, const nsFileURL& url)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return s << url.GetAsString();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsresult ReadDescriptor(
|
||||
nsIInputStream* aStream,
|
||||
nsPersistentFileDescriptor& desc)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsInputStream inputStream(aStream);
|
||||
inputStream >> desc;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsresult WriteDescriptor(
|
||||
nsIOutputStream* aStream,
|
||||
const nsPersistentFileDescriptor& desc)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsOutputStream outputStream(aStream);
|
||||
outputStream << desc;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsInputStream& operator >> (nsInputStream& s, nsPersistentFileDescriptor& d)
|
||||
// reads the data from a file
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char bigBuffer[MAX_PERSISTENT_DATA_SIZE + 1];
|
||||
// The first 8 bytes of the data should be a hex version of the data size to follow.
|
||||
PRInt32 bytesRead = 8;
|
||||
bytesRead = s.read(bigBuffer, bytesRead);
|
||||
if (bytesRead != 8)
|
||||
return s;
|
||||
bigBuffer[8] = '\0';
|
||||
sscanf(bigBuffer, "%x", (PRUint32*)&bytesRead);
|
||||
if (bytesRead > MAX_PERSISTENT_DATA_SIZE)
|
||||
{
|
||||
// Try to tolerate encoded values with no length header
|
||||
bytesRead = 8 + s.read(bigBuffer + 8, MAX_PERSISTENT_DATA_SIZE - 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Now we know how many bytes to read, do it.
|
||||
bytesRead = s.read(bigBuffer, bytesRead);
|
||||
}
|
||||
d.SetData(bigBuffer, bytesRead);
|
||||
return s;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream& operator << (nsOutputStream& s, const nsPersistentFileDescriptor& d)
|
||||
// writes the data to a file
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char littleBuf[9];
|
||||
PRInt32 dataSize;
|
||||
nsSimpleCharString data;
|
||||
d.GetData(data, dataSize);
|
||||
// First write (in hex) the length of the data to follow. Exactly 8 bytes
|
||||
sprintf(littleBuf, "%0.8x", dataSize);
|
||||
s << littleBuf;
|
||||
// Now write the data itself
|
||||
s << (const char*)data;
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -22,257 +22,272 @@
|
||||
|
||||
#include "nsFileStream.h"
|
||||
|
||||
#include "nsIStringStream.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef XP_MAC
|
||||
#include <Errors.h>
|
||||
#endif
|
||||
|
||||
//========================================================================================
|
||||
// nsInputStream
|
||||
// nsBasicFileStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsInputStream::~nsInputStream()
|
||||
nsBasicFileStream::nsBasicFileStream()
|
||||
//----------------------------------------------------------------------------------------
|
||||
: mFileDesc(0)
|
||||
, mNSPRMode(0)
|
||||
, mFailed(false)
|
||||
, mEOF(false)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
char nsInputStream::get()
|
||||
nsBasicFileStream::nsBasicFileStream(
|
||||
const nsFilePath& inFile,
|
||||
int nsprMode,
|
||||
PRIntn accessMode)
|
||||
//----------------------------------------------------------------------------------------
|
||||
: mFileDesc(0)
|
||||
, mNSPRMode(0)
|
||||
, mFailed(false)
|
||||
, mEOF(false)
|
||||
{
|
||||
char c;
|
||||
if (read(&c, sizeof(c)) == sizeof(c))
|
||||
return c;
|
||||
return 0;
|
||||
open(inFile, nsprMode, accessMode);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
PRInt32 nsInputStream::read(void* s, PRInt32 n)
|
||||
nsBasicFileStream::nsBasicFileStream(PRFileDesc* desc, int nsprMode)
|
||||
//----------------------------------------------------------------------------------------
|
||||
: mFileDesc(desc)
|
||||
, mNSPRMode(nsprMode)
|
||||
, mFailed(false)
|
||||
, mEOF(false)
|
||||
{
|
||||
if (!mInputStream)
|
||||
return 0;
|
||||
PRInt32 result = 0;
|
||||
mInputStream->Read((char*)s, n, (PRUint32*)&result);
|
||||
if (result < n)
|
||||
set_at_eof(PR_TRUE);
|
||||
return result;
|
||||
} // nsInputStream::read
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
static void TidyEndOfLine(char*& cp)
|
||||
// Assumes that cp is pointing at \n or \r. Nulls out the character, checks for
|
||||
// a second terminator (of the opposite persuasion), and returns cp pointing past the
|
||||
// entire eol construct (one or two characters).
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char ch = *cp;
|
||||
*cp++ = '\0'; // terminate at the newline, then skip past it
|
||||
if ((ch == '\n' && *cp == '\r') || (ch == '\r' && *cp == '\n'))
|
||||
cp++; // possibly a pair.
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsInputStream& nsInputStream::operator >> (char& c)
|
||||
nsBasicFileStream::~nsBasicFileStream()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
c = get();
|
||||
return *this;
|
||||
close();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsBasicFileStream::open(
|
||||
const nsFilePath& inFile,
|
||||
int nsprMode,
|
||||
PRIntn accessMode)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (mFileDesc)
|
||||
return;
|
||||
|
||||
const int nspr_modes[]={
|
||||
PR_WRONLY | PR_CREATE_FILE,
|
||||
PR_WRONLY | PR_CREATE_FILE | PR_APPEND,
|
||||
PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE,
|
||||
PR_RDONLY,
|
||||
PR_RDONLY | PR_APPEND,
|
||||
PR_RDWR | PR_CREATE_FILE,
|
||||
PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE,
|
||||
// "wb",
|
||||
// "ab",
|
||||
// "wb",
|
||||
// "rb",
|
||||
// "r+b",
|
||||
// "w+b",
|
||||
0 };
|
||||
const int* currentLegalMode = nspr_modes;
|
||||
while (*currentLegalMode && nsprMode != *currentLegalMode)
|
||||
++currentLegalMode;
|
||||
if (!*currentLegalMode)
|
||||
return;
|
||||
|
||||
#ifdef XP_MAC
|
||||
// Use the file spec to open the file, because one path can be common to
|
||||
// several files on the Macintosh (you can have several volumes with the
|
||||
// same name, see).
|
||||
mFileDesc = 0;
|
||||
if (inFile.GetNativeSpec().Error() != noErr)
|
||||
return;
|
||||
OSErr err = noErr;
|
||||
#if DEBUG
|
||||
const OSType kCreator = 'CWIE';
|
||||
#else
|
||||
const OSType kCreator = 'MOSS';
|
||||
#endif
|
||||
nsNativeFileSpec nativeSpec = inFile.GetNativeSpec();
|
||||
FSSpec* spec = (FSSpec*)nativeSpec;
|
||||
if (nsprMode & PR_CREATE_FILE)
|
||||
err = FSpCreate(spec, kCreator, 'TEXT', 0);
|
||||
if (err == dupFNErr)
|
||||
err = noErr;
|
||||
if (err != noErr)
|
||||
return;
|
||||
|
||||
SInt8 perm;
|
||||
if (nsprMode & PR_RDWR)
|
||||
perm = fsRdWrPerm;
|
||||
else if (nsprMode & PR_WRONLY)
|
||||
perm = fsWrPerm;
|
||||
else
|
||||
perm = fsRdPerm;
|
||||
|
||||
short refnum;
|
||||
err = FSpOpenDF(spec, perm, &refnum);
|
||||
|
||||
if (err == noErr && (nsprMode & PR_TRUNCATE))
|
||||
err = SetEOF(refnum, 0);
|
||||
if (err == noErr && (nsprMode & PR_APPEND))
|
||||
err = SetFPos(refnum, fsFromLEOF, 0);
|
||||
if (err != noErr)
|
||||
return;
|
||||
|
||||
if ((mFileDesc = PR_ImportFile(refnum)) == 0)
|
||||
return;
|
||||
#else
|
||||
// Platforms other than Macintosh...
|
||||
// Another bug in NSPR: Mac PR_Open assumes a unix style path, but Win PR_Open assumes
|
||||
// a windows path.
|
||||
if ((mFileDesc = PR_Open((const char*)nsNativeFileSpec(inFile), nsprMode, accessMode)) == 0)
|
||||
return;
|
||||
#endif
|
||||
mNSPRMode = nsprMode;
|
||||
} // nsFileStreamHelpers::open
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsBasicFileStream::close()
|
||||
// Must precede the destructor because both are inline.
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (mFileDesc==PR_STDIN || mFileDesc==PR_STDOUT || mFileDesc==PR_STDERR || mFileDesc == 0)
|
||||
return;
|
||||
if (PR_Close(mFileDesc) == PR_SUCCESS)
|
||||
mFileDesc = 0;
|
||||
} // nsBasicFileStream::close
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsBasicFileStream::seek(PRSeekWhence whence, PRInt32 offset)
|
||||
// Must precede the destructor because both are inline.
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (mFileDesc==PR_STDIN || mFileDesc==PR_STDOUT || mFileDesc==PR_STDERR || mFileDesc == 0)
|
||||
return;
|
||||
mFailed = false; // reset on a seek.
|
||||
mEOF = false; // reset on a seek.
|
||||
PRInt32 position = PR_Seek(mFileDesc, 0, PR_SEEK_CUR);
|
||||
PRInt32 available = PR_Available(mFileDesc);
|
||||
PRInt32 fileSize = position + available;
|
||||
PRInt32 newPosition;
|
||||
switch (whence)
|
||||
{
|
||||
case PR_SEEK_CUR: newPosition = position + offset; break;
|
||||
case PR_SEEK_SET: newPosition = offset; break;
|
||||
case PR_SEEK_END: newPosition = fileSize + offset; break;
|
||||
}
|
||||
if (newPosition < 0)
|
||||
{
|
||||
newPosition = 0;
|
||||
mFailed = true;
|
||||
}
|
||||
else if (newPosition >= fileSize)
|
||||
{
|
||||
newPosition = fileSize;
|
||||
mEOF = true;
|
||||
}
|
||||
if (PR_Seek(mFileDesc, newPosition, PR_SEEK_SET) < 0)
|
||||
mFailed = true;
|
||||
} // nsBasicFileStream::seek
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
PRIntn nsBasicFileStream::tell() const
|
||||
// Must precede the destructor because both are inline.
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (mFileDesc==PR_STDIN || mFileDesc==PR_STDOUT || mFileDesc==PR_STDERR || mFileDesc == 0)
|
||||
return -1;
|
||||
return PR_Seek(mFileDesc, 0, PR_SEEK_CUR);
|
||||
} // nsBasicFileStream::tell
|
||||
|
||||
//========================================================================================
|
||||
// nsOutputStream
|
||||
// nsBasicInStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream::~nsOutputStream()
|
||||
nsBasicInStream::nsBasicInStream(nsBasicFileStream& inBasicStream, istream* inStream)
|
||||
//----------------------------------------------------------------------------------------
|
||||
: mBase(inBasicStream)
|
||||
, mStdStream(inStream)
|
||||
{
|
||||
}
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsBasicInStream::get(char& c)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
read(&c, sizeof(char));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsOutputStream::put(char c)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
write(&c, sizeof(c));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
PRInt32 nsOutputStream::write(const void* s, PRInt32 n)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!mOutputStream)
|
||||
return 0;
|
||||
PRInt32 result = 0;
|
||||
mOutputStream->Write((char*)s, n, (PRUint32*)&result);
|
||||
return result;
|
||||
} // nsOutputStream::write
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsOutputStream::flush()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream& nsOutputStream::operator << (char c)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
put(c);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream& nsOutputStream::operator << (const char* s)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
write(s, strlen(s));
|
||||
return *this;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream& nsOutputStream::operator << (short val)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char buf[30];
|
||||
sprintf(buf, "%hd", val);
|
||||
return (*this << buf);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream& nsOutputStream::operator << (unsigned short val)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char buf[30];
|
||||
sprintf(buf, "%hu", val);
|
||||
return (*this << buf);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream& nsOutputStream::operator << (long val)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char buf[30];
|
||||
sprintf(buf, "%ld", val);
|
||||
return (*this << buf);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream& nsOutputStream::operator << (unsigned long val)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char buf[30];
|
||||
sprintf(buf, "%lu", val);
|
||||
return (*this << buf);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream& nsOutputStream::operator << (int val)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char buf[30];
|
||||
sprintf(buf, "%d", val);
|
||||
return (*this << buf);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream& nsOutputStream::operator << (unsigned int val)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char buf[30];
|
||||
sprintf(buf, "%u", val);
|
||||
return (*this << buf);
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// nsRandomAccessInputStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
PRBool nsRandomAccessInputStream::readline(char* s, PRInt32 n)
|
||||
PRBool nsBasicInStream::readline(char* s, PRInt32 n)
|
||||
// This will truncate if the buffer is too small. Result will always be null-terminated.
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
PRBool bufferLargeEnough = PR_TRUE; // result
|
||||
PRBool bufferLargeEnough = true; // result
|
||||
if (!s || !n)
|
||||
return PR_TRUE;
|
||||
|
||||
PRIntn position = tell();
|
||||
return true;
|
||||
PRIntn position = mBase.tell();
|
||||
if (position < 0)
|
||||
return PR_FALSE;
|
||||
return false;
|
||||
PRInt32 bytesRead = read(s, n - 1);
|
||||
if (failed())
|
||||
return PR_FALSE;
|
||||
if (mBase.failed())
|
||||
return false;
|
||||
s[bytesRead] = '\0'; // always terminate at the end of the buffer
|
||||
char* tp = strpbrk(s, "\n\r");
|
||||
if (tp)
|
||||
{
|
||||
TidyEndOfLine(tp);
|
||||
char ch = *tp;
|
||||
*tp++ = '\0'; // terminate at the newline, then skip past it
|
||||
if ((ch == '\n' && *tp == '\r') || (ch == '\r' && *tp == '\n'))
|
||||
tp++; // possibly a pair.
|
||||
bytesRead = (tp - s);
|
||||
}
|
||||
else if (!eof())
|
||||
bufferLargeEnough = PR_FALSE;
|
||||
else if (!mBase.eof())
|
||||
bufferLargeEnough = false;
|
||||
position += bytesRead;
|
||||
seek(position);
|
||||
mBase.seek(position);
|
||||
return bufferLargeEnough;
|
||||
} // nsRandomAccessInputStream::readline
|
||||
|
||||
//========================================================================================
|
||||
// nsInputStringStream
|
||||
//========================================================================================
|
||||
} // nsBasicInStream::getline
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsInputStringStream::nsInputStringStream(const char* stringToRead)
|
||||
PRInt32 nsBasicInStream::read(void* s, PRInt32 n)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewCharInputStream(&stream, stringToRead)))
|
||||
return;
|
||||
mInputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
#ifndef NS_USE_PR_STDIO
|
||||
// Calling PR_Read on stdin is sure suicide on Macintosh.
|
||||
if (GetStandardStream())
|
||||
{
|
||||
GetStandardStream()->read((char*)s, n);
|
||||
return n;
|
||||
}
|
||||
#endif
|
||||
if (!mBase.is_open() || mBase.failed())
|
||||
return -1;
|
||||
PRInt32 bytesRead = PR_Read(mBase.GetFileDescriptor(), s, n);
|
||||
if (bytesRead < 0)
|
||||
mBase.mFailed = true;
|
||||
else if (bytesRead < n)
|
||||
mBase.mEOF = true;
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsInputStringStream::nsInputStringStream(const nsString& stringToRead)
|
||||
nsBasicInStream& nsBasicInStream::operator >> (char& c)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewStringInputStream(&stream, stringToRead)))
|
||||
return;
|
||||
mInputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// nsOutputStringStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStringStream::nsOutputStringStream(char*& stringToChange)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewCharOutputStream(&stream, &stringToChange)))
|
||||
return;
|
||||
mOutputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStringStream::nsOutputStringStream(nsString& stringToChange)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewStringOutputStream(&stream, stringToChange)))
|
||||
return;
|
||||
mOutputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
get(c);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
@@ -280,32 +295,146 @@ nsOutputStringStream::nsOutputStringStream(nsString& stringToChange)
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsInputFileStream::nsInputFileStream(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode,
|
||||
PRIntn accessMode)
|
||||
nsInputFileStream::nsInputFileStream(istream* stream)
|
||||
//----------------------------------------------------------------------------------------
|
||||
#ifndef NS_USE_PR_STDIO
|
||||
: nsBasicFileStream(0, kDefaultMode)
|
||||
, nsBasicInStream(*this, stream)
|
||||
#else
|
||||
: nsBasicFileStream(PR_STDIN, kDefaultMode)
|
||||
, nsBasicInStream(*this, 0)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// nsBasicOutStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsBasicOutStream::nsBasicOutStream(nsBasicFileStream& inBase, ostream* stream)
|
||||
//----------------------------------------------------------------------------------------
|
||||
: mBase(inBase)
|
||||
, mStdStream(stream)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsBasicOutStream::put(char c)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewIOFileStream(&stream, inFile, nsprMode, accessMode)))
|
||||
write(&c, sizeof(c));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
PRInt32 nsBasicOutStream::write(const void* s, PRInt32 n)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
#ifndef NS_USE_PR_STDIO
|
||||
// Calling PR_Write on stdout is sure suicide.
|
||||
if (mStdStream)
|
||||
{
|
||||
mStdStream->write((const char*)s, n);
|
||||
return n;
|
||||
}
|
||||
#endif
|
||||
if (!mBase.mFileDesc || mBase.failed())
|
||||
return -1;
|
||||
PRInt32 bytesWrit = PR_Write(mBase.mFileDesc, s, n);
|
||||
if (bytesWrit != n)
|
||||
mBase.mFailed = true;
|
||||
return bytesWrit;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsBasicOutStream& nsBasicOutStream::operator << (char c)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
put(c);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsBasicOutStream& nsBasicOutStream::operator << (const char* s)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
write(s, strlen(s));
|
||||
return *this;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsBasicOutStream& nsBasicOutStream::operator << (short val)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char buf[30];
|
||||
sprintf(buf, "%d", val);
|
||||
return *this << buf;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsBasicOutStream& nsBasicOutStream::operator << (unsigned short val)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char buf[30];
|
||||
sprintf(buf, "%ud", val);
|
||||
return *this << buf;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsBasicOutStream& nsBasicOutStream::operator << (long val)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char buf[30];
|
||||
sprintf(buf, "%ld", val);
|
||||
return *this << buf;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsBasicOutStream& nsBasicOutStream::operator << (unsigned long val)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char buf[30];
|
||||
sprintf(buf, "%uld", val);
|
||||
return *this << buf;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsBasicOutStream::flush()
|
||||
// Must precede the destructor because both are inline.
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
#ifndef NS_USE_PR_STDIO
|
||||
if (mStdStream)
|
||||
{
|
||||
mStdStream->flush();
|
||||
return;
|
||||
mFile = nsQueryInterface(stream);
|
||||
mInputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
mFileInputStream = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
} // nsInputFileStream::nsInputFileStream
|
||||
}
|
||||
#endif
|
||||
if (mBase.mFileDesc == 0)
|
||||
return;
|
||||
PRBool itFailed = PR_Sync(mBase.mFileDesc) != PR_SUCCESS;
|
||||
#ifdef XP_MAC
|
||||
// On unix, it seems to fail always.
|
||||
if (itFailed)
|
||||
mBase.mFailed = true;
|
||||
#endif
|
||||
} // nsBasicOutStream::flush
|
||||
|
||||
//========================================================================================
|
||||
// nsOutputFileStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsOutputFileStream::flush()
|
||||
nsOutputFileStream::nsOutputFileStream(ostream* stream)
|
||||
//----------------------------------------------------------------------------------------
|
||||
#ifndef NS_USE_PR_STDIO
|
||||
: nsBasicFileStream(0, kDefaultMode)
|
||||
, nsBasicOutStream(*this, stream)
|
||||
#else
|
||||
: nsBasicFileStream(PR_STDOUT, kDefaultMode)
|
||||
, nsBasicOutStream(*this, 0)
|
||||
#endif
|
||||
{
|
||||
if (mFileOutputStream)
|
||||
mFileOutputStream->Flush();
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
@@ -313,14 +442,19 @@ void nsOutputFileStream::flush()
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream& nsEndl(nsOutputStream& os)
|
||||
nsBasicOutStream& nsEndl(nsBasicOutStream& os)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
#ifdef XP_PC
|
||||
os.write("\r\n", 2);
|
||||
#else
|
||||
os.put('\n');
|
||||
#ifndef NS_USE_PR_STDIO
|
||||
// Calling PR_Write on stdout is sure suicide on Macintosh.
|
||||
ostream* stream = os.GetStandardStream();
|
||||
if (stream)
|
||||
{
|
||||
*stream << std::endl;
|
||||
return os;
|
||||
}
|
||||
#endif
|
||||
os.flush();
|
||||
return os;
|
||||
} // nsEndl
|
||||
os.put('\n');
|
||||
os.flush();
|
||||
return os;
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
#include "nsCaretProperties.h"
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
nsCaretProperties::nsCaretProperties()
|
||||
: mCaretWidth(eDefaultCaretWidth)
|
||||
, mBlinkRate(eDefaulBlinkRate)
|
||||
{
|
||||
// in your platform-specific class, get data from the OS in your constructor
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
nsCaretProperties* NewCaretProperties()
|
||||
{
|
||||
return new nsCaretProperties();
|
||||
}
|
||||
@@ -37,8 +37,6 @@
|
||||
*/
|
||||
class nsIArena : public nsISupports {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IARENA_IID; return iid; }
|
||||
|
||||
virtual void* Alloc(PRInt32 size) = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -35,8 +35,6 @@ class nsISizeOfHandler;
|
||||
*/
|
||||
class nsIAtom : public nsISupports {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IATOM_IID; return iid; }
|
||||
|
||||
/**
|
||||
* Translate the unicode string into the stringbuf.
|
||||
*/
|
||||
|
||||
@@ -31,8 +31,6 @@
|
||||
class nsIBaseStream : public nsISupports {
|
||||
public:
|
||||
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IBASESTREAM_IID; return iid; }
|
||||
|
||||
/** Close the stream. */
|
||||
NS_IMETHOD
|
||||
Close(void) = 0;
|
||||
@@ -52,8 +50,6 @@ public:
|
||||
#define NS_BASE_STREAM_NO_CONVERTER NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 5)
|
||||
/// For unichar streams
|
||||
#define NS_BASE_STREAM_BAD_CONVERSION NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 6)
|
||||
|
||||
#define NS_BASE_STREAM_WOULD_BLOCK NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_BASE, 7)
|
||||
//@}
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIByteBuffer_h___
|
||||
#define nsIByteBuffer_h___
|
||||
|
||||
@@ -32,28 +31,27 @@ class nsIInputStream;
|
||||
class nsIByteBuffer : public nsISupports {
|
||||
public:
|
||||
/** @return length of buffer, i.e. how many bytes are currently in it. */
|
||||
NS_IMETHOD_(PRUint32) GetLength(void) const = 0;
|
||||
virtual PRUint32 GetLength(void) const = 0;
|
||||
|
||||
/** @return number of bytes allocated in the buffer */
|
||||
NS_IMETHOD_(PRUint32) GetBufferSize(void) const = 0;
|
||||
virtual PRUint32 GetBufferSize(void) const = 0;
|
||||
|
||||
/** @return the buffer */
|
||||
NS_IMETHOD_(char*) GetBuffer(void) const = 0;
|
||||
virtual char* GetBuffer(void) const = 0;
|
||||
|
||||
/** Grow buffer to aNewSize bytes. */
|
||||
NS_IMETHOD_(PRBool) Grow(PRUint32 aNewSize) = 0;
|
||||
virtual PRBool Grow(PRUint32 aNewSize) = 0;
|
||||
|
||||
/** Fill the buffer with data from aStream. Don't grow the buffer, only
|
||||
* read until length of buffer equals buffer size. */
|
||||
NS_IMETHOD_(PRInt32) Fill(nsresult* aErrorCode, nsIInputStream* aStream,
|
||||
PRUint32 aKeep) = 0;
|
||||
virtual PRInt32 Fill(nsresult* aErrorCode, nsIInputStream* aStream,
|
||||
PRUint32 aKeep) = 0;
|
||||
};
|
||||
|
||||
/** Create a new byte buffer using the given buffer size. */
|
||||
extern NS_BASE nsresult
|
||||
NS_NewByteBuffer(nsIByteBuffer** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
PRUint32 aBufferSize = 0);
|
||||
extern NS_BASE nsresult NS_NewByteBuffer(nsIByteBuffer** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
PRUint32 aBufferSize = 0);
|
||||
|
||||
#endif /* nsIByteBuffer_h___ */
|
||||
|
||||
|
||||
@@ -1,482 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsIFileStream.h"
|
||||
#include "nsFileSpec.h"
|
||||
|
||||
#include "prerror.h"
|
||||
|
||||
#ifdef XP_MAC
|
||||
#include "pprio.h" // To get PR_ImportFile
|
||||
#else
|
||||
#include "prio.h"
|
||||
#endif
|
||||
|
||||
#ifdef XP_MAC
|
||||
#include <Errors.h>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
//========================================================================================
|
||||
class FileImpl
|
||||
: public nsIRandomAccessStore
|
||||
, public nsIFileOutputStream
|
||||
, public nsIFileInputStream
|
||||
, public nsIFile
|
||||
//========================================================================================
|
||||
{
|
||||
public:
|
||||
FileImpl(PRFileDesc* inDesc)
|
||||
: mFileDesc(inDesc)
|
||||
, mFailed(PR_FALSE)
|
||||
, mEOF(PR_FALSE)
|
||||
, mLength(-1)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
FileImpl(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode,
|
||||
PRIntn accessMode)
|
||||
: mFileDesc(nsnull)
|
||||
, mFailed(PR_FALSE)
|
||||
, mEOF(PR_FALSE)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
Open(inFile, nsprMode, accessMode);
|
||||
}
|
||||
virtual ~FileImpl()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFile interface
|
||||
NS_IMETHOD Open(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode,
|
||||
PRIntn accessMode);
|
||||
NS_IMETHOD Close();
|
||||
NS_IMETHOD Seek(PRSeekWhence whence, PRInt32 offset);
|
||||
|
||||
NS_IMETHOD GetIsOpen(PRBool* outOpen)
|
||||
{
|
||||
*outOpen = (mFileDesc != nsnull);
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD Tell(PRIntn* outWhere);
|
||||
|
||||
// nsIInputStream interface
|
||||
NS_IMETHOD GetLength(PRUint32 *aLength)
|
||||
{
|
||||
NS_PRECONDITION(aLength != nsnull, "null ptr");
|
||||
if (!aLength)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (mLength < 0)
|
||||
return NS_FILE_RESULT(NS_ERROR_UNEXPECTED);
|
||||
*aLength = mLength;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD Read(char* aBuf,
|
||||
PRUint32 aCount,
|
||||
PRUint32 *aReadCount)
|
||||
{
|
||||
NS_PRECONDITION(aBuf != nsnull, "null ptr");
|
||||
if (!aBuf)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_PRECONDITION(aReadCount != nsnull, "null ptr");
|
||||
if (!aReadCount)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!mFileDesc)
|
||||
return NS_FILE_RESULT(PR_BAD_DESCRIPTOR_ERROR);
|
||||
if (mFailed)
|
||||
return NS_ERROR_FAILURE;
|
||||
PRInt32 bytesRead = PR_Read(mFileDesc, aBuf, aCount);
|
||||
if (bytesRead < 0)
|
||||
{
|
||||
*aReadCount = 0;
|
||||
mFailed = PR_TRUE;
|
||||
return NS_FILE_RESULT(PR_GetError());
|
||||
}
|
||||
else if (bytesRead == 0) {
|
||||
mEOF = PR_TRUE;
|
||||
return NS_BASE_STREAM_EOF;
|
||||
}
|
||||
*aReadCount = bytesRead;
|
||||
return NS_OK;
|
||||
}
|
||||
// nsIOutputStream interface
|
||||
NS_IMETHOD Write(const char* aBuf,
|
||||
PRUint32 aCount,
|
||||
PRUint32 *aWriteCount)
|
||||
{
|
||||
NS_PRECONDITION(aBuf != nsnull, "null ptr");
|
||||
NS_PRECONDITION(aWriteCount != nsnull, "null ptr");
|
||||
|
||||
|
||||
#ifdef XP_MAC
|
||||
// Calling PR_Write on stdout is sure suicide.
|
||||
if (mFileDesc == PR_STDOUT || mFileDesc == PR_STDERR)
|
||||
{
|
||||
cout.write(aBuf, aCount);
|
||||
*aWriteCount = aCount;
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
if (!mFileDesc)
|
||||
return NS_FILE_RESULT(PR_BAD_DESCRIPTOR_ERROR);
|
||||
if (mFailed)
|
||||
return NS_ERROR_FAILURE;
|
||||
PRInt32 bytesWrit = PR_Write(mFileDesc, aBuf, aCount);
|
||||
if (bytesWrit != (PRInt32)aCount)
|
||||
{
|
||||
mFailed = PR_TRUE;
|
||||
*aWriteCount = 0;
|
||||
return NS_FILE_RESULT(PR_GetError());
|
||||
}
|
||||
*aWriteCount = bytesWrit;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
NS_IMETHOD Flush();
|
||||
|
||||
NS_IMETHOD GetAtEOF(PRBool* outAtEOF)
|
||||
{
|
||||
*outAtEOF = mEOF;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD SetAtEOF(PRBool inAtEOF)
|
||||
{
|
||||
mEOF = inAtEOF;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
PRFileDesc* mFileDesc;
|
||||
int mNSPRMode;
|
||||
PRBool mFailed;
|
||||
PRBool mEOF;
|
||||
PRInt32 mLength;
|
||||
}; // class FileImpl
|
||||
|
||||
#define SAY_I_IMPLEMENT(classname) \
|
||||
if (aIID.Equals(classname::GetIID())) \
|
||||
{ \
|
||||
*aInstancePtr = (void*)((classname*)this); \
|
||||
NS_ADDREF_THIS(); \
|
||||
return NS_OK; \
|
||||
}
|
||||
|
||||
NS_IMPL_RELEASE(FileImpl)
|
||||
NS_IMPL_ADDREF(FileImpl)
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_IMETHODIMP FileImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!aInstancePtr)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aInstancePtr = nsnull;
|
||||
|
||||
SAY_I_IMPLEMENT(nsIFile)
|
||||
SAY_I_IMPLEMENT(nsIRandomAccessStore)
|
||||
SAY_I_IMPLEMENT(nsIOutputStream)
|
||||
SAY_I_IMPLEMENT(nsIInputStream)
|
||||
SAY_I_IMPLEMENT(nsIFileInputStream)
|
||||
SAY_I_IMPLEMENT(nsIFileOutputStream)
|
||||
// Note that we derive from two copies of nsIBaseStream (and hence
|
||||
// of nsISupports), one through
|
||||
// nsIOutputStream, the other through nsIInputStream. Resolve this
|
||||
// by giving them a specific one
|
||||
if (aIID.Equals(((nsIBaseStream*)(nsIOutputStream*)this)->GetIID()))
|
||||
{
|
||||
*aInstancePtr = (void*)((nsIBaseStream*)(nsIOutputStream*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(((nsISupports*)(nsIOutputStream*)this)->GetIID()))
|
||||
{
|
||||
*aInstancePtr = (void*)((nsISupports*)(nsIOutputStream*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
} // FileImpl::QueryInterface
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_IMETHODIMP FileImpl::Open(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode,
|
||||
PRIntn accessMode)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (mFileDesc)
|
||||
if ((nsprMode & mNSPRMode) == nsprMode)
|
||||
return NS_OK;
|
||||
else
|
||||
return NS_FILE_RESULT(PR_ILLEGAL_ACCESS_ERROR);
|
||||
|
||||
const int nspr_modes[]={
|
||||
PR_WRONLY | PR_CREATE_FILE,
|
||||
PR_WRONLY | PR_CREATE_FILE | PR_APPEND,
|
||||
PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE,
|
||||
PR_RDONLY,
|
||||
PR_RDONLY | PR_APPEND,
|
||||
PR_RDWR | PR_CREATE_FILE,
|
||||
PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE,
|
||||
// "wb",
|
||||
// "ab",
|
||||
// "wb",
|
||||
// "rb",
|
||||
// "r+b",
|
||||
// "w+b",
|
||||
0 };
|
||||
const int* currentLegalMode = nspr_modes;
|
||||
while (*currentLegalMode && nsprMode != *currentLegalMode)
|
||||
++currentLegalMode;
|
||||
if (!*currentLegalMode)
|
||||
return NS_FILE_RESULT(PR_ILLEGAL_ACCESS_ERROR);
|
||||
|
||||
#ifdef XP_MAC
|
||||
// Use the file spec to open the file, because one path can be common to
|
||||
// several files on the Macintosh (you can have several volumes with the
|
||||
// same name, see).
|
||||
mFileDesc = 0;
|
||||
if (inFile.Error() != noErr)
|
||||
return NS_FILE_RESULT(inFile.Error());
|
||||
OSErr err = noErr;
|
||||
#if DEBUG
|
||||
const OSType kCreator = 'CWIE';
|
||||
#else
|
||||
const OSType kCreator = 'MOSS';
|
||||
#endif
|
||||
// Resolve the alias to the original file.
|
||||
nsFileSpec original = inFile;
|
||||
PRBool ignoredResult;
|
||||
original.ResolveAlias(ignoredResult);
|
||||
const FSSpec& spec = original.operator const FSSpec&();
|
||||
if (nsprMode & PR_CREATE_FILE)
|
||||
err = FSpCreate(&spec, kCreator, 'TEXT', 0);
|
||||
if (err == dupFNErr)
|
||||
err = noErr;
|
||||
if (err != noErr)
|
||||
return NS_FILE_RESULT(err);
|
||||
|
||||
SInt8 perm;
|
||||
if (nsprMode & PR_RDWR)
|
||||
perm = fsRdWrPerm;
|
||||
else if (nsprMode & PR_WRONLY)
|
||||
perm = fsWrPerm;
|
||||
else
|
||||
perm = fsRdPerm;
|
||||
|
||||
short refnum;
|
||||
err = FSpOpenDF(&spec, perm, &refnum);
|
||||
|
||||
if (err == noErr && (nsprMode & PR_TRUNCATE))
|
||||
err = SetEOF(refnum, 0);
|
||||
if (err == noErr && (nsprMode & PR_APPEND))
|
||||
err = SetFPos(refnum, fsFromLEOF, 0);
|
||||
if (err != noErr)
|
||||
return NS_FILE_RESULT(err);
|
||||
|
||||
if ((mFileDesc = PR_ImportFile(refnum)) == 0)
|
||||
return NS_FILE_RESULT(PR_GetError());
|
||||
#else
|
||||
// Platforms other than Macintosh...
|
||||
// Another bug in NSPR: Mac PR_Open assumes a unix style path, but Win PR_Open assumes
|
||||
// a windows path.
|
||||
if ((mFileDesc = PR_Open((const char*)nsFileSpec(inFile), nsprMode, accessMode)) == 0)
|
||||
return NS_FILE_RESULT(PR_GetError());
|
||||
#endif
|
||||
mNSPRMode = nsprMode;
|
||||
mLength = PR_Available(mFileDesc);
|
||||
return NS_OK;
|
||||
} // FileImpl::Open
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_IMETHODIMP FileImpl::Seek(PRSeekWhence whence, PRInt32 offset)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (mFileDesc==PR_STDIN || mFileDesc==PR_STDOUT || mFileDesc==PR_STDERR || !mFileDesc)
|
||||
return NS_FILE_RESULT(PR_BAD_DESCRIPTOR_ERROR);
|
||||
mFailed = PR_FALSE; // reset on a seek.
|
||||
mEOF = PR_FALSE; // reset on a seek.
|
||||
PRInt32 position = PR_Seek(mFileDesc, 0, PR_SEEK_CUR);
|
||||
PRInt32 available = PR_Available(mFileDesc);
|
||||
PRInt32 fileSize = position + available;
|
||||
PRInt32 newPosition = 0;
|
||||
switch (whence)
|
||||
{
|
||||
case PR_SEEK_CUR: newPosition = position + offset; break;
|
||||
case PR_SEEK_SET: newPosition = offset; break;
|
||||
case PR_SEEK_END: newPosition = fileSize + offset; break;
|
||||
}
|
||||
if (newPosition < 0)
|
||||
{
|
||||
newPosition = 0;
|
||||
mFailed = PR_TRUE;
|
||||
}
|
||||
if (newPosition >= fileSize) // nb: not "else if".
|
||||
{
|
||||
newPosition = fileSize;
|
||||
mEOF = PR_TRUE;
|
||||
}
|
||||
if (PR_Seek(mFileDesc, newPosition, PR_SEEK_SET) < 0)
|
||||
mFailed = PR_TRUE;
|
||||
return NS_OK;
|
||||
} // FileImpl::Seek
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_IMETHODIMP FileImpl::Tell(PRIntn* outWhere)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (mFileDesc==PR_STDIN || mFileDesc==PR_STDOUT || mFileDesc==PR_STDERR || !mFileDesc)
|
||||
return NS_FILE_RESULT(PR_BAD_DESCRIPTOR_ERROR);
|
||||
*outWhere = PR_Seek(mFileDesc, 0, PR_SEEK_CUR);
|
||||
return NS_OK;
|
||||
} // FileImpl::Tell
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_IMETHODIMP FileImpl::Close()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (mFileDesc==PR_STDIN || mFileDesc==PR_STDOUT || mFileDesc==PR_STDERR || !mFileDesc)
|
||||
return NS_OK;
|
||||
if (PR_Close(mFileDesc) == PR_SUCCESS)
|
||||
mFileDesc = 0;
|
||||
else
|
||||
return NS_FILE_RESULT(PR_GetError());
|
||||
return NS_OK;
|
||||
} // FileImpl::close
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_IMETHODIMP FileImpl::Flush()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
#ifdef XP_MAC
|
||||
if (mFileDesc == PR_STDOUT || mFileDesc == PR_STDERR)
|
||||
{
|
||||
cout.flush();
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
if (!mFileDesc)
|
||||
return NS_FILE_RESULT(PR_BAD_DESCRIPTOR_ERROR);
|
||||
PRBool itFailed = PR_Sync(mFileDesc) != PR_SUCCESS;
|
||||
#ifdef XP_MAC
|
||||
// On unix, it seems to fail always.
|
||||
if (itFailed)
|
||||
mFailed = PR_TRUE;
|
||||
#endif
|
||||
return NS_OK;
|
||||
} // FileImpl::flush
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_BASE nsresult NS_NewTypicalInputFileStream(
|
||||
nsISupports** aResult,
|
||||
const nsFileSpec& inFile
|
||||
/*Default nsprMode == PR_RDONLY*/
|
||||
/*Default accessmode = 0700 (octal)*/)
|
||||
// Factory method to get an nsInputStream from a file, using most common options
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return NS_NewIOFileStream(aResult, inFile, PR_RDONLY, 0700);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_BASE nsresult NS_NewOutputConsoleStream(
|
||||
nsISupports** aResult)
|
||||
// Factory method to get an nsOutputStream to the console.
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
NS_PRECONDITION(aResult != nsnull, "null ptr");
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
FileImpl* stream = new FileImpl(PR_STDOUT);
|
||||
if (! stream)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(stream);
|
||||
*aResult = (nsISupports*)(void*)stream;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_BASE nsresult NS_NewTypicalOutputFileStream(
|
||||
nsISupports** aResult,
|
||||
const nsFileSpec& inFile
|
||||
/*default nsprMode= (PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE)*/
|
||||
/*Default accessMode= 0700 (octal)*/)
|
||||
// Factory method to get an nsOutputStream to a file - most common case.
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return NS_NewIOFileStream(
|
||||
aResult,
|
||||
inFile,
|
||||
(PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE),
|
||||
0700);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_BASE nsresult NS_NewIOFileStream(
|
||||
nsISupports** aResult,
|
||||
const nsFileSpec& inFile,
|
||||
PRInt32 nsprMode /*default = (PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE)*/,
|
||||
PRInt32 accessMode /*Default = 0700 (octal)*/)
|
||||
// Factory method to get an object that implements both nsIInputStream
|
||||
// and nsIOutputStream, associated with a file.
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
NS_PRECONDITION(aResult != nsnull, "null ptr");
|
||||
if (!aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
FileImpl* stream = new FileImpl(inFile, nsprMode, accessMode);
|
||||
if (! stream)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(stream);
|
||||
*aResult = (nsISupports*)(void*)stream;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_BASE nsresult NS_NewTypicalIOFileStream(
|
||||
nsISupports** aResult,
|
||||
const nsFileSpec& inFile
|
||||
/*default nsprMode= (PR_RDWR | PR_CREATE_FILE)*/
|
||||
/*Default accessMode= 0700 (octal)*/)
|
||||
// Factory method to get an object that implements both nsIInputStream
|
||||
// and nsIOutputStream, associated with a single file.
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return NS_NewIOFileStream(
|
||||
aResult,
|
||||
inFile,
|
||||
(PR_RDWR | PR_CREATE_FILE),
|
||||
0700);
|
||||
}
|
||||
@@ -28,8 +28,6 @@
|
||||
class nsIInputStream : public nsIBaseStream {
|
||||
public:
|
||||
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IINPUTSTREAM_IID; return iid; }
|
||||
|
||||
/** Return the number of bytes in the stream
|
||||
* @param aLength out parameter to hold the length
|
||||
* of the stream. if an error occurs, the length
|
||||
@@ -40,7 +38,9 @@ public:
|
||||
GetLength(PRUint32 *aLength) = 0;
|
||||
|
||||
/** Read data from the stream.
|
||||
* @param aErrorCode the error code if an error occurs
|
||||
* @param aBuf the buffer into which the data is read
|
||||
* @param aOffset the start offset of the data
|
||||
* @param aCount the maximum number of bytes to read
|
||||
* @param aReadCount out parameter to hold the number of
|
||||
* bytes read, eof if 0. if an error occurs, the
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
* @return error status
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount) = 0;
|
||||
Read(char* aBuf, PRUint32 aOffset, PRUint32 aCount, PRUint32 *aReadCount) = 0;
|
||||
};
|
||||
|
||||
#endif /* nsInputStream_h___ */
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
@@ -15,14 +15,11 @@
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIOutputStream_h___
|
||||
#define nsIOutputStream_h___
|
||||
|
||||
#include "nsIBaseStream.h"
|
||||
|
||||
class nsIInputStream;
|
||||
|
||||
/* 7f13b870-e95f-11d1-beae-00805f8a66dc */
|
||||
#define NS_IOUTPUTSTREAM_IID \
|
||||
{ 0x7f13b870, 0xe95f, 0x11d1, \
|
||||
@@ -32,41 +29,17 @@ class nsIInputStream;
|
||||
class nsIOutputStream : public nsIBaseStream {
|
||||
public:
|
||||
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IOUTPUTSTREAM_IID; return iid; }
|
||||
|
||||
/** Write data into the stream.
|
||||
* @param aBuf the buffer from which the data is read
|
||||
* @param aCount the maximum number of bytes to write
|
||||
* @param aBuf the buffer into which the data is read
|
||||
* @param aOffset the start offset of the data
|
||||
* @param aCount the maximum number of bytes to read
|
||||
* @param aWriteCount out parameter to hold the number of
|
||||
* bytes written. if an error occurs, the writecount
|
||||
* is undefined
|
||||
* @return error status
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount) = 0;
|
||||
|
||||
/**
|
||||
* Writes data into the stream from an input stream.
|
||||
* Implementer's note: This method is defined by this interface in order
|
||||
* to allow the output stream to efficiently copy the data from the input
|
||||
* stream into its internal buffer (if any). If this method was provide
|
||||
* as an external facility, a separate char* buffer would need to be used
|
||||
* in order to call the output stream's other Write method.
|
||||
* @param fromStream the stream from which the data is read
|
||||
* @param aWriteCount out parameter to hold the number of
|
||||
* bytes written. if an error occurs, the writecount
|
||||
* is undefined
|
||||
* @return error status
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) = 0;
|
||||
|
||||
/**
|
||||
* Flushes the stream.
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Flush(void) = 0;
|
||||
|
||||
Write(const char* aBuf, PRUint32 aOffset, PRUint32 aCount, PRUint32 *aWriteCount) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,485 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsIStringStream.h"
|
||||
#include "nsIFileStream.h"
|
||||
|
||||
#include "prerror.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "plstr.h"
|
||||
|
||||
//========================================================================================
|
||||
class BasicStringImpl
|
||||
: public nsIOutputStream
|
||||
, public nsIInputStream
|
||||
, public nsIRandomAccessStore
|
||||
//========================================================================================
|
||||
{
|
||||
public:
|
||||
BasicStringImpl()
|
||||
: mOffset(0)
|
||||
, mLastResult(NS_OK)
|
||||
, mEOF(PR_FALSE)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
virtual ~BasicStringImpl()
|
||||
{
|
||||
}
|
||||
NS_IMETHOD Seek(PRSeekWhence whence, PRInt32 offset);
|
||||
|
||||
NS_IMETHOD Tell(PRIntn* outWhere)
|
||||
{
|
||||
*outWhere = mOffset;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetAtEOF(PRBool* outAtEOF)
|
||||
{
|
||||
*outAtEOF = mEOF;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD SetAtEOF(PRBool inAtEOF)
|
||||
{
|
||||
mEOF = inAtEOF;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetLength(PRUint32 *aLength)
|
||||
{
|
||||
NS_PRECONDITION(aLength != nsnull, "null ptr");
|
||||
if (!aLength)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
*aLength = length();
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD Read(char* aBuf,
|
||||
PRUint32 aCount,
|
||||
PRUint32 *aReadCount)
|
||||
{
|
||||
NS_PRECONDITION(aBuf != nsnull, "null ptr");
|
||||
if (!aBuf)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_PRECONDITION(aReadCount != nsnull, "null ptr");
|
||||
if (!aReadCount)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (NS_FAILED(mLastResult))
|
||||
return mLastResult;
|
||||
PRInt32 bytesRead = read(aBuf, aCount);
|
||||
if (NS_FAILED(mLastResult))
|
||||
{
|
||||
*aReadCount = 0;
|
||||
return mLastResult;
|
||||
}
|
||||
*aReadCount = bytesRead;
|
||||
if (bytesRead < (PRInt32)aCount)
|
||||
SetAtEOF(PR_TRUE);
|
||||
return NS_OK;
|
||||
}
|
||||
// nsIOutputStream interface
|
||||
NS_IMETHOD Write(const char* aBuf,
|
||||
PRUint32 aCount,
|
||||
PRUint32 *aWriteCount)
|
||||
{
|
||||
NS_PRECONDITION(aBuf != nsnull, "null ptr");
|
||||
NS_PRECONDITION(aWriteCount != nsnull, "null ptr");
|
||||
|
||||
if (NS_FAILED(mLastResult))
|
||||
return mLastResult;
|
||||
PRInt32 bytesWrit = write(aBuf, aCount);
|
||||
if (NS_FAILED(mLastResult))
|
||||
{
|
||||
*aWriteCount = 0;
|
||||
return mLastResult;
|
||||
}
|
||||
*aWriteCount = bytesWrit;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
public:
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Close() { return NS_OK; }
|
||||
|
||||
// nsIInputStream interface
|
||||
NS_IMETHOD Flush() { return NS_OK; }
|
||||
|
||||
|
||||
public:
|
||||
nsresult get_result() const { return mLastResult; }
|
||||
|
||||
protected:
|
||||
|
||||
virtual PRInt32 length() const = 0;
|
||||
virtual PRInt32 read(char* buf, PRUint32 count) = 0;
|
||||
virtual PRInt32 write(const char*, PRUint32)
|
||||
{
|
||||
NS_ASSERTION(PR_FALSE, "Write to a const string");
|
||||
mLastResult = NS_FILE_RESULT(PR_ILLEGAL_ACCESS_ERROR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
PRUint32 mOffset;
|
||||
nsresult mLastResult;
|
||||
PRBool mEOF;
|
||||
}; // class BasicStringImpl
|
||||
|
||||
//========================================================================================
|
||||
class ConstCharImpl
|
||||
: public BasicStringImpl
|
||||
//========================================================================================
|
||||
{
|
||||
public:
|
||||
ConstCharImpl(const char* inString)
|
||||
: mConstString(inString)
|
||||
, mLength(inString ? strlen(inString) : 0)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual PRInt32 length() const
|
||||
{
|
||||
return mLength;
|
||||
}
|
||||
|
||||
virtual PRInt32 read(char* buf, PRUint32 aCount)
|
||||
{
|
||||
PRInt32 maxCount = mLength - mOffset;
|
||||
if ((PRInt32)aCount > maxCount)
|
||||
aCount = maxCount;
|
||||
memcpy(buf, mConstString + mOffset, aCount);
|
||||
mOffset += aCount;
|
||||
return aCount;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
const char* mConstString;
|
||||
size_t mLength;
|
||||
|
||||
}; // class ConstCharImpl
|
||||
|
||||
//========================================================================================
|
||||
class CharImpl
|
||||
: public ConstCharImpl
|
||||
//========================================================================================
|
||||
{
|
||||
enum { kAllocQuantum = 256 };
|
||||
|
||||
public:
|
||||
CharImpl(char** inString)
|
||||
: ConstCharImpl(*inString)
|
||||
, mString(*inString)
|
||||
, mAllocLength(mLength + 1)
|
||||
, mOriginalLength(mLength)
|
||||
{
|
||||
if (!mString)
|
||||
{
|
||||
mAllocLength += kAllocQuantum;
|
||||
mString = new char[mAllocLength];
|
||||
if (!mString)
|
||||
{
|
||||
mLastResult = NS_ERROR_OUT_OF_MEMORY;
|
||||
return;
|
||||
}
|
||||
mConstString = mString;
|
||||
*mString = '\0';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
virtual PRInt32 write(const char* buf, PRUint32 aCount)
|
||||
{
|
||||
PRInt32 maxCount = mAllocLength - 1 - mOffset;
|
||||
if ((PRInt32)aCount > maxCount)
|
||||
{
|
||||
|
||||
do {
|
||||
maxCount += kAllocQuantum;
|
||||
} while ((PRInt32)aCount > maxCount);
|
||||
mAllocLength = maxCount + 1 + mOffset;
|
||||
char* newString = new char[mAllocLength];
|
||||
if (!newString)
|
||||
{
|
||||
mLastResult = NS_ERROR_OUT_OF_MEMORY;
|
||||
return 0;
|
||||
}
|
||||
strcpy(newString, mString);
|
||||
delete [] mString;
|
||||
mString = newString;
|
||||
mConstString = newString;
|
||||
}
|
||||
memcpy(mString + mOffset, buf, aCount);
|
||||
mOffset += aCount;
|
||||
if (mOffset > mOriginalLength)
|
||||
mString[mOffset] = 0;
|
||||
return aCount;
|
||||
}
|
||||
protected:
|
||||
|
||||
char*& mString;
|
||||
size_t mAllocLength;
|
||||
size_t mOriginalLength;
|
||||
|
||||
}; // class CharImpl
|
||||
|
||||
//========================================================================================
|
||||
class ConstStringImpl
|
||||
: public ConstCharImpl
|
||||
//========================================================================================
|
||||
{
|
||||
public:
|
||||
ConstStringImpl(const nsString& inString)
|
||||
: ConstCharImpl(inString.ToNewCString())
|
||||
{
|
||||
}
|
||||
|
||||
~ConstStringImpl()
|
||||
{
|
||||
delete [] (char*)mConstString;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
protected:
|
||||
|
||||
}; // class ConstStringImpl
|
||||
|
||||
|
||||
//========================================================================================
|
||||
class StringImpl
|
||||
: public ConstStringImpl
|
||||
//========================================================================================
|
||||
{
|
||||
public:
|
||||
StringImpl(nsString& inString)
|
||||
: ConstStringImpl(inString)
|
||||
, mString(inString)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual PRInt32 write(const char* buf, PRUint32 count)
|
||||
{
|
||||
// Clone our string as chars
|
||||
char* cstring = mString.ToNewCString();
|
||||
// Make a CharImpl and do the write
|
||||
CharImpl chars(&cstring);
|
||||
chars.Seek(PR_SEEK_SET, mOffset);
|
||||
// Get the bytecount and result from the CharImpl
|
||||
PRInt32 result = chars.write(buf,count);
|
||||
mLastResult = chars.get_result();
|
||||
// Set our string to match the new chars
|
||||
mString = cstring;
|
||||
// Set our const string also...
|
||||
delete [] (char*)mConstString;
|
||||
mConstString = cstring;
|
||||
return result;
|
||||
}
|
||||
protected:
|
||||
|
||||
nsString& mString;
|
||||
|
||||
}; // class StringImpl
|
||||
|
||||
#define SAY_I_IMPLEMENT(classname) \
|
||||
if (aIID.Equals(classname::GetIID())) \
|
||||
{ \
|
||||
*aInstancePtr = (void*)((classname*)this); \
|
||||
NS_ADDREF_THIS(); \
|
||||
return NS_OK; \
|
||||
}
|
||||
|
||||
NS_IMPL_RELEASE(BasicStringImpl)
|
||||
NS_IMPL_ADDREF(BasicStringImpl)
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_IMETHODIMP BasicStringImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!aInstancePtr)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aInstancePtr = nsnull;
|
||||
|
||||
SAY_I_IMPLEMENT(nsIRandomAccessStore)
|
||||
SAY_I_IMPLEMENT(nsIOutputStream)
|
||||
SAY_I_IMPLEMENT(nsIInputStream)
|
||||
// Note that we derive from two copies of nsIBaseStream (and hence
|
||||
// of nsISupports), one through
|
||||
// nsIOutputStream, the other through nsIInputStream. Resolve this
|
||||
// by giving them a specific one
|
||||
if (aIID.Equals(((nsIBaseStream*)(nsIOutputStream*)this)->GetIID()))
|
||||
{
|
||||
*aInstancePtr = (void*)((nsIBaseStream*)(nsIOutputStream*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(((nsISupports*)(nsIOutputStream*)this)->GetIID()))
|
||||
{
|
||||
*aInstancePtr = (void*)((nsISupports*)(nsIOutputStream*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
} // StringImpl::QueryInterface
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_IMETHODIMP BasicStringImpl::Seek(PRSeekWhence whence, PRInt32 offset)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
mLastResult = NS_OK; // reset on a seek.
|
||||
mEOF = PR_FALSE; // reset on a seek.
|
||||
PRInt32 fileSize = length();
|
||||
PRInt32 newPosition=-1;
|
||||
switch (whence)
|
||||
{
|
||||
case PR_SEEK_CUR: newPosition = mOffset + offset; break;
|
||||
case PR_SEEK_SET: newPosition = offset; break;
|
||||
case PR_SEEK_END: newPosition = fileSize + offset; break;
|
||||
}
|
||||
if (newPosition < 0)
|
||||
{
|
||||
newPosition = 0;
|
||||
mLastResult = NS_FILE_RESULT(PR_FILE_SEEK_ERROR);
|
||||
}
|
||||
if (newPosition >= fileSize)
|
||||
{
|
||||
newPosition = fileSize;
|
||||
mEOF = PR_TRUE;
|
||||
}
|
||||
mOffset = newPosition;
|
||||
return NS_OK;
|
||||
} // StringImpl::Seek
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
extern "C" NS_BASE nsresult NS_NewStringInputStream(
|
||||
nsISupports** aStreamResult,
|
||||
const nsString& aStringToRead)
|
||||
// Factory method to get an nsInputStream from a string. Result will implement all the
|
||||
// file stream interfaces in nsIFileStream.h
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
NS_PRECONDITION(aStreamResult != nsnull, "null ptr");
|
||||
if (! aStreamResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
ConstStringImpl* stream = new ConstStringImpl(aStringToRead);
|
||||
if (! stream)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(stream);
|
||||
*aStreamResult = (nsISupports*)(void*)stream;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
extern "C" NS_BASE nsresult NS_NewStringOutputStream(
|
||||
nsISupports** aStreamResult,
|
||||
nsString& aStringToChange)
|
||||
// Factory method to get an nsOutputStream from a string. Result will implement all the
|
||||
// file stream interfaces in nsIFileStream.h
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
NS_PRECONDITION(aStreamResult != nsnull, "null ptr");
|
||||
if (! aStreamResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
StringImpl* stream = new StringImpl(aStringToChange);
|
||||
if (! stream)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(stream);
|
||||
*aStreamResult = (nsISupports*)(void*)stream;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
extern "C" NS_BASE nsresult NS_NewCharInputStream(
|
||||
nsISupports** aStreamResult,
|
||||
const char* aStringToRead)
|
||||
// Factory method to get an nsInputStream from a string. Result will implement all the
|
||||
// file stream interfaces in nsIFileStream.h
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
NS_PRECONDITION(aStreamResult != nsnull, "null ptr");
|
||||
if (! aStreamResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
ConstCharImpl* stream = new ConstCharImpl(aStringToRead);
|
||||
if (! stream)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(stream);
|
||||
*aStreamResult = (nsISupports*)(void*)stream;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
extern "C" NS_BASE nsresult NS_NewCharOutputStream(
|
||||
nsISupports** aStreamResult,
|
||||
char** aStringToChange)
|
||||
// Factory method to get an nsOutputStream to a string. Result will implement all the
|
||||
// file stream interfaces in nsIFileStream.h
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
NS_PRECONDITION(aStreamResult != nsnull, "null ptr");
|
||||
NS_PRECONDITION(aStringToChange != nsnull, "null ptr");
|
||||
if (!aStreamResult || !aStringToChange)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
CharImpl* stream = new CharImpl(aStringToChange);
|
||||
if (! stream)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(stream);
|
||||
*aStreamResult = (nsISupports*)(void*)stream;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
extern "C" NS_BASE nsresult NS_NewStringIOStream(
|
||||
nsISupports** aStreamResult,
|
||||
nsString& aStringToChange)
|
||||
// Factory method to get an nsOutputStream to a string. Result will implement all the
|
||||
// file stream interfaces in nsIFileStream.h
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return NS_NewStringOutputStream(aStreamResult, aStringToChange);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
extern "C" NS_BASE nsresult NS_NewCharIOStream(
|
||||
nsISupports** aStreamResult,
|
||||
char** aStringToChange)
|
||||
// Factory method to get an nsOutputStream to a string. Result will implement all the
|
||||
// file stream interfaces in nsIFileStream.h
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return NS_NewCharOutputStream(aStreamResult, aStringToChange);
|
||||
}
|
||||
@@ -45,8 +45,6 @@ typedef void
|
||||
*/
|
||||
class nsITimer : public nsISupports {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITIMER_IID)
|
||||
|
||||
/**
|
||||
* Initialize a timer to fire after the given millisecond interval.
|
||||
* This version takes a function to call and a closure to pass to
|
||||
|
||||
@@ -35,9 +35,7 @@ class nsITimer;
|
||||
*/
|
||||
class nsITimerCallback : public nsISupports {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITIMERCALLBACK_IID)
|
||||
|
||||
virtual void Notify(nsITimer *timer) = 0;
|
||||
virtual void Notify(nsITimer *timer)=0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,11 @@ class nsString;
|
||||
{ 0x2d97fbf0, 0x93b5, 0x11d1, \
|
||||
{0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
|
||||
|
||||
#define NS_IB2UCONVERTER_IID \
|
||||
{ 0x35e40290, 0x93b5, 0x11d1, \
|
||||
{0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
|
||||
|
||||
|
||||
/** Abstract unicode character input stream
|
||||
* @see nsIInputStream
|
||||
*/
|
||||
@@ -47,6 +52,21 @@ extern NS_BASE nsresult
|
||||
NS_NewStringUnicharInputStream(nsIUnicharInputStream** aInstancePtrResult,
|
||||
nsString* aString);
|
||||
|
||||
/// Abstract interface for converting from bytes to unicode characters
|
||||
class nsIB2UConverter : public nsISupports {
|
||||
public:
|
||||
/** aDstLen is updated to indicate how much data was translated into
|
||||
* aDst; aSrcLen is updated to indicate how much data was used in
|
||||
* the source buffer.
|
||||
*/
|
||||
NS_IMETHOD Convert(PRUnichar* aDst,
|
||||
PRUint32 aDstOffset,
|
||||
PRUint32& aDstLen,
|
||||
const char* aSrc,
|
||||
PRUint32 aSrcOffset,
|
||||
PRUint32& aSrcLen) = 0;
|
||||
};
|
||||
|
||||
/** Create a new nsUnicharInputStream that provides a converter for the
|
||||
* byte input stream aStreamToWrap. If no converter can be found then
|
||||
* nsnull is returned and the error code is set to
|
||||
@@ -59,4 +79,13 @@ extern NS_BASE nsresult
|
||||
PRInt32 aBufferSize = 0,
|
||||
nsString* aCharSet = nsnull);
|
||||
|
||||
/** Create a new nsB2UConverter for the given character set. When given
|
||||
* nsnull, the converter for iso-latin1 to unicode is provided. If no
|
||||
* converter can be found, nsnull is returned.
|
||||
*/
|
||||
extern NS_BASE nsresult
|
||||
NS_NewB2UConverter(nsIB2UConverter** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
nsString* aCharSet = nsnull);
|
||||
|
||||
#endif /* nsUnicharInputStream_h___ */
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#define NS_IMPL_IDS
|
||||
#include "pratom.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsRepository.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsObserver.h"
|
||||
#include "nsString.h"
|
||||
|
||||
static NS_DEFINE_IID(kIObserverIID, NS_IOBSERVER_IID);
|
||||
static NS_DEFINE_IID(kObserverCID, NS_OBSERVER_CID);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsObserver Implementation
|
||||
|
||||
|
||||
NS_IMPL_AGGREGATED(nsObserver);
|
||||
|
||||
NS_BASE nsresult NS_NewObserver(nsIObserver** anObserver)
|
||||
{
|
||||
if (anObserver == NULL)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
nsObserver* it = new nsObserver();
|
||||
|
||||
if (it == 0) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return it->QueryInterface(kIObserverIID, (void **) anObserver);
|
||||
}
|
||||
|
||||
nsObserver::nsObserver()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsObserver::~nsObserver(void)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsObserver::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (aInstancePtr == nsnull)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (aIID.Equals(nsIObserver::GetIID()) ||
|
||||
aIID.Equals(nsISupports::GetIID())) {
|
||||
*aInstancePtr = this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
nsresult nsObserver::Notify(nsISupports** result)
|
||||
{
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -1,40 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsObserver_h___
|
||||
#define nsObserver_h___
|
||||
|
||||
#include "nsIObserver.h"
|
||||
#include "nsAgg.h"
|
||||
|
||||
class nsObserver : public nsIObserver {
|
||||
public:
|
||||
|
||||
NS_IMETHOD Notify(nsISupports** result);
|
||||
|
||||
nsObserver();
|
||||
virtual ~nsObserver(void);
|
||||
|
||||
NS_DECL_AGGREGATED
|
||||
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsObserver_h___ */
|
||||
@@ -1,133 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#define NS_IMPL_IDS
|
||||
#include "pratom.h"
|
||||
#include "nsIObserverList.h"
|
||||
#include "nsObserverList.h"
|
||||
#include "nsString.h"
|
||||
#include "nsAutoLock.h"
|
||||
|
||||
|
||||
#define NS_AUTOLOCK(__monitor) nsAutoLock __lock(__monitor)
|
||||
|
||||
static NS_DEFINE_IID(kIObserverListIID, NS_IOBSERVERLIST_IID);
|
||||
static NS_DEFINE_IID(kObserverListCID, NS_OBSERVERLIST_CID);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsObserverList Implementation
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsObserverList, kIObserverListIID);
|
||||
|
||||
NS_BASE nsresult NS_NewObserverList(nsIObserverList** anObserverList)
|
||||
{
|
||||
|
||||
if (anObserverList == NULL)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
nsObserverList* it = new nsObserverList();
|
||||
|
||||
if (it == 0) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return it->QueryInterface(kIObserverListIID, (void **) anObserverList);
|
||||
}
|
||||
|
||||
nsObserverList::nsObserverList()
|
||||
: mObserverList(NULL),
|
||||
mLock(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mLock = PR_NewLock();
|
||||
}
|
||||
|
||||
nsObserverList::~nsObserverList(void)
|
||||
{
|
||||
PR_DestroyLock(mLock);
|
||||
}
|
||||
|
||||
|
||||
nsresult nsObserverList::AddObserver(nsIObserver** anObserver)
|
||||
{
|
||||
nsresult rv;
|
||||
PRBool inserted;
|
||||
|
||||
NS_AUTOLOCK(mLock);
|
||||
|
||||
if (anObserver == NULL)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if(!mObserverList) {
|
||||
rv = NS_NewISupportsArray(&mObserverList);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
if(*anObserver) {
|
||||
inserted = mObserverList->AppendElement(*anObserver);
|
||||
return inserted ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult nsObserverList::RemoveObserver(nsIObserver** anObserver)
|
||||
{
|
||||
PRBool removed;
|
||||
|
||||
NS_AUTOLOCK(mLock);
|
||||
|
||||
if (anObserver == NULL)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if(!mObserverList) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if(*anObserver) {
|
||||
removed = mObserverList->RemoveElement(*anObserver);
|
||||
return removed ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsObserverList::EnumerateObserverList(nsIEnumerator** anEnumerator)
|
||||
{
|
||||
NS_AUTOLOCK(mLock);
|
||||
|
||||
if (anEnumerator == NULL)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if(!mObserverList) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return mObserverList->Enumerate(anEnumerator);
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsObserverList_h___
|
||||
#define nsObserverList_h___
|
||||
|
||||
#include "nsIObserverList.h"
|
||||
#include "nsIEnumerator.h"
|
||||
#include "nsISupportsArray.h"
|
||||
|
||||
|
||||
class nsObserverList : public nsIObserverList {
|
||||
public:
|
||||
|
||||
NS_IMETHOD AddObserver(nsIObserver** anObserver);
|
||||
NS_IMETHOD RemoveObserver(nsIObserver** anObserver);
|
||||
|
||||
NS_IMETHOD EnumerateObserverList(nsIEnumerator** anEnumerator);
|
||||
|
||||
nsObserverList();
|
||||
virtual ~nsObserverList(void);
|
||||
|
||||
// This is ObserverList monitor object.
|
||||
PRLock* mLock;
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
||||
private:
|
||||
|
||||
nsISupportsArray *mObserverList;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsObserverList_h___ */
|
||||
@@ -1,226 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#define NS_IMPL_IDS
|
||||
#include "prlock.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsRepository.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsObserverService.h"
|
||||
#include "nsIObserverList.h"
|
||||
#include "nsObserverList.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsString.h"
|
||||
|
||||
static NS_DEFINE_IID(kIObserverServiceIID, NS_IOBSERVERSERVICE_IID);
|
||||
static NS_DEFINE_IID(kObserverServiceCID, NS_OBSERVERSERVICE_CID);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsObserverService : public nsIObserverService {
|
||||
public:
|
||||
|
||||
static nsresult GetObserverService(nsIObserverService** anObserverService);
|
||||
|
||||
NS_IMETHOD AddObserver(nsIObserver** anObserver, nsString* aTopic);
|
||||
NS_IMETHOD RemoveObserver(nsIObserver** anObserver, nsString* aTopic);
|
||||
NS_IMETHOD EnumerateObserverList(nsIEnumerator** anEnumerator, nsString* aTopic);
|
||||
|
||||
|
||||
nsObserverService();
|
||||
virtual ~nsObserverService(void);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
||||
private:
|
||||
|
||||
NS_IMETHOD GetObserverList(nsIObserverList** anObserverList, nsString* aTopic);
|
||||
|
||||
nsHashtable *mObserverTopicTable;
|
||||
|
||||
};
|
||||
|
||||
static nsObserverService* gObserverService = nsnull; // The one-and-only ObserverService
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsObserverService Implementation
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsObserverService, kIObserverServiceIID);
|
||||
|
||||
NS_BASE nsresult NS_NewObserverService(nsIObserverService** anObserverService)
|
||||
{
|
||||
return nsObserverService::GetObserverService(anObserverService);
|
||||
}
|
||||
|
||||
nsObserverService::nsObserverService()
|
||||
: mObserverTopicTable(NULL)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mObserverTopicTable = nsnull;
|
||||
}
|
||||
|
||||
nsObserverService::~nsObserverService(void)
|
||||
{
|
||||
if(mObserverTopicTable)
|
||||
delete mObserverTopicTable;
|
||||
gObserverService = nsnull;
|
||||
}
|
||||
|
||||
|
||||
nsresult nsObserverService::GetObserverService(nsIObserverService** anObserverService)
|
||||
{
|
||||
if (! gObserverService) {
|
||||
nsObserverService* it = new nsObserverService();
|
||||
if (! it)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
gObserverService = it;
|
||||
}
|
||||
|
||||
NS_ADDREF(gObserverService);
|
||||
*anObserverService = gObserverService;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsObserverService::GetObserverList(nsIObserverList** anObserverList, nsString* aTopic)
|
||||
{
|
||||
if (anObserverList == NULL)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if(mObserverTopicTable == NULL) {
|
||||
mObserverTopicTable = new nsHashtable(256, PR_TRUE);
|
||||
if (mObserverTopicTable == NULL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
||||
// Safely convert to a C-string
|
||||
char buf[128];
|
||||
char* topic = buf;
|
||||
|
||||
if ((*aTopic).Length() >= sizeof(buf))
|
||||
topic = new char[(*aTopic).Length() + 1];
|
||||
|
||||
if (topic == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
(*aTopic).ToCString(topic, (*aTopic).Length() + 1);
|
||||
|
||||
nsCStringKey key(topic);
|
||||
|
||||
nsIObserverList *topicObservers = nsnull;
|
||||
if (mObserverTopicTable->Exists(&key)) {
|
||||
topicObservers = (nsIObserverList *) mObserverTopicTable->Get(&key);
|
||||
if (topicObservers != NULL) {
|
||||
*anObserverList = topicObservers;
|
||||
} else {
|
||||
NS_NewObserverList(&topicObservers);
|
||||
mObserverTopicTable->Put(&key, topicObservers);
|
||||
}
|
||||
} else {
|
||||
NS_NewObserverList(&topicObservers);
|
||||
*anObserverList = topicObservers;
|
||||
mObserverTopicTable->Put(&key, topicObservers);
|
||||
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsObserverService::AddObserver(nsIObserver** anObserver, nsString* aTopic)
|
||||
{
|
||||
nsIObserverList* anObserverList;
|
||||
nsresult rv;
|
||||
|
||||
if (anObserver == NULL)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (aTopic == NULL)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
rv = GetObserverList(&anObserverList, aTopic);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (anObserverList) {
|
||||
return anObserverList->AddObserver(anObserver);
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult nsObserverService::RemoveObserver(nsIObserver** anObserver, nsString* aTopic)
|
||||
{
|
||||
nsIObserverList* anObserverList;
|
||||
nsresult rv;
|
||||
|
||||
if (anObserver == NULL)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (aTopic == NULL)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
rv = GetObserverList(&anObserverList, aTopic);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (anObserverList) {
|
||||
return anObserverList->RemoveObserver(anObserver);
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult nsObserverService::EnumerateObserverList(nsIEnumerator** anEnumerator, nsString* aTopic)
|
||||
{
|
||||
nsIObserverList* anObserverList;
|
||||
nsresult rv;
|
||||
|
||||
if (anEnumerator == NULL)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (aTopic == NULL)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
rv = GetObserverList(&anObserverList, aTopic);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (anObserverList) {
|
||||
return anObserverList->EnumerateObserverList(anEnumerator);
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsObserverService_h___
|
||||
#define nsObserverService_h___
|
||||
|
||||
#endif /* nsObserverService_h___ */
|
||||
@@ -1,759 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsPageMgr.h"
|
||||
#include "prmem.h"
|
||||
|
||||
#if defined(XP_PC)
|
||||
#include <windows.h>
|
||||
#elif defined(XP_MAC)
|
||||
#include <stdlib.h>
|
||||
#elif defined(XP_UNIX)
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifndef MAP_FAILED
|
||||
#if defined (__STDC__) && __STDC__
|
||||
#define MAP_FAILED ((void *) -1)
|
||||
#else
|
||||
#define MAP_FAILED ((char *) -1)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#define NS_PAGEMGR_CLUSTERDESC_CLUMPSIZE 16
|
||||
|
||||
void
|
||||
nsPageMgr::DeleteFreeClusterDesc(nsClusterDesc *desc)
|
||||
{
|
||||
desc->mNext = mUnusedClusterDescs;
|
||||
mUnusedClusterDescs = desc;
|
||||
}
|
||||
|
||||
nsPageMgr::nsClusterDesc*
|
||||
nsPageMgr::NewFreeClusterDesc(void)
|
||||
{
|
||||
nsClusterDesc *desc = mUnusedClusterDescs;
|
||||
if (desc)
|
||||
mUnusedClusterDescs = desc->mNext;
|
||||
else {
|
||||
/* Allocate a clump of cluster records at once, and link all except
|
||||
the first onto the list of mUnusedClusterDescs */
|
||||
desc = (nsClusterDesc*)PR_Malloc(NS_PAGEMGR_CLUSTERDESC_CLUMPSIZE * sizeof(nsClusterDesc));
|
||||
if (desc) {
|
||||
nsClusterDesc* desc2 = desc + (NS_PAGEMGR_CLUSTERDESC_CLUMPSIZE - 1);
|
||||
while (desc2 != desc) {
|
||||
DeleteFreeClusterDesc(desc2--);
|
||||
}
|
||||
}
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
|
||||
/* Search the mFreeClusters looking for the first cluster of consecutive free
|
||||
pages that is at least size bytes long. If there is one, remove these pages
|
||||
from the free page list and return their address; if not, return nil. */
|
||||
nsPage*
|
||||
nsPageMgr::AllocClusterFromFreeList(PRUword nPages)
|
||||
{
|
||||
nsClusterDesc **p = &mFreeClusters;
|
||||
nsClusterDesc *desc;
|
||||
while ((desc = *p) != NULL) {
|
||||
if (desc->mPageCount >= nPages) {
|
||||
nsPage* addr = desc->mAddr;
|
||||
if (desc->mPageCount == nPages) {
|
||||
*p = desc->mNext;
|
||||
DeleteFreeClusterDesc(desc);
|
||||
}
|
||||
else {
|
||||
desc->mAddr += nPages;
|
||||
desc->mPageCount -= nPages;
|
||||
}
|
||||
return addr;
|
||||
}
|
||||
p = &desc->mNext;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Add the segment to the nsClusterDesc list, coalescing it with any
|
||||
clusters already in the list when possible. */
|
||||
void
|
||||
nsPageMgr::AddClusterToFreeList(nsPage* addr, PRWord nPages)
|
||||
{
|
||||
nsClusterDesc **p = &mFreeClusters;
|
||||
nsClusterDesc *desc;
|
||||
nsClusterDesc *newDesc;
|
||||
|
||||
while ((desc = *p) != NULL) {
|
||||
if (desc->mAddr + desc->mPageCount == addr) {
|
||||
/* Coalesce with the previous cluster. */
|
||||
nsClusterDesc *next = desc->mNext;
|
||||
|
||||
desc->mPageCount += nPages;
|
||||
if (next && next->mAddr == addr + nPages) {
|
||||
/* We can coalesce with both the previous and the next cluster. */
|
||||
desc->mPageCount += next->mPageCount;
|
||||
desc->mNext = next->mNext;
|
||||
DeleteFreeClusterDesc(next);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (desc->mAddr == addr + nPages) {
|
||||
/* Coalesce with the next cluster. */
|
||||
desc->mAddr -= nPages;
|
||||
desc->mPageCount += nPages;
|
||||
return;
|
||||
}
|
||||
if (desc->mAddr > addr) {
|
||||
PR_ASSERT(desc->mAddr > addr + nPages);
|
||||
break;
|
||||
}
|
||||
PR_ASSERT(desc->mAddr + desc->mPageCount < addr);
|
||||
p = &desc->mNext;
|
||||
}
|
||||
newDesc = NewFreeClusterDesc();
|
||||
/* In the unlikely event that this malloc fails, we drop the free cluster
|
||||
on the floor. The only consequence is that the memory mapping table
|
||||
becomes slightly larger. */
|
||||
if (newDesc) {
|
||||
newDesc->mNext = desc;
|
||||
newDesc->mAddr = addr;
|
||||
newDesc->mPageCount = nPages;
|
||||
*p = newDesc;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef NS_PAGEMGR_VERIFYCLUSTERS
|
||||
|
||||
#ifndef XP_PC
|
||||
#define OutputDebugString(x) puts(x)
|
||||
#endif
|
||||
|
||||
void
|
||||
nsPageMgr::VerifyClusters(PRWord nPagesDelta)
|
||||
{
|
||||
static PRUword expectedPagesUsed = 0;
|
||||
nsPageCount calculatedPagesUsed;
|
||||
nsPage* lastDescEnd = 0;
|
||||
nsClusterDesc* desc;
|
||||
char str[256];
|
||||
expectedPagesUsed += nPagesDelta;
|
||||
calculatedPagesUsed = mBoundary - mMemoryBase;
|
||||
sprintf(str, "[Clusters: %p", mMemoryBase);
|
||||
OutputDebugString(str);
|
||||
for (desc = mFreeClusters; desc; desc = desc->mNext) {
|
||||
PR_ASSERT(desc->mAddr > lastDescEnd);
|
||||
calculatedPagesUsed -= desc->mPageCount;
|
||||
lastDescEnd = desc->mAddr + desc->mPageCount;
|
||||
sprintf(str, "..%p, %p", desc->mAddr-1, desc->mAddr + desc->mPageCount);
|
||||
OutputDebugString(str);
|
||||
}
|
||||
sprintf(str, "..%p]\n", mBoundary);
|
||||
OutputDebugString(str);
|
||||
PR_ASSERT(lastDescEnd < mBoundary);
|
||||
PR_ASSERT(calculatedPagesUsed == expectedPagesUsed);
|
||||
}
|
||||
|
||||
#endif /* NS_PAGEMGR_VERIFYCLUSTERS */
|
||||
|
||||
/*******************************************************************************
|
||||
* Machine-dependent stuff
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(XP_PC)
|
||||
|
||||
#define GC_VMBASE 0x40000000 /* XXX move */
|
||||
#define GC_VMLIMIT 0x0FFFFFFF
|
||||
|
||||
#elif defined(XP_MAC)
|
||||
|
||||
#define NS_PAGEMGR_MAC_SEGMENT_SIZE
|
||||
#define NS_PAGEMGR_MAC_SEGMENT_COUNT
|
||||
|
||||
#endif
|
||||
|
||||
PRStatus
|
||||
nsPageMgr::InitPages(nsPageCount minPages, nsPageCount maxPages)
|
||||
{
|
||||
#if defined(XP_PC)
|
||||
|
||||
nsPage* addr = NULL;
|
||||
nsPageCount size = maxPages;
|
||||
|
||||
#ifdef NS_PAGEMGR_DEBUG
|
||||
/* first try to place the heap at a well-known address for debugging */
|
||||
addr = (nsPage*)VirtualAlloc((void*)GC_VMBASE, size << NS_PAGEMGR_PAGE_BITS,
|
||||
MEM_RESERVE, PAGE_READWRITE);
|
||||
#endif
|
||||
while (addr == NULL) {
|
||||
/* let the system place the heap */
|
||||
addr = (nsPage*)VirtualAlloc(0, size << NS_PAGEMGR_PAGE_BITS,
|
||||
MEM_RESERVE, PAGE_READWRITE);
|
||||
if (addr == NULL) {
|
||||
size--;
|
||||
if (size < minPages) {
|
||||
return PR_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
PR_ASSERT(NS_PAGEMGR_IS_ALIGNED(addr, NS_PAGEMGR_PAGE_BITS));
|
||||
mMemoryBase = addr;
|
||||
mPageCount = size;
|
||||
mBoundary = addr;
|
||||
|
||||
return PR_SUCCESS;
|
||||
|
||||
#elif defined(XP_MAC)
|
||||
|
||||
OSErr err;
|
||||
void* seg;
|
||||
void* segLimit;
|
||||
Handle h;
|
||||
PRUword segSize = (minPages + 1) * NS_PAGEMGR_PAGE_SIZE;
|
||||
nsPage* firstPage;
|
||||
nsPage* lastPage;
|
||||
nsSegmentDesc* mSegTable;
|
||||
int mSegTableCount, otherCount;
|
||||
|
||||
h = TempNewHandle(segSize, &err);
|
||||
if (err || h == NULL) goto fail;
|
||||
MoveHHi(h);
|
||||
TempHLock(h, &err);
|
||||
if (err) goto fail;
|
||||
seg = *h;
|
||||
segLimit = (void*)((char*)seg + segSize);
|
||||
firstPage = NS_PAGEMGR_PAGE_ROUNDUP(seg);
|
||||
lastPage = NS_PAGEMGR_PAGE_ROUNDDN(((char*)seg + segSize));
|
||||
|
||||
/* Put the segment table in the otherwise wasted space at one
|
||||
end of the segment. We'll put it at which ever end is bigger. */
|
||||
mSegTable = (nsSegmentDesc*)seg;
|
||||
mSegTableCount = ((char*)firstPage - (char*)seg) / sizeof(nsSegmentDesc);
|
||||
otherCount = ((char*)segLimit - (char*)lastPage) / sizeof(nsSegmentDesc);
|
||||
if (otherCount > mSegTableCount) {
|
||||
mSegTable = (nsSegmentDesc*)lastPage;
|
||||
mSegTableCount = otherCount;
|
||||
}
|
||||
else if (mSegTableCount == 0) {
|
||||
mSegTable = (nsSegmentDesc*)firstPage;
|
||||
firstPage++;
|
||||
mSegTableCount = NS_PAGEMGR_PAGE_SIZE / sizeof(nsSegmentDesc);
|
||||
}
|
||||
PR_ASSERT(mSegTableCount > 0);
|
||||
mSegTable = mSegTable;
|
||||
mSegTableCount = mSegTableCount;
|
||||
|
||||
mSegTable[0].handle = h;
|
||||
mSegTable[0].firstPage = firstPage;
|
||||
mSegTable[0].lastPage = lastPage;
|
||||
|
||||
/* XXX hack for now -- just one segment */
|
||||
mMemoryBase = firstPage;
|
||||
mBoundary = firstPage;
|
||||
mPageCount = lastPage - firstPage;
|
||||
|
||||
return PR_SUCCESS;
|
||||
|
||||
fail:
|
||||
if (h) {
|
||||
TempDisposeHandle(h, &err);
|
||||
}
|
||||
return PR_FAILURE;
|
||||
|
||||
#else
|
||||
|
||||
nsPage* addr = NULL;
|
||||
nsPageCount size = maxPages;
|
||||
int zero_fd;
|
||||
|
||||
zero_fd = open("/dev/zero", O_RDWR);
|
||||
|
||||
while (addr == NULL) {
|
||||
/* let the system place the heap */
|
||||
addr = (nsPage*)mmap(0, size << NS_PAGEMGR_PAGE_BITS,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE,
|
||||
zero_fd, 0);
|
||||
if (addr == (nsPage*)MAP_FAILED) {
|
||||
addr = NULL;
|
||||
size--;
|
||||
if (size < minPages) {
|
||||
return PR_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
PR_ASSERT(NS_PAGEMGR_IS_ALIGNED(addr, NS_PAGEMGR_PAGE_BITS));
|
||||
mMemoryBase = addr;
|
||||
mPageCount = size;
|
||||
mBoundary = addr;
|
||||
|
||||
return PR_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
nsPageMgr::FinalizePages()
|
||||
{
|
||||
#if defined(XP_PC)
|
||||
|
||||
BOOL ok;
|
||||
ok = VirtualFree((void*)mMemoryBase, 0, MEM_RELEASE);
|
||||
PR_ASSERT(ok);
|
||||
mMemoryBase = NULL;
|
||||
mPageCount = 0;
|
||||
PR_DestroyMonitor(mMonitor);
|
||||
mMonitor = NULL;
|
||||
|
||||
#elif defined(XP_MAC)
|
||||
|
||||
OSErr err;
|
||||
PRUword i;
|
||||
for (i = 0; i < mSegTableCount; i++) {
|
||||
if (mSegTable[i].handle) {
|
||||
TempDisposeHandle(mSegTable[i].handle, &err);
|
||||
PR_ASSERT(err == 0);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
munmap((caddr_t)mMemoryBase, mPageCount << NS_PAGEMGR_PAGE_BITS);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Page Manager
|
||||
******************************************************************************/
|
||||
|
||||
nsPageMgr::nsPageMgr()
|
||||
: mUnusedClusterDescs(nsnull),
|
||||
mFreeClusters(nsnull),
|
||||
mInUseClusters(nsnull),
|
||||
mMonitor(nsnull),
|
||||
mMemoryBase(nsnull),
|
||||
mBoundary(nsnull),
|
||||
#ifdef XP_PC
|
||||
mLastPageFreed(nsnull),
|
||||
mLastPageFreedSize(0),
|
||||
mLastPageTemp(nsnull),
|
||||
mLastPageTempSize(0),
|
||||
#ifdef NS_PAGEMGR_DEBUG
|
||||
mLastPageAllocTries(0),
|
||||
mLastPageAllocHits(0),
|
||||
mLastPageFreeTries(0),
|
||||
mLastPageFreeHits(0),
|
||||
#endif
|
||||
#endif
|
||||
#if defined(XP_MAC)
|
||||
mSegMap(nsnull),
|
||||
mSegTable(nsnull),
|
||||
mSegTableCount(0),
|
||||
#endif
|
||||
mPageCount(0)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPageMgr::Init(nsPageCount minPages, nsPageCount maxPages)
|
||||
{
|
||||
PRStatus status;
|
||||
|
||||
mMonitor = PR_NewMonitor();
|
||||
if (mMonitor == NULL)
|
||||
return PR_FAILURE;
|
||||
|
||||
status = InitPages(minPages, maxPages);
|
||||
if (status != PR_SUCCESS)
|
||||
return status;
|
||||
|
||||
/* make sure these got set */
|
||||
PR_ASSERT(mMemoryBase);
|
||||
PR_ASSERT(mBoundary);
|
||||
|
||||
mFreeClusters = NULL;
|
||||
mInUseClusters = NULL;
|
||||
|
||||
return status == PR_SUCCESS ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsPageMgr::~nsPageMgr()
|
||||
{
|
||||
#if defined(XP_PC) && defined(NS_PAGEMGR_DEBUG)
|
||||
if (stderr) {
|
||||
fprintf(stderr, "Page Manager Cache: alloc hits: %u/%u %u%%, free hits: %u/%u %u%%\n",
|
||||
mLastPageAllocHits, mLastPageAllocTries,
|
||||
(mLastPageAllocHits * 100 / mLastPageAllocTries),
|
||||
mLastPageFreeHits, mLastPageFreeTries,
|
||||
(mLastPageFreeHits * 100 / mLastPageFreeTries));
|
||||
}
|
||||
#endif
|
||||
FinalizePages();
|
||||
|
||||
nsClusterDesc* chain = mUnusedClusterDescs;
|
||||
while (chain) {
|
||||
nsClusterDesc* desc = chain;
|
||||
chain = chain->mNext;
|
||||
PR_Free(desc);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsPageMgr);
|
||||
NS_IMPL_RELEASE(nsPageMgr);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPageMgr::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
NS_ASSERTION(aInstancePtr != nsnull, "null ptr");
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(nsIPageManager::GetIID()) ||
|
||||
aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIPageManager*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIAllocator::GetIID())) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIAllocator*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#ifdef XP_PC
|
||||
|
||||
#ifdef NS_PAGEMGR_PAGE_HYSTERESIS
|
||||
|
||||
#ifdef NS_PAGEMGR_DEBUG
|
||||
|
||||
void*
|
||||
nsPageMgr::NS_PAGEMGR_COMMIT_CLUSTER(void* addr, PRUword size)
|
||||
{
|
||||
mLastPageAllocTries++;
|
||||
if (mLastPageFreed == (void*)(addr) && mLastPageFreedSize == (size)) {
|
||||
#ifdef NS_PAGEMGR_COMMIT_TRACE
|
||||
char buf[64];
|
||||
PR_snprintf(buf, sizeof(buf), "lalloc %p %u\n",
|
||||
mLastPageFreed, mLastPageFreedSize);
|
||||
OutputDebugString(buf);
|
||||
#endif
|
||||
DBG_MEMSET(mLastPageFreed, NS_PAGEMGR_PAGE_ALLOC_PATTERN, mLastPageFreedSize);
|
||||
mLastPageTemp = mLastPageFreed;
|
||||
mLastPageFreed = NULL;
|
||||
mLastPageFreedSize = 0;
|
||||
mLastPageAllocHits++;
|
||||
return mLastPageTemp;
|
||||
}
|
||||
else {
|
||||
/* If the cached pages intersect the current request, we lose.
|
||||
Just free the cached request instead of trying to split it up. */
|
||||
if (mLastPageFreed &&
|
||||
nsOverlapping((char*)mLastPageFreed, ((char*)mLastPageFreed + mLastPageFreedSize),
|
||||
(char*)(addr), ((char*)(addr) + (size)))
|
||||
// ((char*)mLastPageFreed < ((char*)(addr) + (size))
|
||||
// && ((char*)mLastPageFreed + mLastPageFreedSize) > (char*)(addr))
|
||||
) {
|
||||
#ifdef NS_PAGEMGR_COMMIT_TRACE
|
||||
char buf[64];
|
||||
PR_snprintf(buf, sizeof(buf), "valloc %p %u (vfree %p %u last=%u:%u req=%u:%u)\n",
|
||||
addr, size,
|
||||
mLastPageFreed, mLastPageFreedSize,
|
||||
(char*)mLastPageFreed, ((char*)mLastPageFreed + mLastPageFreedSize),
|
||||
(char*)(addr), ((char*)(addr) + (size)));
|
||||
OutputDebugString(buf);
|
||||
#endif
|
||||
VirtualFree(mLastPageFreed, mLastPageFreedSize, MEM_DECOMMIT);
|
||||
mLastPageFreed = NULL;
|
||||
mLastPageFreedSize = 0;
|
||||
mLastPageFreeHits--; /* lost after all */
|
||||
}
|
||||
else {
|
||||
#ifdef NS_PAGEMGR_COMMIT_TRACE
|
||||
char buf[64];
|
||||
PR_snprintf(buf, sizeof(buf), "valloc %p %u (skipping %p %u)\n",
|
||||
addr, size,
|
||||
mLastPageFreed, mLastPageFreedSize);
|
||||
OutputDebugString(buf);
|
||||
#endif
|
||||
}
|
||||
return VirtualAlloc((void*)(addr), (size), MEM_COMMIT, PAGE_READWRITE);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
nsPageMgr::NS_PAGEMGR_DECOMMIT_CLUSTER(void* addr, PRUword size)
|
||||
{
|
||||
mLastPageFreeTries++;
|
||||
PR_ASSERT(mLastPageFreed != (void*)(addr));
|
||||
if (mLastPageFreed) {
|
||||
/* If we've already got a cached page, just keep it. Heuristically,
|
||||
this tends to give us a higher hit rate because of the order in
|
||||
which pages are decommitted. */
|
||||
#ifdef NS_PAGEMGR_COMMIT_TRACE
|
||||
char buf[64];
|
||||
PR_snprintf(buf, sizeof(buf), "vfree %p %u (cached %p %u)\n",
|
||||
addr, size, mLastPageFreed, mLastPageFreedSize);
|
||||
OutputDebugString(buf);
|
||||
#endif
|
||||
return VirtualFree(addr, size, MEM_DECOMMIT);
|
||||
}
|
||||
mLastPageFreed = (void*)(addr);
|
||||
mLastPageFreedSize = (size);
|
||||
DBG_MEMSET(mLastPageFreed, NS_PAGEMGR_PAGE_FREE_PATTERN, mLastPageFreedSize);
|
||||
#ifdef NS_PAGEMGR_COMMIT_TRACE
|
||||
{
|
||||
char buf[64];
|
||||
PR_snprintf(buf, sizeof(buf), "lfree %p %u\n",
|
||||
mLastPageFreed, mLastPageFreedSize);
|
||||
OutputDebugString(buf);
|
||||
}
|
||||
#endif
|
||||
mLastPageFreeHits++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#else /* !NS_PAGEMGR_DEBUG */
|
||||
|
||||
#define NS_PAGEMGR_COMMIT_CLUSTER(addr, size) \
|
||||
(PR_ASSERT((void*)(addr) != NULL), \
|
||||
((mLastPageFreed == (void*)(addr) && mLastPageFreedSize == (size)) \
|
||||
? (DBG_MEMSET(mLastPageFreed, NS_PAGEMGR_PAGE_ALLOC_PATTERN, mLastPageFreedSize), \
|
||||
mLastPageTemp = mLastPageFreed, \
|
||||
mLastPageFreed = NULL, \
|
||||
mLastPageFreedSize = 0, \
|
||||
mLastPageTemp) \
|
||||
: (((mLastPageFreed && \
|
||||
((char*)mLastPageFreed < ((char*)(addr) + (size)) \
|
||||
&& ((char*)mLastPageFreed + mLastPageFreedSize) > (char*)(addr))) \
|
||||
? (VirtualFree(mLastPageFreed, mLastPageFreedSize, MEM_DECOMMIT), \
|
||||
mLastPageFreed = NULL, \
|
||||
mLastPageFreedSize = 0) \
|
||||
: ((void)0)), \
|
||||
VirtualAlloc((void*)(addr), (size), MEM_COMMIT, PAGE_READWRITE)))) \
|
||||
|
||||
#define NS_PAGEMGR_DECOMMIT_CLUSTER(addr, size) \
|
||||
(PR_ASSERT(mLastPageFreed != (void*)(addr)), \
|
||||
(mLastPageFreed \
|
||||
? (VirtualFree(addr, size, MEM_DECOMMIT)) \
|
||||
: (mLastPageFreed = (addr), \
|
||||
mLastPageFreedSize = (size), \
|
||||
DBG_MEMSET(mLastPageFreed, NS_PAGEMGR_PAGE_FREE_PATTERN, mLastPageFreedSize), \
|
||||
1))) \
|
||||
|
||||
#endif /* !NS_PAGEMGR_DEBUG */
|
||||
|
||||
#else /* !NS_PAGEMGR_PAGE_HYSTERESIS */
|
||||
|
||||
#define NS_PAGEMGR_COMMIT_CLUSTER(addr, size) \
|
||||
VirtualAlloc((void*)(addr), (size), MEM_COMMIT, PAGE_READWRITE)
|
||||
|
||||
#define NS_PAGEMGR_DECOMMIT_CLUSTER(addr, size) \
|
||||
VirtualFree((void*)(addr), (size), MEM_DECOMMIT)
|
||||
|
||||
#endif /* !NS_PAGEMGR_PAGE_HYSTERESIS */
|
||||
|
||||
#else /* !XP_PC */
|
||||
|
||||
#define NS_PAGEMGR_COMMIT_CLUSTER(addr, size) (addr)
|
||||
#define NS_PAGEMGR_DECOMMIT_CLUSTER(addr, size) 1
|
||||
|
||||
#endif /* !XP_PC */
|
||||
|
||||
nsPage*
|
||||
nsPageMgr::NewCluster(nsPageCount nPages)
|
||||
{
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
|
||||
nsPage* addr;
|
||||
PR_ASSERT(nPages > 0);
|
||||
addr = AllocClusterFromFreeList(nPages);
|
||||
if (!addr && mBoundary + nPages <= mMemoryBase + mPageCount) {
|
||||
addr = mBoundary;
|
||||
mBoundary += nPages;
|
||||
}
|
||||
if (addr) {
|
||||
/* Extend the mapping */
|
||||
nsPage* vaddr;
|
||||
PRUword size = nPages << NS_PAGEMGR_PAGE_BITS;
|
||||
PR_ASSERT(NS_PAGEMGR_IS_ALIGNED(addr, NS_PAGEMGR_PAGE_BITS));
|
||||
vaddr = (nsPage*)NS_PAGEMGR_COMMIT_CLUSTER((void*)addr, size);
|
||||
#ifdef NS_PAGEMGR_VERIFYCLUSTERS
|
||||
VerifyClusters(nPages);
|
||||
#endif
|
||||
if (addr) {
|
||||
PR_ASSERT(vaddr == addr);
|
||||
}
|
||||
else {
|
||||
DestroyCluster(addr, nPages);
|
||||
}
|
||||
DBG_MEMSET(addr, NS_PAGEMGR_PAGE_ALLOC_PATTERN, size);
|
||||
}
|
||||
return (nsPage*)addr;
|
||||
}
|
||||
|
||||
void
|
||||
nsPageMgr::DestroyCluster(nsPage* basePage, nsPageCount nPages)
|
||||
{
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
|
||||
int freeResult;
|
||||
PRUword size = nPages << NS_PAGEMGR_PAGE_BITS;
|
||||
|
||||
PR_ASSERT(nPages > 0);
|
||||
PR_ASSERT(NS_PAGEMGR_IS_ALIGNED(basePage, NS_PAGEMGR_PAGE_BITS));
|
||||
PR_ASSERT(mMemoryBase <= basePage);
|
||||
PR_ASSERT(basePage + nPages <= mMemoryBase + mPageCount);
|
||||
DBG_MEMSET(basePage, NS_PAGEMGR_PAGE_FREE_PATTERN, size);
|
||||
freeResult = NS_PAGEMGR_DECOMMIT_CLUSTER((void*)basePage, size);
|
||||
PR_ASSERT(freeResult);
|
||||
if (basePage + nPages == mBoundary) {
|
||||
nsClusterDesc **p;
|
||||
nsClusterDesc *desc;
|
||||
/* We deallocated the last set of clusters. Move the mBoundary lower. */
|
||||
mBoundary = basePage;
|
||||
/* The last free cluster might now be adjacent to the mBoundary; if so,
|
||||
move the mBoundary before that cluster and delete that cluster
|
||||
altogether. */
|
||||
p = &mFreeClusters;
|
||||
while ((desc = *p) != NULL) {
|
||||
if (!desc->mNext && desc->mAddr + desc->mPageCount == mBoundary) {
|
||||
*p = 0;
|
||||
mBoundary = desc->mAddr;
|
||||
DeleteFreeClusterDesc(desc);
|
||||
}
|
||||
else {
|
||||
p = &desc->mNext;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
AddClusterToFreeList(basePage, nPages);
|
||||
}
|
||||
#ifdef NS_PAGEMGR_VERIFYCLUSTERS
|
||||
VerifyClusters(-(PRWord)nPages);
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIPageManager methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPageMgr::AllocPages(PRUint32 pageCount, void* *result)
|
||||
{
|
||||
nsPage* page = NewCluster(NS_STATIC_CAST(nsPageCount, pageCount));
|
||||
if (page == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
*result = page;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPageMgr::DeallocPages(PRUint32 pageCount, void* pages)
|
||||
{
|
||||
DestroyCluster(NS_STATIC_CAST(nsPage*, pages),
|
||||
NS_STATIC_CAST(nsPageCount, pageCount));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIAllocator methods:
|
||||
//
|
||||
// Note: nsIAllocator needs to keep track of the size of the blocks it allocates
|
||||
// whereas, nsIPageManager doesn't. That means that there's a little extra
|
||||
// overhead for users of this interface. It also means that things allocated
|
||||
// with the nsIPageManager interface can't be freed with the nsIAllocator
|
||||
// interface and vice versa.
|
||||
|
||||
NS_IMETHODIMP_(void*)
|
||||
nsPageMgr::Alloc(PRUint32 size)
|
||||
{
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
|
||||
nsresult rv;
|
||||
void* page = nsnull;
|
||||
PRUint32 pageCount = NS_PAGEMGR_PAGE_COUNT(size);
|
||||
|
||||
rv = AllocPages(pageCount, &page);
|
||||
if (NS_FAILED(rv))
|
||||
return nsnull;
|
||||
|
||||
// Add this cluster to the mInUseClusters list:
|
||||
nsClusterDesc* desc = NewFreeClusterDesc();
|
||||
if (desc == nsnull) {
|
||||
rv = DeallocPages(pageCount, page);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "DeallocPages failed");
|
||||
return nsnull;
|
||||
}
|
||||
desc->mAddr = (nsPage*)page;
|
||||
desc->mPageCount = pageCount;
|
||||
desc->mNext = mInUseClusters;
|
||||
mInUseClusters = desc;
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(void*)
|
||||
nsPageMgr::Realloc(void* ptr, PRUint32 size)
|
||||
{
|
||||
// XXX This realloc implementation could be made smarter by trying to
|
||||
// append to the current block, but I don't think we really care right now.
|
||||
nsresult rv;
|
||||
rv = Free(ptr);
|
||||
if (NS_FAILED(rv)) return nsnull;
|
||||
void* newPtr = Alloc(size);
|
||||
return newPtr;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPageMgr::Free(void* ptr)
|
||||
{
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
|
||||
PR_ASSERT(NS_PAGEMGR_IS_ALIGNED(ptr, NS_PAGEMGR_PAGE_BITS));
|
||||
|
||||
// Remove the cluster from the mInUseClusters list:
|
||||
nsClusterDesc** list = &mInUseClusters;
|
||||
nsClusterDesc* desc;
|
||||
while ((desc = *list) != nsnull) {
|
||||
if (desc->mAddr == ptr) {
|
||||
// found -- unlink the desc and free it
|
||||
*list = desc->mNext;
|
||||
nsresult rv = DeallocPages(desc->mPageCount, ptr);
|
||||
DeleteFreeClusterDesc(desc);
|
||||
return rv;
|
||||
}
|
||||
list = &desc->mNext;
|
||||
}
|
||||
NS_ASSERTION(0, "memory not allocated with nsPageMgr::Alloc");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPageMgr::HeapMinimize(void)
|
||||
{
|
||||
// can't compact this heap
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1,185 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsPageMgr_h__
|
||||
#define nsPageMgr_h__
|
||||
|
||||
#include "nsIPageManager.h"
|
||||
#include "nsIAllocator.h"
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsAutoLock.h"
|
||||
#include "prlog.h"
|
||||
#ifdef XP_MAC
|
||||
#include <Types.h>
|
||||
#include <Memory.h>
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* Configuration/Debugging parameters:
|
||||
******************************************************************************/
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
//#define NS_PAGEMGR_DEBUG
|
||||
#endif
|
||||
|
||||
#define NS_PAGEMGR_PAGE_HYSTERESIS /* undef if you want to compare */
|
||||
//#define NS_PAGEMGR_COMMIT_TRACE
|
||||
|
||||
#ifdef NS_PAGEMGR_DEBUG
|
||||
#define NS_PAGEMGR_VERIFYCLUSTERS
|
||||
#define NS_PAGEMGR_DBG_MEMSET
|
||||
#endif
|
||||
|
||||
#define NS_PAGEMGR_MIN_PAGES 32 // XXX bogus -- this should be a runtime parameter
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#ifdef NS_PAGEMGR_DBG_MEMSET
|
||||
|
||||
#include <string.h> /* for memset */
|
||||
#include <stdio.h>
|
||||
|
||||
#define DBG_MEMSET(dest, pattern, size) memset(dest, pattern, size)
|
||||
|
||||
#define NS_PAGEMGR_PAGE_ALLOC_PATTERN 0xCB
|
||||
#define NS_PAGEMGR_PAGE_FREE_PATTERN 0xCD
|
||||
|
||||
#else
|
||||
|
||||
#define DBG_MEMSET(dest, pattern, size) ((void)0)
|
||||
|
||||
#endif
|
||||
|
||||
#define NS_PAGEMGR_ALIGN(p, nBits) ((PRWord)(p) & ~((1 << nBits) - 1))
|
||||
#define NS_PAGEMGR_IS_ALIGNED(p, nBits) ((PRWord)(p) == NS_PAGEMGR_ALIGN(p, nBits))
|
||||
|
||||
/*******************************************************************************
|
||||
* Test for overlapping (one-dimensional) regions
|
||||
******************************************************************************/
|
||||
|
||||
inline PRBool nsOverlapping(char* min1, char* max1, char* min2, char* max2)
|
||||
{
|
||||
PR_ASSERT(min1 < max1);
|
||||
PR_ASSERT(min2 < max2);
|
||||
return (min1 < max2 && max1 > min2);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Types
|
||||
******************************************************************************/
|
||||
|
||||
typedef PRUint8 nsPage[NS_PAGEMGR_PAGE_SIZE];
|
||||
typedef PRUword nsPageCount; /* int big enough to count pages */
|
||||
|
||||
/*******************************************************************************
|
||||
* Macros
|
||||
******************************************************************************/
|
||||
|
||||
#define NS_PAGEMGR_PAGE_ROUNDDN(addr) ((nsPage*)NS_PAGEMGR_ALIGN((PRUword)(addr), NS_PAGEMGR_PAGE_BITS))
|
||||
#define NS_PAGEMGR_PAGE_ROUNDUP(addr) NS_PAGEMGR_PAGE_ROUNDDN((PRUword)(addr) + NS_PAGEMGR_PAGE_SIZE)
|
||||
|
||||
/*******************************************************************************
|
||||
* Page Manager
|
||||
******************************************************************************/
|
||||
|
||||
class nsPageMgr : public nsIPageManager, public nsIAllocator {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIPageManager methods:
|
||||
NS_IMETHOD AllocPages(PRUint32 pageCount, void* *result);
|
||||
NS_IMETHOD DeallocPages(PRUint32 pageCount, void* pages);
|
||||
|
||||
// nsIAllocator methods:
|
||||
NS_IMETHOD_(void*) Alloc(PRUint32 size);
|
||||
NS_IMETHOD_(void*) Realloc(void* ptr, PRUint32 size);
|
||||
NS_IMETHOD Free(void* ptr);
|
||||
NS_IMETHOD HeapMinimize(void);
|
||||
|
||||
// nsPageMgr methods:
|
||||
nsPageMgr();
|
||||
virtual ~nsPageMgr();
|
||||
|
||||
nsresult Init(nsPageCount minPages = NS_PAGEMGR_MIN_PAGES,
|
||||
nsPageCount maxPages = NS_PAGEMGR_MIN_PAGES);
|
||||
|
||||
struct nsClusterDesc {
|
||||
nsClusterDesc* mNext; /* Link to next cluster of free pages */
|
||||
nsPage* mAddr; /* First page in cluster of free pages */
|
||||
nsPageCount mPageCount; /* Total size of cluster of free pages in bytes */
|
||||
};
|
||||
|
||||
void DeleteFreeClusterDesc(nsClusterDesc *desc);
|
||||
nsClusterDesc* NewFreeClusterDesc(void);
|
||||
nsPage* AllocClusterFromFreeList(PRUword nPages);
|
||||
void AddClusterToFreeList(nsPage* addr, PRWord nPages);
|
||||
#ifdef NS_PAGEMGR_VERIFYCLUSTERS
|
||||
void VerifyClusters(PRWord nPagesDelta);
|
||||
#endif
|
||||
|
||||
#if defined(XP_PC) && defined(NS_PAGEMGR_DEBUG)
|
||||
void* NS_PAGEMGR_COMMIT_CLUSTER(void* addr, PRUword size);
|
||||
int NS_PAGEMGR_DECOMMIT_CLUSTER(void* addr, PRUword size);
|
||||
#endif
|
||||
|
||||
// Managing Pages:
|
||||
PRStatus InitPages(nsPageCount minPages, nsPageCount maxPages);
|
||||
void FinalizePages();
|
||||
|
||||
nsPage* NewCluster(nsPageCount nPages);
|
||||
void DestroyCluster(nsPage* basePage, nsPageCount nPages);
|
||||
|
||||
protected:
|
||||
nsClusterDesc* mUnusedClusterDescs;
|
||||
nsClusterDesc* mFreeClusters;
|
||||
nsClusterDesc* mInUseClusters; // used by nsIAllocator methods
|
||||
PRMonitor* mMonitor;
|
||||
nsPage* mMemoryBase;
|
||||
nsPage* mBoundary;
|
||||
nsPageCount mPageCount;
|
||||
|
||||
#ifdef XP_PC
|
||||
/* one-page hysteresis */
|
||||
void* mLastPageFreed;
|
||||
PRUword mLastPageFreedSize;
|
||||
void* mLastPageTemp;
|
||||
PRUword mLastPageTempSize;
|
||||
# ifdef NS_PAGEMGR_DEBUG
|
||||
PRUword mLastPageAllocTries;
|
||||
PRUword mLastPageAllocHits;
|
||||
PRUword mLastPageFreeTries;
|
||||
PRUword mLastPageFreeHits;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(XP_MAC)
|
||||
struct nsSegmentDesc {
|
||||
Handle mHandle;
|
||||
nsPage* mFirstPage;
|
||||
nsPage* mLastPage;
|
||||
};
|
||||
PRUint8* mSegMap;
|
||||
nsSegmentDesc* mSegTable;
|
||||
PRWord mSegTableCount;
|
||||
#endif
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#endif /* nsPageMgr_h__ */
|
||||
@@ -1,424 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsIBuffer.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsAutoLock.h"
|
||||
|
||||
class nsBufferInputStream;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsBufferInputStream : public nsIInputStream
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIBaseStream methods:
|
||||
NS_IMETHOD Close(void);
|
||||
|
||||
// nsIInputStream methods:
|
||||
NS_IMETHOD GetLength(PRUint32 *aLength);
|
||||
NS_IMETHOD Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount);
|
||||
|
||||
// nsBufferInputStream methods:
|
||||
nsBufferInputStream(nsIBuffer* buf, PRBool blocking);
|
||||
virtual ~nsBufferInputStream();
|
||||
|
||||
PRUint32 ReadableAmount() {
|
||||
nsresult rv;
|
||||
PRUint32 amt;
|
||||
char* buf;
|
||||
rv = mBuffer->GetReadBuffer(&amt, &buf); // should never fail
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "GetInputBuffer failed");
|
||||
return amt;
|
||||
}
|
||||
|
||||
nsresult SetEOF();
|
||||
nsresult Fill();
|
||||
|
||||
protected:
|
||||
nsIBuffer* mBuffer;
|
||||
PRBool mBlocking;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsBufferOutputStream : public nsIOutputStream
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIBaseStream methods:
|
||||
NS_IMETHOD Close(void);
|
||||
|
||||
// nsIOutputStream methods:
|
||||
NS_IMETHOD Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount);
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount);
|
||||
NS_IMETHOD Flush(void);
|
||||
|
||||
// nsBufferOutputStream methods:
|
||||
nsBufferOutputStream(nsIBuffer* buf, PRBool blocking);
|
||||
virtual ~nsBufferOutputStream();
|
||||
|
||||
protected:
|
||||
nsIBuffer* mBuffer;
|
||||
PRBool mBlocking;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsBufferInputStream methods:
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsBufferInputStream::nsBufferInputStream(nsIBuffer* buf, PRBool blocking)
|
||||
: mBuffer(buf), mBlocking(blocking)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF(mBuffer);
|
||||
}
|
||||
|
||||
nsBufferInputStream::~nsBufferInputStream()
|
||||
{
|
||||
(void)Close();
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsBufferInputStream);
|
||||
NS_IMPL_RELEASE(nsBufferInputStream);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBufferInputStream::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (aInstancePtr == nsnull)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (aIID.Equals(nsIInputStream::GetIID()) ||
|
||||
aIID.Equals(nsIBaseStream::GetIID()) ||
|
||||
aIID.Equals(nsISupports::GetIID())) {
|
||||
*aInstancePtr = this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBufferInputStream::Close(void)
|
||||
{
|
||||
if (mBuffer == nsnull)
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
|
||||
if (mBlocking) {
|
||||
nsAutoMonitor mon(mBuffer);
|
||||
NS_RELEASE(mBuffer);
|
||||
mBuffer = nsnull;
|
||||
nsresult rv = mon.Notify(); // wake up the writer
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
NS_RELEASE(mBuffer);
|
||||
mBuffer = nsnull;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBufferInputStream::GetLength(PRUint32 *aLength)
|
||||
{
|
||||
if (mBuffer == nsnull)
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
|
||||
char* buf;
|
||||
return mBuffer->GetReadBuffer(aLength, &buf);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBufferInputStream::Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount)
|
||||
{
|
||||
if (mBuffer == nsnull)
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
*aReadCount = 0;
|
||||
|
||||
while (aCount > 0) {
|
||||
PRUint32 amt;
|
||||
rv = mBuffer->Read(aBuf, aCount, &amt);
|
||||
if (rv == NS_BASE_STREAM_EOF)
|
||||
return *aReadCount > 0 ? NS_OK : rv;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (amt == 0) {
|
||||
rv = Fill();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
*aReadCount += amt;
|
||||
aBuf += amt;
|
||||
aCount -= amt;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBufferInputStream::SetEOF()
|
||||
{
|
||||
if (mBuffer == nsnull)
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
|
||||
if (mBlocking) {
|
||||
nsAutoMonitor mon(mBuffer);
|
||||
mBuffer->SetEOF();
|
||||
nsresult rv = mon.Notify(); // wake up the writer
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
mBuffer->SetEOF();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBufferInputStream::Fill()
|
||||
{
|
||||
if (mBuffer == nsnull)
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
|
||||
if (mBlocking) {
|
||||
nsAutoMonitor mon(mBuffer);
|
||||
while (PR_TRUE) {
|
||||
nsresult rv;
|
||||
|
||||
// check read buffer again while in the monitor
|
||||
PRUint32 amt;
|
||||
char* buf;
|
||||
rv = mBuffer->GetReadBuffer(&amt, &buf);
|
||||
if (rv == NS_BASE_STREAM_EOF) return rv;
|
||||
if (NS_SUCCEEDED(rv) && amt > 0) return NS_OK;
|
||||
|
||||
// else notify the writer and wait
|
||||
rv = mon.Notify();
|
||||
if (NS_FAILED(rv)) return rv; // interrupted
|
||||
rv = mon.Wait();
|
||||
if (NS_FAILED(rv)) return rv; // interrupted
|
||||
}
|
||||
}
|
||||
else {
|
||||
return NS_BASE_STREAM_WOULD_BLOCK;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_BASE nsresult
|
||||
NS_NewBufferInputStream(nsIInputStream* *result, nsIBuffer* buffer, PRBool blocking)
|
||||
{
|
||||
nsBufferInputStream* str = new nsBufferInputStream(buffer, blocking);
|
||||
if (str == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(str);
|
||||
*result = str;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsBufferOutputStream methods:
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsBufferOutputStream::nsBufferOutputStream(nsIBuffer* buf, PRBool blocking)
|
||||
: mBuffer(buf), mBlocking(blocking)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF(mBuffer);
|
||||
}
|
||||
|
||||
nsBufferOutputStream::~nsBufferOutputStream()
|
||||
{
|
||||
(void)Close();
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsBufferOutputStream);
|
||||
NS_IMPL_RELEASE(nsBufferOutputStream);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBufferOutputStream::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (aInstancePtr == nsnull)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (aIID.Equals(nsIOutputStream::GetIID()) ||
|
||||
aIID.Equals(nsIBaseStream::GetIID()) ||
|
||||
aIID.Equals(nsISupports::GetIID())) {
|
||||
*aInstancePtr = this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBufferOutputStream::Close(void)
|
||||
{
|
||||
if (mBuffer == nsnull)
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
|
||||
if (mBlocking) {
|
||||
nsAutoMonitor mon(mBuffer);
|
||||
mBuffer->SetEOF();
|
||||
NS_RELEASE(mBuffer);
|
||||
mBuffer = nsnull;
|
||||
nsresult rv = mon.Notify(); // wake up the writer
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
NS_RELEASE(mBuffer);
|
||||
mBuffer = nsnull;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBufferOutputStream::Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount)
|
||||
{
|
||||
if (mBuffer == nsnull)
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
*aWriteCount = 0;
|
||||
|
||||
while (aCount > 0) {
|
||||
PRUint32 amt;
|
||||
rv = mBuffer->Write(aBuf, aCount, &amt);
|
||||
if (rv == NS_BASE_STREAM_EOF)
|
||||
return *aWriteCount > 0 ? NS_OK : rv;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (amt == 0) {
|
||||
rv = Flush();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
aBuf += amt;
|
||||
aCount -= amt;
|
||||
*aWriteCount += amt;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBufferOutputStream::Write(nsIInputStream* fromStream, PRUint32 *aWriteCount)
|
||||
{
|
||||
if (mBuffer == nsnull)
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
*aWriteCount = 0;
|
||||
|
||||
while (PR_TRUE) { // write until fromStream gets EOF
|
||||
PRUint32 amt;
|
||||
rv = mBuffer->Write(fromStream, &amt);
|
||||
if (rv == NS_BASE_STREAM_EOF)
|
||||
return *aWriteCount > 0 ? NS_OK : rv;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (amt == 0) {
|
||||
rv = Flush();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
*aWriteCount += amt;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBufferOutputStream::Flush(void)
|
||||
{
|
||||
if (mBuffer == nsnull)
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
|
||||
if (mBlocking) {
|
||||
nsresult rv;
|
||||
nsAutoMonitor mon(mBuffer);
|
||||
|
||||
// check write buffer again while in the monitor
|
||||
PRUint32 amt;
|
||||
char* buf;
|
||||
rv = mBuffer->GetWriteBuffer(&amt, &buf);
|
||||
if (rv == NS_BASE_STREAM_EOF) return rv;
|
||||
if (NS_SUCCEEDED(rv) && amt > 0) return NS_OK;
|
||||
|
||||
// else notify the reader and wait
|
||||
rv = mon.Notify();
|
||||
if (NS_FAILED(rv)) return rv; // interrupted
|
||||
rv = mon.Wait();
|
||||
if (NS_FAILED(rv)) return rv; // interrupted
|
||||
}
|
||||
else {
|
||||
return NS_BASE_STREAM_WOULD_BLOCK;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_BASE nsresult
|
||||
NS_NewBufferOutputStream(nsIOutputStream* *result, nsIBuffer* buffer, PRBool blocking)
|
||||
{
|
||||
nsBufferOutputStream* ostr = new nsBufferOutputStream(buffer, blocking);
|
||||
if (ostr == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(ostr);
|
||||
*result = ostr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_BASE nsresult
|
||||
NS_NewPipe2(nsIInputStream* *inStrResult,
|
||||
nsIOutputStream* *outStrResult,
|
||||
PRUint32 growBySize, PRUint32 maxSize)
|
||||
{
|
||||
nsresult rv;
|
||||
nsIInputStream* inStr = nsnull;
|
||||
nsIOutputStream* outStr = nsnull;
|
||||
nsIBuffer* buf = nsnull;
|
||||
|
||||
rv = NS_NewPageBuffer(&buf, growBySize, maxSize);
|
||||
if (NS_FAILED(rv)) goto error;
|
||||
|
||||
rv = NS_NewBufferInputStream(&inStr, buf, PR_TRUE);
|
||||
if (NS_FAILED(rv)) goto error;
|
||||
|
||||
rv = NS_NewBufferOutputStream(&outStr, buf, PR_TRUE);
|
||||
if (NS_FAILED(rv)) goto error;
|
||||
|
||||
NS_RELEASE(buf);
|
||||
*inStrResult = inStr;
|
||||
*outStrResult = outStr;
|
||||
return NS_OK;
|
||||
|
||||
error:
|
||||
NS_IF_RELEASE(inStr);
|
||||
NS_IF_RELEASE(outStr);
|
||||
NS_IF_RELEASE(buf);
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -17,173 +17,71 @@
|
||||
*/
|
||||
|
||||
#define NS_IMPL_IDS
|
||||
|
||||
#include "nsProperties.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsProperties, nsIProperties::GetIID());
|
||||
|
||||
nsProperties::nsProperties()
|
||||
{
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsProperties::ReleaseValues(nsHashKey* key, void* data, void* closure)
|
||||
{
|
||||
nsISupports* value = (nsISupports*)data;
|
||||
NS_IF_RELEASE(value);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsProperties::~nsProperties()
|
||||
{
|
||||
Enumerate(ReleaseValues);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsProperties::DefineProperty(const char* prop, nsISupports* initialValue)
|
||||
{
|
||||
nsCStringKey key(prop);
|
||||
if (Exists(&key))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsISupports* prevValue = (nsISupports*)Put(&key, initialValue);
|
||||
NS_ASSERTION(prevValue == NULL, "hashtable error");
|
||||
NS_IF_ADDREF(initialValue);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsProperties::UndefineProperty(const char* prop)
|
||||
{
|
||||
nsCStringKey key(prop);
|
||||
if (!Exists(&key))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsISupports* prevValue = (nsISupports*)Remove(&key);
|
||||
NS_IF_RELEASE(prevValue);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsProperties::GetProperty(const char* prop, nsISupports* *result)
|
||||
{
|
||||
nsCStringKey key(prop);
|
||||
if (!Exists(&key))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsISupports* value = (nsISupports*)Get(&key);
|
||||
NS_IF_ADDREF(value);
|
||||
*result = value;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsProperties::SetProperty(const char* prop, nsISupports* value)
|
||||
{
|
||||
nsCStringKey key(prop);
|
||||
if (!Exists(&key))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsISupports* prevValue = (nsISupports*)Put(&key, value);
|
||||
NS_IF_RELEASE(prevValue);
|
||||
NS_IF_ADDREF(value);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsProperties::HasProperty(const char* prop, nsISupports* expectedValue)
|
||||
{
|
||||
nsISupports* value;
|
||||
nsresult rv = GetProperty(prop, &value);
|
||||
if (NS_FAILED(rv)) return NS_COMFALSE;
|
||||
rv = (value == expectedValue) ? NS_OK : NS_COMFALSE;
|
||||
NS_IF_RELEASE(value);
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewIProperties(nsIProperties* *result)
|
||||
{
|
||||
nsProperties* props = new nsProperties();
|
||||
if (props == NULL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(props);
|
||||
*result = props;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Persistent Properties (should go in a separate file)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "nsID.h"
|
||||
|
||||
#include "nsBaseDLL.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIProperties.h"
|
||||
#include "nsIUnicharInputStream.h"
|
||||
#include "nsProperties.h"
|
||||
#include "plhash.h"
|
||||
#include "pratom.h"
|
||||
|
||||
nsPersistentProperties::nsPersistentProperties()
|
||||
class nsProperties : public nsIProperties
|
||||
{
|
||||
public:
|
||||
nsProperties();
|
||||
~nsProperties();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Load(nsIInputStream* aIn);
|
||||
NS_IMETHOD GetProperty(const nsString& aKey, nsString& aValue);
|
||||
NS_IMETHOD SetProperty(const nsString& aKey, nsString& aNewValue,
|
||||
nsString& aOldValue);
|
||||
NS_IMETHOD Save(nsIOutputStream* aOut, const nsString& aHeader);
|
||||
NS_IMETHOD Subclass(nsIProperties* aSubclass);
|
||||
|
||||
PRInt32 Read();
|
||||
PRInt32 SkipLine(PRInt32 c);
|
||||
PRInt32 SkipWhiteSpace(PRInt32 c);
|
||||
|
||||
nsIUnicharInputStream* mIn;
|
||||
nsIProperties* mSubclass;
|
||||
struct PLHashTable* mTable;
|
||||
};
|
||||
|
||||
nsProperties::nsProperties()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
mIn = nsnull;
|
||||
mSubclass = NS_STATIC_CAST(nsIPersistentProperties*, this);
|
||||
mSubclass = NS_STATIC_CAST(nsIProperties*, this);
|
||||
mTable = nsnull;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(PRIntn)
|
||||
FreeHashEntries(PLHashEntry* he, PRIntn i, void* arg)
|
||||
{
|
||||
delete[] (PRUnichar*)he->key;
|
||||
delete[] (PRUnichar*)he->value;
|
||||
return HT_ENUMERATE_REMOVE;
|
||||
}
|
||||
|
||||
nsPersistentProperties::~nsPersistentProperties()
|
||||
nsProperties::~nsProperties()
|
||||
{
|
||||
if (mTable) {
|
||||
// Free the PRUnicode* pointers contained in the hash table entries
|
||||
PL_HashTableEnumerateEntries(mTable, FreeHashEntries, 0);
|
||||
PL_HashTableDestroy(mTable);
|
||||
mTable = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsPersistentProperties)
|
||||
NS_IMPL_RELEASE(nsPersistentProperties)
|
||||
NS_DEFINE_IID(kIPropertiesIID, NS_IPROPERTIES_IID);
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsProperties, kIPropertiesIID)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPersistentProperties::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
NS_ASSERTION(aInstancePtr != nsnull, "null ptr");
|
||||
if (aIID.Equals(nsIPersistentProperties::GetIID()) ||
|
||||
aIID.Equals(nsIProperties::GetIID()) ||
|
||||
aIID.Equals(nsISupports::GetIID())) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIPersistentProperties*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPersistentProperties::Load(nsIInputStream *aIn)
|
||||
nsProperties::Load(nsIInputStream *aIn)
|
||||
{
|
||||
PRInt32 c;
|
||||
nsresult ret;
|
||||
|
||||
ret = NS_NewConverterStream(&mIn, nsnull, aIn);
|
||||
if (ret != NS_OK) {
|
||||
#ifdef NS_DEBUG
|
||||
cout << "NS_NewConverterStream failed" << endl;
|
||||
#endif
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
c = Read();
|
||||
@@ -228,8 +126,7 @@ nsPersistentProperties::Load(nsIInputStream *aIn)
|
||||
}
|
||||
}
|
||||
mIn->Close();
|
||||
NS_RELEASE(mIn);
|
||||
NS_ASSERTION(!mIn, "unexpected remaining reference");
|
||||
mIn = nsnull;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -247,14 +144,10 @@ CompareKeys(const PRUnichar *aStr1, const PRUnichar *aStr2)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPersistentProperties::SetProperty(const nsString& aKey, nsString& aNewValue,
|
||||
nsProperties::SetProperty(const nsString& aKey, nsString& aNewValue,
|
||||
nsString& aOldValue)
|
||||
{
|
||||
// XXX The ToNewCString() calls allocate memory using "new" so this code
|
||||
// causes a memory leak...
|
||||
#if 0
|
||||
cout << "will add " << aKey.ToNewCString() << "=" << aNewValue.ToNewCString() << endl;
|
||||
#endif
|
||||
if (!mTable) {
|
||||
mTable = PL_NewHashTable(8, (PLHashFunction) HashKey,
|
||||
(PLHashComparator) CompareKeys,
|
||||
@@ -264,28 +157,28 @@ nsPersistentProperties::SetProperty(const nsString& aKey, nsString& aNewValue,
|
||||
}
|
||||
}
|
||||
|
||||
const PRUnichar *key = aKey.GetUnicode(); // returns internal pointer (not a copy)
|
||||
PRUint32 len;
|
||||
PRUnichar *key = aKey.ToNewUnicode();
|
||||
PRInt32 len;
|
||||
PRUint32 hashValue = nsCRT::HashValue(key, &len);
|
||||
PLHashEntry **hep = PL_HashTableRawLookup(mTable, hashValue, key);
|
||||
PLHashEntry *he = *hep;
|
||||
if (he && aOldValue.GetUnicode()) {
|
||||
if (he && aOldValue) {
|
||||
// XXX fix me
|
||||
}
|
||||
PL_HashTableRawAdd(mTable, hep, hashValue, aKey.ToNewUnicode(),
|
||||
aNewValue.ToNewUnicode());
|
||||
PL_HashTableRawAdd(mTable, hep, hashValue, key,
|
||||
new nsString(aNewValue.ToNewUnicode()));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPersistentProperties::Save(nsIOutputStream* aOut, const nsString& aHeader)
|
||||
nsProperties::Save(nsIOutputStream* aOut, const nsString& aHeader)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPersistentProperties::Subclass(nsIPersistentProperties* aSubclass)
|
||||
nsProperties::Subclass(nsIProperties* aSubclass)
|
||||
{
|
||||
if (aSubclass) {
|
||||
mSubclass = aSubclass;
|
||||
@@ -295,15 +188,15 @@ nsPersistentProperties::Subclass(nsIPersistentProperties* aSubclass)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPersistentProperties::GetProperty(const nsString& aKey, nsString& aValue)
|
||||
nsProperties::GetProperty(const nsString& aKey, nsString& aValue)
|
||||
{
|
||||
const PRUnichar *key = aKey.GetUnicode();
|
||||
PRUint32 len;
|
||||
PRUnichar *key = aKey;
|
||||
PRInt32 len;
|
||||
PRUint32 hashValue = nsCRT::HashValue(key, &len);
|
||||
PLHashEntry **hep = PL_HashTableRawLookup(mTable, hashValue, key);
|
||||
PLHashEntry *he = *hep;
|
||||
if (he) {
|
||||
aValue = (const PRUnichar*)he->value;
|
||||
((nsString *) he->value)->Copy(aValue);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -311,7 +204,7 @@ nsPersistentProperties::GetProperty(const nsString& aKey, nsString& aValue)
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsPersistentProperties::Read()
|
||||
nsProperties::Read()
|
||||
{
|
||||
PRUnichar c;
|
||||
PRUint32 nRead;
|
||||
@@ -329,7 +222,7 @@ nsPersistentProperties::Read()
|
||||
(((c) == ' ') || ((c) == '\t') || ((c) == '\r') || ((c) == '\n'))
|
||||
|
||||
PRInt32
|
||||
nsPersistentProperties::SkipWhiteSpace(PRInt32 c)
|
||||
nsProperties::SkipWhiteSpace(PRInt32 c)
|
||||
{
|
||||
while ((c >= 0) && IS_WHITE_SPACE(c)) {
|
||||
c = Read();
|
||||
@@ -339,7 +232,7 @@ nsPersistentProperties::SkipWhiteSpace(PRInt32 c)
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsPersistentProperties::SkipLine(PRInt32 c)
|
||||
nsProperties::SkipLine(PRInt32 c)
|
||||
{
|
||||
while ((c >= 0) && (c != '\r') && (c != '\n')) {
|
||||
c = Read();
|
||||
@@ -354,36 +247,42 @@ nsPersistentProperties::SkipLine(PRInt32 c)
|
||||
return c;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPersistentProperties::DefineProperty(const char* prop, nsISupports* initialValue)
|
||||
NS_IMPL_ISUPPORTS(nsPropertiesFactory, kIFactoryIID);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPropertiesFactory::CreateInstance(nsISupports* aOuter, REFNSIID aIID,
|
||||
void** aResult)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
if (aOuter) {
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
if (!aResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
*aResult = nsnull;
|
||||
nsProperties* props = new nsProperties();
|
||||
if (!props) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsresult ret = props->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(ret)) {
|
||||
delete props;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPersistentProperties::UndefineProperty(const char* prop)
|
||||
NS_IMETHODIMP
|
||||
nsPropertiesFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
if (aLock) {
|
||||
PR_AtomicIncrement(&gLockCount);
|
||||
}
|
||||
else {
|
||||
PR_AtomicDecrement(&gLockCount);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPersistentProperties::GetProperty(const char* prop, nsISupports* *result)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPersistentProperties::SetProperty(const char* prop, nsISupports* value)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPersistentProperties::HasProperty(const char* prop, nsISupports* value)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -19,65 +19,16 @@
|
||||
#ifndef nsProperties_h___
|
||||
#define nsProperties_h___
|
||||
|
||||
#include "nsIProperties.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsIFactory.h"
|
||||
|
||||
class nsIUnicharInputStream;
|
||||
|
||||
class nsProperties : public nsIProperties, public nsHashtable {
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIProperties methods:
|
||||
NS_IMETHOD DefineProperty(const char* prop, nsISupports* initialValue);
|
||||
NS_IMETHOD UndefineProperty(const char* prop);
|
||||
NS_IMETHOD GetProperty(const char* prop, nsISupports* *result);
|
||||
NS_IMETHOD SetProperty(const char* prop, nsISupports* value);
|
||||
NS_IMETHOD HasProperty(const char* prop, nsISupports* value);
|
||||
|
||||
// nsProperties methods:
|
||||
nsProperties();
|
||||
virtual ~nsProperties();
|
||||
|
||||
static PRBool ReleaseValues(nsHashKey* key, void* data, void* closure);
|
||||
|
||||
};
|
||||
|
||||
class nsPersistentProperties : public nsIPersistentProperties
|
||||
class nsPropertiesFactory : nsIFactory
|
||||
{
|
||||
public:
|
||||
nsPersistentProperties();
|
||||
virtual ~nsPersistentProperties();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIProperties methods:
|
||||
NS_IMETHOD DefineProperty(const char* prop, nsISupports* initialValue);
|
||||
NS_IMETHOD UndefineProperty(const char* prop);
|
||||
NS_IMETHOD GetProperty(const char* prop, nsISupports* *result);
|
||||
NS_IMETHOD SetProperty(const char* prop, nsISupports* value);
|
||||
NS_IMETHOD HasProperty(const char* prop, nsISupports* value);
|
||||
|
||||
// nsIPersistentProperties methods:
|
||||
NS_IMETHOD Load(nsIInputStream* aIn);
|
||||
NS_IMETHOD Save(nsIOutputStream* aOut, const nsString& aHeader);
|
||||
NS_IMETHOD Subclass(nsIPersistentProperties* aSubclass);
|
||||
|
||||
// XXX these 2 methods will be subsumed by the ones from
|
||||
// nsIProperties once we figure this all out
|
||||
NS_IMETHOD GetProperty(const nsString& aKey, nsString& aValue);
|
||||
NS_IMETHOD SetProperty(const nsString& aKey, nsString& aNewValue,
|
||||
nsString& aOldValue);
|
||||
|
||||
// nsPersistentProperties methods:
|
||||
PRInt32 Read();
|
||||
PRInt32 SkipLine(PRInt32 c);
|
||||
PRInt32 SkipWhiteSpace(PRInt32 c);
|
||||
|
||||
nsIUnicharInputStream* mIn;
|
||||
nsIPersistentProperties* mSubclass;
|
||||
struct PLHashTable* mTable;
|
||||
NS_IMETHOD CreateInstance(nsISupports* aOuter, REFNSIID aIID,
|
||||
void** aResult);
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
};
|
||||
|
||||
#endif /* nsProperties_h___ */
|
||||
|
||||
@@ -1,182 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* We need this because Solaris' version of qsort is broken and
|
||||
* causes array bounds reads.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "prtypes.h"
|
||||
#include "nsQuickSort.h"
|
||||
|
||||
#if !defined(DEBUG) && (defined(__cplusplus) || defined(__gcc))
|
||||
# ifndef INLINE
|
||||
# define INLINE inline
|
||||
# endif
|
||||
#else
|
||||
# define INLINE
|
||||
#endif
|
||||
|
||||
typedef int cmp_t(const void *, const void *, void *);
|
||||
static INLINE char *med3(char *, char *, char *, cmp_t *, void *);
|
||||
static INLINE void swapfunc(char *, char *, int, int);
|
||||
|
||||
/*
|
||||
* Qsort routine from Bentley & McIlroy's "Engineering a Sort Function".
|
||||
*/
|
||||
#define swapcode(TYPE, parmi, parmj, n) { \
|
||||
long i = (n) / sizeof (TYPE); \
|
||||
register TYPE *pi = (TYPE *) (parmi); \
|
||||
register TYPE *pj = (TYPE *) (parmj); \
|
||||
do { \
|
||||
register TYPE t = *pi; \
|
||||
*pi++ = *pj; \
|
||||
*pj++ = t; \
|
||||
} while (--i > 0); \
|
||||
}
|
||||
|
||||
#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \
|
||||
es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;
|
||||
|
||||
static INLINE void
|
||||
swapfunc(char *a, char *b, int n, int swaptype)
|
||||
{
|
||||
if(swaptype <= 1)
|
||||
swapcode(long, a, b, n)
|
||||
else
|
||||
swapcode(char, a, b, n)
|
||||
}
|
||||
|
||||
#define swap(a, b) \
|
||||
if (swaptype == 0) { \
|
||||
long t = *(long *)(a); \
|
||||
*(long *)(a) = *(long *)(b); \
|
||||
*(long *)(b) = t; \
|
||||
} else \
|
||||
swapfunc((char *)a, (char*)b, (int)es, swaptype)
|
||||
|
||||
#define vecswap(a, b, n) if ((n) > 0) swapfunc((char *)a, (char *)b, (int)n, swaptype)
|
||||
|
||||
static INLINE char *
|
||||
med3(char *a, char *b, char *c, cmp_t* cmp, void *data)
|
||||
{
|
||||
return cmp(a, b, data) < 0 ?
|
||||
(cmp(b, c, data) < 0 ? b : (cmp(a, c, data) < 0 ? c : a ))
|
||||
:(cmp(b, c, data) > 0 ? b : (cmp(a, c, data) < 0 ? a : c ));
|
||||
}
|
||||
|
||||
void NS_QuickSort (
|
||||
void *a,
|
||||
unsigned int n,
|
||||
unsigned int es,
|
||||
cmp_t *cmp,
|
||||
void *data
|
||||
)
|
||||
{
|
||||
char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
|
||||
int d, r, swaptype, swap_cnt;
|
||||
|
||||
loop: SWAPINIT(a, es);
|
||||
swap_cnt = 0;
|
||||
if (n < 7) {
|
||||
for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
|
||||
for (pl = pm; pl > (char *)a && cmp(pl - es, pl, data) > 0;
|
||||
pl -= es)
|
||||
swap(pl, pl - es);
|
||||
return;
|
||||
}
|
||||
pm = (char *)a + (n / 2) * es;
|
||||
if (n > 7) {
|
||||
pl = (char *)a;
|
||||
pn = (char *)a + (n - 1) * es;
|
||||
if (n > 40) {
|
||||
d = (n / 8) * es;
|
||||
pl = med3(pl, pl + d, pl + 2 * d, cmp, data);
|
||||
pm = med3(pm - d, pm, pm + d, cmp, data);
|
||||
pn = med3(pn - 2 * d, pn - d, pn, cmp, data);
|
||||
}
|
||||
pm = med3(pl, pm, pn, cmp, data);
|
||||
}
|
||||
swap(a, pm);
|
||||
pa = pb = (char *)a + es;
|
||||
|
||||
pc = pd = (char *)a + (n - 1) * es;
|
||||
for (;;) {
|
||||
while (pb <= pc && (r = cmp(pb, a, data)) <= 0) {
|
||||
if (r == 0) {
|
||||
swap_cnt = 1;
|
||||
swap(pa, pb);
|
||||
pa += es;
|
||||
}
|
||||
pb += es;
|
||||
}
|
||||
while (pb <= pc && (r = cmp(pc, a, data)) >= 0) {
|
||||
if (r == 0) {
|
||||
swap_cnt = 1;
|
||||
swap(pc, pd);
|
||||
pd -= es;
|
||||
}
|
||||
pc -= es;
|
||||
}
|
||||
if (pb > pc)
|
||||
break;
|
||||
swap(pb, pc);
|
||||
swap_cnt = 1;
|
||||
pb += es;
|
||||
pc -= es;
|
||||
}
|
||||
if (swap_cnt == 0) { /* Switch to insertion sort */
|
||||
for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
|
||||
for (pl = pm; pl > (char *)a && cmp(pl - es, pl, data) > 0;
|
||||
pl -= es)
|
||||
swap(pl, pl - es);
|
||||
return;
|
||||
}
|
||||
|
||||
pn = (char *)a + n * es;
|
||||
r = PR_MIN(pa - (char *)a, pb - pa);
|
||||
vecswap(a, pb - r, r);
|
||||
r = PR_MIN(pd - pc, pn - pd - es);
|
||||
vecswap(pb, pn - r, r);
|
||||
if ((r = pb - pa) > es)
|
||||
NS_QuickSort(a, r / es, es, cmp, data);
|
||||
if ((r = pd - pc) > es) {
|
||||
/* Iterate rather than recurse to save stack space */
|
||||
a = pn - r;
|
||||
n = r / es;
|
||||
goto loop;
|
||||
}
|
||||
/* NS_QuickSort(pn - r, r / es, es, cmp, data);*/
|
||||
}
|
||||
@@ -1,233 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsIScriptable.h"
|
||||
#include "nscore.h"
|
||||
#include "xptcall.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
|
||||
class nsScriptable : public nsIScriptable {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIProperties methods:
|
||||
NS_IMETHOD DefineProperty(const char* prop, nsISupports* initialValue);
|
||||
NS_IMETHOD UndefineProperty(const char* prop);
|
||||
NS_IMETHOD GetProperty(const char* prop, nsISupports* *result);
|
||||
NS_IMETHOD SetProperty(const char* prop, nsISupports* value);
|
||||
NS_IMETHOD HasProperty(const char* prop, nsISupports* value);
|
||||
|
||||
// nsIScriptable methods:
|
||||
NS_IMETHOD Call(const char* command,
|
||||
nsISupportsArray* arguments,
|
||||
nsISupports* *result);
|
||||
|
||||
// nsScriptable methods:
|
||||
nsScriptable(REFNSIID iid, nsISupports* object);
|
||||
virtual ~nsScriptable();
|
||||
|
||||
nsresult Init();
|
||||
// XXX should this be a method on nsIScriptable?
|
||||
NS_IMETHOD QueryInterfaceScriptable(REFNSIID aIID, void** aInstancePtr);
|
||||
|
||||
// XXX later this will be a service
|
||||
static nsIInterfaceInfoManager* gInterfaceInfoManager;
|
||||
|
||||
protected:
|
||||
nsISupports* mObject;
|
||||
nsIInterfaceInfo* mInterfaceInfo;
|
||||
nsID mIID;
|
||||
// nsXPCWrappedNativeClass* mClazz;
|
||||
// nsXPCWrappedNative* mWrapper;
|
||||
};
|
||||
|
||||
// XXX later this will be a service
|
||||
nsIInterfaceInfoManager* nsScriptable::gInterfaceInfoManager = nsnull;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsScriptable::nsScriptable(REFNSIID iid, nsISupports* object)
|
||||
: mObject(object), mInterfaceInfo(nsnull), mIID(iid)
|
||||
// , mClazz(nsnull), mWrapper(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF(mObject);
|
||||
}
|
||||
|
||||
nsScriptable::~nsScriptable()
|
||||
{
|
||||
NS_RELEASE(mObject);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsScriptable, nsIScriptable::GetIID());
|
||||
|
||||
nsresult
|
||||
nsScriptable::Init()
|
||||
{
|
||||
nsresult rv;
|
||||
if (gInterfaceInfoManager == nsnull) {
|
||||
gInterfaceInfoManager = XPTI_GetInterfaceInfoManager();
|
||||
if (gInterfaceInfoManager == nsnull)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// get the interface info
|
||||
NS_IF_RELEASE(mInterfaceInfo);
|
||||
rv = gInterfaceInfoManager->GetInfoForIID(&mIID, &mInterfaceInfo);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIProperties methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptable::DefineProperty(const char* prop, nsISupports* initialValue)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptable::UndefineProperty(const char* prop)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptable::GetProperty(const char* prop, nsISupports* *result)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptable::SetProperty(const char* prop, nsISupports* value)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptable::HasProperty(const char* prop, nsISupports* expectedValue)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIScriptable methods:
|
||||
|
||||
#define PARAM_BUFFER_COUNT 16
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptable::Call(const char* methodName,
|
||||
nsISupportsArray* arguments,
|
||||
nsISupports* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
const nsXPTMethodInfo* methodInfo;
|
||||
PRUint16 vtblIndex;
|
||||
PRUint8 paramCount;
|
||||
rv = arguments->Count(¶mCount);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsXPTCVariant paramBuffer[PARAM_BUFFER_COUNT];
|
||||
nsXPTCVariant* dispatchParams;
|
||||
PRUint8 requiredArgs;
|
||||
|
||||
// get the method info and vtable index
|
||||
rv = mInterfaceInfo->GetMethodInfoForName(methodName, &vtblIndex, &methodInfo);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (paramCount < PARAM_BUFFER_COUNT) {
|
||||
dispatchParams = paramBuffer;
|
||||
}
|
||||
else {
|
||||
dispatchParams = new nsXPTCVariant[paramCount];
|
||||
if (dispatchParams == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// put together the parameter list
|
||||
for (PRUint8 i = 0; i < paramCount; i++) {
|
||||
nsISupports* arg = (*arguments)[i];
|
||||
const nsXPTParamInfo& paramInfo = methodInfo->GetParam(i);
|
||||
const nsXPTType& paramType = paramInfo.GetType();
|
||||
nsXPTCVariant* dp = &dispatchParams[i];
|
||||
|
||||
if (paramInfo.IsOut()) {
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
switch (paramType.TagPart()) {
|
||||
case nsXPTType::T_INTERFACE:
|
||||
dp->flags |= nsXPTCVariant::VAL_IS_IFACE;
|
||||
nsID* iid;
|
||||
rv = mInterfaceInfo->GetIIDForParam(¶mInfo, &iid);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
break;
|
||||
case nsXPTType::T_INTERFACE_IS:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// invoke the method
|
||||
rv = XPTC_InvokeByIndex(mObject, vtblIndex, paramCount, dispatchParams);
|
||||
// return any out parameters
|
||||
|
||||
done:
|
||||
if (dispatchParams != paramBuffer)
|
||||
delete[] dispatchParams;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptable::QueryInterfaceScriptable(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
NS_PRECONDITION(aInstancePtr, "null aInstancePtr");
|
||||
nsresult rv;
|
||||
rv = mObject->QueryInterface(aIID, aInstancePtr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
NS_RELEASE(mObject);
|
||||
mObject = *(nsISupports**)aInstancePtr;
|
||||
mIID = aIID;
|
||||
return Init();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern nsresult
|
||||
NS_NewIScriptable(REFNSIID iid, nsISupports* object, nsIScriptable* *result)
|
||||
{
|
||||
nsScriptable* s = new nsScriptable(iid, object);
|
||||
if (s == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsresult rv = s->Init();
|
||||
if (NS_FAILED(rv)) {
|
||||
delete s;
|
||||
return rv;
|
||||
}
|
||||
NS_ADDREF(s);
|
||||
*result = s;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -23,7 +23,7 @@ static NS_DEFINE_IID(kISizeOfHandlerIID, NS_ISIZEOF_HANDLER_IID);
|
||||
class nsSizeOfHandler : public nsISizeOfHandler {
|
||||
public:
|
||||
nsSizeOfHandler();
|
||||
virtual ~nsSizeOfHandler();
|
||||
~nsSizeOfHandler();
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
@@ -1,566 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
#include "nsDebug.h"
|
||||
|
||||
#ifdef XP_MAC
|
||||
#include <Folders.h>
|
||||
#include <Files.h>
|
||||
#include <Memory.h>
|
||||
#include <Processes.h>
|
||||
#elif defined(XP_PC)
|
||||
#include <windows.h>
|
||||
#include <shlobj.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#elif defined(XP_UNIX)
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/param.h>
|
||||
#include "prenv.h"
|
||||
#endif
|
||||
|
||||
#include "plstr.h"
|
||||
|
||||
#if XP_PC
|
||||
//----------------------------------------------------------------------------------------
|
||||
static char* MakeUpperCase(char* aPath)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
// windows does not care about case. push to uppercase:
|
||||
int length = strlen(aPath);
|
||||
for (int i = 0; i < length; i++)
|
||||
if (islower(aPath[i]))
|
||||
aPath[i] = _toupper(aPath[i]);
|
||||
|
||||
return aPath;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
static void GetWindowsFolder(int folder, nsFileSpec& outDirectory)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
LPMALLOC pMalloc = NULL;
|
||||
LPSTR pBuffer = NULL;
|
||||
LPITEMIDLIST pItemIDList = NULL;
|
||||
int len;
|
||||
|
||||
// Get the shell's allocator.
|
||||
if (!SUCCEEDED(SHGetMalloc(&pMalloc)))
|
||||
return;
|
||||
|
||||
// Allocate a buffer
|
||||
if ((pBuffer = (LPSTR) pMalloc->Alloc(MAX_PATH + 2)) == NULL)
|
||||
return;
|
||||
|
||||
// Get the PIDL for the folder.
|
||||
if (!SUCCEEDED(SHGetSpecialFolderLocation(
|
||||
NULL, folder, &pItemIDList)))
|
||||
goto Clean;
|
||||
|
||||
if (!SUCCEEDED(SHGetPathFromIDList(pItemIDList, pBuffer)))
|
||||
goto Clean;
|
||||
|
||||
// Append the trailing slash
|
||||
len = PL_strlen(pBuffer);
|
||||
pBuffer[len] = '\\';
|
||||
pBuffer[len + 1] = '\0';
|
||||
|
||||
// Assign the directory
|
||||
outDirectory = MakeUpperCase(pBuffer);
|
||||
|
||||
Clean:
|
||||
// Clean up.
|
||||
if (pItemIDList)
|
||||
pMalloc->Free(pItemIDList);
|
||||
if (pBuffer)
|
||||
pMalloc->Free(pBuffer);
|
||||
} // GetWindowsFolder
|
||||
#endif // XP_PC
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
static void GetCurrentWorkingDirectory(nsFileSpec& aFileSpec)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
aFileSpec = ".";
|
||||
return;
|
||||
} // GetCurrentWorkingDirectory
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
static void GetCurrentProcessDirectory(nsFileSpec& aFileSpec)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
#ifdef XP_PC
|
||||
char buf[MAX_PATH];
|
||||
if ( ::GetModuleFileName(0, buf, sizeof(buf)) ) {
|
||||
// chop of the executable name by finding the rightmost backslash
|
||||
char* lastSlash = PL_strrchr(buf, '\\');
|
||||
if (lastSlash)
|
||||
*(lastSlash + 1) = '\0';
|
||||
|
||||
aFileSpec = buf;
|
||||
return;
|
||||
}
|
||||
|
||||
#elif defined(XP_MAC)
|
||||
// get info for the the current process to determine the directory
|
||||
// its located in
|
||||
OSErr err;
|
||||
ProcessSerialNumber psn;
|
||||
if (!(err = GetCurrentProcess(&psn)))
|
||||
{
|
||||
ProcessInfoRec pInfo;
|
||||
FSSpec tempSpec;
|
||||
|
||||
// initialize ProcessInfoRec before calling
|
||||
// GetProcessInformation() or die horribly.
|
||||
pInfo.processName = nil;
|
||||
pInfo.processAppSpec = &tempSpec;
|
||||
pInfo.processInfoLength = sizeof(ProcessInfoRec);
|
||||
|
||||
if (!(err = GetProcessInformation(&psn, &pInfo)))
|
||||
{
|
||||
FSSpec appFSSpec = *(pInfo.processAppSpec);
|
||||
long theDirID = appFSSpec.parID;
|
||||
|
||||
Str255 name;
|
||||
CInfoPBRec catInfo;
|
||||
catInfo.dirInfo.ioCompletion = NULL;
|
||||
catInfo.dirInfo.ioNamePtr = (StringPtr)&name;
|
||||
catInfo.dirInfo.ioVRefNum = appFSSpec.vRefNum;
|
||||
catInfo.dirInfo.ioDrDirID = theDirID;
|
||||
catInfo.dirInfo.ioFDirIndex = -1; // -1 = query dir in ioDrDirID
|
||||
|
||||
if (!(err = PBGetCatInfoSync(&catInfo)))
|
||||
{
|
||||
aFileSpec = nsFileSpec(appFSSpec.vRefNum,
|
||||
catInfo.dirInfo.ioDrParID,
|
||||
name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(XP_UNIX)
|
||||
|
||||
// In the absence of a good way to get the executable directory let
|
||||
// us try this for unix:
|
||||
// - if MOZILLA_FIVE_HOME is defined, that is it
|
||||
// - else give the current directory
|
||||
char buf[MAXPATHLEN];
|
||||
char *moz5 = PR_GetEnv("MOZILLA_FIVE_HOME");
|
||||
if (moz5)
|
||||
{
|
||||
aFileSpec = moz5;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
static PRBool firstWarning = PR_TRUE;
|
||||
|
||||
if(firstWarning) {
|
||||
// Warn that MOZILLA_FIVE_HOME not set, once.
|
||||
printf("Warning: MOZILLA_FIVE_HOME not set.\n");
|
||||
firstWarning = PR_FALSE;
|
||||
}
|
||||
|
||||
// Fall back to current directory.
|
||||
if (getcwd(buf, sizeof(buf)))
|
||||
{
|
||||
aFileSpec = buf;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
NS_ERROR("unable to get current process directory");
|
||||
} // GetCurrentProcessDirectory()
|
||||
|
||||
//nsSpecialSystemDirectory::nsSpecialSystemDirectory()
|
||||
//: nsFileSpec(nsnull)
|
||||
//{
|
||||
//}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsSpecialSystemDirectory::nsSpecialSystemDirectory(SystemDirectories aSystemSystemDirectory)
|
||||
//----------------------------------------------------------------------------------------
|
||||
: nsFileSpec(nsnull)
|
||||
{
|
||||
*this = aSystemSystemDirectory;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsSpecialSystemDirectory::~nsSpecialSystemDirectory()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsSpecialSystemDirectory::operator = (SystemDirectories aSystemSystemDirectory)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
*this = (const char*)nsnull;
|
||||
switch (aSystemSystemDirectory)
|
||||
{
|
||||
|
||||
case OS_DriveDirectory:
|
||||
#ifdef XP_PC
|
||||
{
|
||||
char path[_MAX_PATH];
|
||||
PRInt32 len = GetWindowsDirectory( path, _MAX_PATH );
|
||||
if (len)
|
||||
{
|
||||
if ( path[1] == ':' && path[2] == '\\' )
|
||||
path[3] = 0;
|
||||
}
|
||||
*this = MakeUpperCase(path);
|
||||
}
|
||||
#elif defined(XP_MAC)
|
||||
{
|
||||
*this = kVolumeRootFolderType;
|
||||
}
|
||||
#else
|
||||
*this = "/";
|
||||
#endif
|
||||
break;
|
||||
|
||||
|
||||
case OS_TemporaryDirectory:
|
||||
#ifdef XP_PC
|
||||
{
|
||||
char path[_MAX_PATH];
|
||||
DWORD len = GetTempPath(_MAX_PATH, path);
|
||||
*this = MakeUpperCase(path);
|
||||
}
|
||||
#elif defined(XP_MAC)
|
||||
*this = kTemporaryFolderType;
|
||||
|
||||
#elif defined(XP_UNIX)
|
||||
*this = "/tmp/";
|
||||
#endif
|
||||
break;
|
||||
|
||||
case OS_CurrentProcessDirectory:
|
||||
GetCurrentProcessDirectory(*this);
|
||||
break;
|
||||
|
||||
case OS_CurrentWorkingDirectory:
|
||||
GetCurrentWorkingDirectory(*this);
|
||||
break;
|
||||
|
||||
#ifdef XP_MAC
|
||||
case Mac_SystemDirectory:
|
||||
*this = kSystemFolderType;
|
||||
break;
|
||||
|
||||
case Mac_DesktopDirectory:
|
||||
*this = kDesktopFolderType;
|
||||
break;
|
||||
|
||||
case Mac_TrashDirectory:
|
||||
*this = kTrashFolderType;
|
||||
break;
|
||||
|
||||
case Mac_StartupDirectory:
|
||||
*this = kStartupFolderType;
|
||||
break;
|
||||
|
||||
case Mac_ShutdownDirectory:
|
||||
*this = kShutdownFolderType;
|
||||
break;
|
||||
|
||||
case Mac_AppleMenuDirectory:
|
||||
*this = kAppleMenuFolderType;
|
||||
break;
|
||||
|
||||
case Mac_ControlPanelDirectory:
|
||||
*this = kControlPanelFolderType;
|
||||
break;
|
||||
|
||||
case Mac_ExtensionDirectory:
|
||||
*this = kExtensionFolderType;
|
||||
break;
|
||||
|
||||
case Mac_FontsDirectory:
|
||||
*this = kFontsFolderType;
|
||||
break;
|
||||
|
||||
case Mac_PreferencesDirectory:
|
||||
*this = kPreferencesFolderType;
|
||||
break;
|
||||
|
||||
case Mac_DocumentsDirectory:
|
||||
*this = kDocumentsFolderType;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef XP_PC
|
||||
case Win_SystemDirectory:
|
||||
{
|
||||
char path[_MAX_PATH];
|
||||
PRInt32 len = GetSystemDirectory( path, _MAX_PATH );
|
||||
|
||||
// Need enough space to add the trailing backslash
|
||||
if (len > _MAX_PATH-2)
|
||||
break;
|
||||
path[len] = '\\';
|
||||
path[len+1] = '\0';
|
||||
|
||||
*this = MakeUpperCase(path);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Win_WindowsDirectory:
|
||||
{
|
||||
char path[_MAX_PATH];
|
||||
PRInt32 len = GetWindowsDirectory( path, _MAX_PATH );
|
||||
|
||||
// Need enough space to add the trailing backslash
|
||||
if (len > _MAX_PATH-2)
|
||||
break;
|
||||
|
||||
path[len] = '\\';
|
||||
path[len+1] = '\0';
|
||||
|
||||
*this = MakeUpperCase(path);
|
||||
break;
|
||||
}
|
||||
|
||||
case Win_HomeDirectory:
|
||||
{
|
||||
char path[_MAX_PATH];
|
||||
if (GetEnvironmentVariable(TEXT("HOMEDRIVE"), path, _MAX_PATH) >= 0)
|
||||
{
|
||||
char temp[_MAX_PATH];
|
||||
if (GetEnvironmentVariable(TEXT("HOMEPATH"), temp, _MAX_PATH) > 0)
|
||||
PL_strcatn(path, _MAX_PATH, temp);
|
||||
|
||||
PRInt32 len = PL_strlen(path);
|
||||
|
||||
// Need enough space to add the trailing backslash
|
||||
if (len > _MAX_PATH - 2)
|
||||
break;
|
||||
|
||||
path[len] = '\\';
|
||||
path[len+1] = '\0';
|
||||
}
|
||||
|
||||
*this = MakeUpperCase(path);
|
||||
break;
|
||||
}
|
||||
case Win_Desktop:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_DESKTOP, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Programs:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_PROGRAMS, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Controls:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_CONTROLS, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Printers:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_PRINTERS, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Personal:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_PERSONAL, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Favorites:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_FAVORITES, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Startup:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_STARTUP, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Recent:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_RECENT, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Sendto:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_SENDTO, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Bitbucket:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_BITBUCKET, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Startmenu:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_STARTMENU, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Desktopdirectory:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_DESKTOPDIRECTORY, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Drives:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_DRIVES, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Network:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_NETWORK, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Nethood:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_NETHOOD, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Fonts:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_FONTS, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Templates:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_TEMPLATES, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Common_Startmenu:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_COMMON_STARTMENU, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Common_Programs:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_COMMON_PROGRAMS, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Common_Startup:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_COMMON_STARTUP, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Common_Desktopdirectory:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_COMMON_DESKTOPDIRECTORY, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Appdata:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_APPDATA, *this);
|
||||
break;
|
||||
}
|
||||
case Win_Printhood:
|
||||
{
|
||||
GetWindowsFolder(CSIDL_PRINTHOOD, *this);
|
||||
break;
|
||||
}
|
||||
#endif // XP_PC
|
||||
|
||||
#ifdef XP_UNIX
|
||||
case Unix_LocalDirectory:
|
||||
*this = "/usr/local/netscape/";
|
||||
break;
|
||||
|
||||
case Unix_LibDirectory:
|
||||
*this = "/usr/local/lib/netscape/";
|
||||
break;
|
||||
|
||||
case Unix_HomeDirectory:
|
||||
*this = PR_GetEnv("HOME");
|
||||
break;
|
||||
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef XP_MAC
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsSpecialSystemDirectory::nsSpecialSystemDirectory(OSType folderType)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
*this = folderType;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsSpecialSystemDirectory::operator = (OSType folderType)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
CInfoPBRec cinfo;
|
||||
DirInfo *dipb=(DirInfo *)&cinfo;
|
||||
|
||||
// Call FindFolder to fill in the vrefnum and dirid
|
||||
for (int attempts = 0; attempts < 2; attempts++)
|
||||
{
|
||||
mError = NS_FILE_RESULT(
|
||||
FindFolder(
|
||||
kOnSystemDisk,
|
||||
folderType,
|
||||
true,
|
||||
&dipb->ioVRefNum,
|
||||
&dipb->ioDrDirID));
|
||||
if (NS_SUCCEEDED(mError))
|
||||
break;
|
||||
if (attempts > 0)
|
||||
return;
|
||||
switch (folderType)
|
||||
{
|
||||
case kDocumentsFolderType:
|
||||
// Find folder will find this, as long as it exists.
|
||||
// The "create" parameter, however, is sadly ignored.
|
||||
// How do we internationalize this?
|
||||
*this = kVolumeRootFolderType;
|
||||
*this += "Documents";
|
||||
CreateDirectory();
|
||||
break;
|
||||
} // switch
|
||||
} // for
|
||||
StrFileName filename;
|
||||
filename[0] = '\0';
|
||||
dipb->ioNamePtr = (StringPtr)&filename;
|
||||
dipb->ioFDirIndex = -1;
|
||||
|
||||
mError = NS_FILE_RESULT(PBGetCatInfoSync(&cinfo));
|
||||
if (NS_SUCCEEDED(mError))
|
||||
{
|
||||
mError = NS_FILE_RESULT(FSMakeFSSpec(dipb->ioVRefNum, dipb->ioDrParID, filename, &mSpec));
|
||||
}
|
||||
}
|
||||
#endif // XP_MAC
|
||||
@@ -1,603 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/******************************************************************************************
|
||||
MODULE NOTES:
|
||||
|
||||
This file contains the nsStr data structure.
|
||||
This general purpose buffer management class is used as the basis for our strings.
|
||||
It's benefits include:
|
||||
1. An efficient set of library style functions for manipulating nsStrs
|
||||
2. Support for 1 and 2 byte character strings (which can easily be increased to n)
|
||||
3. Unicode awareness and interoperability.
|
||||
|
||||
*******************************************************************************************/
|
||||
|
||||
#include "nsStr.h"
|
||||
#include "bufferRoutines.h"
|
||||
#include "stdio.h" //only used for printf
|
||||
#include "nsDeque.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
|
||||
static const char* kFoolMsg = "Error: Some fool overwrote the shared buffer.";
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// The following is a memory agent who knows how to recycled (pool) freed memory...
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
/**************************************************************
|
||||
Define the char* (pooled) deallocator class...
|
||||
**************************************************************/
|
||||
class nsBufferDeallocator: public nsDequeFunctor{
|
||||
public:
|
||||
virtual void* operator()(void* anObject) {
|
||||
char* aCString= (char*)anObject;
|
||||
delete [] aCString;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
class nsPoolingMemoryAgent : public nsMemoryAgent{
|
||||
public:
|
||||
nsPoolingMemoryAgent() {
|
||||
memset(mPools,0,sizeof(mPools));
|
||||
}
|
||||
|
||||
virtual ~nsPoolingMemoryAgent() {
|
||||
nsBufferDeallocator theDeallocator;
|
||||
int i=0;
|
||||
for(i=0;i<10;i++){
|
||||
if(mPools[i]){
|
||||
mPools[i]->ForEach(theDeallocator); //now delete the buffers
|
||||
}
|
||||
delete mPools[i];
|
||||
mPools[i]=0;
|
||||
}
|
||||
}
|
||||
|
||||
virtual PRBool Alloc(nsStr& aDest,PRInt32 aCount) {
|
||||
|
||||
//we're given the acount value in charunits; we have to scale up by the charsize.
|
||||
int theShift=4;
|
||||
PRInt32 theNewCapacity=eDefaultSize;
|
||||
while(theNewCapacity<aCount){
|
||||
theNewCapacity<<=1;
|
||||
theShift++;
|
||||
}
|
||||
|
||||
aDest.mCapacity=theNewCapacity++;
|
||||
theShift=(theShift<<aDest.mCharSize)-4;
|
||||
if((theShift<12) && (mPools[theShift])){
|
||||
aDest.mStr=(char*)mPools[theShift]->Pop();
|
||||
}
|
||||
if(!aDest.mStr) {
|
||||
//we're given the acount value in charunits; we have to scale up by the charsize.
|
||||
size_t theSize=(theNewCapacity<<aDest.mCharSize);
|
||||
aDest.mStr=new char[theSize];
|
||||
}
|
||||
aDest.mOwnsBuffer=1;
|
||||
return PR_TRUE;
|
||||
|
||||
}
|
||||
|
||||
virtual PRBool Free(nsStr& aDest){
|
||||
if(aDest.mStr){
|
||||
if(aDest.mOwnsBuffer){
|
||||
int theShift=1;
|
||||
unsigned int theValue=1;
|
||||
while((theValue<<=1)<aDest.mCapacity){
|
||||
theShift++;
|
||||
}
|
||||
theShift-=4;
|
||||
if(theShift<12){
|
||||
if(!mPools[theShift]){
|
||||
mPools[theShift]=new nsDeque(0);
|
||||
}
|
||||
mPools[theShift]->Push(aDest.mStr);
|
||||
}
|
||||
else delete [] aDest.mStr; //it's too big. Just delete it.
|
||||
}
|
||||
aDest.mStr=0;
|
||||
aDest.mOwnsBuffer=0;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
nsDeque* mPools[16];
|
||||
};
|
||||
|
||||
static char* gCommonEmptyBuffer=0;
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
char* GetSharedEmptyBuffer() {
|
||||
if(!gCommonEmptyBuffer) {
|
||||
const size_t theDfltSize=5;
|
||||
gCommonEmptyBuffer=new char[theDfltSize];
|
||||
if(gCommonEmptyBuffer){
|
||||
nsCRT::zero(gCommonEmptyBuffer,theDfltSize);
|
||||
gCommonEmptyBuffer[0]=0;
|
||||
}
|
||||
else {
|
||||
printf("%s\n","Memory allocation error!");
|
||||
}
|
||||
}
|
||||
return gCommonEmptyBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) {
|
||||
aDest.mStr=GetSharedEmptyBuffer();
|
||||
aDest.mLength=0;
|
||||
aDest.mCapacity=0;
|
||||
aDest.mCharSize=aCharSize;
|
||||
aDest.mOwnsBuffer=0;
|
||||
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer){
|
||||
aDest.mStr=(aCString) ? aCString : GetSharedEmptyBuffer();
|
||||
aDest.mLength=aLength;
|
||||
aDest.mCapacity=aCapacity;
|
||||
aDest.mCharSize=aCharSize;
|
||||
aDest.mOwnsBuffer=aOwnsBuffer;
|
||||
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsIMemoryAgent* GetDefaultAgent(void){
|
||||
// static nsPoolingMemoryAgent gDefaultAgent;
|
||||
static nsMemoryAgent gDefaultAgent;
|
||||
return (nsIMemoryAgent*)&gDefaultAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
||||
if((aDest.mStr) && (aDest.mStr!=GetSharedEmptyBuffer())) {
|
||||
if(!anAgent)
|
||||
anAgent=GetDefaultAgent();
|
||||
|
||||
if(anAgent) {
|
||||
anAgent->Free(aDest);
|
||||
}
|
||||
else{
|
||||
printf("%s\n","Leak occured in nsStr.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called when the internal buffer needs
|
||||
* to grow to a given size. The original contents are not preserved.
|
||||
* @update gess 3/30/98
|
||||
* @param aNewLength -- new capacity of string in charSize units
|
||||
* @return void
|
||||
*/
|
||||
void nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
||||
if(aNewLength>aString.mCapacity) {
|
||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
||||
theAgent->Realloc(aString,aNewLength);
|
||||
AddNullTerminator(aString);
|
||||
}
|
||||
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when the internal buffer needs
|
||||
* to grow to a given size. The original contents ARE preserved.
|
||||
* @update gess 3/30/98
|
||||
* @param aNewLength -- new capacity of string in charSize units
|
||||
* @return void
|
||||
*/
|
||||
void nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
||||
if(aNewLength>aDest.mCapacity) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,(eCharSize)aDest.mCharSize);
|
||||
|
||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
||||
EnsureCapacity(theTempStr,aNewLength,theAgent);
|
||||
|
||||
if(aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,theAgent);
|
||||
}
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||
aDest.mLength=theTempStr.mLength;
|
||||
aDest.mCapacity=theTempStr.mCapacity;
|
||||
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
|
||||
}
|
||||
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the contents of aDest with aSource, up to aCount of chars.
|
||||
* @update gess10/30/98
|
||||
* @param aDest is the nsStr that gets changed.
|
||||
* @param aSource is where chars are copied from
|
||||
* @param aCount is the number of chars copied from aSource
|
||||
*/
|
||||
void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
|
||||
Truncate(aDest,0,anAgent);
|
||||
Append(aDest,aSource,anOffset,aCount,anAgent);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method appends the given nsStr to this one. Note that we have to
|
||||
* pay attention to the underlying char-size of both structs.
|
||||
* @update gess10/30/98
|
||||
* @param aDest is the nsStr to be manipulated
|
||||
* @param aSource is where char are copied from
|
||||
* @aCount is the number of bytes to be copied
|
||||
*/
|
||||
void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
|
||||
if(anOffset<aSource.mLength){
|
||||
PRUint32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||
PRUint32 theLength=(anOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-anOffset);
|
||||
if(0<theLength){
|
||||
if(aDest.mLength+theLength > aDest.mCapacity) {
|
||||
GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
}
|
||||
|
||||
//now append new chars, starting at offset
|
||||
(*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDest.mLength,aSource.mStr,anOffset,theLength);
|
||||
|
||||
aDest.mLength+=theLength;
|
||||
}
|
||||
}
|
||||
AddNullTerminator(aDest);
|
||||
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method inserts up to "aCount" chars from a source nsStr into a dest nsStr.
|
||||
* @update gess10/30/98
|
||||
* @param aDest is the nsStr that gets changed
|
||||
* @param aDestOffset is where in aDest the insertion is to occur
|
||||
* @param aSource is where chars are copied from
|
||||
* @param aSrcOffset is where in aSource chars are copied from
|
||||
* @param aCount is the number of chars from aSource to be inserted into aDest
|
||||
*/
|
||||
void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
|
||||
//there are a few cases for insert:
|
||||
// 1. You're inserting chars into an empty string (assign)
|
||||
// 2. You're inserting onto the end of a string (append)
|
||||
// 3. You're inserting onto the 1..n-1 pos of a string (the hard case).
|
||||
if(0<aSource.mLength){
|
||||
if(aDest.mLength){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
PRInt32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||
PRInt32 theLength=(aSrcOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-aSrcOffset);
|
||||
|
||||
if(aSrcOffset<aSource.mLength) {
|
||||
//here's the only new case we have to handle.
|
||||
//chars are really being inserted into our buffer...
|
||||
GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
|
||||
//shift the chars right by theDelta...
|
||||
(*gShiftChars[aDest.mCharSize][PR_TRUE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
|
||||
//now insert new chars, starting at offset
|
||||
(*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength);
|
||||
|
||||
//finally, make sure to update the string length...
|
||||
aDest.mLength+=theLength;
|
||||
AddNullTerminator(aDest);
|
||||
|
||||
}//if
|
||||
//else nothing to do!
|
||||
}
|
||||
else Append(aDest,aSource,0,aCount,anAgent);
|
||||
}
|
||||
else Append(aDest,aSource,0,aCount,anAgent);
|
||||
}
|
||||
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method deletes up to aCount chars from aDest
|
||||
* @update gess10/30/98
|
||||
* @param aDest is the nsStr to be manipulated
|
||||
* @param aDestOffset is where in aDest deletion is to occur
|
||||
* @param aCount is the number of chars to be deleted in aDest
|
||||
*/
|
||||
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
|
||||
PRUint32 theDelta=aDest.mLength-aDestOffset;
|
||||
PRUint32 theLength=(theDelta<aCount) ? theDelta : aCount;
|
||||
|
||||
if(aDestOffset+theLength<aDest.mLength) {
|
||||
|
||||
//if you're here, it means we're cutting chars out of the middle of the string...
|
||||
//so shift the chars left by theLength...
|
||||
(*gShiftChars[aDest.mCharSize][PR_FALSE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
aDest.mLength-=theLength;
|
||||
}
|
||||
else Truncate(aDest,aDestOffset,anAgent);
|
||||
}//if
|
||||
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method truncates the given nsStr at given offset
|
||||
* @update gess10/30/98
|
||||
* @param aDest is the nsStr to be truncated
|
||||
* @param aDestOffset is where in aDest truncation is to occur
|
||||
*/
|
||||
void nsStr::Truncate(nsStr& aDest,PRUint32 aDestOffset,nsIMemoryAgent* anAgent){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
aDest.mLength=aDestOffset;
|
||||
AddNullTerminator(aDest);
|
||||
}
|
||||
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess1/7/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) {
|
||||
// somehow UnicharUtil return failed, fallback to the old ascii only code
|
||||
gCaseConverters[aDest.mCharSize](aDest.mStr,aDest.mLength,aToUpper);
|
||||
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess1/7/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsStr::StripChars(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,const char* aCharSet){
|
||||
PRUint32 aNewLen=gStripChars[aDest.mCharSize](aDest.mStr,aDestOffset,aCount,aCharSet);
|
||||
aDest.mLength=aNewLen;
|
||||
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess1/7/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
PRUint32 aNewLen=gTrimChars[aDest.mCharSize](aDest.mStr,aDest.mLength,aSet,aEliminateLeading,aEliminateTrailing);
|
||||
aDest.mLength=aNewLen;
|
||||
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess1/7/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
PRUint32 aNewLen=gCompressChars[aDest.mCharSize](aDest.mStr,aDest.mLength,aSet,aChar,aEliminateLeading,aEliminateTrailing);
|
||||
aDest.mLength=aNewLen;
|
||||
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
/**************************************************************
|
||||
Searching methods...
|
||||
**************************************************************/
|
||||
|
||||
|
||||
PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 index=anOffset-1;
|
||||
PRInt32 theMax=aDest.mLength-aTarget.mLength;
|
||||
if((aDest.mLength>0) && (aTarget.mLength>0)){
|
||||
PRInt32 theNewStartPos=-1;
|
||||
PRUnichar theFirstTargetChar=GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRInt32 theTargetMax=aTarget.mLength;
|
||||
while(++index<=theMax) {
|
||||
PRInt32 theSubIndex=-1;
|
||||
PRBool matches=PR_TRUE;
|
||||
while((++theSubIndex<theTargetMax) && (matches)){
|
||||
PRUnichar theChar=GetCharAt(aDest,index+theSubIndex);
|
||||
if(theSubIndex>0) {
|
||||
if(theFirstTargetChar==theChar){
|
||||
PRUnichar theDestJumpChar=GetCharAt(aDest,index+theTargetMax);
|
||||
if(theDestJumpChar==theLastTargetChar) {
|
||||
theNewStartPos=index; //this lets us jump ahead during our search where possible.
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
PRUnichar theTargetChar=GetCharAt(aTarget,theSubIndex);
|
||||
matches=PRBool(theChar==theTargetChar);
|
||||
}
|
||||
if(matches)
|
||||
return index;
|
||||
if(-1<theNewStartPos){
|
||||
index=theNewStartPos-1;
|
||||
}
|
||||
}
|
||||
}//if
|
||||
return kNotFound;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess1/7/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRUint32 index=anOffset-1;
|
||||
PRInt32 thePos;
|
||||
|
||||
while(++index<aDest.mLength) {
|
||||
PRUnichar theChar=GetCharAt(aDest,index);
|
||||
thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,anOffset,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return index;
|
||||
} //while
|
||||
return kNotFound;
|
||||
}
|
||||
|
||||
/**************************************************************
|
||||
Reverse Searching methods...
|
||||
**************************************************************/
|
||||
|
||||
|
||||
PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 index=(anOffset ? anOffset : aDest.mLength-aTarget.mLength+1);
|
||||
if((aDest.mLength>0) && (aTarget.mLength>0)){
|
||||
PRInt32 theNewStartPos=-1;
|
||||
PRUnichar theFirstTargetChar=GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRInt32 theTargetMax=aTarget.mLength;
|
||||
|
||||
while(index--) {
|
||||
PRInt32 theSubIndex=-1;
|
||||
PRBool matches=PR_TRUE;
|
||||
|
||||
if(anOffset+aTarget.mLength<=aDest.mLength) {
|
||||
while((++theSubIndex<theTargetMax) && (matches)){
|
||||
PRUnichar theChar=GetCharAt(aDest,index+theSubIndex);
|
||||
if(theSubIndex>0) {
|
||||
if(theFirstTargetChar==theChar){
|
||||
PRUnichar theDestJumpChar=GetCharAt(aDest,index+theTargetMax);
|
||||
if(theDestJumpChar==theLastTargetChar) {
|
||||
theNewStartPos=index; //this lets us jump ahead during our search where possible.
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
PRUnichar theTargetChar=GetCharAt(aTarget,theSubIndex);
|
||||
matches=PRBool(theChar==theTargetChar);
|
||||
} //while
|
||||
} //if
|
||||
if(matches)
|
||||
return index;
|
||||
if(-1<theNewStartPos){
|
||||
index=theNewStartPos-1;
|
||||
}
|
||||
}
|
||||
}//if
|
||||
return kNotFound;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess1/7/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gRFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRUint32 offset=aDest.mLength-anOffset;
|
||||
PRInt32 thePos;
|
||||
|
||||
while(--offset>=0) {
|
||||
PRUnichar theChar=GetCharAt(aDest,offset);
|
||||
thePos=gRFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,anOffset,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return offset;
|
||||
} //while
|
||||
return kNotFound;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess11/12/98
|
||||
* @param
|
||||
* @return aDest<aSource=-1;aDest==aSource==0;aDest>aSource=1
|
||||
*/
|
||||
PRInt32 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) {
|
||||
int minlen=(aSource.mLength<aDest.mLength) ? aSource.mLength : aDest.mLength;
|
||||
|
||||
if(0==minlen) {
|
||||
if ((aDest.mLength == 0) && (aSource.mLength == 0))
|
||||
return 0;
|
||||
if (aDest.mLength == 0)
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int maxlen=(aSource.mLength<aDest.mLength) ? aDest.mLength : aSource.mLength;
|
||||
PRInt32 result=(*gCompare[aDest.mCharSize][aSource.mCharSize])(aDest.mStr,aSource.mStr,maxlen,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,333 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
MODULE NOTES:
|
||||
|
||||
1. There are two philosophies to building string classes:
|
||||
A. Hide the underlying buffer & offer API's allow indirect iteration
|
||||
B. Reveal underlying buffer, risk corruption, but gain performance
|
||||
|
||||
We chose the option B for performance reasons.
|
||||
|
||||
2 Our internal buffer always holds capacity+1 bytes.
|
||||
|
||||
The nsStr struct is a simple structure (no methods) that contains
|
||||
the necessary info to be described as a string. This simple struct
|
||||
is manipulated by the static methods provided in this class.
|
||||
(Which effectively makes this a library that works on structs).
|
||||
|
||||
There are also object-based versions called nsString and nsAutoString
|
||||
which use nsStr but makes it look at feel like an object.
|
||||
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _nsStr
|
||||
#define _nsStr
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
enum eCharSize {eOneByte=0,eTwoByte=1};
|
||||
#define kDefaultCharSize eTwoByte
|
||||
const PRInt32 kNotFound = -1;
|
||||
|
||||
|
||||
class nsIMemoryAgent;
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
struct nsStr {
|
||||
|
||||
/**
|
||||
* This method initializes an nsStr for use
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the nsStr to be initialized
|
||||
* @param aCharSize tells us the requested char size (1 or 2 bytes)
|
||||
*/
|
||||
static void Initialize(nsStr& aDest,eCharSize aCharSize);
|
||||
|
||||
/**
|
||||
* This method initializes an nsStr for use
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the nsStr to be initialized
|
||||
* @param aCharSize tells us the requested char size (1 or 2 bytes)
|
||||
*/
|
||||
static void Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer);
|
||||
|
||||
/**
|
||||
* This method destroys the given nsStr, and *MAY*
|
||||
* deallocate it's memory depending on the setting
|
||||
* of the internal mOwnsBUffer flag.
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the nsStr to be manipulated
|
||||
* @param anAgent is the allocator to be used to the nsStr
|
||||
*/
|
||||
static void Destroy(nsStr& aDest,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* These methods are where memory allocation/reallocation occur.
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the nsStr to be manipulated
|
||||
* @param anAgent is the allocator to be used on the nsStr
|
||||
* @return
|
||||
*/
|
||||
static void EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
||||
static void GrowCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* These methods are used to append content to the given nsStr
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be appended to
|
||||
* @param aSource is the buffer to be copied from
|
||||
* @param anOffset tells us where in source to start copying
|
||||
* @param aCount tells us the (max) # of chars to copy
|
||||
* @param anAgent is the allocator to be used for alloc/free operations
|
||||
*/
|
||||
static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* These methods are used to assign contents of a source string to dest string
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be appended to
|
||||
* @param aSource is the buffer to be copied from
|
||||
* @param anOffset tells us where in source to start copying
|
||||
* @param aCount tells us the (max) # of chars to copy
|
||||
* @param anAgent is the allocator to be used for alloc/free operations
|
||||
*/
|
||||
static void Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* These methods are used to insert content from source string to the dest nsStr
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be appended to
|
||||
* @param aDestOffset tells us where in dest to start insertion
|
||||
* @param aSource is the buffer to be copied from
|
||||
* @param aSrcOffset tells us where in source to start copying
|
||||
* @param aCount tells us the (max) # of chars to insert
|
||||
* @param anAgent is the allocator to be used for alloc/free operations
|
||||
*/
|
||||
static void Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* This method deletes chars from the given str.
|
||||
* The given allocator may choose to resize the str as well.
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be deleted from
|
||||
* @param aDestOffset tells us where in dest to start deleting
|
||||
* @param aCount tells us the (max) # of chars to delete
|
||||
* @param anAgent is the allocator to be used for alloc/free operations
|
||||
*/
|
||||
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* This method is used to truncate the given string.
|
||||
* The given allocator may choose to resize the str as well (but it's not likely).
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be appended to
|
||||
* @param aDestOffset tells us where in dest to start insertion
|
||||
* @param aSource is the buffer to be copied from
|
||||
* @param aSrcOffset tells us where in source to start copying
|
||||
* @param anAgent is the allocator to be used for alloc/free operations
|
||||
*/
|
||||
static void Truncate(nsStr& aDest,PRUint32 aDestOffset,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* This method is used to perform a case conversion on the given string
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be case shifted
|
||||
* @param toUpper tells us to go upper vs. lower
|
||||
*/
|
||||
static void ChangeCase(nsStr& aDest,PRBool aToUpper);
|
||||
|
||||
/**
|
||||
* This method removes chars (given in aSet) from the given buffer
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the buffer to be manipulated
|
||||
* @param aDestOffset is starting pos in buffer for manipulation
|
||||
* @param aCount is the number of chars to compare
|
||||
* @param aSet tells us which chars to remove from given buffer
|
||||
*/
|
||||
static void StripChars(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,const char* aCharSet);
|
||||
|
||||
/**
|
||||
* This method trims chars (given in aSet) from the edges of given buffer
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the buffer to be manipulated
|
||||
* @param aSet tells us which chars to remove from given buffer
|
||||
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
|
||||
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
|
||||
*/
|
||||
static void Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing);
|
||||
|
||||
/**
|
||||
* This method compresses duplicate runs of a given char from the given buffer
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the buffer to be manipulated
|
||||
* @param aSet tells us which chars to compress from given buffer
|
||||
* @param aChar is the replacement char
|
||||
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
|
||||
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
|
||||
*/
|
||||
static void CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing);
|
||||
|
||||
/**
|
||||
* This method compares the data bewteen two nsStr's
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aStr1 is the first buffer to be compared
|
||||
* @param aStr2 is the 2nd buffer to be compared
|
||||
* @param aCount is the number of chars to compare
|
||||
* @param aIgnorecase tells us whether to use a case-sensitive comparison
|
||||
* @return -1,0,1 depending on <,==,>
|
||||
*/
|
||||
static PRInt32 Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase);
|
||||
|
||||
/**
|
||||
* These methods scan the given string for 1 or more chars in a given direction
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be searched to
|
||||
* @param aSource (or aChar) is the substr we're looking to find
|
||||
* @param aIgnoreCase tells us whether to search in a case-sensitive manner
|
||||
* @param anOffset tells us where in the dest string to start searching
|
||||
* @return the index of the source (substr) in dest, or -1 (kNotFound) if not found.
|
||||
*/
|
||||
static PRInt32 FindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRUint32 anOffset);
|
||||
static PRInt32 FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset);
|
||||
static PRInt32 FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset);
|
||||
|
||||
static PRInt32 RFindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRUint32 anOffset);
|
||||
static PRInt32 RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset);
|
||||
static PRInt32 RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset);
|
||||
|
||||
|
||||
PRUint32 mLength;
|
||||
PRUint32 mCapacity;
|
||||
eCharSize mCharSize;
|
||||
PRBool mOwnsBuffer;
|
||||
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
};
|
||||
};
|
||||
|
||||
/**************************************************************
|
||||
A couple of tiny helper methods used in the string classes.
|
||||
**************************************************************/
|
||||
|
||||
inline PRInt32 MinInt(PRInt32 anInt1,PRInt32 anInt2){
|
||||
return (anInt1<anInt2) ? anInt1 : anInt2;
|
||||
}
|
||||
|
||||
inline PRInt32 MaxInt(PRInt32 anInt1,PRInt32 anInt2){
|
||||
return (anInt1<anInt2) ? anInt2 : anInt1;
|
||||
}
|
||||
|
||||
inline void AddNullTerminator(nsStr& aDest) {
|
||||
if(eTwoByte==aDest.mCharSize)
|
||||
aDest.mUStr[aDest.mLength]=0;
|
||||
else aDest.mStr[aDest.mLength]=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to access a given char in the given string
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be appended to
|
||||
* @param anIndex tells us where in dest to get the char from
|
||||
* @return the given char, or 0 if anIndex is out of range
|
||||
*/
|
||||
inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex){
|
||||
if(anIndex<aDest.mLength) {
|
||||
return (eTwoByte==aDest.mCharSize) ? aDest.mUStr[anIndex] : aDest.mStr[anIndex];
|
||||
}//if
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
class nsIMemoryAgent {
|
||||
public:
|
||||
virtual PRBool Alloc(nsStr& aString,PRUint32 aCount)=0;
|
||||
virtual PRBool Realloc(nsStr& aString,PRUint32 aCount)=0;
|
||||
virtual PRBool Free(nsStr& aString)=0;
|
||||
};
|
||||
|
||||
class nsMemoryAgent : public nsIMemoryAgent {
|
||||
protected:
|
||||
enum eDelta{eDefaultSize=16};
|
||||
public:
|
||||
|
||||
virtual PRBool Alloc(nsStr& aDest,PRUint32 aCount) {
|
||||
|
||||
//we're given the acount value in charunits; now scale up to next multiple.
|
||||
PRUint32 theNewCapacity=eDefaultSize;
|
||||
while(theNewCapacity<aCount){
|
||||
theNewCapacity<<=1;
|
||||
}
|
||||
|
||||
aDest.mCapacity=theNewCapacity++;
|
||||
size_t theSize=(theNewCapacity<<aDest.mCharSize);
|
||||
aDest.mStr=new char[theSize];
|
||||
aDest.mOwnsBuffer=1;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
virtual PRBool Free(nsStr& aDest){
|
||||
if(aDest.mStr){
|
||||
if(aDest.mOwnsBuffer){
|
||||
delete [] aDest.mStr;
|
||||
}
|
||||
aDest.mStr=0;
|
||||
aDest.mOwnsBuffer=0;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
virtual PRBool Realloc(nsStr& aDest,PRUint32 aCount){
|
||||
Free(aDest);
|
||||
return Alloc(aDest,aCount);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
char* GetSharedEmptyBuffer();
|
||||
nsIMemoryAgent* GetDefaultAgent(void);
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -30,8 +30,8 @@
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _nsString1
|
||||
#define _nsString1
|
||||
#ifndef _NSSTRING
|
||||
#define _NSSTRING
|
||||
|
||||
|
||||
#include "prtypes.h"
|
||||
@@ -39,18 +39,9 @@
|
||||
#include "nsIAtom.h"
|
||||
#include <iostream.h>
|
||||
#include <stdio.h>
|
||||
#include "nsStr.h"
|
||||
|
||||
#ifndef USE_STRING2
|
||||
#define nsString1 nsString
|
||||
#define nsAutoString1 nsAutoString
|
||||
#else
|
||||
#include "nsString2.h" //get new string class
|
||||
#endif
|
||||
|
||||
class nsISizeOfHandler;
|
||||
|
||||
class NS_BASE nsString1 {
|
||||
class NS_BASE nsString {
|
||||
public:
|
||||
|
||||
/**
|
||||
@@ -59,30 +50,30 @@ class NS_BASE nsString1 {
|
||||
* was to allow developers direct access to the underlying buffer for
|
||||
* performance reasons.
|
||||
*/
|
||||
nsString1();
|
||||
nsString();
|
||||
|
||||
/**
|
||||
* This constructor accepts an isolatin string
|
||||
* @param an ascii is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsString1(const char* aCString);
|
||||
nsString(const char* aCString);
|
||||
|
||||
/**
|
||||
* This is our copy constructor
|
||||
* @param reference to another nsString1
|
||||
* @param reference to another nsString
|
||||
*/
|
||||
nsString1(const nsString1&);
|
||||
nsString(const nsString&);
|
||||
|
||||
/**
|
||||
* Constructor from a unicode string
|
||||
* @param anicodestr pts to a unicode string
|
||||
*/
|
||||
nsString1(const PRUnichar* aUnicode);
|
||||
nsString(const PRUnichar* aUnicode);
|
||||
|
||||
/**
|
||||
* Virtual Destructor
|
||||
*/
|
||||
virtual ~nsString1();
|
||||
virtual ~nsString();
|
||||
|
||||
|
||||
/**
|
||||
@@ -145,14 +136,14 @@ const PRUnichar* GetUnicode(void) const;
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
operator const PRUnichar*() const;
|
||||
operator PRUnichar*() const;
|
||||
|
||||
/**
|
||||
* Retrieve unicode char at given index
|
||||
* @param offset into string
|
||||
* @return PRUnichar* to internal string
|
||||
*/
|
||||
//PRUnichar operator()(PRInt32 anIndex) const;
|
||||
PRUnichar operator()(PRInt32 anIndex) const;
|
||||
|
||||
/**
|
||||
* Retrieve reference to unicode char at given index
|
||||
@@ -180,9 +171,6 @@ PRUnichar& First() const;
|
||||
*/
|
||||
PRUnichar& Last() const;
|
||||
|
||||
PRBool SetCharAt(PRUnichar aChar,PRInt32 anIndex);
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
String creation methods...
|
||||
*********************************************************************/
|
||||
@@ -192,35 +180,35 @@ PRBool SetCharAt(PRUnichar aChar,PRInt32 anIndex);
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString1 operator+(const nsString1& aString);
|
||||
nsString operator+(const nsString& aString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given buffer.
|
||||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString1 operator+(const char* aCString);
|
||||
nsString operator+(const char* aCString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString1 operator+(char aChar);
|
||||
nsString operator+(char aChar);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given buffer.
|
||||
* @param aStr unichar buffer to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString1 operator+(const PRUnichar* aBuffer);
|
||||
nsString operator+(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString1 operator+(PRUnichar aChar);
|
||||
nsString operator+(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Converts all chars in internal string to lower
|
||||
@@ -230,7 +218,7 @@ void ToLowerCase();
|
||||
/**
|
||||
* Converts all chars in given string to lower
|
||||
*/
|
||||
void ToLowerCase(nsString1& aString) const;
|
||||
void ToLowerCase(nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Converts all chars in given string to upper
|
||||
@@ -246,13 +234,13 @@ void ToUCS2(PRInt32 aStartOffset);
|
||||
/**
|
||||
* Converts all chars in internal string to upper
|
||||
*/
|
||||
void ToUpperCase(nsString1& aString) const;
|
||||
void ToUpperCase(nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Creates a duplicate clone (ptr) of this string.
|
||||
* @return ptr to clone of this string
|
||||
*/
|
||||
nsString1* ToNewString() const;
|
||||
nsString* ToNewString() const;
|
||||
|
||||
/**
|
||||
* Creates an ascii clone of this string
|
||||
@@ -274,7 +262,7 @@ char* ToCString(char* aBuf,PRInt32 aBufLength) const;
|
||||
* @param aString to hold copy of this
|
||||
* @return nada.
|
||||
*/
|
||||
void Copy(nsString1& aString) const;
|
||||
void Copy(nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Creates an unichar clone of this string
|
||||
@@ -307,72 +295,79 @@ PRInt32 ToInteger(PRInt32* aErrorCode,PRInt32 aRadix=10) const;
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const nsString1& aString);
|
||||
nsString& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* assign given char* to this string
|
||||
* @param aCString: buffer to be assigned to this
|
||||
* @param alength is the length of the given str (or -1)
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& SetString(const char* aCString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* assign given string to this one
|
||||
* @param aString: string to be added to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(const nsString1& aString);
|
||||
nsString& operator=(const nsString& aString);
|
||||
|
||||
/**
|
||||
* assign given char* to this string
|
||||
* @param aCString: buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(const char* aCString);
|
||||
nsString& operator=(const char* aCString);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(char aChar);
|
||||
nsString& operator=(char aChar);
|
||||
|
||||
/**
|
||||
* assign given unichar* to this string
|
||||
* @param aBuffer: unichar buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(const PRUnichar* aBuffer);
|
||||
nsString& operator=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(PRUnichar aChar);
|
||||
nsString& operator=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(const nsString1& aString);
|
||||
nsString& operator+=(const nsString& aString);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param aCString: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(const char* aCString);
|
||||
nsString& operator+=(const char* aCString);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param aBuffer: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(const PRUnichar* aBuffer);
|
||||
nsString& operator+=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* append given char to this string
|
||||
* @param aChar: char to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(PRUnichar aChar);
|
||||
nsString& operator+=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
@@ -381,7 +376,7 @@ nsString1& operator+=(PRUnichar aChar);
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(const nsString1& aString,PRInt32 aLength=-1);
|
||||
nsString& Append(const nsString& aString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
@@ -390,14 +385,14 @@ nsString1& Append(const nsString1& aString,PRInt32 aLength=-1);
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString& Append(const char* aCString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(char aChar);
|
||||
nsString& Append(char aChar);
|
||||
|
||||
/**
|
||||
* append given unichar buffer to this string
|
||||
@@ -406,14 +401,14 @@ nsString1& Append(char aChar);
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(const PRUnichar* aBuffer,PRInt32 aLength=-1);
|
||||
nsString& Append(const PRUnichar* aBuffer,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given unichar character to this string
|
||||
* @param aChar is the char to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(PRUnichar aChar);
|
||||
nsString& Append(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Append an integer onto this string
|
||||
@@ -421,14 +416,14 @@ nsString1& Append(PRUnichar aChar);
|
||||
* @param aRadix specifies 8,10,16
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(PRInt32 aInteger,PRInt32 aRadix); //radix=8,10 or 16
|
||||
nsString& Append(PRInt32 aInteger,PRInt32 aRadix); //radix=8,10 or 16
|
||||
|
||||
/**
|
||||
* Append a float value onto this string
|
||||
* @param aFloat is the float to be appended
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(float aFloat);
|
||||
nsString& Append(float aFloat);
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
@@ -439,7 +434,7 @@ nsString1& Append(float aFloat);
|
||||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Left(nsString1& aCopy,PRInt32 aCount) const;
|
||||
PRInt32 Left(nsString& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
@@ -451,7 +446,7 @@ PRInt32 Left(nsString1& aCopy,PRInt32 aCount) const;
|
||||
* @param anOffset -- position where copying begins
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Mid(nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
PRInt32 Mid(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
@@ -462,7 +457,7 @@ PRInt32 Mid(nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Right(nsString1& aCopy,PRInt32 aCount) const;
|
||||
PRInt32 Right(nsString& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* This method inserts n chars from given string into this
|
||||
@@ -473,7 +468,7 @@ PRInt32 Right(nsString1& aCopy,PRInt32 aCount) const;
|
||||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
PRInt32 Insert(const nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
PRInt32 Insert(const nsString& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a single unicode char into this string at
|
||||
@@ -493,7 +488,7 @@ PRInt32 Insert(PRUnichar aChar,PRInt32 anOffset);
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
nsString1& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
nsString& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
|
||||
/**
|
||||
* This method is used to remove all occurances of the
|
||||
@@ -502,23 +497,14 @@ nsString1& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
* @param aSet -- characters to be cut from this
|
||||
* @return *this
|
||||
*/
|
||||
nsString1& StripChars(const char* aSet);
|
||||
|
||||
/**
|
||||
* This method is used to replace all occurances of the
|
||||
* given source char with the given dest char
|
||||
*
|
||||
* @param
|
||||
* @return *this
|
||||
*/
|
||||
nsString1& ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar);
|
||||
nsString& StripChars(const char* aSet);
|
||||
|
||||
/**
|
||||
* This method strips whitespace throughout the string
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
nsString1& StripWhitespace();
|
||||
nsString& StripWhitespace();
|
||||
|
||||
/**
|
||||
* This method trims characters found in aTrimSet from
|
||||
@@ -528,7 +514,7 @@ nsString1& StripWhitespace();
|
||||
* both ends
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Trim(const char* aSet,
|
||||
nsString& Trim(const char* aSet,
|
||||
PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
@@ -541,7 +527,7 @@ nsString1& Trim(const char* aSet,
|
||||
* @param aEliminateTrailing controls stripping of trailing ws
|
||||
* @return this
|
||||
*/
|
||||
nsString1& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**
|
||||
@@ -590,7 +576,7 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
|
||||
*/
|
||||
PRInt32 Find(const char* aString) const;
|
||||
PRInt32 Find(const PRUnichar* aString) const;
|
||||
PRInt32 Find(const nsString1& aString) const;
|
||||
PRInt32 Find(const nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Search for given char within this string
|
||||
@@ -608,7 +594,7 @@ PRInt32 Find(PRUnichar aChar,PRInt32 offset=0) const;
|
||||
* @return -1 if not found, else the offset in this
|
||||
*/
|
||||
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 FindCharInSet(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 FindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
/**
|
||||
* This method searches this string for the last character
|
||||
@@ -618,7 +604,7 @@ PRInt32 FindCharInSet(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
* @return -1 if not found, else the offset in this
|
||||
*/
|
||||
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 RFindCharInSet(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 RFindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
|
||||
/**
|
||||
@@ -629,7 +615,7 @@ PRInt32 RFindCharInSet(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
*/
|
||||
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const nsString1& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
|
||||
/**
|
||||
* This methods scans the string backwards, looking for the given char
|
||||
@@ -650,7 +636,7 @@ PRInt32 RFind(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
* @param aIgnoreCase tells us how to treat case
|
||||
* @return -1,0,1
|
||||
*/
|
||||
virtual PRInt32 Compare(const nsString1 &aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
virtual PRInt32 Compare(const nsString &aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
virtual PRInt32 Compare(const char *aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
|
||||
virtual PRInt32 Compare(const PRUnichar *aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
|
||||
|
||||
@@ -659,17 +645,16 @@ virtual PRInt32 Compare(const PRUnichar *aString,PRBool aIgnoreCase=PR_FALSE,PRI
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator==(const nsString1 &aString) const;
|
||||
PRBool operator==(const nsString &aString) const;
|
||||
PRBool operator==(const char *aString) const;
|
||||
PRBool operator==(const PRUnichar* aString) const;
|
||||
PRBool operator==(PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods perform a !compare of a given string type to this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE
|
||||
*/
|
||||
PRBool operator!=(const nsString1 &aString) const;
|
||||
PRBool operator!=(const nsString &aString) const;
|
||||
PRBool operator!=(const char *aString) const;
|
||||
PRBool operator!=(const PRUnichar* aString) const;
|
||||
|
||||
@@ -678,7 +663,7 @@ PRBool operator!=(const PRUnichar* aString) const;
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator<(const nsString1 &aString) const;
|
||||
PRBool operator<(const nsString &aString) const;
|
||||
PRBool operator<(const char *aString) const;
|
||||
PRBool operator<(const PRUnichar* aString) const;
|
||||
|
||||
@@ -687,7 +672,7 @@ PRBool operator<(const PRUnichar* aString) const;
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator>(const nsString1 &S) const;
|
||||
PRBool operator>(const nsString &S) const;
|
||||
PRBool operator>(const char *aCString) const;
|
||||
PRBool operator>(const PRUnichar* aString) const;
|
||||
|
||||
@@ -696,7 +681,7 @@ PRBool operator>(const PRUnichar* aString) const;
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator<=(const nsString1 &S) const;
|
||||
PRBool operator<=(const nsString &S) const;
|
||||
PRBool operator<=(const char *aCString) const;
|
||||
PRBool operator<=(const PRUnichar* aString) const;
|
||||
|
||||
@@ -705,7 +690,7 @@ PRBool operator<=(const PRUnichar* aString) const;
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator>=(const nsString1 &S) const;
|
||||
PRBool operator>=(const nsString &S) const;
|
||||
PRBool operator>=(const char* aCString) const;
|
||||
PRBool operator>=(const PRUnichar* aString) const;
|
||||
|
||||
@@ -719,7 +704,7 @@ PRBool operator>=(const PRUnichar* aString) const;
|
||||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool Equals(const nsString1& aString) const;
|
||||
PRBool Equals(const nsString& aString) const;
|
||||
PRBool Equals(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool Equals(const nsIAtom *aAtom) const;
|
||||
|
||||
@@ -742,7 +727,7 @@ PRBool Equals(const PRUnichar* s1, const PRUnichar* s2) const;
|
||||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool EqualsIgnoreCase(const nsString1& aString) const;
|
||||
PRBool EqualsIgnoreCase(const nsString& aString) const;
|
||||
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
|
||||
|
||||
@@ -765,39 +750,36 @@ typedef PRUnichar chartype;
|
||||
chartype* mStr;
|
||||
PRInt32 mLength;
|
||||
PRInt32 mCapacity;
|
||||
#ifdef RICKG_DEBUG
|
||||
static PRBool mSelfTested;
|
||||
#endif
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsString1& aString);
|
||||
extern NS_BASE int fputs(const nsString1& aString, FILE* out);
|
||||
ostream& operator<<(ostream& os,nsString& aString);
|
||||
extern NS_BASE int fputs(const nsString& aString, FILE* out);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A version of nsString1 which is designed to be used as an automatic
|
||||
* A version of nsString which is designed to be used as an automatic
|
||||
* variable. It attempts to operate out of a fixed size internal
|
||||
* buffer until too much data is added; then a dynamic buffer is
|
||||
* allocated and grown as necessary.
|
||||
*/
|
||||
// XXX template this with a parameter for the size of the buffer?
|
||||
class NS_BASE nsAutoString1 : public nsString1 {
|
||||
class NS_BASE nsAutoString : public nsString {
|
||||
public:
|
||||
nsAutoString1();
|
||||
nsAutoString1(const nsString1& other);
|
||||
nsAutoString1(const nsAutoString1& other);
|
||||
nsAutoString1(PRUnichar aChar);
|
||||
nsAutoString1(const char* aCString);
|
||||
nsAutoString1(const PRUnichar* us, PRInt32 uslen = -1);
|
||||
virtual ~nsAutoString1();
|
||||
nsAutoString();
|
||||
nsAutoString(const nsString& other);
|
||||
nsAutoString(const nsAutoString& other);
|
||||
nsAutoString(PRUnichar aChar);
|
||||
nsAutoString(const char* aCString);
|
||||
nsAutoString(const PRUnichar* us, PRInt32 uslen = -1);
|
||||
virtual ~nsAutoString();
|
||||
|
||||
nsAutoString1& operator=(const nsString1& aString) {nsString1::operator=(aString); return *this;}
|
||||
nsAutoString1& operator=(const nsAutoString1& aString) {nsString1::operator=(aString); return *this;}
|
||||
nsAutoString1& operator=(const char* aCString) {nsString1::operator=(aCString); return *this;}
|
||||
nsAutoString1& operator=(char aChar) {nsString1::operator=(aChar); return *this;}
|
||||
nsAutoString1& operator=(const PRUnichar* aBuffer) {nsString1::operator=(aBuffer); return *this;}
|
||||
nsAutoString1& operator=(PRUnichar aChar) {nsString1::operator=(aChar); return *this;}
|
||||
nsAutoString& operator=(const nsString& aString) {nsString::operator=(aString); return *this;}
|
||||
nsAutoString& operator=(const char* aCString) {nsString::operator=(aCString); return *this;}
|
||||
nsAutoString& operator=(char aChar) {nsString::operator=(aChar); return *this;}
|
||||
nsAutoString& operator=(const PRUnichar* aBuffer) {nsString::operator=(aBuffer); return *this;}
|
||||
nsAutoString& operator=(PRUnichar aChar) {nsString::operator=(aChar); return *this;}
|
||||
|
||||
virtual void SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
@@ -809,7 +791,7 @@ protected:
|
||||
chartype mBuf[32];
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsAutoString1& aString);
|
||||
ostream& operator<<(ostream& os,nsAutoString& aString);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,799 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
MODULE NOTES:
|
||||
|
||||
This version of the nsString class offers many improvements over the
|
||||
original version:
|
||||
1. Wide and narrow chars
|
||||
2. Allocators
|
||||
3. Much smarter autostrings
|
||||
4. Subsumable strings
|
||||
5. Memory pools and recycling
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _nsString2
|
||||
#define _nsString2
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
#include <iostream.h>
|
||||
#include <stdio.h>
|
||||
#include "nsCRT.h"
|
||||
|
||||
#include "nsStr.h"
|
||||
#include <iostream.h>
|
||||
#include <stdio.h>
|
||||
#include "nsIAtom.h"
|
||||
|
||||
class nsISizeOfHandler;
|
||||
|
||||
|
||||
#ifdef USE_STRING2
|
||||
#define nsString2 nsString
|
||||
#define nsAutoString2 nsAutoString
|
||||
#endif
|
||||
|
||||
class NS_BASE nsSubsumeStr;
|
||||
|
||||
class NS_BASE nsString2 : public nsStr {
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default constructor. Note that we actually allocate a small buffer
|
||||
* to begin with. This is because the "philosophy" of the string class
|
||||
* was to allow developers direct access to the underlying buffer for
|
||||
* performance reasons.
|
||||
*/
|
||||
nsString2(eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
|
||||
/**
|
||||
* This constructor accepts an isolatin string
|
||||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsString2(const char* aCString,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* This constructor accepts a unichar string
|
||||
* @param aCString is a ptr to a 2-byte cstr
|
||||
*/
|
||||
nsString2(const PRUnichar* aString,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* This is a copy constructor that accepts an nsStr
|
||||
* @param reference to another nsString2
|
||||
*/
|
||||
nsString2(const nsStr&,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* This is our copy constructor
|
||||
* @param reference to another nsString2
|
||||
*/
|
||||
nsString2(const nsString2& aString);
|
||||
|
||||
/**
|
||||
* This constructor takes a subsumestr
|
||||
* @param reference to subsumestr
|
||||
*/
|
||||
nsString2(nsSubsumeStr& aSubsumeStr);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
*/
|
||||
virtual ~nsString2();
|
||||
|
||||
/**
|
||||
* Retrieve the length of this string
|
||||
* @return string length
|
||||
*/
|
||||
inline PRInt32 Length() const { return (PRInt32)mLength; }
|
||||
|
||||
/**
|
||||
* Retrieve the size of this string
|
||||
* @return string length
|
||||
*/
|
||||
virtual void SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
|
||||
/**
|
||||
* Call this method if you want to force a different string capacity
|
||||
* @update gess7/30/98
|
||||
* @param aLength -- contains new length for mStr
|
||||
* @return
|
||||
*/
|
||||
void SetLength(PRUint32 aLength) {
|
||||
SetCapacity(aLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new length of the string.
|
||||
* @param aLength is new string length.
|
||||
* @return nada
|
||||
*/
|
||||
void SetCapacity(PRUint32 aLength);
|
||||
/**
|
||||
* This method truncates this string to given length.
|
||||
*
|
||||
* @param anIndex -- new length of string
|
||||
* @return nada
|
||||
*/
|
||||
void Truncate(PRInt32 anIndex=0);
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether or not the characters in this
|
||||
* string are in sorted order.
|
||||
*
|
||||
* @return TRUE if ordered.
|
||||
*/
|
||||
PRBool IsOrdered(void) const;
|
||||
|
||||
/**
|
||||
* Determine whether or not the characters in this
|
||||
* string are in store as 1 or 2 byte (unicode) strings.
|
||||
*
|
||||
* @return TRUE if ordered.
|
||||
*/
|
||||
PRBool IsUnicode(void) const {
|
||||
PRBool result=PRBool(mCharSize==eTwoByte);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not this string has a length of 0
|
||||
*
|
||||
* @return TRUE if empty.
|
||||
*/
|
||||
PRBool IsEmpty(void) const {
|
||||
return PRBool(0==mLength);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
Accessor methods...
|
||||
*********************************************************************/
|
||||
|
||||
const char* GetBuffer(void) const;
|
||||
const PRUnichar* GetUnicode(void) const;
|
||||
|
||||
|
||||
/**
|
||||
* Get nth character.
|
||||
*/
|
||||
PRUnichar operator[](PRUint32 anIndex) const;
|
||||
PRUnichar CharAt(PRUint32 anIndex) const;
|
||||
PRUnichar First(void) const;
|
||||
PRUnichar Last(void) const;
|
||||
|
||||
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
String creation methods...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* Create a new string by appending given string to this
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsSubsumeStr operator+(const nsStr& aString);
|
||||
|
||||
/**
|
||||
* Create a new string by appending given string to this
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsSubsumeStr operator+(const nsString2& aString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given buffer.
|
||||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr operator+(const char* aCString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given wide buffer.
|
||||
* @param aString is a ptr to UC-string to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr operator+(const PRUnichar* aString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr operator+(char aChar);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr operator+(PRUnichar aChar);
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* Converts all chars in given string to UCS2
|
||||
* which ensure that the lower 256 chars are correct.
|
||||
*/
|
||||
void ToUCS2(PRUint32 aStartOffset);
|
||||
|
||||
/**
|
||||
* Converts chars in this to lowercase
|
||||
* @update gess 7/27/98
|
||||
*/
|
||||
void ToLowerCase();
|
||||
|
||||
|
||||
/**
|
||||
* Converts chars in this to lowercase, and
|
||||
* stores them in aOut
|
||||
* @update gess 7/27/98
|
||||
* @param aOut is a string to contain result
|
||||
*/
|
||||
void ToLowerCase(nsString2& aString) const;
|
||||
|
||||
/**
|
||||
* Converts chars in this to uppercase
|
||||
* @update gess 7/27/98
|
||||
*/
|
||||
void ToUpperCase();
|
||||
|
||||
/**
|
||||
* Converts chars in this to lowercase, and
|
||||
* stores them in a given output string
|
||||
* @update gess 7/27/98
|
||||
* @param aOut is a string to contain result
|
||||
*/
|
||||
void ToUpperCase(nsString2& aString) const;
|
||||
|
||||
|
||||
/**
|
||||
* This method is used to remove all occurances of the
|
||||
* characters found in aSet from this string.
|
||||
*
|
||||
* @param aSet -- characters to be cut from this
|
||||
* @return *this
|
||||
*/
|
||||
nsString2& StripChars(const char* aSet);
|
||||
|
||||
/**
|
||||
* This method strips whitespace throughout the string
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
nsString2& StripWhitespace();
|
||||
|
||||
/**
|
||||
* swaps occurence of 1 string for another
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
nsString2& ReplaceChar(PRUnichar aSourceChar,PRUnichar aDestChar);
|
||||
|
||||
/**
|
||||
* This method trims characters found in aTrimSet from
|
||||
* either end of the underlying string.
|
||||
*
|
||||
* @param aTrimSet -- contains chars to be trimmed from
|
||||
* both ends
|
||||
* @return this
|
||||
*/
|
||||
nsString2& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**
|
||||
* This method strips whitespace from string.
|
||||
* You can control whether whitespace is yanked from
|
||||
* start and end of string as well.
|
||||
*
|
||||
* @param aEliminateLeading controls stripping of leading ws
|
||||
* @param aEliminateTrailing controls stripping of trailing ws
|
||||
* @return this
|
||||
*/
|
||||
nsString2& CompressSet(const char* aSet, char aChar, PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**
|
||||
* This method strips whitespace from string.
|
||||
* You can control whether whitespace is yanked from
|
||||
* start and end of string as well.
|
||||
*
|
||||
* @param aEliminateLeading controls stripping of leading ws
|
||||
* @param aEliminateTrailing controls stripping of trailing ws
|
||||
* @return this
|
||||
*/
|
||||
nsString2& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**********************************************************************
|
||||
string conversion methods...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* This method constructs a new nsString2 on the stack that is a copy
|
||||
* of this string.
|
||||
*
|
||||
*/
|
||||
nsString2* ToNewString() const;
|
||||
|
||||
/**
|
||||
* Creates an ISOLatin1 clone of this string
|
||||
* @return ptr to new isolatin1 string
|
||||
*/
|
||||
char* ToNewCString() const;
|
||||
|
||||
/**
|
||||
* Creates a unicode clone of this string
|
||||
* @return ptr to new unicode string
|
||||
*/
|
||||
PRUnichar* ToNewUnicode() const;
|
||||
|
||||
/**
|
||||
* Copies data from internal buffer onto given char* buffer
|
||||
* @param aBuf is the buffer where data is stored
|
||||
* @param aBuflength is the max # of chars to move to buffer
|
||||
* @return ptr to given buffer
|
||||
*/
|
||||
char* ToCString(char* aBuf,PRUint32 aBufLength) const;
|
||||
|
||||
/**
|
||||
* Perform string to float conversion.
|
||||
* @param aErrorCode will contain error if one occurs
|
||||
* @return float rep of string value
|
||||
*/
|
||||
float ToFloat(PRInt32* aErrorCode) const;
|
||||
|
||||
/**
|
||||
* Perform string to int conversion.
|
||||
* @param aErrorCode will contain error if one occurs
|
||||
* @return int rep of string value
|
||||
*/
|
||||
PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=10) const;
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
String manipulation methods...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* Functionally equivalent to assign or operator=
|
||||
*
|
||||
*/
|
||||
nsString2& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
|
||||
nsString2& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
|
||||
nsString2& SetString(const nsString2& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
|
||||
|
||||
/**
|
||||
* assign given string to this string
|
||||
* @param aStr: buffer to be assigned to this
|
||||
* @param alength is the length of the given str (or -1)
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString2& Assign(const nsString2& aString,PRInt32 aCount=-1);
|
||||
nsString2& Assign(const nsStr& aString,PRInt32 aCount=-1);
|
||||
nsString2& Assign(const char* aString,PRInt32 aCount=-1);
|
||||
nsString2& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
|
||||
nsString2& Assign(char aChar);
|
||||
nsString2& Assign(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* here come a bunch of assignment operators...
|
||||
* @param aString: string to be added to this
|
||||
* @return this
|
||||
*/
|
||||
nsString2& operator=(const nsString2& aString) {return Assign(aString);}
|
||||
nsString2& operator=(const nsStr& aString) {return Assign(aString);}
|
||||
nsString2& operator=(char aChar) {return Assign(aChar);}
|
||||
nsString2& operator=(PRUnichar aChar) {return Assign(aChar);}
|
||||
nsString2& operator=(const char* aCString) {return Assign(aCString);}
|
||||
nsString2& operator=(const PRUnichar* aString) {return Assign(aString);}
|
||||
nsString2& operator=(nsSubsumeStr& aSubsumeString);
|
||||
|
||||
/**
|
||||
* Here's a bunch of append mehtods for varying types...
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString2& operator+=(const nsStr& aString){return Append(aString,aString.mLength);}
|
||||
nsString2& operator+=(const nsString2& aString){return Append(aString,aString.mLength);}
|
||||
nsString2& operator+=(const char* aCString) {return Append(aCString);}
|
||||
//nsString2& operator+=(char aChar){return Append(aChar);}
|
||||
nsString2& operator+=(const PRUnichar* aUCString) {return Append(aUCString);}
|
||||
nsString2& operator+=(PRUnichar aChar){return Append(aChar);}
|
||||
|
||||
/*
|
||||
* Appends n characters from given string to this,
|
||||
* This version computes the length of your given string
|
||||
*
|
||||
* @param aString is the source to be appended to this
|
||||
* @return number of chars copied
|
||||
*/
|
||||
nsString2& Append(const nsStr& aString) {return Append(aString,aString.mLength);}
|
||||
nsString2& Append(const nsString2& aString) {return Append(aString,aString.mLength);}
|
||||
|
||||
|
||||
/*
|
||||
* Appends n characters from given string to this,
|
||||
*
|
||||
* @param aString is the source to be appended to this
|
||||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
nsString2& Append(const nsStr& aString,PRInt32 aCount);
|
||||
nsString2& Append(const nsString2& aString,PRInt32 aCount);
|
||||
nsString2& Append(const char* aString,PRInt32 aCount=-1);
|
||||
nsString2& Append(const PRUnichar* aString,PRInt32 aCount=-1);
|
||||
nsString2& Append(char aChar);
|
||||
nsString2& Append(PRUnichar aChar);
|
||||
nsString2& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
|
||||
nsString2& Append(float aFloat);
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
* starting at the leftmost offset.
|
||||
*
|
||||
*
|
||||
* @param aCopy -- Receiving string
|
||||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRUint32 Left(nsString2& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
* starting at the given offset.
|
||||
*
|
||||
*
|
||||
* @param aCopy -- Receiving string
|
||||
* @param aCount -- number of chars to copy
|
||||
* @param anOffset -- position where copying begins
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRUint32 Mid(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
* starting at rightmost char.
|
||||
*
|
||||
*
|
||||
* @param aCopy -- Receiving string
|
||||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRUint32 Right(nsString2& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* This method inserts n chars from given string into this
|
||||
* string at str[anOffset].
|
||||
*
|
||||
* @param aCopy -- String to be inserted into this
|
||||
* @param anOffset -- insertion position within this str
|
||||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
nsString2& Insert(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a given string into this string at
|
||||
* a specified offset.
|
||||
*
|
||||
* @param aString* to be inserted into this string
|
||||
* @param anOffset is insert pos in str
|
||||
* @return the number of chars inserted into this string
|
||||
*/
|
||||
nsString2& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
nsString2& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a single char into this string at
|
||||
* a specified offset.
|
||||
*
|
||||
* @param character to be inserted into this string
|
||||
* @param anOffset is insert pos in str
|
||||
* @return the number of chars inserted into this string
|
||||
*/
|
||||
//nsString2& Insert(char aChar,PRUint32 anOffset);
|
||||
nsString2& Insert(PRUnichar aChar,PRUint32 anOffset);
|
||||
|
||||
/*
|
||||
* This method is used to cut characters in this string
|
||||
* starting at anOffset, continuing for aCount chars.
|
||||
*
|
||||
* @param anOffset -- start pos for cut operation
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
nsString2& Cut(PRUint32 anOffset,PRInt32 aCount);
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
Searching methods...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* Search for given character within this string.
|
||||
* This method does so by using a binary search,
|
||||
* so your string HAD BETTER BE ORDERED!
|
||||
*
|
||||
* @param aChar is the unicode char to be found
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 BinarySearch(PRUnichar aChar) const;
|
||||
|
||||
/**
|
||||
* Search for given substring within this string
|
||||
*
|
||||
* @param aString is substring to be sought in this
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 Find(const nsString2& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 Find(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
|
||||
/**
|
||||
* This method searches this string for the first character
|
||||
* found in the given string
|
||||
* @param aString contains set of chars to be found
|
||||
* @param anOffset tells us where to start searching in this
|
||||
* @return -1 if not found, else the offset in this
|
||||
*/
|
||||
PRInt32 FindCharInSet(const char* aString,PRUint32 anOffset=0) const;
|
||||
PRInt32 FindCharInSet(const PRUnichar* aString,PRUint32 anOffset=0) const;
|
||||
PRInt32 FindCharInSet(const nsString2& aString,PRUint32 anOffset=0) const;
|
||||
|
||||
/**
|
||||
* This method searches this string for the last character
|
||||
* found in the given string
|
||||
* @param aString contains set of chars to be found
|
||||
* @param anOffset tells us where to start searching in this
|
||||
* @return -1 if not found, else the offset in this
|
||||
*/
|
||||
PRInt32 RFindCharInSet(const char* aString,PRUint32 anOffset=0) const;
|
||||
PRInt32 RFindCharInSet(const PRUnichar* aString,PRUint32 anOffset=0) const;
|
||||
PRInt32 RFindCharInSet(const nsString2& aString,PRUint32 anOffset=0) const;
|
||||
|
||||
|
||||
/**
|
||||
* This methods scans the string backwards, looking for the given string
|
||||
* @param aString is substring to be sought in this
|
||||
* @param aIgnoreCase tells us whether or not to do caseless compare
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const nsString2& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
|
||||
/**********************************************************************
|
||||
Comparison methods...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* Compares a given string type to this string.
|
||||
* @update gess 7/27/98
|
||||
* @param S is the string to be compared
|
||||
* @param aIgnoreCase tells us how to treat case
|
||||
* @return -1,0,1
|
||||
*/
|
||||
virtual PRInt32 Compare(const nsString2& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
|
||||
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
|
||||
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
|
||||
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
|
||||
|
||||
/**
|
||||
* These methods compare a given string type to this one
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator==(const nsString2 &aString) const;
|
||||
PRBool operator==(const nsStr &aString) const;
|
||||
PRBool operator==(const char *aString) const;
|
||||
PRBool operator==(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods perform a !compare of a given string type to this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE
|
||||
*/
|
||||
PRBool operator!=(const nsString2 &aString) const;
|
||||
PRBool operator!=(const nsStr &aString) const;
|
||||
PRBool operator!=(const char* aString) const;
|
||||
PRBool operator!=(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods test if a given string is < than this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator<(const nsString2 &aString) const;
|
||||
PRBool operator<(const nsStr &aString) const;
|
||||
PRBool operator<(const char* aString) const;
|
||||
PRBool operator<(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods test if a given string is > than this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator>(const nsString2 &aString) const;
|
||||
PRBool operator>(const nsStr &S) const;
|
||||
PRBool operator>(const char* aString) const;
|
||||
PRBool operator>(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods test if a given string is <= than this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator<=(const nsString2 &aString) const;
|
||||
PRBool operator<=(const nsStr &S) const;
|
||||
PRBool operator<=(const char* aString) const;
|
||||
PRBool operator<=(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods test if a given string is >= than this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator>=(const nsString2 &aString) const;
|
||||
PRBool operator>=(const nsStr &S) const;
|
||||
PRBool operator>=(const char* aString) const;
|
||||
PRBool operator>=(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* Compare this to given string; note that we compare full strings here.
|
||||
* The optional length argument just lets us know how long the given string is.
|
||||
* If you provide a length, it is compared to length of this string as an
|
||||
* optimization.
|
||||
*
|
||||
* @param aString -- the string to compare to this
|
||||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool Equals(const nsString2 &aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRBool Equals(const char* aString,PRUint32 aCount,PRBool aIgnoreCase) const;
|
||||
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRBool Equals(const PRUnichar* aString,PRUint32 aCount,PRBool aIgnoreCase) const;
|
||||
PRBool Equals(const nsIAtom* anAtom,PRBool aIgnoreCase) const;
|
||||
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
|
||||
PRBool EqualsIgnoreCase(const nsString2& aString) const;
|
||||
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
|
||||
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
|
||||
|
||||
|
||||
/**
|
||||
* Determine if given char is a valid space character
|
||||
*
|
||||
* @param aChar is character to be tested
|
||||
* @return TRUE if is valid space char
|
||||
*/
|
||||
static PRBool IsSpace(PRUnichar ch);
|
||||
|
||||
/**
|
||||
* Determine if given char in valid alpha range
|
||||
*
|
||||
* @param aChar is character to be tested
|
||||
* @return TRUE if in alpha range
|
||||
*/
|
||||
static PRBool IsAlpha(PRUnichar ch);
|
||||
|
||||
/**
|
||||
* Determine if given char is valid digit
|
||||
*
|
||||
* @param aChar is character to be tested
|
||||
* @return TRUE if char is a valid digit
|
||||
*/
|
||||
static PRBool IsDigit(PRUnichar ch);
|
||||
|
||||
static void Recycle(nsString2* aString);
|
||||
static nsString2* CreateString(eCharSize aCharSize=eTwoByte);
|
||||
|
||||
virtual void DebugDump(ostream& aStream) const;
|
||||
|
||||
nsIMemoryAgent* mAgent;
|
||||
|
||||
};
|
||||
|
||||
extern NS_BASE int fputs(const nsString2& aString, FILE* out);
|
||||
ostream& operator<<(ostream& os,nsString2& aString);
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Here comes the AutoString class which uses internal memory
|
||||
(typically found on the stack) for its default buffer.
|
||||
If the buffer needs to grow, it gets reallocated on the heap.
|
||||
**************************************************************/
|
||||
|
||||
class NS_BASE nsAutoString2 : public nsString2 {
|
||||
public:
|
||||
|
||||
nsAutoString2(eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(nsStr& anExtBuffer,const char* aCString);
|
||||
|
||||
|
||||
nsAutoString2(const char* aCString,eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(char* aCString,PRUint32 aLength,eCharSize aCharSize=kDefaultCharSize,PRBool assumeOwnership=PR_FALSE);
|
||||
nsAutoString2(const PRUnichar* aString,eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(PRUnichar* aString,PRUint32 aLength,eCharSize aCharSize=kDefaultCharSize,PRBool assumeOwnership=PR_FALSE);
|
||||
|
||||
nsAutoString2(const nsStr& aString,eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(const nsString2& aString,eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(nsSubsumeStr& aSubsumeStr);
|
||||
nsAutoString2(PRUnichar aChar,eCharSize aCharSize=kDefaultCharSize);
|
||||
virtual ~nsAutoString2();
|
||||
|
||||
nsAutoString2& operator=(const nsString2& aString) {nsString2::operator=(aString); return *this;}
|
||||
nsAutoString2& operator=(const nsStr& aString) {nsString2::Assign(aString); return *this;}
|
||||
nsAutoString2& operator=(const nsAutoString2& aString) {nsString2::operator=(aString); return *this;}
|
||||
nsAutoString2& operator=(const char* aCString) {nsString2::operator=(aCString); return *this;}
|
||||
nsAutoString2& operator=(char aChar) {nsString2::operator=(aChar); return *this;}
|
||||
nsAutoString2& operator=(const PRUnichar* aBuffer) {nsString2::operator=(aBuffer); return *this;}
|
||||
nsAutoString2& operator=(PRUnichar aChar) {nsString2::operator=(aChar); return *this;}
|
||||
|
||||
/**
|
||||
* Retrieve the size of this string
|
||||
* @return string length
|
||||
*/
|
||||
virtual void SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
char mBuffer[32];
|
||||
};
|
||||
|
||||
|
||||
/***************************************************************
|
||||
The subsumestr class is very unusual.
|
||||
It differs from a normal string in that it doesn't use normal
|
||||
copy semantics when another string is assign to this.
|
||||
Instead, it "steals" the contents of the source string.
|
||||
|
||||
This is very handy for returning nsString classes as part of
|
||||
an operator+(...) for example, in that it cuts down the number
|
||||
of copy operations that must occur.
|
||||
|
||||
You should probably not use this class unless you really know
|
||||
what you're doing.
|
||||
***************************************************************/
|
||||
class NS_BASE nsSubsumeStr : public nsString2 {
|
||||
public:
|
||||
nsSubsumeStr(nsString2& aString);
|
||||
nsSubsumeStr(nsStr& aString);
|
||||
nsSubsumeStr(const PRUnichar* aString);
|
||||
nsSubsumeStr(const char* aString);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,137 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
The default implementation for nsIString.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include "nsIString.h"
|
||||
#include "nsStr.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kIStringIID, NS_ISTRING_IID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsStringImpl : public nsIString
|
||||
{
|
||||
protected:
|
||||
nsStr mStr;
|
||||
|
||||
public:
|
||||
nsStringImpl();
|
||||
virtual ~nsStringImpl();
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIString interface
|
||||
NS_IMETHOD Init(eCharSize aCharSize);
|
||||
NS_IMETHOD SetStr(nsStr* aStr);
|
||||
NS_IMETHOD GetStr(nsStr* aStr);
|
||||
NS_IMETHOD GetImmutableStr(const nsStr** aStr);
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsStringImpl::nsStringImpl()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
nsStr::Initialize(mStr, kDefaultCharSize);
|
||||
}
|
||||
|
||||
|
||||
nsStringImpl::~nsStringImpl()
|
||||
{
|
||||
nsStr::Destroy(mStr);
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(nsresult)
|
||||
NS_NewString(nsIString** aString)
|
||||
{
|
||||
NS_PRECONDITION(aString != nsnull, "null ptr");
|
||||
if (! aString)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsStringImpl* s = new nsStringImpl();
|
||||
if (! s)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(s);
|
||||
*aString = s;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsISupports interface
|
||||
|
||||
NS_IMPL_ADDREF(nsStringImpl);
|
||||
NS_IMPL_RELEASE(nsStringImpl);
|
||||
NS_IMPL_QUERY_INTERFACE(nsStringImpl, kIStringIID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsStringImpl::Init(eCharSize aCharSize)
|
||||
{
|
||||
nsStr::Initialize(mStr, aCharSize);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsStringImpl::SetStr(nsStr* aStr)
|
||||
{
|
||||
NS_PRECONDITION(aStr != nsnull, "null ptr");
|
||||
if (! aStr)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsStr::Assign(mStr, *aStr, 0, aStr->mLength);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsStringImpl::GetStr(nsStr* aStr)
|
||||
{
|
||||
NS_PRECONDITION(aStr != nsnull, "null ptr");
|
||||
if (! aStr)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsStr::Assign(*aStr, mStr, 0, mStr.mLength);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsStringImpl::GetImmutableStr(const nsStr** aImmutableStr)
|
||||
{
|
||||
NS_PRECONDITION(aImmutableStr != nsnull, "null ptr");
|
||||
if (! aImmutableStr)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aImmutableStr = &mStr;
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1,489 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsThread.h"
|
||||
#include "prmem.h"
|
||||
//#include <stdio.h>
|
||||
|
||||
PRUintn nsThread::kIThreadSelfIndex = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsThread::nsThread()
|
||||
: mThread(nsnull), mRunnable(nsnull), mDead(PR_FALSE)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsThread::Init(nsIRunnable* runnable,
|
||||
PRUint32 stackSize,
|
||||
PRThreadPriority priority,
|
||||
PRThreadScope scope,
|
||||
PRThreadState state)
|
||||
{
|
||||
mRunnable = runnable;
|
||||
NS_ADDREF(mRunnable);
|
||||
|
||||
NS_ADDREF_THIS(); // released in nsThread::Exit
|
||||
if (state == PR_JOINABLE_THREAD)
|
||||
NS_ADDREF_THIS(); // released in nsThread::Join
|
||||
mThread = PR_CreateThread(PR_USER_THREAD, Main, this,
|
||||
priority, scope, state, stackSize);
|
||||
// printf("%x %x (%d) create\n", this, mThread, mRefCnt);
|
||||
if (mThread == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsThread::~nsThread()
|
||||
{
|
||||
// printf("%x %x (%d) destroy\n", this, mThread, mRefCnt);
|
||||
NS_IF_RELEASE(mRunnable);
|
||||
}
|
||||
|
||||
void
|
||||
nsThread::Main(void* arg)
|
||||
{
|
||||
nsThread* self = (nsThread*)arg;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
rv = self->RegisterThreadSelf();
|
||||
NS_ASSERTION(rv == NS_OK, "failed to set thread self");
|
||||
|
||||
// printf("%x %x (%d) start run\n", self, self->mThread, self->mRefCnt);
|
||||
rv = self->mRunnable->Run();
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "runnable failed");
|
||||
|
||||
PRThreadState state;
|
||||
rv = self->GetState(&state);
|
||||
// printf("%x %x (%d) end run\n", self, self->mThread, self->mRefCnt);
|
||||
}
|
||||
|
||||
void
|
||||
nsThread::Exit(void* arg)
|
||||
{
|
||||
nsThread* self = (nsThread*)arg;
|
||||
nsresult rv = NS_OK;
|
||||
self->mDead = PR_TRUE;
|
||||
// printf("%x %x (%d) exit\n", self, self->mThread, self->mRefCnt - 1);
|
||||
NS_RELEASE(self);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsThread, nsIThread::GetIID());
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThread::Join()
|
||||
{
|
||||
// don't check for mDead here because nspr calls Exit (cleaning up
|
||||
// thread-local storage) before they let us join with the thread
|
||||
|
||||
// printf("%x %x (%d) start join\n", this, mThread, mRefCnt);
|
||||
PRStatus status = PR_JoinThread(mThread);
|
||||
// XXX can't use NS_RELEASE here because the macro wants to set
|
||||
// this to null (bad c++)
|
||||
// printf("%x %x (%d) end join\n", this, mThread, mRefCnt);
|
||||
if (status == PR_SUCCESS) {
|
||||
this->Release(); // most likely the final release of this thread
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThread::GetPriority(PRThreadPriority *result)
|
||||
{
|
||||
if (mDead)
|
||||
return NS_ERROR_FAILURE;
|
||||
*result = PR_GetThreadPriority(mThread);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThread::SetPriority(PRThreadPriority value)
|
||||
{
|
||||
if (mDead)
|
||||
return NS_ERROR_FAILURE;
|
||||
PR_SetThreadPriority(mThread, value);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThread::Interrupt()
|
||||
{
|
||||
if (mDead)
|
||||
return NS_ERROR_FAILURE;
|
||||
PRStatus status = PR_Interrupt(mThread);
|
||||
return status == PR_SUCCESS ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThread::GetScope(PRThreadScope *result)
|
||||
{
|
||||
if (mDead)
|
||||
return NS_ERROR_FAILURE;
|
||||
*result = PR_GetThreadScope(mThread);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThread::GetState(PRThreadState *result)
|
||||
{
|
||||
if (mDead)
|
||||
return NS_ERROR_FAILURE;
|
||||
*result = PR_GetThreadState(mThread);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThread::GetPRThread(PRThread* *result)
|
||||
{
|
||||
if (mDead)
|
||||
return NS_ERROR_FAILURE;
|
||||
*result = mThread;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_BASE nsresult
|
||||
NS_NewThread(nsIThread* *result,
|
||||
nsIRunnable* runnable,
|
||||
PRUint32 stackSize,
|
||||
PRThreadPriority priority,
|
||||
PRThreadScope scope,
|
||||
PRThreadState state)
|
||||
{
|
||||
nsresult rv;
|
||||
nsThread* thread = new nsThread();
|
||||
if (thread == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = thread->Init(runnable, stackSize, priority, scope, state);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete thread;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_ADDREF(thread);
|
||||
*result = thread;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
nsThread::RegisterThreadSelf()
|
||||
{
|
||||
PRStatus status;
|
||||
|
||||
if (kIThreadSelfIndex == 0) {
|
||||
status = PR_NewThreadPrivateIndex(&kIThreadSelfIndex, Exit);
|
||||
if (status != PR_SUCCESS) return NS_ERROR_FAILURE;
|
||||
NS_ASSERTION(kIThreadSelfIndex != 0, "couldn't get thread private index");
|
||||
}
|
||||
|
||||
status = PR_SetThreadPrivate(kIThreadSelfIndex, this);
|
||||
if (status != PR_SUCCESS) return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_BASE nsresult
|
||||
nsIThread::GetCurrent(nsIThread* *result)
|
||||
{
|
||||
return GetIThread(PR_CurrentThread(), result);
|
||||
}
|
||||
|
||||
NS_BASE nsresult
|
||||
nsIThread::GetIThread(PRThread* prthread, nsIThread* *result)
|
||||
{
|
||||
PRStatus status;
|
||||
nsThread* thread;
|
||||
|
||||
if (nsThread::kIThreadSelfIndex == 0) {
|
||||
status = PR_NewThreadPrivateIndex(&nsThread::kIThreadSelfIndex, nsThread::Exit);
|
||||
if (status != PR_SUCCESS) return NS_ERROR_FAILURE;
|
||||
NS_ASSERTION(nsThread::kIThreadSelfIndex != 0, "couldn't get thread private index");
|
||||
}
|
||||
|
||||
thread = (nsThread*)PR_GetThreadPrivate(nsThread::kIThreadSelfIndex);
|
||||
if (thread == nsnull) {
|
||||
// if the current thread doesn't have an nsIThread associated
|
||||
// with it, make one
|
||||
thread = new nsThread();
|
||||
if (thread == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(thread);
|
||||
thread->SetPRThread(prthread);
|
||||
nsresult rv = thread->RegisterThreadSelf();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
NS_ADDREF(thread);
|
||||
*result = thread;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsThreadPool::nsThreadPool(PRUint32 minThreads, PRUint32 maxThreads)
|
||||
: mThreads(nsnull), mRequests(nsnull),
|
||||
mMinThreads(minThreads), mMaxThreads(maxThreads), mShuttingDown(PR_FALSE)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsThreadPool::Init(PRUint32 stackSize,
|
||||
PRThreadPriority priority,
|
||||
PRThreadScope scope)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
rv = NS_NewISupportsArray(&mThreads);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = NS_NewISupportsArray(&mRequests);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mRequestMonitor = PR_NewMonitor();
|
||||
if (mRequestMonitor == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
PR_CEnterMonitor(this);
|
||||
|
||||
for (PRUint32 i = 0; i < mMinThreads; i++) {
|
||||
nsThreadPoolRunnable* runnable =
|
||||
new nsThreadPoolRunnable(this);
|
||||
if (runnable == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(runnable);
|
||||
|
||||
nsIThread* thread;
|
||||
|
||||
rv = NS_NewThread(&thread, runnable, stackSize, priority, scope,
|
||||
PR_JOINABLE_THREAD); // needed for Shutdown
|
||||
NS_RELEASE(runnable);
|
||||
if (NS_FAILED(rv)) goto exit;
|
||||
|
||||
rv = mThreads->AppendElement(thread) ? NS_OK : NS_ERROR_FAILURE;
|
||||
NS_RELEASE(thread);
|
||||
if (NS_FAILED(rv)) goto exit;
|
||||
}
|
||||
// wait for some worker thread to be ready
|
||||
PR_CWait(this, PR_INTERVAL_NO_TIMEOUT);
|
||||
|
||||
exit:
|
||||
PR_CExitMonitor(this);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsThreadPool::~nsThreadPool()
|
||||
{
|
||||
if (mThreads) {
|
||||
Shutdown();
|
||||
NS_RELEASE(mThreads);
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(mRequests);
|
||||
|
||||
if (mRequestMonitor) {
|
||||
PR_DestroyMonitor(mRequestMonitor);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsThreadPool, nsIThreadPool::GetIID());
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThreadPool::DispatchRequest(nsIRunnable* runnable)
|
||||
{
|
||||
nsresult rv;
|
||||
PR_EnterMonitor(mRequestMonitor);
|
||||
|
||||
if (mShuttingDown) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
else {
|
||||
// XXX for now AppendElement returns a PRBool
|
||||
rv = ((PRBool) mRequests->AppendElement(runnable)) ? NS_OK : NS_ERROR_FAILURE;
|
||||
if (NS_SUCCEEDED(rv))
|
||||
PR_Notify(mRequestMonitor);
|
||||
}
|
||||
PR_ExitMonitor(mRequestMonitor);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsIRunnable*
|
||||
nsThreadPool::GetRequest()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsIRunnable* request = nsnull;
|
||||
|
||||
PR_EnterMonitor(mRequestMonitor);
|
||||
|
||||
PRUint32 cnt;
|
||||
while (PR_TRUE) {
|
||||
rv = mRequests->Count(&cnt);
|
||||
if (NS_FAILED(rv) || cnt != 0)
|
||||
break;
|
||||
|
||||
if (mShuttingDown) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
break;
|
||||
}
|
||||
// printf("thread %x waiting\n", PR_CurrentThread());
|
||||
PRStatus status = PR_Wait(mRequestMonitor, PR_INTERVAL_NO_TIMEOUT);
|
||||
if (status != PR_SUCCESS || mShuttingDown) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
NS_ASSERTION((NS_SUCCEEDED(mRequests->Count(&cnt)) && cnt > 0),
|
||||
"request queue out of sync");
|
||||
request = (nsIRunnable*)(*mRequests)[0];
|
||||
NS_ASSERTION(request != nsnull, "null runnable");
|
||||
|
||||
PRBool removed = mRequests->RemoveElementAt(0);
|
||||
NS_ASSERTION(removed, "nsISupportsArray broken");
|
||||
}
|
||||
PR_ExitMonitor(mRequestMonitor);
|
||||
return request;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThreadPool::ProcessPendingRequests()
|
||||
{
|
||||
nsresult rv;
|
||||
PR_CEnterMonitor(this);
|
||||
|
||||
while (PR_TRUE) {
|
||||
PRUint32 cnt;
|
||||
rv = mRequests->Count(&cnt);
|
||||
if (NS_FAILED(rv) || cnt == 0)
|
||||
break;
|
||||
|
||||
PRStatus status = PR_CWait(this, PR_INTERVAL_NO_TIMEOUT);
|
||||
if (status != PR_SUCCESS) {
|
||||
rv = NS_ERROR_FAILURE; // our thread was interrupted!
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PR_CExitMonitor(this);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThreadPool::Shutdown()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
PRUint32 count = 0;
|
||||
PRUint32 i;
|
||||
|
||||
mShuttingDown = PR_TRUE;
|
||||
ProcessPendingRequests();
|
||||
|
||||
// then interrupt the threads and join them
|
||||
rv = mThreads->Count(&count);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
for (i = 0; i < count; i++) {
|
||||
nsIThread* thread = (nsIThread*)((*mThreads)[0]);
|
||||
|
||||
// we don't care about the error from Interrupt, because the
|
||||
// thread may have already terminated its event loop
|
||||
(void)thread->Interrupt();
|
||||
|
||||
rv = thread->Join();
|
||||
// don't break out of the loop because of an error here
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Join failed");
|
||||
|
||||
NS_RELEASE(thread);
|
||||
rv = mThreads->RemoveElementAt(0);
|
||||
// don't break out of the loop because of an error here
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "RemoveElementAt failed");
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_BASE nsresult
|
||||
NS_NewThreadPool(nsIThreadPool* *result,
|
||||
PRUint32 minThreads, PRUint32 maxThreads,
|
||||
PRUint32 stackSize,
|
||||
PRThreadPriority priority,
|
||||
PRThreadScope scope)
|
||||
{
|
||||
nsresult rv;
|
||||
nsThreadPool* pool = new nsThreadPool(minThreads, maxThreads);
|
||||
if (pool == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = pool->Init(stackSize, priority, scope);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete pool;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_ADDREF(pool);
|
||||
*result = pool;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsThreadPoolRunnable::nsThreadPoolRunnable(nsThreadPool* pool)
|
||||
: mPool(pool)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF(mPool);
|
||||
}
|
||||
|
||||
nsThreadPoolRunnable::~nsThreadPoolRunnable()
|
||||
{
|
||||
NS_RELEASE(mPool);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsThreadPoolRunnable, nsIRunnable::GetIID());
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThreadPoolRunnable::Run()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsIRunnable* request;
|
||||
|
||||
// let the thread pool know we're ready
|
||||
PR_CEnterMonitor(mPool);
|
||||
PR_CNotify(mPool);
|
||||
PR_CExitMonitor(mPool);
|
||||
|
||||
while ((request = mPool->GetRequest()) != nsnull) {
|
||||
// printf("running %x, thread %x\n", this, PR_CurrentThread());
|
||||
rv = request->Run();
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "runnable failed");
|
||||
|
||||
// let the thread pool know we're finished a run
|
||||
PR_CEnterMonitor(mPool);
|
||||
PR_CNotify(mPool);
|
||||
PR_CExitMonitor(mPool);
|
||||
}
|
||||
// printf("quitting %x, thread %x\n", this, PR_CurrentThread());
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -1,114 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsThread_h__
|
||||
#define nsThread_h__
|
||||
|
||||
#include "nsIThread.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "prcmon.h"
|
||||
|
||||
class nsThread : public nsIThread
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIThread methods:
|
||||
NS_IMETHOD Join();
|
||||
NS_IMETHOD GetPriority(PRThreadPriority *result);
|
||||
NS_IMETHOD SetPriority(PRThreadPriority value);
|
||||
NS_IMETHOD Interrupt();
|
||||
NS_IMETHOD GetScope(PRThreadScope *result);
|
||||
NS_IMETHOD GetState(PRThreadState *result);
|
||||
NS_IMETHOD GetPRThread(PRThread* *result);
|
||||
|
||||
// nsThread methods:
|
||||
nsThread();
|
||||
virtual ~nsThread();
|
||||
|
||||
nsresult Init(nsIRunnable* runnable,
|
||||
PRUint32 stackSize,
|
||||
PRThreadPriority priority,
|
||||
PRThreadScope scope,
|
||||
PRThreadState state);
|
||||
nsresult RegisterThreadSelf();
|
||||
void SetPRThread(PRThread* thread) { mThread = thread; }
|
||||
|
||||
static void Main(void* arg);
|
||||
static void Exit(void* arg);
|
||||
|
||||
static PRUintn kIThreadSelfIndex;
|
||||
|
||||
protected:
|
||||
PRThread* mThread;
|
||||
nsIRunnable* mRunnable;
|
||||
PRBool mDead;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsThreadPool : public nsIThreadPool
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIThreadPool methods:
|
||||
NS_IMETHOD DispatchRequest(nsIRunnable* runnable);
|
||||
NS_IMETHOD ProcessPendingRequests();
|
||||
NS_IMETHOD Shutdown();
|
||||
|
||||
// nsThreadPool methods:
|
||||
nsThreadPool(PRUint32 minThreads, PRUint32 maxThreads);
|
||||
virtual ~nsThreadPool();
|
||||
|
||||
nsresult Init(PRUint32 stackSize,
|
||||
PRThreadPriority priority,
|
||||
PRThreadScope scope);
|
||||
nsIRunnable* GetRequest();
|
||||
|
||||
protected:
|
||||
nsISupportsArray* mThreads;
|
||||
nsISupportsArray* mRequests;
|
||||
PRMonitor* mRequestMonitor;
|
||||
PRUint32 mMinThreads;
|
||||
PRUint32 mMaxThreads;
|
||||
PRBool mShuttingDown;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsThreadPoolRunnable : public nsIRunnable
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIRunnable methods:
|
||||
NS_IMETHOD Run();
|
||||
|
||||
// nsThreadPoolRunnable methods:
|
||||
nsThreadPoolRunnable(nsThreadPool* pool);
|
||||
virtual ~nsThreadPoolRunnable();
|
||||
|
||||
protected:
|
||||
nsThreadPool* mPool;
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // nsThread_h__
|
||||
@@ -44,18 +44,6 @@ public:
|
||||
nsTime(void) : mValue(PR_Now()) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the time from a string.
|
||||
*/
|
||||
nsTime(const char* dateStr, PRBool defaultToGMT) {
|
||||
PRInt64 time;
|
||||
PRStatus status = PR_ParseTimeString(dateStr, defaultToGMT, &time);
|
||||
if (status == PR_SUCCESS)
|
||||
mValue = time;
|
||||
else
|
||||
mValue = LL_ZERO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a time from a PRTime.
|
||||
*/
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user