=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/dc/inout.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- src/usr.bin/dc/inout.c 2005/03/28 19:19:36 1.11 +++ src/usr.bin/dc/inout.c 2005/03/29 10:53:54 1.12 @@ -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 @@ -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 @@ -29,9 +29,9 @@ #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 *); static char *src_getlinestream(struct source *); @@ -40,6 +40,7 @@ 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 @@ } 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 @@ struct stack stack; char *p; + charcount = 0; + lastchar = -1; if (BN_is_zero(b->number)) putcharwrap(f, '0'); @@ -305,7 +319,6 @@ i++; } sz = i; - charCount = 0; if (BN_cmp(b->number, &zero) < 0) putcharwrap(f, '-'); for (i = 0; i < sz; i++) { @@ -353,6 +366,7 @@ BN_free(&mult); BN_free(&stop); } + flushwrap(f); free_number(int_part); free_number(fract_part); }