MCPcopy Create free account
hub / github.com/cgsecurity/testdisk / wmenuUpdate

Function wmenuUpdate

src/intrfn.c:165–273  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163 */
164
165static int wmenuUpdate(WINDOW *window, const int yinfo, int y, int x, const struct MenuItem *menuItems, const unsigned int itemLength, const char *available, const int menuType, unsigned int current)
166{
167 unsigned int i;
168 const unsigned int lmargin = x;
169 const unsigned int ymargin = y;
170 unsigned int lenNameMax=0;
171 for( i = 0; menuItems[i].key!=0; i++ )
172 if(strchr(available, menuItems[i].key)!=NULL )
173 {
174 const unsigned int lenName = strlen( menuItems[i].name );
175 if(lenNameMax<lenName && lenName < itemLength)
176 lenNameMax=lenName;
177 }
178 /* Print available buttons */
179 for( i = 0; menuItems[i].key!=0; i++ )
180 {
181 char buff[80];
182 unsigned int lenName;
183 const char *mi;
184 wmove(window, y, x );
185 wclrtoeol(window);
186
187 /* Search next available button */
188 while( menuItems[i].key!=0 && strchr(available, menuItems[i].key)==NULL )
189 {
190 i++;
191 }
192 if( menuItems[i].key==0 ) break; /* No more menu items */
193
194 /* If selected item is not available and we have bypassed it,
195 make current item selected */
196 if( current < i && menuItems[current].key < 0 ) current = i;
197
198 mi = menuItems[i].name;
199 lenName = strlen( mi );
200 if(lenName>=sizeof(buff))
201 {
202 log_critical("\nBUG: %s\n",mi);
203 }
204 if(lenName >= itemLength)
205 {
206 if( menuType & MENU_BUTTON )
207 snprintf(buff, sizeof(buff)," [%s]",mi);
208 else
209 snprintf(buff, sizeof(buff)," %s",mi);
210 }
211 else
212 {
213 if( menuType & MENU_BUTTON )
214 {
215 if(menuType & MENU_VERT)
216 snprintf( buff, sizeof(buff)," [%*s%-*s]", (itemLength - lenNameMax) / 2, "",
217 (itemLength - lenNameMax + 1) / 2 + lenNameMax, mi );
218 else
219 snprintf( buff, sizeof(buff)," [%*s%-*s]", (itemLength - lenName) / 2, "",
220 (itemLength - lenName + 1) / 2 + lenName, mi );
221 }
222 else

Callers 1

wmenuSelect_extFunction · 0.85

Calls 1

snprintfFunction · 0.85

Tested by

no test coverage detected