2020-09-21 20:38:58 +02:00
|
|
|
#!/usr/bin/env python3
|
2020-09-21 15:58:02 +02:00
|
|
|
|
2020-09-22 17:54:04 +02:00
|
|
|
# retro-unu is a tool for extracting code from literate sources. It
|
|
|
|
# will write output to stdout.
|
|
|
|
#
|
|
|
|
# A code block starts with ~~~ on a line by itself and ends with a
|
|
|
|
# second ~~~.
|
|
|
|
#
|
|
|
|
# Copyright (c)2020, Charles Childers
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
#
|
|
|
|
# retro-unu.py filename
|
|
|
|
|
2020-09-21 15:58:02 +02:00
|
|
|
import sys
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-09-22 14:06:40 +02:00
|
|
|
f = sys.argv[1]
|
|
|
|
in_block = False
|
|
|
|
with open(f, "r") as source:
|
|
|
|
for line in source.readlines():
|
|
|
|
if line.rstrip() == "~~~":
|
|
|
|
in_block = not in_block
|
|
|
|
elif in_block:
|
|
|
|
print(line.rstrip())
|