summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2010-10-10 12:56:53 +0200
committerAndy Wingo <wingo@pobox.com>2010-10-10 12:56:53 +0200
commita531e76a74d4517aec0888d38d3c5e412ce67d1a (patch)
tree47db4b6af7af1745b0cdf38f36ac5cf5ccca9ab3
parentd30542c2b7e52be9e5293b4d4ef065c64316872c (diff)
downloadguile-a531e76a74d4517aec0888d38d3c5e412ce67d1a.tar.gz
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.
-rw-r--r--libguile/script.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/libguile/script.c b/libguile/script.c
index 318e5aa15..caf3ac681 100644
--- a/libguile/script.c
+++ b/libguile/script.c
@@ -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"))
{