1 | #include <Singular/mod2.h> |
---|
2 | #include <Singular/tok.h> |
---|
3 | #include <Singular/subexpr.h> |
---|
4 | #include <Singular/blackbox.h> |
---|
5 | |
---|
6 | static blackbox* blackboxTable[100]; |
---|
7 | static char * blackboxName[100]; |
---|
8 | static int blackboxTableCnt=0; |
---|
9 | #define BLACKBOX_OFFSET (MAX_TOK+1) |
---|
10 | blackbox* getBlackboxStuff(const int t) |
---|
11 | { |
---|
12 | return (blackboxTable[t-BLACKBOX_OFFSET]); |
---|
13 | } |
---|
14 | |
---|
15 | |
---|
16 | void blackbox_default_destroy(blackbox *b, void *d) |
---|
17 | { |
---|
18 | Werror("missing blackbox_destroy"); |
---|
19 | } |
---|
20 | char *blackbox_default_String(blackbox *b,void *d) |
---|
21 | { |
---|
22 | Werror("missing blackbox_String"); |
---|
23 | return omStrDup(""); |
---|
24 | } |
---|
25 | void *blackbox_default_Copy(blackbox *b,void *d) |
---|
26 | { |
---|
27 | Werror("missing blackbox_Copy"); |
---|
28 | return NULL; |
---|
29 | } |
---|
30 | void blackbox_default_Print(blackbox *b,void *d) |
---|
31 | { |
---|
32 | char *s=b->blackbox_String(b,d); |
---|
33 | PrintS(s); |
---|
34 | omFree(s); |
---|
35 | } |
---|
36 | void *blackbox_default_Init() |
---|
37 | { |
---|
38 | return NULL; |
---|
39 | } |
---|
40 | BOOLEAN 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 | } |
---|
45 | BOOLEAN 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 | } |
---|
50 | BOOLEAN 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 | } |
---|
55 | BOOLEAN 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 | |
---|
61 | int 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 | } |
---|
78 | void removeBlackboxStuff(const int rt) |
---|
79 | { |
---|
80 | blackboxTable[rt-BLACKBOX_OFFSET]=NULL; |
---|
81 | blackboxName[rt-BLACKBOX_OFFSET]=NULL; |
---|
82 | } |
---|
83 | const char *getBlackboxName(const int t) |
---|
84 | { |
---|
85 | char *b=blackboxName[t-BLACKBOX_OFFSET]; |
---|
86 | if (b!=NULL) return b; |
---|
87 | else return ""; |
---|
88 | } |
---|
89 | int 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 | |
---|
103 | void printBlackboxTypes() |
---|
104 | { |
---|
105 | for(int i=blackboxTableCnt-1;i>=0;i--) |
---|
106 | { |
---|
107 | Print("blackbox %d: %s\n",i,blackboxName[i]); |
---|
108 | } |
---|
109 | } |
---|