File: args.c

package info (click to toggle)
grass 8.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 277,040 kB
  • sloc: ansic: 460,798; python: 227,732; cpp: 42,026; sh: 11,262; makefile: 7,007; xml: 3,637; sql: 968; lex: 520; javascript: 484; yacc: 450; asm: 387; perl: 157; sed: 25; objc: 6; ruby: 4
file content (108 lines) | stat: -rw-r--r-- 3,988 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#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 = "output";
    options->dsn->type = TYPE_STRING;
    options->dsn->label =
        _("Name of output directory or OGR or PostGIS data source");
    options->dsn->description =
        _("Examples:\n"
          "\t\tESRI Shapefile: directory containing a shapefile\n"
          "\t\tMapInfo File: directory containing a mapinfo file\n"
          "\t\tPostGIS database: connection string, eg. 'PG:dbname=db "
          "user=grass'");
    options->dsn->required = NO;
    options->dsn->guisection = _("Settings");

    options->format = G_define_option();
    options->format->key = "format";
    options->format->description = _("Format for output vector data");
    options->format->required = NO;
    options->format->type = TYPE_STRING;
    options->format->options = format_options();
#ifdef HAVE_OGR
    options->format->answer = "ESRI_Shapefile";
#else
#ifdef HAVE_POSTGRES
    options->format->answer = "PostgreSQL";
#endif /* HAVE_POSTGRES */
#endif /* HAVE_OGR */
    options->format->guisection = _("Settings");

    options->opts = G_define_option();
    options->opts->key = "options";
    options->opts->label = _("Creation options");
    options->opts->description =
        _("Examples:\n"
          "\t\t'SHPT=POINTZ': create 3D point Shapefile data\n"
          "\t\t'GEOM_TYPE=geography': use geography PostGIS data\n"
          "\t\t'SCHEMA=grass': create new PostGIS tables in 'grass' schema");
    options->opts->required = NO;
    options->opts->multiple = YES;
    options->opts->type = TYPE_STRING;
    options->opts->guisection = _("Settings");

    options->input = G_define_standard_option(G_OPT_F_INPUT);
    options->input->key = "loadsettings";
    options->input->required = NO;
    options->input->description = _("Name of input file to read settings from");
    options->input->guisection = _("Settings");

    options->output = G_define_standard_option(G_OPT_F_OUTPUT);
    options->output->key = "savesettings";
    options->output->required = NO;
    options->output->description =
        _("Name for output file where to save current settings");

    flags->f = G_define_flag();
    flags->f->key = 'f';
    flags->f->description = _("List supported formats and exit");
    flags->f->guisection = _("Print");
    flags->f->suppress_required = YES;

    flags->r = G_define_flag();
    flags->r->key = 'r';
    flags->r->description =
        _("Cease using OGR/PostGIS, revert to native output and exit");
    flags->r->suppress_required = YES;
    flags->r->guisection = _("Native");

    flags->p = G_define_flag();
    flags->p->key = 'p';
    flags->p->description = _("Print current status");
    flags->p->guisection = _("Print");
    flags->p->suppress_required = YES;

    flags->g = G_define_flag();
    flags->g->key = 'g';
    flags->g->description = _("Print current status in shell script style");
    flags->g->guisection = _("Print");
    flags->g->suppress_required = YES;

    if (G_parser(argc, argv))
        exit(EXIT_FAILURE);

    /* check options */
    if (options->dsn->answer && options->format->answer &&
        options->input->answer)
        G_fatal_error(_("%s= and %s=/%s= are mutually exclusive"),
                      options->input->key, options->dsn->key,
                      options->format->key);
    if (flags->f->answer || flags->p->answer || flags->r->answer ||
        flags->g->answer || options->output->answer)
        return;

    if (!options->dsn->answer && !options->input->answer)
        G_fatal_error(_("%s= or %s= must be specified"), options->dsn->key,
                      options->input->key);
    if (options->dsn->answer && !options->format->answer)
        G_fatal_error(_("%s= must be specified"), options->format->key);
}