dorfmt.c (1008B) download
1/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */
2#include "fmt.h"
3#include "fmtdef.h"
4#include "plan9.h"
5
6#include <stdarg.h>
7#include <string.h>
8
9/* format the output into f->to and return the number of characters fmted */
10
11/* BUG: THIS FILE IS NOT UPDATED TO THE NEW SPEC */
12int dorfmt(Fmt* f, const Rune* fmt) {
13 Rune *rt, *rs;
14 int r;
15 char *t, *s;
16 int nfmt;
17
18 nfmt = f->nfmt;
19 for (;;) {
20 if (f->runes) {
21 rt = (Rune*) f->to;
22 rs = (Rune*) f->stop;
23 while ((r = *fmt++) && r != '%') {
24 FMTRCHAR(f, rt, rs, r);
25 }
26 f->nfmt += rt - (Rune*) f->to;
27 f->to = rt;
28 if (!r)
29 return f->nfmt - nfmt;
30 f->stop = rs;
31 } else {
32 t = (char*) f->to;
33 s = (char*) f->stop;
34 while ((r = *fmt++) && r != '%') {
35 FMTRUNE(f, t, f->stop, r);
36 }
37 f->nfmt += t - (char*) f->to;
38 f->to = t;
39 if (!r)
40 return f->nfmt - nfmt;
41 f->stop = s;
42 }
43
44 fmt = (Rune*) __fmtdispatch(f, (Rune*) fmt, 1);
45 if (fmt == nil)
46 return -1;
47 }
48 return 0; /* not reached */
49}