1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

add --listen command line argument.

* libguile/script.c (scm_shell_usage, scm_compile_shell_switches): Add a
  --listen argument to spawn a REPL server, possibly specifying the port
  or path to listen on. The goal is for this to be the default way to
  allow debugging via Emacs or simply using netcat.
This commit is contained in:
Andy Wingo 2010-10-10 12:56:53 +02:00
parent d30542c2b7
commit a531e76a74

View file

@ -386,6 +386,8 @@ scm_shell_usage (int fatal, char *message)
" --no-autocompile disable automatic source file compilation\n"
" Default is to enable autocompilation of source\n"
" files.\n"
" --listen[=P] Listen on a local port or a path for REPL clients.\n"
" If P is not given, the default is local port 37146.\n"
" -q inhibit loading of user init file\n"
" --use-srfi=LS load SRFI modules for the SRFIs in LS,\n"
" which is a list of numbers like \"2,13,14\"\n"
@ -640,6 +642,60 @@ scm_compile_shell_switches (int argc, char **argv)
tail);
}
else if (! strncmp (argv[i], "--listen", 8) /* start a repl server */
&& (argv[i][8] == '\0' || argv[i][8] == '='))
{
const char default_template[] =
"(@@ (system repl server) (spawn-server))";
const char port_template[] =
"(@@ (system repl server)"
" (spawn-server (make-tcp-server-socket #:port ~a)))";
const char path_template[] =
"(@@ (system repl server)"
" (spawn-server (make-unix-domain-server-socket #:path ~s)))";
SCM form_str = SCM_BOOL_F;
char * p = argv[i] + 8;
if (*p == '=')
{
p++;
if (*p > '0' && *p <= '9')
{
/* --listen=PORT */
SCM port = scm_string_to_number (scm_from_locale_string (p),
SCM_UNDEFINED);
if (scm_is_false (port))
scm_shell_usage (1, "invalid port for --listen");
form_str =
scm_simple_format (SCM_BOOL_F,
scm_from_locale_string (port_template),
scm_list_1 (port));
}
else if (*p == '/')
{
/* --listen=/PATH/TO/SOCKET */
SCM path = scm_from_locale_string (p);
form_str =
scm_simple_format (SCM_BOOL_F,
scm_from_locale_string (path_template),
scm_list_1 (path));
}
else
{
/* unknown --listen arg */
scm_shell_usage (1, "unknown argument to --listen");
}
}
else
form_str = scm_from_locale_string (default_template);
tail = scm_cons (scm_read (scm_open_input_string (form_str)), tail);
}
else if (! strcmp (argv[i], "-h")
|| ! strcmp (argv[i], "--help"))
{