diff --git a/cmp_tool.c b/cmp_tool.c index ab0febd1c069f21857ea68f7e95c82b626f72a55..fd8401f96975fd06a4c82b7a0216758ab33aae2a 100755 --- a/cmp_tool.c +++ b/cmp_tool.c @@ -502,7 +502,7 @@ static enum cmp_ent_data_type cmp_ent_map_cmp_mode_data_type(uint32_t cmp_mode) /* set raw bit if needed */ if (raw_mode_is_used(cmp_mode)) - data_type |= 1UL << RAW_BIT_IN_DATA_TYPE; + data_type |= 1UL << RAW_BIT_DATA_TYPE_POS; return data_type; } diff --git a/include/cmp_entity.h b/include/cmp_entity.h index bce7af674331181815d41f6ea35723273d4adef8..2d6bf542f1ec5b0c25f63fd257a2c3fbb325f78d 100644 --- a/include/cmp_entity.h +++ b/include/cmp_entity.h @@ -75,7 +75,7 @@ enum cmp_ent_data_type { #define CMP_ENTITY_MAX_SIZE 0xFFFFFFUL -#define RAW_BIT_IN_DATA_TYPE 15U +#define RAW_BIT_DATA_TYPE_POS 15U #define CMP_TOOL_VERSION_ID_BIT 0x80000000U @@ -128,7 +128,7 @@ compile_time_assert(sizeof(struct non_imagette_header) == SPECIFIC_NON_IMAGETTE_ __extension__ struct cmp_entity { - uint32_t asw_version_id; /* ICU ASW Version ID */ + uint32_t version_id; /* ICU ASW/cmp_tool Version ID */ uint32_t cmp_ent_size:24; /* Compression Entity Size */ uint32_t original_size:24; /* Original Data Size */ union { @@ -163,7 +163,7 @@ size_t cmp_ent_create(struct cmp_entity *ent, enum cmp_ent_data_type data_type, /* create a compression entity and set the header fields */ size_t cmp_ent_build(struct cmp_entity *ent, enum cmp_ent_data_type data_type, - uint32_t asw_version_id, uint64_t start_time, + uint32_t version_id, uint64_t start_time, uint64_t end_time, uint16_t model_id, uint8_t model_counter, struct cmp_info *info, struct cmp_cfg *cfg); @@ -173,7 +173,7 @@ int cmp_ent_read_imagette_header(struct cmp_entity *ent, struct cmp_info *info); /* set functions for generic compression entity header */ -int cmp_ent_set_asw_version_id(struct cmp_entity *ent, uint32_t asw_version_id); +int cmp_ent_set_version_id(struct cmp_entity *ent, uint32_t version_id); int cmp_ent_set_size(struct cmp_entity *ent, uint32_t cmp_ent_size); int cmp_ent_set_original_size(struct cmp_entity *ent, uint32_t original_size); @@ -235,7 +235,7 @@ int cmp_ent_set_non_ima_cmp_par6(struct cmp_entity *ent, uint32_t cmp_par6_used) /* get functions for generic compression entity header */ -uint32_t cmp_ent_get_asw_version_id(struct cmp_entity *ent); +uint32_t cmp_ent_get_version_id(struct cmp_entity *ent); uint32_t cmp_ent_get_size(struct cmp_entity *ent); uint32_t cmp_ent_get_original_size(struct cmp_entity *ent); diff --git a/lib/cmp_entity.c b/lib/cmp_entity.c index 44b2d968b8b9b5baac107878626cc9c4a905dfed..84f784d0993f62f12336966ce398ec7ff33f3e1d 100644 --- a/lib/cmp_entity.c +++ b/lib/cmp_entity.c @@ -84,7 +84,7 @@ uint32_t cmp_ent_cal_hdr_size(enum cmp_ent_data_type data_type) return 0; } - if ((data_type >> RAW_BIT_IN_DATA_TYPE) & 1U) + if ((data_type >> RAW_BIT_DATA_TYPE_POS) & 1U) return GENERIC_HEADER_SIZE; return 0; @@ -112,17 +112,17 @@ int cmp_ent_data_type_valid(enum cmp_ent_data_type data_type) * @brief set ICU ASW Version ID in the compression entity header * * @param ent pointer to a compression entity - * @param asw_version_id the applications software version identifier + * @param version_id the applications software version identifier * * @returns 0 on success, otherwise error */ -int cmp_ent_set_asw_version_id(struct cmp_entity *ent, uint32_t asw_version_id) +int cmp_ent_set_version_id(struct cmp_entity *ent, uint32_t version_id) { if (!ent) return -1; - ent->asw_version_id = cpu_to_be32(asw_version_id); + ent->version_id = cpu_to_be32(version_id); return 0; } @@ -939,12 +939,12 @@ int cmp_ent_set_non_ima_cmp_par6(struct cmp_entity *ent, uint32_t cmp_par_6_used * @returns the ASW version identifier on success, 0 on error */ -uint32_t cmp_ent_get_asw_version_id(struct cmp_entity *ent) +uint32_t cmp_ent_get_version_id(struct cmp_entity *ent) { if (!ent) return 0; - return be32_to_cpu(ent->asw_version_id); + return be32_to_cpu(ent->version_id); } @@ -1136,7 +1136,7 @@ int cmp_ent_get_data_type_raw_bit(struct cmp_entity *ent) if (!ent) return 0; - return (be16_to_cpu(ent->data_type) >> RAW_BIT_IN_DATA_TYPE) & 1U; + return (be16_to_cpu(ent->data_type) >> RAW_BIT_DATA_TYPE_POS) & 1U; } @@ -1934,7 +1934,7 @@ size_t cmp_ent_create(struct cmp_entity *ent, enum cmp_ent_data_type data_type, * @param ent pointer to a compression entity; if NULL, the * function returns the needed size * @param data_type compression entity data product type - * @param asw_version_id applications software version identifier + * @param version_id applications software version identifier * @param start_time compression start timestamp (coarse and fine) * @param end_time compression end timestamp (coarse and fine) * @param model_id model identifier @@ -1947,7 +1947,7 @@ size_t cmp_ent_create(struct cmp_entity *ent, enum cmp_ent_data_type data_type, */ size_t cmp_ent_build(struct cmp_entity *ent, enum cmp_ent_data_type data_type, - uint32_t asw_version_id, uint64_t start_time, + uint32_t version_id, uint64_t start_time, uint64_t end_time, uint16_t model_id, uint8_t model_counter, struct cmp_info *info, struct cmp_cfg *cfg) { @@ -1961,7 +1961,7 @@ size_t cmp_ent_build(struct cmp_entity *ent, enum cmp_ent_data_type data_type, return 0; if (ent) { - if (cmp_ent_set_asw_version_id(ent, asw_version_id)) + if (cmp_ent_set_version_id(ent, version_id)) return 0; if (cmp_ent_set_start_timestamp(ent, start_time)) return 0; @@ -2194,20 +2194,20 @@ void cmp_ent_print(struct cmp_entity *ent) static void cmp_ent_parse_generic_header(struct cmp_entity *ent) { - uint32_t asw_version_id, cmp_ent_size, original_size, cmp_mode_used, + uint32_t version_id, cmp_ent_size, original_size, cmp_mode_used, model_value_used, model_id, model_counter, lossy_cmp_par_used, start_coarse_time, end_coarse_time; uint16_t start_fine_time, end_fine_time; enum cmp_ent_data_type data_type; int raw_bit; - asw_version_id = cmp_ent_get_asw_version_id(ent); - if (asw_version_id & CMP_TOOL_VERSION_ID_BIT) { - uint16_t major = (asw_version_id & 0x7FFF0000U) >> 16U; - uint16_t minor = asw_version_id & 0xFFFFU; - printf("Compressed with cmp_tool version: %u.%02u\n", major,minor); + version_id = cmp_ent_get_version_id(ent); + if (version_id & CMP_TOOL_VERSION_ID_BIT) { + uint16_t major = (version_id & 0x7FFF0000U) >> 16U; + uint16_t minor = version_id & 0xFFFFU; + printf("Compressed with cmp_tool version: %u.%02u\n", major, minor); } else - printf("ICU ASW Version ID: %u\n", asw_version_id); + printf("ICU ASW Version ID: %u\n", version_id); cmp_ent_size = cmp_ent_get_size(ent); printf("Compression Entity Size: %u byte\n", cmp_ent_size); diff --git a/lib/cmp_io.c b/lib/cmp_io.c index 9dae3b9e44978d17c7c8c45777cb7b2801012666..bbd44c184ed73bdad31613cde5be9bcf5d6362bc 100644 --- a/lib/cmp_io.c +++ b/lib/cmp_io.c @@ -937,6 +937,7 @@ static const char *skip_space(const char *str) static const char *skip_comment(const char *str) { char c = *str; + if (c == '#') { do { str++; @@ -1040,14 +1041,15 @@ static ssize_t str2uint8_arr(const char *str, uint8_t *data, uint32_t n_word, errno = 0; if (!data) - n_word =~0; + n_word = ~0; if (!file_name) file_name = "unknown file name"; - for (i=0; i < n_word; ) { + for (i = 0; i < n_word; ) { uint8_t read_val; unsigned char c = *nptr; + if (c == '\0') { if (!data) /* finished counting the sample */ break; @@ -1140,15 +1142,15 @@ ssize_t read_file8(const char *file_name, uint8_t *buf, uint32_t n_word, int ver char *file_cpy = NULL; long file_size; ssize_t size; + size_t ret_code; if (!file_name) abort(); errno = 0; fp = fopen(file_name, "r"); - if (fp == NULL) { + if (fp == NULL) goto fail; - } /* Get the number of bytes */ if (fseek(fp, 0L, SEEK_END) != 0) @@ -1172,8 +1174,8 @@ ssize_t read_file8(const char *file_name, uint8_t *buf, uint32_t n_word, int ver } /* copy all the text into the file_cpy buffer */ - size_t ret_code = fread(file_cpy, sizeof(char), file_size, fp); - if(ret_code != (size_t)file_size) { + ret_code = fread(file_cpy, sizeof(char), file_size, fp); + if (ret_code != (size_t)file_size) { if (feof(fp)) printf("%s: %s: Error: unexpected end of file.\n", PROGRAM_NAME, file_name); goto fail; @@ -1304,6 +1306,7 @@ ssize_t read_file_cmp_entity(const char *file_name, struct cmp_entity *ent, if (ent) { enum cmp_ent_data_type data_type = cmp_ent_get_data_type(ent); + if (!cmp_ent_data_type_valid(data_type)) { fprintf(stderr, "%s: %s: Error: Compression data type is not supported.\n", PROGRAM_NAME, file_name);