From 02a30bfecdd841b4ca48acfc9b5f2df7930e7a69 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 25 Feb 2010 01:43:18 +0000 Subject: warning fixes --- BatteryMeter.c | 10 ++++----- CategoriesPanel.c | 12 +++++------ ChangeLog | 5 ++++- ColorsPanel.c | 2 +- FunctionBar.c | 14 ++++++------ FunctionBar.h | 4 ++-- HostnameMeter.c | 1 + ListItem.c | 2 +- ListItem.h | 2 +- LoadAverageMeter.c | 6 +++--- MemoryMeter.c | 10 ++++----- Meter.c | 21 +++++++++--------- Meter.h | 10 ++++----- MetersPanel.c | 2 +- MetersPanel.h | 2 +- OpenFilesScreen.c | 8 +++---- Panel.c | 2 +- Panel.h | 2 +- Process.c | 26 +++++++++++------------ Process.h | 14 ++++++------ ProcessList.c | 2 ++ ProcessList.h | 1 + RichString.c | 12 +++++------ RichString.h | 10 ++++----- ScreenManager.c | 8 +++---- ScreenManager.h | 2 +- SignalItem.c | 4 ++-- SignalItem.h | 2 +- SignalsPanel.c | 6 +++--- String.c | 10 ++++----- String.h | 10 ++++----- TraceScreen.c | 4 ++-- Vector.c | 62 +++++++++++++++++++++++++++--------------------------- Vector.h | 14 ++++++------ htop.c | 48 +++++++++++++++++++++--------------------- 35 files changed, 179 insertions(+), 171 deletions(-) diff --git a/BatteryMeter.c b/BatteryMeter.c index c1ec9ec4..11399d46 100644 --- a/BatteryMeter.c +++ b/BatteryMeter.c @@ -28,7 +28,7 @@ int BatteryMeter_attributes[] = { BATTERY }; -static unsigned long int parseUevent(FILE * file, char *key) { +static unsigned long int parseUevent(FILE * file, const char *key) { char line[100]; unsigned long int dValue = 0; @@ -117,7 +117,7 @@ static ACPresence chkIsOnline() { if (access(PROCDIR "/acpi/ac_adapter", F_OK) == 0) { const struct dirent *dirEntries; - char *power_supplyPath = PROCDIR "/acpi/ac_adapter"; + const char *power_supplyPath = PROCDIR "/acpi/ac_adapter"; DIR *power_supplyDir = opendir(power_supplyPath); char *entryName; @@ -170,7 +170,7 @@ static ACPresence chkIsOnline() { } else { - char *power_supplyPath = "/sys/class/power_supply"; + const char *power_supplyPath = "/sys/class/power_supply"; if (access("/sys/class/power_supply", F_OK) == 0) { const struct dirent *dirEntries; @@ -240,7 +240,7 @@ static double getProcBatData() { static double getSysBatData() { const struct dirent *dirEntries; - char *power_supplyPath = "/sys/class/power_supply/"; + const char *power_supplyPath = "/sys/class/power_supply/"; DIR *power_supplyDir = opendir(power_supplyPath); @@ -292,7 +292,7 @@ static void BatteryMeter_setValues(Meter * this, char *buffer, int len) { this->values[0] = percent; - char *onAcText, *onBatteryText, *unknownText; + const char *onAcText, *onBatteryText, *unknownText; unknownText = "%.1f%%"; if (this->mode == TEXT_METERMODE) { diff --git a/CategoriesPanel.c b/CategoriesPanel.c index 9a8bc196..24316f39 100644 --- a/CategoriesPanel.c +++ b/CategoriesPanel.c @@ -23,17 +23,17 @@ typedef struct CategoriesPanel_ { }*/ -static char* MetersFunctions[] = {" ", " ", " ", "Type ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL}; +static const char* MetersFunctions[] = {" ", " ", " ", "Type ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL}; -static char* AvailableMetersFunctions[] = {" ", " ", " ", " ", "Add L ", "Add R ", " ", " ", " ", "Done ", NULL}; +static const char* AvailableMetersFunctions[] = {" ", " ", " ", " ", "Add L ", "Add R ", " ", " ", " ", "Done ", NULL}; -static char* DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; +static const char* DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; -static char* ColumnsFunctions[] = {" ", " ", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL}; +static const char* ColumnsFunctions[] = {" ", " ", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL}; -static char* ColorsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; +static const char* ColorsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; -static char* AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL}; +static const char* AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL}; static void CategoriesPanel_delete(Object* object) { Panel* super = (Panel*) object; diff --git a/ChangeLog b/ChangeLog index 79e31608..5531e56c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,10 @@ What's new in version 0.8.4 - +* Show custom thread names + (thanks to Anders Torger) +* Fix license terms with regard to PLPA + (thanks to Tom Callaway) What's new in version 0.8.3 diff --git a/ColorsPanel.c b/ColorsPanel.c index cdc01662..5e58670c 100644 --- a/ColorsPanel.c +++ b/ColorsPanel.c @@ -27,7 +27,7 @@ typedef struct ColorsPanel_ { }*/ -static char* ColorSchemes[] = { +static const char* ColorSchemes[] = { "Default", "Monochromatic", "Black on White", diff --git a/FunctionBar.c b/FunctionBar.c index 70339ca9..618f9307 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -36,17 +36,17 @@ char* FUNCTIONBAR_CLASS = "FunctionBar"; #define FUNCTIONBAR_CLASS NULL #endif -static char* FunctionBar_FKeys[] = {"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", NULL}; +static const char* FunctionBar_FKeys[] = {"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", NULL}; -static char* FunctionBar_FLabels[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", NULL}; +static const char* FunctionBar_FLabels[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", NULL}; static int FunctionBar_FEvents[] = {KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5), KEY_F(6), KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10)}; -FunctionBar* FunctionBar_new(char** functions, char** keys, int* events) { +FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* events) { FunctionBar* this = malloc(sizeof(FunctionBar)); Object_setClass(this, FUNCTIONBAR_CLASS); ((Object*) this)->delete = FunctionBar_delete; - this->functions = functions; + this->functions = (char**) functions; if (keys && events) { this->staticData = false; this->functions = malloc(sizeof(char*) * 15); @@ -60,8 +60,8 @@ FunctionBar* FunctionBar_new(char** functions, char** keys, int* events) { } } else { this->staticData = true; - this->functions = functions ? functions : FunctionBar_FLabels; - this->keys = FunctionBar_FKeys; + this->functions = (char**)( functions ? functions : FunctionBar_FLabels ); + this->keys = (char**) FunctionBar_FKeys; this->events = FunctionBar_FEvents; this->size = 10; } @@ -82,7 +82,7 @@ void FunctionBar_delete(Object* cast) { free(this); } -void FunctionBar_setLabel(FunctionBar* this, int event, char* text) { +void FunctionBar_setLabel(FunctionBar* this, int event, const char* text) { assert(!this->staticData); for (int i = 0; i < this->size; i++) { if (this->events[i] == event) { diff --git a/FunctionBar.h b/FunctionBar.h index ae84496b..afa96fde 100644 --- a/FunctionBar.h +++ b/FunctionBar.h @@ -37,11 +37,11 @@ extern char* FUNCTIONBAR_CLASS; #define FUNCTIONBAR_CLASS NULL #endif -FunctionBar* FunctionBar_new(char** functions, char** keys, int* events); +FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* events); void FunctionBar_delete(Object* cast); -void FunctionBar_setLabel(FunctionBar* this, int event, char* text); +void FunctionBar_setLabel(FunctionBar* this, int event, const char* text); void FunctionBar_draw(FunctionBar* this, char* buffer); diff --git a/HostnameMeter.c b/HostnameMeter.c index db3528c6..676f3f23 100644 --- a/HostnameMeter.c +++ b/HostnameMeter.c @@ -17,6 +17,7 @@ int HostnameMeter_attributes[] = { }; static void HostnameMeter_setValues(Meter* this, char* buffer, int size) { + (void) this; gethostname(buffer, size-1); } diff --git a/ListItem.c b/ListItem.c index 05754ac6..f6d6cc5f 100644 --- a/ListItem.c +++ b/ListItem.c @@ -44,7 +44,7 @@ static void ListItem_display(Object* cast, RichString* out) { RichString_write(out, CRT_colors[DEFAULT_COLOR], buffer); } -ListItem* ListItem_new(char* value, int key) { +ListItem* ListItem_new(const char* value, int key) { ListItem* this = malloc(sizeof(ListItem)); Object_setClass(this, LISTITEM_CLASS); ((Object*)this)->display = ListItem_display; diff --git a/ListItem.h b/ListItem.h index 9597a358..fea5db3e 100644 --- a/ListItem.h +++ b/ListItem.h @@ -30,7 +30,7 @@ extern char* LISTITEM_CLASS; #define LISTITEM_CLASS NULL #endif -ListItem* ListItem_new(char* value, int key); +ListItem* ListItem_new(const char* value, int key); void ListItem_append(ListItem* this, char* text); diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c index b692b9f6..e3eb1a78 100644 --- a/LoadAverageMeter.c +++ b/LoadAverageMeter.c @@ -21,10 +21,10 @@ int LoadMeter_attributes[] = { LOAD }; static inline void LoadAverageMeter_scan(double* one, double* five, double* fifteen) { int activeProcs, totalProcs, lastProc; FILE *fd = fopen(PROCDIR "/loadavg", "r"); - int read = fscanf(fd, "%lf %lf %lf %d/%d %d", one, five, fifteen, + int total = fscanf(fd, "%lf %lf %lf %d/%d %d", one, five, fifteen, &activeProcs, &totalProcs, &lastProc); - (void) read; - assert(read == 6); + (void) total; + assert(total == 6); fclose(fd); } diff --git a/MemoryMeter.c b/MemoryMeter.c index 43215eba..e7e33160 100644 --- a/MemoryMeter.c +++ b/MemoryMeter.c @@ -38,11 +38,11 @@ static void MemoryMeter_setValues(Meter* this, char* buffer, int size) { static void MemoryMeter_display(Object* cast, RichString* out) { char buffer[50]; Meter* this = (Meter*)cast; - int div = 1024; char* format = "%ldM "; - long int totalMem = this->total / div; - long int usedMem = this->values[0] / div; - long int buffersMem = this->values[1] / div; - long int cachedMem = this->values[2] / div; + int k = 1024; const char* format = "%ldM "; + long int totalMem = this->total / k; + long int usedMem = this->values[0] / k; + long int buffersMem = this->values[1] / k; + long int cachedMem = this->values[2] / k; RichString_init(out); RichString_append(out, CRT_colors[METER_TEXT], ":"); sprintf(buffer, format, totalMem); diff --git a/Meter.c b/Meter.c index 9c32d353..33df6e3d 100644 --- a/Meter.c +++ b/Meter.c @@ -42,7 +42,7 @@ typedef void(*Meter_Draw)(Meter*, int, int, int); struct MeterMode_ { Meter_Draw draw; - char* uiName; + const char* uiName; int h; }; @@ -53,9 +53,9 @@ struct MeterType_ { int items; double total; int* attributes; - char* name; - char* uiName; - char* caption; + const char* name; + const char* uiName; + const char* caption; MeterType_Init init; MeterType_Done done; MeterType_SetMode setMode; @@ -161,7 +161,7 @@ void Meter_delete(Object* cast) { free(this); } -void Meter_setCaption(Meter* this, char* caption) { +void Meter_setCaption(Meter* this, const char* caption) { free(this->caption); this->caption = strdup(caption); } @@ -325,7 +325,7 @@ static int GraphMeterMode_colors[21] = { GRAPH_8, GRAPH_8, GRAPH_9 }; -static char* GraphMeterMode_characters = "^`'-.,_~'`-.,_~'`-.,_"; +static const char* GraphMeterMode_characters = "^`'-.,_~'`-.,_~'`-.,_"; static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { @@ -345,15 +345,15 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { value /= this->total; drawBuffer[METER_BUFFER_LEN - 1] = value; for (int i = METER_BUFFER_LEN - w, k = 0; i < METER_BUFFER_LEN; i++, k++) { - double value = drawBuffer[i]; + value = drawBuffer[i]; DrawDot( CRT_colors[DEFAULT_COLOR], y, ' ' ); DrawDot( CRT_colors[DEFAULT_COLOR], y+1, ' ' ); DrawDot( CRT_colors[DEFAULT_COLOR], y+2, ' ' ); double threshold = 1.00; - for (int i = 0; i < 21; i++, threshold -= 0.05) + for (int j = 0; j < 21; j++, threshold -= 0.05) if (value >= threshold) { - DrawDot(CRT_colors[GraphMeterMode_colors[i]], y+(i/7.0), GraphMeterMode_characters[i]); + DrawDot(CRT_colors[GraphMeterMode_colors[j]], y+(j/7.0), GraphMeterMode_characters[j]); break; } } @@ -362,7 +362,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { /* ---------- LEDMeterMode ---------- */ -static char* LEDMeterMode_digits[3][10] = { +static const char* LEDMeterMode_digits[3][10] = { { " __ "," "," __ "," __ "," "," __ "," __ "," __ "," __ "," __ "}, { "| |"," |"," __|"," __|","|__|","|__ ","|__ "," |","|__|","|__|"}, { "|__|"," |","|__ "," __|"," |"," __|","|__|"," |","|__|"," __|"}, @@ -374,6 +374,7 @@ static void LEDMeterMode_drawDigit(int x, int y, int n) { } static void LEDMeterMode_draw(Meter* this, int x, int y, int w) { + (void) w; MeterType* type = this->type; char buffer[METER_BUFFER_LEN]; type->setValues(this, buffer, METER_BUFFER_LEN - 1); diff --git a/Meter.h b/Meter.h index fb2ec1ed..39c92768 100644 --- a/Meter.h +++ b/Meter.h @@ -44,7 +44,7 @@ typedef void(*Meter_Draw)(Meter*, int, int, int); struct MeterMode_ { Meter_Draw draw; - char* uiName; + const char* uiName; int h; }; @@ -55,9 +55,9 @@ struct MeterType_ { int items; double total; int* attributes; - char* name; - char* uiName; - char* caption; + const char* name; + const char* uiName; + const char* caption; MeterType_Init init; MeterType_Done done; MeterType_SetMode setMode; @@ -120,7 +120,7 @@ Meter* Meter_new(ProcessList* pl, int param, MeterType* type); void Meter_delete(Object* cast); -void Meter_setCaption(Meter* this, char* caption); +void Meter_setCaption(Meter* this, const char* caption); void Meter_setMode(Meter* this, int modeIndex); diff --git a/MetersPanel.c b/MetersPanel.c index 291164fb..26c2f75b 100644 --- a/MetersPanel.c +++ b/MetersPanel.c @@ -87,7 +87,7 @@ static HandlerResult MetersPanel_EventHandler(Panel* super, int ch) { return result; } -MetersPanel* MetersPanel_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr) { +MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr) { MetersPanel* this = (MetersPanel*) malloc(sizeof(MetersPanel)); Panel* super = (Panel*) this; Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true); diff --git a/MetersPanel.h b/MetersPanel.h index 674cf391..2e6d2253 100644 --- a/MetersPanel.h +++ b/MetersPanel.h @@ -21,6 +21,6 @@ typedef struct MetersPanel_ { } MetersPanel; -MetersPanel* MetersPanel_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr); +MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr); #endif diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index 3b7bfa92..2b047593 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -43,9 +43,9 @@ typedef struct OpenFilesScreen_ { }*/ -static char* tbFunctions[] = {"Refresh", "Done ", NULL}; +static const char* tbFunctions[] = {"Refresh", "Done ", NULL}; -static char* tbKeys[] = {"F5", "Esc"}; +static const char* tbKeys[] = {"F5", "Esc"}; static int tbEvents[] = {KEY_F(5), 27}; @@ -112,7 +112,7 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(int pid) { static void OpenFilesScreen_scan(OpenFilesScreen* this) { Panel* panel = this->display; - int index = MAX(Panel_getSelectedIndex(panel), 0); + int idx = MAX(Panel_getSelectedIndex(panel), 0); Panel_prune(panel); OpenFiles_ProcessData* process = OpenFilesScreen_getProcessData(this->process->pid); if (process->error == 127) { @@ -144,7 +144,7 @@ static void OpenFilesScreen_scan(OpenFilesScreen* this) { } free(process); Vector_sort(panel->items); - Panel_setSelected(panel, index); + Panel_setSelected(panel, idx); } void OpenFilesScreen_run(OpenFilesScreen* this) { diff --git a/Panel.c b/Panel.c index 3ae492e0..a9d2f60c 100644 --- a/Panel.c +++ b/Panel.c @@ -113,7 +113,7 @@ inline void Panel_setRichHeader(Panel* this, RichString header) { this->needsRedraw = true; } -inline void Panel_setHeader(Panel* this, char* header) { +inline void Panel_setHeader(Panel* this, const char* header) { Panel_setRichHeader(this, RichString_quickString(CRT_colors[PANEL_HEADER_FOCUS], header)); } diff --git a/Panel.h b/Panel.h index ba522b95..859de73d 100644 --- a/Panel.h +++ b/Panel.h @@ -76,7 +76,7 @@ void Panel_done(Panel* this); extern void Panel_setRichHeader(Panel* this, RichString header); -extern void Panel_setHeader(Panel* this, char* header); +extern void Panel_setHeader(Panel* this, const char* header); void Panel_setEventHandler(Panel* this, Panel_EventHandler eh); diff --git a/Process.c b/Process.c index a63f2671..ac02de02 100644 --- a/Process.c +++ b/Process.c @@ -73,16 +73,16 @@ typedef struct Process_ { struct ProcessList_ *pl; bool updated; - unsigned int pid; + pid_t pid; char* comm; int indent; char state; bool tag; - unsigned int ppid; + pid_t ppid; unsigned int pgrp; unsigned int session; unsigned int tty_nr; - unsigned int tgid; + pid_t tgid; int tpgid; unsigned long int flags; #ifdef DEBUG @@ -160,7 +160,7 @@ char* PROCESS_CLASS = "Process"; #define PROCESS_CLASS NULL #endif -char *Process_fieldNames[] = { +const char *Process_fieldNames[] = { "", "PID", "Command", "STATE", "PPID", "PGRP", "SESSION", "TTY_NR", "TPGID", "FLAGS", "MINFLT", "CMINFLT", "MAJFLT", "CMAJFLT", "UTIME", "STIME", "CUTIME", "CSTIME", "PRIORITY", "NICE", "ITREALVALUE", @@ -182,7 +182,7 @@ char *Process_fieldNames[] = { "*** report bug! ***" }; -char *Process_fieldTitles[] = { +const char *Process_fieldTitles[] = { "", " PID ", "Command ", "S ", " PPID ", " PGRP ", " SESN ", " TTY ", "TPGID ", "- ", "- ", "- ", "- ", "- ", " UTIME+ ", " STIME+ ", "- ", "- ", "PRI ", " NI ", "- ", @@ -198,7 +198,7 @@ char *Process_fieldTitles[] = { " VXID ", #endif #ifdef HAVE_TASKSTATS - " RD_CHAR ", " WR_CHAR ", " RD_SYSC ", " WR_SYSC ", " IO_RD ", " IO_WR ", " IO_CANCEL ", + " RD_CHAR ", " WR_CHAR ", " RD_SYSC ", " WR_SYSC ", " IO_RBYTES ", " IO_WBYTES ", " IO_CANCEL ", " IORR ", " IOWR ", " IO ", #endif }; @@ -367,7 +367,7 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel case M_SHARE: Process_printLargeNumber(this, str, this->m_share * PAGE_SIZE_KB); return; case ST_UID: snprintf(buffer, n, "%4d ", this->st_uid); break; case USER: { - if (Process_getuid != this->st_uid) + if (Process_getuid != (int) this->st_uid) attr = CRT_colors[PROCESS_SHADOW]; if (this->user) { snprintf(buffer, n, "%-8s ", this->user); @@ -435,7 +435,7 @@ static void Process_display(Object* cast, RichString* out) { RichString_init(out); for (int i = 0; fields[i]; i++) Process_writeField(this, out, fields[i]); - if (this->pl->shadowOtherUsers && this->st_uid != Process_getuid) + if (this->pl->shadowOtherUsers && (int)this->st_uid != Process_getuid) RichString_setAttr(out, CRT_colors[PROCESS_SHADOW]); if (this->tag == true) RichString_setAttr(out, CRT_colors[PROCESS_TAG]); @@ -467,7 +467,7 @@ Process* Process_new(struct ProcessList_ *pl) { } Process* Process_clone(Process* this) { - Process* clone = malloc(sizeof(Process)); + Process* copy = malloc(sizeof(Process)); #if HAVE_TASKSTATS this->io_rchar = 0; this->io_wchar = 0; @@ -481,10 +481,10 @@ Process* Process_clone(Process* this) { this->io_rate_write_time = 0; this->io_cancelled_write_bytes = 0; #endif - memcpy(clone, this, sizeof(Process)); + memcpy(copy, this, sizeof(Process)); this->comm = NULL; this->pid = 0; - return clone; + return copy; } void Process_toggleTag(Process* this) { @@ -512,8 +512,8 @@ bool Process_setAffinity(Process* this, unsigned long mask) { } #endif -void Process_sendSignal(Process* this, int signal) { - kill(this->pid, signal); +void Process_sendSignal(Process* this, int sgn) { + kill(this->pid, sgn); } int Process_pidCompare(const void* v1, const void* v2) { diff --git a/Process.h b/Process.h index c8019d7d..5cd8da40 100644 --- a/Process.h +++ b/Process.h @@ -46,7 +46,7 @@ in the source distribution for its full text. #ifndef Process_isThread -#define Process_isThread(process) (process->pid != process->tgid || process->m_size == 0) +#define Process_isThread(_process) (_process->pid != _process->tgid || _process->m_size == 0) #endif typedef enum ProcessField_ { @@ -75,16 +75,16 @@ typedef struct Process_ { struct ProcessList_ *pl; bool updated; - unsigned int pid; + pid_t pid; char* comm; int indent; char state; bool tag; - unsigned int ppid; + pid_t ppid; unsigned int pgrp; unsigned int session; unsigned int tty_nr; - unsigned int tgid; + pid_t tgid; int tpgid; unsigned long int flags; #ifdef DEBUG @@ -161,9 +161,9 @@ extern char* PROCESS_CLASS; #define PROCESS_CLASS NULL #endif -extern char *Process_fieldNames[]; +extern const char *Process_fieldNames[]; -extern char *Process_fieldTitles[]; +extern const char *Process_fieldTitles[]; #define ONE_K 1024 #define ONE_M (ONE_K * ONE_K) @@ -185,7 +185,7 @@ unsigned long Process_getAffinity(Process* this); bool Process_setAffinity(Process* this, unsigned long mask); #endif -void Process_sendSignal(Process* this, int signal); +void Process_sendSignal(Process* this, int sgn); int Process_pidCompare(const void* v1, const void* v2); diff --git a/ProcessList.c b/ProcessList.c index 25ea4ff8..f3845d63 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -27,6 +27,7 @@ in the source distribution for its full text. #include #include #include +#include #include "debug.h" #include @@ -699,6 +700,7 @@ static bool ProcessList_processEntries(ProcessList* this, const char* dirname, P int percent_cpu = (process->utime + process->stime - lasttimes) / period * 100.0; process->percent_cpu = MAX(MIN(percent_cpu, processors*100.0), 0.0); + if (isnan(process->percent_cpu)) process->percent_cpu = 0.0; process->percent_mem = (process->m_resident * PAGE_SIZE_KB) / (float)(this->totalMem) * diff --git a/ProcessList.h b/ProcessList.h index 6ce807d0..509dfce0 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -30,6 +30,7 @@ in the source distribution for its full text. #include #include #include +#include #include "debug.h" #include diff --git a/RichString.c b/RichString.c index 753c8cfa..a62a053a 100644 --- a/RichString.c +++ b/RichString.c @@ -52,7 +52,7 @@ typedef struct RichString_ { #ifdef HAVE_LIBNCURSESW -inline void RichString_appendn(RichString* this, int attrs, char* data_c, int len) { +inline void RichString_appendn(RichString* this, int attrs, const char* data_c, int len) { wchar_t data[RICHSTRING_MAXLEN]; len = mbstowcs(data, data_c, RICHSTRING_MAXLEN); if (len<0) @@ -88,7 +88,7 @@ int RichString_findChar(RichString *this, char c, int start) { #else -inline void RichString_appendn(RichString* this, int attrs, char* data_c, int len) { +inline void RichString_appendn(RichString* this, int attrs, const char* data_c, int len) { int last = MIN(RICHSTRING_MAXLEN - 1, len + this->len); for (int i = this->len, j = 0; i < last; i++, j++) this->chstr[i] = (isprint(data_c[j]) ? data_c[j] : '?') | attrs; @@ -108,7 +108,7 @@ void RichString_setAttrn(RichString *this, int attrs, int start, int finish) { int RichString_findChar(RichString *this, char c, int start) { chtype* ch = this->chstr + start; for (int i = start; i < this->len; i++) { - if ((*ch & 0xff) == c) + if ((*ch & 0xff) == (chtype) c) return i; ch++; } @@ -125,16 +125,16 @@ void RichString_setAttr(RichString *this, int attrs) { RichString_setAttrn(this, attrs, 0, this->len - 1); } -inline void RichString_append(RichString* this, int attrs, char* data) { +inline void RichString_append(RichString* this, int attrs, const char* data) { RichString_appendn(this, attrs, data, strlen(data)); } -void RichString_write(RichString* this, int attrs, char* data) { +void RichString_write(RichString* this, int attrs, const char* data) { RichString_init(this); RichString_append(this, attrs, data); } -RichString RichString_quickString(int attrs, char* data) { +RichString RichString_quickString(int attrs, const char* data) { RichString str; RichString_initVal(str); RichString_write(&str, attrs, data); diff --git a/RichString.h b/RichString.h index 994f504f..7b2de38e 100644 --- a/RichString.h +++ b/RichString.h @@ -53,7 +53,7 @@ typedef struct RichString_ { #ifdef HAVE_LIBNCURSESW -extern void RichString_appendn(RichString* this, int attrs, char* data_c, int len); +extern void RichString_appendn(RichString* this, int attrs, const char* data_c, int len); extern void RichString_setAttrn(RichString *this, int attrs, int start, int finish); @@ -61,7 +61,7 @@ int RichString_findChar(RichString *this, char c, int start); #else -extern void RichString_appendn(RichString* this, int attrs, char* data_c, int len); +extern void RichString_appendn(RichString* this, int attrs, const char* data_c, int len); void RichString_setAttrn(RichString *this, int attrs, int start, int finish); @@ -73,10 +73,10 @@ void RichString_prune(RichString* this); void RichString_setAttr(RichString *this, int attrs); -extern void RichString_append(RichString* this, int attrs, char* data); +extern void RichString_append(RichString* this, int attrs, const char* data); -void RichString_write(RichString* this, int attrs, char* data); +void RichString_write(RichString* this, int attrs, const char* data); -RichString RichString_quickString(int attrs, char* data); +RichString RichString_quickString(int attrs, const char* data); #endif diff --git a/ScreenManager.c b/ScreenManager.c index 536ff03d..a3ec8e62 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -89,10 +89,10 @@ void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int this->itemCount++; } -Panel* ScreenManager_remove(ScreenManager* this, int index) { - assert(this->itemCount > index); - Panel* panel = (Panel*) Vector_remove(this->items, index); - Vector_remove(this->fuBars, index); +Panel* ScreenManager_remove(ScreenManager* this, int idx) { + assert(this->itemCount > idx); + Panel* panel = (Panel*) Vector_remove(this->items, idx); + Vector_remove(this->fuBars, idx); this->fuBar = NULL; this->itemCount--; return panel; diff --git a/ScreenManager.h b/ScreenManager.h index 699aa0c3..1b80e356 100644 --- a/ScreenManager.h +++ b/ScreenManager.h @@ -47,7 +47,7 @@ extern int ScreenManager_size(ScreenManager* this); void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int size); -Panel* ScreenManager_remove(ScreenManager* this, int index); +Panel* ScreenManager_remove(ScreenManager* this, int idx); void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2); diff --git a/SignalItem.c b/SignalItem.c index 4d6df589..21b56dc3 100644 --- a/SignalItem.c +++ b/SignalItem.c @@ -19,7 +19,7 @@ in the source distribution for its full text. typedef struct Signal_ { Object super; - char* name; + const char* name; int number; } Signal; @@ -47,7 +47,7 @@ static void Signal_display(Object* cast, RichString* out) { RichString_write(out, CRT_colors[DEFAULT_COLOR], buffer); } -static Signal* Signal_new(char* name, int number) { +static Signal* Signal_new(const char* name, int number) { Signal* this = malloc(sizeof(Signal)); Object_setClass(this, SIGNAL_CLASS); ((Object*)this)->display = Signal_display; diff --git a/SignalItem.h b/SignalItem.h index 17cb0e02..865abc3f 100644 --- a/SignalItem.h +++ b/SignalItem.h @@ -21,7 +21,7 @@ in the source distribution for its full text. typedef struct Signal_ { Object super; - char* name; + const char* name; int number; } Signal; diff --git a/SignalsPanel.c b/SignalsPanel.c index 2d1e967b..83dfda86 100644 --- a/SignalsPanel.c +++ b/SignalsPanel.c @@ -26,13 +26,13 @@ static HandlerResult SignalsPanel_eventHandler(Panel* super, int ch) { int size = Panel_size(super); if (ch <= 255 && isdigit(ch)) { - int signal = ch-48 + this->state; + int sgn = ch-48 + this->state; for (int i = 0; i < size; i++) - if (((Signal*) Panel_get(super, i))->number == signal) { + if (((Signal*) Panel_get(super, i))->number == sgn) { Panel_setSelected(super, i); break; } - this->state = signal * 10; + this->state = sgn * 10; if (this->state > 100) this->state = 0; return HANDLED; diff --git a/String.c b/String.c index 99b27707..76f21f1d 100644 --- a/String.c +++ b/String.c @@ -18,11 +18,11 @@ in the source distribution for its full text. #define String_startsWith(s, match) (strstr((s), (match)) == (s)) }*/ -inline char* String_copy(char* orig) { +inline char* String_copy(const char* orig) { return strdup(orig); } -char* String_cat(char* s1, char* s2) { +char* String_cat(const char* s1, const char* s2) { int l1 = strlen(s1); int l2 = strlen(s2); char* out = malloc(l1 + l2 + 1); @@ -31,7 +31,7 @@ char* String_cat(char* s1, char* s2) { return out; } -char* String_trim(char* in) { +char* String_trim(const char* in) { while (in[0] == ' ' || in[0] == '\t' || in[0] == '\n') { in++; } @@ -55,7 +55,7 @@ inline int String_eq(const char* s1, const char* s2) { return (strcmp(s1, s2) == 0); } -char** String_split(char* s, char sep) { +char** String_split(const char* s, char sep) { const int rate = 10; char** out = (char**) malloc(sizeof(char*) * rate); int ctr = 0; @@ -93,7 +93,7 @@ void String_freeArray(char** s) { free(s); } -int String_contains_i(char* s, char* match) { +int String_contains_i(const char* s, const char* match) { int lens = strlen(s); int lenmatch = strlen(match); for (int i = 0; i < lens-lenmatch; i++) { diff --git a/String.h b/String.h index 82c958f0..9ffd30cf 100644 --- a/String.h +++ b/String.h @@ -19,19 +19,19 @@ in the source distribution for its full text. #define String_startsWith(s, match) (strstr((s), (match)) == (s)) -extern char* String_copy(char* orig); +extern char* String_copy(const char* orig); -char* String_cat(char* s1, char* s2); +char* String_cat(const char* s1, const char* s2); -char* String_trim(char* in); +char* String_trim(const char* in); extern int String_eq(const char* s1, const char* s2); -char** String_split(char* s, char sep); +char** String_split(const char* s, char sep); void String_freeArray(char** s); -int String_contains_i(char* s, char* match); +int String_contains_i(const char* s, const char* match); char* String_getToken(const char* line, const unsigned short int numMatch); diff --git a/TraceScreen.c b/TraceScreen.c index 19254f99..c843e749 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -32,9 +32,9 @@ typedef struct TraceScreen_ { }*/ -static char* tbFunctions[] = {"AutoScroll ", "Stop Tracing ", "Done ", NULL}; +static const char* tbFunctions[] = {"AutoScroll ", "Stop Tracing ", "Done ", NULL}; -static char* tbKeys[] = {"F4", "F5", "Esc"}; +static const char* tbKeys[] = {"F4", "F5", "Esc"}; static int tbEvents[] = {KEY_F(4), KEY_F(5), 27}; diff --git a/Vector.c b/Vector.c index e2da1eeb..a4c03df4 100644 --- a/Vector.c +++ b/Vector.c @@ -127,37 +127,37 @@ static void Vector_checkArraySize(Vector* this) { assert(Vector_isConsistent(this)); } -void Vector_insert(Vector* this, int index, void* data_) { - assert(index >= 0); +void Vector_insert(Vector* this, int idx, void* data_) { + assert(idx >= 0); assert(((Object*)data_)->class == this->vectorType); Object* data = data_; assert(Vector_isConsistent(this)); Vector_checkArraySize(this); assert(this->array[this->items] == NULL); - for (int i = this->items; i >= index; i--) { + for (int i = this->items; i >= idx; i--) { this->array[i+1] = this->array[i]; } - this->array[index] = data; + this->array[idx] = data; this->items++; assert(Vector_isConsistent(this)); } -Object* Vector_take(Vector* this, int index) { - assert(index >= 0 && index < this->items); +Object* Vector_take(Vector* this, int idx) { + assert(idx >= 0 && idx < this->items); assert(Vector_isConsistent(this)); - Object* removed = this->array[index]; + Object* removed = this->array[idx]; assert (removed != NULL); this->items--; - for (int i = index; i < this->items; i++) + for (int i = idx; i < this->items; i++) this->array[i] = this->array[i+1]; this->array[this->items] = NULL; assert(Vector_isConsistent(this)); return removed; } -Object* Vector_remove(Vector* this, int index) { - Object* removed = Vector_take(this, index); +Object* Vector_remove(Vector* this, int idx) { + Object* removed = Vector_take(this, idx); if (this->owner) { removed->delete(removed); return NULL; @@ -165,52 +165,52 @@ Object* Vector_remove(Vector* this, int index) { return removed; } -void Vector_moveUp(Vector* this, int index) { - assert(index >= 0 && index < this->items); +void Vector_moveUp(Vector* this, int idx) { + assert(idx >= 0 && idx < this->items); assert(Vector_isConsistent(this)); - if (index == 0) + if (idx == 0) return; - Object* temp = this->array[index]; - this->array[index] = this->array[index - 1]; - this->array[index - 1] = temp; + Object* temp = this->array[idx]; + this->array[idx] = this->array[idx - 1]; + this->array[idx - 1] = temp; } -void Vector_moveDown(Vector* this, int index) { - assert(index >= 0 && index < this->items); +void Vector_moveDown(Vector* this, int idx) { + assert(idx >= 0 && idx < this->items); assert(Vector_isConsistent(this)); - if (index == this->items - 1) + if (idx == this->items - 1) return; - Object* temp = this->array[index]; - this->array[index] = this->array[index + 1]; - this->array[index + 1] = temp; + Object* temp = this->array[idx]; + this->array[idx] = this->array[idx + 1]; + this->array[idx + 1] = temp; } -void Vector_set(Vector* this, int index, void* data_) { - assert(index >= 0); +void Vector_set(Vector* this, int idx, void* data_) { + assert(idx >= 0); assert(((Object*)data_)->class == this->vectorType); Object* data = data_; assert(Vector_isConsistent(this)); Vector_checkArraySize(this); - if (index >= this->items) { - this->items = index+1; + if (idx >= this->items) { + this->items = idx+1; } else { if (this->owner) { - Object* removed = this->array[index]; + Object* removed = this->array[idx]; assert (removed != NULL); if (this->owner) { removed->delete(removed); } } } - this->array[index] = data; + this->array[idx] = data; assert(Vector_isConsistent(this)); } -inline Object* Vector_get(Vector* this, int index) { - assert(index < this->items); +inline Object* Vector_get(Vector* this, int idx) { + assert(idx < this->items); assert(Vector_isConsistent(this)); - return this->array[index]; + return this->array[idx]; } inline int Vector_size(Vector* this) { diff --git a/Vector.h b/Vector.h index b8010bfc..d04f9a5c 100644 --- a/Vector.h +++ b/Vector.h @@ -49,19 +49,19 @@ void Vector_prune(Vector* this); void Vector_sort(Vector* this); -void Vector_insert(Vector* this, int index, void* data_); +void Vector_insert(Vector* this, int idx, void* data_); -Object* Vector_take(Vector* this, int index); +Object* Vector_take(Vector* this, int idx); -Object* Vector_remove(Vector* this, int index); +Object* Vector_remove(Vector* this, int idx); -void Vector_moveUp(Vector* this, int index); +void Vector_moveUp(Vector* this, int idx); -void Vector_moveDown(Vector* this, int index); +void Vector_moveDown(Vector* this, int idx); -void Vector_set(Vector* this, int index, void* data_); +void Vector_set(Vector* this, int idx, void* data_); -extern Object* Vector_get(Vector* this, int index); +extern Object* Vector_get(Vector* this, int idx); extern int Vector_size(Vector* this); diff --git a/htop.c b/htop.c index fee60928..df1d1085 100644 --- a/htop.c +++ b/htop.c @@ -151,7 +151,7 @@ static void showHelp(ProcessList* pl) { clear(); } -static char* CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; +static const char* CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; static void Setup_run(Settings* settings, int headerHeight) { ScreenManager* scr = ScreenManager_new(0, headerHeight, 0, -1, HORIZONTAL, true); @@ -184,13 +184,14 @@ static bool changePriority(Panel* panel, int delta) { } static HandlerResult pickWithEnter(Panel* panel, int ch) { + (void) panel; if (ch == 13) return BREAK_LOOP; return IGNORED; } -static Object* pickFromVector(Panel* panel, Panel* list, int x, int y, char** keyLabels, FunctionBar* prevBar) { - char* fuKeys[] = {"Enter", "Esc", NULL}; +static Object* pickFromVector(Panel* panel, Panel* list, int x, int y, const char** keyLabels, FunctionBar* prevBar) { + const char* fuKeys[] = {"Enter", "Esc", NULL}; int fuEvents[] = {13, 27}; if (!list->eventHandler) Panel_setEventHandler(list, pickWithEnter); @@ -325,12 +326,12 @@ int main(int argc, char** argv) { } Panel_setRichHeader(panel, ProcessList_printHeader(pl)); - char* searchFunctions[] = {"Next ", "Exit ", " Search: ", NULL}; - char* searchKeys[] = {"F3", "Esc", " "}; + const char* searchFunctions[] = {"Next ", "Exit ", " Search: ", NULL}; + const char* searchKeys[] = {"F3", "Esc", " "}; int searchEvents[] = {KEY_F(3), 27, ERR}; FunctionBar* searchBar = FunctionBar_new(searchFunctions, searchKeys, searchEvents); - char* defaultFunctions[] = {"Help ", "Setup ", "Search", "Invert", "Tree ", + const char* defaultFunctions[] = {"Help ", "Setup ", "Search", "Invert", "Tree ", "SortBy", "Nice -", "Nice +", "Kill ", "Quit ", NULL}; FunctionBar* defaultBar = FunctionBar_new(defaultFunctions, NULL, NULL); @@ -358,7 +359,7 @@ int main(int argc, char** argv) { oldTime = newTime; if (doRefresh) { int currPos = Panel_getSelectedIndex(panel); - unsigned int currPid = 0; + pid_t currPid = 0; int currScrollV = panel->scrollV; if (follow) currPid = ProcessList_get(pl, currPos)->pid; @@ -372,16 +373,16 @@ int main(int argc, char** argv) { } Panel_prune(panel); int size = ProcessList_size(pl); - int index = 0; + int idx = 0; for (int i = 0; i < size; i++) { Process* p = ProcessList_get(pl, i); if (!userOnly || (p->st_uid == userId)) { - Panel_set(panel, index, (Object*)p); - if ((!follow && index == currPos) || (follow && p->pid == currPid)) { - Panel_setSelected(panel, index); + Panel_set(panel, idx, (Object*)p); + if ((!follow && idx == currPos) || (follow && p->pid == currPid)) { + Panel_setSelected(panel, idx); panel->scrollV = currScrollV; } - index++; + idx++; } } } @@ -452,7 +453,7 @@ int main(int argc, char** argv) { continue; } if (isdigit((char)ch)) { - unsigned int pid = ch-48 + acc; + pid_t pid = ch-48 + acc; for (int i = 0; i < ProcessList_size(pl) && ((Process*) Panel_getSelected(panel))->pid != pid; i++) Panel_setSelected(panel, i); acc = pid * 10; @@ -600,7 +601,7 @@ int main(int argc, char** argv) { Vector_sort(usersPanel->items); ListItem* allUsers = ListItem_new("All users", -1); Panel_insert(usersPanel, 0, (Object*) allUsers); - char* fuFunctions[] = {"Show ", "Cancel ", NULL}; + const char* fuFunctions[] = {"Show ", "Cancel ", NULL}; ListItem* picked = (ListItem*) pickFromVector(panel, usersPanel, 20, headerHeight, fuFunctions, defaultBar); if (picked) { if (picked == allUsers) { @@ -619,10 +620,10 @@ int main(int argc, char** argv) { killPanel = (Panel*) SignalsPanel_new(0, 0, 0, 0); } SignalsPanel_reset((SignalsPanel*) killPanel); - char* fuFunctions[] = {"Send ", "Cancel ", NULL}; - Signal* signal = (Signal*) pickFromVector(panel, killPanel, 15, headerHeight, fuFunctions, defaultBar); - if (signal) { - if (signal->number != 0) { + const char* fuFunctions[] = {"Send ", "Cancel ", NULL}; + Signal* sgn = (Signal*) pickFromVector(panel, killPanel, 15, headerHeight, fuFunctions, defaultBar); + if (sgn) { + if (sgn->number != 0) { Panel_setHeader(panel, "Sending..."); Panel_draw(panel, true); refresh(); @@ -630,13 +631,13 @@ int main(int argc, char** argv) { for (int i = 0; i < Panel_size(panel); i++) { Process* p = (Process*) Panel_get(panel, i); if (p->tag) { - Process_sendSignal(p, signal->number); + Process_sendSignal(p, sgn->number); anyTagged = true; } } if (!anyTagged) { Process* p = (Process*) Panel_getSelected(panel); - Process_sendSignal(p, signal->number); + Process_sendSignal(p, sgn->number); } napms(500); } @@ -651,12 +652,11 @@ int main(int argc, char** argv) { if (pl->processorCount == 1) break; - Process* p = (Process*) Panel_getSelected(panel); - unsigned long curr = Process_getAffinity(p); + unsigned long curr = Process_getAffinity((Process*) Panel_getSelected(panel)); Panel* affinityPanel = AffinityPanel_new(pl->processorCount, curr); - char* fuFunctions[] = {"Set ", "Cancel ", NULL}; + const char* fuFunctions[] = {"Set ", "Cancel ", NULL}; void* set = pickFromVector(panel, affinityPanel, 15, headerHeight, fuFunctions, defaultBar); if (set) { unsigned long new = AffinityPanel_getAffinity(affinityPanel); @@ -695,7 +695,7 @@ int main(int argc, char** argv) { { Panel* sortPanel = Panel_new(0, 0, 0, 0, LISTITEM_CLASS, true, ListItem_compare); Panel_setHeader(sortPanel, "Sort by"); - char* fuFunctions[] = {"Sort ", "Cancel ", NULL}; + const char* fuFunctions[] = {"Sort ", "Cancel ", NULL}; ProcessField* fields = pl->fields; for (int i = 0; fields[i]; i++) { char* name = String_trim(Process_fieldTitles[fields[i]]); -- cgit v1.2.3