/* ******************************************************************************* * Copyright (c) 1996 Martin Poole * ******************************************************************************* ** ** WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! ** ** Any changes to be made to this file should first be checked with ** mplib1 source control for library integrity. ** ** mplib1 source control can be reached at mplib1@quatermass.co.uk ** * * $Source: /home/cvs/cvsroot/onelan/onelan/src/mplib1/libsrc/cfg_f_020.c,v $ * $Author: mpoole $ * $Date: 2002/10/07 09:37:38 $ * $Revision: 1.2 $ * ******************************************************************************* * * Change History * * $Log: cfg_f_020.c,v $ * Revision 1.2 2002/10/07 09:37:38 mpoole * Initial checkin of mplib1-3.1.0 * * Revision 1.1 2002/10/07 09:36:55 mpoole * Initial checkin of mplib1-3.1.0 * * ******************************************************************************* */ #ident "$Header: /home/cvs/cvsroot/onelan/onelan/src/mplib1/libsrc/cfg_f_020.c,v 1.2 2002/10/07 09:37:38 mpoole Exp $" /* ------------------------------------------------------------------ Include files ------------------------------------------------------------------ */ #include #include #include #include #include #include #include /* ------------------------------------------------------------------ defines ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ Code starts here ------------------------------------------------------------------ */ char * eval_private_str( const char *list_name, const char *from ) { static char tbuf[500]; char buf2[500]; char *rto = tbuf; char *ep, *ep2; int do_getenv,fallback_env,fallback_config; while ( *from ) { if ( *from == '$' || *from == '%' ) { do_getenv = ( *from == '$' ); /* something to do */ from++; fallback_env = fallback_config = 0; if ( *from == '$' && !do_getenv ) { fallback_env = 1; from++; }else if ( *from == '%' && do_getenv ) { fallback_config = 1; from++; } /* we are now pointing at the environment name, we copy all characters [a-zA-z_-\.:] into the enquire string */ ep = buf2; if (*from == '(' || *from == '{') { char close; close = (*from == '(')?')':'}'; from++; /* read until corresponding close char */ while ( *from && *from != close ) *ep++ = *from++; from++; }else { while ( *from && ( isalpha(*from) || isdigit(*from) || strchr( "-_.:", *from ) ) ) *ep++ = *from++; } *ep = '\0'; /* now get the value from the environment */ if (do_getenv) ep2 = getenv( buf2 ); else ep2 = get_private_string( list_name, buf2 ); if ((!ep2 || !*ep2) && (fallback_env || fallback_config) ) { if (fallback_env) ep2 = getenv( buf2 ); else ep2 = get_private_string( list_name, buf2 ); } if (ep2) while ( *ep2 ) *rto++ = *ep2++; }else while ( *from && *from != '$' && *from != '%' ) *rto++ = *from++; } /* And terminate the buffer */ *rto = '\0'; return(tbuf); } /* -- End of File -- */