@@ -166,47 +166,54 @@ class Newt : public View {
166
166
167
167
auto cStrings = convertToNewtList (tempStrings);
168
168
169
- // goto implementation
170
- question:
171
- returnValue = newtWinMenu (const_cast <char *>(title),
172
- const_cast <char *>(message), m_suggestedWidth, m_flexDown, m_flexUp ,
173
- m_maxListHeight, const_cast <char **>(cStrings.data ()), &selector ,
174
- const_cast <char *>(TUIText::Buttons::ok),
175
- const_cast <char *>(TUIText::Buttons::cancel),
176
- const_cast <char *>(TUIText::Buttons::add),
177
- const_cast <char *>(TUIText::Buttons::remove),
178
- const_cast <char *>(TUIText::Buttons::help), nullptr );
169
+ bool stay = true ;
170
+ while (stay) {
171
+ returnValue = newtWinMenu (const_cast <char *>(title),
172
+ const_cast <char *>(message), m_suggestedWidth, m_flexDown,
173
+ m_flexUp, m_maxListHeight, const_cast <char **>(cStrings.data ()),
174
+ &selector, const_cast <char *>(TUIText::Buttons::ok),
175
+ const_cast <char *>(TUIText::Buttons::cancel),
176
+ const_cast <char *>(TUIText::Buttons::add),
177
+ const_cast <char *>(TUIText::Buttons::remove),
178
+ const_cast <char *>(TUIText::Buttons::help), nullptr );
179
179
180
- switch (returnValue) {
181
- case 0 :
182
- /* F12 is pressed, and we don't care; continue to case 1 */
183
- case 1 :
184
- return tempStrings;
185
- case 2 :
186
- abort ();
187
- break ;
188
- case 3 : { // add
189
- bool ret = addCallback (tempStrings);
190
- if (ret) {
191
- cStrings = convertToNewtList (tempStrings);
192
- goto question;
193
- } else {
180
+ stay = false ;
181
+
182
+ switch (returnValue) {
183
+ case 0 :
184
+ /* F12 is pressed, and we don't care; continue to case 1 */
185
+ case 1 :
194
186
return tempStrings;
187
+ case 2 :
188
+ abort ();
189
+ break ;
190
+ case 3 : { // add
191
+ bool ret = addCallback (tempStrings);
192
+ if (ret) {
193
+ cStrings = convertToNewtList (tempStrings);
194
+ stay = true ;
195
+ } else {
196
+ return tempStrings;
197
+ }
198
+ break ;
195
199
}
200
+ case 4 : // remove
201
+ if (selector >= 0 && selector < cStrings.size ()) {
202
+ tempStrings.erase (tempStrings.begin () + selector);
203
+ cStrings = convertToNewtList (tempStrings);
204
+ }
205
+ stay = true ;
206
+ break ;
207
+ case 5 :
208
+ this ->helpMessage (helpMessage);
209
+ stay = true ;
210
+ break ;
211
+ default :
212
+ __builtin_unreachable ();
196
213
}
197
- case 4 : // remove
198
- if (selector >= 0 && selector < cStrings.size ()) {
199
- tempStrings.erase (tempStrings.begin () + selector);
200
- cStrings = convertToNewtList (tempStrings);
201
- }
202
-
203
- goto question;
204
- case 5 :
205
- this ->helpMessage (helpMessage);
206
- goto question;
207
- default :
208
- __builtin_unreachable ();
209
214
}
215
+
216
+ __builtin_unreachable ();
210
217
}
211
218
212
219
template <std::ranges::range T>
@@ -226,55 +233,35 @@ class Newt : public View {
226
233
// Newt expects a NULL terminated array of C style strings
227
234
std::vector<const char *> cStrings = convertToNewtList (tempStrings);
228
235
229
- #if 1
230
- // goto implementation
231
- question:
232
- returnValue = newtWinMenu (const_cast <char *>(title),
233
- const_cast <char *>(message), m_suggestedWidth, m_flexDown, m_flexUp,
234
- m_maxListHeight, const_cast <char **>(cStrings.data ()), &selector,
235
- const_cast <char *>(TUIText::Buttons::ok),
236
- const_cast <char *>(TUIText::Buttons::cancel),
237
- const_cast <char *>(TUIText::Buttons::help), nullptr );
236
+ bool stay = true ;
238
237
239
- switch (returnValue) {
240
- case 0 :
241
- /* F12 is pressed, and we don't care; continue to case 1 */
242
- case 1 :
243
- return tempStrings[boost::lexical_cast<std::size_t >(selector)];
244
- case 2 :
245
- abort ();
246
- break ;
247
- case 3 :
248
- this ->helpMessage (helpMessage);
249
- goto question;
250
- default :
251
- __builtin_unreachable ();
252
- }
253
- #else
254
- // gotoless implementation
255
- for (;;) {
238
+ while (stay) {
256
239
returnValue = newtWinMenu (const_cast <char *>(title),
257
- const_cast<char*>(message), m_suggestedWidth, m_flexUp,
258
- m_flexDown, m_maxListHeight,
259
- const_cast<char**>(cStrings.data()), &selector,
260
- const_cast<char*>(TUIText::Buttons::ok),
240
+ const_cast <char *>(message), m_suggestedWidth, m_flexDown,
241
+ m_flexUp, m_maxListHeight, const_cast <char **>(cStrings.data ()),
242
+ &selector, const_cast <char *>(TUIText::Buttons::ok),
261
243
const_cast <char *>(TUIText::Buttons::cancel),
262
- const_cast<char*>(TUIText::Buttons::help), NULL);
244
+ const_cast <char *>(TUIText::Buttons::help), nullptr );
245
+ stay = false ;
263
246
264
247
switch (returnValue) {
265
248
case 0 :
266
249
/* F12 is pressed, and we don't care; continue to case 1 */
267
250
case 1 :
268
- return items[selector];
251
+ return tempStrings[boost::lexical_cast<std::size_t >(
252
+ selector)];
269
253
case 2 :
270
- abortInstall();
254
+ abort ();
255
+ break ;
271
256
case 3 :
272
257
this ->helpMessage (helpMessage);
273
- continue;
258
+ stay = true ;
259
+ break ;
260
+ default :
261
+ __builtin_unreachable ();
274
262
}
275
- break; // for (;;)
276
263
}
277
- # endif
264
+
278
265
__builtin_unreachable ();
279
266
}
280
267
@@ -328,40 +315,51 @@ class Newt : public View {
328
315
329
316
T returnArray;
330
317
331
- question:
332
- returnValue = newtWinEntries (const_cast <char *>(title),
333
- const_cast <char *>(message), m_suggestedWidth, m_flexDown, m_flexUp,
334
- m_dataWidth, field.get (), const_cast <char *>(TUIText::Buttons::ok),
335
- const_cast <char *>(TUIText::Buttons::cancel),
336
- const_cast <char *>(TUIText::Buttons::help), nullptr );
318
+ bool stay = true ;
337
319
338
- switch (returnValue) {
339
- case 0 :
340
- /* F12 is pressed, and we don't care; continue to case 1 */
341
- case 1 :
342
- // TODO: The view should now check for this, it's a passive view
343
- if (hasEmptyField (field.get ()))
344
- goto question;
345
-
346
- // FIXME: We forgot that we should return size_t sometimes and
347
- // that was triggering an exception on the presenter, so
348
- // basically the std::variant is useless here, we always
349
- // return std:string.
350
- for (std::size_t i = 0 ; field[i].text ; i++) {
351
- returnArray[i] = std::make_pair<std::string, std::string>(
352
- field[i].text , *field[i].value );
353
- }
320
+ while (stay) {
321
+ returnValue = newtWinEntries (const_cast <char *>(title),
322
+ const_cast <char *>(message), m_suggestedWidth, m_flexDown,
323
+ m_flexUp, m_dataWidth, field.get (),
324
+ const_cast <char *>(TUIText::Buttons::ok),
325
+ const_cast <char *>(TUIText::Buttons::cancel),
326
+ const_cast <char *>(TUIText::Buttons::help), nullptr );
327
+ stay = false ;
354
328
355
- return returnArray;
356
- case 2 :
357
- abort ();
358
- break ;
359
- case 3 :
360
- this ->helpMessage (helpMessage);
361
- goto question;
362
- default :
363
- throw std::runtime_error (
364
- " Invalid return value from fields on newt library" );
329
+ switch (returnValue) {
330
+ case 0 :
331
+ /* F12 is pressed, and we don't care; continue to case 1 */
332
+ case 1 :
333
+ // TODO: The view should now check for this, it's a passive
334
+ // view
335
+ if (hasEmptyField (field.get ())) {
336
+ stay = true ;
337
+ continue ;
338
+ }
339
+
340
+ // FIXME: We forgot that we should return size_t sometimes
341
+ // and
342
+ // that was triggering an exception on the presenter,
343
+ // so basically the std::variant is useless here, we
344
+ // always return std:string.
345
+ for (std::size_t i = 0 ; field[i].text ; i++) {
346
+ returnArray[i]
347
+ = std::make_pair<std::string, std::string>(
348
+ field[i].text , *field[i].value );
349
+ }
350
+
351
+ return returnArray;
352
+ case 2 :
353
+ abort ();
354
+ break ;
355
+ case 3 :
356
+ this ->helpMessage (helpMessage);
357
+ stay = true ;
358
+ break ;
359
+ default :
360
+ throw std::runtime_error (
361
+ " Invalid return value from fields on newt library" );
362
+ }
365
363
}
366
364
throw std::runtime_error (" Invalid return path on newt library" );
367
365
}
0 commit comments