OpenScop  0.9.0
null.c
Go to the documentation of this file.
00001 
00002     /*+-----------------------------------------------------------------**
00003      **                       OpenScop Library                          **
00004      **-----------------------------------------------------------------**
00005      **                       extensions/null.c                         **
00006      **-----------------------------------------------------------------**
00007      **                   First version: 28/06/2012                     **
00008      **-----------------------------------------------------------------**
00009 
00010  
00011  *****************************************************************************
00012  * OpenScop: Structures and formats for polyhedral tools to talk together    *
00013  *****************************************************************************
00014  *    ,___,,_,__,,__,,__,,__,,_,__,,_,__,,__,,___,_,__,,_,__,                *
00015  *    /   / /  //  //  //  // /   / /  //  //   / /  // /  /|,_,             *
00016  *   /   / /  //  //  //  // /   / /  //  //   / /  // /  / / /\             *
00017  *  |~~~|~|~~~|~~~|~~~|~~~|~|~~~|~|~~~|~~~|~~~|~|~~~|~|~~~|/_/  \            *
00018  *  | G |C| P | = | L | P |=| = |C| = | = | = |=| = |=| C |\  \ /\           *
00019  *  | R |l| o | = | e | l |=| = |a| = | = | = |=| = |=| L | \# \ /\          *
00020  *  | A |a| l | = | t | u |=| = |n| = | = | = |=| = |=| o | |\# \  \         *
00021  *  | P |n| l | = | s | t |=| = |d| = | = | = | |   |=| o | | \# \  \        *
00022  *  | H | | y |   | e | o | | = |l|   |   | = | |   | | G | |  \  \  \       *
00023  *  | I | |   |   | e |   | |   | |   |   |   | |   | |   | |   \  \  \      *
00024  *  | T | |   |   |   |   | |   | |   |   |   | |   | |   | |    \  \  \     *
00025  *  | E | |   |   |   |   | |   | |   |   |   | |   | |   | |     \  \  \    *
00026  *  | * |*| * | * | * | * |*| * |*| * | * | * |*| * |*| * | /      \* \  \   *
00027  *  | O |p| e | n | S | c |o| p |-| L | i | b |r| a |r| y |/        \  \ /   *
00028  *  '---'-'---'---'---'---'-'---'-'---'---'---'-'---'-'---'          '--'    *
00029  *                                                                           *
00030  * Copyright (C) 2008 University Paris-Sud 11 and INRIA                      *
00031  *                                                                           *
00032  * (3-clause BSD license)                                                    *
00033  * Redistribution and use in source  and binary forms, with or without       *
00034  * modification, are permitted provided that the following conditions        *
00035  * are met:                                                                  *
00036  *                                                                           *
00037  * 1. Redistributions of source code must retain the above copyright notice, *
00038  *    this list of conditions and the following disclaimer.                  *
00039  * 2. Redistributions in binary form must reproduce the above copyright      *
00040  *    notice, this list of conditions and the following disclaimer in the    *
00041  *    documentation and/or other materials provided with the distribution.   *
00042  * 3. The name of the author may not be used to endorse or promote products  *
00043  *    derived from this software without specific prior written permission.  *
00044  *                                                                           *
00045  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR      *
00046  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES *
00047  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.   *
00048  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,          *
00049  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT  *
00050  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
00051  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY     *
00052  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT       *
00053  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF  *
00054  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.         *
00055  *                                                                           *
00056  * OpenScop Library, a library to manipulate OpenScop formats and data       *
00057  * structures. Written by:                                                   *
00058  * Cedric Bastoul     <Cedric.Bastoul@u-psud.fr> and                         *
00059  * Louis-Noel Pouchet <Louis-Noel.pouchet@inria.fr>                          *
00060  *                                                                           *
00061  *****************************************************************************/
00062 
00063 #include <stdlib.h>
00064 #include <stdio.h>
00065 #include <string.h>
00066 
00067 #include <osl/macros.h>
00068 #include <osl/util.h>
00069 #include <osl/interface.h>
00070 #include <osl/extensions/null.h>
00071 
00072 
00073 /*+***************************************************************************
00074  *                          Structure display function                       *
00075  *****************************************************************************/
00076 
00077 
00088 void osl_null_idump(FILE * file, osl_null_p null, int level) {
00089   int j;
00090 
00091   // Go to the right level.
00092   for (j = 0; j < level; j++)
00093     fprintf(file, "|\t");
00094 
00095   if (null != NULL)
00096     fprintf(file, "+-- osl_null_t\n");
00097   else
00098     fprintf(file, "+-- NULL null\n");
00099 
00100   // The last line.
00101   for (j = 0; j <= level; j++)
00102     fprintf(file, "|\t");
00103   fprintf(file, "\n");
00104 }
00105 
00106 
00114 void osl_null_dump(FILE * file, osl_null_p null) {
00115   osl_null_idump(file, null, 0);
00116 }
00117 
00118 
00126 char * osl_null_sprint(osl_null_p null) {
00127   char * string = NULL;
00128 
00129   if (null != NULL) {
00130     // Print nothing.
00131     OSL_malloc(string, char *, sizeof(char));
00132     string[0] = '\0';
00133   }
00134 
00135   return string;
00136 }
00137 
00138 
00139 /*****************************************************************************
00140  *                               Reading function                            *
00141  *****************************************************************************/
00142 
00143 
00154 osl_null_p osl_null_sread(char ** input) {
00155   osl_null_p null;
00156 
00157   if (*input == NULL) {
00158     OSL_debug("no null optional tag");
00159     return NULL;
00160   }
00161 
00162   // Build the null structure
00163   null = osl_null_malloc();
00164 
00165   // Update the input pointer (everything has been read and ignored).
00166   input += strlen(*input);
00167 
00168   return null;
00169 }
00170 
00171 
00172 /*+***************************************************************************
00173  *                    Memory allocation/deallocation function                *
00174  *****************************************************************************/
00175 
00176 
00185 osl_null_p osl_null_malloc() {
00186   osl_null_p null;
00187 
00188   OSL_malloc(null, osl_null_p, sizeof(osl_null_t));
00189   return null;
00190 }
00191 
00192 
00199 void osl_null_free(osl_null_p null) {
00200   if (null != NULL) {
00201     free(null);
00202   }
00203 }
00204 
00205 
00206 /*+***************************************************************************
00207  *                            Processing functions                           *
00208  *****************************************************************************/
00209 
00210 
00218 osl_null_p osl_null_clone(osl_null_p null) {
00219   osl_null_p clone;
00220 
00221   if (null == NULL)
00222     return NULL;
00223 
00224   clone = osl_null_malloc();
00225   return clone;
00226 }
00227 
00228 
00237 int osl_null_equal(osl_null_p c1, osl_null_p c2) {
00238   if (c1 == c2)
00239     return 1;
00240 
00241   if (((c1 == NULL) && (c2 != NULL)) || ((c1 != NULL) && (c2 == NULL))) {
00242     OSL_info("nulls are not the same");
00243     return 0;
00244   }
00245 
00246   return 1;
00247 }
00248 
00249 
00256 osl_interface_p osl_null_interface() {
00257   osl_interface_p interface = osl_interface_malloc();
00258   
00259   OSL_strdup(interface->URI, OSL_URI_NULL);
00260   interface->idump  = (osl_idump_f)osl_null_idump;
00261   interface->sprint = (osl_sprint_f)osl_null_sprint;
00262   interface->sread  = (osl_sread_f)osl_null_sread;
00263   interface->malloc = (osl_malloc_f)osl_null_malloc;
00264   interface->free   = (osl_free_f)osl_null_free;
00265   interface->clone  = (osl_clone_f)osl_null_clone;
00266   interface->equal  = (osl_equal_f)osl_null_equal;
00267 
00268   return interface;
00269 }