File: envp2lis.c

package info (click to toggle)
icmake 6.22-7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,148 kB
  • ctags: 1,042
  • sloc: ansic: 9,241; makefile: 1,134; sh: 235; asm: 126
file content (54 lines) | stat: -rw-r--r-- 1,267 bytes parent folder | download | duplicates (3)
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
/*
\funcref{envp2list}{VAR\_ envp2list (\params)}
    {
        {char} {**envp} {array of environment settings}
    }
    {list variable holding environment}
    {newvar(), addtolist()}
    {main()}
    {envp2lis.c}
    {

        This function converts the array of strings, which is passed to the
        main function of {\em icm-exec} as {\em envp}, to a list. The list
        consists of an even number of elements. The first element of each pair
        is the name of the environment variable (e.g., ``path''); the second of
        each pair is the setting of the variable.

        The returned {\em VAR\_} structure is pushed onto the {\em icmake}
        stack by the {\em main()} function.

    }
*/

#include "icm-exec.h"

VAR_ envp2list (envp)
char **envp;
{
    VAR_
        ret;
    char
        buf [200];
    register char
        *cp;

    ret = newvar (e_list);
    while (*envp)
    {
        strncpy (buf, *envp, 199);
        if ( (cp = strrchr (buf, '=')) || (cp = strrchr (buf, ' ')) )
        {
            *cp = '\0';
            cp++;
            
            ret = addtolist (ret, buf);
            
            if (! *cp)
            	cp = " ";
            ret = addtolist (ret, cp);
        }
        envp++;
    }
    return (ret);
}