source: git/Singular/silink.cc @ 894057

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