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

Go to the source code of this file.

Macros

#define LINE_SUFFIX   "\n"
 

Functions

char * int2a (int i)
 util.c More...
 
char * f2a (float f)
 
void add_one_unformated_printf_to_text (text r, string a_format,...)
 
string first_word_of_sentence (sentence s)
 Return the first word of a sentence: More...
 
string last_word_of_sentence (sentence s)
 Return the last word of a sentence: More...
 
static int last_comma_or_clopar (string s)
 returns a possible index where to cut the string. More...
 
void add_to_current_line (string buffer, const char *append, string continuation, text txt)
 
void close_current_line (string buffer, text txt, string continuation)
 
void add_words_to_text (text t, list wl)
 Add the word list wl to the end of the last sentence of text t. More...
 

Macro Definition Documentation

◆ LINE_SUFFIX

#define LINE_SUFFIX   "\n"

Definition at line 125 of file util.c.

Function Documentation

◆ add_one_unformated_printf_to_text()

void add_one_unformated_printf_to_text ( text  r,
string  a_format,
  ... 
)

beurk

Parameters
a_format_format

Definition at line 59 of file util.c.

61 {
62  /* beurk */
63  char *buffer;
64  va_list some_arguments;
65  va_start(some_arguments, a_format);
66  int ret = vasprintf(&buffer, a_format, some_arguments);
67  pips_assert("vasprintf is ok", ret >= 0);
69  buffer));
70  va_end(some_arguments);
71 }
sentence make_sentence(enum sentence_utype tag, void *val)
Definition: text.c:59
#define ret(why, what)
true if not a remapping for old.
Definition: dynamic.c:986
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
static string buffer
Definition: string.c:113
#define ADD_SENTENCE_TO_TEXT(t, p)
@ is_sentence_formatted
Definition: text.h:57
int vasprintf(char **resultp, const char *format, va_list args)
Formatted output to strings.
Definition: vasprintf.c:33

References ADD_SENTENCE_TO_TEXT, buffer, is_sentence_formatted, make_sentence(), pips_assert, ret, and vasprintf().

Referenced by ensure_comment_consistency().

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

◆ add_to_current_line()

void add_to_current_line ( string  buffer,
const char *  append,
string  continuation,
text  txt 
)

special case: appends a sole "," on end of line...

2 = strlen("\n\0")

cannot append the string. must go next line.

save the end of the line

trunc!

happend new line.

now regenerate the beginning of the line

get back saved part

current line + new line are too large. Try to append the buffer alone, before trying to add the new line alone

Append the new line

this shouldn't happen. it can occur if lappend+lcontinuation is too large.

Cut the comment

G: warning: I removed the const modifier here

Parameters
bufferuffer
appendcurrent line being processed
continuationstring to add to this line
txtprefix when breaking a line where to append completed lines

Definition at line 140 of file util.c.

145 {
146  bool divide;
147  char tmp[MAX_LINE_LENGTH];
148  int last_cut;
149  int lappend;
150  int lbuffer = strlen(buffer);
151  bool comment = false;
152  char stmp;
153  /* special case: appends a sole "," on end of line... */
154  if (same_string_p(append, ", ") && lbuffer+3==MAX_LINE_LENGTH)
155  append = ",";
156 
157  lappend = strlen(append);
158 
159 
160  if (lbuffer + lappend + 2 > MAX_LINE_LENGTH) /* 2 = strlen("\n\0") */
161  {
162  /* cannot append the string. must go next line.
163  */
164  last_cut = last_comma_or_clopar(buffer);
165 
166  divide = (last_cut > 0)
167  && (last_cut != lbuffer-1)
168  && (lbuffer - last_cut + lappend +strlen(continuation)
169  < MAX_LINE_LENGTH - 2);
170 
171  if (divide)
172  {
173  int nl_cut = last_cut;
174  while (buffer[nl_cut+1]==' ') nl_cut++;
175  strcpy(tmp, buffer+nl_cut+1); /* save the end of the line */
176  buffer[last_cut+1] = '\0'; /* trunc! */
177  }
178 
179  /* happend new line. */
180  strcat(buffer, LINE_SUFFIX);
183 
184  /* now regenerate the beginning of the line */
185  strcpy(buffer, continuation);
186 
187  if (divide) {
188  strcat(buffer, tmp); /* get back saved part */
189 
190  if (strlen(buffer) + lappend + 2 > MAX_LINE_LENGTH
192  /* current line + new line are too large. Try to append the
193  buffer alone, before trying to add the new line alone */
194  strcat(buffer, LINE_SUFFIX);
197  strcpy(buffer, continuation);
198  }
199  }
200 
201  }
202 
203  /* Append the new line */
204  lbuffer = strlen(buffer);
205  stmp = continuation[0];
206  comment = (stmp == 'c'|| stmp == 'C' || stmp == '!'|| stmp == '*'
207  || (continuation[0] == '/' && continuation[1] == '/')
208  || (continuation[0] == '/' && continuation[1] == '*'));
209 
210  if (strlen(buffer) + lappend + 2 > MAX_LINE_LENGTH) {
211  /* this shouldn't happen.
212  * it can occur if lappend+lcontinuation is too large.
213  */
214  if (comment) {
215  /* Cut the comment */
216  int coupure = MAX_LINE_LENGTH-2 -lbuffer;
217  char tmp2[2*MAX_LINE_LENGTH];
218  strcpy(tmp2,append+coupure);
219  /*SG: warning: I removed the const modifier here */
220  ((char*)append)[coupure]='\0';
221 
224 
225  }
226  else
227  pips_internal_error("line code too large...");
228  }
229  else if (! same_string_p(append, " ")
231  strcat(buffer, append);
232 }
#define append(s)
text text_region_no_action(effect reg) input : a region output : a text consisting of several lines o...
Definition: prettyprint.c:77
#define divide(a, b)
#define continuation
Definition: prettyprint.c:102
static void comment(string_buffer code, spoc_hardware_type hw, dagvtx v, int stage, int side, bool flip)
Definition: freia_spoc.c:52
#define pips_internal_error
Definition: misc-local.h:149
#define same_string_p(s1, s2)
char * strdup()
#define MAX_LINE_LENGTH
maximum length of a line when prettyprinting...
void add_to_current_line(string buffer, const char *append, string continuation, text txt)
Definition: util.c:140
static int last_comma_or_clopar(string s)
returns a possible index where to cut the string.
Definition: util.c:130
#define LINE_SUFFIX
Definition: util.c:125

References ADD_SENTENCE_TO_TEXT, add_to_current_line(), append, buffer, comment(), continuation, divide, is_sentence_formatted, last_comma_or_clopar(), LINE_SUFFIX, make_sentence(), MAX_LINE_LENGTH, pips_internal_error, same_string_p, and strdup().

Referenced by add_separation(), add_to_current_line(), add_Value_to_current_line(), close_current_line(), constante_to_textline(), contrainte_to_text_2(), contraintes_text_format(), entity_list_text_format(), signed_operation_to_textline(), system_sorted_text_format(), text_directive(), and unsigned_operation_to_textline().

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

◆ add_words_to_text()

void add_words_to_text ( text  t,
list  wl 
)

Add the word list wl to the end of the last sentence of text t.

Parameters
wll

Definition at line 273 of file util.c.

274 {
275  list sl = text_sentences(t);
276 
277  if(ENDP(sl)) {
278  pips_internal_error("what kind of sentence to make?");
279  }
280  else {
281  sentence s = SENTENCE(CAR(gen_last(sl)));
282  if(sentence_formatted_p(s)) {
283  pips_internal_error("Not implemented");
284  }
285  else {
288  }
289  }
290  pips_assert("t is consistent", text_consistent_p(t));
291 }
bool text_consistent_p(text p)
Definition: text.c:80
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
list gen_last(list l)
Return the last element of a list.
Definition: list.c:578
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define SENTENCE(x)
newgen_unformatted_domain_defined
Definition: text.h:36
#define sentence_unformatted(x)
Definition: text.h:81
#define text_sentences(x)
Definition: text.h:113
#define unformatted_words(x)
Definition: text.h:155
#define sentence_formatted_p(x)
Definition: text.h:76

References CAR, ENDP, gen_last(), gen_nconc(), pips_assert, pips_internal_error, SENTENCE, sentence_formatted_p, sentence_unformatted, text_consistent_p(), text_sentences, and unformatted_words.

Referenced by c_text_related_entities().

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

◆ close_current_line()

void close_current_line ( string  buffer,
text  txt,
string  continuation 
)

do not append an empty line to text

Parameters
bufferuffer
txtxt
continuationontinuation

Definition at line 235 of file util.c.

239 {
240  if (strlen(buffer)!=0) /* do not append an empty line to text */ {
241  int lbuffer=0;
242  char stmp = continuation[0];
243  char stmp1 = continuation[1];
244  bool comment = stmp == 'c'|| stmp == 'C'
245  || stmp == '!'|| stmp == '*'
246  || (stmp == '/' && stmp1 == '*') || (stmp == '/' && stmp1 == '/');
247 
248  if ((lbuffer=strlen(buffer))+2>MAX_LINE_LENGTH) {
249  if (comment) {
250  int coupure = MAX_LINE_LENGTH-2;
251  char tmp2[2*MAX_LINE_LENGTH];
252  strcpy(tmp2,buffer+coupure);
253  buffer[coupure]='\0';
254 
258  }
259  else
260  pips_assert("buffer is too large",
261  strlen(buffer)+1<MAX_LINE_LENGTH);
262  }
263  else {
264  strcat(buffer, LINE_SUFFIX);
267  buffer[0] = '\0';
268  }
269  }
270 }
void close_current_line(string buffer, text txt, string continuation)
Definition: util.c:235

References ADD_SENTENCE_TO_TEXT, add_to_current_line(), buffer, close_current_line(), comment(), continuation, is_sentence_formatted, LINE_SUFFIX, make_sentence(), MAX_LINE_LENGTH, pips_assert, and strdup().

Referenced by close_current_line(), text_continuation(), text_directive(), text_pointer_value(), text_points_to_relation(), text_region_no_action(), and text_transformer().

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

◆ f2a()

char* f2a ( float  f)

Definition at line 51 of file util.c.

52 {
53  char *buffer;
54  asprintf(&buffer, "%f", f);
55  return buffer;
56 }
#define asprintf
Definition: misc-local.h:225
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15

References asprintf, buffer, and f().

+ Here is the call graph for this function:

◆ first_word_of_sentence()

string first_word_of_sentence ( sentence  s)

Return the first word of a sentence:

The sentence is seen as a big word:

From the first word to the last one. Label should is skipped:

Definition at line 76 of file util.c.

77 {
78  string begin = string_undefined;
79 
80  if (sentence_formatted_p(s))
81  /* The sentence is seen as a big word: */
82  begin = sentence_formatted(s);
83  else if (sentence_unformatted_p(s)) {
85  /* From the first word to the last one. Label should is
86  skipped: */
87  begin = STRING(CAR(l));
88  }
89  else {
90  pips_assert("s should be formatted or unformatted...", 0);
91  // redundant... to avoid a warning
92  abort();
93  }
94 
95  return begin;
96 }
#define STRING(x)
Definition: genC.h:87
#define abort()
Definition: misc-local.h:53
#define string_undefined
Definition: newgen_types.h:40
#define sentence_unformatted_p(x)
Definition: text.h:79
#define sentence_formatted(x)
Definition: text.h:78

References abort, CAR, pips_assert, sentence_formatted, sentence_formatted_p, sentence_unformatted, sentence_unformatted_p, STRING, string_undefined, and unformatted_words.

Referenced by attach_to_sentence_list(), get_vertex_by_string(), print_graph_of_text_to_daVinci(), and safe_make_successor().

+ Here is the caller graph for this function:

◆ int2a()

◆ last_comma_or_clopar()

static int last_comma_or_clopar ( string  s)
static

returns a possible index where to cut the string.

0 if none.

Definition at line 130 of file util.c.

131 {
132  int last = 0, i;
133  for (i=strlen(s)-1; i>0 && !last; i--)
134  if (s[i] == ',' || s[i]==')')
135  last = i;
136  return last;
137 }

Referenced by add_to_current_line().

+ Here is the caller graph for this function:

◆ last_word_of_sentence()

string last_word_of_sentence ( sentence  s)

Return the last word of a sentence:

The sentence is seen as a big word:

From the first word to the last one. Label should is skipped:

Definition at line 101 of file util.c.

102 {
103  string end = string_undefined;
104 
105  if (sentence_formatted_p(s))
106  /* The sentence is seen as a big word: */
107  end = sentence_formatted(s);
108  else if (sentence_unformatted_p(s)) {
110  /* From the first word to the last one. Label should is
111  skipped: */
112  end = STRING(CAR(gen_last(l)));
113  }
114  else {
115  pips_assert("s should be formatted or unformatted...", 0);
116  // redundant... to avoid a warning
117  abort();
118  }
119 
120  return end;
121 }
char end
Definition: gtk_status.c:82

References abort, CAR, end, gen_last(), pips_assert, sentence_formatted, sentence_formatted_p, sentence_unformatted, sentence_unformatted_p, STRING, string_undefined, and unformatted_words.

Referenced by attach_to_sentence_list().

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