wrlib: return NULL if XImage could not be taken, for consistency
[wmaker-crm.git] / src / main.c
blobbc1472169fb8113cab3f24e2eed5f02797a7dcc0
1 /*
2 * Window Maker window manager
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "wconfig.h"
23 #ifdef HAVE_INOTIFY
24 #include <sys/inotify.h>
25 #endif
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <sys/stat.h>
32 #include <sys/types.h>
33 #include <fcntl.h>
35 #include <X11/Xlib.h>
36 #include <X11/Xutil.h>
38 /* Xlocale.h and locale.h are the same if X_LOCALE is undefind in wconfig.h,
39 * and if X_LOCALE is defined, X's locale emulating functions will be used.
40 * See Xlocale.h for more information.
42 #include <X11/Xlocale.h>
44 #define MAINFILE
46 #include "WindowMaker.h"
47 #include "window.h"
48 #include "defaults.h"
49 #include "event.h"
50 #include "startup.h"
51 #include "menu.h"
52 #include "keybind.h"
53 #include "xmodifier.h"
54 #include "session.h"
55 #include "shutdown.h"
56 #include "dialog.h"
57 #include "main.h"
58 #include "monitor.h"
60 #include <WINGs/WUtil.h>
62 #ifndef GLOBAL_DEFAULTS_SUBDIR
63 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
64 #endif
66 /****** Global Variables ******/
67 struct wmaker_global_variables w_global;
69 /* general info */
71 Display *dpy;
73 char *ProgName;
75 struct WPreferences wPreferences;
77 WShortKey wKeyBindings[WKBD_LAST];
79 /* notifications */
80 const char WMNManaged[] = "WMNManaged";
81 const char WMNUnmanaged[] = "WMNUnmanaged";
82 const char WMNChangedWorkspace[] = "WMNChangedWorkspace";
83 const char WMNChangedState[] = "WMNChangedState";
84 const char WMNChangedFocus[] = "WMNChangedFocus";
85 const char WMNChangedStacking[] = "WMNChangedStacking";
86 const char WMNChangedName[] = "WMNChangedName";
88 const char WMNWorkspaceCreated[] = "WMNWorkspaceCreated";
89 const char WMNWorkspaceDestroyed[] = "WMNWorkspaceDestroyed";
90 const char WMNWorkspaceChanged[] = "WMNWorkspaceChanged";
91 const char WMNWorkspaceNameChanged[] = "WMNWorkspaceNameChanged";
93 const char WMNResetStacking[] = "WMNResetStacking";
95 /******** End Global Variables *****/
97 static char *DisplayName = NULL;
99 static char **Arguments;
101 static int ArgCount;
103 static Bool multiHead = True;
105 static int *wVisualID = NULL;
106 static int wVisualID_len = 0;
108 static int real_main(int argc, char **argv);
110 int getWVisualID(int screen)
112 if (wVisualID == NULL)
113 return -1;
114 if (screen < 0 || screen >= wVisualID_len)
115 return -1;
117 return wVisualID[screen];
120 static void setWVisualID(int screen, int val)
122 int i;
124 if (screen < 0)
125 return;
127 if (wVisualID == NULL) {
128 /* no array at all, alloc space for screen + 1 entries
129 * and init with default value */
130 wVisualID_len = screen + 1;
131 wVisualID = (int *)malloc(wVisualID_len * sizeof(int));
132 for (i = 0; i < wVisualID_len; i++) {
133 wVisualID[i] = -1;
135 } else if (screen >= wVisualID_len) {
136 /* larger screen number than previously allocated
137 so enlarge array */
138 int oldlen = wVisualID_len;
140 wVisualID_len = screen + 1;
141 wVisualID = (int *)realloc(wVisualID, wVisualID_len * sizeof(int));
142 for (i = oldlen; i < wVisualID_len; i++) {
143 wVisualID[i] = -1;
147 wVisualID[screen] = val;
151 * this function splits a given string at the comma into tokens
152 * and set the wVisualID variable to each parsed number
154 static int initWVisualID(const char *user_str)
156 char *mystr = strdup(user_str);
157 int cur_in_pos = 0;
158 int cur_out_pos = 0;
159 int cur_screen = 0;
160 int error_found = 0;
162 for (;;) {
163 /* check for delimiter */
164 if (user_str[cur_in_pos] == '\0' || user_str[cur_in_pos] == ',') {
165 int v;
167 mystr[cur_out_pos] = '\0';
169 if (sscanf(mystr, "%i", &v) != 1) {
170 error_found = 1;
171 break;
174 setWVisualID(cur_screen, v);
176 cur_screen++;
177 cur_out_pos = 0;
180 /* break in case last char has been consumed */
181 if (user_str[cur_in_pos] == '\0')
182 break;
184 /* if the current char is no delimiter put it into mystr */
185 if (user_str[cur_in_pos] != ',') {
186 mystr[cur_out_pos++] = user_str[cur_in_pos];
188 cur_in_pos++;
191 free(mystr);
193 if (cur_screen == 0||error_found != 0)
194 return 1;
196 return 0;
199 noreturn void Exit(int status)
201 if (dpy)
202 XCloseDisplay(dpy);
204 RShutdown(); /* wrlib clean exit */
205 wutil_shutdown(); /* WUtil clean-up */
207 exit(status);
210 void Restart(char *manager, Bool abortOnFailure)
212 char *prog = NULL;
213 char *argv[MAX_RESTART_ARGS];
214 int i;
216 if (manager && manager[0] != 0) {
217 prog = argv[0] = strtok(manager, " ");
218 for (i = 1; i < MAX_RESTART_ARGS; i++) {
219 argv[i] = strtok(NULL, " ");
220 if (argv[i] == NULL) {
221 break;
225 if (dpy) {
226 XCloseDisplay(dpy);
227 dpy = NULL;
229 if (!prog) {
230 execvp(Arguments[0], Arguments);
231 wfatal(_("failed to restart Window Maker."));
232 } else {
233 execvp(prog, argv);
234 werror(_("could not exec %s"), prog);
236 if (abortOnFailure)
237 exit(7);
240 void SetupEnvironment(WScreen * scr)
242 char *tmp, *ptr;
243 char buf[16];
245 if (multiHead) {
246 int len = strlen(DisplayName) + 64;
247 tmp = wmalloc(len);
248 snprintf(tmp, len, "DISPLAY=%s", XDisplayName(DisplayName));
249 ptr = strchr(strchr(tmp, ':'), '.');
250 if (ptr)
251 *ptr = 0;
252 snprintf(buf, sizeof(buf), ".%i", scr->screen);
253 strcat(tmp, buf);
254 putenv(tmp);
256 tmp = wmalloc(60);
257 snprintf(tmp, 60, "WRASTER_COLOR_RESOLUTION%i=%i", scr->screen,
258 scr->rcontext->attribs->colors_per_channel);
259 putenv(tmp);
262 typedef struct {
263 WScreen *scr;
264 char *command;
265 } _tuple;
267 static void shellCommandHandler(pid_t pid, unsigned int status, void *client_data)
269 _tuple *data = (_tuple *) client_data;
271 /* Parameter not used, but tell the compiler that it is ok */
272 (void) pid;
274 if (status == 127) {
275 char *buffer;
277 buffer = wstrconcat(_("Could not execute command: "), data->command);
279 wMessageDialog(data->scr, _("Error"), buffer, _("OK"), NULL, NULL);
280 wfree(buffer);
281 } else if (status != 127) {
283 printf("%s: %i\n", data->command, status);
287 wfree(data->command);
288 wfree(data);
291 void ExecuteShellCommand(WScreen *scr, const char *command)
293 static char *shell = NULL;
294 pid_t pid;
297 * This have a problem: if the shell is tcsh (not sure about others)
298 * and ~/.tcshrc have /bin/stty erase ^H somewhere on it, the shell
299 * will block and the command will not be executed.
300 if (!shell) {
301 shell = getenv("SHELL");
302 if (!shell)
303 shell = "/bin/sh";
306 shell = "/bin/sh";
308 pid = fork();
310 if (pid == 0) {
312 SetupEnvironment(scr);
314 #ifdef HAVE_SETSID
315 setsid();
316 #endif
317 execl(shell, shell, "-c", command, NULL);
318 werror("could not execute %s -c %s", shell, command);
319 Exit(-1);
320 } else if (pid < 0) {
321 werror("cannot fork a new process");
322 } else {
323 _tuple *data = wmalloc(sizeof(_tuple));
325 data->scr = scr;
326 data->command = wstrdup(command);
328 wAddDeathHandler(pid, shellCommandHandler, data);
333 *---------------------------------------------------------------------
334 * RelaunchWindow--
335 * Launch a new instance of the active window
337 *----------------------------------------------------------------------
339 Bool RelaunchWindow(WWindow *wwin)
341 if (! wwin || ! wwin->client_win) {
342 werror("no window to relaunch");
343 return False;
346 char **argv;
347 int argc;
349 if (! XGetCommand(dpy, wwin->client_win, &argv, &argc) || argc == 0 || argv == NULL) {
350 werror("cannot relaunch the application because no WM_COMMAND property is set");
351 return False;
354 pid_t pid = fork();
356 if (pid == 0) {
357 SetupEnvironment(wwin->screen_ptr);
358 #ifdef HAVE_SETSID
359 setsid();
360 #endif
361 /* argv is not null-terminated */
362 char **a = (char **) malloc(argc + 1);
363 if (! a) {
364 werror("out of memory trying to relaunch the application");
365 Exit(-1);
368 int i;
369 for (i = 0; i < argc; i++)
370 a[i] = argv[i];
371 a[i] = NULL;
373 execvp(a[0], a);
374 Exit(-1);
375 } else if (pid < 0) {
376 werror("cannot fork a new process");
378 XFreeStringList(argv);
379 return False;
380 } else {
381 _tuple *data = wmalloc(sizeof(_tuple));
383 data->scr = wwin->screen_ptr;
384 data->command = wtokenjoin(argv, argc);
386 /* not actually a shell command */
387 wAddDeathHandler(pid, shellCommandHandler, data);
389 XFreeStringList(argv);
392 return True;
396 *---------------------------------------------------------------------
397 * wAbort--
398 * Do a major cleanup and exit the program
400 *----------------------------------------------------------------------
402 noreturn void wAbort(Bool dumpCore)
404 int i;
405 WScreen *scr;
407 for (i = 0; i < w_global.screen_count; i++) {
408 scr = wScreenWithNumber(i);
409 if (scr)
410 RestoreDesktop(scr);
412 printf(_("%s aborted.\n"), ProgName);
413 if (dumpCore)
414 abort();
415 else
416 exit(1);
419 static void print_help(void)
421 printf(_("Usage: %s [options]\n"), ProgName);
422 puts(_("The Window Maker window manager for the X window system"));
423 puts("");
424 puts(_(" -display host:dpy display to use"));
425 puts(_(" --no-dock do not open the application Dock"));
426 puts(_(" --no-clip do not open the workspace Clip"));
427 puts(_(" --no-autolaunch do not autolaunch applications"));
428 puts(_(" --dont-restore do not restore saved session"));
430 puts(_(" --locale locale locale to use"));
432 puts(_(" --visual-id visualid visual id of visual to use"));
433 puts(_(" --static do not update or save configurations"));
434 #ifndef HAVE_INOTIFY
435 puts(_(" --no-polling do not periodically check for configuration updates"));
436 #endif
437 puts(_(" --version print version and exit"));
438 puts(_(" --help show this message"));
441 static void check_defaults(void)
443 char *path;
445 path = wdefaultspathfordomain("WindowMaker");
447 if (access(path, R_OK) != 0) {
448 wwarning(_("could not find user GNUstep directory (%s)."), path);
450 if (system("wmaker.inst --batch") != 0) {
451 wwarning(_("There was an error while creating GNUstep directory, please "
452 "make sure you have installed Window Maker correctly and run wmaker.inst"));
453 } else {
454 wwarning(_("%s directory created with default configuration."), path);
458 wfree(path);
461 #ifdef HAVE_INOTIFY
463 * Add watch here, used to notify if configuration
464 * files have changed, using linux kernel inotify mechanism
467 static void inotifyWatchConfig(void)
469 char *watchPath = NULL;
471 w_global.inotify.fd_event_queue = inotify_init(); /* Initialise an inotify instance */
472 if (w_global.inotify.fd_event_queue < 0) {
473 wwarning(_("could not initialise an inotify instance."
474 " Changes to the defaults database will require"
475 " a restart to take effect. Check your kernel!"));
476 } else {
477 watchPath = wstrconcat(wusergnusteppath(), "/Defaults");
478 /* Add the watch; really we are only looking for modify events
479 * but we might want more in the future so check all events for now.
480 * The individual events are checked for in event.c.
482 w_global.inotify.wd_defaults = inotify_add_watch(w_global.inotify.fd_event_queue, watchPath, IN_ALL_EVENTS);
483 if (w_global.inotify.wd_defaults < 0) {
484 wwarning(_("could not add an inotify watch on path %s."
485 "Changes to the defaults database will require"
486 " a restart to take effect."), watchPath);
487 close(w_global.inotify.fd_event_queue);
488 w_global.inotify.fd_event_queue = -1;
491 wfree(watchPath);
493 #endif /* HAVE_INOTIFY */
495 static void execInitScript(void)
497 char *file, *paths;
499 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
500 paths = wstrappend(paths, ":" DEF_CONFIG_PATHS);
502 file = wfindfile(paths, DEF_INIT_SCRIPT);
503 wfree(paths);
505 if (file) {
506 if (system(file) != 0)
507 werror(_("%s:could not execute initialization script"), file);
509 wfree(file);
513 void ExecExitScript(void)
515 char *file, *paths;
517 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
518 paths = wstrappend(paths, ":" DEF_CONFIG_PATHS);
520 file = wfindfile(paths, DEF_EXIT_SCRIPT);
521 wfree(paths);
523 if (file) {
524 if (system(file) != 0)
525 werror(_("%s:could not execute exit script"), file);
527 wfree(file);
531 int main(int argc, char **argv)
533 int i_am_the_monitor, i, len;
534 char *str, *alt;
536 memset(&w_global, 0, sizeof(w_global));
537 w_global.program.state = WSTATE_NORMAL;
538 w_global.program.signal_state = WSTATE_NORMAL;
539 w_global.timestamp.last_event = CurrentTime;
540 w_global.timestamp.focus_change = CurrentTime;
541 w_global.workspace.ignore_change = False;
542 w_global.shortcut.modifiers_mask = 0xff;
544 /* setup common stuff for the monitor and wmaker itself */
545 WMInitializeApplication("WindowMaker", &argc, argv);
547 memset(&wPreferences, 0, sizeof(wPreferences));
549 wPreferences.fallbackWMs = WMCreateArray(8);
550 alt = getenv("WINDOWMAKER_ALT_WM");
551 if (alt != NULL)
552 WMAddToArray(wPreferences.fallbackWMs, wstrdup(alt));
554 WMAddToArray(wPreferences.fallbackWMs, wstrdup("blackbox"));
555 WMAddToArray(wPreferences.fallbackWMs, wstrdup("metacity"));
556 WMAddToArray(wPreferences.fallbackWMs, wstrdup("fvwm"));
557 WMAddToArray(wPreferences.fallbackWMs, wstrdup("twm"));
558 WMAddToArray(wPreferences.fallbackWMs, NULL);
559 WMAddToArray(wPreferences.fallbackWMs, wstrdup("rxvt"));
560 WMAddToArray(wPreferences.fallbackWMs, wstrdup("xterm"));
562 i_am_the_monitor = 1;
564 for (i = 1; i < argc; i++) {
565 if (strncmp(argv[i], "--for-real", strlen("--for-real")) == 0) {
566 i_am_the_monitor = 0;
567 break;
568 } else if (strcmp(argv[i], "-display") == 0 || strcmp(argv[i], "--display") == 0) {
569 i++;
570 if (i >= argc) {
571 wwarning(_("too few arguments for %s"), argv[i - 1]);
572 exit(0);
574 DisplayName = argv[i];
578 DisplayName = XDisplayName(DisplayName);
579 len = strlen(DisplayName) + 64;
580 str = wmalloc(len);
581 snprintf(str, len, "DISPLAY=%s", DisplayName);
582 putenv(str);
584 if (i_am_the_monitor)
585 return MonitorLoop(argc, argv);
586 else
587 return real_main(argc, argv);
590 static int real_main(int argc, char **argv)
592 int i;
593 char *pos;
594 int d, s;
596 setlocale(LC_ALL, "");
597 wsetabort(wAbort);
599 /* for telling WPrefs what's the name of the wmaker binary being ran */
600 setenv("WMAKER_BIN_NAME", argv[0], 1);
602 ArgCount = argc;
603 Arguments = wmalloc(sizeof(char *) * (ArgCount + 1));
604 for (i = 0; i < argc; i++) {
605 Arguments[i] = argv[i];
607 /* add the extra option to signal that we're just restarting wmaker */
608 Arguments[argc - 1] = "--for-real=";
609 Arguments[argc] = NULL;
611 ProgName = strrchr(argv[0], '/');
612 if (!ProgName)
613 ProgName = argv[0];
614 else
615 ProgName++;
617 if (argc > 1) {
618 for (i = 1; i < argc; i++) {
619 if (strcmp(argv[i], "-nocpp") == 0 || strcmp(argv[i], "--no-cpp") == 0) {
620 wwarning(_("option \"%s\" is deprecated, please remove it from your script"), argv[i]);
621 } else if (strcmp(argv[i], "--for-real") == 0) {
622 wPreferences.flags.restarting = 0;
623 } else if (strcmp(argv[i], "--for-real=") == 0) {
624 wPreferences.flags.restarting = 1;
625 } else if (strcmp(argv[i], "--for-real-") == 0) {
626 wPreferences.flags.restarting = 2;
627 } else if (strcmp(argv[i], "-no-autolaunch") == 0
628 || strcmp(argv[i], "--no-autolaunch") == 0) {
629 wPreferences.flags.noautolaunch = 1;
630 } else if (strcmp(argv[i], "-dont-restore") == 0 || strcmp(argv[i], "--dont-restore") == 0) {
631 wPreferences.flags.norestore = 1;
632 } else if (strcmp(argv[i], "-nodock") == 0 || strcmp(argv[i], "--no-dock") == 0) {
633 wPreferences.flags.nodock = 1;
634 wPreferences.flags.nodrawer = 1;
635 } else if (strcmp(argv[i], "-noclip") == 0 || strcmp(argv[i], "--no-clip") == 0) {
636 wPreferences.flags.noclip = 1;
637 } else if (strcmp(argv[i], "-nodrawer") == 0 || strcmp(argv[i], "--no-drawer") == 0) {
638 wPreferences.flags.nodrawer = 1;
639 } else if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
640 printf("Window Maker %s\n", VERSION);
641 exit(0);
642 } else if (strcmp(argv[i], "--global_defaults_path") == 0) {
643 printf("%s/%s\n", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR);
644 exit(0);
645 } else if (strcmp(argv[i], "-locale") == 0 || strcmp(argv[i], "--locale") == 0) {
646 i++;
647 if (i >= argc) {
648 wwarning(_("too few arguments for %s"), argv[i - 1]);
649 exit(0);
651 w_global.locale = argv[i];
652 } else if (strcmp(argv[i], "-display") == 0 || strcmp(argv[i], "--display") == 0) {
653 i++;
654 if (i >= argc) {
655 wwarning(_("too few arguments for %s"), argv[i - 1]);
656 exit(0);
658 DisplayName = argv[i];
659 } else if (strcmp(argv[i], "-visualid") == 0 || strcmp(argv[i], "--visual-id") == 0) {
660 i++;
661 if (i >= argc) {
662 wwarning(_("too few arguments for %s"), argv[i - 1]);
663 exit(0);
665 if (initWVisualID(argv[i]) != 0) {
666 wwarning(_("bad value for visualid: \"%s\""), argv[i]);
667 exit(0);
669 } else if (strcmp(argv[i], "-static") == 0 || strcmp(argv[i], "--static") == 0
670 #ifndef HAVE_INOTIFY
671 || strcmp(argv[i], "--no-polling") == 0
672 #endif
674 wPreferences.flags.noupdates = 1;
675 } else if (strcmp(argv[i], "--help") == 0) {
676 print_help();
677 exit(0);
678 } else {
679 printf(_("%s: invalid argument '%s'\n"), argv[0], argv[i]);
680 printf(_("Try '%s --help' for more information\n"), argv[0]);
681 exit(1);
686 if (!wPreferences.flags.noupdates) {
687 /* check existence of Defaults DB directory */
688 check_defaults();
691 if (w_global.locale) {
692 setenv("LANG", w_global.locale, 1);
693 } else {
694 w_global.locale = getenv("LC_ALL");
695 if (!w_global.locale) {
696 w_global.locale = getenv("LANG");
700 setlocale(LC_ALL, "");
702 if (!w_global.locale || strcmp(w_global.locale, "C") == 0 || strcmp(w_global.locale, "POSIX") == 0)
703 w_global.locale = NULL;
704 #ifdef I18N
705 if (getenv("NLSPATH")) {
706 bindtextdomain("WindowMaker", getenv("NLSPATH"));
707 #if defined(MENU_TEXTDOMAIN)
708 bindtextdomain(MENU_TEXTDOMAIN, getenv("NLSPATH"));
709 #endif
710 } else {
711 bindtextdomain("WindowMaker", LOCALEDIR);
712 #if defined(MENU_TEXTDOMAIN)
713 bindtextdomain(MENU_TEXTDOMAIN, LOCALEDIR);
714 #endif
716 bind_textdomain_codeset("WindowMaker", "UTF-8");
717 #if defined(MENU_TEXTDOMAIN)
718 bind_textdomain_codeset(MENU_TEXTDOMAIN, "UTF-8");
719 #endif
720 textdomain("WindowMaker");
722 if (!XSupportsLocale()) {
723 wwarning(_("X server does not support locale"));
726 if (XSetLocaleModifiers("") == NULL) {
727 wwarning(_("cannot set locale modifiers"));
729 #endif
731 if (w_global.locale) {
732 char *ptr;
734 w_global.locale = wstrdup(w_global.locale);
735 ptr = strchr(w_global.locale, '.');
736 if (ptr)
737 *ptr = 0;
740 /* open display */
741 dpy = XOpenDisplay(DisplayName);
742 if (dpy == NULL) {
743 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName));
744 exit(1);
747 if (fcntl(ConnectionNumber(dpy), F_SETFD, FD_CLOEXEC) < 0) {
748 werror("error setting close-on-exec flag for X connection");
749 exit(1);
753 if (getWVisualID(0) < 0) {
755 * If unspecified, use default visual instead of waiting
756 * for wrlib/context.c:bestContext() that may end up choosing
757 * the "fake" 24 bits added by the Composite extension.
758 * This is required to avoid all sort of corruptions when
759 * composite is enabled, and at a depth other than 24.
761 setWVisualID(0, (int)DefaultVisual(dpy, DefaultScreen(dpy))->visualid);
764 /* check if the user specified a complete display name (with screen).
765 * If so, only manage the specified screen */
766 if (DisplayName)
767 pos = strchr(DisplayName, ':');
768 else
769 pos = NULL;
771 if (pos && sscanf(pos, ":%i.%i", &d, &s) == 2)
772 multiHead = False;
774 DisplayName = XDisplayName(DisplayName);
775 setenv("DISPLAY", DisplayName, 1);
777 wXModifierInitialize();
778 StartUp(!multiHead);
780 if (w_global.screen_count == 1)
781 multiHead = False;
783 execInitScript();
784 #ifdef HAVE_INOTIFY
785 inotifyWatchConfig();
786 #endif
787 EventLoop();
788 return -1;