From 6b1598c8b98699b115525155b43d19365e79dd08 Mon Sep 17 00:00:00 2001 From: Nima Talebi Date: Sat, 23 May 2009 23:02:46 +1000 Subject: Reimplementing the type() function - WIP --- src/config.h | 4 ++++ src/util.c | 9 +++++++++ src/util.h | 1 + src/xmlpythonizer.c | 21 +++++++++++++++------ 4 files changed, 29 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/config.h b/src/config.h index a2e7e58..8eb38ad 100644 --- a/src/config.h +++ b/src/config.h @@ -27,4 +27,8 @@ #define PYTHON_XML_MAP "/usr/share/python-dmidecode/pythonmap.xml" #endif +#ifndef PYTHON_XML_TYPEMAP +#define PYTHON_XML_TYPEMAP "/usr/share/python-dmidecode/typemap.xml" +#endif + #endif diff --git a/src/util.c b/src/util.c index d9ac510..58fd5ec 100644 --- a/src/util.c +++ b/src/util.c @@ -189,3 +189,12 @@ int write_dump(size_t base, size_t len, const void *data, const char *dumpfile, fclose(f); return -1; } + +int is_int(const char *s) +{ + char _s[3]; + snprintf(_s, 3, "%ld", strtol(s, (char **)NULL, 10)); + return !strcmp(s, _s); +} + + diff --git a/src/util.h b/src/util.h index 3effd0c..e216566 100644 --- a/src/util.h +++ b/src/util.h @@ -28,3 +28,4 @@ int checksum(const u8 * buf, size_t len); void *mem_chunk(size_t base, size_t len, const char *devmem); int write_dump(size_t base, size_t len, const void *data, const char *dumpfile, int add); +int is_int(const char *s); diff --git a/src/xmlpythonizer.c b/src/xmlpythonizer.c index f1d755e..ea78b94 100644 --- a/src/xmlpythonizer.c +++ b/src/xmlpythonizer.c @@ -35,6 +35,7 @@ #include #include +#include "util.h" #include "dmixml.h" #include "xmlpythonizer.h" @@ -338,14 +339,22 @@ ptzMAP *dmiMAP_ParseMappingXML(xmlDoc *xmlmap, const char *mapname) { return NULL; } - // Find the section matching our request (mapname) - for( node = node->children->next; node != NULL; node = node->next ) { - if( xmlStrcmp(node->name, (xmlChar *) "Mapping") == 0) { - char *name = dmixml_GetAttrValue(node, "name"); - if( (name != NULL) && (strcmp(name, mapname) == 0) ) { - break; + if(!is_int(mapname)) { + // Find the section matching our request (mapname) + for( node = node->children->next; node != NULL; node = node->next ) { + if( xmlStrcmp(node->name, (xmlChar *) "Mapping") == 0) { + char *name = dmixml_GetAttrValue(node, "name"); + if( (name != NULL) && (strcmp(name, mapname) == 0) ) { + break; + } } } + } else { + //. FIXME + char msg[8194]; + snprintf(msg, 8193, "Not (yet) implemented%c", 0); + PyErr_SetString(PyExc_SystemError, msg); + return NULL; } if( node == NULL ) { -- cgit