static enum output_format parse_output_format(const char *name, char *callname) { if (!hwloc_strncasecmp(name, "default", 3)) return LSTOPO_OUTPUT_DEFAULT; else if (!hwloc_strncasecmp(name, "console", 3)) return LSTOPO_OUTPUT_CONSOLE; else if (!strcasecmp(name, "synthetic")) return LSTOPO_OUTPUT_SYNTHETIC; else if (!strcasecmp(name, "ascii") || !strcasecmp(name, "txt") /* backward compat with 1.10 */) return LSTOPO_OUTPUT_ASCII; else if (!strcasecmp(name, "fig")) return LSTOPO_OUTPUT_FIG; else if (!strcasecmp(name, "png")) return LSTOPO_OUTPUT_PNG; else if (!strcasecmp(name, "pdf")) return LSTOPO_OUTPUT_PDF; else if (!strcasecmp(name, "ps")) return LSTOPO_OUTPUT_PS; else if (!strcasecmp(name, "svg")) return LSTOPO_OUTPUT_SVG; else if (!strcasecmp(name, "xml")) return LSTOPO_OUTPUT_XML; fprintf(stderr, "file format `%s' not supported\n", name); usage(callname, stderr); exit(EXIT_FAILURE); }
static hwloc_uint64_t hwloc_synthetic_parse_memory_attr(const char *attr, const char **endp) { const char *endptr; hwloc_uint64_t size; size = strtoull(attr, (char **) &endptr, 0); if (!hwloc_strncasecmp(endptr, "TB", 2)) { size <<= 40; endptr += 2; } else if (!hwloc_strncasecmp(endptr, "GB", 2)) { size <<= 30; endptr += 2; } else if (!hwloc_strncasecmp(endptr, "MB", 2)) { size <<= 20; endptr += 2; } else if (!hwloc_strncasecmp(endptr, "kB", 2)) { size <<= 10; endptr += 2; } *endp = endptr; return size; }
int hwloc_obj_type_sscanf(const char *string, hwloc_obj_type_t *typep, int *depthattrp, void *typeattrp, size_t typeattrsize) { hwloc_obj_type_t type = (hwloc_obj_type_t) -1; int depthattr = -1; hwloc_obj_cache_type_t cachetypeattr = (hwloc_obj_cache_type_t) -1; /* unspecified */ char *end; /* types without depthattr */ if (!hwloc_strncasecmp(string, "system", 2)) { type = HWLOC_OBJ_SYSTEM; } else if (!hwloc_strncasecmp(string, "machine", 2)) { type = HWLOC_OBJ_MACHINE; } else if (!hwloc_strncasecmp(string, "node", 1) || !hwloc_strncasecmp(string, "numa", 1)) { /* matches node and numanode */ type = HWLOC_OBJ_NODE; } else if (!hwloc_strncasecmp(string, "socket", 2)) { type = HWLOC_OBJ_SOCKET; } else if (!hwloc_strncasecmp(string, "core", 2)) { type = HWLOC_OBJ_CORE; } else if (!hwloc_strncasecmp(string, "pu", 2)) { type = HWLOC_OBJ_PU; } else if (!hwloc_strncasecmp(string, "misc", 2)) { type = HWLOC_OBJ_MISC; } else if (!hwloc_strncasecmp(string, "bridge", 2)) { type = HWLOC_OBJ_BRIDGE; } else if (!hwloc_strncasecmp(string, "pci", 2)) { type = HWLOC_OBJ_PCI_DEVICE; } else if (!hwloc_strncasecmp(string, "os", 2)) { type = HWLOC_OBJ_OS_DEVICE; /* types with depthattr */ } else if (!hwloc_strncasecmp(string, "cache", 2)) { type = HWLOC_OBJ_CACHE; } else if ((string[0] == 'l' || string[0] == 'L') && string[1] >= '0' && string[1] <= '9') { type = HWLOC_OBJ_CACHE; depthattr = strtol(string+1, &end, 10); if (*end == 'd') { cachetypeattr = HWLOC_OBJ_CACHE_DATA; } else if (*end == 'i') { cachetypeattr = HWLOC_OBJ_CACHE_INSTRUCTION; } else if (*end == 'u') { cachetypeattr = HWLOC_OBJ_CACHE_UNIFIED; } } else if (!hwloc_strncasecmp(string, "group", 2)) { int length; type = HWLOC_OBJ_GROUP; length = strcspn(string, "0123456789"); if (length <= 5 && !hwloc_strncasecmp(string, "group", length) && string[length] >= '0' && string[length] <= '9') { depthattr = strtol(string+length, &end, 10); } } else return -1; *typep = type; if (depthattrp) *depthattrp = depthattr; if (typeattrp) { if (type == HWLOC_OBJ_CACHE && sizeof(hwloc_obj_cache_type_t) <= typeattrsize) memcpy(typeattrp, &cachetypeattr, sizeof(hwloc_obj_cache_type_t)); } return 0; }
int hwloc_type_sscanf(const char *string, hwloc_obj_type_t *typep, union hwloc_obj_attr_u *attrp, size_t attrsize) { hwloc_obj_type_t type = (hwloc_obj_type_t) -1; unsigned depthattr = (unsigned) -1; hwloc_obj_cache_type_t cachetypeattr = (hwloc_obj_cache_type_t) -1; /* unspecified */ hwloc_obj_bridge_type_t ubtype = (hwloc_obj_bridge_type_t) -1; hwloc_obj_osdev_type_t ostype = (hwloc_obj_osdev_type_t) -1; char *end; /* never match the ending \0 since we want to match things like core:2 too. * just use hwloc_strncasecmp() everywhere. */ /* types without a custom depth */ if (!hwloc_strncasecmp(string, "system", 2)) { type = HWLOC_OBJ_SYSTEM; } else if (!hwloc_strncasecmp(string, "machine", 2)) { type = HWLOC_OBJ_MACHINE; } else if (!hwloc_strncasecmp(string, "node", 2) || !hwloc_strncasecmp(string, "numa", 2)) { /* matches node and numanode */ type = HWLOC_OBJ_NUMANODE; } else if (!hwloc_strncasecmp(string, "package", 2) || !hwloc_strncasecmp(string, "socket", 2)) { /* backward compat with v1.10 */ type = HWLOC_OBJ_PACKAGE; } else if (!hwloc_strncasecmp(string, "core", 2)) { type = HWLOC_OBJ_CORE; } else if (!hwloc_strncasecmp(string, "pu", 2)) { type = HWLOC_OBJ_PU; } else if (!hwloc_strncasecmp(string, "misc", 4)) { type = HWLOC_OBJ_MISC; } else if (!hwloc_strncasecmp(string, "bridge", 4)) { type = HWLOC_OBJ_BRIDGE; } else if (!hwloc_strncasecmp(string, "hostbridge", 6)) { type = HWLOC_OBJ_BRIDGE; ubtype = HWLOC_OBJ_BRIDGE_HOST; } else if (!hwloc_strncasecmp(string, "pcibridge", 5)) { type = HWLOC_OBJ_BRIDGE; ubtype = HWLOC_OBJ_BRIDGE_PCI; } else if (!hwloc_strncasecmp(string, "pci", 3)) { type = HWLOC_OBJ_PCI_DEVICE; } else if (!hwloc_strncasecmp(string, "os", 2)) { type = HWLOC_OBJ_OS_DEVICE; } else if (!hwloc_strncasecmp(string, "bloc", 4)) { type = HWLOC_OBJ_OS_DEVICE; ostype = HWLOC_OBJ_OSDEV_BLOCK; } else if (!hwloc_strncasecmp(string, "net", 3)) { type = HWLOC_OBJ_OS_DEVICE; ostype = HWLOC_OBJ_OSDEV_NETWORK; } else if (!hwloc_strncasecmp(string, "openfab", 7)) { type = HWLOC_OBJ_OS_DEVICE; ostype = HWLOC_OBJ_OSDEV_OPENFABRICS; } else if (!hwloc_strncasecmp(string, "dma", 3)) { type = HWLOC_OBJ_OS_DEVICE; ostype = HWLOC_OBJ_OSDEV_DMA; } else if (!hwloc_strncasecmp(string, "gpu", 3)) { type = HWLOC_OBJ_OS_DEVICE; ostype = HWLOC_OBJ_OSDEV_GPU; } else if (!hwloc_strncasecmp(string, "copro", 5) || !hwloc_strncasecmp(string, "co-pro", 6)) { type = HWLOC_OBJ_OS_DEVICE; ostype = HWLOC_OBJ_OSDEV_COPROC; /* types with depthattr */ } else if ((string[0] == 'l' || string[0] == 'L') && string[1] >= '0' && string[1] <= '9') { depthattr = strtol(string+1, &end, 10); if (*end == 'i') { if (depthattr >= 1 && depthattr <= 3) { type = HWLOC_OBJ_L1ICACHE + depthattr-1; cachetypeattr = HWLOC_OBJ_CACHE_INSTRUCTION; } else return -1; } else { if (depthattr >= 1 && depthattr <= 5) { type = HWLOC_OBJ_L1CACHE + depthattr-1; cachetypeattr = *end == 'd' ? HWLOC_OBJ_CACHE_DATA : HWLOC_OBJ_CACHE_UNIFIED; } else return -1; } } else if (!hwloc_strncasecmp(string, "group", 2)) { size_t length; type = HWLOC_OBJ_GROUP; length = strcspn(string, "0123456789"); if (length <= 5 && !hwloc_strncasecmp(string, "group", length) && string[length] >= '0' && string[length] <= '9') { depthattr = strtol(string+length, &end, 10); } } else return -1; *typep = type; if (attrp) { if (hwloc_obj_type_is_cache(type) && attrsize >= sizeof(attrp->cache)) { attrp->cache.depth = depthattr; attrp->cache.type = cachetypeattr; } else if (type == HWLOC_OBJ_GROUP && attrsize >= sizeof(attrp->group)) { attrp->group.depth = depthattr; } else if (type == HWLOC_OBJ_BRIDGE && attrsize >= sizeof(attrp->bridge)) { attrp->bridge.upstream_type = ubtype; attrp->bridge.downstream_type = HWLOC_OBJ_BRIDGE_PCI; /* nothing else so far */ } else if (type == HWLOC_OBJ_OS_DEVICE && attrsize >= sizeof(attrp->osdev)) { attrp->osdev.type = ostype; } } return 0; }