drake
1.0.0
|
00001 /* 00002 Copyright 2015 Nicolas Melot 00003 00004 This file is part of Drake. 00005 00006 Drake is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 Drake is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with Drake. If not, see <http://www.gnu.org/licenses/>. 00018 00019 */ 00020 00021 00022 #include <stdlib.h> 00023 #include <string.h> 00024 00025 #include <drake/link.h> 00026 #include <drake/cross_link.h> 00027 #include <drake/platform.h> 00028 00029 cross_link_tp * 00030 pelib_alloc_struct(cross_link_tp)() 00031 { 00032 return malloc(sizeof(cross_link_tp)); 00033 } 00034 00035 cross_link_tp * 00036 pelib_alloc(cross_link_tp)(void* aux) 00037 { 00038 return pelib_alloc_struct(cross_link_tp)(); 00039 } 00040 00041 int 00042 pelib_init(cross_link_tp)(cross_link_tp *link) 00043 { 00044 *link = NULL; 00045 return 1; 00046 } 00047 00048 int 00049 pelib_copy(cross_link_tp)(cross_link_tp src, cross_link_tp* dst) 00050 { 00051 if(dst != NULL) 00052 { 00053 *dst = src; 00054 00055 return 1; 00056 } 00057 else 00058 { 00059 return 0; 00060 } 00061 } 00062 00063 int 00064 pelib_free_struct(cross_link_tp)(cross_link_tp * link) 00065 { 00066 free(link); 00067 00068 return 1; 00069 } 00070 00071 int 00072 pelib_free(cross_link_tp)(cross_link_tp *link) 00073 { 00074 return pelib_free_struct(cross_link_tp)(link); 00075 } 00076 00077 int 00078 pelib_compare(cross_link_tp)(cross_link_tp l1, cross_link_tp l2) 00079 { 00080 return 0; 00081 } 00082 00083 FILE* 00084 pelib_printf(cross_link_tp)(FILE* stream, cross_link_tp link) 00085 { 00086 return pelib_printf_detail(cross_link_tp)(stream, link, 0); 00087 } 00088 00089 FILE* 00090 pelib_printf_detail(cross_link_tp)(FILE* stream, cross_link_tp link, int level) 00091 { 00092 char* str; 00093 00094 str = pelib_string_detail(cross_link_tp)(link, level); 00095 printf("%s", str); 00096 free(str); 00097 00098 return stream; 00099 } 00100 00101 size_t 00102 pelib_fwrite(cross_link_tp)(cross_link_tp link, FILE* file) 00103 { 00104 fprintf(stderr, "[%s:%d] Not implemented\n", __FILE__, __LINE__); 00105 return 0; 00106 } 00107 00108 size_t 00109 pelib_fread(cross_link_tp)(cross_link_tp* link, FILE* file) 00110 { 00111 fprintf(stderr, "[%s:%d] Not implemented\n", __FILE__, __LINE__); 00112 return 0; 00113 } 00114 00115 char* 00116 pelib_string(cross_link_tp)(cross_link_tp link) 00117 { 00118 return pelib_string_detail(cross_link_tp)(link, 0); 00119 } 00120 00121 char* 00122 pelib_string_detail(cross_link_tp)(cross_link_tp link, int level) 00123 { 00124 char *str, *link_str; 00125 00126 if(level == 0) 00127 { 00128 link_str = pelib_string(link_tp)(link->link); 00129 00130 return link_str; 00131 } 00132 else 00133 { 00134 link_str = pelib_string_detail(link_tp)(link->link, level - 1); 00135 str = malloc(sizeof(char) * (strlen(link_str) + 3 + sizeof(cross_link_tp) * 2 + 1 + 1 + 1)); 00136 00137 sprintf(str, "->{%p:%s}", link, link_str); 00138 free(link_str); 00139 00140 return str; 00141 } 00142 } 00143 00144 #define ARRAY_T cross_link_tp 00145 #include <pelib/array.c>