File: grgenv.c

package info (click to toggle)
pgplot5 5.2-8
  • links: PTS
  • area: non-free
  • in suites: slink
  • size: 6,268 kB
  • ctags: 5,900
  • sloc: fortran: 37,938; ansic: 18,809; sh: 1,136; objc: 532; perl: 443; makefile: 271; pascal: 233; tcl: 178; awk: 51; csh: 25
file content (83 lines) | stat: -rw-r--r-- 2,587 bytes parent folder | download | duplicates (26)
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
#include <stdlib.h>
#include <string.h>
/*
 **GRGENV -- get value of PGPLOT environment parameter (Cray)
 *+
 *    SUBROUTINE GRGENV(NAME, VALUE, L)
 *    CHARACTER*(*) NAME, VALUE
 *    INTEGER L
 *
 * Return the value of a PGPLOT environment parameter. In Sun/Convex-UNIX,
 * environment parameters are UNIX environment variables; e.g. parameter
 * ENVOPT is environment variable PGPLOT_ENVOPT. Translation is not
 * recursive and is case-sensitive.
 *
 * Arguments:
 *  NAME   : (input) the name of the parameter to evaluate.
 *  VALUE  : receives the value of the parameter, truncated or extended
 *           with blanks as necessary. If the parameter is undefined,
 *           a blank string is returned.
 *  L      : receives the number of characters in VALUE, excluding
 *           trailing blanks. If the parameter is undefined, zero is
 *           returned.
 *--
 * 13-Nov-1994 - [mcs] f2c callable C version for NeXT.
 *-----------------------------------------------------------------------
 */
void grgenv_(name, value, length, name_dim, value_dim)
  char *name, *value; int *length;
  int name_dim, value_dim;
{
  static char *prefix = "PGPLOT_";  /* Environment variable name prefix */
  char test[33];     /* PGPLOT_* Concatenation buffer */
  int name_len;      /* Un-padded length of 'name' string */
  int prefix_len;    /* The length of prefix[] */
  char *env=0;       /* Environment variable value */
  int i;
/*
 * Determine the length of 'name' by searching for the last
 * non-space character.
 */
  name_len = name_dim;
  while(name_len > 0 && name[name_len-1] == ' ')
    name_len--;
/*
 * Determine the length of the prefix.
 */
  prefix_len = strlen(prefix);
/*
 * Prefix 'name' with PGPLOT_ if there is room in test[].
 */
  if(prefix_len + name_len + 1 <= sizeof(test)/sizeof(char)) {
    strcpy(test, prefix);
    strncpy(&test[prefix_len], name, name_len);
    test[prefix_len+name_len] = '\0';
/*
 * Get the value of the environment variable now named in test[].
 */
    env = getenv(test);
  };
/*
 * Substitute an empty string if no value was obtained, or the value
 * obtained is too long to fit in the output string.
 */
  if(env==0 || strlen(env) > value_dim)
    env = "";
/*
 * Copy the environment variable value into the output string.
 */
  strncpy(value, env, value_dim);
/*
 * Return the unpadded length of the string.
 */
  {
    int env_len = strlen(env);
    *length = (env_len <= value_dim) ? env_len : value_dim;
  };
/*
 * Pad the fortran string with spaces.
 */
  for(i = *length; i<value_dim; i++)
    value[i] = ' ';
  return;
}