Menu

[r5829]: / trunk / fuse-basic / basic.c  Maximize  Restore  History

Download this file

68 lines (49 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* main.c: placeholder */
#include "config.h"
#include <stdio.h>
#include <glib.h>
#include "basic.h"
#include "parse.h"
#include "program.h"
#include "utils.h"
const char *progname;
static int
interpret_program( struct program *program )
{
if( program_find_functions( program ) ) {
fprintf( stderr, "%s: error finding functions\n", progname );
return 1;
}
while( !program->error ) {
if( program_execute_statement( program ) ) {
program_free( program );
return 1;
}
}
printf( "%s\n", program_strerror( program->error ) );
return 0;
}
int
main( int argc, char **argv )
{
char *buffer; size_t length;
struct program *basic_program;
int error;
progname = argv[0];
if( argc < 2 ) {
fprintf( stderr, "%s: usage: %s <basic file>\n", progname, progname );
return 1;
}
error = utils_read_file( &buffer, &length, argv[1] );
if( error ) return error;
basic_program = parse_program( buffer, length );
if( !basic_program ) return 1;
free( buffer );
error = interpret_program( basic_program );
if( error ) { program_free( basic_program ); return error; }
if( program_free( basic_program ) ) {
fprintf( stderr, "%s: error freeing program\n", progname );
return 1;
}
return 0;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.