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.6 2004/03/07 13:22:47 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 guchar *
00049 cr_pseudo_to_string (CRPseudo * a_this)
00050 {
00051         guchar *result = NULL;
00052         GString *str_buf = NULL;
00053 
00054         g_return_val_if_fail (a_this, NULL);
00055 
00056         str_buf = g_string_new (NULL);
00057 
00058         if (a_this->type == IDENT_PSEUDO) {
00059                 guchar *name = NULL;
00060 
00061                 if (a_this->name == NULL) {
00062                         goto error;
00063                 }
00064 
00065                 name = g_strndup (a_this->name->str, a_this->name->len);
00066 
00067                 if (name) {
00068                         g_string_append_printf (str_buf, "%s", name);
00069                         g_free (name);
00070                         name = NULL;
00071                 }
00072         } else if (a_this->type == FUNCTION_PSEUDO) {
00073                 guchar *name = NULL,
00074                         *arg = NULL;
00075 
00076                 if (a_this->name == NULL)
00077                         goto error;
00078 
00079                 name = g_strndup (a_this->name->str, a_this->name->len);
00080 
00081                 if (a_this->extra) {
00082                         arg = g_strndup (a_this->extra->str,
00083                                          a_this->extra->len);
00084                 }
00085 
00086                 if (name) {
00087                         g_string_append_printf (str_buf, "%s(", name);
00088                         g_free (name);
00089                         name = NULL;
00090 
00091                         if (arg) {
00092                                 g_string_append_printf (str_buf, "%s", arg);
00093                                 g_free (arg);
00094                                 arg = NULL;
00095                         }
00096 
00097                         g_string_append_printf (str_buf, ")");
00098                 }
00099         }
00100 
00101         if (str_buf) {
00102                 result = str_buf->str;
00103                 g_string_free (str_buf, FALSE);
00104                 str_buf = NULL;
00105         }
00106 
00107         return result;
00108 
00109       error:
00110         g_string_free (str_buf, TRUE);
00111         return NULL;
00112 }
00113 
00114 /**
00115  *Dumps the pseudo to a file.
00116  *@param a_this the current instance of pseudo
00117  *@param a_fp the destination file pointer.
00118  */
00119 void
00120 cr_pseudo_dump (CRPseudo * a_this, FILE * a_fp)
00121 {
00122         guchar *tmp_str = NULL;
00123 
00124         if (a_this) {
00125                 tmp_str = cr_pseudo_to_string (a_this);
00126                 if (tmp_str) {
00127                         fprintf (a_fp, "%s", tmp_str);
00128                         g_free (tmp_str);
00129                         tmp_str = NULL;
00130                 }
00131         }
00132 }
00133 
00134 /**
00135  *destructor of the #CRPseudo class.
00136  *@param a_this the current instance to destroy.
00137  */
00138 void
00139 cr_pseudo_destroy (CRPseudo * a_this)
00140 {
00141         g_return_if_fail (a_this);
00142 
00143         if (a_this->name) {
00144                 g_string_free (a_this->name, TRUE);
00145                 a_this->name = NULL;
00146         }
00147 
00148         if (a_this->extra) {
00149                 g_string_free (a_this->extra, TRUE);
00150                 a_this->extra = NULL;
00151         }
00152 
00153         g_free (a_this);
00154 }

Generated on Sat Mar 20 02:38:43 2004 for Libcroco by doxygen 1.3.5