source: git/Singular/silink.cc @ 9db0567

spielwiese
Last change on this file since 9db0567 was 9db0567, checked in by Hans Schönemann <hannes@…>, 16 years ago
*hannes: gcc 4 fixes git-svn-id: file:///usr/local/Singular/svn/trunk@11039 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 18.7 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: silink.cc,v 1.48 2008-09-10 08:52:57 Singular Exp $ */
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 "mod2.h"
17#include "tok.h"
18#include <omalloc.h>
19#include "febase.h"
20#include "subexpr.h"
21#include "ipid.h"
22#include "silink.h"
23#include "ipshell.h"
24#include "matpol.h"
25#include "ring.h"
26#include "lists.h"
27#include "ideals.h"
28#include "numbers.h"
29#include "intvec.h"
30
31// #ifdef HAVE_DBM
32// #ifdef ix86_Win
33// #define USE_GDBM
34// #endif
35// #endif
36
37omBin s_si_link_extension_bin = omGetSpecBin(sizeof(s_si_link_extension));
38omBin sip_link_bin = omGetSpecBin(sizeof(sip_link));
39omBin ip_link_bin = omGetSpecBin(sizeof(ip_link));
40
41/* declarations */
42static BOOLEAN DumpAscii(FILE *fd, idhdl h);
43static BOOLEAN DumpAsciiIdhdl(FILE *fd, idhdl h);
44static const char* GetIdString(idhdl h);
45static int DumpRhs(FILE *fd, idhdl h);
46static BOOLEAN DumpQring(FILE *fd, idhdl h, const char *type_str);
47static BOOLEAN DumpAsciiMaps(FILE *fd, idhdl h, idhdl rhdl);
48static si_link_extension slTypeInit(si_link_extension s, const char* type);
49
50/* ====================================================================== */
51si_link_extension si_link_root=NULL;
52
53BOOLEAN slInit(si_link l, char *istr)
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}
131
132void slCleanUp(si_link l)
133{
134  (l->ref)--;
135  if (l->ref == 0)
136  {
137    if (SI_LINK_OPEN_P(l))
138    {
139      if (l->m->Kill != NULL) l->m->Kill(l);
140      else if (l->m->Close != NULL) l->m->Close(l);
141    }
142    omFree((ADDRESS)l->name);
143    omFree((ADDRESS)l->mode);
144    memset((void *) l, 0, sizeof(ip_link));
145  }
146}
147
148void slKill(si_link l)
149{
150  slCleanUp(l);
151  if (l->ref == 0)
152    omFreeBin((ADDRESS)l,  ip_link_bin);
153}
154
155const char* slStatus(si_link l, const char *request)
156{
157  if (l == NULL) return "empty link";
158  else if (l->m == NULL) return "unknown link type";
159  else if (strcmp(request, "type") == 0) return l->m->type;
160  else if (strcmp(request, "mode") == 0) return l->mode;
161  else if (strcmp(request, "name") == 0) return l->name;
162  else if (strcmp(request, "exists") ==0)
163  {
164    struct stat buf;
165    if (lstat(l->name,&buf)==0) return "yes";
166    else return "no";
167  }
168  else if (strcmp(request, "open") == 0)
169  {
170    if (SI_LINK_OPEN_P(l)) return "yes";
171    else return "no";
172  }
173  else if (strcmp(request, "openread") == 0)
174  {
175    if (SI_LINK_R_OPEN_P(l)) return "yes";
176    else return "no";
177  }
178  else if (strcmp(request, "openwrite") == 0)
179  {
180    if (SI_LINK_W_OPEN_P(l)) return "yes";
181    else return "no";
182  }
183  else if (l->m->Status == NULL) return "unknown status request";
184  else return l->m->Status(l, request);
185}
186
187//--------------------------------------------------------------------------
188BOOLEAN slOpen(si_link l, short flag)
189{
190  BOOLEAN res;
191
192  if (l->m == NULL) slInit(l, "");
193
194  if (SI_LINK_OPEN_P(l))
195  {
196    Warn("open: link of type: %s, mode: %s, name: %s is already open",
197         l->m->type, l->mode, l->name);
198    return FALSE;
199  }
200  else if (l->m->Open != NULL)
201    res = l->m->Open(l, flag);
202  else
203    res = TRUE;
204
205  if (res)
206    Werror("open: Error for link of type: %s, mode: %s, name: %s",
207           l->m->type, l->mode, l->name);
208  return res;
209}
210
211BOOLEAN slClose(si_link l)
212{
213  BOOLEAN res;
214
215  if(! SI_LINK_OPEN_P(l))
216    return FALSE;
217  else if (l->m->Close != NULL)
218    res = l->m->Close(l);
219  else
220    res = TRUE;
221
222  if (res)
223    Werror("close: Error for link of type: %s, mode: %s, name: %s",
224           l->m->type, l->mode, l->name);
225  return res;
226}
227
228leftv slRead(si_link l, leftv a)
229{
230  char *mode;
231  leftv v = NULL;
232  if( ! SI_LINK_R_OPEN_P(l)) // open r ?
233  {
234#ifdef HAVE_DBM
235#ifdef USE_GDBM
236    if (! SI_LINK_CLOSE_P(l))
237      {
238        if (slClose(l)) return NULL;
239      }
240#endif
241#endif
242    if (slOpen(l, SI_LINK_READ)) return NULL;
243  }
244
245  if (SI_LINK_R_OPEN_P(l))
246  { // open r
247    if (a==NULL)
248    {
249      if (l->m->Read != NULL) v = l->m->Read(l);
250    }
251    else
252    {
253      if (l->m->Read2 != NULL) v = l->m->Read2(l,a);
254    }
255  }
256  else
257  {
258    Werror("read: Error to open link of type %s, mode: %s, name: %s for reading",
259           l->m->type, l->mode, l->name);
260    return NULL;
261  }
262
263  // here comes the eval:
264  if (v != NULL)
265  {
266    if (v->Eval() && !errorreported)
267      WerrorS("eval: failed");
268  }
269  else
270    Werror("read: Error for link of type %s, mode: %s, name: %s",
271           l->m->type, l->mode, l->name);
272  return v;
273}
274
275BOOLEAN slWrite(si_link l, leftv v)
276{
277  BOOLEAN res;
278
279  if(! SI_LINK_W_OPEN_P(l)) // open w ?
280  {
281#ifdef HAVE_DBM
282#ifdef USE_GDBM
283    if (! SI_LINK_CLOSE_P(l))
284      {
285        if (slClose(l)) return TRUE;
286      }
287#endif
288#endif
289    if (slOpen(l, SI_LINK_WRITE)) return TRUE;
290  }
291
292  if (SI_LINK_W_OPEN_P(l))
293  { // now open w
294    if (l->m->Write != NULL)
295      res = l->m->Write(l,v);
296    else
297      res = TRUE;
298
299    if (res)
300      Werror("write: Error for link of type %s, mode: %s, name: %s",
301             l->m->type, l->mode, l->name);
302    return res;
303  }
304  else
305  {
306    Werror("write: Error to open link of type %s, mode: %s, name: %s for writing",
307           l->m->type, l->mode, l->name);
308    return TRUE;
309  }
310}
311
312BOOLEAN slDump(si_link l)
313{
314  BOOLEAN res;
315
316  if(! SI_LINK_W_OPEN_P(l)) // open w ?
317  {
318    if (slOpen(l, SI_LINK_WRITE)) return TRUE;
319  }
320
321  if(SI_LINK_W_OPEN_P(l))
322  { // now open w
323    if (l->m->Dump != NULL)
324      res = l->m->Dump(l);
325    else
326      res = TRUE;
327
328    if (res)
329      Werror("dump: Error for link of type %s, mode: %s, name: %s",
330             l->m->type, l->mode, l->name);
331    return res;
332  }
333  else
334  {
335    Werror("dump: Error to open link of type %s, mode: %s, name: %s for writing",
336           l->m->type, l->mode, l->name);
337    return TRUE;
338  }
339}
340
341BOOLEAN slGetDump(si_link l)
342{
343  BOOLEAN res;
344
345  if(! SI_LINK_R_OPEN_P(l)) // open r ?
346  {
347    if (slOpen(l, SI_LINK_READ)) return TRUE;
348  }
349
350  if(SI_LINK_R_OPEN_P(l))
351  { // now open r
352    if (l->m->GetDump != NULL)
353      res = l->m->GetDump(l);
354    else
355      res = TRUE;
356
357    if (res)
358      Werror("getdump: Error for link of type %s, mode: %s, name: %s",
359             l->m->type, l->mode, l->name);
360    //res|=slClose(l);
361    return res;
362  }
363  else
364  {
365    Werror("dump: Error open link of type %s, mode: %s, name: %s for reading",
366           l->m->type, l->mode, l->name);
367    return TRUE;
368  }
369}
370
371
372/* =============== ASCII ============================================= */
373BOOLEAN slOpenAscii(si_link l, short flag)
374{
375  const char *mode;
376  if (flag & SI_LINK_OPEN)
377  {
378    if (l->mode[0] != '\0' && (strcmp(l->mode, "r") == 0))
379      flag = SI_LINK_READ;
380    else flag = SI_LINK_WRITE;
381  }
382
383  if (flag == SI_LINK_READ) mode = "r";
384  else if (strcmp(l->mode, "w") == 0) mode = "w";
385  else mode = "a";
386
387
388  if (l->name[0] == '\0')
389  {
390    // stdin or stdout
391    if (flag == SI_LINK_READ)
392    {
393      l->data = (void *) stdin;
394      mode = "r";
395    }
396    else
397    {
398      l->data = (void *) stdout;
399      mode = "a";
400    }
401  }
402  else
403  {
404    // normal ascii link to a file
405    FILE *outfile;
406    char *filename=l->name;
407
408    if(filename[0]=='>')
409    {
410      if (filename[1]=='>')
411      {
412        filename+=2;
413        mode = "a";
414      }
415      else
416      {
417        filename++;
418        mode="w";
419      }
420    }
421    outfile=myfopen(filename,mode);
422    if (outfile!=NULL)
423      l->data = (void *) outfile;
424    else
425      return TRUE;
426  }
427
428  omFree(l->mode);
429  l->mode = omStrDup(mode);
430  SI_LINK_SET_OPEN_P(l, flag);
431  return FALSE;
432}
433
434BOOLEAN slCloseAscii(si_link l)
435{
436  SI_LINK_SET_CLOSE_P(l);
437  if (l->name[0] != '\0')
438  {
439    return (fclose((FILE *)l->data)!=0);
440  }
441  return FALSE;
442}
443
444leftv slReadAscii2(si_link l, leftv pr)
445{
446  FILE * fp=(FILE *)l->data;
447  char * buf=NULL;
448  if (fp!=NULL && l->name[0] != '\0')
449  {
450    fseek(fp,0L,SEEK_END);
451    long len=ftell(fp);
452    fseek(fp,0L,SEEK_SET);
453    buf=(char *)omAlloc((int)len+1);
454    if (BVERBOSE(V_READING))
455      Print("//Reading %d chars\n",len);
456    myfread( buf, len, 1, fp);
457    buf[len]='\0';
458  }
459  else
460  {
461  #ifdef HAVE_TCL
462    if(tclmode)
463    {
464      WerrorS("reading from STDIN in TCL-mode not implemented");
465      buf=omStrDup("");
466    }
467    else
468  #endif
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  }
482  leftv v=(leftv)omAlloc0Bin(sleftv_bin);
483  v->rtyp=STRING_CMD;
484  v->data=buf;
485  return v;
486}
487
488leftv slReadAscii(si_link l)
489{
490  sleftv tmp;
491  memset(&tmp,0,sizeof(sleftv));
492  tmp.rtyp=STRING_CMD;
493  tmp.data=(void*) "? ";
494  return slReadAscii2(l,&tmp);
495}
496
497BOOLEAN slWriteAscii(si_link l, leftv v)
498{
499  FILE *outfile=(FILE *)l->data;
500  BOOLEAN err=FALSE;
501  char *s;
502  while (v!=NULL)
503  {
504    s = v->String();
505    // free v ??
506    if (s!=NULL)
507    {
508      fprintf(outfile,"%s\n",s);
509      omFree((ADDRESS)s);
510    }
511    else
512    {
513      Werror("cannot convert to string");
514      err=TRUE;
515    }
516    v = v->next;
517  }
518  fflush(outfile);
519  return err;
520}
521
522const char* slStatusAscii(si_link l, const char* request)
523{
524  if (strcmp(request, "read") == 0)
525  {
526    if (SI_LINK_R_OPEN_P(l)) return "ready";
527    else return "not ready";
528  }
529  else if (strcmp(request, "write") == 0)
530  {
531    if (SI_LINK_W_OPEN_P(l)) return "ready";
532    else return "not ready";
533  }
534  else return "unknown status request";
535}
536
537/*------------------ Dumping in Ascii format -----------------------*/
538
539BOOLEAN slDumpAscii(si_link l)
540{
541  FILE *fd = (FILE *) l->data;
542  idhdl h = IDROOT, rh = currRingHdl;
543  BOOLEAN status = DumpAscii(fd, h);
544
545  if (! status ) status = DumpAsciiMaps(fd, h, NULL);
546
547  if (currRingHdl != rh) rSetHdl(rh);
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  idtyp type_id = IDTYP(h);
608
609#ifdef HAVE_NS
610  if ((type_id == PACKAGE_CMD) &&(strcmp(IDID(h), "Top") == 0))
611    return FALSE;
612#endif
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#ifndef HAVE_NS
623  // do not dump LIB string
624  if (type_id == STRING_CMD && strcmp("LIB", IDID(h)) == 0)
625    return FALSE;
626#endif
627
628  // put type and name
629  if (fprintf(fd, "%s %s", type_str, IDID(h)) == EOF)
630    return TRUE;
631  // for matricies, append the dimension
632  if (type_id == MATRIX_CMD)
633  {
634    ideal id = IDIDEAL(h);
635    if (fprintf(fd, "[%d][%d]", id->nrows, id->ncols)== EOF) return TRUE;
636  }
637  else if (type_id == INTMAT_CMD)
638  {
639    if (fprintf(fd, "[%d][%d]", IDINTVEC(h)->rows(), IDINTVEC(h)->cols())
640        == EOF) return TRUE;
641  }
642
643#ifdef HAVE_NS
644  if (type_id == PACKAGE_CMD)
645  {
646    return (fprintf(fd, ";\n") == EOF);
647  }
648#endif
649
650  // write the equal sign
651  if (fprintf(fd, " = ") == EOF) return TRUE;
652
653  // and the right hand side
654  if (DumpRhs(fd, h) == EOF) return TRUE;
655
656  // semicolon und tschuess
657  if (fprintf(fd, ";\n") == EOF) return TRUE;
658
659  return FALSE;
660}
661
662static const char* GetIdString(idhdl h)
663{
664  idtyp type = IDTYP(h);
665
666  switch(type)
667  {
668      case LIST_CMD:
669      {
670        lists l = IDLIST(h);
671        int i, nl = l->nr + 1;
672        char *name;
673
674        for (i=0; i<nl; i++)
675          if (GetIdString((idhdl) &(l->m[i])) == NULL) return NULL;
676      }
677      case PACKAGE_CMD:
678      case INT_CMD:
679      case INTVEC_CMD:
680      case INTMAT_CMD:
681      case STRING_CMD:
682      case RING_CMD:
683      case QRING_CMD:
684      case PROC_CMD:
685      case NUMBER_CMD:
686      case POLY_CMD:
687      case IDEAL_CMD:
688      case VECTOR_CMD:
689      case MODUL_CMD:
690      case MATRIX_CMD:
691        return Tok2Cmdname(type);
692
693      case MAP_CMD:
694      case LINK_CMD:
695        return NULL;
696
697      default:
698       Warn("Error dump data of type %s", Tok2Cmdname(IDTYP(h)));
699       return NULL;
700  }
701}
702
703static BOOLEAN DumpQring(FILE *fd, idhdl h, const char *type_str)
704{
705  char *ring_str = h->String();
706  if (fprintf(fd, "%s temp_ring = %s;\n", Tok2Cmdname(RING_CMD), ring_str)
707              == EOF) return TRUE;
708  if (fprintf(fd, "%s temp_ideal = %s;\n", Tok2Cmdname(IDEAL_CMD),
709              iiStringMatrix((matrix) IDRING(h)->qideal, 1))
710      == EOF) return TRUE;
711  if (fprintf(fd, "attrib(temp_ideal, \"isSB\", 1);\n") == EOF) return TRUE;
712  if (fprintf(fd, "%s %s = temp_ideal;\n", type_str, IDID(h)) == EOF)
713    return TRUE;
714  if (fprintf(fd, "kill temp_ring;\n") == EOF) return TRUE;
715  else
716  {
717    omFree(ring_str);
718    return FALSE;
719  }
720}
721
722
723static int DumpRhs(FILE *fd, idhdl h)
724{
725  idtyp type_id = IDTYP(h);
726
727  if (type_id == LIST_CMD)
728  {
729    lists l = IDLIST(h);
730    int i, nl = l->nr;
731
732    fprintf(fd, "list(");
733
734    for (i=0; i<nl; i++)
735    {
736      if (DumpRhs(fd, (idhdl) &(l->m[i])) == EOF) return EOF;
737      fprintf(fd, ",");
738    }
739    if (nl > 0)
740    {
741      if (DumpRhs(fd, (idhdl) &(l->m[nl])) == EOF) return EOF;
742    }
743    fprintf(fd, ")");
744  }
745  else  if (type_id == STRING_CMD)
746  {
747    char *pstr = IDSTRING(h), c;
748    fputc('"', fd);
749    while (*pstr != '\0')
750    {
751      if (*pstr == '"' || *pstr == '\\')  fputc('\\', fd);
752      fputc(*pstr, fd);
753      pstr++;
754    }
755    fputc('"', fd);
756  }
757  else  if (type_id == PROC_CMD)
758  {
759    procinfov pi = IDPROC(h);
760    if (pi->language == LANG_SINGULAR) {
761      if( pi->data.s.body==NULL) iiGetLibProcBuffer(pi);
762      char *pstr = pi->data.s.body, c;
763      fputc('"', fd);
764      while (*pstr != '\0') {
765        if (*pstr == '"' || *pstr == '\\') fputc('\\', fd);
766        fputc(*pstr, fd);
767        pstr++;
768      }
769      fputc('"', fd);
770    } else fputs("(null)", fd);
771  }
772  else
773  {
774    char *rhs = h->String();
775
776    if (rhs == NULL) return EOF;
777
778    if (type_id == INTVEC_CMD) fprintf(fd, "intvec(");
779
780    if (fprintf(fd, "%s", rhs) == EOF) return EOF;
781    omFree(rhs);
782
783    if ((type_id == RING_CMD || type_id == QRING_CMD) &&
784        IDRING(h)->minpoly != NULL)
785    {
786      StringSetS("");
787      nWrite(IDRING(h)->minpoly);
788      rhs = StringAppendS("");
789      if (fprintf(fd, "; minpoly = %s", rhs) == EOF) return EOF;
790    }
791    else if (type_id == INTVEC_CMD) fprintf(fd, ")");
792  }
793  return 1;
794}
795
796BOOLEAN slGetDumpAscii(si_link l)
797{
798  if (l->name[0] == '\0')
799  {
800    Werror("getdump: Can not get dump from stdin");
801    return TRUE;
802  }
803  else
804  {
805    BOOLEAN status = newFile(l->name);
806    if (status)
807      return TRUE;
808
809    int old_echo=si_echo;
810    si_echo=0;
811
812    status=yyparse();
813
814    si_echo=old_echo;
815
816    if (status)
817      return TRUE;
818    else
819    {
820      // lets reset the file pointer to the end to reflect that
821      // we are finished with reading
822      FILE *f = (FILE *) l->data;
823      fseek(f, 0L, SEEK_END);
824      return FALSE;
825    }
826  }
827}
828
829
830/*------------Initialization at Start-up time------------------------*/
831
832#include "slInit.h"
833
834static si_link_extension slTypeInit(si_link_extension s, const char* type)
835{
836  assume(s != NULL);
837  s->next = NULL;
838  si_link_extension ns = (si_link_extension)omAlloc0Bin(s_si_link_extension_bin);
839
840#ifdef HAVE_MPSR
841  if (strcmp(type, "MPfile") == 0)
842    s->next = slInitMPFileExtension(ns);
843  else if (strcmp(type, "MPtcp") == 0)
844    s->next = slInitMPTcpExtension(ns);
845#ifdef HAVE_DBM
846  else
847#endif
848#endif
849#ifdef HAVE_DBM
850  if (strcmp(type, "DBM") == 0)
851    s->next = slInitDBMExtension(ns);
852#endif
853#if defined(HAVE_DBM) || defined(HAVE_MPSR)
854  else
855#endif
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.