annotate bin/whatis @ 12256:821155c00e34 draft

<fizzie> ` sed -e \'s|wisdom|bin|\' < ../bin/culprits > ../bin/cblprits; chmod a+x ../bin/cblprits
author HackEso <hackeso@esolangs.org>
date Sat, 07 Dec 2019 23:36:22 +0000
parents 44379732c06b
children
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
12022
dff0129e4a40 <b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 11854
diff changeset
2 import sys, os, re
11848
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)
12023
f79df0b509c8 <b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 12022
diff changeset
14 with open(os.environ.get("HACKENV","/hackenv") + "/share/whatis", errors="surrogateescape") as whatisdb:
11848
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:
12231
44379732c06b <b_jonas> fetch /hackenv/bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 12023
diff changeset
16 parts = re.match(r"([^()]+)\(([0-9A-Z_a-z])([0-9A-Z_a-z]*)\)", line)
11848
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):
12231
44379732c06b <b_jonas> fetch /hackenv/bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 12023
diff changeset
20 if (argfold == parts.group(1).casefold() or
44379732c06b <b_jonas> fetch /hackenv/bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 12023
diff changeset
21 argfold == parts.group(1) + "(" + parts.group(2) + parts.group(3) + ")" or
44379732c06b <b_jonas> fetch /hackenv/bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 12023
diff changeset
22 argfold == parts.group(1) + "(" + parts.group(3) + ")") \
44379732c06b <b_jonas> fetch /hackenv/bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 12023
diff changeset
23 :
11853
97b02eed7f57 <b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 11850
diff changeset
24 match = True
97b02eed7f57 <b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 11850
diff changeset
25 foundv[argind] = True
11848
fb7d032ba453 <wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff changeset
26 if match:
11853
97b02eed7f57 <b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 11850
diff changeset
27 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
28 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
29 if not found:
97b02eed7f57 <b_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 11850
diff changeset
30 print(arg + ": nothing appropriate.")
12231
44379732c06b <b_jonas> fetch /hackenv/bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents: 12023
diff changeset
31