Buddy Allocator  0.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Data Structures | Typedefs | Enumerations | Functions | Variables
simulator.c File Reference
#include <assert.h>
#include <errno.h>
#include <getopt.h>
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include "buddy.h"

Go to the source code of this file.

Data Structures

struct  var_t
 

Typedefs

typedef enum status_t status_t
 
typedef enum severity_t severity_t
 
typedef struct var_t var_t
 

Enumerations

enum  status_t { SUCCESS = 0, OUTOFMEMORY, DOUBLEFREE, BADINPUT }
 
enum  severity_t { ERROR, WARNING }
 

Functions

static var_tget_var (char var)
 
static void print_fault (const char *cmd, const char *msg, severity_t sev)
 
static status_t parse_error (const char *cmd)
 
static status_t parse_alloc (char *cmd)
 
static status_t parse_free (char *cmd)
 
static status_t parse_command (char *cmd, int cmd_len)
 
static status_t parse_file ()
 
void print_usage (char *prog_name, FILE *out)
 
int main (int argc, char **argv)
 

Variables

static FILE * in = NULL
 
static var_t var_map [256]
 
static int linenum = 0
 

Typedef Documentation

typedef enum severity_t severity_t

Severity of faults

typedef enum status_t status_t

Various program statuses indicating success or failure of an operation

typedef struct var_t var_t

Tracks a variable's pointer in memory and whether it is allocated or not

Enumeration Type Documentation

enum severity_t

Severity of faults

Enumerator
ERROR 
WARNING 

Definition at line 25 of file simulator.c.

enum status_t

Various program statuses indicating success or failure of an operation

Enumerator
SUCCESS 
OUTOFMEMORY 
DOUBLEFREE 
BADINPUT 

Definition at line 15 of file simulator.c.

Function Documentation

static var_t* get_var ( char  var)
static

Resolve a variable by name

Parameters
varName of variable
Returns
Returns a pointer to location of the variable's representation. Returns NULL if the var is not an alphabetic character.

Definition at line 52 of file simulator.c.

int main ( int  argc,
char **  argv 
)

Definition at line 277 of file simulator.c.

static status_t parse_alloc ( char *  cmd)
static

Parses an allocation instruction

Parameters
cmdString representing an allocation command in the program
Returns
Status of read and execute

Definition at line 104 of file simulator.c.

static status_t parse_command ( char *  cmd,
int  cmd_len 
)
static

Simplify the command and call one of the sub parser functions

Parameters
cmdRaw command string. This parameter is mutated. This parameter cannot be NULL.
cmd_lenLength in bytes of the command string.
Returns
Program status.

Definition at line 199 of file simulator.c.

static status_t parse_error ( const char *  cmd)
static

Throw a parsing error

Parameters
cmdA string representing the faulting command
Returns
Returns BADINPUT status

Definition at line 92 of file simulator.c.

static status_t parse_file ( )
static

Feed each line of a file into the function parse_command

Returns
Program status.

Definition at line 246 of file simulator.c.

static status_t parse_free ( char *  cmd)
static

Parses a free instruction

Parameters
cmdString representing an allocation command in the program
Returns
Status of read and execute

Definition at line 160 of file simulator.c.

static void print_fault ( const char *  cmd,
const char *  msg,
severity_t  sev 
)
static

Multi-purpose fault error message

Parameters
cmdA string representing a command
msgA string that describes the nature of the fault
sevSpecify the severity of the fault

Definition at line 67 of file simulator.c.

void print_usage ( char *  prog_name,
FILE *  out 
)

Output program manual

Parameters
prog_nameName of the program passed in as a command line argument.
outFile stream to write to.

Definition at line 269 of file simulator.c.

Variable Documentation

FILE* in = NULL
static

Definition at line 40 of file simulator.c.

int linenum = 0
static

Definition at line 42 of file simulator.c.

var_t var_map[256]
static

Definition at line 41 of file simulator.c.