source: git/Singular/silink.cc @ 4e654a2

spielwiese
Last change on this file since 4e654a2 was 09afeb, checked in by Hans Schoenemann <hannes@…>, 12 years ago
chg: close link after dumping
  • 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
341    slClose(l);
342    return res;
343  }
344  else
345  {
346    Werror("dump: Error to open link of type %s, mode: %s, name: %s for writing",
347           l->m->type, l->mode, l->name);
348    return TRUE;
349  }
350}
351
352BOOLEAN slGetDump(si_link l)
353{
354  BOOLEAN res;
355
356  if(! SI_LINK_R_OPEN_P(l)) // open r ?
357  {
358    if (slOpen(l, SI_LINK_READ,NULL)) return TRUE;
359  }
360
361  if(SI_LINK_R_OPEN_P(l))
362  { // now open r
363    if (l->m->GetDump != NULL)
364      res = l->m->GetDump(l);
365    else
366      res = TRUE;
367
368    if (res)
369      Werror("getdump: Error for link of type %s, mode: %s, name: %s",
370             l->m->type, l->mode, l->name);
371    //res|=slClose(l);
372    return res;
373  }
374  else
375  {
376    Werror("dump: Error open link of type %s, mode: %s, name: %s for reading",
377           l->m->type, l->mode, l->name);
378    return TRUE;
379  }
380}
381
382
383/* =============== ASCII ============================================= */
384BOOLEAN slOpenAscii(si_link l, short flag, leftv h)
385{
386  const char *mode;
387  if (flag & SI_LINK_OPEN)
388  {
389    if (l->mode[0] != '\0' && (strcmp(l->mode, "r") == 0))
390      flag = SI_LINK_READ;
391    else flag = SI_LINK_WRITE;
392  }
393
394  if (flag == SI_LINK_READ) mode = "r";
395  else if (strcmp(l->mode, "w") == 0) mode = "w";
396  else mode = "a";
397
398
399  if (l->name[0] == '\0')
400  {
401    // stdin or stdout
402    if (flag == SI_LINK_READ)
403    {
404      l->data = (void *) stdin;
405      mode = "r";
406    }
407    else
408    {
409      l->data = (void *) stdout;
410      mode = "a";
411    }
412  }
413  else
414  {
415    // normal ascii link to a file
416    FILE *outfile;
417    char *filename=l->name;
418
419    if(filename[0]=='>')
420    {
421      if (filename[1]=='>')
422      {
423        filename+=2;
424        mode = "a";
425      }
426      else
427      {
428        filename++;
429        mode="w";
430      }
431    }
432    outfile=myfopen(filename,mode);
433    if (outfile!=NULL)
434      l->data = (void *) outfile;
435    else
436      return TRUE;
437  }
438
439  omFree(l->mode);
440  l->mode = omStrDup(mode);
441  SI_LINK_SET_OPEN_P(l, flag);
442  return FALSE;
443}
444
445BOOLEAN slCloseAscii(si_link l)
446{
447  SI_LINK_SET_CLOSE_P(l);
448  if (l->name[0] != '\0')
449  {
450    return (fclose((FILE *)l->data)!=0);
451  }
452  return FALSE;
453}
454
455leftv slReadAscii2(si_link l, leftv pr)
456{
457  FILE * fp=(FILE *)l->data;
458  char * buf=NULL;
459  if (fp!=NULL && l->name[0] != '\0')
460  {
461    fseek(fp,0L,SEEK_END);
462    long len=ftell(fp);
463    fseek(fp,0L,SEEK_SET);
464    buf=(char *)omAlloc((int)len+1);
465    if (BVERBOSE(V_READING))
466      Print("//Reading %ld chars\n",len);
467    myfread( buf, len, 1, fp);
468    buf[len]='\0';
469  }
470  else
471  {
472    if (pr->Typ()==STRING_CMD)
473    {
474      buf=(char *)omAlloc(80);
475      fe_fgets_stdin((char *)pr->Data(),buf,80);
476    }
477    else
478    {
479      WerrorS("read(<link>,<string>) expected");
480      buf=omStrDup("");
481    }
482  }
483  leftv v=(leftv)omAlloc0Bin(sleftv_bin);
484  v->rtyp=STRING_CMD;
485  v->data=buf;
486  return v;
487}
488
489leftv slReadAscii(si_link l)
490{
491  sleftv tmp;
492  memset(&tmp,0,sizeof(sleftv));
493  tmp.rtyp=STRING_CMD;
494  tmp.data=(void*) "? ";
495  return slReadAscii2(l,&tmp);
496}
497
498BOOLEAN slWriteAscii(si_link l, leftv v)
499{
500  FILE *outfile=(FILE *)l->data;
501  BOOLEAN err=FALSE;
502  char *s;
503  while (v!=NULL)
504  {
505    s = v->String();
506    // free v ??
507    if (s!=NULL)
508    {
509      fprintf(outfile,"%s\n",s);
510      omFree((ADDRESS)s);
511    }
512    else
513    {
514      Werror("cannot convert to string");
515      err=TRUE;
516    }
517    v = v->next;
518  }
519  fflush(outfile);
520  return err;
521}
522
523const char* slStatusAscii(si_link l, const char* request)
524{
525  if (strcmp(request, "read") == 0)
526  {
527    if (SI_LINK_R_OPEN_P(l)) return "ready";
528    else return "not ready";
529  }
530  else if (strcmp(request, "write") == 0)
531  {
532    if (SI_LINK_W_OPEN_P(l)) return "ready";
533    else return "not ready";
534  }
535  else return "unknown status request";
536}
537
538/*------------------ Dumping in Ascii format -----------------------*/
539
540BOOLEAN slDumpAscii(si_link l)
541{
542  FILE *fd = (FILE *) l->data;
543  idhdl h = IDROOT, rh = currRingHdl;
544  BOOLEAN status = DumpAscii(fd, h);
545
546  if (! status ) status = DumpAsciiMaps(fd, h, NULL);
547
548  if (currRingHdl != rh) rSetHdl(rh);
549  fprintf(fd, "option(set, intvec(%d, %d));\n", test, verbose);
550  fprintf(fd, "RETURN();\n");
551  fflush(fd);
552
553  return status;
554}
555
556// we do that recursively, to dump ids in the the order in which they
557// were actually defined
558static BOOLEAN DumpAscii(FILE *fd, idhdl h)
559{
560  if (h == NULL) return FALSE;
561
562  if (DumpAscii(fd, IDNEXT(h))) return TRUE;
563
564  // need to set the ring before writing it, otherwise we get in
565  // trouble with minpoly
566  if (IDTYP(h) == RING_CMD || IDTYP(h) == QRING_CMD)
567    rSetHdl(h);
568
569  if (DumpAsciiIdhdl(fd, h)) return TRUE;
570
571  if (IDTYP(h) == RING_CMD || IDTYP(h) == QRING_CMD)
572    return DumpAscii(fd, IDRING(h)->idroot);
573  else
574    return FALSE;
575}
576
577static BOOLEAN DumpAsciiMaps(FILE *fd, idhdl h, idhdl rhdl)
578{
579  if (h == NULL) return FALSE;
580  if (DumpAsciiMaps(fd, IDNEXT(h), rhdl)) return TRUE;
581
582  if (IDTYP(h) == RING_CMD || IDTYP(h) == QRING_CMD)
583    return DumpAsciiMaps(fd, IDRING(h)->idroot, h);
584  else if (IDTYP(h) == MAP_CMD)
585  {
586    char *rhs;
587    rSetHdl(rhdl);
588    rhs = h->String();
589
590    if (fprintf(fd, "setring %s;\n", IDID(rhdl)) == EOF) return TRUE;
591    if (fprintf(fd, "%s %s = %s, %s;\n", Tok2Cmdname(MAP_CMD), IDID(h),
592                IDMAP(h)->preimage, rhs) == EOF)
593    {
594      omFree(rhs);
595      return TRUE;
596    }
597    else
598    {
599      omFree(rhs);
600      return FALSE;
601    }
602  }
603  else return FALSE;
604}
605
606static BOOLEAN DumpAsciiIdhdl(FILE *fd, idhdl h)
607{
608  const char *type_str = GetIdString(h);
609  int type_id = IDTYP(h);
610
611  if ((type_id == PACKAGE_CMD) &&(strcmp(IDID(h), "Top") == 0))
612    return FALSE;
613
614  // we do not throw an error if a wrong type was attempted to be dumped
615  if (type_str == NULL)
616    return FALSE;
617
618  // handle qrings separately
619  if (type_id == QRING_CMD)
620    return DumpQring(fd, h, type_str);
621
622  // C-proc not to be dumped
623  if ((type_id == PROC_CMD) && (IDPROC(h)->language == LANG_C))
624    return FALSE;
625
626  // put type and name
627  if (fprintf(fd, "%s %s", type_str, IDID(h)) == EOF)
628    return TRUE;
629  // for matricies, append the dimension
630  if (type_id == MATRIX_CMD)
631  {
632    ideal id = IDIDEAL(h);
633    if (fprintf(fd, "[%d][%d]", id->nrows, id->ncols)== EOF) return TRUE;
634  }
635  else if (type_id == INTMAT_CMD)
636  {
637    if (fprintf(fd, "[%d][%d]", IDINTVEC(h)->rows(), IDINTVEC(h)->cols())
638        == EOF) return TRUE;
639  }
640
641  if (type_id == PACKAGE_CMD)
642  {
643    return (fprintf(fd, ";\n") == EOF);
644  }
645
646  // write the equal sign
647  if (fprintf(fd, " = ") == EOF) return TRUE;
648
649  // and the right hand side
650  if (DumpRhs(fd, h) == EOF) return TRUE;
651
652  // semicolon und tschuess
653  if (fprintf(fd, ";\n") == EOF) return TRUE;
654
655  return FALSE;
656}
657
658static const char* GetIdString(idhdl h)
659{
660  int type = IDTYP(h);
661
662  switch(type)
663  {
664      case LIST_CMD:
665      {
666        lists l = IDLIST(h);
667        int i, nl = l->nr + 1;
668        char *name;
669
670        for (i=0; i<nl; i++)
671          if (GetIdString((idhdl) &(l->m[i])) == NULL) return NULL;
672      }
673      case PACKAGE_CMD:
674      case INT_CMD:
675      case INTVEC_CMD:
676      case INTMAT_CMD:
677      case STRING_CMD:
678      case RING_CMD:
679      case QRING_CMD:
680      case PROC_CMD:
681      case NUMBER_CMD:
682      case POLY_CMD:
683      case IDEAL_CMD:
684      case VECTOR_CMD:
685      case MODUL_CMD:
686      case MATRIX_CMD:
687        return Tok2Cmdname(type);
688
689      case MAP_CMD:
690      case LINK_CMD:
691        return NULL;
692
693      default:
694       Warn("Error dump data of type %s", Tok2Cmdname(IDTYP(h)));
695       return NULL;
696  }
697}
698
699static BOOLEAN DumpQring(FILE *fd, idhdl h, const char *type_str)
700{
701  char *ring_str = h->String();
702  if (fprintf(fd, "%s temp_ring = %s;\n", Tok2Cmdname(RING_CMD), ring_str)
703              == EOF) return TRUE;
704  if (fprintf(fd, "%s temp_ideal = %s;\n", Tok2Cmdname(IDEAL_CMD),
705              iiStringMatrix((matrix) IDRING(h)->qideal, 1, currRing, n_GetChar(currRing->cf)))
706      == EOF) return TRUE;
707  if (fprintf(fd, "attrib(temp_ideal, \"isSB\", 1);\n") == EOF) return TRUE;
708  if (fprintf(fd, "%s %s = temp_ideal;\n", type_str, IDID(h)) == EOF)
709    return TRUE;
710  if (fprintf(fd, "kill temp_ring;\n") == EOF) return TRUE;
711  else
712  {
713    omFree(ring_str);
714    return FALSE;
715  }
716}
717
718
719static int DumpRhs(FILE *fd, idhdl h)
720{
721  int type_id = IDTYP(h);
722
723  if (type_id == LIST_CMD)
724  {
725    lists l = IDLIST(h);
726    int i, nl = l->nr;
727
728    fprintf(fd, "list(");
729
730    for (i=0; i<nl; i++)
731    {
732      if (DumpRhs(fd, (idhdl) &(l->m[i])) == EOF) return EOF;
733      fprintf(fd, ",");
734    }
735    if (nl > 0)
736    {
737      if (DumpRhs(fd, (idhdl) &(l->m[nl])) == EOF) return EOF;
738    }
739    fprintf(fd, ")");
740  }
741  else  if (type_id == STRING_CMD)
742  {
743    char *pstr = IDSTRING(h), c;
744    fputc('"', fd);
745    while (*pstr != '\0')
746    {
747      if (*pstr == '"' || *pstr == '\\')  fputc('\\', fd);
748      fputc(*pstr, fd);
749      pstr++;
750    }
751    fputc('"', fd);
752  }
753  else  if (type_id == PROC_CMD)
754  {
755    procinfov pi = IDPROC(h);
756    if (pi->language == LANG_SINGULAR) {
757      if( pi->data.s.body==NULL) iiGetLibProcBuffer(pi);
758      char *pstr = pi->data.s.body, c;
759      fputc('"', fd);
760      while (*pstr != '\0') {
761        if (*pstr == '"' || *pstr == '\\') fputc('\\', fd);
762        fputc(*pstr, fd);
763        pstr++;
764      }
765      fputc('"', fd);
766    } else fputs("(null)", fd);
767  }
768  else
769  {
770    char *rhs = h->String();
771
772    if (rhs == NULL) return EOF;
773
774    if (type_id == INTVEC_CMD) fprintf(fd, "intvec(");
775
776    if (fprintf(fd, "%s", rhs) == EOF) return EOF;
777    omFree(rhs);
778
779    if ((type_id == RING_CMD || type_id == QRING_CMD) &&
780        IDRING(h)->cf->type==n_algExt)
781    {
782      StringSetS("");
783      p_Write(IDRING(h)->cf->extRing->qideal->m[0],IDRING(h)->cf->extRing);
784      rhs = StringAppendS("");
785      if (fprintf(fd, "; minpoly = %s", rhs) == EOF) return EOF;
786    }
787    else if (type_id == INTVEC_CMD) fprintf(fd, ")");
788  }
789  return 1;
790}
791
792BOOLEAN slGetDumpAscii(si_link l)
793{
794  if (l->name[0] == '\0')
795  {
796    Werror("getdump: Can not get dump from stdin");
797    return TRUE;
798  }
799  else
800  {
801    BOOLEAN status = newFile(l->name);
802    if (status)
803      return TRUE;
804
805    int old_echo=si_echo;
806    si_echo=0;
807
808    status=yyparse();
809
810    si_echo=old_echo;
811
812    if (status)
813      return TRUE;
814    else
815    {
816      // lets reset the file pointer to the end to reflect that
817      // we are finished with reading
818      FILE *f = (FILE *) l->data;
819      fseek(f, 0L, SEEK_END);
820      return FALSE;
821    }
822  }
823}
824
825
826/*------------Initialization at Start-up time------------------------*/
827
828#include <Singular/slInit.h>
829
830static si_link_extension slTypeInit(si_link_extension s, const char* type)
831{
832  assume(s != NULL);
833  s->next = NULL;
834  si_link_extension ns = (si_link_extension)omAlloc0Bin(s_si_link_extension_bin);
835
836  if (0) 0;
837#ifdef HAVE_MPSR
838  else if (strcmp(type, "MPfile") == 0)
839    s->next = slInitMPFileExtension(ns);
840  else if (strcmp(type, "MPtcp") == 0)
841    s->next = slInitMPTcpExtension(ns);
842#endif
843#ifdef HAVE_DBM
844  else if (strcmp(type, "DBM") == 0)
845    s->next = slInitDBMExtension(ns);
846#endif
847#if 1
848  else if (strcmp(type, "ssi") == 0)
849    s->next = slInitSsiExtension(ns);
850#endif
851#if 1
852  else if (strcmp(type, "|") == 0)
853    s->next = slInitPipeExtension(ns);
854#endif
855  else
856  {
857    Warn("Found unknown link type: %s", type);
858    Warn("Use default link type: %s", si_link_root->type);
859    omFreeBin(ns, s_si_link_extension_bin);
860    return si_link_root;
861  }
862
863  if (s->next == NULL)
864  {
865    Werror("Can not initialize link type %s", type);
866    omFreeBin(ns, s_si_link_extension_bin);
867    return NULL;
868  }
869  return s->next;
870}
871
872void slStandardInit()
873{
874  si_link_extension s;
875  si_link_root=(si_link_extension)omAlloc0Bin(s_si_link_extension_bin);
876  si_link_root->Open=slOpenAscii;
877  si_link_root->Close=slCloseAscii;
878  si_link_root->Kill=slCloseAscii;
879  si_link_root->Read=slReadAscii;
880  si_link_root->Read2=slReadAscii2;
881  si_link_root->Write=slWriteAscii;
882  si_link_root->Dump=slDumpAscii;
883  si_link_root->GetDump=slGetDumpAscii;
884  si_link_root->Status=slStatusAscii;
885  si_link_root->type="ASCII";
886  s = si_link_root;
887  s->next = NULL;
888}
Note: See TracBrowser for help on using the repository browser.