My Project
Loading...
Searching...
No Matches
Macros | Functions | Variables
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, poly p, const ring r)
 
static void ssiWritePoly_R_S (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 poly ssiReadPoly_R_S (char **s, 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)
 
void ssiWriteInt_S (const int i)
 
static void ssiWriteString (const ssiInfo *d, const char *s)
 
static void ssiWriteString_S (const char *s)
 
static void ssiWriteBigInt (const ssiInfo *d, const number n)
 
static void ssiWriteBigInt_S (const number n)
 
static void ssiWriteNumber_CF (const ssiInfo *d, const number n, const coeffs cf)
 
static void ssiWriteNumber_CF_S (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, poly p)
 
charssiWritePoly_S (poly p, const ring r)
 
static void ssiWriteIdeal_R_S (int typ, const ideal I, const ring R)
 
void ssiWriteIdeal (const ssiInfo *d, int typ, const ideal I)
 
charssiWriteIdeal_S (const ideal I, const ring R)
 
charssiWriteMatrix_S (const matrix M, const ring R)
 
charssiWriteModule_S (const ideal M, const ring R)
 
static void ssiWriteCommand (si_link l, command D)
 
static void ssiWriteProc (const ssiInfo *d, procinfov p)
 
static void ssiWriteProc_S (procinfov p)
 
static void ssiWriteList (si_link l, lists dd)
 
static void ssiWriteList_S (lists dd, const ring R)
 
static void ssiWriteIntvec (const ssiInfo *d, intvec *v)
 
static void ssiWriteIntvec_S (intvec *v)
 
static void ssiWriteIntmat (const ssiInfo *d, intvec *v)
 
static void ssiWriteIntmat_S (intvec *v)
 
static void ssiWriteBigintmat (const ssiInfo *d, bigintmat *v)
 
static void ssiWriteBigintmat_S (bigintmat *v)
 
static void ssiWriteBigintvec (const ssiInfo *d, bigintmat *v)
 
static void ssiWriteBigintvec_S (bigintmat *v)
 
static charssiReadString (const ssiInfo *d)
 
static charssiReadString_S (char **s)
 
int ssiReadInt (const ssiInfo *d)
 
int ssiReadInt_S (char **s)
 
static number ssiReadNumber_CF (const ssiInfo *d, const coeffs cf)
 
static number ssiReadNumber_CF_S (char **s, const coeffs cf)
 
static number ssiReadBigInt (const ssiInfo *d)
 
static number ssiReadBigInt_S (char **s)
 
static number ssiReadNumber (ssiInfo *d)
 
static ring ssiReadRing (ssiInfo *d)
 
static poly ssiReadPoly (ssiInfo *d)
 
poly ssiReadPoly_S (char *s, const ring r)
 
static ideal ssiReadIdeal_R_S (char **s, const ring r)
 
ideal ssiReadIdeal (ssiInfo *d)
 
ideal ssiReadIdeal_S (char *s, const ring R)
 
static matrix ssiReadMatrix (ssiInfo *d)
 
static matrix ssiReadMatrix_R_S (char **s, const ring R)
 
matrix ssiReadMatrix_R_S (char *s, const ring R)
 
static command ssiReadCommand (si_link l)
 
static procinfov ssiReadProc (const ssiInfo *d)
 
static procinfov ssiReadProc_S (char **s)
 
static lists ssiReadList (si_link l)
 
static lists ssiReadList_S (char **s, const ring R)
 
static intvecssiReadIntvec (const ssiInfo *d)
 
static intvecssiReadIntvec_S (char **s)
 
static intvecssiReadIntmat (const ssiInfo *d)
 
static intvecssiReadIntmat_S (char **s)
 
static bigintmatssiReadBigintmat (const ssiInfo *d)
 
static bigintmatssiReadBigintmat_S (char **s)
 
static bigintmatssiReadBigintvec (const ssiInfo *d)
 
static bigintmatssiReadBigintvec_S (char **s)
 
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)
 
BOOLEAN ssiClose (si_link l)
 
leftv ssiRead1 (si_link l)
 
leftv ssiRead1_S (char **s, const ring R)
 
static BOOLEAN ssiSetRing (si_link l, ring r, BOOLEAN send)
 
BOOLEAN ssiWrite (si_link l, leftv data)
 
void ssiWrite_S (leftv data, const ring R)
 
BOOLEAN ssiGetDump (si_link l)
 
BOOLEAN ssiDump (si_link l)
 
si_link_extension slInitSsiExtension (si_link_extension s)
 
const charslStatusSsi (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 ()
 
BOOLEAN ssiWrite2 (si_link l, leftv res, leftv u)
 
leftv ssiRead2 (si_link l, leftv u)
 

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

3014{
3015 int type_id = IDTYP(h);
3016
3017 // C-proc not to be dumped, also LIB-proc not
3018 if (type_id == PROC_CMD)
3019 {
3020 if (IDPROC(h)->language == LANG_C) return FALSE;
3021 if (IDPROC(h)->libname != NULL) return FALSE;
3022 }
3023 // do not dump links
3024 if (type_id == LINK_CMD) return FALSE;
3025
3026 // do not dump ssi internal rings: ssiRing*
3027 if ((type_id == RING_CMD) && (strncmp(IDID(h),"ssiRing",7)==0))
3028 return FALSE;
3029
3030 // do not dump default cring:
3031 if (type_id == CRING_CMD)
3032 {
3033 if (strcmp(IDID(h),"ZZ")==0) return FALSE;
3034 if (strcmp(IDID(h),"QQ")==0) return FALSE;
3035 #ifdef SINGULAR_4_2
3036 if (strcmp(IDID(h),"AE")==0) return FALSE;
3037 if (strcmp(IDID(h),"QAE")==0) return FALSE;
3038 #endif
3039 }
3040
3041 command D=(command)omAlloc0(sizeof(*D));
3042 sleftv tmp;
3043 memset(&tmp,0,sizeof(tmp));
3044 tmp.rtyp=COMMAND;
3045 tmp.data=D;
3046
3047 if (type_id == PACKAGE_CMD)
3048 {
3049 // do not dump Top, Standard
3050 if ((strcmp(IDID(h), "Top") == 0)
3051 || (strcmp(IDID(h), "Standard") == 0))
3052 {
3053 omFreeSize(D,sizeof(*D));
3054 return FALSE;
3055 }
3056 package p=(package)IDDATA(h);
3057 // dump Singular-packages as LIB("...");
3058 if (p->language==LANG_SINGULAR)
3059 {
3060 D->op=LOAD_CMD;
3061 D->argc=2;
3062 D->arg1.rtyp=STRING_CMD;
3063 D->arg1.data=p->libname;
3064 D->arg2.rtyp=STRING_CMD;
3065 D->arg2.data=(char*)"with";
3066 ssiWrite(l,&tmp);
3067 omFreeSize(D,sizeof(*D));
3068 return FALSE;
3069 }
3070 // dump Singular-packages as load("...");
3071 else if (p->language==LANG_C)
3072 {
3073 D->op=LOAD_CMD;
3074 D->argc=1;
3075 D->arg1.rtyp=STRING_CMD;
3076 D->arg1.data=p->libname;
3077 ssiWrite(l,&tmp);
3078 omFreeSize(D,sizeof(*D));
3079 return FALSE;
3080 }
3081 }
3082
3083 // put type and name
3084 //Print("generic dump:%s,%s\n",IDID(h),Tok2Cmdname(IDTYP(h)));
3085 D->op='=';
3086 D->argc=2;
3087 D->arg1.rtyp=DEF_CMD;
3088 D->arg1.name=IDID(h);
3089 D->arg2.rtyp=IDTYP(h);
3090 D->arg2.data=IDDATA(h);
3091 ssiWrite(l,&tmp);
3092 omFreeSize(D,sizeof(*D));
3093 return FALSE;
3094}
#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
#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
@ STRING_CMD
Definition tok.h:187
@ LOAD_CMD
Definition tok.h:119
#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 2969 of file ssiLink.cc.

2970{
2971
2972#if 0
2973 pid_t kidpid;
2974 int status;
2975 loop
2976 {
2978 if (kidpid==-1)
2979 {
2980 /* continue on interruption (EINTR): */
2981 if (errno == EINTR) continue;
2982 /* break on anything else (EINVAL or ECHILD according to manpage): */
2983 break;
2984 }
2985 else if (kidpid==0) break; /* no more children to process, so break */
2986
2987 //printf("Child %ld terminated\n", kidpid);
2989 while((hh!=NULL)&&(ssiToBeClosed_inactive))
2990 {
2991 if((hh->l!=NULL) && (hh->l->m->Open==ssiOpen))
2992 {
2993 ssiInfo *d = (ssiInfo *)hh->l->data;
2994 if(d->pid==kidpid)
2995 {
2997 {
2999 slClose(hh->l);
3001 break;
3002 }
3003 else break;
3004 }
3005 else hh=(link_list)hh->next;
3006 }
3007 else hh=(link_list)hh->next;
3008 }
3009 }
3010#endif
3011}
#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 3159 of file ssiLink.cc.

3160{
3162 while(hh!=NULL)
3163 {
3164 if ((hh->l->m!=NULL)
3165 && (hh->l->m->Open==ssiOpen)
3166 && SI_LINK_OPEN_P(hh->l)
3167 && (strcmp(hh->l->mode, "fork")==0))
3168 {
3170 ssiInfo *d = (ssiInfo *)hh->l->data;
3171 if (d->f_read!=NULL) { s_close(d->f_read);d->f_read=NULL;}
3172 if (d->f_write!=NULL) { fclose(d->f_write); d->f_write=NULL; }
3173 }
3174 hh=(link_list)hh->next;
3175 }
3177}
int s_close(s_buff &F)
Definition s_buff.cc:46

◆ slInitSsiExtension()

si_link_extension slInitSsiExtension ( si_link_extension  s)

Definition at line 2512 of file ssiLink.cc.

2513{
2514 s->Open=ssiOpen;
2515 s->Close=ssiClose;
2516 s->Kill=ssiClose;
2517 s->Read=ssiRead1;
2518 s->Read2=ssiRead2;
2519 s->Write=ssiWrite;
2520 s->Dump=ssiDump;
2521 s->GetDump=ssiGetDump;
2522
2523 s->Status=slStatusSsi;
2524 s->SetRing=ssiSetRing;
2525 s->type="ssi";
2526 return s;
2527}
const CanonicalForm int s
Definition facAbsFact.cc:51

◆ slStatusSsi()

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

Definition at line 2529 of file ssiLink.cc.

2530{
2531 if (strcmp(l->mode,"string")==0)
2532 {
2533 if (strcmp(request, "read") == 0)
2534 {
2535 if (SI_LINK_R_OPEN_P(l)) return "yes";
2536 else return "no";
2537 }
2538 if (strcmp(request, "write") == 0)
2539 {
2540 if (SI_LINK_W_OPEN_P(l)) return "yes";
2541 else return "no";
2542 }
2543 return "inavlid";
2544 }
2545 ssiInfo *d=(ssiInfo*)l->data;
2546 if (d==NULL)
2547 return "no";
2548 if (((strcmp(l->mode,"fork")==0)
2549 ||(strcmp(l->mode,"tcp")==0)
2550 ||(strcmp(l->mode,"connect")==0))
2551 && (strcmp(request, "read") == 0))
2552 {
2553 if (s_isready(d->f_read)) return "ready";
2554#if defined(HAVE_POLL)
2555 pollfd pfd;
2556 loop
2557 {
2558 /* Don't block. Return socket status immediately. */
2559 pfd.fd=d->fd_read;
2560 pfd.events=POLLIN;
2561 //Print("test fd %d\n",d->fd_read);
2562 /* check with select: chars waiting: no -> not ready */
2563 switch (si_poll(&pfd,1,0))
2564 {
2565 case 0: /* not ready */ return "not ready";
2566 case -1: /*error*/ return "error";
2567 case 1: /*ready ? */ break;
2568 }
2569#else
2570 fd_set mask;
2571 struct timeval wt;
2572 if (FD_SETSIZE<=d->fd_read)
2573 {
2574 Werror("file descriptor number too high (%d)",d->fd_read);
2575 return "error";
2576 }
2577
2578 loop
2579 {
2580 /* Don't block. Return socket status immediately. */
2581 wt.tv_sec = 0;
2582 wt.tv_usec = 0;
2583
2584 FD_ZERO(&mask);
2585 FD_SET(d->fd_read, &mask);
2586 //Print("test fd %d\n",d->fd_read);
2587 /* check with select: chars waiting: no -> not ready */
2588 switch (si_select(d->fd_read+1, &mask, NULL, NULL, &wt))
2589 {
2590 case 0: /* not ready */ return "not ready";
2591 case -1: /*error*/ return "error";
2592 case 1: /*ready ? */ break;
2593 }
2594#endif
2595 /* yes: read 1 char*/
2596 /* if \n, check again with select else ungetc(c), ready*/
2597 int c=s_getc(d->f_read);
2598 //Print("try c=%d\n",c);
2599 if (c== -1) return "eof"; /* eof or error */
2600 else if (isdigit(c))
2601 { s_ungetc(c,d->f_read); return "ready"; }
2602 else if (c>' ')
2603 {
2604 Werror("unknown char in ssiLink(%d)",c);
2605 return "error";
2606 }
2607 /* else: next char */
2608 }
2609 }
2610 else if (strcmp(request, "read") == 0)
2611 {
2612 if (SI_LINK_R_OPEN_P(l) && (!s_iseof(d->f_read)) && (s_isready(d->f_read))) return "ready";
2613 else return "not ready";
2614 }
2615 else if (strcmp(request, "write") == 0)
2616 {
2617 if (SI_LINK_W_OPEN_P(l)) return "ready";
2618 else return "not ready";
2619 }
2620 else return "unknown status request";
2621}
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:352
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 2623 of file ssiLink.cc.

2624{
2625// input: L: a list with links of type
2626// ssi-connect, ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch.
2627// Note: Not every entry in L must be set.
2628// timeout: timeout for select in milli-seconds
2629// or -1 for infinity
2630// or 0 for polling
2631// returns: ERROR (via Werror): L has wrong elements or link not open
2632// -2: error in L
2633// -1: the read state of all links is eof
2634// 0: timeout (or polling): none ready,
2635// i>0: (at least) L[i] is ready
2636#if defined(HAVE_POLL) && !defined(__APPLE__)
2637// fd is restricted on OsX by ulimit "file descriptors" (256)
2638 si_link l;
2639 ssiInfo *d=NULL;
2640 int d_fd;
2641 int s;
2642 int nfd=L->nr+1;
2643 pollfd *pfd=(pollfd*)omAlloc0(nfd*sizeof(pollfd));
2644 for(int i=L->nr; i>=0; i--)
2645 {
2646 pfd[i].fd=-1;
2647 if (L->m[i].Typ()!=DEF_CMD)
2648 {
2649 if (L->m[i].Typ()!=LINK_CMD)
2650 { WerrorS("all elements must be of type link"); return -2;}
2651 l=(si_link)L->m[i].Data();
2652 if(SI_LINK_OPEN_P(l)==0)
2653 { WerrorS("all links must be open"); return -2;}
2654 if (((strcmp(l->m->type,"ssi")!=0) && (strcmp(l->m->type,"MPtcp")!=0))
2655 || ((strcmp(l->mode,"fork")!=0) && (strcmp(l->mode,"tcp")!=0)
2656 && (strcmp(l->mode,"launch")!=0) && (strcmp(l->mode,"connect")!=0)))
2657 {
2658 WerrorS("all links must be of type ssi:fork, ssi:tcp, ssi:connect");
2659 return -2;
2660 }
2661 if (strcmp(l->m->type,"ssi")==0)
2662 {
2663 d=(ssiInfo*)l->data;
2664 d_fd=d->fd_read;
2665 if (!s_isready(d->f_read))
2666 {
2667 pfd[i].fd=d_fd;
2668 pfd[i].events=POLLIN;
2669 }
2670 else
2671 {
2672 return i+1;
2673 }
2674 }
2675 else
2676 {
2677 Werror("wrong link type >>%s<<",l->m->type);
2678 return -2;
2679 }
2680 }
2681 else if (ignore!=NULL)
2682 {
2683 ignore[i]=TRUE; // not a link
2684 }
2685 }
2687 if (s==-1)
2688 {
2689 Werror("error in poll call (errno:%d)",errno);
2690 return -2; /*error*/
2691 }
2692 if(s==0)
2693 {
2694 return 0; /*timeout*/
2695 }
2696 for(int i=L->nr; i>=0; i--)
2697 {
2698 if ((L->m[i].rtyp==LINK_CMD)
2699 && ((ignore==NULL)||(ignore[i]==FALSE)))
2700 {
2701 // the link type is ssi, that's already tested
2702 l=(si_link)L->m[i].Data();
2703 d=(ssiInfo*)l->data;
2704 d_fd=d->fd_read;
2705 if (pfd[i].fd==d_fd)
2706 {
2707 if (pfd[i].revents &POLLIN)
2708 {
2709 omFree(pfd);
2710 return i+1;
2711 }
2712 }
2713 }
2714 }
2715 // no ready
2716 return 0;
2717#else
2718 // fd is restricted to <=1024
2719 si_link l;
2720 ssiInfo *d=NULL;
2721 int d_fd;
2722 fd_set fdmask;
2723 FD_ZERO(&fdmask);
2724 int max_fd=0; /* 1 + max fd in fd_set */
2725
2726 /* timeout */
2727 struct timeval wt;
2728 struct timeval *wt_ptr=&wt;
2729 int startingtime = getRTimer()/TIMER_RESOLUTION; // in seconds
2730 if (timeout== -1)
2731 {
2732 wt_ptr=NULL;
2733 }
2734 else
2735 {
2736 wt.tv_sec = timeout / 1000;
2737 wt.tv_usec = (timeout % 1000)*1000;
2738 }
2739
2740 /* auxiliary variables */
2741 int i;
2742 int j;
2743 int k;
2744 int s;
2745 char fdmaskempty;
2746
2747 /* check the links and fill in fdmask */
2748 /* check ssi links for ungetc_buf */
2749 for(i=L->nr; i>=0; i--)
2750 {
2751 if (L->m[i].Typ()!=DEF_CMD)
2752 {
2753 if (L->m[i].Typ()!=LINK_CMD)
2754 { WerrorS("all elements must be of type link"); return -2;}
2755 l=(si_link)L->m[i].Data();
2756 if(SI_LINK_OPEN_P(l)==0)
2757 { WerrorS("all links must be open"); return -2;}
2758 if (((strcmp(l->m->type,"ssi")!=0) && (strcmp(l->m->type,"MPtcp")!=0))
2759 || ((strcmp(l->mode,"fork")!=0) && (strcmp(l->mode,"tcp")!=0)
2760 && (strcmp(l->mode,"launch")!=0) && (strcmp(l->mode,"connect")!=0)))
2761 {
2762 WerrorS("all links must be of type ssi:fork, ssi:tcp, ssi:connect");
2763 return -2;
2764 }
2765 if (strcmp(l->m->type,"ssi")==0)
2766 {
2767 d=(ssiInfo*)l->data;
2768 d_fd=d->fd_read;
2769 if (!s_isready(d->f_read))
2770 {
2771 if ((ignore==NULL) || (ignore[i]==FALSE))
2772 {
2773 FD_SET(d_fd, &fdmask);
2774 if (d_fd > max_fd) max_fd=d_fd;
2775 }
2776 }
2777 else
2778 return i+1;
2779 }
2780 else
2781 {
2782 Werror("wrong link type >>%s<<",l->m->type);
2783 return -2;
2784 }
2785 }
2786 }
2787 max_fd++;
2788 if (FD_SETSIZE<=max_fd)
2789 {
2790 Werror("file descriptor number too high (%d)",max_fd);
2791 return -2;
2792 }
2793
2794 /* check with select: chars waiting: no -> not ready */
2796 if (s==-1)
2797 {
2798 Werror("error in select call (errno:%d)",errno);
2799 return -2; /*error*/
2800 }
2801 if (s==0)
2802 {
2803 return 0; /*poll: not ready */
2804 }
2805 else /* s>0, at least one ready (the number of fd which are ready is s)*/
2806 {
2807 j=0;
2808 while (j<=max_fd) { if (FD_ISSET(j,&fdmask)) break; j++; }
2809 for(i=L->nr; i>=0; i--)
2810 {
2811 if (L->m[i].rtyp==LINK_CMD)
2812 {
2813 l=(si_link)L->m[i].Data();
2814 if (strcmp(l->m->type,"ssi")==0)
2815 {
2816 d=(ssiInfo*)l->data;
2817 d_fd=d->fd_read;
2818 if(j==d_fd) return i+1;
2819 }
2820 }
2821 }
2822 }
2823 return 0;
2824#endif
2825}
int i
Definition cfEzgcd.cc:132
int k
Definition cfEzgcd.cc:99
int Typ()
Definition subexpr.cc:1048
int rtyp
Definition subexpr.h:91
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 2827 of file ssiLink.cc.

2829{
2831 char *buf=(char*)omAlloc(256);
2832 snprintf(buf,256,"ssi:connect %s:%s",host,port);
2833 slInit(l, buf);
2834 omFreeSize(buf,256);
2835 if (slOpen(l,SI_LINK_OPEN,NULL)) return 1;
2837
2838 idhdl id = enterid("link_ll", 0, LINK_CMD, &IDROOT, FALSE);
2839 IDLINK(id) = l;
2840
2841 loop
2842 {
2843 leftv h=ssiRead1(l); /*contains an exit.... */
2844 if (feErrors != NULL && *feErrors != '\0')
2845 {
2846 // handle errors:
2847 PrintS(feErrors); /* currently quite simple */
2848 *feErrors = '\0';
2849 }
2850 ssiWrite(l,h);
2851 h->CleanUp();
2853 }
2854 /* never reached*/
2855 _exit(0);
2856}
Definition idrec.h:35
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition ipid.cc:279
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:288
VAR char * feErrors
Definition reporter.cc:47
int status int void * buf
Definition si_signals.h:69

◆ ssiCheckCurrRing()

static void ssiCheckCurrRing ( const ring  r)
static

Definition at line 125 of file ssiLink.cc.

126{
127 if ((r!=currRing)
128 ||(currRingHdl==NULL)
129 ||(IDRING(currRingHdl)!=r))
130 {
131 char name[20];
132 int nr=0;
133 idhdl h=NULL;
134 loop
135 {
136 snprintf(name,20,"ssiRing%d",nr); nr++;
137 h=IDROOT->get(name, 0);
138 if (h==NULL)
139 {
141 IDRING(h)=rIncRefCnt(r);
142 r->ref=2;/*ref==2: d->r and h */
143 break;
144 }
145 else if ((IDTYP(h)==RING_CMD)
146 && (rEqual(r,IDRING(h),1)))
147 {
148 break;
149 }
150 }
151 rSetHdl(h);
152 }
153 assume((currRing==r) || rEqual(r,currRing));
154}
char name(const Variable &v)
Definition factory.h:189
VAR idhdl currRingHdl
Definition ipid.cc:57
#define IDRING(a)
Definition ipid.h:127
void rSetHdl(idhdl h)
Definition ipshell.cc:5129
#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:1752
static ring rIncRefCnt(ring r)
Definition ring.h:849

◆ ssiClose()

BOOLEAN ssiClose ( si_link  l)

Definition at line 1818 of file ssiLink.cc.

1819{
1820 if (l!=NULL)
1821 {
1823 ssiInfo *d = (ssiInfo *)l->data;
1824 if (d!=NULL)
1825 {
1826 // send quit signal
1827 if ((d->send_quit_at_exit)
1828 && (d->quit_sent==0))
1829 {
1830 fputs("99\n",d->f_write);
1831 fflush(d->f_write);
1832 d->quit_sent=1;
1833 }
1834 // clean ring
1835 if (d->r!=NULL) rKill(d->r);
1836 for(int i=0;i<SI_RING_CACHE;i++)
1837 {
1838 if (d->rings[i]!=NULL) rKill(d->rings[i]);
1839 d->rings[i]=NULL;
1840 }
1841 if (d->f_read!=NULL) { s_close(d->f_read);d->f_read=NULL;}
1842 if (d->f_write!=NULL) { fclose(d->f_write); d->f_write=NULL; }
1843 if (((strcmp(l->mode,"tcp")==0)
1844 || (strcmp(l->mode,"fork")==0))
1845 && (d->pid>1))
1846 {
1847 // did the child stop ?
1848 int pid=si_waitpid(d->pid,NULL,WNOHANG);
1849 if ((pid==0) /* no status change for child*/
1850 && (kill(d->pid,0)==0)) // child is still running
1851 {
1852 struct timespec t;
1853 struct timespec rem;
1854 // wait 60 sec
1855 for(int i=0;i<50;i++)
1856 {
1857 // wait till signal or 100ms:
1858 t.tv_sec=0;
1859 t.tv_nsec=100000000; // <=100 ms
1860 nanosleep(&t, &rem);
1861 // child finished ?
1862 if (si_waitpid(d->pid,NULL,WNOHANG) == d->pid) break;
1863 }
1864 if (kill(d->pid,0)==0) // child still exists
1865 {
1866 kill(d->pid,SIGTERM);
1867 t.tv_sec=1;
1868 t.tv_nsec=0; // <=1000 ms
1869 nanosleep(&t, &rem);
1870 si_waitpid(d->pid,NULL,WNOHANG);
1871 }
1872 }
1873 }
1874 if ((strcmp(l->mode,"tcp")==0)
1875 || (strcmp(l->mode,"fork")==0))
1876 {
1878 if (hh!=NULL)
1879 {
1880 if (hh->l==l)
1881 {
1882 ssiToBeClosed=(link_list)hh->next;
1883 omFreeSize(hh,sizeof(link_struct));
1884 }
1885 else while(hh->next!=NULL)
1886 {
1887 link_list hhh=(link_list)hh->next;
1888 if (hhh->l==l)
1889 {
1890 hh->next=hhh->next;
1891 omFreeSize(hhh,sizeof(link_struct));
1892 break;
1893 }
1894 else
1895 hh=(link_list)hh->next;
1896 }
1897 }
1898 }
1899 omFreeSize((ADDRESS)d,(sizeof *d));
1900 }
1901 l->data=NULL;
1902 }
1903 return FALSE;
1904}
void rKill(ring r)
Definition ipshell.cc:6181
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 2898 of file ssiLink.cc.

2899{
2900 if (ssiReserved_P==0)
2901 {
2902 WerrorS("ERROR no reserved port requested");
2903 return NULL;
2904 }
2905 struct sockaddr_in cli_addr;
2906 int clilen = sizeof(cli_addr);
2908 if(newsockfd < 0)
2909 {
2910 Werror("ERROR on accept (errno=%d)",errno);
2911 return NULL;
2912 }
2915 si_link_extension prev = s;
2916 while (strcmp(s->type, "ssi") != 0)
2917 {
2918 if (s->next == NULL)
2919 {
2920 prev = s;
2921 s = NULL;
2922 break;
2923 }
2924 else
2925 {
2926 s = s->next;
2927 }
2928 }
2929 if (s != NULL)
2930 l->m = s;
2931 else
2932 {
2934 prev->next=slInitSsiExtension(ns);
2935 l->m = prev->next;
2936 }
2937 l->name=omStrDup("");
2938 l->mode=omStrDup("tcp");
2939 l->ref=1;
2940 ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo));
2941 l->data=d;
2942 d->fd_read = newsockfd;
2943 d->fd_write = newsockfd;
2944 d->f_read = s_open(newsockfd);
2945 d->f_write = fdopen(newsockfd, "w");
2948 if (ssiReserved_Clients<=0)
2949 {
2950 ssiReserved_P=0;
2952 }
2953 return l;
2954}
#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 3116 of file ssiLink.cc.

3117{
3118 if (strcmp(l->mode,"string")==0)
3119 {
3120 WerrorS("no dump for ssi:string");
3121 return TRUE;
3122 }
3125
3126 //if (! status ) status = DumpAsciiMaps(fd, h, NULL);
3127
3128 if (currRingHdl != rh) rSetHdl(rh);
3129 //fprintf(fd, "option(set, intvec(%d, %d));\n", si_opt_1, si_opt_2);
3130
3131 return status;
3132}
int BOOLEAN
Definition auxiliary.h:88

◆ ssiDumpIter()

static BOOLEAN ssiDumpIter ( si_link  l,
idhdl  h 
)
static

Definition at line 3095 of file ssiLink.cc.

3096{
3097 if (h == NULL) return FALSE;
3098
3099 if (ssiDumpIter(l, IDNEXT(h))) return TRUE;
3100
3101 // need to set the ring before writing it, otherwise we get in
3102 // trouble with minpoly
3103 if (IDTYP(h) == RING_CMD)
3104 rSetHdl(h);
3105
3106 if (DumpSsiIdhdl(l, h)) return TRUE;
3107
3108 // do not dump ssi internal rings: ssiRing*
3109 // but dump objects of all other rings
3110 if ((IDTYP(h) == RING_CMD)
3111 && (strncmp(IDID(h),"ssiRing",7)!=0))
3112 return ssiDumpIter(l, IDRING(h)->idroot);
3113 else
3114 return FALSE;
3115}
#define IDNEXT(a)
Definition ipid.h:118

◆ ssiGetDump()

BOOLEAN ssiGetDump ( si_link  l)

Definition at line 3133 of file ssiLink.cc.

3134{
3135 if (strcmp(l->mode,"string")==0)
3136 {
3137 WerrorS("no dump for ssi:string");
3138 return TRUE;
3139 }
3140 ssiInfo *d=(ssiInfo*)l->data;
3141 loop
3142 {
3143 if (!SI_LINK_OPEN_P(l)) break;
3144 if (s_iseof(d->f_read)) break;
3145 leftv h=ssiRead1(l); /*contains an exit.... */
3146 if (feErrors != NULL && *feErrors != '\0')
3147 {
3148 // handle errors:
3149 PrintS(feErrors); /* currently quite simple */
3150 return TRUE;
3151 *feErrors = '\0';
3152 }
3153 h->CleanUp();
3155 }
3156 return FALSE;
3157}

◆ ssiOpen()

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

Definition at line 1345 of file ssiLink.cc.

1346{
1347 if (l!=NULL)
1348 {
1349 const char *mode;
1350 if (flag & SI_LINK_OPEN)
1351 {
1352 if (strcmp(l->mode, "r") == 0)
1353 flag = SI_LINK_READ;
1354 else if (strcmp(l->mode,"string")==0)
1355 {
1357 return FALSE;
1358 }
1359 else flag = SI_LINK_WRITE;
1360 }
1361 if (((flag == SI_LINK_READ)
1362 || (flag == SI_LINK_WRITE))
1363 && (strcmp(l->mode,"string")==0))
1364 {
1366 return FALSE;
1367 }
1368
1369 if (flag == SI_LINK_READ) mode = "r";
1370 else if (strcmp(l->mode, "w") == 0) mode = "w";
1371 else if (strcmp(l->mode, "fork") == 0) mode = "fork";
1372 else if (strcmp(l->mode, "tcp") == 0) mode = "tcp";
1373 else if (strcmp(l->mode, "connect") == 0) mode = "connect";
1374 else mode = "a";
1375
1376
1377 SI_LINK_SET_OPEN_P(l, flag);
1378 if(l->data!=NULL) omFreeSize(l->data,sizeof(ssiInfo));
1379 omFreeBinAddr(l->mode);
1380 l->mode = omStrDup(mode);
1381
1382 ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo));
1383 l->data=d;
1384 if (l->name[0] == '\0')
1385 {
1386 if (strcmp(mode,"fork")==0)
1387 {
1389 if (cpus<1)
1390 {
1391 WerrorS("no sub-processes allowed");
1392 l->flags=0;
1393 l->data=NULL;
1394 omFreeSize(d,sizeof(ssiInfo));
1395 return TRUE;
1396 }
1397 int pc[2];
1398 int cp[2];
1399 int err1=pipe(pc);
1400 int err2=pipe(cp);
1401 if (err1 || err2)
1402 {
1403 Werror("pipe failed with %d\n",errno);
1404 l->flags=0;
1405 l->data=NULL;
1406 omFreeSize(d,sizeof(ssiInfo));
1407 return TRUE;
1408 }
1410 n->u=u;
1411 n->l=l;
1412 n->next=(void *)ssiToBeClosed;
1413 ssiToBeClosed=n;
1414
1415 pid_t pid = fork();
1416 if (pid == -1 && errno == EAGAIN) // RLIMIT_NPROC too low?
1417 {
1419 pid = fork();
1420 }
1421 if (pid == -1)
1422 {
1423 WerrorS("could not fork");
1424 l->flags=0;
1425 l->data=NULL;
1426 omFreeSize(d,sizeof(ssiInfo));
1427 return TRUE;
1428 }
1429 if (pid==0) /*fork: child*/
1430 {
1431 /* block SIGINT */
1437 /* set #cpu to 1 for the child:*/
1439
1441 /* we know: l is the first entry in ssiToBeClosed-list */
1442 while(hh!=NULL)
1443 {
1445 ssiInfo *dd=(ssiInfo*)hh->l->data;
1446 s_close(dd->f_read);
1447 fclose(dd->f_write);
1448 if (dd->r!=NULL) rKill(dd->r);
1449 omFreeSize((ADDRESS)dd,(sizeof *dd));
1450 hh->l->data=NULL;
1451 link_list nn=(link_list)hh->next;
1452 omFree(hh);
1453 hh=nn;
1454 }
1456#ifdef HAVE_SIMPLEIPC
1458#endif // HAVE_SIMPLEIPC
1459 si_close(pc[1]); si_close(cp[0]);
1460 d->f_write=fdopen(cp[1],"w");
1461 d->f_read=s_open(pc[0]);
1462 d->fd_read=pc[0];
1463 d->fd_write=cp[1];
1464 //d->r=currRing;
1465 //if (d->r!=NULL) d->r->ref++;
1466 l->data=d;
1467 omFreeBinAddr(l->mode);
1468 l->mode = omStrDup(mode);
1471 //myynest=0;
1473 if ((u!=NULL)&&(u->rtyp==IDHDL))
1474 {
1475 idhdl h=(idhdl)u->data;
1476 h->lev=0;
1477 }
1478 loop
1479 {
1480 if (!SI_LINK_OPEN_P(l)) m2_end(-1);
1481 if(d->f_read->is_eof) m2_end(-1);
1482 leftv h=ssiRead1(l); /*contains an exit.... */
1483 if (feErrors != NULL && *feErrors != '\0')
1484 {
1485 // handle errors:
1486 PrintS(feErrors); /* currently quite simple */
1487 *feErrors = '\0';
1488 }
1489 ssiWrite(l,h);
1490 h->CleanUp();
1492 }
1493 /* never reached*/
1494 }
1495 else if (pid>0) /*fork: parent*/
1496 {
1497 d->pid=pid;
1498 si_close(pc[0]); si_close(cp[1]);
1499 d->f_write=fdopen(pc[1],"w");
1500 d->f_read=s_open(cp[0]);
1501 d->fd_read=cp[0];
1502 d->fd_write=pc[1];
1504 d->send_quit_at_exit=1;
1505 //d->r=currRing;
1506 //if (d->r!=NULL) d->r->ref++;
1507 }
1508 else
1509 {
1510 Werror("fork failed (%d)",errno);
1511 l->data=NULL;
1512 omFreeSize(d,sizeof(ssiInfo));
1513 return TRUE;
1514 }
1515 }
1516 // ---------------------------------------------------------------------
1517 else if (strcmp(mode,"tcp")==0)
1518 {
1522 if(sockfd < 0)
1523 {
1524 WerrorS("ERROR opening socket");
1525 l->data=NULL;
1526 l->flags=0;
1527 omFreeSize(d,sizeof(ssiInfo));
1528 return TRUE;
1529 }
1530 memset((char *) &serv_addr,0, sizeof(serv_addr));
1531 portno = 1025;
1532 serv_addr.sin_family = AF_INET;
1533 serv_addr.sin_addr.s_addr = INADDR_ANY;
1534 do
1535 {
1536 portno++;
1537 serv_addr.sin_port = htons(portno);
1538 if(portno > 50000)
1539 {
1540 WerrorS("ERROR on binding (no free port available?)");
1541 l->data=NULL;
1542 l->flags=0;
1543 omFreeSize(d,sizeof(ssiInfo));
1544 return TRUE;
1545 }
1546 }
1547 while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
1548 Print("waiting on port %d\n", portno);mflush();
1549 listen(sockfd,1);
1551 if(newsockfd < 0)
1552 {
1553 WerrorS("ERROR on accept");
1554 l->data=NULL;
1555 l->flags=0;
1556 omFreeSize(d,sizeof(ssiInfo));
1557 return TRUE;
1558 }
1559 PrintS("client accepted\n");
1560 d->fd_read = newsockfd;
1561 d->fd_write = newsockfd;
1562 d->f_read = s_open(newsockfd);
1563 d->f_write = fdopen(newsockfd, "w");
1566 }
1567 // no ssi-Link on stdin or stdout
1568 else if (strcmp(mode,"string")==0)
1569 {
1571 }
1572 else
1573 {
1574 Werror("invalid mode >>%s<< for ssi",mode);
1575 l->data=NULL;
1576 l->flags=0;
1577 omFreeSize(d,sizeof(ssiInfo));
1578 return TRUE;
1579 }
1580 }
1581 // =========================================================================
1582 else /*now l->name!=NULL*/
1583 {
1584 // tcp mode
1585 if(strcmp(mode,"tcp")==0)
1586 {
1590 if(sockfd < 0)
1591 {
1592 WerrorS("ERROR opening socket");
1593 l->data=NULL;
1594 l->flags=0;
1595 omFreeSize(d,sizeof(ssiInfo));
1596 return TRUE;
1597 }
1598 memset((char *) &serv_addr,0, sizeof(serv_addr));
1599 portno = 1025;
1600 serv_addr.sin_family = AF_INET;
1601 serv_addr.sin_addr.s_addr = INADDR_ANY;
1602 do
1603 {
1604 portno++;
1605 serv_addr.sin_port = htons(portno);
1606 if(portno > 50000)
1607 {
1608 WerrorS("ERROR on binding (no free port available?)");
1609 l->data=NULL;
1610 l->flags=0;
1611 omFreeSize(d,sizeof(ssiInfo));
1612 return TRUE;
1613 }
1614 }
1615 while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
1616 //Print("waiting on port %d\n", portno);mflush();
1617 listen(sockfd,1);
1618 char* cli_host = (char*)omAlloc(256);
1619 char* path = (char*)omAlloc(1024);
1620 int r = si_sscanf(l->name,"%255[^:]:%s",cli_host,path);
1621 if(r == 0)
1622 {
1623 WerrorS("ERROR: no host specified");
1624 l->data=NULL;
1625 l->flags=0;
1626 omFreeSize(d,sizeof(ssiInfo));
1627 omFree(path);
1629 return TRUE;
1630 }
1631 else if(r == 1)
1632 {
1633 WarnS("program not specified, using /usr/local/bin/Singular");
1634 Warn("in line >>%s<<",my_yylinebuf);
1635 strcpy(path,"/usr/local/bin/Singular");
1636 }
1637 char* ssh_command = (char*)omAlloc(256);
1638 char* ser_host = (char*)omAlloc(64);
1639 if(strcmp(cli_host,"localhost")==0)
1640 strcpy(ser_host,"localhost");
1641 else
1643 if (strcmp(cli_host,"localhost")==0) /*avoid "ssh localhost" as key may change*/
1644 snprintf(ssh_command,256,"%s -q --batch --link=ssi --MPhost=%s --MPport=%d &",path,ser_host,portno);
1645 else
1646 snprintf(ssh_command,256,"ssh %s %s -q --batch --link=ssi --MPhost=%s --MPport=%d &",cli_host,path,ser_host,portno);
1647 //Print("client on %s started:%s\n",cli_host,path);
1648 omFree(path);
1650 if (TEST_OPT_PROT) { Print("running >>%s<<\n",ssh_command); }
1651 int re=system(ssh_command);
1652 if (re<0)
1653 {
1654 Werror("ERROR running `%s` (%d)",ssh_command,re);
1655 l->data=NULL;
1656 l->flags=0;
1657 omFreeSize(d,sizeof(ssiInfo));
1658 return TRUE;
1659 }
1662 clilen = sizeof(cli_addr);
1664 if(newsockfd < 0)
1665 {
1666 WerrorS("ERROR on accept");
1667 l->data=NULL;
1668 l->flags=0;
1669 omFreeSize(d,sizeof(ssiInfo));
1670 return TRUE;
1671 }
1672 //PrintS("client accepted\n");
1673 d->fd_read = newsockfd;
1674 d->fd_write = newsockfd;
1675 d->f_read = s_open(newsockfd);
1676 d->f_write = fdopen(newsockfd, "w");
1679 d->send_quit_at_exit=1;
1681 newlink->u=u;
1682 newlink->l=l;
1683 newlink->next=(void *)ssiToBeClosed;
1685 fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,si_opt_1,si_opt_2);
1686 }
1687 // ----------------------------------------------------------------------
1688 else if(strcmp(mode,"connect")==0)
1689 {
1690 char* host = (char*)omAlloc(256);
1691 int sockfd, portno;
1692 struct sockaddr_in serv_addr;
1693 struct hostent *server;
1694
1695 si_sscanf(l->name,"%255[^:]:%d",host,&portno);
1696 //Print("connect to host %s, port %d\n",host,portno);mflush();
1697 if (portno!=0)
1698 {
1700 if (sockfd < 0)
1701 {
1702 WerrorS("ERROR opening socket");
1703 l->flags=0;
1704 l->data=NULL;
1705 omFreeSize(d,sizeof(ssiInfo));
1706 return TRUE;
1707 }
1709 if (server == NULL)
1710 {
1711 WerrorS("ERROR, no such host");
1712 l->flags=0;
1713 l->data=NULL;
1714 omFreeSize(d,sizeof(ssiInfo));
1715 return TRUE;
1716 }
1717 memset((char *) &serv_addr, 0, sizeof(serv_addr));
1718 serv_addr.sin_family = AF_INET;
1719 memcpy((char *)&serv_addr.sin_addr.s_addr,
1720 (char *)server->h_addr,
1721 server->h_length);
1722 serv_addr.sin_port = htons(portno);
1723 if (si_connect(sockfd,(sockaddr*)&serv_addr,sizeof(serv_addr)) < 0)
1724 {
1725 Werror("ERROR connecting(errno=%d)",errno);
1726 l->flags=0;
1727 l->data=NULL;
1728 omFreeSize(d,sizeof(ssiInfo));
1729 return TRUE;
1730 }
1731 //PrintS("connected\n");mflush();
1732 d->f_read=s_open(sockfd);
1733 d->fd_read=sockfd;
1734 d->f_write=fdopen(sockfd,"w");
1735 d->fd_write=sockfd;
1737 omFree(host);
1738 }
1739 else
1740 {
1741 l->data=NULL;
1742 l->flags=0;
1743 omFreeSize(d,sizeof(ssiInfo));
1744 return TRUE;
1745 }
1746 }
1747 // ======================================================================
1748 else
1749 {
1750 // normal link to a file
1751 if (FE_OPT_NO_SHELL_FLAG) {WerrorS("no links allowed");return TRUE;}
1752 FILE *outfile;
1753 char *filename=l->name;
1754
1755 if(filename[0]=='>')
1756 {
1757 if (filename[1]=='>')
1758 {
1759 filename+=2;
1760 mode = "a";
1761 }
1762 else
1763 {
1764 filename++;
1765 mode="w";
1766 }
1767 }
1768 outfile=myfopen(filename,mode);
1769 if (outfile!=NULL)
1770 {
1771 if (strcmp(l->mode,"r")==0)
1772 {
1773 fclose(outfile);
1774 d->f_read=s_open_by_name(filename);
1775 }
1776 else
1777 {
1778 d->f_write = outfile;
1779 fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,si_opt_1,si_opt_2);
1780 }
1781 }
1782 else
1783 {
1784 omFree(d);
1785 l->data=NULL;
1786 l->flags=0;
1787 return TRUE;
1788 }
1789 }
1790 }
1791 }
1792
1793 return FALSE;
1794}
void * data
Definition subexpr.h:88
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
FILE * myfopen(const char *path, const char *mode)
Definition feFopen.cc:167
const char * feSetOptValue(feOptIndex opt, char *optarg)
Definition feOpt.cc:154
static void * feOptValue(feOptIndex opt)
Definition feOpt.h:40
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:1104
#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
idrec * idhdl
Definition ring.h:22
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

◆ ssiRead1()

leftv ssiRead1 ( si_link  l)

Definition at line 1907 of file ssiLink.cc.

1908{
1909 ssiInfo *d = (ssiInfo *)l->data;
1911 int t=0;
1912 t=s_readint(d->f_read);
1913 //Print("got type %d\n",t);
1914 switch(t)
1915 {
1916 case 1:res->rtyp=INT_CMD;
1917 res->data=(char *)(long)ssiReadInt(d);
1918 //Print("int: %d\n",(int)(long)res->data);
1919 break;
1920 case 2:res->rtyp=STRING_CMD;
1921 res->data=(char *)ssiReadString(d);
1922 //Print("str: %s\n",(char*)res->data);
1923 break;
1924 case 3:res->rtyp=NUMBER_CMD;
1925 if (d->r==NULL) goto no_ring;
1926 ssiCheckCurrRing(d->r);
1927 res->data=(char *)ssiReadNumber(d);
1928 //Print("number\n");
1929 break;
1930 case 4:res->rtyp=BIGINT_CMD;
1931 res->data=(char *)ssiReadBigInt(d);
1932 //Print("bigint\n");
1933 break;
1934 case 15:
1935 case 5:{
1936 //Print("ring %d\n",t);
1937 d->r=ssiReadRing(d);
1938 if (errorreported) return NULL;
1939 res->data=(char*)d->r;
1940 if (d->r!=NULL) rIncRefCnt(d->r);
1941 res->rtyp=RING_CMD;
1942 if (t==15) // setring
1943 {
1944 if(ssiSetCurrRing(d->r)) { d->r=currRing; }
1946 return ssiRead1(l);
1947 }
1948 }
1949 break;
1950 case 6:res->rtyp=POLY_CMD;
1951 //Print("poly\n");
1952 if (d->r==NULL) goto no_ring;
1953 ssiCheckCurrRing(d->r);
1954 res->data=(char*)ssiReadPoly(d);
1955 break;
1956 case 7:res->rtyp=IDEAL_CMD;
1957 //Print("ideal\n");
1958 if (d->r==NULL) goto no_ring;
1959 ssiCheckCurrRing(d->r);
1960 res->data=(char*)ssiReadIdeal(d);
1961 break;
1962 case 8:res->rtyp=MATRIX_CMD;
1963 //Print("matrix\n");
1964 if (d->r==NULL) goto no_ring;
1965 ssiCheckCurrRing(d->r);
1966 res->data=(char*)ssiReadMatrix(d);
1967 break;
1968 case 9:res->rtyp=VECTOR_CMD;
1969 //Print("vector\n");
1970 if (d->r==NULL) goto no_ring;
1971 ssiCheckCurrRing(d->r);
1972 res->data=(char*)ssiReadPoly(d);
1973 break;
1974 case 10:
1975 case 22:if (t==22) res->rtyp=SMATRIX_CMD;
1976 else res->rtyp=MODUL_CMD;
1977 //Print("module/smatrix %d\n",t);
1978 if (d->r==NULL) goto no_ring;
1979 ssiCheckCurrRing(d->r);
1980 {
1981 int rk=s_readint(d->f_read);
1982 ideal M=ssiReadIdeal(d);
1983 M->rank=rk;
1984 res->data=(char*)M;
1985 }
1986 break;
1987 case 11:
1988 {
1989 //Print("cmd\n",t);
1990 res->rtyp=COMMAND;
1991 res->data=ssiReadCommand(l);
1992 int nok=res->Eval();
1993 if (nok) WerrorS("error in eval");
1994 break;
1995 }
1996 case 12: /*DEF_CMD*/
1997 {
1998 //Print("def\n",t);
1999 res->rtyp=0;
2000 res->name=(char *)ssiReadString(d);
2001 int nok=res->Eval();
2002 if (nok) WerrorS("error in name lookup");
2003 break;
2004 }
2005 case 13: res->rtyp=PROC_CMD;
2006 res->data=ssiReadProc(d);
2007 break;
2008 case 14: res->rtyp=LIST_CMD;
2009 res->data=ssiReadList(l);
2010 break;
2011 case 16: res->rtyp=NONE; res->data=NULL;
2012 break;
2013 case 17: res->rtyp=INTVEC_CMD;
2014 res->data=ssiReadIntvec(d);
2015 break;
2016 case 18: res->rtyp=INTMAT_CMD;
2017 res->data=ssiReadIntmat(d);
2018 break;
2019 case 19: res->rtyp=BIGINTMAT_CMD;
2020 res->data=ssiReadBigintmat(d);
2021 break;
2022 case 20: ssiReadBlackbox(res,l);
2023 break;
2024 case 21: ssiReadAttrib(res,l);
2025 break;
2026 case 23: ssiReadRingProperties(l);
2027 return ssiRead1(l);
2028 break;
2029 case 24: res->rtyp=BIGINTVEC_CMD;
2030 res->data=ssiReadBigintvec(d);
2031 break;
2032 // ------------
2033 case 98: // version
2034 {
2035 int n98_v,n98_m;
2037 n98_v=s_readint(d->f_read);
2038 n98_m=s_readint(d->f_read);
2039 n98_o1=s_readint(d->f_read);
2040 n98_o2=s_readint(d->f_read);
2041 if ((n98_v!=SSI_VERSION) ||(n98_m!=MAX_TOK))
2042 {
2043 Print("incompatible versions of ssi: %d/%d vs %d/%d\n",
2045 }
2046 #ifndef SING_NDEBUG
2047 if (TEST_OPT_DEBUG)
2048 Print("// opening ssi-%d, MAX_TOK=%d\n",n98_v,n98_m);
2049 #endif
2053 return ssiRead1(l);
2054 }
2055 case 99: omFreeBin(res,sleftv_bin); ssiClose(l); m2_end(-1);
2056 break; /*to make compiler happy*/
2057 case 0: if (s_iseof(d->f_read))
2058 {
2059 ssiClose(l);
2060 }
2061 res->rtyp=DEF_CMD;
2062 break;
2063 default: Werror("not implemented (t:%d)",t);
2065 res=NULL;
2066 break;
2067 }
2068 // if currRing is required for the result, but lost
2069 // define "ssiRing%d" as currRing:
2070 if ((d->r!=NULL)
2071 && (currRing!=d->r)
2072 && (res->RingDependend()))
2073 {
2074 if(ssiSetCurrRing(d->r)) { d->r=currRing; }
2075 }
2076 return res;
2077no_ring: WerrorS("no ring");
2079 return NULL;
2080}
#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
sleftv * leftv
Definition structs.h:53
@ BIGINT_CMD
Definition tok.h:38
@ LIST_CMD
Definition tok.h:118
@ INTVEC_CMD
Definition tok.h:101
@ INT_CMD
Definition tok.h:96
#define NONE
Definition tok.h:223

◆ ssiRead1_S()

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

Definition at line 2081 of file ssiLink.cc.

2082{
2084 int t=0;
2085 t=s_readint_S(s);
2086 switch(t)
2087 {
2088 case 1:res->rtyp=INT_CMD;
2089 res->data=(char *)(long)ssiReadInt_S(s);
2090 break;
2091 case 2:res->rtyp=STRING_CMD;
2092 res->data=(char *)ssiReadString_S(s);
2093 break;
2094 case 3:res->rtyp=NUMBER_CMD;
2095 res->data=(char *)ssiReadNumber_CF_S(s,R->cf);
2096 break;
2097 case 4:res->rtyp=BIGINT_CMD;
2098 res->data=(char *)ssiReadBigInt_S(s);
2099 //Print("bigint\n");
2100 break;
2101 #if 0
2102 case 15:
2103 case 5:{
2104 //Print("ring %d\n",t);
2105 d->r=ssiReadRing(d);
2106 if (errorreported) return NULL;
2107 res->data=(char*)d->r;
2108 if (d->r!=NULL) rIncRefCnt(d->r);
2109 res->rtyp=RING_CMD;
2110 if (t==15) // setring
2111 {
2112 if(ssiSetCurrRing(d->r)) { d->r=currRing; }
2114 return ssiRead1(l);
2115 }
2116 }
2117 break;
2118 #endif
2119 case 6:res->rtyp=POLY_CMD;
2120 res->data=(char*)ssiReadPoly_R_S(s,R);
2121 break;
2122 case 7:res->rtyp=IDEAL_CMD;
2123 res->data=(char*)ssiReadIdeal_R_S(s,R);
2124 break;
2125 case 8:res->rtyp=MATRIX_CMD;
2126 res->data=(char*)ssiReadMatrix_R_S(s,R);
2127 break;
2128 case 9:res->rtyp=VECTOR_CMD;
2129 res->data=(char*)ssiReadPoly_R_S(s,R);
2130 break;
2131 case 10:
2132 case 22:if (t==22) res->rtyp=SMATRIX_CMD;
2133 else res->rtyp=MODUL_CMD;
2134 {
2135 int rk=s_readint_S(s);
2137 M->rank=rk;
2138 res->data=(char*)M;
2139 }
2140 break;
2141 #if 0
2142 case 11:
2143 {
2144 res->rtyp=COMMAND;
2145 res->data=ssiReadCommand(l);
2146 int nok=res->Eval();
2147 if (nok) WerrorS("error in eval");
2148 break;
2149 }
2150 #endif
2151 case 12: /*DEF_CMD*/
2152 {
2153 res->rtyp=0;
2154 res->name=(char *)ssiReadString_S(s);
2155 int nok=res->Eval();
2156 if (nok) WerrorS("error in name lookup");
2157 break;
2158 }
2159 case 13: res->rtyp=PROC_CMD;
2160 res->data=ssiReadProc_S(s);
2161 break;
2162 case 14: res->rtyp=LIST_CMD;
2163 res->data=ssiReadList_S(s,R);
2164 break;
2165 case 16: res->rtyp=NONE; res->data=NULL;
2166 break;
2167 case 17: res->rtyp=INTVEC_CMD;
2168 res->data=ssiReadIntvec_S(s);
2169 break;
2170 case 18: res->rtyp=INTMAT_CMD;
2171 res->data=ssiReadIntmat_S(s);
2172 break;
2173 case 19: res->rtyp=BIGINTMAT_CMD;
2174 res->data=ssiReadBigintmat_S(s);
2175 break;
2176 #if 0
2177 case 20: ssiReadBlackbox(res,l);
2178 break;
2179 case 21: ssiReadAttrib(res,l);
2180 break;
2181 case 23: ssiReadRingProperties(l);
2182 return ssiRead1(l);
2183 break;
2184 #endif
2185 case 24: res->rtyp=BIGINTVEC_CMD;
2186 res->data=ssiReadBigintvec_S(s);
2187 break;
2188 // ------------
2189 case 98: // version
2190 {
2191 int n98_v,n98_m;
2197 Print("// version ssi-%d, MAX_TOK=%d\n",n98_v,n98_m);
2201 return ssiRead1_S(s,R);
2202 }
2203 #if 0
2204 case 99: omFreeBin(res,sleftv_bin); ssiClose(l); m2_end(-1);
2205 break; /*to make compiler happy*/
2206 #endif
2207 case 0: res->rtyp=DEF_CMD;
2208 **s='\0'; /* unkown char?*/
2209 break;
2210 default: Werror("not implemented (t:%d)",t);
2212 res=NULL;
2213 break;
2214 }
2215 while((**s!='\0') &&(**s<=' ')) (*s)++;
2216 if (**s>' ') res->next=ssiRead1_S(s,R);
2217 return res;
2218}
int s_readint_S(char **s)
Definition s_buff.cc:141
#define R
Definition sirandom.c:27

◆ ssiRead2()

leftv ssiRead2 ( si_link  l,
leftv  u 
)

Definition at line 3192 of file ssiLink.cc.

3193{
3194 if((strcmp(l->mode,"string")==0)
3195 &&(u->Typ()==STRING_CMD))
3196 {
3197 char *s=(char*)u->Data();
3198 return ssiRead1_S(&s,currRing);
3199 }
3200 return NULL;
3201}

◆ ssiReadAttrib()

static void ssiReadAttrib ( leftv  res,
si_link  l 
)
static

Definition at line 1284 of file ssiLink.cc.

1285{
1286 ssiInfo *d=(ssiInfo*)l->data;
1287 BITSET fl=(BITSET)s_readint(d->f_read);
1288 int nr_of_attr=s_readint(d->f_read);
1289 if (nr_of_attr>0)
1290 {
1291 for(int i=1;i<nr_of_attr;i++)
1292 {
1293 }
1294 }
1296 memcpy(res,tmp,sizeof(sleftv));
1297 memset(tmp,0,sizeof(sleftv));
1299 if (nr_of_attr>0)
1300 {
1301 }
1302 res->flag=fl;
1303}

◆ ssiReadBigInt()

static number ssiReadBigInt ( const ssiInfo d)
static

Definition at line 723 of file ssiLink.cc.

724{
726 if ((SR_HDL(n) & SR_INT)==0)
727 {
728 if (n->s!=3) Werror("invalid sub type in bigint:%d",n->s);
729 }
730 return n;
731}
#define SR_INT
Definition longrat.h:67
VAR coeffs coeffs_BIGINT
Definition polys.cc:14
#define SR_HDL(A)
Definition tgb.cc:35

◆ ssiReadBigInt_S()

static number ssiReadBigInt_S ( char **  s)
static

Definition at line 732 of file ssiLink.cc.

733{
735 if ((SR_HDL(n) & SR_INT)==0)
736 {
737 if (n->s!=3) Werror("invalid sub type in bigint:%d",n->s);
738 }
739 return n;
740}

◆ ssiReadBigintmat()

static bigintmat * ssiReadBigintmat ( const ssiInfo d)
static

Definition at line 1209 of file ssiLink.cc.

1210{
1211 int r,c;
1212 r=s_readint(d->f_read);
1213 c=s_readint(d->f_read);
1215 for(int i=0;i<r*c;i++)
1216 {
1217 (*v)[i]=ssiReadBigInt(d);
1218 }
1219 return v;
1220}
Matrices of numbers.
Definition bigintmat.h:51
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39

◆ ssiReadBigintmat_S()

static bigintmat * ssiReadBigintmat_S ( char **  s)
static

Definition at line 1221 of file ssiLink.cc.

1222{
1223 int r,c;
1224 r=s_readint_S(s);
1225 c=s_readint_S(s);
1227 for(int i=0;i<r*c;i++)
1228 {
1229 (*v)[i]=ssiReadBigInt_S(s);
1230 }
1231 return v;
1232}

◆ ssiReadBigintvec()

static bigintmat * ssiReadBigintvec ( const ssiInfo d)
static

Definition at line 1233 of file ssiLink.cc.

1234{
1235 int c;
1236 c=s_readint(d->f_read);
1238 for(int i=0;i<c;i++)
1239 {
1240 (*v)[i]=ssiReadBigInt(d);
1241 }
1242 return v;
1243}

◆ ssiReadBigintvec_S()

static bigintmat * ssiReadBigintvec_S ( char **  s)
static

Definition at line 1244 of file ssiLink.cc.

1245{
1246 int c;
1247 c=s_readint_S(s);
1249 for(int i=0;i<c;i++)
1250 {
1251 (*v)[i]=ssiReadBigInt_S(s);
1252 }
1253 return v;
1254}

◆ ssiReadBlackbox()

static void ssiReadBlackbox ( leftv  res,
si_link  l 
)
static

Definition at line 1256 of file ssiLink.cc.

1257{
1258 leftv lv=ssiRead1(l);
1259 char *name=(char*)lv->data;
1261 int tok;
1263 if (tok>MAX_TOK)
1264 {
1268 res->rtyp=tok;
1269 b->blackbox_deserialize(&b,&(res->data),l);
1270 if (save_ring!=currRing)
1271 {
1274 else currRingHdl=NULL;
1275 }
1276 }
1277 else
1278 {
1279 Werror("blackbox %s not found",name);
1280 }
1281 omFree(name);
1282}
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 1062 of file ssiLink.cc.

1063{
1064 ssiInfo *d=(ssiInfo*)l->data;
1065 // syntax: <num ops> <operation> <op1> <op2> ....
1066 command D=(command)omAlloc0(sizeof(*D));
1067 int argc,op;
1068 argc=s_readint(d->f_read);
1069 op=s_readint(d->f_read);
1070 D->argc=argc; D->op=op;
1071 leftv v;
1072 if (argc >0)
1073 {
1074 v=ssiRead1(l);
1075 memcpy(&(D->arg1),v,sizeof(*v));
1077 }
1078 if (argc <4)
1079 {
1080 if (D->argc >1)
1081 {
1082 v=ssiRead1(l);
1083 memcpy(&(D->arg2),v,sizeof(*v));
1085 }
1086 if (D->argc >2)
1087 {
1088 v=ssiRead1(l);
1089 memcpy(&(D->arg3),v,sizeof(*v));
1091 }
1092 }
1093 else
1094 {
1095 leftv prev=&(D->arg1);
1096 argc--;
1097 while(argc >0)
1098 {
1099 v=ssiRead1(l);
1100 prev->next=v;
1101 prev=v;
1102 argc--;
1103 }
1104 }
1105 return D;
1106}
leftv next
Definition subexpr.h:86

◆ ssiReadIdeal()

ideal ssiReadIdeal ( ssiInfo d)

Definition at line 1017 of file ssiLink.cc.

1018{
1019 return ssiReadIdeal_R(d,d->r);
1020}
ring r
Definition s_buff.h:24

◆ ssiReadIdeal_R()

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

Definition at line 990 of file ssiLink.cc.

991{
992// < # of terms> < term1> < .....
993 int n,i;
994 ideal I;
995 n=s_readint(d->f_read);
996 I=idInit(n,1); // will be fixed later for module/smatrix
997 for(i=0;i<IDELEMS(I);i++) // read n terms
998 {
999 I->m [i]=ssiReadPoly_R(d,r);
1000 }
1001 return I;
1002}
ideal idInit(int idsize, int rank)
initialise an ideal / module
#define IDELEMS(i)

◆ ssiReadIdeal_R_S()

static ideal ssiReadIdeal_R_S ( char **  s,
const ring  r 
)
static

Definition at line 1003 of file ssiLink.cc.

1004{
1005// < # of terms> < term1> < .....
1006 int n,i;
1007 ideal I;
1008 n=s_readint_S(s);
1009 I=idInit(n,1); // will be fixed later for module/smatrix
1010 for(i=0;i<IDELEMS(I);i++) // read n terms
1011 {
1012 I->m [i]=ssiReadPoly_R_S(s,r);
1013 }
1014 return I;
1015}

◆ ssiReadIdeal_S()

ideal ssiReadIdeal_S ( char s,
const ring  R 
)

Definition at line 1022 of file ssiLink.cc.

1023{
1024 return ssiReadIdeal_R_S(&s,R);
1025}

◆ ssiReadInt()

int ssiReadInt ( const ssiInfo d)

Definition at line 666 of file ssiLink.cc.

667{
668 return s_readint(d->f_read);
669}

◆ ssiReadInt_S()

int ssiReadInt_S ( char **  s)

Definition at line 670 of file ssiLink.cc.

671{
672 return s_readint_S(s);
673}

◆ ssiReadIntmat()

static intvec * ssiReadIntmat ( const ssiInfo d)
static

Definition at line 1185 of file ssiLink.cc.

1186{
1187 int r,c;
1188 r=s_readint(d->f_read);
1189 c=s_readint(d->f_read);
1190 intvec *v=new intvec(r,c,0);
1191 for(int i=0;i<r*c;i++)
1192 {
1193 (*v)[i]=s_readint(d->f_read);
1194 }
1195 return v;
1196}

◆ ssiReadIntmat_S()

static intvec * ssiReadIntmat_S ( char **  s)
static

Definition at line 1197 of file ssiLink.cc.

1198{
1199 int r,c;
1200 r=s_readint_S(s);
1201 c=s_readint_S(s);
1202 intvec *v=new intvec(r,c,0);
1203 for(int i=0;i<r*c;i++)
1204 {
1205 (*v)[i]=s_readint_S(s);
1206 }
1207 return v;
1208}

◆ ssiReadIntvec()

static intvec * ssiReadIntvec ( const ssiInfo d)
static

Definition at line 1163 of file ssiLink.cc.

1164{
1165 int nr;
1166 nr=s_readint(d->f_read);
1167 intvec *v=new intvec(nr);
1168 for(int i=0;i<nr;i++)
1169 {
1170 (*v)[i]=s_readint(d->f_read);
1171 }
1172 return v;
1173}

◆ ssiReadIntvec_S()

static intvec * ssiReadIntvec_S ( char **  s)
static

Definition at line 1174 of file ssiLink.cc.

1175{
1176 int nr;
1177 nr=s_readint_S(s);
1178 intvec *v=new intvec(nr);
1179 for(int i=0;i<nr;i++)
1180 {
1181 (*v)[i]=s_readint_S(s);
1182 }
1183 return v;
1184}

◆ ssiReadList()

static lists ssiReadList ( si_link  l)
static

Definition at line 1128 of file ssiLink.cc.

1129{
1130 ssiInfo *d=(ssiInfo*)l->data;
1131 int nr;
1132 nr=s_readint(d->f_read);
1134 L->Init(nr);
1135
1136 int i;
1137 leftv v;
1138 for(i=0;i<=L->nr;i++)
1139 {
1140 v=ssiRead1(l);
1141 memcpy(&(L->m[i]),v,sizeof(*v));
1143 }
1144 return L;
1145}
Definition lists.h:24
INLINE_THIS void Init(int l=0)
VAR omBin slists_bin
Definition lists.cc:23
slists * lists

◆ ssiReadList_S()

static lists ssiReadList_S ( char **  s,
const ring  R 
)
static

Definition at line 1146 of file ssiLink.cc.

1147{
1148 int nr;
1149 nr=s_readint_S(s);
1151 L->Init(nr);
1152
1153 int i;
1154 leftv v;
1155 for(i=0;i<=L->nr;i++)
1156 {
1157 v=ssiRead1_S(s,R);
1158 memcpy(&(L->m[i]),v,sizeof(*v));
1160 }
1161 return L;
1162}

◆ ssiReadMatrix()

static matrix ssiReadMatrix ( ssiInfo d)
static

Definition at line 1027 of file ssiLink.cc.

1028{
1029 int n,m;
1030 m=s_readint(d->f_read);
1031 n=s_readint(d->f_read);
1032 matrix M=mpNew(m,n);
1033 poly p;
1034 for(int i=1;i<=MATROWS(M);i++)
1035 for(int j=1;j<=MATCOLS(M);j++)
1036 {
1037 p=ssiReadPoly(d);
1038 MATELEM(M,i,j)=p;
1039 }
1040 return M;
1041}
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
#define MATROWS(i)
Definition matpol.h:26
#define MATCOLS(i)
Definition matpol.h:27

◆ ssiReadMatrix_R_S() [1/2]

static matrix ssiReadMatrix_R_S ( char **  s,
const ring  R 
)
static

Definition at line 1042 of file ssiLink.cc.

1043{
1044 int n,m;
1045 m=s_readint_S(s);
1046 n=s_readint_S(s);
1047 matrix M=mpNew(m,n);
1048 poly p;
1049 for(int i=1;i<=MATROWS(M);i++)
1050 for(int j=1;j<=MATCOLS(M);j++)
1051 {
1053 MATELEM(M,i,j)=p;
1054 }
1055 return M;
1056}

◆ ssiReadMatrix_R_S() [2/2]

matrix ssiReadMatrix_R_S ( char s,
const ring  R 
)

Definition at line 1057 of file ssiLink.cc.

1058{
1059 return ssiReadMatrix_R_S(&s,R);
1060}

◆ ssiReadNumber()

static number ssiReadNumber ( ssiInfo d)
static

Definition at line 742 of file ssiLink.cc.

743{
744 return ssiReadNumber_CF(d,d->r->cf);
745}

◆ ssiReadNumber_CF()

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

Definition at line 675 of file ssiLink.cc.

676{
677 if (cf->cfReadFd!=ndReadFd)
678 {
679 return n_ReadFd(d,cf);
680 }
681 else if (getCoeffType(cf) == n_transExt)
682 {
683 // poly poly
685 p_Delete(&NUM(f),cf->extRing);
686 NUM(f)=ssiReadPoly_R(d,cf->extRing);
687 DEN(f)=ssiReadPoly_R(d,cf->extRing);
688 return (number)f;
689 }
690 else if (getCoeffType(cf) == n_algExt)
691 {
692 // poly
693 return (number)ssiReadPoly_R(d,cf->extRing);
694 }
695 else WerrorS("coeffs not implemented in ssiReadNumber");
696 return NULL;
697}
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:975
@ 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:431
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:541
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

◆ ssiReadNumber_CF_S()

static number ssiReadNumber_CF_S ( char **  s,
const coeffs  cf 
)
static

Definition at line 699 of file ssiLink.cc.

700{
701 if (cf->cfReadFd_S!=ndReadFd_S)
702 {
703 return n_ReadFd_S(s,cf);
704 }
705 else if (getCoeffType(cf) == n_transExt)
706 {
707 // poly poly
709 p_Delete(&NUM(f),cf->extRing);
710 NUM(f)=ssiReadPoly_R_S(s,cf->extRing);
711 DEN(f)=ssiReadPoly_R_S(s,cf->extRing);
712 return (number)f;
713 }
714 else if (getCoeffType(cf) == n_algExt)
715 {
716 // poly
717 return (number)ssiReadPoly_R_S(s,cf->extRing);
718 }
719 else WerrorS("coeffs not implemented in ssiReadNumber");
720 return NULL;
721}
static FORCE_INLINE number n_ReadFd_S(char **s, const coeffs r)
Definition coeffs.h:977
number ndReadFd_S(char **, const coeffs r)
Definition numbers.cc:156

◆ ssiReadPoly()

static poly ssiReadPoly ( ssiInfo d)
static

Definition at line 981 of file ssiLink.cc.

982{
983 return ssiReadPoly_R(d,d->r);
984}

◆ ssiReadPoly_R()

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

Definition at line 917 of file ssiLink.cc.

918{
919// < # of terms> < term1> < .....
920 int n,i,l;
921 n=ssiReadInt(d); // # of terms
922 //Print("poly: terms:%d\n",n);
923 poly p;
924 poly ret=NULL;
925 poly prev=NULL;
926 for(l=0;l<n;l++) // read n terms
927 {
928// coef,comp.exp1,..exp N
929 p=p_Init(r,r->PolyBin);
930 pSetCoeff0(p,ssiReadNumber_CF(d,r->cf));
931 int D;
932 D=s_readint(d->f_read);
933 p_SetComp(p,D,r);
934 for(i=1;i<=rVar(r);i++)
935 {
936 D=s_readint(d->f_read);
937 p_SetExp(p,i,D,r);
938 }
939 p_Setm(p,r);
940 p_Test(p,r);
941 if (ret==NULL) ret=p;
942 else pNext(prev)=p;
943 prev=p;
944 }
945 return ret;
946}
#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:1341
#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

◆ ssiReadPoly_R_S()

static poly ssiReadPoly_R_S ( char **  s,
const ring  r 
)
static

Definition at line 948 of file ssiLink.cc.

949{
950// < # of terms> < term1> < .....
951 int n,i,l;
952 char* c=*s;
953 n=s_readint_S(&c); // # of terms
954 poly p;
955 poly ret=NULL;
956 poly prev=NULL;
957 for(l=0;l<n;l++) // read n terms
958 {
959// coef,comp.exp1,..exp N
960 p=p_Init(r,r->PolyBin);
961 number cf=ssiReadNumber_CF_S(&c,r->cf);
962 pSetCoeff0(p,cf);
963 int D;
964 D=s_readint_S(&c);
965 p_SetComp(p,D,r);
966 for(i=1;i<=rVar(r);i++)
967 {
968 D=s_readint_S(&c);
969 p_SetExp(p,i,D,r);
970 }
971 p_Setm(p,r);
972 p_Test(p,r);
973 if (ret==NULL) ret=p;
974 else pNext(prev)=p;
975 prev=p;
976 }
977 *s=c;
978 return ret;
979}

◆ ssiReadPoly_S()

poly ssiReadPoly_S ( char s,
const ring  r 
)

Definition at line 986 of file ssiLink.cc.

987{
988 return ssiReadPoly_R_S(&s,r);
989}

◆ ssiReadProc()

static procinfov ssiReadProc ( const ssiInfo d)
static

Definition at line 1108 of file ssiLink.cc.

1109{
1110 char *s=ssiReadString(d);
1112 p->language=LANG_SINGULAR;
1113 p->libname=omStrDup("");
1114 p->procname=omStrDup("");
1115 p->data.s.body=s;
1116 return p;
1117}
procinfo * procinfov
Definition structs.h:56
VAR omBin procinfo_bin
Definition subexpr.cc:42

◆ ssiReadProc_S()

static procinfov ssiReadProc_S ( char **  s)
static

Definition at line 1118 of file ssiLink.cc.

1119{
1120 char *st=ssiReadString_S(s);
1122 p->language=LANG_SINGULAR;
1123 p->libname=omStrDup("");
1124 p->procname=omStrDup("");
1125 p->data.s.body=st;
1126 return p;
1127}

◆ ssiReadRing()

static ring ssiReadRing ( ssiInfo d)
static

Definition at line 747 of file ssiLink.cc.

748{
749/* syntax is <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... <Q-ideal> */
750 int ch;
751 int new_ref=-1;
752 ch=s_readint(d->f_read);
753 if (ch==-6)
754 {
756 ch=s_readint(d->f_read);
757 }
758 if (ch==-5)
759 {
760 int index=s_readint(d->f_read);
761 ring r=d->rings[index];
762 rIncRefCnt(r);
763 return r;
764 }
765 if (ch==-4)
766 return NULL;
767 int N=s_readint(d->f_read);
768 char **names;
769 coeffs cf=NULL;
770 if (ch==-3)
771 {
772 char *cf_name=ssiReadString(d);
774 if (cf==NULL)
775 {
776 Werror("cannot find cf:%s",cf_name);
778 return NULL;
779 }
780 }
781 if (N!=0)
782 {
783 names=(char**)omAlloc(N*sizeof(char*));
784 for(int i=0;i<N;i++)
785 {
786 names[i]=ssiReadString(d);
787 }
788 }
789 // read the orderings:
790 int num_ord; // number of orderings
793 int *block0=(int *)omAlloc0((num_ord+1)*sizeof(int));
794 int *block1=(int *)omAlloc0((num_ord+1)*sizeof(int));
795 int **wvhdl=(int**)omAlloc0((num_ord+1)*sizeof(int*));
796 for(int i=0;i<num_ord;i++)
797 {
798 ord[i]=(rRingOrder_t)s_readint(d->f_read);
799 block0[i]=s_readint(d->f_read);
800 block1[i]=s_readint(d->f_read);
801 switch(ord[i])
802 {
803 case ringorder_a:
804 case ringorder_wp:
805 case ringorder_Wp:
806 case ringorder_ws:
807 case ringorder_Ws:
808 case ringorder_aa:
809 {
810 int s=block1[i]-block0[i]+1; // #vars
811 wvhdl[i]=(int*)omAlloc(s*sizeof(int));
812 for(int ii=0;ii<s;ii++)
813 wvhdl[i][ii]=s_readint(d->f_read);
814 }
815 break;
816 case ringorder_M:
817 {
818 int s=block1[i]-block0[i]+1; // #vars
819 wvhdl[i]=(int*)omAlloc(s*s*sizeof(int));
820 for(int ii=0;ii<s*s;ii++)
821 {
822 wvhdl[i][ii]=s_readint(d->f_read);
823 }
824 }
825 break;
826 case ringorder_a64:
827 case ringorder_L:
828 case ringorder_IS:
829 Werror("ring order not implemented for ssi:%d",ord[i]);
830 break;
831
832 default: break;
833 }
834 }
835 if (N==0)
836 {
837 omFree(ord);
838 omFree(block0);
839 omFree(block1);
840 omFree(wvhdl);
841 return NULL;
842 }
843 else
844 {
845 ring r=NULL;
846 if (ch>=0) /* Q, Z/p */
847 r=rDefault(ch,N,names,num_ord,ord,block0,block1,wvhdl);
848 else if (ch==-1) /* trans ext. */
849 {
851 T.r=ssiReadRing(d);
852 if (T.r==NULL) return NULL;
854 r=rDefault(cf,N,names,num_ord,ord,block0,block1,wvhdl);
855 }
856 else if (ch==-2) /* alg ext. */
857 {
859 T.r=ssiReadRing(d); /* includes qideal */
860 if (T.r==NULL) return NULL;
862 r=rDefault(cf,N,names,num_ord,ord,block0,block1,wvhdl);
863 }
864 else if (ch==-3)
865 {
866 r=rDefault(cf,N,names,num_ord,ord,block0,block1,wvhdl);
867 }
868 else
869 {
870 Werror("ssi: read unknown coeffs type (%d)",ch);
871 for(int i=0;i<N;i++)
872 {
873 omFree(names[i]);
874 }
875 omFreeSize(names,N*sizeof(char*));
876 return NULL;
877 }
878 ideal q=ssiReadIdeal_R(d,r);
879 if (IDELEMS(q)==0) omFreeBin(q,sip_sideal_bin);
880 else r->qideal=q;
881 for(int i=0;i<N;i++)
882 {
883 omFree(names[i]);
884 }
885 omFreeSize(names,N*sizeof(char*));
886 rIncRefCnt(r);
887 // check if such ring already exist as ssiRing*
888 char name[20];
889 int nr=0;
890 idhdl h=NULL;
891 loop
892 {
893 snprintf(name,20,"ssiRing%d",nr); nr++;
894 h=IDROOT->get(name, 0);
895 if (h==NULL)
896 {
897 break;
898 }
899 else if ((IDTYP(h)==RING_CMD)
900 && (r!=IDRING(h))
901 && (rEqual(r,IDRING(h),1)))
902 {
903 rDelete(r);
904 r=rIncRefCnt(IDRING(h));
905 break;
906 }
907 }
908 if (new_ref!=-1)
909 {
910 d->rings[new_ref]=r;
911 rIncRefCnt(r);
912 }
913 return r;
914 }
915}
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:412
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:640
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 1304 of file ssiLink.cc.

1305{
1306 ssiInfo *d=(ssiInfo*)l->data;
1307 int what=s_readint(d->f_read);
1308 switch(what)
1309 {
1310 case 0: // bitmask
1311 {
1312 int lb=s_readint(d->f_read);
1313 unsigned long bm=~0L;
1314 bm=bm<<lb;
1315 bm=~bm;
1316 rUnComplete(d->r);
1317 d->r->bitmask=bm;
1318 rComplete(d->r);
1319 break;
1320 }
1321 case 1: // LPRing
1322 {
1323 int lb=s_readint(d->f_read);
1324 int isLPring=s_readint(d->f_read);
1325 unsigned long bm=~0L;
1326 bm=bm<<lb;
1327 bm=~bm;
1328 rUnComplete(d->r);
1329 d->r->bitmask=bm;
1330 d->r->isLPring=isLPring;
1331 rComplete(d->r);
1332 break;
1333 }
1334 case 2: // Plural rings
1335 {
1336 matrix C=ssiReadMatrix(d);
1338 nc_CallPlural(C,D,NULL,NULL,d->r,true,true,false,d->r,false);
1339 break;
1340 }
1341 }
1342}
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:3527
void rUnComplete(ring r)
Definition ring.cc:4057

◆ ssiReadString()

static char * ssiReadString ( const ssiInfo d)
static

Definition at line 642 of file ssiLink.cc.

643{
644 char *buf;
645 int l;
646 l=s_readint(d->f_read);
647 buf=(char*)omAlloc0(l+1);
648 int throwaway =s_getc(d->f_read); /* skip ' '*/
650 //if (throwaway!=l) printf("want %d, got %d bytes\n",l,throwaway);
651 buf[l]='\0';
652 return buf;
653}
int s_readbytes(char *buff, int len, s_buff F)
Definition s_buff.cc:203

◆ ssiReadString_S()

static char * ssiReadString_S ( char **  s)
static

Definition at line 654 of file ssiLink.cc.

655{
656 char *buf;
657 int l;
658 l=s_readint_S(s);
659 buf=(char*)omAlloc0(l+1);
660 (*s)++; /* skip ' '*/
661 for(int i=0;i<l;i++) { buf[i]=(**s); (*s)++; }
662 buf[l]='\0';
663 return buf;
664}

◆ ssiReservePort()

int ssiReservePort ( int  clients)

Definition at line 2862 of file ssiLink.cc.

2863{
2864 if (ssiReserved_P!=0)
2865 {
2866 WerrorS("ERROR already a reserved port requested");
2867 return 0;
2868 }
2869 int portno;
2871 if(ssiReserved_sockfd < 0)
2872 {
2873 WerrorS("ERROR opening socket");
2874 return 0;
2875 }
2876 memset((char *) &ssiResverd_serv_addr,0, sizeof(ssiResverd_serv_addr));
2877 portno = 1025;
2878 ssiResverd_serv_addr.sin_family = AF_INET;
2879 ssiResverd_serv_addr.sin_addr.s_addr = INADDR_ANY;
2880 do
2881 {
2882 portno++;
2883 ssiResverd_serv_addr.sin_port = htons(portno);
2884 if(portno > 50000)
2885 {
2886 WerrorS("ERROR on binding (no free port available?)");
2887 return 0;
2888 }
2889 }
2894 return portno;
2895}

◆ ssiSetCurrRing()

static BOOLEAN ssiSetCurrRing ( const ring  r)
static

Definition at line 80 of file ssiLink.cc.

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

◆ ssiSetRing()

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

Definition at line 2220 of file ssiLink.cc.

2221{
2222 if(SI_LINK_W_OPEN_P(l)==0)
2224 ssiInfo *d = (ssiInfo *)l->data;
2225 if (d->r!=r)
2226 {
2227 if (send)
2228 {
2229 fputs("15 ",d->f_write);
2230 ssiWriteRing(d,r);
2231 }
2232 d->r=r;
2233 }
2234 if (currRing!=r) rChangeCurrRing(r);
2235 return FALSE;
2236}

◆ ssiWrite()

BOOLEAN ssiWrite ( si_link  l,
leftv  data 
)

Definition at line 2239 of file ssiLink.cc.

2240{
2241 if(SI_LINK_W_OPEN_P(l)==0)
2243 if (strcmp(l->mode,"string")==0) return TRUE;
2244 ssiInfo *d = (ssiInfo *)l->data;
2245 d->level++;
2246 //FILE *fich=d->f;
2247 while (data!=NULL)
2248 {
2249 int tt=data->Typ();
2250 void *dd=data->Data();
2251 attr *aa=data->Attribute();
2252 if ((aa!=NULL) && ((*aa)!=NULL)) // n user attributes
2253 {
2254 attr a=*aa;
2255 int n=0;
2256 while(a!=NULL) { n++; a=a->next;}
2257 fprintf(d->f_write,"21 %d %d ",data->flag,n);
2258 }
2259 else if (data->flag!=0) // only "flag" attributes
2260 {
2261 fprintf(d->f_write,"21 %d 0 ",data->flag);
2262 }
2263 if ((dd==NULL) && (data->name!=NULL) && (tt==0)) tt=DEF_CMD;
2264 // return pure undefined names as def
2265
2266 switch(tt /*data->Typ()*/)
2267 {
2268 case 0: /*error*/
2269 case NONE/* nothing*/:fputs("16 ",d->f_write);
2270 break;
2271 case STRING_CMD: fputs("2 ",d->f_write);
2272 ssiWriteString(d,(char *)dd);
2273 break;
2274 case INT_CMD: fputs("1 ",d->f_write);
2275 ssiWriteInt(d,(int)(long)dd);
2276 break;
2277 case BIGINT_CMD:fputs("4 ",d->f_write);
2279 break;
2280 case NUMBER_CMD:
2281 if (d->r!=currRing)
2282 {
2283 fputs("15 ",d->f_write);
2285 if (d->level<=1) fputc('\n',d->f_write);
2286 }
2287 fputs("3 ",d->f_write);
2289 break;
2290 case RING_CMD:fputs("5 ",d->f_write);
2291 ssiWriteRing(d,(ring)dd);
2292 break;
2293 case BUCKET_CMD:
2294 {
2296 if (d->r!=sBucketGetRing(b))
2297 {
2298 fputs("15 ",d->f_write);
2300 if (d->level<=1) fputc('\n',d->f_write);
2301 }
2302 fputs("6 ",d->f_write);
2304 break;
2305 }
2306 case POLY_CMD:
2307 case VECTOR_CMD:
2308 if (d->r!=currRing)
2309 {
2310 fputs("15 ",d->f_write);
2312 if (d->level<=1) fputc('\n',d->f_write);
2313 }
2314 if(tt==POLY_CMD) fputs("6 ",d->f_write);
2315 else fputs("9 ",d->f_write);
2316 ssiWritePoly(d,(poly)dd);
2317 break;
2318 case IDEAL_CMD:
2319 case MODUL_CMD:
2320 case MATRIX_CMD:
2321 case SMATRIX_CMD:
2322 if (d->r!=currRing)
2323 {
2324 fputs("15 ",d->f_write);
2326 if (d->level<=1) fputc('\n',d->f_write);
2327 }
2328 if(tt==IDEAL_CMD) fputs("7 ",d->f_write);
2329 else if(tt==MATRIX_CMD) fputs("8 ",d->f_write);
2330 else /* tt==MODUL_CMD, SMATRIX_CMD*/
2331 {
2332 ideal M=(ideal)dd;
2333 if (tt==MODUL_CMD)
2334 fprintf(d->f_write,"10 %d ",(int)M->rank);
2335 else /*(tt==SMATRIX_CMD)*/
2336 fprintf(d->f_write,"22 %d ",(int)M->rank);
2337 }
2339 break;
2340 case COMMAND:
2341 fputs("11 ",d->f_write);
2343 break;
2344 case DEF_CMD: /* not evaluated stuff in quotes */
2345 fputs("12 ",d->f_write);
2346 ssiWriteString(d,data->Name());
2347 break;
2348 case PROC_CMD:
2349 fputs("13 ",d->f_write);
2351 break;
2352 case LIST_CMD:
2353 fputs("14 ",d->f_write);
2355 break;
2356 case INTVEC_CMD:
2357 fputs("17 ",d->f_write);
2358 ssiWriteIntvec(d,(intvec *)dd);
2359 break;
2360 case INTMAT_CMD:
2361 fputs("18 ",d->f_write);
2362 ssiWriteIntmat(d,(intvec *)dd);
2363 break;
2364 case BIGINTMAT_CMD:
2365 fputs("19 ",d->f_write);
2367 break;
2368 case BIGINTVEC_CMD:
2369 fputs("24 ",d->f_write);
2371 break;
2372 default:
2373 if (tt>MAX_TOK)
2374 {
2376 fputs("20 ",d->f_write);
2377 b->blackbox_serialize(b,dd,l);
2378 }
2379 else
2380 {
2381 Werror("not implemented (t:%d, rtyp:%d)",tt, data->rtyp);
2382 d->level=0;
2383 return TRUE;
2384 }
2385 break;
2386 }
2387 if (d->level<=1) { fputc('\n',d->f_write); fflush(d->f_write); }
2388 data=data->next;
2389 }
2390 d->level--;
2391 return FALSE;
2392}
Definition attrib.h:21
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

◆ ssiWrite2()

BOOLEAN ssiWrite2 ( si_link  l,
leftv  res,
leftv  u 
)

Definition at line 3179 of file ssiLink.cc.

3180{
3181 if((strcmp(l->mode,"string")==0)
3182 &&(u->Typ()==STRING_CMD))
3183 {
3184 StringSetS("");
3185 ssiWrite_S(u, currRing);
3186 res->data=(void*)StringEndS();
3187 res->rtyp=STRING_CMD;
3188 return res->data==NULL;
3189 }
3190 return TRUE;
3191}
void StringSetS(const char *st)
Definition reporter.cc:128
char * StringEndS()
Definition reporter.cc:151

◆ ssiWrite_S()

void ssiWrite_S ( leftv  data,
const ring  R 
)

Definition at line 2393 of file ssiLink.cc.

2394{
2395 while(data!=NULL)
2396 {
2397 int tt=data->Typ();
2398 void *dd=data->Data();
2399 switch(tt /*data->Typ()*/)
2400 {
2401 case 0: /*error*/
2402 case NONE/* nothing*/:StringAppendS("16 ");
2403 break;
2404 case INT_CMD: StringAppendS("1 ");
2405 ssiWriteInt_S((int)(long)dd);
2406 break;
2407 case STRING_CMD: StringAppendS("2 ");
2408 ssiWriteString_S((char *)dd);
2409 break;
2410 case BIGINT_CMD:StringAppendS("4 ");
2412 break;
2413 case NUMBER_CMD:
2414 StringAppendS("3 ");
2416 break;
2417 #if 0
2418 case RING_CMD:fputs("5 ",d->f_write);
2419 ssiWriteRing(d,(ring)dd);
2420 break;
2421 #endif
2422 case BUCKET_CMD:
2423 {
2425 StringAppendS("6 ");
2427 break;
2428 }
2429 case POLY_CMD:
2430 case VECTOR_CMD:
2431 if(tt==POLY_CMD) StringAppendS("6 ");
2432 else StringAppendS("9 ");
2433 ssiWritePoly_R_S((poly)dd,R);
2434 break;
2435 case IDEAL_CMD:
2436 case MODUL_CMD:
2437 case MATRIX_CMD:
2438 case SMATRIX_CMD:
2439 if(tt==IDEAL_CMD) StringAppendS("7 ");
2440 else if(tt==MATRIX_CMD) StringAppendS("8 ");
2441 else /* tt==MODUL_CMD, SMATRIX_CMD*/
2442 {
2443 ideal M=(ideal)dd;
2444 if (tt==MODUL_CMD)
2445 {
2446 StringAppendS("10 ");StringAppend("%d ",(int)M->rank);
2447 }
2448 else /*(tt==SMATRIX_CMD)*/
2449 {
2450 StringAppendS("22 ");StringAppend("%d ",(int)M->rank);
2451 }
2452 }
2454 break;
2455 #if 0
2456 case COMMAND:
2457 fputs("11 ",d->f_write);
2459 break;
2460 #endif
2461 case DEF_CMD: /* not evaluated stuff in quotes */
2462 StringAppendS("12 ");
2463 ssiWriteString_S(data->Name());
2464 break;
2465 case PROC_CMD:
2466 StringAppendS("13 ");
2468 break;
2469 case LIST_CMD:
2470 StringAppendS("14 ");
2472 break;
2473 case INTVEC_CMD:
2474 StringAppendS("17 ");
2476 break;
2477 case INTMAT_CMD:
2478 StringAppendS("18 ");
2480 break;
2481 case BIGINTMAT_CMD:
2482 StringAppendS("19 ");
2484 break;
2485 case BIGINTVEC_CMD:
2486 StringAppendS("24 ");
2488 break;
2489 default:
2490 #if 0
2491 if (tt>MAX_TOK)
2492 {
2494 fputs("20 ",d->f_write);
2495 b->blackbox_serialize(b,dd,l);
2496 }
2497 else
2498 #endif
2499 {
2500 Werror("not implemented (t:%d, rtyp:%d)",tt, data->rtyp);
2501 return;
2502 }
2503 break;
2504 }
2505 data=data->next;
2506 }
2507}
#define StringAppend
Definition emacs.cc:79
void StringAppendS(const char *st)
Definition reporter.cc:107

◆ ssiWriteBigInt()

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

Definition at line 174 of file ssiLink.cc.

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

◆ ssiWriteBigInt_S()

static void ssiWriteBigInt_S ( const number  n)
static

Definition at line 178 of file ssiLink.cc.

179{
181}
static FORCE_INLINE void n_WriteFd_S(number a, const coeffs r)
Definition coeffs.h:971

◆ ssiWriteBigintmat()

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

Definition at line 604 of file ssiLink.cc.

605{
606 fprintf(d->f_write,"%d %d ",v->rows(),v->cols());
607 int i;
608 for(i=0;i<v->length();i++)
609 {
610 ssiWriteBigInt(d,(*v)[i]);
611 }
612}

◆ ssiWriteBigintmat_S()

static void ssiWriteBigintmat_S ( bigintmat v)
static

Definition at line 613 of file ssiLink.cc.

614{
615 StringAppend("%d %d ",v->rows(),v->cols());
616 int i;
617 for(i=0;i<v->length();i++)
618 {
619 ssiWriteBigInt_S((*v)[i]);
620 }
621}

◆ ssiWriteBigintvec()

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

Definition at line 623 of file ssiLink.cc.

624{
625 fprintf(d->f_write,"%d ",v->cols());
626 int i;
627 for(i=0;i<v->length();i++)
628 {
629 ssiWriteBigInt(d,(*v)[i]);
630 }
631}

◆ ssiWriteBigintvec_S()

static void ssiWriteBigintvec_S ( bigintmat v)
static

Definition at line 632 of file ssiLink.cc.

633{
634 StringAppend("%d ",v->cols());
635 int i;
636 for(i=0;i<v->length();i++)
637 {
638 ssiWriteBigInt_S((*v)[i]);
639 }
640}

◆ ssiWriteCommand()

static void ssiWriteCommand ( si_link  l,
command  D 
)
static

Definition at line 514 of file ssiLink.cc.

515{
516 ssiInfo *d=(ssiInfo*)l->data;
517 // syntax: <num ops> <operation> <op1> <op2> ....
518 fprintf(d->f_write,"%d %d ",D->argc,D->op);
519 if (D->argc >0) ssiWrite(l, &(D->arg1));
520 if (D->argc < 4)
521 {
522 if (D->argc >1) ssiWrite(l, &(D->arg2));
523 if (D->argc >2) ssiWrite(l, &(D->arg3));
524 }
525}

◆ ssiWriteIdeal()

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

Definition at line 491 of file ssiLink.cc.

492{
493 ssiWriteIdeal_R(d,typ,I,d->r);
494}

◆ ssiWriteIdeal_R()

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

Definition at line 445 of file ssiLink.cc.

446{
447 // syntax: 7 # of elements <poly 1> <poly2>.....(ideal,module,smatrix)
448 // syntax: 8 <rows> <cols> <poly 1> <poly2>.....(matrix)
449 // syntax
450 matrix M=(matrix)I;
451 int mn;
452 if (typ==MATRIX_CMD)
453 {
454 mn=MATROWS(M)*MATCOLS(M);
455 fprintf(d->f_write,"%d %d ", MATROWS(M),MATCOLS(M));
456 }
457 else
458 {
459 mn=IDELEMS(I);
460 fprintf(d->f_write,"%d ",IDELEMS(I));
461 }
462
463 for(int i=0;i<mn;i++)
464 {
465 ssiWritePoly_R(d,I->m[i],R);
466 }
467}
ip_smatrix * matrix
Definition matpol.h:43

◆ ssiWriteIdeal_R_S()

static void ssiWriteIdeal_R_S ( int  typ,
const ideal  I,
const ring  R 
)
static

Definition at line 468 of file ssiLink.cc.

469{
470 // syntax: 7 # of elements <poly 1> <poly2>.....(ideal,module,smatrix)
471 // syntax: 8 <rows> <cols> <poly 1> <poly2>.....(matrix)
472 // syntax
473 matrix M=(matrix)I;
474 int mn;
475 if (typ==MATRIX_CMD)
476 {
477 mn=MATROWS(M)*MATCOLS(M);
478 StringAppend("%d %d ", MATROWS(M),MATCOLS(M));
479 }
480 else
481 {
482 mn=IDELEMS(I);
483 StringAppend("%d ",IDELEMS(I));
484 }
485
486 for(int i=0;i<mn;i++)
487 {
488 ssiWritePoly_R_S(I->m[i],R);
489 }
490}

◆ ssiWriteIdeal_S()

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

Definition at line 495 of file ssiLink.cc.

496{
497 StringSetS("");
499 return StringEndS();
500}

◆ ssiWriteInt()

void ssiWriteInt ( const ssiInfo d,
const int  i 
)

Definition at line 156 of file ssiLink.cc.

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

◆ ssiWriteInt_S()

void ssiWriteInt_S ( const int  i)

Definition at line 160 of file ssiLink.cc.

161{
162 StringAppend("%d ",i);
163}

◆ ssiWriteIntmat()

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

Definition at line 585 of file ssiLink.cc.

586{
587 fprintf(d->f_write,"%d %d ",v->rows(),v->cols());
588 int i;
589 for(i=0;i<v->length();i++)
590 {
591 fprintf(d->f_write,"%d ",(*v)[i]);
592 }
593}

◆ ssiWriteIntmat_S()

static void ssiWriteIntmat_S ( intvec v)
static

Definition at line 594 of file ssiLink.cc.

595{
596 StringAppend("%d %d ",v->rows(),v->cols());
597 int i;
598 for(i=0;i<v->length();i++)
599 {
600 StringAppend("%d ",(*v)[i]);
601 }
602}

◆ ssiWriteIntvec()

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

Definition at line 567 of file ssiLink.cc.

568{
569 fprintf(d->f_write,"%d ",v->length());
570 int i;
571 for(i=0;i<v->length();i++)
572 {
573 fprintf(d->f_write,"%d ",(*v)[i]);
574 }
575}

◆ ssiWriteIntvec_S()

static void ssiWriteIntvec_S ( intvec v)
static

Definition at line 576 of file ssiLink.cc.

577{
578 StringAppend("%d ",v->length());
579 int i;
580 for(i=0;i<v->length();i++)
581 {
582 StringAppend("%d ",(*v)[i]);
583 }
584}

◆ ssiWriteList()

static void ssiWriteList ( si_link  l,
lists  dd 
)
static

Definition at line 546 of file ssiLink.cc.

547{
548 ssiInfo *d=(ssiInfo*)l->data;
549 int Ll=dd->nr;
550 fprintf(d->f_write,"%d ",Ll+1);
551 int i;
552 for(i=0;i<=Ll;i++)
553 {
554 ssiWrite(l,&(dd->m[i]));
555 }
556}

◆ ssiWriteList_S()

static void ssiWriteList_S ( lists  dd,
const ring  R 
)
static

Definition at line 557 of file ssiLink.cc.

558{
559 int Ll=dd->nr;
560 StringAppend("%d ",Ll+1);
561 int i;
562 for(i=0;i<=Ll;i++)
563 {
564 ssiWrite_S(&(dd->m[i]),R);
565 }
566}

◆ ssiWriteMatrix_S()

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

Definition at line 501 of file ssiLink.cc.

502{
503 StringSetS("");
505 return StringEndS();
506}

◆ ssiWriteModule_S()

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

Definition at line 507 of file ssiLink.cc.

508{
509 StringSetS("");
511 return StringEndS();
512}

◆ ssiWriteNumber()

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

Definition at line 239 of file ssiLink.cc.

240{
241 ssiWriteNumber_CF(d,n,d->r->cf);
242}

◆ ssiWriteNumber_CF()

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

Definition at line 183 of file ssiLink.cc.

184{
185 // syntax is as follows:
186 // case 1 Z/p: 3 <int>
187 // case 2 Q: 3 4 <int>
188 // or 3 0 <mpz_t nominator> <mpz_t denominator>
189 // or 3 1 dto.
190 // or 3 3 <mpz_t nominator>
191 // or 3 5 <mpz_t raw nom.> <mpz_t raw denom.>
192 // or 3 6 <mpz_t raw nom.> <mpz_t raw denom.>
193 // or 3 8 <mpz_t raw nom.>
195 {
197 ssiWritePoly_R(d,NUM(f),cf->extRing);
198 ssiWritePoly_R(d,DEN(f),cf->extRing);
199 }
200 else if (getCoeffType(cf)==n_algExt)
201 {
202 ssiWritePoly_R(d,(poly)n,cf->extRing);
203 }
204 else if (cf->cfWriteFd!=NULL)
205 {
206 n_WriteFd(n,d,cf);
207 }
208 else WerrorS("coeff field not implemented");
209}

◆ ssiWriteNumber_CF_S()

static void ssiWriteNumber_CF_S ( const number  n,
const coeffs  cf 
)
static

Definition at line 211 of file ssiLink.cc.

212{
213 // syntax is as follows:
214 // case 1 Z/p: 3 <int>
215 // case 2 Q: 3 4 <int>
216 // or 3 0 <mpz_t nominator> <mpz_t denominator>
217 // or 3 1 dto.
218 // or 3 3 <mpz_t nominator>
219 // or 3 5 <mpz_t raw nom.> <mpz_t raw denom.>
220 // or 3 6 <mpz_t raw nom.> <mpz_t raw denom.>
221 // or 3 8 <mpz_t raw nom.>
223 {
225 ssiWritePoly_R_S(NUM(f),cf->extRing);
226 ssiWritePoly_R_S(DEN(f),cf->extRing);
227 }
228 else if (getCoeffType(cf)==n_algExt)
229 {
230 ssiWritePoly_R_S((poly)n,cf->extRing);
231 }
232 else if (cf->cfWriteFd_S!=NULL)
233 {
234 n_WriteFd_S(n,cf);
235 }
236 else WerrorS("coeff field not implemented");
237}

◆ ssiWritePoly()

static void ssiWritePoly ( const ssiInfo d,
poly  p 
)
static

Definition at line 434 of file ssiLink.cc.

435{
436 ssiWritePoly_R(d,p,d->r);
437}

◆ ssiWritePoly_R()

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

Definition at line 399 of file ssiLink.cc.

400{
401 fprintf(d->f_write,"%d ",pLength(p));//number of terms
402
403 while(p!=NULL)
404 {
405 ssiWriteNumber_CF(d,pGetCoeff(p),r->cf);
406 //nWrite(fich,pGetCoeff(p));
407 fprintf(d->f_write,"%ld ",p_GetComp(p,r));//component
408
409 for(int j=1;j<=rVar(r);j++)
410 {
411 fprintf(d->f_write,"%ld ",p_GetExp(p,j,r ));//x^j
412 }
413 pIter(p);
414 }
415}
#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

◆ ssiWritePoly_R_S()

static void ssiWritePoly_R_S ( poly  p,
const ring  r 
)
static

Definition at line 416 of file ssiLink.cc.

417{
418 StringAppend("%d ",pLength(p));//number of terms
419
420 while(p!=NULL)
421 {
423 //nWrite(fich,pGetCoeff(p));
424 StringAppend("%ld ",p_GetComp(p,r));//component
425
426 for(int j=1;j<=rVar(r);j++)
427 {
428 StringAppend("%ld ",p_GetExp(p,j,r ));//x^j
429 }
430 pIter(p);
431 }
432}

◆ ssiWritePoly_S()

char * ssiWritePoly_S ( poly  p,
const ring  r 
)

Definition at line 439 of file ssiLink.cc.

440{
441 StringSetS("");
443 return StringEndS();
444}

◆ ssiWriteProc()

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

Definition at line 527 of file ssiLink.cc.

528{
529 if (p->data.s.body==NULL)
531 if (p->data.s.body!=NULL)
532 ssiWriteString(d,p->data.s.body);
533 else
534 ssiWriteString(d,"");
535}
char * iiGetLibProcBuffer(procinfo *pi, int part)
Definition iplib.cc:197

◆ ssiWriteProc_S()

static void ssiWriteProc_S ( procinfov  p)
static

Definition at line 536 of file ssiLink.cc.

537{
538 if (p->data.s.body==NULL)
540 if (p->data.s.body!=NULL)
541 ssiWriteString_S(p->data.s.body);
542 else
544}

◆ ssiWriteRing()

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

Definition at line 374 of file ssiLink.cc.

375{
376 /* 5 <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... <extRing> <Q-ideal> */
377 /* ch=-1: transext, coeff ring follows */
378 /* ch=-2: algext, coeff ring and minpoly follows */
379 /* ch=-3: cf name follows */
380 /* ch=-4: NULL */
381 /* ch=-5: reference <int> */
382 /* ch=-6: new reference <int> <ring> */
383 if ((r==NULL)||(r->cf==NULL))
384 {
385 fputs("-4 ",d->f_write);
386 return;
387 }
388 if (r==currRing) // see recursive calls for transExt/algExt
389 {
390 if (d->r!=NULL) rKill(d->r);
391 d->r=r;
392 }
393 if (r!=NULL)
394 {
395 /*d->*/rIncRefCnt(r);
396 }
397 ssiWriteRing_R(d,r);
398}

◆ ssiWriteRing_R()

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

Definition at line 244 of file ssiLink.cc.

245{
246 /* 5 <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... <extRing> <Q-ideal> */
247 /* ch=-1: transext, coeff ring follows */
248 /* ch=-2: algext, coeff ring and minpoly follows */
249 /* ch=-3: cf name follows */
250 /* ch=-4: NULL*/
251 /* ch=-5: reference <int> */
252 /* ch=-6: new reference <int> <ring> */
253 if (r!=NULL)
254 {
255 for(int i=0;i<SI_RING_CACHE;i++)
256 {
257 if (d->rings[i]==r)
258 {
259 fprintf(d->f_write,"-5 %d ",i);
260 return;
261 }
262 }
263 for(int i=0;i<SI_RING_CACHE;i++)
264 {
265 if (d->rings[i]==NULL)
266 {
267 d->rings[i]=rIncRefCnt(r);
268 fprintf(d->f_write,"-6 %d ",i);
269 break;
270 }
271 }
272 if (rField_is_Q(r) || rField_is_Zp(r))
273 fprintf(d->f_write,"%d %d ",n_GetChar(r->cf),r->N);
274 else if (rFieldType(r)==n_transExt)
275 fprintf(d->f_write,"-1 %d ",r->N);
276 else if (rFieldType(r)==n_algExt)
277 fprintf(d->f_write,"-2 %d ",r->N);
278 else /*dummy*/
279 {
280 fprintf(d->f_write,"-3 %d ",r->N);
281 ssiWriteString(d,nCoeffName(r->cf));
282 }
283
284 int i;
285 for(i=0;i<r->N;i++)
286 {
287 fprintf(d->f_write,"%d %s ",(int)strlen(r->names[i]),r->names[i]);
288 }
289 /* number of orderings:*/
290 i=0;
291 // remember dummy ring: everything 0:
292 if (r->order!=NULL) while (r->order[i]!=0) i++;
293 fprintf(d->f_write,"%d ",i);
294 /* each ordering block: */
295 i=0;
296 if (r->order!=NULL) while(r->order[i]!=0)
297 {
298 fprintf(d->f_write,"%d %d %d ",r->order[i],r->block0[i], r->block1[i]);
299 switch(r->order[i])
300 {
301 case ringorder_a:
302 case ringorder_wp:
303 case ringorder_Wp:
304 case ringorder_ws:
305 case ringorder_Ws:
306 case ringorder_aa:
307 {
308 int s=r->block1[i]-r->block0[i]+1; // #vars
309 for(int ii=0;ii<s;ii++)
310 fprintf(d->f_write,"%d ",r->wvhdl[i][ii]);
311 }
312 break;
313 case ringorder_M:
314 {
315 int s=r->block1[i]-r->block0[i]+1; // #vars
316 for(int ii=0;ii<s*s;ii++)
317 {
318 fprintf(d->f_write,"%d ",r->wvhdl[i][ii]);
319 }
320 }
321 break;
322
323 case ringorder_a64:
324 case ringorder_L:
325 case ringorder_IS:
326 Werror("ring oder not implemented for ssi:%d",r->order[i]);
327 break;
328
329 default: break;
330 }
331 i++;
332 }
333 if ((rFieldType(r)==n_transExt)
334 || (rFieldType(r)==n_algExt))
335 {
336 ssiWriteRing_R(d,r->cf->extRing); /* includes alg.ext if rFieldType(r)==n_algExt */
337 }
338 /* Q-ideal :*/
339 if (r->qideal!=NULL)
340 {
341 ssiWriteIdeal_R(d,IDEAL_CMD,r->qideal,r);
342 }
343 else
344 {
345 fputs("0 ",d->f_write/*ideal with 0 entries */);
346 }
347 }
348 else /* dummy ring r==NULL*/
349 {
350 fputs("0 0 0 0 "/*,r->ch,r->N, blocks, q-ideal*/,d->f_write);
351 }
352 if (rIsLPRing(r)) // cannot be combined with 23 2
353 {
354 fprintf(d->f_write,"23 1 %d %d ",SI_LOG2(r->bitmask),r->isLPring);
355 }
356 else
357 {
358 unsigned long bm=0;
359 int b=0;
360 bm=rGetExpSize(bm,b,r->N);
361 if (r->bitmask!=bm)
362 {
363 fprintf(d->f_write,"23 0 %d ",SI_LOG2(r->bitmask));
364 }
365 if (rIsPluralRing(r))
366 {
367 fputs("23 2 ",d->f_write);
368 ssiWriteIdeal(d,MATRIX_CMD,(ideal)r->GetNC()->C);
369 ssiWriteIdeal(d,MATRIX_CMD,(ideal)r->GetNC()->D);
370 }
371 }
372}
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition coeffs.h:450
static FORCE_INLINE char * nCoeffName(const coeffs cf)
Definition coeffs.h:962
static unsigned long rGetExpSize(unsigned long bitmask, int &bits)
Definition ring.cc:2630
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 165 of file ssiLink.cc.

166{
167 fprintf(d->f_write,"%d %s ",(int)strlen(s),s);
168}

◆ ssiWriteString_S()

static void ssiWriteString_S ( const char s)
static

Definition at line 169 of file ssiLink.cc.

170{
171 StringAppend("%d %s ",(int)strlen(s),s);
172}

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

Definition at line 2897 of file ssiLink.cc.

◆ ssiReserved_Clients

STATIC_VAR int ssiReserved_Clients

Definition at line 2861 of file ssiLink.cc.

◆ ssiReserved_P

STATIC_VAR int ssiReserved_P =0

Definition at line 2858 of file ssiLink.cc.

◆ ssiReserved_sockfd

STATIC_VAR int ssiReserved_sockfd

Definition at line 2859 of file ssiLink.cc.

◆ ssiResverd_serv_addr

STATIC_VAR struct sockaddr_in ssiResverd_serv_addr

Definition at line 2860 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.