Skip to content

Replaced chars with int8_ts and unsigned chars with uint8_t for clarity #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ void compute_crc_table(unsigned int* crc_table) {


unsigned int update_crc(unsigned int* crc_table, unsigned crc,
unsigned char *buf, int len) {
int8_t *buf, int len) {

char b;
unsigned c = crc ^ 0xffffffff;
Expand All @@ -347,7 +347,7 @@ unsigned int update_crc(unsigned int* crc_table, unsigned crc,
return c ^ 0xffffffff;
}

unsigned crc32(unsigned char *buf, int len) {
unsigned crc32(int8_t *buf, int len) {
static unsigned int crc_table[256];

compute_crc_table(crc_table);
Expand All @@ -357,7 +357,7 @@ unsigned crc32(unsigned char *buf, int len) {

// TODO

int compare_checksum(char* data, struct waveform_data_header* header) {
int compare_checksum(int8_t* data, struct waveform_data_header* header) {
unsigned int crc;
unsigned int crc_table[256];
compute_crc_table(crc_table);
Expand Down Expand Up @@ -478,16 +478,16 @@ uint32_t get_waveform_length(uint32_t* wav_addrs, uint32_t wav_addr) {
return 0;
}

uint16_t parse_waveform(char* data, uint32_t* wav_addrs, uint32_t wav_addr, FILE* outfile) {
uint32_t parse_waveform(int8_t* data, uint32_t* wav_addrs, uint32_t wav_addr, FILE* outfile) {
uint32_t i, j;
struct packed_state* s;
struct unpacked_state u;
uint16_t count;
int fc_active;
int zero_pad;
size_t written;
uint16_t state_count = 0;
char* waveform = data + wav_addr;
uint32_t state_count = 0;
int8_t* waveform = data + wav_addr;

// TODO
// We are cutting off the last two bytes
Expand Down Expand Up @@ -550,11 +550,11 @@ uint16_t parse_waveform(char* data, uint32_t* wav_addrs, uint32_t wav_addr, FILE
return state_count;
}

int parse_temp_ranges(struct waveform_data_header* header, char* data, char* tr_start, uint8_t tr_count, uint32_t* wav_addrs, int first_pass, FILE* outfile, int do_print) {
int parse_temp_ranges(struct waveform_data_header* header, int8_t* data, int8_t* tr_start, uint8_t tr_count, uint32_t* wav_addrs, int first_pass, FILE* outfile, int do_print) {
struct pointer* tr;
uint8_t checksum;
uint8_t i;
uint16_t state_count;
uint32_t state_count;
size_t written;
long ftable;
long fprev;
Expand Down Expand Up @@ -675,7 +675,7 @@ int parse_temp_ranges(struct waveform_data_header* header, char* data, char* tr_
}


int parse_modes(struct waveform_data_header* header, char* data, char* mode_start, uint8_t mode_count, uint8_t temp_range_count, uint32_t* wav_addrs, int first_pass, FILE* outfile, int do_print) {
int parse_modes(struct waveform_data_header* header, int8_t* data, int8_t* mode_start, uint8_t mode_count, uint8_t temp_range_count, uint32_t* wav_addrs, int first_pass, FILE* outfile, int do_print) {
struct pointer* mode;
uint8_t checksum;
uint8_t i;
Expand Down Expand Up @@ -745,7 +745,7 @@ int parse_modes(struct waveform_data_header* header, char* data, char* mode_star
return 0;
}

int check_xwia(char* xwia, int do_print) {
int check_xwia(int8_t* xwia, int do_print) {
uint8_t xwia_len;
uint8_t i;
uint8_t checksum;
Expand Down Expand Up @@ -786,7 +786,7 @@ int check_xwia(char* xwia, int do_print) {
return 0;
}

int parse_temp_range_table(char* table, uint8_t range_count, FILE* outfile, int do_print) {
int parse_temp_range_table(int8_t* table, uint8_t range_count, FILE* outfile, int do_print) {
uint8_t i;
uint8_t checksum;
struct temp_range range;
Expand Down Expand Up @@ -904,14 +904,14 @@ void usage(FILE* fd) {

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

char* data;
int8_t* data;
char* infile_path;
FILE* infile = NULL;
size_t len;
struct waveform_data_header* header; // points to `data` at beginning of header
struct stat st;
char* modes; // points to `data` where the modes table begins
char* temp_range_table; // points to `data` where the temp range table begins
int8_t* modes; // points to `data` where the modes table begins
int8_t* temp_range_table; // points to `data` where the temp range table begins
uint32_t xwia_len;
uint8_t mode_count;
uint8_t temp_range_count;
Expand Down Expand Up @@ -998,7 +998,7 @@ int main(int argc, char **argv) {
to_alloc = sizeof(struct waveform_data_header);
}

data = malloc(to_alloc);
data = (int8_t*) malloc(to_alloc);
if(!data) {
fprintf(stderr, "Failed to allocate %d bytes of memory: %s\n", (int) st.st_size, strerror(errno));
goto fail;
Expand Down