source: git/Singular/blackbox.cc @ 06fdbe

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