"Fossies" - the Fresh Open Source Software Archive

Member "cook-2.34/cook/stmt/list.c" (25 Sep 2010, 2896 Bytes) of package /linux/misc/old/cook-2.34.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "list.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  *      cook - file construction tool
    3  *      Copyright (C) 1997, 1999, 2001, 2006-2009 Peter Miller
    4  *
    5  *      This program is free software; you can redistribute it and/or modify
    6  *      it under the terms of the GNU General Public License as published by
    7  *      the Free Software Foundation; either version 3 of the License, or
    8  *      (at your option) any later version.
    9  *
   10  *      This program is distributed in the hope that it will be useful,
   11  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  *      GNU General Public License for more details.
   14  *
   15  *      You should have received a copy of the GNU General Public License
   16  *      along with this program. If not, see
   17  *      <http://www.gnu.org/licenses/>.
   18  */
   19 
   20 #include <common/mem.h>
   21 #include <cook/stmt.h>
   22 #include <cook/stmt/list.h>
   23 #include <common/trace.h>
   24 
   25 
   26 /*
   27  *  NAME
   28  *      stmt_list_append - append to a statement list
   29  *
   30  *  SYNOPSIS
   31  *      void stmt_list_append(stmt_list_ty *slp, stmt *sp);
   32  *
   33  *  DESCRIPTION
   34  *      stmt_list_append is used to append a statement to a statement list.
   35  */
   36 
   37 void
   38 stmt_list_append(stmt_list_ty *sl, stmt_ty *s)
   39 {
   40     trace(("stmt_list_append(sl = %p, s = %p)\n{\n", sl, s));
   41     if (sl->sl_nstmts >= sl->sl_nstmts_max)
   42     {
   43         size_t          nbytes;
   44 
   45         sl->sl_nstmts_max = sl->sl_nstmts_max * 2 + 4;
   46         nbytes = sl->sl_nstmts_max * sizeof(sl->sl_stmt[0]);
   47         sl->sl_stmt = mem_change_size(sl->sl_stmt, nbytes);
   48     }
   49     sl->sl_stmt[sl->sl_nstmts++] = stmt_copy(s);
   50     trace(("}\n"));
   51 }
   52 
   53 
   54 /*
   55  *  NAME
   56  *      stmt_list_destructor - free statement list
   57  *
   58  *  SYNOPSIS
   59  *      void stmt_list_destructor(stmt_list_ty *);
   60  *
   61  *  DESCRIPTION
   62  *      The stmt_list_destructor function is used to free the list of
   63  *      statement trees.
   64  *
   65  *  RETURNS
   66  *      void
   67  */
   68 
   69 void
   70 stmt_list_destructor(stmt_list_ty *sl)
   71 {
   72     size_t          j;
   73 
   74     trace(("stmt_list_destructor(sl = %p)\n{\n", sl));
   75     for (j = 0; j < sl->sl_nstmts; ++j)
   76         stmt_delete(sl->sl_stmt[j]);
   77     if (sl->sl_stmt)
   78         mem_free(sl->sl_stmt);
   79     sl->sl_nstmts = 0;
   80     sl->sl_nstmts_max = 0;
   81     sl->sl_stmt = 0;
   82     trace(("}\n"));
   83 }
   84 
   85 
   86 void
   87 stmt_list_constructor(stmt_list_ty *slp)
   88 {
   89     slp->sl_nstmts = 0;
   90     slp->sl_nstmts_max = 0;
   91     slp->sl_stmt = 0;
   92 }
   93 
   94 
   95 void
   96 stmt_list_copy_constructor(stmt_list_ty *slp, const stmt_list_ty *other)
   97 {
   98     size_t          j;
   99 
  100     slp->sl_nstmts = 0;
  101     slp->sl_nstmts_max = 0;
  102     slp->sl_stmt = 0;
  103 
  104     for (j = 0; j < other->sl_nstmts; ++j)
  105         stmt_list_append(slp, other->sl_stmt[j]);
  106 }
  107 
  108 
  109 stmt_list_ty *
  110 stmt_list_new(void)
  111 {
  112     stmt_list_ty    *slp;
  113 
  114     slp = mem_alloc(sizeof(stmt_list_ty));
  115     stmt_list_constructor(slp);
  116     return slp;
  117 }
  118 
  119 
  120 void
  121 stmt_list_delete(stmt_list_ty *slp)
  122 {
  123     stmt_list_destructor(slp);
  124     mem_free(slp);
  125 }