PIPS
standardize_structure.c
Go to the documentation of this file.
1 /*
2 
3  $Id: standardize_structure.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 
25 // do not compile unless required
26 #include "phases.h"
27 #ifdef BUILDER_STF
28 
29 #ifdef HAVE_CONFIG_H
30  #include "pips_config.h"
31 #endif
32 /*
33  * STF()
34  *
35  * Guillaume Oget
36  */
37 #include <stdlib.h> // mkstemp, system
38 #include <unistd.h> // unlink
39 #include <stdio.h>
40 #include <string.h>
41 
42 #include "genC.h"
43 #include "linear.h"
44 
45 #include "misc.h"
46 #include "pipsdbm.h"
47 
48 #include "ri.h"
49 #include "ri-util.h"
50 
51 /* Top-level functions
52  */
53 
54 bool stf(const string mod_name)
55 {
56 
57 #define MAX__LENGTH 256
58 
59  char tmpfile[MAX__LENGTH];
60  char outline[MAX__LENGTH];
61  FILE *ftmp;
62  int status;
64 
65  debug_on("STF_DEBUG_LEVEL");
66 
67  strncpy (tmpfile,".stf-workspace-outputXXXXXX", MAX__LENGTH - 1);
68  int fd = mkstemp (tmpfile);
69  if (fd == -1)
70  pips_internal_error("unable to make a temporary file");
71  pips_debug (9, "temporary filename for output %s\n", tmpfile);
72 
74  ("stf-module ",
75  wdn,
76  "/",
77  db_get_memory_resource(DBR_SOURCE_FILE, mod_name, true),
78  " > ",
79  tmpfile,
80  " 2>&1 ",
81  NULL));
82 
83  debug (9,"stf","status=%d\n",status);
84 
85  /* Print log info if any */
86  if ((ftmp = fopen (tmpfile,"r")) != NULL)
87  {
88  while (!feof (ftmp))
89  {
90  if (fgets(outline, MAX__LENGTH, ftmp))
91  user_log ("[stf-log] %s", outline);
92  else
93  break;
94  }
95  fclose (ftmp);
96  unlink (tmpfile);
97  }
98  else
99  user_warning ("stf","No ouput from command\n");
100 
101  if (!status) {
102  debug (1,"stf", "ok for module %s\n", mod_name);
103  /* Why did GO use a touch instead of a put? */
104  if(!db_update_time (DBR_SOURCE_FILE, mod_name))
105  user_error ("stf",
106  "Cannot find new source file for module %s\n",
107  mod_name);
108  }
109  else if (status == 2)
110  user_error ("stf",
111  "should clean up with toolpack command for module %s\n",
112  mod_name);
113  else
114  user_error ("stf",
115  "failed for module %s\n",
116  mod_name);
117 
118  debug_off ();
119 
120  free(wdn);
121 
122  return true;
123 }
124 
125 #endif // BUILDER_STF
void user_log(const char *format,...)
Definition: message.c:234
bool db_update_time(const char *rname, const char *oname)
this should really be a put.
Definition: database.c:380
bool outline(const string)
entry point for outline module outlining will be performed using either comment recognition or intera...
Definition: outlining.c:1385
struct _newgen_struct_status_ * status
Definition: database.h:31
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
#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 pips_internal_error
Definition: misc-local.h:149
#define debug_off()
Definition: misc-local.h:160
#define user_error(fn,...)
Definition: misc-local.h:265
#define user_warning(fn,...)
Definition: misc-local.h:262
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
int safe_system_no_abort(string)
the command to be executed
Definition: system.c:47
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
bool stf(const string)
standardize_structure.c