#%TITLE% hg.mac
#%NAME%
#
#%CATEGORY%
#%DESCRIPTION%
#
#%EXAMPLE%
#%DL%
#%DT%XXXsetup%DD%
#%SETUP%
#%UL%
#%LI%
#%XUL%
need spec_utils
global HG_PAR[]
# arg danger multi load !!!
list_test "HG_PAR"
######################################################################
############################## ##############################
############################## CONFIG ##############################
############################## ##############################
######################################################################
#%UU% (<module>, <info_style>, <debug_style>, <error_style>)
#%MDESC%
#
def hg_config_style(module, info_style, debug_style, error_style) '{
list_add(HG_PAR, module)
# info style test.
if (is_number_in_range(info_style, 0, 5)){
list_setpar(HG_PAR, module, "info", info_style)
}
else{
printf("Error in info style selection for module \"%s\" (0..5)", module)
list_setpar(HG_PAR, module, "info", 0)
}
# debug style test.
if (is_number_in_range(debug_style, 0, 5)){
list_setpar(HG_PAR, module, "debug", debug_style)
}
else{
printf("Error in debug style selection for module \"%s\" (0..5)", module)
list_setpar(HG_PAR, module, "debug", 0)
}
# error style test.
if (is_number_in_range(error_style, 0, 5)){
list_setpar(HG_PAR, module, "error", error_style)
}
else{
printf("Error in error style selection for module \"%s\" (0..5)", module)
list_setpar(HG_PAR, module, "error", 0)
}
}'
#%UU% (<module>, <info_indent>, <debug_indent>, <error_indent>)
#%MDESC%
#
def hg_config_indent(module, info_indent, debug_indent, error_indent) '{
list_add(HG_PAR, module)
list_setpar(HG_PAR, module, "info_indent", info_indent)
list_setpar(HG_PAR, module, "debug_indent", debug_indent)
list_setpar(HG_PAR, module, "error_indent", error_indent)
}'
#%UU% (<module>, <info_header>, <debug_header>, <error_header>)
#%MDESC%
#
def hg_config_headers(module, info_header, debug_header, error_header) '{
list_add(HG_PAR, module)
list_setpar(HG_PAR, module, "info_header", info_header)
list_setpar(HG_PAR, module, "debug_header", debug_header)
list_setpar(HG_PAR, module, "error_header", error_header)
}'
######################################################################
############################### ###############################
############################### HELP ###############################
############################### ###############################
######################################################################
#def ttttt() '{
# hg_generate("HG_EXAMPLE_DEFAULT")
#}'
#eval("ttttt()")
def hg_example '{
print " ---------------- HG.MAC -----------------------------------"
print " hg.mac is an info/debug/error messages functions generator."
print " # Example of configuration:"
print " # Just Replace \"toto\" by your module name"
print " # Messages styles configuration."
print " [hg_config_style(\"toto\", 2, 3, 4)]"
print " [hg_config_indent(\"toto\", 0, 0, 1)]"
print " [hg_config_headers(\"toto\", \"TOTO\", \"TOTO\", \"TOTO\")]"
print " # all config are optionals."
print " # (2,5,2) are the default styles numbers"
print " # hg_generate() is the only mandatory call"
print " hg_generate(\"toto\")"
print " "
print " "
HG_EXAMPLE_DEFAULT_debug 1
print " "
print " example with \"hg_generate(\"HG_EXAMPLE_DEFAULT\") \" "
HG_EXAMPLE_DEFAULT_dbg("DDDddd")
HG_EXAMPLE_DEFAULT_err("EEEeee")
HG_EXAMPLE_DEFAULT_msg("MMMmmm")
print " "
print " "
}'
######################################################################
####################### #######################
####################### FUNCTIONS GENERATION #######################
####################### #######################
######################################################################
#%UU% (<module>)
#%MDESC%
#
def hg_generate(module) '{
# printf("[HG] : Generation of functions : %s_msg() %s_dbg() %s_err() %s_debug\n", module, module, module, module )
# HEADERS
if(list_getpar(HG_PAR, module, "info_header")==-1){
#printf ("no HG header defined, using default ones : module name : %s\n", module)
hg_config_headers(module, module, module, module)
}
# STYLES
if (list_getpar(HG_PAR, module, "info")==-1){
# no style defined ? then use default one:
hg_config_style(module, 2, 5, 2)
}
hg_generate_debug(module)
hg_generate_msg(module)
hg_generate_dbg(module)
hg_generate_err(module)
}'
def hg_generate_debug(module) '{
local _cmd
_cmd = sprintf( "rdef %s_debug \\\'{ \n \
local _d_on_off \n \
if( \$# ){ \n \
if ($1){ \n \
_d_on_off = 1 \n \
} \n \
else{ \n \
_d_on_off = 0 \n \
} \n \
} \n \
else{ \n \
if(list_getpar(HG_PAR, \"%s\", \"debug_on\")) { \n \
_d_on_off = 0 \n \
} \n \
else{ \n \
_d_on_off = 1 \n \
} \n \
} \n \
\n \
list_setpar(HG_PAR, \"%s\", \"debug_on\", _d_on_off) \n \
printf(\"%s DEBUG is now \") \n \
cprint_on_off(_d_on_off) \n \
print \n \
}\\\' \
", module, module, module, module, module )
eval( _cmd)
# set debug off by default.
list_setpar(HG_PAR, module, "debug_on", 0)
}'
def hg_generate_msg(module) '{
local _cmd
_cmd = sprintf( "rdef %s_msg(info_msg) \\\'{ \n \
local _msg _style _fg _bg _bold _indent_fmt _indent _header
_indent_fmt = sprintf(\"%%%%%%ds\", list_getpar(HG_PAR, \"%s\", \"info_indent\"))
_indent = sprintf(_indent_fmt, \"\")
_header = list_getpar(HG_PAR, \"%s\", \"info_header\")
_msg = sprintf(\"%%s[%%s][%%s] : %%s\\n\", _indent, _header, \"INFO\", info_msg)
_style = list_getpar(HG_PAR, \"%s\", \"info\")
_fg = HG_INFO_STYLE[_style][\"fg\"]
_bg = HG_INFO_STYLE[_style][\"bg\"]
_bold = HG_INFO_STYLE[_style][\"bold\"]
cprint(_msg, _fg ,_bg, _bold)
}\\\' \
", module, module, module, module)
eval( _cmd)
}'
def hg_generate_dbg(module) '{
local _cmd
_cmd = sprintf( "rdef %s_dbg(dbg_msg) \\\'{ \n \
local _msg _style _fg _bg _bold _indent_fmt _indent _header
if(list_getpar(HG_PAR, \"%s\", \"debug_on\")){
_indent_fmt = sprintf(\"%%%%%%ds\", list_getpar(HG_PAR, \"%s\", \"debug_indent\"))
_indent = sprintf(_indent_fmt, \"\")
_header = list_getpar(HG_PAR, \"%s\", \"debug_header\")
_msg = sprintf(\"%%s[%%s][%%s] : %%s\\n\", _indent,_header, \"DEBUG\", dbg_msg)
_style = list_getpar(HG_PAR, \"%s\", \"debug\")
_fg = HG_DEBUG_STYLE[_style][\"fg\"]
_bg = HG_DEBUG_STYLE[_style][\"bg\"]
_bold = HG_DEBUG_STYLE[_style][\"bold\"]
cprint(_msg, _fg ,_bg, _bold)
}
}\\\' \
", module, module, module, module, module)
eval( _cmd)
}'
def hg_generate_err(module) '{
local _cmd
_cmd = sprintf( "rdef %s_err(err_msg) \\\'{ \n \
local _msg _style _fg _bg _bold _indent_fmt _indent _header
_indent_fmt = sprintf(\"%%%%%%ds\", list_getpar(HG_PAR, \"%s\", \"error_indent\"))
_indent = sprintf(_indent_fmt, \"\")
_header = list_getpar(HG_PAR, \"%s\", \"error_header\")
_msg = sprintf(\"%%s[%%s][%%s][%%s] : %%s\n\", _indent, _header, \"ERROR\", date_stamping_second(), err_msg)
_style = list_getpar(HG_PAR, \"%s\", \"error\")
_fg = HG_ERROR_STYLE[_style][\"fg\"]
_bg = HG_ERROR_STYLE[_style][\"bg\"]
_bold = HG_ERROR_STYLE[_style][\"bold\"]
ceprint(_msg, _fg ,_bg, _bold)
}\\\' \
", module, module, module, module)
eval( _cmd)
}'
######################################################################
######################### ########################
######################### STYLES DEFINITION ########################
######################### ########################
######################################################################
def hg_show_styles '{
for (ii = 0 ; ii < 6 ; ii++){
cprint(sprintf("[EXAMPLE][%d][INFO] : exemple de msg dinfo\n", ii), \
HG_INFO_STYLE[ii]["fg"], \
HG_INFO_STYLE[ii]["bg"], \
HG_INFO_STYLE[ii]["bold"])
}
print ""
for (ii = 0 ; ii < 6 ; ii++){
cprint(sprintf("[EXAMPLE][%d][DEBUG] : exemple de msg de debug\n", ii), \
HG_DEBUG_STYLE[ii]["fg"], \
HG_DEBUG_STYLE[ii]["bg"], \
HG_DEBUG_STYLE[ii]["bold"])
}
print ""
for (ii = 0 ; ii < 6 ; ii++){
cprint(sprintf("[EXAMPLE][%d][ERROR] : exemple de msg derreur\n", ii), \
HG_ERROR_STYLE[ii]["fg"], \
HG_ERROR_STYLE[ii]["bg"], \
HG_ERROR_STYLE[ii]["bold"])
}
}'
global HG_INFO_STYLE[]
HG_INFO_STYLE[0]["fg"] = 2
HG_INFO_STYLE[0]["bg"] = 8
HG_INFO_STYLE[0]["bold"] = 0
HG_INFO_STYLE[1]["fg"] = 3
HG_INFO_STYLE[1]["bg"] = 8
HG_INFO_STYLE[1]["bold"] = 1
HG_INFO_STYLE[2]["fg"] = 4
HG_INFO_STYLE[2]["bg"] = 8
HG_INFO_STYLE[2]["bold"] = 1
HG_INFO_STYLE[3]["fg"] = 5
HG_INFO_STYLE[3]["bg"] = 8
HG_INFO_STYLE[3]["bold"] = 1
HG_INFO_STYLE[4]["fg"] = 6
HG_INFO_STYLE[4]["bg"] = 8
HG_INFO_STYLE[4]["bold"] = 1
HG_INFO_STYLE[5]["fg"] = 7
HG_INFO_STYLE[5]["bg"] = 8
HG_INFO_STYLE[5]["bold"] = 1
HG_INFO_STYLE["nb_styles"] = 6
######################################################################
global HG_DEBUG_STYLE[]
HG_DEBUG_STYLE[0]["fg"] = 0
HG_DEBUG_STYLE[0]["bg"] = 7
HG_DEBUG_STYLE[0]["bold"] = 0
HG_DEBUG_STYLE[1]["fg"] = 2
HG_DEBUG_STYLE[1]["bg"] = 7
HG_DEBUG_STYLE[1]["bold"] = 0
HG_DEBUG_STYLE[2]["fg"] = 3
HG_DEBUG_STYLE[2]["bg"] = 7
HG_DEBUG_STYLE[2]["bold"] = 0
HG_DEBUG_STYLE[3]["fg"] = 4
HG_DEBUG_STYLE[3]["bg"] = 7
HG_DEBUG_STYLE[3]["bold"] = 0
HG_DEBUG_STYLE[4]["fg"] = 6
HG_DEBUG_STYLE[4]["bg"] = 7
HG_DEBUG_STYLE[4]["bold"] = 0
HG_DEBUG_STYLE[5]["fg"] = 7
HG_DEBUG_STYLE[5]["bg"] = 7
HG_DEBUG_STYLE[5]["bold"] = 0
HG_DEBUG_STYLE["nb_styles"] = 6
######################################################################
global HG_ERROR_STYLE[]
HG_ERROR_STYLE[0]["fg"] = 0
HG_ERROR_STYLE[0]["bg"] = 1
HG_ERROR_STYLE[0]["bold"] = 0
HG_ERROR_STYLE[1]["fg"] = 2
HG_ERROR_STYLE[1]["bg"] = 1
HG_ERROR_STYLE[1]["bold"] = 0
HG_ERROR_STYLE[2]["fg"] = 3
HG_ERROR_STYLE[2]["bg"] = 1
HG_ERROR_STYLE[2]["bold"] = 1
HG_ERROR_STYLE[3]["fg"] = 4
HG_ERROR_STYLE[3]["bg"] = 1
HG_ERROR_STYLE[3]["bold"] = 1
HG_ERROR_STYLE[4]["fg"] = 6
HG_ERROR_STYLE[4]["bg"] = 1
HG_ERROR_STYLE[4]["bold"] = 1
HG_ERROR_STYLE[5]["fg"] = 7
HG_ERROR_STYLE[5]["bg"] = 1
HG_ERROR_STYLE[5]["bold"] = 1
HG_ERROR_STYLE["nb_styles"] = 6
|