chiark
/
gitweb
/
~mdw
/
disorder
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
disobedience/disobedience.h: Declare variables as `extern'.
[disorder]
/
lib
/
printf.c
diff --git
a/lib/printf.c
b/lib/printf.c
index f921791ed32961b6c12959a1e070e1a30d44fd0e..9f1b57a39ff6036e2c312d0a7febca9e3bb5eae7 100644
(file)
--- a/
lib/printf.c
+++ b/
lib/printf.c
@@
-29,9
+29,14
@@
#include <stddef.h>
#include "printf.h"
#include <stddef.h>
#include "printf.h"
+#include "log.h"
#include "sink.h"
#include "vacopy.h"
#include "sink.h"
#include "vacopy.h"
+/** @brief Flags from a converstion specification
+ *
+ * Order significant!
+ */
enum flags {
f_thousands = 1,
f_left = 2,
enum flags {
f_thousands = 1,
f_left = 2,
@@
-43,6
+48,7
@@
enum flags {
f_precision = 512
};
f_precision = 512
};
+/** @brief Possible lengths of a conversion specification */
enum lengths {
l_char = 1,
l_short,
enum lengths {
l_char = 1,
l_short,
@@
-56,29
+62,65
@@
enum lengths {
struct conversion;
struct conversion;
+/** @brief Formatter state */
struct state {
struct state {
+ /** @brief Output stream */
struct sink *output;
struct sink *output;
+
+ /** @brief Number of bytes written */
int bytes;
int bytes;
+
+ /** @brief Argument list */
va_list ap;
};
va_list ap;
};
+/** @brief Definition of a conversion specifier */
struct specifier {
struct specifier {
+ /** @brief Defining character ('d', 's' etc) */
int ch;
int ch;
+
+ /** @brief Consistency check
+ * @param c Conversion being processed
+ * @return 0 if OK, -1 on error
+ */
int (*check)(const struct conversion *c);
int (*check)(const struct conversion *c);
+
+ /** @brief Generate output
+ * @param s Formatter state
+ * @param c Conversion being processed
+ * @return 0 on success, -1 on error
+ */
int (*output)(struct state *s, struct conversion *c);
int (*output)(struct state *s, struct conversion *c);
+
+ /** @brief Number base */
int base;
int base;
+
+ /** @brief Digit set */
const char *digits;
const char *digits;
+
+ /** @brief Alternative-form prefix */
const char *xform;
};
const char *xform;
};
+/** @brief One conversion specified as it's handled */
struct conversion {
struct conversion {
+ /** @brief Flags in this conversion */
unsigned flags;
unsigned flags;
+
+ /** @brief Field width (if @ref f_width) */
int width;
int width;
+
+ /** @brief Precision (if @ref f_precision) */
int precision;
int precision;
+
+ /** @brief Length modifier or 0 */
int length;
int length;
+
+ /** @brief Specifier used */
const struct specifier *specifier;
};
const struct specifier *specifier;
};
+/** @brief Flag characters (order significant!) */
static const char flags[] = "'-+ #0";
/* write @nbytes@ to the output. Return -1 on error, 0 on success.
static const char flags[] = "'-+ #0";
/* write @nbytes@ to the output. Return -1 on error, 0 on success.