Skip to content

Commit

Permalink
style: clang-format fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jeezab committed Sep 30, 2024
1 parent 4a5c52a commit 8c32767
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
13 changes: 7 additions & 6 deletions src/polish_calc/polish_calc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ int polish_calc(char const *const postfix, double *const result) {
Stack_double operandStack;
initStack_double(&operandStack);

char *const expr_copy = (char *)malloc((strlen(postfix) + 1) * sizeof(char));
char *const expr_copy =
(char *)malloc((strlen(postfix) + 1) * sizeof(char));
if (!expr_copy) {
fprintf(stderr, "Memory allocation failed! [polish_calc()]\n");
destroyStack_double(&operandStack);
return ERROR_MEMORY_ALLOC;
}
strcpy(expr_copy, postfix);
char *token = strtok(expr_copy, " ");
char const *token = strtok(expr_copy, " ");

while (token != NULL && error_code == ERROR_NONE) {
error_code = calc_process_token(&operandStack, token);
Expand All @@ -36,7 +37,7 @@ int polish_calc(char const *const postfix, double *const result) {
return error_code;
}

int calc_process_operand(Stack_double *operandStack, char *token) {
int calc_process_operand(Stack_double *operandStack, char const *const token) {
if (isDigit(token[0]) || (token[0] == '.' && isDigit(token[1]))) {
push_double(operandStack, atof(token));
return ERROR_NONE;
Expand All @@ -61,7 +62,7 @@ int calc_process_operator(Stack_double *operandStack, char operator) {
return error_code;
}

int calc_process_function(Stack_double *operandStack, char *token) {
int calc_process_function(Stack_double *operandStack, char const *const token) {
int func_code = get_function_code(token);

if (func_code != -1) {
Expand All @@ -82,7 +83,7 @@ int calc_process_function(Stack_double *operandStack, char *token) {
return ERROR_UNKNOWN_FUNCTION;
}

int calc_process_constant(Stack_double *operandStack, char *token) {
int calc_process_constant(Stack_double *operandStack, char const *const token) {
int const_code = get_constant_code(token);
if (const_code != -1) {
double const_value = get_constant_value(const_code);
Expand All @@ -92,7 +93,7 @@ int calc_process_constant(Stack_double *operandStack, char *token) {
return ERROR_UNKNOWN_FUNCTION;
}

int calc_process_token(Stack_double *operandStack, char *token) {
int calc_process_token(Stack_double *operandStack, char const *const token) {
if (isDigit(token[0]) || (token[0] == '.' && isDigit(token[1]))) {
return calc_process_operand(operandStack, token);
} else if (strcmp(token, "~") == 0) {
Expand Down
8 changes: 4 additions & 4 deletions src/polish_calc/polish_calc.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
#define ERROR_MEMORY_ALLOC -6

int polish_calc(char const *const postfix, double *const result);
int calc_process_operand(Stack_double *operandStack, char *token);
int calc_process_operand(Stack_double *operandStack, char const *const token);
int calc_process_operator(Stack_double *operandStack, char operator);
int calc_process_function(Stack_double *operandStack, char *token);
int calc_process_constant(Stack_double *operandStack, char *token);
int calc_process_token(Stack_double *operandStack, char *token);
int calc_process_function(Stack_double *operandStack, char const *const token);
int calc_process_constant(Stack_double *operandStack, char const *const token);
int calc_process_token(Stack_double *operandStack, char const *const token);

int apply_operator(int const op, double const operand1, double const operand2,
double *const result);
Expand Down

0 comments on commit 8c32767

Please sign in to comment.