Commit Graph

56 Commits

Author SHA1 Message Date
Kurtis Rader
8440308470 two more /tmp references that aren't necessary
Eliminate two more references to /tmp as part of removing our dependency
on /tmp being a valid directory.
2017-04-08 21:47:05 -07:00
Kurtis Rader
03571b82be cleanup env code and contains()
Switch from null terminated arrays to `wcstring_list_t` for lists of
special env var names. Rename `list_contains_string` to `contains` and
modify the latter interface to not rely on a `#define`.

Rename `list_contains_string()` to `contains()` and eliminate the
current variadic implementation. Update all callers of the removed
version to use the string list version.
2017-04-05 17:09:12 -07:00
Kurtis Rader
509ee64fc9 implement our own assert() function
I recently upgraded the software on my macOS server and was dismayed to
see that cppcheck reported a huge number of format string errors due to
mismatches between the format string and its arguments from calls to
`assert()`. It turns out they are due to the macOS header using `%lu`
for the line number which is obviously wrong since it is using the C
preprocessor `__LINE__` symbol which evaluates to a signed int.

I also noticed that the macOS implementation writes to stdout, rather
than stderr. It also uses `printf()` which can be a problem on some
platforms if the stream is already in wide mode which is the normal case
for fish.

So implement our own `assert()` implementation. This also eliminates
double-negative warnings that we get from some of our calls to
`assert()` on some platforms by oclint.

Also reimplement the `DIE()` macro in terms of our internal
implementation.

Rewrite `assert(0 && msg)` statements to `DIE(msg)` for clarity and to
eliminate oclint warnings about constant expressions.

Fixes #3276, albeit not in the fashion I originally envisioned.
2017-02-14 18:48:27 -08:00
Kurtis Rader
69731f6642 more IWYU fixes
I'm starting to wonder if IWYU is worth the effort. Nonetheless, this
makes it lint clean on macOS and reduces the number of warnings on
FreeBSD and Linux.
2017-02-12 20:36:37 -08:00
Kurtis Rader
9443a415bf time for another make style-all 2016-12-03 20:12:53 -08:00
Kurtis Rader
f6047f02d6 lint: constant conditional operator 2016-11-01 21:19:34 -07:00
Kurtis Rader
71e69b6d75 lint: empty if statement 2016-11-01 20:42:02 -07:00
Kurtis Rader
e73226d7e8 lint: unused parameter 2016-11-01 19:12:39 -07:00
Kurtis Rader
ca5a4ec1d5 lint: Use early exit/continue 2016-10-31 13:29:10 -07:00
Kurtis Rader
f382fa8e8a lint: multiple unary operator 2016-10-27 21:21:54 -07:00
Kurtis Rader
21521b2953 lint: too few branches in switch statement
Someone was way too enamored of the `switch` statement. Using it in
places where a simple `if...else if...else` was clearer and shorter.
2016-10-22 21:01:27 -07:00
Kurtis Rader
42458ff7ab lint: "collapsible if statements" warnings 2016-10-22 19:09:40 -07:00
Kurtis Rader
6e6b294a3f lint: deal with "double negative" warnings 2016-10-20 21:14:40 -07:00
Kurtis Rader
d389b22afc make style-all C++ style cleanup
It's time once again to run `make style-all` to fix some style bogosities
that have crept in.
2016-10-04 20:06:14 -07:00
ridiculousfish
c0c2e1d4fa Don't modify valid directory segments in fuzzy completions
When performing fuzzy completion, if a directory segment is
valid, then don't consider it for a fuzzy match even if
the literal match produces no results.

Fixes #3211
2016-10-01 17:58:15 -07:00
Kurtis Rader
10ae6d8b26 fix some style problems that have crept in 2016-07-21 19:36:32 -07:00
ridiculousfish
8b06d2ad66 Untangle some fuzzy completion logic
Prior to this fix, when performing completions, we would prepend
the wildcard to the resulting files. When doing fuzzy completions,
we would take some wildcard segment, attempt to locate it in the
final completion, and then replace it with our fuzzy-matched directory.

With this fix, we pass along the "resolved so far" path, and prepend
that instead of doing "surgery" on the completion. This simplifies the
logic.

Fixes #3185
2016-07-09 15:27:10 -07:00
Aaron Gyes
fa78a7101c Make IWYU output in lint.cpp less messy
And re-run IWYU, adjust #includes.
2016-06-23 17:26:08 -07:00
Kurtis Rader
9ad3488b5d fix some style bogosities that crept in 2016-05-27 14:44:30 -07:00
David Adam
9225b16d12 add (or restore) config.h to all files
The autoconf-generated config.h contains a number of directives which
may alter the behaviour of system headers on certain platforms. Always
include it in every C++ file as the first include.

Closes #2993.
2016-05-18 22:30:21 +00:00
Kurtis Rader
79f342b954 lint cleanup: eliminate "redundant" errors
This removes some pointless parentheses but the primary focus is removing
redundancies like unnecessary "else" clauses.
2016-05-04 15:32:04 -07:00
Kurtis Rader
fc44cffac5 restyle switch blocks to match project style
I missed restyling a few "switch" blocks to make them consistent with the rest
of the code base. This fixes that oversight. This should be the final step in
restyling the C++ code to have a consistent style. This also includes a few
trivial cleanups elsewhere.

I also missed restyling the "complete" module when working my way from a to z
so this final change includes restyling that module.

Total lint errors decreased 36%. Cppcheck errors went from 47 to 24. Oclint P2
errors went from 819 to 778. Oclint P3 errors went from 3252 to 1842.

Resolves #2902.
2016-05-03 17:14:56 -07:00
Kurtis Rader
5c8763be0e restyle remaining modules to match project style
For this change I decided to bundle the remaining modules that need to be
resytyled because only two were large enough to warrant doing on their own.

Reduces lint errors from 225 to 162 (-28%). Line count from 3073 to 2465 (-20%).

Another step in resolving issue #2902.
2016-05-03 16:09:45 -07:00
Kurtis Rader
1f06e5f0b9 add better support for IWYU and fix things
Remove the "make iwyu" build target. Move the functionality into the
recently introduced lint.fish script. Fix a lot, but not all, of the
include-what-you-use errors. Specifically, it fixes all of the IWYU errors
on my OS X server but only removes some of them on my Ubuntu 14.04 server.

Fixes #2957
2016-04-26 15:02:22 -07:00
ridiculousfish
e395a0eb69 Migrate PATH-completion logic from complete.cpp to expand.cpp
Prior to this fix, when completing a command that doesn't have a /, we
would prepend each component of PATH and then expand the whole thing. So
any special characters in the PATH would be interpreted when performing
tab completion.

With this fix, we pull the PATH resolution out of complete.cpp and
migrate it to expand.cpp. This unifies nicely with the CDPATH resolution
already in that file. This requires introducing a new expand flag
EXPAND_SPECIAL_FOR_COMMAND, which is analogous to EXPAND_SPECIAL_CD
(which is renamed to EXPAND_SPECIAL_FOR_CD). This flag tells expand to
resolve paths against PATH instead of the working directory.

Fixes #952
2016-04-07 20:15:32 -07:00
ridiculousfish
947f659f96 Miscellaneous cleanup and dead code removal
Noticed by cppcheck
2016-02-19 15:45:31 -08:00
ridiculousfish
718d9baead Implement the cd "unique hierarchy" autosuggestion in expand.cpp 2016-02-18 17:00:26 -08:00
ridiculousfish
1907323afc Additional work on unifying cd autosuggestions with complete 2016-02-18 17:00:26 -08:00
ridiculousfish
c5ed4e5cdf Pass a struct stat by const reference instead of by value 2016-01-03 12:12:42 -08:00
ridiculousfish
aeaacedf75 Don't do intermediate fuzzy directory matching with $PATH
When expanding an executable with $PATH, don't attempt to
interpret the directories in PATH as fuzzy matching. Fixes #2413.
2015-10-03 15:44:57 -07:00
ridiculousfish
71e38dec11 Fix a typo 2015-09-27 17:33:00 -07:00
ridiculousfish
11376ae25b Fix for recursive wildcard expansion ignoring directories
When ascending out of a directory, we need to clear the directory
from the visited set. Fixes #2414.
2015-09-27 17:19:52 -07:00
ridiculousfish
dd245f62f0 Trailing slashes in wildcards need to match directories
Fixes the wrong sense in a waccess test.
2015-09-27 17:19:52 -07:00
ridiculousfish
3a3a9f5cc1 Add wreaddir_for_dirs function
Eliminates some stat calls, speeding up wildcard expansion
2015-08-08 14:52:04 -07:00
ridiculousfish
6347988e0a Eliminate wildcard_expand function 2015-08-08 13:55:51 -07:00
ridiculousfish
b92acd3cf2 Initial implementation of intermediate fuzzy completion
e.g. /u/l/b<tab> may be expanded to /usr/local/bin
2015-08-08 13:55:51 -07:00
ridiculousfish
fd96bafbc8 Experiment to rework wildcard matching
Preparation for zsh-style intermediate component
tab completion
2015-08-08 13:55:51 -07:00
ridiculousfish
b7e16cb0dd Tweak try_add_completion_result logic
Preparation for zsh-style intermediate fuzzy matching
2015-08-08 13:55:51 -07:00
ridiculousfish
459df23931 Migrate the prepend_token_prefix logic into the expander 2015-08-08 13:55:50 -07:00
ridiculousfish
e7b22a7ed2 Factor the expander class a bit more 2015-08-08 13:55:50 -07:00
ridiculousfish
bcbe91461e Move the "wildcard_complete" test into wildcard_test_flags_then_complete
Simplifies code yet further
2015-08-08 13:55:50 -07:00
ridiculousfish
b68410d619 Eliminate the wildcard_expand_internal function 2015-08-08 13:55:50 -07:00
ridiculousfish
602e9cebd9 rename FOR_COMPLETIONS to EXPAND_FOR_COMPLETIONS
This is yet clearer
2015-08-08 13:55:50 -07:00
ridiculousfish
d2049edcab Slight refactoring of expander's return code implementation 2015-08-08 13:55:49 -07:00
ridiculousfish
83322f63c6 Rewrite wildcard_complete_internal to be easier to follow 2015-08-08 13:55:49 -07:00
ridiculousfish
f0a2f24701 Remove some dead code 2015-08-08 13:55:49 -07:00
ridiculousfish
97f1a8fe91 Factor the completion prefix behavior into its own function
In a few places, we need to add a prefix to completions that
replace the token. This change factors that logic into its
own function prepend_token_prefix.
2015-08-08 13:55:49 -07:00
ridiculousfish
0ac9f159d6 Eliminate recurse_to_subdirectories function 2015-08-08 13:55:49 -07:00
ridiculousfish
a3f8e27bf8 rename ACCEPT_INCOMPLETE to FOR_COMPLETIONS, which is clearer 2015-08-08 13:55:49 -07:00
ridiculousfish
b55c13f275 Turn on the new wildcard expander 2015-08-08 13:55:48 -07:00