Google style changes + write errors to stderr

This commit is contained in:
Miguel M 2023-04-23 19:36:36 +01:00
parent 168a8cf88c
commit 77d61f36e4
3 changed files with 15 additions and 12 deletions

View File

@ -1,5 +1,5 @@
#ifndef __H_MATRIX
#define __H_MATRIX
#ifndef ACED__MATRIX_H_
#define ACED__MATRIX_H_
#include <stddef.h>
#include <inttypes.h>
@ -33,7 +33,7 @@ typedef struct
} matrix_bufs_t;
// Prints a debug view of a `matrix_t` to standard output.
void debug_print_grid(matrix_t *grid);
void DebugPrintGrid(matrix_t *grid);
// Parse a matrix from the standard input.
//
@ -41,6 +41,6 @@ void debug_print_grid(matrix_t *grid);
// l is an m-sized column vector. This input is given in standard input as
//
// <row length> <whitespace separated entries>
matrix_t parse_matrix(void);
matrix_t ParseMatrix(void);
#endif // __H_MATRIX
#endif // ACED__MATRIX_H_

View File

@ -6,7 +6,7 @@
int main(int argc, char *argv[])
{
matrix_t grid = parse_matrix();
debug_print_grid(&grid);
matrix_t grid = ParseMatrix();
DebugPrintGrid(&grid);
return 0;
}

View File

@ -4,7 +4,7 @@
#include <ctype.h>
// Prints a debug view of a `matrix_t` to standard output.
void debug_print_grid(matrix_t *matrix)
void DebugPrintGrid(matrix_t *matrix)
{
printf("Grid ( row_len: %zu, data_head: %p, entries_head: %p, data_len: %zu, entries_len: %zu ) { ",
(matrix->row_len), (void *)(matrix->data_head), (void *)(matrix->entries_head),
@ -84,7 +84,8 @@ matrix_bufs_t compact_buffers(matrix_t *matrix) {
matrix->entries_head = realloc(matrix->entries_head, matrix->entries_len * sizeof(grid_data_t *));
if ((matrix->data_head == NULL) || (matrix->entries_head == NULL))
{
printf(
fprintf(
stderr,
"Failed to reallocate matrix data buffers. Was trying to "
"allocate for %zu data entries, aborting.",
matrix->data_len);
@ -103,7 +104,7 @@ matrix_bufs_t compact_buffers(matrix_t *matrix) {
// what we have is contiguous blocks of strings, structured as
//
// <string length> <characters...>
matrix_t parse_matrix(void)
matrix_t ParseMatrix(void)
{
size_t row_len;
scanf("%zu", &row_len);
@ -127,7 +128,8 @@ matrix_t parse_matrix(void)
// A little input sanitization.
if (!(isdigit(scanned) || (scanned == '-') || (scanned == '.')))
{
printf(
fprintf(
stderr,
"Foreign character %c (%x) found when processing input, aborting.",
scanned, scanned);
exit(EXIT_FAILURE);
@ -172,7 +174,8 @@ matrix_t parse_matrix(void)
// of the number of entries in a row.
if (!((entries_len % row_len) == 0))
{
printf("Number of entries is not consistent with provided row length. "
fprintf(stderr,
"Number of entries is not consistent with provided row length. "
"Got row length of %zu, and read %zu entries. Aborting.",
row_len, entries_len);
// No need to free the buffers.