52 lines
1.6 KiB
C
52 lines
1.6 KiB
C
#ifndef COMMAND_H
|
|
#define COMMAND_H
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#define COMMAND_ARGUMENTS 5u
|
|
#define INPUT_CAPACITY 256u
|
|
typedef struct {
|
|
char code;
|
|
unsigned count;
|
|
uint32_t argument[COMMAND_ARGUMENTS];
|
|
unsigned line;
|
|
} command_t;
|
|
typedef struct {
|
|
FILE *stream;
|
|
unsigned line;
|
|
unsigned commands;
|
|
unsigned rejected;
|
|
unsigned exhausted;
|
|
} input_t;
|
|
typedef struct {
|
|
int status;
|
|
unsigned value;
|
|
unsigned detail;
|
|
} result_t;
|
|
typedef struct {
|
|
FILE *stream;
|
|
unsigned operation;
|
|
unsigned fields;
|
|
unsigned failures;
|
|
unsigned used;
|
|
char buffer[512];
|
|
} observation_t;
|
|
void input_init(input_t *input, FILE *stream);
|
|
int input_next(input_t *input, command_t *command);
|
|
int command_arity(char code);
|
|
int parse_uint32(const char *start, const char **end, uint32_t *value);
|
|
unsigned byte_pattern(unsigned seed, unsigned index);
|
|
unsigned checksum_bytes(const unsigned char *data, unsigned length);
|
|
int range_valid(unsigned offset, unsigned length, unsigned capacity);
|
|
void observation_init(observation_t *observation, FILE *stream);
|
|
void observation_begin(observation_t *observation, unsigned operation,
|
|
const result_t *result);
|
|
void observation_unsigned(observation_t *observation, unsigned value);
|
|
void observation_bytes(observation_t *observation, const unsigned char *bytes,
|
|
unsigned length);
|
|
void observation_array(observation_t *observation, const unsigned *values,
|
|
unsigned length);
|
|
void observation_end(observation_t *observation);
|
|
int observation_status(const observation_t *observation);
|
|
#endif
|