-
Notifications
You must be signed in to change notification settings - Fork 0
/
sim04.c
83 lines (73 loc) · 2.04 KB
/
sim04.c
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* Required Header Stuff
1) Creating my own waiting loop that does not depend on Dr. Leverington's allows
Multithreading
2) Memory management Is included
*/
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include "helper_lib.h"
#include "linked_list.h"
#include "input_data_management.h"
#include "simtimer.h"
#include "simulator.h"
ReturnMessage errorHandling( ReturnMessage );
int main( int argc, char* argv[] )
{
ReturnMessage returnMessage;
char *fileHandle = argv[1];
char *metaHandle;
ConfigStruct *conStruct = createConfigStruct();
List *metaList = list_create();
// Check if all input parameters present
if ( argc != 2 )
{
printf("Missing file(s)\n");
return 1;
}
// Open and parse the config file
// Store into config structure
// Check if errors occured
returnMessage = openConfig( fileHandle, conStruct );
returnMessage = errorHandling( returnMessage );
if ( returnMessage == FAIL )
{
return 1;
}
// Open and parse the meta data file
// Store into linked list with nodes conatining meta data stuctures
metaHandle = conStruct->fileName;
returnMessage = openMetaData( metaHandle, metaList );
returnMessage = errorHandling( returnMessage );
if ( returnMessage == FAIL )
{
return 1;
}
// Run the simulator
startSimulator( conStruct, metaList );
destroyMetaDataList( metaList );
list_destroy( metaList );
destroyConfigStruct( conStruct );
return 0;
}
// Return error message depending on error
ReturnMessage errorHandling( ReturnMessage message )
{
if ( message == FAIL )
{
printf( "An unknown error occured\n" );
}
else if ( message == FILE_ERROR )
{
printf( "There was an error in the config or meta_data file(s)\n" );
}
else if ( message == NO_FILE_FOUND )
{
printf( "File Not Found\n" );
}
else
{
return PASS;
}
return FAIL;
}