source: git/Singular/blackbox.cc @ c728c0

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