fmt.c (e026a48c34d396fe7d0e382673a69bc047c0bfca) fmt.c (7bd73b069cd7960c9352342e6728c094f740b63f)
1/* $OpenBSD: fmt.c,v 1.16 2000/06/25 15:35:42 pjanzen Exp $ */
2
3/* Sensible version of fmt
4 *
5 * Syntax: fmt [ options ] [ goal [ max ] ] [ filename ... ]
6 *
7 * Since the documentation for the original fmt is so poor, here
8 * is an accurate description of what this one does. It's usually

--- 348 unchanged lines hidden (view full) ---

357
358}
359
360/* Process a single file, given its name.
361 */
362static void
363process_named_file(const char *name) {
364 FILE *f=fopen(name, "r");
1/* $OpenBSD: fmt.c,v 1.16 2000/06/25 15:35:42 pjanzen Exp $ */
2
3/* Sensible version of fmt
4 *
5 * Syntax: fmt [ options ] [ goal [ max ] ] [ filename ... ]
6 *
7 * Since the documentation for the original fmt is so poor, here
8 * is an accurate description of what this one does. It's usually

--- 348 unchanged lines hidden (view full) ---

357
358}
359
360/* Process a single file, given its name.
361 */
362static void
363process_named_file(const char *name) {
364 FILE *f=fopen(name, "r");
365 if (!f) { perror(name); ++n_errors; }
365 if (!f) { warn("%s", name); ++n_errors; }
366 else {
367 process_stream(f, name);
368 fclose(f);
369 }
370}
371
372/* Types of mail header continuation lines:
373 */

--- 80 unchanged lines hidden (view full) ---

454 output_word(first_indent, last_indent,
455 line+n, word_length, space_length-word_length);
456 n += space_length;
457 }
458 }
459 ++para_line_number;
460 }
461 new_paragraph(output_in_paragraph ? last_indent : first_indent, 0);
366 else {
367 process_stream(f, name);
368 fclose(f);
369 }
370}
371
372/* Types of mail header continuation lines:
373 */

--- 80 unchanged lines hidden (view full) ---

454 output_word(first_indent, last_indent,
455 line+n, word_length, space_length-word_length);
456 n += space_length;
457 }
458 }
459 ++para_line_number;
460 }
461 new_paragraph(output_in_paragraph ? last_indent : first_indent, 0);
462 if (ferror(stream)) { perror(name); ++n_errors; }
462 if (ferror(stream)) { warn("%s", name); ++n_errors; }
463}
464
465/* How long is the indent on this line?
466 */
467static size_t
468indent_length(const char *line, size_t length) {
469 size_t n=0;
470 while (n<length && *line++ == ' ') ++n;

--- 110 unchanged lines hidden (view full) ---

581 while ((line=get_line(stream, &length)) != 0) {
582 size_t l=length;
583 while (l>0 && isspace(*line)) { ++line; --l; }
584 length=l;
585 while (l<goal_length) { putchar(' '); l+=2; }
586 fwrite(line, 1, length, stdout);
587 putchar('\n');
588 }
463}
464
465/* How long is the indent on this line?
466 */
467static size_t
468indent_length(const char *line, size_t length) {
469 size_t n=0;
470 while (n<length && *line++ == ' ') ++n;

--- 110 unchanged lines hidden (view full) ---

581 while ((line=get_line(stream, &length)) != 0) {
582 size_t l=length;
583 while (l>0 && isspace(*line)) { ++line; --l; }
584 length=l;
585 while (l<goal_length) { putchar(' '); l+=2; }
586 fwrite(line, 1, length, stdout);
587 putchar('\n');
588 }
589 if (ferror(stream)) { perror(name); ++n_errors; }
589 if (ferror(stream)) { warn("%s", name); ++n_errors; }
590}
591
592/* Get a single line from a stream. Expand tabs, strip control
593 * characters and trailing whitespace, and handle backspaces.
594 * Return the address of the buffer containing the line, and
595 * put the length of the line in |lengthp|.
596 * This can cope with arbitrarily long lines, and with lines
597 * without terminating \n.

--- 41 unchanged lines hidden ---
590}
591
592/* Get a single line from a stream. Expand tabs, strip control
593 * characters and trailing whitespace, and handle backspaces.
594 * Return the address of the buffer containing the line, and
595 * put the length of the line in |lengthp|.
596 * This can cope with arbitrarily long lines, and with lines
597 * without terminating \n.

--- 41 unchanged lines hidden ---