~ubuntu-branches/ubuntu/maverick/9base/maverick

« back to all changes in this revision

Viewing changes to lib9/fmt/fmtlocale.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-08-20 17:34:06 UTC
  • mfrom: (6.2.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090820173406-xpwqa9ruyevvc0ut
Tags: 1:3-3
* Updating maintainer field.
* Updating vcs fields.
* Updating package to standards version 3.8.3.
* Updatin variables writing in rules to consistent style.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2004 Google Inc.; see LICENSE */
 
2
 
 
3
#include <stdarg.h>
 
4
#include <string.h>
 
5
#include "plan9.h"
 
6
#include "fmt.h"
 
7
#include "fmtdef.h"
 
8
 
 
9
/*
 
10
 * Fill in the internationalization stuff in the State structure.
 
11
 * For nil arguments, provide the sensible defaults:
 
12
 *      decimal is a period
 
13
 *      thousands separator is a comma
 
14
 *      thousands are marked every three digits
 
15
 */
 
16
void
 
17
fmtlocaleinit(Fmt *f, char *decimal, char *thousands, char *grouping)
 
18
{
 
19
        if(decimal == nil || decimal[0] == '\0')
 
20
                decimal = ".";
 
21
        if(thousands == nil)
 
22
                thousands = ",";
 
23
        if(grouping == nil)
 
24
                grouping = "\3";
 
25
        f->decimal = decimal;
 
26
        f->thousands = thousands;
 
27
        f->grouping = grouping;
 
28
}
 
29
 
 
30
/*
 
31
 * We are about to emit a digit in e.g. %'d.  If that digit would
 
32
 * overflow a thousands (e.g.) grouping, tell the caller to emit
 
33
 * the thousands separator.  Always advance the digit counter
 
34
 * and pointer into the grouping descriptor.
 
35
 */
 
36
int
 
37
__needsep(int *ndig, char **grouping)
 
38
{
 
39
        int group;
 
40
        
 
41
        (*ndig)++;
 
42
        group = *(unsigned char*)*grouping;
 
43
        /* CHAR_MAX means no further grouping. \0 means we got the empty string */
 
44
        if(group == 0xFF || group == 0x7f || group == 0x00)
 
45
                return 0;
 
46
        if(*ndig > group){
 
47
                /* if we're at end of string, continue with this grouping; else advance */
 
48
                if((*grouping)[1] != '\0')
 
49
                        (*grouping)++;
 
50
                *ndig = 1;
 
51
                return 1;
 
52
        }
 
53
        return 0;
 
54
}
 
55