Basic configuration functionality in place (not yet used)
[pazpar2-moved-to-github.git] / src / pazpar2.c
index 2c4826f..8605397 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: pazpar2.c,v 1.4 2006-12-21 04:27:48 quinn Exp $ */;
+/* $Id: pazpar2.c,v 1.6 2006-12-27 21:11:10 quinn Exp $ */;
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -17,6 +17,7 @@
 #include <yaz/readconf.h>
 #include <yaz/pquery.h>
 #include <yaz/yaz-util.h>
+#include <yaz/nmem.h>
 
 #include "pazpar2.h"
 #include "eventl.h"
@@ -25,6 +26,7 @@
 #include "termlists.h"
 #include "reclists.h"
 #include "relevance.h"
+#include "config.h"
 
 #define PAZPAR2_VERSION "0.1"
 #define MAX_CHUNK 15
@@ -69,6 +71,7 @@ struct parameters global_parameters =
     0,
     0,
     0,
+    0,
     0
 };
 
@@ -675,6 +678,17 @@ static void ingest_records(struct client *cl, Z_Records *r)
         session_alert_watch(s, SESSION_WATCH_RECORDS);
 }
 
+xsltStylesheetPtr load_stylesheet(const char *fname)
+{
+    xsltStylesheetPtr ret;
+    if (!(ret = xsltParseStylesheetFile((const xmlChar *) fname)))
+    {
+        yaz_log(YLOG_FATAL|YLOG_ERRNO, "Failed to load stylesheet %s", fname);
+        exit(1);
+    }
+    return ret;
+}
+
 static void do_presentResponse(IOCHAN i, Z_APDU *a)
 {
     struct connection *co = iochan_getdata(i);
@@ -1261,6 +1275,9 @@ struct termlist_score **termlist(struct session *s, int *num)
     return termlist_highscore(s->termlist, num);
 }
 
+#ifdef REPORT_NMEM
+// conditional compilation by SH: This lead to a warning with currently installed
+// YAZ header files on us1
 void report_nmem_stats(void)
 {
     size_t in_use, is_free;
@@ -1271,6 +1288,7 @@ void report_nmem_stats(void)
     yaz_log(YLOG_LOG, "nmem stat: use=%ld free=%ld", 
             (long) in_use, (long) is_free);
 }
+#endif
 
 struct record **show(struct session *s, int start, int *num, int *total,
                      int *sumhits, NMEM nmem_show)
@@ -1355,9 +1373,13 @@ int main(int argc, char **argv)
 
     yaz_log_init(YLOG_DEFAULT_LEVEL, "pazpar2", 0);
 
-    while ((ret = options("c:h:p:C:s:", argv, argc, &arg)) != -2)
+    while ((ret = options("f:x:c:h:p:C:s:", argv, argc, &arg)) != -2)
     {
        switch (ret) {
+            case 'f':
+                if (!read_config(arg))
+                    exit(1);
+                break;
            case 'c':
                command_init(atoi(arg));
                 setport++;
@@ -1375,8 +1397,12 @@ int main(int argc, char **argv)
             case 's':
                 load_simpletargets(arg);
                 break;
+            case 'x':
+                global_parameters.xsl = load_stylesheet(arg);
+                break;
            default:
                fprintf(stderr, "Usage: pazpar2\n"
+                        "    -f configfile\n"
                         "    -h [host:]port          (REST protocol listener)\n"
                         "    -c cmdport              (telnet-style)\n"
                         "    -C cclconfig\n"
@@ -1392,7 +1418,9 @@ int main(int argc, char **argv)
         exit(1);
     }
 
-    global_parameters.ccl_filter = load_cclfile("default.bib");
+    if (!global_parameters.xsl)
+        global_parameters.xsl = load_stylesheet("../etc/default.xsl");
+    global_parameters.ccl_filter = load_cclfile("../etc/default.bib");
     global_parameters.yaz_marc = yaz_marc_create();
     yaz_marc_subfield_str(global_parameters.yaz_marc, "\t");
     global_parameters.odr_in = odr_createmem(ODR_DECODE);