chiark / gitweb /
set default gap to 0
[disorder] / lib / printf.c
index 7129df5f0716818ec938f821901d4e06114b7f00..15478ce0a71c53b4277d3310d6a09b71382c8ac8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of DisOrder
- * Copyright (C) 2004 Richard Kettlewell
+ * Copyright (C) 2004, 2007 Richard Kettlewell
  *
  * 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
@@ -33,6 +33,7 @@
 
 #include "printf.h"
 #include "sink.h"
+#include "vacopy.h"
 
 enum flags {
   f_thousands = 1,
@@ -144,6 +145,7 @@ static int check_integer(const struct conversion *c) {
   case l_intmax_t:
   case l_size_t:
   case l_longdouble:
+  case l_ptrdiff_t:
     return 0;
   default:
     return -1;
@@ -282,11 +284,11 @@ static int output_integer(struct state *s, struct conversion *c) {
    * '-' beats '0'.
    */
   if(c->flags & f_left) {
-    if(pad && do_pad(s, ' ', pad) < 0) return -1;
     if(sign && do_write(s, &sign, 1)) return -1;
     if(xform && do_write(s, c->specifier->xform, xform)) return -1;
     if(prec && do_pad(s, '0', prec) < 0) return -1;
     if(ndigits && do_write(s, digits + dp, ndigits)) return -1;
+    if(pad && do_pad(s, ' ', pad) < 0) return -1;
   } else if(c->flags & f_zero) {
     if(sign && do_write(s, &sign, 1)) return -1;
     if(xform && do_write(s, c->specifier->xform, xform)) return -1;
@@ -294,11 +296,11 @@ static int output_integer(struct state *s, struct conversion *c) {
     if(prec && do_pad(s, '0', prec) < 0) return -1;
     if(ndigits && do_write(s, digits + dp, ndigits)) return -1;
   } else {
+    if(pad && do_pad(s, ' ', pad) < 0) return -1;
     if(sign && do_write(s, &sign, 1)) return -1;
     if(xform && do_write(s, c->specifier->xform, xform)) return -1;
     if(prec && do_pad(s, '0', prec) < 0) return -1;
     if(ndigits && do_write(s, digits + dp, ndigits)) return -1;
-    if(pad && do_pad(s, ' ', pad) < 0) return -1;
   }
   return 0;
 }
@@ -321,11 +323,11 @@ static int output_string(struct state *s, struct conversion *c) {
   } else
     pad = 0;
   if(c->flags & f_left) {
-    if(pad && do_pad(s, ' ', pad) < 0) return -1;
     if(do_write(s, str, len) < 0) return -1;
+    if(pad && do_pad(s, ' ', pad) < 0) return -1;
   } else {
-    if(do_write(s, str, len) < 0) return -1;
     if(pad && do_pad(s, ' ', pad) < 0) return -1;
+    if(do_write(s, str, len) < 0) return -1;
   }
   return 0;
   
@@ -342,11 +344,11 @@ static int output_char(struct state *s, struct conversion *c) {
   } else
     pad = 0;
   if(c->flags & f_left) {
-    if(pad && do_pad(s, ' ', pad) < 0) return -1;
     if(do_write(s, &ch, 1) < 0) return -1;
+    if(pad && do_pad(s, ' ', pad) < 0) return -1;
   } else {
-    if(do_write(s, &ch, 1) < 0) return -1;
     if(pad && do_pad(s, ' ', pad) < 0) return -1;
+    if(do_write(s, &ch, 1) < 0) return -1;
   }
   return 0;
 }
@@ -413,7 +415,7 @@ static int parse_conversion(struct conversion *c, const char *ptr) {
       ++ptr;
       c->precision = -1;
     } else
-      return -1;
+      c->precision = 0;
     c->flags |= f_precision;
   }
   /* length modifier */