Revision: 806 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=806&view=rev Author: frlan Date: 2009-07-09 21:38:35 +0000 (Thu, 09 Jul 2009)
Log Message: ----------- GeanyLaTeX: Migrated bibTeX inserting entry framework to make usage of a GPtrArray.
Modified Paths: -------------- trunk/geanylatex/ChangeLog trunk/geanylatex/src/bibtex.c trunk/geanylatex/src/bibtex.h trunk/geanylatex/src/bibtexlabels.c
Modified: trunk/geanylatex/ChangeLog =================================================================== --- trunk/geanylatex/ChangeLog 2009-07-07 17:51:06 UTC (rev 805) +++ trunk/geanylatex/ChangeLog 2009-07-09 21:38:35 UTC (rev 806) @@ -1,3 +1,8 @@ +2009-07-08 Frank Lanitz <frank(at)frank(dot)uvena(dot)de> + + * Migrated bibTeX inserting entry framework to make usage of a GPtrArray. + + 2009-06-27 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
* Added Portuguese translation. Thanks to André Glória for providing.
Modified: trunk/geanylatex/src/bibtex.c =================================================================== --- trunk/geanylatex/src/bibtex.c 2009-07-07 17:51:06 UTC (rev 805) +++ trunk/geanylatex/src/bibtex.c 2009-07-09 21:38:35 UTC (rev 806) @@ -22,10 +22,6 @@ #include "bibtex.h" #include "reftex.h"
-#define glatex_set_status(entry_number, flag) \ - fields[entry_number] = flag; - - #if 0 static int get_entry_pos(char *str) { @@ -44,99 +40,128 @@ void glatex_insert_bibtex_entry(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer gdata) { - int doctype = GPOINTER_TO_INT(gdata); - gboolean fields[GLATEX_BIBTEX_N_ENTRIES]; - gchar *output = g_strdup("@"); - int i; + gint i; + gint doctype = GPOINTER_TO_INT(gdata); + GPtrArray *entry = glatex_bibtex_init_empty_entry();
- for (i = 0; i < GLATEX_BIBTEX_N_ENTRIES; i++) - { - glatex_set_status(i, FALSE); - } - switch(doctype) { case GLATEX_BIBTEX_ARTICLE: - glatex_set_status(GLATEX_BIBTEX_AUTHOR, TRUE); - glatex_set_status(GLATEX_BIBTEX_TITLE, TRUE); - glatex_set_status(GLATEX_BIBTEX_JOURNAL, TRUE); - glatex_set_status(GLATEX_BIBTEX_YEAR, TRUE); + g_ptr_array_index(entry, GLATEX_BIBTEX_AUTHOR) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_TITLE) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_JOURNAL) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_YEAR) = g_strdup("\0"); break; case GLATEX_BIBTEX_BOOK: - glatex_set_status(GLATEX_BIBTEX_AUTHOR, TRUE); - glatex_set_status(GLATEX_BIBTEX_EDITOR, TRUE); - glatex_set_status(GLATEX_BIBTEX_TITLE, TRUE); - glatex_set_status(GLATEX_BIBTEX_PUBLISHER, TRUE); - glatex_set_status(GLATEX_BIBTEX_YEAR, TRUE); + g_ptr_array_index(entry, GLATEX_BIBTEX_AUTHOR) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_EDITOR) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_TITLE) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_PUBLISHER) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_YEAR) = g_strdup("\0"); break; case GLATEX_BIBTEX_BOOKLET: - glatex_set_status(GLATEX_BIBTEX_TITLE, TRUE); + g_ptr_array_index(entry, GLATEX_BIBTEX_TITLE) = g_strdup("\0"); break; case GLATEX_BIBTEX_CONFERENCE: case GLATEX_BIBTEX_INCOLLECTION: case GLATEX_BIBTEX_INPROCEEDINGS: - glatex_set_status(GLATEX_BIBTEX_AUTHOR, TRUE); - glatex_set_status(GLATEX_BIBTEX_TITLE, TRUE); - glatex_set_status(GLATEX_BIBTEX_BOOKTITLE, TRUE); - glatex_set_status(GLATEX_BIBTEX_YEAR, TRUE); + g_ptr_array_index(entry, GLATEX_BIBTEX_AUTHOR) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_TITLE) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_BOOKTITLE) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_YEAR) = g_strdup("\0"); break; case GLATEX_BIBTEX_INBOOK: - glatex_set_status(GLATEX_BIBTEX_AUTHOR, TRUE); - glatex_set_status(GLATEX_BIBTEX_EDITOR, TRUE); - glatex_set_status(GLATEX_BIBTEX_TITLE, TRUE); - glatex_set_status(GLATEX_BIBTEX_CHAPTER, TRUE); - glatex_set_status(GLATEX_BIBTEX_PAGES, TRUE); - glatex_set_status(GLATEX_BIBTEX_PUBLISHER, TRUE); - glatex_set_status(GLATEX_BIBTEX_YEAR, TRUE); + g_ptr_array_index(entry, GLATEX_BIBTEX_AUTHOR) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_EDITOR) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_TITLE) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_CHAPTER) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_PAGES) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_PUBLISHER) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_YEAR) = g_strdup("\0"); break; case GLATEX_BIBTEX_MANUAL: - glatex_set_status(GLATEX_BIBTEX_TITLE, TRUE); + g_ptr_array_index(entry, GLATEX_BIBTEX_TITLE) = g_strdup("\0"); break; case GLATEX_BIBTEX_MASTERSTHESIS: case GLATEX_BIBTEX_PHDTHESIS: - glatex_set_status(GLATEX_BIBTEX_AUTHOR, TRUE); - glatex_set_status(GLATEX_BIBTEX_TITLE, TRUE); - glatex_set_status(GLATEX_BIBTEX_SCHOOL, TRUE); - glatex_set_status(GLATEX_BIBTEX_YEAR, TRUE); + g_ptr_array_index(entry, GLATEX_BIBTEX_AUTHOR) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_TITLE) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_SCHOOL) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_YEAR) = g_strdup("\0"); break; case GLATEX_BIBTEX_MISC: for (i = 0; i < GLATEX_BIBTEX_N_ENTRIES; i++) { - glatex_set_status(i, TRUE); + g_ptr_array_index(entry, i) = g_strdup("\0"); } case GLATEX_BIBTEX_TECHREPORT: - glatex_set_status(GLATEX_BIBTEX_AUTHOR, TRUE); - glatex_set_status(GLATEX_BIBTEX_TITLE, TRUE); - glatex_set_status(GLATEX_BIBTEX_INSTITUTION, TRUE); - glatex_set_status(GLATEX_BIBTEX_YEAR, TRUE); + g_ptr_array_index(entry, GLATEX_BIBTEX_AUTHOR) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_TITLE) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_INSTITUTION) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_YEAR) = g_strdup("\0"); break; case GLATEX_BIBTEX_UNPUBLISHED: - glatex_set_status(GLATEX_BIBTEX_AUTHOR, TRUE); - glatex_set_status(GLATEX_BIBTEX_TITLE, TRUE); - glatex_set_status(GLATEX_BIBTEX_NOTE, TRUE); + g_ptr_array_index(entry, GLATEX_BIBTEX_AUTHOR) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_TITLE) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_NOTE) = g_strdup("\0"); break; case GLATEX_BIBTEX_PROCEEDINGS: - glatex_set_status(GLATEX_BIBTEX_TITLE, TRUE); - glatex_set_status(GLATEX_BIBTEX_YEAR, TRUE); + g_ptr_array_index(entry, GLATEX_BIBTEX_TITLE) = g_strdup("\0"); + g_ptr_array_index(entry, GLATEX_BIBTEX_YEAR) = g_strdup("\0"); break; default: for (i = 0; i < GLATEX_BIBTEX_N_ENTRIES; i++) { - glatex_set_status(i, TRUE); + g_ptr_array_index(entry, i) = g_strdup("\0"); } }
+ glatex_bibtex_write_entry(entry, doctype); + + g_ptr_array_free(entry, TRUE); +} + +/* Creating and initialising a array for a bibTeX entry with NULL pointers*/ +GPtrArray *glatex_bibtex_init_empty_entry() +{ + gint i; + GPtrArray *entry = g_ptr_array_new(); + g_ptr_array_set_size(entry, GLATEX_BIBTEX_N_ENTRIES); + return entry; +} + + +void glatex_bibtex_write_entry(GPtrArray *entry, gint doctype) +{ + gint i; + gchar *output = g_strdup("@"); + + /* Adding the doctype to entry */ output = g_strconcat(output, glatex_label_types[doctype], "{ \n",NULL); + + /* Adding the keywords and values to entry */ for (i = 0; i < GLATEX_BIBTEX_N_ENTRIES; i++) { - if (fields[i] == TRUE) + /* Check whether a field has been marked for being used */ + if (g_ptr_array_index (entry, i) != NULL) { - output = g_strconcat(output, glatex_label_entry_keywords[i], " = {},\n", NULL); + /* Check whether a field was only set for being used ... */ + if (utils_str_equal(g_ptr_array_index (entry, i), "\0")) + { + output = g_strconcat(output, + glatex_label_entry_keywords[i], " = {},\n", NULL); + } + /* ... or has some real value inside. */ + else + { + output = g_strconcat(output, + glatex_label_entry_keywords[i], " = {", g_ptr_array_index(entry, i), + "},\n", NULL); + } } }
output = g_strconcat(output, "}\n", NULL); glatex_insert_string(output, FALSE);
- g_free(output); }
Modified: trunk/geanylatex/src/bibtex.h =================================================================== --- trunk/geanylatex/src/bibtex.h 2009-07-07 17:51:06 UTC (rev 805) +++ trunk/geanylatex/src/bibtex.h 2009-07-09 21:38:35 UTC (rev 806) @@ -44,7 +44,6 @@ GLATEX_BIBTEX_N_TYPES };
- enum { GLATEX_BIBTEX_ADDRESS = 0, GLATEX_BIBTEX_ANNOTE, @@ -88,4 +87,7 @@ void glatex_insert_bibtex_entry(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer gdata);
+void glatex_bibtex_write_entry(GPtrArray *entry, gint doctype); + +GPtrArray *glatex_bibtex_init_empty_entry(); #endif
Modified: trunk/geanylatex/src/bibtexlabels.c =================================================================== --- trunk/geanylatex/src/bibtexlabels.c 2009-07-07 17:51:06 UTC (rev 805) +++ trunk/geanylatex/src/bibtexlabels.c 2009-07-09 21:38:35 UTC (rev 806) @@ -93,7 +93,8 @@ ("Type"), ("URL"), ("Volume"), - ("Year")}; + ("Year"), + ( NULL) };
const gchar *glatex_label_tooltips[] = { N_("Address of publisher"),
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.