source: git/Singular/blackbox.cc @ 7a0a4c

spielwiese
Last change on this file since 7a0a4c was 7a0a4c, checked in by Hans Schoenemann <hannes@…>, 13 years ago
better error message for blackbox stuff git-svn-id: file:///usr/local/Singular/svn/trunk@13826 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.4 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 blackbox_default_Op1(int op,leftv l, leftv r)
44{
45  Werror("blackbox_Op1 of type %s(%d) for op %s(%d) not implemented",
46     getBlackboxName(r->Typ()),r->Typ(),Tok2Cmdname(op),op);
47  return TRUE;
48}
49BOOLEAN blackbox_default_Op2(int op,leftv l, leftv r1, leftv r2)
50{
51  Werror("blackbox_Op2 of type %s(%d) for op %s(%d) not implemented",
52     getBlackboxName(r1->Typ()),r1->Typ(),Tok2Cmdname(op),op);
53  return TRUE;
54}
55BOOLEAN blackbox_default_Op3(int op,leftv l, leftv r1,leftv r2, leftv r3)
56{
57  Werror("blackbox_Op3 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_OpM(int op,leftv l, leftv r)
62{
63  Werror("blackbox_OpM of type %s(%d) for op %s(%d) not implemented",
64     getBlackboxName(r->Typ()),r->Typ(),Tok2Cmdname(op),op);
65  return TRUE;
66}
67
68int setBlackboxStuff(blackbox *bb, const char *n)
69{
70  blackboxTable[blackboxTableCnt]=bb;
71  blackboxName[blackboxTableCnt]=omStrDup(n);
72#ifdef BLACKBOX_DEVEL
73  Print("define bb:name=%s:rt=%d (table:cnt=%d)\n",blackboxName[blackboxTableCnt],blackboxTableCnt+BLACKBOX_OFFSET,blackboxTableCnt);
74#endif
75  if (bb->blackbox_destroy==NULL) bb->blackbox_destroy=blackbox_default_destroy;
76  if (bb->blackbox_String==NULL)  bb->blackbox_String=blackbox_default_String;
77  if (bb->blackbox_Print==NULL)   bb->blackbox_Print=blackbox_default_Print;
78  if (bb->blackbox_Init==NULL)    bb->blackbox_Init=blackbox_default_Init;
79  if (bb->blackbox_Copy==NULL)    bb->blackbox_Copy=blackbox_default_Copy;
80  if (bb->blackbox_Op1==NULL)     bb->blackbox_Op1=blackbox_default_Op1;
81  if (bb->blackbox_Op2==NULL)     bb->blackbox_Op2=blackbox_default_Op2;
82  if (bb->blackbox_Op3==NULL)     bb->blackbox_Op3=blackbox_default_Op3;
83  if (bb->blackbox_OpM==NULL)     bb->blackbox_OpM=blackbox_default_OpM;
84  blackboxTableCnt++;
85  return blackboxTableCnt+BLACKBOX_OFFSET-1;
86}
87void removeBlackboxStuff(const int rt)
88{
89  blackboxTable[rt-BLACKBOX_OFFSET]=NULL;
90  blackboxName[rt-BLACKBOX_OFFSET]=NULL;
91}
92const char *getBlackboxName(const int t)
93{
94 char *b=blackboxName[t-BLACKBOX_OFFSET];
95  if (b!=NULL) return b;
96  else         return "";
97}
98int blackboxIsCmd(const char *n, int & tok)
99{
100  for(int i=blackboxTableCnt-1;i>=0;i--)
101  {
102    if(strcmp(n,blackboxName[i])==0)
103    {
104#ifdef BLACKBOX_DEVEL
105      Print("found bb:%s:%d (table:%d)\n",n,i+BLACKBOX_OFFSET,i);
106#endif
107      tok=i+BLACKBOX_OFFSET;
108      return ROOT_DECL;
109    }
110  }
111  return 0;
112}
113
114void printBlackboxTypes()
115{
116  for(int i=blackboxTableCnt-1;i>=0;i--)
117  {
118    Print("blackbox %d: %s\n",i,blackboxName[i]);
119  }
120}
Note: See TracBrowser for help on using the repository browser.