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