/misc/src/release/graphviz-2.18-1/src/graphviz-2.18/lib/cdt/dtrestore.c

Go to the documentation of this file.
00001 /* $Id: dtrestore.c,v 1.1.1.1 2004/12/23 04:04:00 ellson Exp $ $Revision: 1.1.1.1 $ */
00002 /* vim:set shiftwidth=4 ts=8: */
00003 
00004 /**********************************************************
00005 *      This software is part of the graphviz package      *
00006 *                http://www.graphviz.org/                 *
00007 *                                                         *
00008 *            Copyright (c) 1994-2004 AT&T Corp.           *
00009 *                and is licensed under the                *
00010 *            Common Public License, Version 1.0           *
00011 *                      by AT&T Corp.                      *
00012 *                                                         *
00013 *        Information and Software Systems Research        *
00014 *              AT&T Research, Florham Park NJ             *
00015 **********************************************************/
00016 
00017 #include        "dthdr.h"
00018 
00019 #ifdef DMALLOC
00020 #include "dmalloc.h"
00021 #endif
00022 
00023 /*      Restore dictionary from given tree or list of elements.
00024 **      There are two cases. If called from within, list is nil.
00025 **      From without, list is not nil and data->size must be 0.
00026 **
00027 **      Written by Kiem-Phong Vo (5/25/96)
00028 */
00029 
00030 #if __STD_C
00031 int dtrestore(reg Dt_t * dt, reg Dtlink_t * list)
00032 #else
00033 int dtrestore(dt, list)
00034 reg Dt_t *dt;
00035 reg Dtlink_t *list;
00036 #endif
00037 {
00038     reg Dtlink_t *t, **s, **ends;
00039     reg int type;
00040     reg Dtsearch_f searchf = dt->meth->searchf;
00041 
00042     type = dt->data->type & DT_FLATTEN;
00043     if (!list) {                /* restoring a flattened dictionary */
00044         if (!type)
00045             return -1;
00046         list = dt->data->here;
00047     } else {                    /* restoring an extracted list of elements */
00048         if (dt->data->size != 0)
00049             return -1;
00050         type = 0;
00051     }
00052     dt->data->type &= ~DT_FLATTEN;
00053 
00054     if (dt->data->type & (DT_SET | DT_BAG)) {
00055         dt->data->here = NIL(Dtlink_t *);
00056         if (type) {             /* restoring a flattened dictionary */
00057             for (ends = (s = dt->data->htab) + dt->data->ntab; s < ends;
00058                  ++s) {
00059                 if ((t = *s)) {
00060                     *s = list;
00061                     list = t->right;
00062                     t->right = NIL(Dtlink_t *);
00063                 }
00064             }
00065         } else {                /* restoring an extracted list of elements */
00066             dt->data->size = 0;
00067             while (list) {
00068                 t = list->right;
00069                 (*searchf) (dt, (Void_t *) list, DT_RENEW);
00070                 list = t;
00071             }
00072         }
00073     } else {
00074         if (dt->data->type & (DT_OSET | DT_OBAG))
00075             dt->data->here = list;
00076         else {                  /*if(dt->data->type&(DT_LIST|DT_STACK|DT_QUEUE)) */
00077             dt->data->here = NIL(Dtlink_t *);
00078             dt->data->head = list;
00079         }
00080         if (!type)
00081             dt->data->size = -1;
00082     }
00083 
00084     return 0;
00085 }

Generated on Mon Mar 31 19:03:23 2008 for Graphviz by  doxygen 1.5.1