00001 #ifndef __UTI_H
00002 #define __UTI_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include <stdio.h>
00043 #include <string.h>
00044 #include <stdarg.h>
00045
00046 #include "arch.h"
00047 #include "tdef.h"
00048
00049
00050
00051 #ifdef __cplusplus
00052 extern "C" {
00053 #endif
00054
00055
00056
00057 #if (defined(__OS_UNIX__)&&!defined(__OS_MSDOS32__))
00058 #define CL_SWITCH "-"
00059 #else
00060 #define CL_SWITCH "-/"
00061 #endif
00062
00063
00064 #define FILE_COMMENT "#;"
00065 #define FILE_STRCODE '"'
00066 #define FILE_KVASSIGN '='
00067
00068
00069
00070 int nptrs( const void * const *ptrarray );
00071 int str_match( const char * const * strarr, int nstrs, const char * str,
00072 int lcode, int case_sensitive );
00073 int label_match( const char * const * labelarr, int nlabels, const char * label,
00074 int case_sensitive, int allow_partial );
00075 int xstr_match( const char * const *strarr, int nstrs, const char * str,
00076 int lcode, int case_sensitive );
00077 int xlabel_match( const char * const *labelarr, int nlabels, const char * label,
00078 int case_sensitive, int allow_partial );
00079 int str2k( const char * str, const char * const *labels,
00080 int defval, int case_sensitive, int allow_partial );
00081
00082
00083
00084 void die( const char *fmt, ... );
00085
00086 void die_beep( const char *fmt, ... );
00087 void cdie( int condition, const char *fmt, ... );
00088
00089 void cdie_beep( int condition, const char *fmt, ... );
00090
00091 void vdie( const char *fmt, va_list argptr );
00092 void vdie_beep( const char *fmt, va_list argptr );
00093 void vcdie( int condition, const char *fmt, va_list argptr );
00094 void vcdie_beep( int condition, const char *fmt, va_list argptr );
00095
00096 #define show_srcpos() __show_srcpos(__FILE__,__LINE__)
00097 #define cshow_srcpos(c) if (c) __show_srcpos(__FILE__,__LINE__)
00098 void __show_srcpos( const char *file, int line );
00099
00100
00101
00102
00103
00104
00105
00106 #define XFILE_EOFE_NEVER 0
00107 #define XFILE_EOFE_RETRY 1
00108 #define XFILE_EOFE_ALWAYS 2
00109
00110
00111
00112 #if __CC_BORLANDC__
00113 #define XFILE_FCLOSEALL
00114 #define XFILE_FLUSHALL
00115 #define XFILE_UNLINK
00116
00117 #elif __CC_GNUC__
00118 #define XFILE_UNLINK
00119
00120 #else
00121 #endif
00122
00123
00124
00125
00126
00127 char * fgetln( char * s, int n, FILE *fp, int *tl );
00128 char * fgetln_filt( char * s, int n, FILE *fp, int rm_comnt, int rm_white, int rm_wline, int *tl );
00129 #define fgetlnf(s,n,fp) fgetln_filt(s,n,fp,1,8,1,NULL)
00130 long flen( FILE * fp );
00131 int ftrunc( FILE * fp );
00132 int fmoven( FILE* fp, long from, long to, long n );
00133 int finsn( FILE* fp, long pos, long n );
00134 int fdeln( FILE* fp, long pos, long n );
00135
00136
00137
00138
00139 char * xfgetln( char * s, int n, FILE *fp, int *tl );
00140 char * xfgetln_filt( char * s, int n, FILE *fp, int rm_comnt, int rm_white, int rm_wline, int *tl);
00141 #define xfgetlnf(s,n,fp) xfgetln_filt(s,n,fp,1,8,1,NULL)
00142 long xflen( FILE * fp );
00143 int xftrunc( FILE * fp );
00144 int xfmoven( FILE* fp, long from, long to, long n );
00145 int xfinsn( FILE* fp, long pos, long n );
00146 int xfdeln( FILE* fp, long pos, long n );
00147 void xfile_error( const char * fn );
00148 int set_eof_error( int eof_error );
00149 #define eof_error_off() set_eof_error(XFILE_EOFE_NEVER)
00150 #define eof_error_on() set_eof_error(XFILE_EOFE_ALWAYS)
00151 int get_eof_error( void );
00152 #define xfeof(fp) feof(fp)
00153 int xfclose( FILE * fp );
00154 int xfflush( FILE * fp );
00155 int xfgetc( FILE * fp );
00156 int xfgetpos( FILE * fp, fpos_t * pos );
00157 char * xfgets( char * s, int n, FILE * fp );
00158 FILE * xfopen( const char * filename, const char * mode );
00159 int xfputc( int c, FILE * fp );
00160 int xfputs( const char * s, FILE * fp );
00161 size_t xfread( void * ptr, size_t size, size_t n, FILE * fp );
00162 int xfseek( FILE * fp, long int offset, int whence );
00163 int xfsetpos( FILE * fp, const fpos_t * pos );
00164 long int xftell( FILE * fp );
00165 size_t xfwrite( const void * ptr, size_t size, size_t n, FILE * fp );
00166 int xrename( const char * oldname, const char * newname );
00167 int xremove( const char * filename );
00168 #ifdef XFILE_FCLOSEALL
00169 int xfcloseall( void );
00170 #endif
00171 #ifdef XFILE_FLUSHALL
00172 int xflushall( void );
00173 #endif
00174 #ifdef XFILE_UNLINK
00175 int xunlink( const char * filename );
00176 #endif
00177
00178
00179
00180
00181
00182
00183
00184 #ifdef __CC_BORLANDC__
00185 #define STRISTR
00186
00187 #elif __OS_LINUX__
00188 #define STRUPR
00189 #define STRLWR
00190 #define STRNICMP
00191 #define STRICMP
00192 #define STRISTR
00193
00194 #elif __OS_UNIX__
00195 #define STRUPR
00196 #define STRLWR
00197 #define STRDUP
00198 #define STRNICMP
00199 #define STRICMP
00200 #define STRISTR
00201
00202 #else
00203 #endif
00204
00205
00206 char * str_stripch( char * str, char sch );
00207
00208 char * str_stripchset( char * str, const char *schs );
00209
00210 char * str_cutfromch( char * s, char cutch );
00211 char * str_cutfromchset( char * s, const char *cutchset );
00212
00213 char * str_xchr( const char * s, char ch );
00214
00215 char * str_xchrnext( const char * s, char ch );
00216
00217 char * str_xchrnextdiv( char * s, char ch );
00218 char * str_assignptr( const char * s );
00219
00220 char * str_assignptrnext( const char * s );
00221 int str_isswitch( const char * str );
00222
00223
00224 int str2si( const char * str, short int * si );
00225 int str2i( const char * str, int * ii );
00226 int str2li( const char * str, long int * li );
00227 int str2f( const char * str, float * f );
00228 int str2d( const char * str, double * d );
00229 int str2ld( const char * str, long double * ld );
00230
00231 short int xstr2si( const char * str, short int defval);
00232 int xstr2i( const char * str, int defval );
00233 long int xstr2li( const char * str, long int defval );
00234 float xstr2f( const char * str, float defval );
00235 double xstr2d( const char * str, double defval );
00236 long double xstr2ld( const char * str, long double defval);
00237
00238 int str2bool( const char *str, int def );
00239 const char *bool2str( int boo );
00240
00241
00242 #ifdef STRUPR
00243 char * strupr( char * str );
00244 #endif
00245 #ifdef STRLWR
00246 char * strlwr( char * str );
00247 #endif
00248 #ifdef STRDUP
00249 char * strdup( const char * str );
00250 #endif
00251 #ifdef STRNICMP
00252 #ifdef __CC_GNUC__
00253 #define strnicmp(s1,s2,maxlen) strncasecmp(s1,s2,maxlen)
00254 #else
00255 int strnicmp( const char * s1, const char * s2, size_t maxlen );
00256 #endif
00257 #endif
00258 #ifdef STRICMP
00259 #ifdef __CC_GNUC__
00260 #define stricmp(s1,s2) strcasecmp(s1,s2)
00261 #else
00262 int stricmp( const char * s1, const char * s2 );
00263 #endif
00264 #endif
00265 #ifdef STRISTR
00266 char * stristr( const char * s1, const char * s2 );
00267 #endif
00268
00269 const char *strsearch( const char* txt, const char* sub, int casesens );
00270
00271
00272 char* vstr_dup( char* oldvs, const char* newstr );
00273 void vstr_free( char* vs );
00274 char* vstr_getstr( const char* vs, const char* defval );
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284 #if (defined(__OS_UNIX__)&&!defined(__OS_MSDOS32__))
00285 #define PATH_DIRSEP '/'
00286 #define PATH_DRIVESEP '/'
00287
00288 #else
00289 #define PATH_DIRSEP '\\'
00290 #define PATH_DRIVESEP ':'
00291 #endif
00292
00293 #define PATH_EXT_BAK ".bak"
00294
00295 typedef struct {
00296 char *name;
00297 char *tmp;
00298 } fntmp;
00299 fntmp *fntmp_construct (const char *dest, const char *tmpfile);
00300 const char *fntmp_getname (fntmp * f);
00301 void fntmp_destruct (fntmp * f);
00302
00303 size_t path_namepos (const char *path);
00304 size_t path_extpos (const char *path);
00305
00306 char *path_dirchange (char *path, const char *new_dir);
00307 char *path_namechange(char *path, const char *new_name);
00308 char *path_extchange (char *path, const char *new_ext);
00309 #define path_dirextchange(fname,new_dir,new_ext) path_dirchange(path_extchange(fname,new_ext),new_dir)
00310 char * path_src2dest( const char * source, const char * dest );
00311 char * path_src2deste( const char * source, const char * dest, const char *dext );
00312 char *path_src2destp(const char *source, const char *dest,
00313 const char *dpath);
00314 #define path_applyrule(source,dest) path_src2destp(source,dest,NULL)
00315
00316 char *path_src2destde(const char *source, const char *dest,
00317 const char *ddir, const char *dext);
00318
00319 int frename_del (const char *name, const char *new_name);
00320 int frename_ext_del (const char *name, const char *new_ext);
00321 int frename_bak (const char *name, const char *new_name);
00322 int frename_ext_bak (const char *name, const char *new_ext);
00323
00324 void xfrename_del (const char *name, const char *new_name);
00325 void xfrename_ext_del (const char *name, const char *new_ext);
00326 void xfrename_bak (const char *name, const char *new_name);
00327 void xfrename_ext_bak (const char *name, const char *new_ext);
00328
00329
00330
00331
00332 double fround( double n );
00333 int float2int( double n );
00334 long float2long( double n );
00335 double cuadfit( double y1, double y2, double y3, double *y );
00336 double linterpol( double x, double x1, double x2, double y1, double y2 );
00337
00338 #ifdef __CC_BORLANDC__
00339 #define REMAINDER
00340 #elif __OS_LINUX__
00341 #define REMAINDER
00342 #else
00343
00344 #endif
00345
00346 #ifdef REMAINDER
00347 double remainder( double x, double y );
00348 #endif
00349
00350
00351
00352
00353 void endian_swap16( VOID * word16 );
00354 void endian_swap32( VOID * word32 );
00355 void endian_swap64( VOID * word32 );
00356 void endian_swap16_n( VOID * word16, int n );
00357 void endian_swap32_n( VOID * word32, int n );
00358 void endian_swap64_n( VOID * word32, int n );
00359
00360 #ifdef __LITTLE_ENDIAN__
00361 #define endian_tolittle16(x) ((void)0)
00362 #define endian_tolittle32(x) ((void)0)
00363 #define endian_tolittle64(x) ((void)0)
00364 #define endian_fromlittle16(x) ((void)0)
00365 #define endian_fromlittle32(x) ((void)0)
00366 #define endian_fromlittle64(x) ((void)0)
00367 #define endian_tolittle16_n(x,n) ((void)0)
00368 #define endian_tolittle32_n(x,n) ((void)0)
00369 #define endian_tolittle64_n(x,n) ((void)0)
00370 #define endian_fromlittle16_n(x,n) ((void)0)
00371 #define endian_fromlittle32_n(x,n) ((void)0)
00372 #define endian_fromlittle64_n(x,n) ((void)0)
00373 #else
00374 #define endian_tolittle16(w) endian_swap16(w)
00375 #define endian_tolittle32(w) endian_swap32(w)
00376 #define endian_tolittle64(w) endian_swap64(w)
00377 #define endian_fromlittle16(w) endian_swap16(w)
00378 #define endian_fromlittle32(w) endian_swap32(w)
00379 #define endian_fromlittle64(w) endian_swap64(w)
00380 #define endian_tolittle16_n(w,n) endian_swap16_n(w,n)
00381 #define endian_tolittle32_n(w,n) endian_swap32_n(w,n)
00382 #define endian_tolittle64_n(w,n) endian_swap64_n(w,n)
00383 #define endian_fromlittle16_n(w,n) endian_swap16_n(w,n)
00384 #define endian_fromlittle32_n(w,n) endian_swap32_n(w,n)
00385 #define endian_fromlittle64_n(w,n) endian_swap64_n(w,n)
00386 #endif
00387
00388 #ifdef __BIG_ENDIAN__
00389 #define endian_tobig16(x) ((void)0)
00390 #define endian_tobig32(x) ((void)0)
00391 #define endian_tobig64(x) ((void)0)
00392 #define endian_frombig16(x) ((void)0)
00393 #define endian_frombig32(x) ((void)0)
00394 #define endian_frombig64(x) ((void)0)
00395 #define endian_tobig16_n(x,n) ((void)0)
00396 #define endian_tobig32_n(x,n) ((void)0)
00397 #define endian_tobig64_n(x,n) ((void)0)
00398 #define endian_frombig16_n(x,n) ((void)0)
00399 #define endian_frombig32_n(x,n) ((void)0)
00400 #define endian_frombig64_n(x,n) ((void)0)
00401 #else
00402 #define endian_tobig16(w) endian_swap16(w)
00403 #define endian_tobig32(w) endian_swap32(w)
00404 #define endian_tobig64(w) endian_swap64(w)
00405 #define endian_frombig16(w) endian_swap16(w)
00406 #define endian_frombig32(w) endian_swap32(w)
00407 #define endian_frombig64(w) endian_swap64(w)
00408 #define endian_tobig16_n(w,n) endian_swap16_n(w,n)
00409 #define endian_tobig32_n(w,n) endian_swap32_n(w,n)
00410 #define endian_tobig64_n(w,n) endian_swap64_n(w,n)
00411 #define endian_frombig16_n(w,n) endian_swap16_n(w,n)
00412 #define endian_frombig32_n(w,n) endian_swap32_n(w,n)
00413 #define endian_frombig64_n(w,n) endian_swap64_n(w,n)
00414 #endif
00415
00416
00417
00418 #ifdef __cplusplus
00419 }
00420 #endif
00421
00422
00423
00424 #endif