]> git.ozlabs.org Git - petitboot/blob - ui/ncurses/nc-cui.c
i18n: Add english translation
[petitboot] / ui / ncurses / nc-cui.c
1 /*
2  *  Copyright (C) 2009 Sony Computer Entertainment Inc.
3  *  Copyright 2009 Sony Corp.
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; version 2 of the License.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #if defined(HAVE_CONFIG_H)
20 #include "config.h"
21 #endif
22
23 #include <assert.h>
24 #include <errno.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <sys/ioctl.h>
28
29 #include "log/log.h"
30 #include "pb-protocol/pb-protocol.h"
31 #include "talloc/talloc.h"
32 #include "waiter/waiter.h"
33 #include "process/process.h"
34 #include "i18n/i18n.h"
35 #include "ui/common/discover-client.h"
36 #include "ui/common/ui-system.h"
37 #include "nc-cui.h"
38 #include "nc-boot-editor.h"
39 #include "nc-config.h"
40 #include "nc-sysinfo.h"
41 #include "nc-helpscreen.h"
42
43 static void cui_start(void)
44 {
45         initscr();                      /* Initialize ncurses. */
46         cbreak();                       /* Disable line buffering. */
47         noecho();                       /* Disable getch() echo. */
48         keypad(stdscr, TRUE);           /* Enable num keypad keys. */
49         nonl();                         /* Disable new-line translation. */
50         intrflush(stdscr, FALSE);       /* Disable interrupt flush. */
51         curs_set(0);                    /* Make cursor invisible */
52         nodelay(stdscr, TRUE);          /* Enable non-blocking getch() */
53
54         /* We may be operating with an incorrect $TERM type; in this case
55          * the keymappings will be slightly broken. We want at least
56          * backspace to work though, so we'll define both DEL and ^H to
57          * map to backspace */
58         define_key("\x7f", KEY_BACKSPACE);
59         define_key("\x08", KEY_BACKSPACE);
60
61         /* we need backtab too, for form navigation. vt220 doesn't include
62          * this (kcbt), but we don't want to require a full linux/xterm termcap
63          */
64         define_key("\x1b[Z", KEY_BTAB);
65
66         while (getch() != ERR)          /* flush stdin */
67                 (void)0;
68 }
69
70 static void cui_atexit(void)
71 {
72         clear();
73         refresh();
74         endwin();
75 }
76
77 /**
78  * cui_abort - Signal the main cui program loop to exit.
79  *
80  * Sets cui.abort, which causes the cui_run() routine to return.
81  */
82
83 void cui_abort(struct cui *cui)
84 {
85         pb_log("%s: exiting\n", __func__);
86         cui->abort = 1;
87 }
88
89 /**
90  * cui_resize - Signal the main cui program loop to resize
91  *
92  * Called at SIGWINCH.
93  */
94
95 void cui_resize(struct cui *cui)
96 {
97         pb_debug("%s: resizing\n", __func__);
98         cui->resize = 1;
99 }
100
101 /**
102  * cui_on_exit - A generic main menu exit callback.
103  */
104
105 void cui_on_exit(struct pmenu *menu)
106 {
107         cui_abort(cui_from_pmenu(menu));
108 }
109
110 /**
111  * cui_run_cmd - A generic cb to run the supplied command.
112  */
113
114 int cui_run_cmd(struct pmenu_item *item)
115 {
116         int result;
117         struct cui *cui = cui_from_item(item);
118         const char **cmd_argv = item->data;
119
120         nc_scr_status_printf(cui->current, _("Running %s..."), cmd_argv[0]);
121
122         def_prog_mode();
123
124         result = process_run_simple_argv(item, cmd_argv);
125
126         reset_prog_mode();
127         redrawwin(cui->current->main_ncw);
128
129         if (result) {
130                 pb_log("%s: failed: '%s'\n", __func__, cmd_argv[0]);
131                 nc_scr_status_printf(cui->current, _("Failed: %s"),
132                                 cmd_argv[0]);
133         }
134
135         return result;
136 }
137
138 /**
139  * cui_boot - A generic cb to run kexec.
140  */
141
142 static int cui_boot(struct pmenu_item *item)
143 {
144         int result;
145         struct cui *cui = cui_from_item(item);
146         struct cui_opt_data *cod = cod_from_item(item);
147
148         assert(cui->current == &cui->main->scr);
149
150         pb_debug("%s: %s\n", __func__, cod->name);
151
152         nc_scr_status_printf(cui->current, _("Booting %s..."), cod->name);
153
154         result = discover_client_boot(cui->client, NULL, cod->opt, cod->bd);
155
156         if (result) {
157                 nc_scr_status_printf(cui->current,
158                                 _("Failed: boot %s"), cod->bd->image);
159         }
160
161         return 0;
162 }
163
164 static void cui_boot_editor_on_exit(struct cui *cui,
165                 struct pmenu_item *item,
166                 struct pb_boot_data *bd)
167 {
168         struct pmenu *menu = cui->main;
169         struct cui_opt_data *cod;
170         static int user_idx = 0;
171
172         /* Was the edit cancelled? */
173         if (!bd) {
174                 cui_set_current(cui, &cui->main->scr);
175                 talloc_free(cui->boot_editor);
176                 cui->boot_editor = NULL;
177                 return;
178         }
179
180         /* Is this was a new item, we'll need to update the menu */
181         if (!item) {
182                 int insert_pt;
183
184                 cod = talloc_zero(NULL, struct cui_opt_data);
185                 cod->name = talloc_asprintf(cod, _("User item %u"), ++user_idx);
186
187                 item = pmenu_item_create(menu, cod->name);
188                 if (!item) {
189                         talloc_free(cod);
190                         goto out;
191                 }
192
193                 item->on_edit = cui_item_edit;
194                 item->on_execute = cui_boot;
195                 item->data = cod;
196
197                 talloc_steal(item, cod);
198
199                 /* Detach the items array. */
200                 set_menu_items(menu->ncm, NULL);
201
202                 /* Insert new item at insert_pt. */
203                 insert_pt = pmenu_grow(menu, 1);
204                 pmenu_item_insert(menu, item, insert_pt);
205
206                 /* Re-attach the items array. */
207                 set_menu_items(menu->ncm, menu->items);
208                 nc_scr_post(&menu->scr);
209         } else {
210                 cod = item->data;
211         }
212
213         cod->bd = talloc_steal(cod, bd);
214
215         set_current_item(item->pmenu->ncm, item->nci);
216 out:
217         cui_set_current(cui, &cui->main->scr);
218         talloc_free(cui->boot_editor);
219         cui->boot_editor = NULL;
220 }
221
222 void cui_item_edit(struct pmenu_item *item)
223 {
224         struct cui *cui = cui_from_item(item);
225         cui->boot_editor = boot_editor_init(cui, item, cui->sysinfo,
226                                         cui_boot_editor_on_exit);
227         cui_set_current(cui, boot_editor_scr(cui->boot_editor));
228 }
229
230 void cui_item_new(struct pmenu *menu)
231 {
232         struct cui *cui = cui_from_pmenu(menu);
233         cui->boot_editor = boot_editor_init(cui, NULL, cui->sysinfo,
234                                         cui_boot_editor_on_exit);
235         cui_set_current(cui, boot_editor_scr(cui->boot_editor));
236 }
237
238 static void cui_sysinfo_exit(struct cui *cui)
239 {
240         cui_set_current(cui, &cui->main->scr);
241         talloc_free(cui->sysinfo_screen);
242         cui->sysinfo_screen = NULL;
243 }
244
245 void cui_show_sysinfo(struct cui *cui)
246 {
247         cui->sysinfo_screen = sysinfo_screen_init(cui, cui->sysinfo,
248                         cui_sysinfo_exit);
249         cui_set_current(cui, sysinfo_screen_scr(cui->sysinfo_screen));
250 }
251
252 static void cui_config_exit(struct cui *cui)
253 {
254         cui_set_current(cui, &cui->main->scr);
255         talloc_free(cui->config_screen);
256         cui->config_screen = NULL;
257 }
258
259 void cui_show_config(struct cui *cui)
260 {
261         cui->config_screen = config_screen_init(cui, cui->config,
262                         cui->sysinfo, cui_config_exit);
263         cui_set_current(cui, config_screen_scr(cui->config_screen));
264 }
265
266 static void cui_help_exit(struct cui *cui)
267 {
268         cui_set_current(cui, help_screen_return_scr(cui->help_screen));
269         talloc_free(cui->help_screen);
270         cui->help_screen = NULL;
271 }
272
273 void cui_show_help(struct cui *cui, const char *title,
274                 const struct help_text *text)
275 {
276         if (!cui->current)
277                 return;
278
279         if (cui->help_screen)
280                 return;
281
282         cui->help_screen = help_screen_init(cui, cui->current,
283                         title, text, cui_help_exit);
284
285         if (cui->help_screen)
286                 cui_set_current(cui, help_screen_scr(cui->help_screen));
287 }
288
289 /**
290  * cui_set_current - Set the currently active screen and redraw it.
291  */
292
293 struct nc_scr *cui_set_current(struct cui *cui, struct nc_scr *scr)
294 {
295         struct nc_scr *old;
296
297         DBGS("%p -> %p\n", cui->current, scr);
298
299         assert(cui->current != scr);
300
301         old = cui->current;
302         nc_scr_unpost(old);
303
304         cui->current = scr;
305
306         nc_scr_post(cui->current);
307
308         return old;
309 }
310
311 static bool process_global_keys(struct cui *cui, int key)
312 {
313         switch (key) {
314         case 0xc:
315                 if (cui->current && cui->current->main_ncw)
316                         wrefresh(curscr);
317                 return true;
318         }
319         return false;
320 }
321
322 /**
323  * cui_process_key - Process input on stdin.
324  */
325
326 static int cui_process_key(void *arg)
327 {
328         struct cui *cui = cui_from_arg(arg);
329
330         assert(cui->current);
331
332         for (;;) {
333                 int c = getch();
334
335                 pb_debug("%s: got key %d\n", __func__, c);
336
337                 if (c == ERR)
338                         break;
339
340                 if (!cui->has_input) {
341                         pb_log("UI input received (key = %d), aborting "
342                                         "default boot\n", c);
343                         discover_client_cancel_default(cui->client);
344                         cui->has_input = true;
345                 }
346
347                 if (process_global_keys(cui, c))
348                         continue;
349
350                 cui->current->process_key(cui->current, c);
351         }
352
353         return 0;
354 }
355
356 /**
357  * cui_process_js - Process joystick events.
358  */
359
360 static int cui_process_js(void *arg)
361 {
362         struct cui *cui = cui_from_arg(arg);
363         int c;
364
365         c = pjs_process_event(cui->pjs);
366
367         if (c) {
368                 ungetch(c);
369                 cui_process_key(arg);
370         }
371
372         return 0;
373 }
374
375 /**
376  * cui_handle_resize - Handle the term resize.
377  */
378
379 static void cui_handle_resize(struct cui *cui)
380 {
381         struct winsize ws;
382
383         if (ioctl(1, TIOCGWINSZ, &ws) == -1) {
384                 pb_log("%s: ioctl failed: %s\n", __func__, strerror(errno));
385                 return;
386         }
387
388         pb_debug("%s: {%u,%u}\n", __func__, ws.ws_row, ws.ws_col);
389
390         wclear(cui->current->main_ncw);
391         resize_term(ws.ws_row, ws.ws_col);
392         cui->current->resize(cui->current);
393
394         /* For some reason this makes ncurses redraw the screen */
395         getch();
396         redrawwin(cui->current->main_ncw);
397         wrefresh(cui->current->main_ncw);
398 }
399
400 /**
401  * cui_device_add - Client device_add callback.
402  *
403  * Creates menu_items for all the device boot_options and inserts those
404  * menu_items into the main menu.  Redraws the main menu if it is active.
405  */
406
407 static int cui_boot_option_add(struct device *dev, struct boot_option *opt,
408                 void *arg)
409 {
410         struct pmenu_item *i, *dev_hdr = NULL;
411         struct cui *cui = cui_from_arg(arg);
412         struct cui_opt_data *cod;
413         const char *tab = "  ";
414         unsigned int insert_pt;
415         int result, rows, cols;
416         ITEM *selected;
417         char *name;
418
419         pb_debug("%s: %p %s\n", __func__, opt, opt->id);
420
421         selected = current_item(cui->main->ncm);
422         menu_format(cui->main->ncm, &rows, &cols);
423
424         if (cui->current == &cui->main->scr)
425                 nc_scr_unpost(cui->current);
426
427         /* Check if the boot device is new */
428         dev_hdr = pmenu_find_device(cui->main, dev, opt);
429
430         /* All actual boot entries are 'tabbed' across */
431         name = talloc_asprintf(cui->main, "%s%s",
432                         tab, opt->name ? : "Unknown Name");
433
434         /* Save the item in opt->ui_info for cui_device_remove() */
435         opt->ui_info = i = pmenu_item_create(cui->main, name);
436         talloc_free(name);
437         if (!i)
438                 return -1;
439
440         i->on_edit = cui_item_edit;
441         i->on_execute = cui_boot;
442         i->data = cod = talloc(i, struct cui_opt_data);
443
444         cod->opt = opt;
445         cod->dev = dev;
446         cod->opt_hash = pb_opt_hash(dev, opt);
447         cod->name = opt->name;
448         cod->bd = talloc(i, struct pb_boot_data);
449
450         cod->bd->image = talloc_strdup(cod->bd, opt->boot_image_file);
451         cod->bd->initrd = talloc_strdup(cod->bd, opt->initrd_file);
452         cod->bd->dtb = talloc_strdup(cod->bd, opt->dtb_file);
453         cod->bd->args = talloc_strdup(cod->bd, opt->boot_args);
454
455         /* This disconnects items array from menu. */
456         result = set_menu_items(cui->main->ncm, NULL);
457
458         if (result)
459                 pb_log("%s: set_menu_items failed: %d\n", __func__, result);
460
461         /* Insert new items at insert_pt. */
462         if (dev_hdr) {
463                 insert_pt = pmenu_grow(cui->main, 2);
464                 pmenu_item_insert(cui->main, dev_hdr, insert_pt);
465                 pb_log("%s: adding new device hierarchy %s\n",
466                         __func__,opt->device_id);
467                 pmenu_item_insert(cui->main, i, insert_pt+1);
468         } else {
469                 insert_pt = pmenu_grow(cui->main, 1);
470                 pmenu_item_add(cui->main, i, insert_pt);
471         }
472
473         pb_log("%s: adding opt '%s'\n", __func__, cod->name);
474         pb_log("   image  '%s'\n", cod->bd->image);
475         pb_log("   initrd '%s'\n", cod->bd->initrd);
476         pb_log("   args   '%s'\n", cod->bd->args);
477
478         /* Re-attach the items array. */
479         result = set_menu_items(cui->main->ncm, cui->main->items);
480
481         if (result)
482                 pb_log("%s: set_menu_items failed: %d\n", __func__, result);
483
484         if (0) {
485                 pb_log("%s\n", __func__);
486                 pmenu_dump_items(cui->main->items,
487                         item_count(cui->main->ncm) + 1);
488         }
489
490         if (!item_visible(selected)) {
491                 int idx, top;
492
493                 top = top_row(cui->main->ncm);
494                 idx = item_index(selected);
495
496                 /* If our index is above the current top row, align
497                  * us to the new top. Otherwise, align us to the new
498                  * bottom */
499                 top = top < idx ? idx - rows : idx;
500
501                 set_top_row(cui->main->ncm, top);
502                 set_current_item(cui->main->ncm, selected);
503         }
504
505         if (cui->current == &cui->main->scr)
506                 nc_scr_post(cui->current);
507
508         return 0;
509 }
510
511 /**
512  * cui_device_remove - Client device remove callback.
513  *
514  * Removes all the menu_items for the device from the main menu and redraws the
515  * main menu if it is active.
516  */
517
518 static void cui_device_remove(struct device *dev, void *arg)
519 {
520         struct cui *cui = cui_from_arg(arg);
521         struct boot_option *opt;
522         unsigned int i;
523         int result;
524
525         pb_log("%s: %p %s\n", __func__, dev, dev->id);
526
527         if (cui->current == &cui->main->scr)
528                 nc_scr_unpost(cui->current);
529
530         /* This disconnects items array from menu. */
531
532         result = set_menu_items(cui->main->ncm, NULL);
533
534         if (result)
535                 pb_log("%s: set_menu_items failed: %d\n", __func__, result);
536
537         list_for_each_entry(&dev->boot_options, opt, list) {
538                 struct pmenu_item *item = pmenu_item_from_arg(opt->ui_info);
539
540                 assert(pb_protocol_device_cmp(dev, cod_from_item(item)->dev));
541                 pmenu_remove(cui->main, item);
542         }
543
544         /* Manually remove remaining device hierarchy item */
545         for (i=0; i < cui->main->item_count; i++) {
546                 struct pmenu_item *item = item_userptr(cui->main->items[i]);
547                 if (!item || !item->data )
548                         continue;
549
550                 struct cui_opt_data *data = item->data;
551                 if (data && data->dev && data->dev == dev)
552                         pmenu_remove(cui->main,item);
553         }
554
555         /* Re-attach the items array. */
556
557         result = set_menu_items(cui->main->ncm, cui->main->items);
558
559         if (result)
560                 pb_log("%s: set_menu_items failed: %d\n", __func__, result);
561
562         if (0) {
563                 pb_log("%s\n", __func__);
564                 pmenu_dump_items(cui->main->items,
565                         item_count(cui->main->ncm) + 1);
566         }
567
568         if (cui->current == &cui->main->scr)
569                 nc_scr_post(cui->current);
570 }
571
572 static void cui_update_status(struct boot_status *status, void *arg)
573 {
574         struct cui *cui = cui_from_arg(arg);
575
576         nc_scr_status_printf(cui->current,
577                         "%s: %s",
578                         status->type == BOOT_STATUS_ERROR ?
579                                 _("Error") : _("Info"),
580                         status->message);
581
582 }
583
584 static void cui_update_mm_title(struct cui *cui)
585 {
586         struct nc_frame *frame = &cui->main->scr.frame;
587
588         talloc_free(frame->rtitle);
589
590         frame->rtitle = talloc_strdup(cui->main, cui->sysinfo->type);
591         if (cui->sysinfo->identifier)
592                 frame->rtitle = talloc_asprintf_append(frame->rtitle,
593                                 " %s", cui->sysinfo->identifier);
594
595         if (cui->current == &cui->main->scr)
596                 nc_scr_post(cui->current);
597 }
598
599 static void cui_update_sysinfo(struct system_info *sysinfo, void *arg)
600 {
601         struct cui *cui = cui_from_arg(arg);
602         cui->sysinfo = talloc_steal(cui, sysinfo);
603
604         /* if we're currently displaying the system info screen, inform it
605          * of the updated information. */
606         if (cui->sysinfo_screen)
607                 sysinfo_screen_update(cui->sysinfo_screen, sysinfo);
608
609         /* ... and do the same with the config screen... */
610         if (cui->config_screen)
611                 config_screen_update(cui->config_screen, cui->config, sysinfo);
612
613         /* ... and the boot editor. */
614         if (cui->boot_editor)
615                 boot_editor_update(cui->boot_editor, sysinfo);
616
617         cui_update_mm_title(cui);
618 }
619
620 static void cui_update_config(struct config *config, void *arg)
621 {
622         struct cui *cui = cui_from_arg(arg);
623         cui->config = talloc_steal(cui, config);
624
625         if (cui->config_screen)
626                 config_screen_update(cui->config_screen, config, cui->sysinfo);
627
628         if (config->safe_mode)
629                 nc_scr_status_printf(cui->current,
630                                 _("SAFE MODE: select '%s' to continue"),
631                                 _("Rescan devices"));
632 }
633
634 int cui_send_config(struct cui *cui, struct config *config)
635 {
636         return discover_client_send_config(cui->client, config);
637 }
638
639 void cui_send_reinit(struct cui *cui)
640 {
641         discover_client_send_reinit(cui->client);
642 }
643
644 static struct discover_client_ops cui_client_ops = {
645         .device_add = NULL,
646         .boot_option_add = cui_boot_option_add,
647         .device_remove = cui_device_remove,
648         .update_status = cui_update_status,
649         .update_sysinfo = cui_update_sysinfo,
650         .update_config = cui_update_config,
651 };
652
653 /**
654  * cui_init - Setup the cui instance.
655  * @platform_info: A value for the struct cui platform_info member.
656  *
657  * Returns a pointer to a struct cui on success, or NULL on error.
658  *
659  * Allocates the cui instance, sets up the client and stdin waiters, and
660  * sets up the ncurses menu screen.
661  */
662
663 struct cui *cui_init(void* platform_info,
664         int (*js_map)(const struct js_event *e), int start_deamon)
665 {
666         struct cui *cui;
667         unsigned int i;
668
669         cui = talloc_zero(NULL, struct cui);
670
671         if (!cui) {
672                 pb_log("%s: alloc cui failed.\n", __func__);
673                 fprintf(stderr, _("%s: alloc cui failed.\n"), __func__);
674                 goto fail_alloc;
675         }
676
677         cui->c_sig = pb_cui_sig;
678         cui->platform_info = platform_info;
679         cui->waitset = waitset_create(cui);
680
681         process_init(cui, cui->waitset, false);
682
683         /* Loop here for scripts that just started the server. */
684
685 retry_start:
686         for (i = start_deamon ? 2 : 10; i; i--) {
687                 cui->client = discover_client_init(cui->waitset,
688                                 &cui_client_ops, cui);
689                 if (cui->client || !i)
690                         break;
691                 pb_log("%s: waiting for server %d\n", __func__, i);
692                 sleep(1);
693         }
694
695         if (!cui->client && start_deamon) {
696                 int result;
697
698                 start_deamon = 0;
699
700                 result = pb_start_daemon(cui);
701
702                 if (!result)
703                         goto retry_start;
704
705                 pb_log("%s: discover_client_init failed.\n", __func__);
706                 fprintf(stderr, _("%s: error: discover_client_init failed.\n"),
707                         __func__);
708                 fprintf(stderr, _("could not start pb-discover, the petitboot "
709                         "daemon.\n"));
710                 goto fail_client_init;
711         }
712
713         if (!cui->client) {
714                 pb_log("%s: discover_client_init failed.\n", __func__);
715                 fprintf(stderr, _("%s: error: discover_client_init failed.\n"),
716                         __func__);
717                 fprintf(stderr, _("check that pb-discover, "
718                         "the petitboot daemon is running.\n"));
719                 goto fail_client_init;
720         }
721
722         atexit(cui_atexit);
723         talloc_steal(cui, cui->client);
724         cui_start();
725
726         waiter_register_io(cui->waitset, STDIN_FILENO, WAIT_IN,
727                         cui_process_key, cui);
728
729         if (js_map) {
730
731                 cui->pjs = pjs_init(cui, js_map);
732
733                 if (cui->pjs)
734                         waiter_register_io(cui->waitset, pjs_get_fd(cui->pjs),
735                                         WAIT_IN, cui_process_js, cui);
736         }
737
738         return cui;
739
740 fail_client_init:
741         talloc_free(cui);
742 fail_alloc:
743         return NULL;
744 }
745
746 /**
747  * cui_run - The main cui program loop.
748  * @cui: The cui instance.
749  * @main: The menu to use as the main menu.
750  *
751  * Runs the cui engine.  Does not return until indicated to do so by some
752  * user action, or an error occurs.  Frees the cui object on return.
753  * Returns 0 on success (return to shell), -1 on error (should restart).
754  */
755
756 int cui_run(struct cui *cui, struct pmenu *main, unsigned int default_item)
757 {
758         assert(main);
759
760         cui->main = main;
761         cui->current = &cui->main->scr;
762         cui->default_item = default_item;
763
764         nc_scr_post(cui->current);
765
766         while (1) {
767                 int result = waiter_poll(cui->waitset);
768
769                 if (result < 0) {
770                         pb_log("%s: poll: %s\n", __func__, strerror(errno));
771                         break;
772                 }
773
774                 if (cui->abort)
775                         break;
776
777                 while (cui->resize) {
778                         cui->resize = 0;
779                         cui_handle_resize(cui);
780                 }
781         }
782
783         cui_atexit();
784
785         return cui->abort ? 0 : -1;
786 }