source: git/Singular/links/silink.cc @ 80c703

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