Reindent - including tabs -> spaces.
[yaz-moved-to-github.git] / src / marc_read_xml.c
index 3f3e05b..f448b5b 100644 (file)
@@ -90,30 +90,33 @@ int yaz_marc_read_xml_subfields(yaz_marc_t mt, const xmlNode *ptr)
     return 0;
 }
 
-const char *tag_value_extract(const char *name, char tag_buffer[5]) {
-       size_t length = strlen(name);
-       if (length == 3) {
-               strcpy(tag_buffer, name);
-               return tag_buffer;
-       }
-       return 0;
+const char *tag_value_extract(const char *name, char tag_buffer[5])
+{
+    size_t length = strlen(name);
+    if (length == 3)
+    {
+        strcpy(tag_buffer, name);
+        return tag_buffer;
+    }
+    return 0;
 }
 
 // Given a xmlNode ptr,  extract a value from either a element name or from a given attribute
-const char *element_attribute_value_extract(const xmlNode *ptr, const char *attribute_name, NMEM nmem) {
+const char *element_attribute_value_extract(const xmlNode *ptr,
+                                            const char *attribute_name,
+                                            NMEM nmem)
+{
 
-       const char *name = ptr->name;
-       size_t length = strlen(name);
-       if (length > 1 ) {
-               return nmem_strdup(nmem, name+1);
-       }
-       // TODO Extract from attribute where matches attribute_name
-       xmlAttr *attr;
+    const char *name = ptr->name;
+    size_t length = strlen(name);
+    if (length > 1 )
+        return nmem_strdup(nmem, name+1);
+    // TODO Extract from attribute where matches attribute_name
+    xmlAttr *attr;
     for (attr = ptr->properties; attr; attr = attr->next)
-        if (!strcmp((const char *)attr->name, attribute_name)) {
-               return nmem_text_node_cdata(attr->children, nmem);
-        }
-       return 0;
+        if (!strcmp((const char *)attr->name, attribute_name))
+            return nmem_text_node_cdata(attr->children, nmem);
+    return 0;
 }
 
 
@@ -124,12 +127,12 @@ int yaz_marc_read_turbo_xml_subfields(yaz_marc_t mt, const xmlNode *ptr)
     {
         if (ptr->type == XML_ELEMENT_NODE)
         {
-               xmlNode *p;
+            xmlNode *p;
             if (!strncmp((const char *) ptr->name, "s", 1))
             {
-                       NMEM nmem = yaz_marc_get_nmem(mt);
-                       char *buffer = (char *) nmem_malloc(nmem, 5);
-                               const char *tag_value = element_attribute_value_extract(ptr, "code", nmem);
+                NMEM nmem = yaz_marc_get_nmem(mt);
+                char *buffer = (char *) nmem_malloc(nmem, 5);
+                const char *tag_value = element_attribute_value_extract(ptr, "code", nmem);
                 if (!tag_value)
                 {
                     yaz_marc_cprintf(
@@ -139,13 +142,13 @@ int yaz_marc_read_turbo_xml_subfields(yaz_marc_t mt, const xmlNode *ptr)
 
                size_t ctrl_data_len = 0;
                 char *ctrl_data_buf = 0;
-                               ctrl_data_len = strlen((const char *) tag_value);
-                               // Extract (length) from CDATA
-                               xmlNode *p;
-                               for (p = ptr->children; p ; p = p->next)
+                ctrl_data_len = strlen((const char *) tag_value);
+                // Extract (length) from CDATA
+                xmlNode *p;
+                for (p = ptr->children; p ; p = p->next)
                     if (p->type == XML_TEXT_NODE)
                         ctrl_data_len += strlen((const char *)p->content);
-                               // Allocate memory for code value (1 character (can be multi-byte) and data
+                // Allocate memory for code value (1 character (can be multi-byte) and data
                 ctrl_data_buf = (char *) nmem_malloc(nmem, ctrl_data_len+1);
                 // Build a string with "<Code><data>"
                 strcpy(ctrl_data_buf, (const char *) tag_value);
@@ -180,8 +183,8 @@ static int yaz_marc_read_xml_leader(yaz_marc_t mt, const xmlNode **ptr_p)
     for(; ptr; ptr = ptr->next)
         if (ptr->type == XML_ELEMENT_NODE)
         {
-               if ( !strcmp( (const char *) ptr->name, "leader") ||
-                       (!strncmp((const char *) ptr->name, "l", 1) ))
+            if ( !strcmp( (const char *) ptr->name, "leader") ||
+                 (!strncmp((const char *) ptr->name, "l", 1) ))
             {
                 xmlNode *p = ptr->children;
                 for(; p; p = p->next)
@@ -222,7 +225,7 @@ static int yaz_marc_read_xml_fields(yaz_marc_t mt, const xmlNode *ptr)
     for(; ptr; ptr = ptr->next)
         if (ptr->type == XML_ELEMENT_NODE)
         {
-               if (!strcmp( (const char *) ptr->name, "controlfield"))
+            if (!strcmp( (const char *) ptr->name, "controlfield"))
             {
                 const xmlNode *ptr_tag = 0;
                 struct _xmlAttr *attr;
@@ -300,10 +303,10 @@ static int yaz_marc_read_turbo_xml_fields(yaz_marc_t mt, const xmlNode *ptr)
     for(; ptr; ptr = ptr->next)
         if (ptr->type == XML_ELEMENT_NODE)
         {
-               if (!strncmp( (const char *) ptr->name, "c", 1))
+            if (!strncmp( (const char *) ptr->name, "c", 1))
             {
-                       NMEM nmem = yaz_marc_get_nmem(mt);
-                       const char *tag_value = element_attribute_value_extract(ptr, "tag", nmem);
+                NMEM nmem = yaz_marc_get_nmem(mt);
+                const char *tag_value = element_attribute_value_extract(ptr, "tag", nmem);
                 if (!tag_value)
                 {
                     yaz_marc_cprintf(
@@ -315,21 +318,21 @@ static int yaz_marc_read_turbo_xml_fields(yaz_marc_t mt, const xmlNode *ptr)
             else if (!strncmp((const char *) ptr->name, "d",1))
             {
                 struct _xmlAttr *attr;
-                       NMEM nmem = yaz_marc_get_nmem(mt);
+                NMEM nmem = yaz_marc_get_nmem(mt);
                 char *indstr = nmem_malloc(nmem, 11);  /* 0(unused), 1,....9, + zero term */
                 int index = 0;
                 for (index = 0; index < 11; index++)
-                                       indstr[index] = '\0';
-                       const char *tag_value = element_attribute_value_extract(ptr, "tag", nmem);
+                    indstr[index] = '\0';
+                const char *tag_value = element_attribute_value_extract(ptr, "tag", nmem);
                 if (!tag_value)
-                               {
+                {
                     yaz_marc_cprintf(
                         mt, "Missing attribute 'tag' for 'datafield'" );
                     return -1;
                 }
                 for (attr = ptr->properties; attr; attr = attr->next)
                     if (strlen((const char *)attr->name) == 2 &&
-                             attr->name[0] == 'i')
+                        attr->name[0] == 'i')
                     {
                        //extract indicator attribute from i#="Y" pattern
                         int no = atoi((const char *)attr->name+1);
@@ -371,12 +374,14 @@ int yaz_marc_read_xml(yaz_marc_t mt, const xmlNode *ptr)
     for(; ptr; ptr = ptr->next)
         if (ptr->type == XML_ELEMENT_NODE)
         {
-                       //TODO Should actually look at the namespace but...
-            if (!strcmp((const char *) ptr->name, "record")) {
+            //TODO Should actually look at the namespace but...
+            if (!strcmp((const char *) ptr->name, "record"))
+            {
                yaz_marc_set_read_format(mt, YAZ_MARC_MARCXML);
                 break;
             }
-            else if (!strcmp((const char *) ptr->name, "r")) {
+            else if (!strcmp((const char *) ptr->name, "r"))
+            {
                yaz_marc_set_read_format(mt, YAZ_MARC_TMARCXML);
                 break;
             }
@@ -397,13 +402,14 @@ int yaz_marc_read_xml(yaz_marc_t mt, const xmlNode *ptr)
     if (yaz_marc_read_xml_leader(mt, &ptr))
         return -1;
 
-    switch (yaz_marc_get_read_format(mt)) {
-               case YAZ_MARC_MARCXML:
-                       return yaz_marc_read_xml_fields(mt, ptr->next);
-               case YAZ_MARC_TMARCXML:
-                       return yaz_marc_read_turbo_xml_fields(mt, ptr->next);
+    switch (yaz_marc_get_read_format(mt))
+    {
+    case YAZ_MARC_MARCXML:
+        return yaz_marc_read_xml_fields(mt, ptr->next);
+    case YAZ_MARC_TMARCXML:
+        return yaz_marc_read_turbo_xml_fields(mt, ptr->next);
     }
-       return -1;
+    return -1;
 }
 #endif