File: getenv_.c

package info (click to toggle)
insighttoolkit 3.20.1%2Bgit20120521-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 80,652 kB
  • sloc: cpp: 458,133; ansic: 196,223; fortran: 28,000; python: 3,839; tcl: 1,811; sh: 1,184; java: 583; makefile: 430; csh: 220; perl: 193; xml: 20
file content (62 lines) | stat: -rw-r--r-- 1,533 bytes parent folder | download | duplicates (15)
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
#include "v3p_f2c.h"
#undef abs
#ifdef KR_headers
extern char *F77_aloc(), *getenv();
#else
#include <stdlib.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
extern char *F77_aloc(ftnlen, char*);
#endif

/*
 * getenv - f77 subroutine to return environment variables
 *
 * called by:
 *      call getenv (ENV_NAME, char_var)
 * where:
 *      ENV_NAME is the name of an environment variable
 *      char_var is a character variable which will receive
 *              the current value of ENV_NAME, or all blanks
 *              if ENV_NAME is not defined
 */

#ifdef KR_headers
 VOID
getenv_(fname, value, flen, vlen) char *value, *fname; ftnlen vlen, flen;
#else
 void
getenv_(char *fname, char *value, ftnlen flen, ftnlen vlen)
#endif
{
        char buf[256], *ep, *fp;
        integer i;

        if (flen <= 0)
                goto add_blanks;
        for(i = 0; i < sizeof(buf); i++) {
                if (i == flen || (buf[i] = fname[i]) == ' ') {
                        buf[i] = 0;
                        ep = getenv(buf);
                        goto have_ep;
                        }
                }
        while(i < flen && fname[i] != ' ')
                i++;
        strncpy(fp = F77_aloc(i+1, "getenv_"), fname, (int)i);
        fp[i] = 0;
        ep = getenv(fp);
        free(fp);
 have_ep:
        if (ep)
                while(*ep && vlen-- > 0)
                        *value++ = *ep++;
 add_blanks:
        while(vlen-- > 0)
                *value++ = ' ';
        }
#ifdef __cplusplus
}
#endif