PIPS
file.c File Reference
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include <ctype.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <dirent.h>
#include <regex.h>
#include "genC.h"
#include "misc.h"
+ Include dependency graph for file.c:

Go to the source code of this file.

Macros

#define to_escape(c)    !isalnum(c) && c != '_' && c != '/' && c != '.'
 
#define COLON   ':'
 
#define PATH_MAX   255
 
#define MAX_INPUT_LINE_SIZE   (200)
 
#define MAX_INPUT_LINE_SIZE   (200)
 
#define SLASH_SUBSTITUTION_CHARACTER   '_'
 
#define DEFAULT_CONFIG_DIR   "etc"
 utility to open configuration file, (read only!) its name can be found using various ways property and env can be NULL (and ignored) if the file if not found a pips_error is generated canonical_name should be a file name, not a path More...
 
#define CONFIG_DEFAULT_RIGHT   "r"
 

Functions

bool get_bool_property (const string)
 FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties.h". More...
 
char * get_string_property (const char *)
 
FILE * check_fopen (const char *file, const char *mode)
 file.c More...
 
FILE * safe_fopen (const char *filename, const char *what)
 
int safe_fclose (FILE *stream, const char *filename)
 
int safe_fflush (FILE *stream, char *filename)
 
FILE * safe_freopen (char *filename, char *what, FILE *stream)
 
int safe_fseek (FILE *stream, long int offset, int wherefrom, char *filename)
 
long int safe_ftell (FILE *stream, char *filename)
 
void safe_rewind (FILE *stream, char *filename)
 
int safe_fgetc (FILE *stream, char *filename)
 
int safe_getc (FILE *stream, char *filename)
 
char * safe_fgets (char *s, int n, FILE *stream, char *filename)
 
int safe_fputc (char c, FILE *stream, char *filename)
 
int safe_putc (char c, FILE *stream, char *filename)
 
int safe_fputs (char *s, FILE *stream, char *filename)
 
int safe_fread (char *ptr, int element_size, int count, FILE *stream, char *filename)
 
int safe_fwrite (char *ptr, int element_size, int count, FILE *stream, char *filename)
 
int safe_list_files_in_directory (gen_array_t files, string dir, string re, bool(*file_name_predicate)(const char *))
 returns a sorted arg list of files matching regular expression re in directory 'dir' and with file_name_predicate() returning true on the file name (for example use directory_exists_p to select directories, of file_exists_p to select regular files). More...
 
void list_files_in_directory (gen_array_t files, string dir, string re, bool(*file_name_predicate)(const char *))
 The same as the previous safe_list_files_in_directory() but with no return code and a call to user error if it cannot open the directory. More...
 
bool directory_exists_p (const char *name)
 
bool file_exists_p (const char *name)
 
char * strescape (const char *source)
 protect a string, for example for use in a system call list of non escaped characters in the macro above. More...
 
string nth_path (const char *path_list, int n)
 Returns the allocated nth path from colon-separated path string. More...
 
static char * relative_name_if_necessary (const char *name)
 
char * find_file_in_directories (const char *file_name, const char *dir_path)
 returns an allocated string pointing to the file, possibly with an additional path taken from colon-separated dir_path. More...
 
bool file_readable_p (char *name)
 
bool create_directory (char *name)
 
bool purge_directory (char *name)
 
char * get_cwd (void)
 returns the current working directory name. More...
 
char * safe_readline (FILE *file)
 returns the allocated line read, whatever its length. More...
 
string safe_read_nth_line (string fn, int n)
 Assumes "fn" is the name of a text file, opens it, and returns its nth line (starting with 1) in a newly allocated buffer, whatever the line length. More...
 
string safe_get_line_interval (const string fn, int f, int l)
 return lines f-l from file fn as a string More...
 
void safe_copy_line_interval (string fn, int f, int l, FILE *out)
 Assumes "fn" is the name of a text file, opens it, and copies the lines whose number belongs to [f..l] into file descriptor "out", except if they have been generated by a C preprocessor. More...
 
char * safe_readfile (FILE *file)
 returns the file as an allocated string. More...
 
void safe_cat (FILE *out, FILE *in)
 
void safe_append (FILE *out, char *file, int margin, bool but_comments)
 
void safe_copy (char *source, char *target)
 
int safe_display (char *fname)
 Display a file through $PIPS_MORE (or $PAGER) if stdout is a TTY, on stdout otherwise. More...
 
char * pips_filename (char *fullpath, char *suffix, bool short_p)
 Some OS do not define basename and dirname. More...
 
char * pips_basename (char *fullpath, char *suffix)
 
char * pips_initial_filename (char *fullpath, char *suffix)
 The source file name access path is shortened or not depending on the property. More...
 
some path to file suffix some path to *char * pips_dirname (char *fullpath)
 
void safe_unlink (const char *file_name)
 Delete the given file. More...
 
void safe_symlink (const char *topath, const char *frompath)
 
void safe_link (const char *topath, const char *frompath)
 Create a hard link to topath. More...
 
char * safe_system_output (char *what)
 attempt shell substitutions to what. More...
 
char * safe_system_substitute (char *what)
 returns what after variable, command and file substitutions. More...
 
char * safe_new_tmp_file (char *prefix)
 SunOS forgets to declare this one. More...
 
FILE * fopen_config (const char *canonical_name, const char *cproperty, const char *cenv)
 

Macro Definition Documentation

◆ COLON

#define COLON   ':'

Definition at line 349 of file file.c.

◆ CONFIG_DEFAULT_RIGHT

#define CONFIG_DEFAULT_RIGHT   "r"

Definition at line 950 of file file.c.

◆ DEFAULT_CONFIG_DIR

#define DEFAULT_CONFIG_DIR   "etc"

utility to open configuration file, (read only!) its name can be found using various ways property and env can be NULL (and ignored) if the file if not found a pips_error is generated canonical_name should be a file name, not a path

Definition at line 949 of file file.c.

◆ MAX_INPUT_LINE_SIZE [1/2]

#define MAX_INPUT_LINE_SIZE   (200)

◆ MAX_INPUT_LINE_SIZE [2/2]

#define MAX_INPUT_LINE_SIZE   (200)

◆ PATH_MAX

#define PATH_MAX   255

Definition at line 479 of file file.c.

◆ SLASH_SUBSTITUTION_CHARACTER

#define SLASH_SUBSTITUTION_CHARACTER   '_'

◆ to_escape

#define to_escape (   c)     !isalnum(c) && c != '_' && c != '/' && c != '.'

Definition at line 327 of file file.c.

Function Documentation

◆ check_fopen()

FILE* check_fopen ( const char *  file,
const char *  mode 
)

file.c

Returns
a file descriptor.
Parameters
fileile
modeode

Definition at line 56 of file file.c.

57 {
58  FILE * fd = fopen(file, mode);
59  if (fd==(FILE*)NULL)
60  {
61  pips_user_warning("fopen failed on file \"%s\" (mode \"%s\")\n%s\n",
62  file, mode, strerror(errno));
63  }
64  return fd;
65 }
#define pips_user_warning
Definition: misc-local.h:146

References pips_user_warning.

Referenced by load_meta_data().

+ Here is the caller graph for this function:

◆ create_directory()

bool create_directory ( char *  name)
Parameters
nameame

Definition at line 435 of file file.c.

436 {
437  bool success = true;
438 
439  if (directory_exists_p(name)) {
440  pips_internal_error("existing directory: %s", name);
441  }
442 
443  if (mkdir(name, 0777) == -1) {
444  pips_user_warning("cannot create directory: %s (%s)\n",
445  name, strerror(errno));
446  success = false;
447  }
448 
449  return success;
450 }
bool directory_exists_p(const char *name)
Definition: file.c:314
bool success
Definition: gpips-local.h:59
#define pips_internal_error
Definition: misc-local.h:149

References directory_exists_p(), pips_internal_error, and pips_user_warning.

Referenced by db_create_workspace(), and db_get_directory_name_for_module().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ directory_exists_p()

bool directory_exists_p ( const char *  name)
Parameters
nameame

Definition at line 314 of file file.c.

315 {
316  struct stat buf;
317  return (stat(name, &buf) == 0) && S_ISDIR(buf.st_mode);
318 }
static char buf[BSZ]
Definition: split_file.c:157

References buf.

Referenced by create_directory(), db_get_directory_name_for_module(), db_open_workspace(), generate_a_directory_menu(), pips_change_directory(), pips_get_workspace_list(), purge_directory(), and workspace_exists_p().

+ Here is the caller graph for this function:

◆ file_exists_p()

bool file_exists_p ( const char *  name)
Parameters
nameame

Definition at line 321 of file file.c.

322 {
323  struct stat buf;
324  return (stat(name, &buf) == 0) && S_ISREG(buf.st_mode);
325 }

References buf.

Referenced by add_new_compilation_unit(), add_new_module_from_text(), find_file_in_directories(), get_first_main_module(), hpfc_get_file_list(), load_meta_data(), parse_arguments(), pips_get_fortran_list(), safe_display(), and text_area_included().

+ Here is the caller graph for this function:

◆ file_readable_p()

bool file_readable_p ( char *  name)
Parameters
nameame

Definition at line 428 of file file.c.

429 {
430  struct stat buf;
431  return !stat(name, &buf) && (S_IRUSR & buf.st_mode);
432 }

References buf.

Referenced by freia_compile(), freia_opencl_compile_calls(), and workspace_ok_p().

+ Here is the caller graph for this function:

◆ find_file_in_directories()

char* find_file_in_directories ( const char *  file_name,
const char *  dir_path 
)

returns an allocated string pointing to the file, possibly with an additional path taken from colon-separated dir_path.

returns NULL if no file was found.

looks for the file with an additional path ahead.

Parameters
file_nameile_name
dir_pathir_path

Definition at line 399 of file file.c.

400 {
401  char *path;
402  int n=0;
403  pips_assert("some file name", file_name);
404 
407 
408  if (!dir_path || file_name[0]=='/')
409  return (string) NULL;
410 
411  /* looks for the file with an additional path ahead.
412  */
413  while ((path=nth_path(dir_path, n++)))
414  {
415  char *name = strdup(concatenate(path, "/", file_name, NULL)),
416  *res=NULL;
417  free(path);
418  if (file_exists_p(name))
419  res = relative_name_if_necessary(name);
420  free(name);
421  if (res) return res;
422  }
423 
424  return (string) NULL;
425 }
bool file_exists_p(const char *name)
Definition: file.c:321
string nth_path(const char *path_list, int n)
Returns the allocated nth path from colon-separated path string.
Definition: file.c:362
static char * relative_name_if_necessary(const char *name)
Definition: file.c:388
void free(void *)
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
char * strdup()
static string file_name

References concatenate(), file_exists_p(), file_name, free(), nth_path(), pips_assert, relative_name_if_necessary(), and strdup().

Referenced by find_file(), parse_arguments(), and process_user_file().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fopen_config()

FILE* fopen_config ( const char *  canonical_name,
const char *  cproperty,
const char *  cenv 
)
Parameters
canonical_nameanonical_name
cpropertyproperty
cenvenv

Definition at line 952 of file file.c.

955 {
956  FILE * fconf;
957 
958  // try various combinaison :
959  // pips property
960  if (cproperty) {
961  const string sproperty = get_string_property(cproperty);
962  if (sproperty && (fconf = fopen(sproperty, CONFIG_DEFAULT_RIGHT)))
963  return fconf;
964  }
965 
966  // then pips env var
967  if (cenv) {
968  string senv = getenv(cenv);
969  if (senv && (fconf = fopen(senv, CONFIG_DEFAULT_RIGHT)))
970  return fconf;
971  }
972 
973  // then default, with PIPS_ROOT if set
974  string pipsenv = getenv("PIPS_ROOT");
975  string sdefault;
976  if(pipsenv)
977  sdefault =
978  concatenate(pipsenv,"/" DEFAULT_CONFIG_DIR "/" , canonical_name, NULL);
979  else
980  sdefault = concatenate(CONFIG_DIR "/", canonical_name, NULL);
981 
982  return safe_fopen(sdefault, CONFIG_DEFAULT_RIGHT);
983 }
FILE * safe_fopen(const char *filename, const char *what)
Definition: file.c:67
#define CONFIG_DEFAULT_RIGHT
Definition: file.c:950
char * get_string_property(const char *)
#define DEFAULT_CONFIG_DIR
utility to open configuration file, (read only!) its name can be found using various ways property an...
Definition: file.c:949

References concatenate(), CONFIG_DEFAULT_RIGHT, DEFAULT_CONFIG_DIR, get_string_property(), and safe_fopen().

Referenced by build_aliases(), get_help_topic(), get_help_topics(), get_model(), init_cost_table(), parse_makefile(), and simd_treematcher().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_bool_property()

bool get_bool_property ( const  string)

FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties.h".

Definition at line 173 of file gfc2pips-stubs.c.

173  {
174  if ( strcmp( "PRETTYPRINT_LISTS_WITH_SPACES", name ) == 0
175  || strcmp( "PRETTYPRINT_REGENERATE_ALTERNATE_RETURNS", name ) == 0
176  || strcmp( "PRETTYPRINT_C_CODE", name ) == 0
177  || strcmp( "ABORT_ON_USER_ERROR", name ) == 0 ) {
178  return true;
179  }
180  if ( strcmp( "NO_USER_WARNING", name ) == 0 ) {
181  return false;
182  }
183  fprintf( stderr, "***** Property requested : %s ***** ", name );
184  STUB_WARNING();
185  return 0;
186 }
#define STUB_WARNING()
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...

References fprintf(), and STUB_WARNING.

Referenced by abstract_locations_max(), activate_phase(), add_formal_parameters_to_hash_table(), add_implicit_interprocedural_write_effects(), add_loop_parallel_threshold(), add_pragma(), add_rule(), add_values_for_simple_effects_of_statement(), AK_ignore_this_level(), AK_ignore_this_successor(), alias_propagation(), alias_propagation_callers(), AnalyzeData(), any_complexities(), any_user_call_site_to_transformer(), application_to_points_to_sinks(), apply_a_rule(), arguments_to_complexity(), array_formal_parameter_to_stub_points_to(), atomize_call_statement(), atomize_this_expression(), atomizer(), average_probability_matrix(), begin_attachment_prettyprint(), block_to_complexity(), bottom_up_abc_reference(), bourdoncle_partition(), build_outline_name(), build_trail(), c_basic_string(), c_dim_string(), c_head(), c_include(), c_parser_user_warning_alist(), c_return_to_transformer(), c_text_related_entities(), c_unstructured(), c_user_call_to_transformer(), call_to_complexity(), call_to_polynome(), call_to_postcondition(), call_to_transformer(), cast_constant(), cast_to_polynome(), cell_to_nowhere_sink(), check_in_declarations(), clean_up_points_to_stubs(), cluster_stage_spire(), cluster_stage_spire_generation(), CodeGenerate(), comEngine_generate_HRECode(), commutative_call_p(), complexity_check_and_warn(), complexity_var_subst(), ComputeAddresses(), ConnectedStatements(), constraints_to_loop_bound(), controlize_forloop(), controlize_sequence(), controlizer(), convert_constant_from_double_to_dcomplex(), convert_constant_from_real_to_complex(), create_advanced_stub_points_to(), create_HRE_module(), create_k_limited_stub_points_to(), create_pointer_to_array_stub_points_to(), create_stub_points_to(), create_workspace(), cse_atom_call_flt(), cse_call_flt(), csplit_copy(), csplit_parser_warning_alist(), current_entity_is_updated_before_p(), current_entity_is_used_later_p(), cusq_ctxt_init(), cycle_to_flow_sensitive_preconditions(), dag_or_cycle_to_flow_sensitive_postconditions_or_transformers(), dag_to_flow_sensitive_preconditions(), dagvtx_dot(), dbll_stat_file(), debug_print_effects_list(), declaration_to_transformer(), declaration_to_transformer_list(), DeclarePointer(), decorate_trail(), dereferencing_to_points_to(), dereferencing_to_sinks(), derived_formal_parameter_to_stub_points_to(), display_clean_up_sequences_statistics(), display_unspaghettify_statistics(), distance_between_expression(), distributer(), do_check_isolate_statement_preconditions_on_call(), do_convert_this_array_to_pointer_p(), do_group_constant_entity(), do_group_statement_constant(), do_grouping_filter_out_self(), do_inlining(), do_loop_unroll(), do_loop_unroll_with_epilogue(), do_loop_unroll_with_prologue(), do_unfolding(), DSC(), dsc_code_parallelization(), dump_common_layout(), effect_words_reference(), effects_to_dma(), EndOfProcedure(), ensure_comment_consistency(), EvalCall(), EvalSyntax(), evaluate_var_to_complexity(), expr_compute_local_index(), expression_to_complexity_polynome(), expression_to_postcondition(), extended_source_to_sinks(), extract_lattice(), fetch_callees_complexities(), fetch_complexity_parameters(), filter_formal_context_according_to_actual_context(), fix_storage(), FixCReturnStatements(), flag_loop(), flatten_code(), float_call_expression_to_transformer(), flow_sensitive_malloc_to_points_to_sinks(), formal_source_to_sinks(), freia_allocate_new_images_if_needed(), freia_compile(), freia_dag_optimize(), freia_extract_params(), freia_opencl_compile_calls(), fs_filter(), fsm_generation(), full_loop_unroll(), full_simd_unroll_loop_filter(), fuse_sequences_in_unstructured(), gen_may_set(), generate_code_call(), generate_remapping_code(), generate_remapping_guard(), generic_apply_effects_to_transformer(), generic_c_words_simplified_entity(), generic_entity_typed_anywhere_locations(), generic_initializer(), generic_module_name_to_transformers(), generic_reference_to_points_to_matching_list(), generic_reference_to_transformer(), generic_stub_source_to_sinks(), generic_substitute_formal_array_elements_in_transformer(), get_final_offset(), get_text_preconditions(), get_text_total_preconditions(), get_variables_to_remove(), global_source_to_sinks(), gpips_user_error_message(), gpips_user_log(), gpu_ify_statement(), gpu_loop_nest_annotate_on_statement(), gpu_qualify_pointers(), group_constant_range_filter(), handle_hpf_directives(), handle_set_directive(), handle_synchro_directive(), handle_time_directive(), hbdsc_parallelization(), hierarchical_schedule(), hierarchical_schedule_step(), hpf_remapping(), hpfc_algorithm_row_echelon(), hpfc_broadcast_buffers(), hpfc_compute_lid(), html_prettyprint(), if_different_pe_and_not_twin(), init_convex_rw_regions(), init_live_paths_context(), init_parser_reader_properties(), init_points_to_analysis(), init_text_statement(), inline_expression_call(), inline_statement_crawler(), insert_test_before_statement(), integer_binary_operation_to_transformer(), integer_call_expression_to_transformer(), integer_expression_to_transformer(), interface_basic_string(), io_comp_regions(), io_efficient_compile(), keep_directive_in_code_p(), linearize_array_generic(), list_assignment_to_points_to(), live_paths_from_block_to_statements(), load_control_fix_point(), load_cost_file(), load_cycle_temporary_precondition(), logs_off(), logs_on(), loop_expansion(), loop_private_variables(), loop_to_complexity(), loop_to_postcondition(), loop_to_total_precondition(), loop_to_transformer(), main_summary_precondition(), make_anywhere_points_to_cell(), make_anywhere_reference(), make_bottom_up_abc_tests(), make_constraint_expression(), make_filtered_dg_or_dvdg(), make_interprocedural_abc_tests(), make_loadsave_statement(), MakeAssignInst(), MakeAtom(), MakeDoInst(), MakeForloopWithIndexDeclaration(), MakeFortranType(), MakeNestOfParallelLoops(), MakeNewLabelledStatement(), MakeStatement(), malloc_type_to_abstract_location(), mark_block(), module_name_to_preconditions(), module_name_to_total_preconditions(), module_name_to_transformers_in_context(), move_declaration_control_node_declarations_to_statement(), new_controlizer(), new_filter_formal_context_according_to_actual_context(), node_successors_to_matrix(), NormalizeCall(), nowhere_source_to_sinks(), null_equal_condition_to_points_to(), null_source_to_sinks(), offset_cell(), offset_points_to_cell(), old_array_bound_check_instrumentation(), opencl_compile_mergeable_dag(), opencl_merge_and_compile(), ordinary_summary_precondition(), outline(), outliner(), outliner_compilation_unit(), outliner_file(), outliner_independent(), outliner_independent_recursively(), outliner_init(), outliner_parameters(), outliner_scan(), parallel_tiling(), parser_substitute_all_macros(), partial_eval_syntax(), pips_check_syntax(), pips_initial_filename(), pixel_name(), pointer_call_expression_to_transformer(), pointer_formal_parameter_to_stub_points_to(), points_to_cell_null_initialization(), points_to_cell_types_compatibility(), points_to_unary_operation_to_transformer(), points_to_with_stripped_sink(), potential_out_effects_p(), ppt_call(), ppt_min_max(), ppt_unknown(), pragma_scop(), prettyprint_dependence_graph(), prettyprint_dependence_graph_view(), prettyprint_dot_dependence_graph(), print_code_or_source(), print_code_or_source_comp(), print_code_preconditions(), print_code_semantics(), print_code_total_preconditions(), print_code_with_comp_regions(), print_continuation_conditions(), print_dependence_or_chains_graph(), print_module_icfg(), print_parallelization_statistics(), print_parallelizedOMP_code(), print_sentence(), print_source_preconditions(), print_source_total_preconditions(), process_ready_node(), process_user_file(), ProcessEntries(), ProcessEntry(), put_summary(), pvecteur_to_polynome(), range_to_complexity(), rdg_loop(), reference_add_field_dimension(), reference_filter(), reference_to_complexity(), reference_to_polynome(), references_may_conflict_p(), regenerate_expression(), region_translation(), remapping_compile(), remapping_stats(), remove_common_variables_from_hash_table(), remove_formal_parameters_from_hash_table(), remove_impossible_arcs_to_null(), remove_points_to_cell(), rename_operator(), rename_statement_declarations(), replace_formal_parameters_by_real_ones(), reset_resources_for_module(), ResetCurrentCompilationUnitEntity(), ResetCurrentModule(), ReuseLabelledStatement(), rice(), rice_dependence_graph(), rice_loop(), safe_assigned_expression_to_transformer(), safe_assigned_expression_to_transformer_list(), sc_delimiter(), sc_inst(), scalar_by_pointer(), select_fix_point_operator(), semantics_user_warning_alist(), sentence_area(), sentence_data_statement(), set_analyzed_types(), set_conflict_testing_properties(), set_resources_for_module(), set_translation_mode(), simd_atomize_this_expression(), simd_loop_unroll(), simd_unroll_as_needed(), simple_simd_unroll_rate(), simplify_sc_to_complexity(), source_to_sinks(), spaghettify_statement(), split_initializations_in_statement(), sreference_offset(), st_compute_current_computer(), st_compute_current_owners(), statement_dependence_graph(), statement_remove_useless_label(), statement_to_complexity(), statement_to_postcondition(), statement_to_transformer(), statement_to_transformer_list(), statements_localize_declarations(), static_controlize_statement(), step_compile_analysed_module(), step_print_directives_regions(), string_predicate_to_commentary(), stub_text(), subscript_to_points_to_sinks(), SubstituteAlternateReturns(), summary_complexity(), summary_precondition(), summary_total_postcondition(), switch_specific_cmplx(), switch_specific_dcmplx(), symbolic_tiling_valid_p(), taskify(), test_to_complexity(), TestCoupleOfReferences(), text_array_comp_regions(), text_block(), text_block_else(), text_block_if(), text_comp_region(), text_complexity(), text_continuation_conditions(), text_directive(), text_entity_declaration(), text_equivalence_class(), text_instruction(), text_loop(), text_loop_default(), text_pointer_values(), text_points_to_relations(), text_region_no_action(), text_test(), text_trail(), text_transformer(), text_unstructured(), text_whileloop(), this_entity_cdeclaration(), tiling_transformation(), top_down_abc_array(), tp_substitutions(), tpips_behaves_like_a_shell(), tpips_init(), tpips_internal_error(), tpips_user_error(), trace_off(), trace_on(), transfer_cost(), transformer_list_closure_to_precondition_depth_two(), transformer_list_closure_to_precondition_max_depth(), transformer_list_multiple_closure_to_precondition(), transformers_intra_fast(), two_addresses_code_generator_split_p(), typedef_formal_parameter_to_stub_points_to(), unique_malloc_to_points_to_sinks(), unspaghettify_or_restructure_statement(), unspaghettify_statement(), unstructured_to_flow_insensitive_transformer(), unstructured_to_flow_sensitive_postconditions(), unstructured_to_transformer(), update_functional_type_with_actual_arguments(), user_call_to_points_to_sinks(), user_call_to_transformer(), values_for_current_module_intraprocedural_simple_effects(), variable_to_abstract_location(), verify_array_element(), verify_array_variable(), verify_scalar_variable(), whileloop_to_complexity(), whileloop_to_postcondition(), words_brace_expression(), words_comma_op(), words_declaration(), words_dimensions(), words_implied_do(), words_io_inst(), words_parameters(), words_regular_call(), words_stat_io_inst(), words_va_arg(), wpips_user_error_message(), wpips_user_log(), and xml_Chain_Graph().

+ Here is the call graph for this function:

◆ get_cwd()

char* get_cwd ( void  )

returns the current working directory name.

argh

Definition at line 486 of file file.c.

487 {
488  static char cwd[PATH_MAX]; /* argh */
489  cwd[PATH_MAX-1] = '\0';
490  return getcwd(cwd, PATH_MAX);
491 }
#define PATH_MAX
Definition: file.c:479

References PATH_MAX.

Referenced by direct_change_directory(), generate_directory_menu(), make_open_workspace(), pips_change_directory(), send_view_to_emacs(), show_directory(), and wpips_display_graph_file_display().

+ Here is the caller graph for this function:

◆ get_string_property()

const char * get_string_property ( const char *  )

Referenced by activate_phases(), add_pragma(), c_basic_string(), c_head(), c_include(), call_load_store_p(), clean_statement_label(), common_subexpression_elimination(), delete_some_resources(), do_group_constants_terapix(), do_inlining(), do_loop_expansion_init(), do_solve_hardware_constraints(), do_statement_insertion(), do_unfolding(), dsc_code_parallelization(), entity_sesam_buffer_p(), fetch_complexity_parameters(), find_code_status(), fopen_config(), formal_label_replacement_p(), freia_is_transpose_call(), freia_terapix_call(), generate_compact(), generate_pseudo_formal_variable_for_formal_label(), generic_initializer(), generic_words_qualifiers(), get_clean_mod_name(), get_dma_name(), get_eole_command(), get_grouping_layout(), get_if_clause_policy(), get_model(), get_next_task_name(), get_variables_to_filter(), GetReturnCodeVariable(), gpu_ify_statement(), group_constants(), hbdsc_parallelization(), icm(), init_computation_intensity_param(), init_cost_table(), interface_basic_string(), isolate_statement(), kernel_load_store_generator(), load_atomic_profile(), local_tile_constraints(), loop_expansion(), loop_expansion_init(), loop_fully_unrollable_p(), make_eliminate_original_variables(), make_exec_statement_from_name(), make_get_rc_statement(), make_loadsave_statement(), make_phi_assign_instruction(), make_reduction_vector_entity(), make_required(), make_statement_copy_i(), MakeCurrentFunction(), malloc_to_points_to_sinks(), malloc_type_to_abstract_location(), normalize_microcode(), omp_merge_pragma(), opencl_compile_mergeable_dag(), optimize_expressions(), outline(), outliner(), outliner_independent_recursively(), parallel_tiling(), pp_style_p(), pragma_outliner(), prepend_call(), prepend_comment(), prettyprint_dot_dependence_graph(), print_code_or_source(), print_loopnest_dependence_cone(), print_parallel_statement(), print_parallelized_code_common(), print_parallelizedCMF_code(), print_parallelizedCRAFT_code(), print_sesam_tasks_buffers_header(), region_entity_variable_to_new_declare_entity(), rename_operator(), replace_sender_entity_by_receiver_entity_in_reference(), replicate_declaration(), reset_step_transform(), retrieve_a_missing_file_using_external_resolver(), sac_expression_reduction_p(), scalopragma(), select_fix_point_operator(), sesam_buffer_to_server_entity(), sesam_task_label_p(), set_current_optimization_strategy(), set_pattern(), set_prettyprint_language_from_property(), set_rc_function(), simd_load_call_p(), simd_store_call_p(), simd_work_call_p(), solve_hardware_constraints(), statement_phi_function_p(), step_install(), symbolic_tiling(), system_sorted_text_format(), text_entity_declaration(), tile_hyperplane_constraints(), tiling_transformation(), transformer_list_closure_to_precondition(), uses_alternate_return(), words_basic(), words_regular_call(), wp65(), and wrap_kernel_argument().

◆ list_files_in_directory()

void list_files_in_directory ( gen_array_t  files,
string  dir,
string  re,
bool(*)(const char *)  file_name_predicate 
)

The same as the previous safe_list_files_in_directory() but with no return code and a call to user error if it cannot open the directory.

Parameters
filesiles
dirir
ree

Definition at line 299 of file file.c.

304 {
305  int return_code =
306  safe_list_files_in_directory(files, dir, re, file_name_predicate);
307 
308  if (return_code == -1)
309  pips_user_error("opendir() failed on directory \"%s\", %s.\n",
310  dir, strerror(errno));
311 }
int safe_list_files_in_directory(gen_array_t files, string dir, string re, bool(*file_name_predicate)(const char *))
returns a sorted arg list of files matching regular expression re in directory 'dir' and with file_na...
Definition: file.c:250
#define pips_user_error
Definition: misc-local.h:147

References pips_user_error, and safe_list_files_in_directory().

Referenced by pips_get_fortran_list(), and pips_get_workspace_list().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nth_path()

string nth_path ( const char *  path_list,
int  n 
)

Returns the allocated nth path from colon-separated path string.

Parameters
path_listthe string that contains a colon-separated path
nthe n-th instance to extract
Returns
an allocated string with the n-th part name

If the path is empty or if n is out-of-bound, NULL is returned. The resulting string is *not*escaped, and can contain spaces

Find the n-th part:

Out-of-bound...

Compute the length up to the COLON or the end of string:

Parameters
path_listath_list

Definition at line 362 of file file.c.

363 {
364  int len;
365 
366  if (path_list == NULL)
367  return NULL;
368 
369  /* Find the n-th part: */
370  while (*path_list && n > 0)
371  if (*path_list++ == COLON)
372  n--;
373 
374  if (!*path_list)
375  /* Out-of-bound... */
376  return NULL;
377 
378  /* Compute the length up to the COLON or the end of string: */
379  for(len = 0; path_list[len] && path_list[len] != COLON; len++)
380  ;
381 
382  char *unescaped = strndup(path_list, len);
383  return unescaped;
384 }
#define COLON
Definition: file.c:349
char * strndup(char const *s, size_t n)
A replacement function, for systems that lack strndup.
Definition: strndup.c:26

References COLON, and strndup().

Referenced by find_file_in_directories(), and include_path_to_include_flags().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pips_basename()

char* pips_basename ( char *  fullpath,
char *  suffix 
)
Parameters
fullpathullpath
suffixuffix

Definition at line 822 of file file.c.

823 {
824  return pips_filename(fullpath, suffix, true);
825 }
char * pips_filename(char *fullpath, char *suffix, bool short_p)
Some OS do not define basename and dirname.
Definition: file.c:775

References pips_filename().

Referenced by compilation_unit_of_module(), csplit_open_compilation_unit(), get_new_user_file(), hpfc_fclose(), hpfc_fopen(), insert_check_alias_before_statement(), insert_flag_before_call_site(), insert_test_before_caller(), insert_test_before_statement(), module_name_to_input_file_name(), process_thru_fortran_pp(), step_install(), and used_before_set().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pips_dirname()

some path to file suffix some path to* char* pips_dirname ( char *  fullpath)
Parameters
fullpathullpath

Definition at line 837 of file file.c.

838 {
839  char *result = strdup(fullpath);
840  int len = strlen(result);
841  while (result[--len]!='/' && len>=0);
842  result[len] = '\0';
843  return result;
844 }

References strdup().

Referenced by filter_file(), and parse_arguments().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pips_filename()

char* pips_filename ( char *  fullpath,
char *  suffix,
bool  short_p 
)

Some OS do not define basename and dirname.

Others like DEC OSF1 do. So define them and use another name for them:

/some/path/to/file.suffix -> file

This may create conflicting file names, when the same source filename is used in different subdirectory as in:

create foo mod.c src/mod.c src/init/mod.c src/close/mod.c

To avoid the problem a larger part of the access path should be preserved. This can be done by substituting / by another character.

Drop the suffix

ok

Keep the basename only

fullpath[i+1:len]

Or substitute slashes by a neutral character

Parameters
fullpathullpath
suffixuffix
short_phort_p

Definition at line 775 of file file.c.

776 {
777  int len = strlen(fullpath)-1, i, j;
778  char *result;
779 
780  if (suffix) /* Drop the suffix */
781  {
782  int ls = strlen(suffix) - 1, le = len;
783  while (suffix[ls] == fullpath[le]) {
784  ls--;
785  le--;
786  if (ls < 0 || le < 0)
787  break;
788  }
789  if (ls < 0) /* ok */
790  len = le;
791  }
792 
793  if(short_p) {
794  /* Keep the basename only */
795  for (i=len; i>=0; i--) if (fullpath[i]=='/') break;
796  /* fullpath[i+1:len] */
797  result = (char*) malloc(sizeof(char)*(len-i+1));
798  for (i++, j=0; i<=len; i++, j++)
799  result[j] = fullpath[i];
800  result[j++] = '\0';
801  }
802  else {
803  /* Or substitute slashes by a neutral character */
804  char * cc;
805 
806  if(fullpath[0]=='.' && fullpath[1]=='/')
807  result = strndup(fullpath+2, len-1);
808  else
809  result = strndup(fullpath, len+1);
810 
811 
812 #define SLASH_SUBSTITUTION_CHARACTER '_'
813 
814  for(cc=result; *cc!='\000'; cc++) {
815  if(*cc=='/')
817  }
818  }
819  return result;
820 }
#define SLASH_SUBSTITUTION_CHARACTER
void * malloc(YYSIZE_T)

References malloc(), SLASH_SUBSTITUTION_CHARACTER, and strndup().

Referenced by pips_basename(), and pips_initial_filename().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pips_initial_filename()

char* pips_initial_filename ( char *  fullpath,
char *  suffix 
)

The source file name access path is shortened or not depending on the property.

It is shorten if the name conflicts are not managed.

Parameters
fullpathullpath
suffixuffix

Definition at line 829 of file file.c.

830 {
831  return pips_filename(fullpath, suffix,
832  !get_bool_property("PREPROCESSOR_FILE_NAME_CONFLICT_HANDLING"));
833 }
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....

References get_bool_property(), and pips_filename().

Referenced by process_thru_C_pp().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ purge_directory()

bool purge_directory ( char *  name)
Parameters
nameame

Definition at line 453 of file file.c.

454 {
455  bool success = true;
456 
457  if (directory_exists_p(name)) {
458  if(system(concatenate("/bin/rm -r ", name, (char*) NULL))) {
459  // FI: this warning should be emitted by a higher-level routine!
460  pips_user_warning("cannot purge directory %s. Check owner rights\n", name);
461  success = false;
462  }
463  else {
464  success = true;
465  }
466  }
467  else {
468  // Well, it's purged if it does not exist...
469  success = true;
470  }
471 
472  return success;
473 }

References concatenate(), directory_exists_p(), and pips_user_warning.

Referenced by db_create_workspace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ relative_name_if_necessary()

static char* relative_name_if_necessary ( const char *  name)
static

Definition at line 388 of file file.c.

389 {
390  if (name[0]=='/' || name[0]=='.') return strdup(name);
391  else return strdup(concatenate("./", name, NULL));
392 }

References concatenate(), and strdup().

Referenced by find_file_in_directories().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ safe_append()

void safe_append ( FILE *  out,
char *  file,
int  margin,
bool  but_comments 
)
Parameters
outwhere to output the file content
filethe content of which is appended
marginnumber of spaces for shifting
but_commentsdo not shift F77 comment lines

Definition at line 679 of file file.c.

684 {
685  FILE * in = safe_fopen(file, "r");
686  bool first = true;
687  int c, i;
688  while ((c=getc(in))!=EOF)
689  {
690  if (first && (!but_comments || (c!='C' && c!='c' && c!='*' && c!='!')))
691  {
692  for (i=0; i<margin; i++)
693  if (putc(' ', out)==EOF)
694  pips_internal_error("append failed");
695  first = false;
696  }
697  if (c=='\n')
698  first = true;
699  if (putc(c, out)==EOF)
700  pips_internal_error("append failed");
701  }
702  safe_fclose(in, file);
703 }
static FILE * out
Definition: alias_check.c:128
int safe_fclose(FILE *stream, const char *filename)
Definition: file.c:77

References out, pips_internal_error, safe_fclose(), and safe_fopen().

Referenced by callgraph_module_name().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ safe_cat()

void safe_cat ( FILE *  out,
FILE *  in 
)
Parameters
outut
inn

Definition at line 669 of file file.c.

670 {
671  int c;
672  while ((c=getc(in))!=EOF)
673  if (putc(c, out)==EOF)
674  pips_internal_error("cat failed");
675  safe_fflush(out, "<probably stdout>");
676 }
int safe_fflush(FILE *stream, char *filename)
Definition: file.c:90

References out, pips_internal_error, and safe_fflush().

Referenced by handle_include_file(), safe_copy(), safe_display(), step_install(), and unsplit_internal().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ safe_copy()

void safe_copy ( char *  source,
char *  target 
)
Parameters
sourceource
targetarget

Definition at line 706 of file file.c.

707 {
708  FILE * in, * out;
709  in = safe_fopen(source, "r");
710  out = safe_fopen(target, "w");
711  safe_cat(out, in);
712  safe_fclose(out, target);
713  safe_fclose(in, source);
714 }
void safe_cat(FILE *out, FILE *in)
Definition: file.c:669

References out, safe_cat(), safe_fclose(), and safe_fopen().

Referenced by compile_a_pure_function(), compile_a_special_io_function(), and step_compile_generated_module().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ safe_copy_line_interval()

void safe_copy_line_interval ( string  fn,
int  f,
int  l,
FILE *  out 
)

Assumes "fn" is the name of a text file, opens it, and copies the lines whose number belongs to [f..l] into file descriptor "out", except if they have been generated by a C preprocessor.

Line starting with '#' are counted but not copied.

This function is used by the PIPS preprocessor and its parsers to print out the lines where an error has been detected.

Do not reproduce this line as it was generated by an external preprocessor whose behavior is not controlled

Parameters
fnn
outut

Definition at line 601 of file file.c.

602 {
603  FILE * fd = safe_fopen(fn, "r");
604  int i = 0;
605 #define MAX_INPUT_LINE_SIZE (200)
607 
608  pips_assert("The interval is strictly positive and non empty",
609  f>=1 && l>=f);
610 
611  // Skip f-1 lines
612  for(i=0; i<f-1; i++)
614 
615  // Copy l-f+1 lines
616  int c = l - f + 1;
617  while(c>0) {
618  int n = fgetc(fd);
619  if(n==EOF)
620  break;
621  else {
622  if((char) n == '#') {
623  /* Do not reproduce this line as it was generated by an
624  external preprocessor whose behavior is not controlled */
625  while(c>0) {
626  n = fgetc(fd);
627  if(n==EOF)
628  c = -1; // stop
629  else if((char) n == '\n') {
630  c--; // One useless line has been read
631  break;
632  }
633  }
634  }
635  else {
636  fputc(n, out);
637  if((char) n == '\n')
638  c--;
639  }
640  }
641  }
642 
643  safe_fclose(fd, fn);
644 }
char * safe_fgets(char *s, int n, FILE *stream, char *filename)
Definition: file.c:170
#define MAX_INPUT_LINE_SIZE
static int current_line
Poor attempt at associating physical line numbers to statement.
Definition: statement.c:2405
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15

References current_line, f(), MAX_INPUT_LINE_SIZE, out, pips_assert, safe_fclose(), safe_fgets(), and safe_fopen().

+ Here is the call graph for this function:

◆ safe_display()

int safe_display ( char *  fname)

Display a file through $PIPS_MORE (or $PAGER) if stdout is a TTY, on stdout otherwise.

Return false if the file couldn't be displayed.

Parameters
fnamename

Definition at line 722 of file file.c.

723 {
724  if (!file_exists_p(fname))
725  {
726  pips_user_error("View file \"%s\" not found\n", fname);
727  return 0;
728  }
729 
730  if (isatty(fileno(stdout)))
731  {
732  int pgpid = fork();
733  if (pgpid)
734  {
735  int status;
736  waitpid(pgpid, &status, 0);
737  return WIFEXITED(status) && WEXITSTATUS(status) == 0;
738  }
739  else
740  {
741  char *pager = getenv("PIPS_MORE");
742  if (!pager)
743  pager = getenv("PAGER");
744  if (!pager)
745  pager = "more";
746  execlp(pager, pager, fname, NULL);
747  pips_internal_error("running %s %s: %s",
748  pager, fname, strerror(errno));
749  exit(127);
750  }
751  }
752  else
753  {
754  FILE * in = safe_fopen(fname, "r");
755  safe_cat(stdout, in);
756  safe_fclose(in, fname);
757  return 1;
758  }
759 }
struct _newgen_struct_status_ * status
Definition: database.h:31
#define exit(code)
Definition: misc-local.h:54

References exit, file_exists_p(), pips_internal_error, pips_user_error, safe_cat(), safe_fclose(), and safe_fopen().

Referenced by display(), and display_a_resource().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ safe_fclose()

int safe_fclose ( FILE *  stream,
const char *  filename 
)
Parameters
streamtream
filenameilename

Definition at line 77 of file file.c.

78 {
79  if(fclose(stream) == EOF) {
80  if(errno==ENOSPC)
81  pips_user_irrecoverable_error("fclose failed on file %s (%s)\n",
82  filename, strerror(errno));
83  else
84  pips_internal_error("fclose failed on file %s (%s)",
85  filename, strerror(errno));
86  }
87  return 0;
88 }
#define pips_user_irrecoverable_error
Definition: misc-local.h:148

References pips_internal_error, and pips_user_irrecoverable_error.

Referenced by actual_c_parser(), actual_symbol_table_dump(), add_new_compilation_unit(), add_new_module_from_text(), alias_check(), build_aliases(), check_first_statement(), clean_file(), close_resource_file(), close_warning_file(), close_xml_logfile(), csplit_close_compilation_unit(), csplit_close_files(), csplit_copy(), dag_dot_dump(), davinci_dump_expressions(), davinci_print_control_nodes(), davinci_print_non_deterministic_unstructured(), direct_change_directory(), directive_in_file_p(), dump_current_statement(), f95split(), find_eol_coding(), flinter(), freia_compile(), freia_opencl_compile_calls(), full_graph_of_calls(), generic_print_xml_application(), get_first_main_module(), get_new_user_file(), gfc2pips_namespace(), gpu_xml_dump(), graph_of_calls(), handle_file_name(), handle_include_file(), hbdsc_parallelization(), hpfc_fclose(), html_prettyprint(), html_prettyprint_symbol_table(), load_entities(), load_meta_data(), make_resource_from_starting_node(), make_text_resource(), module_to_callgraph(), open_logfile(), open_makefile(), outliner_independent(), parse_arguments(), parse_makefile(), ParserError(), pips_process_file(), pips_split_file(), print_array_dfg(), print_bdt(), print_code_smalltalk(), print_crough(), print_dependence_or_chains_graph(), print_dinf_statistics(), print_dot_dependence_or_chains_graph(), print_dsup_statistics(), print_filtered_dg_or_dvdg(), print_interface(), print_loopnest_dependence_cone(), print_loops(), print_module_name_to_toposorts(), print_plc(), print_proj_op_statistics(), print_sesam_tasks_buffers_header(), print_umay_statistics(), print_umust_statistics(), print_xml_code(), print_xml_code_with_explicit_motif(), process_user_file(), put_result(), region_translation_statistics_close(), rice_dependence_graph(), safe_append(), safe_copy(), safe_copy_line_interval(), safe_display(), safe_get_line_interval(), safe_read_nth_line(), save_entities(), save_makefile(), save_meta_data(), sequence_dependence_graph(), step_compile_analysed_module(), step_compile_generated_module(), step_install(), text_area_included(), the_actual_parser(), tpips_close(), unimodular(), unsplit_internal(), used_before_set(), write_an_attachment_file(), write_to_eole(), and writeresult().

◆ safe_fflush()

int safe_fflush ( FILE *  stream,
char *  filename 
)
Parameters
streamtream
filenameilename

Definition at line 90 of file file.c.

91 {
92  if (fflush(stream) == EOF)
93  pips_internal_error("fflush failed on file %s (%s)",
94  filename,
95  strerror(errno));
96  return 0;
97 }

References pips_internal_error.

Referenced by safe_cat().

+ Here is the caller graph for this function:

◆ safe_fgetc()

int safe_fgetc ( FILE *  stream,
char *  filename 
)
Parameters
streamtream
filenameilename

Definition at line 147 of file file.c.

148 {
149  int value;
150  if((value = fgetc( stream)) == EOF) {
151  pips_internal_error("fgetc failed on file %s (%s)",
152  filename, strerror(errno));
153  }
154  return(value);
155 }
struct _newgen_struct_value_ * value
Definition: ri.h:455

References pips_internal_error.

◆ safe_fgets()

char* safe_fgets ( char *  s,
int  n,
FILE *  stream,
char *  filename 
)
Parameters
streamtream
filenameilename

Definition at line 170 of file file.c.

171 {
172  if (fgets(s, n, stream) == (char *) NULL) {
173  pips_internal_error("gets failed on file %s (%s)",
174  filename, strerror(errno));
175  }
176  return s;
177 }

References pips_internal_error.

Referenced by get_main_entity_name(), safe_copy_line_interval(), and safe_read_nth_line().

+ Here is the caller graph for this function:

◆ safe_fopen()

FILE* safe_fopen ( const char *  filename,
const char *  what 
)
Parameters
filenameilename
whathat

Definition at line 67 of file file.c.

68 {
69  FILE * f;
70  if((f = fopen( filename, what)) == (FILE *) NULL) {
71  pips_internal_error("fopen failed on file %s\n%s",
72  filename, strerror(errno));
73  }
74  return f;
75 }

References f(), and pips_internal_error.

Referenced by actual_c_parser(), actual_symbol_table_dump(), add_new_compilation_unit(), add_new_module_from_text(), alias_check(), check_first_statement(), clean_file(), csplit(), csplit_open_compilation_unit(), dag_dot_dump(), davinci_dump_expressions(), davinci_print_control_nodes(), davinci_print_non_deterministic_unstructured(), direct_change_directory(), directive_in_file_p(), do_recompile_module(), dump_current_statement(), f95split(), find_eol_coding(), flinter(), fopen_config(), freia_compile(), freia_opencl_compile_calls(), full_graph_of_calls(), generic_print_xml_application(), get_first_main_module(), get_new_user_file(), gfc2pips_namespace(), gpu_xml_dump(), graph_of_calls(), handle_file_name(), handle_include_file(), hbdsc_parallelization(), Hierarchical_tiling(), hpfc_fopen(), html_prettyprint(), html_prettyprint_symbol_table(), load_entities(), make_resource_from_starting_node(), make_text_resource(), module_to_callgraph(), open_logfile(), open_resource_file(), open_warning_file(), open_xml_logfile(), outliner_independent(), pips_process_file(), pips_split_file(), print_array_dfg(), print_bdt(), print_code_smalltalk(), print_crough(), print_dependence_or_chains_graph(), print_dinf_statistics(), print_dot_dependence_or_chains_graph(), print_dsup_statistics(), print_filtered_dg_or_dvdg(), print_interface(), print_loopnest_dependence_cone(), print_loops(), print_module_name_to_toposorts(), print_plc(), print_proj_op_statistics(), print_sesam_tasks_buffers_header(), print_umay_statistics(), print_umust_statistics(), print_xml_code(), print_xml_code_with_explicit_motif(), process_user_file(), put_result(), read_from_eole(), region_translation_statistics_close(), rice_dependence_graph(), safe_append(), safe_copy(), safe_copy_line_interval(), safe_display(), safe_get_line_interval(), safe_read_nth_line(), save_entities(), save_makefile(), save_meta_data(), sc_delimiter(), sequence_dependence_graph(), step_compile_analysed_module(), step_compile_generated_module(), step_install(), text_area_included(), the_actual_parser(), Tiling2_buffer(), Tiling_buffer_allocation(), unimodular(), unsplit_internal(), used_before_set(), write_an_attachment_file(), write_to_eole(), and writeresult().

+ Here is the call graph for this function:

◆ safe_fputc()

int safe_fputc ( char  c,
FILE *  stream,
char *  filename 
)

Definition at line 179 of file file.c.

183 {
184  if(fputc( c, stream) == EOF) {
185  pips_internal_error("fputc failed on file %s (%s)",
186  filename, strerror(errno));
187  }
188  return(c);
189 }

References pips_internal_error.

◆ safe_fputs()

int safe_fputs ( char *  s,
FILE *  stream,
char *  filename 
)
Parameters
streamtream
filenameilename

Definition at line 203 of file file.c.

206 {
207  if(fputs( s, stream) == EOF) {
208  pips_internal_error("fputs failed on file %s (%s)",
209  filename, strerror(errno));
210  }
211  return(1);
212 }

References pips_internal_error.

◆ safe_fread()

int safe_fread ( char *  ptr,
int  element_size,
int  count,
FILE *  stream,
char *  filename 
)
Parameters
ptrtr
element_sizelement_size
countount
streamtream
filenameilename

Definition at line 214 of file file.c.

219 {
220  if(((int)fread(ptr, element_size, count, stream)) != count) {
221  pips_internal_error("fread failed on file %s (%s)",
222  filename, strerror(errno));
223  }
224  return(count);
225 }
static int count
Definition: SDG.c:519

References count, and pips_internal_error.

◆ safe_freopen()

FILE* safe_freopen ( char *  filename,
char *  what,
FILE *  stream 
)
Parameters
filenameilename
whathat
streamtream

Definition at line 99 of file file.c.

100 {
101  FILE *f;
102 
103  if((f = freopen( filename, what, stream)) == (FILE *) NULL) {
104  pips_internal_error("freopen failed on file %s (%s)",
105  filename,
106  strerror(errno));
107  }
108  return f;
109 }

References f(), and pips_internal_error.

+ Here is the call graph for this function:

◆ safe_fseek()

int safe_fseek ( FILE *  stream,
long int  offset,
int  wherefrom,
char *  filename 
)
Parameters
streamtream
offsetffset
wherefromherefrom
filenameilename

Definition at line 112 of file file.c.

113 {
114  if( fseek( stream, offset, wherefrom) != 0) {
115  pips_internal_error("fseek failed on file %s (%s)",
116  filename,
117  strerror(errno));
118  }
119  return(0);
120 }
static Value offset
Definition: translation.c:283

References offset, and pips_internal_error.

◆ safe_ftell()

long int safe_ftell ( FILE *  stream,
char *  filename 
)
Parameters
streamtream
filenameilename

Definition at line 123 of file file.c.

124 {
125  long int pt;
126  pt = ftell( stream);
127  if((pt == -1L) && (errno != 0)) {
128  pips_internal_error("ftell failed on file %s (%s)",
129  filename,
130  strerror(errno));
131  }
132  return(pt);
133 }

References pips_internal_error.

◆ safe_fwrite()

int safe_fwrite ( char *  ptr,
int  element_size,
int  count,
FILE *  stream,
char *  filename 
)
Parameters
ptrtr
element_sizelement_size
countount
streamtream
filenameilename

Definition at line 227 of file file.c.

232 {
233  if(((int)fwrite(ptr, element_size, count, stream)) != count) {
234  pips_internal_error("fwrite failed on file %s (%s)",
235  filename,
236  strerror(errno));
237  }
238  return(count);
239 }

References count, and pips_internal_error.

◆ safe_get_line_interval()

string safe_get_line_interval ( const string  fn,
int  f,
int  l 
)

return lines f-l from file fn as a string

Parameters
fnn

Definition at line 539 of file file.c.

540 {
541  pips_assert("positive lines", 1 <= f && 1 <= l);
542 
543  if (l < f) {
544  // ooops, empty interval...
545  // TODO: generate an internal error instead
546  // however there are some impact on the validation...
547  string msg;
548  asprintf(&msg, "<empty interval on \"%s\": %d-%d>\n", fn, f, l);
549  return msg;
550  }
551 
552  FILE * fd = safe_fopen(fn, "r");
554 
555  // skip first lines
556  int i;
557  for (i = 1; i < f ; i++) {
558  char * line = safe_readline(fd);
559  pips_assert("expecting a line", line != NULL);
560  free(line);
561  }
562 
563  // keep next lines, although without preprocessor stuff
564  for (i = f; i <= l; i++)
565  {
566  char * line = safe_readline(fd);
567  // pips_assert("expecting a line", line != NULL);
568  if (line == NULL) break;
569 
570  // ??? skip preprocessor #... lines?
571  // I'm not sure that it really works (FC)
572  char * c = line;
573  while (*c && (*c == ' ' || *c == '\t')) c++;
574  if (*c == '#') // ??? preprocessor line?
575  i--;
576  else {
578  string_buffer_append(sb, "\n");
579  }
580 
581  free(line);
582  }
583 
584  // we are done
585  safe_fclose(fd, fn);
586 
587  string extract = string_buffer_to_string(sb);
589 
590  return extract;
591 }
char * safe_readline(FILE *file)
returns the allocated line read, whatever its length.
Definition: file.c:497
#define asprintf
Definition: misc-local.h:225
void string_buffer_append(string_buffer, const string)
append string s (if non empty) to string buffer sb, the duplication is done if needed according to th...
string string_buffer_to_string(const string_buffer)
return malloc'ed string from string buffer sb
void string_buffer_free(string_buffer *)
free string buffer structure, also free string contents according to the dup field
Definition: string_buffer.c:82
string_buffer string_buffer_make(bool dup)
allocate a new string buffer
Definition: string_buffer.c:58
static int line
FLEX_SCANNER.
Definition: scanner.c:852
internally defined structure.
Definition: string_buffer.c:47
Definition: statement.c:4047

References asprintf, f(), free(), line, pips_assert, safe_fclose(), safe_fopen(), safe_readline(), string_buffer_append(), string_buffer_free(), string_buffer_make(), and string_buffer_to_string().

Referenced by c_parser_user_warning_alist().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ safe_getc()

int safe_getc ( FILE *  stream,
char *  filename 
)
Parameters
streamtream
filenameilename

Definition at line 158 of file file.c.

159 {
160  int value;
161  if((value = getc( stream)) == EOF ) {
162  pips_internal_error("getc failed on file %s (%s)",
163  filename,
164  strerror(errno));
165  }
166  return(value);
167 }

References pips_internal_error.

◆ safe_link()

void safe_link ( const char *  topath,
const char *  frompath 
)

Create a hard link to topath.

That means that the file is accessible with the new name frompath too.

Throw a pips_internal_error() if it fails.

Parameters
topathopath
frompathrompath

Definition at line 878 of file file.c.

879 {
880  if (link(frompath, topath))
881  {
882  perror("[safe_link] ");
883  pips_internal_error("link(%s,%s) failed", frompath, topath);
884  }
885 }

References pips_internal_error.

Referenced by add_new_module_from_text().

+ Here is the caller graph for this function:

◆ safe_list_files_in_directory()

int safe_list_files_in_directory ( gen_array_t  files,
string  dir,
string  re,
bool(*)(const char *)  file_name_predicate 
)

returns a sorted arg list of files matching regular expression re in directory 'dir' and with file_name_predicate() returning true on the file name (for example use directory_exists_p to select directories, of file_exists_p to select regular files).

re has the ed syntax.

Return 0 on success, -1 on directory openning error.

Parameters
filesiles
diran allocated array
rethe directory we're interested in
file_name_predicateregular expression condition to list a file

Definition at line 250 of file file.c.

255 {
256  DIR * dirp;
257  struct dirent * dp;
258  int index = 0;
259 
260  pips_assert("some dir", strcmp(dir, "") != 0);
261 
262  dirp = opendir(dir);
263 
264  if (dirp != NULL)
265  {
266  regex_t re_compiled;
267 
268  if (regcomp(&re_compiled, re, REG_ICASE))
269  pips_user_error("regcomp() failed to compile \"%s\".\n", re);
270 
271  while((dp = readdir(dirp)) != NULL) {
272  if (!regexec(&re_compiled, dp->d_name, 0, NULL, 0))
273  {
274  char * full_file_name =
275  strdup(concatenate(dir, "/", dp->d_name, NULL));
276  if (file_name_predicate(full_file_name))
277  gen_array_dupaddto(files, index++, dp->d_name);
278  free(full_file_name);
279  }
280  }
281 
282  regfree(&re_compiled);
283 
284  closedir(dirp);
285  }
286  else
287  return -1;
288 
289  gen_array_sort(files);
290  return 0;
291 }
void gen_array_dupaddto(gen_array_t a, size_t i, void *what)
Definition: array.c:111
void gen_array_sort(gen_array_t a)
Definition: array.c:164

References concatenate(), free(), gen_array_dupaddto(), gen_array_sort(), pips_assert, pips_user_error, and strdup().

Referenced by generate_a_directory_menu(), hpfc_get_file_list(), and list_files_in_directory().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ safe_new_tmp_file()

char* safe_new_tmp_file ( char *  prefix)

SunOS forgets to declare this one.

extern char * mktemp(char *);

Returns
a new temporary file name, starting with "prefix". the name is freshly allocated.

FI: mkstemp() is being deprecated and it returns an integer, usable as file descriptor, not a character string.

Parameters
prefixrefix

Definition at line 935 of file file.c.

936 {
937  string name = strdup(concatenate(prefix, ".XXXXXX", NULL));
938  int desc = mkstemp(name);
939  pips_assert("could create temporary name", desc!=-1);
940  return name;
941 }
static const char * prefix

References concatenate(), pips_assert, prefix, and strdup().

Referenced by apply_eole_on_statement(), and parse_arguments().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ safe_putc()

int safe_putc ( char  c,
FILE *  stream,
char *  filename 
)

Definition at line 191 of file file.c.

195 {
196  if(putc( c, stream) == EOF) {
197  pips_internal_error("putc failed on file %s (%s)",
198  filename, strerror(errno));
199  }
200  return(c);
201 }

References pips_internal_error.

◆ safe_read_nth_line()

string safe_read_nth_line ( string  fn,
int  n 
)

Assumes "fn" is the name of a text file, opens it, and returns its nth line (starting with 1) in a newly allocated buffer, whatever the line length.

Returns NULL if it does not exist.

This function is used by the PIPS preprocessor and its parsers to print out the line where an error has been detected.

Parameters
fnn

Definition at line 523 of file file.c.

524 {
525  FILE * fd = safe_fopen(fn, "r");
526  int i = 0;
527 #define MAX_INPUT_LINE_SIZE (200)
529  // Skip n-1 lines
530  for(i=0; i<n-1; i++)
532  string nth_line = safe_readline(fd);
533  safe_fclose(fd, fn);
534  return nth_line;
535 }

References current_line, MAX_INPUT_LINE_SIZE, safe_fclose(), safe_fgets(), safe_fopen(), and safe_readline().

Referenced by csplit_parser_warning_alist().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ safe_readfile()

char* safe_readfile ( FILE *  file)

returns the file as an allocated string.


is dropped at the time.

Parameters
fileile

Definition at line 650 of file file.c.

651 {
652  char * line, * buf=NULL;
653  while ((line=safe_readline(file)))
654  {
655  if (buf)
656  {
657  buf = (char*)
658  realloc(buf, sizeof(char)*(strlen(buf)+strlen(line)+2));
659  strcat(buf, " ");
660  strcat(buf, line);
661  free(line);
662  }
663  else buf = line;
664  }
665  return buf;
666 }

References buf, free(), line, and safe_readline().

Referenced by safe_system_output().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ safe_readline()

char* safe_readline ( FILE *  file)

returns the allocated line read, whatever its length.

returns NULL on EOF. also some asserts. FC 09/97.

larger for trailing '\0'

Parameters
fileile

Definition at line 497 of file file.c.

498 {
499  int i=0, size = 20, c;
500  char * buf = (char*) malloc(sizeof(char)*size), * res;
501  pips_assert("malloc ok", buf);
502  while((c=getc(file)) && c!=EOF && c!='\n')
503  {
504  if (i==size-1) /* larger for trailing '\0' */
505  {
506  size+=20; buf = (char*) realloc((char*) buf, sizeof(char)*size);
507  pips_assert("realloc ok", buf);
508  }
509  buf[i++] = (char) c;
510  }
511  if (c==EOF && i==0) { res = NULL; free(buf); }
512  else { buf[i++] = '\0'; res = strdup(buf); free(buf); }
513  return res;
514 }

References buf, free(), malloc(), pips_assert, and strdup().

Referenced by clean_file(), declarations_read(), default_user_request(), get_first_main_module(), get_help_topic(), get_help_topics(), get_next_line(), handle_file(), load_meta_data(), process_user_file(), safe_get_line_interval(), safe_read_nth_line(), and safe_readfile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ safe_rewind()

void safe_rewind ( FILE *  stream,
char *  filename 
)
Parameters
streamtream
filenameilename

Definition at line 136 of file file.c.

137 {
138  rewind( stream );
139  if(errno != 0) {
140  pips_internal_error("rewind failed on file %s (%s)",
141  filename,
142  strerror(errno));
143  }
144 }

References pips_internal_error.

◆ safe_symlink()

void safe_symlink ( const char *  topath,
const char *  frompath 
)
Parameters
topathopath
frompathrompath

Definition at line 862 of file file.c.

863 {
864  if (symlink(topath, frompath))
865  {
866  perror("[safe_symlink] ");
867  pips_internal_error("symlink(%s, %s) failed", topath, frompath);
868  }
869 }

References pips_internal_error.

◆ safe_system_output()

char* safe_system_output ( char *  what)

attempt shell substitutions to what.

returns NULL on errors.

on failures, do not stop it anyway...

Parameters
whathat

Definition at line 890 of file file.c.

891 {
892  char * result;
893  FILE * in;
894 
895  in = popen(what, "r");
896 
897  if (in==NULL) {
898  perror("[safe_system_output] ");
899  pips_internal_error("popen failed: %s", what);
900  }
901 
902  result = safe_readfile(in);
903 
904  if (pclose(in)) {
905  /* on failures, do not stop it anyway...
906  */
907  perror("[safe_system_output] ");
908  pips_user_warning("\n pclose failed: %s\n", what);
909  if (result) free(result), result = NULL;
910  }
911 
912  return result;
913 }
char * safe_readfile(FILE *file)
returns the file as an allocated string.
Definition: file.c:650

References free(), pips_internal_error, pips_user_warning, and safe_readfile().

Referenced by safe_system_substitute().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ safe_system_substitute()

char* safe_system_substitute ( char *  what)

returns what after variable, command and file substitutions.

the returned string is newly allocated. it's NULL on errors.

Parameters
whathat

Definition at line 919 of file file.c.

920 {
921  return safe_system_output(concatenate("echo ", what, NULL));
922 }
char * safe_system_output(char *what)
attempt shell substitutions to what.
Definition: file.c:890

References concatenate(), and safe_system_output().

Referenced by tp_substitutions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ safe_unlink()

void safe_unlink ( const char *  file_name)

Delete the given file.

Throw a pips_internal_error() if it fails.

Parameters
file_nameile_name

Definition at line 852 of file file.c.

853 {
854  if (unlink(file_name))
855  {
856  perror("[safe_unlink] ");
857  pips_internal_error("unlink %s failed", file_name);
858  }
859 }

References file_name, and pips_internal_error.

Referenced by add_new_module_from_text(), apply_eole_on_statement(), filter_file(), and handle_include_file().

+ Here is the caller graph for this function:

◆ strescape()

char* strescape ( const char *  source)

protect a string, for example for use in a system call list of non escaped characters in the macro above.

Parameters
sourceource

Definition at line 334 of file file.c.

335 {
336  size_t new_size = 1; // for \0
337  for (const char *iter=source; *iter; ++iter,++new_size)
338  if (to_escape(*iter)) ++new_size;
339  char *escaped = malloc(sizeof(char)*new_size);
340  char *eiter = escaped;
341  for (const char *iter=source; *iter; ++iter,++eiter) {
342  if (to_escape(*iter)) *eiter++ = '\\';
343  *eiter = *iter;
344  }
345  *eiter=0;
346  return escaped;
347 }
#define to_escape(c)
Definition: file.c:327

References malloc(), and to_escape.

Referenced by check_delete_workspace(), check_input_file_syntax(), and process_thru_C_pp().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: