home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / unofficial-plug-ins / mathmap / vars.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-21  |  2.0 KB  |  96 lines

  1. /*
  2.  * vars.c
  3.  *
  4.  * MathMap
  5.  *
  6.  * Copyright (C) 1997-2000 Mark Probst
  7.  *
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License
  10.  * as published by the Free Software Foundation; either version 2
  11.  * of the License, or (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23. #include <assert.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <stdio.h>
  27.  
  28. #include "vars.h"
  29.  
  30. variable_t *firstVariable = 0;
  31.  
  32. variable_t*
  33. register_variable (const char *name, tuple_info_t type)
  34. {
  35.     variable_t *var;
  36.  
  37.     var = (variable_t*)malloc(sizeof(variable_t));
  38.     assert(strlen(name) < VAR_MAX_LENGTH);
  39.     strcpy(var->name, name);
  40.     var->type = type;
  41.     var->value.number = type.number;
  42.     var->value.length = type.length;
  43.     var->next = firstVariable;
  44.     firstVariable = var;
  45.  
  46.     return var;
  47. }
  48.  
  49. variable_t*
  50. lookup_variable (const char *name, tuple_info_t *type)
  51. {
  52.     variable_t *var;
  53.  
  54.     for (var = firstVariable; var != 0; var = var->next)
  55.     if (strcmp(name, var->name) == 0)
  56.     {
  57.         *type = var->type;
  58.         return var;
  59.     }
  60.  
  61.     return 0;
  62. }
  63.  
  64. variable_t*
  65. new_temporary_variable (tuple_info_t type)
  66. {
  67.     static int num = 0;
  68.  
  69.     variable_t *var = (variable_t*)malloc(sizeof(variable_t));
  70.  
  71.     sprintf(var->name, "tmp____%d", ++num);
  72.     var->type = type;
  73.     var->value.number = type.number;
  74.     var->value.length = type.length;
  75.     var->next = firstVariable;
  76.     firstVariable = var;
  77.  
  78.     return var;
  79. }
  80.  
  81. void
  82. clear_all_variables (void)
  83. {
  84.     variable_t *var = firstVariable;
  85.  
  86.     while (var != 0)
  87.     {
  88.     variable_t *next = var->next;
  89.  
  90.     free(var);
  91.     var = next;
  92.     }
  93.  
  94.     firstVariable = 0;
  95. }
  96.