• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/ap/gpl/timemachine/gettext-0.17/gnulib-local/lib/libcroco/
1/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
2
3/*
4 * This file is part of The Croco Library
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2.1 of the GNU Lesser General Public
8 * License as published by the Free Software Foundation.
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 Lesser General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 *
20 * Author: Dodji Seketeli
21 * See COPYRIGHTS file for copyright information.
22 */
23
24#include <config.h>
25#include "cr-pseudo.h"
26
27/**
28 *@CRPseudo:
29 *The definition of the #CRPseudo class.
30 */
31
32/**
33 * cr_pseudo_new:
34 *Constructor of the #CRPseudo class.
35 *
36 *Returns the newly build instance.
37 */
38CRPseudo *
39cr_pseudo_new (void)
40{
41        CRPseudo *result = NULL;
42
43        result = g_malloc0 (sizeof (CRPseudo));
44
45        return result;
46}
47
48/**
49 * cr_pseudo_to_string:
50 * @a_this: the current instance of #CRPseud.
51 * Returns the serialized pseudo. Caller must free the returned
52 * string using g_free().
53 */
54guchar *
55cr_pseudo_to_string (CRPseudo * a_this)
56{
57        guchar *result = NULL;
58        GString *str_buf = NULL;
59
60        g_return_val_if_fail (a_this, NULL);
61
62        str_buf = g_string_new (NULL);
63
64        if (a_this->type == IDENT_PSEUDO) {
65                guchar *name = NULL;
66
67                if (a_this->name == NULL) {
68                        goto error;
69                }
70
71                name = g_strndup (a_this->name->stryng->str,
72                                  a_this->name->stryng->len);
73
74                if (name) {
75                        g_string_append (str_buf, name);
76                        g_free (name);
77                        name = NULL;
78                }
79        } else if (a_this->type == FUNCTION_PSEUDO) {
80                guchar *name = NULL,
81                        *arg = NULL;
82
83                if (a_this->name == NULL)
84                        goto error;
85
86                name = g_strndup (a_this->name->stryng->str,
87                                  a_this->name->stryng->len);
88
89                if (a_this->extra) {
90                        arg = g_strndup (a_this->extra->stryng->str,
91                                         a_this->extra->stryng->len);
92                }
93
94                if (name) {
95                        g_string_append_printf (str_buf, "%s(", name);
96                        g_free (name);
97                        name = NULL;
98
99                        if (arg) {
100                                g_string_append (str_buf, arg);
101                                g_free (arg);
102                                arg = NULL;
103                        }
104
105                        g_string_append_c (str_buf, ')');
106                }
107        }
108
109        if (str_buf) {
110                result = str_buf->str;
111                g_string_free (str_buf, FALSE);
112                str_buf = NULL;
113        }
114
115        return result;
116
117      error:
118        g_string_free (str_buf, TRUE);
119        return NULL;
120}
121
122/**
123 * cr_pseudo_dump:
124 *@a_this: the current instance of pseudo
125 *@a_fp: the destination file pointer.
126 *
127 *Dumps the pseudo to a file.
128 *
129 */
130void
131cr_pseudo_dump (CRPseudo * a_this, FILE * a_fp)
132{
133        guchar *tmp_str = NULL;
134
135        if (a_this) {
136                tmp_str = cr_pseudo_to_string (a_this);
137                if (tmp_str) {
138                        fprintf (a_fp, "%s", tmp_str);
139                        g_free (tmp_str);
140                        tmp_str = NULL;
141                }
142        }
143}
144
145/**
146 * cr_pseudo_destroy:
147 *@a_this: the current instance to destroy.
148 *
149 *destructor of the #CRPseudo class.
150 */
151void
152cr_pseudo_destroy (CRPseudo * a_this)
153{
154        g_return_if_fail (a_this);
155
156        if (a_this->name) {
157                cr_string_destroy (a_this->name);
158                a_this->name = NULL;
159        }
160
161        if (a_this->extra) {
162                cr_string_destroy (a_this->extra);
163                a_this->extra = NULL;
164        }
165
166        g_free (a_this);
167}
168