Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals  

data.c

00001  /*
00002   * plint/data.c : shared plint data
00003   * 
00004   * Time-stamp: <2002-12-21 14:46:37 gseba>
00005   * 
00006   * Copyright (C) Sebastian Glita, email: gseba@users.sourceforge.net
00007   * 
00008   * This file is part of plint.
00009   * 
00010   * plint is free software; you can  redistribute it and/or modify it under the
00011   * terms of the  GNU General Public License as published  by the Free Software
00012   * Foundation; either version 2, or (at your option) any later version.
00013   *
00014   * plint  is distributed  in the  hope  that it  will be  useful, but  WITHOUT
00015   * ANY  WARRANTY; without  even  the implied  warranty  of MERCHANTABILITY  or
00016   * FITNESS FOR A  PARTICULAR PURPOSE.  See the GNU  General Public License for
00017   * more details.
00018   * 
00019   * You should  have received a  copy of the  GNU General Public  License along
00020   * with  plint; see  the file  COPYING.  If  not, write  to the  Free Software
00021   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA USA.
00022   *
00023   */
00024 
00025 #pragma GCC dependency "Makefile" maybe some command line defines have changed
00026 
00027 #include "plint.h"
00028 #include "data.h"
00029 #include "error.h"
00030 
00031 #include "parse/mygrm.h"
00032 #include "parse/stack.h"
00033 
00034 
00035 
00036 void plint_pst_idx()
00037 {
00038   int n;
00039 
00040   plint->idx.num.n += PLINT_idx_SIZE - plint->idx.num.n;
00041 
00042   if (plint->idx.num.n)
00043     plint->idx.num.a = realloc(plint->idx.num.a, plint->idx.num.n * sizeof(int));
00044   else if (plint->idx.num.a)
00045     {
00046       free(plint->idx.num.a);
00047       plint->idx.num.a = 0;
00048     }
00049 
00050   for (n=0; !PLINT_idx_EMPTY; ++n)
00051     {
00052       plint->idx.num.a[n] = PLINT_idx_TIP.val.num_int;
00053       PLINT_idx_REM;
00054     }
00055   PLINT_idx_POP;
00056 }
00057 
00058 
00059 int plint_tab_pst_idx(plint_tab_t tab)
00060 {
00061   int n;
00062   plint_var_t var;
00063   if (plint_tab_n(tab) == 0)
00064     PLINT_ERROR(PLINT_ERR_FIELD);
00065   for (n = 0; n < plint_tab_n(tab)-1; ++n)
00066     {
00067       var = n[plint_tab_a(tab)];
00068       if (plint_var_typ(var) != PLINT_num_int)
00069         PLINT_ERROR(PLINT_ERR_FIELD);
00070       PLINT_IDX_CHK(*plint_var_val(var));
00071       PLINT_idx_ADD({ type:PLINT_idx_int, typ:PLINT_num_int, val:(plint_val_t)plint_var_num_int(var) });
00072     }
00073   var = n[plint_tab_a(tab)];
00074 
00075   if (plint_var_typ(var) != PLINT_num_int)
00076     PLINT_ERROR(PLINT_ERR_FIELD);
00077 
00078   PLINT_IDX_CHK(*plint_var_val(var));
00079   return plint_var_num_int(var);
00080 }
00081 
00082 int plint_var_pst_idx(plint_var_t var)
00083 {
00084   if (plint_var_typ(var) == PLINT_tab)
00085     return plint_tab_pst_idx(plint_var_tab(var));
00086   else if (plint_var_typ(var) != PLINT_num_int)
00087     PLINT_ERROR(PLINT_ERR_FIELD);
00088 
00089   PLINT_IDX_CHK(*plint_var_val(var));
00090   return plint_var_num_int(var);
00091 }
00092 
00093 
00094 
00095 plint_str_t plint_str_ret(int b)
00096 {
00097   plint_str_t s = plint_str_new("0_", 2);
00098   0[plint_str_s(s)] += b;
00099   return s;
00100 }
00101 
00102 
00103 
00104 int (* plint_prim_tab(int * pn))[2]
00105 {
00106   int i, (* p)[2];
00107 
00108   if (plint_tab_n(plint->reg.tab) == 0)
00109     PLINT_ERROR(PLINT_ERR_PRIM);
00110 
00111   p = malloc(plint_tab_n(plint->reg.tab) * sizeof(int[2]));
00112   for (i = 0; i < plint_tab_n(plint->reg.tab); ++i)
00113     if (plint_var_typ(i[plint_tab_a(plint->reg.tab)]) == PLINT_pnt)
00114       {
00115         p[i][0] = plint_pnt_x(plint_var_pnt(i[plint_tab_a(plint->reg.tab)]));
00116         p[i][1] = plint_pnt_y(plint_var_pnt(i[plint_tab_a(plint->reg.tab)]));
00117       }
00118     else
00119       {
00120         free(p);
00121         PLINT_ERROR(PLINT_ERR_PRIM);
00122       }
00123 
00124   *pn = i;
00125   plint_free_tab();
00126 
00127   return p;
00128 }
00129 
00130 
00131 
00132 void plint_clean_str()
00133 {
00134   plint_str_n(plint->reg.str) = 0;
00135   plint_str_s(plint->reg.str) = 0;
00136 }
00137 
00138 void plint_clean_tab()
00139 {
00140   plint_tab_n(plint->reg.tab) = 0;
00141   plint_tab_a(plint->reg.tab) = 0;
00142 }
00143 
00144 void plint_clean_hsh()
00145 {
00146   plint->reg.hsh = 0;
00147 }
00148 
00149 void plint_clean_ref()
00150 {
00151 }
00152 
00153 void plint_clean_var()
00154 {
00155   plint->reg.var = 0;
00156 }
00157 
00158 #define PLINT_FREE(__typ__, __cond__)           \
00159 void plint_free_##__typ__()                     \
00160 {                                               \
00161   if (plint->reg.__typ__ __cond__)              \
00162   {                                             \
00163     plint_##__typ__##_fre(plint->reg.__typ__);  \
00164     plint_clean_##__typ__();                    \
00165   }                                             \
00166 }
00167 
00168 PLINT_FREE(str,.s)
00169 PLINT_FREE(tab,.n)
00170 PLINT_FREE(hsh,)
00171 PLINT_FREE(var,)
00172 
00173 
00174 #undef PLINT_FREE

Generated on Thu Jan 9 19:02:37 2003 for plint by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002