SF.net SVN: geany:[5012] branches/unstable

ntrel at users.sourceforge.net ntrel at xxxxx
Wed Jun 9 12:27:58 UTC 2010


Revision: 5012
          http://geany.svn.sourceforge.net/geany/?rev=5012&view=rev
Author:   ntrel
Date:     2010-06-09 12:27:58 +0000 (Wed, 09 Jun 2010)

Log Message:
-----------
Move general templates from source code into files.
Load general templates from system path instead of creating them in
the user's config dir.

Modified Paths:
--------------
    branches/unstable/ChangeLog
    branches/unstable/Makefile.am
    branches/unstable/src/templates.c
    branches/unstable/wscript

Added Paths:
-----------
    branches/unstable/data/templates/bsd
    branches/unstable/data/templates/changelog
    branches/unstable/data/templates/fileheader
    branches/unstable/data/templates/function
    branches/unstable/data/templates/gpl

Modified: branches/unstable/ChangeLog
===================================================================
--- branches/unstable/ChangeLog	2010-06-09 12:21:39 UTC (rev 5011)
+++ branches/unstable/ChangeLog	2010-06-09 12:27:58 UTC (rev 5012)
@@ -1,3 +1,13 @@
+2010-06-09  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>
+
+ * src/templates.c, data/templates/gpl, data/templates/function,
+   data/templates/changelog, data/templates/bsd,
+   data/templates/fileheader, wscript, Makefile.am:
+   Move general templates from source code into files.
+   Load general templates from system path instead of creating them in
+   the user's config dir.
+
+
 2010-06-08  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>
 
  * Makefile.am:

Modified: branches/unstable/Makefile.am
===================================================================
--- branches/unstable/Makefile.am	2010-06-09 12:21:39 UTC (rev 5011)
+++ branches/unstable/Makefile.am	2010-06-09 12:27:58 UTC (rev 5012)
@@ -22,6 +22,7 @@
 	data/filetype_extensions.conf \
 	data/snippets.conf \
 	data/ui_toolbar.xml \
+	$(srcdir)/data/templates/* \
 	$(srcdir)/data/templates/files/*
 
 EXTRA_DIST = \
@@ -63,6 +64,11 @@
 	  fi \
 	done
 	$(mkinstalldirs) $(DESTDIR)$(pkgdatadir)/templates;
+	for file in $(srcdir)/data/templates/*; do \
+	  if test -f $$file; then \
+	    $(INSTALL_DATA) $$file $(DESTDIR)$(pkgdatadir)/templates/; \
+	  fi \
+	done
 	$(mkinstalldirs) $(DESTDIR)$(pkgdatadir)/templates/files;
 	for file in $(srcdir)/data/templates/files/*; do \
 	  if test -f $$file; then \

Added: branches/unstable/data/templates/bsd
===================================================================
--- branches/unstable/data/templates/bsd	                        (rev 0)
+++ branches/unstable/data/templates/bsd	2010-06-09 12:27:58 UTC (rev 5012)
@@ -0,0 +1,26 @@
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+* Redistributions of source code must retain the above copyright
+  notice, this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above
+  copyright notice, this list of conditions and the following disclaimer
+  in the documentation and/or other materials provided with the
+  distribution.
+* Neither the name of the {company} nor the names of its
+  contributors may be used to endorse or promote products derived from
+  this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+


Property changes on: branches/unstable/data/templates/bsd
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + native

Added: branches/unstable/data/templates/changelog
===================================================================
--- branches/unstable/data/templates/changelog	                        (rev 0)
+++ branches/unstable/data/templates/changelog	2010-06-09 12:27:58 UTC (rev 5012)
@@ -0,0 +1,6 @@
+{date}  {developer}  <{mail}>
+
+ * 
+
+
+


Property changes on: branches/unstable/data/templates/changelog
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + native

Added: branches/unstable/data/templates/fileheader
===================================================================
--- branches/unstable/data/templates/fileheader	                        (rev 0)
+++ branches/unstable/data/templates/fileheader	2010-06-09 12:27:58 UTC (rev 5012)
@@ -0,0 +1,5 @@
+{filename}
+
+Copyright {year} {developer} <{mail}>
+
+{gpl}


Property changes on: branches/unstable/data/templates/fileheader
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + native

Added: branches/unstable/data/templates/function
===================================================================
--- branches/unstable/data/templates/function	                        (rev 0)
+++ branches/unstable/data/templates/function	2010-06-09 12:27:58 UTC (rev 5012)
@@ -0,0 +1,5 @@
+
+name: {functionname}
+ at param
+ at return
+


Property changes on: branches/unstable/data/templates/function
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + native

Added: branches/unstable/data/templates/gpl
===================================================================
--- branches/unstable/data/templates/gpl	                        (rev 0)
+++ branches/unstable/data/templates/gpl	2010-06-09 12:27:58 UTC (rev 5012)
@@ -0,0 +1,15 @@
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+MA 02110-1301, USA.
+


Property changes on: branches/unstable/data/templates/gpl
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + native

Modified: branches/unstable/src/templates.c
===================================================================
--- branches/unstable/src/templates.c	2010-06-09 12:21:39 UTC (rev 5011)
+++ branches/unstable/src/templates.c	2010-06-09 12:27:58 UTC (rev 5012)
@@ -102,11 +102,6 @@
 @return\n\
 ";
 
-static const gchar templates_multiline[] = "\
- \n\
- \n\
-";
-
 static const gchar templates_fileheader[] = "\
 {filename}\n\
 \n\
@@ -145,24 +140,30 @@
 	g_file_get_contents(fname, contents_ptr, NULL, NULL);
 
 
-static void create_template_file_if_necessary(const gchar *filename, const gchar *content)
+static void read_template(const gchar *name, gint id)
 {
-	if (! g_file_test(filename, G_FILE_TEST_EXISTS))
+	gchar *fname = TEMPLATES_GET_FILENAME(name);
+
+	/* try system if user template doesn't exist */
+	if (!g_file_test(fname, G_FILE_TEST_EXISTS))
+		setptr(fname, g_strconcat(app->datadir,
+			G_DIR_SEPARATOR_S GEANY_TEMPLATES_SUBDIR G_DIR_SEPARATOR_S, name, NULL));
+
+	TEMPLATES_READ_FILE(fname, &templates[id]);
+
+	/* FIXME: we should replace the line ends on insertion with doc pref, not on loading */
+	if (file_prefs.default_eol_character != SC_EOL_LF)
 	{
-		if (file_prefs.default_eol_character != SC_EOL_LF)
-		{
-			/* Replace the \n characters in the default template text by the proper
-			 * platform-specific line ending characters. */
-			GString *tmp = g_string_new(content);
-			const gchar *eol_str = (file_prefs.default_eol_character == SC_EOL_CR) ? "\r" : "\r\n";
+		/* Replace the \n characters in the default template text by the proper
+		 * platform-specific line ending characters. */
+		GString *tmp = g_string_new(templates[id]);
+		const gchar *eol_str = (file_prefs.default_eol_character == SC_EOL_CR) ? "\r" : "\r\n";
 
-			utils_string_replace_all(tmp, "\n", eol_str);
-			utils_write_file(filename, tmp->str);
-			g_string_free(tmp, TRUE);
-		}
-		else
-			utils_write_file(filename, content);
+		utils_string_replace_all(tmp, "\n", eol_str);
+		setptr(templates[id], tmp->str);
+		g_string_free(tmp, FALSE);
 	}
+	g_free(fname);
 }
 
 
@@ -189,41 +190,18 @@
 
 static void init_general_templates(const gchar *year, const gchar *date, const gchar *datetime)
 {
-	gchar *template_filename_fileheader = TEMPLATES_GET_FILENAME("fileheader");
-	gchar *template_filename_gpl = TEMPLATES_GET_FILENAME("gpl");
-	gchar *template_filename_bsd = TEMPLATES_GET_FILENAME("bsd");
-	gchar *template_filename_function = TEMPLATES_GET_FILENAME("function");
-	gchar *template_filename_changelog = TEMPLATES_GET_FILENAME("changelog");
+	guint id;
 
-	/* create the template files in the configuration directory, if they don't exist */
-	create_template_file_if_necessary(template_filename_fileheader, templates_fileheader);
-	create_template_file_if_necessary(template_filename_gpl, templates_gpl_notice);
-	create_template_file_if_necessary(template_filename_bsd, templates_bsd_notice);
-	create_template_file_if_necessary(template_filename_function, templates_function_description);
-	create_template_file_if_necessary(template_filename_changelog, templates_changelog);
-
 	/* read the contents */
-	TEMPLATES_READ_FILE(template_filename_fileheader, &templates[GEANY_TEMPLATE_FILEHEADER]);
-	templates[GEANY_TEMPLATE_FILEHEADER] = replace_all(templates[GEANY_TEMPLATE_FILEHEADER], year, date, datetime);
+	read_template("fileheader", GEANY_TEMPLATE_FILEHEADER);
+	read_template("gpl", GEANY_TEMPLATE_GPL);
+	read_template("bsd", GEANY_TEMPLATE_BSD);
+	read_template("function", GEANY_TEMPLATE_FUNCTION);
+	read_template("changelog", GEANY_TEMPLATE_CHANGELOG);
 
-	TEMPLATES_READ_FILE(template_filename_gpl, &templates[GEANY_TEMPLATE_GPL]);
-	templates[GEANY_TEMPLATE_GPL] = replace_all(templates[GEANY_TEMPLATE_GPL], year, date, datetime);
-
-	TEMPLATES_READ_FILE(template_filename_bsd, &templates[GEANY_TEMPLATE_BSD]);
-	templates[GEANY_TEMPLATE_BSD] = replace_all(templates[GEANY_TEMPLATE_BSD], year, date, datetime);
-
-	TEMPLATES_READ_FILE(template_filename_function, &templates[GEANY_TEMPLATE_FUNCTION]);
-	templates[GEANY_TEMPLATE_FUNCTION] = replace_all(templates[GEANY_TEMPLATE_FUNCTION], year, date, datetime);
-
-	TEMPLATES_READ_FILE(template_filename_changelog, &templates[GEANY_TEMPLATE_CHANGELOG]);
-	templates[GEANY_TEMPLATE_CHANGELOG] = replace_all(templates[GEANY_TEMPLATE_CHANGELOG], year, date, datetime);
-
-	/* free the whole stuff */
-	g_free(template_filename_fileheader);
-	g_free(template_filename_gpl);
-	g_free(template_filename_bsd);
-	g_free(template_filename_function);
-	g_free(template_filename_changelog);
+	/* FIXME: we should replace the dates on insertion, not on loading */
+	for (id = 0; id < GEANY_MAX_TEMPLATES; id++)
+		templates[id] = replace_all(templates[id], year, date, datetime);
 }
 
 

Modified: branches/unstable/wscript
===================================================================
--- branches/unstable/wscript	2010-06-09 12:21:39 UTC (rev 5011)
+++ branches/unstable/wscript	2010-06-09 12:27:58 UTC (rev 5012)
@@ -518,6 +518,7 @@
 	bld.install_files('${DATADIR}/%s' % dir, 'data/*.tags')
 	bld.install_files('${DATADIR}/%s' % dir, 'data/snippets.conf')
 	bld.install_files('${DATADIR}/%s' % dir, 'data/ui_toolbar.xml')
+	bld.install_files('${DATADIR}/%s/templates' % dir, 'data/templates/*')
 	bld.install_files('${DATADIR}/%s/templates/files' % dir, 'data/templates/files/*.*')
 	bld.install_as('${DATADIR}/%s/GPL-2' % dir, 'COPYING')
 	# Icons


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