tools.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #include "tools.h"
00036 #if LIBDARC_HAVE_LIBDAR_HPP
00037 #include <dar/libdar.hpp>
00038 #endif
00039
00040 #include <string>
00041
00042 #if HAVE_MALLOC_H
00043 #include <malloc.h>
00044 #endif
00045
00046 NAMESPACE_LIBDAR_START
00047
00048
00049
00050 extern "C" dar_infinint *dar_tools_get_extended_size(char* s, U_I base)
00051 {
00052 std::string size = s;
00053 infinint* tmp = new infinint();
00054 *tmp = tools_get_extended_size( size, base );
00055 return reinterpret_cast<dar_infinint*>(tmp);
00056 }
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 extern "C" char* dar_tools_display_date( dar_infinint* date )
00078 {
00079 infinint* d = reinterpret_cast<infinint*>(date);
00080 std::string str = tools_display_date( *d );
00081 char* ret = (char*)malloc( str.size() + 1 );
00082 if (ret == NULL) { return NULL; }
00083 strcpy( ret, str.c_str() );
00084 return ret;
00085 }
00086
00087
00088 char* dar_internal_string_return_overflow(char *s, U_I size)
00089 {
00090
00091 char* ret = (char*)malloc(size + 1);
00092 if (ret == NULL) { return NULL; }
00093 strcpy( ret, s );
00094
00095
00096 return ret;
00097 }
00098
00099
00100 char* dar_internal_string_return_truncate(char *s, U_I size, U_I fixed_size)
00101 {
00102 char* ret = (char*)malloc(fixed_size + 1);
00103 if (ret == NULL) { return NULL; }
00104 strncpy( ret, s, fixed_size );
00105 ret[fixed_size] = '\0';
00106 return ret;
00107 }
00108
00109 extern "C" char* dar_tools_string_justify_right(char* s, U_I min_size)
00110 {
00111 char* ret;
00112 U_I l = strlen(s);
00113 if ( l > min_size )
00114 return dar_internal_string_return_overflow(s, l);
00115 ret = (char*)malloc( min_size + 1 );
00116 if (ret == NULL) { return NULL; }
00117 unsigned int i;
00118 for ( i = 0; i < min_size - l; i++ )
00119 ret[i] = ' ';
00120 strcpy( ret + i, s );
00121 return ret;
00122 }
00123
00124 extern "C" char* dar_tools_string_justify_center(char* s, U_I min_size)
00125 {
00126 char* ret;
00127 U_I l = strlen(s);
00128 if ( l > min_size )
00129 return dar_internal_string_return_overflow(s, l);
00130 ret = (char*)malloc( min_size + 1 );
00131 if (ret == NULL) { return NULL; }
00132 unsigned int i;
00133 for ( i = 0; i < (min_size - l)/2; i++ )
00134 ret[i] = ' ';
00135 strcpy( ret + i, s );
00136 for ( i += l; i < min_size; i++ )
00137 ret[i] = ' ';
00138 ret[min_size] = '\0';
00139 return ret;
00140 }
00141
00142 extern "C" char* dar_tools_string_justify_left(char* s, U_I min_size)
00143 {
00144 char* ret;
00145 U_I l = strlen(s);
00146 if ( l > min_size )
00147 return dar_internal_string_return_overflow(s, l);
00148 ret = (char*)malloc( min_size + 1 );
00149 if (ret == NULL) { return NULL; }
00150 strcpy( ret, s );
00151 unsigned int i;
00152 for ( i = l; i < min_size; i++ )
00153 ret[i] = ' ';
00154 ret[min_size] = '\0';
00155 return ret;
00156 }
00157
00158
00159 extern "C" char* dar_tools_string_justify_right_truncate(char* s, U_I fixed_size)
00160 {
00161 char* ret;
00162 U_I l = strlen(s);
00163 if ( l > fixed_size )
00164 return dar_internal_string_return_truncate(s, l, fixed_size);
00165 ret = (char*)malloc( fixed_size + 1 );
00166 if (ret == NULL) { return NULL; }
00167 unsigned int i;
00168 for ( i = 0; i < fixed_size - l; i++ )
00169 ret[i] = ' ';
00170 strcpy( ret + i, s );
00171 return ret;
00172 }
00173
00174 extern "C" char* dar_tools_string_justify_center_truncate(char* s, U_I fixed_size)
00175 {
00176 char* ret;
00177 U_I l = strlen(s);
00178 if ( l > fixed_size )
00179 return dar_internal_string_return_truncate(s, l, fixed_size);
00180 ret = (char*)malloc( fixed_size + 1 );
00181 if (ret == NULL) { return NULL; }
00182 unsigned int i;
00183 for ( i = 0; i < (fixed_size - l)/2; i++ )
00184 ret[i] = ' ';
00185 strcpy( ret + i, s );
00186 for ( i += l; i < fixed_size; i++ )
00187 ret[i] = ' ';
00188 ret[fixed_size] = '\0';
00189 return ret;
00190 }
00191
00192 extern "C" char* dar_tools_string_justify_left_truncate(char* s, U_I fixed_size)
00193 {
00194 char* ret;
00195 U_I l = strlen(s);
00196 if ( l > fixed_size )
00197 return dar_internal_string_return_truncate(s, l, fixed_size);
00198 ret = (char*)malloc( fixed_size + 1 );
00199 if (ret == NULL) { return NULL; }
00200 strcpy( ret, s );
00201 unsigned int i;
00202 for ( i = l; i < fixed_size; i++ )
00203 ret[i] = ' ';
00204 ret[fixed_size] = '\0';
00205 return ret;
00206 }
00207
00208
00209 extern "C" char* dar_tools_name_of_uid( U_16 uid )
00210 {
00211 printf("name_of_uid function\n");
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224 }
00225
00226 extern "C" char* dar_tools_name_of_gid( U_16 gid )
00227 {
00228
00229
00230
00231
00232
00233
00234
00235 }
00236
00237 extern "C" char* dar_tools_get_cwd( )
00238 {
00239
00240
00241
00242
00243
00244
00245
00246 }
00247
00248
00249
00250
00251
00252
00253 NAMESPACE_LIBDAR_END
00254