Mercurial > repo
annotate bin/whatis @ 12092:ceb43c4d37de draft
<fizzie> ` for w in benvenuto bienvenido bienvenue bonvenon tervetuloa v\xc3\xa4lkommen velkomin velkommen welcome welkom wercome willkommen \xd0\xb4\xd0\xbe\xd0\xb1\xd1\x80\xd0\xbe-\xd0\xbf\xd0\xbe\xd0\xb6\xd0\xb0\xd0\xbb\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x82\xd1\x8c; do sed -i -e \'2s|^|my $bin = $ENV{"HACKENV"}."/bin"; |;s|bin/[@?]|$&|g\' /hackenv/bin/$w; done
author | HackEso <hackeso@esolangs.org> |
---|---|
date | Sat, 16 Nov 2019 22:19:36 +0000 |
parents | f79df0b509c8 |
children | 44379732c06b |
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: |
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.") |