From 8056ed7bbbfbcaec69a70c46c8501b234186ad50 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Fri, 23 Dec 2022 15:25:36 +0100 Subject: [PATCH] Cosmetic changes (enumerate values in header files when applicable) Signed-off-by: Sebastien GODARD --- common.h | 31 ++++--- iostat.h | 10 ++- json_stats.c | 6 +- pr_stats.c | 2 +- sa.h | 230 ++++++++++++++++++++++++++++----------------------- sa_common.c | 18 ++-- sadf.c | 2 +- sadf.h | 6 +- sadf_misc.c | 4 +- sar.c | 2 +- svg_stats.c | 4 +- svg_stats.h | 1 - tapestat.h | 6 +- xml_stats.c | 6 +- 14 files changed, 181 insertions(+), 147 deletions(-) diff --git a/common.h b/common.h index fcf1189..2c37fce 100644 --- a/common.h +++ b/common.h @@ -35,9 +35,12 @@ /* Index in units array (see common.c) */ #define NO_UNIT -1 -#define UNIT_SECTOR 0 -#define UNIT_BYTE 1 -#define UNIT_KILOBYTE 2 + +enum { + UNIT_SECTOR = 0, + UNIT_BYTE = 1, + UNIT_KILOBYTE = 2 +}; #define NR_UNITS 8 @@ -211,18 +214,22 @@ extern char persistent_name_type[MAX_FILE_LEN]; #define PERCENT_LIMIT_LOW 25.0 #define PERCENT_LIMIT_XLOW 10.0 -#define XHIGH 1 -#define XLOW 2 -#define XLOW0 3 +enum { + XHIGH = 1, + XLOW = 2, + XLOW0 = 3 +}; #define MAX_SGR_LEN 16 -#define IS_INT 0 -#define IS_STR 1 -#define IS_RESTART 2 -#define IS_DEBUG IS_RESTART -#define IS_COMMENT 3 -#define IS_ZERO 4 +enum { + IS_INT = 0, + IS_STR = 1, + IS_RESTART = 2, + IS_COMMENT = 3, + IS_ZERO = 4, + IS_DEBUG = IS_RESTART +}; /* *************************************************************************** diff --git a/iostat.h b/iostat.h index 380263c..26eed23 100644 --- a/iostat.h +++ b/iostat.h @@ -57,10 +57,12 @@ #define USE_ALL_DIR(m) (((m) & I_D_ALL_DIR) == I_D_ALL_DIR) #define DISPLAY_COMPACT(m) (((m) & I_D_COMPACT) == I_D_COMPACT) -#define T_PART 0 -#define T_DEV 1 -#define T_PART_DEV 2 -#define T_GROUP 3 +enum { + T_PART = 0, + T_DEV = 1, + T_PART_DEV = 2, + T_GROUP = 3 +}; #define UKWN_MAJ_NR 0 diff --git a/json_stats.c b/json_stats.c index 532ca10..51a7e66 100644 --- a/json_stats.c +++ b/json_stats.c @@ -46,7 +46,7 @@ extern uint64_t flags; * @action Open or close action. *************************************************************************** */ -void json_markup_network(int tab, int action) +void json_markup_network(int tab, enum json_action action) { static int markup_state = CLOSE_JSON_MARKUP; @@ -74,7 +74,7 @@ void json_markup_network(int tab, int action) * @action Open or close action. *************************************************************************** */ -void json_markup_power_management(int tab, int action) +void json_markup_power_management(int tab, enum json_action action) { static int markup_state = CLOSE_JSON_MARKUP; @@ -102,7 +102,7 @@ void json_markup_power_management(int tab, int action) * @action Open or close action. *************************************************************************** */ -void json_markup_psi(int tab, int action) +void json_markup_psi(int tab, enum json_action action) { static int markup_state = CLOSE_JSON_MARKUP; diff --git a/pr_stats.c b/pr_stats.c index 0040f94..cbd9800 100644 --- a/pr_stats.c +++ b/pr_stats.c @@ -48,7 +48,7 @@ extern unsigned long avg_count; * IN: * @p_timestamp Timestamp for previous stat sample. * @a Activity structure. - * @pos Header to display, 0 being the first header (headers + * @pos Header to display, FIRST being the first header (headers * are delimited by the '|' character). * @iwidth First column width (generally this is the item name). * A negative value means that the corresponding field diff --git a/sa.h b/sa.h index 14d82c4..e59a728 100644 --- a/sa.h +++ b/sa.h @@ -28,49 +28,50 @@ #define NR_F_COUNT 13 /* Activities */ -#define A_CPU 1 -#define A_PCSW 2 -#define A_IRQ 3 -#define A_SWAP 4 -#define A_PAGE 5 -#define A_IO 6 -#define A_MEMORY 7 -#define A_KTABLES 8 -#define A_QUEUE 9 -#define A_SERIAL 10 -#define A_DISK 11 -#define A_NET_DEV 12 -#define A_NET_EDEV 13 -#define A_NET_NFS 14 -#define A_NET_NFSD 15 -#define A_NET_SOCK 16 -#define A_NET_IP 17 -#define A_NET_EIP 18 -#define A_NET_ICMP 19 -#define A_NET_EICMP 20 -#define A_NET_TCP 21 -#define A_NET_ETCP 22 -#define A_NET_UDP 23 -#define A_NET_SOCK6 24 -#define A_NET_IP6 25 -#define A_NET_EIP6 26 -#define A_NET_ICMP6 27 -#define A_NET_EICMP6 28 -#define A_NET_UDP6 29 -#define A_PWR_CPU 30 -#define A_PWR_FAN 31 -#define A_PWR_TEMP 32 -#define A_PWR_IN 33 -#define A_HUGE 34 -#define A_PWR_FREQ 35 -#define A_PWR_USB 36 -#define A_FS 37 -#define A_NET_FC 38 -#define A_NET_SOFT 39 -#define A_PSI_CPU 40 -#define A_PSI_IO 41 -#define A_PSI_MEM 42 - +enum { + A_CPU = 1, + A_PCSW = 2, + A_IRQ = 3, + A_SWAP = 4, + A_PAGE = 5, + A_IO = 6, + A_MEMORY = 7, + A_KTABLES = 8, + A_QUEUE = 9, + A_SERIAL = 10, + A_DISK = 11, + A_NET_DEV = 12, + A_NET_EDEV = 13, + A_NET_NFS = 14, + A_NET_NFSD = 15, + A_NET_SOCK = 16, + A_NET_IP = 17, + A_NET_EIP = 18, + A_NET_ICMP = 19, + A_NET_EICMP = 20, + A_NET_TCP = 21, + A_NET_ETCP = 22, + A_NET_UDP = 23, + A_NET_SOCK6 = 24, + A_NET_IP6 = 25, + A_NET_EIP6 = 26, + A_NET_ICMP6 = 27, + A_NET_EICMP6 = 28, + A_NET_UDP6 = 29, + A_PWR_CPU = 30, + A_PWR_FAN = 31, + A_PWR_TEMP = 32, + A_PWR_IN = 33, + A_HUGE = 34, + A_PWR_FREQ = 35, + A_PWR_USB = 36, + A_FS = 37, + A_NET_FC = 38, + A_NET_SOFT = 39, + A_PSI_CPU = 40, + A_PSI_IO = 41, + A_PSI_MEM = 42 +}; /* Macro used to flag an activity that should be collected */ #define COLLECT_ACTIVITY(m) act[get_activity_position(act, m, EXIT_IF_NOT_FOUND)]->options |= AO_COLLECTED @@ -308,26 +309,40 @@ #define EXIT_IF_NOT_FOUND 1 #define RESUME_IF_NOT_FOUND 0 -#define SOFT_SIZE 0 -#define HARD_SIZE 1 +enum size_mode { + SOFT_SIZE = 0, + HARD_SIZE = 1 +}; -#define FIRST 0 -#define SECOND 1 +enum { + FIRST = 0, + SECOND = 1 +}; -#define END_OF_DATA_UNEXPECTED 1 -#define INCONSISTENT_INPUT_DATA 2 +enum sa_err_codes { + END_OF_DATA_UNEXPECTED = 1, + INCONSISTENT_INPUT_DATA = 2 +}; -#define UEOF_STOP 0 -#define UEOF_CONT 1 +enum on_eof { + UEOF_STOP = 0, + UEOF_CONT = 1 +}; -#define CLOSE_XML_MARKUP 0 -#define OPEN_XML_MARKUP 1 +enum xml_action { + CLOSE_XML_MARKUP = 0, + OPEN_XML_MARKUP = 1 +}; -#define CLOSE_JSON_MARKUP 0 -#define OPEN_JSON_MARKUP 1 +enum json_action { + CLOSE_JSON_MARKUP = 0, + OPEN_JSON_MARKUP = 1 +}; -#define COUNT_ACTIVITIES 0 -#define COUNT_OUTPUTS 1 +enum count_mode { + COUNT_ACTIVITIES = 0, + COUNT_OUTPUTS = 1 +}; /* Type for all functions reading statistics */ #define __read_funct_t void @@ -336,7 +351,7 @@ /* *************************************************************************** - * Output formats for sadf + * Output formats for sadfsize_mode *************************************************************************** */ @@ -344,17 +359,18 @@ #define NR_FMT 9 /* Output formats */ -#define F_SAR_OUTPUT 0 -#define F_DB_OUTPUT 1 -#define F_HEADER_OUTPUT 2 -#define F_PPC_OUTPUT 3 -#define F_XML_OUTPUT 4 -#define F_JSON_OUTPUT 5 -#define F_CONV_OUTPUT 6 -#define F_SVG_OUTPUT 7 -#define F_RAW_OUTPUT 8 -#define F_PCP_OUTPUT 9 - +enum { + F_SAR_OUTPUT = 0, + F_DB_OUTPUT = 1, + F_HEADER_OUTPUT = 2, + F_PPC_OUTPUT = 3, + F_XML_OUTPUT = 4, + F_JSON_OUTPUT = 5, + F_CONV_OUTPUT = 6, + F_SVG_OUTPUT = 7, + F_RAW_OUTPUT = 8, + F_PCP_OUTPUT = 9 +}; /* Structure for SVG specific parameters */ struct svg_parm { @@ -716,33 +732,35 @@ struct extra_desc { #define MAX_EXTRA_SIZE 1024 /* Record type */ -/* - * R_STATS means that this is a record of statistics. - */ -#define R_STATS 1 -/* - * R_RESTART means that this is a special record containing - * a LINUX RESTART message. - */ -#define R_RESTART 2 -/* - * R_LAST_STATS warns sar that this is the last record to be written - * to file before a file rotation, and that the next data to come will - * be a header file. - * Such a record is tagged R_STATS anyway before being written to file. - */ -#define R_LAST_STATS 3 -/* - * R_COMMENT means that this is a special record containing - * a comment. - */ -#define R_COMMENT 4 -/* - * R_EXTRA* records means that extra structures are following current - * record_header structure, but no statistics structures. - */ -#define R_EXTRA_MIN 5 -#define R_EXTRA_MAX 15 +enum { + /* + * R_STATS means that this is a record of statistics. + */ + R_STATS = 1, + /* + * R_RESTART means that this is a special record containing + * a LINUX RESTART message. + */ + R_RESTART = 2, + /* + * R_LAST_STATS warns sar that this is the last record to be written + * to file before a file rotation, and that the next data to come will + * be a header file. + * Such a record is tagged R_STATS anyway before being written to file. + */ + R_LAST_STATS = 3, + /* + * R_COMMENT means that this is a special record containing + * a comment. + */ + R_COMMENT = 4, + /* + * R_EXTRA* records means that extra structures are following current + * record_header structure, but no statistics structures. + */ + R_EXTRA_MIN = 5, + R_EXTRA_MAX = 15 +}; /* Maximum length of a comment */ #define MAX_COMMENT_LEN 64 @@ -1277,8 +1295,10 @@ struct report_format { /* Maximum number of views on a single row */ #define MAX_VIEWS_ON_A_ROW 6 -#define SVG_LINE_GRAPH 1 -#define SVG_BAR_GRAPH 2 +enum svg_graph_type { + SVG_LINE_GRAPH = 1, + SVG_BAR_GRAPH = 2 +}; /* Maximum number of horizontal lines for the background grid */ #define MAX_HLINES_NR 10 @@ -1296,9 +1316,11 @@ struct report_format { #define SVG_COL_HEADER_IDX 22 #define SVG_COL_ERROR_IDX 23 -#define SVG_DEFAULT_COL_PALETTE 0 -#define SVG_CUSTOM_COL_PALETTE 1 -#define SVG_BW_COL_PALETTE 2 +enum { + SVG_DEFAULT_COL_PALETTE = 0, + SVG_CUSTOM_COL_PALETTE = 1, + SVG_BW_COL_PALETTE = 2 +}; #define MAYBE 0x80 @@ -1484,7 +1506,7 @@ int check_alt_sa_dir void enum_version_nr (struct file_magic *); int get_activity_nr - (struct activity * [], unsigned int, int); + (struct activity * [], unsigned int, enum count_mode); int get_activity_position (struct activity * [], unsigned int, int); void handle_invalid_sa_file @@ -1573,7 +1595,7 @@ int print_special_record struct file_header *, struct activity * [], struct report_format *, int, int); int read_file_stat_bunch (struct activity * [], int, int, int, struct file_activity *, int, int, - char *, struct file_magic *, int); + char *, struct file_magic *, enum on_eof); __nr_t read_nr_value (int, char *, struct file_magic *, int, int, int); int read_record_hdr @@ -1584,7 +1606,7 @@ void reallocate_all_buffers void replace_nonprintable_char (int, char *); int sa_fread - (int, void *, size_t, int, int); + (int, void *, size_t, enum size_mode, enum on_eof); int sa_get_record_timestamp_struct (uint64_t, struct record_header *, struct tm *); int sa_open_read_magic diff --git a/sa_common.c b/sa_common.c index 0ca8b03..5b4aeac 100644 --- a/sa_common.c +++ b/sa_common.c @@ -91,17 +91,17 @@ int get_activity_position(struct activity *act[], unsigned int act_flag, int sto * Count number of activities with given option. * * IN: - * @act Array of activities. - * @option Option that activities should have to be counted - * (eg. AO_COLLECTED...) - * @count_outputs TRUE if each output should be counted for activities with - * multiple outputs. + * @act Array of activities. + * @option Option that activities should have to be counted + * (eg. AO_COLLECTED...) + * @count Set to COUNT_OUTPUTS if each output should be counted for + * activities with multiple outputs. * * RETURNS: * Number of selected activities *************************************************************************** */ -int get_activity_nr(struct activity *act[], unsigned int option, int count_outputs) +int get_activity_nr(struct activity *act[], unsigned int option, enum count_mode count) { int i, n = 0; unsigned int msk; @@ -109,7 +109,7 @@ int get_activity_nr(struct activity *act[], unsigned int option, int count_outpu for (i = 0; i < NR_ACT; i++) { if ((act[i]->options & option) == option) { - if (HAS_MULTIPLE_OUTPUTS(act[i]->options) && count_outputs) { + if (HAS_MULTIPLE_OUTPUTS(act[i]->options) && (count == COUNT_OUTPUTS)) { for (msk = 1; msk < 0x100; msk <<= 1) { if ((act[i]->opt_flags & 0xff) & msk) { n++; @@ -1373,7 +1373,7 @@ int remap_struct(unsigned int gtypes_nr[], unsigned int ftypes_nr[], * 0 otherwise. *************************************************************************** */ -int sa_fread(int ifd, void *buffer, size_t size, int mode, int oneof) +int sa_fread(int ifd, void *buffer, size_t size, enum size_mode mode, enum on_eof oneof) { ssize_t n; @@ -1649,7 +1649,7 @@ __nr_t read_nr_value(int ifd, char *file, struct file_magic *file_magic, int read_file_stat_bunch(struct activity *act[], int curr, int ifd, int act_nr, struct file_activity *file_actlst, int endian_mismatch, int arch_64, char *dfile, struct file_magic *file_magic, - int oneof) + enum on_eof oneof) { int i, j, p; struct file_activity *fal = file_actlst; diff --git a/sadf.c b/sadf.c index dede787..29fdc5d 100644 --- a/sadf.c +++ b/sadf.c @@ -241,7 +241,7 @@ void check_format_options(void) */ int read_next_sample(int ifd, int action, int curr, char *file, int *rtype, int tab, struct file_magic *file_magic, struct file_activity *file_actlst, - struct tm *rectime, int oneof) + struct tm *rectime, enum on_eof oneof) { int rc; char rec_hdr_tmp[MAX_RECORD_HEADER_SIZE]; diff --git a/sadf.h b/sadf.h index 582659c..3989f2e 100644 --- a/sadf.h +++ b/sadf.h @@ -12,8 +12,10 @@ #define XML_DTD_VERSION "3.12" /* Various constants */ -#define DO_SAVE 0 -#define DO_RESTORE 1 +enum { + DO_SAVE = 0, + DO_RESTORE = 1 +}; #define IGNORE_NOTHING 0 #define IGNORE_RESTART 1 diff --git a/sadf_misc.c b/sadf_misc.c index 3fef6bc..432fda0 100644 --- a/sadf_misc.c +++ b/sadf_misc.c @@ -868,14 +868,14 @@ char *print_dbppc_timestamp(int fmt, struct file_header *file_hdr, char *cur_dat * @itv Interval of time with preceding record. * @record_hdr Record header for current sample (unused here). * @file_hdr System activity file standard header. - * @flags Flags for common options. + * @flags Flags for common options (unused here). * * RETURNS: * Pointer on the "timestamp" string. *************************************************************************** */ __tm_funct_t print_ppc_timestamp(void *parm, int action, char *cur_date, - char *cur_time, char * my_tz, unsigned long long itv, + char *cur_time, char *my_tz, unsigned long long itv, struct record_header *record_hdr, struct file_header *file_hdr, unsigned int flags) { diff --git a/sar.c b/sar.c index 0bc2910..c66c3b1 100644 --- a/sar.c +++ b/sar.c @@ -278,7 +278,7 @@ void salloc(int i, char *ltemp) * @error_code Code of error message to display. *************************************************************************** */ -void print_read_error(int error_code) +void print_read_error(enum sa_err_codes error_code) { switch (error_code) { diff --git a/svg_stats.c b/svg_stats.c index e1d88a9..f5b1b4e 100644 --- a/svg_stats.c +++ b/svg_stats.c @@ -596,8 +596,8 @@ void compute_next_graduation_timestamp(struct record_header *stamp, long int xpo * @asfactor Autoscale factors (one for each graph). *************************************************************************** */ -void gr_autoscaling(unsigned int asfactor[], int asf_nr, int group, int g_type, int pos, - double gmax, double *spmax) +void gr_autoscaling(unsigned int asfactor[], int asf_nr, int group, enum svg_graph_type g_type, + int pos, double gmax, double *spmax) { int j; char val[32]; diff --git a/svg_stats.h b/svg_stats.h index a64d2d0..634bbf7 100644 --- a/svg_stats.h +++ b/svg_stats.h @@ -6,7 +6,6 @@ #ifndef _SVG_STATS_H #define _SVG_STATS_H - /* *************************************************************************** * Prototypes for functions used to display system statistics in SVG. diff --git a/tapestat.h b/tapestat.h index 9e41102..49162bc 100644 --- a/tapestat.h +++ b/tapestat.h @@ -28,8 +28,10 @@ #define DISPLAY_ZERO_OMIT(m) (((m) & T_D_ZERO_OMIT) == T_D_ZERO_OMIT) #define DISPLAY_UNIT(m) (((m) & T_D_UNIT) == T_D_UNIT) -#define TAPE_STATS_VALID 1 -#define TAPE_STATS_INVALID 0 +enum { + TAPE_STATS_INVALID = 0, + TAPE_STATS_VALID = 1 +}; #define SYSFS_CLASS_TAPE_DIR PRE "/sys/class/scsi_tape" #define TAPE_STAT_PATH PRE "/sys/class/scsi_tape/st%i/stats/" diff --git a/xml_stats.c b/xml_stats.c index 4865492..d48524f 100644 --- a/xml_stats.c +++ b/xml_stats.c @@ -46,7 +46,7 @@ extern uint64_t flags; * @action Open or close action. *************************************************************************** */ -void xml_markup_network(int tab, int action) +void xml_markup_network(int tab, enum xml_action action) { static int markup_state = CLOSE_XML_MARKUP; @@ -73,7 +73,7 @@ void xml_markup_network(int tab, int action) * @action Open or close action. *************************************************************************** */ -void xml_markup_power_management(int tab, int action) +void xml_markup_power_management(int tab, enum xml_action action) { static int markup_state = CLOSE_XML_MARKUP; @@ -100,7 +100,7 @@ void xml_markup_power_management(int tab, int action) * @action Open or close action. *************************************************************************** */ -void xml_markup_psi(int tab, int action) +void xml_markup_psi(int tab, enum xml_action action) { static int markup_state = CLOSE_XML_MARKUP; -- 2.40.0