home *** CD-ROM | disk | FTP | other *** search
- /* main.c -- Entry point for Jade
- Copyright (C) 1993, 1994 John Harper <jsh@ukc.ac.uk>
-
- This file is part of Jade.
-
- Jade is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- Jade is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Jade; see the file COPYING. If not, write to
- the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
-
- #include "jade.h"
- #include "jade_protos.h"
- #include "revision.h"
-
- #include <string.h>
-
- #define INIT_SCR "init"
-
- _PR int main(int, char **);
- _PR void doconmsg(u_char *);
- _PR void main_init(void);
-
- _PR u_char NoMemMsg[];
- u_char NoMemMsg[] = "panic: no memory!";
- _PR bool ILock;
- bool ILock;
- _PR STRMEM MainStrMem;
- STRMEM MainStrMem;
-
- _PR int RecurseDepth;
- int RecurseDepth = -1;
-
- _PR VALUE sym_exit, sym_quit, sym_top_level, sym_command_line_args;
- VALUE sym_exit, sym_quit, sym_top_level, sym_command_line_args;
-
- static u_char *InitScript = INIT_SCR;
-
- static void
- usage(void)
- {
- fputs("usage: jade [SYSTEM-OPTIONS...] [STANDARD-OPTIONS...] [LISP-OPTIONS...]\n", stderr);
- sys_usage();
- fputs("STANDARD-OPTIONS are,\n"
- " -rc FILE use FILE instead of `init.jl' to boot from\n"
- " -v print version/revision details\n"
- " -log-msgs print all messages to standard-error as well\n"
- "and LISP-OPTIONS are,\n"
- " -f FUNCTION call the Lisp function FUNCTION\n"
- " -l FILE load the file of Lisp forms called FILE\n"
- " -q quit\n"
- " FILE load FILE into a new buffer\n"
- , stderr);
- }
-
- static int
- getmainoptions(int *argc_p, char ***argv_p)
- {
- int argc = *argc_p;
- char **argv = *argv_p;
- VALUE head, *last;
- while(argc && (**argv == '-'))
- {
- if((argc >= 2) && !strcmp("-rc", *argv))
- {
- InitScript = *(++argv);
- argc--;
- }
- else if(!strcmp("-v", *argv))
- {
- doconmsg(VERSSTRING "\n");
- return(FALSE);
- }
- else if(!strcmp("-log-msgs", *argv))
- LogMsgs = TRUE;
- else if(!strcmp("-?", *argv) || !strcmp("-help", *argv))
- {
- usage();
- return(FALSE);
- }
- else
- break;
- argc--;
- argv++;
- }
- /* any command line args left now get made into a list of strings
- in symbol "command-line-args". */
- head = sym_nil;
- last = &head;
- while(argc > 0)
- {
- *last = cmd_cons(valstrdup(*argv), sym_nil);
- last = &VCDR(*last);
- argc--;
- argv++;
- }
- VSYM(sym_command_line_args)->sym_Value = head;
- *argc_p = argc;
- *argv_p = argv;
- return(TRUE);
- }
-
- int
- main(int argc, char **argv)
- {
- int rc = 5;
- if(!initmem())
- return(10);
- sm_init(&MainStrMem);
- values_init();
- if(symbols_init() && initwinsys(&argc, &argv))
- {
- values_init2();
- lisp_init();
- lispcmds_init();
- lispmach_init();
- buffers_init();
- commandline_init();
- edit_init();
- find_init();
- io_init();
- keys_init();
- main_init();
- misc_init();
- movement_init();
- refresh_init();
- streams_init();
- windows_init();
- sys_misc_init();
- sys_windows_init();
- #ifdef HAVE_UNIX
- sys_proc_init();
- #endif
- if(getmainoptions(&argc, &argv) && firstbuffer())
- {
- VALUE arg, res;
- if((arg = valstrdup(InitScript))
- && (res = cmd_load(arg, sym_nil, sym_nil, sym_nil)))
- {
- rc = 0;
- cursor(CurrVW, CURS_ON);
- res = eventloop();
- }
- else if(ThrowValue && VCAR(ThrowValue) == sym_quit)
- {
- if(NUMBERP(VCDR(ThrowValue)))
- rc = VNUM(VCDR(ThrowValue));
- else
- rc = 0;
- }
- else
- doconmsg("jade: error in initialisation script\n");
- #ifdef HAVE_UNIX
- sys_proc_kill();
- #endif
- windows_kill();
- buffers_kill();
- commandline_kill();
- keys_kill();
- streams_kill();
- }
- symbols_kill();
- killwinsys();
- }
- values_kill();
- sm_kill(&MainStrMem);
- killmem();
- return(rc);
- }
-
- _PR VALUE cmd_recursive_edit(void);
- DEFUN("recursive-edit", cmd_recursive_edit, subr_recursive_edit, (void), V_Subr0, DOC_recursive_edit) /*
- ::doc:recursive_edit::
- (recursive-edit)
- Enter a new recursive-edit.
- ::end:: */
- {
- VALUE res;
- cursor(CurrVW, CURS_ON);
- res = eventloop();
- if(CurrVW)
- cursor(CurrVW, CURS_OFF);
- return(res);
- }
-
- _PR VALUE cmd_recursion_depth(void);
- DEFUN("recursion-depth", cmd_recursion_depth, subr_recursion_depth, (void), V_Subr0, DOC_recursion_depth) /*
- ::doc:recursion_depth::
- (recursion-depth)
- Returns the number of recursive-edit's deep we are, zero signifies the
- original level.
- ::end:: */
- {
- return(newnumber(RecurseDepth));
- }
-
- _PR VALUE cmd_input_lock(VALUE status);
- DEFUN("input-lock", cmd_input_lock, subr_input_lock, (VALUE args), V_SubrN, DOC_input_lock) /*
- ::doc:input_lock::
- (input-lock [STATUS])
- Sets or returns the status of the input lock. When this value is non-zero
- no user input is accepted, only messages from ARexx can get through.
- ::end:: */
- {
- if(CONSP(args))
- {
- args = VCAR(args);
- if(NILP(args))
- ILock = FALSE;
- else
- ILock = TRUE;
- }
- if(ILock)
- return(sym_t);
- return(sym_nil);
- }
-
- void
- main_init(void)
- {
- ADD_SUBR(subr_recursive_edit);
- ADD_SUBR(subr_recursion_depth);
- ADD_SUBR(subr_input_lock);
- INTERN(sym_quit, "quit");
- INTERN(sym_exit, "exit");
- INTERN(sym_top_level, "top-level");
- INTERN(sym_command_line_args, "command-line-args");
- }
-