[comp.binaries.apple2] merlin.perl; perl script to translate merlin source files...

cwilson@NISC.SRI.COM (Chan Wilson) (09/07/90)

Well, until I break down and get a printer at home, I continue
to transfer source files to the unix box at work and print them out.
Little perl script below might come in useful to anyone using merlin
who does the same stunt I do.  Rather nice to have fast laser output
of your 50 page source file....

Enjoy!

--Chan

----------<snip>--------------------<snip>--------------------<snip>----------
#!/usr/local/bin/perl

# merlin.perl:  translate a merlin source file into something a bit
# more legible for output.
#
# 1.0 - written sometime in fall of '89, hackish approach. 
# 	cwilson@nisc.sri.com
# 1.1 - re-wrote using enhanced knowledge of perl, added comments.
#	first release to internet world.  90/09/07
#	cwilson@nisc.sri.com
#
# There's at least one known bug, fairly obscure, occuring if
# you have a line like so:
# asc "Some Text" ;some text
# which will probably get transformed something like this...
#         asc     "Some Text" ;some text
# where the ;comment doesn't get spaced out correctly.  I don't
# tend to write code like this, if I run into a bunch of it, I'll
# figure out how to fix it...
#
# Usage:  merlin.perl [filename] 
# 	Reads stdin if filename not specified.  Writes to stdout.
#
#
# converts this:
#
# use macros/promacs
# use macros/macros
# use 4/dos.8.macs
# use 5/general.equ
#
#*-------------------------------
#* video externals
#
#init ext
#home ext
#homeCursor ext
#==================================================
#			     into this:
#==================================================
#                use        macros/promacs 
#                use        macros/macros  
#                use        4/dos.8.macs   
#                use        5/general.equ  
#                                          
#*-------------------------------
#* video externals
#                                          
#init            ext                       
#home            ext                       
#homeCursor      ext                       
#
#==================================================
# let's begin:
#

# Tab stops.  Rather generous, but then again, I tend to get carried
# away with labels and comments.  Adjust to your own preference.

$TAB1=16;
$TAB2=8;
$TAB3=15;

# loop over file/stdin.

while (<>) {
	chop $_;		# nuke newline
	@x = (split(/\ /,$_,4));

# handle ';' lines
	if (/^;/o) {print ' ' x ($TAB1+$TAB2+$TAB3),$_,"\n"; next;}

# handle '*' lines
	if (/^\*/o) { print $_,"\n"; next;}

# check for 'lda #" "' condition, which will split into
# 'lda #"       "' unless we fix it.
	if (@x[3]) {
	    if (@x[3]=~/^\"/) {@x[2]=@x[2]." ".@x[3];@x[3]='';}}

# check for 'asc "Text"
	if (@x[2]) {
	    if (@x[2]=~/^\"/) {@x[2]=@x[2]." ".@x[3];@x[3]='';}}

# print out line if no label:
	if (!length(@x[0])) {print ' ' x $TAB1,@x[1],' ' x 
				 ($TAB2+(3-length(@x[1]))),
				 @x[2],' ' x ($TAB3-length(@x[2])),@x[3],
				 "\n"; next;}

# we've got a label, print here instead:
	print @x[0],' ' x ($TAB1-length(@x[0])),@x[1],' ' x 
	    ($TAB2+(3-length(@x[1]))),
	    @x[2],' ' x ($TAB3-length(@x[2])),@x[3],"\n";

# around and around we go, where we stop, only EOF will tell...
    }


----------<snip>--------------------<snip>--------------------<snip>----------
			   ................
    Chan Wilson -- cwilson@nisc.sri.com <!> I don't speak for SRI.
Janitor/Architect of comp.binaries.apple2 archive on wuarchive.wustl.edu
			      "a2fx it!"
			   ................