Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/col/col.c
Show First 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | |||||
static void dowarn(int); | static void dowarn(int); | ||||
static void flush_line(LINE *); | static void flush_line(LINE *); | ||||
static void flush_lines(int); | static void flush_lines(int); | ||||
static void flush_blanks(void); | static void flush_blanks(void); | ||||
static void free_line(LINE *); | static void free_line(LINE *); | ||||
static void usage(void); | static void usage(void); | ||||
static CSET last_set; /* char_set of last char printed */ | static CSET last_set; /* char_set of last char printed */ | ||||
static LINE *lines; | static LINE *lines; | ||||
markj: Please fix the whitespace in the `alloc_line()` declaration as well. | |||||
static int compress_spaces; /* if doing space -> tab conversion */ | static int compress_spaces; /* if doing space -> tab conversion */ | ||||
static int fine; /* if `fine' resolution (half lines) */ | static int fine; /* if `fine' resolution (half lines) */ | ||||
static int max_bufd_lines; /* max # of half lines to keep in memory */ | static int max_bufd_lines; /* max # of half lines to keep in memory */ | ||||
static int nblank_lines; /* # blanks after last flushed line */ | static int nblank_lines; /* # blanks after last flushed line */ | ||||
static int no_backspaces; /* if not to output any backspaces */ | static int no_backspaces; /* if not to output any backspaces */ | ||||
static int pass_unknown_seqs; /* pass unknown control sequences */ | static int pass_unknown_seqs; /* pass unknown control sequences */ | ||||
#define PUTC(ch) \ | #define PUTC(ch) \ | ||||
▲ Show 20 Lines • Show All 214 Lines • ▼ Show 20 Lines | if (cur_col < l->l_max_col) | ||||
l->l_needs_sort = 1; | l->l_needs_sort = 1; | ||||
else | else | ||||
l->l_max_col = cur_col; | l->l_max_col = cur_col; | ||||
if (c->c_width > 0) | if (c->c_width > 0) | ||||
cur_col += c->c_width; | cur_col += c->c_width; | ||||
} | } | ||||
if (ferror(stdin)) | if (ferror(stdin)) | ||||
err(1, NULL); | err(1, NULL); | ||||
if (extra_lines) | if (extra_lines) { | ||||
/* | |||||
* Extra lines only exist if no lines have been flushed | |||||
* yet. This means that 'lines' must point to line zero | |||||
* after we flush the extra lines. | |||||
*/ | |||||
flush_lines(extra_lines); | flush_lines(extra_lines); | ||||
l = lines; | |||||
this_line = 0; | |||||
} | |||||
/* goto the last line that had a character on it */ | /* goto the last line that had a character on it */ | ||||
for (; l->l_next; l = l->l_next) | for (; l->l_next; l = l->l_next) | ||||
this_line++; | this_line++; | ||||
flush_lines(this_line - nflushd_lines + 1); | flush_lines(this_line - nflushd_lines + 1); | ||||
/* make sure we leave things in a sane state */ | /* make sure we leave things in a sane state */ | ||||
if (last_set != CS_NORMAL) | if (last_set != CS_NORMAL) | ||||
PUTC(SI); | PUTC(SI); | ||||
/* flush out the last few blank lines */ | /* flush out the last few blank lines */ | ||||
if (max_line > this_line) | if (max_line >= this_line) | ||||
nblank_lines = max_line - this_line; | nblank_lines = max_line - this_line + (max_line & 1); | ||||
if (max_line & 1) | if (nblank_lines == 0) | ||||
nblank_lines++; | /* end with a newline even if the source doesn't */ | ||||
nblank_lines = 2; | |||||
flush_blanks(); | flush_blanks(); | ||||
exit(0); | exit(0); | ||||
} | } | ||||
Done Inline ActionsThere should be a blank line here. markj: There should be a blank line here. | |||||
/* | |||||
* Prints the first 'nflush' lines. Printed lines are freed. | |||||
* After this function returns, 'lines' points to the first | |||||
* of the remaining lines, and 'nblank_lines' will have the | |||||
* number of half line feeds between the final flushed line | |||||
* and the first remaining line. | |||||
*/ | |||||
static void | static void | ||||
flush_lines(int nflush) | flush_lines(int nflush) | ||||
{ | { | ||||
LINE *l; | LINE *l; | ||||
while (--nflush >= 0) { | while (--nflush >= 0) { | ||||
l = lines; | l = lines; | ||||
lines = l->l_next; | lines = l->l_next; | ||||
if (l->l_line) { | if (l->l_line) { | ||||
flush_blanks(); | flush_blanks(); | ||||
flush_line(l); | flush_line(l); | ||||
free(l->l_line); | |||||
Done Inline ActionsYou can drop the cast of free()'s return value - it has none. markj: You can drop the cast of free()'s return value - it has none. | |||||
} | } | ||||
if (l->l_line || l->l_next) | if (l->l_next) | ||||
nblank_lines++; | nblank_lines++; | ||||
if (l->l_line) | |||||
(void)free(l->l_line); | |||||
free_line(l); | free_line(l); | ||||
} | } | ||||
if (lines) | if (lines) | ||||
lines->l_prev = NULL; | lines->l_prev = NULL; | ||||
} | } | ||||
/* | /* | ||||
* Print a number of newline/half newlines. If fine flag is set, nblank_lines | * Print a number of newline/half newlines. | ||||
* is the number of half line feeds, otherwise it is the number of whole line | * nblank_lines is the number of half line feeds. | ||||
* feeds. | |||||
*/ | */ | ||||
static void | static void | ||||
flush_blanks(void) | flush_blanks(void) | ||||
{ | { | ||||
int half, i, nb; | int half, i, nb; | ||||
half = 0; | half = 0; | ||||
nb = nblank_lines; | nb = nblank_lines; | ||||
▲ Show 20 Lines • Show All 196 Lines • Show Last 20 Lines |
Please fix the whitespace in the alloc_line() declaration as well.