yaz_poll: Allow num_fds == 0
[yaz-moved-to-github.git] / src / odr.c
index beb2986..49c7753 100644 (file)
--- a/src/odr.c
+++ b/src/odr.c
@@ -1,9 +1,6 @@
-/*
- * Copyright (C) 1995-2007, Index Data ApS
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2012 Index Data
  * See the file LICENSE for details.
- *
- * $Id: odr.c,v 1.16 2007-03-19 21:08:13 adam Exp $
- *
  */
 
 /**
 #include <yaz/snprintf.h>
 #include "odr-priv.h"
 
-static int log_level=0;
-static int log_level_initialized=0;
+static int log_level = 0;
+static int log_level_initialized = 0;
 
 Odr_null *ODR_NULLVAL = (Odr_null *) "NULL";  /* the presence of a null value */
 
-Odr_null *odr_nullval (void)
+Odr_null *odr_nullval(void)
 {
     return ODR_NULLVAL;
 }
@@ -147,10 +144,10 @@ void odr_FILE_write(ODR o, void *handle, int type,
         fputs("\n", (FILE*) handle);
     }
 #endif
-    for (i = 0; i<len; i++)
+    for (i = 0; i < len; i++)
     {
         unsigned c = ((const unsigned char *) buf)[i];
-        if (i == 2000 && len > 3100)
+        if (i == 20000 && len > 31000)
         {
             fputs(" ..... ", (FILE*) handle);
                 i = len - 1000;
@@ -178,6 +175,7 @@ void odr_setprint(ODR o, FILE *file)
     odr_set_stream(o, file, odr_FILE_write, odr_FILE_close);
 }
 
+
 void odr_set_stream(ODR o, void *handle,
                     void (*stream_write)(ODR o, 
                                          void *handle, int type,
@@ -196,7 +194,7 @@ int odr_set_charset(ODR o, const char *to, const char *from)
     o->op->iconv_handle = 0;
     if (to && from)
     {
-        o->op->iconv_handle = yaz_iconv_open (to, from);
+        o->op->iconv_handle = yaz_iconv_open(to, from);
         if (o->op->iconv_handle == 0)
             return -1;
     }
@@ -209,13 +207,13 @@ ODR odr_createmem(int direction)
     ODR o;
     if (!log_level_initialized)
     {
-        log_level=yaz_log_module_level("odr");
-        log_level_initialized=1;
+        log_level = yaz_log_module_level("odr");
+        log_level_initialized = 1;
     }
 
-    if (!(o = (ODR)xmalloc(sizeof(*o))))
+    if (!(o = (ODR) xmalloc(sizeof(*o))))
         return 0;
-    o->op = (struct Odr_private *) xmalloc (sizeof(*o->op));
+    o->op = (struct Odr_private *) xmalloc(sizeof(*o->op));
     o->direction = direction;
     o->buf = 0;
     o->size = o->pos = o->top = 0;
@@ -226,7 +224,7 @@ ODR odr_createmem(int direction)
     o->op->iconv_handle = 0;
     odr_setprint(o, stderr);
     odr_reset(o);
-    yaz_log (log_level, "odr_createmem dir=%d o=%p", direction, o);
+    yaz_log(log_level, "odr_createmem dir=%d o=%p", direction, o);
     return o;
 }
 
@@ -234,8 +232,8 @@ void odr_reset(ODR o)
 {
     if (!log_level_initialized)
     {
-        log_level=yaz_log_module_level("odr");
-        log_level_initialized=1;
+        log_level = yaz_log_module_level("odr");
+        log_level_initialized = 1;
     }
 
     odr_seterror(o, ONONE, 0);
@@ -254,7 +252,7 @@ void odr_reset(ODR o)
     o->op->lenlen = 1;
     if (o->op->iconv_handle != 0)
         yaz_iconv(o->op->iconv_handle, 0, 0, 0, 0);
-    yaz_log (log_level, "odr_reset o=%p", o);
+    yaz_log(log_level, "odr_reset o=%p", o);
 }
     
 void odr_destroy(ODR o)
@@ -265,17 +263,16 @@ void odr_destroy(ODR o)
     if (o->op->stream_close)
         o->op->stream_close(o->op->print);
     if (o->op->iconv_handle != 0)
-        yaz_iconv_close (o->op->iconv_handle);
+        yaz_iconv_close(o->op->iconv_handle);
     xfree(o->op);
     xfree(o);
-    yaz_log (log_level, "odr_destroy o=%p", o);
+    yaz_log(log_level, "odr_destroy o=%p", o);
 }
 
 void odr_setbuf(ODR o, char *buf, int len, int can_grow)
 {
     odr_seterror(o, ONONE, 0);
     o->bp = (unsigned char *) buf;
-
     o->buf = (unsigned char *) buf;
     o->op->can_grow = can_grow;
     o->top = o->pos = 0;
@@ -303,6 +300,7 @@ void odr_printf(ODR o, const char *fmt, ...)
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab