MISR Toolkit  1.5.1
p_nodesp.c
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Description: This file contains C routines to that create and manipulate
4  the parameters -- attributes and pointers -- of an object
5  or group.
6 
7  Author: Randy Davis, University of Colorado LASP
8 
9  Creation Date: 12 March 1989
10  Last Modified: 18 May 1991
11 
12  History:
13 
14  Creation - This module was introduced in a somewhat different form in
15  the Version 1 release of the ODLC library.
16 
17  Version 2.0 - 30 August 1990 - R. Davis, U. of Colorado LASP
18  a) This set of routines has been adapted from the Version 1 set of
19  routines for manipulating attributes. The routines NewParameter,
20  RemoveParameter, FindParameter and NextParameter have been con-
21  structed from the Version 1 routines NewAttribute, RemoveAttribute,
22  FindAttribute and NextAttribute, respectively. The function of the
23  Version 1 routine FirstAttribute is now part of FindParameter.
24  Routines CopyParameter, CutParameter and PasteParameter are new
25  for this version.
26 
27  Version 2.1 - 13 March 1991 - R. Davis, U. of Colorado LASP
28  a) Implemented cut, copy and paste routines and changed some of the
29  other routines to take advantage of them.
30  b) Added support for comments attached to parameters.
31 
32  Version 2.2 - 18 May 1991 - M. DeMore, Jet Propulsion Laboratory
33  a) Removed include statements that were Unix specific and placed them
34  in odldef.h.
35  b) Added intialization of two application specific fields to the
36  NewParameter routine.
37  c) Removed unused variables from several routines.
38 *****************************************************************************/
39 
40 #include <stdlib.h>
41 #include "odldef.h"
42 
43 
44 
45 
46 /*****************************************************************************
47 
48  Routine: NewParameter
49 
50  Description: Create a new parameter node and attach it to an
51  object or group node.
52 
53  Input:
54  aggregate - Pointer to the aggregate node to which the parameter
55  is to be attached. If this value is NULL, the
56  parameter node is created but not attached to
57  any aggregate node.
58  kind - Kind of parameter: attribute (KP_ATTRIBUTE) or
59  pointer (KP_POINTER).
60  name - A character string containing the name to be given
61  to the parameter.
62 
63  Output: A pointer to the new parameter node is returned as the function
64  result. A NULL value indicates that the parameter could not be
65  added, probably due to lack of dynamic memory. The NULL value is
66  also returned if the name input name argument is NULL.
67 
68 *****************************************************************************/
69 
70 
72 
73  AGGREGATE aggregate,
74  PARAMETER_KIND kind,
75  char *name)
76 
77 {
78  PARAMETER parameter; /* Pointer to the new parameter node */
79  char *string;
80 
81 /* >>>>>>>>>>>>>>>>>>>>>>>>>> BEGIN CN CHANGES >>>>>>>>>>>>>>>>>>>>>>>>> */
82 /* >>>>> MDD 5/18/91 Removed unused variable old_last >>>>> */
83 /* >>>>>>>>>>>>>>>>>>>>>>>>>> END OF CN CHANGES >>>>>>>>>>>>>>>>>>>>>>>> */
84 
85 
86  if (name == NULL)
87  {
88  return (NULL);
89  }
90 
91  /* Allocate memory for the new parameter node */
92 
93  parameter = (PARAMETER) malloc (PARAMETER_NODE_SIZE);
94  if (parameter != NULL)
95  {
96  /* Copy the parameters's kind and name */
97 
98  parameter->node_kind = kind;
99 
100  string = (char *) malloc (strlen(name)+1);
101  if (string == NULL)
102  {
103  /* Error: Allocation failed, probably due to lack of memory.
104  Free up all space and return */
105 
106  free (parameter);
107  return (NULL);
108  }
109 
110  parameter->name = strcpy (string, name);
111 
112  /* Initialize the other data fields in the parameter node */
113 
114  parameter->comment = NULL;
115  parameter->value_kind = KV_UNKNOWN;
116  parameter->value_count = 0;
117  parameter->columns = 0;
118  parameter->rows = 0;
119 
120 /* >>>>>>>>>>>>>>>>>>>>>>>>>> BEGIN CN CHANGES >>>>>>>>>>>>>>>>>>>>>>>>> */
121 /* >>>>> MDD 5/18/91 Added intialization of two application >>>>> */
122 /* >>>>> defined fields in the parameter structure. >>>>> */
123 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
124 
125 #ifdef PDS_TOOLBOX
126  parameter->appl1 = 0;
127  parameter->appl2 = 0;
128 #endif
129 
130 /* >>>>>>>>>>>>>>>>>>>>>>>>>> END OF CN CHANGES >>>>>>>>>>>>>>>>>>>>>>>> */
131 
132  /* Indicate that there are no values for this parameter yet */
133 
134  parameter->first_value = NULL;
135  parameter->last_value = NULL;
136 
137  /* Attach the parameter node to its aggregate node, if any */
138 
139  if (aggregate != NULL)
140  {
141  PasteParameter (aggregate, parameter);
142  }
143  else
144  {
145  /* There is no aggregate node to attach to: this parameter
146  node will stand alone */
147 
148  parameter->owner = NULL;
149  parameter->left_sibling = NULL;
150  parameter->right_sibling = NULL;
151  }
152  }
153 
154  return (parameter);
155 }
156 
157 
158 
159 
160 /*****************************************************************************
161 
162  Routine: RemoveParameter
163 
164  Description: Removes a parameter node and all of its values.
165 
166  Input:
167  parameter - A pointer to the parameter node to be removed.
168 
169  Output: A pointer to the next parameter of the aggregate. The NULL
170  value is returned if there is no next parameter. The NULL
171  value is also returned if input argument is NULL.
172 
173 *****************************************************************************/
174 
175 
177 
178  PARAMETER parameter)
179 
180 {
181  PARAMETER r_parameter; /* Pointer to parameter's right sibling */
182  VALUE value; /* Pointer to parameter's value nodes */
183 
184 
185  if (parameter == NULL)
186  {
187  return (NULL);
188  }
189 
190  /* Remove all the values associated with the parameter */
191 
192  value = FirstValue (parameter);
193 
194  while (value != NULL)
195  {
196  value = RemoveValue (value);
197  }
198 
199  /* Remember the location of the next parameter node for this aggregate */
200 
201  r_parameter = parameter->right_sibling;
202 
203  /* Detach the parameter node from its aggregate node */
204 
205  CutParameter (parameter);
206 
207  /* Free up the memory space used to hold the parameter node, its
208  name string and any comment attached to the node */
209 
210  if(parameter->comment != NULL)
211  {
212  free (parameter->comment);
213  parameter->comment = NULL;
214  }
215  if(parameter->name != NULL)
216  {
217  free (parameter->name);
218  parameter->name = NULL;
219  }
220  free (parameter);
221  parameter = NULL;
222 
223  /* Point to the next available parameter, if any */
224 
225  return (r_parameter);
226 }
227 
228 
229 
230 
231 /*****************************************************************************
232 
233  Routine: FirstParameter
234 
235  Description: Returns the first parameter node of an object or group node.
236 
237  Input:
238  parameter - A pointer to the aggregate node.
239 
240  Output: A pointer to the first parameter node is returned as the function
241  result. The value NULL is returned if there are no parameters for
242  the aggregate. The NULL value is also returned if the input
243  argument is NULL.
244 
245 *****************************************************************************/
246 
247 
249 
250  AGGREGATE aggregate)
251 
252 {
253 
254  if (aggregate == NULL)
255  {
256  return (NULL);
257  }
258  else
259  {
260  return (aggregate->first_parameter);
261  }
262 
263 }
264 
265 
266 
267 
268 /*****************************************************************************
269 
270  Routine: NextParameter
271 
272  Description: Returns the next parameter of an object or group node.
273 
274  Input:
275  parameter - A pointer to the current parameter node.
276 
277  Output: A pointer to the next parameter node is returned as the function
278  result. The value NULL is returned if there are no more parameters
279  for the object or group. The NULL value is also returned if the
280  input argument is NULL.
281 
282 *****************************************************************************/
283 
284 
286 
287  PARAMETER parameter)
288 
289 {
290 
291  if (parameter == NULL)
292  {
293  return (NULL);
294  }
295  else
296  {
297  return (parameter->right_sibling);
298  }
299 
300 }
301 
302 
303 
304 
305 /*****************************************************************************
306 
307  Routine: FindParameter
308 
309  Description: Finds the first parameter of an object or group node with a
310  specified name.
311 
312  Input:
313  base_node - A pointer to the aggregate node for which the
314  parameter node search is to be performed.
315  name - Character string containing parameter name to be
316  located.
317 
318  Output: A pointer to the parameter node with the specified name. If
319  no match is found, then the NULL value is returned. The NULL
320  value will also be returned if either of the input arguments
321  is NULL.
322 
323 *****************************************************************************/
324 
325 
327 
328  AGGREGATE aggregate,
329  char *name)
330 
331 {
332  PARAMETER parameter; /* Pointer to parameter node */
333 
334 
335  if (aggregate == NULL || name == NULL)
336  {
337  return (NULL);
338  }
339 
340  /* Start searching with the first parameter of the specified aggregate */
341 
342  parameter = FirstParameter (aggregate);
343 
344  while (parameter != NULL && strcmp (parameter->name, name) != 0)
345  {
346  parameter = NextParameter (parameter);
347  }
348 
349  return (parameter);
350 }
351 
352 
353 
354 
355 /*****************************************************************************
356 
357  Routine: CutParameter
358 
359  Description: Cuts a parameter node and its values from an ODL tree.
360 
361  Input:
362  parameter - A pointer to the parameter node that is to be
363  cut from the tree.
364 
365  Output: A pointer to the cut parameter node is returned as the function
366  value. The NULL value is returned if the input argument is NULL.
367 
368 *****************************************************************************/
369 
370 
372 
373  PARAMETER parameter)
374 
375 {
376  AGGREGATE aggregate; /* Pointer to parameter's aggregate node */
377  PARAMETER l_parameter; /* Pointer to parameter's left sibling */
378  PARAMETER r_parameter; /* Pointer to parameter's right sibling */
379 
380 
381  if (parameter == NULL)
382  {
383  return (NULL);
384  }
385 
386  /* Detach the parameter node from its aggregate node */
387 
388  aggregate = parameter->owner;
389  l_parameter = parameter->left_sibling;
390  r_parameter = parameter->right_sibling;
391 
392  if (l_parameter != NULL)
393  {
394  l_parameter->right_sibling = r_parameter;
395  }
396  else if (aggregate != NULL)
397  {
398  aggregate->first_parameter = r_parameter;
399  }
400 
401  if (r_parameter != NULL)
402  {
403  r_parameter->left_sibling = l_parameter;
404  }
405  else if (aggregate != NULL)
406  {
407  aggregate->last_parameter = l_parameter;
408  }
409 
410  /* Reset the parent pointer and the sibling pointers in the parameter
411  node, since this node now stands alone */
412 
413  parameter->owner = NULL;
414  parameter->left_sibling = NULL;
415  parameter->right_sibling = NULL;
416 
417  /* Return a pointer to the cut parameter node */
418 
419  return (parameter);
420 }
421 
422 
423 
424 
425 /*****************************************************************************
426 
427  Routine: CopyParameter
428 
429  Description: Copies a parameter node and all of its values.
430 
431  Input:
432  parameter - A pointer to the parameter node to be copied. This
433  parameter node remains in the ODL tree.
434 
435  Output: A pointer to the copied parameter node. The value NULL is returned
436  if the input parameter pointer is NULL or if storage couldn't be
437  obtained for the copy.
438 
439 *****************************************************************************/
440 
441 
443 
444  PARAMETER parameter)
445 
446 {
447  PARAMETER parameter_copy; /* Copy of the specified parameter */
448  VALUE value; /* Value node currently being copied */
449  VALUE value_copy; /* Copy of the specified value */
450 
451 /* >>>>>>>>>>>>>>>>>>>>>>>>>> BEGIN CN CHANGES >>>>>>>>>>>>>>>>>>>>>>>>> */
452 /* >>>>> MDD 5/18/91 Removed unused variable string >>>>> */
453 /* >>>>>>>>>>>>>>>>>>>>>>>>>> END OF CN CHANGES >>>>>>>>>>>>>>>>>>>>>>>> */
454 
455 
456  if (parameter == NULL)
457  {
458  return (NULL);
459  }
460 
461  /* Create a new parameter node */
462 
463  parameter_copy = NewParameter (NULL, parameter->node_kind, parameter->name);
464  if (parameter_copy == NULL)
465  {
466  return (NULL);
467  }
468 
469  /* Copy the comment attached to the parameter node, if any */
470 
471  CommentParameter (parameter_copy, parameter->comment);
472 
473  /* Copy the other data fields in the parameter node */
474 
475  parameter_copy->value_kind = parameter->value_kind;
476  parameter_copy->value_count = parameter->value_count;
477  parameter_copy->columns = parameter->columns;
478  parameter_copy->rows = parameter->rows;
479 
480  /* Copy each value node attached to the parameter. For error values there
481  may be none; for scalar values there will be one; for set and sequence
482  values there may be zero, one or more */
483 
484  value = FirstValue (parameter);
485 
486  while (value != NULL)
487  {
488  value_copy = CopyValue (value);
489  NewValue (parameter_copy, &value_copy->item);
490  free (value_copy);
491  value = NextValue (value);
492  }
493 
494  return (parameter_copy);
495 }
496 
497 
498 
499 
500 /*****************************************************************************
501 
502  Routine: PasteParameter
503 
504  Description: Inserts a parameter node and all its values into an ODL tree.
505  The parameter node becomes the current last parameter node
506  of the specified aggregate node.
507 
508  Input:
509  aggregate - A pointer to the aggregate node to which the
510  parameter node is to be added.
511  parameter - A pointer to the parameter node to be pasted.
512 
513  Output: A pointer to the inserted parameter node is returned as the
514  function result. The value NULL is returned if either the
515  target aggregate node or the input parameter node are NULL.
516 
517 *****************************************************************************/
518 
519 
521 
522  AGGREGATE aggregate,
523  PARAMETER parameter)
524 
525 {
526  PARAMETER old_last; /* Previously last parameter node */
527 
528 
529  if (aggregate == NULL || parameter == NULL)
530  {
531  return (NULL);
532  }
533 
534  /* Place the new parameter node at the end of the list of parameters
535  for the specified aggregate */
536 
537  old_last = aggregate->last_parameter;
538  if (old_last != NULL)
539  {
540  old_last->right_sibling = parameter;
541  }
542 
543  aggregate->last_parameter = parameter;
544  if (aggregate->first_parameter == NULL)
545  {
546  aggregate->first_parameter = parameter;
547  }
548 
549  parameter->owner = aggregate;
550  parameter->left_sibling = old_last;
551  parameter->right_sibling = NULL;
552 
553  return (parameter);
554 }
int CommentParameter(PARAMETER parameter, char *comment)
Definition: comments.c:114
struct Parameter_Node * last_parameter
Definition: odldef.h:124
char * name
Definition: odldef.h:138
long value_count
Definition: odldef.h:142
struct Parameter_Node * PARAMETER
Definition: odldef.h:248
PARAMETER FindParameter(AGGREGATE aggregate, char *name)
Definition: p_nodesp.c:326
enum Parameter_Kind PARAMETER_KIND
Definition: odldef.h:91
char * comment
Definition: odldef.h:139
struct Parameter_Node * left_sibling
Definition: odldef.h:146
PARAMETER CopyParameter(PARAMETER parameter)
Definition: p_nodesp.c:442
PARAMETER PasteParameter(AGGREGATE aggregate, PARAMETER parameter)
Definition: p_nodesp.c:520
HDFFCLIBAPI intf intf _fcd string
HDFFCLIBAPI _fcd name
PARAMETER RemoveParameter(PARAMETER parameter)
Definition: p_nodesp.c:176
short rows
Definition: odldef.h:144
VALUE RemoveValue()
struct Value_Data item
Definition: odldef.h:229
VALUE CopyValue()
PARAMETER CutParameter(PARAMETER parameter)
Definition: p_nodesp.c:371
struct Aggregate_Node * owner
Definition: odldef.h:145
PARAMETER NewParameter(AGGREGATE aggregate, PARAMETER_KIND kind, char *name)
Definition: p_nodesp.c:71
PARAMETER NextParameter(PARAMETER parameter)
Definition: p_nodesp.c:285
struct Parameter_Node * first_parameter
Definition: odldef.h:123
struct Value_Node * first_value
Definition: odldef.h:148
VALUE FirstValue()
VALUE NextValue()
VALUE NewValue()
struct Value_Node * last_value
Definition: odldef.h:149
VALUE_KIND value_kind
Definition: odldef.h:141
PARAMETER_KIND node_kind
Definition: odldef.h:140
#define PARAMETER_NODE_SIZE
Definition: odldef.h:266
short columns
Definition: odldef.h:143
union Value_Data::@2 value
PARAMETER FirstParameter(AGGREGATE aggregate)
Definition: p_nodesp.c:248
struct Parameter_Node * right_sibling
Definition: odldef.h:147

MISR Toolkit - Copyright © 2005 - 2020 Jet Propulsion Laboratory
Generated on Fri Jun 19 2020 22:49:51