00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <string.h>
00025 #include "cr-parsing-location.h"
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 CRParsingLocation *
00042 cr_parsing_location_new (void)
00043 {
00044 CRParsingLocation * result = NULL ;
00045
00046 result = g_try_malloc (sizeof (CRParsingLocation)) ;
00047 if (!result) {
00048 cr_utils_trace_info ("Out of memory error") ;
00049 return NULL ;
00050 }
00051 cr_parsing_location_init (result) ;
00052 return result ;
00053 }
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 enum CRStatus
00064 cr_parsing_location_init (CRParsingLocation *a_this)
00065 {
00066 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00067
00068 memset (a_this, 0, sizeof (CRParsingLocation)) ;
00069 return CR_OK ;
00070 }
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 enum CRStatus
00084 cr_parsing_location_copy (CRParsingLocation *a_to,
00085 CRParsingLocation *a_from)
00086 {
00087 g_return_val_if_fail (a_to && a_from, CR_BAD_PARAM_ERROR) ;
00088
00089 memcpy (a_to, a_from, sizeof (CRParsingLocation)) ;
00090 return CR_OK ;
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 gchar *
00102 cr_parsing_location_to_string (CRParsingLocation *a_this,
00103 enum CRParsingLocationSerialisationMask a_mask)
00104 {
00105 GString *result = NULL ;
00106 gchar *str = NULL ;
00107
00108 g_return_val_if_fail (a_this, NULL) ;
00109
00110 if (!a_mask) {
00111 a_mask = DUMP_LINE | DUMP_COLUMN | DUMP_BYTE_OFFSET ;
00112 }
00113 result =g_string_new (NULL) ;
00114 if (!result)
00115 return NULL ;
00116 if (a_mask & DUMP_LINE) {
00117 g_string_append_printf (result, "line:%d ",
00118 a_this->line) ;
00119 }
00120 if (a_mask & DUMP_COLUMN) {
00121 g_string_append_printf (result, "column:%d ",
00122 a_this->column) ;
00123 }
00124 if (a_mask & DUMP_BYTE_OFFSET) {
00125 g_string_append_printf (result, "byte offset:%d ",
00126 a_this->byte_offset) ;
00127 }
00128 if (result->len) {
00129 str = result->str ;
00130 g_string_free (result, FALSE) ;
00131 } else {
00132 g_string_free (result, TRUE) ;
00133 }
00134 return str ;
00135 }
00136
00137
00138
00139
00140
00141
00142
00143 void
00144 cr_parsing_location_dump (CRParsingLocation *a_this,
00145 enum CRParsingLocationSerialisationMask a_mask,
00146 FILE *a_fp)
00147 {
00148 gchar *str = NULL ;
00149
00150 g_return_if_fail (a_this && a_fp) ;
00151 str = cr_parsing_location_to_string (a_this, a_mask) ;
00152 if (str) {
00153 fprintf (a_fp, "%s", str) ;
00154 g_free (str) ;
00155 str = NULL ;
00156 }
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166 void
00167 cr_parsing_location_destroy (CRParsingLocation *a_this)
00168 {
00169 g_return_if_fail (a_this) ;
00170 g_free (a_this) ;
00171 }
00172