script.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. /* Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
  2. * This library is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU Lesser General Public
  4. * License as published by the Free Software Foundation; either
  5. * version 2.1 of the License, or (at your option) any later version.
  6. *
  7. * This library is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. * Lesser General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU Lesser General Public
  13. * License along with this library; if not, write to the Free Software
  14. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  15. */
  16. /* "script.c" argv tricks for `#!' scripts.
  17. Authors: Aubrey Jaffer and Jim Blandy */
  18. #ifdef HAVE_CONFIG_H
  19. # include <config.h>
  20. #endif
  21. #include <stdio.h>
  22. #include <errno.h>
  23. #include <ctype.h>
  24. #include "libguile/_scm.h"
  25. #include "libguile/gh.h"
  26. #include "libguile/load.h"
  27. #include "libguile/version.h"
  28. #include "libguile/validate.h"
  29. #include "libguile/script.h"
  30. #ifdef HAVE_STRING_H
  31. #include <string.h>
  32. #endif
  33. #ifdef HAVE_UNISTD_H
  34. #include <unistd.h> /* for X_OK define */
  35. #endif
  36. #ifdef HAVE_IO_H
  37. #include <io.h>
  38. #endif
  39. /* Concatentate str2 onto str1 at position n and return concatenated
  40. string if file exists; 0 otherwise. */
  41. static char *
  42. scm_cat_path (char *str1, const char *str2, long n)
  43. {
  44. if (!n)
  45. n = strlen (str2);
  46. if (str1)
  47. {
  48. size_t len = strlen (str1);
  49. str1 = (char *) realloc (str1, (size_t) (len + n + 1));
  50. if (!str1)
  51. return 0L;
  52. strncat (str1 + len, str2, n);
  53. return str1;
  54. }
  55. str1 = (char *) scm_malloc ((size_t) (n + 1));
  56. if (!str1)
  57. return 0L;
  58. str1[0] = 0;
  59. strncat (str1, str2, n);
  60. return str1;
  61. }
  62. #if 0
  63. static char *
  64. scm_try_path (char *path)
  65. {
  66. FILE *f;
  67. /* fprintf(stderr, "Trying %s\n", path);fflush(stderr); */
  68. if (!path)
  69. return 0L;
  70. SCM_SYSCALL (f = fopen (path, "r");
  71. );
  72. if (f)
  73. {
  74. fclose (f);
  75. return path;
  76. }
  77. free (path);
  78. return 0L;
  79. }
  80. static char *
  81. scm_sep_init_try (char *path, const char *sep, const char *initname)
  82. {
  83. if (path)
  84. path = scm_cat_path (path, sep, 0L);
  85. if (path)
  86. path = scm_cat_path (path, initname, 0L);
  87. return scm_try_path (path);
  88. }
  89. #endif
  90. #ifndef LINE_INCREMENTORS
  91. #define LINE_INCREMENTORS '\n'
  92. #ifdef MSDOS
  93. #define WHITE_SPACES ' ':case '\t':case '\r':case '\f':case 26
  94. #else
  95. #define WHITE_SPACES ' ':case '\t':case '\r':case '\f'
  96. #endif /* def MSDOS */
  97. #endif /* ndef LINE_INCREMENTORS */
  98. #ifndef MAXPATHLEN
  99. #define MAXPATHLEN 80
  100. #endif /* ndef MAXPATHLEN */
  101. #ifndef X_OK
  102. #define X_OK 1
  103. #endif /* ndef X_OK */
  104. char *
  105. scm_find_executable (const char *name)
  106. {
  107. char tbuf[MAXPATHLEN];
  108. int i = 0, c;
  109. FILE *f;
  110. /* fprintf(stderr, "s_f_e checking access %s ->%d\n", name, access(name, X_OK)); fflush(stderr); */
  111. if (access (name, X_OK))
  112. return 0L;
  113. f = fopen (name, "r");
  114. if (!f)
  115. return 0L;
  116. if ((fgetc (f) == '#') && (fgetc (f) == '!'))
  117. {
  118. while (1)
  119. switch (c = fgetc (f))
  120. {
  121. case /*WHITE_SPACES */ ' ':
  122. case '\t':
  123. case '\r':
  124. case '\f':
  125. case EOF:
  126. tbuf[i] = 0;
  127. fclose (f);
  128. return scm_cat_path (0L, tbuf, 0L);
  129. default:
  130. tbuf[i++] = c;
  131. break;
  132. }
  133. }
  134. fclose (f);
  135. return scm_cat_path (0L, name, 0L);
  136. }
  137. /* Read a \nnn-style escape. We've just read the backslash. */
  138. static int
  139. script_get_octal (FILE *f)
  140. #define FUNC_NAME "script_get_octal"
  141. {
  142. int i;
  143. int value = 0;
  144. for (i = 0; i < 3; i++)
  145. {
  146. int c = getc (f);
  147. if ('0' <= c && c <= '7')
  148. value = (value * 8) + (c - '0');
  149. else
  150. SCM_MISC_ERROR ("malformed script: bad octal backslash escape",
  151. SCM_EOL);
  152. }
  153. return value;
  154. }
  155. #undef FUNC_NAME
  156. static int
  157. script_get_backslash (FILE *f)
  158. #define FUNC_NAME "script_get_backslash"
  159. {
  160. int c = getc (f);
  161. switch (c)
  162. {
  163. case 'a': return '\a';
  164. case 'b': return '\b';
  165. case 'f': return '\f';
  166. case 'n': return '\n';
  167. case 'r': return '\r';
  168. case 't': return '\t';
  169. case 'v': return '\v';
  170. case '\\':
  171. case ' ':
  172. case '\t':
  173. case '\n':
  174. return c;
  175. case '0': case '1': case '2': case '3':
  176. case '4': case '5': case '6': case '7':
  177. ungetc (c, f);
  178. return script_get_octal (f);
  179. case EOF:
  180. SCM_MISC_ERROR ("malformed script: backslash followed by EOF", SCM_EOL);
  181. return 0; /* not reached? */
  182. default:
  183. SCM_MISC_ERROR ("malformed script: bad backslash sequence", SCM_EOL);
  184. return 0; /* not reached? */
  185. }
  186. }
  187. #undef FUNC_NAME
  188. static char *
  189. script_read_arg (FILE *f)
  190. #define FUNC_NAME "script_read_arg"
  191. {
  192. size_t size = 7;
  193. char *buf = scm_malloc (size + 1);
  194. size_t len = 0;
  195. if (! buf)
  196. return 0;
  197. for (;;)
  198. {
  199. int c = getc (f);
  200. switch (c)
  201. {
  202. case '\\':
  203. c = script_get_backslash (f);
  204. /* The above produces a new character to add to the argument.
  205. Fall through. */
  206. default:
  207. if (len >= size)
  208. {
  209. size = (size + 1) * 2;
  210. buf = realloc (buf, size);
  211. if (! buf)
  212. return 0;
  213. }
  214. buf[len++] = c;
  215. break;
  216. case '\n':
  217. /* This may terminate an arg now, but it will terminate the
  218. entire list next time through. */
  219. ungetc ('\n', f);
  220. case EOF:
  221. if (len == 0)
  222. {
  223. free (buf);
  224. return 0;
  225. }
  226. /* Otherwise, those characters terminate the argument; fall
  227. through. */
  228. case ' ':
  229. buf[len] = '\0';
  230. return buf;
  231. case '\t':
  232. free (buf);
  233. SCM_MISC_ERROR ("malformed script: TAB in meta-arguments", SCM_EOL);
  234. return 0; /* not reached? */
  235. }
  236. }
  237. }
  238. #undef FUNC_NAME
  239. static int
  240. script_meta_arg_P (char *arg)
  241. {
  242. if ('\\' != arg[0])
  243. return 0L;
  244. #ifdef MSDOS
  245. return !arg[1];
  246. #else
  247. switch (arg[1])
  248. {
  249. case 0:
  250. case '%':
  251. case WHITE_SPACES:
  252. return !0;
  253. default:
  254. return 0L;
  255. }
  256. #endif
  257. }
  258. char **
  259. scm_get_meta_args (int argc, char **argv)
  260. {
  261. int nargc = argc, argi = 1, nargi = 1;
  262. char *narg, **nargv;
  263. if (!(argc > 2 && script_meta_arg_P (argv[1])))
  264. return 0L;
  265. if (!(nargv = (char **) scm_malloc ((1 + nargc) * sizeof (char *))))
  266. return 0L;
  267. nargv[0] = argv[0];
  268. while (((argi + 1) < argc) && (script_meta_arg_P (argv[argi])))
  269. {
  270. FILE *f = fopen (argv[++argi], "r");
  271. if (f)
  272. {
  273. nargc--; /* to compensate for replacement of '\\' */
  274. while (1)
  275. switch (getc (f))
  276. {
  277. case EOF:
  278. return 0L;
  279. default:
  280. continue;
  281. case '\n':
  282. goto found_args;
  283. }
  284. found_args:
  285. while ((narg = script_read_arg (f)))
  286. if (!(nargv = (char **) realloc (nargv,
  287. (1 + ++nargc) * sizeof (char *))))
  288. return 0L;
  289. else
  290. nargv[nargi++] = narg;
  291. fclose (f);
  292. nargv[nargi++] = argv[argi++];
  293. }
  294. }
  295. while (argi <= argc)
  296. nargv[nargi++] = argv[argi++];
  297. return nargv;
  298. }
  299. int
  300. scm_count_argv (char **argv)
  301. {
  302. int argc = 0;
  303. while (argv[argc])
  304. argc++;
  305. return argc;
  306. }
  307. /* For use in error messages. */
  308. char *scm_usage_name = 0;
  309. void
  310. scm_shell_usage (int fatal, char *message)
  311. {
  312. FILE *fp = (fatal ? stderr : stdout);
  313. if (message)
  314. fprintf (fp, "%s\n", message);
  315. fprintf (fp,
  316. "Usage: %s OPTION ...\n"
  317. "Evaluate Scheme code, interactively or from a script.\n"
  318. "\n"
  319. " [-s] FILE load Scheme source code from FILE, and exit\n"
  320. " -c EXPR evalute Scheme expression EXPR, and exit\n"
  321. " -- stop scanning arguments; run interactively\n"
  322. "The above switches stop argument processing, and pass all\n"
  323. "remaining arguments as the value of (command-line).\n"
  324. "If FILE begins with `-' the -s switch is mandatory.\n"
  325. "\n"
  326. " -L DIRECTORY add DIRECTORY to the front of the module load path\n"
  327. " -l FILE load Scheme source code from FILE\n"
  328. " -e FUNCTION after reading script, apply FUNCTION to\n"
  329. " command line arguments\n"
  330. " -ds do -s script at this point\n"
  331. " --debug start with debugging evaluator and backtraces\n"
  332. " --no-debug start with normal evaluator\n"
  333. " Default is to enable debugging for interactive\n"
  334. " use, but not for `-s' and `-c'.\n"
  335. " -q inhibit loading of user init file\n"
  336. " --emacs enable Emacs protocol (experimental)\n"
  337. " --use-srfi=LS load SRFI modules for the SRFIs in LS,\n"
  338. " which is a list of numbers like \"2,13,14\"\n"
  339. " -h, --help display this help and exit\n"
  340. " -v, --version display version information and exit\n"
  341. " \\ read arguments from following script lines\n"
  342. "\n"
  343. "Please report bugs to bug-guile@gnu.org\n",
  344. scm_usage_name);
  345. if (fatal)
  346. exit (fatal);
  347. }
  348. /* Some symbols used by the command-line compiler. */
  349. SCM_SYMBOL (sym_load, "load");
  350. SCM_SYMBOL (sym_eval_string, "eval-string");
  351. SCM_SYMBOL (sym_command_line, "command-line");
  352. SCM_SYMBOL (sym_begin, "begin");
  353. SCM_SYMBOL (sym_turn_on_debugging, "turn-on-debugging");
  354. SCM_SYMBOL (sym_load_user_init, "load-user-init");
  355. SCM_SYMBOL (sym_top_repl, "top-repl");
  356. SCM_SYMBOL (sym_quit, "quit");
  357. SCM_SYMBOL (sym_use_srfis, "use-srfis");
  358. SCM_SYMBOL (sym_load_path, "%load-path");
  359. SCM_SYMBOL (sym_set_x, "set!");
  360. SCM_SYMBOL (sym_cons, "cons");
  361. SCM_SYMBOL (sym_at, "@");
  362. SCM_SYMBOL (sym_atat, "@@");
  363. SCM_SYMBOL (sym_main, "main");
  364. /* Given an array of command-line switches, return a Scheme expression
  365. to carry out the actions specified by the switches.
  366. If you told me this should have been written in Scheme, I'd
  367. probably agree. I'd say I didn't feel comfortable doing that in
  368. the present system. You'd say, well, fix the system so you are
  369. comfortable doing that. I'd agree again. *shrug*
  370. */
  371. static char guile[] = "guile";
  372. static int
  373. all_symbols (SCM list)
  374. {
  375. while (scm_is_pair (list))
  376. {
  377. if (!scm_is_symbol (SCM_CAR (list)))
  378. return 0;
  379. list = SCM_CDR (list);
  380. }
  381. return 1;
  382. }
  383. SCM
  384. scm_compile_shell_switches (int argc, char **argv)
  385. {
  386. SCM tail = SCM_EOL; /* We accumulate the list backwards,
  387. and then reverse! it before we
  388. return it. */
  389. SCM do_script = SCM_EOL; /* The element of the list containing
  390. the "load" command, in case we get
  391. the "-ds" switch. */
  392. SCM entry_point = SCM_EOL; /* for -e switch */
  393. SCM user_load_path = SCM_EOL; /* for -L switch */
  394. int interactive = 1; /* Should we go interactive when done? */
  395. int inhibit_user_init = 0; /* Don't load user init file */
  396. int use_emacs_interface = 0;
  397. int turn_on_debugging = 0;
  398. int dont_turn_on_debugging = 0;
  399. int i;
  400. char *argv0 = guile;
  401. if (argc > 0)
  402. {
  403. argv0 = argv[0];
  404. scm_usage_name = strrchr (argv[0], '/');
  405. if (! scm_usage_name)
  406. scm_usage_name = argv[0];
  407. else
  408. scm_usage_name++;
  409. }
  410. if (! scm_usage_name)
  411. scm_usage_name = guile;
  412. for (i = 1; i < argc; i++)
  413. {
  414. if ((! strcmp (argv[i], "-s")) || (argv[i][0] != '-')) /* load script */
  415. {
  416. if ((argv[i][0] == '-') && (++i >= argc))
  417. scm_shell_usage (1, "missing argument to `-s' switch");
  418. /* If we specified the -ds option, do_script points to the
  419. cdr of an expression like (load #f); we replace the car
  420. (i.e., the #f) with the script name. */
  421. if (!scm_is_null (do_script))
  422. {
  423. SCM_SETCAR (do_script, scm_from_locale_string (argv[i]));
  424. do_script = SCM_EOL;
  425. }
  426. else
  427. /* Construct an application of LOAD to the script name. */
  428. tail = scm_cons (scm_cons2 (sym_load,
  429. scm_from_locale_string (argv[i]),
  430. SCM_EOL),
  431. tail);
  432. argv0 = argv[i];
  433. i++;
  434. interactive = 0;
  435. break;
  436. }
  437. else if (! strcmp (argv[i], "-c")) /* evaluate expr */
  438. {
  439. if (++i >= argc)
  440. scm_shell_usage (1, "missing argument to `-c' switch");
  441. tail = scm_cons (scm_cons2 (sym_eval_string,
  442. scm_from_locale_string (argv[i]),
  443. SCM_EOL),
  444. tail);
  445. i++;
  446. interactive = 0;
  447. break;
  448. }
  449. else if (! strcmp (argv[i], "--")) /* end args; go interactive */
  450. {
  451. i++;
  452. break;
  453. }
  454. else if (! strcmp (argv[i], "-l")) /* load a file */
  455. {
  456. if (++i < argc)
  457. tail = scm_cons (scm_cons2 (sym_load,
  458. scm_from_locale_string (argv[i]),
  459. SCM_EOL),
  460. tail);
  461. else
  462. scm_shell_usage (1, "missing argument to `-l' switch");
  463. }
  464. else if (! strcmp (argv[i], "-L")) /* add to %load-path */
  465. {
  466. if (++i < argc)
  467. user_load_path =
  468. scm_cons (scm_list_3 (sym_set_x,
  469. sym_load_path,
  470. scm_list_3 (sym_cons,
  471. scm_from_locale_string (argv[i]),
  472. sym_load_path)),
  473. user_load_path);
  474. else
  475. scm_shell_usage (1, "missing argument to `-L' switch");
  476. }
  477. else if (! strcmp (argv[i], "-e")) /* entry point */
  478. {
  479. if (++i < argc)
  480. {
  481. SCM port
  482. = scm_open_input_string (scm_from_locale_string (argv[i]));
  483. SCM arg1 = scm_read (port);
  484. SCM arg2 = scm_read (port);
  485. /* Recognize syntax of certain versions of Guile 1.4 and
  486. transform to (@ MODULE-NAME FUNC).
  487. */
  488. if (scm_is_false (scm_eof_object_p (arg2)))
  489. entry_point = scm_list_3 (sym_at, arg1, arg2);
  490. else if (scm_is_pair (arg1)
  491. && !(scm_is_eq (SCM_CAR (arg1), sym_at)
  492. || scm_is_eq (SCM_CAR (arg1), sym_atat))
  493. && all_symbols (arg1))
  494. entry_point = scm_list_3 (sym_at, arg1, sym_main);
  495. else
  496. entry_point = arg1;
  497. }
  498. else
  499. scm_shell_usage (1, "missing argument to `-e' switch");
  500. }
  501. else if (! strcmp (argv[i], "-ds")) /* do script here */
  502. {
  503. /* We put a dummy "load" expression, and let the -s put the
  504. filename in. */
  505. if (!scm_is_null (do_script))
  506. scm_shell_usage (1, "the -ds switch may only be specified once");
  507. do_script = scm_cons (SCM_BOOL_F, SCM_EOL);
  508. tail = scm_cons (scm_cons (sym_load, do_script),
  509. tail);
  510. }
  511. else if (! strcmp (argv[i], "--debug"))
  512. {
  513. turn_on_debugging = 1;
  514. dont_turn_on_debugging = 0;
  515. }
  516. else if (! strcmp (argv[i], "--no-debug"))
  517. {
  518. dont_turn_on_debugging = 1;
  519. turn_on_debugging = 0;
  520. }
  521. else if (! strcmp (argv[i], "--emacs")) /* use emacs protocol */
  522. use_emacs_interface = 1;
  523. else if (! strcmp (argv[i], "-q")) /* don't load user init */
  524. inhibit_user_init = 1;
  525. else if (! strncmp (argv[i], "--use-srfi=", 11)) /* load SRFIs */
  526. {
  527. SCM srfis = SCM_EOL; /* List of requested SRFIs. */
  528. char * p = argv[i] + 11;
  529. while (*p)
  530. {
  531. long num;
  532. char * end;
  533. num = strtol (p, &end, 10);
  534. if (end - p > 0)
  535. {
  536. srfis = scm_cons (scm_from_long (num), srfis);
  537. if (*end)
  538. {
  539. if (*end == ',')
  540. p = end + 1;
  541. else
  542. scm_shell_usage (1, "invalid SRFI specification");
  543. }
  544. else
  545. break;
  546. }
  547. else
  548. scm_shell_usage (1, "invalid SRFI specification");
  549. }
  550. if (scm_ilength (srfis) <= 0)
  551. scm_shell_usage (1, "invalid SRFI specification");
  552. srfis = scm_reverse_x (srfis, SCM_UNDEFINED);
  553. tail = scm_cons (scm_list_2 (sym_use_srfis,
  554. scm_list_2 (scm_sym_quote, srfis)),
  555. tail);
  556. }
  557. else if (! strcmp (argv[i], "-h")
  558. || ! strcmp (argv[i], "--help"))
  559. {
  560. scm_shell_usage (0, 0);
  561. exit (0);
  562. }
  563. else if (! strcmp (argv[i], "-v")
  564. || ! strcmp (argv[i], "--version"))
  565. {
  566. /* Print version number. */
  567. printf ("Guile %s\n"
  568. "Copyright (c) 1995, 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation\n"
  569. "Guile may be distributed under the terms of the GNU General Public Licence;\n"
  570. "certain other uses are permitted as well. For details, see the file\n"
  571. "`COPYING', which is included in the Guile distribution.\n"
  572. "There is no warranty, to the extent permitted by law.\n",
  573. scm_to_locale_string (scm_version ()));
  574. exit (0);
  575. }
  576. else
  577. {
  578. fprintf (stderr, "%s: Unrecognized switch `%s'\n",
  579. scm_usage_name, argv[i]);
  580. scm_shell_usage (1, 0);
  581. }
  582. }
  583. /* Check to make sure the -ds got a -s. */
  584. if (!scm_is_null (do_script))
  585. scm_shell_usage (1, "the `-ds' switch requires the use of `-s' as well");
  586. /* Make any remaining arguments available to the
  587. script/command/whatever. */
  588. scm_set_program_arguments (argc ? argc - i : 0, argv + i, argv0);
  589. /* If the --emacs switch was set, now is when we process it. */
  590. scm_c_define ("use-emacs-interface", scm_from_bool (use_emacs_interface));
  591. /* Handle the `-e' switch, if it was specified. */
  592. if (!scm_is_null (entry_point))
  593. tail = scm_cons (scm_cons2 (entry_point,
  594. scm_cons (sym_command_line, SCM_EOL),
  595. SCM_EOL),
  596. tail);
  597. /* If we didn't end with a -c or a -s, start the repl. */
  598. if (interactive)
  599. {
  600. tail = scm_cons (scm_cons (sym_top_repl, SCM_EOL), tail);
  601. }
  602. else
  603. {
  604. /* After doing all the other actions prescribed by the command line,
  605. quit. */
  606. tail = scm_cons (scm_cons (sym_quit, SCM_EOL),
  607. tail);
  608. }
  609. /* After the following line, actions will be added to the front. */
  610. tail = scm_reverse_x (tail, SCM_UNDEFINED);
  611. /* add the user-specified load path here, so it won't be in effect
  612. during the loading of the user's customization file. */
  613. if(!scm_is_null(user_load_path))
  614. {
  615. tail = scm_append_x( scm_cons2(user_load_path, tail, SCM_EOL) );
  616. }
  617. /* If we didn't end with a -c or a -s and didn't supply a -q, load
  618. the user's customization file. */
  619. if (interactive && !inhibit_user_init)
  620. {
  621. tail = scm_cons (scm_cons (sym_load_user_init, SCM_EOL), tail);
  622. }
  623. /* If debugging was requested, or we are interactive and debugging
  624. was not explicitly turned off, turn on debugging. */
  625. if (turn_on_debugging || (interactive && !dont_turn_on_debugging))
  626. {
  627. tail = scm_cons (scm_cons (sym_turn_on_debugging, SCM_EOL), tail);
  628. }
  629. {
  630. SCM val = scm_cons (sym_begin, tail);
  631. #if 0
  632. scm_write (val, SCM_UNDEFINED);
  633. scm_newline (SCM_UNDEFINED);
  634. #endif
  635. return val;
  636. }
  637. }
  638. void
  639. scm_shell (int argc, char **argv)
  640. {
  641. /* If present, add SCSH-style meta-arguments from the top of the
  642. script file to the argument vector. See the SCSH manual: "The
  643. meta argument" for more details. */
  644. {
  645. char **new_argv = scm_get_meta_args (argc, argv);
  646. if (new_argv)
  647. {
  648. argv = new_argv;
  649. argc = scm_count_argv (new_argv);
  650. }
  651. }
  652. exit (scm_exit_status (scm_eval_x (scm_compile_shell_switches (argc, argv),
  653. scm_current_module ())));
  654. }
  655. void
  656. scm_init_script ()
  657. {
  658. #include "libguile/script.x"
  659. }
  660. /*
  661. Local Variables:
  662. c-file-style: "gnu"
  663. End:
  664. */