char *strchr (const char *, int); void abort (); #define isblank(c) ((c) == ' ' || (c) == '\t') /* Return the address of the first nonwhitespace or null in the string S. */ char * next_token (s) char *s; { register char *p = s; while (isblank ((unsigned char)*p)) ++p; return p; } void collapse_continuations (line) char *line; { register char *in, *out, *p; register int backslash; register unsigned int bs_write; in = strchr (line, '\n'); if (in == 0) return; out = in; while (out > line && out[-1] == '\\') --out; while (*in != '\0') { /* BS_WRITE gets the number of quoted backslashes at the end just before IN, and BACKSLASH gets nonzero if the next character is quoted. */ backslash = 0; bs_write = 0; for (p = in - 1; p >= line && *p == '\\'; --p) { if (backslash) ++bs_write; backslash = !backslash; /* It should be impossible to go back this far without exiting, but if we do, we can't get the right answer. */ if (in == out - 1) abort (); } /* Output the appropriate number of backslashes. */ while (bs_write-- > 0) *out++ = '\\'; /* Skip the newline. */ ++in; /* If the newline is quoted, discard following whitespace and any preceding whitespace; leave just one space. */ if (backslash) { in = next_token (in); while (out > line && isblank ((unsigned char)out[-1])) --out; *out++ = ' '; } else /* If the newline isn't quoted, put it in the output. */ *out++ = '\n'; /* Now copy the following line to the output. Stop when we find backslashes followed by a newline. */ while (*in != '\0') if (*in == '\\') { p = in + 1; while (*p == '\\') ++p; if (*p == '\n') { in = p; break; } while (in < p) *out++ = *in++; } else *out++ = *in++; } *out = '\0'; } int main () { char line[] = "VER = `\tif grep AM_INIT_AUTOMAKE $(TOOL)/configure.in >/dev/null 2>&1; then \\\n\t sed < $(TOOL)/configure.in -n 's/AM_INIT_AUTOMAKE[^,]*, *\\([^)]*\\))/\\1/p'; \\\n\telse \\\n\t sed < $(TOOL)/Makefile.in -n 's/^VERSION *= *//p'; \\\n\tfi`"; collapse_continuations (line); return 0; }