OpenScop  0.9.0
null.c
Go to the documentation of this file.
1 
2  /*+-----------------------------------------------------------------**
3  ** OpenScop Library **
4  **-----------------------------------------------------------------**
5  ** extensions/null.c **
6  **-----------------------------------------------------------------**
7  ** First version: 28/06/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/null.h>
71 
72 
73 /*+***************************************************************************
74  * Structure display function *
75  *****************************************************************************/
76 
77 
88 void osl_null_idump(FILE * file, osl_null_p null, int level) {
89  int j;
90 
91  // Go to the right level.
92  for (j = 0; j < level; j++)
93  fprintf(file, "|\t");
94 
95  if (null != NULL)
96  fprintf(file, "+-- osl_null_t\n");
97  else
98  fprintf(file, "+-- NULL null\n");
99 
100  // The last line.
101  for (j = 0; j <= level; j++)
102  fprintf(file, "|\t");
103  fprintf(file, "\n");
104 }
105 
106 
114 void osl_null_dump(FILE * file, osl_null_p null) {
115  osl_null_idump(file, null, 0);
116 }
117 
118 
127  char * string = NULL;
128 
129  if (null != NULL) {
130  // Print nothing.
131  OSL_malloc(string, char *, sizeof(char));
132  string[0] = '\0';
133  }
134 
135  return string;
136 }
137 
138 
139 /*****************************************************************************
140  * Reading function *
141  *****************************************************************************/
142 
143 
154 osl_null_p osl_null_sread(char ** input) {
155  osl_null_p null;
156 
157  if (*input == NULL) {
158  OSL_debug("no null optional tag");
159  return NULL;
160  }
161 
162  // Build the null structure
163  null = osl_null_malloc();
164 
165  // Update the input pointer (everything has been read and ignored).
166  input += strlen(*input);
167 
168  return null;
169 }
170 
171 
172 /*+***************************************************************************
173  * Memory allocation/deallocation function *
174  *****************************************************************************/
175 
176 
186  osl_null_p null;
187 
188  OSL_malloc(null, osl_null_p, sizeof(osl_null_t));
189  return null;
190 }
191 
192 
200  if (null != NULL) {
201  free(null);
202  }
203 }
204 
205 
206 /*+***************************************************************************
207  * Processing functions *
208  *****************************************************************************/
209 
210 
219  osl_null_p clone;
220 
221  if (null == NULL)
222  return NULL;
223 
224  clone = osl_null_malloc();
225  return clone;
226 }
227 
228 
238  if (c1 == c2)
239  return 1;
240 
241  if (((c1 == NULL) && (c2 != NULL)) || ((c1 != NULL) && (c2 == NULL))) {
242  OSL_info("nulls are not the same");
243  return 0;
244  }
245 
246  return 1;
247 }
248 
249 
258 
259  OSL_strdup(interface->URI, OSL_URI_NULL);
260  interface->idump = (osl_idump_f)osl_null_idump;
261  interface->sprint = (osl_sprint_f)osl_null_sprint;
262  interface->sread = (osl_sread_f)osl_null_sread;
263  interface->malloc = (osl_malloc_f)osl_null_malloc;
264  interface->free = (osl_free_f)osl_null_free;
265  interface->clone = (osl_clone_f)osl_null_clone;
266  interface->equal = (osl_equal_f)osl_null_equal;
267 
268  return interface;
269 }
char * osl_null_sprint(osl_null_p null)
Definition: null.c:126
void *(* osl_clone_f)(void *)
Definition: interface.h:80
osl_interface_p osl_interface_malloc()
Definition: interface.c:212
void *(* osl_sread_f)(char **)
Definition: interface.h:77
osl_null_p osl_null_sread(char **input)
Definition: null.c:154
Definition: null.h:83
void osl_null_idump(FILE *file, osl_null_p null, int level)
Definition: null.c:88
osl_null_p osl_null_malloc()
Definition: null.c:185
void(* osl_idump_f)(FILE *, void *, int)
Definition: interface.h:75
void osl_null_dump(FILE *file, osl_null_p null)
Definition: null.c:114
int osl_null_equal(osl_null_p c1, osl_null_p c2)
Definition: null.c:237
char *(* osl_sprint_f)(void *)
Definition: interface.h:76
osl_interface_p osl_null_interface()
Definition: null.c:256
void osl_null_free(osl_null_p null)
Definition: null.c:199
void *(* osl_malloc_f)()
Definition: interface.h:78
int(* osl_equal_f)(void *, void *)
Definition: interface.h:81
osl_null_p osl_null_clone(osl_null_p null)
Definition: null.c:218
void(* osl_free_f)(void *)
Definition: interface.h:79