From ea859f50d9438bc61ae96721a4d255b49de78653 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 11 Apr 2016 13:00:20 +0200 Subject: Imported Upstream version 0.6.2 --- AvailableMetersListBox.c | 43 ++-- CPUMeter.c | 121 +++++++---- CPUMeter.h | 31 +-- CRT.c | 13 +- CRT.h | 2 +- ChangeLog | 29 +++ CheckItem.c | 2 +- CheckItem.h | 2 +- ClockMeter.c | 54 ++--- ClockMeter.h | 22 +- ColorsListBox.c | 3 +- DebugMemory.c | 2 + FunctionBar.c | 2 +- FunctionBar.h | 2 +- Hashtable.c | 2 +- Hashtable.h | 2 +- Header.c | 80 ++++---- Header.h | 25 +-- ListBox.c | 2 +- ListBox.h | 2 +- ListItem.c | 2 +- ListItem.h | 2 +- LoadAverageMeter.c | 81 +++++--- LoadAverageMeter.h | 18 +- LoadMeter.c | 63 ------ LoadMeter.h | 34 ---- Makefile.am | 13 +- Makefile.in | 102 +++++++--- MemoryMeter.c | 69 +++---- MemoryMeter.h | 17 +- Meter.c | 512 ++++++++++++++++++++++++++++------------------- Meter.h | 155 ++++++++++---- MetersListBox.c | 5 +- Object.c | 2 +- Object.h | 2 +- Process.c | 11 +- Process.h | 11 +- ProcessList.c | 147 +++++++++++--- ProcessList.h | 46 ++++- README | 10 +- ScreenManager.c | 2 +- ScreenManager.h | 2 +- Settings.c | 39 ++-- Settings.h | 10 +- SignalItem.c | 2 +- SignalItem.h | 2 +- String.c | 2 +- String.h | 2 +- SwapMeter.c | 53 ++--- SwapMeter.h | 15 +- TODO | 10 - TasksMeter.c | 45 ++--- TasksMeter.h | 15 +- TraceScreen.c | 7 +- TypedVector.c | 2 +- TypedVector.h | 2 +- UptimeMeter.c | 85 +++----- UptimeMeter.h | 21 +- UsersTable.c | 2 +- UsersTable.h | 2 +- config.h | 9 +- config.h.in | 3 + configure | 136 ++++++++++--- configure.ac | 21 +- depcomp | 57 +++++- htop.1 | 2 +- htop.c | 38 +++- htop.desktop | 12 ++ htop.h | 2 +- htop.png | Bin 0 -> 169 bytes install-sh | 477 ++++++++++++++++++++++--------------------- missing | 54 +++-- mkinstalldirs | 111 ---------- scripts/MakeHeader.py | 60 ++++++ 74 files changed, 1711 insertions(+), 1334 deletions(-) delete mode 100644 LoadMeter.c delete mode 100644 LoadMeter.h delete mode 100644 TODO create mode 100644 htop.desktop create mode 100644 htop.png delete mode 100755 mkinstalldirs create mode 100755 scripts/MakeHeader.py diff --git a/AvailableMetersListBox.c b/AvailableMetersListBox.c index 757cd59..88011ba 100644 --- a/AvailableMetersListBox.c +++ b/AvailableMetersListBox.c @@ -35,19 +35,23 @@ AvailableMetersListBox* AvailableMetersListBox_new(Settings* settings, ListBox* super->eventHandler = AvailableMetersListBox_EventHandler; ListBox_setHeader(super, "Available meters"); - ListBox_add(super, (Object*) ListItem_new("Swap", 0)); - ListBox_add(super, (Object*) ListItem_new("Memory", 0)); - ListBox_add(super, (Object*) ListItem_new("Clock", 0)); - ListBox_add(super, (Object*) ListItem_new("Load", 0)); - ListBox_add(super, (Object*) ListItem_new("LoadAverage", 0)); - ListBox_add(super, (Object*) ListItem_new("Uptime", 0)); - ListBox_add(super, (Object*) ListItem_new("Tasks", 0)); - if (settings->pl->processorCount > 1) - ListBox_add(super, (Object*) ListItem_new("CPUAverage", 0)); - for (int i = 1; i <= settings->pl->processorCount; i++) { - char buffer[50]; - sprintf(buffer, "CPU(%d)", i); - ListBox_add(super, (Object*) ListItem_new(buffer, 0)); + for (int i = 1; Meter_types[i]; i++) { + MeterType* type = Meter_types[i]; + if (type != &CPUMeter) { + ListBox_add(super, (Object*) ListItem_new(type->uiName, i << 16)); + } + } + MeterType* type = &CPUMeter; + int processors = settings->pl->processorCount; + if (processors > 1) { + ListBox_add(super, (Object*) ListItem_new("CPU average", 0)); + for (int i = 1; i <= processors; i++) { + char buffer[50]; + sprintf(buffer, "%s %d", type->uiName, i); + ListBox_add(super, (Object*) ListItem_new(buffer, i)); + } + } else { + ListBox_add(super, (Object*) ListItem_new("CPU", 1)); } return this; } @@ -60,10 +64,8 @@ void AvailableMetersListBox_delete(Object* object) { } /* private */ -inline void AvailableMetersListBox_addHeader(Header* header, ListBox* lb, char* name, HeaderSide side) { - Header_createMeter(header, name, side); - int i = Header_size(header, side) - 1; - Meter* meter = (Meter*) Header_getMeter(header, i, side); +inline void AvailableMetersListBox_addHeader(Header* header, ListBox* lb, MeterType* type, int param, HeaderSide side) { + Meter* meter = (Meter*) Header_addMeter(header, type, param, side); ListBox_add(lb, (Object*) Meter_toListItem(meter)); } @@ -72,7 +74,8 @@ HandlerResult AvailableMetersListBox_EventHandler(ListBox* super, int ch) { Header* header = this->settings->header; ListItem* selected = (ListItem*) ListBox_getSelected(super); - char* name = selected->value; + int param = selected->key & 0xff; + int type = selected->key >> 16; HandlerResult result = IGNORED; switch(ch) { @@ -80,7 +83,7 @@ HandlerResult AvailableMetersListBox_EventHandler(ListBox* super, int ch) { case 'l': case 'L': { - AvailableMetersListBox_addHeader(header, this->leftBox, name, LEFT_HEADER); + AvailableMetersListBox_addHeader(header, this->leftBox, Meter_types[type], param, LEFT_HEADER); result = HANDLED; break; } @@ -88,7 +91,7 @@ HandlerResult AvailableMetersListBox_EventHandler(ListBox* super, int ch) { case 'r': case 'R': { - AvailableMetersListBox_addHeader(header, this->rightBox, name, RIGHT_HEADER); + AvailableMetersListBox_addHeader(header, this->rightBox, Meter_types[type], param, RIGHT_HEADER); result = HANDLED; break; } diff --git a/CPUMeter.c b/CPUMeter.c index c59c2c4..07c6a00 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -1,6 +1,6 @@ /* htop - CPUMeter.c -(C) 2004,2005 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -18,17 +18,37 @@ in the source distribution for its full text. #include "debug.h" #include -/*{ +/* private property */ +static int CPUMeter_attributes[] = { CPU_NICE, CPU_NORMAL, CPU_KERNEL }; -typedef struct CPUMeter_ CPUMeter; - -struct CPUMeter_ { - Meter super; - ProcessList* pl; - int processor; +/* private */ +MeterType CPUMeter = { + .setValues = CPUMeter_setValues, + .display = CPUMeter_display, + .mode = BAR_METERMODE, + .items = 3, + .total = 100.0, + .attributes = CPUMeter_attributes, + .name = "CPU", + .uiName = "CPU", + .caption = "CPU", + .init = CPUMeter_init }; -}*/ +/* private */ +MeterType AllCPUsMeter = { + .mode = 0, + .items = 1, + .total = 100.0, + .attributes = CPUMeter_attributes, + .name = "AllCPUs", + .uiName = "All CPUs", + .caption = "CPU", + .draw = AllCPUsMeter_draw, + .init = AllCPUsMeter_init, + .setMode = AllCPUsMeter_setMode, + .done = AllCPUsMeter_done +}; #ifndef MIN #define MIN(a,b) ((a)<(b)?(a):(b)) @@ -37,50 +57,73 @@ struct CPUMeter_ { #define MAX(a,b) ((a)>(b)?(a):(b)) #endif -CPUMeter* CPUMeter_new(ProcessList* pl, int processor) { - CPUMeter* this = malloc(sizeof(CPUMeter)); - char* caption; - if (pl->processorCount == 1 || processor == 0) { - caption = String_copy("CPU"); - } else { - caption = (char*) malloc(4); +void CPUMeter_init(Meter* this) { + int processor = this->param; + if (this->pl->processorCount > 1) { + char caption[10]; sprintf(caption, "%-3d", processor); + Meter_setCaption(this, caption); } - Meter_init((Meter*)this, NULL, caption, 3); - ((Meter*)this)->name = malloc(20); - sprintf(((Meter*)this)->name, "CPU(%d)", processor); - ((Meter*)this)->attributes[0] = CPU_NICE; - ((Meter*)this)->attributes[1] = CPU_NORMAL; - ((Meter*)this)->attributes[2] = CPU_KERNEL; - ((Meter*)this)->setValues = CPUMeter_setValues; - ((Object*)this)->display = CPUMeter_display; - ((Meter*)this)->total = 1.0; - Meter_setMode((Meter*)this, BAR); - this->processor = processor; - this->pl = pl; - return this; + if (this->param == 0) + Meter_setCaption(this, "Avg"); } -void CPUMeter_setValues(Meter* cast) { - CPUMeter* this = (CPUMeter*)cast; - cast->values[0] = this->pl->nicePeriod[this->processor] / (double)this->pl->totalPeriod[this->processor]; - cast->values[1] = this->pl->userPeriod[this->processor] / (double)this->pl->totalPeriod[this->processor]; - cast->values[2] = this->pl->systemPeriod[this->processor] / (double)this->pl->totalPeriod[this->processor]; - double cpu = MIN(100.0, MAX(0.0, (cast->values[0]+cast->values[1]+cast->values[2])*100.0 )); - snprintf(cast->displayBuffer.c, 7, "%5.1f%%", cpu ); +void CPUMeter_setValues(Meter* this, char* buffer, int size) { + ProcessList* pl = this->pl; + int processor = this->param; + double total = (double) pl->totalPeriod[processor]; + this->values[0] = pl->nicePeriod[processor] / total * 100.0; + this->values[1] = pl->userPeriod[processor] / total * 100.0; + this->values[2] = pl->systemPeriod[processor] / total * 100.0; + double cpu = MIN(100.0, MAX(0.0, (this->values[0]+this->values[1]+this->values[2]))); + snprintf(buffer, size, "%5.1f%%", cpu ); } void CPUMeter_display(Object* cast, RichString* out) { char buffer[50]; Meter* this = (Meter*)cast; RichString_prune(out); - sprintf(buffer, "%5.1f%% ", this->values[1] * 100.0); + sprintf(buffer, "%5.1f%% ", this->values[1]); RichString_append(out, CRT_colors[METER_TEXT], ":"); RichString_append(out, CRT_colors[CPU_NORMAL], buffer); - sprintf(buffer, "%5.1f%% ", this->values[2] * 100.0); + sprintf(buffer, "%5.1f%% ", this->values[2]); RichString_append(out, CRT_colors[METER_TEXT], "sys:"); RichString_append(out, CRT_colors[CPU_KERNEL], buffer); - sprintf(buffer, "%5.1f%% ", this->values[0] * 100.0); + sprintf(buffer, "%5.1f%% ", this->values[0]); RichString_append(out, CRT_colors[METER_TEXT], "low:"); RichString_append(out, CRT_colors[CPU_NICE], buffer); } + +void AllCPUsMeter_init(Meter* this) { + int processors = this->pl->processorCount; + this->drawBuffer = malloc(sizeof(Meter*) * processors); + Meter** meters = (Meter**) this->drawBuffer; + for (int i = 0; i < processors; i++) + meters[i] = Meter_new(this->pl, i+1, &CPUMeter); + this->h = processors; + this->mode = BAR_METERMODE; +} + +void AllCPUsMeter_done(Meter* this) { + int processors = this->pl->processorCount; + Meter** meters = (Meter**) this->drawBuffer; + for (int i = 0; i < processors; i++) + Meter_delete((Object*)meters[i]); +} + +void AllCPUsMeter_setMode(Meter* this, int mode) { + this->mode = mode; + int processors = this->pl->processorCount; + int h = Meter_modes[this->mode]->h; + this->h = h * processors; +} + +void AllCPUsMeter_draw(Meter* this, int x, int y, int w) { + int processors = this->pl->processorCount; + Meter** meters = (Meter**) this->drawBuffer; + for (int i = 0; i < processors; i++) { + Meter_setMode(meters[i], this->mode); + meters[i]->draw(meters[i], x, y, w); + y += meters[i]->h; + } +} diff --git a/CPUMeter.h b/CPUMeter.h index 87994db..f9f389a 100644 --- a/CPUMeter.h +++ b/CPUMeter.h @@ -1,10 +1,10 @@ -/* Do not edit this file. It was automatically genarated. */ +/* Do not edit this file. It was automatically generated. */ #ifndef HEADER_CPUMeter #define HEADER_CPUMeter /* -htop -(C) 2004 Hisham H. Muhammad +htop - CPUMeter.c +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -17,25 +17,32 @@ in the source distribution for its full text. #include #include #include -#include #include "debug.h" #include -typedef struct CPUMeter_ CPUMeter; -struct CPUMeter_ { - Meter super; - ProcessList* pl; - int processor; -}; +#ifndef MIN +#define MIN(a,b) ((a)<(b)?(a):(b)) +#endif +#ifndef MAX +#define MAX(a,b) ((a)>(b)?(a):(b)) +#endif -CPUMeter* CPUMeter_new(ProcessList* pl, int processor); +void CPUMeter_init(Meter* this); -void CPUMeter_setValues(Meter* cast); +void CPUMeter_setValues(Meter* this, char* buffer, int size); void CPUMeter_display(Object* cast, RichString* out); +void AllCPUsMeter_init(Meter* this); + +void AllCPUsMeter_done(Meter* this); + +void AllCPUsMeter_setMode(Meter* this, int mode); + +void AllCPUsMeter_draw(Meter* this, int x, int y, int w); + #endif diff --git a/CRT.c b/CRT.c index 910485e..6b1d120 100644 --- a/CRT.c +++ b/CRT.c @@ -1,6 +1,6 @@ /* htop - CRT.c -(C) 2004,2005 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -18,6 +18,13 @@ in the source distribution for its full text. #define ColorPair(i,j) COLOR_PAIR((7-i)*8+j) +#define COLORSCHEME_DEFAULT 0 +#define COLORSCHEME_MONOCHROME 1 +#define COLORSCHEME_BLACKONWHITE 2 +#define COLORSCHEME_BLACKONWHITE2 3 +#define COLORSCHEME_MIDNIGHT 4 +#define COLORSCHEME_BLACKNIGHT 5 + #define Black COLOR_BLACK #define Red COLOR_RED #define Green COLOR_GREEN @@ -93,6 +100,8 @@ extern int CRT_delay; extern int CRT_colors[LAST_COLORELEMENT]; +extern int CRT_colorScheme; + }*/ // TODO: centralize these in Settings. @@ -187,7 +196,7 @@ void CRT_handleSIGTERM(int signal) { void CRT_setColors(int colorScheme) { CRT_colorScheme = colorScheme; if (colorScheme == COLORSCHEME_BLACKNIGHT) { - for (int i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) init_pair((7-i)*8+j, i, j); } else { diff --git a/CRT.h b/CRT.h index 0cf2518..32a9481 100644 --- a/CRT.h +++ b/CRT.h @@ -4,7 +4,7 @@ #define HEADER_CRT /* htop - CRT.h -(C) 2004,2005 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/ChangeLog b/ChangeLog index 8e82693..b217c70 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,33 @@ +What's new in version 0.6.2 + +* BUGFIX: Fixed crash when using some .htoprc files from 0.6 + (thanks to Wolfram Schlich and John Thomas for the reports) +* BUGFIX: Ensure changes to color scheme are saved +* BUGFIX: Make configure behave correctly with --with-proc +* Minor addition to .desktop file. + +What's new in version 0.6.1 + +* New meter type: "All CPUs", which dynamically adjusts + to the number of CPUs present in the machine. Note that + because of this, older versions of htop may crash when + using an .htoprc file modified my the newer version. +* Accept --with-proc= in configure, to specify + alternative procfs locations (making htop friendlier + to the Linux compatibility layer in FreeBSD) +* Included icon .desktop and desktop entry + (thanks to Peter Hyman) +* Added a check to make sure that a root-user htop closes + when its parent non-root terminal is closed. + (thanks to Ilya Evseev for the report) +* BUGFIX: does not crash anymore when $HOME is not set + (thanks to Henning Schild for the report) +* Wait for strace child process to die properly. + (thanks to Marcus Fritzsch) +* Support $HTOPRC + (thanks to Luis Limon) + What's new in version 0.6 * Configuration of columns merged into the Setup screen diff --git a/CheckItem.c b/CheckItem.c index 0c42867..ba5bd20 100644 --- a/CheckItem.c +++ b/CheckItem.c @@ -1,6 +1,6 @@ /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/CheckItem.h b/CheckItem.h index d3bffcc..6cba3e2 100644 --- a/CheckItem.h +++ b/CheckItem.h @@ -4,7 +4,7 @@ #define HEADER_CheckItem /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/ClockMeter.c b/ClockMeter.c index 2a27906..9e48c29 100644 --- a/ClockMeter.c +++ b/ClockMeter.c @@ -1,6 +1,6 @@ /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -8,47 +8,29 @@ in the source distribution for its full text. #include "ClockMeter.h" #include "Meter.h" -#include "ProcessList.h" - -#include #include #include "debug.h" -/*{ - -typedef struct ClockMeter_ ClockMeter; - -struct ClockMeter_ { - Meter super; - ProcessList* pl; - char clock[10]; +/* private */ +static int ClockMeter_attributes[] = { CLOCK }; + +/* private */ +MeterType ClockMeter = { + .setValues = ClockMeter_setValues, + .display = NULL, + .mode = TEXT_METERMODE, + .total = 100.0, + .items = 1, + .attributes = ClockMeter_attributes, + .name = "Clock", + .uiName = "Clock", + .caption = "Time: ", }; -}*/ - -ClockMeter* ClockMeter_new() { - ClockMeter* this = malloc(sizeof(ClockMeter)); - Meter_init((Meter*)this, String_copy("Clock"), String_copy("Time: "), 1); - ((Meter*)this)->attributes[0] = CLOCK; - ((Meter*)this)->setValues = ClockMeter_setValues; - ((Object*)this)->display = ClockMeter_display; - ((Meter*)this)->total = 24 * 60; - Meter_setMode((Meter*)this, TEXT); - return this; -} - -void ClockMeter_setValues(Meter* cast) { - ClockMeter* this = (ClockMeter*) cast; +void ClockMeter_setValues(Meter* this, char* buffer, int size) { time_t t = time(NULL); struct tm *lt = localtime(&t); - cast->values[0] = lt->tm_hour * 60 + lt->tm_min; - strftime(this->clock, 9, "%H:%M:%S", lt); - snprintf(cast->displayBuffer.c, 9, "%s", this->clock); -} - -void ClockMeter_display(Object* cast, RichString* out) { - Meter* super = (Meter*) cast; - ClockMeter* this = (ClockMeter*) cast; - RichString_write(out, CRT_colors[super->attributes[0]], this->clock); + this->values[0] = lt->tm_hour * 60 + lt->tm_min; + strftime(buffer, size, "%H:%M:%S", lt); } diff --git a/ClockMeter.h b/ClockMeter.h index 2e8fc86..7ca276e 100644 --- a/ClockMeter.h +++ b/ClockMeter.h @@ -1,37 +1,21 @@ -/* Do not edit this file. It was automatically genarated. */ +/* Do not edit this file. It was automatically generated. */ #ifndef HEADER_ClockMeter #define HEADER_ClockMeter /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ #include "Meter.h" -#include "ProcessList.h" - -#include #include #include "debug.h" -typedef struct ClockMeter_ ClockMeter; - -struct ClockMeter_ { - Meter super; - ProcessList* pl; - char clock[10]; -}; - - -ClockMeter* ClockMeter_new(); - -void ClockMeter_setValues(Meter* cast); - -void ClockMeter_display(Object* cast, RichString* out); +void ClockMeter_setValues(Meter* this, char* buffer, int size); #endif diff --git a/ColorsListBox.c b/ColorsListBox.c index 31cfc63..b47a398 100644 --- a/ColorsListBox.c +++ b/ColorsListBox.c @@ -28,7 +28,7 @@ typedef struct ColorsListBox_ { }*/ -/* private property */ +/* private */ static char* ColorSchemes[] = { "Default", "Monochromatic", @@ -85,6 +85,7 @@ HandlerResult ColorsListBox_EventHandler(ListBox* super, int ch) { } if (result == HANDLED) { + this->settings->changed = true; Header* header = this->settings->header; CRT_setColors(mark); ListBox* lbMenu = (ListBox*) TypedVector_get(this->scr->items, 0); diff --git a/DebugMemory.c b/DebugMemory.c index 8f28af6..6e5156d 100644 --- a/DebugMemory.c +++ b/DebugMemory.c @@ -141,6 +141,8 @@ void DebugMemory_registerAllocation(void* data, char* file, int line) { } void DebugMemory_registerDeallocation(void* data, char* file, int line) { + if (!data) + return; assert(singleton); assert(singleton->first); DebugMemoryItem* walk = singleton->first; diff --git a/FunctionBar.c b/FunctionBar.c index 02f3e0b..7f04d8e 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -1,6 +1,6 @@ /* htop - FunctionBar.c -(C) 2004,2005 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/FunctionBar.h b/FunctionBar.h index 5bb2161..05c8260 100644 --- a/FunctionBar.h +++ b/FunctionBar.h @@ -4,7 +4,7 @@ #define HEADER_FunctionBar /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/Hashtable.c b/Hashtable.c index 617a5be..759cbef 100644 --- a/Hashtable.c +++ b/Hashtable.c @@ -1,6 +1,6 @@ /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/Hashtable.h b/Hashtable.h index 2f52831..51d8704 100644 --- a/Hashtable.h +++ b/Hashtable.h @@ -4,7 +4,7 @@ #define HEADER_Hashtable /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/Header.c b/Header.c index c20066d..766dc75 100644 --- a/Header.c +++ b/Header.c @@ -1,19 +1,12 @@ /* htop - Header.c -(C) 2004,2005 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ #include "Header.h" -#include "CPUMeter.h" -#include "MemoryMeter.h" -#include "SwapMeter.h" -#include "LoadMeter.h" -#include "LoadAverageMeter.h" -#include "UptimeMeter.h" -#include "ClockMeter.h" -#include "TasksMeter.h" +#include "Meter.h" #include "debug.h" #include @@ -60,31 +53,22 @@ void Header_createMeter(Header* this, char* name, HeaderSide side) { ? this->leftMeters : this->rightMeters; - if (String_eq(name, "Swap")) { - TypedVector_add(meters, SwapMeter_new(this->pl)); - } else if (String_eq(name, "Memory")) { - TypedVector_add(meters, MemoryMeter_new(this->pl)); - } else if (String_eq(name, "Clock")) { - TypedVector_add(meters, ClockMeter_new(this->pl)); - } else if (String_eq(name, "Load")) { - TypedVector_add(meters, LoadMeter_new(this->pl)); - } else if (String_eq(name, "LoadAverage")) { - TypedVector_add(meters, LoadAverageMeter_new(this->pl)); - } else if (String_eq(name, "Uptime")) { - TypedVector_add(meters, UptimeMeter_new(this->pl)); - } else if (String_eq(name, "Tasks")) { - TypedVector_add(meters, TasksMeter_new(this->pl)); - } else if (String_startsWith(name, "CPUAverage")) { - TypedVector_add(meters, CPUMeter_new(this->pl, 0)); - } else if (String_startsWith(name, "CPU")) { - int num; - int ok = sscanf(name, "CPU(%d)", &num); - if (ok) - TypedVector_add(meters, CPUMeter_new(this->pl, num)); + char* paren = strchr(name, '('); + int param = 0; + if (paren) { + int ok = sscanf(paren, "(%d)", ¶m); + if (!ok) param = 0; + *paren = '\0'; + } + for (MeterType** type = Meter_types; *type; type++) { + if (String_eq(name, (*type)->name)) { + TypedVector_add(meters, Meter_new(this->pl, param, *type)); + break; + } } } -void Header_setMode(Header* this, int i, MeterMode mode, HeaderSide side) { +void Header_setMode(Header* this, int i, MeterModeId mode, HeaderSide side) { TypedVector* meters = side == LEFT_HEADER ? this->leftMeters : this->rightMeters; @@ -93,12 +77,14 @@ void Header_setMode(Header* this, int i, MeterMode mode, HeaderSide side) { Meter_setMode(meter, mode); } -Meter* Header_getMeter(Header* this, int i, HeaderSide side) { +Meter* Header_addMeter(Header* this, MeterType* type, int param, HeaderSide side) { TypedVector* meters = side == LEFT_HEADER ? this->leftMeters : this->rightMeters; - return (Meter*) TypedVector_get(meters, i); + Meter* meter = Meter_new(this->pl, param, type); + TypedVector_add(meters, meter); + return meter; } int Header_size(Header* this, HeaderSide side) { @@ -113,12 +99,20 @@ char* Header_readMeterName(Header* this, int i, HeaderSide side) { TypedVector* meters = side == LEFT_HEADER ? this->leftMeters : this->rightMeters; - Meter* meter = (Meter*) TypedVector_get(meters, i); - return meter->name; + + int nameLen = strlen(meter->type->name); + int len = nameLen + 100; + char* name = malloc(len); + strncpy(name, meter->type->name, nameLen); + name[nameLen] = '\0'; + if (meter->param) + snprintf(name + nameLen, len - nameLen, "(%d)", meter->param); + + return name; } -MeterMode Header_readMeterMode(Header* this, int i, HeaderSide side) { +MeterModeId Header_readMeterMode(Header* this, int i, HeaderSide side) { TypedVector* meters = side == LEFT_HEADER ? this->leftMeters : this->rightMeters; @@ -128,14 +122,12 @@ MeterMode Header_readMeterMode(Header* this, int i, HeaderSide side) { } void Header_defaultMeters(Header* this) { - for (int i = 1; i <= this->pl->processorCount; i++) { - TypedVector_add(this->leftMeters, CPUMeter_new(this->pl, i)); - } - TypedVector_add(this->leftMeters, MemoryMeter_new(this->pl)); - TypedVector_add(this->leftMeters, SwapMeter_new(this->pl)); - TypedVector_add(this->rightMeters, TasksMeter_new(this->pl)); - TypedVector_add(this->rightMeters, LoadAverageMeter_new(this->pl)); - TypedVector_add(this->rightMeters, UptimeMeter_new(this->pl)); + TypedVector_add(this->leftMeters, Meter_new(this->pl, 0, &AllCPUsMeter)); + TypedVector_add(this->leftMeters, Meter_new(this->pl, 0, &MemoryMeter)); + TypedVector_add(this->leftMeters, Meter_new(this->pl, 0, &SwapMeter)); + TypedVector_add(this->rightMeters, Meter_new(this->pl, 0, &TasksMeter)); + TypedVector_add(this->rightMeters, Meter_new(this->pl, 0, &LoadAverageMeter)); + TypedVector_add(this->rightMeters, Meter_new(this->pl, 0, &UptimeMeter)); } void Header_draw(Header* this) { diff --git a/Header.h b/Header.h index 59ac9af..96cedb6 100644 --- a/Header.h +++ b/Header.h @@ -1,22 +1,15 @@ -/* Do not edit this file. It was automatically genarated. */ +/* Do not edit this file. It was automatically generated. */ #ifndef HEADER_Header #define HEADER_Header /* -htop -(C) 2004 Hisham H. Muhammad +htop - Header.c +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#include "CPUMeter.h" -#include "MemoryMeter.h" -#include "SwapMeter.h" -#include "LoadMeter.h" -#include "LoadAverageMeter.h" -#include "UptimeMeter.h" -#include "ClockMeter.h" -#include "TasksMeter.h" +#include "Meter.h" #include "debug.h" #include @@ -37,21 +30,25 @@ typedef struct Header_ { } Header; +#ifndef MAX +#define MAX(a,b) ((a)>(b)?(a):(b)) +#endif + Header* Header_new(ProcessList* pl); void Header_delete(Header* this); void Header_createMeter(Header* this, char* name, HeaderSide side); -void Header_setMode(Header* this, int i, MeterMode mode, HeaderSide side); +void Header_setMode(Header* this, int i, MeterModeId mode, HeaderSide side); -Meter* Header_getMeter(Header* this, int i, HeaderSide side); +Meter* Header_addMeter(Header* this, MeterType* type, int param, HeaderSide side); int Header_size(Header* this, HeaderSide side); char* Header_readMeterName(Header* this, int i, HeaderSide side); -MeterMode Header_readMeterMode(Header* this, int i, HeaderSide side); +MeterModeId Header_readMeterMode(Header* this, int i, HeaderSide side); void Header_defaultMeters(Header* this); diff --git a/ListBox.c b/ListBox.c index 6076236..4a4b4f7 100644 --- a/ListBox.c +++ b/ListBox.c @@ -1,6 +1,6 @@ /* htop - ListBox.c -(C) 2004,2005 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/ListBox.h b/ListBox.h index 750bcfd..e89ec06 100644 --- a/ListBox.h +++ b/ListBox.h @@ -4,7 +4,7 @@ #define HEADER_ListBox /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/ListItem.c b/ListItem.c index 95b5677..1889a35 100644 --- a/ListItem.c +++ b/ListItem.c @@ -1,6 +1,6 @@ /* htop - ListItem.c -(C) 2004,2005 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/ListItem.h b/ListItem.h index 580cbc8..17b2fcf 100644 --- a/ListItem.h +++ b/ListItem.h @@ -4,7 +4,7 @@ #define HEADER_ListItem /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c index 824e71c..4f62260 100644 --- a/LoadAverageMeter.c +++ b/LoadAverageMeter.c @@ -1,6 +1,6 @@ /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -8,42 +8,44 @@ in the source distribution for its full text. #include "LoadAverageMeter.h" #include "Meter.h" -#include "ProcessList.h" - #include #include "debug.h" -/*{ - -typedef struct LoadAverageMeter_ LoadAverageMeter; +/* private property */ +int LoadAverageMeter_attributes[] = { LOAD_AVERAGE_FIFTEEN, LOAD_AVERAGE_FIVE, LOAD_AVERAGE_ONE }; -struct LoadAverageMeter_ { - Meter super; - ProcessList* pl; +/* private */ +MeterType LoadAverageMeter = { + .setValues = LoadAverageMeter_setValues, + .display = LoadAverageMeter_display, + .mode = TEXT_METERMODE, + .items = 3, + .total = 100.0, + .attributes = LoadAverageMeter_attributes, + .name = "LoadAverage", + .uiName = "Load average", + .caption = "Load average: " }; -}*/ - /* private property */ -void LoadAverageMeter_scan(double* one, double* five, double* fifteen); +int LoadMeter_attributes[] = { LOAD }; -LoadAverageMeter* LoadAverageMeter_new() { - LoadAverageMeter* this = malloc(sizeof(LoadAverageMeter)); - Meter_init((Meter*)this, String_copy("LoadAverage"), String_copy("Load average: "), 3); - ((Meter*)this)->attributes[0] = LOAD_AVERAGE_FIFTEEN; - ((Meter*)this)->attributes[1] = LOAD_AVERAGE_FIVE; - ((Meter*)this)->attributes[2] = LOAD_AVERAGE_ONE; - ((Object*)this)->display = LoadAverageMeter_display; - ((Meter*)this)->setValues = LoadAverageMeter_setValues; - Meter_setMode((Meter*)this, TEXT); - LoadAverageMeter_scan(&((Meter*)this)->values[0], &((Meter*)this)->values[1], &((Meter*)this)->values[2]); - ((Meter*)this)->total = 100.0; - return this; -} +/* private */ +MeterType LoadMeter = { + .setValues = LoadMeter_setValues, + .display = LoadMeter_display, + .mode = TEXT_METERMODE, + .items = 1, + .total = 100.0, + .attributes = LoadMeter_attributes, + .name = "Load", + .uiName = "Load", + .caption = "Load: " +}; /* private */ -void LoadAverageMeter_scan(double* one, double* five, double* fifteen) { +inline static void LoadAverageMeter_scan(double* one, double* five, double* fifteen) { int activeProcs, totalProcs, lastProc; FILE *fd = fopen(PROCDIR "/loadavg", "r"); int read = fscanf(fd, "%lf %lf %lf %d/%d %d", one, five, fifteen, @@ -53,9 +55,9 @@ void LoadAverageMeter_scan(double* one, double* five, double* fifteen) { fclose(fd); } -void LoadAverageMeter_setValues(Meter* cast) { - LoadAverageMeter_scan(&cast->values[2], &cast->values[1], &cast->values[0]); - snprintf(cast->displayBuffer.c, 25, "%.2f/%.2f/%.2f", cast->values[2], cast->values[1], cast->values[0]); +void LoadAverageMeter_setValues(Meter* this, char* buffer, int size) { + LoadAverageMeter_scan(&this->values[2], &this->values[1], &this->values[0]); + snprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[2], this->values[1], this->values[0]); } void LoadAverageMeter_display(Object* cast, RichString* out) { @@ -63,9 +65,26 @@ void LoadAverageMeter_display(Object* cast, RichString* out) { char buffer[20]; RichString_prune(out); sprintf(buffer, "%.2f ", this->values[2]); - RichString_append(out, CRT_colors[LOAD_AVERAGE_ONE], buffer); + RichString_append(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer); sprintf(buffer, "%.2f ", this->values[1]); RichString_append(out, CRT_colors[LOAD_AVERAGE_FIVE], buffer); sprintf(buffer, "%.2f ", this->values[0]); - RichString_append(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer); + RichString_append(out, CRT_colors[LOAD_AVERAGE_ONE], buffer); +} + +void LoadMeter_setValues(Meter* this, char* buffer, int size) { + double five, fifteen; + LoadAverageMeter_scan(&this->values[0], &five, &fifteen); + if (this->values[0] > this->total) { + this->total = this->values[0]; + } + snprintf(buffer, size, "%.2f", this->values[0]); +} + +void LoadMeter_display(Object* cast, RichString* out) { + Meter* this = (Meter*)cast; + char buffer[20]; + RichString_prune(out); + sprintf(buffer, "%.2f ", ((Meter*)this)->values[0]); + RichString_append(out, CRT_colors[LOAD], buffer); } diff --git a/LoadAverageMeter.h b/LoadAverageMeter.h index 8528fd4..27e33a1 100644 --- a/LoadAverageMeter.h +++ b/LoadAverageMeter.h @@ -1,37 +1,31 @@ -/* Do not edit this file. It was automatically genarated. */ +/* Do not edit this file. It was automatically generated. */ #ifndef HEADER_LoadAverageMeter #define HEADER_LoadAverageMeter /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ #include "Meter.h" -#include "ProcessList.h" - #include #include "debug.h" -typedef struct LoadAverageMeter_ LoadAverageMeter; -struct LoadAverageMeter_ { - Meter super; - ProcessList* pl; -}; -LoadAverageMeter* LoadAverageMeter_new(); +void LoadAverageMeter_setValues(Meter* this, char* buffer, int size); +void LoadAverageMeter_display(Object* cast, RichString* out); -void LoadAverageMeter_setValues(Meter* cast); +void LoadMeter_setValues(Meter* this, char* buffer, int size); -void LoadAverageMeter_display(Object* cast, RichString* out); +void LoadMeter_display(Object* cast, RichString* out); #endif diff --git a/LoadMeter.c b/LoadMeter.c deleted file mode 100644 index b93f305..0000000 --- a/LoadMeter.c +++ /dev/null @@ -1,63 +0,0 @@ -/* -htop -(C) 2004 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file -in the source distribution for its full text. -*/ - -#include "LoadMeter.h" -#include "Meter.h" - -#include "ProcessList.h" - -#include "debug.h" - -/*{ - -typedef struct LoadMeter_ LoadMeter; - -struct LoadMeter_ { - Meter super; - ProcessList* pl; -}; - -}*/ - -LoadMeter* LoadMeter_new() { - LoadMeter* this = malloc(sizeof(LoadMeter)); - Meter_init((Meter*)this, String_copy("Load"), String_copy("Load: "), 1); - ((Meter*)this)->attributes[0] = LOAD; - ((Meter*)this)->setValues = LoadMeter_setValues; - ((Object*)this)->display = LoadMeter_display; - Meter_setMode((Meter*)this, GRAPH); - ((Meter*)this)->total = 1.0; - return this; -} - -/* private */ -void LoadMeter_scan(double* one, double* five, double* fifteen) { - int activeProcs, totalProcs, lastProc; - FILE *fd = fopen(PROCDIR "/loadavg", "r"); - int read = fscanf(fd, "%lf %lf %lf %d/%d %d", one, five, fifteen, - &activeProcs, &totalProcs, &lastProc); - (void) read; - assert(read == 6); - fclose(fd); -} - -void LoadMeter_setValues(Meter* cast) { - double five, fifteen; - LoadMeter_scan(&cast->values[0], &five, &fifteen); - if (cast->values[0] > cast->total) { - cast->total = cast->values[0]; - } - snprintf(cast->displayBuffer.c, 7, "%.2f", cast->values[0]); -} - -void LoadMeter_display(Object* cast, RichString* out) { - LoadMeter* this = (LoadMeter*)cast; - char buffer[20]; - RichString_prune(out); - sprintf(buffer, "%.2f ", ((Meter*)this)->values[0]); - RichString_append(out, CRT_colors[LOAD], buffer); -} diff --git a/LoadMeter.h b/LoadMeter.h deleted file mode 100644 index f880bbe..0000000 --- a/LoadMeter.h +++ /dev/null @@ -1,34 +0,0 @@ -/* Do not edit this file. It was automatically genarated. */ - -#ifndef HEADER_LoadMeter -#define HEADER_LoadMeter -/* -htop -(C) 2004 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file -in the source distribution for its full text. -*/ - -#include "Meter.h" - -#include "ProcessList.h" - -#include "debug.h" - - -typedef struct LoadMeter_ LoadMeter; - -struct LoadMeter_ { - Meter super; - ProcessList* pl; -}; - - -LoadMeter* LoadMeter_new(); - - -void LoadMeter_setValues(Meter* cast); - -void LoadMeter_display(Object* cast, RichString* out); - -#endif diff --git a/Makefile.am b/Makefile.am index ede3484..1a568f2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,11 @@ bin_PROGRAMS = htop dist_man_MANS = htop.1 -EXTRA_DIST = $(dist_man_MANS) +EXTRA_DIST = $(dist_man_MANS) htop.desktop htop.png scripts/MakeHeader.py +applicationsdir = $(datadir)/applications +applications_DATA = htop.desktop +pixmapdir = $(datadir)/pixmaps +pixmap_DATA = htop.png AM_CFLAGS = -pedantic -Wall -std=c99 AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\" @@ -9,16 +13,19 @@ AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\" htop_SOURCES = AvailableMetersListBox.c CategoriesListBox.c ClockMeter.c \ CPUMeter.c CRT.c DebugMemory.c DisplayOptionsListBox.c FunctionBar.c \ Hashtable.c Header.c htop.c ListBox.c ListItem.c LoadAverageMeter.c \ -LoadMeter.c MemoryMeter.c Meter.c MetersListBox.c Object.c Process.c \ +MemoryMeter.c Meter.c MetersListBox.c Object.c Process.c \ ProcessList.c RichString.c ScreenManager.c Settings.c SignalItem.c \ SignalsListBox.c String.c SwapMeter.c TasksMeter.c TypedVector.c \ UptimeMeter.c UsersTable.c AvailableMetersListBox.h CategoriesListBox.h \ ClockMeter.h config.h CPUMeter.h CRT.h debug.h DebugMemory.h \ DisplayOptionsListBox.h FunctionBar.h Hashtable.h Header.h htop.h ListBox.h \ -ListItem.h LoadAverageMeter.h LoadMeter.h MemoryMeter.h Meter.h \ +ListItem.h LoadAverageMeter.h MemoryMeter.h Meter.h \ MetersListBox.h Object.h Process.h ProcessList.h RichString.h ScreenManager.h \ Settings.h SignalItem.h SignalsListBox.h String.h SwapMeter.h TasksMeter.h \ TypedVector.h UptimeMeter.h UsersTable.h CheckItem.c CheckItem.h \ ColorsListBox.c ColorsListBox.h TraceScreen.c TraceScreen.h \ AvailableColumnsListBox.c AvailableColumnsListBox.h ColumnsListBox.c \ ColumnsListBox.h + +debug: + $(MAKE) all CFLAGS="-g -DDEBUG" diff --git a/Makefile.in b/Makefile.in index 6af6ff9..29db495 100644 --- a/Makefile.in +++ b/Makefile.in @@ -14,6 +14,7 @@ @SET_MAKE@ + SOURCES = $(htop_SOURCES) srcdir = @srcdir@ @@ -41,18 +42,17 @@ subdir = . DIST_COMMON = README $(am__configure_deps) $(dist_man_MANS) \ $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ $(srcdir)/config.h.in $(top_srcdir)/configure AUTHORS COPYING \ - ChangeLog INSTALL NEWS TODO depcomp install-sh missing \ - mkinstalldirs + ChangeLog INSTALL NEWS depcomp install-sh missing ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ configure.lineno configure.status.lineno -mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +mkinstalldirs = $(mkdir_p) CONFIG_HEADER = config.h CONFIG_CLEAN_FILES = -am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)" +am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)" "$(DESTDIR)$(applicationsdir)" "$(DESTDIR)$(pixmapdir)" binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) PROGRAMS = $(bin_PROGRAMS) am_htop_OBJECTS = AvailableMetersListBox.$(OBJEXT) \ @@ -61,13 +61,12 @@ am_htop_OBJECTS = AvailableMetersListBox.$(OBJEXT) \ DisplayOptionsListBox.$(OBJEXT) FunctionBar.$(OBJEXT) \ Hashtable.$(OBJEXT) Header.$(OBJEXT) htop.$(OBJEXT) \ ListBox.$(OBJEXT) ListItem.$(OBJEXT) \ - LoadAverageMeter.$(OBJEXT) LoadMeter.$(OBJEXT) \ - MemoryMeter.$(OBJEXT) Meter.$(OBJEXT) MetersListBox.$(OBJEXT) \ - Object.$(OBJEXT) Process.$(OBJEXT) ProcessList.$(OBJEXT) \ - RichString.$(OBJEXT) ScreenManager.$(OBJEXT) \ - Settings.$(OBJEXT) SignalItem.$(OBJEXT) \ - SignalsListBox.$(OBJEXT) String.$(OBJEXT) SwapMeter.$(OBJEXT) \ - TasksMeter.$(OBJEXT) TypedVector.$(OBJEXT) \ + LoadAverageMeter.$(OBJEXT) MemoryMeter.$(OBJEXT) \ + Meter.$(OBJEXT) MetersListBox.$(OBJEXT) Object.$(OBJEXT) \ + Process.$(OBJEXT) ProcessList.$(OBJEXT) RichString.$(OBJEXT) \ + ScreenManager.$(OBJEXT) Settings.$(OBJEXT) \ + SignalItem.$(OBJEXT) SignalsListBox.$(OBJEXT) String.$(OBJEXT) \ + SwapMeter.$(OBJEXT) TasksMeter.$(OBJEXT) TypedVector.$(OBJEXT) \ UptimeMeter.$(OBJEXT) UsersTable.$(OBJEXT) CheckItem.$(OBJEXT) \ ColorsListBox.$(OBJEXT) TraceScreen.$(OBJEXT) \ AvailableColumnsListBox.$(OBJEXT) ColumnsListBox.$(OBJEXT) @@ -89,7 +88,6 @@ am__depfiles_maybe = depfiles @AMDEP_TRUE@ ./$(DEPDIR)/Hashtable.Po ./$(DEPDIR)/Header.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/ListBox.Po ./$(DEPDIR)/ListItem.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/LoadAverageMeter.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/LoadMeter.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/MemoryMeter.Po ./$(DEPDIR)/Meter.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/MetersListBox.Po ./$(DEPDIR)/Object.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/Process.Po ./$(DEPDIR)/ProcessList.Po \ @@ -112,6 +110,9 @@ DIST_SOURCES = $(htop_SOURCES) man1dir = $(mandir)/man1 NROFF = nroff MANS = $(dist_man_MANS) +applicationsDATA_INSTALL = $(INSTALL_DATA) +pixmapDATA_INSTALL = $(INSTALL_DATA) +DATA = $(applications_DATA) $(pixmap_DATA) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -195,19 +196,23 @@ sharedstatedir = @sharedstatedir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ dist_man_MANS = htop.1 -EXTRA_DIST = $(dist_man_MANS) +EXTRA_DIST = $(dist_man_MANS) htop.desktop htop.png scripts/MakeHeader.py +applicationsdir = $(datadir)/applications +applications_DATA = htop.desktop +pixmapdir = $(datadir)/pixmaps +pixmap_DATA = htop.png AM_CFLAGS = -pedantic -Wall -std=c99 AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\" htop_SOURCES = AvailableMetersListBox.c CategoriesListBox.c ClockMeter.c \ CPUMeter.c CRT.c DebugMemory.c DisplayOptionsListBox.c FunctionBar.c \ Hashtable.c Header.c htop.c ListBox.c ListItem.c LoadAverageMeter.c \ -LoadMeter.c MemoryMeter.c Meter.c MetersListBox.c Object.c Process.c \ +MemoryMeter.c Meter.c MetersListBox.c Object.c Process.c \ ProcessList.c RichString.c ScreenManager.c Settings.c SignalItem.c \ SignalsListBox.c String.c SwapMeter.c TasksMeter.c TypedVector.c \ UptimeMeter.c UsersTable.c AvailableMetersListBox.h CategoriesListBox.h \ ClockMeter.h config.h CPUMeter.h CRT.h debug.h DebugMemory.h \ DisplayOptionsListBox.h FunctionBar.h Hashtable.h Header.h htop.h ListBox.h \ -ListItem.h LoadAverageMeter.h LoadMeter.h MemoryMeter.h Meter.h \ +ListItem.h LoadAverageMeter.h MemoryMeter.h Meter.h \ MetersListBox.h Object.h Process.h ProcessList.h RichString.h ScreenManager.h \ Settings.h SignalItem.h SignalsListBox.h String.h SwapMeter.h TasksMeter.h \ TypedVector.h UptimeMeter.h UsersTable.h CheckItem.c CheckItem.h \ @@ -320,7 +325,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ListBox.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ListItem.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LoadAverageMeter.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LoadMeter.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MemoryMeter.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Meter.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MetersListBox.Po@am__quote@ @@ -402,6 +406,40 @@ uninstall-man1: echo " rm -f '$(DESTDIR)$(man1dir)/$$inst'"; \ rm -f "$(DESTDIR)$(man1dir)/$$inst"; \ done +install-applicationsDATA: $(applications_DATA) + @$(NORMAL_INSTALL) + test -z "$(applicationsdir)" || $(mkdir_p) "$(DESTDIR)$(applicationsdir)" + @list='$(applications_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(applicationsDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(applicationsdir)/$$f'"; \ + $(applicationsDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(applicationsdir)/$$f"; \ + done + +uninstall-applicationsDATA: + @$(NORMAL_UNINSTALL) + @list='$(applications_DATA)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f '$(DESTDIR)$(applicationsdir)/$$f'"; \ + rm -f "$(DESTDIR)$(applicationsdir)/$$f"; \ + done +install-pixmapDATA: $(pixmap_DATA) + @$(NORMAL_INSTALL) + test -z "$(pixmapdir)" || $(mkdir_p) "$(DESTDIR)$(pixmapdir)" + @list='$(pixmap_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(pixmapDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(pixmapdir)/$$f'"; \ + $(pixmapDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(pixmapdir)/$$f"; \ + done + +uninstall-pixmapDATA: + @$(NORMAL_UNINSTALL) + @list='$(pixmap_DATA)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f '$(DESTDIR)$(pixmapdir)/$$f'"; \ + rm -f "$(DESTDIR)$(pixmapdir)/$$f"; \ + done ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ @@ -454,6 +492,7 @@ distclean-tags: distdir: $(DISTFILES) $(am__remove_distdir) mkdir $(distdir) + $(mkdir_p) $(distdir)/scripts @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ list='$(DISTFILES)'; for file in $$list; do \ @@ -579,9 +618,9 @@ distcleancheck: distclean exit 1; } >&2 check-am: all-am check: check-am -all-am: Makefile $(PROGRAMS) $(MANS) config.h +all-am: Makefile $(PROGRAMS) $(MANS) $(DATA) config.h installdirs: - for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"; do \ + for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)" "$(DESTDIR)$(applicationsdir)" "$(DESTDIR)$(pixmapdir)"; do \ test -z "$$dir" || $(mkdir_p) "$$dir"; \ done install: install-am @@ -629,7 +668,8 @@ info: info-am info-am: -install-data-am: install-man +install-data-am: install-applicationsDATA install-man \ + install-pixmapDATA install-exec-am: install-binPROGRAMS @@ -658,7 +698,8 @@ ps: ps-am ps-am: -uninstall-am: uninstall-binPROGRAMS uninstall-info-am uninstall-man +uninstall-am: uninstall-applicationsDATA uninstall-binPROGRAMS \ + uninstall-info-am uninstall-man uninstall-pixmapDATA uninstall-man: uninstall-man1 @@ -668,14 +709,19 @@ uninstall-man: uninstall-man1 distclean-compile distclean-generic distclean-hdr \ distclean-tags distcleancheck distdir distuninstallcheck dvi \ dvi-am html html-am info info-am install install-am \ - install-binPROGRAMS install-data install-data-am install-exec \ - install-exec-am install-info install-info-am install-man \ - install-man1 install-strip installcheck installcheck-am \ - installdirs maintainer-clean maintainer-clean-generic \ - mostlyclean mostlyclean-compile mostlyclean-generic pdf pdf-am \ - ps ps-am tags uninstall uninstall-am uninstall-binPROGRAMS \ - uninstall-info-am uninstall-man uninstall-man1 - + install-applicationsDATA install-binPROGRAMS install-data \ + install-data-am install-exec install-exec-am install-info \ + install-info-am install-man install-man1 install-pixmapDATA \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-applicationsDATA \ + uninstall-binPROGRAMS uninstall-info-am uninstall-man \ + uninstall-man1 uninstall-pixmapDATA + + +debug: + $(MAKE) all CFLAGS="-g -DDEBUG" # 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. .NOEXPORT: diff --git a/MemoryMeter.c b/MemoryMeter.c index 5efa5b7..d4f6722 100644 --- a/MemoryMeter.c +++ b/MemoryMeter.c @@ -1,6 +1,6 @@ /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -19,61 +19,42 @@ in the source distribution for its full text. #include "debug.h" #include -/*{ +/* private property */ +static int MemoryMeter_attributes[] = { MEMORY_USED, MEMORY_BUFFERS, MEMORY_CACHE }; -typedef struct MemoryMeter_ MemoryMeter; - -struct MemoryMeter_ { - Meter super; - ProcessList* pl; - char* wideFormat; - int wideLimit; +/* private */ +MeterType MemoryMeter = { + .setValues = MemoryMeter_setValues, + .display = MemoryMeter_display, + .mode = BAR_METERMODE, + .items = 3, + .total = 100.0, + .attributes = MemoryMeter_attributes, + "Memory", + "Memory", + "Mem" }; -}*/ - -MemoryMeter* MemoryMeter_new(ProcessList* pl) { - MemoryMeter* this = malloc(sizeof(MemoryMeter)); - Meter_init((Meter*)this, String_copy("Memory"), String_copy("Mem"), 3); - ((Meter*)this)->attributes[0] = MEMORY_USED; - ((Meter*)this)->attributes[1] = MEMORY_BUFFERS; - ((Meter*)this)->attributes[2] = MEMORY_CACHE; - ((Meter*)this)->setValues = MemoryMeter_setValues; - ((Object*)this)->display = MemoryMeter_display; - this->pl = pl; - Meter_setMode((Meter*)this, BAR); - this->wideFormat = "%6ldk "; - this->wideLimit = 22 + 8 * 4; - return this; -} - -void MemoryMeter_setValues(Meter* cast) { - MemoryMeter* this = (MemoryMeter*)cast; - - double totalMem = (double)this->pl->totalMem; +void MemoryMeter_setValues(Meter* this, char* buffer, int size) { long int usedMem = this->pl->usedMem; long int buffersMem = this->pl->buffersMem; long int cachedMem = this->pl->cachedMem; usedMem -= buffersMem + cachedMem; - cast->total = totalMem; - cast->values[0] = usedMem; - cast->values[1] = buffersMem; - cast->values[2] = cachedMem; - snprintf(cast->displayBuffer.c, 14, "%ld/%ldMB", usedMem / 1024, this->pl->totalMem / 1024); + this->total = this->pl->totalMem; + this->values[0] = usedMem; + this->values[1] = buffersMem; + this->values[2] = cachedMem; + snprintf(buffer, size, "%ld/%ldMB", (long int) usedMem / 1024, (long int) this->total / 1024); } void MemoryMeter_display(Object* cast, RichString* out) { char buffer[50]; - MemoryMeter* this = (MemoryMeter*)cast; - Meter* meter = (Meter*)cast; + Meter* this = (Meter*)cast; int div = 1024; char* format = "%ldM "; - if (meter->w > this->wideLimit) { - div = 1; format = this->wideFormat; - } - long int totalMem = meter->total / div; - long int usedMem = meter->values[0] / div; - long int buffersMem = meter->values[1] / div; - long int cachedMem = meter->values[2] / div; + long int totalMem = this->total / div; + long int usedMem = this->values[0] / div; + long int buffersMem = this->values[1] / div; + long int cachedMem = this->values[2] / div; RichString_prune(out); RichString_append(out, CRT_colors[METER_TEXT], ":"); sprintf(buffer, format, totalMem); diff --git a/MemoryMeter.h b/MemoryMeter.h index 7bab321..e2f42e0 100644 --- a/MemoryMeter.h +++ b/MemoryMeter.h @@ -1,10 +1,10 @@ -/* Do not edit this file. It was automatically genarated. */ +/* Do not edit this file. It was automatically generated. */ #ifndef HEADER_MemoryMeter #define HEADER_MemoryMeter /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -23,19 +23,8 @@ in the source distribution for its full text. #include -typedef struct MemoryMeter_ MemoryMeter; -struct MemoryMeter_ { - Meter super; - ProcessList* pl; - char* wideFormat; - int wideLimit; -}; - - -MemoryMeter* MemoryMeter_new(ProcessList* pl); - -void MemoryMeter_setValues(Meter* cast); +void MemoryMeter_setValues(Meter* this, char* buffer, int size); void MemoryMeter_display(Object* cast, RichString* out); diff --git a/Meter.c b/Meter.c index c35b6a9..973a63e 100644 --- a/Meter.c +++ b/Meter.c @@ -1,142 +1,294 @@ /* htop - Meter.c -(C) 2004,2005 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad 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 "Meter.h" #include "Object.h" #include "CRT.h" #include "ListItem.h" #include "String.h" - -#include -#include -#include -#include +#include "ProcessList.h" #include "debug.h" #include -#define METER_BARBUFFER_LEN 128 -#define METER_GRAPHBUFFER_LEN 128 +#ifndef USE_FUNKY_MODES +#define USE_FUNKY_MODES 1 +#endif + +#define METER_BUFFER_LEN 128 /*{ typedef struct Meter_ Meter; +typedef struct MeterType_ MeterType; +typedef struct MeterMode_ MeterMode; -typedef void(*Meter_SetValues)(Meter*); +typedef void(*MeterType_Init)(Meter*); +typedef void(*MeterType_Done)(Meter*); +typedef void(*MeterType_SetMode)(Meter*, int); +typedef void(*Meter_SetValues)(Meter*, char*, int); typedef void(*Meter_Draw)(Meter*, int, int, int); -typedef enum MeterMode_ { - UNSET, - BAR, - TEXT, - GRAPH, - LED, - LAST_METERMODE -} MeterMode; - -struct Meter_ { - Object super; - - int h; - int w; +struct MeterMode_ { Meter_Draw draw; + char* uiName; + int h; +}; + +struct MeterType_ { Meter_SetValues setValues; + Object_Display display; + int mode; int items; + double total; int* attributes; + char* name; + char* uiName; + char* caption; + MeterType_Init init; + MeterType_Done done; + MeterType_SetMode setMode; + Meter_Draw draw; +}; + +struct Meter_ { + Object super; + char* caption; + MeterType* type; + int mode; + int param; + Meter_Draw draw; + void* drawBuffer; + int h; + ProcessList* pl; double* values; double total; - char* caption; - char* name; - union { - RichString* rs; - char* c; - double* graph; - } displayBuffer; - MeterMode mode; }; extern char* METER_CLASS; +extern MeterType CPUMeter; +extern MeterType ClockMeter; +extern MeterType LoadAverageMeter; +extern MeterType LoadMeter; +extern MeterType MemoryMeter; +extern MeterType SwapMeter; +extern MeterType TasksMeter; +extern MeterType UptimeMeter; +extern MeterType AllCPUsMeter; + +typedef enum { + CUSTOM_METERMODE = 0, + BAR_METERMODE, + TEXT_METERMODE, +#ifdef USE_FUNKY_MODES + GRAPH_METERMODE, + LED_METERMODE, +#endif + LAST_METERMODE +} MeterModeId; + +extern MeterType* Meter_types[]; +extern MeterMode* Meter_modes[]; + }*/ #ifndef MIN #define MIN(a,b) ((a)<(b)?(a):(b)) #endif +#ifndef MAX +#define MAX(a,b) ((a)>(b)?(a):(b)) +#endif /* private property */ char* METER_CLASS = "Meter"; /* private */ -char* Meter_ledDigits[3][10] = { - { " __ "," "," __ "," __ "," "," __ "," __ "," __ "," __ "," __ "}, - { "| |"," |"," __|"," __|","|__|","|__ ","|__ "," |","|__|","|__|"}, - { "|__|"," |","|__ "," __|"," |"," __|","|__|"," |","|__|"," __|"}, +MeterType* Meter_types[] = { + &CPUMeter, + &ClockMeter, + &LoadAverageMeter, + &LoadMeter, + &MemoryMeter, + &SwapMeter, + &TasksMeter, + &UptimeMeter, + &AllCPUsMeter, + NULL }; -/* private property */ -char Meter_barCharacters[] = "|#*@$%&"; +/* private */ +static MeterMode BarMeterMode = { + .uiName = "Bar", + .h = 1, + .draw = BarMeterMode_draw, +}; + +/* private */ +static MeterMode TextMeterMode = { + .uiName = "Text", + .h = 1, + .draw = TextMeterMode_draw, +}; + +#ifdef USE_FUNKY_MODES +/* private */ +static MeterMode GraphMeterMode = { + .uiName = "Graph", + .h = 3, + .draw = GraphMeterMode_draw, +}; + +/* private */ +static MeterMode LEDMeterMode = { + .uiName = "LED", + .h = 3, + .draw = LEDMeterMode_draw, +}; +#endif + +/* private */ +MeterMode* Meter_modes[] = { + NULL, + &BarMeterMode, + &TextMeterMode, +#ifdef USE_FUNKY_MODES + &GraphMeterMode, + &LEDMeterMode, +#endif + NULL +}; /* private property */ static RichString Meter_stringBuffer; -Meter* Meter_new(char* name, char* caption, int items) { - Meter* this = malloc(sizeof(Meter)); - Meter_init(this, name, caption, items); - return this; -} - -void Meter_init(Meter* this, char* name, char* caption, int items) { +Meter* Meter_new(ProcessList* pl, int param, MeterType* type) { + Meter* this = calloc(sizeof(Meter), 1); + this->h = 1; + this->type = type; + this->param = param; + this->pl = pl; + this->values = calloc(sizeof(double), type->items); + this->total = type->total; + this->caption = strdup(type->caption); ((Object*)this)->delete = Meter_delete; ((Object*)this)->class = METER_CLASS; - this->items = items; - this->name = name; - this->caption = caption; - this->attributes = malloc(sizeof(int) * items); - this->values = malloc(sizeof(double) * items); - this->displayBuffer.c = NULL; - this->mode = UNSET; - this->h = 0; + ((Object*)this)->display = type->display; + Meter_setMode(this, type->mode); + if (this->type->init) + this->type->init(this); + return this; } void Meter_delete(Object* cast) { Meter* this = (Meter*) cast; assert (this != NULL); - Meter_done(this); + if (this->type->done) { + this->type->done(this); + } + if (this->drawBuffer) + free(this->drawBuffer); + free(this->caption); + free(this->values); free(this); } +void Meter_setCaption(Meter* this, char* caption) { + free(this->caption); + this->caption = strdup(caption); +} + /* private */ -void Meter_freeBuffer(Meter* this) { - switch (this->mode) { - case BAR: { - free(this->displayBuffer.c); - break; - } - case GRAPH: { - free(this->displayBuffer.graph); - break; - } - default: { +inline static void Meter_displayToStringBuffer(Meter* this, char* buffer) { + MeterType* type = this->type; + Object_Display display = ((Object*)this)->display; + if (display) { + display((Object*)this, &Meter_stringBuffer); + } else { + RichString_prune(&Meter_stringBuffer); + RichString_append(&Meter_stringBuffer, CRT_colors[type->attributes[0]], buffer); } +} + +void Meter_setMode(Meter* this, int modeIndex) { + if (modeIndex > 0 && modeIndex == this->mode) + return; + if (!modeIndex) + modeIndex = 1; + assert(modeIndex < LAST_METERMODE); + if (this->type->mode == 0) { + this->draw = this->type->draw; + if (this->type->setMode) + this->type->setMode(this, modeIndex); + } else { + assert(modeIndex >= 1); + if (this->drawBuffer) + free(this->drawBuffer); + this->drawBuffer = NULL; + + MeterMode* mode = Meter_modes[modeIndex]; + this->draw = mode->draw; + this->h = mode->h; } - this->h = 0; + this->mode = modeIndex; } -void Meter_done(Meter* this) { - free(this->caption); - free(this->attributes); - free(this->values); - free(this->name); - Meter_freeBuffer(this); +ListItem* Meter_toListItem(Meter* this) { + MeterType* type = this->type; + char mode[21]; + if (this->mode) + snprintf(mode, 20, " [%s]", Meter_modes[this->mode]->uiName); + else + mode[0] = '\0'; + char number[11]; + if (this->param > 0) + snprintf(number, 10, " %d", this->param); + else + number[0] = '\0'; + char buffer[51]; + snprintf(buffer, 50, "%s%s%s", type->uiName, number, mode); + return ListItem_new(buffer, 0); } -/* private */ -void Meter_drawBar(Meter* this, int x, int y, int w) { - +/* ---------- TextMeterMode ---------- */ + +void TextMeterMode_draw(Meter* this, int x, int y, int w) { + MeterType* type = this->type; + char buffer[METER_BUFFER_LEN]; + type->setValues(this, buffer, METER_BUFFER_LEN - 1); + + attrset(CRT_colors[METER_TEXT]); + mvaddstr(y, x, this->caption); + int captionLen = strlen(this->caption); + w -= captionLen; + x += captionLen; + Meter_displayToStringBuffer(this, buffer); + mvhline(y, x, ' ', CRT_colors[DEFAULT_COLOR]); + attrset(CRT_colors[RESET_COLOR]); + mvaddchstr(y, x, Meter_stringBuffer.chstr); +} + +/* ---------- BarMeterMode ---------- */ + +/* private property */ +char BarMeterMode_characters[] = "|#*@$%&"; + +void BarMeterMode_draw(Meter* this, int x, int y, int w) { + MeterType* type = this->type; + char buffer[METER_BUFFER_LEN]; + type->setValues(this, buffer, METER_BUFFER_LEN - 1); + w -= 2; attrset(CRT_colors[METER_TEXT]); mvaddstr(y, x, this->caption); @@ -151,21 +303,19 @@ void Meter_drawBar(Meter* this, int x, int y, int w) { x++; char bar[w]; - this->setValues(this); - int blockSizes[10]; for (int i = 0; i < w; i++) bar[i] = ' '; - sprintf(bar + (w-strlen(this->displayBuffer.c)), "%s", this->displayBuffer.c); + sprintf(bar + (w-strlen(buffer)), "%s", buffer); // First draw in the bar[] buffer... double total = 0.0; int offset = 0; - for (int i = 0; i < this->items; i++) { - this->values[i] = MAX(this->values[i], 0); - this->values[i] = MIN(this->values[i], this->total); + for (int i = 0; i < type->items; i++) { double value = this->values[i]; + value = MAX(value, 0); + value = MIN(value, this->total); if (value > 0) { blockSizes[i] = ceil((value/this->total) * w); } else { @@ -173,12 +323,11 @@ void Meter_drawBar(Meter* this, int x, int y, int w) { } int nextOffset = offset + blockSizes[i]; // (Control against invalid values) - nextOffset = MAX(nextOffset, 0); - nextOffset = MIN(nextOffset, w); + nextOffset = MIN(MAX(nextOffset, 0), w); for (int j = offset; j < nextOffset; j++) if (bar[j] == ' ') { if (CRT_colorScheme == COLORSCHEME_MONOCHROME) { - bar[j] = Meter_barCharacters[i]; + bar[j] = BarMeterMode_characters[i]; } else { bar[j] = '|'; } @@ -189,8 +338,8 @@ void Meter_drawBar(Meter* this, int x, int y, int w) { // ...then print the buffer. offset = 0; - for (int i = 0; i < this->items; i++) { - attrset(CRT_colors[this->attributes[i]]); + for (int i = 0; i < type->items; i++) { + attrset(CRT_colors[type->attributes[i]]); mvaddnstr(y, x + offset, bar + offset, blockSizes[i]); offset += blockSizes[i]; offset = MAX(offset, 0); @@ -205,40 +354,85 @@ void Meter_drawBar(Meter* this, int x, int y, int w) { attrset(CRT_colors[RESET_COLOR]); } +#ifdef USE_FUNKY_MODES + +/* ---------- GraphMeterMode ---------- */ + +#define DrawDot(a,y,c) do { attrset(a); mvaddch(y, x+k, c); } while(0) + /* private */ -void Meter_drawText(Meter* this, int x, int y, int w) { - this->setValues(this); - this->w = w; - attrset(CRT_colors[METER_TEXT]); - mvaddstr(y, x, this->caption); - int captionLen = strlen(this->caption); - w -= captionLen; - x += captionLen; - ((Object*)this)->display((Object*)this, this->displayBuffer.rs); - mvhline(y, x, ' ', CRT_colors[DEFAULT_COLOR]); +static int GraphMeterMode_colors[21] = {GRAPH_1, GRAPH_1, GRAPH_1, + GRAPH_2, GRAPH_2, GRAPH_2, GRAPH_3, GRAPH_3, GRAPH_3, + GRAPH_4, GRAPH_4, GRAPH_4, GRAPH_5, GRAPH_5, GRAPH_6, + GRAPH_7, GRAPH_7, GRAPH_7, GRAPH_8, GRAPH_8, GRAPH_9 +}; + +/* private property */ +static char* GraphMeterMode_characters = "^`'-.,_~'`-.,_~'`-.,_"; + +void GraphMeterMode_draw(Meter* this, int x, int y, int w) { + + if (!this->drawBuffer) this->drawBuffer = calloc(sizeof(double), METER_BUFFER_LEN); + double* drawBuffer = (double*) this->drawBuffer; + + for (int i = 0; i < METER_BUFFER_LEN - 1; i++) + drawBuffer[i] = drawBuffer[i+1]; + + MeterType* type = this->type; + char buffer[METER_BUFFER_LEN]; + type->setValues(this, buffer, METER_BUFFER_LEN - 1); + + double value = 0.0; + for (int i = 0; i < type->items; i++) + value += this->values[i]; + value /= this->total; + drawBuffer[METER_BUFFER_LEN - 1] = value; + for (int i = METER_BUFFER_LEN - w, k = 0; i < METER_BUFFER_LEN; i++, k++) { + double value = drawBuffer[i]; + DrawDot( CRT_colors[DEFAULT_COLOR], y, ' ' ); + DrawDot( CRT_colors[DEFAULT_COLOR], y+1, ' ' ); + DrawDot( CRT_colors[DEFAULT_COLOR], y+2, ' ' ); + + double threshold = 1.00; + for (int i = 0; i < 21; i++, threshold -= 0.05) + if (value >= threshold) { + DrawDot(CRT_colors[GraphMeterMode_colors[i]], y+(i/7.0), GraphMeterMode_characters[i]); + break; + } + } attrset(CRT_colors[RESET_COLOR]); - mvaddchstr(y, x, this->displayBuffer.rs->chstr); } +/* ---------- LEDMeterMode ---------- */ + /* private */ -void Meter_drawDigit(int x, int y, int n) { - for (int i = 0; i < 3; i++) { - mvaddstr(y+i, x, Meter_ledDigits[i][n]); - } -} +static char* LEDMeterMode_digits[3][10] = { + { " __ "," "," __ "," __ "," "," __ "," __ "," __ "," __ "," __ "}, + { "| |"," |"," __|"," __|","|__|","|__ ","|__ "," |","|__|","|__|"}, + { "|__|"," |","|__ "," __|"," |"," __|","|__|"," |","|__|"," __|"}, +}; /* private */ -void Meter_drawLed(Meter* this, int x, int y, int w) { - this->setValues(this); - ((Object*)this)->display((Object*)this, this->displayBuffer.rs); +static void LEDMeterMode_drawDigit(int x, int y, int n) { + for (int i = 0; i < 3; i++) + mvaddstr(y+i, x, LEDMeterMode_digits[i][n]); +} + +void LEDMeterMode_draw(Meter* this, int x, int y, int w) { + MeterType* type = this->type; + char buffer[METER_BUFFER_LEN]; + type->setValues(this, buffer, METER_BUFFER_LEN - 1); + + Meter_displayToStringBuffer(this, buffer); + attrset(CRT_colors[LED_COLOR]); mvaddstr(y+2, x, this->caption); int xx = x + strlen(this->caption); - for (int i = 0; i < this->displayBuffer.rs->len; i++) { - char c = this->displayBuffer.rs->chstr[i]; + for (int i = 0; i < Meter_stringBuffer.len; i++) { + char c = Meter_stringBuffer.chstr[i]; if (c >= '0' && c <= '9') { - Meter_drawDigit(xx, y, c-48); - xx += 4; + LEDMeterMode_drawDigit(xx, y, c-48); + xx += 4; } else { mvaddch(y+2, xx, c); xx += 1; @@ -247,104 +441,4 @@ void Meter_drawLed(Meter* this, int x, int y, int w) { attrset(CRT_colors[RESET_COLOR]); } -#define DrawDot(a,y,c) do { \ - attrset(a); \ - mvaddstr(y, x+k, c); \ -} while(0) - -/* private */ -void Meter_drawGraph(Meter* this, int x, int y, int w) { - - for (int i = 0; i < METER_GRAPHBUFFER_LEN - 1; i++) { - this->displayBuffer.graph[i] = this->displayBuffer.graph[i+1]; - } - - this->setValues(this); - - double value = 0.0; - for (int i = 0; i < this->items; i++) - value += this->values[i] / this->total; - this->displayBuffer.graph[METER_GRAPHBUFFER_LEN - 1] = value; - - for (int i = METER_GRAPHBUFFER_LEN - w, k = 0; i < METER_GRAPHBUFFER_LEN; i++, k++) { - double value = this->displayBuffer.graph[i]; - DrawDot( CRT_colors[DEFAULT_COLOR], y, " " ); - DrawDot( CRT_colors[DEFAULT_COLOR], y+1, " " ); - DrawDot( CRT_colors[DEFAULT_COLOR], y+2, " " ); - if (value >= 1.00) DrawDot( CRT_colors[GRAPH_1], y, "^" ); - else if (value >= 0.95) DrawDot( CRT_colors[GRAPH_1], y, "`" ); - else if (value >= 0.90) DrawDot( CRT_colors[GRAPH_1], y, "'" ); - else if (value >= 0.85) DrawDot( CRT_colors[GRAPH_2], y, "-" ); - else if (value >= 0.80) DrawDot( CRT_colors[GRAPH_2], y, "." ); - else if (value >= 0.75) DrawDot( CRT_colors[GRAPH_2], y, "," ); - else if (value >= 0.70) DrawDot( CRT_colors[GRAPH_3], y, "_" ); - else if (value >= 0.65) DrawDot( CRT_colors[GRAPH_3], y+1, "~" ); - else if (value >= 0.60) DrawDot( CRT_colors[GRAPH_3], y+1, "`" ); - else if (value >= 0.55) DrawDot( CRT_colors[GRAPH_4], y+1, "'" ); - else if (value >= 0.50) DrawDot( CRT_colors[GRAPH_4], y+1, "-" ); - else if (value >= 0.45) DrawDot( CRT_colors[GRAPH_4], y+1, "." ); - else if (value >= 0.40) DrawDot( CRT_colors[GRAPH_5], y+1, "," ); - else if (value >= 0.35) DrawDot( CRT_colors[GRAPH_5], y+1, "_" ); - else if (value >= 0.30) DrawDot( CRT_colors[GRAPH_6], y+2, "~" ); - else if (value >= 0.25) DrawDot( CRT_colors[GRAPH_7], y+2, "`" ); - else if (value >= 0.20) DrawDot( CRT_colors[GRAPH_7], y+2, "'" ); - else if (value >= 0.15) DrawDot( CRT_colors[GRAPH_7], y+2, "-" ); - else if (value >= 0.10) DrawDot( CRT_colors[GRAPH_8], y+2, "." ); - else if (value >= 0.05) DrawDot( CRT_colors[GRAPH_8], y+2, "," ); - else DrawDot( CRT_colors[GRAPH_9], y+2, "_" ); - } - attrset(CRT_colors[RESET_COLOR]); -} - -void Meter_setMode(Meter* this, MeterMode mode) { - Meter_freeBuffer(this); - switch (mode) { - case UNSET: { - // fallthrough to a sane default. - mode = TEXT; - } - case TEXT: { - this->draw = Meter_drawText; - this->displayBuffer.rs = & Meter_stringBuffer; - this->h = 1; - break; - } - case LED: { - this->draw = Meter_drawLed; - this->displayBuffer.rs = & Meter_stringBuffer; - this->h = 3; - break; - } - case BAR: { - this->draw = Meter_drawBar; - this->displayBuffer.c = malloc(METER_BARBUFFER_LEN); - this->h = 1; - break; - } - case GRAPH: { - this->draw = Meter_drawGraph; - this->displayBuffer.c = calloc(METER_GRAPHBUFFER_LEN, sizeof(double)); - this->h = 3; - break; - } - default: { - assert(false); - } - } - this->mode = mode; -} - -ListItem* Meter_toListItem(Meter* this) { - char buffer[50]; char* mode = NULL; - switch (this->mode) { - case BAR: mode = "Bar"; break; - case LED: mode = "LED"; break; - case TEXT: mode = "Text"; break; - case GRAPH: mode = "Graph"; break; - default: { - assert(false); - } - } - sprintf(buffer, "%s [%s]", this->name, mode); - return ListItem_new(buffer, 0); -} +#endif diff --git a/Meter.h b/Meter.h index 4e0e5fa..73fa657 100644 --- a/Meter.h +++ b/Meter.h @@ -1,94 +1,163 @@ -/* Do not edit this file. It was automatically genarated. */ +/* Do not edit this file. It was automatically generated. */ #ifndef HEADER_Meter #define HEADER_Meter /* -htop -(C) 2004 Hisham H. Muhammad +htop - Meter.c +(C) 2004-2006 Hisham H. Muhammad 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 "Object.h" #include "CRT.h" #include "ListItem.h" #include "String.h" - -#include -#include -#include -#include -#include +#include "ProcessList.h" #include "debug.h" #include -#define METER_BARBUFFER_LEN 128 -#define METER_GRAPHBUFFER_LEN 128 +#ifndef USE_FUNKY_MODES +#define USE_FUNKY_MODES 1 +#endif + +#define METER_BUFFER_LEN 128 typedef struct Meter_ Meter; +typedef struct MeterType_ MeterType; +typedef struct MeterMode_ MeterMode; -typedef void(*Meter_SetValues)(Meter*); +typedef void(*MeterType_Init)(Meter*); +typedef void(*MeterType_Done)(Meter*); +typedef void(*MeterType_SetMode)(Meter*, int); +typedef void(*Meter_SetValues)(Meter*, char*, int); typedef void(*Meter_Draw)(Meter*, int, int, int); -typedef enum MeterMode_ { - UNSET, - BAR, - TEXT, - GRAPH, - LED, - LAST_METERMODE -} MeterMode; - -struct Meter_ { - Object super; - - int h; - int w; +struct MeterMode_ { Meter_Draw draw; + char* uiName; + int h; +}; + +struct MeterType_ { Meter_SetValues setValues; + Object_Display display; + int mode; int items; + double total; int* attributes; + char* name; + char* uiName; + char* caption; + MeterType_Init init; + MeterType_Done done; + MeterType_SetMode setMode; + Meter_Draw draw; +}; + +struct Meter_ { + Object super; + char* caption; + MeterType* type; + int mode; + int param; + Meter_Draw draw; + void* drawBuffer; + int h; + ProcessList* pl; double* values; double total; - char* caption; - char* name; - union { - RichString* rs; - char* c; - double* graph; - } displayBuffer; - MeterMode mode; }; extern char* METER_CLASS; +extern MeterType CPUMeter; +extern MeterType ClockMeter; +extern MeterType LoadAverageMeter; +extern MeterType LoadMeter; +extern MeterType MemoryMeter; +extern MeterType SwapMeter; +extern MeterType TasksMeter; +extern MeterType UptimeMeter; +extern MeterType AllCPUsMeter; + +typedef enum { + CUSTOM_METERMODE = 0, + BAR_METERMODE, + TEXT_METERMODE, +#ifdef USE_FUNKY_MODES + GRAPH_METERMODE, + LED_METERMODE, +#endif + LAST_METERMODE +} MeterModeId; +extern MeterType* Meter_types[]; +extern MeterMode* Meter_modes[]; +#ifndef MIN +#define MIN(a,b) ((a)<(b)?(a):(b)) +#endif +#ifndef MAX +#define MAX(a,b) ((a)>(b)?(a):(b)) +#endif + -Meter* Meter_new(char* name, char* caption, int items); -void Meter_init(Meter* this, char* name, char* caption, int items); -void Meter_delete(Object* cast); +#ifdef USE_FUNKY_MODES -void Meter_done(Meter* this); +#endif +Meter* Meter_new(ProcessList* pl, int param, MeterType* type); +void Meter_delete(Object* cast); -#define DrawDot(a,y,c) do { \ - attrset(a); \ - mvaddstr(y, x+k, c); \ -} while(0) +void Meter_setCaption(Meter* this, char* caption); -void Meter_setMode(Meter* this, MeterMode mode); +void Meter_setMode(Meter* this, int modeIndex); ListItem* Meter_toListItem(Meter* this); +/* ---------- TextMeterMode ---------- */ + +void TextMeterMode_draw(Meter* this, int x, int y, int w); + +/* ---------- BarMeterMode ---------- */ + + +void BarMeterMode_draw(Meter* this, int x, int y, int w); + +#ifdef USE_FUNKY_MODES + +/* ---------- GraphMeterMode ---------- */ + +#define DrawDot(a,y,c) do { attrset(a); mvaddch(y, x+k, c); } while(0) + + + +void GraphMeterMode_draw(Meter* this, int x, int y, int w); + +/* ---------- LEDMeterMode ---------- */ + + + +void LEDMeterMode_draw(Meter* this, int x, int y, int w); + +#endif + #endif diff --git a/MetersListBox.c b/MetersListBox.c index dc756ca..15f4a27 100644 --- a/MetersListBox.c +++ b/MetersListBox.c @@ -59,9 +59,8 @@ HandlerResult MetersListBox_EventHandler(ListBox* super, int ch) { case 't': { Meter* meter = (Meter*) TypedVector_get(this->meters, selected); - MeterMode mode = meter->mode + 1; - if (mode == LAST_METERMODE) - mode = 1; // skip mode 0, "unset" + int mode = meter->mode + 1; + if (mode == LAST_METERMODE) mode = 1; Meter_setMode(meter, mode); ListBox_set(super, selected, (Object*) Meter_toListItem(meter)); result = HANDLED; diff --git a/Object.c b/Object.c index dfa5e09..c368b9c 100644 --- a/Object.c +++ b/Object.c @@ -1,6 +1,6 @@ /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/Object.h b/Object.h index b69c902..78886c2 100644 --- a/Object.h +++ b/Object.h @@ -4,7 +4,7 @@ #define HEADER_Object /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/Process.c b/Process.c index fae1ed4..0396151 100644 --- a/Process.c +++ b/Process.c @@ -1,6 +1,6 @@ /* htop - Process.c -(C) 2004,2005 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -179,7 +179,7 @@ void Process_sendSignal(Process* this, int signal) { /* private */ void Process_printLargeNumber(Process* this, RichString *str, unsigned int number) { - char buffer[10]; + char buffer[11]; int len; if(number >= (1000 * ONE_M)) { len = snprintf(buffer, 10, "%4.2fG ", (float)number / ONE_M); @@ -206,7 +206,7 @@ void Process_printLargeNumber(Process* this, RichString *str, unsigned int numbe double jiffy = 0.0; /* private */ -void Process_printTime(RichString* str, unsigned long t) { +static void Process_printTime(RichString* str, unsigned long t) { if(jiffy == 0.0) jiffy = sysconf(_SC_CLK_TCK); double jiffytime = 1.0 / jiffy; @@ -217,7 +217,7 @@ void Process_printTime(RichString* str, unsigned long t) { int minutes = (iRealTime / 60) % 60; int seconds = iRealTime % 60; int hundredths = (realTime - iRealTime) * 100; - char buffer[10]; + char buffer[11]; if (hours) { snprintf(buffer, 10, "%2dh", hours); RichString_append(str, CRT_colors[LARGE_NUMBER], buffer); @@ -228,7 +228,8 @@ void Process_printTime(RichString* str, unsigned long t) { RichString_append(str, CRT_colors[DEFAULT_COLOR], buffer); } -inline void Process_writeCommand(Process* this, int attr, RichString* str) { +/* private */ +inline static void Process_writeCommand(Process* this, int attr, RichString* str) { if (this->pl->highlightBaseName) { char* firstSpace = strchr(this->comm, ' '); if (firstSpace) { diff --git a/Process.h b/Process.h index 5cf127e..f4f1b20 100644 --- a/Process.h +++ b/Process.h @@ -4,11 +4,12 @@ #define HEADER_Process /* htop - Process.h -(C) 2004,2005 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#define _GNU_SOURCE #include "ProcessList.h" #include "Object.h" #include "CRT.h" @@ -28,9 +29,6 @@ in the source distribution for its full text. #include #include -// TODO: wtf!? -int kill(pid_t pid, int signal); - // This works only with glibc 2.1+. On earlier versions // the behavior is similar to have a hardcoded page size. #define PAGE_SIZE ( sysconf(_SC_PAGESIZE) / 1024 ) @@ -133,11 +131,6 @@ void Process_sendSignal(Process* this, int signal); #define ONE_M (ONE_K * ONE_K) #define ONE_G (ONE_M * ONE_K) - - - -inline void Process_writeCommand(Process* this, int attr, RichString* str); - void Process_writeField(Process* this, RichString* str, ProcessField field); int Process_compare(const Object* v1, const Object* v2); diff --git a/ProcessList.c b/ProcessList.c index 3d87ec0..a2f1c99 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -5,6 +5,11 @@ 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 "TypedVector.h" @@ -20,6 +25,7 @@ in the source distribution for its full text. #include #include #include +#include #include "debug.h" #include @@ -38,7 +44,11 @@ in the source distribution for its full text. #endif #ifndef MAX_NAME -#define MAX_NAME 128; +#define MAX_NAME 128 +#endif + +#ifndef MAX_READ +#define MAX_READ 8192 #endif }*/ @@ -87,12 +97,73 @@ typedef struct ProcessList_ { bool treeView; bool highlightBaseName; bool highlightMegabytes; + #ifdef DEBUG + FILE* traceFile; + #endif } ProcessList; }*/ /* private property */ -ProcessField defaultHeaders[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, LAST_PROCESSFIELD, 0 }; +ProcessField defaultHeaders[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; + +#ifdef DEBUG + +/* private property */ +typedef int(*vxscanf)(void*, const char*, va_list); + +#define ProcessList_read(this, buffer, format, ...) ProcessList_xread(this, (vxscanf) vsscanf, buffer, format, ## __VA_ARGS__ ) +#define ProcessList_fread(this, file, format, ...) ProcessList_xread(this, (vxscanf) vfscanf, file, format, ## __VA_ARGS__ ) + +/* private */ +FILE* ProcessList_fopen(ProcessList* this, const char* path, const char* mode) { + fprintf(this->traceFile, "[%s]\n", path); + return fopen(path, mode); +} + +/* private */ +static inline int ProcessList_xread(ProcessList* this, vxscanf fn, void* buffer, char* format, ...) { + va_list ap; + va_start(ap, format); + int num = fn(buffer, format, ap); + va_end(format); + va_start(ap, format); + while (*format) { + char ch = *format; + char* c; int* d; long int* ld; unsigned long int* lu; char** s; + if (ch != '%') { + fprintf(this->traceFile, "%c", ch); + format++; + continue; + } + format++; + switch(*format) { + case 'c': c = va_arg(ap, char*); fprintf(this->traceFile, "%c", *c); break; + case 'd': d = va_arg(ap, int*); fprintf(this->traceFile, "%d", *d); break; + case 's': s = va_arg(ap, char**); fprintf(this->traceFile, "%s", *s); break; + case 'l': + format++; + switch (*format) { + case 'd': ld = va_arg(ap, long int*); fprintf(this->traceFile, "%ld", *ld); break; + case 'u': lu = va_arg(ap, unsigned long int*); fprintf(this->traceFile, "%lu", *lu); break; + } + } + format++; + } + fprintf(this->traceFile, "\n"); + va_end(format); + return num; +} + +#else + +#ifndef ProcessList_read +#define ProcessList_fopen(this, path, mode) fopen(path, mode) +#define ProcessList_read(this, buffer, format, ...) sscanf(buffer, format, ## __VA_ARGS__ ) +#define ProcessList_fread(this, file, format, ...) fscanf(file, format, ## __VA_ARGS__ ) +#endif + +#endif ProcessList* ProcessList_new(UsersTable* usersTable) { ProcessList* this; @@ -104,6 +175,10 @@ ProcessList* ProcessList_new(UsersTable* usersTable) { /* tree-view auxiliary buffers */ this->processes2 = TypedVector_new(PROCESS_CLASS, true, DEFAULT_SIZE); + + #ifdef DEBUG + this->traceFile = fopen("/tmp/htop-proc-trace", "w"); + #endif FILE* status = fopen(PROCSTATFILE, "r"); assert(status != NULL); @@ -166,6 +241,10 @@ void ProcessList_delete(ProcessList* this) { free(this->nicePeriod); free(this->idlePeriod); + #ifdef DEBUG + fclose(this->traceFile); + #endif + free(this->fields); free(this); } @@ -226,7 +305,7 @@ void ProcessList_buildTree(ProcessList* this, int pid, int level, int indent, in if (process->ppid == pid) { Process* process = (Process*) (TypedVector_take(this->processes, i)); TypedVector_add(children, process); - i--; + i--; } } int size = TypedVector_size(children); @@ -268,8 +347,7 @@ void ProcessList_sort(ProcessList* this) { } /* private */ -int ProcessList_readStatFile(Process *proc, FILE *f, char *command) { - #define MAX_READ 8192 +int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, char *command) { static char buf[MAX_READ]; long int zero; @@ -289,7 +367,7 @@ int ProcessList_readStatFile(Process *proc, FILE *f, char *command) { command[commsize] = '\0'; location = end + 2; - int num = sscanf(location, + int num = ProcessList_read(this, location, "%c %d %d %d %d %d %lu %lu %lu %lu " "%lu %lu %lu %ld %ld %ld %ld %ld %ld " "%lu %lu %ld %lu %lu %lu %lu %lu " @@ -313,11 +391,11 @@ int ProcessList_readStatFile(Process *proc, FILE *f, char *command) { return 1; } -bool ProcessList_readStatusFile(Process* proc, char* dirname, char* name) { +bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname, char* name) { char statusfilename[MAX_NAME+1]; statusfilename[MAX_NAME] = '\0'; snprintf(statusfilename, MAX_NAME, "%s/%s/status", dirname, name); - FILE* status = fopen(statusfilename, "r"); + FILE* status = ProcessList_fopen(this, statusfilename, "r"); bool success = false; if (status) { char buffer[1024]; @@ -329,7 +407,7 @@ bool ProcessList_readStatusFile(Process* proc, char* dirname, char* name) { if (String_startsWith(buffer, "Uid:")) { int uid1, uid2, uid3, uid4; // TODO: handle other uid's. - int ok = sscanf(buffer, "Uid:\t%d\t%d\t%d\t%d\n", &uid1, &uid2, &uid3, &uid4); + int ok = ProcessList_read(this, buffer, "Uid:\t%d\t%d\t%d\t%d", &uid1, &uid2, &uid3, &uid4); if (ok >= 1) { proc->st_uid = uid1; success = true; @@ -381,8 +459,8 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl if (access(subdirname, X_OK) == 0) { ProcessList_processEntries(this, subdirname, pid, period); } - } - + } + FILE* status; char statusfilename[MAX_NAME+1]; char command[PROCESS_COMM_LEN + 1]; @@ -393,7 +471,7 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl process = Process_clone(prototype); process->pid = pid; ProcessList_add(this, process); - if (! ProcessList_readStatusFile(process, dirname, name)) + if (! ProcessList_readStatusFile(this, process, dirname, name)) goto errorReadingProcess; } else { process = existingProcess; @@ -410,11 +488,12 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl int lasttimes = (process->utime + process->stime); snprintf(statusfilename, MAX_NAME, "%s/%s/stat", dirname, name); - status = fopen(statusfilename, "r"); + + status = ProcessList_fopen(this, statusfilename, "r"); if (status == NULL) goto errorReadingProcess; - - int success = ProcessList_readStatFile(process, status, command); + + int success = ProcessList_readStatFile(this, process, status, command); fclose(status); if(!success) { goto errorReadingProcess; @@ -425,7 +504,7 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl if(!existingProcess) { snprintf(statusfilename, MAX_NAME, "%s/%s/cmdline", dirname, name); - status = fopen(statusfilename, "r"); + status = ProcessList_fopen(this, statusfilename, "r"); if (!status) { goto errorReadingProcess; } @@ -443,14 +522,16 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl } snprintf(statusfilename, MAX_NAME, "%s/%s/statm", dirname, name); - status = fopen(statusfilename, "r"); + status = ProcessList_fopen(this, statusfilename, "r"); + if(!status) { goto errorReadingProcess; } - int num = fscanf(status, "%d %d %d %d %d %d %d", + int num = ProcessList_fread(this, status, "%d %d %d %d %d %d %d", &process->m_size, &process->m_resident, &process->m_share, &process->m_trs, &process->m_drs, &process->m_lrs, &process->m_dt); + fclose(status); if(num != 7) goto errorReadingProcess; @@ -460,9 +541,9 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl 100.0; this->totalTasks++; - if (process->state == 'R') { - this->runningTasks++; - } + if (process->state == 'R') { + this->runningTasks++; + } if (this->hideKernelThreads && process->m_size == 0) ProcessList_remove(this, process); @@ -484,7 +565,7 @@ void ProcessList_scan(ProcessList* this) { FILE* status; char buffer[128]; - status = fopen(PROCMEMINFOFILE, "r"); + status = ProcessList_fopen(this, PROCMEMINFOFILE, "r"); assert(status != NULL); while (!feof(status)) { fgets(buffer, 128, status); @@ -492,33 +573,35 @@ void ProcessList_scan(ProcessList* this) { switch (buffer[0]) { case 'M': if (String_startsWith(buffer, "MemTotal:")) - sscanf(buffer, "MemTotal: %ld kB", &this->totalMem); + ProcessList_read(this, buffer, "MemTotal: %ld kB", &this->totalMem); else if (String_startsWith(buffer, "MemFree:")) - sscanf(buffer, "MemFree: %ld kB", &this->freeMem); + ProcessList_read(this, buffer, "MemFree: %ld kB", &this->freeMem); else if (String_startsWith(buffer, "MemShared:")) - sscanf(buffer, "MemShared: %ld kB", &this->sharedMem); + ProcessList_read(this, buffer, "MemShared: %ld kB", &this->sharedMem); break; case 'B': if (String_startsWith(buffer, "Buffers:")) - sscanf(buffer, "Buffers: %ld kB", &this->buffersMem); + ProcessList_read(this, buffer, "Buffers: %ld kB", &this->buffersMem); break; case 'C': if (String_startsWith(buffer, "Cached:")) - sscanf(buffer, "Cached: %ld kB", &this->cachedMem); + ProcessList_read(this, buffer, "Cached: %ld kB", &this->cachedMem); break; case 'S': if (String_startsWith(buffer, "SwapTotal:")) - sscanf(buffer, "SwapTotal: %ld kB", &this->totalSwap); + ProcessList_read(this, buffer, "SwapTotal: %ld kB", &this->totalSwap); if (String_startsWith(buffer, "SwapFree:")) - sscanf(buffer, "SwapFree: %ld kB", &swapFree); + ProcessList_read(this, buffer, "SwapFree: %ld kB", &swapFree); break; } } + this->usedMem = this->totalMem - this->freeMem; this->usedSwap = this->totalSwap - swapFree; fclose(status); - status = fopen(PROCSTATFILE, "r"); + status = ProcessList_fopen(this, PROCSTATFILE, "r"); + assert(status != NULL); for (int i = 0; i <= this->processorCount; i++) { char buffer[256]; @@ -530,9 +613,9 @@ void ProcessList_scan(ProcessList* this) { // The rest will remain at zero. fgets(buffer, 255, status); if (i == 0) - sscanf(buffer, "cpu %ld %ld %ld %ld %ld %ld %ld %ld\n", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal); + ProcessList_read(this, buffer, "cpu %ld %ld %ld %ld %ld %ld %ld %ld", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal); else { - sscanf(buffer, "cpu%d %ld %ld %ld %ld %ld %ld %ld %ld\n", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal); + ProcessList_read(this, buffer, "cpu%d %ld %ld %ld %ld %ld %ld %ld %ld", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal); assert(cpuid == i - 1); } // Fields existing on kernels >= 2.6 diff --git a/ProcessList.h b/ProcessList.h index 530af6f..23d28f2 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -1,14 +1,19 @@ -/* Do not edit this file. It was automatically genarated. */ +/* Do not edit this file. It was automatically generated. */ #ifndef HEADER_ProcessList #define HEADER_ProcessList /* -htop - ProcessList.h +htop - ProcessList.c (C) 2004,2005 Hisham H. Muhammad 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 "TypedVector.h" #include "UsersTable.h" @@ -23,6 +28,7 @@ in the source distribution for its full text. #include #include #include +#include #include "debug.h" #include @@ -43,6 +49,12 @@ in the source distribution for its full text. #define MAX_NAME 128 #endif +#ifndef MAX_READ +#define MAX_READ 8192 +#endif + + + typedef struct ProcessList_ { TypedVector* processes; TypedVector* processes2; @@ -75,11 +87,6 @@ typedef struct ProcessList_ { long int usedSwap; long int freeSwap; - int kernelMajor; - int kernelMiddle; - int kernelMinor; - int kernelTiny; - ProcessField* fields; ProcessField sortKey; int direction; @@ -90,10 +97,30 @@ typedef struct ProcessList_ { bool treeView; bool highlightBaseName; bool highlightMegabytes; + #ifdef DEBUG + FILE* traceFile; + #endif } ProcessList; +#ifdef DEBUG + + +#define ProcessList_read(this, buffer, format, ...) ProcessList_xread(this, (vxscanf) vsscanf, buffer, format, ## __VA_ARGS__ ) +#define ProcessList_fread(this, file, format, ...) ProcessList_xread(this, (vxscanf) vfscanf, file, format, ## __VA_ARGS__ ) + + + +#else + +#ifndef ProcessList_read +#define ProcessList_fopen(this, path, mode) fopen(path, mode) +#define ProcessList_read(this, buffer, format, ...) sscanf(buffer, format, ## __VA_ARGS__ ) +#define ProcessList_fread(this, file, format, ...) fscanf(file, format, ## __VA_ARGS__ ) +#endif + +#endif ProcessList* ProcessList_new(UsersTable* usersTable); @@ -103,6 +130,7 @@ void ProcessList_invertSortOrder(ProcessList* this); RichString ProcessList_printHeader(ProcessList* this); + void ProcessList_prune(ProcessList* this); void ProcessList_add(ProcessList* this, Process* p); @@ -117,6 +145,10 @@ int ProcessList_size(ProcessList* this); void ProcessList_sort(ProcessList* this); +bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname, char* name); + +void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, float period); + void ProcessList_scan(ProcessList* this); void ProcessList_dontCrash(int signal); diff --git a/README b/README index 39db6ae..3857327 100644 --- a/README +++ b/README @@ -2,17 +2,17 @@ htop by Hisham Muhammad -May, 2004 - December, 2005 +May, 2004 - March, 2006 Introduction ~~~~~~~~~~~~ -This is htop, an interactive process viewer for Linux. +This is htop, an interactive process viewer. It requires ncurses. Tested with Linux 2.4 and 2.6. -Note that, currently, htop is _Linux_ specific -- it is based -on the Linux /proc filesystem. Contributions of ports to -other operating systems are welcome and will gladly be merged. +Note that, while, htop is Linux specific -- it is based +on the Linux /proc filesystem -- it is also reported to work +with FreeBSD systems featuring a Linux-compatible /proc. This software has evolved considerably during the last months, and is reasonably complete, but there is still room for diff --git a/ScreenManager.c b/ScreenManager.c index 3d0c1d9..28009ca 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -1,6 +1,6 @@ /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/ScreenManager.h b/ScreenManager.h index 1eb685f..b89d802 100644 --- a/ScreenManager.h +++ b/ScreenManager.h @@ -4,7 +4,7 @@ #define HEADER_ScreenManager /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/Settings.c b/Settings.c index 30b5c54..91a833e 100644 --- a/Settings.c +++ b/Settings.c @@ -1,6 +1,6 @@ /* htop - Settings.c -(C) 2004,2005 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -32,9 +32,15 @@ Settings* Settings_new(ProcessList* pl, Header* header) { this->pl = pl; this->header = header; char* home; + char* rcfile; home = getenv("HOME_ETC"); if (!home) home = getenv("HOME"); - this->userSettings = String_cat(home, "/.htoprc"); + if (!home) home = ""; + rcfile = getenv("HOMERC"); + if (!rcfile) + this->userSettings = String_cat(home, "/.htoprc"); + else + this->userSettings = String_copy(rcfile); this->colorScheme = 0; this->changed = false; this->delay = DEFAULT_DELAY; @@ -142,17 +148,17 @@ bool Settings_read(Settings* this, char* fileName) { if (this->colorScheme < 0) this->colorScheme = 0; if (this->colorScheme > 5) this->colorScheme = 5; } else if (String_eq(option[0], "left_meters")) { - Settings_readMeters(this, option[1], LEFT_HEADER); - readMeters = true; + Settings_readMeters(this, option[1], LEFT_HEADER); + readMeters = true; } else if (String_eq(option[0], "right_meters")) { - Settings_readMeters(this, option[1], RIGHT_HEADER); - readMeters = true; + Settings_readMeters(this, option[1], RIGHT_HEADER); + readMeters = true; } else if (String_eq(option[0], "left_meter_modes")) { - Settings_readMeterModes(this, option[1], LEFT_HEADER); - readMeters = true; + Settings_readMeterModes(this, option[1], LEFT_HEADER); + readMeters = true; } else if (String_eq(option[0], "right_meter_modes")) { - Settings_readMeterModes(this, option[1], RIGHT_HEADER); - readMeters = true; + Settings_readMeterModes(this, option[1], RIGHT_HEADER); + readMeters = true; } String_freeArray(option); } @@ -195,7 +201,9 @@ bool Settings_write(Settings* this) { fprintf(fd, "delay=%d\n", (int) this->delay); fprintf(fd, "left_meters="); for (int i = 0; i < Header_size(this->header, LEFT_HEADER); i++) { - fprintf(fd, "%s ", Header_readMeterName(this->header, i, LEFT_HEADER)); + char* name = Header_readMeterName(this->header, i, LEFT_HEADER); + fprintf(fd, "%s ", name); + free(name); } fprintf(fd, "\n"); fprintf(fd, "left_meter_modes="); @@ -203,14 +211,15 @@ bool Settings_write(Settings* this) { fprintf(fd, "%d ", Header_readMeterMode(this->header, i, LEFT_HEADER)); fprintf(fd, "\n"); fprintf(fd, "right_meters="); - for (int i = 0; i < Header_size(this->header, RIGHT_HEADER); i++) - fprintf(fd, "%s ", Header_readMeterName(this->header, i, RIGHT_HEADER)); + for (int i = 0; i < Header_size(this->header, RIGHT_HEADER); i++) { + char* name = Header_readMeterName(this->header, i, RIGHT_HEADER); + fprintf(fd, "%s ", name); + free(name); + } fprintf(fd, "\n"); fprintf(fd, "right_meter_modes="); for (int i = 0; i < Header_size(this->header, RIGHT_HEADER); i++) fprintf(fd, "%d ", Header_readMeterMode(this->header, i, RIGHT_HEADER)); - fprintf(fd, "\n"); - fclose(fd); return true; } diff --git a/Settings.h b/Settings.h index 91be193..66795e9 100644 --- a/Settings.h +++ b/Settings.h @@ -1,10 +1,10 @@ -/* Do not edit this file. It was automatically genarated. */ +/* Do not edit this file. It was automatically generated. */ #ifndef HEADER_Settings #define HEADER_Settings /* -htop -(C) 2004 Hisham H. Muhammad +htop - Settings.c +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -15,14 +15,16 @@ in the source distribution for its full text. #include "debug.h" +#define DEFAULT_DELAY 15 + typedef struct Settings_ { char* userSettings; ProcessList* pl; Header* header; int colorScheme; - int delay; bool changed; + int delay; } Settings; diff --git a/SignalItem.c b/SignalItem.c index 2cef877..5a39d3b 100644 --- a/SignalItem.c +++ b/SignalItem.c @@ -1,6 +1,6 @@ /* htop - SignalItem.c -(C) 2004,2005 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/SignalItem.h b/SignalItem.h index 7dcfa72..071d8d8 100644 --- a/SignalItem.h +++ b/SignalItem.h @@ -4,7 +4,7 @@ #define HEADER_Signal /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/String.c b/String.c index 20ec7d1..00cd4f2 100644 --- a/String.c +++ b/String.c @@ -1,6 +1,6 @@ /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/String.h b/String.h index 636c1e1..f096db1 100644 --- a/String.h +++ b/String.h @@ -4,7 +4,7 @@ #define HEADER_String /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/SwapMeter.c b/SwapMeter.c index 55a531f..7b295e9 100644 --- a/SwapMeter.c +++ b/SwapMeter.c @@ -1,6 +1,6 @@ /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -19,45 +19,36 @@ in the source distribution for its full text. #include "debug.h" #include -/*{ - -typedef struct SwapMeter_ SwapMeter; - -struct SwapMeter_ { - Meter super; - ProcessList* pl; +/* private property */ +static int SwapMeter_attributes[] = { SWAP }; + +/* private */ +MeterType SwapMeter = { + .setValues = SwapMeter_setValues, + .display = SwapMeter_display, + .mode = BAR_METERMODE, + .items = 1, + .total = 100.0, + .attributes = SwapMeter_attributes, + .name = "Swap", + .uiName = "Swap", + .caption = "Swp" }; -}*/ - -SwapMeter* SwapMeter_new(ProcessList* pl) { - SwapMeter* this = malloc(sizeof(SwapMeter)); - Meter_init((Meter*)this, String_copy("Swap"), String_copy("Swp"), 1); - ((Meter*)this)->attributes[0] = SWAP; - ((Meter*)this)->setValues = SwapMeter_setValues; - ((Object*)this)->display = SwapMeter_display; - this->pl = pl; - Meter_setMode((Meter*)this, BAR); - return this; -} - -void SwapMeter_setValues(Meter* cast) { - SwapMeter* this = (SwapMeter*)cast; - - double totalSwap = (double)this->pl->totalSwap; +void SwapMeter_setValues(Meter* this, char* buffer, int len) { long int usedSwap = this->pl->usedSwap; - cast->total = totalSwap; - cast->values[0] = usedSwap; - snprintf(cast->displayBuffer.c, 14, "%ld/%ldMB", usedSwap / 1024, this->pl->totalSwap / 1024); + this->total = this->pl->totalSwap; + this->values[0] = usedSwap; + snprintf(buffer, len, "%ld/%ldMB", (long int) usedSwap / 1024, (long int) this->total / 1024); } void SwapMeter_display(Object* cast, RichString* out) { char buffer[50]; - Meter* meter = (Meter*)cast; - long int swap = (long int) meter->values[0]; + Meter* this = (Meter*)cast; + long int swap = (long int) this->values[0]; RichString_prune(out); RichString_append(out, CRT_colors[METER_TEXT], ":"); - sprintf(buffer, "%ldM ", (long int) meter->total / 1024); + sprintf(buffer, "%ldM ", (long int) this->total / 1024); RichString_append(out, CRT_colors[METER_VALUE], buffer); sprintf(buffer, "%ldk", swap); RichString_append(out, CRT_colors[METER_TEXT], "used:"); diff --git a/SwapMeter.h b/SwapMeter.h index 5071ef6..f9be990 100644 --- a/SwapMeter.h +++ b/SwapMeter.h @@ -1,10 +1,10 @@ -/* Do not edit this file. It was automatically genarated. */ +/* Do not edit this file. It was automatically generated. */ #ifndef HEADER_SwapMeter #define HEADER_SwapMeter /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -23,17 +23,8 @@ in the source distribution for its full text. #include -typedef struct SwapMeter_ SwapMeter; -struct SwapMeter_ { - Meter super; - ProcessList* pl; -}; - - -SwapMeter* SwapMeter_new(ProcessList* pl); - -void SwapMeter_setValues(Meter* cast); +void SwapMeter_setValues(Meter* this, char* buffer, int len); void SwapMeter_display(Object* cast, RichString* out); diff --git a/TODO b/TODO deleted file mode 100644 index ffe15df..0000000 --- a/TODO +++ /dev/null @@ -1,10 +0,0 @@ - -FEATURES: - - * read SYSCONFDIR/htoprc (help, autoconf gurus!) - * make bars display refresh independent from list refresh - * auto-calibrate delay - * add some more 'top' features - * add more command-line parameters - * show 'process view' - * make keybindings configurable, blah blah blah... diff --git a/TasksMeter.c b/TasksMeter.c index 86bda9b..d970de0 100644 --- a/TasksMeter.c +++ b/TasksMeter.c @@ -1,6 +1,6 @@ /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -14,33 +14,26 @@ in the source distribution for its full text. #include "debug.h" -/*{ - -typedef struct TasksMeter_ TasksMeter; - -struct TasksMeter_ { - Meter super; - ProcessList* pl; +/* private property */ +int TasksMeter_attributes[] = { TASKS_RUNNING }; + +/* private */ +MeterType TasksMeter = { + .setValues = TasksMeter_setValues, + .display = TasksMeter_display, + .mode = TEXT_METERMODE, + .items = 1, + .total = 100.0, + .attributes = TasksMeter_attributes, + .name = "Tasks", + .uiName = "Task counter", + .caption = "Tasks: " }; -}*/ - -TasksMeter* TasksMeter_new(ProcessList* pl) { - TasksMeter* this = malloc(sizeof(TasksMeter)); - Meter_init((Meter*)this, String_copy("Tasks"), String_copy("Tasks: "), 1); - ((Meter*)this)->attributes[0] = TASKS_RUNNING; - ((Object*)this)->display = TasksMeter_display; - ((Meter*)this)->setValues = TasksMeter_setValues; - this->pl = pl; - Meter_setMode((Meter*)this, TEXT); - return this; -} - -void TasksMeter_setValues(Meter* cast) { - TasksMeter* this = (TasksMeter*)cast; - cast->total = this->pl->totalTasks; - cast->values[0] = this->pl->runningTasks; - snprintf(cast->displayBuffer.c, 20, "%d/%d", (int) cast->values[0], (int) cast->total); +void TasksMeter_setValues(Meter* this, char* buffer, int len) { + this->total = this->pl->totalTasks; + this->values[0] = this->pl->runningTasks; + snprintf(buffer, len, "%d/%d", (int) this->values[0], (int) this->total); } void TasksMeter_display(Object* cast, RichString* out) { diff --git a/TasksMeter.h b/TasksMeter.h index 68fb882..837730f 100644 --- a/TasksMeter.h +++ b/TasksMeter.h @@ -1,10 +1,10 @@ -/* Do not edit this file. It was automatically genarated. */ +/* Do not edit this file. It was automatically generated. */ #ifndef HEADER_TasksMeter #define HEADER_TasksMeter /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -18,17 +18,8 @@ in the source distribution for its full text. #include "debug.h" -typedef struct TasksMeter_ TasksMeter; -struct TasksMeter_ { - Meter super; - ProcessList* pl; -}; - - -TasksMeter* TasksMeter_new(ProcessList* pl); - -void TasksMeter_setValues(Meter* cast); +void TasksMeter_setValues(Meter* this, char* buffer, int len); void TasksMeter_display(Object* cast, RichString* out); diff --git a/TraceScreen.c b/TraceScreen.c index 9628290..a5feded 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -1,6 +1,6 @@ /* htop - TraceScreen.c -(C) 2005 Hisham H. Muhammad +(C) 2005-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -11,11 +11,15 @@ in the source distribution for its full text. #include #include #include +#include +#include #include "TraceScreen.h" #include "ProcessList.h" #include "Process.h" #include "ListItem.h" +#include "ListBox.h" +#include "FunctionBar.h" /*{ @@ -160,5 +164,6 @@ void TraceScreen_run(TraceScreen* this) { ListBox_draw(lb, true); } kill(child, SIGTERM); + waitpid(child, NULL, 0); fclose(strace); } diff --git a/TypedVector.c b/TypedVector.c index 0fd5e91..09cc2b0 100644 --- a/TypedVector.c +++ b/TypedVector.c @@ -1,6 +1,6 @@ /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/TypedVector.h b/TypedVector.h index 3a9da4d..e9e0dfa 100644 --- a/TypedVector.h +++ b/TypedVector.h @@ -4,7 +4,7 @@ #define HEADER_TypedVector /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/UptimeMeter.c b/UptimeMeter.c index ced1e1a..4b21245 100644 --- a/UptimeMeter.c +++ b/UptimeMeter.c @@ -1,6 +1,6 @@ /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -14,64 +14,45 @@ in the source distribution for its full text. #include "debug.h" -/*{ - -typedef struct UptimeMeter_ UptimeMeter; - -struct UptimeMeter_ { - Meter super; - ProcessList* pl; - int seconds; - int minutes; - int hours; - int days; +/* private property */ +static int UptimeMeter_attributes[] = { UPTIME }; + +/* private */ +MeterType UptimeMeter = { + .setValues = UptimeMeter_setValues, + .display = NULL, + .mode = TEXT_METERMODE, + .items = 1, + .total = 100.0, + .attributes = UptimeMeter_attributes, + .name = "Uptime", + .uiName = "Uptime", + .caption = "Uptime: " }; -}*/ - -UptimeMeter* UptimeMeter_new() { - UptimeMeter* this = malloc(sizeof(UptimeMeter)); - Meter_init((Meter*)this, String_copy("Uptime"), String_copy("Uptime: "), 1); - ((Meter*)this)->attributes[0] = UPTIME; - ((Object*)this)->display = UptimeMeter_display; - ((Meter*)this)->setValues = UptimeMeter_setValues; - Meter_setMode((Meter*)this, TEXT); - ((Meter*)this)->total = 100.0; - return this; -} - -void UptimeMeter_setValues(Meter* cast) { - UptimeMeter* this = (UptimeMeter*)cast; +void UptimeMeter_setValues(Meter* this, char* buffer, int len) { double uptime; FILE* fd = fopen(PROCDIR "/uptime", "r"); fscanf(fd, "%lf", &uptime); fclose(fd); int totalseconds = (int) ceil(uptime); - this->seconds = totalseconds % 60; - this->minutes = (totalseconds-this->seconds) % 3600 / 60; - this->hours = (totalseconds-this->seconds-(this->minutes*60)) % 86400 / 3600; - this->days = (totalseconds-this->seconds-(this->minutes*60)-(this->hours*3600)) / 86400; - cast->values[0] = this->days; - if (this->days > cast->total) { - cast->total = this->days; + int seconds = totalseconds % 60; + int minutes = (totalseconds-seconds) % 3600 / 60; + int hours = (totalseconds-seconds-(minutes*60)) % 86400 / 3600; + int days = (totalseconds-seconds-(minutes*60)-(hours*3600)) / 86400; + this->values[0] = days; + if (days > this->total) { + this->total = days; } - snprintf(cast->displayBuffer.c, 14, "%d", this->days); -} - -void UptimeMeter_display(Object* cast, RichString* out) { - UptimeMeter* this = (UptimeMeter*)cast; - char buffer[20]; - RichString_prune(out); - if (this->days > 100) { - sprintf(buffer, "%d days, ", this->days); - RichString_write(out, CRT_colors[LARGE_NUMBER], buffer); - } else if (this->days > 1) { - sprintf(buffer, "%d days, ", this->days); - RichString_write(out, CRT_colors[UPTIME], buffer); - } else if (this->days == 1) { - sprintf(buffer, "%d day, ", this->days); - RichString_write(out, CRT_colors[UPTIME], buffer); + char daysbuf[10]; + if (days > 100) { + sprintf(daysbuf, "%d days(!), ", days); + } else if (days > 1) { + sprintf(daysbuf, "%d days, ", days); + } else if (days == 1) { + sprintf(daysbuf, "1 day, "); + } else { + daysbuf[0] = '\0'; } - sprintf(buffer, "%02d:%02d:%02d ", this->hours, this->minutes, this->seconds); - RichString_append(out, CRT_colors[UPTIME], buffer); + snprintf(buffer, len, "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds); } diff --git a/UptimeMeter.h b/UptimeMeter.h index 6254f54..4fe279f 100644 --- a/UptimeMeter.h +++ b/UptimeMeter.h @@ -1,10 +1,10 @@ -/* Do not edit this file. It was automatically genarated. */ +/* Do not edit this file. It was automatically generated. */ #ifndef HEADER_UptimeMeter #define HEADER_UptimeMeter /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -18,22 +18,7 @@ in the source distribution for its full text. #include "debug.h" -typedef struct UptimeMeter_ UptimeMeter; -struct UptimeMeter_ { - Meter super; - ProcessList* pl; - int seconds; - int minutes; - int hours; - int days; -}; - - -UptimeMeter* UptimeMeter_new(); - -void UptimeMeter_setValues(Meter* cast); - -void UptimeMeter_display(Object* cast, RichString* out); +void UptimeMeter_setValues(Meter* cast, char* buffer, int len); #endif diff --git a/UsersTable.c b/UsersTable.c index d3b84e9..f738334 100644 --- a/UsersTable.c +++ b/UsersTable.c @@ -1,6 +1,6 @@ /* htop - UsersTable.c -(C) 2004,2005 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/UsersTable.h b/UsersTable.h index 4e8e665..fd717c2 100644 --- a/UsersTable.h +++ b/UsersTable.h @@ -4,7 +4,7 @@ #define HEADER_UsersTable /* htop -(C) 2004 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/config.h b/config.h index 1fb8f16..359fdcb 100644 --- a/config.h +++ b/config.h @@ -105,13 +105,16 @@ #define PACKAGE_NAME "htop" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "htop 0.6" +#define PACKAGE_STRING "htop 0.6.2" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "htop" /* Define to the version of this package. */ -#define PACKAGE_VERSION "0.6" +#define PACKAGE_VERSION "0.6.2" + +/* Path of proc filesystem */ +#define PROCDIR "/System/Kernel/Status" /* Define as the return type of signal handlers (`int' or `void'). */ #define RETSIGTYPE void @@ -120,7 +123,7 @@ #define STDC_HEADERS 1 /* Version number of package */ -#define VERSION "0.6" +#define VERSION "0.6.2" /* Define to empty if `const' does not conform to ANSI C. */ /* #undef const */ diff --git a/config.h.in b/config.h.in index 4776bae..f0218da 100644 --- a/config.h.in +++ b/config.h.in @@ -112,6 +112,9 @@ /* Define to the version of this package. */ #undef PACKAGE_VERSION +/* Path of proc filesystem */ +#undef PROCDIR + /* Define as the return type of signal handlers (`int' or `void'). */ #undef RETSIGTYPE diff --git a/configure b/configure index f5b3b10..e702f6c 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.59 for htop 0.6. +# Generated by GNU Autoconf 2.59 for htop 0.6.2. # # Report bugs to . # @@ -269,8 +269,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='htop' PACKAGE_TARNAME='htop' -PACKAGE_VERSION='0.6' -PACKAGE_STRING='htop 0.6' +PACKAGE_VERSION='0.6.2' +PACKAGE_STRING='htop 0.6.2' PACKAGE_BUGREPORT='loderunner@users.sourceforge.net' ac_unique_file="htop.c" @@ -780,7 +780,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 0.6 to adapt to many kinds of systems. +\`configure' configures htop 0.6.2 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -842,7 +842,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of htop 0.6:";; + short | recursive ) echo "Configuration of htop 0.6.2:";; esac cat <<\_ACEOF @@ -852,6 +852,11 @@ Optional Features: --disable-dependency-tracking speeds up one-time build --enable-dependency-tracking do not reject slow dependency extractors +Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] + --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) + --with-proc=DIR Location of a Linux-compatible proc filesystem (default=/proc). + Some influential environment variables: CC C compiler command CFLAGS C compiler flags @@ -960,7 +965,7 @@ fi test -n "$ac_init_help" && exit 0 if $ac_init_version; then cat <<\_ACEOF -htop configure 0.6 +htop configure 0.6.2 generated by GNU Autoconf 2.59 Copyright (C) 2003 Free Software Foundation, Inc. @@ -974,7 +979,7 @@ cat >&5 <<_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 0.6, which was +It was created by htop $as_me 0.6.2, which was generated by GNU Autoconf 2.59. Invocation command line was $ $0 $@ @@ -1609,7 +1614,7 @@ fi # Define the identity of the package. PACKAGE='htop' - VERSION='0.6' + VERSION='0.6.2' cat >>confdefs.h <<_ACEOF @@ -5188,24 +5193,98 @@ fi done -echo "$as_me:$LINENO: checking for /proc/stat" >&5 -echo $ECHO_N "checking for /proc/stat... $ECHO_C" >&6 -if test "${ac_cv_file__proc_stat+set}" = set; then +CFLAGS="${CFLAGS} -std=c99" +echo "$as_me:$LINENO: checking whether gcc -std=c99 option works" >&5 +echo $ECHO_N "checking whether gcc -std=c99 option works... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +char *a; a = strdup("foo"); int i = 0; i++; // C99 + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { echo "$as_me:$LINENO: error: htop is written in C99. A newer version of gcc is required." >&5 +echo "$as_me: error: htop is written in C99. A newer version of gcc is required." >&2;} + { (exit 1); exit 1; }; } +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext + +PROCDIR=/proc + +# Check whether --with-proc or --without-proc was given. +if test "${with_proc+set}" = set; then + withval="$with_proc" + if test -n "$withval"; then + +cat >>confdefs.h <<_ACEOF +#define PROCDIR "$withval" +_ACEOF + + PROCDIR="$withval" + fi +else + +cat >>confdefs.h <<\_ACEOF +#define PROCDIR "/proc" +_ACEOF + +fi; + +as_ac_File=`echo "ac_cv_file_$PROCDIR/stat" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $PROCDIR/stat" >&5 +echo $ECHO_N "checking for $PROCDIR/stat... $ECHO_C" >&6 +if eval "test \"\${$as_ac_File+set}\" = set"; then echo $ECHO_N "(cached) $ECHO_C" >&6 else test "$cross_compiling" = yes && { { echo "$as_me:$LINENO: error: cannot check for file existence when cross compiling" >&5 echo "$as_me: error: cannot check for file existence when cross compiling" >&2;} { (exit 1); exit 1; }; } -if test -r "/proc/stat"; then - ac_cv_file__proc_stat=yes +if test -r "$PROCDIR/stat"; then + eval "$as_ac_File=yes" else - ac_cv_file__proc_stat=no + eval "$as_ac_File=no" fi fi -echo "$as_me:$LINENO: result: $ac_cv_file__proc_stat" >&5 -echo "${ECHO_T}$ac_cv_file__proc_stat" >&6 -if test $ac_cv_file__proc_stat = yes; then +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_File'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_File'}'`" >&6 +if test `eval echo '${'$as_ac_File'}'` = yes; then : else { { echo "$as_me:$LINENO: error: Cannot find /proc/stat. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help." >&5 @@ -5213,24 +5292,25 @@ echo "$as_me: error: Cannot find /proc/stat. Make sure you have a Linux-compatib { (exit 1); exit 1; }; } fi -echo "$as_me:$LINENO: checking for /proc/meminfo" >&5 -echo $ECHO_N "checking for /proc/meminfo... $ECHO_C" >&6 -if test "${ac_cv_file__proc_meminfo+set}" = set; then +as_ac_File=`echo "ac_cv_file_$PROCDIR/meminfo" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $PROCDIR/meminfo" >&5 +echo $ECHO_N "checking for $PROCDIR/meminfo... $ECHO_C" >&6 +if eval "test \"\${$as_ac_File+set}\" = set"; then echo $ECHO_N "(cached) $ECHO_C" >&6 else test "$cross_compiling" = yes && { { echo "$as_me:$LINENO: error: cannot check for file existence when cross compiling" >&5 echo "$as_me: error: cannot check for file existence when cross compiling" >&2;} { (exit 1); exit 1; }; } -if test -r "/proc/meminfo"; then - ac_cv_file__proc_meminfo=yes +if test -r "$PROCDIR/meminfo"; then + eval "$as_ac_File=yes" else - ac_cv_file__proc_meminfo=no + eval "$as_ac_File=no" fi fi -echo "$as_me:$LINENO: result: $ac_cv_file__proc_meminfo" >&5 -echo "${ECHO_T}$ac_cv_file__proc_meminfo" >&6 -if test $ac_cv_file__proc_meminfo = yes; then +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_File'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_File'}'`" >&6 +if test `eval echo '${'$as_ac_File'}'` = yes; then : else { { echo "$as_me:$LINENO: error: Cannot find /proc/meminfo. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help." >&5 @@ -5617,7 +5697,7 @@ _ASBOX } >&5 cat >&5 <<_CSEOF -This file was extended by htop $as_me 0.6, which was +This file was extended by htop $as_me 0.6.2, which was generated by GNU Autoconf 2.59. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -5680,7 +5760,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -htop config.status 0.6 +htop config.status 0.6.2 configured by $0, generated by GNU Autoconf 2.59, with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" diff --git a/configure.ac b/configure.ac index f68a38f..029c2b6 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.57) -AC_INIT([htop],[0.6],[loderunner@users.sourceforge.net]) +AC_INIT([htop],[0.6.2],[loderunner@users.sourceforge.net]) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([htop.c]) AC_CONFIG_HEADER([config.h]) @@ -33,8 +33,23 @@ AC_TYPE_SIGNAL AC_FUNC_STAT AC_CHECK_FUNCS([memmove strncasecmp strstr strdup]) -AC_CHECK_FILE(/proc/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(/proc/meminfo,,AC_MSG_ERROR(Cannot find /proc/meminfo. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help.)) +CFLAGS="${CFLAGS} -std=c99" +AC_MSG_CHECKING([whether gcc -std=c99 option works]) +AC_TRY_COMPILE(AC_INCLUDES_DEFAULT, [char *a; a = strdup("foo"); int i = 0; i++; // C99], + AC_MSG_RESULT([yes]), + AC_MSG_ERROR([htop is written in C99. A newer version of gcc is required.])) + +PROCDIR=/proc +AC_ARG_WITH(proc, [ --with-proc=DIR Location of a Linux-compatible proc filesystem (default=/proc).], + + if test -n "$withval"; then + AC_DEFINE_UNQUOTED(PROCDIR, "$withval", [Path of proc filesystem]) + PROCDIR="$withval" + fi, + AC_DEFINE(PROCDIR, "/proc", [Path of proc filesystem])) + +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.)) AC_CONFIG_FILES([Makefile]) AC_OUTPUT diff --git a/depcomp b/depcomp index edb5d38..25bdb18 100755 --- a/depcomp +++ b/depcomp @@ -1,7 +1,9 @@ #! /bin/sh - # depcomp - compile a program generating dependencies as side-effects -# Copyright 1999, 2000, 2003 Free Software Foundation, Inc. + +scriptversion=2004-04-25.13 + +# Copyright (C) 1999, 2000, 2003, 2004 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,6 +27,36 @@ # Originally written by Alexandre Oliva . +case $1 in + '') + echo "$0: No command. Try \`$0 --help' for more information." 1>&2 + exit 1; + ;; + -h | --h*) + cat <<\EOF +Usage: depcomp [--help] [--version] PROGRAM [ARGS] + +Run PROGRAMS ARGS to compile a file, generating dependencies +as side-effects. + +Environment variables: + depmode Dependency tracking mode. + source Source file read by `PROGRAMS ARGS'. + object Object file output by `PROGRAMS ARGS'. + depfile Dependency file to output. + tmpdepfile Temporary file to use when outputing dependencies. + libtool Whether libtool is used (yes/no). + +Report bugs to . +EOF + exit 0 + ;; + -v | --v*) + echo "depcomp $scriptversion" + exit 0 + ;; +esac + if test -z "$depmode" || test -z "$source" || test -z "$object"; then echo "depcomp: Variables source, object and depmode must be set" 1>&2 exit 1 @@ -262,26 +294,32 @@ tru64) base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` if test "$libtool" = yes; then + # Dependencies are output in .lo.d with libtool 1.4. + # They are output in .o.d with libtool 1.5. tmpdepfile1="$dir.libs/$base.lo.d" - tmpdepfile2="$dir.libs/$base.d" + tmpdepfile2="$dir.libs/$base.o.d" + tmpdepfile3="$dir.libs/$base.d" "$@" -Wc,-MD else tmpdepfile1="$dir$base.o.d" tmpdepfile2="$dir$base.d" + tmpdepfile3="$dir$base.d" "$@" -MD fi stat=$? if test $stat -eq 0; then : else - rm -f "$tmpdepfile1" "$tmpdepfile2" + rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" exit $stat fi if test -f "$tmpdepfile1"; then tmpdepfile="$tmpdepfile1" - else + elif test -f "$tmpdepfile2"; then tmpdepfile="$tmpdepfile2" + else + tmpdepfile="$tmpdepfile3" fi if test -f "$tmpdepfile"; then sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" @@ -477,3 +515,12 @@ none) esac exit 0 + +# Local Variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-end: "$" +# End: diff --git a/htop.1 b/htop.1 index ddca7bb..3572c95 100644 --- a/htop.1 +++ b/htop.1 @@ -1,4 +1,4 @@ -.TH "htop" "1" "0.6" "Bartosz Fenski " "Utils" +.TH "htop" "1" "0.6.2" "Bartosz Fenski " "Utils" .SH "NAME" htop \- interactive process viewer .SH "SYNTAX" diff --git a/htop.c b/htop.c index a1bd7ee..4290920 100644 --- a/htop.c +++ b/htop.c @@ -1,6 +1,6 @@ /* htop - htop.c -(C) 2004,2005 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -38,14 +38,14 @@ char htop_barCharacters[] = "|#*@$%&"; void printVersionFlag() { clear(); - printf("htop " VERSION " - (C) 2004,2005 Hisham Muhammad.\n"); + printf("htop " VERSION " - (C) 2004-2006 Hisham Muhammad.\n"); printf("Released under the GNU GPL.\n\n"); exit(0); } void printHelpFlag() { clear(); - printf("htop " VERSION " - (C) 2004,2005 Hisham Muhammad.\n"); + printf("htop " VERSION " - (C) 2004-2006 Hisham Muhammad.\n"); printf("Released under the GNU GPL.\n\n"); printf("-d DELAY Delay between updates, in tenths of seconds\n\n"); printf("-u USERNAME Show only processes of a given user\n\n"); @@ -57,7 +57,7 @@ void printHelpFlag() { void showHelp() { clear(); attrset(CRT_colors[HELP_BOLD]); - mvaddstr(0, 0, "htop " VERSION " - (C) 2004 Hisham Muhammad."); + mvaddstr(0, 0, "htop " VERSION " - (C) 2004-2006 Hisham Muhammad."); mvaddstr(1, 0, "Released under the GNU GPL. See 'man' page for more info."); attrset(CRT_colors[DEFAULT_COLOR]); @@ -213,6 +213,11 @@ int main(int argc, char** argv) { setUserOnly(argv[2], &userOnly, &userId); } } + + if (access(PROCDIR, R_OK) != 0) { + fprintf(stderr, "Error: could not read procfs (compiled to look in %s).\n", PROCDIR); + exit(1); + } ListBox* lb; int quit = 0; @@ -268,6 +273,8 @@ int main(int argc, char** argv) { double oldTime = 0.0; bool recalculate; + int ch = 0; + int closeTimeout = 0; while (!quit) { gettimeofday(&tv, NULL); @@ -309,12 +316,24 @@ int main(int argc, char** argv) { Header_draw(header); ListBox_draw(lb, true); - int ch = getch(); + int prev = ch; + ch = getch(); + + if (ch == ERR) { + if (!incSearchMode) + refreshTimeout--; + if (prev == ch && !recalculate) { + closeTimeout++; + if (closeTimeout == 10) + break; + } else + closeTimeout = 0; + continue; + } + if (incSearchMode) { doRefresh = false; - if (ch == ERR) { - continue; - } else if (ch == KEY_F(3)) { + if (ch == KEY_F(3)) { int here = ListBox_getSelectedIndex(lb); int size = ProcessList_size(pl); int i = here+1; @@ -393,9 +412,6 @@ int main(int argc, char** argv) { } switch (ch) { - case ERR: - refreshTimeout--; - continue; case KEY_RESIZE: ListBox_resize(lb, COLS, LINES-headerHeight-1); if (incSearchMode) diff --git a/htop.desktop b/htop.desktop new file mode 100644 index 0000000..2b3ff00 --- /dev/null +++ b/htop.desktop @@ -0,0 +1,12 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=0.6.2 +Name=Htop +Type=Application +Comment=Show System Processes +Terminal=true +Exec=htop +Path= +Icon=htop +Categories=ConsoleOnly;System;Application; +GenericName=Process Viewer diff --git a/htop.h b/htop.h index 2f6be51..e069678 100644 --- a/htop.h +++ b/htop.h @@ -4,7 +4,7 @@ #define HEADER_htop /* htop - htop.h -(C) 2004,2005 Hisham H. Muhammad +(C) 2004-2006 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ diff --git a/htop.png b/htop.png new file mode 100644 index 0000000..2b16ebd Binary files /dev/null and b/htop.png differ diff --git a/install-sh b/install-sh index 6ce63b9..e4160c9 100755 --- a/install-sh +++ b/install-sh @@ -1,7 +1,8 @@ #!/bin/sh -# # install - install a program, script, or datafile -# + +scriptversion=2004-04-01.17 + # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the # following copyright and license. @@ -41,13 +42,11 @@ # from scratch. It can only install one file at a time, a restriction # shared with many OS's install programs. - # set DOITPROG to echo to test this script # Don't use :- since 4.3BSD and earlier shells don't like it. doit="${DOITPROG-}" - # put in absolute paths if you don't have them in your path; or use env. vars. mvprog="${MVPROG-mv}" @@ -59,236 +58,268 @@ stripprog="${STRIPPROG-strip}" rmprog="${RMPROG-rm}" mkdirprog="${MKDIRPROG-mkdir}" -transformbasename="" -transform_arg="" +transformbasename= +transform_arg= instcmd="$mvprog" chmodcmd="$chmodprog 0755" -chowncmd="" -chgrpcmd="" -stripcmd="" +chowncmd= +chgrpcmd= +stripcmd= rmcmd="$rmprog -f" mvcmd="$mvprog" -src="" -dst="" -dir_arg="" - -while [ x"$1" != x ]; do - case $1 in - -c) instcmd=$cpprog - shift - continue;; - - -d) dir_arg=true - shift - continue;; - - -m) chmodcmd="$chmodprog $2" - shift - shift - continue;; - - -o) chowncmd="$chownprog $2" - shift - shift - continue;; - - -g) chgrpcmd="$chgrpprog $2" - shift - shift - continue;; - - -s) stripcmd=$stripprog - shift - continue;; - - -t=*) transformarg=`echo $1 | sed 's/-t=//'` - shift - continue;; - - -b=*) transformbasename=`echo $1 | sed 's/-b=//'` - shift - continue;; - - *) if [ x"$src" = x ] - then - src=$1 - else - # this colon is to work around a 386BSD /bin/sh bug - : - dst=$1 - fi - shift - continue;; - esac +src= +dst= +dir_arg= + +usage="Usage: $0 [OPTION]... SRCFILE DSTFILE + or: $0 [OPTION]... SRCFILES... DIRECTORY + or: $0 -d DIRECTORIES... + +In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default. +In the second, create the directory path DIR. + +Options: +-b=TRANSFORMBASENAME +-c copy source (using $cpprog) instead of moving (using $mvprog). +-d create directories instead of installing files. +-g GROUP $chgrp installed files to GROUP. +-m MODE $chmod installed files to MODE. +-o USER $chown installed files to USER. +-s strip installed files (using $stripprog). +-t=TRANSFORM +--help display this help and exit. +--version display version info and exit. + +Environment variables override the default commands: + CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG +" + +while test -n "$1"; do + case $1 in + -b=*) transformbasename=`echo $1 | sed 's/-b=//'` + shift + continue;; + + -c) instcmd=$cpprog + shift + continue;; + + -d) dir_arg=true + shift + continue;; + + -g) chgrpcmd="$chgrpprog $2" + shift + shift + continue;; + + --help) echo "$usage"; exit 0;; + + -m) chmodcmd="$chmodprog $2" + shift + shift + continue;; + + -o) chowncmd="$chownprog $2" + shift + shift + continue;; + + -s) stripcmd=$stripprog + shift + continue;; + + -t=*) transformarg=`echo $1 | sed 's/-t=//'` + shift + continue;; + + --version) echo "$0 $scriptversion"; exit 0;; + + *) # When -d is used, all remaining arguments are directories to create. + test -n "$dir_arg" && break + # Otherwise, the last argument is the destination. Remove it from $@. + for arg + do + if test -n "$dstarg"; then + # $@ is not empty: it contains at least $arg. + set fnord "$@" "$dstarg" + shift # fnord + fi + shift # arg + dstarg=$arg + done + break;; + esac done -if [ x"$src" = x ] -then - echo "$0: no input file specified" >&2 - exit 1 -else - : +if test -z "$1"; then + if test -z "$dir_arg"; then + echo "$0: no input file specified." >&2 + exit 1 + fi + # It's OK to call `install-sh -d' without argument. + # This can happen when creating conditional directories. + exit 0 fi -if [ x"$dir_arg" != x ]; then - dst=$src - src="" - - if [ -d "$dst" ]; then - instcmd=: - chmodcmd="" - else - instcmd=$mkdirprog - fi -else - -# Waiting for this to be detected by the "$instcmd $src $dsttmp" command -# might cause directories to be created, which would be especially bad -# if $src (and thus $dsttmp) contains '*'. - - if [ -f "$src" ] || [ -d "$src" ] - then - : - else - echo "$0: $src does not exist" >&2 - exit 1 - fi - - if [ x"$dst" = x ] - then - echo "$0: no destination specified" >&2 - exit 1 - else - : - fi - -# If destination is a directory, append the input filename; if your system -# does not like double slashes in filenames, you may need to add some logic - - if [ -d "$dst" ] - then - dst=$dst/`basename "$src"` - else - : - fi -fi - -## this sed command emulates the dirname command -dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` - -# Make sure that the destination directory exists. -# this part is taken from Noah Friedman's mkinstalldirs script - -# Skip lots of stat calls in the usual case. -if [ ! -d "$dstdir" ]; then -defaultIFS=' - ' -IFS="${IFS-$defaultIFS}" - -oIFS=$IFS -# Some sh's can't handle IFS=/ for some reason. -IFS='%' -set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` -IFS=$oIFS - -pathcomp='' - -while [ $# -ne 0 ] ; do - pathcomp=$pathcomp$1 - shift - - if [ ! -d "$pathcomp" ] ; - then - $mkdirprog "$pathcomp" - else - : - fi +for src +do + # Protect names starting with `-'. + case $src in + -*) src=./$src ;; + esac + + if test -n "$dir_arg"; then + dst=$src + src= + + if test -d "$dst"; then + instcmd=: + chmodcmd= + else + instcmd=$mkdirprog + fi + else + # Waiting for this to be detected by the "$instcmd $src $dsttmp" command + # might cause directories to be created, which would be especially bad + # if $src (and thus $dsttmp) contains '*'. + if test ! -f "$src" && test ! -d "$src"; then + echo "$0: $src does not exist." >&2 + exit 1 + fi + + if test -z "$dstarg"; then + echo "$0: no destination specified." >&2 + exit 1 + fi + + dst=$dstarg + # Protect names starting with `-'. + case $dst in + -*) dst=./$dst ;; + esac - pathcomp=$pathcomp/ + # If destination is a directory, append the input filename; won't work + # if double slashes aren't ignored. + if test -d "$dst"; then + dst=$dst/`basename "$src"` + fi + fi + + # This sed command emulates the dirname command. + dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` + + # Make sure that the destination directory exists. + + # Skip lots of stat calls in the usual case. + if test ! -d "$dstdir"; then + defaultIFS=' + ' + IFS="${IFS-$defaultIFS}" + + oIFS=$IFS + # Some sh's can't handle IFS=/ for some reason. + IFS='%' + set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` + IFS=$oIFS + + pathcomp= + + while test $# -ne 0 ; do + pathcomp=$pathcomp$1 + shift + if test ! -d "$pathcomp"; then + $mkdirprog "$pathcomp" || lasterr=$? + # mkdir can fail with a `File exist' error in case several + # install-sh are creating the directory concurrently. This + # is OK. + test ! -d "$pathcomp" && { (exit ${lasterr-1}); exit; } + fi + pathcomp=$pathcomp/ + done + fi + + if test -n "$dir_arg"; then + $doit $instcmd "$dst" \ + && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \ + && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \ + && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \ + && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; } + + else + # If we're going to rename the final executable, determine the name now. + if test -z "$transformarg"; then + dstfile=`basename "$dst"` + else + dstfile=`basename "$dst" $transformbasename \ + | sed $transformarg`$transformbasename + fi + + # don't allow the sed command to completely eliminate the filename. + test -z "$dstfile" && dstfile=`basename "$dst"` + + # Make a couple of temp file names in the proper directory. + dsttmp=$dstdir/_inst.$$_ + rmtmp=$dstdir/_rm.$$_ + + # Trap to clean up those temp files at exit. + trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0 + trap '(exit $?); exit' 1 2 13 15 + + # Move or copy the file name to the temp name + $doit $instcmd "$src" "$dsttmp" && + + # and set any options; do chmod last to preserve setuid bits. + # + # If any of these fail, we abort the whole thing. If we want to + # ignore errors from any of these, just make sure not to ignore + # errors from the above "$doit $instcmd $src $dsttmp" command. + # + { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \ + && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \ + && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \ + && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } && + + # Now rename the file to the real destination. + { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \ + || { + # The rename failed, perhaps because mv can't rename something else + # to itself, or perhaps because mv is so ancient that it does not + # support -f. + + # Now remove or move aside any old file at destination location. + # We try this two ways since rm can't unlink itself on some + # systems and the destination file might be busy for other + # reasons. In this case, the final cleanup might fail but the new + # file should still install successfully. + { + if test -f "$dstdir/$dstfile"; then + $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \ + || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \ + || { + echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2 + (exit 1); exit + } + else + : + fi + } && + + # Now rename the file to the real destination. + $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" + } + } + fi || { (exit 1); exit; } done -fi - -if [ x"$dir_arg" != x ] -then - $doit $instcmd "$dst" && - - if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi -else - -# If we're going to rename the final executable, determine the name now. - - if [ x"$transformarg" = x ] - then - dstfile=`basename "$dst"` - else - dstfile=`basename "$dst" $transformbasename | - sed $transformarg`$transformbasename - fi - -# don't allow the sed command to completely eliminate the filename - - if [ x"$dstfile" = x ] - then - dstfile=`basename "$dst"` - else - : - fi - -# Make a couple of temp file names in the proper directory. - - dsttmp=$dstdir/_inst.$$_ - rmtmp=$dstdir/_rm.$$_ - -# Trap to clean up temp files at exit. - - trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0 - trap '(exit $?); exit' 1 2 13 15 - -# Move or copy the file name to the temp name - - $doit $instcmd "$src" "$dsttmp" && - -# and set any options; do chmod last to preserve setuid bits - -# If any of these fail, we abort the whole thing. If we want to -# ignore errors from any of these, just make sure not to ignore -# errors from the above "$doit $instcmd $src $dsttmp" command. - - if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi && - -# Now remove or move aside any old file at destination location. We try this -# two ways since rm can't unlink itself on some systems and the destination -# file might be busy for other reasons. In this case, the final cleanup -# might fail but the new file should still install successfully. - -{ - if [ -f "$dstdir/$dstfile" ] - then - $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null || - $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null || - { - echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2 - (exit 1); exit - } - else - : - fi -} && - -# Now rename the file to the real destination. - - $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" - -fi && # The final little trick to "correctly" pass the exit status to the exit trap. - { - (exit 0); exit + (exit 0); exit } + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-end: "$" +# End: diff --git a/missing b/missing index fc54c64..e7ef83a 100755 --- a/missing +++ b/missing @@ -1,6 +1,10 @@ #! /bin/sh # Common stub for a few missing GNU programs while installing. -# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003 Free Software Foundation, Inc. + +scriptversion=2003-09-02.23 + +# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003 +# Free Software Foundation, Inc. # Originally by Fran,cois Pinard , 1996. # This program is free software; you can redistribute it and/or modify @@ -38,12 +42,23 @@ else configure_ac=configure.in fi +msg="missing on your system" + case "$1" in --run) # Try to run requested program, and just exit if it succeeds. run= shift "$@" && exit 0 + # Exit code 63 means version mismatch. This often happens + # when the user try to use an ancient version of a tool on + # a file that requires a minimum version. In this case we + # we should proceed has if the program had been absent, or + # if --run hadn't been passed. + if test $? = 63; then + run=: + msg="probably too old" + fi ;; esac @@ -74,11 +89,13 @@ Supported PROGRAM values: lex create \`lex.yy.c', if possible, from existing .c makeinfo touch the output file tar try tar, gnutar, gtar, then tar without non-portable flags - yacc create \`y.tab.[ch]', if possible, from existing .[ch]" + yacc create \`y.tab.[ch]', if possible, from existing .[ch] + +Send bug reports to ." ;; -v|--v|--ve|--ver|--vers|--versi|--versio|--version) - echo "missing 0.4 - GNU automake" + echo "missing $scriptversion (GNU Automake)" ;; -*) @@ -94,7 +111,7 @@ Supported PROGRAM values: fi echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if +WARNING: \`$1' is $msg. You should only need it if you modified \`acinclude.m4' or \`${configure_ac}'. You might want to install the \`Automake' and \`Perl' packages. Grab them from any GNU archive site." @@ -108,7 +125,7 @@ WARNING: \`$1' is missing on your system. You should only need it if fi echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if +WARNING: \`$1' is $msg. You should only need it if you modified \`${configure_ac}'. You might want to install the \`Autoconf' and \`GNU m4' packages. Grab them from any GNU archive site." @@ -122,7 +139,7 @@ WARNING: \`$1' is missing on your system. You should only need it if fi echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if +WARNING: \`$1' is $msg. You should only need it if you modified \`acconfig.h' or \`${configure_ac}'. You might want to install the \`Autoconf' and \`GNU m4' packages. Grab them from any GNU archive site." @@ -146,7 +163,7 @@ WARNING: \`$1' is missing on your system. You should only need it if fi echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if +WARNING: \`$1' is $msg. You should only need it if you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'. You might want to install the \`Automake' and \`Perl' packages. Grab them from any GNU archive site." @@ -162,8 +179,8 @@ WARNING: \`$1' is missing on your system. You should only need it if fi echo 1>&2 "\ -WARNING: \`$1' is needed, and you do not seem to have it handy on your - system. You might have modified some files without having the +WARNING: \`$1' is needed, but is $msg. + You might have modified some files without having the proper tools for further handling them. You can get \`$1' as part of \`Autoconf' from any GNU archive site." @@ -185,7 +202,7 @@ WARNING: \`$1' is needed, and you do not seem to have it handy on your bison|yacc) echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if +WARNING: \`$1' $msg. You should only need it if you modified a \`.y' file. You may need the \`Bison' package in order for those modifications to take effect. You can get \`Bison' from any GNU archive site." @@ -215,7 +232,7 @@ WARNING: \`$1' is missing on your system. You should only need it if lex|flex) echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if +WARNING: \`$1' is $msg. You should only need it if you modified a \`.l' file. You may need the \`Flex' package in order for those modifications to take effect. You can get \`Flex' from any GNU archive site." @@ -243,7 +260,7 @@ WARNING: \`$1' is missing on your system. You should only need it if fi echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if +WARNING: \`$1' is $msg. You should only need it if you modified a dependency of a manual page. You may need the \`Help2man' package in order for those modifications to take effect. You can get \`Help2man' from any GNU archive site." @@ -268,7 +285,7 @@ WARNING: \`$1' is missing on your system. You should only need it if fi echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if +WARNING: \`$1' is $msg. You should only need it if you modified a \`.texi' or \`.texinfo' file, or any other file indirectly affecting the aspect of the manual. The spurious call might also be the consequence of using a buggy \`make' (AIX, @@ -323,8 +340,8 @@ WARNING: I can't seem to be able to run \`tar' with the given arguments. *) echo 1>&2 "\ -WARNING: \`$1' is needed, and you do not seem to have it handy on your - system. You might have modified some files without having the +WARNING: \`$1' is needed, and is $msg. + You might have modified some files without having the proper tools for further handling them. Check the \`README' file, it often tells you about the needed prerequisites for installing this package. You may also peek at any GNU archive site, in case @@ -334,3 +351,10 @@ WARNING: \`$1' is needed, and you do not seem to have it handy on your esac exit 0 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-end: "$" +# End: diff --git a/mkinstalldirs b/mkinstalldirs deleted file mode 100755 index d2d5f21..0000000 --- a/mkinstalldirs +++ /dev/null @@ -1,111 +0,0 @@ -#! /bin/sh -# mkinstalldirs --- make directory hierarchy -# Author: Noah Friedman -# Created: 1993-05-16 -# Public domain - -errstatus=0 -dirmode="" - -usage="\ -Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..." - -# process command line arguments -while test $# -gt 0 ; do - case $1 in - -h | --help | --h*) # -h for help - echo "$usage" 1>&2 - exit 0 - ;; - -m) # -m PERM arg - shift - test $# -eq 0 && { echo "$usage" 1>&2; exit 1; } - dirmode=$1 - shift - ;; - --) # stop option processing - shift - break - ;; - -*) # unknown option - echo "$usage" 1>&2 - exit 1 - ;; - *) # first non-opt arg - break - ;; - esac -done - -for file -do - if test -d "$file"; then - shift - else - break - fi -done - -case $# in - 0) exit 0 ;; -esac - -case $dirmode in - '') - if mkdir -p -- . 2>/dev/null; then - echo "mkdir -p -- $*" - exec mkdir -p -- "$@" - fi - ;; - *) - if mkdir -m "$dirmode" -p -- . 2>/dev/null; then - echo "mkdir -m $dirmode -p -- $*" - exec mkdir -m "$dirmode" -p -- "$@" - fi - ;; -esac - -for file -do - set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` - shift - - pathcomp= - for d - do - pathcomp="$pathcomp$d" - case $pathcomp in - -*) pathcomp=./$pathcomp ;; - esac - - if test ! -d "$pathcomp"; then - echo "mkdir $pathcomp" - - mkdir "$pathcomp" || lasterr=$? - - if test ! -d "$pathcomp"; then - errstatus=$lasterr - else - if test ! -z "$dirmode"; then - echo "chmod $dirmode $pathcomp" - lasterr="" - chmod "$dirmode" "$pathcomp" || lasterr=$? - - if test ! -z "$lasterr"; then - errstatus=$lasterr - fi - fi - fi - fi - - pathcomp="$pathcomp/" - done -done - -exit $errstatus - -# Local Variables: -# mode: shell-script -# sh-indentation: 2 -# End: -# mkinstalldirs ends here diff --git a/scripts/MakeHeader.py b/scripts/MakeHeader.py new file mode 100755 index 0000000..2268fcf --- /dev/null +++ b/scripts/MakeHeader.py @@ -0,0 +1,60 @@ +#!/usr/bin/python + +import os, sys, string + +ANY=1 +COPY=2 +SKIP=3 +SKIPONE=4 + +state = ANY + +file = open(sys.argv[1]) +name = sys.argv[1][:-2] + +out = open(name + ".h", "w") +class writer: + def __init__(self, file): + self.file = file + def write(self, text): + self.file.write(text + "\n") +out = writer(out) + +selfheader = '#include "' + name + '.h"' + +out.write( "/* Do not edit this file. It was automatically generated. */" ) +out.write( "" ) + +out.write( "#ifndef HEADER_" + name ) +out.write( "#define HEADER_" + name ) +for line in file.readlines(): + line = line[:-1] + if state == ANY: + if line == '/*{': + state = COPY + elif line == selfheader: + pass + elif string.find(line, "typedef") == 0 or line == "/* private */": + state = SKIP + elif string.find(line, "/* private property */") == 0: + state = SKIPONE + elif len(line) > 1 and line[-1] == "{": + out.write( line[:-2] + ";" ) + state = SKIP + elif line == "": + out.write( "" ) + else: + out.write( line ) + elif state == COPY: + if line == "}*/": + state = ANY + else: + out.write( line ) + elif state == SKIP: + if len(line) >= 1 and line[0] == "}": + state = ANY + elif state == SKIPONE: + state = ANY + +out.write( "" ) +out.write( "#endif" ) -- cgit v1.2.3