Functions
ssiLink.h File Reference
#include <Singular/links/silink.h>

Go to the source code of this file.

Functions

BOOLEAN ssiOpen (si_link l, short flag, leftv u)
 
BOOLEAN ssiWrite (si_link l, leftv v)
 
leftv ssiRead1 (si_link l)
 
leftv ssiRead2 (si_link l, leftv key)
 
BOOLEAN ssiClose (si_link l)
 
const char * slStatusSsi (si_link l, const char *request)
 
si_link_extension slInitSsiExtension (si_link_extension s)
 
void sig_chld_hdl (int sig)
 additional default signal handler More...
 

Function Documentation

void sig_chld_hdl ( int  )

additional default signal handler

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

Parameters
[in]sig

Definition at line 1890 of file ssiLink.cc.

1891 {
1892  pid_t kidpid;
1893  int status;
1894 
1895  loop
1896  {
1897  kidpid = si_waitpid(-1, &status, WNOHANG);
1898  if (kidpid==-1)
1899  {
1900  /* continue on interruption (EINTR): */
1901  if (errno == EINTR) continue;
1902  /* break on anything else (EINVAL or ECHILD according to manpage): */
1903  break;
1904  }
1905  else if (kidpid==0) break; /* no more children to process, so break */
1906 
1907  //printf("Child %ld terminated\n", kidpid);
1909  while((hh!=NULL)&&(ssiToBeClosed_inactive))
1910  {
1911  if((hh->l!=NULL) && (hh->l->m->Open==ssiOpen))
1912  {
1913  ssiInfo *d = (ssiInfo *)hh->l->data;
1914  if(d->pid==kidpid)
1915  {
1917  {
1919  slClose(hh->l);
1921  break;
1922  }
1923  else break;
1924  }
1925  else hh=(link_list)hh->next;
1926  }
1927  else hh=(link_list)hh->next;
1928  }
1929  }
1930 }
loop
Definition: myNF.cc:98
#define FALSE
Definition: auxiliary.h:140
#define TRUE
Definition: auxiliary.h:144
#define NULL
Definition: omList.c:10
int * status
Definition: si_signals.h:50
si_link_extension slInitSsiExtension ( si_link_extension  s)

Definition at line 1504 of file ssiLink.cc.

1505 {
1506  s->Open=ssiOpen;
1507  s->Close=ssiClose;
1508  s->Kill=ssiClose;
1509  s->Read=ssiRead1;
1510  s->Read2=(slRead2Proc)NULL;
1511  s->Write=ssiWrite;
1512  s->Dump=ssiDump;
1513  s->GetDump=ssiGetDump;
1514 
1515  s->Status=slStatusSsi;
1516  s->SetRing=ssiSetRing;
1517  s->type="ssi";
1518  return s;
1519 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define NULL
Definition: omList.c:10
const char* slStatusSsi ( si_link  l,
const char *  request 
)

Definition at line 1521 of file ssiLink.cc.

1522 {
1523  ssiInfo *d=(ssiInfo*)l->data;
1524  if (d==NULL) return "not open";
1525  if (((strcmp(l->mode,"fork")==0)
1526  ||(strcmp(l->mode,"tcp")==0)
1527  ||(strcmp(l->mode,"connect")==0))
1528  && (strcmp(request, "read") == 0))
1529  {
1530  fd_set mask;
1531  struct timeval wt;
1532  if (s_isready(d->f_read)) return "ready";
1533  loop
1534  {
1535  /* Don't block. Return socket status immediately. */
1536  wt.tv_sec = 0;
1537  wt.tv_usec = 0;
1538 
1539  FD_ZERO(&mask);
1540  FD_SET(d->fd_read, &mask);
1541  //Print("test fd %d\n",d->fd_read);
1542  /* check with select: chars waiting: no -> not ready */
1543  switch (si_select(d->fd_read+1, &mask, NULL, NULL, &wt))
1544  {
1545  case 0: /* not ready */ return "not ready";
1546  case -1: /*error*/ return "error";
1547  case 1: /*ready ? */ break;
1548  }
1549  /* yes: read 1 char*/
1550  /* if \n, check again with select else ungetc(c), ready*/
1551  int c=s_getc(d->f_read);
1552  //Print("try c=%d\n",c);
1553  if (c== -1) return "eof"; /* eof or error */
1554  else if (isdigit(c))
1555  { s_ungetc(c,d->f_read); return "ready"; }
1556  else if (c>' ')
1557  {
1558  Werror("unknown char in ssiLink(%d)",c);
1559  return "error";
1560  }
1561  /* else: next char */
1562  }
1563  }
1564  else if (strcmp(request, "read") == 0)
1565  {
1566  if (SI_LINK_R_OPEN_P(l) && (!s_iseof(d->f_read)) && (s_isready(d->f_read))) return "ready";
1567  else return "not ready";
1568  }
1569  else if (strcmp(request, "write") == 0)
1570  {
1571  if (SI_LINK_W_OPEN_P(l)) return "ready";
1572  else return "not ready";
1573  }
1574  else return "unknown status request";
1575 }
loop
Definition: myNF.cc:98
int int kStrategy strat if(h==NULL) return NULL
int s_getc(s_buff F)
Definition: s_buff.cc:66
void s_ungetc(int c, s_buff F)
Definition: s_buff.cc:107
int s_iseof(s_buff F)
Definition: s_buff.cc:260
#define NULL
Definition: omList.c:10
int s_isready(s_buff F)
Definition: s_buff.cc:93
void Werror(const char *fmt,...)
Definition: reporter.cc:199
int l
Definition: cfEzgcd.cc:94
BOOLEAN ssiClose ( si_link  l)

Definition at line 1128 of file ssiLink.cc.

1129 {
1130  if (l!=NULL)
1131  {
1133  ssiInfo *d = (ssiInfo *)l->data;
1134  if (d!=NULL)
1135  {
1136  if ((d->send_quit_at_exit)
1137  && (d->quit_sent==0))
1138  {
1139  fputs("99\n",d->f_write);
1140  fflush(d->f_write);
1141  }
1142  if (d->r!=NULL) rKill(d->r);
1143  if ((d->pid!=0)
1144  && (si_waitpid(d->pid,NULL,WNOHANG)==0))
1145  {
1146  struct timespec t;
1147  t.tv_sec=0;
1148  t.tv_nsec=100000000; // <=100 ms
1149  struct timespec rem;
1150  int r;
1151  do
1152  {
1153  r = nanosleep(&t, &rem);
1154  t = rem;
1155  } while ((r < 0) && (errno == EINTR)
1156  && (si_waitpid(d->pid,NULL,WNOHANG) == 0));
1157  if ((r == 0) && (si_waitpid(d->pid,NULL,WNOHANG) == 0))
1158  {
1159  kill(d->pid,15);
1160  t.tv_sec=5; // <=5s
1161  t.tv_nsec=0;
1162  do
1163  {
1164  r = nanosleep(&t, &rem);
1165  t = rem;
1166  } while ((r < 0) && (errno == EINTR)
1167  && (si_waitpid(d->pid,NULL,WNOHANG) == 0));
1168  if ((r == 0) && (si_waitpid(d->pid,NULL,WNOHANG) == 0))
1169  {
1170  kill(d->pid,9); // just to be sure
1171  si_waitpid(d->pid,NULL,0);
1172  }
1173  }
1174  }
1175  if (d->f_read!=NULL) s_close(d->f_read);
1176  if (d->f_read!=NULL) s_free(d->f_read);
1177  if (d->f_write!=NULL) fclose(d->f_write);
1178  if ((strcmp(l->mode,"tcp")==0)
1179  || (strcmp(l->mode,"fork")==0))
1180  {
1182  if (hh!=NULL)
1183  {
1184  if (hh->l==l)
1185  {
1187  omFreeSize(hh,sizeof(link_struct));
1188  }
1189  else while(hh->next!=NULL)
1190  {
1191  link_list hhh=(link_list)hh->next;
1192  if (hhh->l==l)
1193  {
1194  hh->next=hhh->next;
1195  omFreeSize(hhh,sizeof(link_struct));
1196  break;
1197  }
1198  else
1199  hh=(link_list)hh->next;
1200  }
1201  }
1202  }
1203  omFreeSize((ADDRESS)d,(sizeof *d));
1204  }
1205  l->data=NULL;
1206  }
1207  return FALSE;
1208 }
void rem(unsigned long *a, unsigned long *q, unsigned long p, int &dega, int degq)
Definition: minpoly.cc:574
#define FALSE
Definition: auxiliary.h:140
int s_free(s_buff &F)
Definition: s_buff.cc:45
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
void * ADDRESS
Definition: auxiliary.h:161
int s_close(s_buff &F)
Definition: s_buff.cc:56
int int kStrategy strat if(h==NULL) return NULL
const ring r
Definition: syzextra.cc:208
void rKill(ring r)
Definition: ipshell.cc:5815
#define NULL
Definition: omList.c:10
int l
Definition: cfEzgcd.cc:94
BOOLEAN ssiOpen ( si_link  l,
short  flag,
leftv  u 
)

Definition at line 747 of file ssiLink.cc.

748 {
749  if (l!=NULL)
750  {
751  const char *mode;
752  ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo));
753  if (flag & SI_LINK_OPEN)
754  {
755  if (l->mode[0] != '\0' && (strcmp(l->mode, "r") == 0))
756  flag = SI_LINK_READ;
757  else flag = SI_LINK_WRITE;
758  }
759 
760  if (flag == SI_LINK_READ) mode = "r";
761  else if (strcmp(l->mode, "w") == 0) mode = "w";
762  else if (strcmp(l->mode, "fork") == 0) mode = "fork";
763  else if (strcmp(l->mode, "tcp") == 0) mode = "tcp";
764  else if (strcmp(l->mode, "connect") == 0) mode = "connect";
765  else mode = "a";
766 
767 
768  SI_LINK_SET_OPEN_P(l, flag);
769  l->data=d;
770  omFree(l->mode);
771  l->mode = omStrDup(mode);
772 
773  if (l->name[0] == '\0')
774  {
775  if (strcmp(mode,"fork")==0)
776  {
778  n->u=u;
779  n->l=l;
780  n->next=(void *)ssiToBeClosed;
782 
783  int pc[2];
784  int cp[2];
785  pipe(pc);
786  pipe(cp);
787  pid_t pid = fork();
788  if (pid == -1 && errno == EAGAIN) // RLIMIT_NPROC too low?
789  {
791  pid = fork();
792  }
793  if (pid == -1)
794  {
795  WerrorS("could not fork");
796  }
797  if (pid==0) /*fork: child*/
798  {
799  /* block SIGINT */
800  sigset_t sigint;
801  sigemptyset(&sigint);
802  sigaddset(&sigint, SIGINT);
803  sigprocmask(SIG_BLOCK, &sigint, NULL);
804 
806  /* we know: l is the first entry in ssiToBeClosed-list */
807  while(hh!=NULL)
808  {
809  SI_LINK_SET_CLOSE_P(hh->l);
810  ssiInfo *dd=(ssiInfo*)hh->l->data;
811  s_close(dd->f_read);
812  s_free(dd->f_read);
813  fclose(dd->f_write);
814  if (dd->r!=NULL) rKill(dd->r);
815  omFreeSize((ADDRESS)dd,(sizeof *dd));
816  hh->l->data=NULL;
817  link_list nn=(link_list)hh->next;
818  omFree(hh);
819  hh=nn;
820  }
822 #ifdef HAVE_SIMPLEIPC
823  memset(sem_acquired, 0, SIPC_MAX_SEMAPHORES*sizeof(sem_acquired[0]));
824 #endif // HAVE_SIMPLEIPC
825  si_close(pc[1]); si_close(cp[0]);
826  d->f_write=fdopen(cp[1],"w");
827  d->f_read=s_open(pc[0]);
828  d->fd_read=pc[0];
829  d->fd_write=cp[1];
830  //d->r=currRing;
831  //if (d->r!=NULL) d->r->ref++;
832  l->data=d;
833  omFree(l->mode);
834  l->mode = omStrDup(mode);
837  //myynest=0;
839  if ((u!=NULL)&&(u->rtyp==IDHDL))
840  {
841  idhdl h=(idhdl)u->data;
842  h->lev=0;
843  }
844  loop
845  {
846  leftv h=ssiRead1(l); /*contains an exit.... */
847  if (feErrors != NULL && *feErrors != '\0')
848  {
849  // handle errors:
850  PrintS(feErrors); /* currently quite simple */
851  *feErrors = '\0';
852  }
853  ssiWrite(l,h);
854  h->CleanUp();
855  omFreeBin(h, sleftv_bin);
856  }
857  /* never reached*/
858  }
859  else if (pid>0) /*fork: parent*/
860  {
861  d->pid=pid;
862  si_close(pc[0]); si_close(cp[1]);
863  d->f_write=fdopen(pc[1],"w");
864  d->f_read=s_open(cp[0]);
865  d->fd_read=cp[0];
866  d->fd_write=pc[1];
868  d->send_quit_at_exit=1;
869  //d->r=currRing;
870  //if (d->r!=NULL) d->r->ref++;
871  }
872  else
873  {
874  Werror("fork failed (%d)",errno);
875  l->data=NULL;
876  omFree(d);
877  return TRUE;
878  }
879  }
880  // ---------------------------------------------------------------------
881  else if (strcmp(mode,"tcp")==0)
882  {
883  int sockfd, newsockfd, portno, clilen;
884  struct sockaddr_in serv_addr, cli_addr;
885  sockfd = socket(AF_INET, SOCK_STREAM, 0);
886  if(sockfd < 0)
887  {
888  WerrorS("ERROR opening socket");
889  l->data=NULL;
890  omFree(d);
891  return TRUE;
892  }
893  memset((char *) &serv_addr,0, sizeof(serv_addr));
894  portno = 1025;
895  serv_addr.sin_family = AF_INET;
896  serv_addr.sin_addr.s_addr = INADDR_ANY;
897  do
898  {
899  portno++;
900  serv_addr.sin_port = htons(portno);
901  if(portno > 50000)
902  {
903  WerrorS("ERROR on binding (no free port available?)");
904  l->data=NULL;
905  omFree(d);
906  return TRUE;
907  }
908  }
909  while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
910  Print("waiting on port %d\n", portno);mflush();
911  listen(sockfd,1);
912  newsockfd = si_accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
913  if(newsockfd < 0)
914  {
915  WerrorS("ERROR on accept");
916  l->data=NULL;
917  omFree(d);
918  return TRUE;
919  }
920  PrintS("client accepted\n");
921  d->fd_read = newsockfd;
922  d->fd_write = newsockfd;
923  d->f_read = s_open(newsockfd);
924  d->f_write = fdopen(newsockfd, "w");
926  si_close(sockfd);
927  }
928  // no ssi-Link on stdin or stdout
929  else
930  {
931  Werror("invalid mode >>%s<< for ssi",mode);
932  l->data=NULL;
933  omFree(d);
934  return TRUE;
935  }
936  }
937  // =========================================================================
938  else /*l->name=NULL*/
939  {
940  // tcp mode
941  if(strcmp(mode,"tcp")==0)
942  {
943  int sockfd, newsockfd, portno, clilen;
944  struct sockaddr_in serv_addr, cli_addr;
945  sockfd = socket(AF_INET, SOCK_STREAM, 0);
946  if(sockfd < 0)
947  {
948  WerrorS("ERROR opening socket");
949  l->data=NULL;
950  omFree(d);
951  return TRUE;
952  }
953  memset((char *) &serv_addr,0, sizeof(serv_addr));
954  portno = 1025;
955  serv_addr.sin_family = AF_INET;
956  serv_addr.sin_addr.s_addr = INADDR_ANY;
957  do
958  {
959  portno++;
960  serv_addr.sin_port = htons(portno);
961  if(portno > 50000)
962  {
963  WerrorS("ERROR on binding (no free port available?)");
964  l->data=NULL;
965  return TRUE;
966  }
967  }
968  while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
969  //Print("waiting on port %d\n", portno);mflush();
970  listen(sockfd,1);
971  char* cli_host = (char*)omAlloc(256);
972  char* path = (char*)omAlloc(1024);
973  int r = si_sscanf(l->name,"%255[^:]:%s",cli_host,path);
974  if(r == 0)
975  {
976  WerrorS("ERROR: no host specified");
977  l->data=NULL;
978  omFree(d);
979  omFree(path);
980  omFree(cli_host);
981  return TRUE;
982  }
983  else if(r == 1)
984  {
985  WarnS("program not specified, using /usr/local/bin/Singular");
986  strcpy(path,"/usr/local/bin/Singular");
987  }
988  char* ssh_command = (char*)omAlloc(256);
989  char* ser_host = (char*)omAlloc(64);
990  gethostname(ser_host,64);
991  sprintf(ssh_command,"ssh %s %s -q --batch --link=ssi --MPhost=%s --MPport=%d &",cli_host,path,ser_host,portno);
992  //Print("client on %s started:%s\n",cli_host,path);
993  omFree(path);
994  omFree(cli_host);
995  if (TEST_OPT_PROT) { Print("running >>%s<<\n",ssh_command); }
996  system(ssh_command);
997  omFree(ssh_command);
998  omFree(ser_host);
999  clilen = sizeof(cli_addr);
1000  newsockfd = si_accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
1001  if(newsockfd < 0)
1002  {
1003  WerrorS("ERROR on accept");
1004  l->data=NULL;
1005  omFree(d);
1006  return TRUE;
1007  }
1008  //PrintS("client accepted\n");
1009  d->fd_read = newsockfd;
1010  d->fd_write = newsockfd;
1011  d->f_read = s_open(newsockfd);
1012  d->f_write = fdopen(newsockfd, "w");
1013  si_close(sockfd);
1015  d->send_quit_at_exit=1;
1016  link_list newlink=(link_list)omAlloc(sizeof(link_struct));
1017  newlink->u=u;
1018  newlink->l=l;
1019  newlink->next=(void *)ssiToBeClosed;
1020  ssiToBeClosed=newlink;
1021  fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,si_opt_1,si_opt_2);
1022  }
1023  // ----------------------------------------------------------------------
1024  else if(strcmp(mode,"connect")==0)
1025  {
1026  char* host = (char*)omAlloc(256);
1027  int sockfd, portno;
1028  struct sockaddr_in serv_addr;
1029  struct hostent *server;
1030 
1031  si_sscanf(l->name,"%255[^:]:%d",host,&portno);
1032  //Print("connect to host %s, port %d\n",host,portno);mflush();
1033  if (portno!=0)
1034  {
1035  sockfd = socket(AF_INET, SOCK_STREAM, 0);
1036  if (sockfd < 0) { WerrorS("ERROR opening socket"); return TRUE; }
1037  server = gethostbyname(host);
1038  if (server == NULL) { WerrorS("ERROR, no such host"); return TRUE; }
1039  memset((char *) &serv_addr, 0, sizeof(serv_addr));
1040  serv_addr.sin_family = AF_INET;
1041  memcpy((char *)&serv_addr.sin_addr.s_addr,
1042  (char *)server->h_addr,
1043  server->h_length);
1044  serv_addr.sin_port = htons(portno);
1045  if (si_connect(sockfd,(sockaddr*)&serv_addr,sizeof(serv_addr)) < 0)
1046  { Werror("ERROR connecting(errno=%d)",errno); return TRUE; }
1047  //PrintS("connected\n");mflush();
1048  d->f_read=s_open(sockfd);
1049  d->fd_read=sockfd;
1050  d->f_write=fdopen(sockfd,"w");
1051  d->fd_write=sockfd;
1053  omFree(host);
1054  }
1055  else
1056  {
1057  l->data=NULL;
1058  omFree(d);
1059  return TRUE;
1060  }
1061  }
1062  // ======================================================================
1063  else
1064  {
1065  // normal link to a file
1066  FILE *outfile;
1067  char *filename=l->name;
1068 
1069  if(filename[0]=='>')
1070  {
1071  if (filename[1]=='>')
1072  {
1073  filename+=2;
1074  mode = "a";
1075  }
1076  else
1077  {
1078  filename++;
1079  mode="w";
1080  }
1081  }
1082  outfile=myfopen(filename,mode);
1083  if (outfile!=NULL)
1084  {
1085  if (strcmp(l->mode,"r")==0)
1086  {
1087  fclose(outfile);
1088  d->f_read=s_open_by_name(filename);
1089  }
1090  else
1091  {
1092  d->f_write = outfile;
1093  fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,si_opt_1,si_opt_2);
1094  }
1095  }
1096  else
1097  {
1098  omFree(d);
1099  l->data=NULL;
1100  return TRUE;
1101  }
1102  }
1103  }
1104  }
1105 
1106  return FALSE;
1107 }
unsigned si_opt_1
Definition: options.c:5
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition: feread.cc:33
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
#define Print
Definition: emacs.cc:83
#define TEST_OPT_PROT
Definition: options.h:98
loop
Definition: myNF.cc:98
#define FALSE
Definition: auxiliary.h:140
int s_free(s_buff &F)
Definition: s_buff.cc:45
Definition: tok.h:167
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
char * fe_fgets_dummy(const char *, char *, int)
Definition: feread.cc:418
#define TRUE
Definition: auxiliary.h:144
void * ADDRESS
Definition: auxiliary.h:161
void WerrorS(const char *s)
Definition: feFopen.cc:23
int s_close(s_buff &F)
Definition: s_buff.cc:56
#define WarnS
Definition: emacs.cc:81
#define omAlloc(size)
Definition: omAllocDecl.h:210
Definition: idrec.h:34
#define IDHDL
Definition: tok.h:35
void * data
Definition: subexpr.h:89
#define mflush()
Definition: reporter.h:42
char * feErrors
Definition: reporter.cc:47
const ring r
Definition: syzextra.cc:208
BOOLEAN singular_in_batchmode
Definition: cntrlc.cc:78
void rKill(ring r)
Definition: ipshell.cc:5815
#define omFree(addr)
Definition: omAllocDecl.h:261
FILE * myfopen(const char *path, const char *mode)
Definition: feFopen.cc:166
int raise_rlimit_nproc()
Definition: rlimit.c:18
idrec * idhdl
Definition: ring.h:18
omBin sleftv_bin
Definition: subexpr.cc:50
void PrintS(const char *s)
Definition: reporter.cc:294
#define NULL
Definition: omList.c:10
short lev
Definition: idrec.h:45
int rtyp
Definition: subexpr.h:92
#define SIPC_MAX_SEMAPHORES
Definition: simpleipc.h:10
void CleanUp(ring r=currRing)
Definition: subexpr.cc:301
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
int sem_acquired[SIPC_MAX_SEMAPHORES]
Definition: semaphore.c:30
s_buff s_open_by_name(const char *n)
Definition: s_buff.cc:39
unsigned si_opt_2
Definition: options.c:6
static Poly * h
Definition: janet.cc:978
void Werror(const char *fmt,...)
Definition: reporter.cc:199
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:94
s_buff s_open(int fd)
Definition: s_buff.cc:31
#define omStrDup(s)
Definition: omAllocDecl.h:263
leftv ssiRead1 ( si_link  l)

Definition at line 1211 of file ssiLink.cc.

1212 {
1213  ssiInfo *d = (ssiInfo *)l->data;
1214  leftv res=(leftv)omAlloc0(sizeof(sleftv));
1215  int t=0;
1216  t=s_readint(d->f_read);
1217  //Print("got type %d\n",t);
1218  switch(t)
1219  {
1220  case 1:res->rtyp=INT_CMD;
1221  res->data=(char *)(long)ssiReadInt(d->f_read);
1222  break;
1223  case 2:res->rtyp=STRING_CMD;
1224  res->data=(char *)ssiReadString(d);
1225  break;
1226  case 3:res->rtyp=NUMBER_CMD;
1227  res->data=(char *)ssiReadNumber(d);
1228  break;
1229  case 4:res->rtyp=BIGINT_CMD;
1230  res->data=(char *)ssiReadBigInt(d);
1231  break;
1232  case 15:
1233  case 5:{
1234  d->r=ssiReadRing(d);
1235  res->data=(char*)d->r;
1236  if (d->r->qideal==NULL)
1237  res->rtyp=RING_CMD;
1238  else
1239  res->rtyp=QRING_CMD;
1240  // we are in the top-level, so set the basering to d->r:
1241  if (d->r!=NULL)
1242  {
1243  d->r->ref++;
1244  ssiSetCurrRing(d->r);
1245  }
1246  if (t==15) return ssiRead1(l);
1247  }
1248  break;
1249  case 6:res->rtyp=POLY_CMD;
1250  if (d->r==NULL) goto no_ring;
1251  res->data=(char*)ssiReadPoly(d);
1252  break;
1253  case 7:res->rtyp=IDEAL_CMD;
1254  if (d->r==NULL) goto no_ring;
1255  res->data=(char*)ssiReadIdeal(d);
1256  break;
1257  case 8:res->rtyp=MATRIX_CMD;
1258  if (d->r==NULL) goto no_ring;
1259  res->data=(char*)ssiReadMatrix(d);
1260  break;
1261  case 9:res->rtyp=VECTOR_CMD;
1262  if (d->r==NULL) goto no_ring;
1263  res->data=(char*)ssiReadPoly(d);
1264  break;
1265  case 10:res->rtyp=MODUL_CMD;
1266  if (d->r==NULL) goto no_ring;
1267  res->data=(char*)ssiReadIdeal(d);
1268  break;
1269  case 11:
1270  {
1271  res->rtyp=COMMAND;
1272  res->data=ssiReadCommand(l);
1273  int nok=res->Eval();
1274  if (nok) WerrorS("error in eval");
1275  break;
1276  }
1277  case 12: /*DEF_CMD*/
1278  {
1279  res->rtyp=0;
1280  res->name=(char *)ssiReadString(d);
1281  int nok=res->Eval();
1282  if (nok) WerrorS("error in name lookup");
1283  break;
1284  }
1285  case 13: res->rtyp=PROC_CMD;
1286  res->data=ssiReadProc(d);
1287  break;
1288  case 14: res->rtyp=LIST_CMD;
1289  res->data=ssiReadList(l);
1290  break;
1291  case 16: res->rtyp=NONE; res->data=NULL;
1292  break;
1293  case 17: res->rtyp=INTVEC_CMD;
1294  res->data=ssiReadIntvec(d);
1295  break;
1296  case 18: res->rtyp=INTMAT_CMD;
1297  res->data=ssiReadIntmat(d);
1298  break;
1299  case 19: res->rtyp=BIGINTMAT_CMD;
1300  res->data=ssiReadBigintmat(d);
1301  break;
1302  case 20: ssiReadBlackbox(res,l);
1303  break;
1304  case 21: ssiReadAttrib(res,l);
1305  break;
1306  // ------------
1307  case 98: // version
1308  {
1309  int n98_v,n98_m;
1310  BITSET n98_o1,n98_o2;
1311  n98_v=s_readint(d->f_read);
1312  n98_m=s_readint(d->f_read);
1313  n98_o1=s_readint(d->f_read);
1314  n98_o2=s_readint(d->f_read);
1315  if ((n98_v!=SSI_VERSION) ||(n98_m!=MAX_TOK))
1316  {
1317  Print("incompatible versions of ssi: %d/%d vs %d/%d",
1318  SSI_VERSION,MAX_TOK,n98_v,n98_m);
1319  }
1320  #ifndef SING_NDEBUG
1321  if (TEST_OPT_DEBUG)
1322  Print("// opening ssi-%d, MAX_TOK=%d\n",n98_v,n98_m);
1323  #endif
1324  si_opt_1=n98_o1;
1325  si_opt_2=n98_o2;
1326  return ssiRead1(l);
1327  }
1328  case 99: ssiClose(l); m2_end(0);
1329  case 0: if (s_iseof(d->f_read))
1330  {
1331  ssiClose(l);
1332  }
1333  res->rtyp=DEF_CMD;
1334  break;
1335  default: Werror("not implemented (t:%d)",t);
1336  omFreeSize(res,sizeof(sleftv));
1337  res=NULL;
1338  break;
1339  }
1340  // if currRing is required for the result, but lost
1341  // define "ssiRing%d" as currRing:
1342  if ((d->r!=NULL)
1343  && (currRing!=d->r)
1344  && (res->RingDependend()))
1345  {
1346  ssiSetCurrRing(d->r);
1347  }
1348  return res;
1349 no_ring: WerrorS("no ring");
1350  omFreeSize(res,sizeof(sleftv));
1351  return NULL;
1352 }
unsigned si_opt_1
Definition: options.c:5
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
#define Print
Definition: emacs.cc:83
Definition: tok.h:85
Definition: tok.h:42
Definition: tok.h:167
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
void m2_end(int i)
Definition: misc_ip.cc:1074
void WerrorS(const char *s)
Definition: feFopen.cc:23
#define TEST_OPT_DEBUG
Definition: options.h:103
#define BITSET
Definition: structs.h:17
int int kStrategy strat if(h==NULL) return NULL
poly res
Definition: myNF.cc:322
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:12
int s_readint(s_buff F)
Definition: s_buff.cc:120
Definition: tok.h:58
int s_iseof(s_buff F)
Definition: s_buff.cc:260
Definition: tok.h:88
#define NULL
Definition: omList.c:10
Definition: tok.h:96
Definition: tok.h:126
unsigned si_opt_2
Definition: options.c:6
#define NONE
Definition: tok.h:170
void Werror(const char *fmt,...)
Definition: reporter.cc:199
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:94
#define COMMAND
Definition: tok.h:33
leftv ssiRead2 ( si_link  l,
leftv  key 
)
BOOLEAN ssiWrite ( si_link  l,
leftv  v 
)

Definition at line 1373 of file ssiLink.cc.

1374 {
1375  if(SI_LINK_W_OPEN_P(l)==0)
1376  if (slOpen(l,SI_LINK_OPEN|SI_LINK_WRITE,NULL)) return TRUE;
1377  ssiInfo *d = (ssiInfo *)l->data;
1378  d->level++;
1379  //FILE *fich=d->f;
1380  while (data!=NULL)
1381  {
1382  int tt=data->Typ();
1383  void *dd=data->Data();
1384  attr *aa=data->Attribute();
1385  BOOLEAN with_attr=FALSE;
1386  if (((*aa)!=NULL)||(data->flag!=0))
1387  {
1388  attr a=*aa;
1389  int n=0;
1390  while(a!=NULL) { n++; a=a->next;}
1391  fprintf(d->f_write,"21 %d %d ",data->flag,n);
1392  a=*aa;
1393  }
1394  if ((dd==NULL) && (data->name!=NULL) && (tt==0)) tt=DEF_CMD;
1395  // return pure undefined names as def
1396 
1397  switch(tt /*data->Typ()*/)
1398  {
1399  case 0: /*error*/
1400  case NONE/* nothing*/:fputs("16 ",d->f_write);
1401  break;
1402  case STRING_CMD: fputs("2 ",d->f_write);
1403  ssiWriteString(d,(char *)dd);
1404  break;
1405  case INT_CMD: fputs("1 ",d->f_write);
1406  ssiWriteInt(d,(int)(long)dd);
1407  break;
1408  case BIGINT_CMD:fputs("4 ",d->f_write);
1409  ssiWriteBigInt(d,(number)dd);
1410  break;
1411  case NUMBER_CMD:
1412  if (d->r!=currRing)
1413  {
1414  fputs("15 ",d->f_write);
1416  if (d->level<=1) fputc('\n',d->f_write);
1417  }
1418  fputs("3 ",d->f_write);
1419  ssiWriteNumber(d,(number)dd);
1420  break;
1421  case QRING_CMD:
1422  case RING_CMD:fputs("5 ",d->f_write);
1423  ssiWriteRing(d,(ring)dd);
1424  break;
1425  case POLY_CMD:
1426  case VECTOR_CMD:
1427  if (d->r!=currRing)
1428  {
1429  fputs("15 ",d->f_write);
1431  if (d->level<=1) fputc('\n',d->f_write);
1432  }
1433  if(tt==POLY_CMD) fputs("6 ",d->f_write);
1434  else fputs("9 ",d->f_write);
1435  ssiWritePoly(d,tt,(poly)dd);
1436  break;
1437  case IDEAL_CMD:
1438  case MODUL_CMD:
1439  case MATRIX_CMD:
1440  if (d->r!=currRing)
1441  {
1442  fputs("15 ",d->f_write);
1444  if (d->level<=1) fputc('\n',d->f_write);
1445  }
1446  if(tt==IDEAL_CMD) fputs("7 ",d->f_write);
1447  else if(tt==MATRIX_CMD) fputs("8 ",d->f_write);
1448  else fputs("10 ",d->f_write);
1449  ssiWriteIdeal(d,tt,(ideal)dd);
1450  break;
1451  case COMMAND:
1452  fputs("11 ",d->f_write);
1453  ssiWriteCommand(l,(command)dd);
1454  break;
1455  case DEF_CMD: /* not evaluated stuff in quotes */
1456  fputs("12 ",d->f_write);
1457  ssiWriteString(d,data->Name());
1458  break;
1459  case PROC_CMD:
1460  fputs("13 ",d->f_write);
1461  ssiWriteProc(d,(procinfov)dd);
1462  break;
1463  case LIST_CMD:
1464  fputs("14 ",d->f_write);
1465  ssiWriteList(l,(lists)dd);
1466  break;
1467  case INTVEC_CMD:
1468  fputs("17 ",d->f_write);
1469  ssiWriteIntvec(d,(intvec *)dd);
1470  break;
1471  case INTMAT_CMD:
1472  fputs("18 ",d->f_write);
1473  ssiWriteIntmat(d,(intvec *)dd);
1474  break;
1475  case BIGINTMAT_CMD:
1476  fputs("19 ",d->f_write);
1477  ssiWriteBigintmat(d,(bigintmat *)dd);
1478  break;
1479  default:
1480  if (tt>MAX_TOK)
1481  {
1482  blackbox *b=getBlackboxStuff(tt);
1483  fputs("20 ",d->f_write);
1484  b->blackbox_serialize(b,dd,l);
1485  }
1486  else
1487  {
1488  Werror("not implemented (t:%d, rtyp:%d)",tt, data->rtyp);
1489  d->level=0;
1490  return TRUE;
1491  }
1492  break;
1493  }
1494  if (d->level<=1) { fputc('\n',d->f_write); fflush(d->f_write); }
1495  data=data->next;
1496  }
1497  d->level--;
1498  return FALSE;
1499 }
ip_command * command
Definition: ipid.h:24
const poly a
Definition: syzextra.cc:212
Definition: tok.h:85
Definition: attrib.h:14
Definition: lists.h:22
#define FALSE
Definition: auxiliary.h:140
Definition: tok.h:42
Matrices of numbers.
Definition: bigintmat.h:32
Definition: tok.h:167
const ideal
Definition: gb_hack.h:42
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
#define TRUE
Definition: auxiliary.h:144
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:12
Definition: intvec.h:16
Definition: tok.h:58
polyrec * poly
Definition: hilb.h:10
while(1)
Definition: libparse.cc:1442
Definition: tok.h:88
#define NULL
Definition: omList.c:10
attr next
Definition: attrib.h:20
Definition: tok.h:96
Definition: tok.h:126
int BOOLEAN
Definition: auxiliary.h:131
const poly b
Definition: syzextra.cc:213
#define NONE
Definition: tok.h:170
void Werror(const char *fmt,...)
Definition: reporter.cc:199
int l
Definition: cfEzgcd.cc:94
#define COMMAND
Definition: tok.h:33
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:20