[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

gEDA-cvs: gaf.git: branch: master updated (1.6.1-20100214-185-g35c3a28)



The branch, master has been updated
       via  35c3a2862d6ee68415fbe8163e2c8c06627dba01 (commit)
      from  fda647ce9ff7b57c465382c55a47304183766a0b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


=========
 Summary
=========

 gattrib/src/f_export.c |   22 ++++++++++++++++++----
 1 files changed, 18 insertions(+), 4 deletions(-)


=================
 Commit Messages
=================

commit 35c3a2862d6ee68415fbe8163e2c8c06627dba01
Author: Dima Kogan <dkogan@xxxxxxxxxxxxxxx>
Commit: Peter TB Brett <peter@xxxxxxxxxxxxx>

    gattrib: Escape special chars & quote commas in CSV output.
    
    Signed-off-by: Dima Kogan <dkogan@xxxxxxxxxxxxxxx>
    Reviewed-by: Peter TB Brett <peter@xxxxxxxxxxxxx>

:100644 100644 06f0683... bb7f6be... M	gattrib/src/f_export.c

=========
 Changes
=========

commit 35c3a2862d6ee68415fbe8163e2c8c06627dba01
Author: Dima Kogan <dkogan@xxxxxxxxxxxxxxx>
Commit: Peter TB Brett <peter@xxxxxxxxxxxxx>

    gattrib: Escape special chars & quote commas in CSV output.
    
    Signed-off-by: Dima Kogan <dkogan@xxxxxxxxxxxxxxx>
    Reviewed-by: Peter TB Brett <peter@xxxxxxxxxxxxx>

diff --git a/gattrib/src/f_export.c b/gattrib/src/f_export.c
index 06f0683..bb7f6be 100644
--- a/gattrib/src/f_export.c
+++ b/gattrib/src/f_export.c
@@ -125,11 +125,18 @@ void f_export_components(gchar *filename)
     /*  Now export the attrib values for first n-1 cols */
     for (j = 0; j < num_cols-1; j++) {
       if ( (sheet_head->component_table)[i][j].attrib_value ) { /* found a string */
-        text = (gchar *) g_strdup( (sheet_head->component_table)[i][j].attrib_value );
+        /* make a copy of the text, escaping any special chars, like " */
+        text = (gchar *) g_strescape( (sheet_head->component_table)[i][j].attrib_value, "" );
 #ifdef DEBUG
   printf("In f_export_components, output attribute %s.\n", text);
 #endif
-	fprintf(fp, "%s, ", text);
+        /* if there's a comma anywhere in the field, wrap the field in " */
+        gboolean havecomma = ( g_strstr_len(text, -1, ",") != NULL );
+        if(havecomma) fprintf(fp, "\"");
+        fprintf(fp, "%s", text);
+        if(havecomma) fprintf(fp, "\"");
+        fprintf(fp, ", ");
+
 	g_free(text);
       } else {                                                  /* no attrib string */
 #ifdef DEBUG
@@ -140,11 +147,18 @@ void f_export_components(gchar *filename)
     }  /* end of for over cols  */
     /* Now export attrib value for last col (with no "," and with "\n" */
     if ( (sheet_head->component_table)[i][j].attrib_value ) { /* found a string */
-      text = (gchar *) g_strdup( (sheet_head->component_table)[i][j].attrib_value );
+      /* make a copy of the text, escaping any special chars, like " */
+      text = (gchar *) g_strescape( (sheet_head->component_table)[i][j].attrib_value, "" );
 #ifdef DEBUG
   printf("In f_export_components, output final attribute %s.\n", text);
 #endif
-      fprintf(fp, "%s\n", text);
+      /* if there's a comma anywhere in the field, wrap the field in " */
+      gboolean havecomma = ( g_strstr_len(text, -1, ",") != NULL );
+      if(havecomma) fprintf(fp, "\"");
+      fprintf(fp, "%s", text);
+      if(havecomma) fprintf(fp, "\"");
+      fprintf(fp, "\n");
+
       g_free(text);
     } else {                                                  /* no attrib string */
 #ifdef DEBUG




_______________________________________________
geda-cvs mailing list
geda-cvs@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-cvs