home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / GNU / GPTX01AS.ZIP / GPTX.TI < prev    next >
Encoding:
Text File  |  1990-08-05  |  36.0 KB  |  860 lines

  1. @setfilename gptx.info
  2. Copyright @copyright{} 1990 Free Software Foundation, Inc.
  3. Francois Pinard <pinard@@iro.umontreal.ca>, 1988.
  4.  
  5. $Id$
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. This program is distributed in the hope that it will be useful, but
  13. WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.  
  22. @node Top, Usage, , (DIR)
  23. @section @code{gptx} - GNU permuted index generator
  24.  
  25. This is the GNU prerelease of @code{gptx}, a permuted index generator.
  26. This prerelease has the main goal of providing a @code{ptx}
  27. @emph{almost} compatible replacement, able to handle small files
  28. quickly, while providing a platform for more development.
  29.  
  30. This version reimplements and extends standard @code{ptx}.  In
  31. particular, it can produce a readable @dfn{KWIC} without the need of
  32. @code{nroff}.  This program does not repeat all @code{ptx} disposition
  33. quirks (but should it really do?).  Also, this version does not yet
  34. handle huge input files, that is, those files which do not fit in memory
  35. all at once.
  36.  
  37. @menu
  38. * Usage::    How to use the program, its options and parameters.
  39. * Regexps::    How a regular expression is written and used.
  40. * ptx mode::    In which ways @code{ptx} mode is different.
  41. * Future::    What are the development lines of this program.
  42. @end menu
  43.  
  44.  
  45. @node Usage, Regexps, Top, Top
  46. @subsection How to use this program
  47.  
  48. This tool reads a text file and essentially produces a permuted index, with
  49. each keyword in its context.  The calling sketch is one of:
  50.  
  51. @example
  52. gptx [@var{option}]@dots{} [@var{input}]@dots{} >@var{output}
  53. @end example
  54.  
  55. or:
  56.  
  57. @example
  58. ptx [@var{option}]@dots{} [@var{input} [@var{output}]]
  59. @end example
  60.  
  61. If the program is called as @code{ptx} instead of @code{gptx}, or if
  62. @code{-p} option is selected, this implies @code{ptx} compatibility
  63. mode, disallowing extensions, introducing some limitations, and changing
  64. several of the program's default option values.  See @xref{ptx mode} for
  65. a list of differences.
  66.  
  67. As usual, each option is represented by an hyphen followed by a single
  68. letter.  Some options require a parameter in the form of a decimal number
  69. or a file name, in which case the parameter follows the option after some
  70. whitespace.  Option letters may be grouped and tied together as a string
  71. which follows only one hyphen; if one of several of them require
  72. parameters, they should follow the combined options in the order of
  73. appearance of individual letters in the string.  Individual options are
  74. explained below.
  75.  
  76. When @emph{not} in @code{ptx} compatibility mode, there may be zero, one
  77. or several parameters after the options.  If there is no parameters, the
  78. program reads the standard input.  If there is one or several
  79. parameters, they give the name of input files, which are all read in
  80. turn; a little as if all the input files were concatenated.  However,
  81. there is a full contextual break between each file; and when automatic
  82. referencing is requested, file names and line numbers refer to
  83. individual text input files.  In all cases, the program produces the
  84. permuted index onto the standard output.
  85.   
  86. When in @code{ptx} compatibility mode, besides the options, there may be
  87. zero, one or two parameters.  If there is no parameters, the program
  88. reads the standard input and produces the permuted index onto the
  89. standard output.  If there is only one parameter, it names the text file
  90. to be read instead of the standard input.  If two parameters are given,
  91. they give respectively the name of the file to read and the name of the
  92. file to produce.
  93.  
  94. Note that for @emph{any} file named as the value of an option or as an
  95. input text file, a single dash @kbd{-} may be used, in which case
  96. standard input is assumed.  However, it would not make sense to use this
  97. convention more than once per program invocation.
  98.  
  99.  
  100. @menu
  101. * General options::    Options which affect general program behaviour.
  102. * Charset selection::    Underlying character set considerations.
  103. * Input processing::    Input fields, contexts, and keyword selection.
  104. * Output formatting::    Types of output format, and sizing the fields.
  105. @end menu
  106.  
  107.  
  108. @node General options, Charset selection, , Usage
  109. @subsubsection General options
  110.  
  111. @table @code
  112.  
  113. @item -p
  114. This requests @code{ptx} behaviour, as far as we understand it.  This
  115. option is selected by default when the program is installed under the
  116. name @code{ptx}.
  117.  
  118. This option is not available once the program is operating in @code{ptx}
  119. compatibility mode.
  120.  
  121. @item -C
  122. Prints a short note about the Copyright and copying conditions.
  123.  
  124. @end table
  125.  
  126.  
  127. @node Charset selection, Input processing, General options , Usage
  128. @subsubsection Charset selection
  129.  
  130. As it is setup now, the program assumes that the input file is coded
  131. using 8-bit ISO 8859-1 code, also known as Latin-1 character set,
  132. @emph{unless} if it is compiled for MS-DOS, in which case it uses the
  133. character set of the IBM-PC.  Compared to 7-bit ASCII, the set of
  134. characters which are letters is then different, this fact alters the
  135. behaviour of regular expression matching.  Thus, the default regular
  136. expression for a keyword allows foreign or diacriticized letters.
  137. Keyword sorting, however, is still crude; it obeys the underlying
  138. character set ordering quite blindly.
  139.  
  140. @table @code
  141.  
  142. @item -f
  143. Fold lower case letters to upper case for sorting.
  144.  
  145. @end table
  146.  
  147.  
  148. @node Input processing, Output formatting, Charset selection, Usage
  149. @subsubsection Word selection
  150.  
  151. @table @code
  152.  
  153. @item -b @var{file}
  154.  
  155. This option is an alternative way to option @code{-W} for describing
  156. which characters make up words.  This option introduces the name of a
  157. file which contains a list of characters which can@emph{not} be part of
  158. one word, this file is called the @dfn{Break file}.  Any character which
  159. is not part of the Break file is a word constituent.  If both options
  160. @code{-b} and @code{-W} are specified, then @code{-W} has precedence and
  161. @code{-b} is ignored.
  162.  
  163. In normal mode, the only way to avoid newline as a break character is to
  164. write all the break characters in the file with no newline at all, not
  165. even at the end of the file.  In @code{ptx} compatibility mode, spaces,
  166. tabs and newlines are always considered as break characters even if not
  167. included in the Break file.
  168.  
  169. @item -i @var{file}
  170.  
  171. The file associated with this option contains a list of words which will
  172. never be taken as keywords in concordance output.  It is called the
  173. @dfn{Ignore file}.  The file contains exactly one word in each line; the
  174. end of line separation of words is not subject to the value of the
  175. @code{-S} option.
  176.  
  177. If not specified, there might be a default Ignore file.  Default Ignore
  178. files are not necessarily the same in normal mode or in @code{ptx}
  179. compatibility mode.  Unless changed by the local installation, there is
  180. @emph{no} default Ignore file in normal mode, and the Ignore file is
  181. @code{/usr/lib/eign} in @code{ptx} compatibility mode.  If you want to
  182. deactivate a default Ignore file, use @code{/dev/null} instead.
  183.  
  184. @item -o @var{file}
  185.  
  186. The file associated with this option contains a list of words which will
  187. be retained in concordance output, any word not mentionned in this file
  188. is ignored.  The file is called the @dfn{Only file}.  The file contains
  189. exactly one word in each line; the end of line separation of words is
  190. not subject to the value of the @code{-S} option.
  191.  
  192. There is no default for the Only file.  In the case there are both an
  193. Only file and an Ignore file, a word will be subject to be a keyword
  194. only if it is given in the Only file and not given in the Ignore file.
  195.  
  196. @item -r
  197. On each input line, the leading sequence of non white characters will be
  198. taken to be a reference that has the purpose of identifying this input
  199. line on the produced permuted index.  See @xref{Output formatting} for
  200. more information about reference production.  Using this option change
  201. the default value for option @code{-S}.
  202.  
  203. Using this option, the program does not try very hard to remove
  204. references from contexts in output, but it succeeds in doing so
  205. @emph{when} the context ends exactly at the newline.  If option
  206. @code{-r} is used with @code{-S} default value, or when in @code{ptx}
  207. compatibility mode, this condition is always met and references are
  208. completely excluded from the output contexts.
  209.  
  210. @item -S @var{regexp}
  211. This option selects which regular expression will describe the end of a
  212. line or the end of a sentence.  In fact, there is other distinction
  213. between end of lines or end of sentences than the effect of this regular
  214. expression, and input line boundaries have no special significance
  215. outside this option.  By default, in @code{ptx} compatibility mode or if
  216. @code{-r} option is used, end of lines are used; in this case, the
  217. @var{regexp} used is very simple:
  218.  
  219. @example
  220. \n
  221. @end example
  222.  
  223. In normal mode and if @code{-r} option is not used, by default, end of
  224. sentences are used; the precise @var{regex} is imported from GNU emacs:
  225.  
  226. @example
  227. [.?!][]\"')@}]*\\($\\|\t\\|  \\)[ \t\n]*
  228. @end example
  229.  
  230. An empty REGEXP is equivalent to completly disabling end of line or end
  231. of sentence recognition.  In this case, the whole file is considered to
  232. be a single big line or sentence.  The user might want to disallow all
  233. truncation flag generation as well, through option @code{-F ""}.  On
  234. regular expression writing and usage, see @xref{Regexps}.
  235.  
  236. When the keywords happen to be near the beginning of the input line or
  237. sentence, this often creates an unused area at the beginning of the
  238. output context line; when the keywords happen to be near the end of the
  239. input line or sentence, this often creates an unused area at the end of
  240. the output context line.  The program tries to fill those unused areas
  241. by wrapping around context in them; the tail of the input line or
  242. sentence is used to fill the unused area on the left of the output line;
  243. the head of the input line or sentence is used to fill the unused area
  244. on the right of the output line.
  245.  
  246. This option is not available when the program is operating @code{ptx}
  247. compatibility mode.
  248.  
  249. @item -W @var{regexp}
  250. This option selects which regular expression will describe each keyword.
  251. By default, in @code{ptx} compatibility mode, a word is anything which
  252. ends with a space, a tab or a newline; the @var{regexp} used is @code{[^
  253. \t\n]+}.
  254.  
  255. In normal mode, a word is a sequence of letters; the
  256. @var{regexp} used is @code{\w+}.
  257.  
  258. An empty REGEXP is equivalent to not using this option, letting the
  259. default dive in.  On regular expression writing and usage, see
  260. @xref{Regexps}.
  261.  
  262. This option is not available when the program is operating @code{ptx}
  263. compatibility mode.
  264.  
  265. @end table
  266.  
  267.  
  268. @node Output formatting, , Input processing, Usage
  269. @subsubsection Output formatting
  270.  
  271. Output format is mainly controlled by @code{-O} and @code{-T} options,
  272. described in the table below.  However, when neither @code{-O} nor
  273. @code{-T} is selected, and if we are not running in @code{ptx}
  274. compatibility mode, the program choose an output format suited for a
  275. dumb terminal.  This is the default format when working in normal mode.
  276. Each keyword occurrence is output to the center of one line, surrounded
  277. by its left and rigth contexts.  Each field is properly justified, so
  278. the concordance output could readily be observed.  As a special feature,
  279. if automatic references are selected by option @code{-A} and are output
  280. before the left context, that is, if option @code{-R} is @emph{not}
  281. selected, then a colon is added after the reference; this nicely
  282. interface with GNU Emacs @code{next-error} processing.  In this default
  283. output format, each white space character, like newline and tab, is
  284. merely changed to exactly one space, with no special attempt to compress
  285. consecutive spaces.  This might change in the future.  Except for those
  286. white space characters, every other character of the underlying set of
  287. 256 characters is transmitted verbatim.
  288.  
  289. Output format is further controlled by the following options.
  290.  
  291. @table @code
  292.  
  293. @item -g @var{number}
  294. Select the size of the minimum white gap between the fields on the output
  295. line.
  296.  
  297. @item -w @var{number}
  298. Select the output maximum width of each final line.  If references are
  299. used, they are included or excluded from the output maximum width
  300. depending on the value of option @code{-R}.  If this option is not
  301. selected, that is, when references are output before the left context,
  302. the output maximum width takes into account the maximum length of all
  303. references.  If this options is selected, that is, when references are
  304. output after the right context, the output maximum width does not take
  305. into account the space taken by references, nor the gap that precedes
  306. them.
  307.  
  308. @item -A
  309. Select automatic references.  Each input line will have an automatic
  310. reference made up of the file name, an open parenthesis, the line
  311. ordinal and a close parenthesis.  However, the file name will be empty
  312. when standard input is being read.  If both @code{-A} and @code{-r} are
  313. selected, then the input reference is still read and skipped, but the
  314. automatic reference is used at output time, overriding the input
  315. reference.
  316.  
  317. This option is not available when the program is operating @code{ptx}
  318. compatibility mode.
  319.  
  320. @item -R
  321. In default output format, when option @code{-R} is not used, any
  322. reference produced by the effect of options @code{-r} or @code{-A} are
  323. given to the far right of output lines, after the right context.  In
  324. default output format, when option @code{-R} is specified, references
  325. are rather given to the beginning of each output line, before the left
  326. context.  For any other output format, option @code{-R} is almost
  327. ignored, except for the fact that the width of references is @emph{not}
  328. taken into account in total output width given by @code{-w} whenever
  329. @code{-R} is selected.
  330.  
  331. This option is not explicitely selectable when the program is operating
  332. in @code{ptx} compatibility mode.  However, in this case, it is always
  333. implicitely selected.
  334.  
  335. @item -F @var{string}
  336. This option will request that any truncation in the output be reported
  337. using the string @var{string}.  Most output fields theoretically extend
  338. towards the beginning or the end of the current line, or current
  339. sentence, as selected with option @code{-S}.  But there is a maximum
  340. allowed output line width, changeable through option @code{-w}, which is
  341. further divided into space for various output fields.  When a field has
  342. to be truncated because cannot extend until the beginning or the end of
  343. the current line to fit in the, then a truncation occurs.  By default,
  344. the string used is a single slash, as in @code{-F /}.
  345.  
  346. @var{string} may have more than one character, as in @code{-F ...}.
  347. Also, in the particular case @var{string} is empty (@code{-F ""}),
  348. truncation flagging is disabled, and no truncation marks are appended in
  349. this case.
  350.  
  351. This option is not available when the program is operating @code{ptx}
  352. compatibility mode.
  353.  
  354. @item -O
  355. Choose an output format suitable for @code{nroff} or @code{troff}
  356. processing.  Each output line will look like:
  357.  
  358. @example
  359. .xx "@var{tail}" "@var{before}" "@var{keyword_and_after}" "@var{head}" "@var{ref}"
  360. @end example
  361.  
  362. so it will be possible to write an @samp{.xx} roff macro to take care of
  363. the output typesetting.  This is the default output format when working
  364. in @code{ptx} compatibility mode.
  365.  
  366. In this output format, each non-graphical character, like newline and
  367. tab, is merely changed to exactly one space, with no special attempt to
  368. compress consecutive spaces.  Each quote character: @kbd{"} is doubled
  369. so it will be correctly processed by @code{nroff} or @code{troff}.  All
  370. characters having their eight bit set are turned into spaces in this
  371. version.  It is expectable that diacriticized characters will be
  372. correctly expressed in @code{roff} terms if I learn how to do this.  So,
  373. let me know how to improve this special character processing.
  374.  
  375. This option is not available when the program is operating @code{ptx}
  376. compatibility mode.  In fact, it then becomes the default and sole output
  377. format.
  378.  
  379. @item -T
  380. Choose an output format suitable for @TeX{} processing.  Each output
  381. line will look like:
  382.  
  383. @example
  384. \xx @{@var{tail}@}@{@var{before}@}@{@var{keyword}@}@{@var{after}@}@{@var{head}@}@{@var{ref}@}
  385. @end example
  386.  
  387. @noindent
  388. so it will be possible to write write a @code{\xx} definition to take
  389. care of the output typesetting.  Note that when references are not being
  390. produced, that is, neither option @code{-A} nor option @code{-r} is
  391. selected, the last parameter of each @code{\xx} call is inhibited.
  392.  
  393. In this output format, some special characters, like @kbd{$}, @kbd{%},
  394. @kbd{&}, @kbd{#} and @kbd{_} are automatically protected with a
  395. backslash.  Curly brackets @kbd{@{}, @kbd{@}} are also protected with a
  396. backslash, but also enclosed in a pair of dollar signs to force
  397. mathematical mode.  The backslash itself produces the sequence
  398. @code{\backslash@{@}}.  Circumflex and tilde diacritics produce the
  399. sequence @code{^\@{ @}} and @code{~\@{ @}} respectively.  Other
  400. diacriticized characters of the underlying character set produce an
  401. appropriate @TeX{} sequence as far as possible.  The other non-graphical
  402. characters, like newline and tab, and all others characters which are
  403. not part of ASCII, are merely changed to exactly one space, with no
  404. special attempt to compress consecutive spaces.  Let me know how to
  405. improve this special character processing for @TeX{}.
  406.  
  407. This option is not available when the program is operating @code{ptx}
  408. compatibility mode.
  409.  
  410. @end table
  411.  
  412.  
  413. @node Regexps, ptx mode, Usage, Top
  414. @subsection Syntax of Regular Expressions
  415.  
  416. @c This node is taken from the GNU emacs 18.55 manual.  The best thing
  417. @c would be that it is linked from here.  But, to obviate various usages
  418. @c in installation, it is simpler to take a mere copy of it for now.
  419. @c
  420. @c I also removed \s@var{code} and \S@var{code} documentation, which is
  421. @c not compiled into regex.c, and the reference to GNU emacs Syntax
  422. @c node.  Some references to the Emacs buffer should be changed too.
  423.  
  424. Regular expressions have a syntax in which a few characters are special
  425. constructs and the rest are @dfn{ordinary}.  An ordinary character is a
  426. simple regular expression which matches that character and nothing else.
  427. The special characters are @samp{$}, @samp{^}, @samp{.}, @samp{*},
  428. @samp{+}, @samp{?}, @samp{[}, @samp{]} and @samp{\}; no new special
  429. characters will be defined.  Any other character appearing in a regular
  430. expression is ordinary, unless a @samp{\} precedes it.@refill
  431.  
  432. For example, @samp{f} is not a special character, so it is ordinary, and
  433. therefore @samp{f} is a regular expression that matches the string @samp{f}
  434. and no other string.  (It does @i{not} match the string @samp{ff}.)  Likewise,
  435. @samp{o} is a regular expression that matches only @samp{o}.@refill
  436.  
  437. Any two regular expressions @var{a} and @var{b} can be concatenated.  The
  438. result is a regular expression which matches a string if @var{a} matches
  439. some amount of the beginning of that string and @var{b} matches the rest of
  440. the string.@refill
  441.  
  442. As a simple example, we can concatenate the regular expressions @samp{f}
  443. and @samp{o} to get the regular expression @samp{fo}, which matches only
  444. the string @samp{fo}.  Still trivial.  To do something nontrivial, you
  445. need to use one of the special characters.  Here is a list of them.
  446.  
  447. @table @kbd
  448. @item .@: @r{(Period)}
  449. is a special character that matches any single character except a newline.
  450. Using concatenation, we can make regular expressions like @samp{a.b} which
  451. matches any three-character string which begins with @samp{a} and ends with
  452. @samp{b}.@refill
  453.  
  454. @item *
  455. is not a construct by itself; it is a suffix, which means the
  456. preceding regular expression is to be repeated as many times as
  457. possible.  In @samp{fo*}, the @samp{*} applies to the @samp{o}, so
  458. @samp{fo*} matches one @samp{f} followed by any number of @samp{o}s.
  459. The case of zero @samp{o}s is allowed: @samp{fo*} does match
  460. @samp{f}.@refill
  461.  
  462. @samp{*} always applies to the @i{smallest} possible preceding
  463. expression.  Thus, @samp{fo*} has a repeating @samp{o}, not a
  464. repeating @samp{fo}.@refill
  465.  
  466. The matcher processes a @samp{*} construct by matching, immediately,
  467. as many repetitions as can be found.  Then it continues with the rest
  468. of the pattern.  If that fails, backtracking occurs, discarding some
  469. of the matches of the @samp{*}-modified construct in case that makes
  470. it possible to match the rest of the pattern.  For example, matching
  471. @samp{ca*ar} against the string @samp{caaar}, the @samp{a*} first
  472. tries to match all three @samp{a}s; but the rest of the pattern is
  473. @samp{ar} and there is only @samp{r} left to match, so this try fails.
  474. The next alternative is for @samp{a*} to match only two @samp{a}s.
  475. With this choice, the rest of the regexp matches successfully.@refill
  476.  
  477. @item +
  478. Is a suffix character similar to @samp{*} except that it requires that
  479. the preceding expression be matched at least once.  So, for example,
  480. @samp{ca+r} will match the strings @samp{car} and @samp{caaaar}
  481. but not the string @samp{cr}, whereas @samp{ca*r} would match all
  482. three strings.@refill
  483.  
  484. @item ?
  485. Is a suffix character similar to @samp{*} except that it can match the
  486. preceding expression either once or not at all.  For example,
  487. @samp{ca?r} will match @samp{car} or @samp{cr}; nothing else.
  488.  
  489. @item [ @dots{} ]
  490. @samp{[} begins a @dfn{character set}, which is terminated by a
  491. @samp{]}.  In the simplest case, the characters between the two form
  492. the set.  Thus, @samp{[ad]} matches either one @samp{a} or one
  493. @samp{d}, and @samp{[ad]*} matches any string composed of just
  494. @samp{a}s and @samp{d}s (including the empty string), from which it
  495. follows that @samp{c[ad]*r} matches @samp{cr}, @samp{car}, @samp{cdr},
  496. @samp{caddaar}, etc.@refill
  497.  
  498. Character ranges can also be included in a character set, by writing
  499. two characters with a @samp{-} between them.  Thus, @samp{[a-z]}
  500. matches any lower-case letter.  Ranges may be intermixed freely with
  501. individual characters, as in @samp{[a-z$%.]}, which matches any lower
  502. case letter or @samp{$}, @samp{%} or period.@refill
  503.  
  504. Note that the usual special characters are not special any more inside
  505. a character set.  A completely different set of special characters
  506. exists inside character sets: @samp{]}, @samp{-} and @samp{^}.@refill
  507.  
  508. To include a @samp{]} in a character set, you must make it the first
  509. character.  For example, @samp{[]a]} matches @samp{]} or @samp{a}.  To
  510. include a @samp{-}, write @samp{---}, which is a range containing only
  511. @samp{-}.  To include @samp{^}, make it other than the first character
  512. in the set.@refill
  513.  
  514. @item [^ @dots{} ]
  515. @samp{[^} begins a @dfn{complement character set}, which matches any
  516. character except the ones specified.  Thus, @samp{[^a-z0-9A-Z]}
  517. matches all characters @i{except} letters and digits.@refill
  518.  
  519. @samp{^} is not special in a character set unless it is the first
  520. character.  The character following the @samp{^} is treated as if it
  521. were first (@samp{-} and @samp{]} are not special there).
  522.  
  523. Note that a complement character set can match a newline, unless
  524. newline is mentioned as one of the characters not to match.
  525.  
  526. @item ^
  527. is a special character that matches the empty string, but only if at
  528. the beginning of a line in the text being matched.  Otherwise it fails
  529. to match anything.  Thus, @samp{^foo} matches a @samp{foo} which occurs
  530. at the beginning of a line.
  531.  
  532. @item $
  533. is similar to @samp{^} but matches only at the end of a line.  Thus,
  534. @samp{xx*$} matches a string of one @samp{x} or more at the end of a line.
  535.  
  536. @item \
  537. has two functions: it quotes the special characters (including
  538. @samp{\}), and it introduces additional special constructs.
  539.  
  540. Because @samp{\} quotes special characters, @samp{\$} is a regular
  541. expression which matches only @samp{$}, and @samp{\[} is a regular
  542. expression which matches only @samp{[}, and so on.@refill
  543. @end table
  544.  
  545. Note: for historical compatibility, special characters are treated as
  546. ordinary ones if they are in contexts where their special meanings make no
  547. sense.  For example, @samp{*foo} treats @samp{*} as ordinary since there is
  548. no preceding expression on which the @samp{*} can act.  It is poor practice
  549. to depend on this behavior; better to quote the special character anyway,
  550. regardless of where is appears.@refill
  551.  
  552. For the most part, @samp{\} followed by any character matches only
  553. that character.  However, there are several exceptions: characters
  554. which, when preceded by @samp{\}, are special constructs.  Such
  555. characters are always ordinary when encountered on their own.  Here
  556. is a table of @samp{\} constructs.
  557.  
  558. @table @kbd
  559. @item \|
  560. specifies an alternative.
  561. Two regular expressions @var{a} and @var{b} with @samp{\|} in
  562. between form an expression that matches anything that either @var{a} or
  563. @var{b} will match.@refill
  564.  
  565. Thus, @samp{foo\|bar} matches either @samp{foo} or @samp{bar}
  566. but no other string.@refill
  567.  
  568. @samp{\|} applies to the largest possible surrounding expressions.  Only a
  569. surrounding @samp{\( @dots{} \)} grouping can limit the grouping power of
  570. @samp{\|}.@refill
  571.  
  572. Full backtracking capability exists to handle multiple uses of @samp{\|}.
  573.  
  574. @item \( @dots{} \)
  575. is a grouping construct that serves three purposes:
  576.  
  577. @enumerate
  578. @item
  579. To enclose a set of @samp{\|} alternatives for other operations.
  580. Thus, @samp{\(foo\|bar\)x} matches either @samp{foox} or @samp{barx}.
  581.  
  582. @item
  583. To enclose a complicated expression for the postfix @samp{*} to operate on.
  584. Thus, @samp{ba\(na\)*} matches @samp{bananana}, etc., with any (zero or
  585. more) number of @samp{na} strings.@refill
  586.  
  587. @item
  588. To mark a matched substring for future reference.
  589.  
  590. @end enumerate
  591.  
  592. This last application is not a consequence of the idea of a
  593. parenthetical grouping; it is a separate feature which happens to be
  594. assigned as a second meaning to the same @samp{\( @dots{} \)} construct
  595. because there is no conflict in practice between the two meanings.
  596. Here is an explanation of this feature:
  597.  
  598. @item \@var{digit}
  599. after the end of a @samp{\( @dots{} \)} construct, the matcher remembers the
  600. beginning and end of the text matched by that construct.  Then, later on
  601. in the regular expression, you can use @samp{\} followed by @var{digit}
  602. to mean ``match the same text matched the @var{digit}'th time by the
  603. @samp{\( @dots{} \)} construct.''@refill
  604.  
  605. The strings matching the first nine @samp{\( @dots{} \)} constructs appearing
  606. in a regular expression are assigned numbers 1 through 9 in order that the
  607. open-parentheses appear in the regular expression.  @samp{\1} through
  608. @samp{\9} may be used to refer to the text matched by the corresponding
  609. @samp{\( @dots{} \)} construct.
  610.  
  611. For example, @samp{\(.*\)\1} matches any newline-free string that is
  612. composed of two identical halves.  The @samp{\(.*\)} matches the first
  613. half, which may be anything, but the @samp{\1} that follows must match
  614. the same exact text.
  615.  
  616. @item \`
  617. matches the empty string, provided it is at the beginning
  618. of the buffer.
  619.  
  620. @item \'
  621. matches the empty string, provided it is at the end of
  622. the buffer.
  623.  
  624. @item \b
  625. matches the empty string, provided it is at the beginning or
  626. end of a word.  Thus, @samp{\bfoo\b} matches any occurrence of
  627. @samp{foo} as a separate word.  @samp{\bballs?\b} matches
  628. @samp{ball} or @samp{balls} as a separate word.@refill
  629.  
  630. @item \B
  631. matches the empty string, provided it is @i{not} at the beginning or
  632. end of a word.
  633.  
  634. @item \<
  635. matches the empty string, provided it is at the beginning of a word.
  636.  
  637. @item \>
  638. matches the empty string, provided it is at the end of a word.
  639.  
  640. @item \w
  641. matches any word-constituent character.  The editor syntax table
  642. determines which characters these are.
  643.  
  644. @item \W
  645. matches any character that is not a word-constituent.
  646. @end table
  647.  
  648.   Here is a complicated regexp, used by Emacs to recognize the end of a
  649. sentence together with any whitespace that follows.  It is given in Lisp
  650. syntax to enable you to distinguish the spaces from the tab characters.  In
  651. Lisp syntax, the string constant begins and ends with a double-quote.
  652. @samp{\"} stands for a double-quote as part of the regexp, @samp{\\} for a
  653. backslash as part of the regexp, @samp{\t} for a tab and @samp{\n} for a
  654. newline.
  655.  
  656. @example
  657. "[.?!][]\"')]*\\($\\|\t\\|  \\)[ \t\n]*"
  658. @end example
  659.  
  660. @noindent
  661. This contains four parts in succession: a character set matching period,
  662. @samp{?} or @samp{!}; a character set matching close-brackets,
  663. quotes or parentheses, repeated any number of times; an alternative in
  664. backslash-parentheses that matches end-of-line, a tab or two spaces; and a
  665. character set matching whitespace characters, repeated any number of times.
  666.  
  667.  
  668. @node ptx mode, Future, Regexps, Top
  669. @subsection @code{ptx} compatibility mode
  670.  
  671. This section outlines the differences between this program and standard
  672. @code{ptx}.  There is also a @code{ptx} compatibility mode in this
  673. program which is activated implicitely when the program is called under
  674. the name @code{ptx} or explicitely through the usage of option
  675. @code{-p}.  For someone used to standard @code{ptx}, here are some
  676. points worth noticing when not using @code{ptx} compatibility mode:
  677.  
  678. @itemize @bullet
  679.  
  680. @item
  681. In normal mode, concordance output is not formatted for @code{troff} or
  682. @code{nroff}.  By default, output is rather formatted for a dumb
  683. terminal.  @code{troff} or @code{nroff} output may still be selected
  684. through option @code{-O}.
  685.  
  686. @item
  687. In normal mode, unless @code{-R} option is used, the maximum reference
  688. width is subtracted from the total output line width.  In @code{ptx}
  689. compatibility mode, width of references are not taken into account in
  690. the output line width computations.
  691.  
  692. @item
  693. In normal mode, all 256 characters, even @kbd{NUL}s, are read and
  694. processed from input file with no adverse effect.  No attempt is made to
  695. limit this in @code{ptx} compatibility mode.  However, standard
  696. @code{ptx} does not accept 8-bit characters, a few control characters
  697. are rejected, and the tilde @kbd{~} is condemned.
  698.  
  699. @item
  700. In normal mode, input lines may be of infinite length.  No attempt is
  701. made to limit this in @code{ptx} compatibility mode.  However, standard
  702. @code{ptx} processes only the first 200 characters in each line.
  703.  
  704. @item
  705. In normal mode, the break (non-word) characters default to be every
  706. character except letters.  In @code{ptx} compatibility mode, the break
  707. characters default to space, tab and newline only.
  708.  
  709. @item
  710. In some circumstances, output lines are filled a little more completely
  711. in normal mode than in @code{ptx} compatibility mode.  Even in
  712. @code{ptx} mode, there are some slight disposition glitches this
  713. program does not completely reproduce, even if it comes quite close.
  714.  
  715. @item
  716. The Ignore file default in @code{ptx} compatibility mode is not the same
  717. as in normal mode.  In default installation, default Ignore files are
  718. @file{/usr/lib/eign} in @code{ptx} compatibility mode, and nothing in
  719. normal mode.
  720.  
  721. @item
  722. Standard @code{ptx} disallows specifying both the Ignore file and the
  723. Only file at the same time.  This version allows both, and specifying an
  724. Only file does not inhibit processing the Ignore file.
  725.  
  726. @end itemize
  727.  
  728.  
  729. @node Future, , ptx mode, Top
  730. @subsection Development guidelines
  731.  
  732. This should evolve towards a concordance package for GNU, able to tackle
  733. true, real, big concordance jobs, while being fast and of easy use for
  734. little jobs.  The start point is standard @code{ptx}.  Because several
  735. packages of this kind are awfully slow, I should reasonnably try to keep
  736. speed in mind.  On the other end, I do not want to burden myself too
  737. much about interactive query for now; so, a future reorientation along
  738. this topic might require some work.
  739.  
  740. Here is a @emph{What To Do Next} list, in expected execution order.
  741.  
  742. @enumerate
  743.  
  744. @item
  745. Increase short term usability:
  746.  
  747. @itemize @bullet
  748.  
  749. @item
  750. Support the program for the GNU community.  As directed by user
  751. comments, test and debug the whole thing more fully, and on bigger
  752. examples.  Solve portability glitches as long as this do not induce too
  753. ugly things in the code.
  754.  
  755. @item
  756. Provide sample macros in the documentation.
  757.  
  758. @item
  759. Understand and mimic `-t' option, if I can.
  760.  
  761. @item
  762. See how TeX mode could be made more useful, and if a texinfo mode would
  763. mean something to someone.
  764.  
  765. @item
  766. Sort keywords intelligently for Latin-1 code.  See how to interface this
  767. character set with various output formats.  Also, introduce options to
  768. inverse-sort and possibly to reverse-sort.
  769.  
  770. @item
  771. Improve speed for Ignore and Only tables.  Consider hashing instead of
  772. sorting.  Consider playing with obstacks to digest them.
  773.  
  774. @item
  775. Provide better handling of format effectors obtained from input, and
  776. also attempt white space compression on output which would still
  777. maximize full output width usage.
  778.  
  779. @end itemize
  780.  
  781. @item
  782. Provide multiple language support.
  783.  
  784. Most of the boosting work should go along the line of fast recognition
  785. of multiple and complex boundaries, which define various `languages'.
  786. Each such language has its own rules for words, sentences, paragraphs,
  787. and reporting requests.  This is less difficult than I first thought:
  788.  
  789. @itemize @bullet
  790.  
  791. @item
  792. Learn how to use getopt, or write something if necessary.  Recognize
  793. language modifiers with each option.  At least -b, -i, -o, -W, -S, and
  794. also new language switcher options, will have such modifiers.  Modifiers
  795. on language switchers will allow or disallow language transitions.
  796.  
  797. @item
  798. Complete the transformation of underlying variables into arrays in the
  799. code.
  800.  
  801. @item
  802. Implement a heap of positions in the input file.  There is one entry in
  803. the heap for each compiled regexp; it is initialized by a re_search
  804. after each regexp compile.  Regexps reschedule themselves in the heap
  805. when their position passes while scanning input.  In this way, looking
  806. simultaneously for a lot of regexps should not be too inefficient, once
  807. the scanning starts.  If this works ok, maybe consider accepting regexps
  808. in Only and Ignore tables.
  809.  
  810. @item
  811. Merge with language processing boundary processing options, really
  812. integrating -S processing as a special case.  Maybe, implement several
  813. level of boundaries.  See how to implement a stack of languages, for
  814. handling quotations.  See if more sophisticated references could be
  815. handled as another special case of a language.
  816.  
  817. @end itemize
  818.  
  819. @item
  820. Tackle other aspects, in a more long term view:
  821.  
  822. @itemize @bullet
  823.  
  824. @item
  825. Add options for statistics, frequency lists, referencing, and all other
  826. prescreening tools and subsidiary tasks of concordance production.
  827.  
  828. @item
  829. Develop an interactive mode.  Even better, construct a GNU emacs
  830. interface.  I'm looking at Gene Myers <gene@@cs.arizona.edu> suffix
  831. arrays as a possible implementation along those ideas.
  832.  
  833. @item
  834. Implement hooks so word classification and tagging should be merged in.
  835. See how to effectively hook in lemmatisation or other morphological
  836. features.  It is far from being clear by now how to interface this
  837. correctly, so some experimentation is mandatory.
  838.  
  839. @item
  840. Profile and speed up the whole thing.
  841.  
  842. @item
  843. Make it work on small address space machines.  Consider three levels of
  844. hugeness for files, and three corresponding algorithms to make optimal
  845. use of memory.  The first case is when all the input files and all the
  846. word references fit in memory: this is the case currently implemented.
  847. The second case is when the files cannot fit all together in memory, but
  848. the word references do.  The third case is when even the word references
  849. cannot fit in memory.
  850.  
  851. @item
  852. There also are subsidiary developments for in-core incremental sort
  853. routines as well as for a huge external sort package.  The need for more
  854. flexible sort packages comes partly from the fact that linguists use
  855. kinds of keys which compare in unusual and more sophisticated ways.
  856.  
  857. @end itemize
  858.  
  859. @end enumerate
  860.