source: git/Singular/silink.cc @ 584f84d

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