Commit 0fda206a authored by albert's avatar albert

warning and variable name fixes

parent c785a0e3
......@@ -212,40 +212,43 @@ static void init_libproc(void){
#define NAN (-0.0)
#endif
#define JT unsigned long long
void five_cpu_numbers(double *uret, double *nret, double *sret, double *iret, double *Iret){
double tmp_u, tmp_n, tmp_s, tmp_i, tmp_I;
void five_cpu_numbers(double *uret, double *nret, double *sret, double *iret, double *wret){
double tmp_u, tmp_n, tmp_s, tmp_i, tmp_w;
double scale; /* scale values to % */
static JT old_u, old_n, old_s, old_i, old_I;
JT new_u, new_n, new_s, new_i, new_I;
static JT old_u, old_n, old_s, old_i, old_w;
JT new_u, new_n, new_s, new_i, new_w;
JT ticks_past; /* avoid div-by-0 by not calling too often :-( */
tmp_w = 0.0;
new_w = 0;
FILE_TO_BUF(STAT_FILE,stat_fd);
sscanf(buf, "cpu %Lu %Lu %Lu %Lu %Lu", &new_u, &new_n, &new_s, &new_i, &new_I);
ticks_past = (new_u+new_n+new_s+new_i+new_I)-(old_u+old_n+old_s+old_i+old_I);
sscanf(buf, "cpu %Lu %Lu %Lu %Lu %Lu", &new_u, &new_n, &new_s, &new_i, &new_w);
ticks_past = (new_u+new_n+new_s+new_i+new_w)-(old_u+old_n+old_s+old_i+old_w);
if(ticks_past){
scale = 100.0 / (double)ticks_past;
tmp_u = ( (double)new_u - (double)old_u ) * scale;
tmp_n = ( (double)new_n - (double)old_n ) * scale;
tmp_s = ( (double)new_s - (double)old_s ) * scale;
tmp_i = ( (double)new_i - (double)old_i ) * scale;
tmp_I = ( (double)new_I - (double)old_I ) * scale;
tmp_w = ( (double)new_w - (double)old_w ) * scale;
}else{
tmp_u = NAN;
tmp_n = NAN;
tmp_s = NAN;
tmp_i = NAN;
tmp_I = NAN;
tmp_w = NAN;
}
SET_IF_DESIRED(uret, tmp_u);
SET_IF_DESIRED(nret, tmp_n);
SET_IF_DESIRED(sret, tmp_s);
SET_IF_DESIRED(iret, tmp_i);
SET_IF_DESIRED(iret, tmp_I);
SET_IF_DESIRED(wret, tmp_w);
old_u=new_u;
old_n=new_n;
old_s=new_s;
old_i=new_i;
old_i=new_I;
old_w=new_w;
}
#undef JT
......
......@@ -5,7 +5,7 @@ extern unsigned long long Hertz; /* clock tick frequency */
extern long smp_num_cpus; /* number of CPUs */
#define JT double
extern void five_cpu_numbers(JT *uret, JT *nret, JT *sret, JT *iret, JT *Iret);
extern void five_cpu_numbers(JT *uret, JT *nret, JT *sret, JT *iret, JT *wret);
#undef JT
extern int uptime (double *uptime_secs, double *idle_secs);
......
......@@ -669,7 +669,7 @@ static int get_int (const char *prompt)
* SK_Kb (1) it's kilobytes
* SK_Mb (2) it's megabytes
* SK_Gb (3) it's gigabytes */
static char *scale_num (unsigned num, const unsigned width, const unsigned type)
static char *scale_num (unsigned num, const int width, const unsigned type)
{
/* kilobytes, megabytes, gigabytes, duh! */
static float scale[] = { 1024, 1024*1024, 1024*1024*1024, 0 };
......@@ -705,7 +705,7 @@ static char *scale_num (unsigned num, const unsigned width, const unsigned type)
/*
* Do some scaling stuff.
* Format 'tics' to fit 'width' */
static char *scale_tics (TICS_t tics, const unsigned width)
static char *scale_tics (TICS_t tics, const int width)
{
#define T1 "%u:%02u.%02u"
#define T2 "%u:%02u"
......@@ -828,7 +828,7 @@ static CPUS_t *refreshcpus (CPUS_t *cpus)
/* first value the last slot with the cpu summary line */
if (!fgets(buf, sizeof(buf), fp)) std_err("failed /proc/stat read");
if (4 > sscanf(buf, CPU_FMTS_JUST1
, &cpus[Cpu_tot].u, &cpus[Cpu_tot].n, &cpus[Cpu_tot].s, &cpus[Cpu_tot].i, &cpus[Cpu_tot].I))
, &cpus[Cpu_tot].u, &cpus[Cpu_tot].n, &cpus[Cpu_tot].s, &cpus[Cpu_tot].i, &cpus[Cpu_tot].w))
std_err("failed /proc/stat read");
/* and now value each separate cpu's tics */
......@@ -841,7 +841,7 @@ static CPUS_t *refreshcpus (CPUS_t *cpus)
if (!fgets(buf, sizeof(buf), fp)) std_err("failed /proc/stat read");
if (4 > sscanf(buf, CPU_FMTS_MULTI
#endif
, &cpus[i].u, &cpus[i].n, &cpus[i].s, &cpus[i].i, &cpus[i].I))
, &cpus[i].u, &cpus[i].n, &cpus[i].s, &cpus[i].i, &cpus[i].w))
std_err("failed /proc/stat read");
}
......@@ -858,7 +858,10 @@ static proc_t **refreshprocs (proc_t **tbl)
#define PTRsz sizeof(proc_t *) /* eyeball candy */
#define ENTsz sizeof(proc_t)
static int flags = PROC_FILLMEM | PROC_FILLCOM | PROC_FILLUSR
| PROC_FILLGRP | PROC_FILLSTATUS | PROC_FILLSTAT;
#ifndef UGH_ITS_4_RH
| PROC_FILLGRP
#endif
| PROC_FILLSTATUS | PROC_FILLSTAT;
static unsigned savmax = 0; /* first time, Bypass: (i) */
proc_t *ptsk = (proc_t *)-1; /* first time, Force: (ii) */
unsigned curmax = 0; /* every time (jeeze) */
......@@ -1216,9 +1219,8 @@ static void display_fields (const char *fields, const char *xtra)
const char *p;
int i, cmax = Screen_cols / 2, rmax = Screen_rows - yRSVD;
/* we're relying on our callers to first clear the screen --
thus 'fields_toggle' can avoid screen flicker since he's
too lazy to handle his own asterisk (*) logic */
/* we're relying on callers to first clear the screen and thus avoid screen
flicker if they're too lazy to handle their own asterisk (*) logic */
putp(Cap_bold);
for (i = 0; i < MAXTBL(Fieldstab); ++i) {
int b = (NULL != strchr(fields, i + 'A'));
......@@ -1416,7 +1418,7 @@ static void win_names (WIN_t *q, const char *name)
/*
* Display a window/field group (ie. make it "current"). */
static void win_select (int ch)
static void win_select (char ch)
{
static const char *prompt = "Choose field group (1 - 4)";
......@@ -1694,15 +1696,15 @@ static void cpudo (CPUS_t *cpu, const char *pfx)
/* we'll trim to zero if we get negative time ticks,
which has happened with some SMP kernels (pre-2.4?) */
#define TRIMz(x) ((tz = (STIC_t)x) < 0 ? 0 : tz)
STIC_t u_frme, s_frme, n_frme, i_frme, I_frme, tot_frme, tz;
STIC_t u_frme, s_frme, n_frme, i_frme, w_frme, tot_frme, tz;
float scale;
u_frme = TRIMz(cpu->u - cpu->u_sav);
s_frme = TRIMz(cpu->s - cpu->s_sav);
n_frme = TRIMz(cpu->n - cpu->n_sav);
i_frme = TRIMz(cpu->i - cpu->i_sav);
I_frme = TRIMz(cpu->I - cpu->I_sav);
tot_frme = u_frme + s_frme + n_frme + i_frme + I_frme;
w_frme = TRIMz(cpu->w - cpu->w_sav);
tot_frme = u_frme + s_frme + n_frme + i_frme + w_frme;
if (1 > tot_frme) tot_frme = 1;
scale = 100.0 / (float)tot_frme;
......@@ -1714,7 +1716,7 @@ static void cpudo (CPUS_t *cpu, const char *pfx)
, (float)s_frme * scale
, (float)n_frme * scale
, (float)i_frme * scale
, (float)I_frme * scale));
, (float)w_frme * scale));
Msg_row += 1;
/* remember for next time around */
......@@ -1722,7 +1724,7 @@ static void cpudo (CPUS_t *cpu, const char *pfx)
cpu->s_sav = cpu->s;
cpu->n_sav = cpu->n;
cpu->i_sav = cpu->i;
cpu->I_sav = cpu->I;
cpu->w_sav = cpu->w;
#undef TRIMz
}
......
......@@ -165,12 +165,12 @@ typedef struct {
n, /* (not in the order of our display) */
s,
i,
I;
w;
TICS_t u_sav, /* tics count in the order of our display */
s_sav,
n_sav,
i_sav,
I_sav;
w_sav;
} CPUS_t;
/* The scaling 'type' used with scale_num() -- this is how
......@@ -288,7 +288,7 @@ typedef struct win {
/* An rcfile 'footprint' used to invalidate existing local rcfile
and the global rcfile path + name */
#define RCF_FILEID 'j'
#define RCF_FILEID 'a'
#define SYS_RCFILE "/etc/toprc"
/* The default fields displayed and their order,
......@@ -402,10 +402,14 @@ typedef struct win {
" 0x00000200 PF_DUMPCORE\n" \
" 0x00000400 PF_SIGNALED\n" \
" 0x00000800 PF_MEMALLOC\n" \
" 0x00040000 PF_KERNTHREAD (2.5)\n" \
" 0x00002000 PF_FREE_PAGES (2.5)\n" \
" 0x00008000 debug flag (2.5)\n" \
" 0x00024000 special threads (2.5)\n" \
" 0x001D0000 special states (2.5)\n" \
" 0x00100000 PF_USEDFPU (thru 2.4)\n" \
" 0x00400000 PF_ATOMICALLOC\n" \
""
/* no room, sacrificed this one: 'Killed for out-of-memory' */
/* " 0x00001000 PF_MEMDIE (2.5)\n" ....................... */
/* Sort Select specially formatted string(s) --
see 'show_special' for syntax details + other cautions
......@@ -522,8 +526,8 @@ typedef struct win {
//atic char *ask4str (const char *prompt);
//atic float get_float (const char *prompt);
//atic int get_int (const char *prompt);
//atic char *scale_num (unsigned num, const unsigned width, const unsigned type);
//atic char *scale_tics (TICS_t tics, const unsigned width);
//atic char *scale_num (unsigned num, const int width, const unsigned type);
//atic char *scale_tics (TICS_t tics, const int width);
//atic float time_elapsed (void);
/*------ Library Alternatives ------------------------------------------*/
//atic void *alloc_c (unsigned numb);
......@@ -544,7 +548,7 @@ typedef struct win {
/*------ Windows/Field Groups support ----------------------------------*/
//atic void win_colsheads (WIN_t *q);
//atic void win_names (WIN_t *q, const char *name);
//atic void win_select (int ch);
//atic void win_select (char ch);
//atic int win_warn (void);
//atic void winsclr (WIN_t *q, int save);
//atic void wins_colors (void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment