inc/obscure.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

long incCounterFile (char *fileName)
int digitsBaseTwo (unsigned long x)
int digitsBaseTen (int x)
void sprintLongWithCommas (char *s, long long l)
void printLongWithCommas (FILE *f, long long l)
void writeGulp (char *file, char *buf, int size)
void readInGulp (char *fileName, char **retBuf, size_t *retSize)
void readAllWords (char *fileName, char ***retWords, int *retWordCount, char **retBuf)
int countWordsInFile (char *fileName)
slNamereadAllLines (char *fileName)
void copyFile (char *source, char *dest)
void copyOpenFile (FILE *inFh, FILE *outFh)
void cpFile (int s, int d)
void * intToPt (int i)
int ptToInt (void *pt)
void * sizetToPt (size_t i)
size_t ptToSizet (void *pt)
boolean parseQuotedString (char *in, char *out, char **retNext)
char * nextQuotedWord (char **pLine)
char * makeQuotedString (char *in, char quoteChar)
char * makeEscapedString (char *in, char toEscape)
void escCopy (char *in, char *out, char toEscape, char escape)
slNamestringToSlNames (char *string)
slNamecommaSepToSlNames (char *commaSep)
slNamecharSepToSlNames (char *string, char c)
hashhashVarLine (char *line, int lineIx)
hashhashWordsInFile (char *fileName, int hashSize)
hashhashNameIntFile (char *fileName)
hashhashTwoColumnFile (char *fileName)
void shuffleArrayOfPointers (void *pointerArray, int arraySize, int shuffleCount)
void shuffleList (void *pList, int shuffleCount)
char * stripCommas (char *position)
void dotForUserInit (int dotMod)
void dotForUser ()
void spaceToUnderbar (char *s)


Function Documentation

struct slName* charSepToSlNames ( char *  string,
char  c 
) [read]

Definition at line 456 of file obscure.c.

References slAddHead, slNameNew, slNameNewN(), and slReverse().

Referenced by commaSepToSlNames().

00461 {
00462 struct slName *list = NULL, *el;
00463 char *s, *e;
00464 
00465 s = string;
00466 while (s != NULL && s[0] != 0)
00467     {
00468     e = strchr(s, c);
00469     if (e == NULL)
00470         {
00471         el = slNameNew(s);
00472         slAddHead(&list, el);
00473         break;
00474         }
00475     else
00476         {
00477         el = slNameNewN(s, e - s);
00478         slAddHead(&list, el);
00479         s = e+1;
00480         }
00481     }
00482 slReverse(&list);
00483 return list;
00484 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct slName* commaSepToSlNames ( char *  commaSep  )  [read]

Definition at line 486 of file obscure.c.

References charSepToSlNames().

Referenced by spacedColumnFromSizeCommaList().

00488 {
00489 return charSepToSlNames(commaSep, ',');
00490 }

Here is the call graph for this function:

Here is the caller graph for this function:

void copyFile ( char *  source,
char *  dest 
)

Definition at line 185 of file obscure.c.

References errAbort(), errno, errnoAbort(), freeMem(), and needMem().

00187 {
00188 int bufSize = 64*1024;
00189 char *buf = needMem(bufSize);
00190 int bytesRead;
00191 int s, d;
00192 
00193 s = open(source, O_RDONLY);
00194 if (s < 0)
00195     errAbort("Couldn't open %s. %s\n", source, strerror(errno));
00196 d = creat(dest, 0777);
00197 if (d < 0)
00198     {
00199     close(s);
00200     errAbort("Couldn't open %s. %s\n", dest, strerror(errno));
00201     }
00202 while ((bytesRead = read(s, buf, bufSize)) > 0)
00203     {
00204     if (write(d, buf, bytesRead) < 0)
00205         errAbort("Write error on %s. %s\n", dest, strerror(errno));
00206     }
00207 close(s);
00208 if (close(d) != 0)
00209     errnoAbort("close failed");
00210 freeMem(buf);
00211 }

Here is the call graph for this function:

void copyOpenFile ( FILE *  inFh,
FILE *  outFh 
)

Definition at line 213 of file obscure.c.

References errnoAbort().

00215 {
00216 int c;
00217 while ((c = fgetc(inFh)) != EOF)
00218     fputc(c, outFh);
00219 if (ferror(inFh))
00220     errnoAbort("file read failed");
00221 if (ferror(outFh))
00222     errnoAbort("file write failed");
00223 }

Here is the call graph for this function:

int countWordsInFile ( char *  fileName  ) 

Definition at line 113 of file obscure.c.

References chopByWhite(), lineFileClose(), lineFileNext(), lineFileOpen(), and TRUE.

00115 {
00116 struct lineFile *lf = lineFileOpen(fileName, TRUE);
00117 char *line;
00118 int wordCount = 0;
00119 while (lineFileNext(lf, &line, NULL))
00120     wordCount += chopByWhite(line, NULL, 0);
00121 lineFileClose(&lf);
00122 return wordCount;
00123 }

Here is the call graph for this function:

void cpFile ( int  s,
int  d 
)

Definition at line 225 of file obscure.c.

References freeMem(), and needMem().

00227 {
00228 int bufSize = 64*1024, readSize;
00229 char *buf = needMem(bufSize);
00230 
00231 for (;;)
00232     {
00233     readSize = read(s, buf, bufSize);
00234     if (readSize > 0)
00235         write(d, buf, readSize);
00236     if (readSize <= 0)
00237         break;
00238     }
00239 freeMem(buf);
00240 }

Here is the call graph for this function:

int digitsBaseTen ( int  x  ) 

Definition at line 53 of file obscure.c.

Referenced by axtPrintTraditional(), calcDigitCount(), mafWrite(), and maxDigits().

00055 {
00056 int digCount = 1;
00057 if (x < 0)
00058     {
00059     digCount = 2;
00060     x = -x;
00061     }
00062 while (x >= 10)
00063     {
00064     digCount += 1;
00065     x /= 10;
00066     }
00067 return digCount;
00068 }

Here is the caller graph for this function:

int digitsBaseTwo ( unsigned long  x  ) 

Definition at line 41 of file obscure.c.

Referenced by dnaSeqHash(), ffCalcCdnaGapPenalty(), leftNextMatch(), rightNextMatch(), and twoBitOpen().

00043 {
00044 int digits = 0;
00045 while (x)
00046     {
00047     digits += 1;
00048     x >>= 1;
00049     }
00050 return digits;
00051 }

Here is the caller graph for this function:

void dotForUser (  ) 

Definition at line 602 of file obscure.c.

References _dotForUserMod.

00604 {
00605 static int dot = -10;
00606 /* Check to see if dot has been initialized. */
00607 if(dot == - 10)
00608     dot = _dotForUserMod;
00609 
00610 if (--dot <= 0)
00611     {
00612     putc('.', stderr);
00613     fflush(stderr);
00614     dot = _dotForUserMod;
00615     }
00616 }

void dotForUserInit ( int  dotMod  ) 

Definition at line 595 of file obscure.c.

References _dotForUserMod.

00597 {
00598 assert(dotMod > 0);
00599 _dotForUserMod = dotMod;
00600 }

void escCopy ( char *  in,
char *  out,
char  toEscape,
char  escape 
)

Definition at line 342 of file obscure.c.

Referenced by makeEscapedString(), and makeQuotedString().

00345 {
00346 char c;
00347 for (;;)
00348     {
00349     c = *in++;
00350     if (c == toEscape)
00351         *out++ = escape;
00352     *out++ = c;
00353     if (c == 0)
00354         break;
00355     }
00356 }

Here is the caller graph for this function:

struct hash* hashNameIntFile ( char *  fileName  )  [read]

Definition at line 140 of file obscure.c.

References hashAddInt(), hashNew, lineFileClose(), lineFileNeedNum(), lineFileOpen(), lineFileRow, and TRUE.

00143 {
00144 struct lineFile *lf = lineFileOpen(fileName, TRUE);
00145 char *row[2];
00146 struct hash *hash = hashNew(16);
00147 while (lineFileRow(lf, row))
00148     hashAddInt(hash, row[0], lineFileNeedNum(lf, row, 1));
00149 lineFileClose(&lf);
00150 return hash;
00151 }

Here is the call graph for this function:

struct hash* hashTwoColumnFile ( char *  fileName  )  [read]

Definition at line 153 of file obscure.c.

References hashAdd(), hashNew, lineFileClose(), lineFileOpen(), lineFileRow, hash::lm, lmCloneString(), name, and TRUE.

00155 {
00156 struct lineFile *lf = lineFileOpen(fileName, TRUE);
00157 char *row[2];
00158 struct hash *hash = hashNew(16);
00159 while (lineFileRow(lf, row))
00160     {
00161     char *name = row[0];
00162     char *value = lmCloneString(hash->lm, row[1]);
00163     hashAdd(hash, name, value);
00164     }
00165 lineFileClose(&lf);
00166 return hash;
00167 }

Here is the call graph for this function:

struct hash* hashVarLine ( char *  line,
int  lineIx 
) [read]

Definition at line 381 of file obscure.c.

References cloneString(), errAbort(), freez(), hashAdd(), newHash(), parseQuotedString(), skipLeadingSpaces(), and skipToSpaces().

00382                                             :
00383  *   var1=val1 var2='quoted val2' var3="another val" */
00384 {
00385 char *dupe = cloneString(line);
00386 char *s = dupe, c;
00387 char *var, *val;
00388 struct hash *hash = newHash(8);
00389 
00390 for (;;)
00391     {
00392     if ((var = skipLeadingSpaces(s)) == NULL)
00393         break;
00394 
00395     if ((c = *var) == 0)
00396         break;
00397     if (!isalpha(c))
00398         errAbort("line %d of custom input: variable needs to start with letter '%s'", lineIx, var);
00399     val = strchr(var, '=');
00400     if (val == NULL)
00401         {
00402         errAbort("line %d of var %s in custom input: %s \n missing = in var/val pair", lineIx, var, line);
00403         }
00404     *val++ = 0;
00405     c = *val;
00406     if (c == '\'' || c == '"')
00407         {
00408         if (!parseQuotedString(val, val, &s))
00409             errAbort("line %d of input: missing closing %c", lineIx, c);
00410         }
00411     else
00412         {
00413         s = skipToSpaces(val);
00414         if (s != NULL) *s++ = 0;
00415         }
00416     hashAdd(hash, var, cloneString(val));
00417     }
00418 freez(&dupe);
00419 return hash;
00420 }

Here is the call graph for this function:

struct hash* hashWordsInFile ( char *  fileName,
int  hashSize 
) [read]

Definition at line 125 of file obscure.c.

References hashAdd(), lineFileClose(), lineFileNext(), lineFileOpen(), newHash(), nextWord(), and TRUE.

00127 {
00128 struct hash *hash = newHash(hashSize);
00129 struct lineFile *lf = lineFileOpen(fileName, TRUE);
00130 char *line, *word;
00131 while (lineFileNext(lf, &line, NULL))
00132     {
00133     while ((word = nextWord(&line)) != NULL)
00134         hashAdd(hash, word, NULL);
00135     }
00136 lineFileClose(&lf);
00137 return hash;
00138 }

Here is the call graph for this function:

long incCounterFile ( char *  fileName  ) 

Definition at line 17 of file obscure.c.

References errnoAbort().

Referenced by _makeTempName().

00019 {
00020 long val = 0;
00021 FILE *f = fopen(fileName, "r+b");
00022 if (f != NULL)
00023     {
00024     fread(&val, sizeof(val), 1, f);
00025     rewind(f);
00026     }
00027 else
00028     {
00029     f = fopen(fileName, "wb");
00030     }
00031 ++val;
00032 if (f != NULL)
00033     {
00034     fwrite(&val, sizeof(val), 1, f);
00035     if (fclose(f) != 0)
00036         errnoAbort("fclose failed");
00037     }
00038 return val;
00039 }

Here is the call graph for this function:

Here is the caller graph for this function:

void* intToPt ( int  i  ) 

Definition at line 242 of file obscure.c.

00245 {
00246 char *pt = NULL;
00247 return pt+i;
00248 }

char* makeEscapedString ( char *  in,
char  toEscape 
)

Definition at line 358 of file obscure.c.

References countChars(), escCopy(), and needMem().

00362 {
00363 int newSize = strlen(in) + countChars(in, toEscape);
00364 char *out = needMem(newSize+1);
00365 escCopy(in, out, toEscape, '\\');
00366 return out;
00367 }

Here is the call graph for this function:

char* makeQuotedString ( char *  in,
char  quoteChar 
)

Definition at line 369 of file obscure.c.

References countChars(), escCopy(), and needMem().

00372 {
00373 int newSize = 2 + strlen(in) + countChars(in, quoteChar);
00374 char *out = needMem(newSize+1);
00375 out[0] = quoteChar;
00376 escCopy(in, out+1, quoteChar, '\\');
00377 out[newSize-1] = quoteChar;
00378 return out;
00379 }

Here is the call graph for this function:

char* nextQuotedWord ( char **  pLine  ) 

Definition at line 319 of file obscure.c.

References nextWord(), parseQuotedString(), and skipLeadingSpaces().

00324 {
00325 char *line, c;
00326 line = skipLeadingSpaces(*pLine);
00327 if (line == NULL || line[0] == 0)
00328     return NULL;
00329 c = *line;
00330 if (c == '"' || c == '\'')
00331     {
00332     if (!parseQuotedString(line, line, pLine))
00333         return NULL;
00334     return line;
00335     }
00336 else
00337     {
00338     return nextWord(pLine);
00339     }
00340 }

Here is the call graph for this function:

boolean parseQuotedString ( char *  in,
char *  out,
char **  retNext 
)

Definition at line 274 of file obscure.c.

References FALSE, TRUE, and warn().

Referenced by apacheAccessLogParse(), hashVarLine(), htmlTagScan(), needQuotedString(), nextQuotedWord(), readQuotedString(), and stringToSlNames().

00279 {
00280 char c, *s = in;
00281 int quoteChar = *s++;
00282 boolean escaped = FALSE;
00283 
00284 for (;;)
00285    {
00286    c = *s++;
00287    if (c == 0)
00288        {
00289        warn("Unmatched %c", quoteChar);
00290        return FALSE;
00291        }
00292    if (escaped)
00293        {
00294        if (c == '\\' || c == quoteChar)
00295           *out++ = c;
00296        else
00297           {
00298           *out++ = '\\';
00299           *out++ = c;
00300           }
00301        escaped = FALSE;
00302        }
00303    else
00304        {
00305        if (c == '\\')
00306            escaped = TRUE;
00307        else if (c == quoteChar)
00308            break;
00309        else
00310            *out++ = c;
00311        }
00312    }
00313 *out = 0;
00314 if (retNext != NULL)
00315     *retNext = s;
00316 return TRUE;
00317 }

Here is the call graph for this function:

Here is the caller graph for this function:

void printLongWithCommas ( FILE *  f,
long long  l 
)

Definition at line 525 of file obscure.c.

References sprintLongWithCommas().

00527 {
00528 char ascii[32];
00529 sprintLongWithCommas(ascii, l);
00530 fprintf(f, "%s", ascii);
00531 }

Here is the call graph for this function:

int ptToInt ( void *  pt  ) 

Definition at line 250 of file obscure.c.

Referenced by hashIntSum(), hashIntVal(), and hashIntValDefault().

00253 {
00254 char *a = NULL, *b = pt;
00255 return b - a;
00256 }

Here is the caller graph for this function:

size_t ptToSizet ( void *  pt  ) 

Definition at line 266 of file obscure.c.

00269 {
00270 char *a = NULL, *b = pt;
00271 return b - a;
00272 }

struct slName* readAllLines ( char *  fileName  )  [read]

Definition at line 169 of file obscure.c.

References lineFileNext(), lineFileOpen(), newSlName(), slAddHead, slReverse(), and TRUE.

00171 {
00172 struct lineFile *lf = lineFileOpen(fileName, TRUE);
00173 struct slName *list = NULL, *el;
00174 char *line;
00175 
00176 while (lineFileNext(lf, &line, NULL))
00177      {
00178      el = newSlName(line);
00179      slAddHead(&list, el);
00180      }
00181 slReverse(&list);
00182 return list;
00183 }

Here is the call graph for this function:

void readAllWords ( char *  fileName,
char ***  retWords,
int *  retWordCount,
char **  retBuf 
)

Definition at line 92 of file obscure.c.

References chopByWhite(), needMem(), and readInGulp().

Referenced by gfClientFileArray().

00095 {
00096 int wordCount;
00097 char *buf = NULL;
00098 char **words = NULL;
00099 size_t bufSize;
00100 
00101 readInGulp(fileName, &buf, &bufSize);
00102 wordCount = chopByWhite(buf, NULL, 0);
00103 if (wordCount != 0)
00104     {
00105     words = needMem(wordCount * sizeof(words[0]));
00106     chopByWhite(buf, words, wordCount);
00107     }
00108 *retWords = words;
00109 *retWordCount = wordCount;
00110 *retBuf = buf;
00111 }

Here is the call graph for this function:

Here is the caller graph for this function:

void readInGulp ( char *  fileName,
char **  retBuf,
size_t *  retSize 
)

Definition at line 78 of file obscure.c.

References fileSize(), mustOpen(), mustRead(), and needLargeMem().

Referenced by axtScoreSchemeProteinRead(), htmlIncludeFile(), htmlPageGet(), and readAllWords().

00080 {
00081 size_t size = (size_t)fileSize(fileName);
00082 char *buf;
00083 FILE *f = mustOpen(fileName, "rb");
00084 *retBuf = buf = needLargeMem(size+1);
00085 mustRead(f, buf, size);
00086 buf[size] = 0;      /* Just in case it needs zero termination. */
00087 fclose(f);
00088 if (retSize != NULL)
00089     *retSize = size;
00090 }

Here is the call graph for this function:

Here is the caller graph for this function:

void shuffleArrayOfPointers ( void *  pointerArray,
int  arraySize,
int  shuffleCount 
)

Definition at line 533 of file obscure.c.

Referenced by shuffleList().

00535 {
00536 void **array = pointerArray, *pt;
00537 int i, randIx;
00538 
00539 for (i=0; i<arraySize; ++i)
00540     {
00541     randIx = rand() % arraySize;
00542     pt = array[i];
00543     array[i] = array[randIx];
00544     array[randIx] = pt;
00545     }
00546 }

Here is the caller graph for this function:

void shuffleList ( void *  pList,
int  shuffleCount 
)

Definition at line 548 of file obscure.c.

References freeMem(), needLargeMem(), slList::next, shuffleArrayOfPointers(), slCount(), and slReverse().

00549                                     :
00550  *     randomizeList(&list)
00551  * where list is a pointer to a structure that
00552  * begins with a next field. */
00553 {
00554 struct slList **pL = (struct slList **)pList;
00555 struct slList *list = *pL;
00556 int count;
00557 count = slCount(list);
00558 if (count > 1)
00559     {
00560     struct slList *el;
00561     struct slList **array;
00562     int i;
00563     array = needLargeMem(count * sizeof(*array));
00564     for (el = list, i=0; el != NULL; el = el->next, i++)
00565         array[i] = el;
00566     for (i=0; i<4; ++i)
00567         shuffleArrayOfPointers(array, count, shuffleCount);
00568     list = NULL;
00569     for (i=0; i<count; ++i)
00570         {
00571         array[i]->next = list;
00572         list = array[i];
00573         }
00574     freeMem(array);
00575     slReverse(&list);
00576     *pL = list;       
00577     }
00578 }

Here is the call graph for this function:

void* sizetToPt ( size_t  i  ) 

Definition at line 258 of file obscure.c.

00261 {
00262 char *pt = NULL;
00263 return pt+i;
00264 }

void spaceToUnderbar ( char *  s  ) 

Definition at line 618 of file obscure.c.

00620 {
00621 char c;
00622 while ((c = *s) != 0)
00623     {
00624     if (isspace(c))
00625         *s = '_';
00626     ++s;
00627     }
00628 }

void sprintLongWithCommas ( char *  s,
long long  l 
)

Definition at line 493 of file obscure.c.

Referenced by carefulAlloc(), ncbiBlastOut(), printLongWithCommas(), and wuBlastOut().

00495 {
00496 long long billions, millions, thousands;
00497 if (l >= 1000000000)
00498     {
00499     billions = l/1000000000;
00500     l -= billions * 1000000000;
00501     millions = l/1000000;
00502     l -= millions * 1000000;
00503     thousands = l/1000;
00504     l -= thousands * 1000;
00505     sprintf(s, "%lld,%03lld,%03lld,%03lld", billions, millions, thousands, l);
00506     }
00507 else if (l >= 1000000)
00508     {
00509     millions = l/1000000;
00510     l -= millions * (long long)1000000;
00511     thousands = l/1000;
00512     l -= thousands * 1000;
00513     sprintf(s, "%lld,%03lld,%03lld", millions, thousands, l);
00514     }
00515 else if (l >= 1000)
00516     {
00517     thousands = l/1000;
00518     l -= thousands * 1000;
00519     sprintf(s, "%lld,%03lld", thousands, l);
00520     }
00521 else
00522     sprintf(s, "%lld", l);
00523 }

Here is the caller graph for this function:

struct slName* stringToSlNames ( char *  string  )  [read]

Definition at line 422 of file obscure.c.

References cloneString(), errAbort(), freeMem(), name, parseQuotedString(), skipLeadingSpaces(), skipToSpaces(), slAddHead, slNameNew, and slReverse().

00426 {
00427 struct slName *list = NULL, *name;
00428 char *dupe = cloneString(string);
00429 char c, *s = dupe, *e;
00430 
00431 for (;;)
00432     {
00433     if ((s = skipLeadingSpaces(s)) == NULL)
00434         break;
00435     if ((c = *s) == 0)
00436         break;
00437     if (c == '\'' || c == '"')
00438         {
00439         if (!parseQuotedString(s, s, &e))
00440             errAbort("missing closing %c in %s", c, string);
00441         }
00442     else
00443         {
00444         e = skipToSpaces(s);
00445         if (e != NULL) *e++ = 0;
00446         }
00447     name = slNameNew(s);
00448     slAddHead(&list, name);
00449     s = e;
00450     }
00451 freeMem(dupe);
00452 slReverse(&list);
00453 return list;
00454 }

Here is the call graph for this function:

char* stripCommas ( char *  position  ) 

Definition at line 580 of file obscure.c.

References cloneString().

00582 {
00583 char *newPos = cloneString(position);
00584 char *nPtr = newPos;
00585 
00586 if (position == NULL)
00587     return NULL;
00588 while((*nPtr = *position++))
00589     if (*nPtr != ',')
00590         nPtr++;
00591 
00592 return newPos;
00593 }

Here is the call graph for this function:

void writeGulp ( char *  file,
char *  buf,
int  size 
)

Definition at line 70 of file obscure.c.

References carefulClose(), mustOpen(), and mustWrite().

00072 {
00073 FILE *f = mustOpen(file, "w");
00074 mustWrite(f, buf, size);
00075 carefulClose(&f);
00076 }

Here is the call graph for this function:


Generated on Tue Dec 25 19:08:47 2007 for blat by  doxygen 1.5.2