util.h

Go to the documentation of this file.
00001 #ifndef __UTIL_H__
00002 #define __UTIL_H__
00003 
00004 /*
00005  Copyright (c) 2006-2010 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_quiet( bool value );
00057 
00059 void set_terse( bool value );
00060 
00062 void set_debug( bool value );
00063 
00065 void set_testmode();
00066 
00068 void print_output( const char* msg, int type, const char* file, int line );
00069 
00071 bool check_option_value( int argc, const char** argv, int option_index );
00072 
00074 bool is_variable( const char* token );
00075 
00077 bool is_legal_filename( const char* token );
00078 
00080 bool is_func_unit( const char* token );
00081 
00083 const char* get_basename( /*@returned@*/ const char* str );
00084 
00086 char* get_dirname( char* str );
00087 
00089 char* get_absolute_path( const char* filename );
00090 
00092 char* get_relative_path( const char* abs_path );
00093 
00095 bool directory_exists( const char* dir );
00096 
00098 void directory_load( const char* dir, const str_link* ext_head, str_link** file_head, str_link** file_tail );
00099 
00101 bool file_exists( const char* file );
00102 
00104 bool util_readline(
00105             FILE*  file,
00106   /*@out@*/ char** line,
00107   /*@out@*/ unsigned int*   line_size
00108 );
00109 
00111 bool get_quoted_string(
00112             FILE* file,
00113   /*@out@*/ char* line
00114 );
00115 
00117 char* substitute_env_vars( const char* value );
00118 
00120 void scope_extract_front( const char* scope, /*@out@*/char* front, /*@out@*/char* rest );
00121 
00123 void scope_extract_back( const char* scope, /*@out@*/char* back, /*@out@*/char* rest );
00124 
00126 void scope_extract_scope( const char* scope, const char* front, /*@out@*/char* back );
00127 
00129 /*@only@*/ char* scope_gen_printable( const char* str );
00130 
00132 bool scope_compare( const char* str1, const char* str2 );
00133 
00135 bool scope_local( const char* scope );
00136 
00138 str_link* get_next_vfile( str_link* curr, const char* mod );
00139 
00141 /*@only@*/ void* malloc_safe1( size_t size, const char* file, int line, unsigned int profile_index );
00142 
00144 /*@only@*/ void* malloc_safe_nolimit1( size_t size, const char* file, int line, unsigned int profile_index );
00145 
00147 void free_safe1( /*@only@*/ /*@out@*/ /*@null@*/ void* ptr, unsigned int profile_index ) /*@releases ptr@*/;
00148 
00150 void free_safe2( /*@only@*/ /*@out@*/ /*@null@*/ void* ptr, size_t size, const char* file, int line, unsigned int profile_index ) /*@releases ptr@*/;
00151 
00153 /*@only@*/ char* strdup_safe1( const char* str, const char* file, int line, unsigned int profile_index );
00154 
00156 /*@only@*/ void* realloc_safe1(
00157   /*@null@*/ void*        ptr,
00158              size_t       old_size,
00159              size_t       size,
00160              const char*  file,
00161              int          line,
00162              unsigned int profile_index
00163 );
00164 
00166 /*@only@*/ void* calloc_safe1(
00167   size_t       num,
00168   size_t       size,
00169   const char*  file,
00170   int          line,
00171   unsigned int profile_index
00172 );
00173 
00175 void gen_char_string(
00176   /*@out@*/ char* spaces,
00177             char  c,
00178             int   num_spaces
00179 );
00180 
00182 char* remove_underscores(
00183   char* str
00184 );
00185 
00186 #ifdef HAVE_SYS_TIME_H
00187 
00188 void timer_clear( /*@out@*/ timer** tm );
00189 
00191 void timer_start( /*@out@*/ timer** tm );
00192 
00194 void timer_stop( /*@out@*/ timer** tm );
00195 
00197 char* timer_to_string( timer* tm );
00198 #endif
00199 
00201 const char* get_funit_type( int type );
00202 
00204 void calc_miss_percent(
00205             int    hits,
00206             int    total,
00207   /*@out@*/ int*   misses,
00208   /*@out@*/ float* percent );
00209 
00211 void set_timestep( sim_time* st, char* value );
00212 
00214 void read_command_file(
00215             const char* cmd_file,
00216   /*@out@*/ char***     arg_list,
00217   /*@out@*/ int*        arg_num
00218 );
00219 
00221 void gen_exclusion_id(
00222   char* excl_id,
00223   char  type,
00224   int   id
00225 );
00226 
00227 #endif
00228 
Generated on Sun Nov 21 00:55:36 2010 for Covered by  doxygen 1.6.3