Update of /cvsroot/monetdb/clients/src/mapiclient
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17874

Modified Files:
        MapiClient.mx 
Log Message:
Do not use a calculated offset with fseek.  It is not portable.
Instead, we read one line at a time in XQuery mode to find lines that
contain only "<>".


Index: MapiClient.mx
===================================================================
RCS file: /cvsroot/monetdb/clients/src/mapiclient/MapiClient.mx,v
retrieving revision 1.102
retrieving revision 1.103
diff -u -d -r1.102 -r1.103
--- MapiClient.mx       11 Jan 2008 10:34:34 -0000      1.102
+++ MapiClient.mx       11 Jan 2008 16:44:13 -0000      1.103
@@ -1044,6 +1044,7 @@
        MapiHdl hdl = NULL;
        MapiMsg rc = MOK;
        int bufsize = 0;
+       int xquery_sep = 0;    /* we saw an XQuery separator (<>\n) */
 
        if (file == NULL)
                fp = stdin;
@@ -1064,7 +1065,24 @@
        timerStart();
        do {
                timerPause();
-               if ((length = fread(buf, 1, bufsize, fp)) == 0) {
+               if (mode == XQUERY) {
+                       /* In XQuery mode we must read one line at a
+                          time so that we can stop when we encounter
+                          a line with just "<>" on it. */
+                       if (fgets(buf, bufsize, fp) == NULL) {
+                               /* end of file */
+                               if (file != NULL) {
+                                       fclose(fp);
+                                       file = NULL;
+                               }
+                               length = 0;
+                               if (hdl == NULL)
+                                       break;  /* nothing more to do */
+                       } else {
+                               length = strlen(buf);
+                               xquery_sep = length >= 3 && buf[0] == '<' && 
buf[1] == '>' && (buf[2] == '\n' || buf[2] == '\r');
+                       }
+               } else if ((length = fread(buf, 1, bufsize, fp)) == 0) {
                        /* end of file */
                        if (file != NULL) {
                                fclose(fp);
@@ -1079,34 +1097,14 @@
                        hdl = mapi_query_prep(mid);
                        CHECK_RESULT(mid, hdl, buf, continue);
                }
-               if (length > 0) {
-                       char *xquery_sep = buf;
-
+               if (length > 0 && !xquery_sep) {
                        assert(hdl != NULL);
 
-                       if (mode == XQUERY) {
-                               /* support <>\n xquery separator in file mode 
-                                  (must be at start of line) */
-                               while (xquery_sep) {
-                                       xquery_sep = strstr(xquery_sep + 1, 
"<>");
-                                       if (xquery_sep && (xquery_sep[-1] == 
'\n' || xquery_sep[-1] == '\r')) {
-                                               char *next = xquery_sep + 2;
-
-                                               while (*next && isspace(*next))
-                                                       next++;
-                                               fseek(fp, next - (buf + 
length), SEEK_CUR);
-                                               length = xquery_sep - buf;
-                                               buf[length] = 0;
-                                               break;
-                                       }
-                               }
-                       }
-
                        mapi_query_part(hdl, buf, length);
                        CHECK_RESULT(mid, hdl, buf, continue);
 
-                       /* in case of xquery; do the whole file in one go */
-                       if (xquery_sep == NULL && !feof(fp))
+                       /* in case of XQuery; do the whole file in one go */
+                       if (mode == XQUERY)
                                continue;
                }
 


-------------------------------------------------------------------------
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-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to