Functions | Variables
silink.cc File Reference
#include <kernel/mod2.h>
#include <omalloc/omalloc.h>
#include <misc/options.h>
#include <misc/intvec.h>
#include <reporter/si_signals.h>
#include <coeffs/numbers.h>
#include <polys/matpol.h>
#include <polys/monomials/ring.h>
#include <kernel/ideals.h>
#include <Singular/lists.h>
#include <Singular/cntrlc.h>
#include <Singular/links/ssiLink.h>
#include <Singular/links/pipeLink.h>
#include <Singular/tok.h>
#include <Singular/subexpr.h>
#include <Singular/ipid.h>
#include <Singular/links/silink.h>
#include <Singular/ipshell.h>
#include "feOpt.h"
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <Singular/links/slInit.h>

Go to the source code of this file.

Functions

static si_link_extension slTypeInit (si_link_extension s, const char *type)
 
BOOLEAN slInit (si_link l, char *istr)
 
void slCleanUp (si_link l)
 
void slKill (si_link l)
 
const char * slStatus (si_link l, const char *request)
 
BOOLEAN slSetRingDummy (si_link, ring r, BOOLEAN send)
 
BOOLEAN slOpen (si_link l, short flag, leftv h)
 
BOOLEAN slPrepClose (si_link l)
 
BOOLEAN slClose (si_link l)
 
leftv slRead (si_link l, leftv a)
 
BOOLEAN slWrite (si_link l, leftv v)
 
BOOLEAN slDump (si_link l)
 
BOOLEAN slGetDump (si_link l)
 

Variables

omBin s_si_link_extension_bin = omGetSpecBin(sizeof(s_si_link_extension))
 
omBin sip_link_bin = omGetSpecBin(sizeof(sip_link))
 
omBin ip_link_bin = omGetSpecBin(sizeof(ip_link))
 
si_link_extension si_link_root =NULL
 

Function Documentation

void slCleanUp ( si_link  l)

Definition at line 132 of file silink.cc.

133 {
134  defer_shutdown++;
135  (l->ref)--;
136  if (l->ref == 0)
137  {
138  if (SI_LINK_OPEN_P(l))
139  {
140  if (l->m->Close != NULL) l->m->Close(l);
141  }
142  if ((l->data != NULL) && (l->m->Kill != NULL)) l->m->Kill(l);
143  omFree((ADDRESS)l->name);
144  omFree((ADDRESS)l->mode);
145  memset((void *) l, 0, sizeof(ip_link));
146  }
147  defer_shutdown--;
148  if (!defer_shutdown && do_shutdown) m2_end(1);
149 }
void m2_end(int i)
Definition: misc_ip.cc:1074
void * ADDRESS
Definition: auxiliary.h:161
volatile BOOLEAN do_shutdown
Definition: cntrlc.cc:84
#define omFree(addr)
Definition: omAllocDecl.h:261
#define NULL
Definition: omList.c:10
volatile int defer_shutdown
Definition: cntrlc.cc:85
int l
Definition: cfEzgcd.cc:94
BOOLEAN slClose ( si_link  l)

Definition at line 247 of file silink.cc.

248 {
249 
250  if(! SI_LINK_OPEN_P(l))
251  return FALSE;
252 
253  defer_shutdown++;
254  BOOLEAN res = TRUE;
255  if (l->m->Close != NULL)
256  {
257  res = l->m->Close(l);
258  if (res)
259  Werror("close: Error for link of type: %s, mode: %s, name: %s",
260  l->m->type, l->mode, l->name);
261  }
262  defer_shutdown--;
263  if (!defer_shutdown && do_shutdown) m2_end(1);
264  return res;
265 }
#define FALSE
Definition: auxiliary.h:140
void m2_end(int i)
Definition: misc_ip.cc:1074
#define TRUE
Definition: auxiliary.h:144
poly res
Definition: myNF.cc:322
volatile BOOLEAN do_shutdown
Definition: cntrlc.cc:84
#define NULL
Definition: omList.c:10
volatile int defer_shutdown
Definition: cntrlc.cc:85
int BOOLEAN
Definition: auxiliary.h:131
void Werror(const char *fmt,...)
Definition: reporter.cc:199
int l
Definition: cfEzgcd.cc:94
BOOLEAN slDump ( si_link  l)

Definition at line 350 of file silink.cc.

351 {
352  BOOLEAN res;
353 
354  if(! SI_LINK_W_OPEN_P(l)) // open w ?
355  {
356  if (slOpen(l, SI_LINK_WRITE,NULL)) return TRUE;
357  }
358 
359  if(SI_LINK_W_OPEN_P(l))
360  { // now open w
361  if (l->m->Dump != NULL)
362  res = l->m->Dump(l);
363  else
364  res = TRUE;
365 
366  if (res)
367  Werror("dump: Error for link of type %s, mode: %s, name: %s",
368  l->m->type, l->mode, l->name);
369  if (!SI_LINK_R_OPEN_P(l)) slClose(l); // do not close r/w links
370  return res;
371  }
372  else
373  {
374  Werror("dump: Error to open link of type %s, mode: %s, name: %s for writing",
375  l->m->type, l->mode, l->name);
376  return TRUE;
377  }
378 }
#define TRUE
Definition: auxiliary.h:144
poly res
Definition: myNF.cc:322
#define NULL
Definition: omList.c:10
int BOOLEAN
Definition: auxiliary.h:131
void Werror(const char *fmt,...)
Definition: reporter.cc:199
int l
Definition: cfEzgcd.cc:94
BOOLEAN slGetDump ( si_link  l)

Definition at line 380 of file silink.cc.

381 {
382  BOOLEAN res;
383 
384  if(! SI_LINK_R_OPEN_P(l)) // open r ?
385  {
386  if (slOpen(l, SI_LINK_READ,NULL)) return TRUE;
387  }
388 
389  if(SI_LINK_R_OPEN_P(l))
390  { // now open r
391  if (l->m->GetDump != NULL)
392  res = l->m->GetDump(l);
393  else
394  res = TRUE;
395 
396  if (res)
397  Werror("getdump: Error for link of type %s, mode: %s, name: %s",
398  l->m->type, l->mode, l->name);
399  //res|=slClose(l);
400  return res;
401  }
402  else
403  {
404  Werror("dump: Error open link of type %s, mode: %s, name: %s for reading",
405  l->m->type, l->mode, l->name);
406  return TRUE;
407  }
408 }
#define TRUE
Definition: auxiliary.h:144
poly res
Definition: myNF.cc:322
#define NULL
Definition: omList.c:10
int BOOLEAN
Definition: auxiliary.h:131
void Werror(const char *fmt,...)
Definition: reporter.cc:199
int l
Definition: cfEzgcd.cc:94
BOOLEAN slInit ( si_link  l,
char *  istr 
)

Definition at line 53 of file silink.cc.

54 {
55  char *type = NULL, *mode = NULL, *name = NULL;
56  int i = 0, j;
57 
58  // set mode and type
59  if (istr != NULL)
60  {
61  // find the first colon char in istr
62  i = 0;
63  while (istr[i] != ':' && istr[i] != '\0') i++;
64  if (istr[i] == ':')
65  {
66  // if found, set type
67  if (i > 0)
68  {
69  istr[i] = '\0';
70  type = omStrDup(istr);
71  istr[i] = ':';
72  }
73  // and check for mode
74  j = ++i;
75  while (istr[j] != ' ' && istr[j] != '\0') j++;
76  if (j > i)
77  {
78  mode = omStrDup(&(istr[i]));
79  mode[j - i] = '\0';
80  }
81  // and for the name
82  while (istr[j] == ' '&& istr[j] != '\0') j++;
83  if (istr[j] != '\0') name = omStrDup(&(istr[j]));
84  }
85  else // no colon find -- string is entire name
86  {
87  j=0;
88  while (istr[j] == ' '&& istr[j] != '\0') j++;
89  if (istr[j] != '\0') name = omStrDup(&(istr[j]));
90  }
91  }
92 
93  // set the link extension
94  if (type != NULL)
95  {
96  si_link_extension s = si_link_root;
97  si_link_extension prev = s;
98 
99  while (strcmp(s->type, type) != 0)
100  {
101  if (s->next == NULL)
102  {
103  prev = s;
104  s = NULL;
105  break;
106  }
107  else
108  {
109  s = s->next;
110  }
111  }
112 
113  if (s != NULL)
114  l->m = s;
115  else
116  {
117  l->m = slTypeInit(prev, type);
118  }
119  omFree(type);
120  }
121  else
122  l->m = si_link_root;
123 
124  if (l->m == NULL) return TRUE;
125 
126  l->name = (name != NULL ? name : omStrDup(""));
127  l->mode = (mode != NULL ? mode : omStrDup(""));
128  l->ref = 1;
129  return FALSE;
130 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define FALSE
Definition: auxiliary.h:140
#define TRUE
Definition: auxiliary.h:144
int j
Definition: myNF.cc:70
#define omFree(addr)
Definition: omAllocDecl.h:261
int i
Definition: cfEzgcd.cc:123
char name(const Variable &v)
Definition: variable.h:95
#define NULL
Definition: omList.c:10
int l
Definition: cfEzgcd.cc:94
#define omStrDup(s)
Definition: omAllocDecl.h:263
void slKill ( si_link  l)

Definition at line 151 of file silink.cc.

152 {
153  defer_shutdown++;
154  slCleanUp(l);
155  if ((l!=NULL) &&(l->ref == 0))
157  defer_shutdown--;
158  if (!defer_shutdown && do_shutdown) m2_end(1);
159 }
void m2_end(int i)
Definition: misc_ip.cc:1074
void * ADDRESS
Definition: auxiliary.h:161
volatile BOOLEAN do_shutdown
Definition: cntrlc.cc:84
#define NULL
Definition: omList.c:10
volatile int defer_shutdown
Definition: cntrlc.cc:85
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
int l
Definition: cfEzgcd.cc:94
BOOLEAN slOpen ( si_link  l,
short  flag,
leftv  h 
)

Definition at line 199 of file silink.cc.

200 {
201  BOOLEAN res = TRUE;
202  if (l!=NULL)
203  {
204 
205  if (l->m == NULL) slInit(l, ((char*)""));
206 
207  if (feOptValue(FE_OPT_NO_SHELL)) {WerrorS("no links allowed");return TRUE;}
208 
209  const char *c="_";;
210  if (h!=NULL) c=h->Name();
211 
212  if (SI_LINK_OPEN_P(l))
213  {
214  Warn("open: link of type: %s, mode: %s, name: %s is already open",
215  l->m->type, l->mode, l->name);
216  return FALSE;
217  }
218  else if (l->m->Open != NULL)
219  {
220  res = l->m->Open(l, flag, h);
221  if (res)
222  Werror("open: Error for link %s of type: %s, mode: %s, name: %s",
223  c, l->m->type, l->mode, l->name);
224  }
225  if (l->m->SetRing==NULL) l->m->SetRing=slSetRingDummy;
226  }
227  return res;
228 }
static void * feOptValue(feOptIndex opt)
Definition: feOpt.h:40
#define FALSE
Definition: auxiliary.h:140
#define TRUE
Definition: auxiliary.h:144
void WerrorS(const char *s)
Definition: feFopen.cc:23
const char * Name()
Definition: subexpr.h:121
poly res
Definition: myNF.cc:322
#define NULL
Definition: omList.c:10
int BOOLEAN
Definition: auxiliary.h:131
void Werror(const char *fmt,...)
Definition: reporter.cc:199
int l
Definition: cfEzgcd.cc:94
#define Warn
Definition: emacs.cc:80
BOOLEAN slPrepClose ( si_link  l)

Definition at line 230 of file silink.cc.

231 {
232 
233  if(! SI_LINK_OPEN_P(l))
234  return FALSE;
235 
236  BOOLEAN res = TRUE;
237  if (l->m->PrepClose != NULL)
238  {
239  res = l->m->PrepClose(l);
240  if (res)
241  Werror("close: Error for link of type: %s, mode: %s, name: %s",
242  l->m->type, l->mode, l->name);
243  }
244  return res;
245 }
#define FALSE
Definition: auxiliary.h:140
#define TRUE
Definition: auxiliary.h:144
poly res
Definition: myNF.cc:322
#define NULL
Definition: omList.c:10
int BOOLEAN
Definition: auxiliary.h:131
void Werror(const char *fmt,...)
Definition: reporter.cc:199
int l
Definition: cfEzgcd.cc:94
leftv slRead ( si_link  l,
leftv  a 
)

Definition at line 267 of file silink.cc.

268 {
269  leftv v = NULL;
270  if( ! SI_LINK_R_OPEN_P(l)) // open r ?
271  {
272 #ifdef HAVE_DBM
273 #ifdef USE_GDBM
274  if (! SI_LINK_CLOSE_P(l))
275  {
276  if (slClose(l)) return NULL;
277  }
278 #endif
279 #endif
280  if (slOpen(l, SI_LINK_READ,NULL)) return NULL;
281  }
282 
283  if (SI_LINK_R_OPEN_P(l))
284  { // open r
285  if (a==NULL)
286  {
287  if (l->m->Read != NULL) v = l->m->Read(l);
288  }
289  else
290  {
291  if (l->m->Read2 != NULL) v = l->m->Read2(l,a);
292  }
293  }
294  else
295  {
296  Werror("read: Error to open link of type %s, mode: %s, name: %s for reading",
297  l->m->type, l->mode, l->name);
298  return NULL;
299  }
300 
301  // here comes the eval:
302  if (v != NULL)
303  {
304  if (v->Eval() && !errorreported)
305  WerrorS("eval: failed");
306  }
307  else
308  Werror("read: Error for link of type %s, mode: %s, name: %s",
309  l->m->type, l->mode, l->name);
310  return v;
311 }
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
int Eval()
Definition: subexpr.cc:1721
void WerrorS(const char *s)
Definition: feFopen.cc:23
short errorreported
Definition: feFopen.cc:22
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
#define NULL
Definition: omList.c:10
void Werror(const char *fmt,...)
Definition: reporter.cc:199
int l
Definition: cfEzgcd.cc:94
BOOLEAN slSetRingDummy ( si_link  ,
ring  r,
BOOLEAN  send 
)

Definition at line 194 of file silink.cc.

195 {
196  if (currRing!=r) rChangeCurrRing(r);
197  return FALSE;
198 }
#define FALSE
Definition: auxiliary.h:140
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:12
const ring r
Definition: syzextra.cc:208
void rChangeCurrRing(ring r)
Definition: polys.cc:14
const char* slStatus ( si_link  l,
const char *  request 
)

Definition at line 161 of file silink.cc.

162 {
163  if (l == NULL) return "empty link";
164  else if (l->m == NULL) return "unknown link type";
165  else if (strcmp(request, "type") == 0) return l->m->type;
166  else if (strcmp(request, "mode") == 0) return l->mode;
167  else if (strcmp(request, "name") == 0) return l->name;
168  else if (strcmp(request, "exists") ==0)
169  {
170  struct stat buf;
171  if (si_lstat(l->name,&buf)==0) return "yes";
172  else return "no";
173  }
174  else if (strcmp(request, "open") == 0)
175  {
176  if (SI_LINK_OPEN_P(l)) return "yes";
177  else return "no";
178  }
179  else if (strcmp(request, "openread") == 0)
180  {
181  if (SI_LINK_R_OPEN_P(l)) return "yes";
182  else return "no";
183  }
184  else if (strcmp(request, "openwrite") == 0)
185  {
186  if (SI_LINK_W_OPEN_P(l)) return "yes";
187  else return "no";
188  }
189  else if (l->m->Status == NULL) return "unknown status request";
190  else return l->m->Status(l, request);
191 }
int status int void * buf
Definition: si_signals.h:59
#define NULL
Definition: omList.c:10
int l
Definition: cfEzgcd.cc:94
static si_link_extension slTypeInit ( si_link_extension  s,
const char *  type 
)
static

Definition at line 414 of file silink.cc.

415 {
416  assume(s != NULL);
417  s->next = NULL;
418  si_link_extension ns = (si_link_extension)omAlloc0Bin(s_si_link_extension_bin);
419 
420  if (0)
421  ; // dummy
422 #ifdef HAVE_DBM
423  else if (strcmp(type, "DBM") == 0)
424  s->next = slInitDBMExtension(ns);
425 #endif
426 #if 1
427  else if (strcmp(type, "ssi") == 0)
428  s->next = slInitSsiExtension(ns);
429 #endif
430 #if 1
431  else if (strcmp(type, "|") == 0)
432  s->next = slInitPipeExtension(ns);
433 #endif
434  else
435  {
436  Warn("Found unknown link type: %s", type);
437  Warn("Use default link type: %s", si_link_root->type);
439  return si_link_root;
440  }
441 
442  if (s->next == NULL)
443  {
444  Werror("Can not initialize link type %s", type);
446  return NULL;
447  }
448  return s->next;
449 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define assume(x)
Definition: mod2.h:405
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
#define NULL
Definition: omList.c:10
si_link_extension slInitDBMExtension(si_link_extension s)
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
void Werror(const char *fmt,...)
Definition: reporter.cc:199
#define Warn
Definition: emacs.cc:80
BOOLEAN slWrite ( si_link  l,
leftv  v 
)

Definition at line 313 of file silink.cc.

314 {
315  BOOLEAN res;
316 
317  if(! SI_LINK_W_OPEN_P(l)) // open w ?
318  {
319 #ifdef HAVE_DBM
320 #ifdef USE_GDBM
321  if (! SI_LINK_CLOSE_P(l))
322  {
323  if (slClose(l)) return TRUE;
324  }
325 #endif
326 #endif
327  if (slOpen(l, SI_LINK_WRITE,NULL)) return TRUE;
328  }
329 
330  if (SI_LINK_W_OPEN_P(l))
331  { // now open w
332  if (l->m->Write != NULL)
333  res = l->m->Write(l,v);
334  else
335  res = TRUE;
336 
337  if (res)
338  Werror("write: Error for link of type %s, mode: %s, name: %s",
339  l->m->type, l->mode, l->name);
340  return res;
341  }
342  else
343  {
344  Werror("write: Error to open link of type %s, mode: %s, name: %s for writing",
345  l->m->type, l->mode, l->name);
346  return TRUE;
347  }
348 }
#define TRUE
Definition: auxiliary.h:144
poly res
Definition: myNF.cc:322
#define NULL
Definition: omList.c:10
int BOOLEAN
Definition: auxiliary.h:131
void Werror(const char *fmt,...)
Definition: reporter.cc:199
int l
Definition: cfEzgcd.cc:94

Variable Documentation

omBin ip_link_bin = omGetSpecBin(sizeof(ip_link))

Definition at line 47 of file silink.cc.

omBin s_si_link_extension_bin = omGetSpecBin(sizeof(s_si_link_extension))

Definition at line 45 of file silink.cc.

si_link_extension si_link_root =NULL

Definition at line 51 of file silink.cc.

omBin sip_link_bin = omGetSpecBin(sizeof(sip_link))

Definition at line 46 of file silink.cc.