示例#1
0
文件: main.c 项目: Lampus/icoutils
static FILE *
extract_outfile_gen(char **outname_ptr, int w, int h, int bc, int i)
{
    char *inname = *outname_ptr;

    if (output == NULL || is_directory(output)) {
	StrBuf *outname;
	char *inbase;

	outname = strbuf_new();
	if (output != NULL) {
	    strbuf_append(outname, output);
	    if (!ends_with(output, "/"))
		strbuf_append(outname, "/");
	}
	inbase = strrchr(inname, '/');
	inbase = (inbase == NULL ? inname : inbase+1);
	if (ends_with_nocase(inbase, ".ico") || ends_with_nocase(inbase, ".cur")) {
	    strbuf_append_substring(outname, inbase, 0, strlen(inbase)-4);
	} else {
	    strbuf_append(outname, inbase);
	}
	strbuf_appendf(outname, "_%d_%dx%dx%d.png", i, w, h, bc);
	*outname_ptr = strbuf_free_to_string(outname);
	return fopen(*outname_ptr, "wb");
    }
    else if (strcmp(output, "-") == 0) {
	*outname_ptr = xstrdup(_("(standard out)"));
	return stdout;
    }

    *outname_ptr = xstrdup(output);
    return fopen(output, "wb");
}
示例#2
0
static bool
expand_variable(StrBuf *buf, const char *in, uint32_t len, MatchState *ms, uint32_t subc, SubmatchSpec *subv)
{
	if (len == 1 && in[0] == '`') {
		strbuf_append_substring(buf, strbuf_buffer(ms->top->buffer), ms->subv[0].so, subv[0].so);
	} else if (len == 1 && in[0] == '&') {
		strbuf_append_substring(buf, strbuf_buffer(ms->top->buffer), subv[0].so, subv[0].eo);
	} else if (len == 1 && in[0] == '\'') {
		strbuf_append_substring(buf, strbuf_buffer(ms->top->buffer), subv[0].eo, ms->subv[0].eo);
	} else {
		uint32_t idx = 0;
		int c;
		for (c = 0; c < len; c++) {
			if (!isdigit(in[c]))
				return false;
			idx = idx*10 + (in[c]-'0');
		}
		if (idx < 0 || idx >= subc)
			return true;
		strbuf_append_substring(buf, strbuf_buffer(ms->top->buffer), subv[idx].so, subv[idx].eo);
	}

	return true;
}