Skip to content
Open
Show file tree
Hide file tree
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
14 changes: 8 additions & 6 deletions FunctionBar.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ in the source distribution for its full text.
#include "XUtils.h"


#define FUNCTIONBAR_MAXEVENTS 11 /* sufficient for all cases, includes NULL */

static const char* const FunctionBar_FKeys[] = {"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", NULL};

static const char* const FunctionBar_FLabels[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", NULL};
Expand All @@ -31,28 +33,28 @@ static const int FunctionBar_EnterEscEvents[] = {13, 27};
static int currentLen = 0;

FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc) {
const char* functions[FUNCTIONBAR_MAXEVENTS + 1] = {enter, esc, NULL};
const char* functions[FUNCTIONBAR_MAXEVENTS] = {enter, esc, NULL};
return FunctionBar_new(functions, FunctionBar_EnterEscKeys, FunctionBar_EnterEscEvents);
}

FunctionBar* FunctionBar_new(const char* const* functions, const char* const* keys, const int* events) {
FunctionBar* this = xCalloc(1, sizeof(FunctionBar));
this->functions = xCalloc(FUNCTIONBAR_MAXEVENTS + 1, sizeof(char*));
this->functions = xCalloc(FUNCTIONBAR_MAXEVENTS, sizeof(char*));
if (!functions) {
functions = FunctionBar_FLabels;
}
for (size_t i = 0; i < FUNCTIONBAR_MAXEVENTS && functions[i]; i++) {
for (size_t i = 0; functions[i]; i++) {
this->functions[i] = xStrdup(functions[i]);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add an assert here: assert(i <= FUNCTIONBAR_MAXEVENTS);

if (keys && events) {
this->staticData = false;
this->keys.keys = xCalloc(FUNCTIONBAR_MAXEVENTS, sizeof(char*));
this->events = xCalloc(FUNCTIONBAR_MAXEVENTS, sizeof(int));
size_t i = 0;
while (i < FUNCTIONBAR_MAXEVENTS && functions[i]) {
while (functions[i]) {
this->keys.keys[i] = xStrdup(keys[i]);
this->events[i] = events[i];
i++;
i++;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This space-to-tab change is probably unintentional.

}
this->size = (uint32_t)i;
} else {
Expand All @@ -66,7 +68,7 @@ FunctionBar* FunctionBar_new(const char* const* functions, const char* const* ke
}

void FunctionBar_delete(FunctionBar* this) {
for (size_t i = 0; i < FUNCTIONBAR_MAXEVENTS && this->functions[i]; i++) {
for (size_t i = 0; this->functions[i]; i++) {
free(this->functions[i]);
}
free(this->functions);
Expand Down
2 changes: 0 additions & 2 deletions FunctionBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ typedef struct FunctionBar_ {
bool staticData;
} FunctionBar;

#define FUNCTIONBAR_MAXEVENTS 15

FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc);

FunctionBar* FunctionBar_new(const char* const* functions, const char* const* keys, const int* events);
Expand Down
Loading