Index: Singular/Makefile.am
===================================================================
--- Singular/Makefile.am	(revision 4fb3a73a9ab769b9cdb2ec0db33cdbf9e88bfedd)
+++ Singular/Makefile.am	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
@@ -68,15 +68,15 @@
    minpoly.cc\
    misc_ip.cc\
-   ndbm.cc\
+   links/ndbm.cc\
    newstruct.cc\
    pcv.cc\
-   pipeLink.cc\
+   links/pipeLink.cc\
    scanner.cc\
    sdb.cc\
-   silink.cc\
-   sing_dbm.cc\
+   links/silink.cc\
+   links/sing_dbm.cc\
    sing_win.cc\
    slInit_Static.cc\
-   ssiLink.cc\
+   links/ssiLink.cc\
    subexpr.cc\
    walk.cc\
@@ -99,5 +99,5 @@
    blackbox.h \
    cntrlc.h \
-   dbm_sl.h \
+   links/dbm_sl.h \
    distrib.h \
    eigenval_ip.h \
@@ -123,16 +123,16 @@
    mmalloc.h \
    omSingularConfig.h \
-   ndbm.h \
+   links/ndbm.h \
    newstruct.h \
    pcv.h \
-   pipeLink.h \
+   links/pipeLink.h \
    pyobject_setup.h \
    run.h \
    sdb.h \
    silink.h \
-   sing_dbm.h \
+   links/sing_dbm.h \
    sing_win.h \
    slInit.h \
-   ssiLink.h \
+   links/ssiLink.h \
    static.h \
    stype.h \
Index: ngular/dbm_sl.h
===================================================================
--- Singular/dbm_sl.h	(revision 4fb3a73a9ab769b9cdb2ec0db33cdbf9e88bfedd)
+++ 	(revision )
@@ -1,15 +1,0 @@
-/****************************************
-*  Computer Algebra System SINGULAR     *
-****************************************/
-/***************************************************************
- *  File:    dbm_sl.h
- *  Purpose: declaration of sl_link routines for dbm
- *  Author:  obachman (Olaf Bachmann)
- *  Created: 12/00
- *******************************************************************/
-LINKAGE BOOLEAN dbOpen(si_link l, short flag, leftv u);
-LINKAGE BOOLEAN dbWrite(si_link l, leftv v);
-LINKAGE leftv dbRead1(si_link l);
-LINKAGE leftv dbRead2(si_link l, leftv key);
-LINKAGE BOOLEAN dbClose(si_link l);
-
Index: Singular/links/dbm_sl.h
===================================================================
--- Singular/links/dbm_sl.h	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
+++ Singular/links/dbm_sl.h	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
@@ -0,0 +1,15 @@
+/****************************************
+*  Computer Algebra System SINGULAR     *
+****************************************/
+/***************************************************************
+ *  File:    dbm_sl.h
+ *  Purpose: declaration of sl_link routines for dbm
+ *  Author:  obachman (Olaf Bachmann)
+ *  Created: 12/00
+ *******************************************************************/
+LINKAGE BOOLEAN dbOpen(si_link l, short flag, leftv u);
+LINKAGE BOOLEAN dbWrite(si_link l, leftv v);
+LINKAGE leftv dbRead1(si_link l);
+LINKAGE leftv dbRead2(si_link l, leftv key);
+LINKAGE BOOLEAN dbClose(si_link l);
+
Index: Singular/links/ndbm.cc
===================================================================
--- Singular/links/ndbm.cc	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
+++ Singular/links/ndbm.cc	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
@@ -0,0 +1,566 @@
+/****************************************
+*  Computer Algebra System SINGULAR     *
+****************************************/
+
+//**************************************************************************/
+//
+//
+//**************************************************************************/
+// 'ndbm.cc' containes all low-level functions to manipulate dbm-files
+// for the original Copyright of this file and 'ndbm.h' see below .
+//
+// some minor change where needed to compile and run under MacOS/MPW
+//
+//**************************************************************************/
+
+#include "config.h"
+#include <kernel/mod2.h>
+#ifdef HAVE_DBM
+#ifndef HPUX_9
+#include <strings.h>
+#endif
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ * for details see ndbm.h
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)ndbm.c        5.3 (Berkeley) 3/9/86";
+#endif
+
+//**************************************************************************/
+
+#include <stdio.h>
+/* alternative:
+* #   define EPERM 1
+* #   define ENOMEM 23
+* #   define ENOSPC 28
+* #   define L_SET SEEK_SET
+*/
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/file.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#ifndef HAVE_BCOPY
+#   define bcopy(a,b,c) memmove(b,a,c)
+#endif /* not HAVE_BCOPY */
+#include <Singular/links/ndbm.h>
+
+#define BYTESIZ 8
+#undef setbit
+
+static  void dbm_access(register DBM *db, long hash);
+static  int getbit(register DBM *db);
+static  void setbit(register DBM *db);
+static  datum makdatum(char buf[PBLKSIZ], int n);
+static  int finddatum(char buf[PBLKSIZ], datum item);
+static  long hashinc(register DBM *db, long hash);
+static  long dcalchash(datum item);
+static  int delitem(char buf[PBLKSIZ], int n);
+static  int additem(char buf[PBLKSIZ], datum item, datum item1);
+// extern  int errno;
+extern "C" int singular_fstat(int fd, struct stat *buf);
+
+DBM * dbm_open(char *file, int flags, int mode)
+{
+  struct stat statb;
+  register DBM *db;
+
+  if ((db = (DBM *)malloc(sizeof *db)) == 0)
+  {
+    errno = ENOMEM;
+    return ((DBM *)0);
+  }
+#ifdef MSDOS
+  // default mode of open is ascii, we need binary mode.
+  flags |= O_BINARY;
+#endif
+  db->dbm_flags = (flags & 03) == O_RDONLY ? _DBM_RDONLY : 0;
+  if ((flags & 03) == O_WRONLY)
+    flags = (flags & ~03) | O_RDWR;
+  strcpy(db->dbm_pagbuf, file);
+  strcat(db->dbm_pagbuf, ".pag");
+  db->dbm_pagf = open(db->dbm_pagbuf, flags, mode);
+  if (db->dbm_pagf < 0)
+    goto bad;
+  strcpy(db->dbm_pagbuf, file);
+  strcat(db->dbm_pagbuf, ".dir");
+  db->dbm_dirf = open(db->dbm_pagbuf, flags, mode);
+  if (db->dbm_dirf < 0)
+    goto bad1;
+  singular_fstat(db->dbm_dirf, &statb);
+  db->dbm_maxbno = statb.st_size*BYTESIZ-1;
+  db->dbm_pagbno = db->dbm_dirbno = -1;
+  return (db);
+bad1:
+  (void) close(db->dbm_pagf);
+bad:
+  free((char *)db);
+  return ((DBM *)0);
+}
+
+void dbm_close(DBM *db)
+{
+  (void) close(db->dbm_dirf);
+  (void) close(db->dbm_pagf);
+  free((char *)db);
+}
+
+long dbm_forder(register DBM *db, datum key)
+{
+  long hash;
+
+  hash = dcalchash(key);
+  for (db->dbm_hmask=0;; db->dbm_hmask=(db->dbm_hmask<<1)+1)
+  {
+    db->dbm_blkno = hash & db->dbm_hmask;
+    db->dbm_bitno = db->dbm_blkno + db->dbm_hmask;
+    if (getbit(db) == 0)
+      break;
+  }
+  return (db->dbm_blkno);
+}
+
+datum dbm_fetch(register DBM *db, datum key)
+{
+  register int i;
+  datum item;
+
+  if (dbm_error(db))
+    goto err;
+  dbm_access(db, dcalchash(key));
+  if ((i = finddatum(db->dbm_pagbuf, key)) >= 0)
+  {
+    item = makdatum(db->dbm_pagbuf, i+1);
+    if (item.dptr != NULL)
+      return (item);
+  }
+err:
+  item.dptr = NULL;
+  item.dsize = 0;
+  return (item);
+}
+
+int dbm_delete(register DBM *db, datum key)
+{
+  register int i;
+  datum item;
+
+  if (dbm_error(db))
+    return (-1);
+  if (dbm_rdonly(db))
+  {
+    errno = EPERM;
+    return (-1);
+  }
+  dbm_access(db, dcalchash(key));
+  if ((i = finddatum(db->dbm_pagbuf, key)) < 0)
+    return (-1);
+  if (!delitem(db->dbm_pagbuf, i))
+    goto err;
+  db->dbm_pagbno = db->dbm_blkno;
+  (void) lseek(db->dbm_pagf, db->dbm_blkno*PBLKSIZ, L_SET);
+  if (write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ)
+  {
+  err:
+    db->dbm_flags |= _DBM_IOERR;
+    return (-1);
+  }
+  return (0);
+}
+
+int dbm_store(register DBM *db, datum key, datum dat, int replace)
+{
+  register int i;
+  int ret;
+  datum item, item1;
+  char ovfbuf[PBLKSIZ];
+
+  if (dbm_error(db))
+    return (-1);
+  if (dbm_rdonly(db))
+  {
+    errno = EPERM;
+    return (-1);
+  }
+   
+_loop:
+  dbm_access(db, dcalchash(key));
+  if ((i = finddatum(db->dbm_pagbuf, key)) >= 0)
+  {
+    if (!replace)
+      return (1);
+    if (!delitem(db->dbm_pagbuf, i))
+    {
+      db->dbm_flags |= _DBM_IOERR;
+      return (-1);
+    }
+  }
+  if (!additem(db->dbm_pagbuf, key, dat))
+    goto split;
+  db->dbm_pagbno = db->dbm_blkno;
+  (void) lseek(db->dbm_pagf, db->dbm_blkno*PBLKSIZ, L_SET);
+  if ( (ret=write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ)) != PBLKSIZ)
+  {
+    db->dbm_flags |= _DBM_IOERR;
+    return (-1);
+  }
+  return (0);
+
+split:
+  if (key.dsize+dat.dsize+3*sizeof(short) >= PBLKSIZ)
+  {
+    db->dbm_flags |= _DBM_IOERR;
+    errno = ENOSPC;
+    return (-1);
+  }
+  memset(ovfbuf, 0, PBLKSIZ);
+  for (i=0;;) {
+    item = makdatum(db->dbm_pagbuf, i);
+    if (item.dptr == NULL)
+      break;
+    if (dcalchash(item) & (db->dbm_hmask+1))
+    {
+      item1 = makdatum(db->dbm_pagbuf, i+1);
+      if (item1.dptr == NULL) {
+        fprintf(stderr, "ndbm: split not paired\n");
+        db->dbm_flags |= _DBM_IOERR;
+        break;
+      }
+      if (!additem(ovfbuf, item, item1) ||
+          !delitem(db->dbm_pagbuf, i))
+      {
+        db->dbm_flags |= _DBM_IOERR;
+        return (-1);
+      }
+      continue;
+    }
+    i += 2;
+  }
+  db->dbm_pagbno = db->dbm_blkno;
+  (void) lseek(db->dbm_pagf, db->dbm_blkno*PBLKSIZ, L_SET);
+  if (write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ)
+  {
+    db->dbm_flags |= _DBM_IOERR;
+    return (-1);
+  }
+  (void) lseek(db->dbm_pagf, (db->dbm_blkno+db->dbm_hmask+1)*PBLKSIZ, L_SET);
+  if (write(db->dbm_pagf, ovfbuf, PBLKSIZ) != PBLKSIZ)
+  {
+    db->dbm_flags |= _DBM_IOERR;
+    return (-1);
+  }
+  setbit(db);
+  goto _loop;
+}
+
+datum dbm_firstkey(DBM *db)
+{
+
+  db->dbm_blkptr = 0L;
+  db->dbm_keyptr = 0;
+  return (dbm_nextkey(db));
+}
+
+datum dbm_nextkey(register DBM *db)
+{
+  struct stat statb;
+  datum item;
+
+  if (dbm_error(db) 
+       || singular_fstat(db->dbm_pagf, &statb) < 0
+  )
+                goto err;
+  statb.st_size /= PBLKSIZ;
+  for (;;)
+  {
+    if (db->dbm_blkptr != db->dbm_pagbno)
+    {
+      db->dbm_pagbno = db->dbm_blkptr;
+      (void) lseek(db->dbm_pagf, db->dbm_blkptr*PBLKSIZ, L_SET);
+      if (read(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ)
+        memset(db->dbm_pagbuf, 0, PBLKSIZ);
+#ifdef DEBUG
+      else if (chkblk(db->dbm_pagbuf) < 0)
+        db->dbm_flags |= _DBM_IOERR;
+#endif
+    }
+    if (((short *)db->dbm_pagbuf)[0] != 0)
+    {
+      item = makdatum(db->dbm_pagbuf, db->dbm_keyptr);
+      if (item.dptr != NULL)
+      {
+        db->dbm_keyptr += 2;
+        return (item);
+      }
+      db->dbm_keyptr = 0;
+    }
+    if (++db->dbm_blkptr >= statb.st_size)
+      break;
+  }
+err:
+  item.dptr = NULL;
+  item.dsize = 0;
+  return (item);
+}
+
+static void dbm_access(register DBM *db, long hash)
+{
+  for (db->dbm_hmask=0;; db->dbm_hmask=(db->dbm_hmask<<1)+1)
+  {
+    db->dbm_blkno = hash & db->dbm_hmask;
+    db->dbm_bitno = db->dbm_blkno + db->dbm_hmask;
+    if (getbit(db) == 0)
+      break;
+  }
+  if (db->dbm_blkno != db->dbm_pagbno)
+  {
+    db->dbm_pagbno = db->dbm_blkno;
+    (void) lseek(db->dbm_pagf, db->dbm_blkno*PBLKSIZ, L_SET);
+    if (read(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ)
+      memset(db->dbm_pagbuf, 0, PBLKSIZ);
+#ifdef DEBUG
+    else if (chkblk(db->dbm_pagbuf) < 0)
+      db->dbm_flags |= _DBM_IOERR;
+#endif
+  }
+}
+
+static int getbit(register DBM *db)
+{
+  long bn;
+  register int b, i, n;
+
+
+  if (db->dbm_bitno > db->dbm_maxbno)
+    return (0);
+  n = db->dbm_bitno % BYTESIZ;
+  bn = db->dbm_bitno / BYTESIZ;
+  i = bn % DBLKSIZ;
+  b = bn / DBLKSIZ;
+  if (b != db->dbm_dirbno)
+  {
+    db->dbm_dirbno = b;
+    (void) lseek(db->dbm_dirf, (long)b*DBLKSIZ, L_SET);
+    if (read(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ)
+      memset(db->dbm_dirbuf, 0, DBLKSIZ);
+  }
+  return (db->dbm_dirbuf[i] & (1<<n));
+}
+
+static void setbit(register DBM *db)
+{
+  long bn;
+  register int i, n, b;
+
+  if (db->dbm_bitno > db->dbm_maxbno)
+    db->dbm_maxbno = db->dbm_bitno;
+  n = db->dbm_bitno % BYTESIZ;
+  bn = db->dbm_bitno / BYTESIZ;
+  i = bn % DBLKSIZ;
+  b = bn / DBLKSIZ;
+  if (b != db->dbm_dirbno)
+  {
+    db->dbm_dirbno = b;
+    (void) lseek(db->dbm_dirf, (long)b*DBLKSIZ, L_SET);
+    if (read(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ)
+      memset(db->dbm_dirbuf, 0, DBLKSIZ);
+  }
+  db->dbm_dirbuf[i] |= 1<<n;
+  db->dbm_dirbno = b;
+  (void) lseek(db->dbm_dirf, (long)b*DBLKSIZ, L_SET);
+  if (write(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ)
+    db->dbm_flags |= _DBM_IOERR;
+}
+
+static datum makdatum(char buf[PBLKSIZ], int n)
+{
+  register short *sp;
+  register int t;
+  datum item;
+
+  sp = (short *)buf;
+  if ((unsigned)n >= (unsigned)sp[0])
+  {
+    item.dptr = NULL;
+    item.dsize = 0;
+    return (item);
+  }
+  t = PBLKSIZ;
+  if (n > 0)
+    t = sp[n];
+  item.dptr = buf+sp[n+1];
+  item.dsize = t - sp[n+1];
+  return (item);
+}
+
+static int finddatum(char buf[PBLKSIZ], datum item)
+{
+  register short *sp;
+  register int i, n, j;
+
+  sp = (short *)buf;
+  n = PBLKSIZ;
+  for (i=0, j=sp[0]; i<j; i+=2, n = sp[i])
+  {
+    n -= sp[i+1];
+    if (n != item.dsize)
+      continue;
+    if (n == 0 || memcmp(&buf[sp[i+1]], item.dptr, n) == 0)
+      return (i);
+  }
+  return (-1);
+}
+
+static  int hitab[16]
+/* ken's
+{
+        055,043,036,054,063,014,004,005,
+        010,064,077,000,035,027,025,071,
+};
+*/
+ = {    61, 57, 53, 49, 45, 41, 37, 33,
+        29, 25, 21, 17, 13,  9,  5,  1,
+};
+static  long hltab[64]
+ = {
+        06100151277L,06106161736L,06452611562L,05001724107L,
+        02614772546L,04120731531L,04665262210L,07347467531L,
+        06735253126L,06042345173L,03072226605L,01464164730L,
+        03247435524L,07652510057L,01546775256L,05714532133L,
+        06173260402L,07517101630L,02431460343L,01743245566L,
+        00261675137L,02433103631L,03421772437L,04447707466L,
+        04435620103L,03757017115L,03641531772L,06767633246L,
+        02673230344L,00260612216L,04133454451L,00615531516L,
+        06137717526L,02574116560L,02304023373L,07061702261L,
+        05153031405L,05322056705L,07401116734L,06552375715L,
+        06165233473L,05311063631L,01212221723L,01052267235L,
+        06000615237L,01075222665L,06330216006L,04402355630L,
+        01451177262L,02000133436L,06025467062L,07121076461L,
+        03123433522L,01010635225L,01716177066L,05161746527L,
+        01736635071L,06243505026L,03637211610L,01756474365L,
+        04723077174L,03642763134L,05750130273L,03655541561L,
+};
+
+static long hashinc(register DBM *db, long hash)
+{
+  long bit;
+
+  hash &= db->dbm_hmask;
+  bit = db->dbm_hmask+1;
+  for (;;)
+  {
+    bit >>= 1;
+    if (bit == 0)
+      return (0L);
+    if ((hash & bit) == 0)
+      return (hash | bit);
+    hash &= ~bit;
+  }
+}
+
+static long dcalchash(datum item)
+{
+  register int s, c, j;
+  register char *cp;
+  register long hashl;
+  register int hashi;
+
+  hashl = 0;
+  hashi = 0;
+  for (cp = item.dptr, s=item.dsize; --s >= 0; )
+  {
+    c = *cp++;
+    for (j=0; j<BYTESIZ; j+=4)
+    {
+      hashi += hitab[c&017];
+      hashl += hltab[hashi&63];
+      c >>= 4;
+    }
+  }
+  return (hashl);
+}
+
+/*
+ * Delete pairs of items (n & n+1).
+ */
+static int delitem(char buf[PBLKSIZ], int n)
+{
+  register short *sp, *sp1;
+  register int i1, i2;
+
+  sp = (short *)buf;
+  i2 = sp[0];
+  if ((unsigned)n >= (unsigned)i2 || (n & 1))
+    return (0);
+  if (n == i2-2)
+  {
+    sp[0] -= 2;
+    return (1);
+  }
+  i1 = PBLKSIZ;
+  if (n > 0)
+    i1 = sp[n];
+  i1 -= sp[n+2];
+  if (i1 > 0)
+  {
+    i2 = sp[i2];
+    bcopy(&buf[i2], &buf[i2 + i1], sp[n+2] - i2);
+  }
+  sp[0] -= 2;
+  for (sp1 = sp + sp[0], sp += n+1; sp <= sp1; sp++)
+    sp[0] = sp[2] + i1;
+  return (1);
+}
+
+/*
+ * Add pairs of items (item & item1).
+ */
+static int additem(char buf[PBLKSIZ], datum item, datum item1)
+{
+  register short *sp;
+  register int i1, i2, tmp;
+
+  sp = (short *)buf;
+  i1 = PBLKSIZ;
+  i2 = sp[0];
+  if (i2 > 0)
+    i1 = sp[i2];
+  i1 -= item.dsize + item1.dsize;
+  tmp = (i2+3) * sizeof(short);
+  if (i1 <= tmp) return (0);
+  sp[0] += 2;
+  sp[++i2] = i1 + item1.dsize;
+  bcopy(item.dptr, &buf[i1 + item1.dsize], item.dsize);
+  sp[++i2] = i1;
+  bcopy(item1.dptr, &buf[i1], item1.dsize);
+  return (1);
+}
+
+#ifdef DEBUG
+static chkblk(char buf[PBLKSIZ])
+{
+  register short *sp;
+  register t, i;
+
+  sp = (short *)buf;
+  t = PBLKSIZ;
+  for (i=0; i<sp[0]; i++)
+  {
+    if (sp[i+1] > t)
+      return (-1);
+    t = sp[i+1];
+  }
+  if (t < (sp[0]+1)*sizeof(short))
+    return (-1);
+  return (0);
+}
+#endif
+
+#endif /* HAVE_DBM */
Index: Singular/links/ndbm.h
===================================================================
--- Singular/links/ndbm.h	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
+++ Singular/links/ndbm.h	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
@@ -0,0 +1,103 @@
+#ifndef NDBM_H
+#define NDBM_H
+/****************************************
+*  Computer Algebra System SINGULAR     *
+****************************************/
+/*
+* ABSTRACT: DBM
+*/
+
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)ndbm.h	5.1 (Berkeley) 5/30/85
+ *
+ * Par. 3 removed due to a license change (1999)
+ * see ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
+ */
+
+/*
+ * Hashed key data base library.
+ */
+#define PBLKSIZ 1024
+
+#define DBLKSIZ 4096
+
+typedef struct {
+	int	dbm_dirf;		/* open directory file */
+	int	dbm_pagf;		/* open page file */
+	int	dbm_flags;		/* flags, see below */
+	long	dbm_maxbno;		/* last ``bit'' in dir file */
+	long	dbm_bitno;		/* current bit number */
+	long	dbm_hmask;		/* hash mask */
+	long	dbm_blkptr;		/* current block for dbm_nextkey */
+	int	dbm_keyptr;		/* current key for dbm_nextkey */
+	long	dbm_blkno;		/* current page to read/write */
+	long	dbm_pagbno;		/* current page in pagbuf */
+	char	dbm_pagbuf[PBLKSIZ];	/* page file block buffer */
+	long	dbm_dirbno;		/* current block in dirbuf */
+	char	dbm_dirbuf[DBLKSIZ];	/* directory file block buffer */
+} DBM;
+
+#define _DBM_RDONLY	0x01	/* data base open read-only */
+#define _DBM_IOERR	0x02	/* data base I/O error */
+
+#define dbm_rdonly(db)	((db)->dbm_flags & _DBM_RDONLY)
+
+#define dbm_error(db)	((db)->dbm_flags & _DBM_IOERR)
+	/* use this one at your own risk! */
+#define dbm_clearerr(db)	((db)->dbm_flags &= ~_DBM_IOERR)
+
+/* for flock(2) and fstat(2) */
+#define dbm_dirfno(db)	((db)->dbm_dirf)
+#define dbm_pagfno(db)	((db)->dbm_pagf)
+
+typedef struct {
+	char	*dptr;
+	int	dsize;
+} datum;
+
+/*
+ * flags to dbm_store()
+ */
+#define DBM_INSERT	0
+#define DBM_REPLACE	1
+
+DBM	*dbm_open(char *file, int flags, int mode);
+void	dbm_close(DBM *db);
+datum	dbm_fetch(register DBM *db, datum key);
+datum	dbm_firstkey(DBM *db);
+datum	dbm_nextkey(register DBM *db);
+long	dbm_forder(register DBM *db, datum key);
+int	dbm_delete(register DBM *db, datum key);
+int	dbm_store(register DBM *db, datum key, datum dat, int replace);
+
+#endif /* NDBM_H */
Index: Singular/links/pipeLink.cc
===================================================================
--- Singular/links/pipeLink.cc	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
+++ Singular/links/pipeLink.cc	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
@@ -0,0 +1,207 @@
+/****************************************
+ * Computer Algebra System SINGULAR     *
+ ****************************************/
+/***************************************************************
+ * File:    pipeLink.h
+ *  Purpose: declaration of sl_link routines for pipe
+ ***************************************************************/
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <signal.h>
+#include <sys/types.h>          /* for portability */
+#include <sys/select.h>
+#include <sys/socket.h>
+
+
+#include "config.h"
+#include <kernel/mod2.h>
+
+#include "tok.h"
+#include "ipid.h"
+#include <omalloc/omalloc.h>
+#include "subexpr.h"
+#include "silink.h"
+#include "lists.h"
+#include "pipeLink.h"
+
+typedef struct
+{
+  FILE *f_read;
+  FILE *f_write;
+  pid_t pid; /* only valid for fork/tcp mode*/
+  int fd_read,fd_write; /* only valid for fork/tcp mode*/
+  char level;
+} pipeInfo;
+
+//**************************************************************************/
+BOOLEAN pipeOpen(si_link l, short flag, leftv u)
+{
+  pipeInfo *d=(pipeInfo*)omAlloc0(sizeof(pipeInfo));
+  if (flag & SI_LINK_OPEN)
+  {
+      flag = SI_LINK_READ| SI_LINK_WRITE;
+  }
+  int pc[2];
+  int cp[2];
+  pipe(pc);
+  pipe(cp);
+  pid_t pid=fork();
+  if (pid==0) /*child*/
+  {
+    /* close unnecessary pipe descriptors for a clean environment */
+    close(pc[1]); close(cp[0]);
+    /* dup pipe read/write to stdin/stdout */
+    dup2( pc[0], STDIN_FILENO );
+    dup2( cp[1], STDOUT_FILENO  );
+    int r=system(l->name);
+    close(pc[0]);
+    close(cp[1]);
+    exit(r);
+        /* never reached*/
+  }
+  else if (pid>0)
+  {
+    d->pid=pid;
+    close(pc[0]); close(cp[1]);
+    d->f_read=fdopen(cp[0],"r");
+    d->fd_read=cp[0];
+    d->f_write=fdopen(pc[1],"w");
+    d->fd_write=pc[1];
+    SI_LINK_SET_RW_OPEN_P(l);
+  }
+  else
+  {
+    Werror("fork failed (%d)",errno);
+    omFreeSize(d,sizeof(*d));
+    return TRUE;
+  }
+  l->data=d;
+  return FALSE;
+}
+
+//**************************************************************************/
+LINKAGE BOOLEAN pipeClose(si_link l)
+{
+  pipeInfo *d = (pipeInfo *)l->data;
+  if (d!=NULL)
+  {
+    if (d->f_read!=NULL) fclose(d->f_read);
+    if (d->f_write!=NULL) fclose(d->f_write);
+    if (d->pid!=0) { kill(d->pid,15); kill(d->pid,9); }
+  }
+  SI_LINK_SET_CLOSE_P(l);
+  return FALSE;
+}
+
+//**************************************************************************/
+LINKAGE BOOLEAN pipeKill(si_link l)
+{
+  if(SI_LINK_OPEN_P(l)) pipeClose(l);
+  pipeInfo *d = (pipeInfo *)l->data;
+  if (d!=NULL)
+  {
+    omFreeSize((ADDRESS)d,(sizeof *d));
+  }
+  l->data=NULL;
+  return FALSE;
+}
+
+//**************************************************************************/
+LINKAGE leftv pipeRead1(si_link l)
+{
+  pipeInfo *d = (pipeInfo *)l->data;
+  leftv res=(leftv)omAlloc0(sizeof(sleftv));
+  char *s=(char *)omAlloc0(1024);
+  char *ss=fgets(s,1024,d->f_read);
+  if (ss==NULL) { omFreeSize(s,1024); pipeClose(l);return NULL; }
+  int i=strlen(s)-1;
+  if ((i>=0) && (s[i]=='\n')) s[i]='\0';
+  res->rtyp=STRING_CMD;
+  res->data=s;
+  return res;
+}
+//**************************************************************************/
+extern si_link pipeLastLink;
+LINKAGE BOOLEAN pipeWrite(si_link l, leftv data)
+{
+  if(!SI_LINK_W_OPEN_P(l)) slOpen(l,SI_LINK_OPEN|SI_LINK_WRITE,NULL);
+  pipeInfo *d = (pipeInfo *)l->data;
+  FILE *outfile=d->f_write;;
+  BOOLEAN err=FALSE;
+  char *s;
+  pipeLastLink=l;
+  while (data!=NULL)
+  {
+    s = data->String();
+    // free data ??
+    if (s!=NULL)
+    {
+      fprintf(outfile,"%s\n",s);
+      omFree((ADDRESS)s);
+    }
+    else
+    {
+      Werror("cannot convert to string");
+      err=TRUE;
+    }
+    if (pipeLastLink==NULL) return TRUE;
+    data = data->next;
+  }
+  fflush(outfile);
+  pipeLastLink=NULL;
+  return err;
+}
+
+const char* slStatusPipe(si_link l, const char* request)
+{
+  pipeInfo *d=(pipeInfo*)l->data;
+  if (d==NULL) return "not open";
+  if(strcmp(request, "read") == 0)
+  {
+    int s;
+    if ((!SI_LINK_R_OPEN_P(l)) || (feof(d->f_read))) s=0;
+    else
+    {
+      fd_set  mask, fdmask;
+      struct timeval wt;
+      /* Don't block. Return socket status immediately. */
+      wt.tv_sec  = 0;
+      wt.tv_usec = 0;
+
+      FD_ZERO(&mask);
+      FD_SET(d->fd_read, &mask);
+      //Print("test fd %d\n",d->fd_read);
+      /* check with select: chars waiting: no -> not ready */
+      s=select(d->fd_read+1, &mask, NULL, NULL, &wt);
+    }
+    switch (s)
+    {
+      case 0: /* not ready */ return "not ready";
+      case -1: /*error*/      return "error";
+      default: /*1: ready ? */return "ready";
+    }
+  }
+  else if (strcmp(request, "write") == 0)
+  {
+    if (SI_LINK_W_OPEN_P(l)) return "ready";
+    return "not ready";
+  }
+  return "unknown status request";
+}
+
+si_link_extension slInitPipeExtension(si_link_extension s)
+{
+  s->Open=pipeOpen;
+  s->Close=pipeClose;
+  s->Kill=pipeKill;
+  s->Read=pipeRead1;
+  s->Read2=(slRead2Proc)NULL;
+  s->Write=pipeWrite;
+
+  s->Status=slStatusPipe;
+  s->type="pipe";
+  return s;
+}
Index: Singular/links/pipeLink.h
===================================================================
--- Singular/links/pipeLink.h	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
+++ Singular/links/pipeLink.h	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
@@ -0,0 +1,12 @@
+/****************************************
+ * Computer Algebra System SINGULAR     *
+ ****************************************/
+/***************************************************************
+ * File:    pipeLink.h
+ *  Purpose: declaration of sl_link routines for pipe
+ ***************************************************************/
+#ifndef PIPELINK_H
+#define PIPELINK_H
+si_link_extension slInitPipeExtension(si_link_extension s);
+#endif
+
Index: Singular/links/silink.cc
===================================================================
--- Singular/links/silink.cc	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
+++ Singular/links/silink.cc	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
@@ -0,0 +1,881 @@
+/****************************************
+*  Computer Algebra System SINGULAR     *
+****************************************/
+
+/*
+* ABSTRACT: general interface to links
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "config.h"
+#include <kernel/mod2.h>
+#include <Singular/tok.h>
+#include <misc/options.h>
+#include <omalloc/omalloc.h>
+#include <kernel/febase.h>
+#include <Singular/subexpr.h>
+#include <Singular/ipid.h>
+#include <Singular/silink.h>
+#include <Singular/ipshell.h>
+#include <polys/matpol.h>
+#include <polys/monomials/ring.h>
+#include <Singular/lists.h>
+#include <kernel/ideals.h>
+#include <coeffs/numbers.h>
+#include <misc/intvec.h>
+#include <Singular/links/ssiLink.h>
+#include <Singular/links/pipeLink.h>
+
+// #ifdef HAVE_DBM
+// #ifdef ix86_Win
+// #define USE_GDBM
+// #endif
+// #endif
+
+omBin s_si_link_extension_bin = omGetSpecBin(sizeof(s_si_link_extension));
+omBin sip_link_bin = omGetSpecBin(sizeof(sip_link));
+omBin ip_link_bin = omGetSpecBin(sizeof(ip_link));
+
+/* declarations */
+static BOOLEAN DumpAscii(FILE *fd, idhdl h);
+static BOOLEAN DumpAsciiIdhdl(FILE *fd, idhdl h);
+static const char* GetIdString(idhdl h);
+static int DumpRhs(FILE *fd, idhdl h);
+static BOOLEAN DumpQring(FILE *fd, idhdl h, const char *type_str);
+static BOOLEAN DumpAsciiMaps(FILE *fd, idhdl h, idhdl rhdl);
+static si_link_extension slTypeInit(si_link_extension s, const char* type);
+
+/* ====================================================================== */
+si_link_extension si_link_root=NULL;
+
+BOOLEAN slInit(si_link l, char *istr)
+{
+  char *type = NULL, *mode = NULL, *name = NULL;
+  int i = 0, j;
+
+  // set mode and type
+  if (istr != NULL)
+  {
+    // find the first colon char in istr
+    i = 0;
+    while (istr[i] != ':' && istr[i] != '\0') i++;
+    if (istr[i] == ':')
+    {
+      // if found, set type
+      if (i > 0)
+      {
+        istr[i] = '\0';
+        type = omStrDup(istr);
+        istr[i] = ':';
+      }
+      // and check for mode
+      j = ++i;
+      while (istr[j] != ' ' && istr[j] != '\0') j++;
+      if (j > i)
+      {
+        mode = omStrDup(&(istr[i]));
+        mode[j - i] = '\0';
+      }
+      // and for the name
+      while (istr[j] == ' '&& istr[j] != '\0') j++;
+      if (istr[j] != '\0') name = omStrDup(&(istr[j]));
+    }
+    else // no colon find -- string is entire name
+    {
+      j=0;
+      while (istr[j] == ' '&& istr[j] != '\0') j++;
+      if (istr[j] != '\0') name = omStrDup(&(istr[j]));
+    }
+  }
+
+  // set the link extension
+  if (type != NULL)
+  {
+    si_link_extension s = si_link_root;
+    si_link_extension prev = s;
+
+    while (strcmp(s->type, type) != 0)
+    {
+      if (s->next == NULL)
+      {
+        prev = s;
+        s = NULL;
+        break;
+      }
+      else
+      {
+        s = s->next;
+      }
+    }
+
+    if (s != NULL)
+      l->m = s;
+    else
+    {
+      l->m = slTypeInit(prev, type);
+    }
+    omFree(type);
+  }
+  else
+    l->m = si_link_root;
+
+  if (l->m == NULL) return TRUE;
+
+  l->name = (name != NULL ? name : omStrDup(""));
+  l->mode = (mode != NULL ? mode : omStrDup(""));
+  l->ref = 1;
+  return FALSE;
+}
+
+void slCleanUp(si_link l)
+{
+  (l->ref)--;
+  if (l->ref == 0)
+  {
+    if (SI_LINK_OPEN_P(l))
+    {
+      if (l->m->Kill != NULL) l->m->Kill(l);
+      else if (l->m->Close != NULL) l->m->Close(l);
+    }
+    omFree((ADDRESS)l->name);
+    omFree((ADDRESS)l->mode);
+    memset((void *) l, 0, sizeof(ip_link));
+  }
+}
+
+void slKill(si_link l)
+{
+  slCleanUp(l);
+  if (l->ref == 0)
+    omFreeBin((ADDRESS)l,  ip_link_bin);
+}
+
+const char* slStatus(si_link l, const char *request)
+{
+  if (l == NULL) return "empty link";
+  else if (l->m == NULL) return "unknown link type";
+  else if (strcmp(request, "type") == 0) return l->m->type;
+  else if (strcmp(request, "mode") == 0) return l->mode;
+  else if (strcmp(request, "name") == 0) return l->name;
+  else if (strcmp(request, "exists") ==0)
+  {
+    struct stat buf;
+    if (lstat(l->name,&buf)==0) return "yes";
+    else return "no";
+  }
+  else if (strcmp(request, "open") == 0)
+  {
+    if (SI_LINK_OPEN_P(l)) return "yes";
+    else return "no";
+  }
+  else if (strcmp(request, "openread") == 0)
+  {
+    if (SI_LINK_R_OPEN_P(l)) return "yes";
+    else return "no";
+  }
+  else if (strcmp(request, "openwrite") == 0)
+  {
+    if (SI_LINK_W_OPEN_P(l)) return "yes";
+    else return "no";
+  }
+  else if (l->m->Status == NULL) return "unknown status request";
+  else return l->m->Status(l, request);
+}
+
+//--------------------------------------------------------------------------
+BOOLEAN slOpen(si_link l, short flag, leftv h)
+{
+  BOOLEAN res = TRUE;
+  if (l!=NULL)
+  {
+
+    if (l->m == NULL) slInit(l, ((char*)""));
+
+    const char *c="_";;
+    if (h!=NULL) c=h->Name();
+
+    if (SI_LINK_OPEN_P(l))
+    {
+      Warn("open: link of type: %s, mode: %s, name: %s is already open",
+         l->m->type, l->mode, l->name);
+      return FALSE;
+    }
+    else if (l->m->Open != NULL)
+    {
+      res = l->m->Open(l, flag, h);
+      if (res)
+        Werror("open: Error for link %s of type: %s, mode: %s, name: %s",
+             c, l->m->type, l->mode, l->name);
+    }
+  }
+  return res;
+}
+
+BOOLEAN slClose(si_link l)
+{
+
+  if(! SI_LINK_OPEN_P(l))
+    return FALSE;
+
+  BOOLEAN res = TRUE;
+  if (l->m->Close != NULL)
+  {
+    res = l->m->Close(l);
+    if (res)
+      Werror("close: Error for link of type: %s, mode: %s, name: %s",
+           l->m->type, l->mode, l->name);
+  }
+  return res;
+}
+
+leftv slRead(si_link l, leftv a)
+{
+  char *mode;
+  leftv v = NULL;
+  if( ! SI_LINK_R_OPEN_P(l)) // open r ?
+  {
+#ifdef HAVE_DBM
+#ifdef USE_GDBM
+    if (! SI_LINK_CLOSE_P(l))
+      {
+        if (slClose(l)) return NULL;
+      }
+#endif
+#endif
+    if (slOpen(l, SI_LINK_READ,NULL)) return NULL;
+  }
+
+  if (SI_LINK_R_OPEN_P(l))
+  { // open r
+    if (a==NULL)
+    {
+      if (l->m->Read != NULL) v = l->m->Read(l);
+    }
+    else
+    {
+      if (l->m->Read2 != NULL) v = l->m->Read2(l,a);
+    }
+  }
+  else
+  {
+    Werror("read: Error to open link of type %s, mode: %s, name: %s for reading",
+           l->m->type, l->mode, l->name);
+    return NULL;
+  }
+
+  // here comes the eval:
+  if (v != NULL)
+  {
+    if (v->Eval() && !errorreported)
+      WerrorS("eval: failed");
+  }
+  else
+    Werror("read: Error for link of type %s, mode: %s, name: %s",
+           l->m->type, l->mode, l->name);
+  return v;
+}
+
+BOOLEAN slWrite(si_link l, leftv v)
+{
+  BOOLEAN res;
+
+  if(! SI_LINK_W_OPEN_P(l)) // open w ?
+  {
+#ifdef HAVE_DBM
+#ifdef USE_GDBM
+    if (! SI_LINK_CLOSE_P(l))
+      {
+        if (slClose(l)) return TRUE;
+      }
+#endif
+#endif
+    if (slOpen(l, SI_LINK_WRITE,NULL)) return TRUE;
+  }
+
+  if (SI_LINK_W_OPEN_P(l))
+  { // now open w
+    if (l->m->Write != NULL)
+      res = l->m->Write(l,v);
+    else
+      res = TRUE;
+
+    if (res)
+      Werror("write: Error for link of type %s, mode: %s, name: %s",
+             l->m->type, l->mode, l->name);
+    return res;
+  }
+  else
+  {
+    Werror("write: Error to open link of type %s, mode: %s, name: %s for writing",
+           l->m->type, l->mode, l->name);
+    return TRUE;
+  }
+}
+
+BOOLEAN slDump(si_link l)
+{
+  BOOLEAN res;
+
+  if(! SI_LINK_W_OPEN_P(l)) // open w ?
+  {
+    if (slOpen(l, SI_LINK_WRITE,NULL)) return TRUE;
+  }
+
+  if(SI_LINK_W_OPEN_P(l))
+  { // now open w
+    if (l->m->Dump != NULL)
+      res = l->m->Dump(l);
+    else
+      res = TRUE;
+
+    if (res)
+      Werror("dump: Error for link of type %s, mode: %s, name: %s",
+             l->m->type, l->mode, l->name);
+
+    if (!SI_LINK_R_OPEN_P(l)) slClose(l); // do not close r/w links
+    return res;
+  }
+  else
+  {
+    Werror("dump: Error to open link of type %s, mode: %s, name: %s for writing",
+           l->m->type, l->mode, l->name);
+    return TRUE;
+  }
+}
+
+BOOLEAN slGetDump(si_link l)
+{
+  BOOLEAN res;
+
+  if(! SI_LINK_R_OPEN_P(l)) // open r ?
+  {
+    if (slOpen(l, SI_LINK_READ,NULL)) return TRUE;
+  }
+
+  if(SI_LINK_R_OPEN_P(l))
+  { // now open r
+    if (l->m->GetDump != NULL)
+      res = l->m->GetDump(l);
+    else
+      res = TRUE;
+
+    if (res)
+      Werror("getdump: Error for link of type %s, mode: %s, name: %s",
+             l->m->type, l->mode, l->name);
+    //res|=slClose(l);
+    return res;
+  }
+  else
+  {
+    Werror("dump: Error open link of type %s, mode: %s, name: %s for reading",
+           l->m->type, l->mode, l->name);
+    return TRUE;
+  }
+}
+
+
+/* =============== ASCII ============================================= */
+BOOLEAN slOpenAscii(si_link l, short flag, leftv h)
+{
+  const char *mode;
+  if (flag & SI_LINK_OPEN)
+  {
+    if (l->mode[0] != '\0' && (strcmp(l->mode, "r") == 0))
+      flag = SI_LINK_READ;
+    else flag = SI_LINK_WRITE;
+  }
+
+  if (flag == SI_LINK_READ) mode = "r";
+  else if (strcmp(l->mode, "w") == 0) mode = "w";
+  else mode = "a";
+
+
+  if (l->name[0] == '\0')
+  {
+    // stdin or stdout
+    if (flag == SI_LINK_READ)
+    {
+      l->data = (void *) stdin;
+      mode = "r";
+    }
+    else
+    {
+      l->data = (void *) stdout;
+      mode = "a";
+    }
+  }
+  else
+  {
+    // normal ascii link to a file
+    FILE *outfile;
+    char *filename=l->name;
+
+    if(filename[0]=='>')
+    {
+      if (filename[1]=='>')
+      {
+        filename+=2;
+        mode = "a";
+      }
+      else
+      {
+        filename++;
+        mode="w";
+      }
+    }
+    outfile=myfopen(filename,mode);
+    if (outfile!=NULL)
+      l->data = (void *) outfile;
+    else
+      return TRUE;
+  }
+
+  omFree(l->mode);
+  l->mode = omStrDup(mode);
+  SI_LINK_SET_OPEN_P(l, flag);
+  return FALSE;
+}
+
+BOOLEAN slCloseAscii(si_link l)
+{
+  SI_LINK_SET_CLOSE_P(l);
+  if (l->name[0] != '\0')
+  {
+    return (fclose((FILE *)l->data)!=0);
+  }
+  return FALSE;
+}
+
+leftv slReadAscii2(si_link l, leftv pr)
+{
+  FILE * fp=(FILE *)l->data;
+  char * buf=NULL;
+  if (fp!=NULL && l->name[0] != '\0')
+  {
+    fseek(fp,0L,SEEK_END);
+    long len=ftell(fp);
+    fseek(fp,0L,SEEK_SET);
+    buf=(char *)omAlloc((int)len+1);
+    if (BVERBOSE(V_READING))
+      Print("//Reading %ld chars\n",len);
+    myfread( buf, len, 1, fp);
+    buf[len]='\0';
+  }
+  else
+  {
+    if (pr->Typ()==STRING_CMD)
+    {
+      buf=(char *)omAlloc(80);
+      fe_fgets_stdin((char *)pr->Data(),buf,80);
+    }
+    else
+    {
+      WerrorS("read(<link>,<string>) expected");
+      buf=omStrDup("");
+    }
+  }
+  leftv v=(leftv)omAlloc0Bin(sleftv_bin);
+  v->rtyp=STRING_CMD;
+  v->data=buf;
+  return v;
+}
+
+leftv slReadAscii(si_link l)
+{
+  sleftv tmp;
+  memset(&tmp,0,sizeof(sleftv));
+  tmp.rtyp=STRING_CMD;
+  tmp.data=(void*) "? ";
+  return slReadAscii2(l,&tmp);
+}
+
+BOOLEAN slWriteAscii(si_link l, leftv v)
+{
+  FILE *outfile=(FILE *)l->data;
+  BOOLEAN err=FALSE;
+  char *s;
+  while (v!=NULL)
+  {
+    s = v->String();
+    // free v ??
+    if (s!=NULL)
+    {
+      fprintf(outfile,"%s\n",s);
+      omFree((ADDRESS)s);
+    }
+    else
+    {
+      Werror("cannot convert to string");
+      err=TRUE;
+    }
+    v = v->next;
+  }
+  fflush(outfile);
+  return err;
+}
+
+const char* slStatusAscii(si_link l, const char* request)
+{
+  if (strcmp(request, "read") == 0)
+  {
+    if (SI_LINK_R_OPEN_P(l)) return "ready";
+    else return "not ready";
+  }
+  else if (strcmp(request, "write") == 0)
+  {
+    if (SI_LINK_W_OPEN_P(l)) return "ready";
+    else return "not ready";
+  }
+  else return "unknown status request";
+}
+
+/*------------------ Dumping in Ascii format -----------------------*/
+
+BOOLEAN slDumpAscii(si_link l)
+{
+  FILE *fd = (FILE *) l->data;
+  idhdl h = IDROOT, rh = currRingHdl;
+  BOOLEAN status = DumpAscii(fd, h);
+
+  if (! status ) status = DumpAsciiMaps(fd, h, NULL);
+
+  if (currRingHdl != rh) rSetHdl(rh);
+  fprintf(fd, "option(set, intvec(%d, %d));\n", test, verbose);
+  fprintf(fd, "RETURN();\n");
+  fflush(fd);
+
+  return status;
+}
+
+// we do that recursively, to dump ids in the the order in which they
+// were actually defined
+static BOOLEAN DumpAscii(FILE *fd, idhdl h)
+{
+  if (h == NULL) return FALSE;
+
+  if (DumpAscii(fd, IDNEXT(h))) return TRUE;
+
+  // need to set the ring before writing it, otherwise we get in
+  // trouble with minpoly
+  if (IDTYP(h) == RING_CMD || IDTYP(h) == QRING_CMD)
+    rSetHdl(h);
+
+  if (DumpAsciiIdhdl(fd, h)) return TRUE;
+
+  if (IDTYP(h) == RING_CMD || IDTYP(h) == QRING_CMD)
+    return DumpAscii(fd, IDRING(h)->idroot);
+  else
+    return FALSE;
+}
+
+static BOOLEAN DumpAsciiMaps(FILE *fd, idhdl h, idhdl rhdl)
+{
+  if (h == NULL) return FALSE;
+  if (DumpAsciiMaps(fd, IDNEXT(h), rhdl)) return TRUE;
+
+  if (IDTYP(h) == RING_CMD || IDTYP(h) == QRING_CMD)
+    return DumpAsciiMaps(fd, IDRING(h)->idroot, h);
+  else if (IDTYP(h) == MAP_CMD)
+  {
+    char *rhs;
+    rSetHdl(rhdl);
+    rhs = h->String();
+
+    if (fprintf(fd, "setring %s;\n", IDID(rhdl)) == EOF) return TRUE;
+    if (fprintf(fd, "%s %s = %s, %s;\n", Tok2Cmdname(MAP_CMD), IDID(h),
+                IDMAP(h)->preimage, rhs) == EOF)
+    {
+      omFree(rhs);
+      return TRUE;
+    }
+    else
+    {
+      omFree(rhs);
+      return FALSE;
+    }
+  }
+  else return FALSE;
+}
+
+static BOOLEAN DumpAsciiIdhdl(FILE *fd, idhdl h)
+{
+  const char *type_str = GetIdString(h);
+  int type_id = IDTYP(h);
+
+  if ((type_id == PACKAGE_CMD) &&(strcmp(IDID(h), "Top") == 0))
+    return FALSE;
+
+  // we do not throw an error if a wrong type was attempted to be dumped
+  if (type_str == NULL)
+    return FALSE;
+
+  // handle qrings separately
+  if (type_id == QRING_CMD)
+    return DumpQring(fd, h, type_str);
+
+  // C-proc not to be dumped
+  if ((type_id == PROC_CMD) && (IDPROC(h)->language == LANG_C))
+    return FALSE;
+
+  // put type and name
+  if (fprintf(fd, "%s %s", type_str, IDID(h)) == EOF)
+    return TRUE;
+  // for matricies, append the dimension
+  if (type_id == MATRIX_CMD)
+  {
+    ideal id = IDIDEAL(h);
+    if (fprintf(fd, "[%d][%d]", id->nrows, id->ncols)== EOF) return TRUE;
+  }
+  else if (type_id == INTMAT_CMD)
+  {
+    if (fprintf(fd, "[%d][%d]", IDINTVEC(h)->rows(), IDINTVEC(h)->cols())
+        == EOF) return TRUE;
+  }
+
+  if (type_id == PACKAGE_CMD)
+  {
+    return (fprintf(fd, ";\n") == EOF);
+  }
+
+  // write the equal sign
+  if (fprintf(fd, " = ") == EOF) return TRUE;
+
+  // and the right hand side
+  if (DumpRhs(fd, h) == EOF) return TRUE;
+
+  // semicolon und tschuess
+  if (fprintf(fd, ";\n") == EOF) return TRUE;
+
+  return FALSE;
+}
+
+static const char* GetIdString(idhdl h)
+{
+  int type = IDTYP(h);
+
+  switch(type)
+  {
+      case LIST_CMD:
+      {
+        lists l = IDLIST(h);
+        int i, nl = l->nr + 1;
+        char *name;
+
+        for (i=0; i<nl; i++)
+          if (GetIdString((idhdl) &(l->m[i])) == NULL) return NULL;
+      }
+      case PACKAGE_CMD:
+      case INT_CMD:
+      case INTVEC_CMD:
+      case INTMAT_CMD:
+      case STRING_CMD:
+      case RING_CMD:
+      case QRING_CMD:
+      case PROC_CMD:
+      case NUMBER_CMD:
+      case POLY_CMD:
+      case IDEAL_CMD:
+      case VECTOR_CMD:
+      case MODUL_CMD:
+      case MATRIX_CMD:
+        return Tok2Cmdname(type);
+
+      case MAP_CMD:
+      case LINK_CMD:
+        return NULL;
+
+      default:
+       Warn("Error dump data of type %s", Tok2Cmdname(IDTYP(h)));
+       return NULL;
+  }
+}
+
+static BOOLEAN DumpQring(FILE *fd, idhdl h, const char *type_str)
+{
+  char *ring_str = h->String();
+  if (fprintf(fd, "%s temp_ring = %s;\n", Tok2Cmdname(RING_CMD), ring_str)
+              == EOF) return TRUE;
+  if (fprintf(fd, "%s temp_ideal = %s;\n", Tok2Cmdname(IDEAL_CMD),
+              iiStringMatrix((matrix) IDRING(h)->qideal, 1, currRing, n_GetChar(currRing->cf)))
+      == EOF) return TRUE;
+  if (fprintf(fd, "attrib(temp_ideal, \"isSB\", 1);\n") == EOF) return TRUE;
+  if (fprintf(fd, "%s %s = temp_ideal;\n", type_str, IDID(h)) == EOF)
+    return TRUE;
+  if (fprintf(fd, "kill temp_ring;\n") == EOF) return TRUE;
+  else
+  {
+    omFree(ring_str);
+    return FALSE;
+  }
+}
+
+
+static int DumpRhs(FILE *fd, idhdl h)
+{
+  int type_id = IDTYP(h);
+
+  if (type_id == LIST_CMD)
+  {
+    lists l = IDLIST(h);
+    int i, nl = l->nr;
+
+    fprintf(fd, "list(");
+
+    for (i=0; i<nl; i++)
+    {
+      if (DumpRhs(fd, (idhdl) &(l->m[i])) == EOF) return EOF;
+      fprintf(fd, ",");
+    }
+    if (nl > 0)
+    {
+      if (DumpRhs(fd, (idhdl) &(l->m[nl])) == EOF) return EOF;
+    }
+    fprintf(fd, ")");
+  }
+  else  if (type_id == STRING_CMD)
+  {
+    char *pstr = IDSTRING(h), c;
+    fputc('"', fd);
+    while (*pstr != '\0')
+    {
+      if (*pstr == '"' || *pstr == '\\')  fputc('\\', fd);
+      fputc(*pstr, fd);
+      pstr++;
+    }
+    fputc('"', fd);
+  }
+  else  if (type_id == PROC_CMD)
+  {
+    procinfov pi = IDPROC(h);
+    if (pi->language == LANG_SINGULAR) {
+      if( pi->data.s.body==NULL) iiGetLibProcBuffer(pi);
+      char *pstr = pi->data.s.body, c;
+      fputc('"', fd);
+      while (*pstr != '\0') {
+        if (*pstr == '"' || *pstr == '\\') fputc('\\', fd);
+        fputc(*pstr, fd);
+        pstr++;
+      }
+      fputc('"', fd);
+    } else fputs("(null)", fd);
+  }
+  else
+  {
+    char *rhs = h->String();
+
+    if (rhs == NULL) return EOF;
+
+    if (type_id == INTVEC_CMD) fprintf(fd, "intvec(");
+
+    if (fprintf(fd, "%s", rhs) == EOF) return EOF;
+    omFree(rhs);
+
+    if ((type_id == RING_CMD || type_id == QRING_CMD) &&
+        IDRING(h)->cf->type==n_algExt)
+    {
+      StringSetS("");
+      p_Write(IDRING(h)->cf->extRing->qideal->m[0],IDRING(h)->cf->extRing);
+      rhs = StringAppendS("");
+      if (fprintf(fd, "; minpoly = %s", rhs) == EOF) return EOF;
+    }
+    else if (type_id == INTVEC_CMD) fprintf(fd, ")");
+  }
+  return 1;
+}
+
+BOOLEAN slGetDumpAscii(si_link l)
+{
+  if (l->name[0] == '\0')
+  {
+    Werror("getdump: Can not get dump from stdin");
+    return TRUE;
+  }
+  else
+  {
+    BOOLEAN status = newFile(l->name);
+    if (status)
+      return TRUE;
+
+    int old_echo=si_echo;
+    si_echo=0;
+
+    status=yyparse();
+
+    si_echo=old_echo;
+
+    if (status)
+      return TRUE;
+    else
+    {
+      // lets reset the file pointer to the end to reflect that
+      // we are finished with reading
+      FILE *f = (FILE *) l->data;
+      fseek(f, 0L, SEEK_END);
+      return FALSE;
+    }
+  }
+}
+
+
+/*------------Initialization at Start-up time------------------------*/
+
+#include <Singular/slInit.h>
+
+static si_link_extension slTypeInit(si_link_extension s, const char* type)
+{
+  assume(s != NULL);
+  s->next = NULL;
+  si_link_extension ns = (si_link_extension)omAlloc0Bin(s_si_link_extension_bin);
+
+  if (0) 0;
+#ifdef HAVE_DBM
+  else if (strcmp(type, "DBM") == 0)
+    s->next = slInitDBMExtension(ns);
+#endif
+#if 1
+  else if (strcmp(type, "ssi") == 0)
+    s->next = slInitSsiExtension(ns);
+#endif
+#if 1
+  else if (strcmp(type, "|") == 0)
+    s->next = slInitPipeExtension(ns);
+#endif
+  else
+  {
+    Warn("Found unknown link type: %s", type);
+    Warn("Use default link type: %s", si_link_root->type);
+    omFreeBin(ns, s_si_link_extension_bin);
+    return si_link_root;
+  }
+
+  if (s->next == NULL)
+  {
+    Werror("Can not initialize link type %s", type);
+    omFreeBin(ns, s_si_link_extension_bin);
+    return NULL;
+  }
+  return s->next;
+}
+
+void slStandardInit()
+{
+  si_link_extension s;
+  si_link_root=(si_link_extension)omAlloc0Bin(s_si_link_extension_bin);
+  si_link_root->Open=slOpenAscii;
+  si_link_root->Close=slCloseAscii;
+  si_link_root->Kill=slCloseAscii;
+  si_link_root->Read=slReadAscii;
+  si_link_root->Read2=slReadAscii2;
+  si_link_root->Write=slWriteAscii;
+  si_link_root->Dump=slDumpAscii;
+  si_link_root->GetDump=slGetDumpAscii;
+  si_link_root->Status=slStatusAscii;
+  si_link_root->type="ASCII";
+  s = si_link_root;
+  s->next = NULL;
+}
Index: Singular/links/sing_dbm.cc
===================================================================
--- Singular/links/sing_dbm.cc	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
+++ Singular/links/sing_dbm.cc	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
@@ -0,0 +1,461 @@
+/****************************************
+*  Computer Algebra System SINGULAR     *
+****************************************/
+
+//**************************************************************************/
+//
+//
+//**************************************************************************/
+//  'sing_dbm.cc' containes command to handle dbm-files under
+// Singular.
+//
+//**************************************************************************/
+
+#  include <stdio.h>
+#  include <fcntl.h>
+#  include <errno.h>
+
+#include "config.h"
+#include <kernel/mod2.h>
+
+#ifdef HAVE_DBM
+
+#  include <Singular/tok.h>
+#  include <kernel/febase.h>
+#include <omalloc/omalloc.h>
+#  include <Singular/ipid.h>
+#  include <Singular/silink.h>
+#  include <Singular/links/sing_dbm.h>
+
+// #ifdef ix86_Win
+// #  define USE_GDBM
+// #  define BLOCKSIZE 1
+// #  define GDBM_STATIC
+// #  include <gdbm.h>
+// #endif
+
+#ifdef USE_GDBM
+typedef struct {
+  GDBM_FILE db;        // pointer to open database
+  int first;      // firstkey to look for?
+  datum actual;  // the actual key
+} GDBM_info;
+
+//**************************************************************************/
+LINKAGE BOOLEAN dbOpen(si_link l, short flag, leftv u)
+{
+  char *mode = "r";
+  GDBM_info *db;
+  datum d_key;
+  //  int dbm_flags = O_RDONLY | O_CREAT;  // open database readonly as default
+  int read_write= GDBM_READER;
+
+  if(flag & SI_LINK_WRITE)
+  {
+ //    if((l->mode==NULL)
+//     || ((l->mode[0]!='w')&&(l->mode[1]!='w')))
+//     {
+//       // request w- open, but mode is not "w" nor "rw" => fail
+//       return TRUE;
+//    }
+    //    dbm_flags = O_RDWR | O_CREAT;
+    read_write =  GDBM_WRCREAT | GDBM_NOLOCK;
+    mode = "rw";
+  }
+  if(flag & SI_LINK_READ)
+    {
+      if (strcmp(l->mode,"rw")==0) mode="rw";	
+    }
+  //if (((db = (DBM_info *)omAlloc(sizeof *db)) != NULL)
+  //&&((db->db = dbm_open(l->name, dbm_flags, 0664 )) != NULL ))
+  db = (GDBM_info *)omAlloc0(sizeof *db);
+  if((db->db = gdbm_open(l->name, BLOCKSIZE, read_write, 0664, 0)) != NULL )
+  {
+//     if (db->first) // first created?
+//       {
+//         db->actual=gdbm_firstkey(db->db);
+//       }
+//     else
+//       {
+//     d_key=db->actual;
+//     if (d_key.dptr!=NULL)
+//       {
+//         db->actual=gdbm_nextkey(db->db,db->actual);
+//       }
+//     else { db->actual=gdbm_firstkey(db->db); }
+//      }
+    db->first=1;
+    if(flag & SI_LINK_WRITE)
+      SI_LINK_SET_W_OPEN_P(l);
+    else
+      SI_LINK_SET_R_OPEN_P(l);
+    l->data=(void *)(db);
+    omFree(l->mode);
+    l->mode=omStrDup(mode);
+    return FALSE;
+  }
+  Print("%d/%s",gdbm_errno,gdbm_strerror(gdbm_errno));
+  return TRUE;
+}
+
+//**************************************************************************/
+LINKAGE BOOLEAN dbClose(si_link l)
+{
+  GDBM_info *db = (GDBM_info *)l->data;
+  gdbm_sync(db->db);
+  gdbm_close(db->db);
+  omFreeSize((ADDRESS)db,(sizeof *db));
+  l->data=NULL;
+  SI_LINK_SET_CLOSE_P(l);
+  return FALSE;
+}
+
+//**************************************************************************/
+static datum d_value;
+LINKAGE leftv dbRead2(si_link l, leftv key)
+{
+  GDBM_info *db = (GDBM_info *)l->data;
+  // GDBM_info *db;
+//   db = (GDBM_info *)omAlloc0(sizeof *db);
+//   db = (GDBM_info *)l->data;
+  leftv v=NULL;
+  datum d_key;
+  int flag;
+
+  if (!SI_LINK_R_OPEN_P(l)) //exceptions
+    //  if (strcmp(l->mode,"rw")==0) //rw-mode
+    {
+      if (!SI_LINK_CLOSE_P(l))
+	{
+	  if (!dbClose(l)) {Print("cannot close link!\n");}
+	}
+      //(SI_LINK_CLOSE_P(l)) automatically
+      if (dbOpen(l, SI_LINK_READ)) return NULL;
+    }
+  if (SI_LINK_RW_OPEN_P(l)) {Print("I/O Error!\n");}
+
+  if(key!=NULL)
+  {
+    if (key->Typ()==STRING_CMD)
+    {
+      d_key.dptr = (char*)key->Data();
+      d_key.dsize = strlen(d_key.dptr)+1;
+      d_value = gdbm_fetch(db->db, d_key);
+      v=(leftv)omAlloc0Bin(sleftv_bin);
+      if (d_value.dptr!=NULL) v->data=omStrDup(d_value.dptr);
+      else                    v->data=omStrDup("");
+      v->rtyp=STRING_CMD;
+    }
+    else
+    {
+      WerrorS("read(`GDBM link`,`string`) expected");
+    }
+  }
+  else
+  {
+    if (db->first)
+    {
+      db->first=0;
+      d_key = gdbm_firstkey(db->db);
+   //    db->actual=d_key;
+//       Print("firstkey:%s\n",d_key.dptr);
+    }
+    else
+    {
+      if (db->actual.dptr==NULL)
+      {
+	db->actual=gdbm_firstkey(db->db);
+      }
+      d_key = gdbm_nextkey(db->db,db->actual);
+      db->actual=d_key;
+      if (d_key.dptr==NULL)
+      {
+        db->first=1;
+      // Print("nextkey:NULL\n");
+      }
+     //  else
+//       Print("nextkey:%s\n",d_key.dptr);
+    }
+
+    if (d_key.dptr!=NULL)
+      d_value = gdbm_fetch(db->db, d_key);
+    else
+      d_value.dptr=NULL;
+
+    v=(leftv)omAlloc0Bin(sleftv_bin);
+    v->rtyp=STRING_CMD;
+    if (d_value.dptr!=NULL)
+    {
+      v->data=omStrDup(d_key.dptr);
+      db->first = 0;
+    }
+    else
+    {
+      v->data=omStrDup("");
+      //      db->first = 1;
+    }
+
+  }
+  return v;
+}
+LINKAGE leftv dbRead1(si_link l)
+{
+  return dbRead2(l,NULL);
+}
+//**************************************************************************/
+LINKAGE BOOLEAN dbWrite(si_link l, leftv key)
+{
+  GDBM_info *db = (GDBM_info *)l->data;
+ //  GDBM_info *db;
+//   db = (GDBM_info *)omAlloc0(sizeof *db);
+//   db = (GDBM_info *)l->data;
+  BOOLEAN b=TRUE;
+  register int ret;
+
+  if (strcmp(l->mode,"rw")!=0) // r-mode
+    {
+      Print("Write error on readonly source\n");
+    }
+  else //rw-mode
+    {
+      if (!SI_LINK_W_OPEN_P(l)) //exceptions
+	{
+	  if (!SI_LINK_CLOSE_P(l))
+	    {
+	      if (!dbClose(l)) {Print("close error\n");};
+	    }
+	  if (!dbOpen(l,SI_LINK_WRITE)) {Print("open_for_write error\n");}
+	}
+    }
+
+  if((key!=NULL) && (key->Typ()==STRING_CMD) )
+  {
+    if (key->next!=NULL)                   // have a second parameter ?
+    {
+      if(key->next->Typ()==STRING_CMD)     // replace (key,value)
+      {
+        datum d_key, d_value;
+
+        d_key.dptr = (char *)key->Data();
+        d_key.dsize = strlen(d_key.dptr)+1;
+        d_value.dptr = (char *)key->next->Data();
+        d_value.dsize = strlen(d_value.dptr)+1;
+        ret  = gdbm_store(db->db, d_key, d_value, GDBM_REPLACE);
+//         db->actual=d_key;
+	if (ret==-1) {Print("reader calls gdbm_store!");}
+        if (ret==0)
+          { b=FALSE; }
+        else
+        {
+          //          if(gdbm_error(db->db))
+          if (gdbm_errno != 0)
+          {
+            Werror("GDBM link I/O error: '%s' ", gdbm_errno);
+	    //            Print(gdbm_strerror(gdbm_errno));
+            //dbm_clearerr(db->db);
+	    //            gdbm_errno=0;
+          }
+        }
+      }
+    }
+    else
+    {                               // delete (key)
+      datum d_key;
+
+      d_key.dptr = (char *)key->Data();
+      d_key.dsize = strlen(d_key.dptr)+1;
+ //      db->actual=gdbm_nextkey(db->db,d_key);
+      gdbm_delete(db->db, d_key);
+      b=FALSE;
+    }
+  }
+  else
+  {
+    WerrorS("write(`GDBM link`,`key string` [,`data string`]) expected");
+  }
+  gdbm_sync(db->db);
+  return b;
+}
+#endif /* USE_GDBM */
+
+#ifndef USE_GDBM
+/* These are the routines in dbm. */
+#  include "ndbm.h"
+typedef struct {
+  DBM *db;        // pointer to open database
+  int first;      // firstkey to look for?
+} DBM_info;
+
+//**************************************************************************/
+LINKAGE BOOLEAN dbOpen(si_link l, short flag, leftv u)
+{
+  const char *mode = "r";
+  DBM_info *db;
+  int dbm_flags = O_RDONLY | O_CREAT;  // open database readonly as default
+
+  if((l->mode!=NULL)
+  && ((l->mode[0]=='w')||(l->mode[1]=='w')))
+  {
+    dbm_flags = O_RDWR | O_CREAT;
+    mode = "rw";
+    flag|=SI_LINK_WRITE|SI_LINK_READ;
+  }
+  else if(flag & SI_LINK_WRITE)
+  {
+    // request w- open, but mode is not "w" nor "rw" => fail
+    return TRUE;
+  }
+  //if (((db = (DBM_info *)omAlloc(sizeof *db)) != NULL)
+  //&&((db->db = dbm_open(l->name, dbm_flags, 0664 )) != NULL ))
+  db = (DBM_info *)omAlloc(sizeof *db);
+  if((db->db = dbm_open(l->name, dbm_flags, 0664 )) != NULL )
+  {
+    db->first=1;
+    if(flag & SI_LINK_WRITE)
+      SI_LINK_SET_RW_OPEN_P(l);
+    else
+      SI_LINK_SET_R_OPEN_P(l);
+    l->data=(void *)(db);
+    omFree(l->mode);
+    l->mode=omStrDup(mode);
+    return FALSE;
+  }
+  return TRUE;
+}
+
+//**************************************************************************/
+LINKAGE BOOLEAN dbClose(si_link l)
+{
+  DBM_info *db = (DBM_info *)l->data;
+
+  dbm_close(db->db);
+  omFreeSize((ADDRESS)db,(sizeof *db));
+  l->data=NULL;
+  SI_LINK_SET_CLOSE_P(l);
+  return FALSE;
+}
+
+//**************************************************************************/
+static datum d_value;
+LINKAGE leftv dbRead2(si_link l, leftv key)
+{
+  DBM_info *db = (DBM_info *)l->data;
+  leftv v=NULL;
+  datum d_key;
+
+  if(key!=NULL)
+  {
+    if (key->Typ()==STRING_CMD)
+    {
+      d_key.dptr = (char*)key->Data();
+      d_key.dsize = strlen(d_key.dptr)+1;
+      d_value = dbm_fetch(db->db, d_key);
+      v=(leftv)omAlloc0Bin(sleftv_bin);
+      if (d_value.dptr!=NULL) v->data=omStrDup(d_value.dptr);
+      else                    v->data=omStrDup("");
+      v->rtyp=STRING_CMD;
+    }
+    else
+    {
+      WerrorS("read(`DBM link`,`string`) expected");
+    }
+  }
+  else
+  {
+    if(db->first)
+      d_value = dbm_firstkey((DBM *)db->db);
+    else
+      d_value = dbm_nextkey((DBM *)db->db);
+
+    v=(leftv)omAlloc0Bin(sleftv_bin);
+    v->rtyp=STRING_CMD;
+    if (d_value.dptr!=NULL)
+    {
+      v->data=omStrDup(d_value.dptr);
+      db->first = 0;
+    }
+    else
+    {
+      v->data=omStrDup("");
+      db->first = 1;
+    }
+
+  }
+  return v;
+}
+LINKAGE leftv dbRead1(si_link l)
+{
+  return dbRead2(l,NULL);
+}
+//**************************************************************************/
+LINKAGE BOOLEAN dbWrite(si_link l, leftv key)
+{
+  DBM_info *db = (DBM_info *)l->data;
+  BOOLEAN b=TRUE;
+  register int ret;
+
+  // database is opened
+  if((key!=NULL) && (key->Typ()==STRING_CMD) )
+  {
+    if (key->next!=NULL)                   // have a second parameter ?
+    {
+      if(key->next->Typ()==STRING_CMD)     // replace (key,value)
+      {
+        datum d_key, d_value;
+
+        d_key.dptr = (char *)key->Data();
+        d_key.dsize = strlen(d_key.dptr)+1;
+        d_value.dptr = (char *)key->next->Data();
+        d_value.dsize = strlen(d_value.dptr)+1;
+        ret  = dbm_store(db->db, d_key, d_value, DBM_REPLACE);
+        if(!ret )
+          b=FALSE;
+        else
+        {
+          if(dbm_error(db->db))
+          {
+            Werror("DBM link I/O error. Is '%s' readonly?", l->name);
+            dbm_clearerr(db->db);
+          }
+        }
+      }
+    }
+    else
+    {                               // delete (key)
+      datum d_key;
+
+      d_key.dptr = (char *)key->Data();
+      d_key.dsize = strlen(d_key.dptr)+1;
+      dbm_delete(db->db, d_key);
+      b=FALSE;
+    }
+  }
+  else
+  {
+    WerrorS("write(`DBM link`,`key string` [,`data string`]) expected");
+  }
+  return b;
+}
+//**************************************************************************/
+//char *dbStatus(si_link l, char *request)
+//{
+//  if (strcmp(request, "read") == 0)
+//  {
+//    if (SI_LINK_R_OPEN_P(l))
+//      return "ready";
+//    else
+//      return "not ready";
+//  }
+//  else if (strcmp(request, "write") == 0)
+//  {
+//    if (SI_LINK_W_OPEN_P(l))
+//      return "ready";
+//    else
+//      return "not ready";
+//  }
+//  else return "unknown status request";
+//}
+//**************************************************************************/
+
+#endif /* USE_GDBM */
+#endif /* HAVE_DBM */
Index: Singular/links/sing_dbm.h
===================================================================
--- Singular/links/sing_dbm.h	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
+++ Singular/links/sing_dbm.h	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
@@ -0,0 +1,14 @@
+#ifndef SING_DBM_H
+#define SING_DBM_H
+/****************************************
+*  Computer Algebra System SINGULAR     *
+****************************************/
+/*
+* ABSTRACT: interface to DBM links
+*/
+
+struct s_si_link_extension;
+typedef struct s_si_link_extension *si_link_extension;
+
+si_link_extension slInitDBMExtension(si_link_extension s);
+#endif
Index: Singular/links/ssiLink.cc
===================================================================
--- Singular/links/ssiLink.cc	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
+++ Singular/links/ssiLink.cc	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
@@ -0,0 +1,1639 @@
+/****************************************
+ * Computer Algebra System SINGULAR     *
+ ****************************************/
+/***************************************************************
+ * File:    ssiLink.h
+ *  Purpose: declaration of sl_link routines for ssi
+ ***************************************************************/
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <signal.h>
+#include <sys/types.h>          /* for portability */
+#include <sys/select.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <ctype.h>   /*for isdigit*/
+#include <netdb.h>
+#include <sys/wait.h>
+
+
+
+#include "config.h"
+#include <kernel/mod2.h>
+
+#include <Singular/tok.h>
+#include <Singular/ipshell.h>
+#include <Singular/ipid.h>
+#include <omalloc/omalloc.h>
+#include <polys/monomials/ring.h>
+#include <polys/matpol.h>
+#include <kernel/ideals.h>
+#include <kernel/polys.h>
+#include <kernel/longrat.h>
+#include <kernel/ideals.h>
+#include <misc/intvec.h>
+#include <misc/options.h>
+#include <kernel/timer.h>
+#include <Singular/subexpr.h>
+#include <Singular/silink.h>
+#include <Singular/cntrlc.h>
+#include <Singular/lists.h>
+#include <Singular/blackbox.h>
+#include <Singular/links/ssiLink.h>
+
+struct snumber_dummy
+{
+  mpz_t z;
+  mpz_t n;
+  #if defined(LDEBUG)
+  int debug;
+  #endif
+  BOOLEAN s;
+};
+typedef struct snumber_dummy  *number_dummy;
+
+//#if (_POSIX_C_SOURCE >= 200112L) || (_XOPEN_SOURCE >= 600)
+//#define HAVE_PSELECT
+//#endif
+
+#define SSI_VERSION 3
+
+typedef struct
+{
+  FILE *f_read;
+  FILE *f_write;
+  ring r;
+  pid_t pid; /* only valid for fork/tcp mode*/
+  int fd_read,fd_write; /* only valid for fork/tcp mode*/
+  char level;
+  char ungetc_buf; /* status sets to !=0, if ungetc was used, ssiRead* set to 0*/
+  char send_quit_at_exit;
+
+} ssiInfo;
+
+
+link_list ssiToBeClosed=NULL;
+sigset_t ssi_sigmask;
+sigset_t ssi_oldmask;
+#define SSI_BLOCK_CHLD sigprocmask(SIG_SETMASK, &ssi_sigmask, &ssi_oldmask)
+#define SSI_UNBLOCK_CHLD sigprocmask(SIG_SETMASK, &ssi_oldmask, NULL)
+
+#define SR_INT 1L
+#define SR_HDL(A) ((long)(A))
+#define SR_TO_INT(SR)   (((long)SR) >> 2)
+
+// the helper functions:
+void ssiSetCurrRing(const ring r)
+{
+  if (!rEqual(r,currRing,1))
+  {
+    char name[20];
+    int nr=0;
+    do
+    { sprintf(name,"ssiRing%d",nr); nr++; }
+    while(IDROOT->get(name, 0)!=NULL);
+    idhdl h=enterid(omStrDup(name),0,RING_CMD,&IDROOT,FALSE);
+    IDRING(h)=r;
+    r->ref++;
+    rSetHdl(h);
+  }
+}
+// the implementation of the functions:
+void ssiWriteInt(ssiInfo *d,const int i)
+{
+  SSI_BLOCK_CHLD;
+  fprintf(d->f_write,"%d ",i);
+  SSI_UNBLOCK_CHLD;
+  //if (d->f_debug!=NULL) fprintf(d->f_debug,"int: %d ",i);
+}
+
+void ssiWriteString(ssiInfo *d,const char *s)
+{
+  SSI_BLOCK_CHLD;
+  fprintf(d->f_write,"%d %s ",strlen(s),s);
+  SSI_UNBLOCK_CHLD;
+  //if (d->f_debug!=NULL) fprintf(d->f_debug,"stringi: %d \"%s\" ",strlen(s),s);
+}
+
+
+void ssiWriteBigInt(const ssiInfo *d, const number n)
+{
+  // syntax is as follows:
+  // case 2 Q:     3 4 <int>
+  //        or     3 3 <mpz_t nominator>
+  SSI_BLOCK_CHLD;
+  if((long)(n) & SR_INT)
+  {
+    fprintf(d->f_write,"4 %ld ",SR_TO_INT(n));
+    //if (d->f_debug!=NULL) fprintf(d->f_debug,"bigint: short \"%ld\" ",SR_TO_INT(n));
+  }
+  else if (((number_dummy)n)->s==3)
+  {
+    fputs("3 ",d->f_write);
+    mpz_out_str(d->f_write,10,((number_dummy)n)->z);
+    fputc(' ',d->f_write);
+    //gmp_fprintf(d->f_write,"3 %Zd ",n->z);
+    //if (d->f_debug!=NULL) gmp_fprintf(d->f_debug,"bigint: gmp \"%Zd\" ",n->z);
+  }
+  else WerrorS("illiegal bigint");
+  SSI_UNBLOCK_CHLD;
+}
+
+void ssiWriteNumber(const ssiInfo *d, const number n)
+{
+  // syntax is as follows:
+  // case 1 Z/p:   3 <int>
+  // case 2 Q:     3 4 <int>
+  //        or     3 0 <mpz_t nominator> <mpz_t denominator>
+  //        or     3 1  dto.
+  //        or     3 3 <mpz_t nominator>
+  //        or     3 5 <mpz_t raw nom.> <mpz_t raw denom.>
+  //        or     3 6 <mpz_t raw nom.> <mpz_t raw denom.>
+  //        or     3 7 <mpz_t raw nom.>
+  SSI_BLOCK_CHLD;
+  if(rField_is_Zp(d->r))
+  {
+    fprintf(d->f_write,"%d ",(int)(long)n);
+    //if (d->f_debug!=NULL) fprintf(d->f_debug,"number: \"%ld\" ",(int)(long)n);
+  }
+  else if (rField_is_Q(d->r))
+  {
+    if(SR_HDL(n) & SR_INT)
+    {
+      fprintf(d->f_write,"4 %ld ",SR_TO_INT(n));
+      //if (d->f_debug!=NULL) fprintf(d->f_debug,"number: short \"%ld\" ",SR_TO_INT(n));
+    }
+    else if (((number_dummy)n)->s<2)
+    {
+      //gmp_fprintf(d->f_write,"%d %Zd %Zd ",n->s,n->z,n->n);
+      fprintf(d->f_write,"%d ",((number_dummy)n)->s+5);
+      mpz_out_str (d->f_write,32, ((number_dummy)n)->z);
+      fputc(' ',d->f_write);
+      mpz_out_str (d->f_write,32, ((number_dummy)n)->n);
+      fputc(' ',d->f_write);
+
+      //if (d->f_debug!=NULL) gmp_fprintf(d->f_debug,"number: s=%d gmp/gmp \"%Zd %Zd\" ",n->s,n->z,n->n);
+    }
+    else /*n->s==3*/
+    {
+      //gmp_fprintf(d->f_write,"3 %Zd ",n->z);
+      fputs("8 ",d->f_write);
+      mpz_out_str (d->f_write,32, ((number_dummy)n)->z);
+      fputc(' ',d->f_write);
+
+      //if (d->f_debug!=NULL) gmp_fprintf(d->f_debug,"number: gmp \"%Zd\" ",n->z);
+    }
+  }
+  else WerrorS("coeff field not implemented");
+  SSI_UNBLOCK_CHLD;
+}
+
+void ssiWriteRing(ssiInfo *d,const ring r)
+{
+  /* 5 <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... */
+  if (d->r!=NULL) rKill(d->r);
+  d->r=r;
+  d->r->ref++;
+  SSI_BLOCK_CHLD;
+  fprintf(d->f_write,"%d %d ",n_GetChar(r->cf),r->N);
+
+  int i;
+  for(i=0;i<r->N;i++)
+  {
+    fprintf(d->f_write,"%d %s ",strlen(r->names[i]),r->names[i]);
+  }
+  /* number of orderings:*/
+  i=0;
+  while (r->order[i]!=0) i++;
+  fprintf(d->f_write,"%d ",i);
+  /* each ordering block: */
+  i=0;
+  while(r->order[i]!=0)
+  {
+    fprintf(d->f_write,"%d %d %d ",r->order[i],r->block0[i], r->block1[i]);
+    switch(r->order[i])
+    {
+      case ringorder_a:
+      case ringorder_wp:
+      case ringorder_Wp:
+      case ringorder_ws:
+      case ringorder_Ws:
+      case ringorder_aa:
+      {
+        int ii;
+        for(ii=r->block0[i];ii<=r->block1[i];ii++)
+          fprintf(d->f_write,"%d ",r->wvhdl[i][ii-r->block0[i]]);
+      }
+      break;
+      case ringorder_a64:
+      case ringorder_M:
+      case ringorder_L:
+      case ringorder_IS:
+        Werror("ring oder not implemented for ssi:%d",r->order[i]);
+        break;
+
+      default: break;
+    }
+    i++;
+  }
+  SSI_UNBLOCK_CHLD;
+}
+
+void ssiWritePoly(ssiInfo *d, int typ, poly p)
+{
+  SSI_BLOCK_CHLD;
+  fprintf(d->f_write,"%d ",pLength(p));//number of terms
+  SSI_UNBLOCK_CHLD;
+  int i;
+
+  while(p!=NULL)
+  {
+    ssiWriteNumber(d,pGetCoeff(p));
+    //nWrite(fich,pGetCoeff(p));
+    SSI_BLOCK_CHLD;
+    fprintf(d->f_write,"%ld ",p_GetComp(p,d->r));//component
+
+    for(int j=1;j<=rVar(d->r);j++)
+    {
+      fprintf(d->f_write,"%ld ",p_GetExp(p,j,d->r ));//x^j
+    }
+    pIter(p);
+    SSI_UNBLOCK_CHLD;
+  }
+}
+
+void ssiWriteIdeal(ssiInfo *d, int typ,ideal I)
+{
+   // syntax: 7 # of elements <poly 1> <poly2>.....
+   // syntax: 8 <rows> <cols> <poly 1> <poly2>.....
+   matrix M=(matrix)I;
+   SSI_BLOCK_CHLD;
+   if (typ==MATRIX_CMD)
+        fprintf(d->f_write,"%d %d ", MATROWS(M),MATCOLS(M));
+   else
+     fprintf(d->f_write,"%d ",IDELEMS(I));
+    SSI_UNBLOCK_CHLD;
+
+   int i;
+   int tt;
+   if (typ==MODUL_CMD) tt=VECTOR_CMD;
+   else                tt=POLY_CMD;
+
+   for(i=0;i<IDELEMS(I);i++)
+   {
+     ssiWritePoly(d,tt,I->m[i]);
+   }
+}
+void ssiWriteCommand(si_link l, command D)
+{
+  ssiInfo *d=(ssiInfo*)l->data;
+  // syntax: <num ops> <operation> <op1> <op2> ....
+  SSI_BLOCK_CHLD;
+  fprintf(d->f_write,"%d %d ",D->argc,D->op);
+  SSI_UNBLOCK_CHLD;
+  if (D->argc >0) ssiWrite(l, &(D->arg1));
+  if (D->argc < 4)
+  {
+    if (D->argc >1) ssiWrite(l, &(D->arg2));
+    if (D->argc >2) ssiWrite(l, &(D->arg3));
+  }
+}
+
+void ssiWriteProc(ssiInfo *d,procinfov p)
+{
+  ssiWriteString(d,p->data.s.body);
+}
+
+void ssiWriteList(si_link l,lists dd)
+{
+  ssiInfo *d=(ssiInfo*)l->data;
+  SSI_BLOCK_CHLD;
+  fprintf(d->f_write,"%d ",dd->nr+1);
+  SSI_UNBLOCK_CHLD;
+  int i;
+  for(i=0;i<=dd->nr;i++)
+  {
+    ssiWrite(l,&(dd->m[i]));
+  }
+}
+void ssiWriteIntvec(ssiInfo *d,intvec * v)
+{
+  SSI_BLOCK_CHLD;
+  fprintf(d->f_write,"%d ",v->length());
+  int i;
+  for(i=0;i<v->length();i++)
+  {
+    fprintf(d->f_write,"%d ",(*v)[i]);
+  }
+  SSI_UNBLOCK_CHLD;
+}
+
+char *ssiReadString(ssiInfo *d)
+{
+  char *buf;
+  int l;
+  SSI_BLOCK_CHLD;
+  fscanf(d->f_read,"%d ",&l);
+  SSI_UNBLOCK_CHLD;
+  buf=(char*)omAlloc(l+1);
+  SSI_BLOCK_CHLD;
+  fread(buf,1,l,d->f_read);
+  SSI_UNBLOCK_CHLD;
+  buf[l]='\0';
+  return buf;
+}
+
+int ssiReadInt(FILE *fich)
+{
+  int d;
+  SSI_BLOCK_CHLD;
+  fscanf(fich,"%d",&d);
+  SSI_UNBLOCK_CHLD;
+  return d;
+}
+
+number ssiReadBigInt(ssiInfo *d)
+{
+  int sub_type=-1;
+  SSI_BLOCK_CHLD;
+  fscanf(d->f_read,"%d",&sub_type);
+  SSI_UNBLOCK_CHLD;
+  switch(sub_type)
+  {
+   case 3:
+     {// read int or mpz_t or mpz_t, mpz_t
+       number n=(number)omAlloc0(sizeof(snumber_dummy));
+       SSI_BLOCK_CHLD;
+       mpz_inp_str(((number_dummy)n)->z,d->f_read,0);
+       SSI_UNBLOCK_CHLD;
+       ((number_dummy)n)->s=sub_type;
+       return n;
+     }
+   case 4:
+     {
+       int dd;
+       SSI_BLOCK_CHLD;
+       fscanf(d->f_read,"%d",&dd);
+       SSI_UNBLOCK_CHLD;
+       return n_Init(dd,d->r->cf);
+     }
+   default:
+       Werror("error in reading bigint: invalid subtype %d",sub_type);
+       return NULL;
+   }
+}
+
+number ssiReadNumber(ssiInfo *d)
+{
+  if (rField_is_Q(d->r))
+  {
+     int sub_type=-1;
+     SSI_BLOCK_CHLD;
+     fscanf(d->f_read,"%d",&sub_type);
+     SSI_UNBLOCK_CHLD;
+     switch(sub_type)
+     {
+     case 0:
+     case 1:
+       {// read mpz_t, mpz_t
+         number n=(number)omAlloc0(sizeof(snumber_dummy));
+         mpz_init(((number_dummy)n)->n);
+         SSI_BLOCK_CHLD;
+         gmp_fscanf(d->f_read,"%Zd %Zd",((number_dummy)n)->z,((number_dummy)n)->n);
+         SSI_UNBLOCK_CHLD;
+         ((number_dummy)n)->s=sub_type;
+         return n;
+       }
+
+     case 3:
+       {// read mpz_t
+         number n=(number)omAlloc0(sizeof(snumber_dummy));
+         SSI_BLOCK_CHLD;
+         gmp_fscanf(d->f_read,"%Zd",((number_dummy)n)->z);
+         SSI_UNBLOCK_CHLD;
+         ((number_dummy)n)->s=3; /*sub_type*/
+         return n;
+       }
+     case 4:
+       {
+         int dd;
+         SSI_BLOCK_CHLD;
+         fscanf(d->f_read,"%d",&dd);
+         SSI_UNBLOCK_CHLD;
+         return n_Init(dd,d->r->cf);
+       }
+     case 5:
+     case 6:
+       {// read raw mpz_t, mpz_t
+         number n=(number)omAlloc0(sizeof(snumber_dummy));
+         mpz_init(((number_dummy)n)->n);
+         SSI_BLOCK_CHLD;
+         mpz_inp_str (((number_dummy)n)->z, d->f_read, 32);
+         mpz_inp_str (((number_dummy)n)->n, d->f_read, 32);
+         SSI_UNBLOCK_CHLD;
+         ((number_dummy)n)->s=sub_type-5;
+         return n;
+       }
+     case 8:
+       {// read raw mpz_t
+         number n=(number)omAlloc0(sizeof(snumber_dummy));
+         SSI_BLOCK_CHLD;
+         mpz_inp_str (((number_dummy)n)->z, d->f_read, 32);
+         SSI_UNBLOCK_CHLD;
+         ((number_dummy)n)->s=sub_type=3; /*subtype-5*/
+         return n;
+       }
+
+     default: Werror("error in reading number: invalid subtype %d",sub_type);
+              return NULL;
+     }
+  }
+  else if (rField_is_Zp(d->r))
+  {
+    // read int
+    int dd;
+    SSI_BLOCK_CHLD;
+    fscanf(d->f_read,"%d",&dd);
+    SSI_UNBLOCK_CHLD;
+    return (number)dd;
+  }
+  else Werror("coeffs not implemented");
+  return NULL;
+}
+
+ring ssiReadRing(ssiInfo *d)
+{
+/* syntax is <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... */
+  int ch, N,i,l;
+  char **names;
+  SSI_BLOCK_CHLD;
+  fscanf(d->f_read,"%d %d ",&ch,&N);
+  SSI_UNBLOCK_CHLD;
+  names=(char**)omAlloc(N*sizeof(char*));
+  for(i=0;i<N;i++)
+  {
+    names[i]=ssiReadString(d);
+  }
+  // read the orderings:
+  int num_ord; // number of orderings
+  SSI_BLOCK_CHLD;
+  fscanf(d->f_read,"%d",&num_ord);
+  SSI_UNBLOCK_CHLD;
+  int *ord=(int *)omAlloc0((num_ord+1)*sizeof(int));
+  int *block0=(int *)omAlloc0((num_ord+1)*sizeof(int));
+  int *block1=(int *)omAlloc0((num_ord+1)*sizeof(int));
+  SSI_BLOCK_CHLD;
+  int **wvhdl=(int**)omAlloc0((num_ord+1)*sizeof(int*));
+  for(i=0;i<num_ord;i++)
+  {
+    fscanf(d->f_read,"%d %d %d",&ord[i],&block0[i],&block1[i]);
+    switch(ord[i])
+    {
+      case ringorder_a:
+      case ringorder_wp:
+      case ringorder_Wp:
+      case ringorder_ws:
+      case ringorder_Ws:
+      case ringorder_aa:
+      {
+        wvhdl[i]=(int*)omAlloc((block1[i]-block0[i]+1)*sizeof(int));
+        int ii;
+        for(ii=block0[i];ii<=block1[i];ii++)
+          fscanf(d->f_read,"%d",&(wvhdl[i][ii-block0[i]]));
+      }
+      break;
+
+      case ringorder_a64:
+      case ringorder_M:
+      case ringorder_L:
+      case ringorder_IS:
+        Werror("ring oder not implemented for ssi:%d",ord[i]);
+        break;
+
+      default: break;
+    }
+  }
+  SSI_UNBLOCK_CHLD;
+  return rDefault(ch,N,names,num_ord,ord,block0,block1,wvhdl);
+}
+
+poly ssiReadPoly(ssiInfo *D)
+{
+// < # of terms> < term1> < .....
+  int n,i,l;
+  n=ssiReadInt(D->f_read);
+  //Print("poly: terms:%d\n",n);
+  poly p;
+  int j;
+  j=0;
+  poly ret=NULL;
+  poly prev=NULL;
+  for(l=0;l<n;l++) // read n terms
+  {
+// coef,comp.exp1,..exp N
+    p=p_Init(D->r);
+    pGetCoeff(p)=ssiReadNumber(D);
+    int d;
+    SSI_BLOCK_CHLD;
+    fscanf(D->f_read,"%d",&d);
+    SSI_UNBLOCK_CHLD;
+    p_SetComp(p,d,D->r);
+    for(i=1;i<=rVar(D->r);i++)
+    {
+      SSI_BLOCK_CHLD;
+      fscanf(D->f_read,"%d",&d);
+      SSI_UNBLOCK_CHLD;
+      p_SetExp(p,i,d,D->r);
+    }
+    p_Setm(p,D->r);
+    p_Test(p,D->r);
+    if (ret==NULL) ret=p;
+    else           pNext(prev)=p;
+    prev=p;
+ }
+ return ret;
+}
+
+ideal ssiReadIdeal(ssiInfo *d)
+{
+  int n,i;
+  ideal I;
+  SSI_BLOCK_CHLD;
+  fscanf(d->f_read,"%d",&n);
+  SSI_UNBLOCK_CHLD;
+  I=idInit(n,1);
+  for(i=0;i<IDELEMS(I);i++) // read n terms
+  {
+    I->m [i]=ssiReadPoly(d);
+  }
+  return I;
+}
+
+matrix ssiReadMatrix(ssiInfo *d)
+{
+  int n,m,i,j;
+  SSI_BLOCK_CHLD;
+  fscanf(d->f_read,"%d %d",&m,&n);
+  SSI_UNBLOCK_CHLD;
+  matrix M=mpNew(m,n);
+  poly p;
+  for(int i=1;i<=MATROWS(M);i++)
+    for(int j=1;j<=MATCOLS(M);j++)
+    {
+      p=ssiReadPoly(d);
+      MATELEM(M,i,j)=p;
+    }
+  return M;
+}
+
+command ssiReadCommand(si_link l)
+{
+  ssiInfo *d=(ssiInfo*)l->data;
+  // syntax: <num ops> <operation> <op1> <op2> ....
+  command D=(command)omAlloc0(sizeof(*D));
+  int argc,op;
+  SSI_BLOCK_CHLD;
+  fscanf(d->f_read,"%d %d",&argc,&op);
+  SSI_UNBLOCK_CHLD;
+  D->argc=argc; D->op=op;
+  leftv v;
+  if (argc >0)
+  {
+    v=ssiRead1(l);
+    memcpy(&(D->arg1),v,sizeof(*v));
+    omFreeBin(v,sleftv_bin);
+  }
+  if (argc <4)
+  {
+    if (D->argc >1)
+    {
+      v=ssiRead1(l);
+      memcpy(&(D->arg2),v,sizeof(*v));
+      omFreeBin(v,sleftv_bin);
+    }
+    if (D->argc >2)
+    {
+      v=ssiRead1(l);
+      memcpy(&(D->arg3),v,sizeof(*v));
+      omFreeBin(v,sleftv_bin);
+    }
+  }
+  else
+  {
+    leftv prev=&(D->arg1);
+    argc--;
+    while(argc >0)
+    {
+      v=ssiRead1(l);
+      prev->next=v;
+      prev=v;
+      argc--;
+    }
+  }
+  return D;
+}
+
+procinfov ssiReadProc(ssiInfo *d)
+{
+  char *s=ssiReadString(d);
+  procinfov p=(procinfov)omAlloc0Bin(procinfo_bin);
+  p->language=LANG_SINGULAR;
+  p->libname=omStrDup("");
+  p->procname=omStrDup("");
+  p->data.s.body=s;
+  return p;
+}
+lists ssiReadList(si_link l)
+{
+  ssiInfo *d=(ssiInfo*)l->data;
+  int nr;
+  SSI_BLOCK_CHLD;
+  fscanf(d->f_read,"%d",&nr);
+  SSI_UNBLOCK_CHLD;
+  lists L=(lists)omAlloc(sizeof(*L));
+  L->Init(nr);
+
+  int i;
+  leftv v;
+  for(i=0;i<nr;i++)
+  {
+    v=ssiRead1(l);
+    memcpy(&(L->m[i]),v,sizeof(*v));
+    omFreeBin(v,sleftv_bin);
+  }
+  return L;
+}
+intvec* ssiReadIntvec(ssiInfo *d)
+{
+  int nr;
+  SSI_BLOCK_CHLD;
+  fscanf(d->f_read,"%d",&nr);
+  SSI_UNBLOCK_CHLD;
+  intvec *v=new intvec(nr);
+  SSI_BLOCK_CHLD;
+  for(int i=0;i<nr;i++)
+  {
+    fscanf(d->f_read,"%d",&((*v)[i]));
+  }
+  SSI_UNBLOCK_CHLD;
+  return v;
+}
+
+void ssiReadBlackbox(leftv res, si_link l)
+{
+  ssiInfo *d=(ssiInfo*)l->data;
+  int throwaway;
+  SSI_BLOCK_CHLD;
+  fscanf(d->f_read,"%d ",&throwaway);
+  SSI_UNBLOCK_CHLD;
+  char *name=ssiReadString(d);
+  int tok;
+  blackboxIsCmd(name,tok);
+  if (tok>MAX_TOK)
+  {
+    blackbox *b=getBlackboxStuff(tok);
+    res->rtyp=tok;
+    b->blackbox_deserialize(&b,&(res->data),l);
+  }
+  else
+  {
+    Werror("blackbox %s not found",name);
+  }
+}
+
+//**************************************************************************/
+
+BOOLEAN ssiOpen(si_link l, short flag, leftv u)
+{
+  if (l!=NULL)
+  {
+    const char *mode;
+    ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo));
+    sigprocmask(SIG_SETMASK, NULL, &ssi_sigmask);
+    sigaddset(&ssi_sigmask, SIGCHLD);
+    if (flag & SI_LINK_OPEN)
+    {
+      if (l->mode[0] != '\0' && (strcmp(l->mode, "r") == 0))
+        flag = SI_LINK_READ;
+      else flag = SI_LINK_WRITE;
+    }
+
+    if (flag == SI_LINK_READ) mode = "r";
+    else if (strcmp(l->mode, "w") == 0) mode = "w";
+    else if (strcmp(l->mode, "fork") == 0) mode = "fork";
+    else if (strcmp(l->mode, "tcp") == 0) mode = "tcp";
+    else if (strcmp(l->mode, "connect") == 0) mode = "connect";
+    else mode = "a";
+
+
+    SI_LINK_SET_OPEN_P(l, flag);
+    l->data=d;
+    omFree(l->mode);
+    l->mode = omStrDup(mode);
+
+    if (l->name[0] == '\0')
+    {
+      if (strcmp(mode,"fork")==0)
+      {
+        link_list n=(link_list)omAlloc(sizeof(link_struct));
+        n->u=u;
+        n->l=l;
+        n->next=(void *)ssiToBeClosed;
+        ssiToBeClosed=n;
+
+        int pc[2];
+        int cp[2];
+        pipe(pc);
+        pipe(cp);
+        pid_t pid=fork();
+        if (pid==0) /*fork: child*/
+        {
+          link_list hh=(link_list)ssiToBeClosed->next;
+          /* we know: l is the first entry in ssiToBeClosed-list */
+          while(hh!=NULL)
+          {
+            ssiInfo *dd=(ssiInfo*)hh->l->data;
+            fclose(dd->f_read);
+            fclose(dd->f_write);
+            if (dd->r!=NULL) rKill(dd->r);
+            omFreeSize((ADDRESS)dd,(sizeof *dd));
+            hh->l->data=NULL;
+            SI_LINK_SET_CLOSE_P(hh->l);
+            link_list nn=(link_list)hh->next;
+            omFree(hh);
+            hh=nn;
+          }
+          ssiToBeClosed->next=NULL;
+          close(pc[1]); close(cp[0]);
+          d->f_read=fdopen(pc[0],"r");
+          d->fd_read=pc[0];
+          d->f_write=fdopen(cp[1],"w");
+          d->fd_write=cp[1];
+          l->data=d;
+          omFree(l->mode);
+          l->mode = omStrDup(mode);
+          singular_in_batchmode=TRUE;
+          SI_LINK_SET_RW_OPEN_P(l);
+          //myynest=0;
+          fe_fgets_stdin=fe_fgets_dummy;
+          WerrorS_callback=WerrorS_batch;
+          if ((u!=NULL)&&(u->rtyp==IDHDL))
+          {
+            idhdl h=(idhdl)u->data;
+            h->lev=0;
+          }
+          loop
+          {
+            leftv h=ssiRead1(l); /*contains an exit.... */
+            if (feErrors != NULL && *feErrors != '\0')
+            {
+              // handle errors:
+              PrintS(feErrors); /* currently quite simple */
+              *feErrors = '\0';
+            }
+            ssiWrite(l,h);
+            h->CleanUp();
+            omFreeBin(h, sleftv_bin);
+          }
+          /* never reached*/
+        }
+        else if (pid>0) /*fork: parent*/
+        {
+          d->pid=pid;
+          close(pc[0]); close(cp[1]);
+          d->f_read=fdopen(cp[0],"r");
+          d->fd_read=cp[0];
+          d->f_write=fdopen(pc[1],"w");
+          d->fd_write=pc[1];
+          SI_LINK_SET_RW_OPEN_P(l);
+          d->send_quit_at_exit=1;
+        }
+        else
+        {
+          Werror("fork failed (%d)",errno);
+          l->data=NULL;
+          omFree(d);
+          return TRUE;
+        }
+      }
+      // ---------------------------------------------------------------------
+      else if (strcmp(mode,"tcp")==0)
+      {
+        int sockfd, newsockfd, portno, clilen;
+        struct sockaddr_in serv_addr, cli_addr;
+        int n;
+        sockfd = socket(AF_INET, SOCK_STREAM, 0);
+        if(sockfd < 0)
+        {
+          WerrorS("ERROR opening socket");
+          l->data=NULL;
+          omFree(d);
+          return TRUE;
+        }
+        memset((char *) &serv_addr,0, sizeof(serv_addr));
+        portno = 1025;
+        serv_addr.sin_family = AF_INET;
+        serv_addr.sin_addr.s_addr = INADDR_ANY;
+        do
+        {
+          portno++;
+          serv_addr.sin_port = htons(portno);
+          if(portno > 50000)
+          {
+            WerrorS("ERROR on binding (no free port available?)");
+            l->data=NULL;
+            omFree(d);
+            return TRUE;
+          }
+        }
+        while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
+        Print("waiting on port %d\n", portno);mflush();
+        listen(sockfd,5);
+        newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
+        if(newsockfd < 0)
+        {
+          WerrorS("ERROR on accept");
+          l->data=NULL;
+          omFree(d);
+          return TRUE;
+        }
+        PrintS("client accepted\n");
+        d->fd_read = newsockfd;
+        d->fd_write = newsockfd;
+        d->f_read = fdopen(newsockfd, "r");
+        d->f_write = fdopen(newsockfd, "w");
+        SI_LINK_SET_RW_OPEN_P(l);
+        close(sockfd);
+      }
+      // no ssi-Link on stdin or stdout
+      else
+      {
+        Werror("invalid mode >>%s<< for ssi",mode);
+        l->data=NULL;
+        omFree(d);
+        return TRUE;
+      }
+    }
+    // =========================================================================
+    else /*l->name=NULL*/
+    {
+      // tcp mode
+      if(strcmp(mode,"tcp")==0)
+      {
+        int sockfd, newsockfd, portno, clilen;
+        struct sockaddr_in serv_addr, cli_addr;
+        int n;
+        sockfd = socket(AF_INET, SOCK_STREAM, 0);
+        if(sockfd < 0)
+        {
+          WerrorS("ERROR opening socket");
+          l->data=NULL;
+          omFree(d);
+          return TRUE;
+        }
+        memset((char *) &serv_addr,0, sizeof(serv_addr));
+        portno = 1025;
+        serv_addr.sin_family = AF_INET;
+        serv_addr.sin_addr.s_addr = INADDR_ANY;
+        do
+        {
+          portno++;
+          serv_addr.sin_port = htons(portno);
+          if(portno > 50000)
+          {
+            WerrorS("ERROR on binding (no free port available?)");
+            l->data=NULL;
+            return TRUE;
+          }
+        }
+        while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
+        //Print("waiting on port %d\n", portno);mflush();
+        listen(sockfd,5);
+        char* cli_host = (char*)omAlloc(256);
+        char* path = (char*)omAlloc(1024);
+        int r = sscanf(l->name,"%255[^:]:%s",cli_host,path);
+        if(r == 0)
+        {
+          WerrorS("ERROR: no host specified");
+          l->data=NULL;
+          omFree(d);
+          omFree(path);
+          omFree(cli_host);
+          return TRUE;
+        }
+        else if(r == 1)
+        {
+          WarnS("program not specified, using /usr/local/bin/Singular");
+          strcpy(path,"/usr/local/bin/Singular");
+        }
+        char* ssh_command = (char*)omAlloc(256);
+        char* ser_host = (char*)omAlloc(64);
+        gethostname(ser_host,64);
+        sprintf(ssh_command,"ssh %s %s -q --batch --link=ssi --MPhost=%s --MPport=%d &",cli_host,path,ser_host,portno);
+        //Print("client on %s started:%s\n",cli_host,path);
+        omFree(path);
+        omFree(cli_host);
+        if (TEST_OPT_PROT) { Print("running >>%s<<\n",ssh_command); }
+        system(ssh_command);
+        omFree(ssh_command);
+        omFree(ser_host);
+        clilen = sizeof(cli_addr);
+        newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
+        if(newsockfd < 0)
+        {
+          WerrorS("ERROR on accept");
+          l->data=NULL;
+          omFree(d);
+          return TRUE;
+        }
+        //PrintS("client accepted\n");
+        d->fd_read = newsockfd;
+        d->fd_write = newsockfd;
+        d->f_read = fdopen(newsockfd, "r");
+        d->f_write = fdopen(newsockfd, "w");
+        SI_LINK_SET_RW_OPEN_P(l);
+        d->send_quit_at_exit=1;
+        close(sockfd);
+        fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,test,verbose);
+      }
+      // ----------------------------------------------------------------------
+      else if(strcmp(mode,"connect")==0)
+      {
+        char* host = (char*)omAlloc(256);
+        int sockfd, portno, n;
+        struct sockaddr_in serv_addr;
+        struct hostent *server;
+
+        sscanf(l->name,"%255[^:]:%d",host,&portno);
+        //Print("connect to host %s, port %d\n",host,portno);mflush();
+        if (portno!=0)
+        {
+          sockfd = socket(AF_INET, SOCK_STREAM, 0);
+          if (sockfd < 0) { WerrorS("ERROR opening socket"); return TRUE; }
+          server = gethostbyname(host);
+          if (server == NULL) {  WerrorS("ERROR, no such host");  return TRUE; }
+          memset((char *) &serv_addr, 0, sizeof(serv_addr));
+          serv_addr.sin_family = AF_INET;
+          memcpy((char *)&serv_addr.sin_addr.s_addr,
+                (char *)server->h_addr,
+                server->h_length);
+          serv_addr.sin_port = htons(portno);
+          if (connect(sockfd,(sockaddr*)&serv_addr,sizeof(serv_addr)) < 0)
+          { Werror("ERROR connecting(errno=%d)",errno); return TRUE; }
+          //PrintS("connected\n");mflush();
+          d->f_read=fdopen(sockfd,"r");
+          d->fd_read=sockfd;
+          d->f_write=fdopen(sockfd,"w");
+          d->fd_write=sockfd;
+          SI_LINK_SET_RW_OPEN_P(l);
+          d->send_quit_at_exit=1;
+          omFree(host);
+        }
+        else
+        {
+          l->data=NULL;
+          omFree(d);
+          return TRUE;
+        }
+      }
+      // ======================================================================
+      else
+      {
+        // normal link to a file
+        FILE *outfile;
+        char *filename=l->name;
+
+        if(filename[0]=='>')
+        {
+          if (filename[1]=='>')
+          {
+            filename+=2;
+            mode = "a";
+          }
+          else
+          {
+            filename++;
+            mode="w";
+          }
+        }
+        outfile=myfopen(filename,mode);
+        if (outfile!=NULL)
+        {
+          if (strcmp(l->mode,"r")==0) d->f_read = outfile;
+          else
+          {
+            d->f_write = outfile;
+            fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,test,verbose);
+          }
+        }
+        else
+        {
+          omFree(d);
+          l->data=NULL;
+          return TRUE;
+        }
+      }
+    }
+  }
+
+  return FALSE;
+}
+
+//**************************************************************************/
+BOOLEAN ssiClose(si_link l)
+{
+  if (l!=NULL)
+  {
+    ssiInfo *d = (ssiInfo *)l->data;
+    if (d!=NULL)
+    {
+      if (d->r!=NULL) rKill(d->r);
+      if ((strcmp(l->mode,"tcp")==0)
+      || (strcmp(l->mode,"fork")==0))
+      {
+        link_list hh=ssiToBeClosed;
+        if (hh!=NULL)
+        {
+          if (hh->l==l)
+          {
+             ssiToBeClosed=(link_list)hh->next;
+             omFreeSize(hh,sizeof(link_struct));
+          }
+          else while(hh!=NULL)
+          {
+            link_list hhh=(link_list)hh->next;
+            if (hhh->l==l)
+            {
+              hh->next=hhh->next;
+              omFreeSize(hhh,sizeof(link_struct));
+              break;
+            }
+            hh=(link_list)hh->next;
+          }
+        }
+        if (d->send_quit_at_exit)
+        {
+          fputs("99\n",d->f_write);fflush(d->f_write);
+        }
+      }
+      if (d->f_read!=NULL) fclose(d->f_read);
+      if (d->f_write!=NULL) fclose(d->f_write);
+      if (d->pid!=0)
+      {
+        kill(d->pid,15);
+        waitpid(d->pid,NULL,WNOHANG);
+        kill(d->pid,9); // just to be sure
+        waitpid(d->pid,NULL,0);
+      }
+      omFreeSize((ADDRESS)d,(sizeof *d));
+    }
+    l->data=NULL;
+    SI_LINK_SET_CLOSE_P(l);
+  }
+  return FALSE;
+}
+
+//**************************************************************************/
+leftv ssiRead1(si_link l)
+{
+  ssiInfo *d = (ssiInfo *)l->data;
+  d->ungetc_buf='\0';
+  leftv res=(leftv)omAlloc0(sizeof(sleftv));
+  int t=0;
+  SSI_BLOCK_CHLD;
+  fscanf(d->f_read,"%d",&t);
+  SSI_UNBLOCK_CHLD;
+  //Print("got type %d\n",t);
+  switch(t)
+  {
+    case 1:res->rtyp=INT_CMD;
+           res->data=(char *)ssiReadInt(d->f_read);
+           break;
+    case 2:res->rtyp=STRING_CMD;
+           res->data=(char *)ssiReadString(d);
+           break;
+    case 3:res->rtyp=NUMBER_CMD;
+           res->data=(char *)ssiReadNumber(d);
+           break;
+    case 4:res->rtyp=BIGINT_CMD;
+           res->data=(char *)ssiReadBigInt(d);
+           break;
+    case 15:
+    case 5:{
+             d->r=ssiReadRing(d);
+             d->r->ref++;
+             res->rtyp=RING_CMD;
+             res->data=(char*)d->r;
+             // we are in the top-level, so set the basering to d->r:
+             ssiSetCurrRing(d->r);
+             if (t==15) return ssiRead1(l);
+           }
+           break;
+    case 6:res->rtyp=POLY_CMD;
+           if (d->r==NULL) goto no_ring;
+           res->data=(char*)ssiReadPoly(d);
+           break;
+    case 7:res->rtyp=IDEAL_CMD;
+           if (d->r==NULL) goto no_ring;
+           res->data=(char*)ssiReadIdeal(d);
+           break;
+    case 8:res->rtyp=MATRIX_CMD;
+           if (d->r==NULL) goto no_ring;
+           res->data=(char*)ssiReadMatrix(d);
+           break;
+    case 9:res->rtyp=VECTOR_CMD;
+           if (d->r==NULL) goto no_ring;
+           res->data=(char*)ssiReadPoly(d);
+           break;
+    case 10:res->rtyp=MODUL_CMD;
+           if (d->r==NULL) goto no_ring;
+           res->data=(char*)ssiReadIdeal(d);
+           break;
+    case 11:
+           {
+             res->rtyp=COMMAND;
+             res->data=ssiReadCommand(l);
+             int nok=res->Eval();
+             if (nok) WerrorS("error in eval");
+             break;
+           }
+    case 12: /*DEF_CMD*/
+           {
+             res->rtyp=0;
+             res->name=(char *)ssiReadString(d);
+             int nok=res->Eval();
+             if (nok) WerrorS("error in name lookup");
+             break;
+           }
+    case 13: res->rtyp=PROC_CMD;
+             res->data=ssiReadProc(d);
+             break;
+    case 14: res->rtyp=LIST_CMD;
+             res->data=ssiReadList(l);
+             break;
+    case 16: res->rtyp=NONE; res->data=NULL;
+             break;
+    case 17: res->rtyp=INTVEC_CMD;
+             res->data=ssiReadIntvec(d);
+             break;
+    case 20: ssiReadBlackbox(res,l);
+             break;
+    // ------------
+    case 98: // version
+             {
+                int n98_v,n98_m;
+                BITSET n98_o1,n98_o2;
+                SSI_BLOCK_CHLD;
+                fscanf(d->f_read,"%d %d %u %u\n",&n98_v,&n98_m,&n98_o1,&n98_o2);
+                SSI_UNBLOCK_CHLD;
+                if ((n98_v!=SSI_VERSION) ||(n98_m!=MAX_TOK))
+                {
+                  Print("incompatible versions of ssi: %d/%d vs %d/%d",
+                                  SSI_VERSION,MAX_TOK,n98_v,n98_m);
+                }
+                #ifndef NDEBUG
+                if (TEST_OPT_DEBUG)
+                  Print("// opening ssi-%d, MAX_TOK=%d\n",n98_v,n98_m);
+                #endif
+                test=n98_o1;
+                verbose=n98_o2;
+                return ssiRead1(l);
+             }
+    case 99: ssiClose(l); m2_end(0);
+    case 0: if (feof(d->f_read))
+            {
+              ssiClose(l);
+              res->rtyp=DEF_CMD;
+              break;
+            }
+    default: Werror("not implemented (t:%d)",t);
+             omFreeSize(res,sizeof(sleftv));
+             res=NULL;
+             break;
+  }
+  return res;
+no_ring: WerrorS("no ring");
+  omFreeSize(res,sizeof(sleftv));
+  return NULL;
+}
+//**************************************************************************/
+BOOLEAN ssiWrite(si_link l, leftv data)
+{
+  if(SI_LINK_W_OPEN_P(l)==0)
+     if (slOpen(l,SI_LINK_OPEN|SI_LINK_WRITE,NULL)) return TRUE;
+  ssiInfo *d = (ssiInfo *)l->data;
+  d->level++;
+  //FILE *fich=d->f;
+  while (data!=NULL)
+  {
+    int tt=data->Typ();
+    void *dd=data->Data();
+
+    switch(tt /*data->Typ()*/)
+    {
+          case NONE/* nothing*/:fputs("16 ",d->f_write);
+                          break;
+          case STRING_CMD: fputs("2 ",d->f_write);
+                           ssiWriteString(d,(char *)dd);
+                           break;
+          case INT_CMD: fputs("1 ",d->f_write);
+                        ssiWriteInt(d,(int)(long)dd);
+                        break;
+          case BIGINT_CMD:fputs("4 ",d->f_write);
+                        ssiWriteBigInt(d,(number)dd);
+                        break;
+          case NUMBER_CMD:
+                          if (d->r!=currRing)
+                          {
+                            fputs("15 ",d->f_write);
+                            ssiWriteRing(d,currRing);
+                            if (d->level<=1) fputc('\n',d->f_write);
+                          }
+                          fputs("3 ",d->f_write);
+                          ssiWriteNumber(d,(number)dd);
+                        break;
+          case RING_CMD:fputs("5 ",d->f_write);
+                        ssiWriteRing(d,(ring)dd);
+                        break;
+          case POLY_CMD:
+          case VECTOR_CMD:
+                        if (d->r!=currRing)
+                        {
+                          fputs("15 ",d->f_write);
+                          ssiWriteRing(d,currRing);
+                          if (d->level<=1) fputc('\n',d->f_write);
+                        }
+                        if(tt==POLY_CMD) fputs("6 ",d->f_write);
+                        else             fputs("9 ",d->f_write);
+                        ssiWritePoly(d,tt,(poly)dd);
+                        break;
+          case IDEAL_CMD:
+          case MODUL_CMD:
+          case MATRIX_CMD:
+                        if (d->r!=currRing)
+                        {
+                          fputs("15 ",d->f_write);
+                          ssiWriteRing(d,currRing);
+                          if (d->level<=1) fputc('\n',d->f_write);
+                        }
+                        if(tt==IDEAL_CMD)       fputs("7 ",d->f_write);
+                        else if(tt==MATRIX_CMD) fputs("8 ",d->f_write);
+                        else                    fputs("10 ",d->f_write);
+                        ssiWriteIdeal(d,tt,(ideal)dd);
+                        break;
+          case COMMAND:
+                   fputs("11 ",d->f_write);
+                   ssiWriteCommand(l,(command)dd);
+                   break;
+          case DEF_CMD: /* not evaluated stuff in quotes */
+                   fputs("12 ",d->f_write);
+                   ssiWriteString(d,data->Name());
+                   break;
+          case PROC_CMD:
+                   fputs("13 ",d->f_write);
+                   ssiWriteProc(d,(procinfov)dd);
+                   break;
+          case LIST_CMD:
+                   fputs("14 ",d->f_write);
+                   ssiWriteList(l,(lists)dd);
+                   break;
+          case INTVEC_CMD:
+                   fputs("17 ",d->f_write);
+                   ssiWriteIntvec(d,(intvec *)dd);
+                   break;
+          default:
+            if (tt>MAX_TOK)
+            {
+              blackbox *b=getBlackboxStuff(tt);
+              fputs("20 ",d->f_write);
+              b->blackbox_serialize(b,dd,l);
+            }
+            else
+            {
+              Werror("not implemented (t:%d, rtyp:%d)",tt, data->rtyp);
+              d->level=0;
+              return TRUE;
+            }
+            break;
+    }
+    if (d->level<=1) { fputc('\n',d->f_write); fflush(d->f_write); }
+    data=data->next;
+  }
+  d->level--;
+  return FALSE;
+}
+
+si_link_extension slInitSsiExtension(si_link_extension s)
+{
+  s->Open=ssiOpen;
+  s->Close=ssiClose;
+  s->Kill=ssiClose;
+  s->Read=ssiRead1;
+  s->Read2=(slRead2Proc)NULL;
+  s->Write=ssiWrite;
+
+  s->Status=slStatusSsi;
+  s->type="ssi";
+  return s;
+}
+
+const char* slStatusSsi(si_link l, const char* request)
+{
+  ssiInfo *d=(ssiInfo*)l->data;
+  if (d==NULL) return "not open";
+  if (((strcmp(l->mode,"fork")==0)||(strcmp(l->mode,"tcp")==0))
+  && (strcmp(request, "read") == 0))
+  {
+    fd_set  mask, fdmask;
+    struct timeval wt;
+    if (d->ungetc_buf) return "ready";
+    loop
+    {
+      /* Don't block. Return socket status immediately. */
+      wt.tv_sec  = 0;
+      wt.tv_usec = 0;
+
+      FD_ZERO(&mask);
+      FD_SET(d->fd_read, &mask);
+      //Print("test fd %d\n",d->fd_read);
+    /* check with select: chars waiting: no -> not ready */
+      switch (select(d->fd_read+1, &mask, NULL, NULL, &wt))
+      {
+        case 0: /* not ready */ return "not ready";
+        case -1: /*error*/      return "error";
+        case 1: /*ready ? */    break;
+      }
+    /* yes: read 1 char*/
+    /* if \n, check again with select else ungetc(c), ready*/
+      int c=fgetc(d->f_read);
+      //Print("try c=%d\n",c);
+      if (c== -1) return "eof"; /* eof or error */
+      else if (isdigit(c))
+      { ungetc(c,d->f_read); d->ungetc_buf='\1'; return "ready"; }
+      else if (c>' ')
+      {
+        Werror("unknown char in ssiLink(%d)",c);
+        return "error";
+      }
+      /* else: next char */
+    }
+  }
+  else if (strcmp(request, "read") == 0)
+  {
+    if (SI_LINK_R_OPEN_P(l) && (!feof(d->f_read))) return "ready";
+    else return "not ready";
+  }
+  else if (strcmp(request, "write") == 0)
+  {
+    if (SI_LINK_W_OPEN_P(l)) return "ready";
+    else return "not ready";
+  }
+  else return "unknown status request";
+}
+
+int slStatusSsiL(lists L, int timeout)
+{
+// input: L: a list with links of type
+//           ssi-connect, ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch.
+//           Note: Not every entry in L must be set.
+//        timeout: timeout for select in micro-seconds
+//           or -1 for infinity
+//           or 0 for polling
+// returns: ERROR (via Werror): L has wrong elements or link not open
+//           -2: select returns an error
+//           -1: the read state of all links is eof
+//           0:  timeout (or polling): none ready,
+//           i>0: (at least) L[i] is ready
+  si_link l;
+  ssiInfo *d;
+  int d_fd;
+  fd_set  mask, fdmask;
+  FD_ZERO(&fdmask);
+  FD_ZERO(&mask);
+  int max_fd=0; /* 1 + max fd in fd_set */
+
+  /* timeout */
+  #ifdef HAVE_PSELECT
+  struct timespec wt;
+  struct timespec *wt_ptr=&wt;
+  #else
+  struct timeval wt;
+  struct timeval *wt_ptr=&wt;
+  #endif
+  int startingtime = getRTimer()/TIMER_RESOLUTION;  // in seconds
+  if (timeout== -1)
+  {
+    wt_ptr=NULL;
+  }
+  else
+  {
+    wt.tv_sec  = timeout / 1000000;
+  #ifdef HAVE_PSELECT
+    wt.tv_nsec = 1000 * (timeout % 1000000);
+  #else
+    wt.tv_usec = timeout % 1000000;
+  #endif
+  }
+
+  /* signal mask for pselect() */
+  sigset_t sigmask;
+  if(sigprocmask(SIG_SETMASK, NULL, &sigmask) < 0)
+  {
+    WerrorS("error in sigprocmask()");
+    return -2;
+  }
+  if(sigaddset(&sigmask, SIGCHLD) < 0)
+  {
+    WerrorS("error in sigaddset()");
+    return -2;
+  }
+
+  /* auxiliary variables */
+  int i;
+  int j;
+  int k;
+  int s;
+  char fdmaskempty;
+
+  /* check the links and fill in fdmask */
+  /* check ssi links for ungetc_buf */
+  for(i=L->nr; i>=0; i--)
+  {
+    if (L->m[i].Typ()!=DEF_CMD)
+    {
+      if (L->m[i].Typ()!=LINK_CMD)
+      { WerrorS("all elements must be of type link"); return -2;}
+      l=(si_link)L->m[i].Data();
+      if(SI_LINK_OPEN_P(l)==0)
+      { WerrorS("all links must be open"); return -2;}
+      if (((strcmp(l->m->type,"ssi")!=0) && (strcmp(l->m->type,"MPtcp")!=0))
+      || ((strcmp(l->mode,"fork")!=0) && (strcmp(l->mode,"tcp")!=0)
+        && (strcmp(l->mode,"launch")!=0) && (strcmp(l->mode,"connect")!=0)))
+      {
+        WerrorS("all links must be of type ssi:fork, ssi:tcp, ssi:connect,");
+        WerrorS(" MPtcp:fork or MPtcp:launch");
+        return -2;
+      }
+      d=(ssiInfo*)l->data;
+      d_fd=d->fd_read;
+      if (d->ungetc_buf=='\0')
+      {
+        FD_SET(d_fd, &fdmask);
+        if (d_fd > max_fd) max_fd=d_fd;
+      }
+      else
+        return i+1;
+    }
+  }
+  max_fd++;
+
+do_select:
+  /* copy fdmask to mask */
+  FD_ZERO(&mask);
+  for(k = 0; k < max_fd; k++)
+  {
+    if(FD_ISSET(k, &fdmask))
+    {
+      FD_SET(k, &mask);
+    }
+  }
+
+  /* check with select: chars waiting: no -> not ready */
+  #ifdef HAVE_PSELECT
+  s = pselect(max_fd, &mask, NULL, NULL, wt_ptr, &sigmask);
+  #else
+  SSI_BLOCK_CHLD;
+  s = select(max_fd, &mask, NULL, NULL, wt_ptr);
+  SSI_UNBLOCK_CHLD;
+  #endif
+
+  if (s==-1)
+  {
+    WerrorS("error in select call");
+    return -2; /*error*/
+  }
+  if (s==0)
+  {
+    return 0; /*poll: not ready */
+  }
+  else /* s>0, at least one ready  (the number of fd which are ready is s)*/
+  {
+    j=0;
+    while (j<=max_fd) { if (FD_ISSET(j,&mask)) break; j++; }
+    for(i=L->nr; i>=0; i--)
+    {
+      if (L->m[i].rtyp==LINK_CMD)
+      {
+        l=(si_link)L->m[i].Data();
+        d=(ssiInfo*)l->data;
+        d_fd=d->fd_read;
+        if(j==d_fd) break;
+      }
+    }
+    // only ssi links:
+    loop
+    {
+      /* yes: read 1 char*/
+      /* if \n, check again with select else ungetc(c), ready*/
+      /* setting: d: current ssiInfo, j current fd, i current entry in L*/
+      int c=fgetc(d->f_read);
+      //Print("try c=%d\n",c);
+      if (c== -1) /* eof */
+      {
+        FD_CLR(j,&fdmask);
+        fdmaskempty = 1;
+        for(k = 0; k < max_fd; k++)
+        {
+          if(FD_ISSET(k, &fdmask))
+          {
+            fdmaskempty = 0;
+            break;
+          }
+        }
+        if(fdmaskempty)
+        {
+          return -1;
+        }
+        if(timeout != -1)
+        {
+          timeout = si_max(0,
+               timeout - 1000000*(getRTimer()/TIMER_RESOLUTION - startingtime));
+          wt.tv_sec  = timeout / 1000000;
+          #ifdef HAVE_PSELECT
+          wt.tv_nsec = 1000 * (timeout % 1000000);
+          #else
+          wt.tv_usec = (timeout % 1000000);
+          #endif
+        }
+        goto do_select;
+      }
+
+      else if (isdigit(c))
+      { ungetc(c,d->f_read); d->ungetc_buf='\1'; return i+1; }
+      else if (c>' ')
+      {
+        Werror("unknown char in ssiLink(%d)",c);
+        return -2;
+      }
+      /* else: next char */
+    }
+  }
+}
+
+int ssiBatch(const char *host, const char * port)
+/* return 0 on success, >0 else*/
+{
+  si_link l=(si_link) omAlloc0Bin(sip_link_bin);
+  char *buf=(char*)omAlloc(256);
+  sprintf(buf,"ssi:connect %s:%s",host,port);
+  slInit(l, buf);
+  if (slOpen(l,SI_LINK_OPEN,NULL)) return 1;
+  SI_LINK_SET_RW_OPEN_P(l);
+
+  idhdl id = enterid(omStrDup("link_ll"), 0, LINK_CMD, &IDROOT, FALSE);
+  IDLINK(id) = l;
+
+  loop
+  {
+    leftv h=ssiRead1(l); /*contains an exit.... */
+    if (feErrors != NULL && *feErrors != '\0')
+    {
+      // handle errors:
+      PrintS(feErrors); /* currently quite simple */
+      *feErrors = '\0';
+    }
+    ssiWrite(l,h);
+    h->CleanUp();
+    omFreeBin(h, sleftv_bin);
+  }
+  /* never reached*/
+  exit(0);
+}
+
+// ----------------------------------------------------------------
+// format
+// 1 int %d
+// 2 string <len> %s
+// 3 number
+// 4 bigint 4 %d or 3 <mpz_t>
+// 5 ring
+// 6 poly
+// 7 ideal
+// 8 matrix
+// 9 vector
+// 10 module
+// 11 command
+// 12 def <len> %s
+// 13 proc <len> %s
+// 14 list %d <elem1> ....
+// 15 setring .......
+// 16 nothing
+// 17 intvec <len> ...
+//
+// 20 blackbox <name> ...
+//
+// 98: verify version: <ssi-version> <MAX_TOK> <OPT1> <OPT2>
+// 99: quit Singular
Index: Singular/links/ssiLink.h
===================================================================
--- Singular/links/ssiLink.h	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
+++ Singular/links/ssiLink.h	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
@@ -0,0 +1,20 @@
+/****************************************
+ * Computer Algebra System SINGULAR     *
+ ****************************************/
+/***************************************************************
+ * File:    ssiLink.h
+ *  Purpose: declaration of sl_link routines for ssi
+ ***************************************************************/
+ #ifndef SSILINK_H
+ #define SSILINK_H
+BOOLEAN ssiOpen(si_link l, short flag, leftv u);
+BOOLEAN ssiWrite(si_link l, leftv v);
+leftv ssiRead1(si_link l);
+leftv ssiRead2(si_link l, leftv key);
+BOOLEAN ssiClose(si_link l);
+const char* slStatusSsi(si_link l, const char* request);
+si_link_extension slInitSsiExtension(si_link_extension s);
+int ssiBatch(const char *host, const char * port);
+/* return 0 on success, >0 else*/
+#endif
+
Index: ngular/ndbm.cc
===================================================================
--- Singular/ndbm.cc	(revision 4fb3a73a9ab769b9cdb2ec0db33cdbf9e88bfedd)
+++ 	(revision )
@@ -1,566 +1,0 @@
-/****************************************
-*  Computer Algebra System SINGULAR     *
-****************************************/
-
-//**************************************************************************/
-//
-//
-//**************************************************************************/
-// 'ndbm.cc' containes all low-level functions to manipulate dbm-files
-// for the original Copyright of this file and 'ndbm.h' see below .
-//
-// some minor change where needed to compile and run under MacOS/MPW
-//
-//**************************************************************************/
-
-#include "config.h"
-#include <kernel/mod2.h>
-#ifdef HAVE_DBM
-#ifndef HPUX_9
-#include <strings.h>
-#endif
-/*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
- * for details see ndbm.h
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)ndbm.c        5.3 (Berkeley) 3/9/86";
-#endif
-
-//**************************************************************************/
-
-#include <stdio.h>
-/* alternative:
-* #   define EPERM 1
-* #   define ENOMEM 23
-* #   define ENOSPC 28
-* #   define L_SET SEEK_SET
-*/
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/file.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#ifndef HAVE_BCOPY
-#   define bcopy(a,b,c) memmove(b,a,c)
-#endif /* not HAVE_BCOPY */
-#include <Singular/ndbm.h>
-
-#define BYTESIZ 8
-#undef setbit
-
-static  void dbm_access(register DBM *db, long hash);
-static  int getbit(register DBM *db);
-static  void setbit(register DBM *db);
-static  datum makdatum(char buf[PBLKSIZ], int n);
-static  int finddatum(char buf[PBLKSIZ], datum item);
-static  long hashinc(register DBM *db, long hash);
-static  long dcalchash(datum item);
-static  int delitem(char buf[PBLKSIZ], int n);
-static  int additem(char buf[PBLKSIZ], datum item, datum item1);
-// extern  int errno;
-extern "C" int singular_fstat(int fd, struct stat *buf);
-
-DBM * dbm_open(char *file, int flags, int mode)
-{
-  struct stat statb;
-  register DBM *db;
-
-  if ((db = (DBM *)malloc(sizeof *db)) == 0)
-  {
-    errno = ENOMEM;
-    return ((DBM *)0);
-  }
-#ifdef MSDOS
-  // default mode of open is ascii, we need binary mode.
-  flags |= O_BINARY;
-#endif
-  db->dbm_flags = (flags & 03) == O_RDONLY ? _DBM_RDONLY : 0;
-  if ((flags & 03) == O_WRONLY)
-    flags = (flags & ~03) | O_RDWR;
-  strcpy(db->dbm_pagbuf, file);
-  strcat(db->dbm_pagbuf, ".pag");
-  db->dbm_pagf = open(db->dbm_pagbuf, flags, mode);
-  if (db->dbm_pagf < 0)
-    goto bad;
-  strcpy(db->dbm_pagbuf, file);
-  strcat(db->dbm_pagbuf, ".dir");
-  db->dbm_dirf = open(db->dbm_pagbuf, flags, mode);
-  if (db->dbm_dirf < 0)
-    goto bad1;
-  singular_fstat(db->dbm_dirf, &statb);
-  db->dbm_maxbno = statb.st_size*BYTESIZ-1;
-  db->dbm_pagbno = db->dbm_dirbno = -1;
-  return (db);
-bad1:
-  (void) close(db->dbm_pagf);
-bad:
-  free((char *)db);
-  return ((DBM *)0);
-}
-
-void dbm_close(DBM *db)
-{
-  (void) close(db->dbm_dirf);
-  (void) close(db->dbm_pagf);
-  free((char *)db);
-}
-
-long dbm_forder(register DBM *db, datum key)
-{
-  long hash;
-
-  hash = dcalchash(key);
-  for (db->dbm_hmask=0;; db->dbm_hmask=(db->dbm_hmask<<1)+1)
-  {
-    db->dbm_blkno = hash & db->dbm_hmask;
-    db->dbm_bitno = db->dbm_blkno + db->dbm_hmask;
-    if (getbit(db) == 0)
-      break;
-  }
-  return (db->dbm_blkno);
-}
-
-datum dbm_fetch(register DBM *db, datum key)
-{
-  register int i;
-  datum item;
-
-  if (dbm_error(db))
-    goto err;
-  dbm_access(db, dcalchash(key));
-  if ((i = finddatum(db->dbm_pagbuf, key)) >= 0)
-  {
-    item = makdatum(db->dbm_pagbuf, i+1);
-    if (item.dptr != NULL)
-      return (item);
-  }
-err:
-  item.dptr = NULL;
-  item.dsize = 0;
-  return (item);
-}
-
-int dbm_delete(register DBM *db, datum key)
-{
-  register int i;
-  datum item;
-
-  if (dbm_error(db))
-    return (-1);
-  if (dbm_rdonly(db))
-  {
-    errno = EPERM;
-    return (-1);
-  }
-  dbm_access(db, dcalchash(key));
-  if ((i = finddatum(db->dbm_pagbuf, key)) < 0)
-    return (-1);
-  if (!delitem(db->dbm_pagbuf, i))
-    goto err;
-  db->dbm_pagbno = db->dbm_blkno;
-  (void) lseek(db->dbm_pagf, db->dbm_blkno*PBLKSIZ, L_SET);
-  if (write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ)
-  {
-  err:
-    db->dbm_flags |= _DBM_IOERR;
-    return (-1);
-  }
-  return (0);
-}
-
-int dbm_store(register DBM *db, datum key, datum dat, int replace)
-{
-  register int i;
-  int ret;
-  datum item, item1;
-  char ovfbuf[PBLKSIZ];
-
-  if (dbm_error(db))
-    return (-1);
-  if (dbm_rdonly(db))
-  {
-    errno = EPERM;
-    return (-1);
-  }
-   
-_loop:
-  dbm_access(db, dcalchash(key));
-  if ((i = finddatum(db->dbm_pagbuf, key)) >= 0)
-  {
-    if (!replace)
-      return (1);
-    if (!delitem(db->dbm_pagbuf, i))
-    {
-      db->dbm_flags |= _DBM_IOERR;
-      return (-1);
-    }
-  }
-  if (!additem(db->dbm_pagbuf, key, dat))
-    goto split;
-  db->dbm_pagbno = db->dbm_blkno;
-  (void) lseek(db->dbm_pagf, db->dbm_blkno*PBLKSIZ, L_SET);
-  if ( (ret=write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ)) != PBLKSIZ)
-  {
-    db->dbm_flags |= _DBM_IOERR;
-    return (-1);
-  }
-  return (0);
-
-split:
-  if (key.dsize+dat.dsize+3*sizeof(short) >= PBLKSIZ)
-  {
-    db->dbm_flags |= _DBM_IOERR;
-    errno = ENOSPC;
-    return (-1);
-  }
-  memset(ovfbuf, 0, PBLKSIZ);
-  for (i=0;;) {
-    item = makdatum(db->dbm_pagbuf, i);
-    if (item.dptr == NULL)
-      break;
-    if (dcalchash(item) & (db->dbm_hmask+1))
-    {
-      item1 = makdatum(db->dbm_pagbuf, i+1);
-      if (item1.dptr == NULL) {
-        fprintf(stderr, "ndbm: split not paired\n");
-        db->dbm_flags |= _DBM_IOERR;
-        break;
-      }
-      if (!additem(ovfbuf, item, item1) ||
-          !delitem(db->dbm_pagbuf, i))
-      {
-        db->dbm_flags |= _DBM_IOERR;
-        return (-1);
-      }
-      continue;
-    }
-    i += 2;
-  }
-  db->dbm_pagbno = db->dbm_blkno;
-  (void) lseek(db->dbm_pagf, db->dbm_blkno*PBLKSIZ, L_SET);
-  if (write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ)
-  {
-    db->dbm_flags |= _DBM_IOERR;
-    return (-1);
-  }
-  (void) lseek(db->dbm_pagf, (db->dbm_blkno+db->dbm_hmask+1)*PBLKSIZ, L_SET);
-  if (write(db->dbm_pagf, ovfbuf, PBLKSIZ) != PBLKSIZ)
-  {
-    db->dbm_flags |= _DBM_IOERR;
-    return (-1);
-  }
-  setbit(db);
-  goto _loop;
-}
-
-datum dbm_firstkey(DBM *db)
-{
-
-  db->dbm_blkptr = 0L;
-  db->dbm_keyptr = 0;
-  return (dbm_nextkey(db));
-}
-
-datum dbm_nextkey(register DBM *db)
-{
-  struct stat statb;
-  datum item;
-
-  if (dbm_error(db) 
-       || singular_fstat(db->dbm_pagf, &statb) < 0
-  )
-                goto err;
-  statb.st_size /= PBLKSIZ;
-  for (;;)
-  {
-    if (db->dbm_blkptr != db->dbm_pagbno)
-    {
-      db->dbm_pagbno = db->dbm_blkptr;
-      (void) lseek(db->dbm_pagf, db->dbm_blkptr*PBLKSIZ, L_SET);
-      if (read(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ)
-        memset(db->dbm_pagbuf, 0, PBLKSIZ);
-#ifdef DEBUG
-      else if (chkblk(db->dbm_pagbuf) < 0)
-        db->dbm_flags |= _DBM_IOERR;
-#endif
-    }
-    if (((short *)db->dbm_pagbuf)[0] != 0)
-    {
-      item = makdatum(db->dbm_pagbuf, db->dbm_keyptr);
-      if (item.dptr != NULL)
-      {
-        db->dbm_keyptr += 2;
-        return (item);
-      }
-      db->dbm_keyptr = 0;
-    }
-    if (++db->dbm_blkptr >= statb.st_size)
-      break;
-  }
-err:
-  item.dptr = NULL;
-  item.dsize = 0;
-  return (item);
-}
-
-static void dbm_access(register DBM *db, long hash)
-{
-  for (db->dbm_hmask=0;; db->dbm_hmask=(db->dbm_hmask<<1)+1)
-  {
-    db->dbm_blkno = hash & db->dbm_hmask;
-    db->dbm_bitno = db->dbm_blkno + db->dbm_hmask;
-    if (getbit(db) == 0)
-      break;
-  }
-  if (db->dbm_blkno != db->dbm_pagbno)
-  {
-    db->dbm_pagbno = db->dbm_blkno;
-    (void) lseek(db->dbm_pagf, db->dbm_blkno*PBLKSIZ, L_SET);
-    if (read(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ)
-      memset(db->dbm_pagbuf, 0, PBLKSIZ);
-#ifdef DEBUG
-    else if (chkblk(db->dbm_pagbuf) < 0)
-      db->dbm_flags |= _DBM_IOERR;
-#endif
-  }
-}
-
-static int getbit(register DBM *db)
-{
-  long bn;
-  register int b, i, n;
-
-
-  if (db->dbm_bitno > db->dbm_maxbno)
-    return (0);
-  n = db->dbm_bitno % BYTESIZ;
-  bn = db->dbm_bitno / BYTESIZ;
-  i = bn % DBLKSIZ;
-  b = bn / DBLKSIZ;
-  if (b != db->dbm_dirbno)
-  {
-    db->dbm_dirbno = b;
-    (void) lseek(db->dbm_dirf, (long)b*DBLKSIZ, L_SET);
-    if (read(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ)
-      memset(db->dbm_dirbuf, 0, DBLKSIZ);
-  }
-  return (db->dbm_dirbuf[i] & (1<<n));
-}
-
-static void setbit(register DBM *db)
-{
-  long bn;
-  register int i, n, b;
-
-  if (db->dbm_bitno > db->dbm_maxbno)
-    db->dbm_maxbno = db->dbm_bitno;
-  n = db->dbm_bitno % BYTESIZ;
-  bn = db->dbm_bitno / BYTESIZ;
-  i = bn % DBLKSIZ;
-  b = bn / DBLKSIZ;
-  if (b != db->dbm_dirbno)
-  {
-    db->dbm_dirbno = b;
-    (void) lseek(db->dbm_dirf, (long)b*DBLKSIZ, L_SET);
-    if (read(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ)
-      memset(db->dbm_dirbuf, 0, DBLKSIZ);
-  }
-  db->dbm_dirbuf[i] |= 1<<n;
-  db->dbm_dirbno = b;
-  (void) lseek(db->dbm_dirf, (long)b*DBLKSIZ, L_SET);
-  if (write(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ)
-    db->dbm_flags |= _DBM_IOERR;
-}
-
-static datum makdatum(char buf[PBLKSIZ], int n)
-{
-  register short *sp;
-  register int t;
-  datum item;
-
-  sp = (short *)buf;
-  if ((unsigned)n >= (unsigned)sp[0])
-  {
-    item.dptr = NULL;
-    item.dsize = 0;
-    return (item);
-  }
-  t = PBLKSIZ;
-  if (n > 0)
-    t = sp[n];
-  item.dptr = buf+sp[n+1];
-  item.dsize = t - sp[n+1];
-  return (item);
-}
-
-static int finddatum(char buf[PBLKSIZ], datum item)
-{
-  register short *sp;
-  register int i, n, j;
-
-  sp = (short *)buf;
-  n = PBLKSIZ;
-  for (i=0, j=sp[0]; i<j; i+=2, n = sp[i])
-  {
-    n -= sp[i+1];
-    if (n != item.dsize)
-      continue;
-    if (n == 0 || memcmp(&buf[sp[i+1]], item.dptr, n) == 0)
-      return (i);
-  }
-  return (-1);
-}
-
-static  int hitab[16]
-/* ken's
-{
-        055,043,036,054,063,014,004,005,
-        010,064,077,000,035,027,025,071,
-};
-*/
- = {    61, 57, 53, 49, 45, 41, 37, 33,
-        29, 25, 21, 17, 13,  9,  5,  1,
-};
-static  long hltab[64]
- = {
-        06100151277L,06106161736L,06452611562L,05001724107L,
-        02614772546L,04120731531L,04665262210L,07347467531L,
-        06735253126L,06042345173L,03072226605L,01464164730L,
-        03247435524L,07652510057L,01546775256L,05714532133L,
-        06173260402L,07517101630L,02431460343L,01743245566L,
-        00261675137L,02433103631L,03421772437L,04447707466L,
-        04435620103L,03757017115L,03641531772L,06767633246L,
-        02673230344L,00260612216L,04133454451L,00615531516L,
-        06137717526L,02574116560L,02304023373L,07061702261L,
-        05153031405L,05322056705L,07401116734L,06552375715L,
-        06165233473L,05311063631L,01212221723L,01052267235L,
-        06000615237L,01075222665L,06330216006L,04402355630L,
-        01451177262L,02000133436L,06025467062L,07121076461L,
-        03123433522L,01010635225L,01716177066L,05161746527L,
-        01736635071L,06243505026L,03637211610L,01756474365L,
-        04723077174L,03642763134L,05750130273L,03655541561L,
-};
-
-static long hashinc(register DBM *db, long hash)
-{
-  long bit;
-
-  hash &= db->dbm_hmask;
-  bit = db->dbm_hmask+1;
-  for (;;)
-  {
-    bit >>= 1;
-    if (bit == 0)
-      return (0L);
-    if ((hash & bit) == 0)
-      return (hash | bit);
-    hash &= ~bit;
-  }
-}
-
-static long dcalchash(datum item)
-{
-  register int s, c, j;
-  register char *cp;
-  register long hashl;
-  register int hashi;
-
-  hashl = 0;
-  hashi = 0;
-  for (cp = item.dptr, s=item.dsize; --s >= 0; )
-  {
-    c = *cp++;
-    for (j=0; j<BYTESIZ; j+=4)
-    {
-      hashi += hitab[c&017];
-      hashl += hltab[hashi&63];
-      c >>= 4;
-    }
-  }
-  return (hashl);
-}
-
-/*
- * Delete pairs of items (n & n+1).
- */
-static int delitem(char buf[PBLKSIZ], int n)
-{
-  register short *sp, *sp1;
-  register int i1, i2;
-
-  sp = (short *)buf;
-  i2 = sp[0];
-  if ((unsigned)n >= (unsigned)i2 || (n & 1))
-    return (0);
-  if (n == i2-2)
-  {
-    sp[0] -= 2;
-    return (1);
-  }
-  i1 = PBLKSIZ;
-  if (n > 0)
-    i1 = sp[n];
-  i1 -= sp[n+2];
-  if (i1 > 0)
-  {
-    i2 = sp[i2];
-    bcopy(&buf[i2], &buf[i2 + i1], sp[n+2] - i2);
-  }
-  sp[0] -= 2;
-  for (sp1 = sp + sp[0], sp += n+1; sp <= sp1; sp++)
-    sp[0] = sp[2] + i1;
-  return (1);
-}
-
-/*
- * Add pairs of items (item & item1).
- */
-static int additem(char buf[PBLKSIZ], datum item, datum item1)
-{
-  register short *sp;
-  register int i1, i2, tmp;
-
-  sp = (short *)buf;
-  i1 = PBLKSIZ;
-  i2 = sp[0];
-  if (i2 > 0)
-    i1 = sp[i2];
-  i1 -= item.dsize + item1.dsize;
-  tmp = (i2+3) * sizeof(short);
-  if (i1 <= tmp) return (0);
-  sp[0] += 2;
-  sp[++i2] = i1 + item1.dsize;
-  bcopy(item.dptr, &buf[i1 + item1.dsize], item.dsize);
-  sp[++i2] = i1;
-  bcopy(item1.dptr, &buf[i1], item1.dsize);
-  return (1);
-}
-
-#ifdef DEBUG
-static chkblk(char buf[PBLKSIZ])
-{
-  register short *sp;
-  register t, i;
-
-  sp = (short *)buf;
-  t = PBLKSIZ;
-  for (i=0; i<sp[0]; i++)
-  {
-    if (sp[i+1] > t)
-      return (-1);
-    t = sp[i+1];
-  }
-  if (t < (sp[0]+1)*sizeof(short))
-    return (-1);
-  return (0);
-}
-#endif
-
-#endif /* HAVE_DBM */
Index: ngular/ndbm.h
===================================================================
--- Singular/ndbm.h	(revision 4fb3a73a9ab769b9cdb2ec0db33cdbf9e88bfedd)
+++ 	(revision )
@@ -1,103 +1,0 @@
-#ifndef NDBM_H
-#define NDBM_H
-/****************************************
-*  Computer Algebra System SINGULAR     *
-****************************************/
-/*
-* ABSTRACT: DBM
-*/
-
-/*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
- *
- *
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)ndbm.h	5.1 (Berkeley) 5/30/85
- *
- * Par. 3 removed due to a license change (1999)
- * see ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
- */
-
-/*
- * Hashed key data base library.
- */
-#define PBLKSIZ 1024
-
-#define DBLKSIZ 4096
-
-typedef struct {
-	int	dbm_dirf;		/* open directory file */
-	int	dbm_pagf;		/* open page file */
-	int	dbm_flags;		/* flags, see below */
-	long	dbm_maxbno;		/* last ``bit'' in dir file */
-	long	dbm_bitno;		/* current bit number */
-	long	dbm_hmask;		/* hash mask */
-	long	dbm_blkptr;		/* current block for dbm_nextkey */
-	int	dbm_keyptr;		/* current key for dbm_nextkey */
-	long	dbm_blkno;		/* current page to read/write */
-	long	dbm_pagbno;		/* current page in pagbuf */
-	char	dbm_pagbuf[PBLKSIZ];	/* page file block buffer */
-	long	dbm_dirbno;		/* current block in dirbuf */
-	char	dbm_dirbuf[DBLKSIZ];	/* directory file block buffer */
-} DBM;
-
-#define _DBM_RDONLY	0x01	/* data base open read-only */
-#define _DBM_IOERR	0x02	/* data base I/O error */
-
-#define dbm_rdonly(db)	((db)->dbm_flags & _DBM_RDONLY)
-
-#define dbm_error(db)	((db)->dbm_flags & _DBM_IOERR)
-	/* use this one at your own risk! */
-#define dbm_clearerr(db)	((db)->dbm_flags &= ~_DBM_IOERR)
-
-/* for flock(2) and fstat(2) */
-#define dbm_dirfno(db)	((db)->dbm_dirf)
-#define dbm_pagfno(db)	((db)->dbm_pagf)
-
-typedef struct {
-	char	*dptr;
-	int	dsize;
-} datum;
-
-/*
- * flags to dbm_store()
- */
-#define DBM_INSERT	0
-#define DBM_REPLACE	1
-
-DBM	*dbm_open(char *file, int flags, int mode);
-void	dbm_close(DBM *db);
-datum	dbm_fetch(register DBM *db, datum key);
-datum	dbm_firstkey(DBM *db);
-datum	dbm_nextkey(register DBM *db);
-long	dbm_forder(register DBM *db, datum key);
-int	dbm_delete(register DBM *db, datum key);
-int	dbm_store(register DBM *db, datum key, datum dat, int replace);
-
-#endif /* NDBM_H */
Index: ngular/pipeLink.cc
===================================================================
--- Singular/pipeLink.cc	(revision 4fb3a73a9ab769b9cdb2ec0db33cdbf9e88bfedd)
+++ 	(revision )
@@ -1,207 +1,0 @@
-/****************************************
- * Computer Algebra System SINGULAR     *
- ****************************************/
-/***************************************************************
- * File:    pipeLink.h
- *  Purpose: declaration of sl_link routines for pipe
- ***************************************************************/
-#include <stdio.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <signal.h>
-#include <sys/types.h>          /* for portability */
-#include <sys/select.h>
-#include <sys/socket.h>
-
-
-#include "config.h"
-#include <kernel/mod2.h>
-
-#include "tok.h"
-#include "ipid.h"
-#include <omalloc/omalloc.h>
-#include "subexpr.h"
-#include "silink.h"
-#include "lists.h"
-#include "pipeLink.h"
-
-typedef struct
-{
-  FILE *f_read;
-  FILE *f_write;
-  pid_t pid; /* only valid for fork/tcp mode*/
-  int fd_read,fd_write; /* only valid for fork/tcp mode*/
-  char level;
-} pipeInfo;
-
-//**************************************************************************/
-BOOLEAN pipeOpen(si_link l, short flag, leftv u)
-{
-  pipeInfo *d=(pipeInfo*)omAlloc0(sizeof(pipeInfo));
-  if (flag & SI_LINK_OPEN)
-  {
-      flag = SI_LINK_READ| SI_LINK_WRITE;
-  }
-  int pc[2];
-  int cp[2];
-  pipe(pc);
-  pipe(cp);
-  pid_t pid=fork();
-  if (pid==0) /*child*/
-  {
-    /* close unnecessary pipe descriptors for a clean environment */
-    close(pc[1]); close(cp[0]);
-    /* dup pipe read/write to stdin/stdout */
-    dup2( pc[0], STDIN_FILENO );
-    dup2( cp[1], STDOUT_FILENO  );
-    int r=system(l->name);
-    close(pc[0]);
-    close(cp[1]);
-    exit(r);
-        /* never reached*/
-  }
-  else if (pid>0)
-  {
-    d->pid=pid;
-    close(pc[0]); close(cp[1]);
-    d->f_read=fdopen(cp[0],"r");
-    d->fd_read=cp[0];
-    d->f_write=fdopen(pc[1],"w");
-    d->fd_write=pc[1];
-    SI_LINK_SET_RW_OPEN_P(l);
-  }
-  else
-  {
-    Werror("fork failed (%d)",errno);
-    omFreeSize(d,sizeof(*d));
-    return TRUE;
-  }
-  l->data=d;
-  return FALSE;
-}
-
-//**************************************************************************/
-LINKAGE BOOLEAN pipeClose(si_link l)
-{
-  pipeInfo *d = (pipeInfo *)l->data;
-  if (d!=NULL)
-  {
-    if (d->f_read!=NULL) fclose(d->f_read);
-    if (d->f_write!=NULL) fclose(d->f_write);
-    if (d->pid!=0) { kill(d->pid,15); kill(d->pid,9); }
-  }
-  SI_LINK_SET_CLOSE_P(l);
-  return FALSE;
-}
-
-//**************************************************************************/
-LINKAGE BOOLEAN pipeKill(si_link l)
-{
-  if(SI_LINK_OPEN_P(l)) pipeClose(l);
-  pipeInfo *d = (pipeInfo *)l->data;
-  if (d!=NULL)
-  {
-    omFreeSize((ADDRESS)d,(sizeof *d));
-  }
-  l->data=NULL;
-  return FALSE;
-}
-
-//**************************************************************************/
-LINKAGE leftv pipeRead1(si_link l)
-{
-  pipeInfo *d = (pipeInfo *)l->data;
-  leftv res=(leftv)omAlloc0(sizeof(sleftv));
-  char *s=(char *)omAlloc0(1024);
-  char *ss=fgets(s,1024,d->f_read);
-  if (ss==NULL) { omFreeSize(s,1024); pipeClose(l);return NULL; }
-  int i=strlen(s)-1;
-  if ((i>=0) && (s[i]=='\n')) s[i]='\0';
-  res->rtyp=STRING_CMD;
-  res->data=s;
-  return res;
-}
-//**************************************************************************/
-extern si_link pipeLastLink;
-LINKAGE BOOLEAN pipeWrite(si_link l, leftv data)
-{
-  if(!SI_LINK_W_OPEN_P(l)) slOpen(l,SI_LINK_OPEN|SI_LINK_WRITE,NULL);
-  pipeInfo *d = (pipeInfo *)l->data;
-  FILE *outfile=d->f_write;;
-  BOOLEAN err=FALSE;
-  char *s;
-  pipeLastLink=l;
-  while (data!=NULL)
-  {
-    s = data->String();
-    // free data ??
-    if (s!=NULL)
-    {
-      fprintf(outfile,"%s\n",s);
-      omFree((ADDRESS)s);
-    }
-    else
-    {
-      Werror("cannot convert to string");
-      err=TRUE;
-    }
-    if (pipeLastLink==NULL) return TRUE;
-    data = data->next;
-  }
-  fflush(outfile);
-  pipeLastLink=NULL;
-  return err;
-}
-
-const char* slStatusPipe(si_link l, const char* request)
-{
-  pipeInfo *d=(pipeInfo*)l->data;
-  if (d==NULL) return "not open";
-  if(strcmp(request, "read") == 0)
-  {
-    int s;
-    if ((!SI_LINK_R_OPEN_P(l)) || (feof(d->f_read))) s=0;
-    else
-    {
-      fd_set  mask, fdmask;
-      struct timeval wt;
-      /* Don't block. Return socket status immediately. */
-      wt.tv_sec  = 0;
-      wt.tv_usec = 0;
-
-      FD_ZERO(&mask);
-      FD_SET(d->fd_read, &mask);
-      //Print("test fd %d\n",d->fd_read);
-      /* check with select: chars waiting: no -> not ready */
-      s=select(d->fd_read+1, &mask, NULL, NULL, &wt);
-    }
-    switch (s)
-    {
-      case 0: /* not ready */ return "not ready";
-      case -1: /*error*/      return "error";
-      default: /*1: ready ? */return "ready";
-    }
-  }
-  else if (strcmp(request, "write") == 0)
-  {
-    if (SI_LINK_W_OPEN_P(l)) return "ready";
-    return "not ready";
-  }
-  return "unknown status request";
-}
-
-si_link_extension slInitPipeExtension(si_link_extension s)
-{
-  s->Open=pipeOpen;
-  s->Close=pipeClose;
-  s->Kill=pipeKill;
-  s->Read=pipeRead1;
-  s->Read2=(slRead2Proc)NULL;
-  s->Write=pipeWrite;
-
-  s->Status=slStatusPipe;
-  s->type="pipe";
-  return s;
-}
Index: ngular/pipeLink.h
===================================================================
--- Singular/pipeLink.h	(revision 4fb3a73a9ab769b9cdb2ec0db33cdbf9e88bfedd)
+++ 	(revision )
@@ -1,12 +1,0 @@
-/****************************************
- * Computer Algebra System SINGULAR     *
- ****************************************/
-/***************************************************************
- * File:    pipeLink.h
- *  Purpose: declaration of sl_link routines for pipe
- ***************************************************************/
-#ifndef PIPELINK_H
-#define PIPELINK_H
-si_link_extension slInitPipeExtension(si_link_extension s);
-#endif
-
Index: ngular/silink.cc
===================================================================
--- Singular/silink.cc	(revision 4fb3a73a9ab769b9cdb2ec0db33cdbf9e88bfedd)
+++ 	(revision )
@@ -1,881 +1,0 @@
-/****************************************
-*  Computer Algebra System SINGULAR     *
-****************************************/
-
-/*
-* ABSTRACT: general interface to links
-*/
-
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include "config.h"
-#include <kernel/mod2.h>
-#include <Singular/tok.h>
-#include <misc/options.h>
-#include <omalloc/omalloc.h>
-#include <kernel/febase.h>
-#include <Singular/subexpr.h>
-#include <Singular/ipid.h>
-#include <Singular/silink.h>
-#include <Singular/ipshell.h>
-#include <polys/matpol.h>
-#include <polys/monomials/ring.h>
-#include <Singular/lists.h>
-#include <kernel/ideals.h>
-#include <coeffs/numbers.h>
-#include <misc/intvec.h>
-#include <Singular/ssiLink.h>
-#include <Singular/pipeLink.h>
-
-// #ifdef HAVE_DBM
-// #ifdef ix86_Win
-// #define USE_GDBM
-// #endif
-// #endif
-
-omBin s_si_link_extension_bin = omGetSpecBin(sizeof(s_si_link_extension));
-omBin sip_link_bin = omGetSpecBin(sizeof(sip_link));
-omBin ip_link_bin = omGetSpecBin(sizeof(ip_link));
-
-/* declarations */
-static BOOLEAN DumpAscii(FILE *fd, idhdl h);
-static BOOLEAN DumpAsciiIdhdl(FILE *fd, idhdl h);
-static const char* GetIdString(idhdl h);
-static int DumpRhs(FILE *fd, idhdl h);
-static BOOLEAN DumpQring(FILE *fd, idhdl h, const char *type_str);
-static BOOLEAN DumpAsciiMaps(FILE *fd, idhdl h, idhdl rhdl);
-static si_link_extension slTypeInit(si_link_extension s, const char* type);
-
-/* ====================================================================== */
-si_link_extension si_link_root=NULL;
-
-BOOLEAN slInit(si_link l, char *istr)
-{
-  char *type = NULL, *mode = NULL, *name = NULL;
-  int i = 0, j;
-
-  // set mode and type
-  if (istr != NULL)
-  {
-    // find the first colon char in istr
-    i = 0;
-    while (istr[i] != ':' && istr[i] != '\0') i++;
-    if (istr[i] == ':')
-    {
-      // if found, set type
-      if (i > 0)
-      {
-        istr[i] = '\0';
-        type = omStrDup(istr);
-        istr[i] = ':';
-      }
-      // and check for mode
-      j = ++i;
-      while (istr[j] != ' ' && istr[j] != '\0') j++;
-      if (j > i)
-      {
-        mode = omStrDup(&(istr[i]));
-        mode[j - i] = '\0';
-      }
-      // and for the name
-      while (istr[j] == ' '&& istr[j] != '\0') j++;
-      if (istr[j] != '\0') name = omStrDup(&(istr[j]));
-    }
-    else // no colon find -- string is entire name
-    {
-      j=0;
-      while (istr[j] == ' '&& istr[j] != '\0') j++;
-      if (istr[j] != '\0') name = omStrDup(&(istr[j]));
-    }
-  }
-
-  // set the link extension
-  if (type != NULL)
-  {
-    si_link_extension s = si_link_root;
-    si_link_extension prev = s;
-
-    while (strcmp(s->type, type) != 0)
-    {
-      if (s->next == NULL)
-      {
-        prev = s;
-        s = NULL;
-        break;
-      }
-      else
-      {
-        s = s->next;
-      }
-    }
-
-    if (s != NULL)
-      l->m = s;
-    else
-    {
-      l->m = slTypeInit(prev, type);
-    }
-    omFree(type);
-  }
-  else
-    l->m = si_link_root;
-
-  if (l->m == NULL) return TRUE;
-
-  l->name = (name != NULL ? name : omStrDup(""));
-  l->mode = (mode != NULL ? mode : omStrDup(""));
-  l->ref = 1;
-  return FALSE;
-}
-
-void slCleanUp(si_link l)
-{
-  (l->ref)--;
-  if (l->ref == 0)
-  {
-    if (SI_LINK_OPEN_P(l))
-    {
-      if (l->m->Kill != NULL) l->m->Kill(l);
-      else if (l->m->Close != NULL) l->m->Close(l);
-    }
-    omFree((ADDRESS)l->name);
-    omFree((ADDRESS)l->mode);
-    memset((void *) l, 0, sizeof(ip_link));
-  }
-}
-
-void slKill(si_link l)
-{
-  slCleanUp(l);
-  if (l->ref == 0)
-    omFreeBin((ADDRESS)l,  ip_link_bin);
-}
-
-const char* slStatus(si_link l, const char *request)
-{
-  if (l == NULL) return "empty link";
-  else if (l->m == NULL) return "unknown link type";
-  else if (strcmp(request, "type") == 0) return l->m->type;
-  else if (strcmp(request, "mode") == 0) return l->mode;
-  else if (strcmp(request, "name") == 0) return l->name;
-  else if (strcmp(request, "exists") ==0)
-  {
-    struct stat buf;
-    if (lstat(l->name,&buf)==0) return "yes";
-    else return "no";
-  }
-  else if (strcmp(request, "open") == 0)
-  {
-    if (SI_LINK_OPEN_P(l)) return "yes";
-    else return "no";
-  }
-  else if (strcmp(request, "openread") == 0)
-  {
-    if (SI_LINK_R_OPEN_P(l)) return "yes";
-    else return "no";
-  }
-  else if (strcmp(request, "openwrite") == 0)
-  {
-    if (SI_LINK_W_OPEN_P(l)) return "yes";
-    else return "no";
-  }
-  else if (l->m->Status == NULL) return "unknown status request";
-  else return l->m->Status(l, request);
-}
-
-//--------------------------------------------------------------------------
-BOOLEAN slOpen(si_link l, short flag, leftv h)
-{
-  BOOLEAN res = TRUE;
-  if (l!=NULL)
-  {
-
-    if (l->m == NULL) slInit(l, ((char*)""));
-
-    const char *c="_";;
-    if (h!=NULL) c=h->Name();
-
-    if (SI_LINK_OPEN_P(l))
-    {
-      Warn("open: link of type: %s, mode: %s, name: %s is already open",
-         l->m->type, l->mode, l->name);
-      return FALSE;
-    }
-    else if (l->m->Open != NULL)
-    {
-      res = l->m->Open(l, flag, h);
-      if (res)
-        Werror("open: Error for link %s of type: %s, mode: %s, name: %s",
-             c, l->m->type, l->mode, l->name);
-    }
-  }
-  return res;
-}
-
-BOOLEAN slClose(si_link l)
-{
-
-  if(! SI_LINK_OPEN_P(l))
-    return FALSE;
-
-  BOOLEAN res = TRUE;
-  if (l->m->Close != NULL)
-  {
-    res = l->m->Close(l);
-    if (res)
-      Werror("close: Error for link of type: %s, mode: %s, name: %s",
-           l->m->type, l->mode, l->name);
-  }
-  return res;
-}
-
-leftv slRead(si_link l, leftv a)
-{
-  char *mode;
-  leftv v = NULL;
-  if( ! SI_LINK_R_OPEN_P(l)) // open r ?
-  {
-#ifdef HAVE_DBM
-#ifdef USE_GDBM
-    if (! SI_LINK_CLOSE_P(l))
-      {
-        if (slClose(l)) return NULL;
-      }
-#endif
-#endif
-    if (slOpen(l, SI_LINK_READ,NULL)) return NULL;
-  }
-
-  if (SI_LINK_R_OPEN_P(l))
-  { // open r
-    if (a==NULL)
-    {
-      if (l->m->Read != NULL) v = l->m->Read(l);
-    }
-    else
-    {
-      if (l->m->Read2 != NULL) v = l->m->Read2(l,a);
-    }
-  }
-  else
-  {
-    Werror("read: Error to open link of type %s, mode: %s, name: %s for reading",
-           l->m->type, l->mode, l->name);
-    return NULL;
-  }
-
-  // here comes the eval:
-  if (v != NULL)
-  {
-    if (v->Eval() && !errorreported)
-      WerrorS("eval: failed");
-  }
-  else
-    Werror("read: Error for link of type %s, mode: %s, name: %s",
-           l->m->type, l->mode, l->name);
-  return v;
-}
-
-BOOLEAN slWrite(si_link l, leftv v)
-{
-  BOOLEAN res;
-
-  if(! SI_LINK_W_OPEN_P(l)) // open w ?
-  {
-#ifdef HAVE_DBM
-#ifdef USE_GDBM
-    if (! SI_LINK_CLOSE_P(l))
-      {
-        if (slClose(l)) return TRUE;
-      }
-#endif
-#endif
-    if (slOpen(l, SI_LINK_WRITE,NULL)) return TRUE;
-  }
-
-  if (SI_LINK_W_OPEN_P(l))
-  { // now open w
-    if (l->m->Write != NULL)
-      res = l->m->Write(l,v);
-    else
-      res = TRUE;
-
-    if (res)
-      Werror("write: Error for link of type %s, mode: %s, name: %s",
-             l->m->type, l->mode, l->name);
-    return res;
-  }
-  else
-  {
-    Werror("write: Error to open link of type %s, mode: %s, name: %s for writing",
-           l->m->type, l->mode, l->name);
-    return TRUE;
-  }
-}
-
-BOOLEAN slDump(si_link l)
-{
-  BOOLEAN res;
-
-  if(! SI_LINK_W_OPEN_P(l)) // open w ?
-  {
-    if (slOpen(l, SI_LINK_WRITE,NULL)) return TRUE;
-  }
-
-  if(SI_LINK_W_OPEN_P(l))
-  { // now open w
-    if (l->m->Dump != NULL)
-      res = l->m->Dump(l);
-    else
-      res = TRUE;
-
-    if (res)
-      Werror("dump: Error for link of type %s, mode: %s, name: %s",
-             l->m->type, l->mode, l->name);
-
-    if (!SI_LINK_R_OPEN_P(l)) slClose(l); // do not close r/w links
-    return res;
-  }
-  else
-  {
-    Werror("dump: Error to open link of type %s, mode: %s, name: %s for writing",
-           l->m->type, l->mode, l->name);
-    return TRUE;
-  }
-}
-
-BOOLEAN slGetDump(si_link l)
-{
-  BOOLEAN res;
-
-  if(! SI_LINK_R_OPEN_P(l)) // open r ?
-  {
-    if (slOpen(l, SI_LINK_READ,NULL)) return TRUE;
-  }
-
-  if(SI_LINK_R_OPEN_P(l))
-  { // now open r
-    if (l->m->GetDump != NULL)
-      res = l->m->GetDump(l);
-    else
-      res = TRUE;
-
-    if (res)
-      Werror("getdump: Error for link of type %s, mode: %s, name: %s",
-             l->m->type, l->mode, l->name);
-    //res|=slClose(l);
-    return res;
-  }
-  else
-  {
-    Werror("dump: Error open link of type %s, mode: %s, name: %s for reading",
-           l->m->type, l->mode, l->name);
-    return TRUE;
-  }
-}
-
-
-/* =============== ASCII ============================================= */
-BOOLEAN slOpenAscii(si_link l, short flag, leftv h)
-{
-  const char *mode;
-  if (flag & SI_LINK_OPEN)
-  {
-    if (l->mode[0] != '\0' && (strcmp(l->mode, "r") == 0))
-      flag = SI_LINK_READ;
-    else flag = SI_LINK_WRITE;
-  }
-
-  if (flag == SI_LINK_READ) mode = "r";
-  else if (strcmp(l->mode, "w") == 0) mode = "w";
-  else mode = "a";
-
-
-  if (l->name[0] == '\0')
-  {
-    // stdin or stdout
-    if (flag == SI_LINK_READ)
-    {
-      l->data = (void *) stdin;
-      mode = "r";
-    }
-    else
-    {
-      l->data = (void *) stdout;
-      mode = "a";
-    }
-  }
-  else
-  {
-    // normal ascii link to a file
-    FILE *outfile;
-    char *filename=l->name;
-
-    if(filename[0]=='>')
-    {
-      if (filename[1]=='>')
-      {
-        filename+=2;
-        mode = "a";
-      }
-      else
-      {
-        filename++;
-        mode="w";
-      }
-    }
-    outfile=myfopen(filename,mode);
-    if (outfile!=NULL)
-      l->data = (void *) outfile;
-    else
-      return TRUE;
-  }
-
-  omFree(l->mode);
-  l->mode = omStrDup(mode);
-  SI_LINK_SET_OPEN_P(l, flag);
-  return FALSE;
-}
-
-BOOLEAN slCloseAscii(si_link l)
-{
-  SI_LINK_SET_CLOSE_P(l);
-  if (l->name[0] != '\0')
-  {
-    return (fclose((FILE *)l->data)!=0);
-  }
-  return FALSE;
-}
-
-leftv slReadAscii2(si_link l, leftv pr)
-{
-  FILE * fp=(FILE *)l->data;
-  char * buf=NULL;
-  if (fp!=NULL && l->name[0] != '\0')
-  {
-    fseek(fp,0L,SEEK_END);
-    long len=ftell(fp);
-    fseek(fp,0L,SEEK_SET);
-    buf=(char *)omAlloc((int)len+1);
-    if (BVERBOSE(V_READING))
-      Print("//Reading %ld chars\n",len);
-    myfread( buf, len, 1, fp);
-    buf[len]='\0';
-  }
-  else
-  {
-    if (pr->Typ()==STRING_CMD)
-    {
-      buf=(char *)omAlloc(80);
-      fe_fgets_stdin((char *)pr->Data(),buf,80);
-    }
-    else
-    {
-      WerrorS("read(<link>,<string>) expected");
-      buf=omStrDup("");
-    }
-  }
-  leftv v=(leftv)omAlloc0Bin(sleftv_bin);
-  v->rtyp=STRING_CMD;
-  v->data=buf;
-  return v;
-}
-
-leftv slReadAscii(si_link l)
-{
-  sleftv tmp;
-  memset(&tmp,0,sizeof(sleftv));
-  tmp.rtyp=STRING_CMD;
-  tmp.data=(void*) "? ";
-  return slReadAscii2(l,&tmp);
-}
-
-BOOLEAN slWriteAscii(si_link l, leftv v)
-{
-  FILE *outfile=(FILE *)l->data;
-  BOOLEAN err=FALSE;
-  char *s;
-  while (v!=NULL)
-  {
-    s = v->String();
-    // free v ??
-    if (s!=NULL)
-    {
-      fprintf(outfile,"%s\n",s);
-      omFree((ADDRESS)s);
-    }
-    else
-    {
-      Werror("cannot convert to string");
-      err=TRUE;
-    }
-    v = v->next;
-  }
-  fflush(outfile);
-  return err;
-}
-
-const char* slStatusAscii(si_link l, const char* request)
-{
-  if (strcmp(request, "read") == 0)
-  {
-    if (SI_LINK_R_OPEN_P(l)) return "ready";
-    else return "not ready";
-  }
-  else if (strcmp(request, "write") == 0)
-  {
-    if (SI_LINK_W_OPEN_P(l)) return "ready";
-    else return "not ready";
-  }
-  else return "unknown status request";
-}
-
-/*------------------ Dumping in Ascii format -----------------------*/
-
-BOOLEAN slDumpAscii(si_link l)
-{
-  FILE *fd = (FILE *) l->data;
-  idhdl h = IDROOT, rh = currRingHdl;
-  BOOLEAN status = DumpAscii(fd, h);
-
-  if (! status ) status = DumpAsciiMaps(fd, h, NULL);
-
-  if (currRingHdl != rh) rSetHdl(rh);
-  fprintf(fd, "option(set, intvec(%d, %d));\n", test, verbose);
-  fprintf(fd, "RETURN();\n");
-  fflush(fd);
-
-  return status;
-}
-
-// we do that recursively, to dump ids in the the order in which they
-// were actually defined
-static BOOLEAN DumpAscii(FILE *fd, idhdl h)
-{
-  if (h == NULL) return FALSE;
-
-  if (DumpAscii(fd, IDNEXT(h))) return TRUE;
-
-  // need to set the ring before writing it, otherwise we get in
-  // trouble with minpoly
-  if (IDTYP(h) == RING_CMD || IDTYP(h) == QRING_CMD)
-    rSetHdl(h);
-
-  if (DumpAsciiIdhdl(fd, h)) return TRUE;
-
-  if (IDTYP(h) == RING_CMD || IDTYP(h) == QRING_CMD)
-    return DumpAscii(fd, IDRING(h)->idroot);
-  else
-    return FALSE;
-}
-
-static BOOLEAN DumpAsciiMaps(FILE *fd, idhdl h, idhdl rhdl)
-{
-  if (h == NULL) return FALSE;
-  if (DumpAsciiMaps(fd, IDNEXT(h), rhdl)) return TRUE;
-
-  if (IDTYP(h) == RING_CMD || IDTYP(h) == QRING_CMD)
-    return DumpAsciiMaps(fd, IDRING(h)->idroot, h);
-  else if (IDTYP(h) == MAP_CMD)
-  {
-    char *rhs;
-    rSetHdl(rhdl);
-    rhs = h->String();
-
-    if (fprintf(fd, "setring %s;\n", IDID(rhdl)) == EOF) return TRUE;
-    if (fprintf(fd, "%s %s = %s, %s;\n", Tok2Cmdname(MAP_CMD), IDID(h),
-                IDMAP(h)->preimage, rhs) == EOF)
-    {
-      omFree(rhs);
-      return TRUE;
-    }
-    else
-    {
-      omFree(rhs);
-      return FALSE;
-    }
-  }
-  else return FALSE;
-}
-
-static BOOLEAN DumpAsciiIdhdl(FILE *fd, idhdl h)
-{
-  const char *type_str = GetIdString(h);
-  int type_id = IDTYP(h);
-
-  if ((type_id == PACKAGE_CMD) &&(strcmp(IDID(h), "Top") == 0))
-    return FALSE;
-
-  // we do not throw an error if a wrong type was attempted to be dumped
-  if (type_str == NULL)
-    return FALSE;
-
-  // handle qrings separately
-  if (type_id == QRING_CMD)
-    return DumpQring(fd, h, type_str);
-
-  // C-proc not to be dumped
-  if ((type_id == PROC_CMD) && (IDPROC(h)->language == LANG_C))
-    return FALSE;
-
-  // put type and name
-  if (fprintf(fd, "%s %s", type_str, IDID(h)) == EOF)
-    return TRUE;
-  // for matricies, append the dimension
-  if (type_id == MATRIX_CMD)
-  {
-    ideal id = IDIDEAL(h);
-    if (fprintf(fd, "[%d][%d]", id->nrows, id->ncols)== EOF) return TRUE;
-  }
-  else if (type_id == INTMAT_CMD)
-  {
-    if (fprintf(fd, "[%d][%d]", IDINTVEC(h)->rows(), IDINTVEC(h)->cols())
-        == EOF) return TRUE;
-  }
-
-  if (type_id == PACKAGE_CMD)
-  {
-    return (fprintf(fd, ";\n") == EOF);
-  }
-
-  // write the equal sign
-  if (fprintf(fd, " = ") == EOF) return TRUE;
-
-  // and the right hand side
-  if (DumpRhs(fd, h) == EOF) return TRUE;
-
-  // semicolon und tschuess
-  if (fprintf(fd, ";\n") == EOF) return TRUE;
-
-  return FALSE;
-}
-
-static const char* GetIdString(idhdl h)
-{
-  int type = IDTYP(h);
-
-  switch(type)
-  {
-      case LIST_CMD:
-      {
-        lists l = IDLIST(h);
-        int i, nl = l->nr + 1;
-        char *name;
-
-        for (i=0; i<nl; i++)
-          if (GetIdString((idhdl) &(l->m[i])) == NULL) return NULL;
-      }
-      case PACKAGE_CMD:
-      case INT_CMD:
-      case INTVEC_CMD:
-      case INTMAT_CMD:
-      case STRING_CMD:
-      case RING_CMD:
-      case QRING_CMD:
-      case PROC_CMD:
-      case NUMBER_CMD:
-      case POLY_CMD:
-      case IDEAL_CMD:
-      case VECTOR_CMD:
-      case MODUL_CMD:
-      case MATRIX_CMD:
-        return Tok2Cmdname(type);
-
-      case MAP_CMD:
-      case LINK_CMD:
-        return NULL;
-
-      default:
-       Warn("Error dump data of type %s", Tok2Cmdname(IDTYP(h)));
-       return NULL;
-  }
-}
-
-static BOOLEAN DumpQring(FILE *fd, idhdl h, const char *type_str)
-{
-  char *ring_str = h->String();
-  if (fprintf(fd, "%s temp_ring = %s;\n", Tok2Cmdname(RING_CMD), ring_str)
-              == EOF) return TRUE;
-  if (fprintf(fd, "%s temp_ideal = %s;\n", Tok2Cmdname(IDEAL_CMD),
-              iiStringMatrix((matrix) IDRING(h)->qideal, 1, currRing, n_GetChar(currRing->cf)))
-      == EOF) return TRUE;
-  if (fprintf(fd, "attrib(temp_ideal, \"isSB\", 1);\n") == EOF) return TRUE;
-  if (fprintf(fd, "%s %s = temp_ideal;\n", type_str, IDID(h)) == EOF)
-    return TRUE;
-  if (fprintf(fd, "kill temp_ring;\n") == EOF) return TRUE;
-  else
-  {
-    omFree(ring_str);
-    return FALSE;
-  }
-}
-
-
-static int DumpRhs(FILE *fd, idhdl h)
-{
-  int type_id = IDTYP(h);
-
-  if (type_id == LIST_CMD)
-  {
-    lists l = IDLIST(h);
-    int i, nl = l->nr;
-
-    fprintf(fd, "list(");
-
-    for (i=0; i<nl; i++)
-    {
-      if (DumpRhs(fd, (idhdl) &(l->m[i])) == EOF) return EOF;
-      fprintf(fd, ",");
-    }
-    if (nl > 0)
-    {
-      if (DumpRhs(fd, (idhdl) &(l->m[nl])) == EOF) return EOF;
-    }
-    fprintf(fd, ")");
-  }
-  else  if (type_id == STRING_CMD)
-  {
-    char *pstr = IDSTRING(h), c;
-    fputc('"', fd);
-    while (*pstr != '\0')
-    {
-      if (*pstr == '"' || *pstr == '\\')  fputc('\\', fd);
-      fputc(*pstr, fd);
-      pstr++;
-    }
-    fputc('"', fd);
-  }
-  else  if (type_id == PROC_CMD)
-  {
-    procinfov pi = IDPROC(h);
-    if (pi->language == LANG_SINGULAR) {
-      if( pi->data.s.body==NULL) iiGetLibProcBuffer(pi);
-      char *pstr = pi->data.s.body, c;
-      fputc('"', fd);
-      while (*pstr != '\0') {
-        if (*pstr == '"' || *pstr == '\\') fputc('\\', fd);
-        fputc(*pstr, fd);
-        pstr++;
-      }
-      fputc('"', fd);
-    } else fputs("(null)", fd);
-  }
-  else
-  {
-    char *rhs = h->String();
-
-    if (rhs == NULL) return EOF;
-
-    if (type_id == INTVEC_CMD) fprintf(fd, "intvec(");
-
-    if (fprintf(fd, "%s", rhs) == EOF) return EOF;
-    omFree(rhs);
-
-    if ((type_id == RING_CMD || type_id == QRING_CMD) &&
-        IDRING(h)->cf->type==n_algExt)
-    {
-      StringSetS("");
-      p_Write(IDRING(h)->cf->extRing->qideal->m[0],IDRING(h)->cf->extRing);
-      rhs = StringAppendS("");
-      if (fprintf(fd, "; minpoly = %s", rhs) == EOF) return EOF;
-    }
-    else if (type_id == INTVEC_CMD) fprintf(fd, ")");
-  }
-  return 1;
-}
-
-BOOLEAN slGetDumpAscii(si_link l)
-{
-  if (l->name[0] == '\0')
-  {
-    Werror("getdump: Can not get dump from stdin");
-    return TRUE;
-  }
-  else
-  {
-    BOOLEAN status = newFile(l->name);
-    if (status)
-      return TRUE;
-
-    int old_echo=si_echo;
-    si_echo=0;
-
-    status=yyparse();
-
-    si_echo=old_echo;
-
-    if (status)
-      return TRUE;
-    else
-    {
-      // lets reset the file pointer to the end to reflect that
-      // we are finished with reading
-      FILE *f = (FILE *) l->data;
-      fseek(f, 0L, SEEK_END);
-      return FALSE;
-    }
-  }
-}
-
-
-/*------------Initialization at Start-up time------------------------*/
-
-#include <Singular/slInit.h>
-
-static si_link_extension slTypeInit(si_link_extension s, const char* type)
-{
-  assume(s != NULL);
-  s->next = NULL;
-  si_link_extension ns = (si_link_extension)omAlloc0Bin(s_si_link_extension_bin);
-
-  if (0) 0;
-#ifdef HAVE_DBM
-  else if (strcmp(type, "DBM") == 0)
-    s->next = slInitDBMExtension(ns);
-#endif
-#if 1
-  else if (strcmp(type, "ssi") == 0)
-    s->next = slInitSsiExtension(ns);
-#endif
-#if 1
-  else if (strcmp(type, "|") == 0)
-    s->next = slInitPipeExtension(ns);
-#endif
-  else
-  {
-    Warn("Found unknown link type: %s", type);
-    Warn("Use default link type: %s", si_link_root->type);
-    omFreeBin(ns, s_si_link_extension_bin);
-    return si_link_root;
-  }
-
-  if (s->next == NULL)
-  {
-    Werror("Can not initialize link type %s", type);
-    omFreeBin(ns, s_si_link_extension_bin);
-    return NULL;
-  }
-  return s->next;
-}
-
-void slStandardInit()
-{
-  si_link_extension s;
-  si_link_root=(si_link_extension)omAlloc0Bin(s_si_link_extension_bin);
-  si_link_root->Open=slOpenAscii;
-  si_link_root->Close=slCloseAscii;
-  si_link_root->Kill=slCloseAscii;
-  si_link_root->Read=slReadAscii;
-  si_link_root->Read2=slReadAscii2;
-  si_link_root->Write=slWriteAscii;
-  si_link_root->Dump=slDumpAscii;
-  si_link_root->GetDump=slGetDumpAscii;
-  si_link_root->Status=slStatusAscii;
-  si_link_root->type="ASCII";
-  s = si_link_root;
-  s->next = NULL;
-}
Index: Singular/silink.h
===================================================================
--- Singular/silink.h	(revision 4fb3a73a9ab769b9cdb2ec0db33cdbf9e88bfedd)
+++ Singular/silink.h	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
@@ -11,5 +11,5 @@
 #include <kernel/structs.h>
 
-#include <Singular/sing_dbm.h>
+#include <Singular/links/sing_dbm.h>
 #include <Singular/lists.h>
 #include <Singular/attrib.h>
Index: ngular/sing_dbm.cc
===================================================================
--- Singular/sing_dbm.cc	(revision 4fb3a73a9ab769b9cdb2ec0db33cdbf9e88bfedd)
+++ 	(revision )
@@ -1,461 +1,0 @@
-/****************************************
-*  Computer Algebra System SINGULAR     *
-****************************************/
-
-//**************************************************************************/
-//
-//
-//**************************************************************************/
-//  'sing_dbm.cc' containes command to handle dbm-files under
-// Singular.
-//
-//**************************************************************************/
-
-#  include <stdio.h>
-#  include <fcntl.h>
-#  include <errno.h>
-
-#include "config.h"
-#include <kernel/mod2.h>
-
-#ifdef HAVE_DBM
-
-#  include <Singular/tok.h>
-#  include <kernel/febase.h>
-#include <omalloc/omalloc.h>
-#  include <Singular/ipid.h>
-#  include <Singular/silink.h>
-#  include <Singular/sing_dbm.h>
-
-// #ifdef ix86_Win
-// #  define USE_GDBM
-// #  define BLOCKSIZE 1
-// #  define GDBM_STATIC
-// #  include <gdbm.h>
-// #endif
-
-#ifdef USE_GDBM
-typedef struct {
-  GDBM_FILE db;        // pointer to open database
-  int first;      // firstkey to look for?
-  datum actual;  // the actual key
-} GDBM_info;
-
-//**************************************************************************/
-LINKAGE BOOLEAN dbOpen(si_link l, short flag, leftv u)
-{
-  char *mode = "r";
-  GDBM_info *db;
-  datum d_key;
-  //  int dbm_flags = O_RDONLY | O_CREAT;  // open database readonly as default
-  int read_write= GDBM_READER;
-
-  if(flag & SI_LINK_WRITE)
-  {
- //    if((l->mode==NULL)
-//     || ((l->mode[0]!='w')&&(l->mode[1]!='w')))
-//     {
-//       // request w- open, but mode is not "w" nor "rw" => fail
-//       return TRUE;
-//    }
-    //    dbm_flags = O_RDWR | O_CREAT;
-    read_write =  GDBM_WRCREAT | GDBM_NOLOCK;
-    mode = "rw";
-  }
-  if(flag & SI_LINK_READ)
-    {
-      if (strcmp(l->mode,"rw")==0) mode="rw";	
-    }
-  //if (((db = (DBM_info *)omAlloc(sizeof *db)) != NULL)
-  //&&((db->db = dbm_open(l->name, dbm_flags, 0664 )) != NULL ))
-  db = (GDBM_info *)omAlloc0(sizeof *db);
-  if((db->db = gdbm_open(l->name, BLOCKSIZE, read_write, 0664, 0)) != NULL )
-  {
-//     if (db->first) // first created?
-//       {
-//         db->actual=gdbm_firstkey(db->db);
-//       }
-//     else
-//       {
-//     d_key=db->actual;
-//     if (d_key.dptr!=NULL)
-//       {
-//         db->actual=gdbm_nextkey(db->db,db->actual);
-//       }
-//     else { db->actual=gdbm_firstkey(db->db); }
-//      }
-    db->first=1;
-    if(flag & SI_LINK_WRITE)
-      SI_LINK_SET_W_OPEN_P(l);
-    else
-      SI_LINK_SET_R_OPEN_P(l);
-    l->data=(void *)(db);
-    omFree(l->mode);
-    l->mode=omStrDup(mode);
-    return FALSE;
-  }
-  Print("%d/%s",gdbm_errno,gdbm_strerror(gdbm_errno));
-  return TRUE;
-}
-
-//**************************************************************************/
-LINKAGE BOOLEAN dbClose(si_link l)
-{
-  GDBM_info *db = (GDBM_info *)l->data;
-  gdbm_sync(db->db);
-  gdbm_close(db->db);
-  omFreeSize((ADDRESS)db,(sizeof *db));
-  l->data=NULL;
-  SI_LINK_SET_CLOSE_P(l);
-  return FALSE;
-}
-
-//**************************************************************************/
-static datum d_value;
-LINKAGE leftv dbRead2(si_link l, leftv key)
-{
-  GDBM_info *db = (GDBM_info *)l->data;
-  // GDBM_info *db;
-//   db = (GDBM_info *)omAlloc0(sizeof *db);
-//   db = (GDBM_info *)l->data;
-  leftv v=NULL;
-  datum d_key;
-  int flag;
-
-  if (!SI_LINK_R_OPEN_P(l)) //exceptions
-    //  if (strcmp(l->mode,"rw")==0) //rw-mode
-    {
-      if (!SI_LINK_CLOSE_P(l))
-	{
-	  if (!dbClose(l)) {Print("cannot close link!\n");}
-	}
-      //(SI_LINK_CLOSE_P(l)) automatically
-      if (dbOpen(l, SI_LINK_READ)) return NULL;
-    }
-  if (SI_LINK_RW_OPEN_P(l)) {Print("I/O Error!\n");}
-
-  if(key!=NULL)
-  {
-    if (key->Typ()==STRING_CMD)
-    {
-      d_key.dptr = (char*)key->Data();
-      d_key.dsize = strlen(d_key.dptr)+1;
-      d_value = gdbm_fetch(db->db, d_key);
-      v=(leftv)omAlloc0Bin(sleftv_bin);
-      if (d_value.dptr!=NULL) v->data=omStrDup(d_value.dptr);
-      else                    v->data=omStrDup("");
-      v->rtyp=STRING_CMD;
-    }
-    else
-    {
-      WerrorS("read(`GDBM link`,`string`) expected");
-    }
-  }
-  else
-  {
-    if (db->first)
-    {
-      db->first=0;
-      d_key = gdbm_firstkey(db->db);
-   //    db->actual=d_key;
-//       Print("firstkey:%s\n",d_key.dptr);
-    }
-    else
-    {
-      if (db->actual.dptr==NULL)
-      {
-	db->actual=gdbm_firstkey(db->db);
-      }
-      d_key = gdbm_nextkey(db->db,db->actual);
-      db->actual=d_key;
-      if (d_key.dptr==NULL)
-      {
-        db->first=1;
-      // Print("nextkey:NULL\n");
-      }
-     //  else
-//       Print("nextkey:%s\n",d_key.dptr);
-    }
-
-    if (d_key.dptr!=NULL)
-      d_value = gdbm_fetch(db->db, d_key);
-    else
-      d_value.dptr=NULL;
-
-    v=(leftv)omAlloc0Bin(sleftv_bin);
-    v->rtyp=STRING_CMD;
-    if (d_value.dptr!=NULL)
-    {
-      v->data=omStrDup(d_key.dptr);
-      db->first = 0;
-    }
-    else
-    {
-      v->data=omStrDup("");
-      //      db->first = 1;
-    }
-
-  }
-  return v;
-}
-LINKAGE leftv dbRead1(si_link l)
-{
-  return dbRead2(l,NULL);
-}
-//**************************************************************************/
-LINKAGE BOOLEAN dbWrite(si_link l, leftv key)
-{
-  GDBM_info *db = (GDBM_info *)l->data;
- //  GDBM_info *db;
-//   db = (GDBM_info *)omAlloc0(sizeof *db);
-//   db = (GDBM_info *)l->data;
-  BOOLEAN b=TRUE;
-  register int ret;
-
-  if (strcmp(l->mode,"rw")!=0) // r-mode
-    {
-      Print("Write error on readonly source\n");
-    }
-  else //rw-mode
-    {
-      if (!SI_LINK_W_OPEN_P(l)) //exceptions
-	{
-	  if (!SI_LINK_CLOSE_P(l))
-	    {
-	      if (!dbClose(l)) {Print("close error\n");};
-	    }
-	  if (!dbOpen(l,SI_LINK_WRITE)) {Print("open_for_write error\n");}
-	}
-    }
-
-  if((key!=NULL) && (key->Typ()==STRING_CMD) )
-  {
-    if (key->next!=NULL)                   // have a second parameter ?
-    {
-      if(key->next->Typ()==STRING_CMD)     // replace (key,value)
-      {
-        datum d_key, d_value;
-
-        d_key.dptr = (char *)key->Data();
-        d_key.dsize = strlen(d_key.dptr)+1;
-        d_value.dptr = (char *)key->next->Data();
-        d_value.dsize = strlen(d_value.dptr)+1;
-        ret  = gdbm_store(db->db, d_key, d_value, GDBM_REPLACE);
-//         db->actual=d_key;
-	if (ret==-1) {Print("reader calls gdbm_store!");}
-        if (ret==0)
-          { b=FALSE; }
-        else
-        {
-          //          if(gdbm_error(db->db))
-          if (gdbm_errno != 0)
-          {
-            Werror("GDBM link I/O error: '%s' ", gdbm_errno);
-	    //            Print(gdbm_strerror(gdbm_errno));
-            //dbm_clearerr(db->db);
-	    //            gdbm_errno=0;
-          }
-        }
-      }
-    }
-    else
-    {                               // delete (key)
-      datum d_key;
-
-      d_key.dptr = (char *)key->Data();
-      d_key.dsize = strlen(d_key.dptr)+1;
- //      db->actual=gdbm_nextkey(db->db,d_key);
-      gdbm_delete(db->db, d_key);
-      b=FALSE;
-    }
-  }
-  else
-  {
-    WerrorS("write(`GDBM link`,`key string` [,`data string`]) expected");
-  }
-  gdbm_sync(db->db);
-  return b;
-}
-#endif /* USE_GDBM */
-
-#ifndef USE_GDBM
-/* These are the routines in dbm. */
-#  include "ndbm.h"
-typedef struct {
-  DBM *db;        // pointer to open database
-  int first;      // firstkey to look for?
-} DBM_info;
-
-//**************************************************************************/
-LINKAGE BOOLEAN dbOpen(si_link l, short flag, leftv u)
-{
-  const char *mode = "r";
-  DBM_info *db;
-  int dbm_flags = O_RDONLY | O_CREAT;  // open database readonly as default
-
-  if((l->mode!=NULL)
-  && ((l->mode[0]=='w')||(l->mode[1]=='w')))
-  {
-    dbm_flags = O_RDWR | O_CREAT;
-    mode = "rw";
-    flag|=SI_LINK_WRITE|SI_LINK_READ;
-  }
-  else if(flag & SI_LINK_WRITE)
-  {
-    // request w- open, but mode is not "w" nor "rw" => fail
-    return TRUE;
-  }
-  //if (((db = (DBM_info *)omAlloc(sizeof *db)) != NULL)
-  //&&((db->db = dbm_open(l->name, dbm_flags, 0664 )) != NULL ))
-  db = (DBM_info *)omAlloc(sizeof *db);
-  if((db->db = dbm_open(l->name, dbm_flags, 0664 )) != NULL )
-  {
-    db->first=1;
-    if(flag & SI_LINK_WRITE)
-      SI_LINK_SET_RW_OPEN_P(l);
-    else
-      SI_LINK_SET_R_OPEN_P(l);
-    l->data=(void *)(db);
-    omFree(l->mode);
-    l->mode=omStrDup(mode);
-    return FALSE;
-  }
-  return TRUE;
-}
-
-//**************************************************************************/
-LINKAGE BOOLEAN dbClose(si_link l)
-{
-  DBM_info *db = (DBM_info *)l->data;
-
-  dbm_close(db->db);
-  omFreeSize((ADDRESS)db,(sizeof *db));
-  l->data=NULL;
-  SI_LINK_SET_CLOSE_P(l);
-  return FALSE;
-}
-
-//**************************************************************************/
-static datum d_value;
-LINKAGE leftv dbRead2(si_link l, leftv key)
-{
-  DBM_info *db = (DBM_info *)l->data;
-  leftv v=NULL;
-  datum d_key;
-
-  if(key!=NULL)
-  {
-    if (key->Typ()==STRING_CMD)
-    {
-      d_key.dptr = (char*)key->Data();
-      d_key.dsize = strlen(d_key.dptr)+1;
-      d_value = dbm_fetch(db->db, d_key);
-      v=(leftv)omAlloc0Bin(sleftv_bin);
-      if (d_value.dptr!=NULL) v->data=omStrDup(d_value.dptr);
-      else                    v->data=omStrDup("");
-      v->rtyp=STRING_CMD;
-    }
-    else
-    {
-      WerrorS("read(`DBM link`,`string`) expected");
-    }
-  }
-  else
-  {
-    if(db->first)
-      d_value = dbm_firstkey((DBM *)db->db);
-    else
-      d_value = dbm_nextkey((DBM *)db->db);
-
-    v=(leftv)omAlloc0Bin(sleftv_bin);
-    v->rtyp=STRING_CMD;
-    if (d_value.dptr!=NULL)
-    {
-      v->data=omStrDup(d_value.dptr);
-      db->first = 0;
-    }
-    else
-    {
-      v->data=omStrDup("");
-      db->first = 1;
-    }
-
-  }
-  return v;
-}
-LINKAGE leftv dbRead1(si_link l)
-{
-  return dbRead2(l,NULL);
-}
-//**************************************************************************/
-LINKAGE BOOLEAN dbWrite(si_link l, leftv key)
-{
-  DBM_info *db = (DBM_info *)l->data;
-  BOOLEAN b=TRUE;
-  register int ret;
-
-  // database is opened
-  if((key!=NULL) && (key->Typ()==STRING_CMD) )
-  {
-    if (key->next!=NULL)                   // have a second parameter ?
-    {
-      if(key->next->Typ()==STRING_CMD)     // replace (key,value)
-      {
-        datum d_key, d_value;
-
-        d_key.dptr = (char *)key->Data();
-        d_key.dsize = strlen(d_key.dptr)+1;
-        d_value.dptr = (char *)key->next->Data();
-        d_value.dsize = strlen(d_value.dptr)+1;
-        ret  = dbm_store(db->db, d_key, d_value, DBM_REPLACE);
-        if(!ret )
-          b=FALSE;
-        else
-        {
-          if(dbm_error(db->db))
-          {
-            Werror("DBM link I/O error. Is '%s' readonly?", l->name);
-            dbm_clearerr(db->db);
-          }
-        }
-      }
-    }
-    else
-    {                               // delete (key)
-      datum d_key;
-
-      d_key.dptr = (char *)key->Data();
-      d_key.dsize = strlen(d_key.dptr)+1;
-      dbm_delete(db->db, d_key);
-      b=FALSE;
-    }
-  }
-  else
-  {
-    WerrorS("write(`DBM link`,`key string` [,`data string`]) expected");
-  }
-  return b;
-}
-//**************************************************************************/
-//char *dbStatus(si_link l, char *request)
-//{
-//  if (strcmp(request, "read") == 0)
-//  {
-//    if (SI_LINK_R_OPEN_P(l))
-//      return "ready";
-//    else
-//      return "not ready";
-//  }
-//  else if (strcmp(request, "write") == 0)
-//  {
-//    if (SI_LINK_W_OPEN_P(l))
-//      return "ready";
-//    else
-//      return "not ready";
-//  }
-//  else return "unknown status request";
-//}
-//**************************************************************************/
-
-#endif /* USE_GDBM */
-#endif /* HAVE_DBM */
Index: ngular/sing_dbm.h
===================================================================
--- Singular/sing_dbm.h	(revision 4fb3a73a9ab769b9cdb2ec0db33cdbf9e88bfedd)
+++ 	(revision )
@@ -1,14 +1,0 @@
-#ifndef SING_DBM_H
-#define SING_DBM_H
-/****************************************
-*  Computer Algebra System SINGULAR     *
-****************************************/
-/*
-* ABSTRACT: interface to DBM links
-*/
-
-struct s_si_link_extension;
-typedef struct s_si_link_extension *si_link_extension;
-
-si_link_extension slInitDBMExtension(si_link_extension s);
-#endif
Index: Singular/slInit_Static.cc
===================================================================
--- Singular/slInit_Static.cc	(revision 4fb3a73a9ab769b9cdb2ec0db33cdbf9e88bfedd)
+++ Singular/slInit_Static.cc	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
@@ -18,7 +18,7 @@
 
 # ifndef USE_GDBM
-#   include <Singular/dbm_sl.h>
+#   include <Singular/links/dbm_sl.h>
 # else
-#   include <Singular/sing_dbm.h>
+#   include <Singular/links/sing_dbm.h>
 #endif
 
Index: ngular/ssiLink.cc
===================================================================
--- Singular/ssiLink.cc	(revision 4fb3a73a9ab769b9cdb2ec0db33cdbf9e88bfedd)
+++ 	(revision )
@@ -1,1639 +1,0 @@
-/****************************************
- * Computer Algebra System SINGULAR     *
- ****************************************/
-/***************************************************************
- * File:    ssiLink.h
- *  Purpose: declaration of sl_link routines for ssi
- ***************************************************************/
-#include <stdio.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <signal.h>
-#include <sys/types.h>          /* for portability */
-#include <sys/select.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <ctype.h>   /*for isdigit*/
-#include <netdb.h>
-#include <sys/wait.h>
-
-
-
-#include "config.h"
-#include <kernel/mod2.h>
-
-#include <Singular/tok.h>
-#include <Singular/ipshell.h>
-#include <Singular/ipid.h>
-#include <omalloc/omalloc.h>
-#include <polys/monomials/ring.h>
-#include <polys/matpol.h>
-#include <kernel/ideals.h>
-#include <kernel/polys.h>
-#include <kernel/longrat.h>
-#include <kernel/ideals.h>
-#include <misc/intvec.h>
-#include <misc/options.h>
-#include <kernel/timer.h>
-#include <Singular/subexpr.h>
-#include <Singular/silink.h>
-#include <Singular/cntrlc.h>
-#include <Singular/lists.h>
-#include <Singular/blackbox.h>
-#include <Singular/ssiLink.h>
-
-struct snumber_dummy
-{
-  mpz_t z;
-  mpz_t n;
-  #if defined(LDEBUG)
-  int debug;
-  #endif
-  BOOLEAN s;
-};
-typedef struct snumber_dummy  *number_dummy;
-
-//#if (_POSIX_C_SOURCE >= 200112L) || (_XOPEN_SOURCE >= 600)
-//#define HAVE_PSELECT
-//#endif
-
-#define SSI_VERSION 3
-
-typedef struct
-{
-  FILE *f_read;
-  FILE *f_write;
-  ring r;
-  pid_t pid; /* only valid for fork/tcp mode*/
-  int fd_read,fd_write; /* only valid for fork/tcp mode*/
-  char level;
-  char ungetc_buf; /* status sets to !=0, if ungetc was used, ssiRead* set to 0*/
-  char send_quit_at_exit;
-
-} ssiInfo;
-
-
-link_list ssiToBeClosed=NULL;
-sigset_t ssi_sigmask;
-sigset_t ssi_oldmask;
-#define SSI_BLOCK_CHLD sigprocmask(SIG_SETMASK, &ssi_sigmask, &ssi_oldmask)
-#define SSI_UNBLOCK_CHLD sigprocmask(SIG_SETMASK, &ssi_oldmask, NULL)
-
-#define SR_INT 1L
-#define SR_HDL(A) ((long)(A))
-#define SR_TO_INT(SR)   (((long)SR) >> 2)
-
-// the helper functions:
-void ssiSetCurrRing(const ring r)
-{
-  if (!rEqual(r,currRing,1))
-  {
-    char name[20];
-    int nr=0;
-    do
-    { sprintf(name,"ssiRing%d",nr); nr++; }
-    while(IDROOT->get(name, 0)!=NULL);
-    idhdl h=enterid(omStrDup(name),0,RING_CMD,&IDROOT,FALSE);
-    IDRING(h)=r;
-    r->ref++;
-    rSetHdl(h);
-  }
-}
-// the implementation of the functions:
-void ssiWriteInt(ssiInfo *d,const int i)
-{
-  SSI_BLOCK_CHLD;
-  fprintf(d->f_write,"%d ",i);
-  SSI_UNBLOCK_CHLD;
-  //if (d->f_debug!=NULL) fprintf(d->f_debug,"int: %d ",i);
-}
-
-void ssiWriteString(ssiInfo *d,const char *s)
-{
-  SSI_BLOCK_CHLD;
-  fprintf(d->f_write,"%d %s ",strlen(s),s);
-  SSI_UNBLOCK_CHLD;
-  //if (d->f_debug!=NULL) fprintf(d->f_debug,"stringi: %d \"%s\" ",strlen(s),s);
-}
-
-
-void ssiWriteBigInt(const ssiInfo *d, const number n)
-{
-  // syntax is as follows:
-  // case 2 Q:     3 4 <int>
-  //        or     3 3 <mpz_t nominator>
-  SSI_BLOCK_CHLD;
-  if((long)(n) & SR_INT)
-  {
-    fprintf(d->f_write,"4 %ld ",SR_TO_INT(n));
-    //if (d->f_debug!=NULL) fprintf(d->f_debug,"bigint: short \"%ld\" ",SR_TO_INT(n));
-  }
-  else if (((number_dummy)n)->s==3)
-  {
-    fputs("3 ",d->f_write);
-    mpz_out_str(d->f_write,10,((number_dummy)n)->z);
-    fputc(' ',d->f_write);
-    //gmp_fprintf(d->f_write,"3 %Zd ",n->z);
-    //if (d->f_debug!=NULL) gmp_fprintf(d->f_debug,"bigint: gmp \"%Zd\" ",n->z);
-  }
-  else WerrorS("illiegal bigint");
-  SSI_UNBLOCK_CHLD;
-}
-
-void ssiWriteNumber(const ssiInfo *d, const number n)
-{
-  // syntax is as follows:
-  // case 1 Z/p:   3 <int>
-  // case 2 Q:     3 4 <int>
-  //        or     3 0 <mpz_t nominator> <mpz_t denominator>
-  //        or     3 1  dto.
-  //        or     3 3 <mpz_t nominator>
-  //        or     3 5 <mpz_t raw nom.> <mpz_t raw denom.>
-  //        or     3 6 <mpz_t raw nom.> <mpz_t raw denom.>
-  //        or     3 7 <mpz_t raw nom.>
-  SSI_BLOCK_CHLD;
-  if(rField_is_Zp(d->r))
-  {
-    fprintf(d->f_write,"%d ",(int)(long)n);
-    //if (d->f_debug!=NULL) fprintf(d->f_debug,"number: \"%ld\" ",(int)(long)n);
-  }
-  else if (rField_is_Q(d->r))
-  {
-    if(SR_HDL(n) & SR_INT)
-    {
-      fprintf(d->f_write,"4 %ld ",SR_TO_INT(n));
-      //if (d->f_debug!=NULL) fprintf(d->f_debug,"number: short \"%ld\" ",SR_TO_INT(n));
-    }
-    else if (((number_dummy)n)->s<2)
-    {
-      //gmp_fprintf(d->f_write,"%d %Zd %Zd ",n->s,n->z,n->n);
-      fprintf(d->f_write,"%d ",((number_dummy)n)->s+5);
-      mpz_out_str (d->f_write,32, ((number_dummy)n)->z);
-      fputc(' ',d->f_write);
-      mpz_out_str (d->f_write,32, ((number_dummy)n)->n);
-      fputc(' ',d->f_write);
-
-      //if (d->f_debug!=NULL) gmp_fprintf(d->f_debug,"number: s=%d gmp/gmp \"%Zd %Zd\" ",n->s,n->z,n->n);
-    }
-    else /*n->s==3*/
-    {
-      //gmp_fprintf(d->f_write,"3 %Zd ",n->z);
-      fputs("8 ",d->f_write);
-      mpz_out_str (d->f_write,32, ((number_dummy)n)->z);
-      fputc(' ',d->f_write);
-
-      //if (d->f_debug!=NULL) gmp_fprintf(d->f_debug,"number: gmp \"%Zd\" ",n->z);
-    }
-  }
-  else WerrorS("coeff field not implemented");
-  SSI_UNBLOCK_CHLD;
-}
-
-void ssiWriteRing(ssiInfo *d,const ring r)
-{
-  /* 5 <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... */
-  if (d->r!=NULL) rKill(d->r);
-  d->r=r;
-  d->r->ref++;
-  SSI_BLOCK_CHLD;
-  fprintf(d->f_write,"%d %d ",n_GetChar(r->cf),r->N);
-
-  int i;
-  for(i=0;i<r->N;i++)
-  {
-    fprintf(d->f_write,"%d %s ",strlen(r->names[i]),r->names[i]);
-  }
-  /* number of orderings:*/
-  i=0;
-  while (r->order[i]!=0) i++;
-  fprintf(d->f_write,"%d ",i);
-  /* each ordering block: */
-  i=0;
-  while(r->order[i]!=0)
-  {
-    fprintf(d->f_write,"%d %d %d ",r->order[i],r->block0[i], r->block1[i]);
-    switch(r->order[i])
-    {
-      case ringorder_a:
-      case ringorder_wp:
-      case ringorder_Wp:
-      case ringorder_ws:
-      case ringorder_Ws:
-      case ringorder_aa:
-      {
-        int ii;
-        for(ii=r->block0[i];ii<=r->block1[i];ii++)
-          fprintf(d->f_write,"%d ",r->wvhdl[i][ii-r->block0[i]]);
-      }
-      break;
-      case ringorder_a64:
-      case ringorder_M:
-      case ringorder_L:
-      case ringorder_IS:
-        Werror("ring oder not implemented for ssi:%d",r->order[i]);
-        break;
-
-      default: break;
-    }
-    i++;
-  }
-  SSI_UNBLOCK_CHLD;
-}
-
-void ssiWritePoly(ssiInfo *d, int typ, poly p)
-{
-  SSI_BLOCK_CHLD;
-  fprintf(d->f_write,"%d ",pLength(p));//number of terms
-  SSI_UNBLOCK_CHLD;
-  int i;
-
-  while(p!=NULL)
-  {
-    ssiWriteNumber(d,pGetCoeff(p));
-    //nWrite(fich,pGetCoeff(p));
-    SSI_BLOCK_CHLD;
-    fprintf(d->f_write,"%ld ",p_GetComp(p,d->r));//component
-
-    for(int j=1;j<=rVar(d->r);j++)
-    {
-      fprintf(d->f_write,"%ld ",p_GetExp(p,j,d->r ));//x^j
-    }
-    pIter(p);
-    SSI_UNBLOCK_CHLD;
-  }
-}
-
-void ssiWriteIdeal(ssiInfo *d, int typ,ideal I)
-{
-   // syntax: 7 # of elements <poly 1> <poly2>.....
-   // syntax: 8 <rows> <cols> <poly 1> <poly2>.....
-   matrix M=(matrix)I;
-   SSI_BLOCK_CHLD;
-   if (typ==MATRIX_CMD)
-        fprintf(d->f_write,"%d %d ", MATROWS(M),MATCOLS(M));
-   else
-     fprintf(d->f_write,"%d ",IDELEMS(I));
-    SSI_UNBLOCK_CHLD;
-
-   int i;
-   int tt;
-   if (typ==MODUL_CMD) tt=VECTOR_CMD;
-   else                tt=POLY_CMD;
-
-   for(i=0;i<IDELEMS(I);i++)
-   {
-     ssiWritePoly(d,tt,I->m[i]);
-   }
-}
-void ssiWriteCommand(si_link l, command D)
-{
-  ssiInfo *d=(ssiInfo*)l->data;
-  // syntax: <num ops> <operation> <op1> <op2> ....
-  SSI_BLOCK_CHLD;
-  fprintf(d->f_write,"%d %d ",D->argc,D->op);
-  SSI_UNBLOCK_CHLD;
-  if (D->argc >0) ssiWrite(l, &(D->arg1));
-  if (D->argc < 4)
-  {
-    if (D->argc >1) ssiWrite(l, &(D->arg2));
-    if (D->argc >2) ssiWrite(l, &(D->arg3));
-  }
-}
-
-void ssiWriteProc(ssiInfo *d,procinfov p)
-{
-  ssiWriteString(d,p->data.s.body);
-}
-
-void ssiWriteList(si_link l,lists dd)
-{
-  ssiInfo *d=(ssiInfo*)l->data;
-  SSI_BLOCK_CHLD;
-  fprintf(d->f_write,"%d ",dd->nr+1);
-  SSI_UNBLOCK_CHLD;
-  int i;
-  for(i=0;i<=dd->nr;i++)
-  {
-    ssiWrite(l,&(dd->m[i]));
-  }
-}
-void ssiWriteIntvec(ssiInfo *d,intvec * v)
-{
-  SSI_BLOCK_CHLD;
-  fprintf(d->f_write,"%d ",v->length());
-  int i;
-  for(i=0;i<v->length();i++)
-  {
-    fprintf(d->f_write,"%d ",(*v)[i]);
-  }
-  SSI_UNBLOCK_CHLD;
-}
-
-char *ssiReadString(ssiInfo *d)
-{
-  char *buf;
-  int l;
-  SSI_BLOCK_CHLD;
-  fscanf(d->f_read,"%d ",&l);
-  SSI_UNBLOCK_CHLD;
-  buf=(char*)omAlloc(l+1);
-  SSI_BLOCK_CHLD;
-  fread(buf,1,l,d->f_read);
-  SSI_UNBLOCK_CHLD;
-  buf[l]='\0';
-  return buf;
-}
-
-int ssiReadInt(FILE *fich)
-{
-  int d;
-  SSI_BLOCK_CHLD;
-  fscanf(fich,"%d",&d);
-  SSI_UNBLOCK_CHLD;
-  return d;
-}
-
-number ssiReadBigInt(ssiInfo *d)
-{
-  int sub_type=-1;
-  SSI_BLOCK_CHLD;
-  fscanf(d->f_read,"%d",&sub_type);
-  SSI_UNBLOCK_CHLD;
-  switch(sub_type)
-  {
-   case 3:
-     {// read int or mpz_t or mpz_t, mpz_t
-       number n=(number)omAlloc0(sizeof(snumber_dummy));
-       SSI_BLOCK_CHLD;
-       mpz_inp_str(((number_dummy)n)->z,d->f_read,0);
-       SSI_UNBLOCK_CHLD;
-       ((number_dummy)n)->s=sub_type;
-       return n;
-     }
-   case 4:
-     {
-       int dd;
-       SSI_BLOCK_CHLD;
-       fscanf(d->f_read,"%d",&dd);
-       SSI_UNBLOCK_CHLD;
-       return n_Init(dd,d->r->cf);
-     }
-   default:
-       Werror("error in reading bigint: invalid subtype %d",sub_type);
-       return NULL;
-   }
-}
-
-number ssiReadNumber(ssiInfo *d)
-{
-  if (rField_is_Q(d->r))
-  {
-     int sub_type=-1;
-     SSI_BLOCK_CHLD;
-     fscanf(d->f_read,"%d",&sub_type);
-     SSI_UNBLOCK_CHLD;
-     switch(sub_type)
-     {
-     case 0:
-     case 1:
-       {// read mpz_t, mpz_t
-         number n=(number)omAlloc0(sizeof(snumber_dummy));
-         mpz_init(((number_dummy)n)->n);
-         SSI_BLOCK_CHLD;
-         gmp_fscanf(d->f_read,"%Zd %Zd",((number_dummy)n)->z,((number_dummy)n)->n);
-         SSI_UNBLOCK_CHLD;
-         ((number_dummy)n)->s=sub_type;
-         return n;
-       }
-
-     case 3:
-       {// read mpz_t
-         number n=(number)omAlloc0(sizeof(snumber_dummy));
-         SSI_BLOCK_CHLD;
-         gmp_fscanf(d->f_read,"%Zd",((number_dummy)n)->z);
-         SSI_UNBLOCK_CHLD;
-         ((number_dummy)n)->s=3; /*sub_type*/
-         return n;
-       }
-     case 4:
-       {
-         int dd;
-         SSI_BLOCK_CHLD;
-         fscanf(d->f_read,"%d",&dd);
-         SSI_UNBLOCK_CHLD;
-         return n_Init(dd,d->r->cf);
-       }
-     case 5:
-     case 6:
-       {// read raw mpz_t, mpz_t
-         number n=(number)omAlloc0(sizeof(snumber_dummy));
-         mpz_init(((number_dummy)n)->n);
-         SSI_BLOCK_CHLD;
-         mpz_inp_str (((number_dummy)n)->z, d->f_read, 32);
-         mpz_inp_str (((number_dummy)n)->n, d->f_read, 32);
-         SSI_UNBLOCK_CHLD;
-         ((number_dummy)n)->s=sub_type-5;
-         return n;
-       }
-     case 8:
-       {// read raw mpz_t
-         number n=(number)omAlloc0(sizeof(snumber_dummy));
-         SSI_BLOCK_CHLD;
-         mpz_inp_str (((number_dummy)n)->z, d->f_read, 32);
-         SSI_UNBLOCK_CHLD;
-         ((number_dummy)n)->s=sub_type=3; /*subtype-5*/
-         return n;
-       }
-
-     default: Werror("error in reading number: invalid subtype %d",sub_type);
-              return NULL;
-     }
-  }
-  else if (rField_is_Zp(d->r))
-  {
-    // read int
-    int dd;
-    SSI_BLOCK_CHLD;
-    fscanf(d->f_read,"%d",&dd);
-    SSI_UNBLOCK_CHLD;
-    return (number)dd;
-  }
-  else Werror("coeffs not implemented");
-  return NULL;
-}
-
-ring ssiReadRing(ssiInfo *d)
-{
-/* syntax is <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... */
-  int ch, N,i,l;
-  char **names;
-  SSI_BLOCK_CHLD;
-  fscanf(d->f_read,"%d %d ",&ch,&N);
-  SSI_UNBLOCK_CHLD;
-  names=(char**)omAlloc(N*sizeof(char*));
-  for(i=0;i<N;i++)
-  {
-    names[i]=ssiReadString(d);
-  }
-  // read the orderings:
-  int num_ord; // number of orderings
-  SSI_BLOCK_CHLD;
-  fscanf(d->f_read,"%d",&num_ord);
-  SSI_UNBLOCK_CHLD;
-  int *ord=(int *)omAlloc0((num_ord+1)*sizeof(int));
-  int *block0=(int *)omAlloc0((num_ord+1)*sizeof(int));
-  int *block1=(int *)omAlloc0((num_ord+1)*sizeof(int));
-  SSI_BLOCK_CHLD;
-  int **wvhdl=(int**)omAlloc0((num_ord+1)*sizeof(int*));
-  for(i=0;i<num_ord;i++)
-  {
-    fscanf(d->f_read,"%d %d %d",&ord[i],&block0[i],&block1[i]);
-    switch(ord[i])
-    {
-      case ringorder_a:
-      case ringorder_wp:
-      case ringorder_Wp:
-      case ringorder_ws:
-      case ringorder_Ws:
-      case ringorder_aa:
-      {
-        wvhdl[i]=(int*)omAlloc((block1[i]-block0[i]+1)*sizeof(int));
-        int ii;
-        for(ii=block0[i];ii<=block1[i];ii++)
-          fscanf(d->f_read,"%d",&(wvhdl[i][ii-block0[i]]));
-      }
-      break;
-
-      case ringorder_a64:
-      case ringorder_M:
-      case ringorder_L:
-      case ringorder_IS:
-        Werror("ring oder not implemented for ssi:%d",ord[i]);
-        break;
-
-      default: break;
-    }
-  }
-  SSI_UNBLOCK_CHLD;
-  return rDefault(ch,N,names,num_ord,ord,block0,block1,wvhdl);
-}
-
-poly ssiReadPoly(ssiInfo *D)
-{
-// < # of terms> < term1> < .....
-  int n,i,l;
-  n=ssiReadInt(D->f_read);
-  //Print("poly: terms:%d\n",n);
-  poly p;
-  int j;
-  j=0;
-  poly ret=NULL;
-  poly prev=NULL;
-  for(l=0;l<n;l++) // read n terms
-  {
-// coef,comp.exp1,..exp N
-    p=p_Init(D->r);
-    pGetCoeff(p)=ssiReadNumber(D);
-    int d;
-    SSI_BLOCK_CHLD;
-    fscanf(D->f_read,"%d",&d);
-    SSI_UNBLOCK_CHLD;
-    p_SetComp(p,d,D->r);
-    for(i=1;i<=rVar(D->r);i++)
-    {
-      SSI_BLOCK_CHLD;
-      fscanf(D->f_read,"%d",&d);
-      SSI_UNBLOCK_CHLD;
-      p_SetExp(p,i,d,D->r);
-    }
-    p_Setm(p,D->r);
-    p_Test(p,D->r);
-    if (ret==NULL) ret=p;
-    else           pNext(prev)=p;
-    prev=p;
- }
- return ret;
-}
-
-ideal ssiReadIdeal(ssiInfo *d)
-{
-  int n,i;
-  ideal I;
-  SSI_BLOCK_CHLD;
-  fscanf(d->f_read,"%d",&n);
-  SSI_UNBLOCK_CHLD;
-  I=idInit(n,1);
-  for(i=0;i<IDELEMS(I);i++) // read n terms
-  {
-    I->m [i]=ssiReadPoly(d);
-  }
-  return I;
-}
-
-matrix ssiReadMatrix(ssiInfo *d)
-{
-  int n,m,i,j;
-  SSI_BLOCK_CHLD;
-  fscanf(d->f_read,"%d %d",&m,&n);
-  SSI_UNBLOCK_CHLD;
-  matrix M=mpNew(m,n);
-  poly p;
-  for(int i=1;i<=MATROWS(M);i++)
-    for(int j=1;j<=MATCOLS(M);j++)
-    {
-      p=ssiReadPoly(d);
-      MATELEM(M,i,j)=p;
-    }
-  return M;
-}
-
-command ssiReadCommand(si_link l)
-{
-  ssiInfo *d=(ssiInfo*)l->data;
-  // syntax: <num ops> <operation> <op1> <op2> ....
-  command D=(command)omAlloc0(sizeof(*D));
-  int argc,op;
-  SSI_BLOCK_CHLD;
-  fscanf(d->f_read,"%d %d",&argc,&op);
-  SSI_UNBLOCK_CHLD;
-  D->argc=argc; D->op=op;
-  leftv v;
-  if (argc >0)
-  {
-    v=ssiRead1(l);
-    memcpy(&(D->arg1),v,sizeof(*v));
-    omFreeBin(v,sleftv_bin);
-  }
-  if (argc <4)
-  {
-    if (D->argc >1)
-    {
-      v=ssiRead1(l);
-      memcpy(&(D->arg2),v,sizeof(*v));
-      omFreeBin(v,sleftv_bin);
-    }
-    if (D->argc >2)
-    {
-      v=ssiRead1(l);
-      memcpy(&(D->arg3),v,sizeof(*v));
-      omFreeBin(v,sleftv_bin);
-    }
-  }
-  else
-  {
-    leftv prev=&(D->arg1);
-    argc--;
-    while(argc >0)
-    {
-      v=ssiRead1(l);
-      prev->next=v;
-      prev=v;
-      argc--;
-    }
-  }
-  return D;
-}
-
-procinfov ssiReadProc(ssiInfo *d)
-{
-  char *s=ssiReadString(d);
-  procinfov p=(procinfov)omAlloc0Bin(procinfo_bin);
-  p->language=LANG_SINGULAR;
-  p->libname=omStrDup("");
-  p->procname=omStrDup("");
-  p->data.s.body=s;
-  return p;
-}
-lists ssiReadList(si_link l)
-{
-  ssiInfo *d=(ssiInfo*)l->data;
-  int nr;
-  SSI_BLOCK_CHLD;
-  fscanf(d->f_read,"%d",&nr);
-  SSI_UNBLOCK_CHLD;
-  lists L=(lists)omAlloc(sizeof(*L));
-  L->Init(nr);
-
-  int i;
-  leftv v;
-  for(i=0;i<nr;i++)
-  {
-    v=ssiRead1(l);
-    memcpy(&(L->m[i]),v,sizeof(*v));
-    omFreeBin(v,sleftv_bin);
-  }
-  return L;
-}
-intvec* ssiReadIntvec(ssiInfo *d)
-{
-  int nr;
-  SSI_BLOCK_CHLD;
-  fscanf(d->f_read,"%d",&nr);
-  SSI_UNBLOCK_CHLD;
-  intvec *v=new intvec(nr);
-  SSI_BLOCK_CHLD;
-  for(int i=0;i<nr;i++)
-  {
-    fscanf(d->f_read,"%d",&((*v)[i]));
-  }
-  SSI_UNBLOCK_CHLD;
-  return v;
-}
-
-void ssiReadBlackbox(leftv res, si_link l)
-{
-  ssiInfo *d=(ssiInfo*)l->data;
-  int throwaway;
-  SSI_BLOCK_CHLD;
-  fscanf(d->f_read,"%d ",&throwaway);
-  SSI_UNBLOCK_CHLD;
-  char *name=ssiReadString(d);
-  int tok;
-  blackboxIsCmd(name,tok);
-  if (tok>MAX_TOK)
-  {
-    blackbox *b=getBlackboxStuff(tok);
-    res->rtyp=tok;
-    b->blackbox_deserialize(&b,&(res->data),l);
-  }
-  else
-  {
-    Werror("blackbox %s not found",name);
-  }
-}
-
-//**************************************************************************/
-
-BOOLEAN ssiOpen(si_link l, short flag, leftv u)
-{
-  if (l!=NULL)
-  {
-    const char *mode;
-    ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo));
-    sigprocmask(SIG_SETMASK, NULL, &ssi_sigmask);
-    sigaddset(&ssi_sigmask, SIGCHLD);
-    if (flag & SI_LINK_OPEN)
-    {
-      if (l->mode[0] != '\0' && (strcmp(l->mode, "r") == 0))
-        flag = SI_LINK_READ;
-      else flag = SI_LINK_WRITE;
-    }
-
-    if (flag == SI_LINK_READ) mode = "r";
-    else if (strcmp(l->mode, "w") == 0) mode = "w";
-    else if (strcmp(l->mode, "fork") == 0) mode = "fork";
-    else if (strcmp(l->mode, "tcp") == 0) mode = "tcp";
-    else if (strcmp(l->mode, "connect") == 0) mode = "connect";
-    else mode = "a";
-
-
-    SI_LINK_SET_OPEN_P(l, flag);
-    l->data=d;
-    omFree(l->mode);
-    l->mode = omStrDup(mode);
-
-    if (l->name[0] == '\0')
-    {
-      if (strcmp(mode,"fork")==0)
-      {
-        link_list n=(link_list)omAlloc(sizeof(link_struct));
-        n->u=u;
-        n->l=l;
-        n->next=(void *)ssiToBeClosed;
-        ssiToBeClosed=n;
-
-        int pc[2];
-        int cp[2];
-        pipe(pc);
-        pipe(cp);
-        pid_t pid=fork();
-        if (pid==0) /*fork: child*/
-        {
-          link_list hh=(link_list)ssiToBeClosed->next;
-          /* we know: l is the first entry in ssiToBeClosed-list */
-          while(hh!=NULL)
-          {
-            ssiInfo *dd=(ssiInfo*)hh->l->data;
-            fclose(dd->f_read);
-            fclose(dd->f_write);
-            if (dd->r!=NULL) rKill(dd->r);
-            omFreeSize((ADDRESS)dd,(sizeof *dd));
-            hh->l->data=NULL;
-            SI_LINK_SET_CLOSE_P(hh->l);
-            link_list nn=(link_list)hh->next;
-            omFree(hh);
-            hh=nn;
-          }
-          ssiToBeClosed->next=NULL;
-          close(pc[1]); close(cp[0]);
-          d->f_read=fdopen(pc[0],"r");
-          d->fd_read=pc[0];
-          d->f_write=fdopen(cp[1],"w");
-          d->fd_write=cp[1];
-          l->data=d;
-          omFree(l->mode);
-          l->mode = omStrDup(mode);
-          singular_in_batchmode=TRUE;
-          SI_LINK_SET_RW_OPEN_P(l);
-          //myynest=0;
-          fe_fgets_stdin=fe_fgets_dummy;
-          WerrorS_callback=WerrorS_batch;
-          if ((u!=NULL)&&(u->rtyp==IDHDL))
-          {
-            idhdl h=(idhdl)u->data;
-            h->lev=0;
-          }
-          loop
-          {
-            leftv h=ssiRead1(l); /*contains an exit.... */
-            if (feErrors != NULL && *feErrors != '\0')
-            {
-              // handle errors:
-              PrintS(feErrors); /* currently quite simple */
-              *feErrors = '\0';
-            }
-            ssiWrite(l,h);
-            h->CleanUp();
-            omFreeBin(h, sleftv_bin);
-          }
-          /* never reached*/
-        }
-        else if (pid>0) /*fork: parent*/
-        {
-          d->pid=pid;
-          close(pc[0]); close(cp[1]);
-          d->f_read=fdopen(cp[0],"r");
-          d->fd_read=cp[0];
-          d->f_write=fdopen(pc[1],"w");
-          d->fd_write=pc[1];
-          SI_LINK_SET_RW_OPEN_P(l);
-          d->send_quit_at_exit=1;
-        }
-        else
-        {
-          Werror("fork failed (%d)",errno);
-          l->data=NULL;
-          omFree(d);
-          return TRUE;
-        }
-      }
-      // ---------------------------------------------------------------------
-      else if (strcmp(mode,"tcp")==0)
-      {
-        int sockfd, newsockfd, portno, clilen;
-        struct sockaddr_in serv_addr, cli_addr;
-        int n;
-        sockfd = socket(AF_INET, SOCK_STREAM, 0);
-        if(sockfd < 0)
-        {
-          WerrorS("ERROR opening socket");
-          l->data=NULL;
-          omFree(d);
-          return TRUE;
-        }
-        memset((char *) &serv_addr,0, sizeof(serv_addr));
-        portno = 1025;
-        serv_addr.sin_family = AF_INET;
-        serv_addr.sin_addr.s_addr = INADDR_ANY;
-        do
-        {
-          portno++;
-          serv_addr.sin_port = htons(portno);
-          if(portno > 50000)
-          {
-            WerrorS("ERROR on binding (no free port available?)");
-            l->data=NULL;
-            omFree(d);
-            return TRUE;
-          }
-        }
-        while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
-        Print("waiting on port %d\n", portno);mflush();
-        listen(sockfd,5);
-        newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
-        if(newsockfd < 0)
-        {
-          WerrorS("ERROR on accept");
-          l->data=NULL;
-          omFree(d);
-          return TRUE;
-        }
-        PrintS("client accepted\n");
-        d->fd_read = newsockfd;
-        d->fd_write = newsockfd;
-        d->f_read = fdopen(newsockfd, "r");
-        d->f_write = fdopen(newsockfd, "w");
-        SI_LINK_SET_RW_OPEN_P(l);
-        close(sockfd);
-      }
-      // no ssi-Link on stdin or stdout
-      else
-      {
-        Werror("invalid mode >>%s<< for ssi",mode);
-        l->data=NULL;
-        omFree(d);
-        return TRUE;
-      }
-    }
-    // =========================================================================
-    else /*l->name=NULL*/
-    {
-      // tcp mode
-      if(strcmp(mode,"tcp")==0)
-      {
-        int sockfd, newsockfd, portno, clilen;
-        struct sockaddr_in serv_addr, cli_addr;
-        int n;
-        sockfd = socket(AF_INET, SOCK_STREAM, 0);
-        if(sockfd < 0)
-        {
-          WerrorS("ERROR opening socket");
-          l->data=NULL;
-          omFree(d);
-          return TRUE;
-        }
-        memset((char *) &serv_addr,0, sizeof(serv_addr));
-        portno = 1025;
-        serv_addr.sin_family = AF_INET;
-        serv_addr.sin_addr.s_addr = INADDR_ANY;
-        do
-        {
-          portno++;
-          serv_addr.sin_port = htons(portno);
-          if(portno > 50000)
-          {
-            WerrorS("ERROR on binding (no free port available?)");
-            l->data=NULL;
-            return TRUE;
-          }
-        }
-        while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
-        //Print("waiting on port %d\n", portno);mflush();
-        listen(sockfd,5);
-        char* cli_host = (char*)omAlloc(256);
-        char* path = (char*)omAlloc(1024);
-        int r = sscanf(l->name,"%255[^:]:%s",cli_host,path);
-        if(r == 0)
-        {
-          WerrorS("ERROR: no host specified");
-          l->data=NULL;
-          omFree(d);
-          omFree(path);
-          omFree(cli_host);
-          return TRUE;
-        }
-        else if(r == 1)
-        {
-          WarnS("program not specified, using /usr/local/bin/Singular");
-          strcpy(path,"/usr/local/bin/Singular");
-        }
-        char* ssh_command = (char*)omAlloc(256);
-        char* ser_host = (char*)omAlloc(64);
-        gethostname(ser_host,64);
-        sprintf(ssh_command,"ssh %s %s -q --batch --link=ssi --MPhost=%s --MPport=%d &",cli_host,path,ser_host,portno);
-        //Print("client on %s started:%s\n",cli_host,path);
-        omFree(path);
-        omFree(cli_host);
-        if (TEST_OPT_PROT) { Print("running >>%s<<\n",ssh_command); }
-        system(ssh_command);
-        omFree(ssh_command);
-        omFree(ser_host);
-        clilen = sizeof(cli_addr);
-        newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
-        if(newsockfd < 0)
-        {
-          WerrorS("ERROR on accept");
-          l->data=NULL;
-          omFree(d);
-          return TRUE;
-        }
-        //PrintS("client accepted\n");
-        d->fd_read = newsockfd;
-        d->fd_write = newsockfd;
-        d->f_read = fdopen(newsockfd, "r");
-        d->f_write = fdopen(newsockfd, "w");
-        SI_LINK_SET_RW_OPEN_P(l);
-        d->send_quit_at_exit=1;
-        close(sockfd);
-        fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,test,verbose);
-      }
-      // ----------------------------------------------------------------------
-      else if(strcmp(mode,"connect")==0)
-      {
-        char* host = (char*)omAlloc(256);
-        int sockfd, portno, n;
-        struct sockaddr_in serv_addr;
-        struct hostent *server;
-
-        sscanf(l->name,"%255[^:]:%d",host,&portno);
-        //Print("connect to host %s, port %d\n",host,portno);mflush();
-        if (portno!=0)
-        {
-          sockfd = socket(AF_INET, SOCK_STREAM, 0);
-          if (sockfd < 0) { WerrorS("ERROR opening socket"); return TRUE; }
-          server = gethostbyname(host);
-          if (server == NULL) {  WerrorS("ERROR, no such host");  return TRUE; }
-          memset((char *) &serv_addr, 0, sizeof(serv_addr));
-          serv_addr.sin_family = AF_INET;
-          memcpy((char *)&serv_addr.sin_addr.s_addr,
-                (char *)server->h_addr,
-                server->h_length);
-          serv_addr.sin_port = htons(portno);
-          if (connect(sockfd,(sockaddr*)&serv_addr,sizeof(serv_addr)) < 0)
-          { Werror("ERROR connecting(errno=%d)",errno); return TRUE; }
-          //PrintS("connected\n");mflush();
-          d->f_read=fdopen(sockfd,"r");
-          d->fd_read=sockfd;
-          d->f_write=fdopen(sockfd,"w");
-          d->fd_write=sockfd;
-          SI_LINK_SET_RW_OPEN_P(l);
-          d->send_quit_at_exit=1;
-          omFree(host);
-        }
-        else
-        {
-          l->data=NULL;
-          omFree(d);
-          return TRUE;
-        }
-      }
-      // ======================================================================
-      else
-      {
-        // normal link to a file
-        FILE *outfile;
-        char *filename=l->name;
-
-        if(filename[0]=='>')
-        {
-          if (filename[1]=='>')
-          {
-            filename+=2;
-            mode = "a";
-          }
-          else
-          {
-            filename++;
-            mode="w";
-          }
-        }
-        outfile=myfopen(filename,mode);
-        if (outfile!=NULL)
-        {
-          if (strcmp(l->mode,"r")==0) d->f_read = outfile;
-          else
-          {
-            d->f_write = outfile;
-            fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,test,verbose);
-          }
-        }
-        else
-        {
-          omFree(d);
-          l->data=NULL;
-          return TRUE;
-        }
-      }
-    }
-  }
-
-  return FALSE;
-}
-
-//**************************************************************************/
-BOOLEAN ssiClose(si_link l)
-{
-  if (l!=NULL)
-  {
-    ssiInfo *d = (ssiInfo *)l->data;
-    if (d!=NULL)
-    {
-      if (d->r!=NULL) rKill(d->r);
-      if ((strcmp(l->mode,"tcp")==0)
-      || (strcmp(l->mode,"fork")==0))
-      {
-        link_list hh=ssiToBeClosed;
-        if (hh!=NULL)
-        {
-          if (hh->l==l)
-          {
-             ssiToBeClosed=(link_list)hh->next;
-             omFreeSize(hh,sizeof(link_struct));
-          }
-          else while(hh!=NULL)
-          {
-            link_list hhh=(link_list)hh->next;
-            if (hhh->l==l)
-            {
-              hh->next=hhh->next;
-              omFreeSize(hhh,sizeof(link_struct));
-              break;
-            }
-            hh=(link_list)hh->next;
-          }
-        }
-        if (d->send_quit_at_exit)
-        {
-          fputs("99\n",d->f_write);fflush(d->f_write);
-        }
-      }
-      if (d->f_read!=NULL) fclose(d->f_read);
-      if (d->f_write!=NULL) fclose(d->f_write);
-      if (d->pid!=0)
-      {
-        kill(d->pid,15);
-        waitpid(d->pid,NULL,WNOHANG);
-        kill(d->pid,9); // just to be sure
-        waitpid(d->pid,NULL,0);
-      }
-      omFreeSize((ADDRESS)d,(sizeof *d));
-    }
-    l->data=NULL;
-    SI_LINK_SET_CLOSE_P(l);
-  }
-  return FALSE;
-}
-
-//**************************************************************************/
-leftv ssiRead1(si_link l)
-{
-  ssiInfo *d = (ssiInfo *)l->data;
-  d->ungetc_buf='\0';
-  leftv res=(leftv)omAlloc0(sizeof(sleftv));
-  int t=0;
-  SSI_BLOCK_CHLD;
-  fscanf(d->f_read,"%d",&t);
-  SSI_UNBLOCK_CHLD;
-  //Print("got type %d\n",t);
-  switch(t)
-  {
-    case 1:res->rtyp=INT_CMD;
-           res->data=(char *)ssiReadInt(d->f_read);
-           break;
-    case 2:res->rtyp=STRING_CMD;
-           res->data=(char *)ssiReadString(d);
-           break;
-    case 3:res->rtyp=NUMBER_CMD;
-           res->data=(char *)ssiReadNumber(d);
-           break;
-    case 4:res->rtyp=BIGINT_CMD;
-           res->data=(char *)ssiReadBigInt(d);
-           break;
-    case 15:
-    case 5:{
-             d->r=ssiReadRing(d);
-             d->r->ref++;
-             res->rtyp=RING_CMD;
-             res->data=(char*)d->r;
-             // we are in the top-level, so set the basering to d->r:
-             ssiSetCurrRing(d->r);
-             if (t==15) return ssiRead1(l);
-           }
-           break;
-    case 6:res->rtyp=POLY_CMD;
-           if (d->r==NULL) goto no_ring;
-           res->data=(char*)ssiReadPoly(d);
-           break;
-    case 7:res->rtyp=IDEAL_CMD;
-           if (d->r==NULL) goto no_ring;
-           res->data=(char*)ssiReadIdeal(d);
-           break;
-    case 8:res->rtyp=MATRIX_CMD;
-           if (d->r==NULL) goto no_ring;
-           res->data=(char*)ssiReadMatrix(d);
-           break;
-    case 9:res->rtyp=VECTOR_CMD;
-           if (d->r==NULL) goto no_ring;
-           res->data=(char*)ssiReadPoly(d);
-           break;
-    case 10:res->rtyp=MODUL_CMD;
-           if (d->r==NULL) goto no_ring;
-           res->data=(char*)ssiReadIdeal(d);
-           break;
-    case 11:
-           {
-             res->rtyp=COMMAND;
-             res->data=ssiReadCommand(l);
-             int nok=res->Eval();
-             if (nok) WerrorS("error in eval");
-             break;
-           }
-    case 12: /*DEF_CMD*/
-           {
-             res->rtyp=0;
-             res->name=(char *)ssiReadString(d);
-             int nok=res->Eval();
-             if (nok) WerrorS("error in name lookup");
-             break;
-           }
-    case 13: res->rtyp=PROC_CMD;
-             res->data=ssiReadProc(d);
-             break;
-    case 14: res->rtyp=LIST_CMD;
-             res->data=ssiReadList(l);
-             break;
-    case 16: res->rtyp=NONE; res->data=NULL;
-             break;
-    case 17: res->rtyp=INTVEC_CMD;
-             res->data=ssiReadIntvec(d);
-             break;
-    case 20: ssiReadBlackbox(res,l);
-             break;
-    // ------------
-    case 98: // version
-             {
-                int n98_v,n98_m;
-                BITSET n98_o1,n98_o2;
-                SSI_BLOCK_CHLD;
-                fscanf(d->f_read,"%d %d %u %u\n",&n98_v,&n98_m,&n98_o1,&n98_o2);
-                SSI_UNBLOCK_CHLD;
-                if ((n98_v!=SSI_VERSION) ||(n98_m!=MAX_TOK))
-                {
-                  Print("incompatible versions of ssi: %d/%d vs %d/%d",
-                                  SSI_VERSION,MAX_TOK,n98_v,n98_m);
-                }
-                #ifndef NDEBUG
-                if (TEST_OPT_DEBUG)
-                  Print("// opening ssi-%d, MAX_TOK=%d\n",n98_v,n98_m);
-                #endif
-                test=n98_o1;
-                verbose=n98_o2;
-                return ssiRead1(l);
-             }
-    case 99: ssiClose(l); m2_end(0);
-    case 0: if (feof(d->f_read))
-            {
-              ssiClose(l);
-              res->rtyp=DEF_CMD;
-              break;
-            }
-    default: Werror("not implemented (t:%d)",t);
-             omFreeSize(res,sizeof(sleftv));
-             res=NULL;
-             break;
-  }
-  return res;
-no_ring: WerrorS("no ring");
-  omFreeSize(res,sizeof(sleftv));
-  return NULL;
-}
-//**************************************************************************/
-BOOLEAN ssiWrite(si_link l, leftv data)
-{
-  if(SI_LINK_W_OPEN_P(l)==0)
-     if (slOpen(l,SI_LINK_OPEN|SI_LINK_WRITE,NULL)) return TRUE;
-  ssiInfo *d = (ssiInfo *)l->data;
-  d->level++;
-  //FILE *fich=d->f;
-  while (data!=NULL)
-  {
-    int tt=data->Typ();
-    void *dd=data->Data();
-
-    switch(tt /*data->Typ()*/)
-    {
-          case NONE/* nothing*/:fputs("16 ",d->f_write);
-                          break;
-          case STRING_CMD: fputs("2 ",d->f_write);
-                           ssiWriteString(d,(char *)dd);
-                           break;
-          case INT_CMD: fputs("1 ",d->f_write);
-                        ssiWriteInt(d,(int)(long)dd);
-                        break;
-          case BIGINT_CMD:fputs("4 ",d->f_write);
-                        ssiWriteBigInt(d,(number)dd);
-                        break;
-          case NUMBER_CMD:
-                          if (d->r!=currRing)
-                          {
-                            fputs("15 ",d->f_write);
-                            ssiWriteRing(d,currRing);
-                            if (d->level<=1) fputc('\n',d->f_write);
-                          }
-                          fputs("3 ",d->f_write);
-                          ssiWriteNumber(d,(number)dd);
-                        break;
-          case RING_CMD:fputs("5 ",d->f_write);
-                        ssiWriteRing(d,(ring)dd);
-                        break;
-          case POLY_CMD:
-          case VECTOR_CMD:
-                        if (d->r!=currRing)
-                        {
-                          fputs("15 ",d->f_write);
-                          ssiWriteRing(d,currRing);
-                          if (d->level<=1) fputc('\n',d->f_write);
-                        }
-                        if(tt==POLY_CMD) fputs("6 ",d->f_write);
-                        else             fputs("9 ",d->f_write);
-                        ssiWritePoly(d,tt,(poly)dd);
-                        break;
-          case IDEAL_CMD:
-          case MODUL_CMD:
-          case MATRIX_CMD:
-                        if (d->r!=currRing)
-                        {
-                          fputs("15 ",d->f_write);
-                          ssiWriteRing(d,currRing);
-                          if (d->level<=1) fputc('\n',d->f_write);
-                        }
-                        if(tt==IDEAL_CMD)       fputs("7 ",d->f_write);
-                        else if(tt==MATRIX_CMD) fputs("8 ",d->f_write);
-                        else                    fputs("10 ",d->f_write);
-                        ssiWriteIdeal(d,tt,(ideal)dd);
-                        break;
-          case COMMAND:
-                   fputs("11 ",d->f_write);
-                   ssiWriteCommand(l,(command)dd);
-                   break;
-          case DEF_CMD: /* not evaluated stuff in quotes */
-                   fputs("12 ",d->f_write);
-                   ssiWriteString(d,data->Name());
-                   break;
-          case PROC_CMD:
-                   fputs("13 ",d->f_write);
-                   ssiWriteProc(d,(procinfov)dd);
-                   break;
-          case LIST_CMD:
-                   fputs("14 ",d->f_write);
-                   ssiWriteList(l,(lists)dd);
-                   break;
-          case INTVEC_CMD:
-                   fputs("17 ",d->f_write);
-                   ssiWriteIntvec(d,(intvec *)dd);
-                   break;
-          default:
-            if (tt>MAX_TOK)
-            {
-              blackbox *b=getBlackboxStuff(tt);
-              fputs("20 ",d->f_write);
-              b->blackbox_serialize(b,dd,l);
-            }
-            else
-            {
-              Werror("not implemented (t:%d, rtyp:%d)",tt, data->rtyp);
-              d->level=0;
-              return TRUE;
-            }
-            break;
-    }
-    if (d->level<=1) { fputc('\n',d->f_write); fflush(d->f_write); }
-    data=data->next;
-  }
-  d->level--;
-  return FALSE;
-}
-
-si_link_extension slInitSsiExtension(si_link_extension s)
-{
-  s->Open=ssiOpen;
-  s->Close=ssiClose;
-  s->Kill=ssiClose;
-  s->Read=ssiRead1;
-  s->Read2=(slRead2Proc)NULL;
-  s->Write=ssiWrite;
-
-  s->Status=slStatusSsi;
-  s->type="ssi";
-  return s;
-}
-
-const char* slStatusSsi(si_link l, const char* request)
-{
-  ssiInfo *d=(ssiInfo*)l->data;
-  if (d==NULL) return "not open";
-  if (((strcmp(l->mode,"fork")==0)||(strcmp(l->mode,"tcp")==0))
-  && (strcmp(request, "read") == 0))
-  {
-    fd_set  mask, fdmask;
-    struct timeval wt;
-    if (d->ungetc_buf) return "ready";
-    loop
-    {
-      /* Don't block. Return socket status immediately. */
-      wt.tv_sec  = 0;
-      wt.tv_usec = 0;
-
-      FD_ZERO(&mask);
-      FD_SET(d->fd_read, &mask);
-      //Print("test fd %d\n",d->fd_read);
-    /* check with select: chars waiting: no -> not ready */
-      switch (select(d->fd_read+1, &mask, NULL, NULL, &wt))
-      {
-        case 0: /* not ready */ return "not ready";
-        case -1: /*error*/      return "error";
-        case 1: /*ready ? */    break;
-      }
-    /* yes: read 1 char*/
-    /* if \n, check again with select else ungetc(c), ready*/
-      int c=fgetc(d->f_read);
-      //Print("try c=%d\n",c);
-      if (c== -1) return "eof"; /* eof or error */
-      else if (isdigit(c))
-      { ungetc(c,d->f_read); d->ungetc_buf='\1'; return "ready"; }
-      else if (c>' ')
-      {
-        Werror("unknown char in ssiLink(%d)",c);
-        return "error";
-      }
-      /* else: next char */
-    }
-  }
-  else if (strcmp(request, "read") == 0)
-  {
-    if (SI_LINK_R_OPEN_P(l) && (!feof(d->f_read))) return "ready";
-    else return "not ready";
-  }
-  else if (strcmp(request, "write") == 0)
-  {
-    if (SI_LINK_W_OPEN_P(l)) return "ready";
-    else return "not ready";
-  }
-  else return "unknown status request";
-}
-
-int slStatusSsiL(lists L, int timeout)
-{
-// input: L: a list with links of type
-//           ssi-connect, ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch.
-//           Note: Not every entry in L must be set.
-//        timeout: timeout for select in micro-seconds
-//           or -1 for infinity
-//           or 0 for polling
-// returns: ERROR (via Werror): L has wrong elements or link not open
-//           -2: select returns an error
-//           -1: the read state of all links is eof
-//           0:  timeout (or polling): none ready,
-//           i>0: (at least) L[i] is ready
-  si_link l;
-  ssiInfo *d;
-  int d_fd;
-  fd_set  mask, fdmask;
-  FD_ZERO(&fdmask);
-  FD_ZERO(&mask);
-  int max_fd=0; /* 1 + max fd in fd_set */
-
-  /* timeout */
-  #ifdef HAVE_PSELECT
-  struct timespec wt;
-  struct timespec *wt_ptr=&wt;
-  #else
-  struct timeval wt;
-  struct timeval *wt_ptr=&wt;
-  #endif
-  int startingtime = getRTimer()/TIMER_RESOLUTION;  // in seconds
-  if (timeout== -1)
-  {
-    wt_ptr=NULL;
-  }
-  else
-  {
-    wt.tv_sec  = timeout / 1000000;
-  #ifdef HAVE_PSELECT
-    wt.tv_nsec = 1000 * (timeout % 1000000);
-  #else
-    wt.tv_usec = timeout % 1000000;
-  #endif
-  }
-
-  /* signal mask for pselect() */
-  sigset_t sigmask;
-  if(sigprocmask(SIG_SETMASK, NULL, &sigmask) < 0)
-  {
-    WerrorS("error in sigprocmask()");
-    return -2;
-  }
-  if(sigaddset(&sigmask, SIGCHLD) < 0)
-  {
-    WerrorS("error in sigaddset()");
-    return -2;
-  }
-
-  /* auxiliary variables */
-  int i;
-  int j;
-  int k;
-  int s;
-  char fdmaskempty;
-
-  /* check the links and fill in fdmask */
-  /* check ssi links for ungetc_buf */
-  for(i=L->nr; i>=0; i--)
-  {
-    if (L->m[i].Typ()!=DEF_CMD)
-    {
-      if (L->m[i].Typ()!=LINK_CMD)
-      { WerrorS("all elements must be of type link"); return -2;}
-      l=(si_link)L->m[i].Data();
-      if(SI_LINK_OPEN_P(l)==0)
-      { WerrorS("all links must be open"); return -2;}
-      if (((strcmp(l->m->type,"ssi")!=0) && (strcmp(l->m->type,"MPtcp")!=0))
-      || ((strcmp(l->mode,"fork")!=0) && (strcmp(l->mode,"tcp")!=0)
-        && (strcmp(l->mode,"launch")!=0) && (strcmp(l->mode,"connect")!=0)))
-      {
-        WerrorS("all links must be of type ssi:fork, ssi:tcp, ssi:connect,");
-        WerrorS(" MPtcp:fork or MPtcp:launch");
-        return -2;
-      }
-      d=(ssiInfo*)l->data;
-      d_fd=d->fd_read;
-      if (d->ungetc_buf=='\0')
-      {
-        FD_SET(d_fd, &fdmask);
-        if (d_fd > max_fd) max_fd=d_fd;
-      }
-      else
-        return i+1;
-    }
-  }
-  max_fd++;
-
-do_select:
-  /* copy fdmask to mask */
-  FD_ZERO(&mask);
-  for(k = 0; k < max_fd; k++)
-  {
-    if(FD_ISSET(k, &fdmask))
-    {
-      FD_SET(k, &mask);
-    }
-  }
-
-  /* check with select: chars waiting: no -> not ready */
-  #ifdef HAVE_PSELECT
-  s = pselect(max_fd, &mask, NULL, NULL, wt_ptr, &sigmask);
-  #else
-  SSI_BLOCK_CHLD;
-  s = select(max_fd, &mask, NULL, NULL, wt_ptr);
-  SSI_UNBLOCK_CHLD;
-  #endif
-
-  if (s==-1)
-  {
-    WerrorS("error in select call");
-    return -2; /*error*/
-  }
-  if (s==0)
-  {
-    return 0; /*poll: not ready */
-  }
-  else /* s>0, at least one ready  (the number of fd which are ready is s)*/
-  {
-    j=0;
-    while (j<=max_fd) { if (FD_ISSET(j,&mask)) break; j++; }
-    for(i=L->nr; i>=0; i--)
-    {
-      if (L->m[i].rtyp==LINK_CMD)
-      {
-        l=(si_link)L->m[i].Data();
-        d=(ssiInfo*)l->data;
-        d_fd=d->fd_read;
-        if(j==d_fd) break;
-      }
-    }
-    // only ssi links:
-    loop
-    {
-      /* yes: read 1 char*/
-      /* if \n, check again with select else ungetc(c), ready*/
-      /* setting: d: current ssiInfo, j current fd, i current entry in L*/
-      int c=fgetc(d->f_read);
-      //Print("try c=%d\n",c);
-      if (c== -1) /* eof */
-      {
-        FD_CLR(j,&fdmask);
-        fdmaskempty = 1;
-        for(k = 0; k < max_fd; k++)
-        {
-          if(FD_ISSET(k, &fdmask))
-          {
-            fdmaskempty = 0;
-            break;
-          }
-        }
-        if(fdmaskempty)
-        {
-          return -1;
-        }
-        if(timeout != -1)
-        {
-          timeout = si_max(0,
-               timeout - 1000000*(getRTimer()/TIMER_RESOLUTION - startingtime));
-          wt.tv_sec  = timeout / 1000000;
-          #ifdef HAVE_PSELECT
-          wt.tv_nsec = 1000 * (timeout % 1000000);
-          #else
-          wt.tv_usec = (timeout % 1000000);
-          #endif
-        }
-        goto do_select;
-      }
-
-      else if (isdigit(c))
-      { ungetc(c,d->f_read); d->ungetc_buf='\1'; return i+1; }
-      else if (c>' ')
-      {
-        Werror("unknown char in ssiLink(%d)",c);
-        return -2;
-      }
-      /* else: next char */
-    }
-  }
-}
-
-int ssiBatch(const char *host, const char * port)
-/* return 0 on success, >0 else*/
-{
-  si_link l=(si_link) omAlloc0Bin(sip_link_bin);
-  char *buf=(char*)omAlloc(256);
-  sprintf(buf,"ssi:connect %s:%s",host,port);
-  slInit(l, buf);
-  if (slOpen(l,SI_LINK_OPEN,NULL)) return 1;
-  SI_LINK_SET_RW_OPEN_P(l);
-
-  idhdl id = enterid(omStrDup("link_ll"), 0, LINK_CMD, &IDROOT, FALSE);
-  IDLINK(id) = l;
-
-  loop
-  {
-    leftv h=ssiRead1(l); /*contains an exit.... */
-    if (feErrors != NULL && *feErrors != '\0')
-    {
-      // handle errors:
-      PrintS(feErrors); /* currently quite simple */
-      *feErrors = '\0';
-    }
-    ssiWrite(l,h);
-    h->CleanUp();
-    omFreeBin(h, sleftv_bin);
-  }
-  /* never reached*/
-  exit(0);
-}
-
-// ----------------------------------------------------------------
-// format
-// 1 int %d
-// 2 string <len> %s
-// 3 number
-// 4 bigint 4 %d or 3 <mpz_t>
-// 5 ring
-// 6 poly
-// 7 ideal
-// 8 matrix
-// 9 vector
-// 10 module
-// 11 command
-// 12 def <len> %s
-// 13 proc <len> %s
-// 14 list %d <elem1> ....
-// 15 setring .......
-// 16 nothing
-// 17 intvec <len> ...
-//
-// 20 blackbox <name> ...
-//
-// 98: verify version: <ssi-version> <MAX_TOK> <OPT1> <OPT2>
-// 99: quit Singular
Index: ngular/ssiLink.h
===================================================================
--- Singular/ssiLink.h	(revision 4fb3a73a9ab769b9cdb2ec0db33cdbf9e88bfedd)
+++ 	(revision )
@@ -1,20 +1,0 @@
-/****************************************
- * Computer Algebra System SINGULAR     *
- ****************************************/
-/***************************************************************
- * File:    ssiLink.h
- *  Purpose: declaration of sl_link routines for ssi
- ***************************************************************/
- #ifndef SSILINK_H
- #define SSILINK_H
-BOOLEAN ssiOpen(si_link l, short flag, leftv u);
-BOOLEAN ssiWrite(si_link l, leftv v);
-leftv ssiRead1(si_link l);
-leftv ssiRead2(si_link l, leftv key);
-BOOLEAN ssiClose(si_link l);
-const char* slStatusSsi(si_link l, const char* request);
-si_link_extension slInitSsiExtension(si_link_extension s);
-int ssiBatch(const char *host, const char * port);
-/* return 0 on success, >0 else*/
-#endif
-
Index: Singular/tesths.cc
===================================================================
--- Singular/tesths.cc	(revision 4fb3a73a9ab769b9cdb2ec0db33cdbf9e88bfedd)
+++ Singular/tesths.cc	(revision 47367fd534cd6fb5e9d3a999aa476df1d6ee78c9)
@@ -37,5 +37,5 @@
 #include "version.h"
 #include "slInit.h"
-#include "ssiLink.h"
+#include  <Singular/links/ssiLink.h>
 #include "bigintm.h"
 #include "mmalloc.h"
