home *** CD-ROM | disk | FTP | other *** search
- From: smidt@fy.chalmers.se (Peter Smidt)
- Newsgroups: alt.sources
- Subject: mfold - Maaniker's fold and column making
- Message-ID: <1990Sep9.164538.6621@fy.chalmers.se>
- Date: 9 Sep 90 16:45:38 GMT
-
- Submitted-by: smidt@cd.chalmers.se
- Archive-name: mfold.shar/part01 (one part)
-
- ---- Cut Here and unpack ----
- #!/bin/sh
- # This is mfold.shar, a shell archive (shar 3.21)
- # made 09/09/1990 14:40 UTC by smidt@sponsz
- # Source directory /nfs/alcazar/u/smidt/src/mfold/exp
- #
- # existing files will NOT be overwritten
- #
- # This shar contains:
- # length mode name
- # ------ ---------- ------------------------------------------
- # 351 -rw-r--r-- README
- # 94 -rw-r--r-- makefile
- # 3621 -rw-r--r-- mfold.1
- # 13825 -rw-r--r-- mfold.c
- #
- if touch 2>&1 | fgrep '[-amc]' > /dev/null
- then TOUCH=touch
- else TOUCH=true
- fi
- # ============= README ==============
- if test X"$1" != X"-c" -a -f 'README'; then
- echo "File already exists: skipping 'README'"
- else
- echo "x - extracting README (Text)"
- sed 's/^Y//' << 'XXX' > README &&
- YThe program mfold is a simpel folding and column making program.
- Yunpack the files from the shar file put them in a empty
- Ydirectory, type 'make' and you'll get the executable. A manual
- Yis included in the shar file.
- Y
- YBug reports, ideas, or patches could be sent to;
- YPeter Smidt smidt@cd.chalmers.se or
- YPeter Smidt smidt@fy.chalmers.se
- Y
- Y/Maaniker
- XXX
- $TOUCH -am 0909162990 README &&
- chmod 0644 README ||
- echo "restore of README failed"
- set `wc -c README`;Wc_c=$1
- if test "$Wc_c" != "351"; then
- echo original size 351, current size $Wc_c
- fi
- fi
- # ============= makefile ==============
- if test X"$1" != X"-c" -a -f 'makefile'; then
- echo "File already exists: skipping 'makefile'"
- else
- echo "x - extracting makefile (Text)"
- sed 's/^Y//' << 'XXX' > makefile &&
- Ynyfold: nyfold.o
- Y cc nyfold.o -o mfold
- Y rm -f nyfold.o
- Y
- Ynyfold.o: nyfold.c
- Y cc -c nyfold.c -g
- XXX
- $TOUCH -am 0909162690 makefile &&
- chmod 0644 makefile ||
- echo "restore of makefile failed"
- set `wc -c makefile`;Wc_c=$1
- if test "$Wc_c" != "94"; then
- echo original size 94, current size $Wc_c
- fi
- fi
- # ============= mfold.1 ==============
- if test X"$1" != X"-c" -a -f 'mfold.1'; then
- echo "File already exists: skipping 'mfold.1'"
- else
- echo "x - extracting mfold.1 (Text)"
- sed 's/^Y//' << 'XXX' > mfold.1 &&
- Y.\" Shareware 1990 of Chalmers Computer Society.
- Y.\"
- Y.\" @(#)mfold.1 (G|teborg) 1990-09-07
- Y.\"
- Y.TH MFOLD 1 "September 7, 1990"
- Y.UC
- Y.SH NAME
- Ymfold \- Maaniker's fold and column making
- Y.SH SYNOPSIS
- Y.B mfold
- Y[
- Y.B \-sn -ln -en -wn -f -d
- Y.B -rn
- Y.B -tn -cn -pn -n -L -Bn
- Y.B -D '<text>' -i '<text>'
- Y]
- Y.SH DESCRIPTION
- Y.I Mfold
- Yreads text files from standard input and writes to standard
- Youtput.
- Y.I Mfold
- Yconcatenates and folds the text in one or more columns
- Ywithout breaking in the middle of a word. Tabs and newlines are
- Yconverted to blank space. Multiple blank space is substituted with
- Yone single blank space. Some flags don't do anything if they aren't
- Yused together with either '-c' or '-d'.
- Y.PP
- YThere is a limited amount of options:
- Y.TP
- Y.B \-sn
- YStart line for
- Y.I mfold,
- Ywhere n is the line number. The preceding text
- Yis passed through
- Y.I mfold
- Ywithout being changed. If an end-of-file character is encountered
- Ybefore line n,
- Y.I mfold
- Ywill end the execution.
- Y.TP
- Y.B \-i
- YInsert text at the beginning of every line, or with '\-c', at every
- Ycolumn. This option as the last flag doesn't need any argument if
- Ya null argument is wanted. A space is required between the flag
- Yand the argument. Tabs may be present in the insert text. Default
- Yinsert text is a tab.
- Y.TP
- Y.B \-ln
- YLenght for output lines, excluding any insert text and excluding
- Yany delimiter text. Where n is the number of characters. Default
- Ylength is 76.
- Y.TP
- Y.B \-en
- Y.I Mfold
- Ywill end the folding at input line n. Text coming after this
- Yline is not being changed by
- Y.I mfold.
- Y.TP
- Y.B \-wn
- YSpecify the width n, of the not folded lines to avoid overrunning the
- Yinternal reverse buffer when using the '-d' flag. '-w' is not always
- Yprovided. Run
- Y.I mfold,
- Ylook at the result and decide if you want to specify the full
- Ywidth. Default is 80 characters.
- Y.TP
- Y.B \-f
- YFill each line with blank space to its full line length.
- Y.TP
- Y.B \-rn
- YFills the lines with extra blank space up to an amount of
- Yn blank spaces, to get an even right margin. The words will get
- Ya little random placement on the lines.
- Y.TP
- Y.B \-d
- YReverse the text for dyslexics.
- Y.TP
- Y.B \-tn
- YExpanding the tabs to spaces. Where n is the number of
- Yspaces. Default is four spaces. Use only with '-d'.
- Y.TP
- Y.B \-cn
- YSpecifies columns where n is the number of columns. Text is inserted at
- Yevery column.
- Y.TP
- Y.B \-pn
- YSpecifies page length n, meaningfull when used with the '-c'
- Yflag. Default are 40 lines per page.
- Y.TP
- Y.B \-n
- YMany newlines in a row is not substituted with one single
- Yblank space, which is otherwise the default. Instead they are
- Yleft without change, but may be put in a separate column.
- Y.TP
- Y.B \-L
- YWrite a ^L (newpage) at the end of each page. Use with '-c'.
- Y.TP
- Y.B \-Bn
- YWrite n newlines at the bottom (end) of the page. Default is
- Yone newline. Use when the number of columns are greater then one.
- Y.TP
- Y.B \-D
- YSpecify column delimiter. Default is three blank spaces. Tabs may be
- Ypresent in the delimiter. This option as the last flag doesn't need
- Yany argument if a null argument is wanted.
- Y.SH ERRORS
- YYou will notice them, when you give bad flags.
- Y.SH AUTHOR
- YPeter Smidt, Chalmers Computer Society.
- Y.SH SEE ALSO
- Yawk(1), sed(1), lex(1), nroff(1), fmt(1), fold(1), rev(1)
- Y.SH BUGS
- YIf underlining is present it will get messed up with the
- Ytext. The '-c' and the '-d' flags
- Y.I may
- Yproduce some extra
- Yunnecessary blank space at the end of the lines. When
- Ya word is longer than the line length, the word may be
- Ycut at an inappropriate place. Everything except blank space,
- Ynewline and tab counts as parts of words.
- Y.SH BUG REPORTS TO
- YPeter Smidt smidt@cd.chalmers.se or
- Y.br
- YPeter Smidt smidt@fy.chalmers.se
- XXX
- $TOUCH -am 0909162690 mfold.1 &&
- chmod 0644 mfold.1 ||
- echo "restore of mfold.1 failed"
- set `wc -c mfold.1`;Wc_c=$1
- if test "$Wc_c" != "3621"; then
- echo original size 3621, current size $Wc_c
- fi
- fi
- # ============= mfold.c ==============
- if test X"$1" != X"-c" -a -f 'mfold.c'; then
- echo "File already exists: skipping 'mfold.c'"
- else
- echo "x - extracting mfold.c (Text)"
- sed 's/^Y//' << 'XXX' > mfold.c &&
- Y#include <stdio.h>
- Y#include <curses.h>
- Y#include <strings.h>
- Y
- Y#define DEF_LINE_LEN 76
- Y#define DEF_WORD_LEN 40
- Y#define DEF_TAB_LEN 4
- Y#define FULL_WIDTH 80
- Y#define PAGE_LEN 40
- Y#define POS1 1
- Y#define DO_ALL1 \
- Y col_pos = POS1;\
- Y for ( doo = 0; doo < ins_len; doo++ ) {\
- Y putcolu(insert[doo]);\
- Y }
- Y#define BOT_LINES 1
- Y#define STR 15
- Y#define TEST_STR 25
- Y#define GET_NUM_STR 25
- Y
- Yint colu_chars, colu_lines;
- Yint page_len = PAGE_LEN, columns = 1, lin = 0, bot_lines = BOT_LINES;
- Yint got_newpage = FALSE, got_dyslexi = FALSE, full_line = FULL_WIDTH;
- Yint tab_len = DEF_TAB_LEN, ins_tabs = 0, del_len, got_fill = FALSE;
- Yint got_mrandom = FALSE, got_bot = FALSE, ins_len, mrandom = 1;
- Ychar **cur_page, *malloc(), *delim = " ", **glob_argv;
- Y
- Ymain(argc, argv)
- Ychar *argv[];
- Yint argc;
- Y{
- Y int col_pos = 1, j = 0, k, in, doo, line_len = DEF_LINE_LEN, row_count = 1;
- Y int cnt_nwl = 0, new_wo_le, dummy = TRUE, end = 2;
- Y int width = FULL_WIDTH, err = FALSE, in_2 = 0, in_3 = 0, tmp_chars = 0;
- Y char *cur_word, *insert = "\t", *s = "Bad option ' '";
- Y int index, start = 1, word_len = DEF_WORD_LEN;
- Y int got_start = FALSE, got_line_len = FALSE, got_insert = FALSE;
- Y int got_tab_len = FALSE, got_end = FALSE, got_width = FALSE;
- Y int got_columns = FALSE, got_page_len = FALSE;
- Y int got_newlines = FALSE, got_delim = FALSE;
- Y int index_start = 0, index_insert = 0, index_line_len = 0;
- Y int index_tab_len = 0, index_end = 0, index_width = 0;
- Y int index_columns = 0, index_page_len = 0, index_delim = 0;
- Y int index_bot = 0, index_mrandom = 0;
- Y glob_argv = argv;
- Y for ( index = 1; index < argc; index++) {
- Y if ( argv[index][0] != '-' ) {
- Y if ( index != 1 ) {
- Y if ( argv[index - 1][0] == '-' ) {
- Y if ( argv[index - 1][1] == 'i' ) {
- Y index_insert = index;
- Y } else if ( argv[index - 1][1] == 'D' ) {
- Y index_delim = index;
- Y } else {
- Y err = TRUE;
- Y }
- Y } else {
- Y err = TRUE;
- Y }
- Y } else {
- Y err = TRUE;
- Y }
- Y if ( err ) {
- Y fprintf(stderr, "Flag '%s' not allowed.\n", argv[index]);
- Y usage(11);
- Y }
- Y }
- Y doo = index_insert != index && index_delim != index;
- Y switch ( argv[index][1] ) {
- Y case 'i':
- Y check_it(&got_insert, "-i", 8, doo, &index_insert, index + 1);
- Y break;
- Y case 's':
- Y check_it(&got_start, "-s", 9, doo, &index_start, index);
- Y break;
- Y case 'l':
- Y check_it(&got_line_len, "-l", 10, doo, &index_line_len, index);
- Y break;
- Y case 'e':
- Y check_it(&got_end, "-e", 10, doo, &index_end, index);
- Y break;
- Y case 'w':
- Y check_it(&got_width, "-w", 10, doo, &index_width, index);
- Y break;
- Y case 'r':
- Y check_it(&got_mrandom, "-r", 37, doo, &index_mrandom, index);
- Y break;
- Y case 'd':
- Y check_it(&got_dyslexi, "-d", 11, doo, &dummy, index);
- Y break;
- Y case 't':
- Y check_it(&got_tab_len, "-t", 13, doo, &index_tab_len, index);
- Y break;
- Y case 'c':
- Y check_it(&got_columns, "-c", 15, doo, &index_columns, index);
- Y break;
- Y case 'p':
- Y check_it(&got_page_len, "-p", 16, doo, &index_page_len, index);
- Y break;
- Y case 'B':
- Y check_it(&got_bot, "-B", 17, doo, &index_bot, index);
- Y break;
- Y case 'f':
- Y check_it(&got_fill, "-f", 33, doo, &dummy, index);
- Y break;
- Y case 'n':
- Y check_it(&got_newlines, "-n", 18, doo, &dummy, index);
- Y break;
- Y case 'L':
- Y check_it(&got_newpage, "-L", 19, doo, &dummy, index);
- Y break;
- Y case 'D':
- Y check_it(&got_delim, "-D", 36, doo, &index_delim, index + 1);
- Y break;
- Y case '\0':
- Y write_err(doo, "Empty flag '-'", 31);
- Y break;
- Y default:
- Y s[12] = argv[index][0];
- Y s[13] = argv[index][1];
- Y write_err(doo, s, 20);
- Y break;
- Y }
- Y }
- Y ext_num(got_start, &start, argv[index_start],
- Y "Line zero, for start, not allowed", 21);
- Y ext_num(got_page_len, &page_len, argv[index_page_len],
- Y "Page length zero, not allowed", 24);
- Y ext_num(got_tab_len, &tab_len, argv[index_tab_len],
- Y "Tab length zero, not allowed", 27);
- Y ext_num(got_line_len, &line_len, argv[index_line_len],
- Y "Line length zero, not allowed", 25);
- Y write_err(line_len < 2, "Too short line length, not allowed", 32);
- Y ext_num(got_end, &end, argv[index_end],
- Y "End length zero, not allowed", 25);
- Y write_err(got_end && end <= start,
- Y "End not greater than start line, not allowed", 33);
- Y ext_num(got_width, &width, argv[index_width],
- Y "Line length zero, not allowed", 25);
- Y ext_num(got_mrandom, &mrandom, argv[index_mrandom],
- Y "Zero fill length, not allowed", 36);
- Y if ( got_bot ) get_num(&bot_lines, argv[index_bot]);
- Y if ( got_insert ) {
- Y if ( index_insert < argc ) {
- Y insert = argv[index_insert];
- Y } else {
- Y insert = "";
- Y }
- Y }
- Y if ( got_delim ) {
- Y if ( index_insert < argc ) {
- Y delim = argv[index_delim];
- Y } else {
- Y delim = "";
- Y }
- Y }
- Y del_len = strlen(delim);
- Y if ( got_columns ) {
- Y get_num(&columns, argv[index_columns]);
- Y write_err(columns == 0, "columns count zero, not allowed", 26);
- Y write_err(line_len % columns,
- Y "Lines not an even multiple of columns length", 27);
- Y }
- Y/* colu_chars is the chars on one column. colu_lines is the total number of
- Ylines in all the columns in one page. page_len is the number of lines in one
- Ypage. */
- Y ins_len = strlen(insert);
- Y colu_chars = line_len / columns + ins_len;
- Y colu_lines = page_len * columns;
- Y write_err( !(cur_page = (char**) malloc(colu_lines * sizeof(char*))),
- Y "Can not malloc that page length", 39);
- Y for ( in = 0; in < colu_lines; in++ ) {
- Y if ( !(cur_page[in] = malloc(colu_chars * sizeof(char))) ) {
- Y write_err(TRUE, "Can not malloc that page length", 40);
- Y }
- Y }
- Y for ( doo = 0; doo < ins_len; doo++ ) {
- Y if ( insert[doo] == '\t' ) {
- Y ins_tabs++;
- Y }
- Y }
- Y full_line = line_len + ins_len * columns + del_len * ( columns - 1);
- Y full_line += ( tab_len - 1 ) * columns * ins_tabs;
- Y line_len = line_len / columns;
- Y word_len = line_len;
- Y write_err( !(cur_word = malloc(word_len * sizeof(char))),
- Y "Can not malloc that word (line?) length", 41);
- Y if ( width > full_line ) initrev(width);
- Y else initrev(full_line);
- Y while ( row_count < start ) {
- Y in = getchar();
- Y if ( in == EOF ) exit(0);
- Y if ( in == '\n' ) {
- Y if ( got_dyslexi ) {
- Y flushrev();
- Y }
- Y putchar('\n');
- Y row_count++;
- Y } else if ( got_dyslexi ) {
- Y putrev(in);
- Y } else {
- Y putchar(in);
- Y }
- Y }
- Y if ( !got_end ) end = row_count + 1;
- Y lin = ( ( start - 1 ) % page_len ) * columns;
- Y new_wo_le = word_len - 1;
- Y/* ******************** The fold follows ******************** */
- Y while ( 1 ) {
- Y DO_ALL1
- Y while ( 1 ) {
- Y if ( row_count > end ) {
- Y in = EOF;
- Y } else if ( j == new_wo_le && tmp_chars == 0 ) {
- Y in_2 = getchar();
- Y if ( in_2 == ' ' || in_2 == '\n' || in_2 == '\t' ) {
- Y in = in_2;
- Y } else {
- Y in_3 = getchar();
- Y if ( in_3 == ' ' || in_3 == '\n' || in_3 == '\t' ) {
- Y in = in_2;
- Y tmp_chars = 1;
- Y } else {
- Y in = '-';
- Y tmp_chars = 2;
- Y }
- Y }
- Y } else if ( j == word_len ) {
- Y in = ' ';
- Y } else if ( tmp_chars > 0 ) {
- Y if ( tmp_chars == 1 && j == 0 ) {
- Y in = in_3;
- Y tmp_chars = 0;
- Y } else if ( tmp_chars == 1 && j == 1 ) {
- Y in_2 = in_3;
- Y tmp_chars = 0;
- Y if ( line_len != 2 || in_2 == ' ' || in_2 == '\n'
- Y || in_2 == '\t' ) {
- Y in = in_2;
- Y } else {
- Y in_3 = getchar();
- Y if ( in_3 == ' ' || in_3 == '\n' || in_3 == '\t' ) {
- Y in = in_2;
- Y tmp_chars = 1;
- Y } else {
- Y in = '-';
- Y tmp_chars = 2;
- Y }
- Y }
- Y } else {
- Y in = in_2;
- Y tmp_chars = 1;
- Y }
- Y } else {
- Y in = getchar();
- Y }
- Y if ( cnt_nwl > 1 && got_newlines && in != '\n' ) {
- Y putcolu('\n');
- Y while ( --cnt_nwl ) {
- Y putcolu(' ');
- Y putcolu('\n');
- Y }
- Y DO_ALL1
- Y }
- Y if ( in != '\n' ) cnt_nwl = 0;
- Y if ( in == '\n' || in == '\t' ) {
- Y if ( in == '\n' ) {
- Y if ( got_end ) row_count++;
- Y if ( got_newlines ) cnt_nwl++;
- Y }
- Y in = ' ';
- Y }
- Y if ( in == EOF ) {
- Y putcolu('\n');
- Y flushpage(columns);
- Y if ( !got_end ) exit(0);
- Y else break;
- Y }
- Y if ( in != ' ' ) {
- Y write_err( j >= word_len || j < 0 ,
- Y "Internal error or to long text word", 3);
- Y cur_word[j++] = in;
- Y } else {
- Y if ( col_pos != POS1 && (col_pos + j) <= line_len &&
- Y j != 0 ) {
- Y putcolu(' ');
- Y col_pos++;
- Y } else if ( (col_pos + j) > line_len && col_pos != POS1 ) {
- Y putcolu('\n');
- Y DO_ALL1
- Y }
- Y for ( k = 0; k < j; k++ ) {
- Y putcolu(cur_word[k]);
- Y }
- Y col_pos += j;
- Y j = 0;
- Y }
- Y if ( col_pos == line_len ) break;
- Y }
- Y if ( in == EOF ) break;
- Y putcolu('\n');
- Y }
- Y if ( cnt_nwl > 1 && got_newlines ) {
- Y while ( cnt_nwl-- ) putcolu('\n');
- Y }
- Y while ( 1 ) {
- Y in = getchar();
- Y if ( in == EOF ) exit(0);
- Y if ( in == '\n' ) {
- Y if ( got_dyslexi ) {
- Y flushrev();
- Y }
- Y putchar('\n');
- Y } else if ( got_dyslexi ) {
- Y putrev(in);
- Y } else {
- Y putchar(in);
- Y }
- Y }
- Y}
- Y
- Ychar *buff;
- Yint gl_i = 0, len;
- Y/* lin is the line index in the one long column before it is pasted out onto the
- Ypage. len is the lenght of each line in the one long column. */
- Y
- Yputrev(c)
- Y{
- Y int i;
- Y
- Y if ( gl_i >= 0 && gl_i < len ) {
- Y if ( c != '\t' ) {
- Y buff[gl_i++] = c;
- Y } else {
- Y int k = tab_len - gl_i % tab_len;
- Y for ( i = 0; i < k; i++ ) {
- Y putrev(' ');
- Y }
- Y }
- Y } else {
- Y write_err(TRUE,
- Y "Internal error in reverse buffer. Specify bigger buffer", 4);
- Y }
- Y}
- Y
- Yflushrev() {
- Y int i;
- Y
- Y for ( i = len - 1; i > 0; i--) {
- Y if ( buff[i] != '\0' ) {
- Y putchar(buff[i]);
- Y buff[i] = '\0';
- Y } else {
- Y putchar(' ');
- Y }
- Y }
- Y if ( buff[0] != ' ' ) {
- Y putchar(buff[0]);
- Y }
- Y gl_i = 0;
- Y}
- Y
- Yinitrev(l)
- Yint l;
- Y{
- Y int i;
- Y
- Y len = l;
- Y write_err( !(buff = malloc(len * sizeof(char))),
- Y "Can not malloc that internal reverse buffer length", 42);
- Y for ( i = 0; i < len; i++ ) {
- Y buff[i] = '\0';
- Y }
- Y}
- Y
- Ycheck_it(got_flag, s, err, boole, index_flag, index)
- Yint *got_flag, *index_flag;
- Ychar *s;
- Y{
- Y test(*got_flag, s, err);
- Y test_two(boole, index_flag, index, got_flag);
- Y}
- Y
- Ytest(flag, s1, err)
- Ychar *s1;
- Y{
- Y char *s2 = "Multiple ' ' not allowed";
- Y
- Y s2[10] = s1[0];
- Y s2[11] = s1[1];
- Y write_err(flag, s2, err);
- Y}
- Y
- Ytest_two(boole, index_flag, index, got_flag)
- Yint *index_flag, *got_flag;
- Y{
- Y if ( boole ) {
- Y if ( *index_flag && glob_argv[index][2] != '\0' ) {
- Y fprintf(stderr, "Flag '%c%c' doesn't want any argument.\n",
- Y glob_argv[index][0], glob_argv[index][1]);
- Y usage(35);
- Y }
- Y *index_flag = index;
- Y *got_flag = TRUE;
- Y }
- Y}
- Y
- Ywrite_err(flag, s, err)
- Ychar *s;
- Y{
- Y if ( flag ) {
- Y fprintf(stderr, "%s.\n", s);
- Y usage(err);
- Y }
- Y}
- Y
- Yext_num(bulle, tal, arg, s, err)
- Yint *tal;
- Ychar *arg, *s;
- Y{
- Y if ( bulle ) {
- Y get_num(tal, arg);
- Y write_err(*tal == 0, s, err);
- Y }
- Y}
- Y
- Yget_num(number, argv)
- Yint *number;
- Ychar argv[];
- Y{
- Y int k, in, tmp;
- Y char *s = "Not a number in flag ' '";
- Y
- Y s[22] = argv[0];
- Y s[23] = argv[1];
- Y *number = 0;
- Y k = strlen(argv);
- Y write_err(k == 1, s, 9);
- Y for( in = 2; in < k; in++) {
- Y tmp = argv[in] - '0';
- Y write_err(tmp < 0 || tmp > 9, "Bad flag, N-A-P-N", 5);
- Y *number = tmp + *number * 10;
- Y }
- Y}
- Y
- Yusage(t) {
- Y fprintf(stderr, "[ %d ] Usage: mfold [ -sn -ln -en -wn -f -d -rn -tn -cn -pn -n -L -Bn\n-D '<text>' -i '<text>' ]\n", t);
- Y exit(t);
- Y}
- Y
- Yint col = 0;
- Y
- Yputcolu(c)
- Ychar c;
- Y{
- Y if ( c == '\n' || col == colu_chars ) {
- Y advance_line();
- Y return;
- Y }
- Y cur_page[lin][col++] = c;
- Y}
- Y
- Yadvance_line() {
- Y col = 0;
- Y if ( ++lin == colu_lines ) {
- Y flushpage(columns);
- Y end_page();
- Y }
- Y}
- Y
- Yend_page() {
- Y int i;
- Y
- Y if ( columns > 1 || got_bot ) {
- Y for ( i = 0; i < bot_lines; i++ ) {
- Y putchar('\n');
- Y }
- Y }
- Y if ( got_newpage ) putchar(12); /* 12 == ^L (ascii) */
- Y}
- Y
- Yflushpage(columns) {
- Y int line_sta = 0, cs, tmpl, lin_diff, lin_end;
- Y int end_col = columns - 1, lin_sto = colu_lines, end_char = colu_chars - 1;
- Y
- Y for ( lin = 0; lin < colu_lines; lin++ ) {
- Y if ( cur_page[lin][0] != '\0' ) {
- Y line_sta = lin;
- Y break;
- Y }
- Y }
- Y for ( lin = line_sta; lin < colu_lines; lin += columns ) {
- Y if ( cur_page[lin][0] == '\0' ) {
- Y lin_sto = lin;
- Y break;
- Y }
- Y }
- Y lin_diff = (lin_sto - line_sta) / columns;
- Y lin_end = line_sta + lin_diff;
- Y for ( lin = line_sta; lin < lin_end; lin++) {
- Y if ( cur_page[lin][0] == ' ' && cur_page[lin][1] == '\0'
- Y && columns == 1 ) {
- Y putchar('\n');
- Y } else {
- Y for ( cs = 0; cs < columns; cs++ ) {
- Y tmpl = lin + lin_diff * cs;
- Y if ( cur_page[tmpl][end_char] == '\0' && got_mrandom ) {
- Y fill_sp(tmpl, end_char);
- Y }
- Y for ( col = 0; col < colu_chars; col++ ) {
- Y if ( cur_page[tmpl][col] == '\0' ) {
- Y if ( cs == end_col && !got_fill ) break;
- Y if ( got_dyslexi ) putrev(' ');
- Y else putchar(' ');
- Y } else {
- Y if ( got_dyslexi ) putrev(cur_page[tmpl][col]);
- Y else putchar(cur_page[tmpl][col]);
- Y cur_page[tmpl][col] = '\0';
- Y }
- Y }
- Y if ( cs < end_col ) {
- Y for ( col = 0; col < del_len; col++ ) {
- Y if ( got_dyslexi ) putrev(delim[col]);
- Y else putchar(delim[col]);
- Y }
- Y }
- Y }
- Y }
- Y if ( got_dyslexi ) flushrev();
- Y putchar('\n');
- Y }
- Y lin = col = 0;
- Y}
- Y
- Yfill_sp(line, end_char) {
- Y int pass = 0, last, nulls = end_char, words = 0, i, found_sp = FALSE;
- Y int found_word = FALSE, moves, new_end, old_end;
- Y
- Y while ( cur_page[line][--nulls] == '\0' && nulls != 1 );
- Y nulls = end_char - nulls;
- Y last = end_char - nulls;
- Y for ( i = ins_len; i <= last; i++) {
- Y if ( cur_page[line][i] != ' ' ) {
- Y if ( !found_word ) {
- Y words++;
- Y found_word = TRUE;
- Y }
- Y } else {
- Y found_word = FALSE;
- Y }
- Y }
- Y if ( words < 2 ) return;
- Y old_end = last;
- Y while ( ++pass < mrandom ) {
- Y if ( words > nulls ) moves = nulls;
- Y else moves = words - 1;
- Y i = moves;
- Y new_end = moves + old_end;
- Y last = new_end;
- Y while( 1 ) {
- Y cur_page[line][new_end--] = cur_page[line][old_end--];
- Y if ( old_end < 0 ) break;
- Y if ( cur_page[line][old_end] == ' ' ) {
- Y if ( !found_sp ) {
- Y if ( moves-- > 0 ) cur_page[line][new_end--] = ' ' ;
- Y }
- Y found_sp = TRUE;
- Y } else {
- Y found_sp = FALSE;
- Y }
- Y }
- Y if ( cur_page[line][end_char] != '\0' ) return;
- Y nulls = nulls - i;
- Y old_end = last;
- Y }
- Y}
- XXX
- $TOUCH -am 0909162690 mfold.c &&
- chmod 0644 mfold.c ||
- echo "restore of mfold.c failed"
- set `wc -c mfold.c`;Wc_c=$1
- if test "$Wc_c" != "13825"; then
- echo original size 13825, current size $Wc_c
- fi
- fi
- exit 0
- --
- +=======================================+
- "The whole valley is like a smorgasbord."
- -- TREMORS
-