17
17
* and Technology (RIST). All rights reserved.
18
18
* Copyright (c) 2017-2022 IBM Corporation. All rights reserved.
19
19
* 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.
20
22
* $COPYRIGHT$
21
23
*
22
24
* Additional copyrights may follow
@@ -46,7 +48,8 @@ static void mca_base_var_enum_flag_destructor(mca_base_var_enum_flag_t *enumerat
46
48
static OBJ_CLASS_INSTANCE (mca_base_var_enum_flag_t , opal_object_t ,
47
49
mca_base_var_enum_flag_constructor , mca_base_var_enum_flag_destructor ) ;
48
50
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 );
50
53
static int enum_get_count (mca_base_var_enum_t * self , int * count );
51
54
static int enum_get_value (mca_base_var_enum_t * self , int index , int * value ,
52
55
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
109
112
return OPAL_SUCCESS ;
110
113
}
111
114
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 )
113
117
{
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 ;
116
146
}
117
147
118
148
mca_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
199
229
return OPAL_SUCCESS ;
200
230
}
201
231
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 )
203
234
{
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 ;
206
266
}
207
267
208
268
mca_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
284
344
return OPAL_SUCCESS ;
285
345
}
286
346
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 )
288
349
{
289
350
char * tmp ;
290
351
int ret ;
291
352
292
- ret = enum_dump (self , out );
353
+ char * color_vv = "" , * color_reset = "" ;
354
+
355
+ ret = enum_dump (self , out , output_type );
293
356
if (OPAL_SUCCESS != ret ) {
294
357
return ret ;
295
358
}
296
359
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 );
298
368
free (* out );
299
369
if (0 > ret ) {
300
370
* out = NULL ;
@@ -408,22 +478,32 @@ int mca_base_var_enum_create_flag(const char *name, const mca_base_var_enum_valu
408
478
return OPAL_SUCCESS ;
409
479
}
410
480
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 )
412
483
{
413
484
int i ;
414
485
char * tmp ;
415
486
int ret ;
416
487
488
+ char * color_vv = "" , * color_reset = "" ;
489
+
417
490
* out = NULL ;
418
491
419
492
if (NULL == self ) {
420
493
return OPAL_ERROR ;
421
494
}
422
495
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
+
423
501
tmp = NULL ;
424
502
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 );
427
507
if (tmp ) {
428
508
free (tmp );
429
509
}
@@ -691,18 +771,26 @@ static int enum_string_from_value_flag(mca_base_var_enum_t *self, const int valu
691
771
return OPAL_SUCCESS ;
692
772
}
693
773
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 )
695
776
{
696
777
mca_base_var_enum_flag_t * flag_enum = (mca_base_var_enum_flag_t * ) self ;
697
778
char * tmp ;
698
779
int ret ;
699
780
781
+ char * color_vv = "" , * color_reset = "" ;
782
+
700
783
* out = NULL ;
701
784
702
785
if (NULL == self ) {
703
786
return OPAL_ERROR ;
704
787
}
705
788
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
+
706
794
* out = strdup ("Comma-delimited list of: " );
707
795
if (NULL == * out ) {
708
796
return OPAL_ERR_OUT_OF_RESOURCE ;
@@ -711,8 +799,10 @@ static int enum_dump_flag(mca_base_var_enum_t *self, char **out)
711
799
for (int i = 0 ; i < self -> enum_value_count ; ++ i ) {
712
800
tmp = * out ;
713
801
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 );
716
806
free (tmp );
717
807
if (0 > ret ) {
718
808
return OPAL_ERR_OUT_OF_RESOURCE ;
0 commit comments