From 31fb8432ef01f9d5a08cc801a785a07b4e9d12bd Mon Sep 17 00:00:00 2001 From: Peter Verthez Date: Sun, 26 Jan 2003 09:18:35 +0000 Subject: [PATCH] Some const correctness fixes. --- gedcom/age.c | 4 ++-- gedcom/date.c | 6 +++--- gedcom/interface.c | 3 ++- gedcom/write.c | 24 +++++++++++++----------- include/gedcom.h.in | 27 ++++++++++++++------------- 5 files changed, 34 insertions(+), 30 deletions(-) diff --git a/gedcom/age.c b/gedcom/age.c index 37a49fe..9429ff8 100644 --- a/gedcom/age.c +++ b/gedcom/age.c @@ -103,7 +103,7 @@ int parse_numeric_age(struct age_value *age, const char *ptr) return 0; } -struct age_value* gedcom_new_age_value(struct age_value* copy_from) +struct age_value* gedcom_new_age_value(const struct age_value* copy_from) { struct age_value* age_ptr; age_ptr = (struct age_value*) malloc(sizeof(struct age_value)); @@ -154,7 +154,7 @@ struct age_value gedcom_parse_age(const char* line_value) return age_s; } -char* gedcom_age_to_string(struct age_value* val) +char* gedcom_age_to_string(const struct age_value* val) { int num = 0; reset_buffer(&age_buffer); diff --git a/gedcom/date.c b/gedcom/date.c index 4f61cca..40cb18a 100644 --- a/gedcom/date.c +++ b/gedcom/date.c @@ -383,7 +383,7 @@ int gedcom_normalize_date(Date_input input, struct date_value *val) return result; } -struct date_value* gedcom_new_date_value(struct date_value* copy_from) +struct date_value* gedcom_new_date_value(const struct date_value* copy_from) { struct date_value* dv_ptr; dv_ptr = (struct date_value*) malloc(sizeof(struct date_value)); @@ -429,7 +429,7 @@ struct date_value gedcom_parse_date(const char* line_value) return dv_s; } -void write_date(struct date* d) +void write_date(const struct date* d) { if (! d->year_str[0] || d->year <= 0 || d->sdn1 <= 0) gedcom_error(_("Date is not normalized: some fields are invalid")); @@ -455,7 +455,7 @@ void write_date(struct date* d) } } -char* gedcom_date_to_string(struct date_value* val) +char* gedcom_date_to_string(const struct date_value* val) { init_buffer(&date_buffer); reset_buffer(&date_buffer); diff --git a/gedcom/interface.c b/gedcom/interface.c index 24cf4e6..8b42b21 100644 --- a/gedcom/interface.c +++ b/gedcom/interface.c @@ -32,8 +32,9 @@ static Gedcom_def_cb default_cb = NULL; void gedcom_set_default_callback(Gedcom_def_cb func) { - if (default_cb) + if (default_cb) { gedcom_error(_("Internal error: Duplicate registration for default callback")); + } default_cb = func; } diff --git a/gedcom/write.c b/gedcom/write.c index f880bbb..eb7f5d6 100644 --- a/gedcom/write.c +++ b/gedcom/write.c @@ -104,7 +104,8 @@ int write_simple(Gedcom_write_hndl hndl, } int write_encoding_value(Gedcom_write_hndl hndl, - int level, char* xref, char* tag, char* value) + int level, const char* xref, const char* tag, + const char* value) { if (strcmp(value, write_encoding.charset)) gedcom_warning(_("Forcing HEAD.CHAR value to '%s'"), @@ -321,7 +322,7 @@ char* convert_at(const char* input) int _gedcom_write_val(Gedcom_write_hndl hndl, int rec_or_elt, int tag, int parent_rec_or_elt, - char* xrefstr, char* val) + const char* xrefstr, const char* val) { int result = 1; int level = 0; @@ -342,7 +343,8 @@ int _gedcom_write_val(Gedcom_write_hndl hndl, } int gedcom_write_record_str(Gedcom_write_hndl hndl, - Gedcom_rec rec, char* xrefstr, char* val) + Gedcom_rec rec, const char* xrefstr, + const char* val) { int result = 1; if (check_type(rec, (val ? GV_CHAR_PTR : GV_NULL))) @@ -352,7 +354,7 @@ int gedcom_write_record_str(Gedcom_write_hndl hndl, int gedcom_write_element_str(Gedcom_write_hndl hndl, Gedcom_elt elt, int tag, int parent_rec_or_elt, - char* val) + const char* val) { int result = 1; if (check_type(elt, (val ? GV_CHAR_PTR : GV_NULL))) @@ -363,7 +365,7 @@ int gedcom_write_element_str(Gedcom_write_hndl hndl, int gedcom_write_element_xref(Gedcom_write_hndl hndl, Gedcom_elt elt, int tag, int parent_rec_or_elt, - struct xref_value* val) + const struct xref_value* val) { int result = 1; if (check_type(elt, (val ? GV_XREF_PTR : GV_NULL))) @@ -374,7 +376,7 @@ int gedcom_write_element_xref(Gedcom_write_hndl hndl, int gedcom_write_element_date(Gedcom_write_hndl hndl, Gedcom_elt elt, int tag, int parent_rec_or_elt, - struct date_value* val) + const struct date_value* val) { int result = 1; if (check_type(elt, (val ? GV_DATE_VALUE : GV_NULL))) @@ -385,7 +387,7 @@ int gedcom_write_element_date(Gedcom_write_hndl hndl, int gedcom_write_element_age(Gedcom_write_hndl hndl, Gedcom_elt elt, int tag, int parent_rec_or_elt, - struct age_value* val) + const struct age_value* val) { int result = 1; if (check_type(elt, (val ? GV_AGE_VALUE : GV_NULL))) @@ -394,8 +396,8 @@ int gedcom_write_element_age(Gedcom_write_hndl hndl, return result; } -int gedcom_write_user_str(Gedcom_write_hndl hndl, int level, char* tag, - char* xrefstr, char* value) +int gedcom_write_user_str(Gedcom_write_hndl hndl, int level, const char* tag, + const char* xrefstr, const char* value) { int result = 1; if (tag && tag[0] == '_') @@ -403,8 +405,8 @@ int gedcom_write_user_str(Gedcom_write_hndl hndl, int level, char* tag, return result; } -int gedcom_write_user_xref(Gedcom_write_hndl hndl, int level, char* tag, - char* xrefstr, struct xref_value* val) +int gedcom_write_user_xref(Gedcom_write_hndl hndl, int level, const char* tag, + const char* xrefstr, const struct xref_value* val) { int result = 1; if (tag && tag[0] == '_') diff --git a/include/gedcom.h.in b/include/gedcom.h.in index 0a3d68f..8129975 100644 --- a/include/gedcom.h.in +++ b/include/gedcom.h.in @@ -530,13 +530,13 @@ void gedcom_subscribe_to_element(Gedcom_elt elt, /* Separate value parsing functions */ struct date_value gedcom_parse_date(const char* line_value); -char* gedcom_date_to_string(struct date_value* val); -struct date_value* gedcom_new_date_value(struct date_value* copy_from); +char* gedcom_date_to_string(const struct date_value* val); +struct date_value* gedcom_new_date_value(const struct date_value* copy_from); int gedcom_normalize_date(Date_input compute_from, struct date_value *val); struct age_value gedcom_parse_age(const char* line_value); -struct age_value* gedcom_new_age_value(struct age_value* copy_from); -char* gedcom_age_to_string(struct age_value* val); +struct age_value* gedcom_new_age_value(const struct age_value* copy_from); +char* gedcom_age_to_string(const struct age_value* val); /* Handling cross-references */ struct xref_value *gedcom_get_by_xref(const char *key); @@ -555,26 +555,27 @@ int gedcom_write_set_encoding(Enc_from from, int gedcom_write_set_line_terminator(Enc_from from, Enc_line_end end); int gedcom_write_record_str(Gedcom_write_hndl hndl, - Gedcom_rec rec, char* xrefstr, char* val); + Gedcom_rec rec, const char* xrefstr, + const char* val); int gedcom_write_element_str(Gedcom_write_hndl hndl, Gedcom_elt elt, int parsed_tag, int parent_rec_or_elt, - char* val); + const char* val); int gedcom_write_element_xref(Gedcom_write_hndl hndl, Gedcom_elt elt, int parsed_tag, int parent_rec_or_elt, - struct xref_value* val); + const struct xref_value* val); int gedcom_write_element_date(Gedcom_write_hndl hndl, Gedcom_elt elt, int tag, int parent_rec_or_elt, - struct date_value* val); + const struct date_value* val); int gedcom_write_element_age(Gedcom_write_hndl hndl, Gedcom_elt elt, int tag, int parent_rec_or_elt, - struct age_value* val); + const struct age_value* val); -int gedcom_write_user_str(Gedcom_write_hndl hndl, int level, char* tag, - char* xrefstr, char* value); -int gedcom_write_user_xref(Gedcom_write_hndl hndl, int level, char* tag, - char* xrefstr, struct xref_value* val); +int gedcom_write_user_str(Gedcom_write_hndl hndl, int level, const char* tag, + const char* xrefstr, const char* value); +int gedcom_write_user_xref(Gedcom_write_hndl hndl, int level, const char* tag, + const char* xrefstr, const struct xref_value* val); /* For use in gom */ int gedcom_error(const char* s, ...); -- 2.30.2