2 b2cfc4e2 2003-09-30 devnull * The authors of this software are Rob Pike and Ken Thompson.
3 b2cfc4e2 2003-09-30 devnull * Copyright (c) 2002 by Lucent Technologies.
4 b2cfc4e2 2003-09-30 devnull * Permission to use, copy, modify, and distribute this software for any
5 b2cfc4e2 2003-09-30 devnull * purpose without fee is hereby granted, provided that this entire notice
6 b2cfc4e2 2003-09-30 devnull * is included in all copies of any software which is or includes a copy
7 b2cfc4e2 2003-09-30 devnull * or modification of this software and in all copies of the supporting
8 b2cfc4e2 2003-09-30 devnull * documentation for such software.
9 b2cfc4e2 2003-09-30 devnull * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
10 b2cfc4e2 2003-09-30 devnull * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
11 b2cfc4e2 2003-09-30 devnull * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
12 b2cfc4e2 2003-09-30 devnull * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
14 b2cfc4e2 2003-09-30 devnull #include <stdarg.h>
15 b2cfc4e2 2003-09-30 devnull #include <string.h>
16 b2cfc4e2 2003-09-30 devnull #include "utf.h"
17 b2cfc4e2 2003-09-30 devnull #include "fmt.h"
18 b2cfc4e2 2003-09-30 devnull #include "fmtdef.h"
20 b2cfc4e2 2003-09-30 devnull /* format the output into f->to and return the number of characters fmted */
23 b2cfc4e2 2003-09-30 devnull dorfmt(Fmt *f, const Rune *fmt)
25 b2cfc4e2 2003-09-30 devnull Rune *rt, *rs;
27 b2cfc4e2 2003-09-30 devnull char *t, *s;
28 b2cfc4e2 2003-09-30 devnull int nfmt;
30 b2cfc4e2 2003-09-30 devnull nfmt = f->nfmt;
32 b2cfc4e2 2003-09-30 devnull if(f->runes){
33 b2cfc4e2 2003-09-30 devnull rt = f->to;
34 b2cfc4e2 2003-09-30 devnull rs = f->stop;
35 b2cfc4e2 2003-09-30 devnull while((r = *fmt++) && r != '%'){
36 b2cfc4e2 2003-09-30 devnull FMTRCHAR(f, rt, rs, r);
38 b2cfc4e2 2003-09-30 devnull f->nfmt += rt - (Rune *)f->to;
39 b2cfc4e2 2003-09-30 devnull f->to = rt;
41 b2cfc4e2 2003-09-30 devnull return f->nfmt - nfmt;
42 b2cfc4e2 2003-09-30 devnull f->stop = rs;
44 b2cfc4e2 2003-09-30 devnull t = f->to;
45 b2cfc4e2 2003-09-30 devnull s = f->stop;
46 b2cfc4e2 2003-09-30 devnull while((r = *fmt++) && r != '%'){
47 b2cfc4e2 2003-09-30 devnull FMTRUNE(f, t, f->stop, r);
49 b2cfc4e2 2003-09-30 devnull f->nfmt += t - (char *)f->to;
50 b2cfc4e2 2003-09-30 devnull f->to = t;
52 b2cfc4e2 2003-09-30 devnull return f->nfmt - nfmt;
53 b2cfc4e2 2003-09-30 devnull f->stop = s;
56 b2cfc4e2 2003-09-30 devnull fmt = __fmtdispatch(f, fmt, 1);
57 b2cfc4e2 2003-09-30 devnull if(fmt == nil)
58 b2cfc4e2 2003-09-30 devnull return -1;
60 b2cfc4e2 2003-09-30 devnull return 0; /* not reached */