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

Go to the source code of this file.

Functions

void safe_free_vertex (vertex ver, list l_of_vers)
 util.c More...
 
list safe_add_vertex_to_list (vertex ver, list l_of_vers)
 
list list_of_connected_nodes (vertex ver, list l_of_vers)
 
static string convert_string_for_daVinci_graph (string s)
 
vertex get_vertex_by_string (const char *str_name, list l_of_vers)
 
list safe_make_successor (vertex ver_parent, vertex ver_child, list l_of_vers)
 
void print_graph_of_text_to_daVinci (FILE *f_out, list l_of_vers)
 
void print_graph_daVinci_from_starting_node (FILE *f_out, vertex start_ver)
 
void print_marged_text_from_starting_node (FILE *fd, int margin, vertex start_ver, list l_of_vers)
 
bool make_resource_from_starting_node (const char *mod_name, string res_name, string file_ext, vertex start_ver, list l_of_vers, bool res_text_type)
 

Function Documentation

◆ convert_string_for_daVinci_graph()

static string convert_string_for_daVinci_graph ( string  s)
static

if empty, do nothing

effects lines

delete the comment of effects

Definition at line 67 of file util.c.

68 {
69  string r;
70  int l = strlen(s);
71  if (l == 0) /* if empty, do nothing */
72  return strdup(s);
73  else {
74  int len;
75  r = (string) malloc(l + 3);
76  memset(r, 0, l + 3);
77  if (strstr(s, "C <") == s) {/* effects lines */
78  r[0] = ' '; /* delete the comment of effects */
79  strcpy(r + 1, s + 1);
80  len = l+1;
81  } else {
82  strcpy(r, s);
83  len = l;
84  }
85  // append a \n if needed
86  if (r[len-1] != '\n')
87  r[len] = '\n';
88  }
89  return r;
90 }
void * malloc(YYSIZE_T)
void * memset(void *str, int c, size_t len)
memset.c – set an area of memory to a given value Copyright (C) 1991, 2003, 2009-2011 Free Software F...
Definition: memset.c:23
char * string
STRING.
Definition: newgen_types.h:39
char * strdup()

References malloc(), memset(), and strdup().

Referenced by print_graph_of_text_to_daVinci().

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

◆ get_vertex_by_string()

vertex get_vertex_by_string ( const char *  str_name,
list  l_of_vers 
)
Parameters
str_nametr_name
l_of_vers_of_vers

Definition at line 92 of file util.c.

93 {
94  MAP(VERTEX, ver, {
95  text ver_label = (text)vertex_vertex_label(ver);
96  list sens = text_sentences(ver_label);
97  sentence ver_first_sen = SENTENCE(CAR(sens));
98  string ver_name = first_word_of_sentence(ver_first_sen);
99  string ver_real_name = remove_newline_of_string(ver_name);
100  if (same_string_p(ver_real_name, str_name) || same_string_p(ver_name, str_name)) {
101  free(ver_real_name);
102  return ver;
103  } else
104  free(ver_real_name);
105  }, l_of_vers);
106  return vertex_undefined;
107 }
void free(void *)
#define vertex_undefined
Definition: graph.h:128
#define vertex_vertex_label(x)
Definition: graph.h:152
#define VERTEX(x)
VERTEX.
Definition: graph.h:122
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
Definition: newgen_list.h:226
string remove_newline_of_string(string)
Definition: string.c:309
#define same_string_p(s1, s2)
int sens
facteur multiplicatif suivant qu'on analyse un terme
Definition: sc_gram.c:100
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
string first_word_of_sentence(sentence s)
Return the first word of a sentence:
Definition: util.c:76
struct _newgen_struct_text_ * text
Definition: text.h:23
#define SENTENCE(x)
newgen_unformatted_domain_defined
Definition: text.h:36
#define text_sentences(x)
Definition: text.h:113

References CAR, first_word_of_sentence(), free(), MAP, remove_newline_of_string(), same_string_p, sens, SENTENCE, text_sentences, VERTEX, vertex_undefined, and vertex_vertex_label.

Referenced by call_flt(), and print_marged_text_from_starting_node().

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

◆ list_of_connected_nodes()

list list_of_connected_nodes ( vertex  ver,
list  l_of_vers 
)
Parameters
verer
l_of_vers_of_vers

Definition at line 57 of file util.c.

58 {
59  MAP(SUCCESSOR, succ, {
60  vertex ver_child = successor_vertex(succ);
61  l_of_vers = safe_add_vertex_to_list(ver_child, l_of_vers);
62  l_of_vers = list_of_connected_nodes(ver_child, l_of_vers);
63  }, vertex_successors(ver));
64  return l_of_vers;
65 }
#define successor_vertex(x)
Definition: graph.h:118
#define vertex_successors(x)
Definition: graph.h:154
#define SUCCESSOR(x)
SUCCESSOR.
Definition: graph.h:86
list list_of_connected_nodes(vertex ver, list l_of_vers)
Definition: util.c:57
list safe_add_vertex_to_list(vertex ver, list l_of_vers)
Definition: util.c:50

References list_of_connected_nodes(), MAP, safe_add_vertex_to_list(), SUCCESSOR, successor_vertex, and vertex_successors.

Referenced by list_of_connected_nodes(), and print_graph_daVinci_from_starting_node().

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

◆ make_resource_from_starting_node()

bool make_resource_from_starting_node ( const char *  mod_name,
string  res_name,
string  file_ext,
vertex  start_ver,
list  l_of_vers,
bool  res_text_type 
)

ree(dir);

this line may cause a problem of bus errone

this line must be after DB_PUT_FILE_RESOURCE for the reason of memory liberation

Parameters
mod_nameod_name
res_namees_name
file_extile_ext
start_vertart_ver
l_of_vers_of_vers
res_text_typees_text_type

Definition at line 220 of file util.c.

222 {
223  string filename, localfilename, dir;
224  FILE *fd;
225 
226  localfilename = db_build_file_resource_name(res_name, mod_name, file_ext);
228  filename = strdup(concatenate(dir, "/", localfilename, NULL));
229  /*free(dir);*/ /* this line may cause a problem of bus errone*/
230 
231  fd = safe_fopen(filename, "w");
232  if (!vertex_undefined_p(start_ver)) {
233  if (res_text_type) {
234  print_marged_text_from_starting_node(fd, 0, start_ver, l_of_vers);
235  safe_fclose(fd, filename);
236  write_an_attachment_file(filename);
237  } else {
239  safe_fclose(fd, filename);
240  }
241  }
242  DB_PUT_FILE_RESOURCE(res_name, mod_name, localfilename);
243  free(filename); /* this line must be after DB_PUT_FILE_RESOURCE for the reason of memory liberation */
244 
245  return true;
246 }
void write_an_attachment_file(string file_name)
Add the attachment in Emacs mode by creating a twin file that is decorated with Emacs properties:
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
#define vertex_undefined_p(x)
Definition: graph.h:129
#define DB_PUT_FILE_RESOURCE
Put a file resource into the current workspace database.
Definition: pipsdbm-local.h:85
void print_graph_daVinci_from_starting_node(FILE *f_out, vertex start_ver)
Definition: util.c:190
void print_marged_text_from_starting_node(FILE *fd, int margin, vertex start_ver, list l_of_vers)
Definition: util.c:200
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 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

References concatenate(), db_build_file_resource_name(), db_get_current_workspace_directory(), DB_PUT_FILE_RESOURCE, free(), print_graph_daVinci_from_starting_node(), print_marged_text_from_starting_node(), safe_fclose(), safe_fopen(), strdup(), vertex_undefined_p, and write_an_attachment_file().

Referenced by print_module_icfg().

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

◆ print_graph_daVinci_from_starting_node()

void print_graph_daVinci_from_starting_node ( FILE *  f_out,
vertex  start_ver 
)
Parameters
f_out_out
start_vertart_ver

Definition at line 190 of file util.c.

191 {
192  list l = NIL;
193  ADD_ELEMENT_TO_LIST(l, VERTEX, start_ver);
194  l = list_of_connected_nodes(start_ver, l);
196  gen_free_list(l);
197  return;
198 }
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#define ADD_ELEMENT_TO_LIST(_list, _type, _element)
Definition: icfg-local.h:50
void print_graph_of_text_to_daVinci(FILE *f_out, list l_of_vers)
Definition: util.c:134

References ADD_ELEMENT_TO_LIST, gen_free_list(), list_of_connected_nodes(), NIL, print_graph_of_text_to_daVinci(), and VERTEX.

Referenced by make_resource_from_starting_node().

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

◆ print_graph_of_text_to_daVinci()

void print_graph_of_text_to_daVinci ( FILE *  f_out,
list  l_of_vers 
)

printf(f_out, convert_string_for_daVinci_graph(s + strlen(CALL_MARK)));

Parameters
f_out_out
l_of_vers_of_vers

Definition at line 134 of file util.c.

135 {
136  bool first_node_parent = true;
137  fprintf(f_out, "[\n");
138 
139  FOREACH (VERTEX, ver_parent, l_of_vers) {
140  bool first_node_child = true;
141  text node_parent_text = (text)vertex_vertex_label(ver_parent);
142  bool first_sentence = true;
143 
144  if (first_node_parent)
145  first_node_parent = false;
146  else
147  fprintf(f_out, ",\n");
148 
149  FOREACH (SENTENCE, sen, text_sentences(node_parent_text)){
150  string s = sentence_to_string(sen);
151  if (first_sentence) {
152  string tmp = remove_newline_of_string (s);
153  fprintf(f_out, "l(\"%s\",n(\"\",[a(\"OBJECT\",\"", tmp);
154  first_sentence = false;
155  free (tmp);
156  }
157  if (strstr(s, CALL_MARK)) {
158  /*fprintf(f_out, convert_string_for_daVinci_graph(s + strlen(CALL_MARK)));*/
159  } else {
160  string r = convert_string_for_daVinci_graph(s);
161  fputs(r, f_out);
162  free(r);
163  }
164  }
165 
166  fprintf(f_out, "\")],[\n");
167 
168  FOREACH (SUCCESSOR, succ, vertex_successors(ver_parent)){
169  vertex ver_child = successor_vertex(succ);
170  text node_child_text = (text)vertex_vertex_label(ver_child);
171  sentence node_child_sen = SENTENCE(CAR(text_sentences(node_child_text)));
172  string node_name_child = remove_newline_of_string(first_word_of_sentence(node_child_sen));
173 
174  if (first_node_child)
175  first_node_child = false;
176  else
177  fprintf(f_out, ",\n");
178  fprintf(f_out, " l(\"\",e(\"\",[],r(\"%s\")))", node_name_child);
179  free(node_name_child);
180  }
181 
182  fprintf(f_out, "]))");
183  }
184 
185  fprintf(f_out, "\n]");
186 
187  return;
188 }
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
#define CALL_MARK
Definition: icfg-local.h:49
static string convert_string_for_daVinci_graph(string s)
Definition: util.c:67
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
string sentence_to_string(sentence sen)
SG: moved here from icfdg.
Definition: print.c:230

References CALL_MARK, CAR, convert_string_for_daVinci_graph(), first_word_of_sentence(), FOREACH, fprintf(), free(), remove_newline_of_string(), SENTENCE, sentence_to_string(), SUCCESSOR, successor_vertex, text_sentences, VERTEX, vertex_successors, and vertex_vertex_label.

Referenced by print_graph_daVinci_from_starting_node().

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

◆ print_marged_text_from_starting_node()

void print_marged_text_from_starting_node ( FILE *  fd,
int  margin,
vertex  start_ver,
list  l_of_vers 
)

if s in not empty, ok write out

Parameters
fdd
marginargin
start_vertart_ver
l_of_vers_of_vers

Definition at line 200 of file util.c.

201 {
202  if (!vertex_undefined_p(start_ver)) {
203  text txt = (text)vertex_vertex_label(start_ver);
204  MAP(SENTENCE, sen, {
205  string s = sentence_to_string(sen);
206  string call_mark = strstr(s, CALL_MARK);
207  if(call_mark) {
208  vertex ver_child = get_vertex_by_string(call_mark + strlen(CALL_MARK), l_of_vers);
209  print_marged_text_from_starting_node(fd, margin + (call_mark - s), ver_child, l_of_vers);
210  } else if (strlen(s)) { /* if s in not empty, ok write out */
211  string tmp = remove_newline_of_string(s);
212  fprintf(fd, "%*s%s\n", margin, "", tmp);
213  free (tmp);
214  }
215  }, text_sentences(txt));
216  }
217  return;
218 }
vertex get_vertex_by_string(const char *str_name, list l_of_vers)
Definition: util.c:92

References CALL_MARK, fprintf(), free(), get_vertex_by_string(), MAP, print_marged_text_from_starting_node(), remove_newline_of_string(), SENTENCE, sentence_to_string(), text_sentences, vertex_undefined_p, and vertex_vertex_label.

Referenced by make_resource_from_starting_node(), and print_marged_text_from_starting_node().

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

◆ safe_add_vertex_to_list()

list safe_add_vertex_to_list ( vertex  ver,
list  l_of_vers 
)
Parameters
verer
l_of_vers_of_vers

Definition at line 50 of file util.c.

51 {
52  if (!gen_in_list_p(ver, l_of_vers))
53  ADD_ELEMENT_TO_LIST(l_of_vers, VERTEX, ver);
54  return l_of_vers;
55 }
bool gen_in_list_p(const void *vo, const list lx)
tell whether vo belongs to lx
Definition: list.c:734

References ADD_ELEMENT_TO_LIST, gen_in_list_p(), and VERTEX.

Referenced by list_of_connected_nodes(), print_module_icfg(), and safe_make_successor().

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

◆ safe_free_vertex()

void safe_free_vertex ( vertex  ver,
list  l_of_vers 
)

util.c

Parameters
verer
l_of_vers_of_vers

Definition at line 43 of file util.c.

44 {
45  if (!gen_in_list_p(ver, l_of_vers))
46  free_vertex(ver);
47  return;
48 }
void free_vertex(vertex p)
Definition: graph.c:107

References free_vertex(), and gen_in_list_p().

Referenced by print_module_icfg().

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

◆ safe_make_successor()

list safe_make_successor ( vertex  ver_parent,
vertex  ver_child,
list  l_of_vers 
)

search if it was made yet, do not make

if it was not made, do it

add vertex parent to the list of vertex

Parameters
ver_parenter_parent
ver_childer_child
l_of_vers_of_vers

Definition at line 110 of file util.c.

111 {
112  successor succ;
113  sentence ver_child_first_sen = SENTENCE(CAR(text_sentences((text)vertex_vertex_label(ver_child))));
114  string ver_child_name = first_word_of_sentence(ver_child_first_sen);
115 
116  /* search if it was made yet, do not make */
117  MAP(SUCCESSOR, succ, {
118  vertex ver = successor_vertex(succ);
119  sentence ver_first_sen = SENTENCE(CAR(text_sentences((text)vertex_vertex_label(ver))));
120  string ver_name = first_word_of_sentence(ver_first_sen);
121  if (same_string_p(ver_name, ver_child_name)) return l_of_vers;
122  }, vertex_successors(ver_parent));
123 
124  /* if it was not made, do it */
125  succ = make_successor(NULL, ver_child);
126  ADD_ELEMENT_TO_LIST(vertex_successors(ver_parent), SUCCESSOR, succ);
127  /* add vertex parent to the list of vertex */
128  l_of_vers = safe_add_vertex_to_list(ver_parent, l_of_vers);
129 
130  return l_of_vers;
131 }
successor make_successor(arc_label a1, vertex a2)
Definition: graph.c:98

References ADD_ELEMENT_TO_LIST, CAR, first_word_of_sentence(), make_successor(), MAP, safe_add_vertex_to_list(), same_string_p, SENTENCE, SUCCESSOR, successor_vertex, text_sentences, vertex_successors, and vertex_vertex_label.

Referenced by call_flt().

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