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