Skip to content

Commit

Permalink
set no-operation = NULL, and set operations as static in operations.c
Browse files Browse the repository at this point in the history
  • Loading branch information
alt-romes committed Feb 4, 2021
1 parent 5adaf48 commit f55e12e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
2 changes: 0 additions & 2 deletions include/operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ typedef struct operation {
extern unsigned long long globalmask;
extern int globalmasksize;

extern operation operations[];

operation* getopcode(char c);

long long shr(long long, long long);
Expand Down
2 changes: 1 addition & 1 deletion src/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void draw(numberstack* numbers, operation* current_op) {
}

if(!operation_enabled) prio += 2;
else mvwprintw(displaywin, 2, 2, "Operation: %c\n", current_op->character ? current_op->character : ' ');
else mvwprintw(displaywin, 2, 2, "Operation: %c\n", current_op ? current_op->character : ' ');

if(!decimal_enabled) prio += 2;
else mvwprintw(displaywin, 4-prio, 2, "Decimal: %lld", n);
Expand Down
11 changes: 5 additions & 6 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ extern int history_enabled;
extern unsigned long long globalmask;
extern int globalmasksize;

extern operation operations[];




Expand Down Expand Up @@ -129,7 +127,7 @@ int main(int argc, char *argv[])
* the operation is executed, and the result of the calculation is pushed to the stack
*/
numbers = create_numberstack(4);
operation* current_op = &operations[0];
operation* current_op = NULL;

// Initalize history pointers with NULL (realloc will bahave like malloc)
history.records = NULL;
Expand Down Expand Up @@ -382,7 +380,8 @@ static void process_input(operation** current_op, char* in) {
if (strpbrk(in, VALID_NUMBER_INPUT) || in[0] == '\0') {

// If is the invalid operation (first in array of operations)
if (*current_op == operations || (in[0] == '\0' && (*current_op = operations)) ) {
// Or if is an empty string (and if it is, set the operation as NULL)
if (*current_op == NULL || (in[0] == '\0' && !(*current_op = NULL)) ) {

clear_numberstack(numbers);
clear_history();
Expand All @@ -408,7 +407,7 @@ static void process_input(operation** current_op, char* in) {

static void apply_operations(numberstack* numbers, operation** current_op) {

if (*current_op != operations) {
if (*current_op != NULL) {

unsigned char noperands = (*current_op)->noperands;

Expand All @@ -423,7 +422,7 @@ static void apply_operations(numberstack* numbers, operation** current_op) {

push_numberstack(numbers, result);

*current_op = &operations[0]; // Set to invalid operation
*current_op = NULL; // Set to invalid operation
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ static long long modulus(long long, long long);
static long long not(long long, long long);
static long long twos_complement(long long, long long);

operation operations[16] = {
{0, 0, NULL},
static operation operations[15] = {
{'+', 2, add},
{'-', 2, subtract},
{'*', 2, multiply},
Expand Down

0 comments on commit f55e12e

Please sign in to comment.