Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

cr-pseudo.c

Go to the documentation of this file.
00001 /* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
00002 
00003 /*
00004  * This file is part of The Croco Library
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of version 2.1 of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00018  * USA
00019  *
00020  * Author: Dodji Seketeli
00021  * See COPYRIGHTS file for copyright information.
00022  */
00023 
00024 #include "cr-pseudo.h"
00025 
00026 /**
00027  *@file
00028  *The definition of the #CRPseudo class.
00029  */
00030 
00031 /**
00032  *Constructor of the #CRPseudo class.
00033  *@return the newly build instance.
00034  */
00035 CRPseudo *
00036 cr_pseudo_new (void)
00037 {
00038         CRPseudo *result = NULL;
00039 
00040         result = g_malloc0 (sizeof (CRPseudo));
00041 
00042         return result;
00043 }
00044 
00045 guchar *
00046 cr_pseudo_to_string (CRPseudo * a_this)
00047 {
00048         guchar *result = NULL;
00049         GString *str_buf = NULL;
00050 
00051         g_return_val_if_fail (a_this, NULL);
00052 
00053         str_buf = g_string_new (NULL);
00054 
00055         if (a_this->type == IDENT_PSEUDO) {
00056                 guchar *name = NULL;
00057 
00058                 if (a_this->name == NULL) {
00059                         goto error;
00060                 }
00061 
00062                 name = g_strndup (a_this->name->stryng->str, 
00063                                   a_this->name->stryng->len);
00064 
00065                 if (name) {
00066                         g_string_append (str_buf, name);
00067                         g_free (name);
00068                         name = NULL;
00069                 }
00070         } else if (a_this->type == FUNCTION_PSEUDO) {
00071                 guchar *name = NULL,
00072                         *arg = NULL;
00073 
00074                 if (a_this->name == NULL)
00075                         goto error;
00076 
00077                 name = g_strndup (a_this->name->stryng->str, 
00078                                   a_this->name->stryng->len);
00079 
00080                 if (a_this->extra) {
00081                         arg = g_strndup (a_this->extra->stryng->str,
00082                                          a_this->extra->stryng->len);
00083                 }
00084 
00085                 if (name) {
00086                         g_string_append_printf (str_buf, "%s(", name);
00087                         g_free (name);
00088                         name = NULL;
00089 
00090                         if (arg) {
00091                                 g_string_append (str_buf, arg);
00092                                 g_free (arg);
00093                                 arg = NULL;
00094                         }
00095 
00096                         g_string_append_c (str_buf, ')');
00097                 }
00098         }
00099 
00100         if (str_buf) {
00101                 result = str_buf->str;
00102                 g_string_free (str_buf, FALSE);
00103                 str_buf = NULL;
00104         }
00105 
00106         return result;
00107 
00108       error:
00109         g_string_free (str_buf, TRUE);
00110         return NULL;
00111 }
00112 
00113 /**
00114  *Dumps the pseudo to a file.
00115  *@param a_this the current instance of pseudo
00116  *@param a_fp the destination file pointer.
00117  */
00118 void
00119 cr_pseudo_dump (CRPseudo * a_this, FILE * a_fp)
00120 {
00121         guchar *tmp_str = NULL;
00122 
00123         if (a_this) {
00124                 tmp_str = cr_pseudo_to_string (a_this);
00125                 if (tmp_str) {
00126                         fprintf (a_fp, "%s", tmp_str);
00127                         g_free (tmp_str);
00128                         tmp_str = NULL;
00129                 }
00130         }
00131 }
00132 
00133 /**
00134  *destructor of the #CRPseudo class.
00135  *@param a_this the current instance to destroy.
00136  */
00137 void
00138 cr_pseudo_destroy (CRPseudo * a_this)
00139 {
00140         g_return_if_fail (a_this);
00141 
00142         if (a_this->name) {
00143                 cr_string_destroy (a_this->name);
00144                 a_this->name = NULL;
00145         }
00146 
00147         if (a_this->extra) {
00148                 cr_string_destroy (a_this->extra);
00149                 a_this->extra = NULL;
00150         }
00151 
00152         g_free (a_this);
00153 }

Generated on Fri Oct 29 08:29:12 2004 for Libcroco by  doxygen 1.3.9.1