Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
clean-and-itasks
sapl-interpreter
Commits
46f20bde
Commit
46f20bde
authored
Aug 26, 2015
by
Laszlo Domoszlai
Browse files
get rid of creepy getline
parent
afb6dc66
Changes
4
Hide whitespace changes
Inline
Side-by-side
interpreter/Makefile
View file @
46f20bde
TARGET
=
main
LIBS
=
CC
=
clan
g++
CFLAGS
=
-g
-Wno-write-strings
CC
=
g++
CFLAGS
=
-g
-Wno-write-strings
.PHONY
:
default all clean
...
...
@@ -17,7 +17,7 @@ HEADERS = $(wildcard *.h)
.PRECIOUS
:
$(TARGET) $(OBJECTS)
$(TARGET)
:
$(OBJECTS)
$(CC)
$(OBJECTS)
-g
-Wall
$(LIBS)
-o
$@
$(CC)
$(OBJECTS)
-static
-static-libgcc
-static-libstdc
++
-g
-Wall
$(LIBS)
-o
$@
clean
:
-
rm
-f
*
.o
...
...
interpreter/getline.c
deleted
100644 → 0
View file @
afb6dc66
/* This code is public domain -- Will Hartung 4/9/09 */
#include
<stdio.h>
#include
<stdlib.h>
size_t
getline
(
char
**
lineptr
,
size_t
*
n
,
FILE
*
stream
)
{
char
*
bufptr
=
NULL
;
char
*
p
=
bufptr
;
size_t
size
;
int
c
;
if
(
lineptr
==
NULL
)
{
return
-
1
;
}
if
(
stream
==
NULL
)
{
return
-
1
;
}
if
(
n
==
NULL
)
{
return
-
1
;
}
bufptr
=
*
lineptr
;
size
=
*
n
;
c
=
fgetc
(
stream
);
if
(
c
==
EOF
)
{
return
-
1
;
}
if
(
bufptr
==
NULL
)
{
bufptr
=
(
char
*
)
malloc
(
128
);
if
(
bufptr
==
NULL
)
{
return
-
1
;
}
size
=
128
;
}
p
=
bufptr
;
while
(
c
!=
EOF
)
{
if
((
p
-
bufptr
)
>
(
size
-
1
))
{
size
=
size
+
128
;
bufptr
=
(
char
*
)
realloc
(
bufptr
,
size
);
if
(
bufptr
==
NULL
)
{
return
-
1
;
}
}
*
p
++
=
c
;
if
(
c
==
'\n'
)
{
break
;
}
c
=
fgetc
(
stream
);
}
*
p
++
=
'\0'
;
*
lineptr
=
bufptr
;
*
n
=
size
;
return
p
-
bufptr
-
1
;
}
\ No newline at end of file
interpreter/getline.h
deleted
100644 → 0
View file @
afb6dc66
#ifndef GETLINE_H
#define GETLINE_H
size_t
getline
(
char
**
lineptr
,
size_t
*
n
,
FILE
*
stream
);
#endif
/* GETLINE_H */
interpreter/main.c
View file @
46f20bde
...
...
@@ -4,8 +4,6 @@
#include
<string.h>
#include
<sys/time.h>
#include
"getline.h"
#include
"debug.h"
#include
"desc.h"
#include
"prim.h"
...
...
@@ -13,6 +11,18 @@
#include
"code.h"
#include
"mem.h"
long
readfile
(
char
**
string
,
FILE
*
f
)
{
fseek
(
f
,
0
,
SEEK_END
);
long
fsize
=
ftell
(
f
);
fseek
(
f
,
0
,
SEEK_SET
);
*
string
=
(
char
*
)
malloc
(
fsize
);
fread
(
*
string
,
fsize
,
1
,
f
);
fclose
(
f
);
return
fsize
;
}
int
main
(
int
argc
,
char
*
argv
[]
)
{
init_mem
();
...
...
@@ -28,23 +38,24 @@ int main ( int argc, char *argv[] )
FILE
*
file
=
fopen
(
input
,
"r"
);
char
*
line
=
NULL
;
size_t
bufsize
=
0
;
size_t
len
=
0
;
long
len
=
0
;
if
(
file
==
0
)
{
printf
(
"Could not open file
\n
"
);
exit
(
-
1
);
}
else
{
len
=
getline
(
&
line
,
&
bufsize
,
file
);
if
(
len
==
-
1
)
{
len
=
readfile
(
&
line
,
file
);
if
(
len
<
0
)
{
printf
(
"No Input
\n
"
);
}
fclose
(
file
);
if
(
len
==
-
1
)
exit
(
-
1
);
if
(
len
<
0
)
exit
(
-
1
);
}
#ifdef DEBUG
...
...
@@ -58,6 +69,11 @@ int main ( int argc, char *argv[] )
printf
(
"Number of functions parsed: %d
\n
"
,
nrfuns
);
#endif
if
(
nrfuns
<=
0
)
{
exit
(
0
);
}
// TODO: put it into a special "expression" space, instead of "code"
char
*
exprstream
=
"VF4 main"
;
...
...
@@ -67,10 +83,10 @@ int main ( int argc, char *argv[] )
struct
timeval
t1
,
t2
;
gettimeofday
(
&
t1
,
NULL
);
#endif
exec
(
expr
,
stack_top_a
,
stack_top_a
,
NULL
,
true
);
exec
(
expr
,
stack_top_a
,
stack_top_a
,
NULL
,
true
);
Thunk
*
res
=
eval
(
pop_a
());
#ifdef DEBUG
gettimeofday
(
&
t2
,
NULL
);
#endif
...
...
@@ -85,4 +101,6 @@ int main ( int argc, char *argv[] )
printf
(
"
\n\n
execution time: %G ms
\n
"
,
elapsedTime
);
print_stat
();
#endif
exit
(
0
);
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment