OpenScop  0.9.0
scatnames.c
Go to the documentation of this file.
1 
2  /*+-----------------------------------------------------------------**
3  ** OpenScop Library **
4  **-----------------------------------------------------------------**
5  ** extensions/scatnames.c **
6  **-----------------------------------------------------------------**
7  ** First version: 03/12/2011 **
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/strings.h>
72 
73 
74 /*+***************************************************************************
75  * Structure display function *
76  *****************************************************************************/
77 
78 
89 void osl_scatnames_idump(FILE * file, osl_scatnames_p scatnames, int level) {
90  int j;
91 
92  // Go to the right level.
93  for (j = 0; j < level; j++)
94  fprintf(file, "|\t");
95 
96  if (scatnames != NULL)
97  fprintf(file, "+-- osl_scatnames_t\n");
98  else
99  fprintf(file, "+-- NULL scatnames\n");
100 
101  if (scatnames != NULL) {
102  // Go to the right level.
103  for(j = 0; j <= level + 1; j++)
104  fprintf(file, "|\t");
105  fprintf(file, "\n");
106 
107  // Display the list of scattering names.
108  osl_strings_idump(file, scatnames->names, level + 1);
109  }
110 
111  // The last line.
112  for (j = 0; j <= level; j++)
113  fprintf(file, "|\t");
114  fprintf(file, "\n");
115 }
116 
117 
125 void osl_scatnames_dump(FILE * file, osl_scatnames_p scatnames) {
126  osl_scatnames_idump(file, scatnames, 0);
127 }
128 
129 
138  return osl_strings_sprint(scatnames->names);
139 }
140 
141 
142 /*****************************************************************************
143  * Reading function *
144  *****************************************************************************/
145 
146 
159  osl_scatnames_p scatnames = NULL;
160  osl_strings_p names = NULL;
161 
162  if (*input == NULL) {
163  OSL_debug("no scatnames optional tag");
164  return NULL;
165  }
166 
167  // Build the scatnames structure
168  names = osl_strings_sread(input);
169  if (names != NULL) {
170  scatnames = osl_scatnames_malloc();
171  scatnames->names = names;
172  }
173 
174  return scatnames;
175 }
176 
177 
178 /*+***************************************************************************
179  * Memory allocation/deallocation function *
180  *****************************************************************************/
181 
182 
192  osl_scatnames_p scatnames;
193 
194  OSL_malloc(scatnames, osl_scatnames_p, sizeof(osl_scatnames_t));
195  scatnames->names = NULL;
196 
197  return scatnames;
198 }
199 
200 
208  if (scatnames != NULL) {
209  osl_strings_free(scatnames->names);
210  free(scatnames);
211  }
212 }
213 
214 
215 /*+***************************************************************************
216  * Processing functions *
217  *****************************************************************************/
218 
219 
228  osl_scatnames_p clone;
229 
230  if (scatnames == NULL)
231  return NULL;
232 
233  clone = osl_scatnames_malloc();
234  clone->names = osl_strings_clone(scatnames->names);
235 
236  return clone;
237 }
238 
239 
249 
250  if (s1 == s2)
251  return 1;
252 
253  if (((s1 == NULL) && (s2 != NULL)) || ((s1 != NULL) && (s2 == NULL)))
254  return 0;
255 
256  if (!osl_strings_equal(s1->names, s2->names))
257  return 0;
258 
259  return 1;
260 }
261 
262 
271 
272  OSL_strdup(interface->URI, OSL_URI_SCATNAMES);
273  interface->idump = (osl_idump_f)osl_scatnames_idump;
274  interface->sprint = (osl_sprint_f)osl_scatnames_sprint;
275  interface->sread = (osl_sread_f)osl_scatnames_sread;
276  interface->malloc = (osl_malloc_f)osl_scatnames_malloc;
277  interface->free = (osl_free_f)osl_scatnames_free;
278  interface->clone = (osl_clone_f)osl_scatnames_clone;
279  interface->equal = (osl_equal_f)osl_scatnames_equal;
280 
281  return interface;
282 }
void *(* osl_clone_f)(void *)
Definition: interface.h:80
osl_strings_p osl_strings_clone(osl_strings_p strings)
Definition: strings.c:328
osl_interface_p osl_interface_malloc()
Definition: interface.c:212
int osl_scatnames_equal(osl_scatnames_p s1, osl_scatnames_p s2)
Definition: scatnames.c:248
void *(* osl_sread_f)(char **)
Definition: interface.h:77
osl_interface_p osl_scatnames_interface()
Definition: scatnames.c:269
void osl_scatnames_idump(FILE *file, osl_scatnames_p scatnames, int level)
Definition: scatnames.c:89
void osl_scatnames_free(osl_scatnames_p scatnames)
Definition: scatnames.c:207
osl_strings_p osl_strings_sread(char **input)
Definition: strings.c:194
void osl_strings_idump(FILE *file, osl_strings_p strings, int level)
Definition: strings.c:89
void osl_scatnames_dump(FILE *file, osl_scatnames_p scatnames)
Definition: scatnames.c:125
osl_scatnames_p osl_scatnames_clone(osl_scatnames_p scatnames)
Definition: scatnames.c:227
void(* osl_idump_f)(FILE *, void *, int)
Definition: interface.h:75
char * osl_scatnames_sprint(osl_scatnames_p scatnames)
Definition: scatnames.c:137
osl_strings_p names
Definition: scatnames.h:88
char *(* osl_sprint_f)(void *)
Definition: interface.h:76
char * osl_strings_sprint(osl_strings_p strings)
Definition: strings.c:131
void *(* osl_malloc_f)()
Definition: interface.h:78
void osl_strings_free(osl_strings_p strings)
Definition: strings.c:299
int osl_strings_equal(osl_strings_p s1, osl_strings_p s2)
Definition: strings.c:387
int(* osl_equal_f)(void *, void *)
Definition: interface.h:81
osl_scatnames_p osl_scatnames_malloc()
Definition: scatnames.c:191
osl_scatnames_p osl_scatnames_sread(char **input)
Definition: scatnames.c:158
void(* osl_free_f)(void *)
Definition: interface.h:79