home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / gle / gle / fn.c < prev    next >
C/C++ Source or Header  |  1992-11-29  |  3KB  |  133 lines

  1. #include "all.h"
  2.  
  3. /*------------------------------------------------------------------*/
  4. /*      Find the function callped *cp, and return it's number       */
  5. /*------------------------------------------------------------------*/
  6.  
  7. /* You can add a function, you MUST place it in alphabetical order  */
  8. /* and give it the next unused index number                */
  9.  
  10. /* ret = Type of returned value,  1=number, 2=string */
  11. /* np = number of paramters expected */
  12. /* Parameters p0...p4  ==  1=number, 2=string, 0=none (e.g. height()) .  */
  13.  
  14. #define NKEYS (sizeof keywfn / sizeof(struct keyw))
  15. struct keyw { char *word; int index; int ret,np,p[5]; } keywfn[] = {
  16.         " ",0        ,1 ,0 ,0,0,0,0,0
  17.         ,"+",1        ,1 ,0 ,0,0,0,0,0
  18.         ,"-",2        ,1 ,0 ,0,0,0,0,0
  19.         ,"ABS",3    ,1 ,1 ,1,0,0,0,0
  20.         ,"ACOS",53    ,1 ,1 ,1,0,0,0,0
  21.         ,"ASIN",54    ,1 ,1 ,1,0,0,0,0
  22.         ,"ATN",4    ,1 ,1 ,1,0,0,0,0
  23.         ,"CHR$",52    ,2 ,1 ,1,0,0,0,0
  24.         ,"COS",5    ,1 ,1 ,1,0,0,0,0
  25.         ,"CVTCOLOR",49  ,1 ,1 ,2,0,0,0,0
  26.         ,"CVTFONT",50    ,1 ,1 ,2,0,0,0,0
  27.         ,"CVTGREY",45    ,1 ,1 ,1,0,0,0,0
  28.         ,"CVTINT",46    ,1 ,1 ,1,0,0,0,0
  29.         ,"CVTMARKER",48 ,1 ,1 ,2,0,0,0,0
  30.         ,"CVTRGB",47    ,1 ,3 ,1,1,1,0,0
  31.         ,"DATE$",6    ,2 ,0 ,0,0,0,0,0
  32.         ,"DEVICE$",51    ,2 ,0 ,0,0,0,0,0
  33.         ,"EOF",55    ,1 ,1 ,1,0,0,0,0
  34.         ,"EXP",7    ,1 ,1 ,1,0,0,0,0
  35.         ,"FEOF",55    ,1 ,1 ,1,0,0,0,0
  36.         ,"FIX",8    ,1 ,1 ,1,0,0,0,0
  37.         ,"HEIGHT",9    ,1 ,1 ,0,0,0,0,0
  38.         ,"INT",10    ,1 ,1 ,1,0,0,0,0
  39.         ,"LEFT$",11    ,2 ,2 ,2,1,0,0,0
  40.         ,"LEN",12    ,1 ,1 ,2,0,0,0,0
  41.         ,"LOG",13    ,1 ,1 ,1,0,0,0,0
  42.         ,"LOG10",14    ,1 ,1 ,1,0,0,0,0
  43.         ,"NOT",15    ,1 ,1 ,1,0,0,0,0
  44.         ,"NUM$",16    ,2 ,1 ,1,0,0,0,0
  45.         ,"NUM1$",17    ,2 ,1 ,1,0,0,0,0
  46.         ,"PAGEHEIGHT",18,1 ,1 ,0,0,0,0,0
  47.         ,"PAGEWIDTH",19    ,1 ,1 ,0,0,0,0,0
  48.         ,"POS",20    ,1 ,3 ,2,2,1,0,0
  49.         ,"RIGHT$",21    ,2 ,2 ,2,1,0,0,0
  50.         ,"RND",22    ,1 ,1 ,1,0,0,0,0
  51.         ,"SEG$",23    ,2 ,3 ,2,1,1,0,0
  52.         ,"SGN",24    ,1 ,1 ,1,0,0,0,0
  53.         ,"SIN",25    ,1 ,1 ,1,0,0,0,0
  54.         ,"SQR",26    ,1 ,1 ,1,0,0,0,0
  55.         ,"SQRT",27    ,1 ,1 ,1,0,0,0,0
  56.         ,"TAN",28    ,1 ,1 ,1,0,0,0,0
  57.         ,"TDEPTH",29    ,1 ,1 ,2,0,0,0,0
  58.         ,"THEIGHT",30    ,1 ,1 ,2,0,0,0,0
  59.         ,"TIME$",31    ,2 ,0 ,0,0,0,0,0
  60.         ,"TWIDTH",32    ,1 ,1 ,2,0,0,0,0
  61.         ,"VAL",33    ,1 ,1 ,2,0,0,0,0
  62.         ,"WIDTH",34    ,1 ,1 ,0,0,0,0,0
  63.         ,"XEND",35    ,1 ,1 ,0,0,0,0,0
  64.         ,"XG",36    ,1 ,1 ,1,0,0,0,0
  65.         ,"XGRAPH",36    ,1 ,1 ,1,0,0,0,0
  66.         ,"XMAX",37    ,1 ,1 ,0,0,0,0,0
  67.         ,"XMIN",38    ,1 ,1 ,0,0,0,0,0
  68.         ,"XPOS",39    ,1 ,1 ,0,0,0,0,0
  69.         ,"YEND",40    ,1 ,1 ,0,0,0,0,0
  70.         ,"YG",41    ,1 ,1 ,1,0,0,0,0
  71.         ,"YGRAPH",41    ,1 ,1 ,1,0,0,0,0
  72.         ,"YMAX",42    ,1 ,1 ,0,0,0,0,0
  73.         ,"YMIN",43    ,1 ,1 ,0,0,0,0,0
  74.         ,"YPOS",44    ,1 ,1 ,0,0,0,0,0
  75. } ;
  76.  
  77. int binsearch(char *word, struct keyw tab[], int n);
  78.  
  79. find_un(char *cp, int *idx,int *ret,int *np,int **plist)
  80. {
  81.     int i;
  82.     i = binsearch(cp,keywfn,NKEYS);
  83.     *idx = keywfn[i].index;
  84.     *ret = keywfn[i].ret;
  85.     *np =  keywfn[i].np;
  86.     *plist = &keywfn[i].p[0];
  87. }
  88.  
  89. /*------------------------------------------------------------------*/
  90. /* Simple binary search                         */
  91. /*------------------------------------------------------------------*/
  92. binsearch(char *word, struct keyw tab[], int n)
  93. {
  94.     int cond,low,high,mid;
  95.     low = 0;
  96.     high = n-1;
  97.     while (low <= high) {
  98.         mid = (low+high) / 2;
  99.         if ((cond = strcmp(word,tab[mid].word)) < 0)
  100.             high = mid - 1;
  101.         else if (cond > 0)
  102.             low = mid + 1;
  103.         else
  104.             return mid;
  105.     }
  106.     return 0;
  107. }
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.