From c7ba92cef963d3c443f09160fa8420192a47a302 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Fri, 19 Aug 2011 17:10:05 +0200 Subject: [PATCH] [lib-result] fprint_*(): const pointers & asserts owl_fprint_*(): - Mark pointer arguments as const. - Rename main argument "src". - Use assertion to check the source. --- .../libowlps-resultreader-udp.c | 32 +++++++++++-------- .../owlps-resultreader-udp.h | 12 +++---- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/libowlps-resultreader-udp/libowlps-resultreader-udp.c b/libowlps-resultreader-udp/libowlps-resultreader-udp.c index bd09ba6..37cfd48 100644 --- a/libowlps-resultreader-udp/libowlps-resultreader-udp.c +++ b/libowlps-resultreader-udp/libowlps-resultreader-udp.c @@ -4,6 +4,8 @@ #include #include +#include + #define CSV_DELIMITER ";" @@ -183,23 +185,25 @@ void owl_fill_result(owl_result **result, char *csv) /* * Prints an owl_result to the given stream. */ -void owl_fprint_result(FILE *stream, owl_result *result) +void owl_fprint_result(FILE *stream, const owl_result *const src) { char timestamp_str[OWL_TIMESTAMP_STRLEN] ; - owl_timestamp_to_string(timestamp_str, result->mobile_timestamp) ; + assert(src) ; + + owl_timestamp_to_string(timestamp_str, src->mobile_timestamp) ; fprintf(stream, "Mobile MAC: %s\n" "Request type: %"PRIu8"\n" "Mobile timestamp: %s\n" "Results:\n" , - result->mobile_mac_addr, - result->request_type, + src->mobile_mac_addr, + src->request_type, timestamp_str ) ; - owl_algorithm_result *algo = result->results ; + owl_algorithm_result *algo = src->results ; while (algo) { owl_fprint_algorithm_result(stream, algo) ; @@ -209,11 +213,13 @@ void owl_fprint_result(FILE *stream, owl_result *result) /* - * Prints an owl_result to the given stream. + * Prints an owl_algorithm_result to the given stream. */ void owl_fprint_algorithm_result(FILE *stream, - owl_algorithm_result *algo) + const owl_algorithm_result *const src) { + assert(src) ; + fprintf(stream, "* Algorithm: %s\n" " X: %f\n" @@ -222,12 +228,12 @@ void owl_fprint_algorithm_result(FILE *stream, " Error: %f\n" " Area: %s\n" , - algo->algorithm, - algo->x, - algo->y, - algo->z, - algo->error, - algo->area ? algo->area : "" + src->algorithm, + src->x, + src->y, + src->z, + src->error, + src->area ? src->area : "" ) ; } diff --git a/libowlps-resultreader-udp/owlps-resultreader-udp.h b/libowlps-resultreader-udp/owlps-resultreader-udp.h index 60d857a..4ebc900 100644 --- a/libowlps-resultreader-udp/owlps-resultreader-udp.h +++ b/libowlps-resultreader-udp/owlps-resultreader-udp.h @@ -55,13 +55,13 @@ typedef struct _owl_result void owl_receive_position(int sockfd, owl_result **result) ; void owl_fill_result(owl_result **result, char *csv) ; -void owl_fprint_result(FILE *stream, owl_result *result) ; +void owl_fprint_result(FILE *stream, const owl_result *const src) ; void owl_fprint_algorithm_result(FILE *stream, - owl_algorithm_result *algo) ; -#define owl_print_result(RESULT) \ - (owl_fprint_result(stdout, (RESULT))) -#define owl_print_algorithm_result(ALGO) \ - (owl_fprint_algorithm_result(stdout, (ALGO))) + const owl_algorithm_result *const src) ; +#define owl_print_result(SRC) \ + (owl_fprint_result(stdout, (SRC))) +#define owl_print_algorithm_result(SRC) \ + (owl_fprint_algorithm_result(stdout, (SRC))) void owl_free_result(owl_result *result) ; void owl_free_algorithm_result(owl_algorithm_result *algo) ;