]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/scm-option.cc
2003 -> 2004
[lilypond.git] / lily / scm-option.cc
index 525c2e54f3212b376497c4b9bbeb0b9950ad838b..64302127c80ba53bc6902eef670578c49b7653e3 100644 (file)
@@ -3,15 +3,17 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 2001--2004  Han-Wen Nienhuys <hanwen@cs.uu.nl>
   
  */
+#include <stdio.h>
 
-#include <iostream.h>
+#include "parse-scm.hh"
 #include "string.hh"
 #include "lily-guile.hh"
 #include "scm-option.hh"
-
+#include "warn.hh"
+#include "main.hh"
 
 /*
   This interface to option setting is meant for setting options are
@@ -33,42 +35,78 @@ bool midi_debug_global_b;
 /* General purpose testing flag */
 int testing_level_global;
 
-
-
 /*
+  Backwards compatibility.
+ */
+bool lily_1_8_relative = false;
+bool lily_1_8_compatibility_used = false;
 
-  TODO: verzin iets tegen optie code bloot
-
+/*
+  crash if internally the wrong type is used for a grob property.
+ */
+bool internal_type_checking_global_b;
+
+LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (SCM),
+                 "Print ly-set-option usage")
+{  
+  printf ( _("lilypond -e EXPR means:").to_str0 ());
+  puts ("");
+  printf (_ ("  Evalute the Scheme EXPR before parsing any .ly files.").to_str0 ());
+  puts ("");
+  printf (_ ("  Multiple -e options may be given, they will be evaluated sequentially.").to_str0 ());
+  puts ("");
+  printf (_("  The function ly-set-option allows for access to some internal variables.").to_str0 ());
+  puts ("\n");
+  printf (_ ("Usage: lilypond -e \"(ly-set-option SYMBOL VAL)\"").to_str0 ());
+  puts ("\n");
+  printf (_ ("Where SYMBOL VAL pair is any of:").to_str0 ());
+  puts ("");
+  printf ( "  help ANY-SYMBOL\n"
+          "  internal-type-checking BOOLEAN\n"
+          "  midi-debug BOOLEAN\n"
+          "  parse-protect BOOLEAN\n"
+          "  testing-level INTEGER\n");
+  
+  exit (0);
+  return SCM_UNSPECIFIED;
+}
 
-  other interesting stuff to add:
+/* Add these as well:
 
 @item -T,--no-timestamps
 don't timestamp the output
 
 @item -t,--test
-Switch on any experimental features.  Not for general public use.
-
- */
-
-SCM
-set_lily_option (SCM var, SCM val)
+Switch on any experimental features.  Not for general public use. */
+LY_DEFINE (ly_set_option, "ly:set-option", 1, 1, 0, (SCM var, SCM val),
+           "Set a global option value.  Supported options include\n"
+"\n"
+"@table @code\n"
+"@item help\n"
+"List all options.\n"
+"@item midi-debug\n"
+"If set to true, generate human readable MIDI\n"
+"@item internal-type-checking\n"
+"Set paranoia for property assignments\n"
+"@item parse-protect\n"
+"If protection is switched on, errors in inline scheme are caught in the parser. \n"
+"If off, GUILE will halt on errors, and give a stack trace. Default is protected evaluation. \n"
+"@item old-relative\n"
+"Relative for simultaneous functions similar to chord syntax\n"
+"@item new-relative\n"
+"Relative for simultaneous functions similar to sequential music\n"
+"@end table\n"
+"\n"
+"This function is useful to call from the command line: @code{lilypond -e\n"
+"\"(ly-set-option 'midi-debug #t)\"}.\n")
 {
-  /*
-    Scheme option usage:
-    lilypond -e "(set-lily-option 'help 0)"
-   */
+  if (val == SCM_UNDEFINED)
+    val = SCM_BOOL_T;
+
   if (var == ly_symbol2scm ("help"))
     {
-      cout << '\n';
-      cout << _ ("Scheme options:");
-      cout << '\n';
-      cout << "  help (any-symbol)"; 
-      cout << '\n';
-      cout << "  midi-debug (boolean)"; 
-      cout << '\n';
-      cout << "  testing-level (int)"; 
-      cout << '\n';
-      exit (0);
+      /* lilypond -e "(ly-set-option 'help #t)" */
+      ly_option_usage (SCM_EOL);
     }
   else if (var == ly_symbol2scm ("midi-debug"))
     {
@@ -78,33 +116,65 @@ set_lily_option (SCM var, SCM val)
     {
      testing_level_global = gh_scm2int (val); 
     }
-  else if (var == ly_symbol2scm ("find-old-relative"))
+  else if (var == ly_symbol2scm ("parse-protect" ))
     {
-      /*
-       Seems to have been broken for some time!
-       
-       @item  -Q,--find-old-relative
-       show all changes needed to convert a file to  relative octave syntax.
-
-
-       
-      */
-
-      ;
-      
+      parse_protect_global = to_boolean(val);
+    }
+  else if (var == ly_symbol2scm ("internal-type-checking"))
+    {
+     internal_type_checking_global_b = to_boolean (val); 
+    }
+  else if (var == ly_symbol2scm ("old-relative"))
+    {
+      lily_1_8_relative = true;
+      lily_1_8_compatibility_used = false; 
+    }
+  else if (var == ly_symbol2scm ("new-relative"))
+    {
+      lily_1_8_relative = false;
+    }
+  else if (var == ly_symbol2scm ("debug-beam"))
+    {
+      extern bool debug_beam_quanting_flag;
+      debug_beam_quanting_flag = true;
+    }
+  else
+    {
+      warning (_("Unknown internal option!"));
     }
 
   return SCM_UNSPECIFIED;
 }
 
 
-static void
-init_functions ()
+LY_DEFINE (ly_get_option, "ly:get-option", 1, 0, 0, (SCM var),
+           "Get a global option setting.  Supported options include\n"
+          "@table @code\n"
+          "@item old-relative-used\n"
+          "Report whether old-relative compatibility mode is necessary\n"
+          "@item old-relative\n"
+          "Report whether old-relative compatibility mode is used\n"
+          "@item verbose\n"
+          "Report whether we are running in verbose mode\n"
+          "@end table\n"
+          "\n")
 {
-  scm_c_define_gsubr ("set-lily-option", 2, 0, 0, (Scheme_function_unknown)set_lily_option);
-}
-
-
-ADD_SCM_INIT_FUNC (init_functions_sopt, init_functions);
-
+  if (var == ly_symbol2scm ("old-relative-used"))
+    {
+      return gh_bool2scm (lily_1_8_compatibility_used);
+    }
+  if (var == ly_symbol2scm ("old-relative"))
+    {
+      return gh_bool2scm (lily_1_8_relative);
+    }
+  if (var == ly_symbol2scm ("verbose"))
+    {
+      return gh_bool2scm (verbose_global_b);
+    }  
+  else
+    {
+      warning (_("Unknown internal option!"));
+    }
 
+  return SCM_UNSPECIFIED;
+}