Revision: 2147 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=2147&view=re... Author: frlan Date: 2011-08-15 06:55:03 +0000 (Mon, 15 Aug 2011)
Log Message: ----------- Tableconvert: Move code for converting into a LaTeX table into a seperate function
Modified Paths: -------------- trunk/geany-plugins/tableconvert/src/tableconvert.c
Modified: trunk/geany-plugins/tableconvert/src/tableconvert.c =================================================================== --- trunk/geany-plugins/tableconvert/src/tableconvert.c 2011-08-15 06:54:44 UTC (rev 2146) +++ trunk/geany-plugins/tableconvert/src/tableconvert.c 2011-08-15 06:55:03 UTC (rev 2147) @@ -45,6 +45,7 @@
static GtkWidget *main_menu_item = NULL;
+ static GString* convert_to_table_html(gchar **rows, gboolean header) { guint i; @@ -106,6 +107,41 @@ return replacement_str; }
+static GString* convert_to_table_latex(gchar** rows, gboolean header) +{ + guint i; + guint j; + GString *replacement_str = NULL; + + /* Adding header to replacement */ + replacement_str = g_string_new("\begin{tabular}{}\n"); + + /* Iteration onto rows and building up lines of table for + * replacement */ + for (i = 0; rows[i] != NULL ; i++) + { + gchar **columns = NULL; + columns = g_strsplit_set(rows[i], "\t", -1); + + for (j = 0; columns[j] != NULL; j++) + { + if (j > 0) + { + g_string_append(replacement_str, " & "); + } + g_string_append(replacement_str, columns[j]); + } + + g_string_append(replacement_str, "\\\n"); + + g_free(columns); + } + /* Adding the footer of table */ + + g_string_append(replacement_str, "\end{tabular}\n"); + return replacement_str; +} + void convert_to_table(gboolean header) { GeanyDocument *doc = NULL; @@ -136,35 +172,7 @@
else if (doc->file_type->id == GEANY_FILETYPES_LATEX) { - guint i; - guint j; - - /* Adding header to replacement */ - replacement_str = g_string_new("\begin{tabular}{}\n"); - - /* Iteration onto rows and building up lines of table for - * replacement */ - for (i = 0; rows[i] != NULL ; i++) - { - gchar **columns = NULL; - columns = g_strsplit_set(rows[i], "\t", -1); - - for (j = 0; columns[j] != NULL; j++) - { - if (j > 0) - { - g_string_append(replacement_str, " & "); - } - g_string_append(replacement_str, columns[j]); - } - - g_string_append(replacement_str, "\\\n"); - - g_free(columns); - } - /* Adding the footer of table */ - - g_string_append(replacement_str, "\end{tabular}\n"); + replacement_str = convert_to_table_latex(rows, header); } } else
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.