=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/term.c,v retrieving revision 1.32 retrieving revision 1.33 diff -c -r1.32 -r1.33 *** src/usr.bin/mandoc/term.c 2010/05/15 21:09:53 1.32 --- src/usr.bin/mandoc/term.c 2010/05/17 02:25:42 1.33 *************** *** 1,4 **** ! /* $Id: term.c,v 1.32 2010/05/15 21:09:53 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * --- 1,4 ---- ! /* $Id: term.c,v 1.33 2010/05/17 02:25:42 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * *************** *** 130,136 **** int i; /* current input position in p->buf */ size_t vis; /* current visual position on output */ size_t vbl; /* number of blanks to prepend to output */ ! size_t vend; /* end of word visual position on output */ size_t bp; /* visual right border position */ int j; /* temporary loop index */ int jhy; /* last hyphen before line overflow */ --- 130,136 ---- int i; /* current input position in p->buf */ size_t vis; /* current visual position on output */ size_t vbl; /* number of blanks to prepend to output */ ! size_t vend; /* end of word visual position on output */ size_t bp; /* visual right border position */ int j; /* temporary loop index */ int jhy; /* last hyphen before line overflow */ *************** *** 154,186 **** bp = TERMP_NOBREAK & p->flags ? mmax : maxvis; /* * FIXME: if bp is zero, we still output the first word before * breaking the line. */ ! vis = i = 0; while (i < (int)p->col) { /* - * Choose the number of blanks to prepend: no blank at the - * beginning of a line, one between words -- but do not - * actually write them yet. - */ - vbl = (size_t)(0 == vis ? 0 : 1); - vis += vbl; - vend = vis; - - /* * Handle literal tab characters. */ for (j = i; j < (int)p->col; j++) { if ('\t' != p->buf[j]) break; ! /* Collapse tab with inter-word spacing. */ ! if (vis > 0 && j == i) ! vend = vis - 1; ! vend = (vend/p->tabwidth+1)*p->tabwidth; vbl += vend - vis; vis = vend; } --- 154,179 ---- bp = TERMP_NOBREAK & p->flags ? mmax : maxvis; + /* + * Indent the first line of a paragraph. + */ + vbl = p->flags & TERMP_NOLPAD ? 0 : p->offset; + /* * FIXME: if bp is zero, we still output the first word before * breaking the line. */ ! vis = vend = i = 0; while (i < (int)p->col) { /* * Handle literal tab characters. */ for (j = i; j < (int)p->col; j++) { if ('\t' != p->buf[j]) break; ! vend = (vis/p->tabwidth+1)*p->tabwidth; vbl += vend - vis; vis = vend; } *************** *** 196,202 **** for (jhy = 0; j < (int)p->col; j++) { if ((j && ' ' == p->buf[j]) || '\t' == p->buf[j]) break; ! else if (8 == p->buf[j]) vend--; else { if (vend > vis && vend < bp && --- 189,195 ---- for (jhy = 0; j < (int)p->col; j++) { if ((j && ' ' == p->buf[j]) || '\t' == p->buf[j]) break; ! if (8 == p->buf[j]) vend--; else { if (vend > vis && vend < bp && *************** *** 207,227 **** } /* - * Usually, indent the first line of each paragraph. - */ - if (0 == i && ! (p->flags & TERMP_NOLPAD)) { - p->viscol += p->offset; - /* LINTED */ - for (j = 0; j < (int)p->offset; j++) - putchar(' '); - } - - /* * Find out whether we would exceed the right margin. ! * If so, break to the next line. (TODO: hyphenate) ! * Otherwise, write the chosen number of blanks now. */ ! if (vend > bp && 0 == jhy && vis > vbl) { vend -= vis; putchar('\n'); if (TERMP_NOBREAK & p->flags) { --- 200,209 ---- } /* * Find out whether we would exceed the right margin. ! * If so, break to the next line. */ ! if (vend > bp && 0 == jhy && vis > 0) { vend -= vis; putchar('\n'); if (TERMP_NOBREAK & p->flags) { *************** *** 230,247 **** putchar(' '); vend += p->rmargin - p->offset; } else { ! p->viscol = p->offset; ! for (j = 0; j < (int)p->offset; j++) ! putchar(' '); } /* Remove the p->overstep width. */ bp += (int)/* LINTED */ p->overstep; p->overstep = 0; - } else { - p->viscol += vbl; - for (j = 0; j < (int)vbl; j++) - putchar(' '); } /* --- 212,226 ---- putchar(' '); vend += p->rmargin - p->offset; } else { ! p->viscol = 0; ! vbl = p->offset; } + /* Remove the p->overstep width. */ + bp += (int)/* LINTED */ p->overstep; p->overstep = 0; } /* *************** *** 250,273 **** while (i < (int)p->col && '\t' == p->buf[i]) i++; ! /* ! * Finally, write out the word. ! */ for ( ; i < (int)p->col; i++) { if (vend > bp && jhy > 0 && i > jhy) break; if ('\t' == p->buf[i]) break; if (' ' == p->buf[i]) { ! i++; break; } ! if (ASCII_NBRSP == p->buf[i]) ! putchar(' '); ! else ! putchar(p->buf[i]); } ! p->viscol += vend - vis; vis = vend; } --- 229,267 ---- while (i < (int)p->col && '\t' == p->buf[i]) i++; ! /* Write out the [remaining] word. */ for ( ; i < (int)p->col; i++) { if (vend > bp && jhy > 0 && i > jhy) break; if ('\t' == p->buf[i]) break; if (' ' == p->buf[i]) { ! while (' ' == p->buf[i]) { ! vbl++; ! i++; ! } break; } ! if (ASCII_NBRSP == p->buf[i]) { ! vbl++; ! continue; ! } ! ! /* ! * Now we definitely know there will be ! * printable characters to output, ! * so write preceding white space now. ! */ ! if (vbl) { ! for (j = 0; j < (int)vbl; j++) ! putchar(' '); ! p->viscol += vbl; ! vbl = 0; ! } ! putchar(p->buf[i]); ! p->viscol += 1; } ! vend += vbl; vis = vend; }