~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to temporal/t.connect/main.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/****************************************************************************
 
3
 *
 
4
 * MODULE:       t.connect
 
5
 * AUTHOR(S):    Soeren Gebbert, based on db.connect
 
6
 *
 
7
 * PURPOSE:      Prints/sets general temporal GIS database connection for current mapset.
 
8
 * COPYRIGHT:    (C) 2002-2010 by the GRASS Development Team
 
9
 *
 
10
 *               This program is free software under the GNU General Public
 
11
 *               License (>=v2). Read the file COPYING that comes with GRASS
 
12
 *               for details.
 
13
 *
 
14
 *****************************************************************************/
 
15
#include <stdio.h>
 
16
#include <stdlib.h>
 
17
#include <string.h>
 
18
#include <grass/gis.h>
 
19
#include <grass/temporal.h>
 
20
#include <grass/glocale.h>
 
21
 
 
22
int main(int argc, char *argv[])
 
23
{
 
24
    dbConnection conn;
 
25
    struct Flag *print, *check_set_default, *def, *sh;
 
26
    struct Option *driver, *database;
 
27
    struct GModule *module;
 
28
 
 
29
    /* Initialize the GIS calls */
 
30
    G_gisinit(argv[0]);
 
31
 
 
32
    /* Set description */
 
33
    module = G_define_module();
 
34
    G_add_keyword(_("database"));
 
35
    G_add_keyword(_("attribute table"));
 
36
    G_add_keyword(_("connection settings"));
 
37
    module->description =
 
38
        _("Prints/sets general temporal GIS database connection for current mapset.");
 
39
 
 
40
    print = G_define_flag();
 
41
    print->key = 'p';
 
42
    print->description = _("Print current connection parameters and exit");
 
43
    print->guisection = _("Print");
 
44
 
 
45
    check_set_default = G_define_flag();
 
46
    check_set_default->key = 'c';
 
47
    check_set_default->description =
 
48
        _("Check connection parameters, set if uninitialized, and exit");
 
49
    check_set_default->guisection = _("Set");
 
50
    
 
51
    def = G_define_flag();
 
52
    def->key = 'd';
 
53
    def->label = _("Set from default settings and exit");
 
54
    def->description = _("Overwrite current settings if initialized");
 
55
    def->guisection = _("Set");
 
56
    
 
57
    sh = G_define_flag();
 
58
    sh->key = 'g';
 
59
    sh->description = _("Print current connection parameter in shell style and exit");
 
60
    sh->guisection = _("Set");
 
61
 
 
62
    driver = G_define_standard_option(G_OPT_DB_DRIVER);
 
63
    driver->options = "sqlite,pg";
 
64
    driver->answer = (char *) tgis_get_default_driver_name();
 
65
    driver->guisection = _("Set");
 
66
 
 
67
    database = G_define_standard_option(G_OPT_DB_DATABASE);
 
68
    database->answer = (char *) tgis_get_default_database_name();
 
69
    database->guisection = _("Set");
 
70
 
 
71
    if (G_parser(argc, argv))
 
72
        exit(EXIT_FAILURE);
 
73
 
 
74
    if (print->answer) {
 
75
        if(sh->answer) {
 
76
            if (tgis_get_connection(&conn) == DB_OK) {
 
77
                fprintf(stdout, "driver=%s\n",
 
78
                        conn.driverName ? conn.driverName : "");
 
79
                fprintf(stdout, "database=%s\n",
 
80
                        conn.databaseName ? conn.databaseName : "");
 
81
            }
 
82
            else
 
83
                G_fatal_error(_("Temporal GIS database connection not defined. "
 
84
                                "Run t.connect."));
 
85
 
 
86
        } else {
 
87
        /* get and print connection */
 
88
            if (tgis_get_connection(&conn) == DB_OK) {
 
89
                fprintf(stdout, "driver:%s\n",
 
90
                        conn.driverName ? conn.driverName : "");
 
91
                fprintf(stdout, "database:%s\n",
 
92
                        conn.databaseName ? conn.databaseName : "");
 
93
            }
 
94
            else
 
95
                G_fatal_error(_("Temporal GIS database connection not defined. "
 
96
                                "Run t.connect."));
 
97
        }
 
98
 
 
99
        exit(EXIT_SUCCESS);
 
100
    }
 
101
 
 
102
    if (check_set_default->answer) {
 
103
        /* check connection and set to system-wide default in required */
 
104
        tgis_get_connection(&conn);
 
105
 
 
106
        if (!conn.driverName && !conn.databaseName) {
 
107
 
 
108
            tgis_set_default_connection();
 
109
            tgis_get_connection(&conn);
 
110
 
 
111
            G_important_message(_("Default TGIS driver / database set to:\n"
 
112
                                  "driver: %s\ndatabase: %s"), conn.driverName,
 
113
                                conn.databaseName);
 
114
        }
 
115
        /* they must be a matched pair, so if one is set but not the other
 
116
           then give up and let the user figure it out */
 
117
        else if (!conn.driverName) {
 
118
            G_fatal_error(_("Default TGIS driver is not set"));
 
119
        }
 
120
        else if (!conn.databaseName) {
 
121
            G_fatal_error(_("Default TGIS database is not set"));
 
122
        }
 
123
 
 
124
        /* connection either already existed or now exists */
 
125
        exit(EXIT_SUCCESS);
 
126
    }
 
127
 
 
128
 
 
129
    if (def->answer) {
 
130
        tgis_set_default_connection();
 
131
        tgis_get_connection(&conn);
 
132
        
 
133
        G_important_message(_("Default driver / database set to:\n"
 
134
                              "driver: %s\ndatabase: %s"), conn.driverName,
 
135
                            conn.databaseName);
 
136
        exit(EXIT_SUCCESS);
 
137
    }
 
138
    
 
139
    /* set connection */
 
140
    tgis_get_connection(&conn); /* read current */
 
141
 
 
142
    if (driver->answer)
 
143
        conn.driverName = driver->answer;
 
144
 
 
145
    if (database->answer)
 
146
        conn.databaseName = database->answer;
 
147
 
 
148
    tgis_set_connection(&conn);
 
149
 
 
150
    exit(EXIT_SUCCESS);
 
151
}