goer@ellis.uchicago.edu (Richard L. Goerwitz) (03/27/91)
Sometimes it's not convenient to insert numerous and/or large blocks of text into hash tables at run-time. Some time ago I posted some simple routines which make it possible to perform table-like operations on files containing key/value combinations. I've updated these rou- tines a bit, and expanded them slightly. Instead of reposting, I've decided to mail them out individually to anyone who asks. -Richard ------------ From the README file: This archive contains gettext() and associated routines. Gettext() allows the user to maintain a file of key/value combinations such that a call to gettext(key, FNAME) will produce value. Fails if no such key exists. Returns an empty string if the key exists, but has no associated value in the file named in arg 2 (FNAME). Gettext() is intended for use in situations where keys need to be associated with very large strings (i.e. where hand-inserting these values into hash tables would be unwieldy, and would take up a sizable chunk of memory). The file format is simple. Keys belong on separate lines, marked as such by an initial colon+colon (::). Values begin on the line following their respective keys, and extend up to the next colon+colon-initial line or EOF. E.g. ::sample.1 Notice how the key above, sample.1, has :: prepended to mark it out as a key. The text you are now reading represents that key's value. To retrieve this text, you would call gettext() with the name of the key passed as its first argument, and the name of the file in which this text is stored as its second argument (as in gettext("sample.1","tmp.idx")). ::next.key etc... For faster access, an indexing utility is included, idxtext. Idxtext creates a separate index for a given text-base file. If an index file exists in the same directory as FNAME, gettext() will make use of it. Otherwise, it just does a sequential search of the entire file (this works fine for smaller files). Please don't change a file, once you've run idxtext on it, except to append key/value entries to it. If you alter the indexed portion of the file in any way, you must reindex. If you want a list of all the keys in FNAME, call getkeys(FNAME). Getkeys (as one might expect) resides in the file getkeys.icn. I guess an in-core regexp pattern search could be implemented by stuffing all keys for a given text-base file into a list, and then using findre.icn to match patterns agains the keys (hits could then be retrieved via calls to gettext()). -- -Richard L. Goerwitz goer%sophist@uchicago.bitnet goer@sophist.uchicago.edu rutgers!oddjob!gide!sophist!goer