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
00029
00030
00031
00032
00033
00034
00035
00036
#include <stdlib.h>
00037
#include "idliste.h"
00038
#include "idprint.h"
00039
00040
00041
00042
00043
00044
00053
void
00054 _IdFreeElement(
PLIST_ELEMENT p,
int d)
00055 {
00056
if (p) {
00057
_IdFreeElement(p->
Next,
d);
00058
if (
d)
00059
_IdFreeElement(p->
Pred,
d);
00060 free(p);
00061 }
00062 }
00063
00069
void
00070 _IdLstFree(
PLIST * lst)
00071 {
00072
PLIST_ELEMENT p;
00073
int m;
00074
00075
if (*lst) {
00076
if (
_IdLstPrivate(*lst)->_message)
00077 free((
_IdLstPrivate(*lst)->_message));
00078
_IdLstPrivate(*lst)->_message = 0;
00079 if (
_IdLstPrivate(*lst)->_fichier)
00080 free((
_IdLstPrivate(*lst)->_fichier));
00081
_IdLstPrivate(*lst)->_fichier = 0;
00082
00083 if (
IdLstNbElems(*lst) != 0) {
00084 p =
IdLstList(*lst);
00085 m = 1;
00086
if (p->
Next)
00087
if (p->
Next->
Pred == p)
00088 m = 0;
00089
00090
_IdFreeElement(p, m);
00091 }
00092 free(
_IdLstPrivate(*lst));
00093 *lst = 0;
00094 }
00095 }
00096
00103 PLIST_ELEMENT _IdLstAllocElement(
void)
00104 {
00105
void *p = calloc(
sizeof(
LIST_ELEMENT), 1);
00106
00107
if (!p)
00108
IdErrPrintf
00109 (
"Echec d'allocation d'element de liste. Memoire saturee.");
00110
return (
PLIST_ELEMENT) p;
00111 }
00112
00120
PLIST
00121 IdLstAlloc(
void)
00122 {
00123
PRIVATE_LIST *si;
00124
00125 si = (
PRIVATE_LIST *) calloc(
sizeof(
PRIVATE_LIST), 1);
00126
if (si) {
00127 si->
Type =
LST;
00128 si->
_message = 0;
00129 si->
_fichier = 0;
00130 }
else {
00131
IdErrPrintf
00132 (
"Echec d'allocation 'partie privee' de liste.");
00133 }
00134
00135
return ((
PLIST) & (si[1]));
00136 }
00137
00146
PLIST_ELEMENT
00147 IdLstSearchElemObj(
PLIST pl,
void *obj)
00148 {
00149
PLIST_ELEMENT el;
00150 el =
IdLstFirst(pl);
00151
while (el) {
00152
if (el->
Object == obj) {
00153
return ((
PLIST_ELEMENT) el);
00154 }
00155 el = el->
Next;
00156 }
00157
return (0);
00158 }
00159
00182
PLIST_ELEMENT
00183 IdLstFindElem(
PLIST pl,
00184
int (*UserCompareFonc) (
PLIST_ELEMENT,
void *),
00185
void *key)
00186 {
00187
PLIST_ELEMENT el;
00188 el =
IdLstFirst(pl);
00189
while (el) {
00190
if (UserCompareFonc(el, key) == 0)
00191
return (el);
00192 el = el->
Next;
00193 }
00194
return (0);
00195 }
00196
00206
void
00207 _IdLstDestroyNoControl(
PLIST * lst,
00208 VOID_FUNCTION_VOIDP_POINTER foncDestr)
00209 {
00210
PLIST_ELEMENT e;
00211
if (!*lst)
00212
return;
00213 e =
IdLstFirst(*lst);
00214
while (e != NULL) {
00215 foncDestr(
IdLstPtrObj(e));
00216 e =
IdLstNext(e);
00217 }
00218
_IdLstFree(lst);
00219 }
00220
00230
void
00231 IdLstClear(
PLIST lst)
00232 {
00233
PLIST_ELEMENT e, suiv;
00234
if (!lst)
00235
return;
00236 e =
IdLstFirst(lst);
00237
while (e != NULL) {
00238 suiv =
IdLstNext(e);
00239
IdLstRemoveElem(lst, e);
00240 e = suiv;
00241 }
00242 }
00243
00255
void
00256 IdLstDestroyElemNoControl(
PLIST lst,
00257
PLIST_ELEMENT elem,
00258 VOID_FUNCTION_VOIDP_POINTER foncDestr)
00259 {
00260
if (!lst)
00261
return;
00262
if (!elem)
00263
return;
00264 foncDestr(
IdLstPtrObj(elem));
00265
IdLstRemoveElem(lst, elem);
00266 }
00267
00275
PLIST
00276 IdLstCopy(
PLIST lst)
00277 {
00278
PLIST_ELEMENT ed;
00279
PRIVATE_LIST *si;
00280
PLIST lstResult;
00281
int retCode;
00282
00283
if (!lst)
00284
return ((
PLIST) NULL);
00285
00286 si = (
PRIVATE_LIST *) calloc(
sizeof(
PRIVATE_LIST), 1);
00287
if (si) {
00288 si->
Type =
LST;
00289 si->
_message = 0;
00290 si->
_fichier = 0;
00291 }
else {
00292
IdErrPrintf
00293 (
"Echec allocation 'partie privee' de liste.\n");
00294
return ((
PLIST) NULL);
00295 }
00296
00297 lstResult = (
PLIST) & (si[1]);
00298
00299 ed =
IdLstFirst(lst);
00300
00301
while (ed != NULL) {
00302 retCode =
IdLstAddLast(lstResult,
IdLstPtrObj(ed));
00303
if (!retCode) {
00304
IdErrPrintf
00305 (
"Echec allocation 'Element' de liste.\n");
00306
return ((
PLIST) NULL);
00307 }
00308 ed =
IdLstNext(ed);
00309 }
00310
00311
return (lstResult);
00312 }
00313