00001 /***************************************************************************** 00002 * Copyright (C) 2000 Jim Kent. This source code may be freely used * 00003 * for personal, academic, and non-profit purposes. Commercial use * 00004 * permitted only by explicit agreement with Jim Kent (jim_kent@pacbell.net) * 00005 *****************************************************************************/ 00006 /* snof.h - Sorted Name Offset File - stuff to handle a simple 00007 * indexed file. 00008 * 00009 * This accesses a file of name/offset pairs that are sorted by 00010 * name. Does a binary search of file to find the offset given name. 00011 * Most typically this is used to do a quick lookup given an index file. 00012 */ 00013 00014 struct snof 00015 /* Sorted Name Offset File structure. Get one from snofOpen. Use 00016 * with snofFindOffset. Finish up with snofClose. */ 00017 { 00018 FILE *file; 00019 int maxNameSize; 00020 int itemSize; 00021 int headSize; 00022 int endIx; 00023 char *first; 00024 char *last; 00025 char *less; 00026 char *mid; 00027 char *more; 00028 }; 00029 00030 struct snof *snofOpen(char *indexName); 00031 /* Open up the index file. Returns NULL if there's any problem. */ 00032 00033 struct snof *snofMustOpen(char *indexName); 00034 /* Open up index file or die. */ 00035 00036 void snofClose(struct snof **pSnof); 00037 /* Close down the index file. */ 00038 00039 int snofElementCount(struct snof *snof); 00040 /* How many names are in snof file? */ 00041 00042 long snofOffsetAtIx(struct snof *snof, int ix); 00043 /* The offset of a particular index in file. */ 00044 00045 char *snofNameAtIx(struct snof *snof, int ix); 00046 /* The name at a particular index in file. (This will be overwritten by 00047 * later calls to snof system. Strdup if you want to keep it.) 00048 */ 00049 00050 void snofNameOffsetAtIx(struct snof *snof, int ix, char **pName, long *pOffset); 00051 /* Get both name and offset for an index. */ 00052 00053 boolean snofFindFirstStartingWith(struct snof *snof, char *prefix, int prefixSize, 00054 int *pSnofIx); 00055 /* Find first index in snof file whose name begins with prefix. */ 00056 00057 boolean snofFindOffset(struct snof *snof, char *name, long *pOffset); 00058 /* Find offset corresponding with name. Returns FALSE if no such name 00059 * in the index file. */ 00060
1.5.2