#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <ctype.h>
typedef enum { False, True } Bool;
Dispose (r);
}
+void
+Bail (char *format, char *arg)
+{
+ fprintf (stderr, "fatal: ");
+ fprintf (stderr, format, arg);
+ fprintf (stderr, "\n");
+ exit (1);
+}
+
Replace *
ReplaceRead (FILE *f)
{
ReplaceDispose (r);
return 0;
}
+ if (isspace (c))
+ Bail ("invalid character after tag %s", r->tag->buf);
StringAdd (r->tag, c);
}
if (r->tag->buf[0] == '\0')
StringAdd (r->text, c);
if (c == '@')
ungetc (c, f);
- while (StringLast (r->text) == '\n')
+ while (isspace (StringLast (r->text)))
StringDel (r->text);
return r;
}
FILE *f;
ReplaceSet *s;
+ if (!argv[1])
+ Bail ("usage: %s <template.sgml>", argv[0]);
f = fopen (argv[1], "r");
if (!f)
{
- perror (argv[1]);
+ Bail ("can't open file %s", argv[1]);
exit (1);
}
while ((s = ReplaceSetRead (stdin)))
rewind (f);
}
if (ferror (stdout))
- exit (1);
+ Bail ("%s", "error writing output");
exit (0);
}