guile.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* Copyright 1996-1997,2000-2001,2006,2008,2011,2013,2018,2021
  2. Free Software Foundation, Inc.
  3. This file is part of Guile.
  4. Guile is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Lesser General Public License as published
  6. by the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Guile is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  11. License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with Guile. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. /* This is the 'main' function for the `guile' executable. It is not
  16. included in libguile.a.
  17. Eventually, we hope this file will be automatically generated,
  18. based on the list of installed, statically linked libraries on the
  19. system. For now, please don't put interesting code in here. */
  20. #ifdef HAVE_CONFIG_H
  21. # include <config.h>
  22. #endif
  23. #include <locale.h>
  24. #include <stdio.h>
  25. #ifdef HAVE_WINSOCK2_H
  26. #include <winsock2.h>
  27. #endif
  28. #include <libguile.h>
  29. static void
  30. inner_main (void *closure SCM_UNUSED, int argc, char **argv)
  31. {
  32. #ifdef __MINGW32__
  33. /* This is necessary to startup the Winsock API under Win32. */
  34. WSADATA WSAData;
  35. WSAStartup (0x0202, &WSAData);
  36. #endif /* __MINGW32__ */
  37. /* module initializations would go here */
  38. scm_shell (argc, argv);
  39. #ifdef __MINGW32__
  40. WSACleanup ();
  41. #endif /* __MINGW32__ */
  42. }
  43. static int
  44. get_integer_from_environment (const char *var, int def)
  45. {
  46. char *end = 0;
  47. char *val = getenv (var);
  48. long res = def;
  49. if (!val)
  50. return def;
  51. res = strtol (val, &end, 10);
  52. if (end == val)
  53. {
  54. fprintf (stderr, "guile: warning: invalid %s: %s\n", var, val);
  55. return def;
  56. }
  57. return res;
  58. }
  59. static int
  60. should_install_locale (void)
  61. {
  62. /* If the GUILE_INSTALL_LOCALE environment variable is unset,
  63. or set to a nonzero value, we should install the locale via
  64. setlocale(). */
  65. return get_integer_from_environment ("GUILE_INSTALL_LOCALE", 1);
  66. }
  67. int
  68. main (int argc, char **argv)
  69. {
  70. /* If we should install a locale, do it right at the beginning so that
  71. string conversion for command-line arguments, along with possible
  72. error messages, use the right locale. See
  73. <https://lists.gnu.org/archive/html/guile-devel/2011-11/msg00041.html>
  74. for the rationale. */
  75. if (should_install_locale () && setlocale (LC_ALL, "") == NULL)
  76. fprintf (stderr, "guile: warning: failed to install locale\n");
  77. scm_boot_guile (argc, argv, inner_main, 0);
  78. return 0; /* never reached */
  79. }