Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

/Users/trevorw/projects/release/covered-0.7.4/src/util.h

Go to the documentation of this file.
00001 #ifndef __UTIL_H__
00002 #define __UTIL_H__
00003 
00004 /*
00005  Copyright (c) 2006-2009 Trevor Williams
00006 
00007  This program is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU General Public License as published by the Free Software
00009  Foundation; either version 2 of the License, or (at your option) any later version.
00010 
00011  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
00012  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00013  See the GNU General Public License for more details.
00014 
00015  You should have received a copy of the GNU General Public License along with this program;
00016  if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 */
00018 
00026 #include <stdio.h>
00027 
00028 #include "defines.h"
00029 #include "profiler.h"
00030 
00031 
00033 #define malloc_safe(x)         malloc_safe1(x,__FILE__,__LINE__,profile_index)
00034 
00036 #define malloc_safe_nolimit(x) malloc_safe_nolimit1(x,__FILE__,__LINE__,profile_index)
00037 
00039 #define strdup_safe(x)         strdup_safe1(x,__FILE__,__LINE__,profile_index)
00040 
00042 #define realloc_safe(x,y,z)    realloc_safe1(x,(((x)!=NULL)?y:0),z,__FILE__,__LINE__,profile_index)
00043 
00045 #define calloc_safe(x,y)       calloc_safe1(x,y,__FILE__,__LINE__,profile_index)
00046 
00048 #ifdef TESTMODE
00049 #define free_safe(x,y)         free_safe2(x,(((x)!=NULL)?y:0),__FILE__, __LINE__,profile_index)
00050 #else
00051 #define free_safe(x,y)         free_safe1(x,profile_index)
00052 #endif
00053 
00054 
00056 void set_output_suppression( bool value );
00057 
00059 void set_debug( bool value );
00060 
00062 void set_testmode();
00063 
00065 void print_output( const char* msg, int type, const char* file, int line );
00066 
00068 bool check_option_value( int argc, const char** argv, int option_index );
00069 
00071 bool is_variable( const char* token );
00072 
00074 bool is_legal_filename( const char* token );
00075 
00077 bool is_func_unit( const char* token );
00078 
00080 const char* get_basename( /*@returned@*/ const char* str );
00081 
00083 char* get_dirname( char* str );
00084 
00086 char* get_absolute_path( const char* filename );
00087 
00089 char* get_relative_path( const char* abs_path );
00090 
00092 bool directory_exists( const char* dir );
00093 
00095 void directory_load( const char* dir, const str_link* ext_head, str_link** file_head, str_link** file_tail );
00096 
00098 bool file_exists( const char* file );
00099 
00101 bool util_readline(
00102             FILE*  file,
00103   /*@out@*/ char** line,
00104   /*@out@*/ unsigned int*   line_size
00105 );
00106 
00108 bool get_quoted_string(
00109             FILE* file,
00110   /*@out@*/ char* line
00111 );
00112 
00114 char* substitute_env_vars( const char* value );
00115 
00117 void scope_extract_front( const char* scope, /*@out@*/char* front, /*@out@*/char* rest );
00118 
00120 void scope_extract_back( const char* scope, /*@out@*/char* back, /*@out@*/char* rest );
00121 
00123 void scope_extract_scope( const char* scope, const char* front, /*@out@*/char* back );
00124 
00126 /*@only@*/ char* scope_gen_printable( const char* str );
00127 
00129 bool scope_compare( const char* str1, const char* str2 );
00130 
00132 bool scope_local( const char* scope );
00133 
00135 str_link* get_next_vfile( str_link* curr, const char* mod );
00136 
00138 /*@only@*/ void* malloc_safe1( size_t size, const char* file, int line, unsigned int profile_index );
00139 
00141 /*@only@*/ void* malloc_safe_nolimit1( size_t size, const char* file, int line, unsigned int profile_index );
00142 
00144 void free_safe1( /*@only@*/ /*@out@*/ /*@null@*/ void* ptr, unsigned int profile_index ) /*@releases ptr@*/;
00145 
00147 void free_safe2( /*@only@*/ /*@out@*/ /*@null@*/ void* ptr, size_t size, const char* file, int line, unsigned int profile_index ) /*@releases ptr@*/;
00148 
00150 /*@only@*/ char* strdup_safe1( const char* str, const char* file, int line, unsigned int profile_index );
00151 
00153 /*@only@*/ void* realloc_safe1(
00154   /*@null@*/ void*        ptr,
00155              size_t       old_size,
00156              size_t       size,
00157              const char*  file,
00158              int          line,
00159              unsigned int profile_index
00160 );
00161 
00163 /*@only@*/ void* calloc_safe1(
00164   size_t       num,
00165   size_t       size,
00166   const char*  file,
00167   int          line,
00168   unsigned int profile_index
00169 );
00170 
00172 void gen_char_string(
00173   /*@out@*/ char* spaces,
00174             char  c,
00175             int   num_spaces
00176 );
00177 
00179 char* remove_underscores(
00180   char* str
00181 );
00182 
00183 #ifdef HAVE_SYS_TIME_H
00184 
00185 void timer_clear( /*@out@*/ timer** tm );
00186 
00188 void timer_start( /*@out@*/ timer** tm );
00189 
00191 void timer_stop( /*@out@*/ timer** tm );
00192 
00194 char* timer_to_string( timer* tm );
00195 #endif
00196 
00198 const char* get_funit_type( int type );
00199 
00201 void calc_miss_percent(
00202             int    hits,
00203             int    total,
00204   /*@out@*/ int*   misses,
00205   /*@out@*/ float* percent );
00206 
00208 void set_timestep( sim_time* st, char* value );
00209 
00211 void read_command_file(
00212             const char* cmd_file,
00213   /*@out@*/ char***     arg_list,
00214   /*@out@*/ int*        arg_num
00215 );
00216 
00218 void gen_exclusion_id(
00219   char* excl_id,
00220   char  type,
00221   int   id
00222 );
00223 
00224 #endif
00225 

Generated on Wed Jun 17 22:19:20 2009 for Covered by doxygen 1.3.4