OpenScop  0.9.0
clay.c
Go to the documentation of this file.
1 
2  /*+-----------------------------------------------------------------**
3  ** OpenScop Library **
4  **-----------------------------------------------------------------**
5  ** extensions/clay.c **
6  **-----------------------------------------------------------------**
7  ** First version: 09/05/2012 **
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/clay.h>
71 
72 
73 /*+***************************************************************************
74  * Structure display function *
75  *****************************************************************************/
76 
77 
88 void osl_clay_idump(FILE * file, osl_clay_p clay, int level) {
89  int j;
90  size_t l;
91  char * tmp;
92 
93  // Go to the right level.
94  for (j = 0; j < level; j++)
95  fprintf(file, "|\t");
96 
97  if (clay != NULL)
98  fprintf(file, "+-- osl_clay_t\n");
99  else
100  fprintf(file, "+-- NULL clay\n");
101 
102  if (clay != NULL) {
103  // Go to the right level.
104  for(j = 0; j <= level; j++)
105  fprintf(file, "|\t");
106 
107  // Display the clay script (without any carriage return).
108  OSL_strdup(tmp, clay->script);
109  for (l = 0; l < strlen(tmp); l++)
110  if (tmp[l] == '\n')
111  tmp[l] = ' ';
112  fprintf(file, "script: %s\n", tmp);
113  free(tmp);
114  }
115 
116  // The last line.
117  for (j = 0; j <= level; j++)
118  fprintf(file, "|\t");
119  fprintf(file, "\n");
120 }
121 
122 
130 void osl_clay_dump(FILE * file, osl_clay_p clay) {
131  osl_clay_idump(file, clay, 0);
132 }
133 
134 
143  int high_water_mark = OSL_MAX_STRING;
144  char * string = NULL;
145  char buffer[OSL_MAX_STRING];
146 
147  if (clay != NULL) {
148  OSL_malloc(string, char *, high_water_mark * sizeof(char));
149  string[0] = '\0';
150 
151  // Print the clay.
152  sprintf(buffer, "%s", clay->script);
153  osl_util_safe_strcat(&string, buffer, &high_water_mark);
154 
155  // Keep only the memory space we need.
156  OSL_realloc(string, char *, (strlen(string) + 1) * sizeof(char));
157  }
158 
159  return string;
160 }
161 
162 
163 /*****************************************************************************
164  * Reading function *
165  *****************************************************************************/
166 
167 
178 osl_clay_p osl_clay_sread(char ** input) {
179  osl_clay_p clay;
180  char * script;
181 
182  if (*input == NULL) {
183  OSL_debug("no clay optional tag");
184  return NULL;
185  }
186 
187  if (strlen(*input) > OSL_MAX_STRING)
188  OSL_error("clay script too long");
189 
190  // Build the clay structure
191  clay = osl_clay_malloc();
192  script = *input;
193 
194  // Pass the carriage returns (this allows to remove those inserted by
195  // osl_generic_print), and copy the textual script.
196  while (*script && (*script == '\n'))
197  script++;
198  OSL_strdup(clay->script, script);
199 
200  // Update the input pointer (everything has been read).
201  input += strlen(*input);
202 
203  return clay;
204 }
205 
206 
207 /*+***************************************************************************
208  * Memory allocation/deallocation function *
209  *****************************************************************************/
210 
211 
221  osl_clay_p clay;
222 
223  OSL_malloc(clay, osl_clay_p, sizeof(osl_clay_t));
224  clay->script = NULL;
225 
226  return clay;
227 }
228 
229 
237  if (clay != NULL) {
238  if(clay->script != NULL)
239  free(clay->script);
240  free(clay);
241  }
242 }
243 
244 
245 /*+***************************************************************************
246  * Processing functions *
247  *****************************************************************************/
248 
249 
258  osl_clay_p clone;
259 
260  if (clay == NULL)
261  return NULL;
262 
263  clone = osl_clay_malloc();
264  OSL_strdup(clone->script, clay->script);
265 
266  return clone;
267 }
268 
269 
279  if (c1 == c2)
280  return 1;
281 
282  if (((c1 == NULL) && (c2 != NULL)) || ((c1 != NULL) && (c2 == NULL))) {
283  OSL_info("clay extensions are not the same");
284  return 0;
285  }
286 
287  if (strcmp(c1->script, c2->script)) {
288  OSL_info("clay scripts are not the same");
289  return 0;
290  }
291 
292  return 1;
293 }
294 
295 
304 
305  OSL_strdup(interface->URI, OSL_URI_CLAY);
306  interface->idump = (osl_idump_f)osl_clay_idump;
307  interface->sprint = (osl_sprint_f)osl_clay_sprint;
308  interface->sread = (osl_sread_f)osl_clay_sread;
309  interface->malloc = (osl_malloc_f)osl_clay_malloc;
310  interface->free = (osl_free_f)osl_clay_free;
311  interface->clone = (osl_clone_f)osl_clay_clone;
312  interface->equal = (osl_equal_f)osl_clay_equal;
313 
314  return interface;
315 }
osl_interface_p osl_clay_interface()
Definition: clay.c:302
void *(* osl_clone_f)(void *)
Definition: interface.h:80
Definition: clay.h:83
int osl_clay_equal(osl_clay_p c1, osl_clay_p c2)
Definition: clay.c:278
osl_clay_p osl_clay_malloc()
Definition: clay.c:220
osl_interface_p osl_interface_malloc()
Definition: interface.c:212
osl_clay_p osl_clay_sread(char **input)
Definition: clay.c:178
void *(* osl_sread_f)(char **)
Definition: interface.h:77
void osl_util_safe_strcat(char **dst, char *src, int *hwm)
Definition: util.c:483
void osl_clay_idump(FILE *file, osl_clay_p clay, int level)
Definition: clay.c:88
void(* osl_idump_f)(FILE *, void *, int)
Definition: interface.h:75
void osl_clay_free(osl_clay_p clay)
Definition: clay.c:236
char * script
Definition: clay.h:84
char *(* osl_sprint_f)(void *)
Definition: interface.h:76
void osl_clay_dump(FILE *file, osl_clay_p clay)
Definition: clay.c:130
char * osl_clay_sprint(osl_clay_p clay)
Definition: clay.c:142
void *(* osl_malloc_f)()
Definition: interface.h:78
int(* osl_equal_f)(void *, void *)
Definition: interface.h:81
osl_clay_p osl_clay_clone(osl_clay_p clay)
Definition: clay.c:257
void(* osl_free_f)(void *)
Definition: interface.h:79