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
|
@c -*- mode: Noweb; noweb-doc-mode: texinfo-mode; noweb-code-mode: c-mode -*-
@node File f_basic.c,,,Top
@chapter File @file{f_basic.c}
@section File header
<<f_basic.c : *>>=
<<f_basic.c : copyright and license>>
/* DO NOT read or edit this file ! Use ../noweb/f_basic.nw instead */
<<f_basic.c : include directives>>
<<f_basic.c : f_open()>>
<<f_basic.c : f_close()>>
<<f_basic.c : f_save_close()>>
<<f_basic.c : f_save()>>
<<f_basic.c : f_normalize_filename()>>
@
<<f_basic.c : copyright and license>>=
/* 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
*/
@
<<f_basic.c : include directives>>=
#include <config.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <sys/param.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <libguile.h>
#include "defines.h"
#include "struct.h"
#include "globals.h"
#include "../include/prototype.h"
#ifdef HAVE_LIBDMALLOC
#include <dmalloc.h>
#endif
@
/* -------------------------------------------------- */
@section Function @code{f_open()}
@defun f_open w_current filename
Opens the schematic file.
It returns 0 on failure and 1 on success.
Before it reads the schematic, it tries to open and read the local gafrc file.
@end defun
<<f_basic.c : f_open()>>=
int
f_open(TOPLEVEL *w_current, char *filename)
{
int opened=FALSE;
char *full_filename = NULL;
char *full_rcfilename = NULL;
char *file_directory = NULL;
char *saved_cwd = NULL;
/* has the head been freed yet? */
/* probably not hack PAGE */
set_window(w_current, w_current->page_current,
w_current->init_left, w_current->init_right,
w_current->init_top, w_current->init_bottom);
/*
* If we are only opening a preview window, we don't want to
* change the directory. Therefore, if this is only a preview window,
* we cache the cwd so we can restore it later.
*/
if (w_current->wid == -1) {
saved_cwd = getcwd(NULL, 1024);
}
/* get full, absolute path to file */
full_filename = f_normalize_filename(filename);
/* write full, absolute filename into page_current->page_filename */
if (w_current->page_current->page_filename) {
free(w_current->page_current->page_filename);
}
w_current->page_current->page_filename = g_strdup(full_filename);
/* Before we open the page, let's load the corresponding gafrc. */
/* First cd into file's directory. */
file_directory = g_dirname (full_filename);
full_rcfilename = g_strconcat (file_directory,
G_DIR_SEPARATOR_S,
"gafrc",
NULL);
if (file_directory) {
chdir(file_directory);
/* Probably should do some checking of chdir return values */
free (file_directory);
}
/* If directory is not found, we should do something . . . . */
/* Now open RC and process file */
g_rc_parse_specified_rc(w_current, full_rcfilename);
/* Now that we have set the current directory and read
* the RC file, it's time to read in the file. */
w_current->page_current->object_tail = (OBJECT *)
o_read(w_current, w_current->page_current->object_tail,
full_filename);
if (w_current->page_current->object_tail != NULL) {
s_log_message("Opened file [%s]\n", full_filename);
opened = TRUE;
} else {
/* Failed to open page */
opened = FALSE;
}
w_current->page_current->object_tail = (OBJECT *)
return_tail(w_current->page_current->object_head);
/* make sure you init net_consolide to false (default) in all */
/* programs */
if (w_current->net_consolidate == TRUE) {
o_net_consolidate(w_current);
}
w_current->page_current->CHANGED=0; /* added 4/7/98 */
free(full_filename);
free(full_rcfilename);
/* If this was a preview window, reset the directory to the
* value it had when f_open was called. Also get rid of component
* libraries opened while opening preview window. If the component
* is actually selected, they will be re-read later. */
if (w_current->wid == -1) {
chdir(saved_cwd);
free(saved_cwd);
}
if (!opened) {
return (FALSE);
} else {
return (TRUE);
}
}
@ %def f_open
/* -------------------------------------------------- */
@section Function @code{f_close()}
@defun f_close w_current
@end defun
<<f_basic.c : f_close()>>=
void
f_close(TOPLEVEL *w_current)
{
}
@ %def f_close
/* -------------------------------------------------- */
@section Function @code{f_save_close()}
@defun f_save_close w_current filename
@end defun
<<f_basic.c : f_save_close()>>=
void
f_save_close(TOPLEVEL *w_current, char *filename)
{
o_save(w_current, filename);
s_page_delete (w_current, w_current->page_current);
}
@ %def f_save_close
/* -------------------------------------------------- */
@section Function @code{f_save()}
@defun f_save w_current filename
@end defun
<<f_basic.c : f_save()>>=
int
f_save(TOPLEVEL *w_current, const char *filename)
{
return o_save(w_current, filename);
}
@ %def f_save
/* -------------------------------------------------- */
@section Function @code{f_normalize_filename()}
@defun f_normalize_filename filename
Given a filename in any format, this returns the full, absolute resolved filename.
@end defun
<<f_basic.c : f_normalize_filename()>>=
char* f_normalize_filename(const gchar *filename)
{
char filename_buffer[MAXPATHLEN]; /* nasty hack for realpath */
char *full_filename;
/* Check for pathological case */
if (filename == NULL) {
return NULL;
}
realpath(filename, filename_buffer); /* places reult in filename_buffer */
full_filename = g_strdup (filename_buffer);
#ifdef DEBUG
printf("In f_normalize_filename, returning full_filename= %s \n", full_filename);
#endif
return full_filename;
}
@ %def f_normalize_filename
|