mirror of https://github.com/xzeldon/htop.git
Mark several non-modified pointer variables const
This commit is contained in:
parent
1b2d48bc9a
commit
d72b0a682e
29
Action.c
29
Action.c
|
@ -43,10 +43,9 @@ in the source distribution for its full text.
|
||||||
Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) {
|
Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) {
|
||||||
Panel* panel = st->panel;
|
Panel* panel = st->panel;
|
||||||
Header* header = st->header;
|
Header* header = st->header;
|
||||||
Settings* settings = st->settings;
|
|
||||||
|
|
||||||
int y = panel->y;
|
int y = panel->y;
|
||||||
ScreenManager* scr = ScreenManager_new(header, settings, st, false);
|
ScreenManager* scr = ScreenManager_new(header, st->settings, st, false);
|
||||||
scr->allowFocusChange = false;
|
scr->allowFocusChange = false;
|
||||||
ScreenManager_add(scr, list, x - 1);
|
ScreenManager_add(scr, list, x - 1);
|
||||||
ScreenManager_add(scr, panel, -1);
|
ScreenManager_add(scr, panel, -1);
|
||||||
|
@ -67,7 +66,7 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess)
|
||||||
Panel_resize(panel, COLS, LINES - y - 1);
|
Panel_resize(panel, COLS, LINES - y - 1);
|
||||||
if (panelFocus == list && ch == 13) {
|
if (panelFocus == list && ch == 13) {
|
||||||
if (followProcess) {
|
if (followProcess) {
|
||||||
Process* selected = (Process*)Panel_getSelected(panel);
|
const Process* selected = (const Process*)Panel_getSelected(panel);
|
||||||
if (selected && selected->pid == pid)
|
if (selected && selected->pid == pid)
|
||||||
return Panel_getSelected(list);
|
return Panel_getSelected(list);
|
||||||
|
|
||||||
|
@ -141,7 +140,7 @@ static bool expandCollapse(Panel* panel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool collapseIntoParent(Panel* panel) {
|
static bool collapseIntoParent(Panel* panel) {
|
||||||
Process* p = (Process*) Panel_getSelected(panel);
|
const Process* p = (Process*) Panel_getSelected(panel);
|
||||||
if (!p)
|
if (!p)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -168,7 +167,7 @@ static Htop_Reaction actionSetSortColumn(State* st) {
|
||||||
Htop_Reaction reaction = HTOP_OK;
|
Htop_Reaction reaction = HTOP_OK;
|
||||||
Panel* sortPanel = Panel_new(0, 0, 0, 0, Class(ListItem), true, FunctionBar_newEnterEsc("Sort ", "Cancel "));
|
Panel* sortPanel = Panel_new(0, 0, 0, 0, Class(ListItem), true, FunctionBar_newEnterEsc("Sort ", "Cancel "));
|
||||||
Panel_setHeader(sortPanel, "Sort by");
|
Panel_setHeader(sortPanel, "Sort by");
|
||||||
ProcessField* fields = st->settings->fields;
|
const ProcessField* fields = st->settings->fields;
|
||||||
for (int i = 0; fields[i]; i++) {
|
for (int i = 0; fields[i]; i++) {
|
||||||
char* name = String_trim(Process_fields[fields[i]].name);
|
char* name = String_trim(Process_fields[fields[i]].name);
|
||||||
Panel_add(sortPanel, (Object*) ListItem_new(name, fields[i]));
|
Panel_add(sortPanel, (Object*) ListItem_new(name, fields[i]));
|
||||||
|
@ -177,7 +176,7 @@ static Htop_Reaction actionSetSortColumn(State* st) {
|
||||||
|
|
||||||
free(name);
|
free(name);
|
||||||
}
|
}
|
||||||
ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15, false);
|
const ListItem* field = (const ListItem*) Action_pickFromVector(st, sortPanel, 15, false);
|
||||||
if (field) {
|
if (field) {
|
||||||
reaction |= Action_setSortKey(st->settings, field->key);
|
reaction |= Action_setSortKey(st->settings, field->key);
|
||||||
}
|
}
|
||||||
|
@ -293,7 +292,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
|
||||||
#if (defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY))
|
#if (defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY))
|
||||||
Panel* panel = st->panel;
|
Panel* panel = st->panel;
|
||||||
|
|
||||||
Process* p = (Process*) Panel_getSelected(panel);
|
const Process* p = (const Process*) Panel_getSelected(panel);
|
||||||
if (!p)
|
if (!p)
|
||||||
return HTOP_OK;
|
return HTOP_OK;
|
||||||
|
|
||||||
|
@ -306,7 +305,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
|
||||||
width += 1; /* we add a gap between the panels */
|
width += 1; /* we add a gap between the panels */
|
||||||
Affinity_delete(affinity1);
|
Affinity_delete(affinity1);
|
||||||
|
|
||||||
void* set = Action_pickFromVector(st, affinityPanel, width, true);
|
const void* set = Action_pickFromVector(st, affinityPanel, width, true);
|
||||||
if (set) {
|
if (set) {
|
||||||
Affinity* affinity2 = AffinityPanel_getAffinity(affinityPanel, st->pl);
|
Affinity* affinity2 = AffinityPanel_getAffinity(affinityPanel, st->pl);
|
||||||
bool ok = MainPanel_foreachProcess((MainPanel*)panel, Affinity_set, (Arg) { .v = affinity2 }, NULL);
|
bool ok = MainPanel_foreachProcess((MainPanel*)panel, Affinity_set, (Arg) { .v = affinity2 }, NULL);
|
||||||
|
@ -321,7 +320,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
|
||||||
|
|
||||||
static Htop_Reaction actionKill(State* st) {
|
static Htop_Reaction actionKill(State* st) {
|
||||||
Panel* signalsPanel = SignalsPanel_new();
|
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) {
|
||||||
if (sgn->key != 0) {
|
if (sgn->key != 0) {
|
||||||
Panel_setHeader(st->panel, "Sending...");
|
Panel_setHeader(st->panel, "Sending...");
|
||||||
|
@ -342,7 +341,7 @@ static Htop_Reaction actionFilterByUser(State* st) {
|
||||||
Vector_insertionSort(usersPanel->items);
|
Vector_insertionSort(usersPanel->items);
|
||||||
ListItem* allUsers = ListItem_new("All users", -1);
|
ListItem* allUsers = ListItem_new("All users", -1);
|
||||||
Panel_insert(usersPanel, 0, (Object*) allUsers);
|
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) {
|
||||||
if (picked == allUsers) {
|
if (picked == allUsers) {
|
||||||
st->pl->userId = (uid_t)-1;
|
st->pl->userId = (uid_t)-1;
|
||||||
|
@ -370,7 +369,7 @@ static Htop_Reaction actionSetup(State* st) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionLsof(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)
|
if (!p)
|
||||||
return HTOP_OK;
|
return HTOP_OK;
|
||||||
|
|
||||||
|
@ -383,7 +382,7 @@ static Htop_Reaction actionLsof(State* st) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionShowLocks(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;
|
if (!p) return HTOP_OK;
|
||||||
ProcessLocksScreen* pls = ProcessLocksScreen_new(p);
|
ProcessLocksScreen* pls = ProcessLocksScreen_new(p);
|
||||||
InfoScreen_run((InfoScreen*)pls);
|
InfoScreen_run((InfoScreen*)pls);
|
||||||
|
@ -394,7 +393,7 @@ static Htop_Reaction actionShowLocks(State* st) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionStrace(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)
|
if (!p)
|
||||||
return HTOP_OK;
|
return HTOP_OK;
|
||||||
|
|
||||||
|
@ -483,8 +482,6 @@ static inline void addattrstr( int attr, const char* str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionHelp(State* st) {
|
static Htop_Reaction actionHelp(State* st) {
|
||||||
Settings* settings = st->settings;
|
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
attrset(CRT_colors[HELP_BOLD]);
|
attrset(CRT_colors[HELP_BOLD]);
|
||||||
|
|
||||||
|
@ -501,7 +498,7 @@ static Htop_Reaction actionHelp(State* st) {
|
||||||
mvaddstr(line++, 0, "CPU usage bar: ");
|
mvaddstr(line++, 0, "CPU usage bar: ");
|
||||||
|
|
||||||
addattrstr(CRT_colors[BAR_BORDER], "[");
|
addattrstr(CRT_colors[BAR_BORDER], "[");
|
||||||
if (settings->detailedCPUTime) {
|
if (st->settings->detailedCPUTime) {
|
||||||
addattrstr(CRT_colors[CPU_NICE_TEXT], "low"); addstr("/");
|
addattrstr(CRT_colors[CPU_NICE_TEXT], "low"); addstr("/");
|
||||||
addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/");
|
addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/");
|
||||||
addattrstr(CRT_colors[CPU_SYSTEM], "kernel"); addstr("/");
|
addattrstr(CRT_colors[CPU_SYSTEM], "kernel"); addstr("/");
|
||||||
|
|
|
@ -52,7 +52,7 @@ void Affinity_add(Affinity* this, int id) {
|
||||||
|
|
||||||
#ifdef HAVE_LIBHWLOC
|
#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();
|
hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
|
||||||
bool ok = (hwloc_get_proc_cpubind(pl->topology, proc->pid, cpuset, HTOP_HWLOC_CPUBIND_FLAG) == 0);
|
bool ok = (hwloc_get_proc_cpubind(pl->topology, proc->pid, cpuset, HTOP_HWLOC_CPUBIND_FLAG) == 0);
|
||||||
Affinity* affinity = NULL;
|
Affinity* affinity = NULL;
|
||||||
|
@ -86,7 +86,7 @@ bool Affinity_set(Process* proc, Arg arg) {
|
||||||
|
|
||||||
#elif defined(HAVE_LINUX_AFFINITY)
|
#elif defined(HAVE_LINUX_AFFINITY)
|
||||||
|
|
||||||
Affinity* Affinity_get(Process* proc, ProcessList* pl) {
|
Affinity* Affinity_get(const Process* proc, ProcessList* pl) {
|
||||||
cpu_set_t cpuset;
|
cpu_set_t cpuset;
|
||||||
bool ok = (sched_getaffinity(proc->pid, sizeof(cpu_set_t), &cpuset) == 0);
|
bool ok = (sched_getaffinity(proc->pid, sizeof(cpu_set_t), &cpuset) == 0);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
|
|
|
@ -40,7 +40,7 @@ void Affinity_add(Affinity* this, int id);
|
||||||
|
|
||||||
#if defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY)
|
#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);
|
bool Affinity_set(Process* proc, Arg arg);
|
||||||
|
|
||||||
|
|
|
@ -357,7 +357,7 @@ static const char* const AffinityPanelFunctions[] = {
|
||||||
static const char* const AffinityPanelKeys[] = {"Enter", "Esc", "F1", "F2", "F3"};
|
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)};
|
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);
|
AffinityPanel* this = AllocThis(AffinityPanel);
|
||||||
Panel* super = (Panel*) this;
|
Panel* super = (Panel*) this;
|
||||||
Panel_init(super, 1, 1, 1, 1, Class(MaskItem), false, FunctionBar_new(AffinityPanelFunctions, AffinityPanelKeys, AffinityPanelEvents));
|
Panel_init(super, 1, 1, 1, 1, Class(MaskItem), false, FunctionBar_new(AffinityPanelFunctions, AffinityPanelKeys, AffinityPanelEvents));
|
||||||
|
@ -418,7 +418,7 @@ Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity, int* width) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl) {
|
Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl) {
|
||||||
AffinityPanel* this = (AffinityPanel*) super;
|
const AffinityPanel* this = (AffinityPanel*) super;
|
||||||
Affinity* affinity = Affinity_new(pl);
|
Affinity* affinity = Affinity_new(pl);
|
||||||
|
|
||||||
#ifdef HAVE_LIBHWLOC
|
#ifdef HAVE_LIBHWLOC
|
||||||
|
@ -428,7 +428,7 @@ Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl) {
|
||||||
hwloc_bitmap_foreach_end();
|
hwloc_bitmap_foreach_end();
|
||||||
#else
|
#else
|
||||||
for (int i = 0; i < this->pl->cpuCount; i++) {
|
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) {
|
if (item->value) {
|
||||||
Affinity_add(affinity, item->cpu);
|
Affinity_add(affinity, item->cpu);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ in the source distribution for its full text.
|
||||||
|
|
||||||
extern const PanelClass AffinityPanel_class;
|
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);
|
Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl);
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ const PanelClass AvailableMetersPanel_class = {
|
||||||
.eventHandler = AvailableMetersPanel_eventHandler
|
.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);
|
AvailableMetersPanel* this = AllocThis(AvailableMetersPanel);
|
||||||
Panel* super = (Panel*) this;
|
Panel* super = (Panel*) this;
|
||||||
FunctionBar* fuBar = FunctionBar_newEnterEsc("Add ", "Done ");
|
FunctionBar* fuBar = FunctionBar_newEnterEsc("Add ", "Done ");
|
||||||
|
|
|
@ -25,6 +25,6 @@ typedef struct AvailableMetersPanel_ {
|
||||||
|
|
||||||
extern const PanelClass AvailableMetersPanel_class;
|
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
|
#endif
|
||||||
|
|
|
@ -167,8 +167,8 @@ static void CPUMeter_display(const Object* cast, RichString* out) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AllCPUsMeter_getRange(Meter* this, int* start, int* count) {
|
static void AllCPUsMeter_getRange(const Meter* this, int* start, int* count) {
|
||||||
CPUMeterData* data = this->meterData;
|
const CPUMeterData* data = this->meterData;
|
||||||
int cpus = data->cpus;
|
int cpus = data->cpus;
|
||||||
switch(Meter_name(this)[0]) {
|
switch(Meter_name(this)[0]) {
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -22,7 +22,7 @@ static const int ClockMeter_attributes[] = {
|
||||||
static void ClockMeter_updateValues(Meter* this, char* buffer, size_t size) {
|
static void ClockMeter_updateValues(Meter* this, char* buffer, size_t size) {
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
struct tm result;
|
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;
|
this->values[0] = lt->tm_hour * 60 + lt->tm_min;
|
||||||
strftime(buffer, size, "%H:%M:%S", lt);
|
strftime(buffer, size, "%H:%M:%S", lt);
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ ColumnsPanel* ColumnsPanel_new(Settings* settings) {
|
||||||
this->moving = false;
|
this->moving = false;
|
||||||
Panel_setHeader(super, "Active Columns");
|
Panel_setHeader(super, "Active Columns");
|
||||||
|
|
||||||
ProcessField* fields = this->settings->fields;
|
const ProcessField* fields = this->settings->fields;
|
||||||
for (; *fields; fields++) {
|
for (; *fields; fields++) {
|
||||||
if (Process_fields[*fields].name) {
|
if (Process_fields[*fields].name) {
|
||||||
Panel_add(super, (Object*) ListItem_new(Process_fields[*fields].name, *fields));
|
Panel_add(super, (Object*) ListItem_new(Process_fields[*fields].name, *fields));
|
||||||
|
|
|
@ -22,7 +22,7 @@ static const int DateMeter_attributes[] = {
|
||||||
static void DateMeter_updateValues(Meter* this, char* buffer, size_t size) {
|
static void DateMeter_updateValues(Meter* this, char* buffer, size_t size) {
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
struct tm result;
|
struct tm result;
|
||||||
struct tm* lt = localtime_r(&t, &result);
|
const struct tm* lt = localtime_r(&t, &result);
|
||||||
this->values[0] = lt->tm_yday;
|
this->values[0] = lt->tm_yday;
|
||||||
int year = lt->tm_year + 1900;
|
int year = lt->tm_year + 1900;
|
||||||
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
|
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
|
||||||
|
|
|
@ -22,7 +22,7 @@ static const int DateTimeMeter_attributes[] = {
|
||||||
static void DateTimeMeter_updateValues(Meter* this, char* buffer, size_t size) {
|
static void DateTimeMeter_updateValues(Meter* this, char* buffer, size_t size) {
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
struct tm result;
|
struct tm result;
|
||||||
struct tm* lt = localtime_r(&t, &result);
|
const struct tm* lt = localtime_r(&t, &result);
|
||||||
int year = lt->tm_year + 1900;
|
int year = lt->tm_year + 1900;
|
||||||
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
|
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
|
||||||
this->total = 366;
|
this->total = 366;
|
||||||
|
|
|
@ -38,7 +38,7 @@ static void EnvScreen_scan(InfoScreen* this) {
|
||||||
char* env = Platform_getProcessEnv(this->process->pid);
|
char* env = Platform_getProcessEnv(this->process->pid);
|
||||||
CRT_restorePrivileges();
|
CRT_restorePrivileges();
|
||||||
if (env) {
|
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);
|
InfoScreen_addLine(this, p);
|
||||||
free(env);
|
free(env);
|
||||||
}
|
}
|
||||||
|
|
22
Header.c
22
Header.c
|
@ -42,7 +42,7 @@ void Header_delete(Header* this) {
|
||||||
|
|
||||||
void Header_populateFromSettings(Header* this) {
|
void Header_populateFromSettings(Header* this) {
|
||||||
Header_forEachColumn(this, col) {
|
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++) {
|
for (int i = 0; i < colSettings->len; i++) {
|
||||||
Header_addMeterByName(this, colSettings->names[i], col);
|
Header_addMeterByName(this, colSettings->names[i], col);
|
||||||
if (colSettings->modes[i] != 0) {
|
if (colSettings->modes[i] != 0) {
|
||||||
|
@ -60,7 +60,7 @@ void Header_writeBackToSettings(const Header* this) {
|
||||||
String_freeArray(colSettings->names);
|
String_freeArray(colSettings->names);
|
||||||
free(colSettings->modes);
|
free(colSettings->modes);
|
||||||
|
|
||||||
Vector* vec = this->columns[col];
|
const Vector* vec = this->columns[col];
|
||||||
int len = Vector_size(vec);
|
int len = Vector_size(vec);
|
||||||
|
|
||||||
colSettings->names = xCalloc(len + 1, sizeof(char*));
|
colSettings->names = xCalloc(len + 1, sizeof(char*));
|
||||||
|
@ -68,7 +68,7 @@ void Header_writeBackToSettings(const Header* this) {
|
||||||
colSettings->len = len;
|
colSettings->len = len;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
Meter* meter = (Meter*) Vector_get(vec, i);
|
const Meter* meter = (Meter*) Vector_get(vec, i);
|
||||||
char* name;
|
char* name;
|
||||||
if (meter->param) {
|
if (meter->param) {
|
||||||
xAsprintf(&name, "%s(%d)", As_Meter(meter)->name, meter->param);
|
xAsprintf(&name, "%s(%d)", As_Meter(meter)->name, meter->param);
|
||||||
|
@ -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];
|
Vector* meters = this->columns[column];
|
||||||
|
|
||||||
char* paren = strchr(name, '(');
|
char* paren = strchr(name, '(');
|
||||||
|
@ -126,15 +126,15 @@ Meter* Header_addMeterByClass(Header* this, const MeterClass* type, int param, i
|
||||||
return meter;
|
return meter;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Header_size(Header* this, int column) {
|
int Header_size(const Header* this, int column) {
|
||||||
Vector* meters = this->columns[column];
|
const Vector* meters = this->columns[column];
|
||||||
return Vector_size(meters);
|
return Vector_size(meters);
|
||||||
}
|
}
|
||||||
|
|
||||||
MeterModeId Header_readMeterMode(Header* this, int i, int column) {
|
MeterModeId Header_readMeterMode(const Header* this, int i, int column) {
|
||||||
Vector* meters = this->columns[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;
|
return meter->mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,10 +175,10 @@ int Header_calculateHeight(Header* this) {
|
||||||
int maxHeight = pad;
|
int maxHeight = pad;
|
||||||
|
|
||||||
Header_forEachColumn(this, col) {
|
Header_forEachColumn(this, col) {
|
||||||
Vector* meters = this->columns[col];
|
const Vector* meters = this->columns[col];
|
||||||
int height = pad;
|
int height = pad;
|
||||||
for (int i = 0; i < Vector_size(meters); i++) {
|
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;
|
height += meter->h;
|
||||||
}
|
}
|
||||||
maxHeight = MAXIMUM(maxHeight, height);
|
maxHeight = MAXIMUM(maxHeight, height);
|
||||||
|
|
6
Header.h
6
Header.h
|
@ -31,15 +31,15 @@ void Header_populateFromSettings(Header* this);
|
||||||
|
|
||||||
void Header_writeBackToSettings(const 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);
|
void Header_setMode(Header* this, int i, MeterModeId mode, int column);
|
||||||
|
|
||||||
Meter* Header_addMeterByClass(Header* this, const MeterClass* type, int param, 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);
|
void Header_reinit(Header* this);
|
||||||
|
|
||||||
|
|
10
IncSet.c
10
IncSet.c
|
@ -77,8 +77,8 @@ void IncSet_delete(IncSet* this) {
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) {
|
static void updateWeakPanel(const IncSet* this, Panel* panel, Vector* lines) {
|
||||||
Object* selected = Panel_getSelected(panel);
|
const Object* selected = Panel_getSelected(panel);
|
||||||
Panel_prune(panel);
|
Panel_prune(panel);
|
||||||
if (this->filtering) {
|
if (this->filtering) {
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
@ -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);
|
int size = Panel_size(panel);
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
if (String_contains_i(getPanelValue(panel, i), mode->buffer)) {
|
if (String_contains_i(getPanelValue(panel, i), mode->buffer)) {
|
||||||
|
@ -117,7 +117,7 @@ static bool search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelVa
|
||||||
return false;
|
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 size = Panel_size(panel);
|
||||||
int here = Panel_getSelectedIndex(panel);
|
int here = Panel_getSelectedIndex(panel);
|
||||||
int i = here;
|
int i = here;
|
||||||
|
@ -208,7 +208,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* IncSet_getListItemValue(Panel* panel, int i) {
|
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 : "";
|
return l ? l->value : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ void MainPanel_pidSearch(MainPanel* this, int ch) {
|
||||||
Panel* super = (Panel*) this;
|
Panel* super = (Panel*) this;
|
||||||
pid_t pid = ch - 48 + this->pidSearch;
|
pid_t pid = ch - 48 + this->pidSearch;
|
||||||
for (int i = 0; i < Panel_size(super); i++) {
|
for (int i = 0; i < Panel_size(super); i++) {
|
||||||
Process* p = (Process*) Panel_get(super, i);
|
const Process* p = (const Process*) Panel_get(super, i);
|
||||||
if (p && p->pid == pid) {
|
if (p && p->pid == pid) {
|
||||||
Panel_setSelected(super, i);
|
Panel_setSelected(super, i);
|
||||||
break;
|
break;
|
||||||
|
@ -134,7 +134,7 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int MainPanel_selectedPid(MainPanel* this) {
|
int MainPanel_selectedPid(MainPanel* this) {
|
||||||
Process* p = (Process*) Panel_getSelected((Panel*)this);
|
const Process* p = (const Process*) Panel_getSelected((Panel*)this);
|
||||||
if (p) {
|
if (p) {
|
||||||
return p->pid;
|
return p->pid;
|
||||||
}
|
}
|
||||||
|
|
2
Meter.c
2
Meter.c
|
@ -131,7 +131,7 @@ void Meter_setMode(Meter* this, int modeIndex) {
|
||||||
this->mode = modeIndex;
|
this->mode = modeIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
ListItem* Meter_toListItem(Meter* this, bool moving) {
|
ListItem* Meter_toListItem(const Meter* this, bool moving) {
|
||||||
char mode[20];
|
char mode[20];
|
||||||
if (this->mode) {
|
if (this->mode) {
|
||||||
xSnprintf(mode, sizeof(mode), " [%s]", Meter_modes[this->mode]->uiName);
|
xSnprintf(mode, sizeof(mode), " [%s]", Meter_modes[this->mode]->uiName);
|
||||||
|
|
2
Meter.h
2
Meter.h
|
@ -133,7 +133,7 @@ void Meter_setCaption(Meter* this, const char* caption);
|
||||||
|
|
||||||
void Meter_setMode(Meter* this, int modeIndex);
|
void Meter_setMode(Meter* this, int modeIndex);
|
||||||
|
|
||||||
ListItem* Meter_toListItem(Meter* this, bool moving);
|
ListItem* Meter_toListItem(const Meter* this, bool moving);
|
||||||
|
|
||||||
extern const MeterMode* const Meter_modes[];
|
extern const MeterMode* const Meter_modes[];
|
||||||
|
|
||||||
|
|
10
Panel.c
10
Panel.c
|
@ -172,13 +172,13 @@ void Panel_moveSelectedDown(Panel* this) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Panel_getSelectedIndex(Panel* this) {
|
int Panel_getSelectedIndex(const Panel* this) {
|
||||||
assert (this != NULL);
|
assert (this != NULL);
|
||||||
|
|
||||||
return this->selected;
|
return this->selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Panel_size(Panel* this) {
|
int Panel_size(const Panel* this) {
|
||||||
assert (this != NULL);
|
assert (this != NULL);
|
||||||
|
|
||||||
return Vector_size(this->items);
|
return Vector_size(this->items);
|
||||||
|
@ -269,7 +269,7 @@ void Panel_draw(Panel* this, bool force_redraw, bool focus, bool highlightSelect
|
||||||
if (this->needsRedraw || force_redraw) {
|
if (this->needsRedraw || force_redraw) {
|
||||||
int line = 0;
|
int line = 0;
|
||||||
for (int i = first; line < h && i < upTo; i++) {
|
for (int i = first; line < h && i < upTo; i++) {
|
||||||
Object* itemObj = Vector_get(this->items, i);
|
const Object* itemObj = Vector_get(this->items, i);
|
||||||
RichString_begin(item);
|
RichString_begin(item);
|
||||||
Object_display(itemObj, &item);
|
Object_display(itemObj, &item);
|
||||||
int itemLen = RichString_sizeVal(item);
|
int itemLen = RichString_sizeVal(item);
|
||||||
|
@ -296,11 +296,11 @@ void Panel_draw(Panel* this, bool force_redraw, bool focus, bool highlightSelect
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Object* oldObj = Vector_get(this->items, this->oldSelected);
|
const Object* oldObj = Vector_get(this->items, this->oldSelected);
|
||||||
RichString_begin(old);
|
RichString_begin(old);
|
||||||
Object_display(oldObj, &old);
|
Object_display(oldObj, &old);
|
||||||
int oldLen = RichString_sizeVal(old);
|
int oldLen = RichString_sizeVal(old);
|
||||||
Object* newObj = Vector_get(this->items, this->selected);
|
const Object* newObj = Vector_get(this->items, this->selected);
|
||||||
RichString_begin(new);
|
RichString_begin(new);
|
||||||
Object_display(newObj, &new);
|
Object_display(newObj, &new);
|
||||||
int newLen = RichString_sizeVal(new);
|
int newLen = RichString_sizeVal(new);
|
||||||
|
|
4
Panel.h
4
Panel.h
|
@ -112,9 +112,9 @@ void Panel_moveSelectedUp(Panel* this);
|
||||||
|
|
||||||
void Panel_moveSelectedDown(Panel* this);
|
void Panel_moveSelectedDown(Panel* this);
|
||||||
|
|
||||||
int Panel_getSelectedIndex(Panel* this);
|
int Panel_getSelectedIndex(const Panel* this);
|
||||||
|
|
||||||
int Panel_size(Panel* this);
|
int Panel_size(const Panel* this);
|
||||||
|
|
||||||
void Panel_setSelected(Panel* this, int selected);
|
void Panel_setSelected(Panel* this, int selected);
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ static const char* alignedProcessFieldTitle(ProcessField field) {
|
||||||
return titleBuffer;
|
return titleBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessList_printHeader(ProcessList* this, RichString* header) {
|
void ProcessList_printHeader(const ProcessList* this, RichString* header) {
|
||||||
RichString_prune(header);
|
RichString_prune(header);
|
||||||
|
|
||||||
const Settings* settings = this->settings;
|
const Settings* settings = this->settings;
|
||||||
|
@ -141,11 +141,11 @@ void ProcessList_add(ProcessList* this, Process* p) {
|
||||||
assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
|
assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessList_remove(ProcessList* this, Process* p) {
|
void ProcessList_remove(ProcessList* this, const Process* p) {
|
||||||
assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1);
|
assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1);
|
||||||
assert(Hashtable_get(this->processTable, p->pid) != NULL);
|
assert(Hashtable_get(this->processTable, p->pid) != NULL);
|
||||||
|
|
||||||
Process* pp = Hashtable_remove(this->processTable, p->pid);
|
const Process* pp = Hashtable_remove(this->processTable, p->pid);
|
||||||
assert(pp == p); (void)pp;
|
assert(pp == p); (void)pp;
|
||||||
|
|
||||||
pid_t pid = p->pid;
|
pid_t pid = p->pid;
|
||||||
|
@ -169,7 +169,7 @@ Process* ProcessList_get(ProcessList* this, int idx) {
|
||||||
return (Process*)Vector_get(this->processes, idx);
|
return (Process*)Vector_get(this->processes, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ProcessList_size(ProcessList* this) {
|
int ProcessList_size(const ProcessList* this) {
|
||||||
return Vector_size(this->processes);
|
return Vector_size(this->processes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,15 +85,15 @@ void ProcessList_done(ProcessList* this);
|
||||||
|
|
||||||
void ProcessList_setPanel(ProcessList* this, Panel* panel);
|
void ProcessList_setPanel(ProcessList* this, Panel* panel);
|
||||||
|
|
||||||
void ProcessList_printHeader(ProcessList* this, RichString* header);
|
void ProcessList_printHeader(const ProcessList* this, RichString* header);
|
||||||
|
|
||||||
void ProcessList_add(ProcessList* this, Process* p);
|
void ProcessList_add(ProcessList* this, Process* p);
|
||||||
|
|
||||||
void ProcessList_remove(ProcessList* this, Process* p);
|
void ProcessList_remove(ProcessList* this, const Process* p);
|
||||||
|
|
||||||
Process* ProcessList_get(ProcessList* this, int idx);
|
Process* ProcessList_get(ProcessList* this, int idx);
|
||||||
|
|
||||||
int ProcessList_size(ProcessList* this);
|
int ProcessList_size(const ProcessList* this);
|
||||||
|
|
||||||
void ProcessList_sort(ProcessList* this);
|
void ProcessList_sort(ProcessList* this);
|
||||||
|
|
||||||
|
|
10
RichString.c
10
RichString.c
|
@ -80,9 +80,9 @@ inline void RichString_setAttrn(RichString* this, int attrs, int start, int char
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int RichString_findChar(RichString* this, char c, int start) {
|
int RichString_findChar(const RichString* this, char c, int start) {
|
||||||
wchar_t wc = btowc(c);
|
const wchar_t wc = btowc(c);
|
||||||
cchar_t* ch = this->chptr + start;
|
const cchar_t* ch = this->chptr + start;
|
||||||
for (int i = start; i < this->chlen; i++) {
|
for (int i = start; i < this->chlen; i++) {
|
||||||
if (ch->chars[0] == wc)
|
if (ch->chars[0] == wc)
|
||||||
return i;
|
return i;
|
||||||
|
@ -115,8 +115,8 @@ void RichString_setAttrn(RichString* this, int attrs, int start, int charcount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int RichString_findChar(RichString* this, char c, int start) {
|
int RichString_findChar(const RichString* this, char c, int start) {
|
||||||
chtype* ch = this->chptr + start;
|
const chtype* ch = this->chptr + start;
|
||||||
for (int i = start; i < this->chlen; i++) {
|
for (int i = start; i < this->chlen; i++) {
|
||||||
if ((*ch & 0xff) == (chtype) c)
|
if ((*ch & 0xff) == (chtype) c)
|
||||||
return i;
|
return i;
|
||||||
|
|
|
@ -44,7 +44,7 @@ typedef struct RichString_ {
|
||||||
|
|
||||||
void RichString_setAttrn(RichString* this, int attrs, int start, int charcount);
|
void RichString_setAttrn(RichString* this, int attrs, int start, int charcount);
|
||||||
|
|
||||||
int RichString_findChar(RichString* this, char c, int start);
|
int RichString_findChar(const RichString* this, char c, int start);
|
||||||
|
|
||||||
void RichString_prune(RichString* this);
|
void RichString_prune(RichString* this);
|
||||||
|
|
||||||
|
|
|
@ -42,14 +42,14 @@ void ScreenManager_delete(ScreenManager* this) {
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int ScreenManager_size(ScreenManager* this) {
|
inline int ScreenManager_size(const ScreenManager* this) {
|
||||||
return this->panelCount;
|
return this->panelCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenManager_add(ScreenManager* this, Panel* item, int size) {
|
void ScreenManager_add(ScreenManager* this, Panel* item, int size) {
|
||||||
int lastX = 0;
|
int lastX = 0;
|
||||||
if (this->panelCount > 0) {
|
if (this->panelCount > 0) {
|
||||||
Panel* last = (Panel*) Vector_get(this->panels, this->panelCount - 1);
|
const Panel* last = (const Panel*) Vector_get(this->panels, this->panelCount - 1);
|
||||||
lastX = last->x + last->w + 1;
|
lastX = last->x + last->w + 1;
|
||||||
}
|
}
|
||||||
int height = LINES - this->y1 + this->y2;
|
int height = LINES - this->y1 + this->y2;
|
||||||
|
@ -181,7 +181,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||||
if (panel == panelFocus || this->allowFocusChange) {
|
if (panel == panelFocus || this->allowFocusChange) {
|
||||||
focus = i;
|
focus = i;
|
||||||
panelFocus = panel;
|
panelFocus = panel;
|
||||||
Object* oldSelection = Panel_getSelected(panel);
|
const Object* oldSelection = Panel_getSelected(panel);
|
||||||
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
|
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
|
||||||
if (Panel_getSelected(panel) == oldSelection) {
|
if (Panel_getSelected(panel) == oldSelection) {
|
||||||
ch = KEY_RECLICK;
|
ch = KEY_RECLICK;
|
||||||
|
|
|
@ -34,7 +34,7 @@ ScreenManager* ScreenManager_new(Header* header, const Settings* settings, const
|
||||||
|
|
||||||
void ScreenManager_delete(ScreenManager* this);
|
void ScreenManager_delete(ScreenManager* this);
|
||||||
|
|
||||||
int ScreenManager_size(ScreenManager* this);
|
int ScreenManager_size(const ScreenManager* this);
|
||||||
|
|
||||||
void ScreenManager_add(ScreenManager* this, Panel* item, int size);
|
void ScreenManager_add(ScreenManager* this, Panel* item, int size);
|
||||||
|
|
||||||
|
|
|
@ -29,14 +29,14 @@ void Settings_delete(Settings* this) {
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Settings_readMeters(Settings* this, char* line, int column) {
|
static void Settings_readMeters(Settings* this, const char* line, int column) {
|
||||||
char* trim = String_trim(line);
|
char* trim = String_trim(line);
|
||||||
char** ids = String_split(trim, ' ', NULL);
|
char** ids = String_split(trim, ' ', NULL);
|
||||||
free(trim);
|
free(trim);
|
||||||
this->columns[column].names = ids;
|
this->columns[column].names = ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Settings_readMeterModes(Settings* this, char* line, int column) {
|
static void Settings_readMeterModes(Settings* this, const char* line, int column) {
|
||||||
char* trim = String_trim(line);
|
char* trim = String_trim(line);
|
||||||
char** ids = String_split(trim, ' ', NULL);
|
char** ids = String_split(trim, ' ', NULL);
|
||||||
free(trim);
|
free(trim);
|
||||||
|
@ -237,7 +237,7 @@ static bool Settings_read(Settings* this, const char* fileName, int initialCpuCo
|
||||||
return didReadFields;
|
return didReadFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void writeFields(FILE* fd, ProcessField* fields, const char* name) {
|
static void writeFields(FILE* fd, const ProcessField* fields, const char* name) {
|
||||||
fprintf(fd, "%s=", name);
|
fprintf(fd, "%s=", name);
|
||||||
const char* sep = "";
|
const char* sep = "";
|
||||||
for (int i = 0; fields[i]; i++) {
|
for (int i = 0; fields[i]; i++) {
|
||||||
|
@ -370,7 +370,7 @@ Settings* Settings_new(int initialCpuCount) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char* legacyDotfile = NULL;
|
char* legacyDotfile = NULL;
|
||||||
char* rcfile = getenv("HTOPRC");
|
const char* rcfile = getenv("HTOPRC");
|
||||||
if (rcfile) {
|
if (rcfile) {
|
||||||
this->filename = xStrdup(rcfile);
|
this->filename = xStrdup(rcfile);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -35,7 +35,7 @@ static const char* const TraceScreenKeys[] = {"F3", "F4", "F8", "F9", "Esc"};
|
||||||
|
|
||||||
static const int TraceScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(8), KEY_F(9), 27};
|
static const int TraceScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(8), KEY_F(9), 27};
|
||||||
|
|
||||||
TraceScreen* TraceScreen_new(Process* process) {
|
TraceScreen* TraceScreen_new(const Process* process) {
|
||||||
// This initializes all TraceScreen variables to "false" so only default = true ones need to be set below
|
// This initializes all TraceScreen variables to "false" so only default = true ones need to be set below
|
||||||
TraceScreen* this = xCalloc(1, sizeof(TraceScreen));
|
TraceScreen* this = xCalloc(1, sizeof(TraceScreen));
|
||||||
Object_setClass(this, Class(TraceScreen));
|
Object_setClass(this, Class(TraceScreen));
|
||||||
|
|
|
@ -28,7 +28,7 @@ typedef struct TraceScreen_ {
|
||||||
|
|
||||||
extern const InfoScreenClass TraceScreen_class;
|
extern const InfoScreenClass TraceScreen_class;
|
||||||
|
|
||||||
TraceScreen* TraceScreen_new(Process* process);
|
TraceScreen* TraceScreen_new(const Process* process);
|
||||||
|
|
||||||
void TraceScreen_delete(Object* cast);
|
void TraceScreen_delete(Object* cast);
|
||||||
|
|
||||||
|
|
2
XUtils.c
2
XUtils.c
|
@ -173,7 +173,7 @@ char* String_readLine(FILE* fd) {
|
||||||
char* buffer = xMalloc(step + 1);
|
char* buffer = xMalloc(step + 1);
|
||||||
char* at = buffer;
|
char* at = buffer;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char* ok = fgets(at, step + 1, fd);
|
const char* ok = fgets(at, step + 1, fd);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -107,7 +107,7 @@ static void LinuxProcessList_initTtyDrivers(LinuxProcessList* this) {
|
||||||
while (*at != '\0') {
|
while (*at != '\0') {
|
||||||
at = strchr(at, ' '); // skip first token
|
at = strchr(at, ' '); // skip first token
|
||||||
while (*at == ' ') at++; // skip spaces
|
while (*at == ' ') at++; // skip spaces
|
||||||
char* token = at; // mark beginning of path
|
const char* token = at; // mark beginning of path
|
||||||
at = strchr(at, ' '); // find end of path
|
at = strchr(at, ' '); // find end of path
|
||||||
*at = '\0'; at++; // clear and skip
|
*at = '\0'; at++; // clear and skip
|
||||||
ttyDrivers[numDrivers].path = xStrdup(token); // save
|
ttyDrivers[numDrivers].path = xStrdup(token); // save
|
||||||
|
@ -394,7 +394,7 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, openat_arg_t proc
|
||||||
unsigned long long last_read = process->io_read_bytes;
|
unsigned long long last_read = process->io_read_bytes;
|
||||||
unsigned long long last_write = process->io_write_bytes;
|
unsigned long long last_write = process->io_write_bytes;
|
||||||
char* buf = buffer;
|
char* buf = buffer;
|
||||||
char* line = NULL;
|
const char* line;
|
||||||
while ((line = strsep(&buf, "\n")) != NULL) {
|
while ((line = strsep(&buf, "\n")) != NULL) {
|
||||||
switch (line[0]) {
|
switch (line[0]) {
|
||||||
case 'r':
|
case 'r':
|
||||||
|
@ -486,7 +486,7 @@ static void LinuxProcessList_calcLibSize_helper(ATTR_UNUSED ht_key_t key, void*
|
||||||
if (!value)
|
if (!value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LibraryData* v = (LibraryData *)value;
|
const LibraryData* v = (const LibraryData *)value;
|
||||||
uint64_t* d = (uint64_t *)data;
|
uint64_t* d = (uint64_t *)data;
|
||||||
if (!v->exec)
|
if (!v->exec)
|
||||||
return;
|
return;
|
||||||
|
@ -755,7 +755,7 @@ static void LinuxProcessList_readCGroupFile(LinuxProcess* process, openat_arg_t
|
||||||
int left = PROC_LINE_LENGTH;
|
int left = PROC_LINE_LENGTH;
|
||||||
while (!feof(file) && left > 0) {
|
while (!feof(file) && left > 0) {
|
||||||
char buffer[PROC_LINE_LENGTH + 1];
|
char buffer[PROC_LINE_LENGTH + 1];
|
||||||
char* ok = fgets(buffer, PROC_LINE_LENGTH, file);
|
const char* ok = fgets(buffer, PROC_LINE_LENGTH, file);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -859,7 +859,7 @@ static void LinuxProcessList_readSecattrData(LinuxProcess* process, openat_arg_t
|
||||||
}
|
}
|
||||||
|
|
||||||
char buffer[PROC_LINE_LENGTH + 1];
|
char buffer[PROC_LINE_LENGTH + 1];
|
||||||
char* res = fgets(buffer, sizeof(buffer), file);
|
const char* res = fgets(buffer, sizeof(buffer), file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
free(process->secattr);
|
free(process->secattr);
|
||||||
|
@ -906,7 +906,7 @@ static void LinuxProcessList_readCwd(LinuxProcess* process, openat_arg_t procFd)
|
||||||
static int handleNetlinkMsg(struct nl_msg* nlmsg, void* linuxProcess) {
|
static int handleNetlinkMsg(struct nl_msg* nlmsg, void* linuxProcess) {
|
||||||
struct nlmsghdr* nlhdr;
|
struct nlmsghdr* nlhdr;
|
||||||
struct nlattr* nlattrs[TASKSTATS_TYPE_MAX + 1];
|
struct nlattr* nlattrs[TASKSTATS_TYPE_MAX + 1];
|
||||||
struct nlattr* nlattr;
|
const struct nlattr* nlattr;
|
||||||
struct taskstats stats;
|
struct taskstats stats;
|
||||||
int rem;
|
int rem;
|
||||||
LinuxProcess* lp = (LinuxProcess*) linuxProcess;
|
LinuxProcess* lp = (LinuxProcess*) linuxProcess;
|
||||||
|
@ -1663,7 +1663,7 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) {
|
||||||
// Depending on your kernel version,
|
// Depending on your kernel version,
|
||||||
// 5, 7, 8 or 9 of these fields will be set.
|
// 5, 7, 8 or 9 of these fields will be set.
|
||||||
// The rest will remain at zero.
|
// The rest will remain at zero.
|
||||||
char* ok = fgets(buffer, PROC_LINE_LENGTH, file);
|
const char* ok = fgets(buffer, PROC_LINE_LENGTH, file);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
buffer[0] = '\0';
|
buffer[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,13 +131,13 @@ void Platform_done(void) {
|
||||||
static Htop_Reaction Platform_actionSetIOPriority(State* st) {
|
static Htop_Reaction Platform_actionSetIOPriority(State* st) {
|
||||||
Panel* panel = st->panel;
|
Panel* panel = st->panel;
|
||||||
|
|
||||||
LinuxProcess* p = (LinuxProcess*) Panel_getSelected(panel);
|
const LinuxProcess* p = (const LinuxProcess*) Panel_getSelected(panel);
|
||||||
if (!p)
|
if (!p)
|
||||||
return HTOP_OK;
|
return HTOP_OK;
|
||||||
|
|
||||||
IOPriority ioprio1 = p->ioPriority;
|
IOPriority ioprio1 = p->ioPriority;
|
||||||
Panel* ioprioPanel = IOPriorityPanel_new(ioprio1);
|
Panel* ioprioPanel = IOPriorityPanel_new(ioprio1);
|
||||||
void* set = Action_pickFromVector(st, ioprioPanel, 21, true);
|
const void* set = Action_pickFromVector(st, ioprioPanel, 21, true);
|
||||||
if (set) {
|
if (set) {
|
||||||
IOPriority ioprio2 = IOPriorityPanel_getIOPriority(ioprioPanel);
|
IOPriority ioprio2 = IOPriorityPanel_getIOPriority(ioprioPanel);
|
||||||
bool ok = MainPanel_foreachProcess((MainPanel*)panel, LinuxProcess_setIOPriority, (Arg) { .i = ioprio2 }, NULL);
|
bool ok = MainPanel_foreachProcess((MainPanel*)panel, LinuxProcess_setIOPriority, (Arg) { .i = ioprio2 }, NULL);
|
||||||
|
@ -366,7 +366,7 @@ char* Platform_getProcessEnv(pid_t pid) {
|
||||||
*/
|
*/
|
||||||
char* Platform_getInodeFilename(pid_t pid, ino_t inode) {
|
char* Platform_getInodeFilename(pid_t pid, ino_t inode) {
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
struct dirent *de;
|
const struct dirent *de;
|
||||||
DIR *dirp;
|
DIR *dirp;
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -596,11 +596,11 @@ static unsigned long int parseBatInfo(const char* fileName, const unsigned short
|
||||||
memset(batteries, 0, MAX_BATTERIES * sizeof(char*));
|
memset(batteries, 0, MAX_BATTERIES * sizeof(char*));
|
||||||
|
|
||||||
while (nBatteries < MAX_BATTERIES) {
|
while (nBatteries < MAX_BATTERIES) {
|
||||||
struct dirent* dirEntry = readdir(batteryDir);
|
const struct dirent* dirEntry = readdir(batteryDir);
|
||||||
if (!dirEntry)
|
if (!dirEntry)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
char* entryName = dirEntry->d_name;
|
const char* entryName = dirEntry->d_name;
|
||||||
if (!String_startsWith(entryName, "BAT"))
|
if (!String_startsWith(entryName, "BAT"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -653,7 +653,7 @@ static ACPresence procAcpiCheck(void) {
|
||||||
return AC_ERROR;
|
return AC_ERROR;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
struct dirent* dirEntry = readdir(dir);
|
const struct dirent* dirEntry = readdir(dir);
|
||||||
if (!dirEntry)
|
if (!dirEntry)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -728,7 +728,7 @@ static void Platform_Battery_getSysData(double* percent, ACPresence* isOnAC) {
|
||||||
unsigned long int totalRemain = 0;
|
unsigned long int totalRemain = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
struct dirent* dirEntry = readdir(dir);
|
const struct dirent* dirEntry = readdir(dir);
|
||||||
if (!dirEntry)
|
if (!dirEntry)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue