summaryrefslogtreecommitdiffstats
path: root/src/usr/errl/parser/errlusrparser.C
blob: 569b2202d5923c5c988e4dec267fe3d422b7d964 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//  IBM_PROLOG_BEGIN_TAG
//  This is an automatically generated prolog.
//
//  $Source: src/usr/errl/parser/errlusrparser.C $
//
//  IBM CONFIDENTIAL
//
//  COPYRIGHT International Business Machines Corp. 2011
//
//  p1
//
//  Object Code Only (OCO) source materials
//  Licensed Internal Code Source Materials
//  IBM HostBoot Licensed Internal Code
//
//  The source code for this program is not published or other-
//  wise divested of its trade secrets, irrespective of what has
//  been deposited with the U.S. Copyright Office.
//
//  Origin: 30
//
//  IBM_PROLOG_END
/**
 *  @file errlusrparser.C
 *
 *  @brief <Brief Description of this file>
 *
 *  <Detailed description of what this file does, functions it includes,
 *  etc,>
*/

/*****************************************************************************/
// I n c l u d e s
/*****************************************************************************/
#include <cstring>
#include <ctype.h>
#include <cstdarg>

#include <errl/parser/errlusrparser.H>

/*****************************************************************************/
//  Constant string defines
/*****************************************************************************/
const   char *  ERRL_MSG_UNKNOWN        =   "Unknown";
const   char *  ERRL_MSG_BOOL_TRUE      =   "True";
const   char *  ERRL_MSG_BOOL_FALSE     =   "False";
const   char *  ERRL_MSG_STR_ENABLED    =   "Enabled";
const   char *  ERRL_MSG_STR_DISABLED   =   "Disabled";


/*****************************************************************************/
// Send the label & return # of chars printed
/*****************************************************************************/
static int PrintLabel(
                     FILE *   i_stream,
                     const char * i_label
                     )
{
    if ( ! i_label )
    {
        i_label = "";
    }

    return fprintf(i_stream,"| %-25.25s: ",i_label);
}


/*****************************************************************************/
// Regular string ( may be multiline )
/*****************************************************************************/
void ErrlUsrParser::PrintString(
                               const char * i_label,
                               const char * i_string
                               )
{
    // Must make sure the string fits on the available width
    int l_strlen = 0;
    int l_printed = 0;


    // Ensure String is valid
    if ( i_string )
    {
        l_strlen = strlen( i_string );
    }

    // Fake a blank string
    if ( ! l_strlen )
    {
        l_strlen = 1;
        i_string = " ";
    }

    // Print it out
    while ( l_strlen > l_printed )
    {
        // Leader ( label or blanks )
        PrintLabel( iv_Stream, i_label );

        // label is only printed once
        i_label = "";

        l_printed += fprintf(
                            iv_Stream,
                            "%-50.50s",
                            i_string+l_printed
                            );

        fprintf(iv_Stream,"|\n");
    }
}
/*****************************************************************************/
// Numeric Print
/*****************************************************************************/
void ErrlUsrParser::PrintNumber(
                               const char * i_label,
                               const char * i_fmt,
                               uint32_t     i_value
                               ){
    ErrlParser::PrintNumber( i_label, i_fmt, i_value );
}


/*****************************************************************************/
// Hex Dump
/*****************************************************************************/
void ErrlUsrParser::PrintHexDump(
                                const void * i_data,
                                uint32_t     i_len
                                )
{
    uint32_t i = 0 ;
    uint32_t l_counter = 0;
    uint32_t l_written;
    uint8_t *l_data = (uint8_t*)i_data;

    while ( l_counter < i_len)
    {
        fprintf(iv_Stream,"|   %08X     ",l_counter);

        // Display 16 bytes in Hex with 2 spaces in between
        l_written = 0;
        for ( i = 0; i < 16 && l_counter < i_len; i++ )
        {
            l_written += fprintf(iv_Stream,"%02X",l_data[l_counter++]);

            if ( ! ( l_counter % 4 ) )
            {
                l_written += fprintf(iv_Stream,"  ");
            }
        }

        // Pad with spaces
        fprintf(iv_Stream,"%-*c",43-l_written,' ');

        // Display ASCII -- fk1
        l_written = 0;
        uint8_t l_char;
        for ( ; i > 0 ; i-- )
        {
            l_char = l_data[ l_counter-i ];

            if ( isprint( l_char ) &&
                 ( l_char != '&' ) &&
                 ( l_char != '<' ) &&
                 ( l_char != '>' )
               )
            {
                l_written += fprintf( iv_Stream,"%c",l_char );
            }
            else
            {
                l_written += fprintf( iv_Stream,"." );
            }
        }

        // Pad with spaces -- fk1
        fprintf( iv_Stream,"%-*c|\n",19-l_written,' ' );



    }
}


OpenPOWER on IntegriCloud