]> git.donarmstrong.com Git - lilypond.git/blob - lily/lily-guile.cc
* scm/lily.scm (completize-formats): new function
[lilypond.git] / lily / lily-guile.cc
1 /*
2   lily-guile.cc -- implement assorted guile functions
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7                  Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
9
10 #include "lily-guile.hh"
11
12 #include <cstdio>
13 #include <cstdlib>
14 #include <math.h>   /* isinf */
15 #include <cstring> /* strdup, strchr */
16 #include <cctype>
17
18 #include <libintl.h>            // gettext on macos x
19
20 #include "version.hh"
21
22 /* MacOS S fix:
23    source-file.hh includes cmath which undefines isinf and isnan
24 */
25 #ifdef __APPLE__
26 inline int my_isinf (Real r) { return isinf (r); }
27 inline int my_isnan (Real r) { return isnan (r); }
28 #endif
29
30 #include "libc-extension.hh"
31 #include "main.hh"
32 #include "file-path.hh"
33 #include "warn.hh"
34 #include "direction.hh"
35 #include "offset.hh"
36 #include "pitch.hh"
37 #include "dimensions.hh"
38 #include "source-file.hh"
39 #include "misc.hh"
40
41 // #define TEST_GC
42
43 SCM
44 ly_to_symbol (SCM scm)
45 {
46   return scm_string_to_symbol (ly_to_string (scm));
47 }
48
49 SCM
50 ly_to_string (SCM scm)
51 {
52   return scm_call_3 (ly_lily_module_constant ("format"), SCM_BOOL_F,
53                      scm_makfrom0str ("~S"), scm);
54 }
55
56 SCM
57 ly_last (SCM list)
58 {
59   return scm_car (scm_last_pair (list));
60 }
61
62 SCM
63 ly_write2scm (SCM s)
64 {
65   SCM port = scm_mkstrport (SCM_INUM0, 
66                             scm_make_string (SCM_INUM0, SCM_UNDEFINED),
67                             SCM_OPN | SCM_WRTNG,
68                             "ly_write2string");
69   //  SCM write = scm_eval_3 (ly_symbol2scm ("write"), s, SCM_EOL);
70   SCM write = scm_primitive_eval (ly_symbol2scm ("write"));
71   
72   // scm_apply (write, port, SCM_EOL);
73   scm_call_2 (write, s, port);
74   return scm_strport_to_string (port);
75 }
76
77 SCM
78 ly_quote_scm (SCM s)
79 {
80   return scm_list_n (ly_symbol2scm ("quote"), s, SCM_UNDEFINED);
81 }
82
83 String
84 ly_symbol2string (SCM s)
85 {
86   /*
87     Ugh. this is not very efficient.
88    */
89   SCM str = scm_symbol_to_string (s);
90   return ly_scm2string (str);
91 }
92
93 String
94 gulp_file_to_string (String fn, bool must_exist)
95 {
96   String s = global_path.find (fn);
97   if (s == "")
98     {
99       if (must_exist)
100         {
101           String e = _f ("can't find file: `%s'", fn);
102           e += " ";
103           e += _f ("(load path: `%s')", global_path.to_string ());
104           error (e);
105           /* unreachable */
106         }
107       return s;
108     }
109
110   if (verbose_global_b)
111     progress_indication ("[" + s);
112
113   int n;
114   char *str = gulp_file (s, &n);
115   String result ((Byte*) str, n);
116   delete[] str;
117   
118   if (verbose_global_b)
119     progress_indication ("]");
120
121   return result;
122 }
123
124 LY_DEFINE (ly_gulp_file, "ly:gulp-file",
125            1, 0, 0, (SCM name),
126            "Read the file @var{name}, and return its contents in a string.  "
127            "The file is looked up using the search path.")
128 {
129   SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string");
130   String contents = gulp_file_to_string (ly_scm2string (name), true);
131   return scm_from_locale_stringn (contents.get_str0 (), contents.length ());
132 }
133
134
135 extern "C" {
136   // maybe gdb 5.0 becomes quicker if it doesn't do fancy C++ typing?
137 void
138 ly_display_scm (SCM s)
139 {
140   scm_display (s, scm_current_output_port ());
141   scm_newline (scm_current_output_port ());
142 }
143 };
144
145 String
146 ly_scm2string (SCM str)
147 {
148   assert (scm_is_string (str));
149   return String ((Byte*)scm_i_string_chars (str),
150                  (int) scm_i_string_length (str));
151 }
152
153 char *
154 ly_scm2newstr (SCM str, size_t *lenp)
155 {
156   SCM_ASSERT_TYPE (scm_is_string (str), str, SCM_ARG1, __FUNCTION__, "string");
157
158   size_t len = SCM_STRING_LENGTH (str);
159   if (char *new_str = (char *) malloc ((len + 1) * sizeof (char)))
160     {
161       memcpy (new_str, scm_i_string_chars (str), len);
162       new_str[len] = '\0';
163
164       if (lenp)
165         *lenp = len;
166       
167       return new_str;
168     }
169   return 0;
170 }
171
172 SCM
173 index_get_cell (SCM s, Direction d)
174 {
175   
176   assert (d);
177   return (d == LEFT) ? scm_car (s) : scm_cdr (s);
178 }
179
180 SCM
181 index_set_cell (SCM s, Direction d, SCM v)
182 {
183   if (d == LEFT)
184     scm_set_car_x (s, v);
185   else if (d == RIGHT)
186     scm_set_cdr_x (s, v);
187   return s;
188 }
189   
190 LY_DEFINE (ly_warn, "ly:warn",
191            1, 0, 1, (SCM str, SCM rest),
192            "Scheme callable function to issue the warning @code{msg}. "
193            "The message is formatted with @code{format} and @code{rest}.")
194 {
195   SCM_ASSERT_TYPE (scm_is_string (str), str, SCM_ARG1, __FUNCTION__, "string");
196   progress_indication ("\n");
197
198   str = scm_simple_format (SCM_BOOL_F, str, rest);
199   warning (ly_scm2string (str));
200   return SCM_UNSPECIFIED;
201 }
202
203 LY_DEFINE (ly_programming_error, "ly:programming-error",
204            1, 0, 1, (SCM str, SCM rest),
205            "Scheme callable function to issue the warning @code{msg}. "
206            "The message is formatted with @code{format} and @code{rest}.")
207 {
208   SCM_ASSERT_TYPE (scm_is_string (str), str, SCM_ARG1, __FUNCTION__, "string");
209   progress_indication ("\n");
210
211   str = scm_simple_format (SCM_BOOL_F, str, rest);
212   programming_error (ly_scm2string (str));
213   return SCM_UNSPECIFIED;
214 }
215
216 LY_DEFINE (ly_dir_p, "ly:dir?",
217            1, 0, 0, (SCM s),
218           "type predicate. A direction is @code{-1}, @code{0} or "
219            "@code{1}, where @code{-1} represents "
220           "left or down and @code{1} represents right or up.")
221 {
222   if (scm_is_number (s))
223     {
224       int i = scm_to_int (s);
225       return (i>= -1 && i <= 1)  ? SCM_BOOL_T : SCM_BOOL_F; 
226     }
227   return SCM_BOOL_F;
228 }
229
230 bool
231 is_number_pair (SCM p)
232 {
233   return scm_is_pair (p)
234     && scm_is_number (scm_car (p)) && scm_is_number (scm_cdr (p));
235 }
236
237 typedef void (*Void_fptr) ();
238 Array<Void_fptr> *scm_init_funcs_;
239
240 void add_scm_init_func (void (*f) ())
241 {
242   if (!scm_init_funcs_)
243     scm_init_funcs_ = new Array<Void_fptr>;
244
245   scm_init_funcs_->push (f);
246 }
247
248 void
249 ly_init_ly_module (void *)
250 {
251   for (int i = scm_init_funcs_->size () ; i--;)
252     (scm_init_funcs_->elem (i)) ();
253
254   if (verbose_global_b)
255     progress_indication ("\n");
256   
257   scm_primitive_load_path (scm_makfrom0str ("lily.scm"));
258 }
259
260 SCM global_lily_module;
261
262 void
263 ly_c_init_guile ()
264 {
265   global_lily_module = scm_c_define_module ("lily", ly_init_ly_module, 0);
266   scm_c_use_module ("lily");
267 }
268
269 unsigned int
270 ly_scm_hash (SCM s)
271 {
272   return scm_ihashv (s, ~1u);
273 }
274
275 bool
276 is_direction (SCM s)
277 {
278   if (scm_is_number (s))
279     {
280       int i = scm_to_int (s);
281       return i>= -1 && i <= 1; 
282     }
283   return false;
284 }
285
286 LY_DEFINE (ly_assoc_get, "ly:assoc-get",
287            2, 1, 0,
288            (SCM key, SCM alist, SCM default_value),
289            "Return value if KEY in ALIST, else DEFAULT-VALUE "
290            "(or #f if not specified).")
291 {
292   SCM handle = scm_assoc (key, alist);
293
294   if (default_value == SCM_UNDEFINED)
295     default_value = SCM_BOOL_F;
296   
297   if (scm_is_pair (handle))
298     return scm_cdr (handle);
299   else
300     return default_value;
301 }
302
303 bool
304 is_axis (SCM s)
305 {
306   if (scm_is_number (s))
307     {
308       int i = scm_to_int (s);
309       return i == 0 || i == 1;
310     }
311   return false;
312 }
313
314 Direction
315 to_dir (SCM s)
316 {
317   return scm_is_integer (s) ? (Direction) scm_to_int (s) : CENTER;
318 }
319
320 Interval
321 ly_scm2interval (SCM p)
322 {
323   return Interval (scm_to_double (scm_car (p)), scm_to_double (scm_cdr (p)));
324 }
325
326 Drul_array<Real>
327 ly_scm2realdrul (SCM p)
328 {
329   return Drul_array<Real> (scm_to_double (scm_car (p)),
330                            scm_to_double (scm_cdr (p)));
331 }
332
333 SCM
334 ly_interval2scm (Drul_array<Real> i)
335 {
336   return scm_cons (scm_make_real (i[LEFT]), scm_make_real (i[RIGHT]));
337 }
338
339 bool
340 to_boolean (SCM s)
341 {
342   return scm_is_bool (s) && ly_scm2bool (s);
343 }
344
345 /* Appendable list L: the cdr contains the list, the car the last cons
346    in the list.  */
347 SCM
348 appendable_list ()
349 {
350   SCM s = scm_cons (SCM_EOL, SCM_EOL);
351   scm_set_car_x (s, s);
352   
353   return s;
354 }
355
356 void
357 appendable_list_append (SCM l, SCM elt)
358 {
359   SCM newcons = scm_cons (elt, SCM_EOL);
360   
361   scm_set_cdr_x (scm_car (l), newcons);      
362   scm_set_car_x (l, newcons);
363 }
364
365 SCM
366 ly_offset2scm (Offset o)
367 {
368   return scm_cons (scm_make_real (o[X_AXIS]), scm_make_real (o[Y_AXIS]));
369 }
370
371 Offset
372 ly_scm2offset (SCM s)
373 {
374   return Offset (scm_to_double (scm_car (s)),
375                  scm_to_double (scm_cdr (s)));
376 }
377
378 LY_DEFINE (ly_number2string, "ly:number->string",
379            1, 0, 0, (SCM s),
380            "Convert @var{num} to a string without generating many decimals.")
381 {
382   SCM_ASSERT_TYPE (scm_is_number (s), s, SCM_ARG1, __FUNCTION__, "number");
383
384   char str[400];                        // ugh.
385
386   if (scm_exact_p (s) == SCM_BOOL_F)
387     {
388       Real r (scm_to_double (s));
389 #ifdef __APPLE__
390       if (my_isinf (r) || my_isnan (r))
391 #else
392       if (isinf (r) || isnan (r))
393 #endif
394         {
395           programming_error ("Infinity or NaN encountered while converting Real number; setting to zero.");
396           r = 0.0;
397         }
398
399       sprintf (str, "%08.4f", r);
400     }
401   else
402     sprintf (str, "%d", scm_to_int (s));
403
404   return scm_makfrom0str (str);
405 }
406
407
408
409 LY_DEFINE (ly_version,  "ly:version", 0, 0, 0, (),
410           "Return the current lilypond version as a list, e.g. @code{(1 3 127 uu1)}. ")
411 {
412   char const* vs = "\'(" MAJOR_VERSION " " MINOR_VERSION " "  PATCH_LEVEL " " MY_PATCH_LEVEL ")" ;
413   
414   return scm_c_eval_string ((char*)vs);
415 }
416
417 LY_DEFINE (ly_unit,  "ly:unit", 0, 0, 0, (),
418           "Return the unit used for lengths as a string.")
419 {
420   return scm_makfrom0str (INTERNAL_UNIT);
421 }
422
423
424
425 LY_DEFINE (ly_dimension_p,  "ly:dimension?", 1, 0, 0, (SCM d),
426           "Return @var{d} is a number. Used to distinguish length "
427           "variables from normal numbers.")
428 {
429   return scm_number_p (d);
430 }
431
432 SCM
433 ly_deep_copy (SCM src)
434 {
435   if (scm_is_pair (src))
436     return scm_cons (ly_deep_copy (scm_car (src)), ly_deep_copy (scm_cdr (src)));
437   else if (ly_c_vector_p (src))
438     {
439       int len = SCM_VECTOR_LENGTH (src);
440       SCM nv = scm_c_make_vector (len, SCM_UNDEFINED);
441       for (int i = 0 ;i < len ; i++)
442         {
443           SCM si = scm_int2num (i);
444           scm_vector_set_x (nv, si, ly_deep_copy (scm_vector_ref (src, si))); 
445         }
446     }
447   return src;
448 }
449
450 SCM
451 ly_chain_assoc_get (SCM key, SCM achain, SCM dfault)
452 {
453   if (scm_is_pair (achain))
454     {
455       SCM handle = scm_assoc (key, scm_car (achain));
456       if (scm_is_pair (handle))
457         return scm_cdr (handle);
458       else
459         return ly_chain_assoc (key, scm_cdr (achain));
460     }
461   else
462     return dfault;
463 }
464
465 SCM
466 ly_chain_assoc (SCM key, SCM achain)
467 {
468   if (scm_is_pair (achain))
469     {
470       SCM handle = scm_assoc (key, scm_car (achain));
471       if (scm_is_pair (handle))
472         return handle;
473       else
474         return ly_chain_assoc (key, scm_cdr (achain));
475     }
476   else
477     return SCM_BOOL_F;
478 }
479
480 /* looks the key up in the cdrs of the alist-keys
481    - ignoring the car and ignoring non-pair keys.
482    Returns first match found, i.e.
483
484    alist = ((1 . 10)
485                    ((1 . 2) . 11)
486                    ((2 . 1) . 12)
487                    ((3 . 0) . 13)
488                    ((4 . 1) . 14) )
489
490 I would like (ly_assoc_cdr 1) to return 12 - because it's the first
491 element with the cdr of the key = 1.  In other words (alloc_cdr key)
492 corresponds to call
493
494 (alloc (anything . key))
495
496
497
498 */
499 SCM
500 ly_assoc_cdr (SCM key, SCM alist)
501 {
502   if (scm_is_pair (alist))
503     {
504       SCM trykey = scm_caar (alist);
505       if (scm_is_pair (trykey) && to_boolean (scm_equal_p (key, scm_cdr (trykey))))
506         return scm_car (alist);
507       else
508         return ly_assoc_cdr (key, scm_cdr (alist));
509     }
510   return SCM_BOOL_F;
511 }
512
513 /* LST has the form "sym1 sym2 sym3\nsym4\nsym5"
514    i.e. \n and ' ' can be used interchangeably as separators.  */
515 SCM
516 parse_symbol_list (char const *lst)
517 {
518   char *s = strdup (lst);
519   char *orig = s;
520   SCM create_list = SCM_EOL;
521
522   char * e = s + strlen (s) - 1;
523   while (e >= s && isspace (*e))
524     *e-- = 0;
525
526   for (char * p = s; *p; p++)
527     if (*p == '\n')
528       *p = ' ';
529   
530   if (!s[0])
531     s = 0;
532   
533   while (s)
534     {
535       char *next = strchr (s, ' ');
536       if (next)
537         *next++ = 0;
538
539       create_list = scm_cons (ly_symbol2scm (s), create_list);
540       s = next;
541     }
542
543   free (orig);
544   return create_list;
545 }
546
547 SCM
548 ly_truncate_list (int k, SCM lst)
549 {
550   if (k == 0)
551     lst = SCM_EOL;
552   else
553     {
554       SCM s = lst;
555       k--;
556       for (; scm_is_pair (s) && k--; s = scm_cdr (s))
557         ;
558
559       if (scm_is_pair (s))
560         scm_set_cdr_x (s, SCM_EOL);
561     }
562   return lst;
563 }
564
565 String
566 print_scm_val (SCM val)
567 {
568   String realval = ly_scm2string (ly_write2scm (val));
569   if (realval.length () > 200)
570     realval = realval.left_string (100)
571       + "\n :\n :\n"
572       + realval.right_string (100);
573   return realval;        
574 }
575
576 bool
577 type_check_assignment (SCM sym, SCM val,  SCM type_symbol) 
578 {
579   bool ok = true;
580
581   /*
582     Always succeeds.
583
584
585     TODO: should remove #f from allowed vals?
586    */
587   if (val == SCM_EOL || val == SCM_BOOL_F)
588     return ok;
589
590   if (!scm_is_symbol (sym))
591 #if 0
592     return false;
593 #else
594   /*
595     This is used for autoBeamSettings.
596
597     TODO: deprecate the use of \override and \revert for
598     autoBeamSettings?
599
600     or use a symbol autoBeamSettingS?  
601    */
602   return true; 
603 #endif
604   
605   SCM type = scm_object_property (sym, type_symbol);
606
607   if (type != SCM_EOL && !ly_c_procedure_p (type))
608       {
609         warning (_f ("Can't find property type-check for `%s' (%s).",
610                      ly_symbol2string (sym).to_str0 (),
611                      ly_symbol2string (type_symbol).to_str0 ())
612                  + "  " + _ ("Perhaps you made a typing error?"));
613
614         /* Be strict when being anal :) */
615         if (internal_type_checking_global_b)
616           abort ();
617         
618         warning (_ ("Doing assignment anyway."));
619       }
620   else
621     {
622       if (val != SCM_EOL
623           && ly_c_procedure_p (type)
624           && scm_call_1 (type, val) == SCM_BOOL_F)
625         {
626           SCM errport = scm_current_error_port ();
627           ok = false;
628           SCM typefunc = ly_lily_module_constant ("type-name");
629           SCM type_name = scm_call_1 (typefunc, type);
630
631          
632           scm_puts (_f ("Type check for `%s' failed; value `%s' must be of type `%s'",
633                         ly_symbol2string (sym).to_str0 (),
634                         print_scm_val (val),
635                         ly_scm2string (type_name).to_str0 ()).to_str0 (),
636                     errport);
637           scm_puts ("\n", errport);                   
638         }
639     }
640   return ok;
641 }
642
643
644 /* some SCM abbrevs
645
646    zijn deze nou handig?
647    zijn ze er al in scheme, maar heten ze anders? */
648
649
650 /* Remove doubles from (sorted) list */
651 SCM
652 ly_unique (SCM list)
653 {
654   SCM unique = SCM_EOL;
655   for (SCM i = list; scm_is_pair (i); i = scm_cdr (i))
656     {
657       if (!scm_is_pair (scm_cdr (i))
658           || !ly_c_equal_p (scm_car (i), scm_cadr (i)))
659         unique = scm_cons (scm_car (i), unique);
660     }
661   return scm_reverse_x (unique, SCM_EOL);
662 }
663
664
665 static int
666 scm_default_compare (void const *a, void const *b)
667 {
668   SCM pa = *(SCM*) a;
669   SCM pb = *(SCM*) b;
670   if (pa == pb)
671     return 0;
672   return pa < pb ? -1 : 1;
673 }
674
675 /*  Modify LST in place: qsort it.  */
676 SCM
677 ly_list_qsort_uniq_x (SCM lst)
678 {
679   int len = scm_ilength (lst);
680   SCM *arr = new SCM[len];
681   int k = 0;
682   for (SCM s = lst; SCM_NNULLP (s); s = scm_cdr (s))
683     arr[k++] = scm_car (s);
684
685   assert (k == len);
686   qsort (arr, len, sizeof (SCM), &scm_default_compare);
687
688   SCM *tail = &lst;
689   for (int i = 0; i < len; i++)
690     if (!i || arr[i] != arr[i - 1])
691       {
692         SCM_SETCAR (*tail, arr[i]);
693         tail = SCM_CDRLOC (*tail);
694       }
695
696   *tail = SCM_EOL;
697   delete[] arr;
698
699   return lst; 
700 }
701
702
703 /* tail add */
704 SCM
705 ly_snoc (SCM s, SCM list)
706 {
707   return ly_append2 (list, scm_list_n (s, SCM_UNDEFINED));
708 }
709
710 /* Split list at member s, removing s.
711    Return (BEFORE . AFTER)  */
712 SCM
713 ly_split_list (SCM s, SCM list)
714 {
715   SCM before = SCM_EOL;
716   SCM after = list;
717   for (; scm_is_pair (after);)
718     {
719       SCM i = scm_car (after);
720       after = scm_cdr (after);
721       if (ly_c_equal_p (i, s))
722         break;
723       before = scm_cons (i, before);
724     }
725   return scm_cons ( scm_reverse_x (before, SCM_EOL),  after);
726   
727 }
728
729
730 void
731 taint (SCM *)
732 {
733   /*
734     nop.
735    */
736 }
737
738 /*
739   display stuff without using stack
740  */
741 SCM
742 display_list (SCM s)
743 {
744   SCM p = scm_current_output_port ();
745
746   scm_puts ("(", p);
747   for (; scm_is_pair (s); s = scm_cdr (s))
748     {
749       scm_display (scm_car (s), p);
750       scm_puts (" ", p);      
751     }
752   scm_puts (")", p);
753   return SCM_UNSPECIFIED;
754 }
755
756 Slice
757 int_list_to_slice (SCM l)
758 {
759   Slice s;
760   s.set_empty ();
761   for (; scm_is_pair (l); l = scm_cdr (l))
762     if (scm_is_number (scm_car (l)))
763       s.add_point (scm_to_int (scm_car (l))); 
764   return s;
765 }
766
767 /* Return I-th element, or last elt L. If I < 0, then we take the first
768    element.
769    
770    PRE: length (L) > 0  */
771 SCM
772 robust_list_ref (int i, SCM l)
773 {
774   while (i-- > 0 && scm_is_pair (scm_cdr (l)))
775     l = scm_cdr (l);
776   return scm_car (l);
777 }
778
779 Real
780 robust_scm2double (SCM k, double x)
781 {
782   if (scm_is_number (k))
783     x = scm_to_double (k);
784   return x;
785 }
786
787 Interval
788 robust_scm2interval (SCM k, Drul_array<Real> v)
789 {
790   Interval i;
791   i[LEFT]= v[LEFT];
792   i[RIGHT]= v[RIGHT];
793   if (is_number_pair (k))
794     i = ly_scm2interval (k);
795   return i;
796 }
797
798 Drul_array<Real>
799 robust_scm2drul (SCM k, Drul_array<Real> v)
800 {
801   if (is_number_pair (k))
802     v = ly_scm2interval (k);
803   return v;
804 }
805
806 Offset
807 robust_scm2offset (SCM k, Offset o)
808 {
809   if (is_number_pair (k))
810     o = ly_scm2offset (k);
811   return o;
812 }
813
814 int
815 robust_scm2int (SCM k, int o)
816 {
817   if (scm_integer_p (k) == SCM_BOOL_T)
818     o = scm_to_int (k);
819   return o;
820 }
821
822 SCM
823 alist_to_hashq (SCM alist)
824 {
825   int i = scm_ilength (alist);
826   if (i < 0)
827     return scm_c_make_hash_table (0);
828           
829   SCM tab = scm_c_make_hash_table (i);
830   for (SCM s = alist; scm_is_pair (s); s = scm_cdr (s))
831     {
832       SCM pt = scm_cdar (s);
833       scm_hashq_set_x (tab, scm_caar (s), pt);
834     }
835   return tab; 
836 }
837
838 /*
839   Debugging mem leaks:
840  */
841 LY_DEFINE (ly_protects, "ly:protects",
842            0, 0, 0, (),
843           "Return hash of protected objects.")
844 {
845   return scm_protects;
846 }
847
848 LY_DEFINE (ly_gettext, "ly:gettext",
849            1, 0, 0, (SCM string),
850            "Gettext wrapper.")
851 {
852   SCM_ASSERT_TYPE (scm_is_string (string), string, SCM_ARG1,
853                    __FUNCTION__, "string");
854   return scm_makfrom0str (gettext (scm_i_string_chars (string)));
855 }
856
857
858
859
860 LY_DEFINE (ly_output_backend, "ly:output-backend",
861            0, 0, 0, (),
862            "Return name of output backend.")
863 {
864   return scm_makfrom0str (output_backend_global.to_str0 ());
865 }
866
867
868 LY_DEFINE (ly_output_formats, "ly:output-formats",
869            0, 0, 0, (),
870            "Formats passed to --format as a list of strings, "
871            "used for the output.")
872 {
873   Array<String> output_formats = split_string (output_format_global, ',');
874
875   SCM lst = SCM_EOL;
876   int output_formats_count = output_formats.size ();
877   for (int i = 0; i < output_formats_count; i ++)
878     lst = scm_cons (scm_makfrom0str (output_formats[i].to_str0 ()), lst);
879
880   return lst;
881 }