import changes from plan 9
This commit is contained in:
parent
a76c0fd4a9
commit
df121a0027
18 changed files with 171 additions and 167 deletions
|
|
@ -526,11 +526,9 @@ __flagfmt(Fmt *f)
|
||||||
f->flags |= FmtByte;
|
f->flags |= FmtByte;
|
||||||
f->flags |= FmtShort;
|
f->flags |= FmtShort;
|
||||||
break;
|
break;
|
||||||
#ifndef PLAN9PORT
|
|
||||||
case 'L':
|
case 'L':
|
||||||
f->flags |= FmtLDouble;
|
f->flags |= FmtLDouble;
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
case 'l':
|
case 'l':
|
||||||
if(f->flags & FmtLong)
|
if(f->flags & FmtLong)
|
||||||
f->flags |= FmtVLong;
|
f->flags |= FmtVLong;
|
||||||
|
|
|
||||||
|
|
@ -370,39 +370,6 @@ found:
|
||||||
s2[d] = 0;
|
s2[d] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
fmtzdotpad(Fmt *f, int n, int pt)
|
|
||||||
{
|
|
||||||
char *t, *s;
|
|
||||||
int i;
|
|
||||||
Rune *rt, *rs;
|
|
||||||
|
|
||||||
if(f->runes){
|
|
||||||
rt = (Rune*)f->to;
|
|
||||||
rs = (Rune*)f->stop;
|
|
||||||
for(i = 0; i < n; i++){
|
|
||||||
if(i == pt){
|
|
||||||
FMTRCHAR(f, rt, rs, '.');
|
|
||||||
}
|
|
||||||
FMTRCHAR(f, rt, rs, '0');
|
|
||||||
}
|
|
||||||
f->nfmt += rt - (Rune*)f->to;
|
|
||||||
f->to = rt;
|
|
||||||
}else{
|
|
||||||
t = (char*)f->to;
|
|
||||||
s = (char*)f->stop;
|
|
||||||
for(i = 0; i < n; i++){
|
|
||||||
if(i == pt){
|
|
||||||
FMTCHAR(f, t, s, '.');
|
|
||||||
}
|
|
||||||
FMTCHAR(f, t, s, '0');
|
|
||||||
}
|
|
||||||
f->nfmt += t - (char *)f->to;
|
|
||||||
f->to = t;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
floatfmt(Fmt *fmt, double f)
|
floatfmt(Fmt *fmt, double f)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,13 @@ static Convfmt knownfmt[] = {
|
||||||
'-', __flagfmt,
|
'-', __flagfmt,
|
||||||
'C', __runefmt, /* Plan 9 addition */
|
'C', __runefmt, /* Plan 9 addition */
|
||||||
'E', __efgfmt,
|
'E', __efgfmt,
|
||||||
|
#ifndef PLAN9PORT
|
||||||
'F', __efgfmt, /* ANSI only */
|
'F', __efgfmt, /* ANSI only */
|
||||||
|
#endif
|
||||||
'G', __efgfmt,
|
'G', __efgfmt,
|
||||||
|
#ifndef PLAN9PORT
|
||||||
'L', __flagfmt, /* ANSI only */
|
'L', __flagfmt, /* ANSI only */
|
||||||
|
#endif
|
||||||
'S', __runesfmt, /* Plan 9 addition */
|
'S', __runesfmt, /* Plan 9 addition */
|
||||||
'X', __ifmt,
|
'X', __ifmt,
|
||||||
'b', __ifmt, /* Plan 9 addition */
|
'b', __ifmt, /* Plan 9 addition */
|
||||||
|
|
@ -57,7 +61,9 @@ static Convfmt knownfmt[] = {
|
||||||
'f', __efgfmt,
|
'f', __efgfmt,
|
||||||
'g', __efgfmt,
|
'g', __efgfmt,
|
||||||
'h', __flagfmt,
|
'h', __flagfmt,
|
||||||
|
#ifndef PLAN9PORT
|
||||||
'i', __ifmt, /* ANSI only */
|
'i', __ifmt, /* ANSI only */
|
||||||
|
#endif
|
||||||
'l', __flagfmt,
|
'l', __flagfmt,
|
||||||
'n', __countfmt,
|
'n', __countfmt,
|
||||||
'o', __ifmt,
|
'o', __ifmt,
|
||||||
|
|
|
||||||
|
|
@ -105,3 +105,12 @@ int __strfmt(Fmt *f);
|
||||||
t += runetochar(t, &_rune);\
|
t += runetochar(t, &_rune);\
|
||||||
}\
|
}\
|
||||||
}while(0)
|
}while(0)
|
||||||
|
|
||||||
|
#ifdef va_copy
|
||||||
|
# define VA_COPY(a,b) va_copy(a,b)
|
||||||
|
# define VA_END(a) va_end(a)
|
||||||
|
#else
|
||||||
|
# define VA_COPY(a,b) (a) = (b)
|
||||||
|
# define VA_END(a)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,9 @@
|
||||||
void
|
void
|
||||||
__fmtlock(void)
|
__fmtlock(void)
|
||||||
{
|
{
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
__fmtunlock(void)
|
__fmtunlock(void)
|
||||||
{
|
{
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
#include "fmt.h"
|
#include "fmt.h"
|
||||||
#include "fmtdef.h"
|
#include "fmtdef.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* format a string into the output buffer
|
* format a string into the output buffer
|
||||||
* designed for formats which themselves call fmt,
|
* designed for formats which themselves call fmt,
|
||||||
|
|
@ -32,15 +31,16 @@ fmtprint(Fmt *f, char *fmt, ...)
|
||||||
f->flags = 0;
|
f->flags = 0;
|
||||||
f->width = 0;
|
f->width = 0;
|
||||||
f->prec = 0;
|
f->prec = 0;
|
||||||
va_copy(va, f->args);
|
VA_COPY(va, f->args);
|
||||||
|
VA_END(f->args);
|
||||||
va_start(f->args, fmt);
|
va_start(f->args, fmt);
|
||||||
n = dofmt(f, fmt);
|
n = dofmt(f, fmt);
|
||||||
va_end(f->args);
|
va_end(f->args);
|
||||||
f->flags = 0;
|
f->flags = 0;
|
||||||
f->width = 0;
|
f->width = 0;
|
||||||
f->prec = 0;
|
f->prec = 0;
|
||||||
va_copy(f->args,va);
|
VA_COPY(f->args,va);
|
||||||
va_end(va);
|
VA_END(va);
|
||||||
if(n >= 0)
|
if(n >= 0)
|
||||||
return 0;
|
return 0;
|
||||||
return n;
|
return n;
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ __quotesetup(char *s, Rune *r, int nin, int nout, Quoteinfo *q, int sharp, int r
|
||||||
q->nbytesout = 2;
|
q->nbytesout = 2;
|
||||||
q->nrunesout = 2;
|
q->nrunesout = 2;
|
||||||
}
|
}
|
||||||
for(; nin!=0; nin-=w){
|
for(; nin!=0; nin--){
|
||||||
if(s)
|
if(s)
|
||||||
w = chartorune(&c, s);
|
w = chartorune(&c, s);
|
||||||
else{
|
else{
|
||||||
|
|
@ -183,12 +183,14 @@ qstrfmt(char *sin, Rune *rin, Quoteinfo *q, Fmt *f)
|
||||||
int
|
int
|
||||||
__quotestrfmt(int runesin, Fmt *f)
|
__quotestrfmt(int runesin, Fmt *f)
|
||||||
{
|
{
|
||||||
int outlen;
|
int nin, outlen;
|
||||||
Rune *r;
|
Rune *r;
|
||||||
char *s;
|
char *s;
|
||||||
Quoteinfo q;
|
Quoteinfo q;
|
||||||
|
|
||||||
f->flags &= ~FmtPrec; /* ignored for %q %Q, so disable for %s %S in easy case */
|
nin = -1;
|
||||||
|
if(f->flags&FmtPrec)
|
||||||
|
nin = f->prec;
|
||||||
if(runesin){
|
if(runesin){
|
||||||
r = va_arg(f->args, Rune *);
|
r = va_arg(f->args, Rune *);
|
||||||
s = nil;
|
s = nil;
|
||||||
|
|
@ -206,7 +208,7 @@ __quotestrfmt(int runesin, Fmt *f)
|
||||||
else
|
else
|
||||||
outlen = (char*)f->stop - (char*)f->to;
|
outlen = (char*)f->stop - (char*)f->to;
|
||||||
|
|
||||||
__quotesetup(s, r, -1, outlen, &q, f->flags&FmtSharp, f->runes);
|
__quotesetup(s, r, nin, outlen, &q, f->flags&FmtSharp, f->runes);
|
||||||
//print("bytes in %d bytes out %d runes in %d runesout %d\n", q.nbytesin, q.nbytesout, q.nrunesin, q.nrunesout);
|
//print("bytes in %d bytes out %d runes in %d runesout %d\n", q.nbytesin, q.nbytesout, q.nrunesin, q.nrunesout);
|
||||||
|
|
||||||
if(runesin){
|
if(runesin){
|
||||||
|
|
|
||||||
|
|
@ -11,63 +11,17 @@
|
||||||
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
|
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
|
||||||
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
/*
|
|
||||||
* Plan 9 port version must include libc.h in order to
|
|
||||||
* get Plan 9 debugging malloc, which sometimes returns
|
|
||||||
* different pointers than the standard malloc.
|
|
||||||
*/
|
|
||||||
#ifdef PLAN9PORT
|
|
||||||
#include <u.h>
|
|
||||||
#include <libc.h>
|
|
||||||
#else
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include "plan9.h"
|
#include "plan9.h"
|
||||||
#include "fmt.h"
|
#include "fmt.h"
|
||||||
#include "fmtdef.h"
|
#include "fmtdef.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
static int
|
|
||||||
fmtStrFlush(Fmt *f)
|
|
||||||
{
|
|
||||||
char *s;
|
|
||||||
int n;
|
|
||||||
|
|
||||||
n = (int)f->farg;
|
|
||||||
n += 256;
|
|
||||||
f->farg = (void*)n;
|
|
||||||
s = (char*)f->start;
|
|
||||||
f->start = realloc(s, n);
|
|
||||||
if(f->start == nil){
|
|
||||||
f->start = s;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
f->to = (char*)f->start + ((char*)f->to - s);
|
|
||||||
f->stop = (char*)f->start + n - 1;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
fmtstrinit(Fmt *f)
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
|
|
||||||
f->runes = 0;
|
|
||||||
n = 32;
|
|
||||||
f->start = malloc(n);
|
|
||||||
if(f->start == nil)
|
|
||||||
return -1;
|
|
||||||
f->to = f->start;
|
|
||||||
f->stop = (char*)f->start + n - 1;
|
|
||||||
f->flush = fmtStrFlush;
|
|
||||||
f->farg = (void*)n;
|
|
||||||
f->nfmt = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
char*
|
char*
|
||||||
fmtstrflush(Fmt *f)
|
fmtstrflush(Fmt *f)
|
||||||
{
|
{
|
||||||
|
if(f->start == nil)
|
||||||
|
return nil;
|
||||||
*(char*)f->to = '\0';
|
*(char*)f->to = '\0';
|
||||||
f->to = f->start;
|
|
||||||
return (char*)f->start;
|
return (char*)f->start;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,15 +32,16 @@ fmtvprint(Fmt *f, char *fmt, va_list args)
|
||||||
f->flags = 0;
|
f->flags = 0;
|
||||||
f->width = 0;
|
f->width = 0;
|
||||||
f->prec = 0;
|
f->prec = 0;
|
||||||
va_copy(va,f->args);
|
VA_COPY(va,f->args);
|
||||||
va_copy(f->args,args);
|
VA_END(f->args);
|
||||||
|
VA_COPY(f->args,args);
|
||||||
n = dofmt(f, fmt);
|
n = dofmt(f, fmt);
|
||||||
f->flags = 0;
|
f->flags = 0;
|
||||||
f->width = 0;
|
f->width = 0;
|
||||||
f->prec = 0;
|
f->prec = 0;
|
||||||
va_end(f->args);
|
VA_END(f->args);
|
||||||
va_copy(f->args,va);
|
VA_COPY(f->args,va);
|
||||||
va_end(va);
|
VA_END(va);
|
||||||
if(n >= 0)
|
if(n >= 0)
|
||||||
return 0;
|
return 0;
|
||||||
return n;
|
return n;
|
||||||
|
|
|
||||||
|
|
@ -11,63 +11,17 @@
|
||||||
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
|
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
|
||||||
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
/*
|
#include <stdarg.h>
|
||||||
* Plan 9 port version must include libc.h in order to
|
|
||||||
* get Plan 9 debugging malloc, which sometimes returns
|
|
||||||
* different pointers than the standard malloc.
|
|
||||||
*/
|
|
||||||
#ifdef PLAN9PORT
|
|
||||||
#include <u.h>
|
|
||||||
#include <libc.h>
|
|
||||||
#else
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "plan9.h"
|
#include "plan9.h"
|
||||||
#include "fmt.h"
|
#include "fmt.h"
|
||||||
#include "fmtdef.h"
|
#include "fmtdef.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
static int
|
|
||||||
runeFmtStrFlush(Fmt *f)
|
|
||||||
{
|
|
||||||
Rune *s;
|
|
||||||
int n;
|
|
||||||
|
|
||||||
n = (int)f->farg;
|
|
||||||
n += 256;
|
|
||||||
f->farg = (void*)n;
|
|
||||||
s = (Rune*)f->start;
|
|
||||||
f->start = realloc(s, sizeof(Rune)*n);
|
|
||||||
if(f->start == nil){
|
|
||||||
f->start = s;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
f->to = (Rune*)f->start + ((Rune*)f->to - s);
|
|
||||||
f->stop = (Rune*)f->start + n - 1;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
runefmtstrinit(Fmt *f)
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
|
|
||||||
f->runes = 1;
|
|
||||||
n = 32;
|
|
||||||
f->start = malloc(sizeof(Rune)*n);
|
|
||||||
if(f->start == nil)
|
|
||||||
return -1;
|
|
||||||
f->to = f->start;
|
|
||||||
f->stop = (Rune*)f->start + n - 1;
|
|
||||||
f->flush = runeFmtStrFlush;
|
|
||||||
f->farg = (void*)n;
|
|
||||||
f->nfmt = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Rune*
|
Rune*
|
||||||
runefmtstrflush(Fmt *f)
|
runefmtstrflush(Fmt *f)
|
||||||
{
|
{
|
||||||
|
if(f->start == nil)
|
||||||
|
return nil;
|
||||||
*(Rune*)f->to = '\0';
|
*(Rune*)f->to = '\0';
|
||||||
f->to = f->start;
|
|
||||||
return f->start;
|
return f->start;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,9 @@ runevseprint(Rune *buf, Rune *e, char *fmt, va_list args)
|
||||||
f.flush = nil;
|
f.flush = nil;
|
||||||
f.farg = nil;
|
f.farg = nil;
|
||||||
f.nfmt = 0;
|
f.nfmt = 0;
|
||||||
va_copy(f.args,args);
|
VA_COPY(f.args,args);
|
||||||
dofmt(&f, fmt);
|
dofmt(&f, fmt);
|
||||||
va_end(f.args);
|
VA_END(f.args);
|
||||||
*(Rune*)f.to = '\0';
|
*(Rune*)f.to = '\0';
|
||||||
return (Rune*)f.to;
|
return (Rune*)f.to;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,64 @@
|
||||||
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
|
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
|
||||||
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
#include <stdarg.h>
|
/*
|
||||||
|
* Plan 9 port version must include libc.h in order to
|
||||||
|
* get Plan 9 debugging malloc, which sometimes returns
|
||||||
|
* different pointers than the standard malloc.
|
||||||
|
*/
|
||||||
|
#ifdef PLAN9PORT
|
||||||
|
#include <u.h>
|
||||||
|
#include <libc.h>
|
||||||
|
#else
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "plan9.h"
|
#include "plan9.h"
|
||||||
#include "fmt.h"
|
#include "fmt.h"
|
||||||
#include "fmtdef.h"
|
#include "fmtdef.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int
|
||||||
|
runeFmtStrFlush(Fmt *f)
|
||||||
|
{
|
||||||
|
Rune *s;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
if(f->start == nil)
|
||||||
|
return 0;
|
||||||
|
n = (int)f->farg;
|
||||||
|
n *= 2;
|
||||||
|
s = (Rune*)f->start;
|
||||||
|
f->start = realloc(s, sizeof(Rune)*n);
|
||||||
|
if(f->start == nil){
|
||||||
|
f->farg = nil;
|
||||||
|
f->to = nil;
|
||||||
|
f->stop = nil;
|
||||||
|
free(s);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
f->farg = (void*)n;
|
||||||
|
f->to = (Rune*)f->start + ((Rune*)f->to - s);
|
||||||
|
f->stop = (Rune*)f->start + n - 1;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
runefmtstrinit(Fmt *f)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
|
||||||
|
memset(f, 0, sizeof *f);
|
||||||
|
f->runes = 1;
|
||||||
|
n = 32;
|
||||||
|
f->start = malloc(sizeof(Rune)*n);
|
||||||
|
if(f->start == nil)
|
||||||
|
return -1;
|
||||||
|
f->to = f->start;
|
||||||
|
f->stop = (Rune*)f->start + n - 1;
|
||||||
|
f->flush = runeFmtStrFlush;
|
||||||
|
f->farg = (void*)n;
|
||||||
|
f->nfmt = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* print into an allocated string buffer
|
* print into an allocated string buffer
|
||||||
|
|
@ -28,11 +81,15 @@ runevsmprint(char *fmt, va_list args)
|
||||||
|
|
||||||
if(runefmtstrinit(&f) < 0)
|
if(runefmtstrinit(&f) < 0)
|
||||||
return nil;
|
return nil;
|
||||||
va_copy(f.args,args);
|
VA_COPY(f.args,args);
|
||||||
n = dofmt(&f, fmt);
|
n = dofmt(&f, fmt);
|
||||||
va_end(f.args);
|
VA_END(f.args);
|
||||||
if(n < 0)
|
if(f.start == nil)
|
||||||
return nil;
|
return nil;
|
||||||
|
if(n < 0){
|
||||||
|
free(f.start);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
*(Rune*)f.to = '\0';
|
*(Rune*)f.to = '\0';
|
||||||
return (Rune*)f.start;
|
return (Rune*)f.start;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,9 @@ runevsnprint(Rune *buf, int len, char *fmt, va_list args)
|
||||||
f.flush = nil;
|
f.flush = nil;
|
||||||
f.farg = nil;
|
f.farg = nil;
|
||||||
f.nfmt = 0;
|
f.nfmt = 0;
|
||||||
va_copy(f.args,args);
|
VA_COPY(f.args,args);
|
||||||
dofmt(&f, fmt);
|
dofmt(&f, fmt);
|
||||||
va_end(f.args);
|
VA_END(f.args);
|
||||||
*(Rune*)f.to = '\0';
|
*(Rune*)f.to = '\0';
|
||||||
return (Rune*)f.to - buf;
|
return (Rune*)f.to - buf;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
|
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
|
||||||
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <utf.h>
|
#include <utf.h>
|
||||||
#include "plan9.h"
|
#include "plan9.h"
|
||||||
|
|
@ -32,10 +33,12 @@ main(int argc, char *argv[])
|
||||||
print("e: %e %e %e\n", 3.14159, 3.14159e10, 3.14159e-10);
|
print("e: %e %e %e\n", 3.14159, 3.14159e10, 3.14159e-10);
|
||||||
print("f: %f %f %f\n", 3.14159, 3.14159e10, 3.14159e-10);
|
print("f: %f %f %f\n", 3.14159, 3.14159e10, 3.14159e-10);
|
||||||
print("smiley: %C\n", (Rune)0x263a);
|
print("smiley: %C\n", (Rune)0x263a);
|
||||||
print("%g %.18\n", 2e25, 2e25);
|
print("%g %.18g\n", 2e25, 2e25);
|
||||||
print("%2.18g\n", 1.0);
|
print("%2.18g\n", 1.0);
|
||||||
|
print("%2.18f\n", 1.0);
|
||||||
print("%f\n", 3.1415927/4);
|
print("%f\n", 3.1415927/4);
|
||||||
print("%d\n", 23);
|
print("%d\n", 23);
|
||||||
print("%i\n", 23);
|
print("%i\n", 23);
|
||||||
|
print("%0.10d\n", 12345);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,9 @@ vfprint(int fd, char *fmt, va_list args)
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
fmtfdinit(&f, fd, buf, sizeof(buf));
|
fmtfdinit(&f, fd, buf, sizeof(buf));
|
||||||
va_copy(f.args,args);
|
VA_COPY(f.args,args);
|
||||||
n = dofmt(&f, fmt);
|
n = dofmt(&f, fmt);
|
||||||
va_end(f.args);
|
VA_END(f.args);
|
||||||
if(n > 0 && __fmtFdFlush(&f) == 0)
|
if(n > 0 && __fmtFdFlush(&f) == 0)
|
||||||
return -1;
|
return -1;
|
||||||
return n;
|
return n;
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,9 @@ vseprint(char *buf, char *e, char *fmt, va_list args)
|
||||||
f.flush = 0;
|
f.flush = 0;
|
||||||
f.farg = nil;
|
f.farg = nil;
|
||||||
f.nfmt = 0;
|
f.nfmt = 0;
|
||||||
va_copy(f.args,args);
|
VA_COPY(f.args,args);
|
||||||
dofmt(&f, fmt);
|
dofmt(&f, fmt);
|
||||||
va_end(f.args);
|
VA_END(f.args);
|
||||||
*(char*)f.to = '\0';
|
*(char*)f.to = '\0';
|
||||||
return (char*)f.to;
|
return (char*)f.to;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,64 @@
|
||||||
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
|
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
|
||||||
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
|
* Plan 9 port version must include libc.h in order to
|
||||||
|
* get Plan 9 debugging malloc, which sometimes returns
|
||||||
|
* different pointers than the standard malloc.
|
||||||
|
*/
|
||||||
|
#ifdef PLAN9PORT
|
||||||
|
#include <u.h>
|
||||||
|
#include <libc.h>
|
||||||
|
#else
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
|
||||||
#include "plan9.h"
|
#include "plan9.h"
|
||||||
#include "fmt.h"
|
#include "fmt.h"
|
||||||
#include "fmtdef.h"
|
#include "fmtdef.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int
|
||||||
|
fmtStrFlush(Fmt *f)
|
||||||
|
{
|
||||||
|
char *s;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
if(f->start == nil)
|
||||||
|
return 0;
|
||||||
|
n = (int)f->farg;
|
||||||
|
n *= 2;
|
||||||
|
s = (char*)f->start;
|
||||||
|
f->start = realloc(s, n);
|
||||||
|
if(f->start == nil){
|
||||||
|
f->farg = nil;
|
||||||
|
f->to = nil;
|
||||||
|
f->stop = nil;
|
||||||
|
free(s);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
f->farg = (void*)n;
|
||||||
|
f->to = (char*)f->start + ((char*)f->to - s);
|
||||||
|
f->stop = (char*)f->start + n - 1;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
fmtstrinit(Fmt *f)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
|
||||||
|
memset(f, 0, sizeof *f);
|
||||||
|
f->runes = 0;
|
||||||
|
n = 32;
|
||||||
|
f->start = malloc(n);
|
||||||
|
if(f->start == nil)
|
||||||
|
return -1;
|
||||||
|
f->to = f->start;
|
||||||
|
f->stop = (char*)f->start + n - 1;
|
||||||
|
f->flush = fmtStrFlush;
|
||||||
|
f->farg = (void*)n;
|
||||||
|
f->nfmt = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* print into an allocated string buffer
|
* print into an allocated string buffer
|
||||||
|
|
@ -28,10 +81,12 @@ vsmprint(char *fmt, va_list args)
|
||||||
|
|
||||||
if(fmtstrinit(&f) < 0)
|
if(fmtstrinit(&f) < 0)
|
||||||
return nil;
|
return nil;
|
||||||
va_copy(f.args,args);
|
VA_COPY(f.args,args);
|
||||||
n = dofmt(&f, fmt);
|
n = dofmt(&f, fmt);
|
||||||
va_end(f.args);
|
VA_END(f.args);
|
||||||
if(n < 0)
|
if(n < 0){
|
||||||
|
free(f.start);
|
||||||
return nil;
|
return nil;
|
||||||
|
}
|
||||||
return fmtstrflush(&f);
|
return fmtstrflush(&f);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,9 @@ vsnprint(char *buf, int len, char *fmt, va_list args)
|
||||||
f.flush = 0;
|
f.flush = 0;
|
||||||
f.farg = nil;
|
f.farg = nil;
|
||||||
f.nfmt = 0;
|
f.nfmt = 0;
|
||||||
va_copy(f.args,args);
|
VA_COPY(f.args,args);
|
||||||
dofmt(&f, fmt);
|
dofmt(&f, fmt);
|
||||||
va_end(f.args);
|
VA_END(f.args);
|
||||||
*(char*)f.to = '\0';
|
*(char*)f.to = '\0';
|
||||||
return (char*)f.to - buf;
|
return (char*)f.to - buf;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue