home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2950 < prev    next >
Encoding:
Internet Message Format  |  1991-03-04  |  44.9 KB

  1. From: lee@sq.sq.com (Liam R. E. Quin)
  2. Newsgroups: alt.sources
  3. Subject: lq-text Full Text Retrieval Database Part 02/13
  4. Message-ID: <1991Mar4.020107.16142@sq.sq.com>
  5. Date: 4 Mar 91 02:01:07 GMT
  6.  
  7.  
  8. : cut here --- cut here --
  9. : To unbundle, sh this file
  10. #! /bin/sh
  11. : part 02
  12. echo x - lq-text/src/filters/Makefile 1>&2
  13. sed 's/^X//' >lq-text/src/filters/Makefile <<'@@@End of lq-text/src/filters/Makefile'
  14. X# filters/Makefile -- Copyright 1990 Liam R. Quin.  All Rights Reserved.
  15. X# This code is NOT in the public domain.
  16. X# See the file ../COPYRIGHT for full details.
  17. X
  18. X# This Makefile belongs in the "src/filters" directory.
  19. X#
  20. X# Note that most of the actual configuration is done in ../Makefile and
  21. X# in ../h/global.h, and not here.
  22. X
  23. X# $Id: Makefile,v 1.4 90/10/06 00:57:26 lee Rel $
  24. X
  25. X
  26. X# This is what gets made:
  27. XTARGETS = MailFilter NewsFilter
  28. XLIBFILES=$(TARGETS)
  29. XEXTRA=-DMAILFILTER='$(MAILFILTER)' -DNEWSFILTER='$(NEWSFILTER)' $(EXTRA)
  30. X
  31. XSRCS = FilterMain.c FilterType.c MailFilter.c NewsFilter.c
  32. XOBJS = FilterMain.o FilterType.o MailFilter.o NewsFilter.o
  33. X
  34. XPWD=filters
  35. X
  36. XDESTDIR=../lib
  37. XLQ=../lib/liblq.a
  38. XMODE=755
  39. X
  40. X# for compiling:
  41. XEXTRA=-I../h
  42. XRANLIB=echo
  43. X
  44. Xall: $(TARGETS)
  45. X
  46. Xsaber_src:
  47. X    echo $(PWD)
  48. X    #cd $(PWD)
  49. X    #load $(CFLAGS) $(SRCS)
  50. X    #cd ..
  51. X
  52. Xsaber_obj:
  53. X    #cd $(PWD)
  54. X    #load $(CFLAGS) $(SRCS)
  55. X    #cd ..
  56. X
  57. Xinstall: all
  58. X    for i in $(LIBFILES); do cp "$$i" $(DESTDIR); \
  59. X    strip "$(DESTDIR)/$$i" ; \
  60. X    chmod $(MODE) "$(DESTDIR)/$$i" ; \
  61. X    done
  62. X
  63. Xtidy:
  64. X    /bin/rm -f *.o core m.log tags
  65. X
  66. Xclean: tidy
  67. X    /bin/rm -f $(TARGETS) $(TEST)
  68. X
  69. Xdepend:
  70. X    mkdep $(CFLAGS) *.c
  71. X
  72. XCFilter: FilterMain.o CFilter.o
  73. X    $(CC) $(CFLAGS) -o CFilter FilterMain.o CFilter.o $(MALLOC) $(LQ)
  74. X
  75. XNewsFilter: FilterMain.o NewsFilter.o
  76. X    $(CC) $(CFLAGS) -o NewsFilter FilterMain.o NewsFilter.o $(MALLOC) $(LQ)
  77. X
  78. XMailFilter: FilterMain.o MailFilter.o
  79. X    $(CC) $(CFLAGS) -o MailFilter FilterMain.o MailFilter.o $(MALLOC) $(LQ)
  80. X
  81. XCDMSFilter: FilterMain.o CDMSFilter.o
  82. X    $(CC) $(CFLAGS) -o CDMSFilter FilterMain.o CDMSFilter.o $(MALLOC) $(LQ)
  83. X
  84. X#
  85. X# $Log:    Makefile,v $
  86. X# Revision 1.4  90/10/06  00:57:26  lee
  87. X# Prepared for first beta release.
  88. X# 
  89. X# Revision 1.3  90/10/03  21:14:45  lee
  90. X# Added MAILFILTER stuff.
  91. X# 
  92. X# Revision 1.2  90/09/28  21:54:43  lee
  93. X# No longer uses OWNER.
  94. X# 
  95. X# Revision 1.1  90/08/09  19:17:58  lee
  96. X# Initial revision
  97. X# DO NOT PUT ANYTHING AFTER THIS LINE
  98. X# DO NOT DELETE THIS LINE -- mkdep uses it.
  99. X# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
  100. X
  101. XFilterMain.o: FilterMain.c
  102. XMailFilter.o: MailFilter.c /usr/include/malloc.h
  103. XMailFilter.o: ../h/wordrules.h ../h/emalloc.h
  104. XNewsFilter.o: NewsFilter.c 
  105. XNewsFilter.o: ../h/wordrules.h ../h/emalloc.h
  106. XTroffFilter.o: TroffFilter.c 
  107. XTroffFilter.o: ../h/wordrules.h ../h/emalloc.h
  108. X
  109. X# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
  110. @@@End of lq-text/src/filters/Makefile
  111. echo x - lq-text/src/filters/NewsFilter.c 1>&2
  112. sed 's/^X//' >lq-text/src/filters/NewsFilter.c <<'@@@End of lq-text/src/filters/NewsFilter.c'
  113. X/* NewsFilter.c -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  114. X * This code is NOT in the public domain.
  115. X * See the file COPYRIGHT for full details.
  116. X */
  117. X
  118. X/* $Id: NewsFilter.c,v 1.5 90/10/06 00:57:27 lee Rel1-10 $
  119. X */
  120. X
  121. X/* Filter for usenet articles.
  122. X * Throw away all of the header except
  123. X * Subject
  124. X * From
  125. X * Organi[sz]ation
  126. X *
  127. X * Probably ought to keep Message-ID, but I can't store it anyway!
  128. X *
  129. X * See FilterMain and wordrules.h for more info.
  130. X *
  131. X */
  132. X
  133. X#ifdef SYSV
  134. X extern int _filbuf(), _flsbuf(); /* for lint! */
  135. X#endif
  136. X#include <stdio.h>
  137. X#include <malloc.h>
  138. X#include <ctype.h>
  139. X#include "wordrules.h"
  140. X
  141. X#include "emalloc.h"
  142. X
  143. X#define STREQ(boy, girl) ((*(boy) == *(girl)) && !strcmp(boy, girl))
  144. X
  145. X/** C Library functions that need to be declared: **/
  146. X#ifndef tolower
  147. X extern int tolower();
  148. X#endif
  149. Xextern int strcmp();
  150. X/** Functions in this file that need to be declared **/
  151. Xint GetChar();
  152. Xvoid Header(), Body();
  153. X/** **/
  154. X
  155. Xextern char *progname;
  156. Xvoid Filter();
  157. X
  158. Xchar *KeepThese[] = { /* these must be sorted on the first character */
  159. X    "from",
  160. X    "keywords",
  161. X    "summary",
  162. X    "subject",
  163. X    "organisation",
  164. X    "organization",
  165. X    0
  166. X};
  167. X
  168. Xint icstreq(s1, s2) /* case insensitive strcmp */
  169. X    char *s1, *s2;
  170. X{
  171. X    register char ch1, ch2;
  172. X
  173. X    while (*s1 && *s2) {
  174. X    if (*s1 != *s2) {
  175. X        if (isupper(*s1)) {
  176. X        ch1 = tolower(*s1);
  177. X        ch2 = (*s2);
  178. X        } else if (isupper(*s2)) {
  179. X        /* Note that we only have to test one character for case! */
  180. X        ch1 = (*s1);
  181. X        ch2 = tolower(*s2);
  182. X        } else {
  183. X        return 0; /* they are different */
  184. X        }
  185. X        if (ch1 != ch2) return 0; /* the strings differ */
  186. X    }
  187. X    s1++; s2++;
  188. X    }
  189. X    if (!*s1 && !*s2) {
  190. X    return 1; /* they are the same */
  191. X    }
  192. X    return 0; /* they are different */
  193. X}
  194. X
  195. Xint
  196. XIsWanted(String)
  197. X    char *String;
  198. X{
  199. X    char **p;
  200. X    int ch = String[0];
  201. X
  202. X    if (isupper(ch)) ch = tolower(ch);
  203. X
  204. X    for (p = KeepThese; *p && **p; p++) {
  205. X    if (ch < **p) return 0; /* gone too far */
  206. X     else if (icstreq(String, *p)) return 1;
  207. X    }
  208. X    return 0;
  209. X}
  210. X
  211. Xvoid
  212. XFilter(InputFile, Name)
  213. X    FILE *InputFile;
  214. X    char *Name;
  215. X{
  216. X    Header(InputFile, Name);
  217. X    Body(InputFile, Name);
  218. X}
  219. X
  220. Xtypedef enum {
  221. X    F_NotSeenAnythingYet,
  222. X    F_InTheFirstWord,
  223. X    F_AfterTheFirstWord
  224. X} t_FirstWord;
  225. X
  226. Xint InWord = 0;
  227. X
  228. Xvoid
  229. XHeader(InputFile, Name)
  230. X    FILE *InputFile;
  231. X    char *Name;
  232. X{
  233. X    int AtStartOfLine = 1;
  234. X    int IgnoreLine = 1; /* initialised for lint and gcc -W really... */
  235. X    t_FirstWord FirstWord = F_NotSeenAnythingYet;
  236. X    int ch;
  237. X    static int BufLen;
  238. X    static char *Buffer = 0;
  239. X    int AtStartOfWord;
  240. X    register char *q;
  241. X
  242. X    if (Buffer == 0) {
  243. X    BufLen = 24;
  244. X    Buffer = emalloc(BufLen);
  245. X    }
  246. X
  247. X    q = Buffer;
  248. X    InWord = 0;
  249. X
  250. X    while ((ch = GetChar(InputFile)) != EOF) {
  251. X    if (ch == '\n') {
  252. X        if (AtStartOfLine) { /* a blank line */
  253. X        putchar('\n');
  254. X        return;
  255. X        }
  256. X    }
  257. X
  258. X    InWord = InWord ? WithinWord(ch) : StartsWord(ch);
  259. X
  260. X    switch (FirstWord) {
  261. X    case F_NotSeenAnythingYet:
  262. X        if (InWord) {
  263. X        FirstWord = F_InTheFirstWord;
  264. X        if (q - Buffer >= BufLen - 1) {
  265. X            int where = q - Buffer;
  266. X
  267. X            BufLen += 24;
  268. X            Buffer = erealloc(Buffer, BufLen);
  269. X            q = &Buffer[where];
  270. X        }
  271. X        *q++ = ch;
  272. X        } else {
  273. X        putchar(' ');
  274. X        }
  275. X        break;
  276. X    case F_InTheFirstWord:
  277. X        if (InWord) {
  278. X        if (q - Buffer >= BufLen - 1) {
  279. X            int where = q - Buffer;
  280. X
  281. X            BufLen += 24;
  282. X            Buffer = erealloc(Buffer, BufLen += 24);
  283. X            q = &Buffer[where];
  284. X        }
  285. X        *q++ = ch;
  286. X        break;
  287. X        } else { /* reached the end of the first word on the line */
  288. X        *q = '\0';
  289. X        /* See if it's a keyword */
  290. X          if ((IgnoreLine = !IsWanted(Buffer)) != 0) {
  291. X            /* Turn the word into one that won't get indexed,
  292. X             * so that word counmts are unaffected:
  293. X             * We use qxxxxxxx (any number of x's) for this.
  294. X             */
  295. X            for (q = Buffer; *q; q++) {
  296. X            putchar((q == Buffer) ? 'q' : 'x');
  297. X            }
  298. X            putchar (ch == '\n' ? '\n' : ' ');
  299. X        } else {
  300. X            printf("%s%c", Buffer, ch == '\n' ? ch : ' ');
  301. X        }
  302. X        FirstWord = F_AfterTheFirstWord;
  303. X        }
  304. X        break;
  305. X    default:
  306. X        if ((AtStartOfLine = (ch == '\n'))) {
  307. X        IgnoreLine = 0;
  308. X        q = Buffer;
  309. X        FirstWord = F_NotSeenAnythingYet;
  310. X        AtStartOfWord = 1;
  311. X        }
  312. X        if (InWord && !IgnoreLine) {
  313. X        putchar(ch);
  314. X        } else {
  315. X        if (AtStartOfWord && InWord) {
  316. X            putchar('q');
  317. X            AtStartOfWord = 0;
  318. X        } else if (InWord) {
  319. X            putchar('x');
  320. X        } else if (isspace(ch)) {
  321. X            putchar(ch);
  322. X        } else {
  323. X            putchar(' ');
  324. X        }
  325. X        }
  326. X        if (!InWord) AtStartOfWord = 1;
  327. X    }
  328. X    if ((AtStartOfLine = (ch == '\n'))) {
  329. X        IgnoreLine = 0;
  330. X        q = Buffer;
  331. X        FirstWord = F_NotSeenAnythingYet;
  332. X        AtStartOfWord = 1;
  333. X    }
  334. X    }
  335. X    if (ch == EOF) {
  336. X    fprintf(stderr, "%s: warning: Mail folder %s has no message body\n",
  337. X            progname, Name);
  338. X    }
  339. X}
  340. X
  341. Xvoid
  342. XBody(InputFile, Name)
  343. X    FILE *InputFile;
  344. X    char *Name;
  345. X{
  346. X    int ch;
  347. X
  348. X    while ((ch = GetChar(InputFile)) != EOF) {
  349. X    if (InWord = InWord ? WithinWord(ch) : StartsWord(ch)) {
  350. X        putchar(ch);
  351. X    } else {
  352. X        putchar((ch == '\n') ? '\n' : ' ');
  353. X    }
  354. X    }
  355. X}
  356. X
  357. X#ifdef __GNU__
  358. Xinline
  359. X#endif
  360. Xint
  361. XGetChar(fd)
  362. X    FILE *fd;
  363. X{
  364. X    static int LastChar = 0;
  365. X
  366. X    if (LastChar) {
  367. X    int ch = LastChar;
  368. X    LastChar = 0;
  369. X    return ch;
  370. X    }
  371. X
  372. X    /* Only return a single quote if it is surrounded by letters */
  373. X    if ((LastChar = getc(fd)) == '\'') {
  374. X    LastChar = getc(fd);
  375. X    if (InWord && isalpha(LastChar)) return '\'';
  376. X    else return ' ';
  377. X    } else {
  378. X    int ch = LastChar;
  379. X    LastChar = 0;
  380. X    return ch;
  381. X    }
  382. X}
  383. X
  384. X/*
  385. X * $Log:    NewsFilter.c,v $
  386. X * Revision 1.5  90/10/06  00:57:27  lee
  387. X * Prepared for first beta release.
  388. X * 
  389. X * Revision 1.4  90/09/20  16:36:59  lee
  390. X * Fixed icstrcmp() and IsWanted() so that the unwanted parts of headers
  391. X * get deleted again.... (oops!)
  392. X * 
  393. X * Revision 1.3  90/09/19  21:19:50  lee
  394. X * Now supports turning unindexed stuff into qxxxxx-words.
  395. X * 
  396. X * Revision 1.2  90/08/29  21:56:58  lee
  397. X * Alpha release.
  398. X * 
  399. X * Revision 1.1  90/08/09  19:17:57  lee
  400. X * Initial revision
  401. X * 
  402. X * Revision 1.2  89/09/16  21:16:01  lee
  403. X * First demonstratable version.
  404. X * 
  405. X * Revision 1.1  89/09/07  21:05:48  lee
  406. X * Initial revision
  407. X * 
  408. X */
  409. @@@End of lq-text/src/filters/NewsFilter.c
  410. echo x - lq-text/src/h/Liamdbm.h 1>&2
  411. sed 's/^X//' >lq-text/src/h/Liamdbm.h <<'@@@End of lq-text/src/h/Liamdbm.h'
  412. X/* Liamdbm.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  413. X * This code is NOT in the public domain.
  414. X * See the file COPYRIGHT for full details.
  415. X */
  416. X
  417. X/* $Id: Liamdbm.h,v 1.2 90/10/06 02:18:14 lee Rel1-10 $
  418. X *
  419. X * This is used with gdbm.  I have not linked with gdbm, and, if you
  420. X * wish to do so, you must be careful not to voilate any copyright
  421. X * notices... (sigh)
  422. X *
  423. X * The version of gdbm for which I had a manual is rather old and had no
  424. X * ndbm compatibility.
  425. X */
  426. X
  427. X#include "gdbm.h"
  428. Xextern datum gdbm_fetch();
  429. Xextern datum gdbm_firstkey();
  430. Xextern datum gdbm_nextkey();
  431. X
  432. Xtypedef char DBM;
  433. X
  434. X#define dbm_store(db, key, data, mode) gdbm_store(db, key, data)
  435. X/* gdbm_open is stupder than ndbm_open.... */
  436. X#define dbm_open(FileName, Mode, m) gdbm_open(FileName, 512, Mode, 0)
  437. X#define dbm_fetch gdbm_fetch
  438. X#define dbm_close gdbm_close
  439. X#define dbm_firstkey gdbm_firstkey
  440. X#define dbm_nextkey gdbm_nextkey
  441. X
  442. X/*
  443. X * $Log:    Liamdbm.h,v $
  444. X * Revision 1.2  90/10/06  02:18:14  lee
  445. X * Prepared for first beta release.
  446. X * 
  447. X *
  448. X */
  449. @@@End of lq-text/src/h/Liamdbm.h
  450. echo x - lq-text/src/h/Revision.h 1>&2
  451. sed 's/^X//' >lq-text/src/h/Revision.h <<'@@@End of lq-text/src/h/Revision.h'
  452. X/* This header file gets updated with every distributed change to any source
  453. X * file anywhere in the lq-text package.
  454. X * A short description of the change is added to the Log here, too.
  455. X * Lee.
  456. X */
  457. X
  458. X#define LQTEXTREVISION "Release 1.10"
  459. X
  460. X/* $Revision: 1.10 $
  461. X *
  462. X * Revision 1.6  90/10/04  17:12:45  lee
  463. X * lqtext now compiles and mostly works under BSD.
  464. X * Fixes bug in phrase matching -- PhraseMatchLevel now works on one-word
  465. X * phrases.
  466. X * 
  467. X * Revision 1.5  90/09/28  22:19:36  lee
  468. X * Made GetChar() a macro in lqaddfile -- speed improvement...
  469. X * 
  470. X * Revision 1.4  90/09/20  16:37:35  lee
  471. X * Fixed Mail and News filters so that they throw away the unwanted header
  472. X * parts correctly.
  473. X * 
  474. X * Revision 1.3  90/09/20  12:51:24  lee
  475. X * Major sdbm initialisation bug fixed.
  476. X * 
  477. X * Revision 1.2  90/09/20  11:52:35  lee
  478. X * Fixed the filters so that lqshow highlights the right word (the qxx fix)
  479. X * 
  480. X * Revision 1.1  90/09/20  11:52:18  lee
  481. X * Initial revision
  482. X * 
  483. X *
  484. X */
  485. @@@End of lq-text/src/h/Revision.h
  486. echo x - lq-text/src/h/blkheader.h 1>&2
  487. sed 's/^X//' >lq-text/src/h/blkheader.h <<'@@@End of lq-text/src/h/blkheader.h'
  488. X/* blkheader.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  489. X * This code is NOT in the public domain.
  490. X * See the file COPYRIGHT for full details.
  491. X *
  492. X * (was called blockheader.h, but this was too long on SysV for RCS)
  493. X */
  494. X
  495. X/* descibe the physical WOrdPlace database...
  496. X *
  497. X * $Header: /usr/src/cmd/lq-text/src/h/RCS/blkheader.h,v 1.2 90/03/20 20:57:46 lee Rel1-10 $
  498. X *
  499. X * $Log:    blkheader.h,v $
  500. X * Revision 1.2  90/03/20  20:57:46  lee
  501. X * removed WID from the block.  This reduces checking, but should also
  502. X * noticeably reduce the size of the database.
  503. X * 
  504. X * Revision 1.1  90/03/20  20:54:44  lee
  505. X * Initial revision
  506. X *
  507. X */
  508. X
  509. X/* The header of each block -- I can't use sReadNumber, because I don't know
  510. X * the size of NextOffset until I get to the end, and it's too late by then!
  511. X *
  512. X * I should really store the block offset, and not the byte offset.  This
  513. X * would save a whole byte -- I could use 3 bytes for the NextBlock!
  514. X */
  515. Xtypedef struct {
  516. X    unsigned long NextOffset; /* a byte offset */
  517. X    char Data[1]; /* the address of this is where the number start... */
  518. X} t_BlockHeader;
  519. @@@End of lq-text/src/h/blkheader.h
  520. echo x - lq-text/src/h/emalloc.h 1>&2
  521. sed 's/^X//' >lq-text/src/h/emalloc.h <<'@@@End of lq-text/src/h/emalloc.h'
  522. X/* emalloc.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  523. X * This code is NOT in the public domain.
  524. X * See the file COPYRIGHT for full details.
  525. X */
  526. X
  527. X/* emalloc.h -- header file for emalloc.c, Liam Quin's malloc() wrapper
  528. X *
  529. X * $Id: emalloc.h,v 1.5 91/03/02 19:40:04 lee Rel1-10 $
  530. X *
  531. X * $Log:    emalloc.h,v $
  532. X * Revision 1.5  91/03/02  19:40:04  lee
  533. X * Simpler version of malloc defines if MALLOCTRACE unused...
  534. X * 
  535. X * Revision 1.4  91/03/02  18:31:21  lee
  536. X * Simpler call to malloc wrappers if MALLOCTRACE undefined.
  537. X * 
  538. X * Revision 1.3  90/10/06  02:18:26  lee
  539. X * Prepared for first beta release.
  540. X * 
  541. X * Revision 1.2  90/08/29  21:57:44  lee
  542. X * removed most of the testing code
  543. X * 
  544. X * Revision 1.1  90/08/09  19:14:48  lee
  545. X * Initial revision
  546. X * 
  547. X * Revision 2.2  89/10/08  20:45:20  lee
  548. X * Working version of nx-text engine.  Addfile and wordinfo work OK.
  549. X * 
  550. X *
  551. X */
  552. X
  553. Xextern int _LiamIsInCurses;
  554. X
  555. X#define InitScr() (_LiamIsInCurses = initscr())
  556. X#define EndWin() (_LiamIsInCurses ? (_LiamIsInCurses = 0), endwin() : 0)
  557. X
  558. Xextern char *_emalloc(), *_erealloc(), *_ecalloc();
  559. Xextern void _efree();
  560. X
  561. X#ifdef MALLOCTRACE
  562. X#define emalloc(u) _emalloc(u, __FILE__, __LINE__)
  563. X#define erealloc(s, u) _erealloc(s, u, __FILE__, __LINE__)
  564. X#define ecalloc(n, siz) _ecalloc(n, siz, __FILE__, __LINE__)
  565. X#define efree(s) _efree(s, __FILE__, __LINE__)
  566. X#else
  567. X#define emalloc _emalloc
  568. X#define erealloc _erealloc
  569. X#define ecalloc _ecalloc
  570. X#define efree _efree
  571. X#endif
  572. @@@End of lq-text/src/h/emalloc.h
  573. echo x - lq-text/src/h/fileinfo.h 1>&2
  574. sed 's/^X//' >lq-text/src/h/fileinfo.h <<'@@@End of lq-text/src/h/fileinfo.h'
  575. X/* fileinfo.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  576. X * This code is NOT in the public domain.
  577. X * See the file COPYRIGHT for full details.
  578. X */
  579. X
  580. X/* Internal structure used by NX-Text to represent a word */
  581. X
  582. X/* Needs: sys/types.h */
  583. X
  584. X/* $Id: fileinfo.h,v 1.2 90/10/06 02:18:27 lee Rel1-10 $
  585. X *
  586. X * $Log:    fileinfo.h,v $
  587. X * Revision 1.2  90/10/06  02:18:27  lee
  588. X * Prepared for first beta release.
  589. X * 
  590. X * Revision 1.1  90/08/09  19:14:57  lee
  591. X * Initial revision
  592. X * 
  593. X * Revision 2.2  89/10/08  20:45:57  lee
  594. X * Working version of nx-text engine.  Addfile and wordinfo work OK.
  595. X * 
  596. X * Revision 2.1  89/10/02  01:14:29  lee
  597. X * New index format, with Block/WordInBlock/Flags/BytesSkipped info.
  598. X * 
  599. X * Revision 1.2  89/09/16  21:15:19  lee
  600. X * First demonstratable version.
  601. X * 
  602. X * Revision 1.1  89/09/07  21:00:34  lee
  603. X * Initial revision
  604. X * 
  605. X *
  606. X */
  607. X
  608. Xtypedef unsigned long t_FID;
  609. X
  610. Xtypedef struct {
  611. X    char *Name;
  612. X    t_FID FID; /* File Identifier */
  613. X    int FilterType; /* command to ASCIIify, 0 unknown, 1 none */
  614. X    time_t Date; /* when the file was last indexed */
  615. X    FILE *Stream;
  616. X} t_FileInfo;
  617. X
  618. X#define FindFile(name) ((*(name) == '/') ? (name) : _FindFile(name))
  619. Xextern char *_FindFile();
  620. @@@End of lq-text/src/h/fileinfo.h
  621. echo x - lq-text/src/h/filter.h 1>&2
  622. sed 's/^X//' >lq-text/src/h/filter.h <<'@@@End of lq-text/src/h/filter.h'
  623. X/* filter.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  624. X * This code is NOT in the public domain.
  625. X * See the file COPYRIGHT for full details.
  626. X */
  627. X
  628. X/* filter.h -- define filter table for NX-Text, Liam Quin's text retrieval
  629. X * program.
  630. X * This table is built from a file like a simplified /etc/magic, normally
  631. X * stored in /usr/local/lib/nx-text/lib/filtertable
  632. X * but you can set this either here or in the Makefile.
  633. X *
  634. X * NEEDS: stdio.h
  635. X *
  636. X * $Id: filter.h,v 1.6 91/03/02 18:45:04 lee Rel1-10 $
  637. X *
  638. X * $Log:    filter.h,v $
  639. X * Revision 1.6  91/03/02  18:45:04  lee
  640. X * Spell MAILFILTER correctly in the ifdef...
  641. X * 
  642. X * Revision 1.5  90/10/13  03:11:31  lee
  643. X * Now defines filters for easier stand-alone testing of stuff...
  644. X * 
  645. X * Revision 1.4  90/10/06  02:18:28  lee
  646. X * Prepared for first beta release.
  647. X * 
  648. X * Revision 1.3  90/09/28  23:03:16  lee
  649. X * Now use MAILFILTER and NEWSFILTER...
  650. X * 
  651. X * Revision 1.2  90/08/29  21:57:57  lee
  652. X * removed most of the testing code
  653. X * 
  654. X * Revision 1.1  90/08/09  19:15:01  lee
  655. X * Initial revision
  656. X * 
  657. X * Revision 2.2  89/10/08  20:46:04  lee
  658. X * Working version of nx-text engine.  Addfile and wordinfo work OK.
  659. X * 
  660. X * Revision 2.1  89/10/02  01:14:33  lee
  661. X * New index format, with Block/WordInBlock/Flags/BytesSkipped info.
  662. X * 
  663. X *
  664. X */
  665. X
  666. X#define FTYPE_NEWS  1
  667. X#define FTYPE_MAIL  2
  668. X#define FTYPE_CDMS  3
  669. X#define FTYPE_MOSTLYASCII 4
  670. X#define FTYPE_C_SOURCE 5
  671. X
  672. X/* The Type field in each array entry is so that I can do some very simple
  673. X * checking...
  674. X */
  675. Xextern int fclose(), pclose();
  676. Xstruct s_FilterTable {
  677. X    int Type;
  678. X    int (* close)(); /* how to close the darned stream */
  679. X    char *String;
  680. X};
  681. X#ifndef FILTERDEF
  682. Xextern struct s_FilterTable FilterTable[];
  683. X#else
  684. Xstruct s_FilterTable FilterTable[] = {
  685. X    { 0, fclose, 0 }, /* use fopen() */
  686. X#ifndef NEWSFILTER
  687. X# define NEWSFILTER "NewsFilter"
  688. X#endif
  689. X    { FTYPE_NEWS, pclose, NEWSFILTER },
  690. X#ifndef MAILFILTER
  691. X# define MAILFILTER "MailFilter"
  692. X#endif
  693. X    { FTYPE_MAIL, pclose, MAILFILTER },
  694. X#ifdef FTYPE_CDMS /* CrystalWriter from Syntactics... */
  695. X    { FTYPE_CDMS, pclose, "CDMSFilter" },
  696. X#endif
  697. X#ifdef FTYPE_NTROFF
  698. X    { FTYPE_NTROFF, pclose, "lqderoff" }, /* not yet released, sorry */
  699. X#endif
  700. X    { FTYPE_MOSTLYASCII, pclose, "AsciiFilter" },
  701. X#ifdef FTYPE_C_SOURCE
  702. X    { FTYPE_C_SOURCE, pclose, "CFilter" }, /* leave me last! */
  703. X#endif
  704. X    /* If you add more, you MUST update MaxFilterType */
  705. X    { 0, 0, 0 }
  706. X};
  707. X#endif
  708. X#define MaxFilterType FTYPE_C_SOURCE
  709. @@@End of lq-text/src/h/filter.h
  710. echo x - lq-text/src/h/globals.h 1>&2
  711. sed 's/^X//' >lq-text/src/h/globals.h <<'@@@End of lq-text/src/h/globals.h'
  712. X/* globals.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  713. X * This code is NOT in the public domain.
  714. X * See the file COPYRIGHT for full details.
  715. X *
  716. X * $Id: globals.h,v 1.6 91/02/20 19:26:53 lee Rel1-10 $
  717. X *
  718. X * (see Log at end of this file for change history.  Keep this up to date
  719. X * using rcs if you have it...)
  720. X */
  721. X
  722. X/* globals.h -- declarations of globally accessible variables, and also
  723. X * of configurable parameters.
  724. X *
  725. X * Some of the configuation options might be given in ../Makefile, so
  726. X * you must check in there too.
  727. X *
  728. X * Everything that includes this file must be linked with Defaults.c
  729. X */
  730. X
  731. X/* 
  732. X * DOCPATH gives the list of directories in which to search in order
  733. X * to find files to retrieve and to index.  The default can be wired
  734. X * in here, or can be simply "." (in which case relative pathnames will
  735. X * be from wherever one invokes the commands, and absolute pathnames
  736. X * will be absolute.  For example,
  737. X * #define DFLTDOCPATH "/usr/man:."
  738. X * In any case, it can be overridden by a DOCPATH line in the configuration
  739. X * file for a given database (README in the database directory), and also
  740. X * by an environment variable DOCPATH (the latter taking precedence over
  741. X * the former).
  742. X *
  743. X * Use ((char *) 0) to disable the default -- in this case, you always have
  744. X * to give one, either with the $DOCPATH variable or in the database file.
  745. X *
  746. X */
  747. X#ifndef DFLTDOCPATH
  748. X# define DFLTDOCPATH ((char *) 0)
  749. X#endif
  750. X
  751. X/* LQTEXTDIR: if the programs can't find the directory to use -- i.e.,
  752. X * there was no -d option and $(LQTEXTDIR) is unset, we either
  753. X * look in UNDERHOME (if that was defined here) or in wherever LQTEXTDIR
  754. X * is defined to point.
  755. X */
  756. X#ifndef LQTEXTDIR
  757. X# define LQTEXTDIR "/usr/spool/lqtextdir"
  758. X#endif
  759. X
  760. X/* If UNDERHOME is set, look there for a directory -- e.g. 
  761. X * #define UNDERHOME "sockdrawer"
  762. X * would make lqtext programs look for a directory something like
  763. X * /users/liam/sockdrawer
  764. X * (where /users/liam is my login directory)
  765. X */
  766. X#ifndef UNDERHOME
  767. X# define UNDERHOME "LQTEXTDIR"
  768. X#endif
  769. X
  770. X/* The name of a configuration file found in the database directory:
  771. X */
  772. X#define CONFIGFILE "README"
  773. X
  774. X/* If the config file doesn't give a filename for a list of common
  775. X * words, we look for one called DFLTCOMMONFILE (and don't mind if we
  776. X * don't find it).  Use "/dev/null" or ((char *) 0) if you want to
  777. X * disable the default.
  778. X * It's case sensitive, of course.
  779. X */
  780. X#define DFLTCOMMONFILE "CommonWords"
  781. X
  782. X#ifndef PAGER
  783. X/* The default pager to use if the user doesn't set $PAGER.  This is only
  784. X * used in lqshow, the browser.  Good things to try are
  785. X * more, "less -Ce", and (generally only on System V) "pg -ns".
  786. X * Specify an absolute path if possible.  It's often a lot faster, and
  787. X * it's somewhat safer...
  788. X */
  789. X# ifdef BSD
  790. X#  define PAGER "/usr/ucb/more"
  791. X# else
  792. X#  define PAGER "/usr/bin/pg -ns"
  793. X# endif
  794. X#endif
  795. X
  796. X#ifndef DBMCREAT
  797. X/* If you are using dbm or gdbm (?), you will need to create the dbm files
  798. X * by hand yourself.  Defining DBMCREAT as 0 makes the software do this
  799. X * automatically, with a very slight performance penalty.
  800. X *
  801. X * ndbm and sdbm can use O_CREAT, so set it to 1 here for them.
  802. X * You will also have to look at ../Makefile, ../PORTING, smalldb.h and
  803. X * ../lqlib/smalldb.h, making whatever changes are needed.
  804. X */
  805. X# define DBMCREAT 1 /* 1 for ndbm, 0 for dbm */
  806. X#endif
  807. X
  808. X#ifdef sparc
  809. X# define NEEDALIGN
  810. X#endif
  811. X
  812. X#ifdef mips /* e.g. SGI machines */
  813. X# define NEEDALIGN
  814. X#endif
  815. X
  816. X/* NEEDALIGN is for C compilers that require C structures to start at
  817. X * word boundaries.  You need this on sparc and sgi machines...
  818. X */
  819. X
  820. X/***
  821. X *** If you want to change anything beyond here...
  822. X ***
  823. X *** well, you can.
  824. X *** After all, it's your copy.
  825. X ***
  826. X *** But don't come running back to me if it doesn't work!
  827. X *** At least not until you have tried
  828. X ***    +  understanding what the problem is;
  829. X ***    +  looking at the source to see why;
  830. X ***    +  fixing the problem;
  831. X ***    +  taking off your shoes and socks and grinning for a while.
  832. X ***
  833. X *** Liam.
  834. X ***
  835. X ***/
  836. X
  837. X/* The following let you reconfigure the names of the files that form
  838. X * part of the database, but there is no point in doing so unless you
  839. X * are porting to some strange system that has absurd filename restrictions!
  840. X */
  841. X#ifndef WORDINDEX
  842. X# define WORDINDEX "wordlist"
  843. X    /* This is a dbm file, so you'll get two files, one with ".pag"
  844. X     * stuck on the end and one with ".dir" on the end.
  845. X     * It contains an entry for every word in the database, enabling
  846. X     * the software to go from a word to an integer (well, a t_WID)
  847. X     * very quickly.
  848. X     * It tends to be a little over one tenth of the size of the DATABASE.
  849. X     */
  850. X#endif
  851. X#ifndef WIDINDEXFILE
  852. X# define WIDINDEXFILE "WIDIndex"
  853. X    /* WIDINDEXFILE contains each word in the datbase, together with some
  854. X     * information and the first few bytes of data.
  855. X     * It contains WIDBLOCKSIZE bytes for every word, but this has to
  856. X     * be at least MAXWORDLEN + 10 bytes long (see WordInfo.c).
  857. X     */
  858. X#endif
  859. X#ifndef DATABASE
  860. X# define DATABASE "data"
  861. X    /* For those words whose data doesn't fit into the first WIDBLOCKSIZE
  862. X     * bytes, space is allocated in this file in BLOCKSIZE chunks.  Make
  863. X     * BLOCKSIZE small, or you will waste a lot of space -- on the other
  864. X     * hand, there's a 4-byte-per-block overhead at the moment.
  865. X     * This file gets very  b  i  g  indeed.
  866. X     */
  867. X#endif
  868. X#ifndef FILEINDEX
  869. X# define FILEINDEX "FileList"
  870. X    /* This is a list of every file in the database, again in dbm format,
  871. X     * so there are actually two files (a .pag and a .dir) involved.
  872. X     * If your files are short, it will quickly grow to a tenth of the size
  873. X     * of the database.
  874. X     * It stores the filename, and some other information.
  875. X     */
  876. X#endif
  877. X#ifndef FIDFILE
  878. X# define FIDFILE "FIDFile"
  879. X    /* This contains the largest currently used file number... you can
  880. X     * look at it to see how many files have been indexed.
  881. X     * It is only a few bytes long.
  882. X     */
  883. X#endif
  884. X#ifndef WIDFILE
  885. X# define WIDFILE "WIDFile"
  886. X    /* This contains the largest currently used word number... you can
  887. X     * look at it to see how many unique words have been seen.
  888. X     * It is only a few bytes long.
  889. X     */
  890. X#endif
  891. X
  892. X#ifndef WIDBLOCKSIZE
  893. X# define WIDBLOCKSIZE    32
  894. X/* WIDBLOCKSIZE absolutely must be large enough to fit at least one byte
  895. X * of actual data, or all hell will break loose.
  896. X * (actually that could be fixed...).
  897. X * In any case, it has to contain (apart from the >= 1 byte of data):
  898. X * + the length count (1 byte) and the word itself (no null on the end)
  899. X * + the block number in the database (1..5 bytes)
  900. X * + the number of matches (1..5 bytes)
  901. X *
  902. X * It helps efficiency very, very slightly if these are a power of two
  903. X * bytes, as then they never cross Unix block boundaries.
  904. X *
  905. X */
  906. X#endif
  907. X
  908. X#ifndef BLOCKSIZE
  909. X#define BLOCKSIZE    64
  910. X/* BLOCKSIZE is the size of blocks in the data file.  There are several
  911. X * tradeoffs:
  912. X * + there is a 4-bytes-per-block overhead for list pointers, so it's
  913. X *   a good idea to make them large
  914. X * + there's a bit of work involved in fetching the blocks, so things go
  915. X *   faster if they're larger...
  916. X * + many blocks are not full, so it's a good idea to make them small.
  917. X *   On average, a little over (BLOCKSIZE - 4) / 2 bytes are wasted for
  918. X *   every word chain.
  919. X * + since many of the blocks are not full, it's a good idea to make them
  920. X *   small, minimising the amount of extra data that gets copied around by
  921. X *   the Unix kernel.  If the blocks are smaller it'll go faster...
  922. X *
  923. X * It helps efficiency very, very slightly if these are a power of two
  924. X * bytes, as then they never cross Unix block boundaries.
  925. X *
  926. X */
  927. X#endif
  928. X
  929. X/**** Some useful macros */
  930. X
  931. X/* STREQ(a,b) is much faster than strcmp() in the (common) case that the
  932. X * first character of the strings differ.
  933. X * It is due (as far as I know) to Henry Spencer, at the University of
  934. X * Toronto Zoology Dept.,
  935. X * utzoo!henry
  936. X */
  937. X#ifndef STREQ
  938. X# define STREQ(henry,utzoo) (*(henry) == *(utzoo) && !strcmp(henry, utzoo))
  939. X#endif
  940. X
  941. X/* Inline functions are functions that get expanded inline during
  942. X * compilation -- sort of like macros with real local arguments.
  943. X * Not all compilers support them.
  944. X */
  945. X#ifdef __GNUC__
  946. X#  define INLINE inline
  947. X#else
  948. X#  define INLINE /* not supported */
  949. X#endif
  950. X
  951. X#ifdef DefineThem
  952. X# define DECL(name, type, value)   type name = value
  953. X# define EXTERN /* just define them please */
  954. X#else
  955. X# define EXTERN extern /* declare but do not define */
  956. X# define DECL(name, type, value)   EXTERN type name
  957. X#endif
  958. X
  959. X/****/
  960. X
  961. X/* Now declare (or define) things: */
  962. X
  963. Xextern char *progname; /* from progname.c, for error messages */
  964. XDECL(CommonWordFile, char *, DFLTCOMMONFILE); 
  965. XDECL(DatabaseDir, char *, LQTEXTDIR); 
  966. XDECL(FileIndex, char *, FILEINDEX);
  967. XDECL(WordIndex, char *, WORDINDEX);
  968. XDECL(DataBase, char *, DATABASE);
  969. XDECL(FidFile, char *, FIDFILE);
  970. XDECL(WidFile, char *, WIDFILE);
  971. XDECL(WidIndexFile, char *, WIDINDEXFILE);
  972. XDECL(DocPath, char *, DFLTDOCPATH); 
  973. X
  974. X/*
  975. X * $Log:    globals.h,v $
  976. X * Revision 1.6  91/02/20  19:26:53  lee
  977. X * Added NEEDALIGN on mips systems
  978. X * (thanks to Mark Moraes, moraes@cs.toronto.edu)
  979. X * 
  980. X * Revision 1.5  90/10/07  20:41:20  lee
  981. X * Added NEEDALIGN for fussy architectures.
  982. X * 
  983. X * Revision 1.4  90/10/06  02:21:21  lee
  984. X * Prepared for first beta release.
  985. X * 
  986. X * Revision 1.3  90/10/03  21:31:54  lee
  987. X * Added definition of PAGER, which has moved here from lqshow.c
  988. X * 
  989. X * Revision 1.2  90/08/09  19:15:03  lee
  990. X * after BSD lint and saber-C
  991. X * 
  992. X * Revision 1.1  90/03/23  17:32:11  lee
  993. X * Initial revision
  994. X * 
  995. X *
  996. X */
  997. @@@End of lq-text/src/h/globals.h
  998. echo x - lq-text/src/h/numbers.h 1>&2
  999. sed 's/^X//' >lq-text/src/h/numbers.h <<'@@@End of lq-text/src/h/numbers.h'
  1000. X/* numbers.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  1001. X * This code is NOT in the public domain.
  1002. X * See the file COPYRIGHT for full details.
  1003. X */
  1004. X
  1005. X/* ReadNumber and WriteNumber take/return a long, using a compression
  1006. X * algorithm to reduce the amount of data taken.
  1007. X *
  1008. X * They use (char *) pointers instead if prefixes with an s.
  1009. X *
  1010. X * $Id: numbers.h,v 1.3 90/10/06 02:18:30 lee Rel1-10 $
  1011. X *
  1012. X */
  1013. X
  1014. Xextern INLINE unsigned long fReadNumber();
  1015. Xextern INLINE unsigned long sReadNumber();
  1016. X
  1017. Xextern INLINE void fWriteNumber();
  1018. Xextern INLINE void sWriteNumber();
  1019. X
  1020. X/*
  1021. X * $Log:    numbers.h,v $
  1022. X * Revision 1.3  90/10/06  02:18:30  lee
  1023. X * Prepared for first beta release.
  1024. X * 
  1025. X * Revision 1.2  90/08/09  19:15:42  lee
  1026. X * after BSD lint and saber-C
  1027. X * 
  1028. X * Revision 1.1  90/04/19  19:27:04  lee
  1029. X * Initial revision
  1030. X * 
  1031. X * Revision 2.2  89/10/08  20:46:43  lee
  1032. X * Working version of nx-text engine.  Addfile and wordinfo work OK.
  1033. X * 
  1034. X * Revision 1.2  89/09/16  21:15:40  lee
  1035. X * First demonstratable version.
  1036. X * 
  1037. X * Revision 1.1  89/09/07  21:06:02  lee
  1038. X * Initial revision
  1039. X * 
  1040. X */
  1041. @@@End of lq-text/src/h/numbers.h
  1042. echo x - lq-text/src/h/pblock.h 1>&2
  1043. sed 's/^X//' >lq-text/src/h/pblock.h <<'@@@End of lq-text/src/h/pblock.h'
  1044. X/* pblock.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  1045. X * This code is NOT in the public domain.
  1046. X * See the file COPYRIGHT for full details.
  1047. X */
  1048. X
  1049. X#ifndef PBLOCK_H /* the matching endif is at the end of the file... */
  1050. X
  1051. X# define PBLOCK_H
  1052. X/* The physical Word Database...
  1053. X *
  1054. X * First, there is the WID (from 1 to 4 bytes)
  1055. X *
  1056. X * Then, there is a NEXT pointer (or 0).
  1057. X *
  1058. X * Then, there is a list of (FID, OFFSET) pairs.
  1059. X *
  1060. X * $Header: /usr/src/cmd/lq-text/src/h/RCS/pblock.h,v 1.2 90/08/09 19:15:45 lee Rel1-10 $
  1061. X *
  1062. X * $Log:    pblock.h,v $
  1063. X * Revision 1.2  90/08/09  19:15:45  lee
  1064. X * after BSD lint and saber-C
  1065. X * 
  1066. X * Revision 1.1  90/03/01  23:54:37  lee
  1067. X * Initial revision
  1068. X * 
  1069. X * Revision 2.2  89/10/08  20:47:04  lee
  1070. X * Working version of nx-text engine.  Addfile and wordinfo work OK.
  1071. X * 
  1072. X * Revision 2.1  89/10/02  01:15:36  lee
  1073. X * New index format, with Block/WordInBlock/Flags/BytesSkipped info.
  1074. X * 
  1075. X * Revision 1.2  89/09/16  21:15:43  lee
  1076. X * First demonstratable version.
  1077. X * 
  1078. X * Revision 1.1  89/09/07  21:06:09  lee
  1079. X * Initial revision
  1080. X * 
  1081. X *
  1082. X */
  1083. X
  1084. Xtypedef struct {
  1085. X    t_FID FID;
  1086. X    unsigned long BlockInFile;
  1087. X    unsigned short WordInBlock;
  1088. X    unsigned short Flags;
  1089. X    unsigned char StuffBefore; /* preceding ignored garbage */
  1090. X} t_WordPlace;
  1091. X
  1092. X/* This structure is really only used by addfile; elsewhere arrays of
  1093. X * WordlPlace are used.
  1094. X */
  1095. X
  1096. Xtypedef struct s_WordPlaceList {
  1097. X    char *Word;
  1098. X    t_WordPlace WordPlace;
  1099. X    struct s_WordPlaceList *Next;
  1100. X} t_WordPlaceList;
  1101. X
  1102. X/* Warning: One cannot use structure copy for a pblock! */
  1103. X
  1104. X/* This does *NOT* correspond to the physical disk layout -- see pblock.c */
  1105. Xtypedef struct {
  1106. X    t_WID WID; /* for checking; */
  1107. X    unsigned long ChainStart;
  1108. X    unsigned long NumberOfWordPlaces;
  1109. X    t_WordPlace WordPlaces[1]; /* made by joining lots of disk blocks... */
  1110. X} t_pblock;
  1111. X
  1112. X#endif
  1113. @@@End of lq-text/src/h/pblock.h
  1114. echo x - lq-text/src/h/phrase.h 1>&2
  1115. sed 's/^X//' >lq-text/src/h/phrase.h <<'@@@End of lq-text/src/h/phrase.h'
  1116. X/* phrase.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  1117. X * This code is NOT in the public domain.
  1118. X * See the file COPYRIGHT for full details.
  1119. X */
  1120. X
  1121. X/* LQ-Text -- Liam's Text Retrieval Package
  1122. X * Liam R. Quin, September 1989, and later...
  1123. X *
  1124. X * phrase.h -- data structures for handling entire phrases
  1125. X *
  1126. X */
  1127. X
  1128. X/* $Id: phrase.h,v 1.2 90/10/06 02:18:33 lee Rel1-10 $
  1129. X *
  1130. X */
  1131. X
  1132. X/* Represent a Phrase as a linked list of WordInfo pointers, plus a list
  1133. X * of matches.
  1134. X */
  1135. X
  1136. Xtypedef struct s_PhraseItem {
  1137. X    t_WordInfo *Word;
  1138. X    struct s_PhraseItem *Next;
  1139. X    unsigned long SearchIndex; /* For phrase-matching */
  1140. X    char *WordStart; /* pointer into original phrase */
  1141. X} t_PhraseItem;
  1142. X
  1143. Xtypedef enum {
  1144. X    PCM_AnyCase, /* Ignore case entirely */
  1145. X    PCM_HalfCase, /* Upper only matches upper; lower matches either */
  1146. X    PCM_SameCase, /* Exact matching */
  1147. X} t_PhraseCaseMatch;
  1148. X
  1149. Xtypedef struct s_Match {
  1150. X    t_WID WID;
  1151. X    t_WordPlace *Where;
  1152. X    struct s_Match *Next;
  1153. X} t_Match;
  1154. X
  1155. Xtypedef struct s_MatchList {
  1156. X    t_Match *Match;
  1157. X    struct s_MatchList *Next;
  1158. X} t_MatchList;
  1159. X
  1160. X
  1161. Xtypedef struct s_Phrase {
  1162. X    t_PhraseItem *Words; /* list of words and pblocks */
  1163. X    char *OriginalString; /* as supplied by the user */
  1164. X    char *ModifiedString; /* after deleting short/unindexed words */
  1165. X    unsigned long NumberOfMatches;
  1166. X    t_MatchList *Matches;
  1167. X    struct s_Phrase *Next; /* for use when we're in a list of phrases... */
  1168. X    unsigned short HasUnknownWords;
  1169. X} t_Phrase;
  1170. X
  1171. X/* This is for FilleList() */
  1172. Xtypedef struct s_Answer {
  1173. X    char *Answer;
  1174. X    struct s_Answer *Next;
  1175. X} t_Answer;
  1176. X
  1177. X/*
  1178. X * $Log:    phrase.h,v $
  1179. X * Revision 1.2  90/10/06  02:18:33  lee
  1180. X * Prepared for first beta release.
  1181. X * 
  1182. X * Revision 1.1  90/08/09  19:15:49  lee
  1183. X * Initial revision
  1184. X * 
  1185. X * Revision 1.1  89/09/17  23:03:37  lee
  1186. X * Initial revision
  1187. X * 
  1188. X */
  1189. @@@End of lq-text/src/h/phrase.h
  1190. echo x - lq-text/src/h/smalldb.h 1>&2
  1191. sed 's/^X//' >lq-text/src/h/smalldb.h <<'@@@End of lq-text/src/h/smalldb.h'
  1192. X/* smalldb.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  1193. X * This code is NOT in the public domain.
  1194. X * See the file COPYRIGHT for full details.
  1195. X */
  1196. X
  1197. X/* $Id: smalldb.h,v 1.3 91/03/03 00:12:56 lee Exp $
  1198. X */
  1199. X
  1200. X/* You must include fcntl.h before this file. */
  1201. X
  1202. X#ifdef ndbm
  1203. X# include <ndbm.h>
  1204. X# define FoundDbmOK
  1205. X# define NDBM
  1206. X#endif
  1207. X
  1208. X#ifdef sdbm
  1209. X# include "sdbm.h"
  1210. X# define FoundDbmOK
  1211. X# define NDBM /* it's compatible */
  1212. X#endif
  1213. X
  1214. X#ifdef ozmahash
  1215. X# include "ozmadbm.h"
  1216. X# define FoundDbmOK
  1217. X# define NDBM /* it's compatible as well... */
  1218. X#endif
  1219. X
  1220. X#ifndef FoundDbmOK
  1221. X# include "Liamdbm.h"
  1222. X#endif
  1223. X
  1224. X#ifndef O_RDWR
  1225. X# include <fcntl.h>
  1226. X#endif
  1227. X
  1228. X#define CACHE 2 /* size of DBM cache in startdb() -- I only use two! */
  1229. X/* If you rip out the dbm cache stuff for use elsewhere, increse the 2
  1230. X * to something like 5 or so!!!  Each entry uses two file pointers.
  1231. X * Lee
  1232. X */
  1233. X
  1234. X#ifndef CACHE
  1235. X# define startdb(FilePrefix) dbm_open(FilePrefix, O_RDWR|O_CREAT, 0640)
  1236. X# define enddb(db) { if (db) dbm_close(db); }
  1237. X#endif
  1238. X
  1239. X
  1240. X#ifndef startdb
  1241. XDBM *startdb();
  1242. X#endif
  1243. X
  1244. X#ifndef enddb
  1245. X# ifdef CACHE
  1246. X#  define enddb(db) /* nothing to do, because of the cache */
  1247. X# else
  1248. X   void enddb();
  1249. X# endif /* CACHE */
  1250. X#endif /* !enddb */
  1251. X
  1252. X/*
  1253. X * $Log:    smalldb.h,v $
  1254. X * Revision 1.3  91/03/03  00:12:56  lee
  1255. X * Integrated ozmahash.
  1256. X * 
  1257. X * Revision 1.2  90/10/06  02:18:36  lee
  1258. X * Prepared for first beta release.
  1259. X * 
  1260. X * Revision 1.1  90/08/09  19:16:00  lee
  1261. X * Initial revision
  1262. X * 
  1263. X * Revision 2.2  89/10/08  20:47:19  lee
  1264. X * Working version of nx-text engine.  Addfile and wordinfo work OK.
  1265. X * 
  1266. X * Revision 2.1  89/10/02  01:16:01  lee
  1267. X * New index format, with Block/WordInBlock/Flags/BytesSkipped info.
  1268. X * 
  1269. X * Revision 1.2  89/09/16  21:15:45  lee
  1270. X * First demonstratable version.
  1271. X * 
  1272. X * Revision 1.1  89/09/07  21:06:12  lee
  1273. X * Initial revision
  1274. X * 
  1275. X */
  1276. @@@End of lq-text/src/h/smalldb.h
  1277. echo x - lq-text/src/h/wordindex.h 1>&2
  1278. sed 's/^X//' >lq-text/src/h/wordindex.h <<'@@@End of lq-text/src/h/wordindex.h'
  1279. X/* wordindex.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  1280. X * This code is NOT in the public domain.
  1281. X * See the file COPYRIGHT for full details.
  1282. X */
  1283. X
  1284. X/* (this file is currently empty, but might return...) */
  1285. X
  1286. X/*
  1287. X * $Id: wordindex.h,v 1.2 90/10/06 02:18:38 lee Rel1-10 $
  1288. X *
  1289. X * $Log:    wordindex.h,v $
  1290. X * Revision 1.2  90/10/06  02:18:38  lee
  1291. X * Prepared for first beta release.
  1292. X * 
  1293. X * Revision 1.1  90/08/09  19:16:02  lee
  1294. X * Initial revision
  1295. X * 
  1296. X * Revision 2.1  89/10/02  01:16:06  lee
  1297. X * New index format, with Block/WordInBlock/Flags/BytesSkipped info.
  1298. X * 
  1299. X * Revision 1.2  89/09/16  21:15:47  lee
  1300. X * First demonstratable version.
  1301. X * 
  1302. X * Revision 1.1  89/09/07  21:06:13  lee
  1303. X * Initial revision
  1304. X * 
  1305. X *
  1306. X */
  1307. @@@End of lq-text/src/h/wordindex.h
  1308. echo x - lq-text/src/h/wordinfo.h 1>&2
  1309. sed 's/^X//' >lq-text/src/h/wordinfo.h <<'@@@End of lq-text/src/h/wordinfo.h'
  1310. X/* wordinfo.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  1311. X * This code is NOT in the public domain.
  1312. X * See the file COPYRIGHT for full details.
  1313. X */
  1314. X
  1315. X/*
  1316. X * $Id: wordinfo.h,v 1.3 90/10/06 02:21:30 lee Rel1-10 $
  1317. X */
  1318. X
  1319. Xtypedef unsigned long t_WID;
  1320. X
  1321. X#ifndef PBLOCK_H
  1322. X# include "pblock.h"
  1323. X#endif
  1324. X
  1325. X#ifndef WIDBLOCKSIZE
  1326. X#define WIDBLOCKSIZE 32
  1327. X#endif
  1328. X
  1329. Xextern char *WidIndexFile; /* Default.c */
  1330. X
  1331. X/* this is a hack for speed: */
  1332. X#define GetNextWID SpoofGetNextWID
  1333. X
  1334. X/** A t_WordInfo describes a single word, in terms of
  1335. X ** where it came from
  1336. X ** how to find its database entries
  1337. X ** how to find the in-core database entries (a copy of the above)
  1338. X **/
  1339. X
  1340. X/* There would be a performance benefit if this struct was smaller.
  1341. X * It was foolish of me to use WordInfo for so many different things in
  1342. X * addfile, and now I pay the price.
  1343. X * Addfile may end up calling malloc for 10,000 of these things...
  1344. X *
  1345. X * There should be:
  1346. X * t_WordPlace (exists, pblock.h)
  1347. X *    for recording a specific occurrence of a given word in a given file
  1348. X * t_WordInfo (definition follows... look down...)
  1349. X *    for recording information about a WID's entry in the database
  1350. X * t_WordPlaceList
  1351. X *    for addfile to make a list of word places...
  1352. X * t_pblock (exists, see pblock.h)
  1353. X *    for containing the list of WordPlaces found in the database for a
  1354. X *    given word, or for putting them there.  Uses arrays rather than
  1355. X *    lists to squeeze a few extra milliseconds.  Some hope :-( :-)
  1356. X *
  1357. X * t_WordPlaceList almost certainly happen in the next major edit phase...
  1358. X * t_WordInfo will then be somewhat smaller.
  1359. X * All of the entries marked with a leading comment (below) should
  1360. X * be elsewhere (and some of them were, in the Grand Design!).
  1361. X *
  1362. X */
  1363. Xtypedef struct s_WordInfo {
  1364. X    char *Word;
  1365. X    t_WID WID; /* My Word Identifier */
  1366. X    unsigned long NumberOfWordPlaces; /* total */
  1367. X    t_FID FID; /* where we got it from */
  1368. X    unsigned long Offset; /* word entry position in the data base */
  1369. X    struct s_WordInfo *Next; /* for making lists of WordInfo structs */
  1370. X    char *DataBlock; /* for writing me out to the index */
  1371. X    char *WordPlaceStart;
  1372. X    t_WordPlace *WordPlaces; /* first few pairs */
  1373. X    t_WordPlace WordPlace; /* For addfile -- this is due to go!!!! */
  1374. X    /* shorts are at the end to obviate alignment padding... */
  1375. X    unsigned long WordPlacesInHere;
  1376. X    unsigned short Length; /* Word length; reduce the need for strlen */
  1377. X#if 0
  1378. X    unsigned char Flags;
  1379. X    /* Flags serve two purposes:
  1380. X     * the LSB says whether the entry is sorted.
  1381. X     * the remainder are a logical AND of all entries in a sorted
  1382. X     * block.  NOTE: if the block is unsorted, the other bits should
  1383. X     * still be up to date.
  1384. X     */
  1385. X#endif
  1386. X} t_WordInfo;
  1387. X
  1388. X/*
  1389. X * $Log:    wordinfo.h,v $
  1390. X * Revision 1.3  90/10/06  02:21:30  lee
  1391. X * Prepared for first beta release.
  1392. X * 
  1393. X * Revision 1.2  90/08/09  19:16:04  lee
  1394. X * after BSD lint and saber-C
  1395. X * 
  1396. X * Revision 2.2  89/10/08  20:47:27  lee
  1397. X * Working version of nx-text engine.  Addfile and wordinfo work OK.
  1398. X * 
  1399. X * Revision 2.1  89/10/02  01:16:15  lee
  1400. X * New index format, with Block/WordInBlock/Flags/BytesSkipped info.
  1401. X * 
  1402. X * Revision 1.3  89/09/17  23:04:52  lee
  1403. X * Various fixes; NumberInBlock now a short...
  1404. X * 
  1405. X * Revision 1.2  89/09/16  21:15:49  lee
  1406. X * First demonstratable version.
  1407. X * 
  1408. X * Revision 1.1  89/09/07  21:06:16  lee
  1409. X * Initial revision
  1410. X * 
  1411. X */
  1412. @@@End of lq-text/src/h/wordinfo.h
  1413. echo x - lq-text/src/h/wordrules.h 1>&2
  1414. sed 's/^X//' >lq-text/src/h/wordrules.h <<'@@@End of lq-text/src/h/wordrules.h'
  1415. X/* wordrules.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  1416. X * This code is NOT in the public domain.
  1417. X * See the file COPYRIGHT for full details.
  1418. X */
  1419. X
  1420. X/* $Id: wordrules.h,v 1.2 90/10/06 02:18:39 lee Rel1-10 $
  1421. X *
  1422. X */
  1423. X
  1424. X/* Rules for determining what an indexable word looks like;
  1425. X * These are implemented by the various filters, as well as by
  1426. X * the indexing software itself.  This means that the filters
  1427. X * don't need to keep track of word lengths, as addfile will do this,
  1428. X * but that they should not emit non-word stuff if they can help it,
  1429. X * turning it into the equivalent amount (in bytes) of white-space
  1430. X * instead.
  1431. X * They should also turn words they don't want indexed into "qxxx",
  1432. X * with the right number of x's (e.g. "bare" --> "qxxx").
  1433. X */
  1434. X
  1435. X/* A "word" is a letter followed by any combination of
  1436. X * letters, digits or '_'.  An embedded (not trailing) ' is also allowed
  1437. X * (_ is allowed so that one can index progamming languages; strictly
  1438. X * speaking, a lot of languages allow _ at the start too, but I don't
  1439. X * want to get confused by nroff output etc., which contains lines of
  1440. X * underscores)
  1441. X *
  1442. X * This scheme currently excludes numbers...
  1443. X * 31, 31.4 and 31.9e4 will all be ignored.  So will 1987.
  1444. X */
  1445. X
  1446. X#define StartsWord(ch) isalpha(ch)
  1447. X#define WithinWord(ch) (isalnum(ch) || (ch == '_') || (ch == '\''))
  1448. X#define EndsWord(ch) isalnum(ch)
  1449. X
  1450. X/* Don't index words unless they are at least MinWordLength characters
  1451. X * long!
  1452. X */
  1453. X#define MinWordLength 3
  1454. X#define MaxWordLength 18 /* truncate words to this */
  1455. X/* The Following is for *.WordPlace.BlockInFile.  If words are constrained
  1456. X * to be 3 or more characters long, there can be at most
  1457. X * (FileBlockSize / 4) of them in a block (since words must be separated
  1458. X * by at least one character).
  1459. X * Hence, 7 bits, which allows 0..127 giving 128  distinct values,
  1460. X * gives us a block that is 128 * (MinWordLength + 1) bytes long.
  1461. X */
  1462. X#define FileBlockSize (128 * (MinWordLength + 1))
  1463. X
  1464. X/* WordPlace Flags:
  1465. X * When a plural word is found, or a possessive word, it is reduced to
  1466. X * being singular, and flags are set appropriately.
  1467. X * Also, a flag is set to say if the word started with a Capital Letter.
  1468. X * This puts Window, windows, and Window's all together, but enables them
  1469. X * to be differentiated for searching if required.
  1470. X * These flags are implemented by WordInfo and addfile, not by the various
  1471. X * filters, but the filters must preserve capitalisation of the first letter
  1472. X * in each word, and pass through apostrophes within words (like this's).
  1473. X */
  1474. X
  1475. X#define WPF_WASPLURAL        0001 /* The word...  ended in s */
  1476. X#define WPF_UPPERCASE        0002 /* ...Started with a capital letter */
  1477. X#define WPF_POSSESSIVE        0004 /* ...ended in 's */
  1478. X#define WPF_ENDEDINING        0010 /* ...ended in ing */
  1479. X#define WPF_LASTWASCOMMON    0020 /* the previous word was common */
  1480. X#define WPF_LASTHADLETTERS    0040 /* we skipped some letters to get here */
  1481. X#define WPF_HASSTUFFBEFORE    0100 /* Other than 1 byte of garbage before */
  1482. X#define WPF_LASTINBLOCK        0200 /* I'm the last word in this block */
  1483. X
  1484. X/* new note (jan 90):
  1485. X * You can't currently have both plural and posessive in the most common case
  1486. X * of the boys' muddy feet (for example), as the trailing ' gets deleted.
  1487. X * this doesn't matter, but perhaps that combination should be reserved for
  1488. X * had-another-standard-ending??? e.g. -ed or -ing, that isn't often followed by
  1489. X * -s or -'s...
  1490. X *
  1491. X * Also, ENDEDINING (ended in "ing") is currently unused entirely.
  1492. X * Perhaps if it is set, the plural and possessive bits should index which of
  1493. X * four endings was found, although this would preclude special-casing of the
  1494. X * s's combination.  Probably better that way.
  1495. X *
  1496. X * I should very much like to have another flag or two, perhaps embedded in
  1497. X * one of the other fields.  This might be feasible if there is a pre-scan
  1498. X * when the index is written to determine the most common (modal) flags and
  1499. X * distance (currently I assume 1) and to omit these whenever they are the default.
  1500. X * In this case, the fact that every occurrence of Jesus starts with a capital
  1501. X * letter (and ends in -s, *blush*), can still lead to most of the flags being
  1502. X * omitted.
  1503. X *
  1504. X * The next revision will separate the list of FIDs from the rest of the information,
  1505. X * in which case the embedding of the flags becomes a little trickier.  This
  1506. X * belongs in the TODO file now, sorry.
  1507. X *
  1508. X * Liam Quin, January 22nd 1990, at home in Warrington, England (ugh)
  1509. X *
  1510. X */
  1511. X
  1512. X/*
  1513. X * $Log:    wordrules.h,v $
  1514. X * Revision 1.2  90/10/06  02:18:39  lee
  1515. X * Prepared for first beta release.
  1516. X * 
  1517. X * Revision 1.1  90/08/09  19:16:05  lee
  1518. X * Initial revision
  1519. X * 
  1520. X * Revision 2.2  89/10/08  20:47:35  lee
  1521. X * Working version of nx-text engine.  Addfile and wordinfo work OK.
  1522. X * 
  1523. X * Revision 2.1  89/10/02  01:16:19  lee
  1524. X * New index format, with Block/WordInBlock/Flags/BytesSkipped info.
  1525. X * 
  1526. X * Revision 1.2  89/09/16  21:15:52  lee
  1527. X * First demonstratable version.
  1528. X * 
  1529. X * Revision 1.1  89/09/07  21:06:17  lee
  1530. X * Initial revision
  1531. X * 
  1532. X */
  1533. @@@End of lq-text/src/h/wordrules.h
  1534. echo end of part 02
  1535. -- 
  1536. Liam R. E. Quin,  lee@sq.com, SoftQuad Inc., Toronto, +1 (416) 963-8337
  1537.