ugly wart gone
This commit is contained in:
parent
ac6260bc23
commit
35859fb0a8
@ -1,6 +1,6 @@
|
|||||||
#ifndef PROCPS_PROC_READPROC_H
|
#ifndef PROCPS_PROC_READPROC_H
|
||||||
#define PROCPS_PROC_READPROC_H
|
#define PROCPS_PROC_READPROC_H
|
||||||
/*
|
|
||||||
// New Interface to Process Table -- PROCTAB Stream (a la Directory streams)
|
// New Interface to Process Table -- PROCTAB Stream (a la Directory streams)
|
||||||
// Copyright 1996 Charles L. Blake.
|
// Copyright 1996 Charles L. Blake.
|
||||||
// Copyright 1998 Michael K. Johnson
|
// Copyright 1998 Michael K. Johnson
|
||||||
|
21
ps/common.h
21
ps/common.h
@ -71,6 +71,25 @@
|
|||||||
|
|
||||||
/******************* PS DEFINE *******************/
|
/******************* PS DEFINE *******************/
|
||||||
|
|
||||||
|
// Column flags
|
||||||
|
// Justification control for flags field comes first.
|
||||||
|
#define CF_JUST_MASK 0x0f
|
||||||
|
// CF_AIXHACK 0
|
||||||
|
#define CF_USER 1 // left if text, right if numeric
|
||||||
|
#define CF_LEFT 2
|
||||||
|
#define CF_RIGHT 3
|
||||||
|
#define CF_UNLIMITED 4
|
||||||
|
#define CF_WCHAN 5 // left if text, right if numeric
|
||||||
|
#define CF_SIGNAL 6 // right in 9, or 16 if screen_cols>107
|
||||||
|
// Then the other flags
|
||||||
|
#define CF_CUMUL 0x00000010 // mark cumulative (Summed) headers with 'C' */
|
||||||
|
#define CF_PIDMAX 0x00000020 // react to pid_max
|
||||||
|
#define CF_PRINT_THREAD_ONLY 0x10000000
|
||||||
|
#define CF_PRINT_PROCESS_ONLY 0x20000000
|
||||||
|
#define CF_PRINT_EVERY_TIME 0x40000000
|
||||||
|
#define CF_PRINT_AS_NEEDED 0x80000000 // means we have no clue, so assume EVERY TIME
|
||||||
|
|
||||||
|
|
||||||
#define needs_for_select (PROC_FILLSTAT | PROC_FILLSTATUS)
|
#define needs_for_select (PROC_FILLSTAT | PROC_FILLSTATUS)
|
||||||
|
|
||||||
/* thread_flags */
|
/* thread_flags */
|
||||||
@ -226,7 +245,7 @@ typedef struct sf_node {
|
|||||||
/********************* UNDECIDED GLOBALS **************/
|
/********************* UNDECIDED GLOBALS **************/
|
||||||
|
|
||||||
/* output.c */
|
/* output.c */
|
||||||
extern void show_one_proc(const proc_t *restrict const p);
|
extern void show_one_proc(const proc_t *restrict const p, const format_node *restrict fmt);
|
||||||
extern void print_format_specifiers(void);
|
extern void print_format_specifiers(void);
|
||||||
extern const aix_struct *search_aix_array(const int findme);
|
extern const aix_struct *search_aix_array(const int findme);
|
||||||
extern const shortsort_struct *search_shortsort_array(const int findme);
|
extern const shortsort_struct *search_shortsort_array(const int findme);
|
||||||
|
10
ps/display.c
10
ps/display.c
@ -251,11 +251,11 @@ static void simple_spew(void){
|
|||||||
memset(&buf, '#', sizeof(proc_t));
|
memset(&buf, '#', sizeof(proc_t));
|
||||||
while(readproc(ptp,&buf)){
|
while(readproc(ptp,&buf)){
|
||||||
if(want_this_proc(&buf)){
|
if(want_this_proc(&buf)){
|
||||||
if(thread_flags & TF_show_proc) show_one_proc(&buf);
|
if(thread_flags & TF_show_proc) show_one_proc(&buf,format_list);
|
||||||
if(thread_flags & TF_show_task){
|
if(thread_flags & TF_show_task){
|
||||||
proc_t buf2;
|
proc_t buf2;
|
||||||
// must still have the process allocated
|
// must still have the process allocated
|
||||||
while(readtask(ptp,&buf,&buf2)) show_one_proc(&buf2);
|
while(readtask(ptp,&buf,&buf2)) show_one_proc(&buf2,format_list);
|
||||||
// must not attempt to free cmdline and environ
|
// must not attempt to free cmdline and environ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,7 +313,7 @@ static int compare_two_procs(const void *a, const void *b){
|
|||||||
static void show_proc_array(int n){
|
static void show_proc_array(int n){
|
||||||
proc_t **p = processes;
|
proc_t **p = processes;
|
||||||
while(n--){
|
while(n--){
|
||||||
show_one_proc(*p);
|
show_one_proc(*p,format_list);
|
||||||
/* no point freeing any of this -- won't need more mem */
|
/* no point freeing any of this -- won't need more mem */
|
||||||
// if((*p)->cmdline) free((void*)*(*p)->cmdline);
|
// if((*p)->cmdline) free((void*)*(*p)->cmdline);
|
||||||
// if((*p)->environ) free((void*)*(*p)->environ);
|
// if((*p)->environ) free((void*)*(*p)->environ);
|
||||||
@ -334,7 +334,7 @@ static void show_tree(const int self, const int n, const int level, const int ha
|
|||||||
else forest_prefix[level-1] = 'L';
|
else forest_prefix[level-1] = 'L';
|
||||||
forest_prefix[level] = '\0';
|
forest_prefix[level] = '\0';
|
||||||
}
|
}
|
||||||
show_one_proc(processes[self]); /* first show self */
|
show_one_proc(processes[self],format_list); /* first show self */
|
||||||
/* no point freeing any of this -- won't need more mem */
|
/* no point freeing any of this -- won't need more mem */
|
||||||
// if(processes[self]->cmdline) free((void*)*processes[self]->cmdline);
|
// if(processes[self]->cmdline) free((void*)*processes[self]->cmdline);
|
||||||
// if(processes[self]->environ) free((void*)*processes[self]->environ);
|
// if(processes[self]->environ) free((void*)*processes[self]->environ);
|
||||||
@ -461,6 +461,6 @@ int main(int argc, char *argv[]){
|
|||||||
|
|
||||||
if(forest_type || sort_list) fancy_spew(); /* sort or forest */
|
if(forest_type || sort_list) fancy_spew(); /* sort or forest */
|
||||||
else simple_spew(); /* no sort, no forest */
|
else simple_spew(); /* no sort, no forest */
|
||||||
show_one_proc((proc_t *)-1); /* no output yet? */
|
show_one_proc((proc_t *)-1,format_list); /* no output yet? */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
76
ps/output.c
76
ps/output.c
@ -42,9 +42,6 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* proc_t offset macro */
|
|
||||||
#define PO(q) ((unsigned long)(&(((proc_t*)0)->q)))
|
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
@ -86,19 +83,6 @@ static unsigned max_rightward = 0x12345678; /* space for RIGHT stuff */
|
|||||||
static unsigned max_leftward = 0x12345678; /* space for LEFT stuff */
|
static unsigned max_leftward = 0x12345678; /* space for LEFT stuff */
|
||||||
|
|
||||||
|
|
||||||
/* Justification control for flags field. */
|
|
||||||
#define JUST_MASK 0x0f
|
|
||||||
// AIXHACK 0
|
|
||||||
#define USER 1 // left if text, right if numeric
|
|
||||||
#define LEFT 2
|
|
||||||
#define RIGHT 3
|
|
||||||
#define UNLIMITED 4
|
|
||||||
#define WCHAN 5 // left if text, right if numeric
|
|
||||||
#define SIGNAL 6 // right in 9, or 16 if screen_cols>107
|
|
||||||
|
|
||||||
#define CUMUL 0x10 // mark cumulative (Summed) headers with 'C' */
|
|
||||||
#define PIDMAX 0x20 // react to pid_max
|
|
||||||
|
|
||||||
|
|
||||||
static int wide_signals; /* true if we have room */
|
static int wide_signals; /* true if we have room */
|
||||||
|
|
||||||
@ -1122,6 +1106,20 @@ static int sr_context ( const proc_t* P, const proc_t* Q ) {
|
|||||||
* BSD n: "user" becomes "uid" and "wchan" becomes "nwchan" (number)
|
* BSD n: "user" becomes "uid" and "wchan" becomes "nwchan" (number)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Justification control for flags field. */
|
||||||
|
#define USER CF_USER // left if text, right if numeric
|
||||||
|
#define LEFT CF_LEFT
|
||||||
|
#define RIGHT CF_RIGHT
|
||||||
|
#define UNLIMITED CF_UNLIMITED
|
||||||
|
#define WCHAN CF_WCHAN // left if text, right if numeric
|
||||||
|
#define SIGNAL CF_SIGNAL // right in 9, or 16 if room
|
||||||
|
#define CUMUL CF_CUMUL
|
||||||
|
#define PIDMAX CF_PIDMAX
|
||||||
|
#define TO CF_PRINT_THREAD_ONLY
|
||||||
|
#define PO CF_PRINT_PROCESS_ONLY
|
||||||
|
#define ET CF_PRINT_EVERY_TIME
|
||||||
|
#define AN CF_PRINT_AS_NEEDED // no idea
|
||||||
|
|
||||||
/* short names to save space */
|
/* short names to save space */
|
||||||
#define MEM PROC_FILLMEM /* read statm */
|
#define MEM PROC_FILLMEM /* read statm */
|
||||||
#define ARG PROC_FILLARG /* read cmdline (cleared if c option) */
|
#define ARG PROC_FILLARG /* read cmdline (cleared if c option) */
|
||||||
@ -1131,10 +1129,6 @@ static int sr_context ( const proc_t* P, const proc_t* Q ) {
|
|||||||
#define GRP PROC_FILLGRP /* gid_t -> group names */
|
#define GRP PROC_FILLGRP /* gid_t -> group names */
|
||||||
#define WCH PROC_FILLWCHAN /* do WCHAN lookup */
|
#define WCH PROC_FILLWCHAN /* do WCHAN lookup */
|
||||||
|
|
||||||
#define TO PRINT_THREAD_ONLY
|
|
||||||
#define PO PRINT_PROCESS_ONLY
|
|
||||||
#define ET PRINT_EVERY_TIME
|
|
||||||
#define AN PRINT_AS_NEEDED // no idea
|
|
||||||
|
|
||||||
/* TODO
|
/* TODO
|
||||||
* pull out annoying BSD aliases into another table (to macro table?)
|
* pull out annoying BSD aliases into another table (to macro table?)
|
||||||
@ -1364,6 +1358,14 @@ static const format_struct format_array[] = {
|
|||||||
{"~", "-", pr_nop, sr_nop, 1, 0, LNX, AN|RIGHT} /* NULL would ruin alphabetical order */
|
{"~", "-", pr_nop, sr_nop, 1, 0, LNX, AN|RIGHT} /* NULL would ruin alphabetical order */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#undef USER
|
||||||
|
#undef LEFT
|
||||||
|
#undef RIGHT
|
||||||
|
#undef UNLIMITED
|
||||||
|
#undef WCHAN
|
||||||
|
#undef SIGNAL
|
||||||
|
#undef CUMUL
|
||||||
|
#undef PIDMAX
|
||||||
#undef PO
|
#undef PO
|
||||||
#undef TO
|
#undef TO
|
||||||
#undef AN
|
#undef AN
|
||||||
@ -1567,19 +1569,19 @@ static void check_header_width(void){
|
|||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
unsigned int sigs = 0;
|
unsigned int sigs = 0;
|
||||||
while(walk){
|
while(walk){
|
||||||
switch((walk->flags) & JUST_MASK){
|
switch((walk->flags) & CF_JUST_MASK){
|
||||||
default:
|
default:
|
||||||
total += walk->width;
|
total += walk->width;
|
||||||
total += was_normal;
|
total += was_normal;
|
||||||
was_normal = 1;
|
was_normal = 1;
|
||||||
break;
|
break;
|
||||||
case SIGNAL:
|
case CF_SIGNAL:
|
||||||
sigs++;
|
sigs++;
|
||||||
total += walk->width;
|
total += walk->width;
|
||||||
total += was_normal;
|
total += was_normal;
|
||||||
was_normal = 1;
|
was_normal = 1;
|
||||||
break;
|
break;
|
||||||
case UNLIMITED: /* could chop this a bit */
|
case CF_UNLIMITED: /* could chop this a bit */
|
||||||
if(walk->next) total += walk->width;
|
if(walk->next) total += walk->width;
|
||||||
else total += 3; /* not strlen(walk->name) */
|
else total += 3; /* not strlen(walk->name) */
|
||||||
total += was_normal;
|
total += was_normal;
|
||||||
@ -1599,12 +1601,6 @@ static void check_header_width(void){
|
|||||||
if(screen_cols*i >= OUTBUF_SIZE/2) break; /* can't go over */
|
if(screen_cols*i >= OUTBUF_SIZE/2) break; /* can't go over */
|
||||||
}
|
}
|
||||||
wide_signals = (total+sigs*7 <= active_cols);
|
wide_signals = (total+sigs*7 <= active_cols);
|
||||||
|
|
||||||
#if 0
|
|
||||||
printf("123456789-123456789-123456789-123456789-"
|
|
||||||
"123456789-123456789-123456789-123456789\n");
|
|
||||||
printf("need %d, using %d\n", total, active_cols);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1615,7 +1611,7 @@ static void check_header_width(void){
|
|||||||
|
|
||||||
static char *saved_outbuf;
|
static char *saved_outbuf;
|
||||||
|
|
||||||
void show_one_proc(const proc_t *restrict const p){
|
void show_one_proc(const proc_t *restrict const p, const format_node *restrict fmt){
|
||||||
/* unknown: maybe set correct & actual to 1, remove +/- 1 below */
|
/* unknown: maybe set correct & actual to 1, remove +/- 1 below */
|
||||||
int correct = 0; /* screen position we should be at */
|
int correct = 0; /* screen position we should be at */
|
||||||
int actual = 0; /* screen position we are at */
|
int actual = 0; /* screen position we are at */
|
||||||
@ -1624,17 +1620,15 @@ void show_one_proc(const proc_t *restrict const p){
|
|||||||
int space = 0; /* amount of space we actually need to print */
|
int space = 0; /* amount of space we actually need to print */
|
||||||
int dospace = 0; /* previous column determined that we need a space */
|
int dospace = 0; /* previous column determined that we need a space */
|
||||||
int legit = 0; /* legitimately stolen extra space */
|
int legit = 0; /* legitimately stolen extra space */
|
||||||
const format_node *restrict fmt = format_list;
|
|
||||||
char *restrict const outbuf = saved_outbuf;
|
char *restrict const outbuf = saved_outbuf;
|
||||||
static int did_stuff = 0; /* have we ever printed anything? */
|
static int did_stuff = 0; /* have we ever printed anything? */
|
||||||
|
|
||||||
if(unlikely(-1==(long)p)){ /* true only once, at the end */
|
if(unlikely(-1==(long)p)){ /* true only once, at the end */
|
||||||
check_header_width(); /* temporary test code */
|
|
||||||
if(did_stuff) return;
|
if(did_stuff) return;
|
||||||
/* have _never_ printed anything, but might need a header */
|
/* have _never_ printed anything, but might need a header */
|
||||||
if(!--lines_to_next_header){
|
if(!--lines_to_next_header){
|
||||||
lines_to_next_header = header_gap;
|
lines_to_next_header = header_gap;
|
||||||
show_one_proc(NULL);
|
show_one_proc(NULL,fmt);
|
||||||
}
|
}
|
||||||
/* fprintf(stderr, "No processes available.\n"); */ /* legal? */
|
/* fprintf(stderr, "No processes available.\n"); */ /* legal? */
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -1642,7 +1636,7 @@ void show_one_proc(const proc_t *restrict const p){
|
|||||||
if(likely(p)){ /* not header, maybe we should call ourselves for it */
|
if(likely(p)){ /* not header, maybe we should call ourselves for it */
|
||||||
if(unlikely(!--lines_to_next_header)){
|
if(unlikely(!--lines_to_next_header)){
|
||||||
lines_to_next_header = header_gap;
|
lines_to_next_header = header_gap;
|
||||||
show_one_proc(NULL);
|
show_one_proc(NULL,fmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
did_stuff = 1;
|
did_stuff = 1;
|
||||||
@ -1658,18 +1652,18 @@ void show_one_proc(const proc_t *restrict const p){
|
|||||||
/* prepare data and calculate leftpad */
|
/* prepare data and calculate leftpad */
|
||||||
if(likely(p) && likely(fmt->pr)) amount = (*fmt->pr)(outbuf,p);
|
if(likely(p) && likely(fmt->pr)) amount = (*fmt->pr)(outbuf,p);
|
||||||
else amount = strlen(strcpy(outbuf, fmt->name)); /* AIX or headers */
|
else amount = strlen(strcpy(outbuf, fmt->name)); /* AIX or headers */
|
||||||
switch((fmt->flags) & JUST_MASK){
|
switch((fmt->flags) & CF_JUST_MASK){
|
||||||
case 0: /* for AIX, assigned outside this file */
|
case 0: /* for AIX, assigned outside this file */
|
||||||
leftpad = 0;
|
leftpad = 0;
|
||||||
break;
|
break;
|
||||||
case LEFT: /* bad */
|
case CF_LEFT: /* bad */
|
||||||
leftpad = 0;
|
leftpad = 0;
|
||||||
break;
|
break;
|
||||||
case RIGHT: /* OK */
|
case CF_RIGHT: /* OK */
|
||||||
leftpad = fmt->width - amount;
|
leftpad = fmt->width - amount;
|
||||||
if(leftpad < 0) leftpad = 0;
|
if(leftpad < 0) leftpad = 0;
|
||||||
break;
|
break;
|
||||||
case SIGNAL:
|
case CF_SIGNAL:
|
||||||
/* if the screen is wide enough, use full 16-character output */
|
/* if the screen is wide enough, use full 16-character output */
|
||||||
if(wide_signals){
|
if(wide_signals){
|
||||||
leftpad = 16 - amount;
|
leftpad = 16 - amount;
|
||||||
@ -1679,12 +1673,12 @@ void show_one_proc(const proc_t *restrict const p){
|
|||||||
}
|
}
|
||||||
if(leftpad < 0) leftpad = 0;
|
if(leftpad < 0) leftpad = 0;
|
||||||
break;
|
break;
|
||||||
case USER: /* bad */
|
case CF_USER: /* bad */
|
||||||
leftpad = fmt->width - amount;
|
leftpad = fmt->width - amount;
|
||||||
if(leftpad < 0) leftpad = 0;
|
if(leftpad < 0) leftpad = 0;
|
||||||
if(!user_is_number) leftpad = 0;
|
if(!user_is_number) leftpad = 0;
|
||||||
break;
|
break;
|
||||||
case WCHAN: /* bad */
|
case CF_WCHAN: /* bad */
|
||||||
if(wchan_is_number){
|
if(wchan_is_number){
|
||||||
leftpad = fmt->width - amount;
|
leftpad = fmt->width - amount;
|
||||||
if(leftpad < 0) leftpad = 0;
|
if(leftpad < 0) leftpad = 0;
|
||||||
@ -1704,7 +1698,7 @@ void show_one_proc(const proc_t *restrict const p){
|
|||||||
leftpad = 0;
|
leftpad = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case UNLIMITED:
|
case CF_UNLIMITED:
|
||||||
if(unlikely(fmt->next)){
|
if(unlikely(fmt->next)){
|
||||||
outbuf[fmt->width] = '\0'; /* Must chop, more columns! */
|
outbuf[fmt->width] = '\0'; /* Must chop, more columns! */
|
||||||
}else{
|
}else{
|
||||||
|
@ -31,11 +31,6 @@ static int have_gnu_sort = 0; /* if true, "O" must be format */
|
|||||||
static int already_parsed_sort = 0; /* redundantly set in & out of fn */
|
static int already_parsed_sort = 0; /* redundantly set in & out of fn */
|
||||||
static int already_parsed_format = 0;
|
static int already_parsed_format = 0;
|
||||||
|
|
||||||
#ifndef COL_PIDMAX
|
|
||||||
#warning Ugly wart needs fixing, use common.h to sync w/ output.c
|
|
||||||
#define COL_PIDMAX 0x20
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/**************** Parse single format specifier *******************/
|
/**************** Parse single format specifier *******************/
|
||||||
static format_node *do_one_spec(const char *spec, const char *override){
|
static format_node *do_one_spec(const char *spec, const char *override){
|
||||||
@ -47,7 +42,7 @@ static format_node *do_one_spec(const char *spec, const char *override){
|
|||||||
int w1, w2;
|
int w1, w2;
|
||||||
format_node *thisnode;
|
format_node *thisnode;
|
||||||
thisnode = malloc(sizeof(format_node));
|
thisnode = malloc(sizeof(format_node));
|
||||||
if(fs->flags & COL_PIDMAX){
|
if(fs->flags & CF_PIDMAX){
|
||||||
w1 = (int)get_pid_digits();
|
w1 = (int)get_pid_digits();
|
||||||
w2 = strlen(fs->head);
|
w2 = strlen(fs->head);
|
||||||
if(w2>w1) w1=w2; // FIXME w/ separate header/body column sizing
|
if(w2>w1) w1=w2; // FIXME w/ separate header/body column sizing
|
||||||
|
Loading…
x
Reference in New Issue
Block a user