SF.net SVN: geany:[4843] trunk
ntrel at users.sourceforge.net
ntrel at xxxxx
Wed Apr 21 16:47:54 UTC 2010
Revision: 4843
http://geany.svn.sourceforge.net/geany/?rev=4843&view=rev
Author: ntrel
Date: 2010-04-21 16:47:54 +0000 (Wed, 21 Apr 2010)
Log Message:
-----------
Support {ob} and {cb} in fileheader and file templates; they are
replaced last with { and }. This allows 'escaping' of wildcard
strings (fixes #2937008).
Modified Paths:
--------------
trunk/doc/geany.html
trunk/doc/geany.txt
trunk/src/templates.c
Modified: trunk/doc/geany.html
===================================================================
--- trunk/doc/geany.html 2010-04-19 21:20:15 UTC (rev 4842)
+++ trunk/doc/geany.html 2010-04-21 16:47:54 UTC (rev 4843)
@@ -6,7 +6,7 @@
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
<title>Geany</title>
<meta name="authors" content="Enrico Tröger Nick Treleaven Frank Lanitz" />
-<meta name="date" content="2010-04-17" />
+<meta name="date" content="2010-04-19" />
<style type="text/css">
/*
@@ -139,7 +139,7 @@
<br />Nick Treleaven
<br />Frank Lanitz</td></tr>
<tr><th class="docinfo-name">Date:</th>
-<td>2010-04-17</td></tr>
+<td>2010-04-19</td></tr>
<tr><th class="docinfo-name">Version:</th>
<td>0.19</td></tr>
</tbody>
@@ -435,7 +435,7 @@
</li>
<li><a class="reference" href="#customizing-templates" id="id200" name="id200">Customizing templates</a><ul>
<li><a class="reference" href="#template-wildcards" id="id201" name="id201">Template wildcards</a><ul>
-<li><a class="reference" href="#special-command-wilcard" id="id202" name="id202">Special {command:} wilcard</a></li>
+<li><a class="reference" href="#special-command-wildcard" id="id202" name="id202">Special {command:} wildcard</a></li>
</ul>
</li>
</ul>
@@ -4886,6 +4886,15 @@
</tr>
</thead>
<tbody valign="top">
+<tr><td>ob</td>
+<td>Opening Brace (used to prevent other
+wildcards being expanded).</td>
+<td>file templates, file header</td>
+</tr>
+<tr><td>cb</td>
+<td>Closing Brace.</td>
+<td>file templates, file header</td>
+</tr>
<tr><td>developer</td>
<td>The name of the developer.</td>
<td>filetype templates, file header,
@@ -4912,7 +4921,7 @@
bsd, gpl, snippets</td>
</tr>
<tr><td>year <a class="footnote-reference" href="#id10" id="id7" name="id7">[1]</a></td>
-<td>The current year. Default format is: YYYY</td>
+<td>The current year. Default format is: YYYY.</td>
<td>filetype templates, file header,
function description, ChangeLog entry,
bsd, gpl, snippets</td>
@@ -4924,7 +4933,8 @@
bsd, gpl, snippets</td>
</tr>
<tr><td>date <a class="footnote-reference" href="#id10" id="id8" name="id8">[1]</a></td>
-<td>The current date. Default format: YYYY-MM-DD.</td>
+<td>The current date. Default format:
+YYYY-MM-DD.</td>
<td>filetype templates, file header,
function description, ChangeLog entry,
bsd, gpl, snippets</td>
@@ -4974,13 +4984,13 @@
<td>The file header template. This wildcard
will only be replaced in filetype
templates.</td>
-<td>file header, snippets, custom filetype
+<td>file header, snippets, file
templates</td>
</tr>
<tr><td>command:path</td>
<td>Executes the specified command and replace
the wildcard with the command's standard
-output. See <a class="reference" href="#special-command-wilcard">Special {command:} wilcard</a>
+output. See <a class="reference" href="#special-command-wildcard">Special {command:} wildcard</a>
for details.</td>
<td>filetype templates, file header,
function description, ChangeLog entry,
@@ -4998,8 +5008,8 @@
</tbody>
</table>
<div class="section">
-<h5><a class="toc-backref" href="#id202" id="special-command-wilcard" name="special-command-wilcard">Special {command:} wilcard</a></h5>
-<p>The {command:} wilcard is a special one because it can execute
+<h5><a class="toc-backref" href="#id202" id="special-command-wildcard" name="special-command-wildcard">Special {command:} wildcard</a></h5>
+<p>The {command:} wildcard is a special one because it can execute
a specified command and put the command's output (stdout) into
the template.</p>
<p>Example:</p>
@@ -5986,7 +5996,7 @@
<div class="footer">
<hr class="footer" />
<a class="reference" href="geany.txt">View document source</a>.
-Generated on: 2010-04-19 12:32 UTC.
+Generated on: 2010-04-21 16:38 UTC.
Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
</div>
Modified: trunk/doc/geany.txt
===================================================================
--- trunk/doc/geany.txt 2010-04-19 21:20:15 UTC (rev 4842)
+++ trunk/doc/geany.txt 2010-04-21 16:47:54 UTC (rev 4843)
@@ -4230,6 +4230,10 @@
============== ============================================= =======================================
Wildcard Description Available in
============== ============================================= =======================================
+ob Opening Brace (used to prevent other file templates, file header
+ wildcards being expanded).
+cb Closing Brace. file templates, file header
+
developer The name of the developer. filetype templates, file header,
function description, ChangeLog entry,
bsd, gpl, snippets
@@ -4246,7 +4250,7 @@
function description, ChangeLog entry,
bsd, gpl, snippets
-year [1]_ The current year. Default format is: YYYY filetype templates, file header,
+year [1]_ The current year. Default format is: YYYY. filetype templates, file header,
function description, ChangeLog entry,
bsd, gpl, snippets
@@ -4254,8 +4258,8 @@
function description, ChangeLog entry,
bsd, gpl, snippets
-date [1]_ The current date. Default format: YYYY-MM-DD. filetype templates, file header,
- function description, ChangeLog entry,
+date [1]_ The current date. Default format: filetype templates, file header,
+ YYYY-MM-DD. function description, ChangeLog entry,
bsd, gpl, snippets
untitled The string "untitled" (this will be filetype templates, file header,
@@ -4281,13 +4285,13 @@
replaced in the function description
template.
-fileheader The file header template. This wildcard file header, snippets, custom filetype
+fileheader The file header template. This wildcard file header, snippets, file
will only be replaced in filetype templates
templates.
command:path Executes the specified command and replace filetype templates, file header,
the wildcard with the command's standard function description, ChangeLog entry,
- output. See `Special {command:} wilcard`_ bsd, gpl, snippets
+ output. See `Special {command:} wildcard`_ bsd, gpl, snippets
for details.
============== ============================================= =======================================
@@ -4298,10 +4302,10 @@
For details please see http://man.cx/strftime.
-Special {command:} wilcard
-**************************
+Special {command:} wildcard
+***************************
-The {command:} wilcard is a special one because it can execute
+The {command:} wildcard is a special one because it can execute
a specified command and put the command's output (stdout) into
the template.
Modified: trunk/src/templates.c
===================================================================
--- trunk/src/templates.c 2010-04-19 21:20:15 UTC (rev 4842)
+++ trunk/src/templates.c 2010-04-21 16:47:54 UTC (rev 4843)
@@ -127,6 +127,7 @@
static void replace_static_values(GString *text);
+static gchar *get_template_fileheader(GeanyFiletype *ft);
/* some simple macros to reduce code size and make the code readable */
@@ -284,6 +285,37 @@
}
+static void templates_replace_common(GString *template, const gchar *fname,
+ GeanyFiletype *ft, const gchar *func_name)
+{
+ gchar *shortname;
+
+ if (fname == NULL)
+ {
+ if (!ft->extension)
+ shortname = g_strdup(GEANY_STRING_UNTITLED);
+ else
+ shortname = g_strconcat(GEANY_STRING_UNTITLED, ".", ft->extension, NULL);
+ }
+ else
+ shortname = g_path_get_basename(fname);
+
+ templates_replace_valist(template,
+ "{filename}", shortname,
+ NULL);
+ g_free(shortname);
+
+ templates_replace_default_dates(template);
+ templates_replace_command(template, fname, ft->name, func_name);
+ /* Bug: command results could have {ob} {cb} strings in! */
+ /* replace braces last */
+ templates_replace_valist(template,
+ "{ob}", "{",
+ "{cb}", "}",
+ NULL);
+}
+
+
static gchar *get_template_from_file(const gchar *locale_fname, const gchar *doc_filename,
GeanyFiletype *ft)
{
@@ -298,13 +330,11 @@
template = g_string_new(content);
- file_header = templates_get_template_fileheader(FILETYPE_ID(ft), doc_filename);
+ file_header = get_template_fileheader(ft);
templates_replace_valist(template,
- "{filename}", doc_filename,
"{fileheader}", file_header,
NULL);
- templates_replace_default_dates(template);
- templates_replace_command(template, doc_filename, ft->name, NULL);
+ templates_replace_common(template, doc_filename, ft, NULL);
utils_free_pointers(2, file_header, content, NULL);
return g_string_free(template, FALSE);
@@ -552,43 +582,38 @@
}
-/* TODO change the signature to take a GeanyDocument although this would break plugin API/ABI */
-gchar *templates_get_template_fileheader(gint filetype_idx, const gchar *fname)
+static gchar *get_template_fileheader(GeanyFiletype *ft)
{
GString *template = g_string_new(templates[GEANY_TEMPLATE_FILEHEADER]);
- gchar *shortname;
gchar *result;
- filetype_id ft_id = filetype_idx;
- GeanyFiletype *ft = filetypes[ft_id];
- filetypes_load_config(ft_id, FALSE); /* load any user extension setting */
+ filetypes_load_config(ft->id, FALSE); /* load any user extension setting */
- if (fname == NULL)
- {
- if (!ft->extension)
- shortname = g_strdup(GEANY_STRING_UNTITLED);
- else
- shortname = g_strconcat(GEANY_STRING_UNTITLED, ".", ft->extension, NULL);
- }
- else
- shortname = g_path_get_basename(fname);
-
templates_replace_valist(template,
- "{filename}", shortname,
"{gpl}", templates[GEANY_TEMPLATE_GPL],
"{bsd}", templates[GEANY_TEMPLATE_BSD],
NULL);
- templates_replace_default_dates(template);
- templates_replace_command(template, fname, ft->name, NULL);
- result = make_comment_block(template->str, ft_id, 8);
-
+ /* 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);
- g_free(shortname);
return result;
}
+/* TODO change the signature to take a GeanyDocument? this would break plugin API/ABI */
+gchar *templates_get_template_fileheader(gint filetype_idx, const gchar *fname)
+{
+ GeanyFiletype *ft = filetypes[filetype_idx];
+ gchar *str = get_template_fileheader(ft);
+ GString *template = g_string_new(str);
+
+ g_free(str);
+ templates_replace_common(template, fname, ft, NULL);
+ return g_string_free(template, FALSE);
+}
+
+
gchar *templates_get_template_new_file(GeanyFiletype *ft)
{
GString *ft_template;
@@ -604,11 +629,10 @@
}
else
{ /* file template only used for new files */
- file_header = templates_get_template_fileheader(ft->id, NULL);
+ file_header = get_template_fileheader(ft);
templates_replace_valist(ft_template, "{fileheader}", file_header, NULL);
}
- templates_replace_default_dates(ft_template);
- templates_replace_command(ft_template, NULL, ft->name, NULL);
+ templates_replace_common(ft_template, NULL, ft, NULL);
g_free(file_header);
return g_string_free(ft_template, 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