Blame


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