OpenScop  0.9.0
textual.c
Go to the documentation of this file.
1 
2  /*+-----------------------------------------------------------------**
3  ** OpenScop Library **
4  **-----------------------------------------------------------------**
5  ** extensions/textual.c **
6  **-----------------------------------------------------------------**
7  ** First version: 15/17/2010 **
8  **-----------------------------------------------------------------**
9 
10 
11  *****************************************************************************
12  * OpenScop: Structures and formats for polyhedral tools to talk together *
13  *****************************************************************************
14  * ,___,,_,__,,__,,__,,__,,_,__,,_,__,,__,,___,_,__,,_,__, *
15  * / / / // // // // / / / // // / / // / /|,_, *
16  * / / / // // // // / / / // // / / // / / / /\ *
17  * |~~~|~|~~~|~~~|~~~|~~~|~|~~~|~|~~~|~~~|~~~|~|~~~|~|~~~|/_/ \ *
18  * | G |C| P | = | L | P |=| = |C| = | = | = |=| = |=| C |\ \ /\ *
19  * | R |l| o | = | e | l |=| = |a| = | = | = |=| = |=| L | \# \ /\ *
20  * | A |a| l | = | t | u |=| = |n| = | = | = |=| = |=| o | |\# \ \ *
21  * | P |n| l | = | s | t |=| = |d| = | = | = | | |=| o | | \# \ \ *
22  * | H | | y | | e | o | | = |l| | | = | | | | G | | \ \ \ *
23  * | I | | | | e | | | | | | | | | | | | | \ \ \ *
24  * | T | | | | | | | | | | | | | | | | | \ \ \ *
25  * | E | | | | | | | | | | | | | | | | | \ \ \ *
26  * | * |*| * | * | * | * |*| * |*| * | * | * |*| * |*| * | / \* \ \ *
27  * | O |p| e | n | S | c |o| p |-| L | i | b |r| a |r| y |/ \ \ / *
28  * '---'-'---'---'---'---'-'---'-'---'---'---'-'---'-'---' '--' *
29  * *
30  * Copyright (C) 2008 University Paris-Sud 11 and INRIA *
31  * *
32  * (3-clause BSD license) *
33  * Redistribution and use in source and binary forms, with or without *
34  * modification, are permitted provided that the following conditions *
35  * are met: *
36  * *
37  * 1. Redistributions of source code must retain the above copyright notice, *
38  * this list of conditions and the following disclaimer. *
39  * 2. Redistributions in binary form must reproduce the above copyright *
40  * notice, this list of conditions and the following disclaimer in the *
41  * documentation and/or other materials provided with the distribution. *
42  * 3. The name of the author may not be used to endorse or promote products *
43  * derived from this software without specific prior written permission. *
44  * *
45  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR *
46  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES *
47  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. *
48  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, *
49  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT *
50  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
51  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
52  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
53  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF *
54  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
55  * *
56  * OpenScop Library, a library to manipulate OpenScop formats and data *
57  * structures. Written by: *
58  * Cedric Bastoul <Cedric.Bastoul@u-psud.fr> and *
59  * Louis-Noel Pouchet <Louis-Noel.pouchet@inria.fr> *
60  * *
61  *****************************************************************************/
62 
63 #include <stdlib.h>
64 #include <stdio.h>
65 #include <string.h>
66 
67 #include <osl/macros.h>
68 #include <osl/util.h>
69 #include <osl/interface.h>
70 #include <osl/extensions/textual.h>
71 
72 
73 /* CAUTION : TEXTUAL IS A VERY SPECIAL CASE: DO NOT USE IT AS AN EXAMPLE !!! */
74 
75 
76 /*+***************************************************************************
77  * Structure display function *
78  *****************************************************************************/
79 
80 
91 void osl_textual_idump(FILE * file, osl_textual_p textual, int level) {
92  int j;
93  char * tmp;
94 
95  // Go to the right level.
96  for (j = 0; j < level; j++)
97  fprintf(file, "|\t");
98 
99  if (textual != NULL) {
100  fprintf(file, "+-- osl_textual_t: ");
101 
102  // Display the textual message (without any carriage return).
103  OSL_strdup(tmp, textual->textual);
104  for (j = 0; j < (int)strlen(tmp); j++)
105  if (tmp[j] == '\n')
106  tmp[j] = ' ';
107 
108  if (strlen(tmp) > 40) {
109  for (j = 0; j < 20; j++)
110  fprintf(file, "%c", tmp[j]);
111  fprintf(file, " ... ");
112  for (j = (int)strlen(tmp) - 20; j < (int)strlen(tmp); j++)
113  fprintf(file, "%c", tmp[j]);
114  fprintf(file, "\n");
115  }
116  else {
117  fprintf(file,"%s\n", tmp);
118  }
119  free(tmp);
120  }
121  else {
122  fprintf(file, "+-- NULL textual\n");
123  }
124 
125  // The last line.
126  for (j = 0; j <= level; j++)
127  fprintf(file, "|\t");
128  fprintf(file, "\n");
129 }
130 
131 
139 void osl_textual_dump(FILE * file, osl_textual_p textual) {
140  osl_textual_idump(file, textual, 0);
141 }
142 
143 
144 
145 #if 0
146 
154  char * string = NULL;
155 
156  if ((textual != NULL) && (textual->textual != NULL)) {
157  if (strlen(textual->textual) > OSL_MAX_STRING)
158  OSL_error("textual too long");
159 
160  string = strdup(textual->textual);
161  if (string == NULL)
162  OSL_error("memory overflow");
163  }
164 
165  return string;
166 }
167 #else
168 
176 char * osl_textual_sprint(osl_textual_p textual) {
177 
178  return NULL;
179 }
180 #endif
181 
182 
183 /*****************************************************************************
184  * Reading function *
185  *****************************************************************************/
186 
187 
197 osl_textual_p osl_textual_sread(char ** extensions) {
198  osl_textual_p textual = NULL;
199 
200  if (*extensions != NULL) {
201  textual = osl_textual_malloc();
202  OSL_strdup(textual->textual, *extensions);
203 
204  // Update the input string pointer to the end of the string (since
205  // everything has been read).
206  *extensions = *extensions + strlen(*extensions);
207  }
208 
209  return textual;
210 }
211 
212 
213 /*+***************************************************************************
214  * Memory allocation/deallocation function *
215  *****************************************************************************/
216 
217 
227  osl_textual_p textual;
228 
229  OSL_malloc(textual, osl_textual_p, sizeof(osl_textual_t));
230  textual->textual = NULL;
231 
232  return textual;
233 }
234 
235 
243  if (textual != NULL) {
244  if(textual->textual != NULL)
245  free(textual->textual);
246  free(textual);
247  }
248 }
249 
250 
251 /*+***************************************************************************
252  * Processing functions *
253  *****************************************************************************/
254 
255 
264  osl_textual_p clone;
265 
266  if (textual == NULL)
267  return NULL;
268 
269  clone = osl_textual_malloc();
270  OSL_strdup(clone->textual, textual->textual);
271 
272  return clone;
273 }
274 
275 
276 #if 0
277 
286 
287  if (f1 == f2)
288  return 1;
289 
290  if (((f1 == NULL) && (f2 != NULL)) || ((f1 != NULL) && (f2 == NULL)))
291  return 0;
292 
293  if (strcmp(f1->textual, f2->textual))
294  return 0;
295 
296  return 1;
297 }
298 #else
299 
309 
310  return 1;
311 }
312 #endif
313 
314 
323 
324  OSL_strdup(interface->URI, OSL_URI_TEXTUAL);
325  interface->idump = (osl_idump_f)osl_textual_idump;
326  interface->sprint = (osl_sprint_f)osl_textual_sprint;
327  interface->sread = (osl_sread_f)osl_textual_sread;
328  interface->malloc = (osl_malloc_f)osl_textual_malloc;
329  interface->free = (osl_free_f)osl_textual_free;
330  interface->clone = (osl_clone_f)osl_textual_clone;
331  interface->equal = (osl_equal_f)osl_textual_equal;
332 
333  return interface;
334 }
335 
osl_textual_p osl_textual_malloc()
Definition: textual.c:226
void *(* osl_clone_f)(void *)
Definition: interface.h:80
char * textual
Definition: textual.h:85
osl_interface_p osl_interface_malloc()
Definition: interface.c:212
osl_interface_p osl_textual_interface()
Definition: textual.c:321
osl_textual_p osl_textual_sread(char **extensions)
Definition: textual.c:197
void osl_textual_idump(FILE *file, osl_textual_p textual, int level)
Definition: textual.c:91
void *(* osl_sread_f)(char **)
Definition: interface.h:77
int osl_textual_equal(osl_textual_p f1, osl_textual_p f2)
Definition: textual.c:285
void(* osl_idump_f)(FILE *, void *, int)
Definition: interface.h:75
osl_textual_p osl_textual_clone(osl_textual_p textual)
Definition: textual.c:263
void osl_textual_free(osl_textual_p textual)
Definition: textual.c:242
char *(* osl_sprint_f)(void *)
Definition: interface.h:76
void *(* osl_malloc_f)()
Definition: interface.h:78
char * osl_textual_sprint(osl_textual_p textual)
Definition: textual.c:153
void osl_textual_dump(FILE *file, osl_textual_p textual)
Definition: textual.c:139
int(* osl_equal_f)(void *, void *)
Definition: interface.h:81
void(* osl_free_f)(void *)
Definition: interface.h:79