annotate bin/whatis @ 11854:cc933fc31298 draft

<b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
author HackEso <hackeso@esolangs.org>
date Tue, 16 Jul 2019 16:54:42 +0000
parents 97b02eed7f57
children dff0129e4a40
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11848
fb7d032ba453 <wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff changeset
1 #!/usr/bin/python3
fb7d032ba453 <wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff changeset
2 import sys, re
fb7d032ba453 <wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff changeset
3 if len(sys.argv) <= 1:
fb7d032ba453 <wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff changeset
4 print("whatis what?")
fb7d032ba453 <wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff changeset
5 sys.exit(1)
fb7d032ba453 <wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff changeset
6 else:
11853
97b02eed7f57 <b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 11850
diff changeset
7 argorg = []
11848
fb7d032ba453 <wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff changeset
8 argfoldv = []
11853
97b02eed7f57 <b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 11850
diff changeset
9 foundv = []
11848
fb7d032ba453 <wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff changeset
10 for arg in sys.argv[1:]:
11853
97b02eed7f57 <b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 11850
diff changeset
11 argorg.append(arg)
11848
fb7d032ba453 <wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff changeset
12 argfoldv.append(arg.casefold())
11853
97b02eed7f57 <b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 11850
diff changeset
13 foundv.append(False)
11848
fb7d032ba453 <wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff changeset
14 with open("/hackenv/share/whatis", errors="surrogateescape") as whatisdb:
fb7d032ba453 <wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff changeset
15 for line in whatisdb:
fb7d032ba453 <wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff changeset
16 parts = re.match(r"([^()]+)\(([0-9A-Z_a-z]+)\)", line)
fb7d032ba453 <wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff changeset
17 if parts:
fb7d032ba453 <wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff changeset
18 match = False
11853
97b02eed7f57 <b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 11850
diff changeset
19 for argind, argfold in enumerate(argfoldv):
97b02eed7f57 <b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 11850
diff changeset
20 if argfold == parts.group(1).casefold():
97b02eed7f57 <b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 11850
diff changeset
21 match = True
97b02eed7f57 <b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 11850
diff changeset
22 foundv[argind] = True
11848
fb7d032ba453 <wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff changeset
23 if match:
11853
97b02eed7f57 <b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 11850
diff changeset
24 print(line, end="")
11854
cc933fc31298 <b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 11853
diff changeset
25 for arg, found in zip(argorg, foundv):
11853
97b02eed7f57 <b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 11850
diff changeset
26 if not found:
97b02eed7f57 <b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 11850
diff changeset
27 print(arg + ": nothing appropriate.")