summaryrefslogtreecommitdiff
path: root/dmake/mac/eold.c
blob: 5c389c5851db0c6a27c43c0069f3ca6601e02f5a (plain)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* RCS  $Id: eold.c,v 1.1.1.1 2000-09-22 15:33:27 hr Exp $
--
-- SYNOPSIS
--      Set up and free for environ
--
-- DESCRIPTION
--  This file contains routines that will fill in and dispose of the
--  list of environmental variables in the environ global variable.
--
-- AUTHOR
--      Dennis Vadura, dvadura@dmake.wticorp.com
--
--
-- WWW
--      http://dmake.wticorp.com/
--
-- COPYRIGHT
--      Copyright (c) 1996,1997 by WTI Corp.  All rights reserved.
--
--      This program is NOT free software; you can redistribute it and/or
--      modify it under the terms of the Software License Agreement Provided
--      in the file <distribution-root>/readme/license.txt.
--
-- LOG
--      Use cvs log to obtain detailed change logs.
*/

#include "extern.h"


/*
 * Keep track of any environmental variables that have '='s in their
 * name.
 */
struct EqualPos {
    char *fpPos;
    struct equalsign *fpNext;
} /* struct EqualPos */

struct EqualPos *gpEqualList;

/*
 * The character used to replae the equal signs.
 */
const char gEqualReplace = '_';



/*
 * Set up the environmental variables in a format used by
 * the environ global variable.
 *
 * environ has already been set to main's envp argument when
 * this suboroutine is called.
 */
void main_env () {
    char **ppCurEnv;
    char *pCurPos;
    struct equalpos *pNewEqual;

    gpEqualList = NULL;

    for (ppCurEnv = environ; *ppCurEnv != NULL; ++ppCurEnv) {
        for (pCurPos = *ppCurEnv; *pCurPos != '\0'; ++pCurPos) {
            if (*pCurPos == '=') {
                if ((pNewEqual =
                     (struct EqualPos *) malloc (sizeof (struct EqualPos))) ==
                    NULL) {
                    fputs ("Out of Memory", stderr);
                    exit (EXIT_FAILURE);
                } /* if */
                pNewEqual->fpPos = pCurPos;
                pNewEqual->fpNext = gpEqualList;
                gpEqualList = pNewEqual;

                *pCurPos = gEqualReplace;
            } /* if */
        } /* for */

        *pCurPos = '=';
    } /* for */
} /* void main_env () */



/*
 * Reset the environmental variables so they look like they did
 * before the main_env() call.
 *
 * environ has already been set to main's envp argument when
 * this suboroutine is called.
 */
void main_env () {
    char **ppCurEnv;
    char *pCurPos;
    struct equalpos *pNewEqual;

    gpEqualList = NULL;

    for (ppCurEnv = environ; *ppCurEnv != NULL; ++ppCurEnv) {
        for (pCurPos = *ppCurEnv; *pCurPos != '\0'; ++pCurPos) {
            if (*pCurPos == '=') {
                if ((pNewEqual =
                     (struct EqualPos *) malloc (sizeof (struct EqualPos))) ==
                    NULL) {
                    fputs ("Out of Memory", stderr);
                    exit (EXIT_FAILURE);
                } /* if */
                pNewEqual->fpPos = pCurPos;
                pNewEqual->fpNext = gpEqualList;
                gpEqualList = pNewEqual;

                *pCurPos = gEqualReplace;
            } /* if */
        } /* for */

        *pCurPos = '=';
    } /* for */
} /* void main_env () */