diff options
| author | Matthew Parlane <parlane@gmail.com> | 2009-09-21 11:10:38 +1200 |
|---|---|---|
| committer | Matthew Parlane <parlane@gmail.com> | 2009-09-21 11:10:38 +1200 |
| commit | 3af6f9431232ced52faabb1a0019ff968d9483af (patch) | |
| tree | ae44d2f51802c6bc24b24b8367d416c5f411b0ff /xml.c | |
| parent | 5aa5f3d835fd5d5ab5eded056175ad2c34cfbab4 (diff) | |
| parent | 30d7029aa7e0da4f85284bb0e2a017823f53f842 (diff) | |
Merge branch 'master' of github.com:SquidMan/benzin
Diffstat (limited to 'xml.c')
| -rw-r--r-- | xml.c | 151 |
1 files changed, 78 insertions, 73 deletions
@@ -13,86 +13,91 @@ char xmlbuff[4096]; -char * /* O - Buffer */ -get_value(mxml_node_t *node, /* I - Node to get */ - void *buffer, /* I - Buffer */ - int buflen) /* I - Size of buffer */ +char * /* O - Buffer */ +get_value(mxml_node_t *node, /* I - Node to get */ + void *buffer, /* I - Buffer */ + int buflen) /* I - Size of buffer */ { - char *ptr, /* Pointer into buffer */ - *end; /* End of buffer */ - int len; /* Length of node */ - mxml_node_t *current; /* Current node */ + char *ptr, /* Pointer into buffer */ + *end; /* End of buffer */ + int len; /* Length of node */ + mxml_node_t *current; /* Current node */ - ptr = (char*)buffer; - end = (char*)buffer + buflen - 1; - char tempbuf[4092]; - current = node->child; - for (current = node->child; current && ptr < end; current = current->next) - { - if (current->type == MXML_TEXT) - { - if (current->value.text.whitespace) - *ptr++ = ' '; - - len = (int)strlen(current->value.text.string); - if (len > (int)(end - ptr)) - len = (int)(end - ptr); - - memcpy(ptr, current->value.text.string, len); - ptr += len; - } - else if (current->type == MXML_OPAQUE) - { - len = (int)strlen(current->value.opaque); - if (len > (int)(end - ptr)) - len = (int)(end - ptr); - - memcpy(ptr, current->value.opaque, len); - ptr += len; - } - else if (current->type == MXML_INTEGER) - { - sprintf(tempbuf, "%d", current->value.integer); - len = (int)strlen(tempbuf); - if (len > (int)(end - ptr)) - len = (int)(end - ptr); - - memcpy(ptr, tempbuf, len); - ptr += len; - } - else if (current->type == MXML_REAL) - { - sprintf(tempbuf, "%f", current->value.real); - len = (int)strlen(tempbuf); - if (len > (int)(end - ptr)) - len = (int)(end - ptr); + ptr = (char*)buffer; + end = (char*)buffer + buflen - 1; + char tempbuf[4092]; + current = node->child; + for (current = node->child; current && ptr < end; current = current->next) + { + if (current->type == MXML_TEXT) + { + if (current->value.text.whitespace) + *ptr++ = ' '; + + len = (int)strlen(current->value.text.string); + if (len > (int)(end - ptr)) + len = (int)(end - ptr); + + memcpy(ptr, current->value.text.string, len); + ptr += len; + } + else if (current->type == MXML_OPAQUE) + { + len = (int)strlen(current->value.opaque); + if (len > (int)(end - ptr)) + len = (int)(end - ptr); + + memcpy(ptr, current->value.opaque, len); + ptr += len; + } + else if (current->type == MXML_INTEGER) + { + sprintf(tempbuf, "%d", current->value.integer); + len = (int)strlen(tempbuf); + if (len > (int)(end - ptr)) + len = (int)(end - ptr); + + memcpy(ptr, tempbuf, len); + ptr += len; + } + else if (current->type == MXML_REAL) + { + sprintf(tempbuf, "%f", current->value.real); + len = (int)strlen(tempbuf); + if (len > (int)(end - ptr)) + len = (int)(end - ptr); - memcpy(ptr, tempbuf, len); - ptr += len; - } - } - *ptr = 0; - return buffer; + memcpy(ptr, tempbuf, len); + ptr += len; + } + } + *ptr = 0; + return buffer; } const char *whitespace_cb(mxml_node_t *node, int where) { - /* code by Matt_P */ - const char *name = node->value.element.name; - mxml_node_t * temp = node; - int depth = 0; - while(temp){ - depth++; - temp = temp->parent; - } - if (where == 3 || where == 1){ - return ""; - }else if(((node->prev && where == 0) || node->parent) && !(where == 2 && strncmp(name, "ua", 2) && strcmp(name, "flip") && strcmp(name, "zoom") && strcmp(name, "coords") && strcmp(name, "entries") && strcmp(name, "xmlyt") && strcmp(name, "xmlan") && strcmp(name, "entries") && strcmp(name, "triplet") && strcmp(name, "pair") && strcmp(name, "entry") && strcmp(name, "pane") && (strcmp(name, "tag") && strcmp(name, "size") && strcmp(name, "material") && strcmp(name, "colors") && strcmp(name, "subs") && strcmp(name, "font") && strcmp(name, "wnd4") && strcmp(name, "wnd4mat") && strcmp(name, "set") && strcmp(name, "coordinates"))) ){ - sprintf(xmlbuff, "\n%*s", (depth-1)*4, ""); - }else{ - return ""; - } - return xmlbuff; + /* code by Matt_P */ + const char *name = node->value.element.name; + mxml_node_t * temp = node; + char tab_buffer[25]; + memset( tab_buffer , 0 , 15 ); + int depth = 0; + while(temp){ + depth++; + tab_buffer[depth - 1] = '\t'; + temp = temp->parent; + } + if (where == 3 || where == 1){ + return ""; + }else if(((node->prev && where == 0) || node->parent) && !(where == 2 && strncmp(name, "ua", 2) && strcmp(name, "rotate") && strcmp(name, "scale") && strcmp(name, "translate") && strcmp(name, "entries") && strcmp(name, "xmlyt") && strcmp(name, "xmlan") && strcmp(name, "entries") && strcmp(name, "triplet") && strcmp(name, "pair") && strcmp(name, "entry") && strcmp(name, "pane") && (strcmp(name, "tag") && strcmp(name, "size") && strcmp(name, "material") && strcmp(name, "vtx") && strcmp(name, "colors") && strcmp(name, "subs") && strcmp(name, "font") && strcmp(name, "wnd4") && strcmp(name, "wnd4mat") && strcmp(name, "set") && strcmp(name, "coordinates") && strcmp(name, "TevStage") && strcmp(name, "texture") && strcmp(name, "TextureSRT") && strcmp(name, "CoordGen") && strcmp(name, "ChanControl") && strcmp(name, "MaterialColor") && strcmp(name, "TevSwapModeTable") && strcmp(name, "IndTextureSRT") && strcmp(name, "IndTextureOrder") && strcmp(name, "AlphaCompare") && strcmp(name, "BlendMode") )) ){ + //sprintf(xmlbuff, "\n%*s", (depth-1)*4 , ""); + //sprintf(xmlbuff, "\n%*s", (depth)*4 , "\t"); + sprintf( xmlbuff , "\n%s" , tab_buffer ); + }else{ + return ""; + } + return xmlbuff; } |
