]> git.wh0rd.org - fontconfig.git/blobdiff - doc/edit-sgml.c
Got rid of the newline at the end of the file. It's yucky but, I'm not sure
[fontconfig.git] / doc / edit-sgml.c
index 6e04e1cb1536d9e95c447dfc0ace333d6de75afe..407dd2c240cbb28dd6e4580261019b5ea884f648 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <ctype.h>
 
 typedef enum { False, True } Bool;
@@ -145,6 +146,15 @@ ReplaceDispose (Replace *r)
     Dispose (r);
 }
 
+void
+Bail (char *format, char *arg)
+{
+    fprintf (stderr, "fatal: ");
+    fprintf (stderr, format, arg);
+    fprintf (stderr, "\n");
+    exit (1);
+}
+
 Replace *
 ReplaceRead (FILE *f)
 {
@@ -164,6 +174,8 @@ 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')
@@ -178,7 +190,7 @@ ReplaceRead (FILE *f)
        StringAdd (r->text, c);
     if (c == '@')
        ungetc (c, f);
-    while (StringLast (r->text) == '\n')
+    while (isspace (StringLast (r->text)))
        StringDel (r->text);
     return r;
 }
@@ -408,10 +420,12 @@ main (int argc, char **argv)
     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)))
@@ -421,6 +435,6 @@ main (int argc, char **argv)
        rewind (f);
     }
     if (ferror (stdout))
-       exit (1);
+       Bail ("%s", "error writing output");
     exit (0);
 }