Пример #1
0
/* Like outstr(), but quote for re-input into the shell. */
void
outqstr(const char *p, struct output *file)
{
	char ch;
	int inquotes;

	if (p[0] == '\0') {
		outstr("''", file);
		return;
	}
	/* Caller will handle '=' if necessary */
	if (p[strcspn(p, "|&;<>()$`\\\"' \t\n*?[~#")] == '\0' ||
			strcmp(p, "[") == 0) {
		outstr(p, file);
		return;
	}

	inquotes = 0;
	while ((ch = *p++) != '\0') {
		switch (ch) {
		case '\'':
			/* Can't quote single quotes inside single quotes. */
			if (inquotes)
				outcslow('\'', file);
			inquotes = 0;
			outstr("\\'", file);
			break;
		default:
			if (!inquotes)
				outcslow('\'', file);
			inquotes = 1;
			outc(ch, file);
		}
	}
	if (inquotes)
		outcslow('\'', file);
}
Пример #2
0
static void
exvwarning2(const char *msg, va_list ap)
{
	struct output *errs;
	const char *name;
	const char *fmt;

	errs = out2;
	name = arg0 ?: "sh";
	fmt = "%s: ";
	if (commandname) {
		name = commandname;
		fmt = "%s: %d: ";
	}
	outfmt(errs, fmt, name, startlinno);
	doformat(errs, msg, ap);
#if FLUSHERR
	outc('\n', errs);
#else
	outcslow('\n', errs);
#endif
}