Пример #1
0
int readLine(rpmSpec spec, int strip)
{
    char *s;
    int match;
    struct ReadLevelEntry *rl;
    OFI_t *ofi = spec->fileStack;
    int rc;
    int startLine = 0;

    if (!restoreFirstChar(spec)) {
retry:
        if ((rc = readLineFromOFI(spec, ofi)) != 0) {
            if (spec->readStack->next) {
                rpmlog(RPMLOG_ERR, _("line %d: Unclosed %%if\n"),
                       spec->readStack->lineNum);
                rc = PART_ERROR;
            } else if (startLine > 0) {
                rpmlog(RPMLOG_ERR,
                       _("line %d: unclosed macro or bad line continuation\n"),
                       startLine);
                rc = PART_ERROR;
            }
            return rc;
        }
        ofi = spec->fileStack;

        /* Copy next file line into the spec line buffer */
        rc = copyNextLineFromOFI(spec, ofi, strip);
        if (rc > 0) {
            if (startLine == 0)
                startLine = spec->lineNum;
            goto retry;
        } else if (rc < 0) {
            return PART_ERROR;
        }
    }

    copyNextLineFinish(spec, strip);

    s = spec->line;
    SKIPSPACE(s);

    match = -1;
    if (!spec->readStack->reading && ISMACROWITHARG(s, "%if")) {
        match = 0;
    } else if (ISMACROWITHARG(s, "%ifarch")) {
        ARGMATCH(s, "%{_target_cpu}", match);
    } else if (ISMACROWITHARG(s, "%ifnarch")) {
        ARGMATCH(s, "%{_target_cpu}", match);
        match = !match;
    } else if (ISMACROWITHARG(s, "%ifos")) {
        ARGMATCH(s, "%{_target_os}", match);
    } else if (ISMACROWITHARG(s, "%ifnos")) {
        ARGMATCH(s, "%{_target_os}", match);
        match = !match;
    } else if (ISMACROWITHARG(s, "%if")) {
        s += 3;
        match = parseExpressionBoolean(s);
        if (match < 0) {
            rpmlog(RPMLOG_ERR,
                   _("%s:%d: bad %%if condition\n"),
                   ofi->fileName, ofi->lineNum);
            return PART_ERROR;
        }
    } else if (ISMACRO(s, "%else")) {
        if (! spec->readStack->next) {
            /* Got an else with no %if ! */
            rpmlog(RPMLOG_ERR,
                   _("%s:%d: Got a %%else with no %%if\n"),
                   ofi->fileName, ofi->lineNum);
            return PART_ERROR;
        }
        spec->readStack->reading =
            spec->readStack->next->reading && ! spec->readStack->reading;
        spec->line[0] = '\0';
    } else if (ISMACRO(s, "%endif")) {
        if (! spec->readStack->next) {
            /* Got an end with no %if ! */
            rpmlog(RPMLOG_ERR,
                   _("%s:%d: Got a %%endif with no %%if\n"),
                   ofi->fileName, ofi->lineNum);
            return PART_ERROR;
        }
        rl = spec->readStack;
        spec->readStack = spec->readStack->next;
        free(rl);
        spec->line[0] = '\0';
    } else if (spec->readStack->reading && ISMACROWITHARG(s, "%include")) {
        char *fileName, *endFileName, *p;

        fileName = s+8;
        SKIPSPACE(fileName);
        endFileName = fileName;
        SKIPNONSPACE(endFileName);
        p = endFileName;
        SKIPSPACE(p);
        if (*fileName == '\0' || *p != '\0') {
            rpmlog(RPMLOG_ERR, _("%s:%d: malformed %%include statement\n"),
                   ofi->fileName, ofi->lineNum);
            return PART_ERROR;
        }
        *endFileName = '\0';

        ofi = pushOFI(spec, fileName);
        goto retry;
    }

    if (match != -1) {
        rl = xmalloc(sizeof(*rl));
        rl->reading = spec->readStack->reading && match;
        rl->next = spec->readStack;
        rl->lineNum = ofi->lineNum;
        spec->readStack = rl;
        spec->line[0] = '\0';
    }

    if (! spec->readStack->reading) {
        spec->line[0] = '\0';
    }

    /* Collect parsed line */
    if (spec->parsed == NULL)
        spec->parsed = newStringBuf();
    appendStringBufAux(spec->parsed, spec->line,(strip & STRIP_TRAILINGSPACE));

    /* FIX: spec->readStack->next should be dependent */
    return 0;
}
Пример #2
0
int readLine(rpmSpec spec, int strip)
{
    char  *s;
    int match;
    struct ReadLevelEntry *rl;
    OFI_t *ofi = spec->fileStack;
    int rc;

    if (!restoreFirstChar(spec)) {
    retry:
	if ((rc = readLineFromOFI(spec, ofi)) != 0)
	    return rc;

	/* Copy next file line into the spec line buffer */
	rc = copyNextLineFromOFI(spec, ofi);
	if (rc > 0) {
	    goto retry;
	} else if (rc < 0) {
	    return PART_ERROR;
	}
    }

    copyNextLineFinish(spec, strip);

    s = spec->line;
    SKIPSPACE(s);

    match = -1;
    if (!spec->readStack->reading && rstreqn("%if", s, sizeof("%if")-1)) {
	match = 0;
    } else if (rstreqn("%ifarch", s, sizeof("%ifarch")-1)) {
	char *arch = rpmExpand("%{_target_cpu}", NULL);
	s += 7;
	match = matchTok(arch, s);
	arch = _free(arch);
    } else if (rstreqn("%ifnarch", s, sizeof("%ifnarch")-1)) {
	char *arch = rpmExpand("%{_target_cpu}", NULL);
	s += 8;
	match = !matchTok(arch, s);
	arch = _free(arch);
    } else if (rstreqn("%ifos", s, sizeof("%ifos")-1)) {
	char *os = rpmExpand("%{_target_os}", NULL);
	s += 5;
	match = matchTok(os, s);
	os = _free(os);
    } else if (rstreqn("%ifnos", s, sizeof("%ifnos")-1)) {
	char *os = rpmExpand("%{_target_os}", NULL);
	s += 6;
	match = !matchTok(os, s);
	os = _free(os);
    } else if (rstreqn("%if", s, sizeof("%if")-1)) {
	s += 3;
        match = parseExpressionBoolean(spec, s);
	if (match < 0) {
	    rpmlog(RPMLOG_ERR,
			_("%s:%d: parseExpressionBoolean returns %d\n"),
			ofi->fileName, ofi->lineNum, match);
	    return PART_ERROR;
	}
    } else if (rstreqn("%else", s, sizeof("%else")-1)) {
	s += 5;
	if (! spec->readStack->next) {
	    /* Got an else with no %if ! */
	    rpmlog(RPMLOG_ERR,
			_("%s:%d: Got a %%else with no %%if\n"),
			ofi->fileName, ofi->lineNum);
	    return PART_ERROR;
	}
	spec->readStack->reading =
	    spec->readStack->next->reading && ! spec->readStack->reading;
	spec->line[0] = '\0';
    } else if (rstreqn("%endif", s, sizeof("%endif")-1)) {
	s += 6;
	if (! spec->readStack->next) {
	    /* Got an end with no %if ! */
	    rpmlog(RPMLOG_ERR,
			_("%s:%d: Got a %%endif with no %%if\n"),
			ofi->fileName, ofi->lineNum);
	    return PART_ERROR;
	}
	rl = spec->readStack;
	spec->readStack = spec->readStack->next;
	free(rl);
	spec->line[0] = '\0';
    } else if (rstreqn("%include", s, sizeof("%include")-1)) {
	char *fileName, *endFileName, *p;

	s += 8;
	fileName = s;
	if (! risspace(*fileName)) {
	    rpmlog(RPMLOG_ERR, _("malformed %%include statement\n"));
	    return PART_ERROR;
	}
	SKIPSPACE(fileName);
	endFileName = fileName;
	SKIPNONSPACE(endFileName);
	p = endFileName;
	SKIPSPACE(p);
	if (*p != '\0') {
	    rpmlog(RPMLOG_ERR, _("malformed %%include statement\n"));
	    return PART_ERROR;
	}
	*endFileName = '\0';

	forceIncludeFile(spec, fileName);

	ofi = spec->fileStack;
	goto retry;
    }

    if (match != -1) {
	rl = xmalloc(sizeof(*rl));
	rl->reading = spec->readStack->reading && match;
	rl->next = spec->readStack;
	spec->readStack = rl;
	spec->line[0] = '\0';
    }

    if (! spec->readStack->reading) {
	spec->line[0] = '\0';
    }

    /* FIX: spec->readStack->next should be dependent */
    return 0;
}