ssiLink.cc
Go to the documentation of this file.
1 /****************************************
2  * Computer Algebra System SINGULAR *
3  ****************************************/
4 /***************************************************************
5  * File: ssiLink.h
6  * Purpose: declaration of sl_link routines for ssi
7  ***************************************************************/
8 #define TRANSEXT_PRIVATES 1 /* allow access to transext internals */
9 
10 #include <kernel/mod2.h>
11 
12 #include <omalloc/omalloc.h>
13 
14 #include <misc/intvec.h>
15 #include <misc/options.h>
16 
17 #include <reporter/si_signals.h>
18 #include <reporter/s_buff.h>
19 
20 #include <coeffs/bigintmat.h>
21 #include <coeffs/longrat.h>
22 
23 #include <polys/monomials/ring.h>
26 #include <polys/simpleideals.h>
27 #include <polys/matpol.h>
28 
29 #include <kernel/oswrapper/timer.h>
32 
33 #include <Singular/tok.h>
34 #include <Singular/ipid.h>
35 #include <Singular/ipshell.h>
36 #include <Singular/subexpr.h>
37 #include <Singular/links/silink.h>
38 #include <Singular/cntrlc.h>
39 #include <Singular/lists.h>
40 #include <Singular/blackbox.h>
41 #include <Singular/links/ssiLink.h>
42 
43 #ifdef HAVE_SIMPLEIPC
45 #endif
46 
47 #include <stdio.h>
48 #include <fcntl.h>
49 #include <errno.h>
50 #include <unistd.h>
51 #include <sys/types.h>
52 #include <signal.h>
53 #include <sys/types.h> /* for portability */
54 #include <sys/select.h>
55 #include <sys/socket.h>
56 #include <netinet/in.h>
57 #include <ctype.h> /*for isdigit*/
58 #include <netdb.h>
59 #include <sys/wait.h>
60 #include <time.h>
61 
62 #define SSI_VERSION 8
63 // 5->6: changed newstruct representation
64 // 6->7: attributes
65 // 7->8: qring
66 
67 #define SSI_BASE 16
68 typedef struct
69 {
70  s_buff f_read;
71  FILE *f_write;
72  ring r;
73  pid_t pid; /* only valid for fork/tcp mode*/
74  int fd_read,fd_write; /* only valid for fork/tcp mode*/
75  char level;
77  char quit_sent;
78 
79 } ssiInfo;
80 
83 
84 // forward declarations:
85 void ssiWritePoly_R(const ssiInfo *d, int typ, poly p, const ring r);
86 void ssiWriteIdeal(const ssiInfo *d, int typ,ideal I);
87 poly ssiReadPoly_R(const ssiInfo *D, const ring r);
88 ideal ssiReadIdeal_R(const ssiInfo *d,const ring r);
89 
90 // the helper functions:
91 void ssiSetCurrRing(const ring r)
92 {
93  // if (currRing!=NULL)
94  // Print("need to change the ring, currRing:%s, switch to: ssiRing%d\n",IDID(currRingHdl),nr);
95  // else
96  // Print("no ring, switch to ssiRing%d\n",nr);
97  if (!rEqual(r,currRing,1))
98  {
99  char name[20];
100  int nr=0;
101  do
102  { sprintf(name,"ssiRing%d",nr); nr++; }
103  while(IDROOT->get(name, 0)!=NULL);
105  IDRING(h)=r;
106  r->ref++;
107  rSetHdl(h);
108  }
109 }
110 // the implementation of the functions:
111 void ssiWriteInt(const ssiInfo *d,const int i)
112 {
113  fprintf(d->f_write,"%d ",i);
114  //if (d->f_debug!=NULL) fprintf(d->f_debug,"int: %d ",i);
115 }
116 
117 void ssiWriteString(const ssiInfo *d,const char *s)
118 {
119  fprintf(d->f_write,"%d %s ",(int)strlen(s),s);
120  //if (d->f_debug!=NULL) fprintf(d->f_debug,"stringi: %d \"%s\" ",strlen(s),s);
121 }
122 
123 void ssiWriteBigInt(const ssiInfo *d, const number n)
124 {
126 }
127 
128 void ssiWriteNumber_CF(const ssiInfo *d, const number n, const coeffs cf)
129 {
130  // syntax is as follows:
131  // case 1 Z/p: 3 <int>
132  // case 2 Q: 3 4 <int>
133  // or 3 0 <mpz_t nominator> <mpz_t denominator>
134  // or 3 1 dto.
135  // or 3 3 <mpz_t nominator>
136  // or 3 5 <mpz_t raw nom.> <mpz_t raw denom.>
137  // or 3 6 <mpz_t raw nom.> <mpz_t raw denom.>
138  // or 3 8 <mpz_t raw nom.>
139  if (getCoeffType(cf)==n_transExt)
140  {
141  fraction f=(fraction)n;
142  ssiWritePoly_R(d,POLY_CMD,NUM(f),cf->extRing);
143  ssiWritePoly_R(d,POLY_CMD,DEN(f),cf->extRing);
144  }
145  else if (getCoeffType(cf)==n_algExt)
146  {
147  ssiWritePoly_R(d,POLY_CMD,(poly)n,cf->extRing);
148  }
149  else if (cf->cfWriteFd!=NULL)
150  {
151  n_WriteFd(n,d->f_write,cf);
152  }
153  else WerrorS("coeff field not implemented");
154 }
155 
156 void ssiWriteNumber(const ssiInfo *d, const number n)
157 {
158  ssiWriteNumber_CF(d,n,d->r->cf);
159 }
160 
161 void ssiWriteRing_R(ssiInfo *d,const ring r)
162 {
163  /* 5 <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... <extRing> <Q-ideal> */
164  /* ch=-1: transext, coeff ring follows */
165  /* ch=-2: algext, coeff ring and minpoly follows */
166  if (r!=NULL)
167  {
168  if (rField_is_Q(r) || rField_is_Zp(r))
169  fprintf(d->f_write,"%d %d ",n_GetChar(r->cf),r->N);
170  else if (rFieldType(r)==n_transExt)
171  fprintf(d->f_write,"-1 %d ",r->N);
172  else if (rFieldType(r)==n_algExt)
173  fprintf(d->f_write,"-2 %d ",r->N);
174  else /*dummy*/
175  fprintf(d->f_write,"0 %d ",r->N);
176 
177  int i;
178  for(i=0;i<r->N;i++)
179  {
180  fprintf(d->f_write,"%d %s ",(int)strlen(r->names[i]),r->names[i]);
181  }
182  /* number of orderings:*/
183  i=0;
184  // remember dummy ring: everything 0:
185  if (r->order!=NULL) while (r->order[i]!=0) i++;
186  fprintf(d->f_write,"%d ",i);
187  /* each ordering block: */
188  i=0;
189  if (r->order!=NULL) while(r->order[i]!=0)
190  {
191  fprintf(d->f_write,"%d %d %d ",r->order[i],r->block0[i], r->block1[i]);
192  switch(r->order[i])
193  {
194  case ringorder_a:
195  case ringorder_wp:
196  case ringorder_Wp:
197  case ringorder_ws:
198  case ringorder_Ws:
199  case ringorder_aa:
200  {
201  int ii;
202  for(ii=r->block0[i];ii<=r->block1[i];ii++)
203  fprintf(d->f_write,"%d ",r->wvhdl[i][ii-r->block0[i]]);
204  }
205  break;
206 
207  case ringorder_a64:
208  case ringorder_M:
209  case ringorder_L:
210  case ringorder_IS:
211  Werror("ring oder not implemented for ssi:%d",r->order[i]);
212  break;
213 
214  default: break;
215  }
216  i++;
217  }
218  if ((rFieldType(r)==n_transExt)
219  || (rFieldType(r)==n_algExt))
220  {
221  ssiWriteRing_R(d,r->cf->extRing);
222  if (rFieldType(r)==n_algExt)
223  {
224  ssiWritePoly_R(d,POLY_CMD,r->cf->extRing->qideal->m[0],r->cf->extRing);
225  }
226  }
227  /* Q-ideal :*/
228  if (r->qideal!=NULL)
229  {
230  ssiWriteIdeal(d,IDEAL_CMD,r->qideal);
231  }
232  else
233  {
234  fprintf(d->f_write,"0 "/*ideal with 0 entries */);
235  }
236  }
237  else /* dummy ring r==NULL*/
238  {
239  fprintf(d->f_write,"0 0 0 0 "/*,r->ch,r->N, blocks, q-ideal*/);
240  }
241 }
242 
243 void ssiWriteRing(ssiInfo *d,const ring r)
244 {
245  /* 5 <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... <extRing> <Q-ideal> */
246  /* ch=-1: transext, coeff ring follows */
247  /* ch=-2: algext, coeff ring and minpoly follows */
248  if (r==currRing) // see recursive calls for transExt/algExt
249  {
250  if (d->r!=NULL) rKill(d->r);
251  d->r=r;
252  }
253  if (r!=NULL)
254  {
255  /*d->*/r->ref++;
256  }
257  ssiWriteRing_R(d,r);
258 }
259 void ssiWritePoly_R(const ssiInfo *d, int typ, poly p, const ring r)
260 {
261  fprintf(d->f_write,"%d ",pLength(p));//number of terms
262 
263  while(p!=NULL)
264  {
265  ssiWriteNumber_CF(d,pGetCoeff(p),r->cf);
266  //nWrite(fich,pGetCoeff(p));
267  fprintf(d->f_write,"%ld ",p_GetComp(p,r));//component
268 
269  for(int j=1;j<=rVar(r);j++)
270  {
271  fprintf(d->f_write,"%ld ",p_GetExp(p,j,r ));//x^j
272  }
273  pIter(p);
274  }
275 }
276 
277 void ssiWritePoly(const ssiInfo *d, int typ, poly p)
278 {
279  ssiWritePoly_R(d,typ,p,d->r);
280 }
281 
282 void ssiWriteIdeal(const ssiInfo *d, int typ,ideal I)
283 {
284  // syntax: 7 # of elements <poly 1> <poly2>.....
285  // syntax: 8 <rows> <cols> <poly 1> <poly2>.....
286  matrix M=(matrix)I;
287  int mn;
288  if (typ==MATRIX_CMD)
289  {
290  mn=MATROWS(M)*MATCOLS(M);
291  fprintf(d->f_write,"%d %d ", MATROWS(M),MATCOLS(M));
292  }
293  else
294  {
295  mn=IDELEMS(I);
296  fprintf(d->f_write,"%d ",IDELEMS(I));
297  }
298 
299  int i;
300  int tt;
301  if (typ==MODUL_CMD) tt=VECTOR_CMD;
302  else tt=POLY_CMD;
303 
304  for(i=0;i<mn;i++)
305  {
306  ssiWritePoly(d,tt,I->m[i]);
307  }
308 }
309 
311 {
312  ssiInfo *d=(ssiInfo*)l->data;
313  // syntax: <num ops> <operation> <op1> <op2> ....
314  fprintf(d->f_write,"%d %d ",D->argc,D->op);
315  if (D->argc >0) ssiWrite(l, &(D->arg1));
316  if (D->argc < 4)
317  {
318  if (D->argc >1) ssiWrite(l, &(D->arg2));
319  if (D->argc >2) ssiWrite(l, &(D->arg3));
320  }
321 }
322 
324 {
325  if (p->data.s.body==NULL)
327  if (p->data.s.body!=NULL)
328  ssiWriteString(d,p->data.s.body);
329  else
330  ssiWriteString(d,"");
331 }
332 
334 {
335  ssiInfo *d=(ssiInfo*)l->data;
336  int Ll=lSize(dd);
337  fprintf(d->f_write,"%d ",Ll+1);
338  int i;
339  for(i=0;i<=Ll;i++)
340  {
341  ssiWrite(l,&(dd->m[i]));
342  }
343 }
344 void ssiWriteIntvec(const ssiInfo *d,intvec * v)
345 {
346  fprintf(d->f_write,"%d ",v->length());
347  int i;
348  for(i=0;i<v->length();i++)
349  {
350  fprintf(d->f_write,"%d ",(*v)[i]);
351  }
352 }
353 void ssiWriteIntmat(const ssiInfo *d,intvec * v)
354 {
355  fprintf(d->f_write,"%d %d ",v->rows(),v->cols());
356  int i;
357  for(i=0;i<v->length();i++)
358  {
359  fprintf(d->f_write,"%d ",(*v)[i]);
360  }
361 }
362 
364 {
365  fprintf(d->f_write,"%d %d ",v->rows(),v->cols());
366  int i;
367  for(i=0;i<v->length();i++)
368  {
369  ssiWriteBigInt(d,(*v)[i]);
370  }
371 }
372 
373 char *ssiReadString(const ssiInfo *d)
374 {
375  char *buf;
376  int l;
377  l=s_readint(d->f_read);
378  buf=(char*)omAlloc0(l+1);
379  int c =s_getc(d->f_read); /* skip ' '*/
380  int ll=s_readbytes(buf,l,d->f_read);
381  //if (ll!=l) printf("want %d, got %d bytes\n",l,ll);
382  buf[l]='\0';
383  return buf;
384 }
385 
386 int ssiReadInt(s_buff fich)
387 {
388  return s_readint(fich);
389 }
390 
391 number ssiReadNumber_CF(const ssiInfo *d, const coeffs cf)
392 {
393  if (cf->cfReadFd!=NULL)
394  {
395  return n_ReadFd(d->f_read,cf);
396  }
397  else if (getCoeffType(cf) == n_transExt)
398  {
399  // poly poly
400  fraction f=(fraction)n_Init(1,cf);
401  p_Delete(&NUM(f),cf->extRing);
402  NUM(f)=ssiReadPoly_R(d,cf->extRing);
403  DEN(f)=ssiReadPoly_R(d,cf->extRing);
404  return (number)f;
405  }
406  else if (getCoeffType(cf) == n_algExt)
407  {
408  // poly
409  return (number)ssiReadPoly_R(d,cf->extRing);
410  }
411  else Werror("coeffs not implemented in ssiReadNumber");
412  return NULL;
413 }
414 
415 number ssiReadBigInt(const ssiInfo *d)
416 {
417  number n=ssiReadNumber_CF(d,coeffs_BIGINT);
418  if ((SR_HDL(n) & SR_INT)==0)
419  {
420  if (n->s!=3) Werror("invalid sub type in bigint:%d",n->s);
421  }
422  return n;
423 }
424 
425 number ssiReadNumber(const ssiInfo *d)
426 {
427  return ssiReadNumber_CF(d,d->r->cf);
428 }
429 
430 ring ssiReadRing(const ssiInfo *d)
431 {
432 /* syntax is <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... <Q-ideal> */
433  int ch, N,i;
434  char **names;
435  ch=s_readint(d->f_read);
436  N=s_readint(d->f_read);
437  if (N!=0)
438  {
439  names=(char**)omAlloc(N*sizeof(char*));
440  for(i=0;i<N;i++)
441  {
442  names[i]=ssiReadString(d);
443  }
444  }
445  // read the orderings:
446  int num_ord; // number of orderings
447  num_ord=s_readint(d->f_read);
448  int *ord=(int *)omAlloc0((num_ord+1)*sizeof(int));
449  int *block0=(int *)omAlloc0((num_ord+1)*sizeof(int));
450  int *block1=(int *)omAlloc0((num_ord+1)*sizeof(int));
451  int **wvhdl=(int**)omAlloc0((num_ord+1)*sizeof(int*));
452  for(i=0;i<num_ord;i++)
453  {
454  ord[i]=s_readint(d->f_read);
455  block0[i]=s_readint(d->f_read);
456  block1[i]=s_readint(d->f_read);
457  switch(ord[i])
458  {
459  case ringorder_a:
460  case ringorder_wp:
461  case ringorder_Wp:
462  case ringorder_ws:
463  case ringorder_Ws:
464  case ringorder_aa:
465  {
466  wvhdl[i]=(int*)omAlloc((block1[i]-block0[i]+1)*sizeof(int));
467  int ii;
468  for(ii=block0[i];ii<=block1[i];ii++)
469  wvhdl[i][ii-block0[i]]=s_readint(d->f_read);
470  }
471  break;
472 
473  case ringorder_a64:
474  case ringorder_M:
475  case ringorder_L:
476  case ringorder_IS:
477  Werror("ring oder not implemented for ssi:%d",ord[i]);
478  break;
479 
480  default: break;
481  }
482  }
483  if (N==0)
484  {
485  omFree(ord);
486  omFree(block0);
487  omFree(block1);
488  omFree(wvhdl);
489  return NULL;
490  }
491  else
492  {
493  ring r=NULL;
494  if (ch>=0) /* Q, Z/p */
495  r=rDefault(ch,N,names,num_ord,ord,block0,block1,wvhdl);
496  else if (ch==-1) /* trans ext. */
497  {
498  TransExtInfo T;
499  T.r=ssiReadRing(d);
501  r=rDefault(cf,N,names,num_ord,ord,block0,block1,wvhdl);
502  }
503  else if (ch==-2) /* alg ext. */
504  {
505  TransExtInfo T;
506  T.r=ssiReadRing(d);
507  T.r->qideal=idInit(1,1);
508  T.r->qideal->m[0]=ssiReadPoly_R(d,T.r);
510  r=rDefault(cf,N,names,num_ord,ord,block0,block1,wvhdl);
511  }
512  else
513  {
514  Werror("ssi: read unknown coeffs type (%d)",ch);
515  return NULL;
516  }
517  ideal q=ssiReadIdeal_R(d,r);
518  if (IDELEMS(q)==0) omFreeBin(q,sip_sideal_bin);
519  else r->qideal=q;
520  return r;
521  }
522 }
523 
524 poly ssiReadPoly_R(const ssiInfo *D, const ring r)
525 {
526 // < # of terms> < term1> < .....
527  int n,i,l;
528  n=ssiReadInt(D->f_read);
529  //Print("poly: terms:%d\n",n);
530  poly p;
531  poly ret=NULL;
532  poly prev=NULL;
533  for(l=0;l<n;l++) // read n terms
534  {
535 // coef,comp.exp1,..exp N
536  p=p_Init(r);
537  pSetCoeff0(p,ssiReadNumber_CF(D,r->cf));
538  int d;
539  d=s_readint(D->f_read);
540  p_SetComp(p,d,r);
541  for(i=1;i<=rVar(r);i++)
542  {
543  d=s_readint(D->f_read);
544  p_SetExp(p,i,d,r);
545  }
546  p_Setm(p,r);
547  p_Test(p,r);
548  if (ret==NULL) ret=p;
549  else pNext(prev)=p;
550  prev=p;
551  }
552  return ret;
553 }
554 
556 {
557 // < # of terms> < term1> < .....
558  return ssiReadPoly_R(D,D->r);
559 }
560 
561 ideal ssiReadIdeal_R(const ssiInfo *d,const ring r)
562 {
563  int n,i;
564  ideal I;
565  n=s_readint(d->f_read);
566  I=idInit(n,1);
567  for(i=0;i<IDELEMS(I);i++) // read n terms
568  {
569  I->m [i]=ssiReadPoly_R(d,r);
570  }
571  return I;
572 }
573 
575 {
576  return ssiReadIdeal_R(d,d->r);
577 }
578 
580 {
581  int n,m;
582  m=s_readint(d->f_read);
583  n=s_readint(d->f_read);
584  matrix M=mpNew(m,n);
585  poly p;
586  for(int i=1;i<=MATROWS(M);i++)
587  for(int j=1;j<=MATCOLS(M);j++)
588  {
589  p=ssiReadPoly(d);
590  MATELEM(M,i,j)=p;
591  }
592  return M;
593 }
594 
596 {
597  ssiInfo *d=(ssiInfo*)l->data;
598  // syntax: <num ops> <operation> <op1> <op2> ....
599  command D=(command)omAlloc0(sizeof(*D));
600  int argc,op;
601  argc=s_readint(d->f_read);
602  op=s_readint(d->f_read);
603  D->argc=argc; D->op=op;
604  leftv v;
605  if (argc >0)
606  {
607  v=ssiRead1(l);
608  memcpy(&(D->arg1),v,sizeof(*v));
610  }
611  if (argc <4)
612  {
613  if (D->argc >1)
614  {
615  v=ssiRead1(l);
616  memcpy(&(D->arg2),v,sizeof(*v));
618  }
619  if (D->argc >2)
620  {
621  v=ssiRead1(l);
622  memcpy(&(D->arg3),v,sizeof(*v));
624  }
625  }
626  else
627  {
628  leftv prev=&(D->arg1);
629  argc--;
630  while(argc >0)
631  {
632  v=ssiRead1(l);
633  prev->next=v;
634  prev=v;
635  argc--;
636  }
637  }
638  return D;
639 }
640 
642 {
643  char *s=ssiReadString(d);
646  p->libname=omStrDup("");
647  p->procname=omStrDup("");
648  p->data.s.body=s;
649  return p;
650 }
652 {
653  ssiInfo *d=(ssiInfo*)l->data;
654  int nr;
655  nr=s_readint(d->f_read);
656  lists L=(lists)omAlloc(sizeof(*L));
657  L->Init(nr);
658 
659  int i;
660  leftv v;
661  for(i=0;i<nr;i++)
662  {
663  v=ssiRead1(l);
664  memcpy(&(L->m[i]),v,sizeof(*v));
666  }
667  return L;
668 }
670 {
671  int nr;
672  nr=s_readint(d->f_read);
673  intvec *v=new intvec(nr);
674  for(int i=0;i<nr;i++)
675  {
676  (*v)[i]=s_readint(d->f_read);
677  }
678  return v;
679 }
681 {
682  int r,c;
683  r=s_readint(d->f_read);
684  c=s_readint(d->f_read);
685  intvec *v=new intvec(r,c,0);
686  for(int i=0;i<r*c;i++)
687  {
688  (*v)[i]=s_readint(d->f_read);
689  }
690  return v;
691 }
693 {
694  int r,c;
695  r=s_readint(d->f_read);
696  c=s_readint(d->f_read);
698  for(int i=0;i<r*c;i++)
699  {
700  (*v)[i]=ssiReadBigInt(d);
701  }
702  return v;
703 }
704 
706 {
707  ssiInfo *d=(ssiInfo*)l->data;
708  int throwaway;
709  throwaway=s_readint(d->f_read);
710  char *name=ssiReadString(d);
711  int tok;
712  blackboxIsCmd(name,tok);
713  if (tok>MAX_TOK)
714  {
715  blackbox *b=getBlackboxStuff(tok);
716  res->rtyp=tok;
717  b->blackbox_deserialize(&b,&(res->data),l);
718  }
719  else
720  {
721  Werror("blackbox %s not found",name);
722  }
723 }
724 
726 {
727  ssiInfo *d=(ssiInfo*)l->data;
728  BITSET fl=(BITSET)s_readint(d->f_read);
729  int nr_of_attr=s_readint(d->f_read);
730  if (nr_of_attr>0)
731  {
732  for(int i=1;i<nr_of_attr;i++)
733  {
734  }
735  }
736  leftv tmp=ssiRead1(l);
737  memcpy(res,tmp,sizeof(sleftv));
738  memset(tmp,0,sizeof(sleftv));
739  omFreeSize(tmp,sizeof(sleftv));
740  if (nr_of_attr>0)
741  {
742  }
743  res->flag=fl;
744 }
745 //**************************************************************************/
746 
747 BOOLEAN ssiOpen(si_link l, short flag, leftv u)
748 {
749  if (l!=NULL)
750  {
751  const char *mode;
752  ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo));
753  if (flag & SI_LINK_OPEN)
754  {
755  if (l->mode[0] != '\0' && (strcmp(l->mode, "r") == 0))
756  flag = SI_LINK_READ;
757  else flag = SI_LINK_WRITE;
758  }
759 
760  if (flag == SI_LINK_READ) mode = "r";
761  else if (strcmp(l->mode, "w") == 0) mode = "w";
762  else if (strcmp(l->mode, "fork") == 0) mode = "fork";
763  else if (strcmp(l->mode, "tcp") == 0) mode = "tcp";
764  else if (strcmp(l->mode, "connect") == 0) mode = "connect";
765  else mode = "a";
766 
767 
768  SI_LINK_SET_OPEN_P(l, flag);
769  l->data=d;
770  omFree(l->mode);
771  l->mode = omStrDup(mode);
772 
773  if (l->name[0] == '\0')
774  {
775  if (strcmp(mode,"fork")==0)
776  {
778  n->u=u;
779  n->l=l;
780  n->next=(void *)ssiToBeClosed;
781  ssiToBeClosed=n;
782 
783  int pc[2];
784  int cp[2];
785  pipe(pc);
786  pipe(cp);
787  pid_t pid = fork();
788  if (pid == -1 && errno == EAGAIN) // RLIMIT_NPROC too low?
789  {
791  pid = fork();
792  }
793  if (pid == -1)
794  {
795  WerrorS("could not fork");
796  }
797  if (pid==0) /*fork: child*/
798  {
799  /* block SIGINT */
800  sigset_t sigint;
801  sigemptyset(&sigint);
802  sigaddset(&sigint, SIGINT);
803  sigprocmask(SIG_BLOCK, &sigint, NULL);
804 
805  link_list hh=(link_list)ssiToBeClosed->next;
806  /* we know: l is the first entry in ssiToBeClosed-list */
807  while(hh!=NULL)
808  {
809  SI_LINK_SET_CLOSE_P(hh->l);
810  ssiInfo *dd=(ssiInfo*)hh->l->data;
811  s_close(dd->f_read);
812  s_free(dd->f_read);
813  fclose(dd->f_write);
814  if (dd->r!=NULL) rKill(dd->r);
815  omFreeSize((ADDRESS)dd,(sizeof *dd));
816  hh->l->data=NULL;
817  link_list nn=(link_list)hh->next;
818  omFree(hh);
819  hh=nn;
820  }
821  ssiToBeClosed->next=NULL;
822 #ifdef HAVE_SIMPLEIPC
823  memset(sem_acquired, 0, SIPC_MAX_SEMAPHORES*sizeof(sem_acquired[0]));
824 #endif // HAVE_SIMPLEIPC
825  si_close(pc[1]); si_close(cp[0]);
826  d->f_write=fdopen(cp[1],"w");
827  d->f_read=s_open(pc[0]);
828  d->fd_read=pc[0];
829  d->fd_write=cp[1];
830  //d->r=currRing;
831  //if (d->r!=NULL) d->r->ref++;
832  l->data=d;
833  omFree(l->mode);
834  l->mode = omStrDup(mode);
837  //myynest=0;
839  if ((u!=NULL)&&(u->rtyp==IDHDL))
840  {
841  idhdl h=(idhdl)u->data;
842  h->lev=0;
843  }
844  loop
845  {
846  leftv h=ssiRead1(l); /*contains an exit.... */
847  if (feErrors != NULL && *feErrors != '\0')
848  {
849  // handle errors:
850  PrintS(feErrors); /* currently quite simple */
851  *feErrors = '\0';
852  }
853  ssiWrite(l,h);
854  h->CleanUp();
855  omFreeBin(h, sleftv_bin);
856  }
857  /* never reached*/
858  }
859  else if (pid>0) /*fork: parent*/
860  {
861  d->pid=pid;
862  si_close(pc[0]); si_close(cp[1]);
863  d->f_write=fdopen(pc[1],"w");
864  d->f_read=s_open(cp[0]);
865  d->fd_read=cp[0];
866  d->fd_write=pc[1];
868  d->send_quit_at_exit=1;
869  //d->r=currRing;
870  //if (d->r!=NULL) d->r->ref++;
871  }
872  else
873  {
874  Werror("fork failed (%d)",errno);
875  l->data=NULL;
876  omFree(d);
877  return TRUE;
878  }
879  }
880  // ---------------------------------------------------------------------
881  else if (strcmp(mode,"tcp")==0)
882  {
883  int sockfd, newsockfd, portno, clilen;
884  struct sockaddr_in serv_addr, cli_addr;
885  sockfd = socket(AF_INET, SOCK_STREAM, 0);
886  if(sockfd < 0)
887  {
888  WerrorS("ERROR opening socket");
889  l->data=NULL;
890  omFree(d);
891  return TRUE;
892  }
893  memset((char *) &serv_addr,0, sizeof(serv_addr));
894  portno = 1025;
895  serv_addr.sin_family = AF_INET;
896  serv_addr.sin_addr.s_addr = INADDR_ANY;
897  do
898  {
899  portno++;
900  serv_addr.sin_port = htons(portno);
901  if(portno > 50000)
902  {
903  WerrorS("ERROR on binding (no free port available?)");
904  l->data=NULL;
905  omFree(d);
906  return TRUE;
907  }
908  }
909  while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
910  Print("waiting on port %d\n", portno);mflush();
911  listen(sockfd,1);
912  newsockfd = si_accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
913  if(newsockfd < 0)
914  {
915  WerrorS("ERROR on accept");
916  l->data=NULL;
917  omFree(d);
918  return TRUE;
919  }
920  PrintS("client accepted\n");
921  d->fd_read = newsockfd;
922  d->fd_write = newsockfd;
923  d->f_read = s_open(newsockfd);
924  d->f_write = fdopen(newsockfd, "w");
926  si_close(sockfd);
927  }
928  // no ssi-Link on stdin or stdout
929  else
930  {
931  Werror("invalid mode >>%s<< for ssi",mode);
932  l->data=NULL;
933  omFree(d);
934  return TRUE;
935  }
936  }
937  // =========================================================================
938  else /*l->name=NULL*/
939  {
940  // tcp mode
941  if(strcmp(mode,"tcp")==0)
942  {
943  int sockfd, newsockfd, portno, clilen;
944  struct sockaddr_in serv_addr, cli_addr;
945  sockfd = socket(AF_INET, SOCK_STREAM, 0);
946  if(sockfd < 0)
947  {
948  WerrorS("ERROR opening socket");
949  l->data=NULL;
950  omFree(d);
951  return TRUE;
952  }
953  memset((char *) &serv_addr,0, sizeof(serv_addr));
954  portno = 1025;
955  serv_addr.sin_family = AF_INET;
956  serv_addr.sin_addr.s_addr = INADDR_ANY;
957  do
958  {
959  portno++;
960  serv_addr.sin_port = htons(portno);
961  if(portno > 50000)
962  {
963  WerrorS("ERROR on binding (no free port available?)");
964  l->data=NULL;
965  return TRUE;
966  }
967  }
968  while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
969  //Print("waiting on port %d\n", portno);mflush();
970  listen(sockfd,1);
971  char* cli_host = (char*)omAlloc(256);
972  char* path = (char*)omAlloc(1024);
973  int r = si_sscanf(l->name,"%255[^:]:%s",cli_host,path);
974  if(r == 0)
975  {
976  WerrorS("ERROR: no host specified");
977  l->data=NULL;
978  omFree(d);
979  omFree(path);
980  omFree(cli_host);
981  return TRUE;
982  }
983  else if(r == 1)
984  {
985  WarnS("program not specified, using /usr/local/bin/Singular");
986  strcpy(path,"/usr/local/bin/Singular");
987  }
988  char* ssh_command = (char*)omAlloc(256);
989  char* ser_host = (char*)omAlloc(64);
990  gethostname(ser_host,64);
991  sprintf(ssh_command,"ssh %s %s -q --batch --link=ssi --MPhost=%s --MPport=%d &",cli_host,path,ser_host,portno);
992  //Print("client on %s started:%s\n",cli_host,path);
993  omFree(path);
994  omFree(cli_host);
995  if (TEST_OPT_PROT) { Print("running >>%s<<\n",ssh_command); }
996  system(ssh_command);
997  omFree(ssh_command);
998  omFree(ser_host);
999  clilen = sizeof(cli_addr);
1000  newsockfd = si_accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
1001  if(newsockfd < 0)
1002  {
1003  WerrorS("ERROR on accept");
1004  l->data=NULL;
1005  omFree(d);
1006  return TRUE;
1007  }
1008  //PrintS("client accepted\n");
1009  d->fd_read = newsockfd;
1010  d->fd_write = newsockfd;
1011  d->f_read = s_open(newsockfd);
1012  d->f_write = fdopen(newsockfd, "w");
1013  si_close(sockfd);
1015  d->send_quit_at_exit=1;
1016  link_list newlink=(link_list)omAlloc(sizeof(link_struct));
1017  newlink->u=u;
1018  newlink->l=l;
1019  newlink->next=(void *)ssiToBeClosed;
1020  ssiToBeClosed=newlink;
1021  fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,si_opt_1,si_opt_2);
1022  }
1023  // ----------------------------------------------------------------------
1024  else if(strcmp(mode,"connect")==0)
1025  {
1026  char* host = (char*)omAlloc(256);
1027  int sockfd, portno;
1028  struct sockaddr_in serv_addr;
1029  struct hostent *server;
1030 
1031  si_sscanf(l->name,"%255[^:]:%d",host,&portno);
1032  //Print("connect to host %s, port %d\n",host,portno);mflush();
1033  if (portno!=0)
1034  {
1035  sockfd = socket(AF_INET, SOCK_STREAM, 0);
1036  if (sockfd < 0) { WerrorS("ERROR opening socket"); return TRUE; }
1037  server = gethostbyname(host);
1038  if (server == NULL) { WerrorS("ERROR, no such host"); return TRUE; }
1039  memset((char *) &serv_addr, 0, sizeof(serv_addr));
1040  serv_addr.sin_family = AF_INET;
1041  memcpy((char *)&serv_addr.sin_addr.s_addr,
1042  (char *)server->h_addr,
1043  server->h_length);
1044  serv_addr.sin_port = htons(portno);
1045  if (si_connect(sockfd,(sockaddr*)&serv_addr,sizeof(serv_addr)) < 0)
1046  { Werror("ERROR connecting(errno=%d)",errno); return TRUE; }
1047  //PrintS("connected\n");mflush();
1048  d->f_read=s_open(sockfd);
1049  d->fd_read=sockfd;
1050  d->f_write=fdopen(sockfd,"w");
1051  d->fd_write=sockfd;
1053  omFree(host);
1054  }
1055  else
1056  {
1057  l->data=NULL;
1058  omFree(d);
1059  return TRUE;
1060  }
1061  }
1062  // ======================================================================
1063  else
1064  {
1065  // normal link to a file
1066  FILE *outfile;
1067  char *filename=l->name;
1068 
1069  if(filename[0]=='>')
1070  {
1071  if (filename[1]=='>')
1072  {
1073  filename+=2;
1074  mode = "a";
1075  }
1076  else
1077  {
1078  filename++;
1079  mode="w";
1080  }
1081  }
1082  outfile=myfopen(filename,mode);
1083  if (outfile!=NULL)
1084  {
1085  if (strcmp(l->mode,"r")==0)
1086  {
1087  fclose(outfile);
1088  d->f_read=s_open_by_name(filename);
1089  }
1090  else
1091  {
1092  d->f_write = outfile;
1093  fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,si_opt_1,si_opt_2);
1094  }
1095  }
1096  else
1097  {
1098  omFree(d);
1099  l->data=NULL;
1100  return TRUE;
1101  }
1102  }
1103  }
1104  }
1105 
1106  return FALSE;
1107 }
1108 
1109 //**************************************************************************/
1111 {
1112  if (l!=NULL)
1113  {
1114  ssiInfo *d = (ssiInfo *)l->data;
1115  if (d!=NULL)
1116  {
1117  if (d->send_quit_at_exit)
1118  {
1119  fputs("99\n",d->f_write);
1120  fflush(d->f_write);
1121  }
1122  d->quit_sent=1;
1123  }
1124  }
1125  return FALSE;
1126 }
1127 
1129 {
1130  if (l!=NULL)
1131  {
1133  ssiInfo *d = (ssiInfo *)l->data;
1134  if (d!=NULL)
1135  {
1136  if ((d->send_quit_at_exit)
1137  && (d->quit_sent==0))
1138  {
1139  fputs("99\n",d->f_write);
1140  fflush(d->f_write);
1141  }
1142  if (d->r!=NULL) rKill(d->r);
1143  if ((d->pid!=0)
1144  && (si_waitpid(d->pid,NULL,WNOHANG)==0))
1145  {
1146  struct timespec t;
1147  t.tv_sec=0;
1148  t.tv_nsec=100000000; // <=100 ms
1149  struct timespec rem;
1150  int r;
1151  do
1152  {
1153  r = nanosleep(&t, &rem);
1154  t = rem;
1155  } while ((r < 0) && (errno == EINTR)
1156  && (si_waitpid(d->pid,NULL,WNOHANG) == 0));
1157  if ((r == 0) && (si_waitpid(d->pid,NULL,WNOHANG) == 0))
1158  {
1159  kill(d->pid,15);
1160  t.tv_sec=5; // <=5s
1161  t.tv_nsec=0;
1162  do
1163  {
1164  r = nanosleep(&t, &rem);
1165  t = rem;
1166  } while ((r < 0) && (errno == EINTR)
1167  && (si_waitpid(d->pid,NULL,WNOHANG) == 0));
1168  if ((r == 0) && (si_waitpid(d->pid,NULL,WNOHANG) == 0))
1169  {
1170  kill(d->pid,9); // just to be sure
1171  si_waitpid(d->pid,NULL,0);
1172  }
1173  }
1174  }
1175  if (d->f_read!=NULL) s_close(d->f_read);
1176  if (d->f_read!=NULL) s_free(d->f_read);
1177  if (d->f_write!=NULL) fclose(d->f_write);
1178  if ((strcmp(l->mode,"tcp")==0)
1179  || (strcmp(l->mode,"fork")==0))
1180  {
1182  if (hh!=NULL)
1183  {
1184  if (hh->l==l)
1185  {
1186  ssiToBeClosed=(link_list)hh->next;
1187  omFreeSize(hh,sizeof(link_struct));
1188  }
1189  else while(hh->next!=NULL)
1190  {
1191  link_list hhh=(link_list)hh->next;
1192  if (hhh->l==l)
1193  {
1194  hh->next=hhh->next;
1195  omFreeSize(hhh,sizeof(link_struct));
1196  break;
1197  }
1198  else
1199  hh=(link_list)hh->next;
1200  }
1201  }
1202  }
1203  omFreeSize((ADDRESS)d,(sizeof *d));
1204  }
1205  l->data=NULL;
1206  }
1207  return FALSE;
1208 }
1209 
1210 //**************************************************************************/
1212 {
1213  ssiInfo *d = (ssiInfo *)l->data;
1214  leftv res=(leftv)omAlloc0(sizeof(sleftv));
1215  int t=0;
1216  t=s_readint(d->f_read);
1217  //Print("got type %d\n",t);
1218  switch(t)
1219  {
1220  case 1:res->rtyp=INT_CMD;
1221  res->data=(char *)(long)ssiReadInt(d->f_read);
1222  break;
1223  case 2:res->rtyp=STRING_CMD;
1224  res->data=(char *)ssiReadString(d);
1225  break;
1226  case 3:res->rtyp=NUMBER_CMD;
1227  res->data=(char *)ssiReadNumber(d);
1228  break;
1229  case 4:res->rtyp=BIGINT_CMD;
1230  res->data=(char *)ssiReadBigInt(d);
1231  break;
1232  case 15:
1233  case 5:{
1234  d->r=ssiReadRing(d);
1235  res->data=(char*)d->r;
1236  if (d->r->qideal==NULL)
1237  res->rtyp=RING_CMD;
1238  else
1239  res->rtyp=QRING_CMD;
1240  // we are in the top-level, so set the basering to d->r:
1241  if (d->r!=NULL)
1242  {
1243  d->r->ref++;
1244  ssiSetCurrRing(d->r);
1245  }
1246  if (t==15) return ssiRead1(l);
1247  }
1248  break;
1249  case 6:res->rtyp=POLY_CMD;
1250  if (d->r==NULL) goto no_ring;
1251  res->data=(char*)ssiReadPoly(d);
1252  break;
1253  case 7:res->rtyp=IDEAL_CMD;
1254  if (d->r==NULL) goto no_ring;
1255  res->data=(char*)ssiReadIdeal(d);
1256  break;
1257  case 8:res->rtyp=MATRIX_CMD;
1258  if (d->r==NULL) goto no_ring;
1259  res->data=(char*)ssiReadMatrix(d);
1260  break;
1261  case 9:res->rtyp=VECTOR_CMD;
1262  if (d->r==NULL) goto no_ring;
1263  res->data=(char*)ssiReadPoly(d);
1264  break;
1265  case 10:res->rtyp=MODUL_CMD;
1266  if (d->r==NULL) goto no_ring;
1267  res->data=(char*)ssiReadIdeal(d);
1268  break;
1269  case 11:
1270  {
1271  res->rtyp=COMMAND;
1272  res->data=ssiReadCommand(l);
1273  int nok=res->Eval();
1274  if (nok) WerrorS("error in eval");
1275  break;
1276  }
1277  case 12: /*DEF_CMD*/
1278  {
1279  res->rtyp=0;
1280  res->name=(char *)ssiReadString(d);
1281  int nok=res->Eval();
1282  if (nok) WerrorS("error in name lookup");
1283  break;
1284  }
1285  case 13: res->rtyp=PROC_CMD;
1286  res->data=ssiReadProc(d);
1287  break;
1288  case 14: res->rtyp=LIST_CMD;
1289  res->data=ssiReadList(l);
1290  break;
1291  case 16: res->rtyp=NONE; res->data=NULL;
1292  break;
1293  case 17: res->rtyp=INTVEC_CMD;
1294  res->data=ssiReadIntvec(d);
1295  break;
1296  case 18: res->rtyp=INTMAT_CMD;
1297  res->data=ssiReadIntmat(d);
1298  break;
1299  case 19: res->rtyp=BIGINTMAT_CMD;
1300  res->data=ssiReadBigintmat(d);
1301  break;
1302  case 20: ssiReadBlackbox(res,l);
1303  break;
1304  case 21: ssiReadAttrib(res,l);
1305  break;
1306  // ------------
1307  case 98: // version
1308  {
1309  int n98_v,n98_m;
1310  BITSET n98_o1,n98_o2;
1311  n98_v=s_readint(d->f_read);
1312  n98_m=s_readint(d->f_read);
1313  n98_o1=s_readint(d->f_read);
1314  n98_o2=s_readint(d->f_read);
1315  if ((n98_v!=SSI_VERSION) ||(n98_m!=MAX_TOK))
1316  {
1317  Print("incompatible versions of ssi: %d/%d vs %d/%d",
1318  SSI_VERSION,MAX_TOK,n98_v,n98_m);
1319  }
1320  #ifndef SING_NDEBUG
1321  if (TEST_OPT_DEBUG)
1322  Print("// opening ssi-%d, MAX_TOK=%d\n",n98_v,n98_m);
1323  #endif
1324  si_opt_1=n98_o1;
1325  si_opt_2=n98_o2;
1326  return ssiRead1(l);
1327  }
1328  case 99: ssiClose(l); m2_end(0);
1329  case 0: if (s_iseof(d->f_read))
1330  {
1331  ssiClose(l);
1332  }
1333  res->rtyp=DEF_CMD;
1334  break;
1335  default: Werror("not implemented (t:%d)",t);
1336  omFreeSize(res,sizeof(sleftv));
1337  res=NULL;
1338  break;
1339  }
1340  // if currRing is required for the result, but lost
1341  // define "ssiRing%d" as currRing:
1342  if ((d->r!=NULL)
1343  && (currRing!=d->r)
1344  && (res->RingDependend()))
1345  {
1346  ssiSetCurrRing(d->r);
1347  }
1348  return res;
1349 no_ring: WerrorS("no ring");
1350  omFreeSize(res,sizeof(sleftv));
1351  return NULL;
1352 }
1353 //**************************************************************************/
1355 {
1356  if(SI_LINK_W_OPEN_P(l)==0)
1357  if (slOpen(l,SI_LINK_OPEN|SI_LINK_WRITE,NULL)) return TRUE;
1358  ssiInfo *d = (ssiInfo *)l->data;
1359  if (d->r!=r)
1360  {
1361  if (send)
1362  {
1363  fputs("15 ",d->f_write);
1364  ssiWriteRing(d,r);
1365  }
1366  d->r=r;
1367  }
1368  if (currRing!=r) rChangeCurrRing(r);
1369  return FALSE;
1370 }
1371 //**************************************************************************/
1372 
1374 {
1375  if(SI_LINK_W_OPEN_P(l)==0)
1376  if (slOpen(l,SI_LINK_OPEN|SI_LINK_WRITE,NULL)) return TRUE;
1377  ssiInfo *d = (ssiInfo *)l->data;
1378  d->level++;
1379  //FILE *fich=d->f;
1380  while (data!=NULL)
1381  {
1382  int tt=data->Typ();
1383  void *dd=data->Data();
1384  attr *aa=data->Attribute();
1385  BOOLEAN with_attr=FALSE;
1386  if (((*aa)!=NULL)||(data->flag!=0))
1387  {
1388  attr a=*aa;
1389  int n=0;
1390  while(a!=NULL) { n++; a=a->next;}
1391  fprintf(d->f_write,"21 %d %d ",data->flag,n);
1392  a=*aa;
1393  }
1394  if ((dd==NULL) && (data->name!=NULL) && (tt==0)) tt=DEF_CMD;
1395  // return pure undefined names as def
1396 
1397  switch(tt /*data->Typ()*/)
1398  {
1399  case 0: /*error*/
1400  case NONE/* nothing*/:fputs("16 ",d->f_write);
1401  break;
1402  case STRING_CMD: fputs("2 ",d->f_write);
1403  ssiWriteString(d,(char *)dd);
1404  break;
1405  case INT_CMD: fputs("1 ",d->f_write);
1406  ssiWriteInt(d,(int)(long)dd);
1407  break;
1408  case BIGINT_CMD:fputs("4 ",d->f_write);
1409  ssiWriteBigInt(d,(number)dd);
1410  break;
1411  case NUMBER_CMD:
1412  if (d->r!=currRing)
1413  {
1414  fputs("15 ",d->f_write);
1416  if (d->level<=1) fputc('\n',d->f_write);
1417  }
1418  fputs("3 ",d->f_write);
1419  ssiWriteNumber(d,(number)dd);
1420  break;
1421  case QRING_CMD:
1422  case RING_CMD:fputs("5 ",d->f_write);
1423  ssiWriteRing(d,(ring)dd);
1424  break;
1425  case POLY_CMD:
1426  case VECTOR_CMD:
1427  if (d->r!=currRing)
1428  {
1429  fputs("15 ",d->f_write);
1431  if (d->level<=1) fputc('\n',d->f_write);
1432  }
1433  if(tt==POLY_CMD) fputs("6 ",d->f_write);
1434  else fputs("9 ",d->f_write);
1435  ssiWritePoly(d,tt,(poly)dd);
1436  break;
1437  case IDEAL_CMD:
1438  case MODUL_CMD:
1439  case MATRIX_CMD:
1440  if (d->r!=currRing)
1441  {
1442  fputs("15 ",d->f_write);
1444  if (d->level<=1) fputc('\n',d->f_write);
1445  }
1446  if(tt==IDEAL_CMD) fputs("7 ",d->f_write);
1447  else if(tt==MATRIX_CMD) fputs("8 ",d->f_write);
1448  else fputs("10 ",d->f_write);
1449  ssiWriteIdeal(d,tt,(ideal)dd);
1450  break;
1451  case COMMAND:
1452  fputs("11 ",d->f_write);
1453  ssiWriteCommand(l,(command)dd);
1454  break;
1455  case DEF_CMD: /* not evaluated stuff in quotes */
1456  fputs("12 ",d->f_write);
1457  ssiWriteString(d,data->Name());
1458  break;
1459  case PROC_CMD:
1460  fputs("13 ",d->f_write);
1461  ssiWriteProc(d,(procinfov)dd);
1462  break;
1463  case LIST_CMD:
1464  fputs("14 ",d->f_write);
1465  ssiWriteList(l,(lists)dd);
1466  break;
1467  case INTVEC_CMD:
1468  fputs("17 ",d->f_write);
1469  ssiWriteIntvec(d,(intvec *)dd);
1470  break;
1471  case INTMAT_CMD:
1472  fputs("18 ",d->f_write);
1473  ssiWriteIntmat(d,(intvec *)dd);
1474  break;
1475  case BIGINTMAT_CMD:
1476  fputs("19 ",d->f_write);
1477  ssiWriteBigintmat(d,(bigintmat *)dd);
1478  break;
1479  default:
1480  if (tt>MAX_TOK)
1481  {
1482  blackbox *b=getBlackboxStuff(tt);
1483  fputs("20 ",d->f_write);
1484  b->blackbox_serialize(b,dd,l);
1485  }
1486  else
1487  {
1488  Werror("not implemented (t:%d, rtyp:%d)",tt, data->rtyp);
1489  d->level=0;
1490  return TRUE;
1491  }
1492  break;
1493  }
1494  if (d->level<=1) { fputc('\n',d->f_write); fflush(d->f_write); }
1495  data=data->next;
1496  }
1497  d->level--;
1498  return FALSE;
1499 }
1500 
1503 
1504 si_link_extension slInitSsiExtension(si_link_extension s)
1505 {
1506  s->Open=ssiOpen;
1507  s->Close=ssiClose;
1508  s->Kill=ssiClose;
1509  s->Read=ssiRead1;
1510  s->Read2=(slRead2Proc)NULL;
1511  s->Write=ssiWrite;
1512  s->Dump=ssiDump;
1513  s->GetDump=ssiGetDump;
1514 
1515  s->Status=slStatusSsi;
1516  s->SetRing=ssiSetRing;
1517  s->type="ssi";
1518  return s;
1519 }
1520 
1521 const char* slStatusSsi(si_link l, const char* request)
1522 {
1523  ssiInfo *d=(ssiInfo*)l->data;
1524  if (d==NULL) return "not open";
1525  if (((strcmp(l->mode,"fork")==0)
1526  ||(strcmp(l->mode,"tcp")==0)
1527  ||(strcmp(l->mode,"connect")==0))
1528  && (strcmp(request, "read") == 0))
1529  {
1530  fd_set mask;
1531  struct timeval wt;
1532  if (s_isready(d->f_read)) return "ready";
1533  loop
1534  {
1535  /* Don't block. Return socket status immediately. */
1536  wt.tv_sec = 0;
1537  wt.tv_usec = 0;
1538 
1539  FD_ZERO(&mask);
1540  FD_SET(d->fd_read, &mask);
1541  //Print("test fd %d\n",d->fd_read);
1542  /* check with select: chars waiting: no -> not ready */
1543  switch (si_select(d->fd_read+1, &mask, NULL, NULL, &wt))
1544  {
1545  case 0: /* not ready */ return "not ready";
1546  case -1: /*error*/ return "error";
1547  case 1: /*ready ? */ break;
1548  }
1549  /* yes: read 1 char*/
1550  /* if \n, check again with select else ungetc(c), ready*/
1551  int c=s_getc(d->f_read);
1552  //Print("try c=%d\n",c);
1553  if (c== -1) return "eof"; /* eof or error */
1554  else if (isdigit(c))
1555  { s_ungetc(c,d->f_read); return "ready"; }
1556  else if (c>' ')
1557  {
1558  Werror("unknown char in ssiLink(%d)",c);
1559  return "error";
1560  }
1561  /* else: next char */
1562  }
1563  }
1564  else if (strcmp(request, "read") == 0)
1565  {
1566  if (SI_LINK_R_OPEN_P(l) && (!s_iseof(d->f_read)) && (s_isready(d->f_read))) return "ready";
1567  else return "not ready";
1568  }
1569  else if (strcmp(request, "write") == 0)
1570  {
1571  if (SI_LINK_W_OPEN_P(l)) return "ready";
1572  else return "not ready";
1573  }
1574  else return "unknown status request";
1575 }
1576 
1577 int slStatusSsiL(lists L, int timeout)
1578 {
1579 // input: L: a list with links of type
1580 // ssi-connect, ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch.
1581 // Note: Not every entry in L must be set.
1582 // timeout: timeout for select in micro-seconds
1583 // or -1 for infinity
1584 // or 0 for polling
1585 // returns: ERROR (via Werror): L has wrong elements or link not open
1586 // -2: select returns an error
1587 // -1: the read state of all links is eof
1588 // 0: timeout (or polling): none ready,
1589 // i>0: (at least) L[i] is ready
1590  si_link l;
1591  ssiInfo *d;
1592  int d_fd;
1593  fd_set mask, fdmask;
1594  FD_ZERO(&fdmask);
1595  FD_ZERO(&mask);
1596  int max_fd=0; /* 1 + max fd in fd_set */
1597 
1598  /* timeout */
1599  struct timeval wt;
1600  struct timeval *wt_ptr=&wt;
1601  int startingtime = getRTimer()/TIMER_RESOLUTION; // in seconds
1602  if (timeout== -1)
1603  {
1604  wt_ptr=NULL;
1605  }
1606  else
1607  {
1608  wt.tv_sec = timeout / 1000000;
1609  wt.tv_usec = timeout % 1000000;
1610  }
1611 
1612  /* auxiliary variables */
1613  int i;
1614  int j;
1615  int k;
1616  int s;
1617  char fdmaskempty;
1618 
1619  /* check the links and fill in fdmask */
1620  /* check ssi links for ungetc_buf */
1621  for(i=L->nr; i>=0; i--)
1622  {
1623  if (L->m[i].Typ()!=DEF_CMD)
1624  {
1625  if (L->m[i].Typ()!=LINK_CMD)
1626  { WerrorS("all elements must be of type link"); return -2;}
1627  l=(si_link)L->m[i].Data();
1628  if(SI_LINK_OPEN_P(l)==0)
1629  { WerrorS("all links must be open"); return -2;}
1630  if (((strcmp(l->m->type,"ssi")!=0) && (strcmp(l->m->type,"MPtcp")!=0))
1631  || ((strcmp(l->mode,"fork")!=0) && (strcmp(l->mode,"tcp")!=0)
1632  && (strcmp(l->mode,"launch")!=0) && (strcmp(l->mode,"connect")!=0)))
1633  {
1634  WerrorS("all links must be of type ssi:fork, ssi:tcp, ssi:connect");
1635  return -2;
1636  }
1637  if (strcmp(l->m->type,"ssi")==0)
1638  {
1639  d=(ssiInfo*)l->data;
1640  d_fd=d->fd_read;
1641  if (!s_isready(d->f_read))
1642  {
1643  FD_SET(d_fd, &fdmask);
1644  if (d_fd > max_fd) max_fd=d_fd;
1645  }
1646  else
1647  return i+1;
1648  }
1649  else
1650  {
1651  Werror("wrong link type >>%s<<",l->m->type);
1652  return -2;
1653  }
1654  }
1655  }
1656  max_fd++;
1657 
1658 do_select:
1659  /* copy fdmask to mask */
1660  FD_ZERO(&mask);
1661  for(k = 0; k < max_fd; k++)
1662  {
1663  if(FD_ISSET(k, &fdmask))
1664  {
1665  FD_SET(k, &mask);
1666  }
1667  }
1668 
1669  /* check with select: chars waiting: no -> not ready */
1670  s = si_select(max_fd, &mask, NULL, NULL, wt_ptr);
1671  if (s==-1)
1672  {
1673  WerrorS("error in select call");
1674  return -2; /*error*/
1675  }
1676  if (s==0)
1677  {
1678  return 0; /*poll: not ready */
1679  }
1680  else /* s>0, at least one ready (the number of fd which are ready is s)*/
1681  {
1682  j=0;
1683  while (j<=max_fd) { if (FD_ISSET(j,&mask)) break; j++; }
1684  for(i=L->nr; i>=0; i--)
1685  {
1686  if (L->m[i].rtyp==LINK_CMD)
1687  {
1688  l=(si_link)L->m[i].Data();
1689  if (strcmp(l->m->type,"ssi")==0)
1690  {
1691  d=(ssiInfo*)l->data;
1692  d_fd=d->fd_read;
1693  if(j==d_fd) break;
1694  }
1695  else
1696  {
1697  Werror("wrong link type >>%s<<",l->m->type);
1698  return -2;
1699  }
1700  }
1701  }
1702  // only ssi links:
1703  loop
1704  {
1705  /* yes: read 1 char*/
1706  /* if \n, check again with select else ungetc(c), ready*/
1707  /* setting: d: current ssiInfo, j current fd, i current entry in L*/
1708  int c=s_getc(d->f_read);
1709  //Print("try c=%d\n",c);
1710  if (c== -1) /* eof */
1711  {
1712  FD_CLR(j,&fdmask);
1713  fdmaskempty = 1;
1714  for(k = 0; k < max_fd; k++)
1715  {
1716  if(FD_ISSET(k, &fdmask))
1717  {
1718  fdmaskempty = 0;
1719  break;
1720  }
1721  }
1722  if(fdmaskempty)
1723  {
1724  return -1;
1725  }
1726  if(timeout != -1)
1727  {
1728  timeout = si_max(0,
1729  timeout - 1000000*(getRTimer()/TIMER_RESOLUTION - startingtime));
1730  wt.tv_sec = timeout / 1000000;
1731  wt.tv_usec = (timeout % 1000000);
1732  }
1733  goto do_select;
1734  }
1735 
1736  else if (isdigit(c))
1737  { s_ungetc(c,d->f_read); return i+1; }
1738  else if (c>' ')
1739  {
1740  Werror("unknown char in ssiLink(%d)",c);
1741  return -2;
1742  }
1743  /* else: next char */
1744  goto do_select;
1745  }
1746  }
1747 }
1748 
1749 int ssiBatch(const char *host, const char * port)
1750 /* return 0 on success, >0 else*/
1751 {
1753  char *buf=(char*)omAlloc(256);
1754  sprintf(buf,"ssi:connect %s:%s",host,port);
1755  slInit(l, buf);
1756  if (slOpen(l,SI_LINK_OPEN,NULL)) return 1;
1758 
1759  idhdl id = enterid(omStrDup("link_ll"), 0, LINK_CMD, &IDROOT, FALSE);
1760  IDLINK(id) = l;
1761 
1762  loop
1763  {
1764  leftv h=ssiRead1(l); /*contains an exit.... */
1765  if (feErrors != NULL && *feErrors != '\0')
1766  {
1767  // handle errors:
1768  PrintS(feErrors); /* currently quite simple */
1769  *feErrors = '\0';
1770  }
1771  ssiWrite(l,h);
1772  h->CleanUp();
1773  omFreeBin(h, sleftv_bin);
1774  }
1775  /* never reached*/
1776  exit(0);
1777 }
1778 
1779 static int ssiReserved_P=0;
1781 static struct sockaddr_in ssiResverd_serv_addr;
1783 int ssiReservePort(int clients)
1784 {
1785  if (ssiReserved_P!=0)
1786  {
1787  WerrorS("ERROR already a reverved port requested");
1788  return 0;
1789  }
1790  int portno;
1791  ssiReserved_sockfd = socket(AF_INET, SOCK_STREAM, 0);
1792  if(ssiReserved_sockfd < 0)
1793  {
1794  WerrorS("ERROR opening socket");
1795  return 0;
1796  }
1797  memset((char *) &ssiResverd_serv_addr,0, sizeof(ssiResverd_serv_addr));
1798  portno = 1025;
1799  ssiResverd_serv_addr.sin_family = AF_INET;
1800  ssiResverd_serv_addr.sin_addr.s_addr = INADDR_ANY;
1801  do
1802  {
1803  portno++;
1804  ssiResverd_serv_addr.sin_port = htons(portno);
1805  if(portno > 50000)
1806  {
1807  WerrorS("ERROR on binding (no free port available?)");
1808  return 0;
1809  }
1810  }
1811  while(bind(ssiReserved_sockfd, (struct sockaddr *) &ssiResverd_serv_addr, sizeof(ssiResverd_serv_addr)) < 0);
1812  ssiReserved_P=portno;
1813  listen(ssiReserved_sockfd,clients);
1814  ssiReserved_Clients=clients;
1815  return portno;
1816 }
1817 
1818 extern si_link_extension si_link_root;
1820 {
1821  if (ssiReserved_P==0)
1822  {
1823  WerrorS("ERROR no reverved port requested");
1824  return NULL;
1825  }
1826  struct sockaddr_in cli_addr;
1827  int clilen = sizeof(cli_addr);
1828  int newsockfd = si_accept(ssiReserved_sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
1829  if(newsockfd < 0)
1830  {
1831  Werror("ERROR on accept (errno=%d)",errno);
1832  return NULL;
1833  }
1835  si_link_extension s = si_link_root;
1836  si_link_extension prev = s;
1837  while (strcmp(s->type, "ssi") != 0)
1838  {
1839  if (s->next == NULL)
1840  {
1841  prev = s;
1842  s = NULL;
1843  break;
1844  }
1845  else
1846  {
1847  s = s->next;
1848  }
1849  }
1850  if (s != NULL)
1851  l->m = s;
1852  else
1853  {
1854  si_link_extension ns = (si_link_extension)omAlloc0Bin(s_si_link_extension_bin);
1855  prev->next=slInitSsiExtension(ns);
1856  l->m = prev->next;
1857  }
1858  l->name=omStrDup("");
1859  l->mode=omStrDup("tcp");
1860  l->ref=1;
1861  ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo));
1862  l->data=d;
1863  d->fd_read = newsockfd;
1864  d->fd_write = newsockfd;
1865  d->f_read = s_open(newsockfd);
1866  d->f_write = fdopen(newsockfd, "w");
1869  if (ssiReserved_Clients<=0)
1870  {
1871  ssiReserved_P=0;
1872  si_close(ssiReserved_sockfd);
1873  }
1874  return l;
1875 }
1876 /*---------------------------------------------------------------------*/
1877 /**
1878  * @brief additional default signal handler
1879 
1880  // some newer Linux version cannot have SIG_IGN for SIGCHLD,
1881  // so use this nice routine here:
1882  // SuSe 9.x reports -1 always
1883  // Redhat 9.x/FC x reports sometimes -1
1884  // see also: hpux_system
1885  // also needed by getrusage (timer etc.)
1886 
1887  @param[in] sig
1888 **/
1889 /*---------------------------------------------------------------------*/
1890 void sig_chld_hdl(int)
1891 {
1892  pid_t kidpid;
1893  int status;
1894 
1895  loop
1896  {
1897  kidpid = si_waitpid(-1, &status, WNOHANG);
1898  if (kidpid==-1)
1899  {
1900  /* continue on interruption (EINTR): */
1901  if (errno == EINTR) continue;
1902  /* break on anything else (EINVAL or ECHILD according to manpage): */
1903  break;
1904  }
1905  else if (kidpid==0) break; /* no more children to process, so break */
1906 
1907  //printf("Child %ld terminated\n", kidpid);
1909  while((hh!=NULL)&&(ssiToBeClosed_inactive))
1910  {
1911  if((hh->l!=NULL) && (hh->l->m->Open==ssiOpen))
1912  {
1913  ssiInfo *d = (ssiInfo *)hh->l->data;
1914  if(d->pid==kidpid)
1915  {
1917  {
1919  slClose(hh->l);
1921  break;
1922  }
1923  else break;
1924  }
1925  else hh=(link_list)hh->next;
1926  }
1927  else hh=(link_list)hh->next;
1928  }
1929  }
1930 }
1931 
1933 {
1934  int type_id = IDTYP(h);
1935 
1936  // C-proc not to be dumped, also LIB-proc not
1937  if (type_id == PROC_CMD)
1938  {
1939  if (IDPROC(h)->language == LANG_C) return FALSE;
1940  if (IDPROC(h)->libname != NULL) return FALSE;
1941  }
1942  // do not dump links
1943  if (type_id == LINK_CMD) return FALSE;
1944 
1945  // do not dump ssi internal rings: ssiRing*
1946  if ((type_id == RING_CMD) && (strncmp(IDID(h),"ssiRing",7)==0))
1947  return FALSE;
1948 
1949  command D=(command)omAlloc0(sizeof(*D));
1950  sleftv tmp;
1951  memset(&tmp,0,sizeof(tmp));
1952  tmp.rtyp=COMMAND;
1953  tmp.data=D;
1954 
1955  if (type_id == PACKAGE_CMD)
1956  {
1957  // do not dump Top
1958  if (strcmp(IDID(h), "Top") == 0) return FALSE;
1959  package p=(package)IDDATA(h);
1960  // dump Singular-packages as load("...");
1961  if (p->language==LANG_SINGULAR)
1962  {
1963  D->op=LOAD_CMD;
1964  D->argc=1;
1965  D->arg1.rtyp=STRING_CMD;
1966  D->arg1.data=p->libname;
1967  ssiWrite(l,&tmp);
1968  omFree(D);
1969  return FALSE;
1970  }
1971  }
1972 
1973  // handle qrings separately
1974  //if (type_id == QRING_CMD)
1975  // return DumpSsiQringQring(l, h);
1976 
1977  // put type and name
1978  //Print("generic dump:%s,%s\n",IDID(h),Tok2Cmdname(IDTYP(h)));
1979  D->op='=';
1980  D->argc=2;
1981  D->arg1.rtyp=DEF_CMD;
1982  D->arg1.name=IDID(h);
1983  D->arg2.rtyp=IDTYP(h);
1984  D->arg2.data=IDDATA(h);
1985  ssiWrite(l,&tmp);
1986  omFree(D);
1987  return FALSE;
1988 }
1990 {
1991  if (h == NULL) return FALSE;
1992 
1993  if (ssiDumpIter(l, IDNEXT(h))) return TRUE;
1994 
1995  // need to set the ring before writing it, otherwise we get in
1996  // trouble with minpoly
1997  if (IDTYP(h) == RING_CMD || IDTYP(h) == QRING_CMD)
1998  rSetHdl(h);
1999 
2000  if (DumpSsiIdhdl(l, h)) return TRUE;
2001 
2002  // do not dump ssi internal rings: ssiRing*
2003  // but dump objects of all other rings
2004  if ((IDTYP(h) == RING_CMD || IDTYP(h) == QRING_CMD)
2005  && (strncmp(IDID(h),"ssiRing",7)!=0))
2006  return ssiDumpIter(l, IDRING(h)->idroot);
2007  else
2008  return FALSE;
2009 }
2011 {
2012  idhdl h = IDROOT, rh = currRingHdl;
2013  BOOLEAN status = ssiDumpIter(l, h);
2014 
2015  //if (! status ) status = DumpAsciiMaps(fd, h, NULL);
2016 
2017  if (currRingHdl != rh) rSetHdl(rh);
2018  //fprintf(fd, "option(set, intvec(%d, %d));\n", si_opt_1, si_opt_2);
2019 
2020  return status;
2021 }
2023 {
2024  ssiInfo *d=(ssiInfo*)l->data;
2025  loop
2026  {
2027  if (!SI_LINK_OPEN_P(l)) break;
2028  if (s_iseof(d->f_read)) break;
2029  leftv h=ssiRead1(l); /*contains an exit.... */
2030  if (feErrors != NULL && *feErrors != '\0')
2031  {
2032  // handle errors:
2033  PrintS(feErrors); /* currently quite simple */
2034  return TRUE;
2035  *feErrors = '\0';
2036  }
2037  h->CleanUp();
2038  omFreeBin(h, sleftv_bin);
2039  }
2040  return FALSE;
2041 }
2042 // ----------------------------------------------------------------
2043 // format
2044 // 1 int %d
2045 // 2 string <len> %s
2046 // 3 number
2047 // 4 bigint 4 %d or 3 <mpz_t>
2048 // 5 ring
2049 // 6 poly
2050 // 7 ideal
2051 // 8 matrix
2052 // 9 vector
2053 // 10 module
2054 // 11 command
2055 // 12 def <len> %s
2056 // 13 proc <len> %s
2057 // 14 list %d <elem1> ....
2058 // 15 setring .......
2059 // 16 nothing
2060 // 17 intvec <len> ...
2061 // 18 intmat
2062 // 19 bigintmat <r> <c> ...
2063 // 20 blackbox <name> 1 <len> ...
2064 // 21 attrib <bit-attrib> <len> <a-name1> <val1>... <data>
2065 //
2066 // 98: verify version: <ssi-version> <MAX_TOK> <OPT1> <OPT2>
2067 // 99: quit Singular
for idElimination, like a, except pFDeg, pWeigths ignore it
Definition: ring.h:684
const const intvec const intvec const ring _currRing const const intvec const intvec const ring _currRing int
Definition: gb_hack.h:53
n_coeffType rFieldType(ring r)
Definition: ring.cc:5080
int s_readbytes(char *buff, int len, s_buff F)
Definition: s_buff.cc:176
const CanonicalForm int s
Definition: facAbsFact.cc:55
unsigned si_opt_1
Definition: options.c:5
sleftv * m
Definition: lists.h:45
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition: feread.cc:33
for int64 weights
Definition: ring.h:664
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
void rem(unsigned long *a, unsigned long *q, unsigned long p, int &dega, int degq)
Definition: minpoly.cc:574
ip_command * command
Definition: ipid.h:24
const poly a
Definition: syzextra.cc:212
#define Print
Definition: emacs.cc:83
Definition: tok.h:85
#define IDLINK(a)
Definition: ipid.h:137
Definition: attrib.h:14
BITSET flag
Definition: subexpr.h:91
Definition: lists.h:22
#define TEST_OPT_PROT
Definition: options.h:98
loop
Definition: myNF.cc:98
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
Definition: coeffs.h:37
#define IDID(a)
Definition: ipid.h:121
int getRTimer()
Definition: timer.cc:172
#define FALSE
Definition: auxiliary.h:140
attr * Attribute()
Definition: subexpr.cc:1346
Definition: tok.h:42
return P p
Definition: myNF.cc:203
Matrices of numbers.
Definition: bigintmat.h:32
f
Definition: cfModGcd.cc:4022
omBin sip_sideal_bin
Definition: simpleideals.cc:30
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition: p_polys.h:236
int s_free(s_buff &F)
Definition: s_buff.cc:45
#define p_GetComp(p, r)
Definition: monomials.h:72
Definition: tok.h:167
static FORCE_INLINE number n_ReadFd(s_buff f, const coeffs r)
io via ssi:
Definition: coeffs.h:973
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:537
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define IDNEXT(a)
Definition: ipid.h:117
language_defs language
Definition: subexpr.h:58
const ideal
Definition: gb_hack.h:42
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
#define IDROOT
Definition: ipid.h:20
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:531
char * fe_fgets_dummy(const char *, char *, int)
Definition: feread.cc:418
void m2_end(int i)
Definition: misc_ip.cc:1074
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:444
#define TRUE
Definition: auxiliary.h:144
int length() const
Definition: intvec.h:85
void * ADDRESS
Definition: auxiliary.h:161
int length()
Definition: bigintmat.h:127
void WerrorS(const char *s)
Definition: feFopen.cc:23
int k
Definition: cfEzgcd.cc:93
#define TEST_OPT_DEBUG
Definition: options.h:103
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy ...
Definition: monomials.h:51
int s_close(s_buff &F)
Definition: s_buff.cc:56
#define WarnS
Definition: emacs.cc:81
#define BITSET
Definition: structs.h:17
coeffs coeffs_BIGINT
Definition: ipid.cc:53
int Typ()
Definition: subexpr.cc:949
#define omAlloc(size)
Definition: omAllocDecl.h:210
Definition: tok.h:97
const char * Name()
Definition: subexpr.h:121
static int pLength(poly a)
Definition: p_polys.h:189
int int kStrategy strat if(h==NULL) return NULL
Definition: idrec.h:34
#define IDHDL
Definition: tok.h:35
int s_getc(s_buff F)
Definition: s_buff.cc:66
omBin procinfo_bin
Definition: subexpr.cc:51
void * data
Definition: subexpr.h:89
#define mflush()
Definition: reporter.h:42
char * procname
Definition: subexpr.h:56
#define pIter(p)
Definition: monomials.h:44
poly res
Definition: myNF.cc:322
Definition: subexpr.h:20
#define M
Definition: sirandom.c:24
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:12
#define IDTYP(a)
Definition: ipid.h:118
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:256
char * feErrors
Definition: reporter.cc:47
const ring r
Definition: syzextra.cc:208
BOOLEAN singular_in_batchmode
Definition: cntrlc.cc:78
#define TIMER_RESOLUTION
Definition: mod2.h:40
Definition: intvec.h:16
char * libname
Definition: subexpr.h:55
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
void rKill(ring r)
Definition: ipshell.cc:5815
int s_readint(s_buff F)
Definition: s_buff.cc:120
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent : the integer VarOffset encodes:
Definition: p_polys.h:465
int j
Definition: myNF.cc:70
Definition: tok.h:58
const char * name
Definition: subexpr.h:88
#define omFree(addr)
Definition: omAllocDecl.h:261
polyrec * poly
Definition: hilb.h:10
The main handler for Singular numbers which are suitable for Singular polynomials.
FILE * myfopen(const char *path, const char *mode)
Definition: feFopen.cc:166
int status int void * buf
Definition: si_signals.h:58
while(1)
Definition: libparse.cc:1442
void s_ungetc(int c, s_buff F)
Definition: s_buff.cc:107
D(ideal gnc_gr_bba(const ideal, const ideal, const intvec *, const intvec *, kStrategy, const ring _currRing)) D(ideal gnc_gr_mora(const ideal
Modified Plural's Buchberger's algorithmus.
procinfodata data
Definition: subexpr.h:62
ip_smatrix * matrix
idhdl currRingHdl
Definition: ipid.cc:64
int raise_rlimit_nproc()
Definition: rlimit.c:18
int m
Definition: cfEzgcd.cc:119
ring rDefault(const coeffs cf, int N, char **n, int ord_size, int *ord, int *block0, int *block1, int **wvhdl)
Definition: ring.cc:113
struct for passing initialization parameters to naInitChar
Definition: transext.h:92
static int si_max(const int a, const int b)
Definition: auxiliary.h:166
idrec * idhdl
Definition: ring.h:18
omBin sleftv_bin
Definition: subexpr.cc:50
int i
Definition: cfEzgcd.cc:123
Induced (Schreyer) ordering.
Definition: ring.h:686
void PrintS(const char *s)
Definition: reporter.cc:294
static BOOLEAN rField_is_Q(const ring r)
Definition: ring.h:452
int s_iseof(s_buff F)
Definition: s_buff.cc:260
Definition: tok.h:88
#define IDELEMS(i)
Definition: simpleideals.h:19
BOOLEAN rEqual(ring r1, ring r2, BOOLEAN qr)
returns TRUE, if r1 equals r2 FALSE, otherwise Equality is determined componentwise, if qr == 1, then qrideal equality is tested, as well
Definition: ring.cc:1594
int lSize(lists L)
Definition: lists.cc:25
int cols() const
Definition: bigintmat.h:128
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
#define p_Test(p, r)
Definition: p_polys.h:160
leftv next
Definition: subexpr.h:87
void rChangeCurrRing(ring r)
Definition: polys.cc:14
static BOOLEAN rField_is_Zp(const ring r)
Definition: ring.h:446
INLINE_THIS void Init(int l=0)
Definition: lists.h:66
matrix mpNew(int r, int c)
create a r x c zero-matrix
Definition: matpol.cc:48
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:850
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
#define IDPROC(a)
Definition: ipid.h:139
ideal idInit(int idsize, int rank)
Definition: simpleideals.cc:40
static FORCE_INLINE void n_WriteFd(number a, FILE *f, const coeffs r)
io via ssi:
Definition: coeffs.h:969
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent : VarOffset encodes the position in p->exp
Definition: p_polys.h:484
int nr
Definition: lists.h:43
int rows() const
Definition: bigintmat.h:129
char name(const Variable &v)
Definition: variable.h:95
CanonicalForm cf
Definition: cfModGcd.cc:4024
#define MATCOLS(i)
Definition: matpol.h:28
Definition: tok.h:95
#define NULL
Definition: omList.c:10
int cols() const
Definition: intvec.h:86
int * status
Definition: si_signals.h:50
slists * lists
Definition: mpr_numeric.h:146
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic ...
Definition: coeffs.h:34
short lev
Definition: idrec.h:45
int rows() const
Definition: intvec.h:87
#define IDRING(a)
Definition: ipid.h:126
#define SR_INT
Definition: longrat.h:65
int blackboxIsCmd(const char *n, int &tok)
used by scanner: returns ROOT_DECL for known types (and the type number in tok)
Definition: blackbox.cc:191
attr next
Definition: attrib.h:20
int rtyp
Definition: subexpr.h:92
#define SIPC_MAX_SEMAPHORES
Definition: simpleipc.h:10
void CleanUp(ring r=currRing)
Definition: subexpr.cc:301
#define pNext(p)
Definition: monomials.h:43
void * Data()
Definition: subexpr.cc:1091
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:436
#define pSetCoeff0(p, n)
Definition: monomials.h:67
Definition: tok.h:96
Definition: tok.h:126
#define SR_HDL(A)
Definition: tgb.cc:35
int s_isready(s_buff F)
Definition: s_buff.cc:93
#define MATROWS(i)
Definition: matpol.h:27
static jList * T
Definition: janet.cc:37
#define IDDATA(a)
Definition: ipid.h:125
void rSetHdl(idhdl h)
Definition: ipshell.cc:4821
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
int sem_acquired[SIPC_MAX_SEMAPHORES]
Definition: semaphore.c:30
s_buff s_open_by_name(const char *n)
Definition: s_buff.cc:39
unsigned si_opt_2
Definition: options.c:6
char * iiGetLibProcBuffer(procinfo *pi, int part)
Definition: iplib.cc:200
static Poly * h
Definition: janet.cc:978
int BOOLEAN
Definition: auxiliary.h:131
static poly p_Init(const ring r, omBin bin)
Definition: p_polys.h:1248
const poly b
Definition: syzextra.cc:213
#define NONE
Definition: tok.h:170
void Werror(const char *fmt,...)
Definition: reporter.cc:199
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:94
s_buff s_open(int fd)
Definition: s_buff.cc:31
procinfo * procinfov
Definition: structs.h:63
#define COMMAND
Definition: tok.h:33
#define MATELEM(mat, i, j)
Definition: matpol.h:29
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:20
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:316
#define omStrDup(s)
Definition: omAllocDecl.h:263