My Project
Loading...
Searching...
No Matches
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)
 
si_link ssiCommandLink ()
 
void sig_chld_hdl (int sig)
 additional default signal handler More...
 

Function Documentation

◆ sig_chld_hdl()

void sig_chld_hdl ( int  sig)

additional default signal handler

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

Parameters
[in]sig

Definition at line 2140 of file ssiLink.cc.

2141{
2142 pid_t kidpid;
2143 int status;
2144
2145 loop
2146 {
2147 kidpid = si_waitpid(-1, &status, WNOHANG);
2148 if (kidpid==-1)
2149 {
2150 /* continue on interruption (EINTR): */
2151 if (errno == EINTR) continue;
2152 /* break on anything else (EINVAL or ECHILD according to manpage): */
2153 break;
2154 }
2155 else if (kidpid==0) break; /* no more children to process, so break */
2156
2157 //printf("Child %ld terminated\n", kidpid);
2159 while((hh!=NULL)&&(ssiToBeClosed_inactive))
2160 {
2161 if((hh->l!=NULL) && (hh->l->m->Open==ssiOpen))
2162 {
2163 ssiInfo *d = (ssiInfo *)hh->l->data;
2164 if(d->pid==kidpid)
2165 {
2167 {
2169 slClose(hh->l);
2171 break;
2172 }
2173 else break;
2174 }
2175 else hh=(link_list)hh->next;
2176 }
2177 else hh=(link_list)hh->next;
2178 }
2179 }
2180}
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
#define NULL
Definition: omList.c:12
pid_t pid
Definition: s_buff.h:25
Definition: s_buff.h:21
int * status
Definition: si_signals.h:51
#define loop
Definition: structs.h:75

◆ slInitSsiExtension()

si_link_extension slInitSsiExtension ( si_link_extension  s)

Definition at line 1753 of file ssiLink.cc.

1754{
1755 s->Open=ssiOpen;
1756 s->Close=ssiClose;
1757 s->Kill=ssiClose;
1758 s->Read=ssiRead1;
1759 s->Read2=(slRead2Proc)NULL;
1760 s->Write=ssiWrite;
1761 s->Dump=ssiDump;
1762 s->GetDump=ssiGetDump;
1763
1764 s->Status=slStatusSsi;
1765 s->SetRing=ssiSetRing;
1766 s->type="ssi";
1767 return s;
1768}
const CanonicalForm int s
Definition: facAbsFact.cc:51

◆ slStatusSsi()

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

Definition at line 1770 of file ssiLink.cc.

1771{
1772 ssiInfo *d=(ssiInfo*)l->data;
1773 if (d==NULL) return "not open";
1774 if (((strcmp(l->mode,"fork")==0)
1775 ||(strcmp(l->mode,"tcp")==0)
1776 ||(strcmp(l->mode,"connect")==0))
1777 && (strcmp(request, "read") == 0))
1778 {
1779 fd_set mask;
1780 struct timeval wt;
1781 if (s_isready(d->f_read)) return "ready";
1782 loop
1783 {
1784 /* Don't block. Return socket status immediately. */
1785 wt.tv_sec = 0;
1786 wt.tv_usec = 0;
1787
1788 FD_ZERO(&mask);
1789 FD_SET(d->fd_read, &mask);
1790 //Print("test fd %d\n",d->fd_read);
1791 /* check with select: chars waiting: no -> not ready */
1792 switch (si_select(d->fd_read+1, &mask, NULL, NULL, &wt))
1793 {
1794 case 0: /* not ready */ return "not ready";
1795 case -1: /*error*/ return "error";
1796 case 1: /*ready ? */ break;
1797 }
1798 /* yes: read 1 char*/
1799 /* if \n, check again with select else ungetc(c), ready*/
1800 int c=s_getc(d->f_read);
1801 //Print("try c=%d\n",c);
1802 if (c== -1) return "eof"; /* eof or error */
1803 else if (isdigit(c))
1804 { s_ungetc(c,d->f_read); return "ready"; }
1805 else if (c>' ')
1806 {
1807 Werror("unknown char in ssiLink(%d)",c);
1808 return "error";
1809 }
1810 /* else: next char */
1811 }
1812 }
1813 else if (strcmp(request, "read") == 0)
1814 {
1815 if (SI_LINK_R_OPEN_P(l) && (!s_iseof(d->f_read)) && (s_isready(d->f_read))) return "ready";
1816 else return "not ready";
1817 }
1818 else if (strcmp(request, "write") == 0)
1819 {
1820 if (SI_LINK_W_OPEN_P(l)) return "ready";
1821 else return "not ready";
1822 }
1823 else return "unknown status request";
1824}
int l
Definition: cfEzgcd.cc:100
if(!FE_OPT_NO_SHELL_FLAG)(void) system(sys)
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int s_getc(s_buff F)
Definition: s_buff.cc:58
int s_isready(s_buff F)
Definition: s_buff.cc:85
int s_iseof(s_buff F)
Definition: s_buff.cc:254
void s_ungetc(int c, s_buff F)
Definition: s_buff.cc:99
s_buff f_read
Definition: s_buff.h:22
int fd_read
Definition: s_buff.h:26

◆ ssiClose()

BOOLEAN ssiClose ( si_link  l)

Definition at line 1330 of file ssiLink.cc.

1331{
1332 if (l!=NULL)
1333 {
1335 ssiInfo *d = (ssiInfo *)l->data;
1336 if (d!=NULL)
1337 {
1338 // send quit signal
1339 if ((d->send_quit_at_exit)
1340 && (d->quit_sent==0))
1341 {
1342 fputs("99\n",d->f_write);
1343 fflush(d->f_write);
1344 }
1345 // clean ring
1346 if (d->r!=NULL) rKill(d->r);
1347 // did the child to stop ?
1348 si_waitpid(d->pid,NULL,WNOHANG);
1349 if ((d->pid!=0)
1350 && (kill(d->pid,0)==0)) // child is still running
1351 {
1352 struct timespec t;
1353 t.tv_sec=0;
1354 t.tv_nsec=100000000; // <=100 ms
1355 struct timespec rem;
1356 int r;
1357 loop
1358 {
1359 // wait till signal or time rem:
1360 r = nanosleep(&t, &rem);
1361 t = rem;
1362 // child finished:
1363 if (si_waitpid(d->pid,NULL,WNOHANG) != 0) break;
1364 // other signal, waited s>= 100 ms:
1365 if ((r==0) || (errno != EINTR)) break;
1366 }
1367 if (kill(d->pid,0) == 0) // pid still exists
1368 {
1369 kill(d->pid,15);
1370 t.tv_sec=5; // <=5s
1371 t.tv_nsec=0;
1372 loop
1373 {
1374 // wait till signal or time rem:
1375 r = nanosleep(&t, &rem);
1376 t = rem;
1377 // child finished:
1378 if (si_waitpid(d->pid,NULL,WNOHANG) != 0) break;
1379 // other signal, waited s>= 5 s:
1380 if ((r==0) || (errno != EINTR)) break;
1381 }
1382 if (kill(d->pid,0) == 0)
1383 {
1384 kill(d->pid,9); // just to be sure
1385 si_waitpid(d->pid,NULL,0);
1386 }
1387 }
1388 }
1389 if (d->f_read!=NULL) { s_close(d->f_read);d->f_read=NULL;}
1390 if (d->f_write!=NULL) { fclose(d->f_write); d->f_write=NULL; }
1391 if ((strcmp(l->mode,"tcp")==0)
1392 || (strcmp(l->mode,"fork")==0))
1393 {
1395 if (hh!=NULL)
1396 {
1397 if (hh->l==l)
1398 {
1400 omFreeSize(hh,sizeof(link_struct));
1401 }
1402 else while(hh->next!=NULL)
1403 {
1404 link_list hhh=(link_list)hh->next;
1405 if (hhh->l==l)
1406 {
1407 hh->next=hhh->next;
1408 omFreeSize(hhh,sizeof(link_struct));
1409 break;
1410 }
1411 else
1412 hh=(link_list)hh->next;
1413 }
1414 }
1415 }
1416 omFreeSize((ADDRESS)d,(sizeof *d));
1417 }
1418 l->data=NULL;
1419 }
1420 return FALSE;
1421}
void * ADDRESS
Definition: auxiliary.h:119
void rKill(ring r)
Definition: ipshell.cc:6180
void rem(unsigned long *a, unsigned long *q, unsigned long p, int &dega, int degq)
Definition: minpoly.cc:572
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
int s_close(s_buff &F)
Definition: s_buff.cc:45
char send_quit_at_exit
Definition: s_buff.h:28
char quit_sent
Definition: s_buff.h:29
FILE * f_write
Definition: s_buff.h:23
ring r
Definition: s_buff.h:24

◆ ssiCommandLink()

si_link ssiCommandLink ( )

Definition at line 2069 of file ssiLink.cc.

2070{
2071 if (ssiReserved_P==0)
2072 {
2073 WerrorS("ERROR no reserved port requested");
2074 return NULL;
2075 }
2076 struct sockaddr_in cli_addr;
2077 int clilen = sizeof(cli_addr);
2078 int newsockfd = si_accept(ssiReserved_sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
2079 if(newsockfd < 0)
2080 {
2081 Werror("ERROR on accept (errno=%d)",errno);
2082 return NULL;
2083 }
2085 si_link_extension s = si_link_root;
2086 si_link_extension prev = s;
2087 while (strcmp(s->type, "ssi") != 0)
2088 {
2089 if (s->next == NULL)
2090 {
2091 prev = s;
2092 s = NULL;
2093 break;
2094 }
2095 else
2096 {
2097 s = s->next;
2098 }
2099 }
2100 if (s != NULL)
2101 l->m = s;
2102 else
2103 {
2104 si_link_extension ns = (si_link_extension)omAlloc0Bin(s_si_link_extension_bin);
2105 prev->next=slInitSsiExtension(ns);
2106 l->m = prev->next;
2107 }
2108 l->name=omStrDup("");
2109 l->mode=omStrDup("tcp");
2110 l->ref=1;
2111 ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo));
2112 l->data=d;
2113 d->fd_read = newsockfd;
2114 d->fd_write = newsockfd;
2115 d->f_read = s_open(newsockfd);
2116 d->f_write = fdopen(newsockfd, "w");
2119 if (ssiReserved_Clients<=0)
2120 {
2121 ssiReserved_P=0;
2122 si_close(ssiReserved_sockfd);
2123 }
2124 return l;
2125}
void WerrorS(const char *s)
Definition: feFopen.cc:24
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
#define omAlloc0(size)
Definition: omAllocDecl.h:211
s_buff s_open(int fd)
Definition: s_buff.cc:31
int fd_write
Definition: s_buff.h:26

◆ ssiOpen()

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

Definition at line 916 of file ssiLink.cc.

917{
918 if (l!=NULL)
919 {
920 const char *mode;
921 ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo));
922 if (flag & SI_LINK_OPEN)
923 {
924 if (l->mode[0] != '\0' && (strcmp(l->mode, "r") == 0))
925 flag = SI_LINK_READ;
926 else flag = SI_LINK_WRITE;
927 }
928
929 if (flag == SI_LINK_READ) mode = "r";
930 else if (strcmp(l->mode, "w") == 0) mode = "w";
931 else if (strcmp(l->mode, "fork") == 0) mode = "fork";
932 else if (strcmp(l->mode, "tcp") == 0) mode = "tcp";
933 else if (strcmp(l->mode, "connect") == 0) mode = "connect";
934 else mode = "a";
935
936
937 SI_LINK_SET_OPEN_P(l, flag);
938 if(l->data!=NULL) omFreeSize(l->data,sizeof(ssiInfo));
939 l->data=d;
940 omFreeBinAddr(l->mode);
941 l->mode = omStrDup(mode);
942
943 if (l->name[0] == '\0')
944 {
945 if (strcmp(mode,"fork")==0)
946 {
948 n->u=u;
949 n->l=l;
950 n->next=(void *)ssiToBeClosed;
952
953 int pc[2];
954 int cp[2];
955 pipe(pc);
956 pipe(cp);
957 pid_t pid = fork();
958 if (pid == -1 && errno == EAGAIN) // RLIMIT_NPROC too low?
959 {
961 pid = fork();
962 }
963 if (pid == -1)
964 {
965 WerrorS("could not fork");
966 }
967 if (pid==0) /*fork: child*/
968 {
969 /* block SIGINT */
970 sigset_t sigint;
971 sigemptyset(&sigint);
972 sigaddset(&sigint, SIGINT);
973 sigprocmask(SIG_BLOCK, &sigint, NULL);
974 /* set #cpu to 1 for the child:*/
975 feSetOptValue(FE_OPT_CPUS,1);
976
978 /* we know: l is the first entry in ssiToBeClosed-list */
979 while(hh!=NULL)
980 {
982 ssiInfo *dd=(ssiInfo*)hh->l->data;
983 s_close(dd->f_read);
984 fclose(dd->f_write);
985 if (dd->r!=NULL) rKill(dd->r);
986 omFreeSize((ADDRESS)dd,(sizeof *dd));
987 hh->l->data=NULL;
988 link_list nn=(link_list)hh->next;
989 omFree(hh);
990 hh=nn;
991 }
993#ifdef HAVE_SIMPLEIPC
994 memset(sem_acquired, 0, SIPC_MAX_SEMAPHORES*sizeof(sem_acquired[0]));
995#endif // HAVE_SIMPLEIPC
996 si_close(pc[1]); si_close(cp[0]);
997 d->f_write=fdopen(cp[1],"w");
998 d->f_read=s_open(pc[0]);
999 d->fd_read=pc[0];
1000 d->fd_write=cp[1];
1001 //d->r=currRing;
1002 //if (d->r!=NULL) d->r->ref++;
1003 l->data=d;
1004 omFreeBinAddr(l->mode);
1005 l->mode = omStrDup(mode);
1008 //myynest=0;
1010 if ((u!=NULL)&&(u->rtyp==IDHDL))
1011 {
1012 idhdl h=(idhdl)u->data;
1013 h->lev=0;
1014 }
1015 loop
1016 {
1017 if (!SI_LINK_OPEN_P(l)) m2_end(0);
1018 if(d->f_read->is_eof) m2_end(0);
1019 leftv h=ssiRead1(l); /*contains an exit.... */
1020 if (feErrors != NULL && *feErrors != '\0')
1021 {
1022 // handle errors:
1023 PrintS(feErrors); /* currently quite simple */
1024 *feErrors = '\0';
1025 }
1026 ssiWrite(l,h);
1027 h->CleanUp();
1029 }
1030 /* never reached*/
1031 }
1032 else if (pid>0) /*fork: parent*/
1033 {
1034 d->pid=pid;
1035 si_close(pc[0]); si_close(cp[1]);
1036 d->f_write=fdopen(pc[1],"w");
1037 d->f_read=s_open(cp[0]);
1038 d->fd_read=cp[0];
1039 d->fd_write=pc[1];
1041 d->send_quit_at_exit=1;
1042 //d->r=currRing;
1043 //if (d->r!=NULL) d->r->ref++;
1044 }
1045 else
1046 {
1047 Werror("fork failed (%d)",errno);
1048 l->data=NULL;
1049 omFree(d);
1050 return TRUE;
1051 }
1052 }
1053 // ---------------------------------------------------------------------
1054 else if (strcmp(mode,"tcp")==0)
1055 {
1056 int sockfd, newsockfd, portno, clilen;
1057 struct sockaddr_in serv_addr, cli_addr;
1058 sockfd = socket(AF_INET, SOCK_STREAM, 0);
1059 if(sockfd < 0)
1060 {
1061 WerrorS("ERROR opening socket");
1062 l->data=NULL;
1064 omFree(d);
1065 return TRUE;
1066 }
1067 memset((char *) &serv_addr,0, sizeof(serv_addr));
1068 portno = 1025;
1069 serv_addr.sin_family = AF_INET;
1070 serv_addr.sin_addr.s_addr = INADDR_ANY;
1071 do
1072 {
1073 portno++;
1074 serv_addr.sin_port = htons(portno);
1075 if(portno > 50000)
1076 {
1077 WerrorS("ERROR on binding (no free port available?)");
1078 l->data=NULL;
1080 omFree(d);
1081 return TRUE;
1082 }
1083 }
1084 while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
1085 Print("waiting on port %d\n", portno);mflush();
1086 listen(sockfd,1);
1087 newsockfd = si_accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
1088 if(newsockfd < 0)
1089 {
1090 WerrorS("ERROR on accept");
1091 l->data=NULL;
1093 omFree(d);
1094 return TRUE;
1095 }
1096 PrintS("client accepted\n");
1097 d->fd_read = newsockfd;
1098 d->fd_write = newsockfd;
1099 d->f_read = s_open(newsockfd);
1100 d->f_write = fdopen(newsockfd, "w");
1102 si_close(sockfd);
1103 }
1104 // no ssi-Link on stdin or stdout
1105 else
1106 {
1107 Werror("invalid mode >>%s<< for ssi",mode);
1108 l->data=NULL;
1110 omFree(d);
1111 return TRUE;
1112 }
1113 }
1114 // =========================================================================
1115 else /*l->name=NULL*/
1116 {
1117 // tcp mode
1118 if(strcmp(mode,"tcp")==0)
1119 {
1120 int sockfd, newsockfd, portno, clilen;
1121 struct sockaddr_in serv_addr, cli_addr;
1122 sockfd = socket(AF_INET, SOCK_STREAM, 0);
1123 if(sockfd < 0)
1124 {
1125 WerrorS("ERROR opening socket");
1126 l->data=NULL;
1128 omFree(d);
1129 return TRUE;
1130 }
1131 memset((char *) &serv_addr,0, sizeof(serv_addr));
1132 portno = 1025;
1133 serv_addr.sin_family = AF_INET;
1134 serv_addr.sin_addr.s_addr = INADDR_ANY;
1135 do
1136 {
1137 portno++;
1138 serv_addr.sin_port = htons(portno);
1139 if(portno > 50000)
1140 {
1141 WerrorS("ERROR on binding (no free port available?)");
1142 l->data=NULL;
1144 return TRUE;
1145 }
1146 }
1147 while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
1148 //Print("waiting on port %d\n", portno);mflush();
1149 listen(sockfd,1);
1150 char* cli_host = (char*)omAlloc(256);
1151 char* path = (char*)omAlloc(1024);
1152 int r = si_sscanf(l->name,"%255[^:]:%s",cli_host,path);
1153 if(r == 0)
1154 {
1155 WerrorS("ERROR: no host specified");
1156 l->data=NULL;
1158 omFree(d);
1159 omFree(path);
1160 omFree(cli_host);
1161 return TRUE;
1162 }
1163 else if(r == 1)
1164 {
1165 WarnS("program not specified, using /usr/local/bin/Singular");
1166 Warn("in line >>%s<<",my_yylinebuf);
1167 strcpy(path,"/usr/local/bin/Singular");
1168 }
1169 char* ssh_command = (char*)omAlloc(256);
1170 char* ser_host = (char*)omAlloc(64);
1171 gethostname(ser_host,64);
1172 if (strcmp(cli_host,"localhost")==0) /*avoid "ssh localhost" as key may change*/
1173 sprintf(ssh_command,"%s -q --batch --link=ssi --MPhost=%s --MPport=%d &",path,ser_host,portno);
1174 else
1175 sprintf(ssh_command,"ssh %s %s -q --batch --link=ssi --MPhost=%s --MPport=%d &",cli_host,path,ser_host,portno);
1176 //Print("client on %s started:%s\n",cli_host,path);
1177 omFree(path);
1178 omFree(cli_host);
1179 if (TEST_OPT_PROT) { Print("running >>%s<<\n",ssh_command); }
1180 system(ssh_command);
1181 omFree(ssh_command);
1182 omFree(ser_host);
1183 clilen = sizeof(cli_addr);
1184 newsockfd = si_accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
1185 if(newsockfd < 0)
1186 {
1187 WerrorS("ERROR on accept");
1188 l->data=NULL;
1190 omFree(d);
1191 return TRUE;
1192 }
1193 //PrintS("client accepted\n");
1194 d->fd_read = newsockfd;
1195 d->fd_write = newsockfd;
1196 d->f_read = s_open(newsockfd);
1197 d->f_write = fdopen(newsockfd, "w");
1198 si_close(sockfd);
1200 d->send_quit_at_exit=1;
1201 link_list newlink=(link_list)omAlloc(sizeof(link_struct));
1202 newlink->u=u;
1203 newlink->l=l;
1204 newlink->next=(void *)ssiToBeClosed;
1205 ssiToBeClosed=newlink;
1206 fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,si_opt_1,si_opt_2);
1207 }
1208 // ----------------------------------------------------------------------
1209 else if(strcmp(mode,"connect")==0)
1210 {
1211 char* host = (char*)omAlloc(256);
1212 int sockfd, portno;
1213 struct sockaddr_in serv_addr;
1214 struct hostent *server;
1215
1216 si_sscanf(l->name,"%255[^:]:%d",host,&portno);
1217 //Print("connect to host %s, port %d\n",host,portno);mflush();
1218 if (portno!=0)
1219 {
1220 sockfd = socket(AF_INET, SOCK_STREAM, 0);
1221 if (sockfd < 0)
1222 {
1223 WerrorS("ERROR opening socket");
1225 return TRUE;
1226 }
1227 server = gethostbyname(host);
1228 if (server == NULL)
1229 {
1230 WerrorS("ERROR, no such host");
1232 return TRUE;
1233 }
1234 memset((char *) &serv_addr, 0, sizeof(serv_addr));
1235 serv_addr.sin_family = AF_INET;
1236 memcpy((char *)&serv_addr.sin_addr.s_addr,
1237 (char *)server->h_addr,
1238 server->h_length);
1239 serv_addr.sin_port = htons(portno);
1240 if (si_connect(sockfd,(sockaddr*)&serv_addr,sizeof(serv_addr)) < 0)
1241 {
1242 Werror("ERROR connecting(errno=%d)",errno);
1244 return TRUE;
1245 }
1246 //PrintS("connected\n");mflush();
1247 d->f_read=s_open(sockfd);
1248 d->fd_read=sockfd;
1249 d->f_write=fdopen(sockfd,"w");
1250 d->fd_write=sockfd;
1252 omFree(host);
1253 }
1254 else
1255 {
1256 l->data=NULL;
1258 omFree(d);
1259 return TRUE;
1260 }
1261 }
1262 // ======================================================================
1263 else
1264 {
1265 // normal link to a file
1266 FILE *outfile;
1267 char *filename=l->name;
1268
1269 if(filename[0]=='>')
1270 {
1271 if (filename[1]=='>')
1272 {
1273 filename+=2;
1274 mode = "a";
1275 }
1276 else
1277 {
1278 filename++;
1279 mode="w";
1280 }
1281 }
1282 outfile=myfopen(filename,mode);
1283 if (outfile!=NULL)
1284 {
1285 if (strcmp(l->mode,"r")==0)
1286 {
1287 fclose(outfile);
1288 d->f_read=s_open_by_name(filename);
1289 }
1290 else
1291 {
1292 d->f_write = outfile;
1293 fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,si_opt_1,si_opt_2);
1294 }
1295 }
1296 else
1297 {
1298 omFree(d);
1299 l->data=NULL;
1301 return TRUE;
1302 }
1303 }
1304 }
1305 }
1306
1307 return FALSE;
1308}
Definition: idrec.h:35
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
int rtyp
Definition: subexpr.h:91
void * data
Definition: subexpr.h:88
VAR BOOLEAN singular_in_batchmode
Definition: cntrlc.cc:62
#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
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
EXTERN_VAR omBin sleftv_bin
Definition: ipid.h:145
STATIC_VAR Poly * h
Definition: janet.cc:971
void m2_end(int i)
Definition: misc_ip.cc:1097
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omFree(addr)
Definition: omAllocDecl.h:261
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
#define omFreeBinAddr(addr)
Definition: omAllocDecl.h:258
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:104
void PrintS(const char *s)
Definition: reporter.cc:284
VAR char * feErrors
Definition: reporter.cc:47
#define mflush()
Definition: reporter.h:58
idrec * idhdl
Definition: ring.h:21
int raise_rlimit_nproc()
Definition: rlimit.c:18
s_buff s_open_by_name(const char *n)
Definition: s_buff.cc:39
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:218

◆ ssiRead1()

leftv ssiRead1 ( si_link  l)

Definition at line 1424 of file ssiLink.cc.

1425{
1426 ssiInfo *d = (ssiInfo *)l->data;
1428 int t=0;
1429 t=s_readint(d->f_read);
1430 //Print("got type %d\n",t);
1431 switch(t)
1432 {
1433 case 1:res->rtyp=INT_CMD;
1434 res->data=(char *)(long)ssiReadInt(d->f_read);
1435 break;
1436 case 2:res->rtyp=STRING_CMD;
1437 res->data=(char *)ssiReadString(d);
1438 break;
1439 case 3:res->rtyp=NUMBER_CMD;
1440 if (d->r==NULL) goto no_ring;
1441 ssiCheckCurrRing(d->r);
1442 res->data=(char *)ssiReadNumber(d);
1443 break;
1444 case 4:res->rtyp=BIGINT_CMD;
1445 res->data=(char *)ssiReadBigInt(d);
1446 break;
1447 case 15:
1448 case 5:{
1449 d->r=ssiReadRing(d);
1450 if (errorreported) return NULL;
1451 res->data=(char*)d->r;
1452 if (d->r!=NULL) rIncRefCnt(d->r);
1453 res->rtyp=RING_CMD;
1454 if (t==15) // setring
1455 {
1456 if(ssiSetCurrRing(d->r)) { d->r=currRing; }
1458 return ssiRead1(l);
1459 }
1460 }
1461 break;
1462 case 6:res->rtyp=POLY_CMD;
1463 if (d->r==NULL) goto no_ring;
1464 ssiCheckCurrRing(d->r);
1465 res->data=(char*)ssiReadPoly(d);
1466 break;
1467 case 7:res->rtyp=IDEAL_CMD;
1468 if (d->r==NULL) goto no_ring;
1469 ssiCheckCurrRing(d->r);
1470 res->data=(char*)ssiReadIdeal(d);
1471 break;
1472 case 8:res->rtyp=MATRIX_CMD;
1473 if (d->r==NULL) goto no_ring;
1474 ssiCheckCurrRing(d->r);
1475 res->data=(char*)ssiReadMatrix(d);
1476 break;
1477 case 9:res->rtyp=VECTOR_CMD;
1478 if (d->r==NULL) goto no_ring;
1479 ssiCheckCurrRing(d->r);
1480 res->data=(char*)ssiReadPoly(d);
1481 break;
1482 case 10:
1483 case 22:if (t==22) res->rtyp=SMATRIX_CMD;
1484 else res->rtyp=MODUL_CMD;
1485 if (d->r==NULL) goto no_ring;
1486 ssiCheckCurrRing(d->r);
1487 {
1488 int rk=s_readint(d->f_read);
1489 ideal M=ssiReadIdeal(d);
1490 M->rank=rk;
1491 res->data=(char*)M;
1492 }
1493 break;
1494 case 11:
1495 {
1496 res->rtyp=COMMAND;
1497 res->data=ssiReadCommand(l);
1498 int nok=res->Eval();
1499 if (nok) WerrorS("error in eval");
1500 break;
1501 }
1502 case 12: /*DEF_CMD*/
1503 {
1504 res->rtyp=0;
1505 res->name=(char *)ssiReadString(d);
1506 int nok=res->Eval();
1507 if (nok) WerrorS("error in name lookup");
1508 break;
1509 }
1510 case 13: res->rtyp=PROC_CMD;
1511 res->data=ssiReadProc(d);
1512 break;
1513 case 14: res->rtyp=LIST_CMD;
1514 res->data=ssiReadList(l);
1515 break;
1516 case 16: res->rtyp=NONE; res->data=NULL;
1517 break;
1518 case 17: res->rtyp=INTVEC_CMD;
1519 res->data=ssiReadIntvec(d);
1520 break;
1521 case 18: res->rtyp=INTMAT_CMD;
1522 res->data=ssiReadIntmat(d);
1523 break;
1524 case 19: res->rtyp=BIGINTMAT_CMD;
1525 res->data=ssiReadBigintmat(d);
1526 break;
1527 case 20: ssiReadBlackbox(res,l);
1528 break;
1529 case 21: ssiReadAttrib(res,l);
1530 break;
1531 case 23: ssiReadRingProperties(l);
1532 return ssiRead1(l);
1533 break;
1534 // ------------
1535 case 98: // version
1536 {
1537 int n98_v,n98_m;
1538 BITSET n98_o1,n98_o2;
1539 n98_v=s_readint(d->f_read);
1540 n98_m=s_readint(d->f_read);
1541 n98_o1=s_readint(d->f_read);
1542 n98_o2=s_readint(d->f_read);
1543 if ((n98_v!=SSI_VERSION) ||(n98_m!=MAX_TOK))
1544 {
1545 Print("incompatible versions of ssi: %d/%d vs %d/%d\n",
1546 SSI_VERSION,MAX_TOK,n98_v,n98_m);
1547 }
1548 #ifndef SING_NDEBUG
1549 if (TEST_OPT_DEBUG)
1550 Print("// opening ssi-%d, MAX_TOK=%d\n",n98_v,n98_m);
1551 #endif
1552 si_opt_1=n98_o1;
1553 si_opt_2=n98_o2;
1555 return ssiRead1(l);
1556 }
1557 case 99: omFreeBin(res,sleftv_bin); ssiClose(l); m2_end(0);
1558 case 0: if (s_iseof(d->f_read))
1559 {
1560 ssiClose(l);
1561 }
1562 res->rtyp=DEF_CMD;
1563 break;
1564 default: Werror("not implemented (t:%d)",t);
1566 res=NULL;
1567 break;
1568 }
1569 // if currRing is required for the result, but lost
1570 // define "ssiRing%d" as currRing:
1571 if ((d->r!=NULL)
1572 && (currRing!=d->r)
1573 && (res->RingDependend()))
1574 {
1575 if(ssiSetCurrRing(d->r)) { d->r=currRing; }
1576 }
1577 return res;
1578no_ring: WerrorS("no ring");
1580 return NULL;
1581}
CanonicalForm res
Definition: facAbsFact.cc:60
VAR short errorreported
Definition: feFopen.cc:23
@ IDEAL_CMD
Definition: grammar.cc:284
@ MATRIX_CMD
Definition: grammar.cc:286
@ BIGINTMAT_CMD
Definition: grammar.cc:278
@ PROC_CMD
Definition: grammar.cc:280
@ INTMAT_CMD
Definition: grammar.cc:279
@ MODUL_CMD
Definition: grammar.cc:287
@ SMATRIX_CMD
Definition: grammar.cc:291
@ VECTOR_CMD
Definition: grammar.cc:292
@ NUMBER_CMD
Definition: grammar.cc:288
@ POLY_CMD
Definition: grammar.cc:289
@ RING_CMD
Definition: grammar.cc:281
#define TEST_OPT_DEBUG
Definition: options.h:109
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
static ring rIncRefCnt(ring r)
Definition: ring.h:837
int s_readint(s_buff F)
Definition: s_buff.cc:112
#define M
Definition: sirandom.c:25
#define BITSET
Definition: structs.h:16
@ BIGINT_CMD
Definition: tok.h:38
@ LIST_CMD
Definition: tok.h:118
@ INTVEC_CMD
Definition: tok.h:101
@ DEF_CMD
Definition: tok.h:58
@ STRING_CMD
Definition: tok.h:185
@ INT_CMD
Definition: tok.h:96
#define NONE
Definition: tok.h:221
#define COMMAND
Definition: tok.h:29

◆ ssiRead2()

leftv ssiRead2 ( si_link  l,
leftv  key 
)

◆ ssiWrite()

BOOLEAN ssiWrite ( si_link  l,
leftv  v 
)

Definition at line 1602 of file ssiLink.cc.

1603{
1604 if(SI_LINK_W_OPEN_P(l)==0)
1606 ssiInfo *d = (ssiInfo *)l->data;
1607 d->level++;
1608 //FILE *fich=d->f;
1609 while (data!=NULL)
1610 {
1611 int tt=data->Typ();
1612 void *dd=data->Data();
1613 attr *aa=data->Attribute();
1614 if ((aa!=NULL) && ((*aa)!=NULL)) // n user attributes
1615 {
1616 attr a=*aa;
1617 int n=0;
1618 while(a!=NULL) { n++; a=a->next;}
1619 fprintf(d->f_write,"21 %d %d ",data->flag,n);
1620 }
1621 else if (data->flag!=0) // only "flag" attributes
1622 {
1623 fprintf(d->f_write,"21 %d 0 ",data->flag);
1624 }
1625 if ((dd==NULL) && (data->name!=NULL) && (tt==0)) tt=DEF_CMD;
1626 // return pure undefined names as def
1627
1628 switch(tt /*data->Typ()*/)
1629 {
1630 case 0: /*error*/
1631 case NONE/* nothing*/:fputs("16 ",d->f_write);
1632 break;
1633 case STRING_CMD: fputs("2 ",d->f_write);
1634 ssiWriteString(d,(char *)dd);
1635 break;
1636 case INT_CMD: fputs("1 ",d->f_write);
1637 ssiWriteInt(d,(int)(long)dd);
1638 break;
1639 case BIGINT_CMD:fputs("4 ",d->f_write);
1640 ssiWriteBigInt(d,(number)dd);
1641 break;
1642 case NUMBER_CMD:
1643 if (d->r!=currRing)
1644 {
1645 fputs("15 ",d->f_write);
1647 if (d->level<=1) fputc('\n',d->f_write);
1648 }
1649 fputs("3 ",d->f_write);
1650 ssiWriteNumber(d,(number)dd);
1651 break;
1652 case RING_CMD:fputs("5 ",d->f_write);
1653 ssiWriteRing(d,(ring)dd);
1654 break;
1655 case BUCKET_CMD:
1656 {
1658 if (d->r!=sBucketGetRing(b))
1659 {
1660 fputs("15 ",d->f_write);
1662 if (d->level<=1) fputc('\n',d->f_write);
1663 }
1664 fputs("6 ",d->f_write);
1665 ssiWritePoly(d,tt,sBucketPeek(b));
1666 break;
1667 }
1668 case POLY_CMD:
1669 case VECTOR_CMD:
1670 if (d->r!=currRing)
1671 {
1672 fputs("15 ",d->f_write);
1674 if (d->level<=1) fputc('\n',d->f_write);
1675 }
1676 if(tt==POLY_CMD) fputs("6 ",d->f_write);
1677 else fputs("9 ",d->f_write);
1678 ssiWritePoly(d,tt,(poly)dd);
1679 break;
1680 case IDEAL_CMD:
1681 case MODUL_CMD:
1682 case MATRIX_CMD:
1683 case SMATRIX_CMD:
1684 if (d->r!=currRing)
1685 {
1686 fputs("15 ",d->f_write);
1688 if (d->level<=1) fputc('\n',d->f_write);
1689 }
1690 if(tt==IDEAL_CMD) fputs("7 ",d->f_write);
1691 else if(tt==MATRIX_CMD) fputs("8 ",d->f_write);
1692 else if(tt==SMATRIX_CMD) fputs("22 ",d->f_write);
1693 else /* tt==MODUL_CMD*/
1694 {
1695 ideal M=(ideal)dd;
1696 fprintf(d->f_write,"10 %d ",(int)M->rank);
1697 }
1698 ssiWriteIdeal(d,tt,(ideal)dd);
1699 break;
1700 case COMMAND:
1701 fputs("11 ",d->f_write);
1703 break;
1704 case DEF_CMD: /* not evaluated stuff in quotes */
1705 fputs("12 ",d->f_write);
1706 ssiWriteString(d,data->Name());
1707 break;
1708 case PROC_CMD:
1709 fputs("13 ",d->f_write);
1710 ssiWriteProc(d,(procinfov)dd);
1711 break;
1712 case LIST_CMD:
1713 fputs("14 ",d->f_write);
1714 ssiWriteList(l,(lists)dd);
1715 break;
1716 case INTVEC_CMD:
1717 fputs("17 ",d->f_write);
1718 ssiWriteIntvec(d,(intvec *)dd);
1719 break;
1720 case INTMAT_CMD:
1721 fputs("18 ",d->f_write);
1722 ssiWriteIntmat(d,(intvec *)dd);
1723 break;
1724 case BIGINTMAT_CMD:
1725 fputs("19 ",d->f_write);
1727 break;
1728 default:
1729 if (tt>MAX_TOK)
1730 {
1731 blackbox *b=getBlackboxStuff(tt);
1732 fputs("20 ",d->f_write);
1733 b->blackbox_serialize(b,dd,l);
1734 }
1735 else
1736 {
1737 Werror("not implemented (t:%d, rtyp:%d)",tt, data->rtyp);
1738 d->level=0;
1739 return TRUE;
1740 }
1741 break;
1742 }
1743 if (d->level<=1) { fputc('\n',d->f_write); fflush(d->f_write); }
1744 data=data->next;
1745 }
1746 d->level--;
1747 return FALSE;
1748}
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:17
CanonicalForm b
Definition: cfModGcd.cc:4103
Matrices of numbers.
Definition: bigintmat.h:51
Definition: intvec.h:23
Definition: attrib.h:21
attr next
Definition: attrib.h:26
Definition: lists.h:24
while(B< b)
Definition: facBivar.cc:54
@ BUCKET_CMD
Definition: grammar.cc:283
ip_command * command
Definition: ipid.h:23
char level
Definition: s_buff.h:27
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