1 /* -*- Mode: C; indent-tabs-mode: ni; c-basic-offset: 8 -*- */
4 * This file is part of The Croco Library
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.
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.
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
20 * Author: Dodji Seketeli.
21 * See the COPYRIGHTS file for copyright information.
26 #include "cr-parsing-location.h"
31 *Definition of the #CRparsingLocation class.
36 * cr_parsing_location_new:
37 *Instanciates a new parsing location.
39 *Returns the newly instanciated #CRParsingLocation.
40 *Must be freed by cr_parsing_location_destroy()
43 cr_parsing_location_new (void)
45 CRParsingLocation * result = NULL ;
47 result = g_try_malloc (sizeof (CRParsingLocation)) ;
49 cr_utils_trace_info ("Out of memory error") ;
52 cr_parsing_location_init (result) ;
57 * cr_parsing_location_init:
58 *@a_this: the current instance of #CRParsingLocation.
60 *Initializes the an instance of #CRparsingLocation.
62 *Returns CR_OK upon succesful completion, an error code otherwise.
65 cr_parsing_location_init (CRParsingLocation *a_this)
67 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
69 memset (a_this, 0, sizeof (CRParsingLocation)) ;
74 * cr_parsing_location_copy:
75 *@a_to: the destination of the copy.
76 *Must be allocated by the caller.
77 *@a_from: the source of the copy.
79 *Copies an instance of CRParsingLocation into another one.
81 *Returns CR_OK upon succesful completion, an error code
85 cr_parsing_location_copy (CRParsingLocation *a_to,
86 CRParsingLocation *a_from)
88 g_return_val_if_fail (a_to && a_from, CR_BAD_PARAM_ERROR) ;
90 memcpy (a_to, a_from, sizeof (CRParsingLocation)) ;
95 * cr_parsing_location_to_string:
96 *@a_this: the current instance of #CRParsingLocation.
97 *@a_mask: a bitmap that defines which parts of the
98 *parsing location are to be serialized (line, column or byte offset)
100 *Returns the serialized string or NULL in case of an error.
103 cr_parsing_location_to_string (CRParsingLocation *a_this,
104 enum CRParsingLocationSerialisationMask a_mask)
106 GString *result = NULL ;
109 g_return_val_if_fail (a_this, NULL) ;
112 a_mask = DUMP_LINE | DUMP_COLUMN | DUMP_BYTE_OFFSET ;
114 result =g_string_new (NULL) ;
117 if (a_mask & DUMP_LINE) {
118 g_string_append_printf (result, "line:%d ",
121 if (a_mask & DUMP_COLUMN) {
122 g_string_append_printf (result, "column:%d ",
125 if (a_mask & DUMP_BYTE_OFFSET) {
126 g_string_append_printf (result, "byte offset:%d ",
127 a_this->byte_offset) ;
131 g_string_free (result, FALSE) ;
133 g_string_free (result, TRUE) ;
139 * cr_parsing_location_dump:
140 * @a_this: current instance of #CRParsingLocation
141 * @a_mask: the serialization mask.
142 * @a_fp: the file pointer to dump the parsing location to.
145 cr_parsing_location_dump (CRParsingLocation *a_this,
146 enum CRParsingLocationSerialisationMask a_mask,
151 g_return_if_fail (a_this && a_fp) ;
152 str = cr_parsing_location_to_string (a_this, a_mask) ;
154 fprintf (a_fp, "%s", str) ;
161 * cr_parsing_location_destroy:
162 *@a_this: the current instance of #CRParsingLocation. Must
163 *have been allocated with cr_parsing_location_new().
165 *Destroys the current instance of #CRParsingLocation
168 cr_parsing_location_destroy (CRParsingLocation *a_this)
170 g_return_if_fail (a_this) ;