My Project
Loading...
Searching...
No Matches
ssiLink.cc File Reference
#include "kernel/mod2.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/feOpt.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   15
 

Functions

static void ssiWritePoly_R (const ssiInfo *d, int typ, poly p, const ring r)
 
static void ssiWriteIdeal_R (const ssiInfo *d, int typ, const ideal I, const ring r)
 
static poly ssiReadPoly_R (const ssiInfo *D, const ring r)
 
static ideal ssiReadIdeal_R (const ssiInfo *d, const ring r)
 
static BOOLEAN ssiSetCurrRing (const ring r)
 
static void ssiCheckCurrRing (const ring r)
 
void ssiWriteInt (const ssiInfo *d, const int i)
 
static void ssiWriteString (const ssiInfo *d, const char *s)
 
static void ssiWriteBigInt (const ssiInfo *d, const number n)
 
static void ssiWriteNumber_CF (const ssiInfo *d, const number n, const coeffs cf)
 
static void ssiWriteNumber (const ssiInfo *d, const number n)
 
static void ssiWriteRing_R (ssiInfo *d, const ring r)
 
static void ssiWriteRing (ssiInfo *d, const ring r)
 
static void ssiWritePoly (const ssiInfo *d, int typ, poly p)
 
void ssiWriteIdeal (const ssiInfo *d, int typ, const ideal I)
 
static void ssiWriteCommand (si_link l, command D)
 
static void ssiWriteProc (const ssiInfo *d, procinfov p)
 
static void ssiWriteList (si_link l, lists dd)
 
static void ssiWriteIntvec (const ssiInfo *d, intvec *v)
 
static void ssiWriteIntmat (const ssiInfo *d, intvec *v)
 
static void ssiWriteBigintmat (const ssiInfo *d, bigintmat *v)
 
static void ssiWriteBigintvec (const ssiInfo *d, bigintmat *v)
 
static char * ssiReadString (const ssiInfo *d)
 
int ssiReadInt (const ssiInfo *d)
 
static number ssiReadNumber_CF (const ssiInfo *d, const coeffs cf)
 
static number ssiReadBigInt (const ssiInfo *d)
 
static number ssiReadNumber (ssiInfo *d)
 
static ring ssiReadRing (ssiInfo *d)
 
static poly ssiReadPoly (ssiInfo *d)
 
ideal ssiReadIdeal (ssiInfo *d)
 
static matrix ssiReadMatrix (ssiInfo *d)
 
static command ssiReadCommand (si_link l)
 
static procinfov ssiReadProc (const ssiInfo *d)
 
static lists ssiReadList (si_link l)
 
static intvecssiReadIntvec (const ssiInfo *d)
 
static intvecssiReadIntmat (const ssiInfo *d)
 
static bigintmatssiReadBigintmat (const ssiInfo *d)
 
static bigintmatssiReadBigintvec (const ssiInfo *d)
 
static void ssiReadBlackbox (leftv res, si_link l)
 
static void ssiReadAttrib (leftv res, si_link l)
 
static void ssiReadRingProperties (si_link l)
 
BOOLEAN ssiOpen (si_link l, short flag, leftv u)
 
static BOOLEAN ssiPrepClose (si_link l)
 
BOOLEAN ssiClose (si_link l)
 
leftv ssiRead1 (si_link l)
 
static 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, BOOLEAN *ignore)
 
int ssiBatch (const char *host, const char *port)
 
int ssiReservePort (int clients)
 
si_link ssiCommandLink ()
 
void sig_chld_hdl (int)
 additional default signal handler
 
static BOOLEAN DumpSsiIdhdl (si_link l, idhdl h)
 
static BOOLEAN ssiDumpIter (si_link l, idhdl h)
 
void singular_close_links ()
 

Variables

EXTERN_VAR BOOLEAN FE_OPT_NO_SHELL_FLAG
 
VAR link_list ssiToBeClosed =NULL
 
VAR volatile BOOLEAN ssiToBeClosed_inactive =TRUE
 
STATIC_VAR int ssiReserved_P =0
 
STATIC_VAR int ssiReserved_sockfd
 
STATIC_VAR struct sockaddr_in ssiResverd_serv_addr
 
STATIC_VAR int ssiReserved_Clients
 
EXTERN_VAR si_link_extension si_link_root
 

Macro Definition Documentation

◆ SSI_VERSION

#define SSI_VERSION   15

Definition at line 55 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 2357 of file ssiLink.cc.

2358{
2359 int type_id = IDTYP(h);
2360
2361 // C-proc not to be dumped, also LIB-proc not
2362 if (type_id == PROC_CMD)
2363 {
2364 if (IDPROC(h)->language == LANG_C) return FALSE;
2365 if (IDPROC(h)->libname != NULL) return FALSE;
2366 }
2367 // do not dump links
2368 if (type_id == LINK_CMD) return FALSE;
2369
2370 // do not dump ssi internal rings: ssiRing*
2371 if ((type_id == RING_CMD) && (strncmp(IDID(h),"ssiRing",7)==0))
2372 return FALSE;
2373
2374 // do not dump default cring:
2375 if (type_id == CRING_CMD)
2376 {
2377 if (strcmp(IDID(h),"ZZ")==0) return FALSE;
2378 if (strcmp(IDID(h),"QQ")==0) return FALSE;
2379 #ifdef SINGULAR_4_2
2380 if (strcmp(IDID(h),"AE")==0) return FALSE;
2381 if (strcmp(IDID(h),"QAE")==0) return FALSE;
2382 #endif
2383 }
2384
2385 command D=(command)omAlloc0(sizeof(*D));
2386 sleftv tmp;
2387 memset(&tmp,0,sizeof(tmp));
2388 tmp.rtyp=COMMAND;
2389 tmp.data=D;
2390
2391 if (type_id == PACKAGE_CMD)
2392 {
2393 // do not dump Top, Standard
2394 if ((strcmp(IDID(h), "Top") == 0)
2395 || (strcmp(IDID(h), "Standard") == 0))
2396 {
2397 omFreeSize(D,sizeof(*D));
2398 return FALSE;
2399 }
2400 package p=(package)IDDATA(h);
2401 // dump Singular-packages as LIB("...");
2402 if (p->language==LANG_SINGULAR)
2403 {
2404 D->op=LOAD_CMD;
2405 D->argc=2;
2406 D->arg1.rtyp=STRING_CMD;
2407 D->arg1.data=p->libname;
2408 D->arg2.rtyp=STRING_CMD;
2409 D->arg2.data=(char*)"with";
2410 ssiWrite(l,&tmp);
2411 omFreeSize(D,sizeof(*D));
2412 return FALSE;
2413 }
2414 // dump Singular-packages as load("...");
2415 else if (p->language==LANG_C)
2416 {
2417 D->op=LOAD_CMD;
2418 D->argc=1;
2419 D->arg1.rtyp=STRING_CMD;
2420 D->arg1.data=p->libname;
2421 ssiWrite(l,&tmp);
2422 omFreeSize(D,sizeof(*D));
2423 return FALSE;
2424 }
2425 }
2426
2427 // put type and name
2428 //Print("generic dump:%s,%s\n",IDID(h),Tok2Cmdname(IDTYP(h)));
2429 D->op='=';
2430 D->argc=2;
2431 D->arg1.rtyp=DEF_CMD;
2432 D->arg1.name=IDID(h);
2433 D->arg2.rtyp=IDTYP(h);
2434 D->arg2.data=IDDATA(h);
2435 ssiWrite(l,&tmp);
2436 omFreeSize(D,sizeof(*D));
2437 return FALSE;
2438}
#define FALSE
Definition auxiliary.h:97
int l
Definition cfEzgcd.cc:100
int p
Definition cfModGcd.cc:4086
Class used for (list of) interpreter objects.
Definition subexpr.h:83
int rtyp
Definition subexpr.h:91
void * data
Definition subexpr.h:88
if(!FE_OPT_NO_SHELL_FLAG)
Definition fehelp.cc:1000
#define D(A)
Definition gentable.cc:128
@ PROC_CMD
Definition grammar.cc:281
@ RING_CMD
Definition grammar.cc:282
ip_command * command
Definition ipid.h:23
#define IDDATA(a)
Definition ipid.h:126
#define IDPROC(a)
Definition ipid.h:140
#define IDID(a)
Definition ipid.h:122
#define IDTYP(a)
Definition ipid.h:119
STATIC_VAR Poly * h
Definition janet.cc:971
#define omFreeSize(addr, size)
#define omAlloc0(size)
#define NULL
Definition omList.c:12
@ LANG_SINGULAR
Definition subexpr.h:22
@ LANG_C
Definition subexpr.h:22
@ CRING_CMD
Definition tok.h:56
@ PACKAGE_CMD
Definition tok.h:150
@ DEF_CMD
Definition tok.h:58
@ LINK_CMD
Definition tok.h:117
#define COMMAND
Definition tok.h:29

◆ sig_chld_hdl()

void sig_chld_hdl ( int sig)

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 2313 of file ssiLink.cc.

2314{
2315 pid_t kidpid;
2316 int status;
2317
2318#if 0
2319 loop
2320 {
2321 kidpid = si_waitpid(-1, &status, WNOHANG);
2322 if (kidpid==-1)
2323 {
2324 /* continue on interruption (EINTR): */
2325 if (errno == EINTR) continue;
2326 /* break on anything else (EINVAL or ECHILD according to manpage): */
2327 break;
2328 }
2329 else if (kidpid==0) break; /* no more children to process, so break */
2330
2331 //printf("Child %ld terminated\n", kidpid);
2333 while((hh!=NULL)&&(ssiToBeClosed_inactive))
2334 {
2335 if((hh->l!=NULL) && (hh->l->m->Open==ssiOpen))
2336 {
2337 ssiInfo *d = (ssiInfo *)hh->l->data;
2338 if(d->pid==kidpid)
2339 {
2341 {
2343 slClose(hh->l);
2345 break;
2346 }
2347 else break;
2348 }
2349 else hh=(link_list)hh->next;
2350 }
2351 else hh=(link_list)hh->next;
2352 }
2353 }
2354#endif
2355}
#define TRUE
Definition auxiliary.h:101
int * status
Definition si_signals.h:61
#define loop
Definition structs.h:71

◆ singular_close_links()

void singular_close_links ( )

Definition at line 2493 of file ssiLink.cc.

2494{
2496 while(hh!=NULL)
2497 {
2498 if ((hh->l->m!=NULL)
2499 && (hh->l->m->Open==ssiOpen)
2500 && SI_LINK_OPEN_P(hh->l)
2501 && (strcmp(hh->l->mode, "fork")==0))
2502 {
2504 ssiInfo *d = (ssiInfo *)hh->l->data;
2505 if (d->f_read!=NULL) { s_close(d->f_read);d->f_read=NULL;}
2506 if (d->f_write!=NULL) { fclose(d->f_write); d->f_write=NULL; }
2507 }
2508 hh=(link_list)hh->next;
2509 }
2511}
int s_close(s_buff &F)
Definition s_buff.cc:46

◆ slInitSsiExtension()

si_link_extension slInitSsiExtension ( si_link_extension s)

Definition at line 1871 of file ssiLink.cc.

1872{
1873 s->Open=ssiOpen;
1874 s->Close=ssiClose;
1875 s->Kill=ssiClose;
1876 s->Read=ssiRead1;
1877 s->Read2=(slRead2Proc)NULL;
1878 s->Write=ssiWrite;
1879 s->Dump=ssiDump;
1880 s->GetDump=ssiGetDump;
1881
1882 s->Status=slStatusSsi;
1883 s->SetRing=ssiSetRing;
1884 s->type="ssi";
1885 return s;
1886}
const CanonicalForm int s
Definition facAbsFact.cc:51

◆ slStatusSsi()

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

Definition at line 1888 of file ssiLink.cc.

1889{
1890 ssiInfo *d=(ssiInfo*)l->data;
1891 if (d==NULL) return "not open";
1892 if (((strcmp(l->mode,"fork")==0)
1893 ||(strcmp(l->mode,"tcp")==0)
1894 ||(strcmp(l->mode,"connect")==0))
1895 && (strcmp(request, "read") == 0))
1896 {
1897 if (s_isready(d->f_read)) return "ready";
1898#if defined(HAVE_POLL)
1899 pollfd pfd;
1900 loop
1901 {
1902 /* Don't block. Return socket status immediately. */
1903 pfd.fd=d->fd_read;
1904 pfd.events=POLLIN;
1905 //Print("test fd %d\n",d->fd_read);
1906 /* check with select: chars waiting: no -> not ready */
1907 switch (si_poll(&pfd,1,0))
1908 {
1909 case 0: /* not ready */ return "not ready";
1910 case -1: /*error*/ return "error";
1911 case 1: /*ready ? */ break;
1912 }
1913#else
1914 fd_set mask;
1915 struct timeval wt;
1916 if (FD_SETSIZE<=d->fd_read)
1917 {
1918 Werror("file descriptor number too high (%d)",d->fd_read);
1919 return "error";
1920 }
1921
1922 loop
1923 {
1924 /* Don't block. Return socket status immediately. */
1925 wt.tv_sec = 0;
1926 wt.tv_usec = 0;
1927
1928 FD_ZERO(&mask);
1929 FD_SET(d->fd_read, &mask);
1930 //Print("test fd %d\n",d->fd_read);
1931 /* check with select: chars waiting: no -> not ready */
1932 switch (si_select(d->fd_read+1, &mask, NULL, NULL, &wt))
1933 {
1934 case 0: /* not ready */ return "not ready";
1935 case -1: /*error*/ return "error";
1936 case 1: /*ready ? */ break;
1937 }
1938#endif
1939 /* yes: read 1 char*/
1940 /* if \n, check again with select else ungetc(c), ready*/
1941 int c=s_getc(d->f_read);
1942 //Print("try c=%d\n",c);
1943 if (c== -1) return "eof"; /* eof or error */
1944 else if (isdigit(c))
1945 { s_ungetc(c,d->f_read); return "ready"; }
1946 else if (c>' ')
1947 {
1948 Werror("unknown char in ssiLink(%d)",c);
1949 return "error";
1950 }
1951 /* else: next char */
1952 }
1953 }
1954 else if (strcmp(request, "read") == 0)
1955 {
1956 if (SI_LINK_R_OPEN_P(l) && (!s_iseof(d->f_read)) && (s_isready(d->f_read))) return "ready";
1957 else return "not ready";
1958 }
1959 else if (strcmp(request, "write") == 0)
1960 {
1961 if (SI_LINK_W_OPEN_P(l)) return "ready";
1962 else return "not ready";
1963 }
1964 else return "unknown status request";
1965}
void Werror(const char *fmt,...)
Definition reporter.cc:189
int s_getc(s_buff F)
Definition s_buff.cc:59
int s_isready(s_buff F)
Definition s_buff.cc:86
int s_iseof(s_buff F)
Definition s_buff.cc:255
void s_ungetc(int c, s_buff F)
Definition s_buff.cc:100

◆ slStatusSsiL()

int slStatusSsiL ( lists L,
int timeout,
BOOLEAN * ignore )

Definition at line 1967 of file ssiLink.cc.

1968{
1969// input: L: a list with links of type
1970// ssi-connect, ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch.
1971// Note: Not every entry in L must be set.
1972// timeout: timeout for select in milli-seconds
1973// or -1 for infinity
1974// or 0 for polling
1975// returns: ERROR (via Werror): L has wrong elements or link not open
1976// -2: error in L
1977// -1: the read state of all links is eof
1978// 0: timeout (or polling): none ready,
1979// i>0: (at least) L[i] is ready
1980#if defined(HAVE_POLL) && !defined(__APPLE__)
1981// fd is restricted on OsX by ulimit "file descriptors" (256)
1982 si_link l;
1983 ssiInfo *d=NULL;
1984 int d_fd;
1985 int s;
1986 int nfd=L->nr+1;
1987 pollfd *pfd=(pollfd*)omAlloc0(nfd*sizeof(pollfd));
1988 for(int i=L->nr; i>=0; i--)
1989 {
1990 pfd[i].fd=-1;
1991 if (L->m[i].Typ()!=DEF_CMD)
1992 {
1993 if (L->m[i].Typ()!=LINK_CMD)
1994 { WerrorS("all elements must be of type link"); return -2;}
1995 l=(si_link)L->m[i].Data();
1996 if(SI_LINK_OPEN_P(l)==0)
1997 { WerrorS("all links must be open"); return -2;}
1998 if (((strcmp(l->m->type,"ssi")!=0) && (strcmp(l->m->type,"MPtcp")!=0))
1999 || ((strcmp(l->mode,"fork")!=0) && (strcmp(l->mode,"tcp")!=0)
2000 && (strcmp(l->mode,"launch")!=0) && (strcmp(l->mode,"connect")!=0)))
2001 {
2002 WerrorS("all links must be of type ssi:fork, ssi:tcp, ssi:connect");
2003 return -2;
2004 }
2005 if (strcmp(l->m->type,"ssi")==0)
2006 {
2007 d=(ssiInfo*)l->data;
2008 d_fd=d->fd_read;
2009 if (!s_isready(d->f_read))
2010 {
2011 pfd[i].fd=d_fd;
2012 pfd[i].events=POLLIN;
2013 }
2014 else
2015 {
2016 return i+1;
2017 }
2018 }
2019 else
2020 {
2021 Werror("wrong link type >>%s<<",l->m->type);
2022 return -2;
2023 }
2024 }
2025 else if (ignore!=NULL)
2026 {
2027 ignore[i]=TRUE; // not a link
2028 }
2029 }
2030 s=si_poll(pfd,nfd,timeout);
2031 if (s==-1)
2032 {
2033 Werror("error in poll call (errno:%d)",errno);
2034 return -2; /*error*/
2035 }
2036 if(s==0)
2037 {
2038 return 0; /*timeout*/
2039 }
2040 for(int i=L->nr; i>=0; i--)
2041 {
2042 if ((L->m[i].rtyp==LINK_CMD)
2043 && ((ignore==NULL)||(ignore[i]==FALSE)))
2044 {
2045 // the link type is ssi, that's already tested
2046 l=(si_link)L->m[i].Data();
2047 d=(ssiInfo*)l->data;
2048 d_fd=d->fd_read;
2049 if (pfd[i].fd==d_fd)
2050 {
2051 if (pfd[i].revents &POLLIN)
2052 {
2053 omFree(pfd);
2054 return i+1;
2055 }
2056 }
2057 }
2058 }
2059 // no ready
2060 return 0;
2061#else
2062 // fd is restricted to <=1024
2063 si_link l;
2064 ssiInfo *d=NULL;
2065 int d_fd;
2066 fd_set fdmask;
2067 FD_ZERO(&fdmask);
2068 int max_fd=0; /* 1 + max fd in fd_set */
2069
2070 /* timeout */
2071 struct timeval wt;
2072 struct timeval *wt_ptr=&wt;
2073 int startingtime = getRTimer()/TIMER_RESOLUTION; // in seconds
2074 if (timeout== -1)
2075 {
2076 wt_ptr=NULL;
2077 }
2078 else
2079 {
2080 wt.tv_sec = timeout / 1000;
2081 wt.tv_usec = (timeout % 1000)*1000;
2082 }
2083
2084 /* auxiliary variables */
2085 int i;
2086 int j;
2087 int k;
2088 int s;
2089 char fdmaskempty;
2090
2091 /* check the links and fill in fdmask */
2092 /* check ssi links for ungetc_buf */
2093 for(i=L->nr; i>=0; i--)
2094 {
2095 if (L->m[i].Typ()!=DEF_CMD)
2096 {
2097 if (L->m[i].Typ()!=LINK_CMD)
2098 { WerrorS("all elements must be of type link"); return -2;}
2099 l=(si_link)L->m[i].Data();
2100 if(SI_LINK_OPEN_P(l)==0)
2101 { WerrorS("all links must be open"); return -2;}
2102 if (((strcmp(l->m->type,"ssi")!=0) && (strcmp(l->m->type,"MPtcp")!=0))
2103 || ((strcmp(l->mode,"fork")!=0) && (strcmp(l->mode,"tcp")!=0)
2104 && (strcmp(l->mode,"launch")!=0) && (strcmp(l->mode,"connect")!=0)))
2105 {
2106 WerrorS("all links must be of type ssi:fork, ssi:tcp, ssi:connect");
2107 return -2;
2108 }
2109 if (strcmp(l->m->type,"ssi")==0)
2110 {
2111 d=(ssiInfo*)l->data;
2112 d_fd=d->fd_read;
2113 if (!s_isready(d->f_read))
2114 {
2115 if ((ignore==NULL) || (ignore[i]==FALSE))
2116 {
2117 FD_SET(d_fd, &fdmask);
2118 if (d_fd > max_fd) max_fd=d_fd;
2119 }
2120 }
2121 else
2122 return i+1;
2123 }
2124 else
2125 {
2126 Werror("wrong link type >>%s<<",l->m->type);
2127 return -2;
2128 }
2129 }
2130 }
2131 max_fd++;
2132 if (FD_SETSIZE<=max_fd)
2133 {
2134 Werror("file descriptor number too high (%d)",max_fd);
2135 return -2;
2136 }
2137
2138 /* check with select: chars waiting: no -> not ready */
2139 s = si_select(max_fd, &fdmask, NULL, NULL, wt_ptr);
2140 if (s==-1)
2141 {
2142 Werror("error in select call (errno:%d)",errno);
2143 return -2; /*error*/
2144 }
2145 if (s==0)
2146 {
2147 return 0; /*poll: not ready */
2148 }
2149 else /* s>0, at least one ready (the number of fd which are ready is s)*/
2150 {
2151 j=0;
2152 while (j<=max_fd) { if (FD_ISSET(j,&fdmask)) break; j++; }
2153 for(i=L->nr; i>=0; i--)
2154 {
2155 if (L->m[i].rtyp==LINK_CMD)
2156 {
2157 l=(si_link)L->m[i].Data();
2158 if (strcmp(l->m->type,"ssi")==0)
2159 {
2160 d=(ssiInfo*)l->data;
2161 d_fd=d->fd_read;
2162 if(j==d_fd) return i+1;
2163 }
2164 }
2165 }
2166 }
2167 return 0;
2168#endif
2169}
int i
Definition cfEzgcd.cc:132
int k
Definition cfEzgcd.cc:99
int Typ()
Definition subexpr.cc:1048
void * Data()
Definition subexpr.cc:1192
sleftv * m
Definition lists.h:46
int nr
Definition lists.h:44
int j
Definition facHensel.cc:110
void WerrorS(const char *s)
Definition feFopen.cc:24
#define TIMER_RESOLUTION
Definition mod2.h:35
#define omFree(addr)
s_buff f_read
Definition s_buff.h:22
int fd_read
Definition s_buff.h:26
int status int fd
Definition si_signals.h:69
int getRTimer()
Definition timer.cc:150

◆ ssiBatch()

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

Definition at line 2171 of file ssiLink.cc.

2173{
2175 char *buf=(char*)omAlloc(256);
2176 snprintf(buf,256,"ssi:connect %s:%s",host,port);
2177 slInit(l, buf);
2178 omFreeSize(buf,256);
2179 if (slOpen(l,SI_LINK_OPEN,NULL)) return 1;
2181
2182 idhdl id = enterid("link_ll", 0, LINK_CMD, &IDROOT, FALSE);
2183 IDLINK(id) = l;
2184
2185 loop
2186 {
2187 leftv h=ssiRead1(l); /*contains an exit.... */
2188 if (feErrors != NULL && *feErrors != '\0')
2189 {
2190 // handle errors:
2191 PrintS(feErrors); /* currently quite simple */
2192 *feErrors = '\0';
2193 }
2194 ssiWrite(l,h);
2195 h->CleanUp();
2197 }
2198 /* never reached*/
2199 _exit(0);
2200}
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition ipid.cc:256
EXTERN_VAR omBin sleftv_bin
Definition ipid.h:145
#define IDLINK(a)
Definition ipid.h:138
#define IDROOT
Definition ipid.h:19
#define omAlloc(size)
#define omAlloc0Bin(bin)
#define omFreeBin(addr, bin)
void PrintS(const char *s)
Definition reporter.cc:284
VAR char * feErrors
Definition reporter.cc:47
idrec * idhdl
Definition ring.h:22
int status int void * buf
Definition si_signals.h:69
sleftv * leftv
Definition structs.h:53

◆ ssiCheckCurrRing()

static void ssiCheckCurrRing ( const ring r)
static

Definition at line 123 of file ssiLink.cc.

124{
125 if ((r!=currRing)
126 ||(currRingHdl==NULL)
127 ||(IDRING(currRingHdl)!=r))
128 {
129 char name[20];
130 int nr=0;
131 idhdl h=NULL;
132 loop
133 {
134 snprintf(name,20,"ssiRing%d",nr); nr++;
135 h=IDROOT->get(name, 0);
136 if (h==NULL)
137 {
139 IDRING(h)=rIncRefCnt(r);
140 r->ref=2;/*ref==2: d->r and h */
141 break;
142 }
143 else if ((IDTYP(h)==RING_CMD)
144 && (rEqual(r,IDRING(h),1)))
145 {
146 break;
147 }
148 }
149 rSetHdl(h);
150 }
151 assume((currRing==r) || rEqual(r,currRing));
152}
VAR idhdl currRingHdl
Definition ipid.cc:57
#define IDRING(a)
Definition ipid.h:127
void rSetHdl(idhdl h)
Definition ipshell.cc:5122
#define assume(x)
Definition mod2.h:389
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
BOOLEAN rEqual(ring r1, ring r2, BOOLEAN qr)
returns TRUE, if r1 equals r2 FALSE, otherwise Equality is determined componentwise,...
Definition ring.cc:1751
static ring rIncRefCnt(ring r)
Definition ring.h:849
int name
New type name for int.

◆ ssiClose()

BOOLEAN ssiClose ( si_link l)

Definition at line 1431 of file ssiLink.cc.

1432{
1433 if (l!=NULL)
1434 {
1436 ssiInfo *d = (ssiInfo *)l->data;
1437 if (d!=NULL)
1438 {
1439 // send quit signal
1440 if ((d->send_quit_at_exit)
1441 && (d->quit_sent==0))
1442 {
1443 fputs("99\n",d->f_write);
1444 fflush(d->f_write);
1445 d->quit_sent=1;
1446 }
1447 // clean ring
1448 if (d->r!=NULL) rKill(d->r);
1449 for(int i=0;i<SI_RING_CACHE;i++)
1450 {
1451 if (d->rings[i]!=NULL) rKill(d->rings[i]);
1452 d->rings[i]=NULL;
1453 }
1454 if (d->f_read!=NULL) { s_close(d->f_read);d->f_read=NULL;}
1455 if (d->f_write!=NULL) { fclose(d->f_write); d->f_write=NULL; }
1456 if (((strcmp(l->mode,"tcp")==0)
1457 || (strcmp(l->mode,"fork")==0))
1458 && (d->pid>1))
1459 {
1460 // did the child stop ?
1461 int pid=si_waitpid(d->pid,NULL,WNOHANG);
1462 if ((pid==0) /* no status change for child*/
1463 && (kill(d->pid,0)==0)) // child is still running
1464 {
1465 struct timespec t;
1466 struct timespec rem;
1467 // wait 60 sec
1468 for(int i=0;i<50;i++)
1469 {
1470 // wait till signal or 100ms:
1471 t.tv_sec=0;
1472 t.tv_nsec=100000000; // <=100 ms
1473 nanosleep(&t, &rem);
1474 // child finished ?
1475 if (si_waitpid(d->pid,NULL,WNOHANG) == d->pid) break;
1476 }
1477 if (kill(d->pid,0)==0) // child still exists
1478 {
1479 kill(d->pid,SIGTERM);
1480 t.tv_sec=1;
1481 t.tv_nsec=0; // <=1000 ms
1482 nanosleep(&t, &rem);
1483 si_waitpid(d->pid,NULL,WNOHANG);
1484 }
1485 }
1486 }
1487 if ((strcmp(l->mode,"tcp")==0)
1488 || (strcmp(l->mode,"fork")==0))
1489 {
1491 if (hh!=NULL)
1492 {
1493 if (hh->l==l)
1494 {
1496 omFreeSize(hh,sizeof(link_struct));
1497 }
1498 else while(hh->next!=NULL)
1499 {
1500 link_list hhh=(link_list)hh->next;
1501 if (hhh->l==l)
1502 {
1503 hh->next=hhh->next;
1504 omFreeSize(hhh,sizeof(link_struct));
1505 break;
1506 }
1507 else
1508 hh=(link_list)hh->next;
1509 }
1510 }
1511 }
1512 omFreeSize((ADDRESS)d,(sizeof *d));
1513 }
1514 l->data=NULL;
1515 }
1516 return FALSE;
1517}
void * ADDRESS
Definition auxiliary.h:120
void rKill(ring r)
Definition ipshell.cc:6174
void rem(unsigned long *a, unsigned long *q, unsigned long p, int &dega, int degq)
Definition minpoly.cc:572
#define SI_RING_CACHE
Definition s_buff.h:30

◆ ssiCommandLink()

si_link ssiCommandLink ( )

Definition at line 2242 of file ssiLink.cc.

2243{
2244 if (ssiReserved_P==0)
2245 {
2246 WerrorS("ERROR no reserved port requested");
2247 return NULL;
2248 }
2249 struct sockaddr_in cli_addr;
2250 int clilen = sizeof(cli_addr);
2251 int newsockfd = si_accept(ssiReserved_sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
2252 if(newsockfd < 0)
2253 {
2254 Werror("ERROR on accept (errno=%d)",errno);
2255 return NULL;
2256 }
2258 si_link_extension s = si_link_root;
2259 si_link_extension prev = s;
2260 while (strcmp(s->type, "ssi") != 0)
2261 {
2262 if (s->next == NULL)
2263 {
2264 prev = s;
2265 s = NULL;
2266 break;
2267 }
2268 else
2269 {
2270 s = s->next;
2271 }
2272 }
2273 if (s != NULL)
2274 l->m = s;
2275 else
2276 {
2277 si_link_extension ns = (si_link_extension)omAlloc0Bin(s_si_link_extension_bin);
2278 prev->next=slInitSsiExtension(ns);
2279 l->m = prev->next;
2280 }
2281 l->name=omStrDup("");
2282 l->mode=omStrDup("tcp");
2283 l->ref=1;
2284 ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo));
2285 l->data=d;
2286 d->fd_read = newsockfd;
2287 d->fd_write = newsockfd;
2288 d->f_read = s_open(newsockfd);
2289 d->f_write = fdopen(newsockfd, "w");
2292 if (ssiReserved_Clients<=0)
2293 {
2294 ssiReserved_P=0;
2295 si_close(ssiReserved_sockfd);
2296 }
2297 return l;
2298}
#define omStrDup(s)
s_buff s_open(int fd)
Definition s_buff.cc:32
int fd_write
Definition s_buff.h:26
FILE * f_write
Definition s_buff.h:23

◆ ssiDump()

BOOLEAN ssiDump ( si_link l)

Definition at line 2460 of file ssiLink.cc.

2461{
2462 idhdl h = IDROOT, rh = currRingHdl;
2464
2465 //if (! status ) status = DumpAsciiMaps(fd, h, NULL);
2466
2467 if (currRingHdl != rh) rSetHdl(rh);
2468 //fprintf(fd, "option(set, intvec(%d, %d));\n", si_opt_1, si_opt_2);
2469
2470 return status;
2471}
int BOOLEAN
Definition auxiliary.h:88

◆ ssiDumpIter()

static BOOLEAN ssiDumpIter ( si_link l,
idhdl h )
static

Definition at line 2439 of file ssiLink.cc.

2440{
2441 if (h == NULL) return FALSE;
2442
2443 if (ssiDumpIter(l, IDNEXT(h))) return TRUE;
2444
2445 // need to set the ring before writing it, otherwise we get in
2446 // trouble with minpoly
2447 if (IDTYP(h) == RING_CMD)
2448 rSetHdl(h);
2449
2450 if (DumpSsiIdhdl(l, h)) return TRUE;
2451
2452 // do not dump ssi internal rings: ssiRing*
2453 // but dump objects of all other rings
2454 if ((IDTYP(h) == RING_CMD)
2455 && (strncmp(IDID(h),"ssiRing",7)!=0))
2456 return ssiDumpIter(l, IDRING(h)->idroot);
2457 else
2458 return FALSE;
2459}
#define IDNEXT(a)
Definition ipid.h:118

◆ ssiGetDump()

BOOLEAN ssiGetDump ( si_link l)

Definition at line 2472 of file ssiLink.cc.

2473{
2474 ssiInfo *d=(ssiInfo*)l->data;
2475 loop
2476 {
2477 if (!SI_LINK_OPEN_P(l)) break;
2478 if (s_iseof(d->f_read)) break;
2479 leftv h=ssiRead1(l); /*contains an exit.... */
2480 if (feErrors != NULL && *feErrors != '\0')
2481 {
2482 // handle errors:
2483 PrintS(feErrors); /* currently quite simple */
2484 return TRUE;
2485 *feErrors = '\0';
2486 }
2487 h->CleanUp();
2489 }
2490 return FALSE;
2491}

◆ ssiOpen()

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

Definition at line 999 of file ssiLink.cc.

1000{
1001 if (l!=NULL)
1002 {
1003 const char *mode;
1004 ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo));
1005 if (flag & SI_LINK_OPEN)
1006 {
1007 if (l->mode[0] != '\0' && (strcmp(l->mode, "r") == 0))
1008 flag = SI_LINK_READ;
1009 else flag = SI_LINK_WRITE;
1010 }
1011
1012 if (flag == SI_LINK_READ) mode = "r";
1013 else if (strcmp(l->mode, "w") == 0) mode = "w";
1014 else if (strcmp(l->mode, "fork") == 0) mode = "fork";
1015 else if (strcmp(l->mode, "tcp") == 0) mode = "tcp";
1016 else if (strcmp(l->mode, "connect") == 0) mode = "connect";
1017 else mode = "a";
1018
1019
1020 SI_LINK_SET_OPEN_P(l, flag);
1021 if(l->data!=NULL) omFreeSize(l->data,sizeof(ssiInfo));
1022 l->data=d;
1023 omFreeBinAddr(l->mode);
1024 l->mode = omStrDup(mode);
1025
1026 if (l->name[0] == '\0')
1027 {
1028 if (strcmp(mode,"fork")==0)
1029 {
1030 int pc[2];
1031 int cp[2];
1032 int err1=pipe(pc);
1033 int err2=pipe(cp);
1034 if (err1 || err2)
1035 {
1036 Werror("pipe failed with %d\n",errno);
1037 return TRUE;
1038 }
1040 n->u=u;
1041 n->l=l;
1042 n->next=(void *)ssiToBeClosed;
1043 ssiToBeClosed=n;
1044
1045 pid_t pid = fork();
1046 if (pid == -1 && errno == EAGAIN) // RLIMIT_NPROC too low?
1047 {
1049 pid = fork();
1050 }
1051 if (pid == -1)
1052 {
1053 WerrorS("could not fork");
1054 }
1055 if (pid==0) /*fork: child*/
1056 {
1057 /* block SIGINT */
1058 sigset_t sigint;
1059 sigemptyset(&sigint);
1060 sigaddset(&sigint, SIGINT);
1061 sigprocmask(SIG_BLOCK, &sigint, NULL);
1062 si_set_signal(SIGTERM,sig_term_hdl);
1063 /* set #cpu to 1 for the child:*/
1064 feSetOptValue(FE_OPT_CPUS,1);
1065
1067 /* we know: l is the first entry in ssiToBeClosed-list */
1068 while(hh!=NULL)
1069 {
1070 SI_LINK_SET_CLOSE_P(hh->l);
1071 ssiInfo *dd=(ssiInfo*)hh->l->data;
1072 s_close(dd->f_read);
1073 fclose(dd->f_write);
1074 if (dd->r!=NULL) rKill(dd->r);
1075 omFreeSize((ADDRESS)dd,(sizeof *dd));
1076 hh->l->data=NULL;
1077 link_list nn=(link_list)hh->next;
1078 omFree(hh);
1079 hh=nn;
1080 }
1081 ssiToBeClosed->next=NULL;
1082#ifdef HAVE_SIMPLEIPC
1083 memset(sem_acquired, 0, SIPC_MAX_SEMAPHORES*sizeof(sem_acquired[0]));
1084#endif // HAVE_SIMPLEIPC
1085 si_close(pc[1]); si_close(cp[0]);
1086 d->f_write=fdopen(cp[1],"w");
1087 d->f_read=s_open(pc[0]);
1088 d->fd_read=pc[0];
1089 d->fd_write=cp[1];
1090 //d->r=currRing;
1091 //if (d->r!=NULL) d->r->ref++;
1092 l->data=d;
1093 omFreeBinAddr(l->mode);
1094 l->mode = omStrDup(mode);
1097 //myynest=0;
1099 if ((u!=NULL)&&(u->rtyp==IDHDL))
1100 {
1101 idhdl h=(idhdl)u->data;
1102 h->lev=0;
1103 }
1104 loop
1105 {
1106 if (!SI_LINK_OPEN_P(l)) m2_end(-1);
1107 if(d->f_read->is_eof) m2_end(-1);
1108 leftv h=ssiRead1(l); /*contains an exit.... */
1109 if (feErrors != NULL && *feErrors != '\0')
1110 {
1111 // handle errors:
1112 PrintS(feErrors); /* currently quite simple */
1113 *feErrors = '\0';
1114 }
1115 ssiWrite(l,h);
1116 h->CleanUp();
1118 }
1119 /* never reached*/
1120 }
1121 else if (pid>0) /*fork: parent*/
1122 {
1123 d->pid=pid;
1124 si_close(pc[0]); si_close(cp[1]);
1125 d->f_write=fdopen(pc[1],"w");
1126 d->f_read=s_open(cp[0]);
1127 d->fd_read=cp[0];
1128 d->fd_write=pc[1];
1130 d->send_quit_at_exit=1;
1131 //d->r=currRing;
1132 //if (d->r!=NULL) d->r->ref++;
1133 }
1134 else
1135 {
1136 Werror("fork failed (%d)",errno);
1137 l->data=NULL;
1138 omFree(d);
1139 return TRUE;
1140 }
1141 }
1142 // ---------------------------------------------------------------------
1143 else if (strcmp(mode,"tcp")==0)
1144 {
1145 int sockfd, newsockfd, portno, clilen;
1146 struct sockaddr_in serv_addr, cli_addr;
1147 sockfd = socket(AF_INET, SOCK_STREAM, 0);
1148 if(sockfd < 0)
1149 {
1150 WerrorS("ERROR opening socket");
1151 l->data=NULL;
1152 l->flags=0;
1153 omFree(d);
1154 return TRUE;
1155 }
1156 memset((char *) &serv_addr,0, sizeof(serv_addr));
1157 portno = 1025;
1158 serv_addr.sin_family = AF_INET;
1159 serv_addr.sin_addr.s_addr = INADDR_ANY;
1160 do
1161 {
1162 portno++;
1163 serv_addr.sin_port = htons(portno);
1164 if(portno > 50000)
1165 {
1166 WerrorS("ERROR on binding (no free port available?)");
1167 l->data=NULL;
1168 l->flags=0;
1169 omFree(d);
1170 return TRUE;
1171 }
1172 }
1173 while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
1174 Print("waiting on port %d\n", portno);mflush();
1175 listen(sockfd,1);
1176 newsockfd = si_accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
1177 if(newsockfd < 0)
1178 {
1179 WerrorS("ERROR on accept");
1180 l->data=NULL;
1181 l->flags=0;
1182 omFree(d);
1183 return TRUE;
1184 }
1185 PrintS("client accepted\n");
1186 d->fd_read = newsockfd;
1187 d->fd_write = newsockfd;
1188 d->f_read = s_open(newsockfd);
1189 d->f_write = fdopen(newsockfd, "w");
1191 si_close(sockfd);
1192 }
1193 // no ssi-Link on stdin or stdout
1194 else
1195 {
1196 Werror("invalid mode >>%s<< for ssi",mode);
1197 l->data=NULL;
1198 l->flags=0;
1199 omFree(d);
1200 return TRUE;
1201 }
1202 }
1203 // =========================================================================
1204 else /*now l->name!=NULL*/
1205 {
1206 // tcp mode
1207 if(strcmp(mode,"tcp")==0)
1208 {
1209 int sockfd, newsockfd, portno, clilen;
1210 struct sockaddr_in serv_addr, cli_addr;
1211 sockfd = socket(AF_INET, SOCK_STREAM, 0);
1212 if(sockfd < 0)
1213 {
1214 WerrorS("ERROR opening socket");
1215 l->data=NULL;
1216 l->flags=0;
1217 omFree(d);
1218 return TRUE;
1219 }
1220 memset((char *) &serv_addr,0, sizeof(serv_addr));
1221 portno = 1025;
1222 serv_addr.sin_family = AF_INET;
1223 serv_addr.sin_addr.s_addr = INADDR_ANY;
1224 do
1225 {
1226 portno++;
1227 serv_addr.sin_port = htons(portno);
1228 if(portno > 50000)
1229 {
1230 WerrorS("ERROR on binding (no free port available?)");
1231 l->data=NULL;
1232 l->flags=0;
1233 return TRUE;
1234 }
1235 }
1236 while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
1237 //Print("waiting on port %d\n", portno);mflush();
1238 listen(sockfd,1);
1239 char* cli_host = (char*)omAlloc(256);
1240 char* path = (char*)omAlloc(1024);
1241 int r = si_sscanf(l->name,"%255[^:]:%s",cli_host,path);
1242 if(r == 0)
1243 {
1244 WerrorS("ERROR: no host specified");
1245 l->data=NULL;
1246 l->flags=0;
1247 omFree(d);
1248 omFree(path);
1249 omFree(cli_host);
1250 return TRUE;
1251 }
1252 else if(r == 1)
1253 {
1254 WarnS("program not specified, using /usr/local/bin/Singular");
1255 Warn("in line >>%s<<",my_yylinebuf);
1256 strcpy(path,"/usr/local/bin/Singular");
1257 }
1258 char* ssh_command = (char*)omAlloc(256);
1259 char* ser_host = (char*)omAlloc(64);
1260 if(strcmp(cli_host,"localhost")==0)
1261 strcpy(ser_host,"localhost");
1262 else
1263 gethostname(ser_host,64);
1264 if (strcmp(cli_host,"localhost")==0) /*avoid "ssh localhost" as key may change*/
1265 snprintf(ssh_command,256,"%s -q --batch --link=ssi --MPhost=%s --MPport=%d &",path,ser_host,portno);
1266 else
1267 snprintf(ssh_command,256,"ssh %s %s -q --batch --link=ssi --MPhost=%s --MPport=%d &",cli_host,path,ser_host,portno);
1268 //Print("client on %s started:%s\n",cli_host,path);
1269 omFree(path);
1270 omFree(cli_host);
1271 if (TEST_OPT_PROT) { Print("running >>%s<<\n",ssh_command); }
1272 int re=system(ssh_command);
1273 if (re<0)
1274 {
1275 Werror("ERROR running `%s` (%d)",ssh_command,re);
1276 l->data=NULL;
1277 l->flags=0;
1278 omFree(d);
1279 return TRUE;
1280 }
1281 omFree(ssh_command);
1282 omFree(ser_host);
1283 clilen = sizeof(cli_addr);
1284 newsockfd = si_accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
1285 if(newsockfd < 0)
1286 {
1287 WerrorS("ERROR on accept");
1288 l->data=NULL;
1289 l->flags=0;
1290 omFree(d);
1291 return TRUE;
1292 }
1293 //PrintS("client accepted\n");
1294 d->fd_read = newsockfd;
1295 d->fd_write = newsockfd;
1296 d->f_read = s_open(newsockfd);
1297 d->f_write = fdopen(newsockfd, "w");
1298 si_close(sockfd);
1300 d->send_quit_at_exit=1;
1301 link_list newlink=(link_list)omAlloc(sizeof(link_struct));
1302 newlink->u=u;
1303 newlink->l=l;
1304 newlink->next=(void *)ssiToBeClosed;
1305 ssiToBeClosed=newlink;
1306 fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,si_opt_1,si_opt_2);
1307 }
1308 // ----------------------------------------------------------------------
1309 else if(strcmp(mode,"connect")==0)
1310 {
1311 char* host = (char*)omAlloc(256);
1312 int sockfd, portno;
1313 struct sockaddr_in serv_addr;
1314 struct hostent *server;
1315
1316 si_sscanf(l->name,"%255[^:]:%d",host,&portno);
1317 //Print("connect to host %s, port %d\n",host,portno);mflush();
1318 if (portno!=0)
1319 {
1320 sockfd = socket(AF_INET, SOCK_STREAM, 0);
1321 if (sockfd < 0)
1322 {
1323 WerrorS("ERROR opening socket");
1324 l->flags=0;
1325 return TRUE;
1326 }
1327 server = gethostbyname(host);
1328 if (server == NULL)
1329 {
1330 WerrorS("ERROR, no such host");
1331 l->flags=0;
1332 return TRUE;
1333 }
1334 memset((char *) &serv_addr, 0, sizeof(serv_addr));
1335 serv_addr.sin_family = AF_INET;
1336 memcpy((char *)&serv_addr.sin_addr.s_addr,
1337 (char *)server->h_addr,
1338 server->h_length);
1339 serv_addr.sin_port = htons(portno);
1340 if (si_connect(sockfd,(sockaddr*)&serv_addr,sizeof(serv_addr)) < 0)
1341 {
1342 Werror("ERROR connecting(errno=%d)",errno);
1343 l->flags=0;
1344 return TRUE;
1345 }
1346 //PrintS("connected\n");mflush();
1347 d->f_read=s_open(sockfd);
1348 d->fd_read=sockfd;
1349 d->f_write=fdopen(sockfd,"w");
1350 d->fd_write=sockfd;
1352 omFree(host);
1353 }
1354 else
1355 {
1356 l->data=NULL;
1357 l->flags=0;
1358 omFree(d);
1359 return TRUE;
1360 }
1361 }
1362 // ======================================================================
1363 else
1364 {
1365 // normal link to a file
1366 if (FE_OPT_NO_SHELL_FLAG) {WerrorS("no links allowed");return TRUE;}
1367 FILE *outfile;
1368 char *filename=l->name;
1369
1370 if(filename[0]=='>')
1371 {
1372 if (filename[1]=='>')
1373 {
1374 filename+=2;
1375 mode = "a";
1376 }
1377 else
1378 {
1379 filename++;
1380 mode="w";
1381 }
1382 }
1383 outfile=myfopen(filename,mode);
1384 if (outfile!=NULL)
1385 {
1386 if (strcmp(l->mode,"r")==0)
1387 {
1388 fclose(outfile);
1389 d->f_read=s_open_by_name(filename);
1390 }
1391 else
1392 {
1393 d->f_write = outfile;
1394 fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,si_opt_1,si_opt_2);
1395 }
1396 }
1397 else
1398 {
1399 omFree(d);
1400 l->data=NULL;
1401 l->flags=0;
1402 return TRUE;
1403 }
1404 }
1405 }
1406 }
1407
1408 return FALSE;
1409}
VAR BOOLEAN singular_in_batchmode
Definition cntrlc.cc:62
si_hdl_typ si_set_signal(int sig, si_hdl_typ signal_handler)
meta function for binding a signal to an handler
Definition cntrlc.cc:121
void sig_term_hdl(int)
Definition cntrlc.cc:77
#define Print
Definition emacs.cc:80
#define Warn
Definition emacs.cc:77
#define WarnS
Definition emacs.cc:78
EXTERN_VAR BOOLEAN FE_OPT_NO_SHELL_FLAG
Definition extra.cc:170
FILE * myfopen(const char *path, const char *mode)
Definition feFopen.cc:167
const char * feSetOptValue(feOptIndex opt, char *optarg)
Definition feOpt.cc:154
VAR char my_yylinebuf[80]
Definition febase.cc:44
char * fe_fgets_dummy(const char *, char *, int)
Definition feread.cc:455
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition feread.cc:32
void m2_end(int i)
Definition misc_ip.cc:1102
#define omFreeBinAddr(addr)
VAR unsigned si_opt_2
Definition options.c:6
VAR unsigned si_opt_1
Definition options.c:5
#define TEST_OPT_PROT
Definition options.h:105
#define mflush()
Definition reporter.h:58
int raise_rlimit_nproc()
Definition rlimit.c:18
s_buff s_open_by_name(const char *n)
Definition s_buff.cc:40
pid_t pid
Definition s_buff.h:25
char send_quit_at_exit
Definition s_buff.h:28
VAR int sem_acquired[SIPC_MAX_SEMAPHORES]
Definition semaphore.c:25
#define SIPC_MAX_SEMAPHORES
Definition simpleipc.h:10
#define IDHDL
Definition tok.h:31
@ MAX_TOK
Definition tok.h:220

◆ ssiPrepClose()

static BOOLEAN ssiPrepClose ( si_link l)
static

Definition at line 1412 of file ssiLink.cc.

1413{
1414 if (l!=NULL)
1415 {
1417 ssiInfo *d = (ssiInfo *)l->data;
1418 if (d!=NULL)
1419 {
1420 if (d->send_quit_at_exit)
1421 {
1422 fputs("99\n",d->f_write);
1423 fflush(d->f_write);
1424 }
1425 d->quit_sent=1;
1426 }
1427 }
1428 return FALSE;
1429}

◆ ssiRead1()

leftv ssiRead1 ( si_link l)

Definition at line 1520 of file ssiLink.cc.

1521{
1522 ssiInfo *d = (ssiInfo *)l->data;
1524 int t=0;
1525 t=s_readint(d->f_read);
1526 //Print("got type %d\n",t);
1527 switch(t)
1528 {
1529 case 1:res->rtyp=INT_CMD;
1530 res->data=(char *)(long)ssiReadInt(d);
1531 //Print("int: %d\n",(int)(long)res->data);
1532 break;
1533 case 2:res->rtyp=STRING_CMD;
1534 res->data=(char *)ssiReadString(d);
1535 //Print("str: %s\n",(char*)res->data);
1536 break;
1537 case 3:res->rtyp=NUMBER_CMD;
1538 if (d->r==NULL) goto no_ring;
1539 ssiCheckCurrRing(d->r);
1540 res->data=(char *)ssiReadNumber(d);
1541 //Print("number\n");
1542 break;
1543 case 4:res->rtyp=BIGINT_CMD;
1544 res->data=(char *)ssiReadBigInt(d);
1545 //Print("bigint\n");
1546 break;
1547 case 15:
1548 case 5:{
1549 //Print("ring %d\n",t);
1550 d->r=ssiReadRing(d);
1551 if (errorreported) return NULL;
1552 res->data=(char*)d->r;
1553 if (d->r!=NULL) rIncRefCnt(d->r);
1554 res->rtyp=RING_CMD;
1555 if (t==15) // setring
1556 {
1557 if(ssiSetCurrRing(d->r)) { d->r=currRing; }
1559 return ssiRead1(l);
1560 }
1561 }
1562 break;
1563 case 6:res->rtyp=POLY_CMD;
1564 //Print("poly\n");
1565 if (d->r==NULL) goto no_ring;
1566 ssiCheckCurrRing(d->r);
1567 res->data=(char*)ssiReadPoly(d);
1568 break;
1569 case 7:res->rtyp=IDEAL_CMD;
1570 //Print("ideal\n");
1571 if (d->r==NULL) goto no_ring;
1572 ssiCheckCurrRing(d->r);
1573 res->data=(char*)ssiReadIdeal(d);
1574 break;
1575 case 8:res->rtyp=MATRIX_CMD;
1576 //Print("matrix\n");
1577 if (d->r==NULL) goto no_ring;
1578 ssiCheckCurrRing(d->r);
1579 res->data=(char*)ssiReadMatrix(d);
1580 break;
1581 case 9:res->rtyp=VECTOR_CMD;
1582 //Print("vector\n");
1583 if (d->r==NULL) goto no_ring;
1584 ssiCheckCurrRing(d->r);
1585 res->data=(char*)ssiReadPoly(d);
1586 break;
1587 case 10:
1588 case 22:if (t==22) res->rtyp=SMATRIX_CMD;
1589 else res->rtyp=MODUL_CMD;
1590 //Print("module/smatrix %d\n",t);
1591 if (d->r==NULL) goto no_ring;
1592 ssiCheckCurrRing(d->r);
1593 {
1594 int rk=s_readint(d->f_read);
1595 ideal M=ssiReadIdeal(d);
1596 M->rank=rk;
1597 res->data=(char*)M;
1598 }
1599 break;
1600 case 11:
1601 {
1602 //Print("cmd\n",t);
1603 res->rtyp=COMMAND;
1604 res->data=ssiReadCommand(l);
1605 int nok=res->Eval();
1606 if (nok) WerrorS("error in eval");
1607 break;
1608 }
1609 case 12: /*DEF_CMD*/
1610 {
1611 //Print("def\n",t);
1612 res->rtyp=0;
1613 res->name=(char *)ssiReadString(d);
1614 int nok=res->Eval();
1615 if (nok) WerrorS("error in name lookup");
1616 break;
1617 }
1618 case 13: res->rtyp=PROC_CMD;
1619 res->data=ssiReadProc(d);
1620 break;
1621 case 14: res->rtyp=LIST_CMD;
1622 res->data=ssiReadList(l);
1623 break;
1624 case 16: res->rtyp=NONE; res->data=NULL;
1625 break;
1626 case 17: res->rtyp=INTVEC_CMD;
1627 res->data=ssiReadIntvec(d);
1628 break;
1629 case 18: res->rtyp=INTMAT_CMD;
1630 res->data=ssiReadIntmat(d);
1631 break;
1632 case 19: res->rtyp=BIGINTMAT_CMD;
1633 res->data=ssiReadBigintmat(d);
1634 break;
1635 case 20: ssiReadBlackbox(res,l);
1636 break;
1637 case 21: ssiReadAttrib(res,l);
1638 break;
1639 case 23: ssiReadRingProperties(l);
1640 return ssiRead1(l);
1641 break;
1642 case 24: res->rtyp=BIGINTVEC_CMD;
1643 res->data=ssiReadBigintvec(d);
1644 break;
1645 // ------------
1646 case 98: // version
1647 {
1648 int n98_v,n98_m;
1649 BITSET n98_o1,n98_o2;
1650 n98_v=s_readint(d->f_read);
1651 n98_m=s_readint(d->f_read);
1652 n98_o1=s_readint(d->f_read);
1653 n98_o2=s_readint(d->f_read);
1654 if ((n98_v!=SSI_VERSION) ||(n98_m!=MAX_TOK))
1655 {
1656 Print("incompatible versions of ssi: %d/%d vs %d/%d\n",
1657 SSI_VERSION,MAX_TOK,n98_v,n98_m);
1658 }
1659 #ifndef SING_NDEBUG
1660 if (TEST_OPT_DEBUG)
1661 Print("// opening ssi-%d, MAX_TOK=%d\n",n98_v,n98_m);
1662 #endif
1663 si_opt_1=n98_o1;
1664 si_opt_2=n98_o2;
1666 return ssiRead1(l);
1667 }
1668 case 99: omFreeBin(res,sleftv_bin); ssiClose(l); m2_end(-1);
1669 break; /*to make compiler happy*/
1670 case 0: if (s_iseof(d->f_read))
1671 {
1672 ssiClose(l);
1673 }
1674 res->rtyp=DEF_CMD;
1675 break;
1676 default: Werror("not implemented (t:%d)",t);
1678 res=NULL;
1679 break;
1680 }
1681 // if currRing is required for the result, but lost
1682 // define "ssiRing%d" as currRing:
1683 if ((d->r!=NULL)
1684 && (currRing!=d->r)
1685 && (res->RingDependend()))
1686 {
1687 if(ssiSetCurrRing(d->r)) { d->r=currRing; }
1688 }
1689 return res;
1690no_ring: WerrorS("no ring");
1692 return NULL;
1693}
#define BITSET
Definition auxiliary.h:85
CanonicalForm res
Definition facAbsFact.cc:60
VAR short errorreported
Definition feFopen.cc:23
@ IDEAL_CMD
Definition grammar.cc:285
@ MATRIX_CMD
Definition grammar.cc:287
@ BIGINTMAT_CMD
Definition grammar.cc:278
@ INTMAT_CMD
Definition grammar.cc:280
@ MODUL_CMD
Definition grammar.cc:288
@ SMATRIX_CMD
Definition grammar.cc:292
@ VECTOR_CMD
Definition grammar.cc:293
@ BIGINTVEC_CMD
Definition grammar.cc:279
@ NUMBER_CMD
Definition grammar.cc:289
@ POLY_CMD
Definition grammar.cc:290
#define TEST_OPT_DEBUG
Definition options.h:110
int s_readint(s_buff F)
Definition s_buff.cc:113
#define M
Definition sirandom.c:25
@ BIGINT_CMD
Definition tok.h:38
@ LIST_CMD
Definition tok.h:118
@ INTVEC_CMD
Definition tok.h:101
@ STRING_CMD
Definition tok.h:187
@ INT_CMD
Definition tok.h:96
#define NONE
Definition tok.h:223

◆ ssiReadAttrib()

static void ssiReadAttrib ( leftv res,
si_link l )
static

Definition at line 938 of file ssiLink.cc.

939{
940 ssiInfo *d=(ssiInfo*)l->data;
941 BITSET fl=(BITSET)s_readint(d->f_read);
942 int nr_of_attr=s_readint(d->f_read);
943 if (nr_of_attr>0)
944 {
945 for(int i=1;i<nr_of_attr;i++)
946 {
947 }
948 }
949 leftv tmp=ssiRead1(l);
950 memcpy(res,tmp,sizeof(sleftv));
951 memset(tmp,0,sizeof(sleftv));
953 if (nr_of_attr>0)
954 {
955 }
956 res->flag=fl;
957}

◆ ssiReadBigInt()

static number ssiReadBigInt ( const ssiInfo * d)
static

Definition at line 532 of file ssiLink.cc.

533{
535 if ((SR_HDL(n) & SR_INT)==0)
536 {
537 if (n->s!=3) Werror("invalid sub type in bigint:%d",n->s);
538 }
539 return n;
540}
#define SR_INT
Definition longrat.h:67
VAR coeffs coeffs_BIGINT
Definition polys.cc:14
#define SR_HDL(A)
Definition tgb.cc:35

◆ ssiReadBigintmat()

static bigintmat * ssiReadBigintmat ( const ssiInfo * d)
static

Definition at line 885 of file ssiLink.cc.

886{
887 int r,c;
888 r=s_readint(d->f_read);
889 c=s_readint(d->f_read);
891 for(int i=0;i<r*c;i++)
892 {
893 (*v)[i]=ssiReadBigInt(d);
894 }
895 return v;
896}
Matrices of numbers.
Definition bigintmat.h:51
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39

◆ ssiReadBigintvec()

static bigintmat * ssiReadBigintvec ( const ssiInfo * d)
static

Definition at line 897 of file ssiLink.cc.

898{
899 int c;
900 c=s_readint(d->f_read);
902 for(int i=0;i<c;i++)
903 {
904 (*v)[i]=ssiReadBigInt(d);
905 }
906 return v;
907}

◆ ssiReadBlackbox()

static void ssiReadBlackbox ( leftv res,
si_link l )
static

Definition at line 909 of file ssiLink.cc.

910{
911 ssiInfo *d=(ssiInfo*)l->data;
912 leftv lv=ssiRead1(l);
913 char *name=(char*)lv->data;
915 int tok;
916 blackboxIsCmd(name,tok);
917 if (tok>MAX_TOK)
918 {
919 ring save_ring=currRing;
920 idhdl save_hdl=currRingHdl;
921 blackbox *b=getBlackboxStuff(tok);
922 res->rtyp=tok;
923 b->blackbox_deserialize(&b,&(res->data),l);
924 if (save_ring!=currRing)
925 {
926 rChangeCurrRing(save_ring);
927 if (save_hdl!=NULL) rSetHdl(save_hdl);
928 else currRingHdl=NULL;
929 }
930 }
931 else
932 {
933 Werror("blackbox %s not found",name);
934 }
935 omFree(name);
936}
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition blackbox.cc:17
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:219
CanonicalForm b
Definition cfModGcd.cc:4111
void rChangeCurrRing(ring r)
Definition polys.cc:16

◆ ssiReadCommand()

static command ssiReadCommand ( si_link l)
static

Definition at line 788 of file ssiLink.cc.

789{
790 ssiInfo *d=(ssiInfo*)l->data;
791 // syntax: <num ops> <operation> <op1> <op2> ....
792 command D=(command)omAlloc0(sizeof(*D));
793 int argc,op;
794 argc=s_readint(d->f_read);
795 op=s_readint(d->f_read);
796 D->argc=argc; D->op=op;
797 leftv v;
798 if (argc >0)
799 {
800 v=ssiRead1(l);
801 memcpy(&(D->arg1),v,sizeof(*v));
803 }
804 if (argc <4)
805 {
806 if (D->argc >1)
807 {
808 v=ssiRead1(l);
809 memcpy(&(D->arg2),v,sizeof(*v));
811 }
812 if (D->argc >2)
813 {
814 v=ssiRead1(l);
815 memcpy(&(D->arg3),v,sizeof(*v));
817 }
818 }
819 else
820 {
821 leftv prev=&(D->arg1);
822 argc--;
823 while(argc >0)
824 {
825 v=ssiRead1(l);
826 prev->next=v;
827 prev=v;
828 argc--;
829 }
830 }
831 return D;
832}
leftv next
Definition subexpr.h:86

◆ ssiReadIdeal()

ideal ssiReadIdeal ( ssiInfo * d)

Definition at line 767 of file ssiLink.cc.

768{
769 return ssiReadIdeal_R(d,d->r);
770}
ring r
Definition s_buff.h:24

◆ ssiReadIdeal_R()

static ideal ssiReadIdeal_R ( const ssiInfo * d,
const ring r )
static

Definition at line 753 of file ssiLink.cc.

754{
755// < # of terms> < term1> < .....
756 int n,i;
757 ideal I;
758 n=s_readint(d->f_read);
759 I=idInit(n,1); // will be fixed later for module/smatrix
760 for(i=0;i<IDELEMS(I);i++) // read n terms
761 {
762 I->m [i]=ssiReadPoly_R(d,r);
763 }
764 return I;
765}
ideal idInit(int idsize, int rank)
initialise an ideal / module
#define IDELEMS(i)

◆ ssiReadInt()

int ssiReadInt ( const ssiInfo * d)

Definition at line 503 of file ssiLink.cc.

504{
505 return s_readint(d->f_read);
506}

◆ ssiReadIntmat()

static intvec * ssiReadIntmat ( const ssiInfo * d)
static

Definition at line 873 of file ssiLink.cc.

874{
875 int r,c;
876 r=s_readint(d->f_read);
877 c=s_readint(d->f_read);
878 intvec *v=new intvec(r,c,0);
879 for(int i=0;i<r*c;i++)
880 {
881 (*v)[i]=s_readint(d->f_read);
882 }
883 return v;
884}

◆ ssiReadIntvec()

static intvec * ssiReadIntvec ( const ssiInfo * d)
static

Definition at line 862 of file ssiLink.cc.

863{
864 int nr;
865 nr=s_readint(d->f_read);
866 intvec *v=new intvec(nr);
867 for(int i=0;i<nr;i++)
868 {
869 (*v)[i]=s_readint(d->f_read);
870 }
871 return v;
872}

◆ ssiReadList()

static lists ssiReadList ( si_link l)
static

Definition at line 844 of file ssiLink.cc.

845{
846 ssiInfo *d=(ssiInfo*)l->data;
847 int nr;
848 nr=s_readint(d->f_read);
850 L->Init(nr);
851
852 int i;
853 leftv v;
854 for(i=0;i<=L->nr;i++)
855 {
856 v=ssiRead1(l);
857 memcpy(&(L->m[i]),v,sizeof(*v));
859 }
860 return L;
861}
INLINE_THIS void Init(int l=0)
VAR omBin slists_bin
Definition lists.cc:23
slists * lists

◆ ssiReadMatrix()

static matrix ssiReadMatrix ( ssiInfo * d)
static

Definition at line 772 of file ssiLink.cc.

773{
774 int n,m;
775 m=s_readint(d->f_read);
776 n=s_readint(d->f_read);
777 matrix M=mpNew(m,n);
778 poly p;
779 for(int i=1;i<=MATROWS(M);i++)
780 for(int j=1;j<=MATCOLS(M);j++)
781 {
782 p=ssiReadPoly(d);
783 MATELEM(M,i,j)=p;
784 }
785 return M;
786}
int m
Definition cfEzgcd.cc:128
matrix mpNew(int r, int c)
create a r x c zero-matrix
Definition matpol.cc:37
#define MATELEM(mat, i, j)
1-based access to matrix
Definition matpol.h:29
ip_smatrix * matrix
Definition matpol.h:43
#define MATROWS(i)
Definition matpol.h:26
#define MATCOLS(i)
Definition matpol.h:27

◆ ssiReadNumber()

static number ssiReadNumber ( ssiInfo * d)
static

Definition at line 542 of file ssiLink.cc.

543{
544 return ssiReadNumber_CF(d,d->r->cf);
545}

◆ ssiReadNumber_CF()

static number ssiReadNumber_CF ( const ssiInfo * d,
const coeffs cf )
static

Definition at line 508 of file ssiLink.cc.

509{
510 if (cf->cfReadFd!=ndReadFd)
511 {
512 return n_ReadFd(d,cf);
513 }
514 else if (getCoeffType(cf) == n_transExt)
515 {
516 // poly poly
517 fraction f=(fraction)n_Init(1,cf);
518 p_Delete(&NUM(f),cf->extRing);
519 NUM(f)=ssiReadPoly_R(d,cf->extRing);
520 DEN(f)=ssiReadPoly_R(d,cf->extRing);
521 return (number)f;
522 }
523 else if (getCoeffType(cf) == n_algExt)
524 {
525 // poly
526 return (number)ssiReadPoly_R(d,cf->extRing);
527 }
528 else WerrorS("coeffs not implemented in ssiReadNumber");
529 return NULL;
530}
CanonicalForm cf
Definition cfModGcd.cc:4091
FILE * f
Definition checklibs.c:9
static FORCE_INLINE number n_ReadFd(const ssiInfo *f, const coeffs r)
io via ssi:
Definition coeffs.h:971
@ n_algExt
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic
Definition coeffs.h:35
@ n_transExt
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
Definition coeffs.h:38
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition coeffs.h:429
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:539
number ndReadFd(const ssiInfo *, const coeffs r)
Definition numbers.cc:150
static void p_Delete(poly *p, const ring r)
Definition p_polys.h:903
#define NUM
Definition readcf.cc:180

◆ ssiReadPoly()

static poly ssiReadPoly ( ssiInfo * d)
static

Definition at line 748 of file ssiLink.cc.

749{
750 return ssiReadPoly_R(d,d->r);
751}

◆ ssiReadPoly_R()

static poly ssiReadPoly_R ( const ssiInfo * D,
const ring r )
static

Definition at line 717 of file ssiLink.cc.

718{
719// < # of terms> < term1> < .....
720 int n,i,l;
721 n=ssiReadInt(d); // # of terms
722 //Print("poly: terms:%d\n",n);
723 poly p;
724 poly ret=NULL;
725 poly prev=NULL;
726 for(l=0;l<n;l++) // read n terms
727 {
728// coef,comp.exp1,..exp N
729 p=p_Init(r,r->PolyBin);
730 pSetCoeff0(p,ssiReadNumber_CF(d,r->cf));
731 int D;
732 D=s_readint(d->f_read);
733 p_SetComp(p,D,r);
734 for(i=1;i<=rVar(r);i++)
735 {
736 D=s_readint(d->f_read);
737 p_SetExp(p,i,D,r);
738 }
739 p_Setm(p,r);
740 p_Test(p,r);
741 if (ret==NULL) ret=p;
742 else pNext(prev)=p;
743 prev=p;
744 }
745 return ret;
746}
#define pNext(p)
Definition monomials.h:36
#define pSetCoeff0(p, n)
Definition monomials.h:59
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:490
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition p_polys.h:249
static void p_Setm(poly p, const ring r)
Definition p_polys.h:235
static poly p_Init(const ring r, omBin bin)
Definition p_polys.h:1336
#define p_Test(p, r)
Definition p_polys.h:161
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition ring.h:598

◆ ssiReadProc()

static procinfov ssiReadProc ( const ssiInfo * d)
static

Definition at line 834 of file ssiLink.cc.

835{
836 char *s=ssiReadString(d);
838 p->language=LANG_SINGULAR;
839 p->libname=omStrDup("");
840 p->procname=omStrDup("");
841 p->data.s.body=s;
842 return p;
843}
procinfo * procinfov
Definition structs.h:56
VAR omBin procinfo_bin
Definition subexpr.cc:42

◆ ssiReadRing()

static ring ssiReadRing ( ssiInfo * d)
static

Definition at line 547 of file ssiLink.cc.

548{
549/* syntax is <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... <Q-ideal> */
550 int ch;
551 int new_ref=-1;
552 ch=s_readint(d->f_read);
553 if (ch==-6)
554 {
555 new_ref=s_readint(d->f_read);
556 ch=s_readint(d->f_read);
557 }
558 if (ch==-5)
559 {
560 int index=s_readint(d->f_read);
561 ring r=d->rings[index];
562 rIncRefCnt(r);
563 return r;
564 }
565 if (ch==-4)
566 return NULL;
567 int N=s_readint(d->f_read);
568 char **names;
569 coeffs cf=NULL;
570 if (ch==-3)
571 {
572 char *cf_name=ssiReadString(d);
573 cf=nFindCoeffByName(cf_name);
574 if (cf==NULL)
575 {
576 Werror("cannot find cf:%s",cf_name);
577 omFreeBinAddr(cf_name);
578 return NULL;
579 }
580 }
581 if (N!=0)
582 {
583 names=(char**)omAlloc(N*sizeof(char*));
584 for(int i=0;i<N;i++)
585 {
586 names[i]=ssiReadString(d);
587 }
588 }
589 // read the orderings:
590 int num_ord; // number of orderings
591 num_ord=s_readint(d->f_read);
592 rRingOrder_t *ord=(rRingOrder_t *)omAlloc0((num_ord+1)*sizeof(rRingOrder_t));
593 int *block0=(int *)omAlloc0((num_ord+1)*sizeof(int));
594 int *block1=(int *)omAlloc0((num_ord+1)*sizeof(int));
595 int **wvhdl=(int**)omAlloc0((num_ord+1)*sizeof(int*));
596 for(int i=0;i<num_ord;i++)
597 {
598 ord[i]=(rRingOrder_t)s_readint(d->f_read);
599 block0[i]=s_readint(d->f_read);
600 block1[i]=s_readint(d->f_read);
601 switch(ord[i])
602 {
603 case ringorder_a:
604 case ringorder_wp:
605 case ringorder_Wp:
606 case ringorder_ws:
607 case ringorder_Ws:
608 case ringorder_aa:
609 {
610 int s=block1[i]-block0[i]+1; // #vars
611 wvhdl[i]=(int*)omAlloc(s*sizeof(int));
612 for(int ii=0;ii<s;ii++)
613 wvhdl[i][ii]=s_readint(d->f_read);
614 }
615 break;
616 case ringorder_M:
617 {
618 int s=block1[i]-block0[i]+1; // #vars
619 wvhdl[i]=(int*)omAlloc(s*s*sizeof(int));
620 for(int ii=0;ii<s*s;ii++)
621 {
622 wvhdl[i][ii]=s_readint(d->f_read);
623 }
624 }
625 break;
626 case ringorder_a64:
627 case ringorder_L:
628 case ringorder_IS:
629 Werror("ring order not implemented for ssi:%d",ord[i]);
630 break;
631
632 default: break;
633 }
634 }
635 if (N==0)
636 {
637 omFree(ord);
638 omFree(block0);
639 omFree(block1);
640 omFree(wvhdl);
641 return NULL;
642 }
643 else
644 {
645 ring r=NULL;
646 if (ch>=0) /* Q, Z/p */
647 r=rDefault(ch,N,names,num_ord,ord,block0,block1,wvhdl);
648 else if (ch==-1) /* trans ext. */
649 {
651 T.r=ssiReadRing(d);
652 if (T.r==NULL) return NULL;
654 r=rDefault(cf,N,names,num_ord,ord,block0,block1,wvhdl);
655 }
656 else if (ch==-2) /* alg ext. */
657 {
659 T.r=ssiReadRing(d); /* includes qideal */
660 if (T.r==NULL) return NULL;
662 r=rDefault(cf,N,names,num_ord,ord,block0,block1,wvhdl);
663 }
664 else if (ch==-3)
665 {
666 r=rDefault(cf,N,names,num_ord,ord,block0,block1,wvhdl);
667 }
668 else
669 {
670 Werror("ssi: read unknown coeffs type (%d)",ch);
671 for(int i=0;i<N;i++)
672 {
673 omFree(names[i]);
674 }
675 omFreeSize(names,N*sizeof(char*));
676 return NULL;
677 }
678 ideal q=ssiReadIdeal_R(d,r);
679 if (IDELEMS(q)==0) omFreeBin(q,sip_sideal_bin);
680 else r->qideal=q;
681 for(int i=0;i<N;i++)
682 {
683 omFree(names[i]);
684 }
685 omFreeSize(names,N*sizeof(char*));
686 rIncRefCnt(r);
687 // check if such ring already exist as ssiRing*
688 char name[20];
689 int nr=0;
690 idhdl h=NULL;
691 loop
692 {
693 snprintf(name,20,"ssiRing%d",nr); nr++;
694 h=IDROOT->get(name, 0);
695 if (h==NULL)
696 {
697 break;
698 }
699 else if ((IDTYP(h)==RING_CMD)
700 && (r!=IDRING(h))
701 && (rEqual(r,IDRING(h),1)))
702 {
703 rDelete(r);
704 r=rIncRefCnt(IDRING(h));
705 break;
706 }
707 }
708 if (new_ref!=-1)
709 {
710 d->rings[new_ref]=r;
711 rIncRefCnt(r);
712 }
713 return r;
714 }
715}
const CanonicalForm CFMap CFMap & N
Definition cfEzgcd.cc:56
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition numbers.cc:406
STATIC_VAR jList * T
Definition janet.cc:30
The main handler for Singular numbers which are suitable for Singular polynomials.
coeffs nFindCoeffByName(char *cf_name)
find an existing coeff by its "CoeffName"
Definition numbers.cc:633
static int index(p_Length length, p_Ord ord)
void rDelete(ring r)
unconditionally deletes fields in r
Definition ring.cc:454
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
rRingOrder_t
order stuff
Definition ring.h:69
@ ringorder_a
Definition ring.h:71
@ ringorder_a64
for int64 weights
Definition ring.h:72
@ ringorder_L
Definition ring.h:91
@ ringorder_aa
for idElimination, like a, except pFDeg, pWeigths ignore it
Definition ring.h:93
@ ringorder_Wp
Definition ring.h:83
@ ringorder_ws
Definition ring.h:88
@ ringorder_Ws
Definition ring.h:89
@ ringorder_IS
Induced (Schreyer) ordering.
Definition ring.h:95
@ ringorder_wp
Definition ring.h:82
@ ringorder_M
Definition ring.h:75
ring rings[SI_RING_CACHE]
Definition s_buff.h:31
VAR omBin sip_sideal_bin
struct for passing initialization parameters to naInitChar
Definition transext.h:88

◆ ssiReadRingProperties()

static void ssiReadRingProperties ( si_link l)
static

Definition at line 958 of file ssiLink.cc.

959{
960 ssiInfo *d=(ssiInfo*)l->data;
961 int what=s_readint(d->f_read);
962 switch(what)
963 {
964 case 0: // bitmask
965 {
966 int lb=s_readint(d->f_read);
967 unsigned long bm=~0L;
968 bm=bm<<lb;
969 bm=~bm;
970 rUnComplete(d->r);
971 d->r->bitmask=bm;
972 rComplete(d->r);
973 break;
974 }
975 case 1: // LPRing
976 {
977 int lb=s_readint(d->f_read);
978 int isLPring=s_readint(d->f_read);
979 unsigned long bm=~0L;
980 bm=bm<<lb;
981 bm=~bm;
982 rUnComplete(d->r);
983 d->r->bitmask=bm;
984 d->r->isLPring=isLPring;
985 rComplete(d->r);
986 break;
987 }
988 case 2: // Plural rings
989 {
992 nc_CallPlural(C,D,NULL,NULL,d->r,true,true,false,d->r,false);
993 break;
994 }
995 }
996}
BOOLEAN nc_CallPlural(matrix cc, matrix dd, poly cn, poly dn, ring r, bool bSetupQuotient, bool bCopyInput, bool bBeQuiet, ring curr, bool dummy_ring=false)
returns TRUE if there were errors analyze inputs, check them for consistency detects nc_type,...
BOOLEAN rComplete(ring r, int force)
this needs to be called whenever a new ring is created: new fields in ring are created (like VarOffse...
Definition ring.cc:3526
void rUnComplete(ring r)
Definition ring.cc:4057

◆ ssiReadString()

static char * ssiReadString ( const ssiInfo * d)
static

Definition at line 490 of file ssiLink.cc.

491{
492 char *buf;
493 int l;
494 l=s_readint(d->f_read);
495 buf=(char*)omAlloc0(l+1);
496 int throwaway =s_getc(d->f_read); /* skip ' '*/
497 throwaway=s_readbytes(buf,l,d->f_read);
498 //if (throwaway!=l) printf("want %d, got %d bytes\n",l,throwaway);
499 buf[l]='\0';
500 return buf;
501}
int s_readbytes(char *buff, int len, s_buff F)
Definition s_buff.cc:169

◆ ssiReservePort()

int ssiReservePort ( int clients)

Definition at line 2206 of file ssiLink.cc.

2207{
2208 if (ssiReserved_P!=0)
2209 {
2210 WerrorS("ERROR already a reserved port requested");
2211 return 0;
2212 }
2213 int portno;
2214 ssiReserved_sockfd = socket(AF_INET, SOCK_STREAM, 0);
2215 if(ssiReserved_sockfd < 0)
2216 {
2217 WerrorS("ERROR opening socket");
2218 return 0;
2219 }
2220 memset((char *) &ssiResverd_serv_addr,0, sizeof(ssiResverd_serv_addr));
2221 portno = 1025;
2222 ssiResverd_serv_addr.sin_family = AF_INET;
2223 ssiResverd_serv_addr.sin_addr.s_addr = INADDR_ANY;
2224 do
2225 {
2226 portno++;
2227 ssiResverd_serv_addr.sin_port = htons(portno);
2228 if(portno > 50000)
2229 {
2230 WerrorS("ERROR on binding (no free port available?)");
2231 return 0;
2232 }
2233 }
2234 while(bind(ssiReserved_sockfd, (struct sockaddr *) &ssiResverd_serv_addr, sizeof(ssiResverd_serv_addr)) < 0);
2235 ssiReserved_P=portno;
2236 listen(ssiReserved_sockfd,clients);
2237 ssiReserved_Clients=clients;
2238 return portno;
2239}

◆ ssiSetCurrRing()

static BOOLEAN ssiSetCurrRing ( const ring r)
static

Definition at line 78 of file ssiLink.cc.

79{
80 // if (currRing!=NULL)
81 // Print("need to change the ring, currRing:%s, switch to: ssiRing%d\n",IDID(currRingHdl),nr);
82 // else
83 // Print("no ring, switch to ssiRing%d\n",nr);
84 if (r==currRing)
85 {
86 rIncRefCnt(r);
88 return TRUE;
89 }
90 else if ((currRing==NULL) || (!rEqual(r,currRing,1)))
91 {
92 char name[20];
93 int nr=0;
94 idhdl h=NULL;
95 loop
96 {
97 snprintf(name,20,"ssiRing%d",nr); nr++;
98 h=IDROOT->get(name, 0);
99 if (h==NULL)
100 {
102 IDRING(h)=rIncRefCnt(r);
103 r->ref=2;/*ref==2: d->r and h */
104 break;
105 }
106 else if ((IDTYP(h)==RING_CMD)
107 && (rEqual(r,IDRING(h),1)))
108 {
110 break;
111 }
112 }
113 rSetHdl(h);
114 return FALSE;
115 }
116 else
117 {
118 rKill(r);
120 return TRUE;
121 }
122}
idhdl rFindHdl(ring r, idhdl n)
Definition ipshell.cc:1695

◆ ssiSetRing()

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

Definition at line 1695 of file ssiLink.cc.

1696{
1697 if(SI_LINK_W_OPEN_P(l)==0)
1699 ssiInfo *d = (ssiInfo *)l->data;
1700 if (d->r!=r)
1701 {
1702 if (send)
1703 {
1704 fputs("15 ",d->f_write);
1705 ssiWriteRing(d,r);
1706 }
1707 d->r=r;
1708 }
1709 if (currRing!=r) rChangeCurrRing(r);
1710 return FALSE;
1711}

◆ ssiWrite()

BOOLEAN ssiWrite ( si_link l,
leftv data )

Definition at line 1714 of file ssiLink.cc.

1715{
1716 if(SI_LINK_W_OPEN_P(l)==0)
1718 ssiInfo *d = (ssiInfo *)l->data;
1719 d->level++;
1720 //FILE *fich=d->f;
1721 while (data!=NULL)
1722 {
1723 int tt=data->Typ();
1724 void *dd=data->Data();
1725 attr *aa=data->Attribute();
1726 if ((aa!=NULL) && ((*aa)!=NULL)) // n user attributes
1727 {
1728 attr a=*aa;
1729 int n=0;
1730 while(a!=NULL) { n++; a=a->next;}
1731 fprintf(d->f_write,"21 %d %d ",data->flag,n);
1732 }
1733 else if (data->flag!=0) // only "flag" attributes
1734 {
1735 fprintf(d->f_write,"21 %d 0 ",data->flag);
1736 }
1737 if ((dd==NULL) && (data->name!=NULL) && (tt==0)) tt=DEF_CMD;
1738 // return pure undefined names as def
1739
1740 switch(tt /*data->Typ()*/)
1741 {
1742 case 0: /*error*/
1743 case NONE/* nothing*/:fputs("16 ",d->f_write);
1744 break;
1745 case STRING_CMD: fputs("2 ",d->f_write);
1746 ssiWriteString(d,(char *)dd);
1747 break;
1748 case INT_CMD: fputs("1 ",d->f_write);
1749 ssiWriteInt(d,(int)(long)dd);
1750 break;
1751 case BIGINT_CMD:fputs("4 ",d->f_write);
1752 ssiWriteBigInt(d,(number)dd);
1753 break;
1754 case NUMBER_CMD:
1755 if (d->r!=currRing)
1756 {
1757 fputs("15 ",d->f_write);
1759 if (d->level<=1) fputc('\n',d->f_write);
1760 }
1761 fputs("3 ",d->f_write);
1762 ssiWriteNumber(d,(number)dd);
1763 break;
1764 case RING_CMD:fputs("5 ",d->f_write);
1765 ssiWriteRing(d,(ring)dd);
1766 break;
1767 case BUCKET_CMD:
1768 {
1770 if (d->r!=sBucketGetRing(b))
1771 {
1772 fputs("15 ",d->f_write);
1774 if (d->level<=1) fputc('\n',d->f_write);
1775 }
1776 fputs("6 ",d->f_write);
1777 ssiWritePoly(d,tt,sBucketPeek(b));
1778 break;
1779 }
1780 case POLY_CMD:
1781 case VECTOR_CMD:
1782 if (d->r!=currRing)
1783 {
1784 fputs("15 ",d->f_write);
1786 if (d->level<=1) fputc('\n',d->f_write);
1787 }
1788 if(tt==POLY_CMD) fputs("6 ",d->f_write);
1789 else fputs("9 ",d->f_write);
1790 ssiWritePoly(d,tt,(poly)dd);
1791 break;
1792 case IDEAL_CMD:
1793 case MODUL_CMD:
1794 case MATRIX_CMD:
1795 case SMATRIX_CMD:
1796 if (d->r!=currRing)
1797 {
1798 fputs("15 ",d->f_write);
1800 if (d->level<=1) fputc('\n',d->f_write);
1801 }
1802 if(tt==IDEAL_CMD) fputs("7 ",d->f_write);
1803 else if(tt==MATRIX_CMD) fputs("8 ",d->f_write);
1804 else /* tt==MODUL_CMD, SMATRIX_CMD*/
1805 {
1806 ideal M=(ideal)dd;
1807 if (tt==MODUL_CMD)
1808 fprintf(d->f_write,"10 %d ",(int)M->rank);
1809 else /*(tt==SMATRIX_CMD)*/
1810 fprintf(d->f_write,"22 %d ",(int)M->rank);
1811 }
1812 ssiWriteIdeal(d,tt,(ideal)dd);
1813 break;
1814 case COMMAND:
1815 fputs("11 ",d->f_write);
1817 break;
1818 case DEF_CMD: /* not evaluated stuff in quotes */
1819 fputs("12 ",d->f_write);
1820 ssiWriteString(d,data->Name());
1821 break;
1822 case PROC_CMD:
1823 fputs("13 ",d->f_write);
1824 ssiWriteProc(d,(procinfov)dd);
1825 break;
1826 case LIST_CMD:
1827 fputs("14 ",d->f_write);
1828 ssiWriteList(l,(lists)dd);
1829 break;
1830 case INTVEC_CMD:
1831 fputs("17 ",d->f_write);
1832 ssiWriteIntvec(d,(intvec *)dd);
1833 break;
1834 case INTMAT_CMD:
1835 fputs("18 ",d->f_write);
1836 ssiWriteIntmat(d,(intvec *)dd);
1837 break;
1838 case BIGINTMAT_CMD:
1839 fputs("19 ",d->f_write);
1841 break;
1842 case BIGINTVEC_CMD:
1843 fputs("24 ",d->f_write);
1845 break;
1846 default:
1847 if (tt>MAX_TOK)
1848 {
1849 blackbox *b=getBlackboxStuff(tt);
1850 fputs("20 ",d->f_write);
1851 b->blackbox_serialize(b,dd,l);
1852 }
1853 else
1854 {
1855 Werror("not implemented (t:%d, rtyp:%d)",tt, data->rtyp);
1856 d->level=0;
1857 return TRUE;
1858 }
1859 break;
1860 }
1861 if (d->level<=1) { fputc('\n',d->f_write); fflush(d->f_write); }
1862 data=data->next;
1863 }
1864 d->level--;
1865 return FALSE;
1866}
sattr * attr
Definition attrib.h:16
attr next
Definition attrib.h:26
const char * name
Definition subexpr.h:87
const char * Name()
Definition subexpr.h:120
attr * Attribute()
Definition subexpr.cc:1505
BITSET flag
Definition subexpr.h:90
@ BUCKET_CMD
Definition grammar.cc:284
poly sBucketPeek(sBucket_pt b)
Definition sbuckets.cc:455
ring sBucketGetRing(const sBucket_pt bucket)
Returns bucket ring.
Definition sbuckets.cc:46
sBucket * sBucket_pt
Definition sbuckets.h:16

◆ ssiWriteBigInt()

static void ssiWriteBigInt ( const ssiInfo * d,
const number n )
static

Definition at line 166 of file ssiLink.cc.

167{
169}
static FORCE_INLINE void n_WriteFd(number a, const ssiInfo *f, const coeffs r)
io via ssi:
Definition coeffs.h:967

◆ ssiWriteBigintmat()

static void ssiWriteBigintmat ( const ssiInfo * d,
bigintmat * v )
static

Definition at line 470 of file ssiLink.cc.

471{
472 fprintf(d->f_write,"%d %d ",v->rows(),v->cols());
473 int i;
474 for(i=0;i<v->length();i++)
475 {
476 ssiWriteBigInt(d,(*v)[i]);
477 }
478}

◆ ssiWriteBigintvec()

static void ssiWriteBigintvec ( const ssiInfo * d,
bigintmat * v )
static

Definition at line 480 of file ssiLink.cc.

481{
482 fprintf(d->f_write,"%d ",v->cols());
483 int i;
484 for(i=0;i<v->length();i++)
485 {
486 ssiWriteBigInt(d,(*v)[i]);
487 }
488}

◆ ssiWriteCommand()

static void ssiWriteCommand ( si_link l,
command D )
static

Definition at line 417 of file ssiLink.cc.

418{
419 ssiInfo *d=(ssiInfo*)l->data;
420 // syntax: <num ops> <operation> <op1> <op2> ....
421 fprintf(d->f_write,"%d %d ",D->argc,D->op);
422 if (D->argc >0) ssiWrite(l, &(D->arg1));
423 if (D->argc < 4)
424 {
425 if (D->argc >1) ssiWrite(l, &(D->arg2));
426 if (D->argc >2) ssiWrite(l, &(D->arg3));
427 }
428}

◆ ssiWriteIdeal()

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

Definition at line 412 of file ssiLink.cc.

413{
414 ssiWriteIdeal_R(d,typ,I,d->r);
415}

◆ ssiWriteIdeal_R()

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

Definition at line 382 of file ssiLink.cc.

383{
384 // syntax: 7 # of elements <poly 1> <poly2>.....(ideal,module,smatrix)
385 // syntax: 8 <rows> <cols> <poly 1> <poly2>.....(matrix)
386 // syntax
387 matrix M=(matrix)I;
388 int mn;
389 if (typ==MATRIX_CMD)
390 {
391 mn=MATROWS(M)*MATCOLS(M);
392 fprintf(d->f_write,"%d %d ", MATROWS(M),MATCOLS(M));
393 }
394 else
395 {
396 mn=IDELEMS(I);
397 fprintf(d->f_write,"%d ",IDELEMS(I));
398 }
399
400 int i;
401 int tt;
402 if ((typ==MODUL_CMD)||(typ==SMATRIX_CMD))
403 tt=VECTOR_CMD;
404 else
405 tt=POLY_CMD;
406
407 for(i=0;i<mn;i++)
408 {
409 ssiWritePoly_R(d,tt,I->m[i],R);
410 }
411}
#define R
Definition sirandom.c:27

◆ ssiWriteInt()

void ssiWriteInt ( const ssiInfo * d,
const int i )

Definition at line 154 of file ssiLink.cc.

155{
156 fprintf(d->f_write,"%d ",i);
157 //if (d->f_debug!=NULL) fprintf(d->f_debug,"int: %d ",i);
158}

◆ ssiWriteIntmat()

static void ssiWriteIntmat ( const ssiInfo * d,
intvec * v )
static

Definition at line 460 of file ssiLink.cc.

461{
462 fprintf(d->f_write,"%d %d ",v->rows(),v->cols());
463 int i;
464 for(i=0;i<v->length();i++)
465 {
466 fprintf(d->f_write,"%d ",(*v)[i]);
467 }
468}

◆ ssiWriteIntvec()

static void ssiWriteIntvec ( const ssiInfo * d,
intvec * v )
static

Definition at line 451 of file ssiLink.cc.

452{
453 fprintf(d->f_write,"%d ",v->length());
454 int i;
455 for(i=0;i<v->length();i++)
456 {
457 fprintf(d->f_write,"%d ",(*v)[i]);
458 }
459}

◆ ssiWriteList()

static void ssiWriteList ( si_link l,
lists dd )
static

Definition at line 440 of file ssiLink.cc.

441{
442 ssiInfo *d=(ssiInfo*)l->data;
443 int Ll=dd->nr;
444 fprintf(d->f_write,"%d ",Ll+1);
445 int i;
446 for(i=0;i<=Ll;i++)
447 {
448 ssiWrite(l,&(dd->m[i]));
449 }
450}

◆ ssiWriteNumber()

static void ssiWriteNumber ( const ssiInfo * d,
const number n )
static

Definition at line 199 of file ssiLink.cc.

200{
201 ssiWriteNumber_CF(d,n,d->r->cf);
202}

◆ ssiWriteNumber_CF()

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

Definition at line 171 of file ssiLink.cc.

172{
173 // syntax is as follows:
174 // case 1 Z/p: 3 <int>
175 // case 2 Q: 3 4 <int>
176 // or 3 0 <mpz_t nominator> <mpz_t denominator>
177 // or 3 1 dto.
178 // or 3 3 <mpz_t nominator>
179 // or 3 5 <mpz_t raw nom.> <mpz_t raw denom.>
180 // or 3 6 <mpz_t raw nom.> <mpz_t raw denom.>
181 // or 3 8 <mpz_t raw nom.>
183 {
184 fraction f=(fraction)n;
185 ssiWritePoly_R(d,POLY_CMD,NUM(f),cf->extRing);
186 ssiWritePoly_R(d,POLY_CMD,DEN(f),cf->extRing);
187 }
188 else if (getCoeffType(cf)==n_algExt)
189 {
190 ssiWritePoly_R(d,POLY_CMD,(poly)n,cf->extRing);
191 }
192 else if (cf->cfWriteFd!=NULL)
193 {
194 n_WriteFd(n,d,cf);
195 }
196 else WerrorS("coeff field not implemented");
197}

◆ ssiWritePoly()

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

Definition at line 377 of file ssiLink.cc.

378{
379 ssiWritePoly_R(d,typ,p,d->r);
380}

◆ ssiWritePoly_R()

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

Definition at line 359 of file ssiLink.cc.

360{
361 fprintf(d->f_write,"%d ",pLength(p));//number of terms
362
363 while(p!=NULL)
364 {
365 ssiWriteNumber_CF(d,pGetCoeff(p),r->cf);
366 //nWrite(fich,pGetCoeff(p));
367 fprintf(d->f_write,"%ld ",p_GetComp(p,r));//component
368
369 for(int j=1;j<=rVar(r);j++)
370 {
371 fprintf(d->f_write,"%ld ",p_GetExp(p,j,r ));//x^j
372 }
373 pIter(p);
374 }
375}
#define p_GetComp(p, r)
Definition monomials.h:64
#define pIter(p)
Definition monomials.h:37
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition monomials.h:44
static int pLength(poly a)
Definition p_polys.h:190
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:471

◆ ssiWriteProc()

static void ssiWriteProc ( const ssiInfo * d,
procinfov p )
static

Definition at line 430 of file ssiLink.cc.

431{
432 if (p->data.s.body==NULL)
434 if (p->data.s.body!=NULL)
435 ssiWriteString(d,p->data.s.body);
436 else
437 ssiWriteString(d,"");
438}
char * iiGetLibProcBuffer(procinfo *pi, int part)
Definition iplib.cc:197

◆ ssiWriteRing()

static void ssiWriteRing ( ssiInfo * d,
const ring r )
static

Definition at line 334 of file ssiLink.cc.

335{
336 /* 5 <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... <extRing> <Q-ideal> */
337 /* ch=-1: transext, coeff ring follows */
338 /* ch=-2: algext, coeff ring and minpoly follows */
339 /* ch=-3: cf name follows */
340 /* ch=-4: NULL */
341 /* ch=-5: reference <int> */
342 /* ch=-6: new reference <int> <ring> */
343 if ((r==NULL)||(r->cf==NULL))
344 {
345 fputs("-4 ",d->f_write);
346 return;
347 }
348 if (r==currRing) // see recursive calls for transExt/algExt
349 {
350 if (d->r!=NULL) rKill(d->r);
351 d->r=r;
352 }
353 if (r!=NULL)
354 {
355 /*d->*/rIncRefCnt(r);
356 }
357 ssiWriteRing_R(d,r);
358}

◆ ssiWriteRing_R()

static void ssiWriteRing_R ( ssiInfo * d,
const ring r )
static

Definition at line 204 of file ssiLink.cc.

205{
206 /* 5 <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... <extRing> <Q-ideal> */
207 /* ch=-1: transext, coeff ring follows */
208 /* ch=-2: algext, coeff ring and minpoly follows */
209 /* ch=-3: cf name follows */
210 /* ch=-4: NULL*/
211 /* ch=-5: reference <int> */
212 /* ch=-6: new reference <int> <ring> */
213 if (r!=NULL)
214 {
215 for(int i=0;i<SI_RING_CACHE;i++)
216 {
217 if (d->rings[i]==r)
218 {
219 fprintf(d->f_write,"-5 %d ",i);
220 return;
221 }
222 }
223 for(int i=0;i<SI_RING_CACHE;i++)
224 {
225 if (d->rings[i]==NULL)
226 {
227 d->rings[i]=rIncRefCnt(r);
228 fprintf(d->f_write,"-6 %d ",i);
229 break;
230 }
231 }
232 if (rField_is_Q(r) || rField_is_Zp(r))
233 fprintf(d->f_write,"%d %d ",n_GetChar(r->cf),r->N);
234 else if (rFieldType(r)==n_transExt)
235 fprintf(d->f_write,"-1 %d ",r->N);
236 else if (rFieldType(r)==n_algExt)
237 fprintf(d->f_write,"-2 %d ",r->N);
238 else /*dummy*/
239 {
240 fprintf(d->f_write,"-3 %d ",r->N);
241 ssiWriteString(d,nCoeffName(r->cf));
242 }
243
244 int i;
245 for(i=0;i<r->N;i++)
246 {
247 fprintf(d->f_write,"%d %s ",(int)strlen(r->names[i]),r->names[i]);
248 }
249 /* number of orderings:*/
250 i=0;
251 // remember dummy ring: everything 0:
252 if (r->order!=NULL) while (r->order[i]!=0) i++;
253 fprintf(d->f_write,"%d ",i);
254 /* each ordering block: */
255 i=0;
256 if (r->order!=NULL) while(r->order[i]!=0)
257 {
258 fprintf(d->f_write,"%d %d %d ",r->order[i],r->block0[i], r->block1[i]);
259 switch(r->order[i])
260 {
261 case ringorder_a:
262 case ringorder_wp:
263 case ringorder_Wp:
264 case ringorder_ws:
265 case ringorder_Ws:
266 case ringorder_aa:
267 {
268 int s=r->block1[i]-r->block0[i]+1; // #vars
269 for(int ii=0;ii<s;ii++)
270 fprintf(d->f_write,"%d ",r->wvhdl[i][ii]);
271 }
272 break;
273 case ringorder_M:
274 {
275 int s=r->block1[i]-r->block0[i]+1; // #vars
276 for(int ii=0;ii<s*s;ii++)
277 {
278 fprintf(d->f_write,"%d ",r->wvhdl[i][ii]);
279 }
280 }
281 break;
282
283 case ringorder_a64:
284 case ringorder_L:
285 case ringorder_IS:
286 Werror("ring oder not implemented for ssi:%d",r->order[i]);
287 break;
288
289 default: break;
290 }
291 i++;
292 }
293 if ((rFieldType(r)==n_transExt)
294 || (rFieldType(r)==n_algExt))
295 {
296 ssiWriteRing_R(d,r->cf->extRing); /* includes alg.ext if rFieldType(r)==n_algExt */
297 }
298 /* Q-ideal :*/
299 if (r->qideal!=NULL)
300 {
301 ssiWriteIdeal_R(d,IDEAL_CMD,r->qideal,r);
302 }
303 else
304 {
305 fputs("0 ",d->f_write/*ideal with 0 entries */);
306 }
307 }
308 else /* dummy ring r==NULL*/
309 {
310 fputs("0 0 0 0 "/*,r->ch,r->N, blocks, q-ideal*/,d->f_write);
311 }
312 if (rIsLPRing(r)) // cannot be combined with 23 2
313 {
314 fprintf(d->f_write,"23 1 %d %d ",SI_LOG2(r->bitmask),r->isLPring);
315 }
316 else
317 {
318 unsigned long bm=0;
319 int b=0;
320 bm=rGetExpSize(bm,b,r->N);
321 if (r->bitmask!=bm)
322 {
323 fprintf(d->f_write,"23 0 %d ",SI_LOG2(r->bitmask));
324 }
325 if (rIsPluralRing(r))
326 {
327 fputs("23 2 ",d->f_write);
328 ssiWriteIdeal(d,MATRIX_CMD,(ideal)r->GetNC()->C);
329 ssiWriteIdeal(d,MATRIX_CMD,(ideal)r->GetNC()->D);
330 }
331 }
332}
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition coeffs.h:448
static FORCE_INLINE char * nCoeffName(const coeffs cf)
Definition coeffs.h:960
static unsigned long rGetExpSize(unsigned long bitmask, int &bits)
Definition ring.cc:2629
static BOOLEAN rField_is_Zp(const ring r)
Definition ring.h:506
static n_coeffType rFieldType(const ring r)
the type of the coefficient filed of r (n_Zp, n_Q, etc)
Definition ring.h:562
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition ring.h:406
static BOOLEAN rIsLPRing(const ring r)
Definition ring.h:417
static BOOLEAN rField_is_Q(const ring r)
Definition ring.h:512
static int SI_LOG2(int v)
Definition si_log2.h:6

◆ ssiWriteString()

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

Definition at line 160 of file ssiLink.cc.

161{
162 fprintf(d->f_write,"%d %s ",(int)strlen(s),s);
163 //if (d->f_debug!=NULL) fprintf(d->f_debug,"stringi: %d \"%s\" ",strlen(s),s);
164}

Variable Documentation

◆ FE_OPT_NO_SHELL_FLAG

EXTERN_VAR BOOLEAN FE_OPT_NO_SHELL_FLAG

Definition at line 67 of file ssiLink.cc.

◆ si_link_root

EXTERN_VAR si_link_extension si_link_root

Definition at line 2241 of file ssiLink.cc.

◆ ssiReserved_Clients

STATIC_VAR int ssiReserved_Clients

Definition at line 2205 of file ssiLink.cc.

◆ ssiReserved_P

STATIC_VAR int ssiReserved_P =0

Definition at line 2202 of file ssiLink.cc.

◆ ssiReserved_sockfd

STATIC_VAR int ssiReserved_sockfd

Definition at line 2203 of file ssiLink.cc.

◆ ssiResverd_serv_addr

STATIC_VAR struct sockaddr_in ssiResverd_serv_addr

Definition at line 2204 of file ssiLink.cc.

◆ ssiToBeClosed

VAR link_list ssiToBeClosed =NULL

Definition at line 68 of file ssiLink.cc.

◆ ssiToBeClosed_inactive

VAR volatile BOOLEAN ssiToBeClosed_inactive =TRUE

Definition at line 69 of file ssiLink.cc.