nemea-common 1.6.3
progress_printer.h
Go to the documentation of this file.
1
8#ifndef PROGRESS_PRINTER_H
9#define PROGRESS_PRINTER_H
10
15#define NMCM_CNT_VALUE 1
16
22#define NMCM_PROGRESS_DECL struct nmcm_progress_t { \
23 int cnt, limit; \
24 char print_char; \
25 }; \
26
33#define NMCM_PROGRESS_DEF struct nmcm_progress_t nmcm_progress; \
34 struct nmcm_progress_t *nmcm_progress_ptr = &nmcm_progress;\
35 nmcm_progress_ptr->print_char = 0; \
36 nmcm_progress_ptr->limit = 0;
37
47#define NMCM_PROGRESS_INIT(a,err_cmd) do { \
48 if (a <= 0) { \
49 fprintf(stderr,"Error: 'progress' argument has to be greater than zero.\n"); \
50 err_cmd; \
51 } else { \
52 nmcm_progress_ptr->cnt = NMCM_CNT_VALUE; \
53 nmcm_progress_ptr->limit = (a); \
54 nmcm_progress_ptr->print_char = '.'; \
55 } \
56 } while (0);
57
62#define NMCM_PROGRESS_PRINT do { \
63 if (nmcm_progress_ptr->cnt == nmcm_progress.limit) { \
64 putchar(nmcm_progress_ptr->print_char); \
65 fflush(stdout); \
66 nmcm_progress_ptr->cnt = NMCM_CNT_VALUE; \
67 } else { \
68 nmcm_progress_ptr->cnt++; \
69 } \
70 } while (0);
71
78#define NMCM_PROGRESS_NEWLINE do { \
79 if (nmcm_progress_ptr->limit > 0) { \
80 putchar('\n'); \
81 } \
82 } while (0);
83
84#endif
85