CVSROOT:        /cvsroot/lilypond
Module name:    lilypond
Branch:         
Changes by:     Han-Wen Nienhuys <[EMAIL PROTECTED]>    05/06/14 00:44:14

Modified files:
        .              : ChangeLog 
        lily           : program-option.cc 
        scm            : documentation-lib.scm lily-library.scm lily.scm 

Log message:
        * lily/program-option.cc (LY_DEFINE): new function ly_add_option.
        
        * scm/lily.scm (lambda): initialize program options from here.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/ChangeLog.diff?tr1=1.3773&tr2=1.3774&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/program-option.cc.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/scm/documentation-lib.scm.diff?tr1=1.40&tr2=1.41&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/scm/lily-library.scm.diff?tr1=1.36&tr2=1.37&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/scm/lily.scm.diff?tr1=1.362&tr2=1.363&r1=text&r2=text

Patches:
Index: lilypond/ChangeLog
diff -u lilypond/ChangeLog:1.3773 lilypond/ChangeLog:1.3774
--- lilypond/ChangeLog:1.3773   Tue Jun 14 00:19:36 2005
+++ lilypond/ChangeLog  Tue Jun 14 00:44:14 2005
@@ -1,5 +1,11 @@
 2005-06-14  Han-Wen Nienhuys  <[EMAIL PROTECTED]>
 
+       * lily/program-option.cc (LY_DEFINE): new function ly_add_option.
+
+       * scm/lily.scm (lambda): initialize program options from here.
+
+       * scm/framework-*.scm: add header info.
+
        * lily/main.cc (parse_argv): only set output format to pdf if no
        other format specified.
 
Index: lilypond/lily/program-option.cc
diff -u lilypond/lily/program-option.cc:1.7 lilypond/lily/program-option.cc:1.8
--- lilypond/lily/program-option.cc:1.7 Fri Jun 10 09:30:42 2005
+++ lilypond/lily/program-option.cc     Tue Jun 14 00:44:14 2005
@@ -32,44 +32,6 @@
 */
 bool do_internal_type_checking_global;
 
-
-struct Lilypond_option_init
-{
-  char const *name_;
-  char const *init_;
-  char const *descr_;
-};
-
-static Lilypond_option_init options[] = {
-  {"point-and-click", "#t",
-   "use point & click"},
-  {"midi-debug", "#f",
-   "generate human readable MIDI",},
-  {"internal-type-checking", "#f",
-   "check every property assignment for types"},
-  {"parse-protect", "#t",
-   "continue when finding errors in inline\n" 
-   "scheme are caught in the parser. If off, halt \n"
-   "on errors, and print a stack trace."},
-  {"old-relative", "#f",
-   "relative for simultaneous music works\n"
-   "similar to chord syntax"},
-  {"resolution", "90",
-   "resolution for generating bitmaps"},
-  {"preview-include-book-title", "#t",
-   "include book-titles in preview images."},
-  {"gs-font-load", "#f",
-   "load fonts via Ghostscript."},
-  {"delete-intermediate-files", "#f",
-   "delete unusable PostScript files"},
-  {"verbose", "#f", "value for the --verbose flag"},
-  {"ttf-verbosity", "0",
-   "how much verbosity for TTF font embedding?"},
-  {"debug-gc", "#f",
-   "dump GC protection info"}, 
-  {0,0,0},
-};
-
 Protected_scm option_hash_;
 
 void internal_set_option (SCM var, SCM val)
@@ -112,16 +74,21 @@
 static String
 get_help_string ()
 {
+  SCM alist = ly_hash2alist (option_hash_);
+  SCM convertor = ly_lily_module_constant ("scm->string");
+  
+  
   String help ("Options supported by ly:set-option\n\n");
-  for (Lilypond_option_init *p = options; p->name_; p ++)
+  for (SCM s = alist; scm_is_pair (s); s = scm_cdr (s))
     {
+      SCM sym = scm_caar (s);
+      SCM val = scm_cdar (s);
       String opt_spec =
        String_convert::char_string (' ', INDENT)
-       + String (p->name_)
+       + ly_symbol2string (sym)
        + " ("
-       + String (p->init_)
+       + ly_scm2string (scm_call_1 (convertor, val))
        + ")";
-       
 
       if (opt_spec.length () + SEPARATION > HELP_INDENT)
        {
@@ -130,8 +97,10 @@
        }
       else
        opt_spec += String_convert::char_string (' ', HELP_INDENT - 
opt_spec.length ());
-      
-      String opt_help = p->descr_;
+
+      SCM opt_help_scm
+       = scm_object_property (sym, ly_symbol2scm 
("program-option-documentation")); 
+      String opt_help = ly_scm2string (opt_help_scm);
       opt_help.substitute (String ("\n"),
                           String ("\n")
                           + String_convert::char_string (' ', HELP_INDENT));
@@ -143,46 +112,32 @@
   return help;
 }
 
-static void
-init_program_options ()
+LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (),
+          "Print ly:set-option usage")
 {
-  option_hash_ = scm_c_make_hash_table (11);
-
-  for (Lilypond_option_init *p = options; p->name_; p ++)
-    {
-      SCM sym = ly_symbol2scm (p->name_);
-      SCM val = scm_c_eval_string (p->init_);
-
-      internal_set_option (sym, val);
-    }
-
   String help = get_help_string ();
+  fputs (help.to_str0 (), stdout); 
 
-
-
-  internal_set_option (ly_symbol2scm ("help"),
-                      scm_makfrom0str (help.to_str0 ()));
+  exit (0);
+  return SCM_UNSPECIFIED;
 }
 
-ADD_SCM_INIT_FUNC(scm_option, init_program_options);
-
+LY_DEFINE (ly_add_option, "ly:add-option", 3, 0, 0,
+          (SCM sym, SCM val,  SCM description),
+          "Add a program option @var{sym} with default @var{val}.")
+{
+  if (scm_hash_table_p (option_hash_) == SCM_BOOL_F)
+    option_hash_ = scm_c_make_hash_table (11);
+
+  SCM_ASSERT_TYPE (scm_is_symbol (sym), sym, SCM_ARG1, __FUNCTION__, "symbol");
+  SCM_ASSERT_TYPE (scm_is_string (description), description,
+                  SCM_ARG3, __FUNCTION__, "string");
+                 
+  internal_set_option (sym, val);
 
-/*
-  This interface to option setting is meant for setting options are
-  useful to a limited audience. The reason for this interface is that
-  making command line options clutters up the command-line option name
-  space.
+  scm_set_object_property_x (sym, ly_symbol2scm 
("program-option-documentation"),
+                            description);
 
-*/
-
-Protected_scm command_line_settings = SCM_EOL;
-
-LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (),
-          "Print ly:set-option usage")
-{
-  SCM scm_stdout = scm_current_output_port();
-  scm_display (ly_get_option (ly_symbol2scm ("help")), scm_stdout);
-  exit (0);
   return SCM_UNSPECIFIED;
 }
 
Index: lilypond/scm/documentation-lib.scm
diff -u lilypond/scm/documentation-lib.scm:1.40 
lilypond/scm/documentation-lib.scm:1.41
--- lilypond/scm/documentation-lib.scm:1.40     Tue Apr 12 22:49:25 2005
+++ lilypond/scm/documentation-lib.scm  Tue Jun 14 00:44:14 2005
@@ -54,16 +54,6 @@
   (string-append "@code{" (texify (scm->string x)) "}"))
 
 
-;;
-;; don't confuse users with #<procedure .. > syntax. 
-;; 
-(define (scm->string val)
-  (if (and (procedure? val) (symbol? (procedure-name val)))
-      (symbol->string (procedure-name val))
-      (string-append
-       (if (self-evaluating? val) "" "'")
-       (call-with-output-string (lambda (port) (display val port))))))
-
 
 (define (texi-section-command level)
   (cdr (assoc level '(
Index: lilypond/scm/lily-library.scm
diff -u lilypond/scm/lily-library.scm:1.36 lilypond/scm/lily-library.scm:1.37
--- lilypond/scm/lily-library.scm:1.36  Wed May 25 10:22:34 2005
+++ lilypond/scm/lily-library.scm       Tue Jun 14 00:44:14 2005
@@ -324,6 +324,16 @@
 (define-public (symbol<? lst r)
   (string<? (symbol->string lst) (symbol->string r)))
 
+;;
+;; don't confuse users with #<procedure .. > syntax. 
+;; 
+(define-public (scm->string val)
+  (if (and (procedure? val) (symbol? (procedure-name val)))
+      (symbol->string (procedure-name val))
+      (string-append
+       (if (self-evaluating? val) "" "'")
+       (call-with-output-string (lambda (port) (display val port))))))
+
 (define-public (!= lst r)
   (not (= lst r)))
 
Index: lilypond/scm/lily.scm
diff -u lilypond/scm/lily.scm:1.362 lilypond/scm/lily.scm:1.363
--- lilypond/scm/lily.scm:1.362 Fri Jun 10 00:36:22 2005
+++ lilypond/scm/lily.scm       Tue Jun 14 00:44:14 2005
@@ -6,6 +6,31 @@
 ;;;; Han-Wen Nienhuys <[EMAIL PROTECTED]>
 
 
+(for-each (lambda (x)
+           (ly:add-option (car x) (cadr x) (caddr x)))
+         
+         '((point-and-click #t "use point & click")
+           (midi-debug #f "generate human readable MIDI")
+           (internal-type-checking #f "check every property assignment for 
types")
+           (parse-protect #t    "continue when finding errors in inline
+scheme are caught in the parser. If off, halt 
+on errors, and print a stack trace.")
+           (old-relative #f
+                         "relative for simultaneous music works
+similar to chord syntax")
+           (resolution 90 "resolution for generating bitmaps")
+           (preview-include-book-title #t "include book-titles in preview 
images.")
+           (gs-font-load #f
+                         "load fonts via Ghostscript.")
+           (delete-intermediate-files #f
+                                      "delete unusable PostScript files")
+           (verbose #f "value for the --verbose flag")
+           (ttf-verbosity 0
+                          "how much verbosity for TTF font embedding?")
+           (debug-gc #f
+                     "dump GC protection info")))
+
+
 (if (defined? 'set-debug-cell-accesses!)
     (set-debug-cell-accesses! #f))
 


_______________________________________________
Lilypond-cvs mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-cvs

Reply via email to