Beispiel #1
0
/* quote path as relative to the given prefix */
char *quote_path_relative(const char *in, const char *prefix,
			  struct strbuf *out)
{
	struct strbuf sb = STRBUF_INIT;
	const char *rel = relative_path(in, prefix, &sb);
	strbuf_reset(out);
	quote_c_style_counted(rel, strlen(rel), out, NULL, 0);
	strbuf_release(&sb);

	return out->buf;
}
Beispiel #2
0
/* quote path as relative to the given prefix */
char *quote_path_relative(const char *in, int len,
			  struct strbuf *out, const char *prefix)
{
	struct strbuf sb = STRBUF_INIT;
	const char *rel = path_relative(in, len, &sb, prefix, -1);
	strbuf_reset(out);
	quote_c_style_counted(rel, strlen(rel), out, NULL, 0);
	strbuf_release(&sb);

	if (!out->len)
		strbuf_addstr(out, "./");

	return out->buf;
}
Beispiel #3
0
void write_name_quotedpfx(const char *pfx, size_t pfxlen,
			  const char *name, FILE *fp, int terminator)
{
	int needquote = 0;

	if (terminator) {
		needquote = next_quote_pos(pfx, pfxlen) < pfxlen
			|| name[next_quote_pos(name, -1)];
	}
	if (needquote) {
		fputc('"', fp);
		quote_c_style_counted(pfx, pfxlen, NULL, fp, 1);
		quote_c_style(name, NULL, fp, 1);
		fputc('"', fp);
	} else {
		fwrite(pfx, pfxlen, 1, fp);
		fputs(name, fp);
	}
	fputc(terminator, fp);
}
Beispiel #4
0
/* quote path as relative to the given prefix */
char *quote_path_relative(const char *in, int len,
			  struct strbuf *out, const char *prefix)
{
	int needquote;

	if (len < 0)
		len = strlen(in);

	/* "../" prefix itself does not need quoting, but "in" might. */
	needquote = (next_quote_pos(in, len) < len);
	strbuf_setlen(out, 0);
	strbuf_grow(out, len);

	if (needquote)
		strbuf_addch(out, '"');
	if (prefix) {
		int off = 0;
		while (prefix[off] && off < len && prefix[off] == in[off])
			if (prefix[off] == '/') {
				prefix += off + 1;
				in += off + 1;
				len -= off + 1;
				off = 0;
			} else
				off++;

		for (; *prefix; prefix++)
			if (*prefix == '/')
				strbuf_addstr(out, "../");
	}

	quote_c_style_counted (in, len, out, NULL, 1);

	if (needquote)
		strbuf_addch(out, '"');
	if (!out->len)
		strbuf_addstr(out, "./");

	return out->buf;
}
Beispiel #5
0
size_t quote_c_style(const char *name, struct strbuf *sb, FILE *fp, int nodq)
{
	return quote_c_style_counted(name, -1, sb, fp, nodq);
}