Azinix

util.h File Reference

Low-level utilities. More...

#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <sys/time.h>
#include <tcl.h>
#include "array.h"
#include "var_set.h"
#include "timing.h"

Go to the source code of this file.

Data Structures

struct  util_int_array_t
 Struct to represent int-arrays. More...
struct  util_byte_array_t
 Struct to represent byte-array. More...
struct  util_attrib_val_t
 Attribute-value pair used to read formula. More...

Defines

#define util_assert(x)
#define fail(why)
#define NIL(type)   ((type *) 0)
#define ALLOC(type, num)   ((type *) MMalloc((long) sizeof(type) * (long) (num)))
 Allocates 'number' objects of type 'type'.
#define REALLOC(type, obj, num)   ((type *) MMrealloc((char *) (obj), (long) sizeof(type) * (long) (num)))
 Re-allocate 'obj' to hold 'number' objects of type 'type'.
#define USE   __attribute__((unused))
 Macro to make an unused variable look like it's used.
#define EXTERN   extern
#define ABS(a)   ((a) < 0 ? -(a) : (a))
#define MAX(a, b)   ((a) > (b) ? (a) : (b))
#define MIN(a, b)   ((a) < (b) ? (a) : (b))
#define HUGE   8.9884656743115790e+307
#define HUGE_VAL   HUGE
#define MAXINT   (1 << 30)

Typedefs

typedef util_int_array_t util_int_array_t
typedef util_byte_array_t util_byte_array_t
typedef util_attrib_val_t util_attrib_val_t

Enumerations

enum  Util_FileOpenMode_t { Util_FileOverWrite_c, Util_FileAppend_c }
 Types of modes in which to open files. More...

Functions

void MMout_of_memory (int)
char * MMalloc (int)
 Safe malloc.
char * MMrealloc (char *, int)
 Safe realloc.
void MMfree (char *)
 Safe free.
void util_print_cpu_stats (FILE *)
void util_getopt_reset (void)
int util_getopt (int, char **, char *)
char * util_path_search (char *)
char * util_file_search (char *, char *, char *)
int util_save_image (char *, char *)
int strstrN (char *, char *, int)
char * util_strsav (char *)
char * util_strchr_N (char *, char, int)
int util_strequal (char *, char *)
char * util_strmax (char *, char *)
char * util_strmin (char *, char *)
int util_strequalN (char *, char *, int)
char * util_strcat (char *, char *)
char * util_strcat3 (char *, char *, char *)
char * util_strcat5 (char *, char *, char *, char *, char *)
char * util_sgets (array_t *, char *)
char * util_file_to_string (FILE *)
array_tutil_process_file (char *)
array_tutil_get_raw_rules (char *)
char * util_get_full_line (array_t *, char *)
util_byte_array_tutil_byte_array_join (util_byte_array_t *, util_byte_array_t *)
int util_byte_array_free (util_byte_array_t *)
int util_byte_array_print (util_byte_array_t *)
int util_byte_array_hash (char *, int)
u_int32_t util_fast_hash (const char *, int)
int util_byte_array_cmp (char *, char *)
util_byte_array_tutil_byte_array_create (char *, int)
util_byte_array_tutil_byte_array_to_lower_case (util_byte_array_t *)
int util_int_array_print (util_int_array_t *)
int util_int_array_free (util_int_array_t *)
util_int_array_tutil_int_array_create (int)
util_int_array_tutil_arrayT_to_int_array (array_t *)
util_int_array_tvar_set_to_int_array (var_set_t *)
double util_unit_rand ()
int util_rand_int ()
void util_set_processor_frequency ()
void util_time (char *)
u_int32_t util_time_to_ticks (double)
 Convert time in seconds to machine ticks; use in conjunction with rdtsc-type instructions.
array_tutil_time_stamp_init (int)
void util_time_stamp_set (array_t *, int)
void util_time_stamp_print (array_t *)
int Perf_CheckHardware (ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
 Routine to determine machine dependent parameters.
int Perf_TimePerf (ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
int Perf_TimePerf2 (ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
int Perf_SpacePerf (ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
int Perf_CheckTimingCode (ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
 Testing the resolution of the rdtsc timing code.

Variables

char * util_optarg


Detailed Description

Low-level utilities.

Definition in file util.h.


Define Documentation

#define ABS (  )     ((a) < 0 ? -(a) : (a))

Definition at line 105 of file util.h.

#define ALLOC ( type,
num   )     ((type *) MMalloc((long) sizeof(type) * (long) (num)))

Allocates 'number' objects of type 'type'.

This macro should be used rather than calling malloc() directly because it casts the arguments appropriately, and ALLOC() will never return NIL(char), choosing instead to terminate the program.

Definition at line 63 of file util.h.

#define EXTERN   extern

Definition at line 101 of file util.h.

#define fail ( why   ) 

Value:

{\
    (void) fprintf(stderr, "Fatal error: file %s, line %d\n%s\n",\
    __FILE__, __LINE__, why);\
    (void) fflush(stdout);\
    abort();\
}

Definition at line 37 of file util.h.

#define HUGE   8.9884656743115790e+307

Definition at line 118 of file util.h.

#define HUGE_VAL   HUGE

Definition at line 120 of file util.h.

#define MAX ( a,
 )     ((a) > (b) ? (a) : (b))

Definition at line 109 of file util.h.

#define MAXINT   (1 << 30)

Definition at line 124 of file util.h.

#define MIN ( a,
 )     ((a) < (b) ? (a) : (b))

Definition at line 113 of file util.h.

#define NIL ( type   )     ((type *) 0)

Definition at line 52 of file util.h.

#define REALLOC ( type,
obj,
num   )     ((type *) MMrealloc((char *) (obj), (long) sizeof(type) * (long) (num)))

Re-allocate 'obj' to hold 'number' objects of type 'type'.

This macro should be used rather than calling realloc() directly because it casts the arguments appropriately, and REALLOC() will never return NIL(char), instead choosing to terminate the program. It also guarantees that REALLOC(type, 0, n) is the same as ALLOC(type, n).

Definition at line 76 of file util.h.

#define USE   __attribute__((unused))

Macro to make an unused variable look like it's used.

Program checkers issue warnings about variables that are declared but never used. Most of the time, such variables should be removed to simplify the code. However, on occasion we want to keep such variables, but we don't want program checkers to complain about them. Using this macro will make an unused variable look like it's being used. This macro is straight out of the gcc documentation, Chapter 5 GCC 3.4.1.

Usage: put USE immediately after the variable gcc -Wall complains about

Example: int foo USE;

Definition at line 95 of file util.h.

#define util_assert (  ) 

Definition at line 34 of file util.h.


Typedef Documentation

typedef struct util_attrib_val_t util_attrib_val_t

Definition at line 195 of file util.h.

typedef struct util_byte_array_t util_byte_array_t

Definition at line 181 of file util.h.

typedef struct util_int_array_t util_int_array_t

Definition at line 162 of file util.h.


Enumeration Type Documentation

enum Util_FileOpenMode_t

Types of modes in which to open files.

Types of modes in which to open files.

Enumerator:
Util_FileOverWrite_c 
Util_FileAppend_c 

Definition at line 138 of file util.h.


Function Documentation

char* MMalloc ( int   ) 

Safe malloc.

Definition at line 36 of file safe_mem.c.

void MMfree ( char *   ) 

Safe free.

Definition at line 87 of file safe_mem.c.

void MMout_of_memory ( int   ) 

char* MMrealloc ( char *  ,
int   
)

Safe realloc.

Definition at line 59 of file safe_mem.c.

int Perf_CheckHardware ( ClientData  cd,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const  objv[] 
)

Routine to determine machine dependent parameters.

Definition at line 37 of file perf.c.

int Perf_CheckTimingCode ( ClientData  cd,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const  objv[] 
)

Testing the resolution of the rdtsc timing code.

Definition at line 10 of file perf.c.

int Perf_SpacePerf ( ClientData  cd,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const  objv[] 
)

Definition at line 378 of file perf.c.

int Perf_TimePerf ( ClientData  cd,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const  objv[] 
)

Definition at line 185 of file perf.c.

int Perf_TimePerf2 ( ClientData  cd,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const  objv[] 
)

Definition at line 550 of file perf.c.

int strstrN ( char *  ,
char *  ,
int   
)

util_int_array_t* util_arrayT_to_int_array ( array_t  ) 

int util_byte_array_cmp ( char *  ,
char *   
)

util_byte_array_t* util_byte_array_create ( char *  ,
int   
)

int util_byte_array_free ( util_byte_array_t  ) 

int util_byte_array_hash ( char *  ,
int   
)

util_byte_array_t* util_byte_array_join ( util_byte_array_t ,
util_byte_array_t  
)

int util_byte_array_print ( util_byte_array_t  ) 

util_byte_array_t* util_byte_array_to_lower_case ( util_byte_array_t  ) 

u_int32_t util_fast_hash ( const char *  ,
int   
)

char* util_file_search ( char *  ,
char *  ,
char *   
)

char* util_file_to_string ( FILE *   ) 

char* util_get_full_line ( array_t ,
char *   
)

array_t* util_get_raw_rules ( char *   ) 

int util_getopt ( int  ,
char **  ,
char *   
)

Definition at line 21 of file getopt.c.

void util_getopt_reset ( void   ) 

Definition at line 13 of file getopt.c.

util_int_array_t* util_int_array_create ( int   ) 

int util_int_array_free ( util_int_array_t  ) 

int util_int_array_print ( util_int_array_t  ) 

char* util_path_search ( char *   ) 

void util_print_cpu_stats ( FILE *   ) 

array_t* util_process_file ( char *   ) 

int util_rand_int (  ) 

int util_save_image ( char *  ,
char *   
)

void util_set_processor_frequency (  ) 

Definition at line 41 of file util.c.

char* util_sgets ( array_t ,
char *   
)

char* util_strcat ( char *  ,
char *   
)

char* util_strcat3 ( char *  ,
char *  ,
char *   
)

char* util_strcat5 ( char *  ,
char *  ,
char *  ,
char *  ,
char *   
)

char* util_strchr_N ( char *  ,
char  ,
int   
)

int util_strequal ( char *  ,
char *   
)

int util_strequalN ( char *  ,
char *  ,
int   
)

char* util_strmax ( char *  ,
char *   
)

char* util_strmin ( char *  ,
char *   
)

char* util_strsav ( char *   ) 

void util_time ( char *   ) 

Definition at line 97 of file util.c.

array_t* util_time_stamp_init ( int   ) 

Definition at line 170 of file util.c.

void util_time_stamp_print ( array_t  ) 

Definition at line 194 of file util.c.

void util_time_stamp_set ( array_t ,
int   
)

Definition at line 183 of file util.c.

u_int32_t util_time_to_ticks ( double  secs  ) 

Convert time in seconds to machine ticks; use in conjunction with rdtsc-type instructions.

Convert time in seconds to machine ticks; use in conjunction with rdtsc-type instructions

Definition at line 146 of file util.c.

double util_unit_rand (  ) 

util_int_array_t* var_set_to_int_array ( var_set_t  ) 


Variable Documentation

char* util_optarg

Definition at line 8 of file getopt.c.