OpenScop  0.9.0
scatnames.c
Go to the documentation of this file.
00001 
00002     /*+-----------------------------------------------------------------**
00003      **                       OpenScop Library                          **
00004      **-----------------------------------------------------------------**
00005      **                    extensions/scatnames.c                       **
00006      **-----------------------------------------------------------------**
00007      **                   First version: 03/12/2011                     **
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/strings.h>
00071 #include <osl/extensions/scatnames.h>
00072 
00073 
00074 /*+***************************************************************************
00075  *                          Structure display function                       *
00076  *****************************************************************************/
00077 
00078 
00089 void osl_scatnames_idump(FILE * file, osl_scatnames_p scatnames, int level) {
00090   int j;
00091 
00092   // Go to the right level.
00093   for (j = 0; j < level; j++)
00094     fprintf(file, "|\t");
00095 
00096   if (scatnames != NULL)
00097     fprintf(file, "+-- osl_scatnames_t\n");
00098   else
00099     fprintf(file, "+-- NULL scatnames\n");
00100 
00101   if (scatnames != NULL) {
00102     // Go to the right level.
00103     for(j = 0; j <= level + 1; j++)
00104       fprintf(file, "|\t");
00105     fprintf(file, "\n");
00106   
00107     // Display the list of scattering names.
00108     osl_strings_idump(file, scatnames->names, level + 1);
00109   }
00110 
00111   // The last line.
00112   for (j = 0; j <= level; j++)
00113     fprintf(file, "|\t");
00114   fprintf(file, "\n");
00115 }
00116 
00117 
00125 void osl_scatnames_dump(FILE * file, osl_scatnames_p scatnames) {
00126   osl_scatnames_idump(file, scatnames, 0);
00127 }
00128 
00129 
00137 char * osl_scatnames_sprint(osl_scatnames_p scatnames) {
00138   return osl_strings_sprint(scatnames->names);
00139 }
00140 
00141 
00142 /*****************************************************************************
00143  *                               Reading function                            *
00144  *****************************************************************************/
00145 
00146 
00158 osl_scatnames_p osl_scatnames_sread(char ** input) {
00159   osl_scatnames_p scatnames = NULL;
00160   osl_strings_p names = NULL;
00161 
00162   if (*input == NULL) {
00163     OSL_debug("no scatnames optional tag");
00164     return NULL;
00165   }
00166 
00167   // Build the scatnames structure
00168   names = osl_strings_sread(input);
00169   if (names != NULL) {
00170     scatnames = osl_scatnames_malloc();
00171     scatnames->names = names;
00172   }
00173 
00174   return scatnames;
00175 }
00176 
00177 
00178 /*+***************************************************************************
00179  *                    Memory allocation/deallocation function                *
00180  *****************************************************************************/
00181 
00182 
00191 osl_scatnames_p osl_scatnames_malloc() {
00192   osl_scatnames_p scatnames;
00193 
00194   OSL_malloc(scatnames, osl_scatnames_p, sizeof(osl_scatnames_t));
00195   scatnames->names = NULL;
00196 
00197   return scatnames;
00198 }
00199 
00200 
00207 void osl_scatnames_free(osl_scatnames_p scatnames) {
00208   if (scatnames != NULL) {
00209     osl_strings_free(scatnames->names);
00210     free(scatnames);
00211   }
00212 }
00213 
00214 
00215 /*+***************************************************************************
00216  *                            Processing functions                           *
00217  *****************************************************************************/
00218 
00219 
00227 osl_scatnames_p osl_scatnames_clone(osl_scatnames_p scatnames) {
00228   osl_scatnames_p clone;
00229 
00230   if (scatnames == NULL)
00231     return NULL;
00232 
00233   clone = osl_scatnames_malloc();
00234   clone->names = osl_strings_clone(scatnames->names);
00235 
00236   return clone;
00237 }
00238 
00239 
00248 int osl_scatnames_equal(osl_scatnames_p s1, osl_scatnames_p s2) {
00249   
00250   if (s1 == s2)
00251     return 1;
00252 
00253   if (((s1 == NULL) && (s2 != NULL)) || ((s1 != NULL) && (s2 == NULL)))
00254     return 0;
00255 
00256   if (!osl_strings_equal(s1->names, s2->names))
00257     return 0;
00258 
00259   return 1;
00260 }
00261 
00262 
00269 osl_interface_p osl_scatnames_interface() {
00270   osl_interface_p interface = osl_interface_malloc();
00271   
00272   OSL_strdup(interface->URI, OSL_URI_SCATNAMES);
00273   interface->idump  = (osl_idump_f)osl_scatnames_idump;
00274   interface->sprint = (osl_sprint_f)osl_scatnames_sprint;
00275   interface->sread  = (osl_sread_f)osl_scatnames_sread;
00276   interface->malloc = (osl_malloc_f)osl_scatnames_malloc;
00277   interface->free   = (osl_free_f)osl_scatnames_free;
00278   interface->clone  = (osl_clone_f)osl_scatnames_clone;
00279   interface->equal  = (osl_equal_f)osl_scatnames_equal;
00280 
00281   return interface;
00282 }