removing incompatibly licensed source.
git-svn-id: svn://10.0.0.236/trunk@65504 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
be030a3bb3
commit
6825eab444
File diff suppressed because it is too large
Load Diff
@ -1,180 +0,0 @@
|
||||
|
||||
/* W3 Copyright statement
|
||||
Copyright 1995 by: Massachusetts Institute of Technology (MIT), INRIA</H2>
|
||||
|
||||
This W3C software is being provided by the copyright holders under the
|
||||
following license. By obtaining, using and/or copying this software,
|
||||
you agree that you have read, understood, and will comply with the
|
||||
following terms and conditions:
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee or royalty is hereby
|
||||
granted, provided that the full text of this NOTICE appears on
|
||||
<EM>ALL</EM> copies of the software and documentation or portions
|
||||
thereof, including modifications, that you make.
|
||||
|
||||
<B>THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
|
||||
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE,
|
||||
BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
|
||||
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
|
||||
THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY
|
||||
THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
||||
COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE
|
||||
OR DOCUMENTATION.
|
||||
|
||||
The name and trademarks of copyright holders may NOT be used
|
||||
in advertising or publicity pertaining to the software without
|
||||
specific, written prior permission. Title to copyright in this
|
||||
software and any associated documentation will at all times remain
|
||||
with copyright holders.
|
||||
*/
|
||||
/* Label parser for libpics
|
||||
LABEL PARSER
|
||||
|
||||
*/
|
||||
/*
|
||||
** (c) COPYRIGHT MIT 1996.
|
||||
** Please first read the full copyright statement in the file COPYRIGH.
|
||||
*/
|
||||
/*
|
||||
|
||||
This module provides the interface to CSLabel.c. Labels are parsed from strings (see
|
||||
CSParse.html). These labels may then be kept in a CSLabel_t structure for inspection by
|
||||
the application or compared to the values in a CSUser_t structure (see CSUser.html).
|
||||
|
||||
*/
|
||||
#ifndef CSLL_H
|
||||
#define CSLL_H
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
|
||||
State Change Enumeration
|
||||
|
||||
Call to the TargetChangeCallback will have one of the following values.
|
||||
|
||||
*/
|
||||
typedef enum {
|
||||
CSLLTC_LIST = 1,
|
||||
CSLLTC_SERVICE,
|
||||
CSLLTC_LABEL,
|
||||
CSLLTC_LABTREE,
|
||||
CSLLTC_SINGLE,
|
||||
CSLLTC_RATING,
|
||||
CSLLTC_RANGE,
|
||||
CSLLTC_AWKWARD,
|
||||
CSLLTC_NORAT,
|
||||
CSLLTC_SRVERR,
|
||||
CSLLTC_LABERR,
|
||||
CSLLTC_EXTEN,
|
||||
CSLLTC_EXTDATA,
|
||||
CSLLTC_COUNT
|
||||
} CSLLTC_t;
|
||||
/*
|
||||
|
||||
Data shell
|
||||
|
||||
All PICS label data is stored in a CSLLData_t
|
||||
|
||||
*/
|
||||
typedef struct CSLLData_s CSLLData_t;
|
||||
#define CSLabel_labelNumber(S) (S->currentLabelNumber)
|
||||
/*
|
||||
|
||||
TargetChangeCallback
|
||||
|
||||
As the label is parsed, it will call the assigned TargetChangeCallback as it passes
|
||||
from state to state.
|
||||
|
||||
*/
|
||||
typedef StateRet_t LabelTargetCallback_t(CSLabel_t * pCSLabel,
|
||||
CSParse_t * pCSParse,
|
||||
CSLLTC_t target, PRBool closed,
|
||||
void * pVoid);
|
||||
/*
|
||||
|
||||
ErrorHandler
|
||||
|
||||
All parsing error will be passed to the Apps LLErrorHandler for user display or
|
||||
automatic dismissal.
|
||||
|
||||
*/
|
||||
typedef StateRet_t LLErrorHandler_t(CSLabel_t * pCSLabel,
|
||||
CSParse_t * pCSParse, const char * token,
|
||||
char demark, StateRet_t errorCode);
|
||||
/*
|
||||
|
||||
Construction/Destruction
|
||||
|
||||
These methods allow the user to create and get access to both the label and the state.
|
||||
CSLabels may be cloned so that one saves state while another continues to iterate or
|
||||
parse. The states mus all be freed. Label data will only be freed after all the
|
||||
CSLabels that refer to it are deleted.
|
||||
|
||||
*/
|
||||
extern CSParse_t * CSParse_newLabel(
|
||||
LabelTargetCallback_t * pLabelTargetCallback,
|
||||
LLErrorHandler_t * pLLErrorHandler);
|
||||
extern PRBool CSParse_deleteLabel(CSParse_t *);
|
||||
extern CSLabel_t * CSParse_getLabel(CSParse_t * me);
|
||||
extern CSLabel_t * CSLabel_copy(CSLabel_t * old);
|
||||
extern void CSLabel_free(CSLabel_t * me);
|
||||
|
||||
extern char * CSLabel_getServiceName(CSLabel_t * pCSLabel);
|
||||
extern PRInt32 CSLabel_getLabelNumber(CSLabel_t * pCSLabel);
|
||||
extern char * CSLabel_getRatingName(CSLabel_t * pCSLabel);
|
||||
extern char * CSLabel_getRatingStr(CSLabel_t * pCSLabel);
|
||||
extern Range_t * CSLabel_getLabelRatingRange(CSLabel_t * pCSLabel);
|
||||
/*
|
||||
|
||||
Iterating methods
|
||||
|
||||
Callback function
|
||||
|
||||
The Iterators are passed a callback function to be called for each matching element.
|
||||
For instance, when iterating through ranges, the callback function is called once for
|
||||
each range, or, if a match is requested, only for the matching range.
|
||||
|
||||
*/
|
||||
typedef CSError_t CSLabel_callback_t(CSLabel_t *, State_Parms_t *,
|
||||
const char *, void * pVoid);
|
||||
typedef CSError_t CSLabel_iterator_t(CSLabel_t *,
|
||||
CSLabel_callback_t *,
|
||||
State_Parms_t *, const char *,
|
||||
void * pVoid);
|
||||
/*
|
||||
|
||||
Iterators
|
||||
|
||||
*/
|
||||
extern CSLabel_iterator_t CSLabel_iterateServices;
|
||||
extern CSLabel_iterator_t CSLabel_iterateLabels;
|
||||
extern CSLabel_iterator_t CSLabel_iterateSingleLabels;
|
||||
extern CSLabel_iterator_t CSLabel_iterateLabelRatings;
|
||||
/*
|
||||
|
||||
Range Utilities
|
||||
|
||||
These funtions allow the application to test the value of a given user parameter
|
||||
against those in the label.
|
||||
|
||||
*/
|
||||
extern HTList * CSLLData_getAllSingleLabels(CSLabel_t * pCSLabel);
|
||||
extern FVal_t CSLabel_ratingsIncludeFVal(CSLabel_t * pCSLabel,
|
||||
FVal_t * userValue);
|
||||
extern FVal_t CSLabel_ratingsIncludeRange(CSLabel_t * pCSLabel,
|
||||
Range_t * pUserRange);
|
||||
extern FVal_t CSLabel_ratingsIncludeRanges(CSLabel_t * pCSLabel,
|
||||
HTList * userRanges);
|
||||
/*
|
||||
|
||||
|
||||
*/
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
#endif /* CSLL_H */
|
||||
/*
|
||||
|
||||
End of Declaration */
|
||||
@ -1,210 +0,0 @@
|
||||
|
||||
/* W3 Copyright statement
|
||||
Copyright 1995 by: Massachusetts Institute of Technology (MIT), INRIA</H2>
|
||||
|
||||
This W3C software is being provided by the copyright holders under the
|
||||
following license. By obtaining, using and/or copying this software,
|
||||
you agree that you have read, understood, and will comply with the
|
||||
following terms and conditions:
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee or royalty is hereby
|
||||
granted, provided that the full text of this NOTICE appears on
|
||||
<EM>ALL</EM> copies of the software and documentation or portions
|
||||
thereof, including modifications, that you make.
|
||||
|
||||
<B>THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
|
||||
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE,
|
||||
BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
|
||||
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
|
||||
THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY
|
||||
THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
||||
COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE
|
||||
OR DOCUMENTATION.
|
||||
|
||||
The name and trademarks of copyright holders may NOT be used
|
||||
in advertising or publicity pertaining to the software without
|
||||
specific, written prior permission. Title to copyright in this
|
||||
software and any associated documentation will at all times remain
|
||||
with copyright holders.
|
||||
*/
|
||||
/* Label data internals
|
||||
LABEL DATA INTERNALS
|
||||
|
||||
*/
|
||||
/*
|
||||
** (c) COPYRIGHT MIT 1996.
|
||||
** Please first read the full copyright statement in the file COPYRIGH.
|
||||
*/
|
||||
/*
|
||||
|
||||
This module defines the Label data structures read by CSParser.c. Applications will
|
||||
include this if they want direct access to the data (as opposed to using iterator
|
||||
methods).
|
||||
|
||||
The following data structures relate to the data encapsulated in a PICS Label. Each
|
||||
data type correlates to a time in the BNF for the label description. See PICS Labels
|
||||
spec for more details.
|
||||
|
||||
*/
|
||||
#ifndef CSLLST_H
|
||||
#define CSLLST
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
|
||||
|
||||
LABEL ERROR
|
||||
|
||||
combination of:
|
||||
|
||||
_label-error_
|
||||
|
||||
_service-error_
|
||||
|
||||
_service-info_ 'no-ratings'
|
||||
|
||||
*/
|
||||
typedef struct {
|
||||
LabelErrorCode_t errorCode;
|
||||
HTList * explanations; /* HTList of (char *) */
|
||||
} LabelError_t;
|
||||
/*
|
||||
|
||||
EXTENSION DATA
|
||||
|
||||
called _data_ in the BNF
|
||||
|
||||
*/
|
||||
typedef struct ExtensionData_s ExtensionData_t;
|
||||
struct ExtensionData_s {
|
||||
char * text;
|
||||
PRBool quoted;
|
||||
HTList * moreData;
|
||||
ExtensionData_t * pParentExtensionData;
|
||||
};
|
||||
/*
|
||||
|
||||
EXTENSION
|
||||
|
||||
_option_ 'extension'
|
||||
|
||||
*/
|
||||
typedef struct {
|
||||
PRBool mandatory;
|
||||
SVal_t url;
|
||||
HTList * extensionData;
|
||||
} Extension_t;
|
||||
/*
|
||||
|
||||
LABEL OPTIONS
|
||||
|
||||
called _option_ in the BNF
|
||||
|
||||
*/
|
||||
typedef struct LabelOptions_s LabelOptions_t;
|
||||
struct LabelOptions_s {
|
||||
DVal_t at;
|
||||
SVal_t by;
|
||||
SVal_t complete_label;
|
||||
BVal_t generic;
|
||||
SVal_t fur; /* for is a reserved word */
|
||||
SVal_t MIC_md5;
|
||||
DVal_t on;
|
||||
SVal_t signature_PKCS;
|
||||
DVal_t until;
|
||||
HTList * comments;
|
||||
HTList * extensions;
|
||||
/* find service-level label options */
|
||||
LabelOptions_t * pParentLabelOptions;
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
RATING
|
||||
|
||||
called _rating_ in the BNF
|
||||
|
||||
*/
|
||||
typedef struct {
|
||||
SVal_t identifier;
|
||||
FVal_t value;
|
||||
HTList * ranges;
|
||||
} LabelRating_t;
|
||||
/*
|
||||
|
||||
SINGLELABEL
|
||||
|
||||
called _single-label_ in the BNF
|
||||
|
||||
*/
|
||||
typedef struct {
|
||||
LabelOptions_t * pLabelOptions;
|
||||
HTList * labelRatings;
|
||||
} SingleLabel_t;
|
||||
|
||||
/*
|
||||
|
||||
LABEL
|
||||
|
||||
also called _label_
|
||||
|
||||
*/
|
||||
typedef struct {
|
||||
LabelError_t * pLabelError;
|
||||
HTList * singleLabels;
|
||||
SingleLabel_t * pSingleLabel;
|
||||
} Label_t;
|
||||
/*
|
||||
|
||||
SERVICEINFO
|
||||
|
||||
called _service-info_ in the BNF
|
||||
|
||||
*/
|
||||
typedef struct {
|
||||
SVal_t rating_service;
|
||||
LabelOptions_t * pLabelOptions;
|
||||
LabelError_t * pLabelError;
|
||||
HTList * labels;
|
||||
} ServiceInfo_t;
|
||||
/*
|
||||
|
||||
CSLLDATA
|
||||
|
||||
The whole shebang.
|
||||
|
||||
*/
|
||||
struct CSLLData_s {
|
||||
FVal_t version;
|
||||
LabelError_t * pLabelError;
|
||||
HTList * serviceInfos;
|
||||
|
||||
/* some usefull flags */
|
||||
PRBool complete;
|
||||
PRBool hasTree; /* so it can't make a list of labels */
|
||||
PRInt32 mandatoryExtensions;
|
||||
};
|
||||
/*
|
||||
|
||||
--------------these need the above structures--------------
|
||||
|
||||
*/
|
||||
extern CSLLData_t * CSLabel_getCSLLData(CSLabel_t * me);
|
||||
extern LabelError_t * CSLabel_getLabelError(CSLabel_t * pCSLabel);
|
||||
extern LabelOptions_t * CSLabel_getLabelOptions(CSLabel_t * pCSLabel);
|
||||
extern ServiceInfo_t * CSLabel_getServiceInfo(CSLabel_t * pCSLabel);
|
||||
extern Label_t * CSLabel_getLabel(CSLabel_t * pCSLabel);
|
||||
extern SingleLabel_t * CSLabel_getSingleLabel(CSLabel_t * pCSLabel);
|
||||
extern LabelRating_t * CSLabel_getLabelRating(CSLabel_t * pCSLabel);
|
||||
/*
|
||||
|
||||
*/
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
#endif /* CSLLST_H */
|
||||
/*
|
||||
|
||||
End of Declaration */
|
||||
@ -1,426 +0,0 @@
|
||||
|
||||
/* W3 Copyright statement
|
||||
Copyright 1995 by: Massachusetts Institute of Technology (MIT), INRIA</H2>
|
||||
|
||||
This W3C software is being provided by the copyright holders under the
|
||||
following license. By obtaining, using and/or copying this software,
|
||||
you agree that you have read, understood, and will comply with the
|
||||
following terms and conditions:
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee or royalty is hereby
|
||||
granted, provided that the full text of this NOTICE appears on
|
||||
<EM>ALL</EM> copies of the software and documentation or portions
|
||||
thereof, including modifications, that you make.
|
||||
|
||||
<B>THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
|
||||
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE,
|
||||
BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
|
||||
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
|
||||
THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY
|
||||
THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
||||
COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE
|
||||
OR DOCUMENTATION.
|
||||
|
||||
The name and trademarks of copyright holders may NOT be used
|
||||
in advertising or publicity pertaining to the software without
|
||||
specific, written prior permission. Title to copyright in this
|
||||
software and any associated documentation will at all times remain
|
||||
with copyright holders.
|
||||
*/
|
||||
/* PICS library utilities
|
||||
PICS LIBRARY UTILITIES
|
||||
|
||||
*/
|
||||
/*
|
||||
** (c) COPYRIGHT MIT 1996.
|
||||
** Please first read the full copyright statement in the file COPYRIGH.
|
||||
*/
|
||||
/*
|
||||
|
||||
This module defines the PICS library interface.
|
||||
|
||||
*/
|
||||
#ifndef CSLUTILS_H
|
||||
#define CSLUTILS_H
|
||||
|
||||
/*
|
||||
|
||||
*/
|
||||
#include "htutils.h"
|
||||
#include "htlist.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
/*
|
||||
|
||||
PRIMITAVE DATA STRUCTURES
|
||||
|
||||
BVal_t, FVal_t, SVal_t, DVal_t - hold a boolean, float (not double), string, or date
|
||||
value (respectively). These data structures are designed so that they may be
|
||||
initialized to all 0s (and hence included directly within larger structures, rather
|
||||
than allocated and initialized individually). You must, however, call their clear
|
||||
method to deallocate any additional memory used to store the actual value once they
|
||||
have been initialized. The following methods are defined on all four data types ("X"
|
||||
should be either "B" "F" "S" or "D", XType is "PRBool" "float" "char *" or "char *",
|
||||
respectively):
|
||||
|
||||
PRBool XVal_readVal(XVal_t, char *), etc. - convert the string to a value of the
|
||||
specified type. Returns TRUE on success, FALSE on failure. If successful, may
|
||||
allocate additional storage.
|
||||
|
||||
PRBool XVal_initialized(XVal_t) - Returns TRUE if the value has been initialized
|
||||
(hence contains a legitimate value and may have additional storage allocated
|
||||
internally), FALSE otherwise.
|
||||
|
||||
XType XVal_value(XVal_t) -- Returns the value stored in the object.
|
||||
|
||||
void XVal_clear(XVal_t) -- Mark the object as uninitialized and release any memory
|
||||
associated with the value currently stored in the object.
|
||||
|
||||
BVAL
|
||||
|
||||
- Boolean value.
|
||||
|
||||
definition
|
||||
|
||||
*/
|
||||
typedef struct {
|
||||
enum {BVal_UNINITIALIZED = 0,BVal_YES = 1, BVal_INITIALIZED = 2} state;
|
||||
} BVal_t;
|
||||
|
||||
extern PRBool BVal_readVal(BVal_t * pBVal, const char * valueStr);
|
||||
extern PRBool BVal_initialized(const BVal_t * pBVal);
|
||||
extern PRBool BVal_value(const BVal_t * pBVal);
|
||||
extern void BVal_clear(BVal_t * pBVal);
|
||||
/*
|
||||
|
||||
additional methods
|
||||
|
||||
void set - assign value
|
||||
|
||||
*/
|
||||
extern void BVal_set(BVal_t * pBVal, PRBool value);
|
||||
/*
|
||||
|
||||
FVAL
|
||||
|
||||
- Float value with negative and positive infinity values
|
||||
|
||||
definition
|
||||
|
||||
*/
|
||||
typedef struct {
|
||||
float value;
|
||||
enum {FVal_UNINITIALIZED = 0, FVal_VALUE = 1, FVal_NEGATIVE_INF = 2,
|
||||
FVal_POSITIVE_INF = 3} stat;
|
||||
} FVal_t;
|
||||
|
||||
extern PRBool FVal_readVal(FVal_t * pFVal, const char * valueStr);
|
||||
extern PRBool FVal_initialized(const FVal_t * pFVal);
|
||||
extern float FVal_value(const FVal_t * pFVal);
|
||||
extern void FVal_clear(FVal_t * pFVal);
|
||||
/*
|
||||
|
||||
additional methods
|
||||
|
||||
void set - assign a float value
|
||||
|
||||
void setInfinite - set to negative or positive infinity
|
||||
|
||||
PRBool isZero - see if value is zero
|
||||
|
||||
PRInt32 isInfinite - -1 or 1 for negative or positive infinity
|
||||
|
||||
PRBool nearerZero - see if check is nearer zero than check
|
||||
|
||||
FVal_t FVal_minus - subtract small from big
|
||||
|
||||
char * FVal_toStr - convert to allocated CString, caller must free
|
||||
|
||||
*/
|
||||
extern void FVal_set(FVal_t * pFVal, float value);
|
||||
extern void FVal_setInfinite(FVal_t * pFVal, PRBool negative);
|
||||
extern PRBool FVal_isZero(const FVal_t * pFVal);
|
||||
extern PRInt32 FVal_isInfinite(const FVal_t * pFVal);
|
||||
extern PRBool FVal_nearerZero(const FVal_t * pRef, const FVal_t * pCheck);
|
||||
extern FVal_t FVal_minus(const FVal_t * pBig, const FVal_t * pSmall);
|
||||
extern char * FVal_toStr(FVal_t * pFVal);
|
||||
/*
|
||||
|
||||
initializers
|
||||
|
||||
FVal intializers may be used when creating an FVal
|
||||
eg. FVal_t localFVal = FVal_NEGATIVE_INF;
|
||||
|
||||
*/
|
||||
#define FVal_NEW_UNINITIALIZED {(float) 0.0, FVal_UNINITIALIZED}
|
||||
#define FVal_NEW_NEGATIVE_INF {(float) 0.0, FVal_NEGATIVE_INF}
|
||||
#define FVal_NEW_POSITIVE_INF {(float) 0.0, FVal_POSITIVE_INF}
|
||||
#define FVal_NEW_ZERO {(float) 0.0, FVal_VALUE}
|
||||
|
||||
/*
|
||||
|
||||
SVAL
|
||||
|
||||
- String value.
|
||||
|
||||
definition
|
||||
|
||||
*/
|
||||
typedef struct {
|
||||
char * value;
|
||||
PRBool initialized;
|
||||
} SVal_t;
|
||||
|
||||
extern PRBool SVal_readVal(SVal_t * pSVal, const char * valueStr);
|
||||
extern PRBool SVal_initialized(const SVal_t * pSVal);
|
||||
extern char * SVal_value(const SVal_t * pSVal);
|
||||
extern void SVal_clear(SVal_t * pSVal);
|
||||
/*
|
||||
|
||||
DVAL
|
||||
|
||||
- Date value.
|
||||
|
||||
definition
|
||||
|
||||
*/
|
||||
typedef struct {
|
||||
char * value; /* keep the string around for debugging and output */
|
||||
PRBool initialized;
|
||||
PRInt32 year;
|
||||
PRInt32 month;
|
||||
PRInt32 day;
|
||||
PRInt32 hour;
|
||||
PRInt32 minute;
|
||||
PRInt32 timeZoneHours;
|
||||
PRInt32 timeZoneMinutes;
|
||||
} DVal_t;
|
||||
|
||||
extern PRBool DVal_readVal(DVal_t * pDVal, const char * valueStr);
|
||||
extern PRBool DVal_initialized(const DVal_t * pDVal);
|
||||
extern char * DVal_value(const DVal_t * pDVal);
|
||||
extern void DVal_clear(DVal_t * pDVal);
|
||||
/*
|
||||
|
||||
additional methods
|
||||
|
||||
PRInt32 compare - -1 or 1 for a before or after b, 0 for equivilence
|
||||
|
||||
*/
|
||||
extern PRInt32 DVal_compare(const DVal_t * a, const DVal_t * b);
|
||||
/*
|
||||
|
||||
RANGE
|
||||
|
||||
- Range of FVals.
|
||||
|
||||
definition
|
||||
|
||||
*/
|
||||
typedef struct {
|
||||
FVal_t min;
|
||||
FVal_t max;
|
||||
} Range_t;
|
||||
/*
|
||||
|
||||
methods
|
||||
|
||||
rangeToStr - print range to malloced string. This string must be freed by caller
|
||||
|
||||
gap - find the difference between a and b
|
||||
|
||||
*/
|
||||
extern char * Range_toStr(Range_t * pRange);
|
||||
extern FVal_t Range_gap(Range_t * a, Range_t * b);
|
||||
/*
|
||||
|
||||
initializers
|
||||
|
||||
*/
|
||||
#define Range_NEW_UNINITIALIZED {FVal_NEW_UNINITIALIZED, \
|
||||
FVal_NEW_UNINITIALIZED}
|
||||
|
||||
/*
|
||||
|
||||
PARSER
|
||||
|
||||
CSPARSE_PARSECHUNK
|
||||
|
||||
CSParse_t - ephemeral parser data, the CSParse structure is defined in CSParse.html.
|
||||
CSDoMore_t - tells caller whether parseChunk expects more or encountered an error
|
||||
|
||||
*/
|
||||
typedef struct CSParse_s CSParse_t;
|
||||
typedef enum {CSDoMore_more, CSDoMore_done, CSDoMore_error} CSDoMore_t;
|
||||
extern CSDoMore_t CSParse_parseChunk (CSParse_t * pCSParse, const char * ptr,
|
||||
PRInt32 len, void * pVoid);
|
||||
/*
|
||||
|
||||
PARSE CALLBACKS
|
||||
|
||||
During parsing, the parser makes callbacks to tell the caller that an error has been
|
||||
encountered or that the parser is reading into a new data structure.
|
||||
|
||||
CSPARSETC
|
||||
|
||||
The TC, or TargetChange, type is a way of itemizing the different targets in a parsable
|
||||
object. It is used in the TargetChangeCallback
|
||||
|
||||
*/
|
||||
typedef PRUint32 CSParseTC_t;
|
||||
|
||||
|
||||
/*
|
||||
|
||||
STATERET
|
||||
|
||||
*/
|
||||
typedef enum {StateRet_OK = 0, StateRet_DONE = 1, StateRet_WARN = 0x10,
|
||||
StateRet_WARN_NO_MATCH = 0x11, StateRet_WARN_BAD_PUNCT = 0x12,
|
||||
StateRet_ERROR = 0x100, StateRet_ERROR_BAD_CHAR = 0x101
|
||||
} StateRet_t;
|
||||
|
||||
/*
|
||||
|
||||
TARGETCHANGECALLBACK
|
||||
|
||||
These callbacks keep the caller abreast of what type of object the parser is currently
|
||||
reading. TargetChangeCallbacks are made whenever the parser starts or finishes reading
|
||||
one of these objects. The actual values of targetChange, and what objects they
|
||||
correlate to, can be found in the modules for the object being parsed.
|
||||
|
||||
CSLL.html for PICS labels.
|
||||
|
||||
CSMR.html for machine-readable service descriptions.
|
||||
|
||||
CSUser.html for PICS user profiles.
|
||||
|
||||
Example: When reading a CSLabel, the callback will be called with pTargetObject =
|
||||
CSLLTC_SERVICE when reading a service, CSLLTC_LABEL when reading a label, etc.
|
||||
|
||||
*/
|
||||
typedef struct TargetObject_s TargetObject_t;
|
||||
typedef StateRet_t TargetChangeCallback_t(CSParse_t * pCSParse,
|
||||
TargetObject_t * pTargetObject,
|
||||
CSParseTC_t targetChange, PRBool closed,
|
||||
void * pVoid);
|
||||
/*
|
||||
|
||||
PARSEERRORHANDLER
|
||||
|
||||
*/
|
||||
typedef StateRet_t ParseErrorHandler_t(CSParse_t * pCSParse,
|
||||
const char * token,
|
||||
char demark, StateRet_t errorCode);
|
||||
|
||||
/*
|
||||
|
||||
CSLIST_ACCEPTLABELS
|
||||
|
||||
get a malloced HTTP Protocol-Request string requesting PICS labels for all services in
|
||||
pServiceList
|
||||
|
||||
*/
|
||||
typedef enum {CSCompleteness_minimal, CSCompleteness_short,
|
||||
CSCompleteness_full, CSCompleteness_signed} CSCompleteness_t;
|
||||
extern char * CSList_acceptLabels(HTList * pServiceList,
|
||||
CSCompleteness_t completeness);
|
||||
|
||||
/*
|
||||
|
||||
CSLIST_GETLABELS
|
||||
|
||||
get a malloced HTTP GET string requesting PICS labels for all services in pServiceList
|
||||
|
||||
*/
|
||||
typedef enum {CSOption_generic, CSOption_normal, CSOption_tree,
|
||||
CSOption_genericTree} CSOption_t;
|
||||
extern char * CSList_getLabels(HTList * pServiceList, CSOption_t option,
|
||||
CSCompleteness_t completeness);
|
||||
/*
|
||||
|
||||
CSLIST_POSTLABELS
|
||||
|
||||
get a malloced HTTP GET string requesting PICS labels for all services in pServiceList
|
||||
|
||||
*/
|
||||
extern char * CSList_postLabels(HTList * pServiceList, char * url,
|
||||
CSOption_t option,
|
||||
CSCompleteness_t completeness);
|
||||
/*
|
||||
|
||||
INDIVIDUAL PARSERS
|
||||
|
||||
CSLABEL
|
||||
|
||||
PICS label list
|
||||
|
||||
*/
|
||||
typedef struct CSLabel_s CSLabel_t;
|
||||
/*
|
||||
|
||||
CSUSER
|
||||
|
||||
PICS user profile
|
||||
|
||||
*/
|
||||
typedef struct CSUser_s CSUser_t;
|
||||
/*
|
||||
|
||||
CSMACHREAD
|
||||
|
||||
PICS machine readable system description
|
||||
|
||||
*/
|
||||
typedef struct CSMachRead_s CSMachRead_t;
|
||||
/*
|
||||
|
||||
for reading label error codes
|
||||
|
||||
*/
|
||||
typedef enum {
|
||||
labelError_NA = 0,
|
||||
labelError_NO_RATINGS,
|
||||
labelError_UNAVAILABLE,
|
||||
labelError_DENIED,
|
||||
labelError_NOT_LABELED,
|
||||
labelError_UNKNOWN
|
||||
} LabelErrorCode_t;
|
||||
|
||||
/*
|
||||
|
||||
State_Parms - obsolete parameter exchange for iterators
|
||||
|
||||
*/
|
||||
typedef struct State_Parms_s State_Parms_t;
|
||||
|
||||
typedef enum {
|
||||
CSError_OK = 0,
|
||||
CSError_YES = 0,
|
||||
CSError_NO = 1,
|
||||
CSError_BUREAU_NONE,
|
||||
CSError_RATING_VALUE,
|
||||
CSError_RATING_RANGE,
|
||||
CSError_RATING_MISSING,
|
||||
CSError_SINGLELABEL_MISSING,
|
||||
CSError_LABEL_MISSING,
|
||||
CSError_SERVICE_MISSING,
|
||||
CSError_CATEGORY_MISSING,
|
||||
CSError_ENUM_MISSING,
|
||||
CSError_BAD_PARAM,
|
||||
CSError_BAD_DATE,
|
||||
CSError_SERVICE_NONE,
|
||||
CSError_RATING_NONE,
|
||||
CSError_APP
|
||||
} CSError_t;
|
||||
/*
|
||||
|
||||
*/
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
#endif /* CSLUTILS_H */
|
||||
/*
|
||||
|
||||
End of Declaration */
|
||||
@ -1,686 +0,0 @@
|
||||
|
||||
/* W3 Copyright statement
|
||||
Copyright 1995 by: Massachusetts Institute of Technology (MIT), INRIA</H2>
|
||||
|
||||
This W3C software is being provided by the copyright holders under the
|
||||
following license. By obtaining, using and/or copying this software,
|
||||
you agree that you have read, understood, and will comply with the
|
||||
following terms and conditions:
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee or royalty is hereby
|
||||
granted, provided that the full text of this NOTICE appears on
|
||||
<EM>ALL</EM> copies of the software and documentation or portions
|
||||
thereof, including modifications, that you make.
|
||||
|
||||
<B>THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
|
||||
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE,
|
||||
BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
|
||||
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
|
||||
THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY
|
||||
THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
||||
COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE
|
||||
OR DOCUMENTATION.
|
||||
|
||||
The name and trademarks of copyright holders may NOT be used
|
||||
in advertising or publicity pertaining to the software without
|
||||
specific, written prior permission. Title to copyright in this
|
||||
software and any associated documentation will at all times remain
|
||||
with copyright holders.
|
||||
*/
|
||||
/* CSParse.c
|
||||
** PICS CONFIGURATION MANAGER FOR CLIENTS AND SERVERS
|
||||
**
|
||||
** (c) COPYRIGHT MIT 1995.
|
||||
** Please first read the full copyright statement in the file COPYRIGHT.
|
||||
**
|
||||
** This module converts application/xpics streams (files or network) to PICS_ class data
|
||||
**
|
||||
** History:
|
||||
** 4 Dec 95 EGP start
|
||||
** 15 Feb 96 EGP alpha 1
|
||||
**
|
||||
** BUGS: no code yet; doesn't actually do anything
|
||||
*/
|
||||
|
||||
/* Library include files */
|
||||
#include <stdarg.h>
|
||||
#include "plstr.h"
|
||||
/* #include "sysdep.h" jhines 7/9/97 */
|
||||
#include "htchunk.h"
|
||||
#include "htstring.h"
|
||||
#include "cslutils.h"
|
||||
#include "csparse.h"
|
||||
|
||||
PUBLIC PRInt32 ParseDebug = 0; /* For use with LablPars and RatPars */
|
||||
|
||||
PUBLIC PRBool BVal_readVal(BVal_t * pBVal, const char * valueStr)
|
||||
{
|
||||
if (!PL_strcasecmp(valueStr, "true") ||
|
||||
!PL_strcasecmp(valueStr, "yes"))
|
||||
pBVal->state = BVal_YES;
|
||||
else if (PL_strcasecmp(valueStr, "false") &&
|
||||
PL_strcasecmp(valueStr, "no"))
|
||||
return NO;;
|
||||
pBVal->state |= BVal_INITIALIZED;
|
||||
return YES;
|
||||
}
|
||||
|
||||
PUBLIC PRBool BVal_initialized(const BVal_t * pBVal)
|
||||
{
|
||||
return (pBVal->state & BVal_INITIALIZED);
|
||||
}
|
||||
|
||||
PUBLIC PRBool BVal_value(const BVal_t * pBVal)
|
||||
{
|
||||
return ((pBVal->state & BVal_YES) ? 1 : 0);
|
||||
}
|
||||
|
||||
PUBLIC void BVal_set(BVal_t * pBVal, PRBool value)
|
||||
{
|
||||
if (value)
|
||||
pBVal->state = BVal_YES;
|
||||
pBVal->state |= BVal_INITIALIZED;
|
||||
return;
|
||||
}
|
||||
|
||||
PUBLIC void BVal_clear(BVal_t * pBVal)
|
||||
{
|
||||
if (pBVal)
|
||||
pBVal->state = BVal_UNINITIALIZED;
|
||||
return;
|
||||
}
|
||||
|
||||
PUBLIC PRBool FVal_readVal(FVal_t * pFVal, const char * valueStr)
|
||||
{
|
||||
if (!PL_strcasecmp(valueStr, "+INF")) {
|
||||
pFVal->stat = FVal_POSITIVE_INF;
|
||||
return YES;
|
||||
}
|
||||
if (!PL_strcasecmp(valueStr, "-INF")) {
|
||||
pFVal->stat = FVal_NEGATIVE_INF;
|
||||
return YES;
|
||||
}
|
||||
pFVal->stat = FVal_VALUE;
|
||||
sscanf(valueStr, "%f", &pFVal->value);
|
||||
return YES;
|
||||
}
|
||||
|
||||
PUBLIC PRBool FVal_initialized(const FVal_t * pFVal)
|
||||
{
|
||||
return (pFVal->stat != FVal_UNINITIALIZED);
|
||||
}
|
||||
|
||||
PUBLIC float FVal_value(const FVal_t * pFVal)
|
||||
{
|
||||
return (pFVal->value);
|
||||
}
|
||||
|
||||
/* C U T T I N G E D G E M A T H T E C H N O L O G Y H E R E */
|
||||
PRIVATE PRBool FVal_lessThan(const FVal_t * pSmall, const FVal_t * pBig)
|
||||
{
|
||||
if (pBig->stat == FVal_UNINITIALIZED || pSmall->stat == FVal_UNINITIALIZED)
|
||||
return PR_FALSE;
|
||||
if (pBig->stat == FVal_POSITIVE_INF || pSmall->stat == FVal_NEGATIVE_INF) {
|
||||
if (pSmall->stat == FVal_POSITIVE_INF)
|
||||
return PR_FALSE;
|
||||
return PR_TRUE;
|
||||
}
|
||||
if (pBig->stat == FVal_NEGATIVE_INF || pSmall->stat == FVal_POSITIVE_INF) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
return pSmall->value < pBig->value;
|
||||
}
|
||||
|
||||
PUBLIC FVal_t FVal_minus(const FVal_t * pBig, const FVal_t * pSmall)
|
||||
{
|
||||
FVal_t ret = FVal_NEW_UNINITIALIZED;
|
||||
/* no notion of 2 time infinity so please keep your limits to a minimum */
|
||||
if (pBig->stat == FVal_UNINITIALIZED || pSmall->stat == FVal_UNINITIALIZED)
|
||||
return ret;
|
||||
FVal_set(&ret, (float)0.0);
|
||||
if (pBig->stat == FVal_POSITIVE_INF || pSmall->stat == FVal_NEGATIVE_INF) {
|
||||
if (pSmall->stat != FVal_POSITIVE_INF)
|
||||
FVal_setInfinite(&ret, 0);
|
||||
return ret;
|
||||
}
|
||||
if (pBig->stat == FVal_NEGATIVE_INF || pSmall->stat == FVal_POSITIVE_INF) {
|
||||
if (pSmall->stat != FVal_NEGATIVE_INF)
|
||||
FVal_setInfinite(&ret, 0);
|
||||
return ret;
|
||||
}
|
||||
ret.value = pBig->value - pSmall->value;
|
||||
return (ret);
|
||||
}
|
||||
|
||||
PUBLIC PRBool FVal_nearerZero(const FVal_t * pRef, const FVal_t * pCheck)
|
||||
{
|
||||
if (pRef->stat == FVal_UNINITIALIZED || pCheck->stat == FVal_UNINITIALIZED ||
|
||||
pCheck->stat == FVal_POSITIVE_INF || pCheck->stat == FVal_NEGATIVE_INF)
|
||||
return NO;
|
||||
if (pRef->stat == FVal_POSITIVE_INF || pRef->stat == FVal_NEGATIVE_INF)
|
||||
return YES;
|
||||
if (pRef->value < 0.0) {
|
||||
if (pCheck->value < 0.0)
|
||||
return pCheck->value > pRef->value;
|
||||
return pCheck->value < -pRef->value;
|
||||
}
|
||||
if (pCheck->value < 0.0)
|
||||
return pCheck->value > -pRef->value;
|
||||
return pCheck->value < pRef->value;
|
||||
}
|
||||
|
||||
PUBLIC PRBool FVal_isZero(const FVal_t * pFVal)
|
||||
{
|
||||
if (pFVal->stat == FVal_VALUE && pFVal->value == 0.0)
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
PUBLIC void FVal_set(FVal_t * pFVal, float value)
|
||||
{
|
||||
pFVal->value = value;
|
||||
pFVal->stat = FVal_VALUE;
|
||||
}
|
||||
|
||||
PUBLIC void FVal_setInfinite(FVal_t * pFVal, PRBool negative)
|
||||
{
|
||||
pFVal->stat = negative ? FVal_NEGATIVE_INF : FVal_POSITIVE_INF;
|
||||
}
|
||||
|
||||
PUBLIC PRInt32 FVal_isInfinite(const FVal_t * pFVal)
|
||||
{
|
||||
return (pFVal->stat == FVal_POSITIVE_INF ? 1 : pFVal->stat == FVal_NEGATIVE_INF ? -1 : 0);
|
||||
}
|
||||
|
||||
PUBLIC void FVal_clear(FVal_t * pFVal)
|
||||
{
|
||||
if (pFVal)
|
||||
pFVal->stat = FVal_UNINITIALIZED;
|
||||
return;
|
||||
}
|
||||
|
||||
PUBLIC char * FVal_toStr(FVal_t * pFVal)
|
||||
{
|
||||
char * ptr;
|
||||
if ((ptr = (char *)HT_MALLOC(40)) == NULL)
|
||||
HT_OUTOFMEM("FVal buffer");
|
||||
sprintf(ptr, "%.1f", FVal_value(pFVal));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
PUBLIC PRBool SVal_readVal(SVal_t * pSVal, const char * valueStr)
|
||||
{
|
||||
pSVal->initialized = YES;
|
||||
StrAllocCopy(pSVal->value, valueStr);
|
||||
return YES;
|
||||
}
|
||||
|
||||
PUBLIC PRBool SVal_initialized(const SVal_t * pSVal)
|
||||
{
|
||||
return (pSVal->initialized != NO);
|
||||
}
|
||||
|
||||
PUBLIC char * SVal_value(const SVal_t * pSVal)
|
||||
{
|
||||
return (pSVal->value);
|
||||
}
|
||||
|
||||
PUBLIC void SVal_clear(SVal_t * pSVal)
|
||||
{
|
||||
if (SVal_initialized(pSVal)) {
|
||||
HT_FREE(pSVal->value);
|
||||
pSVal->initialized = NO;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
PRInt32 year;
|
||||
PRInt32 month;
|
||||
PRInt32 day;
|
||||
PRInt32 hour;
|
||||
PRInt32 minute;
|
||||
PRInt32 timeZoneHours;
|
||||
PRInt32 timeZoneMinutes;
|
||||
#endif
|
||||
PUBLIC PRBool DVal_readVal(DVal_t * pDVal, const char * valueStr)
|
||||
{
|
||||
char space[] = "1994.11.05T08:15-0500";
|
||||
char timeZoneSign;
|
||||
char timeZoneMinutesMSB;
|
||||
if (PL_strlen(valueStr) != 0x15)
|
||||
return NO;
|
||||
memcpy(space, valueStr, 0x15);
|
||||
timeZoneSign = space[16];
|
||||
timeZoneMinutesMSB = space[19];
|
||||
space[4] = space[7] = space[10] = space[13] = space[16] = space[19] = 0;
|
||||
pDVal->year = atoi(space);
|
||||
pDVal->month = atoi(space+5);
|
||||
pDVal->day = atoi(space+8);
|
||||
pDVal->hour = atoi(space+11);
|
||||
pDVal->minute = atoi(space+14);
|
||||
pDVal->timeZoneHours = atoi(space+17);
|
||||
space[19] = timeZoneMinutesMSB;
|
||||
pDVal->timeZoneMinutes = atoi(space+19);
|
||||
if (timeZoneSign == '-') {
|
||||
pDVal->timeZoneHours = -pDVal->timeZoneHours;
|
||||
pDVal->timeZoneMinutes = -pDVal->timeZoneMinutes;
|
||||
}
|
||||
StrAllocCopy(pDVal->value, valueStr);
|
||||
pDVal->initialized = YES;
|
||||
return YES;
|
||||
}
|
||||
|
||||
PUBLIC PRBool DVal_initialized(const DVal_t * pDVal)
|
||||
{
|
||||
return (pDVal->initialized != NO);
|
||||
}
|
||||
|
||||
PUBLIC PRInt32 DVal_compare(const DVal_t * a, const DVal_t * b)
|
||||
{
|
||||
if (a->year > b->year) return 1;
|
||||
if (a->year < b->year) return -1;
|
||||
if (a->month > b->month) return 1;
|
||||
if (a->month < b->month) return -1;
|
||||
if (a->day > b->day) return 1;
|
||||
if (a->day < b->day) return -1;
|
||||
if (a->hour+a->timeZoneHours > b->hour+b->timeZoneHours) return 1;
|
||||
if (a->hour+a->timeZoneHours < b->hour+b->timeZoneHours) return -1;
|
||||
if (a->minute+a->timeZoneMinutes > b->minute+b->timeZoneMinutes) return 1;
|
||||
if (a->minute+a->timeZoneMinutes < b->minute+b->timeZoneMinutes) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
PUBLIC char * DVal_value(const DVal_t * pDVal)
|
||||
{
|
||||
return (pDVal->value);
|
||||
}
|
||||
|
||||
PUBLIC void DVal_clear(DVal_t * pDVal)
|
||||
{
|
||||
if (DVal_initialized(pDVal)) {
|
||||
HT_FREE(pDVal->value);
|
||||
pDVal->initialized = NO;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
PUBLIC char * Range_toStr(Range_t * pRange)
|
||||
{
|
||||
HTChunk * pChunk;
|
||||
char * ptr;
|
||||
pChunk = HTChunk_new(20);
|
||||
ptr = FVal_toStr(&pRange->min);
|
||||
HTChunk_puts(pChunk, ptr);
|
||||
HT_FREE(ptr);
|
||||
if (FVal_initialized(&pRange->max)) {
|
||||
ptr = FVal_toStr(&pRange->max);
|
||||
HTChunk_puts(pChunk, ":");
|
||||
HTChunk_puts(pChunk, ptr);
|
||||
HT_FREE(ptr);
|
||||
}
|
||||
return HTChunk_toCString(pChunk);
|
||||
}
|
||||
|
||||
/* Range_gap - find gap between 2 ranges. Either of these ranges may be a
|
||||
* single value (in the min)
|
||||
* negative vector indicates that ref is greater than test
|
||||
*/
|
||||
PUBLIC FVal_t Range_gap(Range_t * a, Range_t * b)
|
||||
{
|
||||
Range_t aN = *a;
|
||||
Range_t bN = *b;
|
||||
FVal_t ret = FVal_NEW_UNINITIALIZED;
|
||||
if (!FVal_initialized(&a->min) || !FVal_initialized(&b->min))
|
||||
return (ret);
|
||||
|
||||
/* set ret for successful 0 returns */
|
||||
FVal_set(&ret, (float)0.0);
|
||||
|
||||
/* normalize our ranges */
|
||||
if (FVal_lessThan(&aN.max, &aN.min)) {
|
||||
aN.max = a->min;
|
||||
aN.min = a->max;
|
||||
}
|
||||
if (FVal_lessThan(&bN.max, &bN.min)) {
|
||||
bN.max = b->min;
|
||||
bN.min = b->max;
|
||||
}
|
||||
|
||||
/* check partial ranges (just a min, no max) */
|
||||
if (!FVal_initialized(&aN.max)) {
|
||||
if (!FVal_initialized(&bN.max))
|
||||
return FVal_minus(&aN.min, &bN.min);
|
||||
if (FVal_lessThan(&aN.min, &bN.min))
|
||||
return FVal_minus(&bN.min, &aN.min);
|
||||
if (FVal_lessThan(&bN.max, &aN.min))
|
||||
return FVal_minus(&bN.max, &aN.min);
|
||||
return ret;
|
||||
}
|
||||
/* we have four values to compare */
|
||||
{
|
||||
FVal_t minDif = FVal_minus(&bN.min, &aN.min);
|
||||
FVal_t maxDif = FVal_minus(&bN.max, &aN.max);
|
||||
Range_t common;
|
||||
common.min = FVal_lessThan(&bN.min, &aN.min) ? aN.min : bN.min;
|
||||
common.max = FVal_lessThan(&bN.max, &aN.max) ? bN.max : aN.max;
|
||||
if (!FVal_lessThan(&common.max, &common.min))
|
||||
return ret;
|
||||
/* failure - indicate how far we are off */
|
||||
return FVal_nearerZero(&minDif, &maxDif) ? minDif : maxDif;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* C O N S T R U C T O R S */
|
||||
PUBLIC CSParse_t * CSParse_new(void)
|
||||
{
|
||||
CSParse_t * me;
|
||||
if ((me = (CSParse_t *) HT_CALLOC(1, sizeof(CSParse_t))) == NULL)
|
||||
HT_OUTOFMEM("CSParse");
|
||||
me->nowIn = NowIn_NEEDOPEN;
|
||||
me->token = HTChunk_new(0x10);
|
||||
if ((me->pParseContext = (ParseContext_t *) HT_CALLOC(1, sizeof(ParseContext_t))) == NULL)
|
||||
HT_OUTOFMEM("ParseContext_t");
|
||||
return me;
|
||||
}
|
||||
|
||||
PUBLIC void CSParse_delete(CSParse_t * me)
|
||||
{
|
||||
HT_FREE(me->pParseContext);
|
||||
HTChunk_delete(me->token);
|
||||
HT_FREE(me);
|
||||
}
|
||||
|
||||
/* L A B E L P A R S E R S */
|
||||
PRIVATE StateRet_t callErrorHandler(CSParse_t * pCSParse,
|
||||
const char * errorLocation,
|
||||
char demark, StateRet_t errorCode)
|
||||
{
|
||||
char * token = HTChunk_data(pCSParse->token);
|
||||
pCSParse->pParseContext->pTokenError = (char *)errorLocation;
|
||||
return (*pCSParse->pParseContext->pParseErrorHandler)(pCSParse, token,
|
||||
demark, StateRet_ERROR_BAD_CHAR);
|
||||
}
|
||||
|
||||
/* CSParse_parseChunk - elemental parse engine for all pics nowIns. This passes
|
||||
* tokenized data into the handler functions in the CSParse_t.handlersOf. These
|
||||
* handlers are responsibel for placing the data in the appropriate target.
|
||||
* The text is broken into nowIns and passed a SubParser based on the current
|
||||
* nowIn which is one of:
|
||||
* NowIn_NEEDOPEN - get paren and go to NowIn_ENGINE, text is an error
|
||||
* NowIn_ENGINE - in a containing structure, text goes to engineOf_
|
||||
* NowIn_NEEDCLOSE - get paren and go to NowIn_ENGINE, text is an error
|
||||
* NowIn_END - expect no more text or parens
|
||||
* NowIn_ERROR -
|
||||
*/
|
||||
PUBLIC CSDoMore_t CSParse_parseChunk (CSParse_t * pCSParse, const char * ptr, PRInt32 len, void * pVoid)
|
||||
{
|
||||
PRInt32 i;
|
||||
if (!len || !ptr)
|
||||
return CSDoMore_error;
|
||||
for (i = 0; i < len; i++) {
|
||||
pCSParse->offset++;
|
||||
if (pCSParse->quoteState) {
|
||||
if (pCSParse->quoteState == ptr[i]) {
|
||||
pCSParse->quoteState = 0;
|
||||
pCSParse->demark = ' ';
|
||||
}
|
||||
else
|
||||
HTChunk_putb(pCSParse->token, ptr+i, 1);
|
||||
continue;
|
||||
}
|
||||
if (ptr[i] == SQUOTE || ptr[i] == DQUOTE) {
|
||||
if (pCSParse->demark) {
|
||||
while ((pCSParse->nowIn = (*pCSParse->pParseContext->engineOf)(pCSParse, ' ', pVoid)) == NowIn_CHAIN)
|
||||
; /* */
|
||||
HTChunk_clear(pCSParse->token);
|
||||
pCSParse->demark = 0;
|
||||
} else if (HTChunk_size(pCSParse->token) &&
|
||||
/* && warn(pCSParse, message_UNEXPECTED_CHARACTER, ptr[i])) */
|
||||
callErrorHandler(pCSParse, ptr+i, ptr[i],
|
||||
StateRet_ERROR_BAD_CHAR) !=StateRet_OK)
|
||||
pCSParse->nowIn = NowIn_ERROR;
|
||||
pCSParse->quoteState = ptr[i];
|
||||
pCSParse->pParseContext->observedQuotes = YES;
|
||||
continue;
|
||||
}
|
||||
switch (pCSParse->nowIn) {
|
||||
case NowIn_NEEDOPEN:
|
||||
if (ptr[i] == LPAREN) {
|
||||
pCSParse->nowIn = NowIn_ENGINE;
|
||||
continue;
|
||||
}
|
||||
if (isspace(ptr[i]))
|
||||
continue;
|
||||
/* if (warn(pCSParse, message_UNEXPECTED_CHARACTER, ptr[i])) pCSParse->nowIn = NowIn_ERROR; */
|
||||
if (callErrorHandler(pCSParse, ptr+i, ptr[i],
|
||||
StateRet_ERROR_BAD_CHAR) !=StateRet_OK)
|
||||
pCSParse->nowIn = NowIn_ERROR;
|
||||
continue;
|
||||
case NowIn_ENGINE:
|
||||
if (isspace(ptr[i])) {
|
||||
if (HTChunk_size(pCSParse->token))
|
||||
pCSParse->demark = ' ';
|
||||
continue;
|
||||
}
|
||||
if (ptr[i] == LPAREN || ptr[i] == RPAREN || pCSParse->demark) {
|
||||
/* parens override space demarkation */
|
||||
if (ptr[i] == LPAREN) pCSParse->demark = LPAREN;
|
||||
if (ptr[i] == RPAREN) pCSParse->demark = RPAREN;
|
||||
/* call the engine as long as it wants re-entrance */
|
||||
while ((pCSParse->nowIn = (*pCSParse->pParseContext->engineOf)(pCSParse, pCSParse->demark, pVoid)) == NowIn_CHAIN)
|
||||
; /* */
|
||||
HTChunk_clear(pCSParse->token);
|
||||
pCSParse->demark = 0;
|
||||
if (ptr[i] == LPAREN || ptr[i] == RPAREN)
|
||||
continue;
|
||||
/* continue with next token */
|
||||
}
|
||||
HTChunk_putb(pCSParse->token, ptr+i, 1);
|
||||
continue;
|
||||
case NowIn_NEEDCLOSE:
|
||||
if (ptr[i] == RPAREN) {
|
||||
pCSParse->nowIn = NowIn_ENGINE;
|
||||
continue;
|
||||
}
|
||||
if (isspace(ptr[i]))
|
||||
continue;
|
||||
if (callErrorHandler(pCSParse, ptr+i, ptr[i],
|
||||
StateRet_ERROR_BAD_CHAR) !=StateRet_OK)
|
||||
pCSParse->nowIn = NowIn_ERROR;
|
||||
/* if (warn(pCSParse, message_UNEXPECTED_CHARACTER, ptr[i])) pCSParse->nowIn = NowIn_ERROR; */
|
||||
continue;
|
||||
case NowIn_END:
|
||||
#if 0 /* enable this to tell the parser to check the remainder of
|
||||
the stream after the parsed object thinks it is done */
|
||||
if (isspace(ptr[i]))
|
||||
continue;
|
||||
/* if (warn(pCSParse, message_UNEXPECTED_CHARACTER, ptr[i])) pCSParse->nowIn = NowIn_ERROR; */
|
||||
if (callErrorHandler(pCSParse, ptr+i, ptr[i],
|
||||
StateRet_ERROR_BAD_CHAR) !=StateRet_OK)
|
||||
pCSParse->nowIn = NowIn_ERROR;
|
||||
continue;
|
||||
#else
|
||||
return CSDoMore_done;
|
||||
#endif
|
||||
case NowIn_MATCHCLOSE:
|
||||
if (ptr[i] == RPAREN) {
|
||||
if (!pCSParse->depth)
|
||||
pCSParse->nowIn = NowIn_ENGINE;
|
||||
else
|
||||
pCSParse->depth--;
|
||||
}
|
||||
if (ptr[i] == LPAREN)
|
||||
pCSParse->depth++;
|
||||
continue;
|
||||
case NowIn_ERROR:
|
||||
return CSDoMore_error;
|
||||
break;
|
||||
default:
|
||||
/* if (warn(pCSParse, message_INTERNAL_ERROR, "bad nowIn")) pCSParse->nowIn = NowIn_ERROR; */
|
||||
HTTrace("PICS: Internal error in parser - bad nowIn:%d.\n",
|
||||
pCSParse->nowIn);
|
||||
return CSDoMore_error;
|
||||
}
|
||||
}
|
||||
/* check completion */
|
||||
return pCSParse->nowIn == NowIn_END ? CSDoMore_done : CSDoMore_more;
|
||||
}
|
||||
|
||||
PUBLIC PRBool Punct_badDemark(Punct_t validPunctuation, char demark)
|
||||
{
|
||||
switch (demark) {
|
||||
case ' ': return (!(validPunctuation & Punct_WHITE));
|
||||
case LPAREN: return (!(validPunctuation & Punct_LPAREN));
|
||||
case RPAREN: return (!(validPunctuation & Punct_RPAREN));
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
#if 0
|
||||
PRIVATE void Input_dump(char * token, char demark)
|
||||
{
|
||||
char space[256];
|
||||
sprintf(space, " %s |%c|\n", token, demark);
|
||||
HTTrace(space);
|
||||
}
|
||||
#endif
|
||||
PRIVATE char * CSParse_subState2str(SubState_t subState)
|
||||
{
|
||||
static char space[33];
|
||||
space[0] = 0;
|
||||
if (subState == SubState_N)
|
||||
PL_strcpy(space, "N");
|
||||
else if (subState == SubState_X)
|
||||
PL_strcpy(space, "X");
|
||||
else {
|
||||
PRInt32 i;
|
||||
SubState_t comp;
|
||||
char ch[] = "A";
|
||||
for (i = 1, comp = SubState_A; i < (sizeof(SubState_t)*8 - 1); i++, (*ch)++, comp<<=1)
|
||||
if (comp & subState)
|
||||
PL_strcat(space, ch);
|
||||
}
|
||||
return space;
|
||||
}
|
||||
|
||||
PRIVATE PRInt32 ParseTrace(const char * fmt, ...)
|
||||
{
|
||||
va_list pArgs;
|
||||
|
||||
va_start(pArgs, fmt);
|
||||
|
||||
if (!ParseDebug)
|
||||
return 0;
|
||||
return (vfprintf(stderr, fmt, pArgs));
|
||||
}
|
||||
|
||||
PUBLIC NowIn_t CSParse_targetParser(CSParse_t * pCSParse, char demark, void * pVoid)
|
||||
{
|
||||
/* ParseContext_t * pParseContext = pCSParse->pParseContext; */
|
||||
TargetObject_t * pTargetObject = pCSParse->pTargetObject;
|
||||
PRBool failedOnPunct = NO;
|
||||
char * token = 0;
|
||||
StateRet_t ret = StateRet_OK;
|
||||
PRInt32 i;
|
||||
static NowIn_t lastRet = NowIn_END;
|
||||
|
||||
/* changed by montulli@netscape.com 11/29/97
|
||||
* if (HTChunk_size(pCSParse->token)) {
|
||||
* HTChunk_terminate(pCSParse->token);
|
||||
* token = HTChunk_data(pCSParse->token);
|
||||
* }
|
||||
*/
|
||||
if(HTChunk_data(pCSParse->token))
|
||||
{
|
||||
HTChunk_terminate(pCSParse->token);
|
||||
token = HTChunk_data(pCSParse->token);
|
||||
}
|
||||
|
||||
/*Input_dump(token, demark);*/
|
||||
for (i = 0; i < pTargetObject->stateTokenCount; i++) {
|
||||
StateToken_t * pStateToken = pTargetObject->stateTokens + i;
|
||||
pCSParse->pStateToken = pStateToken;
|
||||
|
||||
if (!(pCSParse->currentSubState & pStateToken->validSubStates))
|
||||
continue;
|
||||
if (pStateToken->pCheck) { /* use check function */
|
||||
StateRet_t checkRes;
|
||||
checkRes = (*pStateToken->pCheck)(pCSParse, pStateToken, token, demark);
|
||||
switch (checkRes) {
|
||||
case StateRet_WARN_BAD_PUNCT:
|
||||
failedOnPunct = YES;
|
||||
case StateRet_WARN_NO_MATCH:
|
||||
continue;
|
||||
case StateRet_ERROR_BAD_CHAR:
|
||||
(*pCSParse->pParseContext->pParseErrorHandler)(pCSParse, token, demark, StateRet_ERROR_BAD_CHAR);
|
||||
/* if (pTargetObject->pDestroy)
|
||||
(*pTargetObject->pDestroy)(pCSParse); */
|
||||
return NowIn_ERROR;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else { /* or match by name[s] */
|
||||
if (!(pStateToken->command & Command_MATCHANY)) {
|
||||
if (token && pStateToken->name1) {
|
||||
if (PL_strcasecmp(token, pStateToken->name1) && (!pStateToken->name2 || PL_strcasecmp(token, pStateToken->name2)))
|
||||
continue;
|
||||
} else {
|
||||
if (token != pStateToken->name1)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (Punct_badDemark(pStateToken->validPunctuation, demark)) {
|
||||
failedOnPunct = YES;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/* open or close and do the appropriate callbacks */
|
||||
if (lastRet != NowIn_CHAIN)
|
||||
ParseTrace("%30s %c ", token ? token : "", demark);
|
||||
ParseTrace("%10s - %s:%10s => ", pCSParse->pTargetObject->note, CSParse_subState2str(pCSParse->currentSubState), pStateToken->note);
|
||||
if (pStateToken->command & Command_NOTOKEN) {
|
||||
HTChunk_clear(pCSParse->token);
|
||||
token = 0;
|
||||
}
|
||||
if (pStateToken->command & Command_OPEN && pTargetObject->pOpen)
|
||||
if ((*pTargetObject->pOpen)(pCSParse, token, demark) == StateRet_ERROR)
|
||||
return NowIn_ERROR;
|
||||
|
||||
if (pStateToken->command & (Command_OPEN|Command_CLOSE) && pCSParse->pParseContext->pTargetChangeCallback) {
|
||||
ParseTrace("%3d", pStateToken->command & Command_CLOSE ? -(PRInt32)pTargetObject->targetChange : pTargetObject->targetChange);
|
||||
if ((*pCSParse->pParseContext->pTargetChangeCallback)(pCSParse, pTargetObject, pTargetObject->targetChange,
|
||||
(PRBool)(pStateToken->command & Command_CLOSE), pVoid) == StateRet_ERROR)
|
||||
return NowIn_ERROR;
|
||||
} else
|
||||
ParseTrace(" ");
|
||||
if (pStateToken->command & Command_CLOSE && pTargetObject->pClose)
|
||||
ret = (*pTargetObject->pClose)(pCSParse, token, demark);
|
||||
|
||||
if (pStateToken->pPrep && ret != NowIn_ERROR)
|
||||
ret = (*pStateToken->pPrep)(pCSParse, token, demark);
|
||||
if (pStateToken->pNextTargetObject)
|
||||
pCSParse->pTargetObject = pStateToken->pNextTargetObject;
|
||||
if (pStateToken->nextSubState != SubState_X)
|
||||
pCSParse->currentSubState = pStateToken->nextSubState;
|
||||
/*
|
||||
CSLabel_dump(pCSLabel);
|
||||
HTTrace(pCSParse->pTargetObject->note);
|
||||
*/
|
||||
ParseTrace("%10s - %s", pCSParse->pTargetObject->note, CSParse_subState2str(pCSParse->currentSubState));
|
||||
if (pStateToken->command & Command_CHAIN) {
|
||||
ParseTrace(" -O-O-");
|
||||
return lastRet = NowIn_CHAIN;
|
||||
}
|
||||
ParseTrace("\n");
|
||||
return lastRet = ret == StateRet_ERROR_BAD_CHAR ? NowIn_ERROR : ret == StateRet_DONE ? NowIn_END : NowIn_ENGINE;
|
||||
}
|
||||
(*pCSParse->pParseContext->pParseErrorHandler)(pCSParse, token, demark, failedOnPunct ? StateRet_WARN_BAD_PUNCT : StateRet_WARN_NO_MATCH);
|
||||
if (pTargetObject->pDestroy)
|
||||
(*pTargetObject->pDestroy)(pCSParse);
|
||||
return NowIn_ERROR;
|
||||
}
|
||||
|
||||
@ -1,343 +0,0 @@
|
||||
|
||||
/* W3 Copyright statement
|
||||
Copyright 1995 by: Massachusetts Institute of Technology (MIT), INRIA</H2>
|
||||
|
||||
This W3C software is being provided by the copyright holders under the
|
||||
following license. By obtaining, using and/or copying this software,
|
||||
you agree that you have read, understood, and will comply with the
|
||||
following terms and conditions:
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee or royalty is hereby
|
||||
granted, provided that the full text of this NOTICE appears on
|
||||
<EM>ALL</EM> copies of the software and documentation or portions
|
||||
thereof, including modifications, that you make.
|
||||
|
||||
<B>THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
|
||||
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE,
|
||||
BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
|
||||
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
|
||||
THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY
|
||||
THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
||||
COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE
|
||||
OR DOCUMENTATION.
|
||||
|
||||
The name and trademarks of copyright holders may NOT be used
|
||||
in advertising or publicity pertaining to the software without
|
||||
specific, written prior permission. Title to copyright in this
|
||||
software and any associated documentation will at all times remain
|
||||
with copyright holders.
|
||||
*/
|
||||
/* Parser for libpics
|
||||
PARSER FOR LIBPICS
|
||||
|
||||
*/
|
||||
/*
|
||||
** (c) COPYRIGHT MIT 1996.
|
||||
** Please first read the full copyright statement in the file COPYRIGH.
|
||||
*/
|
||||
/*
|
||||
|
||||
This module provides the interface to CSParse.c. The parser is used to parse labels,
|
||||
machine-readable descriptions, and users. The application creates one of these and
|
||||
iteratevely calls CSParse_parseChunk until it returns a done or an error.
|
||||
|
||||
*/
|
||||
#ifndef CSPARSE_H
|
||||
#define CSPARSE_H
|
||||
#include "cslutils.h"
|
||||
#include "htchunk.h"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
NOWIN
|
||||
|
||||
tells CSParse where it is in the task of tokenizing
|
||||
|
||||
*/
|
||||
typedef enum {
|
||||
NowIn_INVALID = 0,
|
||||
NowIn_NEEDOPEN,
|
||||
NowIn_ENGINE,
|
||||
NowIn_NEEDCLOSE,
|
||||
NowIn_END,
|
||||
NowIn_MATCHCLOSE,
|
||||
NowIn_ERROR,
|
||||
NowIn_CHAIN
|
||||
} NowIn_t;
|
||||
/*
|
||||
|
||||
Construction/Destruction
|
||||
|
||||
The parse objects are never created by the application, but instead by one of the
|
||||
objects that it is used to parse.
|
||||
|
||||
*/
|
||||
extern CSParse_t * CSParse_new(void);
|
||||
extern void CSParse_delete(CSParse_t * me);
|
||||
/*
|
||||
|
||||
some handy definitions
|
||||
|
||||
*/
|
||||
#define LPAREN '('
|
||||
#define RPAREN ')'
|
||||
#define LCURLY '{'
|
||||
#define RCURLY '}'
|
||||
#define LBRACKET '['
|
||||
#define RBRACKET ']'
|
||||
#define SQUOTE 0x27 /* avoid confusing parens checking editors */
|
||||
#define DQUOTE 0x22
|
||||
#define LPARENSTR "("
|
||||
#define RPARENSTR ")"
|
||||
#define raysize(A) (sizeof(A)/sizeof(A[0]))
|
||||
/*
|
||||
|
||||
SUBPARSER DATA
|
||||
|
||||
PUNCT
|
||||
|
||||
valid punctuation
|
||||
|
||||
*/
|
||||
typedef enum {Punct_ZERO = 1, Punct_WHITE = 2, Punct_LPAREN = 4,
|
||||
Punct_RPAREN = 8, Punct_ALL = 0xf} Punct_t;
|
||||
/*
|
||||
|
||||
SUBSTATE
|
||||
|
||||
Enumerated bits that are used to mark a parsing state. Because they are bits, as
|
||||
opposed to sequential numbers, a StateToken may or more than one together and serve
|
||||
more than one state. They must have identical outcomes if this is to be exploited.
|
||||
|
||||
By convention, the following SubState names are used:
|
||||
|
||||
X - has no state
|
||||
|
||||
N - is a newly created object
|
||||
|
||||
A-H - substate definitions. Because they are non-conflicting bits, a subparser may have
|
||||
options that sit in more than state. For instance, the string "error" may be matched in
|
||||
states A and C with:
|
||||
|
||||
{"error test", SubState_A|SubState_C, Punct_LPAREN, 0, "error"} *probs* I meant to keep
|
||||
these 16 bit caompatible, but ran up short at the end of one StateToken list. This can
|
||||
be fixed if anyone needs a 16 bit enum.
|
||||
|
||||
*/
|
||||
typedef enum {SubState_X = -1, SubState_N = 0x4000, SubState_A = 1,
|
||||
SubState_B = 2, SubState_C = 4, SubState_D = 8,
|
||||
SubState_E = 0x10, SubState_F = 0x20, SubState_G = 0x40,
|
||||
SubState_H = 0x80, SubState_I = 0x100} SubState_t;
|
||||
/*
|
||||
|
||||
forward declaration for StateToken_t
|
||||
|
||||
*/
|
||||
typedef struct StateToken_s StateToken_t;
|
||||
/*
|
||||
|
||||
ENGINE
|
||||
|
||||
called by CSParse to process tokens and punctuation
|
||||
|
||||
*/
|
||||
typedef NowIn_t Engine_t(CSParse_t * pCSParse, char demark, void * pVoid);
|
||||
/*
|
||||
|
||||
Engine employed by the Label, MacRed, and User parsers
|
||||
|
||||
*/
|
||||
Engine_t CSParse_targetParser;
|
||||
/*
|
||||
|
||||
SUBSTATE METHODS
|
||||
|
||||
All methods return a StateRet.
|
||||
|
||||
Check
|
||||
|
||||
see if a value is legitimate, may also record it
|
||||
|
||||
*/
|
||||
typedef StateRet_t Check_t(CSParse_t * pCSParse, StateToken_t * pStateToken,
|
||||
char * token, char demark);
|
||||
/*
|
||||
|
||||
Punctuation checker to be employed by Check_t functions
|
||||
|
||||
*/
|
||||
extern PRBool Punct_badDemark(Punct_t validPunctuation, char demark);
|
||||
/*
|
||||
|
||||
Open
|
||||
|
||||
create a new data structure to be filled by the parser
|
||||
|
||||
*/
|
||||
typedef StateRet_t Open_t(CSParse_t * pCSParse, char * token, char demark);
|
||||
/*
|
||||
|
||||
Close
|
||||
|
||||
tell the state that the data structure is no longer current
|
||||
|
||||
*/
|
||||
typedef StateRet_t Close_t(CSParse_t * pCSParse, char * token, char demark);
|
||||
/*
|
||||
|
||||
Prep
|
||||
|
||||
get ready for next state
|
||||
|
||||
*/
|
||||
typedef StateRet_t Prep_t(CSParse_t * pCSParse, char * token, char demark);
|
||||
/*
|
||||
|
||||
Destroy
|
||||
|
||||
something went wrong, throw away the current object
|
||||
|
||||
*/
|
||||
typedef void Destroy_t(CSParse_t * pCSParse);
|
||||
/*
|
||||
|
||||
COMMAND
|
||||
|
||||
substate commands
|
||||
|
||||
open - call the open function for the current data structure
|
||||
|
||||
close - call the close
|
||||
|
||||
chain - call again on the next state without re-reading data
|
||||
|
||||
notoken - clear the token before a chain (so next state just gets punct)
|
||||
|
||||
matchany - match any string
|
||||
|
||||
*/
|
||||
typedef enum {Command_NONE = 0, Command_OPEN = 1, Command_CLOSE = 2,
|
||||
Command_CHAIN = 4, Command_NOTOKEN = 8,
|
||||
Command_MATCHANY = 0x10} Command_t;
|
||||
/*
|
||||
|
||||
STATETOKEN STRUCTURE
|
||||
|
||||
Contains all the information about what tokens are expected in what substates. The
|
||||
StateTokens are kept in array referenced by a TargetObject.
|
||||
|
||||
*/
|
||||
struct StateToken_s {
|
||||
char * note; /* some usefull text that describes the state - usefulll f
|
||||
or debugging */
|
||||
SubState_t validSubStates;
|
||||
Punct_t validPunctuation;
|
||||
Check_t * pCheck; /* call this function to check token */
|
||||
char * name1; /* or compare to this name */
|
||||
char * name2; /* many strings have 2 spellings ("ratings" vs. "r") */
|
||||
CSParseTC_t targetChange; /* whether target change implies diving or climbing from cur
|
||||
rent state */
|
||||
TargetObject_t * pNextTargetObject;
|
||||
SubState_t nextSubState;
|
||||
Command_t command; /* open, close, chain, etc. */
|
||||
Prep_t * pPrep; /* prepare for next state */
|
||||
};
|
||||
/*
|
||||
|
||||
TARGETOBJECT STRUCTURE
|
||||
|
||||
Methods and a lists of StateTokens associated with a data structure. The methods know
|
||||
how to read data into current object and the StateTokens tell when to proceed to the
|
||||
next object.
|
||||
|
||||
*/
|
||||
struct TargetObject_s {
|
||||
char * note;
|
||||
Open_t * pOpen; /* call this function to open structure */
|
||||
Close_t * pClose; /* call this function to close structure */
|
||||
Destroy_t * pDestroy;
|
||||
StateToken_t * stateTokens; /* array of sub states */
|
||||
PRInt32 stateTokenCount; /* number of sub states */
|
||||
CSParseTC_t targetChange; /* target change signal for opening this parse state */
|
||||
};
|
||||
/*
|
||||
|
||||
VALTARGET
|
||||
|
||||
*/
|
||||
typedef union {
|
||||
BVal_t * pTargetBVal;
|
||||
FVal_t * pTargetFVal;
|
||||
SVal_t * pTargetSVal;
|
||||
DVal_t * pTargetDVal;
|
||||
HTList ** pTargetList;
|
||||
} ValTarget_t;
|
||||
/*
|
||||
|
||||
VALTYPE
|
||||
|
||||
Write down what value is to be read, and what type it is
|
||||
|
||||
*/
|
||||
typedef enum {ValType_NONE, ValType_BVAL, ValType_FVAL,
|
||||
ValType_SVAL, ValType_DVAL,
|
||||
ValType_COMMENT} ValType_t;
|
||||
/*
|
||||
|
||||
PARSECONTEXT
|
||||
|
||||
Part of a CSParse. The boundry is a litte fuzzy. Maybe it should not exist.
|
||||
|
||||
*/
|
||||
typedef struct {
|
||||
Engine_t * engineOf;
|
||||
TargetChangeCallback_t * pTargetChangeCallback;
|
||||
ParseErrorHandler_t * pParseErrorHandler;
|
||||
|
||||
/* for reading [BFSD]Val_t */
|
||||
ValTarget_t valTarget;
|
||||
ValType_t valType;
|
||||
|
||||
char * pTokenError;
|
||||
|
||||
PRBool observeQuotes;
|
||||
PRBool observedQuotes;
|
||||
char * legalChars;
|
||||
PRInt32 legalCharCount;
|
||||
} ParseContext_t;
|
||||
/*
|
||||
|
||||
CSPARSE STRUCTURE
|
||||
|
||||
Full parser state and pointer to the object that it is reading.
|
||||
|
||||
*/
|
||||
struct CSParse_s {
|
||||
char quoteState;
|
||||
NowIn_t nowIn;
|
||||
HTChunk * token;
|
||||
char demark;
|
||||
PRInt32 offset;
|
||||
PRInt32 depth;
|
||||
ParseContext_t * pParseContext;
|
||||
union { /* all the types this parse engine fills */
|
||||
CSMachRead_t * pCSMachRead; /* defined in CSMacRed.c */
|
||||
CSLabel_t * pCSLabel; /* defined in CSLabel.c */
|
||||
CSUser_t * pCSUser; /* defined in CSUser.c */
|
||||
} target;
|
||||
TargetObject_t * pTargetObject;
|
||||
SubState_t currentSubState;
|
||||
StateToken_t * pStateToken;
|
||||
};
|
||||
/*
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#endif /* CSPARSE_H */
|
||||
/*
|
||||
|
||||
End of Declaration */
|
||||
@ -1,198 +0,0 @@
|
||||
|
||||
/* W3 Copyright statement
|
||||
Copyright 1995 by: Massachusetts Institute of Technology (MIT), INRIA</H2>
|
||||
|
||||
This W3C software is being provided by the copyright holders under the
|
||||
following license. By obtaining, using and/or copying this software,
|
||||
you agree that you have read, understood, and will comply with the
|
||||
following terms and conditions:
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee or royalty is hereby
|
||||
granted, provided that the full text of this NOTICE appears on
|
||||
<EM>ALL</EM> copies of the software and documentation or portions
|
||||
thereof, including modifications, that you make.
|
||||
|
||||
<B>THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
|
||||
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE,
|
||||
BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
|
||||
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
|
||||
THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY
|
||||
THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
||||
COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE
|
||||
OR DOCUMENTATION.
|
||||
|
||||
The name and trademarks of copyright holders may NOT be used
|
||||
in advertising or publicity pertaining to the software without
|
||||
specific, written prior permission. Title to copyright in this
|
||||
software and any associated documentation will at all times remain
|
||||
with copyright holders.
|
||||
*/
|
||||
/* HTChunk.c
|
||||
** CHUNK HANDLING: FLEXIBLE ARRAYS
|
||||
**
|
||||
** (c) COPYRIGHT MIT 1995.
|
||||
** Please first read the full copyright statement in the file COPYRIGH.
|
||||
** @(#) $Id: htchunk.c,v 1.2 1999-05-07 05:26:11 neeti%netscape.com Exp $
|
||||
**
|
||||
** history: AL, HF 28 Apr 94, Now chunk->data is filled by '\0' so
|
||||
** that the string is terminated at any time. That makes
|
||||
** HTChunk_terminate not needed any more, but never mind.
|
||||
** EGP 15 Mar 96, Added CString conversions.
|
||||
**
|
||||
*/
|
||||
|
||||
/* Library include files */
|
||||
#include "xp_core.h"
|
||||
#include "plstr.h"
|
||||
/* #include "sysdep.h" 7/9/97 -- jhines */
|
||||
#include "htutils.h"
|
||||
#include "htchunk.h" /* Implemented here */
|
||||
|
||||
/* Create a chunk with a certain allocation unit
|
||||
** --------------
|
||||
*/
|
||||
PUBLIC HTChunk * HTChunk_new (PRInt32 grow)
|
||||
{
|
||||
HTChunk * ch;
|
||||
if ((ch = (HTChunk *) HT_CALLOC(1, sizeof(HTChunk))) == NULL)
|
||||
HT_OUTOFMEM("HTChunk_new");
|
||||
ch->growby = grow;
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
/* Clear a chunk of all data
|
||||
** --------------------------
|
||||
** Zero the space but do NOT HT_FREE it. We zero because we promise to have
|
||||
** a NUL terminated string at all times.
|
||||
*/
|
||||
PUBLIC void HTChunk_clear (HTChunk * ch)
|
||||
{
|
||||
if (ch) {
|
||||
ch->size = 0;
|
||||
memset((void *) ch->data, '\0', ch->allocated);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Free a chunk
|
||||
** ------------
|
||||
*/
|
||||
PUBLIC void HTChunk_delete (HTChunk * ch)
|
||||
{
|
||||
if (ch) {
|
||||
HT_FREE(ch->data);
|
||||
HT_FREE(ch);
|
||||
}
|
||||
}
|
||||
|
||||
/* Create a chunk from an allocated string
|
||||
** ---------------------------------------
|
||||
*/
|
||||
PUBLIC HTChunk * HTChunk_fromCString (char * str, PRInt32 grow)
|
||||
{
|
||||
HTChunk * ch;
|
||||
ch = HTChunk_new(grow);
|
||||
if (str) {
|
||||
ch->data = str; /* can't handle non-allocated str */
|
||||
ch->size = PL_strlen(str);
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
|
||||
/* Free a chunk but keep the data
|
||||
** ------------------------------
|
||||
*/
|
||||
PUBLIC char * HTChunk_toCString (HTChunk * ch)
|
||||
{
|
||||
char * ret = 0;
|
||||
if (ch) {
|
||||
ret = ch->data;
|
||||
HT_FREE(ch);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Append a character
|
||||
** ------------------
|
||||
*/
|
||||
PUBLIC void HTChunk_putc (HTChunk * ch, char c)
|
||||
{
|
||||
if (ch) {
|
||||
if (ch->size >= ch->allocated-1) {
|
||||
if (ch->data) {
|
||||
if ((ch->data = (char *) HT_REALLOC(ch->data,ch->allocated+ch->growby)) == NULL)
|
||||
HT_OUTOFMEM("HTChunk_putc");
|
||||
memset((void *) (ch->data + ch->allocated), '\0', ch->growby);
|
||||
} else {
|
||||
if ((ch->data = (char *) HT_CALLOC(1, ch->allocated+ch->growby)) == NULL)
|
||||
HT_OUTOFMEM("HTChunk_putc");
|
||||
}
|
||||
ch->allocated += ch->growby;
|
||||
}
|
||||
*(ch->data+ch->size++) = c;
|
||||
}
|
||||
}
|
||||
|
||||
/* Append a string
|
||||
** ---------------
|
||||
*/
|
||||
PUBLIC void HTChunk_puts (HTChunk * ch, const char * s)
|
||||
{
|
||||
HTChunk_putb(ch, s, (PRInt32) PL_strlen(s));
|
||||
}
|
||||
|
||||
/* Append a block
|
||||
** ---------------
|
||||
** The string is always zero terminated
|
||||
*/
|
||||
PUBLIC void HTChunk_putb (HTChunk * ch, const char * block, PRInt32 len)
|
||||
{
|
||||
if (ch && block && len) {
|
||||
PRInt32 needed = ch->size+len;
|
||||
if (needed >= ch->allocated) {
|
||||
ch->allocated = needed - needed%ch->growby + ch->growby;
|
||||
if (ch->data) {
|
||||
if ((ch->data = (char *) HT_REALLOC(ch->data, ch->allocated)) == NULL)
|
||||
HT_OUTOFMEM("HTChunk_putb");
|
||||
memset((void *) (ch->data + needed), '\0', ch->allocated-needed);
|
||||
} else {
|
||||
if ((ch->data = (char *) HT_CALLOC(1, ch->allocated)) == NULL)
|
||||
HT_OUTOFMEM("HTChunk_putb");
|
||||
}
|
||||
}
|
||||
memcpy((void *) (ch->data+ch->size), block, len);
|
||||
ch->size = needed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Ensure a certain size
|
||||
** ---------------------
|
||||
*/
|
||||
PUBLIC void HTChunk_ensure (HTChunk * ch, PRInt32 len)
|
||||
{
|
||||
if (ch && len) {
|
||||
PRInt32 needed = ch->size+len;
|
||||
if (needed >= ch->allocated) {
|
||||
ch->allocated = needed - needed%ch->growby + ch->growby;
|
||||
if (ch->data) {
|
||||
if ((ch->data = (char *) HT_REALLOC(ch->data, ch->allocated)) == NULL)
|
||||
HT_OUTOFMEM("HTChunk_putb");
|
||||
memset((void *) (ch->data + ch->size), '\0', ch->allocated-ch->size);
|
||||
} else {
|
||||
if ((ch->data = (char *) HT_CALLOC(1, ch->allocated)) == NULL)
|
||||
HT_OUTOFMEM("ch->data ");
|
||||
}
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
if (needed <= ch->allocated) return;
|
||||
ch->allocated = needed-1 - ((needed-1) % ch->growby)
|
||||
+ ch->growby; /* Round up */
|
||||
ch->data = ch->data ? (char *)PR_REALLOC(ch->data, ch->allocated)
|
||||
: (char *)HT_MALLOC(ch->allocated);
|
||||
if (ch->data == NULL) HT_OUTOFMEM(__FILE__, "HTChunk_ensure");
|
||||
#endif
|
||||
}
|
||||
@ -1,192 +0,0 @@
|
||||
|
||||
/* W3 Copyright statement
|
||||
Copyright 1995 by: Massachusetts Institute of Technology (MIT), INRIA</H2>
|
||||
|
||||
This W3C software is being provided by the copyright holders under the
|
||||
following license. By obtaining, using and/or copying this software,
|
||||
you agree that you have read, understood, and will comply with the
|
||||
following terms and conditions:
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee or royalty is hereby
|
||||
granted, provided that the full text of this NOTICE appears on
|
||||
<EM>ALL</EM> copies of the software and documentation or portions
|
||||
thereof, including modifications, that you make.
|
||||
|
||||
<B>THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
|
||||
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE,
|
||||
BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
|
||||
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
|
||||
THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY
|
||||
THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
||||
COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE
|
||||
OR DOCUMENTATION.
|
||||
|
||||
The name and trademarks of copyright holders may NOT be used
|
||||
in advertising or publicity pertaining to the software without
|
||||
specific, written prior permission. Title to copyright in this
|
||||
software and any associated documentation will at all times remain
|
||||
with copyright holders.
|
||||
*/
|
||||
/* W3C Reference Library libwww Chunk Class
|
||||
THE CHUNK CLASS
|
||||
|
||||
*/
|
||||
/*
|
||||
** (c) COPYRIGHT MIT 1995.
|
||||
** Please first read the full copyright statement in the file COPYRIGH.
|
||||
*/
|
||||
/*
|
||||
|
||||
The Chunk Class defines a way to automatically handle dynamic strings and other data
|
||||
types. You create a chunk with an initial size and it will then automatically grow to
|
||||
accomodate added data to the chunk. It is a general utility module. It is garanteed
|
||||
that the array is '\0' terminated at all times (and hence is a valid C type string).
|
||||
The method HTChunkTerminate can be used to explicitly add a terminating '\0'and then to
|
||||
include this character in the chunk size. If left out, the terminating character is
|
||||
_not_ considered part of the chunk.
|
||||
|
||||
_Note_: The names without a "_" (made as a #define's) are only provided for backwards
|
||||
compatibility and should not be used.
|
||||
|
||||
This module is implemented by HTChunk.c, and it is a part of the W3C Reference Library.
|
||||
|
||||
*/
|
||||
#ifndef HTCHUNK_H
|
||||
#define HTCHUNK_H
|
||||
|
||||
/*
|
||||
|
||||
THE CHUNK CLASS
|
||||
|
||||
This structure should not be referenced outside this module! We only keep it here to
|
||||
maintain high performance. _Don't _use it directly!
|
||||
|
||||
*/
|
||||
typedef struct {
|
||||
PRInt32 size; /* In bytes */
|
||||
PRInt32 growby; /* Allocation unit in bytes */
|
||||
PRInt32 allocated; /* Current size of *data */
|
||||
char * data; /* Pointer to malloced area or 0 */
|
||||
} HTChunk;
|
||||
/*
|
||||
|
||||
CREATE NEW CHUNK
|
||||
|
||||
Create a new chunk and specify the number of bytes to allocate at a time when the chunk
|
||||
is later extended. Arbitrary but normally a trade-off time vs. memory
|
||||
|
||||
*/
|
||||
#define HTChunkCreate(growby) HTChunk_new(growby)
|
||||
extern HTChunk * HTChunk_new (PRInt32 growby);
|
||||
/*
|
||||
|
||||
FREE A CHUNK
|
||||
|
||||
Free a chunk created by HTChunkCreatefrom memory
|
||||
|
||||
*/
|
||||
#define HTChunkFree(ch) HTChunk_delete(ch)
|
||||
extern void HTChunk_delete (HTChunk * ch);
|
||||
/*
|
||||
|
||||
CLEAR A CHUNK
|
||||
|
||||
Keep the chunk in memory but clear all data kept inside. This can be used if you know
|
||||
that you can reuse the allocated memory instead of allocating new memory.
|
||||
|
||||
*/
|
||||
#define HTChunkClear(ch) HTChunk_clear(ch)
|
||||
extern void HTChunk_clear (HTChunk * ch);
|
||||
/*
|
||||
|
||||
ENSURE A CHUNK HAS A CERTAIN AMOUNT OF FREE SPACE
|
||||
|
||||
Make sure that a chunk has a certain size. If this is not the case then the chunk is
|
||||
expanded. Nothing is done if the current size if bigger than the size requested.
|
||||
|
||||
*/
|
||||
#define HTChunkEnsure(ch, s) HTChunk_ensure(ch, s)
|
||||
extern void HTChunk_ensure (HTChunk * ch, PRInt32 s);
|
||||
/*
|
||||
|
||||
APPEND A CHARACTER TO A CHUNK
|
||||
|
||||
Add the character and increment the size of the chunk by one character
|
||||
|
||||
*/
|
||||
#define HTChunkPutc(ch, c) HTChunk_putc(ch, c)
|
||||
extern void HTChunk_putc (HTChunk * ch, char c);
|
||||
/*
|
||||
|
||||
APPEND A STRING TO A CHUNK
|
||||
|
||||
Add the string and increment the size of the chunk by the length of the string (without
|
||||
the trailing zero)
|
||||
|
||||
*/
|
||||
#define HTChunkPuts(ch, str) HTChunk_puts(ch, str)
|
||||
extern void HTChunk_puts (HTChunk * ch, const char *str);
|
||||
/*
|
||||
|
||||
APPEND A BLOCK TO A CHUNK
|
||||
|
||||
Add the block and increment the size of the chunk by the len
|
||||
|
||||
*/
|
||||
extern void HTChunk_putb (HTChunk * ch, const char *block, PRInt32 len);
|
||||
|
||||
/*
|
||||
|
||||
ZERO TERMINATE A CHUNK
|
||||
|
||||
As a chunk often is a dynamic string, it needs to be terminated by a zero in order to
|
||||
be used in C. However, _by default_ any chunk is _always_ zero terminated, so the only
|
||||
purpose of this function is to increment the size counter with one corresponding to the
|
||||
zero.
|
||||
|
||||
*/
|
||||
#define HTChunkTerminate(ch) HTChunk_terminate(ch)
|
||||
#define HTChunk_terminate(ch) HTChunk_putc((ch), '\0')
|
||||
/*
|
||||
|
||||
RETURN POINTER TO DATA
|
||||
|
||||
This define converts a chunk to a normal char pointer so that it can be parsed to any
|
||||
ANSI C string function.
|
||||
|
||||
*/
|
||||
#define HTChunkData(me) ((me) ? (me)->data : NULL)
|
||||
#define HTChunk_data(me) ((me) ? (me)->data : NULL)
|
||||
/*
|
||||
|
||||
CSTRING CONVERSIONS
|
||||
|
||||
A Chunk may be build from an allocated string. The chunk assumes control of the passes
|
||||
string, elminating the need for additional allocations and string copies.
|
||||
Once a string is built, the chunk may be destroyed and the string kept around.
|
||||
|
||||
*/
|
||||
extern HTChunk * HTChunk_fromCString (char * str, PRInt32 grow);
|
||||
extern char * HTChunk_toCString (HTChunk * ch);
|
||||
/*
|
||||
|
||||
RETURN CURRENT SIZE
|
||||
|
||||
Returns the current size of the chunk
|
||||
|
||||
*/
|
||||
#define HTChunkSize(me) ((me) ? (me)->size : -1)
|
||||
#define HTChunk_size(me) ((me) ? (me)->size : -1)
|
||||
/*
|
||||
|
||||
*/
|
||||
#endif
|
||||
/*
|
||||
|
||||
|
||||
___________________________________
|
||||
|
||||
@(#) $Id: htchunk.h,v 1.2 1999-05-07 05:26:11 neeti%netscape.com Exp $
|
||||
|
||||
*/
|
||||
@ -1,211 +0,0 @@
|
||||
|
||||
/* W3 Copyright statement
|
||||
Copyright 1995 by: Massachusetts Institute of Technology (MIT), INRIA</H2>
|
||||
|
||||
This W3C software is being provided by the copyright holders under the
|
||||
following license. By obtaining, using and/or copying this software,
|
||||
you agree that you have read, understood, and will comply with the
|
||||
following terms and conditions:
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee or royalty is hereby
|
||||
granted, provided that the full text of this NOTICE appears on
|
||||
<EM>ALL</EM> copies of the software and documentation or portions
|
||||
thereof, including modifications, that you make.
|
||||
|
||||
<B>THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
|
||||
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE,
|
||||
BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
|
||||
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
|
||||
THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY
|
||||
THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
||||
COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE
|
||||
OR DOCUMENTATION.
|
||||
|
||||
The name and trademarks of copyright holders may NOT be used
|
||||
in advertising or publicity pertaining to the software without
|
||||
specific, written prior permission. Title to copyright in this
|
||||
software and any associated documentation will at all times remain
|
||||
with copyright holders.
|
||||
*/
|
||||
/* HTList.c
|
||||
** MANAGEMENT OF LINKED LISTS
|
||||
**
|
||||
** (c) COPYRIGHT MIT 1995.
|
||||
** Please first read the full copyright statement in the file COPYRIGH.
|
||||
** @(#) $Id: htlist.c,v 1.2 1999-05-07 05:26:11 neeti%netscape.com Exp $
|
||||
**
|
||||
** A list is represented as a sequence of linked nodes of type HTList.
|
||||
** The first node is a header which contains no object.
|
||||
** New nodes are inserted between the header and the rest of the list.
|
||||
*/
|
||||
|
||||
/* Library include files */
|
||||
/* #include "sysdep.h" jhines -- 7/9/97 */
|
||||
#include "htutils.h"
|
||||
#include "htlist.h"
|
||||
|
||||
PUBLIC HTList * HTList_new (void)
|
||||
{
|
||||
HTList *newList;
|
||||
if ((newList = (HTList *) HT_CALLOC(1, sizeof (HTList))) == NULL)
|
||||
HT_OUTOFMEM("HTList_new");
|
||||
newList->object = NULL;
|
||||
newList->next = NULL;
|
||||
return newList;
|
||||
}
|
||||
|
||||
PUBLIC PRBool HTList_delete (HTList * me)
|
||||
{
|
||||
if (me) {
|
||||
HTList *current;
|
||||
while ((current = me) != NULL) {
|
||||
me = me->next;
|
||||
HT_FREE(current);
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
PUBLIC PRBool HTList_addObject (HTList * me, void * newObject)
|
||||
{
|
||||
if (me) {
|
||||
HTList *newNode;
|
||||
if ((newNode = (HTList *) HT_CALLOC(1, sizeof(HTList))) == NULL)
|
||||
HT_OUTOFMEM("HTList_addObject");
|
||||
newNode->object = newObject;
|
||||
newNode->next = me->next;
|
||||
me->next = newNode;
|
||||
return YES;
|
||||
} else {
|
||||
if (WWWTRACE)
|
||||
HTTrace(
|
||||
"HTList...... Can not add object %p to nonexisting list\n",
|
||||
newObject);
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
PUBLIC PRBool HTList_appendObject (HTList * me, void * newObject)
|
||||
{
|
||||
if (me) {
|
||||
while (me->next) me = me->next;
|
||||
return HTList_addObject(me, newObject);
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
PUBLIC PRBool HTList_removeObject (HTList * me, void * oldObject)
|
||||
{
|
||||
if (me) {
|
||||
HTList *previous;
|
||||
while (me->next) {
|
||||
previous = me;
|
||||
me = me->next;
|
||||
if (me->object == oldObject) {
|
||||
previous->next = me->next;
|
||||
HT_FREE(me);
|
||||
return YES; /* Success */
|
||||
}
|
||||
}
|
||||
}
|
||||
return NO; /* object not found or NULL list */
|
||||
}
|
||||
|
||||
PUBLIC void * HTList_removeLastObject (HTList * me)
|
||||
{
|
||||
if (me && me->next) {
|
||||
HTList *lastNode = me->next;
|
||||
void * lastObject = lastNode->object;
|
||||
me->next = lastNode->next;
|
||||
HT_FREE(lastNode);
|
||||
return lastObject;
|
||||
} else /* Empty list */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PUBLIC void * HTList_removeFirstObject (HTList * me)
|
||||
{
|
||||
if (me && me->next) {
|
||||
HTList * prevNode;
|
||||
void *firstObject;
|
||||
while (me->next) {
|
||||
prevNode = me;
|
||||
me = me->next;
|
||||
}
|
||||
firstObject = me->object;
|
||||
prevNode->next = NULL;
|
||||
HT_FREE(me);
|
||||
return firstObject;
|
||||
} else /* Empty list */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PUBLIC void * HTList_firstObject (HTList * me)
|
||||
{
|
||||
if (me && me->next) {
|
||||
HTList * prevNode;
|
||||
while (me->next) {
|
||||
prevNode = me;
|
||||
me = me->next;
|
||||
}
|
||||
return me->object;
|
||||
} else /* Empty list */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PUBLIC PRInt32 HTList_count (HTList * me)
|
||||
{
|
||||
PRInt32 count = 0;
|
||||
if (me)
|
||||
while ((me = me->next) != NULL)
|
||||
count++;
|
||||
return count;
|
||||
}
|
||||
|
||||
PUBLIC PRInt32 HTList_indexOf (HTList * me, void * object)
|
||||
{
|
||||
if (me) {
|
||||
PRInt32 position = 0;
|
||||
while ((me = me->next) != NULL) {
|
||||
if (me->object == object)
|
||||
return position;
|
||||
position++;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
PUBLIC void * HTList_objectAt (HTList * me, PRInt32 position)
|
||||
{
|
||||
if (position < 0)
|
||||
return NULL;
|
||||
if (me) {
|
||||
while ((me = me->next) != NULL) {
|
||||
if (position == 0)
|
||||
return me->object;
|
||||
position--;
|
||||
}
|
||||
}
|
||||
return NULL; /* Reached the end of the list */
|
||||
}
|
||||
|
||||
PRIVATE void * HTList_removeObjectAt (HTList * me, PRInt32 position)
|
||||
{
|
||||
if (position < 0)
|
||||
return NULL;
|
||||
if (me) {
|
||||
HTList * prevNode;
|
||||
prevNode = me;
|
||||
while ((me = me->next) != NULL) {
|
||||
if (position == 0) {
|
||||
prevNode->next = me->next;
|
||||
return me->object;
|
||||
}
|
||||
prevNode = me;
|
||||
position--;
|
||||
}
|
||||
}
|
||||
return NULL; /* Reached the end of the list */
|
||||
}
|
||||
@ -1,163 +0,0 @@
|
||||
|
||||
/* W3 Copyright statement
|
||||
Copyright 1995 by: Massachusetts Institute of Technology (MIT), INRIA</H2>
|
||||
|
||||
This W3C software is being provided by the copyright holders under the
|
||||
following license. By obtaining, using and/or copying this software,
|
||||
you agree that you have read, understood, and will comply with the
|
||||
following terms and conditions:
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee or royalty is hereby
|
||||
granted, provided that the full text of this NOTICE appears on
|
||||
<EM>ALL</EM> copies of the software and documentation or portions
|
||||
thereof, including modifications, that you make.
|
||||
|
||||
<B>THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
|
||||
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE,
|
||||
BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
|
||||
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
|
||||
THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY
|
||||
THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
||||
COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE
|
||||
OR DOCUMENTATION.
|
||||
|
||||
The name and trademarks of copyright holders may NOT be used
|
||||
in advertising or publicity pertaining to the software without
|
||||
specific, written prior permission. Title to copyright in this
|
||||
software and any associated documentation will at all times remain
|
||||
with copyright holders.
|
||||
*/
|
||||
/* W3C Reference Library libwww List Class
|
||||
THE LIST CLASS
|
||||
|
||||
*/
|
||||
/*
|
||||
** (c) COPYRIGHT MIT 1995.
|
||||
** Please first read the full copyright statement in the file COPYRIGH.
|
||||
*/
|
||||
/*
|
||||
|
||||
The list class defines a generic container for storing collections of things in order.
|
||||
In principle it could be implemented in many ways, but in practice knowing that it is a
|
||||
linked list is important for speed.
|
||||
|
||||
This module is implemented by HTList.c, and it is a part of the W3C Reference Library.
|
||||
|
||||
*/
|
||||
#ifndef HTLIST_H
|
||||
#define HTLIST_H
|
||||
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
|
||||
#ifndef BOOL
|
||||
#define BOOL PRBool
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct _HTList HTList;
|
||||
|
||||
struct _HTList {
|
||||
void * object;
|
||||
HTList * next;
|
||||
};
|
||||
/*
|
||||
|
||||
CREATION AND DELETION METHODS
|
||||
|
||||
These two functions create and deletes a list
|
||||
|
||||
*/
|
||||
extern HTList * HTList_new (void);
|
||||
extern PRBool HTList_delete (HTList *me);
|
||||
/*
|
||||
|
||||
ADD AN ELEMENT TO LIST
|
||||
|
||||
A new list element is added to the beginning of the list so that it is first element
|
||||
just after the head element.
|
||||
|
||||
*/
|
||||
extern PRBool HTList_addObject (HTList *me, void *newObject);
|
||||
/*
|
||||
|
||||
You can also append an element to the end of the list (the end is the first entered
|
||||
object) by using the following function:
|
||||
|
||||
*/
|
||||
extern PRBool HTList_appendObject (HTList * me, void * newObject);
|
||||
/*
|
||||
|
||||
REMOVE LIST ELEMENTS
|
||||
|
||||
You can delete elements in a list usin the following methods
|
||||
|
||||
*/
|
||||
extern PRBool HTList_removeObject (HTList *me, void *oldObject);
|
||||
extern void * HTList_removeLastObject (HTList *me);
|
||||
extern void * HTList_removeFirstObject (HTList *me);
|
||||
/*
|
||||
|
||||
SIZE OF A LIST
|
||||
|
||||
Two small function to ask for the size
|
||||
|
||||
*/
|
||||
#define HTList_isEmpty(me) (me ? me->next == NULL : YES)
|
||||
extern PRInt32 HTList_count (HTList *me);
|
||||
/*
|
||||
|
||||
REFERENCE LIST ELEMENTS BY INDEX
|
||||
|
||||
In some situations is is required to use an index in order to refer to a list element.
|
||||
This is for example the case if an element can be registered multiple times.
|
||||
|
||||
*/
|
||||
extern PRInt32 HTList_indexOf (HTList *me, void *object);
|
||||
extern void * HTList_objectAt (HTList *me, PRInt32 position);
|
||||
/*
|
||||
|
||||
FIND LIST ELEMENTS
|
||||
|
||||
This method returns the _last_ element to the list or NULL if list is empty
|
||||
|
||||
*/
|
||||
#define HTList_lastObject(me) \
|
||||
((me) && (me)->next ? (me)->next->object : NULL)
|
||||
/*
|
||||
|
||||
This method returns the _first_ element to the list or NULL if list is empty
|
||||
|
||||
*/
|
||||
extern void * HTList_firstObject (HTList * me);
|
||||
/*
|
||||
|
||||
TRAVERSE LIST
|
||||
|
||||
Fast macro to traverse the list. Call it first with copy of list header: it returns the
|
||||
first object and increments the passed list pointer. Call it with the same variable
|
||||
until it returns NULL.
|
||||
|
||||
*/
|
||||
#define HTList_nextObject(me) \
|
||||
((me) && ((me) = (me)->next) ? (me)->object : NULL)
|
||||
/*
|
||||
|
||||
FREE LIST
|
||||
|
||||
*/
|
||||
#define HTList_free(x) HT_FREE(x)
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
#endif /* HTLIST_H */
|
||||
/*
|
||||
|
||||
|
||||
___________________________________
|
||||
|
||||
@(#) $Id: htlist.h,v 1.2 1999-05-07 05:26:11 neeti%netscape.com Exp $
|
||||
|
||||
*/
|
||||
@ -1,186 +0,0 @@
|
||||
|
||||
/* W3 Copyright statement
|
||||
Copyright 1995 by: Massachusetts Institute of Technology (MIT), INRIA</H2>
|
||||
|
||||
This W3C software is being provided by the copyright holders under the
|
||||
following license. By obtaining, using and/or copying this software,
|
||||
you agree that you have read, understood, and will comply with the
|
||||
following terms and conditions:
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee or royalty is hereby
|
||||
granted, provided that the full text of this NOTICE appears on
|
||||
<EM>ALL</EM> copies of the software and documentation or portions
|
||||
thereof, including modifications, that you make.
|
||||
|
||||
<B>THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
|
||||
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE,
|
||||
BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
|
||||
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
|
||||
THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY
|
||||
THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
||||
COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE
|
||||
OR DOCUMENTATION.
|
||||
|
||||
The name and trademarks of copyright holders may NOT be used
|
||||
in advertising or publicity pertaining to the software without
|
||||
specific, written prior permission. Title to copyright in this
|
||||
software and any associated documentation will at all times remain
|
||||
with copyright holders.
|
||||
*/
|
||||
/* W3C Reference Library libwww Dynamic Memory Handlers
|
||||
DYNAMIC MEMORY HANDLERS
|
||||
|
||||
*/
|
||||
/*
|
||||
** (c) COPYRIGHT MIT 1995.
|
||||
** Please first read the full copyright statement in the file COPYRIGH.
|
||||
*/
|
||||
/*
|
||||
|
||||
This module defines any memory handler to be used by libwww for allocating and
|
||||
de-allocating dynamic memory. As dynamic memory may be a scarce resource, it is
|
||||
required that an application can handle memory exhaustion gracefully. This module
|
||||
provides an interface that covers the following situations:
|
||||
|
||||
Handling of allocation, reallocation and de-allocation of dynamic memory
|
||||
|
||||
Recovering from temporary lack of available memory
|
||||
|
||||
Panic handling in case a new allocation fails
|
||||
|
||||
_Note_: The Library _core_ provides a default set of memory handlers for allocating and
|
||||
de-allocating dynamic memory. In order to maintain a reasonable performance, they are
|
||||
not registered dynamically but assigned using _C style macros_. Hence, it is not
|
||||
possible to swap memory handler at run time but this was considered to be a reasonable
|
||||
trade-off.
|
||||
|
||||
This module is implemented by HTMemory.c, and it is a part of the W3C Reference
|
||||
Library.
|
||||
|
||||
*/
|
||||
#ifndef HTMEMORY_H
|
||||
#define HTMEMORY_H
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
|
||||
ALLOCATION, REALLOCATION AND DE-ALLOCATION
|
||||
|
||||
The Library provides a default set of methods for handling dynamic memory. They are
|
||||
very basic and essentially identical to the C style malloc, calloc, realloc, and free:
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#ifndef BOOL
|
||||
#define BOOL PRBool
|
||||
#endif
|
||||
|
||||
|
||||
extern void* HTMemory_malloc(size_t size);
|
||||
extern void* HTMemory_calloc(size_t count, size_t size);
|
||||
extern void* HTMemory_realloc(void * ptr, size_t size);
|
||||
extern void HTMemory_free(void* ptr);
|
||||
|
||||
/*
|
||||
|
||||
Memory Macros
|
||||
|
||||
The methods above are not referred directly in the Library. Instead we use a set of C
|
||||
style macros. If you don't wany any memory management beyond normal malloc and alloc
|
||||
then you can just use that instead of the HTMemory_* function. You can of course also
|
||||
provide your own methods as well.
|
||||
|
||||
*/
|
||||
#ifndef __FILE__
|
||||
#define __FILE__ ""
|
||||
#endif
|
||||
|
||||
#ifndef __LINE__
|
||||
#define __LINE__ 0L
|
||||
#endif
|
||||
|
||||
#define HT_MALLOC(size) HTMemory_malloc((size))
|
||||
#define HT_CALLOC(count, size) HTMemory_calloc((count), (size))
|
||||
#define HT_REALLOC(ptr, size) HTMemory_realloc((ptr), (size))
|
||||
#define HT_FREE(pointer) {HTMemory_free((pointer));((pointer))=NULL;}
|
||||
/*
|
||||
|
||||
MEMORY FREER FUNCTIONS
|
||||
|
||||
The dynamic memory freer functions are typically functions that are capable of freeing
|
||||
large chunks of memory. In case a new allocation fails, the allocation method looks for
|
||||
any registered freer functions to call. There can be multiple freer functions and after
|
||||
each call, the allocation method tries again to allocate the desired amount of dynamic
|
||||
memory. The freer functions are called in reverseorder meaning that the lastone
|
||||
registered gets called first. That way, it is easy to add temporary freer functions
|
||||
which then are guaranteed to be called first if a methods fails.
|
||||
|
||||
Add a Freer Function
|
||||
|
||||
You can add a freer function by using the following method. The Library may itself
|
||||
register a set of free functions during initialization. If the application does not
|
||||
register any freer functions then the Library looks how it can free internal memory.
|
||||
The freer function is passed the total number of _bytes_ requested by the allocation.
|
||||
|
||||
*/
|
||||
typedef void (*HTMemoryCallback()); /* jhines -- 7/9/97 */
|
||||
/* typedef void HTMemoryCallback(size_t size); */
|
||||
|
||||
extern PRBool HTMemoryCall_add (HTMemoryCallback * cbf);
|
||||
/*
|
||||
|
||||
Delete a Freer Function
|
||||
|
||||
Freer functions can be deleted at any time in which case they are not called anymore.
|
||||
|
||||
*/
|
||||
extern PRBool HTMemoryCall_delete (HTMemoryCallback * cbf);
|
||||
extern PRBool HTMemoryCall_deleteAll (void);
|
||||
/*
|
||||
|
||||
PANIC HANDLING
|
||||
|
||||
If the freer functions are not capable of de-allocation enough memory then the
|
||||
application must have an organized way of closing down. This is done using the panic
|
||||
handler. In the libwww, each allocation is tested and HT_OUTOFMEMis called if a NULLwas
|
||||
returned. HT_OUTOFMEMis a macro which by default calls HTMemory_outofmem()but of course
|
||||
can point to any method. The default handler calls an exit function defined by the
|
||||
application in a call to HTMemory_setExit(). If the application has _not_ defined an
|
||||
exit function, HTMemory_outofmem()prints an error message and calls exit(1).
|
||||
|
||||
*/
|
||||
typedef void HTMemory_exitCallback(char *name, char *file, unsigned long line);
|
||||
|
||||
extern void HTMemory_setExit(HTMemory_exitCallback * pExit);
|
||||
extern HTMemory_exitCallback * HTMemory_exit(void);
|
||||
/*
|
||||
|
||||
Call the Exit Handler
|
||||
|
||||
If an allocation fails then this function is called. If the application has registered
|
||||
its own panic handler then this is called directly from this function. Otherwise, the
|
||||
default behavior is to write a small message to stderr and then exit.
|
||||
|
||||
*/
|
||||
#define outofmem(file, name) HT_OUTOFMEM(name)
|
||||
#define HT_OUTOFMEM(name) HTMemory_outofmem((name), __FILE__, __LINE__)
|
||||
|
||||
extern void HTMemory_outofmem(char * name, char * file, unsigned long line);
|
||||
/*
|
||||
|
||||
*/
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
#endif /* HTMEMORY_H */
|
||||
/*
|
||||
|
||||
|
||||
___________________________________
|
||||
|
||||
@(#) $Id: htmemory.h,v 1.2 1999-05-07 05:26:11 neeti%netscape.com Exp $
|
||||
|
||||
*/
|
||||
@ -1,168 +0,0 @@
|
||||
|
||||
/* W3 Copyright statement
|
||||
Copyright 1995 by: Massachusetts Institute of Technology (MIT), INRIA</H2>
|
||||
|
||||
This W3C software is being provided by the copyright holders under the
|
||||
following license. By obtaining, using and/or copying this software,
|
||||
you agree that you have read, understood, and will comply with the
|
||||
following terms and conditions:
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee or royalty is hereby
|
||||
granted, provided that the full text of this NOTICE appears on
|
||||
<EM>ALL</EM> copies of the software and documentation or portions
|
||||
thereof, including modifications, that you make.
|
||||
|
||||
<B>THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
|
||||
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE,
|
||||
BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
|
||||
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
|
||||
THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY
|
||||
THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
||||
COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE
|
||||
OR DOCUMENTATION.
|
||||
|
||||
The name and trademarks of copyright holders may NOT be used
|
||||
in advertising or publicity pertaining to the software without
|
||||
specific, written prior permission. Title to copyright in this
|
||||
software and any associated documentation will at all times remain
|
||||
with copyright holders.
|
||||
*/
|
||||
/* HTString.c
|
||||
** DYNAMIC STRING UTILITIES
|
||||
**
|
||||
** (c) COPYRIGHT MIT 1995.
|
||||
** Please first read the full copyright statement in the file COPYRIGH.
|
||||
** @(#) $Id: htstring.c,v 1.2 1999-05-07 05:26:12 neeti%netscape.com Exp $
|
||||
**
|
||||
** Original version came with listserv implementation.
|
||||
** Version TBL Oct 91 replaces one which modified the strings.
|
||||
** 02-Dec-91 (JFG) Added stralloccopy and stralloccat
|
||||
** 23 Jan 92 (TBL) Changed strallocc* to 8 char HTSAC* for VM and suchlike
|
||||
** 6 Oct 92 (TBL) Moved WWW_TraceFlag in here to be in library
|
||||
** 9 Oct 95 (KR) fixed problem with double quotes in HTNextField
|
||||
*/
|
||||
|
||||
/* Library include files */
|
||||
#include <stdarg.h>
|
||||
#include "plstr.h"
|
||||
/* #include "sysdep.h" jhines -- 7/9/97 */
|
||||
#include "htutils.h"
|
||||
#include "htstring.h" /* Implemented here */
|
||||
|
||||
#if WWWTRACE_MODE == WWWTRACE_FILE
|
||||
PUBLIC FILE *WWWTrace = NULL;
|
||||
#endif
|
||||
|
||||
#ifndef WWW_WIN_DLL
|
||||
PUBLIC PRInt32 WWW_TraceFlag = 0; /* Global trace flag for ALL W3 code */
|
||||
#endif
|
||||
|
||||
|
||||
/* Allocate a new copy of a string, and returns it
|
||||
*/
|
||||
PUBLIC char * HTSACopy (char ** dest, const char * src)
|
||||
{
|
||||
if (*dest) HT_FREE(*dest);
|
||||
if (! src)
|
||||
*dest = NULL;
|
||||
else {
|
||||
if ((*dest = (char *) HT_MALLOC(PL_strlen(src) + 1)) == NULL)
|
||||
HT_OUTOFMEM("HTSACopy");
|
||||
PL_strcpy (*dest, src);
|
||||
}
|
||||
return *dest;
|
||||
}
|
||||
|
||||
/* String Allocate and Concatenate
|
||||
*/
|
||||
PUBLIC char * HTSACat (char ** dest, const char * src)
|
||||
{
|
||||
if (src && *src) {
|
||||
if (*dest) {
|
||||
PRInt32 length = PL_strlen (*dest);
|
||||
if ((*dest = (char *) HT_REALLOC(*dest, length + PL_strlen(src) + 1)) == NULL)
|
||||
HT_OUTOFMEM("HTSACat");
|
||||
PL_strcpy (*dest + length, src);
|
||||
} else {
|
||||
if ((*dest = (char *) HT_MALLOC(PL_strlen(src) + 1)) == NULL)
|
||||
HT_OUTOFMEM("HTSACat");
|
||||
PL_strcpy (*dest, src);
|
||||
}
|
||||
}
|
||||
return *dest;
|
||||
}
|
||||
|
||||
|
||||
/* String Matching
|
||||
** ---------------
|
||||
** String comparison function for file names with one wildcard * in the
|
||||
** template. Arguments are:
|
||||
**
|
||||
** tmpl is a template string to match the name against.
|
||||
** agaist, may contain a single wildcard character * which
|
||||
** matches zero or more arbitrary characters.
|
||||
** name is the name to be matched agaist the template.
|
||||
**
|
||||
** return: - Empty string if perfect match
|
||||
** - pointer to part matched by wildcard if any
|
||||
** - NULL if no match
|
||||
*/
|
||||
PUBLIC char * HTStrMatch (const char * tmpl, const char * name)
|
||||
{
|
||||
while (*tmpl && *name && *tmpl==*name) tmpl++, name++;
|
||||
return ((!*tmpl && !*name) || *tmpl=='*') ? (char *) name : (char *) NULL;
|
||||
}
|
||||
|
||||
PUBLIC char * HTStrCaseMatch (const char * tmpl, const char * name)
|
||||
{
|
||||
while (*tmpl && *name && TOUPPER(*tmpl)==TOUPPER(*name)) tmpl++, name++;
|
||||
return ((!*tmpl && !*name) || *tmpl=='*') ? (char *) name : (char *) NULL;
|
||||
}
|
||||
|
||||
/* Strip white space off a string
|
||||
** ------------------------------
|
||||
** Return value points to first non-white character, or to 0 if none.
|
||||
** All trailing white space is OVERWRITTEN with zero.
|
||||
*/
|
||||
PUBLIC char * HTStrip (char * s)
|
||||
{
|
||||
if (s) {
|
||||
char * p=s;
|
||||
for(p=s;*p;p++); /* Find end of string */
|
||||
for(p--;p>=s;p--) {
|
||||
if (WHITE(*p))
|
||||
*p=0; /* Zap trailing blanks */
|
||||
else
|
||||
break;
|
||||
}
|
||||
while (WHITE(*s)) s++; /* Strip leading blanks */
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
PRIVATE HTTraceCallback * PHTTraceCallback;
|
||||
|
||||
PUBLIC void HTTrace_setCallback(HTTraceCallback * pCall)
|
||||
{
|
||||
PHTTraceCallback = pCall;
|
||||
}
|
||||
|
||||
PUBLIC HTTraceCallback * HTTrace_getCallback(void)
|
||||
{
|
||||
return PHTTraceCallback;
|
||||
}
|
||||
|
||||
PUBLIC PRInt32 HTTrace(const char * fmt, ...)
|
||||
{
|
||||
va_list pArgs;
|
||||
va_start(pArgs, fmt);
|
||||
if (PHTTraceCallback)
|
||||
(*PHTTraceCallback)(fmt, pArgs);
|
||||
#ifdef WWW_WIN_WINDOWS
|
||||
return (0);
|
||||
#else
|
||||
return (vfprintf(stderr, fmt, pArgs));
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1,131 +0,0 @@
|
||||
|
||||
/* W3 Copyright statement
|
||||
Copyright 1995 by: Massachusetts Institute of Technology (MIT), INRIA</H2>
|
||||
|
||||
This W3C software is being provided by the copyright holders under the
|
||||
following license. By obtaining, using and/or copying this software,
|
||||
you agree that you have read, understood, and will comply with the
|
||||
following terms and conditions:
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee or royalty is hereby
|
||||
granted, provided that the full text of this NOTICE appears on
|
||||
<EM>ALL</EM> copies of the software and documentation or portions
|
||||
thereof, including modifications, that you make.
|
||||
|
||||
<B>THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
|
||||
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE,
|
||||
BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
|
||||
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
|
||||
THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY
|
||||
THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
||||
COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE
|
||||
OR DOCUMENTATION.
|
||||
|
||||
The name and trademarks of copyright holders may NOT be used
|
||||
in advertising or publicity pertaining to the software without
|
||||
specific, written prior permission. Title to copyright in this
|
||||
software and any associated documentation will at all times remain
|
||||
with copyright holders.
|
||||
*/
|
||||
/* W3C Reference Library libwww Generic String Management
|
||||
GENERIC STRING MANAGEMENT
|
||||
|
||||
*/
|
||||
/*
|
||||
** (c) COPYRIGHT MIT 1995.
|
||||
** Please first read the full copyright statement in the file COPYRIGH.
|
||||
*/
|
||||
/*
|
||||
|
||||
These functions provide functionality for case-independent string comparison and
|
||||
allocations with copies etc.
|
||||
|
||||
This module is implemented by HTString.c, and it is a part of the W3C Reference
|
||||
Library.
|
||||
|
||||
*/
|
||||
#ifndef HTSTRING_H
|
||||
#define HTSTRING_H
|
||||
|
||||
#include "xp_core.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
|
||||
|
||||
DYNAMIC STRING MANIPULATION
|
||||
|
||||
These two functions are dynamic versions of strcpyand strcat. They use mallocfor
|
||||
allocating space for the string. If StrAllocCopyis called with a non-NULL dest, then
|
||||
this is freed before the new value is assigned so that only the laststring created has
|
||||
to be freed by the user. If StrAllocCatis called with a NULL pointer as destination
|
||||
then it is equivalent to StrAllocCopy.
|
||||
|
||||
*/
|
||||
#define StrAllocCopy(dest, src) HTSACopy (&(dest), src)
|
||||
#define StrAllocCat(dest, src) HTSACat (&(dest), src)
|
||||
|
||||
extern char * HTSACopy (char **dest, const char *src);
|
||||
extern char * HTSACat (char **dest, const char *src);
|
||||
/*
|
||||
|
||||
CASE-INSENSITIVE STRING COMPARISON
|
||||
|
||||
The usual routines (comp instead of cmp) had some problem.
|
||||
|
||||
*/
|
||||
/* extern PRInt32 strcasecomp (const char *a, const char *b); */
|
||||
/* extern PRInt32 strncasecomp (const char *a, const char *b, PRInt32 n); */
|
||||
/*
|
||||
|
||||
STRING COMPARISON WITH WILD CARD MATCH
|
||||
|
||||
String comparison function for file names with one wildcard * in the template.
|
||||
Arguments are:
|
||||
|
||||
tmpl is a template string to match the name against. agaist, may
|
||||
contain a single wildcard character * which matches zero or more
|
||||
arbitrary characters.
|
||||
|
||||
name is the name to be matched agaist the template.
|
||||
|
||||
Returns empty string ("") if perfect match, pointer to part matched by wildcard if any,
|
||||
or NULL if no match. This is basically the same as YES if match, else NO.
|
||||
|
||||
*/
|
||||
extern char * HTStrMatch (const char * tmpl, const char * name);
|
||||
extern char * HTStrCaseMatch (const char * tmpl, const char * name);
|
||||
/*
|
||||
|
||||
CASE-INSENSITIVE STRSTR
|
||||
|
||||
This works like strstr()but is not case-sensitive.
|
||||
|
||||
*/
|
||||
/* extern char * strcasestr (char * s1, char * s2); */
|
||||
/*
|
||||
|
||||
STRIP WHITE SPACE OFF A STRING
|
||||
|
||||
Return value points to first non-white character, or to '/0' if none. All trailing
|
||||
white space is OVERWRITTEN with zero.
|
||||
|
||||
*/
|
||||
extern char * HTStrip (char * s);
|
||||
/*
|
||||
|
||||
*/
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
#endif
|
||||
/*
|
||||
|
||||
|
||||
___________________________________
|
||||
|
||||
@(#) $Id: htstring.h,v 1.2 1999-05-07 05:26:12 neeti%netscape.com Exp $
|
||||
|
||||
*/
|
||||
@ -1,265 +0,0 @@
|
||||
|
||||
/* W3 Copyright statement
|
||||
Copyright 1995 by: Massachusetts Institute of Technology (MIT), INRIA</H2>
|
||||
|
||||
This W3C software is being provided by the copyright holders under the
|
||||
following license. By obtaining, using and/or copying this software,
|
||||
you agree that you have read, understood, and will comply with the
|
||||
following terms and conditions:
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee or royalty is hereby
|
||||
granted, provided that the full text of this NOTICE appears on
|
||||
<EM>ALL</EM> copies of the software and documentation or portions
|
||||
thereof, including modifications, that you make.
|
||||
|
||||
<B>THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
|
||||
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE,
|
||||
BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
|
||||
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
|
||||
THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY
|
||||
THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
||||
COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE
|
||||
OR DOCUMENTATION.
|
||||
|
||||
The name and trademarks of copyright holders may NOT be used
|
||||
in advertising or publicity pertaining to the software without
|
||||
specific, written prior permission. Title to copyright in this
|
||||
software and any associated documentation will at all times remain
|
||||
with copyright holders.
|
||||
*/
|
||||
/* W3C Reference Library libwww General Purpose Macros
|
||||
GENERAL PURPOSE MACROS
|
||||
|
||||
*/
|
||||
/*
|
||||
** (c) COPYRIGHT MIT 1995.
|
||||
** Please first read the full copyright statement in the file COPYRIGH.
|
||||
*/
|
||||
/*
|
||||
|
||||
This module is a part of the W3C Reference Library. See also the system dependent file
|
||||
sysdep module for system specific information.
|
||||
|
||||
*/
|
||||
#ifndef HTUTILS_H
|
||||
#define HTUTILS_H
|
||||
|
||||
#include "xp_core.h"
|
||||
/*
|
||||
|
||||
DEBUG MESSAGE CONTROL
|
||||
|
||||
This is the global flag for setting the WWWTRACEoptions. The verbose mode is no longer
|
||||
a simple boolean but a bit field so that it is possible to see parts of the output
|
||||
messages.
|
||||
|
||||
*/
|
||||
#ifndef DEBUG
|
||||
#define DEBUG /* No one ever turns this off as trace is too important */
|
||||
#endif
|
||||
/*
|
||||
|
||||
Definition of the Global Trace Flag
|
||||
|
||||
The global trace flag variable is available everywhere.
|
||||
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
#ifdef WWW_WIN_DLL
|
||||
extern PRInt32 * WWW_TraceFlag; /* In DLLs, we need the indirection */
|
||||
#define WWWTRACE (*WWW_TraceFlag)
|
||||
#else
|
||||
extern PRInt32 WWW_TraceFlag; /* Global flag for all W3 trace */
|
||||
#define WWWTRACE (WWW_TraceFlag)
|
||||
#endif /* WWW_WIN_DLL */
|
||||
#else
|
||||
#define WWWTRACE 0
|
||||
#endif /* DEBUG */
|
||||
/*
|
||||
|
||||
The WWWTRACEdefine outputs messages if verbose mode is active according to the
|
||||
following rules:
|
||||
|
||||
*/
|
||||
typedef enum _HTTraceFlags {
|
||||
SHOW_UTIL_TRACE = 0x1, /* 1 */
|
||||
SHOW_APP_TRACE = 0x2, /* 10 */
|
||||
SHOW_CACHE_TRACE = 0x4, /* 100 */
|
||||
SHOW_SGML_TRACE = 0x8, /* 1000 */
|
||||
SHOW_BIND_TRACE = 0x10, /* 1.0000 */
|
||||
SHOW_THREAD_TRACE = 0x20, /* 10.0000 */
|
||||
SHOW_STREAM_TRACE = 0x40, /* 100.0000 */
|
||||
SHOW_PROTOCOL_TRACE = 0x80, /* 1000.0000 */
|
||||
SHOW_MEM_TRACE = 0x100, /* 1.0000.0000 */
|
||||
SHOW_URI_TRACE = 0x200, /* 10.0000.0000 */
|
||||
SHOW_AUTH_TRACE = 0x400, /* 100.0000.0000 */
|
||||
SHOW_ANCHOR_TRACE = 0x800, /* 1000.0000.0000 */
|
||||
SHOW_PICS_TRACE = 0x1000, /* 1.0000.0000.0000 */
|
||||
SHOW_CORE_TRACE = 0x2000, /* 10.0000.0000.0000 */
|
||||
SHOW_ALL_TRACE = 0x3FFF /* 11.1111.1111.1111 */
|
||||
} HTTraceFlags;
|
||||
/*
|
||||
|
||||
The flags are made so that they can serve as a group flag for correlated trace
|
||||
messages, e.g. showing messages for SGML and HTML at the same time.
|
||||
|
||||
*/
|
||||
#define UTIL_TRACE (WWWTRACE & SHOW_UTIL_TRACE)
|
||||
#define APP_TRACE (WWWTRACE & SHOW_APP_TRACE)
|
||||
#define CACHE_TRACE (WWWTRACE & SHOW_CACHE_TRACE)
|
||||
#define SGML_TRACE (WWWTRACE & SHOW_SGML_TRACE)
|
||||
#define BIND_TRACE (WWWTRACE & SHOW_BIND_TRACE)
|
||||
#define THD_TRACE (WWWTRACE & SHOW_THREAD_TRACE)
|
||||
#define STREAM_TRACE (WWWTRACE & SHOW_STREAM_TRACE)
|
||||
#define PROT_TRACE (WWWTRACE & SHOW_PROTOCOL_TRACE)
|
||||
#define MEM_TRACE (WWWTRACE & SHOW_MEM_TRACE)
|
||||
#define URI_TRACE (WWWTRACE & SHOW_URI_TRACE)
|
||||
#define AUTH_TRACE (WWWTRACE & SHOW_AUTH_TRACE)
|
||||
#define ANCH_TRACE (WWWTRACE & SHOW_ANCHOR_TRACE)
|
||||
#define PICS_TRACE (WWWTRACE & SHOW_PICS_TRACE)
|
||||
#define CORE_TRACE (WWWTRACE & SHOW_CORE_TRACE)
|
||||
/*
|
||||
|
||||
Destination for Trace Messages
|
||||
|
||||
You can send trace messages to various destinations depending on the type of your
|
||||
application. By default, on Unix the messages are sent to stderr using fprintf() and if
|
||||
we are on Windows and have a windows applications then register a HTTraceCallback
|
||||
function. This is done with HTTrace_setCallback. It tells HTTrace to call a
|
||||
HTTraceCallback. If your compiler has problems with va_list, then you may forget about
|
||||
registering the callback and instead macro HTTrace as follows: #define HTTrace
|
||||
MyAppSpecificTrace
|
||||
|
||||
*/
|
||||
typedef PRInt32 (*HTTraceCallback)(); /* jhines--7/9/97 */
|
||||
/* typedef PRInt32 HTTraceCallback(const char * fmt, va_list pArgs); */
|
||||
|
||||
extern void HTTrace_setCallback(HTTraceCallback * pCall);
|
||||
extern HTTraceCallback * HTTrace_getCallback(void);
|
||||
|
||||
extern PRInt32 HTTrace(const char * fmt, ...);
|
||||
/*
|
||||
|
||||
MACROS FOR FUNCTION DECLARATIONS
|
||||
|
||||
*/
|
||||
/* #define PUBLIC */ /* Accessible outside this module */
|
||||
/* #define PRIVATE static */ /* Accessible only within this module */
|
||||
/*
|
||||
|
||||
OFTEN USED INTERGER MACROS
|
||||
|
||||
Min and Max functions
|
||||
|
||||
*/
|
||||
#ifndef HTMIN
|
||||
#define HTMIN(a,b) ((a) <= (b) ? (a) : (b))
|
||||
#define HTMAX(a,b) ((a) >= (b) ? (a) : (b))
|
||||
#endif
|
||||
/*
|
||||
|
||||
Double abs function
|
||||
|
||||
*/
|
||||
#ifndef HTDABS
|
||||
#define HTDABS(a) ((a) < 0.0 ? (-(a)) : (a))
|
||||
#endif
|
||||
/*
|
||||
|
||||
RETURN CODES FOR PROTOCOL MODULES AND STREAMS
|
||||
|
||||
Theese are the codes returned from the protocol modules, and the stream modules.
|
||||
Success are (>=0) and failure are (<0)
|
||||
|
||||
*/
|
||||
#define HT_OK 0 /* Generic success */
|
||||
#define HT_ALL 1 /* Used by Net Manager */
|
||||
|
||||
#define HT_CONTINUE 29991 /* Continue an operation */
|
||||
#define HT_CLOSED 29992 /* The socket was closed */
|
||||
#define HT_PERSISTENT 29993 /* Wait for persistent connection */
|
||||
#define HT_IGNORE 29994 /* Ignore this in the Net manager */
|
||||
#define HT_NO_DATA 29995 /* OK but no data was loaded */
|
||||
#define HT_RELOAD 29996 /* If we must reload the document */
|
||||
#define HT_PERM_REDIRECT 29997 /* Redo the retrieve with a new URL */
|
||||
#define HT_TEMP_REDIRECT 29998 /* Redo the retrieve with a new URL */
|
||||
#define HT_LOADED 29999 /* Instead of a socket */
|
||||
|
||||
#define HT_ERROR -1 /* Generic failure */
|
||||
|
||||
#define HT_NO_ACCESS -10 /* Access not available */
|
||||
#define HT_FORBIDDEN -11 /* Access forbidden */
|
||||
#define HT_RETRY -13 /* If service isn't available */
|
||||
#define HT_NO_PROXY_ACCESS -14 /* No proxy access */
|
||||
|
||||
#define HT_INTERNAL -100 /* Weird -- should never happen. */
|
||||
|
||||
#define HT_WOULD_BLOCK -29997 /* If we are in a select */
|
||||
#define HT_INTERRUPTED -29998 /* Note the negative value! */
|
||||
#define HT_PAUSE -29999 /* If we want to pause a stream */
|
||||
/*
|
||||
|
||||
UPPER- AND LOWERCASE MACROS
|
||||
|
||||
The problem here is that toupper(x) is not defined officially unless isupper(x) is.
|
||||
These macros are CERTAINLY needed on #if defined(pyr) || define(mips) or BDSI
|
||||
platforms. For safefy, we make them mandatory.
|
||||
|
||||
*/
|
||||
/* #ifndef TOLOWER */
|
||||
/* #define TOLOWER(c) tolower(c) */
|
||||
/* #define TOUPPER(c) toupper(c) */
|
||||
#define TOUPPER(x) ((((PRUint32) (x)) > 0x7f) ? x : toupper(x))
|
||||
/* #endif */
|
||||
/*
|
||||
|
||||
MAX AND MIN VALUES FOR INTEGERS AND FLOATING POINT
|
||||
|
||||
*/
|
||||
#ifdef FLT_EPSILON /* The ANSI C way define */
|
||||
#define HT_EPSILON FLT_EPSILON
|
||||
#else
|
||||
#define HT_EPSILON 0.00000001
|
||||
#endif
|
||||
/*
|
||||
|
||||
WHITE CHARACTERS
|
||||
|
||||
Is character _c_ white space?
|
||||
|
||||
*/
|
||||
/* #define WHITE(c) isspace(c) */
|
||||
#define WHITE(c) isspace(c)
|
||||
/*
|
||||
|
||||
THE LOCAL EQUIVALENTS OF CR AND LF
|
||||
|
||||
We can check for these after net ascii text has been converted to the local
|
||||
representation. Similarly, we include them in strings to be sent as net ascii after
|
||||
translation.
|
||||
|
||||
*/
|
||||
/* #define LF FROMASCII('\012') */ /* ASCII line feed LOCAL EQUIVALENT */
|
||||
/* #define CR FROMASCII('\015') */ /* Will be converted to ^M for transmission */
|
||||
/*
|
||||
|
||||
LIBRARY DYNAMIC MEMORY MAGEMENT
|
||||
|
||||
The Library has it's own dynamic memory API which is declared in memory management
|
||||
module.
|
||||
|
||||
*/
|
||||
#include "htmemory.h"
|
||||
/*
|
||||
|
||||
*/
|
||||
#endif /* HT_UTILS.h */
|
||||
/*
|
||||
|
||||
|
||||
___________________________________
|
||||
|
||||
@(#) $Id: htutils.h,v 1.2 1999-05-07 05:26:12 neeti%netscape.com Exp $
|
||||
|
||||
*/
|
||||
@ -1,244 +0,0 @@
|
||||
|
||||
/* W3 Copyright statement
|
||||
Copyright 1995 by: Massachusetts Institute of Technology (MIT), INRIA</H2>
|
||||
|
||||
This W3C software is being provided by the copyright holders under the
|
||||
following license. By obtaining, using and/or copying this software,
|
||||
you agree that you have read, understood, and will comply with the
|
||||
following terms and conditions:
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee or royalty is hereby
|
||||
granted, provided that the full text of this NOTICE appears on
|
||||
<EM>ALL</EM> copies of the software and documentation or portions
|
||||
thereof, including modifications, that you make.
|
||||
|
||||
<B>THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
|
||||
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE,
|
||||
BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
|
||||
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
|
||||
THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY
|
||||
THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
||||
COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE
|
||||
OR DOCUMENTATION.
|
||||
|
||||
The name and trademarks of copyright holders may NOT be used
|
||||
in advertising or publicity pertaining to the software without
|
||||
specific, written prior permission. Title to copyright in this
|
||||
software and any associated documentation will at all times remain
|
||||
with copyright holders.
|
||||
*/
|
||||
/* #include "malloc.h" */
|
||||
#include "prmem.h"
|
||||
/* #include "sysdep.h" -- jhines 7/9/97 */
|
||||
#include "cslutils.h"
|
||||
#include "csll.h" /* to define states in stateChange */
|
||||
#include "csparse.h"
|
||||
|
||||
PRInt32 Total;
|
||||
|
||||
extern PRInt32 ParseDebug;
|
||||
|
||||
extern PRInt32 SEC_ERROR_NO_MEMORY;
|
||||
|
||||
|
||||
PRIVATE
|
||||
CSError_t spit(char* text, CSLabel_t * pCSMR, PRBool closed)
|
||||
{
|
||||
printf("%s %s\n", text, closed ? "closed" : "opened");
|
||||
return CSDoMore_more;
|
||||
}
|
||||
|
||||
LabelTargetCallback_t targetCallback;
|
||||
StateRet_t targetCallback(CSLabel_t * pCSMR, CSParse_t * pCSParse, CSLLTC_t target, PRBool closed, void * pVoid)
|
||||
{
|
||||
PRInt32 change = closed ? -target : target;
|
||||
|
||||
Total += change;
|
||||
if (!ParseDebug)
|
||||
printf("%3d ", change);
|
||||
/* printf("%s %s (%d)\n", closed ? " ending" : "starting", pCSParse->pParseState->note, closed ? -target : target); */
|
||||
return StateRet_OK;
|
||||
}
|
||||
|
||||
/* LLErrorHandler_t parseErrorHandler; */
|
||||
StateRet_t parseErrorHandler(CSLabel_t * pCSLabel, CSParse_t * pCSParse,
|
||||
const char * token, char demark,
|
||||
StateRet_t errorCode)
|
||||
{
|
||||
char space[256];
|
||||
printf("%20s - %s:", pCSParse->pTargetObject->note,
|
||||
pCSParse->currentSubState == SubState_X ? "SubState_X" :
|
||||
pCSParse->currentSubState == SubState_N ? "SubState_N" :
|
||||
pCSParse->currentSubState == SubState_A ? "SubState_A" :
|
||||
pCSParse->currentSubState == SubState_B ? "SubState_B" :
|
||||
pCSParse->currentSubState == SubState_C ? "SubState_C" :
|
||||
pCSParse->currentSubState == SubState_D ? "SubState_D" :
|
||||
pCSParse->currentSubState == SubState_E ? "SubState_E" :
|
||||
pCSParse->currentSubState == SubState_F ? "SubState_F" :
|
||||
pCSParse->currentSubState == SubState_G ? "SubState_G" :
|
||||
pCSParse->currentSubState == SubState_H ? "SubState_H" :
|
||||
"???");
|
||||
switch (errorCode) {
|
||||
case StateRet_WARN_NO_MATCH:
|
||||
if (token)
|
||||
sprintf(space, "Unexpected token \"%s\".\n", token);
|
||||
else
|
||||
sprintf(space, "Unexpected lack of token.\n");
|
||||
break;
|
||||
case StateRet_WARN_BAD_PUNCT:
|
||||
sprintf(space, "Unexpected punctuation \"%c\"", demark);
|
||||
if (token)
|
||||
printf("after token \"%s\".\n", token);
|
||||
else
|
||||
printf(".\n");
|
||||
break;
|
||||
case StateRet_ERROR_BAD_CHAR:
|
||||
sprintf(space, "Unexpected character \"%c\" in token \"%s\".\n",
|
||||
*pCSParse->pParseContext->pTokenError, token);
|
||||
break;
|
||||
default:
|
||||
sprintf(space, "Internal error: demark:\"%c\" token:\"%s\".\n",
|
||||
demark, token);
|
||||
break;
|
||||
}
|
||||
printf(space);
|
||||
/*
|
||||
CSLabel_dump(pCSMR);
|
||||
HTTrace(pParseState->note);
|
||||
*/
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
/* #if 1 */
|
||||
#if 0
|
||||
/* use this main to test input with a series of labels, each on a line. */
|
||||
PRInt32 main(PRInt32 argc, char** argv)
|
||||
{
|
||||
char lineBuf[512];
|
||||
CSParse_t * pCSParse = 0;
|
||||
CSDoMore_t last = CSDoMore_done;
|
||||
FILE * input;
|
||||
|
||||
if (argc > 1) {
|
||||
if ((input = fopen(argv[1], "r")) == NULL) {
|
||||
printf("Couldn't open \"%s\".\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
input = stdin;
|
||||
}
|
||||
if (argc > 2)
|
||||
ParseDebug = 1;
|
||||
pCSParse = CSParse_newLabel(&targetCallback, &parseErrorHandler);
|
||||
while (fgets(lineBuf, sizeof(lineBuf), input)){
|
||||
PRInt32 len;
|
||||
char * ptr;
|
||||
for (ptr = lineBuf; *ptr; ptr++)
|
||||
if (*ptr == ';') {
|
||||
*ptr = 0;
|
||||
break;
|
||||
}
|
||||
/* if (strchr(lineBuf, ';'))
|
||||
*ptr = 0;
|
||||
if (lineBuf[0] == ';')
|
||||
continue; */
|
||||
len = PL_strlen(lineBuf);
|
||||
if (lineBuf[len - 1] == '\r' || lineBuf[len - 1] == '\n') {
|
||||
lineBuf[len-- - 1] = 0;
|
||||
}
|
||||
if (!lineBuf[0]) {
|
||||
if (last != CSDoMore_done)
|
||||
printf("parsing end error\n");
|
||||
if (pCSParse)
|
||||
CSParse_deleteLabel(pCSParse);
|
||||
pCSParse = CSParse_newLabel(&targetCallback, &parseErrorHandler);
|
||||
last = CSDoMore_done;
|
||||
} else {
|
||||
printf("%s ", lineBuf); if (ParseDebug) printf("\n");
|
||||
switch (last = CSParse_parseChunk(pCSParse, lineBuf, (PRInt32) PL_strlen(lineBuf), 0)) {
|
||||
case CSDoMore_done:
|
||||
printf("= %d - parsing end\n", Total);
|
||||
break;
|
||||
case CSDoMore_error:
|
||||
printf("= %d - parsing error\n", Total);
|
||||
exit (1);
|
||||
case CSDoMore_more:
|
||||
printf("\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pCSParse)
|
||||
CSParse_deleteLabel(pCSParse);
|
||||
if (last != CSDoMore_done)
|
||||
printf("parsing end error\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* #else */
|
||||
#endif
|
||||
#if 0
|
||||
|
||||
/* use this main to test input of a label list spread out over multiple lines*/
|
||||
PRInt32 main(PRInt32 argc, char** argv)
|
||||
{
|
||||
char lineBuf[512];
|
||||
while (gets(lineBuf)){
|
||||
CSParse_t * pCSParse;
|
||||
if (lineBuf[0] == ';')
|
||||
continue;
|
||||
Total = 0;
|
||||
printf("%s", lineBuf);
|
||||
pCSParse = CSParse_newLabel(&targetCallback, &parseErrorHandler);
|
||||
if (CSParse_parseChunk(pCSParse, lineBuf,
|
||||
(PRInt32)PL_strlen(lineBuf), 0) != CSDoMore_done) {
|
||||
printf("parsing end error\n");
|
||||
break;
|
||||
}
|
||||
CSParse_deleteLabel(pCSParse);
|
||||
printf("= %d\n", Total);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0 /* a not-needed but often useful sample implementation of HTTrace */
|
||||
PRInt32 HTTrace(const char * fmt, ...)
|
||||
{
|
||||
va_list pArgs;
|
||||
va_start(pArgs, fmt);
|
||||
return (vfprintf(stderr, fmt, pArgs));
|
||||
}
|
||||
#endif
|
||||
void * HTMemory_malloc (size_t size)
|
||||
{
|
||||
return PR_Malloc(size);
|
||||
}
|
||||
|
||||
void * HTMemory_calloc (size_t nobj, size_t size)
|
||||
{
|
||||
return PR_Calloc(nobj, size);
|
||||
}
|
||||
|
||||
void * HTMemory_realloc (void * p, size_t size)
|
||||
{
|
||||
return PR_Realloc(p, size);
|
||||
}
|
||||
|
||||
void HTMemory_free (void * ptr)
|
||||
{
|
||||
PR_Free(ptr);
|
||||
}
|
||||
|
||||
void HTMemory_outofmem (char * name, char * file, unsigned long line)
|
||||
{
|
||||
HTTrace("%s:%ld failed allocation for \"%s\".\n\
|
||||
Program aborted.\n",
|
||||
file, line, name);
|
||||
/* exit(1); */
|
||||
/* XP_SetError( SEC_ERROR_NO_MEMORY ); */
|
||||
exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user