feature.c 3.5 KB

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