diff options
Diffstat (limited to 'usr.bin/dc/inout.c')
-rw-r--r-- | usr.bin/dc/inout.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/usr.bin/dc/inout.c b/usr.bin/dc/inout.c index c0206535207..2574065b4c5 100644 --- a/usr.bin/dc/inout.c +++ b/usr.bin/dc/inout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: inout.c,v 1.11 2005/03/28 19:19:36 otto Exp $ */ +/* $OpenBSD: inout.c,v 1.12 2005/03/29 10:53:54 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net> @@ -17,7 +17,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: inout.c,v 1.11 2005/03/28 19:19:36 otto Exp $"; +static const char rcsid[] = "$OpenBSD: inout.c,v 1.12 2005/03/29 10:53:54 otto Exp $"; #endif /* not lint */ #include <ssl/ssl.h> @@ -29,8 +29,8 @@ static const char rcsid[] = "$OpenBSD: inout.c,v 1.11 2005/03/28 19:19:36 otto E #define MAX_CHARS_PER_LINE 68 -static int charCount; - +static int lastchar; +static int charcount; static int src_getcharstream(struct source *); static int src_ungetcharstream(struct source *); @@ -40,6 +40,7 @@ static int src_getcharstring(struct source *); static int src_ungetcharstring(struct source *); static char *src_getlinestring(struct source *); static void src_freestring(struct source *); +static void flushwrap(FILE *); static void putcharwrap(FILE *, int); static void printwrap(FILE *, const char *); static char *get_digit(u_long, int, u_int); @@ -152,13 +153,24 @@ src_freestring(struct source *src) } static void +flushwrap(FILE *f) +{ + if (lastchar != -1) + putc(lastchar, f); +} + +static void putcharwrap(FILE *f, int ch) { - putc(ch, f); - if (++charCount >= MAX_CHARS_PER_LINE) { - charCount = 0; + if (charcount >= MAX_CHARS_PER_LINE) { + charcount = 0; fputs("\\\n", f); } + if (lastchar != -1) { + charcount++; + putc(lastchar, f); + } + lastchar = ch; } static void @@ -283,6 +295,8 @@ printnumber(FILE *f, const struct number *b, u_int base) struct stack stack; char *p; + charcount = 0; + lastchar = -1; if (BN_is_zero(b->number)) putcharwrap(f, '0'); @@ -305,7 +319,6 @@ printnumber(FILE *f, const struct number *b, u_int base) i++; } sz = i; - charCount = 0; if (BN_cmp(b->number, &zero) < 0) putcharwrap(f, '-'); for (i = 0; i < sz; i++) { @@ -353,6 +366,7 @@ printnumber(FILE *f, const struct number *b, u_int base) BN_free(&mult); BN_free(&stop); } + flushwrap(f); free_number(int_part); free_number(fract_part); } |