Add doxygen documentation
This commit is contained in:
98
bfckr.c
98
bfckr.c
@@ -30,13 +30,12 @@ typedef struct bf_code_s {
|
||||
} bf_code_t;
|
||||
|
||||
// Prototypes
|
||||
void bfuck_parser(bf_code_t *bf);
|
||||
void bfuck_debugger(bf_code_t *bf);
|
||||
void print_sourceviewer(bf_code_t *bf);
|
||||
void print_memoryviewer(bf_code_t *bf);
|
||||
void init_bf_object(bf_code_t *bf);
|
||||
bool is_brainfuck(char c);
|
||||
char *colorize(char c);
|
||||
static void bfuck_debugger(bf_code_t *bf);
|
||||
static void print_sourceviewer(bf_code_t *bf);
|
||||
static void print_memoryviewer(bf_code_t *bf);
|
||||
static void init_bf_object(bf_code_t *bf);
|
||||
static bool is_brainfuck(char c);
|
||||
static char *colorize(char c);
|
||||
int getopt(int argc, char * const argv[], const char *optstring);
|
||||
|
||||
// Globals
|
||||
@@ -56,8 +55,13 @@ char *colortheme[] = {
|
||||
"\e[1;31m#\e[0m", // red #
|
||||
};
|
||||
|
||||
// Colorize instructions
|
||||
char *colorize(char c)
|
||||
/**
|
||||
* @brief Colorize the ouput string using a colorscheme table
|
||||
* @type static
|
||||
* @param[in] Single character to be colorized
|
||||
* @return Colorized string
|
||||
**/
|
||||
static char *colorize(char c)
|
||||
{
|
||||
char *cs = 0; // colorstring
|
||||
|
||||
@@ -97,8 +101,13 @@ char *colorize(char c)
|
||||
return cs;
|
||||
}
|
||||
|
||||
/* initialize bf object */
|
||||
void init_bf_object(bf_code_t *bf)
|
||||
/**
|
||||
* @brief Initialize a brainfuck object by setting all values to zero
|
||||
* @type static
|
||||
* @param[in] Pointer to a bf_code_t type
|
||||
* @return void
|
||||
**/
|
||||
static void init_bf_object(bf_code_t *bf)
|
||||
{
|
||||
bf->mp = 0; // set data pointer to zero
|
||||
bf->ip = 0; // set instruction pointer to zero
|
||||
@@ -118,13 +127,24 @@ void init_bf_object(bf_code_t *bf)
|
||||
|
||||
}
|
||||
|
||||
bool is_brainfuck(char c)
|
||||
/**
|
||||
* @brief Tests if a single character contains a valid brainfuck instruction
|
||||
* @type static
|
||||
* @param[in] char c containing a brainfuck instruction to test
|
||||
* @return bool which is true if the instruction is in brainfuck set or false if not
|
||||
**/
|
||||
static bool is_brainfuck(char c)
|
||||
{
|
||||
return (c=='+') || (c=='-') || (c=='>') || (c=='<') || (c=='.') || (c==',') || (c=='[') || (c==']' || (c=='#'));
|
||||
}
|
||||
|
||||
/* Error handler */
|
||||
void die(const char *message)
|
||||
/**
|
||||
* @brief Error handler function wich shuts down the application and prints to stderr
|
||||
* @type static
|
||||
* @param[in] Message string
|
||||
* @return void
|
||||
**/
|
||||
static void die(const char *message)
|
||||
{
|
||||
if(errno) {
|
||||
perror(message);
|
||||
@@ -135,8 +155,13 @@ void die(const char *message)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* prints the current output buffered in global output_buffer */
|
||||
void print_output()
|
||||
/**
|
||||
* @brief Prints the current ouput buffered in global output_buffer
|
||||
* @type static
|
||||
* @param[in] void
|
||||
* @return void
|
||||
**/
|
||||
static void print_output()
|
||||
{
|
||||
printf("\nOutput viewer: \n");
|
||||
printf("------------------------------------------------------------\n"); // 61 dashes
|
||||
@@ -147,8 +172,13 @@ void print_output()
|
||||
printf("\n------------------------------------------------------------\n");
|
||||
}
|
||||
|
||||
/* Prints the bf source at the current location */
|
||||
void print_sourceviewer(bf_code_t *bf)
|
||||
/**
|
||||
* @brief Prints the bf source code at the current location
|
||||
* @type static
|
||||
* @param[in] Pointer to a bf_code_t type
|
||||
* @return void
|
||||
**/
|
||||
static void print_sourceviewer(bf_code_t *bf)
|
||||
{
|
||||
int ip = (int)bf->ip; // save instruction pointer
|
||||
|
||||
@@ -165,7 +195,12 @@ void print_sourceviewer(bf_code_t *bf)
|
||||
printf("------------------------------------------------------------\n");
|
||||
}
|
||||
|
||||
/* Prints memory information at the current memory location */
|
||||
/**
|
||||
* @brief Prints a memory dump at the current memory location
|
||||
* @type static
|
||||
* @param[in] Pointer to a bf_code_t type
|
||||
* @return void
|
||||
**/
|
||||
void print_memoryviewer(bf_code_t *bf)
|
||||
{
|
||||
int mp = (int)bf->mp; // save the current memory pointer
|
||||
@@ -198,8 +233,13 @@ void print_memoryviewer(bf_code_t *bf)
|
||||
printf("\n------------------------------------------------------------\n");
|
||||
}
|
||||
|
||||
/* Pauses the program flow and prints information */
|
||||
void bfuck_debugger(bf_code_t *bf) //char *bf_source_input, int instructionpointer)
|
||||
/**
|
||||
* @brief Pauses the program flow and prints information
|
||||
* @type static
|
||||
* @param[in] Pointer to a bf_code_t type
|
||||
* @return void
|
||||
**/
|
||||
static void bfuck_debugger(bf_code_t *bf)
|
||||
{
|
||||
clear(); // clear terminal
|
||||
|
||||
@@ -220,8 +260,13 @@ void bfuck_debugger(bf_code_t *bf) //char *bf_source_input, int instructionpoint
|
||||
}
|
||||
}
|
||||
|
||||
/* Parses and executes a brainfuck expression */
|
||||
void bfuck_execute(bf_code_t *bf)
|
||||
/**
|
||||
* @brief Parses and executes a brainfuck expression using a simple state machine
|
||||
* @type static
|
||||
* @param[in] Pointer to a bf_code_t type
|
||||
* @return void
|
||||
**/
|
||||
static void bfuck_execute(bf_code_t *bf)
|
||||
{
|
||||
int loop = 0;
|
||||
|
||||
@@ -315,6 +360,13 @@ void bfuck_execute(bf_code_t *bf)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Main function which handles the argument parsing
|
||||
* @type static
|
||||
* @param[in] int argc Argument counter
|
||||
* @param[in] char **argv Argument vector
|
||||
* @return int Exitcode Exitcode of the application
|
||||
**/
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// vars
|
||||
|
||||
Reference in New Issue
Block a user