X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/681cb9fb117ab20661273bf45bd5eaa75eddbf8a..refs/heads/master:/lib/printf.c
diff --git a/lib/printf.c b/lib/printf.c
index c5b9ebd..9f1b57a 100644
--- a/lib/printf.c
+++ b/lib/printf.c
@@ -2,39 +2,41 @@
* This file is part of DisOrder
* Copyright (C) 2004, 2007, 2008 Richard Kettlewell
*
- * This program is free software; you can redistribute it and/or modify
+ * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * along with this program. If not, see .
+ */
+/** @file lib/printf.c
+ * @brief UTF-8 *printf workalike (core)
*/
#define NO_MEMORY_ALLOCATION
/* because byte_snprintf used from log.c */
-#include
-#include "types.h"
+#include "common.h"
-#include
#include
-#include
#include
-#include
#include
#include "printf.h"
+#include "log.h"
#include "sink.h"
#include "vacopy.h"
+/** @brief Flags from a converstion specification
+ *
+ * Order significant!
+ */
enum flags {
f_thousands = 1,
f_left = 2,
@@ -46,6 +48,7 @@ enum flags {
f_precision = 512
};
+/** @brief Possible lengths of a conversion specification */
enum lengths {
l_char = 1,
l_short,
@@ -59,29 +62,65 @@ enum lengths {
struct conversion;
+/** @brief Formatter state */
struct state {
+ /** @brief Output stream */
struct sink *output;
+
+ /** @brief Number of bytes written */
int bytes;
+
+ /** @brief Argument list */
va_list ap;
};
+/** @brief Definition of a conversion specifier */
struct specifier {
+ /** @brief Defining character ('d', 's' etc) */
int ch;
+
+ /** @brief Consistency check
+ * @param c Conversion being processed
+ * @return 0 if OK, -1 on error
+ */
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);
+
+ /** @brief Number base */
int base;
+
+ /** @brief Digit set */
const char *digits;
+
+ /** @brief Alternative-form prefix */
const char *xform;
};
+/** @brief One conversion specified as it's handled */
struct conversion {
+ /** @brief Flags in this conversion */
unsigned flags;
+
+ /** @brief Field width (if @ref f_width) */
int width;
+
+ /** @brief Precision (if @ref f_precision) */
int precision;
+
+ /** @brief Length modifier or 0 */
int length;
+
+ /** @brief Specifier used */
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.