Compare commits
1 Commits
Bugzilla_P
...
WINCE_PORT
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b92e98150 |
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.]
|
||||
24
mozilla/base/Makefile
Normal file
24
mozilla/base/Makefile
Normal file
@@ -0,0 +1,24 @@
|
||||
#!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 = ..
|
||||
|
||||
DIRS = public src tests
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
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
|
||||
BIN
mozilla/base/macbuild/base.mcp
Normal file
BIN
mozilla/base/macbuild/base.mcp
Normal file
Binary file not shown.
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>
|
||||
5
mozilla/base/public/MANIFEST
Normal file
5
mozilla/base/public/MANIFEST
Normal file
@@ -0,0 +1,5 @@
|
||||
#
|
||||
# This is a list of local files which get copied to the mozilla:dist:base directory
|
||||
#
|
||||
|
||||
nsISizeOfHandler.h
|
||||
30
mozilla/base/public/Makefile
Normal file
30
mozilla/base/public/Makefile
Normal file
@@ -0,0 +1,30 @@
|
||||
#!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=../..
|
||||
|
||||
DEFINES = -D_IMPL_NS_BASE
|
||||
|
||||
EXPORTS = \
|
||||
nsISizeOfHandler.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = raptor
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
37
mozilla/base/public/Makefile.in
Normal file
37
mozilla/base/public/Makefile.in
Normal file
@@ -0,0 +1,37 @@
|
||||
#!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 = \
|
||||
nsISizeOfHandler.h \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
MODULE = raptor
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
30
mozilla/base/public/makefile.win
Normal file
30
mozilla/base/public/makefile.win
Normal file
@@ -0,0 +1,30 @@
|
||||
#!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 = \
|
||||
nsISizeOfHandler.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = raptor
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
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___ */
|
||||
24
mozilla/base/src/MANIFEST
Normal file
24
mozilla/base/src/MANIFEST
Normal file
@@ -0,0 +1,24 @@
|
||||
#
|
||||
# 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
|
||||
nsString.h
|
||||
nsVoidArray.h
|
||||
nsUnitConversion.h
|
||||
nsIBaseStream.h
|
||||
nsIInputStream.h
|
||||
nsIOutputStream.h
|
||||
nsInt64.h
|
||||
nsTime.h
|
||||
79
mozilla/base/src/Makefile
Normal file
79
mozilla/base/src/Makefile
Normal file
@@ -0,0 +1,79 @@
|
||||
#!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=../..
|
||||
|
||||
DEFINES =-D_IMPL_NS_BASE
|
||||
|
||||
ifeq ($(OS_TARGET),Rhapsody)
|
||||
DIRS = rhapsody
|
||||
else
|
||||
DIRS = unix
|
||||
endif
|
||||
|
||||
LIBRARY_NAME = raptorbase
|
||||
|
||||
CPPSRCS = \
|
||||
nsArena.cpp \
|
||||
nsAtomTable.cpp \
|
||||
nsBTree.cpp \
|
||||
nsByteBuffer.cpp \
|
||||
nsCRT.cpp \
|
||||
nsDeque.cpp \
|
||||
nsRBTree.cpp \
|
||||
nsSizeOfHandler.cpp \
|
||||
nsString.cpp \
|
||||
nsUnicharBuffer.cpp \
|
||||
nsUnicharInputStream.cpp \
|
||||
nsVoidArray.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 \
|
||||
nsString.h \
|
||||
nsTime.h \
|
||||
nsVoidArray.h \
|
||||
nsUnitConversion.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = raptor
|
||||
|
||||
REQUIRES = xpcom netlib raptor
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
TARGET = $(LIBARY)
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
|
||||
test:
|
||||
@echo OS_ARCH = $(OS_ARCH)
|
||||
83
mozilla/base/src/Makefile.in
Normal file
83
mozilla/base/src/Makefile.in
Normal file
@@ -0,0 +1,83 @@
|
||||
#!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
|
||||
|
||||
DEFINES =-D_IMPL_NS_BASE
|
||||
|
||||
ifeq ($(OS_ARCH),Rhapsody)
|
||||
DIRS = rhapsody
|
||||
else
|
||||
DIRS = unix
|
||||
endif
|
||||
|
||||
LIBRARY_NAME = raptorbase
|
||||
|
||||
CPPSRCS = \
|
||||
nsArena.cpp \
|
||||
nsAtomTable.cpp \
|
||||
nsBTree.cpp \
|
||||
nsByteBuffer.cpp \
|
||||
nsCRT.cpp \
|
||||
nsDeque.cpp \
|
||||
nsRBTree.cpp \
|
||||
nsSizeOfHandler.cpp \
|
||||
nsString.cpp \
|
||||
nsUnicharBuffer.cpp \
|
||||
nsUnicharInputStream.cpp \
|
||||
nsVoidArray.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 \
|
||||
nsString.h \
|
||||
nsTime.h \
|
||||
nsVoidArray.h \
|
||||
nsUnitConversion.h \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
MODULE = raptor
|
||||
|
||||
REQUIRES = xpcom netlib raptor
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
TARGET = $(LIBARY)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
292
mozilla/base/src/mac/nsTimerMac.cpp
Normal file
292
mozilla/base/src/mac/nsTimerMac.cpp
Normal file
@@ -0,0 +1,292 @@
|
||||
/* -*- 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
|
||||
//
|
||||
|
||||
// nsMacTimerPeriodical idles,
|
||||
|
||||
|
||||
#include "nsITimer.h"
|
||||
#include "nsITimerCallback.h"
|
||||
#include "prlog.h"
|
||||
#include <LPeriodical.h>
|
||||
#include <LArray.h>
|
||||
#include <LArrayIterator.h>
|
||||
#include <LComparator.h>
|
||||
|
||||
#pragma mark class TimerImpl
|
||||
//
|
||||
// TimerImpl implements nsITimer API
|
||||
//
|
||||
class TimerImpl : public nsITimer
|
||||
{
|
||||
private:
|
||||
nsTimerCallbackFunc mCallbackFunc;
|
||||
nsITimerCallback * mCallbackObject;
|
||||
void * mClosure;
|
||||
PRUint32 mDelay;
|
||||
UInt32 mFireTime; // Timer should fire when TickCount >= this number
|
||||
|
||||
public:
|
||||
|
||||
// constructors
|
||||
|
||||
TimerImpl();
|
||||
|
||||
virtual ~TimerImpl(){};
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
UInt32 GetFireTime() { 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();
|
||||
|
||||
private:
|
||||
// Calculates mFireTime too
|
||||
void SetDelaySelf( PRUint32 aDelay );
|
||||
};
|
||||
|
||||
#pragma mark class TimerPeriodical
|
||||
//
|
||||
// TimerPeriodical is a singleton LPeriodical subclass that fires
|
||||
// off TimerImpl. The firing is done on idle
|
||||
//
|
||||
class TimerPeriodical : public LPeriodical
|
||||
{
|
||||
static TimerPeriodical * gPeriodical;
|
||||
|
||||
LArray mTimers; // List of TimerImpl *
|
||||
|
||||
public:
|
||||
// Returns the singleton instance
|
||||
static TimerPeriodical * GetPeriodical();
|
||||
|
||||
TimerPeriodical();
|
||||
|
||||
virtual ~TimerPeriodical();
|
||||
|
||||
nsresult AddTimer( TimerImpl * aTimer);
|
||||
|
||||
nsresult RemoveTimer( TimerImpl * aTimer);
|
||||
|
||||
virtual void SpendTime( const EventRecord &inMacEvent);
|
||||
};
|
||||
|
||||
#pragma mark class TimerImplComparator
|
||||
//
|
||||
// TimerImplComparator compares two TimerImpl
|
||||
//
|
||||
class TimerImplComparator : public LComparator
|
||||
{
|
||||
virtual Int32 Compare(
|
||||
const void* inItemOne,
|
||||
const void* inItemTwo,
|
||||
Uint32 inSizeOne,
|
||||
Uint32 inSizeTwo) const;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// TimerImpl implementation
|
||||
//
|
||||
|
||||
static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID);
|
||||
NS_IMPL_ISUPPORTS(TimerImpl, kITimerIID)
|
||||
|
||||
TimerImpl::TimerImpl()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mCallbackFunc = NULL;
|
||||
mCallbackObject = NULL;
|
||||
mClosure = NULL;
|
||||
mDelay = 0;
|
||||
mFireTime = 0;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
// Make sure that timer was sorted
|
||||
NS_ADDREF(this);
|
||||
TimerPeriodical::GetPeriodical()->RemoveTimer(this);
|
||||
TimerPeriodical::GetPeriodical()->AddTimer(this);
|
||||
NS_RELEASE(this);
|
||||
}
|
||||
|
||||
void* TimerImpl::GetClosure()
|
||||
{
|
||||
return mClosure;
|
||||
}
|
||||
|
||||
void TimerImpl::Fire()
|
||||
{
|
||||
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 = NULL;
|
||||
|
||||
TimerPeriodical * TimerPeriodical::GetPeriodical()
|
||||
{
|
||||
if (gPeriodical == NULL)
|
||||
gPeriodical = new TimerPeriodical();
|
||||
return gPeriodical;
|
||||
}
|
||||
|
||||
TimerPeriodical::TimerPeriodical()
|
||||
{
|
||||
mTimers.SetComparator( new TimerImplComparator() );
|
||||
mTimers.SetKeepSorted( true );
|
||||
}
|
||||
|
||||
TimerPeriodical::~TimerPeriodical()
|
||||
{
|
||||
PR_ASSERT(mTimers.GetCount() == 0);
|
||||
}
|
||||
|
||||
nsresult TimerPeriodical::AddTimer( TimerImpl * aTimer)
|
||||
{
|
||||
try
|
||||
{
|
||||
NS_ADDREF(aTimer);
|
||||
mTimers.AddItem( &aTimer );
|
||||
StartRepeating();
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult TimerPeriodical::RemoveTimer( TimerImpl * aTimer)
|
||||
{
|
||||
mTimers.SetComparator(LLongComparator::GetComparator(), false);
|
||||
mTimers.Remove(&aTimer);
|
||||
mTimers.SetComparator(new TimerImplComparator());
|
||||
|
||||
NS_RELEASE( aTimer );
|
||||
if ( mTimers.GetCount() == 0 )
|
||||
StopRepeating();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Called through every event loop
|
||||
// Loops through the list of available timers, and
|
||||
// fires off the available ones
|
||||
void TimerPeriodical::SpendTime( const EventRecord &inMacEvent)
|
||||
{
|
||||
LArrayIterator iter(mTimers);
|
||||
TimerImpl * timer;
|
||||
while (iter.Next(&timer))
|
||||
{
|
||||
if (timer->GetFireTime() <= inMacEvent.when)
|
||||
{
|
||||
//NS_ADDREF(timer);
|
||||
RemoveTimer(timer);
|
||||
timer->Fire();
|
||||
//NS_RELEASE(timer);
|
||||
}
|
||||
else
|
||||
break; // Items are sorted, so we do not need to iterate until the end
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// class TimerImplComparator implementation
|
||||
//
|
||||
Int32 TimerImplComparator::Compare(
|
||||
const void* inItemOne,
|
||||
const void* inItemTwo,
|
||||
Uint32 inSizeOne,
|
||||
Uint32 inSizeTwo) const
|
||||
{
|
||||
return (( TimerImpl *) inItemOne)->GetFireTime() - (( TimerImpl *) inItemTwo)->GetFireTime();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
100
mozilla/base/src/makefile.win
Normal file
100
mozilla/base/src/makefile.win
Normal file
@@ -0,0 +1,100 @@
|
||||
#!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 \
|
||||
nsBTree.cpp \
|
||||
nsByteBuffer.cpp \
|
||||
nsCRT.cpp \
|
||||
nsDeque.cpp \
|
||||
nsRBTree.cpp \
|
||||
nsSizeOfHandler.cpp \
|
||||
nsString.cpp \
|
||||
nsUnicharBuffer.cpp \
|
||||
nsUnicharInputStream.cpp \
|
||||
nsVoidArray.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS = \
|
||||
.\$(OBJDIR)\nsArena.obj \
|
||||
.\$(OBJDIR)\nsAtomTable.obj \
|
||||
.\$(OBJDIR)\nsBTree.obj \
|
||||
.\$(OBJDIR)\nsByteBuffer.obj \
|
||||
.\$(OBJDIR)\nsCRT.obj \
|
||||
.\$(OBJDIR)\nsDeque.obj \
|
||||
.\$(OBJDIR)\nsRBTree.obj \
|
||||
.\$(OBJDIR)\nsSizeOfHandler.obj \
|
||||
.\$(OBJDIR)\nsString.obj \
|
||||
.\$(OBJDIR)\nsUnicharBuffer.obj \
|
||||
.\$(OBJDIR)\nsUnicharInputStream.obj \
|
||||
.\$(OBJDIR)\nsVoidArray.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 \
|
||||
nsUnitConversion.h \
|
||||
nsIBaseStream.h nsIInputStream.h nsIOutputStream.h \
|
||||
nsInt64.h nsTime.h
|
||||
|
||||
MODULE=raptor
|
||||
|
||||
REQUIRES=xpcom netlib raptor
|
||||
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\netlib \
|
||||
-I$(PUBLIC)\raptor
|
||||
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
DLLNAME = raptorbase
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
OBJS = $(OBJS) .\$(OBJDIR)\nsTimer.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\libplc21.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
|
||||
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:
|
||||
~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);
|
||||
}
|
||||
154
mozilla/base/src/nsAtomTable.cpp
Normal file
154
mozilla/base/src/nsAtomTable.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
/* -*- 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();
|
||||
~AtomImpl();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
void* operator new(size_t size, const PRUnichar* us, PRInt32 uslen);
|
||||
|
||||
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*) new char[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);
|
||||
}
|
||||
PRInt32 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
|
||||
|
||||
138
mozilla/base/src/nsByteBuffer.cpp
Normal file
138
mozilla/base/src/nsByteBuffer.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
/* -*- 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(PRInt32 aBufferSize);
|
||||
~ByteBufferImpl();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
virtual PRInt32 GetLength() const;
|
||||
virtual PRInt32 GetBufferSize() const;
|
||||
virtual char* GetBuffer() const;
|
||||
virtual PRBool Grow(PRInt32 aNewSize);
|
||||
virtual PRInt32 Fill(nsresult* aErrorCode, nsIInputStream* aStream,
|
||||
PRInt32 aKeep);
|
||||
|
||||
char* mBuffer;
|
||||
PRInt32 mSpace;
|
||||
PRInt32 mLength;
|
||||
};
|
||||
|
||||
ByteBufferImpl::ByteBufferImpl(PRInt32 aBufferSize)
|
||||
{
|
||||
if (PRUint32(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;
|
||||
}
|
||||
|
||||
PRInt32 ByteBufferImpl::GetLength() const
|
||||
{
|
||||
return mLength;
|
||||
}
|
||||
|
||||
PRInt32 ByteBufferImpl::GetBufferSize() const
|
||||
{
|
||||
return mSpace;
|
||||
}
|
||||
|
||||
char* ByteBufferImpl::GetBuffer() const
|
||||
{
|
||||
return mBuffer;
|
||||
}
|
||||
|
||||
PRBool ByteBufferImpl::Grow(PRInt32 aNewSize)
|
||||
{
|
||||
if (PRUint32(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;
|
||||
}
|
||||
|
||||
PRInt32 ByteBufferImpl::Fill(nsresult* aErrorCode, nsIInputStream* aStream,
|
||||
PRInt32 aKeep)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aStream, "null stream");
|
||||
NS_PRECONDITION(PRUint32(aKeep) <= PRUint32(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;
|
||||
PRInt32 amount = mSpace - aKeep;
|
||||
PRInt32 nb;
|
||||
*aErrorCode = aStream->Read(mBuffer, aKeep, amount, &nb);
|
||||
if (NS_SUCCEEDED(*aErrorCode)) {
|
||||
mLength += nb;
|
||||
}
|
||||
else
|
||||
nb = 0;
|
||||
return nb;
|
||||
}
|
||||
|
||||
NS_BASE nsresult NS_NewByteBuffer(nsIByteBuffer** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
PRInt32 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);
|
||||
}
|
||||
400
mozilla/base/src/nsCRT.cpp
Normal file
400
mozilla/base/src/nsCRT.cpp
Normal file
@@ -0,0 +1,400 @@
|
||||
/* -*- 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"
|
||||
|
||||
// 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
|
||||
};
|
||||
|
||||
static const PRUnichar kIsoLatin1ToUCS2[256] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
||||
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
||||
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) < 256) ? PRUnichar(kUpper2Lower[_ucs2]) : _ToLower(_ucs2))
|
||||
|
||||
#define TOUPPER(_ucs2) \
|
||||
(((_ucs2) < 256) ? PRUnichar(kLower2Upper[_ucs2]) : _ToUpper(_ucs2))
|
||||
|
||||
static PRUnichar _ToLower(PRUnichar aChar)
|
||||
{
|
||||
// XXX need i18n code here
|
||||
return aChar;
|
||||
}
|
||||
|
||||
static PRUnichar _ToUpper(PRUnichar aChar)
|
||||
{
|
||||
// XXX need i18n code here
|
||||
return aChar;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
PRUnichar nsCRT::ToUpper(PRUnichar aChar)
|
||||
{
|
||||
return TOUPPER(aChar);
|
||||
}
|
||||
|
||||
PRUnichar nsCRT::ToLower(PRUnichar aChar)
|
||||
{
|
||||
return TOLOWER(aChar);
|
||||
}
|
||||
|
||||
PRInt32 nsCRT::strlen(const PRUnichar* s)
|
||||
{
|
||||
PRInt32 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, PRInt32 n)
|
||||
{
|
||||
if(s1 && s2) {
|
||||
if(0<n) {
|
||||
while (--n >= 0) {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = *s2++;
|
||||
if (c1 != c2) {
|
||||
if (c1 < c2) return -1;
|
||||
return 1;
|
||||
}
|
||||
if ((0==c1) || (0==c2)) break;
|
||||
}
|
||||
}
|
||||
else return 1;
|
||||
}
|
||||
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, PRInt32 n)
|
||||
{
|
||||
if(s1 && s2) {
|
||||
if(0<n){
|
||||
while (--n >= 0) {
|
||||
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;
|
||||
}
|
||||
} else return 1;
|
||||
}
|
||||
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, PRInt32 n)
|
||||
{
|
||||
if(s1 && s2) {
|
||||
if(0<n){
|
||||
while (--n >= 0) {
|
||||
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;
|
||||
}
|
||||
} else return 1;
|
||||
}
|
||||
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, PRInt32 n)
|
||||
{
|
||||
if(s1 && s2){
|
||||
if(0<n){
|
||||
while (--n >= 0) {
|
||||
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;
|
||||
}
|
||||
} else return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
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, PRInt32* uslenp)
|
||||
{
|
||||
PRUint32 rv = 0;
|
||||
PRInt32 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);
|
||||
}
|
||||
|
||||
115
mozilla/base/src/nsCRT.h
Normal file
115
mozilla/base/src/nsCRT.h
Normal file
@@ -0,0 +1,115 @@
|
||||
/* -*- 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"
|
||||
|
||||
/// 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, PRInt32 aCount) {
|
||||
::memcpy(aDest, aSrc, (size_t)aCount);
|
||||
}
|
||||
|
||||
static void memmove(void* aDest, const void* aSrc, PRInt32 aCount) {
|
||||
::memmove(aDest, aSrc, (size_t)aCount);
|
||||
}
|
||||
|
||||
static void memset(void* aDest, PRUint8 aByte, PRInt32 aCount) {
|
||||
::memset(aDest, aByte, aCount);
|
||||
}
|
||||
|
||||
static void zero(void* aDest, PRInt32 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 PRInt32 strlen(const char* s) {
|
||||
return PRInt32(::strlen(s));
|
||||
}
|
||||
|
||||
/// Compare s1 and s2.
|
||||
static PRInt32 strcmp(const char* s1, const char* s2) {
|
||||
return PRInt32(PL_strcmp(s1, s2));
|
||||
}
|
||||
|
||||
/// 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, PRInt32 aMaxLen) {
|
||||
return PRInt32(PL_strncasecmp(s1, s2, aMaxLen));
|
||||
}
|
||||
|
||||
/// Like strlen except for ucs2 strings
|
||||
static PRInt32 strlen(const PRUnichar* s);
|
||||
|
||||
/// Like strcmp except for ucs2 strings
|
||||
static PRInt32 strcmp(const PRUnichar* s1, const PRUnichar* s2);
|
||||
/// Like strcmp except for ucs2 strings
|
||||
static PRInt32 strncmp(const PRUnichar* s1, const PRUnichar* s2,
|
||||
PRInt32 aMaxLen);
|
||||
|
||||
/// Like strcasecmp except for ucs2 strings
|
||||
static PRInt32 strcasecmp(const PRUnichar* s1, const PRUnichar* s2);
|
||||
/// Like strncasecmp except for ucs2 strings
|
||||
static PRInt32 strncasecmp(const PRUnichar* s1, const PRUnichar* s2,
|
||||
PRInt32 aMaxLen);
|
||||
|
||||
/// Like strcmp with a char* and a ucs2 string
|
||||
static PRInt32 strcmp(const PRUnichar* s1, const char* s2);
|
||||
/// Like strncmp with a char* and a ucs2 string
|
||||
static PRInt32 strncmp(const PRUnichar* s1, const char* s2,
|
||||
PRInt32 aMaxLen);
|
||||
|
||||
/// Like strcasecmp with a char* and a ucs2 string
|
||||
static PRInt32 strcasecmp(const PRUnichar* s1, const char* s2);
|
||||
/// Like strncasecmp with a char* and a ucs2 string
|
||||
static PRInt32 strncasecmp(const PRUnichar* s1, const char* s2,
|
||||
PRInt32 aMaxLen);
|
||||
|
||||
/// 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, PRInt32* s1len);
|
||||
|
||||
/// String to integer.
|
||||
static PRInt32 atoi( const PRUnichar *string );
|
||||
|
||||
static PRUnichar ToUpper(PRUnichar aChar);
|
||||
|
||||
static PRUnichar ToLower(PRUnichar aChar);
|
||||
};
|
||||
|
||||
#endif /* nsCRT_h___ */
|
||||
516
mozilla/base/src/nsDeque.cpp
Normal file
516
mozilla/base/src/nsDeque.cpp
Normal file
@@ -0,0 +1,516 @@
|
||||
/* -*- 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& aMemDestroyer) : mMemDestroyer(aMemDestroyer) {
|
||||
mMemDestroyer=aMemDestroyer;
|
||||
mCapacity=eGrowthDelta;
|
||||
mOrigin=mSize=0;
|
||||
mData=new void*[mCapacity];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* @update gess4/18/98
|
||||
*/
|
||||
nsDeque::~nsDeque() {
|
||||
Erase();
|
||||
delete [] mData;
|
||||
mData=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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all items from container without destroying them.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsDeque& nsDeque::Empty() {
|
||||
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() {
|
||||
ForEach(mMemDestroyer);
|
||||
return Empty();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method adds an item to the end of the queue.
|
||||
* This operation has the potential to cause the
|
||||
* underlying buffer to resize.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param anItem: new item to be added to queue
|
||||
* @return nada
|
||||
*/
|
||||
nsDeque& nsDeque::Push(void* anItem) {
|
||||
if(mSize==mCapacity) {
|
||||
void** temp=new void*[mCapacity+eGrowthDelta];
|
||||
|
||||
//Here's the interesting part: You can't just move the elements
|
||||
//directy (in situ) from the old buffer to the new one.
|
||||
//Since capacity has changed, the old origin doesn't make
|
||||
//sense anymore. It's better to resequence the elements now.
|
||||
|
||||
int tempi=0;
|
||||
int i=0;
|
||||
int j=0;
|
||||
for(i=mOrigin;i<mCapacity;i++) temp[tempi++]=mData[i]; //copy the leading elements...
|
||||
for(j=0;j<mOrigin;j++) temp[tempi++]=mData[j]; //copy the trailing elements...
|
||||
mCapacity+=eGrowthDelta;
|
||||
mOrigin=0; //now realign the origin...
|
||||
delete[]mData;
|
||||
mData=temp;
|
||||
}
|
||||
int offset=mOrigin+mSize;
|
||||
if(offset<mCapacity)
|
||||
mData[offset]=anItem;
|
||||
else mData[offset-mCapacity]=anItem;
|
||||
mSize++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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::Pop() {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove and return the last item in the container.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param none
|
||||
* @return ptr to last item in container
|
||||
*/
|
||||
void* nsDeque::PopBack(void) {
|
||||
void* result=0;
|
||||
if(mSize>0) {
|
||||
int offset=mOrigin+mSize;
|
||||
if(offset>=mCapacity)
|
||||
offset-=mCapacity;
|
||||
result=mData[offset-1];
|
||||
mData[offset-1]=0;
|
||||
mSize--;
|
||||
if(0==mSize)
|
||||
mOrigin=0;
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
396
mozilla/base/src/nsDeque.h
Normal file
396
mozilla/base/src/nsDeque.h
Normal file
@@ -0,0 +1,396 @@
|
||||
/* -*- 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& aMemDestroyer);
|
||||
~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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Return topmost item without removing it.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param none
|
||||
* @return ptr to first item in container
|
||||
*/
|
||||
void* Peek(void);
|
||||
|
||||
/**
|
||||
* Remove and return the last item in the container.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param none
|
||||
* @return ptr to first item in container
|
||||
*/
|
||||
void* PopBack(void);
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Perform automated selftest on the deque
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
static void SelfTest();
|
||||
|
||||
protected:
|
||||
|
||||
PRInt32 mSize;
|
||||
PRInt32 mCapacity;
|
||||
PRInt32 mOrigin;
|
||||
nsDequeFunctor& mMemDestroyer;
|
||||
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);
|
||||
|
||||
/**
|
||||
* PRIVATE 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;
|
||||
|
||||
};
|
||||
|
||||
/******************************************************
|
||||
* 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
|
||||
51
mozilla/base/src/nsIArena.h
Normal file
51
mozilla/base/src/nsIArena.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/* -*- 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:
|
||||
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___ */
|
||||
77
mozilla/base/src/nsIAtom.h
Normal file
77
mozilla/base/src/nsIAtom.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/* -*- 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:
|
||||
/**
|
||||
* 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___ */
|
||||
57
mozilla/base/src/nsIBaseStream.h
Normal file
57
mozilla/base/src/nsIBaseStream.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/* -*- 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:
|
||||
|
||||
/** Close the stream. */
|
||||
NS_IMETHOD
|
||||
Close(void) = 0;
|
||||
};
|
||||
|
||||
/** Error codes */
|
||||
//@{
|
||||
// XXX fix up the values so they are not total hacks... MMP
|
||||
/// End of file
|
||||
#define NS_BASE_STREAM_EOF 0x80001001
|
||||
/// Stream closed
|
||||
#define NS_BASE_STREAM_CLOSED 0x80001002
|
||||
/// Error from the operating system
|
||||
#define NS_BASE_STREAM_OSERROR 0x80001003
|
||||
/// Illegal arguments
|
||||
#define NS_BASE_STREAM_ILLEGAL_ARGS 0x80001004
|
||||
/// For unichar streams
|
||||
#define NS_BASE_STREAM_NO_CONVERTER 0x80001005
|
||||
/// For unichar streams
|
||||
#define NS_BASE_STREAM_BAD_CONVERSION 0x80001006
|
||||
//@}
|
||||
|
||||
|
||||
#endif /* nsInputStream_h___ */
|
||||
56
mozilla/base/src/nsIByteBuffer.h
Normal file
56
mozilla/base/src/nsIByteBuffer.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/* -*- 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. */
|
||||
virtual PRInt32 GetLength() const = 0;
|
||||
|
||||
/** @return number of bytes allocated in the buffer */
|
||||
virtual PRInt32 GetBufferSize() const = 0;
|
||||
|
||||
/** @return the buffer */
|
||||
virtual char* GetBuffer() const = 0;
|
||||
|
||||
/** Grow buffer to aNewSize bytes. */
|
||||
virtual PRBool Grow(PRInt32 aNewSize) = 0;
|
||||
|
||||
/** Fill the buffer with data from aStream. Don't grow the buffer, only
|
||||
* read until length of buffer equals buffer size. */
|
||||
virtual PRInt32 Fill(nsresult* aErrorCode, nsIInputStream* aStream,
|
||||
PRInt32 aKeep) = 0;
|
||||
};
|
||||
|
||||
/** Create a new byte buffer using the given buffer size. */
|
||||
extern NS_BASE nsresult NS_NewByteBuffer(nsIByteBuffer** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
PRInt32 aBufferSize = 0);
|
||||
|
||||
#endif /* nsIByteBuffer_h___ */
|
||||
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:
|
||||
|
||||
/** 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(PRInt32 *aLength) = 0;
|
||||
|
||||
/** Read data from the stream.
|
||||
* @param aErrorCode the error code if an error occurs
|
||||
* @param aBuf the buffer into which the data is read
|
||||
* @param aOffset the start offset of the data
|
||||
* @param aCount the maximum number of bytes to read
|
||||
* @param aReadCount out parameter to hold the number of
|
||||
* bytes read, eof if 0. if an error occurs, the
|
||||
* read count will be undefined
|
||||
* @return error status
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Read(char* aBuf, PRInt32 aOffset, PRInt32 aCount, PRInt32 *aReadCount) = 0;
|
||||
};
|
||||
|
||||
#endif /* nsInputStream_h___ */
|
||||
46
mozilla/base/src/nsIOutputStream.h
Normal file
46
mozilla/base/src/nsIOutputStream.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 nsIOutputStream_h___
|
||||
#define nsIOutputStream_h___
|
||||
|
||||
#include "nsIBaseStream.h"
|
||||
|
||||
/* 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:
|
||||
|
||||
/** Write data into the stream.
|
||||
* @param aBuf the buffer into which the data is read
|
||||
* @param aOffset the start offset of the data
|
||||
* @param aCount the maximum number of bytes to read
|
||||
* @param aWriteCount out parameter to hold the number of
|
||||
* bytes written. if an error occurs, the writecount
|
||||
* is undefined
|
||||
* @return error status
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Write(const char* aBuf, PRInt32 aOffset, PRInt32 aCount, PRInt32 *aWriteCount) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsOutputStream_h___ */
|
||||
94
mozilla/base/src/nsITimer.h
Normal file
94
mozilla/base/src/nsITimer.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/* -*- 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:
|
||||
/**
|
||||
* 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
|
||||
41
mozilla/base/src/nsITimerCallback.h
Normal file
41
mozilla/base/src/nsITimerCallback.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/* -*- 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:
|
||||
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,
|
||||
PRInt32 aBufferSize = 0);
|
||||
|
||||
#endif /* nsIUnicharBuffer_h___ */
|
||||
98
mozilla/base/src/nsIUnicharInputStream.h
Normal file
98
mozilla/base/src/nsIUnicharInputStream.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/* -*- 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} }
|
||||
|
||||
#define NS_IB2UCONVERTER_IID \
|
||||
{ 0x35e40290, 0x93b5, 0x11d1, \
|
||||
{0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
|
||||
|
||||
/// Enumeration of character set ids.
|
||||
enum nsCharSetID {
|
||||
eCharSetID_IsoLatin1 = 0,
|
||||
eCharSetID_UTF8,
|
||||
eCharSetID_ShiftJis
|
||||
// XXX more i'm sure...
|
||||
};
|
||||
|
||||
/** Abstract unicode character input stream
|
||||
* @see nsIInputStream
|
||||
*/
|
||||
class nsIUnicharInputStream : public nsISupports {
|
||||
public:
|
||||
NS_IMETHOD Read(PRUnichar* aBuf,
|
||||
PRInt32 aOffset,
|
||||
PRInt32 aCount,
|
||||
PRInt32 *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);
|
||||
|
||||
/// Abstract interface for converting from bytes to unicode characters
|
||||
class nsIB2UConverter : public nsISupports {
|
||||
public:
|
||||
/** aDstLen is updated to indicate how much data was translated into
|
||||
* aDst; aSrcLen is updated to indicate how much data was used in
|
||||
* the source buffer.
|
||||
*/
|
||||
virtual PRInt32 Convert(PRUnichar* aDst,
|
||||
PRInt32 aDstOffset,
|
||||
PRInt32& aDstLen,
|
||||
const char* aSrc,
|
||||
PRInt32 aSrcOffset,
|
||||
PRInt32& aSrcLen) = 0;
|
||||
};
|
||||
|
||||
/** Create a new nsUnicharInputStream that provides a converter for the
|
||||
* byte input stream aStreamToWrap. If no converter can be found then
|
||||
* nsnull is returned and the error code is set to
|
||||
* NS_INPUTSTREAM_NO_CONVERTER.
|
||||
*/
|
||||
extern NS_BASE nsresult
|
||||
NS_NewConverterStream(nsIUnicharInputStream** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
nsIInputStream* aStreamToWrap,
|
||||
PRInt32 aBufferSize = 0,
|
||||
nsCharSetID aCharSet = eCharSetID_IsoLatin1);
|
||||
|
||||
/** Create a new nsB2UConverter for the given character set. When given
|
||||
* nsnull, the converter for iso-latin1 to unicode is provided. If no
|
||||
* converter can be found, nsnull is returned.
|
||||
*/
|
||||
extern NS_BASE nsresult
|
||||
NS_NewB2UConverter(nsIB2UConverter** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
nsCharSetID aCharSet = eCharSetID_IsoLatin1);
|
||||
|
||||
#endif /* nsUnicharInputStream_h___ */
|
||||
335
mozilla/base/src/nsInt64.h
Normal file
335
mozilla/base/src/nsInt64.h
Normal file
@@ -0,0 +1,335 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
class NS_BASE 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.
|
||||
*/
|
||||
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__
|
||||
423
mozilla/base/src/nsRBTree.cpp
Normal file
423
mozilla/base/src/nsRBTree.cpp
Normal file
@@ -0,0 +1,423 @@
|
||||
|
||||
/**
|
||||
* 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 "nsRBTree.h"
|
||||
|
||||
|
||||
|
||||
/**************************************************
|
||||
Here comes the nsRBTree class...
|
||||
*************************************************/
|
||||
|
||||
/**
|
||||
* nsRBTree constructor
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
*/
|
||||
nsRBTree::nsRBTree() : nsBTree() {
|
||||
mRoot=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* nsRBTree constructor
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
*/
|
||||
nsRBTree::nsRBTree(const nsRBTree& aCopy) : nsBTree(aCopy) {
|
||||
mRoot=aCopy.mRoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* nsRBTree destructor
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsRBTree::~nsRBTree(){
|
||||
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
|
||||
* @return
|
||||
*/
|
||||
nsNode* nsRBTree::Add(nsNode& aNode){
|
||||
|
||||
nsBTree::Add(aNode);
|
||||
|
||||
nsNode* node1=&aNode;
|
||||
nsNode* node2=0;
|
||||
|
||||
node1->mColor=nsNode::eRed;
|
||||
|
||||
while((node1!=mRoot) && (node1->mParent->mColor==nsNode::eRed)) {
|
||||
if(node1->mParent==node1->mParent->mParent->mLeft) {
|
||||
node2=node1->mParent->mParent->mLeft;
|
||||
if(node2->mColor==nsNode::eRed) {
|
||||
node1->mParent->mColor=nsNode::eBlack;
|
||||
node2->mColor=nsNode::eBlack;
|
||||
node1->mParent->mParent->mColor=nsNode::eRed;
|
||||
node1=node1->mParent->mParent;
|
||||
}
|
||||
else {
|
||||
if(node1==node1->mParent->mRight) {
|
||||
node1=node1->mParent;
|
||||
ShiftLeft(*node1);
|
||||
}
|
||||
node1->mParent->mColor=nsNode::eBlack;
|
||||
node1->mParent->mParent->mColor=nsNode::eRed;
|
||||
ShiftRight(*node1->mParent->mParent);
|
||||
}
|
||||
}
|
||||
else {
|
||||
node2=node1->mParent->mParent->mRight;
|
||||
if (node2->mColor==nsNode::eRed){
|
||||
node1->mParent->mColor=nsNode::eBlack;
|
||||
node2->mColor=nsNode::eBlack;
|
||||
node1->mParent->mParent->mColor=nsNode::eRed;
|
||||
node1=node1->mParent->mParent;
|
||||
}
|
||||
else {
|
||||
if (node1==node1->mParent->mLeft) {
|
||||
node1=node1->mParent;
|
||||
ShiftRight(*node1);
|
||||
}
|
||||
node1->mParent->mColor=nsNode::eBlack;
|
||||
node1->mParent->mParent->mColor=nsNode::eRed;
|
||||
ShiftLeft(*node1->mParent->mParent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mRoot->mColor=nsNode::eBlack;
|
||||
return &aNode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrive the first node in the tree
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsNode* nsRBTree::First(){
|
||||
nsNode* result=First(*mRoot);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the first node given a starting node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode --
|
||||
* @return node ptr or null
|
||||
*/
|
||||
nsNode* nsRBTree::First(nsNode& aNode){
|
||||
nsNode* result=0;
|
||||
|
||||
if(mRoot) {
|
||||
result=mRoot;
|
||||
while(result->GetLeftNode()) {
|
||||
result=result->GetLeftNode();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the last node in the tree
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return node ptr or null
|
||||
*/
|
||||
nsNode* nsRBTree::Last(){
|
||||
nsNode* result=Last(*mRoot);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the last node from a given node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode -- node ptr to start from
|
||||
* @return node ptr or null
|
||||
*/
|
||||
nsNode* nsRBTree::Last(nsNode& aNode){
|
||||
nsNode* result=0;
|
||||
|
||||
if(mRoot) {
|
||||
result=mRoot;
|
||||
while(result->GetRightNode()) {
|
||||
result=result->GetRightNode();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the node that preceeds the given node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode -- node to find precedent of
|
||||
* @return preceeding node ptr, or null
|
||||
*/
|
||||
nsNode* nsRBTree::Before(nsNode& aNode){
|
||||
|
||||
if(aNode.GetLeftNode())
|
||||
return Last(*aNode.GetLeftNode());
|
||||
|
||||
//otherwise...
|
||||
|
||||
nsNode* node1=&aNode;
|
||||
nsNode* node2=aNode.GetParentNode();
|
||||
|
||||
while((node2) && (node1==node2->GetLeftNode())) {
|
||||
node1=node2;
|
||||
node2=node2->GetParentNode();
|
||||
}
|
||||
return node2;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve a ptr to the node following the given node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode -- node to find successor node from
|
||||
* @return node ptr or null
|
||||
*/
|
||||
nsNode* nsRBTree::After(nsNode& aNode){
|
||||
|
||||
if(aNode.GetRightNode())
|
||||
return First(*aNode.GetRightNode());
|
||||
|
||||
//otherwise...
|
||||
|
||||
nsNode* node1=&aNode;
|
||||
nsNode* node2=aNode.GetParentNode();
|
||||
|
||||
while((node2) && (node1==node2->GetRightNode())) {
|
||||
node1=node2;
|
||||
node2=node2->GetParentNode();
|
||||
}
|
||||
|
||||
return node2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a (given) node in the tree
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param node to find in the tree
|
||||
* @return node ptr (if found) or null
|
||||
*/
|
||||
nsNode* nsRBTree::Find(nsNode& aNode){
|
||||
nsNode* result=mRoot;
|
||||
|
||||
while((result) && (!((*result)==aNode))) {
|
||||
if(aNode<*result)
|
||||
result=result->mLeft;
|
||||
else result=result->mRight;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Causes a shift to the left, to keep the
|
||||
* underlying RB data in balance
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return this
|
||||
*/
|
||||
nsRBTree& nsRBTree::ShiftLeft(nsNode& aNode){
|
||||
|
||||
nsNode* temp= aNode.mRight;
|
||||
|
||||
aNode.mRight=temp->mLeft;
|
||||
if(temp->mLeft)
|
||||
temp->mRight->mParent=&aNode;
|
||||
temp->mParent= aNode.mParent;
|
||||
if (aNode.mParent) {
|
||||
if (&aNode==aNode.mParent->mLeft)
|
||||
aNode.mParent->mLeft=temp;
|
||||
else aNode.mParent->mRight=temp;
|
||||
}
|
||||
else mRoot=temp;
|
||||
temp->mLeft=&aNode;;
|
||||
aNode.mParent=temp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes a shift right to occur, to keep the
|
||||
* underlying RB data in balance
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode -- node at which to perform shift
|
||||
* @return this
|
||||
*/
|
||||
nsRBTree& nsRBTree::ShiftRight(nsNode& aNode){
|
||||
|
||||
nsNode* temp=aNode.mLeft;
|
||||
|
||||
aNode.mLeft=temp->mRight;
|
||||
if(temp->mRight)
|
||||
temp->mRight->mParent=&aNode;
|
||||
temp->mParent=aNode.mParent;
|
||||
if(aNode.mParent){
|
||||
if(&aNode==aNode.mParent->mRight)
|
||||
aNode.mParent->mRight=temp;
|
||||
else aNode.mParent->mLeft=temp;
|
||||
}
|
||||
else mRoot=temp;
|
||||
temp->mRight=&aNode;
|
||||
aNode.mParent=temp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
nsBTree& nsRBTree::ReBalance(nsNode& aNode){
|
||||
|
||||
nsNode* node1=&aNode;
|
||||
nsNode* node2=0;
|
||||
|
||||
while ((node1!=mRoot) && (node1->mColor==nsNode::eBlack)) {
|
||||
if(node1==node1->mParent->mLeft) {
|
||||
node2=node1->mParent->mRight;
|
||||
if(node2->mColor==nsNode::eRed) {
|
||||
node2->mColor=nsNode::eBlack;
|
||||
node1->mParent->mColor=nsNode::eRed;
|
||||
ShiftLeft(*node1->mParent);
|
||||
node2=node1->mParent->mRight;
|
||||
}
|
||||
|
||||
if((node2->mLeft->mColor == nsNode::eBlack) &&
|
||||
(node2->mRight->mColor == nsNode::eBlack)) {
|
||||
node2->mColor=nsNode::eRed;
|
||||
node1=node1->mParent;
|
||||
}
|
||||
else {
|
||||
if(node2->mRight->mColor == nsNode::eBlack) {
|
||||
node2->mLeft->mColor=nsNode::eBlack;
|
||||
node2->mColor=nsNode::eRed;
|
||||
ShiftRight(*node2);
|
||||
node2=node1->mParent->mRight;
|
||||
}
|
||||
|
||||
node2->mColor=node1->mParent->mColor;
|
||||
node1->mParent->mColor=nsNode::eBlack;
|
||||
node2->mRight->mColor=nsNode::eBlack;
|
||||
ShiftLeft(*node1->mParent);
|
||||
node1=mRoot;
|
||||
} //else
|
||||
}
|
||||
else {
|
||||
node2=node1->mParent->mLeft;
|
||||
if(node2->mColor==nsNode::eRed) {
|
||||
node2->mColor=nsNode::eBlack;
|
||||
node1->mParent->mColor=nsNode::eRed;
|
||||
ShiftRight(*node1->mParent);
|
||||
node2=node1->mParent->mLeft;
|
||||
}
|
||||
|
||||
if((node2->mRight->mColor == nsNode::eBlack) &&
|
||||
(node2->mLeft->mColor == nsNode::eBlack)) {
|
||||
node2->mColor=nsNode::eRed;
|
||||
node1=node1->mParent;
|
||||
}
|
||||
else {
|
||||
if(node2->mLeft->mColor == nsNode::eBlack){
|
||||
node2->mRight->mColor=nsNode::eBlack;
|
||||
node2->mColor=nsNode::eRed;
|
||||
ShiftLeft(*node2);
|
||||
node2=node1->mParent->mLeft;
|
||||
}
|
||||
|
||||
node2->mColor=node1->mParent->mColor;
|
||||
node1->mParent->mColor=nsNode::eBlack;
|
||||
node2->mLeft->mColor=nsNode::eBlack;
|
||||
ShiftRight(*node1->mParent);
|
||||
node1=mRoot;
|
||||
} //else
|
||||
} //if
|
||||
} //while
|
||||
|
||||
node1->mColor=nsNode::eBlack;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**************************************************
|
||||
Here comes the nsRBTreeIterator class...
|
||||
*************************************************/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsRBTreeIterator::nsRBTreeIterator(const nsRBTree& aTree) : mTree(aTree) {
|
||||
}
|
||||
|
||||
/**
|
||||
* copy constructor
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aCopy is the object you want to copy from
|
||||
* @return newly constructed object
|
||||
*/
|
||||
nsRBTreeIterator::nsRBTreeIterator(const nsRBTreeIterator& aCopy) : mTree(aCopy.mTree) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor method
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
*/
|
||||
nsRBTreeIterator::~nsRBTreeIterator(){
|
||||
}
|
||||
|
||||
/**
|
||||
* This method iterates over the tree, calling
|
||||
* aFunctor for each node.
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aFunctor -- object to call for each node
|
||||
* @param aNode -- node at which to start iteration
|
||||
* @return this
|
||||
*/
|
||||
const nsRBTreeIterator& nsRBTreeIterator::ForEach(nsNodeFunctor& aFunctor) const{
|
||||
mTree.ForEach(aFunctor);
|
||||
return *this;
|
||||
}
|
||||
223
mozilla/base/src/nsRBTree.h
Normal file
223
mozilla/base/src/nsRBTree.h
Normal file
@@ -0,0 +1,223 @@
|
||||
|
||||
/**
|
||||
* This file defines the binary tree class and its
|
||||
* nsNode child class.
|
||||
*
|
||||
* This simple version stores nodes, and the
|
||||
* nodes store void* ptrs.
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
|
||||
/**
|
||||
* MODULE NOTES
|
||||
* @update gess 4/11/98
|
||||
*
|
||||
* This file declares the nsRBTree (red/black tree).
|
||||
* Red/black trees are auto-balancing binary trees.
|
||||
*
|
||||
* To use this class, define a subclass of nsNode
|
||||
* which stores your data type. It's important that
|
||||
* you overload the following methods:
|
||||
*
|
||||
* virtual PRBool operator<()
|
||||
* virtual PRBool operator==()
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _nsRBTree
|
||||
#define _nsRBTree
|
||||
|
||||
|
||||
#include "nsBTree.h"
|
||||
|
||||
|
||||
/**
|
||||
* Here comes the main event: our nsRBTree (red/black tree).
|
||||
* Red/Black trees are autobalancing binary trees.
|
||||
*
|
||||
* @update gess4/20/98
|
||||
*/
|
||||
|
||||
class NS_BASE nsRBTree : public nsBTree {
|
||||
public:
|
||||
friend class NS_BASE nsRBTreeIterator;
|
||||
|
||||
/**
|
||||
* nsRBTree constructor
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
*/
|
||||
nsRBTree();
|
||||
|
||||
/**
|
||||
* nsRBTree constructor
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
*/
|
||||
nsRBTree(const nsRBTree& aCopy);
|
||||
|
||||
/**
|
||||
* nsRBTree destructor
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
*/
|
||||
virtual ~nsRBTree();
|
||||
|
||||
/**
|
||||
* Given a node, we're supposed to add it into
|
||||
* our tree.
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsNode* Add(nsNode& aNode);
|
||||
|
||||
/**
|
||||
* Retrive the first node in the tree
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsNode* First(void);
|
||||
|
||||
/**
|
||||
* Retrieve the first node given a starting node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode --
|
||||
* @return node ptr or null
|
||||
*/
|
||||
nsNode* First(nsNode& aNode);
|
||||
|
||||
/**
|
||||
* Find the last node in the tree
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return node ptr or null
|
||||
*/
|
||||
nsNode* Last(void);
|
||||
|
||||
/**
|
||||
* Find the last node from a given node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode -- node ptr to start from
|
||||
* @return node ptr or null
|
||||
*/
|
||||
nsNode* Last(nsNode& aNode);
|
||||
|
||||
/**
|
||||
* Retrieve the node that preceeds the given node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode -- node to find precedent of
|
||||
* @return preceeding node ptr, or null
|
||||
*/
|
||||
nsNode* Before(nsNode& aNode);
|
||||
|
||||
/**
|
||||
* Retrieve a ptr to the node following the given node
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode -- node to find successor node from
|
||||
* @return node ptr or null
|
||||
*/
|
||||
nsNode* After(nsNode& aNode);
|
||||
|
||||
/**
|
||||
* Find a (given) node in the tree
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param node to find in the tree
|
||||
* @return node ptr (if found) or null
|
||||
*/
|
||||
nsNode* Find(nsNode& aNode);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Causes a shift to the left, to keep the
|
||||
* underlying RB data in balance
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return this
|
||||
*/
|
||||
nsRBTree& ShiftLeft(nsNode& aNode);
|
||||
|
||||
/**
|
||||
* Causes a shift right to occur, to keep the
|
||||
* underlying RB data in balance
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aNode -- node at which to perform shift
|
||||
* @return this
|
||||
*/
|
||||
nsRBTree& ShiftRight(nsNode& aNode);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
};
|
||||
|
||||
class NS_BASE nsRBTreeIterator {
|
||||
public:
|
||||
|
||||
/**
|
||||
* TreeIterator constructor
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsRBTreeIterator(const nsRBTree& aTree);
|
||||
|
||||
/**
|
||||
* TreeIterator constructor
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsRBTreeIterator(const nsRBTreeIterator& aCopy);
|
||||
|
||||
/**
|
||||
* tree iterator destructor
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
~nsRBTreeIterator();
|
||||
|
||||
/**
|
||||
* This method iterates over the tree, calling
|
||||
* aFunctor for each node.
|
||||
*
|
||||
* @update gess 4/11/98
|
||||
* @param aFunctor -- object to call for each node
|
||||
* @param aNode -- node at which to start iteration
|
||||
* @return this
|
||||
*/
|
||||
const nsRBTreeIterator& ForEach(nsNodeFunctor& aFunctor) const;
|
||||
|
||||
protected:
|
||||
const nsRBTree& mTree;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
121
mozilla/base/src/nsSizeOfHandler.cpp
Normal file
121
mozilla/base/src/nsSizeOfHandler.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
/* -*- 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 "nsISizeOfHandler.h"
|
||||
#include "plhash.h"
|
||||
|
||||
static NS_DEFINE_IID(kISizeOfHandlerIID, NS_ISIZEOF_HANDLER_IID);
|
||||
|
||||
class nsSizeOfHandler : public nsISizeOfHandler {
|
||||
public:
|
||||
nsSizeOfHandler();
|
||||
~nsSizeOfHandler();
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsISizeOfHandler
|
||||
NS_IMETHOD Add(size_t aSize);
|
||||
virtual PRBool HaveSeen(void* anObject);
|
||||
NS_IMETHOD GetSize(PRUint32& aResult);
|
||||
|
||||
protected:
|
||||
PRUint32 mTotalSize;
|
||||
PLHashTable* mTable;
|
||||
};
|
||||
|
||||
static PLHashNumber
|
||||
HashKey(void* key)
|
||||
{
|
||||
return (PLHashNumber) key;
|
||||
}
|
||||
|
||||
static PRIntn
|
||||
CompareKeys(void* key1, void* key2)
|
||||
{
|
||||
return key1 == key2;
|
||||
}
|
||||
|
||||
nsSizeOfHandler::nsSizeOfHandler()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mTotalSize = 0;
|
||||
mTable = PL_NewHashTable(8, (PLHashFunction) HashKey,
|
||||
(PLHashComparator) CompareKeys,
|
||||
(PLHashComparator) nsnull,
|
||||
nsnull, nsnull);
|
||||
}
|
||||
|
||||
nsSizeOfHandler::~nsSizeOfHandler()
|
||||
{
|
||||
if (nsnull != mTable) {
|
||||
PL_HashTableDestroy(mTable);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsSizeOfHandler, kISizeOfHandlerIID)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSizeOfHandler::Add(size_t aSize)
|
||||
{
|
||||
mTotalSize += aSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsSizeOfHandler::HaveSeen(void* anObject)
|
||||
{
|
||||
if (nsnull == mTable) {
|
||||
// When we run out of memory, HaveSeen returns PR_TRUE to stop
|
||||
// wasting time.
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
if (nsnull != anObject) {
|
||||
PRInt32 hashCode = (PRInt32) anObject;
|
||||
PLHashEntry** hep = PL_HashTableRawLookup(mTable, hashCode, anObject);
|
||||
PLHashEntry* he = *hep;
|
||||
if (nsnull != he) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
he = PL_HashTableRawAdd(mTable, hep, hashCode, anObject, anObject);
|
||||
if (nsnull == he) {
|
||||
// When we run out of memory, HaveSeen returns PR_TRUE to stop
|
||||
// wasting time.
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSizeOfHandler::GetSize(PRUint32& aResult)
|
||||
{
|
||||
aResult = mTotalSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_BASE nsresult
|
||||
NS_NewSizeOfHandler(nsISizeOfHandler** aInstancePtrResult)
|
||||
{
|
||||
nsISizeOfHandler *it = new nsSizeOfHandler();
|
||||
if (it == nsnull) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(kISizeOfHandlerIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
2217
mozilla/base/src/nsString.cpp
Normal file
2217
mozilla/base/src/nsString.cpp
Normal file
File diff suppressed because it is too large
Load Diff
790
mozilla/base/src/nsString.h
Normal file
790
mozilla/base/src/nsString.h
Normal file
@@ -0,0 +1,790 @@
|
||||
/* -*- 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:
|
||||
|
||||
A. There are two philosophies to building string classes:
|
||||
1. Hide the underlying buffer & offer API's allow indirect iteration
|
||||
2. Reveal underlying buffer, risk corruption, but gain performance
|
||||
|
||||
We chose the second option for performance reasons.
|
||||
|
||||
B Our internal buffer always holds capacity+1 bytes.
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _NSSTRING
|
||||
#define _NSSTRING
|
||||
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
#include "nsIAtom.h"
|
||||
#include <iostream.h>
|
||||
#include <stdio.h>
|
||||
class nsISizeOfHandler;
|
||||
|
||||
class NS_BASE nsString {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default constructor. Note that we actually allocate a small buffer
|
||||
* to begin with. This is because the "philosophy" of the string class
|
||||
* was to allow developers direct access to the underlying buffer for
|
||||
* performance reasons.
|
||||
*/
|
||||
nsString();
|
||||
|
||||
/**
|
||||
* This constructor accepts an isolatin string
|
||||
* @param anISOLatin1 is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsString(const char* anISOLatin1);
|
||||
|
||||
/**
|
||||
* This is our copy constructor
|
||||
* @param reference to another nsString
|
||||
*/
|
||||
nsString(const nsString&);
|
||||
|
||||
/**
|
||||
* Constructor from a unicode string
|
||||
* @param anicodestr pts to a unicode string
|
||||
*/
|
||||
nsString(const PRUnichar* aUnicode);
|
||||
|
||||
/**
|
||||
* Virtual Destructor
|
||||
*/
|
||||
virtual ~nsString();
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the length of this string
|
||||
* @return string length
|
||||
*/
|
||||
PRInt32 Length() const { return mLength; }
|
||||
|
||||
|
||||
/**
|
||||
* Sets the new length of the string.
|
||||
* @param aLength is new string length.
|
||||
* @return nada
|
||||
*/
|
||||
void SetLength(PRInt32 aLength);
|
||||
|
||||
/**
|
||||
* This method truncates this string to given length.
|
||||
*
|
||||
* @param anIndex -- new length of string
|
||||
* @return nada
|
||||
*/
|
||||
void Truncate(PRInt32 anIndex=0);
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called when the internal buffer needs
|
||||
* to grow to a given size.
|
||||
* @param aNewLength -- new capacity of string
|
||||
* @return void
|
||||
*/
|
||||
virtual void EnsureCapacityFor(PRInt32 aNewLength);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
virtual void SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
/**
|
||||
* Determine whether or not the characters in this
|
||||
* string are in sorted order.
|
||||
*
|
||||
* @return TRUE if ordered.
|
||||
*/
|
||||
PRBool IsOrdered(void) const;
|
||||
|
||||
/**********************************************************************
|
||||
Accessor methods...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* Retrieve pointer to internal string value
|
||||
* @return PRUnichar* to internal string
|
||||
*/
|
||||
const PRUnichar* GetUnicode(void) const;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
operator PRUnichar*() const;
|
||||
|
||||
/**
|
||||
* Retrieve unicode char at given index
|
||||
* @param offset into string
|
||||
* @return PRUnichar* to internal string
|
||||
*/
|
||||
PRUnichar operator()(PRInt32 anIndex) const;
|
||||
|
||||
/**
|
||||
* Retrieve reference to unicode char at given index
|
||||
* @param offset into string
|
||||
* @return PRUnichar& from internal string
|
||||
*/
|
||||
PRUnichar& operator[](PRInt32 anIndex) const;
|
||||
|
||||
/**
|
||||
* Retrieve reference to unicode char at given index
|
||||
* @param offset into string
|
||||
* @return PRUnichar& from internal string
|
||||
*/
|
||||
PRUnichar& CharAt(PRInt32 anIndex) const;
|
||||
|
||||
/**
|
||||
* Retrieve reference to first unicode char in string
|
||||
* @return PRUnichar from internal string
|
||||
*/
|
||||
PRUnichar& First() const;
|
||||
|
||||
/**
|
||||
* Retrieve reference to last unicode char in string
|
||||
* @return PRUnichar from internal string
|
||||
*/
|
||||
PRUnichar& Last() const;
|
||||
|
||||
/**********************************************************************
|
||||
String creation methods...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* Create a new string by appending given string to this
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString operator+(const nsString& aString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given buffer.
|
||||
* @param anISOLatin1 is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(const char* anISOLatin1);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(char aChar);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given buffer.
|
||||
* @param aStr unichar buffer to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Converts all chars in internal string to lower
|
||||
*/
|
||||
void ToLowerCase();
|
||||
|
||||
/**
|
||||
* Converts all chars in given string to lower
|
||||
*/
|
||||
void ToLowerCase(nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Converts all chars in given string to upper
|
||||
*/
|
||||
void ToUpperCase();
|
||||
|
||||
/**
|
||||
* Converts all chars in internal string to upper
|
||||
*/
|
||||
void ToUpperCase(nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Creates a duplicate clone (ptr) of this string.
|
||||
* @return ptr to clone of this string
|
||||
*/
|
||||
nsString* ToNewString() const;
|
||||
|
||||
/**
|
||||
* Creates an ISOLatin1 clone of this string
|
||||
* @return ptr to new isolatin1 string
|
||||
*/
|
||||
char* ToNewCString() const;
|
||||
|
||||
/**
|
||||
* Copies data from internal buffer onto given char* buffer
|
||||
* @param aBuf is the buffer where data is stored
|
||||
* @param aBuflength is the max # of chars to move to buffer
|
||||
* @return ptr to given buffer
|
||||
*/
|
||||
char* ToCString(char* aBuf,PRInt32 aBufLength) const;
|
||||
|
||||
/**
|
||||
* Copies contents of this onto given string.
|
||||
* @param aString to hold copy of this
|
||||
* @return nada.
|
||||
*/
|
||||
void Copy(nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Creates an unichar clone of this string
|
||||
* @return ptr to new unichar string
|
||||
*/
|
||||
PRUnichar* ToNewUnicode() const;
|
||||
|
||||
/**
|
||||
* Perform string to float conversion.
|
||||
* @param aErrorCode will contain error if one occurs
|
||||
* @return float rep of string value
|
||||
*/
|
||||
float ToFloat(PRInt32* aErrorCode) const;
|
||||
|
||||
/**
|
||||
* Perform string to int conversion.
|
||||
* @param aErrorCode will contain error if one occurs
|
||||
* @return int rep of string value
|
||||
*/
|
||||
PRInt32 ToInteger(PRInt32* aErrorCode,PRInt32 aRadix=10) const;
|
||||
|
||||
/**********************************************************************
|
||||
String manipulation methods...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* assign given PRUnichar* to this string
|
||||
* @param anISOLatin1: buffer to be assigned to this
|
||||
* @param alength is the length of the given str (or -1)
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* assign given char* to this string
|
||||
* @param anISOLatin1: buffer to be assigned to this
|
||||
* @param alength is the length of the given str (or -1)
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& SetString(const char* anISOLatin1,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* assign given string to this one
|
||||
* @param aString: string to be added to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(const nsString& aString);
|
||||
|
||||
/**
|
||||
* assign given char* to this string
|
||||
* @param anISOLatin1: buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(const char* anISOLatin1);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(char aChar);
|
||||
|
||||
/**
|
||||
* assign given unichar* to this string
|
||||
* @param aBuffer: unichar buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(const nsString& aString);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param anISOLatin1: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(const char* anISOLatin1);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param aBuffer: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* append given char to this string
|
||||
* @param aChar: char to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @param alength is the length of the given str (or -1)
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(const nsString& aString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @param alength is the length of the given str (or -1)
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(const char* anISOLatin1,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(char aChar);
|
||||
|
||||
/**
|
||||
* append given unichar buffer to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @param alength is the length of the given str (or -1)
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(const PRUnichar* aBuffer,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given unichar character to this string
|
||||
* @param aChar is the char to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Append an integer onto this string
|
||||
* @param aInteger is the int to be appended
|
||||
* @param aRadix specifies 8,10,16
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(PRInt32 aInteger,PRInt32 aRadix); //radix=8,10 or 16
|
||||
|
||||
/**
|
||||
* Append a float value onto this string
|
||||
* @param aFloat is the float to be appended
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(float aFloat);
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
* starting at the leftmost offset.
|
||||
*
|
||||
*
|
||||
* @param aCopy -- Receiving string
|
||||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Left(nsString& aCopy,PRInt32 aCount);
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
* starting at the given offset.
|
||||
*
|
||||
*
|
||||
* @param aCopy -- Receiving string
|
||||
* @param aCount -- number of chars to copy
|
||||
* @param anOffset -- position where copying begins
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Mid(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount);
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
* starting at rightmost char.
|
||||
*
|
||||
*
|
||||
* @param aCopy -- Receiving string
|
||||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Right(nsString& aCopy,PRInt32 aCount);
|
||||
|
||||
/*
|
||||
* This method inserts n chars from given string into this
|
||||
* string at str[anOffset].
|
||||
*
|
||||
* @param aCopy -- String to be inserted into this
|
||||
* @param anOffset -- insertion position within this str
|
||||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
PRInt32 Insert(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a single unicode char into this string at
|
||||
* a specified offset.
|
||||
*
|
||||
* @param aChar char to be inserted into this string
|
||||
* @param anOffset is insert pos in str
|
||||
* @return the number of chars inserted into this string
|
||||
*/
|
||||
PRInt32 Insert(PRUnichar aChar,PRInt32 anOffset);
|
||||
|
||||
/*
|
||||
* This method is used to cut characters in this string
|
||||
* starting at anOffset, continuing for aCount chars.
|
||||
*
|
||||
* @param anOffset -- start pos for cut operation
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
nsString& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
|
||||
/**
|
||||
* This method is used to remove all occurances of the
|
||||
* characters found in aSet from this string.
|
||||
*
|
||||
* @param aSet -- characters to be cut from this
|
||||
* @return *this
|
||||
*/
|
||||
nsString& StripChars(const char* aSet);
|
||||
|
||||
/**
|
||||
* This method strips whitespace throughout the string
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
nsString& StripWhitespace();
|
||||
|
||||
/**
|
||||
* This method trims characters found in aTrimSet from
|
||||
* either end of the underlying string.
|
||||
*
|
||||
* @param aTrimSet -- contains chars to be trimmed from
|
||||
* both ends
|
||||
* @return this
|
||||
*/
|
||||
nsString& Trim(const char* aSet,
|
||||
PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**
|
||||
* This method strips whitespace from string.
|
||||
* You can control whether whitespace is yanked from
|
||||
* start and end of string as well.
|
||||
*
|
||||
* @param aEliminateLeading controls stripping of leading ws
|
||||
* @param aEliminateTrailing controls stripping of trailing ws
|
||||
* @return this
|
||||
*/
|
||||
nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**
|
||||
* Determine if given char is a valid space character
|
||||
*
|
||||
* @param aChar is character to be tested
|
||||
* @return TRUE if is valid space char
|
||||
*/
|
||||
static PRBool IsSpace(PRUnichar ch);
|
||||
|
||||
/**
|
||||
* Determine if given char in valid alpha range
|
||||
*
|
||||
* @param aChar is character to be tested
|
||||
* @return TRUE if in alpha range
|
||||
*/
|
||||
static PRBool IsAlpha(PRUnichar ch);
|
||||
|
||||
/**
|
||||
* Determine if given char is valid digit
|
||||
*
|
||||
* @param aChar is character to be tested
|
||||
* @return TRUE if char is a valid digit
|
||||
*/
|
||||
static PRBool IsDigit(PRUnichar ch);
|
||||
|
||||
/**********************************************************************
|
||||
Searching methods...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* Search for given character within this string.
|
||||
* This method does so by using a binary search,
|
||||
* so your string HAD BETTER BE ORDERED!
|
||||
*
|
||||
* @param aChar is the unicode char to be found
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 BinarySearch(PRUnichar aChar) const;
|
||||
|
||||
/**
|
||||
* Search for given substring within this string
|
||||
*
|
||||
* @param aString is substring to be sought in this
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 Find(const char* aString) const;
|
||||
PRInt32 Find(const PRUnichar* aString) const;
|
||||
PRInt32 Find(const nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Search for given char within this string
|
||||
*
|
||||
* @param aChar - char to be found
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 Find(PRUnichar aChar,PRInt32 offset=0) const;
|
||||
|
||||
/**
|
||||
* This method searches this string for the first character
|
||||
* found in the given string
|
||||
* @param aString contains set of chars to be found
|
||||
* @param anOffset tells us where to start searching in this
|
||||
* @return -1 if not found, else the offset in this
|
||||
*/
|
||||
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 FindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
/**
|
||||
* This method searches this string for the last character
|
||||
* found in the given string
|
||||
* @param aString contains set of chars to be found
|
||||
* @param anOffset tells us where to start searching in this
|
||||
* @return -1 if not found, else the offset in this
|
||||
*/
|
||||
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 RFindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
|
||||
/**
|
||||
* This methods scans the string backwards, looking for the given string
|
||||
* @param aString is substring to be sought in this
|
||||
* @param aIgnoreCase tells us whether or not to do caseless compare
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 RFind(const char* anISOLatin1,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
|
||||
/**
|
||||
* This methods scans the string backwards, looking for the given char
|
||||
* @param char is the char to be sought in this
|
||||
* @param aIgnoreCase tells us whether or not to do caseless compare
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 RFind(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
|
||||
/**********************************************************************
|
||||
Comparison methods...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* Compares a given string type to this string.
|
||||
* @update gess 7/27/98
|
||||
* @param S is the string to be compared
|
||||
* @param aIgnoreCase tells us how to treat case
|
||||
* @return -1,0,1
|
||||
*/
|
||||
virtual PRInt32 Compare(const nsString &aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
virtual PRInt32 Compare(const char *aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
|
||||
virtual PRInt32 Compare(const PRUnichar *aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
|
||||
|
||||
/**
|
||||
* These methods compare a given string type to this one
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator==(const nsString &aString) const;
|
||||
PRBool operator==(const char *aString) const;
|
||||
PRBool operator==(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods perform a !compare of a given string type to this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE
|
||||
*/
|
||||
PRBool operator!=(const nsString &aString) const;
|
||||
PRBool operator!=(const char *aString) const;
|
||||
PRBool operator!=(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods test if a given string is < than this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator<(const nsString &aString) const;
|
||||
PRBool operator<(const char *aString) const;
|
||||
PRBool operator<(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods test if a given string is > than this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator>(const nsString &S) const;
|
||||
PRBool operator>(const char *anISOLatin1) const;
|
||||
PRBool operator>(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods test if a given string is <= than this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator<=(const nsString &S) const;
|
||||
PRBool operator<=(const char *anISOLatin1) const;
|
||||
PRBool operator<=(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods test if a given string is >= than this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator>=(const nsString &S) const;
|
||||
PRBool operator>=(const char *anISOLatin1) const;
|
||||
PRBool operator>=(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* Compare this to given string; note that we compare full strings here.
|
||||
* The optional length argument just lets us know how long the given string is.
|
||||
* If you provide a length, it is compared to length of this string as an
|
||||
* optimization.
|
||||
*
|
||||
* @param aString -- the string to compare to this
|
||||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool Equals(const nsString& aString) const;
|
||||
PRBool Equals(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool Equals(const nsIAtom *aAtom) const;
|
||||
|
||||
|
||||
/**
|
||||
* Compares to unichar string ptrs to each other
|
||||
* @param s1 is a ptr to a unichar buffer
|
||||
* @param s2 is a ptr to a unichar buffer
|
||||
* @return TRUE if they match
|
||||
*/
|
||||
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2) const;
|
||||
|
||||
/**
|
||||
* Compare this to given string; note that we compare full strings here.
|
||||
* The optional length argument just lets us know how long the given string is.
|
||||
* If you provide a length, it is compared to length of this string as an
|
||||
* optimization.
|
||||
*
|
||||
* @param aString -- the string to compare to this
|
||||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool EqualsIgnoreCase(const nsString& aString) const;
|
||||
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
|
||||
|
||||
/**
|
||||
* Compares to unichar string ptrs to each other without respect to case
|
||||
* @param s1 is a ptr to a unichar buffer
|
||||
* @param s2 is a ptr to a unichar buffer
|
||||
* @return TRUE if they match
|
||||
*/
|
||||
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
|
||||
|
||||
|
||||
static void SelfTest();
|
||||
virtual void DebugDump(ostream& aStream) const;
|
||||
|
||||
protected:
|
||||
|
||||
typedef PRUnichar chartype;
|
||||
|
||||
chartype* mStr;
|
||||
PRInt32 mLength;
|
||||
PRInt32 mCapacity;
|
||||
static PRBool mSelfTested;
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsString& aString);
|
||||
extern NS_BASE int fputs(const nsString& aString, FILE* out);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A version of nsString which is designed to be used as an automatic
|
||||
* variable. It attempts to operate out of a fixed size internal
|
||||
* buffer until too much data is added; then a dynamic buffer is
|
||||
* allocated and grown as necessary.
|
||||
*/
|
||||
// XXX template this with a parameter for the size of the buffer?
|
||||
class NS_BASE nsAutoString : public nsString {
|
||||
public:
|
||||
nsAutoString();
|
||||
nsAutoString(const nsString& other);
|
||||
nsAutoString(const nsAutoString& other);
|
||||
nsAutoString(PRUnichar aChar);
|
||||
nsAutoString(const char* isolatin1);
|
||||
nsAutoString(const PRUnichar* us, PRInt32 uslen = -1);
|
||||
virtual ~nsAutoString();
|
||||
|
||||
nsAutoString& operator=(const nsString& aString) {nsString::operator=(aString); return *this;}
|
||||
nsAutoString& operator=(const char* anISOLatin1) {nsString::operator=(anISOLatin1); return *this;}
|
||||
nsAutoString& operator=(char aChar) {nsString::operator=(aChar); return *this;}
|
||||
nsAutoString& operator=(const PRUnichar* aBuffer) {nsString::operator=(aBuffer); return *this;}
|
||||
nsAutoString& operator=(PRUnichar aChar) {nsString::operator=(aChar); return *this;}
|
||||
|
||||
virtual void SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
static void SelfTest();
|
||||
|
||||
protected:
|
||||
virtual void EnsureCapacityFor(PRInt32 aNewLength);
|
||||
|
||||
chartype mBuf[32];
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsAutoString& aString);
|
||||
|
||||
#endif
|
||||
|
||||
179
mozilla/base/src/nsTime.h
Normal file
179
mozilla/base/src/nsTime.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.
|
||||
*/
|
||||
|
||||
#ifndef nsTime_h__
|
||||
#define nsTime_h__
|
||||
|
||||
#include "prtime.h"
|
||||
#include "nsInt64.h"
|
||||
#include "nscore.h"
|
||||
|
||||
/**
|
||||
* This class encapsulates full 64-bit time functionality and
|
||||
* provides simple arithmetic and conversion operations.
|
||||
*/
|
||||
class NS_BASE nsTime
|
||||
{
|
||||
private:
|
||||
nsInt64 mValue;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Construct the current time.
|
||||
*/
|
||||
nsTime(void) : mValue(PR_Now()) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a time from a PRTime.
|
||||
*/
|
||||
nsTime(const PRTime aTime) : mValue(aTime) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a time from a 64-bit value.
|
||||
*/
|
||||
nsTime(const nsInt64& aTime) : mValue(aTime) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a time from another time.
|
||||
*/
|
||||
nsTime(const nsTime& aTime) : mValue(aTime.mValue) {
|
||||
}
|
||||
|
||||
// ~nsTime(void) -- XXX destructor unnecessary
|
||||
|
||||
/**
|
||||
* Assign one time to another.
|
||||
*/
|
||||
const nsTime& operator =(const nsTime& aTime) {
|
||||
mValue = aTime.mValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a nsTime object to a PRTime
|
||||
*/
|
||||
operator PRTime(void) const {
|
||||
return mValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract a 64-bit interval from a time.
|
||||
*/
|
||||
nsTime& operator -=(const nsInt64& aInterval) {
|
||||
mValue -= aInterval;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a 64-bit interval to a time.
|
||||
*/
|
||||
nsTime& operator +=(const nsInt64& aInterval) {
|
||||
mValue += aInterval;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Arithmetic operators
|
||||
friend const nsTime operator +(const nsTime& aTime, const nsInt64& aInterval);
|
||||
friend const nsTime operator -(const nsTime& aTime, const nsInt64& aInterval);
|
||||
friend const nsInt64 operator -(const nsTime& aTime1, const nsTime& aTime2);
|
||||
|
||||
// Comparison operators
|
||||
friend const PRBool operator ==(const nsTime& aTime1, const nsTime& aTime2);
|
||||
friend const PRBool operator !=(const nsTime& aTime1, const nsTime& aTime2);
|
||||
friend const PRBool operator <(const nsTime& aTime1, const nsTime& aTime2);
|
||||
friend const PRBool operator <=(const nsTime& aTime1, const nsTime& aTime2);
|
||||
friend const PRBool operator >(const nsTime& aTime1, const nsTime& aTime2);
|
||||
friend const PRBool operator >=(const nsTime& aTime1, const nsTime& aTime2);
|
||||
};
|
||||
|
||||
/**
|
||||
* Binary addition to add a 64-bit interval to a time.
|
||||
*/
|
||||
inline const nsTime
|
||||
operator +(const nsTime& aTime, const nsInt64& aInterval) {
|
||||
return nsTime(aTime.mValue + aInterval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Binary subtraction to subtract a 64-bit interval to a time.
|
||||
*/
|
||||
inline const nsTime
|
||||
operator -(const nsTime& aTime, const nsInt64& aInterval) {
|
||||
return nsTime(aTime.mValue - aInterval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Binary subtraction to compute an interval from the difference of two times.
|
||||
*/
|
||||
inline const nsInt64
|
||||
operator -(const nsTime& aTime1, const nsTime& aTime2) {
|
||||
return aTime1.mValue - aTime2.mValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if two times are equal
|
||||
*/
|
||||
inline const PRBool
|
||||
operator ==(const nsTime& aTime1, const nsTime& aTime2) {
|
||||
return aTime1.mValue == aTime2.mValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if two times are different
|
||||
*/
|
||||
inline const PRBool
|
||||
operator !=(const nsTime& aTime1, const nsTime& aTime2) {
|
||||
return aTime1.mValue != aTime2.mValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if one time is strictly less than another
|
||||
*/
|
||||
inline const PRBool
|
||||
operator <(const nsTime& aTime1, const nsTime& aTime2) {
|
||||
return aTime1.mValue < aTime2.mValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if one time is less than or equal to another
|
||||
*/
|
||||
inline const PRBool
|
||||
operator <=(const nsTime& aTime1, const nsTime& aTime2) {
|
||||
return aTime1.mValue <= aTime2.mValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if one time is strictly greater than another
|
||||
*/
|
||||
inline const PRBool
|
||||
operator >(const nsTime& aTime1, const nsTime& aTime2) {
|
||||
return aTime1.mValue > aTime2.mValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if one time is greater than or equal to another
|
||||
*/
|
||||
inline const PRBool
|
||||
operator >=(const nsTime& aTime1, const nsTime& aTime2) {
|
||||
return aTime1.mValue >= aTime2.mValue;
|
||||
}
|
||||
|
||||
#endif // nsTime_h__
|
||||
140
mozilla/base/src/nsUnicharBuffer.cpp
Normal file
140
mozilla/base/src/nsUnicharBuffer.cpp
Normal file
@@ -0,0 +1,140 @@
|
||||
/* -*- 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 "nsIUnicharBuffer.h"
|
||||
#include "nsIUnicharInputStream.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
#define MIN_BUFFER_SIZE 32
|
||||
|
||||
class UnicharBufferImpl : public nsIUnicharBuffer {
|
||||
public:
|
||||
UnicharBufferImpl(PRInt32 aBufferSize);
|
||||
~UnicharBufferImpl();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
virtual PRInt32 GetLength() const;
|
||||
virtual PRInt32 GetBufferSize() const;
|
||||
virtual PRUnichar* GetBuffer() const;
|
||||
virtual PRBool Grow(PRInt32 aNewSize);
|
||||
virtual PRInt32 Fill(nsresult* aErrorCode, nsIUnicharInputStream* aStream,
|
||||
PRInt32 aKeep);
|
||||
|
||||
PRUnichar* mBuffer;
|
||||
PRInt32 mSpace;
|
||||
PRInt32 mLength;
|
||||
};
|
||||
|
||||
UnicharBufferImpl::UnicharBufferImpl(PRInt32 aBufferSize)
|
||||
{
|
||||
if (PRUint32(aBufferSize) < MIN_BUFFER_SIZE) {
|
||||
aBufferSize = MIN_BUFFER_SIZE;
|
||||
}
|
||||
mSpace = aBufferSize;
|
||||
mBuffer = new PRUnichar[aBufferSize];
|
||||
mLength = 0;
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
NS_DEFINE_IID(kUnicharBufferIID, NS_IUNICHAR_BUFFER_IID);
|
||||
NS_IMPL_ISUPPORTS(UnicharBufferImpl,kUnicharBufferIID)
|
||||
|
||||
UnicharBufferImpl::~UnicharBufferImpl()
|
||||
{
|
||||
if (nsnull != mBuffer) {
|
||||
delete mBuffer;
|
||||
mBuffer = nsnull;
|
||||
}
|
||||
mLength = 0;
|
||||
}
|
||||
|
||||
PRInt32 UnicharBufferImpl::GetLength() const
|
||||
{
|
||||
return mLength;
|
||||
}
|
||||
|
||||
PRInt32 UnicharBufferImpl::GetBufferSize() const
|
||||
{
|
||||
return mSpace;
|
||||
}
|
||||
|
||||
PRUnichar* UnicharBufferImpl::GetBuffer() const
|
||||
{
|
||||
return mBuffer;
|
||||
}
|
||||
|
||||
PRBool UnicharBufferImpl::Grow(PRInt32 aNewSize)
|
||||
{
|
||||
if (PRUint32(aNewSize) < MIN_BUFFER_SIZE) {
|
||||
aNewSize = MIN_BUFFER_SIZE;
|
||||
}
|
||||
PRUnichar* newbuf = new PRUnichar[aNewSize];
|
||||
if (nsnull != newbuf) {
|
||||
if (0 != mLength) {
|
||||
nsCRT::memcpy(newbuf, mBuffer, mLength * sizeof(PRUnichar));
|
||||
}
|
||||
delete mBuffer;
|
||||
mBuffer = newbuf;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRInt32 UnicharBufferImpl::Fill(nsresult* aErrorCode,
|
||||
nsIUnicharInputStream* aStream,
|
||||
PRInt32 aKeep)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aStream, "null stream");
|
||||
NS_PRECONDITION(PRUint32(aKeep) < PRUint32(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 * sizeof(PRUnichar));
|
||||
}
|
||||
|
||||
// Read in some new data
|
||||
mLength = aKeep;
|
||||
PRInt32 amount = mSpace - aKeep;
|
||||
PRInt32 nb;
|
||||
*aErrorCode = aStream->Read(mBuffer, aKeep, amount, &nb);
|
||||
if (NS_SUCCEEDED(*aErrorCode)) {
|
||||
mLength += nb;
|
||||
}
|
||||
else
|
||||
nb = 0;
|
||||
return nb;
|
||||
}
|
||||
|
||||
NS_BASE nsresult NS_NewUnicharBuffer(nsIUnicharBuffer** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
PRInt32 aBufferSize)
|
||||
{
|
||||
if (nsnull != aOuter) {
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
UnicharBufferImpl* it = new UnicharBufferImpl(aBufferSize);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(kUnicharBufferIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
337
mozilla/base/src/nsUnicharInputStream.cpp
Normal file
337
mozilla/base/src/nsUnicharInputStream.cpp
Normal file
@@ -0,0 +1,337 @@
|
||||
/* -*- 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 "nsIUnicharInputStream.h"
|
||||
#include "nsIByteBuffer.h"
|
||||
#include "nsIUnicharBuffer.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCRT.h"
|
||||
#include <fcntl.h>
|
||||
#ifdef NS_WIN32
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
static NS_DEFINE_IID(kIUnicharInputStreamIID, NS_IUNICHAR_INPUT_STREAM_IID);
|
||||
|
||||
class StringUnicharInputStream : public nsIUnicharInputStream {
|
||||
public:
|
||||
StringUnicharInputStream(nsString* aString);
|
||||
~StringUnicharInputStream();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Read(PRUnichar* aBuf,
|
||||
PRInt32 aOffset,
|
||||
PRInt32 aCount,
|
||||
PRInt32 *aReadCount);
|
||||
NS_IMETHOD Close();
|
||||
|
||||
nsString* mString;
|
||||
PRInt32 mPos;
|
||||
PRInt32 mLen;
|
||||
};
|
||||
|
||||
StringUnicharInputStream::StringUnicharInputStream(nsString* aString)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mString = aString;
|
||||
mPos = 0;
|
||||
mLen = aString->Length();
|
||||
}
|
||||
|
||||
StringUnicharInputStream::~StringUnicharInputStream()
|
||||
{
|
||||
if (nsnull != mString) {
|
||||
delete mString;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult StringUnicharInputStream::Read(PRUnichar* aBuf,
|
||||
PRInt32 aOffset,
|
||||
PRInt32 aCount,
|
||||
PRInt32 *aReadCount)
|
||||
{
|
||||
if (mPos >= mLen) {
|
||||
*aReadCount = 0;
|
||||
return (nsresult)-1;
|
||||
}
|
||||
const PRUnichar* us = mString->GetUnicode();
|
||||
PRInt32 amount = mLen - mPos;
|
||||
if (amount > aCount) {
|
||||
amount = aCount;
|
||||
}
|
||||
nsCRT::memcpy(aBuf + aOffset, us + mPos, sizeof(PRUnichar) * amount);
|
||||
mPos += amount;
|
||||
*aReadCount = amount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult StringUnicharInputStream::Close()
|
||||
{
|
||||
mPos = mLen;
|
||||
if (nsnull != mString) {
|
||||
delete mString;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(StringUnicharInputStream, kIUnicharInputStreamIID);
|
||||
|
||||
NS_BASE nsresult
|
||||
NS_NewStringUnicharInputStream(nsIUnicharInputStream** aInstancePtrResult,
|
||||
nsString* aString)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aString, "null ptr");
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
||||
if ((nsnull == aString) || (nsnull == aInstancePtrResult)) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
StringUnicharInputStream* it = new StringUnicharInputStream(aString);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return it->QueryInterface(kIUnicharInputStreamIID,
|
||||
(void**) aInstancePtrResult);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class IsoLatin1Converter : public nsIB2UConverter {
|
||||
public:
|
||||
IsoLatin1Converter();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
virtual PRInt32 Convert(PRUnichar* aDst,
|
||||
PRInt32 aDstOffset,
|
||||
PRInt32& aDstLen,
|
||||
const char* aSrc,
|
||||
PRInt32 aSrcOffset,
|
||||
PRInt32& aSrcLen);
|
||||
};
|
||||
|
||||
IsoLatin1Converter::IsoLatin1Converter()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
NS_DEFINE_IID(kIB2UConverterIID, NS_IB2UCONVERTER_IID);
|
||||
NS_IMPL_ISUPPORTS(IsoLatin1Converter,kIB2UConverterIID);
|
||||
|
||||
PRInt32 IsoLatin1Converter::Convert(PRUnichar* aDst,
|
||||
PRInt32 aDstOffset,
|
||||
PRInt32& aDstLen,
|
||||
const char* aSrc,
|
||||
PRInt32 aSrcOffset,
|
||||
PRInt32& aSrcLen)
|
||||
{
|
||||
PRInt32 amount = aSrcLen;
|
||||
if (aSrcLen > aDstLen) {
|
||||
amount = aDstLen;
|
||||
}
|
||||
const char* end = aSrc + amount;
|
||||
while (aSrc < end) {
|
||||
PRUint8 isoLatin1 = PRUint8(*aSrc++);
|
||||
/* XXX insert table based lookup converter here */
|
||||
*aDst++ = isoLatin1;
|
||||
}
|
||||
aDstLen = amount;
|
||||
aSrcLen = amount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_BASE nsresult
|
||||
NS_NewB2UConverter(nsIB2UConverter** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
nsCharSetID aCharSet)
|
||||
{
|
||||
if (nsnull != aOuter) {
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
if (eCharSetID_IsoLatin1 != aCharSet) {
|
||||
return NS_BASE_STREAM_NO_CONVERTER;
|
||||
}
|
||||
IsoLatin1Converter* it = new IsoLatin1Converter();
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(kIB2UConverterIID, (void**)aInstancePtrResult);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class ConverterInputStream : public nsIUnicharInputStream {
|
||||
public:
|
||||
ConverterInputStream(nsIInputStream* aStream,
|
||||
nsIB2UConverter* aConverter,
|
||||
PRInt32 aBufSize);
|
||||
~ConverterInputStream();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_IMETHOD Read(PRUnichar* aBuf,
|
||||
PRInt32 aOffset,
|
||||
PRInt32 aCount,
|
||||
PRInt32 *aReadCount);
|
||||
NS_IMETHOD Close();
|
||||
|
||||
protected:
|
||||
PRInt32 Fill(nsresult * aErrorCode);
|
||||
|
||||
nsIInputStream* mInput;
|
||||
nsIB2UConverter* mConverter;
|
||||
nsIByteBuffer* mByteData;
|
||||
PRInt32 mByteDataOffset;
|
||||
nsIUnicharBuffer* mUnicharData;
|
||||
PRInt32 mUnicharDataOffset;
|
||||
PRInt32 mUnicharDataLength;
|
||||
};
|
||||
|
||||
ConverterInputStream::ConverterInputStream(nsIInputStream* aStream,
|
||||
nsIB2UConverter* aConverter,
|
||||
PRInt32 aBufferSize)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mInput = aStream; aStream->AddRef();
|
||||
mConverter = aConverter; aConverter->AddRef();
|
||||
if (aBufferSize == 0) {
|
||||
aBufferSize = 8192;
|
||||
}
|
||||
nsresult rv1 = NS_NewByteBuffer(&mByteData, nsnull, aBufferSize);
|
||||
nsresult rv2 = NS_NewUnicharBuffer(&mUnicharData, nsnull, aBufferSize);
|
||||
mByteDataOffset = 0;
|
||||
mUnicharDataOffset = 0;
|
||||
mUnicharDataLength = 0;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(ConverterInputStream,kIUnicharInputStreamIID);
|
||||
|
||||
ConverterInputStream::~ConverterInputStream()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
nsresult ConverterInputStream::Close()
|
||||
{
|
||||
if (nsnull != mInput) {
|
||||
mInput->Release();
|
||||
mInput = nsnull;
|
||||
}
|
||||
if (nsnull != mConverter) {
|
||||
mConverter->Release();
|
||||
mConverter = nsnull;
|
||||
}
|
||||
if (nsnull != mByteData) {
|
||||
mByteData->Release();
|
||||
mByteData = nsnull;
|
||||
}
|
||||
if (nsnull != mUnicharData) {
|
||||
mUnicharData->Release();
|
||||
mUnicharData = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult ConverterInputStream::Read(PRUnichar* aBuf,
|
||||
PRInt32 aOffset,
|
||||
PRInt32 aCount,
|
||||
PRInt32 *aReadCount)
|
||||
{
|
||||
PRInt32 rv = mUnicharDataLength - mUnicharDataOffset;
|
||||
nsresult errorCode;
|
||||
if (0 == rv) {
|
||||
// Fill the unichar buffer
|
||||
rv = Fill(&errorCode);
|
||||
if (rv <= 0) {
|
||||
*aReadCount = 0;
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
if (rv > aCount) {
|
||||
rv = aCount;
|
||||
}
|
||||
nsCRT::memcpy(aBuf + aOffset, mUnicharData->GetBuffer() + mUnicharDataOffset,
|
||||
rv * sizeof(PRUnichar));
|
||||
mUnicharDataOffset += rv;
|
||||
*aReadCount = rv;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32 ConverterInputStream::Fill(nsresult * aErrorCode)
|
||||
{
|
||||
if (nsnull == mInput) {
|
||||
// We already closed the stream!
|
||||
*aErrorCode = NS_BASE_STREAM_CLOSED;
|
||||
return -1;
|
||||
}
|
||||
|
||||
PRInt32 remainder = mByteData->GetLength() - mByteDataOffset;
|
||||
mByteDataOffset = remainder;
|
||||
PRInt32 nb = mByteData->Fill(aErrorCode, mInput, remainder);
|
||||
if (nb <= 0) {
|
||||
// Because we assume a many to one conversion, the lingering data
|
||||
// in the byte buffer must be a partial conversion
|
||||
// fragment. Because we know that we have recieved no more new
|
||||
// data to add to it, we can't convert it. Therefore, we discard
|
||||
// it.
|
||||
return nb;
|
||||
}
|
||||
NS_ASSERTION(remainder + nb == mByteData->GetLength(), "bad nb");
|
||||
|
||||
// Now convert as much of the byte buffer to unicode as possible
|
||||
PRInt32 dstLen = mUnicharData->GetBufferSize();
|
||||
PRInt32 srcLen = remainder + nb;
|
||||
*aErrorCode = mConverter->Convert(mUnicharData->GetBuffer(), 0, dstLen,
|
||||
mByteData->GetBuffer(), 0, srcLen);
|
||||
mUnicharDataOffset = 0;
|
||||
mUnicharDataLength = dstLen;
|
||||
mByteDataOffset += srcLen;
|
||||
return dstLen;
|
||||
}
|
||||
|
||||
// XXX hook up auto-detect here (do we need more info, like the url?)
|
||||
NS_BASE nsresult
|
||||
NS_NewConverterStream(nsIUnicharInputStream** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
nsIInputStream* aStreamToWrap,
|
||||
PRInt32 aBufferSize,
|
||||
nsCharSetID aCharSet)
|
||||
{
|
||||
if (nsnull != aOuter) {
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
|
||||
// Create converter
|
||||
nsIB2UConverter* converter;
|
||||
nsresult rv = NS_NewB2UConverter(&converter, nsnull, aCharSet);
|
||||
if (NS_OK != rv) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Create converter input stream
|
||||
ConverterInputStream* it =
|
||||
new ConverterInputStream(aStreamToWrap, converter, aBufferSize);
|
||||
converter->Release();
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(kIUnicharInputStreamIID,
|
||||
(void **) aInstancePtrResult);
|
||||
}
|
||||
182
mozilla/base/src/nsUnitConversion.h
Normal file
182
mozilla/base/src/nsUnitConversion.h
Normal file
@@ -0,0 +1,182 @@
|
||||
/* -*- 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 nsUnitConversion_h__
|
||||
#define nsUnitConversion_h__
|
||||
|
||||
#include "nscore.h"
|
||||
#include <math.h>
|
||||
|
||||
/// handy constants
|
||||
#define TWIPS_PER_POINT_INT 20
|
||||
#define TWIPS_PER_POINT_FLOAT 20.0f
|
||||
#define ROUND_EXCLUSIVE_CONST_FLOAT 0.4999999999999999f // XXX this should be derived from platform FLOAT_MIN
|
||||
#define ROUND_CONST_FLOAT 0.5f
|
||||
#define CEIL_CONST_FLOAT 0.9999999999999999f // XXX this should be derived from platform FLOAT_MIN
|
||||
|
||||
|
||||
/*
|
||||
* Coord Rounding Functions
|
||||
*/
|
||||
inline nscoord NSToCoordFloor(float aValue)
|
||||
{
|
||||
return ((0.0f <= aValue) ? nscoord(aValue) : nscoord(aValue - CEIL_CONST_FLOAT));
|
||||
}
|
||||
|
||||
inline nscoord NSToCoordCeil(float aValue)
|
||||
{
|
||||
return ((0.0f <= aValue) ? nscoord(aValue + CEIL_CONST_FLOAT) : nscoord(aValue));
|
||||
}
|
||||
|
||||
inline nscoord NSToCoordRound(float aValue)
|
||||
{
|
||||
return ((0.0f <= aValue) ? nscoord(aValue + ROUND_CONST_FLOAT) : nscoord(aValue - ROUND_CONST_FLOAT));
|
||||
}
|
||||
|
||||
inline nscoord NSToCoordRoundExclusive(float aValue)
|
||||
{
|
||||
return ((0.0f <= aValue) ? nscoord(aValue + ROUND_EXCLUSIVE_CONST_FLOAT) :
|
||||
nscoord(aValue - ROUND_EXCLUSIVE_CONST_FLOAT));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Int Rounding Functions
|
||||
*/
|
||||
inline PRInt32 NSToIntFloor(float aValue)
|
||||
{
|
||||
return ((0.0f <= aValue) ? PRInt32(aValue) : PRInt32(aValue - CEIL_CONST_FLOAT));
|
||||
}
|
||||
|
||||
inline PRInt32 NSToIntCeil(float aValue)
|
||||
{
|
||||
return ((0.0f <= aValue) ? PRInt32(aValue + CEIL_CONST_FLOAT) : PRInt32(aValue));
|
||||
}
|
||||
|
||||
inline PRInt32 NSToIntRound(float aValue)
|
||||
{
|
||||
return ((0.0f <= aValue) ? PRInt32(aValue + ROUND_CONST_FLOAT) : PRInt32(aValue - ROUND_CONST_FLOAT));
|
||||
}
|
||||
|
||||
inline PRInt32 NSToIntRoundExclusive(float aValue)
|
||||
{
|
||||
return ((0.0f <= aValue) ? PRInt32(aValue + ROUND_EXCLUSIVE_CONST_FLOAT) :
|
||||
PRInt32(aValue - ROUND_EXCLUSIVE_CONST_FLOAT));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Twips/Points conversions
|
||||
*/
|
||||
inline nscoord NSFloatPointsToTwips(float aPoints)
|
||||
{
|
||||
return NSToCoordRound(aPoints * TWIPS_PER_POINT_FLOAT);
|
||||
}
|
||||
|
||||
inline nscoord NSIntPointsToTwips(PRInt32 aPoints)
|
||||
{
|
||||
return nscoord(aPoints * TWIPS_PER_POINT_INT);
|
||||
}
|
||||
|
||||
inline PRInt32 NSTwipsToIntPoints(nscoord aTwips)
|
||||
{
|
||||
return NSToIntRound(aTwips / TWIPS_PER_POINT_FLOAT);
|
||||
}
|
||||
|
||||
inline PRInt32 NSTwipsToFloorIntPoints(nscoord aTwips)
|
||||
{
|
||||
return NSToIntFloor(aTwips / TWIPS_PER_POINT_FLOAT);
|
||||
}
|
||||
|
||||
inline PRInt32 NSTwipsToCeilIntPoints(nscoord aTwips)
|
||||
{
|
||||
return NSToIntCeil(aTwips / TWIPS_PER_POINT_FLOAT);
|
||||
}
|
||||
|
||||
inline float NSTwipsToFloatPoints(nscoord aTwips)
|
||||
{
|
||||
return (float(aTwips) / TWIPS_PER_POINT_FLOAT);
|
||||
}
|
||||
|
||||
/*
|
||||
* Twips/Pixel conversions
|
||||
*/
|
||||
inline nscoord NSFloatPixelsToTwips(float aPixels, float aTwipsPerPixel)
|
||||
{
|
||||
return NSToCoordRound(aPixels * aTwipsPerPixel);
|
||||
}
|
||||
|
||||
inline nscoord NSIntPixelsToTwips(PRInt32 aPixels, float aTwipsPerPixel)
|
||||
{
|
||||
return NSToCoordRound(float(aPixels) * aTwipsPerPixel);
|
||||
}
|
||||
|
||||
inline float NSTwipsToFloatPixels(nscoord aTwips, float aPixelsPerTwip)
|
||||
{
|
||||
return (float(aTwips) * aPixelsPerTwip);
|
||||
}
|
||||
|
||||
inline PRInt32 NSTwipsToIntPixels(nscoord aTwips, float aPixelsPerTwip)
|
||||
{
|
||||
return NSToIntRound(float(aTwips) * aPixelsPerTwip);
|
||||
}
|
||||
|
||||
/*
|
||||
* Twips/unit conversions
|
||||
*/
|
||||
inline nscoord NSUnitsToTwips(float aValue, float aPointsPerUnit)
|
||||
{
|
||||
return NSToCoordRound(aValue * aPointsPerUnit * TWIPS_PER_POINT_FLOAT);
|
||||
}
|
||||
|
||||
inline float NSTwipsToUnits(nscoord aTwips, float aUnitsPerPoint)
|
||||
{
|
||||
return (aTwips * (aUnitsPerPoint / TWIPS_PER_POINT_FLOAT));
|
||||
}
|
||||
|
||||
|
||||
/// Unit conversion macros
|
||||
//@{
|
||||
#define NS_INCHES_TO_TWIPS(x) NSUnitsToTwips((x), 72.0f) // 72 points per inch
|
||||
#define NS_FEET_TO_TWIPS(x) NSUnitsToTwips((x), (72.0f * 12.0f)) // 12 inches per foot
|
||||
#define NS_MILES_TO_TWIPS(x) NSUnitsToTwips((x), (72.0f * 12.0f * 5280.0f)) // 5280 feet per mile
|
||||
|
||||
#define NS_MILLIMETERS_TO_TWIPS(x) NSUnitsToTwips((x), (72.0f * 0.03937f))
|
||||
#define NS_CENTIMETERS_TO_TWIPS(x) NSUnitsToTwips((x), (72.0f * 0.3937f))
|
||||
#define NS_METERS_TO_TWIPS(x) NSUnitsToTwips((x), (72.0f * 39.37f))
|
||||
#define NS_KILOMETERS_TO_TWIPS(x) NSUnitsToTwips((x), (72.0f * 39370.0f))
|
||||
|
||||
#define NS_PICAS_TO_TWIPS(x) NSUnitsToTwips((x), 12.0f) // 12 points per pica
|
||||
#define NS_DIDOTS_TO_TWIPS(x) NSUnitsToTwips((x), (16.0f / 15.0f)) // 15 didots per 16 points
|
||||
#define NS_CICEROS_TO_TWIPS(x) NSUnitsToTwips((x), (12.0f * (16.0f / 15.0f))) // 12 didots per cicero
|
||||
|
||||
|
||||
#define NS_TWIPS_TO_INCHES(x) NSTwipsToUnits((x), 1.0f / 72.0f)
|
||||
#define NS_TWIPS_TO_FEET(x) NSTwipsToUnits((x), 1.0f / (72.0f * 12.0f))
|
||||
#define NS_TWIPS_TO_MILES(x) NSTwipsToUnits((x), 1.0f / (72.0f * 12.0f * 5280.0f))
|
||||
|
||||
#define NS_TWIPS_TO_MILLIMETERS(x) NSTwipsToUnits((x), 1.0f / (72.0f * 0.03937f))
|
||||
#define NS_TWIPS_TO_CENTIMETERS(x) NSTwipsToUnits((x), 1.0f / (72.0f * 0.3937f))
|
||||
#define NS_TWIPS_TO_METERS(x) NSTwipsToUnits((x), 1.0f / (72.0f * 39.37f))
|
||||
#define NS_TWIPS_TO_KILOMETERS(x) NSTwipsToUnits((x), 1.0f / (72.0f * 39370.0f))
|
||||
|
||||
#define NS_TWIPS_TO_PICAS(x) NSTwipsToUnits((x), 1.0f / 12.0f)
|
||||
#define NS_TWIPS_TO_DIDOTS(x) NSTwipsToUnits((x), 1.0f / (16.0f / 15.0f))
|
||||
#define NS_TWIPS_TO_CICEROS(x) NSTwipsToUnits((x), 1.0f / (12.0f * (16.0f / 15.0f)))
|
||||
//@}
|
||||
|
||||
#endif
|
||||
227
mozilla/base/src/nsVoidArray.cpp
Normal file
227
mozilla/base/src/nsVoidArray.cpp
Normal file
@@ -0,0 +1,227 @@
|
||||
/* -*- 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 "nsVoidArray.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
|
||||
static PRInt32 kGrowArrayBy = 8;
|
||||
|
||||
nsVoidArray::nsVoidArray()
|
||||
{
|
||||
mArray = nsnull;
|
||||
mArraySize = 0;
|
||||
mCount = 0;
|
||||
}
|
||||
|
||||
nsVoidArray::nsVoidArray(PRInt32 aCount)
|
||||
{
|
||||
NS_PRECONDITION(aCount > 0, "bad count");
|
||||
mCount = mArraySize = aCount;
|
||||
mArray = new void*[mCount];
|
||||
nsCRT::memset(mArray, 0, mCount * sizeof(void*));
|
||||
}
|
||||
|
||||
nsVoidArray& nsVoidArray::operator=(const nsVoidArray& other)
|
||||
{
|
||||
if (nsnull != mArray) {
|
||||
delete mArray;
|
||||
}
|
||||
PRInt32 otherCount = other.mCount;
|
||||
mArraySize = otherCount;
|
||||
mCount = otherCount;
|
||||
if (otherCount != 0) {
|
||||
mArray = new void*[otherCount];
|
||||
nsCRT::memcpy(mArray, other.mArray, otherCount * sizeof(void*));
|
||||
} else {
|
||||
mArray = nsnull;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsVoidArray::~nsVoidArray()
|
||||
{
|
||||
if (nsnull != mArray) {
|
||||
delete [] mArray;
|
||||
}
|
||||
}
|
||||
void
|
||||
nsVoidArray::SizeOf(nsISizeOfHandler* aHandler) const
|
||||
{
|
||||
aHandler->Add(sizeof(*this));
|
||||
aHandler->Add(sizeof(void*) * mArraySize);
|
||||
}
|
||||
|
||||
void* nsVoidArray::ElementAt(PRInt32 aIndex) const
|
||||
{
|
||||
if (PRUint32(aIndex) >= PRUint32(mCount)) {
|
||||
return nsnull;
|
||||
}
|
||||
return mArray[aIndex];
|
||||
}
|
||||
|
||||
PRInt32 nsVoidArray::IndexOf(void* aPossibleElement) const
|
||||
{
|
||||
void** ap = mArray;
|
||||
void** end = ap + mCount;
|
||||
while (ap < end) {
|
||||
if (*ap == aPossibleElement) {
|
||||
return ap - mArray;
|
||||
}
|
||||
ap++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
PRBool nsVoidArray::InsertElementAt(void* aElement, PRInt32 aIndex)
|
||||
{
|
||||
PRInt32 oldCount = mCount;
|
||||
if (PRUint32(aIndex) > PRUint32(oldCount)) {
|
||||
// An invalid index causes the insertion to fail
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
if (oldCount + 1 > mArraySize) {
|
||||
// We have to grow the array
|
||||
PRInt32 newCount = oldCount + kGrowArrayBy;
|
||||
void** newArray = new void*[newCount];
|
||||
if (mArray != nsnull && aIndex != 0)
|
||||
nsCRT::memcpy(newArray, mArray, aIndex * sizeof(void*));
|
||||
PRInt32 slide = oldCount - aIndex;
|
||||
if (0 != slide) {
|
||||
// Slide data over to make room for the insertion
|
||||
nsCRT::memcpy(newArray + aIndex + 1, mArray + aIndex,
|
||||
slide * sizeof(void*));
|
||||
}
|
||||
if (mArray != nsnull)
|
||||
delete [] mArray;
|
||||
mArray = newArray;
|
||||
mArraySize = newCount;
|
||||
} else {
|
||||
// The array is already large enough
|
||||
PRInt32 slide = oldCount - aIndex;
|
||||
if (0 != slide) {
|
||||
// Slide data over to make room for the insertion
|
||||
nsCRT::memmove(mArray + aIndex + 1, mArray + aIndex,
|
||||
slide * sizeof(void*));
|
||||
}
|
||||
}
|
||||
mArray[aIndex] = aElement;
|
||||
mCount++;
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsVoidArray::ReplaceElementAt(void* aElement, PRInt32 aIndex)
|
||||
{
|
||||
if (PRUint32(aIndex) >= PRUint32(mArraySize)) {
|
||||
|
||||
PRInt32 requestedCount = aIndex + 1;
|
||||
PRInt32 growDelta = requestedCount - mCount;
|
||||
PRInt32 newCount = mCount + (growDelta > kGrowArrayBy ? growDelta : kGrowArrayBy);
|
||||
void** newArray = new void*[newCount];
|
||||
nsCRT::memset(newArray, 0, newCount * sizeof(void*));
|
||||
if (newArray==nsnull)
|
||||
return PR_FALSE;
|
||||
if (mArray != nsnull && aIndex != 0) {
|
||||
nsCRT::memcpy(newArray, mArray, mCount * sizeof(void*));
|
||||
if (mArray != nsnull)
|
||||
delete [] mArray;
|
||||
}
|
||||
mArray = newArray;
|
||||
mArraySize = newCount;
|
||||
}
|
||||
mArray[aIndex] = aElement;
|
||||
if (aIndex >= mCount)
|
||||
mCount = aIndex+1;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsVoidArray::RemoveElementAt(PRInt32 aIndex)
|
||||
{
|
||||
PRInt32 oldCount = mCount;
|
||||
if (PRUint32(aIndex) >= PRUint32(oldCount)) {
|
||||
// An invalid index causes the replace to fail
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
// We don't need to move any elements if we're removing the
|
||||
// last element in the array
|
||||
if (aIndex < (oldCount - 1)) {
|
||||
nsCRT::memmove(mArray + aIndex, mArray + aIndex + 1,
|
||||
(oldCount - 1 - aIndex) * sizeof(void*));
|
||||
}
|
||||
|
||||
mCount--;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsVoidArray::RemoveElement(void* aElement)
|
||||
{
|
||||
void** ep = mArray;
|
||||
void** end = ep + mCount;
|
||||
while (ep < end) {
|
||||
void* e = *ep++;
|
||||
if (e == aElement) {
|
||||
ep--;
|
||||
return RemoveElementAt(PRInt32(ep - mArray));
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
void nsVoidArray::Clear()
|
||||
{
|
||||
mCount = 0;
|
||||
}
|
||||
|
||||
void nsVoidArray::Compact()
|
||||
{
|
||||
PRInt32 count = mCount;
|
||||
if (mArraySize != count) {
|
||||
void** newArray = new void*[count];
|
||||
if (nsnull != newArray) {
|
||||
nsCRT::memcpy(newArray, mArray, count * sizeof(void*));
|
||||
delete [] mArray;
|
||||
mArray = newArray;
|
||||
mArraySize = count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PRBool nsVoidArray::EnumerateForwards(nsVoidArrayEnumFunc aFunc, void* aData)
|
||||
{
|
||||
PRInt32 index = -1;
|
||||
PRBool running = PR_TRUE;
|
||||
|
||||
while (running && (++index < mCount)) {
|
||||
running = (*aFunc)(mArray[index], aData);
|
||||
}
|
||||
return running;
|
||||
}
|
||||
|
||||
PRBool nsVoidArray::EnumerateBackwards(nsVoidArrayEnumFunc aFunc, void* aData)
|
||||
{
|
||||
PRInt32 index = mCount;
|
||||
PRBool running = PR_TRUE;
|
||||
|
||||
while (running && (0 <= --index)) {
|
||||
running = (*aFunc)(mArray[index], aData);
|
||||
}
|
||||
return running;
|
||||
}
|
||||
|
||||
74
mozilla/base/src/nsVoidArray.h
Normal file
74
mozilla/base/src/nsVoidArray.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.
|
||||
*/
|
||||
#ifndef nsVoidArray_h___
|
||||
#define nsVoidArray_h___
|
||||
|
||||
#include "nscore.h"
|
||||
class nsISizeOfHandler;
|
||||
|
||||
// Enumerator callback function. Return PR_FALSE to stop
|
||||
typedef PRBool (*nsVoidArrayEnumFunc)(void* aElement, void *aData);
|
||||
|
||||
/// A basic zero-based array of void*'s that manages its own memory
|
||||
class NS_BASE nsVoidArray {
|
||||
public:
|
||||
nsVoidArray();
|
||||
nsVoidArray(PRInt32 aCount); // initial count of aCount elements set to nsnull
|
||||
~nsVoidArray();
|
||||
|
||||
nsVoidArray& operator=(const nsVoidArray& other);
|
||||
|
||||
void SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
PRInt32 Count() const {
|
||||
return mCount;
|
||||
}
|
||||
|
||||
void* ElementAt(PRInt32 aIndex) const;
|
||||
void* operator[](PRInt32 aIndex) const { return ElementAt(aIndex); }
|
||||
|
||||
PRInt32 IndexOf(void* aPossibleElement) const;
|
||||
|
||||
PRBool InsertElementAt(void* aElement, PRInt32 aIndex);
|
||||
|
||||
PRBool ReplaceElementAt(void* aElement, PRInt32 aIndex);
|
||||
|
||||
PRBool AppendElement(void* aElement) {
|
||||
return InsertElementAt(aElement, mCount);
|
||||
}
|
||||
|
||||
PRBool RemoveElement(void* aElement);
|
||||
PRBool RemoveElementAt(PRInt32 aIndex);
|
||||
void Clear();
|
||||
|
||||
void Compact();
|
||||
|
||||
PRBool EnumerateForwards(nsVoidArrayEnumFunc aFunc, void* aData);
|
||||
PRBool EnumerateBackwards(nsVoidArrayEnumFunc aFunc, void* aData);
|
||||
|
||||
protected:
|
||||
void** mArray;
|
||||
PRInt32 mArraySize;
|
||||
PRInt32 mCount;
|
||||
|
||||
private:
|
||||
/// Copy constructors are not allowed
|
||||
nsVoidArray(const nsVoidArray& other);
|
||||
};
|
||||
|
||||
#endif /* nsVoidArray_h___ */
|
||||
139
mozilla/base/src/nscore.h
Normal file
139
mozilla/base/src/nscore.h
Normal file
@@ -0,0 +1,139 @@
|
||||
/* -*- 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 nscore_h___
|
||||
#define nscore_h___
|
||||
|
||||
#ifdef _WIN32
|
||||
#define NS_WIN32 1
|
||||
#endif
|
||||
|
||||
#if defined(__unix)
|
||||
#define NS_UNIX 1
|
||||
#endif
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nsDebug.h"
|
||||
|
||||
/** ucs2 datatype for 2 byte unicode characters */
|
||||
typedef PRUint16 PRUcs2;
|
||||
|
||||
/** ucs4 datatype for 4 byte unicode characters */
|
||||
typedef PRUint32 PRUcs4;
|
||||
|
||||
#ifdef NS_UCS4
|
||||
typedef PRUcs4 PRUnichar;
|
||||
#else
|
||||
typedef PRUcs2 PRUnichar;
|
||||
#endif
|
||||
|
||||
/// The preferred symbol for null.
|
||||
#define nsnull 0
|
||||
|
||||
/* Define brackets for protecting C code from C++ */
|
||||
#ifdef __cplusplus
|
||||
#define NS_BEGIN_EXTERN_C extern "C" {
|
||||
#define NS_END_EXTERN_C }
|
||||
#else
|
||||
#define NS_BEGIN_EXTERN_C
|
||||
#define NS_END_EXTERN_C
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* Import/export defines */
|
||||
|
||||
#ifdef NS_WIN32
|
||||
#define NS_IMPORT _declspec(dllimport)
|
||||
#define NS_IMPORT_(type) type _declspec(dllimport) __stdcall
|
||||
#define NS_EXPORT _declspec(dllexport)
|
||||
// XXX NS_EXPORT_ defined in nsCOm.h (xpcom) differs in where the __declspec
|
||||
// is placed. It needs to be done this way to make the 4.x compiler happy...
|
||||
#undef NS_EXPORT_
|
||||
#define NS_EXPORT_(type) type _declspec(dllexport) __stdcall
|
||||
#elif defined(XP_MAC)
|
||||
|
||||
#define NS_IMPORT
|
||||
#define NS_IMPORT_(type) type
|
||||
|
||||
// XXX NS_EXPORT_ defined in nsCom.h actually does an export. Here it's just sugar.
|
||||
#undef NS_EXPORT
|
||||
#undef NS_EXPORT_
|
||||
|
||||
#define NS_EXPORT
|
||||
#define NS_EXPORT_(type) type
|
||||
|
||||
#else
|
||||
/* XXX do something useful? */
|
||||
#define NS_IMPORT
|
||||
#define NS_IMPORT_(type) type
|
||||
#define NS_EXPORT
|
||||
#define NS_EXPORT_(type) type
|
||||
#endif
|
||||
|
||||
#ifdef _IMPL_NS_BASE
|
||||
#define NS_BASE NS_EXPORT
|
||||
#else
|
||||
#define NS_BASE NS_IMPORT
|
||||
#endif
|
||||
|
||||
#ifdef _IMPL_NS_NET
|
||||
#define NS_NET NS_EXPORT
|
||||
#else
|
||||
#define NS_NET NS_IMPORT
|
||||
#endif
|
||||
|
||||
#ifdef _IMPL_NS_DOM
|
||||
#define NS_DOM NS_EXPORT
|
||||
#else
|
||||
#define NS_DOM NS_IMPORT
|
||||
#endif
|
||||
|
||||
#ifdef _IMPL_NS_WIDGET
|
||||
#define NS_WIDGET NS_EXPORT
|
||||
#else
|
||||
#define NS_WIDGET NS_IMPORT
|
||||
#endif
|
||||
|
||||
#ifdef _IMPL_NS_VIEW
|
||||
#define NS_VIEW NS_EXPORT
|
||||
#else
|
||||
#define NS_VIEW NS_IMPORT
|
||||
#endif
|
||||
|
||||
#ifdef _IMPL_NS_GFXNONXP
|
||||
#define NS_GFXNONXP NS_EXPORT
|
||||
#define NS_GFXNONXP_(type) NS_EXPORT_(type)
|
||||
#else
|
||||
#define NS_GFXNONXP NS_IMPORT
|
||||
#define NS_GFXNONXP_(type) NS_IMPORT_(type)
|
||||
#endif
|
||||
|
||||
#ifdef _IMPL_NS_GFX
|
||||
#define NS_GFX NS_EXPORT
|
||||
#define NS_GFX_(type) NS_EXPORT_(type)
|
||||
#else
|
||||
#define NS_GFX NS_IMPORT
|
||||
#define NS_GFX_(type) NS_IMPORT_(type)
|
||||
#endif
|
||||
|
||||
#ifdef _IMPL_NS_PLUGIN
|
||||
#define NS_PLUGIN NS_EXPORT
|
||||
#else
|
||||
#define NS_PLUGIN NS_IMPORT
|
||||
#endif
|
||||
|
||||
#endif /* nscore_h___ */
|
||||
43
mozilla/base/src/rhapsody/Makefile
Normal file
43
mozilla/base/src/rhapsody/Makefile
Normal file
@@ -0,0 +1,43 @@
|
||||
#!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 = ../../..
|
||||
|
||||
|
||||
LIBRARY_NAME = gmbaseunix
|
||||
|
||||
MODULE=raptor
|
||||
|
||||
REQUIRES=xpcom raptor
|
||||
|
||||
DEFINES = -D_IMPL_NS_WIDGET
|
||||
|
||||
CPPSRCS= \
|
||||
nsTimer.cpp
|
||||
|
||||
CPP_OBJS= \
|
||||
./$(OBJDIR)/nsTimer.o \
|
||||
$(NULL)
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
TARGETS = $(LIBRARY)
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
|
||||
|
||||
47
mozilla/base/src/rhapsody/Makefile.in
Normal file
47
mozilla/base/src/rhapsody/Makefile.in
Normal file
@@ -0,0 +1,47 @@
|
||||
#!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
|
||||
|
||||
LIBRARY_NAME = gmbaseunix
|
||||
|
||||
MODULE=raptor
|
||||
|
||||
REQUIRES=xpcom raptor
|
||||
|
||||
DEFINES = -D_IMPL_NS_WIDGET
|
||||
|
||||
CPPSRCS= \
|
||||
nsTimer.cpp
|
||||
|
||||
CPP_OBJS= \
|
||||
./$(OBJDIR)/nsTimer.o \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
TARGETS = $(LIBRARY)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
||||
181
mozilla/base/src/rhapsody/nsTimer.cpp
Normal file
181
mozilla/base/src/rhapsody/nsTimer.cpp
Normal file
@@ -0,0 +1,181 @@
|
||||
/* -*- 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>
|
||||
|
||||
//
|
||||
// Copied from the unix version, Rhapsody needs to
|
||||
// make this work. Stubs to compile things for now.
|
||||
//
|
||||
|
||||
static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID);
|
||||
|
||||
extern void nsTimerExpired(void *aCallData);
|
||||
|
||||
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;
|
||||
int 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;
|
||||
|
||||
printf("TimerImpl::Init() not implemented\n");
|
||||
|
||||
#ifdef RHAPSODY_NEEDS_TO_IMPLEMENT_THIS
|
||||
mTimerId = XtAppAddTimeOut(gAppContext, aDelay,(XtTimerCallbackProc)nsTimerExpired, this);
|
||||
#endif
|
||||
|
||||
return Init(aDelay);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TimerImpl::Init(nsITimerCallback *aCallback,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay)
|
||||
{
|
||||
mCallback = aCallback;
|
||||
// mRepeat = aRepeat;
|
||||
|
||||
printf("TimerImpl::Init() not implmented.\n");
|
||||
|
||||
#ifdef RHAPSODY_NEEDS_TO_IMPLEMENT_THIS
|
||||
mTimerId = XtAppAddTimeOut(gAppContext, aDelay, (XtTimerCallbackProc)nsTimerExpired, this);
|
||||
#endif
|
||||
|
||||
return Init(aDelay);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TimerImpl::Init(PRUint32 aDelay)
|
||||
{
|
||||
mDelay = aDelay;
|
||||
NS_ADDREF(this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(TimerImpl, kITimerIID)
|
||||
|
||||
|
||||
void
|
||||
TimerImpl::Cancel()
|
||||
{
|
||||
|
||||
printf("TimerImpl::Cancel() not implemented.\n");
|
||||
|
||||
#ifdef RHAPSODY_NEEDS_TO_IMPLEMENT_THIS
|
||||
XtRemoveTimeOut(mTimerId);
|
||||
#endif
|
||||
}
|
||||
|
||||
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(void *aCallData)
|
||||
{
|
||||
TimerImpl* timer = (TimerImpl *)aCallData;
|
||||
timer->FireTimeout();
|
||||
}
|
||||
43
mozilla/base/src/unix/Makefile
Normal file
43
mozilla/base/src/unix/Makefile
Normal file
@@ -0,0 +1,43 @@
|
||||
#!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 = ../../..
|
||||
|
||||
|
||||
LIBRARY_NAME = gmbaseunix
|
||||
|
||||
MODULE=raptor
|
||||
|
||||
REQUIRES=xpcom raptor
|
||||
|
||||
DEFINES = -D_IMPL_NS_WIDGET
|
||||
|
||||
CPPSRCS= \
|
||||
nsTimer.cpp
|
||||
|
||||
CPP_OBJS= \
|
||||
./$(OBJDIR)/nsTimer.o \
|
||||
$(NULL)
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
TARGETS = $(LIBRARY)
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
|
||||
|
||||
47
mozilla/base/src/unix/Makefile.in
Normal file
47
mozilla/base/src/unix/Makefile.in
Normal file
@@ -0,0 +1,47 @@
|
||||
#!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
|
||||
|
||||
LIBRARY_NAME = gmbaseunix
|
||||
|
||||
MODULE=raptor
|
||||
|
||||
REQUIRES=xpcom raptor
|
||||
|
||||
DEFINES = -D_IMPL_NS_WIDGET
|
||||
|
||||
CPPSRCS= \
|
||||
nsTimer.cpp
|
||||
|
||||
CPP_OBJS= \
|
||||
./$(OBJDIR)/nsTimer.o \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
TARGETS = $(LIBRARY)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
||||
173
mozilla/base/src/unix/nsTimer.cpp
Normal file
173
mozilla/base/src/unix/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();
|
||||
}
|
||||
40
mozilla/base/src/windows/makefile.win
Normal file
40
mozilla/base/src/windows/makefile.win
Normal file
@@ -0,0 +1,40 @@
|
||||
#!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
|
||||
LIBRARY_NAME=gmbase
|
||||
MODULE=raptor
|
||||
REQUIRES=xpcom raptor
|
||||
|
||||
CPPSRCS=nsTimer.cpp
|
||||
|
||||
CPP_OBJS=.\$(OBJDIR)\nsTimer.obj
|
||||
|
||||
LINCS=-I$(XPDIST)\public\xpcom -I$(XPDIST)\public\raptor
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
-D_IMPL_NS_BASE \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
libs:: $(OBJS)
|
||||
$(MAKE_INSTALL) $(OBJDIR)\nsTimer.obj ..\$(OBJDIR)
|
||||
362
mozilla/base/src/windows/nsTimer.cpp
Normal file
362
mozilla/base/src/windows/nsTimer.cpp
Normal file
@@ -0,0 +1,362 @@
|
||||
/* -*- 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 <windows.h>
|
||||
#include <limits.h>
|
||||
|
||||
static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID);
|
||||
|
||||
/*
|
||||
* Implementation of timers lifted from Windows front-end file timer.cpp
|
||||
*/
|
||||
class TimerImpl : public nsITimer {
|
||||
public:
|
||||
static TimerImpl *gTimerList;
|
||||
static UINT gWindowsTimer;
|
||||
static DWORD gNextFire;
|
||||
|
||||
static void ProcessTimeouts(DWORD aNow);
|
||||
static void SyncTimeoutPeriod(DWORD aTickCount);
|
||||
|
||||
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();
|
||||
void Fire(DWORD aNow);
|
||||
|
||||
virtual PRUint32 GetDelay() { return mDelay; }
|
||||
virtual void SetDelay(PRUint32 aDelay) {};
|
||||
|
||||
virtual void* GetClosure() { return mClosure; }
|
||||
|
||||
private:
|
||||
nsresult Init(PRUint32 aDelay);
|
||||
|
||||
PRUint32 mDelay;
|
||||
nsTimerCallbackFunc mFunc;
|
||||
void *mClosure;
|
||||
nsITimerCallback *mCallback;
|
||||
DWORD mFireTime;
|
||||
// PRBool mRepeat;
|
||||
TimerImpl *mNext;
|
||||
};
|
||||
|
||||
TimerImpl *TimerImpl::gTimerList = NULL;
|
||||
UINT TimerImpl::gWindowsTimer = 0;
|
||||
DWORD TimerImpl::gNextFire = (DWORD)-1;
|
||||
|
||||
void CALLBACK FireTimeout(HWND aWindow,
|
||||
UINT aMessage,
|
||||
UINT aTimerID,
|
||||
DWORD aTime)
|
||||
{
|
||||
static BOOL bCanEnter = TRUE;
|
||||
|
||||
// Don't allow old timer messages in here.
|
||||
if(aMessage != WM_TIMER) {
|
||||
PR_ASSERT(0);
|
||||
return;
|
||||
}
|
||||
|
||||
if(aTimerID != TimerImpl::gWindowsTimer) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Block only one entry into this function, or else.
|
||||
if(bCanEnter) {
|
||||
bCanEnter = FALSE;
|
||||
// see if we need to fork off any timeout functions
|
||||
if(TimerImpl::gTimerList) {
|
||||
TimerImpl::ProcessTimeouts(aTime);
|
||||
}
|
||||
bCanEnter = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// Function to correctly have the timer be set.
|
||||
void
|
||||
TimerImpl::SyncTimeoutPeriod(DWORD aTickCount)
|
||||
{
|
||||
// May want us to set tick count ourselves.
|
||||
if(aTickCount == 0) {
|
||||
aTickCount = ::GetTickCount();
|
||||
}
|
||||
|
||||
// If there's no list, we should clear the timer.
|
||||
if(!gTimerList) {
|
||||
if(gWindowsTimer) {
|
||||
::KillTimer(NULL, gWindowsTimer);
|
||||
gWindowsTimer = 0;
|
||||
gNextFire = (DWORD)-1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// See if we need to clear the current timer.
|
||||
// Curcumstances are that if the timer will not
|
||||
// fire on time for the next timeout.
|
||||
BOOL bSetTimer = FALSE;
|
||||
TimerImpl *pTimeout = gTimerList;
|
||||
if(gWindowsTimer) {
|
||||
if(pTimeout->mFireTime != gNextFire) {
|
||||
::KillTimer(NULL, gWindowsTimer);
|
||||
gWindowsTimer = 0;
|
||||
gNextFire = (DWORD)-1;
|
||||
|
||||
// Set the timer.
|
||||
bSetTimer = TRUE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// No timer set, attempt.
|
||||
bSetTimer = TRUE;
|
||||
}
|
||||
|
||||
if(bSetTimer) {
|
||||
DWORD dwFireWhen = pTimeout->mFireTime > aTickCount ?
|
||||
pTimeout->mFireTime - aTickCount : 0;
|
||||
if(dwFireWhen > UINT_MAX) {
|
||||
dwFireWhen = UINT_MAX;
|
||||
}
|
||||
UINT uFireWhen = (UINT)dwFireWhen;
|
||||
|
||||
PR_ASSERT(gWindowsTimer == 0);
|
||||
gWindowsTimer = ::SetTimer(NULL, 0, uFireWhen, (TIMERPROC)FireTimeout);
|
||||
|
||||
if(gWindowsTimer) {
|
||||
// Set the fire time.
|
||||
gNextFire = pTimeout->mFireTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Walk down the timeout list and launch anyone appropriate
|
||||
void
|
||||
TimerImpl::ProcessTimeouts(DWORD aNow)
|
||||
{
|
||||
TimerImpl *p = gTimerList;
|
||||
if(aNow == 0) {
|
||||
aNow = ::GetTickCount();
|
||||
}
|
||||
|
||||
BOOL bCalledSync = FALSE;
|
||||
|
||||
// loop over all entries
|
||||
while(p) {
|
||||
// send it
|
||||
if(p->mFireTime < aNow) {
|
||||
// Make sure that the timer cannot be deleted during the
|
||||
// Fire(...) call which may release *all* other references
|
||||
// to p...
|
||||
NS_ADDREF(p);
|
||||
p->Fire(aNow);
|
||||
|
||||
// Clear the timer.
|
||||
// Period synced.
|
||||
p->Cancel();
|
||||
bCalledSync = TRUE;
|
||||
NS_RELEASE(p);
|
||||
|
||||
// Reset the loop (can't look at p->pNext now, and called
|
||||
// code may have added/cleared timers).
|
||||
// (could do this by going recursive and returning).
|
||||
p = gTimerList;
|
||||
} else {
|
||||
// Make sure we fire an timer.
|
||||
// Also, we need to check to see if things are backing up (they
|
||||
// may be asking to be fired long before we ever get to them,
|
||||
// and we don't want to pass in negative values to the real
|
||||
// timer code, or it takes days to fire....
|
||||
if(bCalledSync == FALSE) {
|
||||
SyncTimeoutPeriod(aNow);
|
||||
bCalledSync = TRUE;
|
||||
}
|
||||
// Get next timer.
|
||||
p = p->mNext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TimerImpl::TimerImpl()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mFunc = NULL;
|
||||
mCallback = NULL;
|
||||
mNext = NULL;
|
||||
mClosure = nsnull;
|
||||
}
|
||||
|
||||
TimerImpl::~TimerImpl()
|
||||
{
|
||||
Cancel();
|
||||
NS_IF_RELEASE(mCallback);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TimerImpl::Init(nsTimerCallbackFunc aFunc,
|
||||
void *aClosure,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay)
|
||||
{
|
||||
mFunc = aFunc;
|
||||
mClosure = aClosure;
|
||||
// mRepeat = aRepeat;
|
||||
|
||||
return Init(aDelay);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TimerImpl::Init(nsITimerCallback *aCallback,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay)
|
||||
{
|
||||
mCallback = aCallback;
|
||||
NS_ADDREF(mCallback);
|
||||
// mRepeat = aRepeat;
|
||||
|
||||
return Init(aDelay);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TimerImpl::Init(PRUint32 aDelay)
|
||||
{
|
||||
DWORD dwNow = ::GetTickCount();
|
||||
|
||||
mDelay = aDelay;
|
||||
mFireTime = (DWORD) aDelay + dwNow;
|
||||
mNext = NULL;
|
||||
|
||||
// add it to the list
|
||||
if(!gTimerList) {
|
||||
// no list add it
|
||||
gTimerList = this;
|
||||
}
|
||||
else {
|
||||
|
||||
// is it before everything else on the list?
|
||||
if(mFireTime < gTimerList->mFireTime) {
|
||||
|
||||
mNext = gTimerList;
|
||||
gTimerList = this;
|
||||
|
||||
} else {
|
||||
|
||||
TimerImpl * pPrev = gTimerList;
|
||||
TimerImpl * pCurrent = gTimerList;
|
||||
|
||||
while(pCurrent && (pCurrent->mFireTime <= mFireTime)) {
|
||||
pPrev = pCurrent;
|
||||
pCurrent = pCurrent->mNext;
|
||||
}
|
||||
|
||||
PR_ASSERT(pPrev);
|
||||
|
||||
// insert it after pPrev (this could be at the end of the list)
|
||||
mNext = pPrev->mNext;
|
||||
pPrev->mNext = this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
NS_ADDREF(this);
|
||||
|
||||
// Sync the timer fire period.
|
||||
SyncTimeoutPeriod(dwNow);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(TimerImpl, kITimerIID)
|
||||
|
||||
void
|
||||
TimerImpl::Fire(DWORD aNow)
|
||||
{
|
||||
if (mFunc != NULL) {
|
||||
(*mFunc)(this, mClosure);
|
||||
}
|
||||
else if (mCallback != NULL) {
|
||||
mCallback->Notify(this);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TimerImpl::Cancel()
|
||||
{
|
||||
TimerImpl *me = this;
|
||||
|
||||
if(gTimerList == this) {
|
||||
|
||||
// first element in the list lossage
|
||||
gTimerList = mNext;
|
||||
|
||||
} else {
|
||||
|
||||
// walk until no next pointer
|
||||
for(TimerImpl * p = gTimerList; p && p->mNext && (p->mNext != this); p = p->mNext)
|
||||
;
|
||||
|
||||
// if we found something valid pull it out of the list
|
||||
if(p && p->mNext && p->mNext == this) {
|
||||
p->mNext = mNext;
|
||||
|
||||
} else {
|
||||
// get out before we delete something that looks bogus
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// if we got here it must have been a valid element so trash it
|
||||
NS_RELEASE(me);
|
||||
|
||||
// If there's now no be sure to clear the timer.
|
||||
SyncTimeoutPeriod(0);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
105
mozilla/base/tests/CvtURL.cpp
Normal file
105
mozilla/base/tests/CvtURL.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
/* -*- 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 <stdio.h>
|
||||
#include "nsIUnicharInputStream.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsString.h"
|
||||
#include "prprf.h"
|
||||
#include "prtime.h"
|
||||
|
||||
static nsCharSetID ConvertCharacterSetName(const char* aName)
|
||||
{
|
||||
if (nsCRT::strcasecmp(aName, "iso-latin-1") == 0) {
|
||||
return eCharSetID_IsoLatin1;
|
||||
}
|
||||
return (nsCharSetID) -1;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (3 != argc) {
|
||||
printf("usage: CvtURL url character-set-name\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
char* characterSetName = argv[2];
|
||||
nsCharSetID cset = ConvertCharacterSetName(characterSetName);
|
||||
if (PRInt32(cset) < 0) {
|
||||
printf("illegal character set name: '%s'\n", characterSetName);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create url object
|
||||
char* urlName = argv[1];
|
||||
nsIURL* url;
|
||||
nsresult rv = NS_NewURL(&url, urlName);
|
||||
if (NS_OK != rv) {
|
||||
printf("invalid URL: '%s'\n", urlName);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get an input stream from the url
|
||||
PRInt32 ec;
|
||||
nsIInputStream* in = url->Open(&ec);
|
||||
if (nsnull == in) {
|
||||
printf("open of url('%s') failed: error=%x\n", urlName, ec);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Translate the input using the argument character set id into unicode
|
||||
nsIUnicharInputStream* uin;
|
||||
rv = NS_NewConverterStream(&uin, nsnull, in, 0, cset);
|
||||
if (NS_OK != rv) {
|
||||
printf("can't create converter input stream: %d\n", rv);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Read the input and write some output
|
||||
PRTime start = PR_Now();
|
||||
PRInt32 count = 0;
|
||||
for (;;) {
|
||||
PRUnichar buf[1000];
|
||||
PRInt32 nb;
|
||||
ec = uin->Read(buf, 0, 1000, &nb);
|
||||
if (ec < 0) {
|
||||
if (ec != NS_BASE_STREAM_EOF) {
|
||||
printf("i/o error: %d\n", ec);
|
||||
}
|
||||
break;
|
||||
}
|
||||
count += nb;
|
||||
}
|
||||
PRTime end = PR_Now();
|
||||
PRTime conversion, ustoms;
|
||||
LL_I2L(ustoms, 1000);
|
||||
LL_SUB(conversion, end, start);
|
||||
LL_DIV(conversion, conversion, ustoms);
|
||||
char buf[500];
|
||||
PR_snprintf(buf, sizeof(buf),
|
||||
"converting and discarding %d bytes took %lldms",
|
||||
count, conversion);
|
||||
puts(buf);
|
||||
|
||||
// Release the objects
|
||||
in->Release();
|
||||
uin->Release();
|
||||
url->Release();
|
||||
|
||||
return 0;
|
||||
}
|
||||
62
mozilla/base/tests/Makefile
Normal file
62
mozilla/base/tests/Makefile
Normal file
@@ -0,0 +1,62 @@
|
||||
#!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=../..
|
||||
|
||||
REQUIRES=xpcom netlib
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
CPPSRCS = \
|
||||
TestAtoms.cpp \
|
||||
TestCRT.cpp \
|
||||
$(NULL)
|
||||
|
||||
INCLUDES+=-I../src
|
||||
|
||||
OBJS = $(CPPSRCS:.cpp=.o)
|
||||
|
||||
EX_LIBS = \
|
||||
$(DIST)/lib/libraptorbase.a \
|
||||
$(DIST)/lib/libxpcom.a \
|
||||
$(DIST)/lib/libplc21.a \
|
||||
$(DIST)/lib/libplds21.a \
|
||||
$(DIST)/lib/libnspr21.a \
|
||||
$(NULL)
|
||||
|
||||
PROGS = $(addprefix $(OBJDIR)/, $(CPPSRCS:.cpp=))
|
||||
|
||||
TARGETS = $(PROGS)
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
|
||||
# needed for mac linux
|
||||
ifeq (linux,$(ARCH))
|
||||
OS_LIBS += /usr/lib/libdl.so
|
||||
endif
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
@$(MAKE_OBJDIR)
|
||||
$(CCC) -o $@ $(CFLAGS) -c $*.cpp
|
||||
|
||||
$(PROGS):$(OBJDIR)/%: $(OBJDIR)/%.o $(EX_LIBS)
|
||||
@$(MAKE_OBJDIR)
|
||||
$(CCC) -o $@ $@.o $(LDFLAGS) $(EX_LIBS) $(OS_LIBS)
|
||||
|
||||
install:: $(TARGETS)
|
||||
$(INSTALL) $(PROGS) $(DIST)/bin
|
||||
|
||||
67
mozilla/base/tests/Makefile.in
Normal file
67
mozilla/base/tests/Makefile.in
Normal file
@@ -0,0 +1,67 @@
|
||||
#!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
|
||||
|
||||
REQUIRES=xpcom netlib
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
CPPSRCS = \
|
||||
TestAtoms.cpp \
|
||||
TestCRT.cpp \
|
||||
$(NULL)
|
||||
|
||||
INCLUDES+=-I$(srcdir)/../src
|
||||
|
||||
OBJS = $(CPPSRCS:.cpp=.o)
|
||||
|
||||
EX_LIBS = \
|
||||
$(DIST)/lib/libraptorbase.a \
|
||||
$(DIST)/lib/libxpcom.a \
|
||||
$(DIST)/lib/libplc21.a \
|
||||
$(DIST)/lib/libplds21.a \
|
||||
$(DIST)/lib/libnspr21.a \
|
||||
$(NULL)
|
||||
|
||||
PROGS = $(addprefix $(OBJDIR)/, $(CPPSRCS:.cpp=))
|
||||
|
||||
TARGETS = $(PROGS)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
# needed for mac linux
|
||||
ifeq (linux,$(ARCH))
|
||||
OS_LIBS += /usr/lib/libdl.so
|
||||
endif
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
@$(MAKE_OBJDIR)
|
||||
$(CCC) -o $@ $(CFLAGS) -c $<
|
||||
|
||||
$(PROGS):$(OBJDIR)/%: $(OBJDIR)/%.o $(EX_LIBS)
|
||||
@$(MAKE_OBJDIR)
|
||||
$(CCC) -o $@ $@.o $(LDFLAGS) $(EX_LIBS) $(OS_LIBS)
|
||||
|
||||
install:: $(TARGETS)
|
||||
$(INSTALL) $(PROGS) $(DIST)/bin
|
||||
|
||||
109
mozilla/base/tests/TestAtoms.cpp
Normal file
109
mozilla/base/tests/TestAtoms.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
/* -*- 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 "prprf.h"
|
||||
#include "prtime.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern "C" int _CrtSetDbgFlag(int);
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
FILE* fp = fopen("words.txt", "r");
|
||||
if (nsnull == fp) {
|
||||
printf("can't open words.txt\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
PRInt32 count = 0;
|
||||
PRUnichar** strings = new PRUnichar*[60000];
|
||||
nsIAtom** ids = new nsIAtom*[60000];
|
||||
nsAutoString s1, s2;
|
||||
PRTime start = PR_Now();
|
||||
PRInt32 i;
|
||||
for (i = 0; i < 60000; i++) {
|
||||
char buf[1000];
|
||||
char* s = fgets(buf, sizeof(buf), fp);
|
||||
if (nsnull == s) {
|
||||
break;
|
||||
}
|
||||
nsAutoString sb(buf);
|
||||
strings[count++] = sb.ToNewUnicode();
|
||||
sb.ToUpperCase();
|
||||
strings[count++] = sb.ToNewUnicode();
|
||||
}
|
||||
PRTime end0 = PR_Now();
|
||||
|
||||
// Find and create idents
|
||||
for (i = 0; i < count; i++) {
|
||||
ids[i] = NS_NewAtom(strings[i]);
|
||||
}
|
||||
PRUnichar qqs[1]; qqs[0] = 0;
|
||||
nsIAtom* qq = NS_NewAtom(qqs);
|
||||
PRTime end1 = PR_Now();
|
||||
|
||||
// Now make sure we can find all the idents we just made
|
||||
for (i = 0; i < count; i++) {
|
||||
nsIAtom* id = NS_NewAtom(ids[i]->GetUnicode());
|
||||
if (id != ids[i]) {
|
||||
id->ToString(s1);
|
||||
ids[i]->ToString(s2);
|
||||
printf("find failed: id='%s' ids[%d]='%s'\n",
|
||||
s1.ToNewCString(), i, s2.ToNewCString());
|
||||
return -1;
|
||||
}
|
||||
NS_RELEASE(id);
|
||||
}
|
||||
PRTime end2 = PR_Now();
|
||||
|
||||
// Destroy all the atoms we just made
|
||||
NS_RELEASE(qq);
|
||||
for (i = 0; i < count; i++) {
|
||||
NS_RELEASE(ids[i]);
|
||||
}
|
||||
|
||||
// Print out timings
|
||||
PRTime end3 = PR_Now();
|
||||
PRTime creates, finds, lookups, dtor, ustoms;
|
||||
LL_I2L(ustoms, 1000);
|
||||
LL_SUB(creates, end0, start);
|
||||
LL_DIV(creates, creates, ustoms);
|
||||
LL_SUB(finds, end1, end0);
|
||||
LL_DIV(finds, finds, ustoms);
|
||||
LL_SUB(lookups, end2, end1);
|
||||
LL_DIV(lookups, lookups, ustoms);
|
||||
LL_SUB(dtor, end3, end2);
|
||||
char buf[500];
|
||||
PR_snprintf(buf, sizeof(buf), "making %d ident strings took %lldms",
|
||||
count, creates);
|
||||
puts(buf);
|
||||
PR_snprintf(buf, sizeof(buf), "%d new idents took %lldms",
|
||||
count, finds);
|
||||
puts(buf);
|
||||
PR_snprintf(buf, sizeof(buf), "%d ident lookups took %lldms",
|
||||
count, lookups);
|
||||
puts(buf);
|
||||
PR_snprintf(buf, sizeof(buf), "dtor took %lldusec", dtor);
|
||||
puts(buf);
|
||||
|
||||
printf("%d live atoms\n", NS_GetNumberOfAtoms());
|
||||
NS_POSTCONDITION(0 == NS_GetNumberOfAtoms(), "dangling atoms");
|
||||
|
||||
return 0;
|
||||
}
|
||||
89
mozilla/base/tests/TestCRT.cpp
Normal file
89
mozilla/base/tests/TestCRT.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/* -*- 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 "nsCRT.h"
|
||||
#include "nsString.h"
|
||||
#include "plstr.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
// Verify that nsCRT versions of string comparison routines get the
|
||||
// same answers as the native non-unicode versions. We only pass in
|
||||
// iso-latin-1 strings, so the comparision must be valid.
|
||||
static void Check(const char* s1, const char* s2, PRIntn n)
|
||||
{
|
||||
PRIntn clib = PL_strcmp(s1, s2);
|
||||
PRIntn clib_n = PL_strncmp(s1, s2, n);
|
||||
PRIntn clib_case = PL_strcasecmp(s1, s2);
|
||||
PRIntn clib_case_n = PL_strncasecmp(s1, s2, n);
|
||||
|
||||
nsAutoString t1(s1), t2(s2);
|
||||
const PRUnichar* us1 = t1.GetUnicode();
|
||||
const PRUnichar* us2 = t2.GetUnicode();
|
||||
|
||||
PRIntn u = nsCRT::strcmp(us1, s2);
|
||||
PRIntn u_n = nsCRT::strncmp(us1, s2, n);
|
||||
PRIntn u_case = nsCRT::strcasecmp(us1, s2);
|
||||
PRIntn u_case_n = nsCRT::strncasecmp(us1, s2, n);
|
||||
|
||||
PRIntn u2 = nsCRT::strcmp(us1, us2);
|
||||
PRIntn u2_n = nsCRT::strncmp(us1, us2, n);
|
||||
PRIntn u2_case = nsCRT::strcasecmp(us1, us2);
|
||||
PRIntn u2_case_n = nsCRT::strncasecmp(us1, us2, n);
|
||||
|
||||
NS_ASSERTION(clib == u, "strcmp");
|
||||
NS_ASSERTION(clib_n == u_n, "strncmp");
|
||||
NS_ASSERTION(clib_case == u_case, "strcasecmp");
|
||||
NS_ASSERTION(clib_case_n == u_case_n, "strncasecmp");
|
||||
|
||||
NS_ASSERTION(clib == u2, "strcmp");
|
||||
NS_ASSERTION(clib_n == u2_n, "strncmp");
|
||||
NS_ASSERTION(clib_case == u2_case, "strcasecmp");
|
||||
NS_ASSERTION(clib_case_n == u2_case_n, "strncasecmp");
|
||||
}
|
||||
|
||||
struct Test {
|
||||
const char* s1;
|
||||
const char* s2;
|
||||
PRIntn n;
|
||||
};
|
||||
|
||||
static Test tests[] = {
|
||||
{ "foo", "foo", 3 },
|
||||
{ "foo", "fo", 3 },
|
||||
|
||||
{ "foo", "bar", 3 },
|
||||
{ "foo", "ba", 3 },
|
||||
|
||||
{ "foo", "zap", 3 },
|
||||
{ "foo", "za", 3 },
|
||||
|
||||
{ "bar", "foo", 3 },
|
||||
{ "bar", "fo", 3 },
|
||||
|
||||
{ "bar", "foo", 3 },
|
||||
{ "bar", "fo", 3 },
|
||||
};
|
||||
#define NUM_TESTS (sizeof(tests) / sizeof(tests[0]))
|
||||
|
||||
void main()
|
||||
{
|
||||
Test* tp = tests;
|
||||
for (PRIntn i = 0; i < NUM_TESTS; i++, tp++) {
|
||||
Check(tp->s1, tp->s2, tp->n);
|
||||
}
|
||||
}
|
||||
202
mozilla/base/tests/TimerTest.cpp
Normal file
202
mozilla/base/tests/TimerTest.cpp
Normal file
@@ -0,0 +1,202 @@
|
||||
/* -*- 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 "prtypes.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsITimerCallback.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "resources.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
static char* class1Name = "TimerTest";
|
||||
|
||||
static HINSTANCE gInstance, gPrevInstance;
|
||||
static nsVoidArray *gTimeouts = NULL;
|
||||
|
||||
static void CreateRepeat(PRUint32 aDelay);
|
||||
|
||||
void
|
||||
MyCallback (nsITimer *aTimer, void *aClosure)
|
||||
{
|
||||
printf("Timer executed with delay %d\n", (int)aClosure);
|
||||
|
||||
if (gTimeouts->RemoveElement(aTimer) == PR_TRUE) {
|
||||
NS_RELEASE(aTimer);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MyRepeatCallback (nsITimer *aTimer, void *aClosure)
|
||||
{
|
||||
printf("Timer executed with delay %d\n", (int)aClosure);
|
||||
|
||||
if (gTimeouts->RemoveElement(aTimer) == PR_TRUE) {
|
||||
NS_RELEASE(aTimer);
|
||||
}
|
||||
|
||||
CreateRepeat((PRUint32)aClosure);
|
||||
}
|
||||
|
||||
static void
|
||||
CreateOneShot(PRUint32 aDelay)
|
||||
{
|
||||
nsITimer *timer;
|
||||
|
||||
NS_NewTimer(&timer);
|
||||
timer->Init(MyCallback, (void *)aDelay, aDelay);
|
||||
|
||||
gTimeouts->AppendElement(timer);
|
||||
}
|
||||
|
||||
static void
|
||||
CreateRepeat(PRUint32 aDelay)
|
||||
{
|
||||
nsITimer *timer;
|
||||
|
||||
NS_NewTimer(&timer);
|
||||
timer->Init(MyRepeatCallback, (void *)aDelay, aDelay);
|
||||
|
||||
gTimeouts->AppendElement(timer);
|
||||
}
|
||||
|
||||
static void
|
||||
CancelAll()
|
||||
{
|
||||
int i, count = gTimeouts->Count();
|
||||
|
||||
for (i=0; i < count; i++) {
|
||||
nsITimer *timer = (nsITimer *)gTimeouts->ElementAt(i);
|
||||
|
||||
if (timer != NULL) {
|
||||
timer->Cancel();
|
||||
NS_RELEASE(timer);
|
||||
}
|
||||
}
|
||||
|
||||
gTimeouts->Clear();
|
||||
}
|
||||
|
||||
long PASCAL
|
||||
WndProc(HWND hWnd, UINT msg, WPARAM param, LPARAM lparam)
|
||||
{
|
||||
HMENU hMenu;
|
||||
|
||||
switch (msg) {
|
||||
case WM_COMMAND:
|
||||
hMenu = GetMenu(hWnd);
|
||||
|
||||
switch (LOWORD(param)) {
|
||||
case TIMER_EXIT:
|
||||
::DestroyWindow(hWnd);
|
||||
exit(0);
|
||||
|
||||
case TIMER_1SECOND:
|
||||
CreateOneShot(1000);
|
||||
break;
|
||||
case TIMER_5SECOND:
|
||||
CreateOneShot(5000);
|
||||
break;
|
||||
case TIMER_10SECOND:
|
||||
CreateOneShot(10000);
|
||||
break;
|
||||
|
||||
case TIMER_1REPEAT:
|
||||
CreateRepeat(1000);
|
||||
break;
|
||||
case TIMER_5REPEAT:
|
||||
CreateRepeat(5000);
|
||||
break;
|
||||
case TIMER_10REPEAT:
|
||||
CreateRepeat(10000);
|
||||
break;
|
||||
|
||||
case TIMER_CANCEL:
|
||||
CancelAll();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return DefWindowProc(hWnd, msg, param, lparam);
|
||||
}
|
||||
|
||||
static HWND CreateTopLevel(const char* clazz, const char* title,
|
||||
int aWidth, int aHeight)
|
||||
{
|
||||
// Create a simple top level window
|
||||
HWND window = ::CreateWindowEx(WS_EX_CLIENTEDGE,
|
||||
clazz, title,
|
||||
WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
aWidth, aHeight,
|
||||
HWND_DESKTOP,
|
||||
NULL,
|
||||
gInstance,
|
||||
NULL);
|
||||
|
||||
::ShowWindow(window, SW_SHOW);
|
||||
::UpdateWindow(window);
|
||||
return window;
|
||||
}
|
||||
|
||||
int PASCAL
|
||||
WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParam, int nCmdShow)
|
||||
{
|
||||
gInstance = instance;
|
||||
|
||||
if (!prevInstance) {
|
||||
WNDCLASS wndClass;
|
||||
wndClass.style = 0;
|
||||
wndClass.lpfnWndProc = WndProc;
|
||||
wndClass.cbClsExtra = 0;
|
||||
wndClass.cbWndExtra = 0;
|
||||
wndClass.hInstance = gInstance;
|
||||
wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wndClass.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
|
||||
wndClass.lpszMenuName = class1Name;
|
||||
wndClass.lpszClassName = class1Name;
|
||||
RegisterClass(&wndClass);
|
||||
}
|
||||
|
||||
// Create our first top level window
|
||||
HWND window = CreateTopLevel(class1Name, "Raptor HTML Viewer", 620, 400);
|
||||
|
||||
gTimeouts = new nsVoidArray();
|
||||
|
||||
// Process messages
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, NULL, 0, 0)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
return msg.wParam;
|
||||
}
|
||||
|
||||
void main(int argc, char **argv)
|
||||
{
|
||||
WinMain(GetModuleHandle(NULL), NULL, 0, SW_SHOW);
|
||||
}
|
||||
90
mozilla/base/tests/makefile.win
Normal file
90
mozilla/base/tests/makefile.win
Normal file
@@ -0,0 +1,90 @@
|
||||
#!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=..\..
|
||||
|
||||
MAKE_OBJ_TYPE = EXE
|
||||
PROG0 = .\$(OBJDIR)\TimerTest.exe
|
||||
PROG1 = .\$(OBJDIR)\TestAtoms.exe
|
||||
PROG2 = .\$(OBJDIR)\CvtURL.exe
|
||||
PROG3 = .\$(OBJDIR)\TestCRT.exe
|
||||
RESFILE = timer.res
|
||||
PROGRAMS = $(PROG0) $(PROG1) \
|
||||
!ifdef MODULAR_NETLIB
|
||||
$(PROG2) \
|
||||
$(PROG3) \
|
||||
!endif
|
||||
$(NULL)
|
||||
|
||||
LINCS=-I..\src -I$(PUBLIC)\xpcom -I$(PUBLIC)\netlib
|
||||
|
||||
LLIBS= \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\raptorbase.lib \
|
||||
!ifdef MODULAR_NETLIB
|
||||
$(DIST)\lib\netlib.lib \
|
||||
!endif
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\libplc21.lib \
|
||||
!if "$(MOZ_BITS)"=="32" && defined(MOZ_DEBUG) && defined(GLOWCODE)
|
||||
$(GLOWDIR)\glowcode.lib \
|
||||
!endif
|
||||
$(RESFILE)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(PROGRAMS)
|
||||
$(MAKE_INSTALL) $(PROG0) $(DIST)\bin
|
||||
$(MAKE_INSTALL) $(PROG1) $(DIST)\bin
|
||||
!ifdef MODULAR_NETLIB
|
||||
$(MAKE_INSTALL) $(PROG2) $(DIST)\bin
|
||||
$(MAKE_INSTALL) $(PROG3) $(DIST)\bin
|
||||
!endif
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\bin\TimerTest.exe
|
||||
rm -f $(DIST)\bin\TestAtoms.exe
|
||||
!ifdef MODULAR_NETLIB
|
||||
rm -f $(DIST)\bin\CvtURL.exe
|
||||
rm -f $(DIST)\bin\TestCRT.exe
|
||||
!endif
|
||||
|
||||
# Move this into config/obj.inc when it's allowed
|
||||
.cpp{.\$(OBJDIR)\}.exe:
|
||||
$(CC) @<<$(CFGFILE)
|
||||
$(CFLAGS)
|
||||
$(LCFLAGS)
|
||||
$(LINCS)
|
||||
$(LINCS_1)
|
||||
$(INCS)
|
||||
$(LLIBS)
|
||||
$(OS_LIBS)
|
||||
-Fd$(PBDFILE)
|
||||
-Fe.\$(OBJDIR)\
|
||||
-Fo.\$(OBJDIR)\
|
||||
$(CURDIR)$(*B).cpp
|
||||
<<KEEP
|
||||
|
||||
$(PROG0): $(OBJDIR) TimerTest.cpp $(RESFILE)
|
||||
|
||||
$(PROG1): $(OBJDIR) TestAtoms.cpp
|
||||
|
||||
!ifdef MODULAR_NETLIB
|
||||
$(PROG2): $(OBJDIR) CvtURL.cpp
|
||||
|
||||
$(PROG3): $(OBJDIR) TestCRT.cpp
|
||||
!endif
|
||||
32
mozilla/base/tests/resources.h
Normal file
32
mozilla/base/tests/resources.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/* -*- 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 resources_h___
|
||||
#define resources_h___
|
||||
|
||||
#define TIMER_1SECOND 40000
|
||||
#define TIMER_5SECOND 40001
|
||||
#define TIMER_10SECOND 40002
|
||||
|
||||
#define TIMER_1REPEAT 40003
|
||||
#define TIMER_5REPEAT 40004
|
||||
#define TIMER_10REPEAT 40005
|
||||
|
||||
#define TIMER_CANCEL 40006
|
||||
#define TIMER_EXIT 40010
|
||||
|
||||
#endif /* resources_h___ */
|
||||
38
mozilla/base/tests/timer.rc
Normal file
38
mozilla/base/tests/timer.rc
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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 "resources.h"
|
||||
|
||||
TIMERTEST MENU DISCARDABLE
|
||||
{
|
||||
POPUP "Debug"
|
||||
{
|
||||
POPUP "One Shot"
|
||||
{
|
||||
MENUITEM "1 second", TIMER_1SECOND
|
||||
MENUITEM "5 second", TIMER_5SECOND
|
||||
MENUITEM "10 second", TIMER_10SECOND
|
||||
}
|
||||
POPUP "Repeated"
|
||||
{
|
||||
MENUITEM "1 second", TIMER_1REPEAT
|
||||
MENUITEM "5 second", TIMER_5REPEAT
|
||||
MENUITEM "10 second", TIMER_10REPEAT
|
||||
}
|
||||
MENUITEM "Cancel All", TIMER_CANCEL
|
||||
MENUITEM "Exit", TIMER_EXIT
|
||||
}
|
||||
}
|
||||
53
mozilla/calendar/Makefile
Normal file
53
mozilla/calendar/Makefile
Normal file
@@ -0,0 +1,53 @@
|
||||
#! gmake
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
91
mozilla/calendar/makefile.win
Normal file
91
mozilla/calendar/makefile.win
Normal file
@@ -0,0 +1,91 @@
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright (C) 1996 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
|
||||
#
|
||||
# An NMAKE file to set up and adjust trex's build system for
|
||||
# Client build. Client build should invoke NMAKE on this file
|
||||
# instead of invoking gmake directly.
|
||||
#
|
||||
|
||||
DEPTH = ..
|
||||
include <$(DEPTH)\config\config.mak>
|
||||
|
||||
#
|
||||
# Backslashes are escape characters to gmake, so flip all backslashes
|
||||
# in $(MOZ_TOOLS) to forward slashes and pass that to gmake.
|
||||
#
|
||||
|
||||
GMAKE = $(MOZ_TOOLS)\bin\gmake.exe MOZ_TOOLS_FLIPPED=$(MOZ_TOOLS:\=/)
|
||||
|
||||
#GMAKE_PR_FLAGS = PR_CLIENT_BUILD=1 PR_CLIENT_BUILD_WINDOWS=1
|
||||
GMAKE_PR_FLAGS =
|
||||
|
||||
#
|
||||
# The Client's debug build uses MSVC's debug runtime library (/MDd).
|
||||
#
|
||||
|
||||
!ifdef MOZ_DEBUG
|
||||
GMAKE_DBG_FLAGS = USE_DEBUG_RTL=1
|
||||
!else
|
||||
GMAKE_DBG_FLAGS = BUILD_OPT=1
|
||||
!endif
|
||||
|
||||
!if "$(MOZ_BITS)" == "16"
|
||||
!ifdef MOZ_DEBUG
|
||||
GMAKE_DBG_FLAGS =
|
||||
!else
|
||||
GMAKE_DBG_FLAGS = BUILD_OPT=1
|
||||
!endif
|
||||
|
||||
GMAKE_OS_FLAGS = OS_TARGET=WIN16
|
||||
!else
|
||||
|
||||
GMAKE_OS_FLAGS = OS_TARGET=WIN95
|
||||
|
||||
!ifdef MOZ_DEBUG
|
||||
GMAKE_DBG_FLAGS = USE_DEBUG_RTL=1
|
||||
!else
|
||||
GMAKE_DBG_FLAGS = BUILD_OPT=1
|
||||
!endif
|
||||
|
||||
!ifdef MOZ_DEBUG
|
||||
PR_OBJDIR = WIN954.0_DBG.OBJD
|
||||
!else
|
||||
PR_OBJDIR = WIN954.0_OPT.OBJ
|
||||
!endif
|
||||
|
||||
!endif
|
||||
|
||||
#
|
||||
# The rules. Simply invoke gmake with the same target
|
||||
# for Win16, use the watcom compiler with the MSVC headers and libs
|
||||
#
|
||||
|
||||
# this rule is needed so that nmake with no explicit target will only build
|
||||
# all, and not build all the targets named below in succession!
|
||||
default:: all
|
||||
|
||||
export libs::
|
||||
|
||||
install::
|
||||
$(GMAKE) $(GMAKE_PR_FLAGS) $(GMAKE_DBG_FLAGS) $(GMAKE_OS_FLAGS)
|
||||
|
||||
# a rule like this one must only be used for explicitly named targets!
|
||||
all install::
|
||||
$(GMAKE) $(GMAKE_PR_FLAGS) $(GMAKE_DBG_FLAGS) $(GMAKE_OS_FLAGS)
|
||||
|
||||
depend:
|
||||
$(GMAKE) $(GMAKE_PR_FLAGS) $(GMAKE_DBG_FLAGS) $(GMAKE_OS_FLAGS) depend
|
||||
|
||||
clobber_all clobber:
|
||||
$(GMAKE) $(GMAKE_PR_FLAGS) $(GMAKE_DBG_FLAGS) $(GMAKE_OS_FLAGS) clobber_all
|
||||
|
||||
show:
|
||||
@echo "MAKEFLAGS = $(MAKEFLAGS)"
|
||||
20
mozilla/calendar/manifest.mn
Normal file
20
mozilla/calendar/manifest.mn
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright (C) 1996 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
GDEPTH = ..
|
||||
DEPTH = ..
|
||||
|
||||
IMPORTS = \
|
||||
$(NULL)
|
||||
|
||||
RELEASE = trex
|
||||
|
||||
DIRS = modules
|
||||
|
||||
|
||||
53
mozilla/calendar/modules/Makefile
Normal file
53
mozilla/calendar/modules/Makefile
Normal file
@@ -0,0 +1,53 @@
|
||||
#! gmake
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
55
mozilla/calendar/modules/core/Makefile
Normal file
55
mozilla/calendar/modules/core/Makefile
Normal file
@@ -0,0 +1,55 @@
|
||||
#! gmake
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
include config.mk
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/ruleset.mk
|
||||
include $(GDEPTH)/gconfig/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
53
mozilla/calendar/modules/core/capi/Makefile
Normal file
53
mozilla/calendar/modules/core/capi/Makefile
Normal file
@@ -0,0 +1,53 @@
|
||||
#! gmake
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
53
mozilla/calendar/modules/core/capi/local/Makefile
Normal file
53
mozilla/calendar/modules/core/capi/local/Makefile
Normal file
@@ -0,0 +1,53 @@
|
||||
#! gmake
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
53
mozilla/calendar/modules/core/capi/local/inc/Makefile
Normal file
53
mozilla/calendar/modules/core/capi/local/inc/Makefile
Normal file
@@ -0,0 +1,53 @@
|
||||
#! gmake
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
311
mozilla/calendar/modules/core/capi/local/inc/capi.h
Normal file
311
mozilla/calendar/modules/core/capi/local/inc/capi.h
Normal file
@@ -0,0 +1,311 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* capi.h
|
||||
*
|
||||
* sman
|
||||
* 30-Jun-98
|
||||
*/
|
||||
|
||||
#ifndef __JULIAN_LOCAL_CAPI_H
|
||||
#define __JULIAN_LOCAL_CAPI_H
|
||||
|
||||
#include "jdefines.h"
|
||||
#include <unistring.h>
|
||||
#include "nscore.h"
|
||||
#include "nscalexport.h"
|
||||
|
||||
typedef void* CAPISession;
|
||||
typedef void* CAPIHandle;
|
||||
typedef void* CAPIStream;
|
||||
typedef long CAPIStatus;
|
||||
|
||||
#define CAPI_THISINSTANCE 1
|
||||
#define CAPI_THISANDPRIOR 2
|
||||
#define CAPI_THISANDFUTURE 3
|
||||
|
||||
#define CAPI_CALLBACK_CONTINUE 0
|
||||
#define CAPI_CALLBACK_DONE -1
|
||||
|
||||
#if 0
|
||||
#define CAPI_ERR_OK 0
|
||||
|
||||
#define CAPI_ERR_CALLBACK 1
|
||||
#define CAPI_ERR_COMP_NOT_FOUND 2
|
||||
#define CAPI_ERR_CORRUPT_HANDLE 3
|
||||
#define CAPI_ERR_CORRUPT_SESSION 4
|
||||
#define CAPI_ERR_CORRUPT_STREAM 5
|
||||
#define CAPI_ERR_DATE 6
|
||||
#define CAPI_ERR_DATE_RANGE 7
|
||||
#define CAPI_ERR_EXPIRED 8
|
||||
#define CAPI_ERR_FLAGS 9
|
||||
#define CAPI_ERR_HOST 10
|
||||
#define CAPI_ERR_INTERNAL 11
|
||||
#define CAPI_ERR_IO 12
|
||||
#define CAPI_ERR_NO_MEMORY 13
|
||||
#define CAPI_ERR_NOT_IMPLEMENTED 14
|
||||
#define CAPI_ERR_NULL_PARAMETER 15
|
||||
#define CAPI_ERR_PROPERTIES_BLOCKED 16
|
||||
#define CAPI_ERR_REQUIRED_PROPERTY_MISSING 17
|
||||
#define CAPI_ERR_SECURITY 18
|
||||
#define CAPI_ERR_SERVER 19
|
||||
#define CAPI_ERR_UID 20
|
||||
#define CAPI_ERR_USERNAME_PASSWORD 21
|
||||
#endif
|
||||
|
||||
typedef int (*CAPICallback)(
|
||||
void* pData, /* i: caller-defined data, the value */
|
||||
/* supplied in CAPI_SetStreamCallbacks */
|
||||
char* pBuf, /* i: buffer to read or write */
|
||||
size_t iSize, /* i: the number of characters in pBuf */
|
||||
size_t* piTransferred); /* o: the number of characters from pBuf that */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
NS_CALENDAR CAPIStatus CAPI_Capabilities(
|
||||
const char** ppsVal, /* o: a string describing the capabilities */
|
||||
const char* psHost, /* i: server host */
|
||||
long lFlags ); /* i: bit flags (none at this time; set to 0) */
|
||||
/* were processed. */
|
||||
|
||||
NS_CALENDAR CAPIStatus CAPI_DeleteEvent(
|
||||
CAPISession s, /* i: login session handle */
|
||||
CAPIHandle* pH, /* i: list of CAPIHandles for delete */
|
||||
int iHandleCount, /* i: number of valid handles in ppH */
|
||||
long lFlags, /* i: bit flags (none at this time; set to 0) */
|
||||
char* psUID, /* i: UID of the event to delete */
|
||||
char* dtRecurrenceID, /* i: recurrence-id, NULL means ignore */
|
||||
int iModifier); /* i: one of CAPI_THISINSTANCE, */
|
||||
/* CAPI_THISANDPRIOR, CAPI_THISANDFUTURE */
|
||||
/* only valid if recurrence-id is non-NULL */
|
||||
|
||||
NS_CALENDAR CAPIStatus CAPI_DestroyHandles(
|
||||
CAPISession s, /* i: login session handle */
|
||||
CAPIHandle* pHList, /* i: pointer to a list of handles to destroy */
|
||||
int iHandleCount, /* i: number of valid handles in pHList */
|
||||
long lFlags); /* i: bit flags (none at this time; set to 0) */
|
||||
|
||||
NS_CALENDAR CAPIStatus CAPI_DestroyStreams(
|
||||
CAPISession s, /* i: login session handle */
|
||||
CAPIStream* pS, /* i: array of streams to destroy */
|
||||
int iCount, /* i: number of valid handles in ppH */
|
||||
long lFlags); /* i: bit flags (none at this time; set to 0) */
|
||||
|
||||
NS_CALENDAR CAPIStatus CAPI_FetchEventsByAlarmRange(
|
||||
CAPISession s, /* i: login session handle */
|
||||
CAPIHandle* pH, /* i: list of CAPIHandles for Fetch */
|
||||
int iHandleCount, /* i: number of valid handles in ppH */
|
||||
long lFlags, /* i: bit flags (none at this time; set to 0) */
|
||||
char* dStart, /* i: range start time, ex: "19980704T080000Z" */
|
||||
char* dEnd, /* i: range end time, ex: "19980704T180000Z" */
|
||||
char** ppsPropList, /* i: list of properties to return in events */
|
||||
int iPropCount, /* i: number of properties in *ppsPropList */
|
||||
CAPIStream stream); /* i: stream to which solution set will be written */
|
||||
|
||||
NS_CALENDAR CAPIStatus CAPI_FetchEventsByID(
|
||||
CAPISession s, /* i: login session handle */
|
||||
CAPIHandle h, /* i: calendar from which to fetch events */
|
||||
long lFlags, /* i: bit flags (none at this time; set to 0) */
|
||||
char* psUID, /* i: UID of the event to fetch */
|
||||
char* dtRecurrenceID, /* i: recurrence-id, NULL means ignore */
|
||||
int iModifier, /* i: one of CAPI_THISINSTANCE, */
|
||||
/* CAPI_THISANDPRIOR, CAPI_THISANDFUTURE */
|
||||
/* only valid if recurrence-id is non-NULL */
|
||||
char** ppsPropList, /* i: list of properties returned in events */
|
||||
int iPropCount, /* i: number of properties in the list */
|
||||
CAPIStream stream); /* i: stream to which solution set will be written */
|
||||
|
||||
NS_CALENDAR CAPIStatus CAPI_FetchEventsByRange(
|
||||
CAPISession s, /* i: login session handle */
|
||||
CAPIHandle* pH, /* i: list of CAPIHandles for fetch */
|
||||
int iHandleCount, /* i: number of valid handles in ppH */
|
||||
long lFlags, /* i: bit flags (none at this time; set to 0) */
|
||||
char* dStart, /* i: range start time */
|
||||
char* dEnd, /* i: range end time */
|
||||
char** ppsPropList, /* i: list of properties returned in events */
|
||||
int iPropCount, /* i: number of properties in the list */
|
||||
CAPIStream stream); /* i: stream to which solution set will be written */
|
||||
|
||||
NS_CALENDAR CAPIStatus CAPI_GetHandle(
|
||||
CAPISession s, /* i: login session handle */
|
||||
char* u, /* i: user as defined in Login */
|
||||
long lFlags, /* i: bit flags (none at this time; set to 0) */
|
||||
CAPIHandle* pH); /* o: handle */
|
||||
|
||||
NS_CALENDAR CAPIStatus CAPI_Logoff(
|
||||
CAPISession* s, /* io: session from login */
|
||||
long lFlags); /* i: bit flags (none at this time; set to 0) */
|
||||
|
||||
NS_CALENDAR CAPIStatus CAPI_Logon(
|
||||
const char* psUser, /* i: Calendar store (and ":extra" information ) */
|
||||
const char* psPassword, /* i: password for sUser */
|
||||
const char* psHost, /* i: calendar server host (and :port) */
|
||||
long lFlags, /* i: bit flags (none at this time; set to 0) */
|
||||
CAPISession* pSession); /* o: the session */
|
||||
|
||||
NS_CALENDAR CAPIStatus CAPI_SetStreamCallbacks (
|
||||
CAPISession s, /* i: login session handle */
|
||||
CAPIStream* pStream, /* io: The stream to modify */
|
||||
CAPICallback pfnSndCallback,/* i: Snd iCalendar data */
|
||||
void* userDataSnd, /* i: a user supplied value */
|
||||
CAPICallback pfnRcvCallback,/* i: Rcv iCalendar data */
|
||||
void* userDataRcv, /* i: a user supplied value */
|
||||
long lFlags ); /* i: bit flags (none at this time; set to 0) */
|
||||
|
||||
NS_CALENDAR CAPIStatus CAPI_StoreEvent(
|
||||
CAPISession s, /* i: login session handle */
|
||||
CAPIHandle* pH, /* i: list of CAPIHandles for store */
|
||||
int iHandleCount, /* i: number of valid handles in pH */
|
||||
long lFlags, /* i: bit flags (none at this time; set to 0) */
|
||||
CAPIStream stream ); /* i: stream for reading data to store */
|
||||
|
||||
|
||||
/*
|
||||
* NETSCAPE EXTENSIONS TO CAPI
|
||||
*/
|
||||
NS_CALENDAR CAPIStatus CAPI_LogonCurl(
|
||||
const char* psCurl, /* i: Calendar store (and ":extra" information ) */
|
||||
const char* psPassword, /* i: password for sUser */
|
||||
long lFlags, /* i: bit flags (none at this time; set to 0) */
|
||||
CAPISession* pSession); /* o: the session */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* The ok error */
|
||||
#define CAPI_ERR_OK ((CAPIStatus) 0x00)
|
||||
|
||||
/* Masks for checking for fields of error codes */
|
||||
#define CAPI_ERRMASK_MODE_FIELD ((CAPIStatus) 0xFF << 24)
|
||||
#define CAPI_ERRMASK_TYPE_FIELD ((CAPIStatus) 0x1F << 19)
|
||||
#define CAPI_ERRMASK_ERR1_FIELD ((CAPIStatus) 0x1F << 14)
|
||||
#define CAPI_ERRMASK_ERR2_FIELD ((CAPIStatus) 0x3F << 8)
|
||||
#define CAPI_ERRMASK_VENDOR_FIELD ((CAPIStatus) 0xFF)
|
||||
|
||||
/* Masks for checking for errors at various levels */
|
||||
|
||||
#define CAPI_ERRMASK_TYPE ((CAPIStatus) CAPI_ERRMASK_TYPE_FIELD)
|
||||
#define CAPI_ERRMASK_ERR1 ((CAPIStatus) CAPI_ERRMASK_TYPE + CAPI_ERRMASK_ERR1_FIELD)
|
||||
#define CAPI_ERRMASK_ERR2 ((CAPIStatus) CAPI_ERRMASK_ERR1 + CAPI_ERRMASK_ERR2_FIELD)
|
||||
#define CAPI_ERRMASK_VENDOR ((CAPIStatus) CAPI_ERRMASK_ERR2 + CAPI_ERRMASK_VENDOR_FIELD)
|
||||
|
||||
/* The non fatal error bit */
|
||||
|
||||
#define CAPI_ERRMODE_FATAL ((CAPIStatus) 0x1 << 24))
|
||||
|
||||
/* The various error types (field 2) */
|
||||
#define CAPI_ERRTYPE_DATA ((CAPIStatus) 0x1 << 19)
|
||||
#define CAPI_ERRTYPE_SERVICE ((CAPIStatus) 0x2 << 19)
|
||||
#define CAPI_ERRTYPE_API ((CAPIStatus) 0x3 << 19)
|
||||
#define CAPI_ERRTYPE_SECURITY ((CAPIStatus) 0x4 << 19)
|
||||
#define CAPI_ERRTYPE_LIBRARY ((CAPIStatus) 0x5 << 19)
|
||||
|
||||
/* Data errors */
|
||||
|
||||
/* field 3 values */
|
||||
#define CAPI_ERR1_ICAL ((CAPIStatus) CAPI_ERRTYPE_DATA + (0x1 << 14 ))
|
||||
#define CAPI_ERR1_MIME ((CAPIStatus) CAPI_ERRTYPE_DATA + (0x2 << 14 ))
|
||||
#define CAPI_ERR1_DATE ((CAPIStatus) CAPI_ERRTYPE_DATA + (0x3 << 14 ))
|
||||
#define CAPI_ERR1_ID ((CAPIStatus) CAPI_ERRTYPE_DATA + (0x4 << 14 ))
|
||||
|
||||
/* field 4 values */
|
||||
#define CAPI_ERR2_MIME_NONE ((CAPIStatus) CAPI_ERR1_MIME + (0x1 << 8))
|
||||
#define CAPI_ERR2_MIME_NOICAL ((CAPIStatus) CAPI_ERR1_MIME + (0x2 << 8))
|
||||
|
||||
#define CAPI_ERR2_DATE_RANGE ((CAPIStatus) CAPI_ERR1_DATE + (0x1 << 8))
|
||||
#define CAPI_ERR2_DATE_FORMAT ((CAPIStatus) CAPI_ERR1_DATE + (0x2 << 8))
|
||||
|
||||
#define CAPI_ERR2_ID_USERID ((CAPIStatus) CAPI_ERR1_ID + (0x1 << 8))
|
||||
#define CAPI_ERR2_ID_HOSTNAME ((CAPIStatus) CAPI_ERR1_ID + (0x2 << 8))
|
||||
|
||||
/* field 5 values (Vendor specific errors) */
|
||||
|
||||
#define CAPI_ERR_IDUSERID_INIFILE ((CAPIStatus) CAPI_ERR2_ID_USERID + 0x01)
|
||||
#define CAPI_ERR_IDUSERID_FORMAT ((CAPIStatus) CAPI_ERR2_ID_USERID + 0x02)
|
||||
#define CAPI_ERR_IDUSERID_NONE ((CAPIStatus) CAPI_ERR2_ID_USERID + 0x03)
|
||||
#define CAPI_ERR_IDUSERID_MANY ((CAPIStatus) CAPI_ERR2_ID_USERID + 0x04)
|
||||
#define CAPI_ERR_IDUSERID_NODE ((CAPIStatus) CAPI_ERR2_ID_USERID + 0x05)
|
||||
|
||||
/*
|
||||
* Service errors
|
||||
*/
|
||||
|
||||
/* field 3 values */
|
||||
#define CAPI_ERR1_MEMORY ((CAPIStatus) CAPI_ERRTYPE_SERVICE + (0x1 << 14 ))
|
||||
#define CAPI_ERR1_FILE ((CAPIStatus) CAPI_ERRTYPE_SERVICE + (0x2 << 14 ))
|
||||
#define CAPI_ERR1_NETWORK ((CAPIStatus) CAPI_ERRTYPE_SERVICE + (0x3 << 14 ))
|
||||
|
||||
/* field 4 values */
|
||||
#define CAPI_ERR2_NETWORK_TIMEOUT ((CAPIStatus) CAPI_ERR1_NETWORK + (0x1 << 8))
|
||||
|
||||
|
||||
/*
|
||||
* API errors
|
||||
*/
|
||||
|
||||
/* field 3 values */
|
||||
#define CAPI_ERR1_FLAGS ((CAPIStatus) CAPI_ERRTYPE_API + (0x1 << 14))
|
||||
#define CAPI_ERR1_NULLPARAM ((CAPIStatus) CAPI_ERRTYPE_API + (0x2 << 14))
|
||||
#define CAPI_ERR1_CALLBACK ((CAPIStatus) CAPI_ERRTYPE_API + (0x3 << 14))
|
||||
#define CAPI_ERR1_HANDLE ((CAPIStatus) CAPI_ERRTYPE_API + (0x4 << 14))
|
||||
#define CAPI_ERR1_SESSION ((CAPIStatus) CAPI_ERRTYPE_API + (0x5 << 14))
|
||||
#define CAPI_ERR1_STREAM ((CAPIStatus) CAPI_ERRTYPE_API + (0x6 << 14))
|
||||
|
||||
/* field 4 values */
|
||||
#define CAPI_ERR2_HANDLE_NULL ((CAPIStatus) CAPI_ERR1_HANDLE + (0x1 << 8))
|
||||
#define CAPI_ERR2_HANDLE_BAD ((CAPIStatus) CAPI_ERR1_HANDLE + (0x2 << 8))
|
||||
|
||||
#define CAPI_ERR2_SESSION_NULL ((CAPIStatus) CAPI_ERR1_SESSION + (0x1 << 8))
|
||||
#define CAPI_ERR2_SESSION_BAD ((CAPIStatus) CAPI_ERR1_SESSION + (0x2 << 8))
|
||||
|
||||
#define CAPI_ERR2_STREAM_NULL ((CAPIStatus) CAPI_ERR1_STREAM + (0x1 << 8))
|
||||
#define CAPI_ERR2_STREAM_BAD ((CAPIStatus) CAPI_ERR1_STREAM + (0x2 << 8))
|
||||
|
||||
/*
|
||||
* Security errors
|
||||
*/
|
||||
|
||||
/* field 3 values */
|
||||
#define CAPI_ERR1_READ ((CAPIStatus) CAPI_ERRTYPE_SECURITY + (0x1 << 14))
|
||||
#define CAPI_ERR1_WRITE ((CAPIStatus) CAPI_ERRTYPE_SECURITY + (0x2 << 14))
|
||||
|
||||
/* field 4 values */
|
||||
#define CAPI_ERR2_READ_PROPS ((CAPIStatus) CAPI_ERR1_READ + (0x1 << 8))
|
||||
|
||||
#define CAPI_ERR2_WRITE_AGENDA ((CAPIStatus) CAPI_ERR1_WRITE + (0x1 << 8))
|
||||
#define CAPI_ERR2_WRITE_EVENT ((CAPIStatus) CAPI_ERR1_WRITE + (0x2 << 8))
|
||||
|
||||
|
||||
/*
|
||||
* Library errors
|
||||
*/
|
||||
/* field 3 values */
|
||||
#define CAPI_ERR1_INTERNAL ((CAPIStatus) CAPI_ERRTYPE_LIBRARY + (0x1 << 14))
|
||||
#define CAPI_ERR1_IMPLENTATION ((CAPIStatus) CAPI_ERRTYPE_LIBRARY + (0x2 << 14))
|
||||
|
||||
/* field 4 values */
|
||||
#define CAPI_ERR2_INTERNALEXPIRY ((CAPIStatus) CAPI_ERR_INTERNAL + (0x1 << 8))
|
||||
|
||||
#endif /* __JULIAN_LOCAL_CAPI_H */
|
||||
22
mozilla/calendar/modules/core/capi/local/inc/manifest.mn
Normal file
22
mozilla/calendar/modules/core/capi/local/inc/manifest.mn
Normal file
@@ -0,0 +1,22 @@
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright (C) 1996 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
GDEPTH = ../../../../../..
|
||||
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
PRIVATE_EXPORTS = \
|
||||
capi.h \
|
||||
privcapi.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = trex
|
||||
|
||||
REQUIRES = raptor julian nls shell trex
|
||||
60
mozilla/calendar/modules/core/capi/local/inc/privcapi.h
Normal file
60
mozilla/calendar/modules/core/capi/local/inc/privcapi.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
*** Private CAPI header file.
|
||||
*** Defines the opaque types.
|
||||
**/
|
||||
#ifndef __JULIAN_PRIVATE_CAPI_H
|
||||
#define __JULIAN_PRIVATE_CAPI_H
|
||||
|
||||
#include "nsString.h"
|
||||
#include "xp_mcom.h"
|
||||
#include "jdefines.h"
|
||||
#include "julnstr.h"
|
||||
#include "nspr.h"
|
||||
#include "plstr.h"
|
||||
#include "nsCurlParser.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
nsCurlParser* pCurl;
|
||||
char* psUser; /* i: Calendar store (and ":extra" information ) */
|
||||
char* psPassword; /* i: password for sUser */
|
||||
char* psHost; /* i: calendar server host (and :port) */
|
||||
} PCAPISESSION;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PCAPISESSION *pSession;
|
||||
char* psFile;
|
||||
nsCurlParser* pCurl;
|
||||
} PCAPIHANDLE;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
CAPICallback pfnSndCallback; /* i: Snd iCalendar data */
|
||||
void* pCallerSndDataBuf; /* i: Data buffer pointer Snd function */
|
||||
void* userDataRcv; /* i: a user supplied value */
|
||||
CAPICallback pfnRcvCallback; /* i: Rcv iCalendar data */
|
||||
void* userDataSnd; /* i: a user supplied value */
|
||||
long lFlags; /* i: bit flags (none at this time; set to 0) */
|
||||
} PCAPIStream;
|
||||
|
||||
#endif /* __JULIAN_PRIVATE_CAPI_H */
|
||||
15
mozilla/calendar/modules/core/capi/local/manifest.mn
Normal file
15
mozilla/calendar/modules/core/capi/local/manifest.mn
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright (C) 1996 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
GDEPTH = ../../../../..
|
||||
DEPTH = ../../../../..
|
||||
|
||||
DIRS_EXPORT = inc
|
||||
DIRS_LIBS = src
|
||||
|
||||
53
mozilla/calendar/modules/core/capi/local/src/Makefile
Normal file
53
mozilla/calendar/modules/core/capi/local/src/Makefile
Normal file
@@ -0,0 +1,53 @@
|
||||
#! gmake
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
include config.mk
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/ruleset.mk
|
||||
include $(GDEPTH)/gconfig/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
1400
mozilla/calendar/modules/core/capi/local/src/capi.cpp
Normal file
1400
mozilla/calendar/modules/core/capi/local/src/capi.cpp
Normal file
File diff suppressed because it is too large
Load Diff
27
mozilla/calendar/modules/core/capi/local/src/config.mk
Normal file
27
mozilla/calendar/modules/core/capi/local/src/config.mk
Normal file
@@ -0,0 +1,27 @@
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
|
||||
#
|
||||
# Override TARGETS variable so that only static libraries
|
||||
# are specifed as dependencies within rules.mk.
|
||||
#
|
||||
|
||||
CFLAGS +=-D_IMPL_NS_CALENDAR -DNSPR20 -DNLS_DEFINE_STANDARD_TYPES=1
|
||||
INCLUDES += -I../inc -I$(GDEPTH)/include
|
||||
|
||||
|
||||
LD_LIBS += \
|
||||
$(NATIVE_LIBNLS_LIBS) \
|
||||
cal_core_ical10 \
|
||||
util10 \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_LIBS += $(NSPR_LIBS)
|
||||
|
||||
27
mozilla/calendar/modules/core/capi/local/src/manifest.mn
Normal file
27
mozilla/calendar/modules/core/capi/local/src/manifest.mn
Normal file
@@ -0,0 +1,27 @@
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright (C) 1996 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
GDEPTH = ../../../../../..
|
||||
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
PRIVATE_EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
LIBRARY_NAME = capilocal
|
||||
|
||||
MODULE = trex
|
||||
|
||||
CPPSRCS = \
|
||||
capi.cpp \
|
||||
$(NULL)
|
||||
|
||||
REQUIRES = xpcom raptor trex julian nls netlib
|
||||
|
||||
14
mozilla/calendar/modules/core/capi/manifest.mn
Normal file
14
mozilla/calendar/modules/core/capi/manifest.mn
Normal file
@@ -0,0 +1,14 @@
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright (C) 1996 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
GDEPTH = ../../../..
|
||||
DEPTH = ../../../..
|
||||
|
||||
DIRS = local
|
||||
|
||||
40
mozilla/calendar/modules/core/config.mk
Normal file
40
mozilla/calendar/modules/core/config.mk
Normal file
@@ -0,0 +1,40 @@
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
|
||||
#
|
||||
# Override TARGETS variable so that only static libraries
|
||||
# are specifed as dependencies within rules.mk.
|
||||
#
|
||||
|
||||
CFLAGS +=-D_IMPL_NS_CALENDAR -DNSPR20 -I$(GDEPTH)/include
|
||||
|
||||
ifeq ($(OS_ARCH), WINNT)
|
||||
CFLAGS += /Zm1000
|
||||
endif
|
||||
|
||||
LD_LIBS += \
|
||||
raptorbase \
|
||||
raptorhtmlpars \
|
||||
xpcom$(MOZ_BITS) \
|
||||
$(NATIVE_RAPTOR_WIDGET) \
|
||||
calcapi10 \
|
||||
cal_core_ical10 \
|
||||
util10 \
|
||||
xpcom$(MOZ_BITS) \
|
||||
$(NATIVE_LIBNLS_LIBS) \
|
||||
$(XP_REG_LIB)
|
||||
|
||||
AR_LIBS += \
|
||||
cal_core_src \
|
||||
$(NULL)
|
||||
|
||||
|
||||
EXTRA_LIBS += $(NSPR_LIBS)
|
||||
|
||||
53
mozilla/calendar/modules/core/htmlform/Makefile
Normal file
53
mozilla/calendar/modules/core/htmlform/Makefile
Normal file
@@ -0,0 +1,53 @@
|
||||
#! gmake
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
53
mozilla/calendar/modules/core/htmlform/inc/Makefile
Normal file
53
mozilla/calendar/modules/core/htmlform/inc/Makefile
Normal file
@@ -0,0 +1,53 @@
|
||||
#! gmake
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
106
mozilla/calendar/modules/core/htmlform/inc/form.h
Normal file
106
mozilla/calendar/modules/core/htmlform/inc/form.h
Normal file
@@ -0,0 +1,106 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#ifndef _JULIAN_FORMS_H
|
||||
#define _JULIAN_FORMS_H
|
||||
|
||||
#include "julianform.h"
|
||||
#include "julnstr.h"
|
||||
|
||||
class JULIAN_PUBLIC JulianServerProxy
|
||||
{
|
||||
public:
|
||||
ICalComponent* ic;
|
||||
|
||||
JulianServerProxy() {};
|
||||
virtual ~JulianServerProxy() {};
|
||||
ICalComponent* getByUid(char *uid) { return ic; };
|
||||
|
||||
void setICal(ICalComponent* i) { ic = i; };
|
||||
|
||||
};
|
||||
|
||||
#include "formFactory.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char* type;
|
||||
char* data;
|
||||
} form_data_combo;
|
||||
|
||||
class JULIAN_PUBLIC JulianForm
|
||||
{
|
||||
private:
|
||||
|
||||
JulianString htmlForm;
|
||||
char* mimedata;
|
||||
char buttonLabel[2048];
|
||||
NSCalendar* imipCal;
|
||||
pJulian_Form_Callback_Struct JulianForm_CallBacks;
|
||||
/* added 7-7-98 */
|
||||
static XP_Bool ms_bFoundNLSDataDirectory;
|
||||
JulianFormFactory* jff;
|
||||
|
||||
public:
|
||||
JulianForm();
|
||||
virtual ~JulianForm();
|
||||
|
||||
int32 refcount; /* Who's looking at this */
|
||||
int32 formDataCount; /* number of pointers in formData */
|
||||
PRMonitor * my_monitor;
|
||||
|
||||
/* number of possible pointers in formData */
|
||||
#define formDataIndex 10
|
||||
form_data_combo formData[formDataIndex]; /* a pointer to an array of pointers that point to a type/data string */
|
||||
|
||||
char* contextName;
|
||||
|
||||
XP_Bool StartHTML();
|
||||
char* getHTMLForm(XP_Bool Want_Detail, NET_StreamClass *this_stream = nil);
|
||||
void setMimeData(char *mimedata);
|
||||
void setCallbacks(pJulian_Form_Callback_Struct callBacks) { JulianForm_CallBacks = callBacks; };
|
||||
pJulian_Form_Callback_Struct getCallbacks() { return JulianForm_CallBacks; };
|
||||
|
||||
void setCalendar(NSCalendar* newCal) { imipCal = newCal; }
|
||||
NSCalendar * getCalendar() { return imipCal; }
|
||||
JulianPtrArray * getEvents() { if (imipCal) { return imipCal->getEvents(); } else return 0; }
|
||||
|
||||
/* added 7-7-98 */
|
||||
static void setFoundNLSDataDirectory(XP_Bool bFound) { ms_bFoundNLSDataDirectory = bFound; }
|
||||
static XP_Bool isFoundNLSDataDirectory() { return ms_bFoundNLSDataDirectory; }
|
||||
|
||||
MWContext* getContext() { return (*JulianForm_CallBacks->FindNamedContextInList)((*JulianForm_CallBacks->FindSomeContext)(), contextName); }
|
||||
|
||||
XP_Bool hasComment() { return getComment() != nil; }
|
||||
char* getComment();
|
||||
char* getDelTo();
|
||||
|
||||
char* getLabel() { return buttonLabel; }
|
||||
void setLabel(char *newlabel) { if (newlabel) XP_STRCPY(buttonLabel, newlabel); if (getCallbacks() && getCallbacks()->PlusToSpace) (*getCallbacks()->PlusToSpace)(buttonLabel); }
|
||||
};
|
||||
|
||||
XP_BEGIN_PROTOS
|
||||
|
||||
JulianForm* jform_CreateNewForm (char *calendar_mime_data, pJulian_Form_Callback_Struct callbacks, XP_Bool bFoundNLSDataDirectory);
|
||||
void jform_DeleteForm (JulianForm *jf);
|
||||
char* jform_GetForm (JulianForm *jf);
|
||||
void jform_CallBack (JulianForm *jf, char *type);
|
||||
|
||||
XP_END_PROTOS
|
||||
#endif
|
||||
|
||||
530
mozilla/calendar/modules/core/htmlform/inc/formFactory.h
Normal file
530
mozilla/calendar/modules/core/htmlform/inc/formFactory.h
Normal file
@@ -0,0 +1,530 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#ifndef _JULIAN_FormFactory_H
|
||||
#define _JULIAN_FormFactory_H
|
||||
|
||||
#include "jdefines.h"
|
||||
#include "julnstr.h"
|
||||
|
||||
class JulianForm;
|
||||
#if defined(XP_PC)
|
||||
#pragma warning ( disable : 4251 )
|
||||
#endif
|
||||
|
||||
const int32 jff_clip_events = 50;
|
||||
|
||||
class JULIAN_PUBLIC JulianFormFactory
|
||||
{
|
||||
friend class JulianForm;
|
||||
|
||||
public:
|
||||
JulianFormFactory();
|
||||
JulianFormFactory(NSCalendar& imipCal);
|
||||
JulianFormFactory(NSCalendar& imipCal, JulianServerProxy* jsp);
|
||||
JulianFormFactory(NSCalendar& imipCal, JulianForm& hostForm, pJulian_Form_Callback_Struct callbacks);
|
||||
|
||||
/*
|
||||
** Call init before calling getHTML()
|
||||
*/
|
||||
void init();
|
||||
|
||||
virtual ~JulianFormFactory();
|
||||
|
||||
/*
|
||||
** Returns a new UnicodeString with html that is intended to be enclosed in a real html file.
|
||||
** Call is responable for disposing of the returned UnicodeString.
|
||||
*/
|
||||
XP_Bool getHTML(JulianString* htmlstorage, XP_Bool want_detail = FALSE);
|
||||
XP_Bool getHTML(JulianString* OutString, NET_StreamClass *this_stream, XP_Bool want_detail = FALSE);
|
||||
|
||||
/*
|
||||
** Sets the base NSCalendar.
|
||||
*/
|
||||
void setNSCalendar(NSCalendar& newCalendar) { firstCalendar = &newCalendar; }
|
||||
|
||||
/*
|
||||
** These are the different form button types. The call back url will list
|
||||
** as it's first thing the type = the name.
|
||||
*/
|
||||
static JulianString Buttons_Details_Type;
|
||||
static JulianString Buttons_Add_Type;
|
||||
static JulianString Buttons_Close_Type;
|
||||
static JulianString Buttons_Accept_Type;
|
||||
static JulianString Buttons_Decline_Type;
|
||||
static JulianString Buttons_Tentative_Type;
|
||||
static JulianString Buttons_SendFB_Type;
|
||||
static JulianString Buttons_SendRefresh_Type;
|
||||
static JulianString Buttons_DelTo_Type;
|
||||
static JulianString CommentsFieldName;
|
||||
static JulianString DelToFieldName;
|
||||
static JulianString SubjectSep;
|
||||
|
||||
private:
|
||||
NSCalendar* firstCalendar; // Base NSCalendar
|
||||
ICalComponent* thisICalComp; // Current vEnvent or vFreeBusy that is being made into html
|
||||
ICalComponent* serverICalComp; // Current Database Version vEnvent or vFreeBusy that is being made into html
|
||||
XP_Bool detail;
|
||||
JulianString* s; // Holds the html that is being built up.
|
||||
JulianForm* jf;
|
||||
JulianServerProxy* ServerProxy; // How to get to the server
|
||||
int32 maxical; // # of vevetns otr vfreebusy in the array
|
||||
int32 aref_count; // For muiltevent table of contents
|
||||
int32 aref2_count; // For muiltevent each form. must be in sync with aref_count
|
||||
pJulian_Form_Callback_Struct cb;// How to call code to create urls for the buttons
|
||||
NET_StreamClass *outStream; // Could be streamed output. Optional
|
||||
XP_Bool do_capi_login; // Default is not to ask for capi login info
|
||||
|
||||
// Use by the freebusy table. In order.
|
||||
enum FB_State {
|
||||
Empty_State,
|
||||
Free_State,
|
||||
XParam_State,
|
||||
Busy_State
|
||||
};
|
||||
|
||||
nsCalDuration MinutesPerSlot;
|
||||
int32 SlotsPerHour;
|
||||
XP_Bool displayTimeZone;
|
||||
int32 scaleType; // 1 = days 1 to 31, 2 = hours 0 to 24
|
||||
int32 slotsacross;
|
||||
int32 hoursToDisplay; // 1 to 24. default is 24 hours
|
||||
FB_State state; // For free, busy, skip state
|
||||
FB_State new_state;
|
||||
int32 count;
|
||||
JulianString tz;
|
||||
JulianString uTemp;
|
||||
JulianString lineFormat;
|
||||
char* TimeHour_HTML;
|
||||
int32 start_hour;
|
||||
int32 end_hour;
|
||||
DateTime start;
|
||||
DateTime end;
|
||||
TimeZone* default_tz;
|
||||
Period* p;
|
||||
Freebusy* fb;
|
||||
int32 fbIndex;
|
||||
int32 pIndex;
|
||||
JulianPtrArray* pv;
|
||||
JulianPtrArray* fbv;
|
||||
|
||||
// These bools show what types of ical objects are being used in this message
|
||||
XP_Bool isEvent;
|
||||
XP_Bool isFreeBusy;
|
||||
|
||||
void SetDetail(XP_Bool newDetail) { detail = newDetail; };
|
||||
XP_Bool isDetail() { return detail;};
|
||||
XP_Bool isPreProcessed(JulianString& icalpropstr) { return (ICalPreProcess.IndexOf(icalpropstr.GetBuffer(), 0) >= 0); };
|
||||
XP_Bool isPostProcessed(JulianString& icalpropstr) { return (ICalPostProcess.IndexOf(icalpropstr.GetBuffer(), 0) >= 0); };
|
||||
|
||||
JulianString * doARef(JulianString& refText, JulianString& refTarget, JulianString* outputString);
|
||||
JulianString * doFont(JulianString& fontText, JulianString* outputString);
|
||||
JulianString * doItalic(JulianString& ItalicText, JulianString* outputString);
|
||||
JulianString * doBold(JulianString& BoldText, JulianString* outputString);
|
||||
JulianString * doBold(char* BoldText, JulianString* outputString);
|
||||
|
||||
void doAddHTML(UnicodeString & moreHtml) { char*y = moreHtml.toCString(""); if (y) {*s += y; delete y;} flush_stream(); };
|
||||
void doAddHTML(JulianString & moreHtml) { *s += moreHtml; flush_stream();};
|
||||
void doAddHTML(JulianString * moreHtml) { *s +=*moreHtml; flush_stream();};
|
||||
void doAddHTML(char* moreHtml) { *s += moreHtml; flush_stream();};
|
||||
int32 flush_stream();
|
||||
|
||||
void doPreProcessing(char* icalpropstr);
|
||||
void doPreProcessingDateTime(JulianString & icalpropstr, XP_Bool allday, DateTime &start, DateTime &end, ICalComponent &ic);
|
||||
void doPreProcessingAttend(ICalComponent &ic);
|
||||
void doPreProcessingOrganizer(ICalComponent &ic);
|
||||
void doDifferenceProcessing(JulianString icalpropstr);
|
||||
void doDifferenceProcessingAttendees();
|
||||
void doHeaderMuiltStart();
|
||||
void doHeaderMuilt();
|
||||
void doHeaderMuiltEnd();
|
||||
|
||||
void doProps(int32 labelCount, JulianString labels[], int32 dataCount, JulianString data[]);
|
||||
void doHeader(JulianString HeaderText);
|
||||
void doClose();
|
||||
void doStatus();
|
||||
void doSingleTableLine(JulianString & labelString, JulianString & dataString, XP_Bool addSpacer = TRUE);
|
||||
void doCommentText();
|
||||
JulianString doCreateButton(JulianString InputType, JulianString ButtonName, XP_Bool addtextField = FALSE);
|
||||
void doAddGroupButton(JulianString GroupButton_HTML);
|
||||
void doAddButton(JulianString SingleButton_HTML);
|
||||
void doMakeFreeBusyTable();
|
||||
|
||||
void HandleError();
|
||||
void HandlePublishVEvent();
|
||||
void HandlePublishVFreeBusy(XP_Bool isPublish);
|
||||
void HandleRequestVEvent();
|
||||
void HandleRequestVFreeBusy();
|
||||
void HandleEventReplyVEvent();
|
||||
void HandleEventCancelVEvent();
|
||||
void HandleEventRefreshRequestVEvent();
|
||||
void HandleEventCounterPropVEvent();
|
||||
void HandleDeclineCounterVEvent();
|
||||
|
||||
char* getJulianErrorString(int32 ErrorNum);
|
||||
|
||||
/* Table Utils Functions */
|
||||
void addLegend();
|
||||
void addTimeZone();
|
||||
void addMajorScale();
|
||||
void addMinorScale();
|
||||
void addTicksScale();
|
||||
/*void emptyRow();*/
|
||||
void makeHourFBTable();
|
||||
void makeDaysFBTable();
|
||||
void DaysLineInc(DateTime* dtTime);
|
||||
void MonthLineInc(DateTime* dtTime);
|
||||
void LineInc(DateTime* dtTime);
|
||||
int32 LineCheck(DateTime& baseTime, DateTime& checkTime, DateTime& checkTimeEnd);
|
||||
void enterState(FB_State newState, XP_Bool forse);
|
||||
void checkPeriodBounds(DateTime& startofslot, DateTime& endofslot);
|
||||
Period* getNextPeriod();
|
||||
int32 getFBType();
|
||||
|
||||
JulianString MoreErrors;
|
||||
JulianString TooManyEvents;
|
||||
JulianString error0;
|
||||
JulianString error1;
|
||||
JulianString error2;
|
||||
JulianString error3;
|
||||
JulianString error4;
|
||||
JulianString error5;
|
||||
JulianString error6;
|
||||
JulianString error7;
|
||||
|
||||
static char* Start_HTML;
|
||||
static char* End_HTML;
|
||||
static char* Props_Head_HTML;
|
||||
static char* Props_HTML_Before_Label;
|
||||
static char* Props_HTML_After_Label;
|
||||
static char* Props_HTML_After_Data;
|
||||
static char* Props_HTML_Empty_Label;
|
||||
static char* Props_End_HTML;
|
||||
static char* General_Header_Start_HTML;
|
||||
static char* General_Header_Status_HTML;
|
||||
static char* General_Header_End_HTML;
|
||||
static char* Head2_HTML;
|
||||
static char* Italic_Start_HTML;
|
||||
static char* Italic_End_HTML;
|
||||
static char* Bold_Start_HTML;
|
||||
static char* Bold_End_HTML;
|
||||
static char* Aref_Start_HTML;
|
||||
static char* Aref_End_HTML;
|
||||
static char* ArefTag_End_HTML;
|
||||
static char* nbsp;
|
||||
static char* Accepted_Gif_HTML;
|
||||
static char* Declined_Gif_HTML;
|
||||
static char* Delegated_Gif_HTML;
|
||||
static char* NeedsAction_Gif_HTML;
|
||||
static char* Question_Gif_HTML;
|
||||
static char* Line_3_HTML;
|
||||
static char* Cell_Start_HTML;
|
||||
static char* Cell_End_HTML;
|
||||
static char* Font_Fixed_Start_HTML;
|
||||
static char* Font_Fixed_End_HTML;
|
||||
static char* Line_Break_HTML;
|
||||
|
||||
static char* Start_Font;
|
||||
static char* Start_BIG_Font;
|
||||
static char* End_Font;
|
||||
|
||||
static char* Buttons_Single_Start_HTML;
|
||||
static char* Buttons_Single_Mid_HTML;
|
||||
static char* Buttons_Single_End_HTML;
|
||||
static char* Buttons_Text_End_HTML;
|
||||
|
||||
JulianString Buttons_Details_Label;
|
||||
JulianString Buttons_Add_Label;
|
||||
JulianString Buttons_Close_Label;
|
||||
JulianString Buttons_Accept_Label;
|
||||
JulianString Buttons_AcceptAll_Label;
|
||||
JulianString Buttons_Update_Label;
|
||||
JulianString Buttons_Decline_Label;
|
||||
JulianString Buttons_Tentative_Label;
|
||||
JulianString Buttons_SendFB_Label;
|
||||
JulianString Buttons_SendRefresh_Label;
|
||||
JulianString Buttons_DelTo_Label;
|
||||
|
||||
static char* Buttons_SaveDel_HTML;
|
||||
|
||||
static char* Buttons_GroupStart_HTML;
|
||||
static char* Buttons_GroupEnd_HTML;
|
||||
static char* Buttons_GroupSingleStart_HTML;
|
||||
static char* Buttons_GroupSingleEnd_HTML;
|
||||
|
||||
static char* Text_Label_Start_HTML;
|
||||
static JulianString Text_Label;
|
||||
static char* Text_Label_End_HTML;
|
||||
static char* Text_Field_HTML;
|
||||
|
||||
static JulianString ICalPreProcess;
|
||||
static JulianString ICalPostProcess;
|
||||
|
||||
JulianString EventInSchedule;
|
||||
JulianString EventNotInSchedule;
|
||||
JulianString EventConflict;
|
||||
JulianString EventNote;
|
||||
JulianString EventError;
|
||||
JulianString EventTest;
|
||||
JulianString Text_To;
|
||||
JulianString Text_AllDay;
|
||||
JulianString Text_StartOn;
|
||||
JulianString Text_Was;
|
||||
JulianString MuiltEvent;
|
||||
JulianString WhenStr;
|
||||
JulianString WhatStr;
|
||||
|
||||
JulianString MuiltEvent_Header_HTML;
|
||||
JulianString MuiltFB_Header_HTML;
|
||||
|
||||
char* String_What;
|
||||
char* String_When;
|
||||
char* String_Location;
|
||||
char* String_Organizer;
|
||||
char* String_Status;
|
||||
char* String_Priority;
|
||||
char* String_Categories;
|
||||
char* String_Resources;
|
||||
char* String_Attachments ;
|
||||
char* String_Alarms;
|
||||
char* String_Created ;
|
||||
char* String_Last_Modified;
|
||||
char* String_Sent;
|
||||
char* String_UID ;
|
||||
|
||||
/*
|
||||
** Free/Busy Table
|
||||
*/
|
||||
static char* FBT_Start_HTML;
|
||||
static char* FBT_End_HTML;
|
||||
static char* FBT_NewRow_HTML;
|
||||
static char* FBT_EndRow_HTML;
|
||||
static char* FBT_TimeHead_HTML;
|
||||
static char* FBT_TimeHeadEnd_HTML;
|
||||
static char* FBT_TimeHour_HTML;
|
||||
static char* FBT_TimeHourEnd_HTML;
|
||||
static char* FBT_TD_HourColor_HTML;
|
||||
static char* FBT_TD_HourColorEnd_HTML;
|
||||
static char* FBT_TD_MinuteColor_HTML;
|
||||
static char* FBT_TD_MinuteColorEnd_HTML;
|
||||
static char* FBT_TDOffsetCell_HTML;
|
||||
static char* FBT_TickLong_HTML;
|
||||
static char* FBT_TickShort_HTML;
|
||||
static char* FBT_TimeMin_HTML;
|
||||
static char* FBT_TimeMinEnd_HTML;
|
||||
static char* FBT_HourStart;
|
||||
static char* FBT_HourEnd;
|
||||
|
||||
static char* FBT_DayStart_HTML;
|
||||
static char* FBT_DayEnd_HTML;
|
||||
static char* FBT_DayEmptyCell_HTML;
|
||||
static char* FBT_DayFreeCell_HTML;
|
||||
static char* FBT_DayBusyCell_HTML;
|
||||
static char* FBT_DayXParamCell_HTML;
|
||||
static char* FBT_EmptyRow_HTML;
|
||||
static char* FBT_DayXColFreeCell_HTML;
|
||||
static char* FBT_DayXColBusyCell_HTML;
|
||||
static char* FBT_DayXColEmptyCell_HTML;
|
||||
static char* FBT_DayXXParamCell_HTML;
|
||||
|
||||
static char* FBT_MonthFormat;
|
||||
static char* FBT_TickDaySetting;
|
||||
|
||||
static char* FBT_Legend_Start_HTML;
|
||||
static char* FBT_Legend_Text1_HTML;
|
||||
static char* FBT_Legend_Text2_HTML;
|
||||
static char* FBT_Legend_Text3_HTML;
|
||||
static char* FBT_Legend_Text4_HTML;
|
||||
static char* FBT_Legend_Text5_HTML;
|
||||
static char* FBT_Legend_TextEnd_HTML;
|
||||
static char* FBT_Legend_End_HTML;
|
||||
|
||||
JulianString FBT_Legend_Title;
|
||||
JulianString FBT_Legend_Free;
|
||||
JulianString FBT_Legend_Busy;
|
||||
JulianString FBT_Legend_Unknown;
|
||||
JulianString FBT_Legend_xparam;
|
||||
|
||||
JulianString FBT_AM;
|
||||
JulianString FBT_PM;
|
||||
static char* FBT_TickMark1;
|
||||
static char* FBT_TickMark2;
|
||||
static char* FBT_TickMark3;
|
||||
static char* FBT_TickMark4;
|
||||
static char* FBT_TickSetting;
|
||||
static char* FBT_TickOffset;
|
||||
static char* FBT_DayFormat;
|
||||
|
||||
/*
|
||||
** Error
|
||||
*/
|
||||
char* error_Header_HTML;
|
||||
static int32 error_Fields_Labels_Length;
|
||||
static JulianString error_Fields_Labels[];
|
||||
static int32 error_Fields_Data_HTML_Length;
|
||||
static JulianString error_Fields_Data_HTML[];
|
||||
static char* error_End_HTML ;
|
||||
|
||||
/*
|
||||
** Publish
|
||||
*/
|
||||
char* publish_Header_HTML;
|
||||
static int32 publish_Fields_Labels_Length;
|
||||
static JulianString publish_Fields_Labels[];
|
||||
static int32 publish_Fields_Data_HTML_Length;
|
||||
static JulianString publish_Fields_Data_HTML[];
|
||||
static char* publish_End_HTML;
|
||||
|
||||
/*
|
||||
** Publish Detail
|
||||
*/
|
||||
static int32 publish_D_Fields_Labels_Length;
|
||||
static JulianString publish_D_Fields_Labels[];
|
||||
static int32 publish_D_Fields_Data_HTML_Length;
|
||||
static JulianString publish_D_Fields_Data_HTML[];
|
||||
|
||||
/*
|
||||
** Publish VFreeBusy
|
||||
*/
|
||||
char* publishFB_Header_HTML;
|
||||
char* replyFB_Header_HTML;
|
||||
static int32 publishFB_Fields_Labels_Length;
|
||||
static JulianString publishFB_Fields_Labels[];
|
||||
static int32 publishFB_Fields_Data_HTML_Length;
|
||||
static JulianString publishFB_Fields_Data_HTML[];
|
||||
static char* publishFB_End_HTML;
|
||||
|
||||
/*
|
||||
** Publish VFreeBusy Detail
|
||||
*/
|
||||
static int32 publishFB_D_Fields_Labels_Length;
|
||||
static JulianString publishFB_D_Fields_Labels[];
|
||||
static int32 publishFB_D_Fields_Data_HTML_Length;
|
||||
static JulianString publishFB_D_Fields_Data_HTML[];
|
||||
|
||||
/*
|
||||
** Request
|
||||
*/
|
||||
char* request_Header_HTML;
|
||||
static int32 request_Fields_Labels_Length;
|
||||
static JulianString request_Fields_Labels[];
|
||||
static int32 request_Fields_Data_HTML_Length;
|
||||
static JulianString request_Fields_Data_HTML[];
|
||||
static char* request_End_HTML;
|
||||
|
||||
/*
|
||||
** Request Detail
|
||||
*/
|
||||
static int32 request_D_Fields_Labels_Length;
|
||||
static JulianString request_D_Fields_Labels[];
|
||||
static int32 request_D_Fields_Data_HTML_Length;
|
||||
static JulianString request_D_Fields_Data_HTML[];
|
||||
|
||||
/*
|
||||
** Request VFreeBusy
|
||||
*/
|
||||
char* request_FB_Header_HTML;
|
||||
static int32 request_FB_Fields_Labels_Length;
|
||||
static JulianString request_FB_Fields_Labels[];
|
||||
static int32 request_FB_Fields_Data_HTML_Length;
|
||||
static JulianString request_FB_Fields_Data_HTML[];
|
||||
static char* request_FB_End_HTML;
|
||||
|
||||
/*
|
||||
** Request VFreeBusy Detail
|
||||
*/
|
||||
char* request_D_FB_Header_HTML;
|
||||
static int32 request_D_FB_Fields_Labels_Length;
|
||||
static JulianString request_D_FB_Fields_Labels[];
|
||||
static int32 request_D_FB_Fields_Data_HTML_Length;
|
||||
static JulianString request_D_FB_Fields_Data_HTML[];
|
||||
static char* request_D_FB_End_HTML;
|
||||
|
||||
/*
|
||||
** Event Reply
|
||||
*/
|
||||
char* eventreply_Header_HTML;
|
||||
static int32 eventreply_Fields_Labels_Length;
|
||||
static JulianString eventreply_Fields_Labels[];
|
||||
static int32 eventreply_Fields_Data_HTML_Length;
|
||||
static JulianString eventreply_Fields_Data_HTML[];
|
||||
static char* eventreply_End_HTML;
|
||||
|
||||
/*
|
||||
** Event Reply Detail
|
||||
*/
|
||||
static int32 eventreply_D_Fields_Labels_Length;
|
||||
static JulianString eventreply_D_Fields_Labels[];
|
||||
static int32 eventreply_D_Fields_Data_HTML_Length;
|
||||
static JulianString eventreply_D_Fields_Data_HTML[];
|
||||
|
||||
/*
|
||||
** Event Cancel
|
||||
*/
|
||||
char* eventcancel_Header_HTML;
|
||||
static int32 eventcancel_Fields_Labels_Length;
|
||||
static JulianString eventcancel_Fields_Labels[];
|
||||
static int32 eventcancel_Fields_Data_HTML_Length;
|
||||
static JulianString eventcancel_Fields_Data_HTML[];
|
||||
static char* eventcancel_End_HTML;
|
||||
|
||||
/*
|
||||
** Event Cancel Detail
|
||||
*/
|
||||
static int32 eventcancel_D_Fields_Labels_Length;
|
||||
static JulianString eventcancel_D_Fields_Labels[];
|
||||
static int32 eventcancel_D_Fields_Data_HTML_Length;
|
||||
static JulianString eventcancel_D_Fields_Data_HTML[];
|
||||
|
||||
/*
|
||||
** Event Refresh Request
|
||||
*/
|
||||
char* eventrefreshreg_Header_HTML;
|
||||
static int32 eventrefreshreg_Fields_Labels_Length;
|
||||
static JulianString eventrefreshreg_Fields_Labels[];
|
||||
static int32 eventrefreshreg_Fields_Data_HTML_Length;
|
||||
static JulianString eventrefreshreg_Fields_Data_HTML[];
|
||||
static char* eventrefreshreg_End_HTML;
|
||||
|
||||
/*
|
||||
** Event Refresh Request Detail
|
||||
*/
|
||||
static int32 eventrefreshreg_D_Fields_Labels_Length;
|
||||
static JulianString eventrefreshreg_D_Fields_Labels[];
|
||||
static int32 eventrefreshreg_D_Fields_Data_HTML_Length;
|
||||
static JulianString eventrefreshreg_D_Fields_Data_HTML[];
|
||||
|
||||
/*
|
||||
** Event Counter Proposal
|
||||
*/
|
||||
char* eventcounterprop_Header_HTML;
|
||||
|
||||
/*
|
||||
** Event Deline Counter
|
||||
*/
|
||||
char* eventdelinecounter_Header_HTML;
|
||||
static int32 eventdelinecounter_Fields_Labels_Length;
|
||||
static JulianString eventdelinecounter_Fields_Labels[];
|
||||
static int32 eventdelinecounter_Fields_Data_HTML_Length;
|
||||
static JulianString eventdelinecounter_Fields_Data_HTML[];
|
||||
};
|
||||
#if defined(XP_PC)
|
||||
#pragma warning ( default : 4251 )
|
||||
#endif
|
||||
|
||||
#endif
|
||||
166
mozilla/calendar/modules/core/htmlform/inc/julianform.h
Normal file
166
mozilla/calendar/modules/core/htmlform/inc/julianform.h
Normal file
@@ -0,0 +1,166 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#ifndef _JULIANFORM_H
|
||||
#define _JULIANFORM_H
|
||||
|
||||
#include "jdefines.h"
|
||||
#include "netcburl.h"
|
||||
#include "fe_proto.h"
|
||||
|
||||
XP_BEGIN_PROTOS
|
||||
|
||||
typedef struct Julian_Form_Callback_Struct
|
||||
{
|
||||
/*
|
||||
** callbackurl should be set to NET_CallbackURLCreate(), it's
|
||||
** in netcburl.h. Can also be set to nil.
|
||||
*/
|
||||
char* (*callbackurl)(NET_CallbackURLFunc func, void* closure);
|
||||
|
||||
/*
|
||||
** callbackurlfree should be set to NET_CallbackURLFree(), it's
|
||||
** in netcburl.h. Can also be set to nil.
|
||||
*/
|
||||
int (*callbackurlfree)(NET_CallbackURLFunc func, void* closure);
|
||||
|
||||
/*
|
||||
** Should Link to NET_ParseURL()
|
||||
*/
|
||||
char* (*ParseURL)(const char *url, int wanted);
|
||||
|
||||
/*
|
||||
** Should Link to FE_MakeNewWindow()
|
||||
*/
|
||||
MWContext* (*MakeNewWindow)(MWContext *old_context, URL_Struct *url, char *window_name, Chrome *chrome);
|
||||
|
||||
/*
|
||||
** Should Link to NET_CreateURLStruct ();
|
||||
*/
|
||||
URL_Struct* (*CreateURLStruct) (const char *url, NET_ReloadMethod force_reload);
|
||||
|
||||
/*
|
||||
** Should Link to PA_BeginParseMDL()
|
||||
*/
|
||||
NET_StreamClass* (*BeginParseMDL) (FO_Present_Types format_out, void *init_data, URL_Struct *anchor, MWContext *window_id);
|
||||
|
||||
/*
|
||||
** Should Link to NET_SACopy()
|
||||
*/
|
||||
char* (*SACopy) (char **dest, const char *src);
|
||||
|
||||
/*
|
||||
** Should Link to NET_SendMessageUnattended(). Added by John Sun 4-22-98.
|
||||
*/
|
||||
int (*SendMessageUnattended) (MWContext* context, char* to, char* subject, char* otherheaders, char* body);
|
||||
|
||||
/*
|
||||
** Should Link to FE_DestroyWindow. Added by John Sun 4-22-98.
|
||||
*/
|
||||
void (*DestroyWindow) (MWContext* context);
|
||||
|
||||
/*
|
||||
** Should Link to FE_RaiseWindow.
|
||||
*/
|
||||
void (*RaiseWindow) (MWContext* context);
|
||||
|
||||
/*
|
||||
** Should Link to Current MWContext.
|
||||
*/
|
||||
MWContext* my_context;
|
||||
|
||||
/*
|
||||
** Should Link to XP_GetString.
|
||||
*/
|
||||
char* (*GetString) (int i);
|
||||
|
||||
/*
|
||||
** Should Link to XP_FindSomeContext()
|
||||
*/
|
||||
MWContext* (*FindSomeContext)();
|
||||
|
||||
/*
|
||||
** Should Link to XP_FindNamedContextInList()
|
||||
*/
|
||||
MWContext* (*FindNamedContextInList)(MWContext* context, char *name);
|
||||
|
||||
/*
|
||||
** Should Link to PREF_CopyCharPref()
|
||||
*/
|
||||
int (*CopyCharPref)(const char *pref, char ** return_buf);
|
||||
|
||||
/*
|
||||
** Should Link to NET_UnEscape()
|
||||
*/
|
||||
char* (*UnEscape)(char *str);
|
||||
|
||||
/*
|
||||
** Should Link to NET_PlusToSpace()
|
||||
*/
|
||||
void (*PlusToSpace)(char *str);
|
||||
|
||||
/*
|
||||
** Should Link to PREF_SetCharPref()
|
||||
*/
|
||||
int (*SetCharPref)(const char *pref, const char* buf);
|
||||
|
||||
/*
|
||||
** Should Link to FE_PromptUsernameAndPassword()
|
||||
*/
|
||||
Bool (*PromptUsernameAndPassword)(MWContext* window_id, char* message, char** username, char** password);
|
||||
|
||||
/*
|
||||
** Should Link to LO_ProcessTag().
|
||||
*/
|
||||
intn (*ProcessTag)(void *data_object, PA_Tag *tag, intn status);
|
||||
|
||||
#if defined(XP_WIN)||defined(XP_UNIX)
|
||||
/*
|
||||
** Should link to FEU_GetJulianPath. Get the path to the Julian directory. Added by John Sun 5-14-98.
|
||||
*/
|
||||
void (*GetJulianPath) (char ** julianPath, void * emptyArg);
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Should Link to PREF_GetBoolPref()
|
||||
*/
|
||||
int (*BoolPref)(const char *pref, XP_Bool * return_val);
|
||||
|
||||
/*
|
||||
** Should Link to PREF_GetIntPref()
|
||||
*/
|
||||
int (*IntPref)(const char *pref, int32 * return_int);
|
||||
|
||||
} Julian_Form_Callback_Struct, *pJulian_Form_Callback_Struct;
|
||||
|
||||
/*
|
||||
** Caller disposes of callbacks.
|
||||
*/
|
||||
XP_Bool JULIAN_PUBLIC jf_Initialize(pJulian_Form_Callback_Struct callbacks);
|
||||
|
||||
void JULIAN_PUBLIC *jf_New(char *calendar_mime_data, XP_Bool bFoundNLSDataDirectory);
|
||||
void JULIAN_PUBLIC jf_Destroy(void *instdata);
|
||||
void JULIAN_PUBLIC jf_Shutdown(void);
|
||||
char JULIAN_PUBLIC *jf_getForm(void *instdata);
|
||||
void JULIAN_PUBLIC jf_setDetail(int detail_form);
|
||||
void JULIAN_PUBLIC jf_callback(void *instdata, char* url, URL_Struct *URL_s);
|
||||
void JULIAN_PUBLIC jf_detail_callback(void *instdata, char *url, URL_Struct *URL_s);
|
||||
|
||||
XP_END_PROTOS
|
||||
|
||||
#endif
|
||||
23
mozilla/calendar/modules/core/htmlform/inc/manifest.mn
Normal file
23
mozilla/calendar/modules/core/htmlform/inc/manifest.mn
Normal file
@@ -0,0 +1,23 @@
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright (C) 1996 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
GDEPTH = ../../../../..
|
||||
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
PRIVATE_EXPORTS = \
|
||||
form.h \
|
||||
formFactory.h \
|
||||
julianform.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = trex
|
||||
|
||||
REQUIRES = raptor
|
||||
15
mozilla/calendar/modules/core/htmlform/manifest.mn
Normal file
15
mozilla/calendar/modules/core/htmlform/manifest.mn
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright (C) 1996 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
GDEPTH = ../../../..
|
||||
DEPTH = ../../../..
|
||||
|
||||
DIRS_EXPORT = inc
|
||||
DIRS_LIBS = src
|
||||
|
||||
53
mozilla/calendar/modules/core/htmlform/src/Makefile
Normal file
53
mozilla/calendar/modules/core/htmlform/src/Makefile
Normal file
@@ -0,0 +1,53 @@
|
||||
#! gmake
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
include config.mk
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/ruleset.mk
|
||||
include $(GDEPTH)/gconfig/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
24
mozilla/calendar/modules/core/htmlform/src/config.mk
Normal file
24
mozilla/calendar/modules/core/htmlform/src/config.mk
Normal file
@@ -0,0 +1,24 @@
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
|
||||
#
|
||||
# Override TARGETS variable so that only static libraries
|
||||
# are specifed as dependencies within rules.mk.
|
||||
#
|
||||
|
||||
CFLAGS +=-D_IMPL_NS_CALENDAR -DNSPR20
|
||||
INCLUDES += -I../inc -I$(GDEPTH)/include -I$(GDEPTH)/htmlparser/src
|
||||
|
||||
LIBRARY_NAME = cal_core_htmlform
|
||||
LIBRARY_VERSION = 10
|
||||
|
||||
ARCHIVE_ONLY = 1
|
||||
|
||||
TARGETS = $(LIBRARY)
|
||||
920
mozilla/calendar/modules/core/htmlform/src/form.cpp
Normal file
920
mozilla/calendar/modules/core/htmlform/src/form.cpp
Normal file
@@ -0,0 +1,920 @@
|
||||
/* -*- 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 "jdefines.h"
|
||||
#include "julnstr.h"
|
||||
|
||||
#include <calendar.h>
|
||||
#include <gregocal.h>
|
||||
#include <datefmt.h>
|
||||
#include <time.h>
|
||||
#include <unistring.h>
|
||||
#include "smpdtfmt.h"
|
||||
#include <simpletz.h>
|
||||
#include "datetime.h"
|
||||
#include "jutility.h"
|
||||
#include "duration.h"
|
||||
|
||||
#include "attendee.h"
|
||||
#include "vevent.h"
|
||||
#include "icalsrdr.h"
|
||||
#include "icalfrdr.h"
|
||||
#include "prprty.h"
|
||||
#include "icalprm.h"
|
||||
#include "freebusy.h"
|
||||
#include "vfrbsy.h"
|
||||
#include "nscal.h"
|
||||
#include "keyword.h"
|
||||
|
||||
#include "txnobjfy.h"
|
||||
#include "user.h"
|
||||
#include "txnobj.h"
|
||||
|
||||
#include "jlog.h"
|
||||
#include "uri.h"
|
||||
|
||||
#include "xp.h"
|
||||
#include "prmon.h"
|
||||
|
||||
#include "form.h"
|
||||
|
||||
static void julian_handle_close(JulianForm *jf);
|
||||
#ifdef OSF1
|
||||
void julian_handle_accept(JulianForm *jf, int newStatus);
|
||||
#else
|
||||
void julian_handle_accept(JulianForm *jf, Attendee::STATUS newStatus);
|
||||
#endif
|
||||
static void julian_handle_moredetail(JulianForm *jf);
|
||||
static void julian_send_response(JulianString& subject, JulianPtrArray& recipients, JulianString& LoginName, JulianForm& jf, NSCalendar& calendar);
|
||||
static void julian_send_response_with_events(JulianString& subject, JulianPtrArray& recipients, JulianString& LoginName, JulianForm& jf, NSCalendar& calendar, JulianPtrArray * events);
|
||||
static void julian_add_new_event_to_send(JulianPtrArray * vvEventsToSend, TimeBasedEvent * eventToSend);
|
||||
static XP_Bool julian_events_comments_and_attendees_match(TimeBasedEvent * a, TimeBasedEvent * b);
|
||||
static void julian_fill_in_delegatedToVector(char * deltonames, JulianPtrArray * vDelegatedToFillIn);
|
||||
|
||||
static void Julian_ClearLoginInfo();
|
||||
static int Julian_GetLoginInfo(JulianForm& jf, MWContext* context, char** url, char** password);
|
||||
|
||||
#define julian_pref_name "calendar.login_url"
|
||||
|
||||
XP_Bool JulianForm::ms_bFoundNLSDataDirectory = FALSE;
|
||||
|
||||
JulianForm *jform_CreateNewForm(char *calendar_mime_data, pJulian_Form_Callback_Struct callbacks,
|
||||
XP_Bool bFoundNLSDataDirectory)
|
||||
{
|
||||
JulianForm *jf = new JulianForm();
|
||||
|
||||
if (jf)
|
||||
{
|
||||
jf->refcount = 1;
|
||||
jf->setMimeData(calendar_mime_data);
|
||||
jf->setCallbacks(callbacks);
|
||||
JulianForm::setFoundNLSDataDirectory(bFoundNLSDataDirectory);
|
||||
}
|
||||
return jf;
|
||||
}
|
||||
|
||||
void jform_DeleteForm(JulianForm *jf)
|
||||
{
|
||||
if (jf)
|
||||
{
|
||||
jf->refcount--;
|
||||
if (jf->refcount == 0)
|
||||
{
|
||||
delete jf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char* jform_GetForm(JulianForm *jf)
|
||||
{
|
||||
jf->StartHTML();
|
||||
return jf->getHTMLForm(FALSE);
|
||||
}
|
||||
|
||||
void jform_CallBack(JulianForm *jf, char *type)
|
||||
{
|
||||
char* button_type;
|
||||
char* button_type2;
|
||||
char* button_data;
|
||||
form_data_combo fdc;
|
||||
int32 x;
|
||||
|
||||
PR_EnterMonitor(jf->my_monitor);
|
||||
/*
|
||||
** type contains the html form string for this.
|
||||
** The gernal format is ? type = label or name = data
|
||||
** The last thing in this list is the button that started
|
||||
** this.
|
||||
*/
|
||||
button_type = XP_STRCHR(type, '?');
|
||||
button_type++; // Skip ?. Now points to type
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
button_type2 = XP_STRCHR(button_type, '=');
|
||||
if (button_type2)
|
||||
{
|
||||
*button_type2++ = '\0';
|
||||
button_data = button_type2; // Points to data part
|
||||
button_type2 = XP_STRCHR(button_type2, '&');
|
||||
} else {
|
||||
button_data = nil;
|
||||
button_type2 = nil;
|
||||
}
|
||||
if (button_type2)
|
||||
{
|
||||
*button_type2++ = '\0';
|
||||
}
|
||||
fdc.type = button_type;
|
||||
fdc.data = button_data;
|
||||
jf->formData[jf->formDataCount] = fdc;
|
||||
jf->formDataCount++;
|
||||
if (!button_type2 || (jf->formDataCount > formDataIndex))
|
||||
break;
|
||||
else
|
||||
button_type = button_type2;
|
||||
|
||||
}
|
||||
|
||||
for (x=0; x < jf->formDataCount; x++)
|
||||
{
|
||||
button_type = jf->formData[x].type;
|
||||
jf->setLabel( button_data = jf->formData[x].data );
|
||||
|
||||
if (!JulianFormFactory::Buttons_Details_Type.CompareTo(button_type))
|
||||
{
|
||||
julian_handle_moredetail(jf);
|
||||
} else
|
||||
if (!JulianFormFactory::Buttons_Accept_Type.CompareTo(button_type))
|
||||
{
|
||||
julian_handle_accept(jf, Attendee::STATUS_ACCEPTED);
|
||||
} else
|
||||
if (!JulianFormFactory::Buttons_Add_Type.CompareTo(button_type))
|
||||
{
|
||||
julian_handle_accept(jf, Attendee::STATUS_ACCEPTED);
|
||||
} else
|
||||
if (!JulianFormFactory::Buttons_Close_Type.CompareTo(button_type))
|
||||
{
|
||||
julian_handle_close(jf);
|
||||
} else
|
||||
if (!JulianFormFactory::Buttons_Decline_Type.CompareTo(button_type))
|
||||
{
|
||||
julian_handle_accept(jf, Attendee::STATUS_DECLINED);
|
||||
} else
|
||||
if (!JulianFormFactory::Buttons_Tentative_Type.CompareTo(button_type))
|
||||
{
|
||||
julian_handle_accept(jf, Attendee::STATUS_TENTATIVE);
|
||||
} else
|
||||
if (!JulianFormFactory::Buttons_SendFB_Type.CompareTo(button_type))
|
||||
{
|
||||
} else
|
||||
if (!JulianFormFactory::Buttons_SendRefresh_Type.CompareTo(button_type))
|
||||
{
|
||||
} else
|
||||
if (!JulianFormFactory::Buttons_DelTo_Type.CompareTo(button_type))
|
||||
{
|
||||
julian_handle_accept(jf, Attendee::STATUS_DELEGATED);
|
||||
}
|
||||
}
|
||||
|
||||
PR_ExitMonitor(jf->my_monitor);
|
||||
}
|
||||
|
||||
/**
|
||||
*** JulianForm Class
|
||||
***
|
||||
*** This is the c++ interface to JulianFormFactory
|
||||
***
|
||||
**/
|
||||
|
||||
JulianForm::JulianForm()
|
||||
{
|
||||
mimedata = nil;
|
||||
imipCal = nil;
|
||||
jff = nil;
|
||||
contextName = "Julian:More Details";
|
||||
formDataCount = 0;
|
||||
my_monitor = PR_NewMonitor();
|
||||
}
|
||||
|
||||
JulianForm::~JulianForm()
|
||||
{
|
||||
if (FALSE && imipCal)
|
||||
{
|
||||
if (imipCal->getLog())
|
||||
delete imipCal->getLog();
|
||||
delete imipCal;
|
||||
imipCal = nil;
|
||||
}
|
||||
|
||||
if (jff)
|
||||
{
|
||||
delete jff;
|
||||
}
|
||||
|
||||
if (my_monitor) PR_DestroyMonitor(my_monitor);
|
||||
}
|
||||
|
||||
XP_Bool
|
||||
JulianForm::StartHTML()
|
||||
{
|
||||
JulianString u;
|
||||
UnicodeString ust;
|
||||
if (imipCal == NULL)
|
||||
{
|
||||
ICalReader *tfr = (ICalReader *) new ICalStringReader(mimedata);
|
||||
mimedata = nil;
|
||||
if (tfr)
|
||||
{
|
||||
JLog * log = new JLog();
|
||||
if (!ms_bFoundNLSDataDirectory)
|
||||
{
|
||||
if (log != 0)
|
||||
{
|
||||
// TODO: finish
|
||||
//log->log("ERROR: Can't find REQUIRED NLS Data Directory\n");
|
||||
}
|
||||
}
|
||||
imipCal = new NSCalendar(log);
|
||||
ust = u.GetBuffer();
|
||||
if (imipCal) imipCal->parse(tfr, ust);
|
||||
delete tfr;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
char*
|
||||
JulianForm::getHTMLForm(XP_Bool Want_Detail, NET_StreamClass *this_stream)
|
||||
{
|
||||
if (imipCal != nil)
|
||||
{
|
||||
if ((jff = new JulianFormFactory(*imipCal, *this, getCallbacks())) != nil)
|
||||
{
|
||||
htmlForm = ""; // Empty it
|
||||
|
||||
jff->init();
|
||||
jff->getHTML(&htmlForm, this_stream, Want_Detail);
|
||||
}
|
||||
}
|
||||
|
||||
char* t2 = (char*) XP_ALLOC(htmlForm.GetStrlen() + 1);
|
||||
if (t2) strcpy(t2, htmlForm.GetBuffer());
|
||||
return t2;
|
||||
}
|
||||
|
||||
void
|
||||
JulianForm::setMimeData(char *NewMimeData)
|
||||
{
|
||||
if (NewMimeData)
|
||||
{
|
||||
mimedata = NewMimeData;
|
||||
}
|
||||
}
|
||||
|
||||
char*
|
||||
JulianForm::getComment()
|
||||
{
|
||||
for (int32 x=0; x < formDataCount; x++)
|
||||
{
|
||||
if (!JulianFormFactory::CommentsFieldName.CompareTo(formData[x].type))
|
||||
{
|
||||
(*getCallbacks()->PlusToSpace)(formData[x].data);
|
||||
(*getCallbacks()->UnEscape) (formData[x].data);
|
||||
return formData[x].data;
|
||||
}
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
char*
|
||||
JulianForm::getDelTo()
|
||||
{
|
||||
for (int32 x=0; x < formDataCount; x++)
|
||||
{
|
||||
char* temp;
|
||||
|
||||
temp = PR_smprintf( "%s", formData[x].type); // Where is a pr_strcpy??
|
||||
if (temp)
|
||||
{
|
||||
(*getCallbacks()->PlusToSpace)(temp);
|
||||
if (!XP_STRCMP(jff->Buttons_DelTo_Label.GetBuffer(), temp))
|
||||
{
|
||||
(*getCallbacks()->PlusToSpace)(formData[x].data);
|
||||
(*getCallbacks()->UnEscape) (formData[x].data);
|
||||
return formData[x].data;
|
||||
}
|
||||
PR_DELETE(temp);
|
||||
}
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
void
|
||||
julian_handle_close(JulianForm *jf)
|
||||
{
|
||||
MWContext* cx = nil;
|
||||
|
||||
if ((cx = jf->getContext()) != nil)
|
||||
{
|
||||
(*jf->getCallbacks()->DestroyWindow)(cx);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
julian_handle_moredetail(JulianForm *jf)
|
||||
{
|
||||
MWContext* cx = nil;
|
||||
char* newhtml = NULL;
|
||||
NET_StreamClass* stream = nil;
|
||||
URL_Struct* url = nil;
|
||||
|
||||
if (jf->getCallbacks() == nil ||
|
||||
jf->getCallbacks()->CreateURLStruct == nil)
|
||||
return;
|
||||
|
||||
url = (*jf->getCallbacks()->CreateURLStruct)("internal_url://", NET_RESIZE_RELOAD);
|
||||
if (url)
|
||||
{
|
||||
url->internal_url = TRUE;
|
||||
(*jf->getCallbacks()->SACopy)(&(url->content_type), TEXT_HTML);
|
||||
|
||||
// Look to see if we already made a window for this
|
||||
if ((cx = jf->getContext()) != nil)
|
||||
{
|
||||
(*jf->getCallbacks()->RaiseWindow)(cx);
|
||||
}
|
||||
|
||||
//
|
||||
// If the more details window isn't there,
|
||||
// make one
|
||||
//
|
||||
if (!cx)
|
||||
{
|
||||
Chrome* customChrome = XP_NEW_ZAP(Chrome);
|
||||
|
||||
/* make the window */
|
||||
if (customChrome)
|
||||
{
|
||||
customChrome->show_scrollbar = TRUE; /* TRUE to show scrollbars on window */
|
||||
customChrome->allow_resize = TRUE; /* TRUE to allow resize of windows */
|
||||
customChrome->allow_close = TRUE; /* TRUE to allow window to be closed */
|
||||
customChrome->disable_commands = TRUE; /* TRUE if user has set hot-keys / menus off */
|
||||
customChrome->restricted_target = TRUE; /* TRUE if window is off-limits for opening links into */
|
||||
}
|
||||
|
||||
cx = (*jf->getCallbacks()->MakeNewWindow)((*jf->getCallbacks()->FindSomeContext)(), nil, jf->contextName, customChrome);
|
||||
}
|
||||
|
||||
if (cx)
|
||||
{
|
||||
static PA_InitData data;
|
||||
|
||||
/* make a netlib stream to display in the window */
|
||||
data.output_func = jf->getCallbacks()->ProcessTag;
|
||||
stream = (*jf->getCallbacks()->BeginParseMDL)(FO_CACHE_AND_VIEW_SOURCE | FO_CACHE_AND_PRESENT_INLINE, &data, url, cx);
|
||||
if (stream)
|
||||
{
|
||||
jf->StartHTML();
|
||||
jf->getHTMLForm(TRUE, stream);
|
||||
(*stream->complete) (stream->data_object);
|
||||
XP_FREE(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
julian_send_response_with_events(JulianString& subject, JulianPtrArray& recipients, JulianString& LoginName, JulianForm& jf, NSCalendar& calendar, JulianPtrArray * events)
|
||||
{
|
||||
TransactionObject::ETxnErrorCode txnStatus;
|
||||
TransactionObject* txnObj;
|
||||
JulianPtrArray* capiModifiers = 0;
|
||||
|
||||
if (jf.getCallbacks() == nil ||
|
||||
jf.getCallbacks()->FindSomeContext == nil)
|
||||
return;
|
||||
|
||||
MWContext* this_context = (*jf.getCallbacks()->FindSomeContext)();
|
||||
|
||||
capiModifiers = new JulianPtrArray();
|
||||
|
||||
if (capiModifiers)
|
||||
{
|
||||
UnicodeString usMeUri = LoginName.GetBuffer();
|
||||
URI meUri(usMeUri);
|
||||
User* uFrom = new User(usMeUri, meUri.getName());
|
||||
char *capurl = NULL, *passwd = NULL;
|
||||
UnicodeString uSubject;
|
||||
UnicodeString uLoginName;
|
||||
XP_Bool do_capi_login = FALSE; /* Default is not to ask for capi login info */
|
||||
|
||||
if (jf.getCallbacks()->BoolPref)
|
||||
(*jf.getCallbacks()->BoolPref)("calendar.capi.enabled", &do_capi_login);
|
||||
|
||||
if (do_capi_login &&
|
||||
Julian_GetLoginInfo(jf, this_context, &capurl, &passwd) > 0)
|
||||
{
|
||||
char* calUser = "";
|
||||
char* calHost = "";
|
||||
char* calNode = "10000";
|
||||
char* temp;
|
||||
|
||||
// Skip pass "capi://", if it is there
|
||||
if (XP_STRSTR(capurl, "://"))
|
||||
{
|
||||
capurl = XP_STRSTR(capurl, "://");
|
||||
capurl += 3;
|
||||
}
|
||||
|
||||
// Break apart the user and host:node parts
|
||||
temp = XP_STRSTR(capurl, "/");
|
||||
if (temp)
|
||||
{
|
||||
calUser = temp;
|
||||
*(calUser) = '\0';
|
||||
calUser++;
|
||||
calHost = capurl;
|
||||
}
|
||||
|
||||
// Break apart the host and node parts
|
||||
temp = XP_STRSTR(calHost, ":");
|
||||
if (temp)
|
||||
{
|
||||
calNode = temp;
|
||||
*(calNode++) = '\0';
|
||||
}
|
||||
|
||||
// Currently the URL login form is as follows:
|
||||
// capi://host:node/login
|
||||
// i.e.
|
||||
// capi://calendar-1.mcom.com:10000/John Sun
|
||||
// TODO: this may change.
|
||||
|
||||
uFrom->setRealName(calUser);
|
||||
uFrom->setCAPIInfo(calUser, passwd, calHost, calNode);
|
||||
if (0)
|
||||
{
|
||||
if (passwd) XP_FREE(passwd);
|
||||
if (capurl) XP_FREE(capurl);
|
||||
}
|
||||
}
|
||||
|
||||
uSubject = subject.GetBuffer();
|
||||
uLoginName = LoginName.GetBuffer();
|
||||
|
||||
txnObj = TransactionObjectFactory::Make(calendar, *(events),
|
||||
*uFrom, recipients, uSubject, *capiModifiers,
|
||||
&jf, this_context, uLoginName);
|
||||
if (txnObj != 0)
|
||||
{
|
||||
txnObj->execute(0, txnStatus);
|
||||
delete txnObj; txnObj = 0;
|
||||
}
|
||||
|
||||
if (uFrom) delete uFrom;
|
||||
|
||||
delete capiModifiers;
|
||||
}
|
||||
|
||||
// If more details windows, then close it
|
||||
// Only if there were no problems
|
||||
if (txnStatus == TransactionObject::TR_OK)
|
||||
{
|
||||
if (jf.getContext())
|
||||
{
|
||||
julian_handle_close(&jf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
julian_send_response(JulianString& subject, JulianPtrArray& recipients, JulianString& LoginName, JulianForm& jf, NSCalendar& calendar)
|
||||
{
|
||||
julian_send_response_with_events(subject, recipients, LoginName, jf, calendar, calendar.getEvents());
|
||||
}
|
||||
|
||||
void
|
||||
julian_fill_in_delegatedToVector(char * deltonames,
|
||||
JulianPtrArray * vDelegatedToFillIn)
|
||||
{
|
||||
if (0 != vDelegatedToFillIn)
|
||||
{
|
||||
UnicodeString mailto = "MAILTO:";
|
||||
UnicodeString del_name;
|
||||
char * nextname;
|
||||
while (*deltonames)
|
||||
{
|
||||
del_name = mailto;
|
||||
nextname = deltonames;
|
||||
|
||||
while (nextname && *nextname && *nextname != ' ')
|
||||
{
|
||||
nextname++;
|
||||
}
|
||||
|
||||
if (*nextname)
|
||||
{
|
||||
*nextname = '\0';
|
||||
nextname++;
|
||||
}
|
||||
|
||||
del_name += deltonames;
|
||||
vDelegatedToFillIn->Add(new UnicodeString(del_name));
|
||||
|
||||
if (!(*nextname))
|
||||
{
|
||||
// Last one
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
deltonames = nextname;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XP_Bool
|
||||
julian_events_comments_and_attendees_match(TimeBasedEvent * a, TimeBasedEvent * b)
|
||||
{
|
||||
if (a != 0 && b != 0)
|
||||
{
|
||||
// comments must match and attendees must match
|
||||
if (a->getComment() != 0 && b->getComment() == 0)
|
||||
return FALSE;
|
||||
if (a->getComment() == 0 && b->getComment() != 0)
|
||||
return FALSE;
|
||||
if (a->getComment() != 0 && b->getComment() != 0)
|
||||
{
|
||||
if (a->getComment()->GetSize() != b->getComment()->GetSize())
|
||||
return FALSE;
|
||||
// only compare 1st comment in vector
|
||||
if (a->getComment()->GetSize() > 0 && b->getComment()->GetSize() > 0)
|
||||
{
|
||||
ICalProperty * iua = 0;
|
||||
ICalProperty * iub = 0;
|
||||
UnicodeString ua, ub;
|
||||
iua = (ICalProperty *) a->getComment()->GetAt(0);
|
||||
iub = (ICalProperty *) b->getComment()->GetAt(0);
|
||||
ua = *((UnicodeString *) iua->getValue());
|
||||
ub = *((UnicodeString *) iub->getValue());
|
||||
if (ua != ub)
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (a->getAttendees() != 0 && b->getAttendees() == 0)
|
||||
return FALSE;
|
||||
if (a->getAttendees() == 0 && b->getAttendees() != 0)
|
||||
return FALSE;
|
||||
if (a->getAttendees() != 0 && b->getAttendees() != 0)
|
||||
{
|
||||
if (a->getAttendees()->GetSize() != b->getAttendees()->GetSize())
|
||||
return FALSE;
|
||||
t_int32 i;
|
||||
Attendee * attA = 0;
|
||||
Attendee * attB = 0;
|
||||
for (i = 0; i < a->getAttendees()->GetSize(); i++)
|
||||
{
|
||||
attA = (Attendee *) a->getAttendees()->GetAt(i);
|
||||
attB = (Attendee *) b->getAttendees()->GetAt(i);
|
||||
if (attA->getName() != attB->getName())
|
||||
return FALSE;
|
||||
if (attA->getStatus() != attB->getStatus())
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
julian_add_new_event_to_send(JulianPtrArray * vvEventsToSend, TimeBasedEvent * eventToSend)
|
||||
{
|
||||
|
||||
if (vvEventsToSend != 0)
|
||||
{
|
||||
XP_Bool bFound = FALSE;
|
||||
int32 i;
|
||||
JulianPtrArray * vEventsToSend = 0;
|
||||
TimeBasedEvent * event;
|
||||
for (i = 0; i < vvEventsToSend->GetSize(); i++)
|
||||
{
|
||||
vEventsToSend = (JulianPtrArray *) vvEventsToSend->GetAt(i);
|
||||
if (vEventsToSend != 0 && vEventsToSend->GetSize() > 0)
|
||||
{
|
||||
event = (TimeBasedEvent *) vEventsToSend->GetAt(0);
|
||||
if (julian_events_comments_and_attendees_match(event, eventToSend))
|
||||
{
|
||||
vEventsToSend->Add(eventToSend);
|
||||
bFound = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!bFound)
|
||||
{
|
||||
JulianPtrArray * evtVctrToAdd = new JulianPtrArray();
|
||||
if (evtVctrToAdd != 0)
|
||||
{
|
||||
evtVctrToAdd->Add(eventToSend);
|
||||
vvEventsToSend->Add(evtVctrToAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
#ifdef OSF1
|
||||
julian_handle_accept(JulianForm *jf, int newStatus)
|
||||
#else
|
||||
julian_handle_accept(JulianForm *jf, Attendee::STATUS newStatus)
|
||||
#endif
|
||||
{
|
||||
NSCalendar* imipCal = jf->getCalendar();
|
||||
ICalComponent* component;
|
||||
JulianString orgName;
|
||||
char* name = nil;
|
||||
JulianString nameU;
|
||||
JulianString subject = JulianString(jf->getLabel());
|
||||
UnicodeString uTemp;
|
||||
int32 i;
|
||||
int32 j;
|
||||
int32 k;
|
||||
|
||||
// this should be set to the logged in user
|
||||
// TODO: make it efficient
|
||||
// TRY to minimize number of calls to julian_send_response_with_events.
|
||||
|
||||
if (jf->getCallbacks()->CopyCharPref)
|
||||
(*jf->getCallbacks()->CopyCharPref)("mail.identity.useremail", &name);
|
||||
if (name)
|
||||
{
|
||||
nameU = "MAILTO:";
|
||||
nameU += name;
|
||||
}
|
||||
|
||||
if (imipCal->getEvents() != 0)
|
||||
{
|
||||
XP_Bool firstTime = TRUE;
|
||||
// process events to send
|
||||
UnicodeString uName = nameU.GetBuffer();
|
||||
JulianPtrArray * vDelegatedTo = 0;
|
||||
char * deltonames = 0;
|
||||
char * cOrgName = 0;
|
||||
char * cSummary = 0;
|
||||
|
||||
XP_Bool bDontSend = FALSE;
|
||||
JulianPtrArray * recipients = 0;
|
||||
TimeBasedEvent * tbe;
|
||||
// The overall strategy
|
||||
// Create a vector of vector of events (vvEventsToReply).
|
||||
// This vector is used to minimize the number of send_response calls (which sends email).
|
||||
// Events with the same comments and attendees(status and name) are placed in the same bucket.
|
||||
// Events in the same bucket are send in the same email message.
|
||||
// Thus I minimize the number of sends response calls.
|
||||
//
|
||||
// Foreach event in calendar,
|
||||
// setAttendeeStatus for this user to newStatus
|
||||
// setComment from comment text-field
|
||||
// setDTSTAMP
|
||||
// if (first event in calendar) set subject to its summary.
|
||||
// add event to vvEventsToReply
|
||||
// Foreach vector in vvEventsToReply
|
||||
// send REPLY message to ORGANIZER
|
||||
// if (delegated status)
|
||||
// send DELEGATE-REQUEST message to DELEGATEEs
|
||||
//
|
||||
JulianPtrArray * vvEventsToReply = new JulianPtrArray();
|
||||
|
||||
for (i = 0; i < imipCal->getEvents()->GetSize(); i++)
|
||||
{
|
||||
component = (ICalComponent *) imipCal->getEvents()->GetAt(i);
|
||||
|
||||
if (component->GetType() == ICalComponent::ICAL_COMPONENT_VEVENT)
|
||||
{
|
||||
tbe = (TimeBasedEvent *) component;
|
||||
// Set org
|
||||
if (orgName.GetStrlen() == 0)
|
||||
{
|
||||
if (tbe->getOrganizer().size() > 0)
|
||||
{
|
||||
cOrgName = (tbe->getOrganizer()).toCString("");
|
||||
if (0 != cOrgName)
|
||||
orgName = cOrgName;
|
||||
}
|
||||
}
|
||||
if (newStatus == Attendee::STATUS_DELEGATED)
|
||||
{
|
||||
deltonames = jf->getDelTo();
|
||||
if ((0 != deltonames) && (XP_STRLEN(deltonames) > 0))
|
||||
{
|
||||
vDelegatedTo = new JulianPtrArray();
|
||||
if (0 != vDelegatedTo)
|
||||
julian_fill_in_delegatedToVector(deltonames, vDelegatedTo);
|
||||
}
|
||||
}
|
||||
tbe->setAttendeeStatusInt(uName, newStatus, vDelegatedTo);
|
||||
|
||||
if (jf->hasComment())
|
||||
{
|
||||
tbe->setNewComments(jf->getComment());
|
||||
}
|
||||
tbe->stamp();
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
// only print subject once and use first summary.
|
||||
subject += JulianFormFactory::SubjectSep;
|
||||
cSummary = (tbe->getSummary()).toCString("");
|
||||
subject += cSummary;
|
||||
}
|
||||
|
||||
julian_add_new_event_to_send(vvEventsToReply, tbe);
|
||||
|
||||
if (vDelegatedTo != 0)
|
||||
{
|
||||
ICalComponent::deleteUnicodeStringVector(vDelegatedTo);
|
||||
delete vDelegatedTo; vDelegatedTo = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
JulianPtrArray * vEventsToReply = 0;
|
||||
JulianPtrArray * replyRecipients = new JulianPtrArray();
|
||||
t_int32 method = imipCal->getMethod();
|
||||
|
||||
// setup reply recipients to contain only organizer
|
||||
if (replyRecipients != 0)
|
||||
{
|
||||
if (method != NSCalendar::METHOD_PUBLISH)
|
||||
{
|
||||
UnicodeString usOrgName = orgName.GetBuffer();
|
||||
URI orgUri(usOrgName);
|
||||
User* uToOrg = new User(usOrgName, orgUri.getName());
|
||||
replyRecipients->Add(uToOrg);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < vvEventsToReply->GetSize(); i++)
|
||||
{
|
||||
vEventsToReply = (JulianPtrArray *) vvEventsToReply->GetAt(i);
|
||||
|
||||
// send reply
|
||||
recipients = replyRecipients;
|
||||
imipCal->setMethod(NSCalendar::METHOD_REPLY);
|
||||
julian_send_response_with_events(subject, *recipients, nameU, *jf, *imipCal, vEventsToReply);
|
||||
recipients = 0;
|
||||
|
||||
// send delegate request message if necessary
|
||||
if (newStatus == Attendee::STATUS_DELEGATED &&
|
||||
method == NSCalendar::METHOD_REQUEST)
|
||||
{
|
||||
deltonames = jf->getDelTo();
|
||||
if ((0 != deltonames) && (XP_STRLEN(deltonames) > 0))
|
||||
{
|
||||
vDelegatedTo = new JulianPtrArray();
|
||||
if (0 != vDelegatedTo)
|
||||
julian_fill_in_delegatedToVector(deltonames, vDelegatedTo);
|
||||
else
|
||||
bDontSend = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
bDontSend = TRUE;
|
||||
}
|
||||
if (!bDontSend)
|
||||
{
|
||||
recipients = new JulianPtrArray();
|
||||
if (recipients != 0)
|
||||
{
|
||||
PR_ASSERT(vDelegatedTo != 0 && vDelegatedTo->GetSize() > 0);
|
||||
User * userDelegate = 0;
|
||||
for (j = 0; j < vDelegatedTo->GetSize(); j++)
|
||||
{
|
||||
uTemp = *((UnicodeString *) vDelegatedTo->GetAt(j));
|
||||
URI delUri(uTemp);
|
||||
userDelegate = new User(uTemp, delUri.getName());
|
||||
for (k = 0; k < vEventsToReply->GetSize(); k++)
|
||||
{
|
||||
component = (ICalComponent *) vEventsToReply->GetAt(k);
|
||||
#ifdef OSF1
|
||||
((TimeBasedEvent *)component)->setAttendeeStatusInt(uTemp, 0);
|
||||
#else
|
||||
((TimeBasedEvent *)component)->setAttendeeStatusInt(uTemp, Attendee::STATUS_NEEDSACTION);
|
||||
#endif
|
||||
}
|
||||
recipients->Add(userDelegate);
|
||||
}
|
||||
imipCal->setMethod(NSCalendar::METHOD_REQUEST);
|
||||
|
||||
julian_send_response_with_events(subject, *recipients, nameU, *jf, *imipCal, vEventsToReply);
|
||||
|
||||
User::deleteUserVector(recipients);
|
||||
delete recipients; recipients = 0;
|
||||
}
|
||||
}
|
||||
if (vDelegatedTo != 0)
|
||||
{
|
||||
ICalComponent::deleteUnicodeStringVector(vDelegatedTo);
|
||||
delete vDelegatedTo; vDelegatedTo = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// delete allocated objects.
|
||||
if (cOrgName != 0)
|
||||
{
|
||||
delete [] cOrgName; cOrgName = 0;
|
||||
}
|
||||
if (cSummary != 0)
|
||||
{
|
||||
delete [] cSummary; cSummary = 0;
|
||||
}
|
||||
if (0 != replyRecipients)
|
||||
{
|
||||
User::deleteUserVector(replyRecipients);
|
||||
delete replyRecipients; replyRecipients = 0;
|
||||
}
|
||||
for (i = vvEventsToReply->GetSize() -1; i >= 0; i--)
|
||||
{
|
||||
vEventsToReply = (JulianPtrArray *) vvEventsToReply->GetAt(i);
|
||||
ICalComponent::deleteICalComponentVector(vEventsToReply);
|
||||
delete vEventsToReply; vEventsToReply = 0;
|
||||
}
|
||||
delete vvEventsToReply; vvEventsToReply = 0;
|
||||
}
|
||||
if (name) XP_FREE(name);
|
||||
}
|
||||
|
||||
void
|
||||
Julian_ClearLoginInfo()
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
Julian_GetLoginInfo(JulianForm& jf, MWContext* context, char** url, char** password) {
|
||||
static char* lastCalPwd = NULL;
|
||||
char* defaultUrl;
|
||||
int status = -2;
|
||||
|
||||
if (jf.getCallbacks() &&
|
||||
jf.getCallbacks()->CopyCharPref)
|
||||
status = (*jf.getCallbacks()->CopyCharPref)(julian_pref_name, &defaultUrl);
|
||||
// -1 is pref isn't there, which will be a normal case for us
|
||||
// Any other neg number is some other bad error so bail.
|
||||
if (status < -1) return status;
|
||||
|
||||
*url = defaultUrl;
|
||||
*password = NULL;
|
||||
|
||||
if (lastCalPwd != NULL)
|
||||
{
|
||||
*password = XP_STRDUP(lastCalPwd);
|
||||
if (*password == NULL) return 0 /*MK_OUT_OF_MEMORY*/;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(*context->funcs->PromptUsernameAndPassword)
|
||||
(context,
|
||||
// XP_GetString(JULIAN_LOGIN_PROMPT),
|
||||
"Enter capi url and password",
|
||||
url,
|
||||
password))
|
||||
{
|
||||
*url = NULL;
|
||||
*password = NULL;
|
||||
status = -1;
|
||||
} else {
|
||||
if (jf.getCallbacks() &&
|
||||
jf.getCallbacks()->SetCharPref)
|
||||
{
|
||||
(*jf.getCallbacks()->SetCharPref)(julian_pref_name, *url);
|
||||
}
|
||||
lastCalPwd = XP_STRDUP(*password);
|
||||
status = 1;
|
||||
}
|
||||
XP_FREE(defaultUrl);
|
||||
return status;
|
||||
}
|
||||
|
||||
2676
mozilla/calendar/modules/core/htmlform/src/formFactory.cpp
Normal file
2676
mozilla/calendar/modules/core/htmlform/src/formFactory.cpp
Normal file
File diff suppressed because it is too large
Load Diff
127
mozilla/calendar/modules/core/htmlform/src/julianform.c
Normal file
127
mozilla/calendar/modules/core/htmlform/src/julianform.c
Normal file
@@ -0,0 +1,127 @@
|
||||
/* -*- 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 <xp_mcom.h>
|
||||
#include "jdefines.h"
|
||||
#include "julianform.h"
|
||||
#include "nlsloc.h"
|
||||
|
||||
#ifdef XP_WIN32
|
||||
/*#include "stdafx.h"*/
|
||||
/*#include "feutil.h"*/
|
||||
#endif
|
||||
|
||||
extern void* jform_CreateNewForm(char *, pJulian_Form_Callback_Struct, XP_Bool);
|
||||
extern void jform_DeleteForm(void *);
|
||||
extern char* jform_GetForm(void *);
|
||||
extern void jform_CallBack(void *, void *);
|
||||
|
||||
pJulian_Form_Callback_Struct JulianForm_CallBacks;
|
||||
XP_Bool bCallbacksSet = PR_FALSE ;
|
||||
|
||||
XP_Bool jf_Initialize(pJulian_Form_Callback_Struct callbacks)
|
||||
{
|
||||
/* for some reason I have to do this little trick to get things to work */
|
||||
char * julian = NULL;
|
||||
char buf[1024];
|
||||
julian = &(buf[0]);
|
||||
|
||||
JulianForm_CallBacks = XP_NEW_ZAP(Julian_Form_Callback_Struct);
|
||||
if (JulianForm_CallBacks && callbacks)
|
||||
{
|
||||
*JulianForm_CallBacks = *callbacks;
|
||||
}
|
||||
|
||||
#if defined(XP_WIN)||defined(XP_UNIX)
|
||||
if (JulianForm_CallBacks && callbacks && callbacks->GetJulianPath)
|
||||
{
|
||||
bCallbacksSet = PR_TRUE ;
|
||||
|
||||
/* set the NLS locale30 path to the location of the locale30 from the registry */
|
||||
JulianForm_CallBacks->GetJulianPath(&julian, (void *)sizeof(buf));
|
||||
|
||||
/* use path if it exist, otherwise you NS_NLS_DATADIRECTORY env var if it exists */
|
||||
/* if neither exists return FALSE */
|
||||
if (JXP_ACCESS(julian, 0) != -1)
|
||||
{
|
||||
NLS_Initialize(NULL, julian);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
char * nlsDDir = getenv("NS_NLS_DATADIRECTORY");
|
||||
if (nlsDDir == 0)
|
||||
return FALSE;
|
||||
else
|
||||
{
|
||||
if (JXP_ACCESS(nlsDDir, 0) == -1)
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void *jf_New(char *calendar_mime_data, XP_Bool bFoundNLSDataDirectory)
|
||||
{
|
||||
return jform_CreateNewForm(calendar_mime_data, JulianForm_CallBacks, bFoundNLSDataDirectory);
|
||||
}
|
||||
|
||||
void jf_Destroy(void *instdata)
|
||||
{
|
||||
jform_DeleteForm(instdata);
|
||||
}
|
||||
|
||||
void jf_Shutdown()
|
||||
{
|
||||
XP_FREEIF(JulianForm_CallBacks);
|
||||
}
|
||||
|
||||
char *jf_getForm(void *instdata)
|
||||
{
|
||||
return jform_GetForm(instdata);
|
||||
}
|
||||
|
||||
void jf_setDetail(int detail_form)
|
||||
{
|
||||
}
|
||||
|
||||
/* rhp - needed to add third parameter for other mime related calls */
|
||||
void jf_callback(void *instdata, char *url, URL_Struct *URL_s)
|
||||
{
|
||||
if (instdata && url)
|
||||
{
|
||||
jform_CallBack(instdata, url);
|
||||
}
|
||||
}
|
||||
|
||||
/* rhp - needed to add third parameter for other mime related calls */
|
||||
/* For some unknown reason there can only be one call back funtion/
|
||||
** instdate per button
|
||||
*/
|
||||
void jf_detail_callback(void *instdata, char *url, URL_Struct *URL_s)
|
||||
{
|
||||
if (instdata && url)
|
||||
{
|
||||
jform_CallBack(instdata, url);
|
||||
}
|
||||
}
|
||||
30
mozilla/calendar/modules/core/htmlform/src/manifest.mn
Normal file
30
mozilla/calendar/modules/core/htmlform/src/manifest.mn
Normal file
@@ -0,0 +1,30 @@
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright (C) 1996 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
GDEPTH = ../../../../..
|
||||
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
PRIVATE_EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
MODULE = trex
|
||||
|
||||
CSRCS = \
|
||||
julianform.c \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
form.cpp \
|
||||
formFactory.cpp \
|
||||
$(NULL)
|
||||
|
||||
REQUIRES = xpcom raptor trex julian nls netlib shell xpfc
|
||||
|
||||
53
mozilla/calendar/modules/core/ical/Makefile
Normal file
53
mozilla/calendar/modules/core/ical/Makefile
Normal file
@@ -0,0 +1,53 @@
|
||||
#! gmake
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
53
mozilla/calendar/modules/core/ical/inc/Makefile
Normal file
53
mozilla/calendar/modules/core/ical/inc/Makefile
Normal file
@@ -0,0 +1,53 @@
|
||||
#! gmake
|
||||
#
|
||||
# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
# NETSCAPE COMMUNICATIONS CORPORATION
|
||||
# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
# Reserved. Use of this Source Code is subject to the terms of the
|
||||
# applicable license agreement from Netscape Communications Corporation.
|
||||
# The copyright notice(s) in this Source Code does not indicate actual or
|
||||
# intended publication of this Source Code.
|
||||
#
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(GDEPTH)/gconfig/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
33
mozilla/calendar/modules/core/ical/inc/abprprty.h
Normal file
33
mozilla/calendar/modules/core/ical/inc/abprprty.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/* -*- Mode: C++; tab-width: 4; tabs-indent-mode: nil -*- */
|
||||
/*
|
||||
* abprprty.h
|
||||
* John Sun
|
||||
* 2/18/98 10:29:50 AM
|
||||
*/
|
||||
|
||||
#include <unistring.h>
|
||||
#include "ptrarray.h"
|
||||
#include "xp_mcom.h"
|
||||
|
||||
#ifndef __ABSTRACTPROPERTY_H_
|
||||
#define __ABSTRACTPROPERTY_H_
|
||||
|
||||
/* pure interface */
|
||||
class AbstractProperty
|
||||
{
|
||||
virtual void * getValue() const { PR_ASSERT(FALSE); return 0;}
|
||||
virtual void setValue(void * value) { if (value != 0) {} PR_ASSERT(FALSE); }
|
||||
|
||||
virtual ICalProperty * clone() { PR_ASSERT(FALSE); return 0; }
|
||||
virtual t_bool isValid() { PR_ASSERT(FALSE); return FALSE; }
|
||||
|
||||
/* return human readable string */
|
||||
virtual UnicodeString & toString(UnicodeString & out) { PR_ASSERT(FALSE); return out; }
|
||||
virtual UnicodeString & toString(UnicodeString & dateFmt,
|
||||
UnicodeString & out) { PR_ASSERT(FALSE); if (dateFmt.size() > 0) {} return out; }
|
||||
/* ical format of value */
|
||||
virtual UnicodeString & toExportString(UnicodeString & out) { PR_ASSERT(FALSE); return out; }
|
||||
};
|
||||
|
||||
#endif /* __ABSTRACTPROPERTY_H_ */
|
||||
|
||||
756
mozilla/calendar/modules/core/ical/inc/attendee.h
Normal file
756
mozilla/calendar/modules/core/ical/inc/attendee.h
Normal file
@@ -0,0 +1,756 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* attendee.h
|
||||
* John Sun
|
||||
* 2/6/98 4:33:43 PM
|
||||
*/
|
||||
|
||||
#ifndef __ATTENDEE_H_
|
||||
#define __ATTENDEE_H_
|
||||
|
||||
#include "ptrarray.h"
|
||||
#include "icalcomp.h"
|
||||
#include "prprty.h"
|
||||
#include "jlog.h"
|
||||
#include "datetime.h"
|
||||
|
||||
/**
|
||||
* The Attendee class encapsulates the data in the iCalendar
|
||||
* ATTENDEE property. This class must implement the interface defined
|
||||
* by the ICalProperty abstract class. The keyword parameters in Attendee
|
||||
* are stored as t_int32. Other parameters are stored as UnicodeStrings
|
||||
* or as JulianPtrArray's of UnicodeStrings.
|
||||
*/
|
||||
class Attendee : public ICalProperty
|
||||
{
|
||||
private:
|
||||
|
||||
/**
|
||||
* For now, hide default constructor.
|
||||
* Currently must pass in a Log object to create an Attendee.
|
||||
*/
|
||||
Attendee();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/* enums of attendee keywords */
|
||||
/** Enumeration of ROLE parameter*/
|
||||
enum ROLE {
|
||||
/*ROLE_ATTENDEE = 0, ROLE_ORGANIZER = 1, ROLE_OWNER = 2,
|
||||
ROLE_DELEGATE = 3, ROLE_LENGTH = 4,
|
||||
|
||||
ROLE_CHAIR = 0, ROLE_PARTICIPANT = 1, ROLE_NON_PARTICIPANT = 2,
|
||||
ROLE_LENGTH = 3, ROLE_INVALID = -1*/
|
||||
|
||||
ROLE_REQ_PARTICIPANT = 0, ROLE_CHAIR = 1, ROLE_OPT_PARTICIPANT = 2,
|
||||
ROLE_NON_PARTICIPANT = 3,
|
||||
ROLE_XPARAMVAL = 4, ROLE_LENGTH = 5, ROLE_INVALID = -1
|
||||
};
|
||||
|
||||
/** Enumeration of CUTYPE parameter*/
|
||||
enum TYPE {
|
||||
TYPE_INDIVIDUAL = 0, TYPE_GROUP = 1,
|
||||
TYPE_RESOURCE = 2, TYPE_ROOM = 3, TYPE_UNKNOWN = 4,
|
||||
TYPE_XPARAMVAL = 5,
|
||||
TYPE_LENGTH = 6, TYPE_INVALID = -1
|
||||
};
|
||||
|
||||
/** Enumeration of PARTSTAT parameter*/
|
||||
enum STATUS {
|
||||
/* For VEVENT, VTODO, VJOURNAL */
|
||||
STATUS_NEEDSACTION = 0, STATUS_XPARAMVAL = 1,
|
||||
STATUS_ACCEPTED = 2, STATUS_DECLINED = 3,
|
||||
|
||||
/* For VEVENT and VTODO only */
|
||||
STATUS_TENTATIVE = 4,
|
||||
STATUS_DELEGATED = 5,
|
||||
|
||||
/* For VTODO only */
|
||||
STATUS_COMPLETED = 6, STATUS_INPROCESS = 7,
|
||||
|
||||
|
||||
STATUS_LENGTH = 8, STATUS_INVALID = -1
|
||||
};
|
||||
|
||||
/**
|
||||
* Is the status variable valid for this component type. For example,
|
||||
* if compType is VEVENT and status is INPROCESS, return FALSE.
|
||||
* But if compType is VTODO and status is INPROCESS, return TRUE.
|
||||
* @param compType component type
|
||||
* @param status status
|
||||
*
|
||||
* @return TRUE if valid status for compType, FALSE otherwise
|
||||
*/
|
||||
static t_bool isValidStatus(ICalComponent::ICAL_COMPONENT compType, Attendee::STATUS status);
|
||||
|
||||
/** Enumeration of RSVP parameter */
|
||||
enum RSVP {
|
||||
RSVP_FALSE = 0, RSVP_TRUE = 1,
|
||||
RSVP_LENGTH = 2, RSVP_INVALID = -1
|
||||
};
|
||||
|
||||
/** Enumeration of EXPECT parameter */
|
||||
enum EXPECT {
|
||||
EXPECT_FYI = 0, EXPECT_REQUIRE = 1, EXPECT_REQUEST = 2,
|
||||
/*EXPECT_IMMEDIATE = 3, EXPECT_LENGTH = 4, */
|
||||
EXPECT_LENGTH = 3, EXPECT_INVALID = -1
|
||||
};
|
||||
|
||||
|
||||
/** Enumeration of all keyword properties in an Attendee */
|
||||
enum PROPS {
|
||||
PROPS_ROLE = 0, PROPS_TYPE = 1,
|
||||
PROPS_STATUS = 2, PROPS_RSVP = 3,
|
||||
PROPS_EXPECT = 4
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts ROLE string to a ROLE enumeration
|
||||
* @param sRole role string
|
||||
*
|
||||
* @return ROLE that represents that string
|
||||
*/
|
||||
static Attendee::ROLE stringToRole(UnicodeString & sRole);
|
||||
|
||||
/**
|
||||
* Converts CUTYPE string to a TYPE enumeration
|
||||
* @param sType type string
|
||||
*
|
||||
* @return TYPE that represents that string
|
||||
*/
|
||||
static Attendee::TYPE stringToType(UnicodeString & sType);
|
||||
|
||||
/**
|
||||
* Converts PARTSTAT string to a AT_PARSTAT enumeration
|
||||
* @param sStatus status string
|
||||
*
|
||||
* @return STATUS that represents that string
|
||||
*/
|
||||
static Attendee::STATUS stringToStatus(UnicodeString & sStatus);
|
||||
|
||||
/**
|
||||
* Converts RSVP string to a RSVP enumeration
|
||||
* @param sRSVP rsvp string
|
||||
*
|
||||
* @return RSVP that represents that string
|
||||
*/
|
||||
static Attendee::RSVP stringToRSVP(UnicodeString & sRSVP);
|
||||
|
||||
/**
|
||||
* Converts EXPECT string to a EXPECT enumeration
|
||||
* @param sExpect expect string
|
||||
*
|
||||
* @return EXPECT that represents that string
|
||||
*/
|
||||
static Attendee::EXPECT stringToExpect(UnicodeString & sExpect);
|
||||
|
||||
/**
|
||||
* Converts ROLE to string. If bad role, return default (REQ_PARTICIPANT).
|
||||
* @param role ROLE enumeration
|
||||
* @param out output role string
|
||||
*
|
||||
* @return output role string (out)
|
||||
*/
|
||||
static UnicodeString & roleToString(Attendee::ROLE role, UnicodeString & out);
|
||||
|
||||
/**
|
||||
* Converts TYPE to string. If bad type, return default (INDIVIDUAL).
|
||||
* @param type TYPE enumeration
|
||||
* @param out output type string
|
||||
*
|
||||
* @return output type string (out)
|
||||
*/
|
||||
static UnicodeString & typeToString(Attendee::TYPE type, UnicodeString & out);
|
||||
|
||||
/**
|
||||
* Converts STATUS to string. If bad status, return default (NEEDS-ACTION).
|
||||
* @param status STATUS enumeration
|
||||
* @param out output partstat string
|
||||
*
|
||||
* @return output partstat string (out)
|
||||
*/
|
||||
static UnicodeString & statusToString(Attendee::STATUS status, UnicodeString & out);
|
||||
|
||||
|
||||
/**
|
||||
* Converts RSVP to string. If bad rsvp, return default (FALSE).
|
||||
* @param rsvp RSVP enumeration
|
||||
* @param out output rsvp string
|
||||
*
|
||||
* @return output rsvp string (out)
|
||||
*/
|
||||
static UnicodeString & rsvpToString(Attendee::RSVP rsvp, UnicodeString & out);
|
||||
|
||||
/**
|
||||
* Converts EXPECT to string. If bad expect, return default (FYI).
|
||||
* @param expect EXPECT enumeration
|
||||
* @param out output expect string
|
||||
*
|
||||
* @return output expect string (out)
|
||||
*/
|
||||
static UnicodeString & expectToString(Attendee::EXPECT expect, UnicodeString & out);
|
||||
|
||||
/**
|
||||
* Constructor. Also sets log file to write errors to.
|
||||
* @param ICalComponent::ICAL_COMPONENT componentType
|
||||
* @param initLog log file to write errors to
|
||||
*/
|
||||
Attendee(ICalComponent::ICAL_COMPONENT componentType, JLog * initLog = 0);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~Attendee();
|
||||
|
||||
/**
|
||||
* Factory method that returns a new default Attendee
|
||||
*
|
||||
* @return static Attendee *
|
||||
*/
|
||||
static Attendee * getDefault(ICalComponent::ICAL_COMPONENT compType,
|
||||
JLog * initLog = 0);
|
||||
|
||||
/**
|
||||
* Given attendee name and parameters, populates Attendee
|
||||
* data members.
|
||||
* @param propVal attendee name
|
||||
* @param parameters attendee parameters
|
||||
*
|
||||
*/
|
||||
void parse(UnicodeString & propVal, JulianPtrArray * parameters = 0);
|
||||
|
||||
/**
|
||||
* Sets parameter with name paramName with value paramVal.
|
||||
* For MEMBER, DELEGATED-TO, DELEGATED-FROM, DIR, SENT-BY, the
|
||||
* double quotes are stripped. THE MAILTO: is not stripped.
|
||||
*
|
||||
* @param paramName parameter name to set
|
||||
* @param paramVal new value of parameter
|
||||
*/
|
||||
void setParam(UnicodeString & paramName, UnicodeString & paramVal);
|
||||
|
||||
/**
|
||||
* convert a character to the content of a parameter in
|
||||
* human-readable string format
|
||||
*
|
||||
* @param c a character represents a parameter
|
||||
* @return parameter in a human-readable string
|
||||
*/
|
||||
UnicodeString toStringChar(t_int32 c);
|
||||
|
||||
|
||||
/**
|
||||
* Return the first attendee in vAttendees with the name matching sAttendee.
|
||||
* @param vAttendees vector of attendees
|
||||
* @param sAttendee attendee name to look for
|
||||
*
|
||||
* @return first Attendee with name sAttendee, 0 if not found.
|
||||
*/
|
||||
static Attendee * getAttendee(JulianPtrArray * vAttendees, UnicodeString sAttendee);
|
||||
|
||||
/*---------- To satisfy ICalProperty interface ----------*/
|
||||
/**
|
||||
* Sets parameters.
|
||||
* @param parameters vector of parameters to set
|
||||
*
|
||||
*/
|
||||
virtual void setParameters(JulianPtrArray * parameters);
|
||||
|
||||
/**
|
||||
* Return value of property. Never use. Use getName().
|
||||
*
|
||||
* @return value of property
|
||||
*/
|
||||
virtual void * getValue() const { PR_ASSERT(FALSE); return (void*) (&m_sName); }
|
||||
|
||||
/**
|
||||
* Sets value of property. Never use. Use setName().
|
||||
* @param value new value of property
|
||||
*
|
||||
*/
|
||||
virtual void setValue(void * value) { PR_ASSERT(FALSE); if (value) {}} ;
|
||||
|
||||
/**
|
||||
* Returns a clone of this property.
|
||||
* @param initLog the log file for clone to write to
|
||||
*
|
||||
* @return clone of this ICalProperty object
|
||||
*/
|
||||
virtual ICalProperty * clone(JLog * initLog);
|
||||
|
||||
/**
|
||||
* Checks whether this property is valid or not. Must have MAILTO: in
|
||||
* front of attendee name to be valid.
|
||||
*
|
||||
* @return TRUE if property is valid, FALSE otherwise
|
||||
*/
|
||||
virtual t_bool isValid();
|
||||
|
||||
/**
|
||||
* Return property to human-readable string.
|
||||
* @param dateFmt formatting string
|
||||
* @param out output human-readable string
|
||||
*
|
||||
* @return output human-readable string (out)
|
||||
*/
|
||||
virtual UnicodeString & toString(UnicodeString & strFmt, UnicodeString & out);
|
||||
|
||||
/**
|
||||
* Return property to human-readable string.
|
||||
* @param out output human-readable string
|
||||
*
|
||||
* @return output human-readable string (out)
|
||||
*/
|
||||
virtual UnicodeString & toString(UnicodeString & out);
|
||||
|
||||
/**
|
||||
* Return property to iCal property string.
|
||||
* @param out output iCal string
|
||||
*
|
||||
* @return output iCal string (out)
|
||||
*/
|
||||
virtual UnicodeString & toICALString(UnicodeString & out);
|
||||
|
||||
/**
|
||||
* Return property to iCal property string. Inserts sProp to
|
||||
* front of output string. sProp should be the property name of this
|
||||
* property.
|
||||
* @param sProp property name to append to insert at front of out
|
||||
* @param out output iCal string with sProp in front
|
||||
*
|
||||
* @return output iCal string with sProp in front (out)
|
||||
*/
|
||||
virtual UnicodeString & toICALString(UnicodeString & sProp, UnicodeString & out);
|
||||
/*----------End of ICalProperty interface----------*/
|
||||
|
||||
/* ---- GETTERS AND SETTERS ---- */
|
||||
|
||||
/**
|
||||
* Sets Attendee name.
|
||||
* @param sName new Attendee name
|
||||
*
|
||||
*/
|
||||
void setName(UnicodeString sName);
|
||||
|
||||
/**
|
||||
* Returns Attendee name.
|
||||
*
|
||||
* @return Attendee name
|
||||
*/
|
||||
UnicodeString getName() const { return m_sName; }
|
||||
|
||||
/**
|
||||
* Sets ROLE.
|
||||
* @param i new ROLE value
|
||||
*
|
||||
*/
|
||||
void setRole(Attendee::ROLE i) { m_iRole = i; }
|
||||
|
||||
/**
|
||||
* Sets TYPE.
|
||||
* @param i new TYPE value
|
||||
*
|
||||
*/
|
||||
void setType(Attendee::TYPE i) { m_iType = i; }
|
||||
|
||||
/**
|
||||
* Sets STATUS.
|
||||
* @param i new STATUS value
|
||||
*
|
||||
*/
|
||||
void setStatus(Attendee::STATUS i) { m_iStatus = i; }
|
||||
|
||||
/**
|
||||
* Sets RSVP.
|
||||
* @param i new RSVP value
|
||||
*
|
||||
*/
|
||||
void setRSVP(Attendee::RSVP i) { m_iRSVP = i; }
|
||||
|
||||
/**
|
||||
* Sets EXPECT.
|
||||
* @param i new EXPECT value
|
||||
*
|
||||
*/
|
||||
void setExpect(Attendee::EXPECT i) { m_iExpect = i; }
|
||||
|
||||
/**
|
||||
* Returns ROLE value.
|
||||
*
|
||||
* @return ROLE value
|
||||
*/
|
||||
Attendee::ROLE getRole() const { return (Attendee::ROLE) m_iRole; }
|
||||
|
||||
/**
|
||||
* Returns TYPE value.
|
||||
*
|
||||
* @return TYPE value
|
||||
*/
|
||||
Attendee::TYPE getType() const { return (Attendee::TYPE) m_iType; }
|
||||
|
||||
/**
|
||||
* Returns STATUS value.
|
||||
*
|
||||
* @return STATUS value
|
||||
*/
|
||||
Attendee::STATUS getStatus() const { return (Attendee::STATUS) m_iStatus; }
|
||||
|
||||
/**
|
||||
* Returns RSVP value.
|
||||
*
|
||||
* @return RSVP value
|
||||
*/
|
||||
Attendee::RSVP getRSVP() const { return (Attendee::RSVP) m_iRSVP; }
|
||||
|
||||
/**
|
||||
* Returns EXPECT value.
|
||||
*
|
||||
* @return EXPECT value
|
||||
*/
|
||||
Attendee::EXPECT getExpect() const { return (Attendee::EXPECT) m_iExpect; }
|
||||
|
||||
/**
|
||||
* Add a name to the Delegated-To vector.
|
||||
* @param sDelegatedTo name to add to delegated-to vector
|
||||
*/
|
||||
void addDelegatedTo(UnicodeString sDelegatedTo);
|
||||
|
||||
/**
|
||||
* Add a name to the Delegated-From vector.
|
||||
* @param sDelegatedFrom name to add to delegated-from vector
|
||||
*/
|
||||
void addDelegatedFrom(UnicodeString sDelegatedFrom);
|
||||
|
||||
/**
|
||||
* Add a name to the Member vector.
|
||||
* @param sMember name to add to member vector
|
||||
*/
|
||||
void addMember(UnicodeString sMember);
|
||||
|
||||
/**
|
||||
* Return ptr to Delegated-To vector
|
||||
*
|
||||
* @return Delegated-To vector
|
||||
*/
|
||||
JulianPtrArray * getDelegatedTo() const { return m_vsDelegatedTo; }
|
||||
|
||||
/**
|
||||
* Return ptr to Delegated-From vector
|
||||
*
|
||||
* @return Delegated-From vector
|
||||
*/
|
||||
JulianPtrArray * getDelegatedFrom() const { return m_vsDelegatedFrom; }
|
||||
|
||||
/**
|
||||
* Return ptr to Member vector
|
||||
*
|
||||
* @return Member vector
|
||||
*/
|
||||
JulianPtrArray * getMember() const { return m_vsMember; }
|
||||
|
||||
/**
|
||||
* Return CN (common-name) value
|
||||
*
|
||||
* @return CN value
|
||||
*/
|
||||
UnicodeString getCN() const { return m_CN; }
|
||||
|
||||
/**
|
||||
* Return Language value
|
||||
*
|
||||
* @return Language value
|
||||
*/
|
||||
UnicodeString getLanguage() const { return m_Language; }
|
||||
|
||||
/**
|
||||
* Return DIR (location of directory info) value
|
||||
*
|
||||
* @return DIR value
|
||||
*/
|
||||
UnicodeString getDir() const { return m_Dir; }
|
||||
|
||||
/**
|
||||
* Return SENT-BY (calendar user acting on behalf of the attendee) value
|
||||
*
|
||||
* @return SENT-BY value
|
||||
*/
|
||||
UnicodeString getSentBy() const { return m_SentBy; }
|
||||
|
||||
/**
|
||||
* Set CN (common-name) value
|
||||
* @param new CN value
|
||||
*/
|
||||
void setCN(UnicodeString u) { m_CN = u; }
|
||||
|
||||
/**
|
||||
* Set Language value
|
||||
* @param new Language value
|
||||
*/
|
||||
void setLanguage(UnicodeString u) { m_Language = u; }
|
||||
|
||||
/**
|
||||
* Set DIR (location of directory info) value
|
||||
* @param new DIR value
|
||||
*/
|
||||
void setDir(UnicodeString u) { m_Dir = u; }
|
||||
|
||||
/**
|
||||
* Set SENT-BY (calendar user acting on behalf of the attendee) value
|
||||
* @param new SENT-BY value
|
||||
*/
|
||||
void setSentBy(UnicodeString u) { m_SentBy = u; }
|
||||
|
||||
void setDTStamp(DateTime d) { m_DTStamp = d; }
|
||||
void setSequence(t_int32 i) { m_Sequence = i; }
|
||||
|
||||
/* list the default values for properties
|
||||
(always to 0th element of enumeration) */
|
||||
|
||||
/** the default ROLE value */
|
||||
static const t_int32 ms_iDEFAULT_ROLE;
|
||||
|
||||
/** the default TYPE value */
|
||||
static const t_int32 ms_iDEFAULT_TYPE;
|
||||
|
||||
/** the default STATUS value */
|
||||
static const t_int32 ms_iDEFAULT_STATUS;
|
||||
|
||||
/** the default RSVP value */
|
||||
static const t_int32 ms_iDEFAULT_RSVP;
|
||||
|
||||
/** the default EXPECT value*/
|
||||
static const t_int32 ms_iDEFAULT_EXPECT;
|
||||
|
||||
/* ---- END OF PUBLIC STATIC DATA ---- */
|
||||
private:
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
* @param Attendee & that
|
||||
*/
|
||||
Attendee(Attendee & that);
|
||||
|
||||
/**
|
||||
* Fixes data-members are so that they are valid. If properties
|
||||
* are invalid, then it will set it to defaults.
|
||||
*/
|
||||
void selfCheck();
|
||||
|
||||
/**
|
||||
* Fixes keyword property so that it is valid. If property is
|
||||
* invalid (param is out of range), then set property to default value.
|
||||
* @param prop keyword property to check
|
||||
* @param t_int32 param current value of keyword property
|
||||
*/
|
||||
void selfCheckHelper(Attendee::PROPS prop, t_int32 param);
|
||||
|
||||
/**
|
||||
* helper in parsing delegated-to, delegated-from, member
|
||||
*/
|
||||
void addParamValList(UnicodeString & paramValList,
|
||||
t_int32 hashCode);
|
||||
|
||||
/**
|
||||
* format string to print Attendee with PARTSTAT NOT
|
||||
* set to NEEDS-ACTION.
|
||||
* @return output formatted iCal Attendee string
|
||||
*/
|
||||
UnicodeString formatDoneAction();
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* format string to print Attendee with PARTSTAT NOT
|
||||
* set to NEEDS-ACTION and Delegated-To of attendee.
|
||||
* @return output formatted iCal Attendee string
|
||||
*/
|
||||
UnicodeString formatDoneDelegateToOnly();
|
||||
|
||||
/**
|
||||
* format string to print Attendee with PARTSTAT NOT
|
||||
* set to NEEDS-ACTION and Delegated-From of attendee.
|
||||
* @return output formatted iCal Attendee string
|
||||
*/
|
||||
UnicodeString formatDoneDelegateFromOnly();
|
||||
#endif
|
||||
|
||||
/* BELOW METHODS ALL ARE NEEDS ACTION */
|
||||
/* no need for %S, assumed to be NEEDS-ACTION */
|
||||
|
||||
/**
|
||||
* format string to print Attendee with PARTSTAT
|
||||
* set to NEEDS-ACTION.
|
||||
* @return output formatted iCal Attendee string
|
||||
*/
|
||||
UnicodeString formatNeedsAction();
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* format string to print Attendee with PARTSTAT
|
||||
* set to NEEDS-ACTION and Delegated-To of attendee.
|
||||
* @return output formatted iCal Attendee string
|
||||
*/
|
||||
UnicodeString formatDelegateToOnly();
|
||||
|
||||
/**
|
||||
* format string to print Attendee with PARTSTAT
|
||||
* set to NEEDS-ACTION and Delegated-From of attendee.
|
||||
* @return output formatted iCal Attendee string
|
||||
*/
|
||||
UnicodeString formatDelegateFromOnly();
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Method that takes a format string and returns
|
||||
* the correctly formatted iCal Attendee string
|
||||
* @param strFmt format string
|
||||
*
|
||||
* @return output formatted iCal Attendee string
|
||||
*/
|
||||
UnicodeString format(UnicodeString strFmt);
|
||||
|
||||
/**
|
||||
* Method that takes a character and returns parameter
|
||||
* in iCal output format.
|
||||
* @param c character representing parameter to print
|
||||
*
|
||||
* @return parameter in iCal output format
|
||||
*/
|
||||
UnicodeString formatChar(t_int32 c);
|
||||
|
||||
/**
|
||||
* Strip double quotest from the beginning and end of string
|
||||
* if it has double-quotes at beginning and end.
|
||||
* @param u string to strip double-quotes from
|
||||
*/
|
||||
/*static void stripDoubleQuotes(UnicodeString & u);*/
|
||||
|
||||
/**
|
||||
* Inserts double quotes at start and end of string if
|
||||
* string != "".
|
||||
* @param us string to add double-quotes to
|
||||
*
|
||||
* @return string with double-quotes at start, end (us)
|
||||
*/
|
||||
/*static UnicodeString & addDoubleQuotes(UnicodeString & us);*/
|
||||
|
||||
/**
|
||||
* Prints each element in a vector of MAILTO:'s
|
||||
* (i.e. member,delegated-to,delegated-from).
|
||||
* @param propName name of property (i.e. MEMBER)
|
||||
* @param mailto vector of MAILTO: to print
|
||||
* @param out output string
|
||||
*
|
||||
* @return output string (out)
|
||||
*/
|
||||
UnicodeString & printMailToVector(UnicodeString & propName,
|
||||
JulianPtrArray * mailto, UnicodeString & out);
|
||||
|
||||
/* ---- PRIVATE STATIC DATA ---- */
|
||||
|
||||
/* characters for printing Attendee parameters */
|
||||
static const t_int32 ms_cAttendeeName;/* = 'N';*/
|
||||
static const t_int32 ms_cAttendeeRole;/* = 'R';*/
|
||||
static const t_int32 ms_cAttendeeStatus;/* = 'S';*/
|
||||
static const t_int32 ms_cAttendeeRSVP;/* = 'V';*/
|
||||
static const t_int32 ms_cAttendeeType;/* = 'T';*/
|
||||
static const t_int32 ms_cAttendeeExpect;/* = 'E';*/
|
||||
static const t_int32 ms_cAttendeeDelegatedTo;/* = 'D';*/
|
||||
static const t_int32 ms_cAttendeeDelegatedFrom;/* = 'd';*/
|
||||
static const t_int32 ms_cAttendeeMember;/* = 'M';*/
|
||||
static const t_int32 ms_cAttendeeDir; /* = 'l'; 'el'*/
|
||||
static const t_int32 ms_cAttendeeSentBy;/* = 's';*/
|
||||
static const t_int32 ms_cAttendeeCN;/* = 'C';*/
|
||||
static const t_int32 ms_cAttendeeLanguage;/* = 'm';*/
|
||||
static const t_int32 ms_cAttendeeDisplayName;/* = 'z';*/
|
||||
|
||||
/* ---- END OF PRIVATE STATIC DATA ---- */
|
||||
|
||||
/* ---- PRIVATE DATA MEMBERS ---- */
|
||||
|
||||
/**
|
||||
* the name of the Attendee. Whatever is to the right of the colon
|
||||
* the name must be a URL. Field must be filled to be valid Attendee.
|
||||
*/
|
||||
UnicodeString m_sName;
|
||||
|
||||
/** ptr to log file to write errors to */
|
||||
JLog * m_Log;
|
||||
|
||||
/** the attendee's role value. Default is REQ_PARTICIPANT. */
|
||||
t_int32 m_iRole;
|
||||
|
||||
/** the attendee's type value. Default is INDIVIDUAL. */
|
||||
t_int32 m_iType;
|
||||
|
||||
/** the attendee's status value. Default is NEEDS-ACTION. */
|
||||
t_int32 m_iStatus;
|
||||
|
||||
/** the attendee's RSVP value. Default is FALSE. */
|
||||
t_int32 m_iRSVP;
|
||||
|
||||
/** the attendee's expect value. Default is FYI.*/
|
||||
t_int32 m_iExpect;
|
||||
|
||||
/**
|
||||
* the list of members the attendee belongs to
|
||||
* each element in members must be a MAILTO:
|
||||
*/
|
||||
JulianPtrArray * m_vsMember;
|
||||
|
||||
/**
|
||||
* the list of delegated-to attendees.
|
||||
* each element in delegated-to must be a MAILTO:
|
||||
*/
|
||||
JulianPtrArray * m_vsDelegatedTo;
|
||||
|
||||
/**
|
||||
* the list of delegated-from attendees.
|
||||
* each element in delegated-from must be a MAILTO:
|
||||
*/
|
||||
JulianPtrArray * m_vsDelegatedFrom;
|
||||
|
||||
/* added newer properties 3-23-98 */
|
||||
|
||||
/** the common name of attendee. Optional, default is "". */
|
||||
UnicodeString m_CN;
|
||||
|
||||
/** the language of the common name of the attendee. Optional, default is "". */
|
||||
UnicodeString m_Language;
|
||||
|
||||
/** the MAILTO: of a calendar user acting on behalf of the attendee.
|
||||
* Optional, default is "".
|
||||
*/
|
||||
UnicodeString m_SentBy;
|
||||
|
||||
/** the location of the Attendee's directory information.
|
||||
* Optional, default is "". */
|
||||
UnicodeString m_Dir;
|
||||
|
||||
/** the type of the attendee status: STATUS depends on this */
|
||||
ICalComponent::ICAL_COMPONENT m_ComponentType;
|
||||
|
||||
DateTime m_DTStamp;
|
||||
t_int32 m_Sequence;
|
||||
|
||||
/* ---- END OF DATA MEMBERS ---- */
|
||||
};
|
||||
|
||||
#endif /* __ATTENDEE_H_ */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user