source: git/Singular/silink.cc @ 50cbdc

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