source: git/Singular/silink.cc @ 110345

spielwiese
Last change on this file since 110345 was a3bc95e, checked in by Hans Schönemann <hannes@…>, 23 years ago
*hannes: namespaces ->ns git-svn-id: file:///usr/local/Singular/svn/trunk@5651 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 19.5 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: silink.cc,v 1.42 2001-10-09 16:36:22 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#ifdef HAVE_NS
621  if ((type_id == PACKAGE_CMD) &&(strcmp(IDID(h), "Top") == 0))
622    return FALSE;
623#endif
624
625  // we do not throw an error if a wrong type was attempted to be dumped
626  if (type_str == NULL)
627    return FALSE;
628
629  // handle qrings separately
630  if (type_id == QRING_CMD)
631    return DumpQring(fd, h, type_str);
632
633#ifndef HAVE_NAMESPACES
634#ifndef HAVE_NS
635  // do not dump LIB string
636  if (type_id == STRING_CMD && strcmp("LIB", IDID(h)) == 0)
637    return FALSE;
638#endif
639#endif
640
641  // put type and name
642#ifdef HAVE_NAMESPACES
643  if (fprintf(fd, "%s %s::%s", type_str, namespaceroot->name, IDID(h)) == EOF)
644    return TRUE;
645#else
646  if (fprintf(fd, "%s %s", type_str, IDID(h)) == EOF)
647    return TRUE;
648#endif
649  // for matricies, append the dimension
650  if (type_id == MATRIX_CMD)
651  {
652    ideal id = IDIDEAL(h);
653    if (fprintf(fd, "[%d][%d]", id->nrows, id->ncols)== EOF) return TRUE;
654  }
655  else if (type_id == INTMAT_CMD)
656  {
657    if (fprintf(fd, "[%d][%d]", IDINTVEC(h)->rows(), IDINTVEC(h)->cols())
658        == EOF) return TRUE;
659  }
660
661#ifdef HAVE_NAMESPACES
662  if (type_id == PACKAGE_CMD)
663  {
664    if (fprintf(fd, ";\n") == EOF) return TRUE;
665    else return FALSE;
666  }
667#endif
668#ifdef HAVE_NS
669  if (type_id == PACKAGE_CMD)
670  {
671    return (fprintf(fd, ";\n") == EOF);
672  }
673#endif
674
675  // write the equal sign
676  if (fprintf(fd, " = ") == EOF) return TRUE;
677
678  // and the right hand side
679  if (DumpRhs(fd, h) == EOF) return TRUE;
680
681  // semicolon und tschuess
682  if (fprintf(fd, ";\n") == EOF) return TRUE;
683
684  return FALSE;
685}
686
687static char* GetIdString(idhdl h)
688{
689  idtyp type = IDTYP(h);
690
691  switch(type)
692  {
693      case LIST_CMD:
694      {
695        lists l = IDLIST(h);
696        int i, nl = l->nr + 1;
697        char *name;
698
699        for (i=0; i<nl; i++)
700          if (GetIdString((idhdl) &(l->m[i])) == NULL) return NULL;
701      }
702      case PACKAGE_CMD:
703      case INT_CMD:
704      case INTVEC_CMD:
705      case INTMAT_CMD:
706      case STRING_CMD:
707      case RING_CMD:
708      case QRING_CMD:
709      case PROC_CMD:
710      case NUMBER_CMD:
711      case POLY_CMD:
712      case IDEAL_CMD:
713      case VECTOR_CMD:
714      case MODUL_CMD:
715      case MATRIX_CMD:
716        return Tok2Cmdname(type);
717
718      case MAP_CMD:
719      case LINK_CMD:
720        return NULL;
721
722      default:
723       Warn("Error dump data of type %s", Tok2Cmdname(IDTYP(h)));
724       return NULL;
725  }
726}
727
728static BOOLEAN DumpQring(FILE *fd, idhdl h, char *type_str)
729{
730  char *ring_str = h->String();
731  if (fprintf(fd, "%s temp_ring = %s;\n", Tok2Cmdname(RING_CMD), ring_str)
732              == EOF) return TRUE;
733  if (fprintf(fd, "%s temp_ideal = %s;\n", Tok2Cmdname(IDEAL_CMD),
734              iiStringMatrix((matrix) IDRING(h)->qideal, 1))
735      == EOF) return TRUE;
736  if (fprintf(fd, "attrib(temp_ideal, \"isSB\", 1);\n") == EOF) return TRUE;
737#ifdef HAVE_NAMESPACES
738  if (fprintf(fd, "%s %s::%s = temp_ideal;\n",
739              type_str,  namespaceroot->name, IDID(h)) == EOF)
740#else
741  if (fprintf(fd, "%s %s = temp_ideal;\n", type_str, IDID(h)) == EOF)
742#endif
743    return TRUE;
744  if (fprintf(fd, "kill temp_ring;\n") == EOF) return TRUE;
745  else
746  {
747    omFree(ring_str);
748    return FALSE;
749  }
750}
751
752
753static int DumpRhs(FILE *fd, idhdl h)
754{
755  idtyp type_id = IDTYP(h);
756
757  if (type_id == LIST_CMD)
758  {
759    lists l = IDLIST(h);
760    int i, nl = l->nr;
761
762    fprintf(fd, "list(");
763
764    for (i=0; i<nl; i++)
765    {
766      if (DumpRhs(fd, (idhdl) &(l->m[i])) == EOF) return EOF;
767      fprintf(fd, ",");
768    }
769    if (nl > 0)
770    {
771      if (DumpRhs(fd, (idhdl) &(l->m[nl])) == EOF) return EOF;
772    }
773    fprintf(fd, ")");
774  }
775  else  if (type_id == STRING_CMD)
776  {
777    char *pstr = IDSTRING(h), c;
778    fputc('"', fd);
779    while (*pstr != '\0')
780    {
781      if (*pstr == '"' || *pstr == '\\')  fputc('\\', fd);
782      fputc(*pstr, fd);
783      pstr++;
784    }
785    fputc('"', fd);
786  }
787  else  if (type_id == PROC_CMD)
788  {
789    procinfov pi = IDPROC(h);
790    if (pi->language == LANG_SINGULAR) {
791      if( pi->data.s.body==NULL) iiGetLibProcBuffer(pi);
792      char *pstr = pi->data.s.body, c;
793      fputc('"', fd);
794      while (*pstr != '\0') {
795        if (*pstr == '"' || *pstr == '\\') fputc('\\', fd);
796        fputc(*pstr, fd);
797        pstr++;
798      }
799      fputc('"', fd);
800    } else fputs("(null)", fd);
801  }
802  else
803  {
804    char *rhs = h->String();
805
806    if (rhs == NULL) return EOF;
807
808    if (type_id == INTVEC_CMD) fprintf(fd, "intvec(");
809
810    if (fprintf(fd, "%s", rhs) == EOF) return EOF;
811    omFree(rhs);
812
813    if ((type_id == RING_CMD || type_id == QRING_CMD) &&
814        IDRING(h)->minpoly != NULL)
815    {
816      StringSetS("");
817      nWrite(IDRING(h)->minpoly);
818      rhs = StringAppendS("");
819      if (fprintf(fd, "; minpoly = %s", rhs) == EOF) return EOF;
820    }
821    else if (type_id == INTVEC_CMD) fprintf(fd, ")");
822  }
823  return 1;
824}
825
826BOOLEAN slGetDumpAscii(si_link l)
827{
828  if (l->name[0] == '\0')
829  {
830    Werror("getdump: Can not get dump from stdin");
831    return TRUE;
832  }
833  else
834  {
835    BOOLEAN status = newFile(l->name);
836    if (status)
837      return TRUE;
838
839    int old_echo=si_echo;
840    si_echo=0;
841
842    status=yyparse();
843
844    si_echo=old_echo;
845
846    if (status)
847      return TRUE;
848    else
849    {
850      // lets reset the file pointer to the end to reflect that
851      // we are finished with reading
852      FILE *f = (FILE *) l->data;
853      fseek(f, 0L, SEEK_END);
854      return FALSE;
855    }
856  }
857}
858
859
860/*------------Initialization at Start-up time------------------------*/
861
862#include "slInit.h"
863
864static si_link_extension slTypeInit(si_link_extension s, const char* type)
865{
866  assume(s != NULL);
867  s->next = NULL;
868  si_link_extension ns = (si_link_extension)omAlloc0Bin(s_si_link_extension_bin);
869
870#ifdef HAVE_MPSR
871  if (strcmp(type, "MPfile") == 0)
872    s->next = slInitMPFileExtension(ns);
873  else if (strcmp(type, "MPtcp") == 0)
874    s->next = slInitMPTcpExtension(ns);
875#ifdef HAVE_DBM
876  else
877#endif
878#endif
879#ifdef HAVE_DBM
880  if (strcmp(type, "DBM") == 0)
881    s->next = slInitDBMExtension(ns);
882#endif
883#if defined(HAVE_DBM) || defined(HAVE_MPSR)
884  else
885#endif
886  {
887    Warn("Found unknown link type: %s", type);
888    Warn("Use default link type: %s", si_link_root->type);
889    omFreeBin(ns, s_si_link_extension_bin);
890    return si_link_root;
891  }
892
893  if (s->next == NULL)
894  {
895    Werror("Can not initialize link type %s", type);
896    omFreeBin(ns, s_si_link_extension_bin);
897    return NULL;
898  }
899  return s->next;
900}
901
902void slStandardInit()
903{
904  si_link_extension s;
905  si_link_root=(si_link_extension)omAlloc0Bin(s_si_link_extension_bin);
906  si_link_root->Open=slOpenAscii;
907  si_link_root->Close=slCloseAscii;
908  si_link_root->Kill=slCloseAscii;
909  si_link_root->Read=slReadAscii;
910  si_link_root->Read2=slReadAscii2;
911  si_link_root->Write=slWriteAscii;
912  si_link_root->Dump=slDumpAscii;
913  si_link_root->GetDump=slGetDumpAscii;
914  si_link_root->Status=slStatusAscii;
915  si_link_root->type="ASCII";
916  s = si_link_root;
917  s->next = NULL;
918}
Note: See TracBrowser for help on using the repository browser.