The tests aren't getting 100% coverage and the nested assignments make
it harder to see what's happening, and what needs to happen to gain
coverage. Hoist invariants so it's clear they're such to the reader and
not just the compiler.
fgetstr (char *s, int n, FILE *stream)
{
char *cp, *ep;
fgetstr (char *s, int n, FILE *stream)
{
char *cp, *ep;
- for (ep = (cp = s) + o_n; cp < ep; ) {
- int i;
+ for (cp = s; cp < ep;) {
+ int len;
if (!fgets (cp, n, stream))
if (!fgets (cp, n, stream))
- return (cp != s ? s : NULL);
+ return cp == s ? NULL : s; /* "\\\nEOF" ignored. */
if (cp == s && *cp != '#')
if (cp == s && *cp != '#')
+ return s; /* Plaintext line. */
- cp += (i = strlen (cp)) - 1;
- if (i <= 1 || *cp-- != '\n' || *cp != '\\')
+ len = strlen(cp);
+ if (len <= 1)
+ break; /* Can't contain "\\\n". */
+ cp += len - 1; /* Just before NUL. */
+ if (*cp-- != '\n' || *cp != '\\')
- *cp = '\0';
- n -= (i - 2);
+ *cp = '\0'; /* Erase the trailing "\\\n". */
+ n -= (len - 2);
}
if (strcmp(s, "#on\n") == 0) {
}
if (strcmp(s, "#on\n") == 0) {
} else if (strcmp(s, "#pop\n") == 0) {
directive_pop();
} else {
} else if (strcmp(s, "#pop\n") == 0) {
directive_pop();
} else {