Main Page | Data Structures | File List | Data Fields | Globals

cuf-global.h File Reference

#include <time.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <sys/time.h>

Go to the source code of this file.

Data Structures

struct  _DString

Defines

#define TRUE   (1 == 1)
#define FALSE   (1 == 0)
#define FERR   (-2)
#define addtext(p, s)   { int plen=strlen (p), slen=strlen (s); memmove (p+plen, s, slen); p[plen+slen]='\0'; }
#define insmem(p1, pos, p2, len)   if (len) memmove (p1+pos, p2, len); pos+=len
#define getmem(p1, pos, p2, len)   if (len) memmove (p2, p1+pos, len); pos+=len
#define iffree(p)   if (p) free (p)
#define iffunc(p, f)   if (p) f (p)
#define iffclose(fd)   if (fd) fclose (fd)
#define tcalloc(t)   (t *)calloc (1, sizeof(t))
#define tncalloc(t, n)   (t *)calloc (n, sizeof(t))
#define scalloc(len)   (char *)calloc (len, sizeof(char))
#define ssdup(p, v)   p->v=strdup (v)
#define padstring(s, p, len)   { int _i; for (_i=strlen (s); _i < len; _i+=strlen (p)) addtext (s, p); }
#define tfstr(b)   (b ? "True" : "False")

Typedefs

typedef enum _Comparison Comparison
typedef _DString DString
typedef void(* FuncVoid )(void)
typedef void(* FuncBool )(int)
typedef void(* FuncChar )(char)
typedef void(* FuncInt )(int)
typedef void(* FuncLong )(long)
typedef void(* FuncFloat )(float)
typedef void(* FuncDouble )(double)
typedef void(* FuncString )(char *)
typedef void(* FuncDString )(DString *)
typedef int(* FuncWVoid )(void)
typedef int(* FuncWBool )(void)
typedef char(* FuncWChar )(void)
typedef int(* FuncWInt )(void)
typedef long(* FuncWLong )(void)
typedef float(* FuncWFloat )(void)
typedef double(* FuncWDouble )(void)
typedef char *(* FuncWString )(void)
typedef DString *(* FuncWDString )(void)

Enumerations

enum  _Comparison {
  CLessThan = -1,
  CEqualTo = 0,
  CGreaterThan = 1
}

Functions

char getch (int fd)
char ungetch (int fd)
char * getline (int fd)
int putch (int fd, char c)
int putchunk (int fd, char *str)
int putline (int fd, char *str)
void cuf_error (char *module, int fatal, char *fmt,...)
void cuf_warning (char *module, char *fmt,...)
void cuf_message (char *module, int level, char *fmt,...)
void cuf_debug_level_set (int level)
DStringdstring_new (unsigned long len)
void dstring_free (DString *dstr)
char * get_cwd (void)
int mkdirp (const char *pathname, mode_t mode)


Detailed Description

Misc. Everthing that didn't fit anyware else.

Define Documentation

#define addtext p,
 )     { int plen=strlen (p), slen=strlen (s); memmove (p+plen, s, slen); p[plen+slen]='\0'; }
 

Parameters:
p Target string.
s Source string.
Description:
Works like strcat, accept inlined, and if you have a faster memmove then it might work better with really large strings.

#define FALSE   (1 == 0)
 

Universal False.

#define FERR   (-2)
 

File error. Used by the global file reading/writing functions.

#define getmem p1,
pos,
p2,
len   )     if (len) memmove (p2, p1+pos, len); pos+=len
 

Parameters:
p1 Data buffer.
pos Offset of data buffer to start copy from. Must be a variable because it is auto incrimented.
p2 Reciving buffer.
len Length in bytes to copy from p1 into p2.
Description:
Copies a segment from one buffer into a receiving buffer. Be sure the receiving buffer has adequate size to hold the expected length or this could cause a buffer overflow.

#define iffclose fd   )     if (fd) fclose (fd)
 

Parameters:
fd File descriptor (Must be of the FILE type).
Description:
Checks a FILE descriptor, if non-null it calls fclose() on it.

#define iffree  )     if (p) free (p)
 

Parameters:
p Pointer to check.
Description:
Checks pointer, if non-null it frees it.

#define iffunc p,
 )     if (p) f (p)
 

Parameters:
p Pointer to check.
f Function to call.
Description:
Checks pointer, if non-null it passes it to the specifyed function.

#define insmem p1,
pos,
p2,
len   )     if (len) memmove (p1+pos, p2, len); pos+=len
 

Parameters:
p1 Reciving buffer.
pos Offset to append the other buffer at. Must be a variable because it is auto incrimented.
p2 Buffer to copy from.
len Length in bytes to copy data from p2 into p1.
Description:
Inserts a buffer into another. No bounds checking is done so this could cause a buffer overflow if you underestimate the receiving buffer size.

#define padstring s,
p,
len   )     { int _i; for (_i=strlen (s); _i < len; _i+=strlen (p)) addtext (s, p); }
 

Parameters:
s String.
p Pad character.
len Full length of string+pad.
Description:
Pads string 's' with the string 'p' to the length of 'len'.

#define scalloc len   )     (char *)calloc (len, sizeof(char))
 

Parameters:
len Length of the string to allocate.
Description:
String calloc.

#define ssdup p,
 )     p->v=strdup (v)
 

Description:
Structured string dup. p is the pointer to the struct. v is the string variable name of the struct member and string to be duplicated. Makes the code hard to read, probably will drop this macro edventualy.

#define tcalloc  )     (t *)calloc (1, sizeof(t))
 

Parameters:
t The type to allocate.
Description:
Type calloc.

#define tfstr  )     (b ? "True" : "False")
 

Parameters:
b The boolean argument to check.
Description:
True/False String.

#define tncalloc t,
 )     (t *)calloc (n, sizeof(t))
 

Parameters:
t The type to allocate.
n The number of elements in the array.
Description:
Type array calloc.

#define TRUE   (1 == 1)
 

Universal True.


Typedef Documentation

typedef enum _Comparison Comparison
 

Comparison enumeration.

typedef struct _DString DString
 

Data String.

typedef void(* FuncBool)(int)
 

type name for when calling a function with a boolean argument

typedef void(* FuncChar)(char)
 

type name for when calling a function with a char argument

typedef void(* FuncDouble)(double)
 

type name for when calling a function with a double argument

typedef void(* FuncDString)(DString *)
 

type name for when calling a function with a DString argument

typedef void(* FuncFloat)(float)
 

type name for when calling a function with a float argument

typedef void(* FuncInt)(int)
 

type name for when calling a function with a int argument

typedef void(* FuncLong)(long)
 

type name for when calling a function with a long argument

typedef void(* FuncString)(char *)
 

type name for when calling a function with a string argument

typedef void(* FuncVoid)(void)
 

type name for when calling a void function

typedef int(* FuncWBool)(void)
 

type name for a writing a boolean

typedef char(* FuncWChar)(void)
 

type name for a writing a character

typedef double(* FuncWDouble)(void)
 

type name for a writing a double

typedef DString*(* FuncWDString)(void)
 

type name for a writing a DString

typedef float(* FuncWFloat)(void)
 

type name for a writing a float

typedef int(* FuncWInt)(void)
 

type name for a writing a int

typedef long(* FuncWLong)(void)
 

type name for a writing a long

typedef char*(* FuncWString)(void)
 

type name for a writing a string

typedef int(* FuncWVoid)(void)
 

type name for a writing a void (returns TRUE if function is to be called)


Enumeration Type Documentation

enum _Comparison
 

Comparison enumeration.

Enumeration values:
CLessThan  A is less than B.
CEqualTo  A is equal to B.
CGreaterThan  A is greater than B.


Function Documentation

void cuf_debug_level_set int  level  ) 
 

Parameters:
level The new debug level to set.
Description:
Allows real-time adjustment of the debug level. This mediates which messages will be printed by cuf_message().

void cuf_error char *  module,
int  fatal,
char *  fmt,
... 
 

Parameters:
module The module name the message is printed from.
fatal If the error is fatal to the program.
fmt The string format.
... Format variables.
Description:
Prints a error message pertaining to the CUF module 'module' with the format string 'fmt'. Optionally 'fatal' can be set to the exit value if the program is to be terminated immediately.

void cuf_message char *  module,
int  level,
char *  fmt,
... 
 

Parameters:
module The module name the message is printed from.
level The debug level of this message.
fmt The string format.
... Format variables.
Description:
Prints a message, usually for debugging, pertaining to the CUF module 'module' with the format string 'fmt'. The option 'level' indicates how high the debug level must be in order for the message to be printed.

void cuf_warning char *  module,
char *  fmt,
... 
 

Parameters:
module The module name the message is printed from.
fmt The string format.
... Format variables.
Description:
Prints a warning message pertaining to the CUF module 'module' with the format string 'fmt'.

void dstring_free DString dstr  ) 
 

Parameters:
dstr The data string to free.
Description:
Frees a DString.

DString* dstring_new unsigned long  len  ) 
 

Parameters:
len The string length to allocate.
Return values:
DString * Of the newly allocated data string.
NULL On zero length or out of memory.
Description:
Generates a new DString of the specified length.

char* get_cwd void   ) 
 

Return values:
A Null terminated string of the current working directory.
NULL if out of memory.
Description:
Gets the current working directory.

char getch int  fd  ) 
 

Parameters:
fd File descriptor.
Return values:
char The next character in the file.
EOF when end of file is reached.
FERR when the read() returns error.
Description:
Gets the next charter from the file specified by the file descriptor 'fd' and advances to the next charter position.

char* getline int  fd  ) 
 

Parameters:
fd File descriptor.
Return values:
char* The line read out.
NULL when at end of file or on error.
Description:
Gets the next line delimited by '
' from the file specified by the file descriptor 'fd'. The stream is positioned after the '
'.

int mkdirp const char *  pathname,
mode_t  mode
 

Description:
Tries to emulate 'mkdir -p'

int putch int  fd,
char  c
 

Parameters:
fd File descriptor.
c Character to put.
Return values:
Returns the number of characters written (should always be 1).
FERR when the write() returns error.
Description:
Puts the charter 'c' into a file specified by the file descriptor 'fd' and advances the stream.

int putchunk int  fd,
char *  str
 

Parameters:
fd File descriptor.
str String to put.
Return values:
Returns the number of characters written (should always be 1).
FERR when the write() returns error.
Description:
Puts the string 'str' that must be null terminated into a file specified by the file descriptor 'fd' and advances the stream.

int putline int  fd,
char *  str
 

Parameters:
fd File descriptor.
str String to put.
Return values:
Returns the number of characters written (should always be 1).
FERR when the write() returns error.
Description:
Puts the string 'str' that must be null terminated and adds a new line (
). Placing it into a file specified by the file descriptor 'fd' and advances the stream.

char ungetch int  fd  ) 
 

Parameters:
fd File descriptor.
Return values:
char The previous character in the file.
EOF when beginning of file is reached.
FERR when the read() returns error.
Description:
Gets the previous character from the file specified by the file descriptor 'fd' and backs up to the charter ahead of the one returned.


Generated on Fri Jun 4 18:35:18 2004 for cuf by doxygen 1.3.6