Compare commits
2 Commits
release
...
tags/XPCOM
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9627efa0fd | ||
|
|
0a86e1bb4b |
40
mozilla/LEGAL
Normal file
40
mozilla/LEGAL
Normal file
@@ -0,0 +1,40 @@
|
||||
Please be apprised of the following Legal Notices:
|
||||
|
||||
A) The U.S. District Court for the Eastern District of Virginia has
|
||||
ruled that the Netscape Navigator code does not infringe Wang's U.S.
|
||||
Patent No. 4,751,669 ("the '669 Patent") because: 1) HTML is not
|
||||
Videotex as defined by the '669 patent; 2) web servers are not central
|
||||
suppliers; and 3) Navigator does not "connect," as defined by the '669
|
||||
Patent, to web servers on the Internet. Wang may appeal this decision to
|
||||
the Federal Circuit. Wang contended that its Patent disclosing a
|
||||
"Videotext" system, is infringed by the following functionality in the
|
||||
Netscape Navigator code: 1) the animated logo and status line indicators
|
||||
--See Claims 1,8 and 9; 2) the "File Save As" function --See Claims
|
||||
23-27; 3) Bookmarks and Rename Bookmarks in the Properties window --See
|
||||
Claims 20-22; 4) storing HTML, GIF, and JPEG files and adding filename
|
||||
extensions --See Claim 38
|
||||
|
||||
B) Intermind owns pending U.S. patent applications on communications
|
||||
systems which employ metadata ("channel objects") to define a control
|
||||
structure for information transfer. The Netscape code does not infringe
|
||||
as released; however, modifications which utilize channel objects as
|
||||
described by Intermind should be considered carefully. The following is
|
||||
a statement from Intermind: "Intermind's claims fundamentally involve
|
||||
the use of a control structure to automate communications. ...The
|
||||
essence of Intermind's top claim is that two devices sender and
|
||||
receiver have persistent storage, communicate over a network,
|
||||
and exchange a control structure including metadata which describes: 1)
|
||||
what information is to be updated, 2) when to update this information,
|
||||
and 3) how to transfer the updated information. In addition, at least
|
||||
the receiving device must be able to process the metadata in order to
|
||||
perform the update determination and transfer. Any digital
|
||||
communications system which incorporates all of these elements will be
|
||||
covered by Intermind's patents." See Intermind.com.
|
||||
|
||||
C) Stac, Inc., and its licensing agent Hi/fn, own several patents which
|
||||
disclose data compression methods implementing an LZS compression
|
||||
algorithm, including U.S. Patent Nos. 4,701,745 and 5,016, 009 ("the
|
||||
Stac Patents"). The Netscape Communicator code does not perform
|
||||
compression. If you modify the Netscape source code to perform
|
||||
compression, please take notice of the Stac Patents.
|
||||
|
||||
421
mozilla/LICENSE
Normal file
421
mozilla/LICENSE
Normal file
@@ -0,0 +1,421 @@
|
||||
NETSCAPE PUBLIC LICENSE
|
||||
Version 1.0
|
||||
|
||||
----------------
|
||||
|
||||
1. Definitions.
|
||||
|
||||
1.1. ``Contributor'' means each entity that creates or contributes to
|
||||
the creation of Modifications.
|
||||
|
||||
1.2. ``Contributor Version'' means the combination of the Original
|
||||
Code, prior Modifications used by a Contributor, and the Modifications
|
||||
made by that particular Contributor.
|
||||
|
||||
1.3. ``Covered Code'' means the Original Code or Modifications or the
|
||||
combination of the Original Code and Modifications, in each case
|
||||
including portions thereof.
|
||||
|
||||
1.4. ``Electronic Distribution Mechanism'' means a mechanism generally
|
||||
accepted in the software development community for the electronic
|
||||
transfer of data.
|
||||
|
||||
1.5. ``Executable'' means Covered Code in any form other than Source
|
||||
Code.
|
||||
|
||||
1.6. ``Initial Developer'' means the individual or entity identified as
|
||||
the Initial Developer in the Source Code notice required by Exhibit A.
|
||||
|
||||
1.7. ``Larger Work'' means a work which combines Covered Code or
|
||||
portions thereof with code not governed by the terms of this License.
|
||||
|
||||
1.8. ``License'' means this document.
|
||||
|
||||
1.9. ``Modifications'' means any addition to or deletion from the
|
||||
substance or structure of either the Original Code or any previous
|
||||
Modifications. When Covered Code is released as a series of files, a
|
||||
Modification is:
|
||||
|
||||
A. Any addition to or deletion from the contents of a file
|
||||
containing Original Code or previous Modifications.
|
||||
|
||||
B. Any new file that contains any part of the Original Code or
|
||||
previous Modifications.
|
||||
|
||||
1.10. ``Original Code'' means Source Code of computer software code
|
||||
which is described in the Source Code notice required by Exhibit A as
|
||||
Original Code, and which, at the time of its release under this License
|
||||
is not already Covered Code governed by this License.
|
||||
|
||||
1.11. ``Source Code'' means the preferred form of the Covered Code for
|
||||
making modifications to it, including all modules it contains, plus any
|
||||
associated interface definition files, scripts used to control
|
||||
compilation and installation of an Executable, or a list of source code
|
||||
differential comparisons against either the Original Code or another
|
||||
well known, available Covered Code of the Contributor's choice. The
|
||||
Source Code can be in a compressed or archival form, provided the
|
||||
appropriate decompression or de-archiving software is widely available
|
||||
for no charge.
|
||||
|
||||
1.12. ``You'' means an individual or a legal entity exercising rights
|
||||
under, and complying with all of the terms of, this License or a future
|
||||
version of this License issued under Section 6.1. For legal entities,
|
||||
``You'' includes any entity which controls, is controlled by, or is
|
||||
under common control with You. For purposes of this definition,
|
||||
``control'' means (a) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (b) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares or beneficial ownership of such entity.
|
||||
|
||||
2. Source Code License.
|
||||
|
||||
2.1. The Initial Developer Grant.
|
||||
The Initial Developer hereby grants You a world-wide, royalty-free,
|
||||
non-exclusive license, subject to third party intellectual property
|
||||
claims:
|
||||
|
||||
(a) to use, reproduce, modify, display, perform, sublicense and
|
||||
distribute the Original Code (or portions thereof) with or without
|
||||
Modifications, or as part of a Larger Work; and
|
||||
|
||||
(b) under patents now or hereafter owned or controlled by Initial
|
||||
Developer, to make, have made, use and sell (``Utilize'') the
|
||||
Original Code (or portions thereof), but solely to the extent that
|
||||
any such patent is reasonably necessary to enable You to Utilize
|
||||
the Original Code (or portions thereof) and not to any greater
|
||||
extent that may be necessary to Utilize further Modifications or
|
||||
combinations.
|
||||
|
||||
2.2. Contributor Grant.
|
||||
Each Contributor hereby grants You a world-wide, royalty-free,
|
||||
non-exclusive license, subject to third party intellectual property
|
||||
claims:
|
||||
|
||||
(a) to use, reproduce, modify, display, perform, sublicense and
|
||||
distribute the Modifications created by such Contributor (or
|
||||
portions thereof) either on an unmodified basis, with other
|
||||
Modifications, as Covered Code or as part of a Larger Work; and
|
||||
|
||||
(b) under patents now or hereafter owned or controlled by
|
||||
Contributor, to Utilize the Contributor Version (or portions
|
||||
thereof), but solely to the extent that any such patent is
|
||||
reasonably necessary to enable You to Utilize the Contributor
|
||||
Version (or portions thereof), and not to any greater extent that
|
||||
may be necessary to Utilize further Modifications or combinations.
|
||||
|
||||
3. Distribution Obligations.
|
||||
|
||||
3.1. Application of License.
|
||||
The Modifications which You create or to which You contribute are
|
||||
governed by the terms of this License, including without limitation
|
||||
Section 2.2. The Source Code version of Covered Code may be distributed
|
||||
only under the terms of this License or a future version of this
|
||||
License released under Section 6.1, and You must include a copy of this
|
||||
License with every copy of the Source Code You distribute. You may not
|
||||
offer or impose any terms on any Source Code version that alters or
|
||||
restricts the applicable version of this License or the recipients'
|
||||
rights hereunder. However, You may include an additional document
|
||||
offering the additional rights described in Section 3.5.
|
||||
|
||||
3.2. Availability of Source Code.
|
||||
Any Modification which You create or to which You contribute must be
|
||||
made available in Source Code form under the terms of this License
|
||||
either on the same media as an Executable version or via an accepted
|
||||
Electronic Distribution Mechanism to anyone to whom you made an
|
||||
Executable version available; and if made available via Electronic
|
||||
Distribution Mechanism, must remain available for at least twelve (12)
|
||||
months after the date it initially became available, or at least six
|
||||
(6) months after a subsequent version of that particular Modification
|
||||
has been made available to such recipients. You are responsible for
|
||||
ensuring that the Source Code version remains available even if the
|
||||
Electronic Distribution Mechanism is maintained by a third party.
|
||||
|
||||
3.3. Description of Modifications.
|
||||
You must cause all Covered Code to which you contribute to contain a
|
||||
file documenting the changes You made to create that Covered Code and
|
||||
the date of any change. You must include a prominent statement that the
|
||||
Modification is derived, directly or indirectly, from Original Code
|
||||
provided by the Initial Developer and including the name of the Initial
|
||||
Developer in (a) the Source Code, and (b) in any notice in an
|
||||
Executable version or related documentation in which You describe the
|
||||
origin or ownership of the Covered Code.
|
||||
|
||||
3.4. Intellectual Property Matters
|
||||
|
||||
(a) Third Party Claims.
|
||||
If You have knowledge that a party claims an intellectual property
|
||||
right in particular functionality or code (or its utilization
|
||||
under this License), you must include a text file with the source
|
||||
code distribution titled ``LEGAL'' which describes the claim and
|
||||
the party making the claim in sufficient detail that a recipient
|
||||
will know whom to contact. If you obtain such knowledge after You
|
||||
make Your Modification available as described in Section 3.2, You
|
||||
shall promptly modify the LEGAL file in all copies You make
|
||||
available thereafter and shall take other steps (such as notifying
|
||||
appropriate mailing lists or newsgroups) reasonably calculated to
|
||||
inform those who received the Covered Code that new knowledge has
|
||||
been obtained.
|
||||
|
||||
(b) Contributor APIs.
|
||||
If Your Modification is an application programming interface and
|
||||
You own or control patents which are reasonably necessary to
|
||||
implement that API, you must also include this information in the
|
||||
LEGAL file.
|
||||
|
||||
3.5. Required Notices.
|
||||
You must duplicate the notice in Exhibit A in each file of the Source
|
||||
Code, and this License in any documentation for the Source Code, where
|
||||
You describe recipients' rights relating to Covered Code. If You
|
||||
created one or more Modification(s), You may add your name as a
|
||||
Contributor to the notice described in Exhibit A. If it is not possible
|
||||
to put such notice in a particular Source Code file due to its
|
||||
structure, then you must include such notice in a location (such as a
|
||||
relevant directory file) where a user would be likely to look for such
|
||||
a notice. You may choose to offer, and to charge a fee for, warranty,
|
||||
support, indemnity or liability obligations to one or more recipients
|
||||
of Covered Code. However, You may do so only on Your own behalf, and
|
||||
not on behalf of the Initial Developer or any Contributor. You must
|
||||
make it absolutely clear than any such warranty, support, indemnity or
|
||||
liability obligation is offered by You alone, and You hereby agree to
|
||||
indemnify the Initial Developer and every Contributor for any liability
|
||||
incurred by the Initial Developer or such Contributor as a result of
|
||||
warranty, support, indemnity or liability terms You offer.
|
||||
|
||||
3.6. Distribution of Executable Versions.
|
||||
You may distribute Covered Code in Executable form only if the
|
||||
requirements of Section 3.1-3.5 have been met for that Covered Code,
|
||||
and if You include a notice stating that the Source Code version of the
|
||||
Covered Code is available under the terms of this License, including a
|
||||
description of how and where You have fulfilled the obligations of
|
||||
Section 3.2. The notice must be conspicuously included in any notice in
|
||||
an Executable version, related documentation or collateral in which You
|
||||
describe recipients' rights relating to the Covered Code. You may
|
||||
distribute the Executable version of Covered Code under a license of
|
||||
Your choice, which may contain terms different from this License,
|
||||
provided that You are in compliance with the terms of this License and
|
||||
that the license for the Executable version does not attempt to limit
|
||||
or alter the recipient's rights in the Source Code version from the
|
||||
rights set forth in this License. If You distribute the Executable
|
||||
version under a different license You must make it absolutely clear
|
||||
that any terms which differ from this License are offered by You alone,
|
||||
not by the Initial Developer or any Contributor. You hereby agree to
|
||||
indemnify the Initial Developer and every Contributor for any liability
|
||||
incurred by the Initial Developer or such Contributor as a result of
|
||||
any such terms You offer.
|
||||
|
||||
3.7. Larger Works.
|
||||
You may create a Larger Work by combining Covered Code with other code
|
||||
not governed by the terms of this License and distribute the Larger
|
||||
Work as a single product. In such a case, You must make sure the
|
||||
requirements of this License are fulfilled for the Covered Code.
|
||||
|
||||
4. Inability to Comply Due to Statute or Regulation.
|
||||
|
||||
If it is impossible for You to comply with any of the terms of this
|
||||
License with respect to some or all of the Covered Code due to statute
|
||||
or regulation then You must: (a) comply with the terms of this License
|
||||
to the maximum extent possible; and (b) describe the limitations and
|
||||
the code they affect. Such description must be included in the LEGAL
|
||||
file described in Section 3.4 and must be included with all
|
||||
distributions of the Source Code. Except to the extent prohibited by
|
||||
statute or regulation, such description must be sufficiently detailed
|
||||
for a recipient of ordinary skill to be able to understand it.
|
||||
|
||||
5. Application of this License.
|
||||
|
||||
This License applies to code to which the Initial Developer has
|
||||
attached the notice in Exhibit A, and to related Covered Code.
|
||||
|
||||
6. Versions of the License.
|
||||
|
||||
6.1. New Versions.
|
||||
Netscape Communications Corporation (``Netscape'') may publish revised
|
||||
and/or new versions of the License from time to time. Each version will
|
||||
be given a distinguishing version number.
|
||||
|
||||
6.2. Effect of New Versions.
|
||||
Once Covered Code has been published under a particular version of the
|
||||
License, You may always continue to use it under the terms of that
|
||||
version. You may also choose to use such Covered Code under the terms
|
||||
of any subsequent version of the License published by Netscape. No one
|
||||
other than Netscape has the right to modify the terms applicable to
|
||||
Covered Code created under this License.
|
||||
|
||||
6.3. Derivative Works.
|
||||
If you create or use a modified version of this License (which you may
|
||||
only do in order to apply it to code which is not already Covered Code
|
||||
governed by this License), you must (a) rename Your license so that the
|
||||
phrases ``Mozilla'', ``MOZILLAPL'', ``MOZPL'', ``Netscape'', ``NPL'' or
|
||||
any confusingly similar phrase do not appear anywhere in your license
|
||||
and (b) otherwise make it clear that your version of the license
|
||||
contains terms which differ from the Mozilla Public License and
|
||||
Netscape Public License. (Filling in the name of the Initial Developer,
|
||||
Original Code or Contributor in the notice described in Exhibit A shall
|
||||
not of themselves be deemed to be modifications of this License.)
|
||||
|
||||
7. DISCLAIMER OF WARRANTY.
|
||||
|
||||
COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN ``AS IS'' BASIS,
|
||||
WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
||||
WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF
|
||||
DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING.
|
||||
THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE
|
||||
IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT,
|
||||
YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE
|
||||
COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER
|
||||
OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
|
||||
ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
|
||||
|
||||
8. TERMINATION.
|
||||
|
||||
This License and the rights granted hereunder will terminate
|
||||
automatically if You fail to comply with terms herein and fail to cure
|
||||
such breach within 30 days of becoming aware of the breach. All
|
||||
sublicenses to the Covered Code which are properly granted shall
|
||||
survive any termination of this License. Provisions which, by their
|
||||
nature, must remain in effect beyond the termination of this License
|
||||
shall survive.
|
||||
|
||||
9. LIMITATION OF LIABILITY.
|
||||
|
||||
UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
|
||||
(INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE INITIAL
|
||||
DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE,
|
||||
OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO YOU OR ANY OTHER
|
||||
PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
||||
OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF
|
||||
GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND
|
||||
ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE
|
||||
BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
|
||||
LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY
|
||||
RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW
|
||||
PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE
|
||||
EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THAT
|
||||
EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
|
||||
|
||||
10. U.S. GOVERNMENT END USERS.
|
||||
|
||||
The Covered Code is a ``commercial item,'' as that term is defined in
|
||||
48 C.F.R. 2.101 (Oct. 1995), consisting of ``commercial computer
|
||||
software'' and ``commercial computer software documentation,'' as such
|
||||
terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48
|
||||
C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995),
|
||||
all U.S. Government End Users acquire Covered Code with only those
|
||||
rights set forth herein.
|
||||
|
||||
11. MISCELLANEOUS.
|
||||
|
||||
This License represents the complete agreement concerning subject
|
||||
matter hereof. If any provision of this License is held to be
|
||||
unenforceable, such provision shall be reformed only to the extent
|
||||
necessary to make it enforceable. This License shall be governed by
|
||||
California law provisions (except to the extent applicable law, if any,
|
||||
provides otherwise), excluding its conflict-of-law provisions. With
|
||||
respect to disputes in which at least one party is a citizen of, or an
|
||||
entity chartered or registered to do business in, the United States of
|
||||
America: (a) unless otherwise agreed in writing, all disputes relating
|
||||
to this License (excepting any dispute relating to intellectual
|
||||
property rights) shall be subject to final and binding arbitration,
|
||||
with the losing party paying all costs of arbitration; (b) any
|
||||
arbitration relating to this Agreement shall be held in Santa Clara
|
||||
County, California, under the auspices of JAMS/EndDispute; and (c) any
|
||||
litigation relating to this Agreement shall be subject to the
|
||||
jurisdiction of the Federal Courts of the Northern District of
|
||||
California, with venue lying in Santa Clara County, California, with
|
||||
the losing party responsible for costs, including without limitation,
|
||||
court costs and reasonable attorneys fees and expenses. The application
|
||||
of the United Nations Convention on Contracts for the International
|
||||
Sale of Goods is expressly excluded. Any law or regulation which
|
||||
provides that the language of a contract shall be construed against the
|
||||
drafter shall not apply to this License.
|
||||
|
||||
12. RESPONSIBILITY FOR CLAIMS.
|
||||
|
||||
Except in cases where another Contributor has failed to comply with
|
||||
Section 3.4, You are responsible for damages arising, directly or
|
||||
indirectly, out of Your utilization of rights under this License, based
|
||||
on the number of copies of Covered Code you made available, the
|
||||
revenues you received from utilizing such rights, and other relevant
|
||||
factors. You agree to work with affected parties to distribute
|
||||
responsibility on an equitable basis.
|
||||
|
||||
AMENDMENTS
|
||||
Additional Terms applicable to the Netscape Public License.
|
||||
|
||||
I. Effect.
|
||||
These additional terms described in this Netscape Public License --
|
||||
Amendments shall apply to the Mozilla Communicator client code and to
|
||||
all Covered Code under this License.
|
||||
|
||||
II. ``Netscape's Branded Code'' means Covered Code that Netscape
|
||||
distributes and/or permits others to distribute under one or more
|
||||
trademark(s) which are controlled by Netscape but which are not
|
||||
licensed for use under this License.
|
||||
|
||||
III. Netscape and logo.
|
||||
This License does not grant any rights to use the trademark
|
||||
``Netscape'', the ``Netscape N and horizon'' logo or the Netscape
|
||||
lighthouse logo, even if such marks are included in the Original Code.
|
||||
|
||||
IV. Inability to Comply Due to Contractual Obligation.
|
||||
Prior to licensing the Original Code under this License, Netscape has
|
||||
licensed third party code for use in Netscape's Branded Code. To the
|
||||
extent that Netscape is limited contractually from making such third
|
||||
party code available under this License, Netscape may choose to
|
||||
reintegrate such code into Covered Code without being required to
|
||||
distribute such code in Source Code form, even if such code would
|
||||
otherwise be considered ``Modifications'' under this License.
|
||||
|
||||
V. Use of Modifications and Covered Code by Initial Developer.
|
||||
|
||||
V.1. In General.
|
||||
The obligations of Section 3 apply to Netscape, except to the
|
||||
extent specified in this Amendment, Section V.2 and V.3.
|
||||
|
||||
V.2. Other Products.
|
||||
Netscape may include Covered Code in products other than the
|
||||
Netscape's Branded Code which are released by Netscape during the
|
||||
two (2) years following the release date of the Original Code,
|
||||
without such additional products becoming subject to the terms of
|
||||
this License, and may license such additional products on
|
||||
different terms from those contained in this License.
|
||||
|
||||
V.3. Alternative Licensing.
|
||||
Netscape may license the Source Code of Netscape's Branded Code,
|
||||
including Modifications incorporated therein, without such
|
||||
additional products becoming subject to the terms of this License,
|
||||
and may license such additional products on different terms from
|
||||
those contained in this License.
|
||||
|
||||
VI. Arbitration and Litigation.
|
||||
Notwithstanding the limitations of Section 11 above, the provisions
|
||||
regarding arbitration and litigation in Section 11(a), (b) and (c) of
|
||||
the License shall apply to all disputes relating to this License.
|
||||
|
||||
EXHIBIT A.
|
||||
|
||||
``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.
|
||||
|
||||
Contributor(s): ______________________________________.''
|
||||
|
||||
[NOTE: The text of this Exhibit A may differ slightly from the text of
|
||||
the notices in the Source Code files of the Original Code. This is due
|
||||
to time constraints encountered in simultaneously finalizing the
|
||||
License and in preparing the Original Code for release. You should use
|
||||
the text of this Exhibit A rather than the text found in the Original
|
||||
Code Source Code for Your Modifications.]
|
||||
101
mozilla/Makefile.in
Normal file
101
mozilla/Makefile.in
Normal file
@@ -0,0 +1,101 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
DEPTH = .
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
# The list of directories that need to be built to build the standalone
|
||||
# nglayout test program. The order is important.
|
||||
DIRS = \
|
||||
config \
|
||||
build \
|
||||
$(NULL)
|
||||
|
||||
ifndef MOZ_NATIVE_NSPR
|
||||
DIRS += $(topsrcdir)/nsprpub
|
||||
endif
|
||||
|
||||
DIRS += \
|
||||
dbm \
|
||||
modules/libreg \
|
||||
xpcom \
|
||||
$(NULL)
|
||||
|
||||
ifndef MOZ_NATIVE_ZLIB
|
||||
DIRS += modules/zlib
|
||||
endif
|
||||
|
||||
ifndef MOZ_NATIVE_JPEG
|
||||
DIRS += jpeg
|
||||
endif
|
||||
|
||||
DIRS += \
|
||||
modules/libutil \
|
||||
base \
|
||||
intl \
|
||||
js \
|
||||
modules/security/freenav \
|
||||
modules/libpref \
|
||||
modules/libimg \
|
||||
modules/oji \
|
||||
modules/plugin \
|
||||
modules/libjar \
|
||||
caps \
|
||||
lib/xp \
|
||||
lib/libpwcac \
|
||||
network \
|
||||
htmlparser \
|
||||
expat \
|
||||
gfx \
|
||||
dom \
|
||||
view \
|
||||
widget \
|
||||
layout \
|
||||
rdf \
|
||||
webshell \
|
||||
editor \
|
||||
silentdl \
|
||||
xpinstall \
|
||||
sun-java \
|
||||
profile \
|
||||
$(NULL)
|
||||
|
||||
ifdef MOZ_BUILD_XPFE
|
||||
DIRS += xpfe extensions
|
||||
endif
|
||||
|
||||
ifdef MOZ_MAIL_NEWS
|
||||
DIRS += mailnews
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
real_all: all
|
||||
|
||||
real_export: export
|
||||
|
||||
real_libs: libs
|
||||
|
||||
real_install: install
|
||||
|
||||
real_clobber: clobber
|
||||
|
||||
real_depend: depend
|
||||
BIN
mozilla/README/mozilla/IDEMenuBar.gif
Normal file
BIN
mozilla/README/mozilla/IDEMenuBar.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
BIN
mozilla/README/mozilla/IDEPrefs.gif
Normal file
BIN
mozilla/README/mozilla/IDEPrefs.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
443
mozilla/README/mozilla/classic-mac.html
Normal file
443
mozilla/README/mozilla/classic-mac.html
Normal file
@@ -0,0 +1,443 @@
|
||||
|
||||
<HEAD>
|
||||
<TITLE>Building Mozilla on the Macintosh PPC platform</TITLE>
|
||||
</HEAD>
|
||||
<BODY BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B">
|
||||
<P>
|
||||
|
||||
<HR>
|
||||
|
||||
</P>
|
||||
|
||||
<H1>Building Mozilla on the Macintosh PPC platform</H1>
|
||||
|
||||
<H2>Daniel Nunes, <A HREF="mailto:leaf@netscape.com"><TT>leaf@netscape.com</TT></A></H2>
|
||||
|
||||
<P>v 1.1, 1998-9-29<BR>
|
||||
updated for the Pro4 IDE</P>
|
||||
|
||||
<P>
|
||||
|
||||
<HR>
|
||||
|
||||
<I>How to build Mozilla on a Macintosh PPC System.</I>
|
||||
|
||||
<HR>
|
||||
|
||||
</P>
|
||||
|
||||
<H2>1. <A HREF="#s1">Introduction</A></H2>
|
||||
|
||||
<H2>2. <A HREF="#s2">Building Mozilla</A></H2>
|
||||
|
||||
<UL>
|
||||
<LI><A HREF="#ss2.1">2.1 Get the Code </A></LI>
|
||||
|
||||
<LI><A HREF="#ss2.2">2.2 Requirements</A></LI>
|
||||
|
||||
<LI><A HREF="#ss2.3">2.3 Set up the Build Environment</A></LI>
|
||||
|
||||
<LI><A HREF="#ss2.4">2.4 Build the Lizard </A></LI>
|
||||
</UL>
|
||||
|
||||
<H2>3. <A HREF="#s3"> Common Problems </A></H2>
|
||||
|
||||
<H2>4. <A HREF="#s4"> Credits </A></H2>
|
||||
|
||||
<P>
|
||||
|
||||
<HR>
|
||||
|
||||
</P>
|
||||
|
||||
<H2><A NAME=s1></A>1. Introduction</H2>
|
||||
|
||||
<P>What this document is: A guide to building the Mozilla
|
||||
application. This includes:</P>
|
||||
|
||||
<OL>
|
||||
<LI>A listing of the development tools you will need to build
|
||||
Mozilla.</LI>
|
||||
|
||||
<LI>A list of environment variables you will need to set before
|
||||
building.</LI>
|
||||
</OL>
|
||||
|
||||
<P>If you're looking for documentation on developing features or
|
||||
fixing bugs, the Mozilla <A HREF="http://www.mozilla.org/docs/tplist/tplist.html">Technical
|
||||
Documents </A> or <A HREF="http://www.mozilla.org/library.html">
|
||||
Library </A> are probably what you're looking for.</P>
|
||||
|
||||
<P>
|
||||
|
||||
<HR>
|
||||
|
||||
</P>
|
||||
|
||||
<H2><A NAME=s2></A>2. Building Mozilla</H2>
|
||||
|
||||
<P> </P>
|
||||
|
||||
<UL>
|
||||
<LI>Each of the following subsections describes, or gives
|
||||
references to descriptions of, the steps necessary to build
|
||||
Mozilla.
|
||||
|
||||
<H2><A NAME="ss2.1"></A>2.1 Get the Code</H2>
|
||||
|
||||
<P> </P>
|
||||
|
||||
<UL>
|
||||
<LI>There are two principal ways of getting the code, <A HREF="http://www.mozilla.org/download.html">
|
||||
ftp</A> and <A HREF="http://www.mozilla.org/cvs.html"> CVS</A>.
|
||||
CVS will provide the most current code for building, but is
|
||||
slower than ftp. Ftp drops are generally produced once per
|
||||
month, and are known to compile.</LI>
|
||||
</UL>
|
||||
|
||||
<P> </P>
|
||||
|
||||
<H2><A NAME="ss2.2"></A>2.2 Requirements</H2>
|
||||
|
||||
<P>The following need to be installed:</P>
|
||||
|
||||
<UL>
|
||||
<LI>CodeWarrior (CW) Pro4 - obtainable from <A HREF="http://www.metrowerks.com">Metrowerks</A>.
|
||||
See <A HREF="#s3">Common Sticking Points</A> if you have a
|
||||
different version. Mozilla will no longer build with anything
|
||||
earlier.</LI>
|
||||
|
||||
<LI>PowerPlant - obtainable from the CodeWarrior CD.</LI>
|
||||
|
||||
<LI>MSL - the Metrowerks Standard Library, obtainable from the
|
||||
CodeWarrior CD</LI>
|
||||
|
||||
<LI><A HREF="ftp://ftp.boingo.com//dan/WASTE/waste-13.hqx">WASTE
|
||||
1.3</A></LI>
|
||||
|
||||
<LI><A HREF="http://www.bact.wisc.edu/CWASTEEdit/CWASTEEdit.sit.hqx">CWASTE
|
||||
1.6.2</A></LI>
|
||||
|
||||
<LI><A HREF="ftp://ftp.scripting.com/userland/menuSharingToolkit4.1.sit.hqx">Menu
|
||||
Sharing Toolkit</A> (from UserLand)</LI>
|
||||
|
||||
<LI><A HREF="ftp://ftp.share.com/pub/internet-configuration/ICProgKit1.4.sit">Internet
|
||||
Config 1.4 SDK</A></LI>
|
||||
|
||||
<LI><A HREF="http://www.mooseyard.com/Jens/Software/">AEGizmos
|
||||
1.4.2</A></LI>
|
||||
|
||||
<LI><A HREF="ftp://sunsite.cnlab-switch.ch/software/platform/macos/perl/Mac_Perl_520r4_tool.bin">MacPerl
|
||||
5 MPW Tool</A></LI>
|
||||
|
||||
<LI><A HREF="ftp://sunsite.cnlab-switch.ch/software/platform/macos/perl/Mac_Perl_520r4_appl.bin">MacPerl
|
||||
5 Application</A></LI>
|
||||
|
||||
<LI>The module Mac:AppleEvents:Simple, which should be stored
|
||||
in your Perl library folder under :Mac:AppleEvents:Simple.pm,
|
||||
may be downloaded <A HREF="http://www.perl.com/CPAN-local/modules/by-module/Mac/Mac-AppleEvents-Simple-0.10.tgz">here</A>.</LI>
|
||||
|
||||
<LI>The module Mac:Apps:Launch, which should be stored in your
|
||||
Perl library folder under :Mac:Apps:Launch.pm, may be
|
||||
downloaded <A HREF="http://www.perl.com/CPAN-local/modules/by-module/Mac/Mac-Apps-Launch-1.30.tar.gz">here</A>.</LI>
|
||||
|
||||
<LI>MakeStub - MPW (installed with CodeWarrior Heaven option).
|
||||
If you choose not to install MPW, it is located on the MacOS
|
||||
Tools CD in "CW Pro 4 Tools:CodeWarrior MPW:MPW:Tools"</LI>
|
||||
|
||||
<LI>RunTSScript - in Mozilla source distribution
|
||||
(mozilla:build:mac:RunTSScript), needs to be installed by
|
||||
hand</LI>
|
||||
|
||||
<LI><A HREF="ftp://dev.apple.com/devworld/Tool_Chest/Core_Mac_OS_Tools/MPW_etc./MPW-GM/MPW/ToolServer.sit.hqx">ToolServer</A>
|
||||
- or in the CW distribution (CW Pro 4 Tools:Apple Development
|
||||
Tools:ToolServer 3.4.1.sit). <B>We recommend pulling it off the
|
||||
CD</B> because it comes with configuration files for
|
||||
CodeWarrior which you would have to create manually were you to
|
||||
pull it off the net.</LI>
|
||||
|
||||
<LI><A HREF="http://sunsite.cnlab-switch.ch/ftp/software/platform/macos/src/HTML/MPW_C.html">patch
|
||||
2.1</A></LI>
|
||||
</UL>
|
||||
|
||||
<P>Hardware/OS</P>
|
||||
|
||||
<UL>
|
||||
<LI>To build Navigator, you need a fast PPC Mac. The faster the
|
||||
better.</LI>
|
||||
|
||||
<LI>You will need about 96 MB of physical RAM to "fast link"
|
||||
the app. You can still fast link if you give your machine 96 MB
|
||||
of virtual memory, but then the VM hit is large enough to
|
||||
counteract any improvement. One of our beta testers had a
|
||||
machine with only 64MB of physical RAM (VM was off) and it ran
|
||||
out of memory trying to link. Turning VM on got it to link, but
|
||||
build time increased greatly.</LI>
|
||||
|
||||
<LI>Reports from the net indicate that the optimized version
|
||||
(MozillaPPC) take much less RAM to build than the 96MB we
|
||||
suggest. If you are running out of memory, try building that
|
||||
instead of the debug version (the debug symbols require a lot
|
||||
of RAM come link time).</LI>
|
||||
|
||||
<LI>You should be ok with a 400MB disk partition, even when
|
||||
fully built. This does not include tools like the IDE, just
|
||||
source.</LI>
|
||||
|
||||
<LI>On an HFS+ volume, a full build takes about 110MB. HFS+ is
|
||||
good, but utilities are sparse.</LI>
|
||||
</UL>
|
||||
|
||||
<P> </P>
|
||||
|
||||
<H2><A NAME="ss2.3"></A>2.3 Setup the Build Environment</H2>
|
||||
|
||||
<P> </P>
|
||||
|
||||
<OL>
|
||||
<LI>Install CodeWarrior from the CD. While it is large,
|
||||
installing the "CodeWarrior Heaven" option will guarantee that
|
||||
you have everything you need. This will give you PowerPlant,
|
||||
MSL, and MPW. If you choose to install less, proceed at your
|
||||
own risk.</LI>
|
||||
|
||||
<LI>In the Finder, increase the memory partition of the IDE to
|
||||
15MB (you can get by with 12, if need be).</LI>
|
||||
|
||||
<LI>Uncompress the StuffIt Archive for ToolServer. The goal is
|
||||
to let ToolServer and MPW share the same Tools directory so you
|
||||
don't need to have multiple versions of tools. Do the
|
||||
following:
|
||||
|
||||
<OL>
|
||||
<LI>Open ToolServer's Tools folder. There is one file called
|
||||
"RMetrowerks".</LI>
|
||||
|
||||
<LI>Move RMetrowerks to Tools folder of MPW. MPW folder must
|
||||
be at "Metrowerks:Codewarrior MPW:MPW" if you installed
|
||||
Codewarrior Heaven.</LI>
|
||||
|
||||
<LI>Remove ToolServer's Tools folder.</LI>
|
||||
|
||||
<LI>Now create an alias of Tools folder in "CodeWarrior MPW"
|
||||
and move it to your ToolServer folder. Rename the alias
|
||||
(probably called "Tools alias") to "Tools"</LI>
|
||||
|
||||
<LI><FONT COLOR="#FF0000"><B>IMPORTANT</B></FONT>: Make sure
|
||||
you only have one instance of ToolServer on your machine. If
|
||||
the build script finds the wrong one, the correct tools will
|
||||
not be found and strange things will happen.</LI>
|
||||
</OL>
|
||||
</LI>
|
||||
|
||||
<LI>After installing the MacPerl MPW Tool distribution (run the
|
||||
InstallerVISE application), in the "MacPerl ƒ" folder,
|
||||
there will be an MPW tool named "perl". Install this in MPW's
|
||||
tools folder.</LI>
|
||||
|
||||
<LI>Install the MacPerl Application (run the InstallerVISE
|
||||
application). You can install this anywhere, but it is
|
||||
recommended that you install it inside of your CodeWarrior
|
||||
folder for easy reference. After installation, you will need to
|
||||
set a preference to enable double-click launch of the perl
|
||||
scripts. This preference is set by going under the Edit Menu to
|
||||
Preferences. Click on the "Script" button and hit the radio
|
||||
button "Run Scripts opened from Finder"</LI>
|
||||
|
||||
<LI>Install the "patch" and "MakeStub" Tools in the tools
|
||||
folder. Note that "MakeStub" is automatically installed by the
|
||||
"CodeWarrior Heaven" install option.</LI>
|
||||
|
||||
<LI>Install RunTSScript (found in the Mozilla source
|
||||
distribution) in the compilers folder in your build environment
|
||||
("Metrowerks:Metrowerks Codewarrior:Codewarrior
|
||||
Plugins:Compilers")</LI>
|
||||
|
||||
<LI>Next, after downloading all the 3rd party software
|
||||
components, drag WASTE, CWASTE, Menu Sharing, Internet Config,
|
||||
and the AEGizmo folders (just as they are) into the "MacOS
|
||||
Support" folder in your build environment.</LI>
|
||||
|
||||
<LI>Create a folder inside the PowerPlant folder
|
||||
(Metrowerks:Metrowerks CodeWarrior:MacOS Support:PowerPlant)
|
||||
called "_Will Be Obsolete" Make sure you include the leading
|
||||
underscore.</LI>
|
||||
|
||||
<LI>Unstuff the obsolete LGA classes (located on the Reference
|
||||
CD in "CodeWarrior Examples:MacOS Examples:PowerPlant
|
||||
Examples:Obsolete PP Items:Old GA Classes.sit) and place the
|
||||
resulting folder into the "_Will Be Obsolete" folder you
|
||||
created in the previous step.</LI>
|
||||
|
||||
<LI>Start ToolServer from within CodeWarrior (or use MPW if you
|
||||
are brave enough). We're about to patch some files. Make sure
|
||||
the ToolServer menu is in the CodeWarrior menu bar by turning
|
||||
on the <A HREF="IDEPrefs.gif">preference</A> under the "Extras"
|
||||
panel in the IDE Preferences (not the project preferences!).
|
||||
The menu bar should look like this:
|
||||
|
||||
<P><IMG SRC="IDEMenuBar.gif" WIDTH=359 HEIGHT=20 X-CLARIS-USEIMAGEWIDTH X-CLARIS-USEIMAGEHEIGHT ALIGN=bottom></P>
|
||||
|
||||
<P>Choose "Start ToolServer" from the ToolServer menu (this is
|
||||
the icon menu between "Window" and "Help" in the menubar
|
||||
above). You will now see a window with no close box. This is
|
||||
your ToolServer Worksheet where you will type (or cut &
|
||||
paste) the commands for the following steps.</P>
|
||||
|
||||
<P>In case you have never used MPW/ToolServer before, the
|
||||
following is <B>very important</B>. Pressing "return" does not
|
||||
execute commands like you might think. It just inserts a
|
||||
newline into the worksheet like a normal text editor. <B>To
|
||||
actually get ToolServer to execute the command, you must press
|
||||
"Enter" (lower right of numeric keypad).</B> This executes the
|
||||
line that the cursor is on, and only that line. If you want to
|
||||
execute multiple lines at once, select them all and hit
|
||||
Enter.</P></LI>
|
||||
|
||||
<LI>Set the shell variables {IDE} and {Source} to the correct
|
||||
paths for your build environment. {IDE} is where your
|
||||
CodeWarrior IDE is located. {Source} is the folder containing
|
||||
the toplevel "ns" folder of the Mozilla source. Mine look like
|
||||
this (don't forget to keep the quotes if your path includes
|
||||
spaces), yours will almost certainly be different
|
||||
(<FONT COLOR="#FF0000">to punctuate this, the things you need
|
||||
to change are in red</FONT>).
|
||||
|
||||
<PRE>Set IDE "<FONT COLOR="#FF0000">Develop:CW Pro 4:Metrowerks CodeWarrior:</FONT>"
|
||||
Set Source "<FONT COLOR="#FF0000">Source:FreeSource:</FONT>"</PRE></LI>
|
||||
|
||||
<LI>Execute the following lines to patch menusharing.c to allow
|
||||
it to compile with the new Universal Headers. It references an
|
||||
obsolete header file (GestaltEqu.h).
|
||||
|
||||
<PRE>directory "{IDE}MacOS Support:Menu Sharing Toolkit 4.1:"
|
||||
patch menusharing.c "{Source}mozilla:lib:mac:patches:menusharing.patch"</PRE></LI>
|
||||
|
||||
<LI>You need to patch stat.mac.h to fix a problem in MSL where
|
||||
lines were omitted.
|
||||
|
||||
<PRE>directory "{IDE}Metrowerks Standard Library:MSL C:MSL Mac:Public Includes"
|
||||
patch stat.mac.h "{Source}mozilla:lib:mac:patches:stat.mac.h.patch"</PRE></LI>
|
||||
|
||||
<LI>Congratulations! Now you are ready to build. Once these
|
||||
steps are done, you don't have to repeat these setups the next
|
||||
time!</LI>
|
||||
</OL>
|
||||
|
||||
<P> </P>
|
||||
|
||||
<H2><A NAME="ss2.4"></A>2.4 Run the build</H2>
|
||||
|
||||
<UL>
|
||||
<LI>In the folder mozilla:build:mac:, there are several Perl
|
||||
scripts with names of the form BuildMozillaXXX.pl, where XXX is
|
||||
"Optimized", "Debug", "Tinderbox", et al. Each script builds
|
||||
the corresponding version of Mozilla. If you configured the
|
||||
MacPerl application to execute scripts that are opened from the
|
||||
finder, all you have to do is double click on the appropriate
|
||||
one; otherwise, launch MacPerl, and run the appropriate script
|
||||
from the "Run Script..." menu item.
|
||||
|
||||
<P>These `configured build' scripts are simple, and you might
|
||||
want to make your own to force your build to StopForErrors(),
|
||||
or alternatively DontStopForErrors(), et al. You can set up
|
||||
certain build-script variables and (soon) compile-time flags.
|
||||
Compare the supplied scripts to figure out what you might want.
|
||||
Note that CodeWarriorLib, Moz.pm, and BuildList.pm, are
|
||||
AppleScript libraries and Perl modules meant to be used by a
|
||||
`configured build'. Use your favorite POD viewer (Shuck comes
|
||||
with MacPerl) to view the documentation in the Perl
|
||||
scripts.</P>
|
||||
|
||||
<P>If there were any errors in any of the projects along the
|
||||
way, the script will stop at that point and the IDE will tell
|
||||
you the errors. You can fix them and make sure they current
|
||||
project builds, but to continue the automation, you have to
|
||||
start from the beginning by double-clicking the script again.
|
||||
This isn't quite as bad as it sounds because the previous
|
||||
projects are already built (unless you changed some major
|
||||
header file). Please note that stopping the script once it has
|
||||
started is difficult. We are working to address this issue.</P>
|
||||
|
||||
<P>After the build is complete, you can find aliases to the
|
||||
built libraries and the final Mozilla application. Debug builds
|
||||
are built to Mozilla:dist:client_debug, while optimized builds
|
||||
are built to Mozilla:dist:client.</P>
|
||||
|
||||
<P>Don't worry too much about the numerous warnings generated
|
||||
during the build. We try our best to get the XP teams to use
|
||||
real compilers, but alas, they continue to write warning-laden
|
||||
code. There is also some generated code (Java is one example)
|
||||
that has a lot of warnings that we can't help either. If you
|
||||
write any new code, please help us in our quest to get zero
|
||||
warnings.</P></LI>
|
||||
</UL>
|
||||
</LI>
|
||||
</UL>
|
||||
|
||||
<P>
|
||||
|
||||
<HR>
|
||||
|
||||
</P>
|
||||
|
||||
<H2><A NAME=s3></A>3. Common Sticking Points</H2>
|
||||
|
||||
<UL>
|
||||
<LI><B>I only have CodeWarrior Pro3 or Pro2. How do i build with
|
||||
it?</B>
|
||||
|
||||
<UL>
|
||||
<LI>Currently, the answer is, "You don't." We make use of
|
||||
several classes in PowerPlant which recently appeared in Pro4.
|
||||
Time to upgrade, I'm afraid. Don't even try opening the
|
||||
projects with Pro2 because you will get data loss and have to
|
||||
throw the project away (it won't even prompt you!)</LI>
|
||||
</UL>
|
||||
</LI>
|
||||
|
||||
<LI><B>I'm having problems building. MacPerl tells me it can't
|
||||
fine MemAllocatorStubs</B>
|
||||
|
||||
<UL>
|
||||
<LI>It sounds like your ToolServer environment is not setup
|
||||
correctly. Make sure you follow the directions to the letter.
|
||||
You could also be seeing this if you have multiple versions of
|
||||
ToolServer on your computer and the Finder lauches the wrong
|
||||
one. This is very common, as the <I>Carbon Dater</I> app from
|
||||
Apple DTS contains a copy of ToolServer. Either remove all the
|
||||
other versions of ToolServer or make sure you launch the
|
||||
appropriate version before you start building.</LI>
|
||||
</UL>
|
||||
</LI>
|
||||
|
||||
<LI><B>The IDE runs out of memory building jsinterp.c. What do I
|
||||
do?</B>
|
||||
|
||||
<UL>
|
||||
<LI>We have seen this every now and then, and it only appears
|
||||
to show up when building optimized (non-debug) builds. You can
|
||||
normally get around this by building that file by itself
|
||||
(select it and choose "Compile") and then continuing the make.
|
||||
We're not sure why this is happening, so if you have any
|
||||
answers or solutions, please let us know!</LI>
|
||||
</UL>
|
||||
</LI>
|
||||
</UL>
|
||||
|
||||
<P>
|
||||
|
||||
<HR>
|
||||
|
||||
</P>
|
||||
|
||||
<H2><A NAME=s4></A>4. Credits</H2>
|
||||
|
||||
<UL>
|
||||
<LI>The majority of this document is taken from the build document
|
||||
included in the Mozilla source distribution at
|
||||
README:mozilla:macbuild.htm written by Mike Pinkerton, <A HREF="mailto:pinkerton@netscape.com">
|
||||
pinkerton@netscape.com</A>.</LI>
|
||||
</UL>
|
||||
</BODY>
|
||||
</HTML>
|
||||
158
mozilla/README/mozilla/classic-unix.html
Normal file
158
mozilla/README/mozilla/classic-unix.html
Normal file
@@ -0,0 +1,158 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Building Mozilla on unix platforms</TITLE>
|
||||
</HEAD>
|
||||
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000EE" VLINK="#551A8B"
|
||||
ALINK="#FF0000">
|
||||
<HR>
|
||||
<H1>
|
||||
Building Mozilla on Unix platforms</H1>
|
||||
|
||||
<H2>
|
||||
Daniel Nunes, <TT><A HREF="mailto:leaf@netscape.com">leaf@netscape.com</A></TT></H2>
|
||||
v 1.1, June 1998
|
||||
|
||||
<P>
|
||||
<HR><I>How to build Mozilla on a Unix System.</I>
|
||||
<HR>
|
||||
<H2>1. <A HREF="#s1">Introduction</A></H2>
|
||||
|
||||
<H2>2. <A HREF="#s2">Building Mozilla</A></H2>
|
||||
|
||||
<UL>
|
||||
<LI>
|
||||
<A HREF="#ss2.1">2.1 Get the Code </A></LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="#ss2.2">2.2 Requirements</A></LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="#ss2.3">2.3 Set up the Build Environment</A></LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="#ss2.4">2.4 Build the Lizard </A></LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="#ss2.5">2.5 Run the Lizard </A></LI>
|
||||
</UL>
|
||||
|
||||
<H2>3. <A HREF="#s3"> Common Problems </A></H2>
|
||||
|
||||
<HR>
|
||||
<H2><A NAME="s1">1. Introduction</A></H2>
|
||||
|
||||
<P>
|
||||
What this document is: A guide to building the Mozilla application.
|
||||
<BR>
|
||||
This includes:
|
||||
<OL>
|
||||
<LI> A listing of the development tools you will need to build Mozilla. </LI>
|
||||
<LI> A list of environment variables you will need to set before building. </LI>
|
||||
</OL>
|
||||
<P>
|
||||
If you're looking for documentation on developing features or fixing bugs,
|
||||
the Mozilla
|
||||
<A HREF="http://www.mozilla.org/docs/tplist/tplist.html">Technical Documents
|
||||
</A> or <A HREF="http://www.mozilla.org/library.html"> Library </A>
|
||||
are probably what you're looking for.
|
||||
<P>
|
||||
<HR>
|
||||
<H2><A NAME="s2">2. Building Mozilla </A></H2>
|
||||
<P>
|
||||
<UL>Each of the following subsections describes, or gives references to
|
||||
descriptions of, the steps necessary to build Mozilla.
|
||||
</UL>
|
||||
<H2><A NAME="ss2.1">2.1 Get the Code</A></H2>
|
||||
<P>
|
||||
<UL>
|
||||
There are two principal ways of getting the code,
|
||||
<A HREF="http://www.mozilla.org/download.html"> ftp</A> and
|
||||
<A HREF="http://www.mozilla.org/cvs.html"> CVS</A>.
|
||||
CVS will provide the most current code for building, but is
|
||||
slower than ftp. Ftp drops are generally produced once per month,
|
||||
and are known to compile.
|
||||
</UL>
|
||||
<P>
|
||||
<H2><A NAME="ss2.2">2.2 Requirements</A></H2>
|
||||
<UL>
|
||||
The following should be installed:
|
||||
<UL>
|
||||
<LI>Motif 1.2
|
||||
<LI>The native C/C++ compiler (or GNU C/C++ compiler 2.7.2 in lieu of the
|
||||
native compiler)
|
||||
<LI>GNU make 3.74 or better
|
||||
<LI>Perl (or, if you have no Perl, then set <CODE>PERL=/bin/echo</CODE>)
|
||||
</UL>
|
||||
<P>
|
||||
Your hardware should be equal to, or better than:
|
||||
<UL>
|
||||
32 MB RAM, 128 MB swap (64 MB RAM recommended)
|
||||
</UL>
|
||||
</UL>
|
||||
<P>
|
||||
<H2><A NAME="ss2.3">2.3 Setup the Build Environment</A></H2>
|
||||
<P>
|
||||
<UL>
|
||||
The following environment variables need to be set:
|
||||
<CODE>
|
||||
<PRE>
|
||||
MOZILLA_CLIENT=1
|
||||
MOZ_MEDIUM=1
|
||||
NO_MDUPDATE=1
|
||||
</PRE>
|
||||
</CODE>
|
||||
Optionally, you can set <CODE>BUILD_OPT=1</CODE> if you don't want a debug
|
||||
build.
|
||||
<P>
|
||||
If your Motif libraries are installed in a non-standard place, you can tell
|
||||
the Mozilla makefiles where to look by setting
|
||||
<CODE>MOZILLA_MOTIF_SEARCH_PATH</CODE> to point to the directory in which
|
||||
your Motif installation resides.
|
||||
<P>
|
||||
Environment variables are set by the shell, and there are two common ways
|
||||
of setting them. <BR>
|
||||
Type <CODE>setenv VARIABLE value</CODE> or <CODE>export VARIABLE=value</CODE>.
|
||||
<P>
|
||||
</UL>
|
||||
|
||||
<H2><A NAME="ss2.4">2.4 Run the build </A></H2>
|
||||
<UL>
|
||||
Change to the directory you copied the source into (for example,
|
||||
<CODE>cd /builds</CODE>). If this directory was empty before you
|
||||
installed the source, there should be two directories here:
|
||||
<CODE>README</CODE> and <CODE>mozilla</CODE>.
|
||||
<CODE>
|
||||
<PRE>
|
||||
cd mozilla
|
||||
gmake
|
||||
</PRE>
|
||||
</CODE>
|
||||
</UL>
|
||||
<H2><A NAME="ss2.5">2.5 After the build </A></H2>
|
||||
<UL>
|
||||
You may notice that if you try running mozilla-export right after the build,
|
||||
you'll run into a problem. You need to set <CODE>LD_LIBRARY_PATH</CODE> to
|
||||
<CODE>
|
||||
${LD_LIBRARY_PATH}:/PATH_TO_SOURCE/mozilla/dist/Linux2.0.32_x86_OPT.OBJ/bin
|
||||
</CODE> (where <CODE>PATH_TO_SOURCE</CODE> is the full path to your source
|
||||
tree) before the dynamically linked binary will run. <BR><BR>
|
||||
This varies by platform:<br>
|
||||
<UL>
|
||||
<LI>On HP-UX, the equivalent environment variable is <CODE>SHLIB_PATH</CODE>.
|
||||
<LI>On AIX, the equivalent environment variable is <CODE>LIBPATH</CODE>.
|
||||
</UL>
|
||||
</UL>
|
||||
|
||||
<HR>
|
||||
<H2><A NAME="s3">3. Common Sticking Points</A></H2>
|
||||
<LI>My linker dies with this error: undefined reference to `_Xsetlocale'
|
||||
<UL>If this error occurs, you might have to recompile libX11.so
|
||||
with the -DX_LOCALE flag (thanks to Scott Lampert,
|
||||
<A HREF="mailto:fortunato@heavymetal.org">fortunato@heavymetal.org</A>).
|
||||
|
||||
</UL>
|
||||
<HR>
|
||||
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
||||
217
mozilla/README/mozilla/classic-win.html
Normal file
217
mozilla/README/mozilla/classic-win.html
Normal file
@@ -0,0 +1,217 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Building Mozilla on Microsoft Windows 32-bit platforms</TITLE>
|
||||
</HEAD>
|
||||
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000EE" VLINK="#551A8B"
|
||||
ALINK="#FF0000">
|
||||
<HR>
|
||||
<H1>
|
||||
Building Mozilla on Microsoft Windows 32-bit platforms</H1>
|
||||
|
||||
<H2>
|
||||
Daniel Nunes, <TT><A HREF="mailto:leaf@netscape.com">leaf@netscape.com</A></TT>
|
||||
</H2>
|
||||
v 1.0, June 1998
|
||||
|
||||
<P>
|
||||
<HR><I>How to build Mozilla on a Microsoft Windows 32-bit System.</I>
|
||||
<HR>
|
||||
<H2>1. <A HREF="#s1">Introduction</A></H2>
|
||||
|
||||
<H2>2. <A HREF="#s2">Building Mozilla</A></H2>
|
||||
|
||||
<UL>
|
||||
<LI>
|
||||
<A HREF="#ss2.1">2.1 Get the Code </A></LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="#ss2.2">2.2 Requirements</A></LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="#ss2.3">2.3 Set up the Build Environment</A></LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="#ss2.4">2.4 Build the Lizard </A></LI>
|
||||
</UL>
|
||||
|
||||
<H2>3. <A HREF="#s3"> Common Problems </A></H2>
|
||||
|
||||
<HR>
|
||||
<H2><A NAME="s1">1. Introduction</A></H2>
|
||||
|
||||
<P>
|
||||
What this document is: A guide to building the Mozilla application.
|
||||
<BR>
|
||||
This includes:
|
||||
<OL>
|
||||
<LI> A listing of the development tools you will need to build Mozilla. </LI>
|
||||
<LI> A list of environment variables you will need to set before building. </LI>
|
||||
</OL>
|
||||
<P>
|
||||
If you're looking for documentation on developing features or fixing bugs,
|
||||
the Mozilla
|
||||
<A HREF="http://www.mozilla.org/docs/tplist/tplist.html">Technical Documents
|
||||
</A> or <A HREF="http://www.mozilla.org/library.html"> Library </A>
|
||||
are probably what you're looking for.
|
||||
<P>
|
||||
<HR>
|
||||
<H2><A NAME="s2">2. Building Mozilla </A></H2>
|
||||
<P>
|
||||
<UL>Each of the following subsections describes, or gives references to
|
||||
descriptions of, the steps necessary to build Mozilla.
|
||||
<H2><A NAME="ss2.1">2.1 Get the Code</A></H2>
|
||||
<P>
|
||||
<UL>
|
||||
There are two principal ways of getting the code,
|
||||
<A HREF="http://www.mozilla.org/download.html"> ftp</A> and
|
||||
<A HREF="http://www.mozilla.org/cvs.html"> CVS</A>.
|
||||
CVS will provide the most current code for building, but is
|
||||
slower than ftp. Ftp drops are generally produced once per month,
|
||||
and are known to compile.
|
||||
|
||||
</UL>
|
||||
<P>
|
||||
<H2><A NAME="ss2.2">2.2 Requirements</A></H2>
|
||||
<UL>
|
||||
The following need to be installed:
|
||||
<UL>
|
||||
<LI>Microsoft Visual C++ version 4.2 or later
|
||||
<LI>GNU Tools for Microsoft Windows, located:
|
||||
<UL>
|
||||
<LI><A HREF="http://www.cygnus.com/misc/gnu-win32">Cygnus</A></LI>
|
||||
<LI><A HREF="http://www.gnu.org/order/ftp.html">GNU home page</A></LI>
|
||||
<LI><A HREF="ftp://prep.ai.mit.edu/pub/gnu">MIT</A></LI>
|
||||
</UL>
|
||||
Specifically, you'll need:
|
||||
<UL><CODE>
|
||||
cp.exe<BR>
|
||||
rm.exe<BR>
|
||||
uname.exe<BR>
|
||||
</CODE>
|
||||
</UL>
|
||||
Netscape has internally modified version of gmake, shmsdos and win32gnu
|
||||
that we use to get around some problems we were having keeping in sync
|
||||
with the Unix version of gmake. This version of gmake can be found in the
|
||||
Windows Build Tools package, which can be ftp'd from
|
||||
<A HREF="http://www.mozilla.org/download-mozilla.html"> the Mozilla
|
||||
Download page</A>.
|
||||
The three files you will need are:
|
||||
<UL><CODE>
|
||||
gmake.exe<BR>
|
||||
shmsdos.exe<BR>
|
||||
uname.exe<BR>
|
||||
</CODE>
|
||||
</UL>
|
||||
|
||||
</UL>
|
||||
<P>
|
||||
Hardware/OS
|
||||
<UL>
|
||||
<LI>Pentium 133 MHz or better</LI>
|
||||
<LI>64 MB RAM, 128 MB recommended</LI>
|
||||
<LI>250 MB NTFS or 500 MB FAT disk space</LI>
|
||||
<LI>NT 4.0 is preferred; NT 3.51 will also work.
|
||||
</LI>
|
||||
</UL>
|
||||
</UL>
|
||||
<P>
|
||||
<H2><A NAME="ss2.3">2.3 Setup the Build Environment</A></H2>
|
||||
<P>
|
||||
<UL>
|
||||
The following environment variables need to be set:
|
||||
<UL>
|
||||
<CODE>
|
||||
set MOZ_BITS=32
|
||||
<BR>
|
||||
set MOZ_DEBUG=1 (set this only if you want to build a debug build)
|
||||
<BR>
|
||||
set MOZ_MEDIUM=1
|
||||
<BR>
|
||||
set MOZ_NT=351 (if running NT3.51)
|
||||
<BR>
|
||||
set MOZ_OUT=(optional: specifies location of resultant executable)
|
||||
<BR>
|
||||
set MOZ_SRC=(top of your tree, for example: set MOZ_SRC=d:\mozilla_source
|
||||
if this is the directory where you checked or unzipped the source into)
|
||||
<BR>
|
||||
set MOZ_TOOLS=(the parent directory of the GNU tools 'bin' directory. The build
|
||||
looks for MOZ_TOOLS\bin\gmake.exe, so make sure that the gmake.exe from
|
||||
the Windows Build Tools package resides there.)
|
||||
<BR>
|
||||
set NSPR20=1
|
||||
<BR>
|
||||
set _MSC_VER=1100 (if you are running VC++ 5.0) or 1200
|
||||
(if you are running VC++ 6.0)
|
||||
<BR>
|
||||
</CODE>
|
||||
</UL>
|
||||
<BR>
|
||||
<P>
|
||||
</UL>
|
||||
|
||||
<H2><A NAME="ss2.4">2.4 Run the build </A></H2>
|
||||
<UL>
|
||||
Change to the directory you copied the source into (for example,
|
||||
<CODE>cd d:\mozilla_source</CODE>). If this directory was empty before you
|
||||
installed the source, there should be two directories here:
|
||||
<CODE>README</CODE> and <CODE>mozilla</CODE>.
|
||||
<CODE>
|
||||
<PRE>
|
||||
cd mozilla\config
|
||||
nmake /f makefile.win
|
||||
cd ..
|
||||
nmake /f client.mak
|
||||
</PRE>
|
||||
</CODE>
|
||||
</UL>
|
||||
</UL>
|
||||
|
||||
<HR>
|
||||
<H2><A NAME="s3">3. Common Sticking Points</A></H2>
|
||||
<UL>
|
||||
<LI><B>nmake has a 'fatal error', listing one of the GNU commands and a
|
||||
hexadecimal return code.</B>
|
||||
<UL>
|
||||
This will happen as a result of not having the GNU tools and Windows Build
|
||||
tools in your path. Add the directories with the appropriate binaries to your
|
||||
path.
|
||||
</UL>
|
||||
</LI>
|
||||
<LI>
|
||||
<B>It fails with the message "'.\WIN32' unexpected": </B>
|
||||
<UL>
|
||||
You didn't properly
|
||||
set the environment variables -- you must not include a space at the end
|
||||
of the set statements (be careful if you are cut'n'pasting).
|
||||
</UL>
|
||||
</LI>
|
||||
<LI>
|
||||
<B>It fails to build, with directory-related errors: </B>
|
||||
<UL>
|
||||
The full path
|
||||
to the source must not include any spaces. Additionally, the source must
|
||||
be extracted with an intact directory structure by a utility that understands
|
||||
long filenames. If in doubt, grab Info-Zip at
|
||||
<A HREF="ftp://ftp.cdrom.com/pub/infozip">ftp://ftp.cdrom.com/pub/infozip</A>
|
||||
</UL>
|
||||
</LI>
|
||||
<LI>
|
||||
<B>It fails immediately with the message "Cannot find specified directory":
|
||||
</B>
|
||||
<UL>
|
||||
You didn't properly set the environment variable MOZ_TOOLS;
|
||||
this needs to be set to the path up to, but not including, the final \bin
|
||||
directory in the path to the gnu tools. So, the path to the tool executables
|
||||
is '%MOZ_TOOLS%\bin\<executable>'.
|
||||
</UL>
|
||||
</LI>
|
||||
<LI>
|
||||
<B>I'm not running a 32-bit windows system, how do i build?</B>
|
||||
<UL>
|
||||
Currently, the build process depends on a 32-bit operating system.
|
||||
Windows NT 4.0 is the recommended windows operating system.
|
||||
</UL>
|
||||
</UL>
|
||||
<HR>
|
||||
</BODY>
|
||||
</HTML>
|
||||
400
mozilla/README/mozilla/mac-build.html
Normal file
400
mozilla/README/mozilla/mac-build.html
Normal file
@@ -0,0 +1,400 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Building Mozilla on the Macintosh PPC platform</TITLE>
|
||||
</HEAD>
|
||||
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000EE" VLINK="#551A8B"
|
||||
ALINK="#FF0000">
|
||||
<HR>
|
||||
<H1>
|
||||
Building Mozilla on the Macintosh PPC platform</H1>
|
||||
|
||||
<H2>
|
||||
Daniel Nunes, <TT><A HREF="mailto:leaf@netscape.com">leaf@netscape.com</A></TT>
|
||||
</H2>
|
||||
v 1.0, June 1998
|
||||
|
||||
<P>
|
||||
<HR><I>How to build Mozilla on a Macintosh PPC System.</I>
|
||||
<HR>
|
||||
<H2>1. <A HREF="#s1">Introduction</A></H2>
|
||||
|
||||
<H2>2. <A HREF="#s2">Building Mozilla</A></H2>
|
||||
|
||||
<UL>
|
||||
<LI>
|
||||
<A HREF="#ss2.1">2.1 Get the Code </A></LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="#ss2.2">2.2 Requirements</A></LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="#ss2.3">2.3 Set up the Build Environment</A></LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="#ss2.4">2.4 Build the Lizard </A></LI>
|
||||
</UL>
|
||||
|
||||
<H2>3. <A HREF="#s3"> Common Problems </A></H2>
|
||||
|
||||
<H2>4. <A HREF="#s4"> Credits </A></H2>
|
||||
|
||||
<HR>
|
||||
<H2><A NAME="s1">1. Introduction</A></H2>
|
||||
|
||||
<P>
|
||||
What this document is: A guide to building the Mozilla application.
|
||||
This includes:
|
||||
<OL>
|
||||
<LI> A listing of the development tools you will need to build Mozilla. </LI>
|
||||
<LI> A list of environment variables you will need to set before building. </LI>
|
||||
</OL>
|
||||
<P>
|
||||
If you're looking for documentation on developing features or fixing bugs,
|
||||
the Mozilla
|
||||
<A HREF="http://www.mozilla.org/docs/tplist/tplist.html">Technical Documents
|
||||
</A> or <A HREF="http://www.mozilla.org/library.html"> Library </A>
|
||||
are probably what you're looking for.
|
||||
<P>
|
||||
<HR>
|
||||
<H2><A NAME="s2">2. Building Mozilla </A></H2>
|
||||
<P>
|
||||
<UL>Each of the following subsections describes, or gives references to
|
||||
descriptions of, the steps necessary to build Mozilla.
|
||||
<H2><A NAME="ss2.1">2.1 Get the Code</A></H2>
|
||||
<P>
|
||||
<UL>
|
||||
There are two principal ways of getting the code,
|
||||
<A HREF="http://www.mozilla.org/download.html"> ftp</A> and
|
||||
<A HREF="http://www.mozilla.org/cvs.html"> CVS</A>.
|
||||
CVS will provide the most current code for building, but is
|
||||
slower than ftp (takes longer to download).
|
||||
|
||||
</UL>
|
||||
<P>
|
||||
<H2><A NAME="ss2.2">2.2 Requirements</A></H2>
|
||||
The following need to be installed:
|
||||
<UL>
|
||||
<LI>CodeWarrior (CW) 2 - obtainable from
|
||||
<A HREF="http://www.metrowerks.com">Metrowerks</A>.
|
||||
See <A HREF="#s3">Common Sticking Points</A> if you have a different
|
||||
version.
|
||||
</LI>
|
||||
|
||||
<LI>PowerPlant 1.8 - obtainable from the CodeWarrior CD.</LI>
|
||||
|
||||
<LI>MSL - the Metrowerks Standard Library, obtainable from the
|
||||
CodeWarrior CD</LI>
|
||||
|
||||
<LI><A HREF="ftp://ftp.boingo.com//dan/WASTE/waste-13.hqx">WASTE
|
||||
1.3</A></LI>
|
||||
|
||||
<LI><A HREF="http://www.bact.wisc.edu/CWASTEEdit/CWASTEEdit.sit.hqx">CWASTE
|
||||
1.6.2</A></LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="ftp://ftp.scripting.com/userland/menuSharingToolkit4.1.sit.hqx">
|
||||
Menu Sharing Toolkit</A> (from UserLand)</LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="ftp://ftp.digitalalchemy.com/pub/digitalalchemy/mercutio-SDK.sit.bin">
|
||||
Mercutio 1.5 SDK</A> (only download the SDK, not the entire package, else
|
||||
the access paths will be wrong)</LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="ftp://ftp.share.com/pub/internet-configuration/ICProgKit1.4.sit">
|
||||
Internet Config 1.4 SDK</A></LI>
|
||||
|
||||
<LI><A HREF="http://www.mooseyard.com/Jens/Software/">AEGizmos
|
||||
1.4.2</A></LI>
|
||||
|
||||
<LI><A HREF="ftp://sunsite.cnlab-switch.ch/software/platform/macos/perl/Mac_Perl_520r4_tool.bin">
|
||||
MacPerl 5 MPW Tool</A></LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="ftp://sunsite.cnlab-switch.ch/software/platform/macos/perl/Mac_Perl_520r4_appl.bin">MacPerl 5 Application</A></LI>
|
||||
|
||||
<LI>MakeStub - MPW (installed with CodeWarrior Heaven option). If
|
||||
you choose not to install MPW, it is located on the MacOS Tools CD
|
||||
in "CW Pro 2 Tools:CodeWarrior MPW:MPW:Tools"</LI>
|
||||
|
||||
<LI>RunTSScript - in Mozilla source distribution
|
||||
(mozilla:build:mac:RunTSScript), needs to be installed by hand</LI>
|
||||
|
||||
<LI><A HREF="ftp://dev.apple.com/devworld/Tool_Chest/Core_Mac_OS_Tools/MPW_etc./MPW-GM/MPW/ToolServer.sit.hqx">ToolServer</A>
|
||||
- or in the CW distribution (CW Pro 2 Tools:Apple Development
|
||||
Tools:ToolServer 3.4.1.sit). <B>We recommend pulling it off the
|
||||
CD</B> because it comes with configuration files for CodeWarrior
|
||||
which you would have to create manually were you to pull it off
|
||||
the net.</LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="http://people.netscape.com/sfraser/software/NewAlias_tool.sit.hqx">
|
||||
New Alias MPW Tool</A> An MPW tool that creates Finder aliases for files.
|
||||
</LI>
|
||||
|
||||
<LI>StreamEdit MPW Tool - MPW (installed with CodeWarrior Heaven option). If
|
||||
you choose not to install MPW, it is located on the MacOS Tools CD
|
||||
in "CW Pro 2 Tools:CodeWarrior MPW:MPW:Tools"</LI>
|
||||
</LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="ftp://dev.apple.com/devworld/Periodicals/develop/develop25/develop_Issue_25_code/ToolFrontEnd.sit.hqx">ToolFrontEnd</A></LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="http://sunsite.cnlab-switch.ch/ftp/software/platform/macos/src/HTML/MPW_C.html">
|
||||
patch 2.1</A></LI>
|
||||
</UL>
|
||||
|
||||
<P>
|
||||
Hardware/OS
|
||||
<UL>
|
||||
<LI>To build Navigator, you need a fast PPC Mac. The faster the
|
||||
better. You can't build with a 68K machine because we have too many
|
||||
resources, and the build process will crash when trying to generate
|
||||
resources out of our cross-platform strings. See the discussion below
|
||||
for a way around this.
|
||||
</LI>
|
||||
<LI>You will need about 96 MB of physical RAM to "fast link" the app.
|
||||
You can still fast link if you give your machine 96 MB of virtual
|
||||
memory, but then the VM hit is large enough to counteract any
|
||||
improvement. One of our beta testers had a machine with only 64MB of
|
||||
physical RAM (VM was off) and it ran out of memory trying to link.
|
||||
Turning VM on got it to link, but build time increased greatly.
|
||||
</LI>
|
||||
<LI>Reports from the net indicate that the optimized version
|
||||
(MozillaPPC) take much less RAM to build than the 96MB we suggest. If
|
||||
you are running out of memory, try building that instead of the debug
|
||||
version (the debug symbols require a lot of RAM come link time).
|
||||
</LI>
|
||||
<LI>You should be ok with a 400MB disk partition, even when fully
|
||||
built. This does not include tools like the IDE, just source.
|
||||
</LI>
|
||||
<LI>On an HFS+ volume, a full build takes about 110MB. HFS+ is good,
|
||||
but utilities are sparse.
|
||||
</LI>
|
||||
</UL>
|
||||
<P>
|
||||
<H2><A NAME="ss2.3">2.3 Setup the Build Environment</A></H2>
|
||||
<P>
|
||||
<OL>
|
||||
<LI>Install CodeWarrior from the CD. While it is large, installing
|
||||
the "CodeWarrior Heaven" option will guarantee that you have
|
||||
everything you need. This will give you PowerPlant, MSL, and MPW.
|
||||
If you choose to install less, proceed at your own risk.</LI>
|
||||
|
||||
<LI>In the Finder, increase the memory partition of the IDE to
|
||||
15MB (you can get by with 12, if need be).</LI>
|
||||
|
||||
<LI>Download ToolFrontEnd. After expanding it, in "ToolFrontEnd
|
||||
Folder:Drop-Ins" there are three items:
|
||||
|
||||
<UL>
|
||||
<LI><I>#include</I></LI>
|
||||
|
||||
<LI><I>ToolFrontEnd</I></LI>
|
||||
|
||||
<LI><I>ToolFrontEnd Panel</I></LI>
|
||||
</UL>
|
||||
|
||||
<P>Create a folder named "Include Scanners". Place the file
|
||||
"#include" into the Include Scanners folder. Move the Include
|
||||
Scanners folder to the CodeWarrior Plugins folder. Create a folder
|
||||
named "ToolFrontEnd". Place the files "ToolFrontEnd" and
|
||||
"ToolFrontEnd Panel" into the ToolFrontEnd folder. Place this
|
||||
folder in the CodeWarrior Plugins folder.</P></LI>
|
||||
|
||||
<LI>Open "ToolFrontEnd Panel" with ResEdit. Change the file type
|
||||
from <B>'Panl'</B> to <B>'PanL'</B>. Save.</LI>
|
||||
|
||||
<LI>Uncompress the StuffIt Archive for ToolServer. The goal is to
|
||||
let ToolServer and MPW share the same Tools directory so you don't
|
||||
need to have multiple versions of tools. Do the following:
|
||||
|
||||
<OL>
|
||||
<LI>Open ToolServer's Tools folder. There is one file called
|
||||
"RMetrowerks". </LI>
|
||||
|
||||
<LI>Move RMetrowerks to Tools folder of MPW. MPW folder must be
|
||||
at "Metrowerks:Codewarrior MPW:MPW" if you installed
|
||||
Codewarrior Heaven. </LI>
|
||||
|
||||
<LI>Remove ToolServer's Tools folder.</LI>
|
||||
|
||||
<LI>Now create an alias of Tools folder in "CodeWarrior MPW"
|
||||
and move it to your ToolServer folder. Rename the alias
|
||||
(probably called "Tools alias") to "Tools"</LI>
|
||||
|
||||
|
||||
<LI><FONT COLOR="#FF0000"><B>IMPORTANT</B></FONT>: Make sure
|
||||
you only have one instance of ToolServer on your machine. If
|
||||
the build script finds the wrong one, the correct tools will
|
||||
not be found and strange things will happen.</LI>
|
||||
</OL>
|
||||
</LI>
|
||||
|
||||
<LI>After installing the MacPerl MPW Tool distribution (run the
|
||||
InstallerVISE application), in the "MacPerl ƒ" folder, there
|
||||
will be an MPW tool named "perl". Install this in MPW's tools
|
||||
folder.</LI>
|
||||
|
||||
<LI>Install the MacPerl Application (run the
|
||||
InstallerVISE application). You can install this anywhere, but it is
|
||||
recommended that you install it inside of your CodeWarrior folder for
|
||||
easy reference. After installation, you will need to set a preference
|
||||
to enable double-click launch of the perl scripts. This preference is set
|
||||
by going under the Edit Menu to Preferences. Click on the "Script" button
|
||||
and hit the radio button "Run Scripts opened from Finder"</LI>
|
||||
|
||||
<LI>Install the "patch", "MakeStub", "NewAlias" and "StreamEdit" Tools in the
|
||||
tools
|
||||
folder. Note that "MakeStub" and "StreamEdit" are automatically installed by the
|
||||
"CodeWarrior Heaven" install option.</LI>
|
||||
|
||||
<LI>Install RunTSScript (found in the Mozilla source distribution)
|
||||
in the compilers folder in your build environment
|
||||
("Metrowerks:Metrowerks Codewarrior:Codewarrior
|
||||
Plugins:Compilers")</LI>
|
||||
|
||||
<LI>Next, after downloading all the 3rd party software components,
|
||||
drag WASTE, CWASTE, Menu Sharing, Mercutio, Internet Config, and
|
||||
the AEGizmo folders (just as they are) into the "MacOS Support"
|
||||
folder in your build environment.</LI>
|
||||
|
||||
<LI>Start ToolServer from within CodeWarrior (or use MPW if you
|
||||
are brave enough). We're about to patch some files. Make sure the
|
||||
ToolServer menu is in the CodeWarrior menu bar by turning on the
|
||||
<A HREF="IDEPrefs.gif">preference</A> under the "Extras" panel in
|
||||
the IDE Preferences (not the project preferences!). The menu bar
|
||||
should look like this:
|
||||
|
||||
|
||||
<P><IMG SRC="IDEMenuBar.gif" WIDTH=359 HEIGHT=20 X-CLARIS-USEIMAGEWIDTH X-CLARIS-USEIMAGEHEIGHT ALIGN=bottom></P>
|
||||
|
||||
<P>Choose "Start ToolServer" from the ToolServer menu (this is the
|
||||
icon menu between "Window" and "Help" in the menubar above). You
|
||||
will now see a window with no close box. This is your ToolServer
|
||||
Worksheet where you will type (or cut & paste) the commands
|
||||
for the following steps.</P>
|
||||
|
||||
<P>In case you have never used MPW/ToolServer before, the
|
||||
following is <B>very important</B>. Pressing "return" does not
|
||||
execute commands like you might think. It just inserts a newline
|
||||
into the worksheet like a normal text editor. <B>To actually get
|
||||
ToolServer to execute the command, you must press "Enter" (lower
|
||||
right of numeric keypad).</B> This executes the line that the
|
||||
cursor is on, and only that line. If you want to execute multiple
|
||||
lines at once, select them all and hit Enter.</P></LI>
|
||||
|
||||
<LI>Set the shell variables {IDE} and {Source} to the correct
|
||||
paths for your build environment. {IDE} is where your CodeWarrior
|
||||
IDE is located. {Source} is the folder containing the toplevel
|
||||
"ns" folder of the Mozilla source. Mine look like this (don't
|
||||
forget to keep the quotes if your path includes spaces), yours
|
||||
will almost certainly be different (<FONT COLOR="#FF0000">to
|
||||
punctuate this, the things you need to change are in red</FONT>).
|
||||
|
||||
<PRE>Set IDE "<FONT COLOR="#FF0000">Develop:Source331 Build Environment:CW Pro 2:Metrowerks CodeWarrior:</FONT>"
|
||||
Set Source "<FONT COLOR="#FF0000">Source:FreeSource:</FONT>"</PRE>
|
||||
</LI>
|
||||
|
||||
<LI>If you are using CWPro2, execute the following lines to patch
|
||||
LDropFlag to draw correcly over non-white backgrounds.
|
||||
|
||||
<PRE>directory "{IDE}MacOS Support:PowerPlant:_In Progress:_Table Classes:"
|
||||
patch LDropFlag.cp "{Source}mozilla:lib:mac:patches:LDropFlag.patch"
|
||||
duplicate -y "{Source}mozilla:lib:mac:patches:DropFlag Icons.rsrc" "{IDE}MacOS Support:PowerPlant:PowerPlant Resources:"</PRE></LI>
|
||||
|
||||
<LI>Execute the following lines to patch menusharing.c to allow it
|
||||
to compile with the new Universal Headers. It references an
|
||||
obsolete header file (GestaltEqu.h).
|
||||
|
||||
<PRE>directory "{IDE}MacOS Support:Menu Sharing Toolkit 4.1:"
|
||||
patch menusharing.c "{Source}mozilla:lib:mac:patches:menusharing.patch"</PRE></LI>
|
||||
|
||||
|
||||
<LI>If you are using CWPro2 straight off the CD, you need to patch
|
||||
AppleEvents.r to fix a problem with the Universal Headers (the
|
||||
definition of the 'aedt' resource was omitted). <B>You do not have
|
||||
to do this if you have applied the netborne patch to Pro2e
|
||||
</B> because it has been fixed.
|
||||
|
||||
<PRE>directory "{IDE}MacOS Support:Headers:Rez Headers:"
|
||||
patch AppleEvents.r "{Source}mozilla:lib:mac:patches:AppleEvents.r.patch"</PRE></LI>
|
||||
|
||||
<LI>You need to patch stat.mac.h to fix a problem in MSL where
|
||||
lines were omitted.
|
||||
|
||||
<PRE>directory "{IDE}Metrowerks Standard Library:MSL C:MSL Mac:Public Includes"
|
||||
patch stat.mac.h "{Source}mozilla:lib:mac:patches:stat.mac.h.patch"</PRE></LI>
|
||||
|
||||
<LI>Congratulations! Now you are ready to build. Once these steps
|
||||
are done, you don't have to repeat these setups the next
|
||||
time!</LI>
|
||||
</OL>
|
||||
|
||||
|
||||
<P>
|
||||
|
||||
<H2><A NAME="ss2.4">2.4 Run the build </A></H2>
|
||||
<UL>
|
||||
<P>In the folder mozilla:build:mac:, there are several Perl scripts with
|
||||
names of the form BuildMozillaXXX.pl, where XXX is "Optimized",
|
||||
"Debug", "Tinderbox", et al. Each script builds the corresponding
|
||||
version of Mozilla. If you configured the MacPerl application to
|
||||
execute scripts that are opened from the finder, all you have to do is
|
||||
double click on the appropriate one; otherwise, launch MacPerl, and
|
||||
run the appropriate script from the "Run Script..." menu item.</P>
|
||||
|
||||
<P>These `configured build' scripts are simple, and you might want to
|
||||
make your own to force your build to StopForErrors(), or alternatively
|
||||
DontStopForErrors(), et al. You can set up certain build-script
|
||||
variables and (soon) compile-time flags. Compare the supplied scripts
|
||||
to figure out what you might want. Note that CodeWarriorLib, Moz.pm,
|
||||
and BuildList.pm, are AppleScript libraries and Perl modules meant to
|
||||
be used by a `configured build'. Use your favorite POD viewer (Shuck
|
||||
comes with MacPerl) to view the documentation in the Perl scripts.</P>
|
||||
|
||||
<P>If there were any errors in any of the projects along the way, the
|
||||
script will stop at that point and the IDE will tell you the errors.
|
||||
You can fix them and make sure they current project builds, but to
|
||||
continue the automation, you have to start from the beginning by
|
||||
double-clicking the script again. This isn't quite as bad as it
|
||||
sounds because the previous projects are already built (unless you
|
||||
changed some major header file). Please note that stopping the script
|
||||
once it has started is difficult. We are working to address
|
||||
this issue.</P>
|
||||
|
||||
<P>After the build is complete, you can find aliases to the built libraries
|
||||
and the final Mozilla application. Debug builds are built to
|
||||
Mozilla:dist:client_debug, while optimized builds are built to Mozilla:dist:client.
|
||||
</P>
|
||||
|
||||
<P>Don't worry too much about the numerous warnings generated during
|
||||
the build. We try our best to get the XP teams to use real compilers,
|
||||
but alas, they continue to write warning-laden code. There is also
|
||||
some generated code (Java is one example) that has a lot of warnings
|
||||
that we can't help either. If you write any new code, please help us
|
||||
in our quest to get zero warnings.</P>
|
||||
|
||||
</UL>
|
||||
</UL>
|
||||
|
||||
<HR>
|
||||
<H2><A NAME="s3">3. Common Sticking Points</A></H2>
|
||||
<UL>
|
||||
<LI><B>I have CodeWarrior3, how do i build with it?</B>
|
||||
<UL> Currently, the answer is, "You don't." Eventually, the distribution
|
||||
will be modified to allow building using CodeWarrior3, but for now
|
||||
CodeWarrior2 is the only IDE that is supported.
|
||||
</UL>
|
||||
</LI>
|
||||
</UL>
|
||||
<HR>
|
||||
<H2><A NAME="s4">4. Credits</A></H2>
|
||||
<UL>
|
||||
The majority of this document is taken from the build document included
|
||||
in the Mozilla source distribution at README:mozilla:macbuild.htm written
|
||||
by Mike Pinkerton, <A HREF="mailto:pinkerton@netscape.com">
|
||||
pinkerton@netscape.com</A>.
|
||||
</BODY>
|
||||
</HTML>
|
||||
163
mozilla/README/mozilla/unix-build.html
Normal file
163
mozilla/README/mozilla/unix-build.html
Normal file
@@ -0,0 +1,163 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Building the Mozilla client on unix platforms</TITLE>
|
||||
</HEAD>
|
||||
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000EE" VLINK="#551A8B"
|
||||
ALINK="#FF0000">
|
||||
<HR>
|
||||
<H1>Building the Mozilla client on Unix platforms</H1>
|
||||
|
||||
<H2>
|
||||
Daniel Nunes, <TT><A HREF="mailto:leaf@mozilla.org">leaf@mozilla.org</A></TT></H2>
|
||||
v 1.2, 1998-11-02
|
||||
|
||||
<P>
|
||||
<HR><I>How to build Mozilla on a Unix System.</I>
|
||||
<HR>
|
||||
<H2>1. <A HREF="#s1">Introduction</A></H2>
|
||||
|
||||
<H2>2. <A HREF="#s2">Building Mozilla</A></H2>
|
||||
|
||||
<UL>
|
||||
<LI>
|
||||
<A HREF="#ss2.1">2.1 Get the Code </A></LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="#ss2.2">2.2 Requirements</A></LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="#ss2.3">2.3 Build the Lizard</A></LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="#ss2.4">2.4 After the Build</A></LI>
|
||||
</UL>
|
||||
|
||||
<H2>3. <A HREF="#s3"> Common Problems </A></H2>
|
||||
|
||||
<HR>
|
||||
<H2><A NAME="s1">1. Introduction</A></H2>
|
||||
|
||||
<P>
|
||||
Perhaps you are interested in building classic Mozilla, before the
|
||||
fall of the old layout engine, and the rise of the new. If so, the
|
||||
<B><A HREF="classic-unix.html">Classic Mozilla Build document</A></B>
|
||||
is what you're looking for.
|
||||
|
||||
<P>
|
||||
|
||||
<P>
|
||||
What this document is: A guide to building the Mozilla application.
|
||||
<BR>
|
||||
This includes:
|
||||
<OL>
|
||||
<LI> A listing of the development tools you will need to build Mozilla. </LI>
|
||||
<LI> A sample set of commands to build Mozilla using the Autoconf
|
||||
build system. </LI>
|
||||
</OL>
|
||||
<P>
|
||||
If you're looking for documentation on developing features or fixing bugs,
|
||||
the Mozilla
|
||||
<A HREF="../tplist.html">Technical Documents</A> or
|
||||
<A HREF="../../../library.html"> Library </A>
|
||||
are probably what you're looking for.
|
||||
<P>
|
||||
<HR>
|
||||
<H2><A NAME="s2">2. Building Mozilla </A></H2>
|
||||
<P>
|
||||
<UL>Each of the following subsections describes, or gives references to
|
||||
descriptions of, the steps necessary to build Mozilla.
|
||||
</UL>
|
||||
<UL>
|
||||
<H2><A NAME="ss2.1">2.1 Get the Code</A></H2>
|
||||
<P>
|
||||
<UL>
|
||||
|
||||
Eventually, there will be two principal ways of getting the code,
|
||||
<A HREF="../../../download.html"> ftp</A> and
|
||||
<A HREF="../../../cvs.html"> CVS</A>.
|
||||
CVS will provide the most current code for building, but is
|
||||
slower than ftp. Ftp drops are generally produced once per month,
|
||||
and are known to compile on some machine, somewhere.
|
||||
|
||||
<B>For now</B>, however, you must do the following to obtain the newest
|
||||
browser source:
|
||||
<BR>
|
||||
<CODE>
|
||||
cvs co mozilla/nglayout.mk<BR>
|
||||
cd mozilla<BR>
|
||||
gmake -f nglayout.mk pull_all<BR>
|
||||
</CODE>
|
||||
<BR>
|
||||
This should pull all the right source.
|
||||
</UL>
|
||||
<P>
|
||||
<H2><A NAME="ss2.2">2.2 Requirements</A></H2>
|
||||
<UL>
|
||||
The following should be installed:
|
||||
<UL>
|
||||
<LI>Motif 1.2
|
||||
<LI>The native C/C++ compiler (or GNU C/C++ compiler 2.7.2 in lieu of the
|
||||
native compiler)
|
||||
<LI>GNU make 3.74 or better
|
||||
<LI>Perl5
|
||||
<LI><A HREF="../../../projects/autoconf/">Autconf</A> requirements,
|
||||
including NSPR.
|
||||
<LI><CODE>LD_LIBRARY_PATH</CODE> must include the path to the NSPR
|
||||
shared objects.<BR>
|
||||
For most people, this means adding <CODE>/usr/local/nspr/lib</CODE>
|
||||
to <CODE>LD_LIBRARY_PATH</CODE>
|
||||
(either:
|
||||
<BR>
|
||||
<CODE>setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/usr/local/nspr/lib</CODE>
|
||||
<BR>
|
||||
or
|
||||
<BR>
|
||||
<CODE>export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/nspr/lib</CODE>
|
||||
.<BR>
|
||||
If you get an error like "No such variable" then omit the
|
||||
<CODE>${LD_LIBRARY_PATH}:</CODE> part
|
||||
)
|
||||
</UL>
|
||||
<P>
|
||||
Your hardware should be equal to, or better than:
|
||||
<UL>
|
||||
32 MB RAM, 128 MB swap (64 MB RAM recommended)
|
||||
</UL>
|
||||
</UL>
|
||||
<P>
|
||||
<H2><A NAME="ss2.3">2.3 Build the Lizard</A></H2>
|
||||
<P>
|
||||
<UL>
|
||||
<CODE>
|
||||
autoconf<BR>
|
||||
mkdir obj-`./build/autoconf/config.guess`<BR>
|
||||
cd obj-`./build/autoconf/config.guess`<BR>
|
||||
../configure --with-nspr=/usr/local/nspr --enable-toolkit=motif<BR>
|
||||
gmake depend<BR>
|
||||
gmake<BR>
|
||||
</CODE>
|
||||
</UL>
|
||||
<H2><A NAME="ss2.4">2.4 After the build </A></H2>
|
||||
<UL>
|
||||
|
||||
<LI> <CODE>cd dist/bin</CODE> and you should see links to the objects you
|
||||
need to run <CODE>main</CODE>.
|
||||
|
||||
<LI>On most unixen LD_LIBRARY_PATH must be set to wherever the necessary
|
||||
libraries are.
|
||||
|
||||
<UL>
|
||||
<LI>On HP-UX, the equivalent environment variable is <CODE>SHLIB_PATH</CODE>.
|
||||
<LI>On AIX, the equivalent environment variable is <CODE>LIBPATH</CODE>.
|
||||
</UL>
|
||||
</UL>
|
||||
</UL>
|
||||
<HR>
|
||||
<H2><A NAME="s3">3. Common Sticking Points</A></H2>
|
||||
<LI>I'm sure there are bound to be some. Send
|
||||
<A HREF="mailto:leaf@mozilla.org"> me</A> mail.
|
||||
<HR>
|
||||
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
||||
209
mozilla/README/mozilla/win-build.html
Normal file
209
mozilla/README/mozilla/win-build.html
Normal file
@@ -0,0 +1,209 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Building Mozilla on Microsoft Windows 32-bit platforms</TITLE>
|
||||
</HEAD>
|
||||
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000EE" VLINK="#551A8B"
|
||||
ALINK="#FF0000">
|
||||
<HR>
|
||||
<H1>
|
||||
Building Mozilla on Microsoft Windows 32-bit platforms</H1>
|
||||
|
||||
<H2>
|
||||
Daniel Nunes, <TT><A HREF="mailto:leaf@netscape.com">leaf@netscape.com</A></TT>
|
||||
</H2>
|
||||
v 1.0, June 1998
|
||||
|
||||
<P>
|
||||
<HR><I>How to build Mozilla on a Microsoft Windows 32-bit System.</I>
|
||||
<HR>
|
||||
<H2>1. <A HREF="#s1">Introduction</A></H2>
|
||||
|
||||
<H2>2. <A HREF="#s2">Building Mozilla</A></H2>
|
||||
|
||||
<UL>
|
||||
<LI>
|
||||
<A HREF="#ss2.1">2.1 Get the Code </A></LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="#ss2.2">2.2 Requirements</A></LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="#ss2.3">2.3 Set up the Build Environment</A></LI>
|
||||
|
||||
<LI>
|
||||
<A HREF="#ss2.4">2.4 Build the Lizard </A></LI>
|
||||
</UL>
|
||||
|
||||
<H2>3. <A HREF="#s3"> Common Problems </A></H2>
|
||||
|
||||
<HR>
|
||||
<H2><A NAME="s1">1. Introduction</A></H2>
|
||||
|
||||
<P>
|
||||
What this document is: A guide to building the Mozilla application.
|
||||
<BR>
|
||||
This includes:
|
||||
<OL>
|
||||
<LI> A listing of the development tools you will need to build Mozilla. </LI>
|
||||
<LI> A list of environment variables you will need to set before building. </LI>
|
||||
</OL>
|
||||
<P>
|
||||
If you're looking for documentation on developing features or fixing bugs,
|
||||
the Mozilla
|
||||
<A HREF="http://www.mozilla.org/docs/tplist/tplist.html">Technical Documents
|
||||
</A> or <A HREF="http://www.mozilla.org/library.html"> Library </A>
|
||||
are probably what you're looking for.
|
||||
<P>
|
||||
<HR>
|
||||
<H2><A NAME="s2">2. Building Mozilla </A></H2>
|
||||
<P>
|
||||
<UL>Each of the following subsections describes, or gives references to
|
||||
descriptions of, the steps necessary to build Mozilla.
|
||||
<H2><A NAME="ss2.1">2.1 Get the Code</A></H2>
|
||||
<P>
|
||||
<UL>
|
||||
There are two principal ways of getting the code,
|
||||
<A HREF="http://www.mozilla.org/download.html"> ftp</A> and
|
||||
<A HREF="http://www.mozilla.org/cvs.html"> CVS</A>.
|
||||
CVS will provide the least outdated code for building, but is
|
||||
slower than ftp.
|
||||
|
||||
</UL>
|
||||
<P>
|
||||
<H2><A NAME="ss2.2">2.2 Requirements</A></H2>
|
||||
<UL>
|
||||
The following need to be installed:
|
||||
<UL>
|
||||
<LI>Microsoft Visual C++ version 4.2 or later
|
||||
<LI>GNU Tools for Microsoft Windows, located:
|
||||
<UL>
|
||||
<LI><A HREF="http://www.cygnus.com/misc/gnu-win32">Cygnus</A></LI>
|
||||
<LI><A HREF="http://www.gnu.org/order/ftp.html">GNU home page</A></LI>
|
||||
<LI><A HREF="ftp://prep.ai.mit.edu/pub/gnu">MIT</A></LI>
|
||||
</UL>
|
||||
Specifically, you'll need:
|
||||
<UL><CODE>
|
||||
cp.exe<BR>
|
||||
rm.exe<BR>
|
||||
uname.exe<BR>
|
||||
</CODE>
|
||||
</UL>
|
||||
Netscape has internally modified version of gmake, shmsdos and win32gnu
|
||||
that we use to get around some problems we were having keeping in sync
|
||||
with the Unix version of gmake. This version of gmake can be found in the
|
||||
Windows Build Tools package, which can be ftp'd from
|
||||
<A HREF="http://www.mozilla.org/download-mozilla.html"> the Mozilla
|
||||
Download page</A>.
|
||||
The three files you will need are:
|
||||
<UL><CODE>
|
||||
gmake.exe<BR>
|
||||
shmsdos.exe<BR>
|
||||
uname.exe<BR>
|
||||
</CODE>
|
||||
</UL>
|
||||
|
||||
</UL>
|
||||
<P>
|
||||
Hardware/OS
|
||||
<UL>
|
||||
<LI>Pentium 133 MHz or better</LI>
|
||||
<LI>64 MB RAM, 128 MB recommended</LI>
|
||||
<LI>250 MB NTFS or 500 MB FAT disk space</LI>
|
||||
<LI>NT 4.0 is preferred; NT 3.51 will also work.
|
||||
</LI>
|
||||
</UL>
|
||||
</UL>
|
||||
<P>
|
||||
<H2><A NAME="ss2.3">2.3 Setup the Build Environment</A></H2>
|
||||
<P>
|
||||
<UL>
|
||||
The following environment variables need to be set:
|
||||
<UL>
|
||||
<CODE>
|
||||
set MOZ_BITS=32
|
||||
<BR>
|
||||
set MOZ_DEBUG=1 (set this only if you want to build a debug build)
|
||||
<BR>
|
||||
set MOZ_GOLD=1
|
||||
<BR>
|
||||
set MOZ_MEDIUM=1
|
||||
<BR>
|
||||
set MOZ_NT=351 (if running NT3.51)
|
||||
<BR>
|
||||
set MOZ_OUT=(optional: specifies location of resultant executable)
|
||||
<BR>
|
||||
set MOZ_SRC=(top of your tree, for example: set MOZ_SRC=d:\mozilla_source
|
||||
if this is the directory where you checked or unzipped the source into)
|
||||
<BR>
|
||||
set MOZ_TOOLS=(location of the bin directory of your GNU tools. The build
|
||||
looks for MOZ_TOOLS\bin\gmake.exe, so make sure that the gmake.exe from
|
||||
the Windows Build Tools package resides there.)
|
||||
<BR>
|
||||
set NO_SECURITY=1
|
||||
<BR>
|
||||
set NSPR20=1
|
||||
<BR>
|
||||
set _MSC_VER=1100 (if you are running VC++ 5.0 or higher)
|
||||
<BR>
|
||||
</CODE>
|
||||
</UL>
|
||||
<BR>
|
||||
<P>
|
||||
</UL>
|
||||
|
||||
<H2><A NAME="ss2.4">2.4 Run the build </A></H2>
|
||||
<UL>
|
||||
Change to the directory you copied the source into (for example,
|
||||
<CODE>cd d:\mozilla_source</CODE>). If this directory was empty before you
|
||||
installed the source, there should be two directories here:
|
||||
<CODE>README</CODE> and <CODE>mozilla</CODE>.
|
||||
<CODE>
|
||||
<PRE>
|
||||
cd mozilla\config
|
||||
nmake /f makefile.win
|
||||
cd ..
|
||||
nmake /f client.mak
|
||||
</PRE>
|
||||
</CODE>
|
||||
</UL>
|
||||
</UL>
|
||||
|
||||
<HR>
|
||||
<H2><A NAME="s3">3. Common Sticking Points</A></H2>
|
||||
<UL>
|
||||
<LI><B>nmake has a 'fatal error', listing one of the GNU commands and a
|
||||
hexadecimal return code.</B>
|
||||
<UL>
|
||||
This will happen as a result of not having the GNU tools and Windows Build
|
||||
tools in your path. Add the directories with the appropriate binaries to your
|
||||
path.
|
||||
</UL>
|
||||
</LI>
|
||||
<LI>
|
||||
<B>It fails with the message "'.\WIN32' unexpected": </B>
|
||||
<UL>
|
||||
You didn't properly
|
||||
set the environment variables -- you must not include a space at the end
|
||||
of the set statements (be careful if you are cut'n'pasting).
|
||||
</UL>
|
||||
</LI>
|
||||
<LI>
|
||||
<B>It fails to build, with directory-related errors: </B>
|
||||
<UL>
|
||||
The full path
|
||||
to the source must not include any spaces. Additionally, the source must
|
||||
be extracted with an intact directory structure by a utility that understands
|
||||
long filenames. If in doubt, grab Info-Zip at
|
||||
<A HREF="ftp://ftp.cdrom.com/pub/infozip">ftp://ftp.cdrom.com/pub/infozip</A>
|
||||
</UL>
|
||||
</LI>
|
||||
<LI>
|
||||
<B>I'm not running a 32-bit windows system, how do i build?</B>
|
||||
<UL>
|
||||
Currently, the build process depends on a 32-bit operating system.
|
||||
Windows NT 4.0 is the recommended windows operating system.
|
||||
</UL>
|
||||
</UL>
|
||||
<HR>
|
||||
</BODY>
|
||||
</HTML>
|
||||
53
mozilla/README/mozilla/wininstall.htm
Normal file
53
mozilla/README/mozilla/wininstall.htm
Normal file
@@ -0,0 +1,53 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
|
||||
<META NAME="Author" CONTENT="Chris Yeh">
|
||||
<META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en]C-NSCP (WinNT; U) [Netscape]">
|
||||
<TITLE>Running Mozilla...</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
|
||||
<H2>
|
||||
<FONT FACE="Arial,Helvetica">Running Mozilla Without Trashing Netscape
|
||||
Installation</FONT></H2>
|
||||
This document explains how to run <TT>mozilla.exe</TT> separately from
|
||||
<TT>netscape.exe</TT> without trashing your regular installation of Netscape
|
||||
Communicator. This is necessary if, for example, you want to use Communicator's
|
||||
mail client while you work on Mozilla development.
|
||||
<BR>
|
||||
<HR WIDTH="100%">
|
||||
<OL>
|
||||
<LI>
|
||||
Before running <TT>mozilla.exe</TT>, create a new user profile either from
|
||||
a Netscape 4.0x installation using the "User Profile Manager" shortcut
|
||||
in the Utilities folder (on Windows) or by using the <TT>-new_account</TT>
|
||||
option on the command line of either <TT>netscape.exe</TT> or <TT>mozilla.exe</TT>.
|
||||
We suggest calling the profile "<TT>mozilla</TT>."</LI>
|
||||
|
||||
<LI>
|
||||
Always use that new account when running <TT>mozilla.exe</TT>, and never
|
||||
run <TT>netscape.exe</TT> using that same account profile.</LI>
|
||||
</OL>
|
||||
To make things easier, you can start the application with the user account
|
||||
on the command line, for example:
|
||||
<UL><TT>mozilla.exe -P"mozilla"</TT></UL>
|
||||
This assures that prefs and the cache will not interfere between the two
|
||||
versions. This will be especially
|
||||
<BR>important as new prefs are added to the Mozilla product. Note that
|
||||
you must use quotes around the name and there can be no space between the
|
||||
"P" and the profile name. Otherwise, the application won't catch the profile
|
||||
switch, and it will try to load the profile name as the initial URL.
|
||||
|
||||
<P>
|
||||
<HR WIDTH="100%">
|
||||
<BR>You can copy your <TT>bookmark.htm</TT> file from an existing profile
|
||||
to your new profile directory if you want to share bookmarks.
|
||||
|
||||
<P>After the initial 3/31 release, we will add some code to Mozilla to
|
||||
prevent running with a profile that is already being used by <TT>netscape.exe</TT>.
|
||||
<BR>
|
||||
<HR WIDTH="100%">
|
||||
<BR><FONT SIZE=-1>Copyright © 1998 <A HREF="http://home.netscape.com/misc/contact_info.html">Netscape
|
||||
Communications Corporation</A></FONT>
|
||||
</BODY>
|
||||
</HTML>
|
||||
184
mozilla/README/nglayout/winbuild.html
Normal file
184
mozilla/README/nglayout/winbuild.html
Normal file
@@ -0,0 +1,184 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=x-mac-roman">
|
||||
<META NAME="GENERATOR" CONTENT="Mozilla/4.04 [en] (WinNT; I) [Netscape]">
|
||||
<META NAME="KeyWords" CONTENT="client, source, documentation">
|
||||
<META NAME="Author" CONTENT="Kipp E.B. Hickman">
|
||||
<TITLE>NGLayout Windows Build Instructions</TITLE>
|
||||
</HEAD>
|
||||
<BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H2>
|
||||
<FONT FACE="Arial,Helvetica">NGLayout Windows Build Instructions</FONT></H2>
|
||||
This document explains how to build NGLayout for the Windows platform.
|
||||
<HR><B><FONT SIZE=+1>Required Tools:</FONT></B>
|
||||
<UL>
|
||||
<LI>
|
||||
<B>Microsoft Visual C++ version 4.2 or later</B></LI>
|
||||
|
||||
<LI>
|
||||
<B>The same set of tools for building <A HREF="http://www.mozilla.org/docs/tplist/catBuild/winbuild.htm">Mozilla</A></B></LI>
|
||||
</UL>
|
||||
<B><FONT SIZE=+1>Setting up:</FONT></B>
|
||||
<UL>
|
||||
<LI>
|
||||
You need a Pentium with at least a 133 MHz processor and at least 250 megs
|
||||
(NTFS partition) or 500 megs (FAT partition) of hard drive space. You need
|
||||
to have a minimum of 64 megs of memory in order to build this tree. These
|
||||
numbers are approximations.</LI>
|
||||
|
||||
<LI>
|
||||
The preferred platform is NT 4.0. NT 3.51 will also work, and Win95 might
|
||||
work if you're lucky. Maybe.</LI>
|
||||
|
||||
<LI>
|
||||
Install MSVC. If you don't choose to have the MSVC install modify your
|
||||
environment variables for PATH, INCLUDE, and LIB information, be sure to
|
||||
run VCVARS32.BAT out of the MSVC bin directory prior to attempting to build.</LI>
|
||||
|
||||
<LI>
|
||||
Download and install GNU tools. Put them in your path.</LI>
|
||||
|
||||
<LI>
|
||||
Install NGLayout source.</LI>
|
||||
|
||||
<UL>
|
||||
<LI>
|
||||
cd <your-source-area></LI>
|
||||
|
||||
<LI>
|
||||
unzip -o -q win-19980415.zip</LI>
|
||||
</UL>
|
||||
|
||||
<LI>
|
||||
There are several environment variables you will need to set, either manually
|
||||
or via a script within a command session, or by setting them in your system
|
||||
environment located through the Control Panel | System icon.</LI>
|
||||
|
||||
|
||||
<P> <B>Note: There is an additional variable for building NGLayout!
|
||||
Use this list carefully!</B>
|
||||
|
||||
<P> The variables are:
|
||||
<UL>
|
||||
<LI>
|
||||
set MOZ_BITS=32</LI>
|
||||
|
||||
<LI>
|
||||
set MOZ_DEBUG=1 (don't set this if you want to build an optimized release
|
||||
build)</LI>
|
||||
|
||||
<LI>
|
||||
set MOZ_GOLD=1</LI>
|
||||
|
||||
<LI>
|
||||
set MOZ_MEDIUM=1</LI>
|
||||
|
||||
<LI>
|
||||
set MOZ_NT=351 (if running NT 3.51, don't set otherwise)</LI>
|
||||
|
||||
<LI>
|
||||
set MOZ_OUT=(location of resulting executable and totally optional, see
|
||||
Notes for more details)</LI>
|
||||
|
||||
<LI>
|
||||
set MOZ_SRC=(top of your tree, drive letter and path, i.e. set MOZ_SRC=d:\mozilla_src.
|
||||
The topmost directory under this should be mozilla)</LI>
|
||||
|
||||
<LI>
|
||||
set MOZ_TOOLS=(location of the bin directory containing your GNU tools.
|
||||
The build looks for MOZ_TOOLS\bin\gmake.exe, so make sure your MOZ_TOOLS
|
||||
is figured appropriately)</LI>
|
||||
|
||||
<LI>
|
||||
set NO_SECURITY=1</LI>
|
||||
|
||||
<LI>
|
||||
set NSPR20=1</LI>
|
||||
|
||||
<LI>
|
||||
if you are running VC++ 5.0 or higher: set _MSC_VER=1100; if you are running
|
||||
VC++ 4.2 then set MOZ_VCVER=42</LI>
|
||||
|
||||
<LI>
|
||||
<B>set STANDALONE_IMAGE_LIB=1</B></LI>
|
||||
|
||||
<LI>
|
||||
<B>set MODULAR_NETLIB=1</B></LI>
|
||||
</UL>
|
||||
</UL>
|
||||
<B><FONT SIZE=+1>Building:</FONT></B>
|
||||
<UL>
|
||||
<LI>
|
||||
You need to be running a vanilla command prompt. Other shells may work,
|
||||
but you might have to tweak makefiles.</LI>
|
||||
|
||||
<LI>
|
||||
<B>Build the tools:</B> This generates several tools that handle things
|
||||
like dependency generation</LI>
|
||||
|
||||
<UL>
|
||||
<LI>
|
||||
cd mozilla\config</LI>
|
||||
|
||||
<LI>
|
||||
nmake /f makefile.win</LI>
|
||||
</UL>
|
||||
|
||||
<LI>
|
||||
<B>Build the NGLayout:</B> This will do a complete build of the source
|
||||
tree. You will end up with a viewer.exe at the end. The viewer.exe will
|
||||
be in your dist\win32_[OD].obj\bin directory (O will be used when you don't
|
||||
set MOZ_DEBUG; D will be used when you set MOZ_DEBUG).</LI>
|
||||
|
||||
<UL>
|
||||
<LI>
|
||||
cd mozilla</LI>
|
||||
|
||||
<LI>
|
||||
nmake /f nglayout.mak</LI>
|
||||
</UL>
|
||||
</UL>
|
||||
<B><FONT SIZE=+1>Running:</FONT></B>
|
||||
<UL>
|
||||
<LI>
|
||||
Once you have built the system, do this to run the viewer program (the
|
||||
viewer program is a simple test program that uses the nsIWebWidget API
|
||||
to embed a web widget object). The viewer program has a few basic menu
|
||||
items, include "Samples" which load sample tests.</LI>
|
||||
|
||||
<UL>
|
||||
<LI>
|
||||
cd mozilla\dist\win32_[OD].obj\bin</LI>
|
||||
|
||||
<LI>
|
||||
.\viewer.exe</LI>
|
||||
</UL>
|
||||
</UL>
|
||||
<B><FONT SIZE=+1>Notes:</FONT></B>
|
||||
<UL>
|
||||
<LI>
|
||||
This build process does not use Visual C++ generated project files for
|
||||
several reasons having to do with (among other things) size, maintainability,
|
||||
and the long term desire to start using more of tools like gmake, or plug
|
||||
and play developer tools. This does not preclude you from using the Visual
|
||||
C++ IDE, or it's debugger. Once you have built a viewer.exe do this to
|
||||
run it under the debugger:</LI>
|
||||
</UL>
|
||||
|
||||
<UL>
|
||||
<UL>
|
||||
<LI>
|
||||
cd mozilla\dist\win32_[OD].obj\bin</LI>
|
||||
|
||||
<LI>
|
||||
msdev viewer.exe</LI>
|
||||
</UL>
|
||||
</UL>
|
||||
|
||||
<HR WIDTH="100%">
|
||||
<CENTER><FONT SIZE=-1>Copyright © 1998 <A HREF="http://home.netscape.com/misc/contact_info.html">Netscape
|
||||
Communications Corporation</A></FONT></CENTER>
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
||||
10
mozilla/aclocal.m4
vendored
Normal file
10
mozilla/aclocal.m4
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
dnl
|
||||
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
|
||||
|
||||
451
mozilla/allmakefiles.sh
Executable file
451
mozilla/allmakefiles.sh
Executable file
@@ -0,0 +1,451 @@
|
||||
#! /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
|
||||
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
|
||||
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/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
|
||||
33
mozilla/base/Makefile.in
Normal file
33
mozilla/base/Makefile.in
Normal file
@@ -0,0 +1,33 @@
|
||||
#!gmake
|
||||
#
|
||||
# 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.
|
||||
|
||||
DEPTH = ..
|
||||
topsrcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
srcdir = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = public src
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
DIRS += tests
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
21
mozilla/base/macbuild/BaseDebugPrefix.h
Normal file
21
mozilla/base/macbuild/BaseDebugPrefix.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/* -*- 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"
|
||||
21
mozilla/base/macbuild/BasePrefix.h
Normal file
21
mozilla/base/macbuild/BasePrefix.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/* -*- 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"
|
||||
BIN
mozilla/base/macbuild/TestFiles.mcp
Normal file
BIN
mozilla/base/macbuild/TestFiles.mcp
Normal file
Binary file not shown.
BIN
mozilla/base/macbuild/TestProperties.mcp
Normal file
BIN
mozilla/base/macbuild/TestProperties.mcp
Normal file
Binary file not shown.
BIN
mozilla/base/macbuild/base.mcp
Normal file
BIN
mozilla/base/macbuild/base.mcp
Normal file
Binary file not shown.
19
mozilla/base/macbuild/base.toc
Normal file
19
mozilla/base/macbuild/base.toc
Normal file
@@ -0,0 +1,19 @@
|
||||
# target: baseDebug.shlb
|
||||
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
|
||||
mozilla/base/src/nsDeque.cpp
|
||||
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
|
||||
mozilla/base/src/nsUnicharInputStream.cpp
|
||||
mozilla/base/src/nsVoidArray.cpp
|
||||
19
mozilla/base/macbuild/files.prefix
Normal file
19
mozilla/base/macbuild/files.prefix
Normal file
@@ -0,0 +1,19 @@
|
||||
/* -*- 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 "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 "MacPrefix_debug.h"
|
||||
19
mozilla/base/macbuild/filesDebug.prefix
Normal file
19
mozilla/base/macbuild/filesDebug.prefix
Normal file
@@ -0,0 +1,19 @@
|
||||
/* -*- 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 "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 "MacPrefix_debug.h"
|
||||
23
mozilla/base/makefile.win
Normal file
23
mozilla/base/makefile.win
Normal file
@@ -0,0 +1,23 @@
|
||||
#!nmake
|
||||
#
|
||||
# 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.
|
||||
|
||||
DEPTH=..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
DIRS=public src tests
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
26
mozilla/base/public/MANIFEST
Normal file
26
mozilla/base/public/MANIFEST
Normal file
@@ -0,0 +1,26 @@
|
||||
#
|
||||
# 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
|
||||
58
mozilla/base/public/Makefile.in
Normal file
58
mozilla/base/public/Makefile.in
Normal file
@@ -0,0 +1,58 @@
|
||||
#!gmake
|
||||
#
|
||||
# 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.
|
||||
|
||||
DEPTH=../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
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))
|
||||
|
||||
MODULE=base
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
51
mozilla/base/public/makefile.win
Normal file
51
mozilla/base/public/makefile.win
Normal file
@@ -0,0 +1,51 @@
|
||||
#!nmake
|
||||
#
|
||||
# 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.
|
||||
|
||||
DEPTH=..\..
|
||||
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)
|
||||
|
||||
MODULE = raptor
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
179
mozilla/base/public/nsAutoLock.h
Normal file
179
mozilla/base/public/nsAutoLock.h
Normal file
@@ -0,0 +1,179 @@
|
||||
/* -*- 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__
|
||||
|
||||
53
mozilla/base/public/nsCaretProperties.h
Normal file
53
mozilla/base/public/nsCaretProperties.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/* -*- 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();
|
||||
68
mozilla/base/public/nsEscape.h
Normal file
68
mozilla/base/public/nsEscape.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/* First checked in on 98/12/03 by John R. McMullen, derived from net.h/mkparse.c. */
|
||||
|
||||
#ifndef _ESCAPE_H_
|
||||
#define _ESCAPE_H_
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
|
||||
/* valid mask values for NET_Escape() and NET_EscapedSize(). */
|
||||
typedef enum {
|
||||
url_XAlphas = (1<<0)
|
||||
, url_XPAlphas = (1<<1)
|
||||
, url_Path = (1<<2)
|
||||
} nsEscapeMask;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
NS_BASE char * nsEscape(const char * str, nsEscapeMask mask);
|
||||
/* Caller must use delete [] on the result */
|
||||
|
||||
NS_BASE 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);
|
||||
/* 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);
|
||||
/* 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
|
||||
|
||||
|
||||
|
||||
#endif // _ESCAPE_H_
|
||||
756
mozilla/base/public/nsFileSpec.h
Normal file
756
mozilla/base/public/nsFileSpec.h
Normal file
@@ -0,0 +1,756 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
// 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.
|
||||
|
||||
//========================================================================================
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// This suite provides the following services:
|
||||
//
|
||||
// 1. Encapsulates all platform-specific file details, so that files can be
|
||||
// described correctly without any platform #ifdefs
|
||||
//
|
||||
// 2. Type safety. This will fix the problems that used to occur because people
|
||||
// confused file paths. They used to use const char*, which could mean three
|
||||
// or four different things. Bugs were introduced as people coded, right up
|
||||
// to the moment Communicator 4.5 shipped.
|
||||
//
|
||||
// 3. Used in conjunction with nsFileStream.h (q.v.), this supports all the power
|
||||
// and readability of the ansi stream syntax.
|
||||
//
|
||||
// Basic example:
|
||||
//
|
||||
// nsFilePath myPath("/Development/iotest.txt");
|
||||
//
|
||||
// nsOutputFileStream testStream(nsFileSpec(myPath));
|
||||
// testStream << "Hello World" << nsEndl;
|
||||
//
|
||||
// 4. Handy methods for manipulating file specifiers safely, e.g. MakeUnique(),
|
||||
// SetLeafName(), Exists().
|
||||
//
|
||||
// 5. Easy cross-conversion.
|
||||
//
|
||||
// Examples:
|
||||
//
|
||||
// Initialize a URL from a string
|
||||
//
|
||||
// nsFileURL fileURL("file:///Development/MPW/MPW%20Shell");
|
||||
//
|
||||
// Initialize a Unix-style path from a URL
|
||||
//
|
||||
// nsFilePath filePath(fileURL);
|
||||
//
|
||||
// Initialize a file spec from a URL
|
||||
//
|
||||
// nsFileSpec fileSpec(fileURL);
|
||||
//
|
||||
// Make the spec unique.
|
||||
//
|
||||
// fileSpec.MakeUnique();
|
||||
//
|
||||
// Assign the spec to a URL (causing conversion)
|
||||
//
|
||||
// fileURL = fileSpec;
|
||||
//
|
||||
// Assign a unix path using a string
|
||||
//
|
||||
// filePath = "/Development/MPW/SysErrs.err";
|
||||
//
|
||||
// Assign to a file spec using a unix path (causing conversion).
|
||||
//
|
||||
// fileSpec = filePath;
|
||||
//
|
||||
// Make this unique.
|
||||
//
|
||||
// fileSpec.MakeUnique();
|
||||
//
|
||||
// 6. Fixes a bug that have been there for a long time, and
|
||||
// is inevitable if you use NSPR alone, where files are described as paths.
|
||||
//
|
||||
// The problem affects platforms (Macintosh) in which a path does not fully
|
||||
// specify a file, because two volumes can have the same name. This
|
||||
// is solved by holding a "private" native file spec inside the
|
||||
// nsFilePath and nsFileURL classes, which is used when appropriate.
|
||||
//
|
||||
//========================================================================================
|
||||
|
||||
#ifndef _FILESPEC_H_
|
||||
#define _FILESPEC_H_
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsError.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
//========================================================================================
|
||||
// Compiler-specific macros, as needed
|
||||
//========================================================================================
|
||||
#if !defined(NS_USING_NAMESPACE) && (defined(__MWERKS__) || defined(XP_PC))
|
||||
#define NS_USING_NAMESPACE
|
||||
#endif
|
||||
|
||||
#ifdef NS_USING_NAMESPACE
|
||||
|
||||
#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 ===============================
|
||||
|
||||
#ifdef XP_MAC
|
||||
#include <Files.h>
|
||||
#elif defined(XP_UNIX) || defined (XP_OS2)
|
||||
#include <dirent.h>
|
||||
#elif defined(XP_PC)
|
||||
#include "prio.h"
|
||||
#endif
|
||||
|
||||
//========================================================================================
|
||||
// Here are the allowable ways to describe a file.
|
||||
//========================================================================================
|
||||
|
||||
class nsFileSpec; // Preferred. For i/o use nsInputFileStream, nsOutputFileStream
|
||||
class nsFilePath;
|
||||
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.
|
||||
|
||||
#define kFileURLPrefix "file://"
|
||||
#define kFileURLPrefixLength (7)
|
||||
|
||||
class nsOutputStream;
|
||||
class nsInputStream;
|
||||
class nsIOutputStream;
|
||||
class nsIInputStream;
|
||||
class nsOutputFileStream;
|
||||
class nsInputFileStream;
|
||||
class nsOutputConsoleStream;
|
||||
|
||||
class nsString;
|
||||
|
||||
//========================================================================================
|
||||
// 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
|
||||
// This is whatever each platform really prefers to describe files as. Declared first
|
||||
// because the other two types have an embedded nsFileSpec 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;
|
||||
}
|
||||
|
||||
void operator = (const nsFilePath& inPath);
|
||||
void operator = (const nsFileURL& inURL);
|
||||
void operator = (const nsFileSpec& inOther);
|
||||
void operator = (const nsPersistentFileDescriptor& 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.
|
||||
|
||||
#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(
|
||||
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; }
|
||||
|
||||
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; }
|
||||
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);
|
||||
// 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()); }
|
||||
|
||||
//--------------------------------------------------
|
||||
// Queries and path algebra. These do not modify the disk.
|
||||
//--------------------------------------------------
|
||||
|
||||
char* GetLeafName() const; // Allocated. Use nsCRT::free().
|
||||
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;
|
||||
// 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,
|
||||
// however, that the top node is still not a name,
|
||||
// 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);
|
||||
// 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
|
||||
// from SetLeafName(), since the latter will work
|
||||
// starting with a sibling of the directory and throws
|
||||
// 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;
|
||||
// More stringent than Exists()
|
||||
PRBool IsFile() const;
|
||||
// More stringent than Exists()
|
||||
PRBool Exists() const;
|
||||
|
||||
//--------------------------------------------------
|
||||
// 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;
|
||||
|
||||
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
|
||||
//--------------------------------------------------
|
||||
|
||||
protected:
|
||||
friend class nsFilePath;
|
||||
friend class nsFileURL;
|
||||
friend class nsDirectoryIterator;
|
||||
#ifdef XP_MAC
|
||||
FSSpec mSpec;
|
||||
#endif
|
||||
nsSimpleCharString mPath;
|
||||
nsresult mError;
|
||||
}; // class nsFileSpec
|
||||
|
||||
// FOR HISTORICAL REASONS:
|
||||
|
||||
typedef nsFileSpec nsNativeFileSpec;
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsFileURL
|
||||
// This is an escaped string that looks like "file:///foo/bar/mumble%20fish". Since URLs
|
||||
// are the standard way of doing things in mozilla, this allows a string constructor,
|
||||
// which just stashes the string with no conversion.
|
||||
//========================================================================================
|
||||
{
|
||||
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);
|
||||
virtual ~nsFileURL();
|
||||
|
||||
// nsString GetString() const { return mPath; }
|
||||
// may be needed for implementation reasons,
|
||||
// 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 nsFilePath& inOther);
|
||||
void operator = (const nsFileSpec& 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.
|
||||
|
||||
#ifdef XP_MAC
|
||||
// Accessor to allow quick assignment to a mFileSpec
|
||||
const nsFileSpec& GetFileSpec() const { return mFileSpec; }
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
protected:
|
||||
friend class nsFilePath; // to allow construction of nsFilePath
|
||||
nsSimpleCharString 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;
|
||||
#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.
|
||||
//========================================================================================
|
||||
{
|
||||
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);
|
||||
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.
|
||||
|
||||
void operator = (const nsFilePath& inPath);
|
||||
void operator = (const char* inUnixPathString);
|
||||
void operator = (const nsString& inUnixPathString)
|
||||
{
|
||||
const nsAutoCString string(inUnixPathString);
|
||||
*this = string;
|
||||
}
|
||||
void operator = (const nsFileURL& inURL);
|
||||
void operator = (const nsFileSpec& inOther);
|
||||
|
||||
void operator +=(const char* inRelativeUnixPath);
|
||||
nsFilePath operator +(const char* inRelativeUnixPath) const;
|
||||
|
||||
#ifdef XP_MAC
|
||||
public:
|
||||
// Accessor to allow quick assignment to a mFileSpec
|
||||
const nsFileSpec& GetFileSpec() const { return mFileSpec; }
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
nsSimpleCharString 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;
|
||||
#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++)
|
||||
// {
|
||||
// // do something with i.Spec()
|
||||
// }
|
||||
//
|
||||
// or:
|
||||
//
|
||||
// for (nsDirectoryIterator i(parentDir, -1); i.Exists(); i--)
|
||||
// {
|
||||
// // do something with i.Spec()
|
||||
// }
|
||||
//
|
||||
// Currently, the only platform on which backwards iteration actually goes backwards
|
||||
// is Macintosh. On other platforms, both styles will work, but will go forwards.
|
||||
//========================================================================================
|
||||
{
|
||||
public:
|
||||
nsDirectoryIterator(
|
||||
const nsFileSpec& 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; }
|
||||
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; }
|
||||
|
||||
private:
|
||||
|
||||
#if defined(XP_MAC)
|
||||
OSErr SetToIndex();
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
nsFileSpec mCurrent;
|
||||
PRBool mExists;
|
||||
|
||||
#if defined(XP_UNIX)
|
||||
DIR* mDir;
|
||||
#elif defined(XP_PC)
|
||||
PRDir* mDir; // XXX why not use PRDir for Unix too?
|
||||
#elif defined(XP_MAC)
|
||||
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_
|
||||
47
mozilla/base/public/nsFileSpecStreaming.h
Normal file
47
mozilla/base/public/nsFileSpecStreaming.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/* -*- 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)
|
||||
743
mozilla/base/public/nsFileStream.h
Normal file
743
mozilla/base/public/nsFileStream.h
Normal file
@@ -0,0 +1,743 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
// 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.
|
||||
//
|
||||
// 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:
|
||||
//
|
||||
// 1. Encapsulates all platform-specific file details, so that file i/o
|
||||
// can be done correctly without any platform #ifdefs
|
||||
//
|
||||
// 2. Uses NSPR file services (NOT ansi file I/O), in order to get best
|
||||
// native performance. This performance difference is especially large on
|
||||
// macintosh.
|
||||
//
|
||||
// 3. Allows all the power of the ansi stream syntax.
|
||||
//
|
||||
// Basic example:
|
||||
//
|
||||
// nsFileSpec 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
|
||||
// nsFileSpec.h for more details.
|
||||
//
|
||||
// 5. Fixes a bug that have been there for a long time, and
|
||||
// is inevitable if you use NSPR alone:
|
||||
//
|
||||
// The problem on platforms (Macintosh) in which a path does not fully
|
||||
// specify a file, because two volumes can have the same name.
|
||||
//
|
||||
// Not yet provided:
|
||||
//
|
||||
// Endian-awareness for reading and writing crossplatform binary files. At this
|
||||
// time there seems to be no demand for this.
|
||||
//
|
||||
//========================================================================================
|
||||
|
||||
#ifndef _FILESTREAM_H_
|
||||
#define _FILESTREAM_H_
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
#ifdef XP_MAC
|
||||
#include "pprio.h" // To get PR_ImportFile
|
||||
#else
|
||||
#include "prio.h"
|
||||
#endif
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIFileStream.h"
|
||||
|
||||
// Defined elsewhere
|
||||
class nsFileSpec;
|
||||
class nsString;
|
||||
class nsIInputStream;
|
||||
class nsIOutputStream;
|
||||
|
||||
//========================================================================================
|
||||
// Compiler-specific macros, as needed
|
||||
//========================================================================================
|
||||
#if !defined(NS_USING_NAMESPACE) && (defined(__MWERKS__) || defined(XP_PC))
|
||||
#define NS_USING_NAMESPACE
|
||||
#endif
|
||||
|
||||
#if !defined(NS_USING_STL) && (defined(__MWERKS__) || defined(XP_PC))
|
||||
#define NS_USING_STL
|
||||
#endif
|
||||
|
||||
#ifdef NS_USING_NAMESPACE
|
||||
|
||||
#define NS_NAMESPACE_PROTOTYPE
|
||||
#define NS_NAMESPACE namespace
|
||||
#define NS_NAMESPACE_END
|
||||
|
||||
#else
|
||||
|
||||
#define NS_NAMESPACE_PROTOTYPE static
|
||||
#define NS_NAMESPACE struct
|
||||
#define NS_NAMESPACE_END ;
|
||||
|
||||
#endif // NS_USING_NAMESPACE
|
||||
|
||||
#ifndef XP_MAC
|
||||
// PR_STDOUT and PR_STDIN are fatal on Macintosh. So for console i/o, we must use the std
|
||||
// stream stuff instead. However, we have to require that cout and cin are passed in
|
||||
// to the constructor because in the current build, there is a copy in the base.shlb,
|
||||
// and another in the caller's file. Passing it in as a parameter ensures that the
|
||||
// caller and this library are using the same global object. Groan.
|
||||
//
|
||||
// Unix currently does not support iostreams at all. Their compilers do not support
|
||||
// ANSI C++, or even ARM C++.
|
||||
//
|
||||
// Windows supports them, but only if you turn on the -GX compile flag, to support
|
||||
// exceptions.
|
||||
|
||||
// Catch 22.
|
||||
#define NS_USE_PR_STDIO
|
||||
#endif
|
||||
|
||||
#ifdef NS_USE_PR_STDIO
|
||||
class istream;
|
||||
class ostream;
|
||||
#define CONSOLE_IN 0
|
||||
#define CONSOLE_OUT 0
|
||||
#else
|
||||
#include <iostream>
|
||||
using std::istream;
|
||||
using std::ostream;
|
||||
#define CONSOLE_IN &std::cin
|
||||
#define CONSOLE_OUT &std::cout
|
||||
#endif
|
||||
|
||||
//=========================== 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
|
||||
//========================================================================================
|
||||
{
|
||||
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);
|
||||
|
||||
// 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&))
|
||||
{
|
||||
return pf(*this);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
//========================================================================================
|
||||
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
|
||||
//========================================================================================
|
||||
{
|
||||
public:
|
||||
nsOutputStream() {}
|
||||
nsOutputStream(nsIOutputStream* inStream)
|
||||
: mOutputStream(do_QueryInterface(inStream))
|
||||
{}
|
||||
|
||||
virtual ~nsOutputStream();
|
||||
|
||||
nsCOMPtr<nsIOutputStream> GetIStream() const
|
||||
{
|
||||
return mOutputStream;
|
||||
}
|
||||
void close()
|
||||
{
|
||||
mOutputStream->Close();
|
||||
}
|
||||
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 seek(PRInt32 offset)
|
||||
{
|
||||
seek(PR_SEEK_SET, offset);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsInputFileStream
|
||||
// Please read the comments at the top of this file
|
||||
//========================================================================================
|
||||
: public nsRandomAccessInputStream
|
||||
, public nsFileClient
|
||||
{
|
||||
public:
|
||||
enum { kDefaultMode = PR_RDONLY };
|
||||
nsInputFileStream(nsIInputStream* inStream)
|
||||
: nsRandomAccessInputStream(inStream)
|
||||
, nsFileClient(do_QueryInterface(inStream))
|
||||
, mFileInputStream(do_QueryInterface(inStream))
|
||||
{
|
||||
}
|
||||
nsInputFileStream(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode = kDefaultMode,
|
||||
PRIntn accessMode = 00700); // <- OCTAL
|
||||
|
||||
void Open(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode = kDefaultMode,
|
||||
PRIntn accessMode = 00700) // <- OCTAL
|
||||
{
|
||||
if (mFile)
|
||||
mFile->Open(inFile, nsprMode, accessMode);
|
||||
}
|
||||
|
||||
// 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<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:
|
||||
enum { kDefaultMode = (PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE) };
|
||||
|
||||
nsOutputFileStream() {}
|
||||
nsOutputFileStream(
|
||||
const nsFileSpec& 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);
|
||||
}
|
||||
|
||||
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;
|
||||
}; // 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:
|
||||
enum { kDefaultMode = (PR_RDWR | PR_CREATE_FILE) };
|
||||
|
||||
nsIOFileStream(
|
||||
nsIInputStream* inInputStream
|
||||
, nsIOutputStream* inOutputStream)
|
||||
: nsInputFileStream(inInputStream)
|
||||
, nsOutputStream(inOutputStream)
|
||||
, mFileOutputStream(do_QueryInterface(inOutputStream))
|
||||
{
|
||||
}
|
||||
nsIOFileStream(
|
||||
const nsFileSpec& 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);
|
||||
}
|
||||
|
||||
virtual void close()
|
||||
{
|
||||
// Doesn't matter which of the two we close:
|
||||
// they're hooked up to the same file.
|
||||
nsInputFileStream::close();
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
||||
|
||||
#endif /* _FILESTREAM_H_ */
|
||||
83
mozilla/base/public/nsIBuffer.h
Normal file
83
mozilla/base/public/nsIBuffer.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/* -*- 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___
|
||||
58
mozilla/base/public/nsIByteBufferInputStream.h
Normal file
58
mozilla/base/public/nsIByteBufferInputStream.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/* -*- 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___ */
|
||||
145
mozilla/base/public/nsIFileStream.h
Normal file
145
mozilla/base/public/nsIFileStream.h
Normal file
@@ -0,0 +1,145 @@
|
||||
/* -*- 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___ */
|
||||
45
mozilla/base/public/nsIObserver.h
Normal file
45
mozilla/base/public/nsIObserver.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/* -*- 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__ */
|
||||
48
mozilla/base/public/nsIObserverList.h
Normal file
48
mozilla/base/public/nsIObserverList.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/* -*- 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__ */
|
||||
51
mozilla/base/public/nsIObserverService.h
Normal file
51
mozilla/base/public/nsIObserverService.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/* -*- 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__ */
|
||||
55
mozilla/base/public/nsIPageManager.h
Normal file
55
mozilla/base/public/nsIPageManager.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/* -*- 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__
|
||||
107
mozilla/base/public/nsIProperties.h
Normal file
107
mozilla/base/public/nsIProperties.h
Normal file
@@ -0,0 +1,107 @@
|
||||
/* -*- 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 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 "nsString.h"
|
||||
|
||||
// {1A180F60-93B2-11d2-9B8B-00805F8A16D9}
|
||||
#define NS_IPERSISTENTPROPERTIES_IID \
|
||||
{ 0x1a180f60, 0x93b2, 0x11d2, \
|
||||
{ 0x9b, 0x8b, 0x0, 0x80, 0x5f, 0x8a, 0x16, 0xd9 } }
|
||||
|
||||
// {2245E573-9464-11d2-9B8B-00805F8A16D9}
|
||||
NS_DECLARE_ID(kPersistentPropertiesCID,
|
||||
0x2245e573, 0x9464, 0x11d2, 0x9b, 0x8b, 0x0, 0x80, 0x5f, 0x8a, 0x16, 0xd9);
|
||||
|
||||
class nsIPersistentProperties : public nsIProperties
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // nsIProperties_h___
|
||||
49
mozilla/base/public/nsIScriptable.h
Normal file
49
mozilla/base/public/nsIScriptable.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/* -*- 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___ */
|
||||
66
mozilla/base/public/nsISizeOfHandler.h
Normal file
66
mozilla/base/public/nsISizeOfHandler.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/* -*- 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 nsISizeOfHandler_h___
|
||||
#define nsISizeOfHandler_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
/* c028d1f0-fc9e-11d1-89e4-006008911b81 */
|
||||
#define NS_ISIZEOF_HANDLER_IID \
|
||||
{ 0xc028d1f0, 0xfc9e, 0x11d1, {0x89, 0xe4, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81}}
|
||||
|
||||
/**
|
||||
* An API to managing a sizeof computation of an arbitrary graph.
|
||||
* The handler is responsible for remembering which objects have been
|
||||
* seen before. Note that the handler doesn't hold references to
|
||||
* nsISupport's objects; the assumption is that the objects being
|
||||
* sized are stationary and will not be modified during the sizing
|
||||
* computation and therefore do not need an extra reference count.
|
||||
*/
|
||||
class nsISizeOfHandler : public nsISupports {
|
||||
public:
|
||||
/**
|
||||
* Add in a simple size value to the running total.
|
||||
* Always returns NS_OK.
|
||||
*/
|
||||
NS_IMETHOD Add(size_t aSize) = 0;
|
||||
|
||||
/**
|
||||
* Update aResult with PR_TRUE if the object has been traversed
|
||||
* by the sizeof computation before. Otherwise aResult is set to
|
||||
* PR_FALSE and the object is added to the internal database
|
||||
* of objects that have been traversed. It's ok to pass a null
|
||||
* pointer in; aResult will be set to PR_TRUE so you won't accidently
|
||||
* try to traverse through null pointer.
|
||||
*
|
||||
* Note: This violates the COM API standard on purpose; so there!
|
||||
*/
|
||||
virtual PRBool HaveSeen(void* anObject) = 0;
|
||||
|
||||
/**
|
||||
* Return the currently computed size.
|
||||
* Always returns NS_OK.
|
||||
*/
|
||||
NS_IMETHOD GetSize(PRUint32& aResult) = 0;
|
||||
};
|
||||
|
||||
extern NS_BASE nsresult
|
||||
NS_NewSizeOfHandler(nsISizeOfHandler** aInstancePtrResult);
|
||||
|
||||
#endif /* nsISizeofHandler_h___ */
|
||||
74
mozilla/base/public/nsIString.h
Normal file
74
mozilla/base/public/nsIString.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/* -*- 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__
|
||||
|
||||
67
mozilla/base/public/nsIStringStream.h
Normal file
67
mozilla/base/public/nsIStringStream.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/* -*- 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___ */
|
||||
126
mozilla/base/public/nsIThread.h
Normal file
126
mozilla/base/public/nsIThread.h
Normal file
@@ -0,0 +1,126 @@
|
||||
/* -*- 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__
|
||||
149
mozilla/base/public/nsIVariant.h
Normal file
149
mozilla/base/public/nsIVariant.h
Normal file
@@ -0,0 +1,149 @@
|
||||
/* -*- 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___
|
||||
41
mozilla/base/public/nsQuickSort.h
Normal file
41
mozilla/base/public/nsQuickSort.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/* -*- 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___ */
|
||||
60
mozilla/base/public/nsRepeater.h
Normal file
60
mozilla/base/public/nsRepeater.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* -*- 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 nsRepeater_h___
|
||||
#define nsRepeater_h___
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
class EventRecord;
|
||||
|
||||
class NS_BASE Repeater {
|
||||
public:
|
||||
|
||||
Repeater();
|
||||
virtual ~Repeater();
|
||||
|
||||
virtual void RepeatAction(const EventRecord &aMacEvent) = 0;
|
||||
|
||||
void StartRepeating();
|
||||
void StopRepeating();
|
||||
void StartIdling();
|
||||
void StopIdling();
|
||||
|
||||
static void DoRepeaters(const EventRecord &aMacEvent);
|
||||
static void DoIdlers(const EventRecord &aMacEvent);
|
||||
|
||||
protected:
|
||||
|
||||
void AddToRepeatList();
|
||||
void RemoveFromRepeatList();
|
||||
void AddToIdleList();
|
||||
void RemoveFromIdleList();
|
||||
|
||||
static Repeater* sRepeaters;
|
||||
static Repeater* sIdlers;
|
||||
|
||||
bool mRepeating;
|
||||
bool mIdling;
|
||||
Repeater* mPrevRptr;
|
||||
Repeater* mNextRptr;
|
||||
Repeater* mPrevIdlr;
|
||||
Repeater* mNextIdlr;
|
||||
};
|
||||
|
||||
#endif
|
||||
111
mozilla/base/public/nsSpecialSystemDirectory.h
Normal file
111
mozilla/base/public/nsSpecialSystemDirectory.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/* -*- 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
|
||||
939
mozilla/base/public/nsStdFileStream.h
Normal file
939
mozilla/base/public/nsStdFileStream.h
Normal file
@@ -0,0 +1,939 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#error "Do not use this file. The unix compilers do not support standard C++. Use nsFileStream"
|
||||
|
||||
// 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.
|
||||
|
||||
//========================================================================================
|
||||
//
|
||||
// Classes defined:
|
||||
//
|
||||
// single-byte char:
|
||||
//
|
||||
// nsInputFileStream, nsOutputFileStream, nsIOFileStream
|
||||
//
|
||||
// wide char:
|
||||
//
|
||||
// nsWideInputFileStream, nsWideOutputFileStream, nsWideIOFileStream
|
||||
//
|
||||
// This suite provide the following services:
|
||||
//
|
||||
// 1. Encapsulates all platform-specific file details, so that file i/o
|
||||
// can be done correctly without any platform #ifdefs
|
||||
//
|
||||
// 2. Uses NSPR file services (NOT ansi file I/O), in order to get best
|
||||
// native performance. This performance difference is especially large on
|
||||
// macintosh.
|
||||
//
|
||||
// 3. Allows all the power of the ansi stream syntax: these streams
|
||||
// ARE derived classes of ostream, istream, and iostream. ALL METHODS OF
|
||||
// istream, ostream, AND iostream ARE AVAILABLE!
|
||||
//
|
||||
// Basic example:
|
||||
//
|
||||
// nsFilePath myPath("/Development/iotest.txt");
|
||||
//
|
||||
// nsOutputFileStream testStream(myPath);
|
||||
// testStream << "Hello World" << endl;
|
||||
//
|
||||
// 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
|
||||
// is inevitable if you use NSPR alone:
|
||||
//
|
||||
// The problem on platforms (Macintosh) in which a path does not fully
|
||||
// specify a file, because two volumes can have the same name.
|
||||
//
|
||||
// Not yet provided:
|
||||
//
|
||||
// Endian-awareness for reading and writing crossplatform binary files. At this
|
||||
// time there seems to be no demand for this.
|
||||
//
|
||||
//========================================================================================
|
||||
|
||||
#ifndef _FILESTREAM_H_
|
||||
#define _FILESTREAM_H_
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
#ifdef XP_MAC
|
||||
#include "pprio.h" // To get PR_ImportFile
|
||||
#else
|
||||
#include "prio.h"
|
||||
#endif
|
||||
#include "nsFileSpec.h"
|
||||
|
||||
//========================================================================================
|
||||
// Compiler-specific macros, as needed
|
||||
//========================================================================================
|
||||
#if !defined(NS_USING_NAMESPACE) && (defined(__MWERKS__) || defined(XP_PC))
|
||||
#define NS_USING_NAMESPACE
|
||||
#endif
|
||||
|
||||
#if !defined(NS_USING_STL) && (defined(__MWERKS__) || defined(XP_PC))
|
||||
#define NS_USING_STL
|
||||
#endif
|
||||
|
||||
#ifdef NS_USING_NAMESPACE
|
||||
|
||||
#define NS_NAMESPACE_PROTOTYPE
|
||||
#define NS_NAMESPACE namespace
|
||||
#define NS_NAMESPACE_END
|
||||
|
||||
#else
|
||||
|
||||
#define NS_NAMESPACE_PROTOTYPE static
|
||||
#define NS_NAMESPACE struct
|
||||
#define NS_NAMESPACE_END ;
|
||||
|
||||
#endif // NS_USING_NAMESPACE
|
||||
|
||||
#ifdef NS_USING_STL
|
||||
|
||||
// Macintosh and Windows use this section.
|
||||
//
|
||||
// Here's where the party is. When Unix wants to join in (by supporting
|
||||
// a build system with STL headers), what fun we'll have! Meanwhile, I've used
|
||||
// macros to make this build on all our platforms. Unix doesn't have support for
|
||||
// STL, and therefore we could not use the template forms of these classes on Unix.
|
||||
// (it's a long story). Therefore, Unix supports no stream char types except 1-byte
|
||||
// characters, and therefore nobody else does now either, until Unix catches up.
|
||||
|
||||
|
||||
#define DEFINING_FILE_STREAM // templateers define this when this file is included.
|
||||
#define IOS_BASE ios_base
|
||||
#include <istream>
|
||||
using std::ios_base;
|
||||
using std::basic_streambuf;
|
||||
using std::codecvt_base;
|
||||
using std::codecvt;
|
||||
using std::streamsize;
|
||||
using std::locale;
|
||||
using std::basic_istream;
|
||||
using std::basic_ostream;
|
||||
using std::basic_iostream;
|
||||
using std::char_traits;
|
||||
#define TEMPLATE_DEF template<class charT, class traits>
|
||||
#define FILE_BUFFER_TYPE nsFileBufferT<charT, traits>
|
||||
#define INPUT_FILE_STREAM nsInputFileStreamT<charT, traits>
|
||||
#define OUTPUT_FILE_STREAM nsOutputFileStreamT<charT, traits>
|
||||
#define IO_FILE_STREAM nsIOFileStreamT<charT, traits>
|
||||
#define BASIC_STREAMBUF basic_streambuf<charT, traits>
|
||||
#define BASIC_ISTREAM basic_istream<charT, traits>
|
||||
#define BASIC_OSTREAM basic_ostream<charT, traits>
|
||||
#define BASIC_IOSTREAM basic_iostream<charT, traits>
|
||||
#define INT_TYPE FILE_BUFFER_TYPE::int_type
|
||||
#define POS_TYPE FILE_BUFFER_TYPE::pos_type
|
||||
#define OFF_TYPE FILE_BUFFER_TYPE::off_type
|
||||
#define SEEK_DIR IOS_BASE::seekdir
|
||||
#define EOF_VALUE traits::eof()
|
||||
|
||||
#else
|
||||
|
||||
// Unix uses this section until it supports STL. This means no locales, no traits,
|
||||
// no wide chars, etc. Also, the stream classes are the original ARM-style ones,
|
||||
// and are not templatized.
|
||||
|
||||
#define IOS_BASE ios
|
||||
#include <istream.h>
|
||||
#define TEMPLATE_DEF
|
||||
#define FILE_BUFFER_TYPE nsFileBufferT
|
||||
#define INPUT_FILE_STREAM nsInputFileStreamT
|
||||
#define OUTPUT_FILE_STREAM nsOutputFileStreamT
|
||||
#define IO_FILE_STREAM nsIOFileStreamT
|
||||
#define BASIC_STREAMBUF streambuf
|
||||
#define BASIC_ISTREAM istream
|
||||
#define BASIC_OSTREAM ostream
|
||||
#define BASIC_IOSTREAM iostream
|
||||
#define INT_TYPE int
|
||||
#define POS_TYPE long
|
||||
#define OFF_TYPE long
|
||||
#define SEEK_DIR ios::seek_dir
|
||||
#define int_type int
|
||||
#define pos_type long
|
||||
#define off_type long
|
||||
#define char_type char
|
||||
#define EOF_VALUE EOF
|
||||
|
||||
#endif // NS_USING_STL
|
||||
|
||||
#ifdef __MWERKS__
|
||||
|
||||
#ifdef MSIPL_WCHART
|
||||
#define NS_USING_WIDE_CHAR
|
||||
#endif
|
||||
#ifdef MSIPL_EXPLICIT_FUNC_TEMPLATE_ARG
|
||||
#define NS_EXPLICIT_FUNC_TEMPLATE_ARG
|
||||
#endif
|
||||
#define NS_READ_LOCK(mut) READ_LOCK(mut)
|
||||
#define NS_WRITE_LOCK(mut) WRITE_LOCK(mut)
|
||||
|
||||
#else
|
||||
|
||||
// Fix me, if necessary, for thread-safety.
|
||||
#define NS_READ_LOCK(mut)
|
||||
#define NS_WRITE_LOCK(mut)
|
||||
|
||||
#endif // __MWERKS__
|
||||
|
||||
//=========================== End Compiler-specific macros ===============================
|
||||
|
||||
//========================================================================================
|
||||
NS_NAMESPACE nsFileStreamHelpers
|
||||
// Prototypes for common (non-template) implementations in the .cpp file which do not
|
||||
// need the template args (charT, traits).
|
||||
//========================================================================================
|
||||
{
|
||||
NS_NAMESPACE_PROTOTYPE NS_BASE PRFileDesc* open(
|
||||
const nsFilePath& inFile,
|
||||
IOS_BASE::openmode mode,
|
||||
PRIntn accessMode);
|
||||
} NS_NAMESPACE_END // nsFileStreamHelpers
|
||||
|
||||
//========================================================================================
|
||||
// Template declarations
|
||||
//========================================================================================
|
||||
|
||||
//========================================================================================
|
||||
TEMPLATE_DEF
|
||||
class nsFileBufferT
|
||||
//========================================================================================
|
||||
: public BASIC_STREAMBUF
|
||||
{
|
||||
#ifdef NS_USING_STL
|
||||
typedef codecvt_base::result result;
|
||||
|
||||
public:
|
||||
typedef charT char_type;
|
||||
typedef typename traits::pos_type pos_type;
|
||||
typedef typename traits::off_type off_type;
|
||||
typedef typename traits::int_type int_type;
|
||||
typedef traits traits_type;
|
||||
typedef typename traits::state_type state_type;
|
||||
|
||||
typedef codecvt<charT, char, state_type> ofacet_type;
|
||||
typedef codecvt<char, charT, state_type> ifacet_type;
|
||||
#endif
|
||||
|
||||
public:
|
||||
nsFileBufferT();
|
||||
nsFileBufferT(PRFileDesc* pfile_arg);
|
||||
virtual ~nsFileBufferT();
|
||||
bool is_open() const;
|
||||
FILE_BUFFER_TYPE* open(
|
||||
const nsFilePath& inFile,
|
||||
IOS_BASE::openmode mode,
|
||||
PRIntn accessMode);
|
||||
FILE_BUFFER_TYPE* close();
|
||||
|
||||
protected:
|
||||
virtual int_type overflow(int_type c=EOF_VALUE);
|
||||
virtual int_type pbackfail(int_type c=EOF_VALUE);
|
||||
virtual int_type underflow();
|
||||
virtual pos_type seekoff(
|
||||
off_type off, SEEK_DIR way,
|
||||
IOS_BASE::openmode which=IOS_BASE::in|IOS_BASE::out);
|
||||
virtual pos_type seekpos(pos_type sp,
|
||||
IOS_BASE::openmode which=IOS_BASE::in|IOS_BASE::out);
|
||||
virtual BASIC_STREAMBUF* setbuf(char_type* s, streamsize n);
|
||||
virtual int sync();
|
||||
virtual int_type uflow();
|
||||
#ifdef NS_USING_STL
|
||||
virtual void imbue(const locale& loc);
|
||||
#endif
|
||||
virtual streamsize showmanyc();
|
||||
virtual streamsize xsgetn(char_type* s, streamsize n);
|
||||
virtual streamsize xsputn(const char_type* s, streamsize n);
|
||||
|
||||
private:
|
||||
PRFileDesc* mFileDesc;
|
||||
IOS_BASE::openmode mode_;
|
||||
}; // class nsFileBufferT
|
||||
|
||||
//========================================================================================
|
||||
TEMPLATE_DEF
|
||||
class nsInputFileStreamT
|
||||
//========================================================================================
|
||||
: public BASIC_ISTREAM
|
||||
{
|
||||
#ifdef NS_USING_STL
|
||||
public:
|
||||
typedef charT char_type;
|
||||
typedef typename traits::pos_type pos_type;
|
||||
typedef typename traits::off_type off_type;
|
||||
typedef typename traits::int_type int_type;
|
||||
typedef traits traits_type;
|
||||
#endif
|
||||
|
||||
public:
|
||||
nsInputFileStreamT();
|
||||
explicit nsInputFileStreamT(
|
||||
const nsFilePath& inFile,
|
||||
IOS_BASE::openmode mode=IOS_BASE::in,
|
||||
PRIntn accessMode = 0x00400);
|
||||
|
||||
virtual ~nsInputFileStreamT();
|
||||
|
||||
FILE_BUFFER_TYPE* rdbuf() const;
|
||||
inline bool is_open();
|
||||
inline void open(
|
||||
const nsFilePath& inFile,
|
||||
IOS_BASE::openmode mode=IOS_BASE::in,
|
||||
PRIntn accessMode = 0x00400);
|
||||
inline void close();
|
||||
|
||||
private:
|
||||
FILE_BUFFER_TYPE mBuffer;
|
||||
}; // class nsInputFileStreamT
|
||||
|
||||
//========================================================================================
|
||||
TEMPLATE_DEF
|
||||
class nsOutputFileStreamT
|
||||
//========================================================================================
|
||||
: public BASIC_OSTREAM
|
||||
{
|
||||
#ifdef NS_USING_STL
|
||||
public:
|
||||
typedef charT char_type;
|
||||
typedef typename traits::pos_type pos_type;
|
||||
typedef typename traits::off_type off_type;
|
||||
typedef typename traits::int_type int_type;
|
||||
typedef traits traits_type;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
nsOutputFileStreamT();
|
||||
explicit nsOutputFileStreamT(
|
||||
const nsFilePath& inFile,
|
||||
IOS_BASE::openmode mode = IOS_BASE::out|IOS_BASE::trunc,
|
||||
PRIntn accessMode = 0x00200);
|
||||
|
||||
virtual ~nsOutputFileStreamT();
|
||||
|
||||
FILE_BUFFER_TYPE* rdbuf() const;
|
||||
inline bool is_open();
|
||||
inline void open(
|
||||
const nsFilePath& inFile,
|
||||
IOS_BASE::openmode mode = IOS_BASE::out|IOS_BASE::trunc,
|
||||
PRIntn accessMode = 0x00200);
|
||||
inline void close();
|
||||
|
||||
private:
|
||||
FILE_BUFFER_TYPE mBuffer;
|
||||
}; // class nsOutputFileStreamT
|
||||
|
||||
//========================================================================================
|
||||
// Implementation of nsFileBufferT
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline FILE_BUFFER_TYPE::nsFileBufferT()
|
||||
: BASIC_STREAMBUF(), mFileDesc(NULL)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline FILE_BUFFER_TYPE::nsFileBufferT(PRFileDesc* pfarg)
|
||||
: BASIC_STREAMBUF(), mFileDesc(pfarg)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline FILE_BUFFER_TYPE* FILE_BUFFER_TYPE::close()
|
||||
// Must precede the destructor because both are inline.
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (mFileDesc==PR_STDIN || mFileDesc==PR_STDOUT || mFileDesc==PR_STDERR)
|
||||
return this;
|
||||
NS_WRITE_LOCK(_mutex);
|
||||
return (mFileDesc && PR_Close(mFileDesc) == PR_SUCCESS) ? mFileDesc = 0, this : 0;
|
||||
}
|
||||
|
||||
#if defined(DEFINING_FILE_STREAM)
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
FILE_BUFFER_TYPE::~nsFileBufferT()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
close();
|
||||
}
|
||||
#endif // #if defined(DEFINING_FILE_STREAM)
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline bool
|
||||
FILE_BUFFER_TYPE::is_open() const
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
NS_READ_LOCK(_mutex);
|
||||
return bool(mFileDesc); // in case it is typedefed to int
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline FILE_BUFFER_TYPE* FILE_BUFFER_TYPE::open(
|
||||
const nsFilePath& inFile,
|
||||
IOS_BASE::openmode mode,
|
||||
PRIntn accessMode)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (mFileDesc)
|
||||
return 0;
|
||||
NS_WRITE_LOCK(_mutex);
|
||||
mFileDesc = nsFileStreamHelpers::open(inFile, mode, accessMode);
|
||||
if (!mFileDesc)
|
||||
return 0;
|
||||
mode_ = mode;
|
||||
return this;
|
||||
} // FILE_BUFFER_TYPE::open
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline int FILE_BUFFER_TYPE:: sync()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return (mFileDesc ? (int)PR_Sync(mFileDesc) : 0);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline BASIC_STREAMBUF* FILE_BUFFER_TYPE::setbuf(char_type*, streamsize)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return (!mFileDesc) ? 0 : this;
|
||||
}
|
||||
|
||||
#if defined(DEFINING_FILE_STREAM)
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
INT_TYPE FILE_BUFFER_TYPE::overflow(int_type c)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
#ifndef NS_USING_STL
|
||||
char ch = c;
|
||||
PRInt32 bytesWrit1 = PR_Write(mFileDesc, &ch, sizeof(ch));
|
||||
return bytesWrit1 < sizeof(ch) ? EOF_VALUE : c;
|
||||
#else
|
||||
#ifdef NS_EXPLICIT_FUNC_TEMPLATE_ARG
|
||||
const ofacet_type& ft=use_facet<ofacet_type>(getloc());
|
||||
#elif defined(XP_PC)
|
||||
const ofacet_type& ft=use_facet(getloc(), (ofacet_type*)0, false);
|
||||
#else
|
||||
const ofacet_type& ft=use_facet(getloc(), (ofacet_type*)0);
|
||||
#endif
|
||||
char_type ch = traits_type::to_char_type(c);
|
||||
if (!mFileDesc)
|
||||
return EOF_VALUE;
|
||||
if (traits_type::eq_int_type(c, EOF_VALUE))
|
||||
return traits_type::not_eof(c);
|
||||
if (ft.always_noconv())
|
||||
{
|
||||
PRInt32 bytesWrit1 = PR_Write(mFileDesc, &ch, sizeof(ch));
|
||||
return bytesWrit1 < sizeof(ch) ? EOF_VALUE : c;
|
||||
}
|
||||
{ // <- sic!
|
||||
state_type fst;
|
||||
const char_type* end;
|
||||
char buf[4];
|
||||
char* ebuf;
|
||||
result conv;
|
||||
if ((conv=ft.out(fst, &ch, &ch+1, end, buf, buf+3, ebuf))==
|
||||
codecvt_base::noconv)
|
||||
{
|
||||
PRInt32 bytesWrit2 = PR_Write(mFileDesc, &ch, sizeof(ch));
|
||||
return bytesWrit2 < sizeof(ch) ? EOF_VALUE : c;
|
||||
}
|
||||
if ((conv==codecvt_base::partial)||(conv==codecvt_base::error))
|
||||
return EOF_VALUE;
|
||||
*ebuf=0;
|
||||
PRInt32 bytesWrit3 = strlen(buf);
|
||||
return PR_Write(mFileDesc, buf, bytesWrit3) < bytesWrit3 ? EOF_VALUE : c;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif // #if defined(DEFINING_FILE_STREAM)
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline INT_TYPE FILE_BUFFER_TYPE::underflow()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!mFileDesc)
|
||||
return EOF_VALUE;
|
||||
char_type s;
|
||||
PRInt32 request = 1;
|
||||
if (1 != PR_Read(mFileDesc, &s, request))
|
||||
return EOF_VALUE;
|
||||
PR_Seek(mFileDesc, -1, PR_SEEK_CUR);
|
||||
return (int_type)s;
|
||||
}
|
||||
|
||||
#if defined(DEFINING_FILE_STREAM)
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
streamsize FILE_BUFFER_TYPE::xsputn(const char_type* s, streamsize n)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
#ifndef NS_USING_STL
|
||||
PRInt32 bytesWrit1 = PR_Write(mFileDesc, s, sizeof(char) * size_t(n));
|
||||
return bytesWrit1 < 0 ? 0 : (streamsize)bytesWrit1;
|
||||
#else
|
||||
#ifdef NS_EXPLICIT_FUNC_TEMPLATE_ARG
|
||||
const ofacet_type& ft=use_facet<ofacet_type>(loc);
|
||||
#elif defined(XP_PC)
|
||||
const ofacet_type& ft=use_facet(getloc(), (ofacet_type*)0, false);
|
||||
#else
|
||||
const ofacet_type& ft=use_facet(getloc(), (ofacet_type*)0);
|
||||
#endif
|
||||
if (!mFileDesc || !n)
|
||||
return 0;
|
||||
if (ft.always_noconv())
|
||||
{
|
||||
PRInt32 bytesWrit1 = PR_Write(mFileDesc, s, sizeof(char) * size_t(n));
|
||||
return bytesWrit1 < 0 ? 0 : (streamsize)bytesWrit1;
|
||||
}
|
||||
{ // <- sic!
|
||||
state_type fst;
|
||||
const char_type* end;
|
||||
char buf[8];
|
||||
char* ebuf;
|
||||
result conv;
|
||||
#ifdef NS_EXPLICIT_FUNC_TEMPLATE_ARG
|
||||
if ((conv=use_facet<ofacet_type>(getloc()).
|
||||
#elif defined(XP_PC)
|
||||
if ((conv=use_facet(getloc(), (ofacet_type*)0, false).
|
||||
#else
|
||||
if ((conv=use_facet(getloc(), (ofacet_type*)0).
|
||||
#endif
|
||||
out(fst, s, s+n, end, buf, buf+7, ebuf))==codecvt_base::noconv)
|
||||
return (streamsize)PR_Write(mFileDesc, s, sizeof(char) * size_t(n));
|
||||
if ((conv==codecvt_base::partial) ||(conv==codecvt_base::error))
|
||||
return 0;
|
||||
*ebuf=0;
|
||||
PRInt32 bytesWrit2 = strlen(buf);
|
||||
bytesWrit2 = PR_Write(mFileDesc, buf, bytesWrit2);
|
||||
return bytesWrit2 < 0 ? 0 : streamsize(bytesWrit2 / sizeof(char_type));
|
||||
}
|
||||
#endif
|
||||
} // FILE_BUFFER_TYPE::xsputn
|
||||
#endif // #if defined(DEFINING_FILE_STREAM)
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline INT_TYPE FILE_BUFFER_TYPE::pbackfail(int_type c)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!mFileDesc)
|
||||
return EOF_VALUE;
|
||||
if (PR_Seek(mFileDesc, -1, PR_SEEK_CUR) < 0)
|
||||
return EOF_VALUE;
|
||||
#ifdef NS_USING_STL
|
||||
return (traits::eq_int_type(c, EOF_VALUE)) ? traits::not_eof(c) : c;
|
||||
#else
|
||||
return c;
|
||||
#endif
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline INT_TYPE FILE_BUFFER_TYPE::uflow()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!mFileDesc)
|
||||
return EOF_VALUE;
|
||||
char_type s;
|
||||
if (1 != PR_Read(mFileDesc, &s, 1)) // attempt to read 1 byte, confirm 1 byte
|
||||
return EOF_VALUE;
|
||||
return (int_type)s;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline streamsize FILE_BUFFER_TYPE::xsgetn(char_type* s, streamsize n)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return mFileDesc ? (streamsize)PR_Read(mFileDesc, s, sizeof(char) * size_t(n)) : 0;
|
||||
}
|
||||
|
||||
#ifdef NS_USING_STL
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline void FILE_BUFFER_TYPE::imbue(const locale& loc_arg)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
#ifdef XP_MAC
|
||||
loc = loc_arg;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline streamsize FILE_BUFFER_TYPE::showmanyc()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return (streamsize)PR_Available(mFileDesc);
|
||||
}
|
||||
|
||||
#if defined(DEFINING_FILE_STREAM)
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
POS_TYPE FILE_BUFFER_TYPE::seekoff(
|
||||
OFF_TYPE off,
|
||||
SEEK_DIR way,
|
||||
IOS_BASE::openmode /* which */)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!mFileDesc ||
|
||||
#ifdef NS_USING_STL
|
||||
((way&IOS_BASE::beg) && off<0) || ((way&IOS_BASE::end) && off > 0)
|
||||
#else
|
||||
((way == IOS_BASE::beg) && off<0) || ((way == IOS_BASE::end) && off > 0)
|
||||
#endif
|
||||
)
|
||||
return pos_type(-1);
|
||||
PRSeekWhence poseek = PR_SEEK_CUR;
|
||||
switch (way)
|
||||
{
|
||||
case IOS_BASE::beg : poseek= PR_SEEK_SET;
|
||||
break;
|
||||
case IOS_BASE::end : poseek= PR_SEEK_END;
|
||||
break;
|
||||
}
|
||||
PRInt32 position = PR_Seek(mFileDesc, off, poseek);
|
||||
if (position < 0)
|
||||
return pos_type(-1);
|
||||
return pos_type(position);
|
||||
}
|
||||
#endif // #if defined(DEFINING_FILE_STREAM)
|
||||
|
||||
#if defined(DEFINING_FILE_STREAM)
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
POS_TYPE FILE_BUFFER_TYPE::seekpos(pos_type sp, IOS_BASE::openmode)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!mFileDesc || sp==pos_type(-1))
|
||||
return -1;
|
||||
#if defined(XP_PC) || defined(XP_UNIX)
|
||||
PRInt32 position = sp;
|
||||
#else
|
||||
PRInt32 position = sp.offset();
|
||||
#endif
|
||||
position = PR_Seek(mFileDesc, position, PR_SEEK_SET);
|
||||
if (position < 0)
|
||||
return pos_type(-1);
|
||||
return position;
|
||||
}
|
||||
#endif // #if defined(DEFINING_FILE_STREAM)
|
||||
|
||||
//========================================================================================
|
||||
// Implementation of nsInputFileStreamT
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline INPUT_FILE_STREAM::nsInputFileStreamT()
|
||||
: BASIC_ISTREAM(&mBuffer)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
// already inited
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline INPUT_FILE_STREAM::nsInputFileStreamT(
|
||||
const nsFilePath& inFile,
|
||||
IOS_BASE::openmode mode,
|
||||
PRIntn accessMode)
|
||||
//----------------------------------------------------------------------------------------
|
||||
: BASIC_ISTREAM(&mBuffer)
|
||||
{
|
||||
// already inited
|
||||
if (!mBuffer.open(inFile, openmode(mode|in), accessMode))
|
||||
setstate(failbit);
|
||||
}
|
||||
|
||||
#if defined(DEFINING_FILE_STREAM)
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
INPUT_FILE_STREAM::~nsInputFileStreamT()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
}
|
||||
#endif // #if defined(DEFINING_FILE_STREAM)
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline FILE_BUFFER_TYPE* INPUT_FILE_STREAM::rdbuf() const
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return (FILE_BUFFER_TYPE*)&mBuffer;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline bool INPUT_FILE_STREAM:: is_open()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return mBuffer.is_open();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline void INPUT_FILE_STREAM::open(
|
||||
const nsFilePath& inFile,
|
||||
IOS_BASE::openmode mode,
|
||||
PRIntn accessMode)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!mBuffer.open(inFile, openmode(mode|in), accessMode))
|
||||
setstate(failbit);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline void INPUT_FILE_STREAM::close()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!mBuffer.close())
|
||||
setstate(failbit);
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// Implementation of nsOutputFileStreamT
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline OUTPUT_FILE_STREAM::nsOutputFileStreamT()
|
||||
: BASIC_OSTREAM(&mBuffer)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
// already inited
|
||||
}
|
||||
|
||||
#if defined(DEFINING_FILE_STREAM)
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
OUTPUT_FILE_STREAM::nsOutputFileStreamT(
|
||||
const nsFilePath& inFile,
|
||||
IOS_BASE::openmode mode,
|
||||
PRIntn accessMode)
|
||||
//----------------------------------------------------------------------------------------
|
||||
: BASIC_OSTREAM(&mBuffer)
|
||||
{
|
||||
// already inited
|
||||
if (!mBuffer.open(inFile, openmode(mode|out), accessMode))
|
||||
setstate(failbit);
|
||||
}
|
||||
#endif // #if defined(DEFINING_FILE_STREAM)
|
||||
|
||||
#if defined(DEFINING_FILE_STREAM)
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline OUTPUT_FILE_STREAM::~nsOutputFileStreamT()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
}
|
||||
#endif // #if defined(DEFINING_FILE_STREAM)
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline FILE_BUFFER_TYPE*
|
||||
OUTPUT_FILE_STREAM::rdbuf() const
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return (FILE_BUFFER_TYPE*)&mBuffer;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline bool OUTPUT_FILE_STREAM:: is_open()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return mBuffer.is_open();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline void OUTPUT_FILE_STREAM::open(
|
||||
const nsFilePath& inFile,
|
||||
IOS_BASE::openmode mode,
|
||||
PRIntn accessMode)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!mBuffer.open(inFile, openmode(mode | out), accessMode))
|
||||
setstate(failbit);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline void OUTPUT_FILE_STREAM:: close()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!mBuffer.close())
|
||||
setstate(failbit);
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
TEMPLATE_DEF
|
||||
class nsIOFileStreamT : public BASIC_IOSTREAM
|
||||
//========================================================================================
|
||||
{
|
||||
#ifdef NS_USING_STL
|
||||
public:
|
||||
typedef charT char_type;
|
||||
typedef typename traits::pos_type pos_type;
|
||||
typedef typename traits::off_type off_type;
|
||||
typedef typename traits::int_type int_type;
|
||||
typedef traits traits_type;
|
||||
#endif
|
||||
|
||||
public:
|
||||
nsIOFileStreamT();
|
||||
explicit nsIOFileStreamT(
|
||||
const nsFilePath& inFile,
|
||||
IOS_BASE::openmode mode = IOS_BASE::in|IOS_BASE::out,
|
||||
PRIntn accessMode = 0x00600);
|
||||
|
||||
virtual ~nsIOFileStreamT();
|
||||
|
||||
FILE_BUFFER_TYPE* rdbuf() const;
|
||||
inline bool is_open();
|
||||
inline void open(
|
||||
const nsFilePath& inFile,
|
||||
IOS_BASE::openmode mode = IOS_BASE::in|IOS_BASE::out,
|
||||
PRIntn accessMode = 0x00600);
|
||||
inline void close();
|
||||
|
||||
private:
|
||||
FILE_BUFFER_TYPE mBuffer;
|
||||
}; // class nsIOFileStreamT
|
||||
|
||||
//========================================================================================
|
||||
// Implementation of nsIOFileStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline IO_FILE_STREAM::nsIOFileStreamT()
|
||||
//----------------------------------------------------------------------------------------
|
||||
: mBuffer(), BASIC_IOSTREAM(&mBuffer)
|
||||
{
|
||||
// already inited
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline IO_FILE_STREAM::nsIOFileStreamT(
|
||||
const nsFilePath& inFile,
|
||||
IOS_BASE::openmode mode,
|
||||
PRIntn accessMode)
|
||||
//----------------------------------------------------------------------------------------
|
||||
: mBuffer(), BASIC_IOSTREAM(&mBuffer)
|
||||
{
|
||||
// already inited
|
||||
if (!mBuffer.open(inFile, mode, accessMode))
|
||||
setstate(failbit);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline IO_FILE_STREAM::~nsIOFileStreamT()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline FILE_BUFFER_TYPE*
|
||||
IO_FILE_STREAM::rdbuf() const
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return (FILE_BUFFER_TYPE*)&mBuffer;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline bool IO_FILE_STREAM::is_open()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return mBuffer.is_open();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline void IO_FILE_STREAM::open(
|
||||
const nsFilePath& inFile,
|
||||
IOS_BASE::openmode mode,
|
||||
PRIntn accessMode)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!mBuffer.open(inFile, mode, accessMode))
|
||||
setstate(failbit);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TEMPLATE_DEF
|
||||
inline void IO_FILE_STREAM::close()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!mBuffer.close())
|
||||
setstate(failbit);
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// Specializations of the stream templates
|
||||
//========================================================================================
|
||||
|
||||
#ifdef NS_USING_STL
|
||||
typedef nsFileBufferT<char, char_traits<char> > nsFileBuffer;
|
||||
typedef nsInputFileStreamT<char, char_traits<char> > nsInputFileStream;
|
||||
typedef nsOutputFileStreamT<char, char_traits<char> > nsOutputFileStream;
|
||||
typedef nsIOFileStreamT<char, char_traits<char> > nsIOFileStream;
|
||||
|
||||
#ifdef NS_USING_WIDE_CHAR
|
||||
typedef nsFileBufferT<wchar_t, char_traits<wchar_t> > nsWideFileBuffer;
|
||||
typedef nsInputFileStreamT<wchar_t, char_traits<wchar_t> > nsWideInputFileStream;
|
||||
typedef nsOutputFileStreamT<wchar_t, char_traits<wchar_t> > nsWideOutputFileStream;
|
||||
typedef nsIOFileStreamT<wchar_t, char_traits<wchar_t> > nsWideIOFileStream;
|
||||
#endif // NS_USING_WIDE_CHAR
|
||||
|
||||
#else
|
||||
|
||||
typedef nsFileBufferT nsFileBuffer;
|
||||
typedef nsInputFileStreamT nsInputFileStream;
|
||||
typedef nsOutputFileStreamT nsOutputFileStream;
|
||||
typedef nsIOFileStreamT nsIOFileStream;
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _FILESTREAM_H_ */
|
||||
|
||||
28
mozilla/base/src/MANIFEST
Normal file
28
mozilla/base/src/MANIFEST
Normal file
@@ -0,0 +1,28 @@
|
||||
#
|
||||
# This is a list of local files which get copied to the mozilla:dist directory
|
||||
#
|
||||
|
||||
nscore.h
|
||||
nsIArena.h
|
||||
nsIAtom.h
|
||||
nsIByteBuffer.h
|
||||
nsBTree.h
|
||||
nsCRT.h
|
||||
nsDeque.h
|
||||
nsITimer.h
|
||||
nsITimerCallback.h
|
||||
nsIUnicharBuffer.h
|
||||
nsRBTree.h
|
||||
nsIUnicharInputStream.h
|
||||
nsStr.h
|
||||
nsString.h
|
||||
nsString2.h
|
||||
nsVoidArray.h
|
||||
nsUnitConversion.h
|
||||
nsIBaseStream.h
|
||||
nsIInputStream.h
|
||||
nsIOutputStream.h
|
||||
nsInt64.h
|
||||
nsTime.h
|
||||
nsStr.h
|
||||
nsString2.h
|
||||
105
mozilla/base/src/Makefile.in
Normal file
105
mozilla/base/src/Makefile.in
Normal file
@@ -0,0 +1,105 @@
|
||||
#!gmake
|
||||
#
|
||||
# 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.
|
||||
|
||||
DEPTH=../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DEFINES +=-D_IMPL_NS_BASE
|
||||
|
||||
LOCAL_INCLUDES += -I$(topsrcdir)/base/public
|
||||
|
||||
DIRS = $(MOZ_TOOLKIT)
|
||||
|
||||
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 = \
|
||||
nscore.h \
|
||||
nsBTree.h \
|
||||
nsCRT.h \
|
||||
nsDeque.h \
|
||||
nsIArena.h \
|
||||
nsIAtom.h \
|
||||
nsIByteBuffer.h \
|
||||
nsIBaseStream.h \
|
||||
nsIInputStream.h \
|
||||
nsIOutputStream.h \
|
||||
nsITimer.h \
|
||||
nsITimerCallback.h \
|
||||
nsIUnicharBuffer.h \
|
||||
nsIUnicharInputStream.h \
|
||||
nsInt64.h \
|
||||
nsRBTree.h \
|
||||
nsStr.h \
|
||||
nsString.h \
|
||||
nsString2.h \
|
||||
nsTime.h \
|
||||
nsVoidArray.h \
|
||||
nsUnitConversion.h \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
MODULE=base
|
||||
|
||||
REQUIRES = xpcom netlib raptor
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
TARGET = $(LIBARY)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
894
mozilla/base/src/bufferRoutines.h
Normal file
894
mozilla/base/src/bufferRoutines.h
Normal file
@@ -0,0 +1,894 @@
|
||||
/* -*- 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
|
||||
42
mozilla/base/src/gtk/Makefile.in
Normal file
42
mozilla/base/src/gtk/Makefile.in
Normal file
@@ -0,0 +1,42 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
LIBRARY_NAME = gmbasegtk
|
||||
|
||||
MODULE=base
|
||||
|
||||
REQUIRES = xpcom raptor
|
||||
|
||||
DEFINES += -D_IMPL_NS_WIDGET
|
||||
|
||||
CPPSRCS = \
|
||||
nsTimer.cpp \
|
||||
nsCaretProperties.cpp \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
CXXFLAGS += $(TK_CFLAGS)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
40
mozilla/base/src/gtk/nsCaretProperties.cpp
Normal file
40
mozilla/base/src/gtk/nsCaretProperties.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/* -*- 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();
|
||||
}
|
||||
191
mozilla/base/src/gtk/nsTimer.cpp
Normal file
191
mozilla/base/src/gtk/nsTimer.cpp
Normal file
@@ -0,0 +1,191 @@
|
||||
/* -*- 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 "nsITimer.h"
|
||||
#include "nsITimerCallback.h"
|
||||
#include "nsCRT.h"
|
||||
#include "prlog.h"
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID);
|
||||
|
||||
extern "C" gint nsTimerExpired(gpointer aCallData);
|
||||
|
||||
/*
|
||||
* Implementation of timers using Gtk timer facility
|
||||
*/
|
||||
class TimerImpl : public nsITimer {
|
||||
public:
|
||||
|
||||
public:
|
||||
TimerImpl();
|
||||
virtual ~TimerImpl();
|
||||
|
||||
virtual nsresult Init(nsTimerCallbackFunc aFunc,
|
||||
void *aClosure,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay);
|
||||
|
||||
virtual nsresult Init(nsITimerCallback *aCallback,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual void Cancel();
|
||||
virtual PRUint32 GetDelay() { return mDelay; }
|
||||
virtual void SetDelay(PRUint32 aDelay) { mDelay=aDelay; };
|
||||
virtual void* GetClosure() { return mClosure; }
|
||||
|
||||
void FireTimeout();
|
||||
|
||||
private:
|
||||
nsresult Init(PRUint32 aDelay);
|
||||
|
||||
PRUint32 mDelay;
|
||||
nsTimerCallbackFunc mFunc;
|
||||
void *mClosure;
|
||||
nsITimerCallback *mCallback;
|
||||
// PRBool mRepeat;
|
||||
TimerImpl *mNext;
|
||||
guint mTimerId;
|
||||
};
|
||||
|
||||
void TimerImpl::FireTimeout()
|
||||
{
|
||||
if (mFunc != NULL) {
|
||||
(*mFunc)(this, mClosure);
|
||||
}
|
||||
else if (mCallback != NULL) {
|
||||
mCallback->Notify(this); // Fire the timer
|
||||
}
|
||||
|
||||
// Always repeating here
|
||||
|
||||
// if (mRepeat)
|
||||
// mTimerId = gtk_timeout_add(aDelay, nsTimerExpired, this);
|
||||
}
|
||||
|
||||
|
||||
TimerImpl::TimerImpl()
|
||||
{
|
||||
// printf("TimerImple::TimerImpl called for %p\n", this);
|
||||
NS_INIT_REFCNT();
|
||||
mFunc = NULL;
|
||||
mCallback = NULL;
|
||||
mNext = NULL;
|
||||
mTimerId = 0;
|
||||
mDelay = 0;
|
||||
mClosure = NULL;
|
||||
}
|
||||
|
||||
TimerImpl::~TimerImpl()
|
||||
{
|
||||
//printf("TimerImpl::~TimerImpl called for %p\n", this);
|
||||
Cancel();
|
||||
NS_IF_RELEASE(mCallback);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TimerImpl::Init(nsTimerCallbackFunc aFunc,
|
||||
void *aClosure,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay)
|
||||
{
|
||||
//printf("TimerImpl::Init called with func + closure for %p\n", this);
|
||||
mFunc = aFunc;
|
||||
mClosure = aClosure;
|
||||
// mRepeat = aRepeat;
|
||||
|
||||
if ((aDelay > 10000) || (aDelay < 0)) {
|
||||
printf("Timer::Init() called with bogus value \"%d\"! Not enabling timer.\n",
|
||||
aDelay);
|
||||
return Init(aDelay);
|
||||
}
|
||||
|
||||
mTimerId = gtk_timeout_add(aDelay, nsTimerExpired, this);
|
||||
|
||||
return Init(aDelay);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TimerImpl::Init(nsITimerCallback *aCallback,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay)
|
||||
{
|
||||
//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",
|
||||
aDelay);
|
||||
return Init(aDelay);
|
||||
}
|
||||
|
||||
mTimerId = gtk_timeout_add(aDelay, nsTimerExpired, this);
|
||||
|
||||
return Init(aDelay);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TimerImpl::Init(PRUint32 aDelay)
|
||||
{
|
||||
//printf("TimerImpl::Init called with delay %d only for %p\n", aDelay, this);
|
||||
|
||||
mDelay = aDelay;
|
||||
// NS_ADDREF(this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(TimerImpl, kITimerIID)
|
||||
|
||||
|
||||
void
|
||||
TimerImpl::Cancel()
|
||||
{
|
||||
//printf("TimerImpl::Cancel called for %p\n", this);
|
||||
TimerImpl *me = this;
|
||||
if (mTimerId)
|
||||
gtk_timeout_remove(mTimerId);
|
||||
}
|
||||
|
||||
NS_BASE nsresult NS_NewTimer(nsITimer** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
TimerImpl *timer = new TimerImpl();
|
||||
if (nsnull == timer) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return timer->QueryInterface(kITimerIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
gint nsTimerExpired(gpointer aCallData)
|
||||
{
|
||||
//printf("nsTimerExpired for %p\n", aCallData);
|
||||
TimerImpl* timer = (TimerImpl *)aCallData;
|
||||
timer->FireTimeout();
|
||||
return 0;
|
||||
}
|
||||
43
mozilla/base/src/mac/nsCaretPropertiesMac.cpp
Normal file
43
mozilla/base/src/mac/nsCaretPropertiesMac.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/* -*- 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();
|
||||
}
|
||||
1257
mozilla/base/src/mac/nsFileSpecMac.cpp
Normal file
1257
mozilla/base/src/mac/nsFileSpecMac.cpp
Normal file
File diff suppressed because it is too large
Load Diff
147
mozilla/base/src/mac/nsRepeater.cpp
Normal file
147
mozilla/base/src/mac/nsRepeater.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
/* -*- 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 "nsRepeater.h"
|
||||
|
||||
Repeater* Repeater::sRepeaters = 0;
|
||||
Repeater* Repeater::sIdlers = 0;
|
||||
|
||||
Repeater::Repeater()
|
||||
{
|
||||
mRepeating = false;
|
||||
mIdling = false;
|
||||
mPrevRptr = 0;
|
||||
mNextRptr = 0;
|
||||
mPrevIdlr = 0;
|
||||
mNextIdlr = 0;
|
||||
}
|
||||
|
||||
Repeater::~Repeater()
|
||||
{
|
||||
if (mRepeating) RemoveFromRepeatList();
|
||||
if (mIdling) RemoveFromIdleList();
|
||||
}
|
||||
|
||||
// protected helper functs
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void Repeater::AddToRepeatList()
|
||||
{
|
||||
if (sRepeaters)
|
||||
{
|
||||
sRepeaters->mPrevRptr = this;
|
||||
mNextRptr = sRepeaters;
|
||||
}
|
||||
sRepeaters = this;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void Repeater::RemoveFromRepeatList()
|
||||
{
|
||||
if (sRepeaters == this) sRepeaters = mNextRptr;
|
||||
if (mPrevRptr) mPrevRptr->mNextRptr = mNextRptr;
|
||||
if (mNextRptr) mNextRptr->mPrevRptr = mPrevRptr;
|
||||
mPrevRptr = 0;
|
||||
mNextRptr = 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void Repeater::AddToIdleList()
|
||||
{
|
||||
if (sIdlers)
|
||||
{
|
||||
sIdlers->mPrevIdlr = this;
|
||||
mNextIdlr = sIdlers;
|
||||
}
|
||||
sIdlers = this;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void Repeater::RemoveFromIdleList()
|
||||
{
|
||||
if (sIdlers == this) sIdlers = mNextIdlr;
|
||||
if (mPrevIdlr) mPrevIdlr->mNextIdlr = mNextIdlr;
|
||||
if (mNextIdlr) mNextIdlr->mPrevIdlr = mPrevIdlr;
|
||||
mPrevIdlr = 0;
|
||||
mNextIdlr = 0;
|
||||
}
|
||||
|
||||
// repeater methods
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
void Repeater::StartRepeating()
|
||||
{
|
||||
if (!mRepeating)
|
||||
{
|
||||
AddToRepeatList();
|
||||
mRepeating = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Repeater::StopRepeating()
|
||||
{
|
||||
if (mRepeating)
|
||||
{
|
||||
RemoveFromRepeatList();
|
||||
mRepeating = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Repeater::DoRepeaters(const EventRecord &aMacEvent)
|
||||
{
|
||||
Repeater* theRepeater = sRepeaters;
|
||||
while (theRepeater)
|
||||
{
|
||||
theRepeater->RepeatAction(aMacEvent);
|
||||
theRepeater = theRepeater->mNextRptr;
|
||||
}
|
||||
}
|
||||
|
||||
// idler methods
|
||||
|
||||
void Repeater::StartIdling()
|
||||
{
|
||||
if (!mIdling)
|
||||
{
|
||||
AddToIdleList();
|
||||
mIdling = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Repeater::StopIdling()
|
||||
{
|
||||
if (mIdling)
|
||||
{
|
||||
RemoveFromIdleList();
|
||||
mIdling = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Repeater::DoIdlers(const EventRecord &aMacEvent)
|
||||
{
|
||||
Repeater* theIdler = sIdlers;
|
||||
while (theIdler)
|
||||
{
|
||||
theIdler->RepeatAction(aMacEvent);
|
||||
theIdler = theIdler->mNextIdlr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
357
mozilla/base/src/mac/nsTimerMac.cpp
Normal file
357
mozilla/base/src/mac/nsTimerMac.cpp
Normal file
@@ -0,0 +1,357 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
//
|
||||
// Mac implementation of the nsITimer interface
|
||||
//
|
||||
|
||||
|
||||
|
||||
#include "nsITimer.h"
|
||||
#include "nsITimerCallback.h"
|
||||
#include "prlog.h"
|
||||
#include "nsRepeater.h"
|
||||
|
||||
#include <list.h>
|
||||
#include <Events.h>
|
||||
|
||||
|
||||
|
||||
#pragma mark class TimerImpl
|
||||
|
||||
//========================================================================================
|
||||
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:
|
||||
|
||||
// constructors
|
||||
|
||||
TimerImpl();
|
||||
|
||||
virtual ~TimerImpl();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
PRUint32 GetFireTime() const { return mFireTime; }
|
||||
|
||||
void Fire();
|
||||
|
||||
// nsITimer overrides
|
||||
|
||||
virtual nsresult Init(nsTimerCallbackFunc aFunc,
|
||||
void *aClosure,
|
||||
PRUint32 aDelay);
|
||||
|
||||
virtual nsresult Init(nsITimerCallback *aCallback,
|
||||
PRUint32 aDelay);
|
||||
|
||||
virtual void Cancel();
|
||||
|
||||
virtual PRUint32 GetDelay();
|
||||
|
||||
virtual void SetDelay(PRUint32 aDelay);
|
||||
|
||||
virtual void* GetClosure();
|
||||
|
||||
#if DEBUG
|
||||
enum {
|
||||
eGoodTimerSignature = 'Barf',
|
||||
eDeletedTimerSignature = 'oops'
|
||||
};
|
||||
|
||||
Boolean IsGoodTimer() const { return (mSignature == eGoodTimerSignature); }
|
||||
#endif
|
||||
|
||||
private:
|
||||
// Calculates mFireTime too
|
||||
void SetDelaySelf( PRUint32 aDelay );
|
||||
|
||||
#if DEBUG
|
||||
UInt32 mSignature;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#pragma mark class TimerPeriodical
|
||||
|
||||
//========================================================================================
|
||||
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;
|
||||
|
||||
public:
|
||||
// Returns the singleton instance
|
||||
static TimerPeriodical * GetPeriodical();
|
||||
|
||||
TimerPeriodical();
|
||||
|
||||
virtual ~TimerPeriodical();
|
||||
|
||||
virtual void RepeatAction( const EventRecord &inMacEvent);
|
||||
|
||||
nsresult AddTimer( TimerImpl * aTimer);
|
||||
|
||||
nsresult RemoveTimer( TimerImpl * aTimer);
|
||||
|
||||
};
|
||||
|
||||
|
||||
//========================================================================================
|
||||
// TimerImpl implementation
|
||||
//========================================================================================
|
||||
|
||||
NS_IMPL_ISUPPORTS(TimerImpl, nsITimer::GetIID())
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TimerImpl::TimerImpl()
|
||||
//----------------------------------------------------------------------------------------
|
||||
: mCallbackFunc(nsnull)
|
||||
, mCallbackObject(nsnull)
|
||||
, mClosure(nsnull)
|
||||
, mDelay(0)
|
||||
, mFireTime(0)
|
||||
, mPrev(nsnull)
|
||||
, mNext(nsnull)
|
||||
#if DEBUG
|
||||
, mSignature(eGoodTimerSignature)
|
||||
#endif
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
TimerImpl::~TimerImpl()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
Cancel();
|
||||
NS_IF_RELEASE(mCallbackObject);
|
||||
#if DEBUG
|
||||
mSignature = eDeletedTimerSignature;
|
||||
#endif
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsresult TimerImpl::Init(nsTimerCallbackFunc aFunc,
|
||||
void *aClosure,
|
||||
PRUint32 aDelay)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
mCallbackFunc = aFunc;
|
||||
mClosure = aClosure;
|
||||
SetDelaySelf(aDelay);
|
||||
return TimerPeriodical::GetPeriodical()->AddTimer(this);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsresult TimerImpl::Init(nsITimerCallback *aCallback,
|
||||
PRUint32 aDelay)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
NS_ADDREF(aCallback);
|
||||
mCallbackObject = aCallback;
|
||||
SetDelaySelf(aDelay);
|
||||
return TimerPeriodical::GetPeriodical()->AddTimer(this);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void TimerImpl::Cancel()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
TimerPeriodical::GetPeriodical()->RemoveTimer(this);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
PRUint32 TimerImpl::GetDelay()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return mDelay;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void TimerImpl::SetDelay(PRUint32 aDelay)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
SetDelaySelf(aDelay);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void* TimerImpl::GetClosure()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return mClosure;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void TimerImpl::Fire()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
NS_PRECONDITION(mRefCnt > 0, "Firing a disposed Timer!");
|
||||
if (mCallbackFunc != NULL) {
|
||||
(*mCallbackFunc)(this, mClosure);
|
||||
}
|
||||
else if (mCallbackObject != NULL) {
|
||||
mCallbackObject->Notify(this); // Fire the timer
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void TimerImpl::SetDelaySelf( PRUint32 aDelay )
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
|
||||
mDelay = aDelay;
|
||||
mFireTime = TickCount() + (mDelay * 3) / 50; // We need mFireTime in ticks (1/60th)
|
||||
// but aDelay is in 1000th (60/1000 = 3/50)
|
||||
}
|
||||
|
||||
TimerPeriodical * TimerPeriodical::gPeriodical = nsnull;
|
||||
|
||||
TimerPeriodical * TimerPeriodical::GetPeriodical()
|
||||
{
|
||||
if (gPeriodical == NULL)
|
||||
gPeriodical = new TimerPeriodical();
|
||||
return gPeriodical;
|
||||
}
|
||||
|
||||
TimerPeriodical::TimerPeriodical()
|
||||
{
|
||||
mTimers = nsnull;
|
||||
}
|
||||
|
||||
TimerPeriodical::~TimerPeriodical()
|
||||
{
|
||||
PR_ASSERT(mTimers == 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;
|
||||
|
||||
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 )
|
||||
StopRepeating();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Called through every event loop
|
||||
// Loops through the list of available timers, and
|
||||
// fires off the appropriate ones
|
||||
void TimerPeriodical::RepeatAction( const EventRecord &inMacEvent)
|
||||
{
|
||||
PRBool done = false;
|
||||
while (!done)
|
||||
{
|
||||
TimerImpl* t = mTimers;
|
||||
while (t)
|
||||
{
|
||||
NS_ASSERTION(t->IsGoodTimer(), "Bad timer!");
|
||||
|
||||
if (t->GetFireTime() <= inMacEvent.when)
|
||||
{
|
||||
RemoveTimer(t);
|
||||
t->Fire();
|
||||
break;
|
||||
}
|
||||
t = t->mNext;
|
||||
}
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_BASE nsresult NS_NewTimer(nsITimer** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
TimerImpl *timer = new TimerImpl();
|
||||
if (nsnull == timer) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return timer->QueryInterface(nsITimer::GetIID(), (void **) aInstancePtrResult);
|
||||
}
|
||||
142
mozilla/base/src/makefile.win
Normal file
142
mozilla/base/src/makefile.win
Normal file
@@ -0,0 +1,142 @@
|
||||
#!nmake
|
||||
#
|
||||
# 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.
|
||||
|
||||
DEPTH=..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
DIRS = windows
|
||||
|
||||
DEFINES=-D_IMPL_NS_BASE -DWIN32_LEAN_AND_MEAN
|
||||
LIBRARY_NAME=raptorbase
|
||||
|
||||
CPPSRCS = \
|
||||
nsArena.cpp \
|
||||
nsAtomTable.cpp \
|
||||
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 = \
|
||||
.\$(OBJDIR)\nsArena.obj \
|
||||
.\$(OBJDIR)\nsAtomTable.obj \
|
||||
.\$(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 \
|
||||
nsIBaseStream.h nsIInputStream.h nsIOutputStream.h \
|
||||
nsInt64.h nsTime.h
|
||||
|
||||
MODULE=raptor
|
||||
|
||||
REQUIRES=xpcom netlib raptor uconv
|
||||
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\netlib \
|
||||
-I$(PUBLIC)\raptor -I$(PUBLIC)\uconv -I$(PUBLIC)\unicharutil
|
||||
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
DLLNAME = raptorbase
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
OBJS = $(OBJS) .\$(OBJDIR)\nsTimer.obj .\$(OBJDIR)\nsCaretProperties.obj
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
$(DEFINES) \
|
||||
$(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)
|
||||
!if "$(MOZ_BITS)"=="32" && defined(MOZ_DEBUG) && defined(GLOWCODE)
|
||||
LLIBS=$(LLIBS) $(GLOWDIR)\glowcode.lib
|
||||
!endif
|
||||
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
libs:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\bin\$(DLLNAME).dll
|
||||
rm -f $(DIST)\lib\$(DLLNAME).lib
|
||||
39
mozilla/base/src/motif/Makefile.in
Normal file
39
mozilla/base/src/motif/Makefile.in
Normal file
@@ -0,0 +1,39 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
LIBRARY_NAME = gmbasemotif
|
||||
|
||||
MODULE=base
|
||||
|
||||
REQUIRES = xpcom raptor
|
||||
|
||||
DEFINES += -D_IMPL_NS_WIDGET
|
||||
|
||||
CPPSRCS = \
|
||||
nsTimer.cpp \
|
||||
nsCaretProperties.cpp \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
39
mozilla/base/src/motif/nsCaretProperties.cpp
Normal file
39
mozilla/base/src/motif/nsCaretProperties.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
/* -*- 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();
|
||||
}
|
||||
173
mozilla/base/src/motif/nsTimer.cpp
Normal file
173
mozilla/base/src/motif/nsTimer.cpp
Normal file
@@ -0,0 +1,173 @@
|
||||
/* -*- 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 "nsITimer.h"
|
||||
#include "nsITimerCallback.h"
|
||||
#include "nsCRT.h"
|
||||
#include "prlog.h"
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <X11/Intrinsic.h>
|
||||
|
||||
static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID);
|
||||
|
||||
// Hack for now. This is Bad because it creates a dependency between the widget
|
||||
// library and this library. This needs to be replaced with having code
|
||||
// to pass an interface which can be queried for the app context.
|
||||
extern XtAppContext gAppContext;
|
||||
|
||||
extern void nsTimerExpired(XtPointer aCallData);
|
||||
|
||||
|
||||
/*
|
||||
* Implementation of timers using Xt timer facility
|
||||
*/
|
||||
class TimerImpl : public nsITimer {
|
||||
public:
|
||||
|
||||
public:
|
||||
TimerImpl();
|
||||
virtual ~TimerImpl();
|
||||
|
||||
virtual nsresult Init(nsTimerCallbackFunc aFunc,
|
||||
void *aClosure,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay);
|
||||
|
||||
virtual nsresult Init(nsITimerCallback *aCallback,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual void Cancel();
|
||||
virtual PRUint32 GetDelay() { return mDelay; }
|
||||
virtual void SetDelay(PRUint32 aDelay) { mDelay=aDelay; };
|
||||
virtual void* GetClosure() { return mClosure; }
|
||||
|
||||
void FireTimeout();
|
||||
|
||||
private:
|
||||
nsresult Init(PRUint32 aDelay);
|
||||
|
||||
PRUint32 mDelay;
|
||||
nsTimerCallbackFunc mFunc;
|
||||
void *mClosure;
|
||||
nsITimerCallback *mCallback;
|
||||
// PRBool mRepeat;
|
||||
TimerImpl *mNext;
|
||||
XtIntervalId mTimerId;
|
||||
};
|
||||
|
||||
void TimerImpl::FireTimeout()
|
||||
{
|
||||
if (mFunc != NULL) {
|
||||
(*mFunc)(this, mClosure);
|
||||
}
|
||||
else if (mCallback != NULL) {
|
||||
mCallback->Notify(this); // Fire the timer
|
||||
}
|
||||
|
||||
// Always repeating here
|
||||
|
||||
// if (mRepeat)
|
||||
// mTimerId = XtAppAddTimeOut(gAppContext, GetDelay(),(XtTimerCallbackProc)nsTimerExpired, this);
|
||||
}
|
||||
|
||||
|
||||
TimerImpl::TimerImpl()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mFunc = NULL;
|
||||
mCallback = NULL;
|
||||
mNext = NULL;
|
||||
mTimerId = 0;
|
||||
mDelay = 0;
|
||||
mClosure = NULL;
|
||||
}
|
||||
|
||||
TimerImpl::~TimerImpl()
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
TimerImpl::Init(nsTimerCallbackFunc aFunc,
|
||||
void *aClosure,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay)
|
||||
{
|
||||
mFunc = aFunc;
|
||||
mClosure = aClosure;
|
||||
// mRepeat = aRepeat;
|
||||
|
||||
mTimerId = XtAppAddTimeOut(gAppContext, aDelay,(XtTimerCallbackProc)nsTimerExpired, this);
|
||||
|
||||
return Init(aDelay);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TimerImpl::Init(nsITimerCallback *aCallback,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay)
|
||||
{
|
||||
mCallback = aCallback;
|
||||
// mRepeat = aRepeat;
|
||||
|
||||
mTimerId = XtAppAddTimeOut(gAppContext, aDelay, (XtTimerCallbackProc)nsTimerExpired, this);
|
||||
|
||||
return Init(aDelay);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TimerImpl::Init(PRUint32 aDelay)
|
||||
{
|
||||
mDelay = aDelay;
|
||||
NS_ADDREF(this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(TimerImpl, kITimerIID)
|
||||
|
||||
|
||||
void
|
||||
TimerImpl::Cancel()
|
||||
{
|
||||
XtRemoveTimeOut(mTimerId);
|
||||
}
|
||||
|
||||
NS_BASE nsresult NS_NewTimer(nsITimer** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
TimerImpl *timer = new TimerImpl();
|
||||
if (nsnull == timer) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return timer->QueryInterface(kITimerIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
|
||||
void nsTimerExpired(XtPointer aCallData)
|
||||
{
|
||||
TimerImpl* timer = (TimerImpl *)aCallData;
|
||||
timer->FireTimeout();
|
||||
}
|
||||
80
mozilla/base/src/nsArena.cpp
Normal file
80
mozilla/base/src/nsArena.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
/* -*- 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 "nsIArena.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
#define PL_ARENA_CONST_ALIGN_MASK 7
|
||||
#include "plarena.h"
|
||||
|
||||
static NS_DEFINE_IID(kArenaIID, NS_IARENA_IID);
|
||||
|
||||
// Simple arena implementation layered on plarena
|
||||
class ArenaImpl : public nsIArena {
|
||||
public:
|
||||
ArenaImpl(PRInt32 aBlockSize);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual void* Alloc(PRInt32 aSize);
|
||||
|
||||
protected:
|
||||
virtual ~ArenaImpl();
|
||||
|
||||
PLArenaPool mPool;
|
||||
PRInt32 mBlockSize;
|
||||
};
|
||||
|
||||
ArenaImpl::ArenaImpl(PRInt32 aBlockSize)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
if (aBlockSize < NS_MIN_ARENA_BLOCK_SIZE) {
|
||||
aBlockSize = NS_DEFAULT_ARENA_BLOCK_SIZE;
|
||||
}
|
||||
PL_INIT_ARENA_POOL(&mPool, "nsIArena", aBlockSize);
|
||||
mBlockSize = aBlockSize;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(ArenaImpl,kArenaIID)
|
||||
|
||||
ArenaImpl::~ArenaImpl()
|
||||
{
|
||||
PL_FinishArenaPool(&mPool);
|
||||
}
|
||||
|
||||
void* ArenaImpl::Alloc(PRInt32 size)
|
||||
{
|
||||
// Adjust size so that it's a multiple of sizeof(double)
|
||||
PRInt32 align = size & (sizeof(double) - 1);
|
||||
if (0 != align) {
|
||||
size += sizeof(double) - align;
|
||||
}
|
||||
|
||||
void* p;
|
||||
PL_ARENA_ALLOCATE(p, &mPool, size);
|
||||
return p;
|
||||
}
|
||||
|
||||
NS_BASE nsresult NS_NewHeapArena(nsIArena** aInstancePtrResult,
|
||||
PRInt32 aArenaBlockSize)
|
||||
{
|
||||
ArenaImpl* it = new ArenaImpl(aArenaBlockSize);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(kArenaIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
158
mozilla/base/src/nsAtomTable.cpp
Normal file
158
mozilla/base/src/nsAtomTable.cpp
Normal file
@@ -0,0 +1,158 @@
|
||||
/* -*- 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 "nsIAtom.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCRT.h"
|
||||
#include "plhash.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
|
||||
/**
|
||||
* The shared hash table for atom lookups.
|
||||
*/
|
||||
static nsrefcnt gAtoms;
|
||||
static struct PLHashTable* gAtomHashTable;
|
||||
|
||||
class AtomImpl : public nsIAtom {
|
||||
public:
|
||||
AtomImpl();
|
||||
virtual ~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;
|
||||
|
||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
// Actually more; 0 terminated. This slot is reserved for the
|
||||
// terminating zero.
|
||||
PRUnichar mString[1];
|
||||
};
|
||||
|
||||
AtomImpl::AtomImpl()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
// Every live atom holds a reference on the atom hashtable
|
||||
gAtoms++;
|
||||
}
|
||||
|
||||
AtomImpl::~AtomImpl()
|
||||
{
|
||||
NS_PRECONDITION(nsnull != gAtomHashTable, "null atom hashtable");
|
||||
if (nsnull != gAtomHashTable) {
|
||||
PL_HashTableRemove(gAtomHashTable, mString);
|
||||
nsrefcnt cnt = --gAtoms;
|
||||
if (0 == cnt) {
|
||||
// When the last atom is destroyed, the atom arena is destroyed
|
||||
NS_ASSERTION(0 == gAtomHashTable->nentries, "bad atom table");
|
||||
PL_HashTableDestroy(gAtomHashTable);
|
||||
gAtomHashTable = nsnull;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kIAtomIID, NS_IATOM_IID);
|
||||
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);
|
||||
nsCRT::memcpy(ii->mString, us, uslen * sizeof(PRUnichar));
|
||||
ii->mString[uslen] = 0;
|
||||
return ii;
|
||||
}
|
||||
|
||||
void AtomImpl::ToString(nsString& aBuf) const
|
||||
{
|
||||
aBuf.SetLength(0);
|
||||
aBuf.Append(mString, nsCRT::strlen(mString));
|
||||
}
|
||||
|
||||
const PRUnichar* AtomImpl::GetUnicode() const
|
||||
{
|
||||
return mString;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AtomImpl::SizeOf(nsISizeOfHandler* aHandler) const
|
||||
{
|
||||
aHandler->Add(sizeof(*this) + nsCRT::strlen(mString) * sizeof(PRUnichar));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static PLHashNumber HashKey(const PRUnichar* k)
|
||||
{
|
||||
return (PLHashNumber) nsCRT::HashValue(k);
|
||||
}
|
||||
|
||||
static PRIntn CompareKeys(const PRUnichar* k1, const PRUnichar* k2)
|
||||
{
|
||||
return nsCRT::strcmp(k1, k2) == 0;
|
||||
}
|
||||
|
||||
NS_BASE nsIAtom* NS_NewAtom(const char* isolatin1)
|
||||
{
|
||||
nsAutoString tmp(isolatin1);
|
||||
return NS_NewAtom(tmp.GetUnicode());
|
||||
}
|
||||
|
||||
NS_BASE nsIAtom* NS_NewAtom(const nsString& aString)
|
||||
{
|
||||
return NS_NewAtom(aString.GetUnicode());
|
||||
}
|
||||
|
||||
NS_BASE nsIAtom* NS_NewAtom(const PRUnichar* us)
|
||||
{
|
||||
if (nsnull == gAtomHashTable) {
|
||||
gAtomHashTable = PL_NewHashTable(8, (PLHashFunction) HashKey,
|
||||
(PLHashComparator) CompareKeys,
|
||||
(PLHashComparator) nsnull,
|
||||
nsnull, nsnull);
|
||||
}
|
||||
PRUint32 uslen;
|
||||
PRUint32 hashCode = nsCRT::HashValue(us, &uslen);
|
||||
PLHashEntry** hep = PL_HashTableRawLookup(gAtomHashTable, hashCode, us);
|
||||
PLHashEntry* he = *hep;
|
||||
if (nsnull != he) {
|
||||
nsIAtom* id = (nsIAtom*) he->value;
|
||||
NS_ADDREF(id);
|
||||
return id;
|
||||
}
|
||||
AtomImpl* id = new(us, uslen) AtomImpl();
|
||||
PL_HashTableRawAdd(gAtomHashTable, hep, hashCode, id->mString, id);
|
||||
NS_ADDREF(id);
|
||||
return id;
|
||||
}
|
||||
|
||||
NS_BASE nsrefcnt NS_GetNumberOfAtoms(void)
|
||||
{
|
||||
if (nsnull != gAtomHashTable) {
|
||||
NS_PRECONDITION(nsrefcnt(gAtomHashTable->nentries) == gAtoms, "bad atom table");
|
||||
}
|
||||
return gAtoms;
|
||||
}
|
||||
402
mozilla/base/src/nsBTree.cpp
Normal file
402
mozilla/base/src/nsBTree.cpp
Normal file
@@ -0,0 +1,402 @@
|
||||
|
||||
/**
|
||||
* This file defines the binary tree class and it
|
||||
* nsNode child class.
|
||||
*
|
||||
* This simple version stores nodes, and the
|
||||
* nodes store void* ptrs.
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
|
||||
#include "nsBTree.h"
|
||||
|
||||
/**
|
||||
* default constructor
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
*/
|
||||
nsNode::nsNode(){
|
||||
mLeft=0;
|
||||
mRight=0;
|
||||
mParent=0;
|
||||
mColor=eBlack;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsNode::nsNode(const nsNode& aNode){
|
||||
mLeft=aNode.mLeft;
|
||||
mRight=aNode.mRight;
|
||||
mParent=aNode.mParent;
|
||||
mColor=aNode.mColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* destructor
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
*/
|
||||
nsNode::~nsNode(){
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrive ptr to parent node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @return ptr to parent node
|
||||
*/
|
||||
nsNode* nsNode::GetParentNode(void) const{
|
||||
return mParent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve ptr to left (less) node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @return ptr to left (may be NULL)
|
||||
*/
|
||||
nsNode* nsNode::GetLeftNode(void) const{
|
||||
return mLeft;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve ptr to right (more) node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @return ptr to right node (may be NULL)
|
||||
*/
|
||||
nsNode* nsNode::GetRightNode(void) const{
|
||||
return mRight;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsNode& nsNode::operator=(const nsNode& aNode){
|
||||
if(this!=&aNode){
|
||||
mLeft=aNode.mLeft;
|
||||
mRight=aNode.mRight;
|
||||
mParent=aNode.mParent;
|
||||
mColor=aNode.mColor;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/********************************************************
|
||||
* Here comes the BTREE class...
|
||||
********************************************************/
|
||||
|
||||
/**
|
||||
* nsBTree constructor
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
*/
|
||||
nsBTree::nsBTree(){
|
||||
mRoot=0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* destructor
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
*/
|
||||
nsBTree::~nsBTree(){
|
||||
if(mRoot){
|
||||
//walk the tree and destroy the children.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a node, we're supposed to add it into
|
||||
* our tree.
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode to be added to tree
|
||||
* @return ptr to added node or NULL
|
||||
*/
|
||||
nsNode* nsBTree::Add(nsNode& aNode){
|
||||
|
||||
nsNode* node1=mRoot; //x
|
||||
nsNode* node2=0; //y
|
||||
while(node1) {
|
||||
node2=node1;
|
||||
if(aNode<*node1)
|
||||
node1=node1->mLeft;
|
||||
else node1=node1->mRight;
|
||||
}
|
||||
aNode.mParent=node2;
|
||||
if(!node2){
|
||||
mRoot=&aNode;
|
||||
}
|
||||
else{
|
||||
if(aNode<*node2)
|
||||
node2->mLeft=&aNode;
|
||||
else node2->mRight=&aNode;
|
||||
}
|
||||
|
||||
return &aNode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes given node from tree if present.
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode to be found and removed
|
||||
* @return ptr to remove node, or NULL
|
||||
*/
|
||||
nsNode* nsBTree::Remove(nsNode& aNode){
|
||||
nsNode* result=0;
|
||||
nsNode* node3=Find(aNode);
|
||||
|
||||
if(node3) {
|
||||
nsNode* node1;
|
||||
nsNode* node2;
|
||||
|
||||
if((!node3->mLeft) || (!node3->mRight))
|
||||
node2=node3;
|
||||
else node2=After(*node3);
|
||||
|
||||
if(node2->mLeft)
|
||||
node1=node2->mLeft;
|
||||
else node1=node2->mRight;
|
||||
|
||||
if(node1)
|
||||
node1->mParent=node2->mParent;
|
||||
|
||||
if(node2->mParent) {
|
||||
if(node2==node2->mParent->mLeft)
|
||||
node2->mParent->mLeft=node1;
|
||||
else node2->mParent->mRight=node1;
|
||||
}
|
||||
else mRoot=node1;
|
||||
|
||||
if(node2!=node3)
|
||||
(*node3)==(*node2);
|
||||
|
||||
if(node2->mColor == nsNode::eBlack)
|
||||
ReBalance(*node1);
|
||||
|
||||
delete node2;
|
||||
result=&aNode;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the tree of any data.
|
||||
* Be careful here if your objects are heap based!
|
||||
* This method doesn't free the objects, so if you
|
||||
* don't have your own pointers, they will become
|
||||
* orphaned.
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return this
|
||||
*/
|
||||
nsBTree& nsBTree::Empty(nsNode* aNode) {
|
||||
mRoot=0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method destroys all the objects in the tree.
|
||||
* WARNING: Never call this method on stored objects
|
||||
* that are stack-based!
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return this
|
||||
*/
|
||||
nsBTree& nsBTree::Erase(nsNode* aNode){
|
||||
// nsNode* node1 =(aNode) ? aNode : mRoot;
|
||||
|
||||
if(aNode) {
|
||||
Erase(aNode->mLeft); //begin by walking left side
|
||||
Erase(aNode->mRight); //then search right side
|
||||
delete aNode; //until a leaf, then delete
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve ptr to first node in tree
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @return
|
||||
*/
|
||||
nsNode* nsBTree::First(void) const{
|
||||
if(mRoot)
|
||||
return First(*mRoot);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrive ptr to first node rel to given node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param node to begin scan from
|
||||
* @return ptr to first node from given node or NULL
|
||||
*/
|
||||
nsNode* nsBTree::First(const nsNode& aNode) const{
|
||||
nsNode* result=0;
|
||||
|
||||
if(mRoot) {
|
||||
result=mRoot;
|
||||
while(result->GetLeftNode()) {
|
||||
result=result->GetLeftNode();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrive ptr to last node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @return ptr to last node rel to root or NULL
|
||||
*/
|
||||
nsNode* nsBTree::Last(void) const{
|
||||
if(mRoot)
|
||||
return Last(*mRoot);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrive ptr to last node rel to given node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param node to begin scan from
|
||||
* @return ptr to first node from given node or NULL
|
||||
*/
|
||||
nsNode* nsBTree::Last(const nsNode& aNode) const{
|
||||
nsNode* result=0;
|
||||
|
||||
if(mRoot) {
|
||||
result=mRoot;
|
||||
while(result->GetRightNode()) {
|
||||
result=result->GetRightNode();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrive ptr to prior node rel to given node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param node to begin scan from
|
||||
* @return ptr to prior node from given node or NULL
|
||||
*/
|
||||
nsNode* nsBTree::Before(const nsNode& aNode) const{
|
||||
|
||||
if(aNode.GetLeftNode())
|
||||
return Last(*aNode.GetLeftNode());
|
||||
|
||||
//otherwise...
|
||||
|
||||
nsNode* node1=(nsNode*)&aNode;
|
||||
nsNode* node2=aNode.GetParentNode();
|
||||
|
||||
while((node2) && (node1==node2->GetLeftNode())) {
|
||||
node1=node2;
|
||||
node2=node2->GetParentNode();
|
||||
}
|
||||
return node2;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrive ptr to next node rel to given node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param node to begin scan from
|
||||
* @return ptr to next node from given node or NULL
|
||||
*/
|
||||
nsNode* nsBTree::After(const nsNode& aNode) const{
|
||||
|
||||
if(aNode.GetRightNode())
|
||||
return First(*aNode.GetRightNode());
|
||||
|
||||
//otherwise...
|
||||
|
||||
nsNode* node1=(nsNode*)&aNode;
|
||||
nsNode* node2=aNode.GetParentNode();
|
||||
|
||||
while((node2) && (node1==node2->GetRightNode())) {
|
||||
node1=node2;
|
||||
node2=node2->GetParentNode();
|
||||
}
|
||||
|
||||
return node2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan for given node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param node to find
|
||||
* @return ptr to given node, or NULL
|
||||
*/
|
||||
nsNode* nsBTree::Find(const nsNode& aNode) const{
|
||||
nsNode* result=mRoot;
|
||||
|
||||
while((result) && (!(aNode==(*result)))) {
|
||||
if(aNode<*result)
|
||||
result=result->mLeft;
|
||||
else result=result->mRight;
|
||||
}
|
||||
return (nsNode*)result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebalances tree around the given node. This only
|
||||
* needs to be called after a node is deleted.
|
||||
* This method does nothing for btrees, but is
|
||||
* needed for RBTrees.
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode -- node to balance around
|
||||
* @return this
|
||||
*/
|
||||
nsBTree& nsBTree::ReBalance(nsNode& aNode){
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
const nsBTree& nsBTree::ForEach(nsNodeFunctor& aFunctor,nsNode* aNode) const{
|
||||
nsNode* node1 =(aNode) ? aNode : mRoot;
|
||||
|
||||
if(node1) {
|
||||
if(node1->mLeft)
|
||||
ForEach(aFunctor,node1->mLeft); //begin by walking left side
|
||||
aFunctor(*node1);
|
||||
if(node1->mRight)
|
||||
ForEach(aFunctor,node1->mRight); //then search right side
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
283
mozilla/base/src/nsBTree.h
Normal file
283
mozilla/base/src/nsBTree.h
Normal file
@@ -0,0 +1,283 @@
|
||||
/* -*- 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 file defines the binary tree class and it
|
||||
* nsNode child class. Note that like all nsBTree
|
||||
* containers, this one does not automatically balance.
|
||||
* (Find for random data, bad for pre-ordered data).
|
||||
*
|
||||
* This simple version stores nodes, and the
|
||||
* nodes store void* ptrs.
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* nsNode
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
|
||||
#ifndef _BTREE_H
|
||||
#define _BTREE_H
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
struct NS_BASE nsNode {
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess4/20/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsNode();
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
* @update gess 4/11/98
|
||||
*/
|
||||
nsNode(const nsNode& aNode);
|
||||
|
||||
/**
|
||||
* destructor
|
||||
* @update gess 4/11/98
|
||||
*/
|
||||
virtual ~nsNode();
|
||||
|
||||
/**
|
||||
* Retrieve parent node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @return
|
||||
*/
|
||||
nsNode* GetParentNode(void) const;
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsNode* GetLeftNode() const;
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsNode* GetRightNode() const;
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual nsNode& operator=(const nsNode& aNode);
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called to determine which of
|
||||
* two nodes is less. When you create your own
|
||||
* subclass of nsNode, this is the most important
|
||||
* method for you to overload.
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual PRBool operator<(const nsNode& aNode) const=0;
|
||||
|
||||
/**
|
||||
* This method gets called to determine which of
|
||||
* two nodes is less. When you create your own
|
||||
* subclass of nsNode, this is the most important
|
||||
* method for you to overload.
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual PRBool operator==(const nsNode& aNode) const=0;
|
||||
|
||||
enum eRBColor {eRed,eBlack};
|
||||
|
||||
nsNode* mParent;
|
||||
nsNode* mLeft;
|
||||
nsNode* mRight;
|
||||
eRBColor mColor;
|
||||
};
|
||||
|
||||
/**
|
||||
* The Nodefunctor class is used when you want to create
|
||||
* callbacks between the nsRBTree and your generic code.
|
||||
*
|
||||
* @update gess4/20/98
|
||||
*/
|
||||
class NS_BASE nsNodeFunctor {
|
||||
public:
|
||||
virtual nsNodeFunctor& operator()(nsNode& aNode)=0;
|
||||
};
|
||||
|
||||
|
||||
/****************************************************
|
||||
* Here comes the nsBTree class...
|
||||
****************************************************/
|
||||
|
||||
class NS_BASE nsBTree {
|
||||
public:
|
||||
friend class nsBTreeIterator;
|
||||
|
||||
nsBTree();
|
||||
virtual ~nsBTree();
|
||||
|
||||
/**
|
||||
* Add given node reference into our tree.
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode is a ref to a node to be added
|
||||
* @return newly added node
|
||||
*/
|
||||
nsNode* Add(nsNode& aNode);
|
||||
|
||||
/**
|
||||
* Remove given node reference into our tree.
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode is a ref to a node to be removed
|
||||
* @return Ptr to node if found (and removed) or NULL
|
||||
*/
|
||||
nsNode* Remove(nsNode& aNode);
|
||||
|
||||
/**
|
||||
* Clears the tree of any data.
|
||||
* Be careful here if your objects are heap based!
|
||||
* This method doesn't free the objects, so if you
|
||||
* don't have your own pointers, they will become
|
||||
* orphaned.
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return this
|
||||
*/
|
||||
nsBTree& Empty(nsNode* aNode=0);
|
||||
|
||||
/**
|
||||
* This method destroys all the objects in the tree.
|
||||
* WARNING: Never call this method on stored objects
|
||||
* that are stack-based!
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return this
|
||||
*/
|
||||
nsBTree& Erase(nsNode* aNode=0);
|
||||
|
||||
/**
|
||||
* Retrieve ptr to 1st node in tree (starting at root)
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @return ptr to 1st node, possible to be NULL
|
||||
*/
|
||||
nsNode* First(void) const;
|
||||
|
||||
/**
|
||||
* Find first node in tree starting at given node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode node to begin 1st search from
|
||||
* @return ptr to 1st node below given node
|
||||
*/
|
||||
nsNode* First(const nsNode& aNode) const;
|
||||
|
||||
/**
|
||||
* Retrieve ptr to last node in tree relative to root.
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @return ptr to last node or NULL
|
||||
*/
|
||||
nsNode* Last(void) const;
|
||||
|
||||
/**
|
||||
* Retrieve ptr to last node in tree relative to given node.
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param node to find last node from
|
||||
* @return ptr to last node or NULL
|
||||
*/
|
||||
nsNode* Last(const nsNode& aNode) const;
|
||||
|
||||
/**
|
||||
* Retrieve a ptr to the node that preceeds given node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode used as reference to find prev.
|
||||
* @return ptr to prev node or NULL
|
||||
*/
|
||||
nsNode* Before(const nsNode& aNode) const;
|
||||
|
||||
/**
|
||||
* Retrieve a ptr to the node after given node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode used as reference to find next.
|
||||
* @return ptr to next node or NULL
|
||||
*/
|
||||
nsNode* After(const nsNode& aNode) const;
|
||||
|
||||
/**
|
||||
* Find given node in tree.
|
||||
* (Why would you want to find a node you already have?)
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode is the node you're searching for
|
||||
* @return ptr to node if found, or NULL
|
||||
*/
|
||||
nsNode* Find(const nsNode& aNode) const;
|
||||
|
||||
/**
|
||||
* Walks the tree, starting with root.
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
*/
|
||||
virtual const nsBTree& ForEach(nsNodeFunctor& aFunctor,nsNode* aNode=0) const;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Rebalances tree around the given node. This only
|
||||
* needs to be called after a node is deleted.
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode -- node to balance around
|
||||
* @return this
|
||||
*/
|
||||
virtual nsBTree& ReBalance(nsNode& aNode);
|
||||
|
||||
|
||||
nsNode* mRoot;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
268
mozilla/base/src/nsBaseDLL.cpp
Normal file
268
mozilla/base/src/nsBaseDLL.cpp
Normal file
@@ -0,0 +1,268 @@
|
||||
/* -*- 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 "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 "nsBaseDLL.h"
|
||||
#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"
|
||||
|
||||
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);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSRegisterSelf(nsISupports* aServMgr, const char* path)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
NS_WITH_SERVICE1(nsIComponentManager, compMgr,
|
||||
aServMgr, kComponentManagerCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSUnregisterSelf(nsISupports* aServMgr, const char* path)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
NS_WITH_SERVICE1(nsIComponentManager, compMgr,
|
||||
aServMgr, kComponentManagerCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSGetFactory(nsISupports* aServMgr,
|
||||
const nsCID& aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory** aFactory)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT PRBool
|
||||
NSCanUnload(nsISupports* serviceMgr)
|
||||
{
|
||||
return PR_FALSE; // XXX can we unload this?
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
26
mozilla/base/src/nsBaseDLL.h
Normal file
26
mozilla/base/src/nsBaseDLL.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/* -*- 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 nsBaseDLL_h___
|
||||
#define nsBaseDLL_h___
|
||||
|
||||
#include "prtypes.h"
|
||||
|
||||
extern PRInt32 gLockCount;
|
||||
|
||||
#endif /* nsBaseDLL_h___ */
|
||||
367
mozilla/base/src/nsBuffer.cpp
Normal file
367
mozilla/base/src/nsBuffer.cpp
Normal file
@@ -0,0 +1,367 @@
|
||||
/* -*- 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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
68
mozilla/base/src/nsBuffer.h
Normal file
68
mozilla/base/src/nsBuffer.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/* -*- 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___
|
||||
142
mozilla/base/src/nsByteBuffer.cpp
Normal file
142
mozilla/base/src/nsByteBuffer.cpp
Normal file
@@ -0,0 +1,142 @@
|
||||
/* -*- 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 "nsIByteBuffer.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
#define MIN_BUFFER_SIZE 32
|
||||
|
||||
class ByteBufferImpl : public nsIByteBuffer {
|
||||
public:
|
||||
ByteBufferImpl(PRUint32 aBufferSize);
|
||||
virtual ~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);
|
||||
|
||||
char* mBuffer;
|
||||
PRUint32 mSpace;
|
||||
PRUint32 mLength;
|
||||
};
|
||||
|
||||
ByteBufferImpl::ByteBufferImpl(PRUint32 aBufferSize)
|
||||
{
|
||||
if (aBufferSize < MIN_BUFFER_SIZE) {
|
||||
aBufferSize = MIN_BUFFER_SIZE;
|
||||
}
|
||||
mSpace = aBufferSize;
|
||||
mBuffer = new char[aBufferSize];
|
||||
mLength = 0;
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
NS_DEFINE_IID(kByteBufferIID,NS_IBYTE_BUFFER_IID);
|
||||
NS_IMPL_ISUPPORTS(ByteBufferImpl,kByteBufferIID)
|
||||
|
||||
ByteBufferImpl::~ByteBufferImpl()
|
||||
{
|
||||
if (nsnull != mBuffer) {
|
||||
delete[] mBuffer;
|
||||
mBuffer = nsnull;
|
||||
}
|
||||
mLength = 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRUint32)
|
||||
ByteBufferImpl::GetLength(void) const
|
||||
{
|
||||
return mLength;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRUint32)
|
||||
ByteBufferImpl::GetBufferSize(void) const
|
||||
{
|
||||
return mSpace;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(char*)
|
||||
ByteBufferImpl::GetBuffer(void) const
|
||||
{
|
||||
return mBuffer;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
ByteBufferImpl::Grow(PRUint32 aNewSize)
|
||||
{
|
||||
if (aNewSize < MIN_BUFFER_SIZE) {
|
||||
aNewSize = MIN_BUFFER_SIZE;
|
||||
}
|
||||
char* newbuf = new char[aNewSize];
|
||||
if (nsnull != newbuf) {
|
||||
if (0 != mLength) {
|
||||
nsCRT::memcpy(newbuf, mBuffer, mLength);
|
||||
}
|
||||
delete[] mBuffer;
|
||||
mBuffer = newbuf;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRInt32)
|
||||
ByteBufferImpl::Fill(nsresult* aErrorCode, nsIInputStream* aStream,
|
||||
PRUint32 aKeep)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aStream, "null stream");
|
||||
NS_PRECONDITION(aKeep <= mLength, "illegal keep count");
|
||||
if ((nsnull == aStream) || (PRUint32(aKeep) > PRUint32(mLength))) {
|
||||
// whoops
|
||||
*aErrorCode = NS_BASE_STREAM_ILLEGAL_ARGS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 != aKeep) {
|
||||
// Slide over kept data
|
||||
nsCRT::memmove(mBuffer, mBuffer + (mLength - aKeep), aKeep);
|
||||
}
|
||||
|
||||
// Read in some new data
|
||||
mLength = aKeep;
|
||||
PRUint32 nb;
|
||||
*aErrorCode = aStream->Read(mBuffer + aKeep, mSpace - aKeep, &nb);
|
||||
if (NS_SUCCEEDED(*aErrorCode)) {
|
||||
mLength += nb;
|
||||
}
|
||||
else
|
||||
nb = 0;
|
||||
return nb;
|
||||
}
|
||||
|
||||
NS_BASE nsresult NS_NewByteBuffer(nsIByteBuffer** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
PRUint32 aBufferSize)
|
||||
{
|
||||
if (nsnull != aOuter) {
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
ByteBufferImpl* it = new ByteBufferImpl(aBufferSize);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(kByteBufferIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
575
mozilla/base/src/nsByteBufferInputStream.cpp
Normal file
575
mozilla/base/src/nsByteBufferInputStream.cpp
Normal file
@@ -0,0 +1,575 @@
|
||||
/* -*- 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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
524
mozilla/base/src/nsCRT.cpp
Normal file
524
mozilla/base/src/nsCRT.cpp
Normal file
@@ -0,0 +1,524 @@
|
||||
/* -*- 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:
|
||||
* @update gess7/30/98
|
||||
*
|
||||
* Much as I hate to do it, we were using string compares wrong.
|
||||
* Often, programmers call functions like strcmp(s1,s2), and pass
|
||||
* one or more null strings. Rather than blow up on these, I've
|
||||
* added quick checks to ensure that cases like this don't cause
|
||||
* us to fail.
|
||||
*
|
||||
* In general, if you pass a null into any of these string compare
|
||||
* routines, we simply return 0.
|
||||
*/
|
||||
|
||||
|
||||
#include "nsCRT.h"
|
||||
#include "nsUnicharUtilCIID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICaseConversion.h"
|
||||
|
||||
|
||||
// XXX Bug: These tables don't lowercase the upper 128 characters properly
|
||||
|
||||
// This table maps uppercase characters to lower case characters;
|
||||
// characters that are neither upper nor lower case are unaffected.
|
||||
static const unsigned char kUpper2Lower[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,
|
||||
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
|
||||
64,
|
||||
|
||||
// upper band mapped to lower [A-Z] => [a-z]
|
||||
97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
|
||||
112,113,114,115,116,117,118,119,120,121,122,
|
||||
|
||||
91, 92, 93, 94, 95,
|
||||
96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
|
||||
112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
|
||||
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
|
||||
144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
|
||||
160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
|
||||
176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
|
||||
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
|
||||
208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
|
||||
224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
|
||||
240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
|
||||
};
|
||||
|
||||
static const unsigned char kLower2Upper[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,
|
||||
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
|
||||
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
|
||||
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
|
||||
96,
|
||||
|
||||
// lower band mapped to upper [a-z] => [A-Z]
|
||||
65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
|
||||
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
|
||||
|
||||
123,124,125,126,127,
|
||||
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
|
||||
144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
|
||||
160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
|
||||
176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
|
||||
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
|
||||
208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
|
||||
224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
|
||||
240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
|
||||
};
|
||||
|
||||
// XXX bug: this doesn't map 0x80 to 0x9f properly
|
||||
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,
|
||||
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
|
||||
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
|
||||
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
|
||||
96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
|
||||
112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
|
||||
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
|
||||
144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
|
||||
160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
|
||||
176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
|
||||
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
|
||||
208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
|
||||
224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
|
||||
240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
#define TOLOWER(_ucs2) \
|
||||
(((_ucs2) < 128) ? 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");
|
||||
|
||||
}
|
||||
|
||||
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 ;
|
||||
}
|
||||
|
||||
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 ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
PRUnichar nsCRT::ToUpper(PRUnichar aChar)
|
||||
{
|
||||
return TOUPPER(aChar);
|
||||
}
|
||||
|
||||
PRUnichar nsCRT::ToLower(PRUnichar aChar)
|
||||
{
|
||||
return TOLOWER(aChar);
|
||||
}
|
||||
|
||||
PRBool nsCRT::IsUpper(PRUnichar aChar)
|
||||
{
|
||||
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;
|
||||
if(s) {
|
||||
while (*s++ != 0) {
|
||||
len++;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compare unichar string ptrs, stopping at the 1st null
|
||||
* NOTE: If both are null, we return 0.
|
||||
* @update gess7/30/98
|
||||
* @param s1 and s2 both point to unichar strings
|
||||
* @return 0 if they match, -1 if s1<s2; 1 if s1>s2
|
||||
*/
|
||||
PRInt32 nsCRT::strcmp(const PRUnichar* s1, const PRUnichar* s2)
|
||||
{
|
||||
if(s1 && s2) {
|
||||
for (;;) {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = *s2++;
|
||||
if (c1 != c2) {
|
||||
if (c1 < c2) return -1;
|
||||
return 1;
|
||||
}
|
||||
if ((0==c1) || (0==c2)) break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare unichar string ptrs, stopping at the 1st null or nth char.
|
||||
* NOTE: If either is null, we return 0.
|
||||
* @update gess7/30/98
|
||||
* @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)
|
||||
{
|
||||
if(s1 && s2) {
|
||||
if(n != 0) {
|
||||
do {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = *s2++;
|
||||
if (c1 != c2) {
|
||||
if (c1 < c2) return -1;
|
||||
return 1;
|
||||
}
|
||||
if ((0==c1) || (0==c2)) break;
|
||||
} while (--n != 0);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compare unichar string ptrs without regard to case
|
||||
* NOTE: If both are null, we return 0.
|
||||
* @update gess7/30/98
|
||||
* @param s1 and s2 both point to unichar strings
|
||||
* @return 0 if they match, -1 if s1<s2; 1 if s1>s2
|
||||
*/
|
||||
PRInt32 nsCRT::strcasecmp(const PRUnichar* s1, const PRUnichar* s2)
|
||||
{
|
||||
if(s1 && s2) {
|
||||
for (;;) {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = *s2++;
|
||||
if (c1 != c2) {
|
||||
c1 = TOLOWER(c1);
|
||||
c2 = TOLOWER(c2);
|
||||
if (c1 != c2) {
|
||||
if (c1 < c2) return -1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if ((0==c1) || (0==c2)) break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare unichar string ptrs, stopping at the 1st null or nth char;
|
||||
* also ignoring the case of characters.
|
||||
* NOTE: If both are null, we return 0.
|
||||
* @update gess7/30/98
|
||||
* @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)
|
||||
{
|
||||
if(s1 && s2) {
|
||||
if(n != 0){
|
||||
do {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = *s2++;
|
||||
if (c1 != c2) {
|
||||
c1 = TOLOWER(c1);
|
||||
c2 = TOLOWER(c2);
|
||||
if (c1 != c2) {
|
||||
if (c1 < c2) return -1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if ((0==c1) || (0==c2)) break;
|
||||
} while (--n != 0);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compare a unichar string ptr to cstring.
|
||||
* NOTE: If both are null, we return 0.
|
||||
* @update gess7/30/98
|
||||
* @param s1 points to unichar string
|
||||
* @param s2 points to cstring
|
||||
* @return 0 if they match, -1 if s1<s2; 1 if s1>s2
|
||||
*/
|
||||
PRInt32 nsCRT::strcmp(const PRUnichar* s1, const char* s2)
|
||||
{
|
||||
if(s1 && s2) {
|
||||
for (;;) {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
|
||||
if (c1 != c2) {
|
||||
if (c1 < c2) return -1;
|
||||
return 1;
|
||||
}
|
||||
if ((0==c1) || (0==c2)) break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compare a unichar string ptr to cstring, up to N chars.
|
||||
* NOTE: If both are null, we return 0.
|
||||
* @update gess7/30/98
|
||||
* @param s1 points to unichar string
|
||||
* @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)
|
||||
{
|
||||
if(s1 && s2) {
|
||||
if(n != 0){
|
||||
do {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
|
||||
if (c1 != c2) {
|
||||
if (c1 < c2) return -1;
|
||||
return 1;
|
||||
}
|
||||
if ((0==c1) || (0==c2)) break;
|
||||
} while (--n != 0);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare a unichar string ptr to cstring without regard to case
|
||||
* NOTE: If both are null, we return 0.
|
||||
* @update gess7/30/98
|
||||
* @param s1 points to unichar string
|
||||
* @param s2 points to cstring
|
||||
* @return 0 if they match, -1 if s1<s2; 1 if s1>s2
|
||||
*/
|
||||
PRInt32 nsCRT::strcasecmp(const PRUnichar* s1, const char* s2)
|
||||
{
|
||||
if(s1 && s2) {
|
||||
for (;;) {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
|
||||
if (c1 != c2) {
|
||||
c1 = TOLOWER(c1);
|
||||
c2 = TOLOWER(c2);
|
||||
if (c1 != c2) {
|
||||
if (c1 < c2) return -1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if ((0==c1) || (0==c2)) break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Caseless compare up to N chars between unichar string ptr to cstring.
|
||||
* NOTE: If both are null, we return 0.
|
||||
* @update gess7/30/98
|
||||
* @param s1 points to unichar string
|
||||
* @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)
|
||||
{
|
||||
if(s1 && s2){
|
||||
if(n != 0){
|
||||
do {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
|
||||
if (c1 != c2) {
|
||||
c1 = TOLOWER(c1);
|
||||
c2 = TOLOWER(c2);
|
||||
if (c1 != c2) {
|
||||
if (c1 < c2) return -1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (c1 == 0) break;
|
||||
} while (--n != 0);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRUnichar* nsCRT::strdup(const PRUnichar* str)
|
||||
{
|
||||
PRUint32 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));
|
||||
return rslt;
|
||||
}
|
||||
|
||||
PRUint32 nsCRT::HashValue(const PRUnichar* us)
|
||||
{
|
||||
PRUint32 rv = 0;
|
||||
if(us) {
|
||||
PRUnichar ch;
|
||||
while ((ch = *us++) != 0) {
|
||||
// FYI: rv = rv*37 + ch
|
||||
rv = ((rv << 5) + (rv << 2) + rv) + ch;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
PRUint32 nsCRT::HashValue(const PRUnichar* us, PRUint32* uslenp)
|
||||
{
|
||||
PRUint32 rv = 0;
|
||||
PRUint32 len = 0;
|
||||
PRUnichar ch;
|
||||
while ((ch = *us++) != 0) {
|
||||
// FYI: rv = rv*37 + ch
|
||||
rv = ((rv << 5) + (rv << 2) + rv) + ch;
|
||||
len++;
|
||||
}
|
||||
*uslenp = len;
|
||||
return rv;
|
||||
}
|
||||
|
||||
PRInt32 nsCRT::atoi( const PRUnichar *string )
|
||||
{
|
||||
return atoi(string);
|
||||
}
|
||||
|
||||
210
mozilla/base/src/nsCRT.h
Normal file
210
mozilla/base/src/nsCRT.h
Normal file
@@ -0,0 +1,210 @@
|
||||
/* -*- 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 nsCRT_h___
|
||||
#define nsCRT_h___
|
||||
|
||||
#include <stdlib.h>
|
||||
#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) {
|
||||
::memcpy(aDest, aSrc, (size_t)aCount);
|
||||
}
|
||||
|
||||
static void memmove(void* aDest, const void* aSrc, PRUint32 aCount) {
|
||||
::memmove(aDest, aSrc, (size_t)aCount);
|
||||
}
|
||||
|
||||
static void memset(void* aDest, PRUint8 aByte, PRUint32 aCount) {
|
||||
::memset(aDest, aByte, aCount);
|
||||
}
|
||||
|
||||
static void zero(void* aDest, PRUint32 aCount) {
|
||||
::memset(aDest, 0, (size_t)aCount);
|
||||
}
|
||||
|
||||
/** Compute the string length of s
|
||||
@param s the string in question
|
||||
@return the length of s
|
||||
*/
|
||||
static PRUint32 strlen(const char* s) {
|
||||
return PRUint32(::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));
|
||||
}
|
||||
|
||||
/// Case-insensitive string comparison.
|
||||
static PRInt32 strcasecmp(const char* s1, const char* s2) {
|
||||
return PRInt32(PL_strcasecmp(s1, s2));
|
||||
}
|
||||
|
||||
/// Case-insensitive string comparison with length
|
||||
static PRInt32 strncasecmp(const char* s1, const char* s2, PRUint32 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);
|
||||
|
||||
/// 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);
|
||||
|
||||
/// 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);
|
||||
|
||||
/// 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);
|
||||
|
||||
/// 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);
|
||||
|
||||
// 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);
|
||||
|
||||
/// String to integer.
|
||||
static PRInt32 atoi( const PRUnichar *string );
|
||||
|
||||
static PRUnichar ToUpper(PRUnichar aChar);
|
||||
|
||||
static PRUnichar ToLower(PRUnichar aChar);
|
||||
|
||||
static PRBool IsUpper(PRUnichar aChar);
|
||||
|
||||
static PRBool IsLower(PRUnichar aChar);
|
||||
};
|
||||
|
||||
#endif /* nsCRT_h___ */
|
||||
569
mozilla/base/src/nsDeque.cpp
Normal file
569
mozilla/base/src/nsDeque.cpp
Normal file
@@ -0,0 +1,569 @@
|
||||
/* -*- 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 "nsDeque.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
//#define _SELFTEST_DEQUE 1
|
||||
#undef _SELFTEST_DEQUE
|
||||
|
||||
/**
|
||||
* Standard constructor
|
||||
* @update gess4/18/98
|
||||
* @return new deque
|
||||
*/
|
||||
nsDeque::nsDeque(nsDequeFunctor* aDeallocator) {
|
||||
mDeallocator=aDeallocator;
|
||||
mCapacity=eGrowthDelta;
|
||||
mOrigin=mSize=0;
|
||||
mData=new void*[mCapacity];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* @update gess4/18/98
|
||||
*/
|
||||
nsDeque::~nsDeque() {
|
||||
Erase();
|
||||
delete [] mData;
|
||||
mData=0;
|
||||
if(mDeallocator) {
|
||||
delete mDeallocator;
|
||||
}
|
||||
mDeallocator=0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of elements currently stored in
|
||||
* this deque.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param
|
||||
* @return int contains element count
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsDeque& nsDeque::Empty() {
|
||||
if((0<mCapacity) && (mData)) {
|
||||
nsCRT::zero(mData,mCapacity*sizeof(mData));
|
||||
}
|
||||
mSize=0;
|
||||
mOrigin=0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove and delete all items from container
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @return this
|
||||
*/
|
||||
nsDeque& nsDeque::Erase() {
|
||||
if(mDeallocator) {
|
||||
ForEach(*mDeallocator);
|
||||
}
|
||||
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
|
||||
* underlying buffer to resize.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param anItem: new item to be added to deque
|
||||
* @return nada
|
||||
*/
|
||||
nsDeque& nsDeque::Push(void* anItem) {
|
||||
if(mSize==mCapacity) {
|
||||
GrowCapacity();
|
||||
}
|
||||
int offset=mOrigin+mSize;
|
||||
if(offset<mCapacity)
|
||||
mData[offset]=anItem;
|
||||
else mData[offset-mCapacity]=anItem;
|
||||
mSize++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method adds an item to the front 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::PushFront(void* anItem) {
|
||||
if(mSize==mCapacity) {
|
||||
GrowCapacity();
|
||||
}
|
||||
if(0==mOrigin){ //case1: [xxx..]
|
||||
//mOrigin=mCapacity-1-mSize++;
|
||||
mOrigin=mCapacity-1;
|
||||
mData[mOrigin]=anItem;
|
||||
}
|
||||
else {// if(mCapacity==(mOrigin+mSize-1)){ //case2: [..xxx] and case3: [.xxx.]
|
||||
mData[--mOrigin]=anItem;
|
||||
}
|
||||
mSize++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove and return the last item in the container.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param none
|
||||
* @return ptr to last item in container
|
||||
*/
|
||||
void* nsDeque::Pop(void) {
|
||||
void* result=0;
|
||||
if(mSize>0) {
|
||||
int offset=mOrigin+mSize-1;
|
||||
if(offset>=mCapacity)
|
||||
offset-=mCapacity;
|
||||
result=mData[offset];
|
||||
mData[offset]=0;
|
||||
mSize--;
|
||||
if(0==mSize)
|
||||
mOrigin=0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called you want to remove and return
|
||||
* the first member in the container.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param nada
|
||||
* @return last item in container
|
||||
*/
|
||||
void* nsDeque::PopFront() {
|
||||
void* result=0;
|
||||
if(mSize>0) {
|
||||
result=mData[mOrigin];
|
||||
mData[mOrigin++]=0; //zero it out for debugging purposes.
|
||||
mSize--;
|
||||
if(mCapacity==mOrigin) //you popped off the end, so cycle back around...
|
||||
mOrigin=0;
|
||||
if(0==mSize)
|
||||
mOrigin=0;
|
||||
}
|
||||
NS_ASSERTION(mOrigin<mCapacity,"Error: Bad origin");
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called you want to peek at the topmost
|
||||
* member without removing it.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param nada
|
||||
* @return last item in container
|
||||
*/
|
||||
void* nsDeque::Peek() {
|
||||
void* result=0;
|
||||
if(mSize>0) {
|
||||
result=mData[mOrigin];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this to retrieve the ith element from this container.
|
||||
* Keep in mind that accessing the underlying elements is
|
||||
* done in a relative fashion. Object 0 is not necessarily
|
||||
* the first element (the first element is at mOrigin).
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param anIndex : 0 relative offset of item you want
|
||||
* @return void* or null
|
||||
*/
|
||||
void* nsDeque::ObjectAt(PRInt32 anIndex) const {
|
||||
void* result=0;
|
||||
|
||||
if((anIndex>=0) && (anIndex<mSize))
|
||||
{
|
||||
if(anIndex<(mCapacity-mOrigin)) {
|
||||
result=mData[mOrigin+anIndex];
|
||||
}
|
||||
else {
|
||||
result=mData[anIndex-(mCapacity-mOrigin)];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return an iterator pointing to
|
||||
* the beginning of the queue. Note that this
|
||||
* takes the circular buffer semantics into account.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @return new deque iterator, init'ed to 1st item
|
||||
*/
|
||||
nsDequeIterator nsDeque::Begin(void) const{
|
||||
return nsDequeIterator(*this,0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return an iterator pointing to
|
||||
* the last of the queue. Note that this
|
||||
* takes the circular buffer semantics into account.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @return new deque iterator, init'ed to last item
|
||||
*/
|
||||
nsDequeIterator nsDeque::End(void) const{
|
||||
return nsDequeIterator(*this,mSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this method when you wanto to iterate all the
|
||||
* members of the container, passing a functor along
|
||||
* to call your code.
|
||||
*
|
||||
* @update gess4/20/98
|
||||
* @param aFunctor object to call for each member
|
||||
* @return *this
|
||||
*/
|
||||
void nsDeque::ForEach(nsDequeFunctor& aFunctor) const{
|
||||
int i=0;
|
||||
for(i=0;i<mSize;i++){
|
||||
void* obj=ObjectAt(i);
|
||||
obj=aFunctor(obj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this method when you wanto to iterate all the
|
||||
* members of the container, passing a functor along
|
||||
* to call your code. Iteration continues until your
|
||||
* functor returns a non-null.
|
||||
*
|
||||
* @update gess4/20/98
|
||||
* @param aFunctor object to call for each member
|
||||
* @return *this
|
||||
*/
|
||||
const void* nsDeque::FirstThat(nsDequeFunctor& aFunctor) const{
|
||||
int i=0;
|
||||
for(i=0;i<mSize;i++){
|
||||
void* obj=ObjectAt(i);
|
||||
obj=aFunctor(obj);
|
||||
if(obj)
|
||||
return obj;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************
|
||||
* Here comes the nsDequeIterator class...
|
||||
******************************************************/
|
||||
|
||||
/**
|
||||
* DequeIterator is an object that knows how to iterate (forward and backward)
|
||||
* a Deque. Normally, you don't need to do this, but there are some special
|
||||
* cases where it is pretty handy, so here you go.
|
||||
*
|
||||
* This is a standard dequeiterator constructor
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param aQueue is the deque object to be iterated
|
||||
* @param anIndex is the starting position for your iteration
|
||||
*/
|
||||
nsDequeIterator::nsDequeIterator(const nsDeque& aQueue,int anIndex): mIndex(anIndex), mDeque(aQueue) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy construct a new iterator beginning with given
|
||||
*
|
||||
* @update gess4/20/98
|
||||
* @param aCopy is another iterator to copy from
|
||||
* @return
|
||||
*/
|
||||
nsDequeIterator::nsDequeIterator(const nsDequeIterator& aCopy) : mIndex(aCopy.mIndex), mDeque(aCopy.mDeque) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves iterator to first element in deque
|
||||
* @update gess4/18/98
|
||||
* @return this
|
||||
*/
|
||||
nsDequeIterator& nsDequeIterator::First(void){
|
||||
mIndex=0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard assignment operator for dequeiterator
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param aCopy is an iterator to be copied from
|
||||
* @return *this
|
||||
*/
|
||||
nsDequeIterator& nsDequeIterator::operator=(const nsDequeIterator& aCopy) {
|
||||
//queue's are already equal.
|
||||
mIndex=aCopy.mIndex;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* preform ! operation against to iterators to test for equivalence
|
||||
* (or lack thereof)!
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param anIter is the object to be compared to
|
||||
* @return TRUE if NOT equal.
|
||||
*/
|
||||
PRBool nsDequeIterator::operator!=(nsDequeIterator& anIter) {
|
||||
return PRBool(!this->operator==(anIter));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compare 2 iterators for equivalence.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param anIter is the other iterator to be compared to
|
||||
* @return TRUE if EQUAL
|
||||
*/
|
||||
PRBool nsDequeIterator::operator<(nsDequeIterator& anIter) {
|
||||
return PRBool(((mIndex<anIter.mIndex) && (&mDeque==&anIter.mDeque)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare 2 iterators for equivalence.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param anIter is the other iterator to be compared to
|
||||
* @return TRUE if EQUAL
|
||||
*/
|
||||
PRBool nsDequeIterator::operator==(nsDequeIterator& anIter) {
|
||||
return PRBool(((mIndex==anIter.mIndex) && (&mDeque==&anIter.mDeque)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare 2 iterators for equivalence.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param anIter is the other iterator to be compared to
|
||||
* @return TRUE if EQUAL
|
||||
*/
|
||||
PRBool nsDequeIterator::operator>=(nsDequeIterator& anIter) {
|
||||
return PRBool(((mIndex>=anIter.mIndex) && (&mDeque==&anIter.mDeque)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-increment operator
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @return object at preincremented index
|
||||
*/
|
||||
void* nsDequeIterator::operator++() {
|
||||
return mDeque.ObjectAt(++mIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post-increment operator
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param param is ignored
|
||||
* @return object at post-incremented index
|
||||
*/
|
||||
void* nsDequeIterator::operator++(int) {
|
||||
return mDeque.ObjectAt(mIndex++);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-decrement operator
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @return object at pre-decremented index
|
||||
*/
|
||||
void* nsDequeIterator::operator--() {
|
||||
return mDeque.ObjectAt(--mIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post-decrement operator
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param param is ignored
|
||||
* @return object at post-decremented index
|
||||
*/
|
||||
void* nsDequeIterator::operator--(int) {
|
||||
return mDeque.ObjectAt(mIndex--);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dereference operator
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @return object at ith index
|
||||
*/
|
||||
void* nsDequeIterator::GetCurrent(void) {
|
||||
return mDeque.ObjectAt(mIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this method when you wanto to iterate all the
|
||||
* members of the container, passing a functor along
|
||||
* to call your code.
|
||||
*
|
||||
* @update gess4/20/98
|
||||
* @param aFunctor object to call for each member
|
||||
* @return *this
|
||||
*/
|
||||
void nsDequeIterator::ForEach(nsDequeFunctor& aFunctor) const{
|
||||
mDeque.ForEach(aFunctor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this method when you wanto to iterate all the
|
||||
* members of the container, passing a functor along
|
||||
* to call your code.
|
||||
*
|
||||
* @update gess4/20/98
|
||||
* @param aFunctor object to call for each member
|
||||
* @return *this
|
||||
*/
|
||||
const void* nsDequeIterator::FirstThat(nsDequeFunctor& aFunctor) const{
|
||||
return mDeque.FirstThat(aFunctor);
|
||||
}
|
||||
|
||||
#ifdef _SELFTEST_DEQUE
|
||||
/**************************************************************
|
||||
Now define the token deallocator class...
|
||||
**************************************************************/
|
||||
class _SelfTestDeallocator: public nsDequeFunctor{
|
||||
public:
|
||||
_SelfTestDeallocator::_SelfTestDeallocator() {
|
||||
nsDeque::SelfTest();
|
||||
}
|
||||
virtual void* operator()(void* anObject) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
static _SelfTestDeallocator gDeallocator;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* conduct automated self test for this class
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsDeque::SelfTest(void) {
|
||||
#ifdef _SELFTEST_DEQUE
|
||||
|
||||
{
|
||||
nsDeque theDeque(gDeallocator); //construct a simple one...
|
||||
|
||||
int ints[200];
|
||||
int count=sizeof(ints)/sizeof(int);
|
||||
int i=0;
|
||||
|
||||
for(i=0;i<count;i++){ //initialize'em
|
||||
ints[i]=10*(1+i);
|
||||
}
|
||||
|
||||
for(i=0;i<70;i++){
|
||||
theDeque.Push(&ints[i]);
|
||||
}
|
||||
|
||||
for(i=0;i<56;i++){
|
||||
int* temp=(int*)theDeque.Pop();
|
||||
}
|
||||
|
||||
for(i=0;i<55;i++){
|
||||
theDeque.Push(&ints[i]);
|
||||
}
|
||||
|
||||
for(i=0;i<35;i++){
|
||||
int* temp=(int*)theDeque.Pop();
|
||||
}
|
||||
|
||||
for(i=0;i<35;i++){
|
||||
theDeque.Push(&ints[i]);
|
||||
}
|
||||
|
||||
for(i=0;i<38;i++){
|
||||
int* temp=(int*)theDeque.Pop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int x;
|
||||
x=10;
|
||||
#endif
|
||||
}
|
||||
|
||||
411
mozilla/base/src/nsDeque.h
Normal file
411
mozilla/base/src/nsDeque.h
Normal file
@@ -0,0 +1,411 @@
|
||||
/* -*- 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:
|
||||
* @update gess 4/15/98 (tax day)
|
||||
*
|
||||
* The Deque is a very small, very efficient container object
|
||||
* than can hold elements of type void*, offering the following features:
|
||||
* It's interface supports pushing and poping of children.
|
||||
* It can iterate (via an interator class) it's children.
|
||||
* When full, it can efficently resize dynamically.
|
||||
*
|
||||
*
|
||||
* NOTE: The only bit of trickery here is that this deque is
|
||||
* built upon a ring-buffer. Like all ring buffers, the first
|
||||
* element may not be at index[0]. The mOrigin member determines
|
||||
* where the first child is. This point is quietly hidden from
|
||||
* customers of this class.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _NSDEQUE
|
||||
#define _NSDEQUE
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
/**
|
||||
* The nsDequefunctor class is used when you want to create
|
||||
* callbacks between the deque and your generic code.
|
||||
* Use these objects in a call to ForEach();
|
||||
*
|
||||
* @update gess4/20/98
|
||||
*/
|
||||
class NS_BASE nsDequeFunctor{
|
||||
public:
|
||||
virtual void* operator()(void* anObject)=0;
|
||||
};
|
||||
|
||||
|
||||
/******************************************************
|
||||
* Here comes the nsDeque class itself...
|
||||
******************************************************/
|
||||
|
||||
/**
|
||||
* The deque (double-ended queue) class is a common container type,
|
||||
* whose behavior mimics a line in your favorite checkout stand.
|
||||
* Classic CS describes the common behavior of a queue as FIFO.
|
||||
* A Deque allows items to be added and removed from either end of
|
||||
* the queue.
|
||||
*
|
||||
* @update gess4/20/98
|
||||
*/
|
||||
|
||||
class NS_BASE nsDeque {
|
||||
friend class nsDequeIterator;
|
||||
public:
|
||||
nsDeque(nsDequeFunctor* aDeallocator);
|
||||
~nsDeque();
|
||||
|
||||
/**
|
||||
* Returns the number of elements currently stored in
|
||||
* this deque.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param
|
||||
* @return int contains element count
|
||||
*/
|
||||
PRInt32 GetSize() const;
|
||||
|
||||
|
||||
/**
|
||||
* Pushes new member onto the end of the deque
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param ptr to object to store
|
||||
* @return *this
|
||||
*/
|
||||
nsDeque& Push(void* anItem);
|
||||
|
||||
/**
|
||||
* Pushes new member onto the front of the deque
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param ptr to object to store
|
||||
* @return *this
|
||||
*/
|
||||
nsDeque& PushFront(void* anItem);
|
||||
|
||||
/**
|
||||
* Remove and return the first item in the container.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param none
|
||||
* @return ptr to first item in container
|
||||
*/
|
||||
void* Pop(void);
|
||||
|
||||
/**
|
||||
* Remove and return the first item in the container.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param none
|
||||
* @return ptr to first item in container
|
||||
*/
|
||||
void* PopFront(void);
|
||||
|
||||
|
||||
/**
|
||||
* Return topmost item without removing it.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param none
|
||||
* @return ptr to first item in container
|
||||
*/
|
||||
void* Peek(void);
|
||||
|
||||
/**
|
||||
* method used to retrieve ptr to
|
||||
* ith member in container. DOesn't remove
|
||||
* that item.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param index of desired item
|
||||
* @return ptr to ith element in list
|
||||
*/
|
||||
void* ObjectAt(int anIndex) const;
|
||||
|
||||
/**
|
||||
* Remove all items from container without destroying them
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsDeque& Empty();
|
||||
|
||||
/**
|
||||
* Remove and delete all items from container
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsDeque& Erase();
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new iterator, init'ed to start of container
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @return new dequeIterator
|
||||
*/
|
||||
nsDequeIterator Begin() const;
|
||||
|
||||
/**
|
||||
* Creates a new iterator, init'ed to end of container
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @return new dequeIterator
|
||||
*/
|
||||
nsDequeIterator End() const;
|
||||
|
||||
|
||||
/**
|
||||
* Call this method when you wanto to iterate all the
|
||||
* members of the container, passing a functor along
|
||||
* to call your code.
|
||||
*
|
||||
* @update gess4/20/98
|
||||
* @param aFunctor object to call for each member
|
||||
* @return *this
|
||||
*/
|
||||
void ForEach(nsDequeFunctor& aFunctor) const;
|
||||
|
||||
/**
|
||||
* Call this method when you wanto to iterate all the
|
||||
* members of the container, passing a functor along
|
||||
* to call your code. This process will interupt if
|
||||
* your function returns a null to this iterator.
|
||||
*
|
||||
* @update gess4/20/98
|
||||
* @param aFunctor object to call for each member
|
||||
* @return *this
|
||||
*/
|
||||
const void* FirstThat(nsDequeFunctor& aFunctor) const;
|
||||
|
||||
void SetDeallocator(nsDequeFunctor* aDeallocator);
|
||||
|
||||
/**
|
||||
* Perform automated selftest on the deque
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
static void SelfTest();
|
||||
|
||||
protected:
|
||||
|
||||
PRInt32 mSize;
|
||||
PRInt32 mCapacity;
|
||||
PRInt32 mOrigin;
|
||||
nsDequeFunctor* mDeallocator;
|
||||
void** mData;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
enum {eGrowthDelta=64};
|
||||
|
||||
/**
|
||||
* Simple default constructor (PRIVATE)
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsDeque();
|
||||
|
||||
/**
|
||||
* Copy constructor (PRIVATE)
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsDeque(const nsDeque& other);
|
||||
|
||||
/**
|
||||
* Deque assignment operator (PRIVATE)
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param another deque
|
||||
* @return *this
|
||||
*/
|
||||
nsDeque& operator=(const nsDeque& anOther);
|
||||
|
||||
nsDeque& GrowCapacity(void);
|
||||
|
||||
};
|
||||
|
||||
/******************************************************
|
||||
* Here comes the nsDequeIterator class...
|
||||
******************************************************/
|
||||
|
||||
class NS_BASE nsDequeIterator {
|
||||
public:
|
||||
|
||||
/**
|
||||
* DequeIterator is an object that knows how to iterate (forward and backward)
|
||||
* a Deque. Normally, you don't need to do this, but there are some special
|
||||
* cases where it is pretty handy, so here you go.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param aQueue is the deque object to be iterated
|
||||
* @param anIndex is the starting position for your iteration
|
||||
*/
|
||||
nsDequeIterator(const nsDeque& aQueue,int anIndex=0);
|
||||
|
||||
/**
|
||||
* DequeIterator is an object that knows how to iterate (forward and backward)
|
||||
* a Deque. Normally, you don't need to do this, but there are some special
|
||||
* cases where it is pretty handy, so here you go.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param aQueue is the deque object to be iterated
|
||||
* @param anIndex is the starting position for your iteration
|
||||
*/
|
||||
nsDequeIterator(const nsDequeIterator& aCopy);
|
||||
|
||||
/**
|
||||
* Moves iterator to first element in deque
|
||||
* @update gess4/18/98
|
||||
* @return this
|
||||
*/
|
||||
nsDequeIterator& First(void);
|
||||
|
||||
/**
|
||||
* Standard assignment operator for deque
|
||||
* @update gess4/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsDequeIterator& operator=(const nsDequeIterator& aCopy);
|
||||
|
||||
/**
|
||||
* preform ! operation against to iterators to test for equivalence
|
||||
* (or lack thereof)!
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param anIter is the object to be compared to
|
||||
* @return TRUE if NOT equal.
|
||||
*/
|
||||
PRBool operator!=(nsDequeIterator& anIter);
|
||||
|
||||
/**
|
||||
* Compare 2 iterators for equivalence.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param anIter is the other iterator to be compared to
|
||||
* @return TRUE if EQUAL
|
||||
*/
|
||||
PRBool operator<(nsDequeIterator& anIter);
|
||||
|
||||
/**
|
||||
* Compare 2 iterators for equivalence.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param anIter is the other iterator to be compared to
|
||||
* @return TRUE if EQUAL
|
||||
*/
|
||||
PRBool operator==(nsDequeIterator& anIter);
|
||||
|
||||
/**
|
||||
* Compare 2 iterators for equivalence.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param anIter is the other iterator to be compared to
|
||||
* @return TRUE if EQUAL
|
||||
*/
|
||||
PRBool operator>=(nsDequeIterator& anIter);
|
||||
|
||||
/**
|
||||
* Pre-increment operator
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @return object at preincremented index
|
||||
*/
|
||||
void* operator++();
|
||||
|
||||
/**
|
||||
* Post-increment operator
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param param is ignored
|
||||
* @return object at post-incremented index
|
||||
*/
|
||||
void* operator++(int);
|
||||
|
||||
/**
|
||||
* Pre-decrement operator
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @return object at pre-decremented index
|
||||
*/
|
||||
void* operator--();
|
||||
|
||||
/**
|
||||
* Post-decrement operator
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param param is ignored
|
||||
* @return object at post-decremented index
|
||||
*/
|
||||
void* operator--(int);
|
||||
|
||||
/**
|
||||
* Retrieve the ptr to the iterators notion of current node
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @return object at ith index
|
||||
*/
|
||||
void* GetCurrent(void);
|
||||
|
||||
/**
|
||||
* Call this method when you wanto to iterate all the
|
||||
* members of the container, passing a functor along
|
||||
* to call your code.
|
||||
*
|
||||
* @update gess4/20/98
|
||||
* @param aFunctor object to call for each member
|
||||
* @return *this
|
||||
*/
|
||||
void ForEach(nsDequeFunctor& aFunctor) const;
|
||||
|
||||
/**
|
||||
* Call this method when you wanto to iterate all the
|
||||
* members of the container, passing a functor along
|
||||
* to call your code.
|
||||
*
|
||||
* @update gess4/20/98
|
||||
* @param aFunctor object to call for each member
|
||||
* @return *this
|
||||
*/
|
||||
const void* FirstThat(nsDequeFunctor& aFunctor) const;
|
||||
|
||||
protected:
|
||||
|
||||
PRInt32 mIndex;
|
||||
const nsDeque& mDeque;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
214
mozilla/base/src/nsEscape.cpp
Normal file
214
mozilla/base/src/nsEscape.cpp
Normal file
@@ -0,0 +1,214 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
// First checked in on 98/12/03 by John R. McMullen, derived from net.h/mkparse.c.
|
||||
|
||||
#include "nsEscape.h"
|
||||
|
||||
#include "plstr.h"
|
||||
#include "prmem.h"
|
||||
|
||||
const int netCharType[256] =
|
||||
/* Bit 0 xalpha -- the alphas
|
||||
** Bit 1 xpalpha -- as xalpha but
|
||||
** converts spaces to plus and plus to %20
|
||||
** Bit 3 ... path -- as xalphas but doesn't escape '/'
|
||||
*/
|
||||
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
|
||||
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 1x */
|
||||
0,0,0,0,0,0,0,0,0,0,7,4,0,7,7,4, /* 2x !"#$%&'()*+,-./ */
|
||||
7,7,7,7,7,7,7,7,7,7,0,0,0,0,0,0, /* 3x 0123456789:;<=>? */
|
||||
0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, /* 4x @ABCDEFGHIJKLMNO */
|
||||
/* bits for '@' changed from 7 to 0 so '@' can be escaped */
|
||||
/* in usernames and passwords in publishing. */
|
||||
7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,7, /* 5X PQRSTUVWXYZ[\]^_ */
|
||||
0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, /* 6x `abcdefghijklmno */
|
||||
7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,0, /* 7X pqrstuvwxyz{\}~ DEL */
|
||||
0, };
|
||||
|
||||
/* decode % escaped hex codes into character values
|
||||
*/
|
||||
#define UNHEX(C) \
|
||||
((C >= '0' && C <= '9') ? C - '0' : \
|
||||
((C >= 'A' && C <= 'F') ? C - 'A' + 10 : \
|
||||
((C >= 'a' && C <= 'f') ? C - 'a' + 10 : 0)))
|
||||
|
||||
|
||||
#define IS_OK(C) (netCharType[((unsigned int) (C))] & (mask))
|
||||
#define HEX_ESCAPE '%'
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_BASE char* nsEscape(const char * str, nsEscapeMask mask)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if(!str)
|
||||
return NULL;
|
||||
return nsEscapeCount(str, (PRInt32)PL_strlen(str), mask, NULL);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_BASE char* nsEscapeCount(
|
||||
const char * str,
|
||||
PRInt32 len,
|
||||
nsEscapeMask mask,
|
||||
PRInt32* out_len)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
int i, extra = 0;
|
||||
char* hexChars = "0123456789ABCDEF";
|
||||
|
||||
register const unsigned char* src = (const unsigned char *) str;
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (!IS_OK(*src++))
|
||||
extra += 2; /* the escape, plus an extra byte for each nibble */
|
||||
}
|
||||
|
||||
char* result = new char[len + extra + 1];
|
||||
if (!result)
|
||||
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 */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*dst = '\0'; /* tack on eos */
|
||||
if(out_len)
|
||||
*out_len = dst - (unsigned char *) result;
|
||||
return result;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_BASE char* nsUnescape(char * str)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsUnescapeCount(str);
|
||||
return str;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_BASE PRInt32 nsUnescapeCount(char * str)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
register char *src = str;
|
||||
register char *dst = 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);
|
||||
}
|
||||
1145
mozilla/base/src/nsFileSpec.cpp
Normal file
1145
mozilla/base/src/nsFileSpec.cpp
Normal file
File diff suppressed because it is too large
Load Diff
82
mozilla/base/src/nsFileSpecStreaming.cpp
Normal file
82
mozilla/base/src/nsFileSpecStreaming.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
326
mozilla/base/src/nsFileStream.cpp
Normal file
326
mozilla/base/src/nsFileStream.cpp
Normal file
@@ -0,0 +1,326 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
// First checked in on 98/12/08 by John R. McMullen.
|
||||
// Since nsFileStream.h is entirely templates, common code (such as open())
|
||||
// which does not actually depend on the charT, can be placed here.
|
||||
|
||||
#include "nsFileStream.h"
|
||||
|
||||
#include "nsIStringStream.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
//========================================================================================
|
||||
// nsInputStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsInputStream::~nsInputStream()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
char nsInputStream::get()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char c;
|
||||
if (read(&c, sizeof(c)) == sizeof(c))
|
||||
return c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
PRInt32 nsInputStream::read(void* s, PRInt32 n)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
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)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
c = get();
|
||||
return *this;
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// nsOutputStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream::~nsOutputStream()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
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)
|
||||
// This will truncate if the buffer is too small. Result will always be null-terminated.
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
PRBool bufferLargeEnough = PR_TRUE; // result
|
||||
if (!s || !n)
|
||||
return PR_TRUE;
|
||||
|
||||
PRIntn position = tell();
|
||||
if (position < 0)
|
||||
return PR_FALSE;
|
||||
PRInt32 bytesRead = read(s, n - 1);
|
||||
if (failed())
|
||||
return PR_FALSE;
|
||||
s[bytesRead] = '\0'; // always terminate at the end of the buffer
|
||||
char* tp = strpbrk(s, "\n\r");
|
||||
if (tp)
|
||||
{
|
||||
TidyEndOfLine(tp);
|
||||
bytesRead = (tp - s);
|
||||
}
|
||||
else if (!eof())
|
||||
bufferLargeEnough = PR_FALSE;
|
||||
position += bytesRead;
|
||||
seek(position);
|
||||
return bufferLargeEnough;
|
||||
} // nsRandomAccessInputStream::readline
|
||||
|
||||
//========================================================================================
|
||||
// nsInputStringStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsInputStringStream::nsInputStringStream(const char* stringToRead)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewCharInputStream(&stream, stringToRead)))
|
||||
return;
|
||||
mInputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsInputStringStream::nsInputStringStream(const nsString& stringToRead)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// nsInputFileStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsInputFileStream::nsInputFileStream(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode,
|
||||
PRIntn accessMode)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewIOFileStream(&stream, inFile, nsprMode, accessMode)))
|
||||
return;
|
||||
mFile = nsQueryInterface(stream);
|
||||
mInputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
mFileInputStream = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
} // nsInputFileStream::nsInputFileStream
|
||||
|
||||
//========================================================================================
|
||||
// nsOutputFileStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsOutputFileStream::flush()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (mFileOutputStream)
|
||||
mFileOutputStream->Flush();
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// Manipulators
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream& nsEndl(nsOutputStream& os)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
#ifdef XP_PC
|
||||
os.write("\r\n", 2);
|
||||
#else
|
||||
os.put('\n');
|
||||
#endif
|
||||
os.flush();
|
||||
return os;
|
||||
} // nsEndl
|
||||
22
mozilla/base/src/nsGenericCaretProperties.cpp
Normal file
22
mozilla/base/src/nsGenericCaretProperties.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
|
||||
#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();
|
||||
}
|
||||
53
mozilla/base/src/nsIArena.h
Normal file
53
mozilla/base/src/nsIArena.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/* -*- 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 nsIArena_h___
|
||||
#define nsIArena_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
#define NS_MIN_ARENA_BLOCK_SIZE 64
|
||||
#define NS_DEFAULT_ARENA_BLOCK_SIZE 4096
|
||||
|
||||
/// Interface IID for nsIArena
|
||||
#define NS_IARENA_IID \
|
||||
{ 0xa24fdad0, 0x93b4, 0x11d1, \
|
||||
{0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
|
||||
|
||||
/** Interface to a memory arena abstraction. Arena's use large blocks
|
||||
* of memory to allocate smaller objects. Arena's provide no free
|
||||
* operator; instead, all of the objects in the arena are deallocated
|
||||
* by deallocating the arena (e.g. when it's reference count goes to
|
||||
* zero)
|
||||
*/
|
||||
class nsIArena : public nsISupports {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IARENA_IID; return iid; }
|
||||
|
||||
virtual void* Alloc(PRInt32 size) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new arena using the desired block size for allocating the
|
||||
* underlying memory blocks. The underlying memory blocks are allocated
|
||||
* using the PR heap.
|
||||
*/
|
||||
extern NS_BASE nsresult NS_NewHeapArena(nsIArena** aInstancePtrResult,
|
||||
PRInt32 aArenaBlockSize = 0);
|
||||
|
||||
#endif /* nsIArena_h___ */
|
||||
79
mozilla/base/src/nsIAtom.h
Normal file
79
mozilla/base/src/nsIAtom.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/* -*- 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 nsIAtom_h___
|
||||
#define nsIAtom_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
class nsString;
|
||||
class nsISizeOfHandler;
|
||||
|
||||
#define NS_IATOM_IID \
|
||||
{ 0x3d1b15b0, 0x93b4, 0x11d1, \
|
||||
{0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
|
||||
|
||||
/**
|
||||
* A globally unique identfier. nsIAtom's can be compared for
|
||||
* equality by using operator '=='. These objects are reference
|
||||
* counted like other nsISupports objects. When you are done with
|
||||
* the atom, NS_RELEASE it.
|
||||
*/
|
||||
class nsIAtom : public nsISupports {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IATOM_IID; return iid; }
|
||||
|
||||
/**
|
||||
* Translate the unicode string into the stringbuf.
|
||||
*/
|
||||
virtual void ToString(nsString& aString) const = 0;
|
||||
|
||||
/**
|
||||
* Return a pointer to a zero terminated unicode string.
|
||||
*/
|
||||
virtual const PRUnichar* GetUnicode() const = 0;
|
||||
|
||||
/**
|
||||
* Add the size, in bytes, of the atom to the handler.
|
||||
*/
|
||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler) const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Find an atom that matches the given iso-latin1 C string. The
|
||||
* C string is translated into it's unicode equivalent.
|
||||
*/
|
||||
extern NS_BASE nsIAtom* NS_NewAtom(const char* isolatin1);
|
||||
|
||||
/**
|
||||
* Find an atom that matches the given unicode string. The string is assumed
|
||||
* to be zero terminated.
|
||||
*/
|
||||
extern NS_BASE nsIAtom* NS_NewAtom(const PRUnichar* unicode);
|
||||
|
||||
/**
|
||||
* Find an atom that matches the given string.
|
||||
*/
|
||||
extern NS_BASE nsIAtom* NS_NewAtom(const nsString& aString);
|
||||
|
||||
/**
|
||||
* Return a count of the total number of atoms currently
|
||||
* alive in the system.
|
||||
*/
|
||||
extern NS_BASE nsrefcnt NS_GetNumberOfAtoms(void);
|
||||
|
||||
#endif /* nsIAtom_h___ */
|
||||
60
mozilla/base/src/nsIBaseStream.h
Normal file
60
mozilla/base/src/nsIBaseStream.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* -*- 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 nsIBaseStream_h___
|
||||
#define nsIBaseStream_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
|
||||
/* 6ccb17a0-e95e-11d1-beae-00805f8a66dc */
|
||||
#define NS_IBASESTREAM_IID \
|
||||
{ 0x6ccb17a0, 0xe95e, 0x11d1, \
|
||||
{0xbe, 0xae, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc} }
|
||||
|
||||
/** Abstract stream */
|
||||
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;
|
||||
};
|
||||
|
||||
/** Error codes */
|
||||
//@{
|
||||
/// End of file
|
||||
#define NS_BASE_STREAM_EOF NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 1)
|
||||
/// Stream closed
|
||||
#define NS_BASE_STREAM_CLOSED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 2)
|
||||
/// Error from the operating system
|
||||
#define NS_BASE_STREAM_OSERROR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 3)
|
||||
/// Illegal arguments
|
||||
#define NS_BASE_STREAM_ILLEGAL_ARGS NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 4)
|
||||
/// For unichar streams
|
||||
#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)
|
||||
//@}
|
||||
|
||||
|
||||
#endif /* nsInputStream_h___ */
|
||||
59
mozilla/base/src/nsIByteBuffer.h
Normal file
59
mozilla/base/src/nsIByteBuffer.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/* -*- 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 nsIByteBuffer_h___
|
||||
#define nsIByteBuffer_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIInputStream;
|
||||
|
||||
#define NS_IBYTE_BUFFER_IID \
|
||||
{ 0xe4a6e4b0, 0x93b4, 0x11d1, \
|
||||
{0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
|
||||
|
||||
/** Interface to a buffer that holds bytes */
|
||||
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;
|
||||
|
||||
/** @return number of bytes allocated in the buffer */
|
||||
NS_IMETHOD_(PRUint32) GetBufferSize(void) const = 0;
|
||||
|
||||
/** @return the buffer */
|
||||
NS_IMETHOD_(char*) GetBuffer(void) const = 0;
|
||||
|
||||
/** Grow buffer to aNewSize bytes. */
|
||||
NS_IMETHOD_(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;
|
||||
};
|
||||
|
||||
/** Create a new byte buffer using the given buffer size. */
|
||||
extern NS_BASE nsresult
|
||||
NS_NewByteBuffer(nsIByteBuffer** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
PRUint32 aBufferSize = 0);
|
||||
|
||||
#endif /* nsIByteBuffer_h___ */
|
||||
|
||||
482
mozilla/base/src/nsIFileStream.cpp
Normal file
482
mozilla/base/src/nsIFileStream.cpp
Normal file
@@ -0,0 +1,482 @@
|
||||
/* -*- 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);
|
||||
}
|
||||
54
mozilla/base/src/nsIInputStream.h
Normal file
54
mozilla/base/src/nsIInputStream.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/* -*- 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 nsIInputStream_h___
|
||||
#define nsIInputStream_h___
|
||||
|
||||
#include "nsIBaseStream.h"
|
||||
|
||||
#define NS_IINPUTSTREAM_IID \
|
||||
{ 0x022396f0, 0x93b5, 0x11d1, \
|
||||
{0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
|
||||
|
||||
/** Abstract byte input stream */
|
||||
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
|
||||
* will be undefined
|
||||
* @return error status
|
||||
*/
|
||||
NS_IMETHOD
|
||||
GetLength(PRUint32 *aLength) = 0;
|
||||
|
||||
/** Read data from the stream.
|
||||
* @param aBuf the buffer into which the data is read
|
||||
* @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
|
||||
* read count will be undefined
|
||||
* @return error status
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount) = 0;
|
||||
};
|
||||
|
||||
#endif /* nsInputStream_h___ */
|
||||
73
mozilla/base/src/nsIOutputStream.h
Normal file
73
mozilla/base/src/nsIOutputStream.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/* -*- 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 nsIOutputStream_h___
|
||||
#define nsIOutputStream_h___
|
||||
|
||||
#include "nsIBaseStream.h"
|
||||
|
||||
class nsIInputStream;
|
||||
|
||||
/* 7f13b870-e95f-11d1-beae-00805f8a66dc */
|
||||
#define NS_IOUTPUTSTREAM_IID \
|
||||
{ 0x7f13b870, 0xe95f, 0x11d1, \
|
||||
{0xbe, 0xae, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc} }
|
||||
|
||||
/** Abstract byte output stream */
|
||||
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 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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsOutputStream_h___ */
|
||||
485
mozilla/base/src/nsIStringStream.cpp
Normal file
485
mozilla/base/src/nsIStringStream.cpp
Normal file
@@ -0,0 +1,485 @@
|
||||
/* -*- 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);
|
||||
}
|
||||
96
mozilla/base/src/nsITimer.h
Normal file
96
mozilla/base/src/nsITimer.h
Normal file
@@ -0,0 +1,96 @@
|
||||
/* -*- 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 nsITimer_h___
|
||||
#define nsITimer_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsITimer;
|
||||
class nsITimerCallback;
|
||||
|
||||
// Implementations of nsITimer should be written such that there are no limitations
|
||||
// on what can be called by the TimerCallbackFunc. On platforms like the Macintosh this
|
||||
// means that callback functions must be called from the main event loop NOT from
|
||||
// an interrupt.
|
||||
|
||||
/// Signature of timer callback function
|
||||
typedef void
|
||||
(*nsTimerCallbackFunc) (nsITimer *aTimer, void *aClosure);
|
||||
|
||||
/// Interface IID for nsITimer
|
||||
#define NS_ITIMER_IID \
|
||||
{ 0x497eed20, 0xb740, 0x11d1, \
|
||||
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
|
||||
|
||||
/**
|
||||
* Timer class, used to invoke a function or method after a fixed
|
||||
* millisecond interval. <B>Note that this interface is subject to
|
||||
* change!</B>
|
||||
*/
|
||||
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
|
||||
* that function.
|
||||
*
|
||||
* @param aFunc - The function to invoke
|
||||
* @param aClosure - an opaque pointer to pass to that function
|
||||
* @param aRepeat - (Not yet implemented) One-shot or repeating
|
||||
* @param aDelay - The millisecond interval
|
||||
* @result - NS_OK if this operation was successful
|
||||
*/
|
||||
virtual nsresult Init(nsTimerCallbackFunc aFunc,
|
||||
void *aClosure,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay)=0;
|
||||
|
||||
/**
|
||||
* Initialize a timer to fire after the given millisecond interval.
|
||||
* This version takes an interface of type <code>nsITimerCallback</code>.
|
||||
* The <code>Notify</code> method of this method is invoked.
|
||||
*
|
||||
* @param aCallback - The interface to notify
|
||||
* @param aRepeat - (Not yet implemented) One-shot or repeating
|
||||
* @param aDelay - The millisecond interval
|
||||
* @result - NS_OK if this operation was successful
|
||||
*/
|
||||
virtual nsresult Init(nsITimerCallback *aCallback,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay)=0;
|
||||
|
||||
/// Cancels the timeout
|
||||
virtual void Cancel()=0;
|
||||
|
||||
/// @return the millisecond delay of the timeout
|
||||
virtual PRUint32 GetDelay()=0;
|
||||
|
||||
/// Change the millisecond interval for the timeout
|
||||
virtual void SetDelay(PRUint32 aDelay)=0;
|
||||
|
||||
/// @return the opaque pointer
|
||||
virtual void* GetClosure()=0;
|
||||
};
|
||||
|
||||
/** Factory method for creating an nsITimer */
|
||||
extern NS_BASE nsresult NS_NewTimer(nsITimer** aInstancePtrResult);
|
||||
|
||||
#endif
|
||||
43
mozilla/base/src/nsITimerCallback.h
Normal file
43
mozilla/base/src/nsITimerCallback.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/* -*- 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 nsITimerCallback_h___
|
||||
#define nsITimerCallback_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsITimer;
|
||||
|
||||
/// Interface IID for nsITimerCallback
|
||||
#define NS_ITIMERCALLBACK_IID \
|
||||
{ 0x5079b3a0, 0xb743, 0x11d1, \
|
||||
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
|
||||
|
||||
/**
|
||||
* Interface implemented by users of the nsITimer class. An instance
|
||||
* of this interface is passed in when creating a timer. The Notify()
|
||||
* method of that instance is invoked after the specified delay.
|
||||
*/
|
||||
class nsITimerCallback : public nsISupports {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITIMERCALLBACK_IID)
|
||||
|
||||
virtual void Notify(nsITimer *timer) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
46
mozilla/base/src/nsIUnicharBuffer.h
Normal file
46
mozilla/base/src/nsIUnicharBuffer.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/* -*- 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 nsIUnicharBuffer_h___
|
||||
#define nsIUnicharBuffer_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
class nsIUnicharInputStream;
|
||||
|
||||
#define NS_IUNICHAR_BUFFER_IID \
|
||||
{ 0x14cf6970, 0x93b5, 0x11d1, \
|
||||
{0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
|
||||
|
||||
/// Interface to a buffer that holds unicode characters
|
||||
class nsIUnicharBuffer : public nsISupports {
|
||||
public:
|
||||
virtual PRInt32 GetLength() const = 0;
|
||||
virtual PRInt32 GetBufferSize() const = 0;
|
||||
virtual PRUnichar* GetBuffer() const = 0;
|
||||
virtual PRBool Grow(PRInt32 aNewSize) = 0;
|
||||
virtual PRInt32 Fill(nsresult* aErrorCode, nsIUnicharInputStream* aStream,
|
||||
PRInt32 aKeep) = 0;
|
||||
};
|
||||
|
||||
/// Factory method for nsIUnicharBuffer.
|
||||
extern NS_BASE nsresult
|
||||
NS_NewUnicharBuffer(nsIUnicharBuffer** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
PRUint32 aBufferSize = 0);
|
||||
|
||||
#endif /* nsIUnicharBuffer_h___ */
|
||||
62
mozilla/base/src/nsIUnicharInputStream.h
Normal file
62
mozilla/base/src/nsIUnicharInputStream.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/* -*- 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 nsIUnicharInputStream_h___
|
||||
#define nsIUnicharInputStream_h___
|
||||
|
||||
#include "nsIInputStream.h"
|
||||
class nsString;
|
||||
|
||||
#define NS_IUNICHAR_INPUT_STREAM_IID \
|
||||
{ 0x2d97fbf0, 0x93b5, 0x11d1, \
|
||||
{0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
|
||||
|
||||
/** Abstract unicode character input stream
|
||||
* @see nsIInputStream
|
||||
*/
|
||||
class nsIUnicharInputStream : public nsISupports {
|
||||
public:
|
||||
NS_IMETHOD Read(PRUnichar* aBuf,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aCount,
|
||||
PRUint32 *aReadCount) = 0;
|
||||
NS_IMETHOD Close() = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a nsIUnicharInputStream that wraps up a string. Data is fed
|
||||
* from the string out until the done. When this object is destroyed
|
||||
* it destroyes the string (so make a copy if you don't want it doing
|
||||
* that)
|
||||
*/
|
||||
extern NS_BASE nsresult
|
||||
NS_NewStringUnicharInputStream(nsIUnicharInputStream** aInstancePtrResult,
|
||||
nsString* aString);
|
||||
|
||||
/** 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
|
||||
* NS_INPUTSTREAM_NO_CONVERTER.
|
||||
*/
|
||||
extern NS_BASE nsresult
|
||||
NS_NewConverterStream(nsIUnicharInputStream** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
nsIInputStream* aStreamToWrap,
|
||||
PRInt32 aBufferSize = 0,
|
||||
nsString* aCharSet = nsnull);
|
||||
|
||||
#endif /* nsUnicharInputStream_h___ */
|
||||
340
mozilla/base/src/nsInt64.h
Normal file
340
mozilla/base/src/nsInt64.h
Normal file
@@ -0,0 +1,340 @@
|
||||
/* -*- 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 nsInt64_h__
|
||||
#define nsInt64_h__
|
||||
|
||||
#include "prlong.h"
|
||||
#include "nscore.h"
|
||||
|
||||
/**
|
||||
* This class encapsulates full 64-bit integer functionality and
|
||||
* provides simple arithmetic and conversion operations.
|
||||
*/
|
||||
|
||||
// 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
|
||||
// nsInt64".
|
||||
|
||||
class nsInt64
|
||||
{
|
||||
private:
|
||||
PRInt64 mValue;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Construct a new 64-bit integer.
|
||||
*/
|
||||
nsInt64(void) : mValue(LL_ZERO) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new 64-bit integer from a 32-bit signed integer
|
||||
*/
|
||||
nsInt64(const PRInt32 aInt32) {
|
||||
LL_I2L(mValue, aInt32);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new 64-bit integer from a 32-bit unsigned integer
|
||||
*/
|
||||
nsInt64(const PRUint32 aUint32) {
|
||||
LL_UI2L(mValue, aUint32);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new 64-bit integer from a floating point value.
|
||||
*/
|
||||
nsInt64(const PRFloat64 aFloat64) {
|
||||
LL_D2L(mValue, aFloat64);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new 64-bit integer from a native 64-bit integer
|
||||
*/
|
||||
nsInt64(const PRInt64 aInt64) : mValue(aInt64) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new 64-bit integer from another 64-bit integer
|
||||
*/
|
||||
nsInt64(const nsInt64& aObject) : mValue(aObject.mValue) {
|
||||
}
|
||||
|
||||
// ~nsInt64(void) -- XXX destructor unnecessary
|
||||
|
||||
/**
|
||||
* Assign a 64-bit integer to another 64-bit integer
|
||||
*/
|
||||
const nsInt64& operator =(const nsInt64& aObject) {
|
||||
mValue = aObject.mValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a 64-bit integer to a signed 32-bit value
|
||||
*/
|
||||
operator PRInt32(void) const {
|
||||
PRInt32 result;
|
||||
LL_L2I(result, mValue);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a 64-bit integer to an unsigned 32-bit value
|
||||
*/
|
||||
operator PRUint32(void) const {
|
||||
PRUint32 result;
|
||||
LL_L2UI(result, mValue);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a 64-bit integer to a floating point value
|
||||
*/
|
||||
operator PRFloat64(void) const {
|
||||
PRFloat64 result;
|
||||
LL_L2D(result, mValue);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a 64-bit integer to a native 64-bit integer.
|
||||
*/
|
||||
operator PRInt64(void) const {
|
||||
return mValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform unary negation on a 64-bit integer.
|
||||
*/
|
||||
const nsInt64 operator -(void) {
|
||||
nsInt64 result;
|
||||
LL_NEG(result.mValue, mValue);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Arithmetic operators
|
||||
friend const nsInt64 operator +(const nsInt64& aObject1, const nsInt64& aObject2);
|
||||
friend const nsInt64 operator -(const nsInt64& aObject1, const nsInt64& aObject2);
|
||||
friend const nsInt64 operator *(const nsInt64& aObject1, const nsInt64& aObject2);
|
||||
friend const nsInt64 operator /(const nsInt64& aObject1, const nsInt64& aObject2);
|
||||
friend const nsInt64 operator %(const nsInt64& aObject1, const nsInt64& aObject2);
|
||||
|
||||
/**
|
||||
* Increment a 64-bit integer by a 64-bit integer amount.
|
||||
*/
|
||||
nsInt64& operator +=(const nsInt64& aObject) {
|
||||
LL_ADD(mValue, mValue, aObject.mValue);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement a 64-bit integer by a 64-bit integer amount.
|
||||
*/
|
||||
nsInt64& operator -=(const nsInt64& aObject) {
|
||||
LL_SUB(mValue, mValue, aObject.mValue);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply a 64-bit integer by a 64-bit integer amount.
|
||||
*/
|
||||
nsInt64& operator *=(const nsInt64& aObject) {
|
||||
LL_MUL(mValue, mValue, aObject.mValue);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide a 64-bit integer by a 64-bit integer amount.
|
||||
*/
|
||||
nsInt64& operator /=(const nsInt64& aObject) {
|
||||
LL_DIV(mValue, mValue, aObject.mValue);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the modulus of a 64-bit integer to a 64-bit value.
|
||||
*/
|
||||
nsInt64& operator %=(const nsInt64& aObject) {
|
||||
LL_MOD(mValue, mValue, aObject.mValue);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Comparison operators
|
||||
friend PRBool operator ==(const nsInt64& aObject1, const nsInt64& aObject2);
|
||||
friend PRBool operator !=(const nsInt64& aObject1, const nsInt64& aObject2);
|
||||
friend PRBool operator >(const nsInt64& aObject1, const nsInt64& aObject2);
|
||||
friend PRBool operator >=(const nsInt64& aObject1, const nsInt64& aObject2);
|
||||
friend PRBool operator <(const nsInt64& aObject1, const nsInt64& aObject2);
|
||||
friend PRBool operator <=(const nsInt64& aObject1, const nsInt64& aObject2);
|
||||
|
||||
// Bitwise operators
|
||||
friend const nsInt64 operator &(const nsInt64& aObject1, const nsInt64& aObject2);
|
||||
friend const nsInt64 operator |(const nsInt64& aObject1, const nsInt64& aObject2);
|
||||
friend const nsInt64 operator ^(const nsInt64& aObject1, const nsInt64& aObject2);
|
||||
|
||||
/**
|
||||
* Compute the bitwise NOT of a 64-bit integer
|
||||
*/
|
||||
const nsInt64 operator ~(void) {
|
||||
nsInt64 result;
|
||||
LL_NOT(result.mValue, mValue);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the bitwise AND with another 64-bit integer
|
||||
*/
|
||||
nsInt64& operator &=(const nsInt64& aObject) {
|
||||
LL_AND(mValue, mValue, aObject.mValue);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the bitwise OR with another 64-bit integer
|
||||
*/
|
||||
nsInt64& operator |=(const nsInt64& aObject) {
|
||||
LL_OR(mValue, mValue, aObject.mValue);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the bitwise XOR with another 64-bit integer
|
||||
*/
|
||||
nsInt64& operator ^=(const nsInt64& aObject) {
|
||||
LL_XOR(mValue, mValue, aObject.mValue);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Add two 64-bit integers.
|
||||
*/
|
||||
inline const nsInt64
|
||||
operator +(const nsInt64& aObject1, const nsInt64& aObject2) {
|
||||
return nsInt64(aObject1) += aObject2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract one 64-bit integer from another.
|
||||
*/
|
||||
inline const nsInt64
|
||||
operator -(const nsInt64& aObject1, const nsInt64& aObject2) {
|
||||
return nsInt64(aObject1) -= aObject2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply two 64-bit integers
|
||||
*/
|
||||
inline const nsInt64
|
||||
operator *(const nsInt64& aObject1, const nsInt64& aObject2) {
|
||||
return nsInt64(aObject1) *= aObject2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide one 64-bit integer by another
|
||||
*/
|
||||
inline const nsInt64
|
||||
operator /(const nsInt64& aObject1, const nsInt64& aObject2) {
|
||||
return nsInt64(aObject1) /= aObject2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the modulus of two 64-bit integers
|
||||
*/
|
||||
inline const nsInt64
|
||||
operator %(const nsInt64& aObject1, const nsInt64& aObject2) {
|
||||
return nsInt64(aObject1) %= aObject2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if two 64-bit integers are equal
|
||||
*/
|
||||
inline PRBool
|
||||
operator ==(const nsInt64& aObject1, const nsInt64& aObject2) {
|
||||
return LL_EQ(aObject1.mValue, aObject2.mValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if two 64-bit integers are not equal
|
||||
*/
|
||||
inline PRBool
|
||||
operator !=(const nsInt64& aObject1, const nsInt64& aObject2) {
|
||||
return LL_NE(aObject1.mValue, aObject2.mValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if one 64-bit integer is strictly greater than another, using signed values
|
||||
*/
|
||||
inline PRBool
|
||||
operator >(const nsInt64& aObject1, const nsInt64& aObject2) {
|
||||
return LL_CMP(aObject1.mValue, >, aObject2.mValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if one 64-bit integer is greater than or equal to another, using signed values
|
||||
*/
|
||||
inline PRBool
|
||||
operator >=(const nsInt64& aObject1, const nsInt64& aObject2) {
|
||||
return LL_CMP(aObject1.mValue, >=, aObject2.mValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if one 64-bit integer is strictly less than another, using signed values
|
||||
*/
|
||||
inline PRBool
|
||||
operator <(const nsInt64& aObject1, const nsInt64& aObject2) {
|
||||
return LL_CMP(aObject1.mValue, <, aObject2.mValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if one 64-bit integers is less than or equal to another, using signed values
|
||||
*/
|
||||
inline PRBool
|
||||
operator <=(const nsInt64& aObject1, const nsInt64& aObject2) {
|
||||
return LL_CMP(aObject1.mValue, <=, aObject2.mValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a bitwise AND of two 64-bit integers
|
||||
*/
|
||||
inline const nsInt64
|
||||
operator &(const nsInt64& aObject1, const nsInt64& aObject2) {
|
||||
return nsInt64(aObject1) &= aObject2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a bitwise OR of two 64-bit integers
|
||||
*/
|
||||
inline const nsInt64
|
||||
operator |(const nsInt64& aObject1, const nsInt64& aObject2) {
|
||||
return nsInt64(aObject1) |= aObject2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a bitwise XOR of two 64-bit integers
|
||||
*/
|
||||
inline const nsInt64
|
||||
operator ^(const nsInt64& aObject1, const nsInt64& aObject2) {
|
||||
return nsInt64(aObject1) ^= aObject2;
|
||||
}
|
||||
|
||||
|
||||
#endif // nsInt64_h__
|
||||
83
mozilla/base/src/nsObserver.cpp
Normal file
83
mozilla/base/src/nsObserver.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
/* -*- 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;
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
40
mozilla/base/src/nsObserver.h
Normal file
40
mozilla/base/src/nsObserver.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/* -*- 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___ */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user