CVS update: php3/functions
| From: | rasmus | Date: | Sat, 19 Jun 1999 23:20:22 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-7162@lists.php.net to get a copy of this message | ||
Date: Saturday June 19, 1999 @ 19:20
Author: rasmus
Update of /repository/php3/functions
In directory php:/tmp/cvs-serv26539/functions
Modified Files:
file.c
Log Message:
fgetcsv() fix
Index: php3/functions/file.c
diff -u php3/functions/file.c:1.218 php3/functions/file.c:1.219
--- php3/functions/file.c:1.218 Wed Jun 16 07:34:18 1999
+++ php3/functions/file.c Sat Jun 19 19:20:21 1999
@@ -26,7 +26,7 @@
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
-/* $Id: file.c,v 1.218 1999/06/16 11:34:18 ssb Exp $ */
+/* $Id: file.c,v 1.219 1999/06/19 23:20:21 rasmus Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
@@ -1458,7 +1458,7 @@
pval *fd, *bytes, *p_delim;
FILE *fp;
int id, len, type;
- char *buf;
+ char *buf, *lineEnd;
int issock=0;
int *sock,socketd=0;
TLS_VARS;
@@ -1515,15 +1515,18 @@
/* Now into new section that parses buf for comma/quote delimited fields */
- /* Strip trailing space from buf */
+ /* Strip trailing space from buf, saving end of line in case required for quoted field */
+ lineEnd = emalloc(sizeof(char) * (len + 1));
bptr = buf;
tptr = buf + strlen(buf) -1;
- while ( isspace(*tptr) && (tptr > bptr) ) *tptr--=0;
+ while ( isspace(*tptr) && (tptr > bptr) ) tptr--;
+ tptr++;
+ strcpy(lineEnd, tptr);
/* add single space - makes it easier to parse trailing null field */
- *++tptr = ' ';
- *++tptr = 0;
+ *tptr++ = ' ';
+ *tptr = 0;
/* reserve workspace for building each individual field */
@@ -1532,6 +1535,7 @@
/* Initialize return array */
if (array_init(return_value) == FAILURE) {
+ efree(lineEnd);
efree(temp);
efree(buf);
RETURN_FALSE;
@@ -1563,6 +1567,26 @@
} else {
/* normal character */
*tptr++ = *bptr++;
+
+ if (*bptr == 0) { /* embedded line end? */
+ *(tptr-1)=0; /* remove space character added on reading line */
+ strcat(temp,lineEnd); /* add the embedded line end to the field */
+
+ /* read a new line from input, as at start of routine */
+ memset(buf,0,len+1);
+ if (!(issock?SOCK_FGETS(buf,len,socketd):fgets(buf, len, fp))) {
+ efree(lineEnd); efree(temp); efree(buf);
+ RETURN_FALSE;
+ }
+ bptr = buf;
+ tptr = buf + strlen(buf) -1;
+ while ( isspace(*tptr) && (tptr > bptr) ) tptr--;
+ tptr++; strcpy(lineEnd, tptr);
+ *tptr++ = ' '; *tptr = 0;
+
+ tptr=temp; /* reset temp pointer to end of field as read so far */
+ while (*tptr) tptr++;
+ }
}
}
} else {
@@ -1574,11 +1598,13 @@
while (isspace(*tptr)) *tptr-- = 0; /* strip any trailing spaces */
}
if (*bptr == delimiter) bptr++;
+
}
/* 3. Now pass our field back to php */
add_next_index_string(return_value, temp, 1);
tptr=temp;
} while (*bptr);
+ efree(lineEnd);
efree(temp);
efree(buf);
}