From 89473cc9ae950bbb5e291d1f186d372f66f66394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 15 Dec 2020 19:44:48 +0100 Subject: Rework enum ProcessField Use only one enum instead of a global and a platform specific one. Drop Platform_numberOfFields global variable. Set known size of Process_fields array --- solaris/Platform.c | 4 ---- solaris/Platform.h | 5 ----- solaris/ProcessField.h | 22 ++++++++++++++++++++++ solaris/SolarisProcess.c | 7 +++---- solaris/SolarisProcess.h | 14 +------------- 5 files changed, 26 insertions(+), 26 deletions(-) create mode 100644 solaris/ProcessField.h (limited to 'solaris') diff --git a/solaris/Platform.c b/solaris/Platform.c index 014eaf55..b674998b 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -119,10 +119,6 @@ const MeterClass* const Platform_meterTypes[] = { NULL }; -int Platform_numberOfFields = LAST_PROCESSFIELD; - -extern char Process_pidFormat[20]; - void Platform_init(void) { /* no platform-specific setup needed */ } diff --git a/solaris/Platform.h b/solaris/Platform.h index c3381152..4daf7164 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -25,7 +25,6 @@ in the source distribution for its full text. #define kill(pid, signal) kill(pid / 1024, signal) -extern ProcessFieldData Process_fields[]; typedef struct var kvar_t; typedef struct envAccum_ { @@ -45,10 +44,6 @@ extern ProcessField Platform_defaultFields[]; extern const MeterClass* const Platform_meterTypes[]; -extern int Platform_numberOfFields; - -extern char Process_pidFormat[20]; - void Platform_init(void); void Platform_done(void); diff --git a/solaris/ProcessField.h b/solaris/ProcessField.h new file mode 100644 index 00000000..eb9f1577 --- /dev/null +++ b/solaris/ProcessField.h @@ -0,0 +1,22 @@ +#ifndef HEADER_SolarisProcessField +#define HEADER_SolarisProcessField +/* +htop - solaris/ProcessField.h +(C) 2020 htop dev team +Released under the GNU GPLv2, see the COPYING file +in the source distribution for its full text. +*/ + + +#define PLATFORM_PROCESS_FIELDS \ + ZONEID = 100, \ + ZONE = 101, \ + PROJID = 102, \ + TASKID = 103, \ + POOLID = 104, \ + CONTID = 105, \ + LWPID = 106, \ + // End of list + + +#endif /* HEADER_SolarisProcessField */ diff --git a/solaris/SolarisProcess.c b/solaris/SolarisProcess.c index f6470a3c..3d4f9538 100644 --- a/solaris/SolarisProcess.c +++ b/solaris/SolarisProcess.c @@ -29,7 +29,7 @@ const ProcessClass SolarisProcess_class = { .compareByKey = SolarisProcess_compareByKey }; -ProcessFieldData Process_fields[] = { +ProcessFieldData Process_fields[LAST_PROCESSFIELD] = { [0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, }, [PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, }, [COMM] = { .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, }, @@ -62,7 +62,6 @@ ProcessFieldData Process_fields[] = { [POOLID] = { .name = "POOLID", .title = " POLID ", .description = "Pool ID", .flags = 0, }, [CONTID] = { .name = "CONTID", .title = " CNTID ", .description = "Contract ID", .flags = 0, }, [LWPID] = { .name = "LWPID", .title = " LWPID ", .description = "LWP ID", .flags = 0, }, - [LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, }, }; ProcessPidColumn Process_pidColumns[] = { @@ -100,7 +99,7 @@ void SolarisProcess_writeField(const Process* this, RichString* str, ProcessFiel char buffer[256]; buffer[255] = '\0'; int attr = CRT_colors[DEFAULT_COLOR]; int n = sizeof(buffer) - 1; - switch ((int) field) { + switch (field) { // add Solaris-specific fields here case ZONEID: xSnprintf(buffer, n, Process_pidFormat, sp->zoneid); break; case PROJID: xSnprintf(buffer, n, Process_pidFormat, sp->projid); break; @@ -122,7 +121,7 @@ long SolarisProcess_compareByKey(const void* v1, const void* v2, ProcessField ke const SolarisProcess* p1 = (const SolarisProcess*)v1; const SolarisProcess* p2 = (const SolarisProcess*)v2; - switch ((int) key) { + switch (key) { case ZONEID: return SPACESHIP_NUMBER(p1->zoneid, p2->zoneid); case PROJID: diff --git a/solaris/SolarisProcess.h b/solaris/SolarisProcess.h index 12e6c99f..5f79754a 100644 --- a/solaris/SolarisProcess.h +++ b/solaris/SolarisProcess.h @@ -13,18 +13,6 @@ in the source distribution for its full text. #include #include -typedef enum SolarisProcessField_ { - // Add platform-specific fields here, with ids >= 100 - ZONEID = 100, - ZONE = 101, - PROJID = 102, - TASKID = 103, - POOLID = 104, - CONTID = 105, - LWPID = 106, - LAST_PROCESSFIELD = 107, -} SolarisProcessField; - typedef struct SolarisProcess_ { Process super; int kernel; @@ -46,7 +34,7 @@ typedef struct SolarisProcess_ { extern const ProcessClass SolarisProcess_class; -extern ProcessFieldData Process_fields[]; +extern ProcessFieldData Process_fields[LAST_PROCESSFIELD]; extern ProcessPidColumn Process_pidColumns[]; -- cgit v1.2.3