# HG changeset patch # User Matti Hamalainen # Date 1456384674 -7200 # Node ID 2bf43a13954217f5e3a934cac3e56e0f7f6e1a0a # Parent 75b20d9bef6450dd25ee553b5b7db4123227bdbd Modularize some of the padding code better. diff -r 75b20d9bef64 -r 2bf43a139542 th_string.c --- a/th_string.c Thu Feb 25 09:17:23 2016 +0200 +++ b/th_string.c Thu Feb 25 09:17:54 2016 +0200 @@ -136,20 +136,20 @@ static int th_printf_pad_pre(th_printf_ctx *ctx, th_printf_vputch vputch, - int f_width, const int f_flags) + int f_width, const int f_flags, const char ch) { if (f_width > 0 && (f_flags & TH_PF_LEFT) == 0) - return th_printf_vput_repch(ctx, vputch, f_width, (f_flags & TH_PF_ZERO) ? '0' : ' '); + return th_printf_vput_repch(ctx, vputch, f_width, ch); else return 0; } static int th_printf_pad_post(th_printf_ctx *ctx, th_printf_vputch vputch, - int f_width, const int f_flags) + int f_width, const int f_flags, const char ch) { if (f_width > 0 && (f_flags & TH_PF_LEFT)) - return th_printf_vput_repch(ctx, vputch, f_width, ' '); + return th_printf_vput_repch(ctx, vputch, f_width, ch); else return 0; } @@ -211,7 +211,7 @@ if (f_sign && (f_flags & TH_PF_ZERO) && (ret = vputch(ctx, f_sign)) == EOF) return ret; - if ((ret = th_printf_pad_pre(ctx, vputch, nwidth, f_flags)) == EOF) + if ((ret = th_printf_pad_pre(ctx, vputch, nwidth, f_flags, (f_flags & TH_PF_ZERO) ? '0' : ' ')) == EOF) return ret; if (f_altstr && (ret = th_printf_vput_pstr(ctx, vputch, f_altstr)) == EOF) @@ -236,7 +236,7 @@ } // Postfix padding? - return th_printf_pad_post(ctx, vputch, nwidth, f_flags); + return th_printf_pad_post(ctx, vputch, nwidth, f_flags, ' '); } @@ -258,7 +258,7 @@ nwidth = f_width - f_len; // Prefix padding? - if ((ret = th_printf_pad_pre(ctx, vputch, nwidth, f_flags)) == EOF) + if ((ret = th_printf_pad_pre(ctx, vputch, nwidth, f_flags, ' ')) == EOF) return ret; while (*str && f_len--) @@ -268,7 +268,7 @@ } // Postfix padding? - if ((ret = th_printf_pad_post(ctx, vputch, nwidth, f_flags)) == EOF) + if ((ret = th_printf_pad_post(ctx, vputch, nwidth, f_flags, ' ')) == EOF) return ret; return ret; @@ -387,11 +387,11 @@ return -104; case 'c': - if ((ret = th_printf_pad_pre(ctx, vputch, f_width - 1, f_flags)) == EOF) + if ((ret = th_printf_pad_pre(ctx, vputch, f_width - 1, f_flags, ' ')) == EOF) goto out; if ((ret = vputch(ctx, va_arg(ap, int))) == EOF) goto out; - if ((ret = th_printf_pad_post(ctx, vputch, f_width - 1, f_flags)) == EOF) + if ((ret = th_printf_pad_post(ctx, vputch, f_width - 1, f_flags, ' ')) == EOF) goto out; break;