X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fascii.c;h=b9222b83a29b5b294c98bda64eac519e1bb6e789;hb=7b98b3a4f58f6dc5a8e9cbc188b627966d5e652d;hp=10345005275a412eaab903f72c64a137d1353cd9;hpb=3a7fba81ceae5b049d0f7d671e9e3c3c43bbf703;p=pspp diff --git a/src/ascii.c b/src/ascii.c index 1034500527..b9222b83a2 100644 --- a/src/ascii.c +++ b/src/ascii.c @@ -49,6 +49,7 @@ width=130 lpi=6 Only used to determine font size. cpi=10 + squeeze=off|on Squeeze multiple newlines into exactly one. left-margin=0 right-margin=0 @@ -161,6 +162,7 @@ struct ascii_driver_ext struct len_string fonts[FSTY_COUNT]; /* Font styles; NULL=overstrike. */ int overstrike_style; /* OVS_SINGLE or OVS_LINE. */ int carriage_return_style; /* Carriage return style. */ + int squeeze_blank_lines; /* 1=squeeze multiple blank lines into one. */ /* Internal state. */ struct file_ext file; /* Output file. */ @@ -183,21 +185,21 @@ static int postopen (struct file_ext *); static int preclose (struct file_ext *); static int -ascii_open_global (struct outp_class *this unused) +ascii_open_global (struct outp_class *this UNUSED) { ascii_pool = pool_create (); return 1; } static int -ascii_close_global (struct outp_class *this unused) +ascii_close_global (struct outp_class *this UNUSED) { pool_destroy (ascii_pool); return 1; } static int * -ascii_font_sizes (struct outp_class *this unused, int *n_valid_sizes) +ascii_font_sizes (struct outp_class *this UNUSED, int *n_valid_sizes) { static int valid_sizes[] = {12, 12, 0, 0}; @@ -235,6 +237,7 @@ ascii_preopen_driver (struct outp_driver *this) ls_null (&x->fonts[i]); x->overstrike_style = OVS_SINGLE; x->carriage_return_style = CRS_BS; + x->squeeze_blank_lines = 0; x->file.filename = NULL; x->file.mode = "wb"; x->file.file = NULL; @@ -438,6 +441,7 @@ static struct outp_option option_tab[] = {"overstrike-style", 3, 0}, {"tab-width", nonneg_int_arg, 4}, {"carriage-return-style", 4, 0}, + {"squeeze", boolean_arg, 2}, {"", 0, 0}, }; static struct outp_option_info option_info; @@ -622,11 +626,14 @@ ascii_option (struct outp_driver *this, const char *key, switch (subcat) { case 0: - x->headers = 0; + x->headers = setting; break; case 1: x->paginate = setting; break; + case 2: + x->squeeze_blank_lines = setting; + break; default: assert (0); } @@ -728,7 +735,7 @@ expand_line (struct ascii_driver_ext *x, int i, int l) static void ascii_line_horz (struct outp_driver *this, const struct rect *r, - const struct color *c unused, int style) + const struct color *c UNUSED, int style) { struct ascii_driver_ext *ext = this->ext; int x1 = r->x1 / this->horiz; @@ -762,7 +769,7 @@ ascii_line_horz (struct outp_driver *this, const struct rect *r, static void ascii_line_vert (struct outp_driver *this, const struct rect *r, - const struct color *c unused, int style) + const struct color *c UNUSED, int style) { struct ascii_driver_ext *ext = this->ext; int x1 = r->x1 / this->horiz; @@ -797,7 +804,7 @@ ascii_line_vert (struct outp_driver *this, const struct rect *r, static void ascii_line_intersection (struct outp_driver *this, const struct rect *r, - const struct color *c unused, + const struct color *c UNUSED, const struct outp_styles *style) { struct ascii_driver_ext *ext = this->ext; @@ -828,25 +835,25 @@ ascii_line_intersection (struct outp_driver *this, const struct rect *r, /* FIXME: Later we could set this up so that for certain devices it performs shading? */ static void -ascii_box (struct outp_driver *this unused, const struct rect *r unused, - const struct color *bord unused, const struct color *fill unused) +ascii_box (struct outp_driver *this UNUSED, const struct rect *r UNUSED, + const struct color *bord UNUSED, const struct color *fill UNUSED) { assert (this->driver_open && this->page_open); } /* Polylines not supported. */ static void -ascii_polyline_begin (struct outp_driver *this unused, const struct color *c unused) +ascii_polyline_begin (struct outp_driver *this UNUSED, const struct color *c UNUSED) { assert (this->driver_open && this->page_open); } static void -ascii_polyline_point (struct outp_driver *this unused, int x unused, int y unused) +ascii_polyline_point (struct outp_driver *this UNUSED, int x UNUSED, int y UNUSED) { assert (this->driver_open && this->page_open); } static void -ascii_polyline_end (struct outp_driver *this unused) +ascii_polyline_end (struct outp_driver *this UNUSED) { assert (this->driver_open && this->page_open); } @@ -881,7 +888,7 @@ ascii_text_set_font_by_position (struct outp_driver *this, int pos) } static void -ascii_text_set_font_by_family (struct outp_driver *this unused, const char *s unused) +ascii_text_set_font_by_family (struct outp_driver *this UNUSED, const char *s UNUSED) { assert (this->driver_open && this->page_open); } @@ -909,7 +916,7 @@ ascii_text_get_font_name (struct outp_driver *this) } static const char * -ascii_text_get_font_family (struct outp_driver *this unused) +ascii_text_get_font_family (struct outp_driver *this UNUSED) { assert (this->driver_open && this->page_open); return ""; @@ -1332,9 +1339,8 @@ static void output_lines (struct outp_driver *this, int first, int count) { struct ascii_driver_ext *ext = this->ext; + int line_num; - unsigned short *p = &ext->page[ext->w * first]; - int *len = &ext->line_len[first]; struct len_string *newline = &ext->ops[OPS_NEWLINE]; int n_chars; @@ -1343,15 +1349,24 @@ output_lines (struct outp_driver *this, int first, int count) if (NULL == ext->file.file) return; - while (count--) /* Iterate over all the lines to be output. */ + /* Iterate over all the lines to be output. */ + for (line_num = first; line_num < first + count; line_num++) { - unsigned short *end_p; + unsigned short *p = &ext->page[ext->w * line_num]; + unsigned short *end_p = p + ext->line_len[line_num]; unsigned short *bp, *ep; unsigned short attr = 0; - end_p = p + *len++; assert (end_p >= p); + /* Squeeze multiple blank lines into a single blank line if + requested. */ + if (ext->squeeze_blank_lines + && line_num > first + && ext->line_len[line_num] == 0 + && ext->line_len[line_num - 1] == 0) + continue; + /* Output every character in the line in the appropriate manner. */ n_passes = 1; @@ -1469,7 +1484,6 @@ output_lines (struct outp_driver *this, int first, int count) ep = bp; } } - p += ext->w; output_string (this, ls_value (newline), ls_end (newline)); }