My Project  UNKNOWN_GIT_VERSION
Macros | Functions | Variables
ssiLink.cc File Reference
#include "kernel/mod2.h"
#include "omalloc/omalloc.h"
#include "misc/intvec.h"
#include "misc/options.h"
#include "reporter/si_signals.h"
#include "reporter/s_buff.h"
#include "coeffs/bigintmat.h"
#include "coeffs/longrat.h"
#include "polys/monomials/ring.h"
#include "polys/monomials/p_polys.h"
#include "polys/ext_fields/transext.h"
#include "polys/simpleideals.h"
#include "polys/matpol.h"
#include "kernel/oswrapper/timer.h"
#include "kernel/oswrapper/feread.h"
#include "kernel/oswrapper/rlimit.h"
#include "Singular/tok.h"
#include "Singular/ipid.h"
#include "Singular/ipshell.h"
#include "Singular/subexpr.h"
#include "Singular/links/silink.h"
#include "Singular/cntrlc.h"
#include "Singular/lists.h"
#include "Singular/blackbox.h"
#include "Singular/links/ssiLink.h"
#include "Singular/links/simpleipc.h"
#include <errno.h>
#include <sys/types.h>
#include <ctype.h>
#include <netdb.h>
#include <netinet/in.h>

Go to the source code of this file.

Macros

#define TRANSEXT_PRIVATES   1 /* allow access to transext internals */
 
#define SSI_VERSION   12
 

Functions

void ssiWritePoly_R (const ssiInfo *d, int typ, poly p, const ring r)
 
void ssiWriteIdeal_R (const ssiInfo *d, int typ, const ideal I, const ring r)
 
poly ssiReadPoly_R (const ssiInfo *D, const ring r)
 
ideal ssiReadIdeal_R (const ssiInfo *d, const ring r)
 
BOOLEAN ssiSetCurrRing (const ring r)
 
void ssiWriteInt (const ssiInfo *d, const int i)
 
void ssiWriteString (const ssiInfo *d, const char *s)
 
void ssiWriteBigInt (const ssiInfo *d, const number n)
 
void ssiWriteNumber_CF (const ssiInfo *d, const number n, const coeffs cf)
 
void ssiWriteNumber (const ssiInfo *d, const number n)
 
void ssiWriteRing_R (ssiInfo *d, const ring r)
 
void ssiWriteRing (ssiInfo *d, const ring r)
 
void ssiWritePoly (const ssiInfo *d, int typ, poly p)
 
void ssiWriteIdeal (const ssiInfo *d, int typ, const ideal I)
 
void ssiWriteCommand (si_link l, command D)
 
void ssiWriteProc (const ssiInfo *d, procinfov p)
 
void ssiWriteList (si_link l, lists dd)
 
void ssiWriteIntvec (const ssiInfo *d, intvec *v)
 
void ssiWriteIntmat (const ssiInfo *d, intvec *v)
 
void ssiWriteBigintmat (const ssiInfo *d, bigintmat *v)
 
char * ssiReadString (const ssiInfo *d)
 
int ssiReadInt (s_buff fich)
 
number ssiReadNumber_CF (const ssiInfo *d, const coeffs cf)
 
number ssiReadBigInt (const ssiInfo *d)
 
number ssiReadNumber (const ssiInfo *d)
 
ring ssiReadRing (const ssiInfo *d)
 
poly ssiReadPoly (const ssiInfo *D)
 
ideal ssiReadIdeal (const ssiInfo *d)
 
matrix ssiReadMatrix (const ssiInfo *d)
 
command ssiReadCommand (si_link l)
 
procinfov ssiReadProc (const ssiInfo *d)
 
lists ssiReadList (si_link l)
 
intvecssiReadIntvec (const ssiInfo *d)
 
intvecssiReadIntmat (const ssiInfo *d)
 
bigintmatssiReadBigintmat (const ssiInfo *d)
 
void ssiReadBlackbox (leftv res, si_link l)
 
void ssiReadAttrib (leftv res, si_link l)
 
BOOLEAN ssiOpen (si_link l, short flag, leftv u)
 
BOOLEAN ssiPrepClose (si_link l)
 
BOOLEAN ssiClose (si_link l)
 
leftv ssiRead1 (si_link l)
 
BOOLEAN ssiSetRing (si_link l, ring r, BOOLEAN send)
 
BOOLEAN ssiWrite (si_link l, leftv data)
 
BOOLEAN ssiGetDump (si_link l)
 
BOOLEAN ssiDump (si_link l)
 
si_link_extension slInitSsiExtension (si_link_extension s)
 
const char * slStatusSsi (si_link l, const char *request)
 
int slStatusSsiL (lists L, int timeout)
 
int ssiBatch (const char *host, const char *port)
 
int ssiReservePort (int clients)
 
si_link ssiCommandLink ()
 
void sig_chld_hdl (int)
 additional default signal handler More...
 
static BOOLEAN DumpSsiIdhdl (si_link l, idhdl h)
 
static BOOLEAN ssiDumpIter (si_link l, idhdl h)
 

Variables

link_list ssiToBeClosed =NULL
 
volatile BOOLEAN ssiToBeClosed_inactive =TRUE
 
static int ssiReserved_P =0
 
static int ssiReserved_sockfd
 
static struct sockaddr_in ssiResverd_serv_addr
 
static int ssiReserved_Clients
 
si_link_extension si_link_root
 

Macro Definition Documentation

◆ SSI_VERSION

#define SSI_VERSION   12

Definition at line 53 of file ssiLink.cc.

◆ TRANSEXT_PRIVATES

#define TRANSEXT_PRIVATES   1 /* allow access to transext internals */

Definition at line 8 of file ssiLink.cc.

Function Documentation

◆ DumpSsiIdhdl()

static BOOLEAN DumpSsiIdhdl ( si_link  l,
idhdl  h 
)
static

Definition at line 2014 of file ssiLink.cc.

2015 {
2016  int type_id = IDTYP(h);
2017 
2018  // C-proc not to be dumped, also LIB-proc not
2019  if (type_id == PROC_CMD)
2020  {
2021  if (IDPROC(h)->language == LANG_C) return FALSE;
2022  if (IDPROC(h)->libname != NULL) return FALSE;
2023  }
2024  // do not dump links
2025  if (type_id == LINK_CMD) return FALSE;
2026 
2027  // do not dump ssi internal rings: ssiRing*
2028  if ((type_id == RING_CMD) && (strncmp(IDID(h),"ssiRing",7)==0))
2029  return FALSE;
2030 
2031  // do not dump default cring:
2032  if (type_id == CRING_CMD)
2033  {
2034  if (strcmp(IDID(h),"ZZ")==0) return FALSE;
2035  if (strcmp(IDID(h),"QQ")==0) return FALSE;
2036  #ifdef SINGULAR_4_2
2037  if (strcmp(IDID(h),"AE")==0) return FALSE;
2038  if (strcmp(IDID(h),"QAE")==0) return FALSE;
2039  #endif
2040  }
2041 
2042  command D=(command)omAlloc0(sizeof(*D));
2043  sleftv tmp;
2044  memset(&tmp,0,sizeof(tmp));
2045  tmp.rtyp=COMMAND;
2046  tmp.data=D;
2047 
2048  if (type_id == PACKAGE_CMD)
2049  {
2050  // do not dump Top, Standard
2051  if ((strcmp(IDID(h), "Top") == 0)
2052  || (strcmp(IDID(h), "Standard") == 0))
2053  {
2054  omFreeSize(D,sizeof(*D));
2055  return FALSE;
2056  }
2057  package p=(package)IDDATA(h);
2058  // dump Singular-packages as LIB("...");
2059  if (p->language==LANG_SINGULAR)
2060  {
2061  D->op=LOAD_CMD;
2062  D->argc=2;
2063  D->arg1.rtyp=STRING_CMD;
2064  D->arg1.data=p->libname;
2065  D->arg2.rtyp=STRING_CMD;
2066  D->arg2.data=(char*)"with";
2067  ssiWrite(l,&tmp);
2068  omFreeSize(D,sizeof(*D));
2069  return FALSE;
2070  }
2071  // dump Singular-packages as load("...");
2072  else if (p->language==LANG_C)
2073  {
2074  D->op=LOAD_CMD;
2075  D->argc=1;
2076  D->arg1.rtyp=STRING_CMD;
2077  D->arg1.data=p->libname;
2078  ssiWrite(l,&tmp);
2079  omFreeSize(D,sizeof(*D));
2080  return FALSE;
2081  }
2082  }
2083 
2084  // put type and name
2085  //Print("generic dump:%s,%s\n",IDID(h),Tok2Cmdname(IDTYP(h)));
2086  D->op='=';
2087  D->argc=2;
2088  D->arg1.rtyp=DEF_CMD;
2089  D->arg1.name=IDID(h);
2090  D->arg2.rtyp=IDTYP(h);
2091  D->arg2.data=IDDATA(h);
2092  ssiWrite(l,&tmp);
2093  omFreeSize(D,sizeof(*D));
2094  return FALSE;
2095 }
#define D(A)
Definition: gentable.cc:131
Class used for (list of) interpreter objects.
Definition: subexpr.h:82
ip_command * command
Definition: ipid.h:22
#define IDID(a)
Definition: ipid.h:117
#define FALSE
Definition: auxiliary.h:94
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
Definition: tok.h:119
void * data
Definition: subexpr.h:88
Definition: subexpr.h:22
#define IDTYP(a)
Definition: ipid.h:114
Definition: tok.h:56
Definition: tok.h:58
#define IDPROC(a)
Definition: ipid.h:135
Definition: tok.h:117
#define NULL
Definition: omList.c:10
int rtyp
Definition: subexpr.h:91
int p
Definition: cfModGcd.cc:4019
#define IDDATA(a)
Definition: ipid.h:121
static Poly * h
Definition: janet.cc:972
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:93
#define COMMAND
Definition: tok.h:29

◆ sig_chld_hdl()

void sig_chld_hdl ( int  )

additional default signal handler

some newer Linux version cannot have SIG_IGN for SIGCHLD, so use this nice routine here: SuSe 9.x reports -1 always Redhat 9.x/FC x reports sometimes -1 see also: hpux_system also needed by getrusage (timer etc.)

Parameters
[in]sig

Definition at line 1972 of file ssiLink.cc.

1973 {
1974  pid_t kidpid;
1975  int status;
1976 
1977  loop
1978  {
1979  kidpid = si_waitpid(-1, &status, WNOHANG);
1980  if (kidpid==-1)
1981  {
1982  /* continue on interruption (EINTR): */
1983  if (errno == EINTR) continue;
1984  /* break on anything else (EINVAL or ECHILD according to manpage): */
1985  break;
1986  }
1987  else if (kidpid==0) break; /* no more children to process, so break */
1988 
1989  //printf("Child %ld terminated\n", kidpid);
1991  while((hh!=NULL)&&(ssiToBeClosed_inactive))
1992  {
1993  if((hh->l!=NULL) && (hh->l->m->Open==ssiOpen))
1994  {
1995  ssiInfo *d = (ssiInfo *)hh->l->data;
1996  if(d->pid==kidpid)
1997  {
1999  {
2001  slClose(hh->l);
2003  break;
2004  }
2005  else break;
2006  }
2007  else hh=(link_list)hh->next;
2008  }
2009  else hh=(link_list)hh->next;
2010  }
2011  }
2012 }
Definition: s_buff.h:20
#define FALSE
Definition: auxiliary.h:94
#define TRUE
Definition: auxiliary.h:98
pid_t pid
Definition: s_buff.h:25
#define loop
Definition: structs.h:78
#define NULL
Definition: omList.c:10
int * status
Definition: si_signals.h:51

◆ slInitSsiExtension()

si_link_extension slInitSsiExtension ( si_link_extension  s)

Definition at line 1585 of file ssiLink.cc.

1586 {
1587  s->Open=ssiOpen;
1588  s->Close=ssiClose;
1589  s->Kill=ssiClose;
1590  s->Read=ssiRead1;
1591  s->Read2=(slRead2Proc)NULL;
1592  s->Write=ssiWrite;
1593  s->Dump=ssiDump;
1594  s->GetDump=ssiGetDump;
1595 
1596  s->Status=slStatusSsi;
1597  s->SetRing=ssiSetRing;
1598  s->type="ssi";
1599  return s;
1600 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define NULL
Definition: omList.c:10

◆ slStatusSsi()

const char* slStatusSsi ( si_link  l,
const char *  request 
)

Definition at line 1602 of file ssiLink.cc.

1603 {
1604  ssiInfo *d=(ssiInfo*)l->data;
1605  if (d==NULL) return "not open";
1606  if (((strcmp(l->mode,"fork")==0)
1607  ||(strcmp(l->mode,"tcp")==0)
1608  ||(strcmp(l->mode,"connect")==0))
1609  && (strcmp(request, "read") == 0))
1610  {
1611  fd_set mask;
1612  struct timeval wt;
1613  if (s_isready(d->f_read)) return "ready";
1614  loop
1615  {
1616  /* Don't block. Return socket status immediately. */
1617  wt.tv_sec = 0;
1618  wt.tv_usec = 0;
1619 
1620  FD_ZERO(&mask);
1621  FD_SET(d->fd_read, &mask);
1622  //Print("test fd %d\n",d->fd_read);
1623  /* check with select: chars waiting: no -> not ready */
1624  switch (si_select(d->fd_read+1, &mask, NULL, NULL, &wt))
1625  {
1626  case 0: /* not ready */ return "not ready";
1627  case -1: /*error*/ return "error";
1628  case 1: /*ready ? */ break;
1629  }
1630  /* yes: read 1 char*/
1631  /* if \n, check again with select else ungetc(c), ready*/
1632  int c=s_getc(d->f_read);
1633  //Print("try c=%d\n",c);
1634  if (c== -1) return "eof"; /* eof or error */
1635  else if (isdigit(c))
1636  { s_ungetc(c,d->f_read); return "ready"; }
1637  else if (c>' ')
1638  {
1639  Werror("unknown char in ssiLink(%d)",c);
1640  return "error";
1641  }
1642  /* else: next char */
1643  }
1644  }
1645  else if (strcmp(request, "read") == 0)
1646  {
1647  if (SI_LINK_R_OPEN_P(l) && (!s_iseof(d->f_read)) && (s_isready(d->f_read))) return "ready";
1648  else return "not ready";
1649  }
1650  else if (strcmp(request, "write") == 0)
1651  {
1652  if (SI_LINK_W_OPEN_P(l)) return "ready";
1653  else return "not ready";
1654  }
1655  else return "unknown status request";
1656 }
Definition: s_buff.h:20
#define loop
Definition: structs.h:78
int s_getc(s_buff F)
Definition: s_buff.cc:56
s_buff f_read
Definition: s_buff.h:22
if(yy_init)
Definition: libparse.cc:1418
void s_ungetc(int c, s_buff F)
Definition: s_buff.cc:97
int s_iseof(s_buff F)
Definition: s_buff.cc:250
#define NULL
Definition: omList.c:10
int fd_read
Definition: s_buff.h:26
int s_isready(s_buff F)
Definition: s_buff.cc:83
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int l
Definition: cfEzgcd.cc:93

◆ slStatusSsiL()

int slStatusSsiL ( lists  L,
int  timeout 
)

Definition at line 1658 of file ssiLink.cc.

1659 {
1660 // input: L: a list with links of type
1661 // ssi-connect, ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch.
1662 // Note: Not every entry in L must be set.
1663 // timeout: timeout for select in micro-seconds
1664 // or -1 for infinity
1665 // or 0 for polling
1666 // returns: ERROR (via Werror): L has wrong elements or link not open
1667 // -2: select returns an error
1668 // -1: the read state of all links is eof
1669 // 0: timeout (or polling): none ready,
1670 // i>0: (at least) L[i] is ready
1671  si_link l;
1672  ssiInfo *d;
1673  int d_fd;
1674  fd_set mask, fdmask;
1675  FD_ZERO(&fdmask);
1676  FD_ZERO(&mask);
1677  int max_fd=0; /* 1 + max fd in fd_set */
1678 
1679  /* timeout */
1680  struct timeval wt;
1681  struct timeval *wt_ptr=&wt;
1682  int startingtime = getRTimer()/TIMER_RESOLUTION; // in seconds
1683  if (timeout== -1)
1684  {
1685  wt_ptr=NULL;
1686  }
1687  else
1688  {
1689  wt.tv_sec = timeout / 1000000;
1690  wt.tv_usec = timeout % 1000000;
1691  }
1692 
1693  /* auxiliary variables */
1694  int i;
1695  int j;
1696  int k;
1697  int s;
1698  char fdmaskempty;
1699 
1700  /* check the links and fill in fdmask */
1701  /* check ssi links for ungetc_buf */
1702  for(i=L->nr; i>=0; i--)
1703  {
1704  if (L->m[i].Typ()!=DEF_CMD)
1705  {
1706  if (L->m[i].Typ()!=LINK_CMD)
1707  { WerrorS("all elements must be of type link"); return -2;}
1708  l=(si_link)L->m[i].Data();
1709  if(SI_LINK_OPEN_P(l)==0)
1710  { WerrorS("all links must be open"); return -2;}
1711  if (((strcmp(l->m->type,"ssi")!=0) && (strcmp(l->m->type,"MPtcp")!=0))
1712  || ((strcmp(l->mode,"fork")!=0) && (strcmp(l->mode,"tcp")!=0)
1713  && (strcmp(l->mode,"launch")!=0) && (strcmp(l->mode,"connect")!=0)))
1714  {
1715  WerrorS("all links must be of type ssi:fork, ssi:tcp, ssi:connect");
1716  return -2;
1717  }
1718  if (strcmp(l->m->type,"ssi")==0)
1719  {
1720  d=(ssiInfo*)l->data;
1721  d_fd=d->fd_read;
1722  if (!s_isready(d->f_read))
1723  {
1724  FD_SET(d_fd, &fdmask);
1725  if (d_fd > max_fd) max_fd=d_fd;
1726  }
1727  else
1728  return i+1;
1729  }
1730  else
1731  {
1732  Werror("wrong link type >>%s<<",l->m->type);
1733  return -2;
1734  }
1735  }
1736  }
1737  max_fd++;
1738 
1739 do_select:
1740  /* copy fdmask to mask */
1741  FD_ZERO(&mask);
1742  for(k = 0; k < max_fd; k++)
1743  {
1744  if(FD_ISSET(k, &fdmask))
1745  {
1746  FD_SET(k, &mask);
1747  }
1748  }
1749 
1750  /* check with select: chars waiting: no -> not ready */
1751  s = si_select(max_fd, &mask, NULL, NULL, wt_ptr);
1752  if (s==-1)
1753  {
1754  WerrorS("error in select call");
1755  return -2; /*error*/
1756  }
1757  if (s==0)
1758  {
1759  return 0; /*poll: not ready */
1760  }
1761  else /* s>0, at least one ready (the number of fd which are ready is s)*/
1762  {
1763  j=0;
1764  while (j<=max_fd) { if (FD_ISSET(j,&mask)) break; j++; }
1765  for(i=L->nr; i>=0; i--)
1766  {
1767  if (L->m[i].rtyp==LINK_CMD)
1768  {
1769  l=(si_link)L->m[i].Data();
1770  if (strcmp(l->m->type,"ssi")==0)
1771  {
1772  d=(ssiInfo*)l->data;
1773  d_fd=d->fd_read;
1774  if(j==d_fd) break;
1775  }
1776  else
1777  {
1778  Werror("wrong link type >>%s<<",l->m->type);
1779  return -2;
1780  }
1781  }
1782  }
1783  // only ssi links:
1784  loop
1785  {
1786  /* yes: read 1 char*/
1787  /* if \n, check again with select else ungetc(c), ready*/
1788  /* setting: d: current ssiInfo, j current fd, i current entry in L*/
1789  int c=s_getc(d->f_read);
1790  //Print("try c=%d\n",c);
1791  if (c== -1) /* eof */
1792  {
1793  FD_CLR(j,&fdmask);
1794  fdmaskempty = 1;
1795  for(k = 0; k < max_fd; k++)
1796  {
1797  if(FD_ISSET(k, &fdmask))
1798  {
1799  fdmaskempty = 0;
1800  break;
1801  }
1802  }
1803  if(fdmaskempty)
1804  {
1805  return -1;
1806  }
1807  if(timeout != -1)
1808  {
1809  timeout = si_max(0,
1810  timeout - 1000000*(getRTimer()/TIMER_RESOLUTION - startingtime));
1811  wt.tv_sec = timeout / 1000000;
1812  wt.tv_usec = (timeout % 1000000);
1813  }
1814  goto do_select;
1815  }
1816 
1817  else if (isdigit(c))
1818  { s_ungetc(c,d->f_read); return i+1; }
1819  else if (c>' ')
1820  {
1821  Werror("unknown char in ssiLink(%d)",c);
1822  return -2;
1823  }
1824  /* else: next char */
1825  goto do_select;
1826  }
1827  }
1828 }
Definition: s_buff.h:20
const CanonicalForm int s
Definition: facAbsFact.cc:55
sleftv * m
Definition: lists.h:45
int j
Definition: facHensel.cc:105
int getRTimer()
Definition: timer.cc:172
void WerrorS(const char *s)
Definition: feFopen.cc:24
int k
Definition: cfEzgcd.cc:92
#define loop
Definition: structs.h:78
int Typ()
Definition: subexpr.cc:1039
int s_getc(s_buff F)
Definition: s_buff.cc:56
s_buff f_read
Definition: s_buff.h:22
if(yy_init)
Definition: libparse.cc:1418
#define TIMER_RESOLUTION
Definition: mod2.h:34
Definition: tok.h:58
void s_ungetc(int c, s_buff F)
Definition: s_buff.cc:97
static int si_max(const int a, const int b)
Definition: auxiliary.h:138
int i
Definition: cfEzgcd.cc:125
int nr
Definition: lists.h:43
Definition: tok.h:117
#define NULL
Definition: omList.c:10
int rtyp
Definition: subexpr.h:91
void * Data()
Definition: subexpr.cc:1182
int fd_read
Definition: s_buff.h:26
int s_isready(s_buff F)
Definition: s_buff.cc:83
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int l
Definition: cfEzgcd.cc:93

◆ ssiBatch()

int ssiBatch ( const char *  host,
const char *  port 
)

Definition at line 1830 of file ssiLink.cc.

1832 {
1834  char *buf=(char*)omAlloc(256);
1835  sprintf(buf,"ssi:connect %s:%s",host,port);
1836  slInit(l, buf);
1837  omFreeSize(buf,256);
1838  if (slOpen(l,SI_LINK_OPEN,NULL)) return 1;
1840 
1841  idhdl id = enterid("link_ll", 0, LINK_CMD, &IDROOT, FALSE);
1842  IDLINK(id) = l;
1843 
1844  loop
1845  {
1846  leftv h=ssiRead1(l); /*contains an exit.... */
1847  if (feErrors != NULL && *feErrors != '\0')
1848  {
1849  // handle errors:
1850  PrintS(feErrors); /* currently quite simple */
1851  *feErrors = '\0';
1852  }
1853  ssiWrite(l,h);
1854  h->CleanUp();
1856  }
1857  /* never reached*/
1858  exit(0);
1859 }
Class used for (list of) interpreter objects.
Definition: subexpr.h:82
#define IDLINK(a)
Definition: ipid.h:133
#define FALSE
Definition: auxiliary.h:94
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define IDROOT
Definition: ipid.h:18
#define loop
Definition: structs.h:78
#define omAlloc(size)
Definition: omAllocDecl.h:210
Definition: idrec.h:34
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:267
char * feErrors
Definition: reporter.cc:47
int status int void * buf
Definition: si_signals.h:59
omBin sleftv_bin
Definition: subexpr.cc:47
void PrintS(const char *s)
Definition: reporter.cc:284
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
Definition: tok.h:117
#define NULL
Definition: omList.c:10
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
static Poly * h
Definition: janet.cc:972
int l
Definition: cfEzgcd.cc:93

◆ ssiClose()

BOOLEAN ssiClose ( si_link  l)

Definition at line 1171 of file ssiLink.cc.

1172 {
1173  if (l!=NULL)
1174  {
1176  ssiInfo *d = (ssiInfo *)l->data;
1177  if (d!=NULL)
1178  {
1179  // send quit signal
1180  if ((d->send_quit_at_exit)
1181  && (d->quit_sent==0))
1182  {
1183  fputs("99\n",d->f_write);
1184  fflush(d->f_write);
1185  }
1186  // clean ring
1187  if (d->r!=NULL) rKill(d->r);
1188  // did the child to stop ?
1189  si_waitpid(d->pid,NULL,WNOHANG);
1190  if ((d->pid!=0)
1191  && (kill(d->pid,0)==0)) // child is still running
1192  {
1193  struct timespec t;
1194  t.tv_sec=0;
1195  t.tv_nsec=100000000; // <=100 ms
1196  struct timespec rem;
1197  int r;
1198  loop
1199  {
1200  // wait till signal or time rem:
1201  r = nanosleep(&t, &rem);
1202  t = rem;
1203  // child finished:
1204  if (si_waitpid(d->pid,NULL,WNOHANG) != 0) break;
1205  // other signal, waited s>= 100 ms:
1206  if ((r==0) || (errno != EINTR)) break;
1207  }
1208  if (kill(d->pid,0) == 0) // pid still exists
1209  {
1210  kill(d->pid,15);
1211  t.tv_sec=5; // <=5s
1212  t.tv_nsec=0;
1213  loop
1214  {
1215  // wait till signal or time rem:
1216  r = nanosleep(&t, &rem);
1217  t = rem;
1218  // child finished:
1219  if (si_waitpid(d->pid,NULL,WNOHANG) != 0) break;
1220  // other signal, waited s>= 5 s:
1221  if ((r==0) || (errno != EINTR)) break;
1222  }
1223  if (kill(d->pid,0) == 0)
1224  {
1225  kill(d->pid,9); // just to be sure
1226  si_waitpid(d->pid,NULL,0);
1227  }
1228  }
1229  }
1230  if (d->f_read!=NULL) { s_close(d->f_read);d->f_read=NULL;}
1231  if (d->f_write!=NULL) { fclose(d->f_write); d->f_write=NULL; }
1232  if ((strcmp(l->mode,"tcp")==0)
1233  || (strcmp(l->mode,"fork")==0))
1234  {
1236  if (hh!=NULL)
1237  {
1238  if (hh->l==l)
1239  {
1241  omFreeSize(hh,sizeof(link_struct));
1242  }
1243  else while(hh->next!=NULL)
1244  {
1245  link_list hhh=(link_list)hh->next;
1246  if (hhh->l==l)
1247  {
1248  hh->next=hhh->next;
1249  omFreeSize(hhh,sizeof(link_struct));
1250  break;
1251  }
1252  else
1253  hh=(link_list)hh->next;
1254  }
1255  }
1256  }
1257  omFreeSize((ADDRESS)d,(sizeof *d));
1258  }
1259  l->data=NULL;
1260  }
1261  return FALSE;
1262 }
Definition: s_buff.h:20
void rem(unsigned long *a, unsigned long *q, unsigned long p, int &dega, int degq)
Definition: minpoly.cc:572
char send_quit_at_exit
Definition: s_buff.h:28
#define FALSE
Definition: auxiliary.h:94
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
pid_t pid
Definition: s_buff.h:25
void * ADDRESS
Definition: auxiliary.h:133
#define loop
Definition: structs.h:78
ring r
Definition: s_buff.h:24
int s_close(s_buff &F)
Definition: s_buff.cc:43
s_buff f_read
Definition: s_buff.h:22
if(yy_init)
Definition: libparse.cc:1418
void rKill(ring r)
Definition: ipshell.cc:6119
#define NULL
Definition: omList.c:10
FILE * f_write
Definition: s_buff.h:23
int l
Definition: cfEzgcd.cc:93
char quit_sent
Definition: s_buff.h:29

◆ ssiCommandLink()

si_link ssiCommandLink ( )

Definition at line 1901 of file ssiLink.cc.

1902 {
1903  if (ssiReserved_P==0)
1904  {
1905  WerrorS("ERROR no reverved port requested");
1906  return NULL;
1907  }
1908  struct sockaddr_in cli_addr;
1909  int clilen = sizeof(cli_addr);
1910  int newsockfd = si_accept(ssiReserved_sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
1911  if(newsockfd < 0)
1912  {
1913  Werror("ERROR on accept (errno=%d)",errno);
1914  return NULL;
1915  }
1917  si_link_extension s = si_link_root;
1918  si_link_extension prev = s;
1919  while (strcmp(s->type, "ssi") != 0)
1920  {
1921  if (s->next == NULL)
1922  {
1923  prev = s;
1924  s = NULL;
1925  break;
1926  }
1927  else
1928  {
1929  s = s->next;
1930  }
1931  }
1932  if (s != NULL)
1933  l->m = s;
1934  else
1935  {
1936  si_link_extension ns = (si_link_extension)omAlloc0Bin(s_si_link_extension_bin);
1937  prev->next=slInitSsiExtension(ns);
1938  l->m = prev->next;
1939  }
1940  l->name=omStrDup("");
1941  l->mode=omStrDup("tcp");
1942  l->ref=1;
1943  ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo));
1944  l->data=d;
1945  d->fd_read = newsockfd;
1946  d->fd_write = newsockfd;
1947  d->f_read = s_open(newsockfd);
1948  d->f_write = fdopen(newsockfd, "w");
1951  if (ssiReserved_Clients<=0)
1952  {
1953  ssiReserved_P=0;
1954  si_close(ssiReserved_sockfd);
1955  }
1956  return l;
1957 }
Definition: s_buff.h:20
const CanonicalForm int s
Definition: facAbsFact.cc:55
int fd_write
Definition: s_buff.h:26
void WerrorS(const char *s)
Definition: feFopen.cc:24
s_buff f_read
Definition: s_buff.h:22
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
#define NULL
Definition: omList.c:10
FILE * f_write
Definition: s_buff.h:23
int fd_read
Definition: s_buff.h:26
void Werror(const char *fmt,...)
Definition: reporter.cc:189
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:93
s_buff s_open(int fd)
Definition: s_buff.cc:29
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ ssiDump()

BOOLEAN ssiDump ( si_link  l)

Definition at line 2117 of file ssiLink.cc.

2118 {
2119  idhdl h = IDROOT, rh = currRingHdl;
2121 
2122  //if (! status ) status = DumpAsciiMaps(fd, h, NULL);
2123 
2124  if (currRingHdl != rh) rSetHdl(rh);
2125  //fprintf(fd, "option(set, intvec(%d, %d));\n", si_opt_1, si_opt_2);
2126 
2127  return status;
2128 }
#define IDROOT
Definition: ipid.h:18
Definition: idrec.h:34
idhdl currRingHdl
Definition: ipid.cc:61
int * status
Definition: si_signals.h:51
void rSetHdl(idhdl h)
Definition: ipshell.cc:5081
static Poly * h
Definition: janet.cc:972
int BOOLEAN
Definition: auxiliary.h:85
int l
Definition: cfEzgcd.cc:93

◆ ssiDumpIter()

static BOOLEAN ssiDumpIter ( si_link  l,
idhdl  h 
)
static

Definition at line 2096 of file ssiLink.cc.

2097 {
2098  if (h == NULL) return FALSE;
2099 
2100  if (ssiDumpIter(l, IDNEXT(h))) return TRUE;
2101 
2102  // need to set the ring before writing it, otherwise we get in
2103  // trouble with minpoly
2104  if (IDTYP(h) == RING_CMD)
2105  rSetHdl(h);
2106 
2107  if (DumpSsiIdhdl(l, h)) return TRUE;
2108 
2109  // do not dump ssi internal rings: ssiRing*
2110  // but dump objects of all other rings
2111  if ((IDTYP(h) == RING_CMD)
2112  && (strncmp(IDID(h),"ssiRing",7)!=0))
2113  return ssiDumpIter(l, IDRING(h)->idroot);
2114  else
2115  return FALSE;
2116 }
#define IDID(a)
Definition: ipid.h:117
#define FALSE
Definition: auxiliary.h:94
#define IDNEXT(a)
Definition: ipid.h:113
#define TRUE
Definition: auxiliary.h:98
#define IDTYP(a)
Definition: ipid.h:114
#define NULL
Definition: omList.c:10
#define IDRING(a)
Definition: ipid.h:122
void rSetHdl(idhdl h)
Definition: ipshell.cc:5081
static Poly * h
Definition: janet.cc:972
int l
Definition: cfEzgcd.cc:93

◆ ssiGetDump()

BOOLEAN ssiGetDump ( si_link  l)

Definition at line 2129 of file ssiLink.cc.

2130 {
2131  ssiInfo *d=(ssiInfo*)l->data;
2132  loop
2133  {
2134  if (!SI_LINK_OPEN_P(l)) break;
2135  if (s_iseof(d->f_read)) break;
2136  leftv h=ssiRead1(l); /*contains an exit.... */
2137  if (feErrors != NULL && *feErrors != '\0')
2138  {
2139  // handle errors:
2140  PrintS(feErrors); /* currently quite simple */
2141  return TRUE;
2142  *feErrors = '\0';
2143  }
2144  h->CleanUp();
2146  }
2147  return FALSE;
2148 }
Definition: s_buff.h:20
Class used for (list of) interpreter objects.
Definition: subexpr.h:82
#define FALSE
Definition: auxiliary.h:94
#define TRUE
Definition: auxiliary.h:98
#define loop
Definition: structs.h:78
char * feErrors
Definition: reporter.cc:47
s_buff f_read
Definition: s_buff.h:22
if(yy_init)
Definition: libparse.cc:1418
omBin sleftv_bin
Definition: subexpr.cc:47
void PrintS(const char *s)
Definition: reporter.cc:284
int s_iseof(s_buff F)
Definition: s_buff.cc:250
#define NULL
Definition: omList.c:10
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
static Poly * h
Definition: janet.cc:972
int l
Definition: cfEzgcd.cc:93

◆ ssiOpen()

BOOLEAN ssiOpen ( si_link  l,
short  flag,
leftv  u 
)

Definition at line 786 of file ssiLink.cc.

787 {
788  if (l!=NULL)
789  {
790  const char *mode;
791  ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo));
792  if (flag & SI_LINK_OPEN)
793  {
794  if (l->mode[0] != '\0' && (strcmp(l->mode, "r") == 0))
795  flag = SI_LINK_READ;
796  else flag = SI_LINK_WRITE;
797  }
798 
799  if (flag == SI_LINK_READ) mode = "r";
800  else if (strcmp(l->mode, "w") == 0) mode = "w";
801  else if (strcmp(l->mode, "fork") == 0) mode = "fork";
802  else if (strcmp(l->mode, "tcp") == 0) mode = "tcp";
803  else if (strcmp(l->mode, "connect") == 0) mode = "connect";
804  else mode = "a";
805 
806 
807  SI_LINK_SET_OPEN_P(l, flag);
808  if(l->data!=NULL) omFreeSize(l->data,sizeof(ssiInfo));
809  l->data=d;
810  omFree(l->mode);
811  l->mode = omStrDup(mode);
812 
813  if (l->name[0] == '\0')
814  {
815  if (strcmp(mode,"fork")==0)
816  {
818  n->u=u;
819  n->l=l;
820  n->next=(void *)ssiToBeClosed;
821  ssiToBeClosed=n;
822 
823  int pc[2];
824  int cp[2];
825  pipe(pc);
826  pipe(cp);
827  pid_t pid = fork();
828  if (pid == -1 && errno == EAGAIN) // RLIMIT_NPROC too low?
829  {
831  pid = fork();
832  }
833  if (pid == -1)
834  {
835  WerrorS("could not fork");
836  }
837  if (pid==0) /*fork: child*/
838  {
839  /* block SIGINT */
840  sigset_t sigint;
841  sigemptyset(&sigint);
842  sigaddset(&sigint, SIGINT);
843  sigprocmask(SIG_BLOCK, &sigint, NULL);
844 
846  /* we know: l is the first entry in ssiToBeClosed-list */
847  while(hh!=NULL)
848  {
849  SI_LINK_SET_CLOSE_P(hh->l);
850  ssiInfo *dd=(ssiInfo*)hh->l->data;
851  s_close(dd->f_read);
852  fclose(dd->f_write);
853  if (dd->r!=NULL) rKill(dd->r);
854  omFreeSize((ADDRESS)dd,(sizeof *dd));
855  hh->l->data=NULL;
856  link_list nn=(link_list)hh->next;
857  omFree(hh);
858  hh=nn;
859  }
861 #ifdef HAVE_SIMPLEIPC
862  memset(sem_acquired, 0, SIPC_MAX_SEMAPHORES*sizeof(sem_acquired[0]));
863 #endif // HAVE_SIMPLEIPC
864  si_close(pc[1]); si_close(cp[0]);
865  d->f_write=fdopen(cp[1],"w");
866  d->f_read=s_open(pc[0]);
867  d->fd_read=pc[0];
868  d->fd_write=cp[1];
869  //d->r=currRing;
870  //if (d->r!=NULL) d->r->ref++;
871  l->data=d;
872  omFree(l->mode);
873  l->mode = omStrDup(mode);
876  //myynest=0;
878  if ((u!=NULL)&&(u->rtyp==IDHDL))
879  {
880  idhdl h=(idhdl)u->data;
881  h->lev=0;
882  }
883  loop
884  {
885  if (!SI_LINK_OPEN_P(l)) m2_end(0);
886  if(d->f_read->is_eof) m2_end(0);
887  leftv h=ssiRead1(l); /*contains an exit.... */
888  if (feErrors != NULL && *feErrors != '\0')
889  {
890  // handle errors:
891  PrintS(feErrors); /* currently quite simple */
892  *feErrors = '\0';
893  }
894  ssiWrite(l,h);
895  h->CleanUp();
897  }
898  /* never reached*/
899  }
900  else if (pid>0) /*fork: parent*/
901  {
902  d->pid=pid;
903  si_close(pc[0]); si_close(cp[1]);
904  d->f_write=fdopen(pc[1],"w");
905  d->f_read=s_open(cp[0]);
906  d->fd_read=cp[0];
907  d->fd_write=pc[1];
909  d->send_quit_at_exit=1;
910  //d->r=currRing;
911  //if (d->r!=NULL) d->r->ref++;
912  }
913  else
914  {
915  Werror("fork failed (%d)",errno);
916  l->data=NULL;
917  omFree(d);
918  return TRUE;
919  }
920  }
921  // ---------------------------------------------------------------------
922  else if (strcmp(mode,"tcp")==0)
923  {
924  int sockfd, newsockfd, portno, clilen;
925  struct sockaddr_in serv_addr, cli_addr;
926  sockfd = socket(AF_INET, SOCK_STREAM, 0);
927  if(sockfd < 0)
928  {
929  WerrorS("ERROR opening socket");
930  l->data=NULL;
931  omFree(d);
932  return TRUE;
933  }
934  memset((char *) &serv_addr,0, sizeof(serv_addr));
935  portno = 1025;
936  serv_addr.sin_family = AF_INET;
937  serv_addr.sin_addr.s_addr = INADDR_ANY;
938  do
939  {
940  portno++;
941  serv_addr.sin_port = htons(portno);
942  if(portno > 50000)
943  {
944  WerrorS("ERROR on binding (no free port available?)");
945  l->data=NULL;
946  omFree(d);
947  return TRUE;
948  }
949  }
950  while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
951  Print("waiting on port %d\n", portno);mflush();
952  listen(sockfd,1);
953  newsockfd = si_accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
954  if(newsockfd < 0)
955  {
956  WerrorS("ERROR on accept");
957  l->data=NULL;
958  omFree(d);
959  return TRUE;
960  }
961  PrintS("client accepted\n");
962  d->fd_read = newsockfd;
963  d->fd_write = newsockfd;
964  d->f_read = s_open(newsockfd);
965  d->f_write = fdopen(newsockfd, "w");
967  si_close(sockfd);
968  }
969  // no ssi-Link on stdin or stdout
970  else
971  {
972  Werror("invalid mode >>%s<< for ssi",mode);
973  l->data=NULL;
974  omFree(d);
975  return TRUE;
976  }
977  }
978  // =========================================================================
979  else /*l->name=NULL*/
980  {
981  // tcp mode
982  if(strcmp(mode,"tcp")==0)
983  {
984  int sockfd, newsockfd, portno, clilen;
985  struct sockaddr_in serv_addr, cli_addr;
986  sockfd = socket(AF_INET, SOCK_STREAM, 0);
987  if(sockfd < 0)
988  {
989  WerrorS("ERROR opening socket");
990  l->data=NULL;
991  omFree(d);
992  return TRUE;
993  }
994  memset((char *) &serv_addr,0, sizeof(serv_addr));
995  portno = 1025;
996  serv_addr.sin_family = AF_INET;
997  serv_addr.sin_addr.s_addr = INADDR_ANY;
998  do
999  {
1000  portno++;
1001  serv_addr.sin_port = htons(portno);
1002  if(portno > 50000)
1003  {
1004  WerrorS("ERROR on binding (no free port available?)");
1005  l->data=NULL;
1006  return TRUE;
1007  }
1008  }
1009  while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
1010  //Print("waiting on port %d\n", portno);mflush();
1011  listen(sockfd,1);
1012  char* cli_host = (char*)omAlloc(256);
1013  char* path = (char*)omAlloc(1024);
1014  int r = si_sscanf(l->name,"%255[^:]:%s",cli_host,path);
1015  if(r == 0)
1016  {
1017  WerrorS("ERROR: no host specified");
1018  l->data=NULL;
1019  omFree(d);
1020  omFree(path);
1021  omFree(cli_host);
1022  return TRUE;
1023  }
1024  else if(r == 1)
1025  {
1026  WarnS("program not specified, using /usr/local/bin/Singular");
1027  Warn("in line >>%s<<",my_yylinebuf);
1028  strcpy(path,"/usr/local/bin/Singular");
1029  }
1030  char* ssh_command = (char*)omAlloc(256);
1031  char* ser_host = (char*)omAlloc(64);
1032  gethostname(ser_host,64);
1033  sprintf(ssh_command,"ssh %s %s -q --batch --link=ssi --MPhost=%s --MPport=%d &",cli_host,path,ser_host,portno);
1034  //Print("client on %s started:%s\n",cli_host,path);
1035  omFree(path);
1036  omFree(cli_host);
1037  if (TEST_OPT_PROT) { Print("running >>%s<<\n",ssh_command); }
1038  system(ssh_command);
1039  omFree(ssh_command);
1040  omFree(ser_host);
1041  clilen = sizeof(cli_addr);
1042  newsockfd = si_accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
1043  if(newsockfd < 0)
1044  {
1045  WerrorS("ERROR on accept");
1046  l->data=NULL;
1047  omFree(d);
1048  return TRUE;
1049  }
1050  //PrintS("client accepted\n");
1051  d->fd_read = newsockfd;
1052  d->fd_write = newsockfd;
1053  d->f_read = s_open(newsockfd);
1054  d->f_write = fdopen(newsockfd, "w");
1055  si_close(sockfd);
1057  d->send_quit_at_exit=1;
1058  link_list newlink=(link_list)omAlloc(sizeof(link_struct));
1059  newlink->u=u;
1060  newlink->l=l;
1061  newlink->next=(void *)ssiToBeClosed;
1062  ssiToBeClosed=newlink;
1063  fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,si_opt_1,si_opt_2);
1064  }
1065  // ----------------------------------------------------------------------
1066  else if(strcmp(mode,"connect")==0)
1067  {
1068  char* host = (char*)omAlloc(256);
1069  int sockfd, portno;
1070  struct sockaddr_in serv_addr;
1071  struct hostent *server;
1072 
1073  si_sscanf(l->name,"%255[^:]:%d",host,&portno);
1074  //Print("connect to host %s, port %d\n",host,portno);mflush();
1075  if (portno!=0)
1076  {
1077  sockfd = socket(AF_INET, SOCK_STREAM, 0);
1078  if (sockfd < 0) { WerrorS("ERROR opening socket"); return TRUE; }
1079  server = gethostbyname(host);
1080  if (server == NULL) { WerrorS("ERROR, no such host"); return TRUE; }
1081  memset((char *) &serv_addr, 0, sizeof(serv_addr));
1082  serv_addr.sin_family = AF_INET;
1083  memcpy((char *)&serv_addr.sin_addr.s_addr,
1084  (char *)server->h_addr,
1085  server->h_length);
1086  serv_addr.sin_port = htons(portno);
1087  if (si_connect(sockfd,(sockaddr*)&serv_addr,sizeof(serv_addr)) < 0)
1088  { Werror("ERROR connecting(errno=%d)",errno); return TRUE; }
1089  //PrintS("connected\n");mflush();
1090  d->f_read=s_open(sockfd);
1091  d->fd_read=sockfd;
1092  d->f_write=fdopen(sockfd,"w");
1093  d->fd_write=sockfd;
1095  omFree(host);
1096  }
1097  else
1098  {
1099  l->data=NULL;
1100  omFree(d);
1101  return TRUE;
1102  }
1103  }
1104  // ======================================================================
1105  else
1106  {
1107  // normal link to a file
1108  FILE *outfile;
1109  char *filename=l->name;
1110 
1111  if(filename[0]=='>')
1112  {
1113  if (filename[1]=='>')
1114  {
1115  filename+=2;
1116  mode = "a";
1117  }
1118  else
1119  {
1120  filename++;
1121  mode="w";
1122  }
1123  }
1124  outfile=myfopen(filename,mode);
1125  if (outfile!=NULL)
1126  {
1127  if (strcmp(l->mode,"r")==0)
1128  {
1129  fclose(outfile);
1130  d->f_read=s_open_by_name(filename);
1131  }
1132  else
1133  {
1134  d->f_write = outfile;
1135  fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,si_opt_1,si_opt_2);
1136  }
1137  }
1138  else
1139  {
1140  omFree(d);
1141  l->data=NULL;
1142  return TRUE;
1143  }
1144  }
1145  }
1146  }
1147 
1148  return FALSE;
1149 }
Definition: s_buff.h:20
unsigned si_opt_1
Definition: options.c:5
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition: feread.cc:34
Class used for (list of) interpreter objects.
Definition: subexpr.h:82
#define Print
Definition: emacs.cc:80
int fd_write
Definition: s_buff.h:26
#define TEST_OPT_PROT
Definition: options.h:102
char send_quit_at_exit
Definition: s_buff.h:28
#define FALSE
Definition: auxiliary.h:94
Definition: tok.h:216
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
char * fe_fgets_dummy(const char *, char *, int)
Definition: feread.cc:451
#define TRUE
Definition: auxiliary.h:98
pid_t pid
Definition: s_buff.h:25
void * ADDRESS
Definition: auxiliary.h:133
void WerrorS(const char *s)
Definition: feFopen.cc:24
#define loop
Definition: structs.h:78
ring r
Definition: s_buff.h:24
int s_close(s_buff &F)
Definition: s_buff.cc:43
#define WarnS
Definition: emacs.cc:78
#define omAlloc(size)
Definition: omAllocDecl.h:210
Definition: idrec.h:34
#define IDHDL
Definition: tok.h:31
void * data
Definition: subexpr.h:88
#define mflush()
Definition: reporter.h:57
char * feErrors
Definition: reporter.cc:47
char my_yylinebuf[80]
Definition: febase.cc:43
s_buff f_read
Definition: s_buff.h:22
BOOLEAN singular_in_batchmode
Definition: cntrlc.cc:67
void rKill(ring r)
Definition: ipshell.cc:6119
#define omFree(addr)
Definition: omAllocDecl.h:261
FILE * myfopen(const char *path, const char *mode)
Definition: feFopen.cc:167
void system(sys)
int raise_rlimit_nproc()
Definition: rlimit.c:18
idrec * idhdl
Definition: ring.h:22
omBin sleftv_bin
Definition: subexpr.cc:47
void PrintS(const char *s)
Definition: reporter.cc:284
void m2_end(int i)
Definition: misc_ip.cc:1101
#define NULL
Definition: omList.c:10
FILE * f_write
Definition: s_buff.h:23
int rtyp
Definition: subexpr.h:91
#define SIPC_MAX_SEMAPHORES
Definition: simpleipc.h:10
int fd_read
Definition: s_buff.h:26
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
int sem_acquired[SIPC_MAX_SEMAPHORES]
Definition: semaphore.c:25
s_buff s_open_by_name(const char *n)
Definition: s_buff.cc:37
unsigned si_opt_2
Definition: options.c:6
static Poly * h
Definition: janet.cc:972
void Werror(const char *fmt,...)
Definition: reporter.cc:189
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:93
s_buff s_open(int fd)
Definition: s_buff.cc:29
#define Warn
Definition: emacs.cc:77
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ ssiPrepClose()

BOOLEAN ssiPrepClose ( si_link  l)

Definition at line 1152 of file ssiLink.cc.

1153 {
1154  if (l!=NULL)
1155  {
1157  ssiInfo *d = (ssiInfo *)l->data;
1158  if (d!=NULL)
1159  {
1160  if (d->send_quit_at_exit)
1161  {
1162  fputs("99\n",d->f_write);
1163  fflush(d->f_write);
1164  }
1165  d->quit_sent=1;
1166  }
1167  }
1168  return FALSE;
1169 }
Definition: s_buff.h:20
char send_quit_at_exit
Definition: s_buff.h:28
#define FALSE
Definition: auxiliary.h:94
if(yy_init)
Definition: libparse.cc:1418
#define NULL
Definition: omList.c:10
FILE * f_write
Definition: s_buff.h:23
int l
Definition: cfEzgcd.cc:93
char quit_sent
Definition: s_buff.h:29

◆ ssiRead1()

leftv ssiRead1 ( si_link  l)

Definition at line 1265 of file ssiLink.cc.

1266 {
1267  ssiInfo *d = (ssiInfo *)l->data;
1269  int t=0;
1270  t=s_readint(d->f_read);
1271  //Print("got type %d\n",t);
1272  switch(t)
1273  {
1274  case 1:res->rtyp=INT_CMD;
1275  res->data=(char *)(long)ssiReadInt(d->f_read);
1276  break;
1277  case 2:res->rtyp=STRING_CMD;
1278  res->data=(char *)ssiReadString(d);
1279  break;
1280  case 3:res->rtyp=NUMBER_CMD;
1281  res->data=(char *)ssiReadNumber(d);
1282  break;
1283  case 4:res->rtyp=BIGINT_CMD;
1284  res->data=(char *)ssiReadBigInt(d);
1285  break;
1286  case 15:
1287  case 5:{
1288  d->r=ssiReadRing(d);
1289  if (d->r==NULL) return NULL;
1290  res->data=(char*)d->r;
1291  d->r->ref++;
1292  res->rtyp=RING_CMD;
1293  if (t==15) // setring
1294  {
1295  if(ssiSetCurrRing(d->r)) { d->r=currRing; d->r->ref++; }
1297  return ssiRead1(l);
1298  }
1299  }
1300  break;
1301  case 6:res->rtyp=POLY_CMD;
1302  if (d->r==NULL) goto no_ring;
1303  res->data=(char*)ssiReadPoly(d);
1304  break;
1305  case 7:res->rtyp=IDEAL_CMD;
1306  if (d->r==NULL) goto no_ring;
1307  res->data=(char*)ssiReadIdeal(d);
1308  break;
1309  case 8:res->rtyp=MATRIX_CMD;
1310  if (d->r==NULL) goto no_ring;
1311  res->data=(char*)ssiReadMatrix(d);
1312  break;
1313  case 9:res->rtyp=VECTOR_CMD;
1314  if (d->r==NULL) goto no_ring;
1315  res->data=(char*)ssiReadPoly(d);
1316  break;
1317  case 10:
1318  case 22:if (t==22) res->rtyp=SMATRIX_CMD;
1319  else res->rtyp=MODUL_CMD;
1320  if (d->r==NULL) goto no_ring;
1321  {
1322  int rk=s_readint(d->f_read);
1323  ideal M=ssiReadIdeal(d);
1324  M->rank=rk;
1325  res->data=(char*)M;
1326  }
1327  break;
1328  case 11:
1329  {
1330  res->rtyp=COMMAND;
1331  res->data=ssiReadCommand(l);
1332  int nok=res->Eval();
1333  if (nok) WerrorS("error in eval");
1334  break;
1335  }
1336  case 12: /*DEF_CMD*/
1337  {
1338  res->rtyp=0;
1339  res->name=(char *)ssiReadString(d);
1340  int nok=res->Eval();
1341  if (nok) WerrorS("error in name lookup");
1342  break;
1343  }
1344  case 13: res->rtyp=PROC_CMD;
1345  res->data=ssiReadProc(d);
1346  break;
1347  case 14: res->rtyp=LIST_CMD;
1348  res->data=ssiReadList(l);
1349  break;
1350  case 16: res->rtyp=NONE; res->data=NULL;
1351  break;
1352  case 17: res->rtyp=INTVEC_CMD;
1353  res->data=ssiReadIntvec(d);
1354  break;
1355  case 18: res->rtyp=INTMAT_CMD;
1356  res->data=ssiReadIntmat(d);
1357  break;
1358  case 19: res->rtyp=BIGINTMAT_CMD;
1359  res->data=ssiReadBigintmat(d);
1360  break;
1361  case 20: ssiReadBlackbox(res,l);
1362  break;
1363  case 21: ssiReadAttrib(res,l);
1364  break;
1365  // ------------
1366  case 98: // version
1367  {
1368  int n98_v,n98_m;
1369  BITSET n98_o1,n98_o2;
1370  n98_v=s_readint(d->f_read);
1371  n98_m=s_readint(d->f_read);
1372  n98_o1=s_readint(d->f_read);
1373  n98_o2=s_readint(d->f_read);
1374  if ((n98_v!=SSI_VERSION) ||(n98_m!=MAX_TOK))
1375  {
1376  Print("incompatible versions of ssi: %d/%d vs %d/%d\n",
1377  SSI_VERSION,MAX_TOK,n98_v,n98_m);
1378  }
1379  #ifndef SING_NDEBUG
1380  if (TEST_OPT_DEBUG)
1381  Print("// opening ssi-%d, MAX_TOK=%d\n",n98_v,n98_m);
1382  #endif
1383  si_opt_1=n98_o1;
1384  si_opt_2=n98_o2;
1386  return ssiRead1(l);
1387  }
1388  case 99: omFreeBin(res,sleftv_bin); ssiClose(l); m2_end(0);
1389  case 0: if (s_iseof(d->f_read))
1390  {
1391  ssiClose(l);
1392  }
1393  res->rtyp=DEF_CMD;
1394  break;
1395  default: Werror("not implemented (t:%d)",t);
1397  res=NULL;
1398  break;
1399  }
1400  // if currRing is required for the result, but lost
1401  // define "ssiRing%d" as currRing:
1402  if ((d->r!=NULL)
1403  && (currRing!=d->r)
1404  && (res->RingDependend()))
1405  {
1406  if(ssiSetCurrRing(d->r)) { d->r=currRing; d->r->ref++; }
1407  }
1408  return res;
1409 no_ring: WerrorS("no ring");
1411  return NULL;
1412 }
Definition: s_buff.h:20
unsigned si_opt_1
Definition: options.c:5
Class used for (list of) interpreter objects.
Definition: subexpr.h:82
#define Print
Definition: emacs.cc:80
Definition: tok.h:96
Definition: tok.h:38
Definition: tok.h:216
void WerrorS(const char *s)
Definition: feFopen.cc:24
#define TEST_OPT_DEBUG
Definition: options.h:107
ring r
Definition: s_buff.h:24
#define BITSET
Definition: structs.h:18
#define M
Definition: sirandom.c:24
s_buff f_read
Definition: s_buff.h:22
if(yy_init)
Definition: libparse.cc:1418
CanonicalForm res
Definition: facAbsFact.cc:64
int s_readint(s_buff F)
Definition: s_buff.cc:110
Definition: tok.h:58
omBin sleftv_bin
Definition: subexpr.cc:47
int s_iseof(s_buff F)
Definition: s_buff.cc:250
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
void m2_end(int i)
Definition: misc_ip.cc:1101
#define NULL
Definition: omList.c:10
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
Definition: tok.h:118
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
unsigned si_opt_2
Definition: options.c:6
#define NONE
Definition: tok.h:219
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int l
Definition: cfEzgcd.cc:93
#define COMMAND
Definition: tok.h:29

◆ ssiReadAttrib()

void ssiReadAttrib ( leftv  res,
si_link  l 
)

Definition at line 764 of file ssiLink.cc.

765 {
766  ssiInfo *d=(ssiInfo*)l->data;
767  BITSET fl=(BITSET)s_readint(d->f_read);
768  int nr_of_attr=s_readint(d->f_read);
769  if (nr_of_attr>0)
770  {
771  for(int i=1;i<nr_of_attr;i++)
772  {
773  }
774  }
775  leftv tmp=ssiRead1(l);
776  memcpy(res,tmp,sizeof(sleftv));
777  memset(tmp,0,sizeof(sleftv));
778  omFreeBin(tmp,sleftv_bin);
779  if (nr_of_attr>0)
780  {
781  }
782  res->flag=fl;
783 }
Definition: s_buff.h:20
Class used for (list of) interpreter objects.
Definition: subexpr.h:82
#define BITSET
Definition: structs.h:18
s_buff f_read
Definition: s_buff.h:22
CanonicalForm res
Definition: facAbsFact.cc:64
int s_readint(s_buff F)
Definition: s_buff.cc:110
omBin sleftv_bin
Definition: subexpr.cc:47
int i
Definition: cfEzgcd.cc:125
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
int l
Definition: cfEzgcd.cc:93

◆ ssiReadBigInt()

number ssiReadBigInt ( const ssiInfo d)

Definition at line 425 of file ssiLink.cc.

426 {
427  number n=ssiReadNumber_CF(d,coeffs_BIGINT);
428  if ((SR_HDL(n) & SR_INT)==0)
429  {
430  if (n->s!=3) Werror("invalid sub type in bigint:%d",n->s);
431  }
432  return n;
433 }
coeffs coeffs_BIGINT
Definition: ipid.cc:52
#define SR_INT
Definition: longrat.h:66
#define SR_HDL(A)
Definition: tgb.cc:35
void Werror(const char *fmt,...)
Definition: reporter.cc:189

◆ ssiReadBigintmat()

bigintmat* ssiReadBigintmat ( const ssiInfo d)

Definition at line 731 of file ssiLink.cc.

732 {
733  int r,c;
734  r=s_readint(d->f_read);
735  c=s_readint(d->f_read);
737  for(int i=0;i<r*c;i++)
738  {
739  (*v)[i]=ssiReadBigInt(d);
740  }
741  return v;
742 }
Matrices of numbers.
Definition: bigintmat.h:51
coeffs coeffs_BIGINT
Definition: ipid.cc:52
s_buff f_read
Definition: s_buff.h:22
int s_readint(s_buff F)
Definition: s_buff.cc:110
int i
Definition: cfEzgcd.cc:125
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37

◆ ssiReadBlackbox()

void ssiReadBlackbox ( leftv  res,
si_link  l 
)

Definition at line 744 of file ssiLink.cc.

745 {
746  ssiInfo *d=(ssiInfo*)l->data;
747  int throwaway=s_readint(d->f_read);
748  char *name=ssiReadString(d);
749  int tok;
750  blackboxIsCmd(name,tok);
751  if (tok>MAX_TOK)
752  {
753  blackbox *b=getBlackboxStuff(tok);
754  res->rtyp=tok;
755  b->blackbox_deserialize(&b,&(res->data),l);
756  }
757  else
758  {
759  Werror("blackbox %s not found",name);
760  }
761  omFree(name);
762 }
Definition: s_buff.h:20
Definition: tok.h:216
CanonicalForm b
Definition: cfModGcd.cc:4044
s_buff f_read
Definition: s_buff.h:22
CanonicalForm res
Definition: facAbsFact.cc:64
int s_readint(s_buff F)
Definition: s_buff.cc:110
#define omFree(addr)
Definition: omAllocDecl.h:261
char name(const Variable &v)
Definition: factory.h:180
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:192
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int l
Definition: cfEzgcd.cc:93
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:16

◆ ssiReadCommand()

command ssiReadCommand ( si_link  l)

Definition at line 634 of file ssiLink.cc.

635 {
636  ssiInfo *d=(ssiInfo*)l->data;
637  // syntax: <num ops> <operation> <op1> <op2> ....
638  command D=(command)omAlloc0(sizeof(*D));
639  int argc,op;
640  argc=s_readint(d->f_read);
641  op=s_readint(d->f_read);
642  D->argc=argc; D->op=op;
643  leftv v;
644  if (argc >0)
645  {
646  v=ssiRead1(l);
647  memcpy(&(D->arg1),v,sizeof(*v));
649  }
650  if (argc <4)
651  {
652  if (D->argc >1)
653  {
654  v=ssiRead1(l);
655  memcpy(&(D->arg2),v,sizeof(*v));
657  }
658  if (D->argc >2)
659  {
660  v=ssiRead1(l);
661  memcpy(&(D->arg3),v,sizeof(*v));
663  }
664  }
665  else
666  {
667  leftv prev=&(D->arg1);
668  argc--;
669  while(argc >0)
670  {
671  v=ssiRead1(l);
672  prev->next=v;
673  prev=v;
674  argc--;
675  }
676  }
677  return D;
678 }
Definition: s_buff.h:20
#define D(A)
Definition: gentable.cc:131
Class used for (list of) interpreter objects.
Definition: subexpr.h:82
ip_command * command
Definition: ipid.h:22
s_buff f_read
Definition: s_buff.h:22
int s_readint(s_buff F)
Definition: s_buff.cc:110
omBin sleftv_bin
Definition: subexpr.cc:47
leftv next
Definition: subexpr.h:86
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:93

◆ ssiReadIdeal()

ideal ssiReadIdeal ( const ssiInfo d)

Definition at line 612 of file ssiLink.cc.

613 {
614  if (currRing==NULL) ssiSetCurrRing(d->r);
615  return ssiReadIdeal_R(d,d->r);
616 }
ring r
Definition: s_buff.h:24
#define NULL
Definition: omList.c:10
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13

◆ ssiReadIdeal_R()

ideal ssiReadIdeal_R ( const ssiInfo d,
const ring  r 
)

Definition at line 598 of file ssiLink.cc.

599 {
600 // < # of terms> < term1> < .....
601  int n,i;
602  ideal I;
603  n=s_readint(d->f_read);
604  I=idInit(n,1); // will be fixed later for module/smatrix
605  for(i=0;i<IDELEMS(I);i++) // read n terms
606  {
607  I->m [i]=ssiReadPoly_R(d,r);
608  }
609  return I;
610 }
s_buff f_read
Definition: s_buff.h:22
int s_readint(s_buff F)
Definition: s_buff.cc:110
int i
Definition: cfEzgcd.cc:125
#define IDELEMS(i)
Definition: simpleideals.h:24
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:37

◆ ssiReadInt()

int ssiReadInt ( s_buff  fich)

Definition at line 396 of file ssiLink.cc.

397 {
398  return s_readint(fich);
399 }
int s_readint(s_buff F)
Definition: s_buff.cc:110

◆ ssiReadIntmat()

intvec* ssiReadIntmat ( const ssiInfo d)

Definition at line 719 of file ssiLink.cc.

720 {
721  int r,c;
722  r=s_readint(d->f_read);
723  c=s_readint(d->f_read);
724  intvec *v=new intvec(r,c,0);
725  for(int i=0;i<r*c;i++)
726  {
727  (*v)[i]=s_readint(d->f_read);
728  }
729  return v;
730 }
s_buff f_read
Definition: s_buff.h:22
Definition: intvec.h:17
int s_readint(s_buff F)
Definition: s_buff.cc:110
int i
Definition: cfEzgcd.cc:125
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37

◆ ssiReadIntvec()

intvec* ssiReadIntvec ( const ssiInfo d)

Definition at line 708 of file ssiLink.cc.

709 {
710  int nr;
711  nr=s_readint(d->f_read);
712  intvec *v=new intvec(nr);
713  for(int i=0;i<nr;i++)
714  {
715  (*v)[i]=s_readint(d->f_read);
716  }
717  return v;
718 }
s_buff f_read
Definition: s_buff.h:22
Definition: intvec.h:17
int s_readint(s_buff F)
Definition: s_buff.cc:110
int i
Definition: cfEzgcd.cc:125
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37

◆ ssiReadList()

lists ssiReadList ( si_link  l)

Definition at line 690 of file ssiLink.cc.

691 {
692  ssiInfo *d=(ssiInfo*)l->data;
693  int nr;
694  nr=s_readint(d->f_read);
696  L->Init(nr);
697 
698  int i;
699  leftv v;
700  for(i=0;i<=L->nr;i++)
701  {
702  v=ssiRead1(l);
703  memcpy(&(L->m[i]),v,sizeof(*v));
705  }
706  return L;
707 }
Definition: s_buff.h:20
sleftv * m
Definition: lists.h:45
Class used for (list of) interpreter objects.
Definition: subexpr.h:82
Definition: lists.h:22
s_buff f_read
Definition: s_buff.h:22
int s_readint(s_buff F)
Definition: s_buff.cc:110
omBin sleftv_bin
Definition: subexpr.cc:47
int i
Definition: cfEzgcd.cc:125
INLINE_THIS void Init(int l=0)
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
int nr
Definition: lists.h:43
slists * lists
Definition: mpr_numeric.h:146
omBin slists_bin
Definition: lists.cc:23
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
int l
Definition: cfEzgcd.cc:93

◆ ssiReadMatrix()

matrix ssiReadMatrix ( const ssiInfo d)

Definition at line 618 of file ssiLink.cc.

619 {
620  int n,m;
621  m=s_readint(d->f_read);
622  n=s_readint(d->f_read);
623  matrix M=mpNew(m,n);
624  poly p;
625  for(int i=1;i<=MATROWS(M);i++)
626  for(int j=1;j<=MATCOLS(M);j++)
627  {
628  p=ssiReadPoly(d);
629  MATELEM(M,i,j)=p;
630  }
631  return M;
632 }
int j
Definition: facHensel.cc:105
#define M
Definition: sirandom.c:24
s_buff f_read
Definition: s_buff.h:22
int s_readint(s_buff F)
Definition: s_buff.cc:110
int m
Definition: cfEzgcd.cc:121
int i
Definition: cfEzgcd.cc:125
matrix mpNew(int r, int c)
create a r x c zero-matrix
Definition: matpol.cc:37
#define MATCOLS(i)
Definition: matpol.h:27
#define MATROWS(i)
Definition: matpol.h:26
int p
Definition: cfModGcd.cc:4019
#define MATELEM(mat, i, j)
Definition: matpol.h:28

◆ ssiReadNumber()

number ssiReadNumber ( const ssiInfo d)

Definition at line 435 of file ssiLink.cc.

436 {
437  if (currRing==NULL) ssiSetCurrRing(d->r);
438  return ssiReadNumber_CF(d,d->r->cf);
439 }
ring r
Definition: s_buff.h:24
#define NULL
Definition: omList.c:10
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13

◆ ssiReadNumber_CF()

number ssiReadNumber_CF ( const ssiInfo d,
const coeffs  cf 
)

Definition at line 401 of file ssiLink.cc.

402 {
403  if (cf->cfReadFd!=NULL)
404  {
405  return n_ReadFd(d,cf);
406  }
407  else if (getCoeffType(cf) == n_transExt)
408  {
409  // poly poly
410  fraction f=(fraction)n_Init(1,cf);
411  p_Delete(&NUM(f),cf->extRing);
412  NUM(f)=ssiReadPoly_R(d,cf->extRing);
413  DEN(f)=ssiReadPoly_R(d,cf->extRing);
414  return (number)f;
415  }
416  else if (getCoeffType(cf) == n_algExt)
417  {
418  // poly
419  return (number)ssiReadPoly_R(d,cf->extRing);
420  }
421  else WerrorS("coeffs not implemented in ssiReadNumber");
422  return NULL;
423 }
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
Definition: coeffs.h:39
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:538
void WerrorS(const char *s)
Definition: feFopen.cc:24
static FORCE_INLINE number n_ReadFd(const ssiInfo *f, const coeffs r)
io via ssi:
Definition: coeffs.h:996
FILE * f
Definition: checklibs.c:9
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:858
CanonicalForm cf
Definition: cfModGcd.cc:4024
#define NULL
Definition: omList.c:10
Definition: readcf.cc:164
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic
Definition: coeffs.h:36

◆ ssiReadPoly()

poly ssiReadPoly ( const ssiInfo D)

Definition at line 592 of file ssiLink.cc.

593 {
594  if (currRing==NULL) ssiSetCurrRing(D->r);
595  return ssiReadPoly_R(D,D->r);
596 }
#define D(A)
Definition: gentable.cc:131
#define NULL
Definition: omList.c:10
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13

◆ ssiReadPoly_R()

poly ssiReadPoly_R ( const ssiInfo D,
const ring  r 
)

Definition at line 561 of file ssiLink.cc.

562 {
563 // < # of terms> < term1> < .....
564  int n,i,l;
565  n=ssiReadInt(D->f_read); // # of terms
566  //Print("poly: terms:%d\n",n);
567  poly p;
568  poly ret=NULL;
569  poly prev=NULL;
570  for(l=0;l<n;l++) // read n terms
571  {
572 // coef,comp.exp1,..exp N
573  p=p_Init(r,r->PolyBin);
574  pSetCoeff0(p,ssiReadNumber_CF(D,r->cf));
575  int d;
576  d=s_readint(D->f_read);
577  p_SetComp(p,d,r);
578  for(i=1;i<=rVar(r);i++)
579  {
580  d=s_readint(D->f_read);
581  p_SetExp(p,i,d,r);
582  }
583  p_Setm(p,r);
584  p_Test(p,r);
585  if (ret==NULL) ret=p;
586  else pNext(prev)=p;
587  prev=p;
588  }
589  return ret;
590 }
#define D(A)
Definition: gentable.cc:131
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition: p_polys.h:248
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:582
int s_readint(s_buff F)
Definition: s_buff.cc:110
int i
Definition: cfEzgcd.cc:125
#define p_Test(p, r)
Definition: p_polys.h:164
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent @Note: VarOffset encodes the position in p->exp
Definition: p_polys.h:489
#define NULL
Definition: omList.c:10
#define pNext(p)
Definition: monomials.h:37
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:234
#define pSetCoeff0(p, n)
Definition: monomials.h:60
int p
Definition: cfModGcd.cc:4019
static poly p_Init(const ring r, omBin bin)
Definition: p_polys.h:1257
int l
Definition: cfEzgcd.cc:93

◆ ssiReadProc()

procinfov ssiReadProc ( const ssiInfo d)

Definition at line 680 of file ssiLink.cc.

681 {
682  char *s=ssiReadString(d);
684  p->language=LANG_SINGULAR;
685  p->libname=omStrDup("");
686  p->procname=omStrDup("");
687  p->data.s.body=s;
688  return p;
689 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
omBin procinfo_bin
Definition: subexpr.cc:48
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
int p
Definition: cfModGcd.cc:4019
procinfo * procinfov
Definition: structs.h:63
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ ssiReadRing()

ring ssiReadRing ( const ssiInfo d)

Definition at line 441 of file ssiLink.cc.

442 {
443 /* syntax is <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... <Q-ideal> */
444  int ch, N,i;
445  char **names;
446  ch=s_readint(d->f_read);
447  N=s_readint(d->f_read);
448  coeffs cf=NULL;
449  if (ch==-3)
450  {
451  char *cf_name=ssiReadString(d);
452  cf=nFindCoeffByName(cf_name);
453  if (cf==NULL)
454  {
455  Werror("cannot find cf:%s",cf_name);
456  omFree(cf_name);
457  return NULL;
458  }
459  }
460  if (N!=0)
461  {
462  names=(char**)omAlloc(N*sizeof(char*));
463  for(i=0;i<N;i++)
464  {
465  names[i]=ssiReadString(d);
466  }
467  }
468  // read the orderings:
469  int num_ord; // number of orderings
470  num_ord=s_readint(d->f_read);
471  rRingOrder_t *ord=(rRingOrder_t *)omAlloc0((num_ord+1)*sizeof(rRingOrder_t));
472  int *block0=(int *)omAlloc0((num_ord+1)*sizeof(int));
473  int *block1=(int *)omAlloc0((num_ord+1)*sizeof(int));
474  int **wvhdl=(int**)omAlloc0((num_ord+1)*sizeof(int*));
475  for(i=0;i<num_ord;i++)
476  {
477  ord[i]=(rRingOrder_t)s_readint(d->f_read);
478  block0[i]=s_readint(d->f_read);
479  block1[i]=s_readint(d->f_read);
480  switch(ord[i])
481  {
482  case ringorder_a:
483  case ringorder_wp:
484  case ringorder_Wp:
485  case ringorder_ws:
486  case ringorder_Ws:
487  case ringorder_aa:
488  {
489  wvhdl[i]=(int*)omAlloc((block1[i]-block0[i]+1)*sizeof(int));
490  int ii;
491  for(ii=block0[i];ii<=block1[i];ii++)
492  wvhdl[i][ii-block0[i]]=s_readint(d->f_read);
493  }
494  break;
495 
496  case ringorder_a64:
497  case ringorder_M:
498  case ringorder_L:
499  case ringorder_IS:
500  Werror("ring oder not implemented for ssi:%d",ord[i]);
501  break;
502 
503  default: break;
504  }
505  }
506  if (N==0)
507  {
508  omFree(ord);
509  omFree(block0);
510  omFree(block1);
511  omFree(wvhdl);
512  return NULL;
513  }
514  else
515  {
516  ring r=NULL;
517  if (ch>=0) /* Q, Z/p */
518  r=rDefault(ch,N,names,num_ord,ord,block0,block1,wvhdl);
519  else if (ch==-1) /* trans ext. */
520  {
521  TransExtInfo T;
522  T.r=ssiReadRing(d);
523  if (T.r==NULL) return NULL;
525  r=rDefault(cf,N,names,num_ord,ord,block0,block1,wvhdl);
526  }
527  else if (ch==-2) /* alg ext. */
528  {
529  TransExtInfo T;
530  T.r=ssiReadRing(d); /* includes qideal */
531  if (T.r==NULL) return NULL;
533  r=rDefault(cf,N,names,num_ord,ord,block0,block1,wvhdl);
534  }
535  else if (ch==-3)
536  {
537  r=rDefault(cf,N,names,num_ord,ord,block0,block1,wvhdl);
538  }
539  else
540  {
541  Werror("ssi: read unknown coeffs type (%d)",ch);
542  for(i=0;i<N;i++)
543  {
544  omFree(names[i]);
545  }
546  omFreeSize(names,N*sizeof(char*));
547  return NULL;
548  }
549  ideal q=ssiReadIdeal_R(d,r);
550  if (IDELEMS(q)==0) omFreeBin(q,sip_sideal_bin);
551  else r->qideal=q;
552  for(i=0;i<N;i++)
553  {
554  omFree(names[i]);
555  }
556  omFreeSize(names,N*sizeof(char*));
557  return r;
558  }
559 }
for idElimination, like a, except pFDeg, pWeigths ignore it
Definition: ring.h:92
for int64 weights
Definition: ring.h:72
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
Definition: coeffs.h:39
omBin sip_sideal_bin
Definition: simpleideals.cc:29
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omAlloc(size)
Definition: omAllocDecl.h:210
s_buff f_read
Definition: s_buff.h:22
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:48
int s_readint(s_buff F)
Definition: s_buff.cc:110
#define omFree(addr)
Definition: omAllocDecl.h:261
The main handler for Singular numbers which are suitable for Singular polynomials.
rRingOrder_t
order stuff
Definition: ring.h:68
struct for passing initialization parameters to naInitChar
Definition: transext.h:88
int i
Definition: cfEzgcd.cc:125
Induced (Schreyer) ordering.
Definition: ring.h:94
#define IDELEMS(i)
Definition: simpleideals.h:24
ring rDefault(const coeffs cf, int N, char **n, int ord_size, rRingOrder_t *ord, int *block0, int *block1, int **wvhdl, unsigned long bitmask)
Definition: ring.cc:103
CanonicalForm cf
Definition: cfModGcd.cc:4024
#define NULL
Definition: omList.c:10
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic
Definition: coeffs.h:36
coeffs nFindCoeffByName(char *cf_name)
find an existing coeff by its "CoeffName"
Definition: numbers.cc:589
static jList * T
Definition: janet.cc:31
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
void Werror(const char *fmt,...)
Definition: reporter.cc:189
#define omAlloc0(size)
Definition: omAllocDecl.h:211
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:350

◆ ssiReadString()

char* ssiReadString ( const ssiInfo d)

Definition at line 383 of file ssiLink.cc.

384 {
385  char *buf;
386  int l;
387  l=s_readint(d->f_read);
388  buf=(char*)omAlloc0(l+1);
389  int throwaway =s_getc(d->f_read); /* skip ' '*/
390  throwaway=s_readbytes(buf,l,d->f_read);
391  //if (throwaway!=l) printf("want %d, got %d bytes\n",l,throwaway);
392  buf[l]='\0';
393  return buf;
394 }
int s_readbytes(char *buff, int len, s_buff F)
Definition: s_buff.cc:166
int s_getc(s_buff F)
Definition: s_buff.cc:56
s_buff f_read
Definition: s_buff.h:22
int s_readint(s_buff F)
Definition: s_buff.cc:110
int status int void * buf
Definition: si_signals.h:59
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:93

◆ ssiReservePort()

int ssiReservePort ( int  clients)

Definition at line 1865 of file ssiLink.cc.

1866 {
1867  if (ssiReserved_P!=0)
1868  {
1869  WerrorS("ERROR already a reverved port requested");
1870  return 0;
1871  }
1872  int portno;
1873  ssiReserved_sockfd = socket(AF_INET, SOCK_STREAM, 0);
1874  if(ssiReserved_sockfd < 0)
1875  {
1876  WerrorS("ERROR opening socket");
1877  return 0;
1878  }
1879  memset((char *) &ssiResverd_serv_addr,0, sizeof(ssiResverd_serv_addr));
1880  portno = 1025;
1881  ssiResverd_serv_addr.sin_family = AF_INET;
1882  ssiResverd_serv_addr.sin_addr.s_addr = INADDR_ANY;
1883  do
1884  {
1885  portno++;
1886  ssiResverd_serv_addr.sin_port = htons(portno);
1887  if(portno > 50000)
1888  {
1889  WerrorS("ERROR on binding (no free port available?)");
1890  return 0;
1891  }
1892  }
1893  while(bind(ssiReserved_sockfd, (struct sockaddr *) &ssiResverd_serv_addr, sizeof(ssiResverd_serv_addr)) < 0);
1894  ssiReserved_P=portno;
1895  listen(ssiReserved_sockfd,clients);
1896  ssiReserved_Clients=clients;
1897  return portno;
1898 }
void WerrorS(const char *s)
Definition: feFopen.cc:24

◆ ssiSetCurrRing()

BOOLEAN ssiSetCurrRing ( const ring  r)

Definition at line 72 of file ssiLink.cc.

73 {
74  // if (currRing!=NULL)
75  // Print("need to change the ring, currRing:%s, switch to: ssiRing%d\n",IDID(currRingHdl),nr);
76  // else
77  // Print("no ring, switch to ssiRing%d\n",nr);
78  if (!rEqual(r,currRing,1))
79  {
80  char name[20];
81  int nr=0;
82  idhdl h=NULL;
83  loop
84  {
85  sprintf(name,"ssiRing%d",nr); nr++;
86  h=IDROOT->get(name, 0);
87  if (h==NULL)
88  {
90  IDRING(h)=r;
91  r->ref++;
92  break;
93  }
94  else if ((IDTYP(h)==RING_CMD)
95  && (rEqual(r,IDRING(h),1)))
96  break;
97  }
98  rSetHdl(h);
99  return FALSE;
100  }
101  else
102  {
103  rKill(r);
104  return TRUE;
105  }
106 }
#define FALSE
Definition: auxiliary.h:94
#define IDROOT
Definition: ipid.h:18
#define TRUE
Definition: auxiliary.h:98
#define loop
Definition: structs.h:78
Definition: idrec.h:34
#define IDTYP(a)
Definition: ipid.h:114
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:267
void rKill(ring r)
Definition: ipshell.cc:6119
char name(const Variable &v)
Definition: factory.h:180
BOOLEAN rEqual(ring r1, ring r2, BOOLEAN qr)
returns TRUE, if r1 equals r2 FALSE, otherwise Equality is determined componentwise,...
Definition: ring.cc:1635
#define NULL
Definition: omList.c:10
#define IDRING(a)
Definition: ipid.h:122
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
void rSetHdl(idhdl h)
Definition: ipshell.cc:5081
static Poly * h
Definition: janet.cc:972

◆ ssiSetRing()

BOOLEAN ssiSetRing ( si_link  l,
ring  r,
BOOLEAN  send 
)

Definition at line 1414 of file ssiLink.cc.

1415 {
1416  if(SI_LINK_W_OPEN_P(l)==0)
1417  if (slOpen(l,SI_LINK_OPEN|SI_LINK_WRITE,NULL)) return TRUE;
1418  ssiInfo *d = (ssiInfo *)l->data;
1419  if (d->r!=r)
1420  {
1421  if (send)
1422  {
1423  fputs("15 ",d->f_write);
1424  ssiWriteRing(d,r);
1425  }
1426  d->r=r;
1427  }
1428  if (currRing!=r) rChangeCurrRing(r);
1429  return FALSE;
1430 }
Definition: s_buff.h:20
#define FALSE
Definition: auxiliary.h:94
#define TRUE
Definition: auxiliary.h:98
ring r
Definition: s_buff.h:24
if(yy_init)
Definition: libparse.cc:1418
void rChangeCurrRing(ring r)
Definition: polys.cc:15
#define NULL
Definition: omList.c:10
FILE * f_write
Definition: s_buff.h:23
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
int l
Definition: cfEzgcd.cc:93

◆ ssiWrite()

BOOLEAN ssiWrite ( si_link  l,
leftv  data 
)

Definition at line 1433 of file ssiLink.cc.

1434 {
1435  if(SI_LINK_W_OPEN_P(l)==0)
1436  if (slOpen(l,SI_LINK_OPEN|SI_LINK_WRITE,NULL)) return TRUE;
1437  ssiInfo *d = (ssiInfo *)l->data;
1438  d->level++;
1439  //FILE *fich=d->f;
1440  while (data!=NULL)
1441  {
1442  int tt=data->Typ();
1443  void *dd=data->Data();
1444  attr *aa=data->Attribute();
1445  BOOLEAN with_attr=FALSE;
1446  if ((aa!=NULL) && ((*aa)!=NULL))
1447  {
1448  attr a=*aa;
1449  int n=0;
1450  while(a!=NULL) { n++; a=a->next;}
1451  fprintf(d->f_write,"21 %d %d ",data->flag,n);
1452  }
1453  else if (data->flag!=0)
1454  {
1455  fprintf(d->f_write,"21 %d 0 ",data->flag);
1456  }
1457  if ((dd==NULL) && (data->name!=NULL) && (tt==0)) tt=DEF_CMD;
1458  // return pure undefined names as def
1459 
1460  switch(tt /*data->Typ()*/)
1461  {
1462  case 0: /*error*/
1463  case NONE/* nothing*/:fputs("16 ",d->f_write);
1464  break;
1465  case STRING_CMD: fputs("2 ",d->f_write);
1466  ssiWriteString(d,(char *)dd);
1467  break;
1468  case INT_CMD: fputs("1 ",d->f_write);
1469  ssiWriteInt(d,(int)(long)dd);
1470  break;
1471  case BIGINT_CMD:fputs("4 ",d->f_write);
1472  ssiWriteBigInt(d,(number)dd);
1473  break;
1474  case NUMBER_CMD:
1475  if (d->r!=currRing)
1476  {
1477  fputs("15 ",d->f_write);
1479  if (d->level<=1) fputc('\n',d->f_write);
1480  }
1481  fputs("3 ",d->f_write);
1482  ssiWriteNumber(d,(number)dd);
1483  break;
1484  case RING_CMD:fputs("5 ",d->f_write);
1485  ssiWriteRing(d,(ring)dd);
1486  break;
1487  case BUCKET_CMD:
1488  {
1489  sBucket_pt b=(sBucket_pt)dd;
1490  if (d->r!=sBucketGetRing(b))
1491  {
1492  fputs("15 ",d->f_write);
1494  if (d->level<=1) fputc('\n',d->f_write);
1495  }
1496  fputs("6 ",d->f_write);
1497  ssiWritePoly(d,tt,sBucketPeek(b));
1498  break;
1499  }
1500  case POLY_CMD:
1501  case VECTOR_CMD:
1502  if (d->r!=currRing)
1503  {
1504  fputs("15 ",d->f_write);
1506  if (d->level<=1) fputc('\n',d->f_write);
1507  }
1508  if(tt==POLY_CMD) fputs("6 ",d->f_write);
1509  else fputs("9 ",d->f_write);
1510  ssiWritePoly(d,tt,(poly)dd);
1511  break;
1512  case IDEAL_CMD:
1513  case MODUL_CMD:
1514  case MATRIX_CMD:
1515  case SMATRIX_CMD:
1516  if (d->r!=currRing)
1517  {
1518  fputs("15 ",d->f_write);
1520  if (d->level<=1) fputc('\n',d->f_write);
1521  }
1522  if(tt==IDEAL_CMD) fputs("7 ",d->f_write);
1523  else if(tt==MATRIX_CMD) fputs("8 ",d->f_write);
1524  else if(tt==SMATRIX_CMD) fputs("22 ",d->f_write);
1525  else
1526  {
1527  ideal M=(ideal)dd;
1528  fprintf(d->f_write,"10 %d ",(int)M->rank);
1529  }
1530  ssiWriteIdeal(d,tt,(ideal)dd);
1531  break;
1532  case COMMAND:
1533  fputs("11 ",d->f_write);
1534  ssiWriteCommand(l,(command)dd);
1535  break;
1536  case DEF_CMD: /* not evaluated stuff in quotes */
1537  fputs("12 ",d->f_write);
1538  ssiWriteString(d,data->Name());
1539  break;
1540  case PROC_CMD:
1541  fputs("13 ",d->f_write);
1542  ssiWriteProc(d,(procinfov)dd);
1543  break;
1544  case LIST_CMD:
1545  fputs("14 ",d->f_write);
1546  ssiWriteList(l,(lists)dd);
1547  break;
1548  case INTVEC_CMD:
1549  fputs("17 ",d->f_write);
1550  ssiWriteIntvec(d,(intvec *)dd);
1551  break;
1552  case INTMAT_CMD:
1553  fputs("18 ",d->f_write);
1554  ssiWriteIntmat(d,(intvec *)dd);
1555  break;
1556  case BIGINTMAT_CMD:
1557  fputs("19 ",d->f_write);
1558  ssiWriteBigintmat(d,(bigintmat *)dd);
1559  break;
1560  default:
1561  if (tt>MAX_TOK)
1562  {
1563  blackbox *b=getBlackboxStuff(tt);
1564  fputs("20 ",d->f_write);
1565  b->blackbox_serialize(b,dd,l);
1566  }
1567  else
1568  {
1569  Werror("not implemented (t:%d, rtyp:%d)",tt, data->rtyp);
1570  d->level=0;
1571  return TRUE;
1572  }
1573  break;
1574  }
1575  if (d->level<=1) { fputc('\n',d->f_write); fflush(d->f_write); }
1576  data=data->next;
1577  }
1578  d->level--;
1579  return FALSE;
1580 }
Definition: s_buff.h:20
ip_command * command
Definition: ipid.h:22
Definition: tok.h:96
Definition: attrib.h:17
BITSET flag
Definition: subexpr.h:90
Definition: lists.h:22
#define FALSE
Definition: auxiliary.h:94
attr * Attribute()
Definition: subexpr.cc:1476
Definition: tok.h:38
Matrices of numbers.
Definition: bigintmat.h:51
Definition: tok.h:216
char level
Definition: s_buff.h:27
#define TRUE
Definition: auxiliary.h:98
ring r
Definition: s_buff.h:24
int Typ()
Definition: subexpr.cc:1039
const char * Name()
Definition: subexpr.h:120
#define M
Definition: sirandom.c:24
CanonicalForm b
Definition: cfModGcd.cc:4044
Definition: intvec.h:17
Definition: tok.h:58
const char * name
Definition: subexpr.h:87
sBucket * sBucket_pt
Definition: sbuckets.h:16
while(1)
Definition: libparse.cc:1442
leftv next
Definition: subexpr.h:86
ring sBucketGetRing(const sBucket_pt bucket)
Returns bucket ring.
Definition: sbuckets.cc:48
#define NULL
Definition: omList.c:10
FILE * f_write
Definition: s_buff.h:23
attr next
Definition: attrib.h:26
int rtyp
Definition: subexpr.h:91
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
void * Data()
Definition: subexpr.cc:1182
poly sBucketPeek(sBucket_pt b)
Definition: sbuckets.cc:455
Definition: tok.h:118
int BOOLEAN
Definition: auxiliary.h:85
#define NONE
Definition: tok.h:219
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int l
Definition: cfEzgcd.cc:93
#define COMMAND
Definition: tok.h:29
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:16

◆ ssiWriteBigInt()

void ssiWriteBigInt ( const ssiInfo d,
const number  n 
)

Definition at line 120 of file ssiLink.cc.

121 {
123 }
coeffs coeffs_BIGINT
Definition: ipid.cc:52
static FORCE_INLINE void n_WriteFd(number a, const ssiInfo *f, const coeffs r)
io via ssi:
Definition: coeffs.h:992

◆ ssiWriteBigintmat()

void ssiWriteBigintmat ( const ssiInfo d,
bigintmat v 
)

Definition at line 373 of file ssiLink.cc.

374 {
375  fprintf(d->f_write,"%d %d ",v->rows(),v->cols());
376  int i;
377  for(i=0;i<v->length();i++)
378  {
379  ssiWriteBigInt(d,(*v)[i]);
380  }
381 }
int i
Definition: cfEzgcd.cc:125
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
FILE * f_write
Definition: s_buff.h:23

◆ ssiWriteCommand()

void ssiWriteCommand ( si_link  l,
command  D 
)

Definition at line 320 of file ssiLink.cc.

321 {
322  ssiInfo *d=(ssiInfo*)l->data;
323  // syntax: <num ops> <operation> <op1> <op2> ....
324  fprintf(d->f_write,"%d %d ",D->argc,D->op);
325  if (D->argc >0) ssiWrite(l, &(D->arg1));
326  if (D->argc < 4)
327  {
328  if (D->argc >1) ssiWrite(l, &(D->arg2));
329  if (D->argc >2) ssiWrite(l, &(D->arg3));
330  }
331 }
Definition: s_buff.h:20
#define D(A)
Definition: gentable.cc:131
FILE * f_write
Definition: s_buff.h:23
int l
Definition: cfEzgcd.cc:93

◆ ssiWriteIdeal()

void ssiWriteIdeal ( const ssiInfo d,
int  typ,
const ideal  I 
)

Definition at line 315 of file ssiLink.cc.

316 {
317  ssiWriteIdeal_R(d,typ,I,d->r);
318 }
ring r
Definition: s_buff.h:24

◆ ssiWriteIdeal_R()

void ssiWriteIdeal_R ( const ssiInfo d,
int  typ,
const ideal  I,
const ring  r 
)

Definition at line 285 of file ssiLink.cc.

286 {
287  // syntax: 7 # of elements <poly 1> <poly2>.....(ideal,module,smatrix)
288  // syntax: 8 <rows> <cols> <poly 1> <poly2>.....(matrix)
289  // syntax
290  matrix M=(matrix)I;
291  int mn;
292  if (typ==MATRIX_CMD)
293  {
294  mn=MATROWS(M)*MATCOLS(M);
295  fprintf(d->f_write,"%d %d ", MATROWS(M),MATCOLS(M));
296  }
297  else
298  {
299  mn=IDELEMS(I);
300  fprintf(d->f_write,"%d ",IDELEMS(I));
301  }
302 
303  int i;
304  int tt;
305  if ((typ==MODUL_CMD)||(typ==SMATRIX_CMD))
306  tt=VECTOR_CMD;
307  else
308  tt=POLY_CMD;
309 
310  for(i=0;i<mn;i++)
311  {
312  ssiWritePoly_R(d,tt,I->m[i],R);
313  }
314 }
#define M
Definition: sirandom.c:24
int i
Definition: cfEzgcd.cc:125
#define IDELEMS(i)
Definition: simpleideals.h:24
#define MATCOLS(i)
Definition: matpol.h:27
FILE * f_write
Definition: s_buff.h:23
#define R
Definition: sirandom.c:26
#define MATROWS(i)
Definition: matpol.h:26
ip_smatrix * matrix
Definition: matpol.h:31

◆ ssiWriteInt()

void ssiWriteInt ( const ssiInfo d,
const int  i 
)

Definition at line 108 of file ssiLink.cc.

109 {
110  fprintf(d->f_write,"%d ",i);
111  //if (d->f_debug!=NULL) fprintf(d->f_debug,"int: %d ",i);
112 }
int i
Definition: cfEzgcd.cc:125
FILE * f_write
Definition: s_buff.h:23

◆ ssiWriteIntmat()

void ssiWriteIntmat ( const ssiInfo d,
intvec v 
)

Definition at line 363 of file ssiLink.cc.

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  fprintf(d->f_write,"%d ",(*v)[i]);
370  }
371 }
int i
Definition: cfEzgcd.cc:125
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
FILE * f_write
Definition: s_buff.h:23

◆ ssiWriteIntvec()

void ssiWriteIntvec ( const ssiInfo d,
intvec v 
)

Definition at line 354 of file ssiLink.cc.

355 {
356  fprintf(d->f_write,"%d ",v->length());
357  int i;
358  for(i=0;i<v->length();i++)
359  {
360  fprintf(d->f_write,"%d ",(*v)[i]);
361  }
362 }
int i
Definition: cfEzgcd.cc:125
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
FILE * f_write
Definition: s_buff.h:23

◆ ssiWriteList()

void ssiWriteList ( si_link  l,
lists  dd 
)

Definition at line 343 of file ssiLink.cc.

344 {
345  ssiInfo *d=(ssiInfo*)l->data;
346  int Ll=dd->nr;
347  fprintf(d->f_write,"%d ",Ll+1);
348  int i;
349  for(i=0;i<=Ll;i++)
350  {
351  ssiWrite(l,&(dd->m[i]));
352  }
353 }
Definition: s_buff.h:20
sleftv * m
Definition: lists.h:45
int i
Definition: cfEzgcd.cc:125
int nr
Definition: lists.h:43
FILE * f_write
Definition: s_buff.h:23
int l
Definition: cfEzgcd.cc:93

◆ ssiWriteNumber()

void ssiWriteNumber ( const ssiInfo d,
const number  n 
)

Definition at line 153 of file ssiLink.cc.

154 {
155  ssiWriteNumber_CF(d,n,d->r->cf);
156 }
ring r
Definition: s_buff.h:24

◆ ssiWriteNumber_CF()

void ssiWriteNumber_CF ( const ssiInfo d,
const number  n,
const coeffs  cf 
)

Definition at line 125 of file ssiLink.cc.

126 {
127  // syntax is as follows:
128  // case 1 Z/p: 3 <int>
129  // case 2 Q: 3 4 <int>
130  // or 3 0 <mpz_t nominator> <mpz_t denominator>
131  // or 3 1 dto.
132  // or 3 3 <mpz_t nominator>
133  // or 3 5 <mpz_t raw nom.> <mpz_t raw denom.>
134  // or 3 6 <mpz_t raw nom.> <mpz_t raw denom.>
135  // or 3 8 <mpz_t raw nom.>
136  if (getCoeffType(cf)==n_transExt)
137  {
138  fraction f=(fraction)n;
139  ssiWritePoly_R(d,POLY_CMD,NUM(f),cf->extRing);
140  ssiWritePoly_R(d,POLY_CMD,DEN(f),cf->extRing);
141  }
142  else if (getCoeffType(cf)==n_algExt)
143  {
144  ssiWritePoly_R(d,POLY_CMD,(poly)n,cf->extRing);
145  }
146  else if (cf->cfWriteFd!=NULL)
147  {
148  n_WriteFd(n,d,cf);
149  }
150  else WerrorS("coeff field not implemented");
151 }
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
Definition: coeffs.h:39
void WerrorS(const char *s)
Definition: feFopen.cc:24
FILE * f
Definition: checklibs.c:9
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
CanonicalForm cf
Definition: cfModGcd.cc:4024
#define NULL
Definition: omList.c:10
Definition: readcf.cc:164
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic
Definition: coeffs.h:36
static FORCE_INLINE void n_WriteFd(number a, const ssiInfo *f, const coeffs r)
io via ssi:
Definition: coeffs.h:992

◆ ssiWritePoly()

void ssiWritePoly ( const ssiInfo d,
int  typ,
poly  p 
)

Definition at line 280 of file ssiLink.cc.

281 {
282  ssiWritePoly_R(d,typ,p,d->r);
283 }
ring r
Definition: s_buff.h:24
int p
Definition: cfModGcd.cc:4019

◆ ssiWritePoly_R()

void ssiWritePoly_R ( const ssiInfo d,
int  typ,
poly  p,
const ring  r 
)

Definition at line 262 of file ssiLink.cc.

263 {
264  fprintf(d->f_write,"%d ",pLength(p));//number of terms
265 
266  while(p!=NULL)
267  {
268  ssiWriteNumber_CF(d,pGetCoeff(p),r->cf);
269  //nWrite(fich,pGetCoeff(p));
270  fprintf(d->f_write,"%ld ",p_GetComp(p,r));//component
271 
272  for(int j=1;j<=rVar(r);j++)
273  {
274  fprintf(d->f_write,"%ld ",p_GetExp(p,j,r ));//x^j
275  }
276  pIter(p);
277  }
278 }
int j
Definition: facHensel.cc:105
#define p_GetComp(p, r)
Definition: monomials.h:65
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:582
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition: monomials.h:45
#define pIter(p)
Definition: monomials.h:38
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent @Note: the integer VarOffset encodes:
Definition: p_polys.h:470
static unsigned pLength(poly a)
Definition: p_polys.h:193
#define NULL
Definition: omList.c:10
FILE * f_write
Definition: s_buff.h:23
int p
Definition: cfModGcd.cc:4019

◆ ssiWriteProc()

void ssiWriteProc ( const ssiInfo d,
procinfov  p 
)

Definition at line 333 of file ssiLink.cc.

334 {
335  if (p->data.s.body==NULL)
337  if (p->data.s.body!=NULL)
338  ssiWriteString(d,p->data.s.body);
339  else
340  ssiWriteString(d,"");
341 }
#define NULL
Definition: omList.c:10
int p
Definition: cfModGcd.cc:4019
char * iiGetLibProcBuffer(procinfo *pi, int part)
Definition: iplib.cc:192

◆ ssiWriteRing()

void ssiWriteRing ( ssiInfo d,
const ring  r 
)

Definition at line 240 of file ssiLink.cc.

241 {
242  /* 5 <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... <extRing> <Q-ideal> */
243  /* ch=-1: transext, coeff ring follows */
244  /* ch=-2: algext, coeff ring and minpoly follows */
245  /* ch=-3: cf name follows */
246  if ((r==NULL)||(r->cf==NULL))
247  {
248  WerrorS("undefined ring");
249  return;
250  }
251  if (r==currRing) // see recursive calls for transExt/algExt
252  {
253  if (d->r!=NULL) rKill(d->r);
254  d->r=r;
255  }
256  if (r!=NULL)
257  {
258  /*d->*/r->ref++;
259  }
260  ssiWriteRing_R(d,r);
261 }
void WerrorS(const char *s)
Definition: feFopen.cc:24
ring r
Definition: s_buff.h:24
void rKill(ring r)
Definition: ipshell.cc:6119
#define NULL
Definition: omList.c:10
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13

◆ ssiWriteRing_R()

void ssiWriteRing_R ( ssiInfo d,
const ring  r 
)

Definition at line 158 of file ssiLink.cc.

159 {
160  /* 5 <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... <extRing> <Q-ideal> */
161  /* ch=-1: transext, coeff ring follows */
162  /* ch=-2: algext, coeff ring and minpoly follows */
163  /* ch=-3: cf name follows */
164  if (r!=NULL)
165  {
166  if (rField_is_Q(r) || rField_is_Zp(r))
167  fprintf(d->f_write,"%d %d ",n_GetChar(r->cf),r->N);
168  else if (rFieldType(r)==n_transExt)
169  fprintf(d->f_write,"-1 %d ",r->N);
170  else if (rFieldType(r)==n_algExt)
171  fprintf(d->f_write,"-2 %d ",r->N);
172  else /*dummy*/
173  {
174  fprintf(d->f_write,"-3 %d ",r->N);
175  ssiWriteString(d,nCoeffName(r->cf));
176  }
177 
178  int i;
179  for(i=0;i<r->N;i++)
180  {
181  fprintf(d->f_write,"%d %s ",(int)strlen(r->names[i]),r->names[i]);
182  }
183  /* number of orderings:*/
184  i=0;
185  // remember dummy ring: everything 0:
186  if (r->order!=NULL) while (r->order[i]!=0) i++;
187  fprintf(d->f_write,"%d ",i);
188  /* each ordering block: */
189  i=0;
190  if (r->order!=NULL) while(r->order[i]!=0)
191  {
192  fprintf(d->f_write,"%d %d %d ",r->order[i],r->block0[i], r->block1[i]);
193  switch(r->order[i])
194  {
195  case ringorder_a:
196  case ringorder_wp:
197  case ringorder_Wp:
198  case ringorder_ws:
199  case ringorder_Ws:
200  case ringorder_aa:
201  {
202  int ii;
203  for(ii=r->block0[i];ii<=r->block1[i];ii++)
204  fprintf(d->f_write,"%d ",r->wvhdl[i][ii-r->block0[i]]);
205  }
206  break;
207 
208  case ringorder_a64:
209  case ringorder_M:
210  case ringorder_L:
211  case ringorder_IS:
212  Werror("ring oder not implemented for ssi:%d",r->order[i]);
213  break;
214 
215  default: break;
216  }
217  i++;
218  }
219  if ((rFieldType(r)==n_transExt)
220  || (rFieldType(r)==n_algExt))
221  {
222  ssiWriteRing_R(d,r->cf->extRing); /* includes alg.ext if rFieldType(r)==n_algExt */
223  }
224  /* Q-ideal :*/
225  if (r->qideal!=NULL)
226  {
227  ssiWriteIdeal_R(d,IDEAL_CMD,r->qideal,r);
228  }
229  else
230  {
231  fputs("0 ",d->f_write/*ideal with 0 entries */);
232  }
233  }
234  else /* dummy ring r==NULL*/
235  {
236  fputs("0 0 0 0 "/*,r->ch,r->N, blocks, q-ideal*/,d->f_write);
237  }
238 }
for idElimination, like a, except pFDeg, pWeigths ignore it
Definition: ring.h:92
n_coeffType rFieldType(ring r)
Definition: ring.cc:5119
for int64 weights
Definition: ring.h:72
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
Definition: coeffs.h:39
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:444
static FORCE_INLINE char * nCoeffName(const coeffs cf)
Definition: coeffs.h:985
int i
Definition: cfEzgcd.cc:125
Induced (Schreyer) ordering.
Definition: ring.h:94
static BOOLEAN rField_is_Q(const ring r)
Definition: ring.h:497
static BOOLEAN rField_is_Zp(const ring r)
Definition: ring.h:491
#define NULL
Definition: omList.c:10
FILE * f_write
Definition: s_buff.h:23
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic
Definition: coeffs.h:36
void Werror(const char *fmt,...)
Definition: reporter.cc:189

◆ ssiWriteString()

void ssiWriteString ( const ssiInfo d,
const char *  s 
)

Definition at line 114 of file ssiLink.cc.

115 {
116  fprintf(d->f_write,"%d %s ",(int)strlen(s),s);
117  //if (d->f_debug!=NULL) fprintf(d->f_debug,"stringi: %d \"%s\" ",strlen(s),s);
118 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
FILE * f_write
Definition: s_buff.h:23

Variable Documentation

◆ si_link_root

si_link_extension si_link_root

Definition at line 46 of file silink.cc.

◆ ssiReserved_Clients

int ssiReserved_Clients
static

Definition at line 1864 of file ssiLink.cc.

◆ ssiReserved_P

int ssiReserved_P =0
static

Definition at line 1861 of file ssiLink.cc.

◆ ssiReserved_sockfd

int ssiReserved_sockfd
static

Definition at line 1862 of file ssiLink.cc.

◆ ssiResverd_serv_addr

struct sockaddr_in ssiResverd_serv_addr
static

Definition at line 1863 of file ssiLink.cc.

◆ ssiToBeClosed

link_list ssiToBeClosed =NULL

Definition at line 62 of file ssiLink.cc.

◆ ssiToBeClosed_inactive

volatile BOOLEAN ssiToBeClosed_inactive =TRUE

Definition at line 63 of file ssiLink.cc.