[GRASS-SVN] r31543 - grass/branches/develbranch_6/display/d.font
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed May 28 03:53:20 EDT 2008
Author: neteler
Date: 2008-05-28 03:53:20 -0400 (Wed, 28 May 2008)
New Revision: 31543
Modified:
grass/branches/develbranch_6/display/d.font/main.c
Log:
Add checks for valid font name and file path (merge from trunk)
Modified: grass/branches/develbranch_6/display/d.font/main.c
===================================================================
--- grass/branches/develbranch_6/display/d.font/main.c 2008-05-28 07:52:37 UTC (rev 31542)
+++ grass/branches/develbranch_6/display/d.font/main.c 2008-05-28 07:53:20 UTC (rev 31543)
@@ -18,6 +18,9 @@
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <errno.h>
#include <grass/gis.h>
#include <grass/display.h>
#include <grass/raster.h>
@@ -80,27 +83,56 @@
if (R_open_driver() != 0)
G_fatal_error (_("No graphics device selected"));
- if (flag1->answer)
+ if (flag1->answer) /* List font names */
{
print_font_list(stdout, 0);
R_close_driver();
exit(EXIT_SUCCESS);
}
- if (flag2->answer)
+ if (flag2->answer) /* List fonts verbosely */
{
print_font_list(stdout, 1);
R_close_driver();
exit(EXIT_SUCCESS);
}
- if (opt2->answer)
- R_font(opt2->answer);
+ if (opt2->answer) /* Full path to freetype font */
+ {
+ struct stat info;
+
+ /* Check a valid filename has been supplied */
+ if(stat(opt2->answer, &info) != 0)
+ G_fatal_error(_("Unable to access font path %s: %s"),
+ opt2->answer, strerror(errno));
+
+ if(!S_ISREG(info.st_mode))
+ G_fatal_error(_("Font path %s is not a file"), opt2->answer);
+ else
+ R_font(opt2->answer);
+ }
else
- if (opt1->answer)
- R_font(opt1->answer);
+ if (opt1->answer) /* Font name from fontcap */
+ {
+ int i = 0;
- if (opt3->answer)
+ /* Check the fontname given is valid */
+ read_freetype_fonts(0);
+ while (i < num_fonts)
+ {
+ if(strcmp(opt1->answer, fonts[i]) == 0)
+ {
+ R_font(opt1->answer);
+ break;
+ }
+ i++;
+ }
+ if (i >= num_fonts)
+ G_fatal_error(_("Font name <%s> is invalid. Check font name or consider running 'g.mkfontcap'"),
+ opt1->answer);
+ }
+
+ if (opt3->answer) /* Set character encoding */
R_charset(opt3->answer);
/* add this command to the list */
More information about the grass-commit
mailing list