示例#1
0
文件: main.c 项目: jbl5088/psu
macI *createList(macI *first, char *makeString[], int counter)
{
	macI *previous = first;	

	char *macName;
	char *macVal;
	int sIndex;
	int valIndex;

	for(int i = 0; i < counter; i++)
	{
		if((strchr(makeString[i], '=')) == NULL) continue;

		sIndex = 0;
		valIndex = 0;

		macName = malloc(strlen(makeString[i]) + 1);
		macVal = malloc(strlen(makeString[i]) + 1);

		while(makeString[i][sIndex] != '=')
		{
			macName[sIndex] = makeString[i][sIndex];
			sIndex = sIndex + 1;
		}

		macName[sIndex++] = '\0';

		while(makeString[i][sIndex] != '\n' )
			macVal[valIndex++] = makeString[i][sIndex++];

		macVal[valIndex] = '\0';

		RemoveSpaces(macName);

		macI *newMacro = insertMacro(previous, macName, macVal);
		previous = newMacro;
		free(macName);
		free(macVal);	
	}	

	first = first->next;
	

	return first;
}
示例#2
0
文件: action.cpp 项目: ArildF/masters
BOOL
putMacro(
    char *name,
    char *value,
    UCHAR flags
    )
{
    MACRODEF *p;
    STRINGLIST *q;
    BOOL defined = FALSE;
    BOOL fSyntax = TRUE;

    // Convert path separators to the native path separator.
    // Do that with a copy of the original string so we don't change
    // the original.
    value = makeString(value);
#if PLATFORM_UNIX
    char *tmp = value;
    while ((tmp = FindFirstPathSeparator(tmp))) {
        *tmp++ = PATH_SEPARATOR_CHAR;
    }
#endif // PLATFORM_UNIX

    // Inherit macro definitions.  Call removeMacros() to expand sub-macro
    // definitions.  Must be done before macro is put in table, else
    // recursive definitions won't work.

    if (ON(flags, M_NON_RESETTABLE)) {
        if (*value)
            if ((putEnvStr(name,removeMacros(value)) == -1))
                makeError(currentLine, OUT_OF_ENV_SPACE);
    } else
    if (fInheritUserEnv &&
        OFF(gFlags, F1_USE_ENVIRON_VARS) &&
        getenv(name)
       ) {
        if ((p = findMacro(name))) {  // don't let user
            if (CANT_REDEFINE(p))   // redefine cmdline
                return(FALSE);      // macros, MAKE, etc.
        }
        if ((putEnvStr(name,removeMacros(value)) == -1))
            makeError(currentLine, OUT_OF_ENV_SPACE);
    }

    fInheritUserEnv = (BOOL)FALSE;
    if ((p = findMacro(name))) {      // don't let user
        if (CANT_REDEFINE(p))       // redefine cmdline
            return(FALSE);          // macros, MAKE, etc.
    }

    q = makeNewStrListElement();
    q->text = value;

    if (!p) {
        p = makeNewMacro();
        p->name = name;
        assert(p->flags == 0);
        assert(p->values == NULL);
    } else
        defined = TRUE;

    p->flags &= ~M_UNDEFINED;       // Is no longer undefined
    p->flags |= flags;              // Set flags to union of old and new
    prependItem((STRINGLIST**)&(p->values), (STRINGLIST*)q);
    if (!defined)
        insertMacro((STRINGLIST*)p);

    if (OFF(flags, M_LITERAL) && _tcschr(value, '$')) {     // Check for cyclic Macro Definitions
        SET(p->flags, M_EXPANDING_THIS_ONE);
        // NULL -> don't build list
        fSyntax = findMacroValues(value, NULL, NULL, name, 1, 0, flags);
        CLEAR(p->flags, M_EXPANDING_THIS_ONE);
    }

    if (!fSyntax) {
        p->values = NULL;
        p->flags |= M_UNDEFINED;
        //return(FALSE);
		// return TRUE since p has been added to the macro table
		// Otherwise the caller may free name and value leaving
		// dangling pointers in the macro table.                            
		return(TRUE);
    }
    return(TRUE);
}