summaryrefslogtreecommitdiff
path: root/usr.bin/indent
Commit message (Collapse)AuthorAgeFilesLines
* - address missing whitespace for indentJason Helfman2019-08-291-3/+3
| | | | | | | | | | PR: 239727 Submitted by: gbergling@gmail.com Reviewed by: 0mp@ MFC after: 1 week Notes: svn path=/head/; revision=351614
* capsicum: use a new capsicum helpers in toolsMariusz Zaborski2018-11-041-2/+2
| | | | | | | Use caph_{rights,ioctls,fcntls}_limit to simplify the code. Notes: svn path=/head/; revision=340138
* indent(1): bug fix after r336333Piotr Pawel Stefaniak2018-08-153-1/+4
| | | | | | | | | | The bug was that isalnum() is not exactly equivalent to previous code which also allowed characters "$" and "_", so check for those explicitly. Reported by: tuexen@ Notes: svn path=/head/; revision=337862
* indent(1): revert r334640 and r334632Piotr Pawel Stefaniak2018-08-112-6/+6
| | | | | | | | | While STACKSIZE macro is indeed problematic on some systems, the commits were wrong to shrink il[] and cstk[], because they need to be of the same size as p_stack[] as they're accessed with the same index ps.tos. Notes: svn path=/head/; revision=337651
* indent(1): rewrite the integer/floating constant scanning part of lexi.cPiotr Pawel Stefaniak2018-07-165-103/+87
| | | | | | | | | | | | | | | | | Remove procedural code that did the scanning, which was faulty and didn't support complex constants such as 0x1p-61. Replace it with a finite state machine expressed as a transition table. The table was rewritten by hand from lx's output, given parts of grammar expressed as regular expressions. lx is Katherine Flavel's lexer generator, currently available at https://github.com/katef/libfsm and the parts of grammar were taken from http://quut.com/c/ANSI-C-grammar-l-2011.html and extended to support binary integer constants which are a popular GCC extension. Reported by: bde Notes: svn path=/head/; revision=336333
* indent(1): move case_indent from parser state to the options structPiotr Pawel Stefaniak2018-07-153-7/+7
| | | | | | | This was missed in r334927. Notes: svn path=/head/; revision=336318
* Convert `cap_enter() < 0 && errno != ENOSYS` to `caph_enter() < 0`.Mariusz Zaborski2018-06-191-1/+2
| | | | | | | No functional change intended. Notes: svn path=/head/; revision=335395
* indent(1): rename -nsac/-sac ("space after cast") to -ncs/-csPiotr Pawel Stefaniak2018-06-119-17/+17
| | | | | | | | | Also update tests and the manpage. GNU indent had the option earlier as -cs, let's not diverge unnecessarily. Notes: svn path=/head/; revision=334944
* indent(1): group global option variables into an options structurePiotr Pawel Stefaniak2018-06-107-243/+241
| | | | | | | | | It's clearer now when a variable represents a toggable command line option. Many options were stored in the parser's state structure, so fix also that. Notes: svn path=/head/; revision=334927
* indent(1): fix buildworld after r334632Piotr Pawel Stefaniak2018-06-041-1/+1
| | | | | | | | | | | Fix error: comparison of integers of different signs: 'int' and 'unsigned long' by casting nitems() to int. Reported by: mjg Notes: svn path=/head/; revision=334640
* indent(1): add --version optionPiotr Pawel Stefaniak2018-06-042-1/+14
| | | | | | | | | 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. Notes: svn path=/head/; revision=334636
* indent(1): remove the STACKSIZE macro and all of its usePiotr Pawel Stefaniak2018-06-042-6/+6
| | | | | | | It conflicts with a system-provided macro of the same name on another OS. Notes: svn path=/head/; revision=334632
* indent(1): remove static const char copyright[]Piotr Pawel Stefaniak2018-06-041-8/+0
| | | | | | | | It repeats what is already said in the heading comment and it's optimized out so serves no purpose. Notes: svn path=/head/; revision=334630
* indent(1): replace BSD bcopy() with C memmove()Piotr Pawel Stefaniak2018-06-041-1/+1
| | | | Notes: svn path=/head/; revision=334628
* indent(1): new option -lplPiotr Pawel Stefaniak2018-06-035-1/+24
| | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=334590
* indent(1): revert introduction of -lplPiotr Pawel Stefaniak2018-06-035-24/+1
| | | | | | | That was committed with the wrong message. Will be re-added. Notes: svn path=/head/; revision=334589
* indent(1): new option -lpl (always line up to parenthesis)Piotr Pawel Stefaniak2018-06-035-1/+24
| | | | | | | | | | | 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 Notes: svn path=/head/; revision=334588
* indent(1): manual page corretionsPiotr Pawel Stefaniak2018-06-031-11/+12
| | | | | | | | | | Add missing options, synchronize syntax summary with the actual option list, and other fixes. Submitted by: Tom Lane Notes: svn path=/head/; revision=334587
* indent(1): if an identifier can be either a typedef name or as a structPiotr Pawel Stefaniak2018-06-034-1/+11
| | | | | | | member, it is taken as the latter Notes: svn path=/head/; revision=334583
* indent(1): if the token is a "[" then neither of the blocks is relevantPiotr Pawel Stefaniak2018-06-031-2/+4
| | | | Notes: svn path=/head/; revision=334581
* indent(1): don't add a space after a labelPiotr Pawel Stefaniak2018-06-031-1/+0
| | | | | | | It's not needed and it fools pr_comment(). Notes: svn path=/head/; revision=334580
* indent(1): ignore null characters from inputPiotr Pawel Stefaniak2018-06-031-1/+2
| | | | Notes: svn path=/head/; revision=334579
* indent(1): don't overflow di_stack[]Piotr Pawel Stefaniak2018-06-031-1/+6
| | | | Notes: svn path=/head/; revision=334578
* indent(1): improve CHECK_SIZE_ macrosPiotr Pawel Stefaniak2018-06-034-96/+111
| | | | | | | | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=334576
* indent(1): remove troff output supportPiotr Pawel Stefaniak2018-06-038-363/+63
| | | | | | | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=334574
* indent(1): avoid resetting last_bl to a bogus value when reallocatingPiotr Pawel Stefaniak2018-06-031-2/+7
| | | | | | | underlying buffer Notes: svn path=/head/; revision=334571
* indent(1): the check for buffer overflow has to be done before copyPiotr Pawel Stefaniak2018-06-031-2/+2
| | | | Notes: svn path=/head/; revision=334570
* indent(1): use errx() instead of abort()Piotr Pawel Stefaniak2018-06-031-2/+2
| | | | Notes: svn path=/head/; revision=334569
* indent(1): limit character classification functions' input to unsigned charPiotr Pawel Stefaniak2018-06-034-15/+17
| | | | Notes: svn path=/head/; revision=334568
* indent(1): recognize more type namesPiotr Pawel Stefaniak2018-06-031-0/+10
| | | | | | | Most are from C99. Notes: svn path=/head/; revision=334567
* indent(1): don't format function declarations as variablesPiotr Pawel Stefaniak2018-06-035-27/+119
| | | | Notes: svn path=/head/; revision=334566
* indent(1): remove is_procname.Piotr Pawel Stefaniak2018-06-031-6/+4
| | | | | | | | | 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(). Notes: svn path=/head/; revision=334565
* indent(1): disjoint parser state from lexi()Piotr Pawel Stefaniak2018-06-035-30/+35
| | | | | | | | The function is sometimes used as a look-ahead, so ideally it should bear no information about parser state. Notes: svn path=/head/; revision=334564
* indent(1): improve handling of boxed comments indentationPiotr Pawel Stefaniak2018-06-035-8/+67
| | | | | | | | | | | | | 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). Notes: svn path=/head/; revision=334563
* indent(1): improve predictability of lexi()Piotr Pawel Stefaniak2018-06-033-51/+93
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=334560
* indent(1): improve handling of comments and newlines between "if (...)" orPiotr Pawel Stefaniak2018-06-033-126/+175
| | | | | | | | | | | | | | | | | | "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. Notes: svn path=/head/; revision=334559
* indent(1): remove undocumented and rather useless option (-ps)Piotr Pawel Stefaniak2018-06-033-8/+3
| | | | | | | | It's used to treat the "->" access operator as a binary operator and put space characters around it. Notes: svn path=/head/; revision=334556
* indent(1): improve an error messagePiotr Pawel Stefaniak2018-06-011-1/+1
| | | | | | | | When producing a "[...] requires a parameter" error, provide the recognized name of the option instead of argument provided. Notes: svn path=/head/; revision=334495
* indent(1): restore working -pcsPiotr Pawel Stefaniak2018-06-016-1/+23
| | | | | | | | | | | | | | My previous indent(1) commit accidentally broke the -pcs option (which adds space between function name and opening parenthesis in function calls) by copying all but one of a few conditions in an if clause. Reinstate the condition. Add a regression test to lower the chances of breaking it again. Correct a comment with description of what the option does. Notes: svn path=/head/; revision=334493
* indent(1): don't add unneeded space to function pointer declarationsPiotr Pawel Stefaniak2018-06-012-10/+9
| | | | | | | | | If the current token is an opening parenthesis, it's either a function call (or sizeof or offsetof) or a declaration. The former doesn't need a space before the parenthesis. Notes: svn path=/head/; revision=334480
* indent(1): don't indent typedef declarations as object declarationsPiotr Pawel Stefaniak2018-06-015-2/+12
| | | | Notes: svn path=/head/; revision=334478
* indent(1): consider tab characters when forcing a newline after a commaPiotr Pawel Stefaniak2018-06-013-1/+6
| | | | Notes: svn path=/head/; revision=334477
* indent(1): identifiers inside parentheses are not declarationsPiotr Pawel Stefaniak2018-06-015-6/+59
| | | | | | | | | Also make lparen position calculation consider tab stops. This improves function pointer typedef formatting. Notes: svn path=/head/; revision=334475
* various: general adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-271-0/+2
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. No functional change intended. Notes: svn path=/head/; revision=326276
* spdx: initial adoption of licensing ID tags.Pedro F. Giffuni2017-11-188-0/+16
| | | | | | | | | | | | | | | | | | | | The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Initially, only tag files that use BSD 4-Clause "Original" license. RelNotes: yes Differential Revision: https://reviews.freebsd.org/D13133 Notes: svn path=/head/; revision=325966
* DIRDEPS_BUILD: Update dependencies.Bryan Drewery2017-10-311-1/+0
| | | | | | | Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=325188
* DIRDEPS_BUILD: Connect new directories.Bryan Drewery2017-10-311-0/+11
| | | | | | | Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=325187
* Add supporting changes for `Add limited sandbox capability to "make check"`Enji Cooper2017-08-141-0/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Non-tests/... changes: - Add HAS_TESTS= to Makefiles with libraries and programs to enable iteration and propagate the appropriate environment down to *.test.mk. tests/... changes: - Add appropriate support Makefile.inc's to set HAS_TESTS in a minimal manner, since tests/... is a special subdirectory tree compared to the others. MFC after: 2 months MFC with: r322511 Reviewed by: arch (silence), testing (silence) Differential Revision: D12014 Notes: svn path=/head/; revision=322515
| * Add HAS_TESTS to all Makefiles that are currently using theEnji Cooper2017-08-021-0/+1
| | | | | | | | | | | | | | | | | | `SUBDIR.${MK_TESTS}+= tests` idiom. This is a follow up to r321912. Notes: svn path=/projects/make-check-sandbox/; revision=321914
* | Respect SIMPLE_BACKUP_SUFFIX environment variable in indent(1)Kyle Evans2017-08-072-4/+13
|/ | | | | | | | | | | | | Instead of using a non-configurable ".BAK" suffix, respect the SIMPLE_BACKUP_SUFFIX environment variable also used by patch(1). This simplifies cleanup operations in some patch/indent workflows. Reviewed by: cem (earlier version), emaste, pstef Approved by: emaste (mentor) Differential Revision: https://reviews.freebsd.org/D10921 Notes: svn path=/head/; revision=322177