| 1 |
ben.allan |
704 |
/* ASCEND modelling environment |
| 2 |
|
|
Copyright (C) 2006 Carnegie Mellon University |
| 3 |
|
|
|
| 4 |
|
|
This program is free software; you can redistribute it and/or modify |
| 5 |
|
|
it under the terms of the GNU General Public License as published by |
| 6 |
|
|
the Free Software Foundation; either version 2, or (at your option) |
| 7 |
|
|
any later version. |
| 8 |
|
|
|
| 9 |
|
|
This program is distributed in the hope that it will be useful, |
| 10 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
|
|
GNU General Public License for more details. |
| 13 |
|
|
|
| 14 |
|
|
You should have received a copy of the GNU General Public License |
| 15 |
|
|
along with this program; if not, write to the Free Software |
| 16 |
|
|
Foundation, Inc., 59 Temple Place - Suite 330, |
| 17 |
|
|
Boston, MA 02111-1307, USA. |
| 18 |
|
|
*//** |
| 19 |
|
|
@file |
| 20 |
|
|
Environment variable helper routines |
| 21 |
|
|
*//* |
| 22 |
|
|
by John Pye, May 2006. |
| 23 |
|
|
*/ |
| 24 |
|
|
|
| 25 |
|
|
#ifndef ASC_ENV_H |
| 26 |
|
|
#define ASC_ENV_H |
| 27 |
|
|
|
| 28 |
|
|
#ifdef TEST |
| 29 |
johnpye |
1063 |
# define ASC_DLLSPEC T T |
| 30 |
ben.allan |
704 |
#else |
| 31 |
|
|
# include <utilities/config.h> |
| 32 |
|
|
# include <utilities/ascConfig.h> |
| 33 |
|
|
# include <utilities/ascMalloc.h> |
| 34 |
|
|
# define FREE ascfree |
| 35 |
|
|
# define MALLOC ascmalloc |
| 36 |
|
|
#endif |
| 37 |
|
|
|
| 38 |
|
|
/** |
| 39 |
|
|
This is the type of env var function that you must send to 'env_subst'. |
| 40 |
|
|
It doesn't have to actually consult the environment; it could do all |
| 41 |
|
|
sorts of other stuff if you wanted. |
| 42 |
|
|
*/ |
| 43 |
johnpye |
589 |
typedef char *(GetEnvFn)(const char *name); |
| 44 |
|
|
|
| 45 |
|
|
/** |
| 46 |
|
|
This the type of a putenv function that can be used to set and environment |
| 47 |
|
|
variable. |
| 48 |
|
|
*/ |
| 49 |
|
|
typedef int (PutEnvFn)(const char *inputstring); |
| 50 |
|
|
|
| 51 |
|
|
/** |
| 52 |
|
|
Attempts to read from a getenv function, and if the value is found, write it |
| 53 |
|
|
using a putenv function. You would use this to copy values from one |
| 54 |
|
|
environment to another. |
| 55 |
|
|
|
| 56 |
|
|
@return nonzero on error, -1 means that the value didn't exist in getenv, |
| 57 |
|
|
otherwise the errors are those returned by putenv. |
| 58 |
|
|
*/ |
| 59 |
johnpye |
1063 |
ASC_DLLSPEC int env_import(const char *varname,GetEnvFn *getenvptr,PutEnvFn *putenvptr); |
| 60 |
ben.allan |
704 |
|
| 61 |
|
|
/** |
| 62 |
|
|
Perform variable substitution on a string in shell-like way. |
| 63 |
|
|
This should replace any $VARNAME with the result of |
| 64 |
|
|
(*getenvptr)(VARNAME). |
| 65 |
|
|
|
| 66 |
|
|
At present there will be no allowance for lowercase env var names |
| 67 |
|
|
only uppercase and underscores. No escaping of dollar signs is |
| 68 |
jpye |
1598 |
allowed for yet, and not ${BRACKETING}TO_STOP adjacent characters |
| 69 |
ben.allan |
704 |
from being swallowed up is allowed for, either. These can be added |
| 70 |
|
|
later, 'as an exercise'. |
| 71 |
|
|
*/ |
| 72 |
johnpye |
1063 |
ASC_DLLSPEC char *env_subst(const char *path,GetEnvFn *getenvptr); |
| 73 |
ben.allan |
704 |
|
| 74 |
|
|
#endif |