Skip to content

Commit

Permalink
Mark several non-modified pointer variables const
Browse files Browse the repository at this point in the history
  • Loading branch information
cgzones authored and BenBE committed Jan 11, 2021
1 parent 1b2d48b commit d72b0a6
Show file tree
Hide file tree
Showing 33 changed files with 97 additions and 100 deletions.
29 changes: 13 additions & 16 deletions Action.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ in the source distribution for its full text.
Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) {
Panel* panel = st->panel;
Header* header = st->header;
Settings* settings = st->settings;

int y = panel->y;
ScreenManager* scr = ScreenManager_new(header, settings, st, false);
ScreenManager* scr = ScreenManager_new(header, st->settings, st, false);
scr->allowFocusChange = false;
ScreenManager_add(scr, list, x - 1);
ScreenManager_add(scr, panel, -1);
Expand All @@ -67,7 +66,7 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess)
Panel_resize(panel, COLS, LINES - y - 1);
if (panelFocus == list && ch == 13) {
if (followProcess) {
Process* selected = (Process*)Panel_getSelected(panel);
const Process* selected = (const Process*)Panel_getSelected(panel);
if (selected && selected->pid == pid)
return Panel_getSelected(list);

Expand Down Expand Up @@ -141,7 +140,7 @@ static bool expandCollapse(Panel* panel) {
}

static bool collapseIntoParent(Panel* panel) {
Process* p = (Process*) Panel_getSelected(panel);
const Process* p = (Process*) Panel_getSelected(panel);
if (!p)
return false;

Expand All @@ -168,7 +167,7 @@ static Htop_Reaction actionSetSortColumn(State* st) {
Htop_Reaction reaction = HTOP_OK;
Panel* sortPanel = Panel_new(0, 0, 0, 0, Class(ListItem), true, FunctionBar_newEnterEsc("Sort ", "Cancel "));
Panel_setHeader(sortPanel, "Sort by");
ProcessField* fields = st->settings->fields;
const ProcessField* fields = st->settings->fields;
for (int i = 0; fields[i]; i++) {
char* name = String_trim(Process_fields[fields[i]].name);
Panel_add(sortPanel, (Object*) ListItem_new(name, fields[i]));
Expand All @@ -177,7 +176,7 @@ static Htop_Reaction actionSetSortColumn(State* st) {

free(name);
}
ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15, false);
const ListItem* field = (const ListItem*) Action_pickFromVector(st, sortPanel, 15, false);
if (field) {
reaction |= Action_setSortKey(st->settings, field->key);
}
Expand Down Expand Up @@ -293,7 +292,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
#if (defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY))
Panel* panel = st->panel;

Process* p = (Process*) Panel_getSelected(panel);
const Process* p = (const Process*) Panel_getSelected(panel);
if (!p)
return HTOP_OK;

Expand All @@ -306,7 +305,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
width += 1; /* we add a gap between the panels */
Affinity_delete(affinity1);

void* set = Action_pickFromVector(st, affinityPanel, width, true);
const void* set = Action_pickFromVector(st, affinityPanel, width, true);
if (set) {
Affinity* affinity2 = AffinityPanel_getAffinity(affinityPanel, st->pl);
bool ok = MainPanel_foreachProcess((MainPanel*)panel, Affinity_set, (Arg) { .v = affinity2 }, NULL);
Expand All @@ -321,7 +320,7 @@ static Htop_Reaction actionSetAffinity(State* st) {

static Htop_Reaction actionKill(State* st) {
Panel* signalsPanel = SignalsPanel_new();
ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 15, true);
const ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 15, true);
if (sgn) {
if (sgn->key != 0) {
Panel_setHeader(st->panel, "Sending...");
Expand All @@ -342,7 +341,7 @@ static Htop_Reaction actionFilterByUser(State* st) {
Vector_insertionSort(usersPanel->items);
ListItem* allUsers = ListItem_new("All users", -1);
Panel_insert(usersPanel, 0, (Object*) allUsers);
ListItem* picked = (ListItem*) Action_pickFromVector(st, usersPanel, 20, false);
const ListItem* picked = (ListItem*) Action_pickFromVector(st, usersPanel, 20, false);
if (picked) {
if (picked == allUsers) {
st->pl->userId = (uid_t)-1;
Expand Down Expand Up @@ -370,7 +369,7 @@ static Htop_Reaction actionSetup(State* st) {
}

static Htop_Reaction actionLsof(State* st) {
Process* p = (Process*) Panel_getSelected(st->panel);
const Process* p = (Process*) Panel_getSelected(st->panel);
if (!p)
return HTOP_OK;

Expand All @@ -383,7 +382,7 @@ static Htop_Reaction actionLsof(State* st) {
}

static Htop_Reaction actionShowLocks(State* st) {
Process* p = (Process*) Panel_getSelected(st->panel);
const Process* p = (Process*) Panel_getSelected(st->panel);
if (!p) return HTOP_OK;
ProcessLocksScreen* pls = ProcessLocksScreen_new(p);
InfoScreen_run((InfoScreen*)pls);
Expand All @@ -394,7 +393,7 @@ static Htop_Reaction actionShowLocks(State* st) {
}

static Htop_Reaction actionStrace(State* st) {
Process* p = (Process*) Panel_getSelected(st->panel);
const Process* p = (Process*) Panel_getSelected(st->panel);
if (!p)
return HTOP_OK;

Expand Down Expand Up @@ -483,8 +482,6 @@ static inline void addattrstr( int attr, const char* str) {
}

static Htop_Reaction actionHelp(State* st) {
Settings* settings = st->settings;

clear();
attrset(CRT_colors[HELP_BOLD]);

Expand All @@ -501,7 +498,7 @@ static Htop_Reaction actionHelp(State* st) {
mvaddstr(line++, 0, "CPU usage bar: ");

addattrstr(CRT_colors[BAR_BORDER], "[");
if (settings->detailedCPUTime) {
if (st->settings->detailedCPUTime) {
addattrstr(CRT_colors[CPU_NICE_TEXT], "low"); addstr("/");
addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/");
addattrstr(CRT_colors[CPU_SYSTEM], "kernel"); addstr("/");
Expand Down
4 changes: 2 additions & 2 deletions Affinity.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void Affinity_add(Affinity* this, int id) {

#ifdef HAVE_LIBHWLOC

Affinity* Affinity_get(Process* proc, ProcessList* pl) {
Affinity* Affinity_get(const Process* proc, ProcessList* pl) {
hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
bool ok = (hwloc_get_proc_cpubind(pl->topology, proc->pid, cpuset, HTOP_HWLOC_CPUBIND_FLAG) == 0);
Affinity* affinity = NULL;
Expand Down Expand Up @@ -86,7 +86,7 @@ bool Affinity_set(Process* proc, Arg arg) {

#elif defined(HAVE_LINUX_AFFINITY)

Affinity* Affinity_get(Process* proc, ProcessList* pl) {
Affinity* Affinity_get(const Process* proc, ProcessList* pl) {
cpu_set_t cpuset;
bool ok = (sched_getaffinity(proc->pid, sizeof(cpu_set_t), &cpuset) == 0);
if (!ok)
Expand Down
2 changes: 1 addition & 1 deletion Affinity.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void Affinity_add(Affinity* this, int id);

#if defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY)

Affinity* Affinity_get(Process* proc, ProcessList* pl);
Affinity* Affinity_get(const Process* proc, ProcessList* pl);

bool Affinity_set(Process* proc, Arg arg);

Expand Down
6 changes: 3 additions & 3 deletions AffinityPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ static const char* const AffinityPanelFunctions[] = {
static const char* const AffinityPanelKeys[] = {"Enter", "Esc", "F1", "F2", "F3"};
static const int AffinityPanelEvents[] = {13, 27, KEY_F(1), KEY_F(2), KEY_F(3)};

Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity, int* width) {
Panel* AffinityPanel_new(ProcessList* pl, const Affinity* affinity, int* width) {
AffinityPanel* this = AllocThis(AffinityPanel);
Panel* super = (Panel*) this;
Panel_init(super, 1, 1, 1, 1, Class(MaskItem), false, FunctionBar_new(AffinityPanelFunctions, AffinityPanelKeys, AffinityPanelEvents));
Expand Down Expand Up @@ -418,7 +418,7 @@ Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity, int* width) {
}

Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl) {
AffinityPanel* this = (AffinityPanel*) super;
const AffinityPanel* this = (AffinityPanel*) super;
Affinity* affinity = Affinity_new(pl);

#ifdef HAVE_LIBHWLOC
Expand All @@ -428,7 +428,7 @@ Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl) {
hwloc_bitmap_foreach_end();
#else
for (int i = 0; i < this->pl->cpuCount; i++) {
MaskItem* item = (MaskItem*)Vector_get(this->cpuids, i);
const MaskItem* item = (const MaskItem*)Vector_get(this->cpuids, i);
if (item->value) {
Affinity_add(affinity, item->cpu);
}
Expand Down
2 changes: 1 addition & 1 deletion AffinityPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ in the source distribution for its full text.

extern const PanelClass AffinityPanel_class;

Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity, int* width);
Panel* AffinityPanel_new(ProcessList* pl, const Affinity* affinity, int* width);

Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl);

Expand Down
2 changes: 1 addition & 1 deletion AvailableMetersPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const PanelClass AvailableMetersPanel_class = {
.eventHandler = AvailableMetersPanel_eventHandler
};

AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl) {
AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, const ProcessList* pl) {
AvailableMetersPanel* this = AllocThis(AvailableMetersPanel);
Panel* super = (Panel*) this;
FunctionBar* fuBar = FunctionBar_newEnterEsc("Add ", "Done ");
Expand Down
2 changes: 1 addition & 1 deletion AvailableMetersPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ typedef struct AvailableMetersPanel_ {

extern const PanelClass AvailableMetersPanel_class;

AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl);
AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, const ProcessList* pl);

#endif
4 changes: 2 additions & 2 deletions CPUMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ static void CPUMeter_display(const Object* cast, RichString* out) {
#endif
}

static void AllCPUsMeter_getRange(Meter* this, int* start, int* count) {
CPUMeterData* data = this->meterData;
static void AllCPUsMeter_getRange(const Meter* this, int* start, int* count) {
const CPUMeterData* data = this->meterData;
int cpus = data->cpus;
switch(Meter_name(this)[0]) {
default:
Expand Down
2 changes: 1 addition & 1 deletion ClockMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static const int ClockMeter_attributes[] = {
static void ClockMeter_updateValues(Meter* this, char* buffer, size_t size) {
time_t t = time(NULL);
struct tm result;
struct tm* lt = localtime_r(&t, &result);
const struct tm* lt = localtime_r(&t, &result);
this->values[0] = lt->tm_hour * 60 + lt->tm_min;
strftime(buffer, size, "%H:%M:%S", lt);
}
Expand Down
2 changes: 1 addition & 1 deletion ColumnsPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ ColumnsPanel* ColumnsPanel_new(Settings* settings) {
this->moving = false;
Panel_setHeader(super, "Active Columns");

ProcessField* fields = this->settings->fields;
const ProcessField* fields = this->settings->fields;
for (; *fields; fields++) {
if (Process_fields[*fields].name) {
Panel_add(super, (Object*) ListItem_new(Process_fields[*fields].name, *fields));
Expand Down
2 changes: 1 addition & 1 deletion DateMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static const int DateMeter_attributes[] = {
static void DateMeter_updateValues(Meter* this, char* buffer, size_t size) {
time_t t = time(NULL);
struct tm result;
struct tm* lt = localtime_r(&t, &result);
const struct tm* lt = localtime_r(&t, &result);
this->values[0] = lt->tm_yday;
int year = lt->tm_year + 1900;
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
Expand Down
2 changes: 1 addition & 1 deletion DateTimeMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static const int DateTimeMeter_attributes[] = {
static void DateTimeMeter_updateValues(Meter* this, char* buffer, size_t size) {
time_t t = time(NULL);
struct tm result;
struct tm* lt = localtime_r(&t, &result);
const struct tm* lt = localtime_r(&t, &result);
int year = lt->tm_year + 1900;
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
this->total = 366;
Expand Down
2 changes: 1 addition & 1 deletion EnvScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static void EnvScreen_scan(InfoScreen* this) {
char* env = Platform_getProcessEnv(this->process->pid);
CRT_restorePrivileges();
if (env) {
for (char* p = env; *p; p = strrchr(p, 0) + 1)
for (const char* p = env; *p; p = strrchr(p, 0) + 1)
InfoScreen_addLine(this, p);
free(env);
}
Expand Down
22 changes: 11 additions & 11 deletions Header.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void Header_delete(Header* this) {

void Header_populateFromSettings(Header* this) {
Header_forEachColumn(this, col) {
MeterColumnSettings* colSettings = &this->settings->columns[col];
const MeterColumnSettings* colSettings = &this->settings->columns[col];
for (int i = 0; i < colSettings->len; i++) {
Header_addMeterByName(this, colSettings->names[i], col);
if (colSettings->modes[i] != 0) {
Expand All @@ -60,15 +60,15 @@ void Header_writeBackToSettings(const Header* this) {
String_freeArray(colSettings->names);
free(colSettings->modes);

Vector* vec = this->columns[col];
const Vector* vec = this->columns[col];
int len = Vector_size(vec);

colSettings->names = xCalloc(len + 1, sizeof(char*));
colSettings->modes = xCalloc(len, sizeof(int));
colSettings->len = len;

for (int i = 0; i < len; i++) {
Meter* meter = (Meter*) Vector_get(vec, i);
const Meter* meter = (Meter*) Vector_get(vec, i);
char* name;
if (meter->param) {
xAsprintf(&name, "%s(%d)", As_Meter(meter)->name, meter->param);
Expand All @@ -81,7 +81,7 @@ void Header_writeBackToSettings(const Header* this) {
}
}

MeterModeId Header_addMeterByName(Header* this, char* name, int column) {
MeterModeId Header_addMeterByName(Header* this, const char* name, int column) {
Vector* meters = this->columns[column];

char* paren = strchr(name, '(');
Expand Down Expand Up @@ -126,15 +126,15 @@ Meter* Header_addMeterByClass(Header* this, const MeterClass* type, int param, i
return meter;
}

int Header_size(Header* this, int column) {
Vector* meters = this->columns[column];
int Header_size(const Header* this, int column) {
const Vector* meters = this->columns[column];
return Vector_size(meters);
}

MeterModeId Header_readMeterMode(Header* this, int i, int column) {
Vector* meters = this->columns[column];
MeterModeId Header_readMeterMode(const Header* this, int i, int column) {
const Vector* meters = this->columns[column];

Meter* meter = (Meter*) Vector_get(meters, i);
const Meter* meter = (const Meter*) Vector_get(meters, i);
return meter->mode;
}

Expand Down Expand Up @@ -175,10 +175,10 @@ int Header_calculateHeight(Header* this) {
int maxHeight = pad;

Header_forEachColumn(this, col) {
Vector* meters = this->columns[col];
const Vector* meters = this->columns[col];
int height = pad;
for (int i = 0; i < Vector_size(meters); i++) {
Meter* meter = (Meter*) Vector_get(meters, i);
const Meter* meter = (const Meter*) Vector_get(meters, i);
height += meter->h;
}
maxHeight = MAXIMUM(maxHeight, height);
Expand Down
6 changes: 3 additions & 3 deletions Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ void Header_populateFromSettings(Header* this);

void Header_writeBackToSettings(const Header* this);

MeterModeId Header_addMeterByName(Header* this, char* name, int column);
MeterModeId Header_addMeterByName(Header* this, const char* name, int column);

void Header_setMode(Header* this, int i, MeterModeId mode, int column);

Meter* Header_addMeterByClass(Header* this, const MeterClass* type, int param, int column);

int Header_size(Header* this, int column);
int Header_size(const Header* this, int column);

MeterModeId Header_readMeterMode(Header* this, int i, int column);
MeterModeId Header_readMeterMode(const Header* this, int i, int column);

void Header_reinit(Header* this);

Expand Down
10 changes: 5 additions & 5 deletions IncSet.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ void IncSet_delete(IncSet* this) {
free(this);
}

static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) {
Object* selected = Panel_getSelected(panel);
static void updateWeakPanel(const IncSet* this, Panel* panel, Vector* lines) {
const Object* selected = Panel_getSelected(panel);
Panel_prune(panel);
if (this->filtering) {
int n = 0;
Expand All @@ -105,7 +105,7 @@ static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) {
}
}

static bool search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue) {
static bool search(const IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue) {
int size = Panel_size(panel);
for (int i = 0; i < size; i++) {
if (String_contains_i(getPanelValue(panel, i), mode->buffer)) {
Expand All @@ -117,7 +117,7 @@ static bool search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelVa
return false;
}

static bool IncMode_find(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue, int step) {
static bool IncMode_find(const IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue, int step) {
int size = Panel_size(panel);
int here = Panel_getSelectedIndex(panel);
int i = here;
Expand Down Expand Up @@ -208,7 +208,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
}

const char* IncSet_getListItemValue(Panel* panel, int i) {
ListItem* l = (ListItem*) Panel_get(panel, i);
const ListItem* l = (const ListItem*) Panel_get(panel, i);
return l ? l->value : "";
}

Expand Down
Loading

0 comments on commit d72b0a6

Please sign in to comment.