SF.net SVN: geany:[5112] trunk
eht16 at users.sourceforge.net
eht16 at xxxxx
Sat Jul 31 15:31:31 UTC 2010
Revision: 5112
http://geany.svn.sourceforge.net/geany/?rev=5112&view=rev
Author: eht16
Date: 2010-07-31 15:31:30 +0000 (Sat, 31 Jul 2010)
Log Message:
-----------
Make make_comment_block() work with a GString. This is not yet perfect but a bit better than before.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/templates.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-07-31 14:38:46 UTC (rev 5111)
+++ trunk/ChangeLog 2010-07-31 15:31:30 UTC (rev 5112)
@@ -3,6 +3,9 @@
* src/vte.c:
Fix build with GTK 2.8, use the stock icon name directly instead
of the macro. Though, the icon is still missing for GTK 2.8.
+ * src/templates.c:
+ Make make_comment_block() work with a GString. This is not yet
+ perfect but a bit better than before.
2010-07-29 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/src/templates.c
===================================================================
--- trunk/src/templates.c 2010-07-31 14:38:46 UTC (rev 5111)
+++ trunk/src/templates.c 2010-07-31 15:31:30 UTC (rev 5112)
@@ -430,27 +430,31 @@
* e.g. indent = 8 prints " * here comes the text of the line"
* indent is meant to be the whole amount of characters before the real line content follows, i.e.
* 6 characters are filled with whitespace when the comment characters include " *" */
-/* TODO make this function operating on a GString */
-static gchar *make_comment_block(const gchar *comment_text, gint filetype_idx, guint indent)
+static void make_comment_block(GString *comment_text, gint filetype_idx, guint indent)
{
gchar *frame_start; /* to add before comment_text */
gchar *frame_end; /* to add after comment_text */
const gchar *line_prefix; /* to add before every line in comment_text */
- gchar *result;
gchar *tmp;
gchar *prefix;
gchar **lines;
guint i, len;
+ gint template_eol_mode;
+ const gchar *template_eol_char;
GeanyFiletype *ft = filetypes_index(filetype_idx);
- g_return_val_if_fail(ft != NULL, NULL);
+ g_return_if_fail(comment_text != NULL);
+ g_return_if_fail(ft != NULL);
+ template_eol_mode = utils_get_line_endings(comment_text->str, comment_text->len);
+ template_eol_char = utils_get_eol_char(template_eol_mode);
+
if (NZV(ft->comment_open))
{
if (NZV(ft->comment_close))
{
- frame_start = g_strconcat(ft->comment_open, "\n", NULL);
- frame_end = g_strconcat(ft->comment_close, "\n", NULL);
+ frame_start = g_strconcat(ft->comment_open, template_eol_char, NULL);
+ frame_end = g_strconcat(ft->comment_close, template_eol_char, NULL);
line_prefix = "";
}
else
@@ -462,8 +466,8 @@
}
else
{ /* use C-like multi-line comments as fallback */
- frame_start = g_strdup("/*\n");
- frame_end = g_strdup("*/\n");
+ frame_start = g_strconcat("/*", template_eol_char, NULL);
+ frame_end = g_strconcat("*/", template_eol_char, NULL);
line_prefix = "";
}
@@ -482,7 +486,7 @@
g_free(tmp);
/* add line_prefix to every line of comment_text */
- lines = g_strsplit(comment_text, "\n", -1);
+ lines = g_strsplit(comment_text->str, template_eol_char, -1);
len = g_strv_length(lines) - 1;
for (i = 0; i < len; i++)
{
@@ -490,24 +494,28 @@
lines[i] = g_strconcat(prefix, tmp, NULL);
g_free(tmp);
}
- tmp = g_strjoinv("\n", lines);
+ tmp = g_strjoinv(template_eol_char, lines);
- /* add frame_start and frame_end */
+ /* clear old contents */
+ g_string_erase(comment_text, 0, -1);
+
+ /* add frame_end */
if (frame_start != NULL)
- result = g_strconcat(frame_start, tmp, frame_end, NULL);
- else
- result = g_strconcat(tmp, frame_end, NULL);
+ g_string_append(comment_text, frame_start);
+ /* add the new main content */
+ g_string_append(comment_text, tmp);
+ /* add frame_start */
+ if (frame_end != NULL)
+ g_string_append(comment_text, frame_end);
utils_free_pointers(4, prefix, tmp, frame_start, frame_end, NULL);
g_strfreev(lines);
- return result;
}
gchar *templates_get_template_licence(GeanyDocument *doc, gint licence_type)
{
GString *template;
- gchar *result = NULL;
g_return_val_if_fail(doc != NULL, NULL);
g_return_val_if_fail(licence_type == GEANY_TEMPLATE_GPL || licence_type == GEANY_TEMPLATE_BSD, NULL);
@@ -517,18 +525,15 @@
templates_replace_default_dates(template);
templates_replace_command(template, DOC_FILENAME(doc), doc->file_type->name, NULL);
- result = make_comment_block(template->str, FILETYPE_ID(doc->file_type), 8);
+ make_comment_block(template, FILETYPE_ID(doc->file_type), 8);
- g_string_free(template, TRUE);
-
- return result;
+ return g_string_free(template, FALSE);
}
static gchar *get_template_fileheader(GeanyFiletype *ft)
{
GString *template = g_string_new(templates[GEANY_TEMPLATE_FILEHEADER]);
- gchar *result;
filetypes_load_config(ft->id, FALSE); /* load any user extension setting */
@@ -538,9 +543,8 @@
NULL);
/* we don't replace other wildcards here otherwise they would get done twice for files */
- result = make_comment_block(template->str, ft->id, 8);
- g_string_free(template, TRUE);
- return result;
+ make_comment_block(template, ft->id, 8);
+ return g_string_free(template, FALSE);
}
@@ -584,7 +588,6 @@
gchar *templates_get_template_function(GeanyDocument *doc, const gchar *func_name)
{
- gchar *result;
GString *text;
func_name = (func_name != NULL) ? func_name : "";
@@ -594,10 +597,9 @@
templates_replace_default_dates(text);
templates_replace_command(text, DOC_FILENAME(doc), doc->file_type->name, func_name);
- result = make_comment_block(text->str, doc->file_type->id, 3);
+ make_comment_block(text, doc->file_type->id, 3);
- g_string_free(text, TRUE);
- return result;
+ return g_string_free(text, FALSE);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list