home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 334_01 / eval.c < prev    next >
Text File  |  1991-02-05  |  4KB  |  142 lines

  1. /* GNUPLOT - eval.c */
  2. /*
  3.  * Copyright (C) 1986, 1987, 1990   Thomas Williams, Colin Kelley
  4.  *
  5.  * Permission to use, copy, and distribute this software and its
  6.  * documentation for any purpose with or without fee is hereby granted, 
  7.  * provided that the above copyright notice appear in all copies and 
  8.  * that both that copyright notice and this permission notice appear 
  9.  * in supporting documentation.
  10.  *
  11.  * Permission to modify the software is granted, but not the right to
  12.  * distribute the modified code.  Modifications are to be distributed 
  13.  * as patches to released version.
  14.  *  
  15.  * This software  is provided "as is" without express or implied warranty.
  16.  * 
  17.  *
  18.  * AUTHORS
  19.  * 
  20.  *   Original Software:
  21.  *     Thomas Williams,  Colin Kelley.
  22.  * 
  23.  *   Gnuplot 2.0 additions:
  24.  *       Russell Lang, Dave Kotz, John Campbell.
  25.  * 
  26.  * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  27.  * 
  28.  */
  29.  
  30. #include <stdio.h>
  31. #include "plot.h"
  32.  
  33. extern int c_token;
  34. extern struct ft_entry ft[];
  35. extern struct udvt_entry *first_udv;
  36. extern struct udft_entry *first_udf;
  37. extern struct at_type at;
  38. extern struct lexical_unit token[];
  39.  
  40. struct value *integer();
  41.  
  42.  
  43.  
  44. struct udvt_entry *
  45. add_udv(t_num)  /* find or add value and return pointer */
  46. int t_num;
  47. {
  48. register struct udvt_entry **udv_ptr = &first_udv;
  49.  
  50.     /* check if it's already in the table... */
  51.  
  52.     while (*udv_ptr) {
  53.         if (equals(t_num,(*udv_ptr)->udv_name))
  54.             return(*udv_ptr);
  55.         udv_ptr = &((*udv_ptr)->next_udv);
  56.     }
  57.  
  58.     *udv_ptr = (struct udvt_entry *)
  59.       alloc((unsigned int)sizeof(struct udvt_entry), "value");
  60.     (*udv_ptr)->next_udv = NULL;
  61.     copy_str((*udv_ptr)->udv_name,t_num);
  62.     (*udv_ptr)->udv_value.type = INT;    /* not necessary, but safe! */
  63.     (*udv_ptr)->udv_undef = TRUE;
  64.     return(*udv_ptr);
  65. }
  66.  
  67.  
  68. struct udft_entry *
  69. add_udf(t_num)  /* find or add function and return pointer */
  70. int t_num; /* index to token[] */
  71. {
  72. register struct udft_entry **udf_ptr = &first_udf;
  73.  
  74.     while (*udf_ptr) {
  75.         if (equals(t_num,(*udf_ptr)->udf_name))
  76.             return(*udf_ptr);
  77.         udf_ptr = &((*udf_ptr)->next_udf);
  78.     }
  79.      *udf_ptr = (struct udft_entry *)
  80.       alloc((unsigned int)sizeof(struct udft_entry), "function");
  81.     (*udf_ptr)->next_udf = (struct udft_entry *) NULL;
  82.     (*udf_ptr)->definition = NULL;
  83.     (*udf_ptr)->at = NULL;
  84.     copy_str((*udf_ptr)->udf_name,t_num);
  85.     (void) integer(&((*udf_ptr)->dummy_value), 0);
  86.     return(*udf_ptr);
  87. }
  88.  
  89.  
  90. union argument *
  91. add_action(sf_index)
  92. enum operators sf_index;        /* index of p-code function */
  93. {
  94.     if (at.a_count >= MAX_AT_LEN)
  95.         int_error("action table overflow",NO_CARET);
  96.     at.actions[at.a_count].index = sf_index;
  97.     return(&(at.actions[at.a_count++].arg));
  98. }
  99.  
  100.  
  101. int standard(t_num)  /* return standard function index or 0 */
  102. {
  103. register int i;
  104.     for (i = (int)SF_START; ft[i].f_name != NULL; i++) {
  105.         if (equals(t_num,ft[i].f_name))
  106.             return(i);
  107.     }
  108.     return(0);
  109. }
  110.  
  111.  
  112.  
  113. execute_at(at_ptr)
  114. struct at_type *at_ptr;
  115. {
  116. register int i,index,count,offset;
  117.  
  118.     count = at_ptr->a_count;
  119.     for (i = 0; i < count;) {
  120.         index = (int)at_ptr->actions[i].index;
  121.         offset = (*ft[index].func)(&(at_ptr->actions[i].arg));
  122.         if (is_jump(index))
  123.             i += offset;
  124.         else
  125.             i++;
  126.     }
  127. }
  128.  
  129. /*
  130.  
  131.  'ft' is a table containing C functions within this program. 
  132.  
  133.  An 'action_table' contains pointers to these functions and arguments to be
  134.  passed to them. 
  135.  
  136.  at_ptr is a pointer to the action table which must be executed (evaluated)
  137.  
  138.  so the iterated line exectues the function indexed by the at_ptr and 
  139.  passes the address of the argument which is pointed to by the arg_ptr 
  140.  
  141. */
  142.