source: git/Singular/silink.cc @ eff324

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