[GRASS-SVN] r54536 - in grass/trunk: include/defs lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Jan 5 10:20:06 PST 2013
Author: martinl
Date: 2013-01-05 10:20:05 -0800 (Sat, 05 Jan 2013)
New Revision: 54536
Modified:
grass/trunk/include/defs/gis.h
grass/trunk/lib/gis/parser.c
Log:
libgis: add G_option_to_separator()
Modified: grass/trunk/include/defs/gis.h
===================================================================
--- grass/trunk/include/defs/gis.h 2013-01-05 15:26:21 UTC (rev 54535)
+++ grass/trunk/include/defs/gis.h 2013-01-05 18:20:05 UTC (rev 54536)
@@ -484,6 +484,7 @@
void G_add_keyword(const char *);
void G_set_keywords(const char *);
int G_get_overwrite();
+char G_option_to_separator(const struct Option *);
/* paths.c */
int G_mkdir(const char *);
Modified: grass/trunk/lib/gis/parser.c
===================================================================
--- grass/trunk/lib/gis/parser.c 2013-01-05 15:26:21 UTC (rev 54535)
+++ grass/trunk/lib/gis/parser.c 2013-01-05 18:20:05 UTC (rev 54536)
@@ -1393,3 +1393,51 @@
st->error = G_realloc(st->error, sizeof(char *) * (st->n_errors + 1));
st->error[st->n_errors++] = G_store(msg);
}
+
+/*!
+ \brief Get separator from the option.
+
+ Calls G_fatal_error() on error.
+
+ \code
+ char fs;
+ struct Option *opt_fs;
+
+ opt_fs = G_define_standard_option(G_OPT_F_SEP);
+
+ if (G_parser(argc, argv))
+ exit(EXIT_FAILURE);
+
+ fs = G_option_to_separator(opt_fs);
+ \endcode
+
+ \param option pointer to separator option
+
+ \return character to be used as separator
+*/
+char G_option_to_separator(const struct Option *option)
+{
+ char sep;
+
+ if (option->answer == NULL)
+ G_fatal_error(_("No separator given"));
+
+ if (strcmp(option->answer, "space") == 0)
+ sep = ' ';
+ else if (strcmp(option->answer, "tab") == 0 ||
+ strcmp(option->answer, "\\t") == 0)
+ sep = '\t';
+ else if (strcmp(option->answer, "newline") == 0)
+ sep = '\n';
+ else if (strcmp(option->answer, "comma") == 0)
+ sep = ',';
+ else {
+ if (strlen(option->answer) > 1)
+ G_warning(_("Option <%s>: '%s' is too long, using only first character '%c'"),
+ option->key, option->answer, option->answer[0]);
+
+ sep = option->answer[0];
+ }
+
+ return sep;
+}
More information about the grass-commit
mailing list