File rewrap.icn

Summary

###########################################################################

	File:     rewrap.icn

	Subject:  Procedures for advanced line rewrap

	Author:   Richard L. Goerwitz

	Date:	  March 3, 1996

###########################################################################

   This file is in the public domain.

###########################################################################

	Version:  1.4

###########################################################################

  The procedure rewrap(s,i), included in this file, reformats text
  fed to it into strings < i in length.  Rewrap utilizes a static
  buffer, so it can be called repeatedly with different s arguments,
  and still produce homogenous output.  This buffer is flushed by
  calling rewrap with a null first argument.  The default for
  argument 2 (i) is 70.

###########################################################################

  Here's a simple example of how rewrap could be used.  The following
  program reads the standard input, producing fully rewrapped output.

  procedure main()
      every write(rewrap(!&input))
      write(rewrap())
  end

  Naturally, in practice you would want to do things like check for in-
  dentation or blank lines in order to wrap only on a paragraph-by para-
  graph basis, as in

  procedure main()
      while line := read(&input) do {
          if line == "" then {
              write("" ~== rewrap())
              write(line)
          } else {
              if match("\t", line) then {
                  write(rewrap())
                  write(rewrap(line))
              } else {
                  write(rewrap(line))
              }
          }
      }
  end

  Fill-prefixes can be implemented simply by prepending them to the
  output of rewrap:

      i := 70; fill_prefix := " > "
      while line := read(input_file) do {
          line ?:= (f_bit := tab(many('> ')) | "", tab(0))
          write(fill_prefix || f_bit || rewrap(line, i - *fill_prefix))
          etc.

  Obviously, these examples are fairly simplistic.  Putting them to
  actual use would certainly require a few environment-specific
  modifications and/or extensions.  Still, I hope they offer some
  indication of the kinds of applications rewrap might be used in.
 
  Note:  If you want leading and trailing tabs removed, map them to
  spaces first.  Rewrap only fools with spaces, leaving tabs intact.
  This can be changed easily enough, by running its input through the
  Icon detab() function.

###########################################################################

  See also:  wrap.icn

###########################################################################
Procedures:
EndToFront, rewrap

This file is part of the (main) package.

Source code.

Details
Procedures:

EndToFront(i)


rewrap(s, i)



This page produced by UniDoc on 2021/04/15 @ 23:59:54.