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

Generated on Wed Oct 1 01:36:47 2003 for Libcroco by doxygen 1.3.3