Apologies for my previous attempt at submitting the patch for file.c.

Here is the new patch file.

Basically it adds a fourth optional parameter to fgetcsv which means you
can specify the enclosure character (currently assumes a double quote).

This is only my first attempt at contributing code to the PHP project,
so please be gentle with me! ;)

Thanks

Dean
? file.c.patch
Index: file.c
===================================================================
RCS file: /repository/php4/ext/standard/file.c,v
retrieving revision 1.229
diff -u -r1.229 file.c
--- file.c      12 May 2002 15:59:42 -0000      1.229
+++ file.c      22 May 2002 10:08:38 -0000
@@ -1930,10 +1930,11 @@
 {
        char *temp, *tptr, *bptr, *lineEnd;
        char delimiter = ',';   /* allow this to be set as parameter */
+       char enclosure = '"';   /* allow this to be set as parameter */
 
        /* first section exactly as php_fgetss */
 
-       zval **fd, **bytes, **p_delim;
+       zval **fd, **bytes, **p_delim, **p_enclosure;
        int len, type;
        char *buf;
        php_stream *stream;
@@ -1958,6 +1959,28 @@
                delimiter = Z_STRVAL_PP(p_delim)[0];
                break;
 
+       case 4:
+               if (zend_get_parameters_ex(4, &fd, &bytes, &p_delim, &p_enclosure) == 
+FAILURE) {
+                       WRONG_PARAM_COUNT;
+               }
+               convert_to_string_ex(p_delim);
+               /* Make sure that there is at least one character in string */
+               if (Z_STRLEN_PP(p_delim) < 1) {
+                       WRONG_PARAM_COUNT;
+               }
+                       /* use first character from string */
+               delimiter = Z_STRVAL_PP(p_delim)[0];
+
+               convert_to_string_ex(p_enclosure);
+               /* Make sure that there is at least one character in string */
+               if (Z_STRLEN_PP(p_enclosure) < 1) {
+                       WRONG_PARAM_COUNT;
+               }
+                       /* use first character from string */
+               enclosure = Z_STRVAL_PP(p_enclosure)[0];
+
+               break;
+
        default:
                WRONG_PARAM_COUNT;
                /* NOTREACHED */
@@ -1983,9 +2006,9 @@
                RETURN_FALSE;
        }
 
-       /* Now into new section that parses buf for comma/quote delimited fields */
+       /* Now into new section that parses buf for delimiter/enclosure fields */
 
-       /* Strip trailing space from buf, saving end of line in case required for 
quoted field */
+       /* Strip trailing space from buf, saving end of line in case required for 
+enclosure field */
 
        lineEnd = emalloc(len + 1);
        bptr = buf;
@@ -2013,14 +2036,14 @@
                /* 1. Strip any leading space */
                while(isspace((int) *bptr) && (*bptr!=delimiter)) bptr++;
                /* 2. Read field, leaving bptr pointing at start of next field */
-               if (*bptr == '"') {
-                       /* 2A. handle quote delimited field */
+               if (*bptr == enclosure) {
+                       /* 2A. handle enclosure delimited field */
                        bptr++;         /* move on to first character in field */
                        while (*bptr) {
-                               if (*bptr == '"') {
-                                       /* handle the double-quote */
+                               if (*bptr == enclosure) {
+                                       /* handle the enclosure */
                                        if ( *(bptr+1) == '"') {
-                                       /* embedded double quotes */
+                                       /* embedded enclosure */
                                                *tptr++ = *bptr; bptr +=2;
                                        } else {
                                        /* must be end of string - skip to start of 
next field or end */
@@ -2064,7 +2087,7 @@
                                }
                        }
                } else {
-                       /* 2B. Handle non-quoted field */
+                       /* 2B. Handle non-enclosure field */
                        while ((*bptr != delimiter) && *bptr) 
                                *tptr++ = *bptr++;
                        *tptr=0;        /* terminate temporary string */

Attachment: msg38330/pgp00000.pgp
Description: PGP signature

Reply via email to