Browse Source

- changed signature of __clean_render_pipeline()

- using explicite local variables in __add_to_render_pipeline_via_strncpy()
- minor indent fixes
development
Andreas Romeyke 2 years ago
parent
commit
ee3247428b
3 changed files with 39 additions and 31 deletions
  1. +6
    -6
      src/checkit_tiff.c
  2. +3
    -3
      src/headers/check_helper.h
  3. +30
    -22
      src/helper/check_print.c

+ 6
- 6
src/checkit_tiff.c View File

@ -35,7 +35,7 @@ void help () {
printf ("checkit_tiff\n");
printf ("\tversion: %s\n", VERSION);
printf ("\trevision: %s\n", REPO_REVISION);
printf("licensed under conditions of libtiff (see http://libtiff.maptools.org/misc.html)\n\n");
printf ("licensed under conditions of libtiff (see http://libtiff.maptools.org/misc.html)\n\n");
printf ("call it with:\n");
printf ("\tcheckit_tiff [-c|-h|-m|-d|-q] <configfile> <tifffile> [<tifffile>]\n");
printf ("\nwhere <tifffile> is the tiff file (or directory) to be validated\n");
@ -75,7 +75,7 @@ int check_specific_tiff_file( const char * tiff_file, int use_memmapped) {
__add_to_render_pipeline_via_strncpy(&actual_render, "", rm_endtiff);
//printf("res.val='%s'\n", res.value_found);
goto renderer_exit;
}
}
uint32 offset;
res=get_first_IFD(ctif, &offset);
if (res.returncode != is_valid) {
@ -83,7 +83,7 @@ int check_specific_tiff_file( const char * tiff_file, int use_memmapped) {
__add_to_render_pipeline_via_strncpy(&actual_render, res.value_found, rm_hard_error);
__add_to_render_pipeline_via_strncpy(&actual_render, "", rm_endtiff);
goto renderer_exit;
}
}
execute_plan(ctif);
res = print_plan_results( actual_render);
renderer_exit:
@ -91,7 +91,7 @@ renderer_exit:
const char * render_result_string = renderer( render_pipeline );
printf("%s\n", render_result_string);
/* free all entries of render pipeline */
__clean_render_pipeline( render_pipeline );
__clean_render_pipeline( &render_pipeline );
free((void *) render_result_string);
}
free_ctif( ctif );
@ -173,7 +173,7 @@ int main (int argc, char * argv[]) {
size_t len = strlen( tiff_file_or_dir);
char tiff_dir [ len+1 ];
strncpy(tiff_dir, tiff_file_or_dir, len);
tiff_dir[ len ] = 0;
tiff_dir[ len ] = 0;
DIR *dir;
/* remove trailing / */
char *dirsuffix = strrchr(tiff_dir, '/');
@ -199,7 +199,7 @@ int main (int argc, char * argv[]) {
exit(EXIT_FAILURE);
}
if(attribute.st_mode & S_IFREG) {
printf ("%s\n", fqname);
printf ("%s\n", fqname);
parse_plan_via_file(cfg_file);
are_valid += check_specific_tiff_file( fqname, flag_use_memorymapped_io);
clean_plan();


+ 3
- 3
src/headers/check_helper.h View File

@ -1,7 +1,7 @@
/* rule based checks if given TIFF is a specific baseline TIFF
*
*
* author: Andreas Romeyke, 2015
* licensed under conditions of libtiff
* licensed under conditions of libtiff
* (see http://libtiff.maptools.org/misc.html)
*
*/
@ -44,7 +44,7 @@ int is_byteswapped( ctiff_t * ctif );
ret_t get_first_IFD(ctiff_t * ctif, uint32 * ifd);
ret_t set_value_found_ret (ret_t * rp, const char * msg);
returncode_t __add_to_render_pipeline_via_strncpy (retmsg_t ** pointer, const char * src, rm_type_t src_type);
void __clean_render_pipeline( retmsg_t * pointer );
void __clean_render_pipeline( retmsg_t ** pointer );
#define GET_EMPTY_RET(ret) \
ret_t ret; \


+ 30
- 22
src/helper/check_print.c View File

@ -34,8 +34,8 @@ returncode_t __add_to_render_pipeline_via_strncpy (retmsg_t ** pointer, const ch
assert(src != NULL);
assert(actual_render->next==NULL);
assert(actual_render->rm_msg != NULL);
actual_render->next = malloc ( sizeof(retmsg_t));
if (NULL == actual_render->next) {
retmsg_t * next = malloc ( sizeof(retmsg_t));
if (NULL == next) {
exit( could_not_allocate_memory);
// return could_not_allocate_memory;
}
@ -47,13 +47,14 @@ returncode_t __add_to_render_pipeline_via_strncpy (retmsg_t ** pointer, const ch
}
memset( actual_render->next->rm_msg, '\0', VALUESTRLEN);
*/
actual_render->next->rm_msg = calloc (VALUESTRLEN, sizeof(char) );
if (NULL == actual_render->next->rm_msg) {
char * msg = calloc (VALUESTRLEN, sizeof(char) );
if (NULL == msg) {
exit (could_not_allocate_memory);
// return could_not_allocate_memory;
}
strncpy(actual_render->next->rm_msg, src, VALUESTRLEN-1 );
strncpy(msg, src, VALUESTRLEN-1 );
actual_render->next = next;
actual_render->next->rm_msg = msg;
actual_render->next->rm_type = src_type;
// fprintf(stderr, "rendertype=%i rendermsg='%s'\n",actual_render->next->rm_type, actual_render->next->rm_msg );
actual_render->next->next=NULL;
@ -64,25 +65,32 @@ returncode_t __add_to_render_pipeline_via_strncpy (retmsg_t ** pointer, const ch
return is_valid;
}
void __clean_render_pipeline( retmsg_t * pointer ) {
assert(pointer != NULL);
retmsg_t * next = pointer->next;
if (NULL != pointer->rm_msg) {
free( pointer->rm_msg);
pointer->rm_msg = NULL;
}
if (NULL != next)
__clean_render_pipeline( next );
free( pointer );
pointer = NULL;
/* TODO: needs to be rewritten without stack deep recursive calls */
void __clean_render_pipeline( retmsg_t ** pointer ) {
assert(pointer != NULL);
retmsg_t * actual_render = NULL;
actual_render = *pointer;
if (NULL != actual_render) {
retmsg_t * next = actual_render->next;
char * rm_msg = actual_render->rm_msg;
free( actual_render );
//pointer = NULL;
if (NULL != rm_msg) {
free( rm_msg );
rm_msg = NULL;
}
if (NULL != next) {
__clean_render_pipeline( &next );
}
}
}
/*
ret_t tif_fails(const char* fail_message) {
ret_t res;
char * str =malloc( sizeof(char) *MAXSTRLEN );
if (NULL==str) {
/*
ret_t tif_fails(const char* fail_message) {
ret_t res;
char * str =malloc( sizeof(char) *MAXSTRLEN );
if (NULL==str) {
fprintf(stderr, "could not allocate memory for tif_fails\n");
exit(EXIT_FAILURE);
};


Loading…
Cancel
Save