Skip to content

Instantly share code, notes, and snippets.

@Alyinghood
Created June 12, 2026 15:08
Show Gist options
  • Select an option

  • Save Alyinghood/f4306ede1dd47f8d5f6b2225450b3443 to your computer and use it in GitHub Desktop.

Select an option

Save Alyinghood/f4306ede1dd47f8d5f6b2225450b3443 to your computer and use it in GitHub Desktop.
import sys
import zipfile
outdic = {}
with open(sys.argv[1]) as in_file:
refs = []
queue = []
def dequeue(refs, queue):
fnrefs = []
if len(refs) > 0:
for ref in refs:
fnref = ref[:x.rfind(":")]
if fnref not in fnrefs:
fnrefs.append(fnref)
fnref_single = ""
if len(fnrefs) == 1:
fnref_single = fnrefs[0]
if fnref_single not in outdic:
outdic[fnref_single] = []
for s in queue:
outdic[fnref_single].append(s)
del refs[:]
del queue[:]
for line in in_file:
ln = line.rstrip()
queue.append(ln)
if ln.startswith("#: "):
for x in ln[3:].split(" "):
refs.append(x)
elif ln == "":
dequeue(refs, queue)
dequeue(refs, queue)
with zipfile.ZipFile(sys.argv[2], "w") as out_zip:
out_zip.writestr("00merge.bat", b"copy /b *.tpo 00merged.tpo\r\n")
out_zip.writestr("00merge.sh", b"cat *.tpo > 00merged.tpo\n")
for fn in outdic:
xfn = fn
if xfn == "":
xfn = "00header"
out_zip.writestr(xfn + ".tpo", "\n".join(outdic[fn]).encode("UTF-8"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment