Skip to content
Snippets Groups Projects
Commit 4e894f36 authored by Jonathan Schöbel's avatar Jonathan Schöbel
Browse files

File: read name

parent 1ed8c176
No related branches found
No related tags found
No related merge requests found
......@@ -41,7 +41,7 @@ FILE_NAME_8=4638;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fpr
FILE_NAME_9=881;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Flog.h;0;8
FILE_NAME_10=17855;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Fgrammar.c;0;8
FILE_NAME_11=6839;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Fgrammar.h;0;8
FILE_NAME_12=5937;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Ffile.c;0;8
FILE_NAME_12=7572;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Ffile.c;0;8
FILE_NAME_13=1457;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Ffile.h;0;8
FILE_NAME_14=1282;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Fword.c;0;8
FILE_NAME_15=908;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Fword.h;0;8
......
......@@ -38,6 +38,12 @@ struct GR_File
};
#define BUFFER_SIZE 32
#define SOH 1
#define STX 2
/*@null@*/
/*@only@*/
struct GR_File *
......@@ -207,6 +213,11 @@ bool
File_read_fileversion (struct GR_File * file,
/*@null@*/ /*@out@*/ struct GR_Status * status);
static inline
bool
File_read_name (struct GR_File * file,
/*@null@*/ /*@out@*/ struct GR_Status * status);
static inline
bool
File_read (struct GR_File * file,
......@@ -214,9 +225,10 @@ File_read (struct GR_File * file,
{
if (!File_read_open (file, status)) return FALSE;
if (TRUE
&& (!File_read_filetype (file, status))
&& (!File_read_fileversion (file, status)))
if (FALSE
|| (!File_read_filetype (file, status))
|| (!File_read_fileversion (file, status))
|| (!File_read_name (file, status)))
{
File_close (file, status);
return FALSE;
......@@ -311,3 +323,95 @@ File_read_fileversion (struct GR_File * file,
set_success (status);
return TRUE;
}
static inline
bool
File_read_name (struct GR_File * file,
/*@null@*/ /*@out@*/ struct GR_Status * status)
{
char * buffer;
size_t index;
size_t size;
int c;
if (NULL == file->file)
{
set_status (status, E_STATE, 2, "file not opened");
return FALSE;
}
/* skip to SOH */
do
{
c = getc (file->file);
}
while ((EOF != c) && (SOH != c));
if (EOF == c)
{
if (0 != feof (file->file))
{
set_status (status, E_EOF, 4, "getc failed");
}
else
{
set_status (status, E_IO, 8, "getc failed");
}
return FALSE;
}
buffer = malloc (BUFFER_SIZE);
if (NULL == buffer)
{
set_status (status, E_ALLOC, 3, "malloc failed");
return FALSE;
}
index = 0;
size = BUFFER_SIZE;
/* read to STX */
do
{
if (index == size)
{
char * new_buffer;
size += BUFFER_SIZE;
new_buffer = realloc (buffer, size);
if (NULL == new_buffer)
{
set_status (status, E_ALLOC, 3,
"malloc failed");
return FALSE;
}
buffer = new_buffer;
}
buffer[index] = c = getc (file->file);
index++;
}
while ((EOF != c) && (STX != c));
if (EOF == c)
{
if (0 != feof (file->file))
{
set_status (status, E_EOF, 4, "getc failed");
}
else
{
set_status (status, E_IO, 8, "getc failed");
}
return FALSE;
}
buffer[index] = '\0';
fprintf (stderr, "Name: %s\n", buffer);
free (buffer);
set_success (status);
return TRUE;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment