Bioplib
Protein Structure C Library
|
Header file for general purpose routines. More...
Go to the source code of this file.
Data Structures | |
struct | _stringlist |
Macros | |
#define | FREESTRINGLIST(l) |
#define | _GENERAL_H_DEPRECATED |
Typedefs | |
typedef struct _stringlist | STRINGLIST |
Functions | |
void | blStringToLower (char *string1, char *string2) |
void | blStringToUpper (char *string1, char *string2) |
char * | blKillLeadSpaces (char *string) |
void | blKillLine (FILE *fp) |
void | blSetExtn (char *File, char *Ext) |
int | blChindex (char *string, char ch) |
void | blWord (char *string1, char *string2) |
void | blWordN (char *string1, char *string2, int MaxChar) |
void | blPadterm (char *string, int length) |
void | blPadchar (char *string, int length, char ch) |
BOOL | blCheckExtn (char *string, char *ext) |
char * | blFtostr (char *str, int maxlen, REAL x, int precision) |
void | blGetFilestem (char *filename, char *stem) |
int | blUpstrcmp (char *word1, char *word2) |
int | blUpstrncmp (char *word1, char *word2, int ncomp) |
char * | blGetWord (char *buffer, char *word, int maxsize) |
char ** | blSplitStringOnCommas (char *string, int minItemLen) |
char ** | blSplitStringOnChars (char *string) |
BOOL | blOpenStdFiles (char *infile, char *outfile, FILE **in, FILE **out) |
FILE * | blOpenFile (char *filename, char *envvar, char *mode, BOOL *noenv) |
int | blCountchar (char *string, char ch) |
char * | blFgetsany (FILE *fp) |
char * | blStrcatalloc (char *instr, char *catstr) |
char * | blStrncat (char *out, const char *in, size_t len) |
STRINGLIST * | blStoreString (STRINGLIST *StringList, char *string) |
BOOL | blInStringList (STRINGLIST *StringList, char *string) |
void | blFreeStringList (STRINGLIST *StringList) |
char * | blQueryStrStr (char *string, char *substring) |
void | blIndexReal (REAL *arrin, int *indx, int n) |
FILE * | blOpenOrPipe (char *filename) |
int | blCloseOrPipe (FILE *fp) |
BOOL | blWrapString (char *in, char *out, int maxlen) |
BOOL | blWrapPrint (FILE *out, char *string) |
void | blRightJustify (char *string) |
char * | blGetWordNC (char *buffer, char *word, int maxlen) |
void | blGetfield (char *buffer, int start, int width, char *str) |
BOOL | blCheckProgName (char *name, char *expected) |
char * | blCollapseSpaces (char *inText) |
Header file for general purpose routines.
This code is NOT IN THE PUBLIC DOMAIN, but it may be copied according to the conditions laid out in the accompanying file COPYING.DOC.
The code may be modified as required, but any modifications must be documented so that the person responsible can be identified.
The code may not be sold commercially or included as part of a commercial product except as described in the file COPYING.DOC.
Definition in file general.h.
#define FREESTRINGLIST | ( | l | ) |
typedef struct _stringlist STRINGLIST |
BOOL blCheckExtn | ( | char * | string, |
char * | ext | ||
) |
[in] | *string | String to be checked for given extension |
[in] | *ext | Extension to check for |
Check the extension of a filename. For use on machines like VAXes, MS-DOS and Amigas, everything is converted to upper case first.
Definition at line 120 of file CheckExtn.c.
BOOL blCheckProgName | ( | char * | progname, |
char * | expected | ||
) |
[in] | *filename | A PDB filename containing a PDB code |
This routine attempts to convert a filename stem to a PDB code.
Definition at line 95 of file filename.c.
int blChindex | ( | char * | string, |
char | ch | ||
) |
[in] | *string | A string |
[in] | ch | A character for which to search |
Returns the offset of a character in a string. -1 if not found. This is used in a similar manner to strchr(), but gives an offset in the string rather than a pointer to the character.
int blCloseOrPipe | ( | FILE * | fp | ) |
[in] | *fp | File pointer to be closed |
Attempts to close a file pointer as a pipe. If it isn't associated with a pipe (i.e. pclose returns (-1)), tries again to close it as a normal file.
Definition at line 172 of file openorpipe.c.
char* blCollapseSpaces | ( | char * | inText | ) |
[in] | *inText | Input text string |
Takes a string and collapses multiple spaces down to a single space Equivalent of perl 's/+/ /g' The input string is unmodified and malloc()s the output.
28.04.15 Original By: ACRM
Definition at line 108 of file stringutil.c.
int blCountchar | ( | char * | string, |
char | ch | ||
) |
[in] | *string | String to search for characters |
[in] | ch | Character for which to search |
Counts occurrences of charcater ch in string, string.
Definition at line 115 of file countchar.c.
char* blFgetsany | ( | FILE * | fp | ) |
[in] | *fp | File pointer open for reading |
blFgetsany() provides a routine like fgets() for reading strings from a file, but does not require you to impose a limit on the length of string which may be read. blFgetsany() allocates memory to store a string of any length and returns a pointer to that allocated memory. After use, this memory must be freed by the calling routine.
blFgetsany() returns NULL on end-of-file and if memory allocation failed. It uses the global `errno' variable to indicate a memory allocation failure (errno==ENOMEM).
Definition at line 143 of file fgetsany.c.
void blFreeStringList | ( | STRINGLIST * | StringList | ) |
[in] | *StringList | Linked list of strings |
Frees memory allocated for a string list.
Definition at line 122 of file FreeStringList.c.
char* blFtostr | ( | char * | str, |
int | maxlen, | ||
REAL | x, | ||
int | precision | ||
) |
[out] | *str | String version of number |
[in] | maxlen | Max length for f-form. Switches to e-form if exceeded |
[in] | x | Number to convert |
[in] | precision | Number of decimal places If negative, use e-form rather than f-form |
Convert a REAL to a string using precision decimal places. If precision is negative, use e-form, otherwise use f-form. This is used to generate precisely formatted string versions of numbers for applications where the appearance of a numeric value is important.
void blGetfield | ( | char * | buffer, |
int | start, | ||
int | width, | ||
char * | str | ||
) |
[in] | *buffer | Buffer from which to read a field |
[in] | start | Starting column (count from 0) |
[in] | width | Width of field to read |
[out] | *str | Field read from buffer |
Reads a column out of a buffer. If the specfied column extends beyond the size of the buffer, then it will be padded with spaces.
Note that the output string must be of at lease width+1 characters to store the field read from the buffer plus the terminating character.
Definition at line 99 of file getfield.c.
void blGetFilestem | ( | char * | filename, |
char * | stem | ||
) |
[in] | *filename | Complete filename |
[out] | *stem | The filestem |
Extracts the filestem from a complete filename. Should work under Unix, VMS, MS-DOS, AmigaDOS, etc.
Definition at line 116 of file GetFilestem.c.
char* blGetWord | ( | char * | buffer, |
char * | word, | ||
int | maxlen | ||
) |
[in] | *buffer | Input buffer to read words from |
[in] | maxlen | Max length of output word |
[out] | *word | Word read from buffer |
This code is a wrapper to doGetWord()
Reads a whitespace/comma delimited word out of buffer into word.
Words containing white space may be wrapped in double inverted commas. A \ is used as an escape character and maybe used to escape any following character. In particular: "\\" -> '\' To get a backslash "\ " -> ' ' To get a hard whitespace (alternatively wrap the string in double inverted commas) "\"" -> '"' To get a double inverted comma
char* blGetWordNC | ( | char * | buffer, |
char * | word, | ||
int | maxlen | ||
) |
[in] | *buffer | Input buffer to read words from |
[in] | maxlen | Max length of output word |
[out] | *word | Word read from buffer |
This code is a wrapper to doGetWord()
Reads a whitespace delimited word out of buffer into word. Commas are treated just like normal characters.
Words containing white space may be wrapped in double inverted commas. A \ is used as an escape character and maybe used to escape any following character. In particular: "\\" -> '\' To get a backslash "\ " -> ' ' To get a hard whitespace (alternatively wrap the string in double inverted commas) "\"" -> '"' To get a double inverted comma
void blIndexReal | ( | REAL * | arrin, |
int * | indx, | ||
int | n | ||
) |
[in] | *arrin | Array to be indexed |
[in] | n | Number of elements in array |
[out] | *indx | Index array |
Index an array by Heapsort.
Definition at line 110 of file IndxReal.c.
BOOL blInStringList | ( | STRINGLIST * | StringList, |
char * | string | ||
) |
[in] | *StringList | Linked list of strings |
[in] | *string | String for which to search |
Searches a string list for an exact match with the specified string.
Definition at line 118 of file InStringList.c.
char* blKillLeadSpaces | ( | char * | string | ) |
[in] | *string | A character string |
This routine strips leading spaces and tabs from a string returning a pointer to the first non-whitespace character.
N.B. THE MACRO KILLLEADSPACES() MAY NOW BE USED INSTEAD
Definition at line 121 of file KillLeadSpaces.c.
void blKillLine | ( | FILE * | fp | ) |
[in] | *fp | A file pointer |
This routine reads characters from a file till it reaches a '
' or the end of file.
Definition at line 117 of file KillLine.c.
FILE* blOpenFile | ( | char * | filename, |
char * | envvar, | ||
char * | mode, | ||
BOOL * | noenv | ||
) |
[in] | *filename | Filename to be opened |
[in] | *envvar | Unix/MS-DOS environment variable Other OS assign name (with :) |
[in] | *mode | Mode in which to open file (r, w, etc) |
[out] | *noenv | Set to TRUE under Unix/MS-DOS if the reason for failure was that the environment variable was not set. |
Attempts to open a filename as specified. Returns a file pointer. If this fails:
Under UNIX/MS-DOS: gets the contents of the envvar environment variable and prepends that to the filename and tries again. If envvar was not set, noenv is set to TRUE and the routine returns a NULL pointer.
Under other OSs: prepends the envvar string onto the filename and tries to open the file again.
Returns the pointer returned by the open() command after all this.
Definition at line 146 of file OpenFile.c.
FILE* blOpenOrPipe | ( | char * | filename | ) |
[in] | *filename | A file or pipe to be opened |
Opens a file for writing unless the filename begins with a | in which case it is opened as a pipe.
Broken pipe signals are ignored.
Definition at line 128 of file openorpipe.c.
BOOL blOpenStdFiles | ( | char * | infile, |
char * | outfile, | ||
FILE ** | in, | ||
FILE ** | out | ||
) |
[in] | *infile | Input filename |
[in] | *outfile | Output filename |
[out] | **in | Input file pointer |
[out] | **out | Output file pointer |
Open the files if specified. In and out are not modified if files are not specified.
Definition at line 126 of file OpenStdFiles.c.
void blPadchar | ( | char * | string, |
int | length, | ||
char | ch | ||
) |
[in,out] | *string | String to be padded with spaces |
[in] | length | Required size for string |
[in] | ch | Character with which to pad |
Pads a string with a specified character to length characters, then terminates it.
void blPadterm | ( | char * | string, |
int | length | ||
) |
char* blQueryStrStr | ( | char * | string, |
char * | substring | ||
) |
This is like strstr() but allows a ? character in the substring which matches any character.
Definition at line 113 of file QueryStrStr.c.
void blRightJustify | ( | char * | string | ) |
void blSetExtn | ( | char * | File, |
char * | Ext | ||
) |
[in,out] | *File | Filename to be modified |
[in] | *Ext | New extension |
Force a filename extension. Modifies the input filename to have the specified extension. Note that the string File should be large enough to cope with longer extensions, if required. Searches back through the string to find a `.' Anything after this is replaced with the specified extension. The search for a `.' stops as soon as a `/',`\', or a `:' is found as these indicate a directory. If no `.' is found, one is appended to the string and the extension is added.
char** blSplitStringOnChars | ( | char * | string | ) |
[in] | *string | String containing comma-separated items |
Splits a string into a list of items malloc'ing a 2D array which contains the item strings. The first dimension will be the number if items plus one. The second dimension will be 2 - a single charcater plus the \0
The last position in the first array will be set to a null string
Note that this routine malloc's a 2D array which will need to be freed
char** blSplitStringOnCommas | ( | char * | string, |
int | minItemLen | ||
) |
[in] | *string | String containing comma-separated items |
[in] | minItemLength | Min size to allocate for each item |
Splits a comma separated list of items malloc'ing a 2D array which contains the item strings. The first dimension will be the number if items plus one. The second dimension will be the maximum item length plus one, or at least minItemLen.
The last position in the first array will be set to a null string
Note that this routine malloc's a 2D array which will need to be freed
STRINGLIST* blStoreString | ( | STRINGLIST * | StringList, |
char * | string | ||
) |
[in] | *StringList | The current linked list or NULL if nothing yet allocated |
[in] | *string | The string to store |
Stores strings (of any length) in a linked list of type STRINGLIST. Return a pointer to the start of the linked list which is used on the first call to access the newly allocated memory.
If allocation fails, memory allocated so far is freed and the routine returns NULL.
Definition at line 131 of file StoreString.c.
char* blStrcatalloc | ( | char * | instr, |
char * | catstr | ||
) |
[in] | *instr | String to append to |
[in] | *catstr | String to append |
Like strcat() but uses a realloc() on instr to make space available.
Definition at line 100 of file strcatalloc.c.
void blStringToLower | ( | char * | string1, |
char * | string2 | ||
) |
[in] | *string1 | A character string |
[out] | *string2 | Lower case version of string1 |
This routine converts a lower or mixed case string to lower case.
Definition at line 119 of file StringToLower.c.
void blStringToUpper | ( | char * | string1, |
char * | string2 | ||
) |
[in] | *string1 | A character string |
[out] | *string2 | Upper case version of string1 |
This routine converts a lower or mixed case string to upper case.
Definition at line 119 of file StringToUpper.c.
char* blStrncat | ( | char * | out, |
const char * | in, | ||
size_t | len | ||
) |
[in] | *in | Input string to be appended |
[in] | len | Length of output string |
[in,out] | *out | String that we are appending to |
A simpler version of strncat. strncat takes the max number of chars to be appended whereas this takes the max number of chars that 'out' can hold.
Definition at line 97 of file stringcat.c.
int blUpstrcmp | ( | char * | word1, |
char * | word2 | ||
) |
[in] | *word1 | First word |
[in] | *word2 | Second word |
Like strcmp(), but upcases each character before comparison
Definition at line 116 of file upstrcmp.c.
int blUpstrncmp | ( | char * | word1, |
char * | word2, | ||
int | ncomp | ||
) |
[in] | *word1 | First word |
[in] | *word2 | Second word |
[in] | ncomp | Number of characters to compare |
Like strncmp(), but upcases each character before comparison
Definition at line 116 of file upstrncmp.c.
void blWord | ( | char * | string1, |
char * | string2 | ||
) |
[in] | *string1 | A string |
[out] | *string2 | A new string |
Removes leading spaces and extracts a space/tab delimited word. string2 must have the same amount of space as string1.
void blWordN | ( | char * | string1, |
char * | string2, | ||
int | MaxChar | ||
) |
[in] | *string1 | A string |
[in] | MaxChar | Max characters to copy |
[out] | *string2 | A new string |
Removes leading spaces and extracts a space/tab delimited word. A maximum of MaxChar characters will be copied into the word. If necessary a terminating NULL will be added after MaxChar other characters. Thus MaxChar should always be at least 1 smaller than the size of string2.
BOOL blWrapPrint | ( | FILE * | out, |
char * | string | ||
) |
[in] | *out | Output file pointer |
[in] | *string | String to be printed |
Wraps a string with double inverted commas if it contains spaces and escapes any contained double inverted commas with a backslash. Allocates memory for temporary storage of the wrapped string. Returns FALSE if this memory allocation failed.
Definition at line 204 of file wrapprint.c.
BOOL blWrapString | ( | char * | in, |
char * | out, | ||
int | maxlen | ||
) |
[in] | *in | Input string |
[in] | maxlen | Max length of output string |
[out] | *out | Output wrapped string |
Wraps a string with double inverted commas if it contains spaces and escapes any contained double inverted commas with a backslash. If the output string wasn't big enough, then the routine just returns FALSE without copying anything into the output string.
Definition at line 104 of file wrapprint.c.