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