$TOPRC, eliminate status() fn, avoid /proc/*/stat more

This commit is contained in:
albert 2004-08-30 17:30:41 +00:00
parent 0d77d98bf3
commit 55b3e73334
4 changed files with 15 additions and 65 deletions

View File

@ -1,30 +0,0 @@
// Copyright (C) 1992-1998 by Michael K. Johnson, johnsonm@redhat.com
// Copyright 2002 Albert Cahalan
//
// This file is placed under the conditions of the GNU Library
// General Public License, version 2, or any later version.
// See file COPYING for information on distribution conditions.
#include "procps.h"
#include "readproc.h"
#include "status.h"
const char * status(const proc_t *restrict task) {
static char buf[4] = " ";
buf[0] = task->state;
if (task->rss == 0 && task->state != 'Z')
buf[1] = 'W';
else
buf[1] = ' ';
if (task->nice < 0)
buf[2] = '<';
else if (task->nice > 0)
buf[2] = 'N';
else
buf[2] = ' ';
return(buf);
}

View File

@ -1,12 +0,0 @@
#ifndef PROC_STATUS_H
#define PROC_STATUS_H
#include "procps.h"
EXTERN_C_BEGIN
extern const char * status(const proc_t *restrict task);
EXTERN_C_END
#endif

37
top.c
View File

@ -49,9 +49,6 @@
#include "proc/readproc.h"
#include "proc/escape.h"
#include "proc/sig.h"
#ifdef USE_LIB_STA3
#include "proc/status.h"
#endif
#include "proc/sysinfo.h"
#include "proc/version.h"
#include "proc/whattime.h"
@ -1114,25 +1111,24 @@ static proc_t **procs_refresh (proc_t **table, int flags)
#undef ENTsz
}
/*###### Field Table/RCfile compatability support ######################*/
/* These are the Fieldstab.lflg values used here and in reframewins.
(own identifiers as documentation and protection against changes) */
// from either 'stat' or 'status' (preferred), via bits not otherwise used
#define L_EITHER PROC_SPARE_1
// These are the Fieldstab.lflg values used here and in reframewins.
// (own identifiers as documentation and protection against changes)
#define L_stat PROC_FILLSTAT
#define L_statm PROC_FILLMEM
#define L_status PROC_FILLSTATUS
#define L_CMDLINE L_stat | PROC_FILLARG
#define L_CMDLINE L_EITHER | PROC_FILLARG
#define L_EUSER PROC_FILLUSR
#define L_RUSER L_status | PROC_FILLUSR
#define L_GROUP L_status | PROC_FILLGRP
#define L_NONE 0
// from either 'stat' or 'status' (preferred), via bits not otherwise used
#define L_EITHER PROC_SPARE_1
// for reframewins and summary_show 1st pass
// for reframewins and summary_show 1st pass
#define L_DEFAULT PROC_FILLSTAT
// a temporary macro, soon to be undef'd...
// a temporary macro, soon to be undef'd...
#define SF(f) (QFP_t)sort_P_ ## f
/* These are our gosh darn 'Fields' !
@ -1170,11 +1166,7 @@ static FLD_t Fieldstab[] = {
{ "TtPp", " SHR", " %4.4s", 4, SK_Kb, SF(SHR), "Shared Mem size (kb)", L_statm },
{ "UuJj", " nFLT", " %4.4s", 4, SK_no, SF(FLT), "Page Fault count", L_stat },
{ "VvSs", " nDRT", " %4.4s", 4, SK_no, SF(DRT), "Dirty Pages count", L_statm },
#ifdef USE_LIB_STA3
{ "WwVv", " STA", " %3.3s", -1, -1, SF(STA), "Process Status", L_stat },
#else
{ "WwVv", " S", " %c", -1, -1, SF(STA), "Process Status", L_EITHER },
#endif
// next entry's special: '.head' will be formatted using table entry's own
// '.fmts' plus runtime supplied conversion args!
{ "XxXx", " COMMAND", " %-*.*s", -1, -1, SF(CMD), "Command name/line", L_EITHER },
@ -1638,9 +1630,14 @@ static void configs_read (void)
close(fd);
}
snprintf(Rc_name, sizeof(Rc_name), ".%src", Myname); // eeew...
if (getenv("HOME"))
snprintf(Rc_name, sizeof(Rc_name), "%s/.%src", getenv("HOME"), Myname);
if (getenv("TOPRC")) { // should switch on Myname before documenting this?
// not the most optimal here...
snprintf(Rc_name, sizeof(Rc_name), "%s", getenv("TOPRC"));
} else {
snprintf(Rc_name, sizeof(Rc_name), ".%src", Myname); // eeew...
if (getenv("HOME"))
snprintf(Rc_name, sizeof(Rc_name), "%s/.%src", getenv("HOME"), Myname);
}
rcf = def_rcf;
fd = open(Rc_name, O_RDONLY);
@ -2983,11 +2980,7 @@ static void task_show (const WIN_t *q, const proc_t *p)
MKCOL(scale_num(PAGES_TO_KB(p->share), w, s));
break;
case P_STA:
#ifdef USE_LIB_STA3
MKCOL(status(p));
#else
MKCOL(p->state);
#endif
break;
case P_SWP:
MKCOL(scale_num(PAGES_TO_KB(p->size - p->resident), w, s));

1
top.h
View File

@ -27,7 +27,6 @@
//#define CASEUP_SCALE // show scaled time/num suffix upper case
//#define CASEUP_SUMMK // show memory summary kilobytes with 'K'
//#define SORT_SUPRESS // *attempt* to reduce qsort overhead
//#define USE_LIB_STA3 // use lib status (3 ch) vs. proc_t (1 ch)
//#define WARN_NOT_SMP // restrict '1' & 'I' commands to true smp
// Development/Debugging defines -----------------------------------