PIPS
openclose.c
Go to the documentation of this file.
1 /*
2 
3  $Id: openclose.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 /* Some modifications are made to save the current makefile (s.a. files
28  * pipsmake/readmakefile.y openclose.h )
29  * They only occure between following tags:
30  */
31 /**** Begin saved_makefile version ****/
32 /**** End saved_makefile version ****/
33 
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <sys/types.h>
38 
39 /* Some modifications are made to save the current makefile (s.a. files
40  * pipsmake/readmakefile.y pipsmake.h )
41  * They only occure between following tags:
42  *
43  * Bruno Baron
44  */
45 
46 #include <string.h>
47 #include <sys/param.h>
48 
49 #include "genC.h"
50 #include "database.h"
51 #include "linear.h"
52 #include "ri.h"
53 
54 #include "properties.h"
55 #include "ri-util.h"
56 #include "pipsdbm.h"
57 #include "pipsmake.h"
58 #include "misc.h"
59 
60 /* returns the program makefile file name
61  */
62 #define PIPSMAKE_FILE "/pipsmake"
63 string build_pgm_makefile(const char* __attribute__ ((unused)) n)
64 {
65  pips_assert("true", n==n);
66  string dir_name = db_get_meta_data_directory(),
67  res = strdup(concatenate(dir_name, PIPSMAKE_FILE, NULL));
68  free(dir_name);
69  return res;
70 }
71 
72 string make_open_workspace(const char* name)
73 {
74  if (db_open_workspace(name))
75  {
76  if (open_properties())
77  {
78  if (open_makefile(name) != makefile_undefined)
79  {
80  pips_debug(7, "makefile opened\n");
81  }
82  else
83  {
84  /* should be an error? */
85  pips_user_warning("No special makefile for this workspace "
86  "%s/%s.database\n", get_cwd(), name);
87  }
88  }
89  else
90  {
91  pips_user_warning("Cannot read properties...\n");
92  db_close_workspace(true);
93  }
94  } else
95  pips_user_warning("No workspace %s to open\n", name);
96 
98 }
99 
100 /* FI->GO: could be in top-level, no?
101  */
102 bool make_close_workspace(bool is_quit)
103 {
104  bool res = true;
105  string name;
106 
107  if (db_get_current_module_name()) /* lazy... */
109 
110  /* dup because freed in db_close_workspace */
112 
113  res &= close_makefile(name);
114  save_properties();
115  res &= db_close_workspace(is_quit);
116 
117  if(res)
118  user_log("Workspace %s closed.\n\n", name);
119  else
120  user_log("Failed to close workspace %s.\n\n", name);
121 
122  free(name);
123  return res;
124 }
125 
126 /* checkpoint the current workspace, i.e. save everything so
127  * that it is possible to reopen it in case of failure.
128  */
130 {
132  {
133  user_log("Checkpoint of workspace.\n");
134  /* FC 25/06/2003
135  * this seems to break pipsmake internal data...
136  pips_debug(3, "\tdeleting obsolete resources...\n");
137  delete_obsolete_resources();
138  */
139  pips_debug(3, "\tsaving resources...\n");
141  pips_debug(3, "\tproperties and makefile...\n");
142  save_properties();
144  }
145 }
float a2sf[2] __attribute__((aligned(16)))
USER generates a user error (i.e., non fatal) by printing the given MSG according to the FMT.
Definition: 3dnow.h:3
void user_log(const char *format,...)
Definition: message.c:234
void db_reset_current_module_name(void)
Definition: database.c:1064
string db_get_current_module_name(void)
Also used to check whether set...
Definition: database.c:1059
char * get_cwd(void)
returns the current working directory name.
Definition: file.c:486
void free(void *)
#define makefile_undefined
Definition: makefile.h:58
#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_user_warning
Definition: misc-local.h:146
#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
string build_pgm_makefile(const char *__attribute__((unused)) n)
Definition: openclose.c:63
bool make_close_workspace(bool is_quit)
FI->GO: could be in top-level, no?
Definition: openclose.c:102
#define PIPSMAKE_FILE
Some modifications are made to save the current makefile (s.a.
Definition: openclose.c:62
string make_open_workspace(const char *name)
Definition: openclose.c:72
void checkpoint_workspace(void)
checkpoint the current workspace, i.e.
Definition: openclose.c:129
bool db_close_workspace(bool)
Definition: workspace.c:367
bool db_open_workspace(const char *)
Definition: workspace.c:380
string db_get_meta_data_directory(void)
Definition: workspace.c:139
void db_checkpoint_workspace(void)
Definition: workspace.c:350
string db_get_current_workspace_name(void)
the function is used to check that there is some current workspace...
Definition: workspace.c:82
void save_makefile(const char *)
bool close_makefile(const char *)
makefile open_makefile(const char *)
void save_properties(void)
bool open_properties(void)
char * strdup()