Content-type: text/html
int debug(FILE *f, char *fmt, ...)
char *fgetln(FILE *f, char *buf, int len)
int parseargs(int args, char *arg[], char *format, char *opts, ...)
const char *parseerror(int error)
const char *parseusage(char *progname, int width, char *format, ...)
int badusage(int retval)
char *strlower(char *s)
char *strupper(char *s)
int strmatch(char *s, char **m)
int strcasematch(char *s, char **m)
void strnprefix(char *s, char *pf, int len, char *sep)
void strnsuffix(char *s, char *sf, int len, char *sep)
char **str2ary(char *str, char *delims)
char *ary2str(char **lst, char delim)
char *sizestr(char *buf, double d)
size_t *strfnow(char *s, size_t maxlen, char *fmt)
typedef enum {Error, None, Integer, Float, Character, String} gentype
const char *typename(char *tnam, gentype t)
typedef union {
long i;
double f;
long c;
char *s;
} generic
char *gen2str(char *str, generic gen, gentype t)
generic str2genR(char *str, gentype t)
int gencmp(generic gen1, generic gen2, gentype t)
generic gencpy(generic *gdst, generic gsrc, gentype t)
table *createtable(char *fmt)
void deletetable(table *tbl)
table *readtable(char *ftbl, generic *keyexcl, int numexcl)
int writetable(table *tbl, char *fname, char *header, int wfmt, char delim)
int getfieldvalue(table *tbl, char *fldname, generic *value)
int setfieldvalue(table *tbl, char *fldname, generic value)
gentype getfieldtype(table *tbl, char *fldname)
char *getfieldname(table *tbl, int fldindex, char *str)
int getkeyvalue(table *tbl, int recindex, generic *value)
gentype getkeytype(table *tbl)
int countrecords(table *tbl)
int countfields(table *tbl)
int addrecord(table *tbl, generic key)
int delrecord(table *tbl, generic key)
The debug function, in its current form, is little more than a wrapper for fprintf. If you pass a NULL pointer for the file handle the function will simply return without doing anything, otherwise it acts exactly like fprintf.
The fgetln function is similar to the standard gets or fgets routines, but offers more functionality and better security. fgetln will strip leading white space from the input line and it allows you to specify the length of the buffer you have passed to it. Normally, fgetln will consume all input up to the next newline. This behavior can be prevented by passing a negative len value to the routine.
The parseargs, parseusage, parseerror and badusage functions are a replacement for the getopts routines found in the standard UNIX library. parseargs simplifies the process of parsing command line arguments to a single function call and a format string. The format string is a super-set of the getopts format string, so you can switch over quite easily.
The strlower and strupper functions convert strings to all upper or all lower case.
The strmatch and strcasematch functions try to find the first match to a string in a list of strings, with or without case sensitivity. This can be very usefull if you are trying to spot keywords of one kind or another. The string list must be terminated with a NULL pointer. (a pointer whose value is NULL, not a pointer to the empty string "")
The strnprefix and strnsuffix functions extract a prefix or suffix, delimited by one of the characters in the sep string, from a provided string. The functions are safe in that they require to use to specify the size of the buffer provided for storing the extracted string and are careful not to exceed that size.
The str2ary and ary2str functions convert delimited strings into string arrays and vice versa. The input string delimiters can be from any one of a set of user specified delimiters. The list resulting from a conversion is NULL terminated.
The sizestr function returns a string specifying the size of an object using the standard order of magnitude abbreviations (K,M,G,T,P). The size of the object in bytes is given as a double precision float so that really big values can be used. (the routine will return strings for values up to 9999 Peta-units, just beyond the range that can be represented by a 64-bit integer) If the size value is greater than 9999 Peta-units, then the routine returns a string with an asterisk as the magnitude. If the buf parameter is NULL then the routine will try to allocate a small buffer using malloc, which you will need to free later on. If anything goes wrong, the routine will return NULL.
The strfnow function just encapsulates the strftime function from the time.h standard C library, but uses the current time rather than accepting a time_t value. There isn't all that much to this routine, but I have found myself using this fairly frequently, so here it is. NOTE: this function will not allocate a buffer for you. Sending a NULL pointer for the s parameter will simply cause the fuction to do nothing and return 0.
The generic type routines and datatypes support a (very) primitive form of object orientation. The routines provide methods of converting generic unions to and from strings, and of comparing and copying generics. There is also a method for getting and english name for a generic data type.
The various table manipulation routines allow you to work with tables of assorted data types in memory and on disk. The createtable and deletetable routines create and dispose of the table memory structures. The readtable and writetable routines read and write tables in disk files. The routines getfieldtype, getfieldname, getkeytype, countfields, and countrecords all return information about the table structure. The getkeyvalue, getfieldvalue, setfieldvalue, addrecord, and delrecord modify the contents of the table structure.
All of these routines will detect NULL pointers as parameters and avoid dereferencing them. Unfortunately, I cannot check for other types of wild pointers or invalid buffer length specifications, so you can still see crashes due to bad pointer dereferences.
In parseargs (and related routines) there are a number of serious bugs related to the exact interpretation of arguments when required parameters are specified. These bugs are symptoms of inherent ambiguities in the argument array and the format specification string. The manpages for parseargs addresses these bugs, and provides some workarounds. A future version of the parseargs routines will detect an ambiguous format string and return an error code, but the new version is still too unstable for general use (or even my own use).