|
Packit |
78deda |
/*
|
|
Packit |
78deda |
* Copyright (c) 2001-2002 Michael David Adams.
|
|
Packit |
78deda |
* All rights reserved.
|
|
Packit |
78deda |
*/
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/* __START_OF_JASPER_LICENSE__
|
|
Packit |
78deda |
*
|
|
Packit |
78deda |
* JasPer Software License
|
|
Packit |
78deda |
*
|
|
Packit |
78deda |
* IMAGE POWER JPEG-2000 PUBLIC LICENSE
|
|
Packit |
78deda |
* ************************************
|
|
Packit |
78deda |
*
|
|
Packit |
78deda |
* GRANT:
|
|
Packit |
78deda |
*
|
|
Packit |
78deda |
* Permission is hereby granted, free of charge, to any person (the "User")
|
|
Packit |
78deda |
* obtaining a copy of this software and associated documentation, to deal
|
|
Packit |
78deda |
* in the JasPer Software without restriction, including without limitation
|
|
Packit |
78deda |
* the right to use, copy, modify, merge, publish, distribute, sublicense,
|
|
Packit |
78deda |
* and/or sell copies of the JasPer Software (in source and binary forms),
|
|
Packit |
78deda |
* and to permit persons to whom the JasPer Software is furnished to do so,
|
|
Packit |
78deda |
* provided further that the License Conditions below are met.
|
|
Packit |
78deda |
*
|
|
Packit |
78deda |
* License Conditions
|
|
Packit |
78deda |
* ******************
|
|
Packit |
78deda |
*
|
|
Packit |
78deda |
* A. Redistributions of source code must retain the above copyright notice,
|
|
Packit |
78deda |
* and this list of conditions, and the following disclaimer.
|
|
Packit |
78deda |
*
|
|
Packit |
78deda |
* B. Redistributions in binary form must reproduce the above copyright
|
|
Packit |
78deda |
* notice, and this list of conditions, and the following disclaimer in
|
|
Packit |
78deda |
* the documentation and/or other materials provided with the distribution.
|
|
Packit |
78deda |
*
|
|
Packit |
78deda |
* C. Neither the name of Image Power, Inc. nor any other contributor
|
|
Packit |
78deda |
* (including, but not limited to, the University of British Columbia and
|
|
Packit |
78deda |
* Michael David Adams) may be used to endorse or promote products derived
|
|
Packit |
78deda |
* from this software without specific prior written permission.
|
|
Packit |
78deda |
*
|
|
Packit |
78deda |
* D. User agrees that it shall not commence any action against Image Power,
|
|
Packit |
78deda |
* Inc., the University of British Columbia, Michael David Adams, or any
|
|
Packit |
78deda |
* other contributors (collectively "Licensors") for infringement of any
|
|
Packit |
78deda |
* intellectual property rights ("IPR") held by the User in respect of any
|
|
Packit |
78deda |
* technology that User owns or has a right to license or sublicense and
|
|
Packit |
78deda |
* which is an element required in order to claim compliance with ISO/IEC
|
|
Packit |
78deda |
* 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
|
|
Packit |
78deda |
* rights worldwide arising under statutory or common law, and whether
|
|
Packit |
78deda |
* or not perfected, including, without limitation, all (i) patents and
|
|
Packit |
78deda |
* patent applications owned or licensable by User; (ii) rights associated
|
|
Packit |
78deda |
* with works of authorship including copyrights, copyright applications,
|
|
Packit |
78deda |
* copyright registrations, mask work rights, mask work applications,
|
|
Packit |
78deda |
* mask work registrations; (iii) rights relating to the protection of
|
|
Packit |
78deda |
* trade secrets and confidential information; (iv) any right analogous
|
|
Packit |
78deda |
* to those set forth in subsections (i), (ii), or (iii) and any other
|
|
Packit |
78deda |
* proprietary rights relating to intangible property (other than trademark,
|
|
Packit |
78deda |
* trade dress, or service mark rights); and (v) divisions, continuations,
|
|
Packit |
78deda |
* renewals, reissues and extensions of the foregoing (as and to the extent
|
|
Packit |
78deda |
* applicable) now existing, hereafter filed, issued or acquired.
|
|
Packit |
78deda |
*
|
|
Packit |
78deda |
* E. If User commences an infringement action against any Licensor(s) then
|
|
Packit |
78deda |
* such Licensor(s) shall have the right to terminate User's license and
|
|
Packit |
78deda |
* all sublicenses that have been granted hereunder by User to other parties.
|
|
Packit |
78deda |
*
|
|
Packit |
78deda |
* F. This software is for use only in hardware or software products that
|
|
Packit |
78deda |
* are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
|
|
Packit |
78deda |
* or right to this Software is granted for products that do not comply
|
|
Packit |
78deda |
* with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
|
|
Packit |
78deda |
* from the ISO.
|
|
Packit |
78deda |
*
|
|
Packit |
78deda |
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
|
|
Packit |
78deda |
* NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
|
Packit |
78deda |
* THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
|
|
Packit |
78deda |
* CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
|
|
Packit |
78deda |
* OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
|
|
Packit |
78deda |
* WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
|
|
Packit |
78deda |
* IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
|
|
Packit |
78deda |
* TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
|
|
Packit |
78deda |
* OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
|
|
Packit |
78deda |
* PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
|
|
Packit |
78deda |
* THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
|
|
Packit |
78deda |
* IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
|
|
Packit |
78deda |
* IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
|
|
Packit |
78deda |
* OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
|
|
Packit |
78deda |
* OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
|
|
Packit |
78deda |
* REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
|
|
Packit |
78deda |
* WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
|
|
Packit |
78deda |
* INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
|
|
Packit |
78deda |
* MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
|
|
Packit |
78deda |
* JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
|
|
Packit |
78deda |
* THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
|
|
Packit |
78deda |
* CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
|
|
Packit |
78deda |
* DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
|
|
Packit |
78deda |
* MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
|
|
Packit |
78deda |
* SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
|
|
Packit |
78deda |
* OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
|
|
Packit |
78deda |
* FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
|
|
Packit |
78deda |
* RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
|
|
Packit |
78deda |
* FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
|
|
Packit |
78deda |
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
|
|
Packit |
78deda |
* LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
|
|
Packit |
78deda |
* JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
|
|
Packit |
78deda |
* TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
|
|
Packit |
78deda |
* ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
|
|
Packit |
78deda |
* OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
|
|
Packit |
78deda |
* KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
|
|
Packit |
78deda |
* TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
|
|
Packit |
78deda |
* CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
|
|
Packit |
78deda |
* NOTICE SPECIFIED IN THIS SECTION.
|
|
Packit |
78deda |
*
|
|
Packit |
78deda |
* __END_OF_JASPER_LICENSE__
|
|
Packit |
78deda |
*/
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/*
|
|
Packit |
78deda |
* Tag-Value Parser Library
|
|
Packit |
78deda |
*
|
|
Packit |
78deda |
* $Id$
|
|
Packit |
78deda |
*/
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/******************************************************************************\
|
|
Packit |
78deda |
* Includes.
|
|
Packit |
78deda |
\******************************************************************************/
|
|
Packit |
78deda |
|
|
Packit |
78deda |
#include <assert.h>
|
|
Packit |
78deda |
#include <stdio.h>
|
|
Packit |
78deda |
#include <ctype.h>
|
|
Packit |
78deda |
#include <stdlib.h>
|
|
Packit |
78deda |
|
|
Packit |
78deda |
#include "jasper/jas_malloc.h"
|
|
Packit |
78deda |
#include "jasper/jas_string.h"
|
|
Packit |
78deda |
#include "jasper/jas_tvp.h"
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/******************************************************************************\
|
|
Packit |
78deda |
* Macros.
|
|
Packit |
78deda |
\******************************************************************************/
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/* Is the specified character valid for a tag name? */
|
|
Packit |
78deda |
#define JAS_TVP_ISTAG(x) \
|
|
Packit |
78deda |
(isalpha(x) || (x) == '_' || isdigit(x))
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/******************************************************************************\
|
|
Packit |
78deda |
* Code for creating and destroying a tag-value parser.
|
|
Packit |
78deda |
\******************************************************************************/
|
|
Packit |
78deda |
|
|
Packit |
78deda |
jas_tvparser_t *jas_tvparser_create(const char *s)
|
|
Packit |
78deda |
{
|
|
Packit |
78deda |
jas_tvparser_t *tvp;
|
|
Packit |
78deda |
if (!(tvp = jas_malloc(sizeof(jas_tvparser_t)))) {
|
|
Packit |
78deda |
return 0;
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
if (!(tvp->buf = jas_strdup(s))) {
|
|
Packit |
78deda |
jas_tvparser_destroy(tvp);
|
|
Packit |
78deda |
return 0;
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
tvp->pos = tvp->buf;
|
|
Packit |
78deda |
tvp->tag = 0;
|
|
Packit |
78deda |
tvp->val = 0;
|
|
Packit |
78deda |
return tvp;
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
|
|
Packit |
78deda |
void jas_tvparser_destroy(jas_tvparser_t *tvp)
|
|
Packit |
78deda |
{
|
|
Packit |
78deda |
if (tvp->buf) {
|
|
Packit |
78deda |
jas_free(tvp->buf);
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
jas_free(tvp);
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/******************************************************************************\
|
|
Packit |
78deda |
* Main parsing code.
|
|
Packit |
78deda |
\******************************************************************************/
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/* Get the next tag-value pair. */
|
|
Packit |
78deda |
int jas_tvparser_next(jas_tvparser_t *tvp)
|
|
Packit |
78deda |
{
|
|
Packit |
78deda |
char *p;
|
|
Packit |
78deda |
char *tag;
|
|
Packit |
78deda |
const char *val;
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/* Skip any leading whitespace. */
|
|
Packit |
78deda |
p = tvp->pos;
|
|
Packit |
78deda |
while (*p != '\0' && isspace(*p)) {
|
|
Packit |
78deda |
++p;
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/* Has the end of the input data been reached? */
|
|
Packit |
78deda |
if (*p == '\0') {
|
|
Packit |
78deda |
/* No more tags are present. */
|
|
Packit |
78deda |
tvp->pos = p;
|
|
Packit |
78deda |
return 1;
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/* Does the tag name begin with a valid character? */
|
|
Packit |
78deda |
if (!JAS_TVP_ISTAG(*p)) {
|
|
Packit |
78deda |
return -1;
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/* Remember where the tag name begins. */
|
|
Packit |
78deda |
tag = p;
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/* Find the end of the tag name. */
|
|
Packit |
78deda |
while (*p != '\0' && JAS_TVP_ISTAG(*p)) {
|
|
Packit |
78deda |
++p;
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/* Has the end of the input data been reached? */
|
|
Packit |
78deda |
if (*p == '\0') {
|
|
Packit |
78deda |
/* The value field is empty. */
|
|
Packit |
78deda |
tvp->tag = tag;
|
|
Packit |
78deda |
tvp->val = "";
|
|
Packit |
78deda |
tvp->pos = p;
|
|
Packit |
78deda |
return 0;
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/* Is a value field not present? */
|
|
Packit |
78deda |
if (*p != '=') {
|
|
Packit |
78deda |
if (*p != '\0' && !isspace(*p)) {
|
|
Packit |
78deda |
return -1;
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
*p++ = '\0';
|
|
Packit |
78deda |
tvp->tag = tag;
|
|
Packit |
78deda |
tvp->val = "";
|
|
Packit |
78deda |
tvp->pos = p;
|
|
Packit |
78deda |
return 0;
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
|
|
Packit |
78deda |
*p++ = '\0';
|
|
Packit |
78deda |
|
|
Packit |
78deda |
val = p;
|
|
Packit |
78deda |
while (*p != '\0' && !isspace(*p)) {
|
|
Packit |
78deda |
++p;
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
|
|
Packit |
78deda |
if (*p != '\0') {
|
|
Packit |
78deda |
*p++ = '\0';
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
|
|
Packit |
78deda |
tvp->pos = p;
|
|
Packit |
78deda |
tvp->tag = tag;
|
|
Packit |
78deda |
tvp->val = val;
|
|
Packit |
78deda |
|
|
Packit |
78deda |
return 0;
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/******************************************************************************\
|
|
Packit |
78deda |
* Code for querying the current tag/value.
|
|
Packit |
78deda |
\******************************************************************************/
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/* Get the current tag. */
|
|
Packit |
78deda |
char *jas_tvparser_gettag(jas_tvparser_t *tvp)
|
|
Packit |
78deda |
{
|
|
Packit |
78deda |
return tvp->tag;
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/* Get the current value. */
|
|
Packit |
78deda |
const char *jas_tvparser_getval(jas_tvparser_t *tvp)
|
|
Packit |
78deda |
{
|
|
Packit |
78deda |
return tvp->val;
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/******************************************************************************\
|
|
Packit |
78deda |
* Miscellaneous code.
|
|
Packit |
78deda |
\******************************************************************************/
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/* Lookup a tag by name. */
|
|
Packit |
78deda |
jas_taginfo_t *jas_taginfos_lookup(jas_taginfo_t *taginfos, const char *name)
|
|
Packit |
78deda |
{
|
|
Packit |
78deda |
jas_taginfo_t *taginfo;
|
|
Packit |
78deda |
taginfo = taginfos;
|
|
Packit |
78deda |
while (taginfo->id >= 0) {
|
|
Packit |
78deda |
if (!strcmp(taginfo->name, name)) {
|
|
Packit |
78deda |
return taginfo;
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
++taginfo;
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
return 0;
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/* This function is simply for convenience. */
|
|
Packit |
78deda |
/* One can avoid testing for the special case of a null pointer, by
|
|
Packit |
78deda |
using this function. This function never returns a null pointer. */
|
|
Packit |
78deda |
jas_taginfo_t *jas_taginfo_nonull(jas_taginfo_t *taginfo)
|
|
Packit |
78deda |
{
|
|
Packit |
78deda |
static jas_taginfo_t invalidtaginfo = {
|
|
Packit |
78deda |
-1, 0
|
|
Packit |
78deda |
};
|
|
Packit |
78deda |
|
|
Packit |
78deda |
return taginfo ? taginfo : &invalidtaginfo;
|
|
Packit |
78deda |
}
|