Index: trunk/i386/libsaio/xml.c =================================================================== --- trunk/i386/libsaio/xml.c (revision 2618) +++ trunk/i386/libsaio/xml.c (revision 2619) @@ -133,7 +133,7 @@ if (dict->type != kTagTypeDict) { - return 0; + return NULL; } tag = 0; @@ -152,7 +152,7 @@ return tag->tag; } } - return 0; + return NULL; } //========================================================================== @@ -255,24 +255,26 @@ return tmp; } -/* Function for basic XML character entities parsing */ +typedef const struct XMLEntity { + const char *name; + size_t nameLen; + char value; +} XMLEntity; -char *XMLDecode(const char* src) -{ - typedef const struct XMLEntity { - const char *name; - size_t nameLen; - char value; - } XMLEntity; +/* This is ugly, but better than specifying the lengths by hand */ - /* This is ugly, but better than specifying the lengths by hand */ - #define _e(str,c) {str,sizeof(str)-1,c} - const XMLEntity ents[] = { - _e("quot;",'"'), _e("apos;",'\''), - _e("lt;", '<'), _e("gt;", '>'), - _e("amp;", '&') - }; +#define _e(str,c) {str,sizeof(str)-1,c} +const XMLEntity ents[] = { + _e("quot;",'"'), // double quotation mark + _e("apos;",'\''), // ampersand + _e("lt;", '<'), // apostrophe (apostrophe-quote) + _e("gt;", '>'), // less-than sign + _e("amp;", '&') // greater-than sign +}; +/* Function for basic XML character entities parsing */ +char *XMLDecode(const char *src) +{ size_t len; const char *s; char *out, *o; @@ -372,10 +374,8 @@ { long length = 0; long pos = 0; + char *tagName = NULL; - - char *tagName; - length = GetNextTag(buffer, &tagName, 0); if (length == -1) { @@ -533,6 +533,11 @@ int integer = (int)GetRefString(id); TagPtr tmpTag = NewTag(); + if (tmpTag == 0) + { + return -1; + } + tmpTag->type = kTagTypeInteger; tmpTag->string = (char*) integer; tmpTag->tag = 0; @@ -607,7 +612,7 @@ else { // it wasn't parsed so we consumed no additional characters - *tag = 0; + *tag = NULL; length = 0; } @@ -626,7 +631,7 @@ { long pos = 0; long length = 0; - TagPtr tagList = 0; + TagPtr tagList = NULL; TagPtr tmpTag; @@ -643,7 +648,7 @@ pos += length; // detect end of list - if (tmpTag == 0) + if (tmpTag == NULL) { break; } @@ -659,7 +664,7 @@ } tmpTag = NewTag(); - if (tmpTag == 0) + if (tmpTag == NULL) { XMLFreeTag(tagList); return -1; @@ -700,14 +705,14 @@ } tmpTag = NewTag(); - if (tmpTag == 0) + if (tmpTag == NULL) { XMLFreeTag(subTag); return -1; } string = NewSymbol(buffer); - if (string == 0) + if (string == NULL) { XMLFreeTag(subTag); XMLFreeTag(tmpTag); @@ -740,13 +745,13 @@ } TagPtr tmpTag = NewTag(); - if (tmpTag == 0) + if (tmpTag == NULL) { return -1; } string = NewSymbol(buffer); - if (string == 0) + if (string == NULL) { XMLFreeTag(tmpTag); return -1; @@ -754,8 +759,8 @@ tmpTag->type = kTagTypeString; tmpTag->string = string; - tmpTag->tag = 0; - tmpTag->tagNext = 0; + tmpTag->tag = NULL; + tmpTag->tagNext = NULL; tmpTag->offset = buffer_start ? buffer - buffer_start: 0; *tag = tmpTag; @@ -860,9 +865,9 @@ tmpTag->type = kTagTypeInteger; tmpTag->string = (char *)integer; - tmpTag->tag = 0; + tmpTag->tag = NULL; tmpTag->offset = buffer_start ? buffer - buffer_start: 0; - tmpTag->tagNext = 0; + tmpTag->tagNext = NULL; *tag = tmpTag; @@ -886,7 +891,7 @@ } tmpTag = NewTag(); - if (tmpTag == 0) + if (tmpTag == NULL) { return -1; } @@ -899,10 +904,10 @@ tmpTag->type = kTagTypeData; tmpTag->string = string; - tmpTag->tag = 0; + tmpTag->tag = NULL; tmpTag->offset = actuallen; // buffer_start ? buffer - buffer_start: 0; - tmpTag->tagNext = 0; + tmpTag->tagNext = NULL; *tag = tmpTag; @@ -924,7 +929,7 @@ } tmpTag = NewTag(); - if (tmpTag == 0) + if (tmpTag == NULL) { return -1; } @@ -933,9 +938,9 @@ getchar(); tmpTag->type = kTagTypeDate; - tmpTag->string = 0; - tmpTag->tag = 0; - tmpTag->tagNext = 0; + tmpTag->string = NULL; + tmpTag->tag = NULL; + tmpTag->tagNext = NULL; tmpTag->offset = buffer_start ? buffer - buffer_start: 0; *tag = tmpTag; @@ -951,17 +956,18 @@ TagPtr tmpTag; tmpTag = NewTag(); - if (tmpTag == 0) + if (tmpTag == NULL) { return -1; } tmpTag->type = type; - tmpTag->string = 0; - tmpTag->tag = 0; - tmpTag->tagNext = 0; + tmpTag->string = NULL; + tmpTag->tag = NULL; + tmpTag->tagNext = NULL; tmpTag->offset = buffer_start ? buffer - buffer_start: 0; + *tag = tmpTag; return 0; @@ -975,7 +981,7 @@ long cnt; long cnt2; - if (tag == 0) + if (tag == NULL) { return -1; } @@ -1054,19 +1060,18 @@ #define kTagsPerBlock (0x1000) -static TagPtr gTagsFree; - +static TagPtr gTagsFree = NULL; static TagPtr NewTag( void ) { long cnt; TagPtr tag; - if (gTagsFree == 0) + if (gTagsFree == NULL) { tag = (TagPtr)malloc(kTagsPerBlock *sizeof(Tag)); - if (tag == 0) + if (tag == NULL) { - return 0; + return NULL; } // Initalize the new tags. @@ -1094,7 +1099,7 @@ void XMLFreeTag( TagPtr tag ) { #if DOFREE - if (tag == 0) + if (tag == NULL) { return; } @@ -1109,8 +1114,8 @@ // Clear and free the tag. tag->type = kTagTypeNone; - tag->string = 0; - tag->tag = 0; + tag->string = NULL; + tag->tag = NULL; tag->offset = 0; tag->tagNext = gTagsFree; gTagsFree = tag; @@ -1132,7 +1137,7 @@ static SymbolPtr FindSymbol(char *string, SymbolPtr *prevSymbol); -static SymbolPtr gSymbolsHead; +static SymbolPtr gSymbolsHead = NULL; //========================================================================== // NewSymbol @@ -1147,11 +1152,11 @@ symbol = FindSymbol(string, 0); // Add the new symbol. - if (symbol == 0) + if (symbol == NULL) { symbol = (SymbolPtr)malloc(sizeof(Symbol) + 1 + strlen(string)); - if (symbol == 0) - { //return 0; + if (symbol == NULL) + { stop("NULL symbol!"); } @@ -1182,11 +1187,11 @@ static void FreeSymbol( char *string ) { SymbolPtr symbol, prev; - prev = 0; + prev = NULL; // Look for string in the list of symbols. symbol = FindSymbol(string, &prev); - if (symbol == 0) + if (symbol == NULL) { return; } @@ -1200,7 +1205,7 @@ } // Remove the symbol from the list. - if (prev != 0) + if (prev != NULL) { prev->next = symbol->next; } @@ -1221,8 +1226,13 @@ { SymbolPtr symbol, prev; + if (string == NULL) + { + return NULL; + } + symbol = gSymbolsHead; - prev = 0; + prev = NULL; while (symbol != NULL) { @@ -1235,7 +1245,7 @@ symbol = symbol->next; } - if ((symbol != 0) && (prevSymbol != 0)) + if ((symbol != NULL) && (prevSymbol != NULL)) { *prevSymbol = prev; }