Example #1
0
static void	env_match(char *str, char ***envp)
{
	int		i;

	i = 0;
	while (*envp != NULL && (*envp)[i] != NULL)
	{
		if (variable_match(str, (*envp)[i]))
		{
			remove_variable(*envp, i);
			i = 0;
		}
		else
			i = i + 1;
	}
}
Example #2
0
static void
resolve_variable_reference(
  	char		**string )		/* MODIFIED */
{
   char		*string_end;
   char		*var_start;
   char		*pch;
   char		*value;
   int		n;			/* number of bytes in a string */
   int		len;
   int		found_brace;
   char		variable[256];
   char		*buf = NULL;
   char		*pbeg = *string;
   char		*string_start = *string;

   if (!remove_variable (*string))
      return;

   pch = pbeg;
   
   buf = malloc(2048);

   while (*pbeg) {

      /*
       * Look for '$' - the beginning of a variable reference.
       * If a '$' character is not found, exit the loop
       */
#ifdef NLS16
      while (*pch) {

	 if (((len = mblen (pch, MB_CUR_MAX)) == 1) && (*pch == '$'))
	    break;

	 /*
	  * Move past this char
	  */
	 if (len > 0)
	    pch += len;
	 else
	    /*
	     * pch is null or it points to an invalid mulit-byte
	     * character.
	     */
	    break;
      }
#else
      pch = strchr (pch, '$');
#endif /* NLS16 */

      if (pch == NULL || *pch == '\000')
	 /*
	  * The string doesn't contain any (more) variables
	  */
	 break;

      string_start = *string;

      /*
       * Found a '$' - the beginning of an environment variable so
       * skip it and check the next char for '{' and if it is found
       * skip it and move to the real beginning of an env variable.
       */
      string_end = pch;
      found_brace = 0;
      pch++;

#ifdef NLS16
      if ((mblen (pch, MB_CUR_MAX) == 1) && (*pch == '{')) {
#else
      if (*pch == '{') {
#endif /* NLS16 */
	 pch++;				/* input = ${ */
         found_brace = 1;
      }
      if (*pch == '\0')			/* input = $\0 or ${\0 */
	 break;

      /*
       * Find the end of the variable name - it is assumed to 
       * be the first character that is not an alpha-numeric
       * or '_'.
       */
      var_start = pch;
      n = 0;

      while (*pch) {
#ifdef NLS16
	 if ((mblen (pch, MB_CUR_MAX) > 1) || 
	     ((mblen (pch, MB_CUR_MAX) == 1) && 
	     ((*pch == '_') || (isalnum (*pch))))) {
#else
	 if (isalnum (*pch) || *pch == '_') {
#endif /* NLS16 */
	 
#ifdef NLS16
            len = mblen (pch, MB_CUR_MAX);
#else
            len = 1;
#endif /* NLS16 */
	    n += len;
	    pch += len;
	    continue;
	 }

#ifdef NLS16
         if (found_brace && (mblen (pch, MB_CUR_MAX) == 1) && (*pch == '}'))
#else
	 if (found_brace && *pch == '}')
#endif /* NLS16 */
	    /*
	     * Move past the closing brace
	     */
            pch++;
	 break;
      }

      if (n == 0) {
	 /*
	  * Nothing 'recognizable' follows the $ or ${
	  */
	 pbeg = pch;
	 continue;
      }

      /*
       * Stuff the environment variable name in 'variable' and then
       * get its value.  If the variable doesn't exist, leave its
       * name in the string.
       */
      (void) strncpy (variable, var_start, n);
      variable[n] = '\0';

      if ((value = getenv (variable)) == NULL) {
	 /*
	  * Leave what looks like an environment variable in place.
	  */
	 pbeg = pch;
	 continue;
      }

      if (strlen (value) == 0) {
	 pbeg = pch;
	 continue;
      }

      /*
       * Need to replace the variable definition with the string
       * pointed to by 'value'.  So create a string that contains the 
       * characters before the environment variable, then the contents 
       * of 'value' and finally, the characters after the environment 
       * variable.
       */
      if (string_end == string_start)
	 /*
	  * There is nothing to prepend before 'value'.
	  */
	 buf[0] = '\0';
      else {
	 (void) strncpy (buf, string_start, (string_end - string_start));
	 buf[(string_end - string_start)] = '\0';
      }
      (void) strcat (buf, value);
      len = strlen (buf);
      if (*pch != '\0')
	 (void) strcat (buf, pch);
       
      /*
       * Now put 'buf' into 'string'.
       */
      *string = realloc (*string, strlen (buf) + 1);
      (void) strcpy (*string, buf);
      pch = *string + len;
      pbeg = pch;
   }

   /*
    * Even if no substitutions were made, the variable must
    * be put in the environment.
    */
   (void) putenv (*string);
   if (buf) free(buf);
}
Example #3
0
void lmm_variable_free(lmm_system_t sys, lmm_variable_t var)
{
  remove_variable(sys, var);
  lmm_var_free(sys, var);
}