update dev300-m58
[ooovba.git] / dmake / mac / eold.c
bloba76a2a7a4b828afc6f09a193c146971b0169aae6
1 /* RCS $Id: eold.c,v 1.1.1.1 2000-09-22 15:33:27 hr Exp $
2 --
3 -- SYNOPSIS
4 -- Set up and free for environ
5 --
6 -- DESCRIPTION
7 -- This file contains routines that will fill in and dispose of the
8 -- list of environmental variables in the environ global variable.
9 --
10 -- AUTHOR
11 -- Dennis Vadura, dvadura@dmake.wticorp.com
14 -- WWW
15 -- http://dmake.wticorp.com/
17 -- COPYRIGHT
18 -- Copyright (c) 1996,1997 by WTI Corp. All rights reserved.
19 --
20 -- This program is NOT free software; you can redistribute it and/or
21 -- modify it under the terms of the Software License Agreement Provided
22 -- in the file <distribution-root>/readme/license.txt.
24 -- LOG
25 -- Use cvs log to obtain detailed change logs.
28 #include "extern.h"
32 * Keep track of any environmental variables that have '='s in their
33 * name.
35 struct EqualPos {
36 char *fpPos;
37 struct equalsign *fpNext;
38 } /* struct EqualPos */
40 struct EqualPos *gpEqualList;
43 * The character used to replae the equal signs.
45 const char gEqualReplace = '_';
50 * Set up the environmental variables in a format used by
51 * the environ global variable.
53 * environ has already been set to main's envp argument when
54 * this suboroutine is called.
56 void main_env () {
57 char **ppCurEnv;
58 char *pCurPos;
59 struct equalpos *pNewEqual;
61 gpEqualList = NULL;
63 for (ppCurEnv = environ; *ppCurEnv != NULL; ++ppCurEnv) {
64 for (pCurPos = *ppCurEnv; *pCurPos != '\0'; ++pCurPos) {
65 if (*pCurPos == '=') {
66 if ((pNewEqual =
67 (struct EqualPos *) malloc (sizeof (struct EqualPos))) ==
68 NULL) {
69 fputs ("Out of Memory", stderr);
70 exit (EXIT_FAILURE);
71 } /* if */
72 pNewEqual->fpPos = pCurPos;
73 pNewEqual->fpNext = gpEqualList;
74 gpEqualList = pNewEqual;
76 *pCurPos = gEqualReplace;
77 } /* if */
78 } /* for */
80 *pCurPos = '=';
81 } /* for */
82 } /* void main_env () */
87 * Reset the environmental variables so they look like they did
88 * before the main_env() call.
90 * environ has already been set to main's envp argument when
91 * this suboroutine is called.
93 void main_env () {
94 char **ppCurEnv;
95 char *pCurPos;
96 struct equalpos *pNewEqual;
98 gpEqualList = NULL;
100 for (ppCurEnv = environ; *ppCurEnv != NULL; ++ppCurEnv) {
101 for (pCurPos = *ppCurEnv; *pCurPos != '\0'; ++pCurPos) {
102 if (*pCurPos == '=') {
103 if ((pNewEqual =
104 (struct EqualPos *) malloc (sizeof (struct EqualPos))) ==
105 NULL) {
106 fputs ("Out of Memory", stderr);
107 exit (EXIT_FAILURE);
108 } /* if */
109 pNewEqual->fpPos = pCurPos;
110 pNewEqual->fpNext = gpEqualList;
111 gpEqualList = pNewEqual;
113 *pCurPos = gEqualReplace;
114 } /* if */
115 } /* for */
117 *pCurPos = '=';
118 } /* for */
119 } /* void main_env () */