feature.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* Copyright 1995-1996,1998-2004,2006-2007,2009,2011,2013,2018
  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. #ifdef HAVE_CONFIG_H
  16. # include <config.h>
  17. #endif
  18. #include <string.h>
  19. #include "fluids.h"
  20. #include "gsubr.h"
  21. #include "modules.h"
  22. #include "pairs.h"
  23. #include "strings.h"
  24. #include "symbols.h"
  25. #include "variable.h"
  26. #include "feature.h"
  27. SCM scm_program_arguments_fluid;
  28. static SCM features_var;
  29. void
  30. scm_add_feature (const char *str)
  31. {
  32. SCM old = SCM_VARIABLE_REF (features_var);
  33. SCM new = scm_cons (scm_from_utf8_symbol (str), old);
  34. SCM_VARIABLE_SET (features_var, new);
  35. }
  36. SCM_DEFINE (scm_program_arguments, "program-arguments", 0, 0, 0,
  37. (),
  38. "@deffnx {Scheme Procedure} command-line\n"
  39. "Return the list of command line arguments passed to Guile, as a list of\n"
  40. "strings. The list includes the invoked program name, which is usually\n"
  41. "@code{\"guile\"}, but excludes switches and parameters for command line\n"
  42. "options like @code{-e} and @code{-l}.")
  43. #define FUNC_NAME s_scm_program_arguments
  44. {
  45. return scm_fluid_ref (scm_program_arguments_fluid);
  46. }
  47. #undef FUNC_NAME
  48. /* Set the value returned by program-arguments, given ARGC and ARGV.
  49. If FIRST is non-zero, make it the first element; we do this in
  50. situations where other code (like getopt) has parsed out a few
  51. arguments, but we still want the script name to be the first
  52. element. */
  53. void
  54. scm_set_program_arguments (int argc, char **argv, char *first)
  55. {
  56. SCM args = scm_makfromstrs (argc, argv);
  57. if (first)
  58. args = scm_cons (scm_from_locale_string (first), args);
  59. scm_fluid_set_x (scm_program_arguments_fluid, args);
  60. }
  61. SCM_DEFINE (scm_set_program_arguments_scm, "set-program-arguments", 1, 0, 0,
  62. (SCM lst),
  63. "Set the command line arguments to be returned by\n"
  64. "@code{program-arguments} (and @code{command-line}). @var{lst}\n"
  65. "should be a list of strings, the first of which is the program\n"
  66. "name (either a script name, or just @code{\"guile\"}).\n"
  67. "\n"
  68. "Program arguments are held in a fluid and therefore have a\n"
  69. "separate value in each Guile thread. Neither the list nor the\n"
  70. "strings within it are copied, so should not be modified later.")
  71. #define FUNC_NAME s_scm_set_program_arguments_scm
  72. {
  73. return scm_fluid_set_x (scm_program_arguments_fluid, lst);
  74. }
  75. #undef FUNC_NAME
  76. void
  77. scm_init_feature()
  78. {
  79. scm_program_arguments_fluid = scm_make_fluid ();
  80. features_var = scm_c_define ("*features*", SCM_EOL);
  81. #ifndef _Windows
  82. scm_add_feature("system");
  83. #endif
  84. #ifndef GO32
  85. scm_add_feature("char-ready?");
  86. #endif
  87. #if SCM_USE_PTHREAD_THREADS
  88. scm_add_feature ("threads");
  89. #endif
  90. #include "feature.x"
  91. }