Index: kernel/kutil.cc
===================================================================
--- kernel/kutil.cc	(revision 83be980908d4dc3e33ce00c36b4e4013e3251a00)
+++ kernel/kutil.cc	(revision 0758b5a070556dd402b297144aae88721940fd10)
@@ -1745,5 +1745,5 @@
   if (strat->interred_flag) return;
 
-  int      l,j,compare;
+  int      l;
   poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
               // the corresponding signatures for criteria checks
@@ -1845,5 +1845,5 @@
   // store from which element this pair comes from for further tests
   Lp.from = strat->sl+1;    
-  if(sigCmp==pOrdSgn)
+  if(sigCmp==currRing->OrdSgn)
   {
     // pSig > sSig
@@ -1886,5 +1886,5 @@
              // generalized prod-crit for lie-type
              strat->cp++;
-             Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i]);
+             Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
          }
          else
@@ -4470,5 +4470,5 @@
 {
 if (length<0) return 0;
-if (pLmCmp(set[length].sig,p->sig)== pOrdSgn)
+if (pLmCmp(set[length].sig,p->sig)== currRing->OrdSgn)
   return length+1;
 
@@ -4480,9 +4480,9 @@
   if (an >= en-1)
   {
-    if (pLmCmp(set[an].sig,p->sig) == pOrdSgn) return en;
+    if (pLmCmp(set[an].sig,p->sig) == currRing->OrdSgn) return en;
     return an;
   }
   i=(an+en) / 2;
-  if (pLmCmp(set[i].sig,p->sig) == pOrdSgn) an=i;
+  if (pLmCmp(set[i].sig,p->sig) == currRing->OrdSgn) an=i;
   else                                      en=i;
   /*aend. fuer lazy == in !=- machen */
@@ -4912,4 +4912,209 @@
 }
 
+/*
+ * SYZYGY CRITERION for signature-based standard basis algorithms
+ */
+BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
+{
+//#if 1
+#ifdef DEBUGF5
+  Print("syzygy criterion checks:  ");
+  pWrite(sig);
+#endif
+  for (int k=0; k<strat->syzl; k++)
+  {
+//#if 1
+#ifdef DEBUGF5
+    Print("checking with: %d --  ",k);
+    pWrite(pHead(strat->syz[k]));
+#endif
+    if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing))
+    {
+//#if 1
+#ifdef DEBUGF5
+      printf("DELETE!\n");
+#endif
+      return TRUE;
+    }
+  }
+  return FALSE;
+}
+
+/*
+ * SYZYGY CRITERION for signature-based standard basis algorithms
+ */
+BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
+{
+//#if 1
+#ifdef DEBUGF5
+  Print("syzygy criterion checks:  ");
+  pWrite(sig);
+#endif
+  int comp = p_GetComp(sig, currRing);
+  int min, max;
+  if (comp<=1)
+    return FALSE;
+  else
+  {
+    min = strat->syzIdx[comp-2];
+    //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-2],comp-2);
+    //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-1],comp-1);
+    //printf("SYZIDX %d/%d\n",strat->syzIdx[comp],comp);
+    if (comp == strat->currIdx)
+    {
+      max = strat->syzl;
+    }
+    else
+    {
+      max = strat->syzIdx[comp-1];
+    }
+    for (int k=min; k<max; k++)
+    {
+#ifdef DEBUGF5
+      printf("COMP %d/%d - MIN %d - MAX %d - SYZL %ld\n",comp,strat->currIdx,min,max,strat->syzl);
+      Print("checking with: %d --  ",k);
+      pWrite(pHead(strat->syz[k]));
+#endif
+      if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing))
+        return TRUE;
+    }
+    return FALSE;
+  }
+}
+
+/*
+ * REWRITTEN CRITERION for signature-based standard basis algorithms
+ */
+BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, kStrategy strat, int start=0)
+{
+  //printf("Faugere Rewritten Criterion\n");
+//#if 1
+#ifdef DEBUGF5
+  printf("rewritten criterion checks:  ");
+  pWrite(sig);
+#endif
+  //for(int k = start; k<strat->sl+1; k++)
+  for(int k = strat->sl; k>start; k--)
+  {
+//#if 1
+#ifdef DEBUGF5
+    Print("checking with:  ");
+    pWrite(strat->sig[k]);
+    pWrite(pHead(strat->S[k]));
+#endif
+    if (p_LmShortDivisibleBy(strat->sig[k], strat->sevSig[k], sig, not_sevSig, currRing))
+    //if (p_LmEqual(strat->sig[k], sig, currRing))
+    {
+//#if 1
+#ifdef DEBUGF5
+      printf("DELETE!\n");
+#endif
+      return TRUE;
+    }
+  }
+#ifdef DEBUGF5
+  Print("ALL ELEMENTS OF S\n----------------------------------------\n");
+  for(int kk = 0; kk<strat->sl+1; kk++)
+  {
+    pWrite(pHead(strat->S[kk]));
+  }
+  Print("------------------------------\n");
+#endif
+  return FALSE;
+}
+
+/*
+ * REWRITTEN CRITERION for signature-based standard basis algorithms
+ ***************************************************************************
+ * TODO:This should become the version of Arri/Perry resp. Bjarke/Stillman *
+ ***************************************************************************
+ */
+
+// real implementation of arri's rewritten criterion, only called once in
+// kstd2.cc, right before starting reduction
+// IDEA:  Arri says that it is enough to consider 1 polynomial for each unique
+//        signature appearing during the computations. Thus we first of all go
+//        through strat->L and delete all other pairs of the same signature,
+//        keeping only the one with least possible leading monomial. After this
+//        we check if we really need to compute this critical pair at all: There
+//        can be elements already in strat->S whose signatures divide the
+//        signature of the critical pair in question and whose multiplied
+//        leading monomials are smaller than the leading monomial of the
+//        critical pair. In this situation we can discard the critical pair
+//        completely.
+BOOLEAN arriRewCriterion(poly sig, unsigned long not_sevSig, kStrategy strat, int start=0)
+{
+  //printf("Arri Rewritten Criterion\n");
+  while (strat->Ll > 0 && pLmEqual(strat->L[strat->Ll].sig,strat->P.sig))
+  {
+    // deletes the short spoly
+#ifdef HAVE_RINGS
+    if (rField_is_Ring(currRing))
+      pLmDelete(strat->L[strat->Ll].p);
+    else
+#endif
+      pLmFree(strat->L[strat->Ll].p);
+
+    // TODO: needs some masking
+    // TODO: masking needs to vanish once the signature
+    //       sutff is completely implemented
+    strat->L[strat->Ll].p = NULL;
+    poly m1 = NULL, m2 = NULL;
+
+    // check that spoly creation is ok
+    while (strat->tailRing != currRing &&
+          !kCheckSpolyCreation(&(strat->L[strat->Ll]), strat, m1, m2))
+    {
+      assume(m1 == NULL && m2 == NULL);
+      // if not, change to a ring where exponents are at least
+      // large enough
+      if (!kStratChangeTailRing(strat))
+      {
+        WerrorS("OVERFLOW...");
+        break;
+      }
+    }
+    // create the real one
+    ksCreateSpoly(&(strat->L[strat->Ll]), NULL, strat->use_buckets,
+                  strat->tailRing, m1, m2, strat->R);
+    if (strat->P.GetLmCurrRing() == NULL)
+    {
+      deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
+    }
+    if (strat->L[strat->Ll].GetLmCurrRing() == NULL)
+    {
+      strat->P.Delete();
+      strat->P = strat->L[strat->Ll];
+      strat->Ll--;
+    }
+
+    if (strat->P.GetLmCurrRing() != NULL && strat->L[strat->Ll].GetLmCurrRing() != NULL)
+    {
+      if (pLmCmp(strat->P.GetLmCurrRing(),strat->L[strat->Ll].GetLmCurrRing()) == -1)
+      {
+        deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
+      }
+      else
+      {
+        strat->P.Delete();
+        strat->P = strat->L[strat->Ll];
+        strat->Ll--;
+      }
+    }
+  }
+  for (int ii=strat->sl; ii>-1; ii--)
+  {
+    if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], strat->P.sig, ~strat->P.sevSig, currRing))
+    {
+      if (!(pLmCmp(ppMult_mm(strat->P.sig,pHead(strat->S[ii])),ppMult_mm(strat->sig[ii],strat->P.GetLmCurrRing())) == 1))
+      {
+        strat->P.Delete();
+        return TRUE;
+      }
+    }
+  }
+  return FALSE;
+}
+
 /***************************************************************
  *
@@ -5604,5 +5809,5 @@
         LObject h;
         h.p = pCopy(Q->m[i]);
-        if (pOrdSgn==-1)
+        if (currRing->OrdSgn==-1)
         {
           deleteHC(&h,strat);
@@ -5659,5 +5864,5 @@
       if (h.p!=NULL)
       {
-        if (pOrdSgn==-1)
+        if (currRing->OrdSgn==-1)
         {
           cancelunit(&h);  /*- tries to cancel a unit -*/
@@ -5717,5 +5922,5 @@
   if ((strat->Ll>=0)
 #ifdef HAVE_RINGS
-       && nIsUnit(pGetCoeff(strat->L[strat->Ll].p))
+       && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
 #endif
        && pIsConstant(strat->L[strat->Ll].p))
@@ -5878,4 +6083,150 @@
   strat->S=strat->Shdl->m;
 
+  /*- put polys into S -*/
+  if (Q!=NULL)
+  {
+    strat->fromQ=initec(i);
+    memset(strat->fromQ,0,i*sizeof(int));
+    for (i=0; i<IDELEMS(Q); i++)
+    {
+      if (Q->m[i]!=NULL)
+      {
+        LObject h;
+        h.p = pCopy(Q->m[i]);
+        //if (TEST_OPT_INTSTRATEGY)
+        //{
+        //  //pContent(h.p);
+        //  h.pCleardenom(); // also does a pContent
+        //}
+        //else
+        //{
+        //  h.pNorm();
+        //}
+        if (currRing->OrdSgn==-1)
+        {
+          deleteHC(&h,strat);
+        }
+        if (h.p!=NULL)
+        {
+          strat->initEcart(&h);
+          if (strat->sl==-1)
+            pos =0;
+          else
+          {
+            pos = posInS(strat,strat->sl,h.p,h.ecart);
+          }
+          h.sev = pGetShortExpVector(h.p);
+          strat->enterS(h,pos,strat, strat->tl+1);
+          enterT(h, strat);
+          strat->fromQ[pos]=1;
+        }
+      }
+    }
+  }
+  /*- put polys into S -*/
+  for (i=0; i<IDELEMS(F); i++)
+  {
+    if (F->m[i]!=NULL)
+    {
+      LObject h;
+      h.p = pCopy(F->m[i]);
+      if (currRing->OrdSgn==-1)
+      {
+        deleteHC(&h,strat);
+      }
+      else
+      {
+        h.p=redtailBba(h.p,strat->sl,strat);
+      }
+      if (h.p!=NULL)
+      {
+        strat->initEcart(&h);
+        if (strat->sl==-1)
+          pos =0;
+        else
+          pos = posInS(strat,strat->sl,h.p,h.ecart);
+        h.sev = pGetShortExpVector(h.p);
+        strat->enterS(h,pos,strat, strat->tl+1);
+        enterT(h,strat);
+      }
+    }
+  }
+  for (i=0; i<IDELEMS(P); i++)
+  {
+    if (P->m[i]!=NULL)
+    {
+      LObject h;
+      h.p=pCopy(P->m[i]);
+      if (TEST_OPT_INTSTRATEGY)
+      {
+        h.pCleardenom();
+      }
+      else
+      {
+        h.pNorm();
+      }
+      if(strat->sl>=0)
+      {
+        if (currRing->OrdSgn==1)
+        {
+          h.p=redBba(h.p,strat->sl,strat);
+          if (h.p!=NULL)
+          {
+            h.p=redtailBba(h.p,strat->sl,strat);
+          }
+        }
+        else
+        {
+          h.p=redMora(h.p,strat->sl,strat);
+        }
+        if(h.p!=NULL)
+        {
+          strat->initEcart(&h);
+          if (TEST_OPT_INTSTRATEGY)
+          {
+            h.pCleardenom();
+          }
+          else
+          {
+            h.is_normalized = 0;
+            h.pNorm();
+          }
+          h.sev = pGetShortExpVector(h.p);
+          h.SetpFDeg();
+          pos = posInS(strat,strat->sl,h.p,h.ecart);
+          enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
+          strat->enterS(h,pos,strat, strat->tl+1);
+          enterT(h,strat);
+        }
+      }
+      else
+      {
+        h.sev = pGetShortExpVector(h.p);
+        strat->initEcart(&h);
+        strat->enterS(h,0,strat, strat->tl+1);
+        enterT(h,strat);
+      }
+    }
+  }
+}
+/*2
+*construct the set s from F and {P}
+*/
+
+void initSSpecialSba (ideal F, ideal Q, ideal P,kStrategy strat)
+{
+  int   i,pos;
+
+  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
+  else i=setmaxT;
+  i=((i+IDELEMS(F)+IDELEMS(P)+15)/16)*16;
+  strat->fromS=initec(i);
+  strat->sevS=initsevS(i);
+  strat->sevSig=initsevS(i);
+  strat->S_2_R=initS_2_R(i);
+  strat->fromQ=NULL;
+  strat->Shdl=idInit(i,F->rank);
+  strat->S=strat->Shdl->m;
+  strat->sig=(poly *)omAlloc0(i*sizeof(poly));
   /*- put polys into S -*/
   if (Q!=NULL)
@@ -7081,4 +7432,195 @@
 }
 
+void initSbaPos (kStrategy strat)
+{
+  if (currRing->OrdSgn==1)
+  {
+    if (strat->honey)
+    {
+      strat->posInL = posInL15;
+      // ok -- here is the deal: from my experiments for Singular-2-0
+      // I conclude that that posInT_EcartpLength is the best of
+      // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
+      // see the table at the end of this file
+      if (TEST_OPT_OLDSTD)
+        strat->posInT = posInT15;
+      else
+        strat->posInT = posInT_EcartpLength;
+    }
+    else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
+    {
+      strat->posInL = posInL11;
+      strat->posInT = posInT11;
+    }
+    else if (TEST_OPT_INTSTRATEGY)
+    {
+      strat->posInL = posInL11;
+      strat->posInT = posInT11;
+    }
+    else
+    {
+      strat->posInL = posInL0;
+      strat->posInT = posInT0;
+    }
+    //if (strat->minim>0) strat->posInL =posInLSpecial;
+    if (strat->homog)
+    {
+       strat->posInL = posInL110;
+       strat->posInT = posInT110;
+    }
+  }
+  else
+  {
+    if (strat->homog)
+    {
+      strat->posInL = posInL11;
+      strat->posInT = posInT11;
+    }
+    else
+    {
+      if ((currRing->order[0]==ringorder_c)
+      ||(currRing->order[0]==ringorder_C))
+      {
+        strat->posInL = posInL17_c;
+        strat->posInT = posInT17_c;
+      }
+      else
+      {
+        strat->posInL = posInL17;
+        strat->posInT = posInT17;
+      }
+    }
+  }
+  if (strat->minim>0) strat->posInL =posInLSpecial;
+  // for further tests only
+  if ((BTEST1(11)) || (BTEST1(12)))
+    strat->posInL = posInL11;
+  else if ((BTEST1(13)) || (BTEST1(14)))
+    strat->posInL = posInL13;
+  else if ((BTEST1(15)) || (BTEST1(16)))
+    strat->posInL = posInL15;
+  else if ((BTEST1(17)) || (BTEST1(18)))
+    strat->posInL = posInL17;
+  if (BTEST1(11))
+    strat->posInT = posInT11;
+  else if (BTEST1(13))
+    strat->posInT = posInT13;
+  else if (BTEST1(15))
+    strat->posInT = posInT15;
+  else if ((BTEST1(17)))
+    strat->posInT = posInT17;
+  else if ((BTEST1(19)))
+    strat->posInT = posInT19;
+  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
+    strat->posInT = posInT1;
+#ifdef HAVE_RINGS
+  if (rField_is_Ring(currRing))
+  {
+    strat->posInL = posInL11;
+    strat->posInT = posInT11;
+  }
+#endif
+  strat->posInLDependsOnLength = FALSE;
+  strat->posInLSba  = posInLSig;
+  //strat->posInL     = posInLSig;
+  strat->posInL     = posInLF5C;
+  //strat->posInT     = posInTSig;
+}
+
+void initSbaBuchMora (ideal F,ideal Q,kStrategy strat)
+{
+  strat->interpt = BTEST1(OPT_INTERRUPT);
+  strat->kHEdge=NULL;
+  if (currRing->OrdSgn==1) strat->kHEdgeFound=FALSE;
+  /*- creating temp data structures------------------- -*/
+  strat->cp = 0;
+  strat->c3 = 0;
+  strat->tail = pInit();
+  /*- set s -*/
+  strat->sl = -1;
+  /*- set ps -*/
+  strat->syzl = -1;
+  /*- set L -*/
+  strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
+  strat->Ll = -1;
+  strat->L = initL(((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc);
+  /*- set B -*/
+  strat->Bmax = setmaxL;
+  strat->Bl = -1;
+  strat->B = initL();
+  /*- set T -*/
+  strat->tl = -1;
+  strat->tmax = setmaxT;
+  strat->T = initT();
+  strat->R = initR();
+  strat->sevT = initsevT();
+  /*- init local data struct.---------------------------------------- -*/
+  strat->P.ecart=0;
+  strat->P.length=0;
+  if (currRing->OrdSgn==-1)
+  {
+    if (strat->kHEdge!=NULL) pSetComp(strat->kHEdge, strat->ak);
+    if (strat->kNoether!=NULL) pSetComp(strat->kNoetherTail(), strat->ak);
+  }
+  if(TEST_OPT_SB_1)
+  {
+    int i;
+    ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
+    for (i=strat->newIdeal;i<IDELEMS(F);i++)
+    {
+      P->m[i-strat->newIdeal] = F->m[i];
+      F->m[i] = NULL;
+    }
+    initSSpecialSba(F,Q,P,strat);
+    for (i=strat->newIdeal;i<IDELEMS(F);i++)
+    {
+      F->m[i] = P->m[i-strat->newIdeal];
+      P->m[i-strat->newIdeal] = NULL;
+    }
+    idDelete(&P);
+  }
+  else
+  {
+    /*Shdl=*/initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
+    // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
+  }
+  strat->fromT = FALSE;
+  strat->noTailReduction = !TEST_OPT_REDTAIL;
+  if (!TEST_OPT_SB_1)
+  {
+    updateS(TRUE,strat);
+  }
+  if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
+  strat->fromQ=NULL;
+}
+
+void exitSba (kStrategy strat)
+{
+  /*- release temp data -*/
+  cleanT(strat);
+  omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
+  omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
+  omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
+  omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
+  omFreeSize(strat->fromS,IDELEMS(strat->Shdl)*sizeof(int));
+  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
+  omFreeSize((ADDRESS)strat->sevSig,IDELEMS(strat->Shdl)*sizeof(unsigned long));
+  omFreeSize((ADDRESS)strat->syz,(strat->syzmax)*sizeof(poly));
+  omFreeSize((ADDRESS)strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
+  if (strat->incremental)
+  {
+    omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
+  }
+  omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
+  /*- set L: should be empty -*/
+  omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
+  /*- set B: should be empty -*/
+  omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
+  /*- set sig: no need for the signatures anymore -*/
+  omFreeSize(strat->sig,IDELEMS(strat->Shdl)*sizeof(poly));
+  pLmDelete(&strat->tail);
+  strat->syzComp=0;
+}
+
 /*2
 * in the case of a standardbase of a module over a qring:
@@ -7547,4 +8089,156 @@
 
   kStratChangeTailRing(strat, NULL, NULL, e);
+}
+
+ring sbaRing (kStrategy strat, const ring r, BOOLEAN complete, int sgn)
+{
+  int n = rBlocks(r); // Including trailing zero!
+  // if incremental => use (C,monomial order from r)
+  if (strat->incremental)
+  {
+    if (r->order[0] == ringorder_C || r->order[0] == ringorder_c)
+    {
+      return r;
+    }
+      ring res = rCopy0(r, FALSE, TRUE);
+      for (int i=1; i<n-1; i++)
+      {
+        res->order[i] = res->order[i-1];
+        res->block0[i] = res->block0[i-1];
+        res->block1[i] = res->block1[i-1];
+        res->wvhdl[i] = res->wvhdl[i-1];
+      }
+
+    // new 1st block
+    res->order[0]   = ringorder_C; // Prefix
+    res->block0[0]  = 1;
+    res->block1[0]  = res->N;
+    //res->wvhdl[j]   = NULL;
+    // res->order [j] = 0; // The End!
+    rComplete(res, 1);
+#ifdef HAVE_PLURAL
+    if (rIsPluralRing(r))
+    {
+      if ( nc_rComplete(r, res, false) ) // no qideal!
+      {
+#ifndef NDEBUG
+        WarnS("error in nc_rComplete");
+#endif
+        // cleanup?
+
+        //      rDelete(res);
+        //      return r;
+
+        // just go on..
+      }
+    }
+#endif
+  strat->tailRing = res;
+  return (res);
+  }
+  // not incremental => use Schreyer order
+  // this is done by a trick when initializing the signatures
+  // in initSLSba():
+  // Instead of using the signature 1e_i for F->m[i], we start
+  // with the signature LM(F->m[i])e_i for F->m[i]. Doing this we get a 
+  // Schreyer order w.r.t. the underlying monomial order.
+  // => we do not need to change the underlying polynomial ring at all!
+
+
+  /*
+  else
+  {
+    ring res = rCopy0(r, FALSE, FALSE);
+    // Create 2 more blocks for prefix/suffix:
+    res->order=(int *)omAlloc0((n+2)*sizeof(int)); // 0  ..  n+1
+    res->block0=(int *)omAlloc0((n+2)*sizeof(int));
+    res->block1=(int *)omAlloc0((n+2)*sizeof(int));
+    int ** wvhdl =(int **)omAlloc0((n+2)*sizeof(int**));
+
+    // Encapsulate all existing blocks between induced Schreyer ordering markers: prefix and suffix!
+    // Note that prefix and suffix have the same ringorder marker and only differ in block[] parameters!
+
+    // new 1st block
+    int j = 0;
+    res->order[j] = ringorder_IS; // Prefix
+    res->block0[j] = res->block1[j] = 0;
+    // wvhdl[j] = NULL;
+    j++;
+
+    for(int i = 0; (i < n) && (r->order[i] != 0); i++, j++) // i = [0 .. n-1] <- non-zero old blocks
+    {
+      res->order [j] = r->order [i];
+      res->block0[j] = r->block0[i];
+      res->block1[j] = r->block1[i];
+
+      if (r->wvhdl[i] != NULL)
+      {
+        wvhdl[j] = (int*) omMemDup(r->wvhdl[i]);
+      } // else wvhdl[j] = NULL;
+    }
+
+    // new last block
+    res->order [j] = ringorder_IS; // Suffix
+    res->block0[j] = res->block1[j] = sgn; // Sign of v[o]: 1 for C, -1 for c
+    // wvhdl[j] = NULL;
+    j++;
+
+    // res->order [j] = 0; // The End!
+    res->wvhdl = wvhdl;
+
+    // j == the last zero block now!
+    assume(j == (n+1));
+    assume(res->order[0]==ringorder_IS);
+    assume(res->order[j-1]==ringorder_IS);
+    assume(res->order[j]==0);
+
+    if (complete)
+    {
+      rComplete(res, 1);
+
+#ifdef HAVE_PLURAL
+      if (rIsPluralRing(r))
+      {
+        if ( nc_rComplete(r, res, false) ) // no qideal!
+        {
+        }
+      }
+      assume(rIsPluralRing(r) == rIsPluralRing(res));
+#endif
+
+
+#ifdef HAVE_PLURAL
+      ring old_ring = r;
+
+#endif
+
+      if (r->qideal!=NULL)
+      {
+        res->qideal= idrCopyR_NoSort(r->qideal, r, res);
+
+        assume(idRankFreeModule(res->qideal, res) == 0);
+
+#ifdef HAVE_PLURAL
+        if( rIsPluralRing(res) )
+          if( nc_SetupQuotient(res, r, true) )
+          {
+            //          WarnS("error in nc_SetupQuotient"); // cleanup?      rDelete(res);       return r;  // just go on...?
+          }
+
+#endif
+        assume(idRankFreeModule(res->qideal, res) == 0);
+      }
+
+#ifdef HAVE_PLURAL
+      assume((res->qideal==NULL) == (old_ring->qideal==NULL));
+      assume(rIsPluralRing(res) == rIsPluralRing(old_ring));
+      assume(rIsSCA(res) == rIsSCA(old_ring));
+      assume(ncRingType(res) == ncRingType(old_ring));
+#endif
+    }
+    strat->tailRing = res;
+    return res;
+  }
+  */
 }
 
