Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GSAT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
josc941e
GSAT
Commits
4e894f36
Commit
4e894f36
authored
1 year ago
by
Jonathan Schöbel
Browse files
Options
Downloads
Patches
Plain Diff
File: read name
parent
1ed8c176
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gsat.geany
+1
-1
1 addition, 1 deletion
gsat.geany
src/lib/file.c
+107
-3
107 additions, 3 deletions
src/lib/file.c
with
108 additions
and
4 deletions
gsat.geany
+
1
−
1
View file @
4e894f36
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
src/lib/file.c
+
107
−
3
View file @
4e894f36
...
...
@@ -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
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment