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

« back to all changes in this revision

Viewing changes to lib/gis/env.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
 
   \file env.c
4
 
 
5
 
   \brief GIS library - environment routines
6
 
   
7
 
   (C) 2001-2008 by the GRASS Development Team
8
 
   
9
 
   This program is free software under the 
10
 
   GNU General Public License (>=v2). 
11
 
   Read the file COPYING that comes with GRASS
12
 
   for details.
13
 
   
14
 
   \author Original author CERL
 
1
/*!
 
2
  \file lib/gis/env.c
 
3
 
 
4
  \brief GIS library - environment routines
 
5
  
 
6
  (C) 2001-2014 by the GRASS Development Team
 
7
  
 
8
  This program is free software under the GNU General Public License
 
9
  (>=v2).  Read the file COPYING that comes with GRASS for details.
 
10
  
 
11
  \author Original author CERL
 
12
  \author Updated for GRASS7 by Glynn Clements
15
13
*/
16
14
 
17
15
#include <signal.h>
22
20
#include <grass/gis.h>
23
21
#include <grass/glocale.h>
24
22
 
25
 
#define ENV struct env
26
 
 
27
 
ENV {
 
23
struct bind {
28
24
    int loc;
29
25
    char *name;
30
26
    char *value;
31
27
};
32
28
 
33
 
static ENV *env = NULL;
34
 
static ENV *env2 = NULL;
35
 
static int count = 0;
36
 
static int count2 = 0;
37
 
static int init[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
38
 
static char *gisrc = NULL;
39
 
static int varmode = G_GISRC_MODE_FILE; /* where find/store variables */
 
29
struct env {
 
30
    struct bind *binds;
 
31
    int count;
 
32
    int size;
 
33
};
 
34
 
 
35
static struct state {
 
36
    struct env env;
 
37
    struct env env2;
 
38
    char *gisrc;
 
39
    int varmode;
 
40
    int init[2];
 
41
} state;
 
42
 
 
43
static struct state *st = &state;
40
44
 
41
45
static int read_env(int);
42
46
static int set_env(const char *, const char *, int);
43
47
static int unset_env(const char *, int);
44
 
static char *get_env(const char *, int);
45
 
static int write_env(int);
 
48
static const char *get_env(const char *, int);
 
49
static void write_env(int);
 
50
static void parse_env(FILE *, int);
 
51
static void force_read_env(int);
46
52
static FILE *open_env(const char *, int);
47
53
 
48
 
/**
49
 
   \brief Set where to find/store variables
50
 
 
51
 
   Modes:
52
 
    - G_GISRC_MODE_FILE
53
 
    - G_GISRC_MODE_MEMORY 
 
54
/*!
 
55
  \brief Set where to find/store variables
 
56
  
 
57
  Modes:
 
58
   - G_GISRC_MODE_FILE
 
59
   - G_GISRC_MODE_MEMORY 
54
60
 
55
61
   \param mode mode to find/store variables (G_GISRC_MODE_FILE by default)
56
 
 
57
 
   \return
58
62
*/
59
63
void G_set_gisrc_mode(int mode)
60
64
{
61
 
    varmode = mode;
 
65
    st->varmode = mode;
62
66
}
63
67
 
64
 
/**
65
 
   \brief Get info where variables are stored
66
 
 
67
 
   \param
68
 
 
69
 
   \return mode
 
68
/*!
 
69
  \brief Get info where variables are stored
 
70
  
 
71
  \return mode
70
72
*/
71
73
int G_get_gisrc_mode(void)
72
74
{
73
 
    return (varmode);
74
 
}
75
 
 
76
 
static int read_env(int loc)
77
 
{
 
75
    return (st->varmode);
 
76
}
 
77
 
 
78
/*!
 
79
  \brief Initialize variables
 
80
  
 
81
  \return
 
82
*/
 
83
void G_init_env(void)
 
84
{
 
85
    read_env(G_VAR_GISRC);
 
86
    read_env(G_VAR_MAPSET);
 
87
}
 
88
 
 
89
/*!
 
90
 * \brief Force to read the mapset environment file VAR
 
91
 * 
 
92
 * The mapset specific VAR file of the mapset set with G_setenv()
 
93
 * will be read into memory, ignoring if it was readed before. 
 
94
 * Existing values will be overwritten, new values appended.
 
95
 * 
 
96
 * \return
 
97
 */ 
 
98
void G__read_mapset_env(void)
 
99
{
 
100
    force_read_env(G_VAR_MAPSET);
 
101
}
 
102
 
 
103
/*!
 
104
 * \brief Force to read the GISRC environment file
 
105
 * 
 
106
 * The GISRC file 
 
107
 * will be read into memory, ignoring if it was readed before. 
 
108
 * Existing values will be overwritten, new values appended.
 
109
 * 
 
110
 * \return
 
111
 */ 
 
112
void G__read_gisrc_env(void)
 
113
{
 
114
    force_read_env(G_VAR_GISRC);
 
115
}
 
116
 
 
117
static void parse_env(FILE *fd, int loc)
 
118
{    
78
119
    char buf[200];
79
120
    char *name;
80
121
    char *value;
81
122
 
82
 
    FILE *fd;
83
 
 
84
 
    if (loc == G_VAR_GISRC && varmode == G_GISRC_MODE_MEMORY)
85
 
        return 0;               /* don't use file for GISRC */
86
 
 
87
 
    if (init[loc])
88
 
        return 1;
89
 
 
90
 
    init[loc] = 1;
91
 
 
92
 
    if ((fd = open_env("r", loc))) {
93
 
        while (G_getl2(buf, sizeof buf, fd)) {
 
123
    while (G_getl2(buf, sizeof buf, fd)) {
94
124
            for (name = value = buf; *value; value++)
95
125
                if (*value == ':')
96
126
                    break;
103
133
            if (*name && *value)
104
134
                set_env(name, value, loc);
105
135
        }
106
 
        fclose(fd);
 
136
}
 
137
 
 
138
static int read_env(int loc)
 
139
{
 
140
 
 
141
    FILE *fd;
 
142
 
 
143
    if (loc == G_VAR_GISRC && st->varmode == G_GISRC_MODE_MEMORY)
 
144
        return 0;               /* don't use file for GISRC */
 
145
 
 
146
    if (G_is_initialized(&st->init[loc]))
 
147
        return 1;
 
148
 
 
149
    if ((fd = open_env("r", loc))) {
 
150
        parse_env(fd, loc);
 
151
        fclose(fd);
107
152
    }
108
153
 
 
154
    G_initialize_done(&st->init[loc]);
109
155
    return 0;
110
156
}
111
157
 
 
158
/*!
 
159
 * \brief Force the reading or the GISRC or MAPSET/VAR files
 
160
 * and overwrite/append the specified variables
 
161
 * 
 
162
 */ 
 
163
static void force_read_env(int loc)
 
164
{
 
165
    FILE *fd;
 
166
    if ((fd = open_env("r", loc))) {
 
167
        parse_env(fd, loc);
 
168
        fclose(fd);
 
169
    }
 
170
}
 
171
 
 
172
 
112
173
static int set_env(const char *name, const char *value, int loc)
113
174
{
114
175
    int n;
135
196
     *   and look for name in the environment
136
197
     */
137
198
    empty = -1;
138
 
    for (n = 0; n < count; n++)
139
 
        if (!env[n].name)       /* mark empty slot found */
 
199
    for (n = 0; n < st->env.count; n++) {
 
200
        struct bind *b = &st->env.binds[n];
 
201
        if (!b->name)   /* mark empty slot found */
140
202
            empty = n;
141
 
        else if (strcmp(env[n].name, name) == 0 && env[n].loc == loc) {
142
 
            env[n].value = tv;
 
203
        else if (strcmp(b->name, name) == 0 && b->loc == loc) {
 
204
            b->value = tv;
143
205
            return 1;
144
206
        }
 
207
    }
145
208
 
146
209
    /* add name to env: to empty slot if any */
147
210
    if (empty >= 0) {
148
 
        env[empty].loc = loc;
149
 
        env[empty].name = G_store(name);
150
 
        env[empty].value = tv;
 
211
        struct bind *b = &st->env.binds[empty];
 
212
        b->loc = loc;
 
213
        b->name = G_store(name);
 
214
        b->value = tv;
151
215
        return 0;
152
216
    }
153
217
 
154
218
    /* must increase the env list and add in */
155
 
    if ((n = count++))
156
 
        env = (ENV *) G_realloc((char *)env, count * sizeof(ENV));
157
 
    else
158
 
        env = (ENV *) G_malloc(sizeof(ENV));
159
 
 
160
 
    env[n].loc = loc;
161
 
    env[n].name = G_store(name);
162
 
    env[n].value = tv;
 
219
    if (st->env.count >= st->env.size) {
 
220
        st->env.size += 20;
 
221
        st->env.binds = G_realloc(st->env.binds, st->env.size * sizeof(struct bind));
 
222
    }
 
223
 
 
224
    {
 
225
        struct bind *b = &st->env.binds[st->env.count++];
 
226
 
 
227
        b->loc = loc;
 
228
        b->name = G_store(name);
 
229
        b->value = tv;
 
230
    }
163
231
 
164
232
    return 0;
165
233
}
168
236
{
169
237
    int n;
170
238
 
171
 
    for (n = 0; n < count; n++)
172
 
        if (env[n].name && (strcmp(env[n].name, name) == 0) &&
173
 
            env[n].loc == loc) {
174
 
            G_free(env[n].name);
175
 
            env[n].name = 0;
 
239
    for (n = 0; n < st->env.count; n++) {
 
240
        struct bind *b = &st->env.binds[n];
 
241
        if (b->name && strcmp(b->name, name) == 0 && b->loc == loc) {
 
242
            G_free(b->name);
 
243
            b->name = 0;
176
244
            return 1;
177
245
        }
 
246
    }
178
247
 
179
248
    return 0;
180
249
}
181
250
 
182
 
static char *get_env(const char *name, int loc)
 
251
static const char *get_env(const char *name, int loc)
183
252
{
184
253
    int n;
185
254
 
186
 
    for (n = 0; n < count; n++) {
187
 
        if (env[n].name && (strcmp(env[n].name, name) == 0) &&
188
 
            env[n].loc == loc)
189
 
            return env[n].value;
 
255
    for (n = 0; n < st->env.count; n++) {
 
256
        struct bind *b = &st->env.binds[n];
 
257
        if (b->name && (strcmp(b->name, name) == 0) &&
 
258
            b->loc == loc)
 
259
            return b->value;
190
260
    }
191
261
 
192
262
    return NULL;
193
263
}
194
264
 
195
 
static int write_env(int loc)
 
265
static void write_env(int loc)
196
266
{
197
267
    FILE *fd;
198
268
    int n;
199
269
    char dummy[2];
200
 
    void (*sigint) ()
 
270
    RETSIGTYPE (*sigint)(int);
201
271
#ifdef SIGQUIT
202
 
     , (*sigquit) ()
 
272
    RETSIGTYPE (*sigquit)(int);
203
273
#endif
204
 
     ;
205
274
 
206
 
    if (loc == G_VAR_GISRC && varmode == G_GISRC_MODE_MEMORY)
207
 
        return 0;               /* don't use file for GISRC */
 
275
    if (loc == G_VAR_GISRC && st->varmode == G_GISRC_MODE_MEMORY)
 
276
        return;         /* don't use file for GISRC */
208
277
 
209
278
    /*
210
279
     * THIS CODE NEEDS TO BE PROTECTED FROM INTERRUPTS
215
284
    sigquit = signal(SIGQUIT, SIG_IGN);
216
285
#endif
217
286
    if ((fd = open_env("w", loc))) {
218
 
        for (n = 0; n < count; n++)
219
 
            if (env[n].name && env[n].value && env[n].loc == loc
220
 
                && (sscanf(env[n].value, "%1s", dummy) == 1))
221
 
                fprintf(fd, "%s: %s\n", env[n].name, env[n].value);
 
287
        for (n = 0; n < st->env.count; n++) {
 
288
            struct bind *b = &st->env.binds[n];
 
289
            if (b->name && b->value && b->loc == loc
 
290
                && (sscanf(b->value, "%1s", dummy) == 1))
 
291
                fprintf(fd, "%s: %s\n", b->name, b->value);
 
292
        }
222
293
        fclose(fd);
223
294
    }
224
295
 
226
297
#ifdef SIGQUIT
227
298
    signal(SIGQUIT, sigquit);
228
299
#endif
229
 
 
230
 
    return 0;
231
300
}
232
301
 
233
302
static FILE *open_env(const char *mode, int loc)
234
303
{
235
 
    char buf[1000];
 
304
    char buf[GPATH_MAX];
236
305
 
237
306
    if (loc == G_VAR_GISRC) {
238
 
        if (!gisrc)
239
 
            gisrc = getenv("GISRC");
 
307
        if (!st->gisrc)
 
308
            st->gisrc = getenv("GISRC");
240
309
 
241
 
        if (!gisrc) {
 
310
        if (!st->gisrc) {
242
311
            G_fatal_error(_("GISRC - variable not set"));
243
 
            return (NULL);
 
312
            return NULL;
244
313
        }
245
 
        strcpy(buf, gisrc);
 
314
        strcpy(buf, st->gisrc);
246
315
    }
247
316
    else if (loc == G_VAR_MAPSET) {
248
317
        /* Warning: G_VAR_GISRC must be previously read -> */
255
324
    return fopen(buf, mode);
256
325
}
257
326
 
258
 
/**
259
 
   \brief Get environment variable
260
 
 
261
 
   Calls G_fatal_error() if name not set.
262
 
 
263
 
   \param name variable name
264
 
 
265
 
   \return char pointer to value for name
266
 
*/
267
 
char *G_getenv(const char *name)
268
 
{
269
 
    char *value;
270
 
 
271
 
    if ((value = G__getenv(name)))
272
 
        return value;
273
 
 
274
 
    G_fatal_error(_("G_getenv(): Variable %s not set"), name);
275
 
    return NULL;
276
 
}
277
 
 
278
 
/**
279
 
   \brief Read variable from specific place
280
 
 
281
 
   Locations:
282
 
    - G_VAR_GISRC
283
 
    - G_VAR_MAPSET
284
 
 
285
 
   G_fatal_error() is called when variable is not found.
286
 
 
287
 
   \param name variable name
288
 
   \param loc location id
289
 
 
290
 
   \return variable value
291
 
   \return NULL if not found
292
 
*/
293
 
char *G_getenv2(const char *name, int loc)
294
 
{
295
 
    char *value;
296
 
 
297
 
    if ((value = G__getenv2(name, loc)))
298
 
        return value;
299
 
 
300
 
    G_fatal_error(_("%s not set"), name);
301
 
    return NULL;
302
 
}
303
 
 
304
 
/**
305
 
   \brief Get environment variable
306
 
 
307
 
   \param name variable name
 
327
/*!
 
328
  \brief Get environment variable
 
329
  
 
330
  G_fatal_error() is called when variable is not found.
 
331
  
 
332
  \param name variable name
 
333
  
 
334
  \return char pointer to value for name
 
335
*/
 
336
const char *G_getenv(const char *name)
 
337
{
 
338
    const char *value = G_getenv_nofatal(name);
 
339
 
 
340
    if (value)
 
341
        return value;
 
342
 
 
343
    G_fatal_error(_("Variable '%s' not set"), name);
 
344
    return NULL;
 
345
}
 
346
 
 
347
/*!
 
348
  \brief Get variable from specific place
 
349
  
 
350
  Locations:
 
351
   - G_VAR_GISRC
 
352
   - G_VAR_MAPSET
 
353
 
 
354
  G_fatal_error() is called when variable is not found.
 
355
  
 
356
  \param name variable name
 
357
  \param loc location (G_VAR_GISRC, G_VAR_MAPSET)
308
358
   
309
 
   \return char pointer to value for name
310
 
   \return NULL if name not set
311
 
*/
312
 
char *G__getenv(const char *name)
 
359
  \return variable value
 
360
  \return NULL if not found
 
361
*/
 
362
const char *G_getenv2(const char *name, int loc)
 
363
{
 
364
    const char *value = G_getenv_nofatal2(name, loc);
 
365
 
 
366
    if (value)
 
367
        return value;
 
368
 
 
369
    G_fatal_error(_("Variable '%s' not set"), name);
 
370
    return NULL;
 
371
}
 
372
 
 
373
/*!
 
374
  \brief Get environment variable
 
375
  
 
376
  \param name variable name
 
377
  
 
378
  \return char pointer to value for name
 
379
  \return NULL if name not set
 
380
*/
 
381
const char *G_getenv_nofatal(const char *name)
313
382
{
314
383
    if (strcmp(name, "GISBASE") == 0)
315
384
        return getenv(name);
319
388
    return get_env(name, G_VAR_GISRC);
320
389
}
321
390
 
322
 
/**
323
 
   \brief Get environment variable from specific place
324
 
 
325
 
   \param name variable name
326
 
   \param loc location id
327
 
   
328
 
   \return char pointer to value for name
329
 
   \return NULL if name not set
 
391
/*!
 
392
  \brief Get environment variable from specific place
 
393
  
 
394
  \param name variable name
 
395
  \param loc location (G_VAR_GISRC, G_VAR_MAPSET)
 
396
  
 
397
  \return char pointer to value for name
 
398
  \return NULL if name not set
330
399
*/
331
 
char *G__getenv2(const char *name, int loc)
 
400
const char *G_getenv_nofatal2(const char *name, int loc)
332
401
{
333
402
    if (strcmp(name, "GISBASE") == 0)
334
403
        return getenv(name);
338
407
    return get_env(name, loc);
339
408
}
340
409
 
341
 
/**
342
 
   \brief Set environment variable
343
 
 
344
 
   If value is NULL, becomes an G_unsetenv().
345
 
   Updates .gisrc
346
 
 
347
 
   \param name variable name
348
 
   \param value variable value
349
 
 
350
 
   \return 0
 
410
/*!
 
411
  \brief Set environment variable (updates .gisrc)
 
412
 
 
413
  If value is NULL, becomes an G_unsetenv().
 
414
    
 
415
  \param name variable name
 
416
  \param value variable value
351
417
*/
352
 
int G_setenv(const char *name, const char *value)
 
418
void G_setenv(const char *name, const char *value)
353
419
{
354
420
    read_env(G_VAR_GISRC);
355
421
    set_env(name, value, G_VAR_GISRC);
356
422
    write_env(G_VAR_GISRC);
357
 
    return 0;
358
423
}
359
424
 
360
 
/**
361
 
   \brief Set environment variable from specific place
362
 
 
363
 
   If value is NULL, becomes an G_unsetenv().
364
 
   Updates .gisrc
365
 
 
366
 
   \param name variable name
367
 
   \param value variable value
368
 
   \param loc location id
369
 
 
370
 
   \return 0
 
425
/*!
 
426
  \brief Set environment variable from specific place (updates .gisrc)
 
427
  
 
428
  If value is NULL, becomes an G_unsetenv().
 
429
  
 
430
  \param name variable name
 
431
  \param value variable value
 
432
  \param loc location (G_VAR_GISRC, G_VAR_MAPSET)
 
433
 
371
434
*/
372
 
int G_setenv2(const char *name, const char *value, int loc)
 
435
void G_setenv2(const char *name, const char *value, int loc)
373
436
{
374
437
    read_env(loc);
375
438
    set_env(name, value, loc);
376
439
    write_env(loc);
377
 
    return 0;
378
440
}
379
441
 
380
 
/**
381
 
   \brief Set environment name to value
382
 
 
383
 
   \param name variable name
384
 
   \param value variable value
385
 
 
386
 
   \return 0
 
442
/*!
 
443
  \brief Set environment name to value (doesn't update .gisrc)
 
444
  
 
445
  \param name variable name
 
446
  \param value variable value
387
447
*/
388
 
int G__setenv(const char *name, const char *value)
 
448
void G_setenv_nogisrc(const char *name, const char *value)
389
449
{
390
450
    read_env(G_VAR_GISRC);
391
451
    set_env(name, value, G_VAR_GISRC);
392
 
    return 0;
393
452
}
394
453
 
395
 
/**
396
 
   \brief Set environment name to value from specific place
397
 
 
398
 
   \param name variable name
399
 
   \param value variable value
400
 
   \param loc location id
401
 
 
402
 
   \return 0
 
454
/*!
 
455
  \brief Set environment name to value from specific place (doesn't update .gisrc)
 
456
  
 
457
  \param name variable name
 
458
  \param value variable value
 
459
  \param loc location (G_VAR_GISRC, G_VAR_MAPSET)
403
460
*/
404
 
int G__setenv2(const char *name, const char *value, int loc)
 
461
void G_setenv_nogisrc2(const char *name, const char *value, int loc)
405
462
{
406
463
    read_env(loc);
407
464
    set_env(name, value, loc);
408
 
    return 0;
409
465
}
410
466
 
411
 
/**
412
 
   \brief Remove name from environment
413
 
 
414
 
   Updates .gisrc
415
 
 
416
 
   \param name variable name
417
 
 
418
 
   \return 0
 
467
/*!
 
468
  \brief Remove name from environment
 
469
  
 
470
  Updates .gisrc
 
471
  
 
472
  \param name variable name
419
473
*/
420
 
int G_unsetenv(const char *name)
 
474
void G_unsetenv(const char *name)
421
475
{
422
476
    read_env(G_VAR_GISRC);
423
477
    unset_env(name, G_VAR_GISRC);
424
478
    write_env(G_VAR_GISRC);
425
 
 
426
 
    return 0;
427
479
}
428
480
 
429
 
/**
430
 
   \brief Remove name from environment from specific place
431
 
 
432
 
   Updates .gisrc
433
 
 
434
 
   \param name variable name
435
 
 
436
 
   \return 0
 
481
/*!
 
482
  \brief Remove name from environment from specific place
 
483
  
 
484
  Updates .gisrc
 
485
  
 
486
  \param name variable name
 
487
  \param loc location (G_VAR_GISRC, G_VAR_MAPSET)
437
488
*/
438
 
int G_unsetenv2(const char *name, int loc)
 
489
void G_unsetenv2(const char *name, int loc)
439
490
{
440
491
    read_env(loc);
441
492
    unset_env(name, loc);
442
493
    write_env(loc);
443
 
 
444
 
    return 0;
445
494
}
446
495
 
447
 
/**
448
 
   \brief Writes current environment to .gisrc
449
 
 
450
 
   \param
451
 
 
452
 
   \return 0
 
496
/*!
 
497
  \brief Writes current environment to .gisrc
453
498
*/
454
 
int G__write_env(void)
 
499
void G__write_env(void)
455
500
{
456
 
    if (init[G_VAR_GISRC])
 
501
    if (st->init[G_VAR_GISRC])
457
502
        write_env(G_VAR_GISRC);
458
 
 
459
 
    return 0;
460
503
}
461
504
 
462
 
/**
463
 
   \brief Get variable name for index n.
 
505
/*!
 
506
  \brief Get variable name for index n.
 
507
  
 
508
  For example:
464
509
 
465
 
   For example:
466
 
   \code
 
510
  \code
467
511
   for (n = 0; ; n++)
468
 
      if ((name = G__env_name(n)) == NULL)
 
512
      if ((name = G_get_env_name(n)) == NULL)
469
513
        break;
470
 
   \endcode
471
 
 
472
 
   \param n index of variable
473
 
 
474
 
   \return pointer to variable name
 
514
  \endcode
 
515
 
 
516
  \param n index of variable
 
517
  
 
518
  \return pointer to variable name
 
519
  \return NULL not found
475
520
*/
476
 
char *G__env_name(int n)
 
521
const char *G_get_env_name(int n)
477
522
{
478
523
    int i;
479
524
 
480
525
    read_env(G_VAR_GISRC);
481
526
    if (n >= 0)
482
 
        for (i = 0; i < count; i++)
483
 
            if (env[i].name && *env[i].name && (n-- == 0))
484
 
                return env[i].name;
 
527
        for (i = 0; i < st->env.count; i++)
 
528
            if (st->env.binds[i].name && *st->env.binds[i].name && (n-- == 0))
 
529
                return st->env.binds[i].name;
485
530
    return NULL;
486
531
}
487
532
 
488
 
/**
489
 
   \brief Initialize init array for G_VAR_GISRC.
490
 
 
491
 
   \param
492
 
 
493
 
   \return 0
494
 
*/
495
 
int G__read_env(void)
496
 
{
497
 
    init[G_VAR_GISRC] = 0;
498
 
 
499
 
    return 0;
500
 
}
501
 
 
502
 
/**
503
 
   \brief Sets filename for gisrc
504
 
 
505
 
   \param name filename
506
 
 
507
 
   \return 0
508
 
*/
509
 
int G__set_gisrc_file(const char *name)
510
 
{
511
 
    gisrc = NULL;
512
 
    if (name && *name)
513
 
        gisrc = G_store(name);
514
 
 
515
 
    return 0;
516
 
}
517
 
 
518
 
/**
519
 
   \brief Get gisrc filename
520
 
 
521
 
   \param
522
 
   
523
 
   \return char pointer to filename
524
 
*/
525
 
char *G__get_gisrc_file(void)
526
 
{
527
 
    return gisrc;
528
 
}
529
 
 
530
 
/**
531
 
   \brief Set up alternative environment variables
532
 
 
533
 
   \param
534
 
 
535
 
   \return 0
536
 
*/
537
 
int G__create_alt_env(void)
 
533
/*!
 
534
  \brief Initialize init array for G_VAR_GISRC.
 
535
*/
 
536
void G__read_env(void)
 
537
{
 
538
    st->init[G_VAR_GISRC] = 0;
 
539
}
 
540
 
 
541
/*!
 
542
  \brief Set up alternative environment variables
 
543
*/
 
544
void G_create_alt_env(void)
538
545
{
539
546
    int i;
540
547
 
541
548
    /* copy env to env2 */
542
 
    env2 = env;
543
 
    count2 = count;
544
 
    env = NULL;
545
 
    count = 0;
546
 
 
547
 
    for (i = 0; i < count2; i++)
548
 
        if (env2[count].name)
549
 
            set_env(env2[count].name, env2[count].value, G_VAR_GISRC);
550
 
 
551
 
    return 0;
 
549
    st->env2 = st->env;
 
550
    
 
551
    st->env.count = 0;
 
552
    st->env.size = 0;
 
553
    st->env.binds = NULL;
 
554
    
 
555
    for (i = 0; i < st->env2.count; i++) {
 
556
        struct bind *b = &st->env2.binds[i];
 
557
        if (b->name)
 
558
            set_env(b->name, b->value, G_VAR_GISRC);
 
559
    }
552
560
}
553
561
 
554
 
/**
555
 
   \brief Switch environments
556
 
 
557
 
   \param
558
 
 
559
 
   \return 0
 
562
/*!
 
563
  \brief Switch environments
560
564
*/
561
 
int G__switch_env(void)
 
565
void G_switch_env(void)
562
566
{
563
 
    ENV *tmp;
564
 
    int n;
565
 
 
566
 
    n = count;
567
 
    tmp = env;
568
 
 
569
 
    env = env2;
570
 
    count = count2;
571
 
 
572
 
    env2 = tmp;
573
 
    count2 = n;
574
 
 
575
 
    return 0;
 
567
    struct env tmp;
 
568
 
 
569
    tmp = st->env;
 
570
    st->env = st->env2;
 
571
    st->env2 = tmp;
576
572
}