source: git/Singular/links/silink.cc @ cecef0

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