PIPS
install.c
Go to the documentation of this file.
1 /* Copyright 2007-2012 Alain Muller, Frederique Silber-Chaussumier
2 
3 This file is part of STEP.
4 
5 The program is distributed under the terms of the GNU General Public
6 License.
7 */
8 
9 #ifdef HAVE_CONFIG_H
10  #include "pips_config.h"
11 #endif
12 
13 #include "defines-local.h"
14 
15 bool step_install(const string program_name)
16 {
17  debug_on("STEP_INSTALL_DEBUG_LEVEL");
18  pips_debug(1, "Starting for program \"%s\".\n", program_name);
19 
20  /* Generation des fichiers sources dans workspace.database/Src/ */
23  int n = gen_array_nitems(modules), i;
25 
26  for (i=0; i<n; i++)
27  {
28  string module_name = gen_array_item(modules, i);
29  string user_file = db_get_memory_resource(DBR_USER_FILE, module_name, true);
30  string new_file = hash_get(user_files, user_file);
31  if (new_file == HASH_UNDEFINED_VALUE)
32  {
33  string base_name = pips_basename(user_file, NULL);
34  new_file = strdup(concatenate(dest_dir, "/", base_name, NULL));
35  hash_put(user_files, user_file, new_file);
36  }
37 
38  string step_file = db_get_memory_resource(DBR_STEP_FILE, module_name, true);
39 
40 
41 
42  pips_debug(1, "Module: \"%s\"\n\tuser_file: \"%s\"\n\tinstall file : \"%s\"\n", module_name, user_file, new_file);
43  FILE *out = safe_fopen(new_file, "a");
44  FILE *in = safe_fopen(step_file, "r");
45 
46  safe_cat(out, in);
47 
48  safe_fclose(out, new_file);
49  safe_fclose(in, step_file);
50  }
51 
53  free(dest_dir);
54 
55  /* Instalation des fichiers generes */
56  dest_dir = strdup(get_string_property("STEP_INSTALL_PATH"));
58  if (empty_string_p(dest_dir))
59  {
60  free(dest_dir);
62  }
63 
64  safe_system(concatenate("step_install ", dest_dir, " ", src_dir, NULL));
65 
66  free(src_dir);
67  free(dest_dir);
68 
69  debug_off();
70  return true;
71 }
72 
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_item(const gen_array_t a, size_t i)
Definition: array.c:143
bool empty_string_p(const char *s)
Definition: entity_names.c:239
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
FILE * safe_fopen(const char *filename, const char *what)
Definition: file.c:67
char * get_string_property(const char *)
int safe_fclose(FILE *stream, const char *filename)
Definition: file.c:77
char * pips_basename(char *fullpath, char *suffix)
Definition: file.c:822
void safe_cat(FILE *out, FILE *in)
Definition: file.c:669
static FILE * user_file
These functions implements the writing of objects.
Definition: genClib.c:1485
void free(void *)
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
hash_table hash_table_make(hash_key_type key_type, size_t size)
Definition: hash.c:294
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
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
Definition: hash.c:327
bool step_install(const string program_name)
Copyright 2007-2012 Alain Muller, Frederique Silber-Chaussumier.
Definition: install.c:15
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_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define debug_off()
Definition: misc-local.h:160
void safe_system(string)
system.c
Definition: system.c:38
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
@ hash_string
Definition: newgen_hash.h:32
#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
#define WORKSPACE_SRC_SPACE
Definition: pipsdbm-local.h:32
char * strdup()
static hash_table user_files
initial user file -> generated user file
Definition: unsplit.c:48