Commit Graph

13726 Commits

Author SHA1 Message Date
Eitan Adler
e3225dcf12 top(1): correct header, align it.
THR is always 6 digits or longer. Now that the PID/THR change is
separated, use correct headers.

PR:		228823
Reported by:	Trond.Endrestol@ximalas.info
2018-06-09 02:47:02 +00:00
Eitan Adler
4e08f2f53c top(1): actually make change for tid vs pid 2018-06-09 02:18:15 +00:00
Eitan Adler
fc36f5a7cb top(1): use a different command to toggle tid vs pid
- By popular demand, implement a different switch ("T") for toggling
between thread id and process id.
- Add an assert that the size of command chars is as expected.
- Also clean up some messiness I found when implementing this.
- Further document the new flag.

Requested by:	flo, ronald-lists@klop.ws, bapt
PR:		139389 (for the record)
X-MFC-With:	r334474
2018-06-09 02:14:33 +00:00
Kyle Evans
d1a920b48f bsdgrep(1): Evict character sequence that moved in
Reported by:	trasz
2018-06-08 12:58:55 +00:00
Eitan Adler
4fb80c7008 top(1): remove some unneeded indirection 2018-06-08 02:03:51 +00:00
Eitan Adler
d408c8f742 top(1): fix several style & const related issues
- use parens for return
- put function names on newline
- sprinkle const where possible
2018-06-08 01:55:47 +00:00
Kyle Evans
bd60b9b499 bsdgrep(1): Slooowly peel away the chunky onion
(or peel off the band-aid, whatever floats your boat)

This addresses two separate issues:

1.) Nothing within bsdgrep actually knew whether it cared about line numbers
  or not.

2.) The file layer knew nothing about the context in which it was being
  called.

#1 is only important when we're *not* processing line-by-line. #2 is
debatably a good idea; the parsing context is only handy because that's
where we store current offset information and, as of this commit, whether or
not it needs to be line-aware.
2018-06-08 01:25:07 +00:00
Kyle Evans
66f780aee0 bsdgrep(1): Don't initialize fts_flags twice
Admittedly, this is a clang-scan complaint... but it wasn't wrong. fts_flags
is initialized by all cases in the switch(), which should be fairly obvious.
Annotate this anyways.
2018-06-07 18:38:48 +00:00
Kyle Evans
40f0e0b100 bsdgrep(1): whoops, garbage collect the now write-only variable 2018-06-07 18:36:12 +00:00
Kyle Evans
cbfff13fa2 bsdgrep(1): Do some less dirty things with return types
Neither procfile nor grep_tree return anything meaningful to their callers.
None of the callers actually care about how many lines were matched in all
of the files they processed; it's all about "did anything match?"

This is generally just a light refactoring to remind me of what actually
matters as I'm rewriting these bits to care less about 'stuff'.
2018-06-07 18:27:58 +00:00
Baptiste Daroussin
30dc95029e Remove NLS support from BSD grep
GNU grep as in actually in base does not have any translations support
compiled in, so no functionnality loss.

We do support 193 locales in base, we will never catch up on that number of
translation with bsd grep.

Removing NLS support make bsd grep consistent with the other binaries in base
which are not translated, and also reduce a little bit the code.

Reviewed by:	kevans
Approved by:	kevans
Discussed with:	kevans @BSDCan
Differential Revision:	https://reviews.freebsd.org/D15682
2018-06-06 23:12:35 +00:00
Eitan Adler
59c8d5dc27 top(1): fix err again
I am amazed at my ability to get a one-line error reporting line wrong
thrice.
2018-06-06 07:13:27 +00:00
Eitan Adler
bca1b45bb1 top(1): make error message happy
We don't use a "size" variable, so just don't report it.

Reported by:	bapt
2018-06-06 06:42:12 +00:00
Piotr Pawel Stefaniak
0929b3d971 indent(1): fix buildworld after r334632
Fix
error: comparison of integers of different signs: 'int' and 'unsigned long'
by casting nitems() to int.

Reported by:	mjg
2018-06-04 21:21:55 +00:00
Piotr Pawel Stefaniak
d0f86f663f indent(1): add --version option
There exist multi-platform programs that check indent's version in order to
know what they can expect from it. GNU indent provides that via --version,
so implement the same option here.
2018-06-04 21:05:56 +00:00
Piotr Pawel Stefaniak
88b24a62d1 indent(1): remove the STACKSIZE macro and all of its use
It conflicts with a system-provided macro of the same name on another OS.
2018-06-04 20:39:58 +00:00
Piotr Pawel Stefaniak
4d0c622816 indent(1): remove static const char copyright[]
It repeats what is already said in the heading comment and it's optimized out
so serves no purpose.
2018-06-04 20:24:31 +00:00
Piotr Pawel Stefaniak
03e6aeef3a indent(1): replace BSD bcopy() with C memmove() 2018-06-04 19:47:24 +00:00
Eitan Adler
cda7a5d5ed top(1): some nitpicks
- prefer fully spelled names to "u_long"
- fix speeling
2018-06-04 05:27:00 +00:00
Eitan Adler
8d0d26767b 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
Eitan Adler
5dc98aeeaa top(1): Prefer memcpy over bcopy 2018-06-04 04:59:24 +00:00
Eitan Adler
a9a99372d9 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
Eitan Adler
eae589f1ce 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
Eitan Adler
9f8096e339 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
Piotr Pawel Stefaniak
aac30b753f 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
Piotr Pawel Stefaniak
50a2976094 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
Piotr Pawel Stefaniak
971e1c47ec 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
Piotr Pawel Stefaniak
5834814ee8 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
Piotr Pawel Stefaniak
2364d1a74e 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
Piotr Pawel Stefaniak
01a206e63c indent(1): if the token is a "[" then neither of the blocks is relevant 2018-06-03 18:38:03 +00:00
Piotr Pawel Stefaniak
fa7ea0c961 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
Piotr Pawel Stefaniak
9963ad6fdf indent(1): ignore null characters from input 2018-06-03 18:32:11 +00:00
Piotr Pawel Stefaniak
370d0cf9be indent(1): don't overflow di_stack[] 2018-06-03 18:29:20 +00:00
Piotr Pawel Stefaniak
9de29bfb5a 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
Piotr Pawel Stefaniak
1479f36d8e 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
Piotr Pawel Stefaniak
7c5f6031fe indent(1): avoid resetting last_bl to a bogus value when reallocating
underlying buffer
2018-06-03 17:11:01 +00:00
Piotr Pawel Stefaniak
bef613ff2f indent(1): the check for buffer overflow has to be done before copy 2018-06-03 17:07:56 +00:00
Piotr Pawel Stefaniak
33c2464207 indent(1): use errx() instead of abort() 2018-06-03 17:05:55 +00:00
Piotr Pawel Stefaniak
e1baf57e4b indent(1): limit character classification functions' input to unsigned char 2018-06-03 17:03:55 +00:00
Piotr Pawel Stefaniak
95b813e501 indent(1): recognize more type names
Most are from C99.
2018-06-03 16:52:30 +00:00
Piotr Pawel Stefaniak
9522d0b0d2 indent(1): don't format function declarations as variables 2018-06-03 16:42:58 +00:00
Piotr Pawel Stefaniak
e95d1e3c93 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
Piotr Pawel Stefaniak
f9287a9d85 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
Piotr Pawel Stefaniak
3c51c3cf5f 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
Piotr Pawel Stefaniak
63c3f22696 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
Piotr Pawel Stefaniak
ec5ac89ecd 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
Eitan Adler
a2cda47ac3 top(1): restore size for kern.cp_times
Restore last minute change that broke top(1).
2018-06-03 13:41:23 +00:00
Piotr Pawel Stefaniak
5bdd850968 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
Eitan Adler
c5484668f1 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
Eitan Adler
01a55f006a 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