-static int IsNumber (const char* Value)
-/* Check if Value is an integer number */
-{
- if (*Value == '-' || *Value == '+') {
- ++Value;
- }
- while (IsDigit (*Value)) {
- ++Value;
- }
- return (*Value == '\0');
-}
-
-
-
Attr* NewAttr (const char* Name, const char* Value)
/* Create a new attribute */
{
Attr* NewAttr (const char* Name, const char* Value)
/* Create a new attribute */
{
- /* Determine the length of Value */
- unsigned Len = strlen (Value);
+ /* Determine the string lengths */
+ unsigned NameLen = strlen (Name);
+ unsigned ValueLen = strlen (Value);
- Attr* A = xmalloc (sizeof (Attr) + Len);
+ Attr* A = xmalloc (sizeof (Attr) + ValueLen + NameLen + 1);
/* Initialize the fields */
/* Initialize the fields */
- A->Flags = IsNumber (Value)? afInt : afNone;
- A->Name = xstrdup (Name);
- memcpy (A->Value, Value, Len + 1);
+ A->Name = A->Value + ValueLen + 1;
+ memcpy (A->Value, Value, ValueLen + 1);
+ memcpy (A->Name, Name, NameLen + 1);
/* Return the new struct */
return A;
/* Return the new struct */
return A;
void FreeAttr (Attr* A)
/* Free an attribute structure */
{
void FreeAttr (Attr* A)
/* Free an attribute structure */
{
- /* Allow NULL pointers */
- if (A) {
- xfree (A->Name);
- xfree (A);
- }
void FreeAttrList (Collection* C)
void FreeAttrList (Collection* C)
-/* Free a list of attributes */
+/* Free a list of attributes */
-/* Attribute flags */
-enum AttrFlags {
- afNone,
- afInt, /* Integer number */
-};
-typedef enum AttrFlags AttrFlags;
-
-/* */
+/* Attribute structure */
typedef struct Attr Attr;
struct Attr {
typedef struct Attr Attr;
struct Attr {
- AttrFlags Flags; /* Attribute flags */
- char* Name; /* Attribute name */
- char Value[1]; /* Attribute value */
+ char* Name; /* Attribute name - points into Value */
+ char Value[1]; /* Attribute value followed by Name */