Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
Functions
rle_putcom.c File Reference
#include <stdio.h>
#include "rle.h"
Include dependency graph for rle_putcom.c:

Go to the source code of this file.

Functions

static char * match (char *n, char *v)
 
const char * rle_putcom (char *value, rle_hdr *the_hdr) const
 
const char * rle_delcom (char *name, the_hdr) const
 

Function Documentation

static char* match ( char *  n,
char *  v 
)
static

Definition at line 50 of file rle_putcom.c.

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 }
const char* rle_delcom ( char *  name,
the_hdr   
) const

Definition at line 140 of file rle_putcom.c.

143 {
144  register CONST_DECL char ** cp;
145  CONST_DECL char * v = NULL;
146 
147  if ( the_hdr->comments == NULL )
148  return NULL;
149  else
150  {
151  for ( cp = the_hdr->comments; *cp != NULL; cp++ )
152  if ( match( name, *cp ) != NULL )
153  {
154  v = *cp;
155  for ( ; *cp != NULL; cp++ )
156  *cp = cp[1];
157  break;
158  }
159  /* Not found */
160  }
161 
162  if ( *the_hdr->comments == NULL )
163  the_hdr->comments = NULL;
164 
165  return v;
166 }
rle_hdr the_hdr
Definition: aliastorle.c:100
const char ** comments
Definition: rle.h:113
#define CONST_DECL
Definition: rle_config.h:42
static char * match(char *n, char *v)
Definition: rle_putcom.c:50
const char* rle_putcom ( char *  value,
rle_hdr the_hdr 
) const

Definition at line 82 of file rle_putcom.c.

Referenced by find_most_used(), and write_rle_header().

85 {
86  register CONST_DECL char ** cp, ** old_comments;
87  CONST_DECL char * v;
88  int i;
89 
90  if ( the_hdr->comments == NULL )
91  {
92  the_hdr->comments = (CONST_DECL char **)malloc( 2 * sizeof(char *) );
93  the_hdr->comments[0] = value;
94  the_hdr->comments[1] = NULL;
95  }
96  else
97  {
98  for ( i = 2, cp = the_hdr->comments; *cp != NULL; i++, cp++ )
99  if ( match( value, *cp ) != NULL )
100  {
101  v = *cp;
102  *cp = value;
103  return v;
104  }
105  /* Not found */
106  /* Can't realloc because somebody else might be pointing to this
107  * comments block. Of course, if this were true, then the
108  * assignment above would change the comments for two headers.
109  * But at least, that won't crash the program. Realloc will.
110  * This would work a lot better in C++, where hdr1 = hdr2
111  * could copy the pointers, too.
112  */
113  old_comments = the_hdr->comments;
114  the_hdr->comments = (CONST_DECL char **)malloc(i * sizeof(char *) );
115  the_hdr->comments[--i] = NULL;
116  the_hdr->comments[--i] = value;
117  for ( i--; i >= 0; i-- )
118  the_hdr->comments[i] = old_comments[i];
119  }
120 
121  return NULL;
122 }
const char ** comments
Definition: rle.h:113
#define CONST_DECL
Definition: rle_config.h:42
static char * match(char *n, char *v)
Definition: rle_putcom.c:50
void * malloc()
int i
Definition: rletorla.c:82
const char * value
Definition: rleClock.c:574

Here is the caller graph for this function: