00001 /* Obscure.h - stuff that's relatively rarely used 00002 * but still handy. 00003 * 00004 * This file is copyright 2002 Jim Kent, but license is hereby 00005 * granted for all use - public, private or commercial. */ 00006 00007 #ifndef OBSCURE_H 00008 #define OBSCURE_H 00009 00010 long incCounterFile(char *fileName); 00011 /* Increment a 32 bit value on disk. */ 00012 00013 int digitsBaseTwo(unsigned long x); 00014 /* Return base two # of digits. */ 00015 00016 int digitsBaseTen(int x); 00017 /* Return number of digits base 10. */ 00018 00019 void sprintLongWithCommas(char *s, long long l); 00020 /* Print out a long number with commas a thousands, millions, etc. */ 00021 00022 void printLongWithCommas(FILE *f, long long l); 00023 /* Print out a long number with commas a thousands, millions, etc. */ 00024 00025 void writeGulp(char *file, char *buf, int size); 00026 /* Write out a bunch of memory. */ 00027 00028 void readInGulp(char *fileName, char **retBuf, size_t *retSize); 00029 /* Read whole file in one big gulp. */ 00030 00031 void readAllWords(char *fileName, char ***retWords, int *retWordCount, char **retBuf); 00032 /* Read in whole file and break it into words. You need to freeMem both 00033 * *retWordCount and *retBuf when done. */ 00034 00035 int countWordsInFile(char *fileName); 00036 /* Count number of words in file. */ 00037 00038 struct slName *readAllLines(char *fileName); 00039 /* Read all lines of file into a list. (Removes trailing carriage return.) */ 00040 00041 void copyFile(char *source, char *dest); 00042 /* Copy file from source to dest. */ 00043 00044 void copyOpenFile(FILE *inFh, FILE *outFh); 00045 /* copy an open stdio file */ 00046 00047 void cpFile(int s, int d); 00048 /* Copy from source file to dest until reach end of file. */ 00049 00050 void *intToPt(int i); 00051 /* Convert integer to pointer. Use when really want to store an 00052 * int in a pointer field. */ 00053 00054 int ptToInt(void *pt); 00055 /* Convert pointer to integer. Use when really want to store a 00056 * pointer in an int. */ 00057 00058 void *sizetToPt(size_t i); 00059 /* Convert size_t to pointer. Use when really want to store a 00060 * size_t in a pointer. */ 00061 00062 size_t ptToSizet(void *pt); 00063 /* Convert pointer to size_t. Use when really want to store a 00064 * pointer in a size_t. */ 00065 00066 boolean parseQuotedString( char *in, char *out, char **retNext); 00067 /* Read quoted string from in (which should begin with first quote). 00068 * Write unquoted string to out, which may be the same as in. 00069 * Return pointer to character past end of string in *retNext. 00070 * Return FALSE if can't find end. */ 00071 00072 char *nextQuotedWord(char **pLine); 00073 /* Generalization of nextWord. Returns next quoted 00074 * string or if no quotes next word. Updates *pLine 00075 * to point past word that is returned. Does not return 00076 * quotes. */ 00077 00078 char *makeQuotedString(char *in, char quoteChar); 00079 /* Create a string surrounded by quoteChar, with internal 00080 * quoteChars escaped. freeMem result when done. */ 00081 00082 char *makeEscapedString(char *in, char toEscape); 00083 /* Return string that is a copy of in, but with all 00084 * toEscape characters preceded by '\' 00085 * When done freeMem result. */ 00086 00087 void escCopy(char *in, char *out, char toEscape, char escape); 00088 /* Copy in to out, escaping as needed. Out better be big enough. 00089 * (Worst case is strlen(in)*2 + 1.) */ 00090 00091 struct slName *stringToSlNames(char *string); 00092 /* Convert string to a list of slNames separated by 00093 * white space, but allowing multiple words in quotes. 00094 * Quotes if any are stripped. */ 00095 00096 struct slName *commaSepToSlNames(char *commaSep); 00097 /* Convert comma-separated list of items to slName list. */ 00098 00099 struct slName *charSepToSlNames(char *string, char c); 00100 /* Convert character-separated list of items to slName list. 00101 * Note that the last occurence of c is optional. (That 00102 * is for a comma-separated list a,b,c and a,b,c, are 00103 * equivalent. */ 00104 00105 struct hash *hashVarLine(char *line, int lineIx); 00106 /* Return a symbol table from a line of form: 00107 * var1=val1 var2='quoted val2' var3="another val" */ 00108 00109 struct hash *hashWordsInFile(char *fileName, int hashSize); 00110 /* Create a hash of space delimited words in file. 00111 * hashSize is as in hashNew() - pass 0 for default. */ 00112 00113 struct hash *hashNameIntFile(char *fileName); 00114 /* Given a two column file (name, integer value) return a 00115 * hash keyed by name with integer values */ 00116 00117 struct hash *hashTwoColumnFile(char *fileName); 00118 /* Given a two column file (key, value) return a hash. */ 00119 00120 void shuffleArrayOfPointers(void *pointerArray, int arraySize, 00121 int shuffleCount); 00122 /* Shuffle array of pointers of given size given number of times. */ 00123 00124 void shuffleList(void *pList, int shuffleCount); 00125 /* Randomize order of slList. Usage: 00126 * shuffleList(&list) 00127 * where list is a pointer to a structure that 00128 * begins with a next field. */ 00129 00130 char *stripCommas(char *position); 00131 /* make a new string with commas stripped out */ 00132 00133 void dotForUserInit(int dotMod); 00134 /* Set how often dotForUser() outputs a dot. */ 00135 00136 void dotForUser(); 00137 /* Write out a dot every _dotForUserMod times this is called. */ 00138 00139 void spaceToUnderbar(char *s); 00140 /* Convert white space to underbar. */ 00141 00142 #endif /* OBSCURE_H */
1.5.2