Mercurial > repo
annotate bin/whatis @ 11848:fb7d032ba453 draft
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
author | HackEso <hackeso@esolangs.org> |
---|---|
date | Tue, 16 Jul 2019 15:16:11 +0000 |
parents | |
children | cfb04b3810bf |
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: |
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
7 argfoldv = [] |
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
8 for arg in sys.argv[1:]: |
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
9 argfoldv.append(arg.casefold()) |
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
10 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
|
11 for line in whatisdb: |
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
12 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
|
13 if parts: |
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
14 match = False |
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
15 for argfold in argfoldv: |
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
16 match = match or argfold == parts[1].casefold() |
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
17 if match: |
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
18 sys.stdout.write(line) |
fb7d032ba453
<wob_jonas> fetch bin/whatis https://hack.esolangs.org/get/bin/whatis
HackEso <hackeso@esolangs.org>
parents:
diff
changeset
|
19 |