Doxyfile file description. Indentation. No change of code.
[yaz-moved-to-github.git] / src / cclqfile.c
index b562bac..0684dc3 100644 (file)
  * USE OR PERFORMANCE OF THIS SOFTWARE.
  *
  */
+/** 
+ * \file cclqfile.c
+ * \brief Implements parsing of CCL qualifier specs in files
+ */
 /* CCL qualifiers
  * Europagate, 1995
  *
- * $Id: cclqfile.c,v 1.1 2003-10-27 12:21:30 adam Exp $
+ * $Id: cclqfile.c,v 1.6 2004-10-15 00:19:00 adam Exp $
  *
  * Old Europagate Log:
  *
@@ -132,6 +136,8 @@ void ccl_qual_field (CCL_bibset bibset, const char *cp, const char *qual_name)
                 type = CCL_BIB1_REL;
                 if (!ccl_stricmp (qual_value, "o"))
                     value = CCL_BIB1_REL_ORDER;
+                else if (!ccl_stricmp (qual_value, "r"))
+                    value = CCL_BIB1_REL_PORDER;
                 break;                
             case 'p':
             case 'P':
@@ -186,7 +192,7 @@ void ccl_qual_field (CCL_bibset bibset, const char *cp, const char *qual_name)
                    len = split - qual_value;
                else
                    len = strlen(qual_value);
-               svalue_ar[pair_no] = xmalloc(len+1);
+               svalue_ar[pair_no] = (char *) xmalloc(len+1);
                memcpy(svalue_ar[pair_no], qual_value, len);
                svalue_ar[pair_no][len] = '\0';
            }
@@ -214,6 +220,48 @@ void ccl_qual_fitem (CCL_bibset bibset, const char *cp, const char *qual_name)
        ccl_qual_field(bibset, cp, qual_name);
 }
 
+void ccl_qual_buf(CCL_bibset bibset, const char *buf)
+{
+    const char *cp1 = buf;
+    char line[256];
+    while (1)
+    {
+       const char *cp2 = cp1;
+       int len;
+       while (*cp2 && !strchr("\r\n", *cp2))
+           cp2++;
+       len = cp2 - cp1;
+       if (len > 0)
+       {
+           if (len >= (sizeof(line)-1))
+               len = sizeof(line)-1;
+           memcpy(line, cp1, len);
+           line[len] = '\0';
+           ccl_qual_line(bibset, line);
+       }
+       if (!*cp2)
+           break;
+       cp1 = cp2+1;
+    }
+}
+
+void ccl_qual_line(CCL_bibset bibset, char *line)
+{
+    int  no_scan = 0;
+    char qual_name[128];
+    char *cp1, *cp = line;
+    
+    if (*cp == '#')
+       return;        /* ignore lines starting with # */
+    if (sscanf (cp, "%100s%n", qual_name, &no_scan) < 1)
+       return;        /* also ignore empty lines */
+    cp += no_scan;
+    cp1 = strchr(cp, '#');
+    if (cp1)
+       *cp1 = '\0';
+    ccl_qual_fitem (bibset, cp, qual_name);
+}
+
 /*
  * ccl_qual_file: Read bibset definition from file.
  * bibset:  Bibset
@@ -230,24 +278,9 @@ void ccl_qual_fitem (CCL_bibset bibset, const char *cp, const char *qual_name)
 void ccl_qual_file (CCL_bibset bibset, FILE *inf)
 {
     char line[256];
-    char *cp, *cp1;
-    char qual_name[128];
 
     while (fgets (line, 255, inf))
-    {
-        int  no_scan = 0;
-
-        cp = line;
-        if (*cp == '#')
-            continue;        /* ignore lines starting with # */
-        if (sscanf (cp, "%100s%n", qual_name, &no_scan) < 1)
-            continue;        /* also ignore empty lines */
-        cp += no_scan;
-       cp1 = strchr(cp, '#');
-       if (cp1)
-           *cp1 = '\0';
-        ccl_qual_fitem (bibset, cp, qual_name);
-    }
+       ccl_qual_line(bibset, line);
 }
 
 int ccl_qual_fname (CCL_bibset bibset, const char *fname)