]> git.wh0rd.org - fontconfig.git/blobdiff - doc/edit-sgml.c
Add space between type and formal in devel man pages (bug 8935)
[fontconfig.git] / doc / edit-sgml.c
index 6e04e1cb1536d9e95c447dfc0ace333d6de75afe..3f3be53aaafd64a6e8e1d5bfb26781414ba67a8f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * $Id$
  *
- * Copyright © 2003 Keith Packard
+ * Copyright Â© 2003 Keith Packard
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <ctype.h>
 
+static void *
+New (int size);
+
+static void *
+Reallocate (void *p, int size);
+
+static void
+Dispose (void *p);
+
 typedef enum { False, True } Bool;
 
 typedef struct {
@@ -34,9 +44,107 @@ typedef struct {
     int            len;
 } String;
 
+static String *
+StringNew (void);
+
+static void
+StringAdd (String *s, char c);
+
+static void
+StringAddString (String *s, char *buf);
+
+static String *
+StringMake (char *buf);
+
+static void
+StringDel (String *s);
+
+static void
+StringPut (FILE *f, String *s);
+
+static void
+StringDispose (String *s);
+
+typedef struct {
+    String  *tag;
+    String  *text;
+} Replace;
+
+static Replace *
+ReplaceNew (void);
+
+static void
+ReplaceDispose (Replace *r);
+
+static void
+Bail (const char *format, const char *arg);
+
+static Replace *
+ReplaceRead (FILE *f);
+
+typedef struct _replaceList {
+    struct _replaceList        *next;
+    Replace            *r;
+} ReplaceList;
+
+static ReplaceList *
+ReplaceListNew (Replace *r, ReplaceList *next);
+
+static void
+ReplaceListDispose (ReplaceList *l);
+
+typedef struct {
+    ReplaceList        *head;
+} ReplaceSet;
+
+static ReplaceSet *
+ReplaceSetNew (void);
+
+static void
+ReplaceSetDispose (ReplaceSet *s);
+
+static void
+ReplaceSetAdd (ReplaceSet *s, Replace *r);
+
+static Replace *
+ReplaceSetFind (ReplaceSet *s, char *tag);
+
+static ReplaceSet *
+ReplaceSetRead (FILE *f);
+
+typedef struct _skipStack {
+    struct _skipStack  *prev;
+    int                        skipping;
+} SkipStack;
+
+static SkipStack *
+SkipStackPush (SkipStack *prev, int skipping);
+
+static SkipStack *
+SkipStackPop (SkipStack *prev);
+
+typedef struct _loopStack {
+    struct _loopStack  *prev;
+    String             *tag;
+    String             *extra;
+    long               pos;
+} LoopStack;
+
+static LoopStack *
+LoopStackPush (LoopStack *prev, FILE *f, char *tag);
+
+static LoopStack *
+LoopStackLoop (ReplaceSet *rs, LoopStack *ls, FILE *f);
+
+static void
+LineSkip (FILE *f);
+
+static void
+DoReplace (FILE *f, ReplaceSet *s);
+
 #define STRING_INIT 128
 
-void *
+static void *
 New (int size)
 {
     void    *m = malloc (size);
@@ -45,7 +153,7 @@ New (int size)
     return m;
 }
 
-void *
+static void *
 Reallocate (void *p, int size)
 {
     void    *r = realloc (p, size);
@@ -55,13 +163,13 @@ Reallocate (void *p, int size)
     return r;
 }
 
-void
+static void
 Dispose (void *p)
 {
     free (p);
 }
 
-String *
+static String *
 StringNew (void)
 {
     String  *s;
@@ -74,7 +182,7 @@ StringNew (void)
     return s;
 }
 
-void
+static void
 StringAdd (String *s, char c)
 {
     if (s->len == s->size)
@@ -83,14 +191,14 @@ StringAdd (String *s, char c)
     s->buf[s->len] = '\0';
 }
 
-void
+static void
 StringAddString (String *s, char *buf)
 {
     while (*buf)
        StringAdd (s, *buf++);
 }
 
-String *
+static String *
 StringMake (char *buf)
 {
     String  *s = StringNew ();
@@ -98,14 +206,14 @@ StringMake (char *buf)
     return s;
 }
 
-void
+static void
 StringDel (String *s)
 {
     if (s->len)
        s->buf[--s->len] = '\0';
 }
 
-void
+static void
 StringPut (FILE *f, String *s)
 {
     char    *b = s->buf;
@@ -116,19 +224,14 @@ StringPut (FILE *f, String *s)
 
 #define StringLast(s)  ((s)->len ? (s)->buf[(s)->len - 1] : '\0')
 
-void
+static void
 StringDispose (String *s)
 {
     Dispose (s->buf);
     Dispose (s);
 }
 
-typedef struct {
-    String  *tag;
-    String  *text;
-} Replace;
-
-Replace *
+static Replace *
 ReplaceNew (void)
 {
     Replace *r = New (sizeof (Replace));
@@ -137,7 +240,7 @@ ReplaceNew (void)
     return r;
 }
 
-void
+static void
 ReplaceDispose (Replace *r)
 {
     StringDispose (r->tag);
@@ -145,7 +248,16 @@ ReplaceDispose (Replace *r)
     Dispose (r);
 }
 
-Replace *
+static void
+Bail (const char *format, const char *arg)
+{
+    fprintf (stderr, "fatal: ");
+    fprintf (stderr, format, arg);
+    fprintf (stderr, "\n");
+    exit (1);
+}
+
+static Replace *
 ReplaceRead (FILE *f)
 {
     int            c;
@@ -164,6 +276,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,17 +292,17 @@ 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);
+    if (StringLast(r->text) == '%')
+    {
        StringDel (r->text);
+       StringAdd (r->text, ' ');
+    }
     return r;
 }
 
-typedef struct _replaceList {
-    struct _replaceList        *next;
-    Replace            *r;
-} ReplaceList;
-
-ReplaceList *
+static ReplaceList *
 ReplaceListNew (Replace *r, ReplaceList *next)
 {
     ReplaceList        *l = New (sizeof (ReplaceList));
@@ -197,7 +311,7 @@ ReplaceListNew (Replace *r, ReplaceList *next)
     return l;
 }
 
-void
+static void
 ReplaceListDispose (ReplaceList *l)
 {
     if (l)
@@ -208,11 +322,7 @@ ReplaceListDispose (ReplaceList *l)
     }
 }
 
-typedef struct {
-    ReplaceList        *head;
-} ReplaceSet;
-
-ReplaceSet *
+static ReplaceSet *
 ReplaceSetNew (void)
 {
     ReplaceSet *s = New (sizeof (ReplaceSet));
@@ -220,20 +330,20 @@ ReplaceSetNew (void)
     return s;
 }
 
-void
+static void
 ReplaceSetDispose (ReplaceSet *s)
 {
     ReplaceListDispose (s->head);
     Dispose (s);
 }
 
-void
+static void
 ReplaceSetAdd (ReplaceSet *s, Replace *r)
 {
     s->head = ReplaceListNew (r, s->head);
 }
 
-Replace *
+static Replace *
 ReplaceSetFind (ReplaceSet *s, char *tag)
 {
     ReplaceList        *l;
@@ -244,7 +354,7 @@ ReplaceSetFind (ReplaceSet *s, char *tag)
     return 0;
 }
 
-ReplaceSet *
+static ReplaceSet *
 ReplaceSetRead (FILE *f)
 {
     ReplaceSet *s = ReplaceSetNew ();
@@ -264,12 +374,7 @@ ReplaceSetRead (FILE *f)
     return s;
 }
 
-typedef struct _skipStack {
-    struct _skipStack  *prev;
-    int                        skipping;
-} SkipStack;
-
-SkipStack *
+static SkipStack *
 SkipStackPush (SkipStack *prev, int skipping)
 {
     SkipStack  *ss = New (sizeof (SkipStack));
@@ -278,7 +383,7 @@ SkipStackPush (SkipStack *prev, int skipping)
     return ss;
 }
 
-SkipStack *
+static SkipStack *
 SkipStackPop (SkipStack *prev)
 {
     SkipStack  *ss = prev->prev;
@@ -286,14 +391,7 @@ SkipStackPop (SkipStack *prev)
     return ss;
 }
 
-typedef struct _loopStack {
-    struct _loopStack  *prev;
-    String             *tag;
-    String             *extra;
-    long               pos;
-} LoopStack;
-
-LoopStack *
+static LoopStack *
 LoopStackPush (LoopStack *prev, FILE *f, char *tag)
 {
     LoopStack  *ls = New (sizeof (LoopStack));
@@ -304,7 +402,7 @@ LoopStackPush (LoopStack *prev, FILE *f, char *tag)
     return ls;
 }
 
-LoopStack *
+static LoopStack *
 LoopStackLoop (ReplaceSet *rs, LoopStack *ls, FILE *f)
 {
     String     *s = StringMake (ls->tag->buf);
@@ -327,7 +425,7 @@ LoopStackLoop (ReplaceSet *rs, LoopStack *ls, FILE *f)
     return ret;
 }
 
-void
+static void
 LineSkip (FILE *f)
 {
     int        c;
@@ -337,7 +435,7 @@ LineSkip (FILE *f)
     ungetc (c, f);
 }
 
-void
+static void
 DoReplace (FILE *f, ReplaceSet *s)
 {
     int                c;
@@ -408,10 +506,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 +521,6 @@ main (int argc, char **argv)
        rewind (f);
     }
     if (ferror (stdout))
-       exit (1);
+       Bail ("%s", "error writing output");
     exit (0);
 }