int main(int argc, char *argv[]) { type_code attrType = B_STRING_TYPE; char *attrValue = NULL; size_t valueFileLength = 0; bool resolveLinks = true; int c; while ((c = getopt_long(argc, argv, "hf:t:P", kLongOptions, NULL)) != -1) { switch (c) { case 0: break; case 'f': { // retrieve attribute value from file BFile file; off_t size; status_t status = file.SetTo(optarg, B_READ_ONLY); if (status < B_OK) { ERR("can't read attribute value from file %s: %s\n", optarg, strerror(status)); return 1; } status = file.GetSize(&size); if (status == B_OK) { if (size == 0) { ERR_0("attribute value is empty: 0 bytes\n"); return 1; } if (size > 4 * 1024 * 1024) { ERR("attribute value is too large: %" B_PRIdOFF " bytes\n", size); return 1; } attrValue = (char *)malloc(size); if (attrValue != NULL) status = file.Read(attrValue, size); else status = B_NO_MEMORY; } if (status < B_OK) { ERR("can't read attribute value: %s\n", strerror(status)); return 1; } valueFileLength = (size_t)size; break; } case 't': // Get the attribute type if (typeForString(optarg, &attrType) != B_OK) invalidAttrType(optarg); break; case 'P': resolveLinks = false; break; case 'h': usage(0); break; default: usage(1); break; } } if (argc - optind < 1) usage(1); const char *attrName = argv[optind++]; if (argc - optind < 1) usage(1); if (!valueFileLength) attrValue = argv[optind++]; if (argc - optind < 1) usage(1); // Now that we gathered all the information proceed // to add the attribute to the file(s) int result = 0; for (; optind < argc; optind++) { status_t status = addAttr(argv[optind], attrType, attrName, attrValue, valueFileLength, resolveLinks); // special case for bool types if (status == B_BAD_VALUE && attrType == B_BOOL_TYPE) invalidBoolValue(attrValue); if (status != B_OK) { ERR("can't add attribute to file %s: %s\n", argv[optind], strerror(status)); // proceed files, but return an error at the end result = 1; } } if (valueFileLength) free(attrValue); return result; }
OSPDataType AMRVolume::getVoxelType() { return (voxelType == "") ? typeForString(getParamString("voxelType", "unspecified")): typeForString(voxelType.c_str()); }