1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
|
@c -*- mode: Noweb; noweb-doc-mode: texinfo-mode; noweb-code-mode: c-mode -*-
@node File g_basic.c,,,Top
@chapter File @file{g_basic.c}
@section File header
@format
@anchor{g_basic.c - -root-}
@i{<<g_basic.c : *>>=}@t{
@i{<<g_basic.c : copyright and license -- @ref{g_basic.c - copyright and license}>>}
/* DO NOT read or edit this file ! Use ../noweb/g_basic.nw instead */
@i{<<g_basic.c : include directives -- @ref{g_basic.c - include directives}>>}
@i{<<g_basic.c : load() -- @ref{g_basic.c - load()}>>}
@i{<<g_basic.c : load_error_handler() -- @ref{g_basic.c - load_error_handler()}>>}
@i{<<g_basic.c : g_read_file() -- @ref{g_basic.c - g_read_file()}>>}
}
@end format
@format
@anchor{g_basic.c - copyright and license}
@i{<<g_basic.c : copyright and license>>=}@t{
/* gEDA - GPL Electronic Design Automation
* libgeda - gEDA's library
* Copyright (C) 1998-2000 Ales V. Hvezda
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
*/
}
@end format
@format
@anchor{g_basic.c - include directives}
@i{<<g_basic.c : include directives>>=}@t{
#include <config.h>
#include <stdio.h>
#include <sys/stat.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_ASSERT_H
#include <assert.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <gtk/gtk.h>
#include <libguile.h>
#include "defines.h"
#include "struct.h"
#include "globals.h"
#include "o_types.h"
#include "../include/prototype.h"
#ifdef HAVE_LIBDMALLOC
#include <dmalloc.h>
#endif
}
@end format
@section Function @code{load()}
@defun load data
@end defun
@format
@anchor{g_basic.c - load()}
@i{<<g_basic.c : load()>>=}@t{
/* The following code was contributed by thi (with formating changes
* by Ales) Thanks! */
/* Later updated by spe */
/* This `load()' is modeled after libguile/load.c, load().
* Additionally, the most recent form read is saved in case something
* goes wrong. */
static SCM most_recently_read_form = SCM_BOOL_F;
static SCM
load (void *data)
@{
SCM load_port = (SCM)data;
SCM form;
int eof_found = 0;
while (!eof_found) @{
form = scm_read(load_port);
if (SCM_EOF_OBJECT_P(form)) @{
eof_found = 1;
@} else @{
most_recently_read_form = form;
#ifdef HAVE_SCM_EVAL_X_MODULE
scm_eval_x (form, scm_current_module() );
#else
scm_eval_x (form);
#endif
@}
@}
most_recently_read_form = SCM_BOOL_F;
return SCM_BOOL_T;
@}
@display
@r{Defines :
@t{load},
-- @ref{g_basic.c - g_read_file()}.
@t{most_recently_read_form},
-- @ref{g_basic.c - load_error_handler()}.
}
@end display
}
@end format
@section Function @code{load_error_handler()}
@defun load_error_handler data tag throw_args
@end defun
@format
@anchor{g_basic.c - load_error_handler()}
@i{<<g_basic.c : load_error_handler()>>=}@t{
static SCM
load_error_handler(void *data, SCM tag, SCM throw_args)
@{
SCM cur_out = scm_current_output_port ();
SCM load_port = (SCM)data;
SCM filename = scm_port_filename(load_port);
/*
* If misc-error the column and line pointers points
* to end of file. Not necessary to confuse user.
*/
if (!scm_eq_p (tag, scm_str2symbol ("misc-error"))) @{
scm_display(scm_makfrom0str("Error : "), cur_out);
scm_display(tag, cur_out);
scm_display(scm_makfrom0str(" [C:"), cur_out);
scm_display(scm_port_column(load_port), cur_out );
scm_display(scm_makfrom0str(" L:"), cur_out);
scm_display(scm_port_line(load_port), cur_out );
scm_display(scm_makfrom0str("]"), cur_out);
@} else @{
scm_display(scm_makfrom0str("Probably parenthesis mismatch"),
cur_out);
@}
scm_display(scm_makfrom0str(" in "), cur_out);
scm_display(filename, cur_out);
scm_newline(cur_out);
if (most_recently_read_form != SCM_BOOL_F) @{
scm_display(scm_makfrom0str ("Most recently read form: "),
cur_out);
scm_display(most_recently_read_form, cur_out);
scm_newline(cur_out);
@}
return SCM_BOOL_F;
@}
@display
@r{Defines :
@t{load_error_handler},
-- @ref{g_basic.c - g_read_file()}.
}
@end display
@display
@r{Uses :
@t{most_recently_read_form}, -- @ref{g_basic.c - load()}.
}
@end display
}
@end format
@section Function @code{g_read_file()}
@defun g_read_file filename
@end defun
@format
@anchor{g_basic.c - g_read_file()}
@i{<<g_basic.c : g_read_file()>>=}@t{
int
g_read_file(const gchar *filename)
@{
SCM port;
SCM eval_result = SCM_BOOL_F;
if (filename == NULL) @{
return(-1);
@}
if (access(filename, R_OK) != 0) @{
s_log_message("Could not find [%s] for interpretion\n",
filename);
return(-1);
@}
port = scm_open_file(scm_makfrom0str(filename), scm_makfrom0str("r"));
eval_result = scm_internal_catch (SCM_BOOL_T,
(scm_t_catch_body)load,
(void*)port,
(scm_t_catch_handler)load_error_handler,
(void*)port);
scm_close_port(port);
return (eval_result == SCM_BOOL_T);
@}
@display
@r{Defines :
.
}
@end display
@display
@r{Uses :
@t{load}, -- @ref{g_basic.c - load()}.
@t{load_error_handler}, -- @ref{g_basic.c - load_error_handler()}.
}
@end display
}
@end format
|