00001
00002
00003
00004
00005
00006 #include <string.h>
00007 #include "FTables.h"
00008 #define FTable_H
00009 #include "stack-c.h"
00010 #include "stack2.h"
00011 #include "sciprint.h"
00012 #include "link.h"
00013
00014 static char buf[MAXNAME];
00015
00016 static int SearchComp __PARAMS((FTAB *Ftab, char *op, void (**realop) ( )));
00017 static void Emptyfunc __PARAMS((void)) {}
00018
00019 voidf GetFuncPtr(char *name, int n, FTAB *Table, voidf scifun, int *ifunc, int *lhs, int *rhs);
00020 voidf SetFunction __PARAMS((char *name, int *rep, FTAB *table));
00021
00022
00023
00024
00025
00026 voidf SetFunction(char *name, int *rep, FTAB *table)
00027 {
00028 void (*loc)();
00029 char *s;
00030
00031 strncpy(buf,name,MAXNAME);
00032 s=buf;
00033 while ( *s != ' ' && *s != '\0') { s++;};
00034 *s= '\0';
00035 if ( SearchComp(table,buf,&loc) == OK)
00036 {
00037 *rep = 0;
00038 return(loc);
00039 }
00040 if ( SearchInDynLinks(buf,&loc) >= 0 )
00041 {
00042 *rep = 0;
00043 return(loc);
00044 }
00045 loc = Emptyfunc;
00046 *rep = 1;
00047
00048 return(loc);
00049 }
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 static int SearchComp(FTAB *Ftab, char *op, void (**realop) ())
00060 {
00061 int i=0;
00062 while ( Ftab[i].name != (char *) 0)
00063 {
00064 int j;
00065 j = strcmp(op,Ftab[i].name);
00066 if ( j == 0 )
00067 {
00068 *realop = Ftab[i].f;
00069 return(OK);
00070 }
00071 else
00072 {
00073 if ( j <= 0)
00074 {
00075
00076 return(FAIL);
00077 }
00078 else i++;
00079 }
00080 }
00081
00082 return(FAIL);
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 #define a_chain 10
00106 #define a_function 13
00107
00108 voidf GetFuncPtr(char *name, int n, FTAB *Table, voidf scifun, int *ifunc, int *lhs, int *rhs)
00109 {
00110 int type,rep,mm,nn,nlhs,nrhs;
00111 voidf f;
00112 type=C2F(vartype)(&n);
00113 switch ( type)
00114 {
00115 case a_chain :
00116 GetRhsVar(n, "c", &mm, &nn, ifunc);
00117 f = SetFunction(cstk(*ifunc),&rep,Table);
00118 if ( rep == 1 )
00119 {
00120 Scierror(999,"%s: external %s not found \r\n",name,cstk(*ifunc));
00121 return (voidf) 0;
00122 }
00123 return f ;
00124 case a_function :
00125 GetRhsVar(n, "f", &nlhs,&nrhs, ifunc);
00126
00127
00128
00129
00130
00131
00132
00133
00134 return (voidf) scifun ;
00135 default:
00136 sciprint("Wrong parameter in %s ! (number %d)\r\n",name,n);
00137 Error(999);
00138 return (voidf) 0 ;
00139 }
00140 }