Expose permanent debugging code to the C compiler.
[geda-gaf/berndj.git] / libgeda / src / g_rc.c
blob804c431aba5ccfd073572ff104bd5a93b7e64432
1 /* gEDA - GPL Electronic Design Automation
2 * libgeda - gEDA's library
3 * Copyright (C) 1998-2007 Ales Hvezda
4 * Copyright (C) 1998-2007 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
20 #include <config.h>
22 #include <stdio.h>
23 #include <sys/stat.h>
24 #include <ctype.h>
25 #ifdef HAVE_STRING_H
26 #include <string.h>
27 #endif
28 #ifdef HAVE_DIRENT_H
29 #include <dirent.h>
30 #endif
31 #ifdef HAVE_STDLIB_H
32 #include <stdlib.h>
33 #endif
34 #ifdef HAVE_UNISTD_H
35 #include <unistd.h>
36 #endif
38 #include "libgeda_priv.h"
40 #ifdef HAVE_LIBDMALLOC
41 #include <dmalloc.h>
42 #endif
44 /*! \todo Finish function documentation!!!
45 * \brief
46 * \par Function Description
49 int vstbl_lookup_str(const vstbl_entry *table,
50 int size, const char *str)
52 int i;
54 for(i = 0; i < size; i++) {
55 if(strcmp(table[i].m_str, str) == 0) {
56 break;
59 return i;
62 /*! \todo Finish function documentation!!!
63 * \brief
64 * \par Function Description
67 int vstbl_get_val(const vstbl_entry *table, int index)
69 return table[index].m_val;
72 /*! \todo Finish function documentation!!!
73 * \brief
74 * \par Function Description
77 SCM g_rc_mode_general(SCM scmmode,
78 const char *rc_name,
79 int *mode_var,
80 const vstbl_entry *table,
81 int table_size)
83 SCM ret;
84 int index;
85 char *mode;
87 SCM_ASSERT (scm_is_string (scmmode), scmmode,
88 SCM_ARG1, rc_name);
90 scm_dynwind_begin(0);
92 mode = scm_to_locale_string(scmmode);
93 scm_dynwind_free(mode);
95 index = vstbl_lookup_str(table, table_size, mode);
96 /* no match? */
97 if(index == table_size) {
98 fprintf(stderr,
99 "Invalid mode [%s] passed to %s\n",
100 mode,
101 rc_name);
102 ret = SCM_BOOL_F;
103 } else {
104 *mode_var = vstbl_get_val(table, index);
105 ret = SCM_BOOL_T;
108 scm_dynwind_end();
110 return ret;
113 extern GHashTable *font_char_to_file;
115 /*! \brief Reads the gafrc file.
116 * \par Function Description
117 * This is the function which actually reads in the RC file.
118 * First, it looks in a list of previously read RC files. If the file has
119 * already been read, it just says OK. After reading the file, it places
120 * the filename in the list of read files.
122 * \param [in] toplevel The TOPLEVEL object.
123 * \param [in] fname RC file name to read.
124 * \param [in] ok_msg Message to print if file is read ok.
125 * \param [in] err_msg Message to print if file read error occurs
126 * \return 1 on success, 0 otherwise.
128 gint g_rc_parse_general(TOPLEVEL *toplevel,
129 const gchar *fname,
130 const gchar *ok_msg, const gchar *err_msg)
132 gint found_rc = FALSE;
133 GList *found_rc_filename_element;
135 /* First see if fname is in list of previously read RC files. */
136 found_rc_filename_element = g_list_find_custom(toplevel->RC_list,
137 (gconstpointer) fname,
138 (GCompareFunc) strcmp);
139 if (found_rc_filename_element != NULL) {
140 /* We've already read this one in. */
141 s_log_message(_("RC file [%s] already read in.\n"), fname);
142 return 0;
145 /* Now try to read in contents of RC file. */
146 if (access (fname, R_OK) == 0) {
147 g_read_file (fname);
148 found_rc = 1;
149 /* Everything was OK. Now add this file to list of read RC files. */
150 toplevel->RC_list = g_list_append (toplevel->RC_list,
151 g_strdup (fname));
152 s_log_message (ok_msg, fname);
153 } else {
154 found_rc = 0;
155 s_log_message (err_msg, fname);
158 return found_rc;
162 /*! \brief Read gEDA root path from RC file.
163 * \par Function Description
164 * This function will read the RC file and parse the root path for gEDA.
166 * \return String containing rc root path
168 * \warning Do not free the returned character string.
170 const gchar* g_rc_parse_path(void)
172 const gchar *rc_path;
174 if (g_strcasecmp (GEDARCDIR, "none") == 0) {
175 /* rc dir not specified at configure time, so search for config in */
176 /* the normal GEDADATA directory */
177 rc_path = g_getenv ("GEDADATA");
178 } else {
179 /* rc path specified at configure time, always return specified path */
180 rc_path = GEDARCDIR;
183 return(rc_path);
186 /*! \brief Parses a system RC file.
187 * \par Function Description
188 * This function will open and parse a system rc file.
190 * \param [in] toplevel The TOPLEVEL object.
191 * \param [in] rcname System RC file name to parse.
192 * \return 1 on success, 0 on failure.
194 gint g_rc_parse_system_rc(TOPLEVEL *toplevel, const gchar *rcname)
196 const gchar *geda_data = g_getenv ("GEDADATA");
197 gint found_rc;
198 gchar *tmp;
199 char *filename;
200 gchar *ok_msg, *err_msg;
202 if (geda_data == NULL) {
203 fprintf(stderr, "You must set the GEDADATA environment variable!\n");
204 exit(-1);
207 tmp = g_strconcat (g_rc_parse_path (),
208 G_DIR_SEPARATOR_S,
209 "system-", rcname,
210 NULL);
211 filename = f_normalize_filename (tmp, NULL);
212 if (filename == NULL) {
213 return 0;
216 ok_msg = g_strdup_printf (_("Read system-%s file [%%s]\n"),
217 rcname);
218 err_msg = g_strdup_printf (_("Did not find required system-%s file [%%s]\n"),
219 rcname);
220 found_rc = g_rc_parse_general(toplevel, filename, ok_msg, err_msg);
222 g_free(ok_msg);
223 g_free(err_msg);
224 g_free(tmp);
225 g_free(filename);
227 return found_rc;
230 /*! \brief Parse a RC file in users home directory.
231 * \par Function Description
232 * This function will open and parse a RC file in the users home directory.
234 * \param [in] toplevel The TOPLEVEL object.
235 * \param [in] rcname User's RC file name.
236 * \return 1 on success, 0 on failure.
238 gint g_rc_parse_home_rc(TOPLEVEL *toplevel, const gchar *rcname)
240 const gchar *home = g_getenv ("HOME");
241 gint found_rc;
242 gchar *tmp;
243 char *filename;
244 gchar *ok_msg, *err_msg;
246 if (home == NULL) {
247 return 0;
250 tmp = g_build_filename (home, ".gEDA", rcname, NULL);
251 filename = f_normalize_filename (tmp, NULL);
252 if (filename == NULL) {
253 g_free(tmp);
254 return 0;
257 ok_msg = g_strdup_printf (_("Read ~/.gEDA/%s file [%%s]\n"),
258 rcname);
259 err_msg = g_strdup_printf (_("Did not find optional ~/.gEDA/%s file [%%s]\n"),
260 rcname);
261 found_rc = g_rc_parse_general(toplevel, filename, ok_msg, err_msg);
263 g_free(ok_msg);
264 g_free(err_msg);
265 g_free(tmp);
266 g_free(filename);
268 return found_rc;
271 /*! \brief Parse rc file in current working directory.
272 * \par Function Description
273 * This function will open and parse a RC file in the current working directory.
275 * \param [in] toplevel The TOPLEVEL object.
276 * \param [in] rcname Local directory RC file name.
277 * \return 1 on success, 0 on failure.
279 gint g_rc_parse_local_rc(TOPLEVEL *toplevel, const gchar *rcname)
281 gint found_rc;
282 char *filename;
283 gchar *ok_msg;
284 gchar *err_msg;
286 filename = f_normalize_filename (rcname, NULL);
287 if (filename == NULL) {
288 return 0;
291 ok_msg = g_strdup_printf (_("Read local %s file [%%s]\n"),
292 rcname);
293 err_msg = g_strdup_printf (_("Did not find optional local %s file [%%s]\n"),
294 rcname);
295 found_rc = g_rc_parse_general(toplevel, filename, ok_msg, err_msg);
297 g_free(ok_msg);
298 g_free(err_msg);
299 g_free(filename);
301 return found_rc;
304 /*! \brief Parse a RC file from a specified location.
305 * \par Function Description
306 * This function will open and parse a RC file from a specified location.
308 * \param [in] toplevel The TOPLEVEL object.
309 * \param [in] rcname Specified location RC file name.
310 * \return 1 on success, 0 on failure.
312 gint g_rc_parse_specified_rc(TOPLEVEL *toplevel, const gchar *rcname)
314 gint found_rc = 0;
315 char *filename;
316 gchar *rcbasename;
317 gchar *ok_msg;
318 gchar *err_msg;
320 if (rcname == NULL) {
321 return 0;
324 filename = f_normalize_filename (rcname, NULL);
325 if (filename == NULL) {
326 return 0;
329 rcbasename = g_path_get_basename (rcname);
331 ok_msg = g_strdup_printf (_("Read specified %s file [%%s]\n"),
332 rcbasename);
333 err_msg = g_strdup_printf (_("Did not find specified %s file [%%s]\n"),
334 rcbasename);
335 found_rc = g_rc_parse_general(toplevel, filename, ok_msg, err_msg);
337 g_free(ok_msg);
338 g_free(err_msg);
339 g_free(filename);
340 g_free(rcbasename);
342 return found_rc;
345 /*! \brief General RC file parsing function.
346 * \par Function Description
347 * This function will check for System, HOME and Local RC files matching
348 * the rcname input parameter. If none of those three are found it will
349 * search for the specified_rc_filename. When none are found it will
350 * call exit(-1) to terminate the program.
352 * \param [in] toplevel The TOPLEVEL object.
353 * \param [in] rcname RC file name.
354 * \param [in] specified_rc_filename Specific location RC file name.
355 * \return calls exit(-1) when no RC file matching either rcname or
356 * specified_rc_filename is found.
358 void g_rc_parse(TOPLEVEL *toplevel,
359 const gchar *rcname, const gchar *specified_rc_filename)
361 gint found_rc = 0;
362 char *rc_path;
364 /* set the GEDADATARC environment variable so that the rc files */
365 /* know where to look for others */
366 rc_path = f_normalize_filename (g_rc_parse_path (), NULL);
368 g_setenv ("GEDADATARC", rc_path, TRUE);
369 g_free (rc_path);
371 /* visit rc files in order */
372 /* Changed by SDB 1.2.2005 in response to Peter Kaiser's bug report.
373 * Read gafrc files first */
374 found_rc |= g_rc_parse_system_rc(toplevel, "gafrc");
375 found_rc |= g_rc_parse_home_rc(toplevel, "gafrc");
376 found_rc |= g_rc_parse_local_rc(toplevel, "gafrc");
377 /* continue support for individual rc files for each program. */
378 found_rc |= g_rc_parse_system_rc(toplevel, rcname);
379 found_rc |= g_rc_parse_home_rc(toplevel, rcname);
380 found_rc |= g_rc_parse_local_rc(toplevel, rcname);
382 /* New fcn introduced by SDB to consolidate this & make it available
383 * for other programs */
384 found_rc |= g_rc_parse_specified_rc(toplevel, specified_rc_filename);
386 /* Oh well, I couldn't find any rcfile, exit! */
387 if (!found_rc) {
388 /*! \todo these two are basically the
389 * same. Inefficient!
391 s_log_message(_("Could not find any %s file!\n"), rcname);
392 exit(-1);
396 /*! \brief
397 * \par Function Description
399 * \param [in] path
400 * \param [in] name Optional descriptive name for library directory.
401 * \return SCM_BOOL_T on success, SCM_BOOL_F otherwise.
403 SCM g_rc_component_library(SCM path, SCM name)
405 gchar *string;
406 char *namestr = NULL;
407 char *path_chars;
409 SCM_ASSERT (scm_is_string (path), path,
410 SCM_ARG1, "component-library");
412 scm_dynwind_begin(0);
414 if (name != SCM_UNDEFINED) {
415 SCM_ASSERT (scm_is_string (name), name,
416 SCM_ARG2, "component-library");
417 namestr = scm_to_locale_string(name);
418 scm_dynwind_free(namestr);
421 /* take care of any shell variables */
422 path_chars = scm_to_locale_string(path);
423 scm_dynwind_free(path_chars);
424 string = s_expand_env_variables(path_chars);
426 /* invalid path? */
427 if (!g_file_test (string, G_FILE_TEST_IS_DIR)) {
428 fprintf(stderr,
429 "Invalid path [%s] passed to component-library\n",
430 string);
431 g_free(string);
432 scm_dynwind_end();
433 return SCM_BOOL_F;
436 if (g_path_is_absolute (string)) {
437 s_clib_add_directory (string, namestr);
438 } else {
439 gchar *cwd = g_get_current_dir ();
440 gchar *temp;
441 temp = g_build_filename (cwd, string, NULL);
442 s_clib_add_directory (temp, namestr);
443 g_free(temp);
444 g_free(cwd);
447 g_free(string);
449 scm_dynwind_end();
450 return SCM_BOOL_T;
453 /*! \brief Guile callback for adding library commands.
454 * \par Function Description
455 * Callback function for the "component-library-command" Guile
456 * function, which can be used in the rc files to add a command to
457 * the component library.
459 * \param [in] listcmd command to get a list of symbols
460 * \param [in] getcmd command to get a symbol from the library
461 * \param [in] name Optional descriptive name for component source.
462 * \return SCM_BOOL_T on success, SCM_BOOL_F otherwise.
464 SCM g_rc_component_library_command (SCM listcmd, SCM getcmd,
465 SCM name)
467 const CLibSource *src;
468 gchar *lcmdstr, *gcmdstr;
469 char *listcmd_c, *getcmd_c, *namestr;
471 SCM_ASSERT (scm_is_string (listcmd), listcmd, SCM_ARG1,
472 "component-library-command");
473 SCM_ASSERT (scm_is_string (getcmd), getcmd, SCM_ARG2,
474 "component-library-command");
475 SCM_ASSERT (scm_is_string (name), name, SCM_ARG3,
476 "component-library-command");
478 scm_dynwind_begin(0);
480 /* take care of any shell variables */
481 /*! \bug this may be a security risk! */
482 listcmd_c = scm_to_locale_string(listcmd);
483 scm_dynwind_free(listcmd_c);
484 lcmdstr = s_expand_env_variables(listcmd_c);
485 scm_dynwind_unwind_handler(&g_free, lcmdstr, SCM_F_WIND_EXPLICITLY);
487 /* take care of any shell variables */
488 /*! \bug this may be a security risk! */
489 getcmd_c = scm_to_locale_string(getcmd);
490 scm_dynwind_free(getcmd_c);
491 gcmdstr = s_expand_env_variables(getcmd_c);
492 scm_dynwind_unwind_handler(&g_free, gcmdstr, SCM_F_WIND_EXPLICITLY);
494 namestr = scm_to_locale_string (name);
495 scm_dynwind_free(namestr);
497 src = s_clib_add_command (lcmdstr, gcmdstr, namestr);
499 scm_dynwind_end();
501 if (src != NULL) return SCM_BOOL_T;
503 return SCM_BOOL_F;
506 /*! \brief Guile callback for adding library functions.
507 * \par Function Description
508 * Callback function for the "component-library-funcs" Guile
509 * function, which can be used in the rc files to add a set of Guile
510 * procedures for listing and generating symbols.
512 * \param [in] listfunc A Scheme procedure which takes no arguments
513 * and returns a Scheme list of component names.
514 * \param [in] getfunc A Scheme procedure which takes a component
515 * name as an argument and returns a symbol
516 * encoded in a string in gEDA format, or the \b
517 * \#f if the component name is unknown.
518 * \param [in] name A descriptive name for this component source.
520 * \returns SCM_BOOL_T on success, SCM_BOOL_F otherwise.
522 SCM g_rc_component_library_funcs (SCM listfunc, SCM getfunc, SCM name)
524 SCM_ASSERT (scm_is_true (scm_procedure_p (listfunc)), listfunc, SCM_ARG1,
525 "component-library-funcs");
526 SCM_ASSERT (scm_is_true (scm_procedure_p (getfunc)), getfunc, SCM_ARG2,
527 "component-library-funcs");
528 SCM_ASSERT (scm_is_string (name), name, SCM_ARG1,
529 "component-library-funcs");
531 if (s_clib_add_scm(listfunc, getfunc, name) != NULL) {
532 return SCM_BOOL_T;
533 } else {
534 return SCM_BOOL_F;
538 /*! \todo Finish function description!!!
539 * \brief
540 * \par Function Description
542 * \param [in] path
543 * \return SCM_BOOL_T on success, SCM_BOOL_F otherwise.
545 SCM g_rc_component_library_search(SCM path)
547 gchar *string;
548 GDir *dir;
549 const gchar *entry;
550 char *path_chars;
552 SCM_ASSERT (scm_is_string (path), path,
553 SCM_ARG1, "component-library-search");
555 scm_dynwind_begin(0);
557 /* take care of any shell variables */
558 path_chars = scm_to_locale_string(path);
559 scm_dynwind_free(path_chars);
560 string = s_expand_env_variables(path_chars);
562 /* invalid path? */
563 if (!g_file_test (string, G_FILE_TEST_IS_DIR)) {
564 fprintf (stderr,
565 "Invalid path [%s] passed to component-library-search\n",
566 string);
567 g_free(string);
568 scm_dynwind_end();
569 return SCM_BOOL_F;
572 dir = g_dir_open (string, 0, NULL);
573 if (dir == NULL) {
574 fprintf (stderr,
575 "Invalid path [%s] passed to component-library-search\n",
576 string);
577 g_free(string);
578 scm_dynwind_end();
579 return SCM_BOOL_F;
582 while ((entry = g_dir_read_name (dir))) {
583 /* don't do . and .. and special case font */
584 if ((g_strcasecmp (entry, ".") != 0) &&
585 (g_strcasecmp (entry, "..") != 0) &&
586 (g_strcasecmp (entry, "font") != 0))
588 gchar *fullpath = g_build_filename (string, entry, NULL);
590 if (g_file_test (fullpath, G_FILE_TEST_IS_DIR)) {
591 if (g_path_is_absolute (fullpath)) {
592 s_clib_add_directory (fullpath, NULL);
593 } else {
594 gchar *cwd = g_get_current_dir ();
595 gchar *temp;
596 temp = g_build_filename (cwd, fullpath, NULL);
597 s_clib_add_directory (temp, NULL);
598 g_free(temp);
599 g_free(cwd);
602 g_free(fullpath);
606 g_free(string);
608 scm_dynwind_end();
609 return SCM_BOOL_T;
612 /*! \todo Finish function description!!!
613 * \brief
614 * \par Function Description
616 * \param [in] path
617 * \return SCM_BOOL_T on success, SCM_BOOL_F otherwise.
619 SCM g_rc_source_library(SCM path)
621 gchar *string;
622 char *path_chars;
624 SCM_ASSERT (scm_is_string (path), path,
625 SCM_ARG1, "source-library");
627 scm_dynwind_begin(0);
629 /* take care of any shell variables */
630 path_chars = scm_to_locale_string(path);
631 scm_dynwind_free(path_chars);
632 string = s_expand_env_variables(path_chars);
634 /* invalid path? */
635 if (!g_file_test (string, G_FILE_TEST_IS_DIR)) {
636 fprintf (stderr,
637 "Invalid path [%s] passed to source-library\n",
638 string);
639 g_free(string);
640 scm_dynwind_end();
641 return SCM_BOOL_F;
644 if (g_path_is_absolute (string)) {
645 s_slib_add_entry (string);
646 } else {
647 gchar *cwd = g_get_current_dir ();
648 gchar *temp;
649 temp = g_build_filename (cwd, string, NULL);
650 s_slib_add_entry (temp);
651 g_free(temp);
652 g_free(cwd);
655 g_free(string);
657 scm_dynwind_end();
658 return SCM_BOOL_T;
661 /*! \todo Finish function description!!!
662 * \brief
663 * \par Function Description
665 * \param [in] path
666 * \return SCM_BOOL_T on success, SCM_BOOL_F otherwise.
668 SCM g_rc_source_library_search(SCM path)
670 gchar *string;
671 GDir *dir;
672 const gchar *entry;
673 char *path_chars;
675 SCM_ASSERT (scm_is_string (path), path,
676 SCM_ARG1, "source-library-search");
678 scm_dynwind_begin(0);
680 /* take care of any shell variables */
681 path_chars = scm_to_locale_string(path);
682 scm_dynwind_free(path_chars);
683 string = s_expand_env_variables(path_chars);
685 /* invalid path? */
686 if (!g_file_test (string, G_FILE_TEST_IS_DIR)) {
687 fprintf (stderr,
688 "Invalid path [%s] passed to source-library-search\n",
689 string);
690 g_free(string);
691 scm_dynwind_end();
692 return SCM_BOOL_F;
695 dir = g_dir_open (string, 0, NULL);
696 if (dir == NULL) {
697 fprintf (stderr,
698 "Invalid path [%s] passed to source-library-search\n",
699 string);
700 g_free(string);
701 scm_dynwind_end();
702 return SCM_BOOL_F;
705 while ((entry = g_dir_read_name (dir))) {
706 /* don't do . and .. and special case font */
707 if ((g_strcasecmp (entry, ".") != 0) &&
708 (g_strcasecmp (entry, "..") != 0) &&
709 (g_strcasecmp (entry, "font") != 0))
711 gchar *fullpath = g_build_filename (string, entry, NULL);
713 if (g_file_test (fullpath, G_FILE_TEST_IS_DIR)) {
714 if (s_slib_uniq (fullpath)) {
715 if (g_path_is_absolute (fullpath)) {
716 s_slib_add_entry (fullpath);
717 } else {
718 gchar *cwd = g_get_current_dir ();
719 gchar *temp;
720 temp = g_build_filename (cwd, fullpath, NULL);
721 s_slib_add_entry (temp);
722 g_free(temp);
723 g_free(cwd);
727 g_free(fullpath);
731 g_free(string);
733 scm_dynwind_end();
734 return SCM_BOOL_T;
737 /*! \todo Finish function description!!!
738 * \brief
739 * \par Function Description
741 * \param [in] width
742 * \param [in] height
743 * \param [in] border
744 * \return SCM_BOOL_T always.
746 SCM g_rc_world_size(SCM width, SCM height, SCM border)
747 #define FUNC_NAME "world-size"
749 int i_width, i_height, i_border;
750 int init_right, init_bottom;
752 SCM_ASSERT (SCM_NIMP (width) && SCM_REALP (width), width,
753 SCM_ARG1, FUNC_NAME);
754 SCM_ASSERT (SCM_NIMP (height) && SCM_REALP (height), height,
755 SCM_ARG2, FUNC_NAME);
756 SCM_ASSERT (SCM_NIMP (border) && SCM_REALP (border), border,
757 SCM_ARG3, FUNC_NAME);
759 /* yes this is legit, we are casing the resulting double to an int */
760 i_width = (int) (scm_to_double(width) * MILS_PER_INCH);
761 i_height = (int) (scm_to_double(height) * MILS_PER_INCH);
762 i_border = (int) (scm_to_double(border) * MILS_PER_INCH);
764 PAPERSIZEtoWORLD(i_width, i_height, i_border,
765 &init_right, &init_bottom);
767 if (GEDA_DEBUG) {
768 printf("%d %d\n", i_width, i_height);
769 printf("%d %d\n", init_right, init_bottom);
772 default_init_right = init_right;
773 default_init_bottom = init_bottom;
775 return SCM_BOOL_T;
777 #undef FUNC_NAME
779 /*! \todo Finish function description!!!
780 * \brief
781 * \par Function Description
783 * \param [in] name
784 * \return SCM_BOOL_T always.
786 SCM g_rc_untitled_name(SCM name)
788 SCM_ASSERT (scm_is_string (name), name,
789 SCM_ARG1, "untitled-name");
791 g_free(default_untitled_name);
793 default_untitled_name = g_strdup_scm_string(name);
795 return SCM_BOOL_T;
798 /*! \todo Finish function description!!!
799 * \brief
800 * \par Function Description
802 * \param [in] path
803 * \return SCM_BOOL_T on success, SCM_BOOL_F otherwise.
805 SCM g_rc_font_directory(SCM path)
807 gchar *string;
808 char *path_chars;
810 SCM_ASSERT (scm_is_string (path), path,
811 SCM_ARG1, "font-directory");
813 scm_dynwind_begin(0);
815 /* take care of any shell variables */
816 path_chars = scm_to_locale_string(path);
817 scm_dynwind_free(path_chars);
818 string = s_expand_env_variables(path_chars);
820 /* invalid path? */
821 if (!g_file_test (string, G_FILE_TEST_IS_DIR)) {
822 fprintf (stderr,
823 "Invalid path [%s] passed to font-directory\n",
824 string);
825 g_free(string);
826 scm_dynwind_end();
827 return SCM_BOOL_F;
830 g_free(default_font_directory);
831 default_font_directory = string;
833 scm_dynwind_end();
834 return SCM_BOOL_T;
837 /*! \todo Finish function description!!!
838 * \brief
839 * \par Function Description
841 * \param [in] path
842 * \return SCM_BOOL_T on success, SCM_BOOL_F otherwise.
844 SCM g_rc_scheme_directory(SCM path)
846 gchar *string;
847 char *path_chars;
849 SCM_ASSERT (scm_is_string (path), path,
850 SCM_ARG1, "scheme-directory");
852 scm_dynwind_begin(0);
854 /* take care of any shell variables */
855 path_chars = scm_to_locale_string(path);
856 scm_dynwind_free(path_chars);
857 string = s_expand_env_variables(path_chars);
859 /* invalid path? */
860 if (!g_file_test (string, G_FILE_TEST_IS_DIR)) {
861 fprintf (stderr,
862 "Invalid path [%s] passed to scheme-directory\n",
863 string);
864 g_free(string);
865 scm_dynwind_end();
866 return SCM_BOOL_F;
869 g_free(default_scheme_directory);
870 default_scheme_directory = string;
872 scm_dynwind_end();
873 return SCM_BOOL_T;
876 /*! \todo Finish function description!!!
877 * \brief
878 * \par Function Description
880 * \param [in] path
881 * \return SCM_BOOL_T on success, SCM_BOOL_F otherwise.
883 SCM g_rc_bitmap_directory(SCM path)
885 gchar *string;
886 char *path_chars;
888 SCM_ASSERT (scm_is_string (path), path,
889 SCM_ARG1, "bitmap-directory");
891 scm_dynwind_begin(0);
893 /* take care of any shell variables */
894 path_chars = scm_to_locale_string(path);
895 scm_dynwind_free(path_chars);
896 string = s_expand_env_variables(path_chars);
898 /* invalid path? */
899 if (!g_file_test (string, G_FILE_TEST_IS_DIR)) {
900 fprintf (stderr,
901 "Invalid path [%s] passed to bitmap-directory\n",
902 string);
903 g_free(string);
904 scm_dynwind_end();
905 return SCM_BOOL_F;
908 g_free(default_bitmap_directory);
909 default_bitmap_directory = string;
911 scm_dynwind_end();
912 return SCM_BOOL_T;
915 /*! \todo Finish function description!!!
916 * \brief
917 * \par Function Description
919 * \param [in] scmsymname
920 * \return SCM_BOOL_T always.
922 SCM g_rc_bus_ripper_symname(SCM scmsymname)
924 SCM_ASSERT (scm_is_string (scmsymname), scmsymname,
925 SCM_ARG1, "bus-ripper-symname");
927 g_free(default_bus_ripper_symname);
928 default_bus_ripper_symname = g_strdup_scm_string(scmsymname);
930 return SCM_BOOL_T;
933 /*! \todo Finish function description!!!
934 * \brief
935 * \par Function Description
937 * \param [in] scmsymname
938 * \return SCM_BOOL_T always.
940 SCM g_rc_postscript_prolog(SCM scmsymname)
942 char *sym_chars;
943 SCM_ASSERT (scm_is_string (scmsymname), scmsymname,
944 SCM_ARG1, "postsript-prolog");
946 scm_dynwind_begin(0);
948 g_free(default_postscript_prolog);
950 /* take care of any shell variables */
951 sym_chars = scm_to_locale_string(scmsymname);
952 scm_dynwind_free(sym_chars);
953 default_postscript_prolog = s_expand_env_variables(sym_chars);
955 scm_dynwind_end();
956 return SCM_BOOL_T;
959 /*! \todo Finish function description!!!
960 * \brief
961 * \par Function Description
963 * \return SCM_BOOL_T always.
965 SCM g_rc_reset_component_library(void)
967 s_clib_init();
969 return SCM_BOOL_T;
972 /*! \todo Finish function description!!!
973 * \brief
974 * \par Function Description
976 * \return SCM_BOOL_T always.
978 SCM g_rc_reset_source_library(void)
980 s_slib_free();
981 s_slib_init();
983 return SCM_BOOL_T;
986 /*! \todo Finish function description!!!
987 * \brief
988 * \par Function Description
990 * \param [in] scmcharstr
991 * \param [in] scmfilename
992 * \return SCM_BOOL_T on success, SCM_BOOL_F otherwise.
994 SCM g_rc_map_font_character_to_file(SCM scmcharstr, SCM scmfilename)
996 gchar *charstr, *filename;
997 gunichar character;
999 SCM_ASSERT (scm_is_string (scmcharstr), scmcharstr,
1000 SCM_ARG1, "map-font-character-to-file");
1001 SCM_ASSERT (scm_is_string (scmfilename), scmfilename,
1002 SCM_ARG2, "map-font-character-to-file");
1004 scm_dynwind_begin(0);
1006 charstr = scm_to_locale_string(scmcharstr);
1007 filename = scm_to_locale_string(scmfilename);
1008 scm_dynwind_free(charstr);
1009 scm_dynwind_free(filename);
1011 if (charstr == NULL || filename == NULL) {
1012 fprintf(stderr,
1013 "%s requires two strings as parameters\n",
1014 "map-font-character-to-file"
1016 scm_dynwind_end();
1017 return SCM_BOOL_F;
1020 /* take care of expansion of any shell variables in filename */
1021 filename = s_expand_env_variables (filename);
1023 character = g_utf8_get_char_validated (charstr, -1);
1025 /* insert the new character declaration in the hash table */
1026 g_hash_table_insert (font_char_to_file,
1027 GUINT_TO_POINTER ((guint)character),
1028 filename);
1030 scm_dynwind_end();
1031 return SCM_BOOL_T;
1034 /*! \todo Finish function documentation!!!
1035 * \brief
1036 * \par Function Description
1039 SCM g_rc_attribute_promotion(SCM mode)
1041 static const vstbl_entry mode_table[] = {
1042 {TRUE , "enabled" },
1043 {FALSE, "disabled"},
1046 RETURN_G_RC_MODE("attribute-promotion",
1047 default_attribute_promotion);
1050 /*! \todo Finish function documentation!!!
1051 * \brief
1052 * \par Function Description
1055 SCM g_rc_promote_invisible(SCM mode)
1057 static const vstbl_entry mode_table[] = {
1058 {TRUE , "enabled" },
1059 {FALSE, "disabled"},
1062 RETURN_G_RC_MODE("promote-invisible",
1063 default_promote_invisible);
1066 /*! \todo Finish function documentation!!!
1067 * \brief
1068 * \par Function Description
1071 SCM g_rc_keep_invisible(SCM mode)
1073 static const vstbl_entry mode_table[] = {
1074 {TRUE , "enabled" },
1075 {FALSE, "disabled"},
1078 RETURN_G_RC_MODE("keep-invisible",
1079 default_keep_invisible);
1082 /*! \todo Finish function description!!!
1083 * \brief
1084 * \par Function Description
1086 * \param [in] attrlist
1087 * \return SCM_BOOL_T always.
1089 SCM g_rc_always_promote_attributes(SCM attrlist)
1091 GList *list=NULL;
1092 int i;
1093 gchar *attr;
1094 gchar **attr2;
1096 g_list_foreach(default_always_promote_attributes, (GFunc)g_free, NULL);
1097 g_list_free(default_always_promote_attributes);
1099 if (scm_is_string (attrlist)) {
1100 char *attrlist_chars;
1102 s_log_message(_("WARNING: using a string for 'always-promote-attributes'"
1103 " is deprecated. Use a list of strings instead\n"));
1105 /* convert the space separated strings into a GList */
1106 attrlist_chars = scm_to_locale_string(attrlist);
1107 attr2 = g_strsplit(attrlist_chars, " ", 0);
1108 free(attrlist_chars);
1109 for (i=0; attr2[i] != NULL; i++) {
1110 if (strlen(attr2[i]) > 0) {
1111 list = g_list_prepend(list, g_strdup(attr2[i]));
1114 g_strfreev(attr2);
1115 } else {
1116 SCM rest;
1117 SCM_ASSERT(scm_list_p(attrlist), attrlist, SCM_ARG1, "always-promote-attributes");
1118 /* convert the scm list into a GList */
1119 for (rest = attrlist; !scm_is_null(rest); rest = SCM_CDR(rest)) {
1120 SCM_ASSERT(scm_is_string(SCM_CAR(rest)), SCM_CAR(rest), SCM_ARG1,
1121 "always-promote-attribute: list element is not a string");
1122 attr = g_strdup_scm_string(SCM_CAR(rest));
1123 list = g_list_prepend(list, attr);
1127 default_always_promote_attributes = g_list_reverse(list);
1129 return SCM_BOOL_T;