source: git/Singular/silink.cc @ f2dff02

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