source: git/Singular/silink.cc @ a6904c

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