feature.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* Copyright (C) 1995,1996,1998,1999,2000,2001,2002, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
  2. *
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Lesser General Public License
  5. * as published by the Free Software Foundation; either version 3 of
  6. * the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * Lesser General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public
  14. * License along with this library; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. * 02110-1301 USA
  17. */
  18. #ifdef HAVE_CONFIG_H
  19. # include <config.h>
  20. #endif
  21. #ifdef HAVE_STRING_H
  22. #include <string.h>
  23. #endif
  24. #include "libguile/_scm.h"
  25. #include "libguile/root.h"
  26. #include "libguile/strings.h"
  27. #include "libguile/validate.h"
  28. #include "libguile/fluids.h"
  29. #include "libguile/feature.h"
  30. static SCM progargs_fluid;
  31. static SCM features_var;
  32. void
  33. scm_add_feature (const char *str)
  34. {
  35. SCM old = SCM_VARIABLE_REF (features_var);
  36. SCM new = scm_cons (scm_from_locale_symbol (str), old);
  37. SCM_VARIABLE_SET (features_var, new);
  38. }
  39. SCM_DEFINE (scm_program_arguments, "program-arguments", 0, 0, 0,
  40. (),
  41. "@deffnx {Scheme Procedure} command-line\n"
  42. "Return the list of command line arguments passed to Guile, as a list of\n"
  43. "strings. The list includes the invoked program name, which is usually\n"
  44. "@code{\"guile\"}, but excludes switches and parameters for command line\n"
  45. "options like @code{-e} and @code{-l}.")
  46. #define FUNC_NAME s_scm_program_arguments
  47. {
  48. return scm_fluid_ref (progargs_fluid);
  49. }
  50. #undef FUNC_NAME
  51. /* Set the value returned by program-arguments, given ARGC and ARGV.
  52. If FIRST is non-zero, make it the first element; we do this in
  53. situations where other code (like getopt) has parsed out a few
  54. arguments, but we still want the script name to be the first
  55. element. */
  56. void
  57. scm_set_program_arguments (int argc, char **argv, char *first)
  58. {
  59. SCM args = scm_makfromstrs (argc, argv);
  60. if (first)
  61. args = scm_cons (scm_from_locale_string (first), args);
  62. scm_fluid_set_x (progargs_fluid, args);
  63. }
  64. SCM_DEFINE (scm_set_program_arguments_scm, "set-program-arguments", 1, 0, 0,
  65. (SCM lst),
  66. "Set the command line arguments to be returned by\n"
  67. "@code{program-arguments} (and @code{command-line}). @var{lst}\n"
  68. "should be a list of strings, the first of which is the program\n"
  69. "name (either a script name, or just @code{\"guile\"}).\n"
  70. "\n"
  71. "Program arguments are held in a fluid and therefore have a\n"
  72. "separate value in each Guile thread. Neither the list nor the\n"
  73. "strings within it are copied, so should not be modified later.")
  74. #define FUNC_NAME s_scm_set_program_arguments_scm
  75. {
  76. return scm_fluid_set_x (progargs_fluid, lst);
  77. }
  78. #undef FUNC_NAME
  79. void
  80. scm_init_feature()
  81. {
  82. progargs_fluid = scm_permanent_object (scm_make_fluid ());
  83. features_var = scm_c_define ("*features*", SCM_EOL);
  84. #ifndef _Windows
  85. scm_add_feature("system");
  86. #endif
  87. #ifdef vms
  88. scm_add_feature(s_ed);
  89. #endif
  90. #ifdef SICP
  91. scm_add_feature("sicp");
  92. #endif
  93. #ifndef GO32
  94. scm_add_feature("char-ready?");
  95. #endif
  96. #ifndef CHEAP_CONTINUATIONS
  97. scm_add_feature ("full-continuation");
  98. #endif
  99. #if SCM_USE_PTHREAD_THREADS
  100. scm_add_feature ("threads");
  101. #endif
  102. scm_c_define ("char-code-limit", scm_from_int (SCM_CHAR_CODE_LIMIT));
  103. #include "libguile/feature.x"
  104. }
  105. /*
  106. Local Variables:
  107. c-file-style: "gnu"
  108. End:
  109. */