Changeset 7935
- Timestamp:
- Jul 18, 2006, 4:26:53 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/types/psMetadataConfig.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psMetadataConfig.c
r7933 r7935 10 10 * @author Eric Van Alst, MHPCC 11 11 * 12 * @version $Revision: 1.6 6$ $Name: not supported by cvs2svn $13 * @date $Date: 2006-07-1 8 21:53:25$12 * @version $Revision: 1.67 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-07-19 02:26:53 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 276 276 psS32 *status) 277 277 { 278 psBool value = false;279 280 281 /* if(*inString=='T' || *inString=='t' || *inString=='1') {282 value = true;283 } else if(*inString=='F' || *inString=='f' || *inString=='0') {284 value = false;285 } else {286 *status = 1;287 }288 */289 278 if ( !strncmp(inString, "T", 2) || !strncmp(inString, "t", 2) || 290 279 !strncmp(inString, "1", 2) || !strncmp(inString, "TRUE", 5) || 291 280 !strncmp(inString, "true", 5) || !strncmp(inString, "True", 5)) { 292 value =true;293 } else if ( !strncmp(inString, "F", 2) || !strncmp(inString, "f", 2) ||294 !strncmp(inString, "0", 2) || !strncmp(inString, "FALSE", 6) ||295 !strncmp(inString, "false", 6) || !strncmp(inString, "False", 6) ) {296 value = false;297 } else {298 *status = 1;299 } 300 301 return value;281 return true; 282 } 283 if ( !strncmp(inString, "F", 2) || !strncmp(inString, "f", 2) || 284 !strncmp(inString, "0", 2) || !strncmp(inString, "FALSE", 6) || 285 !strncmp(inString, "false", 6) || !strncmp(inString, "False", 6) ) { 286 return false; 287 } 288 289 *status = 1; 290 return false; 302 291 } 303 292 … … 679 668 psFree(token); 680 669 } 681 // psFree(iter);682 670 } 683 671 return md; … … 1028 1016 // Check if the add status was successful 1029 1017 if (! addStatus) { 1030 // psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_OVERWRITE_ITEM, keyName, lineCount,1031 // fileName);1032 1018 returnValue = false; 1033 1019 } … … 1247 1233 } 1248 1234 1249 // very dangerous to use comments to block out a very long section...1250 # if 01251 psString psMetadataConfigFormat(psMetadata *md)1252 {1253 PS_ASSERT_PTR_NON_NULL(md, NULL);1254 1255 psString newString = NULL;1256 psString newStr = NULL;1257 char mdString[16000];1258 psMetadataItem *item = NULL;1259 psMetadataIterator *iter = psMetadataIteratorAlloc(md, PS_LIST_HEAD, NULL);1260 psDataType type = PS_DATA_UNKNOWN;1261 // int size = 0;1262 int i = 0;1263 char content[MAXSTR];1264 char buffer[MAXSTR];1265 char *buffer2;1266 strcpy(content, "\0");1267 strcpy(mdString, "\0");1268 1269 while ( (item = psMetadataGetAndIncrement(iter)) ) {1270 type = item->type;1271 if ( type == PS_DATA_STRING) {1272 type = PS_DATA_STRING;1273 }1274 if ( type == PS_DATA_VECTOR) {1275 type = PS_DATA_VECTOR;1276 }1277 if ( type == PS_DATA_TIME) {1278 type = PS_DATA_TIME;1279 }1280 if ( item->type == PS_DATA_METADATA) {1281 type = PS_DATA_METADATA;1282 }1283 if (item == NULL) {1284 type = PS_DATA_UNKNOWN;1285 }1286 1287 switch (type) {1288 case PS_DATA_BOOL:1289 // size = strlen(item->name);1290 snprintf(content, MAXSTR, "%s BOOL ", item->name);1291 strncat(mdString, content, MAXSTR);1292 if ( item->data.B )1293 strncat(mdString, "TRUE", MAXSTR);1294 else1295 strncat(mdString, "FALSE", MAXSTR);1296 if ( item->comment != NULL ) {1297 // size = strlen(item->comment);1298 snprintf(content, MAXSTR, " #%s \n", item->comment);1299 strncat(mdString, content, MAXSTR);1300 } else {1301 snprintf(content, MAXSTR, "\n");1302 strncat(mdString, content, MAXSTR);1303 }1304 break;1305 case PS_DATA_S32:1306 // size = strlen(item->name);1307 snprintf(content, MAXSTR, "%s S32 ", item->name);1308 strncat(mdString, content, MAXSTR);1309 snprintf(content, MAXSTR, "%d ", item->data.S32);1310 strncat(mdString, content, MAXSTR);1311 if ( strncmp(item->comment,"",2) ) {1312 // size = strlen(item->comment);1313 snprintf(content, MAXSTR, " #%s \n", item->comment);1314 strncat(mdString, content, MAXSTR);1315 } else {1316 snprintf(content, MAXSTR, "\n");1317 strncat(mdString, content, MAXSTR);1318 }1319 break;1320 case PS_DATA_F32:1321 // size = strlen(item->name);1322 snprintf(content, MAXSTR, "%s F32 ", item->name);1323 strncat(mdString, content, MAXSTR);1324 snprintf(content, MAXSTR, "%22.15g ", item->data.F32);1325 strncat(mdString, content, MAXSTR);1326 if ( strncmp(item->comment,"",2) ) {1327 // if ( item->comment != NULL ) {1328 // size = strlen(item->comment);1329 snprintf(content, MAXSTR, " #%s \n", item->comment);1330 strncat(mdString, content, MAXSTR);1331 } else {1332 snprintf(content, MAXSTR, "\n");1333 strncat(mdString, content, MAXSTR);1334 }1335 break;1336 case PS_DATA_F64:1337 // size = strlen(item->name);1338 snprintf(content, MAXSTR, "%s F64 ", item->name);1339 strncat(mdString, content, MAXSTR);1340 snprintf(content, MAXSTR, "%22.15g ", item->data.F64);1341 strncat(mdString, content, MAXSTR);1342 if ( strncmp(item->comment,"",2) ) {1343 // if ( item->comment != NULL ) {1344 // if ( !strncmp((char*)item->comment, "", 2) ) {1345 // size = strlen(item->comment);1346 snprintf(content, MAXSTR, " #%s \n", item->comment);1347 strncat(mdString, content, MAXSTR);1348 } else {1349 snprintf(content, MAXSTR, "\n");1350 strncat(mdString, content, MAXSTR);1351 }1352 break;1353 case PS_DATA_STRING:1354 // size = strlen(item->name);1355 snprintf(content, MAXSTR, "%s STR ", item->name);1356 strncat(mdString, content, MAXSTR);1357 // size = strlen(((char *)(item->data.V)));1358 snprintf(content, MAXSTR, "%s ", ((char *)(item->data.V)));1359 strncat(mdString, content, MAXSTR);1360 if ( strncmp(item->comment,"",2) ) {1361 // if ( item->comment != NULL ) {1362 // size = strlen(item->comment);1363 snprintf(content, MAXSTR, " #%s \n", item->comment);1364 strncat(mdString, content, MAXSTR);1365 } else {1366 snprintf(content, MAXSTR, "\n");1367 strncat(mdString, content, MAXSTR);1368 }1369 break;1370 case PS_DATA_METADATA:1371 snprintf(content, MAXSTR, "\n%s METADATA ", item->name);1372 strncat(mdString, content, MAXSTR);1373 1374 newStr = psMetadataConfigFormat(item->data.md);1375 strncpy(buffer, (char *)newStr, MAXSTR);1376 buffer2 = strtok(buffer, "\n");1377 while( buffer2 != NULL ) {1378 snprintf(content, MAXSTR, "\n %s", buffer2);1379 strncat(mdString, content, MAXSTR);1380 buffer2 = strtok(NULL, "\n");1381 }1382 if ( strncmp(item->comment,"",2) ) {1383 // if ( item->comment != NULL ) {1384 snprintf(content, MAXSTR, "\nEND #%s\n\n", item->comment);1385 strncat(mdString, content, MAXSTR);1386 } else {1387 snprintf(content, MAXSTR, "\nEND\n\n");1388 strncat(mdString, content, MAXSTR);1389 }1390 psFree(newStr);1391 break;1392 case PS_DATA_TIME:1393 snprintf(content, MAXSTR, "%s ", item->name);1394 if ( ((psTime*)(item->data.V))->type == PS_TIME_UTC )1395 strncat(content, "PS_TIME_UTC ", MAXSTR);1396 else if ( ((psTime*)(item->data.V))->type == PS_TIME_TAI )1397 strncat(content, "PS_TIME_TAI ", MAXSTR);1398 else if ( ((psTime*)(item->data.V))->type == PS_TIME_UT1 )1399 strncat(content, "PS_TIME_UT1 ", MAXSTR);1400 else if ( ((psTime*)(item->data.V))->type == PS_TIME_TT )1401 strncat(content, "PS_TIME_TT ", MAXSTR);1402 else {1403 psError(PS_ERR_BAD_PARAMETER_VALUE, true,1404 PS_ERRORTEXT_psMetadata_METATYPE_INVALID, type);1405 psFree(iter);1406 return NULL;1407 }1408 strncat(mdString, content, MAXSTR);1409 1410 snprintf(content, MAXSTR, "%ld, ", (long)((psTime*)(item->data.V))->sec);1411 strncat(mdString, content, MAXSTR);1412 snprintf(content, MAXSTR, "%u, ", ((psTime*)(item->data.V))->nsec);1413 strncat(mdString, content, MAXSTR);1414 if ( ((psTime*)(item->data.V))->leapsecond )1415 strncat(mdString, "T ", MAXSTR);1416 else1417 strncat(mdString, "F ", MAXSTR);1418 if ( strncmp(item->comment,"",2) ) {1419 // if ( item->comment != NULL ) {1420 snprintf(content, MAXSTR, " #%s \n", item->comment);1421 strncat(mdString, content, MAXSTR);1422 } else {1423 snprintf(content, MAXSTR, "\n");1424 strncat(mdString, content, MAXSTR);1425 }1426 break;1427 case PS_DATA_VECTOR:1428 // size = strlen(item->name);1429 snprintf(content, MAXSTR, "@%s ", item->name);1430 strncat(mdString, content, MAXSTR);1431 type = ((psVector*)(item->data.V))->type.type;1432 switch (type) {1433 case PS_DATA_S32:1434 strncat(mdString, "S32 ", MAXSTR);1435 for (i = 0; ((psVector*)(item->data.V))->data.S32[i] != 0; i++) {1436 snprintf(content, MAXSTR, "%d",1437 ((psVector*)(item->data.V))->data.S32[i]);1438 if ( ((psVector*)(item->data.V))->data.S32[i+1] != 0 ) {1439 strncat(content, ", ", MAXSTR);1440 }1441 strncat(mdString, content, MAXSTR);1442 }1443 break;1444 case PS_DATA_F32:1445 strncat(mdString, "F32 ", MAXSTR);1446 for (i = 0; ((psVector*)(item->data.V))->data.F32[i] != 0; i++) {1447 snprintf(content, MAXSTR, "%22.15g",1448 ((psVector*)(item->data.V))->data.F32[i]);1449 if ( ((psVector*)(item->data.V))->data.F32[i+1] != 0 ) {1450 strncat(content, ", ", MAXSTR);1451 }1452 strncat(mdString, content, MAXSTR);1453 }1454 break;1455 case PS_DATA_F64:1456 strncat(mdString, "F64 ", MAXSTR);1457 for (i = 0; ((psVector*)(item->data.V))->data.F64[i] != 0; i++) {1458 snprintf(content, MAXSTR, "%22.15g",1459 ((psVector*)(item->data.V))->data.F64[i]);1460 if ( ((psVector*)(item->data.V))->data.F64[i+1] != 0 ) {1461 strncat(content, ", ", MAXSTR);1462 }1463 strncat(mdString, content, MAXSTR);1464 }1465 break;1466 case PS_DATA_UNKNOWN:1467 default:1468 psError(PS_ERR_BAD_PARAMETER_VALUE, true,1469 PS_ERRORTEXT_psMetadata_METATYPE_INVALID, type);1470 psFree(iter);1471 return NULL;1472 }1473 if ( strncmp(item->comment,"",2) ) {1474 // if ( item->comment != NULL ) {1475 // size = strlen(item->comment);1476 snprintf(content, MAXSTR, " #%s \n", item->comment);1477 strncat(mdString, content, MAXSTR);1478 } else {1479 snprintf(content, MAXSTR, "\n");1480 strncat(mdString, content, MAXSTR);1481 }1482 break;1483 case PS_DATA_UNKNOWN:1484 default:1485 psError(PS_ERR_BAD_PARAMETER_VALUE, true,1486 PS_ERRORTEXT_psMetadata_METATYPE_INVALID, type);1487 psFree(iter);1488 return NULL;1489 }1490 }1491 newString = psStringNCopy(mdString, 16000);1492 psFree(iter);1493 return newString;1494 }1495 # endif // old version of psMetadataConfigFormat1496 1235 1497 1236 psString psMetadataConfigFormat(psMetadata *md)
Note:
See TracChangeset
for help on using the changeset viewer.
