Update of /cvsroot/monetdb/pathfinder/compiler
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv30675

Modified Files:
        compile.c main.c main_opt.c main_sql.c oops.c qname.c timer.c 
        variable.c win32_getopt.c 
Log Message:
-- The endless Odyssey through the pathfinder code checking
   for correct initialization of global variables (Part 1).

   Today---checking all files in folders:
    o compiler (no subfolders)
    o compiler/xmlimport


U qname.c
Index: qname.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/qname.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- qname.c     17 Mar 2008 17:41:05 -0000      1.18
+++ qname.c     2 Apr 2008 16:13:44 -0000       1.19
@@ -16,7 +16,7 @@
  *    #PFqname_raw_t entries into #PFqname_t entries.  #PFqname_t
  *    is actually just an integer.  The full QName information (prefix,
  *    URI, and local name) are held in the array #qnames located in
- *    this file (and only visible here).  The #PFqname_t integer is 
+ *    this file (and only visible here).  The #PFqname_t integer is
  *    an index into this array.
  *
  * To operate on #PFqname_raw_t types, use the PFqname_raw... functions
@@ -273,7 +273,7 @@
         else
             /* otherwise no prefix to print */
             ns = PFstrdup ("");
-    
+
     s = (char *) PFmalloc (strlen (ns) + (qn.loc ? strlen (qn.loc) : 1) + 1);
 
     sprintf (s, "%s%s", ns, qn.loc ? qn.loc : "*");
@@ -296,7 +296,7 @@
     qname_internal_t qn
         = *((qname_internal_t *) PFarray_at (qnames, q));
 
-    s = (char *) PFmalloc ((qn.ns.uri ? strlen (qn.ns.uri) + 1 : 0) 
+    s = (char *) PFmalloc ((qn.ns.uri ? strlen (qn.ns.uri) + 1 : 0)
                            + strlen (qn.loc) + 1);
 
     return strcat (qn.ns.uri ? strcat (strcpy (s, qn.ns.uri), ":") : s,
@@ -400,7 +400,7 @@
     else {
         /* QName = loc */
         qn.prefix = PFstrdup ("");
-        qn.loc    = nsloc; 
+        qn.loc    = nsloc;
     }
 
     /*
@@ -469,7 +469,7 @@
         else
             /* otherwise no prefix to print */
             ns = PFstrdup ("");
-    
+
     s = (char *) PFmalloc (strlen (ns) + (q.loc ? strlen (q.loc) : 1) + 1);
 
     sprintf (s, "%s%s", ns, q.loc ? q.loc : "*");

U timer.c
Index: timer.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/timer.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- timer.c     11 Jan 2008 10:46:56 -0000      1.14
+++ timer.c     2 Apr 2008 16:13:44 -0000       1.15
@@ -61,6 +61,8 @@
 #include <windows.h>
 #endif
 
+#include "mem.h"
+
 static long
 PFgettime (void)
 {
@@ -72,16 +74,16 @@
             (long) st.wMilliseconds) * 1000;
 #else
 #ifdef HAVE_GETTIMEOFDAY
-       struct timeval tp;
+        struct timeval tp;
 
-       gettimeofday(&tp, NULL);
-       return (long) tp.tv_sec * 1000000 + (long) tp.tv_usec;
+        gettimeofday(&tp, NULL);
+        return (long) tp.tv_sec * 1000000 + (long) tp.tv_usec;
 #else
 #ifdef HAVE_FTIME
-       struct timeb tb;
+        struct timeb tb;
 
-       ftime(&tb);
-       return (long) tb.time * 1000000 + (long) tb.millitm * 1000;
+        ftime(&tb);
+        return (long) tb.time * 1000000 + (long) tb.millitm * 1000;
 #endif
 #endif
 #endif
@@ -96,9 +98,9 @@
  *
  * @return timer value to be passed to PFtimer_stop ()
  */
-long 
+long
 PFtimer_start (void)
-{ 
+{
     return PFgettime();
 }
 
@@ -131,21 +133,22 @@
 char *
 PFtimer_str (long elapsed)
 {
-    static char tm[sizeof ("000h 00m 00s 000ms")] = "";
+    char *tm = PFmalloc (sizeof (char) * (sizeof ("000h 00m 00s 000ms") + 1));
     char *str;
 
+    tm[0] = '\0';
     str = tm;
 
     if (elapsed / 3600000000UL) {
         str += sprintf (str, "%03luh ", elapsed / 3600000000UL);
         elapsed %= 3600000000UL;
     }
-  
+
     if (elapsed / 60000000UL) {
         str += sprintf (str, "%02lum ", elapsed / 60000000UL);
         elapsed %= 60000000UL;
     }
-  
+
     if (elapsed / 1000000UL) {
         str += sprintf (str, "%02lus ", elapsed / 1000000UL);
         elapsed %= 1000000UL;

U compile.c
Index: compile.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/compile.c,v
retrieving revision 1.144
retrieving revision 1.145
diff -u -d -r1.144 -r1.145
--- compile.c   19 Mar 2008 10:58:21 -0000      1.144
+++ compile.c   2 Apr 2008 16:13:41 -0000       1.145
@@ -187,9 +187,11 @@
     struct _urlcache_t *next;
     xmlParserInputBufferPtr  buf;
     char url[1];
-} urlcache_t; 
+} urlcache_t;
 
+/* NOTE: variable is re-used in subsequent pf runs (in server-side setup) */
 urlcache_t *urlcache = NULL;
+/* NOTE: variable is re-used in subsequent pf runs (in server-side setup) */
 int xrpc_port = 80;
 
 /**
@@ -200,7 +202,7 @@
     int         num_read = -1;
     urlcache_t *cache = urlcache;
     xmlParserInputBufferPtr  buf;
-    char *ret, url[1024];  
+    char *ret, url[1024];
 
     /* support for the xrpc://x.y.z/URI naming scheme (maps to 
http://x.y.z:<xrpc_port>/xrpc/URI) */
     if (strncmp(uri, "xrpc://", 7) == 0) {
@@ -222,10 +224,10 @@
 
     if (keep) {
         int len = strlen(url);
-       /* 
-        * URI that ends in .mil is converted into a .xq
-        */
-       if (len > 4 && url[len-4] == '.' && url[len-3] == 'm' && url[len-2] == 
'i' && url[len-1] == 'l') {
+        /*
+         * URI that ends in .mil is converted into a .xq
+         */
+        if (len > 4 && url[len-4] == '.' && url[len-3] == 'm' && url[len-2] == 
'i' && url[len-1] == 'l') {
             url[len-3] = 'x'; url[len-2] = 'q'; url[len-1] = 0;
         }
     }
@@ -234,8 +236,8 @@
      * first try the cache
      */
     while(cache) {
-        if (strcmp(cache->url, url) == 0) 
-           return (char*) cache->buf->buffer->content;
+        if (strcmp(cache->url, url) == 0)
+            return (char*) cache->buf->buffer->content;
         cache = cache->next;
     }
 
@@ -254,7 +256,7 @@
             /* empty */;
     }
     if (num_read < 0) {
-       if (buf) free(buf);
+        if (buf) free(buf);
         return NULL;
     }
     ret = (char*) buf->buffer->content;
@@ -269,7 +271,7 @@
         }
     } else {
         buf->buffer->content = NULL; /* otherwise it will be deleted */
-       xmlFreeParserInputBuffer (buf);
+        xmlFreeParserInputBuffer (buf);
     }
     return ret;
 }
@@ -280,16 +282,16 @@
 void PFurlcache_flush(void) {
     urlcache_t *cache = urlcache;
     while(cache) {
-       urlcache_t *del = cache;
+        urlcache_t *del = cache;
         cache = cache->next;
 
-       /* free resource allocated by libxml2 file reader */
-       xmlFreeParserInputBuffer (del->buf);
-       free(del);
+        /* free resource allocated by libxml2 file reader */
+        xmlFreeParserInputBuffer (del->buf);
+        free(del);
     }
     urlcache = NULL;
 }
-   
+
 
 /**
  * Compiler driver of the Pathfinder compiler,
@@ -299,18 +301,18 @@
 int
 PFcompile (char *url, FILE *pfout, PFstate_t *status)
 {
-    PFpnode_t  *proot  = NULL;
-    PFcnode_t  *croot  = NULL;
-    PFla_op_t  *laroot  = NULL;
-    PFpa_op_t  *paroot = NULL;
-    PFmil_t    *mroot  = NULL;
-    PFarray_t  *mil_program = NULL;
-    char       *xquery = NULL;
+    PFpnode_t *proot  = NULL;
+    PFcnode_t *croot  = NULL;
+    PFla_op_t *laroot  = NULL;
+    PFpa_op_t *paroot = NULL;
+    PFmil_t   *mroot  = NULL;
+    PFarray_t *mil_program = NULL;
+    char      *xquery = NULL;
     int        module_base;
-    
+
     /* elapsed time for compiler phase */
     long tm, tm_first = 0;
-   
+
     PFguide_tree_t *guide_tree = NULL; /* guide tree */
 
     PFquery_t PFquery = {
@@ -327,11 +329,11 @@
     /* setup sementation fault signal handler */
     signal (SIGSEGV, segfault_handler);
 #endif
-    
+
 #ifndef NDEBUG
     PFarray_init ();
 #endif
-    
+
     /*******************************************/
     /* Split Point: Logical Algebra XML Import */
     /*******************************************/
@@ -340,10 +342,10 @@
        /* todo: init-stuff */
        /* e.g. qnameInit */
        /* e.g namespaceInit */
-            
+
         XML2LALGContext *ctx = PFxml2la_xml2lalgContext();
         PFla_op_t       *rootOp;
-        
+
         /* Initialize data structures in the Namespace department */
         PFns_init ();
 
@@ -368,10 +370,10 @@
         }
         else {
             /**
-             * Note, that we don't get explicit error-positions (line 
-             * numbers of the xml-input) from the parser in case of 
-             * validation errors... 
-             * 
+             * Note, that we don't get explicit error-positions (line
+             * numbers of the xml-input) from the parser in case of
+             * validation errors...
+             *
              * Call PF from the command line with an explicit filename
              * (instead of using stdin/pipelining) if you want to get
              * explicit error positions (line numbers) from the xml-parser
@@ -384,10 +386,10 @@
 
         laroot = rootOp;
 
-        goto AFTER_CORE2ALG; 
+        goto AFTER_CORE2ALG;
     }
 
-    /* compiler chain below 
+    /* compiler chain below
      */
     xquery = PFurlcache (url, 1);
 
@@ -397,12 +399,12 @@
     tm_first = tm = PFtimer_start ();
     (void) PFparse (xquery, &proot, &PFquery, status->standoff_axis_steps);
     tm = PFtimer_stop (tm);
-    
+
     if (status->timing)
         PFlog ("parsing:\t\t\t\t %s", PFtimer_str (tm));
 
     STOP_POINT(1);
-    
+
     tm = PFtimer_start ();
     module_base = PFparse_modules (proot, &PFquery, 
status->standoff_axis_steps);
     tm = PFtimer_stop (tm);
@@ -411,10 +413,10 @@
         PFlog ("module import:\t\t\t\t %s", PFtimer_str (tm));
 
     STOP_POINT(2);
-    
+
     tm = PFtimer_start ();
 
-    /* Abstract syntax tree normalization 
+    /* Abstract syntax tree normalization
      */
     proot = PFnormalize_abssyn (proot);
 
@@ -435,7 +437,7 @@
     }
 
     STOP_POINT(3);
-    
+
     /* Initialize data structures in the Namespace department */
     PFns_init ();
 
@@ -457,7 +459,7 @@
      *       to change the value further down.
      */
     STOP_POINT(4);
- 
+
     /*
      * Extract option declarations from the abstract syntax tree
      * and read them into a mapping table.  This table may then be
@@ -470,7 +472,7 @@
 
     /* create guide tree */
     guide_tree =  PFguide_tree ();
-  
+
     STOP_POINT(6);
 
     /* Check variable scoping and replace QNames by PFvar_t pointers */
@@ -483,7 +485,7 @@
 
     STOP_POINT(8);
 
-    /* Resolve function usage 
+    /* Resolve function usage
      */
     PFfun_check (proot);
 
@@ -497,7 +499,7 @@
 
     /* Load XML Schema/XQuery predefined types into the type environment */
     PFty_predefined ();
-    
+
     STOP_POINT(10);
 
     /* XML Schema import */
@@ -543,7 +545,7 @@
 
     /* Type inference and check */
     tm = PFtimer_start ();
-  
+
     croot = PFty_check (croot);
 
     tm = PFtimer_stop (tm);
@@ -554,7 +556,7 @@
 
     /* Core tree optimization */
     tm = PFtimer_start ();
-  
+
     croot = PFcoreopt (croot);
 
     tm = PFtimer_stop (tm);
@@ -570,7 +572,7 @@
     if (status->output_format == PFoutput_format_milprint_summer) {
         char *prologue = NULL, *query = NULL, *epilogue = NULL;
         tm = PFtimer_start ();
-        if (PFprintMILtemp (croot, status->optimize, module_base, -1, 
tm_first, 
+        if (PFprintMILtemp (croot, status->optimize, module_base, -1, tm_first,
                             &prologue, &query, &epilogue, url, 
status->standoff_axis_steps))
             goto failure;
         fputs(prologue, pfout);
@@ -607,7 +609,7 @@
      * Rewrite/optimize algebra tree
      */
     tm = PFtimer_start ();
- 
+
     laroot = PFalgopt (laroot, status->timing, guide_tree, status->opt_alg);
 
     tm = PFtimer_stop (tm);
@@ -617,7 +619,7 @@
 
     STOP_POINT(17);
 
-    /* 
+    /*
      * common subexpression elimination in the algebra tree
      */
     tm = PFtimer_start ();
@@ -641,7 +643,7 @@
         tm = PFtimer_stop (tm);
         if (status->timing)
             PFlog ("Compilation to SQL:\t\t\t %s", PFtimer_str (tm));
-        
+
         STOP_POINT(19);
 
         if (status->dead_code_el) {
@@ -654,7 +656,7 @@
         }
 
         STOP_POINT(20);
-        
+
         /* serialize the internal SQL query tree */
         tm = PFtimer_start ();
         PFsql_print (pfout, sqlroot);
@@ -716,12 +718,12 @@
                                PFmil_var (
                                    PF_MIL_VAR_TIME_PRINT)));
     }
-    
+
     if (status->dead_code_el) {
         tm = PFtimer_start ();
 
         mroot = PFmil_dce (mroot);
-   
+
         tm = PFtimer_stop (tm);
         if (status->timing)
             PFlog ("dead code elimination:\t\t\t %s", PFtimer_str (tm));
@@ -729,7 +731,7 @@
 
     STOP_POINT(21);
 
-    /* Render MIL program in Monet MIL syntax 
+    /* Render MIL program in Monet MIL syntax
      */
     tm = PFtimer_start ();
     mil_program = PFmil_serialize (mroot);
@@ -835,21 +837,21 @@
 
 /**
  * Compiler driver of the Pathfinder compiler interface for usage
- * by the Monet Runtime environment. 
- * 
- * MonetDB actually would like pathfinder to 
- * - be thread-safe (now there are global vars all over the place) 
+ * by the Monet Runtime environment.
+ *
+ * MonetDB actually would like pathfinder to
+ * - be thread-safe (now there are global vars all over the place)
  * - use string input/output rather than files.
  *
  * This interface fixes the second issue. For the moment, the MonetDB
- * Runtime environment uses a lock to stay stable under concurrent requests. 
+ * Runtime environment uses a lock to stay stable under concurrent requests.
  */
 char*
 PFcompile_MonetDB (char *xquery, char* url, char** prologue, char** query, 
char** epilogue, int options)
 {
-        PFstate_t PFstate; 
-       PFpnode_t  *proot  = NULL;
-       PFcnode_t  *croot  = NULL;
+        PFstate_t PFstate;
+        PFpnode_t  *proot  = NULL;
+        PFcnode_t  *croot  = NULL;
         int num_fun;
         long timing;
         int module_base;
@@ -889,7 +891,7 @@
                 PFstate.output_format = PFoutput_format_milprint_summer;
         }
 
-        /* the state of the standoff_axis_steps support should be 
+        /* the state of the standoff_axis_steps support should be
          * passed through the function-arguments.
          */
         PFstate.standoff_axis_steps = (options & COMPILE_OPTION_STANDOFF);
@@ -922,14 +924,14 @@
         croot = PFfs (proot, &PFquery);
         croot = PFsimplify (croot);
         croot = PFty_check (croot);
-       croot = PFcoreopt (croot);
+        croot = PFcoreopt (croot);
 
     if (PFstate.output_format == PFoutput_format_milprint_summer) {
-        (void)  PFprintMILtemp (croot, 1, module_base, num_fun, timing, 
+        (void)  PFprintMILtemp (croot, 1, module_base, num_fun, timing,
                                 &intern_prologue, &intern_query, 
&intern_epilogue,
                                 url, PFstate.standoff_axis_steps);
 
-        /* make sure that we do NOT use memory that lies 
+        /* make sure that we do NOT use memory that lies
            in the pathfinder heap -- MonetDB will use (and free) it */
         *prologue = malloc (strlen (intern_prologue) + 1);
         *query    = malloc (strlen (intern_query) + 1);
@@ -942,7 +944,7 @@
         laroot = PFcore2alg (croot, &PFquery,
                              PFstate.output_format);
         /* optimize logical algebra */
-        laroot = PFalgopt (laroot, false /* no timing output */, 
+        laroot = PFalgopt (laroot, false /* no timing output */,
             NULL /* no guide tree */, PFstate.opt_alg);
         /* common subexpression elimination on logical algebra */
         laroot = PFla_cse (laroot);

U oops.c
Index: oops.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/oops.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- oops.c      25 Feb 2008 15:37:03 -0000      1.29
+++ oops.c      2 Apr 2008 16:13:44 -0000       1.30
@@ -81,12 +81,18 @@
 };
 
 /**
- * global buffer for collecting all errors 
+ * global buffer for collecting all errors
+ * (made visible to the outside world in include/compile_interface.h)
+ *
+ * NOTE: variable is re-used in subsequent pf runs (in server-side setup)
  */
 char *PFerrbuf = NULL;
 
 /**
  * global stack threshold to guard against too deep recursions
+ * (made visible to the outside world in include/oops.h)
+ *
+ * NOTE: variable is re-used in subsequent pf runs (in server-side setup)
  */
 char *PFmaxstack = NULL;
 
@@ -146,7 +152,7 @@
  * Does the work for #PFoops and #PFoops_loc.
  */
 void
-oops (PFrc_t rc, bool halt, 
+oops (PFrc_t rc, bool halt,
       const char *file, const char *func, const int line,
       const char *msg, va_list msgs)
 {
@@ -156,13 +162,13 @@
     mbuf = PFstrndup (oops_msg[-rc], OOPS_SIZE);
 
     if (msg) {
-       /* generate an error message of the form `<oops_msg>: <msg>' */
-       nmsg = strlen (oops_msg[-rc]);
-       mbuf[nmsg++] = ':';
-       mbuf[nmsg++] = ' ';
+        /* generate an error message of the form `<oops_msg>: <msg>' */
+        nmsg = strlen (oops_msg[-rc]);
+        mbuf[nmsg++] = ':';
+        mbuf[nmsg++] = ' ';
 
-       vsnprintf (mbuf + nmsg, OOPS_SIZE - nmsg, msg, msgs);
-       mbuf[OOPS_SIZE - 1] = 0;
+        vsnprintf (mbuf + nmsg, OOPS_SIZE - nmsg, msg, msgs);
+        mbuf[OOPS_SIZE - 1] = 0;
 
         oops_worker_call ("%s", mbuf);
     }
@@ -176,10 +182,10 @@
          */
         oops_worker_call ("# halted in %s (%s), line %d", file, func, line);
 #else
-       /* fool compilers that otherwise complain about unused parameters */
-       (void)file;
-       (void)func;
-       (void)line;
+        /* fool compilers that otherwise complain about unused parameters */
+        (void)file;
+        (void)func;
+        (void)line;
 #endif
         PFexit(-rc);
     }
@@ -187,14 +193,14 @@
 
 
 /**
- * Logs message code @a rc and message string @a msg, then halts 
+ * Logs message code @a rc and message string @a msg, then halts
  * the compiler.
  *
  * You are expected to call this function whenever you encounter a
  * failure or error condition you cannot handle locally: @a rc
  * describes the general kind of the error (see oops.h for known
  * error kinds OOPS_*), @a msg is meant to be a detailed description of
- * the failure (you may use `printf'-like formatting).  
+ * the failure (you may use `printf'-like formatting).
  *
  * NB. DOES NOT RETURN.
  *
@@ -206,7 +212,7 @@
  * @return Returns rc
  */
 void
-PFoops_ (PFrc_t rc, 
+PFoops_ (PFrc_t rc,
          const char *file, const char *func, const int line,
          const char *msg, ...)
 {
@@ -216,7 +222,7 @@
 
     /* does not return */
     oops (rc, true, file, func, line, msg, args);
-    
+
     PFexit(EXIT_FAILURE);
 }
 
@@ -225,7 +231,7 @@
  * as @a loc. The resulting string looks like "at (1,1-3,7): ...".
  */
 void
-PFoops_loc_ (PFrc_t rc, PFloc_t loc, 
+PFoops_loc_ (PFrc_t rc, PFloc_t loc,
              const char *file, const char *func, const int line,
              const char *msg, ...)
 {
@@ -258,7 +264,7 @@
     va_list args;
 
     va_start (args, msg);
-    oops (rc, false, 0, 0, 0, msg, args); 
+    oops (rc, false, 0, 0, 0, msg, args);
     va_end (args);
 }
 

U variable.c
Index: variable.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/variable.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- variable.c  11 Jan 2008 10:46:56 -0000      1.11
+++ variable.c  2 Apr 2008 16:13:48 -0000       1.12
@@ -56,7 +56,7 @@
  *     pointer to the original QName is stored in the new node. The
  *     QName may not be modified from outside after this function has
  *     been called.
- * @return Pointer to the new @c PFvar_t 
+ * @return Pointer to the new @c PFvar_t
  */
 PFvar_t *
 PFnew_var (PFqname_t varname)

U win32_getopt.c
Index: win32_getopt.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/win32_getopt.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- win32_getopt.c      7 Mar 2007 15:20:34 -0000       1.3
+++ win32_getopt.c      2 Apr 2008 16:13:48 -0000       1.4
@@ -9,10 +9,10 @@
  *  modify, merge, publish, distribute, sublicense, and/or sell copies
  *  of the Software, and to permit persons to whom the Software is
  *  furnished to do so, subject to the following conditions:
- *  
+ *
  *  The above copyright notice and this permission notice shall be
  *  included in all copies or substantial portions of the Software.
- *  
+ *
  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -194,7 +194,7 @@
 
     if(((win32_optopt = argv[win32_optind][1]) != '-') && ! 
argv[win32_optind][2]) {
       int c;
-      
+
       ind = shortoff;
       while((c = shortopts[ind++])) {
         if(((shortopts[ind] == ':') ||

U main_opt.c
Index: main_opt.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/main_opt.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- main_opt.c  25 Feb 2008 17:17:59 -0000      1.1
+++ main_opt.c  2 Apr 2008 16:13:43 -0000       1.2
@@ -79,8 +79,8 @@
  */
 static char opt_buf[sizeof ("optimize-algebra") + 10];
 
-static int 
-cmp_opt (const void *o1, const void *o2) 
+static int
+cmp_opt (const void *o1, const void *o2)
 {
     return ((struct option *)o1)->val - ((struct option *)o2)->val;
 }
@@ -89,14 +89,14 @@
  * map a one-character command line option to its equivalent
  * long form
  */
-static const char 
-*long_option (char *buf, char *t, char o) 
+static const char
+*long_option (char *buf, char *t, char o)
 {
     struct option key = { 0, 0, 0, o };
     struct option *l;
 
     if ((l = (struct option *) bsearch (&key, long_options,
-                                        sizeof (long_options) / 
+                                        sizeof (long_options) /
                                             sizeof (struct option) - 1,
                                         sizeof (struct option),
                                         cmp_opt))) {
@@ -110,7 +110,7 @@
 
 #else
 
-#ifndef HAVE_GETOPT_H 
+#ifndef HAVE_GETOPT_H
 
 #include "win32_getopt.c" /* fall back on a standalone impl */
 
@@ -169,16 +169,9 @@
 #include "algopt.h"
 #include "logdebug.h"
 
-/**
- * @c basename(argv[0]) is stored here later. The basename() call may
- * modify its argument (according to the man page). To avoid modifying
- * @c argv[0] we make a copy first and store it here.
- */
-static char *progname = 0;
-
-#define MAIN_EXIT(rtrn)        \
-       fputs (PFerrbuf, stderr);\
-       exit (rtrn);
+#define MAIN_EXIT(rtrn) \
+        fputs (PFerrbuf, stderr);\
+        exit (rtrn);
 
 /**
  * Entry point to the Pathfinder compiler,
@@ -189,7 +182,7 @@
 main (int argc, char *argv[])
 {
 
-   
+
     /* Call setjmp() before variables are declared;
      * otherwise, some compilers complain about clobbered variables.
      */
@@ -200,6 +193,13 @@
     }
 
  {
+    /**
+     * @c basename(argv[0]) is stored here later. The basename() call may
+     * modify its argument (according to the man page). To avoid modifying
+     * @c argv[0] we make a copy first and store it here.
+     */
+    static char *progname = 0;
+
     char *opt_args  = "OIKDCG_VGO_[J]OKVCG"
                           "}IM__{_[J]OKVCG"
                           "}IM__{_[J]OKVCGCG"
@@ -228,6 +228,10 @@
 #endif
     /*pathname = dirname (PFstrdup (argv[0]));*/ /* StM: unused! */
 
+#ifndef HAVE_GETOPT_H
+    win32_getopt_reset();
+#endif
+    
     /* getopt-based command line parsing */
     while (true) {
         int c;
@@ -247,7 +251,7 @@
                 if (!prop_args)
                     prop_args = PFstrdup (optarg);
                 else {
-                    prop_args = PFrealloc (prop_args, 
+                    prop_args = PFrealloc (prop_args,
                                            strlen (prop_args)+1,
                                            strlen (prop_args)
                                            + strlen (optarg) +1);
@@ -262,7 +266,7 @@
                         "\n\n"
                         "($Revision$, $Date$)\n");
                 printf ("(c) Database Group, Technische Universitaet 
Muenchen\n\n");
-                printf ("Usage: %s [OPTION] [FILE]\n\n", argv[0]);            
+                printf ("Usage: %s [OPTION] [FILE]\n\n", argv[0]);
                 printf ("  Reads from standard input if FILE is omitted.\n\n");
                 printf ("  -o<options>%s: optimize algebra according to "
                                             "options:\n",
@@ -325,14 +329,14 @@
     }           /* end of while */
 
     PFla_op_t  *laroot  = NULL;
-    
+
 #if HAVE_SIGNAL_H
     /* setup sementation fault signal handler */
     signal (SIGSEGV, segfault_handler);
 #endif
 
     XML2LALGContext *ctx = PFxml2la_xml2lalgContext();
-    
+
     /* Initialize data structures in the Namespace department */
     PFns_init ();
 
@@ -357,10 +361,10 @@
     }
     else {
         /**
-         * Note, that we don't get explicit error-positions (line 
-         * numbers of the xml-input) from the parser in case of 
-         * validation errors... 
-         * 
+         * Note, that we don't get explicit error-positions (line
+         * numbers of the xml-input) from the parser in case of
+         * validation errors...
+         *
          * Call PF from the command line with an explicit filename
          * (instead of using stdin/pipelining) if you want to get
          * explicit error positions (line numbers) from the xml-parser

U main.c
Index: main.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/main.c,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -d -r1.103 -r1.104
--- main.c      27 Feb 2008 08:15:53 -0000      1.103
+++ main.c      2 Apr 2008 16:13:42 -0000       1.104
@@ -48,7 +48,7 @@
  * @subsection parsing Parsing
  *
  * In the parsing phase, the input query is analyzed according to the
- * XQuery grammar rules. The parser is implemented with 
+ * XQuery grammar rules. The parser is implemented with
  * <a href="http://www.gnu.org/software/bison/bison.html";>bison</a> (see
  * file parser/XQuery.y). The implementation closely follows the grammar
  * described in the
@@ -189,7 +189,7 @@
  * Type inference walks the core expression, inferring a type for each
  * node.  Types are attached to the core tree nodes to facilitate type
  * checking.
- * 
+ *
  * PFty_check() decorates the core tree with type annotations but
  * lets the tree alone otherwise (almost).
  *
@@ -233,7 +233,7 @@
  * operations.
  *
  * @subsection algebra_cse Algebra Common Subexpression Elimination (CSE)
- * 
+ *
  * The algebra code generated in the previous step contains @em many
  * redundancies. To avoid re-computation of the same expression, the
  * code in algebra_cse.c rewrites the algebra expression @em tree into
@@ -284,7 +284,7 @@
  *
  * MIL is Pathfinder's target language. The code in mil/milgen.brg
  * translates a physical algebra tree into MIL. We do not, however,
- * directly generate a serialized MIl program, but assemble an 
+ * directly generate a serialized MIl program, but assemble an
  * internal MIL syntax tree first. This MIL tree is serialized to
  * ``real'' MIL afterwards in mil/milprint.c. This serializer
  * follows some grammar that we define on our MIL trees, which at
@@ -331,7 +331,7 @@
  *
  * @subsection what_to_print Data Structures that may be Printed
  *
- * The command line switches <code>-a</code>, <code>-c</code>, 
+ * The command line switches <code>-a</code>, <code>-c</code>,
  * <code>-l</code>, and <code>-p</code> request printing of abstract
  * syntax tree (aka. parse tree), Core language tree, logical and
  * physical algebra expression tree, respectively.
@@ -401,7 +401,7 @@
  * <a href='http://www.tum.de'>Technische Universit&auml;t M&uuml;nchen</a>.
  * Several students from U Konstanz have been involved in this
  * project, namely
- * 
+ *
  *  - Gerlinde Adam
  *  - Natalia Fibich
  *  - Guenther Hagleitner
@@ -433,7 +433,7 @@
  * Software is distributed as the "MonetDB/XQuery" system at
  * <a href='http://www.monetdb-xquery.org/'>http://www.monetdb-xquery.org/</a>.
  */
-  
+
 #include "pathfinder.h"
 
 #include <stdlib.h>
@@ -508,8 +508,8 @@
  */
 static char opt_buf[sizeof ("mil-dead-code-elimination") + 10];
 
-static int 
-cmp_opt (const void *o1, const void *o2) 
+static int
+cmp_opt (const void *o1, const void *o2)
 {
     return ((struct option *)o1)->val - ((struct option *)o2)->val;
 }
@@ -518,14 +518,14 @@
  * map a one-character command line option to its equivalent
  * long form
  */
-static const char 
-*long_option (char *buf, char *t, char o) 
+static const char
+*long_option (char *buf, char *t, char o)
 {
     struct option key = { 0, 0, 0, o };
     struct option *l;
 
     if ((l = (struct option *) bsearch (&key, long_options,
-                                        sizeof (long_options) / 
+                                        sizeof (long_options) /
                                             sizeof (struct option) - 1,
                                         sizeof (struct option),
                                         cmp_opt))) {
@@ -539,7 +539,7 @@
 
 #else
 
-#ifndef HAVE_GETOPT_H 
+#ifndef HAVE_GETOPT_H
 
 #include "win32_getopt.c" /* fall back on a standalone impl */
 
@@ -589,16 +589,9 @@
     [22]  = "after the MIL program has been serialized"
 };
 
-/**
- * @c basename(argv[0]) is stored here later. The basename() call may
- * modify its argument (according to the man page). To avoid modifying
- * @c argv[0] we make a copy first and store it here.
- */
-static char *progname = 0;
-
-#define MAIN_EXIT(rtrn)        \
-       fputs (PFerrbuf, stderr);\
-       exit (rtrn);
+#define MAIN_EXIT(rtrn) \
+        fputs (PFerrbuf, stderr);\
+        exit (rtrn);
 
 /**
  * Entry point to the Pathfinder compiler,
@@ -609,7 +602,7 @@
 main (int argc, char *argv[])
 {
 
-   
+
     /* Call setjmp() before variables are declared;
      * otherwise, some compilers complain about clobbered variables.
      */
@@ -620,11 +613,18 @@
     }
 
  {
+    /**
+     * @c basename(argv[0]) is stored here later. The basename() call may
+     * modify its argument (according to the man page). To avoid modifying
+     * @c argv[0] we make a copy first and store it here.
+     */
+    char *progname = 0;
+
     PFstate_t  PFstate;
     PFstate_t* status = &PFstate;
     unsigned int i;
     bool explicit_opt = false;
-    
+
     /** initialize global state of the compiler */
     PFstate_init (status);
     PFstate.invocation = invoke_cmdline;
@@ -647,6 +647,10 @@
 #endif
     /*pathname = dirname (PFstrdup (argv[0]));*/ /* StM: unused! */
 
+#ifndef HAVE_GETOPT_H
+    win32_getopt_reset();
+#endif
+    
     /* getopt-based command line parsing */
     while (true) {
         int c;
@@ -657,7 +661,7 @@
 #ifndef NDEBUG
                                      "d:"
 #endif
-                                     "e:f:Shlo:pqrs:t", 
+                                     "e:f:Shlo:pqrs:t",
                          long_options, &option_index);
 #else
         c = getopt (argc, argv, "ADHIMO::PTXabc"
@@ -682,7 +686,7 @@
                 printf ("Pathfinder XQuery Compiler "
                         "($Revision$, $Date$)\n");
                 printf ("(c) Database Group, Technische Universitaet 
Muenchen\n\n");
-                printf ("Usage: %s [OPTION] [FILE]\n\n", argv[0]);            
+                printf ("Usage: %s [OPTION] [FILE]\n\n", argv[0]);
                 printf ("  Reads from standard input if FILE is omitted.\n\n");
                 printf ("  -A%s: generate MIL code"
 #if ALGEBRA_IS_DEFAULT
@@ -709,7 +713,7 @@
                         long_option (opt_buf, ", --%s", 'I'));
                 printf ("\n");
 
-                
+
                 printf ("  -D%s: print internal tree structure in AT&T dot 
notation\n",
                         long_option (opt_buf, ", --%s", 'D'));
                 printf ("  -P%s: print internal tree structure in "
@@ -845,7 +849,7 @@
                 if (!explicit_opt)
                     status->opt_alg = status->opt_sql;
                 break;
-                
+
             case 'T':
                 status->timing = true;
                 break;
@@ -853,7 +857,7 @@
             case 'X':
                 if (status->output_format == PFoutput_format_not_specified)
                     status->output_format = PFoutput_format_xml;
-                
+
                 status->print_xml = true;
                 break;
 
@@ -895,7 +899,7 @@
                 if (!status->format)
                     status->format = PFstrdup (optarg);
                 else {
-                    status->format = PFrealloc (status->format, 
+                    status->format = PFrealloc (status->format,
                                                 strlen (status->format)+1,
                                                 strlen (status->format)
                                                     + strlen (optarg) +1);
@@ -907,7 +911,7 @@
                 printf ("Pathfinder XQuery Compiler "
                         "($Revision$, $Date$)\n");
                 printf ("(c) Database Group, Technische Universitaet 
Muenchen\n\n");
-                printf ("Usage: %s [OPTION] [FILE]\n\n", argv[0]);            
+                printf ("Usage: %s [OPTION] [FILE]\n\n", argv[0]);
                 printf ("  Reads from standard input if FILE is omitted.\n\n");
                 printf ("  -A%s: generate MIL code"
 #if ALGEBRA_IS_DEFAULT
@@ -1018,18 +1022,18 @@
              * fixing/locating this validation-errors unneccessary hard)
              */
             status->import_xml_filename = argv[optind];
-        } 
+        }
         else
         {
             url = argv[optind];
         }
     }
-        
+
 
     /* Now call the main compiler driver */
     if ( PFcompile(url, stdout, status) < 0 )
         goto failure;
-    
+
     PFmem_destroy ();
 
     /* If we are supposed to be quiet

U main_sql.c
Index: main_sql.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/main_sql.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- main_sql.c  1 Apr 2008 16:37:10 -0000       1.2
+++ main_sql.c  2 Apr 2008 16:13:44 -0000       1.3
@@ -77,8 +77,8 @@
  */
 static char opt_buf[sizeof ("optimize-algebra") + 10];
 
-static int 
-cmp_opt (const void *o1, const void *o2) 
+static int
+cmp_opt (const void *o1, const void *o2)
 {
     return ((struct option *)o1)->val - ((struct option *)o2)->val;
 }
@@ -87,14 +87,14 @@
  * map a one-character command line option to its equivalent
  * long form
  */
-static const char 
-*long_option (char *buf, char *t, char o) 
+static const char
+*long_option (char *buf, char *t, char o)
 {
     struct option key = { 0, 0, 0, o };
     struct option *l;
 
     if ((l = (struct option *) bsearch (&key, long_options,
-                                        sizeof (long_options) / 
+                                        sizeof (long_options) /
                                             sizeof (struct option) - 1,
                                         sizeof (struct option),
                                         cmp_opt))) {
@@ -108,7 +108,7 @@
 
 #else
 
-#ifndef HAVE_GETOPT_H 
+#ifndef HAVE_GETOPT_H
 
 #include "win32_getopt.c" /* fall back on a standalone impl */
 
@@ -170,16 +170,9 @@
 #include "sqlprint.h"
 
 
-/**
- * @c basename(argv[0]) is stored here later. The basename() call may
- * modify its argument (according to the man page). To avoid modifying
- * @c argv[0] we make a copy first and store it here.
- */
-static char *progname = 0;
-
-#define MAIN_EXIT(rtrn)        \
-       fputs (PFerrbuf, stderr);\
-       exit (rtrn);
+#define MAIN_EXIT(rtrn) \
+        fputs (PFerrbuf, stderr);\
+        exit (rtrn);
 
 /**
  * Entry point to the Pathfinder compiler,
@@ -190,7 +183,7 @@
 main (int argc, char *argv[])
 {
 
-   
+
     /* Call setjmp() before variables are declared;
      * otherwise, some compilers complain about clobbered variables.
      */
@@ -201,6 +194,13 @@
     }
 
  {
+    /**
+     * @c basename(argv[0]) is stored here later. The basename() call may
+     * modify its argument (according to the man page). To avoid modifying
+     * @c argv[0] we make a copy first and store it here.
+     */
+    static char *progname = 0;
+
     /* URL of query file (if present) */
     char *url = "-";
 
@@ -219,6 +219,10 @@
 #endif
     /*pathname = dirname (PFstrdup (argv[0]));*/ /* StM: unused! */
 
+#ifndef HAVE_GETOPT_H
+    win32_getopt_reset();
+#endif
+    
     /* getopt-based command line parsing */
     while (true) {
         int c;
@@ -239,7 +243,7 @@
                         "Compiles Logical Algebra Dag in XML Format to 
SQL.\n\n"
                         "($Revision$, $Date$)\n");
                 printf ("(c) Database Group, Technische Universitaet 
Muenchen\n\n");
-                printf ("Usage: %s [OPTION] [FILE]\n\n", argv[0]);            
+                printf ("Usage: %s [OPTION] [FILE]\n\n", argv[0]);
                 printf ("  Reads from standard input if FILE is omitted.\n\n");
                 printf ("  -h%s: print this help message\n",
                         long_option (opt_buf, ", --%s", 'h'));
@@ -256,14 +260,14 @@
 
     PFla_op_t  *laroot  = NULL;
     PFsql_t    *sqlroot = NULL;
-    
+
 #if HAVE_SIGNAL_H
     /* setup sementation fault signal handler */
     signal (SIGSEGV, segfault_handler);
 #endif
 
     XML2LALGContext *ctx = PFxml2la_xml2lalgContext();
-    
+
     /* Initialize data structures in the Namespace department */
     PFns_init ();
 
@@ -288,10 +292,10 @@
     }
     else {
         /**
-         * Note, that we don't get explicit error-positions (line 
-         * numbers of the xml-input) from the parser in case of 
-         * validation errors... 
-         * 
+         * Note, that we don't get explicit error-positions (line
+         * numbers of the xml-input) from the parser in case of
+         * validation errors...
+         *
          * Call PF from the command line with an explicit filename
          * (instead of using stdin/pipelining) if you want to get
          * explicit error positions (line numbers) from the xml-parser
@@ -333,7 +337,7 @@
                   false /* icol */,
                   false /* composite key */,
                   true  /* key */,
-                  false /* ocols */, 
+                  false /* ocols */,
                   true  /* req_node */,
                   false /* reqval */,
                   true  /* level */,


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Monetdb-pf-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-pf-checkins

Reply via email to