summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mixlib/mix_code_file.c74
1 files changed, 36 insertions, 38 deletions
diff --git a/mixlib/mix_code_file.c b/mixlib/mix_code_file.c
index 6c1a1bd..8a50a41 100644
--- a/mixlib/mix_code_file.c
+++ b/mixlib/mix_code_file.c
@@ -1,24 +1,24 @@
/* -*-c-*- -------------- mix_code_file.c :
* Implementation of the functions declared in mix_code_file.h
* ------------------------------------------------------------------
- * $Id: mix_code_file.c,v 1.3 2002/03/24 01:22:03 jao Exp $
+ * $Id: mix_code_file.c,v 1.4 2003/06/03 22:33:22 jao Exp $
* ------------------------------------------------------------------
- * Copyright (C) 2000, 2002 Free Software Foundation, Inc.
- *
+ * Copyright (C) 2000, 2002, 2003 Free Software Foundation, Inc.
+ *
* 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-1307, USA.
- *
+ *
*/
#include <string.h>
@@ -28,7 +28,7 @@
#include "mix_code_file.h"
/* mix_code_file_t type */
-static const gint32 SIGNATURE_ = 0xDEADBEEF; /* release files */
+static const gint32 SIGNATURE_ = 0xDEADBEEF; /* release files */
static const gint32 SIGNATURE_D_ = 0xBEEFDEAD; /* debug files */
#define IS_DEBUG_(file) ((file)->header.signature == SIGNATURE_D_)
@@ -45,7 +45,7 @@ struct mix_cfheader_t
size_t path_len;
};
-struct mix_code_file_t
+struct mix_code_file_t
{
mix_file_t *file; /* the underlying disk file */
mix_address_t address; /* current address while reading */
@@ -93,13 +93,14 @@ static mix_code_file_t *
mix_code_file_new_ (const gchar *name, mix_fmode_t mode)
{
mix_code_file_t *result = g_new (mix_code_file_t, 1);
- if ( result != NULL )
+ if ( result != NULL )
{
result->file = mix_file_new_with_def_ext (name, mode, DEFEXT_);
result->address = MIX_SHORT_ZERO;
+ result->source_path = NULL;
result->symbol_table = NULL;
}
- if ( result != NULL && result->file == NULL )
+ if ( result != NULL && result->file == NULL )
{
g_free (result);
result = NULL;
@@ -113,28 +114,22 @@ mix_code_file_new_read (const gchar *name)
mix_code_file_t *result = mix_code_file_new_ (name, mix_io_READ);
mix_cfheader_t *header;
FILE *file;
- gboolean check;
-
- if ( result == NULL )
+ gboolean check;
+
+ if ( result == NULL )
return NULL;
-
+
file = mix_file_to_FILE (result->file);
header = &(result->header);
- check = fread (header, sizeof (mix_cfheader_t), 1, file);
-
- if ( check )
- check = IS_RELEASE_ (result) || IS_DEBUG_ (result);
+ check = fread (header, sizeof (mix_cfheader_t), 1, file)
+ && (IS_RELEASE_ (result) || IS_DEBUG_ (result));
- /* disable check to avoid breaking old files: 0.x and 1.x use
- the same bytecode */
-#if 0
if ( check )
{
gint major, minor;
sscanf (VERSION, "%d.%d", &major, &minor);
check = header->mj_ver == major && header->mn_ver <= minor;
}
-#endif
if ( check )
{/* get source path */
@@ -142,35 +137,38 @@ mix_code_file_new_read (const gchar *name)
check = result->source_path != NULL
&& fgets (result->source_path, 1 + header->path_len, file) != NULL;
}
+
if ( check && IS_DEBUG_ (result) )
{/* read symbol table */
result->symbol_table = mix_symbol_table_new_from_file (file);
check = result->symbol_table != NULL;
}
- if ( !check )
+
+ if ( !check )
{
mix_code_file_delete (result);
return NULL;
}
+
return result;
}
mix_code_file_t *
-mix_code_file_new_write(const gchar *name, mix_address_t addr,
+mix_code_file_new_write(const gchar *name, mix_address_t addr,
const gchar *source_path, gboolean debug,
const mix_symbol_table_t *table)
{
mix_code_file_t *result;
FILE *file;
gboolean check;
-
+
result = mix_code_file_new_ (name, mix_io_WRITE);
- if ( result == NULL || ( file = mix_file_to_FILE (result->file) ) == NULL )
+ if ( result == NULL || ( file = mix_file_to_FILE (result->file) ) == NULL )
return NULL;
else if ( source_path != NULL )
{
result->source_path = g_strdup (source_path/*, MAX_PATH_LEN_*/);
- if ( result->source_path == NULL )
+ if ( result->source_path == NULL )
{
mix_code_file_delete (result);
return NULL;
@@ -178,7 +176,7 @@ mix_code_file_new_write(const gchar *name, mix_address_t addr,
}
else
result->source_path = NULL;
-
+
result->header.signature = debug? SIGNATURE_D_:SIGNATURE_;
sscanf (VERSION, "%d.%d", &result->header.mj_ver, &result->header.mn_ver);
result->header.start = (gint16) addr;
@@ -197,11 +195,11 @@ mix_code_file_new_write(const gchar *name, mix_address_t addr,
}
void
-mix_code_file_delete (mix_code_file_t *file)
+mix_code_file_delete (mix_code_file_t *file)
{
g_return_if_fail (file != NULL);
mix_file_delete (file->file);
- if ( file->source_path ) g_free (file->source_path);
+ if (file->source_path) g_free (file->source_path);
g_free (file);
}
@@ -259,12 +257,12 @@ mix_code_file_get_ins (mix_code_file_t *file, mix_ins_desc_t *desc)
mix_word_t next;
g_return_val_if_fail (file != NULL, FALSE);
g_return_val_if_fail (desc != NULL, FALSE);
- while (TRUE)
+ while (TRUE)
{
if ( ! mix_io_read_word_array (to_io_ (file), &next, 1) ) return FALSE;
if ( is_addr_ (next) )
file->address = extract_addr_ (next);
- else if ( is_ins_ (next) )
+ else if ( is_ins_ (next) )
{
desc->ins = extract_ins_ (next);
desc->address = (file->address)++;
@@ -278,7 +276,7 @@ mix_code_file_get_ins (mix_code_file_t *file, mix_ins_desc_t *desc)
else
desc->lineno = 0;
return TRUE;
- }
+ }
else
{
g_assert_not_reached ();
@@ -297,18 +295,18 @@ mix_code_file_write_ins (mix_code_file_t *file, const mix_ins_desc_t *desc)
}
gboolean
-mix_code_file_write_next_ins (mix_code_file_t *file, mix_word_t ins,
+mix_code_file_write_next_ins (mix_code_file_t *file, mix_word_t ins,
guint lineno)
{
g_return_val_if_fail (file != NULL, FALSE);
- if ( mix_io_write_word (to_io_ (file), tag_ins_ (ins))
+ if ( mix_io_write_word (to_io_ (file), tag_ins_ (ins))
&& ( IS_RELEASE_ (file)
- || mix_io_write_short (to_io_ (file), mix_short_new (lineno)) )
+ || mix_io_write_short (to_io_ (file), mix_short_new (lineno)) )
)
{
++(file->address);
return TRUE;
- }
+ }
else
return FALSE;
}
@@ -325,7 +323,7 @@ mix_code_file_set_address (mix_code_file_t *file, mix_address_t address)
}
return TRUE;
}
-
+
/* get details about the source file */
const gchar *
mix_code_file_get_source_path (const mix_code_file_t *file)