Doxygen Source Code Documentation
list_struct.c File Reference
#include "stdlib.h"
#include "list_struct.h"
Go to the source code of this file.
Functions | |
int | init_float_list (float_list *d_list, int nel) |
int | init_int_list (int_list *d_list, int nel) |
int | init_short_list (short_list *d_list, int nel) |
int | init_void_list (void_list *d_list, int nel) |
int | init_floatp_list (floatp_list *d_list, int nel, int len) |
int | init_intp_list (intp_list *d_list, int nel, int len) |
int | init_shortp_list (shortp_list *d_list, int nel, int len) |
int | init_voidp_list (voidp_list *d_list, int nel, int len) |
int | free_float_list (float_list *d_list) |
int | free_int_list (int_list *d_list) |
int | free_short_list (short_list *d_list) |
int | free_void_list (void_list *d_list) |
int | free_floatp_list (floatp_list *d_list) |
int | free_intp_list (intp_list *d_list) |
int | free_shortp_list (shortp_list *d_list) |
int | free_voidp_list (voidp_list *d_list) |
Function Documentation
|
Definition at line 363 of file list_struct.c. References free, float_list::list, float_list::nall, and float_list::num.
|
|
Definition at line 411 of file list_struct.c. References floatp_list::elen, free, floatp_list::list, floatp_list::nall, and floatp_list::num.
00412 { 00413 int count; 00414 00415 if ( !d_list ) return -1; 00416 00417 /* if nothing has been set, just clear values and return */ 00418 if ( d_list->num <= 0 ){ 00419 d_list->num = d_list->nall = d_list->elen = 0; 00420 d_list->list = NULL; 00421 return 0; 00422 } 00423 00424 /* this is bad, but nothing to do */ 00425 if ( !d_list->list ){ 00426 d_list->num = d_list->nall = d_list->elen = 0; 00427 return -1; 00428 } 00429 00430 /* first, free the nall lists (of length elen) */ 00431 00432 for ( count = 0; count < d_list->nall; count++ ) 00433 if ( d_list->list[count] ) free(d_list->list[count]); 00434 00435 /* now free the list and clear all values */ 00436 free(d_list->list); 00437 d_list->list = NULL; 00438 00439 d_list->num = d_list->nall = d_list->elen = 0; 00440 00441 return 0; 00442 } |
|
Definition at line 373 of file list_struct.c. References free, int_list::list, int_list::nall, and int_list::num.
|
|
Definition at line 444 of file list_struct.c. References intp_list::elen, free, intp_list::list, intp_list::nall, and intp_list::num.
00445 { 00446 int count; 00447 00448 if ( !d_list ) return -1; 00449 00450 /* if nothing has been set, just clear values and return */ 00451 if ( d_list->num <= 0 ){ 00452 d_list->num = d_list->nall = d_list->elen = 0; 00453 d_list->list = NULL; 00454 return 0; 00455 } 00456 00457 /* this is bad, but nothing to do */ 00458 if ( !d_list->list ){ 00459 d_list->num = d_list->nall = d_list->elen = 0; 00460 return -1; 00461 } 00462 00463 /* first, free the nall lists (of length elen) */ 00464 00465 for ( count = 0; count < d_list->nall; count++ ) 00466 if ( d_list->list[count] ) free(d_list->list[count]); 00467 00468 /* now free the list and clear all values */ 00469 free(d_list->list); 00470 d_list->list = NULL; 00471 00472 d_list->num = d_list->nall = d_list->elen = 0; 00473 00474 return 0; 00475 } |
|
Definition at line 383 of file list_struct.c. References free, short_list::list, short_list::nall, and short_list::num.
|
|
Definition at line 477 of file list_struct.c. References shortp_list::elen, free, shortp_list::list, shortp_list::nall, and shortp_list::num.
00478 { 00479 int count; 00480 00481 if ( !d_list ) return -1; 00482 00483 /* if nothing has been set, just clear values and return */ 00484 if ( d_list->num <= 0 ){ 00485 d_list->num = d_list->nall = d_list->elen = 0; 00486 d_list->list = NULL; 00487 return 0; 00488 } 00489 00490 /* this is bad, but nothing to do */ 00491 if ( !d_list->list ){ 00492 d_list->num = d_list->nall = d_list->elen = 0; 00493 return -1; 00494 } 00495 00496 /* first, free the nall lists (of length elen) */ 00497 00498 for ( count = 0; count < d_list->nall; count++ ) 00499 if ( d_list->list[count] ) free(d_list->list[count]); 00500 00501 /* now free the list and clear all values */ 00502 free(d_list->list); 00503 d_list->list = NULL; 00504 00505 d_list->num = d_list->nall = d_list->elen = 0; 00506 00507 return 0; 00508 } |
|
Definition at line 393 of file list_struct.c. References free, void_list::list, void_list::nall, and void_list::num.
|
|
Definition at line 510 of file list_struct.c. References voidp_list::elen, free, voidp_list::list, voidp_list::nall, and voidp_list::num.
00511 { 00512 int count; 00513 00514 if ( !d_list ) return -1; 00515 00516 /* if nothing has been set, just clear values and return */ 00517 if ( d_list->num <= 0 ){ 00518 d_list->num = d_list->nall = d_list->elen = 0; 00519 d_list->list = NULL; 00520 return 0; 00521 } 00522 00523 /* this is bad, but nothing to do */ 00524 if ( !d_list->list ){ 00525 d_list->num = d_list->nall = d_list->elen = 0; 00526 return -1; 00527 } 00528 00529 /* first, free the nall lists (of length elen) */ 00530 00531 for ( count = 0; count < d_list->nall; count++ ) 00532 if ( d_list->list[count] ) free(d_list->list[count]); 00533 00534 /* now free the list and clear all values */ 00535 free(d_list->list); 00536 d_list->list = NULL; 00537 00538 d_list->num = d_list->nall = d_list->elen = 0; 00539 00540 return 0; 00541 } |
|
Definition at line 80 of file list_struct.c. References float_list::list, malloc, float_list::nall, and float_list::num.
00081 { 00082 if ( !d_list ) return -1; 00083 00084 if ( nel <= 0 ) { 00085 d_list->num = 0; d_list->nall = 0; d_list->list = NULL; 00086 return 0; 00087 } 00088 00089 d_list->list = (float *)malloc(nel * sizeof(float)); /* allocate memory */ 00090 00091 if ( d_list->list == NULL ) return -1; /* malloc failure */ 00092 00093 d_list->num = 0; 00094 d_list->nall = nel; 00095 00096 return nel; 00097 } |
|
Definition at line 167 of file list_struct.c. References floatp_list::elen, free, floatp_list::list, malloc, floatp_list::nall, and floatp_list::num.
00168 { 00169 int count; 00170 00171 if ( !d_list ) return -1; 00172 00173 /* an 'empty' structure will contain 0 and NULL field entries */ 00174 if ( nel <= 0 ) { 00175 d_list->num = d_list->nall = d_list->elen = 0; 00176 d_list->list = NULL; 00177 return 0; 00178 } 00179 00180 d_list->list = (float **)malloc(nel * sizeof(float *));/* allocate memory */ 00181 00182 if ( d_list->list == NULL ) return -1; /* malloc failure */ 00183 00184 d_list->num = 0; /* none used yet */ 00185 d_list->nall = nel; /* number of pointers allocated */ 00186 d_list->elen = len; /* length of each list */ 00187 00188 00189 /* now repeat the process for each pointer, allocating 'len' elements */ 00190 00191 /* trivial case, where the user requests no list allocation */ 00192 if ( len <= 0 ){ 00193 d_list->elen = 0; /* number of elements allocated */ 00194 for ( count = 0; count < nel; count++ ) 00195 d_list->list[count] = NULL; 00196 return nel; 00197 } 00198 00199 /* general case, the user wants data, too */ 00200 for ( count = 0; count < nel; count++ ){ 00201 d_list->list[count] = malloc(len * sizeof(float)); 00202 00203 /* on malloc failure, free() everything else, of course */ 00204 if ( d_list->list[count] == NULL ){ 00205 while ( --count >= 0 ) free(d_list->list[count]); 00206 free(d_list->list); 00207 return -1; 00208 } 00209 } 00210 00211 return nel; 00212 } |
|
Definition at line 99 of file list_struct.c. References int_list::list, malloc, int_list::nall, and int_list::num.
00100 { 00101 if ( !d_list ) return -1; 00102 00103 if ( nel <= 0 ) { 00104 d_list->num = 0; d_list->nall = 0; d_list->list = NULL; 00105 return 0; 00106 } 00107 00108 d_list->list = (int *)malloc(nel * sizeof(int)); /* allocate memory */ 00109 00110 if ( d_list->list == NULL ) return -1; /* malloc failure */ 00111 00112 d_list->num = 0; 00113 d_list->nall = nel; 00114 00115 return nel; 00116 } |
|
Definition at line 214 of file list_struct.c. References intp_list::elen, free, intp_list::list, malloc, intp_list::nall, and intp_list::num.
00215 { 00216 int count; 00217 00218 if ( !d_list ) return -1; 00219 00220 /* an 'empty' structure will contain 0 and NULL field entries */ 00221 if ( nel <= 0 ) { 00222 d_list->num = d_list->nall = d_list->elen = 0; 00223 d_list->list = NULL; 00224 return 0; 00225 } 00226 00227 d_list->list = (int **)malloc(nel * sizeof(int *)); /* allocate memory */ 00228 00229 if ( d_list->list == NULL ) return -1; /* malloc failure */ 00230 00231 d_list->num = 0; /* none used yet */ 00232 d_list->nall = nel; /* number of pointers allocated */ 00233 d_list->elen = len; /* length of each list */ 00234 00235 00236 /* now repeat the process for each pointer, allocating 'len' elements */ 00237 00238 /* trivial case, where the user requests no list allocation */ 00239 if ( len <= 0 ){ 00240 d_list->elen = 0; /* number of elements allocated */ 00241 for ( count = 0; count < nel; count++ ) 00242 d_list->list[count] = NULL; 00243 return nel; 00244 } 00245 00246 /* general case, the user wants data, too */ 00247 for ( count = 0; count < nel; count++ ){ 00248 d_list->list[count] = malloc(len * sizeof(int)); 00249 00250 /* on malloc failure, free() everything else, of course */ 00251 if ( d_list->list[count] == NULL ){ 00252 while ( --count >= 0 ) free(d_list->list[count]); 00253 free(d_list->list); 00254 return -1; 00255 } 00256 } 00257 00258 return nel; 00259 } |
|
Definition at line 118 of file list_struct.c. References short_list::list, malloc, short_list::nall, and short_list::num.
00119 { 00120 if ( !d_list ) return -1; 00121 00122 if ( nel <= 0 ) { 00123 d_list->num = 0; d_list->nall = 0; d_list->list = NULL; 00124 return 0; 00125 } 00126 00127 d_list->list = (short *)malloc(nel * sizeof(short)); /* allocate memory */ 00128 00129 if ( d_list->list == NULL ) return -1; /* malloc failure */ 00130 00131 d_list->num = 0; 00132 d_list->nall = nel; 00133 00134 return nel; 00135 } |
|
Definition at line 261 of file list_struct.c. References shortp_list::elen, free, shortp_list::list, malloc, shortp_list::nall, and shortp_list::num.
00262 { 00263 int count; 00264 00265 if ( !d_list ) return -1; 00266 00267 /* an 'empty' structure will contain 0 and NULL field entries */ 00268 if ( nel <= 0 ) { 00269 d_list->num = d_list->nall = d_list->elen = 0; 00270 d_list->list = NULL; 00271 return 0; 00272 } 00273 00274 d_list->list = (short **)malloc(nel * sizeof(short *));/* allocate memory */ 00275 00276 if ( d_list->list == NULL ) return -1; /* malloc failure */ 00277 00278 d_list->num = 0; /* none used yet */ 00279 d_list->nall = nel; /* number of pointers allocated */ 00280 d_list->elen = len; /* length of each list */ 00281 00282 00283 /* now repeat the process for each pointer, allocating 'len' elements */ 00284 00285 /* trivial case, where the user requests no list allocation */ 00286 if ( len <= 0 ){ 00287 d_list->elen = 0; /* number of elements allocated */ 00288 for ( count = 0; count < nel; count++ ) 00289 d_list->list[count] = NULL; 00290 return nel; 00291 } 00292 00293 /* general case, the user wants data, too */ 00294 for ( count = 0; count < nel; count++ ){ 00295 d_list->list[count] = malloc(len * sizeof(short)); 00296 00297 /* on malloc failure, free() everything else, of course */ 00298 if ( d_list->list[count] == NULL ){ 00299 while ( --count >= 0 ) free(d_list->list[count]); 00300 free(d_list->list); 00301 return -1; 00302 } 00303 } 00304 00305 return nel; 00306 } |
|
Definition at line 137 of file list_struct.c. References void_list::list, malloc, void_list::nall, and void_list::num.
00138 { 00139 if ( !d_list ) return -1; 00140 00141 if ( nel <= 0 ) { 00142 d_list->num = 0; d_list->nall = 0; d_list->list = NULL; 00143 return 0; 00144 } 00145 00146 /* special case, list is considered a list of bytes, so use char */ 00147 d_list->list = (void *)malloc(nel * sizeof(char)); /* allocate memory */ 00148 00149 if ( d_list->list == NULL ) return -1; /* malloc failure */ 00150 00151 d_list->num = 0; 00152 d_list->nall = nel; 00153 00154 return nel; 00155 } |
|
Definition at line 308 of file list_struct.c. References voidp_list::elen, free, voidp_list::list, malloc, voidp_list::nall, and voidp_list::num.
00309 { 00310 int count; 00311 00312 if ( !d_list ) return -1; 00313 00314 /* an 'empty' structure will contain 0 and NULL field entries */ 00315 if ( nel <= 0 ) { 00316 d_list->num = d_list->nall = d_list->elen = 0; 00317 d_list->list = NULL; 00318 return 0; 00319 } 00320 00321 d_list->list = (void **)malloc(nel * sizeof(void *)); /* allocate memory */ 00322 00323 if ( d_list->list == NULL ) return -1; /* malloc failure */ 00324 00325 d_list->num = 0; /* none used yet */ 00326 d_list->nall = nel; /* number of pointers allocated */ 00327 d_list->elen = len; /* length of each list */ 00328 00329 00330 /* now repeat the process for each pointer, allocating 'len' elements */ 00331 00332 /* trivial case, where the user requests no list allocation */ 00333 if ( len <= 0 ){ 00334 d_list->elen = 0; /* number of elements allocated */ 00335 for ( count = 0; count < nel; count++ ) 00336 d_list->list[count] = NULL; 00337 return nel; 00338 } 00339 00340 /* general case, the user wants data, too */ 00341 for ( count = 0; count < nel; count++ ){ 00342 /* again, the special case for void * is a list of bytes */ 00343 d_list->list[count] = malloc(len * sizeof(char)); 00344 00345 /* on malloc failure, free() everything else, of course */ 00346 if ( d_list->list[count] == NULL ){ 00347 while ( --count >= 0 ) free(d_list->list[count]); 00348 free(d_list->list); 00349 return -1; 00350 } 00351 } 00352 00353 return nel; 00354 } |