From ee8c198a3c6cbc7bb877fdc2378ef6a8e758032e Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Tue, 21 Mar 2017 04:08:55 -0700 Subject: libvmon: style cleanups Bring libvmon code inline with the direction vwm has headed in terms of coding style. Entirely mechanical changes with one exception replacing a free()/=NULL idiom with try_free(). --- src/libvmon/defs/_begin.def | 408 +++++++++++++++++++++----------------------- 1 file changed, 198 insertions(+), 210 deletions(-) (limited to 'src/libvmon/defs') diff --git a/src/libvmon/defs/_begin.def b/src/libvmon/defs/_begin.def index 047fd4d..f6b441a 100644 --- a/src/libvmon/defs/_begin.def +++ b/src/libvmon/defs/_begin.def @@ -174,28 +174,28 @@ * names etc. */ #define vmon_datum_str(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch(input) {\ - case VMON_PARSER_DELIM:\ - /* store accumulated string, reset tmp, and advance */\ - if(*store)->_name) {\ - if( strncmp((*store)->name, _array, var_array_len) ||\ - (*store)->name[var_array_len] != '\0') {\ - BITSET((*store)->changed, VMON_ ## _sym);\ - changes++;\ - }\ - free((*store)->name);\ - } else {\ - BITSET((*store)->changed, VMON_ ## _sym);\ - changes++;\ + switch (input) {\ + case VMON_PARSER_DELIM:\ + /* store accumulated string, reset tmp, and advance */\ + if ((*store)->_name) {\ + if ( strncmp((*store)->name, _array, var_array_len) ||\ + (*store)->name[var_array_len] != '\0') {\ + BITSET((*store)->changed, VMON_ ## _sym);\ + changes++;\ }\ - (*store)->_name = strndup(var_array, var_array_len);\ - var_array_len = 0;\ - state++;\ - break;\ - default:\ - /* accumulate string */\ - var_array[var_array_len++] = input;\ - break;\ + free((*store)->name);\ + } else {\ + BITSET((*store)->changed, VMON_ ## _sym);\ + changes++;\ + }\ + (*store)->_name = strndup(var_array, var_array_len);\ + var_array_len = 0;\ + state++;\ + break;\ + default:\ + /* accumulate string */\ + var_array[var_array_len++] = input;\ + break;\ }\ break; @@ -204,7 +204,7 @@ break; #define vmon_datum_char(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - if((*store)->_name != input) {\ + if ((*store)->_name != input) {\ BITSET((*store)->changed, VMON_ ## _sym);\ changes++;\ (*store)->_name = input;\ @@ -218,159 +218,153 @@ break; #define vmon_datum_int(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch(input) {\ - case '-':\ - /* TODO: we don't verify the '-' is leading... */\ - var_isneg = 1;\ - break;\ - case '0' ... '9':\ - var_int *= 10;\ - var_int += input - '0';\ - break;\ - default:\ - if(var_isneg) {\ - var_int = -var_int;\ - var_isneg = 0;\ - }\ - if((*store)->_name != var_int) {\ - BITSET((*store)->changed, VMON_ ## _sym);\ - changes++;\ - (*store)->_name = var_int;\ - }\ - var_int = 0;\ - state++;\ - break;\ + switch (input) {\ + case '-':\ + /* TODO: we don't verify the '-' is leading... */\ + var_isneg = 1;\ + break;\ + case '0' ... '9':\ + var_int *= 10;\ + var_int += input - '0';\ + break;\ + default:\ + if (var_isneg) {\ + var_int = -var_int;\ + var_isneg = 0;\ + }\ + if ((*store)->_name != var_int) {\ + BITSET((*store)->changed, VMON_ ## _sym);\ + changes++;\ + (*store)->_name = var_int;\ + }\ + var_int = 0;\ + state++;\ + break;\ }\ - if(state == VMON_PARSER_STATE_ ## _sym) {\ + if (state == VMON_PARSER_STATE_ ## _sym)\ /* we want to fall-through when the state advances */\ - break;\ - } + break; #define vmon_datum_uint(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch(input) {\ - case '0' ... '9':\ - var_uint *= 10;\ - var_uint += input - '0';\ - break;\ - default:\ - if((*store)->_name != var_uint) {\ - BITSET((*store)->changed, VMON_ ## _sym);\ - changes++;\ - (*store)->_name = var_uint;\ - }\ - var_uint = 0;\ - state++;\ - break;\ + switch (input) {\ + case '0' ... '9':\ + var_uint *= 10;\ + var_uint += input - '0';\ + break;\ + default:\ + if ((*store)->_name != var_uint) {\ + BITSET((*store)->changed, VMON_ ## _sym);\ + changes++;\ + (*store)->_name = var_uint;\ + }\ + var_uint = 0;\ + state++;\ + break;\ }\ - if(state == VMON_PARSER_STATE_ ## _sym) {\ + if (state == VMON_PARSER_STATE_ ## _sym)\ /* we want to fall-through when the state advances */\ - break;\ - } + break; #define vmon_datum_ulong(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch(input) {\ - case '0' ... '9':\ - var_ulong *= 10;\ - var_ulong += input - '0';\ - break;\ - default:\ - if((*store)->_name != var_ulong) {\ - BITSET((*store)->changed, VMON_ ## _sym);\ - changes++;\ - (*store)->_name = var_ulong;\ - }\ - var_ulong = 0;\ - state++;\ - break;\ + switch (input) {\ + case '0' ... '9':\ + var_ulong *= 10;\ + var_ulong += input - '0';\ + break;\ + default:\ + if ((*store)->_name != var_ulong) {\ + BITSET((*store)->changed, VMON_ ## _sym);\ + changes++;\ + (*store)->_name = var_ulong;\ + }\ + var_ulong = 0;\ + state++;\ + break;\ }\ - if(state == VMON_PARSER_STATE_ ## _sym) {\ + if (state == VMON_PARSER_STATE_ ## _sym)\ /* we want to fall-through when the state advances */\ - break;\ - } + break; #define vmon_datum_ulonglong(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch(input) {\ - case '0' ... '9':\ - var_ulonglong *= 10;\ - var_ulonglong += input - '0';\ - break;\ - default:\ - if((*store)->_name != var_ulonglong) {\ - BITSET((*store)->changed, VMON_ ## _sym);\ - changes++;\ - (*store)->_name = var_ulonglong;\ - }\ - var_ulonglong = 0;\ - state++;\ - break;\ + switch (input) {\ + case '0' ... '9':\ + var_ulonglong *= 10;\ + var_ulonglong += input - '0';\ + break;\ + default:\ + if ((*store)->_name != var_ulonglong) {\ + BITSET((*store)->changed, VMON_ ## _sym);\ + changes++;\ + (*store)->_name = var_ulonglong;\ + }\ + var_ulonglong = 0;\ + state++;\ + break;\ }\ - if(state == VMON_PARSER_STATE_ ## _sym) {\ + if (state == VMON_PARSER_STATE_ ## _sym)\ /* we want to fall-through when the state advances */\ - break;\ - } + break; #define vmon_datum_long(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch(input) {\ - case '-':\ - /* TODO: we dont verify the '-' is leading... */\ - var_isneg = 1;\ - break;\ - case '0' ... '9':\ - var_long *= 10;\ - var_long += input - '0';\ - break;\ - default:\ - if(var_isneg) {\ - var_long = -var_long;\ - var_isneg = 0;\ - }\ - if((*store)->_name != var_long) {\ - BITSET((*store)->changed, VMON_ ## _sym);\ - changes++;\ - (*store)->_name = var_long;\ - }\ - var_long = 0;\ - state++;\ - break;\ + switch (input) {\ + case '-':\ + /* TODO: we dont verify the '-' is leading... */\ + var_isneg = 1;\ + break;\ + case '0' ... '9':\ + var_long *= 10;\ + var_long += input - '0';\ + break;\ + default:\ + if (var_isneg) {\ + var_long = -var_long;\ + var_isneg = 0;\ + }\ + if ((*store)->_name != var_long) {\ + BITSET((*store)->changed, VMON_ ## _sym);\ + changes++;\ + (*store)->_name = var_long;\ + }\ + var_long = 0;\ + state++;\ + break;\ }\ - if(state == VMON_PARSER_STATE_ ## _sym) {\ + if (state == VMON_PARSER_STATE_ ## _sym)\ /* we want to fall-through when the state advances */\ - break;\ - } + break; #define vmon_datum_longlong(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch(input) {\ - case '-':\ - /* TODO: we dont verify the '-' is leading... */\ - var_isneg = 1;\ - break;\ - case '0' ... '9':\ - var_longlong *= 10;\ - var_longlong += input - '0';\ - break;\ - default:\ - if(var_isneg) {\ - var_longlong = -var_longlong;\ - var_isneg = 0;\ - }\ - if((*store)->_name != var_longlong) {\ - BITSET((*store)->changed, VMON_ ## _sym);\ - changes++;\ - (*store)->_name = var_longlong;\ - }\ - var_longlong = 0;\ - state++;\ - break;\ + switch (input) {\ + case '-':\ + /* TODO: we dont verify the '-' is leading... */\ + var_isneg = 1;\ + break;\ + case '0' ... '9':\ + var_longlong *= 10;\ + var_longlong += input - '0';\ + break;\ + default:\ + if (var_isneg) {\ + var_longlong = -var_longlong;\ + var_isneg = 0;\ + }\ + if ((*store)->_name != var_longlong) {\ + BITSET((*store)->changed, VMON_ ## _sym);\ + changes++;\ + (*store)->_name = var_longlong;\ + }\ + var_longlong = 0;\ + state++;\ + break;\ }\ - if(state == VMON_PARSER_STATE_ ## _sym) {\ + if (state == VMON_PARSER_STATE_ ## _sym)\ /* we want to fall-through when the state advances */\ - break;\ - } + break; /* parse but simply skip omitted fields, advance on the delimiter */ #define vmon_omit_n(_n, _sym, _desc) case VMON_PARSER_STATE_ ## _sym:\ var_int++;\ - if(var_int >= _n) {\ + if (var_int >= _n) {\ var_int = 0;\ state++;\ }\ @@ -379,14 +373,14 @@ #define vmon_omit_literal(_lit, _sym) case VMON_PARSER_STATE_ ## _sym:\ /* TODO make this actually match the literal, for now we skip the length. */ \ var_int++;\ - if(var_int >= (sizeof(_lit) - 1)) {\ + if (var_int >= (sizeof(_lit) - 1)) {\ var_int = 0;\ state++;\ }\ break; #define vmon_omit_run(_char, _sym) case VMON_PARSER_STATE_ ## _sym:\ - if(input != _char) {\ + if (input != _char) {\ state++;\ /* XXX: we fall-through to the next case because this byte belongs to the next state */\ } else {\ @@ -395,14 +389,14 @@ #define vmon_omit_str(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - if(input == VMON_PARSER_DELIM) {\ + if (input == VMON_PARSER_DELIM) {\ state++;\ } else {\ break;\ } #define vmon_omit_str_array(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - if(input == VMON_PARSER_DELIM) {\ + if (input == VMON_PARSER_DELIM) {\ state++;\ } else {\ break;\ @@ -413,92 +407,86 @@ break; #define vmon_omit_char_array(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - if(input == VMON_PARSER_DELIM) {\ + if (input == VMON_PARSER_DELIM) {\ state++;\ } else {\ break;\ } #define vmon_omit_int(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch(input) {\ - case '0' ... '9':\ - case '-':\ - break;\ - default:\ - state++;\ - break;\ + switch (input) {\ + case '0' ... '9':\ + case '-':\ + break;\ + default:\ + state++;\ + break;\ }\ - if(state == VMON_PARSER_STATE_ ## _sym) {\ + if (state == VMON_PARSER_STATE_ ## _sym)\ /* we want to fall-through when the state advances */\ break;\ - } #define vmon_omit_uint(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch(input) {\ - case '0' ... '9':\ - break;\ - default:\ - state++;\ - break;\ + switch (input) {\ + case '0' ... '9':\ + break;\ + default:\ + state++;\ + break;\ }\ - if(state == VMON_PARSER_STATE_ ## _sym) {\ + if (state == VMON_PARSER_STATE_ ## _sym)\ /* we want to fall-through when the state advances */\ - break;\ - } + break; #define vmon_omit_ulong(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch(input) {\ - case '0' ... '9':\ - break;\ - default:\ - state++;\ - break;\ + switch (input) {\ + case '0' ... '9':\ + break;\ + default:\ + state++;\ + break;\ }\ - if(state == VMON_PARSER_STATE_ ## _sym) {\ + if (state == VMON_PARSER_STATE_ ## _sym)\ /* we want to fall-through when the state advances */\ - break;\ - } + break; #define vmon_omit_ulonglong(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch(input) {\ - case '0' ... '9':\ - break;\ - default:\ - state++;\ - break;\ + switch (input) {\ + case '0' ... '9':\ + break;\ + default:\ + state++;\ + break;\ }\ - if(state == VMON_PARSER_STATE_ ## _sym) {\ + if (state == VMON_PARSER_STATE_ ## _sym)\ /* we want to fall-through when the state advances */\ - break;\ - } + break; #define vmon_omit_long(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch(input) {\ - case '0' ... '9':\ - case '-':\ - break;\ - default:\ - state++;\ - break;\ + switch (input) {\ + case '0' ... '9':\ + case '-':\ + break;\ + default:\ + state++;\ + break;\ }\ - if(state == VMON_PARSER_STATE_ ## _sym) {\ + if (state == VMON_PARSER_STATE_ ## _sym)\ /* we want to fall-through when the state advances */\ - break;\ - } + break; #define vmon_omit_longlong(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch(input) {\ - case '0' ... '9':\ - case '-':\ - break;\ - default:\ - state++;\ - break;\ + switch (input) {\ + case '0' ... '9':\ + case '-':\ + break;\ + default:\ + state++;\ + break;\ }\ - if(state == VMON_PARSER_STATE_ ## _sym) {\ + if (state == VMON_PARSER_STATE_ ## _sym)\ /* we want to fall-through when the state advances */\ - break;\ - } + break; #endif -- cgit v1.2.3