source: git/Singular/silink.cc @ 3542f7

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