* a!b ==> a'\!'b ==> 'a'\!'b'
*/
#undef EMIT
-#define EMIT(x) ( (++len < n) && (*bp++ = (x)) )
+#define EMIT(x) do { if (++len < n) *bp++ = (x); } while(0)
static inline int need_bs_quote(char c)
{
return len;
}
+void sq_quote_print(FILE *stream, const char *src)
+{
+ char c;
+
+ fputc('\'', stream);
+ while ((c = *src++)) {
+ if (need_bs_quote(c)) {
+ fputs("'\\", stream);
+ fputc(c, stream);
+ fputc('\'', stream);
+ } else {
+ fputc(c, stream);
+ }
+ }
+ fputc('\'', stream);
+}
+
char *sq_quote(const char *src)
{
char *buf;
if (!no_dq)
EMIT('"');
- for (sp = name; (ch = *sp++) && (sp - name) <= namelen; ) {
-
+ for (sp = name; sp < name + namelen; sp++) {
+ ch = *sp;
+ if (!ch)
+ break;
if ((ch < ' ') || (ch == '"') || (ch == '\\') ||
(ch == 0177)) {
needquote = 1;
case '\\': /* fallthru */
case '"': EMITQ(); break;
- case ' ':
- break;
default:
/* octal */
EMITQ();
case '\\': case '"':
break; /* verbatim */
- case '0'...'7':
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
/* octal */
ac = ((ch - '0') << 6);
if ((ch = *sp++) < '0' || '7' < ch)