Commit Graph

13763 Commits

Author SHA1 Message Date
eadler
137389006f top(1): some nitpicks
- prefer fully spelled names to "u_long"
- fix speeling
2018-06-04 05:27:00 +00:00
eadler
8876d70038 top(1): include what you use
- Change headers to more closely match what we use
- use more standard functions instead of bzero, bcmp, bcopy
- Add myself to authors.

Tested with: base clang (amd64), gcc 9 (amd64), base clang (i386), base
gcc (mips)
2018-06-04 04:59:32 +00:00
eadler
d702882720 top(1): Prefer memcpy over bcopy 2018-06-04 04:59:24 +00:00
eadler
185ad69fb8 top(1): Use strsep instead of homegrown alternative
This replaces some complex, and not quite correct logic, with a more
common strsep pattern.

Reviewed by:	mmacy (older version)
2018-06-04 03:16:24 +00:00
eadler
0d7f83c56e top(1): another pass of cleanup
- avoid the need to call a function to get size of known array. I'll
likely re-arrange some of the indirect in a later to avoid the magic
constants.
- use correct type
- add const
- replace caddr_t with void*. This corrects an alignment warning.
- remove duplicated include from immediately prior commit

Under base clang we're now down to:
- 3 warning in top.c, 1 warning in mahcine.c,  4 warning in display.c,
- 1 warning in utils.c

Tested with base clang, gcc7, gcc9, base gcc (mips)
2018-06-03 23:40:54 +00:00
eadler
098711ee0b top(1): top warnings and cleanup
- Add const where helpful
- add missing 'static' for file-local functions
- use nitems where possible
- convert manual abort() to assert
- use strndup instead of homegrown version

Tested with clang, gcc7, and gcc9
2018-06-03 22:42:54 +00:00
pstef
6eccd4e2ff indent(1): new option -lpl
With -lpl, code surrounded by parentheses in continuation lines is lined up
even if it would extend past the right margin.

With -nlpl (the default), such a line that would extend past the right
margin is moved left to keep it within the margin, if that does not require
placing it to the left of the prevailing indentation level.

These switches have no effect if -nlp is selected.

Submitted by:	Tom Lane
2018-06-03 21:40:38 +00:00
pstef
071fec746e indent(1): revert introduction of -lpl
That was committed with the wrong message. Will be re-added.
2018-06-03 21:34:29 +00:00
pstef
147d175e5b indent(1): new option -lpl (always line up to parenthesis)
With -lp, if a line has an opening paren which is not closed on that line,
then continuation lines will be lined up to start at the character position
just after the opening paren.

Submitted by:	Tom Lane
2018-06-03 20:59:59 +00:00
pstef
53803e008b indent(1): manual page corretions
Add missing options, synchronize syntax summary with the actual option list,
and other fixes.

Submitted by:	Tom Lane
2018-06-03 20:48:58 +00:00
pstef
39ef1b13f1 indent(1): if an identifier can be either a typedef name or as a struct
member, it is taken as the latter
2018-06-03 19:05:20 +00:00
pstef
d4d9bc816d indent(1): if the token is a "[" then neither of the blocks is relevant 2018-06-03 18:38:03 +00:00
pstef
e1f29e6859 indent(1): don't add a space after a label
It's not needed and it fools pr_comment().
2018-06-03 18:34:36 +00:00
pstef
4379cc770b indent(1): ignore null characters from input 2018-06-03 18:32:11 +00:00
pstef
89e7752398 indent(1): don't overflow di_stack[] 2018-06-03 18:29:20 +00:00
pstef
4522d5b3c8 indent(1): improve CHECK_SIZE_ macros
Rewrite the macros so that they take a parameter. Consumers use it to signal
how much room in the buffer they need; this lets them do that once when
required space is known instead of doing the check once every loop step.

Also take the parameter value into consideration when resizing the buffer;
the requested space may be larger than the constant 400 bytes that the
previous version used - now it's the sum of those two values.

On the consumer side, don't copy strings byte by byte - use memcpy().

Deduplicate code that copied base 2, base 8 and base 16 literals.

Don't advance the e_token pointer once the token has been copied into
s_token. This allows easy calculation of the token's length.
2018-06-03 18:19:41 +00:00
pstef
fa09e6dd12 indent(1): remove troff output support
The troff output in indent was invented at Sun and the online documentation
for some post-SunOS operating system includes this:
The usual way to  get  a  troffed listing is with the command
                       indent -troff program.c | troff -mindent

The indent manual page in FreeBSD 1.0 already lacks that information and
troff -mindent complains about not being able to find the macro file.
It seems that the file did exist on SunOS and was supposed to be imported
into 4.3BSD together with the feature, but that has never happened.

Removal of troff output support simplifies a lot of indent's code.

vgrind(1) seems to be a promising replacement.
2018-06-03 17:55:50 +00:00
pstef
4fc80e8f7e indent(1): avoid resetting last_bl to a bogus value when reallocating
underlying buffer
2018-06-03 17:11:01 +00:00
pstef
31b218bf54 indent(1): the check for buffer overflow has to be done before copy 2018-06-03 17:07:56 +00:00
pstef
4582635281 indent(1): use errx() instead of abort() 2018-06-03 17:05:55 +00:00
pstef
446b1ef90c indent(1): limit character classification functions' input to unsigned char 2018-06-03 17:03:55 +00:00
pstef
53a1560b95 indent(1): recognize more type names
Most are from C99.
2018-06-03 16:52:30 +00:00
pstef
861356c5ef indent(1): don't format function declarations as variables 2018-06-03 16:42:58 +00:00
pstef
fc608f4a8c indent(1): remove is_procname.
It was a shorthand for checking if ps.procname is a non-empty string; the
same can be done with ps.procname[0] which avoids the need for updating
is_procname after every call to lexi().
2018-06-03 16:27:40 +00:00
pstef
72a53430c7 indent(1): disjoint parser state from lexi()
The function is sometimes used as a look-ahead, so ideally it should bear
no information about parser state.
2018-06-03 16:21:15 +00:00
pstef
d51ca1681c indent(1): improve handling of boxed comments indentation
The trick is to copy everything from the start of the line into the buffer
that stores newlines and comments until indent finds a brace or an else.
pr_comment() will use that information to calculate the original indentation
of the boxed comment.

This requires storing two pieces of information: the real start of the
buffer (sc_buf) and the start of the comment (save_com).
2018-06-03 15:28:55 +00:00
pstef
ae62d09b33 indent(1): improve predictability of lexi()
lexi() reads the input stream and categorizes the next token. indent will
sometimes buffer up a sequence of tokens in order rearrange them. That is
needed for properly cuddling else or placing braces correctly according to
the chosen style (KNF vs Allman) when comments are around. The loop that
buffers tokens up uses lexi() to decide if it's time to stop buffering. Then
the temporary buffer is used to feed lexi() the same tokens again, this time
for normal processing.

The problem is that lexi() apart from recognizing the token, can change
a lot of information about the current state, for example ps.last_nl,
ps.keyword, buf_ptr. It also abandons leading whitespace, which is needed
mainly for comment-related considerations. So the call to lexi() while
tokens are buffered up and categorized can change the state before they're
read again for normal processing which may easily result in changing
interpretation of the current state and lead to incorrect output.

To work around the problems:
1) copy the whitespace into the save_com buffer so that it will be read
again when processed
2) trick lexi() into modifying a temporary copy of the parser state instead
of the original.
2018-06-03 14:13:11 +00:00
pstef
e8b30e87e5 indent(1): improve handling of comments and newlines between "if (...)" or
"while (...)" and "else" or "{"

* Don't flush newlines - there can be multiple of them and they can happen
before a token that isn't else or {. Instead, always store them in save_com.
* Don't dump the buffer's contents on newline assuming that there is only
one comment before else or {.
* Avoid producing surplus newlines, especially before else when -ce is on.
* When -bl is on, don't treat { as a comment (was implemented by falling
through "case lbrace:" to "case comment:").

This commit fixes the above, but exposes another bug and thus breaks several
other tests. Another commit will make them pass again.
2018-06-03 14:03:20 +00:00
eadler
5943c1f8ae top(1): restore size for kern.cp_times
Restore last minute change that broke top(1).
2018-06-03 13:41:23 +00:00
pstef
030d8b8eb9 indent(1): remove undocumented and rather useless option (-ps)
It's used to treat the "->" access operator as a binary operator and put
space characters around it.
2018-06-03 13:40:58 +00:00
eadler
6b69a377de top(1): Only use NO_WERROR for base gcc
This is what was intended. If statements are hard.
2018-06-03 06:02:31 +00:00
eadler
6458a7dc63 top(1): partial revert of r334517
In fixing issues with uid > INT_MAX, I broke the uid without username
case. The latter is more important so return the old state.

Discussed with:	allanjude
2018-06-03 05:20:11 +00:00
eadler
4991aba55b top(1): remove chdir to /
While this came out of a conversation in IRC, it turn out that some
people don't like it. Since this was a courtesy feature, just remove it.
2018-06-03 05:07:46 +00:00
eadler
e65f0721ff top(1): use greater warnings
One of the downsides of using numeric WARNS is that if we only have a
single type of issue we get no protection from other changes.  For
example, we got no warning for missing variable declaration, due to
the issues with "const".

For this utility, explicitly list out the warnings which are failing.
They should still be fixed, so only reduce them to warning instead of
error.

Tested with: clang base (amd64, i386), gcc6, gcc7, gcc9, gcc base (mips)
2018-06-03 05:07:39 +00:00
eadler
3dee6f7a13 top(1): misc minor improvements
- use bool instead of int [0]
- use calloc correctly [0]
	(this also caught an incorrect sizeof argument) [1]
- use size_t over int [2]
- correct style

Reported by:	pfg [0], scan-build [1], gcc [2]
2018-06-03 02:58:53 +00:00
eadler
7f99483fb2 top(1): Fix two speeling errors I introduced 2018-06-02 22:12:57 +00:00
eadler
4bce4f59c4 top(1): chdir to / as init; remove unneeded comment
- chdir to / to allow unmounting of wd
- remove warning about running top(1) as setuid. If this is a concern we
should just drop privs instead.
2018-06-02 22:06:27 +00:00
eadler
0296b74c55 top(1): cleanup memory allocation and warnings
- Prefer calloc over malloc. This is more predicable and we're not in a
performance sensitive context. [1]
- Remove bogus comment (obsolete from prior commit). [2]
- Remove void casts and type casts of NULL
- Remove redundant declaration of 'quit'
- Add additional const

Reported by:	kib [1], vangyzen [2]
2018-06-02 21:40:45 +00:00
jhibbits
45450d16d7 Included VSX registers in powerpc core dumps
Summary: Included VSX registers in powerpc core dumps (both kernel and gcore)

Submitted by:	Luis Pires
Differential Revision: https://reviews.freebsd.org/D15512
2018-06-02 20:28:58 +00:00
novel
f2fe0a1957 top: add -p option and p command to only show a single process
Allow to show only a single process specified by PID. This could
be done either by running top like 'top -p PID' or using the 'p' command
inside top.

Reviewed by:	eadler
Approved by:	eadler
Obtained from:	OpenBSD
Differential Revision:	https://reviews.freebsd.org/D15501
2018-06-02 15:52:18 +00:00
eadler
aa8c5e3456 Use stpcpy instead of home grown solution 2018-06-02 08:46:09 +00:00
eadler
a8efb181f4 top(1): remove wrapper around putchar
This appears to have been written for portability which we no longer
need.
2018-06-02 07:44:53 +00:00
eadler
1bb7502e75 top(1): const poison part 2
Further reduce the number of warnings emitted by gcc.
2018-06-02 07:44:50 +00:00
eadler
c60e3080a1 top(1): const poison
top(1) has a number of issues with writing to const strings. Begin
helping this along by marking easy cases as const.
2018-06-02 04:37:37 +00:00
eadler
dfdbe4a30f top(1): clean up a bit
- remove unused defines
- use standard defines for STDOUT
- don't cast for memset
- avoid using (void) cast
2018-06-02 04:20:42 +00:00
eadler
ff370bfd90 top(1): help scan-build along a bit
Teach scan-build that some arrays are larger than zero, and thus not to
warn.
2018-06-02 04:08:52 +00:00
eadler
d08be95677 top(1): Use uid_t for uid rather than 'int'
Remove unneeded define while here.
2018-06-02 03:54:50 +00:00
eadler
5af3d07de3 top(1): Remove now-invalid NOTE 2018-06-02 03:33:02 +00:00
eadler
f085a59180 top(1): avoid casting malloc 2018-06-02 03:31:14 +00:00
eadler
28565af2eb top(1): Use standard boolean rather than homegrown alternative 2018-06-02 03:25:15 +00:00