fmt.h - vx32 - Local 9vx git repository for patches.
 (HTM) git clone git://r-36.net/vx32
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       fmt.h (4045B)
       ---
            1 /*
            2  * The authors of this software are Rob Pike and Ken Thompson,
            3  * with contributions from Mike Burrows and Sean Dorward.
            4  *
            5  *     Copyright (c) 2002-2006 by Lucent Technologies.
            6  *     Portions Copyright (c) 2004 Google Inc.
            7  * 
            8  * Permission to use, copy, modify, and distribute this software for any
            9  * purpose without fee is hereby granted, provided that this entire notice
           10  * is included in all copies of any software which is or includes a copy
           11  * or modification of this software and in all copies of the supporting
           12  * documentation for such software.
           13  * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
           14  * WARRANTY.  IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 
           15  * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 
           16  * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
           17  */
           18 #ifndef _FMT_H_
           19 #define _FMT_H_ 1
           20 #if defined(__cplusplus)
           21 extern "C" { 
           22 #endif
           23 
           24 #include <stdarg.h>
           25 #include "utf.h"
           26 
           27 typedef struct Fmt        Fmt;
           28 struct Fmt{
           29         unsigned char        runes;                /* output buffer is runes or chars? */
           30         void        *start;                        /* of buffer */
           31         void        *to;                        /* current place in the buffer */
           32         void        *stop;                        /* end of the buffer; overwritten if flush fails */
           33         int        (*flush)(Fmt *);        /* called when to == stop */
           34         void        *farg;                        /* to make flush a closure */
           35         int        nfmt;                        /* num chars formatted so far */
           36         va_list        args;                        /* args passed to dofmt */
           37         int        r;                        /* % format Rune */
           38         int        width;
           39         int        prec;
           40         unsigned long        flags;
           41         char        *decimal;        /* decimal point; cannot be "" */
           42 
           43         /* For %'d */
           44         char *thousands;        /* separator for thousands */
           45         
           46         /* 
           47          * Each char is an integer indicating #digits before next separator. Values:
           48          *        \xFF: no more grouping (or \x7F; defined to be CHAR_MAX in POSIX)
           49          *        \x00: repeat previous indefinitely
           50          *        \x**: count that many
           51          */
           52         char        *grouping;                /* descriptor of separator placement */
           53 };
           54 
           55 enum{
           56         FmtWidth        = 1,
           57         FmtLeft                = FmtWidth << 1,
           58         FmtPrec                = FmtLeft << 1,
           59         FmtSharp        = FmtPrec << 1,
           60         FmtSpace        = FmtSharp << 1,
           61         FmtSign                = FmtSpace << 1,
           62         FmtApost                = FmtSign << 1,
           63         FmtZero                = FmtApost << 1,
           64         FmtUnsigned        = FmtZero << 1,
           65         FmtShort        = FmtUnsigned << 1,
           66         FmtLong                = FmtShort << 1,
           67         FmtVLong        = FmtLong << 1,
           68         FmtComma        = FmtVLong << 1,
           69         FmtByte                = FmtComma << 1,
           70         FmtLDouble        = FmtByte << 1,
           71 
           72         FmtFlag                = FmtLDouble << 1
           73 };
           74 
           75 extern        int        (*fmtdoquote)(int);
           76 
           77 /* Edit .+1,/^$/ | cfn $PLAN9/src/lib9/fmt/?*.c | grep -v static |grep -v __ */
           78 int                dofmt(Fmt *f, char *fmt);
           79 int                dorfmt(Fmt *f, const Rune *fmt);
           80 double                fmtcharstod(int(*f)(void*), void *vp);
           81 int                fmtfdflush(Fmt *f);
           82 int                fmtfdinit(Fmt *f, int fd, char *buf, int size);
           83 int                fmtinstall(int c, int (*f)(Fmt*));
           84 int                fmtnullinit(Fmt*);
           85 void                fmtlocaleinit(Fmt*, char*, char*, char*);
           86 int                fmtprint(Fmt *f, char *fmt, ...);
           87 int                fmtrune(Fmt *f, int r);
           88 int                fmtrunestrcpy(Fmt *f, Rune *s);
           89 int                fmtstrcpy(Fmt *f, char *s);
           90 char*                fmtstrflush(Fmt *f);
           91 int                fmtstrinit(Fmt *f);
           92 double                fmtstrtod(const char *as, char **aas);
           93 int                fmtvprint(Fmt *f, char *fmt, va_list args);
           94 int                fprint(int fd, char *fmt, ...);
           95 int                print(char *fmt, ...);
           96 void                quotefmtinstall(void);
           97 int                quoterunestrfmt(Fmt *f);
           98 int                quotestrfmt(Fmt *f);
           99 Rune*                runefmtstrflush(Fmt *f);
          100 int                runefmtstrinit(Fmt *f);
          101 Rune*                runeseprint(Rune *buf, Rune *e, char *fmt, ...);
          102 Rune*                runesmprint(char *fmt, ...);
          103 int                runesnprint(Rune *buf, int len, char *fmt, ...);
          104 int                runesprint(Rune *buf, char *fmt, ...);
          105 Rune*                runevseprint(Rune *buf, Rune *e, char *fmt, va_list args);
          106 Rune*                runevsmprint(char *fmt, va_list args);
          107 int                runevsnprint(Rune *buf, int len, char *fmt, va_list args);
          108 char*                seprint(char *buf, char *e, char *fmt, ...);
          109 char*                smprint(char *fmt, ...);
          110 int                snprint(char *buf, int len, char *fmt, ...);
          111 int                sprint(char *buf, char *fmt, ...);
          112 int                vfprint(int fd, char *fmt, va_list args);
          113 char*                vseprint(char *buf, char *e, char *fmt, va_list args);
          114 char*                vsmprint(char *fmt, va_list args);
          115 int                vsnprint(char *buf, int len, char *fmt, va_list args);
          116 
          117 #if defined(__cplusplus)
          118 }
          119 #endif
          120 #endif