PIPS
unsplit.c File Reference
#include <stdio.h>
#include <string.h>
#include "genC.h"
#include "misc.h"
#include "resources.h"
#include "linear.h"
#include "ri.h"
#include "ri-util.h"
#include "pipsdbm.h"
#include "preprocessor.h"
+ Include dependency graph for unsplit.c:

Go to the source code of this file.

Functions

static string get_new_user_file (string dir_name, string preprocessed_user_file)
 returns the new user file where to store user_file More...
 
static bool unsplit_internal (const string name, const string dbr)
 
bool unsplit (const string name)
 unsplit > PROGRAM.user_file < ALL.user_file < ALL.printed_file More...
 
bool unsplit_parsed (const string name)
 

Variables

static hash_table user_files = hash_table_undefined
 initial user file -> generated user file More...
 

Function Documentation

◆ get_new_user_file()

static string get_new_user_file ( string  dir_name,
string  preprocessed_user_file 
)
static

returns the new user file where to store user_file

C or Fortran preprocessing may have or have not occured

could check that the file does not exist... there could be homonymes...

Definition at line 53 of file unsplit.c.

54 {
55  /* C or Fortran preprocessing may have or have not occured */
56  string user_file = preprocessed_to_user_file(preprocessed_user_file);
57  string s = hash_get(user_files, user_file);
58 
59  if (s==HASH_UNDEFINED_VALUE) {
60  FILE * tmp;
61  string name = pips_basename(user_file, NULL);
62 
63  pips_debug(1,
64  "It does not exist a file \"%p\"\n for user_file \"%s\"\n"
65  " and for preprocessed_user_file \"%s\".\n"
66  "in table %p\n",
67  s, user_file, preprocessed_user_file, user_files);
68  s = strdup(concatenate(dir_name, "/", name, NULL));
70  /* could check that the file does not exist...
71  * there could be homonymes...
72  */
73  if((tmp=fopen(s, "r"))!=NULL) {
74  pips_internal_error("Rewriting existing file \"%s\" for user_file \"%s\""
75  " and for preprocessed_user_file \"%s\".\n",
76  s, user_file, preprocessed_user_file);
77  fclose(tmp);
78  }
79  tmp = safe_fopen(s, "w");
82  fprintf(tmp, "!!\n!! file for %s\n!!\n", name);
83  }
84  else if(dot_c_file_p(user_file)) {
85  fprintf(tmp, "/*\n * file for %s\n */\n", name);
86  }
87  else {
88  pips_internal_error("unexpected user file suffix: \"%s\"", user_file);
89  }
90  safe_fclose(tmp, s);
91  free(name);
92  }
93  else {
94  pips_debug(1,
95  "It does exist a file \"%s\"\n for user_file \"%s\"\n"
96  " and for preprocessed_user_file \"%s\".\n"
97  "in table %p\n",
98  s, user_file, preprocessed_user_file, user_files);
99  }
100  free(user_file);
101  return s;
102 }
FILE * safe_fopen(const char *filename, const char *what)
Definition: file.c:67
int safe_fclose(FILE *stream, const char *filename)
Definition: file.c:77
char * pips_basename(char *fullpath, char *suffix)
Definition: file.c:822
static FILE * user_file
These functions implements the writing of objects.
Definition: genClib.c:1485
void free(void *)
void * hash_get(const hash_table htp, const void *key)
this function retrieves in the hash table pointed to by htp the couple whose key is equal to key.
Definition: hash.c:449
void hash_put(hash_table htp, const void *key, const void *val)
This functions stores a couple (key,val) in the hash table pointed to by htp.
Definition: hash.c:364
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define pips_internal_error
Definition: misc-local.h:149
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
#define HASH_UNDEFINED_VALUE
value returned by hash_get() when the key is not found; could also be called HASH_KEY_NOT_FOUND,...
Definition: newgen_hash.h:56
bool dot_c_file_p(string)
Test if a name ends with .c.
Definition: source_file.c:661
bool dot_f95_file_p(string)
Test if a name ends with .f95.
Definition: source_file.c:655
string preprocessed_to_user_file(string)
Allocate a new string containing the user file name, before preprocessing.
Definition: source_file.c:617
bool dot_f90_file_p(string)
Test if a name ends with .f90.
Definition: source_file.c:649
bool dot_f_file_p(string)
Test if a name ends with .f.
Definition: source_file.c:643
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
char * strdup()
static hash_table user_files
initial user file -> generated user file
Definition: unsplit.c:48

References concatenate(), dot_c_file_p(), dot_f90_file_p(), dot_f95_file_p(), dot_f_file_p(), fprintf(), free(), hash_get(), hash_put(), HASH_UNDEFINED_VALUE, pips_basename(), pips_debug, pips_internal_error, preprocessed_to_user_file(), safe_fclose(), safe_fopen(), strdup(), user_file, and user_files.

+ Here is the call graph for this function:

◆ unsplit()

bool unsplit ( const string  name)

unsplit > PROGRAM.user_file < ALL.user_file < ALL.printed_file

unsplit.c

Parameters
nameame

Definition at line 185 of file unsplit.c.

186 {
187  return unsplit_internal(name, DBR_PRINTED_FILE);
188 }
static bool unsplit_internal(const string name, const string dbr)
Definition: unsplit.c:104

References unsplit_internal().

+ Here is the call graph for this function:

◆ unsplit_internal()

static bool unsplit_internal ( const string  name,
const string  dbr 
)
static

Definition at line 104 of file unsplit.c.

105 {
107  int n = gen_array_nitems(modules), i;
109  string summary_name = db_build_file_resource_name
110  (DBR_USER_FILE, PROGRAM_RESOURCE_OWNER, ".txt");
111  string summary_full_name;
112  string dir_name;
113  FILE * summary;
114  int nfiles = 0; // Number of preexisting files in src_dir
115 
116  pips_assert("unused argument", name==name);
117 
118  debug_on("UNSPLIT_DEBUG_LEVEL");
119 
121 
123  summary_full_name = strdup(concatenate(dir_name, "/", summary_name, NULL));
124 
125  // Get rid of previous unsplitted files
126  if ((nfiles = safe_system_no_abort_no_warning(
127  concatenate("i=`ls ", src_dir, " | wc -l`; export i; exit $i ",
128  NULL)))>0) {
129  int failure = 0;
131  concatenate("/bin/rm ", src_dir, "/*", NULL))))
132  pips_user_warning("exit code for /bin/rm is %d\n", failure);
133  }
134 
135  summary = safe_fopen(summary_full_name, "w");
136  fprintf(summary, "! module / file\n");
137 
138  // each module PRINTED_FILE is appended to a new user file
139  // depending on its initial user file.
140  for (i=0; i<n; i++)
141  {
142  string module, user_file, new_user_file, printed_file, full;
143  FILE * out, * in;
144 
145  module = gen_array_item(modules, i);
146  user_file = db_get_memory_resource(DBR_USER_FILE, module, true);
147  new_user_file = get_new_user_file(src_dir, user_file);
148  printed_file = db_get_memory_resource(dbr, module, true);
149  full = strdup(concatenate(dir_name, "/", printed_file, NULL));
150  pips_debug(1, "Module: \"%s\", user_file: \"%s\", new_user_file: \"%s\","
151  "full: \"%s\"\n",
152  module, user_file, new_user_file, full);
153 
154  out = safe_fopen(new_user_file, "a");
155  in = safe_fopen(full, "r");
156 
157  safe_cat(out, in);
158  safe_fclose(out, new_user_file);
159  safe_fclose(in, full);
160 
161  fprintf(summary, "%s: %s\n", module, new_user_file);
162  free(full);
163  }
164 
165  // cleanup
166  safe_fclose(summary, summary_full_name);
167  free(summary_full_name), free(src_dir), free(dir_name);
168  gen_array_full_free(modules);
169  HASH_MAP(k, v, free(v), user_files);
172 
173  debug_off();
174 
175  // kind of a pseudo resource...
176  DB_PUT_FILE_RESOURCE(DBR_USER_FILE, PROGRAM_RESOURCE_OWNER, summary_name);
177 
178  return true;
179 }
gen_array_t db_get_module_list_initial_order(void)
Definition: database.c:1151
static FILE * out
Definition: alias_check.c:128
size_t gen_array_nitems(const gen_array_t a)
Definition: array.c:131
void gen_array_full_free(gen_array_t a)
Definition: array.c:77
void * gen_array_item(const gen_array_t a, size_t i)
Definition: array.c:143
void safe_cat(FILE *out, FILE *in)
Definition: file.c:669
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
Definition: database.c:755
#define DB_PUT_FILE_RESOURCE
Put a file resource into the current workspace database.
Definition: pipsdbm-local.h:85
hash_table hash_table_make(hash_key_type key_type, size_t size)
Definition: hash.c:294
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
Definition: hash.c:327
static int failure(Pproblem XX, Pproblem UU, Pproblem VV, struct rproblem *RR)
Definition: isolve.c:1964
string db_build_file_resource_name(const char *rname, const char *oname, const char *suffix)
returns an allocated file name for a file resource.
Definition: lowlevel.c:169
string db_get_directory_name_for_module(const char *name)
returns the allocated and mkdir'ed directory for module name
Definition: lowlevel.c:150
#define debug_on(env)
Definition: misc-local.h:157
#define pips_user_warning
Definition: misc-local.h:146
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define debug_off()
Definition: misc-local.h:160
int safe_system_no_abort_no_warning(string)
the command to be executed
Definition: system.c:63
int safe_system_no_abort(string)
the command to be executed
Definition: system.c:47
#define HASH_MAP(k, v, code, ht)
Definition: newgen_hash.h:60
@ hash_string
Definition: newgen_hash.h:32
#define hash_table_undefined
Value of an undefined hash_table.
Definition: newgen_hash.h:49
static char * module
Definition: pips.c:74
#define WORKSPACE_SRC_SPACE
Definition: pipsdbm-local.h:32
#define PROGRAM_RESOURCE_OWNER
Definition: pipsdbm-local.h:29
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
@ full
Definition: union-local.h:65
static string get_new_user_file(string dir_name, string preprocessed_user_file)
returns the new user file where to store user_file
Definition: unsplit.c:53

References concatenate(), db_build_file_resource_name(), db_get_current_workspace_directory(), db_get_directory_name_for_module(), db_get_module_list_initial_order(), DB_PUT_FILE_RESOURCE, debug_off, debug_on, exit, failure(), fprintf(), free(), full, gen_array_full_free(), gen_array_nitems(), HASH_MAP, hash_string, hash_table_free(), hash_table_make(), hash_table_undefined, module, out, pips_assert, PROGRAM_RESOURCE_OWNER, safe_cat(), safe_fclose(), safe_fopen(), safe_system_no_abort(), safe_system_no_abort_no_warning(), strdup(), user_file, user_files, and WORKSPACE_SRC_SPACE.

Referenced by unsplit(), and unsplit_parsed().

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

◆ unsplit_parsed()

bool unsplit_parsed ( const string  name)
Parameters
nameame

Definition at line 190 of file unsplit.c.

191 {
192  return unsplit_internal(name, DBR_PARSED_PRINTED_FILE);
193 }

References unsplit_internal().

+ Here is the call graph for this function:

Variable Documentation

◆ user_files

hash_table user_files = hash_table_undefined
static

initial user file -> generated user file

Definition at line 48 of file unsplit.c.

Referenced by get_new_user_file(), step_install(), and unsplit_internal().