[GRASS-SVN] r39481 - grass/trunk/vector/v.external

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Oct 11 03:18:59 EDT 2009


Author: martinl
Date: 2009-10-11 03:18:58 -0400 (Sun, 11 Oct 2009)
New Revision: 39481

Added:
   grass/trunk/vector/v.external/args.c
Modified:
   grass/trunk/vector/v.external/local_proto.h
   grass/trunk/vector/v.external/main.c
Log:
v.external: parse arguments in parse_args()


Added: grass/trunk/vector/v.external/args.c
===================================================================
--- grass/trunk/vector/v.external/args.c	                        (rev 0)
+++ grass/trunk/vector/v.external/args.c	2009-10-11 07:18:58 UTC (rev 39481)
@@ -0,0 +1,64 @@
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+#include "local_proto.h"
+
+void parse_args(int argc, char **argv,
+		struct _options *options, struct _flags* flags)
+{
+    options->dsn = G_define_option();
+    options->dsn->key = "dsn";
+    options->dsn->type = TYPE_STRING;
+    options->dsn->gisprompt = "old_file,file,dsn";
+    options->dsn->label = _("OGR data source name");
+    options->dsn->description = _("Examples:\n"
+			     "\t\tESRI Shapefile: directory containing shapefiles\n"
+			     "\t\tMapInfo File: directory containing mapinfo files");
+    options->dsn->guisection = _("Data source");
+
+    options->layer = G_define_option();
+    options->layer->key = "layer";
+    options->layer->type = TYPE_STRING;
+    options->layer->required = NO;
+    options->layer->multiple = NO;
+    options->layer->label = _("OGR layer name");
+    options->layer->description = _("Examples:\n"
+				   "\t\tESRI Shapefile: shapefile name\n"
+				   "\t\tMapInfo File: mapinfo file name");
+    options->layer->guisection = _("Data source");
+    
+    options->output = G_define_standard_option(G_OPT_V_OUTPUT);
+    options->output->required = NO;
+    options->output->description = _("Name for GRASS vector map");
+
+    flags->format = G_define_flag();
+    flags->format->key = 'f';
+    flags->format->description = _("List supported OGR formats and exit");
+    flags->format->guisection = _("Print");
+
+    flags->layer = G_define_flag();
+    flags->layer->key = 'l';
+    flags->layer->description = _("List available OGR layers in dsn and exit");
+    flags->layer->guisection = _("Print");
+
+    flags->topo = G_define_flag();
+    flags->topo->key = 'b';
+    flags->topo->description = _("Do not build topology");
+    
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+}
+
+void get_args(const struct _options *options, const struct _flags *flags,
+	      char **dsn, char **layer, char **output,
+	      int *list_format, int *list_layers, int *topo)
+{
+    *dsn    = options->dsn->answer;
+    *layer  = options->layer->answer;
+    *output = options->output->answer;
+    *list_format = flags->format->answer ? 1 : 0;
+    *list_layers = flags->layer->answer ? 1 : 0;
+    *topo        = flags->topo-> answer ? 1 : 0;
+}


Property changes on: grass/trunk/vector/v.external/args.c
___________________________________________________________________
Added: svn:mime-type
   + text/x-csrc
Added: svn:keywords
   + Author Date Id
Added: svn:eol-style
   + native

Modified: grass/trunk/vector/v.external/local_proto.h
===================================================================
--- grass/trunk/vector/v.external/local_proto.h	2009-10-11 07:11:26 UTC (rev 39480)
+++ grass/trunk/vector/v.external/local_proto.h	2009-10-11 07:18:58 UTC (rev 39481)
@@ -1,3 +1,23 @@
+#ifndef V_EXTERNAL_LOCAL_PROTO_H
+#define V_EXTERNAL_LOCAL_PROTO_H
+
+struct _options {
+    struct Option *dsn, *output, *layer;
+};
+
+struct _flags {
+    struct Flag *format, *layer, *topo;
+};
+
+/* args.c */
+void parse_args(int, char **,
+		struct _options *, struct _flags*);
+void get_args(const struct _options *, const struct _flags *,
+	      char **, char **, char **,
+	      int *, int *, int *);
+
 /* list.c */
 void list_formats(FILE *);
 int list_layers(FILE *, const char *, const char *);
+
+#endif

Modified: grass/trunk/vector/v.external/main.c
===================================================================
--- grass/trunk/vector/v.external/main.c	2009-10-11 07:11:26 UTC (rev 39480)
+++ grass/trunk/vector/v.external/main.c	2009-10-11 07:18:58 UTC (rev 39481)
@@ -32,71 +32,28 @@
 int main(int argc, char *argv[])
 {
     struct GModule *module;
-    char buf[GPATH_MAX];
-    FILE *fd;
-    struct Map_info Map;
+    struct _options options;
+    struct _flags   flags;
 
-    int layer;
+    struct Map_info Map;
     
-    struct {
-	struct Option *dsn, *output, *layer;
-    } options;
-
-    struct {
-      struct Flag *format, *layer, *topo;
-    } flags;
+    FILE *fd;
     
+    int ilayer;
+    char buf[GPATH_MAX];
+     
     G_gisinit(argv[0]);
     
     module = G_define_module();
     G_add_keyword(_("vector"));
     G_add_keyword(_("external"));
     G_add_keyword(_("ogr"));
-
-    module->description = _("Creates a new vector as a read-only link to OGR layer.");
-
-    options.dsn = G_define_option();
-    options.dsn->key = "dsn";
-    options.dsn->type = TYPE_STRING;
-    options.dsn->gisprompt = "old_file,file,dsn";
-    options.dsn->label = _("OGR data source name");
-    options.dsn->description = _("Examples:\n"
-				 "\t\tESRI Shapefile: directory containing shapefiles\n"
-				 "\t\tMapInfo File: directory containing mapinfo files");
-    options.dsn->guisection = _("Data source");
-
-    options.layer = G_define_option();
-    options.layer->key = "layer";
-    options.layer->type = TYPE_STRING;
-    options.layer->required = NO;
-    options.layer->multiple = NO;
-    options.layer->label = _("OGR layer name");
-    options.layer->description = _("Examples:\n"
-				   "\t\tESRI Shapefile: shapefile name\n"
-				   "\t\tMapInfo File: mapinfo file name");
-    options.layer->guisection = _("Data source");
-
-    options.output = G_define_standard_option(G_OPT_V_OUTPUT);
-    options.output->required = NO;
-    options.output->description = _("Name for output vector map");
-
-    flags.format = G_define_flag();
-    flags.format->key = 'f';
-    flags.format->description = _("List supported formats and exit");
-    flags.format->guisection = _("Print");
-
-    flags.layer = G_define_flag();
-    flags.layer->key = 'l';
-    flags.layer->description = _("List available layers and exit");
-    flags.layer->guisection = _("Print");
-
-    flags.topo = G_define_flag();
-    flags.topo->key = 'b';
-    flags.topo->description = _("Do not build topology");
     
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
+    module->description = _("Creates a new vector map as a link to OGR layer.");
+    
+    parse_args(argc, argv,
+	       &options, &flags);
+    
     OGRRegisterAll();
     
     if (flags.format->answer) {
@@ -118,8 +75,8 @@
 	G_fatal_error(_("Required parameter <%s> not set"), options.layer->key);
         
 
-    layer = list_layers(NULL, options.dsn->answer, options.layer->answer);
-    if (layer == -1) {
+    ilayer = list_layers(NULL, options.dsn->answer, options.layer->answer);
+    if (ilayer == -1) {
 	G_fatal_error(_("Layer <%s> not available"), options.layer->answer);
     }
     



More information about the grass-commit mailing list