Hello all,
I was investigating menus.bas and came up with this script which lists all the
unique strings,in order, in BAS/BI files (whichever files you specify).
I thought that could have applications for developing, so I'm posting it here.
(currently requires grep, but that could easily be changed.)

It produces output like this:

scrcommands.bi :"noop"
scrcommands.bi :"wait"
scrcommands.bi :"waitforall"
scrcommands.bi :"waitforhero"
scrcommands.bi :"waitfornpc"
scrcommands.bi :"suspendnpcs"
scrcommands.bi :"suspendplayer"
scrcommands.bi :"resumenpcs"
scrcommands.bi :"resumeplayer"
scrcommands.bi :"waitforkey"
scrcommands.bi :"walkhero"
scrcommands.bi :"showtextbox"
scrcommands.bi :"checktag"
scrcommands.bi :"settag"
scrcommands.bi :","

customsubs.bas :"THE INN COSTS (# gold)"
customsubs.bas :"THE INN COSTS"
customsubs.bas :"You have (# gold)"
customsubs.bas :"You have"
customsubs.bas :"CANNOT RUN!"

menus.bas      :"Pass through walls"
menus.bas      :"Pass through NPCs"
menus.bas      :"Enable NPC activation"
menus.bas      :"Enable door use"
menus.bas      :"Do not hide leader"
menus.bas      :"Do not hide party"
menus.bas      :"Dismount one space ahead"
menus.bas      :"Pass walls while dismounting"
menus.bas      :"Disable flying shadow"
menus.bas      :"default"
menus.bas      :"A"
menus.bas      :"B"
menus.bas      :"A and B"
menus.bas      :"A or B"
menus.bas      :"not A"
menus.bas      :"not B"
menus.bas      :"neither A nor B"


IMO such output could eg. be used to automatically produce
descriptions of lists of bitsets for wiki fileformat docs.

[attached]
#!/usr/bin/env python
"""
Extract strings from Freebasic BAS or BI files, omitting duplicates
(but preserving order.)

 Intended for application to OHRRPGCE sourcecode.

"""

from subprocess import Popen, PIPE
import sys
command = ['grep','-oEe','"[^"]+"'] + sys.argv[1:]

def extract (args):
    command = ['grep','-oTHEe','"[^"]+"'] + args
    f = Popen (command, stdout = PIPE)
    lines = f.stdout.readlines()
    del f
    for l in list(lines):
        if lines.count(l) > 1:
            lines.pop (lines.index (l,lines.index(l)+1))
    for l in list(lines):
        print l[:-1]

if __name__ == "__main__":
    extract (sys.argv[1:])
_______________________________________________
Ohrrpgce mailing list
ohrrpgce@lists.motherhamster.org
http://lists.motherhamster.org/listinfo.cgi/ohrrpgce-motherhamster.org

Reply via email to