Loading...
Searching...
No Matches
ssiLink.h File Reference
`#include "Singular/links/silink.h"`

Go to the source code of this file.

## Functions

BOOLEAN | ssiOpen (si_link l, short flag, leftv u)
BOOLEAN | ssiWrite (si_link l, leftv v)
BOOLEAN | ssiWrite2 (si_link l, leftv res, leftv v)
leftv | ssiRead1 (si_link l)
leftv | ssiRead2 (si_link l, leftv key)
BOOLEAN | ssiClose (si_link l)
const char * | slStatusSsi (si_link l, const char *request)
si_link_extension | slInitSsiExtension (si_link_extension s)
si_link | ssiCommandLink ()
void | sig_chld_hdl (int sig)
| additional default signal handler
int | ssiReservePort (int clients)
void | singular_close_links ()
ideal | ssiReadIdeal (ssiInfo *d)
void | ssiWriteIdeal (const ssiInfo *d, int typ, const ideal I)
int | ssiReadInt (const ssiInfo *d)
void | ssiWriteInt (const ssiInfo *d, const int i)
char * | ssiWritePoly_S (poly p, const ring r)
poly | ssiReadPoly_S (char *s, const ring r)
char * | ssiWriteIdeal_S (const ideal I, const ring R)
ideal | ssiReadIdeal_S (char *s, const ring R)
char * | ssiWriteMatrix_S (const matrix M, const ring R)
matrix | ssiReadMatrix_S (char *s, const ring R)
char * | ssiWriteModule_S (const ideal M, const ring R)
char * | ssiWriteRing_S (const ring r)
ring | ssiReadRing_S (char *s)
leftv | ssiRead1_S (char **s, const ring R)
void | ssiWrite_S (leftv v, const ring R)

## Function Documentation

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

{
#if 0
pid_t kidpid;
int status;
loop
{
kidpid = si_waitpid(-1, &status, WNOHANG);
if (kidpid==-1)
{
/* continue on interruption (EINTR): */
if (errno == EINTR) continue;
/* break on anything else (EINVAL or ECHILD according to manpage): */
break;
}
else if (kidpid==0) break; /* no more children to process, so break */
//printf("Child %ld terminated\n", kidpid);
link_list hh=ssiToBeClosed;
while((hh!=NULL)&&(ssiToBeClosed_inactive))
{
if((hh->l!=NULL) && (hh->l->m->Open==ssiOpen))
{
ssiInfo *d = (ssiInfo *)hh->l->data;
if(d->pid==kidpid)
{
if(ssiToBeClosed_inactive)
{
ssiToBeClosed_inactive=FALSE;
slClose(hh->l);
ssiToBeClosed_inactive=TRUE;
break;
}
else break;
}
else hh=(link_list)hh->next;
}
else hh=(link_list)hh->next;
}
}
#endif
}
TRUE
#define TRUE
Definition auxiliary.h:101
FALSE
#define FALSE
Definition auxiliary.h:97
NULL
#define NULL
Definition omList.c:12
ssiInfo
Definition s_buff.h:21
status
int * status
Definition si_signals.h:61
slClose
BOOLEAN slClose(si_link l)
Definition silink.cc:240
ssiToBeClosed_inactive
EXTERN_VAR volatile BOOLEAN ssiToBeClosed_inactive
Definition silink.h:131
link_list
link_struct * link_list
Definition silink.h:128
link_struct::next
void * next
Definition silink.h:125
link_struct::l
si_link l
Definition silink.h:124
ssiToBeClosed
EXTERN_VAR link_list ssiToBeClosed
Definition silink.h:130
ssiOpen
BOOLEAN ssiOpen(si_link l, short flag, leftv u)
Definition ssiLink.cc:1647
loop
#define loop
Definition structs.h:71

## singular_close_links()

void singular_close_links | ( |  | ) |

Definition at line 3455 of file ssiLink.cc.

{
link_list hh=ssiToBeClosed;
while(hh!=NULL)
{
if ((hh->l->m!=NULL)
&& (hh->l->m->Open==ssiOpen)
&& SI_LINK_OPEN_P(hh->l)
&& (strcmp(hh->l->mode, "fork")==0))
{
SI_LINK_SET_CLOSE_P(hh->l);
ssiInfo *d = (ssiInfo *)hh->l->data;
if (d->f_read!=NULL) { s_close(d->f_read);d->f_read=NULL;}
if (d->f_write!=NULL) { fclose(d->f_write); d->f_write=NULL; }
}
hh=(link_list)hh->next;
}
ssiToBeClosed=NULL;
}
s_close
int s_close(s_buff &F)
Definition s_buff.cc:46
SI_LINK_SET_CLOSE_P
#define SI_LINK_SET_CLOSE_P(l)
Definition silink.h:76
SI_LINK_OPEN_P
#define SI_LINK_OPEN_P(l)
Definition silink.h:71

## slInitSsiExtension()

si_link_extension slInitSsiExtension | ( | si_link_extension | s | ) |

Definition at line 2808 of file ssiLink.cc.

{
s->Open=ssiOpen;
s->Close=ssiClose;
s->Kill=ssiClose;
s->Read=ssiRead1;
s->Read2=ssiRead2;
s->Write=ssiWrite;
s->Dump=ssiDump;
s->GetDump=ssiGetDump;
s->Status=slStatusSsi;
s->SetRing=ssiSetRing;
s->type="ssi";
return s;
}
s
const CanonicalForm int s
Definition facAbsFact.cc:51
ssiDump
BOOLEAN ssiDump(si_link l)
Definition ssiLink.cc:3412
slStatusSsi
const char * slStatusSsi(si_link l, const char *request)
Definition ssiLink.cc:2825
ssiClose
BOOLEAN ssiClose(si_link l)
Definition ssiLink.cc:2120
ssiWrite
BOOLEAN ssiWrite(si_link l, leftv data)
Definition ssiLink.cc:2537
ssiGetDump
BOOLEAN ssiGetDump(si_link l)
Definition ssiLink.cc:3429
ssiRead2
leftv ssiRead2(si_link l, leftv u)
Definition ssiLink.cc:3488
ssiSetRing
static BOOLEAN ssiSetRing(si_link l, ring r, BOOLEAN send)
Definition ssiLink.cc:2518
ssiRead1
leftv ssiRead1(si_link l)
Definition ssiLink.cc:2209

## slStatusSsi()

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

Definition at line 2825 of file ssiLink.cc.

{
if (strcmp(l->mode,"string")==0)
{
if (strcmp(request, "read") == 0)
{
if (SI_LINK_R_OPEN_P(l)) return "yes";
else return "no";
}
if (strcmp(request, "write") == 0)
{
if (SI_LINK_W_OPEN_P(l)) return "yes";
else return "no";
}
return "inavlid";
}
ssiInfo *d=(ssiInfo*)l->data;
if (d==NULL)
return "no";
if (((strcmp(l->mode,"fork")==0)
||(strcmp(l->mode,"tcp")==0)
||(strcmp(l->mode,"connect")==0))
&& (strcmp(request, "read") == 0))
{
if (s_isready(d->f_read)) return "ready";
#if defined(HAVE_POLL)
pollfd pfd;
loop
{
/* Don't block. Return socket status immediately. */
pfd.fd=d->fd_read;
pfd.events=POLLIN;
//Print("test fd %d\n",d->fd_read);
/* check with select: chars waiting: no -> not ready */
switch (si_poll(&pfd,1,0))
{
case 0: /* not ready */ return "not ready";
case -1: /*error*/ return "error";
case 1: /*ready ? */ break;
}
#else
fd_set mask;
struct timeval wt;
if (FD_SETSIZE<=d->fd_read)
{
Werror("file descriptor number too high (%d)",d->fd_read);
return "error";
}
loop
{
/* Don't block. Return socket status immediately. */
wt.tv_sec = 0;
wt.tv_usec = 0;
FD_ZERO(&mask);
FD_SET(d->fd_read, &mask);
//Print("test fd %d\n",d->fd_read);
/* check with select: chars waiting: no -> not ready */
switch (si_select(d->fd_read+1, &mask, NULL, NULL, &wt))
{
case 0: /* not ready */ return "not ready";
case -1: /*error*/ return "error";
case 1: /*ready ? */ break;
}
#endif
/* yes: read 1 char*/
/* if \n, check again with select else ungetc(c), ready*/
int c=s_getc(d->f_read);
//Print("try c=%d\n",c);
if (c== -1) return "eof"; /* eof or error */
else if (isdigit(c))
{ s_ungetc(c,d->f_read); return "ready"; }
else if (c>' ')
{
Werror("unknown char in ssiLink(%d)",c);
return "error";
}
/* else: next char */
}
}
else if (strcmp(request, "read") == 0)
{
if (SI_LINK_R_OPEN_P(l) && (!s_iseof(d->f_read)) && (s_isready(d->f_read))) return "ready";
else return "not ready";
}
else if (strcmp(request, "write") == 0)
{
if (SI_LINK_W_OPEN_P(l)) return "ready";
else return "not ready";
}
else return "unknown status request";
}
l
int l
Definition cfEzgcd.cc:100
Werror
void Werror(const char *fmt,...)
Definition reporter.cc:189
s_getc
int s_getc(s_buff F)
Definition s_buff.cc:59
s_isready
int s_isready(s_buff F)
Definition s_buff.cc:86
s_iseof
int s_iseof(s_buff F)
Definition s_buff.cc:352
s_ungetc
void s_ungetc(int c, s_buff F)
Definition s_buff.cc:100
SI_LINK_W_OPEN_P
#define SI_LINK_W_OPEN_P(l)
Definition silink.h:72
SI_LINK_R_OPEN_P
#define SI_LINK_R_OPEN_P(l)
Definition silink.h:73

## ssiClose()

BOOLEAN ssiClose | ( | si_link | l | ) |

Definition at line 2120 of file ssiLink.cc.

{
if (l!=NULL)
{
SI_LINK_SET_CLOSE_P(l);
ssiInfo *d = (ssiInfo *)l->data;
if (d!=NULL)
{
// send quit signal
if ((d->send_quit_at_exit)
&& (d->quit_sent==0))
{
fputs("99\n",d->f_write);
fflush(d->f_write);
d->quit_sent=1;
}
// clean ring
if (d->r!=NULL) rKill(d->r);
for(int i=0;i<SI_RING_CACHE;i++)
{
if (d->rings[i]!=NULL) rKill(d->rings[i]);
d->rings[i]=NULL;
}
if (d->f_read!=NULL) { s_close(d->f_read);d->f_read=NULL;}
if (d->f_write!=NULL) { fclose(d->f_write); d->f_write=NULL; }
if (((strcmp(l->mode,"tcp")==0)
|| (strcmp(l->mode,"fork")==0))
&& (d->pid>1))
{
// did the child stop ?
int pid=si_waitpid(d->pid,NULL,WNOHANG);
if ((pid==0) /* no status change for child*/
&& (kill(d->pid,0)==0)) // child is still running
{
struct timespec t;
struct timespec rem;
// wait 60 sec
for(int i=0;i<50;i++)
{
// wait till signal or 100ms:
t.tv_sec=0;
t.tv_nsec=100000000; // <=100 ms
nanosleep(&t, &rem);
// child finished ?
if (si_waitpid(d->pid,NULL,WNOHANG) == d->pid) break;
}
if (kill(d->pid,0)==0) // child still exists
{
kill(d->pid,SIGTERM);
t.tv_sec=1;
t.tv_nsec=0; // <=1000 ms
nanosleep(&t, &rem);
si_waitpid(d->pid,NULL,WNOHANG);
}
}
}
if ((strcmp(l->mode,"tcp")==0)
|| (strcmp(l->mode,"fork")==0))
{
link_list hh=ssiToBeClosed;
if (hh!=NULL)
{
if (hh->l==l)
{
ssiToBeClosed=(link_list)hh->next;
omFreeSize(hh,sizeof(link_struct));
}
else while(hh->next!=NULL)
{
link_list hhh=(link_list)hh->next;
if (hhh->l==l)
{
hh->next=hhh->next;
omFreeSize(hhh,sizeof(link_struct));
break;
}
else
hh=(link_list)hh->next;
}
}
}
omFreeSize((ADDRESS)d,(sizeof *d));
}
l->data=NULL;
}
return FALSE;
}
ADDRESS
void * ADDRESS
Definition auxiliary.h:120
i
int i
Definition cfEzgcd.cc:132
rKill
void rKill(ring r)
Definition ipshell.cc:6181
rem
void rem(unsigned long *a, unsigned long *q, unsigned long p, int &dega, int degq)
Definition minpoly.cc:572
omFreeSize
#define omFreeSize(addr, size)
Definition omAllocDecl.h:260
SI_RING_CACHE
#define SI_RING_CACHE
Definition s_buff.h:30
link_struct
Definition silink.h:122

## ssiCommandLink()

si_link ssiCommandLink | ( |  | ) |

Definition at line 3194 of file ssiLink.cc.

{
if (ssiReserved_P==0)
{
WerrorS("ERROR no reserved port requested");
return NULL;
}
struct sockaddr_in cli_addr;
int clilen = sizeof(cli_addr);
int newsockfd = si_accept(ssiReserved_sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
if(newsockfd < 0)
{
Werror("ERROR on accept (errno=%d)",errno);
return NULL;
}
si_link l=(si_link) omAlloc0Bin(sip_link_bin);
si_link_extension s = si_link_root;
si_link_extension prev = s;
while (strcmp(s->type, "ssi") != 0)
{
if (s->next == NULL)
{
prev = s;
s = NULL;
break;
}
else
{
s = s->next;
}
}
if (s != NULL)
l->m = s;
else
{
si_link_extension ns = (si_link_extension)omAlloc0Bin(s_si_link_extension_bin);
prev->next=slInitSsiExtension(ns);
l->m = prev->next;
}
l->name=omStrDup("");
l->mode=omStrDup("tcp");
l->ref=1;
ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo));
l->data=d;
d->fd_read = newsockfd;
d->fd_write = newsockfd;
d->f_read = s_open(newsockfd);
d->f_write = fdopen(newsockfd, "w");
SI_LINK_SET_RW_OPEN_P(l);
ssiReserved_Clients--;
if (ssiReserved_Clients<=0)
{
ssiReserved_P=0;
si_close(ssiReserved_sockfd);
}
return l;
}
si_link_root
EXTERN_VAR si_link_extension si_link_root
Definition asciiLink.cc:32
WerrorS
void WerrorS(const char *s)
Definition feFopen.cc:24
omStrDup
#define omStrDup(s)
Definition omAllocDecl.h:263
omAlloc0Bin
#define omAlloc0Bin(bin)
Definition omAllocDecl.h:206
omAlloc0
#define omAlloc0(size)
Definition omAllocDecl.h:211
s_open
s_buff s_open(int fd)
Definition s_buff.cc:32
ssiInfo::fd_write
int fd_write
Definition s_buff.h:26
ssiInfo::f_read
s_buff f_read
Definition s_buff.h:22
ssiInfo::f_write
FILE * f_write
Definition s_buff.h:23
ssiInfo::fd_read
int fd_read
Definition s_buff.h:26
sip_link_bin
VAR omBin sip_link_bin
Definition silink.cc:40
s_si_link_extension_bin
VAR omBin s_si_link_extension_bin
Definition silink.cc:39
si_link
ip_link * si_link
Definition silink.h:20
SI_LINK_SET_RW_OPEN_P
#define SI_LINK_SET_RW_OPEN_P(l)
Definition silink.h:80
slInitSsiExtension
si_link_extension slInitSsiExtension(si_link_extension s)
Definition ssiLink.cc:2808
ssiReserved_P
STATIC_VAR int ssiReserved_P
Definition ssiLink.cc:3154
ssiReserved_sockfd
STATIC_VAR int ssiReserved_sockfd
Definition ssiLink.cc:3155
ssiReserved_Clients
STATIC_VAR int ssiReserved_Clients
Definition ssiLink.cc:3157

## ssiOpen()

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

Definition at line 1647 of file ssiLink.cc.

{
if (l!=NULL)
{
const char *mode;
if (flag & SI_LINK_OPEN)
{
if (strcmp(l->mode, "r") == 0)
flag = SI_LINK_READ;
else if (strcmp(l->mode,"string")==0)
{
SI_LINK_SET_RW_OPEN_P(l);
return FALSE;
}
else flag = SI_LINK_WRITE;
}
if (((flag == SI_LINK_READ)
|| (flag == SI_LINK_WRITE))
&& (strcmp(l->mode,"string")==0))
{
SI_LINK_SET_RW_OPEN_P(l);
return FALSE;
}
if (flag == SI_LINK_READ) mode = "r";
else if (strcmp(l->mode, "w") == 0) mode = "w";
else if (strcmp(l->mode, "fork") == 0) mode = "fork";
else if (strcmp(l->mode, "tcp") == 0) mode = "tcp";
else if (strcmp(l->mode, "connect") == 0) mode = "connect";
else mode = "a";
SI_LINK_SET_OPEN_P(l, flag);
if(l->data!=NULL) omFreeSize(l->data,sizeof(ssiInfo));
omFreeBinAddr(l->mode);
l->mode = omStrDup(mode);
ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo));
l->data=d;
if (l->name[0] == '\0')
{
if (strcmp(mode,"fork")==0)
{
int cpus = (long) feOptValue(FE_OPT_CPUS);
if (cpus<1)
{
WerrorS("no sub-processes allowed");
l->flags=0;
l->data=NULL;
omFreeSize(d,sizeof(ssiInfo));
return TRUE;
}
int pc[2];
int cp[2];
int err1=pipe(pc);
int err2=pipe(cp);
if (err1 || err2)
{
Werror("pipe failed with %d\n",errno);
l->flags=0;
l->data=NULL;
omFreeSize(d,sizeof(ssiInfo));
return TRUE;
}
link_list n=(link_list)omAlloc(sizeof(link_struct));
n->u=u;
n->l=l;
n->next=(void *)ssiToBeClosed;
ssiToBeClosed=n;
pid_t pid = fork();
if (pid == -1 && errno == EAGAIN) // RLIMIT_NPROC too low?
{
raise_rlimit_nproc();
pid = fork();
}
if (pid == -1)
{
WerrorS("could not fork");
l->flags=0;
l->data=NULL;
omFreeSize(d,sizeof(ssiInfo));
return TRUE;
}
if (pid==0) /*fork: child*/
{
/* block SIGINT */
sigset_t sigint;
sigemptyset(&sigint);
sigaddset(&sigint, SIGINT);
sigprocmask(SIG_BLOCK, &sigint, NULL);
si_set_signal(SIGTERM,sig_term_hdl);
/* set #cpu to 1 for the child:*/
feSetOptValue(FE_OPT_CPUS,1);
link_list hh=(link_list)ssiToBeClosed->next;
/* we know: l is the first entry in ssiToBeClosed-list */
while(hh!=NULL)
{
SI_LINK_SET_CLOSE_P(hh->l);
ssiInfo *dd=(ssiInfo*)hh->l->data;
s_close(dd->f_read);
fclose(dd->f_write);
if (dd->r!=NULL) rKill(dd->r);
omFreeSize((ADDRESS)dd,(sizeof *dd));
hh->l->data=NULL;
link_list nn=(link_list)hh->next;
omFree(hh);
hh=nn;
}
ssiToBeClosed->next=NULL;
#ifdef HAVE_SIMPLEIPC
memset(sem_acquired, 0, SIPC_MAX_SEMAPHORES*sizeof(sem_acquired[0]));
#endif // HAVE_SIMPLEIPC
si_close(pc[1]); si_close(cp[0]);
d->f_write=fdopen(cp[1],"w");
d->f_read=s_open(pc[0]);
d->fd_read=pc[0];
d->fd_write=cp[1];
//d->r=currRing;
//if (d->r!=NULL) d->r->ref++;
l->data=d;
omFreeBinAddr(l->mode);
l->mode = omStrDup(mode);
singular_in_batchmode=TRUE;
SI_LINK_SET_RW_OPEN_P(l);
//myynest=0;
fe_fgets_stdin=fe_fgets_dummy;
if ((u!=NULL)&&(u->rtyp==IDHDL))
{
idhdl h=(idhdl)u->data;
h->lev=0;
}
loop
{
if (!SI_LINK_OPEN_P(l)) m2_end(-1);
if(d->f_read->is_eof) m2_end(-1);
leftv h=ssiRead1(l); /*contains an exit.... */
if (feErrors != NULL && *feErrors != '\0')
{
// handle errors:
PrintS(feErrors); /* currently quite simple */
*feErrors = '\0';
}
ssiWrite(l,h);
h->CleanUp();
omFreeBin(h, sleftv_bin);
}
/* never reached*/
}
else if (pid>0) /*fork: parent*/
{
d->pid=pid;
si_close(pc[0]); si_close(cp[1]);
d->f_write=fdopen(pc[1],"w");
d->f_read=s_open(cp[0]);
d->fd_read=cp[0];
d->fd_write=pc[1];
SI_LINK_SET_RW_OPEN_P(l);
d->send_quit_at_exit=1;
//d->r=currRing;
//if (d->r!=NULL) d->r->ref++;
}
else
{
Werror("fork failed (%d)",errno);
l->data=NULL;
omFreeSize(d,sizeof(ssiInfo));
return TRUE;
}
}
// ---------------------------------------------------------------------
else if (strcmp(mode,"tcp")==0)
{
int sockfd, newsockfd, portno, clilen;
struct sockaddr_in serv_addr, cli_addr;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd < 0)
{
WerrorS("ERROR opening socket");
l->data=NULL;
l->flags=0;
omFreeSize(d,sizeof(ssiInfo));
return TRUE;
}
memset((char *) &serv_addr,0, sizeof(serv_addr));
portno = 1025;
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
do
{
portno++;
serv_addr.sin_port = htons(portno);
if(portno > 50000)
{
WerrorS("ERROR on binding (no free port available?)");
l->data=NULL;
l->flags=0;
omFreeSize(d,sizeof(ssiInfo));
return TRUE;
}
}
while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
Print("waiting on port %d\n", portno);mflush();
listen(sockfd,1);
newsockfd = si_accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
if(newsockfd < 0)
{
WerrorS("ERROR on accept");
l->data=NULL;
l->flags=0;
omFreeSize(d,sizeof(ssiInfo));
return TRUE;
}
PrintS("client accepted\n");
d->fd_read = newsockfd;
d->fd_write = newsockfd;
d->f_read = s_open(newsockfd);
d->f_write = fdopen(newsockfd, "w");
SI_LINK_SET_RW_OPEN_P(l);
si_close(sockfd);
}
// no ssi-Link on stdin or stdout
else if (strcmp(mode,"string")==0)
{
SI_LINK_SET_RW_OPEN_P(l);
}
else
{
Werror("invalid mode >>%s<< for ssi",mode);
l->data=NULL;
l->flags=0;
omFreeSize(d,sizeof(ssiInfo));
return TRUE;
}
}
// =========================================================================
else /*now l->name!=NULL*/
{
// tcp mode
if(strcmp(mode,"tcp")==0)
{
int sockfd, newsockfd, portno, clilen;
struct sockaddr_in serv_addr, cli_addr;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd < 0)
{
WerrorS("ERROR opening socket");
l->data=NULL;
l->flags=0;
omFreeSize(d,sizeof(ssiInfo));
return TRUE;
}
memset((char *) &serv_addr,0, sizeof(serv_addr));
portno = 1025;
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
do
{
portno++;
serv_addr.sin_port = htons(portno);
if(portno > 50000)
{
WerrorS("ERROR on binding (no free port available?)");
l->data=NULL;
l->flags=0;
omFreeSize(d,sizeof(ssiInfo));
return TRUE;
}
}
while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
//Print("waiting on port %d\n", portno);mflush();
listen(sockfd,1);
char* cli_host = (char*)omAlloc(256);
char* path = (char*)omAlloc(1024);
int r = si_sscanf(l->name,"%255[^:]:%s",cli_host,path);
if(r == 0)
{
WerrorS("ERROR: no host specified");
l->data=NULL;
l->flags=0;
omFreeSize(d,sizeof(ssiInfo));
omFree(path);
omFree(cli_host);
return TRUE;
}
else if(r == 1)
{
WarnS("program not specified, using /usr/local/bin/Singular");
Warn("in line >>%s<<",my_yylinebuf);
strcpy(path,"/usr/local/bin/Singular");
}
char* ssh_command = (char*)omAlloc(256);
char* ser_host = (char*)omAlloc(64);
if(strcmp(cli_host,"localhost")==0)
strcpy(ser_host,"localhost");
else
gethostname(ser_host,64);
if (strcmp(cli_host,"localhost")==0) /*avoid "ssh localhost" as key may change*/
snprintf(ssh_command,256,"%s -q --batch --link=ssi --MPhost=%s --MPport=%d &",path,ser_host,portno);
else
snprintf(ssh_command,256,"ssh %s %s -q --batch --link=ssi --MPhost=%s --MPport=%d &",cli_host,path,ser_host,portno);
//Print("client on %s started:%s\n",cli_host,path);
omFree(path);
omFree(cli_host);
if (TEST_OPT_PROT) { Print("running >>%s<<\n",ssh_command); }
int re=system(ssh_command);
if (re<0)
{
Werror("ERROR running `%s` (%d)",ssh_command,re);
l->data=NULL;
l->flags=0;
omFreeSize(d,sizeof(ssiInfo));
return TRUE;
}
omFree(ssh_command);
omFree(ser_host);
clilen = sizeof(cli_addr);
newsockfd = si_accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
if(newsockfd < 0)
{
WerrorS("ERROR on accept");
l->data=NULL;
l->flags=0;
omFreeSize(d,sizeof(ssiInfo));
return TRUE;
}
//PrintS("client accepted\n");
d->fd_read = newsockfd;
d->fd_write = newsockfd;
d->f_read = s_open(newsockfd);
d->f_write = fdopen(newsockfd, "w");
si_close(sockfd);
SI_LINK_SET_RW_OPEN_P(l);
d->send_quit_at_exit=1;
link_list newlink=(link_list)omAlloc(sizeof(link_struct));
newlink->u=u;
newlink->l=l;
newlink->next=(void *)ssiToBeClosed;
ssiToBeClosed=newlink;
fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,si_opt_1,si_opt_2);
}
// ----------------------------------------------------------------------
else if(strcmp(mode,"connect")==0)
{
char* host = (char*)omAlloc(256);
int sockfd, portno;
struct sockaddr_in serv_addr;
struct hostent *server;
si_sscanf(l->name,"%255[^:]:%d",host,&portno);
//Print("connect to host %s, port %d\n",host,portno);mflush();
if (portno!=0)
{
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
{
WerrorS("ERROR opening socket");
l->flags=0;
l->data=NULL;
omFreeSize(d,sizeof(ssiInfo));
return TRUE;
}
server = gethostbyname(host);
if (server == NULL)
{
WerrorS("ERROR, no such host");
l->flags=0;
l->data=NULL;
omFreeSize(d,sizeof(ssiInfo));
return TRUE;
}
memset((char *) &serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
memcpy((char *)&serv_addr.sin_addr.s_addr,
(char *)server->h_addr,
server->h_length);
serv_addr.sin_port = htons(portno);
if (si_connect(sockfd,(sockaddr*)&serv_addr,sizeof(serv_addr)) < 0)
{
Werror("ERROR connecting(errno=%d)",errno);
l->flags=0;
l->data=NULL;
omFreeSize(d,sizeof(ssiInfo));
return TRUE;
}
//PrintS("connected\n");mflush();
d->f_read=s_open(sockfd);
d->fd_read=sockfd;
d->f_write=fdopen(sockfd,"w");
d->fd_write=sockfd;
SI_LINK_SET_RW_OPEN_P(l);
omFree(host);
}
else
{
l->data=NULL;
l->flags=0;
omFreeSize(d,sizeof(ssiInfo));
return TRUE;
}
}
// ======================================================================
else
{
// normal link to a file
if (FE_OPT_NO_SHELL_FLAG) {WerrorS("no links allowed");return TRUE;}
FILE *outfile;
char *filename=l->name;
if(filename[0]=='>')
{
if (filename[1]=='>')
{
filename+=2;
mode = "a";
}
else
{
filename++;
mode="w";
}
}
outfile=myfopen(filename,mode);
if (outfile!=NULL)
{
if (strcmp(l->mode,"r")==0)
{
fclose(outfile);
d->f_read=s_open_by_name(filename);
}
else
{
d->f_write = outfile;
fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,si_opt_1,si_opt_2);
}
}
else
{
omFree(d);
l->data=NULL;
l->flags=0;
return TRUE;
}
}
}
}
return FALSE;
}
sleftv::rtyp
int rtyp
Definition subexpr.h:91
sleftv::data
void * data
Definition subexpr.h:88
singular_in_batchmode
VAR BOOLEAN singular_in_batchmode
Definition cntrlc.cc:62
si_set_signal
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
sig_term_hdl
void sig_term_hdl(int)
Definition cntrlc.cc:77
Print
#define Print
Definition emacs.cc:80
Warn
#define Warn
Definition emacs.cc:77
WarnS
#define WarnS
Definition emacs.cc:78
FE_OPT_NO_SHELL_FLAG
EXTERN_VAR BOOLEAN FE_OPT_NO_SHELL_FLAG
Definition extra.cc:166
myfopen
FILE * myfopen(const char *path, const char *mode)
Definition feFopen.cc:167
feSetOptValue
const char * feSetOptValue(feOptIndex opt, char *optarg)
Definition feOpt.cc:154
feOptValue
static void * feOptValue(feOptIndex opt)
Definition feOpt.h:40
my_yylinebuf
VAR char my_yylinebuf[80]
Definition febase.cc:44
fe_fgets_dummy
char * fe_fgets_dummy(const char *, char *, int)
Definition feread.cc:455
fe_fgets_stdin
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition feread.cc:32
sleftv_bin
EXTERN_VAR omBin sleftv_bin
Definition ipid.h:145
h
STATIC_VAR Poly * h
Definition janet.cc:971
m2_end
void m2_end(int i)
Definition misc_ip.cc:1104
omAlloc
#define omAlloc(size)
Definition omAllocDecl.h:210
omFree
#define omFree(addr)
Definition omAllocDecl.h:261
omFreeBin
#define omFreeBin(addr, bin)
Definition omAllocDecl.h:259
omFreeBinAddr
#define omFreeBinAddr(addr)
Definition omAllocDecl.h:258
si_opt_2
VAR unsigned si_opt_2
Definition options.c:6
si_opt_1
VAR unsigned si_opt_1
Definition options.c:5
TEST_OPT_PROT
#define TEST_OPT_PROT
Definition options.h:105
PrintS
void PrintS(const char *s)
Definition reporter.cc:288
feErrors
VAR char * feErrors
Definition reporter.cc:47
mflush
#define mflush()
Definition reporter.h:58
idhdl
idrec * idhdl
Definition ring.h:22
raise_rlimit_nproc
int raise_rlimit_nproc()
Definition rlimit.c:18
s_open_by_name
s_buff s_open_by_name(const char *n)
Definition s_buff.cc:40
ssiInfo::pid
pid_t pid
Definition s_buff.h:25
ssiInfo::send_quit_at_exit
char send_quit_at_exit
Definition s_buff.h:28
sem_acquired
VAR int sem_acquired[SIPC_MAX_SEMAPHORES]
Definition semaphore.c:25
SI_LINK_WRITE
#define SI_LINK_WRITE
Definition silink.h:67
link_struct::u
leftv u
Definition silink.h:123
SI_LINK_OPEN
#define SI_LINK_OPEN
Definition silink.h:65
SI_LINK_SET_OPEN_P
#define SI_LINK_SET_OPEN_P(l, flag)
Definition silink.h:77
SI_LINK_READ
#define SI_LINK_READ
Definition silink.h:66
SIPC_MAX_SEMAPHORES
#define SIPC_MAX_SEMAPHORES
Definition simpleipc.h:10
SSI_VERSION
#define SSI_VERSION
Definition ssiLink.cc:55
leftv
sleftv * leftv
Definition structs.h:53
IDHDL
#define IDHDL
Definition tok.h:31
MAX_TOK
@ MAX_TOK
Definition tok.h:220

## ssiRead1()

leftv ssiRead1 | ( | si_link | l | ) |

Definition at line 2209 of file ssiLink.cc.

{
ssiInfo *d = (ssiInfo *)l->data;
leftv res=(leftv)omAlloc0Bin(sleftv_bin);
int t=0;
t=s_readint(d->f_read);
//Print("got type %d\n",t);
switch(t)
{
case 1:res->rtyp=INT_CMD;
res->data=(char *)(long)ssiReadInt(d);
//Print("int: %d\n",(int)(long)res->data);
break;
case 2:res->rtyp=STRING_CMD;
res->data=(char *)ssiReadString(d);
//Print("str: %s\n",(char*)res->data);
break;
case 3:res->rtyp=NUMBER_CMD;
if (d->r==NULL) goto no_ring;
ssiCheckCurrRing(d->r);
res->data=(char *)ssiReadNumber(d);
//Print("number\n");
break;
case 4:res->rtyp=BIGINT_CMD;
res->data=(char *)ssiReadBigInt(d);
//Print("bigint\n");
break;
case 15:
case 5:{
//Print("ring %d\n",t);
d->r=ssiReadRing(d);
if (errorreported) return NULL;
res->data=(char*)d->r;
if (d->r!=NULL) rIncRefCnt(d->r);
res->rtyp=RING_CMD;
if (t==15) // setring
{
if(ssiSetCurrRing(d->r)) { d->r=currRing; }
omFreeBin(res,sleftv_bin);
return ssiRead1(l);
}
}
break;
case 6:res->rtyp=POLY_CMD;
//Print("poly\n");
if (d->r==NULL) goto no_ring;
ssiCheckCurrRing(d->r);
res->data=(char*)ssiReadPoly(d);
break;
case 7:res->rtyp=IDEAL_CMD;
//Print("ideal\n");
if (d->r==NULL) goto no_ring;
ssiCheckCurrRing(d->r);
res->data=(char*)ssiReadIdeal(d);
break;
case 8:res->rtyp=MATRIX_CMD;
//Print("matrix\n");
if (d->r==NULL) goto no_ring;
ssiCheckCurrRing(d->r);
res->data=(char*)ssiReadMatrix(d);
break;
case 9:res->rtyp=VECTOR_CMD;
//Print("vector\n");
if (d->r==NULL) goto no_ring;
ssiCheckCurrRing(d->r);
res->data=(char*)ssiReadPoly(d);
break;
case 10:
case 22:if (t==22) res->rtyp=SMATRIX_CMD;
else res->rtyp=MODUL_CMD;
//Print("module/smatrix %d\n",t);
if (d->r==NULL) goto no_ring;
ssiCheckCurrRing(d->r);
{
int rk=s_readint(d->f_read);
ideal M=ssiReadIdeal(d);
M->rank=rk;
res->data=(char*)M;
}
break;
case 11:
{
//Print("cmd\n",t);
res->rtyp=COMMAND;
res->data=ssiReadCommand(l);
int nok=res->Eval();
if (nok) WerrorS("error in eval");
break;
}
case 12: /*DEF_CMD*/
{
//Print("def\n",t);
res->rtyp=0;
res->name=(char *)ssiReadString(d);
int nok=res->Eval();
if (nok) WerrorS("error in name lookup");
break;
}
case 13: res->rtyp=PROC_CMD;
res->data=ssiReadProc(d);
break;
case 14: res->rtyp=LIST_CMD;
res->data=ssiReadList(l);
break;
case 16: res->rtyp=NONE; res->data=NULL;
break;
case 17: res->rtyp=INTVEC_CMD;
res->data=ssiReadIntvec(d);
break;
case 18: res->rtyp=INTMAT_CMD;
res->data=ssiReadIntmat(d);
break;
case 19: res->rtyp=BIGINTMAT_CMD;
res->data=ssiReadBigintmat(d);
break;
case 20: ssiReadBlackbox(res,l);
break;
case 21: ssiReadAttrib(res,l);
break;
case 23: ssiReadRingProperties(l);
return ssiRead1(l);
break;
case 24: res->rtyp=BIGINTVEC_CMD;
res->data=ssiReadBigintvec(d);
break;
// ------------
case 98: // version
{
int n98_v,n98_m;
BITSET n98_o1,n98_o2;
n98_v=s_readint(d->f_read);
n98_m=s_readint(d->f_read);
n98_o1=s_readint(d->f_read);
n98_o2=s_readint(d->f_read);
if ((n98_v!=SSI_VERSION) ||(n98_m!=MAX_TOK))
{
Print("incompatible versions of ssi: %d/%d vs %d/%d\n",
SSI_VERSION,MAX_TOK,n98_v,n98_m);
}
#ifndef SING_NDEBUG
if (TEST_OPT_DEBUG)
Print("// opening ssi-%d, MAX_TOK=%d\n",n98_v,n98_m);
#endif
si_opt_1=n98_o1;
si_opt_2=n98_o2;
omFreeBin(res,sleftv_bin);
return ssiRead1(l);
}
case 99: omFreeBin(res,sleftv_bin); ssiClose(l); m2_end(-1);
break; /*to make compiler happy*/
case 0: if (s_iseof(d->f_read))
{
ssiClose(l);
}
res->rtyp=DEF_CMD;
break;
default: Werror("not implemented (t:%d)",t);
omFreeBin(res,sleftv_bin);
res=NULL;
break;
}
// if currRing is required for the result, but lost
// define "ssiRing%d" as currRing:
if ((d->r!=NULL)
&& (currRing!=d->r)
&& (res->RingDependend()))
{
if(ssiSetCurrRing(d->r)) { d->r=currRing; }
}
return res;
no_ring: WerrorS("no ring");
omFreeBin(res,sleftv_bin);
return NULL;
}
BITSET
#define BITSET
Definition auxiliary.h:85
res
CanonicalForm res
Definition facAbsFact.cc:60
errorreported
VAR short errorreported
Definition feFopen.cc:23
IDEAL_CMD
@ IDEAL_CMD
Definition grammar.cc:285
MATRIX_CMD
@ MATRIX_CMD
Definition grammar.cc:287
BIGINTMAT_CMD
@ BIGINTMAT_CMD
Definition grammar.cc:278
PROC_CMD
@ PROC_CMD
Definition grammar.cc:281
INTMAT_CMD
@ INTMAT_CMD
Definition grammar.cc:280
MODUL_CMD
@ MODUL_CMD
Definition grammar.cc:288
SMATRIX_CMD
@ SMATRIX_CMD
Definition grammar.cc:292
VECTOR_CMD
@ VECTOR_CMD
Definition grammar.cc:293
BIGINTVEC_CMD
@ BIGINTVEC_CMD
Definition grammar.cc:279
NUMBER_CMD
@ NUMBER_CMD
Definition grammar.cc:289
POLY_CMD
@ POLY_CMD
Definition grammar.cc:290
RING_CMD
@ RING_CMD
Definition grammar.cc:282
TEST_OPT_DEBUG
#define TEST_OPT_DEBUG
Definition options.h:110
currRing
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
rIncRefCnt
static ring rIncRefCnt(ring r)
Definition ring.h:849
s_readint
int s_readint(s_buff F)
Definition s_buff.cc:113
M
#define M
Definition sirandom.c:25
ssiReadMatrix
static matrix ssiReadMatrix(ssiInfo *d)
Definition ssiLink.cc:1329
ssiReadIntvec
static intvec * ssiReadIntvec(const ssiInfo *d)
Definition ssiLink.cc:1465
ssiReadRing
static ring ssiReadRing(ssiInfo *d)
Definition ssiLink.cc:868
ssiReadList
static lists ssiReadList(si_link l)
Definition ssiLink.cc:1430
ssiReadInt
int ssiReadInt(const ssiInfo *d)
Definition ssiLink.cc:787
ssiReadString
static char * ssiReadString(const ssiInfo *d)
Definition ssiLink.cc:763
ssiReadBlackbox
static void ssiReadBlackbox(leftv res, si_link l)
Definition ssiLink.cc:1558
ssiReadBigintvec
static bigintmat * ssiReadBigintvec(const ssiInfo *d)
Definition ssiLink.cc:1535
ssiReadIdeal
ideal ssiReadIdeal(ssiInfo *d)
Definition ssiLink.cc:1319
ssiCheckCurrRing
static void ssiCheckCurrRing(const ring r)
Definition ssiLink.cc:125
ssiReadBigintmat
static bigintmat * ssiReadBigintmat(const ssiInfo *d)
Definition ssiLink.cc:1511
ssiReadBigInt
static number ssiReadBigInt(const ssiInfo *d)
Definition ssiLink.cc:844
ssiReadCommand
static command ssiReadCommand(si_link l)
Definition ssiLink.cc:1364
ssiReadIntmat
static intvec * ssiReadIntmat(const ssiInfo *d)
Definition ssiLink.cc:1487
ssiReadNumber
static number ssiReadNumber(ssiInfo *d)
Definition ssiLink.cc:863
ssiReadRingProperties
static void ssiReadRingProperties(si_link l)
Definition ssiLink.cc:1606
ssiSetCurrRing
static BOOLEAN ssiSetCurrRing(const ring r)
Definition ssiLink.cc:80
ssiReadPoly
static poly ssiReadPoly(ssiInfo *d)
Definition ssiLink.cc:1283
ssiReadAttrib
static void ssiReadAttrib(leftv res, si_link l)
Definition ssiLink.cc:1586
ssiReadProc
static procinfov ssiReadProc(const ssiInfo *d)
Definition ssiLink.cc:1410
BIGINT_CMD
@ BIGINT_CMD
Definition tok.h:38
LIST_CMD
@ LIST_CMD
Definition tok.h:118
INTVEC_CMD
@ INTVEC_CMD
Definition tok.h:101
DEF_CMD
@ DEF_CMD
Definition tok.h:58
STRING_CMD
@ STRING_CMD
Definition tok.h:187
INT_CMD
@ INT_CMD
Definition tok.h:96
NONE
#define NONE
Definition tok.h:223
COMMAND
#define COMMAND
Definition tok.h:29

## ssiRead1_S()

leftv ssiRead1_S | ( | char ** | s,
|  | const ring | R )

Definition at line 2383 of file ssiLink.cc.

{
leftv res=(leftv)omAlloc0Bin(sleftv_bin);
int t=0;
t=s_readint_S(s);
switch(t)
{
case 1:res->rtyp=INT_CMD;
res->data=(char *)(long)ssiReadInt_S(s);
break;
case 2:res->rtyp=STRING_CMD;
res->data=(char *)ssiReadString_S(s);
break;
case 3:res->rtyp=NUMBER_CMD;
res->data=(char *)ssiReadNumber_CF_S(s,R->cf);
break;
case 4:res->rtyp=BIGINT_CMD;
res->data=(char *)ssiReadBigInt_S(s);
//Print("bigint\n");
break;
case 15:
case 5:{
//Print("ring %d\n",t);
ring r=ssiReadRing_R_S(s);
if (errorreported||(r==NULL)) return NULL;
res->rtyp=RING_CMD;
res->data=(char*)r;
if (/*(t==15)&&*/
((currRing==NULL)||(!rSamePolyRep(r,currRing))))
{
rChangeCurrRing(r);
}
break;
}
case 6:res->rtyp=POLY_CMD;
res->data=(char*)ssiReadPoly_R_S(s,R);
break;
case 7:res->rtyp=IDEAL_CMD;
res->data=(char*)ssiReadIdeal_R_S(s,R);
break;
case 8:res->rtyp=MATRIX_CMD;
res->data=(char*)ssiReadMatrix_R_S(s,R);
break;
case 9:res->rtyp=VECTOR_CMD;
res->data=(char*)ssiReadPoly_R_S(s,R);
break;
case 10:
case 22:if (t==22) res->rtyp=SMATRIX_CMD;
else res->rtyp=MODUL_CMD;
{
int rk=s_readint_S(s);
ideal M=ssiReadIdeal_R_S(s,R);
M->rank=rk;
res->data=(char*)M;
}
break;
#if 0
case 11:
{
res->rtyp=COMMAND;
res->data=ssiReadCommand(l);
int nok=res->Eval();
if (nok) WerrorS("error in eval");
break;
}
#endif
case 12: /*DEF_CMD*/
{
res->rtyp=0;
res->name=(char *)ssiReadString_S(s);
int nok=res->Eval();
if (nok) WerrorS("error in name lookup");
break;
}
case 13: res->rtyp=PROC_CMD;
res->data=ssiReadProc_S(s);
break;
case 14: res->rtyp=LIST_CMD;
res->data=ssiReadList_S(s,R);
break;
case 16: res->rtyp=NONE; res->data=NULL;
break;
case 17: res->rtyp=INTVEC_CMD;
res->data=ssiReadIntvec_S(s);
break;
case 18: res->rtyp=INTMAT_CMD;
res->data=ssiReadIntmat_S(s);
break;
case 19: res->rtyp=BIGINTMAT_CMD;
res->data=ssiReadBigintmat_S(s);
break;
#if 0
case 20: ssiReadBlackbox(res,l);
break;
case 21: ssiReadAttrib(res,l);
break;
case 23: ssiReadRingProperties(l);
return ssiRead1(l);
break;
#endif
case 24: res->rtyp=BIGINTVEC_CMD;
res->data=ssiReadBigintvec_S(s);
break;
// ------------
case 98: // version
{
int n98_v,n98_m;
BITSET n98_o1,n98_o2;
n98_v=s_readint_S(s);
n98_m=s_readint_S(s);
n98_o1=s_readint_S(s);
n98_o2=s_readint_S(s);
Print("// version ssi-%d, MAX_TOK=%d\n",n98_v,n98_m);
si_opt_1=n98_o1;
si_opt_2=n98_o2;
omFreeBin(res,sleftv_bin);
return ssiRead1_S(s,R);
}
#if 0
case 99: omFreeBin(res,sleftv_bin); ssiClose(l); m2_end(-1);
break; /*to make compiler happy*/
#endif
case 0: res->rtyp=DEF_CMD;
**s='\0'; /* unkown char?*/
break;
default: Werror("not implemented (t:%d)",t);
omFreeBin(res,sleftv_bin);
res=NULL;
break;
}
while((**s!='\0') &&(**s<=' ')) (*s)++;
if (**s>' ') res->next=ssiRead1_S(s,R);
return res;
}
rChangeCurrRing
void rChangeCurrRing(ring r)
Definition polys.cc:16
rSamePolyRep
BOOLEAN rSamePolyRep(ring r1, ring r2)
returns TRUE, if r1 and r2 represents the monomials in the same way FALSE, otherwise this is an analo...
Definition ring.cc:1805
s_readint_S
int s_readint_S(char **s)
Definition s_buff.cc:141
R
#define R
Definition sirandom.c:27
ssiReadMatrix_R_S
static matrix ssiReadMatrix_R_S(char **s, const ring R)
Definition ssiLink.cc:1344
ssiReadBigintvec_S
static bigintmat * ssiReadBigintvec_S(char **s)
Definition ssiLink.cc:1546
ssiReadIntmat_S
static intvec * ssiReadIntmat_S(char **s)
Definition ssiLink.cc:1499
ssiReadBigintmat_S
static bigintmat * ssiReadBigintmat_S(char **s)
Definition ssiLink.cc:1523
ssiRead1_S
leftv ssiRead1_S(char **s, const ring R)
Definition ssiLink.cc:2383
ssiReadBigInt_S
static number ssiReadBigInt_S(char **s)
Definition ssiLink.cc:853
ssiReadString_S
static char * ssiReadString_S(char **s)
Definition ssiLink.cc:775
ssiReadProc_S
static procinfov ssiReadProc_S(char **s)
Definition ssiLink.cc:1420
ssiReadRing_R_S
static ring ssiReadRing_R_S(char **s)
Definition ssiLink.cc:1038
ssiReadNumber_CF_S
static number ssiReadNumber_CF_S(char **s, const coeffs cf)
Definition ssiLink.cc:820
ssiReadIntvec_S
static intvec * ssiReadIntvec_S(char **s)
Definition ssiLink.cc:1476
ssiReadList_S
static lists ssiReadList_S(char **s, const ring R)
Definition ssiLink.cc:1448
ssiReadInt_S
int ssiReadInt_S(char **s)
Definition ssiLink.cc:791
ssiReadPoly_R_S
static poly ssiReadPoly_R_S(char **s, const ring r)
Definition ssiLink.cc:1250
ssiReadIdeal_R_S
static ideal ssiReadIdeal_R_S(char **s, const ring r)
Definition ssiLink.cc:1305

## ssiRead2()

leftv ssiRead2 | ( | si_link | l,
|  | leftv | key )

Definition at line 3488 of file ssiLink.cc.

{
if((strcmp(l->mode,"string")==0)
&&(u->Typ()==STRING_CMD))
{
char *s=(char*)u->Data();
return ssiRead1_S(&s,currRing);
}
return NULL;
}

## ssiReadIdeal()

ideal ssiReadIdeal | ( | ssiInfo * | d | ) |

Definition at line 1319 of file ssiLink.cc.

{
return ssiReadIdeal_R(d,d->r);
}
ssiInfo::r
ring r
Definition s_buff.h:24
ssiReadIdeal_R
static ideal ssiReadIdeal_R(const ssiInfo *d, const ring r)
Definition ssiLink.cc:1292

## ssiReadIdeal_S()

ideal ssiReadIdeal_S | ( | char * | s,
|  | const ring | R )

Definition at line 1324 of file ssiLink.cc.

{
return ssiReadIdeal_R_S(&s,R);
}

## ssiReadInt()

int ssiReadInt | ( | const ssiInfo * | d | ) |

Definition at line 787 of file ssiLink.cc.

{
return s_readint(d->f_read);
}

## ssiReadMatrix_S()

matrix ssiReadMatrix_S | ( | char * | s,
|  | const ring | R )

## ssiReadPoly_S()

poly ssiReadPoly_S | ( | char * | s,
|  | const ring | r )

Definition at line 1288 of file ssiLink.cc.

{
return ssiReadPoly_R_S(&s,r);
}

## ssiReadRing_S()

ring ssiReadRing_S | ( | char * | s | ) |

Definition at line 1168 of file ssiLink.cc.

{
ring r=ssiReadRing_R_S(&s);
// check if such ring already exist as ssiRing*
char name[20];
int nr=0;
idhdl h=NULL;
loop // already defined?
{
snprintf(name,20,"ssiRing%d",nr); nr++;
h=IDROOT->get(name, 0);
if (h==NULL)
{
break;
}
else if ((IDTYP(h)==RING_CMD)
&& (r!=IDRING(h))
&& (rEqual(r,IDRING(h),1)))
{
rDelete(r);
r=rIncRefCnt(IDRING(h));
break;
}
}
if ((h==NULL) && ((currRing==NULL) || (!rEqual(r,currRing,1))))
{
char name[20];
int nr=0;
idhdl hh=NULL;
loop
{
snprintf(name,20,"ssiRing%d",nr); nr++;
hh=IDROOT->get(name, 0);
if (hh==NULL)
{
hh=enterid(name,0,RING_CMD,&IDROOT,FALSE);
break;
}
else if ((IDTYP(hh)==RING_CMD)
&& (rEqual(r,IDRING(hh),1)))
{
break;
}
}
rSetHdl(hh);
}
else
rSetHdl(h);
return r;
}
name
char name(const Variable &v)
Definition factory.h:189
enterid
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition ipid.cc:279
IDROOT
#define IDROOT
Definition ipid.h:19
IDRING
#define IDRING(a)
Definition ipid.h:127
IDTYP
#define IDTYP(a)
Definition ipid.h:119
rSetHdl
void rSetHdl(idhdl h)
Definition ipshell.cc:5129
rDelete
void rDelete(ring r)
unconditionally deletes fields in r
Definition ring.cc:454
rEqual
BOOLEAN rEqual(ring r1, ring r2, BOOLEAN qr)
returns TRUE, if r1 equals r2 FALSE, otherwise Equality is determined componentwise,...
Definition ring.cc:1752

## ssiReservePort()

int ssiReservePort | ( | int | clients | ) |

Definition at line 3158 of file ssiLink.cc.

{
if (ssiReserved_P!=0)
{
WerrorS("ERROR already a reserved port requested");
return 0;
}
int portno;
ssiReserved_sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(ssiReserved_sockfd < 0)
{
WerrorS("ERROR opening socket");
return 0;
}
memset((char *) &ssiResverd_serv_addr,0, sizeof(ssiResverd_serv_addr));
portno = 1025;
ssiResverd_serv_addr.sin_family = AF_INET;
ssiResverd_serv_addr.sin_addr.s_addr = INADDR_ANY;
do
{
portno++;
ssiResverd_serv_addr.sin_port = htons(portno);
if(portno > 50000)
{
WerrorS("ERROR on binding (no free port available?)");
return 0;
}
}
while(bind(ssiReserved_sockfd, (struct sockaddr *) &ssiResverd_serv_addr, sizeof(ssiResverd_serv_addr)) < 0);
ssiReserved_P=portno;
listen(ssiReserved_sockfd,clients);
ssiReserved_Clients=clients;
return portno;
}
ssiResverd_serv_addr
STATIC_VAR struct sockaddr_in ssiResverd_serv_addr
Definition ssiLink.cc:3156

## ssiWrite()

BOOLEAN ssiWrite | ( | si_link | l,
|  | leftv | v )

Definition at line 2537 of file ssiLink.cc.

{
if(SI_LINK_W_OPEN_P(l)==0)
if (slOpen(l,SI_LINK_OPEN|SI_LINK_WRITE,NULL)) return TRUE;
if (strcmp(l->mode,"string")==0) return TRUE;
ssiInfo *d = (ssiInfo *)l->data;
d->level++;
//FILE *fich=d->f;
while (data!=NULL)
{
int tt=data->Typ();
void *dd=data->Data();
attr *aa=data->Attribute();
if ((aa!=NULL) && ((*aa)!=NULL)) // n user attributes
{
attr a=*aa;
int n=0;
while(a!=NULL) { n++; a=a->next;}
fprintf(d->f_write,"21 %d %d ",data->flag,n);
}
else if (data->flag!=0) // only "flag" attributes
{
fprintf(d->f_write,"21 %d 0 ",data->flag);
}
if ((dd==NULL) && (data->name!=NULL) && (tt==0)) tt=DEF_CMD;
// return pure undefined names as def
switch(tt /*data->Typ()*/)
{
case 0: /*error*/
case NONE/* nothing*/:fputs("16 ",d->f_write);
break;
case STRING_CMD: fputs("2 ",d->f_write);
ssiWriteString(d,(char *)dd);
break;
case INT_CMD: fputs("1 ",d->f_write);
ssiWriteInt(d,(int)(long)dd);
break;
case BIGINT_CMD:fputs("4 ",d->f_write);
ssiWriteBigInt(d,(number)dd);
break;
case NUMBER_CMD:
if (d->r!=currRing)
{
fputs("15 ",d->f_write);
ssiWriteRing(d,currRing);
if (d->level<=1) fputc('\n',d->f_write);
}
fputs("3 ",d->f_write);
ssiWriteNumber(d,(number)dd);
break;
case RING_CMD:fputs("5 ",d->f_write);
ssiWriteRing(d,(ring)dd);
break;
case BUCKET_CMD:
{
sBucket_pt b=(sBucket_pt)dd;
if (d->r!=sBucketGetRing(b))
{
fputs("15 ",d->f_write);
ssiWriteRing(d,sBucketGetRing(b));
if (d->level<=1) fputc('\n',d->f_write);
}
fputs("6 ",d->f_write);
ssiWritePoly(d,sBucketPeek(b));
break;
}
case POLY_CMD:
case VECTOR_CMD:
if (d->r!=currRing)
{
fputs("15 ",d->f_write);
ssiWriteRing(d,currRing);
if (d->level<=1) fputc('\n',d->f_write);
}
if(tt==POLY_CMD) fputs("6 ",d->f_write);
else fputs("9 ",d->f_write);
ssiWritePoly(d,(poly)dd);
break;
case IDEAL_CMD:
case MODUL_CMD:
case MATRIX_CMD:
case SMATRIX_CMD:
if (d->r!=currRing)
{
fputs("15 ",d->f_write);
ssiWriteRing(d,currRing);
if (d->level<=1) fputc('\n',d->f_write);
}
if(tt==IDEAL_CMD) fputs("7 ",d->f_write);
else if(tt==MATRIX_CMD) fputs("8 ",d->f_write);
else /* tt==MODUL_CMD, SMATRIX_CMD*/
{
ideal M=(ideal)dd;
if (tt==MODUL_CMD)
fprintf(d->f_write,"10 %d ",(int)M->rank);
else /*(tt==SMATRIX_CMD)*/
fprintf(d->f_write,"22 %d ",(int)M->rank);
}
ssiWriteIdeal(d,tt,(ideal)dd);
break;
case COMMAND:
fputs("11 ",d->f_write);
ssiWriteCommand(l,(command)dd);
break;
case DEF_CMD: /* not evaluated stuff in quotes */
fputs("12 ",d->f_write);
ssiWriteString(d,data->Name());
break;
case PROC_CMD:
fputs("13 ",d->f_write);
ssiWriteProc(d,(procinfov)dd);
break;
case LIST_CMD:
fputs("14 ",d->f_write);
ssiWriteList(l,(lists)dd);
break;
case INTVEC_CMD:
fputs("17 ",d->f_write);
ssiWriteIntvec(d,(intvec *)dd);
break;
case INTMAT_CMD:
fputs("18 ",d->f_write);
ssiWriteIntmat(d,(intvec *)dd);
break;
case BIGINTMAT_CMD:
fputs("19 ",d->f_write);
ssiWriteBigintmat(d,(bigintmat *)dd);
break;
case BIGINTVEC_CMD:
fputs("24 ",d->f_write);
ssiWriteBigintvec(d,(bigintmat *)dd);
break;
default:
if (tt>MAX_TOK)
{
blackbox *b=getBlackboxStuff(tt);
fputs("20 ",d->f_write);
b->blackbox_serialize(b,dd,l);
}
else
{
Werror("not implemented (t:%d, rtyp:%d)",tt, data->rtyp);
d->level=0;
return TRUE;
}
break;
}
if (d->level<=1) { fputc('\n',d->f_write); fflush(d->f_write); }
data=data->next;
}
d->level--;
return FALSE;
}
attr
sattr * attr
Definition attrib.h:16
getBlackboxStuff
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition blackbox.cc:17
b
CanonicalForm b
Definition cfModGcd.cc:4111
bigintmat
Matrices of numbers.
Definition bigintmat.h:51
intvec
Definition intvec.h:24
sattr::next
attr next
Definition attrib.h:26
BUCKET_CMD
@ BUCKET_CMD
Definition grammar.cc:284
command
ip_command * command
Definition ipid.h:23
lists
slists * lists
Definition mpr_numeric.h:146
sBucketPeek
poly sBucketPeek(sBucket_pt b)
Definition sbuckets.cc:455
sBucketGetRing
ring sBucketGetRing(const sBucket_pt bucket)
Returns bucket ring.
Definition sbuckets.cc:46
sBucket_pt
sBucket * sBucket_pt
Definition sbuckets.h:16
slOpen
BOOLEAN slOpen(si_link l, short flag, leftv h)
Definition silink.cc:194
ssiWriteString
static void ssiWriteString(const ssiInfo *d, const char *s)
Definition ssiLink.cc:165
ssiWriteIntvec
static void ssiWriteIntvec(const ssiInfo *d, intvec *v)
Definition ssiLink.cc:688
ssiWriteList
static void ssiWriteList(si_link l, lists dd)
Definition ssiLink.cc:667
ssiWriteIntmat
static void ssiWriteIntmat(const ssiInfo *d, intvec *v)
Definition ssiLink.cc:706
ssiWriteRing
static void ssiWriteRing(ssiInfo *d, const ring r)
Definition ssiLink.cc:488
ssiWriteProc
static void ssiWriteProc(const ssiInfo *d, procinfov p)
Definition ssiLink.cc:648
ssiWriteIdeal
void ssiWriteIdeal(const ssiInfo *d, int typ, const ideal I)
Definition ssiLink.cc:612
ssiWriteNumber
static void ssiWriteNumber(const ssiInfo *d, const number n)
Definition ssiLink.cc:239
ssiWriteCommand
static void ssiWriteCommand(si_link l, command D)
Definition ssiLink.cc:635
ssiWriteBigintmat
static void ssiWriteBigintmat(const ssiInfo *d, bigintmat *v)
Definition ssiLink.cc:725
ssiWriteBigintvec
static void ssiWriteBigintvec(const ssiInfo *d, bigintmat *v)
Definition ssiLink.cc:744
ssiWriteInt
void ssiWriteInt(const ssiInfo *d, const int i)
Definition ssiLink.cc:156
ssiWriteBigInt
static void ssiWriteBigInt(const ssiInfo *d, const number n)
Definition ssiLink.cc:174
ssiWritePoly
static void ssiWritePoly(const ssiInfo *d, poly p)
Definition ssiLink.cc:555
procinfov
procinfo * procinfov
Definition structs.h:56

## ssiWrite2()

BOOLEAN ssiWrite2 | ( | si_link | l,
|  | leftv | res,
|  | leftv | v )

Definition at line 3475 of file ssiLink.cc.

{
if((strcmp(l->mode,"string")==0)
&&(u->Typ()==STRING_CMD))
{
StringSetS("");
ssiWrite_S(u, currRing);
res->data=(void*)StringEndS();
res->rtyp=STRING_CMD;
return res->data==NULL;
}
return TRUE;
}
StringSetS
void StringSetS(const char *st)
Definition reporter.cc:128
StringEndS
char * StringEndS()
Definition reporter.cc:151
ssiWrite_S
void ssiWrite_S(leftv data, const ring R)
Definition ssiLink.cc:2691

## ssiWrite_S()

void ssiWrite_S | ( | leftv | v,
|  | const ring | R )

Definition at line 2691 of file ssiLink.cc.

{
while(data!=NULL)
{
int tt=data->Typ();
void *dd=data->Data();
switch(tt /*data->Typ()*/)
{
case 0: /*error*/
case NONE/* nothing*/:StringAppendS("16 ");
break;
case INT_CMD: StringAppendS("1 ");
ssiWriteInt_S((int)(long)dd);
break;
case STRING_CMD: StringAppendS("2 ");
ssiWriteString_S((char *)dd);
break;
case BIGINT_CMD:StringAppendS("4 ");
ssiWriteBigInt_S((number)dd);
break;
case NUMBER_CMD:
StringAppendS("3 ");
ssiWriteNumber_CF_S((number)dd,R->cf);
break;
case RING_CMD:StringAppendS("5 ");
ssiWriteRing_R_S((ring)dd);
break;
case BUCKET_CMD:
{
sBucket_pt b=(sBucket_pt)dd;
StringAppendS("6 ");
ssiWritePoly_R_S(sBucketPeek(b),R);
break;
}
case POLY_CMD:
case VECTOR_CMD:
if(tt==POLY_CMD) StringAppendS("6 ");
else StringAppendS("9 ");
ssiWritePoly_R_S((poly)dd,R);
break;
case IDEAL_CMD:
case MODUL_CMD:
case MATRIX_CMD:
case SMATRIX_CMD:
if(tt==IDEAL_CMD) StringAppendS("7 ");
else if(tt==MATRIX_CMD) StringAppendS("8 ");
else /* tt==MODUL_CMD, SMATRIX_CMD*/
{
ideal M=(ideal)dd;
if (tt==MODUL_CMD)
{
StringAppendS("10 ");StringAppend("%d ",(int)M->rank);
}
else /*(tt==SMATRIX_CMD)*/
{
StringAppendS("22 ");StringAppend("%d ",(int)M->rank);
}
}
ssiWriteIdeal_R_S(tt,(ideal)dd,R);
break;
#if 0
case COMMAND:
fputs("11 ",d->f_write);
ssiWriteCommand(l,(command)dd);
break;
#endif
case DEF_CMD: /* not evaluated stuff in quotes */
StringAppendS("12 ");
ssiWriteString_S(data->Name());
break;
case PROC_CMD:
StringAppendS("13 ");
ssiWriteProc_S((procinfov)dd);
break;
case LIST_CMD:
StringAppendS("14 ");
ssiWriteList_S((lists)dd,R);
break;
case INTVEC_CMD:
StringAppendS("17 ");
ssiWriteIntvec_S((intvec *)dd);
break;
case INTMAT_CMD:
StringAppendS("18 ");
ssiWriteIntmat_S((intvec *)dd);
break;
case BIGINTMAT_CMD:
StringAppendS("19 ");
ssiWriteBigintmat_S((bigintmat *)dd);
break;
case BIGINTVEC_CMD:
StringAppendS("24 ");
ssiWriteBigintvec_S((bigintmat *)dd);
break;
default:
#if 0
if (tt>MAX_TOK)
{
blackbox *b=getBlackboxStuff(tt);
fputs("20 ",d->f_write);
b->blackbox_serialize(b,dd,l);
}
else
#endif
{
Werror("not implemented (t:%d, rtyp:%d)",tt, data->rtyp);
return;
}
break;
}
data=data->next;
}
}
StringAppend
#define StringAppend
Definition emacs.cc:79
StringAppendS
void StringAppendS(const char *st)
Definition reporter.cc:107
ssiWriteBigInt_S
static void ssiWriteBigInt_S(const number n)
Definition ssiLink.cc:178
ssiWriteRing_R_S
static void ssiWriteRing_R_S(ring r)
Definition ssiLink.cc:375
ssiWriteIntmat_S
static void ssiWriteIntmat_S(intvec *v)
Definition ssiLink.cc:715
ssiWriteNumber_CF_S
static void ssiWriteNumber_CF_S(const number n, const coeffs cf)
Definition ssiLink.cc:211
ssiWriteIdeal_R_S
static void ssiWriteIdeal_R_S(int typ, const ideal I, const ring R)
Definition ssiLink.cc:589
ssiWriteInt_S
void ssiWriteInt_S(const int i)
Definition ssiLink.cc:160
ssiWriteString_S
static void ssiWriteString_S(const char *s)
Definition ssiLink.cc:169
ssiWriteIntvec_S
static void ssiWriteIntvec_S(intvec *v)
Definition ssiLink.cc:697
ssiWritePoly_R_S
static void ssiWritePoly_R_S(poly p, const ring r)
Definition ssiLink.cc:537
ssiWriteBigintvec_S
static void ssiWriteBigintvec_S(bigintmat *v)
Definition ssiLink.cc:753
ssiWriteList_S
static void ssiWriteList_S(lists dd, const ring R)
Definition ssiLink.cc:678
ssiWriteProc_S
static void ssiWriteProc_S(procinfov p)
Definition ssiLink.cc:657
ssiWriteBigintmat_S
static void ssiWriteBigintmat_S(bigintmat *v)
Definition ssiLink.cc:734

## ssiWriteIdeal()

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

Definition at line 612 of file ssiLink.cc.

{
ssiWriteIdeal_R(d,typ,I,d->r);
}
ssiWriteIdeal_R
static void ssiWriteIdeal_R(const ssiInfo *d, int typ, const ideal I, const ring r)
Definition ssiLink.cc:566

## ssiWriteIdeal_S()

char * ssiWriteIdeal_S | ( | const ideal | I,
|  | const ring | R )

Definition at line 616 of file ssiLink.cc.

{
StringSetS("");
ssiWriteIdeal_R_S(IDEAL_CMD,I,R);
return StringEndS();
}

## ssiWriteInt()

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

Definition at line 156 of file ssiLink.cc.

{
fprintf(d->f_write,"%d ",i);
}

## ssiWriteMatrix_S()

char * ssiWriteMatrix_S | ( | const matrix | M,
|  | const ring | R )

Definition at line 622 of file ssiLink.cc.

{
StringSetS("");
ssiWriteIdeal_R_S(MATRIX_CMD,(ideal)M,R);
return StringEndS();
}

## ssiWriteModule_S()

char * ssiWriteModule_S | ( | const ideal | M,
|  | const ring | R )

Definition at line 628 of file ssiLink.cc.

{
StringSetS("");
ssiWriteIdeal_R_S(MODUL_CMD,M,R);
return StringEndS();
}

## ssiWritePoly_S()

char * ssiWritePoly_S | ( | poly | p,
|  | const ring | r )

Definition at line 560 of file ssiLink.cc.

{
StringSetS("");
ssiWritePoly_R_S(p,r);
return StringEndS();
}
p
int p
Definition cfModGcd.cc:4086

## ssiWriteRing_S()

char * ssiWriteRing_S | ( | const ring | r | ) |

Definition at line 514 of file ssiLink.cc.

{
StringSetS("");
ssiWriteRing_R_S(r);
return StringEndS();
}