lib/snofmake.c File Reference

#include "common.h"
#include "localmem.h"
#include "snofmake.h"
#include "errabort.h"

Include dependency graph for snofmake.c:

Go to the source code of this file.

Data Structures

struct  offsetList

Functions

static void ourErrAbort ()
static void initMem ()
static void cleanupMem ()
static void * localNeedMem (int size)
static struct offsetListnewOffset (char *name, int nameLen)
static int cmpOffsetPointers (const void *va, const void *vb)
static int longestNameSize (struct offsetList *list)
static struct offsetListmakeOffsetList (FILE *inFile, boolean(*nextRecord)(FILE *inFile, void *data, char **rName, int *rNameLen), void *data)
boolean warnAboutDupes (struct offsetList **array, int size)
static void makeIndex (FILE *in, FILE *out, boolean(*nextRecord)(FILE *in, void *data, char **rName, int *rNameLen), void *data, boolean dupeOk)
boolean snofDupeOkIndex (FILE *inFile, char *outName, boolean(*nextRecord)(FILE *inFile, void *data, char **rName, int *rNameLen), void *data, boolean dupeOk)
boolean snofMakeIndex (FILE *inFile, char *outName, boolean(*nextRecord)(FILE *inFile, void *data, char **rName, int *rNameLen), void *data)

Variables

static char const rcsid [] = "$Id: snofmake.c,v 1.5 2003/05/06 07:33:44 kate Exp $"
static jmp_buf errRecover
static struct lmlm


Function Documentation

static void cleanupMem (  )  [static]

Definition at line 29 of file snofmake.c.

References lm, and lmCleanup().

Referenced by snofDupeOkIndex().

00030 {
00031 lmCleanup(&lm);
00032 }

Here is the call graph for this function:

Here is the caller graph for this function:

static int cmpOffsetPointers ( const void *  va,
const void *  vb 
) [static]

Definition at line 56 of file snofmake.c.

References offsetList::name.

Referenced by makeIndex().

00058 {
00059 struct offsetList **pa, **pb;
00060 struct offsetList *a, *b;
00061 pa = (struct offsetList **)va;
00062 pb = (struct offsetList **)vb;
00063 a = *pa;
00064 b = *pb;
00065 return strcmp(a->name, b->name);
00066 }

Here is the caller graph for this function:

static void initMem (  )  [static]

Definition at line 24 of file snofmake.c.

References lm, and lmInit().

Referenced by snofDupeOkIndex().

00025 {
00026 lm = lmInit((1<<16));
00027 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void* localNeedMem ( int  size  )  [static]

Definition at line 34 of file snofmake.c.

References lm, and lmAlloc().

Referenced by makeIndex(), and newOffset().

00035 {
00036 return lmAlloc(lm, size);
00037 }

Here is the call graph for this function:

Here is the caller graph for this function:

static int longestNameSize ( struct offsetList list  )  [static]

Definition at line 68 of file snofmake.c.

References offsetList::name, and offsetList::next.

Referenced by makeIndex().

00069 {
00070 struct offsetList *el;
00071 int size, longestSize = 0;
00072 
00073 for (el = list; el != NULL; el = el->next)
00074     {
00075     size = strlen(el->name);
00076     if (size > longestSize) 
00077         {
00078         longestSize = size;
00079         }
00080     }
00081 return longestSize;
00082 }

Here is the caller graph for this function:

static void makeIndex ( FILE *  in,
FILE *  out,
boolean(*)(FILE *in, void *data, char **rName, int *rNameLen)  nextRecord,
void *  data,
boolean  dupeOk 
) [static]

Definition at line 132 of file snofmake.c.

References cmpOffsetPointers(), localNeedMem(), longestNameSize(), makeOffsetList(), mustWrite(), name, offsetList::next, offsetList::offset, slCount(), snofSignature(), warnAboutDupes(), and zeroBytes().

Referenced by snofDupeOkIndex().

00136 {
00137 struct offsetList *list;
00138 int listSize;
00139 struct offsetList **array;
00140 int i;
00141 struct offsetList *el;
00142 int nameSize;
00143 char *nameBuf;
00144 char *indexSig;
00145 int indexSigSize;
00146 
00147 printf("Reading input\n");
00148 list = makeOffsetList(in, nextRecord, data);
00149 listSize = slCount(list);
00150 array = localNeedMem(listSize * sizeof(*array));
00151 nameSize = longestNameSize(list)+1;
00152 
00153 printf("Got %d offsets %d nameSize.  Sorting...\n", listSize, nameSize);
00154 nameBuf = localNeedMem(nameSize);
00155 
00156 /* Make an array of pointers, one for each element in list. */
00157 for (i=0, el = list; i<listSize; i+=1, el = el->next)
00158     array[i] = el;
00159 
00160 /* Sort alphabetically based on name. */
00161 qsort(array, listSize, sizeof(array[0]), cmpOffsetPointers);
00162 if (!dupeOk)
00163     warnAboutDupes(array, listSize);
00164 
00165 /* Write out file header */
00166 printf("Writing index file \n");
00167 snofSignature(&indexSig, &indexSigSize);
00168 mustWrite(out, indexSig, indexSigSize);
00169 mustWrite(out, &nameSize, sizeof(nameSize));
00170     
00171 /* Write out sorted output */
00172 for (i=0; i<listSize; ++i)
00173     {
00174     zeroBytes(nameBuf, nameSize);
00175     strcpy(nameBuf, array[i]->name);
00176     mustWrite(out, nameBuf, nameSize);
00177     mustWrite(out, &array[i]->offset, sizeof(array[i]->offset));
00178     }
00179 }

Here is the call graph for this function:

Here is the caller graph for this function:

static struct offsetList* makeOffsetList ( FILE *  inFile,
boolean(*)(FILE *inFile, void *data, char **rName, int *rNameLen)  nextRecord,
void *  data 
) [static, read]

Definition at line 84 of file snofmake.c.

References name, newOffset(), offsetList::next, offsetList::offset, and slReverse().

Referenced by makeIndex().

00087 {
00088 struct offsetList *list = NULL;
00089 struct offsetList *newEl;
00090 for (;;)
00091     {
00092     long offset = ftell(inFile);
00093     char *name;
00094     int nameLen;
00095     if (!nextRecord(inFile, data, &name, &nameLen))
00096         break;
00097     if (nameLen > 0)
00098         {
00099         newEl = newOffset(name, nameLen);
00100         newEl->offset = offset;
00101         newEl->next = list;
00102         list = newEl;
00103         }
00104     }
00105 slReverse(&list);
00106 return list;
00107 }

Here is the call graph for this function:

Here is the caller graph for this function:

static struct offsetList* newOffset ( char *  name,
int  nameLen 
) [static, read]

Definition at line 46 of file snofmake.c.

References localNeedMem().

Referenced by makeOffsetList(), and xaReadNext().

00048 {
00049 struct offsetList *nl = localNeedMem(sizeof(*nl));
00050 nl->name = localNeedMem(nameLen+1);
00051 memcpy(nl->name, name, nameLen);
00052 nl->name[nameLen] = 0;
00053 return nl;
00054 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void ourErrAbort (  )  [static]

Definition at line 15 of file snofmake.c.

References errRecover.

Referenced by snofDupeOkIndex().

00018 {
00019 longjmp(errRecover, -1);
00020 }

Here is the caller graph for this function:

boolean snofDupeOkIndex ( FILE *  inFile,
char *  outName,
boolean(*)(FILE *inFile, void *data, char **rName, int *rNameLen)  nextRecord,
void *  data,
boolean  dupeOk 
)

Definition at line 181 of file snofmake.c.

References cleanupMem(), errRecover, FALSE, initMem(), makeIndex(), ourErrAbort(), popAbortHandler(), and pushAbortHandler().

Referenced by snofMakeIndex().

00186 {
00187 FILE *outFile;
00188 int status;
00189 
00190 /* Initialize */
00191 if ((outFile = fopen(outName, "wb")) == NULL)
00192     {
00193     fprintf(stderr, "Couldn't create index file %s\n", outName);
00194     return FALSE;
00195     }
00196 initMem();
00197 
00198 /* Wrap error recovery around main routine. */
00199 status = setjmp(errRecover);
00200 if (status == 0)
00201     {
00202     pushAbortHandler(ourErrAbort);
00203     makeIndex(inFile, outFile, nextRecord, data, dupeOk);
00204     }
00205 popAbortHandler();
00206 
00207 /* Cleanup. */
00208 fclose(outFile);
00209 cleanupMem();
00210 return status == 0;
00211 }

Here is the call graph for this function:

Here is the caller graph for this function:

boolean snofMakeIndex ( FILE *  inFile,
char *  outName,
boolean(*)(FILE *inFile, void *data, char **rName, int *rNameLen)  nextRecord,
void *  data 
)

Definition at line 213 of file snofmake.c.

References FALSE, and snofDupeOkIndex().

00217          :
00218  *     inFile - open file that you're indexing with header read and verified.
00219  *     outName - name of index file to create
00220  *     nextRecord - function that reads next record in file you're indexing
00221  *                  and returns the name of that record.
00222  *     data - void pointer passed through to nextRecord.
00223  *
00224  * In this implementation this function just is an error recovery wrapper
00225  * around the local function makeIndex, which does the real work. */
00226 {
00227 return snofDupeOkIndex(inFile, outName, nextRecord, data, FALSE);
00228 }

Here is the call graph for this function:

boolean warnAboutDupes ( struct offsetList **  array,
int  size 
)

Definition at line 109 of file snofmake.c.

References differentWord(), FALSE, offsetList::name, name, TRUE, and warn().

Referenced by makeIndex().

00111 {
00112 char *name, *prevName;
00113 int i;
00114 boolean ok = TRUE;
00115 
00116 if (size < 2)
00117     return FALSE;
00118 prevName = array[0]->name;
00119 for (i=1; i<size; ++i)
00120     {
00121     name = array[i]->name;
00122     if (!differentWord(name, prevName))
00123         {
00124         warn("Duplicate strings: %s %s", prevName, name);
00125         ok = FALSE;
00126         }
00127     prevName = name;
00128     }
00129 return ok;
00130 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

jmp_buf errRecover [static]

Definition at line 13 of file snofmake.c.

Referenced by ourErrAbort(), and snofDupeOkIndex().

struct lm* lm [static]

Definition at line 22 of file snofmake.c.

char const rcsid[] = "$Id: snofmake.c,v 1.5 2003/05/06 07:33:44 kate Exp $" [static]

Definition at line 11 of file snofmake.c.


Generated on Tue Dec 25 20:16:59 2007 for blat by  doxygen 1.5.2