source: git/Singular/silink.cc @ bcfd11a

spielwiese
Last change on this file since bcfd11a was dd668f, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
use minideal (instead of qideal) in rCompose chg: use qideal instead of minideal for alg_ext TODO: remove direct access to extRing from outside
  • Property mode set to 100644
File size: 19.0 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id$ */
5
6/*
7* ABSTRACT: general interface to links
8*/
9
10#include <stdio.h>
11#include <string.h>
12#include <sys/types.h>
13#include <sys/stat.h>
14#include <unistd.h>
15
16#include "config.h"
17#include <kernel/mod2.h>
18#include <Singular/tok.h>
19#include <misc/options.h>
20#include <omalloc/omalloc.h>
21#include <kernel/febase.h>
22#include <Singular/subexpr.h>
23#include <Singular/ipid.h>
24#include <Singular/silink.h>
25#include <Singular/ipshell.h>
26#include <polys/matpol.h>
27#include <polys/monomials/ring.h>
28#include <Singular/lists.h>
29#include <kernel/ideals.h>
30#include <coeffs/numbers.h>
31#include <misc/intvec.h>
32#include <Singular/ssiLink.h>
33#include <Singular/pipeLink.h>
34
35// #ifdef HAVE_DBM
36// #ifdef ix86_Win
37// #define USE_GDBM
38// #endif
39// #endif
40
41omBin s_si_link_extension_bin = omGetSpecBin(sizeof(s_si_link_extension));
42omBin sip_link_bin = omGetSpecBin(sizeof(sip_link));
43omBin ip_link_bin = omGetSpecBin(sizeof(ip_link));
44
45/* declarations */
46static BOOLEAN DumpAscii(FILE *fd, idhdl h);
47static BOOLEAN DumpAsciiIdhdl(FILE *fd, idhdl h);
48static const char* GetIdString(idhdl h);
49static int DumpRhs(FILE *fd, idhdl h);
50static BOOLEAN DumpQring(FILE *fd, idhdl h, const char *type_str);
51static BOOLEAN DumpAsciiMaps(FILE *fd, idhdl h, idhdl rhdl);
52static si_link_extension slTypeInit(si_link_extension s, const char* type);
53
54/* ====================================================================== */
55si_link_extension si_link_root=NULL;
56
57BOOLEAN slInit(si_link l, char *istr)
58{
59  char *type = NULL, *mode = NULL, *name = NULL;
60  int i = 0, j;
61
62  // set mode and type
63  if (istr != NULL)
64  {
65    // find the first colon char in istr
66    i = 0;
67    while (istr[i] != ':' && istr[i] != '\0') i++;
68    if (istr[i] == ':')
69    {
70      // if found, set type
71      if (i > 0)
72      {
73        istr[i] = '\0';
74        type = omStrDup(istr);
75        istr[i] = ':';
76      }
77      // and check for mode
78      j = ++i;
79      while (istr[j] != ' ' && istr[j] != '\0') j++;
80      if (j > i)
81      {
82        mode = omStrDup(&(istr[i]));
83        mode[j - i] = '\0';
84      }
85      // and for the name
86      while (istr[j] == ' '&& istr[j] != '\0') j++;
87      if (istr[j] != '\0') name = omStrDup(&(istr[j]));
88    }
89    else // no colon find -- string is entire name
90    {
91      j=0;
92      while (istr[j] == ' '&& istr[j] != '\0') j++;
93      if (istr[j] != '\0') name = omStrDup(&(istr[j]));
94    }
95  }
96
97  // set the link extension
98  if (type != NULL)
99  {
100    si_link_extension s = si_link_root;
101    si_link_extension prev = s;
102
103    while (strcmp(s->type, type) != 0)
104    {
105      if (s->next == NULL)
106      {
107        prev = s;
108        s = NULL;
109        break;
110      }
111      else
112      {
113        s = s->next;
114      }
115    }
116
117    if (s != NULL)
118      l->m = s;
119    else
120    {
121      l->m = slTypeInit(prev, type);
122    }
123    omFree(type);
124  }
125  else
126    l->m = si_link_root;
127
128  if (l->m == NULL) return TRUE;
129
130  l->name = (name != NULL ? name : omStrDup(""));
131  l->mode = (mode != NULL ? mode : omStrDup(""));
132  l->ref = 1;
133  return FALSE;
134}
135
136void slCleanUp(si_link l)
137{
138  (l->ref)--;
139  if (l->ref == 0)
140  {
141    if (SI_LINK_OPEN_P(l))
142    {
143      if (l->m->Kill != NULL) l->m->Kill(l);
144      else if (l->m->Close != NULL) l->m->Close(l);
145    }
146    omFree((ADDRESS)l->name);
147    omFree((ADDRESS)l->mode);
148    memset((void *) l, 0, sizeof(ip_link));
149  }
150}
151
152void slKill(si_link l)
153{
154  slCleanUp(l);
155  if (l->ref == 0)
156    omFreeBin((ADDRESS)l,  ip_link_bin);
157}
158
159const char* slStatus(si_link l, const char *request)
160{
161  if (l == NULL) return "empty link";
162  else if (l->m == NULL) return "unknown link type";
163  else if (strcmp(request, "type") == 0) return l->m->type;
164  else if (strcmp(request, "mode") == 0) return l->mode;
165  else if (strcmp(request, "name") == 0) return l->name;
166  else if (strcmp(request, "exists") ==0)
167  {
168    struct stat buf;
169    if (lstat(l->name,&buf)==0) return "yes";
170    else return "no";
171  }
172  else if (strcmp(request, "open") == 0)
173  {
174    if (SI_LINK_OPEN_P(l)) return "yes";
175    else return "no";
176  }
177  else if (strcmp(request, "openread") == 0)
178  {
179    if (SI_LINK_R_OPEN_P(l)) return "yes";
180    else return "no";
181  }
182  else if (strcmp(request, "openwrite") == 0)
183  {
184    if (SI_LINK_W_OPEN_P(l)) return "yes";
185    else return "no";
186  }
187  else if (l->m->Status == NULL) return "unknown status request";
188  else return l->m->Status(l, request);
189}
190
191//--------------------------------------------------------------------------
192BOOLEAN slOpen(si_link l, short flag, leftv h)
193{
194  BOOLEAN res = TRUE;
195  if (l!=NULL)
196  {
197
198    if (l->m == NULL) slInit(l, ((char*)""));
199
200    const char *c="_";;
201    if (h!=NULL) c=h->Name();
202
203    if (SI_LINK_OPEN_P(l))
204    {
205      Warn("open: link of type: %s, mode: %s, name: %s is already open",
206         l->m->type, l->mode, l->name);
207      return FALSE;
208    }
209    else if (l->m->Open != NULL)
210    {
211      res = l->m->Open(l, flag, h);
212      if (res)
213        Werror("open: Error for link %s of type: %s, mode: %s, name: %s",
214             c, l->m->type, l->mode, l->name);
215    }
216  }
217  return res;
218}
219
220BOOLEAN slClose(si_link l)
221{
222
223  if(! SI_LINK_OPEN_P(l))
224    return FALSE;
225
226  BOOLEAN res = TRUE;
227  if (l->m->Close != NULL)
228  {
229    res = l->m->Close(l);
230    if (res)
231      Werror("close: Error for link of type: %s, mode: %s, name: %s",
232           l->m->type, l->mode, l->name);
233  }
234  return res;
235}
236
237leftv slRead(si_link l, leftv a)
238{
239  char *mode;
240  leftv v = NULL;
241  if( ! SI_LINK_R_OPEN_P(l)) // open r ?
242  {
243#ifdef HAVE_DBM
244#ifdef USE_GDBM
245    if (! SI_LINK_CLOSE_P(l))
246      {
247        if (slClose(l)) return NULL;
248      }
249#endif
250#endif
251    if (slOpen(l, SI_LINK_READ,NULL)) return NULL;
252  }
253
254  if (SI_LINK_R_OPEN_P(l))
255  { // open r
256    if (a==NULL)
257    {
258      if (l->m->Read != NULL) v = l->m->Read(l);
259    }
260    else
261    {
262      if (l->m->Read2 != NULL) v = l->m->Read2(l,a);
263    }
264  }
265  else
266  {
267    Werror("read: Error to open link of type %s, mode: %s, name: %s for reading",
268           l->m->type, l->mode, l->name);
269    return NULL;
270  }
271
272  // here comes the eval:
273  if (v != NULL)
274  {
275    if (v->Eval() && !errorreported)
276      WerrorS("eval: failed");
277  }
278  else
279    Werror("read: Error for link of type %s, mode: %s, name: %s",
280           l->m->type, l->mode, l->name);
281  return v;
282}
283
284BOOLEAN slWrite(si_link l, leftv v)
285{
286  BOOLEAN res;
287
288  if(! SI_LINK_W_OPEN_P(l)) // open w ?
289  {
290#ifdef HAVE_DBM
291#ifdef USE_GDBM
292    if (! SI_LINK_CLOSE_P(l))
293      {
294        if (slClose(l)) return TRUE;
295      }
296#endif
297#endif
298    if (slOpen(l, SI_LINK_WRITE,NULL)) return TRUE;
299  }
300
301  if (SI_LINK_W_OPEN_P(l))
302  { // now open w
303    if (l->m->Write != NULL)
304      res = l->m->Write(l,v);
305    else
306      res = TRUE;
307
308    if (res)
309      Werror("write: Error for link of type %s, mode: %s, name: %s",
310             l->m->type, l->mode, l->name);
311    return res;
312  }
313  else
314  {
315    Werror("write: Error to open link of type %s, mode: %s, name: %s for writing",
316           l->m->type, l->mode, l->name);
317    return TRUE;
318  }
319}
320
321BOOLEAN slDump(si_link l)
322{
323  BOOLEAN res;
324
325  if(! SI_LINK_W_OPEN_P(l)) // open w ?
326  {
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->Dump != NULL)
333      res = l->m->Dump(l);
334    else
335      res = TRUE;
336
337    if (res)
338      Werror("dump: 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("dump: 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}
349
350BOOLEAN slGetDump(si_link l)
351{
352  BOOLEAN res;
353
354  if(! SI_LINK_R_OPEN_P(l)) // open r ?
355  {
356    if (slOpen(l, SI_LINK_READ,NULL)) return TRUE;
357  }
358
359  if(SI_LINK_R_OPEN_P(l))
360  { // now open r
361    if (l->m->GetDump != NULL)
362      res = l->m->GetDump(l);
363    else
364      res = TRUE;
365
366    if (res)
367      Werror("getdump: Error for link of type %s, mode: %s, name: %s",
368             l->m->type, l->mode, l->name);
369    //res|=slClose(l);
370    return res;
371  }
372  else
373  {
374    Werror("dump: Error open link of type %s, mode: %s, name: %s for reading",
375           l->m->type, l->mode, l->name);
376    return TRUE;
377  }
378}
379
380
381/* =============== ASCII ============================================= */
382BOOLEAN slOpenAscii(si_link l, short flag, leftv h)
383{
384  const char *mode;
385  if (flag & SI_LINK_OPEN)
386  {
387    if (l->mode[0] != '\0' && (strcmp(l->mode, "r") == 0))
388      flag = SI_LINK_READ;
389    else flag = SI_LINK_WRITE;
390  }
391
392  if (flag == SI_LINK_READ) mode = "r";
393  else if (strcmp(l->mode, "w") == 0) mode = "w";
394  else mode = "a";
395
396
397  if (l->name[0] == '\0')
398  {
399    // stdin or stdout
400    if (flag == SI_LINK_READ)
401    {
402      l->data = (void *) stdin;
403      mode = "r";
404    }
405    else
406    {
407      l->data = (void *) stdout;
408      mode = "a";
409    }
410  }
411  else
412  {
413    // normal ascii link to a file
414    FILE *outfile;
415    char *filename=l->name;
416
417    if(filename[0]=='>')
418    {
419      if (filename[1]=='>')
420      {
421        filename+=2;
422        mode = "a";
423      }
424      else
425      {
426        filename++;
427        mode="w";
428      }
429    }
430    outfile=myfopen(filename,mode);
431    if (outfile!=NULL)
432      l->data = (void *) outfile;
433    else
434      return TRUE;
435  }
436
437  omFree(l->mode);
438  l->mode = omStrDup(mode);
439  SI_LINK_SET_OPEN_P(l, flag);
440  return FALSE;
441}
442
443BOOLEAN slCloseAscii(si_link l)
444{
445  SI_LINK_SET_CLOSE_P(l);
446  if (l->name[0] != '\0')
447  {
448    return (fclose((FILE *)l->data)!=0);
449  }
450  return FALSE;
451}
452
453leftv slReadAscii2(si_link l, leftv pr)
454{
455  FILE * fp=(FILE *)l->data;
456  char * buf=NULL;
457  if (fp!=NULL && l->name[0] != '\0')
458  {
459    fseek(fp,0L,SEEK_END);
460    long len=ftell(fp);
461    fseek(fp,0L,SEEK_SET);
462    buf=(char *)omAlloc((int)len+1);
463    if (BVERBOSE(V_READING))
464      Print("//Reading %ld chars\n",len);
465    myfread( buf, len, 1, fp);
466    buf[len]='\0';
467  }
468  else
469  {
470    if (pr->Typ()==STRING_CMD)
471    {
472      buf=(char *)omAlloc(80);
473      fe_fgets_stdin((char *)pr->Data(),buf,80);
474    }
475    else
476    {
477      WerrorS("read(<link>,<string>) expected");
478      buf=omStrDup("");
479    }
480  }
481  leftv v=(leftv)omAlloc0Bin(sleftv_bin);
482  v->rtyp=STRING_CMD;
483  v->data=buf;
484  return v;
485}
486
487leftv slReadAscii(si_link l)
488{
489  sleftv tmp;
490  memset(&tmp,0,sizeof(sleftv));
491  tmp.rtyp=STRING_CMD;
492  tmp.data=(void*) "? ";
493  return slReadAscii2(l,&tmp);
494}
495
496BOOLEAN slWriteAscii(si_link l, leftv v)
497{
498  FILE *outfile=(FILE *)l->data;
499  BOOLEAN err=FALSE;
500  char *s;
501  while (v!=NULL)
502  {
503    s = v->String();
504    // free v ??
505    if (s!=NULL)
506    {
507      fprintf(outfile,"%s\n",s);
508      omFree((ADDRESS)s);
509    }
510    else
511    {
512      Werror("cannot convert to string");
513      err=TRUE;
514    }
515    v = v->next;
516  }
517  fflush(outfile);
518  return err;
519}
520
521const char* slStatusAscii(si_link l, const char* request)
522{
523  if (strcmp(request, "read") == 0)
524  {
525    if (SI_LINK_R_OPEN_P(l)) return "ready";
526    else return "not ready";
527  }
528  else if (strcmp(request, "write") == 0)
529  {
530    if (SI_LINK_W_OPEN_P(l)) return "ready";
531    else return "not ready";
532  }
533  else return "unknown status request";
534}
535
536/*------------------ Dumping in Ascii format -----------------------*/
537
538BOOLEAN slDumpAscii(si_link l)
539{
540  FILE *fd = (FILE *) l->data;
541  idhdl h = IDROOT, rh = currRingHdl;
542  BOOLEAN status = DumpAscii(fd, h);
543
544  if (! status ) status = DumpAsciiMaps(fd, h, NULL);
545
546  if (currRingHdl != rh) rSetHdl(rh);
547  fprintf(fd, "option(set, intvec(%d, %d));\n", test, verbose);
548  fprintf(fd, "RETURN();\n");
549  fflush(fd);
550
551  return status;
552}
553
554// we do that recursively, to dump ids in the the order in which they
555// were actually defined
556static BOOLEAN DumpAscii(FILE *fd, idhdl h)
557{
558  if (h == NULL) return FALSE;
559
560  if (DumpAscii(fd, IDNEXT(h))) return TRUE;
561
562  // need to set the ring before writing it, otherwise we get in
563  // trouble with minpoly
564  if (IDTYP(h) == RING_CMD || IDTYP(h) == QRING_CMD)
565    rSetHdl(h);
566
567  if (DumpAsciiIdhdl(fd, h)) return TRUE;
568
569  if (IDTYP(h) == RING_CMD || IDTYP(h) == QRING_CMD)
570    return DumpAscii(fd, IDRING(h)->idroot);
571  else
572    return FALSE;
573}
574
575static BOOLEAN DumpAsciiMaps(FILE *fd, idhdl h, idhdl rhdl)
576{
577  if (h == NULL) return FALSE;
578  if (DumpAsciiMaps(fd, IDNEXT(h), rhdl)) return TRUE;
579
580  if (IDTYP(h) == RING_CMD || IDTYP(h) == QRING_CMD)
581    return DumpAsciiMaps(fd, IDRING(h)->idroot, h);
582  else if (IDTYP(h) == MAP_CMD)
583  {
584    char *rhs;
585    rSetHdl(rhdl);
586    rhs = h->String();
587
588    if (fprintf(fd, "setring %s;\n", IDID(rhdl)) == EOF) return TRUE;
589    if (fprintf(fd, "%s %s = %s, %s;\n", Tok2Cmdname(MAP_CMD), IDID(h),
590                IDMAP(h)->preimage, rhs) == EOF)
591    {
592      omFree(rhs);
593      return TRUE;
594    }
595    else
596    {
597      omFree(rhs);
598      return FALSE;
599    }
600  }
601  else return FALSE;
602}
603
604static BOOLEAN DumpAsciiIdhdl(FILE *fd, idhdl h)
605{
606  const char *type_str = GetIdString(h);
607  int type_id = IDTYP(h);
608
609  if ((type_id == PACKAGE_CMD) &&(strcmp(IDID(h), "Top") == 0))
610    return FALSE;
611
612  // we do not throw an error if a wrong type was attempted to be dumped
613  if (type_str == NULL)
614    return FALSE;
615
616  // handle qrings separately
617  if (type_id == QRING_CMD)
618    return DumpQring(fd, h, type_str);
619
620  // C-proc not to be dumped
621  if ((type_id == PROC_CMD) && (IDPROC(h)->language == LANG_C))
622    return FALSE;
623
624  // put type and name
625  if (fprintf(fd, "%s %s", type_str, IDID(h)) == EOF)
626    return TRUE;
627  // for matricies, append the dimension
628  if (type_id == MATRIX_CMD)
629  {
630    ideal id = IDIDEAL(h);
631    if (fprintf(fd, "[%d][%d]", id->nrows, id->ncols)== EOF) return TRUE;
632  }
633  else if (type_id == INTMAT_CMD)
634  {
635    if (fprintf(fd, "[%d][%d]", IDINTVEC(h)->rows(), IDINTVEC(h)->cols())
636        == EOF) return TRUE;
637  }
638
639  if (type_id == PACKAGE_CMD)
640  {
641    return (fprintf(fd, ";\n") == EOF);
642  }
643
644  // write the equal sign
645  if (fprintf(fd, " = ") == EOF) return TRUE;
646
647  // and the right hand side
648  if (DumpRhs(fd, h) == EOF) return TRUE;
649
650  // semicolon und tschuess
651  if (fprintf(fd, ";\n") == EOF) return TRUE;
652
653  return FALSE;
654}
655
656static const char* GetIdString(idhdl h)
657{
658  int type = IDTYP(h);
659
660  switch(type)
661  {
662      case LIST_CMD:
663      {
664        lists l = IDLIST(h);
665        int i, nl = l->nr + 1;
666        char *name;
667
668        for (i=0; i<nl; i++)
669          if (GetIdString((idhdl) &(l->m[i])) == NULL) return NULL;
670      }
671      case PACKAGE_CMD:
672      case INT_CMD:
673      case INTVEC_CMD:
674      case INTMAT_CMD:
675      case STRING_CMD:
676      case RING_CMD:
677      case QRING_CMD:
678      case PROC_CMD:
679      case NUMBER_CMD:
680      case POLY_CMD:
681      case IDEAL_CMD:
682      case VECTOR_CMD:
683      case MODUL_CMD:
684      case MATRIX_CMD:
685        return Tok2Cmdname(type);
686
687      case MAP_CMD:
688      case LINK_CMD:
689        return NULL;
690
691      default:
692       Warn("Error dump data of type %s", Tok2Cmdname(IDTYP(h)));
693       return NULL;
694  }
695}
696
697static BOOLEAN DumpQring(FILE *fd, idhdl h, const char *type_str)
698{
699  char *ring_str = h->String();
700  if (fprintf(fd, "%s temp_ring = %s;\n", Tok2Cmdname(RING_CMD), ring_str)
701              == EOF) return TRUE;
702  if (fprintf(fd, "%s temp_ideal = %s;\n", Tok2Cmdname(IDEAL_CMD),
703              iiStringMatrix((matrix) IDRING(h)->qideal, 1, currRing, n_GetChar(currRing->cf)))
704      == EOF) return TRUE;
705  if (fprintf(fd, "attrib(temp_ideal, \"isSB\", 1);\n") == EOF) return TRUE;
706  if (fprintf(fd, "%s %s = temp_ideal;\n", type_str, IDID(h)) == EOF)
707    return TRUE;
708  if (fprintf(fd, "kill temp_ring;\n") == EOF) return TRUE;
709  else
710  {
711    omFree(ring_str);
712    return FALSE;
713  }
714}
715
716
717static int DumpRhs(FILE *fd, idhdl h)
718{
719  int type_id = IDTYP(h);
720
721  if (type_id == LIST_CMD)
722  {
723    lists l = IDLIST(h);
724    int i, nl = l->nr;
725
726    fprintf(fd, "list(");
727
728    for (i=0; i<nl; i++)
729    {
730      if (DumpRhs(fd, (idhdl) &(l->m[i])) == EOF) return EOF;
731      fprintf(fd, ",");
732    }
733    if (nl > 0)
734    {
735      if (DumpRhs(fd, (idhdl) &(l->m[nl])) == EOF) return EOF;
736    }
737    fprintf(fd, ")");
738  }
739  else  if (type_id == STRING_CMD)
740  {
741    char *pstr = IDSTRING(h), c;
742    fputc('"', fd);
743    while (*pstr != '\0')
744    {
745      if (*pstr == '"' || *pstr == '\\')  fputc('\\', fd);
746      fputc(*pstr, fd);
747      pstr++;
748    }
749    fputc('"', fd);
750  }
751  else  if (type_id == PROC_CMD)
752  {
753    procinfov pi = IDPROC(h);
754    if (pi->language == LANG_SINGULAR) {
755      if( pi->data.s.body==NULL) iiGetLibProcBuffer(pi);
756      char *pstr = pi->data.s.body, c;
757      fputc('"', fd);
758      while (*pstr != '\0') {
759        if (*pstr == '"' || *pstr == '\\') fputc('\\', fd);
760        fputc(*pstr, fd);
761        pstr++;
762      }
763      fputc('"', fd);
764    } else fputs("(null)", fd);
765  }
766  else
767  {
768    char *rhs = h->String();
769
770    if (rhs == NULL) return EOF;
771
772    if (type_id == INTVEC_CMD) fprintf(fd, "intvec(");
773
774    if (fprintf(fd, "%s", rhs) == EOF) return EOF;
775    omFree(rhs);
776
777    if ((type_id == RING_CMD || type_id == QRING_CMD) &&
778        IDRING(h)->cf->type==n_algExt)
779    {
780      StringSetS("");
781      p_Write(IDRING(h)->cf->extRing->qideal->m[0],IDRING(h)->cf->extRing);
782      rhs = StringAppendS("");
783      if (fprintf(fd, "; minpoly = %s", rhs) == EOF) return EOF;
784    }
785    else if (type_id == INTVEC_CMD) fprintf(fd, ")");
786  }
787  return 1;
788}
789
790BOOLEAN slGetDumpAscii(si_link l)
791{
792  if (l->name[0] == '\0')
793  {
794    Werror("getdump: Can not get dump from stdin");
795    return TRUE;
796  }
797  else
798  {
799    BOOLEAN status = newFile(l->name);
800    if (status)
801      return TRUE;
802
803    int old_echo=si_echo;
804    si_echo=0;
805
806    status=yyparse();
807
808    si_echo=old_echo;
809
810    if (status)
811      return TRUE;
812    else
813    {
814      // lets reset the file pointer to the end to reflect that
815      // we are finished with reading
816      FILE *f = (FILE *) l->data;
817      fseek(f, 0L, SEEK_END);
818      return FALSE;
819    }
820  }
821}
822
823
824/*------------Initialization at Start-up time------------------------*/
825
826#include <Singular/slInit.h>
827
828static si_link_extension slTypeInit(si_link_extension s, const char* type)
829{
830  assume(s != NULL);
831  s->next = NULL;
832  si_link_extension ns = (si_link_extension)omAlloc0Bin(s_si_link_extension_bin);
833
834  if (0) 0;
835#ifdef HAVE_MPSR
836  else if (strcmp(type, "MPfile") == 0)
837    s->next = slInitMPFileExtension(ns);
838  else if (strcmp(type, "MPtcp") == 0)
839    s->next = slInitMPTcpExtension(ns);
840#endif
841#ifdef HAVE_DBM
842  else if (strcmp(type, "DBM") == 0)
843    s->next = slInitDBMExtension(ns);
844#endif
845#if 1
846  else if (strcmp(type, "ssi") == 0)
847    s->next = slInitSsiExtension(ns);
848#endif
849#if 1
850  else if (strcmp(type, "|") == 0)
851    s->next = slInitPipeExtension(ns);
852#endif
853  else
854  {
855    Warn("Found unknown link type: %s", type);
856    Warn("Use default link type: %s", si_link_root->type);
857    omFreeBin(ns, s_si_link_extension_bin);
858    return si_link_root;
859  }
860
861  if (s->next == NULL)
862  {
863    Werror("Can not initialize link type %s", type);
864    omFreeBin(ns, s_si_link_extension_bin);
865    return NULL;
866  }
867  return s->next;
868}
869
870void slStandardInit()
871{
872  si_link_extension s;
873  si_link_root=(si_link_extension)omAlloc0Bin(s_si_link_extension_bin);
874  si_link_root->Open=slOpenAscii;
875  si_link_root->Close=slCloseAscii;
876  si_link_root->Kill=slCloseAscii;
877  si_link_root->Read=slReadAscii;
878  si_link_root->Read2=slReadAscii2;
879  si_link_root->Write=slWriteAscii;
880  si_link_root->Dump=slDumpAscii;
881  si_link_root->GetDump=slGetDumpAscii;
882  si_link_root->Status=slStatusAscii;
883  si_link_root->type="ASCII";
884  s = si_link_root;
885  s->next = NULL;
886}
Note: See TracBrowser for help on using the repository browser.