home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume39 / par131 / part02 < prev    next >
Encoding:
Text File  |  1993-09-11  |  45.9 KB  |  1,765 lines

  1. Newsgroups: comp.sources.misc
  2. From: amc@wuecl.wustl.edu (Adam Costello)
  3. Subject: v39i084:  par131 - paragraph reformatter, v1.31, Part02/03
  4. Message-ID: <1993Sep11.143709.9254@sparky.sterling.com>
  5. X-Md4-Signature: b0c730022542eb86fb38d5658517f6d8
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Sat, 11 Sep 1993 14:37:09 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: amc@wuecl.wustl.edu (Adam Costello)
  12. Posting-number: Volume 39, Issue 84
  13. Archive-name: par131/part02
  14. Environment: ANSI-C
  15. Supersedes: par: Volume 39, Issue 40-42
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of shell archive."
  24. # Contents:  Par131 Par131/par.1 Par131/charset.h Par131/charset.c
  25. # Wrapped by amc@wuecl on Fri Sep 10 18:46:39 1993
  26. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  27. if test ! -d 'Par131' ; then
  28.     echo shar: Creating directory \"'Par131'\"
  29.     mkdir 'Par131'
  30. fi
  31. if test -f 'Par131/par.1' -a "${1}" != "-c" ; then 
  32.   echo shar: Will not clobber existing file \"'Par131/par.1'\"
  33. else
  34. echo shar: Extracting \"'Par131/par.1'\" \(33574 characters\)
  35. sed "s/^X//" >'Par131/par.1' <<'END_OF_FILE'
  36. X.\"*********************
  37. X.\"* par.1             *
  38. X.\"* for Par 1.31      *
  39. X.\"* Copyright 1993 by *
  40. X.\"* Adam M. Costello  *
  41. X.\"*********************
  42. X.\"
  43. X.\" This is nroff -man (or troff -man) code.
  44. X.\"
  45. X.TH par 1 "7 September 1993" "Par 1.31" "USER COMMANDS"
  46. X.SH NAME
  47. Xpar \- filter for reformatting paragraphs
  48. X.SH SYNOPSIS
  49. X.ds O \fR[\fP
  50. X.ds C \fR]\fP
  51. X.de OP
  52. X.BI \*O\ \\$1 \\$2\ \*C
  53. X..
  54. X.TP .5i
  55. X.B par
  56. X.na
  57. X.OP help
  58. X.OP version
  59. X.OP B opset
  60. X.OP P opset
  61. X.OP Q opset
  62. X.OP h \*Ohang\*C
  63. X.OP p prefix
  64. X.OP s suffix
  65. X.OP w width
  66. X.OP c \*Ocap\*C
  67. X.OP d \*Odiv\*C
  68. X.OP f \*Ofit\*C
  69. X.OP g \*Oguess\*C
  70. X.OP j \*Ojust\*C
  71. X.OP l \*Olast\*C
  72. X.OP q \*Oquote\*C
  73. X.OP R \*OReport\*C
  74. X.OP t \*Otouch\*C
  75. X.br
  76. X.ad
  77. X.SH DESCRIPTION
  78. X.ie t .ds Q ``
  79. X.el .ds Q ""
  80. X.ie t .ds U ''
  81. X.el .ds U ""
  82. X.de IT
  83. X.LP
  84. X\h'-\w"\\$1\ "u'\\$1\ \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
  85. X..
  86. X.LP
  87. X.B par
  88. Xis a filter which copies its input to its output,
  89. Xchanging all white characters (except newlines) to
  90. Xspaces, and reformatting each paragraph.  Paragraphs are
  91. Xseparated by protected, blank, and vacant lines, (see the
  92. X.SM TERMINOLOGY
  93. Xsection for definitions), and optionally
  94. Xdelimited by indentation (see the
  95. X.B d
  96. Xoption in the
  97. X.SM OPTIONS
  98. Xsection).
  99. X.LP
  100. XEach output paragraph is generated from the
  101. Xcorresponding input paragraph as follows:
  102. X.RS
  103. X.LP
  104. X.IT 1) An optional prefix and/or suffix
  105. Xis removed from each input line.
  106. X.IT 2) The remainder is divided into
  107. Xwords (separated by spaces).
  108. X.IT 3) The words are joined into lines
  109. Xto make an eye-pleasing paragraph.
  110. X.IT 4) The prefixes and suffixes are reattached.
  111. X.RE
  112. X.LP
  113. XIf there are suffixes, spaces are inserted before
  114. Xthem so that they all end in the same column.
  115. X.SH TERMINOLOGY
  116. X.LP
  117. XMiscellaneous terms:
  118. X.RS
  119. X.IP "charset syntax"
  120. XA way of representing a set of characters as a string.
  121. XThe set includes exactly those characters which
  122. Xappear in the string, except that the underscore (_)
  123. Xis an escape character.  Whenever it appears, it
  124. Xmust begin one of the following escape sequences:
  125. X.RS 1.5i
  126. X.IT __\ = an underscore
  127. X.IT _s\ = a space
  128. X.IT _b\ = a backslash (\e)
  129. X.IT _q\ = a single quote (')
  130. X.IT _Q\ = a double quote (")
  131. X.IT _A\ = all upper case letters
  132. X.IT _a\ = all lower case letters
  133. X.IT _0\ = all decimal digits
  134. X.IT _x\fIhh\fP\ = the character represented
  135. Xby the two hexadecimal digits
  136. X.I hh
  137. X(which may be upper or lower case)
  138. X.RE
  139. X.IP
  140. XThe NUL character must not appear in the string, but
  141. Xit may be included in the set with the _x00 sequence.
  142. X.IP error
  143. XA condition which causes
  144. X.B par
  145. Xto abort.  See the
  146. X.SM DIAGNOSTICS
  147. Xsection.
  148. X.IP IP
  149. XInput paragraph.
  150. X.IP OP
  151. XOutput paragraph.
  152. X.IP parameter
  153. XA symbol which may take on unsigned integral values.  There
  154. Xare several parameters whose values affect the behavior of
  155. X.BR par .
  156. XParameters can be assigned values
  157. Xusing command line options.
  158. X.RE
  159. X.LP
  160. XTypes of characters:
  161. X.RS
  162. X.IP "alphanumeric character"
  163. XAn upper case letter, lower case letter, or decimal digit.
  164. X.IP "body character"
  165. XA member of the set of characters defined by the
  166. X.SM PARBODY
  167. Xenvironment variable (see the
  168. X.SM ENVIRONMENT
  169. Xsection).
  170. X.IP "protective character"
  171. XA member  of the set of characters defined by the
  172. X.SM PARPROTECT
  173. Xenvironment variable (see the
  174. X.SM ENVIRONMENT
  175. Xsection).
  176. X.IP "quote character"
  177. XA member of the set of characters defined by the
  178. X.SM PARQUOTE
  179. Xenvironment variable (see the
  180. X.SM ENVIRONMENT
  181. Xsection).
  182. X.IP "terminal character"
  183. XA period, question mark, exclamation point, or colon.
  184. X.IP "white character"
  185. XA space, formfeed, newline, carriage
  186. Xreturn, tab, or vertical tab.
  187. X.RE
  188. X.LP
  189. XFunctions:
  190. X.RS
  191. X.IP comprelen
  192. XThe comprelen of a non-empty set of lines is the
  193. Xlength of the longest string of non-body characters
  194. Xappearing at the beginning of every line in the set.
  195. X.IP comsuflen
  196. XGiven a non-empty set
  197. X.I S
  198. Xof lines, let
  199. X.I p
  200. Xbe the comprelen of
  201. X.IR S .
  202. XLet
  203. X.I T
  204. Xbe the set of lines which result from stripping the first
  205. X.I p
  206. Xcharacters from each line in
  207. X.IR S .
  208. XLet
  209. X.I c
  210. Xbe the longest string of non-body characters
  211. Xappearing at the end of every line in
  212. X.IR T .
  213. XStrip
  214. X.I c
  215. Xof all initial spaces except the last.  The length of
  216. X.I c
  217. Xis the comsuflen of
  218. X.IR S .
  219. X.IP quoteprefix
  220. XThe quoteprefix of a line is the longest string of quote
  221. Xcharacters appearing at the beginning of the line, after
  222. Xthis string has been stripped of any trailing spaces.
  223. X.RE
  224. X.LP
  225. XTypes of lines:
  226. X.RS
  227. X.IP "blank line"
  228. XAn empty line, or a line whose first character is
  229. Xnot protective and which contains only spaces.
  230. X.IP "protected line"
  231. XAn input line whose first character is protective.
  232. X.IP "vacant line"
  233. XAny line which can be shown to be vacant by a finite number
  234. Xof applications of the following recursive rule:  Suppose
  235. X.I S
  236. Xis a subsequence of a segment (see below)
  237. Xbounded above and below by vacant lines or
  238. Xby the beginning/end of the segment.  Let
  239. X.I p
  240. Xand
  241. X.I s
  242. Xbe the comprelen and comsuflen of
  243. X.IR S .
  244. XAny member of
  245. X.I S
  246. Xwhich, if stripped of its first
  247. X.I p
  248. Xcharacters and last
  249. X.I s
  250. Xcharacters, would be blank, is vacant.
  251. X.RE
  252. X.LP
  253. XGroups of lines:
  254. X.RS
  255. X.IP segment
  256. XA contiguous sequence of input lines containing no protected
  257. Xor blank lines, bounded above and below by protected
  258. Xlines, blank lines, and/or the beginning/end of the input.
  259. X.IP block
  260. XA contiguous subsequence of a segment containing
  261. Xno vacant lines, bounded above and below by vacant
  262. Xlines and/or the beginning/end of the segment.
  263. X.RE
  264. X.LP
  265. XTypes of words:
  266. X.RS
  267. X.IP "capitalized word"
  268. XIf
  269. X.I cap
  270. Xis 0, a capitalized word is one which contains
  271. Xat least one alphanumeric character, whose first
  272. Xalphanumeric character is not a lower case letter.  If
  273. X.I cap
  274. Xis 1, every word is considered a capitalized word.
  275. X.IP "curious word"
  276. XA word which contains a terminal character
  277. X.I c
  278. Xsuch that there are no alphanumeric
  279. Xcharacters in the word after
  280. X.IR c ,
  281. Xbut there is at least one alphanumeric
  282. Xcharacter in the word before
  283. X.IR c .
  284. X.RE
  285. X.SH OPTIONS
  286. X.LP
  287. XAny command line argument may begin with one minus
  288. Xsign (\-) which is ignored.  Generally, more
  289. Xthan one option may appear in a single command
  290. Xline argument, but there are exceptions:  The
  291. X.BR help ,
  292. X.BR version ,
  293. X.BR B ,
  294. X.BR P ,
  295. Xand
  296. X.B Q
  297. Xoptions must have a whole arguments all to themselves.
  298. X.TP 1i
  299. X.B help
  300. XCauses all remaining arguments to be ignored.  No
  301. Xinput is read.  A usage message is printed on the
  302. Xoutput briefly describing the options used by
  303. X.BR par .
  304. X.TP
  305. X.B version
  306. XCauses all remaining arguments to be ignored.  No input
  307. Xis read.  \*Qpar 1.31\*U is printed on the output.  Of
  308. Xcourse, this will change in future releases of Par.
  309. X.TP
  310. X.BI B opset
  311. X.I op
  312. Xis a single character, either an equal sign
  313. X(=), a plus sign (+), or a minus sign (-).
  314. X.I set
  315. Xis a string using charset syntax.  If
  316. X.I op
  317. Xis an equal sign, the set of body characters
  318. Xis set to the character set defined by
  319. X.IR set .
  320. XIf
  321. X.I op
  322. Xis a plus/minus sign, the characters in the set defined by
  323. X.I set
  324. Xare added/removed to/from the existing
  325. Xset of body characters defined by the
  326. X.SM PARBODY
  327. Xenvironment variable and any previous B options.  It
  328. Xis okay to add characters that are already in the
  329. Xset or to remove characters that are not in the set.
  330. X.TP
  331. X.BI P opset
  332. XJust like the
  333. X.B B
  334. Xoption, except that it applies to
  335. Xthe set of protective characters.
  336. X.TP
  337. X.BI Q opset
  338. XJust like the
  339. X.B B
  340. Xoption, except that it applies
  341. Xto the set of quote characters.
  342. X.LP
  343. XAll remaining options are used to set values of
  344. Xparameters.  Values set by command line options hold
  345. Xfor all paragraphs.  Unset parameters are given default
  346. Xvalues.  Any unset parameters whose default values depend
  347. Xon the IP are recomputed separately for each paragraph.
  348. X.LP
  349. XThe approximate role of each
  350. Xvariable is described here.  See the
  351. X.SM DETAILS
  352. Xsection for the rest of the story.
  353. X.LP
  354. XThe first four parameters,
  355. X.IR hang ,
  356. X.IR prefix ,
  357. X.IR suffix ,
  358. Xand
  359. X.IR width ,
  360. Xmay be set to any unsigned decimal integer less than 10000.
  361. X.TP 1i
  362. X.BI h\fR[ hang\fR]
  363. XMainly affects the default values of
  364. X.I prefix
  365. Xand
  366. X.IR suffix .
  367. XDefaults to 0.  If the
  368. X.B h
  369. Xoption is given without a number, the
  370. Xvalue 1 is inferred.  (See also the
  371. X.B p
  372. Xand
  373. X.B s
  374. Xoptions.)
  375. X.TP
  376. X.BI p prefix
  377. XThe first
  378. X.I prefix
  379. Xcharacters of each line of the OP are copied from the first
  380. X.I prefix
  381. Xcharacters of the corresponding line
  382. Xof the IP.  If there are more than
  383. X.IR hang \ +\ 1
  384. Xlines in the IP, the default value is the comprelen
  385. Xof all the lines in the IP except the first
  386. X.I hang
  387. Xof them.  If there are exactly
  388. X.IR hang \ +\ 1
  389. Xlines in the IP and
  390. X.I quote
  391. Xis 1, the default value is the number of
  392. Xleading quote characters in the last line.
  393. XOtherwise, the default value is 0.  (See also the
  394. X.B h
  395. Xand
  396. X.B q
  397. Xoptions.)
  398. X.TP
  399. X.BI s suffix
  400. XThe last
  401. X.I suffix
  402. Xcharacters of each line of the OP are copied from the last
  403. X.I suffix
  404. Xcharacters of the corresponding line
  405. Xof the IP.  If there are more than
  406. X.IR hang \ +\ 1
  407. Xlines in the IP, the default value is the comsuflen
  408. Xof all the lines of the IP except the first
  409. X.I hang
  410. Xof them.  Otherwise the default value is 0.  (See also the
  411. X.B h
  412. Xoption.)
  413. X.TP
  414. X.BI w width
  415. XNo line in the OP will contain more than
  416. X.I width
  417. Xcharacters, not including the
  418. Xtrailing newlines.  Defaults to 72.
  419. X.LP
  420. XThe remaining eight parameters,
  421. X.IR div,
  422. X.IR fit,
  423. X.IR guess,
  424. X.IR just,
  425. X.IR last,
  426. X.IR quote,
  427. X.IR Report,
  428. Xand
  429. X.IR touch,
  430. Xmay be set to either 0 or 1.  If the number is
  431. Xabsent in the option, the value 1 is inferred.
  432. X.TP 1i
  433. X.BI c\fR[ cap\fR]
  434. XIf
  435. X.I cap
  436. Xis 1, all words are considered capitalized.  This
  437. Xcurrently affects only the application of the
  438. X.B g
  439. Xoption.
  440. X.TP
  441. X.BI d\fR[ div\fR]
  442. XIf
  443. X.I div
  444. Xis 0, each block becames an IP.  If
  445. X.I div
  446. Xis 1, each block is subdivided into IPs as follows:  Let
  447. X.I p
  448. Xbe the comprelen of the block.
  449. XLet a line's status be 1 if its
  450. X.RI ( p \ +\ 1)st
  451. Xcharacter is a space, 0 otherwise.  Every line in the
  452. Xblock whose status is the same as the status of the
  453. Xfirst line will begin a new paragraph.  Defaults to 0.
  454. X.TP
  455. X.BI f\fR[ fit\fR]
  456. XIf
  457. X.I fit
  458. Xis 1 and
  459. X.I just
  460. Xis 0,
  461. X.B par
  462. Xwill try to make the lines in the OP as nearly the
  463. Xsame length as possible, even if it means making
  464. Xthe OP narrower.  Defaults to 0.  (See also the
  465. X.B j
  466. Xoption.)
  467. X.TP
  468. X.BI g\fR[ guess\fR]
  469. XIf
  470. X.I guess
  471. Xis 1, then when
  472. X.B par
  473. Xis choosing line breaks, whenever it encounters a curious
  474. Xword followed by a capitalized word, it takes one of two
  475. Xspecial actions.  If the two words are separated by a
  476. Xsingle space in the input, they will be merged into one
  477. Xword with an embedded non-breaking space.  If the two words
  478. Xare separated by more than one space, or by a line break,
  479. X.B par
  480. Xwill insure that they are separated by two spaces,
  481. Xor by a line break, in the output.  Defaults to 0.
  482. X.TP
  483. X.BI j\fR[ just\fR]
  484. XIf
  485. X.I just
  486. Xis 1,
  487. X.B par
  488. Xjustifies the OP, inserting spaces between words
  489. Xso that all lines in the OP have length
  490. X.I width
  491. X(except the last, if
  492. X.I last
  493. Xis 0).
  494. X.I fit
  495. Xhas no effect if
  496. X.I just
  497. Xis 1.  Defaults to 0.  (See also the
  498. X.BR w ,
  499. X.BR l ,
  500. Xand
  501. X.B f
  502. Xoptions.)
  503. X.TP
  504. X.BI l\fR[ last\fR]
  505. XIf
  506. X.I last
  507. Xis 1,
  508. X.B par
  509. Xtries to make the last line of the OP about
  510. Xthe same length as the others.  Defaults to 0.
  511. X.TP
  512. X.BI q\fR[ quote\fR]
  513. XIf
  514. X.I quote
  515. Xis 1, then before each segment is scanned for vacant lines,
  516. X.B par
  517. Xwill insert some new lines as follows:  For each pair of
  518. Xadjacent lines in the segment, if the quoteprefix of one
  519. Xis a prefix of (but not the same as) the quoteprefix of
  520. Xthe other, and each of the two lines contains at least
  521. Xone non-quote character, then a line consisting of the
  522. Xsmaller quoteprefix will be inserted between the two lines.
  523. X.I quote
  524. Xalso affects the default value of
  525. X.IR prefix .
  526. XDefaults to 0.  (See also the
  527. X.B p
  528. Xoption.)
  529. X.TP
  530. X.BI R\fR[ Report\fR]
  531. XIf
  532. X.I Report
  533. Xis 1, it will be considered an error
  534. Xfor an input word to contain more than
  535. X.IR L \ =
  536. X.RI ( width \ -
  537. X.IR prefix \ -
  538. X.IR suffix )
  539. Xcharacters.  Otherwise, such
  540. Xwords will be chopped after each
  541. X.IR L th
  542. Xcharacter into shorter words.  Defaults to 0.  It
  543. Xis recommended that this option be included in
  544. X.SM PARINIT
  545. X(see the
  546. X.SM ENVIRONMENT
  547. Xsection).
  548. X.TP
  549. X.BI t\fR[ touch\fR]
  550. XHas no effect if
  551. X.I suffix
  552. Xis 0 or
  553. X.I just
  554. Xis 1.  Otherwise, if
  555. X.I touch
  556. Xis 0, all lines in the OP have length
  557. X.IR width .
  558. XIf
  559. X.I touch
  560. Xis 1, the length of the lines is decreased until the
  561. Xsuffixes touch the body of the OP.  Defaults to the logical
  562. X.SM OR
  563. Xof
  564. X.I fit
  565. Xand
  566. X.IR last .
  567. X(See also the
  568. X.BR s ,
  569. X.BR j ,
  570. X.BR w ,
  571. X.BR f ,
  572. Xand
  573. X.B l
  574. Xoptions.)
  575. X.LP
  576. XIf the value of any parameter is set more
  577. Xthan once, the last value is used.  When
  578. Xunset parameters are assigned default values,
  579. X.I hang
  580. Xand
  581. X.I quote
  582. Xare assigned before
  583. X.IR prefix ,
  584. Xand
  585. X.I fit
  586. Xand
  587. X.I last
  588. Xare assigned before
  589. X.I touch
  590. X(because of the dependencies).
  591. X.LP
  592. XIt is an error if
  593. X.I width
  594. X<=
  595. X.I prefix
  596. X+
  597. X.IR suffix .
  598. X.SH ENVIRONMENT
  599. X.TP 1i
  600. X.SM PARBODY
  601. XDetermines the initial set of body characters
  602. X(which are used for determining comprelens
  603. Xand comsuflens), using charset syntax.  If
  604. X.SM PARBODY
  605. Xis not set, the set of body characters
  606. Xis initially empty.  A good value for
  607. X.SM PARBODY
  608. Xmight be \*Q_A_a.\*U, but it depends on the application.
  609. X.TP
  610. X.SM PARINIT
  611. XIf set,
  612. X.B par
  613. Xwill read command line options from
  614. X.SM PARINIT
  615. Xbefore it reads them from the command line.
  616. XWithin the value of
  617. X.SM PARINIT\s0,
  618. Xarguments are separated by white characters.
  619. X.TP
  620. X.SM PARPROTECT
  621. XDetermines the set of protective
  622. Xcharacters, using charset syntax.  If
  623. X.SM PARPROTECT
  624. Xis not set, the set of protective
  625. Xcharacters is initially empty.
  626. X.TP
  627. X.SM PARQUOTE
  628. XDetermines the set of quote
  629. Xcharacters, using charset syntax.  If
  630. X.SM PARQUOTE
  631. Xis not set, the set of quote characters initially
  632. Xcontains only the greater-than sign (>) and the space.
  633. X.LP
  634. XIf a
  635. X.SM NUL
  636. Xcharacter appears in the value of an environment variable,
  637. Xit and the rest of the string will not be seen by
  638. X.BR par .
  639. X.SH DETAILS
  640. X.LP
  641. XLines are terminated by newline characters, but the
  642. Xnewlines are not considered to be included in the lines.
  643. XIf the last character of the input is a non-newline,
  644. Xa newline will be inferred immediately after it (but
  645. Xif the input is empty, no newline will be inferred;
  646. Xthe number of input lines will be 0).  Thus, the
  647. Xinput can always be viewed as a sequence of lines.
  648. X.LP
  649. XProtected lines are copied unchanged from the input to the
  650. Xoutput.  All other input lines, as they are read, have any
  651. X.SM NUL
  652. Xcharacters removed, and every white character
  653. X(except newlines) turned into a space.
  654. X.LP
  655. XBlank lines in the input are transformed into empty
  656. Xlines in the output.  Vacant lines in the input are
  657. Xstripped of trailing spaces before being output.
  658. X.LP
  659. XThe input is divided into segments, which are
  660. Xdivided into blocks, which are divided into
  661. XIPs.  The exact process depends on the values of
  662. X.I quote
  663. Xand
  664. X.I div
  665. X(see
  666. X.B q
  667. Xand
  668. X.B d
  669. Xin the
  670. X.SM OPTIONS
  671. Xsection).  The remainder of this section describes
  672. Xthe process which is applied independently to
  673. Xeach IP to construct the corresponding OP.
  674. X.LP
  675. XAfter the values of the parameters are determined (see the
  676. X.SM OPTIONS
  677. Xsection), the first
  678. X.I prefix
  679. Xcharacters and the last
  680. X.I suffix
  681. Xcharacters of each input line are removed and remembered.
  682. XIt is an error for any line to contain fewer than
  683. X.IR prefix \ +\  suffix
  684. Xcharacters.
  685. X.LP
  686. XThe remaining text is treated as a sequence of
  687. Xcharacters, not lines.  The text is broken into
  688. Xwords, which are separated by spaces.  That is, a
  689. Xword is a maximal sub-sequence of non-spaces.  If
  690. X.I guess
  691. Xis 1, some words might be merged (see
  692. X.B g
  693. Xin the
  694. X.SM OPTIONS
  695. Xsection).  The first word includes any
  696. Xspaces that preceed it on the same line.
  697. X.LP
  698. XLet
  699. X.I L
  700. X=
  701. X.I width
  702. X\-
  703. X.I prefix
  704. X\-
  705. X.IR suffix .
  706. X.LP
  707. XIf
  708. X.I Report
  709. Xis 0, some words may get chopped up at this point (see
  710. X.B R
  711. Xin the
  712. X.SM
  713. XOPTIONS
  714. Xsection).
  715. X.LP
  716. XThe words are reassembled, preserving
  717. Xtheir order, into lines.  If
  718. X.I just
  719. Xis 0, adjacent words within a line are separated
  720. Xby a single space, (or sometimes two if
  721. X.I guess
  722. Xis 1), and line breaks are chosen so that
  723. Xthe paragraph satisfies the following properties:
  724. X.RS 1i
  725. X.IT 1) No line contains more than
  726. X.I L
  727. Xcharacters.
  728. X.IT 2) If
  729. X.I fit
  730. Xis 1, the difference between the lengths of the
  731. Xshortest and longest lines is as small as possible.
  732. X.IT 3) The shortest line is as long as
  733. Xpossible, subject to properties 1 and 2.
  734. X.IT 4) Let
  735. X.I target
  736. Xbe
  737. X.I L
  738. Xif
  739. X.I fit
  740. Xis 0, or the length of the longest line if
  741. X.I fit
  742. Xis 1.  The sum of the squares of the differences between
  743. X.I target
  744. Xand the lengths of the lines is as small as
  745. Xpossible, subject to properties 1, 2, and 3.
  746. X.RE
  747. X.RS .5i
  748. X.LP
  749. XIf
  750. X.I last
  751. Xis 0, the last line does not count as a line for
  752. Xthe purposes of properties 2, 3, and 4 above.
  753. X.LP
  754. XIf all the words fit on a single line, the
  755. Xproperties as worded above don't make much
  756. Xsense.  In that case, no line breaks are inserted.
  757. X.RE
  758. X.LP
  759. XIf
  760. X.I just
  761. Xis 1, adjacent words within a line are
  762. Xseparated by one space (or sometimes two if
  763. X.I guess
  764. Xis 1) plus zero or more extra spaces.  The value of
  765. X.I fit
  766. Xis disregarded, and line breaks are chosen so that
  767. Xthe paragraph satisfies the following properties:
  768. X.RS 1i
  769. X.IT 1) Every line contains exactly
  770. X.I L
  771. Xcharacters.
  772. X.IT 2) The largest inter-word gap is as small as
  773. Xpossible, subject to property 1.  (An inter-word gap
  774. Xconsists only of the extra spaces, not the regular spaces.)
  775. X.IT 3) The sum of the squares of the lengths
  776. Xof the inter-word gaps is as small as
  777. Xpossible, subject to properties 1 and 2.
  778. X.RE
  779. X.RS .5i
  780. X.LP
  781. XIf
  782. X.I last
  783. Xis 0, the last line does not count as a line
  784. Xfor the purposes of property 1, and it does
  785. Xnot require or contain any extra spaces.
  786. X.LP
  787. XExtra spaces are distributed as uniformly as
  788. Xpossible among the inter-word gaps in each line.
  789. X.LP
  790. XIn a justified paragraph, every line must
  791. Xcontain at least two words, but that's not
  792. Xalways possible to accomplish.  If the paragraph
  793. Xcannot be justified, it is considered an error.
  794. X.RE
  795. X.LP
  796. XIf the number of lines in the
  797. Xresulting paragraph is less than
  798. X.IR hang ,
  799. Xempty lines are added at the end
  800. Xto bring the number of lines up to
  801. X.IR hang .
  802. X.LP
  803. XIf
  804. X.I just
  805. Xis 0 and
  806. X.I touch
  807. Xis 1,
  808. X.I L
  809. Xis changed to be the length of the longest line.
  810. X.LP
  811. XIf
  812. X.I suffix
  813. Xis not 0, each line is padded at the end
  814. Xwith spaces to bring its length up to
  815. X.IR L .
  816. X.LP
  817. XTo each line is prepended
  818. X.I prefix
  819. Xcharacters.  Let
  820. X.I n
  821. Xbe the number of lines in the IP.  The
  822. Xcharacters which are prepended to the
  823. X.IR i th
  824. Xline are chosen as follows:
  825. X.RS
  826. X.LP
  827. X.IT 1) If
  828. X.I i
  829. X<=
  830. X.IR n ,
  831. Xthe characters are copied from the ones
  832. Xthat were removed from the beginning of the
  833. X.IR n th
  834. Xinput line.
  835. X.IT 2) If
  836. X.I i
  837. X>
  838. X.I n
  839. X>
  840. X.IR hang ,
  841. Xthe characters are copied from the ones that were
  842. Xremoved from the beginning of the last input line.
  843. X.IT 3) If
  844. X.I i
  845. X>
  846. X.I n
  847. Xand
  848. X.I n
  849. X<=
  850. X.IR hang ,
  851. Xthe characters are all spaces.
  852. X.RE
  853. X.LP
  854. XThen to each line is appended
  855. X.I suffix
  856. Xcharacters.  The characters which are appended to the
  857. X.IR i th
  858. Xline are chosen as follows:
  859. X.RS
  860. X.LP
  861. X.IT 1) If
  862. X.I i
  863. X<=
  864. X.IR n ,
  865. Xthe characters are copied from the ones
  866. Xthat were removed from the end of the
  867. X.IR n th
  868. Xinput line.
  869. X.IT 2) If
  870. X.I i
  871. X>
  872. X.I n
  873. X> 0, the characters are copied from the ones that
  874. Xwere removed from the end of the last input line.
  875. X.IT 3) If
  876. X.I n
  877. X= 0, the characters are all spaces.
  878. X.RE
  879. X.LP
  880. XFinally, the lines are printed to the output as the OP.
  881. X.SH DIAGNOSTICS
  882. X.LP
  883. XIf there are no errors,
  884. X.B par
  885. Xreturns
  886. X.SM EXIT_SUCCESS
  887. X(see
  888. X.BR <stdlib.h> ).
  889. X.LP
  890. XIf there is an error, an error message
  891. Xwill be printed to the output, and
  892. X.B par
  893. Xwill return
  894. X.SM EXIT_FAILURE\s0\.
  895. XIf the error is local to a single paragraph, the preceeding
  896. Xparagraphs will have been output before the error
  897. Xwas detected.  Line numbers in error messages are
  898. Xlocal to the IP in which the error occurred.  All
  899. Xerror messages begin with \*Qpar\ error:\*U on a line
  900. Xby itself.  Error messages concerning command line
  901. Xor environment variable syntax are accompanied by
  902. Xthe same usage message that the help option produces.
  903. X.LP
  904. XOf course, trying to print an error message would be
  905. Xfutile if an error resulted from an output function, so
  906. X.B par
  907. Xdoesn't bother doing any error checking on output functions.
  908. X.SH EXAMPLES
  909. X.de VS
  910. X.RS -.5i
  911. X.LP
  912. X.nf
  913. X.ps -1p
  914. X.vs -2p
  915. X.cs R 20
  916. X..
  917. X.de VE
  918. X.cs R
  919. X.vs
  920. X.ps
  921. X.fi
  922. X.RE
  923. X..
  924. X.de CM
  925. X\&\*Q\fB\\$1\fP\\*U:
  926. X..
  927. X.LP
  928. XThe superiority of
  929. X.BR par 's
  930. Xdynamic programming algorithm over a
  931. Xgreedy algorithm (such as the one used by
  932. X.BR fmt )
  933. Xcan be seen in the following example:
  934. X.LP
  935. XOriginal paragraph (note that
  936. Xeach line begins with 8 spaces):
  937. X.VS
  938. X        We the people of the United States,
  939. X        in order to form a more perfect union,
  940. X        establish justice,
  941. X        insure domestic tranquility,
  942. X        provide for the common defense,
  943. X        promote the general welfare,
  944. X        and secure the blessing of liberty
  945. X        to ourselves and our posterity,
  946. X        do ordain and establish the Constitution
  947. X        of the United States of America.
  948. X.VE
  949. X.LP
  950. XAfter a greedy algorithm with width = 39:
  951. X.VS
  952. X        We the people of the United
  953. X        States, in order to form a more
  954. X        perfect union, establish
  955. X        justice, insure domestic
  956. X        tranquility, provide for the
  957. X        common defense, promote the
  958. X        general welfare, and secure the
  959. X        blessing of liberty to
  960. X        ourselves and our posterity, do
  961. X        ordain and establish the
  962. X        Constitution of the United
  963. X        States of America.
  964. X.VE
  965. X.LP
  966. XAfter
  967. X.CM "par 39"
  968. X.VS
  969. X        We the people of the United
  970. X        States, in order to form a
  971. X        more perfect union, establish
  972. X        justice, insure domestic
  973. X        tranquility, provide for the
  974. X        common defense, promote the
  975. X        general welfare, and secure
  976. X        the blessing of liberty to
  977. X        ourselves and our posterity,
  978. X        do ordain and establish the
  979. X        Constitution of the United
  980. X        States of America.
  981. X.VE
  982. X.LP
  983. XThe line breaks chosen by
  984. X.B par
  985. Xare clearly more eye-pleasing.
  986. X.LP
  987. X.B par
  988. Xis most useful in conjunction with the text-filtering
  989. Xfeatures of an editor, such as the ! commands of
  990. X.BR vi .
  991. X.LP
  992. XThe rest of this section is a series of
  993. Xbefore-and-after pictures showing some typical uses of
  994. X.BR par .
  995. X.LP
  996. XBefore:
  997. X.VS
  998. X        /*   We the people of the United States, */
  999. X        /* in order to form a more perfect union, */
  1000. X        /* establish justice, */
  1001. X        /* insure domestic tranquility, */
  1002. X        /* provide for the common defense, */
  1003. X        /* promote the general welfare, */
  1004. X        /* and secure the blessing of liberty */
  1005. X        /* to ourselves and our posterity, */
  1006. X        /* do ordain and establish the Constitution */
  1007. X        /* of the United States of America. */
  1008. X.VE
  1009. X.LP
  1010. XAfter
  1011. X.CM "par 59"
  1012. X.VS
  1013. X        /*   We the people of the United States, in      */
  1014. X        /* order to form a more perfect union, establish */
  1015. X        /* justice, insure domestic tranquility, provide */
  1016. X        /* for the common defense, promote the general   */
  1017. X        /* welfare, and secure the blessing of liberty   */
  1018. X        /* to ourselves and our posterity, do ordain     */
  1019. X        /* and establish the Constitution of the United  */
  1020. X        /* States of America.                            */
  1021. X.VE
  1022. X.LP
  1023. XOr after
  1024. X.CM "par 59f"
  1025. X.VS
  1026. X        /*   We the people of the United States,  */
  1027. X        /* in order to form a more perfect union, */
  1028. X        /* establish justice, insure domestic     */
  1029. X        /* tranquility, provide for the common    */
  1030. X        /* defense, promote the general welfare,  */
  1031. X        /* and secure the blessing of liberty to  */
  1032. X        /* ourselves and our posterity, do ordain */
  1033. X        /* and establish the Constitution of the  */
  1034. X        /* United States of America.              */
  1035. X.VE
  1036. X.LP
  1037. XOr after
  1038. X.CM "par 59l"
  1039. X.VS
  1040. X        /*   We the people of the United States, in      */
  1041. X        /* order to form a more perfect union, establish */
  1042. X        /* justice, insure domestic tranquility,         */
  1043. X        /* provide for the common defense, promote       */
  1044. X        /* the general welfare, and secure the           */
  1045. X        /* blessing of liberty to ourselves and our      */
  1046. X        /* posterity, do ordain and establish the        */
  1047. X        /* Constitution of the United States of America. */
  1048. X.VE
  1049. X.LP
  1050. XOr after
  1051. X.CM "par 59lf"
  1052. X.VS
  1053. X        /*   We the people of the United States,  */
  1054. X        /* in order to form a more perfect union, */
  1055. X        /* establish justice, insure domestic     */
  1056. X        /* tranquility, provide for the common    */
  1057. X        /* defense, promote the general welfare,  */
  1058. X        /* and secure the blessing of liberty     */
  1059. X        /* to ourselves and our posterity, do     */
  1060. X        /* ordain and establish the Constitution  */
  1061. X        /* of the United States of America.       */
  1062. X.VE
  1063. X.LP
  1064. XOr after
  1065. X.CM "par 59lft0"
  1066. X.VS
  1067. X        /*   We the people of the United States,         */
  1068. X        /* in order to form a more perfect union,        */
  1069. X        /* establish justice, insure domestic            */
  1070. X        /* tranquility, provide for the common           */
  1071. X        /* defense, promote the general welfare,         */
  1072. X        /* and secure the blessing of liberty            */
  1073. X        /* to ourselves and our posterity, do            */
  1074. X        /* ordain and establish the Constitution         */
  1075. X        /* of the United States of America.              */
  1076. X.VE
  1077. X.LP
  1078. XOr after
  1079. X.CM "par 59j"
  1080. X.VS
  1081. X        /*   We  the people  of  the  United States,  in */
  1082. X        /* order to form a more perfect union, establish */
  1083. X        /* justice, insure domestic tranquility, provide */
  1084. X        /* for the  common defense, promote  the general */
  1085. X        /* welfare, and  secure the blessing  of liberty */
  1086. X        /* to ourselves and our posterity, do ordain and */
  1087. X        /* establish  the  Constitution  of  the  United */
  1088. X        /* States of America.                            */
  1089. X.VE
  1090. X.LP
  1091. XOr after
  1092. X.CM "par 59jl"
  1093. X.VS
  1094. X        /*   We  the   people  of  the   United  States, */
  1095. X        /* in   order    to   form   a    more   perfect */
  1096. X        /* union,  establish  justice,  insure  domestic */
  1097. X        /* tranquility, provide for  the common defense, */
  1098. X        /* promote  the  general   welfare,  and  secure */
  1099. X        /* the  blessing  of  liberty to  ourselves  and */
  1100. X        /* our  posterity, do  ordain and  establish the */
  1101. X        /* Constitution of the United States of America. */
  1102. X.VE
  1103. X.LP
  1104. XBefore:
  1105. X.VS
  1106. X        Preamble      We the people of the United States,
  1107. X        to the US     in order to form
  1108. X        Constitution  a more perfect union,
  1109. X                      establish justice,
  1110. X                      insure domestic tranquility,
  1111. X                      provide for the common defense,
  1112. X                      promote the general welfare,
  1113. X                      and secure the blessing of liberty
  1114. X                      to ourselves and our posterity,
  1115. X                      do ordain and establish
  1116. X                      the Constitution
  1117. X                      of the United States of America.
  1118. X.VE
  1119. X.LP
  1120. XAfter
  1121. X.CM "par 52h3"
  1122. X.VS
  1123. X        Preamble      We the people of the United
  1124. X        to the US     States, in order to form a
  1125. X        Constitution  more perfect union, establish
  1126. X                      justice, insure domestic
  1127. X                      tranquility, provide for the
  1128. X                      common defense, promote the
  1129. X                      general welfare, and secure
  1130. X                      the blessing of liberty to
  1131. X                      ourselves and our posterity,
  1132. X                      do ordain and establish the
  1133. X                      Constitution of the United
  1134. X                      States of America.
  1135. X.VE
  1136. X.LP
  1137. XBefore:
  1138. X.VS
  1139. X         1  We the people of the United States,
  1140. X         2  in order to form a more perfect union,
  1141. X         3  establish justice,
  1142. X         4  insure domestic tranquility,
  1143. X         5  provide for the common defense,
  1144. X         6  promote the general welfare,
  1145. X         7  and secure the blessing of liberty
  1146. X         8  to ourselves and our posterity,
  1147. X         9  do ordain and establish the Constitution
  1148. X        10  of the United States of America.
  1149. X.VE
  1150. X.LP
  1151. XAfter
  1152. X.CM "par 59p12l"
  1153. X.VS
  1154. X         1  We the people of the United States, in order to
  1155. X         2  form a more perfect union, establish justice,
  1156. X         3  insure domestic tranquility, provide for the
  1157. X         4  common defense, promote the general welfare,
  1158. X         5  and secure the blessing of liberty to ourselves
  1159. X         6  and our posterity, do ordain and establish the
  1160. X         7  Constitution of the United States of America.
  1161. X.VE
  1162. X.LP
  1163. XBefore:
  1164. X.VS
  1165. X        > > We the people
  1166. X        > > of the United States,
  1167. X        > > in order to form a more perfect union,
  1168. X        > > establish justice,
  1169. X        > > ensure domestic tranquility,
  1170. X        > > provide for the common defense,
  1171. X        >
  1172. X        > Promote the general welfare,
  1173. X        > and secure the blessing of liberty
  1174. X        > to ourselves and our posterity,
  1175. X        > do ordain and establish
  1176. X        > the Constitution of the United States of America.
  1177. X.VE
  1178. X.LP
  1179. XAfter
  1180. X.CM "par 52"
  1181. X.VS
  1182. X        > > We the people of the United States, in
  1183. X        > > order to form a more perfect union,
  1184. X        > > establish justice, ensure domestic
  1185. X        > > tranquility, provide for the common
  1186. X        > > defense,
  1187. X        >
  1188. X        > Promote the general welfare, and secure
  1189. X        > the blessing of liberty to ourselves and
  1190. X        > our posterity, do ordain and establish
  1191. X        > the Constitution of the United States of
  1192. X        > America.
  1193. X.VE
  1194. X.LP
  1195. XBefore:
  1196. X.VS
  1197. X        >   We the people
  1198. X        > of the United States,
  1199. X        > in order to form a more perfect union,
  1200. X        > establish justice,
  1201. X        > ensure domestic tranquility,
  1202. X        > provide for the common defense,
  1203. X        >   Promote the general welfare,
  1204. X        > and secure the blessing of liberty
  1205. X        > to ourselves and our posterity,
  1206. X        > do ordain and establish
  1207. X        > the Constitution of the United States of America.
  1208. X.VE
  1209. X.LP
  1210. XAfter
  1211. X.CM "par 52d"
  1212. X.VS
  1213. X        >   We the people of the United States,
  1214. X        > in order to form a more perfect union,
  1215. X        > establish justice, ensure domestic
  1216. X        > tranquility, provide for the common
  1217. X        > defense,
  1218. X        >   Promote the general welfare, and secure
  1219. X        > the blessing of liberty to ourselves and
  1220. X        > our posterity, do ordain and establish
  1221. X        > the Constitution of the United States of
  1222. X        > America.
  1223. X.VE
  1224. X.LP
  1225. XBefore:
  1226. X.VS
  1227. X        Joe Public writes:
  1228. X        > Jane Doe writes:
  1229. X        > > I can't find the source for uncompress.
  1230. X        > Oh no, not again!!!
  1231. X        >
  1232. X        > Isn't there a FAQ for this?
  1233. X        That wasn't very helpful, Joe. Jane,
  1234. X        just make a link from uncompress to compress.
  1235. X.VE
  1236. X.LP
  1237. XAfter
  1238. X.CM "par 40q"
  1239. X.VS
  1240. X        Joe Public writes:
  1241. X
  1242. X        > Jane Doe writes:
  1243. X        >
  1244. X        > > I can't find the source for
  1245. X        > > uncompress.
  1246. X        >
  1247. X        > Oh no, not again!!!
  1248. X        >
  1249. X        > Isn't there a FAQ for this?
  1250. X
  1251. X        That wasn't very helpful, Joe.
  1252. X        Jane, just make a link from
  1253. X        uncompress to compress.
  1254. X.VE
  1255. X.LP
  1256. XBefore:
  1257. X.VS
  1258. X        I sure hope there's still room
  1259. X        in Dr. Jones' section of archaeology.
  1260. X        I've heard he's the bestest.  [sic]
  1261. X.VE
  1262. X.LP
  1263. XAfter
  1264. X.CM "par 50g"
  1265. X.VS
  1266. X        I sure hope there's still room in
  1267. X        Dr. Jones' section of archaeology.  I've
  1268. X        heard he's the bestest. [sic]
  1269. X.VE
  1270. X.LP
  1271. XOr after
  1272. X.CM "par 50gc"
  1273. X.VS
  1274. X        I sure hope there's still room in
  1275. X        Dr. Jones' section of archaeology.  I've
  1276. X        heard he's the bestest.  [sic]
  1277. X.VE
  1278. X.SH SEE ALSO
  1279. X.LP
  1280. X.B par.doc
  1281. X.SH LIMITATIONS
  1282. X.LP
  1283. XThe
  1284. X.I guess
  1285. Xfeature guesses wrong in cases like the following:
  1286. X.VS
  1287. X        I calc'd the approx.
  1288. X        Fermi level to 3 sig. digits.
  1289. X.VE
  1290. X.LP
  1291. XWith
  1292. X.I guess
  1293. X= 1,
  1294. X.B par
  1295. Xwill incorrectly assume that \*Qapprox.\*U
  1296. Xends a sentence.  If the input were:
  1297. X.VS
  1298. X        I calc'd the approx. Fermi
  1299. X        level to 3 sig. digits.
  1300. X.VE
  1301. X.LP
  1302. Xthen
  1303. X.B par
  1304. Xwould refuse to put a line break between
  1305. X\*Qapprox.\*U and \*QFermi\*U in the output,
  1306. Xmainly to avoid creating the first situation (in
  1307. Xcase the paragraph were to be fed back through
  1308. X.B par
  1309. Xagain).  This non-breaking space policy does come in handy
  1310. Xfor cases like \*QMr.\ Johnson\*U and \*QJan.\ 1\*U, though.
  1311. X.LP
  1312. XThe
  1313. X.I guess
  1314. Xfeature only goes one way.
  1315. X.B par
  1316. Xcan preserve wide sentence breaks in a
  1317. Xparagraph, or remove them, but it can't insert
  1318. Xthem if they aren't already in the input.
  1319. X.LP
  1320. XIf you use tabs, you probably won't like the way
  1321. X.B par
  1322. Xhandles (or doesn't handle) them.  It turns them into
  1323. Xspaces.  I didn't bother trying to make sense of tabs
  1324. Xbecause they don't make sense to begin with.  Not everyone's
  1325. Xterminal has the same tab settings, so text files containing
  1326. Xtabs are sometimes mangled.  In fact, almost every text
  1327. Xfile containing tabs gets mangled when something is
  1328. Xinserted at the beginning of each line (when quoting
  1329. Xe-mail or commenting out a section of a shell script, for
  1330. Xexample), making them a pain to edit.  In my opinion, the
  1331. Xworld would be a nicer place if everyone stopped using
  1332. Xtabs (so I'm doing my part by not supporting them in
  1333. X.BR par .)
  1334. X(Thanks to ets1@cs.wustl.edu (Eric T. Stuebe)
  1335. Xfor showing me the light about tabs.)
  1336. X.LP
  1337. XThere is currently no way for the length of the
  1338. Xoutput prefix to differ from the length of the
  1339. Xinput prefix.  Ditto for the suffix.  I may consider
  1340. Xadding this capability in a future release, but
  1341. Xright now I'm not sure how I'd want it to work.
  1342. X.SH BUGS
  1343. X.LP
  1344. XIf I knew of any bugs, I wouldn't release the package.  Of
  1345. Xcourse, there may be bugs that I haven't yet discovered.
  1346. X.LP
  1347. XIf you find any bugs (in the program or
  1348. Xin the documentation), or if you have
  1349. Xany suggestions, please send e-mail to:
  1350. X.RS
  1351. X.LP
  1352. Xamc@ecl.wustl.edu
  1353. X.RE
  1354. X.LP
  1355. Xor send paper mail to:
  1356. X.RS
  1357. X.LP
  1358. X.nf
  1359. XAdam M. Costello
  1360. XCampus Box 1045
  1361. XWashington University
  1362. XOne Brookings Dr.
  1363. XSt. Louis, MO 63130
  1364. XUSA
  1365. X.fi
  1366. X.RE
  1367. X.LP
  1368. XNote that both addresses could
  1369. Xchange anytime after June 1994.
  1370. X.LP
  1371. XWhen reporting a bug, please include the exact input and
  1372. Xcommand line options used, and the version number of
  1373. X.BR par ,
  1374. Xso that I can reproduce it.
  1375. END_OF_FILE
  1376. if test 33574 -ne `wc -c <'Par131/par.1'`; then
  1377.     echo shar: \"'Par131/par.1'\" unpacked with wrong size!
  1378. fi
  1379. # end of 'Par131/par.1'
  1380. fi
  1381. if test -f 'Par131/charset.h' -a "${1}" != "-c" ; then 
  1382.   echo shar: Will not clobber existing file \"'Par131/charset.h'\"
  1383. else
  1384. echo shar: Extracting \"'Par131/charset.h'\" \(1853 characters\)
  1385. sed "s/^X//" >'Par131/charset.h' <<'END_OF_FILE'
  1386. X/*********************/
  1387. X/* charset.h         */
  1388. X/* for Par 1.31      */
  1389. X/* Copyright 1993 by */
  1390. X/* Adam M. Costello  */
  1391. X/*********************/
  1392. X
  1393. X/* This is ANSI C code. */
  1394. X
  1395. X
  1396. X/* Note: Those functions declared here which do not use errmsg    */
  1397. X/* always succeed, provided that they are passed valid arguments. */
  1398. X
  1399. X
  1400. X#include "errmsg.h"
  1401. X
  1402. X
  1403. Xtypedef struct charset charset;
  1404. X
  1405. X
  1406. Xcharset *parsecharset(const char *str, errmsg_t errmsg);
  1407. X
  1408. X  /* parsecharset(str,errmsg) returns the set of characters defined by */
  1409. X  /* str using charset syntax (see par.doc).  Returns NULL on failure. */
  1410. X
  1411. X
  1412. Xvoid freecharset(charset *cset);
  1413. X
  1414. X  /* freecharset(cset) frees any memory associated with */
  1415. X  /* *cset.  cset may not be used after this call.      */
  1416. X
  1417. X
  1418. Xint csmember(char c, const charset *cset);
  1419. X
  1420. X  /* csmember(c,cset) returns 1 if c is a member of *cset, 0 otherwise. */
  1421. X
  1422. X
  1423. Xcharset *csunion(const charset *cset1, const charset *cset2, errmsg_t errmsg);
  1424. X
  1425. X  /* csunion(cset1,cset2) returns a pointer to the   */
  1426. X  /* union of *cset1 and *cset2, or NULL on failure. */
  1427. X
  1428. X
  1429. Xcharset *csdiff(const charset *cset1, const charset *cset2, errmsg_t errmsg);
  1430. X
  1431. X  /* csdiff(cset1,cset2) returns a pointer to the set */
  1432. X  /* difference *cset1 - *cset2 , or NULL on failure. */
  1433. X
  1434. X
  1435. Xvoid csadd(charset *cset1, const charset *cset2, errmsg_t errmsg);
  1436. X
  1437. X  /* csadd(cset1,cset2) adds the members of *cset2  */
  1438. X  /* to *cset1.  On failure, *cset1 is not changed. */
  1439. X
  1440. X
  1441. Xvoid csremove(charset *cset1, const charset *cset2, errmsg_t errmsg);
  1442. X
  1443. X  /* csremove(cset1,cset2) removes the members of *cset2 */
  1444. X  /* from *cset1.  On failure, *cset1 is not changed.    */
  1445. X
  1446. X
  1447. Xcharset *cscopy(const charset *cset, errmsg_t errmsg);
  1448. X
  1449. X  /* cscopy(cset) returns a copy of cset, or NULL on failure. */
  1450. X
  1451. X
  1452. Xvoid csswap(charset *cset1, charset *cset2);
  1453. X
  1454. X  /* csswap(cset1,cset2) swaps the contents of *cset1 and *cset2. */
  1455. END_OF_FILE
  1456. if test 1853 -ne `wc -c <'Par131/charset.h'`; then
  1457.     echo shar: \"'Par131/charset.h'\" unpacked with wrong size!
  1458. fi
  1459. # end of 'Par131/charset.h'
  1460. fi
  1461. if test -f 'Par131/charset.c' -a "${1}" != "-c" ; then 
  1462.   echo shar: Will not clobber existing file \"'Par131/charset.c'\"
  1463. else
  1464. echo shar: Extracting \"'Par131/charset.c'\" \(7372 characters\)
  1465. sed "s/^X//" >'Par131/charset.c' <<'END_OF_FILE'
  1466. X/*********************/
  1467. X/* charset.c         */
  1468. X/* for Par 1.31      */
  1469. X/* Copyright 1993 by */
  1470. X/* Adam M. Costello  */
  1471. X/*********************/
  1472. X
  1473. X/* This is ANSI C code. */
  1474. X
  1475. X
  1476. X/* Because this is ANSI C code, we can't assume that there are only 256 */
  1477. X/* characters.  Therefore, we can't use bit vectors to represent sets   */
  1478. X/* without the risk of consuming large amounts of memory.  Therefore,   */
  1479. X/* this code is much more complicated than might be expected.           */
  1480. X
  1481. X
  1482. X#include "charset.h"  /* Makes sure we're consistent with the.  */
  1483. X                      /* prototypes.  Also includes "errmsg.h". */
  1484. X#include "buffer.h"   /* Also includes <stddef.h>.              */
  1485. X
  1486. X#include <ctype.h>
  1487. X#include <string.h>
  1488. X#include <stdlib.h>
  1489. X#include <stdio.h>
  1490. X
  1491. X
  1492. X#undef NULL
  1493. X#define NULL ((void *) 0)
  1494. X
  1495. X#ifdef DONTFREE
  1496. X#define free(ptr)
  1497. X#endif
  1498. X
  1499. X
  1500. Xstruct charset {
  1501. X  char *inlist;   /* Characters in inlist are in the set.                */
  1502. X  char *outlist;  /* Characters in outlist are not in the set.           */
  1503. X                  /* inlist and outlist must have no common characters.  */
  1504. X                  /* inlist and outlist may be NULL, which acts like "". */
  1505. X  short flags;    /* Characters in neither list are in the set if they   */
  1506. X                  /* belong to any of the classes indicated by flags.    */
  1507. X};
  1508. X
  1509. X/* The following may be bitwise-OR'd together */
  1510. X/* to set the flags field of a charset:       */
  1511. X
  1512. Xstatic const short CS_UCASE = 1,  /* Includes all upper case letters. */
  1513. X                   CS_LCASE = 2,  /* Includes all lower case letters. */
  1514. X                   CS_DIGIT = 4,  /* Includes all decimal digits.     */
  1515. X                   CS_NUL   = 8;  /* Includes the NUL character.      */
  1516. X
  1517. X
  1518. Xstatic int appearsin(char c, const char *str)
  1519. X
  1520. X/* Returns 0 if c is '\0' or str is NULL or c     */
  1521. X/* does not appear in *str.  Otherwise returns 1. */
  1522. X{
  1523. X  return c && str && strchr(str,c);
  1524. X}
  1525. X
  1526. X
  1527. Xstatic int hexdigtoint(char c)
  1528. X
  1529. X/* Returns the value represented by the hexadecimal */
  1530. X/* digit c, or -1 if c is not a hexadecimal digit.  */
  1531. X{
  1532. X  const char *p, * const hexdigits = "0123456789ABCDEF";
  1533. X
  1534. X  if (!c) return -1;
  1535. X  p = strchr(hexdigits, toupper(c));
  1536. X  return p ? p - hexdigits : -1;
  1537. X
  1538. X  /* We can't do things like c - '0' or c - 'A' because we can't depend     */
  1539. X  /* on the order of the characters in ANSI C.  Nor can we do things like   */
  1540. X  /* hexdigtoint[c] because we don't know how large such an array might be. */
  1541. X}
  1542. X
  1543. X
  1544. Xcharset *parsecharset(const char *str, errmsg_t errmsg)
  1545. X{
  1546. X  charset *cset = NULL;
  1547. X  struct buffer *cbuf = NULL;
  1548. X  const char *p, * const singleescapes = "_sbqQx";
  1549. X  int hex1, hex2;
  1550. X  char ch;
  1551. X
  1552. X  cset = malloc(sizeof (charset));
  1553. X  if (!cset) {
  1554. X    strcpy(errmsg,outofmem);
  1555. X    goto pcserror;
  1556. X  }
  1557. X  cset->inlist = cset->outlist = NULL;
  1558. X  cset->flags = 0;
  1559. X
  1560. X  cbuf = newbuffer(sizeof (char), errmsg);
  1561. X  if (*errmsg) goto pcserror;
  1562. X
  1563. X  for (p = str;  *p;  ++p)
  1564. X    if (*p == '_') {
  1565. X      ++p;
  1566. X      if (appearsin(*p, singleescapes)) {
  1567. X        if      (*p == '_') ch = '_' ;
  1568. X        else if (*p == 's') ch = ' ' ;
  1569. X        else if (*p == 'b') ch = '\\';
  1570. X        else if (*p == 'q') ch = '\'';
  1571. X        else if (*p == 'Q') ch = '\"';
  1572. X        else /*  *p == 'x'  */ {
  1573. X          hex1 = hexdigtoint(p[1]);
  1574. X          hex2 = hexdigtoint(p[2]);
  1575. X          if (hex1 < 0  ||  hex2 < 0) goto pcsbadstr;
  1576. X          ch = 16 * hex1 + hex2;
  1577. X          p += 2;
  1578. X        }
  1579. X        if (!ch)
  1580. X          cset->flags |= CS_NUL;
  1581. X        else {
  1582. X          additem(cbuf, &ch, errmsg);
  1583. X          if (*errmsg) goto pcserror;
  1584. X        }
  1585. X      }
  1586. X      else {
  1587. X        if      (*p == 'A') cset->flags |= CS_UCASE;
  1588. X        else if (*p == 'a') cset->flags |= CS_LCASE;
  1589. X        else if (*p == '0') cset->flags |= CS_DIGIT;
  1590. X        else goto pcsbadstr;
  1591. X      }
  1592. X    }
  1593. X    else {
  1594. X      additem(cbuf,p,errmsg);
  1595. X      if (*errmsg) goto pcserror;
  1596. X    }
  1597. X  ch = '\0';
  1598. X  additem(cbuf, &ch, errmsg);
  1599. X  if (*errmsg) goto pcserror;
  1600. X  cset->inlist = copyitems(cbuf,errmsg);
  1601. X  if (*errmsg) goto pcserror;
  1602. X
  1603. Xpcscleanup:
  1604. X
  1605. X  if (cbuf) freebuffer(cbuf);
  1606. X  return cset;
  1607. X
  1608. Xpcsbadstr:
  1609. X
  1610. X  sprintf(errmsg, "Bad charset syntax: %.*s\n", errmsg_size - 22, str);
  1611. X
  1612. Xpcserror:
  1613. X
  1614. X  if (cset) freecharset(cset);
  1615. X  cset = NULL;
  1616. X  goto pcscleanup;
  1617. X}
  1618. X
  1619. X
  1620. Xvoid freecharset(charset *cset)
  1621. X{
  1622. X  if (cset->inlist) free(cset->inlist);
  1623. X  if (cset->outlist) free(cset->outlist);
  1624. X  free(cset);
  1625. X}
  1626. X
  1627. X
  1628. Xint csmember(char c, const charset *cset)
  1629. X{
  1630. X  return    appearsin(c, cset->inlist)
  1631. X         ||    !appearsin(c, cset->outlist)
  1632. X            && (    cset->flags & CS_LCASE && islower(c)
  1633. X                ||  cset->flags & CS_UCASE && isupper(c)
  1634. X                ||  cset->flags & CS_DIGIT && isdigit(c)
  1635. X                ||  cset->flags & CS_NUL   && !c         );
  1636. X}
  1637. X
  1638. X
  1639. Xstatic charset *csud(int u, const charset *cset1,
  1640. X                     const charset *cset2, errmsg_t errmsg)
  1641. X
  1642. X/* Returns the union of cset1 and cset2 if u is 1, or the set    */
  1643. X/* difference cset1 - cset2 if u is 0.  Returns NULL on failure. */
  1644. X{
  1645. X  charset *csu;
  1646. X  buffer *inbuf = NULL, *outbuf = NULL;
  1647. X  char *lists[4], **list, *p, nullchar = '\0';
  1648. X
  1649. X  csu = malloc(sizeof (charset));
  1650. X  if (!csu) {
  1651. X    strcpy(errmsg,outofmem);
  1652. X    goto csuderror;
  1653. X  }
  1654. X  inbuf = newbuffer(sizeof (char), errmsg);
  1655. X  if (*errmsg) goto csuderror;
  1656. X  outbuf = newbuffer(sizeof (char), errmsg);
  1657. X  if (*errmsg) goto csuderror;
  1658. X  csu->inlist = csu->outlist = NULL;
  1659. X  csu->flags =  u  ?  cset1->flags |  cset2->flags
  1660. X                   :  cset1->flags & ~cset2->flags;
  1661. X
  1662. X  lists[0] = cset1->inlist;
  1663. X  lists[1] = cset1->outlist;
  1664. X  lists[2] = cset2->inlist;
  1665. X  lists[3] = cset2->outlist;
  1666. X
  1667. X  for (list = lists;  list < lists + 4;  ++list)
  1668. X    for (p = *list;  *p;  ++p)
  1669. X      if (u  ?  csmember(*p, cset1) ||  csmember(*p, cset2)
  1670. X             :  csmember(*p, cset1) && !csmember(*p, cset2)) {
  1671. X        if (!csmember(*p, csu)) {
  1672. X          additem(inbuf,p,errmsg);
  1673. X          if (*errmsg) goto csuderror;
  1674. X        }
  1675. X      }
  1676. X      else
  1677. X        if (csmember(*p, csu)) {
  1678. X          additem(outbuf,p,errmsg);
  1679. X          if (*errmsg) goto csuderror;
  1680. X        }
  1681. X
  1682. X  additem(inbuf, &nullchar, errmsg);
  1683. X  if (*errmsg) goto csuderror;
  1684. X  additem(outbuf, &nullchar, errmsg);
  1685. X  if (*errmsg) goto csuderror;
  1686. X  csu->inlist = copyitems(inbuf,errmsg);
  1687. X  if (*errmsg) goto csuderror;
  1688. X  csu->outlist = copyitems(outbuf,errmsg);
  1689. X  if (*errmsg) goto csuderror;
  1690. X
  1691. Xcsudcleanup:
  1692. X
  1693. X  if (inbuf) freebuffer(inbuf);
  1694. X  if (outbuf) freebuffer(outbuf);
  1695. X  return csu;
  1696. X
  1697. Xcsuderror:
  1698. X
  1699. X  if (csu) freecharset(csu);
  1700. X  csu = NULL;
  1701. X  goto csudcleanup;
  1702. X}
  1703. X
  1704. X
  1705. Xcharset *csunion(const charset *cset1, const charset *cset2, errmsg_t errmsg)
  1706. X{
  1707. X  return csud(1,cset1,cset2,errmsg);
  1708. X}
  1709. X
  1710. X
  1711. Xcharset *csdiff(const charset *cset1, const charset *cset2, errmsg_t errmsg)
  1712. X{
  1713. X  return csud(0,cset1,cset2,errmsg);
  1714. X}
  1715. X
  1716. X
  1717. Xvoid csadd(charset *cset1, const charset *cset2, errmsg_t errmsg)
  1718. X{
  1719. X  charset *csu;
  1720. X
  1721. X  csu = csunion(cset1,cset2,errmsg);
  1722. X  if (*errmsg) return;
  1723. X  csswap(csu,cset1);
  1724. X  freecharset(csu);
  1725. X}
  1726. X
  1727. X
  1728. Xvoid csremove(charset *cset1, const charset *cset2, errmsg_t errmsg)
  1729. X{
  1730. X  charset *csu;
  1731. X
  1732. X  csu = csdiff(cset1,cset2,errmsg);
  1733. X  if (*errmsg) return;
  1734. X  csswap(csu,cset1);
  1735. X  freecharset(csu);
  1736. X}
  1737. X
  1738. X
  1739. Xcharset *cscopy(const charset *cset, errmsg_t errmsg)
  1740. X{
  1741. X  charset emptycharset = { NULL, NULL, 0 };
  1742. X
  1743. X  return csunion(cset, &emptycharset, errmsg);
  1744. X}
  1745. X
  1746. X
  1747. Xvoid csswap(charset *cset1, charset *cset2)
  1748. X{
  1749. X  charset tmp;
  1750. X
  1751. X  tmp = *cset1;
  1752. X  *cset1 = *cset2;
  1753. X  *cset2 = tmp;
  1754. X}
  1755. END_OF_FILE
  1756. if test 7372 -ne `wc -c <'Par131/charset.c'`; then
  1757.     echo shar: \"'Par131/charset.c'\" unpacked with wrong size!
  1758. fi
  1759. # end of 'Par131/charset.c'
  1760. fi
  1761. echo shar: End of shell archive.
  1762. exit 0
  1763.  
  1764. exit 0 # Just in case...
  1765.