Stock Control System
Loading...
Searching...
No Matches
StockControlSystem.c File Reference

Stock Control System driver. More...

#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Pool.h"
#include "Product.h"
Include dependency graph for StockControlSystem.c:

Go to the source code of this file.

Enumerations

enum  MenuOption { MENU_INVALID , MENU_MANAGE_STOCK , MENU_GENERATE_REPORT , MENU_QUIT }
 Represents all menu options on the interactive menu. More...
 

Functions

static enum MenuOption get_menu_selection ()
 Presents the user with a menu and interactively retrieves the selection.
 
static size_t get_input_line (char *const buffer, const size_t buffer_size, FILE *const stream)
 Gets a single line of input from the given input and writes to the given buffer.
 
static unsigned int convert_to_uint (const char *const buffer, bool *error)
 Converts the string in the given buffer to an unsigned integer.
 
static int convert_to_sint (const char *const buffer, bool *error)
 Converts the string in the given buffer to a signed integer.
 
static void manage_stock (const struct Pool *const pool)
 Interactively queries the user for a Product ID and an amount by which to modify the stock level.
 
static void generate_reports (const struct Pool *const pool)
 Interactively query the user for an output file, and write a report to the chosen destination.
 
static bool load_inventory (FILE *const stock_file, struct Pool *const pool)
 Parse the inventory from the given stock file into the given Pool.
 
static FILE * open_stock_file (const char *const filename)
 Open the stock file with the given file name for reading, reporting errors as encountered.
 
static void save_inventory (FILE *const datafile, const struct Pool *const pool)
 Save the inventory in the stock file format to the given file buffer.
 
int main (const int argc, const char **const argv)
 The application entry point for interactive control of the Stock Control System.
 

Detailed Description

Stock Control System driver.

Author
Oliver Dixon
Date
2025-09-06
Version
Development

Definition in file StockControlSystem.c.

Enumeration Type Documentation

◆ MenuOption

enum MenuOption

Represents all menu options on the interactive menu.

See also
get_menu_selection for the usage
Enumerator
MENU_INVALID 

Placeholder invalid menu state.

MENU_MANAGE_STOCK 

Manage Stock option.

MENU_GENERATE_REPORT 

Generate Report option.

MENU_QUIT 

Quit the Program option.

Definition at line 29 of file StockControlSystem.c.

Function Documentation

◆ convert_to_sint()

static int convert_to_sint ( const char *const  buffer,
bool *  error 
)
static

Converts the string in the given buffer to a signed integer.

Parameters
bufferThe buffer containing the string representation of the signed integer.
errorOutput error flag, indicating an error occurred during numerical parsing.
Returns
The parsed signed integer.

Definition at line 138 of file StockControlSystem.c.

◆ convert_to_uint()

static unsigned int convert_to_uint ( const char *const  buffer,
bool *  error 
)
static

Converts the string in the given buffer to an unsigned integer.

Parameters
bufferThe buffer containing the string representation of the unsigned integer.
errorOutput error flag, indicating an error occurred during numerical parsing.
Returns
The parsed unsigned integer.

Definition at line 117 of file StockControlSystem.c.

◆ generate_reports()

static void generate_reports ( const struct Pool *const  pool)
static

Interactively query the user for an output file, and write a report to the chosen destination.

Parameters
poolThe Pool containing the Product items to be serialised in the report.

Definition at line 217 of file StockControlSystem.c.

◆ get_input_line()

static size_t get_input_line ( char *const  buffer,
const size_t  buffer_size,
FILE *const  stream 
)
static

Gets a single line of input from the given input and writes to the given buffer.

Parameters
bufferThe destination buffer.
buffer_sizeThe maximum size in bytes of the destination buffer.
streamThe input stream.
Returns
The number of bytes written to the destination buffer, excluding the NULL terminator.

Definition at line 84 of file StockControlSystem.c.

◆ get_menu_selection()

static enum MenuOption get_menu_selection ( )
static

Presents the user with a menu and interactively retrieves the selection.

Returns
The selected MenuOption.

Definition at line 41 of file StockControlSystem.c.

◆ load_inventory()

static bool load_inventory ( FILE *const  stock_file,
struct Pool *const  pool 
)
static

Parse the inventory from the given stock file into the given Pool.

Parameters
stock_fileThe stock file containing name-quantity pair Product records, delimited with newline characters.
poolThe Pool into which the Product entries should be emplaced.
Returns
Was the stock file successfully parsed until its end? On failure, the Pool may be partially populated.

Definition at line 241 of file StockControlSystem.c.

◆ main()

int main ( const int  argc,
const char **const  argv 
)

The application entry point for interactive control of the Stock Control System.

Parameters
argcThe number of command-line arguments provided by the shell.
argvThe command-line arguments provided by the shell.
Returns
EXIT_SUCCESS or EXIT_FAILURE according to program exit state.

Definition at line 322 of file StockControlSystem.c.

◆ manage_stock()

static void manage_stock ( const struct Pool *const  pool)
static

Interactively queries the user for a Product ID and an amount by which to modify the stock level.

Parameters
poolThe Pool containing the Product items which may be modified.

Definition at line 157 of file StockControlSystem.c.

◆ open_stock_file()

static FILE * open_stock_file ( const char *const  filename)
static

Open the stock file with the given file name for reading, reporting errors as encountered.

Parameters
filenameThe path on the filesystem, relative to the current working directory, of the stock file to open.
Returns
The file handle to the opened stock file.

Definition at line 282 of file StockControlSystem.c.

◆ save_inventory()

static void save_inventory ( FILE *const  datafile,
const struct Pool *const  pool 
)
static

Save the inventory in the stock file format to the given file buffer.

Parameters
datafileThe destination file for the inventory.
poolThe Pool containing the Product inventory items to be saved.

Definition at line 310 of file StockControlSystem.c.