OpenScop
0.9.0
|
00001 00002 /*+-----------------------------------------------------------------** 00003 ** OpenScop Library ** 00004 **-----------------------------------------------------------------** 00005 ** extensions/clay.c ** 00006 **-----------------------------------------------------------------** 00007 ** First version: 09/05/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/clay.h> 00071 00072 00073 /*+*************************************************************************** 00074 * Structure display function * 00075 *****************************************************************************/ 00076 00077 00088 void osl_clay_idump(FILE * file, osl_clay_p clay, int level) { 00089 int j; 00090 size_t l; 00091 char * tmp; 00092 00093 // Go to the right level. 00094 for (j = 0; j < level; j++) 00095 fprintf(file, "|\t"); 00096 00097 if (clay != NULL) 00098 fprintf(file, "+-- osl_clay_t\n"); 00099 else 00100 fprintf(file, "+-- NULL clay\n"); 00101 00102 if (clay != NULL) { 00103 // Go to the right level. 00104 for(j = 0; j <= level; j++) 00105 fprintf(file, "|\t"); 00106 00107 // Display the clay script (without any carriage return). 00108 OSL_strdup(tmp, clay->script); 00109 for (l = 0; l < strlen(tmp); l++) 00110 if (tmp[l] == '\n') 00111 tmp[l] = ' '; 00112 fprintf(file, "script: %s\n", tmp); 00113 free(tmp); 00114 } 00115 00116 // The last line. 00117 for (j = 0; j <= level; j++) 00118 fprintf(file, "|\t"); 00119 fprintf(file, "\n"); 00120 } 00121 00122 00130 void osl_clay_dump(FILE * file, osl_clay_p clay) { 00131 osl_clay_idump(file, clay, 0); 00132 } 00133 00134 00142 char * osl_clay_sprint(osl_clay_p clay) { 00143 int high_water_mark = OSL_MAX_STRING; 00144 char * string = NULL; 00145 char buffer[OSL_MAX_STRING]; 00146 00147 if (clay != NULL) { 00148 OSL_malloc(string, char *, high_water_mark * sizeof(char)); 00149 string[0] = '\0'; 00150 00151 // Print the clay. 00152 sprintf(buffer, "%s", clay->script); 00153 osl_util_safe_strcat(&string, buffer, &high_water_mark); 00154 00155 // Keep only the memory space we need. 00156 OSL_realloc(string, char *, (strlen(string) + 1) * sizeof(char)); 00157 } 00158 00159 return string; 00160 } 00161 00162 00163 /***************************************************************************** 00164 * Reading function * 00165 *****************************************************************************/ 00166 00167 00178 osl_clay_p osl_clay_sread(char ** input) { 00179 osl_clay_p clay; 00180 char * script; 00181 00182 if (*input == NULL) { 00183 OSL_debug("no clay optional tag"); 00184 return NULL; 00185 } 00186 00187 if (strlen(*input) > OSL_MAX_STRING) 00188 OSL_error("clay script too long"); 00189 00190 // Build the clay structure 00191 clay = osl_clay_malloc(); 00192 script = *input; 00193 00194 // Pass the carriage returns (this allows to remove those inserted by 00195 // osl_generic_print), and copy the textual script. 00196 while (*script && (*script == '\n')) 00197 script++; 00198 OSL_strdup(clay->script, script); 00199 00200 // Update the input pointer (everything has been read). 00201 input += strlen(*input); 00202 00203 return clay; 00204 } 00205 00206 00207 /*+*************************************************************************** 00208 * Memory allocation/deallocation function * 00209 *****************************************************************************/ 00210 00211 00220 osl_clay_p osl_clay_malloc() { 00221 osl_clay_p clay; 00222 00223 OSL_malloc(clay, osl_clay_p, sizeof(osl_clay_t)); 00224 clay->script = NULL; 00225 00226 return clay; 00227 } 00228 00229 00236 void osl_clay_free(osl_clay_p clay) { 00237 if (clay != NULL) { 00238 if(clay->script != NULL) 00239 free(clay->script); 00240 free(clay); 00241 } 00242 } 00243 00244 00245 /*+*************************************************************************** 00246 * Processing functions * 00247 *****************************************************************************/ 00248 00249 00257 osl_clay_p osl_clay_clone(osl_clay_p clay) { 00258 osl_clay_p clone; 00259 00260 if (clay == NULL) 00261 return NULL; 00262 00263 clone = osl_clay_malloc(); 00264 OSL_strdup(clone->script, clay->script); 00265 00266 return clone; 00267 } 00268 00269 00278 int osl_clay_equal(osl_clay_p c1, osl_clay_p c2) { 00279 if (c1 == c2) 00280 return 1; 00281 00282 if (((c1 == NULL) && (c2 != NULL)) || ((c1 != NULL) && (c2 == NULL))) { 00283 OSL_info("clay extensions are not the same"); 00284 return 0; 00285 } 00286 00287 if (strcmp(c1->script, c2->script)) { 00288 OSL_info("clay scripts are not the same"); 00289 return 0; 00290 } 00291 00292 return 1; 00293 } 00294 00295 00302 osl_interface_p osl_clay_interface() { 00303 osl_interface_p interface = osl_interface_malloc(); 00304 00305 OSL_strdup(interface->URI, OSL_URI_CLAY); 00306 interface->idump = (osl_idump_f)osl_clay_idump; 00307 interface->sprint = (osl_sprint_f)osl_clay_sprint; 00308 interface->sread = (osl_sread_f)osl_clay_sread; 00309 interface->malloc = (osl_malloc_f)osl_clay_malloc; 00310 interface->free = (osl_free_f)osl_clay_free; 00311 interface->clone = (osl_clone_f)osl_clay_clone; 00312 interface->equal = (osl_equal_f)osl_clay_equal; 00313 00314 return interface; 00315 }