Contents


    Name

  1. br

    Author

  2. R J Botting. 1988-1991

    Synopses

  3. br width --- break lines and word wrap input

    DFD User View/Context

    the context_DFD(inputs=>(in, user), outputs=>(out), process=>br)

    The user can supply a width w or a default value is assumed for the width of a line. The program reads text input and attempts to reformat it so that no line is longer than 'w' characters by breaking lines at the first block of whitespace after the last word that fits on the line. The break is done by removing all the whitespace characters after the last word that fits on the output line and replacing them by CR. Assume that there are no BS chars in the file. If w>250 or <10 then the program should do nothing and report an abnormal termination("error"). Default width is 79. If a single word is too long to fit on a line by itself then it will have to be broken up - Hyphenate words whose length is>w-1.

    Data dictionary

    Input lines (ilines) must be broken up if they are too long. So each iline is split into a group of zero or more shorter output lines followed by part of a line that does not need breaking. The short lines end in the last word that can fit on that line. After the broken lines there is a last part of the iline which is less than 'w' in length, This is ok when each word is smaller than the output line width. Longer words are broken into hyphenated parts.

  4. in::=#iline,
  5. iline::=#( #(word | wsb ) last_word wsb |pt_long_wd ) ok_line,
  6. line::=#(word | wsb ) last_word break |pt_long_wd
  7. hyphen eoln,
  8. out::=#( # line ok_line),

  9. ok_line::= #non_eoln eoln,
  10. user::=w.
  11. w::10..250.

    The length of words, wsb and last word in each 'line' add up to less than w and HT (tab) equals HTWIDTH characters in width.

  12. wsb::= #ws,
  13. ws::= HT|SP|non_print,
  14. Note. Length of HT=HTWIDTH, length of non_print=0.
  15. word::= #non_ws,
  16. last_word::= #last_non_ws,
  17. pt_long_word::= #pt_wd_char. Note. w-1 non_ws chars.
  18. break::= eoln, Alternative: break::=SP eoln, is used by Wordstar to signal a "soft_CR".
  19. break::=eoln HT, would look good. See brt.c hack

  20. hyphen::= "-".

    Correspondences/Program Structure

  21. C_user_C_in_P_out::structure= CU_w; #C_iline,
  22. C_iline::structure= #P_line; CP_ok_line,
  23. P_line::structure= #( CP_word | CP_wsb ); CP_last_word; C_wsb_P_break
  24. | CP_pt_long_wd;P_hyphen;P_eoln,
  25. CP_ok_line::structure= #CP_non_eoln; CP_eoln,
  26. CP_wsb::structure= #(CP_HT|CP_non_HT_ws|CP_non_print),
  27. CP_last_word::structure= #CP_last_non_ws,
  28. CP_word::structure= #CP_non_ws,
  29. C_wsb_P_break::structure= #C_ws,
  30. CP_pt_long_word::structure= #CP_pt_wd_char, Note. w-1 non_ws chars.

    Operations List

    Operations{ !ch, !eoln, ?ch, n:+1, n:+HTWIDTH, n'=0, w?:user, !hyphen
    }

Program Design

  • C_user_C_in_P_out::design= w?:user; ?ch; #C_iline,
  • C_iline::design= #P_line; CP_ok_line,
  • P_line::design= n'=0; #( CP_word | CP_wsb ); CP_last_word; C_wsb_P_break | CP_pt_long_wd;P_hyphen;P_eoln,

  • CP_ok_line::design= #CP_non_eoln; CP_eoln,
  • CP_wsb::design= #(CP_HT|CP_non_HT_ws|CP_non_print),
  • CP_last_word::design= #CP_last_non_ws,
  • CP_word::design= #CP_non_ws,
  • C_wsb_P_break::design= #C_ws; !eoln,
  • CP_non_eoln::design= !ch; ?ch,
  • CP_eoln::design= !eoln; ?ch,
  • CP_HT::design= n:+HTWIDTH; !ch;?ch,
  • CP_non_HT_ws::design= n:+1; !ch; ?ch,
  • CP_non_print::design= !ch; ?ch,
  • CP_non_ws::design= n:+1; !ch; ?ch,
  • CP_last_non_ws::design= !ch; ?ch,
  • C_ws::design= ?ch,
  • CP_pt_long_wd::design= #CP_pt_wd_char,
  • P_hyphen::design= !hyphen
  • P_eoln::design= !eoln,
  • CP_pt_wd_char::design= !ch; ?ch,

    .Diagram Temporal map of Program

         C_user_C_in_P_out
         ________________________________________________________________________
        |    w?:user; ?ch                                                        |
        |________________________________________________________________________|
       /|    C_iline                                                             |\
      | |    ________________________________________________________________    | |
      | |  /| P_line                                                         |\  | |
      | | | |   ___________________________________________________________  | | | |
      | | | |  | n'=0                                     |  CP_pt_long_wd | | | | |
      | | | |  |------------------------------------------|    ----------  | | | | |
      | | | |  |    ______________________    |           |  /| CP_pt_wd|\ | | | | |
      | | | |  |  /|CP_word               |\  |  CP_wsb   | | |  -------| || | | | |
      | | | |  | | |   ________________   | | |           | | | |!ch;?ch| || | | | |
      | | | |  | | | /| CP_non_ws      |\ | | |           | | |  -------| || | | | |
      | | | |  | | || | -------------- | || | |           |  \|_________|/ | | | | |
      | | | |  | | || ||n:+1;!ch; ?ch || || | |           |   | !"-"    |  | | | | |
      | | | |  | | | \| -------------- |/ | | |           |   |---------|  | | | | |
      | | | |  | | |   ----------------   | | |           |   | !eoln   |  | | | | |
      | | | |  |  \|______________________|/  |           |   |_________|  | | | | |
      | | | |  |-----------------------------------------------------------| | | | |
      | | | |  |     CP_last_word                                          | | | | |
      | | | |  |    -----------------                                      | | | | |
      | | | |  |  /|  CP_last_non_ws |\                                    | | | | |
      | | | |  | | |    ---------    | |                                   | | | | |
      | | | |  | | |   |!ch; ?ch |   | |                                   | | | | |
      | | | |  |  \|    ---------    |/                                    | | | | |
      | | | |  |    -----------------                                      | | | | |
      | | | |  |-----------------------------------------------------------| | | | |
      | | | |  |   C_wsb_P_break                                           | | | | |
      | | | |  |    -----------                                            | | | | |
      | | | |  |  /|    C_ws   |\                                          | | | | |
      | | | |  | | |   ------  | |                                         | | | | |
      | | | |  | | |  | ?ch  | | |                                         | | | | |
      | | | |  | | |   ------  | |                                         | | | | |
      | | | |  |  \|-----------|/                                          | | | | |
      | | | |  |   |  !eoln    |                                           | | | | |
      | | | |  |    -----------                                            | | | | |
      | | | |  |___________________________________________________________| | | | |
      | |  \|________________________________________________________________|/  | |
      | |   |      CP_ok_line                                                |   | |
      | |   |   ----------------                                             |   | |
      | |   | /| CP_non_eoln    |\                                           |   | |
      | |   || |    _________   | |                                          |   | |
      | |   || |   |!ch; ?ch |  | |                                          |   | |
      | |   | \|   |_________|  |/                                           |   | |
      | |   |  |----------------|                                            |   | |
      | |   |  | CP_eoln        |                                            |   | |
      | |   |  |    ----------  |                                            |   | |
      | |   |  |   |!eoln; ?ch| |                                            |   | |
      | |   |  |    ----------  |                                            |   | |
      | |   |  |________________|                                            |   | |
      | |   |________________________________________________________________|   | |
       \|________________________________________________________________________|/
    
    
              CP_wsb
        -------------------------------
     (|CP_HT|CP_non_HT_ws|CP_non_print |)
        -------------------------------

  • CP_HT::design= n:+HTWIDTH; !ch;?ch
  • CP_non_HT_ws::design= n:+1; !ch; ?ch
  • CP_non_print::design= !ch; ?ch

    .DChart Schematic Logic wd and ws are buffers

     C_user_C_in_P_out
       \
        | w?:user; ?ch
        | #C_iline
        |  \
        |   | not end(in)
        |   | #P_line(posit iline will be broken after word)
        |   | \2_______________________________________1
        |   |  |admit word not hyphenated              |posit word hyphenated
        |   |  | push ch & wd back out; n'=0           |CP_pt_long_wd
        |   |  | #                                     |  \
        |   |  | \                                     |   |wd!new; n'=0
        |   |  |  |                                    |   |#CP_pt_wd
        |   |  |  |posit room for next word or wsb     |   | \
        |   |  |  |                                    |   |  |n<w;Quit if ch in ws
        |   |  |  |                                    |   | \|wd!ch;n:+1;?ch
        |   |  |  |                                    |   |wd!end;!wd
        |   |  |  |\ _____________________             |   | !'_';!eoln
        |   |  |  | |ch in wdchs          | else       |
        |   |  |  | |CP_word              | CP_wsb    (3)
        |   |  |  | | \                   |  \
        |   |  |  | |  | wd!new           |   |ws!new
        |   |  |  | |  |                  |   |#
        |   |  |  | |  | #CP_non_ws       |   | \
        |   |  |  | |  |  \               |   |  |Quit will be broken if ch=eoln
        |   |  |  | |  |   |              |   |  |
        |   |  |  | |  |   |              |   |  |\ _________________
        |   |  |  | |  |   |ch not ws     |   |  | |      |          |
        |   |  |  | |  |   |Quit if       |   |  | |ch=HT |ch=SP     |ch not SP
        |   |  |  | |  |   |    n=w       |   |  | |      |          |ch not HT
        |   |  |  | |  |   |n:+1;wd!ch    |   | \| |CP_HT |CP_non_HT |CP_non_print
        |   |  |  | |  |  \|?ch           |   |Quit next fits if n>w-1
        |   |  |  | |  |                  |   |ws!end; !ws
        |   |  |  | |wd!end; !wd          |
        |   |  | \|
        |   |  |
        |   |  |admit next did not fit               (3)
        |   |  | CP_last_word                         |
        |   |  |  \                                   |
        |   |  |   side-effects                       |
        |   |  |                                      |
        |   |  |push ch & wd back out (in!b)          |
        |   |  |                                      |
        |   |  | C_wsb_P_break                        |
        |   |  |  \                                   |
        |   |  |   | #C_ws                            |
        |   |  |   |  \                               |
        |   |  |   |   beneficent side-effects        |
        |   |  |   |                                  |
        |   |  |   |!eoln                             |
        |   |  |  \|                                  |
        |   | \|______________________________________|
        |   |
        |   |admit no more breaks needed
        |   |CP_ok_line
        |   | \
        |   |  | #CP_non_eoln
        |   |  |  \
        |   |  |   Beneficient side-effects
        |   |  |
        |   |  |
        |   |  | CP_eoln
        |   |  |  \
        |   |  |   |!eoln; ?ch

  • CP_HT::schematic= n:+HTWIDTH; ws!ch;?ch
  • CP_non_HT_ws::schematic= n:+1; ws!ch; ?ch
  • CP_non_print::schematic= ws!ch; ?ch

    .Next see br.c and br.l

    End