--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2005 Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "list.h"
+#include "list-internal.h"
+
+
+void *
+List_add(struct List *list, void const *data)
+{
+ return List_insertInternal(list, data, &list->root, 0)->data;
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2005 Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "list.h"
+#include "list-internal.h"
+
+void const *
+List_at_const(struct List const *l, size_t idx)
+{
+ struct ListItem const *itm = l->root;
+
+ for (; itm!=0 && idx>0; --idx)
+ itm = itm->next;
+
+ if (itm!=0) return itm->data;
+ else return 0;
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2005 Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "list.h"
+#include "list-internal.h"
+
+void
+List_free(struct List *list)
+{
+ for (struct ListItem *itm = list->root;
+ itm!=0;)
+ {
+ struct ListItem *next = itm->next;
+
+ free(itm->data);
+#ifndef NDEBUG
+ itm->data = (void *)(0xdeadbeaf);
+#endif
+ free(itm);
+
+ itm = next;
+ }
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2005 Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "list.h"
+
+void
+List_init(struct List *list, size_t elem_size)
+{
+ list->root = 0;
+ list->count = 0;
+ list->elem_size = elem_size;
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2005 Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "list.h"
+#include "list-internal.h"
+
+#include <assert.h>
+#include <string.h>
+
+#define ENSC_WRAPPERS_STDLIB 1
+#include <wrappers.h>
+
+struct ListItem *
+List_insertInternal(struct List *list, void const *data,
+ struct ListItem **before_pos,
+ struct ListItem *after_pos)
+{
+ struct ListItem *item = Emalloc(sizeof(struct ListItem));
+
+ assert((before_pos!=0 || after_pos!=0) &&
+ (before_pos==0 || after_pos==0));
+
+ item->data = Emalloc(list->elem_size);
+ memcpy(item->data, data, list->elem_size);
+
+ if (before_pos!=0) {
+ item->next = *before_pos;
+ *before_pos = item;
+ }
+ else {
+ item->next = after_pos->next;
+ after_pos->next = item;
+ }
+
+ ++list->count;
+
+ return item;
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2005 Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+
+#ifndef H_UTILVSERVER_VECTOR_LIST_INTERNAL_H
+#define H_UTILVSERVER_VECTOR_LIST_INTERNAL_H
+
+struct ListItem
+{
+ void *data;
+ struct ListItem *next;
+};
+
+struct ListItem * List_insertInternal(struct List *list,
+ void const *data,
+ struct ListItem **before_pos,
+ struct ListItem *after_pos);
+
+#endif // H_UTILVSERVER_VECTOR_LIST_INTERNAL_H
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2005 Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "list.h"
+#include "list-internal.h"
+
+void const *
+List_search(struct List const *list, void const *key,
+ int (*compare)(const void *, const void *))
+{
+ struct ListItem const *itm = list->root;
+
+ while (itm!=0 && compare(itm->data, key)!=0)
+ itm = itm->next;
+
+ if (itm!=0) return itm->data;
+ else return 0;
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2005 Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "list.h"
+#include "list-internal.h"
+
+#include <assert.h>
+#include <stdbool.h>
+
+void const *
+List_searchSelfOrg(struct List const *list, void const *key,
+ int (*compare)(const void *, const void *),
+ ListSelfOrgMethod method)
+{
+ struct List *list_v = (struct List *)(list);
+ struct ListItem **itm = &list_v->root;
+
+ switch (method) {
+ case listMOVE_FRONT :
+ while (*itm!=0 && compare((*itm)->data, key)!=0)
+ itm = &(*itm)->next;
+
+ if (*itm && *itm!=list->root) {
+ struct ListItem *res = *itm;
+
+ *itm = res->next;
+ res->next = list->root;
+ list_v->root = res;
+
+ itm = &list_v->root;
+ }
+ break;
+
+ case listSHIFT_ONCE :
+ if (*itm!=0 && compare((*itm)->data, key)!=0) {
+ while ((*itm)->next!=0 &&
+ compare((*itm)->next->data, key)!=0)
+ itm = &(*itm)->next;
+
+ if ((*itm)->next==0)
+ itm = &(*itm)->next;
+ else {
+ struct ListItem *res = (*itm)->next;
+
+ (*itm)->next = res->next;
+ res->next = *itm;
+ *itm = res;
+ }
+ }
+ break;
+
+ default : assert(false); return 0;
+ }
+
+ if (*itm!=0) return (*itm)->data;
+ else return 0;
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2005 Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+
+#ifndef H_UTILVSERVER_VECTOR_LIST_H
+#define H_UTILVSERVER_VECTOR_LIST_H
+
+#include <stdlib.h>
+
+struct ListItem;
+struct List
+{
+ struct ListItem *root;
+ size_t count;
+ size_t elem_size;
+};
+
+typedef enum { listMOVE_FRONT, listSHIFT_ONCE } ListSelfOrgMethod;
+
+void List_init(struct List *, size_t elem_size);
+void List_free(struct List *);
+void * List_add(struct List *, void const *key);
+void * List_at(struct List *, size_t idx);
+void const * List_at_const(struct List const *, size_t idx);
+
+void const * List_search(struct List const *, void const *key,
+ int (*compare)(const void *, const void *));
+
+void const * List_searchSelfOrg(struct List const *, void const *key,
+ int (*compare)(const void *, const void *),
+ ListSelfOrgMethod method);
+
+#endif // H_UTILVSERVER_VECTOR_LIST_H
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2005 Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+
+static inline UNUSED void *
+List_at(struct List *list, size_t idx)
+{
+ return (void *)(List_at_const(list, idx));
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2005 Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "ensc_vector/list.h"
+#include "ensc_vector/list-internal.h"
+
+#include <assert.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+int wrapper_exit_code = 2;
+
+static int
+cmp(void const *lhs_v, void const *rhs_v)
+{
+ int const * const lhs = lhs_v;
+ int const * const rhs = rhs_v;
+
+ return *lhs - *rhs;
+}
+
+struct List l;
+
+
+static void A(int val)
+{
+ int * res = List_add(&l, &val);
+
+ assert(*res == val);
+}
+
+static int const * S(int val)
+{
+ return List_search(&l, &val, cmp);
+}
+
+static int const * SSO_F(int val)
+{
+ return List_searchSelfOrg(&l, &val, cmp, listMOVE_FRONT);
+}
+
+static int const * SSO_S(int val)
+{
+ return List_searchSelfOrg(&l, &val, cmp, listSHIFT_ONCE);
+}
+
+static int P(size_t idx)
+{
+ int const *res = List_at_const(&l, idx);
+
+ assert(res!=0);
+ return *res;
+}
+
+static bool P0(size_t idx)
+{
+ return List_at_const(&l, idx) == 0;
+}
+
+static bool CMP(int const *lhs, int rhs)
+{
+ return (lhs!=0 && *lhs==rhs) || (lhs==0 && rhs==-1);
+}
+
+
+int main()
+{
+ List_init(&l, sizeof(int));
+
+ A(5); A(4); A(3); A(2); A(1); A(0);
+ assert(P(0)==0 && P(1)==1 && P(2)==2 && P(3)==3 && P(4)==4 && P(5)==5 && P0(6));
+
+ assert(CMP(S(5), 5) && CMP(S(2), 2) && CMP(S(0), 0));
+ assert(CMP(S(42),-1));
+
+ assert(CMP(SSO_F(5), 5));
+ assert(P(0)==5 && P(1)==0 && P(2)==1 && P(3)==2 && P(4)==3 && P(5)==4 && P0(6));
+
+ assert(CMP(SSO_F(5), 5));
+ assert(P(0)==5 && P(1)==0 && P(2)==1 && P(3)==2 && P(4)==3 && P(5)==4 && P0(6));
+
+ assert(CMP(SSO_F(0), 0));
+ assert(P(0)==0 && P(1)==5 && P(2)==1 && P(3)==2 && P(4)==3 && P(5)==4 && P0(6));
+
+ assert(CMP(SSO_F(4), 4));
+ assert(P(0)==4 && P(1)==0 && P(2)==5 && P(3)==1 && P(4)==2 && P(5)==3 && P0(6));
+
+ assert(CMP(SSO_F(5), 5));
+ assert(P(0)==5 && P(1)==4 && P(2)==0 && P(3)==1 && P(4)==2 && P(5)==3 && P0(6));
+
+ assert(CMP(SSO_F(42),-1));
+ assert(P(0)==5 && P(1)==4 && P(2)==0 && P(3)==1 && P(4)==2 && P(5)==3 && P0(6));
+
+
+
+ assert(CMP(SSO_S(3), 3));
+ assert(P(0)==5 && P(1)==4 && P(2)==0 && P(3)==1 && P(4)==3 && P(5)==2 && P0(6));
+
+ assert(CMP(SSO_S(3), 3));
+ assert(P(0)==5 && P(1)==4 && P(2)==0 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));
+
+ assert(CMP(SSO_S(5), 5));
+ assert(P(0)==5 && P(1)==4 && P(2)==0 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));
+
+ assert(CMP(SSO_S(4), 4));
+ assert(P(0)==4 && P(1)==5 && P(2)==0 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));
+
+ assert(CMP(SSO_S(0), 0));
+ assert(P(0)==4 && P(1)==0 && P(2)==5 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));
+
+ assert(CMP(SSO_S(0), 0));
+ assert(P(0)==0 && P(1)==4 && P(2)==5 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));
+
+ assert(CMP(SSO_S(0), 0));
+ assert(P(0)==0 && P(1)==4 && P(2)==5 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));
+
+ assert(CMP(SSO_S(42), -1));
+ assert(P(0)==0 && P(1)==4 && P(2)==5 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));
+
+ List_free(&l);
+
+ return EXIT_SUCCESS;
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2005 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "vector.h"
+#include "vector-internal.h"
+
+#include <string.h>
+#include <assert.h>
+#include <stdbool.h>
+
+void *
+Vector_searchSelfOrg(struct Vector *vec, void const *key,
+ int (*compare)(const void *, const void *),
+ VectorSelfOrgMethod method)
+{
+ char * const start_ptr = vec->data;
+ char * const end_ptr = start_ptr + vec->count*vec->elem_size;
+ char *ptr = start_ptr;
+
+ for (; ptr<end_ptr && compare(ptr, key)!=0; )
+ ptr += vec->elem_size;
+
+ if (end_ptr <= ptr) ptr = 0;
+ else if (start_ptr < ptr) {
+ char tmp[vec->elem_size];
+ memcpy(tmp, ptr, vec->elem_size);
+
+ assert(ptr >= start_ptr+vec->elem_size);
+
+ switch (method) {
+ case vecMOVE_FRONT :
+ memmove(start_ptr+vec->elem_size, start_ptr, ptr - start_ptr);
+
+ ptr = start_ptr;
+ break;
+
+ case vecSHIFT_ONCE :
+ memmove(ptr, ptr - vec->elem_size, vec->elem_size);
+ ptr -= vec->elem_size;
+ break;
+
+ default :
+ assert(false);
+ ptr = 0;
+ }
+
+ memcpy (ptr, tmp, vec->elem_size);
+ }
+
+ return ptr;
+}
+
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2005 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "unify.h"
+#include "vserver.h"
+
+
+bool
+Unify_isIUnlinkable(char const *filename)
+{
+ uint_least32_t const V = VC_IATTR_IUNLINK|VC_IATTR_IMMUTABLE;
+
+ uint_least32_t flags;
+ uint_least32_t mask = V;
+
+ return (vc_get_iattr(filename, 0, &flags, &mask)!=-1 &&
+ (mask & V)==V &&
+ (flags & V)!=V);
+}