Graphviz 2.29.20120208.0545
lib/cdt/dtrestore.c
Go to the documentation of this file.
00001 #include        "dthdr.h"
00002 
00003 /*      Restore dictionary from given tree or list of elements.
00004 **      There are two cases. If called from within, list is nil.
00005 **      From without, list is not nil and data->size must be 0.
00006 **
00007 **      Written by Kiem-Phong Vo (5/25/96)
00008 */
00009 
00010 #if __STD_C
00011 int dtrestore(reg Dt_t* dt, reg Dtlink_t* list)
00012 #else
00013 int dtrestore(dt, list)
00014 reg Dt_t*       dt;
00015 reg Dtlink_t*   list;
00016 #endif
00017 {
00018         reg Dtlink_t    *t, **s, **ends;
00019         reg int         type;
00020         reg Dtsearch_f  searchf = dt->meth->searchf;
00021 
00022         type = dt->data->type&DT_FLATTEN;
00023         if(!list) /* restoring a flattened dictionary */
00024         {       if(!type)
00025                         return -1;
00026                 list = dt->data->here;
00027         }
00028         else    /* restoring an extracted list of elements */
00029         {       if(dt->data->size != 0)
00030                         return -1;
00031                 type = 0;
00032         }
00033         dt->data->type &= ~DT_FLATTEN;
00034 
00035         if(dt->data->type&(DT_SET|DT_BAG))
00036         {       dt->data->here = NIL(Dtlink_t*);
00037                 if(type) /* restoring a flattened dictionary */
00038                 {       for(ends = (s = dt->data->htab) + dt->data->ntab; s < ends; ++s)
00039                         {       if((t = *s) )
00040                                 {       *s = list;
00041                                         list = t->right;
00042                                         t->right = NIL(Dtlink_t*);
00043                                 }
00044                         }
00045                 }
00046                 else    /* restoring an extracted list of elements */
00047                 {       dt->data->size = 0;
00048                         while(list)
00049                         {       t = list->right;
00050                                 (*searchf)(dt,(Void_t*)list,DT_RENEW);
00051                                 list = t;
00052                         }
00053                 }
00054         }
00055         else
00056         {       if(dt->data->type&(DT_OSET|DT_OBAG))
00057                         dt->data->here = list;
00058                 else /*if(dt->data->type&(DT_LIST|DT_STACK|DT_QUEUE))*/
00059                 {       dt->data->here = NIL(Dtlink_t*);
00060                         dt->data->head = list;
00061                 }
00062                 if(!type)
00063                         dt->data->size = -1;
00064         }
00065 
00066         return 0;
00067 }