guile.c 3.0 KB

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