Changeset 5000 for trunk/psLib/src/xml/psXML.c
- Timestamp:
- Sep 12, 2005, 11:36:54 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/xml/psXML.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/xml/psXML.c
r4891 r5000 10 10 * @author David Robbins, MHPCC 11 11 * 12 * @version $Revision: 1.3 8$ $Name: not supported by cvs2svn $13 * @date $Date: 2005-0 8-27 01:33:41$12 * @version $Revision: 1.39 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2005-09-12 21:36:54 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 54 54 char content[MAXSTR]; 55 55 char vec[MAXVEC]; 56 char timeVal[MAXSTR]; 56 57 int i; 57 58 psMetadataIterator *iter = psMetadataIteratorAlloc(*(psMetadata**)&md, PS_LIST_HEAD, NULL); … … 73 74 if ( type == 65547) 74 75 type = PS_DATA_METADATA; 76 if ( type == 65549) 77 type = PS_DATA_TIME; 75 78 switch (type) { 76 79 case PS_DATA_BOOL: … … 123 126 new_node = xmlAddSibling(cur_node, new_root); 124 127 psFree(newDoc); 128 break; 129 case PS_DATA_TIME: 130 cur_node = xmlNewChild(root, NULL, (const xmlChar*)"time", (const xmlChar*)"\n"); 131 prop = xmlNewProp(cur_node, (const xmlChar*)"name", (const xmlChar*)item->name); 132 if ( ((psTime*)(item->data.V))->type == PS_TIME_UTC ) 133 prop = xmlNewProp(cur_node, (const xmlChar*)"psType", (const xmlChar*)"PS_TIME_UTC"); 134 else if ( ((psTime*)(item->data.V))->type == PS_TIME_TAI ) 135 prop = xmlNewProp(cur_node, (const xmlChar*)"psType", (const xmlChar*)"PS_TIME_TAI"); 136 else if ( ((psTime*)(item->data.V))->type == PS_TIME_UT1 ) 137 prop = xmlNewProp(cur_node, (const xmlChar*)"psType", (const xmlChar*)"PS_TIME_UT1"); 138 else if ( ((psTime*)(item->data.V))->type == PS_TIME_TT ) 139 prop = xmlNewProp(cur_node, (const xmlChar*)"psType", (const xmlChar*)"PS_TIME_TT"); 140 else { 141 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 142 PS_ERRORTEXT_psXML_INVALID_CONTENT); 143 return NULL; 144 } 145 snprintf(content, MAXSTR, "%ld, ", ((psTime*)(item->data.V))->sec); 146 strncpy(timeVal, content, MAXSTR); 147 snprintf(content, MAXSTR, "%u, ", ((psTime*)(item->data.V))->nsec); 148 strncat(timeVal, content, MAXSTR); 149 if ( ((psTime*)(item->data.V))->leapsecond ) 150 strncat(timeVal, "T", MAXSTR); 151 else 152 strncat(timeVal, "F", MAXSTR); 153 prop = xmlNewProp(cur_node, (const xmlChar*)"value", (const xmlChar*)timeVal); 125 154 break; 126 155 case PS_DATA_VECTOR: … … 140 169 strncat(vec, content, MAXSTR); 141 170 } 142 143 171 break; 144 172 case PS_DATA_F32: … … 266 294 } 267 295 296 static void storeTime(psTime *out, char *in) 297 { 298 char *endp; 299 long sec = 0; 300 unsigned int nsec = 0; 301 302 sec = strtol(in, &endp, 10); 303 out->sec = sec; 304 if ( !strncmp(endp, ",", 1) ) 305 endp++; 306 else 307 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 308 PS_ERRORTEXT_psXML_INVALID_CONTENT); 309 in = endp; 310 nsec = (unsigned int)strtol(in, &endp, 10); 311 out->nsec = nsec; 312 if ( !strncmp(endp, ",", 1) ) 313 endp++; 314 else 315 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 316 PS_ERRORTEXT_psXML_INVALID_CONTENT); 317 in = endp; 318 if ( !strncmp(in, "false", 10) || !strncmp(in, "f", 10) || 319 !strncmp(in, "FALSE", 10) || !strncmp(in, " F", 10) ) 320 out->leapsecond = false; 321 else if ( !strncmp(in, "true", 10) || !strncmp(in, "t", 10) || 322 !strncmp(in, "TRUE", 10) || !strncmp(in, "T", 10) ) 323 out->leapsecond = true; 324 else { 325 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 326 PS_ERRORTEXT_psXML_INVALID_CONTENT); 327 } 328 } 329 268 330 //Check the xml item for errors. Returns the data type or PS_DATA_UNKNOWN for errors.// 269 331 static psDataType chkType(xmlNode *node) … … 309 371 } 310 372 } 373 if(!strncmp((const char*)node->name, "time", MAXSTR) || !strncmp((const char*)node->name, "TIME", MAXSTR) ) { 374 if (node->properties != NULL && node->properties->name 375 && node->properties->next != NULL && node->properties->next->name != NULL) { 376 return(PS_DATA_TIME); 377 } else { 378 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 379 PS_ERRORTEXT_psXML_INVALID_CONTENT); 380 return(PS_DATA_UNKNOWN); 381 } 382 } 311 383 return(PS_DATA_UNKNOWN); 312 384 } … … 385 457 psFree(vec); 386 458 break; 459 case PS_DATA_TIME: 460 strncpy(name, (const char*)cur_node->properties->children->content, MAXSTR); 461 strncpy(content, 462 (const char*)cur_node->properties->next->next->children->content, MAXSTR); 463 psTimeType timeType; 464 char type[MAXSTR]; 465 strncpy(type, (const char*)cur_node->properties->next->children->content, MAXSTR); 466 if ( !strncmp(type, "PS_TIME_UTC", MAXSTR) ) 467 timeType = PS_TIME_UTC; 468 else if ( !strncmp(type, "PS_TIME_TAI", MAXSTR) ) 469 timeType = PS_TIME_TAI; 470 else if ( !strncmp(type, "PS_TIME_UT1", MAXSTR) ) 471 timeType = PS_TIME_UT1; 472 else if ( !strncmp(type, "PS_TIME_TT", MAXSTR) ) 473 timeType = PS_TIME_TT; 474 else { 475 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 476 PS_ERRORTEXT_psXML_INVALID_CONTENT); 477 psFree(meta); 478 return NULL; 479 } 480 481 psTime *time; 482 time = psTimeAlloc(timeType); 483 storeTime(time, content); 484 psMetadataAddTime(meta, PS_LIST_TAIL, name, 0, "", time); 485 psFree(time); 486 break; 387 487 case PS_DATA_METADATA: 388 488 strncpy(name, (const char*)cur_node->properties->children->content, MAXSTR); 389 // psMetadata *temp = psMetadataAlloc();390 489 psMetadata *temp = NULL; 391 490 temp = xml2metadata(cur_node->children, nodeNum);
Note:
See TracChangeset
for help on using the changeset viewer.
