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

Go to the source code of this file.

Data Structures

struct  ssiInfo
 

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...
 

Data Structure Documentation

struct ssiInfo

Definition at line 13 of file ssiLink.h.

Data Fields
s_buff f_read
FILE * f_write
int fd_read
int fd_write
char level
pid_t pid
char quit_sent
ring r
char send_quit_at_exit

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

1922 {
1923  pid_t kidpid;
1924  int status;
1925 
1926  loop
1927  {
1928  kidpid = si_waitpid(-1, &status, WNOHANG);
1929  if (kidpid==-1)
1930  {
1931  /* continue on interruption (EINTR): */
1932  if (errno == EINTR) continue;
1933  /* break on anything else (EINVAL or ECHILD according to manpage): */
1934  break;
1935  }
1936  else if (kidpid==0) break; /* no more children to process, so break */
1937 
1938  //printf("Child %ld terminated\n", kidpid);
1940  while((hh!=NULL)&&(ssiToBeClosed_inactive))
1941  {
1942  if((hh->l!=NULL) && (hh->l->m->Open==ssiOpen))
1943  {
1944  ssiInfo *d = (ssiInfo *)hh->l->data;
1945  if(d->pid==kidpid)
1946  {
1948  {
1950  slClose(hh->l);
1952  break;
1953  }
1954  else break;
1955  }
1956  else hh=(link_list)hh->next;
1957  }
1958  else hh=(link_list)hh->next;
1959  }
1960  }
1961 }
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:51
si_link_extension slInitSsiExtension ( si_link_extension  s)

Definition at line 1535 of file ssiLink.cc.

1536 {
1537  s->Open=ssiOpen;
1538  s->Close=ssiClose;
1539  s->Kill=ssiClose;
1540  s->Read=ssiRead1;
1541  s->Read2=(slRead2Proc)NULL;
1542  s->Write=ssiWrite;
1543  s->Dump=ssiDump;
1544  s->GetDump=ssiGetDump;
1545 
1546  s->Status=slStatusSsi;
1547  s->SetRing=ssiSetRing;
1548  s->type="ssi";
1549  return s;
1550 }
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 1552 of file ssiLink.cc.

1553 {
1554  ssiInfo *d=(ssiInfo*)l->data;
1555  if (d==NULL) return "not open";
1556  if (((strcmp(l->mode,"fork")==0)
1557  ||(strcmp(l->mode,"tcp")==0)
1558  ||(strcmp(l->mode,"connect")==0))
1559  && (strcmp(request, "read") == 0))
1560  {
1561  fd_set mask;
1562  struct timeval wt;
1563  if (s_isready(d->f_read)) return "ready";
1564  loop
1565  {
1566  /* Don't block. Return socket status immediately. */
1567  wt.tv_sec = 0;
1568  wt.tv_usec = 0;
1569 
1570  FD_ZERO(&mask);
1571  FD_SET(d->fd_read, &mask);
1572  //Print("test fd %d\n",d->fd_read);
1573  /* check with select: chars waiting: no -> not ready */
1574  switch (si_select(d->fd_read+1, &mask, NULL, NULL, &wt))
1575  {
1576  case 0: /* not ready */ return "not ready";
1577  case -1: /*error*/ return "error";
1578  case 1: /*ready ? */ break;
1579  }
1580  /* yes: read 1 char*/
1581  /* if \n, check again with select else ungetc(c), ready*/
1582  int c=s_getc(d->f_read);
1583  //Print("try c=%d\n",c);
1584  if (c== -1) return "eof"; /* eof or error */
1585  else if (isdigit(c))
1586  { s_ungetc(c,d->f_read); return "ready"; }
1587  else if (c>' ')
1588  {
1589  Werror("unknown char in ssiLink(%d)",c);
1590  return "error";
1591  }
1592  /* else: next char */
1593  }
1594  }
1595  else if (strcmp(request, "read") == 0)
1596  {
1597  if (SI_LINK_R_OPEN_P(l) && (!s_iseof(d->f_read)) && (s_isready(d->f_read))) return "ready";
1598  else return "not ready";
1599  }
1600  else if (strcmp(request, "write") == 0)
1601  {
1602  if (SI_LINK_W_OPEN_P(l)) return "ready";
1603  else return "not ready";
1604  }
1605  else return "unknown status request";
1606 }
loop
Definition: myNF.cc:98
if(0 > strat->sl)
Definition: myNF.cc:73
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 1138 of file ssiLink.cc.

1139 {
1140  if (l!=NULL)
1141  {
1143  ssiInfo *d = (ssiInfo *)l->data;
1144  if (d!=NULL)
1145  {
1146  // send quit signal
1147  if ((d->send_quit_at_exit)
1148  && (d->quit_sent==0))
1149  {
1150  fputs("99\n",d->f_write);
1151  fflush(d->f_write);
1152  }
1153  // clean ring
1154  if (d->r!=NULL) rKill(d->r);
1155  // did the child to stop ?
1156  si_waitpid(d->pid,NULL,WNOHANG);
1157  if ((d->pid!=0)
1158  && (kill(d->pid,0)==0)) // child is still running
1159  {
1160  struct timespec t;
1161  t.tv_sec=0;
1162  t.tv_nsec=100000000; // <=100 ms
1163  struct timespec rem;
1164  int r;
1165  loop
1166  {
1167  // wait till signal or time rem:
1168  r = nanosleep(&t, &rem);
1169  t = rem;
1170  // child finished:
1171  if (si_waitpid(d->pid,NULL,WNOHANG) != 0) break;
1172  // other signal, waited s>= 100 ms:
1173  if ((r==0) || (errno != EINTR)) break;
1174  }
1175  if (kill(d->pid,0) == 0) // pid still exists
1176  {
1177  kill(d->pid,15);
1178  t.tv_sec=5; // <=5s
1179  t.tv_nsec=0;
1180  loop
1181  {
1182  // wait till signal or time rem:
1183  r = nanosleep(&t, &rem);
1184  t = rem;
1185  // child finished:
1186  if (si_waitpid(d->pid,NULL,WNOHANG) != 0) break;
1187  // other signal, waited s>= 5 s:
1188  if ((r==0) || (errno != EINTR)) break;
1189  }
1190  if (kill(d->pid,0) == 0)
1191  {
1192  kill(d->pid,9); // just to be sure
1193  si_waitpid(d->pid,NULL,0);
1194  }
1195  }
1196  }
1197  if (d->f_read!=NULL) { s_close(d->f_read);s_free(d->f_read);d->f_read=NULL;}
1198  if (d->f_write!=NULL) { fclose(d->f_write); d->f_write=NULL; }
1199  if ((strcmp(l->mode,"tcp")==0)
1200  || (strcmp(l->mode,"fork")==0))
1201  {
1203  if (hh!=NULL)
1204  {
1205  if (hh->l==l)
1206  {
1208  omFreeSize(hh,sizeof(link_struct));
1209  }
1210  else while(hh->next!=NULL)
1211  {
1212  link_list hhh=(link_list)hh->next;
1213  if (hhh->l==l)
1214  {
1215  hh->next=hhh->next;
1216  omFreeSize(hhh,sizeof(link_struct));
1217  break;
1218  }
1219  else
1220  hh=(link_list)hh->next;
1221  }
1222  }
1223  }
1224  omFreeSize((ADDRESS)d,(sizeof *d));
1225  }
1226  l->data=NULL;
1227  }
1228  return FALSE;
1229 }
void rem(unsigned long *a, unsigned long *q, unsigned long p, int &dega, int degq)
Definition: minpoly.cc:574
loop
Definition: myNF.cc:98
if(0 > strat->sl)
Definition: myNF.cc:73
#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
const ring r
Definition: syzextra.cc:208
void rKill(ring r)
Definition: ipshell.cc:6057
#define NULL
Definition: omList.c:10
int l
Definition: cfEzgcd.cc:94
BOOLEAN ssiOpen ( si_link  l,
short  flag,
leftv  u 
)

Definition at line 753 of file ssiLink.cc.

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

Definition at line 1232 of file ssiLink.cc.

1233 {
1234  ssiInfo *d = (ssiInfo *)l->data;
1235  leftv res=(leftv)omAlloc0(sizeof(sleftv));
1236  int t=0;
1237  t=s_readint(d->f_read);
1238  //Print("got type %d\n",t);
1239  switch(t)
1240  {
1241  case 1:res->rtyp=INT_CMD;
1242  res->data=(char *)(long)ssiReadInt(d->f_read);
1243  break;
1244  case 2:res->rtyp=STRING_CMD;
1245  res->data=(char *)ssiReadString(d);
1246  break;
1247  case 3:res->rtyp=NUMBER_CMD;
1248  res->data=(char *)ssiReadNumber(d);
1249  break;
1250  case 4:res->rtyp=BIGINT_CMD;
1251  res->data=(char *)ssiReadBigInt(d);
1252  break;
1253  case 15:
1254  case 5:{
1255  d->r=ssiReadRing(d);
1256  if (d->r==NULL) return NULL;
1257  res->data=(char*)d->r;
1258  if (d->r->qideal==NULL)
1259  res->rtyp=RING_CMD;
1260  else
1261  res->rtyp=QRING_CMD;
1262  // we are in the top-level, so set the basering to d->r:
1263  if (d->r!=NULL)
1264  {
1265  d->r->ref++;
1266  ssiSetCurrRing(d->r);
1267  }
1268  if (t==15) return ssiRead1(l);
1269  }
1270  break;
1271  case 6:res->rtyp=POLY_CMD;
1272  if (d->r==NULL) goto no_ring;
1273  res->data=(char*)ssiReadPoly(d);
1274  break;
1275  case 7:res->rtyp=IDEAL_CMD;
1276  if (d->r==NULL) goto no_ring;
1277  res->data=(char*)ssiReadIdeal(d);
1278  break;
1279  case 8:res->rtyp=MATRIX_CMD;
1280  if (d->r==NULL) goto no_ring;
1281  res->data=(char*)ssiReadMatrix(d);
1282  break;
1283  case 9:res->rtyp=VECTOR_CMD;
1284  if (d->r==NULL) goto no_ring;
1285  res->data=(char*)ssiReadPoly(d);
1286  break;
1287  case 10:res->rtyp=MODUL_CMD;
1288  if (d->r==NULL) goto no_ring;
1289  {
1290  int rk=s_readint(d->f_read);
1291  ideal M=ssiReadIdeal(d);
1292  M->rank=rk;
1293  res->data=(char*)M;
1294  }
1295  break;
1296  case 11:
1297  {
1298  res->rtyp=COMMAND;
1299  res->data=ssiReadCommand(l);
1300  int nok=res->Eval();
1301  if (nok) WerrorS("error in eval");
1302  break;
1303  }
1304  case 12: /*DEF_CMD*/
1305  {
1306  res->rtyp=0;
1307  res->name=(char *)ssiReadString(d);
1308  int nok=res->Eval();
1309  if (nok) WerrorS("error in name lookup");
1310  break;
1311  }
1312  case 13: res->rtyp=PROC_CMD;
1313  res->data=ssiReadProc(d);
1314  break;
1315  case 14: res->rtyp=LIST_CMD;
1316  res->data=ssiReadList(l);
1317  break;
1318  case 16: res->rtyp=NONE; res->data=NULL;
1319  break;
1320  case 17: res->rtyp=INTVEC_CMD;
1321  res->data=ssiReadIntvec(d);
1322  break;
1323  case 18: res->rtyp=INTMAT_CMD;
1324  res->data=ssiReadIntmat(d);
1325  break;
1326  case 19: res->rtyp=BIGINTMAT_CMD;
1327  res->data=ssiReadBigintmat(d);
1328  break;
1329  case 20: ssiReadBlackbox(res,l);
1330  break;
1331  case 21: ssiReadAttrib(res,l);
1332  break;
1333  // ------------
1334  case 98: // version
1335  {
1336  int n98_v,n98_m;
1337  BITSET n98_o1,n98_o2;
1338  n98_v=s_readint(d->f_read);
1339  n98_m=s_readint(d->f_read);
1340  n98_o1=s_readint(d->f_read);
1341  n98_o2=s_readint(d->f_read);
1342  if ((n98_v!=SSI_VERSION) ||(n98_m!=MAX_TOK))
1343  {
1344  Print("incompatible versions of ssi: %d/%d vs %d/%d",
1345  SSI_VERSION,MAX_TOK,n98_v,n98_m);
1346  }
1347  #ifndef SING_NDEBUG
1348  if (TEST_OPT_DEBUG)
1349  Print("// opening ssi-%d, MAX_TOK=%d\n",n98_v,n98_m);
1350  #endif
1351  si_opt_1=n98_o1;
1352  si_opt_2=n98_o2;
1353  return ssiRead1(l);
1354  }
1355  case 99: ssiClose(l); m2_end(0);
1356  case 0: if (s_iseof(d->f_read))
1357  {
1358  ssiClose(l);
1359  }
1360  res->rtyp=DEF_CMD;
1361  break;
1362  default: Werror("not implemented (t:%d)",t);
1363  omFreeSize(res,sizeof(sleftv));
1364  res=NULL;
1365  break;
1366  }
1367  // if currRing is required for the result, but lost
1368  // define "ssiRing%d" as currRing:
1369  if ((d->r!=NULL)
1370  && (currRing!=d->r)
1371  && (res->RingDependend()))
1372  {
1373  ssiSetCurrRing(d->r);
1374  }
1375  return res;
1376 no_ring: WerrorS("no ring");
1377  omFreeSize(res,sizeof(sleftv));
1378  return NULL;
1379 }
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:98
if(0 > strat->sl)
Definition: myNF.cc:73
Definition: tok.h:42
Definition: tok.h:217
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
void m2_end(int i)
Definition: misc_ip.cc:1069
void WerrorS(const char *s)
Definition: feFopen.cc:24
#define TEST_OPT_DEBUG
Definition: options.h:103
#define BITSET
Definition: structs.h:17
poly res
Definition: myNF.cc:322
#define M
Definition: sirandom.c:24
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:61
int s_iseof(s_buff F)
Definition: s_buff.cc:260
#define NULL
Definition: omList.c:10
Definition: tok.h:120
Definition: tok.h:159
unsigned si_opt_2
Definition: options.c:6
#define NONE
Definition: tok.h:220
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 1400 of file ssiLink.cc.

1401 {
1402  if(SI_LINK_W_OPEN_P(l)==0)
1403  if (slOpen(l,SI_LINK_OPEN|SI_LINK_WRITE,NULL)) return TRUE;
1404  ssiInfo *d = (ssiInfo *)l->data;
1405  d->level++;
1406  //FILE *fich=d->f;
1407  while (data!=NULL)
1408  {
1409  int tt=data->Typ();
1410  void *dd=data->Data();
1411  attr *aa=data->Attribute();
1412  BOOLEAN with_attr=FALSE;
1413  if (((*aa)!=NULL)||(data->flag!=0))
1414  {
1415  attr a=*aa;
1416  int n=0;
1417  while(a!=NULL) { n++; a=a->next;}
1418  fprintf(d->f_write,"21 %d %d ",data->flag,n);
1419  a=*aa;
1420  }
1421  if ((dd==NULL) && (data->name!=NULL) && (tt==0)) tt=DEF_CMD;
1422  // return pure undefined names as def
1423 
1424  switch(tt /*data->Typ()*/)
1425  {
1426  case 0: /*error*/
1427  case NONE/* nothing*/:fputs("16 ",d->f_write);
1428  break;
1429  case STRING_CMD: fputs("2 ",d->f_write);
1430  ssiWriteString(d,(char *)dd);
1431  break;
1432  case INT_CMD: fputs("1 ",d->f_write);
1433  ssiWriteInt(d,(int)(long)dd);
1434  break;
1435  case BIGINT_CMD:fputs("4 ",d->f_write);
1436  ssiWriteBigInt(d,(number)dd);
1437  break;
1438  case NUMBER_CMD:
1439  if (d->r!=currRing)
1440  {
1441  fputs("15 ",d->f_write);
1443  if (d->level<=1) fputc('\n',d->f_write);
1444  }
1445  fputs("3 ",d->f_write);
1446  ssiWriteNumber(d,(number)dd);
1447  break;
1448  case QRING_CMD:
1449  case RING_CMD:fputs("5 ",d->f_write);
1450  ssiWriteRing(d,(ring)dd);
1451  break;
1452  case POLY_CMD:
1453  case VECTOR_CMD:
1454  if (d->r!=currRing)
1455  {
1456  fputs("15 ",d->f_write);
1458  if (d->level<=1) fputc('\n',d->f_write);
1459  }
1460  if(tt==POLY_CMD) fputs("6 ",d->f_write);
1461  else fputs("9 ",d->f_write);
1462  ssiWritePoly(d,tt,(poly)dd);
1463  break;
1464  case IDEAL_CMD:
1465  case MODUL_CMD:
1466  case MATRIX_CMD:
1467  if (d->r!=currRing)
1468  {
1469  fputs("15 ",d->f_write);
1471  if (d->level<=1) fputc('\n',d->f_write);
1472  }
1473  if(tt==IDEAL_CMD) fputs("7 ",d->f_write);
1474  else if(tt==MATRIX_CMD) fputs("8 ",d->f_write);
1475  else
1476  {
1477  ideal M=(ideal)dd;
1478  fprintf(d->f_write,"10 %d ",(int)M->rank);
1479  }
1480  ssiWriteIdeal(d,tt,(ideal)dd);
1481  break;
1482  case COMMAND:
1483  fputs("11 ",d->f_write);
1484  ssiWriteCommand(l,(command)dd);
1485  break;
1486  case DEF_CMD: /* not evaluated stuff in quotes */
1487  fputs("12 ",d->f_write);
1488  ssiWriteString(d,data->Name());
1489  break;
1490  case PROC_CMD:
1491  fputs("13 ",d->f_write);
1492  ssiWriteProc(d,(procinfov)dd);
1493  break;
1494  case LIST_CMD:
1495  fputs("14 ",d->f_write);
1496  ssiWriteList(l,(lists)dd);
1497  break;
1498  case INTVEC_CMD:
1499  fputs("17 ",d->f_write);
1500  ssiWriteIntvec(d,(intvec *)dd);
1501  break;
1502  case INTMAT_CMD:
1503  fputs("18 ",d->f_write);
1504  ssiWriteIntmat(d,(intvec *)dd);
1505  break;
1506  case BIGINTMAT_CMD:
1507  fputs("19 ",d->f_write);
1508  ssiWriteBigintmat(d,(bigintmat *)dd);
1509  break;
1510  default:
1511  if (tt>MAX_TOK)
1512  {
1513  blackbox *b=getBlackboxStuff(tt);
1514  fputs("20 ",d->f_write);
1515  b->blackbox_serialize(b,dd,l);
1516  }
1517  else
1518  {
1519  Werror("not implemented (t:%d, rtyp:%d)",tt, data->rtyp);
1520  d->level=0;
1521  return TRUE;
1522  }
1523  break;
1524  }
1525  if (d->level<=1) { fputc('\n',d->f_write); fflush(d->f_write); }
1526  data=data->next;
1527  }
1528  d->level--;
1529  return FALSE;
1530 }
ip_command * command
Definition: ipid.h:24
const poly a
Definition: syzextra.cc:212
Definition: tok.h:98
Definition: attrib.h:15
Definition: lists.h:22
#define FALSE
Definition: auxiliary.h:140
Definition: tok.h:42
Matrices of numbers.
Definition: bigintmat.h:51
Definition: tok.h:217
#define TRUE
Definition: auxiliary.h:144
#define M
Definition: sirandom.c:24
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:12
Definition: intvec.h:14
Definition: tok.h:61
while(1)
Definition: libparse.cc:1442
#define NULL
Definition: omList.c:10
attr next
Definition: attrib.h:21
Definition: tok.h:120
Definition: tok.h:159
polyrec * poly
Definition: hilb.h:10
int BOOLEAN
Definition: auxiliary.h:131
const poly b
Definition: syzextra.cc:213
#define NONE
Definition: tok.h:220
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