home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / DMAKE38C.ZIP / MAC / EOLD.C < prev    next >
C/C++ Source or Header  |  1992-01-23  |  4KB  |  129 lines

  1. /* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/mac/eold.c,v 1.1 1992/01/24 03:29:47 dvadura Exp $
  2. -- SYNOPSIS -- Set up and free for environ
  3. --
  4. -- DESCRIPTION
  5. --  This file contains routines that will fill in and dispose of the
  6. --  list of environmental variables in the environ global variable.
  7. --
  8. -- AUTHOR
  9. --      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
  10. --      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
  11. --
  12. --
  13. -- COPYRIGHT
  14. --      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
  15. -- 
  16. --      This program is free software; you can redistribute it and/or
  17. --      modify it under the terms of the GNU General Public License
  18. --      (version 1), as published by the Free Software Foundation, and
  19. --      found in the file 'LICENSE' included with this distribution.
  20. -- 
  21. --      This program is distributed in the hope that it will be useful,
  22. --      but WITHOUT ANY WARRANTY; without even the implied warrant of
  23. --      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24. --      GNU General Public License for more details.
  25. -- 
  26. --      You should have received a copy of the GNU General Public License
  27. --      along with this program;  if not, write to the Free Software
  28. --      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29. --
  30. -- LOG
  31. --     $Log: eold.c,v $
  32.  * Revision 1.1  1992/01/24  03:29:47  dvadura
  33.  * dmake Version 3.8, Initial revision
  34.  *
  35. */
  36.  
  37. #include "extern.h"
  38.  
  39.  
  40. /*
  41.  * Keep track of any environmental variables that have '='s in their
  42.  * name.
  43.  */
  44. struct EqualPos {
  45.     char *fpPos;
  46.     struct equalsign *fpNext;
  47. } /* struct EqualPos */
  48.  
  49. struct EqualPos *gpEqualList;
  50.  
  51. /*
  52.  * The character used to replae the equal signs.
  53.  */
  54. const char gEqualReplace = '_';
  55.  
  56.  
  57.  
  58. /*
  59.  * Set up the environmental variables in a format used by
  60.  * the environ global variable.
  61.  *
  62.  * environ has already been set to main's envp argument when
  63.  * this suboroutine is called.
  64.  */
  65. void main_env () {
  66.     char **ppCurEnv;
  67.     char *pCurPos;
  68.     struct equalpos *pNewEqual;
  69.  
  70.     gpEqualList = NULL;
  71.  
  72.     for (ppCurEnv = environ; *ppCurEnv != NULL; ++ppCurEnv) {
  73.         for (pCurPos = *ppCurEnv; *pCurPos != '\0'; ++pCurPos) {
  74.             if (*pCurPos == '=') {
  75.                 if ((pNewEqual =
  76.                      (struct EqualPos *) malloc (sizeof (struct EqualPos))) ==
  77.                     NULL) {
  78.                     fputs ("Out of Memory", stderr);
  79.                     exit (EXIT_FAILURE);
  80.                 } /* if */
  81.                 pNewEqual->fpPos = pCurPos;
  82.                 pNewEqual->fpNext = gpEqualList;
  83.                 gpEqualList = pNewEqual;
  84.                 
  85.                 *pCurPos = gEqualReplace;
  86.             } /* if */
  87.         } /* for */
  88.  
  89.         *pCurPos = '=';
  90.     } /* for */
  91. } /* void main_env () */
  92.  
  93.  
  94.  
  95. /*
  96.  * Reset the environmental variables so they look like they did
  97.  * before the main_env() call.
  98.  *
  99.  * environ has already been set to main's envp argument when
  100.  * this suboroutine is called.
  101.  */
  102. void main_env () {
  103.     char **ppCurEnv;
  104.     char *pCurPos;
  105.     struct equalpos *pNewEqual;
  106.  
  107.     gpEqualList = NULL;
  108.  
  109.     for (ppCurEnv = environ; *ppCurEnv != NULL; ++ppCurEnv) {
  110.         for (pCurPos = *ppCurEnv; *pCurPos != '\0'; ++pCurPos) {
  111.             if (*pCurPos == '=') {
  112.                 if ((pNewEqual =
  113.                      (struct EqualPos *) malloc (sizeof (struct EqualPos))) ==
  114.                     NULL) {
  115.                     fputs ("Out of Memory", stderr);
  116.                     exit (EXIT_FAILURE);
  117.                 } /* if */
  118.                 pNewEqual->fpPos = pCurPos;
  119.                 pNewEqual->fpNext = gpEqualList;
  120.                 gpEqualList = pNewEqual;
  121.                 
  122.                 *pCurPos = gEqualReplace;
  123.             } /* if */
  124.         } /* for */
  125.  
  126.         *pCurPos = '=';
  127.     } /* for */
  128. } /* void main_env () */
  129.