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 /**   Prompt Management (Prompt)                                          */
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_prompt.h"
29 #include "gx_utility.h"
30 
31 /* Bring in externs for caller checking code.  */
32 GX_CALLER_CHECKING_EXTERNS
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _gxe_prompt_text_set                                PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Kenneth Maxwell, Microsoft Corporation                              */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function checks errors in the prompt text set function.        */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    prompt                                Pointer to prompt widget      */
51 /*                                            control block               */
52 /*    text                                  Pointer to text               */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    status                                Completion status             */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    _gx_prompt_text_set                   The actual function           */
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    Application Code                                                    */
65 /*                                                                        */
66 /*  RELEASE HISTORY                                                       */
67 /*                                                                        */
68 /*    DATE              NAME                      DESCRIPTION             */
69 /*                                                                        */
70 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
71 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
72 /*                                            resulting in version 6.1    */
73 /*                                                                        */
74 /**************************************************************************/
75 #if defined(GX_ENABLE_DEPRECATED_STRING_API)
_gxe_prompt_text_set(GX_PROMPT * prompt,GX_CONST GX_CHAR * text)76 UINT  _gxe_prompt_text_set(GX_PROMPT *prompt, GX_CONST GX_CHAR *text)
77 {
78 UINT status;
79 
80     /* Check for appropriate caller.  */
81     GX_INIT_AND_THREADS_CALLER_CHECKING
82 
83     /* Check error for valid pointer. */
84     if (prompt == GX_NULL)
85     {
86         return(GX_PTR_ERROR);
87     }
88 
89     /* Call the actual function.  */
90     status = _gx_prompt_text_set(prompt, text);
91 
92     /* Return completion status.  */
93     return(status);
94 }
95 #endif
96 
97 /**************************************************************************/
98 /*                                                                        */
99 /*  FUNCTION                                               RELEASE        */
100 /*                                                                        */
101 /*    _gxe_prompt_text_set_ext                            PORTABLE C      */
102 /*                                                           6.1          */
103 /*  AUTHOR                                                                */
104 /*                                                                        */
105 /*    Kenneth Maxwell, Microsoft Corporation                              */
106 /*                                                                        */
107 /*  DESCRIPTION                                                           */
108 /*                                                                        */
109 /*    This function checks errors in the prompt text set function.        */
110 /*                                                                        */
111 /*  INPUT                                                                 */
112 /*                                                                        */
113 /*    prompt                                Pointer to prompt widget      */
114 /*                                            control block               */
115 /*    text                                  Pointer to text               */
116 /*                                                                        */
117 /*  OUTPUT                                                                */
118 /*                                                                        */
119 /*    status                                Completion status             */
120 /*                                                                        */
121 /*  CALLS                                                                 */
122 /*                                                                        */
123 /*    _gx_prompt_text_set_ext               The actual function           */
124 /*                                                                        */
125 /*  CALLED BY                                                             */
126 /*                                                                        */
127 /*    Application Code                                                    */
128 /*                                                                        */
129 /*  RELEASE HISTORY                                                       */
130 /*                                                                        */
131 /*    DATE              NAME                      DESCRIPTION             */
132 /*                                                                        */
133 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
134 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
135 /*                                            resulting in version 6.1    */
136 /*                                                                        */
137 /**************************************************************************/
_gxe_prompt_text_set_ext(GX_PROMPT * prompt,GX_CONST GX_STRING * text)138 UINT _gxe_prompt_text_set_ext(GX_PROMPT *prompt, GX_CONST GX_STRING *text)
139 {
140 UINT status;
141 UINT text_length = 0;
142 
143     /* Check for appropriate caller.  */
144     GX_INIT_AND_THREADS_CALLER_CHECKING
145 
146     /* Check error for valid pointer. */
147     if (prompt == GX_NULL)
148     {
149         return(GX_PTR_ERROR);
150     }
151 
152     if (text)
153     {
154         if (text -> gx_string_ptr)
155         {
156             status = _gx_utility_string_length_check(text -> gx_string_ptr, &text_length, text -> gx_string_length);
157 
158             if (status != GX_SUCCESS)
159             {
160                 return status;
161             }
162         }
163 
164         if (text_length != text -> gx_string_length)
165         {
166             return GX_INVALID_STRING_LENGTH;
167         }
168     }
169 
170     /* Call the actual function.  */
171     status = _gx_prompt_text_set_ext(prompt, text);
172 
173     /* Return completion status.  */
174     return(status);
175 }
176 
177