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

cuf-global.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2000-2003 KFA: Andrew Moenk and Alex Scott
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public
00015  * License along with this program; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  */
00019 
00024 #include <time.h>
00025 #include <ctype.h>
00026 #include <errno.h>
00027 #include <stdio.h>
00028 #include <fcntl.h>
00029 #include <stdlib.h>
00030 #include <string.h>
00031 #include <stdarg.h>
00032 #include <sys/stat.h>
00033 #include <sys/types.h>
00034 # ifndef WIN32
00035 #  include <dirent.h>
00036 #  include <unistd.h>
00037 #  include <stdarg.h>
00038 #  include <sys/time.h>
00039 # else
00040 #  include <io.h>
00041 #  include <direct.h>
00042 # endif
00043 
00044 #ifdef MEMWATCH
00045 # include "memwatch.h"
00046 #endif
00047 
00048 #ifndef _CUF_GLOBAL_H_
00049 # define _CUF_GLOBAL_H_
00050 
00051 # ifdef CONFIGURED
00052 //#  include "config.h"
00053 # endif
00054 
00055 # ifdef __cplusplus
00056 extern "C" {
00057 # endif
00058 
00059 
00060 /*** Commonly used macros through out CUF ***/
00061 
00062 /*
00063    Universal TRUE/FALSE for any C compiler.
00064 */
00068 # ifndef TRUE
00069 #  define TRUE                  (1 == 1)
00070 # endif
00071 
00074 # ifndef FALSE
00075 #  define FALSE                 (1 == 0)
00076 # endif
00077 
00078 
00082 # ifndef FERR
00083 #  define FERR                  (-2)
00084 # endif
00085 
00093 # ifndef addtext
00094 #  define addtext(p,s) { int plen=strlen (p), slen=strlen (s); memmove (p+plen, s, slen); p[plen+slen]='\0'; }
00095 # endif
00096 
00107 # ifndef insmem
00108 #  define insmem(p1, pos, p2, len) if (len) memmove (p1+pos, p2, len); pos+=len
00109 # endif
00110 
00121 # ifndef getmem
00122 #  define getmem(p1, pos, p2, len) if (len) memmove (p2, p1+pos, len); pos+=len
00123 # endif
00124 
00125 /*
00126    A Few time saveing if macros
00127 */
00133 # ifndef iffree
00134 #  define iffree(p) if (p) free (p)
00135 # endif
00136 
00142 # ifndef iffunc
00143 #  define iffunc(p,f) if (p) f (p)
00144 # endif
00145 
00150 # ifndef iffclose
00151 #  define iffclose(fd) if (fd) fclose (fd)
00152 # endif
00153 
00159 # ifndef tcalloc
00160 #  define tcalloc(t) (t *)calloc (1, sizeof(t))
00161 # endif
00162 
00168 # ifndef tncalloc
00169 #  define tncalloc(t,n) (t *)calloc (n, sizeof(t))
00170 # endif
00171 
00176 # ifndef scalloc
00177 #  define scalloc(len) (char *)calloc (len, sizeof(char))
00178 # endif
00179 
00186 # ifndef ssdup
00187 #  define ssdup(p,v) p->v=strdup (v)
00188 # endif
00189 
00197 # ifndef padstring
00198 #  define padstring(s, p, len) { int _i; for (_i=strlen (s); _i < len; _i+=strlen (p)) addtext (s, p); }
00199 # endif
00200 
00206 #define tfstr(b)        (b ? "True" : "False")
00207 
00208 /*
00209    To standardize mapping of __IFUNC_ to the various types.
00210    I dont remember where I pulled this from.
00211 */
00212 #ifdef __GNUC__
00213 # if __GNUC__ > 2 || \
00214      (__GNUC__ == 2 && __GNUC_MINOR__ >= (defined __cplusplus ? 6 : 4))
00215 #  define __IFUNC__     __PRETTY_FUNCTION__
00216 # else
00217 #  define __IFUNC__     ((__const char *) 0)
00218 # endif
00219 #else
00220 # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
00221 #  define __IFUNC__     __func__
00222 # else
00223 #  define __IFUNC__     ((__const char *) 0)
00224 # endif
00225 #endif
00226 
00227 
00228 /*** Global Enumerations ***/
00229 
00233 typedef enum _Comparison {
00234         CLessThan       =       -1,     
00235         CEqualTo        =        0,     
00236         CGreaterThan    =        1      
00237 } Comparison;
00238 
00239 
00240 /*** Global Structures ***/
00241 
00245 typedef struct _DString {
00246         unsigned long len;              
00247         char *data;                     
00248 } DString;
00249 
00250 
00251 /*** Common function shit^H^H^H^Hcastings. ***/
00252 
00254 typedef void (*FuncVoid) (void);
00256 typedef void (*FuncBool) (int);
00258 typedef void (*FuncChar) (char);
00260 typedef void (*FuncInt) (int);
00262 typedef void (*FuncLong) (long);
00264 typedef void (*FuncFloat) (float);
00266 typedef void (*FuncDouble) (double);
00268 typedef void (*FuncString) (char *);
00270 typedef void (*FuncDString) (DString *);
00271 
00273 typedef int (*FuncWVoid) (void);
00275 typedef int (*FuncWBool) (void);
00277 typedef char (*FuncWChar) (void);
00279 typedef int (*FuncWInt) (void);
00281 typedef long (*FuncWLong) (void);
00283 typedef float (*FuncWFloat) (void);
00285 typedef double (*FuncWDouble) (void);
00287 typedef char *(*FuncWString) (void);
00289 typedef DString *(*FuncWDString) (void);
00290 
00291 
00292 /*** Global File read/write Functions ***/
00293 
00294 #ifndef getch
00295 char getch (int fd);
00296 char ungetch (int fd);
00297 #endif
00298 char *getline (int fd);
00299 int putch (int fd, char c);
00300 int putchunk (int fd, char *str);
00301 int putline (int fd, char *str);
00302 
00303 
00304 /*** Wrapers For FILE* Type Operations (WARNING: Untested) ***/
00305 
00306 #define fgetch(ff) getch (fileno (ff))
00307 #define fungetch(ff) ungetch (fileno (ff))
00308 #define fgetline(ff) getline (fileno (ff))
00309 #define fputch(ff, c) putch (fileno (ff), c)
00310 #define fputchunk(ff, s) putchunk (fileno (ff), s)
00311 #define fputline(ff, s) putline (fileno (ff), s)
00312 
00313 
00314 /*** CUF Global Reporting Functions ***/
00315 
00316 void cuf_error (char *module, int fatal, char *fmt, ...);
00317 void cuf_warning (char *module, char *fmt, ...);
00318 void cuf_message (char *module, int level, char *fmt, ...);
00319 void cuf_debug_level_set (int level);
00320 
00321 
00322 /*** Data Strings ***/
00323 
00324 DString *dstring_new (unsigned long len);
00325 void dstring_free (DString *dstr);
00326 
00327 
00328 /*** Miscellaneous ***/
00329 
00330 char *get_cwd (void);
00331 # ifdef WIN32
00332 typedef unsigned int mode_t;
00333 # endif
00334 int mkdirp (const char *pathname, mode_t mode);
00335 
00336 # ifdef __cplusplus
00337 }
00338 # endif
00339 
00340 #endif /* _CUF_GLOBAL_H_ */

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