source: git/Singular/blackbox.cc @ b6efeb1

fieker-DuValspielwiese
Last change on this file since b6efeb1 was b6efeb1, checked in by Hans Schoenemann <hannes@…>, 13 years ago
syntax fix git-svn-id: file:///usr/local/Singular/svn/trunk@13744 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.1 KB
Line 
1#include <Singular/mod2.h>
2#include <Singular/tok.h>
3#include <Singular/subexpr.h>
4#include <Singular/blackbox.h>
5
6static blackbox* blackboxTable[100];
7static char *    blackboxName[100];
8static int blackboxTableCnt=0;
9#define BLACKBOX_OFFSET (MAX_TOK+1)
10blackbox* getBlackboxStuff(const int t)
11{
12  return (blackboxTable[t-BLACKBOX_OFFSET]);
13}
14
15
16void blackbox_default_destroy(blackbox  *b, void *d)
17{
18  Werror("missing blackbox_destroy");
19}
20char *blackbox_default_String(blackbox *b,void *d)
21{
22  Werror("missing blackbox_String");
23  return omStrDup("");
24}
25void *blackbox_default_Copy(blackbox *b,void *d)
26{
27  Werror("missing blackbox_Copy");
28  return NULL;
29}
30void blackbox_default_Print(blackbox *b,void *d)
31{
32  char *s=b->blackbox_String(b,d);
33  PrintS(s);
34  omFree(s);
35}
36void *blackbox_default_Init()
37{
38  return NULL;
39}
40BOOLEAN blackbox_default_Op1(int op,leftv l, leftv r)
41{
42  Werror("blackbox_Op1  of type %d for op %d not implemented",r->Typ(),op);
43  return TRUE;
44}
45BOOLEAN blackbox_default_Op2(int op,leftv l, leftv r1, leftv r2)
46{
47  Werror("blackbox_Op2  of type %d for op %d not implemented",r1->Typ(),op);
48  return TRUE;
49}
50BOOLEAN blackbox_default_Op3(int op,leftv l, leftv r1,leftv r2, leftv r3)
51{
52  Werror("blackbox_Op3 of type %d for op %d not implemented",r1->Typ(),op);
53  return TRUE;
54}
55BOOLEAN blackbox_default_OpM(int op,leftv l, leftv r)
56{
57  Werror("blackbox_OpM of type %d for op %d not implemented",r->Typ(),op);
58  return TRUE;
59}
60
61int setBlackboxStuff(blackbox *bb, char *n)
62{
63  blackboxTable[blackboxTableCnt]=bb;
64  blackboxName[blackboxTableCnt]=omStrDup(n);
65  Print("define bb:name=%s:rt=%d (table:cnt=%d)\n",blackboxName[blackboxTableCnt],blackboxTableCnt+BLACKBOX_OFFSET,blackboxTableCnt);
66  if (bb->blackbox_destroy==NULL) bb->blackbox_destroy=blackbox_default_destroy;
67  if (bb->blackbox_String==NULL)  bb->blackbox_String=blackbox_default_String;
68  if (bb->blackbox_Print==NULL)   bb->blackbox_Print=blackbox_default_Print;
69  if (bb->blackbox_Init==NULL)    bb->blackbox_Init=blackbox_default_Init;
70  if (bb->blackbox_Copy==NULL)    bb->blackbox_Copy=blackbox_default_Copy;
71  if (bb->blackbox_Op1==NULL)     bb->blackbox_Op1=blackbox_default_Op1;
72  if (bb->blackbox_Op2==NULL)     bb->blackbox_Op2=blackbox_default_Op2;
73  if (bb->blackbox_Op3==NULL)     bb->blackbox_Op3=blackbox_default_Op3;
74  if (bb->blackbox_OpM==NULL)     bb->blackbox_OpM=blackbox_default_OpM;
75  blackboxTableCnt++;
76  return blackboxTableCnt+BLACKBOX_OFFSET-1;
77}
78void removeBlackboxStuff(const int rt)
79{
80  blackboxTable[rt-BLACKBOX_OFFSET]=NULL;
81  blackboxName[rt-BLACKBOX_OFFSET]=NULL;
82}
83const char *getBlackboxName(const int t)
84{
85 char *b=blackboxName[t-BLACKBOX_OFFSET];
86  if (b!=NULL) return b;
87  else         return "";
88}
89int blackboxIsCmd(const char *n, int & tok)
90{
91  for(int i=blackboxTableCnt-1;i>=0;i--)
92  {
93    if(strcmp(n,blackboxName[i])==0)
94    {
95      Print("found bb:%s:%d (table:%d)\n",n,i+BLACKBOX_OFFSET,i);
96      tok=i+BLACKBOX_OFFSET;
97      return ROOT_DECL;
98    }
99  }
100  return 0;
101}
102
103void printBlackboxTypes()
104{
105  for(int i=blackboxTableCnt-1;i>=0;i--)
106  {
107    Print("blackbox %d: %s\n",i,blackboxName[i]);
108  }
109}
Note: See TracBrowser for help on using the repository browser.