home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume39 / par / part01 < prev    next >
Encoding:
Text File  |  1993-08-21  |  44.7 KB  |  1,139 lines

  1. Newsgroups: comp.sources.misc
  2. From: amc@wuecl.wustl.edu (Adam Costello)
  3. Subject: v39i040:  par - paragraph reformatter, v1.30, Part01/03
  4. Message-ID: <csm-v39i040=par.204815@sparky.Sterling.COM>
  5. X-Md4-Signature: 29394eec01d83c567a65cc32ba87557e
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Sun, 22 Aug 1993 01:48:27 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: amc@wuecl.wustl.edu (Adam Costello)
  12. Posting-number: Volume 39, Issue 40
  13. Archive-name: par/part01
  14. Environment: ANSI-C
  15. Supersedes: par: Volume 38, Issue 114-116
  16.  
  17. Par 1.30 is a package containing documentation and ANSI C source code
  18. for the filter "par".
  19.  
  20. par is a paragraph reformatter, vaguely similar to fmt, but better.
  21.  
  22. For example, the command "par 44qg", given the input:
  23.  
  24.         John Q. Public writes:
  25.         > Jane Doe writes:
  26.         > > May I remind people that this newsgroup
  27.         > > is for posting binaries only.  Please keep
  28.         > > all discussion in .d where it belongs.
  29.         > Who appointed you net.god?
  30.         > We'll discuss things here if we feel like it.
  31.         Could you two please take this to e-mail?
  32.  
  33. Would produce the output:
  34.  
  35.         John Q. Public writes:
  36.  
  37.         > Jane Doe writes:
  38.         >
  39.         > > May I remind people that this
  40.         > > newsgroup is for posting
  41.         > > binaries only.  Please keep
  42.         > > all discussion in .d where it
  43.         > > belongs.
  44.         >
  45.         > Who appointed you net.god?  We'll
  46.         > discuss things here if we feel
  47.         > like it.
  48.  
  49.         Could you two please take this to
  50.         e-mail?
  51.  
  52. Be sure to read "par.doc".
  53.  
  54. AMC
  55. amc@ecl.wustl.edu (Adam M. Costello)
  56.  
  57. #! /bin/sh
  58. # This is a shell archive.  Remove anything before this line, then unpack
  59. # it by saving it into a file and typing "sh file".  To overwrite existing
  60. # files, type "sh file -c".  You can also feed this as standard input via
  61. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  62. # will see the following message at the end:
  63. #        "End of shell archive."
  64. # Contents:  Par130 Par130/par.doc Par130/protoMakefile
  65. # Wrapped by amc@wuecl on Fri Aug 20 19:08:06 1993
  66. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  67. if test ! -d 'Par130' ; then
  68.     echo shar: Creating directory \"'Par130'\"
  69.     mkdir 'Par130'
  70. fi
  71. if test -f 'Par130/par.doc' -a "${1}" != "-c" ; then 
  72.   echo shar: Will not clobber existing file \"'Par130/par.doc'\"
  73. else
  74. echo shar: Extracting \"'Par130/par.doc'\" \(40058 characters\)
  75. sed "s/^X//" >'Par130/par.doc' <<'END_OF_FILE'
  76. X  *********************
  77. X  * par.doc           *
  78. X  * for Par 1.30      *
  79. X  * Copyright 1993 by *
  80. X  * Adam M. Costello  *
  81. X  *********************
  82. X
  83. X
  84. X    Par 1.30 is a package containing:
  85. X
  86. X       + This doc file.
  87. X       + A man page based on this doc file.
  88. X       + The ANSI C source for the filter "par".
  89. X
  90. X
  91. XContents
  92. X
  93. X    Contents
  94. X    File List
  95. X    Rights and Responsibilities
  96. X    Release Notes
  97. X    Compilation
  98. X    Synopsis
  99. X    Description
  100. X    Terminology
  101. X    Options
  102. X    Environment
  103. X    Details
  104. X    Diagnostics
  105. X    Examples
  106. X    Limitations
  107. X    Bugs
  108. X
  109. X
  110. XFile List
  111. X
  112. X    The Par 1.30 package is always distributed with at least the following
  113. X    files:
  114. X
  115. X        buffer.h
  116. X        buffer.c
  117. X        failf.h
  118. X        failf.c
  119. X        par.1
  120. X        par.c
  121. X        par.doc
  122. X        protoMakefile
  123. X        reformat.h
  124. X        reformat.c
  125. X
  126. X    Each file is a text file which identifies itself on the second line, and
  127. X    identifies the version of Par to which it belongs on the third line,
  128. X    so you can always tell which file is which even if the files have been
  129. X    renamed.
  130. X
  131. X    The file "par.1" is a man page for the filter par (not to be confused
  132. X    with the package Par, which contains the source code for par).  "par.1"
  133. X    is based on this doc file, and conveys much (not all) of the same
  134. X    information, but "par.doc" is the definitive documentation for both par
  135. X    and Par.
  136. X
  137. X
  138. XRights and Responsibilities
  139. X
  140. X    The files listed in the Files List section above are each Copyright 1993
  141. X    by Adam M. Costello (henceforth "I").
  142. X
  143. X    I grant everyone permission to use these files in any way, subject to
  144. X    the following two restrictions:
  145. X
  146. X     1) No one may distribute modifications of any of the files unless I am
  147. X        the one who modified them.
  148. X
  149. X     2) No one may distribute any one of the files unless it is accompanied
  150. X        by all of the other files.
  151. X
  152. X    I cannot disallow the distribution of patches, but I would prefer that
  153. X    users send me suggestions for changes so that I can incorporate them
  154. X    into future versions of Par.  See the Bugs section for my addresses.
  155. X
  156. X    Though I have tried to make sure that Par is free of bugs, I make no
  157. X    guarantees about its soundness.  Therefore, I am not responsible for any
  158. X    damage resulting from the use of these files.
  159. X
  160. X
  161. XRelease Notes
  162. X
  163. X    Each entry below describes changes since the previous version.
  164. X
  165. X    Par 1.00 released 25 July 1993
  166. X        The first release.
  167. X
  168. X    Par 1.10 released 2 August 1993
  169. X        Fixed the following bugs:
  170. X            In reformat.c I used sprintf() but forgot to #include <stdio.h>.
  171. X            I forgot to verify that <width> > <prefix> + <suffix>.
  172. X            The first word of a paragraph was expanded to include initial
  173. X            white characters, not just spaces, contrary to par.doc.
  174. X            Some invalid options were not complained about.
  175. X            NUL characters in the input were not handled.
  176. X            A pointer foul-up in freelines() in par.c could cause a crash.
  177. X        Added the following features:
  178. X            The f option.
  179. X            The j option.
  180. X            The t option.
  181. X            The PARBODY environment variable.
  182. X            Multiple options may be concatenated into a single argument.
  183. X        Removed the m option:
  184. X            Its function is better performed by the f and t options.
  185. X            Normally I would avoid making incompatible changes, unless I
  186. X            were doing a complete overhaul of the whole program, in which
  187. X            case I'd make the version number 2.00 to alert users to possible
  188. X            incompatibilities.  However, in this particular instance I
  189. X            allowed an incompatibility in a minor upgrade because version
  190. X            1.00 was distributed to only four people.
  191. X        Changed the handling of white characters:
  192. X            par now changes all of them (except newlines) to spaces as they
  193. X            are read.  This is another incompatible change, excused for the
  194. X            same reason.
  195. X        Made all error messages begin with "par error:".
  196. X
  197. X    Par 1.20 released 10 Aug 1993
  198. X        Since Par 1.10 was distributed to no one, I've made some more
  199. X            incompatible changes in Par 1.20.
  200. X        Added the following features:
  201. X            The d option.
  202. X            Paragraphs are now delimited by vacant lines, not just blank
  203. X                lines.
  204. X            <hang> now affects not only <prefix> but also <suffix>.
  205. X
  206. X    Par 1.30 released 18 Aug 1993
  207. X        Since Par 1.20 was posted to comp.sources.misc, I have made only
  208. X            backward-compatible changes in Par 1.30.
  209. X        Fixed the following bugs:
  210. X            One wrong word in par.c sometimes caused par to crash. Thanks
  211. X                go to vogelke@c-17igp.wpafb.af.mil (Contr Karl Vogel) for
  212. X                sending me an input file that caused a crash.
  213. X            Too-long words were chopped up before the first word in a
  214. X                paragraph was expanded to include initial spaces, allowing
  215. X                impossibility #1 to occur.  The order of the two operations
  216. X                has been reversed.  Thanks go to splat@deakin.oz.au (Andrew
  217. X                Cashin) for reporting the error message.
  218. X        Added the following features:
  219. X            The g option (motivated by suggestions from several people).
  220. X            The q option (inspired by a suggestion from splat@deakin.oz.au
  221. X                (Andrew Cashin)).
  222. X            The R option (my attempt to squash a bad idea from Par 1.00).
  223. X            The PARQUOTE environment variable (comes with the q option).
  224. X            The PARPROTECT environment variable (inspired by a suggestion
  225. X                from dennisf@se01.elk.miles.com (Dennis Flaherty)).
  226. X        Altered the terminology:
  227. X            Several terms have been added, and the meaning of some terms
  228. X            has been slightly modified.  This is a change in the language
  229. X            used to describe par's behavior, not a change in par's actual
  230. X            behavior.
  231. X        Added a clean target to protoMakefile (suggested by hlj@posix.com
  232. X            (Hal Jespersen)).
  233. X
  234. X
  235. XCompilation
  236. X
  237. X    To compile par, you need an ANSI C compiler.  Copy protoMakefile to
  238. X    Makefile and edit it, following the instructions in the comments.  Then
  239. X    use make (or the equivalent on your system) to compile par.
  240. X
  241. X    If you have no make, compile each .c file into an object file and link
  242. X    all the object files together by whatever method works on your system.
  243. X    Then go look for a version of make that works on your system, since it
  244. X    will come in handy in the future.
  245. X
  246. X    If your compiler warns you about a pointer to a constant being converted
  247. X    to a pointer to a non-constant in line 510 of reformat.c, ignore it.
  248. X    Your compiler (like mine) is in error.  What it thinks is a pointer to
  249. X    a constant is actually a pointer to a pointer to a constant, which is
  250. X    something quite different.  The conversion is legal, and I don't think a
  251. X    correct ANSI C compiler would complain.
  252. X
  253. X    If your compiler generates any other warnings that you think are
  254. X    legitimate, please tell me about them (see the Bugs section).
  255. X
  256. X    Note that all variables in par are either constant or automatic (or
  257. X    both), which means that par can be made reentrant (if your compiler
  258. X    supports it).  Given the right operating system, it should be possible
  259. X    for several par processes to share the same code space and the same data
  260. X    space (but not the same stack, of course) in memory.
  261. X
  262. X
  263. XSynopsis
  264. X
  265. X    par [version] [h[<hang>]] [p<prefix>] [s<suffix>] [w<width>] [d[<div>]]
  266. X        [f[<fit>]] [g[<guess>]] [j[<just>]] [l[<last>]] [q[<quote>]]
  267. X        [R[<Report>]] [t[<touch>]]
  268. X
  269. X    Things enclosed in [square brackets] are optional.  Things enclosed in
  270. X    <angle brackets> are parameters.
  271. X
  272. X
  273. XDescription
  274. X
  275. X    par is a filter which copies its input to its output, changing all white
  276. X    characters (except newlines) to spaces, and reformatting each paragraph.
  277. X    Paragraphs are delimited by protected, blank, and vacant lines (see the
  278. X    Terminology section for definitions), and optionally by indentation (see
  279. X    the d option in the Options section).
  280. X
  281. X    Each output paragraph is generated from the corresponding input
  282. X    paragraph as follows:
  283. X
  284. X     1) An optional prefix and/or suffix is removed from each input line.
  285. X     2) The remainder is divided into words (delimited by spaces).
  286. X     3) The words are joined into lines to make an eye-pleasing paragraph.
  287. X     4) The prefixes and suffixes are reattached.
  288. X
  289. X     If there are suffixes, spaces are inserted before them so that they all
  290. X     end in the same column.
  291. X
  292. X
  293. XTerminology
  294. X
  295. X    Miscellaneous terms:
  296. X
  297. X        error
  298. X            A condition which causes par to abort.  See the Diagnostics
  299. X            section.
  300. X
  301. X        IP  Input paragraph.
  302. X
  303. X        OP  Output paragraph.
  304. X
  305. X        parameter
  306. X            A symbol which may take on unsigned integral values.  There are
  307. X            several parameters whose values affect the behavior of par.
  308. X            Parameters can be assigned values using command line options.
  309. X
  310. X
  311. X    Types of characters:
  312. X
  313. X        alphanumeric character
  314. X            An upper case letter, lower case letter, or decimal digit.
  315. X
  316. X        body character
  317. X            A member of the set of characters defined by the PARBODY
  318. X            environment variable (see the Environment section).
  319. X
  320. X        protective character
  321. X            A member of the set of characters defined by the PARPROTECT
  322. X            environment variable (see the Environment section).
  323. X
  324. X        quote character
  325. X            A member of the set of characters defined by the PARQUOTE
  326. X            environment variable (see the Environment section).
  327. X
  328. X        terminal character
  329. X            A period, question mark, exclamation point, or colon.
  330. X
  331. X        white character
  332. X            A space, formfeed, newline, carriage return, tab, or vertical
  333. X            tab.
  334. X
  335. X    Functions:
  336. X
  337. X        comprelen
  338. X            The comprelen of a non-empty set of lines is the length of
  339. X            the longest string of non-body characters appearing at the
  340. X            beginning of every line in the set.
  341. X
  342. X        comsuflen
  343. X            Given a non-empty set <S> of lines, let <p> be the comprelen of
  344. X            <S>.  Let <T> be the set of lines which result from stripping
  345. X            the first <p> characters from each line in <S>.  Let <c> be the
  346. X            longest string of non-body characters appearing at the end of
  347. X            every line in <T>.  Strip <c> of all initial spaces except the
  348. X            last.  The length of <c> is the comsuflen of <S>.
  349. X
  350. X        quoteprefix
  351. X            The quoteprefix of a line is the longest string of quote
  352. X            characters appearing at the beginning of the line, after this
  353. X            string has been stripped of any trailing spaces.
  354. X
  355. X    Types of lines:
  356. X
  357. X        blank line
  358. X            An empty line, or a line whose first character is not protective
  359. X            and which contains only spaces.
  360. X
  361. X        protected line
  362. X            An input line whose first character is protective.
  363. X
  364. X        vacant line
  365. X            Any line which can be shown to be vacant by a finite number of
  366. X            applications of the following recursive rule:  Suppose <S> is a
  367. X            subsequence of a segment (see below) bounded above and below by
  368. X            vacant lines or by the beginning/end of the segment.  Let <p>
  369. X            and <s> be the comprelen and comsuflen of <S>.  Any member of
  370. X            <S> which, if stripped of its first <p> characters and last <s>
  371. X            characters, would be blank, is vacant.
  372. X
  373. X    Groups of lines:
  374. X
  375. X        segment
  376. X            A contiguous sequence of input lines containing no protected or
  377. X            blank lines, bounded above and below by protected lines, blank
  378. X            lines, and/or the beginning/end of the input.
  379. X
  380. X        block
  381. X            A contiguous subsequence of a segment containing no vacant lines,
  382. X            bounded above and below by vacant lines and/or the beginning/end
  383. X            of the segment.
  384. X
  385. X    Types of words:
  386. X
  387. X        capitalized word
  388. X            A word which contains at least one alphanumeric character, whose
  389. X            first alphanumeric character is not a lower case letter.
  390. X
  391. X        curious word
  392. X            A word which contains a terminal character <c> such that there
  393. X            are no alphanumeric characters in the word after <c>, but there
  394. X            is at least one alphanumeric character in the word before <c>.
  395. X
  396. X
  397. XOptions
  398. X
  399. X    Any command line argument may begin with one minus sign (-) which is
  400. X    ignored.  Generally, more than one option may appear in a single command
  401. X    line argument, but there is one exception:  The version option must have
  402. X    a whole argument all to itself.
  403. X
  404. X    version     Causes all remaining arguments to be ignored.  No input is
  405. X                read.  "par 1.30" is printed on the output.  Of course, this
  406. X                will change in future releases of Par.
  407. X
  408. X    All remaining options are used to set values of parameters.  Values set
  409. X    by command line options hold for all paragraphs.  Unset parameters are
  410. X    given default values.  Any unset parameters whose default values depend
  411. X    on the IP are recomputed separately for each paragraph.
  412. X
  413. X    The approximate role of each parameter is described here.  See the
  414. X    Details section for the rest of the story.
  415. X
  416. X    The first four parameters, <hang>, <prefix>, <suffix>, and <width>, may
  417. X    be set to any unsigned decimal integer less than 10000.
  418. X
  419. X    h[<hang>]   Mainly affects the default values of <prefix> and <suffix>.
  420. X                Defaults to 0.  If the h option is given without a number,
  421. X                the value 1 is inferred.  (See also the p and s options.)
  422. X
  423. X    p<prefix>   The first <prefix> characters of each line of the OP
  424. X                are copied from the first <prefix> characters of the
  425. X                corresponding line of the IP.  If there are more than
  426. X                <hang> + 1 lines in the IP, the default value is the
  427. X                comprelen of all the lines in the IP except the first <hang>
  428. X                of them.  If there are exactly <hang> + 1 lines in the IP
  429. X                and <quote> is 1, the default value is the number of leading
  430. X                quote characters in the last line.  Otherwise the default
  431. X                value is 0.  (See also the h and q options.)
  432. X
  433. X    s<suffix>   The last <suffix> characters of each line of the OP
  434. X                are copied from the last <suffix> characters of the
  435. X                corresponding line of the IP.  If there are more than
  436. X                <hang> + 1 lines in the IP, the default value is the
  437. X                comsuflen of all the lines of the IP except the first <hang>
  438. X                of them.  Otherwise the default value is 0.  (See also the h
  439. X                option.)
  440. X
  441. X    w<width>    No line in the OP will contain more than <width> characters,
  442. X                not including the trailing newlines.  Defaults to 72.
  443. X
  444. X    The remaining eight parameters, <div>, <fit>, <guess>, <just>, <last>,
  445. X    <quote>, <Report>, and <touch>, may be set to either 0 or 1.  If the
  446. X    number is absent in the option, the value 1 is inferred.
  447. X
  448. X    d[<div>]    If <div> is 0, then each block becomes an IP.  If <div> is
  449. X                1, then each block is subdivided into IPs as follows:  Let
  450. X                <p> be the comprelen of the block.  Let a line's status be 1
  451. X                if its (<p> + 1)st character is a space, 0 otherwise.  Every
  452. X                line in the block whose status is the same as the status of
  453. X                the first line will begin a new paragraph.  Defaults to 0.
  454. X
  455. X    f[<fit>]    If <fit> is 1 and <just> is 0, par will try to make the
  456. X                lines in the OP as nearly the same length as possible, even
  457. X                if it means making the OP narrower.  Defaults to 0.  (See
  458. X                also the j option.)
  459. X
  460. X    g[<guess>]  If <guess> is 1, then when par is choosing line breaks,
  461. X                whenever it encounters a curious word followed by a
  462. X                capitalized word, it take one of two special actions.  If
  463. X                the two words are separated by a single space in the
  464. X                input, they will be merged into one word with an embedded
  465. X                non-breaking space.  If the two words are separated by more
  466. X                than one space, or by a line break, then par will insure
  467. X                that they are separated by two spaces, or by a line break,
  468. X                in the output.  Defaults to 0.
  469. X
  470. X    j[<just>]   If <just> is 1, par justifies the OP, inserting spaces
  471. X                between words so that all lines in the OP have length
  472. X                <width> (except the last, if <last> is 0).  <fit> has no
  473. X                effect if <just> is 1.  Defaults to 0.  (See also the w, l,
  474. X                and f options.)
  475. X
  476. X    l[<last>]   If <last> is 1, par tries to make the last line of the OP
  477. X                about the same length as the others.  Defaults to 0.
  478. X
  479. X    q[<quote>]  If <quote> is 1, then before each segment is scanned for
  480. X                vacant lines, par will insert some new lines as follows:
  481. X                For each pair of adjacent lines in the segment, if the
  482. X                quoteprefix of one is a prefix of (but not the same as) the
  483. X                quoteprefix of the other, and each of the two lines contains
  484. X                at least one non-quote character, then a line consisting of
  485. X                the smaller quoteprefix will be inserted between the two
  486. X                lines.  <quote> also affects the default value of <prefix>.
  487. X                Defaults to 0.  (See also the p option.)
  488. X
  489. X    R[<Report>] If <Report> is 1, then it will be considered an error for an
  490. X                input word to contain more than <L> = (<width> - <prefix> -
  491. X                <suffix>) characters.  Otherwise, such words will be chopped
  492. X                after each <L>th character into shorter words.  Defaults
  493. X                to 0.  It is recommended that this option be included in
  494. X                PARINIT (see the Environment section).
  495. X
  496. X    t[<touch>]  Has no effect if <suffix> is 0 or <just> is 1.  Otherwise,
  497. X                if <touch> is 0, all lines in the OP have length <width>.
  498. X                If <touch> is 1, then the length of the lines is decreased
  499. X                until the suffixes touch the body of the OP.  Defaults to
  500. X                the logical OR of <fit> and <last>.  (See also the s, j, w,
  501. X                f, and l options.)
  502. X
  503. X    If the value of any parameter is set more than once, the last value is
  504. X    used.  When unset parameters are assigned default values, <hang> and
  505. X    <quote> are assigned before <prefix>, and <fit> and <last> are assigned
  506. X    before <touch> (because of the dependencies).
  507. X
  508. X    It is an error if <width> <= <prefix> + <suffix>.
  509. X
  510. X
  511. XEnvironment
  512. X
  513. X    PARBODY     All and only the characters appearing in the value of
  514. X                PARBODY count as body characters (which are used for
  515. X                determining comprelens and comsuflens).  The underscore is
  516. X                an escape character, which may begin the following escape
  517. X                sequences:
  518. X
  519. X                   __ = an underscore
  520. X                   _s = a space
  521. X                   _A = all upper case letters
  522. X                   _a = all lower case letters
  523. X                   _0 = all decimal digits
  524. X                 _xhh = the character represented by the two hexadecimal
  525. X                        digits hh (which may be upper or lower case)
  526. X
  527. X                If PARBODY is not set, there are no body characters.
  528. X
  529. X                A good value for PARBODY might be "_A_a.", but it depends on
  530. X                the application.
  531. X
  532. X    PARINIT     If set, par will read command line options from PARINIT
  533. X                before it reads them from the command line.
  534. X
  535. X    PARPROTECT  Determines the set of protective characters, using the same
  536. X                syntax as PARBODY.  If PARPROTECT is not set, there are no
  537. X                protective characters.
  538. X
  539. X    PARQUOTE    Determines the set of quote characters, using the same
  540. X                syntax as PARBODY.  If PARQUOTE is not set, then the quote
  541. X                characters are the greater-than sign and the space.
  542. X
  543. X    If a NUL character appears in the value of an environment variable, it
  544. X    and the rest of the string will not be seen by par.
  545. X
  546. X
  547. XDetails
  548. X
  549. X    Lines are terminated by newline characters, but the newlines are not
  550. X    considered to be included in the lines.  If the last character of the
  551. X    input is a non-newline, then a newline will be inferred immediately
  552. X    after it (but if the input is empty, no newline will be inferred; the
  553. X    number of input lines will be 0).  Thus, the input can always be viewed
  554. X    as a sequence of lines.
  555. X
  556. X    Protected lines are copied unchanged from the input to the output.  All
  557. X    other input lines, as they are read, have any NUL characters removed,
  558. X    and every white character (except newlines) turned into a space.
  559. X
  560. X    Blank lines in the input are transformed into empty lines in the output.
  561. X    Vacant lines in the input are stripped of trailing spaces before being
  562. X    output.
  563. X
  564. X    The input is divided into segments, which are divided into blocks,
  565. X    which are divided into IPs.  The exact process depends on the values of
  566. X    <quote> and <div> (see q and d in the Options section).  The remainder
  567. X    of this section describes the process which is applied independently to
  568. X    each IP to construct the corresponding OP.
  569. X
  570. X    After the values of the parameters are determined (see the Options
  571. X    section), the first <prefix> characters and the last <suffix> characters
  572. X    of each input line are removed and remembered.  It is an error for any
  573. X    line to contain fewer than <prefix> + <suffix> characters.
  574. X
  575. X    The remaining text is treated as a sequence of characters, not lines.
  576. X    The text is broken into words, which are delimited by spaces.  That is,
  577. X    a word is a maximal sub-sequence of non-spaces.  If <guess> is 1, then
  578. X    some words might be merged (see g in the Options section).  The first
  579. X    word includes any spaces that preceed it on the same line.
  580. X
  581. X    Let <L> = <width> - <prefix> - <suffix>.
  582. X
  583. X    If <Report> is 0, then some words may get chopped up at this point (see
  584. X    R in the Options section).
  585. X
  586. X    The words are reassembled, preserving their order, into lines.  If
  587. X    <just> is 0, adjacent words within a line are separated by a single
  588. X    space (or sometimes two if <guess> is 1), and line breaks are chosen so
  589. X    that the paragraph satisfies the following properties:
  590. X
  591. X         1) No line contains more than <L> characters.
  592. X
  593. X         2) If <fit> is 1, the difference between the lengths of the
  594. X            shortest and longest lines is as small as possible.
  595. X
  596. X         3) The shortest line is as long as possible, subject to properties
  597. X            1 and 2.
  598. X
  599. X         4) Let <target> be <L> if <fit> is 0, or the length of the longest
  600. X            line if <fit> is 1.  The sum of the squares of the differences
  601. X            between <target> and the lengths of the lines is as small as
  602. X            possible, subject to properties 1, 2, and 3.
  603. X
  604. X        If <last> is 0, then the last line does not count as a line for the
  605. X        purposes of properties 2, 3, and 4 above.
  606. X
  607. X        If all the words fit on a single line, then the properties as worded
  608. X        above don't make much sense.  In that case, no line breaks are
  609. X        inserted.
  610. X
  611. X    If <just> is 1, then adjacent words within a line are separated by one
  612. X    space (or sometimes two if <guess> is 1) plus zero or more extra spaces.
  613. X    The value of <fit> is disregarded, and line breaks are chosen so that
  614. X    the paragraph satisfies the following properties:
  615. X
  616. X         1) Every line contains exactly <L> characters.
  617. X
  618. X         2) The largest inter-word gap is as small as possible, subject
  619. X            to property 1.  (An inter-word gap consists only of the extra
  620. X            spaces, not the regular spaces.)
  621. X
  622. X         3) The sum of the squares of the lengths of the inter-word gaps is
  623. X            as small as possible, subject to properties 1 and 2.
  624. X
  625. X        If <last> is 0, then the last line does not count as a line for the
  626. X        purposes of property 1, and it does not require or contain any extra
  627. X        spaces.
  628. X
  629. X        Extra spaces are distributed as uniformly as possible among the
  630. X        inter-word gaps in each line.
  631. X
  632. X        In a justified paragraph, every line must contain at least two
  633. X        words, but that's not always possible to accomplish.  If the
  634. X        paragraph cannot be justified, it is considered an error.
  635. X
  636. X    If the number of lines in the resulting paragraph is less than <hang>,
  637. X    then empty lines are added at the end to bring the number of lines up to
  638. X    <hang>.
  639. X
  640. X    If <just> is 0 and <touch> is 1, then <L> is changed to be the length of
  641. X    the longest line.
  642. X
  643. X    If <suffix> is not 0, then each line is padded at the end with spaces to
  644. X    bring its length up to <L>.
  645. X
  646. X    To each line is prepended <prefix> characters.  Let <n> be the number of
  647. X    lines in the IP.  The characters which are prepended to the <i>th line
  648. X    are chosen as follows:
  649. X
  650. X     1) If <i> <= <n>, then the characters are copied from the ones that
  651. X        were removed from the beginning of the <n>th input line.
  652. X
  653. X     2) If <i> > <n> > <hang>, then the characters are copied from the ones
  654. X        that were removed from the beginning of the last input line.
  655. X
  656. X     3) If <i> > <n> and <n> <= <hang>, then the characters are all spaces.
  657. X
  658. X    Then to each line is appended <suffix> characters.  The characters which
  659. X    are appended to the <i>th line are chosen as follows:
  660. X
  661. X     1) If <i> <= <n>, then the characters are copied from the ones that
  662. X        were removed from the end of the nth input line.
  663. X
  664. X     2) If <i> > <n> > 0, then the characters are copied from the ones that
  665. X        were removed from the end of the last input line.
  666. X
  667. X     3) If <n> = 0, then the characters are all spaces.
  668. X
  669. X    Finally, the lines are printed to the output as the OP.
  670. X
  671. X
  672. XDiagnostics
  673. X
  674. X    If there are no errors, par returns EXIT_SUCCESS (see <stdlib.h>).
  675. X
  676. X    If there is an error, then an error message will be printed to the
  677. X    output, and par will return EXIT_FAILURE.  If the error is local to a
  678. X    single paragraph, then the preceeding paragraphs will have been output
  679. X    before the error was detected.  Line numbers in error messages are local
  680. X    to the IP in which the error occurred.  All error messages begin with
  681. X    "par error:" on a line by itself.
  682. X
  683. X    Of course, trying to print an error message would be futile if an error
  684. X    resulted from an output function, so par doesn't bother doing any error
  685. X    checking on output functions.
  686. X
  687. X
  688. XExamples
  689. X
  690. X    The superiority of par's dynamic programming algorithm over a greedy
  691. X    algorithm (such as the one used by fmt) can be seen in the following
  692. X    example:
  693. X
  694. X    Original paragraph:
  695. X
  696. X        We the people of the United States,
  697. X        in order to form a more perfect union,
  698. X        establish justice,
  699. X        insure domestic tranquility,
  700. X        provide for the common defense,
  701. X        promote the general welfare,
  702. X        and secure the blessing of liberty
  703. X        to ourselves and our posterity,
  704. X        do ordain and establish the Constitution
  705. X        of the United States of America.
  706. X
  707. X    After a greedy algorithm with width = 39:
  708. X
  709. X        We the people of the United
  710. X        States, in order to form a more
  711. X        perfect union, establish
  712. X        establish justice, insure
  713. X        domestic tranquility, provide
  714. X        for the common defense, promote
  715. X        the general welfare, and secure
  716. X        the blessing of liberty to
  717. X        ourselves and our posterity, do
  718. X        ordain and establish the
  719. X        Constitution of the United
  720. X        States of America.
  721. X
  722. X    After "par 39":
  723. X
  724. X        We the people of the United    
  725. X        States, in order to form a     
  726. X        more perfect union, establish  
  727. X        justice, insure domestic       
  728. X        tranquility, provide for the   
  729. X        common defense, promote the    
  730. X        general welfare, and secure    
  731. X        the blessing of liberty to     
  732. X        ourselves and our posterity,   
  733. X        do ordain and establish the    
  734. X        Constitution of the United     
  735. X        States of America.             
  736. X
  737. X    The line breaks chosen by par are clearly more eye-pleasing.
  738. X
  739. X    par is most useful in conjunction with the text-filtering features of an
  740. X    editor, such as the ! commands of vi.
  741. X
  742. X    The rest of this section is a series of before-and-after pictures
  743. X    showing some typical uses of par.
  744. X
  745. X    Before:
  746. X
  747. X        /*   We the people of the United States, */
  748. X        /* in order to form a more perfect union, */
  749. X        /* establish justice, */
  750. X        /* insure domestic tranquility, */
  751. X        /* provide for the common defense, */
  752. X        /* promote the general welfare, */
  753. X        /* and secure the blessing of liberty */
  754. X        /* to ourselves and our posterity, */
  755. X        /* do ordain and establish the Constitution */
  756. X        /* of the United States of America. */
  757. X
  758. X    After "par 59":
  759. X
  760. X        /*   We the people of the United States, in      */
  761. X        /* order to form a more perfect union, establish */
  762. X        /* justice, insure domestic tranquility, provide */
  763. X        /* for the common defense, promote the general   */
  764. X        /* welfare, and secure the blessing of liberty   */
  765. X        /* to ourselves and our posterity, do ordain     */
  766. X        /* and establish the Constitution of the United  */
  767. X        /* States of America.                            */
  768. X
  769. X    Or after "par 59f":
  770. X
  771. X        /*   We the people of the United States,  */
  772. X        /* in order to form a more perfect union, */
  773. X        /* establish justice, insure domestic     */
  774. X        /* tranquility, provide for the common    */
  775. X        /* defense, promote the general welfare,  */
  776. X        /* and secure the blessing of liberty to  */
  777. X        /* ourselves and our posterity, do ordain */
  778. X        /* and establish the Constitution of the  */
  779. X        /* United States of America.              */
  780. X
  781. X    Or after "par 59l":
  782. X
  783. X        /*   We the people of the United States, in      */
  784. X        /* order to form a more perfect union, establish */
  785. X        /* justice, insure domestic tranquility,         */
  786. X        /* provide for the common defense, promote       */
  787. X        /* the general welfare, and secure the           */
  788. X        /* blessing of liberty to ourselves and our      */
  789. X        /* posterity, do ordain and establish the        */
  790. X        /* Constitution of the United States of America. */
  791. X
  792. X    Or after "par 59lf":
  793. X
  794. X        /*   We the people of the United States,  */
  795. X        /* in order to form a more perfect union, */
  796. X        /* establish justice, insure domestic     */
  797. X        /* tranquility, provide for the common    */
  798. X        /* defense, promote the general welfare,  */
  799. X        /* and secure the blessing of liberty     */
  800. X        /* to ourselves and our posterity, do     */
  801. X        /* ordain and establish the Constitution  */
  802. X        /* of the United States of America.       */
  803. X
  804. X    Or after "par 59lft0":
  805. X
  806. X        /*   We the people of the United States,         */
  807. X        /* in order to form a more perfect union,        */
  808. X        /* establish justice, insure domestic            */
  809. X        /* tranquility, provide for the common           */
  810. X        /* defense, promote the general welfare,         */
  811. X        /* and secure the blessing of liberty            */
  812. X        /* to ourselves and our posterity, do            */
  813. X        /* ordain and establish the Constitution         */
  814. X        /* of the United States of America.              */
  815. X
  816. X    Or after "par 59j":
  817. X
  818. X        /*   We  the people  of  the  United States,  in */
  819. X        /* order to form a more perfect union, establish */
  820. X        /* justice, insure domestic tranquility, provide */
  821. X        /* for the  common defense, promote  the general */
  822. X        /* welfare, and  secure the blessing  of liberty */
  823. X        /* to ourselves and our posterity, do ordain and */
  824. X        /* establish  the  Constitution  of  the  United */
  825. X        /* States of America.                            */
  826. X
  827. X    Or after "par 59jl":
  828. X
  829. X        /*   We  the   people  of  the   United  States, */
  830. X        /* in   order    to   form   a    more   perfect */
  831. X        /* union,  establish  justice,  insure  domestic */
  832. X        /* tranquility, provide for  the common defense, */
  833. X        /* promote  the  general   welfare,  and  secure */
  834. X        /* the  blessing  of  liberty to  ourselves  and */
  835. X        /* our  posterity, do  ordain and  establish the */
  836. X        /* Constitution of the United States of America. */
  837. X
  838. X    Before:
  839. X
  840. X        Preamble      We the people of the United States,
  841. X        to the US     in order to form
  842. X        Constitution  a more perfect union,
  843. X                      establish justice,
  844. X                      insure domestic tranquility,
  845. X                      provide for the common defense,
  846. X                      promote the general welfare,
  847. X                      and secure the blessing of liberty
  848. X                      to ourselves and our posterity,
  849. X                      do ordain and establish
  850. X                      the Constitution
  851. X                      of the United States of America.
  852. X
  853. X    After "par 52h3":
  854. X
  855. X        Preamble      We the people of the United
  856. X        to the US     States, in order to form a
  857. X        Constitution  more perfect union, establish
  858. X                      justice, insure domestic
  859. X                      tranquility, provide for the
  860. X                      common defense, promote the
  861. X                      general welfare, and secure
  862. X                      the blessing of liberty to
  863. X                      ourselves and our posterity,
  864. X                      do ordain and establish the
  865. X                      Constitution of the United
  866. X                      States of America.
  867. X
  868. X    Before:
  869. X
  870. X         1  We the people of the United States,
  871. X         2  in order to form a more perfect union,
  872. X         3  establish justice,
  873. X         4  insure domestic tranquility,
  874. X         5  provide for the common defense,
  875. X         6  promote the general welfare,
  876. X         7  and secure the blessing of liberty
  877. X         8  to ourselves and our posterity,
  878. X         9  do ordain and establish the Constitution
  879. X        10  of the United States of America.
  880. X
  881. X    After "par 59p12l":
  882. X
  883. X         1  We the people of the United States, in order to
  884. X         2  form a more perfect union, establish justice,
  885. X         3  insure domestic tranquility, provide for the
  886. X         4  common defense, promote the general welfare,
  887. X         5  and secure the blessing of liberty to ourselves
  888. X         6  and our posterity, do ordain and establish the
  889. X         7  Constitution of the United States of America.
  890. X
  891. X    Before:
  892. X
  893. X        > > We the people
  894. X        > > of the United States,
  895. X        > > in order to form a more perfect union,
  896. X        > > establish justice,
  897. X        > > ensure domestic tranquility,
  898. X        > > provide for the common defense,
  899. X        >
  900. X        > Promote the general welfare,
  901. X        > and secure the blessing of liberty
  902. X        > to ourselves and our posterity,
  903. X        > do ordain and establish
  904. X        > the Constitution of the United States of America.
  905. X
  906. X    After "par 52":
  907. X
  908. X        > > We the people of the United States, in
  909. X        > > order to form a more perfect union,
  910. X        > > establish justice, ensure domestic
  911. X        > > tranquility, provide for the common
  912. X        > > defense,
  913. X        >
  914. X        > Promote the general welfare, and secure
  915. X        > the blessing of liberty to ourselves and
  916. X        > our posterity, do ordain and establish
  917. X        > the Constitution of the United States of
  918. X        > America.
  919. X
  920. X    Before:
  921. X
  922. X        >   We the people
  923. X        > of the United States,
  924. X        > in order to form a more perfect union,
  925. X        > establish justice,
  926. X        > ensure domestic tranquility,
  927. X        > provide for the common defense,
  928. X        >   Promote the general welfare,
  929. X        > and secure the blessing of liberty
  930. X        > to ourselves and our posterity,
  931. X        > do ordain and establish
  932. X        > the Constitution of the United States of America.
  933. X
  934. X    After "par 52d":
  935. X
  936. X        >   We the people of the United States,
  937. X        > in order to form a more perfect union,
  938. X        > establish justice, ensure domestic
  939. X        > tranquility, provide for the common
  940. X        > defense,
  941. X        >   Promote the general welfare, and secure
  942. X        > the blessing of liberty to ourselves and
  943. X        > our posterity, do ordain and establish
  944. X        > the Constitution of the United States of
  945. X        > America.
  946. X
  947. X    Before:
  948. X
  949. X        Joe Public writes:
  950. X        > Jane Doe writes:
  951. X        > > I can't find the source for uncompress.
  952. X        > Oh no, not again!!!
  953. X        >
  954. X        > Isn't there a FAQ for this?
  955. X        That wasn't very helpful, Joe. Jane,
  956. X        just make a link from uncompress to compress.
  957. X
  958. X    After "par 40q":
  959. X
  960. X        Joe Public writes:
  961. X
  962. X        > Jane Doe writes:
  963. X        >
  964. X        > > I can't find the source for
  965. X        > > uncompress.
  966. X        >
  967. X        > Oh no, not again!!!
  968. X        >
  969. X        > Isn't there a FAQ for this?
  970. X
  971. X        That wasn't very helpful, Joe.
  972. X        Jane, just make a link from
  973. X        uncompress to compress.
  974. X
  975. X    Before:
  976. X
  977. X        I sure hope there's still room
  978. X        in Dr. Jones' section of archaeology.
  979. X        I've heard he's the best.
  980. X
  981. X    After "par 50g":
  982. X
  983. X        I sure hope there's still room in
  984. X        Dr. Jones' section of archaeology.  I've
  985. X        heard he's the best.
  986. X
  987. X
  988. XLimitations
  989. X
  990. X    The <guess> feature guesses wrong in cases like the following:
  991. X
  992. X        I calc'd the approx.
  993. X        Fermi level to 3 sig. digits.
  994. X
  995. X    With <guess> = 1, par will incorrectly assume that "approx." ends a
  996. X    sentence.  If the input were:
  997. X
  998. X        I calc'd the approx. Fermi
  999. X        level to 3 sig. digits.
  1000. X
  1001. X    then par would refuse to put a line break between "approx." and "Fermi"
  1002. X    in the output, mainly to avoid creating the first situation (in case the
  1003. X    paragraph were to be fed back through par again).  This non-breaking
  1004. X    space policy does come in handy for cases like "Mr. Johnson" and
  1005. X    "Jan. 1", though.
  1006. X
  1007. X    The <guess> feature only goes one way.  par can preserve wide sentence
  1008. X    breaks in a paragraph, or remove them, but it can't insert them if they
  1009. X    aren't already in the input.
  1010. X
  1011. X    If you use tabs, you probably won't like the way par handles (or doesn't
  1012. X    handle) them.  It turns them into spaces.  I didn't bother trying to
  1013. X    make sense of tabs because they don't make sense to begin with.  Not
  1014. X    everyone's terminal has the same tab settings, so text files containing
  1015. X    tabs are sometimes mangled.  In fact, almost every text file containing
  1016. X    tabs gets mangled when something is inserted at the beginning of each
  1017. X    line (when quoting e-mail or commenting out a section of a shell script,
  1018. X    for example), making them a pain to edit.  In my opinion, the world
  1019. X    would be a nicer place if everyone stopped using tabs (so I'm doing my
  1020. X    part by not supporting them in par).  (Thanks to ets1@cs.wustl.edu (Eric
  1021. X    T. Stuebe) for showing me the light about tabs.)
  1022. X
  1023. X    There is currently no way for the length of the output prefix to differ
  1024. X    from the length of the input prefix.  Ditto for the suffix.  I may
  1025. X    consider adding this capability in a future release, but right now I'm
  1026. X    not sure how I'd want it to work.
  1027. X
  1028. X
  1029. XBugs
  1030. X
  1031. X    If I knew of any bugs, I wouldn't release the package.  Of course, there
  1032. X    may be bugs that I haven't yet discovered.
  1033. X
  1034. X    If you find any bugs (in the program or in the documentation), or if you
  1035. X    have any suggestions, please send e-mail to:
  1036. X
  1037. X        amc@ecl.wustl.edu
  1038. X
  1039. X    or send paper mail to:
  1040. X
  1041. X        Adam M. Costello
  1042. X        Campus Box 1045
  1043. X        Washington University
  1044. X        One Brookings Dr.
  1045. X        St. Louis, MO 63130
  1046. X        USA
  1047. X
  1048. X    Note that both addresses could change anytime after June 1994.
  1049. X
  1050. X    When reporting a bug, please include the exact input and command line
  1051. X    options used, and the version number of par, so that I can reproduce it.
  1052. END_OF_FILE
  1053. if test 40058 -ne `wc -c <'Par130/par.doc'`; then
  1054.     echo shar: \"'Par130/par.doc'\" unpacked with wrong size!
  1055. fi
  1056. # end of 'Par130/par.doc'
  1057. fi
  1058. if test -f 'Par130/protoMakefile' -a "${1}" != "-c" ; then 
  1059.   echo shar: Will not clobber existing file \"'Par130/protoMakefile'\"
  1060. else
  1061. echo shar: Extracting \"'Par130/protoMakefile'\" \(1522 characters\)
  1062. sed "s/^X//" >'Par130/protoMakefile' <<'END_OF_FILE'
  1063. X# *********************
  1064. X# * protoMakefile     *
  1065. X# * for Par 1.30      *
  1066. X# * Copyright 1993 by *
  1067. X# * Adam M. Costello  *
  1068. X# *********************
  1069. X
  1070. X
  1071. X# Define CC so that the command
  1072. X# $(CC) foo.c
  1073. X# compiles the ANSI C source file "foo.c" into the object file "foo.o".
  1074. X# You may assume that foo.c uses no floating point math.
  1075. X#
  1076. X# If your operating system or your compiler's exit() function automatically
  1077. X# frees all memory allocated by malloc() when a process terminates, then you
  1078. X# can choose to trade away space efficiency for time efficiency by defining
  1079. X# DONTFREE.
  1080. X#
  1081. X# Example (for Solaris 2.2):
  1082. X# CC = cc -c -O -s -Xc -DDONTFREE
  1083. X
  1084. XCC =
  1085. X
  1086. X# Define LINK1 and LINK2 so that the command
  1087. X# $(LINK1) foo1.o foo2.o foo3.o $(LINK2) foo
  1088. X# links the object files "foo1.o", "foo2.o", "foo3.o"
  1089. X# into the executable file "foo".
  1090. X# You may assume that none of the .o files use floating point math.
  1091. X#
  1092. X# Example (for Solaris 2.2):
  1093. X# LINK1 = cc -s
  1094. X# LINK2 = -o
  1095. X
  1096. XLINK1 =
  1097. XLINK2 =
  1098. X
  1099. X# Define RM so that the command
  1100. X# $(RM) foo1 foo2 foo3
  1101. X# removes the files "foo1", "foo2", and "foo3", and
  1102. X# preferrably doesn't complain if they don't exist.
  1103. X#
  1104. X# Example (for Solaris 2.2):
  1105. X# RM = rm -f
  1106. X
  1107. XRM =
  1108. X
  1109. X# You shouldn't need to modify anything below this line.
  1110. X
  1111. XOBJS = buffer.o errmsg.o par.o reformat.o
  1112. X
  1113. X.c.o:
  1114. X    $(CC) $<
  1115. X
  1116. Xpar: $(OBJS)
  1117. X    $(LINK1) $(OBJS) $(LINK2) par
  1118. X
  1119. Xbuffer.o: buffer.c buffer.h errmsg.h
  1120. X
  1121. Xerrmsg.o: errmsg.c errmsg.h
  1122. X
  1123. Xpar.o: par.c errmsg.h buffer.h reformat.h
  1124. X
  1125. Xreformat.o: reformat.c reformat.h buffer.h errmsg.h
  1126. X
  1127. Xclean:
  1128. X    $(RM) par $(OBJS)
  1129. END_OF_FILE
  1130. if test 1522 -ne `wc -c <'Par130/protoMakefile'`; then
  1131.     echo shar: \"'Par130/protoMakefile'\" unpacked with wrong size!
  1132. fi
  1133. # end of 'Par130/protoMakefile'
  1134. fi
  1135. echo shar: End of shell archive.
  1136. exit 0
  1137.  
  1138. exit 0 # Just in case...
  1139.