Contains miscellaneous global functions used by many functions. More...
#include <stdio.h>
#include "defines.h"
#include "profiler.h"
Go to the source code of this file.
Defines | |
#define | malloc_safe(x) malloc_safe1(x,__FILE__,__LINE__,profile_index) |
#define | malloc_safe_nolimit(x) malloc_safe_nolimit1(x,__FILE__,__LINE__,profile_index) |
#define | strdup_safe(x) strdup_safe1(x,__FILE__,__LINE__,profile_index) |
#define | realloc_safe(x, y, z) realloc_safe1(x,(((x)!=NULL)?y:0),z,__FILE__,__LINE__,profile_index) |
#define | calloc_safe(x, y) calloc_safe1(x,y,__FILE__,__LINE__,profile_index) |
#define | free_safe(x, y) free_safe1(x,profile_index) |
Functions | |
void | set_quiet (bool value) |
Sets quiet output variable to specified value. | |
void | set_terse (bool value) |
Sets terse output variable to specified value. | |
void | set_debug (bool value) |
Sets global debug flag to specified value. | |
void | set_testmode () |
Sets the testmode global variable for outputting purposes. | |
void | print_output (const char *msg, int type, const char *file, int line) |
Displays error message to standard output. | |
bool | check_option_value (int argc, const char **argv, int option_index) |
Checks to make sure that a value was properly specified for a given option. | |
bool | is_variable (const char *token) |
Returns TRUE if the specified string is a legal variable name. | |
bool | is_legal_filename (const char *token) |
Returns TRUE if the specified string could be a valid filename. | |
bool | is_func_unit (const char *token) |
Returns TRUE if the specified string is a legal functional unit value. | |
const char * | get_basename (const char *str) |
Extracts filename from file pathname. | |
char * | get_dirname (char *str) |
Extracts directory path from file pathname. | |
char * | get_absolute_path (const char *filename) |
Allocates memory for and gets the absolute pathname for a given filename. | |
char * | get_relative_path (const char *abs_path) |
Allocates memory for and gets the relative pathname for a given absolute filename. | |
bool | directory_exists (const char *dir) |
Returns TRUE if the specified directory exists. | |
void | directory_load (const char *dir, const str_link *ext_head, str_link **file_head, str_link **file_tail) |
Loads contents of specified directory to file list if extension is part of list. | |
bool | file_exists (const char *file) |
Returns TRUE if the specified file exists. | |
bool | util_readline (FILE *file, char **line, unsigned int *line_size) |
Reads line from file and returns it in string form. | |
bool | get_quoted_string (FILE *file, char *line) |
Reads in line from file and returns the contents of the quoted string following optional whitespace. | |
char * | substitute_env_vars (const char *value) |
Searches the specified string for environment variables and substitutes their value if found. | |
void | scope_extract_front (const char *scope, char *front, char *rest) |
Extracts highest level of hierarchy from specified scope. | |
void | scope_extract_back (const char *scope, char *back, char *rest) |
Extracts lowest level of hierarchy from specified scope. | |
void | scope_extract_scope (const char *scope, const char *front, char *back) |
Extracts rest of scope not included in front. | |
char * | scope_gen_printable (const char *str) |
Generates printable version of given signal/instance string. | |
bool | scope_compare (const char *str1, const char *str2) |
Compares two signal names or two instance names. | |
bool | scope_local (const char *scope) |
Returns TRUE if specified scope is local (contains no periods). | |
str_link * | get_next_vfile (str_link *curr, const char *mod) |
Returns next Verilog file to parse. | |
void * | malloc_safe1 (size_t size, const char *file, int line, unsigned int profile_index) |
Performs safe malloc call. | |
void * | malloc_safe_nolimit1 (size_t size, const char *file, int line, unsigned int profile_index) |
Performs safe malloc call without upper bound on byte allocation. | |
void | free_safe1 (void *ptr, unsigned int profile_index) |
Performs safe deallocation of heap memory. | |
void | free_safe2 (void *ptr, size_t size, const char *file, int line, unsigned int profile_index) |
Performs safe deallocation of heap memory. | |
char * | strdup_safe1 (const char *str, const char *file, int line, unsigned int profile_index) |
Safely allocates heap memory by performing a call to strdup. | |
void * | realloc_safe1 (void *ptr, size_t old_size, size_t size, const char *file, int line, unsigned int profile_index) |
Safely reallocates heap memory by performing a call to realloc. | |
void * | calloc_safe1 (size_t num, size_t size, const char *file, int line, unsigned int profile_index) |
Safely callocs heap memory by performing a call to calloc. | |
void | gen_char_string (char *spaces, char c, int num_spaces) |
Creates a string containing space characters. | |
char * | remove_underscores (char *str) |
Removes underscores from the specified string. | |
const char * | get_funit_type (int type) |
Returns string representation of the specified functional unit type. | |
void | calc_miss_percent (int hits, int total, int *misses, float *percent) |
Calculates miss and percent information from given hit and total information. | |
void | set_timestep (sim_time *st, char *value) |
Sets the given timestep to the correct value from VCD simulation file. | |
void | read_command_file (const char *cmd_file, char ***arg_list, int *arg_num) |
Reads in contents of command file, substitutes environment variables and stores them to the arg_list array. | |
void | gen_exclusion_id (char *excl_id, char type, int id) |
Generates the exclusion identifier. |
Contains miscellaneous global functions used by many functions.
#define calloc_safe | ( | x, | |||
y | ) | calloc_safe1(x,y,__FILE__,__LINE__,profile_index) |
Overload for the calloc_safe1 function which includes profiling information
Referenced by rank_create_comp_cdd_cov(), and rank_perform().
#define free_safe | ( | x, | |||
y | ) | free_safe1(x,profile_index) |
Overload for the free-safe function which includes profiling information
Referenced by add_sym_values_to_sim(), arc_dealloc(), arc_display(), arc_state_hits(), assertion_funit_summary(), assertion_funit_verbose(), assertion_instance_summary(), assertion_instance_verbose(), attribute_dealloc(), bind_dealloc(), bind_find_sig_name(), bind_perform(), bind_remove(), codegen_create_expr_helper(), codegen_gen_expr(), combination_funit_verbose(), combination_get_expression(), combination_instance_summary(), combination_instance_verbose(), combination_list_missed(), combination_multi_var_exprs(), combination_multi_vars(), combination_prep_line(), combination_underline(), combination_underline_tree(), command_exclude(), command_merge(), command_rank(), command_report(), command_score(), covered_end_of_sim(), covered_parse_instance(), covered_parse_task_func(), db_add_function_task_namedblock(), db_add_signal(), db_assign_symbol(), db_close(), db_create_expr_from_static(), db_parallelize_statement(), db_read(), db_sync_curr_instance(), db_vcd_upscope(), defparam_dealloc(), directory_load(), enumerate_dealloc(), exclude_get_message(), exclude_handle_exclude_reason(), exclude_parse_args(), exclude_remove_exclude_reason(), exclude_resolve_reason(), exp_link_delete_list(), exp_link_remove(), expression_create_tmp_vecs(), expression_create_value(), expression_dealloc(), expression_find_rhs_sigs(), expression_op_func__test_plusargs(), expression_op_func__value_plusargs(), fsm_arg_parse(), fsm_arg_parse_attr(), fsm_arg_parse_trans(), fsm_dealloc(), fsm_display_arc_verbose(), fsm_display_state_verbose(), fsm_display_verbose(), fsm_funit_summary(), fsm_funit_verbose(), fsm_get_coverage(), fsm_instance_summary(), fsm_instance_verbose(), fsm_link_delete_list(), fsm_var_bind(), fsm_var_cleanup(), fsm_var_dealloc(), fst_parse(), func_iter_dealloc(), funit_clean(), funit_db_inst_merge(), funit_db_mod_merge(), funit_dealloc(), funit_link_delete_list(), funit_link_remove(), gen_item_bind(), gen_item_calc_signal_name(), gen_item_dealloc(), gen_item_resolve(), gen_item_stringify(), gen_item_varname_contains_genvar(), get_absolute_path(), gitem_link_delete_list(), gitem_link_remove(), info_dealloc(), inst_link_delete_list(), inst_parm_dealloc(), instance_dealloc_single(), instance_display_tree_helper(), instance_only_db_merge(), instance_only_db_read(), instance_resolve_inst(), is_func_unit(), line_display_verbose(), line_funit_summary(), line_funit_verbose(), line_instance_summary(), line_instance_verbose(), lxt2_rd_close(), lxt2_rd_iter_radix(), lxt2_rd_iter_radix0(), lxt2_rd_process_block(), lxt_parse(), memory_ae_funit_summary(), memory_ae_instance_summary(), memory_display_verbose(), memory_get_mem_coverage(), memory_instance_verbose(), memory_toggle_funit_summary(), memory_toggle_instance_summary(), merge_parse_args(), merged_cdd_db_read(), mod_parm_dealloc(), obfuscate_name(), ovl_display_verbose(), parser_dealloc_sig_range(), profiler_dealloc(), profiler_report(), profiler_set_filename(), race_blk_delete_list(), race_check_modules(), rank_dealloc_comp_cdd_cov(), rank_gather_fsm_cov(), rank_output(), rank_parse_args(), rank_perform(), reentrant_dealloc(), report_output_exclusion_reason(), report_parse_args(), report_print_header(), scope_compare(), scope_find_param(), scope_find_signal(), scope_get_parent_funit(), scope_get_parent_module(), score_generate_pli_tab_file(), score_generate_top_dumpvars_module(), score_generate_top_vpi_module(), score_parse_args(), score_parse_define(), sig_link_delete_list(), sim_dealloc(), statement_dealloc(), statement_dealloc_recursive(), statement_queue_compare(), static_expr_dealloc(), statistic_dealloc(), stmt_link_delete_list(), stmt_link_unlink(), str_link_delete_list(), str_link_remove(), struct_union_dealloc(), struct_union_member_dealloc(), substitute_env_vars(), symtable_dealloc(), toggle_display_verbose(), toggle_funit_summary(), toggle_instance_summary(), toggle_instance_verbose(), tree_add(), tree_dealloc(), tree_remove(), util_readline(), vcd_parse(), vector_db_read(), vector_dealloc(), vector_dealloc_value(), vector_from_string(), vector_to_string(), vsignal_create_vec(), vsignal_db_read(), and vsignal_dealloc().
#define malloc_safe | ( | x | ) | malloc_safe1(x,__FILE__,__LINE__,profile_index) |
Overload for the malloc_safe function which includes profiling information
Referenced by arc_add(), arc_create(), arc_db_read(), arc_state_hits(), attribute_create(), bind_add(), bind_find_sig_name(), bind_signal(), codegen_create_expr(), codegen_create_expr_helper(), codegen_gen_expr(), combination_event(), combination_get_expression(), combination_multi_expr_output(), combination_multi_var_exprs(), combination_multi_vars(), combination_prep_line(), combination_two_vars(), combination_unary(), combination_underline_tree(), command_report(), covered_end_of_sim(), db_add_signal(), db_add_typedef(), db_create(), db_gen_curr_inst_scope(), db_gen_exclusion_id(), defparam_add(), directory_load(), enumerate_add_item(), exclude_add_exclude_reason(), exclude_db_merge(), exclude_db_read(), exclude_merge(), exp_link_add(), expression_create(), expression_create_nba(), expression_create_tmp_vecs(), expression_create_value(), expression_set_value(), fsm_add_arc(), fsm_create(), fsm_display_arc_verbose(), fsm_link_add(), fsm_var_add(), fsm_var_bind_add(), fsm_var_stmt_add(), func_iter_init(), funit_add_thread(), funit_create(), funit_link_add(), gen_item_create_bind(), gen_item_create_expr(), gen_item_create_inst(), gen_item_create_sig(), gen_item_create_stmt(), gen_item_create_tfn(), gen_item_resolve(), get_absolute_path(), gitem_link_add(), inst_link_add(), inst_parm_add(), inst_parm_add_genvar(), instance_create(), instance_resolve_inst(), line_collect(), lxt_parse(), memory_get_coverage(), memory_get_mem_coverage(), mod_parm_add(), obfuscate_name(), ovl_get_coverage(), parser_copy_curr_range(), parser_copy_range_to_curr_range(), parser_implicitly_set_curr_range(), perf_gen_stats(), race_blk_create(), race_check_modules(), rank_create_comp_cdd_cov(), rank_gather_fsm_cov(), rank_output(), read_command_file(), reentrant_create(), report_output_exclusion_reason(), scope_find_param(), scope_find_signal(), scope_get_parent_funit(), score_generate_pli_tab_file(), sig_link_add(), sim_create_thread(), sim_initialize(), statement_create(), statement_queue_add(), static_expr_gen(), statistic_create(), stmt_link_add(), str_link_add(), struct_union_add_member_enum(), struct_union_add_member_sig(), struct_union_add_member_struct_union(), struct_union_add_member_typedef(), struct_union_add_member_void(), struct_union_create(), substitute_env_vars(), sym_value_store(), symtable_add_sym_sig(), symtable_create(), symtable_init(), tree_add(), util_readline(), vector_create(), vector_get_toggle01_ulong(), vector_get_toggle10_ulong(), vector_to_string(), vsignal_create(), vsignal_db_read(), vsignal_duplicate(), and vsignal_from_string().
#define malloc_safe_nolimit | ( | x | ) | malloc_safe_nolimit1(x,__FILE__,__LINE__,profile_index) |
Overload for the malloc_safe_nolimit function which includes profiling information
Referenced by covered_sim_calltf(), fst_parse(), gen_item_stringify(), lxt2_rd_process_block(), lxt_parse(), rank_perform(), and vcd_parse().
#define realloc_safe | ( | x, | |||
y, | |||||
z | ) | realloc_safe1(x,(((x)!=NULL)?y:0),z,__FILE__,__LINE__,profile_index) |
Overload for the realloc_safe1 function which includes profiling information
Referenced by arc_add(), arc_get_states(), arc_get_transitions(), combination_collect(), combination_get_exclude_list(), combination_get_expression(), combination_prep_line(), db_create(), db_set_vcd_scope(), db_vcd_upscope(), exclude_format_reason(), exclude_get_message(), exclude_resolve_reason(), fsm_collect(), fsm_gather_signals(), gen_item_calc_signal_name(), info_db_read(), line_collect(), memory_create_pdim_bit_array(), memory_get_coverage(), memory_get_mem_coverage(), merged_cdd_db_read(), ovl_collect(), parser_explicitly_set_curr_range(), parser_implicitly_set_curr_range(), race_collect_lines(), rank_read_cdd(), search_init(), substitute_env_vars(), and util_readline().
#define strdup_safe | ( | x | ) | strdup_safe1(x,__FILE__,__LINE__,profile_index) |
Overload for the strdup_safe function which includes profiling information
Referenced by arc_get_transitions(), attribute_create(), bind_add(), bind_find_sig_name(), bind_perform(), codegen_create_expr_helper(), codegen_gen_expr(), combination_get_exclude_list(), combination_multi_vars(), combination_prep_line(), combination_underline_tree(), command_report(), command_score(), covered_parse_instance(), covered_parse_task_func(), db_add_file_version(), db_add_function_task_namedblock(), db_add_instance(), db_add_module(), db_add_typedef(), db_create_unnamed_scope(), db_parallelize_statement(), db_read(), db_set_vcd_scope(), exclude_db_merge(), exclude_db_read(), exclude_format_reason(), exclude_get_message(), exclude_merge(), exclude_parse_args(), exclude_resolve_reason(), fsm_arg_parse(), fsm_var_add(), fsm_var_bind_add(), fsm_var_stmt_add(), funit_db_write(), funit_gen_task_function_namedblock_name(), funit_version_db_read(), gen_item_bind(), gen_item_calc_signal_name(), gen_item_create_bind(), gen_item_varname_contains_genvar(), gen_next_symbol(), get_absolute_path(), get_relative_path(), info_db_read(), inst_parm_add(), instance_create(), instance_only_db_merge(), instance_only_db_read(), instance_resolve_inst(), is_func_unit(), line_collect(), lxt2_rd_iter_radix(), lxt2_rd_iter_radix0(), memory_get_coverage(), merge_parse_args(), merged_cdd_db_read(), message_db_read(), mod_parm_add(), ovl_collect(), ovl_get_coverage(), parse_design(), profiler_set_filename(), rank_create_comp_cdd_cov(), rank_parse_args(), read_command_file(), report_output_exclusion_reason(), report_parse_args(), scope_find_param(), scope_find_signal(), scope_gen_printable(), scope_get_parent_module(), score_add_args(), score_generate_pli_tab_file(), score_generate_top_dumpvars_module(), score_generate_top_vpi_module(), score_parse_args(), score_parse_define(), search_add_directory_path(), search_add_extensions(), search_add_file(), search_add_include_path(), search_add_no_score_funit(), search_init(), struct_union_create(), sym_value_store(), sys_task_store_plusarg(), toggle_get_coverage(), tree_add(), vector_copy(), vector_db_read(), vector_from_string(), vector_init_r32(), vector_init_r64(), vector_to_string(), vsignal_create(), and vsignal_duplicate().
void calc_miss_percent | ( | int | hits, | |
int | total, | |||
int * | misses, | |||
float * | percent | |||
) |
Calculates miss and percent information from given hit and total information.
Calculates the number of misses and hit percentage information from the given hit and total information, storing the results in the misses and percent storage elements.
hits | Number of items hit during simulation | |
total | Number of total items | |
misses | Pointer to a storage element which will contain the calculated number of items missed during simulation | |
percent | Pointer to a storage element which will contain the calculated hit percent information |
References PROFILE, and PROFILE_END.
Referenced by assertion_display_funit_summary(), assertion_display_instance_summary(), combination_display_funit_summary(), combination_display_instance_summary(), fsm_display_funit_summary(), fsm_display_instance_summary(), line_display_funit_summary(), line_display_instance_summary(), memory_display_ae_funit_summary(), memory_display_ae_instance_summary(), memory_display_toggle_funit_summary(), memory_display_toggle_instance_summary(), toggle_display_funit_summary(), and toggle_display_instance_summary().
01642 { PROFILE(CALC_MISS_PERCENT); 01643 01644 if( total == 0 ) { 01645 *percent = 100; 01646 } else { 01647 *percent = ((hits / (float)total) * 100); 01648 } 01649 01650 *misses = (total - hits); 01651 01652 PROFILE_END; 01653 01654 }
void* calloc_safe1 | ( | size_t | num, | |
size_t | size, | |||
const char * | file, | |||
int | line, | |||
unsigned int | profile_index | |||
) |
Safely callocs heap memory by performing a call to calloc.
Verifies that the specified size is not oversized, callocs the memory, verifies that the memory pointer returned is not NULL, and performs some memory statistic handling.
num | Number of elements to allocate | |
size | Size of each element that is allocated | |
file | Name of file that called this function | |
line | Line number of file that called this function | |
profile_index | Profile index of function that called this function |
References curr_malloc_size, largest_malloc_size, MALLOC_CALL, and test_mode.
01426 { 01427 01428 void* obj; 01429 size_t total = (num * size); 01430 01431 assert( total > 0 ); 01432 01433 curr_malloc_size += total; 01434 01435 if( curr_malloc_size > largest_malloc_size ) { 01436 largest_malloc_size = curr_malloc_size; 01437 } 01438 01439 obj = calloc( num, size ); 01440 #ifdef TESTMODE 01441 if( test_mode ) { 01442 printf( "CALLOC (%p) %d bytes (file: %s, line: %d) - %" FMT64 "d\n", obj, (int)total, file, line, curr_malloc_size ); 01443 } 01444 #endif 01445 assert( obj != NULL ); 01446 01447 MALLOC_CALL(profile_index); 01448 01449 return( obj ); 01450 01451 }
bool check_option_value | ( | int | argc, | |
const char ** | argv, | |||
int | option_index | |||
) |
Checks to make sure that a value was properly specified for a given option.
This function is called whenever a command-line argument requires a value. It verifies that a value was specified (however, it does not make sure that the value is the correct type). Outputs an error message and returns a value of FALSE if a value was not specified; otherwise, returns TRUE.
argc | Number of arguments in the argv parameter list | |
argv | List of arguments being parsed | |
option_index | Index of current option being parsed |
References FALSE, FATAL, print_output(), PROFILE, PROFILE_END, TRUE, user_msg, and USER_MSG_LENGTH.
Referenced by exclude_parse_args(), merge_parse_args(), rank_parse_args(), report_parse_args(), and score_parse_args().
00314 { PROFILE(CHECK_OPTION_VALUE); 00315 00316 bool retval = TRUE; /* Return value for this function */ 00317 00318 if( ((option_index + 1) >= argc) || ((argv[option_index+1][0] == '-') && (strlen(argv[option_index+1]) > 1)) ) { 00319 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Missing option value to the right of the %s option", argv[option_index] ); 00320 assert( rv < USER_MSG_LENGTH ); 00321 print_output( user_msg, FATAL, __FILE__, __LINE__ ); 00322 retval = FALSE; 00323 } 00324 00325 PROFILE_END; 00326 00327 return( retval ); 00328 00329 }
bool directory_exists | ( | const char * | dir | ) |
Returns TRUE if the specified directory exists.
Checks to see if the specified directory actually exists in the file structure. If the directory is found to exist, returns TRUE; otherwise, returns FALSE.
dir | Name of directory to check for existence |
References FALSE, PROFILE, PROFILE_END, and TRUE.
Referenced by merge_parse_args(), rank_parse_args(), search_add_directory_path(), and search_add_include_path().
00641 { PROFILE(DIRECTORY_EXISTS); 00642 00643 bool retval = FALSE; /* Return value for this function */ 00644 struct stat filestat; /* Statistics of specified directory */ 00645 00646 if( stat( dir, &filestat ) == 0 ) { 00647 00648 if( S_ISDIR( filestat.st_mode ) ) { 00649 00650 retval = TRUE; 00651 00652 } 00653 00654 } 00655 00656 PROFILE_END; 00657 00658 return( retval ); 00659 00660 }
void directory_load | ( | const char * | dir, | |
const str_link * | ext_head, | |||
str_link ** | file_head, | |||
str_link ** | file_tail | |||
) |
Loads contents of specified directory to file list if extension is part of list.
anonymous | Throw |
Opens the specified directory for reading and loads (in order) all files that contain the specified extensions (if ext_head is NULL, load only *.v files). Stores all string filenames to the specified string list.
dir | Name of directory to read files from | |
ext_head | Pointer to extension list | |
file_head | Pointer to head element of filename string list | |
file_tail | Pointer to tail element of filename string list |
References FATAL, free_safe, malloc_safe, str_link_s::next, print_output(), PROFILE, PROFILE_END, str_link_s::str, str_link_add(), str_link_find(), str_link_s::suppl, Throw, user_msg, and USER_MSG_LENGTH.
Referenced by merge_parse_args(), rank_parse_args(), and search_add_directory_path().
00676 { PROFILE(DIRECTORY_LOAD); 00677 00678 DIR* dir_handle; /* Pointer to opened directory */ 00679 struct dirent* dirp; /* Pointer to current directory entry */ 00680 const str_link* curr_ext; /* Pointer to current extension string */ 00681 char* ptr; /* Pointer to current character in filename */ 00682 unsigned int tmpchars; /* Number of characters needed to store full pathname for file */ 00683 char* tmpfile; /* Temporary string holder for full pathname of file */ 00684 00685 if( (dir_handle = opendir( dir )) == NULL ) { 00686 00687 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Unable to read directory %s", dir ); 00688 assert( rv < USER_MSG_LENGTH ); 00689 print_output( user_msg, FATAL, __FILE__, __LINE__ ); 00690 Throw 0; 00691 00692 } else { 00693 00694 unsigned int rv; 00695 00696 while( (dirp = readdir( dir_handle )) != NULL ) { 00697 ptr = dirp->d_name + strlen( dirp->d_name ) - 1; 00698 /* Work backwards until a dot is encountered */ 00699 while( (ptr >= dirp->d_name) && (*ptr != '.') ) { 00700 ptr--; 00701 } 00702 if( *ptr == '.' ) { 00703 ptr++; 00704 curr_ext = ext_head; 00705 while( (curr_ext != NULL) && (strcmp( ptr, curr_ext->str ) != 0) ) { 00706 curr_ext = curr_ext->next; 00707 } 00708 if( curr_ext != NULL ) { 00709 unsigned int rv; 00710 /* Found valid extension, add to list */ 00711 tmpchars = strlen( dirp->d_name ) + strlen( dir ) + 2; 00712 tmpfile = (char*)malloc_safe( tmpchars ); 00713 rv = snprintf( tmpfile, tmpchars, "%s/%s", dir, dirp->d_name ); 00714 assert( rv < tmpchars ); 00715 if( str_link_find( tmpfile, *file_head ) == NULL ) { 00716 (void)str_link_add( tmpfile, file_head, file_tail ); 00717 (*file_tail)->suppl = 0x1; 00718 } else { 00719 free_safe( tmpfile, (strlen( tmpfile ) + 1) ); 00720 } 00721 } 00722 } 00723 } 00724 00725 rv = closedir( dir_handle ); 00726 assert( rv == 0 ); 00727 00728 } 00729 00730 PROFILE_END; 00731 00732 }
bool file_exists | ( | const char * | file | ) |
Returns TRUE if the specified file exists.
Checks to see if the specified file actually exists in the file structure. If the file is found to exist, returns TRUE; otherwise, returns FALSE.
file | Name of file to check for existence |
References FALSE, PROFILE, PROFILE_END, and TRUE.
Referenced by exclude_parse_args(), merge_parse_args(), rank_parse_args(), read_command_file(), report_parse_args(), score_parse_args(), and search_add_file().
00742 { PROFILE(FILE_EXISTS); 00743 00744 bool retval = FALSE; /* Return value for this function */ 00745 struct stat filestat; /* Statistics of specified directory */ 00746 00747 if( stat( file, &filestat ) == 0 ) { 00748 00749 if( S_ISREG( filestat.st_mode ) || S_ISFIFO( filestat.st_mode ) ) { 00750 00751 retval = TRUE; 00752 00753 } 00754 00755 } 00756 00757 PROFILE_END; 00758 00759 return( retval ); 00760 00761 }
void free_safe1 | ( | void * | ptr, | |
unsigned int | profile_index | |||
) |
Performs safe deallocation of heap memory.
Safely performs a free function of heap memory. Also keeps track of current memory usage for output information at end of program life.
ptr | Pointer to object to deallocate | |
profile_index | Profile index of function that called this function |
References FREE_CALL.
01297 { 01298 01299 if( ptr != NULL ) { 01300 free( ptr ); 01301 } 01302 01303 /* Profile the free */ 01304 FREE_CALL(profile_index); 01305 01306 }
void free_safe2 | ( | void * | ptr, | |
size_t | size, | |||
const char * | file, | |||
int | line, | |||
unsigned int | profile_index | |||
) |
Performs safe deallocation of heap memory.
Safely performs a free function of heap memory. Also keeps track of current memory usage for output information at end of program life.
ptr | Pointer to object to deallocate | |
size | Number of bytes that will be deallocated | |
file | File that is calling this function | |
line | Line number in file that is calling this function | |
profile_index | Profile index of function that called this function |
References curr_malloc_size, FREE_CALL, and test_mode.
01319 { 01320 01321 if( ptr != NULL ) { 01322 curr_malloc_size -= size; 01323 #ifdef TESTMODE 01324 if( test_mode ) { 01325 printf( "FREE (%p) %d bytes (file: %s, line: %d) - %" FMT64 "d\n", ptr, (int)size, file, line, curr_malloc_size ); 01326 } 01327 #endif 01328 free( ptr ); 01329 } 01330 01331 /* Profile the free */ 01332 FREE_CALL(profile_index); 01333 01334 }
void gen_char_string | ( | char * | str, | |
char | c, | |||
int | num_chars | |||
) |
Creates a string containing space characters.
Creates a string that contains num_chars number of characters specified by the value of c, adding a NULL character at the end of the string to allow for correct usage by the strlen and other string functions.
str | Pointer to string to places spaces into | |
c | Character to write | |
num_chars | Number of spaces to place in string |
References PROFILE, and PROFILE_END.
Referenced by combination_event(), combination_multi_expr_output(), combination_multi_vars(), combination_two_vars(), combination_unary(), combination_underline_tree(), fsm_display_arc_verbose(), ovl_display_verbose(), rank_output(), report_output_exclusion_reason(), search_add_extensions(), and toggle_display_verbose().
01462 { PROFILE(GEN_SPACE); 01463 01464 int i; /* Loop iterator */ 01465 01466 for( i=0; i<num_chars; i++ ) { 01467 str[i] = c; 01468 } 01469 01470 str[i] = '\0'; 01471 01472 PROFILE_END; 01473 01474 }
void gen_exclusion_id | ( | char * | excl_id, | |
char | type, | |||
int | id | |||
) |
Generates the exclusion identifier.
char* get_absolute_path | ( | const char * | filename | ) |
Allocates memory for and gets the absolute pathname for a given filename.
filename | Filename to get the absolute pathname of |
References free_safe, get_dirname(), malloc_safe, PROFILE, PROFILE_END, and strdup_safe.
Referenced by merge_parse_args().
00500 { PROFILE(GET_ABSOLUTE_PATH); 00501 00502 char* abs_path = NULL; 00503 char* tmp; 00504 char* dir; 00505 char this_cwd[4096]; 00506 char* srv; 00507 unsigned int irv; 00508 00509 /* Get a copy of the filename and calculate its directory and basename */ 00510 tmp = strdup_safe( filename ); 00511 dir = get_dirname( tmp ); 00512 00513 /* Get the original working directory so that we can return there */ 00514 srv = getcwd( this_cwd, 4096 ); 00515 assert( srv != NULL ); 00516 00517 /* If we have a directory to go to, change to the directory */ 00518 if( dir[0] != '\0' ) { 00519 00520 char cwd[4096]; 00521 unsigned int slen; 00522 char* file = dir + strlen( dir ) + 1; 00523 00524 /* Change to the specified directory */ 00525 irv = chdir( dir ); 00526 assert( irv == 0 ); 00527 00528 /* Get the current working directory and create the absolute path */ 00529 srv = getcwd( cwd, 4096 ); 00530 assert( srv != NULL ); 00531 00532 slen = strlen( cwd ) + strlen( file ) + 2; 00533 abs_path = (char*)malloc_safe( slen ); 00534 irv = snprintf( abs_path, slen, "%s/%s", cwd, file ); 00535 assert( irv < slen ); 00536 00537 /* Return to the original directory */ 00538 irv = chdir( this_cwd ); 00539 assert( irv == 0 ); 00540 00541 /* Otherwise, the file is in this directory */ 00542 } else { 00543 00544 unsigned int slen; 00545 00546 slen = strlen( this_cwd ) + strlen( filename ) + 2; 00547 00548 abs_path = (char*)malloc_safe( slen ); 00549 irv = snprintf( abs_path, slen, "%s/%s", this_cwd, filename ); 00550 assert( irv < slen ); 00551 00552 } 00553 00554 /* Deallocate used memory */ 00555 free_safe( tmp, (strlen( filename ) + 1) ); 00556 00557 PROFILE_END; 00558 00559 return( abs_path ); 00560 00561 }
const char* get_basename | ( | const char * | str | ) |
Extracts filename from file pathname.
Extracts the file basename of the specified filename string.
str | String containing pathname to file |
References PROFILE, and PROFILE_END.
Referenced by assertion_funit_summary(), combination_funit_summary(), fsm_funit_summary(), line_funit_summary(), memory_ae_funit_summary(), memory_toggle_funit_summary(), race_report_summary(), and toggle_funit_summary().
00446 { PROFILE(GET_BASENAME); 00447 00448 const char* ptr; /* Pointer to current character in str */ 00449 00450 ptr = (str + strlen( str )) - 1; 00451 00452 while( (ptr > str) && (*ptr != '/') ) { 00453 ptr--; 00454 } 00455 00456 if( *ptr == '/' ) { 00457 ptr++; 00458 } 00459 00460 PROFILE_END; 00461 00462 return( ptr ); 00463 00464 }
char* get_dirname | ( | char * | str | ) |
Extracts directory path from file pathname.
Extracts the directory path from the specified filename (or returns NULL if there is no directory path).
str | String containing pathname to file |
References PROFILE, and PROFILE_END.
Referenced by get_absolute_path().
00477 { PROFILE(GET_DIRNAME); 00478 00479 char* ptr; /* Pointer to current character in str */ 00480 00481 ptr = (str + strlen( str )) - 1; 00482 00483 while( (ptr > str) && (*ptr != '/') ) { 00484 ptr--; 00485 } 00486 00487 *ptr = '\0'; 00488 00489 PROFILE_END; 00490 00491 return( str ); 00492 00493 }
const char* get_funit_type | ( | int | type | ) |
Returns string representation of the specified functional unit type.
type | Type of functional unit (see Functional Unit Types for legal values) |
References funit_types, FUNIT_TYPES, PROFILE, and PROFILE_END.
Referenced by bind_task_function_namedblock(), db_add_function_task_namedblock(), db_add_instance(), funit_db_write(), funit_display_expressions(), funit_display_signals(), funit_link_display(), gen_item_stringify(), perf_output_mod_stats(), scope_find_param(), scope_find_signal(), and scope_find_task_function_namedblock().
01614 { PROFILE(GET_FUNIT_TYPE); 01615 01616 const char* type_str; 01617 01618 if( (type >= 0) && (type < FUNIT_TYPES) ) { 01619 type_str = funit_types[type]; 01620 } else { 01621 type_str = funit_types[FUNIT_TYPES]; 01622 } 01623 01624 PROFILE_END; 01625 01626 return( type_str ); 01627 01628 }
Returns next Verilog file to parse.
Iterates through specified file list, searching for next Verilog file to parse. If a file is a library file (suppl field is 'D'), the name of the module to search for is compared with the name of the file.
curr | Pointer to current file in list | |
mod | Name of module searching for |
References convert_file_to_module(), str_link_s::next, PROFILE, PROFILE_END, str_link_s::str, str_link_s::suppl, and str_link_s::suppl2.
01185 { PROFILE(GET_NEXT_VFILE); 01186 01187 str_link* next = NULL; /* Pointer to next Verilog file to parse */ 01188 char name[256]; /* String holder for module name of file */ 01189 01190 while( (curr != NULL) && (next == NULL) ) { 01191 if( (curr->suppl & 0x1) != 0x1 ) { 01192 next = curr; 01193 } else { 01194 convert_file_to_module( name, 256, curr->str ); 01195 if( strcmp( name, mod ) == 0 ) { 01196 next = curr; 01197 } else { 01198 curr = curr->next; 01199 } 01200 } 01201 } 01202 01203 /* Specify that the returned file will be parsed */ 01204 if( next != NULL ) { 01205 next->suppl2 = 1; 01206 } 01207 01208 PROFILE_END; 01209 01210 return( next ); 01211 01212 }
bool get_quoted_string | ( | FILE * | file, | |
char * | line | |||
) |
Reads in line from file and returns the contents of the quoted string following optional whitespace.
Parses a double-quoted string from the file pointer if one exists. Removes quotes.
file | Pointer to file to parse | |
line | User supplied character array to hold quoted string |
References FALSE, PROFILE, PROFILE_END, and TRUE.
Referenced by read_command_file().
00814 { PROFILE(GET_QUOTED_STRING); 00815 00816 bool found = FALSE; /* Return value for this function */ 00817 char c[128]; /* Temporary whitespace storage */ 00818 int i = 0; /* Loop iterator */ 00819 00820 /* First, remove any whitespace and temporarily store it */ 00821 while( ((c[i] = getc( file )) != EOF) && isspace( c[i] ) ) i++; 00822 00823 /* If the character we are looking at is a double-quote, continue parsing */ 00824 if( c[i] == '"' ) { 00825 00826 i = 0; 00827 while( ((line[i] = getc( file )) != EOF) && (line[i] != '"') ) i++; 00828 line[i] = '\0'; 00829 found = TRUE; 00830 00831 /* Otherwise, ungetc the collected characters */ 00832 } else { 00833 00834 for( ; i >= 0; i-- ) { 00835 (void)ungetc( c[i], file ); 00836 } 00837 00838 } 00839 00840 PROFILE_END; 00841 00842 return( found ); 00843 00844 }
char* get_relative_path | ( | const char * | abs_path | ) |
Allocates memory for and gets the relative pathname for a given absolute filename.
abs_path | Absolute pathname of file to get relative path for |
References PROFILE, PROFILE_END, and strdup_safe.
Referenced by merged_cdd_db_read(), and report_print_header().
00568 { PROFILE(GET_RELATIVE_PATH); 00569 00570 char* rel_path = NULL; 00571 char cwd[4096]; 00572 char* rv; 00573 unsigned int i; 00574 00575 /* Get the current working directory */ 00576 rv = getcwd( cwd, 4096 ); 00577 assert( rv != NULL ); 00578 00579 /* 00580 Compare the absolute path to the current working directory path and stop when we see a 00581 miscompare or run into the end of a path string. 00582 */ 00583 i = 0; 00584 while( (i < strlen( cwd )) && (i < strlen( abs_path )) && (abs_path[i] == cwd[i]) ) i++; 00585 00586 /* We should have never gotten to the end of the absolute path */ 00587 assert( i < strlen( abs_path ) ); 00588 00589 /* 00590 If the current working directory is completely a part of the absolute path, the relative pathname 00591 is beneath the current working directory. 00592 */ 00593 if( i == strlen( cwd ) ) { 00594 rel_path = strdup_safe( abs_path + i + 1 ); 00595 00596 /* 00597 Otherwise, we need to back up and go forward. 00598 */ 00599 } else { 00600 00601 unsigned int save_i; 00602 char trel[4096]; 00603 00604 /* Find the previous backslash */ 00605 while( (i > 0) && (cwd[i] != '/') ) i--; 00606 assert( cwd[i] == '/' ); 00607 00608 /* Save the current position of i */ 00609 save_i = i + 1; 00610 00611 /* Create back portion of path */ 00612 trel[0] = '\0'; 00613 for( ; i<strlen( cwd ); i++ ) { 00614 if( cwd[i] == '/' ) { 00615 strcat( trel, "../" ); 00616 } 00617 } 00618 00619 /* Now append the absolute path */ 00620 strcat( trel, (abs_path + save_i) ); 00621 00622 /* Finally, make a copy of the calculated relative path */ 00623 rel_path = strdup_safe( trel ); 00624 00625 } 00626 00627 PROFILE_END; 00628 00629 return( rel_path ); 00630 00631 }
bool is_func_unit | ( | const char * | token | ) |
Returns TRUE if the specified string is a legal functional unit value.
token | Pointer to string to parse |
References FALSE, free_safe, is_variable(), PROFILE, PROFILE_END, scope_extract_front(), and strdup_safe.
Referenced by search_add_no_score_funit().
00383 { PROFILE(IS_FUNC_UNIT); 00384 00385 char* orig; /* Temporary string */ 00386 char* rest; /* Temporary string */ 00387 char* front; /* Temporary string */ 00388 bool okay = (strlen( token ) > 0); /* Specifies if this token is a functional unit value or not */ 00389 00390 /* Allocate memory */ 00391 orig = strdup_safe( token ); 00392 rest = strdup_safe( token ); 00393 front = strdup_safe( token ); 00394 00395 /* Check to make sure that each value between '.' is a valid variable */ 00396 while( (strlen( orig ) > 0) && okay ) { 00397 scope_extract_front( orig, front, rest ); 00398 if( !is_variable( front ) ) { 00399 okay = FALSE; 00400 } else { 00401 strcpy( orig, rest ); 00402 } 00403 } 00404 00405 /* Deallocate memory */ 00406 free_safe( orig, (strlen( token ) + 1) ); 00407 free_safe( rest, (strlen( token ) + 1) ); 00408 free_safe( front, (strlen( token ) + 1) ); 00409 00410 PROFILE_END; 00411 00412 return( okay ); 00413 00414 }
bool is_legal_filename | ( | const char * | token | ) |
Returns TRUE if the specified string could be a valid filename.
token | String to check for valid pathname-ness |
References FALSE, PROFILE, PROFILE_END, and TRUE.
Referenced by merge_parse_args(), rank_parse_args(), report_parse_args(), and score_parse_args().
00422 { PROFILE(IS_LEGAL_FILENAME); 00423 00424 bool retval = FALSE; /* Return value for this function */ 00425 FILE* tmpfile; /* Temporary file pointer */ 00426 00427 if( (tmpfile = fopen( token, "w" )) != NULL ) { 00428 unsigned int rv = fclose( tmpfile ); 00429 assert( rv == 0 ); 00430 retval = TRUE; 00431 } 00432 00433 PROFILE_END; 00434 00435 return( retval ); 00436 00437 }
bool is_variable | ( | const char * | token | ) |
Returns TRUE if the specified string is a legal variable name.
If the specified string follows all of the rules for a legal program variable (doesn't start with a number, contains only a-zA-Z0-9_ characters), returns a value of TRUE; otherwise, returns a value of FALSE.
token | String to check for valid variable name |
References FALSE, PROFILE, PROFILE_END, and TRUE.
Referenced by is_func_unit(), and score_parse_args().
00341 { PROFILE(IS_VARIABLE); 00342 00343 bool retval = TRUE; /* Return value of this function */ 00344 00345 if( token != NULL ) { 00346 00347 if( (token[0] >= '0') && (token[0] <= '9') ) { 00348 00349 retval = FALSE; 00350 00351 } else { 00352 00353 while( (token[0] != '\0') && retval ) { 00354 if( !(((token[0] >= 'a') && (token[0] <= 'z')) || 00355 ((token[0] >= 'A') && (token[0] <= 'Z')) || 00356 ((token[0] >= '0') && (token[0] <= '9')) || 00357 (token[0] == '_')) ) { 00358 retval = FALSE; 00359 } 00360 token++; 00361 } 00362 00363 } 00364 00365 } else { 00366 00367 retval = FALSE; 00368 00369 } 00370 00371 PROFILE_END; 00372 00373 return( retval ); 00374 00375 }
void* malloc_safe1 | ( | size_t | size, | |
const char * | file, | |||
int | line, | |||
unsigned int | profile_index | |||
) |
Performs safe malloc call.
Allocated memory like a malloc() call but performs some pre-allocation and post-allocation checks to be sure that the malloc call works properly.
size | Number of bytes to allocate | |
file | File that called this function | |
line | Line number of file that called this function | |
profile_index | Profile index of function that called this function |
References curr_malloc_size, largest_malloc_size, MALLOC_CALL, MAX_MALLOC_SIZE, and test_mode.
01225 { 01226 01227 void* obj; /* Object getting malloc address */ 01228 01229 assert( size <= MAX_MALLOC_SIZE ); 01230 01231 curr_malloc_size += size; 01232 01233 if( curr_malloc_size > largest_malloc_size ) { 01234 largest_malloc_size = curr_malloc_size; 01235 } 01236 01237 obj = malloc( size ); 01238 #ifdef TESTMODE 01239 if( test_mode ) { 01240 printf( "MALLOC (%p) %d bytes (file: %s, line: %d) - %" FMT64 "d\n", obj, (int)size, file, line, curr_malloc_size ); 01241 } 01242 #endif 01243 assert( obj != NULL ); 01244 01245 /* Profile the malloc */ 01246 MALLOC_CALL(profile_index); 01247 01248 return( obj ); 01249 01250 }
void* malloc_safe_nolimit1 | ( | size_t | size, | |
const char * | file, | |||
int | line, | |||
unsigned int | profile_index | |||
) |
Performs safe malloc call without upper bound on byte allocation.
Allocated memory like a malloc() call but performs some pre-allocation and post-allocation checks to be sure that the malloc call works properly. Unlike malloc_safe, there is no upper bound on the amount of memory to allocate.
size | Number of bytes to allocate | |
file | Name of file that called this function | |
line | Line number of file that called this function | |
profile_index | Profile index of function that called this function |
References curr_malloc_size, largest_malloc_size, MALLOC_CALL, and test_mode.
01264 { 01265 01266 void* obj; /* Object getting malloc address */ 01267 01268 curr_malloc_size += size; 01269 01270 if( curr_malloc_size > largest_malloc_size ) { 01271 largest_malloc_size = curr_malloc_size; 01272 } 01273 01274 obj = malloc( size ); 01275 #ifdef TESTMODE 01276 if( test_mode ) { 01277 printf( "MALLOC (%p) %d bytes (file: %s, line: %d) - %" FMT64 "d\n", obj, (int)size, file, line, curr_malloc_size ); 01278 } 01279 #endif 01280 assert( obj != NULL ); 01281 01282 /* Profile the malloc */ 01283 MALLOC_CALL(profile_index); 01284 01285 return( obj ); 01286 01287 }
void print_output | ( | const char * | msg, | |
int | type, | |||
const char * | file, | |||
int | line | |||
) |
Displays error message to standard output.
Displays the specified message to standard output based on the type of message being output.
msg | Message to display | |
type | Type of message to output (see Output type for legal values) | |
file | Name of file that called this function | |
line | Line number that this function was called in |
References cli_debug_mode, DEBUG, debug_mode, FATAL, FATAL_WRAP, flag_use_command_line_debug, HEADER, interp, NORMAL, obf_file, quiet_mode, terse_mode, USER_MSG_LENGTH, vpi_print_output(), WARNING, WARNING_WRAP, and warnings_suppressed.
Referenced by arc_db_read(), args_db_read(), bind_perform(), bind_signal(), bind_task_function_namedblock(), check_option_value(), combination_underline_tree(), command_exclude(), command_merge(), command_rank(), command_report(), command_score(), covered_create_value_change_cb(), covered_parse_instance(), covered_parse_signals(), covered_parse_task_func(), covered_value_change_bin(), covered_value_change_real(), db_add_declared_param(), db_add_defparam(), db_add_enum(), db_add_expression(), db_add_file_version(), db_add_function_task_namedblock(), db_add_instance(), db_add_module(), db_add_override_param(), db_add_signal(), db_add_statement(), db_add_typedef(), db_add_vector_param(), db_assign_symbol(), db_bind_expr_tree(), db_check_dumpfile_scopes(), db_connect_statement_false(), db_connect_statement_true(), db_create_attr_param(), db_create_expr_from_static(), db_create_expression(), db_create_statement(), db_do_timestep(), db_end_enum_list(), db_end_function_task_namedblock(), db_end_module(), db_find_gen_item(), db_find_signal(), db_find_typedef(), db_gen_item_connect(), db_gen_item_connect_false(), db_gen_item_connect_true(), db_get_curr_gen_block(), db_merge_instance_trees(), db_parallelize_statement(), db_parse_attribute(), db_read(), db_remove_statement(), db_remove_statement_from_current_funit(), db_set_symbol_char(), db_set_symbol_string(), db_set_vcd_scope(), db_statement_connect(), db_vcd_upscope(), db_write(), defparam_add(), directory_load(), enumerate_resolve(), exclude_apply_exclusions(), exclude_assert_from_id(), exclude_db_merge(), exclude_db_read(), exclude_expr_from_id(), exclude_fsm_from_id(), exclude_get_message(), exclude_line_from_id(), exclude_memory_from_id(), exclude_parse_args(), exclude_toggle_from_id(), expression_assign(), expression_create_value(), expression_db_merge(), expression_db_read(), expression_dealloc(), expression_op_func__bitstoreal(), expression_op_func__bitstoshortreal(), expression_op_func__itor(), expression_op_func__realtobits(), expression_op_func__rtoi(), expression_op_func__shortrealtobits(), expression_op_func__test_plusargs(), expression_op_func__urandom_range(), expression_op_func__value_plusargs(), expression_operate(), expression_resize(), fsm_arg_parse(), fsm_arg_parse_attr(), fsm_arg_parse_trans(), fsm_db_merge(), fsm_db_read(), fsm_var_bind_expr(), fst_parse(), funit_db_inst_merge(), funit_db_mod_merge(), funit_db_read(), funit_db_write(), gen_item_create_bind(), gen_item_create_expr(), gen_item_create_inst(), gen_item_create_sig(), gen_item_create_stmt(), gen_item_create_tfn(), gen_item_resolve(), info_db_read(), info_set_vector_elem_size(), instance_only_db_merge(), instance_only_db_read(), instance_resolve_helper(), lxt2_rd_init(), lxt2_rd_iter_radix(), lxt2_rd_iter_radix0(), lxt2_rd_process_block(), lxt_parse(), main(), merge_check(), merge_parse_args(), merged_cdd_db_read(), param_find_and_set_expr_value(), parse_and_score_dumpfile(), parse_design(), parse_readline(), profiler_report(), race_check_modules(), race_check_race_count(), race_db_read(), race_handle_race_condition(), rank_check_index(), rank_output(), rank_parse_args(), rank_perform(), rank_read_cdd(), read_command_file(), report_parse_args(), report_parse_metrics(), report_read_cdd_and_ready(), scope_find_param(), scope_find_signal(), scope_find_task_function_namedblock(), score_generate_pli_tab_file(), score_generate_top_dumpvars_module(), score_generate_top_vpi_module(), score_parse_args(), search_add_directory_path(), search_add_extensions(), search_add_file(), search_add_include_path(), search_add_no_score_funit(), search_init(), sim_expr_changed(), sim_expression(), sim_thread(), statement_db_read(), stmt_blk_specify_removal_reason(), substitute_env_vars(), vcd_parse(), vcd_parse_def(), vcd_parse_def_scope(), vcd_parse_def_var(), vcd_parse_sim(), vcd_parse_sim_ignore(), vcd_parse_sim_real(), vcd_parse_sim_vector(), vector_db_merge(), vector_db_read(), VLerror(), VLwarn(), vsignal_db_merge(), vsignal_db_read(), and vsignal_vcd_assign().
00177 { 00178 00179 FILE* outf = debug_mode ? stdout : stderr; 00180 char tmpmsg[USER_MSG_LENGTH]; 00181 00182 switch( type ) { 00183 case DEBUG: 00184 if( debug_mode && (!flag_use_command_line_debug || cli_debug_mode) ) { 00185 #ifdef VPI_ONLY 00186 vpi_print_output( msg ); 00187 #else 00188 unsigned int rv; 00189 printf( "%s\n", msg ); rv = fflush( stdout ); assert( rv == 0 ); 00190 #endif 00191 } 00192 break; 00193 case HEADER: 00194 if( !quiet_mode || terse_mode || debug_mode ) { 00195 #ifdef VPI_ONLY 00196 vpi_print_output( msg ); 00197 #else 00198 printf( "%s\n", msg ); 00199 #endif 00200 } 00201 break; 00202 case NORMAL: 00203 if( (!quiet_mode && !terse_mode) || debug_mode ) { 00204 #ifdef VPI_ONLY 00205 vpi_print_output( msg ); 00206 #else 00207 printf( "%s\n", msg ); 00208 #endif 00209 } 00210 break; 00211 case WARNING: 00212 if( (!quiet_mode || terse_mode) && !warnings_suppressed ) { 00213 if( interp != NULL ) { 00214 unsigned int rv = snprintf( tmpmsg, USER_MSG_LENGTH, "WARNING! %s\n", msg ); 00215 assert( rv < USER_MSG_LENGTH ); 00216 #ifndef VPI_ONLY 00217 #ifdef HAVE_TCLTK 00218 Tcl_SetResult( interp, tmpmsg, TCL_VOLATILE ); 00219 #endif 00220 #endif 00221 } else { 00222 fprintf( outf, " WARNING! %s\n", msg ); 00223 } 00224 } else if( debug_mode ) { 00225 if( interp != NULL ) { 00226 unsigned int rv = snprintf( tmpmsg, USER_MSG_LENGTH, "WARNING! %s (file: %s, line: %d)\n", msg, file, line ); 00227 assert( rv < USER_MSG_LENGTH ); 00228 #ifndef VPI_ONLY 00229 #ifdef HAVE_TCLTK 00230 Tcl_SetResult( interp, tmpmsg, TCL_VOLATILE ); 00231 #endif 00232 #endif 00233 } else { 00234 fprintf( outf, " WARNING! %s (file: %s, line: %d)\n", msg, obf_file( file ), line ); 00235 } 00236 } 00237 break; 00238 case WARNING_WRAP: 00239 if( ((!quiet_mode || terse_mode) && !warnings_suppressed) || debug_mode ) { 00240 if( interp != NULL ) { 00241 unsigned int rv = snprintf( tmpmsg, USER_MSG_LENGTH, " %s\n", msg ); 00242 assert( rv < USER_MSG_LENGTH ); 00243 #ifndef VPI_ONLY 00244 #ifdef HAVE_TCLTK 00245 Tcl_AppendElement( interp, tmpmsg ); 00246 #endif 00247 #endif 00248 } else { 00249 fprintf( outf, " %s\n", msg ); 00250 } 00251 } 00252 break; 00253 case FATAL: 00254 (void)fflush( outf ); 00255 if( debug_mode ) { 00256 if( interp != NULL ) { 00257 unsigned int rv = snprintf( tmpmsg, USER_MSG_LENGTH, "%s (file: %s, line: %d)\n", msg, file, line ); 00258 assert( rv < USER_MSG_LENGTH ); 00259 #ifndef VPI_ONLY 00260 #ifdef HAVE_TCLTK 00261 Tcl_SetResult( interp, tmpmsg, TCL_VOLATILE ); 00262 fprintf( stderr, "ERROR! %s (file: %s, line: %d)\n", msg, obf_file( file ), line ); 00263 #endif 00264 #endif 00265 } else { 00266 fprintf( stderr, "ERROR! %s (file: %s, line: %d)\n", msg, obf_file( file ), line ); 00267 } 00268 } else { 00269 if( interp != NULL ) { 00270 unsigned int rv = snprintf( tmpmsg, USER_MSG_LENGTH, "%s\n", msg ); 00271 assert( rv < USER_MSG_LENGTH ); 00272 #ifndef VPI_ONLY 00273 #ifdef HAVE_TCLTK 00274 Tcl_SetResult( interp, tmpmsg, TCL_VOLATILE ); 00275 fprintf( stderr, "ERROR! %s\n", msg ); 00276 #endif 00277 #endif 00278 } else { 00279 fprintf( stderr, "ERROR! %s\n", msg ); 00280 } 00281 } 00282 break; 00283 case FATAL_WRAP: 00284 if( interp != NULL ) { 00285 unsigned int rv = snprintf( tmpmsg, USER_MSG_LENGTH, "%s\n", msg ); 00286 assert( rv < USER_MSG_LENGTH ); 00287 #ifndef VPI_ONLY 00288 #ifdef HAVE_TCLTK 00289 Tcl_AppendElement( interp, tmpmsg ); 00290 #endif 00291 #endif 00292 } else { 00293 fprintf( stderr, " %s\n", msg ); 00294 } 00295 break; 00296 default: break; 00297 } 00298 00299 }
void read_command_file | ( | const char * | cmd_file, | |
char *** | arg_list, | |||
int * | arg_num | |||
) |
Reads in contents of command file, substitutes environment variables and stores them to the arg_list array.
anonymous | Throw Throw Throw substitute_env_vars |
Parses the given file specified by the '-f' option to one of Covered's commands which can contain any command-line arguments. Performs environment variable substitution to any $... variables that are found in the file.
cmd_file | Name of file to read commands from | |
arg_list | List of arguments found in specified command file | |
arg_num | Number of arguments in arg_list array |
References Catch_anonymous, FATAL, file_exists(), get_quoted_string(), malloc_safe, str_link_s::next, print_output(), PROFILE, str_link_s::str, str_link_add(), str_link_delete_list(), strdup_safe, substitute_env_vars(), Throw, Try, user_msg, and USER_MSG_LENGTH.
Referenced by exclude_parse_args(), merge_parse_args(), rank_parse_args(), report_parse_args(), and score_parse_args().
01667 { PROFILE(READ_COMMAND_FILE); 01668 01669 str_link* head = NULL; /* Pointer to head element of arg list */ 01670 str_link* tail = NULL; /* Pointer to tail element of arg list */ 01671 FILE* cmd_handle; /* Pointer to command file */ 01672 char tmp_str[4096]; /* Temporary holder for read argument */ 01673 str_link* curr; /* Pointer to current str_link element */ 01674 int tmp_num = 0; /* Temporary argument number holder */ 01675 bool use_stdin; /* If set to TRUE, uses stdin for the cmd_handle */ 01676 01677 /* Figure out if we should use stdin */ 01678 use_stdin = (strcmp( "-", cmd_file ) == 0); 01679 01680 if( use_stdin || file_exists( cmd_file ) ) { 01681 01682 if( (cmd_handle = (use_stdin ? stdin : fopen( cmd_file, "r" ))) != NULL ) { 01683 01684 unsigned int rv; 01685 01686 Try { 01687 01688 while( get_quoted_string( cmd_handle, tmp_str ) || fscanf( cmd_handle, "%s", tmp_str ) == 1 ) { 01689 (void)str_link_add( substitute_env_vars( tmp_str ), &head, &tail ); 01690 tmp_num++; 01691 } 01692 01693 } Catch_anonymous { 01694 rv = fclose( cmd_handle ); 01695 assert( rv == 0 ); 01696 str_link_delete_list( head ); 01697 Throw 0; 01698 } 01699 01700 rv = fclose( cmd_handle ); 01701 assert( rv == 0 ); 01702 01703 /* Set the argument list number now */ 01704 *arg_num = tmp_num; 01705 01706 /* 01707 If there were any arguments found in the file, create an argument list and pass it to the 01708 command-line parser. 01709 */ 01710 if( tmp_num > 0 ) { 01711 01712 /* Create argument list */ 01713 *arg_list = (char**)malloc_safe( sizeof( char* ) * tmp_num ); 01714 tmp_num = 0; 01715 01716 curr = head; 01717 while( curr != NULL ) { 01718 (*arg_list)[tmp_num] = strdup_safe( curr->str ); 01719 tmp_num++; 01720 curr = curr->next; 01721 } 01722 01723 /* Delete list */ 01724 str_link_delete_list( head ); 01725 01726 } 01727 01728 } else { 01729 01730 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Unable to open command file %s for reading", cmd_file ); 01731 assert( rv < USER_MSG_LENGTH ); 01732 print_output( user_msg, FATAL, __FILE__, __LINE__ ); 01733 Throw 0; 01734 01735 } 01736 01737 } else { 01738 01739 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Command file %s does not exist", cmd_file ); 01740 assert( rv < USER_MSG_LENGTH ); 01741 print_output( user_msg, FATAL, __FILE__, __LINE__ ); 01742 Throw 0; 01743 01744 } 01745 01746 }
void* realloc_safe1 | ( | void * | ptr, | |
size_t | old_size, | |||
size_t | size, | |||
const char * | file, | |||
int | line, | |||
unsigned int | profile_index | |||
) |
Safely reallocates heap memory by performing a call to realloc.
Calls the realloc() function for the specified memory and size, making sure that the memory size doesn't exceed a threshold value and that the requested memory was allocated.
ptr | Pointer to old memory to copy | |
old_size | Size of originally allocated memory (in bytes) | |
size | Size of new allocated memory (in bytes) | |
file | Name of file that called this function | |
line | Line number of file that called this function | |
profile_index | Profile index of function that called this function |
References curr_malloc_size, largest_malloc_size, MALLOC_CALL, MAX_MALLOC_SIZE, and test_mode.
01381 { 01382 01383 void* newptr; 01384 01385 assert( size <= MAX_MALLOC_SIZE ); 01386 01387 curr_malloc_size -= old_size; 01388 curr_malloc_size += size; 01389 if( curr_malloc_size > largest_malloc_size ) { 01390 largest_malloc_size = curr_malloc_size; 01391 } 01392 01393 if( size == 0 ) { 01394 if( ptr != NULL ) { 01395 free( ptr ); 01396 } 01397 newptr = NULL; 01398 } else { 01399 newptr = realloc( ptr, size ); 01400 assert( newptr != NULL ); 01401 } 01402 #ifdef TESTMODE 01403 if( test_mode ) { 01404 printf( "REALLOC (%p -> %p) %d (%d) bytes (file: %s, line: %d) - %" FMT64 "d\n", ptr, newptr, (int)size, (int)old_size, file, line, curr_malloc_size ); 01405 } 01406 #endif 01407 01408 MALLOC_CALL(profile_index); 01409 01410 return( newptr ); 01411 01412 }
char* remove_underscores | ( | char * | str | ) |
Removes underscores from the specified string.
str | String to remove underscore characters from |
References PROFILE, and PROFILE_END.
Referenced by vector_db_read(), and vector_from_string().
01482 { PROFILE(REMOVE_UNDERSCORES); 01483 01484 char* start = NULL; 01485 unsigned int i; 01486 unsigned int cur = 1; 01487 01488 for( i=0; i<strlen( str ); i++ ) { 01489 if( str[i] != '_' ) { 01490 if( start == NULL ) { 01491 start = str + i; 01492 } else { 01493 start[cur++] = str[i]; 01494 } 01495 } 01496 } 01497 01498 if( start != NULL ) { 01499 start[cur] = '\0'; 01500 } 01501 01502 PROFILE_END; 01503 01504 return( start ); 01505 01506 }
bool scope_compare | ( | const char * | str1, | |
const char * | str2 | |||
) |
Compares two signal names or two instance names.
str1 | Pointer to signal/instance name | |
str2 | Pointer to signal/instance name |
References free_safe, PROFILE, PROFILE_END, and scope_gen_printable().
Referenced by funit_link_find(), gen_item_compare(), instance_compare(), instance_dealloc(), sig_link_find(), vsignal_db_merge(), and vsignal_merge().
01062 { PROFILE(SCOPE_COMPARE); 01063 01064 bool retval; /* Return value for this function */ 01065 char* new_str1; /* New form of str1 with escaped sequences removed */ 01066 char* new_str2; /* New form of str1 with escaped sequences removed */ 01067 01068 /* Create printable versions of the strings */ 01069 new_str1 = scope_gen_printable( str1 ); 01070 new_str2 = scope_gen_printable( str2 ); 01071 01072 /* Perform the compare */ 01073 retval = (strcmp( new_str1, new_str2 ) == 0); 01074 01075 /* Deallocate the memory */ 01076 free_safe( new_str1, (strlen( new_str1 ) + 1) ); 01077 free_safe( new_str2, (strlen( new_str2 ) + 1) ); 01078 01079 PROFILE_END; 01080 01081 return( retval ); 01082 01083 }
void scope_extract_back | ( | const char * | scope, | |
char * | back, | |||
char * | rest | |||
) |
Extracts lowest level of hierarchy from specified scope.
Extracts the lowest level of hierarchy from the specified scope, returning that instance name to the value of back and the the rest of the hierarchy in the value of rest.
scope | Full scope to extract from | |
back | Lowest level of hierarchy extracted | |
rest | Hierarchy left after extraction |
References PROFILE, and PROFILE_END.
Referenced by bind_task_function_namedblock(), codegen_gen_expr(), combination_underline_tree(), db_read(), funit_is_unnamed(), instance_dealloc(), instance_only_db_merge(), instance_only_db_read(), lxt_parse(), scope_find_param(), scope_find_signal(), scope_get_parent_funit(), scope_get_parent_module(), and search_init().
00968 { PROFILE(SCOPE_EXTRACT_BACK); 00969 00970 const char* ptr; /* Pointer to current character */ 00971 char endchar; /* Set to the character we are searching for */ 00972 00973 ptr = scope + strlen( scope ) - 1; 00974 00975 /* Figure out if we are looking for a '.' or a ' ' character */ 00976 endchar = (*ptr == ' ') ? '\\' : '.'; 00977 00978 while( (ptr > scope) && (*ptr != endchar) ) { 00979 ptr--; 00980 } 00981 00982 /* If this is a literal, keep going until we see the '.' character */ 00983 if( endchar == '\\' ) { 00984 while( (ptr > scope) && (*ptr != '.') ) { 00985 ptr--; 00986 } 00987 } 00988 00989 strncpy( rest, scope, (ptr - scope) ); 00990 rest[ (ptr - scope) ] = '\0'; 00991 00992 if( *ptr == '.' ) { 00993 ptr++; 00994 } 00995 00996 strncpy( back, ptr, ((strlen( scope ) + scope) - ptr) ); 00997 back[ ((strlen( scope ) + scope) - ptr) ] = '\0'; 00998 00999 PROFILE_END; 01000 01001 }
void scope_extract_front | ( | const char * | scope, | |
char * | front, | |||
char * | rest | |||
) |
Extracts highest level of hierarchy from specified scope.
Extracts the highest level of hierarchy from the specified scope, returning that instance name to the value of front and the the rest of the hierarchy in the value of rest.
scope | Full scope to extract from | |
front | Highest level of hierarchy extracted | |
rest | Hierarchy left after extraction |
References PROFILE, and PROFILE_END.
Referenced by bind_find_sig_name(), funit_flatten_name(), instance_find_scope(), is_func_unit(), score_generate_pli_tab_file(), score_generate_top_dumpvars_module(), score_generate_top_vpi_module(), and search_init().
00923 { PROFILE(SCOPE_EXTRACT_FRONT); 00924 00925 const char* ptr; /* Pointer to current character */ 00926 char endchar; /* Set to the character we are searching for */ 00927 00928 ptr = scope; 00929 00930 /* Figure out if we are looking for a '.' or a ' ' character */ 00931 endchar = (*ptr == '\\') ? ' ' : '.'; 00932 00933 while( (*ptr != '\0') && (*ptr != endchar) ) { 00934 ptr++; 00935 } 00936 00937 /* If this is a literal, keep going until we see the '.' character */ 00938 if( endchar == ' ' ) { 00939 while( (*ptr != '\0') && (*ptr != '.') ) { 00940 ptr++; 00941 } 00942 } 00943 00944 strncpy( front, scope, (ptr - scope) ); 00945 front[ (ptr - scope) ] = '\0'; 00946 00947 if( *ptr == '.' ) { 00948 ptr++; 00949 strncpy( rest, ptr, (strlen( scope ) - (ptr - scope)) ); 00950 rest[ (strlen( scope ) - (ptr - scope)) ] = '\0'; 00951 } else { 00952 rest[0] = '\0'; 00953 } 00954 00955 PROFILE_END; 00956 00957 }
void scope_extract_scope | ( | const char * | scope, | |
const char * | front, | |||
char * | back | |||
) |
Extracts rest of scope not included in front.
Parses the given scope and removes the front portion of this scope (if the front portion of the scope matches the beginning portion of scope) and returns the remaining scope in the array pointed to by back. If front does not exist within scope, back is set to a value of the null string. Assumes that the length of back is allocated and large enough to hold the full value of scope, if necessary.
scope | Full scope to search | |
front | Leading portion of scope to exclude | |
back | Following portion of scope that is in scope that is not in front |
References PROFILE, and PROFILE_END.
01013 { PROFILE(SCOPE_EXTRACT_SCOPE); 01014 01015 back[0] = '\0'; 01016 01017 if( (strncmp( scope, front, strlen( front ) ) == 0) && (strlen( scope ) > strlen( front )) ) { 01018 strcpy( back, (scope + strlen( front ) + 1) ); 01019 } 01020 01021 PROFILE_END; 01022 01023 }
char* scope_gen_printable | ( | const char * | str | ) |
Generates printable version of given signal/instance string.
Allocates memory for and generates a printable version of the given string (a signal or instance name). The calling function is responsible for deallocating the string returned.
str | String to create printable version of |
References obf_sig, PROFILE, PROFILE_END, and strdup_safe.
Referenced by assertion_funit_summary(), assertion_funit_verbose(), assertion_instance_summary(), assertion_instance_verbose(), codegen_gen_expr(), combination_funit_verbose(), combination_instance_summary(), combination_instance_verbose(), combination_underline_tree(), fsm_funit_summary(), fsm_funit_verbose(), fsm_instance_summary(), fsm_instance_verbose(), instance_display_tree_helper(), line_funit_summary(), line_funit_verbose(), line_instance_summary(), line_instance_verbose(), memory_ae_funit_summary(), memory_ae_instance_summary(), memory_display_verbose(), memory_instance_verbose(), memory_toggle_funit_summary(), memory_toggle_instance_summary(), scope_compare(), toggle_display_verbose(), toggle_funit_summary(), toggle_instance_summary(), and toggle_instance_verbose().
01033 { PROFILE(SCOPE_GEN_PRINTABLE); 01034 01035 char* new_str; /* New version of string with escaped sequences removed */ 01036 01037 assert( strlen( obf_sig( str ) ) < 4096 ); 01038 01039 /* Remove escape sequences, if any */ 01040 if( str[0] == '\\' ) { 01041 char tmp_str[4096]; 01042 unsigned int rv = sscanf( str, "\\%[^ \n\t\r\b]", tmp_str ); 01043 assert( rv == 1 ); 01044 new_str = strdup_safe( tmp_str ); 01045 } else { 01046 new_str = strdup_safe( obf_sig( str ) ); 01047 } 01048 01049 PROFILE_END; 01050 01051 return( new_str ); 01052 01053 }
bool scope_local | ( | const char * | scope | ) |
Returns TRUE if specified scope is local (contains no periods).
scope | Scope of some signal |
References FALSE, PROFILE, PROFILE_END, and TRUE.
Referenced by bind_param(), bind_signal(), bind_task_function_namedblock(), funit_db_write(), scope_find_param(), and scope_find_signal().
01094 { PROFILE(SCOPE_LOCAL); 01095 01096 const char* ptr; /* Pointer to current character */ 01097 bool esc; /* Set to TRUE if current is escaped */ 01098 bool wspace = FALSE; /* Set if last character seen was a whitespace */ 01099 01100 assert( scope != NULL ); 01101 01102 ptr = scope; 01103 esc = (*ptr == '\\'); 01104 while( (*ptr != '\0') && ((*ptr != '.') || esc) ) { 01105 if( (*ptr == ' ') || (*ptr == '\n') || (*ptr == '\t') || (*ptr == '\b') || (*ptr == '\r') ) { 01106 esc = FALSE; 01107 wspace = TRUE; 01108 } else { 01109 if( wspace && (*ptr == '\\') ) { 01110 esc = TRUE; 01111 } 01112 } 01113 ptr++; 01114 } 01115 01116 PROFILE_END; 01117 01118 return( *ptr == '\0' ); 01119 01120 }
void set_debug | ( | bool | value | ) |
Sets global debug flag to specified value.
Sets the global debug mode to the specified value.
value | Boolean value of debug mode |
References debug_mode.
Referenced by main().
00152 { 00153 00154 debug_mode = value; 00155 00156 }
void set_quiet | ( | bool | value | ) |
Sets quiet output variable to specified value.
Sets the global quiet_mode variable to the specified value.
value | Boolean value of suppression |
References quiet_mode.
Referenced by main().
00130 { 00131 00132 quiet_mode = value; 00133 00134 }
void set_terse | ( | bool | value | ) |
Sets terse output variable to specified value.
Set the global terse_mode variable to the given value.
value | Boolean value of terse mode |
References terse_mode.
Referenced by main().
00141 { 00142 00143 terse_mode = value; 00144 00145 }
void set_testmode | ( | ) |
Sets the testmode global variable for outputting purposes.
Looks at the user's environment and searches for COVERED_TESTMODE, if the environment variable is set, sets the global test_mode variable to TRUE; otherwise, sets it to FALSE.
References test_mode.
Referenced by main().
00162 { 00163 00164 test_mode = (getenv( "COVERED_TESTMODE" ) != NULL); 00165 00166 }
void set_timestep | ( | sim_time * | st, | |
char * | value | |||
) |
Sets the given timestep to the correct value from VCD simulation file.
char* strdup_safe1 | ( | const char * | str, | |
const char * | file, | |||
int | line, | |||
unsigned int | profile_index | |||
) |
Safely allocates heap memory by performing a call to strdup.
Calls the strdup() function for the specified string, making sure that the string to allocate is a healthy string (contains NULL character).
str | String to duplicate | |
file | Name of file that called this function | |
line | Line number of file that called this function | |
profile_index | Profile index of function that called this function |
References curr_malloc_size, largest_malloc_size, MALLOC_CALL, MAX_MALLOC_SIZE, and test_mode.
01345 { 01346 01347 char* new_str; 01348 int str_len = strlen( str ) + 1; 01349 01350 assert( str_len <= MAX_MALLOC_SIZE ); 01351 curr_malloc_size += str_len; 01352 if( curr_malloc_size > largest_malloc_size ) { 01353 largest_malloc_size = curr_malloc_size; 01354 } 01355 new_str = strdup( str ); 01356 #ifdef TESTMODE 01357 if( test_mode ) { 01358 printf( "STRDUP (%p) %d bytes (file: %s, line: %d) - %" FMT64 "d\n", new_str, str_len, file, line, curr_malloc_size ); 01359 } 01360 #endif 01361 assert( new_str != NULL ); 01362 01363 /* Profile the malloc */ 01364 MALLOC_CALL(profile_index); 01365 01366 return( new_str ); 01367 01368 }
char* substitute_env_vars | ( | const char * | value | ) |
Searches the specified string for environment variables and substitutes their value if found.
anonymous | Throw |
value | Input string that will be searched for environment variables |
References Catch_anonymous, FALSE, FATAL, free_safe, malloc_safe, print_output(), PROFILE, PROFILE_END, realloc_safe, Throw, TRUE, Try, user_msg, and USER_MSG_LENGTH.
Referenced by read_command_file().
00854 { PROFILE(SUBSTITUTE_ENV_VARS); 00855 00856 char* newvalue = NULL; /* New value */ 00857 int newvalue_index; /* Current index into newvalue */ 00858 const char* ptr; /* Pointer to current character in value */ 00859 char env_var[4096]; /* Name of found environment variable */ 00860 int env_var_index = 0; /* Current index to write into env_var string */ 00861 bool parsing_var = FALSE; /* Set to TRUE when we are parsing an environment variable */ 00862 char* env_value; /* Environment variable value */ 00863 00864 newvalue = (char*)malloc_safe( 1 ); 00865 newvalue[0] = '\0'; 00866 ptr = value; 00867 newvalue_index = 0; 00868 00869 Try { 00870 00871 while( *ptr != '\0' || parsing_var ) { 00872 if( parsing_var ) { 00873 if( isalnum( *ptr ) || (*ptr == '_') ) { 00874 env_var[env_var_index] = *ptr; 00875 env_var_index++; 00876 } else { 00877 env_var[env_var_index] = '\0'; 00878 if( (env_value = getenv( env_var )) != NULL ) { 00879 newvalue = (char*)realloc_safe( newvalue, (strlen( newvalue ) + 1), (newvalue_index + strlen( env_value ) + 1) ); 00880 strcat( newvalue, env_value ); 00881 newvalue_index += strlen( env_value ); 00882 parsing_var = FALSE; 00883 ptr--; 00884 } else { 00885 unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Unknown environment variable $%s in string \"%s\"", env_var, value ); 00886 assert( rv < USER_MSG_LENGTH ); 00887 print_output( user_msg, FATAL, __FILE__, __LINE__ ); 00888 Throw 0; 00889 } 00890 } 00891 } else if( *ptr == '$' ) { 00892 parsing_var = TRUE; 00893 env_var_index = 0; 00894 } else { 00895 newvalue = (char*)realloc_safe( newvalue, (strlen( newvalue ) + 1), (newvalue_index + 2) ); 00896 newvalue[newvalue_index] = *ptr; 00897 newvalue[newvalue_index+1] = '\0'; 00898 newvalue_index++; 00899 } 00900 ptr++; 00901 } 00902 00903 } Catch_anonymous { 00904 free_safe( newvalue, (strlen( newvalue ) + 1) ); 00905 Throw 0; 00906 } 00907 00908 PROFILE_END; 00909 00910 return( newvalue ); 00911 00912 }
bool util_readline | ( | FILE * | file, | |
char ** | line, | |||
unsigned int * | line_size | |||
) |
Reads line from file and returns it in string form.
Reads in a single line of information from the specified file and returns a string containing the read line to the calling function.
file | File to read next line from | |
line | Pointer to string which will contain read line minus newline character | |
line_size | Pointer to number of characters allocated for line |
References free_safe, malloc_safe, PROFILE, PROFILE_END, and realloc_safe.
Referenced by db_read(), funit_db_inst_merge(), and funit_db_mod_merge().
00773 { PROFILE(UTIL_READLINE); 00774 00775 char c; /* Character recently read from file */ 00776 unsigned int i = 0; /* Current index of line */ 00777 00778 *line_size = 128; 00779 *line = (char*)malloc_safe( *line_size ); 00780 00781 while( !feof( file ) && ((c = (char)fgetc( file )) != '\n') ) { 00782 00783 if( i == (*line_size - 1) ) { 00784 *line_size *= 2; 00785 *line = (char*)realloc_safe( *line, (*line_size / 2), *line_size ); 00786 } 00787 00788 (*line)[i] = c; 00789 i++; 00790 00791 } 00792 00793 if( !feof( file ) ) { 00794 (*line)[i] = '\0'; 00795 } else { 00796 free_safe( *line, *line_size ); 00797 *line = NULL; 00798 } 00799 00800 PROFILE_END; 00801 00802 return( !feof( file ) ); 00803 00804 }