Merge branch 'master' of github.com:periscop/openscop
[openscop.git] / source / extensions / null.c
bloba4499b1ec5f555872034740b1df391f2447c189c
2 /*+-----------------------------------------------------------------**
3 ** OpenScop Library **
4 **-----------------------------------------------------------------**
5 ** extensions/null.c **
6 **-----------------------------------------------------------------**
7 ** First version: 28/06/2012 **
8 **-----------------------------------------------------------------**
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 *****************************************************************************/
63 #include <stdlib.h>
64 #include <stdio.h>
65 #include <string.h>
67 #include <osl/macros.h>
68 #include <osl/util.h>
69 #include <osl/interface.h>
70 #include <osl/extensions/null.h>
73 /*+***************************************************************************
74 * Structure display function *
75 *****************************************************************************/
78 /**
79 * osl_null_idump function:
80 * this function displays an osl_null_t structure (*null) into a
81 * file (file, possibly stdout) in a way that trends to be understandable. It
82 * includes an indentation level (level) in order to work with others
83 * idump functions.
84 * \param[in] file The file where the information has to be printed.
85 * \param[in] null The null structure to print.
86 * \param[in] level Number of spaces before printing, for each line.
88 void osl_null_idump(FILE * file, osl_null_p null, int level) {
89 int j;
91 // Go to the right level.
92 for (j = 0; j < level; j++)
93 fprintf(file, "|\t");
95 if (null != NULL)
96 fprintf(file, "+-- osl_null_t\n");
97 else
98 fprintf(file, "+-- NULL null\n");
100 // The last line.
101 for (j = 0; j <= level; j++)
102 fprintf(file, "|\t");
103 fprintf(file, "\n");
108 * osl_null_dump function:
109 * this function prints the content of an osl_null_t structure
110 * (*null) into a file (file, possibly stdout).
111 * \param[in] file The file where the information has to be printed.
112 * \param[in] null The null structure to print.
114 void osl_null_dump(FILE * file, osl_null_p null) {
115 osl_null_idump(file, null, 0);
120 * osl_null_sprint function:
121 * this function prints the content of an osl_null_t structure
122 * (*null) into a string (returned) in the OpenScop textual format.
123 * \param[in] null The null structure to print.
124 * \return A string containing the OpenScop dump of the null structure.
126 char * osl_null_sprint(osl_null_p null) {
127 char * string = NULL;
129 if (null != NULL) {
130 // Print nothing.
131 OSL_malloc(string, char *, sizeof(char));
132 string[0] = '\0';
135 return string;
139 /*****************************************************************************
140 * Reading function *
141 *****************************************************************************/
145 * osl_null_sread function:
146 * this function reads a null structure from a string complying to the
147 * OpenScop textual format and returns a pointer to this null structure.
148 * The input parameter is updated to the position in the input string this
149 * function reach right after reading the null structure.
150 * \param[in,out] input The input string where to find a null.
151 * Updated to the position after what has been read.
152 * \return A pointer to the null structure that has been read.
154 osl_null_p osl_null_sread(char ** input) {
155 osl_null_p null;
157 if (*input == NULL) {
158 OSL_debug("no null optional tag");
159 return NULL;
162 // Build the null structure
163 null = osl_null_malloc();
165 // Update the input pointer (everything has been read and ignored).
166 input += strlen(*input);
168 return null;
172 /*+***************************************************************************
173 * Memory allocation/deallocation function *
174 *****************************************************************************/
178 * osl_null_malloc function:
179 * this function allocates the memory space for an osl_null_t
180 * structure and sets its fields with default values. Then it returns a
181 * pointer to the allocated space.
182 * \return A pointer to an empty null structure with fields set to
183 * default values.
185 osl_null_p osl_null_malloc() {
186 osl_null_p null;
188 OSL_malloc(null, osl_null_p, sizeof(osl_null_t));
189 return null;
194 * osl_null_free function:
195 * this function frees the allocated memory for an osl_null_t
196 * structure.
197 * \param[in,out] null The pointer to the null structure to free.
199 void osl_null_free(osl_null_p null) {
200 if (null != NULL) {
201 free(null);
206 /*+***************************************************************************
207 * Processing functions *
208 *****************************************************************************/
212 * osl_null_clone function:
213 * this function builds and returns a "hard copy" (not a pointer copy) of an
214 * osl_null_t data structure.
215 * \param[in] null The pointer to the null structure to clone.
216 * \return A pointer to the clone of the null structure.
218 osl_null_p osl_null_clone(osl_null_p null) {
219 osl_null_p clone;
221 if (null == NULL)
222 return NULL;
224 clone = osl_null_malloc();
225 return clone;
230 * osl_null_equal function:
231 * this function returns true if the two null structures are the same
232 * (content-wise), false otherwise.
233 * \param[in] c1 The first null structure.
234 * \param[in] c2 The second null structure.
235 * \return 1 if c1 and c2 are the same (content-wise), 0 otherwise.
237 int osl_null_equal(osl_null_p c1, osl_null_p c2) {
238 if (c1 == c2)
239 return 1;
241 if (((c1 == NULL) && (c2 != NULL)) || ((c1 != NULL) && (c2 == NULL))) {
242 OSL_info("nulls are not the same");
243 return 0;
246 return 1;
251 * osl_null_interface function:
252 * this function creates an interface structure corresponding to the null
253 * extension and returns it).
254 * \return An interface structure for the null extension.
256 osl_interface_p osl_null_interface() {
257 osl_interface_p interface = osl_interface_malloc();
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;
268 return interface;