summaryrefslogtreecommitdiffhomepage
path: root/mixlib
diff options
context:
space:
mode:
authorjaortega <jaortega>2000-12-17 15:12:37 +0000
committerjaortega <jaortega>2000-12-17 15:12:37 +0000
commitb1a65af9a959b8d19046e8fe5990e0e3432104ac (patch)
tree8064f03c17271badbaac02f9f17c485f96e2e843 /mixlib
parent40e364e97b179df231b6abbc774326e10759b814 (diff)
downloadmdk-b1a65af9a959b8d19046e8fe5990e0e3432104ac.tar.gz
mdk-b1a65af9a959b8d19046e8fe5990e0e3432104ac.tar.bz2
bugs corrected
Diffstat (limited to 'mixlib')
-rw-r--r--mixlib/mix_code_file.c8
-rw-r--r--mixlib/mix_code_file.h4
-rw-r--r--mixlib/mix_src_file.c39
3 files changed, 28 insertions, 23 deletions
diff --git a/mixlib/mix_code_file.c b/mixlib/mix_code_file.c
index ba53a64..c290150 100644
--- a/mixlib/mix_code_file.c
+++ b/mixlib/mix_code_file.c
@@ -316,5 +316,11 @@ 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)
+{
+ g_return_val_if_fail (file != NULL, NULL);
+ return file->source_path;
+}
diff --git a/mixlib/mix_code_file.h b/mixlib/mix_code_file.h
index 34c0f21..525ebc3 100644
--- a/mixlib/mix_code_file.h
+++ b/mixlib/mix_code_file.h
@@ -97,6 +97,10 @@ mix_code_file_write_next_ins(mix_code_file_t *file, mix_word_t ins,
extern gboolean
mix_code_file_set_address(mix_code_file_t *file, mix_address_t address);
+/* get details about the source file */
+extern const gchar *
+mix_code_file_get_source_path (const mix_code_file_t *file);
+
#endif /* MIX_CODE_FILE_H */
diff --git a/mixlib/mix_src_file.c b/mixlib/mix_src_file.c
index b8c4356..0569aa6 100644
--- a/mixlib/mix_src_file.c
+++ b/mixlib/mix_src_file.c
@@ -1,7 +1,7 @@
/* -*-c-*- -------------- mix_src_file.c :
* Implementation of the functions declared in mix_src_file.h
* ------------------------------------------------------------------
- * Last change: Time-stamp: "00/12/16 16:41:46 jose"
+ * Last change: Time-stamp: "00/12/17 12:56:50 jose"
* ------------------------------------------------------------------
* Copyright (C) 2000 jose antonio ortega ruiz <jaortega@acm.org>
*
@@ -21,7 +21,8 @@
*
*/
-
+#include <stdio.h>
+#include <unistd.h>
#include "mix_src_file.h"
/* the MIXAL source file type */
@@ -44,26 +45,19 @@ mix_src_file_new_for_read (const gchar *path)
return NULL;
else
{
+ enum {BUFFER_SIZE = 256};
+ static gchar BUFFER[BUFFER_SIZE];
+
mix_src_file_t *result = g_new (mix_src_file_t, 1);
FILE *f = mix_file_to_FILE (file);
- result->lines = g_prt_array_new ();
- result->path = path;
+ result->lines = g_ptr_array_new ();
+ result->path = g_strdup (path);
result->lineno = 0;
- ssize_t s = 0;
- gchar *newline = NULL;
- size_t a = 0;
-
- while (s != -1)
+ while (fgets (BUFFER, BUFFER_SIZE, f) == BUFFER)
{
- s = getline (&newline, &a, f);
- if (s>0)
- {
- g_ptr_array_add (result->lines, (gpointer) newline);
- result->lineno++;
- }
- newline = NULL;
- a = 0;
+ g_ptr_array_add (result->lines, (gpointer) g_strdup (BUFFER));
+ result->lineno++;
}
mix_file_delete (file);
@@ -75,8 +69,9 @@ mix_src_file_new_for_read (const gchar *path)
void
mix_src_file_delete (mix_src_file_t *src)
{
- g_return_val_if_fail (src != NULL, NULL);
- g_ptr_array_free (src->lines);
+ g_return_if_fail (src != NULL);
+ g_ptr_array_free (src->lines, TRUE);
+ g_free (src->path);
g_free (src);
}
@@ -93,17 +88,17 @@ const gchar *
mix_src_file_get_line (const mix_src_file_t *src, guint lineno)
{
g_return_val_if_fail (src != NULL, NULL);
- if (lineno > src->lineo || lineno == 0)
+ if (lineno > src->lineno || lineno == 0)
return NULL;
else
- return (gchar *)g_prt_array_index (src->lines, lineno - 1);
+ return (gchar *)g_ptr_array_index (src->lines, lineno - 1);
}
/* get the total no. of lines in the file */
guint
mix_src_file_get_line_no (const mix_src_file_t *src)
{
- g_return_val_if_fail (src != NULL, NULL);
+ g_return_val_if_fail (src != NULL, 0);
return src->lineno;
}