X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=doc%2Fedit-sgml.c;h=cc2ee763303295d5bc83609e214dcbb53c0dd74a;hb=5aaf466d3899842763e746a9c2b745748eb34b48;hp=77cc807c1d0f16791212de7d384b7a2c0d6431f2;hpb=822ec78c54a24a0f1589154ac2d4906b02b111ef;p=fontconfig.git diff --git a/doc/edit-sgml.c b/doc/edit-sgml.c index 77cc807..cc2ee76 100644 --- a/doc/edit-sgml.c +++ b/doc/edit-sgml.c @@ -1,5 +1,5 @@ /* - * $Id$ + * fontconfig/doc/edit-sgml.c * * Copyright © 2003 Keith Packard * @@ -7,15 +7,15 @@ * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in + * documentation, and that the name of the author(s) not be used in * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no + * specific, written prior permission. The authors make no * representations about the suitability of this software for any purpose. It * is provided "as is" without express or implied warranty. * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR @@ -77,10 +77,10 @@ static void ReplaceDispose (Replace *r); static void -Bail (const char *format, const char *arg); +Bail (const char *format, int line, const char *arg); static Replace * -ReplaceRead (FILE *f); +ReplaceRead (FILE *f, int *linep); typedef struct _replaceList { struct _replaceList *next; @@ -110,7 +110,7 @@ static Replace * ReplaceSetFind (ReplaceSet *s, char *tag); static ReplaceSet * -ReplaceSetRead (FILE *f); +ReplaceSetRead (FILE *f, int *linep); typedef struct _skipStack { struct _skipStack *prev; @@ -137,10 +137,10 @@ static LoopStack * LoopStackLoop (ReplaceSet *rs, LoopStack *ls, FILE *f); static void -LineSkip (FILE *f); +LineSkip (FILE *f, int *linep); static void -DoReplace (FILE *f, ReplaceSet *s); +DoReplace (FILE *f, int *linep, ReplaceSet *s); #define STRING_INIT 128 @@ -249,27 +249,44 @@ ReplaceDispose (Replace *r) } static void -Bail (const char *format, const char *arg) +Bail (const char *format, int line, const char *arg) { fprintf (stderr, "fatal: "); - fprintf (stderr, format, arg); + fprintf (stderr, format, line, arg); fprintf (stderr, "\n"); exit (1); } +static int +Getc (FILE *f, int *linep) +{ + int c = getc (f); + if (c == '\n') + ++(*linep); + return c; +} + +static void +Ungetc (int c, FILE *f, int *linep) +{ + if (c == '\n') + --(*linep); + ungetc (c, f); +} + static Replace * -ReplaceRead (FILE *f) +ReplaceRead (FILE *f, int *linep) { int c; Replace *r; - while ((c = getc (f)) != '@') + while ((c = Getc (f, linep)) != '@') { if (c == EOF) return 0; } r = ReplaceNew(); - while ((c = getc (f)) != '@') + while ((c = Getc (f, linep)) != '@') { if (c == EOF) { @@ -277,7 +294,7 @@ ReplaceRead (FILE *f) return 0; } if (isspace (c)) - Bail ("invalid character after tag %s", r->tag->buf); + Bail ("%d: invalid character after tag %s", *linep, r->tag->buf); StringAdd (r->tag, c); } if (r->tag->buf[0] == '\0') @@ -285,15 +302,20 @@ ReplaceRead (FILE *f) ReplaceDispose (r); return 0; } - while (isspace ((c = getc (f)))) + while (isspace ((c = Getc (f, linep)))) ; - ungetc (c, f); - while ((c = getc (f)) != '@' && c != EOF) + Ungetc (c, f, linep); + while ((c = Getc (f, linep)) != '@' && c != EOF) StringAdd (r->text, c); if (c == '@') - ungetc (c, f); + Ungetc (c, f, linep); while (isspace (StringLast (r->text))) StringDel (r->text); + if (StringLast(r->text) == '%') + { + StringDel (r->text); + StringAdd (r->text, ' '); + } return r; } @@ -350,12 +372,12 @@ ReplaceSetFind (ReplaceSet *s, char *tag) } static ReplaceSet * -ReplaceSetRead (FILE *f) +ReplaceSetRead (FILE *f, int *linep) { ReplaceSet *s = ReplaceSetNew (); Replace *r; - while ((r = ReplaceRead (f))) + while ((r = ReplaceRead (f, linep))) { while (ReplaceSetFind (s, r->tag->buf)) StringAdd (r->tag, '+'); @@ -421,17 +443,17 @@ LoopStackLoop (ReplaceSet *rs, LoopStack *ls, FILE *f) } static void -LineSkip (FILE *f) +LineSkip (FILE *f, int *linep) { int c; - while ((c = getc (f)) == '\n') + while ((c = Getc (f, linep)) == '\n') ; - ungetc (c, f); + Ungetc (c, f, linep); } static void -DoReplace (FILE *f, ReplaceSet *s) +DoReplace (FILE *f, int *linep, ReplaceSet *s) { int c; String *tag; @@ -440,12 +462,12 @@ DoReplace (FILE *f, ReplaceSet *s) LoopStack *ls = 0; int skipping = 0; - while ((c = getc (f)) != EOF) + while ((c = Getc (f, linep)) != EOF) { if (c == '@') { tag = StringNew (); - while ((c = getc (f)) != '@') + while ((c = Getc (f, linep)) != '@') { if (c == EOF) abort (); @@ -458,7 +480,7 @@ DoReplace (FILE *f, ReplaceSet *s) ss = SkipStackPush (ss, skipping); if (!ReplaceSetFind (s, tag->buf + 1)) skipping++; - LineSkip (f); + LineSkip (f, linep); break; case ':': if (!ss) @@ -467,20 +489,20 @@ DoReplace (FILE *f, ReplaceSet *s) ++skipping; else --skipping; - LineSkip (f); + LineSkip (f, linep); break; case ';': skipping = ss->skipping; ss = SkipStackPop (ss); - LineSkip (f); + LineSkip (f, linep); break; case '{': ls = LoopStackPush (ls, f, tag->buf + 1); - LineSkip (f); + LineSkip (f, linep); break; case '}': ls = LoopStackLoop (s, ls, f); - LineSkip (f); + LineSkip (f, linep); break; default: r = ReplaceSetFind (s, tag->buf); @@ -500,22 +522,25 @@ main (int argc, char **argv) { FILE *f; ReplaceSet *s; + int iline, oline; if (!argv[1]) - Bail ("usage: %s ", argv[0]); + Bail ("usage: %*s ", 0, argv[0]); f = fopen (argv[1], "r"); if (!f) { - Bail ("can't open file %s", argv[1]); + Bail ("can't open file %s", 0, argv[1]); exit (1); } - while ((s = ReplaceSetRead (stdin))) + iline = 1; + while ((s = ReplaceSetRead (stdin, &iline))) { - DoReplace (f, s); + oline = 1; + DoReplace (f, &oline, s); ReplaceSetDispose (s); rewind (f); } if (ferror (stdout)) - Bail ("%s", "error writing output"); + Bail ("%s", 0, "error writing output"); exit (0); }