]> Cypherpunks repositories - gostls13.git/commitdiff
convert C runtime to 32-bit runes;
authorRuss Cox <rsc@golang.org>
Mon, 31 Aug 2009 23:38:50 +0000 (16:38 -0700)
committerRuss Cox <rsc@golang.org>
Mon, 31 Aug 2009 23:38:50 +0000 (16:38 -0700)
rune now unsigned.

R=r
DELTA=10  (1 added, 0 deleted, 9 changed)
OCL=34140
CL=34146

include/fmt.h
src/lib9/fmt/dofmt.c
src/lib9/utf/utf.h
src/libbio/bgetrune.c
src/libbio/bputrune.c

index 480ccad58d4538b5bf912b209231d4b41849e925..2280f25250b7adfdfadf7aa0b1ad329ee6bc69d2 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef _FMT_H_
 #define _FMT_H_ 1
 #if defined(__cplusplus)
-extern "C" { 
+extern "C" {
 #endif
 /*
  * The authors of this software are Rob Pike and Ken Thompson.
@@ -30,7 +30,7 @@ struct Fmt{
        void    *farg;                  /* to make flush a closure */
        int     nfmt;                   /* num chars formatted so far */
        va_list args;                   /* args passed to dofmt */
-       int     r;                      /* % format Rune */
+       Rune    r;                      /* % format Rune */
        int     width;
        int     prec;
        unsigned long   flags;
@@ -38,8 +38,8 @@ struct Fmt{
 
        /* For %'d */
        char *thousands;        /* separator for thousands */
-       
-       /* 
+
+       /*
         * Each char is an integer indicating #digits before next separator. Values:
         *      \xFF: no more grouping (or \x7F; defined to be CHAR_MAX in POSIX)
         *      \x00: repeat previous indefinitely
index ea43940d859748c3f06f78fc8edc2b38b4d1b0ef..51f0f079b7cd505745a11b54940be6bcaad5273d 100644 (file)
@@ -4,15 +4,15 @@
  *
  *     Copyright (c) 2002-2006 by Lucent Technologies.
  *     Portions Copyright (c) 2004 Google Inc.
- * 
+ *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose without fee is hereby granted, provided that this entire notice
  * is included in all copies of any software which is or includes a copy
  * or modification of this software and in all copies of the supporting
  * documentation for such software.
  * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTY.  IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 
- * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 
+ * WARRANTY.  IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES
+ * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING
  * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
  */
 
@@ -618,12 +618,13 @@ __flagfmt(Fmt *f)
 int
 __badfmt(Fmt *f)
 {
-       char x[3];
+       char x[2+UTFmax];
+       int n;
 
        x[0] = '%';
-       x[1] = f->r;
-       x[2] = '%';
-       f->prec = 3;
-       __fmtcpy(f, (const void*)x, 3, 3);
+       n = 1 + runetochar(x+1, &f->r);
+       x[n++] = '%';
+       f->prec = n;
+       __fmtcpy(f, (const void*)x, n, n);
        return 0;
 }
index ff5193ad408fed21792172fac63aecd51d04e793..1479e9f2187d7734821cdb7ec96325ae07c3bc47 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <stdint.h>
 
-typedef signed int Rune;       /* Code-point values in Unicode 4.0 are 21 bits wide.*/
+typedef unsigned int Rune;     /* Code-point values in Unicode 4.0 are 21 bits wide.*/
 
 enum
 {
index caeb0a88fff10e88fdd4e542bb44fbcdd456d3fe..1538f3ea7417d36058e83242c5b917a84dcbd0a1 100644 (file)
@@ -33,7 +33,7 @@ Bgetrune(Biobuf *bp)
 {
        int c, i;
        Rune rune;
-       char str[4];
+       char str[UTFmax];
 
        c = Bgetc(bp);
        if(c < Runeself) {              /* one char */
index 9c588db9df0f951978db6cfd32070ed71287ebb9..e46f3c7101c73175b396c301fe39b9d408cb9d02 100644 (file)
@@ -32,7 +32,7 @@ int
 Bputrune(Biobuf *bp, long c)
 {
        Rune rune;
-       char str[4];
+       char str[UTFmax];
        int n;
 
        rune = c;