Blame


1 91c13e54 2004-02-29 devnull /*
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 91c13e54 2004-02-29 devnull * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
11 91c13e54 2004-02-29 devnull * 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.
13 91c13e54 2004-02-29 devnull */
14 91c13e54 2004-02-29 devnull #include <stdarg.h>
15 91c13e54 2004-02-29 devnull #include <string.h>
16 91c13e54 2004-02-29 devnull #include <stdlib.h>
17 91c13e54 2004-02-29 devnull #include "utf.h"
18 91c13e54 2004-02-29 devnull #include "fmt.h"
19 91c13e54 2004-02-29 devnull #include "fmtdef.h"
20 91c13e54 2004-02-29 devnull
21 91c13e54 2004-02-29 devnull static int
22 91c13e54 2004-02-29 devnull runeFmtStrFlush(Fmt *f)
23 91c13e54 2004-02-29 devnull {
24 91c13e54 2004-02-29 devnull Rune *s;
25 91c13e54 2004-02-29 devnull int n;
26 91c13e54 2004-02-29 devnull
27 91c13e54 2004-02-29 devnull n = (int)f->farg;
28 91c13e54 2004-02-29 devnull n += 256;
29 91c13e54 2004-02-29 devnull f->farg = (void*)n;
30 91c13e54 2004-02-29 devnull s = (Rune*)f->start;
31 91c13e54 2004-02-29 devnull f->start = realloc(s, sizeof(Rune)*n);
32 91c13e54 2004-02-29 devnull if(f->start == nil){
33 91c13e54 2004-02-29 devnull f->start = s;
34 91c13e54 2004-02-29 devnull return 0;
35 91c13e54 2004-02-29 devnull }
36 91c13e54 2004-02-29 devnull f->to = (Rune*)f->start + ((Rune*)f->to - s);
37 91c13e54 2004-02-29 devnull f->stop = (Rune*)f->start + n - 1;
38 91c13e54 2004-02-29 devnull return 1;
39 91c13e54 2004-02-29 devnull }
40 91c13e54 2004-02-29 devnull
41 91c13e54 2004-02-29 devnull int
42 91c13e54 2004-02-29 devnull runefmtstrinit(Fmt *f)
43 91c13e54 2004-02-29 devnull {
44 91c13e54 2004-02-29 devnull int n;
45 91c13e54 2004-02-29 devnull
46 91c13e54 2004-02-29 devnull f->runes = 1;
47 91c13e54 2004-02-29 devnull n = 32;
48 91c13e54 2004-02-29 devnull f->start = malloc(sizeof(Rune)*n);
49 91c13e54 2004-02-29 devnull if(f->start == nil)
50 91c13e54 2004-02-29 devnull return -1;
51 91c13e54 2004-02-29 devnull f->to = f->start;
52 91c13e54 2004-02-29 devnull f->stop = (Rune*)f->start + n - 1;
53 91c13e54 2004-02-29 devnull f->flush = runeFmtStrFlush;
54 91c13e54 2004-02-29 devnull f->farg = (void*)n;
55 91c13e54 2004-02-29 devnull f->nfmt = 0;
56 91c13e54 2004-02-29 devnull return 0;
57 91c13e54 2004-02-29 devnull }
58 91c13e54 2004-02-29 devnull
59 91c13e54 2004-02-29 devnull Rune*
60 91c13e54 2004-02-29 devnull runefmtstrflush(Fmt *f)
61 91c13e54 2004-02-29 devnull {
62 91c13e54 2004-02-29 devnull *(Rune*)f->to = '\0';
63 91c13e54 2004-02-29 devnull f->to = f->start;
64 91c13e54 2004-02-29 devnull return f->start;
65 91c13e54 2004-02-29 devnull }