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 CRParsingLocation *
00039 cr_parsing_location_new (void)
00040 {
00041 CRParsingLocation * result = NULL ;
00042
00043 result = g_try_malloc (sizeof (CRParsingLocation)) ;
00044 if (!result) {
00045 cr_utils_trace_info ("Out of memory error") ;
00046 return NULL ;
00047 }
00048 cr_parsing_location_init (result) ;
00049 return result ;
00050 }
00051
00052
00053
00054
00055
00056
00057 enum CRStatus
00058 cr_parsing_location_init (CRParsingLocation *a_this)
00059 {
00060 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00061
00062 memset (a_this, 0, sizeof (CRParsingLocation)) ;
00063 return CR_OK ;
00064 }
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 enum CRStatus
00075 cr_parsing_location_copy (CRParsingLocation *a_to,
00076 CRParsingLocation *a_from)
00077 {
00078 g_return_val_if_fail (a_to && a_from, CR_BAD_PARAM_ERROR) ;
00079
00080 memcpy (a_to, a_from, sizeof (CRParsingLocation)) ;
00081 return CR_OK ;
00082 }
00083
00084
00085
00086
00087
00088
00089
00090 gchar *
00091 cr_parsing_location_to_string (CRParsingLocation *a_this,
00092 enum CRParsingLocationSerialisationMask a_mask)
00093 {
00094 GString *result = NULL ;
00095 gchar *str = NULL ;
00096
00097 g_return_val_if_fail (a_this, NULL) ;
00098
00099 if (!a_mask) {
00100 a_mask = DUMP_LINE | DUMP_COLUMN | DUMP_BYTE_OFFSET ;
00101 }
00102 result =g_string_new (NULL) ;
00103 if (!result)
00104 return NULL ;
00105 if (a_mask & DUMP_LINE) {
00106 g_string_append_printf (result, "line:%d ",
00107 a_this->line) ;
00108 }
00109 if (a_mask & DUMP_COLUMN) {
00110 g_string_append_printf (result, "column:%d ",
00111 a_this->column) ;
00112 }
00113 if (a_mask & DUMP_BYTE_OFFSET) {
00114 g_string_append_printf (result, "byte offset:%d ",
00115 a_this->byte_offset) ;
00116 }
00117 if (result->len) {
00118 str = result->str ;
00119 g_string_free (result, FALSE) ;
00120 } else {
00121 g_string_free (result, TRUE) ;
00122 }
00123 return str ;
00124 }
00125
00126 void
00127 cr_parsing_location_dump (CRParsingLocation *a_this,
00128 enum CRParsingLocationSerialisationMask a_mask,
00129 FILE *a_fp)
00130 {
00131 gchar *str = NULL ;
00132
00133 g_return_if_fail (a_this && a_fp) ;
00134 str = cr_parsing_location_to_string (a_this, a_mask) ;
00135 if (str) {
00136 fprintf (a_fp, "%s", str) ;
00137 g_free (str) ;
00138 str = NULL ;
00139 }
00140 }
00141
00142
00143
00144
00145
00146
00147 void
00148 cr_parsing_location_destroy (CRParsingLocation *a_this)
00149 {
00150 g_return_if_fail (a_this) ;
00151 g_free (a_this) ;
00152 }
00153