Commit Graph

20138 Commits

Author SHA1 Message Date
rillig c5b428c7c1 indent: fix handling of INDENT OFF/ON comments
Previously, the 'INDENT OFF' comments were interpreted when the newline
token from the line above the comment was processed, which was earlier
than could be reasonably expected.

The 'INDENT ON' comments were interpreted equally early, which led to
the situation that the 'INDENT OFF' comments were preserved literally
but the 'INDENT ON' comments weren't.
2023-05-16 08:04:03 +00:00
rillig c73b132b15 indent: move parsing of 'INDENT OFF/ON' comments to the lexer
No functional change.
2023-05-16 07:13:05 +00:00
rillig a0b2b7f9f6 indent: clean up detection of whether parentheses form a cast
No functional change.
2023-05-15 22:52:21 +00:00
rillig 62cf6a24f7 indent: fix cast detection
In process_lparen_or_lbracket, ps.paren[...].maybe_cast was not
initialized, which may have been the cause for seemingly random spacing
around binary operators.

While here, clean up the code by reducing the number of accesses to the
parser state.
2023-05-15 22:35:41 +00:00
rillig 70c3f641d2 indent: fix detection of casts
A word followed by a '(' does not start a cast expression.
2023-05-15 21:51:45 +00:00
rillig 62d29170f1 indent: fix type cast in function definition 2023-05-15 20:50:37 +00:00
rillig 4ebb9a565a indent: clean up local indentation profile
The -eei option now works, the type hints are no longer necessary.
2023-05-15 20:35:56 +00:00
rillig a59ea3192b indent: fix duplicate space between comment and binary operator 2023-05-15 20:30:20 +00:00
rillig 9b57bdf0e0 indent: format its own code, extend some comments
With manual corrections, as there are still some bugs left.

No functional change.
2023-05-15 20:12:28 +00:00
rillig 2aaa93dadf indent: fix line wrapping of comments to the right of code 2023-05-15 19:55:51 +00:00
rillig 219ccf6233 indent: improve type guessing, fix formatting of declarations 2023-05-15 18:22:40 +00:00
rillig 3842fd14e5 indent: remove backslash line continuation outside preprocessing
The indenter did not handle these backslashes well, interpreting them as
unary operators, and they are an edge case anyway.  Line continuations
in string literals and character constants are kept.
2023-05-15 17:28:14 +00:00
rillig 6c38484f82 indent: fix spacing between function prototype and attributes 2023-05-15 14:55:47 +00:00
rillig c74302075d indent: fix indentation of struct member names 2023-05-15 14:12:03 +00:00
rillig 9a3c1ba4c8 indent: indent multi-line conditions
No functional change.
2023-05-15 13:37:16 +00:00
rillig b33d7ae266 indent: fix indentation of statements after controlling expression 2023-05-15 13:33:19 +00:00
rillig 8bbe0ac207 indent: fix indentation of expressions in -nlp -eei mode 2023-05-15 12:59:43 +00:00
rillig 09166ed3ac indent: fix indentation of multi-line '?:' expressions in functions 2023-05-15 10:13:40 +00:00
rillig 0aeec855d0 indent: group parser state by topic
No functional change.
2023-05-15 09:53:32 +00:00
rillig c5f73abc75 indent: let indent format its own code
With manual corrections, as indent does not properly indent multi-line
'?:' expressions nor multi-line controlling expressions.
2023-05-15 09:22:53 +00:00
rillig d78c6deb28 indent: document feature toggle for debugging output 2023-05-15 09:00:51 +00:00
rillig 89e0e636cf indent: fix spacing in for loop with declaration (since 2022-02-13) 2023-05-15 08:56:39 +00:00
rillig dca2e8fb00 indent: remove redundant include lines 2023-05-15 08:11:27 +00:00
rillig 3569a691ac indent: clean up memory allocation
No functional change.
2023-05-15 08:02:01 +00:00
rillig 44b1010705 indent: move debugging code to separate file
No functional change.
2023-05-15 07:57:22 +00:00
rillig 9a2185a149 indent: clean up memory and buffer management
Remove the need to explicitly initialize the buffers.  To avoid
subtracting null pointers or comparing them using '<', migrate the
buffers from the (start, end) form to the (start, len) form.  This form
also avoids inconsistencies in whether 'buf.e == buf.s' or 'buf.s ==
buf.e' is used.

Make buffer.st const, to avoid accidental modification of the buffer's
content.

Replace '*buf.e++ = ch' with buf_add_char, to avoid having to keep track
how much unwritten space is left in the buffer.  Remove all safety
margins, that is, no more unchecked access to buf.st[-1] or appending
using '*buf.e++'.

Fix line number counting in lex_word for words that contain line breaks.

No functional change.
2023-05-15 07:28:45 +00:00
rillig 506e3bec5c indent: only null-terminate the buffers if necessary
The only case where a buffer is used as a C-style string is when looking
up a keyword.

No functional change.
2023-05-14 22:26:37 +00:00
rillig 942c4f27e1 indent: shorten variable names for indenting comments
No functional change.
2023-05-14 18:05:52 +00:00
rillig 1304bdca7f indent: fix handling of multiple block comments in a line 2023-05-14 17:53:38 +00:00
rillig 217e4d847d indent: in comments, keep a leading tab
This kind of comments is used for the CVS IDs at the top of files.
2023-05-14 17:13:37 +00:00
rillig 0cd0431ee6 indent: fix vertical spacing after declarations
A comment is not supposed to change the state of the 'blank line after
declaration', but it did.  The initialization of saved_just_saw_decl was
wrong though since it tried to capture the previous value after it had
already been overwritten.
2023-05-14 16:47:06 +00:00
rillig eb14db9dab indent: reduce code for scanning tokens
The input line is guaranteed to end with '\n', so there's no need to
carry another pointer around.

No functional change.
2023-05-14 14:14:07 +00:00
rillig 0081badbbf indent: remove foreign RCS IDs 2023-05-14 12:12:02 +00:00
rillig e04d6833e7 indent: miscellaneous cleanups 2023-05-14 11:29:23 +00:00
rillig a7a4fde319 indent: reduce binary size
No functional change.
2023-05-14 11:02:53 +00:00
rillig 4f2a635091 lint: add query for chained assignments 2023-05-13 20:55:44 +00:00
rillig 8c2ceb1bdd indent: prevent undefined behavior on unbalanced parentheses 2023-05-13 17:54:34 +00:00
rillig ee7d9431ec indent: do not add a blank at the beginning of a line
Most calls to output_line did already reset the variable.  There may be
some untested edge cases in or after comments, but these should be fine
as well.
2023-05-13 17:20:41 +00:00
rillig c49e59f750 indent: do not add a space before a comment that starts a line 2023-05-13 16:40:18 +00:00
rillig 09f60083f6 indent: replace __dead functions with return statements
No functional change.
2023-05-13 16:19:37 +00:00
rillig 2261e976c8 indent: implement 'blank after declarations' 2023-05-13 15:34:22 +00:00
rillig ae0013d277 indent: use enum instead of magic numbers for tracking declarations
No functional change.
2023-05-13 14:30:48 +00:00
rillig 3c4b7d72f3 indent: improve names of option variables
No functional change.
2023-05-13 13:48:54 +00:00
rillig 272b0ac37c indent: add debug logging for enum token classification 2023-05-13 13:45:24 +00:00
rillig 24dd152d37 indent: fix lexing of numbers that are spread over multiple lines 2023-05-13 13:31:37 +00:00
rillig ae2b6a8fde indent: rename struct fields for buffers
No binary change except for assertion line numbers.
2023-05-13 12:31:02 +00:00
rillig 842f73039b indent: clean up a condition, add comments
No functional change.
2023-05-13 09:40:47 +00:00
rillig ff5c4a3f5c indent: move debugging code to separate file
No functional change.
2023-05-13 09:27:49 +00:00
rillig 38caea9b89 indent: preserve indentation of preprocessor directives 2023-05-13 08:33:39 +00:00
rillig 87b2abcf11 indent: don't try to read from the file '(null)/.indent.pro' 2023-05-13 06:36:33 +00:00
rillig 075e6479a3 indent: rename placeholder symbol for parser stack
No functional change outside debug mode.
2023-05-12 22:38:47 +00:00
rillig 8ba922e8f2 tests/indent: test pushing the placeholder symbol to the parser stack 2023-05-12 22:36:15 +00:00
rillig 1981d21e21 indent: remove code for parsing declarations without semicolon
The statement from the comment that declarations do not need semicolons
is wrong. A possible input that matched this rule is 'void f(void) { int
a }'.
2023-05-12 15:36:02 +00:00
rillig 4c64236705 indent: sync manual page with recent changes 2023-05-12 11:01:11 +00:00
rillig 0cdf93c9f3 indent: remove statistics
The numbers from the statistics were wrong.
2023-05-12 10:53:33 +00:00
rillig a92724c2f9 indent: condense code for handling spaced expressions
No functional change outside debug mode.
2023-05-12 08:40:54 +00:00
rillig 40b8398b3b indent: clean up input buffer handling
No functional change.
2023-05-11 19:14:54 +00:00
rillig d5678748c0 indent: don't touch comments in preprocessing lines
The indentation of multi-line comments was wrong, and the code for
handling them was too complicated.
2023-05-11 19:01:35 +00:00
rillig bacb7fc4b5 tests/indent: add more tests for preprocessing directives 2023-05-11 18:44:14 +00:00
rillig 12ff360db2 indent: remove unused code 2023-05-11 18:26:56 +00:00
rillig d54ae284ce indent: remove broken code for handling blank lines
This fixes several bugs where blank lines were erroneously added or
removed, treating these old bugs for new bugs in different places.
These new bugs are expected to be easier to fix, as the old bugs will
not interfere anymore.
2023-05-11 18:13:55 +00:00
rillig 3ae5a30b3c indent: add debug output for tracking comments and braces 2023-05-11 17:22:56 +00:00
rillig 30e7a62e8c indent: move parser state variables to the parser_state struct
Include the variables in the debug output.
2023-05-11 11:25:47 +00:00
rillig 941baa1b79 indent: eliminate a local variable for else-if handling
No functional change intended.
2023-05-11 10:54:14 +00:00
rillig e623a3bcd0 indent: move force_nl into the parser state
This way, it is included in the debug output.

No functional change.
2023-05-11 10:51:33 +00:00
rillig 44c1f7b6a8 indent: remove unnecessary assignments to last_else
No functional change intended.
2023-05-11 10:39:25 +00:00
rillig 373317666b indent: remove buggy code for swapping tokens
It is not the job of an indenter to swap tokens, even if it's only about
placing comments elsewhere.  The code that swapped the tokens was
complicated, buggy and impossible to understand.

In -br (brace right) mode, indent no longer moves a '{' from the
beginning of a line to the end of the previous line, as that was handled
by the token swapping code as well.  This change is unintended, but it
will be easier to re-add that now that the code is simpler.
2023-05-11 09:28:53 +00:00
rillig 0510ee8e2a lint: fix type name in diagnostic for enum as controlling expression
Previously, the type was reported as 'int' instead of 'enum'.

Continue to only report the type simple for pointer types, as the exact
pointer type is irrelevant to this message.
2023-05-11 08:01:36 +00:00
rillig 7df2cff8f0 lint: make code simpler
No functional change.
2023-05-10 21:46:26 +00:00
sjg 699fcfcdaa Make :mtime operate on each word in variable value.
Reviewed by: rillig
2023-05-10 18:22:33 +00:00
rillig e1e6d6961e make: don't print null filename in stack traces
~~~makefile
!= printf '%s\n' '.include "2.mk"' > 1.mk
!= printf '%s\n' '!= rm 1.mk' '.info message' > 2.mk

.MAKEFLAGS: -dp
.include "1.mk"
.MAKEFLAGS: -d0

all:
~~~
2023-05-10 16:10:02 +00:00
rillig b828d76d72 make: clean up comments 2023-05-10 15:57:16 +00:00
rillig 154809d57d tests/make: clean up comments in tests 2023-05-10 15:53:32 +00:00
rillig de72ac4409 tests/make: clean up tests for .for loops
Most of the tests from forloop.mk were already in directive-for.mk.
2023-05-10 13:03:06 +00:00
rillig ef85afae7d make: improve error message for failed stat in ':mtime' 2023-05-09 21:24:56 +00:00
sjg dbf16036c3 make: :mtime=error throw error on stat(2) failure
Sometimes we want fatal error if stat fails on the
presumed pathname.
2023-05-09 20:53:23 +00:00
mrg b0d9823404 log how much data is valid in debug mode. 2023-05-09 20:42:19 +00:00
sjg ff8067fc6f make: add :mtime to provide mtime of file
The value of the variable is passed to stat(2)
and st_mtime is new value.
An optional arg can be used if stat(2) fails, otherwise
the current time is used.

See varmod-mtime.mk for usage examples.
2023-05-09 20:14:27 +00:00
christos 8499346dc4 Handle OpenSSL-3.x 2023-05-09 20:02:59 +00:00
rillig 2a6095b06a make: skip syntactically wrong .for loops
When a .for loop cannot be interpreted correctly, for example when there
are no iteration variables or the number of words doesn't match the
iteration variables, skip the body of the .for loop instead of
interpreting it once.
2023-05-09 19:43:12 +00:00
rillig f7574bd440 tests/make: clean up tests for ':gmtime' and ':localtime' 2023-05-09 16:31:41 +00:00
rillig 5206f882c3 make: allow ':gmtime' and ':localtime' with dynamic argument
This allows ${%Y:L:gmtime=${mtime}} instead of the indirect
${%Y:L:${:Ugmtime=${mtime}}}.

The direct form also prevents any ':' from the nested expression to be
interpreted as a separator, which doesn't matter for the ':gmtime' and
':localtime' modifiers but will prove useful for other modifiers that
follow the same pattern.
2023-05-09 16:26:59 +00:00
rillig a48523a624 lint: track integer constraints through conditional expressions 2023-05-09 15:51:33 +00:00
rillig 872d56a969 lint: preserve integer constraints on cast 2023-05-09 15:45:06 +00:00
hgutch 836e5e938d Reset SIGCHLD handler to SIG_DFL.
If run with "-c", both child and parent script processes will handle
SIGCHLD resulting in a possible duplicate "Script done" line in the
output.  This fixes bin/54514.
2023-05-09 15:43:39 +00:00
rillig 6b94bf57da tests/make: demonstrate parse bug in :gmtime and :localtime modifiers 2023-05-09 08:26:14 +00:00
rillig 36f24c2b4f make: disallow characters like '$' in variable names in .for loops
Fixes PR 53146.
2023-05-08 10:24:07 +00:00
rillig e997dbfa68 tests/make: add more tests for unusual variable names in .for loops 2023-05-08 09:24:42 +00:00
rillig 34f7aa2d4b make: fix parsing of unusual line continuations in .for loops 2023-05-08 09:01:20 +00:00
sjg 9c8e40c4fa make.1: lose the trailing blank lines 2023-05-07 16:43:50 +00:00
sjg 5a93219217 make: fix description of .PREFIX
For at least 20 years, the setting of .PREFIX in make
has not matched the documentation.
Since the documented behavior does not match reality or
POSIX make, fix the documentation.

In FindDepsRegularPath str_basename is applied to .PREFIX
this is wrong, but I was unable to verify fixing it
was benign in NetBSD build - my NetBSD box (7.2)
was unable to build known-good src with or without any patches.

For now just document the behavior more accurately.
2023-05-07 16:32:47 +00:00
uwe da0afac854 ktrace(1): tweak -c wording for clarity 2023-05-06 10:45:14 +00:00
lukem 55c16b26b6 add timeout for ssl connect
Implement a timeout for SSL connection setup, using -q QUITTIME,
defaulting to 60 seconds.
SSL_connect(3) (unlike connect(2)) doesn't timeout by default.

Adapt ssl error messages destination: if unexpected error
from local API, use warn()/warnx() to stderr;
if expected error from a network operation (e.g., timeouts),
use fprintf to ttyout (which might be stdout).

Consistently use ftp_poll() instead of select();
ssl.c (using select()) was added 7 years after the
previous uses of select() were converted to poll().

Check EAGAIN as well as existing EINTR error from ftp_poll(),
for portability.
2023-05-05 15:46:06 +00:00
kre da39777e71 If chown and chgrp can grow -d flags to suppress performing the
operation when it will have no effect (other than changing the
inode's ctime value) then chmod and chflags should also have -d
flags for the same purpose.   Make it so.
2023-05-05 04:14:02 +00:00
sjg ef3bc782c6 Compat_RunCommand mark bp volatile
gcc 4.8.5 (NetBSD 7.2) gets upset about bp.
2023-05-04 22:31:17 +00:00
rillig 7b4c9b2cdf tests/make: extend test for target-local variables 2023-04-29 10:16:24 +00:00
andvar 6ef0b3e460 one more place for recently fixed typo, s/phisycal/physical/. 2023-04-28 22:23:45 +00:00
rillig 471bb2782b tests/make: add tests for target-local variables
While here, move a test from var-scope-local.mk to parse.mk since that
test is not related to variables.
2023-04-28 13:09:48 +00:00
rillig 0878a3d7ee lint: reword message for missing declaration in header
Suggested by Christos.
2023-04-25 19:00:57 +00:00
gutteridge 15ad6013dd tip.1: s/Mail.1/mail.1/ ("Mail" was removed in 9) 2023-04-25 01:48:37 +00:00