GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_display_string_get.c Lines: 42 42 100.0 %
Date: 2024-12-05 08:52:37 Branches: 32 32 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 *
4
 * This program and the accompanying materials are made available under the
5
 * terms of the MIT License which is available at
6
 * https://opensource.org/licenses/MIT.
7
 *
8
 * SPDX-License-Identifier: MIT
9
 **************************************************************************/
10
11
12
/**************************************************************************/
13
/**************************************************************************/
14
/**                                                                       */
15
/** GUIX Component                                                        */
16
/**                                                                       */
17
/**   System Management (System)                                          */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_system.h"
28
#include "gx_display.h"
29
#include "gx_utility.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _gx_display_string_get                              PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Kenneth Maxwell, Microsoft Corporation                              */
41
/*                                                                        */
42
/*  DESCRIPTION  (deprecated)                                             */
43
/*                                                                        */
44
/*    This service return the string associated with the specified string */
45
/*    ID.                                                                 */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    display                               Pointer to display instance   */
50
/*    string_id                             String resource ID            */
51
/*    return_string                         Pointer to return string      */
52
/*                                            pointer                     */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    status                                Completion status             */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    None                                                                */
61
/*                                                                        */
62
/*  CALLED BY                                                             */
63
/*                                                                        */
64
/*    Application Code                                                    */
65
/*    _gx_context_string_get                                              */
66
/*    _gx_widget_string_get                 Drew the text onto the wdiget */
67
/*                                                                        */
68
/*  RELEASE HISTORY                                                       */
69
/*                                                                        */
70
/*    DATE              NAME                      DESCRIPTION             */
71
/*                                                                        */
72
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
73
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
74
/*                                            resulting in version 6.1    */
75
/*                                                                        */
76
/**************************************************************************/
77
#if defined(GX_ENABLE_DEPRECATED_STRING_API)
78
106
UINT  _gx_display_string_get(GX_DISPLAY *display, GX_RESOURCE_ID string_id, GX_CONST GX_CHAR **return_string)
79
{
80
106
UINT              status = GX_SUCCESS;
81
GX_RESOURCE_ID    string_table_size;
82
106
GX_CONST GX_CHAR *string_ptr = GX_NULL;
83
INT               language;
84
85
    /* Pickup size of string table.  */
86
106
    string_table_size =  display -> gx_display_string_table_size;
87
88
    /* Check to make sure the string ID is valid.  */
89
106
    if(string_id >= string_table_size)
90
    {
91
7
        status = GX_INVALID_RESOURCE_ID;
92
    }
93
99
    else if (string_id > 0)
94
    {
95
        /* Setup return string pointer associated with this ID.  */
96
        /* first try the active language */
97
98
        language = display -> gx_display_active_language;
98
98
        if (display -> gx_display_language_table)
99
        {
100
5
            string_ptr = display -> gx_display_language_table[language][string_id].gx_string_ptr;
101

5
            if (language && string_ptr == GX_NULL)
102
            {
103
                /* If active language string is NULL, return reference language string */
104
1
                string_ptr = display -> gx_display_language_table[0][string_id].gx_string_ptr;
105
            }
106
        }
107
        else
108
        {
109
93
            if (display -> gx_display_language_table_deprecated)
110
            {
111
92
                string_ptr = display -> gx_display_language_table_deprecated[language][string_id];
112

92
                if (language && string_ptr == GX_NULL)
113
                {
114
                    /* If active language string is NULL, return reference language string */
115
1
                    string_ptr = display -> gx_display_language_table_deprecated[0][string_id];
116
                }
117
            }
118
        }
119
    }
120
121
106
    *return_string = string_ptr;
122
106
    return status;
123
}
124
#endif
125
126
/**************************************************************************/
127
/*                                                                        */
128
/*  FUNCTION                                               RELEASE        */
129
/*                                                                        */
130
/*    _gx_display_string_get_ext                          PORTABLE C      */
131
/*                                                           6.1          */
132
/*  AUTHOR                                                                */
133
/*                                                                        */
134
/*    Kenneth Maxwell, Microsoft Corporation                              */
135
/*                                                                        */
136
/*  DESCRIPTION                                                           */
137
/*                                                                        */
138
/*    This service return the string associated with the specified string */
139
/*    ID.                                                                 */
140
/*                                                                        */
141
/*  INPUT                                                                 */
142
/*                                                                        */
143
/*    display                               Pointer to display instance   */
144
/*    string_id                             String resource ID            */
145
/*    return_string                         Pointer to return string      */
146
/*                                            pointer                     */
147
/*                                                                        */
148
/*  OUTPUT                                                                */
149
/*                                                                        */
150
/*    status                                Completion status             */
151
/*                                                                        */
152
/*  CALLS                                                                 */
153
/*                                                                        */
154
/*    None                                                                */
155
/*                                                                        */
156
/*  CALLED BY                                                             */
157
/*                                                                        */
158
/*    Application Code                                                    */
159
/*    _gx_context_string_get                                              */
160
/*    _gx_widget_string_get                 Drew the text onto the wdiget */
161
/*                                                                        */
162
/*  RELEASE HISTORY                                                       */
163
/*                                                                        */
164
/*    DATE              NAME                      DESCRIPTION             */
165
/*                                                                        */
166
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
167
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
168
/*                                            resulting in version 6.1    */
169
/*                                                                        */
170
/**************************************************************************/
171
791817
UINT  _gx_display_string_get_ext(GX_DISPLAY *display, GX_RESOURCE_ID string_id, GX_STRING *return_string)
172
{
173
GX_RESOURCE_ID string_table_size;
174
GX_STRING      string;
175
INT            language;
176
791817
UINT           status = GX_SUCCESS;
177
178
#if defined(GX_ENABLE_DEPRECATED_STRING_API)
179
GX_CONST GX_CHAR *old_string;
180
UINT              string_length;
181
#endif
182
183
791817
    string.gx_string_ptr = GX_NULL;
184
791817
    string.gx_string_length = 0;
185
186
#if defined(GX_ENABLE_DEPRECATED_STRING_API)
187
    /* If application is used the deprecated API to assign string table,
188
       convert to GX_STRING here
189
    */
190
791817
    if (display -> gx_display_language_table_deprecated)
191
    {
192
96
        status = _gx_display_string_get(display, string_id, &old_string);
193
96
        if (status == GX_SUCCESS)
194
        {
195
90
            status = _gx_utility_string_length_check(old_string, &string_length, GX_MAX_STRING_LENGTH);
196
90
            if (status == GX_SUCCESS)
197
            {
198
64
                string.gx_string_length = string_length;
199
64
                string.gx_string_ptr = old_string;
200
            }
201
        }
202
96
        *return_string = string;
203
96
        return status;
204
    }
205
#endif
206
207
    /* Pickup size of string table.  */
208
791721
    string_table_size =  display -> gx_display_string_table_size;
209
210
    /* Check to make sure the string ID is valid.  */
211
791721
    if(string_id >= string_table_size)
212
    {
213
7
        status = GX_INVALID_RESOURCE_ID;
214
    }
215
791714
    else if(string_id > 0)
216
    {
217
791709
        if (display -> gx_display_language_table)
218
        {
219
            /* Setup return string pointer associated with this ID.  */
220
            /* first try the active language */
221
791708
            language = display -> gx_display_active_language;
222
791708
            string = display -> gx_display_language_table[language][string_id];
223
224

791708
            if (language && string.gx_string_ptr == GX_NULL)
225
            {
226
                /* If active language string is NULL, return reference language string */
227
2742
                string = display -> gx_display_language_table[0][string_id];
228
            }
229
        }
230
    }
231
232
791721
    *return_string = string;
233
791721
    return status;
234
}