Update and fixes to 2001/schweikh

Format fix README.md.

Add INABIAF section to bugs.md and README.md.
This commit is contained in:
Cody Boone Ferguson committed 2023-04-24 05:24:54 -07:00
1 parent b8da99f411
commit a1acee4de4
2 files changed
+50 -31

No files matched your search

+39 -31
View File
@@ -1,12 +1,8 @@
# Best one-liner # Best one-liner
Jens Schweikhardt Jens Schweikhardt
Marconi Communications Germany
Schlartaeckerweg 3 <http://www.schweikhardt.net/>
D-71384 Weinstadt
Germany
http://www.schweikhardt.net/
## To build: ## To build:
@@ -20,6 +16,16 @@ make
./schweikh string string2 ./schweikh string string2
``` ```
### INABIAF - it's not a bug it's a feature! :-)
This program will very likely crash or do something else if you do not give it
two args.
Note also that the glob pattern must match the whole string. See the author's
comments for details and a workaround.
There's also no way to escape meta characters.
## Try: ## Try:
```sh ```sh
@@ -35,17 +41,16 @@ Do you get the pattern here?
## Author's remarks: ## Author's remarks:
This one-liner program is a glob pattern matcher. It understands This one-liner program is a glob pattern matcher. It understands
the glob characters `*' meaning `zero or more characters' and the glob characters `*` meaning 'zero or more characters' and
`?' meaning exactly one character, just like your unix shell. `?` meaning exactly one character, just like your unix shell.
Run it with two args, the string and the glob pattern. The exit Run it with two args, the string and the glob pattern. The exit status is 0
status is 0 (shell true) when the pattern matches, 1 otherwise. (shell true) when the pattern matches, 1 otherwise. The glob pattern must match
The glob pattern must match the whole string, so you may want to the whole string, so you may want to use `*` at the beginning and end of the
use * at the beginning and end of the pattern if you are looking pattern if you are looking for something in the middle.
for something in the middle.
You can use it for your shell scripting needs similar to a silent grep You can use it for your shell scripting needs similar to a silent grep
(and without stdout redirected to /dev/null): (and without stdout redirected to `/dev/null`):
```sh ```sh
if prog "${VARIABLE}" '<glob>'; then if prog "${VARIABLE}" '<glob>'; then
@@ -55,32 +60,35 @@ else
fi fi
``` ```
Bugs: there is no way to escape the meta characters. Dammit Jim, I'm a ### Bugs
There is no way to escape the meta characters. Dammit Jim, I'm a
one-liner, not a regexp lib. one-liner, not a regexp lib.
All obfuscation is obviously in the recursive m() function, an 86 All obfuscation is obviously in the recursive `m()` function, an 86
character glob pattern evaluator, returning nonzero for a match: character glob pattern evaluator, returning nonzero for a match:
* just a single complex return expression.
* nested ternary operator ?: to save on if/else verbosity. * Just a single complex return expression.
* short circuiting && and || to save even more on if/else verbosity. * Nested ternary operator `?:` to save on if/else verbosity.
* Subtraction instead of an equality operator in "*t - 42". * Short circuiting `&&` and `||` to save even more on if/else verbosity.
* ASCII codes for '*' and '?'. * Subtraction instead of an equality operator in `*t - 42`.
* careful use of blanks even though this year's rules have extended * ASCII codes for `*` and `?`.
* Careful use of blanks even though this year's rules have extended
that resource limit. that resource limit.
* the source is a complete preprocessed C program. Because it communicates * The source is a complete preprocessed C program. Because it communicates
with the world out there by means of argv and the exit status, there with the world out there by means of argv and the exit status, there
is no need for stdio bloat. An asm guru could surely squeeze this is no need for stdio bloat. An asm guru could surely squeeze this
program in less than a screenful. program in less than a screenful.
* indent(1) is probably not too helpful. * `indent(1)` is probably not too helpful.
The recursion wonderfully and magically takes care of iteration and The recursion wonderfully and magically takes care of iteration and
backtracking. I could tell you how it works but then I would have to backtracking. I could tell you how it works but then I would have to
kill^Wrequest an NDA from you :-) Run it under a debugger with several <strike>kill</strike> request a NDA from you :-) Run it under a debugger with several
inputs, it will be quite helpful and instructive. Handling of '?' is inputs, it will be quite helpful and instructive. Handling of `?` is
straightforward; for '*' start out with '*foo' and 'foo*' against 'foo'. straightforward; for `*` start out with `*foo` and `foo*` against `foo`.
How does it deal with sequences of adjacent `*'? How could this be How does it deal with sequences of adjacent `*`? How could this be
improved? If all else fails, recode the ?: operators with if/else and improved? If all else fails, recode the `?:` operators with if/else and
try again. For extra credit implement character classes like [a-z]. try again. For extra credit implement character classes like `[a-z]`.
## Copyright and CC BY-SA 4.0 License: ## Copyright and CC BY-SA 4.0 License:
+11
View File
@@ -1297,6 +1297,17 @@ points.
Although it is independent of endianness both systems need the same character Although it is independent of endianness both systems need the same character
set. In other words both have to be ASCII or EBCDIC - not one of each. set. In other words both have to be ASCII or EBCDIC - not one of each.
## [2001/schweikh](2001/schweikh/schweikh.c) ([README.md](2001/schweikh/README.md))
## STATUS: INABIAF - please **DO NOT** fix
This program will very likely crash or do something else if you do not give it
two args.
Note also that the glob pattern must match the whole string. See the author's
comments for details and a workaround.
There's also no way to escape meta characters.
# 2002 # 2002
There was no IOCCC in 2002. There was no IOCCC in 2002.