]> git.donarmstrong.com Git - lilypond.git/commitdiff
Use be_safe_global for determining whether file inclusion
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Tue, 2 Jan 2007 22:41:38 +0000 (23:41 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Tue, 2 Jan 2007 22:41:38 +0000 (23:41 +0100)
is allowed.

lily/includable-lexer.cc
lily/include/includable-lexer.hh
lily/include/lily-lexer.hh
lily/lexer.ll
lily/lily-lexer-scheme.cc
lily/lily-lexer.cc
lily/lily-parser.cc

index 0668b91d81e8e14e24e080f52e69b2b9e790aa4d..29b7d9e5f3a025392571f0784ac1e2d3bad77497 100644 (file)
@@ -41,19 +41,12 @@ Includable_lexer::Includable_lexer ()
 #if HAVE_FLEXLEXER_YY_CURRENT_BUFFER
   yy_current_buffer = 0;
 #endif
-  allow_includes_ = true;
 }
 
 /** Set the new input file to NAME, remember old file.  */
 void
 Includable_lexer::new_input (string name, Sources *sources)
 {
-  if (!allow_includes_)
-    {
-      LexerError (_ ("include files are not allowed in safe mode").c_str ());
-      return;
-    }
-
   Source_file *file = sources->get_file (&name);
   if (!file)
     {
index 4b992b8714324a8f58e07b198dc2a11f5f1b928a..c103ba97f52579565aecc16ca7557cd308c7886f 100644 (file)
@@ -33,7 +33,6 @@ protected:
   vector<int> char_count_stack_;
 
 public:
-  bool allow_includes_;
 
   Includable_lexer ();
   ~Includable_lexer ();
@@ -42,9 +41,10 @@ public:
   vector<string> file_name_strings_;
 
   Source_file *get_source_file () const;
-  void new_input (string s, Sources *);
+  virtual void new_input (string s, Sources *);
+  
   void new_input (string name, string data, Sources *);
-
+  
   char const *here_str0 () const;
 };
 
index e8a9c998d162591000e8f7612160314865b730e0..5609f53f4d17479254820e9df489b4465e539384 100644 (file)
@@ -42,7 +42,6 @@ public:
   void *lexval;
   Input *lexloc;
   bool is_main_input_;
-  bool be_safe_;
   
   Sources *sources_;
 
@@ -56,7 +55,7 @@ public:
   Lily_lexer (Sources *, Lily_parser *);
   Lily_lexer (Lily_lexer const &, Lily_parser *);
   int yylex ();
-
+  
   void add_lexed_char (int);
 
   void prepare_for_next_token ();
@@ -70,6 +69,9 @@ public:
 
   void start_main_input ();
 
+  virtual void new_input (string s, Sources *);
+  virtual void new_input (string s, string d, Sources *);
+
   SCM keyword_list () const;
   SCM lookup_identifier (string s);
   SCM lookup_identifier_symbol (SCM s);
index d20b075eb40ffaa292886d88144f1eaa1280f123..b6fb615bd262647803392df890f6b284a04728d5 100644 (file)
@@ -334,7 +334,7 @@ BOM_UTF8    \357\273\277
        Input hi = here_input();
        hi.step_forward ();
        SCM sval = ly_parse_scm (hi.start (), &n, hi,
-               be_safe_ && is_main_input_);
+               be_safe_global && is_main_input_);
 
        if (sval == SCM_UNDEFINED)
        {
index 424b4fa816adb3227493709edcaf12c8146b7673..7cb6d53691de01dd04a3bb281133ad57ac948984 100644 (file)
@@ -17,17 +17,3 @@ LY_DEFINE(ly_lexer_keywords, "ly:lexer-keywords",
   SCM_ASSERT_TYPE(lex, lexer, SCM_ARG1, __FUNCTION__, "lily lexer");
   return lex->keyword_list ();
 }
-         
-
-LY_DEFINE(ly_lexer_set_safe, "ly:lexer-set-safe!",
-         1, 0, 0, (SCM lexer),
-         "Switch on safe mode for the rest of the file.")
-{
-  Lily_lexer * lex = Lily_lexer::unsmob (lexer);
-  SCM_ASSERT_TYPE(lex, lexer, SCM_ARG1, __FUNCTION__, "lily lexer");
-
-  lex->be_safe_ = true;
-  lex->allow_includes_ = false;
-  
-  return SCM_UNSPECIFIED;
-}
index 72e8bb866193534e25bd395962d2a95491e7bb12..cd0c42eaa4eedf910386703de34a975ffaf43909 100644 (file)
@@ -231,14 +231,29 @@ Lily_lexer::start_main_input ()
   
   new_input (main_input_name_, sources_);
 
-  /* Do not allow \include in --safe-mode */
-  allow_includes_ = allow_includes_ && !be_safe_global;
-
   scm_module_define (scm_car (scopes_),
                     ly_symbol2scm ("input-file-name"),
                     scm_makfrom0str (main_input_name_.c_str ()));
 }
 
+void
+Lily_lexer::new_input (string str, string d, Sources *ss)
+{
+  Includable_lexer::new_input (str, d, ss);
+}
+
+void
+Lily_lexer::new_input (string str, Sources *ss)
+{
+  if (is_main_input_ && be_safe_global)
+    {
+      LexerError (_ ("include files are not allowed in safe mode").c_str ());
+      return;
+    }
+
+  Includable_lexer::new_input (str, ss);
+}
+
 void
 Lily_lexer::set_identifier (SCM name, SCM s)
 {
index 708b10659db433339a8033b13ff556da7f5daaba..15cb06c4d7319af1b0915e501c467dd4c8f34268 100644 (file)
@@ -254,5 +254,5 @@ get_header (Lily_parser *parser)
 SCM 
 Lily_parser::make_scope () const
 {
-  return ly_make_anonymous_module (lexer_->be_safe_);
+  return ly_make_anonymous_module (be_safe_global);
 }