Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
rle_getcom.c
Go to the documentation of this file.
1 /*
2  * This software is copyrighted as noted below. It may be freely copied,
3  * modified, and redistributed, provided that the copyright notice is
4  * preserved on all copies.
5  *
6  * There is no warranty or other guarantee of fitness for this software,
7  * it is provided solely "as is". Bug reports or fixes may be sent
8  * to the author, who may or may not act on them as he desires.
9  *
10  * You may not include this software in a program or other software product
11  * without supplying the source, or without informing the end-user that the
12  * source is available for no extra charge.
13  *
14  * If you modify this software, you should include a notice giving the
15  * name of the person performing the modification, the date of modification,
16  * and the reason for such modification.
17  */
18 /*
19  * rle_getcom.c - Get specific comments from the_hdr structure.
20  *
21  * Author: Spencer W. Thomas
22  * Computer Science Dept.
23  * University of Utah
24  * Date: Sun Jan 25 1987
25  * Copyright (c) 1987, University of Utah
26  */
27 
28 #include <stdio.h>
29 #include "rle.h"
30 
31 /*****************************************************************
32  * TAG( match )
33  *
34  * Match a name against a test string for "name=value" or "name".
35  * If it matches name=value, return pointer to value part, if just
36  * name, return pointer to NUL at end of string. If no match, return NULL.
37  *
38  * Inputs:
39  * n: Name to match. May also be "name=value" to make it easier
40  * to replace comments.
41  * v: Test string.
42  * Outputs:
43  * Returns pointer as above.
44  * Assumptions:
45  * [None]
46  * Algorithm:
47  * [None]
48  */
49 static char *
50 match( n, v )
51 register char *n;
52 register char *v;
53 {
54  for ( ; *n != '\0' && *n != '=' && *n == *v; n++, v++ )
55  ;
56  if (*n == '\0' || *n == '=') {
57  if ( *v == '\0' )
58  return v;
59  else if ( *v == '=' )
60  return ++v;
61  }
62 
63  return NULL;
64 }
65 
66 /*****************************************************************
67  * TAG( rle_getcom )
68  *
69  * Return a pointer to the value part of a name=value pair in the comments.
70  * Inputs:
71  * name: Name part of the comment to search for.
72  * the_hdr: rle_dflt_hdr structure.
73  * Outputs:
74  * Returns pointer to value part of comment or NULL if no match.
75  * Assumptions:
76  * [None]
77  * Algorithm:
78  * [None]
79  */
80 char *
82 CONST_DECL char *name;
83 rle_hdr *the_hdr;
84 {
85  CONST_DECL char ** cp;
86  char * v;
87 
88  if ( the_hdr->comments == NULL )
89  return NULL;
90 
91  for ( cp = the_hdr->comments; *cp; cp++ )
92  if ( (v = match( name, *cp )) != NULL )
93  return v;
94 
95  return NULL;
96 }
const char ** comments
Definition: rle.h:113
#define CONST_DECL
Definition: rle_config.h:42
char * rle_getcom(char *name, rle_hdr *the_hdr) const
Definition: rle_getcom.c:81
static char * match(char *n, char *v)
Definition: rle_getcom.c:50