From fffe9618ff8a5cfcac207f231b531615dfb0e38f Mon Sep 17 00:00:00 2001 From: Peter Verthez Date: Sun, 15 Sep 2002 18:10:47 +0000 Subject: [PATCH] Take care of const correctness. --- gedcom/age.c | 6 +++--- gedcom/compat.c | 8 ++++---- gedcom/compat.h | 2 +- gedcom/date.c | 6 +++--- gedcom/date.h | 6 +++--- gedcom/encoding.c | 13 +++++++------ gedcom/encoding.h | 4 ++-- gedcom/gedcom.y | 2 +- gedcom/gedcom_date.lex | 2 +- gedcom/interface.c | 2 +- gedcom/message.c | 10 +++++----- gedcom/multilex.c | 2 +- gedcom/xref.c | 2 +- include/gedcom.h.in | 18 +++++++++--------- 14 files changed, 42 insertions(+), 41 deletions(-) diff --git a/gedcom/age.c b/gedcom/age.c index c597ef3..8518411 100644 --- a/gedcom/age.c +++ b/gedcom/age.c @@ -46,7 +46,7 @@ void init_age(struct age_value *age) age->days = -1; } -int parse_numeric_age(struct age_value *age, char *ptr) +int parse_numeric_age(struct age_value *age, const char *ptr) { char *endptr; while (ptr) { @@ -94,9 +94,9 @@ int parse_numeric_age(struct age_value *age, char *ptr) return 0; } -struct age_value gedcom_parse_age(char* line_value) +struct age_value gedcom_parse_age(const char* line_value) { - char *ptr = line_value; + const char *ptr = line_value; init_age(&age_s); init_age(&def_age_val); diff --git a/gedcom/compat.c b/gedcom/compat.c index d4fdb9f..c566d8e 100644 --- a/gedcom/compat.c +++ b/gedcom/compat.c @@ -31,7 +31,7 @@ int compat_enabled = 1; int compatibility = 0; int compat_at = 0; -char* default_charset = ""; +const char* default_charset = ""; #define SUBMITTER_LINK "@__COMPAT__SUBM__@" #define DEFAULT_SUBMITTER_NAME "Submitter" @@ -61,7 +61,7 @@ void gedcom_set_compat_handling(int enable_compat) compat_enabled = enable_compat; } -void set_compatibility(char* program) +void set_compatibility(const char* program) { /* Reinitialize compatibility */ compat_at = 0; @@ -172,8 +172,8 @@ int compat_generate_char(Gedcom_ctxt parent) /* first generate "1 CHAR " */ ts.string = "CHAR"; ts.value = TAG_CHAR; - self1 = start_element(ELT_HEAD_CHAR, parent, 1, ts, default_charset, - GEDCOM_MAKE_STRING(val1, default_charset)); + self1 = start_element(ELT_HEAD_CHAR, parent, 1, ts, (char*)default_charset, + GEDCOM_MAKE_STRING(val1, (char*)default_charset)); /* close "1 CHAR" */ end_element(ELT_HEAD_CHAR, parent, self1, NULL); diff --git a/gedcom/compat.h b/gedcom/compat.h index ff2423c..31e7576 100644 --- a/gedcom/compat.h +++ b/gedcom/compat.h @@ -33,7 +33,7 @@ enum _COMPAT { C_LIFELINES = 0x02 }; -void set_compatibility(char* program); +void set_compatibility(const char* program); int compat_mode(int flags); void compat_generate_submitter_link(Gedcom_ctxt parent); void compat_generate_submitter(); diff --git a/gedcom/date.c b/gedcom/date.c index 322127e..1a2232a 100644 --- a/gedcom/date.c +++ b/gedcom/date.c @@ -31,7 +31,7 @@ struct date date_s; struct date_value def_date_val; struct date def_date; -char* curr_line_value; +const char* curr_line_value; int max_month[] = { 12, /* CAL_GREGORIAN */ 12, /* CAL_JULIAN */ @@ -69,7 +69,7 @@ void init_date(struct date *d) } struct date_value make_date_value(Date_value_type t, struct date d1, - struct date d2, char* p) + struct date d2, const char* p) { dv_s.type = t; copy_date(&dv_s.date1, d1); @@ -115,7 +115,7 @@ void make_date_complete(struct date *d) } } -struct date_value gedcom_parse_date(char* line_value) +struct date_value gedcom_parse_date(const char* line_value) { init_date(&date_s); init_date(&def_date); diff --git a/gedcom/date.h b/gedcom/date.h index ad7a234..e7e82ca 100644 --- a/gedcom/date.h +++ b/gedcom/date.h @@ -34,17 +34,17 @@ extern struct date_value dv_s; extern struct date date_s; extern struct date def_date; -extern char* curr_line_value; +extern const char* curr_line_value; int gedcom_date_parse(); int gedcom_date_lex(); /* These are defined in gedcom_date.lex */ -void init_gedcom_date_lex(char* string); +void init_gedcom_date_lex(const char* string); void close_gedcom_date_lex(); struct date_value make_date_value(Date_value_type t, struct date d1, - struct date d2, char* p); + struct date d2, const char* p); void copy_date(struct date *to, struct date from); #define GEDCOM_MAKE_DATE(VAR, DATE) \ diff --git a/gedcom/encoding.c b/gedcom/encoding.c index b2c3c41..07a9589 100644 --- a/gedcom/encoding.c +++ b/gedcom/encoding.c @@ -39,7 +39,7 @@ static iconv_t cd_to_internal = (iconv_t) -1; static ENCODING the_enc = ONE_BYTE; static hash_t *encodings = NULL; -char* charwidth_string[] = { "1", "2_HILO", "2_LOHI" }; +const char* charwidth_string[] = { "1", "2_HILO", "2_LOHI" }; hnode_t *node_alloc(void *c __attribute__((unused))) { @@ -53,7 +53,8 @@ void node_free(hnode_t *n, void *c __attribute__((unused))) free(n); } -void add_encoding(char *gedcom_n, char* charwidth, char *iconv_n) +void add_encoding(const char *gedcom_n, const char* charwidth, + const char *iconv_n) { char *key, *val; @@ -79,7 +80,7 @@ void add_encoding(char *gedcom_n, char* charwidth, char *iconv_n) MEMORY_ERROR; } -char* get_encoding(char* gedcom_n, ENCODING enc) +char* get_encoding(const char* gedcom_n, ENCODING enc) { char *key; hnode_t *node; @@ -229,9 +230,9 @@ void set_encoding_width(ENCODING enc) static char conv_buf[MAXGEDCLINELEN * 2]; static size_t conv_buf_size; -int open_conv_to_internal(char* fromcode) +int open_conv_to_internal(const char* fromcode) { - char *encoding = get_encoding(fromcode, the_enc); + const char *encoding = get_encoding(fromcode, the_enc); if (cd_to_internal != (iconv_t) -1) iconv_close(cd_to_internal); if (encoding == NULL) { @@ -257,7 +258,7 @@ void close_conv_to_internal() cd_to_internal = (iconv_t) -1; } -char* to_internal(char* str, size_t len, +char* to_internal(const char* str, size_t len, char* output_buffer, size_t out_len) { size_t res; diff --git a/gedcom/encoding.h b/gedcom/encoding.h index 9eb40ba..d4bd632 100644 --- a/gedcom/encoding.h +++ b/gedcom/encoding.h @@ -31,9 +31,9 @@ typedef enum _ENC { TWO_BYTE_LOHI = 2 } ENCODING; -int open_conv_to_internal(char* fromcode); +int open_conv_to_internal(const char* fromcode); void close_conv_to_internal(); -char* to_internal(char* str, size_t len, +char* to_internal(const char* str, size_t len, char* output_buffer, size_t out_len); void init_encodings(); void set_encoding_width(ENCODING enc); diff --git a/gedcom/gedcom.y b/gedcom/gedcom.y index 3d5243a..b10e0c2 100644 --- a/gedcom/gedcom.y +++ b/gedcom/gedcom.y @@ -3884,7 +3884,7 @@ void gedcom_set_debug_level(int level, FILE* f) } } -int gedcom_debug_print(char* s, ...) +int gedcom_debug_print(const char* s, ...) { int res = 0; if (gedcom_high_level_debug) { diff --git a/gedcom/gedcom_date.lex b/gedcom/gedcom_date.lex index 8d6f887..50daf3f 100644 --- a/gedcom/gedcom_date.lex +++ b/gedcom/gedcom_date.lex @@ -140,7 +140,7 @@ int yywrap() static YY_BUFFER_STATE hndl; -void init_gedcom_date_lex(char* string) +void init_gedcom_date_lex(const char* string) { token_nr = 0; hndl = yy_scan_string(string); diff --git a/gedcom/interface.c b/gedcom/interface.c index 061ec4f..0522f05 100644 --- a/gedcom/interface.c +++ b/gedcom/interface.c @@ -107,7 +107,7 @@ char* val_type_str[] = { N_("null value"), N_("date"), N_("cross-reference") }; -void gedcom_cast_error(char* file, int line, +void gedcom_cast_error(const char* file, int line, Gedcom_val_type tried_type, Gedcom_val_type real_type) { diff --git a/gedcom/message.c b/gedcom/message.c index c3a5abf..62954b4 100644 --- a/gedcom/message.c +++ b/gedcom/message.c @@ -57,7 +57,7 @@ void init_mess_buffer() } } -int safe_buf_vappend(char *s, va_list ap) +int safe_buf_vappend(const char *s, va_list ap) { int res = 0; int len; @@ -82,7 +82,7 @@ int safe_buf_vappend(char *s, va_list ap) return res; } -int safe_buf_append(char *s, ...) +int safe_buf_append(const char *s, ...) { int res; va_list ap; @@ -94,7 +94,7 @@ int safe_buf_append(char *s, ...) return res; } -int gedcom_message(char* s, ...) +int gedcom_message(const char* s, ...) { int res; va_list ap; @@ -108,7 +108,7 @@ int gedcom_message(char* s, ...) return res; } -int gedcom_warning(char* s, ...) +int gedcom_warning(const char* s, ...) { int res; va_list ap; @@ -124,7 +124,7 @@ int gedcom_warning(char* s, ...) return res; } -int gedcom_error(char* s, ...) +int gedcom_error(const char* s, ...) { int res; va_list ap; diff --git a/gedcom/multilex.c b/gedcom/multilex.c index ada4ff0..437f0bd 100644 --- a/gedcom/multilex.c +++ b/gedcom/multilex.c @@ -122,7 +122,7 @@ void gedcom_init() update_gconv_search_path(); } -int gedcom_parse_file(char* file_name) +int gedcom_parse_file(const char* file_name) { ENCODING enc; int result = 1; diff --git a/gedcom/xref.c b/gedcom/xref.c index bc05ac3..d07f387 100644 --- a/gedcom/xref.c +++ b/gedcom/xref.c @@ -133,7 +133,7 @@ int check_xref_table() return result; } -struct xref_value *gedcom_get_by_xref(char *key) +struct xref_value *gedcom_get_by_xref(const char *key) { hnode_t *node = hash_lookup(xrefs, key); if (node) { diff --git a/include/gedcom.h.in b/include/gedcom.h.in index 50bbb0d..223dc0f 100644 --- a/include/gedcom.h.in +++ b/include/gedcom.h.in @@ -388,7 +388,7 @@ typedef struct _Gedcom_val_struct { union _Gedcom_val_union value; } Gedcom_val_struct; -void gedcom_cast_error(char* file, int line, +void gedcom_cast_error(const char* file, int line, Gedcom_val_type tried_type, Gedcom_val_type real_type); @@ -471,7 +471,7 @@ typedef void char *raw_value, int tag_value); void gedcom_init(); -int gedcom_parse_file(char* file_name); +int gedcom_parse_file(const char* file_name); void gedcom_set_debug_level(int level, FILE* trace_output); void gedcom_set_error_handling(Gedcom_err_mech mechanism); void gedcom_set_compat_handling(int enable_compat); @@ -486,15 +486,15 @@ void gedcom_subscribe_to_element(Gedcom_elt elt, Gedcom_elt_end_cb cb_end); /* Separate value parsing functions */ -struct date_value gedcom_parse_date(char* line_value); -struct age_value gedcom_parse_age(char* line_value); -struct xref_value *gedcom_get_by_xref(char *key); +struct date_value gedcom_parse_date(const char* line_value); +struct age_value gedcom_parse_age(const char* line_value); +struct xref_value *gedcom_get_by_xref(const char *key); /* For use in gom */ -int gedcom_error(char* s, ...); -int gedcom_warning(char* s, ...); -int gedcom_message(char* s, ...); -int gedcom_debug_print(char* s, ...); +int gedcom_error(const char* s, ...); +int gedcom_warning(const char* s, ...); +int gedcom_message(const char* s, ...); +int gedcom_debug_print(const char* s, ...); __END_DECLS -- 2.30.2