completed the move, output.* --> escape.*

This commit is contained in:
albert 2002-12-21 13:36:36 +00:00
parent b67dc52160
commit f2a0a095ba
4 changed files with 14 additions and 97 deletions

View File

@ -1,56 +0,0 @@
// Some output conversion routines for libproc
// Copyright (C) 1996, Charles Blake. See COPYING for details.
//
// Copyright 2002, Albert Cahalan
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "output.h"
#if 1
/* output a string, converting unprintables to octal as we go, and stopping after
processing max chars of output (accounting for expansion due to octal rep).
*/
unsigned print_str(FILE *restrict file, const char *restrict const s, unsigned max) {
unsigned i;
for (i=0; likely(s[i]) && likely(i<max); i++)
if (likely(isprint(s[i]) || s[i] == ' '))
fputc(s[i], file);
else {
if (max > i+3) {
fprintf(file, "\\%03o", (unsigned char)s[i]);
i += 3; /* 4 printed, but i counts one */
} else
return max - i;
}
return max - i;
}
#endif
/* output an argv style NULL-terminated string list, converting unprintables
to octal as we go, separating items of the list by 'sep' and stopping after
processing max chars of output (accounting for expansion due to octal rep).
*/
unsigned print_strlist(FILE *restrict file, const char *restrict const *restrict strs, unsigned max) {
unsigned i, n;
for (n=0; *strs && n<max; strs++) {
for (i=0; strs[0][i] && n+i < max; i++)
if (likely(isprint(strs[0][i]) || strs[0][i] == ' '))
fputc(strs[0][i], file);
else {
if (max > n+i+3) {
fprintf(file, "\\%03o", (unsigned char)strs[0][i]);
n += 3; /* 4 printed, but i counts one */
} else
return max - n;
}
n += i;
if (n + 1 < max) {
fputc(' ', file);
n++;
} else
return max - n;
}
return max - n;
}

View File

@ -1,15 +0,0 @@
#ifndef PROCPS_PROC_OUTPUT_H
#define PROCPS_PROC_OUTPUT_H
#include <stdio.h>
#include <sys/types.h>
#include "procps.h"
EXTERN_C_BEGIN
extern unsigned print_str (FILE *restrict file, const char *restrict s, unsigned max);
extern unsigned print_strlist(FILE *restrict file, const char *restrict const *restrict strs, unsigned max);
EXTERN_C_END
#endif

34
top.c
View File

@ -43,6 +43,7 @@
#include "proc/wchan.h" #include "proc/wchan.h"
#include "proc/procps.h" #include "proc/procps.h"
#include "proc/readproc.h" #include "proc/readproc.h"
#include "proc/escape.h"
#include "proc/sig.h" #include "proc/sig.h"
#ifdef USE_LIB_STA3 #ifdef USE_LIB_STA3
#include "proc/status.h" #include "proc/status.h"
@ -282,11 +283,8 @@ static inline char *scat (char *restrict dst, const char *restrict src)
} }
/* // Trim the rc file lines and any 'open_psdb_message' result which arrives
* This guy was originally designed just to trim the rc file lines and // with an inappropriate newline (thanks to 'sysmap_mmap')
* any 'open_psdb_message' result which arrived with an inappropriate
* newline (thanks to 'sysmap_mmap') -- but when tabs (^I) were found
* in some proc cmdlines, a choice was offered twix space or null. */
static char *strim_0 (char *str) static char *strim_0 (char *str)
{ {
static const char ws[] = "\b\e\f\n\r\t\v\x9b"; // 0x9b is an escape static const char ws[] = "\b\e\f\n\r\t\v\x9b"; // 0x9b is an escape
@ -296,20 +294,6 @@ static char *strim_0 (char *str)
return str; return str;
} }
/*
* This guy was originally designed just to trim the rc file lines and
* any 'open_psdb_message' result which arrived with an inappropriate
* newline (thanks to 'sysmap_mmap') -- but when tabs (^I) were found
* in some proc cmdlines, a choice was offered twix space or null. */
static char *strim_1 (char *str)
{
static const char ws[] = "\b\e\f\n\r\t\v\x9b"; // 0x9b is an escape
char *p;
while (unlikely(p = strpbrk(str, ws))) *p = ' ';
return str;
}
/* /*
* This guy just facilitates Batch and protects against dumb ttys * This guy just facilitates Batch and protects against dumb ttys
@ -1016,7 +1000,6 @@ static void prochlp (proc_t *this)
// we're just saving elapsed tics, to be converted into %cpu if // we're just saving elapsed tics, to be converted into %cpu if
// this task wins it's displayable screen row lottery... */ // this task wins it's displayable screen row lottery... */
this->pcpu = tics; this->pcpu = tics;
strim_1(this->cmd);
// if (Frames_maxcmdln) { } // if (Frames_maxcmdln) { }
// shout this to the world with the final call (or us the next time in) // shout this to the world with the final call (or us the next time in)
Frame_maxtask++; Frame_maxtask++;
@ -2909,6 +2892,7 @@ static void task_show (const WIN_t *q, const proc_t *p)
unsigned w = Fieldstab[i].width; unsigned w = Fieldstab[i].width;
switch (i) { switch (i) {
#if 0
case P_CMD: case P_CMD:
{ const char *cp; { const char *cp;
if (CHKw(q, Show_CMDLIN)) { if (CHKw(q, Show_CMDLIN)) {
@ -2930,6 +2914,16 @@ static void task_show (const WIN_t *q, const proc_t *p)
MKCOL(q->maxcmdln, q->maxcmdln, cp); MKCOL(q->maxcmdln, q->maxcmdln, cp);
} }
break; break;
#endif
case P_CMD:
{ char tmp[ROWBUFSIZ];
unsigned flags;
if (CHKw(q, Show_CMDLIN)) flags = ESC_DEFUNCT | ESC_BRACKETS | ESC_ARGS;
else flags = ESC_DEFUNCT;
escape_command(tmp, p, sizeof tmp, q->maxcmdln, flags);
MKCOL(q->maxcmdln, q->maxcmdln, tmp);
}
break;
case P_COD: case P_COD:
MKCOL(scale_num(PAGES_2K(p->trs), w, s)); MKCOL(scale_num(PAGES_2K(p->trs), w, s));
break; break;

6
w.c
View File

@ -10,7 +10,6 @@
#include "proc/readproc.h" #include "proc/readproc.h"
#include "proc/devname.h" #include "proc/devname.h"
#include "proc/procps.h" #include "proc/procps.h"
#include "proc/output.h"
#include "proc/sysinfo.h" #include "proc/sysinfo.h"
#include "proc/escape.h" #include "proc/escape.h"
#include <ctype.h> #include <ctype.h>
@ -221,11 +220,6 @@ static void showinfo(utmp_t *u, int formtype, int maxcmd, int from) {
char cmdbuf[512]; char cmdbuf[512];
escape_command(cmdbuf, best, sizeof cmdbuf, maxcmd, ESC_ARGS); escape_command(cmdbuf, best, sizeof cmdbuf, maxcmd, ESC_ARGS);
fputs(cmdbuf,stdout); fputs(cmdbuf,stdout);
// if (best->cmdline)
// print_strlist(stdout, best->cmdline, maxcmd);
// else
// printf("%*.*s", -maxcmd, maxcmd, best->cmd);
} else { } else {
printf("-"); printf("-");
} }