From e2b58f0ab81b2aafeb8c29a69abad7829fa21ab3 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 11 Apr 2016 13:00:30 +0200 Subject: Imported Upstream version 1.0.1 --- Affinity.c | 8 +- Affinity.h | 9 +- AffinityPanel.c | 20 ++++- AffinityPanel.h | 14 +-- AvailableColumnsPanel.c | 20 +++-- AvailableColumnsPanel.h | 15 ++-- AvailableMetersPanel.c | 19 ++-- AvailableMetersPanel.h | 15 ++-- BatteryMeter.c | 52 +++++------ BatteryMeter.h | 15 ++-- CPUMeter.c | 8 +- CPUMeter.h | 10 --- CRT.c | 14 ++- CRT.h | 14 +-- CategoriesPanel.c | 14 ++- CategoriesPanel.h | 19 ++-- ChangeLog | 13 +++ CheckItem.c | 8 +- CheckItem.h | 6 +- ClockMeter.c | 9 +- ClockMeter.h | 6 +- ColorsPanel.c | 21 +++-- ColorsPanel.h | 19 ++-- ColumnsPanel.c | 19 ++-- ColumnsPanel.h | 11 +-- DebugMemory.c | 230 ------------------------------------------------ DebugMemory.h | 70 --------------- DisplayOptionsPanel.c | 37 ++++---- DisplayOptionsPanel.h | 12 +-- FunctionBar.c | 11 ++- FunctionBar.h | 10 --- Hashtable.c | 7 +- Hashtable.h | 7 +- Header.c | 18 +++- Header.h | 6 +- HostnameMeter.c | 9 +- HostnameMeter.h | 6 +- ListItem.c | 11 ++- ListItem.h | 6 -- LoadAverageMeter.c | 10 ++- LoadAverageMeter.h | 6 +- Makefile.am | 23 ++--- Makefile.in | 67 +++++--------- MemoryMeter.c | 10 ++- MemoryMeter.h | 13 +-- Meter.c | 32 ++++--- Meter.h | 29 +----- MetersPanel.c | 15 ++-- MetersPanel.h | 11 +-- Object.c | 8 +- Object.h | 9 +- OpenFilesScreen.c | 15 ++-- OpenFilesScreen.h | 12 --- Panel.c | 13 +-- Panel.h | 16 +--- Process.c | 30 ++++--- Process.h | 27 +----- ProcessList.c | 84 ++++++++++++++---- ProcessList.h | 37 +++----- RichString.c | 21 ++--- RichString.h | 17 ++-- ScreenManager.c | 76 +++++++++------- ScreenManager.h | 18 ++-- Settings.c | 71 ++++++++++----- Settings.h | 9 +- SignalsPanel.c | 11 ++- SignalsPanel.h | 14 ++- String.c | 12 +-- String.h | 11 +-- SwapMeter.c | 10 ++- SwapMeter.h | 13 +-- TasksMeter.c | 8 +- TasksMeter.h | 8 +- TraceScreen.c | 16 ++-- TraceScreen.h | 12 --- UptimeMeter.c | 10 ++- UptimeMeter.h | 8 +- UsersTable.c | 12 +-- UsersTable.h | 9 -- Vector.c | 9 +- Vector.h | 9 +- config.h | 6 +- configure | 37 ++++---- configure.ac | 15 ++-- debug.h | 28 ------ htop.1 | 2 +- htop.c | 95 +++++++++----------- htop.h | 27 ------ scripts/MakeHeader.py | 12 +++ 89 files changed, 746 insertions(+), 1145 deletions(-) delete mode 100644 DebugMemory.c delete mode 100644 DebugMemory.h delete mode 100644 debug.h diff --git a/Affinity.c b/Affinity.c index 0b2bd46..ce30aed 100644 --- a/Affinity.c +++ b/Affinity.c @@ -1,6 +1,12 @@ +/* +htop - Affinity.c +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ -#include "config.h" #include "Affinity.h" + #include /*{ diff --git a/Affinity.h b/Affinity.h index 0f74bf5..3a19ea4 100644 --- a/Affinity.h +++ b/Affinity.h @@ -2,9 +2,12 @@ #ifndef HEADER_Affinity #define HEADER_Affinity - -#include "config.h" -#include +/* +htop - Affinity.h +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ typedef struct Affinity_ { diff --git a/AffinityPanel.c b/AffinityPanel.c index 404104a..729eec4 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -1,11 +1,23 @@ +/* +htop - AffinityPanel.c +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ -#include "ProcessList.h" #include "AffinityPanel.h" -#include "Panel.h" + #include "CheckItem.h" -#include "debug.h" #include +#include + +/*{ +#include "Panel.h" +#include "Affinity.h" +#include "ProcessList.h" +#include "ListItem.h" +}*/ static HandlerResult AffinityPanel_eventHandler(Panel* this, int ch) { CheckItem* selected = (CheckItem*) Panel_getSelected(this); @@ -38,7 +50,7 @@ Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity) { } else { mode = false; } - Panel_add(this, (Object*) CheckItem_new(String_copy(number), NULL, mode)); + Panel_add(this, (Object*) CheckItem_new(strdup(number), NULL, mode)); } return this; } diff --git a/AffinityPanel.h b/AffinityPanel.h index 8ab3963..392a259 100644 --- a/AffinityPanel.h +++ b/AffinityPanel.h @@ -2,13 +2,17 @@ #ifndef HEADER_AffinityPanel #define HEADER_AffinityPanel +/* +htop - AffinityPanel.h +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ -#include "ProcessList.h" #include "Panel.h" -#include "CheckItem.h" - -#include "debug.h" -#include +#include "Affinity.h" +#include "ProcessList.h" +#include "ListItem.h" Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity); diff --git a/AvailableColumnsPanel.c b/AvailableColumnsPanel.c index c0b6af1..fce9880 100644 --- a/AvailableColumnsPanel.c +++ b/AvailableColumnsPanel.c @@ -1,16 +1,23 @@ +/* +htop - AvailableColumnsPanel.c +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ #include "AvailableColumnsPanel.h" -#include "Settings.h" + #include "Header.h" -#include "ScreenManager.h" #include "ColumnsPanel.h" -#include "Panel.h" - -#include "debug.h" #include +#include +#include /*{ +#include "Panel.h" +#include "Settings.h" +#include "ScreenManager.h" typedef struct AvailableColumnsPanel_ { Panel super; @@ -48,7 +55,8 @@ static HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) { } default: { - result = Panel_selectByTyping(super, ch); + if (isalpha(ch)) + result = Panel_selectByTyping(super, ch); break; } } diff --git a/AvailableColumnsPanel.h b/AvailableColumnsPanel.h index d07acf8..6a32f9f 100644 --- a/AvailableColumnsPanel.h +++ b/AvailableColumnsPanel.h @@ -2,17 +2,16 @@ #ifndef HEADER_AvailableColumnsPanel #define HEADER_AvailableColumnsPanel +/* +htop - AvailableColumnsPanel.h +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ +#include "Panel.h" #include "Settings.h" -#include "Header.h" #include "ScreenManager.h" -#include "ColumnsPanel.h" - -#include "Panel.h" - -#include "debug.h" -#include - typedef struct AvailableColumnsPanel_ { Panel super; diff --git a/AvailableMetersPanel.c b/AvailableMetersPanel.c index cfed46e..0cdb508 100644 --- a/AvailableMetersPanel.c +++ b/AvailableMetersPanel.c @@ -1,16 +1,23 @@ +/* +htop - AvailableMetersPanel.c +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ #include "AvailableMetersPanel.h" -#include "Settings.h" -#include "Header.h" -#include "ScreenManager.h" -#include "CPUMeter.h" -#include "Panel.h" +#include "CPUMeter.h" +#include "Header.h" +#include "ListItem.h" -#include "debug.h" #include +#include /*{ +#include "Settings.h" +#include "Panel.h" +#include "ScreenManager.h" typedef struct AvailableMetersPanel_ { Panel super; diff --git a/AvailableMetersPanel.h b/AvailableMetersPanel.h index 25d4c08..c34f0b2 100644 --- a/AvailableMetersPanel.h +++ b/AvailableMetersPanel.h @@ -2,17 +2,16 @@ #ifndef HEADER_AvailableMetersPanel #define HEADER_AvailableMetersPanel +/* +htop - AvailableMetersPanel.h +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ #include "Settings.h" -#include "Header.h" -#include "ScreenManager.h" -#include "CPUMeter.h" - #include "Panel.h" - -#include "debug.h" -#include - +#include "ScreenManager.h" typedef struct AvailableMetersPanel_ { Panel super; diff --git a/BatteryMeter.c b/BatteryMeter.c index f7323aa..071efd5 100644 --- a/BatteryMeter.c +++ b/BatteryMeter.c @@ -1,20 +1,25 @@ /* - htop - (C) 2004-2011 Hisham H. Muhammad - Released under the GNU GPL, see the COPYING file - in the source distribution for its full text. +htop - BatteryMeter.c +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. - This "Meter" written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). +This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). */ #include "BatteryMeter.h" -#include "Meter.h" + #include "ProcessList.h" #include "CRT.h" #include "String.h" -#include "debug.h" + +#include +#include +#include +#include /*{ +#include "Meter.h" typedef enum ACPresence_ { AC_ABSENT, @@ -45,17 +50,11 @@ static unsigned long int parseUevent(FILE * file, const char *key) { } static unsigned long int parseBatInfo(const char *fileName, const unsigned short int lineNum, const unsigned short int wordNum) { - DIR* batteryDir; - const struct dirent *dirEntries; - const char batteryPath[] = PROCDIR "/acpi/battery/"; - batteryDir = opendir(batteryPath); - - if (batteryDir == NULL) { + DIR* batteryDir = opendir(batteryPath); + if (!batteryDir) return 0; - } - char *entryName; typedef struct listLbl { char *content; struct listLbl *next; @@ -68,8 +67,8 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short Some of this is based off of code found in kismet (they claim it came from gkrellm). Written for multi battery use... */ - for (dirEntries = readdir((DIR *) batteryDir); dirEntries; dirEntries = readdir((DIR *) batteryDir)) { - entryName = (char *) dirEntries->d_name; + for (const struct dirent* dirEntries = readdir((DIR *) batteryDir); dirEntries; dirEntries = readdir((DIR *) batteryDir)) { + char* entryName = (char *) dirEntries->d_name; if (strncmp(entryName, "BAT", 3)) continue; @@ -117,22 +116,16 @@ static ACPresence chkIsOnline() { ACPresence isOn = AC_ERROR; if (access(PROCDIR "/acpi/ac_adapter", F_OK) == 0) { - const struct dirent *dirEntries; const char *power_supplyPath = PROCDIR "/acpi/ac_adapter"; DIR *power_supplyDir = opendir(power_supplyPath); - char *entryName; - - if (!power_supplyDir) { + if (!power_supplyDir) return AC_ERROR; - } - for (dirEntries = readdir((DIR *) power_supplyDir); dirEntries; dirEntries = readdir((DIR *) power_supplyDir)) { - entryName = (char *) dirEntries->d_name; + for (const struct dirent *dirEntries = readdir((DIR *) power_supplyDir); dirEntries; dirEntries = readdir((DIR *) power_supplyDir)) { + char* entryName = (char *) dirEntries->d_name; - if (strncmp(entryName, "A", 1)) { + if (entryName[0] != 'A') continue; - } - char statePath[50]; snprintf((char *) statePath, sizeof statePath, "%s/%s/state", power_supplyPath, entryName); @@ -242,11 +235,8 @@ static double getSysBatData() { const struct dirent *dirEntries; const char *power_supplyPath = "/sys/class/power_supply/"; DIR *power_supplyDir = opendir(power_supplyPath); - - - if (!power_supplyDir) { + if (!power_supplyDir) return 0; - } char *entryName; diff --git a/BatteryMeter.h b/BatteryMeter.h index 9bef8df..56ed951 100644 --- a/BatteryMeter.h +++ b/BatteryMeter.h @@ -3,20 +3,15 @@ #ifndef HEADER_BatteryMeter #define HEADER_BatteryMeter /* - htop - (C) 2004-2011 Hisham H. Muhammad - Released under the GNU GPL, see the COPYING file - in the source distribution for its full text. +htop - BatteryMeter.h +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. - This "Meter" written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). +This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). */ #include "Meter.h" -#include "ProcessList.h" -#include "CRT.h" -#include "String.h" -#include "debug.h" - typedef enum ACPresence_ { AC_ABSENT, diff --git a/CPUMeter.c b/CPUMeter.c index f2a4fe3..90555ff 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -6,17 +6,19 @@ in the source distribution for its full text. */ #include "CPUMeter.h" -#include "Meter.h" +#include "CRT.h" #include "ProcessList.h" +#include #include #include #include #include -#include "debug.h" -#include +/*{ +#include "Meter.h" +}*/ int CPUMeter_attributes[] = { CPU_NICE, CPU_NORMAL, CPU_KERNEL, CPU_IRQ, CPU_SOFTIRQ, CPU_IOWAIT, CPU_STEAL, CPU_GUEST diff --git a/CPUMeter.h b/CPUMeter.h index 47ef888..251fbdc 100644 --- a/CPUMeter.h +++ b/CPUMeter.h @@ -11,16 +11,6 @@ in the source distribution for its full text. #include "Meter.h" -#include "ProcessList.h" - -#include -#include -#include -#include - -#include "debug.h" -#include - extern int CPUMeter_attributes[]; #ifndef MIN diff --git a/CRT.c b/CRT.c index 949b543..621adfc 100644 --- a/CRT.c +++ b/CRT.c @@ -7,19 +7,16 @@ in the source distribution for its full text. #include "CRT.h" +#include "config.h" +#include "String.h" + #include #include #include -#include #ifdef HAVE_EXECINFO_H #include #endif -#include "String.h" - -#include "config.h" -#include "debug.h" - #define ColorPair(i,j) COLOR_PAIR((7-i)*8+j) #define COLORSCHEME_DEFAULT 0 @@ -40,9 +37,8 @@ in the source distribution for its full text. //#link curses -bool CRT_hasColors; - /*{ +#include typedef enum ColorElements_ { RESET_COLOR, @@ -112,6 +108,8 @@ typedef enum ColorElements_ { // TODO: centralize these in Settings. +static bool CRT_hasColors; + int CRT_delay = 0; int CRT_colorScheme = 0; diff --git a/CRT.h b/CRT.h index 55728c8..1fe3d24 100644 --- a/CRT.h +++ b/CRT.h @@ -9,20 +9,9 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ - -#include -#include -#include -#include #ifdef HAVE_EXECINFO_H -#include #endif -#include "String.h" - -#include "config.h" -#include "debug.h" - #define ColorPair(i,j) COLOR_PAIR((7-i)*8+j) #define COLORSCHEME_DEFAULT 0 @@ -43,8 +32,7 @@ in the source distribution for its full text. //#link curses -bool CRT_hasColors; - +#include typedef enum ColorElements_ { RESET_COLOR, diff --git a/CategoriesPanel.c b/CategoriesPanel.c index b3cb3aa..0114ae4 100644 --- a/CategoriesPanel.c +++ b/CategoriesPanel.c @@ -1,5 +1,12 @@ +/* +htop - CategoriesPanel.c +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ #include "CategoriesPanel.h" + #include "AvailableMetersPanel.h" #include "MetersPanel.h" #include "DisplayOptionsPanel.h" @@ -7,12 +14,13 @@ #include "ColorsPanel.h" #include "AvailableColumnsPanel.h" -#include "Panel.h" - -#include "debug.h" #include +#include /*{ +#include "Panel.h" +#include "Settings.h" +#include "ScreenManager.h" typedef struct CategoriesPanel_ { Panel super; diff --git a/CategoriesPanel.h b/CategoriesPanel.h index 7748fe1..1311fe2 100644 --- a/CategoriesPanel.h +++ b/CategoriesPanel.h @@ -2,19 +2,16 @@ #ifndef HEADER_CategoriesPanel #define HEADER_CategoriesPanel - -#include "AvailableMetersPanel.h" -#include "MetersPanel.h" -#include "DisplayOptionsPanel.h" -#include "ColumnsPanel.h" -#include "ColorsPanel.h" -#include "AvailableColumnsPanel.h" +/* +htop - CategoriesPanel.h +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ #include "Panel.h" - -#include "debug.h" -#include - +#include "Settings.h" +#include "ScreenManager.h" typedef struct CategoriesPanel_ { Panel super; diff --git a/ChangeLog b/ChangeLog index 724aaa7..568ec87 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,17 @@ +What's new in version 1.0.1 + +* Move .htoprc to XDG-compliant path ~/.config/htop/htoprc, + respecting $XDG_CONFIG_HOME + (thanks to Hadzhimurad Ustarkhan for the suggestion.) +* Safer behavior on the kill screen, to make it harder to kill the wrong process. +* Fix for building in FreeBSD 8.2 + (thanks to Trond Endrestol) +* BUGFIX: behavior of 'F' (follow) key was broken, also affecting the + persistence of mouse selections. +* BUGFIX: keep main panel up-to-date when running the screen manager, + to fix crash when processes die while on the F9/Kill screen. + What's new in version 1.0 * Performance improvements diff --git a/CheckItem.c b/CheckItem.c index 2d87ade..0fb40cf 100644 --- a/CheckItem.c +++ b/CheckItem.c @@ -1,17 +1,19 @@ /* -htop +htop - CheckItem.c (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ #include "CheckItem.h" -#include "Object.h" + #include "CRT.h" -#include "debug.h" +#include +#include /*{ +#include "Object.h" typedef struct CheckItem_ { Object super; diff --git a/CheckItem.h b/CheckItem.h index 3215623..6c70790 100644 --- a/CheckItem.h +++ b/CheckItem.h @@ -3,17 +3,13 @@ #ifndef HEADER_CheckItem #define HEADER_CheckItem /* -htop +htop - CheckItem.h (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ #include "Object.h" -#include "CRT.h" - -#include "debug.h" - typedef struct CheckItem_ { Object super; diff --git a/ClockMeter.c b/ClockMeter.c index 3764ca7..7edf5bf 100644 --- a/ClockMeter.c +++ b/ClockMeter.c @@ -1,16 +1,19 @@ /* -htop +htop - ClockMeter.c (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ #include "ClockMeter.h" -#include "Meter.h" + +#include "CRT.h" #include -#include "debug.h" +/*{ +#include "Meter.h" +}*/ int ClockMeter_attributes[] = { CLOCK diff --git a/ClockMeter.h b/ClockMeter.h index d4c8f82..ed19786 100644 --- a/ClockMeter.h +++ b/ClockMeter.h @@ -3,7 +3,7 @@ #ifndef HEADER_ClockMeter #define HEADER_ClockMeter /* -htop +htop - ClockMeter.h (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. @@ -11,10 +11,6 @@ in the source distribution for its full text. #include "Meter.h" -#include - -#include "debug.h" - extern int ClockMeter_attributes[]; extern MeterType ClockMeter; diff --git a/ColorsPanel.c b/ColorsPanel.c index 5e58670..bf94bf5 100644 --- a/ColorsPanel.c +++ b/ColorsPanel.c @@ -1,14 +1,18 @@ +/* +htop - ColorsPanel.c +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ -#include "CRT.h" #include "ColorsPanel.h" -#include "Panel.h" +#include "CRT.h" #include "CheckItem.h" -#include "Settings.h" -#include "ScreenManager.h" -#include "debug.h" #include +#include +#include // TO ADD A NEW SCHEME: // * Increment the size of bool check in ColorsPanel.h @@ -17,6 +21,9 @@ // * Add the colors in CRT_setColors /*{ +#include "Panel.h" +#include "Settings.h" +#include "ScreenManager.h" typedef struct ColorsPanel_ { Panel super; @@ -67,7 +74,7 @@ static HandlerResult ColorsPanel_EventHandler(Panel* super, int ch) { this->settings->changed = true; Header* header = this->settings->header; CRT_setColors(mark); - Panel* menu = (Panel*) Vector_get(this->scr->items, 0); + Panel* menu = (Panel*) Vector_get(this->scr->panels, 0); Header_draw(header); RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]); RichString_setAttr(&(menu->header), CRT_colors[PANEL_HEADER_UNFOCUS]); @@ -88,7 +95,7 @@ ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) { Panel_setHeader(super, "Colors"); for (int i = 0; ColorSchemes[i] != NULL; i++) { - Panel_add(super, (Object*) CheckItem_new(String_copy(ColorSchemes[i]), NULL, false)); + Panel_add(super, (Object*) CheckItem_new(strdup(ColorSchemes[i]), NULL, false)); } CheckItem_set((CheckItem*)Panel_get(super, settings->colorScheme), true); return this; diff --git a/ColorsPanel.h b/ColorsPanel.h index fac9963..61b89c0 100644 --- a/ColorsPanel.h +++ b/ColorsPanel.h @@ -2,16 +2,12 @@ #ifndef HEADER_ColorsPanel #define HEADER_ColorsPanel - -#include "CRT.h" - -#include "Panel.h" -#include "CheckItem.h" -#include "Settings.h" -#include "ScreenManager.h" - -#include "debug.h" -#include +/* +htop - ColorsPanel.h +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ // TO ADD A NEW SCHEME: // * Increment the size of bool check in ColorsPanel.h @@ -19,6 +15,9 @@ // * Add a define in CRT.h that matches the order of the array // * Add the colors in CRT_setColors +#include "Panel.h" +#include "Settings.h" +#include "ScreenManager.h" typedef struct ColorsPanel_ { Panel super; diff --git a/ColumnsPanel.c b/ColumnsPanel.c index 5c63074..d6b442a 100644 --- a/ColumnsPanel.c +++ b/ColumnsPanel.c @@ -1,14 +1,22 @@ +/* +htop - ColumnsPanel.c +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ #include "ColumnsPanel.h" -#include "Panel.h" -#include "Settings.h" -#include "ScreenManager.h" +#include "String.h" -#include "debug.h" #include +#include +#include /*{ +#include "Panel.h" +#include "Settings.h" +#include "ScreenManager.h" typedef struct ColumnsPanel_ { Panel super; @@ -62,7 +70,8 @@ static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) { } default: { - result = Panel_selectByTyping(super, ch); + if (isalpha(ch)) + result = Panel_selectByTyping(super, ch); if (result == BREAK_LOOP) result = IGNORED; break; diff --git a/ColumnsPanel.h b/ColumnsPanel.h index a0ed16a..2ebb387 100644 --- a/ColumnsPanel.h +++ b/ColumnsPanel.h @@ -2,16 +2,17 @@ #ifndef HEADER_ColumnsPanel #define HEADER_ColumnsPanel - +/* +htop - ColumnsPanel.h +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ #include "Panel.h" #include "Settings.h" #include "ScreenManager.h" -#include "debug.h" -#include - - typedef struct ColumnsPanel_ { Panel super; diff --git a/DebugMemory.c b/DebugMemory.c deleted file mode 100644 index 7a0f584..0000000 --- a/DebugMemory.c +++ /dev/null @@ -1,230 +0,0 @@ - -#include -#include -#include -#include -#include - -#undef strdup -#undef malloc -#undef realloc -#undef calloc -#undef free - -#include "DebugMemory.h" - -/*{ - -typedef struct DebugMemoryItem_ DebugMemoryItem; - -struct DebugMemoryItem_ { - int magic; - void* data; - char* file; - int line; - DebugMemoryItem* next; -}; - -typedef struct DebugMemory_ { - DebugMemoryItem* first; - int allocations; - int deallocations; - int size; - bool totals; - FILE* file; -} DebugMemory; - -}*/ - -#if defined(DEBUG) - -static DebugMemory* singleton = NULL; - -void DebugMemory_new() { - if (singleton) - return; - singleton = malloc(sizeof(DebugMemory)); - singleton->first = NULL; - singleton->allocations = 0; - singleton->deallocations = 0; - singleton->size = 0; - #ifdef DEBUG_ALLOC - singleton->file = fopen("/tmp/htop-debug-alloc.txt", "w"); - #else - singleton->file = NULL; - #endif - singleton->totals = true; - //singleton->file = NULL; -} - -void* DebugMemory_malloc(int size, char* file, int line, char* str) { - void* data = malloc(size); - DebugMemory_registerAllocation(data, file, line); - if (singleton->file) { - if (singleton->totals) fprintf(singleton->file, "%d\t", singleton->size); - fprintf(singleton->file, "%d\t%s:%d (%s)\n", size, file, line, str); - } - return data; -} - -void* DebugMemory_calloc(int a, int b, char* file, int line) { - void* data = calloc(a, b); - DebugMemory_registerAllocation(data, file, line); - if (singleton->file) { - if (singleton->totals) fprintf(singleton->file, "%d\t", singleton->size); - fprintf(singleton->file, "%d\t%s:%d\n", a*b, file, line); - } - return data; -} - -void* DebugMemory_realloc(void* ptr, int size, char* file, int line, char* str) { - if (ptr != NULL) - DebugMemory_registerDeallocation(ptr, file, line); - void* data = realloc(ptr, size); - DebugMemory_registerAllocation(data, file, line); - if (singleton->file) { - if (singleton->totals) fprintf(singleton->file, "%d\t", singleton->size); - fprintf(singleton->file, "%d\t%s:%d (%s)\n", size, file, line, str); - } - return data; -} - -void* DebugMemory_strdup(const char* str, char* file, int line) { - assert(str); - char* data = strdup(str); - DebugMemory_registerAllocation(data, file, line); - if (singleton->file) { - if (singleton->totals) fprintf(singleton->file, "%d\t", singleton->size); - fprintf(singleton->file, "%d\t%s:%d\n", (int) strlen(str), file, line); - } - return data; -} - -void DebugMemory_free(void* data, char* file, int line) { - if (!data) return; - DebugMemory_registerDeallocation(data, file, line); - if (singleton->file) { - if (singleton->totals) fprintf(singleton->file, "%d\t", singleton->size); - fprintf(singleton->file, "free\t%s:%d\n", file, line); - } - free(data); -} - -void DebugMemory_assertSize() { - if (!singleton->first) { - assert (singleton->size == 0); - } - DebugMemoryItem* walk = singleton->first; - int i = 0; - while (walk != NULL) { - assert(walk->magic == 11061980); - i++; - walk = walk->next; - } - assert (i == singleton->size); -} - -int DebugMemory_getBlockCount() { - if (!singleton->first) { - return 0; - } - DebugMemoryItem* walk = singleton->first; - int i = 0; - while (walk != NULL) { - assert(walk->magic == 11061980); - i++; - walk = walk->next; - } - return i; -} - -void DebugMemory_registerAllocation(void* data, char* file, int line) { - if (!singleton) - DebugMemory_new(); - DebugMemory_assertSize(); - DebugMemoryItem* item = (DebugMemoryItem*) malloc(sizeof(DebugMemoryItem)); - item->magic = 11061980; - item->data = data; - item->file = file; - item->line = line; - item->next = NULL; - int val = DebugMemory_getBlockCount(); - if (singleton->first == NULL) { - assert (val == 0); - singleton->first = item; - } else { - DebugMemoryItem* walk = singleton->first; - while (true) { - if (walk->next == NULL) { - walk->next = item; - break; - } - assert(walk->magic == 11061980); - walk = walk->next; - } - } - int nval = DebugMemory_getBlockCount(); - assert(nval == val + 1); - singleton->allocations++; - singleton->size++; - DebugMemory_assertSize(); -} - -void DebugMemory_registerDeallocation(void* data, char* file, int line) { - assert(singleton); - assert(singleton->first); - DebugMemoryItem* walk = singleton->first; - DebugMemoryItem* prev = NULL; - int val = DebugMemory_getBlockCount(); - while (walk != NULL) { - assert(walk->magic == 11061980); - if (walk->data == data) { - if (prev == NULL) { - singleton->first = walk->next; - } else { - prev->next = walk->next; - } - free(walk); - assert(DebugMemory_getBlockCount() == val - 1); - singleton->deallocations++; - singleton->size--; - DebugMemory_assertSize(); - return; - } - DebugMemoryItem* tmp = walk; - walk = walk->next; - prev = tmp; - } - DebugMemory_report(); - fprintf(stderr, "Couldn't find allocation for memory freed at %s:%d\n", file, line); - assert(false); -} - -void DebugMemory_report() { - assert(singleton); - DebugMemoryItem* walk = singleton->first; - int i = 0; - while (walk != NULL) { - assert(walk->magic == 11061980); - i++; - fprintf(stderr, "%p %s:%d\n", walk->data, walk->file, walk->line); - DebugMemoryItem* old = walk; - walk = walk->next; - free(old->file); - free(old); - } - fprintf(stderr, "Total:\n"); - fprintf(stderr, "%d allocations\n", singleton->allocations); - fprintf(stderr, "%d deallocations\n", singleton->deallocations); - fprintf(stderr, "%d size\n", singleton->size); - fprintf(stderr, "%d non-freed blocks\n", i); - if (singleton->file) - fclose(singleton->file); - free(singleton); -} - -#elif defined(DEBUGLITE) - -//#include "efence.h" - -#endif diff --git a/DebugMemory.h b/DebugMemory.h deleted file mode 100644 index a67a5f2..0000000 --- a/DebugMemory.h +++ /dev/null @@ -1,70 +0,0 @@ -/* Do not edit this file. It was automatically generated. */ - -#ifndef HEADER_DebugMemory -#define HEADER_DebugMemory - -#include -#include -#include -#include -#include - -#undef strdup -#undef malloc -#undef realloc -#undef calloc -#undef free - - - -typedef struct DebugMemoryItem_ DebugMemoryItem; - -struct DebugMemoryItem_ { - int magic; - void* data; - char* file; - int line; - DebugMemoryItem* next; -}; - -typedef struct DebugMemory_ { - DebugMemoryItem* first; - int allocations; - int deallocations; - int size; - bool totals; - FILE* file; -} DebugMemory; - - -#if defined(DEBUG) - -void DebugMemory_new(); - -void* DebugMemory_malloc(int size, char* file, int line, char* str); - -void* DebugMemory_calloc(int a, int b, char* file, int line); - -void* DebugMemory_realloc(void* ptr, int size, char* file, int line, char* str); - -void* DebugMemory_strdup(const char* str, char* file, int line); - -void DebugMemory_free(void* data, char* file, int line); - -void DebugMemory_assertSize(); - -int DebugMemory_getBlockCount(); - -void DebugMemory_registerAllocation(void* data, char* file, int line); - -void DebugMemory_registerDeallocation(void* data, char* file, int line); - -void DebugMemory_report(); - -#elif defined(DEBUGLITE) - -//#include "efence.h" - -#endif - -#endif diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 71d7309..bf521a8 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -1,15 +1,22 @@ +/* +htop - DisplayOptionsPanel.c +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ #include "DisplayOptionsPanel.h" -#include "Panel.h" #include "CheckItem.h" -#include "Settings.h" -#include "ScreenManager.h" -#include "debug.h" #include +#include +#include /*{ +#include "Panel.h" +#include "Settings.h" +#include "ScreenManager.h" typedef struct DisplayOptionsPanel_ { Panel super; @@ -65,16 +72,16 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* super->eventHandler = DisplayOptionsPanel_eventHandler; Panel_setHeader(super, "Display options"); - Panel_add(super, (Object*) CheckItem_new(String_copy("Tree view"), &(settings->pl->treeView), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Shadow other users' processes"), &(settings->pl->shadowOtherUsers), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Hide kernel threads"), &(settings->pl->hideKernelThreads), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Hide userland threads"), &(settings->pl->hideUserlandThreads), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Display threads in a different color"), &(settings->pl->highlightThreads), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Show custom thread names"), &(settings->pl->showThreadNames), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight program \"basename\""), &(settings->pl->highlightBaseName), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight large numbers in memory counters"), &(settings->pl->highlightMegabytes), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Leave a margin around header"), &(settings->header->margin), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->pl->detailedCPUTime), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Count CPUs from 0 instead of 1"), &(settings->pl->countCPUsFromZero), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Tree view"), &(settings->pl->treeView), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Shadow other users' processes"), &(settings->pl->shadowOtherUsers), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Hide kernel threads"), &(settings->pl->hideKernelThreads), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Hide userland threads"), &(settings->pl->hideUserlandThreads), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Display threads in a different color"), &(settings->pl->highlightThreads), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Show custom thread names"), &(settings->pl->showThreadNames), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Highlight program \"basename\""), &(settings->pl->highlightBaseName), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Highlight large numbers in memory counters"), &(settings->pl->highlightMegabytes), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Leave a margin around header"), &(settings->header->margin), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->pl->detailedCPUTime), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Count CPUs from 0 instead of 1"), &(settings->pl->countCPUsFromZero), false)); return this; } diff --git a/DisplayOptionsPanel.h b/DisplayOptionsPanel.h index a908f53..1e013f3 100644 --- a/DisplayOptionsPanel.h +++ b/DisplayOptionsPanel.h @@ -2,17 +2,17 @@ #ifndef HEADER_DisplayOptionsPanel #define HEADER_DisplayOptionsPanel - +/* +htop - DisplayOptionsPanel.h +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ #include "Panel.h" -#include "CheckItem.h" #include "Settings.h" #include "ScreenManager.h" -#include "debug.h" -#include - - typedef struct DisplayOptionsPanel_ { Panel super; diff --git a/FunctionBar.c b/FunctionBar.c index ef0fcba..dc4368e 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -5,19 +5,18 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "Object.h" #include "FunctionBar.h" + #include "CRT.h" -#include "debug.h" #include - #include #include #include #include /*{ +#include "Object.h" typedef struct FunctionBar_ { Object super; @@ -54,8 +53,8 @@ FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* eve this->events = malloc(sizeof(int) * 15); int i = 0; while (i < 15 && functions[i]) { - this->functions[i] = String_copy(functions[i]); - this->keys[i] = String_copy(keys[i]); + this->functions[i] = strdup(functions[i]); + this->keys[i] = strdup(keys[i]); this->events[i] = events[i]; i++; } @@ -89,7 +88,7 @@ void FunctionBar_setLabel(FunctionBar* this, int event, const char* text) { for (int i = 0; i < this->size; i++) { if (this->events[i] == event) { free(this->functions[i]); - this->functions[i] = String_copy(text); + this->functions[i] = strdup(text); break; } } diff --git a/FunctionBar.h b/FunctionBar.h index e7fcb4f..584d7fd 100644 --- a/FunctionBar.h +++ b/FunctionBar.h @@ -10,16 +10,6 @@ in the source distribution for its full text. */ #include "Object.h" -#include "CRT.h" - -#include "debug.h" -#include - -#include -#include -#include -#include - typedef struct FunctionBar_ { Object super; diff --git a/Hashtable.c b/Hashtable.c index f2f87d2..9d84db8 100644 --- a/Hashtable.c +++ b/Hashtable.c @@ -1,5 +1,5 @@ /* -htop +htop - Hashtable.c (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. @@ -8,12 +8,11 @@ in the source distribution for its full text. #include "Hashtable.h" #include -#include #include -#include "debug.h" - /*{ +#include + typedef struct Hashtable_ Hashtable; typedef void(*Hashtable_PairFunction)(int, void*, void*); diff --git a/Hashtable.h b/Hashtable.h index 5f4a261..2560896 100644 --- a/Hashtable.h +++ b/Hashtable.h @@ -3,18 +3,13 @@ #ifndef HEADER_Hashtable #define HEADER_Hashtable /* -htop +htop - Hashtable.h (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ - -#include #include -#include - -#include "debug.h" typedef struct Hashtable_ Hashtable; diff --git a/Header.c b/Header.c index 9a14b15..ea1078f 100644 --- a/Header.c +++ b/Header.c @@ -6,13 +6,27 @@ in the source distribution for its full text. */ #include "Header.h" -#include "Meter.h" -#include "debug.h" +#include "CRT.h" +#include "CPUMeter.h" +#include "MemoryMeter.h" +#include "SwapMeter.h" +#include "TasksMeter.h" +#include "LoadAverageMeter.h" +#include "UptimeMeter.h" +#include "BatteryMeter.h" +#include "ClockMeter.h" +#include "HostnameMeter.h" +#include "String.h" + #include #include +#include +#include /*{ +#include "ProcessList.h" +#include "Meter.h" typedef enum HeaderSide_ { LEFT_HEADER, diff --git a/Header.h b/Header.h index 0fb5a73..938d141 100644 --- a/Header.h +++ b/Header.h @@ -9,13 +9,9 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#include "ProcessList.h" #include "Meter.h" -#include "debug.h" -#include -#include - - typedef enum HeaderSide_ { LEFT_HEADER, RIGHT_HEADER diff --git a/HostnameMeter.c b/HostnameMeter.c index 7c4e6b1..0498ab7 100644 --- a/HostnameMeter.c +++ b/HostnameMeter.c @@ -1,16 +1,19 @@ /* -htop +htop - HostnameMeter.c (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ #include "HostnameMeter.h" -#include "Meter.h" + +#include "CRT.h" #include -#include "debug.h" +/*{ +#include "Meter.h" +}*/ int HostnameMeter_attributes[] = { HOSTNAME diff --git a/HostnameMeter.h b/HostnameMeter.h index ddebfcf..addc753 100644 --- a/HostnameMeter.h +++ b/HostnameMeter.h @@ -3,7 +3,7 @@ #ifndef HEADER_HostnameMeter #define HEADER_HostnameMeter /* -htop +htop - HostnameMeter.h (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. @@ -11,10 +11,6 @@ in the source distribution for its full text. #include "Meter.h" -#include - -#include "debug.h" - extern int HostnameMeter_attributes[]; extern MeterType HostnameMeter; diff --git a/ListItem.c b/ListItem.c index 68ca7c9..9beed0c 100644 --- a/ListItem.c +++ b/ListItem.c @@ -6,14 +6,17 @@ in the source distribution for its full text. */ #include "ListItem.h" + +#include "CRT.h" #include "String.h" -#include "Object.h" #include "RichString.h" -#include -#include "debug.h" +#include +#include +#include /*{ +#include "Object.h" typedef struct ListItem_ { Object super; @@ -49,7 +52,7 @@ ListItem* ListItem_new(const char* value, int key) { Object_setClass(this, LISTITEM_CLASS); ((Object*)this)->display = ListItem_display; ((Object*)this)->delete = ListItem_delete; - this->value = String_copy(value); + this->value = strdup(value); this->key = key; return this; } diff --git a/ListItem.h b/ListItem.h index de0edef..8df792c 100644 --- a/ListItem.h +++ b/ListItem.h @@ -9,13 +9,7 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "String.h" #include "Object.h" -#include "RichString.h" -#include - -#include "debug.h" - typedef struct ListItem_ { Object super; diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c index 02c8ad5..9d5071b 100644 --- a/LoadAverageMeter.c +++ b/LoadAverageMeter.c @@ -1,16 +1,20 @@ /* -htop +htop - LoadAverageMeter.c (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ #include "LoadAverageMeter.h" -#include "Meter.h" + +#include "CRT.h" #include +#include -#include "debug.h" +/*{ +#include "Meter.h" +}*/ int LoadAverageMeter_attributes[] = { LOAD_AVERAGE_FIFTEEN, LOAD_AVERAGE_FIVE, LOAD_AVERAGE_ONE diff --git a/LoadAverageMeter.h b/LoadAverageMeter.h index 7610e60..b30680f 100644 --- a/LoadAverageMeter.h +++ b/LoadAverageMeter.h @@ -3,7 +3,7 @@ #ifndef HEADER_LoadAverageMeter #define HEADER_LoadAverageMeter /* -htop +htop - LoadAverageMeter.h (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. @@ -11,10 +11,6 @@ in the source distribution for its full text. #include "Meter.h" -#include - -#include "debug.h" - extern int LoadAverageMeter_attributes[]; extern int LoadMeter_attributes[]; diff --git a/Makefile.am b/Makefile.am index b648969..a1ff7d6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,12 +10,11 @@ applications_DATA = htop.desktop pixmapdir = $(datadir)/pixmaps pixmap_DATA = htop.png -htop_CFLAGS = -pedantic -Wall -Wextra -std=c99 -rdynamic -D_XOPEN_SOURCE_EXTENDED -AM_CFLAGS = -AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\" +htop_CFLAGS = -pedantic -Wall -Wextra -std=c99 -rdynamic -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" +AM_CPPFLAGS = -DNDEBUG myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \ -ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c DebugMemory.c \ +ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c \ DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \ LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \ BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \ @@ -25,7 +24,7 @@ HostnameMeter.c OpenFilesScreen.c Affinity.c myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \ CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \ -CPUMeter.h CRT.h DebugMemory.h DisplayOptionsPanel.h FunctionBar.h \ +CPUMeter.h CRT.h DisplayOptionsPanel.h FunctionBar.h \ Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \ BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \ ScreenManager.h Settings.h SignalsPanel.h String.h \ @@ -35,22 +34,16 @@ Process.h AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h SUFFIXES = .h BUILT_SOURCES = $(myhtopheaders) -htop_SOURCES = $(myhtopheaders) $(myhtopsources) config.h debug.h +htop_SOURCES = $(myhtopheaders) $(myhtopsources) config.h profile: - $(MAKE) all CFLAGS="-pg -O2" + $(MAKE) all CFLAGS="" AM_CPPFLAGS="-pg -O2" debug: - $(MAKE) all CFLAGS="-ggdb -DDEBUG" - -hardened-debug: - $(MAKE) all CFLAGS="-ggdb -DDEBUG" LDFLAGS="-nopie" - -debuglite: - $(MAKE) all CFLAGS="-ggdb -DDEBUGLITE" + $(MAKE) all CFLAGS="" AM_CPPFLAGS="-ggdb -DDEBUG" .c.h: scripts/MakeHeader.py $< cppcheck: - cppcheck -q -v . --enable=all -ihwloc-1.2.1 -DHAVE_CGROUP -DHAVE_OPENVZ -DHAVE_TASKSTATS + cppcheck -q -v . --enable=all -DHAVE_CGROUP -DHAVE_OPENVZ -DHAVE_TASKSTATS diff --git a/Makefile.in b/Makefile.in index c90fca8..554029e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -65,21 +65,20 @@ am__objects_2 = htop-AvailableMetersPanel.$(OBJEXT) \ htop-CategoriesPanel.$(OBJEXT) htop-CheckItem.$(OBJEXT) \ htop-ClockMeter.$(OBJEXT) htop-ColorsPanel.$(OBJEXT) \ htop-ColumnsPanel.$(OBJEXT) htop-CPUMeter.$(OBJEXT) \ - htop-CRT.$(OBJEXT) htop-DebugMemory.$(OBJEXT) \ - htop-DisplayOptionsPanel.$(OBJEXT) htop-FunctionBar.$(OBJEXT) \ - htop-Hashtable.$(OBJEXT) htop-Header.$(OBJEXT) \ - htop-htop.$(OBJEXT) htop-ListItem.$(OBJEXT) \ - htop-LoadAverageMeter.$(OBJEXT) htop-MemoryMeter.$(OBJEXT) \ - htop-Meter.$(OBJEXT) htop-MetersPanel.$(OBJEXT) \ - htop-Object.$(OBJEXT) htop-Panel.$(OBJEXT) \ - htop-BatteryMeter.$(OBJEXT) htop-Process.$(OBJEXT) \ - htop-ProcessList.$(OBJEXT) htop-RichString.$(OBJEXT) \ - htop-ScreenManager.$(OBJEXT) htop-Settings.$(OBJEXT) \ - htop-SignalsPanel.$(OBJEXT) htop-String.$(OBJEXT) \ - htop-SwapMeter.$(OBJEXT) htop-TasksMeter.$(OBJEXT) \ - htop-TraceScreen.$(OBJEXT) htop-UptimeMeter.$(OBJEXT) \ - htop-UsersTable.$(OBJEXT) htop-Vector.$(OBJEXT) \ - htop-AvailableColumnsPanel.$(OBJEXT) \ + htop-CRT.$(OBJEXT) htop-DisplayOptionsPanel.$(OBJEXT) \ + htop-FunctionBar.$(OBJEXT) htop-Hashtable.$(OBJEXT) \ + htop-Header.$(OBJEXT) htop-htop.$(OBJEXT) \ + htop-ListItem.$(OBJEXT) htop-LoadAverageMeter.$(OBJEXT) \ + htop-MemoryMeter.$(OBJEXT) htop-Meter.$(OBJEXT) \ + htop-MetersPanel.$(OBJEXT) htop-Object.$(OBJEXT) \ + htop-Panel.$(OBJEXT) htop-BatteryMeter.$(OBJEXT) \ + htop-Process.$(OBJEXT) htop-ProcessList.$(OBJEXT) \ + htop-RichString.$(OBJEXT) htop-ScreenManager.$(OBJEXT) \ + htop-Settings.$(OBJEXT) htop-SignalsPanel.$(OBJEXT) \ + htop-String.$(OBJEXT) htop-SwapMeter.$(OBJEXT) \ + htop-TasksMeter.$(OBJEXT) htop-TraceScreen.$(OBJEXT) \ + htop-UptimeMeter.$(OBJEXT) htop-UsersTable.$(OBJEXT) \ + htop-Vector.$(OBJEXT) htop-AvailableColumnsPanel.$(OBJEXT) \ htop-AffinityPanel.$(OBJEXT) htop-HostnameMeter.$(OBJEXT) \ htop-OpenFilesScreen.$(OBJEXT) htop-Affinity.$(OBJEXT) am_htop_OBJECTS = $(am__objects_1) $(am__objects_2) @@ -264,11 +263,10 @@ applicationsdir = $(datadir)/applications applications_DATA = htop.desktop pixmapdir = $(datadir)/pixmaps pixmap_DATA = htop.png -htop_CFLAGS = -pedantic -Wall -Wextra -std=c99 -rdynamic -D_XOPEN_SOURCE_EXTENDED -AM_CFLAGS = -AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\" +htop_CFLAGS = -pedantic -Wall -Wextra -std=c99 -rdynamic -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" +AM_CPPFLAGS = -DNDEBUG myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \ -ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c DebugMemory.c \ +ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c \ DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \ LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \ BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \ @@ -278,7 +276,7 @@ HostnameMeter.c OpenFilesScreen.c Affinity.c myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \ CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \ -CPUMeter.h CRT.h DebugMemory.h DisplayOptionsPanel.h FunctionBar.h \ +CPUMeter.h CRT.h DisplayOptionsPanel.h FunctionBar.h \ Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \ BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \ ScreenManager.h Settings.h SignalsPanel.h String.h \ @@ -287,7 +285,7 @@ Process.h AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h SUFFIXES = .h BUILT_SOURCES = $(myhtopheaders) -htop_SOURCES = $(myhtopheaders) $(myhtopsources) config.h debug.h +htop_SOURCES = $(myhtopheaders) $(myhtopsources) config.h all: $(BUILT_SOURCES) config.h $(MAKE) $(AM_MAKEFLAGS) all-am @@ -411,7 +409,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/htop-ClockMeter.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/htop-ColorsPanel.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/htop-ColumnsPanel.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/htop-DebugMemory.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/htop-DisplayOptionsPanel.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/htop-FunctionBar.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/htop-Hashtable.Po@am__quote@ @@ -573,20 +570,6 @@ htop-CRT.obj: CRT.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(htop_CFLAGS) $(CFLAGS) -c -o htop-CRT.obj `if test -f 'CRT.c'; then $(CYGPATH_W) 'CRT.c'; else $(CYGPATH_W) '$(srcdir)/CRT.c'; fi` -htop-DebugMemory.o: DebugMemory.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(htop_CFLAGS) $(CFLAGS) -MT htop-DebugMemory.o -MD -MP -MF $(DEPDIR)/htop-DebugMemory.Tpo -c -o htop-DebugMemory.o `test -f 'DebugMemory.c' || echo '$(srcdir)/'`DebugMemory.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/htop-DebugMemory.Tpo $(DEPDIR)/htop-DebugMemory.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='DebugMemory.c' object='htop-DebugMemory.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(htop_CFLAGS) $(CFLAGS) -c -o htop-DebugMemory.o `test -f 'DebugMemory.c' || echo '$(srcdir)/'`DebugMemory.c - -htop-DebugMemory.obj: DebugMemory.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(htop_CFLAGS) $(CFLAGS) -MT htop-DebugMemory.obj -MD -MP -MF $(DEPDIR)/htop-DebugMemory.Tpo -c -o htop-DebugMemory.obj `if test -f 'DebugMemory.c'; then $(CYGPATH_W) 'DebugMemory.c'; else $(CYGPATH_W) '$(srcdir)/DebugMemory.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/htop-DebugMemory.Tpo $(DEPDIR)/htop-DebugMemory.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='DebugMemory.c' object='htop-DebugMemory.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(htop_CFLAGS) $(CFLAGS) -c -o htop-DebugMemory.obj `if test -f 'DebugMemory.c'; then $(CYGPATH_W) 'DebugMemory.c'; else $(CYGPATH_W) '$(srcdir)/DebugMemory.c'; fi` - htop-DisplayOptionsPanel.o: DisplayOptionsPanel.c @am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(htop_CFLAGS) $(CFLAGS) -MT htop-DisplayOptionsPanel.o -MD -MP -MF $(DEPDIR)/htop-DisplayOptionsPanel.Tpo -c -o htop-DisplayOptionsPanel.o `test -f 'DisplayOptionsPanel.c' || echo '$(srcdir)/'`DisplayOptionsPanel.c @am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/htop-DisplayOptionsPanel.Tpo $(DEPDIR)/htop-DisplayOptionsPanel.Po @@ -1455,22 +1438,16 @@ uninstall-man: uninstall-man1 profile: - $(MAKE) all CFLAGS="-pg -O2" + $(MAKE) all CFLAGS="" AM_CPPFLAGS="-pg -O2" debug: - $(MAKE) all CFLAGS="-ggdb -DDEBUG" - -hardened-debug: - $(MAKE) all CFLAGS="-ggdb -DDEBUG" LDFLAGS="-nopie" - -debuglite: - $(MAKE) all CFLAGS="-ggdb -DDEBUGLITE" + $(MAKE) all CFLAGS="" AM_CPPFLAGS="-ggdb -DDEBUG" .c.h: scripts/MakeHeader.py $< cppcheck: - cppcheck -q -v . --enable=all -ihwloc-1.2.1 -DHAVE_CGROUP -DHAVE_OPENVZ -DHAVE_TASKSTATS + cppcheck -q -v . --enable=all -DHAVE_CGROUP -DHAVE_OPENVZ -DHAVE_TASKSTATS # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/MemoryMeter.c b/MemoryMeter.c index e9e9125..fa897d7 100644 --- a/MemoryMeter.c +++ b/MemoryMeter.c @@ -1,13 +1,13 @@ /* -htop +htop - MemoryMeter.c (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ #include "MemoryMeter.h" -#include "Meter.h" +#include "CRT.h" #include "ProcessList.h" #include @@ -15,10 +15,12 @@ in the source distribution for its full text. #include #include #include - -#include "debug.h" #include +/*{ +#include "Meter.h" +}*/ + int MemoryMeter_attributes[] = { MEMORY_USED, MEMORY_BUFFERS, MEMORY_CACHE }; diff --git a/MemoryMeter.h b/MemoryMeter.h index 4f6d958..8fa1e42 100644 --- a/MemoryMeter.h +++ b/MemoryMeter.h @@ -3,7 +3,7 @@ #ifndef HEADER_MemoryMeter #define HEADER_MemoryMeter /* -htop +htop - MemoryMeter.h (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. @@ -11,17 +11,6 @@ in the source distribution for its full text. #include "Meter.h" -#include "ProcessList.h" - -#include -#include -#include -#include -#include - -#include "debug.h" -#include - extern int MemoryMeter_attributes[]; extern MeterType MemoryMeter; diff --git a/Meter.c b/Meter.c index 97b1dc4..b009d66 100644 --- a/Meter.c +++ b/Meter.c @@ -5,30 +5,39 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "RichString.h" #include "Meter.h" + +#include "CPUMeter.h" +#include "MemoryMeter.h" +#include "SwapMeter.h" +#include "TasksMeter.h" +#include "LoadAverageMeter.h" +#include "UptimeMeter.h" +#include "BatteryMeter.h" +#include "ClockMeter.h" +#include "HostnameMeter.h" +#include "RichString.h" #include "Object.h" #include "CRT.h" -#include "ListItem.h" #include "String.h" -#include "ProcessList.h" +#include "ListItem.h" #include #include #include #include - -#include "debug.h" #include +#include #ifndef USE_FUNKY_MODES -#include #define USE_FUNKY_MODES 1 #endif #define METER_BUFFER_LEN 128 /*{ +#include "ListItem.h" +#include "ProcessList.h" typedef struct Meter_ Meter; typedef struct MeterType_ MeterType; @@ -96,17 +105,6 @@ typedef enum { }*/ -#include "CPUMeter.h" -#include "MemoryMeter.h" -#include "SwapMeter.h" -#include "TasksMeter.h" -#include "LoadAverageMeter.h" -#include "UptimeMeter.h" -#include "BatteryMeter.h" -#include "ClockMeter.h" -#include "HostnameMeter.h" - - #ifndef MIN #define MIN(a,b) ((a)<(b)?(a):(b)) #endif diff --git a/Meter.h b/Meter.h index dc550e4..0882724 100644 --- a/Meter.h +++ b/Meter.h @@ -9,28 +9,14 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "RichString.h" -#include "Object.h" -#include "CRT.h" -#include "ListItem.h" -#include "String.h" -#include "ProcessList.h" - -#include -#include -#include -#include - -#include "debug.h" -#include - #ifndef USE_FUNKY_MODES -#include #define USE_FUNKY_MODES 1 #endif #define METER_BUFFER_LEN 128 +#include "ListItem.h" +#include "ProcessList.h" typedef struct Meter_ Meter; typedef struct MeterType_ MeterType; @@ -97,17 +83,6 @@ typedef enum { } MeterModeId; -#include "CPUMeter.h" -#include "MemoryMeter.h" -#include "SwapMeter.h" -#include "TasksMeter.h" -#include "LoadAverageMeter.h" -#include "UptimeMeter.h" -#include "BatteryMeter.h" -#include "ClockMeter.h" -#include "HostnameMeter.h" - - #ifndef MIN #define MIN(a,b) ((a)<(b)?(a):(b)) #endif diff --git a/MetersPanel.c b/MetersPanel.c index df1d6fb..8302c5a 100644 --- a/MetersPanel.c +++ b/MetersPanel.c @@ -1,14 +1,19 @@ +/* +htop - MetersPanel.c +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ #include "MetersPanel.h" -#include "Panel.h" -#include "Settings.h" -#include "ScreenManager.h" - -#include "debug.h" +#include #include /*{ +#include "Panel.h" +#include "Settings.h" +#include "ScreenManager.h" typedef struct MetersPanel_ { Panel super; diff --git a/MetersPanel.h b/MetersPanel.h index 2e6d225..4aa2c3d 100644 --- a/MetersPanel.h +++ b/MetersPanel.h @@ -2,16 +2,17 @@ #ifndef HEADER_MetersPanel #define HEADER_MetersPanel - +/* +htop - MetersPanel.h +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ #include "Panel.h" #include "Settings.h" #include "ScreenManager.h" -#include "debug.h" -#include - - typedef struct MetersPanel_ { Panel super; diff --git a/Object.c b/Object.c index f8eb20d..395bd10 100644 --- a/Object.c +++ b/Object.c @@ -1,20 +1,20 @@ /* -htop +htop - Object.c (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ #include "Object.h" -#include "RichString.h" + #include "CRT.h" + #include #include #include -#include "debug.h" - /*{ +#include "RichString.h" #ifndef DEBUG #define Object_setClass(obj, class) diff --git a/Object.h b/Object.h index 097af90..8ebc1d5 100644 --- a/Object.h +++ b/Object.h @@ -3,20 +3,13 @@ #ifndef HEADER_Object #define HEADER_Object /* -htop +htop - Object.h (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ #include "RichString.h" -#include "CRT.h" -#include -#include -#include - -#include "debug.h" - #ifndef DEBUG #define Object_setClass(obj, class) diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index b4ec11a..9adf8b4 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -5,24 +5,27 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#define _GNU_SOURCE +#include "OpenFilesScreen.h" + +#include "CRT.h" +#include "ProcessList.h" +#include "ListItem.h" + +#include #include #include #include #include +#include #include #include #include -#include "OpenFilesScreen.h" -#include "ProcessList.h" +/*{ #include "Process.h" -#include "ListItem.h" #include "Panel.h" #include "FunctionBar.h" -/*{ - typedef struct OpenFiles_ProcessData_ { char* data[256]; struct OpenFiles_FileData_* files; diff --git a/OpenFilesScreen.h b/OpenFilesScreen.h index a5d3cbc..248cac4 100644 --- a/OpenFilesScreen.h +++ b/OpenFilesScreen.h @@ -9,22 +9,10 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include - -#include "ProcessList.h" #include "Process.h" -#include "ListItem.h" #include "Panel.h" #include "FunctionBar.h" - typedef struct OpenFiles_ProcessData_ { char* data[256]; struct OpenFiles_FileData_* files; diff --git a/Panel.c b/Panel.c index 56e1948..b090c52 100644 --- a/Panel.c +++ b/Panel.c @@ -5,23 +5,26 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "Object.h" #include "Panel.h" -#include "Vector.h" + #include "CRT.h" #include "RichString.h" #include "ListItem.h" +#include "String.h" #include #include - -#include "debug.h" +#include +#include +#include #include - #include + //#link curses /*{ +#include "Object.h" +#include "Vector.h" typedef struct Panel_ Panel; diff --git a/Panel.h b/Panel.h index bc83810..3f35583 100644 --- a/Panel.h +++ b/Panel.h @@ -9,21 +9,10 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "Object.h" -#include "Vector.h" -#include "CRT.h" -#include "RichString.h" -#include "ListItem.h" - -#include -#include - -#include "debug.h" -#include - -#include //#link curses +#include "Object.h" +#include "Vector.h" typedef struct Panel_ Panel; @@ -117,7 +106,6 @@ void Panel_draw(Panel* this, bool focus); bool Panel_onKey(Panel* this, int key); - HandlerResult Panel_selectByTyping(Panel* this, int ch); #endif diff --git a/Process.c b/Process.c index fec3f33..1ae96e1 100644 --- a/Process.c +++ b/Process.c @@ -5,29 +5,27 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#include "Process.h" + #include "ProcessList.h" -#include "Object.h" #include "CRT.h" #include "String.h" -#include "Process.h" #include "RichString.h" -#include "Affinity.h" - -#include "debug.h" #include #include #include #include -#include #include #include +#include #include #include #include #include #include #include +#include #ifdef HAVE_LIBHWLOC #include @@ -41,6 +39,9 @@ in the source distribution for its full text. #define PAGE_SIZE_KB ( PAGE_SIZE / ONE_K ) /*{ +#include "Object.h" +#include "Affinity.h" +#include #ifndef Process_isKernelThread #define Process_isKernelThread(_process) (_process->pgrp == 0) @@ -312,19 +313,24 @@ static void Process_printTime(RichString* str, unsigned long long t) { double realTime = t * jiffytime; int iRealTime = (int) realTime; - int hours = iRealTime / 3600; + unsigned long long hours = iRealTime / 3600; int minutes = (iRealTime / 60) % 60; int seconds = iRealTime % 60; int hundredths = (realTime - iRealTime) * 100; char buffer[11]; - if (hours) { - snprintf(buffer, 10, "%2dh", hours); + if (hours >= 100) { + snprintf(buffer, 10, "%7lluh ", hours); RichString_append(str, CRT_colors[LARGE_NUMBER], buffer); - snprintf(buffer, 10, "%02d:%02d ", minutes, seconds); } else { - snprintf(buffer, 10, "%2d:%02d.%02d ", minutes, seconds, hundredths); + if (hours) { + snprintf(buffer, 10, "%2lluh", hours); + RichString_append(str, CRT_colors[LARGE_NUMBER], buffer); + snprintf(buffer, 10, "%02d:%02d ", minutes, seconds); + } else { + snprintf(buffer, 10, "%2d:%02d.%02d ", minutes, seconds, hundredths); + } + RichString_append(str, CRT_colors[DEFAULT_COLOR], buffer); } - RichString_append(str, CRT_colors[DEFAULT_COLOR], buffer); } static inline void Process_writeCommand(Process* this, int attr, int baseattr, RichString* str) { diff --git a/Process.h b/Process.h index e72f816..2c3e0c3 100644 --- a/Process.h +++ b/Process.h @@ -9,31 +9,7 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "ProcessList.h" -#include "Object.h" -#include "CRT.h" -#include "String.h" -#include "RichString.h" -#include "Affinity.h" - -#include "debug.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #ifdef HAVE_LIBHWLOC -#include #endif // This works only with glibc 2.1+. On earlier versions @@ -43,6 +19,9 @@ in the source distribution for its full text. #endif #define PAGE_SIZE_KB ( PAGE_SIZE / ONE_K ) +#include "Object.h" +#include "Affinity.h" +#include #ifndef Process_isKernelThread #define Process_isKernelThread(_process) (_process->pgrp == 0) diff --git a/ProcessList.c b/ProcessList.c index be01ca6..1f47408 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -5,19 +5,13 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#ifndef CONFIG_H -#define CONFIG_H -#include "config.h" -#endif - #include "ProcessList.h" -#include "Process.h" -#include "Vector.h" -#include "UsersTable.h" -#include "Hashtable.h" + +#include "CRT.h" #include "String.h" -#include +#include +#include #include #include #include @@ -25,14 +19,19 @@ in the source distribution for its full text. #include #include #include -#include #include #include - -#include "debug.h" +#include +#include #include /*{ +#include "Vector.h" +#include "Hashtable.h" +#include "UsersTable.h" +#include "Panel.h" +#include "Process.h" +#include #ifndef PROCDIR #define PROCDIR "/proc" @@ -109,6 +108,13 @@ typedef struct ProcessList_ { Hashtable* processTable; UsersTable* usersTable; + Panel* panel; + int following; + bool userOnly; + uid_t userId; + bool filtering; + const char* incFilter; + int cpuCount; int totalTasks; int userlandThreads; @@ -243,6 +249,10 @@ void ProcessList_delete(ProcessList* this) { free(this); } +void ProcessList_setPanel(ProcessList* this, Panel* panel) { + this->panel = panel; +} + void ProcessList_invertSortOrder(ProcessList* this) { if (this->direction == 1) this->direction = -1; @@ -605,7 +615,7 @@ static bool ProcessList_readCmdlineFile(Process* process, const char* dirname, c command[amtRead] = '\0'; fclose(file); free(process->comm); - process->comm = String_copy(command); + process->comm = strdup(command); return true; } @@ -698,11 +708,11 @@ static bool ProcessList_processEntries(ProcessList* this, const char* dirname, P if (process->state == 'Z') { free(process->comm); - process->comm = String_copy(command); + process->comm = strdup(command); } else if (Process_isThread(process)) { if (this->showThreadNames || Process_isKernelThread(process) || process->state == 'Z') { free(process->comm); - process->comm = String_copy(command); + process->comm = strdup(command); } else if (this->showingThreadNames) { if (! ProcessList_readCmdlineFile(process, dirname, name)) goto errorReadingProcess; @@ -888,3 +898,45 @@ void ProcessList_expandTree(ProcessList* this) { process->showChildren = true; } } + +void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, bool userOnly, uid_t userId, bool filtering, const char* incFilter) { + if (!flags) { + following = this->following; + userOnly = this->userOnly; + userId = this->userId; + filtering = this->filtering; + incFilter = this->incFilter; + } else { + this->following = following; + this->userOnly = userOnly; + this->userId = userId; + this->filtering = filtering; + this->incFilter = incFilter; + } + + int currPos = Panel_getSelectedIndex(this->panel); + pid_t currPid = following ? following : 0; + int currScrollV = this->panel->scrollV; + + Panel_prune(this->panel); + int size = ProcessList_size(this); + int idx = 0; + for (int i = 0; i < size; i++) { + bool hidden = false; + Process* p = ProcessList_get(this, i); + + if ( (!p->show) + || (userOnly && (p->st_uid != userId)) + || (filtering && !(String_contains_i(p->comm, incFilter))) ) + hidden = true; + + if (!hidden) { + Panel_set(this->panel, idx, (Object*)p); + if ((following == -1 && idx == currPos) || (following != -1 && p->pid == currPid)) { + Panel_setSelected(this->panel, idx); + this->panel->scrollV = currScrollV; + } + idx++; + } + } +} diff --git a/ProcessList.h b/ProcessList.h index 641a08c..d7a5ef9 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -9,32 +9,12 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#ifndef CONFIG_H -#define CONFIG_H -#include "config.h" -#endif - -#include "Process.h" #include "Vector.h" -#include "UsersTable.h" #include "Hashtable.h" -#include "String.h" - +#include "UsersTable.h" +#include "Panel.h" +#include "Process.h" #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "debug.h" -#include - #ifndef PROCDIR #define PROCDIR "/proc" @@ -111,6 +91,13 @@ typedef struct ProcessList_ { Hashtable* processTable; UsersTable* usersTable; + Panel* panel; + int following; + bool userOnly; + uid_t userId; + bool filtering; + const char* incFilter; + int cpuCount; int totalTasks; int userlandThreads; @@ -161,6 +148,8 @@ ProcessList* ProcessList_new(UsersTable* usersTable); void ProcessList_delete(ProcessList* this); +void ProcessList_setPanel(ProcessList* this, Panel* panel); + void ProcessList_invertSortOrder(ProcessList* this); void ProcessList_printHeader(ProcessList* this, RichString* header); @@ -194,4 +183,6 @@ ProcessField ProcessList_keyAt(ProcessList* this, int at); void ProcessList_expandTree(ProcessList* this); +void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, bool userOnly, uid_t userId, bool filtering, const char* incFilter); + #endif diff --git a/RichString.c b/RichString.c index 4c61709..eca2293 100644 --- a/RichString.c +++ b/RichString.c @@ -1,16 +1,21 @@ +/* +htop - RichString.c +(C) 2004,2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ #include "RichString.h" -#ifndef CONFIG_H -#define CONFIG_H -#include "config.h" -#endif - #include #include + +#define RICHSTRING_MAXLEN 300 + +/*{ +#include "config.h" #include -#include "debug.h" #include #ifdef HAVE_NCURSESW_CURSES_H #include @@ -22,10 +27,6 @@ #include #endif -#define RICHSTRING_MAXLEN 300 - -/*{ - #define RichString_size(this) ((this)->chlen) #define RichString_sizeVal(this) ((this).chlen) diff --git a/RichString.h b/RichString.h index a95726f..1b4d244 100644 --- a/RichString.h +++ b/RichString.h @@ -2,18 +2,18 @@ #ifndef HEADER_RichString #define HEADER_RichString +/* +htop - RichString.h +(C) 2004,2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ +#define RICHSTRING_MAXLEN 300 -#ifndef CONFIG_H -#define CONFIG_H #include "config.h" -#endif - -#include -#include #include -#include "debug.h" #include #ifdef HAVE_NCURSESW_CURSES_H #include @@ -25,9 +25,6 @@ #include #endif -#define RICHSTRING_MAXLEN 300 - - #define RichString_size(this) ((this)->chlen) #define RichString_sizeVal(this) ((this).chlen) diff --git a/ScreenManager.c b/ScreenManager.c index 38d4e23..744ea2b 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -1,24 +1,24 @@ /* -htop +htop - ScreenManager.c (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ #include "ScreenManager.h" + #include "Panel.h" #include "Object.h" -#include "Vector.h" -#include "Header.h" -#include "FunctionBar.h" -#include "debug.h" #include #include - +#include #include /*{ +#include "FunctionBar.h" +#include "Vector.h" +#include "Header.h" typedef enum Orientation_ { VERTICAL, @@ -31,13 +31,14 @@ typedef struct ScreenManager_ { int x2; int y2; Orientation orientation; - Vector* items; + Vector* panels; Vector* fuBars; - int itemCount; + int panelCount; const FunctionBar* fuBar; const Header* header; time_t lastScan; bool owner; + bool allowFocusChange; } ScreenManager; }*/ @@ -51,29 +52,30 @@ ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation ori this->y2 = y2; this->fuBar = NULL; this->orientation = orientation; - this->items = Vector_new(PANEL_CLASS, owner, DEFAULT_SIZE, NULL); + this->panels = Vector_new(PANEL_CLASS, owner, DEFAULT_SIZE, NULL); this->fuBars = Vector_new(FUNCTIONBAR_CLASS, true, DEFAULT_SIZE, NULL); - this->itemCount = 0; + this->panelCount = 0; this->header = header; this->owner = owner; + this->allowFocusChange = true; return this; } void ScreenManager_delete(ScreenManager* this) { - Vector_delete(this->items); + Vector_delete(this->panels); Vector_delete(this->fuBars); free(this); } inline int ScreenManager_size(ScreenManager* this) { - return this->itemCount; + return this->panelCount; } void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int size) { if (this->orientation == HORIZONTAL) { int lastX = 0; - if (this->itemCount > 0) { - Panel* last = (Panel*) Vector_get(this->items, this->itemCount - 1); + if (this->panelCount > 0) { + Panel* last = (Panel*) Vector_get(this->panels, this->panelCount - 1); lastX = last->x + last->w + 1; } if (size > 0) { @@ -84,22 +86,22 @@ void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int Panel_move(item, lastX, this->y1); } // TODO: VERTICAL - Vector_add(this->items, item); + Vector_add(this->panels, item); if (fuBar) Vector_add(this->fuBars, fuBar); else Vector_add(this->fuBars, FunctionBar_new(NULL, NULL, NULL)); if (!this->fuBar && fuBar) this->fuBar = fuBar; item->needsRedraw = true; - this->itemCount++; + this->panelCount++; } Panel* ScreenManager_remove(ScreenManager* this, int idx) { - assert(this->itemCount > idx); - Panel* panel = (Panel*) Vector_remove(this->items, idx); + assert(this->panelCount > idx); + Panel* panel = (Panel*) Vector_remove(this->panels, idx); Vector_remove(this->fuBars, idx); this->fuBar = NULL; - this->itemCount--; + this->panelCount--; return panel; } @@ -108,15 +110,15 @@ void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) { this->y1 = y1; this->x2 = x2; this->y2 = y2; - int items = this->itemCount; + int panels = this->panelCount; int lastX = 0; - for (int i = 0; i < items - 1; i++) { - Panel* panel = (Panel*) Vector_get(this->items, i); + for (int i = 0; i < panels - 1; i++) { + Panel* panel = (Panel*) Vector_get(this->panels, i); Panel_resize(panel, panel->w, LINES-y1+y2); Panel_move(panel, lastX, y1); lastX = panel->x + panel->w + 1; } - Panel* panel = (Panel*) Vector_get(this->items, items-1); + Panel* panel = (Panel*) Vector_get(this->panels, panels-1); Panel_resize(panel, COLS-x1+x2-lastX, LINES-y1+y2); Panel_move(panel, lastX, y1); } @@ -125,7 +127,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { bool quit = false; int focus = 0; - Panel* panelFocus = (Panel*) Vector_get(this->items, focus); + Panel* panelFocus = (Panel*) Vector_get(this->panels, focus); if (this->fuBar) FunctionBar_draw(this->fuBar, NULL); @@ -133,19 +135,21 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { int ch = 0; while (!quit) { - int items = this->itemCount; + int panels = this->panelCount; if (this->header) { time_t now = time(NULL); if (now > this->lastScan) { ProcessList_scan(this->header->pl); + ProcessList_sort(this->header->pl); this->lastScan = now; } Header_draw(this->header); + ProcessList_rebuildPanel(this->header->pl, false, false, false, false, false, NULL); } - for (int i = 0; i < items; i++) { - Panel* panel = (Panel*) Vector_get(this->items, i); + for (int i = 0; i < panels; i++) { + Panel* panel = (Panel*) Vector_get(this->panels, i); Panel_draw(panel, i == focus); - if (i < items) { + if (i < panels) { if (this->orientation == HORIZONTAL) { mvvline(panel->y, panel->x+panel->w, ' ', panel->h+1); } @@ -166,8 +170,8 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { if (mevent.y == LINES - 1) { ch = FunctionBar_synthesizeEvent(this->fuBar, mevent.x); } else { - for (int i = 0; i < this->itemCount; i++) { - Panel* panel = (Panel*) Vector_get(this->items, i); + for (int i = 0; i < this->panelCount; i++) { + Panel* panel = (Panel*) Vector_get(this->panels, i); if (mevent.x > panel->x && mevent.x <= panel->x+panel->w && mevent.y > panel->y && mevent.y <= panel->y+panel->h) { focus = i; @@ -200,21 +204,25 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { } case KEY_LEFT: case KEY_CTRLB: + if (!this->allowFocusChange) + break; tryLeft: if (focus > 0) focus--; - panelFocus = (Panel*) Vector_get(this->items, focus); + panelFocus = (Panel*) Vector_get(this->panels, focus); if (Panel_size(panelFocus) == 0 && focus > 0) goto tryLeft; break; case KEY_RIGHT: case KEY_CTRLF: case 9: + if (!this->allowFocusChange) + break; tryRight: - if (focus < this->itemCount - 1) + if (focus < this->panelCount - 1) focus++; - panelFocus = (Panel*) Vector_get(this->items, focus); - if (Panel_size(panelFocus) == 0 && focus < this->itemCount - 1) + panelFocus = (Panel*) Vector_get(this->panels, focus); + if (Panel_size(panelFocus) == 0 && focus < this->panelCount - 1) goto tryRight; break; case KEY_F(10): diff --git a/ScreenManager.h b/ScreenManager.h index e169c30..5179fe9 100644 --- a/ScreenManager.h +++ b/ScreenManager.h @@ -3,24 +3,15 @@ #ifndef HEADER_ScreenManager #define HEADER_ScreenManager /* -htop +htop - ScreenManager.h (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "Panel.h" -#include "Object.h" +#include "FunctionBar.h" #include "Vector.h" #include "Header.h" -#include "FunctionBar.h" - -#include "debug.h" -#include -#include - -#include - typedef enum Orientation_ { VERTICAL, @@ -33,13 +24,14 @@ typedef struct ScreenManager_ { int x2; int y2; Orientation orientation; - Vector* items; + Vector* panels; Vector* fuBars; - int itemCount; + int panelCount; const FunctionBar* fuBar; const Header* header; time_t lastScan; bool owner; + bool allowFocusChange; } ScreenManager; diff --git a/Settings.c b/Settings.c index 816a7ec..f2573e8 100644 --- a/Settings.c +++ b/Settings.c @@ -6,15 +6,21 @@ in the source distribution for its full text. */ #include "Settings.h" + #include "String.h" -#include "ProcessList.h" -#include "Header.h" +#include "Vector.h" -#include "debug.h" +#include +#include +#include +#include #define DEFAULT_DELAY 15 /*{ +#include "ProcessList.h" +#include "Header.h" +#include typedef struct Settings_ { char* userSettings; @@ -56,13 +62,10 @@ static void Settings_readMeterModes(Settings* this, char* line, HeaderSide side) } static bool Settings_read(Settings* this, char* fileName, int cpuCount) { - // TODO: implement File object and make - // file I/O object-oriented. - FILE* fd; - fd = fopen(fileName, "r"); - if (fd == NULL) { + FILE* fd = fopen(fileName, "r"); + if (!fd) return false; - } + const int maxLine = 2048; char buffer[maxLine]; bool readMeters = false; @@ -212,21 +215,47 @@ Settings* Settings_new(ProcessList* pl, Header* header, int cpuCount) { Settings* this = malloc(sizeof(Settings)); this->pl = pl; this->header = header; - const char* home; - char* rcfile; - home = getenv("HOME_ETC"); - if (!home) home = getenv("HOME"); - if (!home) home = ""; - rcfile = getenv("HOMERC"); - if (!rcfile) - this->userSettings = String_cat(home, "/.htoprc"); - else - this->userSettings = String_copy(rcfile); + char* legacyDotfile = NULL; + char* rcfile = getenv("HTOPRC"); + if (rcfile) { + this->userSettings = strdup(rcfile); + } else { + const char* home = getenv("HOME"); + if (!home) home = ""; + const char* xdgConfigHome = getenv("XDG_CONFIG_HOME"); + char* configDir = NULL; + char* htopDir = NULL; + if (xdgConfigHome) { + this->userSettings = String_cat(xdgConfigHome, "/htop/htoprc"); + configDir = strdup(xdgConfigHome); + htopDir = String_cat(xdgConfigHome, "/htop"); + } else { + this->userSettings = String_cat(home, "/.config/htop/htoprc"); + configDir = String_cat(home, "/.config"); + htopDir = String_cat(home, "/.config/htop"); + } + legacyDotfile = String_cat(home, "/.htoprc"); + mkdir(configDir, 0700); + mkdir(htopDir, 0700); + free(htopDir); + free(configDir); + if (access(legacyDotfile, R_OK) != 0) { + free(legacyDotfile); + legacyDotfile = NULL; + } + } this->colorScheme = 0; this->changed = false; this->delay = DEFAULT_DELAY; - bool ok = Settings_read(this, this->userSettings, cpuCount); - if (!ok) { + bool ok = Settings_read(this, legacyDotfile ? legacyDotfile : this->userSettings, cpuCount); + if (ok) { + if (legacyDotfile) { + // Transition to new location and delete old configuration file + if (Settings_write(this)) + unlink(legacyDotfile); + free(legacyDotfile); + } + } else { this->changed = true; // TODO: how to get SYSCONFDIR correctly through Autoconf? char* systemSettings = String_cat(SYSCONFDIR, "/htoprc"); diff --git a/Settings.h b/Settings.h index b75364e..af54222 100644 --- a/Settings.h +++ b/Settings.h @@ -9,14 +9,11 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "String.h" -#include "ProcessList.h" -#include "Header.h" - -#include "debug.h" - #define DEFAULT_DELAY 15 +#include "ProcessList.h" +#include "Header.h" +#include typedef struct Settings_ { char* userSettings; diff --git a/SignalsPanel.c b/SignalsPanel.c index f591e63..e1a88b5 100644 --- a/SignalsPanel.c +++ b/SignalsPanel.c @@ -1,15 +1,22 @@ +/* +htop - SignalsPanel.c +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ #include "SignalsPanel.h" -#include "Panel.h" + #include "ListItem.h" #include "RichString.h" -#include "debug.h" +#include #include #include /*{ +#include "Panel.h" typedef struct SignalItem_ { const char* name; diff --git a/SignalsPanel.h b/SignalsPanel.h index 83e8b7e..598c70f 100644 --- a/SignalsPanel.h +++ b/SignalsPanel.h @@ -2,16 +2,14 @@ #ifndef HEADER_SignalsPanel #define HEADER_SignalsPanel +/* +htop - SignalsPanel.h +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ #include "Panel.h" -#include "ListItem.h" -#include "RichString.h" - -#include "debug.h" -#include - -#include - typedef struct SignalItem_ { const char* name; diff --git a/String.c b/String.c index 81e9eee..adb6749 100644 --- a/String.c +++ b/String.c @@ -1,27 +1,23 @@ /* -htop +htop - String.c (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#define _GNU_SOURCE #include "String.h" + +#include "config.h" + #include #include #include #include -#include "debug.h" - /*{ #define String_startsWith(s, match) (strstr((s), (match)) == (s)) }*/ -inline char* String_copy(const char* orig) { - return strdup(orig); -} - char* String_cat(const char* s1, const char* s2) { int l1 = strlen(s1); int l2 = strlen(s2); diff --git a/String.h b/String.h index 1d1534f..0662aa1 100644 --- a/String.h +++ b/String.h @@ -3,23 +3,14 @@ #ifndef HEADER_String #define HEADER_String /* -htop +htop - String.h (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include -#include -#include -#include - -#include "debug.h" - #define String_startsWith(s, match) (strstr((s), (match)) == (s)) -extern char* String_copy(const char* orig); - char* String_cat(const char* s1, const char* s2); char* String_trim(const char* in); diff --git a/SwapMeter.c b/SwapMeter.c index 403b057..48a7dae 100644 --- a/SwapMeter.c +++ b/SwapMeter.c @@ -1,13 +1,13 @@ /* -htop +htop - SwapMeter.c (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ #include "SwapMeter.h" -#include "Meter.h" +#include "CRT.h" #include "ProcessList.h" #include @@ -15,10 +15,12 @@ in the source distribution for its full text. #include #include #include - -#include "debug.h" #include +/*{ +#include "Meter.h" +}*/ + #define KILOBYTE 1 #define MEGABYTE 1024 #define GIGABYTE 1048576 diff --git a/SwapMeter.h b/SwapMeter.h index 6bdd130..5b5c940 100644 --- a/SwapMeter.h +++ b/SwapMeter.h @@ -3,7 +3,7 @@ #ifndef HEADER_SwapMeter #define HEADER_SwapMeter /* -htop +htop - SwapMeter.h (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. @@ -11,17 +11,6 @@ in the source distribution for its full text. #include "Meter.h" -#include "ProcessList.h" - -#include -#include -#include -#include -#include - -#include "debug.h" -#include - #define KILOBYTE 1 #define MEGABYTE 1024 #define GIGABYTE 1048576 diff --git a/TasksMeter.c b/TasksMeter.c index 999c681..cfe0309 100644 --- a/TasksMeter.c +++ b/TasksMeter.c @@ -1,18 +1,18 @@ /* -htop +htop - TasksMeter.c (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ #include "TasksMeter.h" -#include "Meter.h" #include "ProcessList.h" - #include "CRT.h" -#include "debug.h" +/*{ +#include "Meter.h" +}*/ int TasksMeter_attributes[] = { TASKS_RUNNING diff --git a/TasksMeter.h b/TasksMeter.h index ea39a41..cc6a60a 100644 --- a/TasksMeter.h +++ b/TasksMeter.h @@ -3,7 +3,7 @@ #ifndef HEADER_TasksMeter #define HEADER_TasksMeter /* -htop +htop - TasksMeter.h (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. @@ -11,12 +11,6 @@ in the source distribution for its full text. #include "Meter.h" -#include "ProcessList.h" - -#include "CRT.h" - -#include "debug.h" - extern int TasksMeter_attributes[]; extern MeterType TasksMeter; diff --git a/TraceScreen.c b/TraceScreen.c index d66d20a..c7250f6 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -5,24 +5,28 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "config.h" +#include "TraceScreen.h" + +#include "CRT.h" +#include "ProcessList.h" +#include "ListItem.h" + #include #include +#include +#include #include #include #include #include #include +#include -#include "TraceScreen.h" -#include "ProcessList.h" +/*{ #include "Process.h" -#include "ListItem.h" #include "Panel.h" #include "FunctionBar.h" -/*{ - typedef struct TraceScreen_ { Process* process; Panel* display; diff --git a/TraceScreen.h b/TraceScreen.h index 7c509d2..62fb67a 100644 --- a/TraceScreen.h +++ b/TraceScreen.h @@ -9,22 +9,10 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "config.h" -#include -#include -#include -#include -#include -#include -#include - -#include "ProcessList.h" #include "Process.h" -#include "ListItem.h" #include "Panel.h" #include "FunctionBar.h" - typedef struct TraceScreen_ { Process* process; Panel* display; diff --git a/UptimeMeter.c b/UptimeMeter.c index 3aa7897..d31f911 100644 --- a/UptimeMeter.c +++ b/UptimeMeter.c @@ -1,18 +1,20 @@ /* -htop +htop - UptimeMeter.c (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ #include "UptimeMeter.h" -#include "Meter.h" #include "ProcessList.h" - #include "CRT.h" -#include "debug.h" +#include + +/*{ +#include "Meter.h" +}*/ int UptimeMeter_attributes[] = { UPTIME diff --git a/UptimeMeter.h b/UptimeMeter.h index 3397bbc..78814de 100644 --- a/UptimeMeter.h +++ b/UptimeMeter.h @@ -3,7 +3,7 @@ #ifndef HEADER_UptimeMeter #define HEADER_UptimeMeter /* -htop +htop - UptimeMeter.h (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. @@ -11,12 +11,6 @@ in the source distribution for its full text. #include "Meter.h" -#include "ProcessList.h" - -#include "CRT.h" - -#include "debug.h" - extern int UptimeMeter_attributes[]; extern MeterType UptimeMeter; diff --git a/UsersTable.c b/UsersTable.c index 1c56da4..ecabb0a 100644 --- a/UsersTable.c +++ b/UsersTable.c @@ -6,18 +6,20 @@ in the source distribution for its full text. */ #include "UsersTable.h" -#include "Hashtable.h" -#include "String.h" + +#include "config.h" #include +#include #include #include #include - -#include "debug.h" +#include #include /*{ +#include "Hashtable.h" + typedef struct UsersTable_ { Hashtable* users; } UsersTable; @@ -40,7 +42,7 @@ char* UsersTable_getRef(UsersTable* this, unsigned int uid) { if (name == NULL) { struct passwd* userData = getpwuid(uid); if (userData != NULL) { - name = String_copy(userData->pw_name); + name = strdup(userData->pw_name); Hashtable_put(this->users, uid, name); } } diff --git a/UsersTable.h b/UsersTable.h index 7a591f7..93ece0d 100644 --- a/UsersTable.h +++ b/UsersTable.h @@ -10,15 +10,6 @@ in the source distribution for its full text. */ #include "Hashtable.h" -#include "String.h" - -#include -#include -#include -#include - -#include "debug.h" -#include typedef struct UsersTable_ { Hashtable* users; diff --git a/Vector.c b/Vector.c index e4d5d5c..955d99c 100644 --- a/Vector.c +++ b/Vector.c @@ -1,20 +1,19 @@ /* -htop +htop - Vector.c (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ #include "Vector.h" -#include "Object.h" + +#include #include #include #include -#include "debug.h" -#include - /*{ +#include "Object.h" #define swap(a_,x_,y_) do{ void* tmp_ = a_[x_]; a_[x_] = a_[y_]; a_[y_] = tmp_; }while(0) diff --git a/Vector.h b/Vector.h index 20c0036..24e2976 100644 --- a/Vector.h +++ b/Vector.h @@ -3,20 +3,13 @@ #ifndef HEADER_Vector #define HEADER_Vector /* -htop +htop - Vector.h (C) 2004-2011 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ #include "Object.h" -#include -#include -#include - -#include "debug.h" -#include - #define swap(a_,x_,y_) do{ void* tmp_ = a_[x_]; a_[x_] = a_[y_]; a_[y_] = tmp_; }while(0) diff --git a/config.h b/config.h index 580ede3..24abfcb 100644 --- a/config.h +++ b/config.h @@ -146,7 +146,7 @@ #define PACKAGE_NAME "htop" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "htop 1.0" +#define PACKAGE_STRING "htop 1.0.1" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "htop" @@ -155,7 +155,7 @@ #define PACKAGE_URL "" /* Define to the version of this package. */ -#define PACKAGE_VERSION "1.0" +#define PACKAGE_VERSION "1.0.1" /* Path of proc filesystem */ #define PROCDIR "/proc" @@ -189,7 +189,7 @@ /* Version number of package */ -#define VERSION "1.0" +#define VERSION "1.0.1" /* Define to 1 if on MINIX. */ /* #undef _MINIX */ diff --git a/configure b/configure index 552499a..18aa703 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.65 for htop 1.0. +# Generated by GNU Autoconf 2.65 for htop 1.0.1. # # Report bugs to . # @@ -562,8 +562,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='htop' PACKAGE_TARNAME='htop' -PACKAGE_VERSION='1.0' -PACKAGE_STRING='htop 1.0' +PACKAGE_VERSION='1.0.1' +PACKAGE_STRING='htop 1.0.1' PACKAGE_BUGREPORT='loderunner@users.sourceforge.net' PACKAGE_URL='' @@ -1286,7 +1286,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures htop 1.0 to adapt to many kinds of systems. +\`configure' configures htop 1.0.1 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1357,7 +1357,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of htop 1.0:";; + short | recursive ) echo "Configuration of htop 1.0.1:";; esac cat <<\_ACEOF @@ -1471,7 +1471,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -htop configure 1.0 +htop configure 1.0.1 generated by GNU Autoconf 2.65 Copyright (C) 2009 Free Software Foundation, Inc. @@ -1896,7 +1896,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by htop $as_me 1.0, which was +It was created by htop $as_me 1.0.1, which was generated by GNU Autoconf 2.65. Invocation command line was $ $0 $@ @@ -4130,7 +4130,7 @@ fi # Define the identity of the package. PACKAGE='htop' - VERSION='1.0' + VERSION='1.0.1' cat >>confdefs.h <<_ACEOF @@ -12452,7 +12452,7 @@ if test ! -z "$missing_headers"; then as_fn_error "missing headers: $missing_headers" "$LINENO" 5 fi -if test "$cross_compiling" = "no"; then +if test "x$cross_compiling" = xno; then as_ac_File=`$as_echo "ac_cv_file_$PROCDIR/stat" | $as_tr_sh` { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $PROCDIR/stat" >&5 $as_echo_n "checking for $PROCDIR/stat... " >&6; } @@ -12510,7 +12510,7 @@ else enable_native_affinity="yes" fi -if test "x$enable_native_affinity" = xyes; then +if test "x$enable_native_affinity" = xyes -a "x$cross_compiling" = xno; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for usable sched_setaffinity" >&5 $as_echo_n "checking for usable sched_setaffinity... " >&6; } if test "$cross_compiling" = yes; then : @@ -12540,19 +12540,22 @@ main () } _ACEOF if ac_fn_c_try_run "$LINENO"; then : - -$as_echo "#define HAVE_NATIVE_AFFINITY 1" >>confdefs.h - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 + enable_native_affinity=no + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi +fi +if test "x$enable_native_affinity" = xyes; then + +$as_echo "#define HAVE_NATIVE_AFFINITY 1" >>confdefs.h + fi # Check whether --enable-hwloc was given. @@ -13150,7 +13153,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by htop $as_me 1.0, which was +This file was extended by htop $as_me 1.0.1, which was generated by GNU Autoconf 2.65. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -13216,7 +13219,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -htop config.status 1.0 +htop config.status 1.0.1 configured by $0, generated by GNU Autoconf 2.65, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 83a096e..639d048 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.65) -AC_INIT([htop],[1.0],[loderunner@users.sourceforge.net]) +AC_INIT([htop],[1.0.1],[loderunner@users.sourceforge.net]) # The following two lines are required by hwloc scripts AC_USE_SYSTEM_EXTENSIONS @@ -108,13 +108,13 @@ if test ! -z "$missing_headers"; then AC_MSG_ERROR([missing headers: $missing_headers]) fi -if test "$cross_compiling" = "no"; then +if test "x$cross_compiling" = xno; then AC_CHECK_FILE($PROCDIR/stat,,AC_MSG_ERROR(Cannot find /proc/stat. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help.)) AC_CHECK_FILE($PROCDIR/meminfo,,AC_MSG_ERROR(Cannot find /proc/meminfo. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help.)) fi AC_ARG_ENABLE(native_affinity, [AC_HELP_STRING([--enable-native-affinity], [enable native sched_setaffinity and sched_getaffinity for affinity support, disables hwloc])], ,enable_native_affinity="yes") -if test "x$enable_native_affinity" = xyes; then +if test "x$enable_native_affinity" = xyes -a "x$cross_compiling" = xno; then AC_MSG_CHECKING([for usable sched_setaffinity]) AC_RUN_IFELSE([ AC_LANG_PROGRAM([[ @@ -126,9 +126,12 @@ if test "x$enable_native_affinity" = xyes; then sched_setaffinity(0, sizeof(cpu_set_t), &cpuset); if (errno == ENOSYS) return 1; ]])], - [AC_DEFINE(HAVE_NATIVE_AFFINITY, 1, [Define if native sched_setaffinity and sched_getaffinity are to be used.]) - AC_MSG_RESULT([yes])], - [AC_MSG_RESULT([no])]) + [AC_MSG_RESULT([yes])], + [enable_native_affinity=no + AC_MSG_RESULT([no])]) +fi +if test "x$enable_native_affinity" = xyes; then + AC_DEFINE(HAVE_NATIVE_AFFINITY, 1, [Define if native sched_setaffinity and sched_getaffinity are to be used.]) fi AC_ARG_ENABLE(hwloc, [AC_HELP_STRING([--enable-hwloc], [enable hwloc support for CPU affinity])],, enable_hwloc="no") diff --git a/debug.h b/debug.h deleted file mode 100644 index ec2f883..0000000 --- a/debug.h +++ /dev/null @@ -1,28 +0,0 @@ - -#if defined(DEBUG) - - /* Full debug */ - #include "DebugMemory.h" - #define calloc(a, b) DebugMemory_calloc(a, b, __FILE__, __LINE__) - #define malloc(x) DebugMemory_malloc(x, __FILE__, __LINE__, #x) - #define realloc(x,s) DebugMemory_realloc(x, s, __FILE__, __LINE__, #x) - #define strdup(x) DebugMemory_strdup(x, __FILE__, __LINE__) - #define free(x) DebugMemory_free(x, __FILE__, __LINE__) - #define debug_done() DebugMemory_report(); _nc_freeall() - -#elif defined(DEBUGLITE) - - /* Assertions and core only */ - #ifdef NDEBUG - #undef NDEBUG - #endif - #define debug_done() - -#else - - /* No debugging */ - #define NDEBUG - #define debug_done() - -#endif - diff --git a/htop.1 b/htop.1 index 40df697..6b201c6 100644 --- a/htop.1 +++ b/htop.1 @@ -1,4 +1,4 @@ -.TH "HTOP" "1" "2011" "htop 1.0" "Utils" +.TH "HTOP" "1" "2011" "htop 1.0.1" "Utils" .SH "NAME" htop \- interactive process viewer .SH "SYNOPSIS" diff --git a/htop.c b/htop.c index ff58d20..dd76071 100644 --- a/htop.c +++ b/htop.c @@ -5,16 +5,8 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include - #include "ProcessList.h" + #include "CRT.h" #include "Panel.h" #include "UsersTable.h" @@ -23,14 +15,25 @@ in the source distribution for its full text. #include "ScreenManager.h" #include "FunctionBar.h" #include "ListItem.h" +#include "String.h" +#include "ColumnsPanel.h" #include "CategoriesPanel.h" #include "SignalsPanel.h" #include "TraceScreen.h" #include "OpenFilesScreen.h" #include "AffinityPanel.h" -#include "config.h" -#include "debug.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include //#link m @@ -199,6 +202,7 @@ static Object* pickFromVector(Panel* panel, Panel* list, int x, int y, const cha if (!list->eventHandler) Panel_setEventHandler(list, Panel_selectByTyping); ScreenManager* scr = ScreenManager_new(0, y, 0, -1, HORIZONTAL, header, false); + scr->allowFocusChange = false; ScreenManager_add(scr, list, FunctionBar_new(keyLabels, fuKeys, fuEvents), x - 1); ScreenManager_add(scr, panel, NULL, -1); Panel* panelFocus; @@ -331,7 +335,6 @@ int main(int argc, char** argv) { exit(1); } - Panel* panel; int quit = 0; int refreshTimeout = 0; int resetRefreshTimeout = 5; @@ -384,10 +387,11 @@ int main(int argc, char** argv) { break; } - CRT_init(settings->delay, settings->colorScheme); + + Panel* panel = Panel_new(0, headerHeight, COLS, LINES - headerHeight - 2, PROCESS_CLASS, false, NULL); + ProcessList_setPanel(pl, panel); - panel = Panel_new(0, headerHeight, COLS, LINES - headerHeight - 2, PROCESS_CLASS, false, NULL); if (sortKey > 0) { pl->sortKey = sortKey; pl->treeView = false; @@ -436,15 +440,10 @@ int main(int argc, char** argv) { gettimeofday(&tv, NULL); newTime = ((double)tv.tv_sec * 10) + ((double)tv.tv_usec / 100000); recalculate = (newTime - oldTime > CRT_delay); + int following = follow ? ((Process*)Panel_getSelected(panel))->pid : -1; if (recalculate) oldTime = newTime; if (doRefresh) { - - int currPos = Panel_getSelectedIndex(panel); - pid_t currPid = 0; - int currScrollV = panel->scrollV; - if (follow) - currPid = ProcessList_get(pl, currPos)->pid; if (recalculate || doRecalculate) { ProcessList_scan(pl); doRecalculate = false; @@ -453,27 +452,7 @@ int main(int argc, char** argv) { ProcessList_sort(pl); refreshTimeout = 1; } - Panel_prune(panel); - int size = ProcessList_size(pl); - int idx = 0; - for (int i = 0; i < size; i++) { - bool hidden = false; - Process* p = ProcessList_get(pl, i); - - if ( (!p->show) - || (userOnly && (p->st_uid != userId)) - || (filtering && !(String_contains_i(p->comm, incFilter.buffer))) ) - hidden = true; - - if (!hidden) { - Panel_set(panel, idx, (Object*)p); - if ((!follow && idx == currPos) || (follow && p->pid == currPid)) { - Panel_setSelected(panel, idx); - panel->scrollV = currScrollV; - } - idx++; - } - } + ProcessList_rebuildPanel(pl, true, following, userOnly, userId, filtering, incFilter.buffer); } doRefresh = true; @@ -746,6 +725,19 @@ int main(int argc, char** argv) { if (!killPanel) { killPanel = (Panel*) SignalsPanel_new(0, 0, 0, 0); } + bool anyTagged = false; + pid_t selectedPid; + for (int i = 0; i < Panel_size(panel); i++) { + Process* p = (Process*) Panel_get(panel, i); + if (p->tag) { + anyTagged = true; + break; + } + } + if (!anyTagged) { + Process* p = (Process*) Panel_getSelected(panel); + selectedPid = p->pid; + } SignalsPanel_reset((SignalsPanel*) killPanel); const char* fuFunctions[] = {"Send ", "Cancel ", NULL}; ListItem* sgn = (ListItem*) pickFromVector(panel, killPanel, 15, headerHeight, fuFunctions, defaultBar, header); @@ -754,17 +746,18 @@ int main(int argc, char** argv) { Panel_setHeader(panel, "Sending..."); Panel_draw(panel, true); refresh(); - bool anyTagged = false; - for (int i = 0; i < Panel_size(panel); i++) { - Process* p = (Process*) Panel_get(panel, i); - if (p->tag) { - Process_sendSignal(p, sgn->key); - anyTagged = true; + if (anyTagged) { + for (int i = 0; i < Panel_size(panel); i++) { + Process* p = (Process*) Panel_get(panel, i); + if (p->tag) { + Process_sendSignal(p, sgn->key); + anyTagged = true; + } } - } - if (!anyTagged) { + } else { Process* p = (Process*) Panel_getSelected(panel); - Process_sendSignal(p, sgn->key); + if (p->pid == selectedPid) + Process_sendSignal(p, sgn->key); } napms(500); } @@ -780,6 +773,7 @@ int main(int argc, char** argv) { break; Affinity* affinity = Process_getAffinity((Process*) Panel_getSelected(panel)); + if (!affinity) break; Panel* affinityPanel = AffinityPanel_new(pl, affinity); Affinity_delete(affinity); @@ -921,6 +915,5 @@ int main(int argc, char** argv) { ((Object*)killPanel)->delete((Object*)killPanel); UsersTable_delete(ut); Settings_delete(settings); - debug_done(); return 0; } diff --git a/htop.h b/htop.h index f0b5282..227f36d 100644 --- a/htop.h +++ b/htop.h @@ -9,33 +9,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include - -#include "ProcessList.h" -#include "CRT.h" -#include "Panel.h" -#include "UsersTable.h" -#include "RichString.h" -#include "Settings.h" -#include "ScreenManager.h" -#include "FunctionBar.h" -#include "ListItem.h" -#include "CategoriesPanel.h" -#include "SignalsPanel.h" -#include "TraceScreen.h" -#include "OpenFilesScreen.h" -#include "AffinityPanel.h" - -#include "config.h" -#include "debug.h" - //#link m #define INCSEARCH_MAX 40 diff --git a/scripts/MakeHeader.py b/scripts/MakeHeader.py index a84ae74..55eeed4 100755 --- a/scripts/MakeHeader.py +++ b/scripts/MakeHeader.py @@ -30,6 +30,7 @@ out.write( "" ) out.write( "#ifndef HEADER_" + name ) out.write( "#define HEADER_" + name ) +is_blank = False for line in file.readlines(): line = line[:-1] if state == ANY: @@ -37,6 +38,8 @@ for line in file.readlines(): state = COPY elif line == selfheader: pass + elif line.find("#include") == 0: + pass elif line.find("htop - ") == 0 and line[-2:] == ".c": out.write(line[:-2] + ".h") elif line.find("static ") != -1: @@ -58,14 +61,22 @@ for line in file.readlines(): state = SKIP else: out.write( line ) + is_blank = False + elif line == "": + if not is_blank: + out.write( line ) + is_blank = True else: out.write( line ) + is_blank = False elif state == COPY: + is_blank = False if line == "}*/": state = ANY else: out.write( line ) elif state == SKIP: + is_blank = False if len(line) >= 1 and line[0] == "}": if static == 1: state = SKIPONE @@ -73,6 +84,7 @@ for line in file.readlines(): state = ANY static = 0 elif state == SKIPONE: + is_blank = False state = ANY out.write( "" ) -- cgit v1.2.3