1717 * and Technology (RIST). All rights reserved.
1818 * Copyright (c) 2017-2022 IBM Corporation. All rights reserved.
1919 * Copyright (c) 2018 Amazon.com, Inc. or its affiliates. All Rights reserved.
20+ * Copyright (c) 2022 Computer Architecture and VLSI Systems (CARV)
21+ * Laboratory, ICS Forth. All rights reserved.
2022 * $COPYRIGHT$
2123 *
2224 * Additional copyrights may follow
@@ -46,7 +48,8 @@ static void mca_base_var_enum_flag_destructor(mca_base_var_enum_flag_t *enumerat
4648static OBJ_CLASS_INSTANCE (mca_base_var_enum_flag_t , opal_object_t ,
4749 mca_base_var_enum_flag_constructor , mca_base_var_enum_flag_destructor ) ;
4850
49- static int enum_dump (mca_base_var_enum_t * self , char * * out );
51+ static int enum_dump (mca_base_var_enum_t * self , char * * out ,
52+ mca_base_var_enum_dump_type_t output_type );
5053static int enum_get_count (mca_base_var_enum_t * self , int * count );
5154static int enum_get_value (mca_base_var_enum_t * self , int index , int * value ,
5255 const char * * string_value );
@@ -109,10 +112,37 @@ static int mca_base_var_enum_bool_sfv(mca_base_var_enum_t *self, const int value
109112 return OPAL_SUCCESS ;
110113}
111114
112- static int mca_base_var_enum_bool_dump (mca_base_var_enum_t * self , char * * out )
115+ static int mca_base_var_enum_bool_dump (mca_base_var_enum_t * self , char * * out ,
116+ mca_base_var_enum_dump_type_t output_type )
113117{
114- * out = strdup ("0: f|false|disabled|no|n, 1: t|true|enabled|yes|y" );
115- return * out ? OPAL_SUCCESS : OPAL_ERR_OUT_OF_RESOURCE ;
118+ int ret ;
119+ char * color_vv = "" , * color_reset = "" ;
120+
121+ if (MCA_BASE_VAR_ENUM_DUMP_READABLE_COLOR == output_type ) {
122+ color_vv = opal_var_dump_color [OPAL_VAR_DUMP_COLOR_VALID_VALUES ];
123+ color_reset = "\033[0m" ;
124+ }
125+
126+ ret = opal_asprintf (out , "%s0%s|%sf%s|%sfalse%s|%sdisabled%s|%sno%s|%sn%s, "
127+ "%s1%s|%st%s|%strue%s|%senabled%s|%syes%s|%sy%s" ,
128+ color_vv , color_reset ,
129+ color_vv , color_reset ,
130+ color_vv , color_reset ,
131+ color_vv , color_reset ,
132+ color_vv , color_reset ,
133+ color_vv , color_reset ,
134+ color_vv , color_reset ,
135+ color_vv , color_reset ,
136+ color_vv , color_reset ,
137+ color_vv , color_reset ,
138+ color_vv , color_reset ,
139+ color_vv , color_reset );
140+ if (ret < 0 ) {
141+ * out = NULL ;
142+ return OPAL_ERR_OUT_OF_RESOURCE ;
143+ }
144+
145+ return OPAL_SUCCESS ;
116146}
117147
118148mca_base_var_enum_t mca_base_var_enum_bool = {.super = OPAL_OBJ_STATIC_INIT (opal_object_t ),
@@ -199,10 +229,40 @@ static int mca_base_var_enum_auto_bool_sfv(mca_base_var_enum_t *self, const int
199229 return OPAL_SUCCESS ;
200230}
201231
202- static int mca_base_var_enum_auto_bool_dump (mca_base_var_enum_t * self , char * * out )
232+ static int mca_base_var_enum_auto_bool_dump (mca_base_var_enum_t * self , char * * out ,
233+ mca_base_var_enum_dump_type_t output_type )
203234{
204- * out = strdup ("-1: auto, 0: f|false|disabled|no|n, 1: t|true|enabled|yes|y" );
205- return * out ? OPAL_SUCCESS : OPAL_ERR_OUT_OF_RESOURCE ;
235+ int ret ;
236+ char * color_vv = "" , * color_reset = "" ;
237+
238+ if (MCA_BASE_VAR_ENUM_DUMP_READABLE_COLOR == output_type ) {
239+ color_vv = opal_var_dump_color [OPAL_VAR_DUMP_COLOR_VALID_VALUES ];
240+ color_reset = "\033[0m" ;
241+ }
242+
243+ ret = opal_asprintf (out , "%s-1%s|%sauto%s, "
244+ "%s0%s|%sf%s|%sfalse%s|%sdisabled%s|%sno%s|%sn%s, "
245+ "%s1%s|%st%s|%strue%s|%senabled%s|%syes%s|%sy%s" ,
246+ color_vv , color_reset ,
247+ color_vv , color_reset ,
248+ color_vv , color_reset ,
249+ color_vv , color_reset ,
250+ color_vv , color_reset ,
251+ color_vv , color_reset ,
252+ color_vv , color_reset ,
253+ color_vv , color_reset ,
254+ color_vv , color_reset ,
255+ color_vv , color_reset ,
256+ color_vv , color_reset ,
257+ color_vv , color_reset ,
258+ color_vv , color_reset ,
259+ color_vv , color_reset );
260+ if (ret < 0 ) {
261+ * out = NULL ;
262+ return OPAL_ERR_OUT_OF_RESOURCE ;
263+ }
264+
265+ return OPAL_SUCCESS ;
206266}
207267
208268mca_base_var_enum_t mca_base_var_enum_auto_bool
@@ -284,17 +344,27 @@ static int mca_base_var_enum_verbose_sfv(mca_base_var_enum_t *self, const int va
284344 return OPAL_SUCCESS ;
285345}
286346
287- static int mca_base_var_enum_verbose_dump (mca_base_var_enum_t * self , char * * out )
347+ static int mca_base_var_enum_verbose_dump (mca_base_var_enum_t * self , char * * out ,
348+ mca_base_var_enum_dump_type_t output_type )
288349{
289350 char * tmp ;
290351 int ret ;
291352
292- ret = enum_dump (self , out );
353+ char * color_vv = "" , * color_reset = "" ;
354+
355+ ret = enum_dump (self , out , output_type );
293356 if (OPAL_SUCCESS != ret ) {
294357 return ret ;
295358 }
296359
297- ret = opal_asprintf (& tmp , "%s, 0 - 100" , * out );
360+ if (MCA_BASE_VAR_ENUM_DUMP_READABLE_COLOR == output_type ) {
361+ color_vv = opal_var_dump_color [OPAL_VAR_DUMP_COLOR_VALID_VALUES ];
362+ color_reset = "\033[0m" ;
363+ }
364+
365+ ret = opal_asprintf (& tmp , "%s, %s0%s-%s100%s" , * out ,
366+ color_vv , color_reset ,
367+ color_vv , color_reset );
298368 free (* out );
299369 if (0 > ret ) {
300370 * out = NULL ;
@@ -408,22 +478,32 @@ int mca_base_var_enum_create_flag(const char *name, const mca_base_var_enum_valu
408478 return OPAL_SUCCESS ;
409479}
410480
411- static int enum_dump (mca_base_var_enum_t * self , char * * out )
481+ static int enum_dump (mca_base_var_enum_t * self , char * * out ,
482+ mca_base_var_enum_dump_type_t output_type )
412483{
413484 int i ;
414485 char * tmp ;
415486 int ret ;
416487
488+ char * color_vv = "" , * color_reset = "" ;
489+
417490 * out = NULL ;
418491
419492 if (NULL == self ) {
420493 return OPAL_ERROR ;
421494 }
422495
496+ if (MCA_BASE_VAR_ENUM_DUMP_READABLE_COLOR == output_type ) {
497+ color_vv = opal_var_dump_color [OPAL_VAR_DUMP_COLOR_VALID_VALUES ];
498+ color_reset = "\033[0m" ;
499+ }
500+
423501 tmp = NULL ;
424502 for (i = 0 ; i < self -> enum_value_count && self -> enum_values [i ].string ; ++ i ) {
425- ret = opal_asprintf (out , "%s%s%d:\"%s\"" , tmp ? tmp : "" , tmp ? ", " : "" ,
426- self -> enum_values [i ].value , self -> enum_values [i ].string );
503+ ret = opal_asprintf (out , "%s%s%s%d%s|%s%s%s" ,
504+ tmp ? tmp : "" , tmp ? ", " : "" ,
505+ color_vv , self -> enum_values [i ].value , color_reset ,
506+ color_vv , self -> enum_values [i ].string , color_reset );
427507 if (tmp ) {
428508 free (tmp );
429509 }
@@ -691,18 +771,26 @@ static int enum_string_from_value_flag(mca_base_var_enum_t *self, const int valu
691771 return OPAL_SUCCESS ;
692772}
693773
694- static int enum_dump_flag (mca_base_var_enum_t * self , char * * out )
774+ static int enum_dump_flag (mca_base_var_enum_t * self , char * * out ,
775+ mca_base_var_enum_dump_type_t output_type )
695776{
696777 mca_base_var_enum_flag_t * flag_enum = (mca_base_var_enum_flag_t * ) self ;
697778 char * tmp ;
698779 int ret ;
699780
781+ char * color_vv = "" , * color_reset = "" ;
782+
700783 * out = NULL ;
701784
702785 if (NULL == self ) {
703786 return OPAL_ERROR ;
704787 }
705788
789+ if (MCA_BASE_VAR_ENUM_DUMP_READABLE_COLOR == output_type ) {
790+ color_vv = opal_var_dump_color [OPAL_VAR_DUMP_COLOR_VALID_VALUES ];
791+ color_reset = "\033[0m" ;
792+ }
793+
706794 * out = strdup ("Comma-delimited list of: " );
707795 if (NULL == * out ) {
708796 return OPAL_ERR_OUT_OF_RESOURCE ;
@@ -711,8 +799,10 @@ static int enum_dump_flag(mca_base_var_enum_t *self, char **out)
711799 for (int i = 0 ; i < self -> enum_value_count ; ++ i ) {
712800 tmp = * out ;
713801
714- ret = opal_asprintf (out , "%s%s0x%x:\"%s\"" , tmp , i ? ", " : " " ,
715- flag_enum -> enum_flags [i ].flag , flag_enum -> enum_flags [i ].string );
802+ ret = opal_asprintf (out , "%s%s%s0x%x%s|%s%s%s" ,
803+ tmp , i ? ", " : " " ,
804+ color_vv , flag_enum -> enum_flags [i ].flag , color_reset ,
805+ color_vv , flag_enum -> enum_flags [i ].string , color_reset );
716806 free (tmp );
717807 if (0 > ret ) {
718808 return OPAL_ERR_OUT_OF_RESOURCE ;
0 commit comments