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

Go to the source code of this file.

Macros

#define MAX_END_COLUMN_F77   (72)
 print_sentence: More...
 
#define MAX_END_COLUMN_F95   (132)
 
#define MAX_END_COLUMN_DEFAULT   (INT_MAX/2)
 Define a huge line size value because the previous one (999) was too small for PIPS generated declarations after the outliner. More...
 
#define MAX_START_COLUMN   (42)
 
#define C_STATEMENT_LINE_COLUMN   (71)
 
#define C_STATEMENT_LINE_STEP   (15)
 

Functions

static void print_sentence_init ()
 Before using print_sentence: More...
 
static char putc_sentence (char c, FILE *fd)
 Output functions that tracks the number of output characters: More...
 
static int fprintf_sentence (FILE *fd, char *a_format,...)
 
void print_sentence (FILE *fd, sentence s)
 cproto-generated files More...
 
void print_text (FILE *fd, text t)
 
void dump_sentence (sentence s)
 
void dump_text (text t)
 FI: print_text() should be fprint_text() and dump_text(), print_text() More...
 
string words_join (list ls, const char *sep)
 
string words_to_string (list ls)
 Convert a word list into a string and translate the position of eventual attachment accordingly: More...
 
string sentence_to_string (sentence sen)
 SG: moved here from icfdg BUG (FC): words_to_string is malloced, but sentence_formatted is not:-(. More...
 
string text_to_string_gen (text t, bool with_newline)
 
string text_to_string (text t)
 SG: moved here from ricedg. More...
 
string text_to_string_nl (text t)
 
void print_words (FILE *fd, list lw)
 
void dump_words (list lw)
 
static void debug_word (string w)
 
void debug_words (list l)
 
static void debug_formatted (string s)
 
static void debug_unformatted (unformatted u)
 
void debug_sentence (sentence s)
 
void debug_text (text t)
 

Variables

static int position_in_the_output = 0
 FI: just to make sure that text.h is built; pips-makemake -l does not take into account a library whose modules do not use the library header. More...
 

Macro Definition Documentation

◆ C_STATEMENT_LINE_COLUMN

#define C_STATEMENT_LINE_COLUMN   (71)

Definition at line 102 of file text_print.c.

◆ C_STATEMENT_LINE_STEP

#define C_STATEMENT_LINE_STEP   (15)

Definition at line 103 of file text_print.c.

◆ MAX_END_COLUMN_DEFAULT

#define MAX_END_COLUMN_DEFAULT   (INT_MAX/2)

Define a huge line size value because the previous one (999) was too small for PIPS generated declarations after the outliner.

Do not use INT_MAX because there are some assertions such as (... < MAX_END_COLUMN_DEFAULT + 1). So (INT_MAX/2) is a rough approximation. :-)

Definition at line 100 of file text_print.c.

◆ MAX_END_COLUMN_F77

#define MAX_END_COLUMN_F77   (72)

print_sentence:

FI: I had to change this module to handle string longer than the space available on one line; I tried to preserve as much as I could of the previous behavior to avoid pseudo-hyphenation at the wrong place and to avoid extensicve problems with validate; the resulting code is lousy, of course; FI, 15 March 1993

RK: the print_sentence could print lower case letter according to a property... 17/12/1993.

Definition at line 93 of file text_print.c.

◆ MAX_END_COLUMN_F95

#define MAX_END_COLUMN_F95   (132)

Definition at line 94 of file text_print.c.

◆ MAX_START_COLUMN

#define MAX_START_COLUMN   (42)

Definition at line 101 of file text_print.c.

Function Documentation

◆ debug_formatted()

static void debug_formatted ( string  s)
static

Definition at line 487 of file text_print.c.

488 {
489  fprintf(stderr, "# formatted\n%s\n# end formatted\n", s);
490 }
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...

References fprintf().

Referenced by debug_sentence().

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

◆ debug_sentence()

void debug_sentence ( sentence  s)

Definition at line 501 of file text_print.c.

502 {
503  fprintf(stderr, "# sentence\n");
504  switch (sentence_tag(s))
505  {
508  break;
511  break;
512  default:
513  pips_internal_error("unexpected sentence tag %d", sentence_tag(s));
514  }
515 
516  fprintf(stderr,"# end sentence\n");
517 }
#define pips_internal_error
Definition: misc-local.h:149
#define sentence_unformatted(x)
Definition: text.h:81
#define sentence_formatted(x)
Definition: text.h:78
#define sentence_tag(x)
Definition: text.h:75
@ is_sentence_formatted
Definition: text.h:57
@ is_sentence_unformatted
Definition: text.h:58
static void debug_unformatted(unformatted u)
Definition: text_print.c:492
static void debug_formatted(string s)
Definition: text_print.c:487

References debug_formatted(), debug_unformatted(), fprintf(), is_sentence_formatted, is_sentence_unformatted, pips_internal_error, sentence_formatted, sentence_tag, and sentence_unformatted.

Referenced by debug_text().

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

◆ debug_text()

void debug_text ( text  t)

Definition at line 519 of file text_print.c.

520 {
521  fprintf(stderr, "# text\n");
523  fprintf(stderr,"# end text\n");
524 }
void gen_map(gen_iter_func_t fp, const list l)
Definition: list.c:172
void(* gen_iter_func_t)(void *)
Definition: newgen_types.h:116
#define text_sentences(x)
Definition: text.h:113
void debug_sentence(sentence s)
Definition: text_print.c:501

References debug_sentence(), fprintf(), gen_map(), and text_sentences.

+ Here is the call graph for this function:

◆ debug_unformatted()

static void debug_unformatted ( unformatted  u)
static

Definition at line 492 of file text_print.c.

493 {
494  fprintf(stderr, "# unformatted\n# label %s, %td, %td\n",
495  unformatted_label(u)? unformatted_label(u): "<null>",
498  fprintf(stderr, "# end unformatted\n");
499 }
#define unformatted_number(x)
Definition: text.h:151
#define unformatted_extra_margin(x)
Definition: text.h:153
#define unformatted_words(x)
Definition: text.h:155
#define unformatted_label(x)
Definition: text.h:149
void debug_words(list l)
Definition: text_print.c:481

References debug_words(), fprintf(), unformatted_extra_margin, unformatted_label, unformatted_number, and unformatted_words.

Referenced by debug_sentence().

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

◆ debug_word()

static void debug_word ( string  w)
static

Definition at line 475 of file text_print.c.

476 {
477  fprintf(stderr, "# string--%s--\n", w? w: "<null>");
478 }

References fprintf().

Referenced by debug_words().

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

◆ debug_words()

void debug_words ( list  l)
Parameters
lof string

Definition at line 481 of file text_print.c.

482 {
484 }
static void debug_word(string w)
Definition: text_print.c:475

References debug_word(), and gen_map().

Referenced by debug_unformatted().

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

◆ dump_sentence()

void dump_sentence ( sentence  s)

Definition at line 373 of file text_print.c.

374 {
375  print_sentence(stderr, s);
376 }
void print_sentence(FILE *fd, sentence s)
cproto-generated files
Definition: text_print.c:105

References print_sentence().

+ Here is the call graph for this function:

◆ dump_text()

void dump_text ( text  t)

FI: print_text() should be fprint_text() and dump_text(), print_text()

Definition at line 380 of file text_print.c.

381 {
382  print_text(stderr, t);
383 }
void print_text(FILE *fd, text t)
Definition: text_print.c:367

References print_text().

+ Here is the call graph for this function:

◆ dump_words()

void dump_words ( list  lw)
Parameters
lww

Definition at line 467 of file text_print.c.

468 {
469  print_words(stderr, lw);
470 }
void print_words(FILE *fd, list lw)
Definition: text_print.c:460

References print_words().

+ Here is the call graph for this function:

◆ fprintf_sentence()

static int fprintf_sentence ( FILE *  fd,
char *  a_format,
  ... 
)
static

Definition at line 65 of file text_print.c.

68 {
69  va_list some_arguments;
70  int number_of_printed_char;
71 
72  va_start(some_arguments, a_format);
73  number_of_printed_char = vfprintf(fd, a_format, some_arguments);
74  va_end(some_arguments);
75 
76  position_in_the_output += number_of_printed_char;
77  return number_of_printed_char;
78 }
static int position_in_the_output
FI: just to make sure that text.h is built; pips-makemake -l does not take into account a library who...
Definition: text_print.c:45

References position_in_the_output.

Referenced by print_sentence().

+ Here is the caller graph for this function:

◆ print_sentence()

void print_sentence ( FILE *  fd,
sentence  s 
)

cproto-generated files

text_print.c

cproto-generated files

print_sentence:

FI: I had to change this module to handle string longer than the space available on one line; I tried to preserve as much as I could of the previous behavior to avoid pseudo-hyphenation at the wrong place and to avoid extensicve problems with validate; the resulting code is lousy, of course; FI, 15 March 1993

RK: the print_sentence could print lower case letter according to a property... 17/12/1993.

col: the next column number, starting from 1. it means tha columns 1 to col-1 have been output. I guess. FC.

first 6 columns (0-5)

05/08/2003 - Nga Nguyen - Add code for C prettyprinter

Keep track of the attachment against the padding:

C prettyprinter: a label cannot begin with a number so "l" is added for this case

FI: do not indent too much (9 June 1995)

Initial tabulation, if needed: do not put useless SPACEs in output file. Well, it's difficult to know if it is useful or not. The test below leads to misplaced opening braces.

& gen_length(lw)>1 && !same_string_p(STRING(CAR(lw)), "\n")

Fortran77 start on 7th column

if the string fits on the current line: no problem

if the string fits on one line: use the 88 algorithm to break as few syntactic constructs as possible

Complete current line with the statement line number, if it is significative:

prepare to cut the line

start a new line with its prefix

Special label for Cray directives

if the string has to be broken in at least two lines: new algorithmic part to avoid line overflow (FI, March 1993)

Complete the current line, but not after :-)

start a new line with its prefix but no indentation since string constants may be broken onto two lines

prepare to cut the line

Special label for Cray directives

statement line number starts at different column depending on the used language : C or fortran

fortran case right the line number on the right where characters are ignored by a f77 parser

C and F95 case, try to align the line number on the right using commentaries. The alignment is done modulo C_STATEMENT_LINE_STEP

Output the statement line number on the right end of the line:

Parameters
fdd

Definition at line 105 of file text_print.c.

105  {
107 
108 
109  if (sentence_formatted_p(s)) {
110  string ps = sentence_formatted(s);
111 
112  while(*ps) {
113  char c = *ps;
114  putc_sentence(c, fd);
116  ps++;
117  }
118  } else {
119  /* col: the next column number, starting from 1.
120  * it means tha columns 1 to col-1 have been output. I guess. FC.
121  */
122  int i, line_num = 1;
123  int col;
125  string label = unformatted_label(u);
126  int em = unformatted_extra_margin(u);
127  int n = unformatted_number(u);
128  cons *lw = unformatted_words(u);
129  int max_line_size;
130  if(lang==is_language_fortran95) {
131  max_line_size = MAX_END_COLUMN_F95;
132  } else if(lang==is_language_fortran ) {
133  max_line_size =MAX_END_COLUMN_F77;
134  } else {
135  max_line_size = MAX_END_COLUMN_DEFAULT;
136  }
137 
138  /* first 6 columns (0-5)
139  */
140  /* 05/08/2003 - Nga Nguyen - Add code for C prettyprinter */
141 
142  if (label != NULL && !string_undefined_p(label)) {
143  /* Keep track of the attachment against the padding: */
145 
146  switch(lang) {
147  case is_language_fortran:
148  fprintf_sentence(fd, "%-5s ", label);
149  break;
151  // Check that the label is non empty
152  if(*label!='\0') {
153  fprintf_sentence(fd, "%-5s ", label);
154  }
155  break;
156  case is_language_c:
157  /* C prettyprinter: a label cannot begin with a number
158  * so "l" is added for this case
159  */
160  if (strlen(label) > 0)
161  fprintf_sentence(fd, get_C_label_printf_format(label), label);
162  break;
163  default:
164  pips_internal_error("language unknown not handled");
165  }
166  } else if (lang==is_language_fortran) {
167  fprintf_sentence(fd, " ");
168  }
169 
170 
171  /* FI: do not indent too much (9 June 1995) */
172  em = (em > MAX_START_COLUMN) ? MAX_START_COLUMN : em;
173  /* Initial tabulation, if needed: do not put useless SPACEs
174  in output file.
175  Well, it's difficult to know if it is useful or not. The
176  test below leads to misplaced opening braces.
177  */
178  if (!ENDP(lw)
179  /*&& gen_length(lw)>1
180  && !same_string_p(STRING(CAR(lw)), "\n")*/)
181  for (i = 0; i < em; i++)
182  putc_sentence(' ', fd);
183 
184  col = em;
185 
186  if (lang == is_language_fortran) {
187  col = col + 7; /* Fortran77 start on 7th column */
188  }
189 
190  pips_assert("not too many columns", col <= max_line_size - 2);
191  FOREACH(string, w, lw) {
192  switch(lang) {
193  case is_language_c:
194  col += fprintf_sentence(fd, "%s", w);
195  break;
196  case is_language_fortran:
197  case is_language_fortran95: {
198  int max_space_on_a_line = max_line_size - em;
199  if(lang==is_language_fortran) {
200  max_space_on_a_line -= 7;
201  }
202 
203 
204  /* if the string fits on the current line: no problem */
205  if (col + (int) strlen(w) <= max_line_size - 2) {
207  col += fprintf_sentence(fd, "%s", w);
208  }
209  /* if the string fits on one line:
210  * use the 88 algorithm to break as few
211  * syntactic constructs as possible */
212  else if ((int)strlen(w) < max_space_on_a_line) {
213  /* Complete current line with the statement
214  line number, if it is significative: */
215  if (n > 0 && get_bool_property("PRETTYPRINT_STATEMENT_NUMBER")) {
216  for (i = col; i <= max_line_size; i++) {
217  putc_sentence(' ', fd);
218  }
219  if (lang == is_language_fortran95) {
220  fprintf_sentence(fd, "! %04d", n);
221  } else {
222  fprintf_sentence(fd, "%04d", n);
223  }
224  }
225 
226  if(lang==is_language_fortran95) {
227  /* prepare to cut the line */
228  fprintf_sentence(fd," &");
229  }
230 
231  /* start a new line with its prefix */
232  putc_sentence('\n', fd);
233 
234  if (label != (char *)NULL && !string_undefined_p(label)
235  && (strcmp(label, "CDIR$") == 0 || strcmp(label, "CDIR@")
236  == 0 || strcmp(label, "CMIC$") == 0)) {
237  pips_assert("Cray with F95 not handled",
238  lang!=is_language_fortran95);
239  /* Special label for Cray directives */
240  fprintf_sentence(fd, "%s%d", label, (++line_num) % 10);
241  } else if (lang == is_language_fortran) {
242  fprintf_sentence(fd, " &");
243  }
244 
245  for (i = 0; i < em; i++)
246  putc_sentence(' ', fd);
247 
248  if (lang == is_language_fortran) {
249  col = 7 + em;
250  } else {
251  col = em;
252  }
254  col += fprintf_sentence(fd, "%s", w);
255  }
256  /* if the string has to be broken in at least two lines:
257  * new algorithmic part
258  * to avoid line overflow (FI, March 1993) */
259  else {
260  char * line = w;
261  int ncar;
262 
263  /* Complete the current line, but not after :-) */
264  ncar = MIN(max_line_size - col + 1, (int) strlen(line));
265  ;
268  ncar);
269  fprintf_sentence(fd, "%.*s", ncar, line);
270  line += ncar;
271  col = max_line_size;
272 
273  pips_debug(9, "line to print, col=%d\n", col);
274 
275  while(strlen(line) != 0) {
276  ncar = MIN(max_line_size - 7 + 1, (int) strlen(line));
277 
278 
279  /* start a new line with its prefix but no indentation
280  * since string constants may be broken onto two lines
281  */
282  if (lang == is_language_fortran95) {
283  /* prepare to cut the line */
284  fprintf_sentence(fd, " &");
285  }
286  putc_sentence('\n', fd);
287 
288  if (label != (char *)NULL
289  && (strcmp(label, "CDIR$") == 0 || strcmp(label, "CDIR@")
290  == 0 || strcmp(label, "CMIC$") == 0)) {
291  /* Special label for Cray directives */
292  (void)fprintf_sentence(fd, "%s%d", label, (++line_num) % 10);
293  } else if (lang == is_language_fortran) {
294  (void)fprintf_sentence(fd, " &");
295  col = 7;
296  } else {
297  col = 0;
298  }
301  ncar);
302  (void)fprintf_sentence(fd, "%.*s", ncar, line);
303  line += ncar;
304  col += ncar;
305  }
306  }
307  break;
308  }
309  default:
310  pips_internal_error("Language unknown !");
311  break;
312  }
313  }
314 
315  pips_debug(9, "line completed, col=%d\n", col);
316  pips_assert("not too many columns", col <= max_line_size + 1);
317 
318  /* statement line number starts at different column depending on
319  * the used language : C or fortran
320  */
321  int column_start = 0;
322  switch (get_prettyprint_language_tag()) {
323  case is_language_fortran:
324  /* fortran case right the line number on the right where characters
325  are ignored by a f77 parser*/
326  column_start = max_line_size;
327  break;
328  case is_language_c:
330  /* C and F95 case, try to align the line number on the right using
331  * commentaries. The alignment is done modulo C_STATEMENT_LINE_STEP
332  */
333  column_start = C_STATEMENT_LINE_COLUMN;
334  while(column_start <= col)
335  column_start += C_STATEMENT_LINE_STEP;
336  break;
337  default:
338  pips_internal_error("Language unknown !");
339  break;
340  }
341 
342  /* Output the statement line number on the right end of the
343  line: */
344  if (n > 0 && get_bool_property("PRETTYPRINT_STATEMENT_NUMBER")) {
345  for (int i = col; i <= column_start; i++) {
346  putc_sentence(' ', fd);
347  }
348  switch (get_prettyprint_language_tag()) {
349  case is_language_fortran:
350  fprintf_sentence(fd, "%04d", n);
351  break;
352  case is_language_c:
353  fprintf_sentence(fd, "/*%04d*/", n);
354  break;
356  fprintf_sentence(fd, "! %04d", n);
357  break;
358  default:
359  pips_internal_error("Language unknown !");
360  break;
361  }
362  }
363  putc_sentence('\n', fd);
364  }
365 }
#define MIN(x, y)
minimum and maximum if they are defined somewhere else, they are very likely to be defined the same w...
void deal_with_attachments_in_this_string(string a_string, int position_in_the_output)
Try to find some attachments in the given string.
void deal_with_attachments_in_this_string_length(string a_string, int position_in_the_output, int a_length)
Try to find some attachments in the a_length first characters of the given string.
void deal_with_attachments_at_this_character(char *a_character, int position_in_the_output)
Try to find some attachments in the given character that are printed out.
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#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
enum language_utype get_prettyprint_language_tag()
Definition: language.c:67
string get_C_label_printf_format(const char *label)
Get the prettyprint format of a C label.
Definition: language.c:155
#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_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define string_undefined_p(s)
Definition: newgen_types.h:41
language_utype
Definition: ri.h:1565
@ is_language_fortran
Definition: ri.h:1566
@ is_language_fortran95
Definition: ri.h:1568
@ is_language_c
Definition: ri.h:1567
static int line
FLEX_SCANNER.
Definition: scanner.c:852
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define sentence_formatted_p(x)
Definition: text.h:76
static char putc_sentence(char c, FILE *fd)
Output functions that tracks the number of output characters:
Definition: text_print.c:57
#define MAX_START_COLUMN
Definition: text_print.c:101
#define MAX_END_COLUMN_F77
print_sentence:
Definition: text_print.c:93
#define MAX_END_COLUMN_F95
Definition: text_print.c:94
#define C_STATEMENT_LINE_STEP
Definition: text_print.c:103
static int fprintf_sentence(FILE *fd, char *a_format,...)
Definition: text_print.c:65
#define C_STATEMENT_LINE_COLUMN
Definition: text_print.c:102
#define MAX_END_COLUMN_DEFAULT
Define a huge line size value because the previous one (999) was too small for PIPS generated declara...
Definition: text_print.c:100

References C_STATEMENT_LINE_COLUMN, C_STATEMENT_LINE_STEP, deal_with_attachments_at_this_character(), deal_with_attachments_in_this_string(), deal_with_attachments_in_this_string_length(), ENDP, FOREACH, fprintf_sentence(), get_bool_property(), get_C_label_printf_format(), get_prettyprint_language_tag(), is_language_c, is_language_fortran, is_language_fortran95, line, MAX_END_COLUMN_DEFAULT, MAX_END_COLUMN_F77, MAX_END_COLUMN_F95, MAX_START_COLUMN, MIN, pips_assert, pips_debug, pips_internal_error, position_in_the_output, putc_sentence(), sentence_formatted, sentence_formatted_p, sentence_unformatted, string_undefined_p, unformatted_extra_margin, unformatted_label, unformatted_number, and unformatted_words.

Referenced by dump_sentence(), and print_text().

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

◆ print_sentence_init()

static void print_sentence_init ( )
static

Before using print_sentence:

Definition at line 49 of file text_print.c.

50 {
52 }

References position_in_the_output.

Referenced by print_text().

+ Here is the caller graph for this function:

◆ print_text()

void print_text ( FILE *  fd,
text  t 
)
Parameters
fdd

Definition at line 367 of file text_print.c.

368 {
370  MAP(SENTENCE, s, print_sentence(fd, s), text_sentences(t));
371 }
#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
#define SENTENCE(x)
newgen_unformatted_domain_defined
Definition: text.h:36
static void print_sentence_init()
Before using print_sentence:
Definition: text_print.c:49

References MAP, print_sentence(), print_sentence_init(), SENTENCE, and text_sentences.

Referenced by dump_text().

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

◆ print_words()

void print_words ( FILE *  fd,
list  lw 
)
Parameters
fdd
lww

Definition at line 460 of file text_print.c.

461 {
462  string s = words_to_string(lw);
463  fputs(s, fd);
464  free(s);
465 }
void free(void *)
string words_to_string(list ls)
Convert a word list into a string and translate the position of eventual attachment accordingly:
Definition: text_print.c:412

References free(), and words_to_string().

Referenced by dump_words().

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

◆ putc_sentence()

static char putc_sentence ( char  c,
FILE *  fd 
)
static

Output functions that tracks the number of output characters:

Definition at line 57 of file text_print.c.

59 {
61  return putc(c, fd);
62 }

References position_in_the_output.

Referenced by print_sentence().

+ Here is the caller graph for this function:

◆ sentence_to_string()

string sentence_to_string ( sentence  sen)

SG: moved here from icfdg BUG (FC): words_to_string is malloced, but sentence_formatted is not:-(.

SG: moved here from icfdg.

Parameters
senen

Definition at line 420 of file text_print.c.

421 {
422  if (!sentence_formatted_p(sen))
424  else
425  return sentence_formatted(sen);
426 }

References sentence_formatted, sentence_formatted_p, sentence_unformatted, unformatted_words, and words_to_string().

Referenced by text_to_string_gen().

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

◆ text_to_string()

string text_to_string ( text  t)

SG: moved here from ricedg.

Definition at line 450 of file text_print.c.

451 {
452  return text_to_string_gen(t, false);
453 }
string text_to_string_gen(text t, bool with_newline)
Definition: text_print.c:428

References text_to_string_gen().

+ Here is the call graph for this function:

◆ text_to_string_gen()

string text_to_string_gen ( text  t,
bool  with_newline 
)
Parameters
with_newlineith_newline

Definition at line 428 of file text_print.c.

429 {
431 
433  {
434  string ss = sentence_to_string(sen);
436  // try to avoid a memory leak... see comments above
437  if (sentence_unformatted_p(sen))
438  free(ss);
439  if (with_newline)
440  string_buffer_append(sb, "\n");
441  }
442 
443  string s = string_buffer_to_string(sb);
445 
446  return s;
447 }
void string_buffer_append(string_buffer, const string)
append string s (if non empty) to string buffer sb, the duplication is done if needed according to th...
string string_buffer_to_string(const string_buffer)
return malloc'ed string from string buffer sb
void string_buffer_free(string_buffer *)
free string buffer structure, also free string contents according to the dup field
Definition: string_buffer.c:82
string_buffer string_buffer_make(bool dup)
allocate a new string buffer
Definition: string_buffer.c:58
internally defined structure.
Definition: string_buffer.c:47
Definition: statement.c:4047
#define sentence_unformatted_p(x)
Definition: text.h:79
string sentence_to_string(sentence sen)
SG: moved here from icfdg BUG (FC): words_to_string is malloced, but sentence_formatted is not:-(.
Definition: text_print.c:420

References FOREACH, free(), sentence_to_string(), sentence_unformatted_p, string_buffer_append(), string_buffer_free(), string_buffer_make(), string_buffer_to_string(), and text_sentences.

Referenced by text_to_string(), and text_to_string_nl().

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

◆ text_to_string_nl()

string text_to_string_nl ( text  t)

Definition at line 455 of file text_print.c.

456 {
457  return text_to_string_gen(t, true);
458 }

References text_to_string_gen().

Referenced by ensure_comment_consistency().

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

◆ words_join()

string words_join ( list  ls,
const char *  sep 
)

1 for null termination.

computes the buffer length.

appends to the buffer...

Parameters
lss
sepep

Definition at line 385 of file text_print.c.

386 {
387  int size = 1; /* 1 for null termination. */
388  size_t sep_sz = strlen(sep);
389  string buffer, p;
390 
391  /* computes the buffer length.
392  */
393  MAP(STRING, s, size+=strlen(s)+sep_sz, ls);
394  buffer = (char*) malloc(sizeof(char)*size);
395  pips_assert("malloc ok", buffer);
396 
397  /* appends to the buffer...
398  */
399  buffer[0] = '\0';
400  p=buffer;
401  FOREACH(STRING, s,ls) {
404  p+=strlen(s);
405  p+=sep_sz;
406  }
407  return buffer;
408 }
char * strcat_word_and_migrate_attachments(char *target, const char *source)
Concatenate source to target and update the source attachments to point to the new location:
#define STRING(x)
Definition: genC.h:87
void * malloc(YYSIZE_T)
static string buffer
Definition: string.c:113

References buffer, FOREACH, malloc(), MAP, pips_assert, strcat_word_and_migrate_attachments(), and STRING.

Referenced by words_to_string().

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

◆ words_to_string()

string words_to_string ( list  ls)

Convert a word list into a string and translate the position of eventual attachment accordingly:

Parameters
lss

Definition at line 412 of file text_print.c.

413 {
414  return words_join(ls,"");
415 }
string words_join(list ls, const char *sep)
Definition: text_print.c:385

References words_join().

Referenced by print_words(), and sentence_to_string().

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

Variable Documentation

◆ position_in_the_output

int position_in_the_output = 0
static

FI: just to make sure that text.h is built; pips-makemake -l does not take into account a library whose modules do not use the library header.

Definition at line 45 of file text_print.c.

Referenced by deal_with_attachment_boundary(), deal_with_attachments_at_this_character(), deal_with_attachments_in_this_string(), deal_with_attachments_in_this_string_length(), fprintf_sentence(), print_sentence(), print_sentence_init(), and putc_sentence().