Postprocessor for the "ST" program

By Peter L. Berghold ·

TML message #719From bundle 65

As I promised, here is the awk script set that I wrote to postprocess the
ASCII output from the program "ST" into [et]roff compatible input specification.
This will allow you to edit the information as you see fit and as well, add
things to the information to make it more complete.   The star map is
rendered in PIC format as well.   It probably could be greatly improved upon
and I invite the programmers out there to hack away at it and come up with
whatever improvements you can think of.

The working script itself was written for the NAWK version of awk because of
the ability to break the script up into modular units easier.  In fact it
almost is like programming in C!

Enjoy!


Pete


#---------------------------------- cut here ----------------------------------
# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by 45252-Peter L. Berghold [email removed] on Thu Nov 16 13:02:45 1989
#
# This archive contains:
#	README		do_map		do_map.awk
#
# Error checking via wc(1) will be performed.
# Error checking via sum(1) will be performed.

LANG=""; export LANG
PATH=/bin:/usr/bin:$PATH; export PATH

if sum -r </dev/null >/dev/null 2>&1
then
	sumopt='-r'
else
	sumopt=''
fi

echo x - README
sed 's/^@//' >README <<'@EOF'
@@(#)
@@(#)README	1.1




What is this program and why was it written?   When I recieved a copy of the
program "st" I was suitably impressed with it.  However, being left with the
choice of outputs of either text or postscript left a little to be desired.
I wanted to be able to add comments and such to the resultant output and then
print all this information via eroff to my laser printer.  I even wanted the
hex map for a subsector printed out as well.

I began hacking at an awk script to do this for me, and the result after many
hours of tweaking ended up being the product you see here.  To use the script
set you execute:

	do_map [seed number] > file

	-or-

	do_map [seed_number] | pic  .... etc ....


Some of my own complaints about this script:

	1) Stars are not "shaded" in.   In the postscript output facility of
	"st" the stars are filled in.   I liked that.  Unfortunately PIC has
	no way of doing this (boo hiss!).

	2) No facility flags in the hexes.   Maybe next release.

	3) Stars are not centered.   I don't know why.  Pic is being
	ostreporous about this.


I wholeheartedly release this set of scripts to the public domain. I don't
claim that they are "the end", and probably could be improved upon greatly.


	Send all questions, complaints, bug reports, flowers and
	brickbats to:

			Peter L. Berghold
			AT&T Red Hill
			[phone removed]
			UUCP: {[email removed]|att}!violin!plb

@EOF
set `sum $sumopt <README`; if test $1 -ne 7787
then
	echo ERROR: README checksum is $1 should be 7787
fi
set `wc -lwc <README`
if test $1$2$3 != 482431421
then
	echo ERROR: wc results of README are $* should be 48 243 1421
fi

chmod 444 README

echo x - do_map
cat >do_map <<'@EOF'
#!/bin/ksh
#
#	@(#) SRCID: @(#)do_map	1.1
#
#########################################################################
##
##	Front end to the "do_map.awk" nawk program.  Filter all the control-l's
##	out and change them to ".bp"s before nawk is forced to process the
##	output from st.
##
##
st $* | sed "s/\/.bp/g"  | do_map.awk
@EOF
set `sum $sumopt <do_map`; if test $1 -ne 24862
then
	echo ERROR: do_map checksum is $1 should be 24862
fi
set `wc -lwc <do_map`
if test $1$2$3 != 1249331
then
	echo ERROR: wc results of do_map are $* should be 12 49 331
fi

chmod 544 do_map

echo x - do_map.awk
cat >do_map.awk <<'@EOF'
#!/usr/bin/nawk -f
########################################################################
##
##	@(#) SRCID: @(#)do_map.awk	1.1
##	@(#)
##	@(#) Author: Peter L. Berghold
##	@(#)	Released to the public domain on 11/16/89
##
##	@(#) do_map.awk  -- Postprocess the output from the program st and
##	@(#)	           change it into [nte]roff compatible input specs.
##
##
BEGIN{		FirstHeader=1	# State for finding the first header
		Star=2;		# Find the star
		Header=3;	# Next header
		Sys=4;	# Process the star system.
		SStab=5;	# Subsector table
		SSmap=6;	# Subsector map
		Swallow=7;	# Swallow lines.

		ocount=0;	# Orbit object count.
		STATE=FirstHeader
		printf ".nr Ej 1\n"
		printf ".PH \"\'IISS Survey Report\'\'UNCLASS\'\"\n"
		printf ".PF \"\'Information released to public\'[ %% ]"
		printf "\'Under the Freedom of Information Act\'\"\n"

		SysCount=0;
		Sysix=0;

	# An array containing the normalized coordinates for a hex map
	# hex vertices.

		hexx[1]=0.866;
		hexy[1]=0;
		hexx[2]=0.433;
		hexy[2]=0.75;
		hexx[3]=-0.433;
		hexy[3]=0.75;
		hexx[4]=-0.866;
		hexy[4]=0;
		hexx[5]=-0.433;
		hexy[5]=-0.75;
		hexx[6]=0.433;
		hexy[6]=-0.75;
}
END {
	hexmapstrt();
	for(ix=0;ix<SysCount;ix++)
		printf "MapSystem(%d,%d,%s,%s)\n",substr(HEX_ENTRY[ix],1,2),\
					substr(HEX_ENTRY[ix],3,2)\
					,HexName[ix]\
					,HexProfile[ix];
	hexmapend();
	print ".TC"
}
NF==0 {
	# ignore blank lines
		next;
}
STATE==FirstHeader && substr($0,1,3) == ".bp" {
		IssueTBhdr1();
		STATE=Star;	# Find the star...
		next;
}
STATE==Star{
		printf "%s %s-%s\n=\n",$1,$2,$3;
		printf "~Planet~Moon\n*~Orbit~Orbit~Name~Description~Remarks\n";
		printf "=\n";
		STATE=Sys
		ocount=0;
		next;
}
STATE==Sys{
	if (substr($0,1,3) == ".bp")
		if ( substr($0,4,1) == "S" ){
			TBhdr();
			STATE=Star;
		} else {	# Processing for the Subsector Table
			print ".TE"
			## We process the first entry CAREFULLY...
			printf ".H 1 \"Subsector Synopsis Table\"\n"
			printf ".TS\nexpand,doublebox,tab(~);\n"
			printf "cccc\nclll.\n"
			printf "Location~Name~Profile~Remarks\n=\n"
			Loc=substr($1,4,length($1)); # Filter out the ".bp"
			Name=$2
			Pr1=$3
			Pr2=$4
			if (NF  > 4 ) {
				for(ix=5;ix<=NF;ix++) Re[ix-4]=$(ix);
				cn=NF-4;
			} else cn=0;
			SSTabEntry(Loc,Name,Pr1,Pr2,cn,Re);
			STATE=SStab;
		}
	else ProcessBody();
	next;
}
STATE==SStab{
	##
	if (substr($0,1,3) == ".bp") STATE=SSmap
	else {
		## Process the SStab entry
		Loc=$1
		Name=$2
		Pr1=$3
		Pr2=$4
		if (NF  > 4 ) {
			for(ix=5;ix<=NF;ix++) Re[ix-4]=$(ix);
			cn=NF-4;
		} else cn=0;
		SSTabEntry(Loc,Name,Pr1,Pr2,cn,Re);
	}
}
STATE==SSmap{
	print ".TE"
	##	Process the SSmap entry
	STATE=Swallow;
}
STATE == Swallow {
	## Gobble this line.
}

#
#	Subfunctions to use in processing the text file...
function IssueTBhdr1()
{
	HEX_ENTRY[SysCount]=substr($3,2,4);
	SysCount++;
	printf ".H 1 \"%s\"\n",substr($0,4,length($0));
	StartTB();
	return
}
function TBhdr()
{
	EndTB();
	HEX_ENTRY[SysCount]=substr($3,2,4);
	SysCount++;
	printf ".H 1 \"%s\"\n",substr($0,4,length($0));
	StartTB();
	return
}
function EndTB()
{
	print ".TE";
	return
}
function StartTB()
{
	print ".TS";
	printf "box,expand,tab(~);\ncsssss\nc|c|c|c|c|c\nc|n|n|l|l|l.\n";
	return
}
function ProcessBody()
{
	Porb=substr($0,4,2);
	Morb=substr($0,7,2);
	if (substr($0,5,1) != " " && ocount > 0)  printf "_\n";
	if ( substr($0,2,1) == "*" )
		printf "*~";
	else
		printf "~";
	if (substr($0,11,11) == "EMPTY ORBIT")
	{
		printf "%d~~~EMPTY ORBIT\n",Porb;
	} else
	{
		ix=10;
		for(iy=10;substr($0,iy,1)!=" ";iy++);
		l=iy-ix;
		OName=substr($0,ix,l);
		ODes_p1=substr($0,27,7);
		ODes_p2=substr($0,36,1);
		Remarks=substr($0,37,length($0));
		if ( substr($0,5,1) == " ")
			printf "~";
		else
			printf "%d~",Porb;
		if ( substr($0,8,1) == " ")
			printf "~";
		else
			printf "%d~",Morb;

		printf "%s~",OName;
		if ( substr($0,27,5) == "Small" )
			printf "Small GG~";
		else
			if ( substr($0,27,5) == "Large" )
				printf "Large GG~";
			else
				printf "%s-%s~",ODes_p1,ODes_p2;
		printf "%s\n",Remarks;
	}
	ocount++;
	return
}

function SSTabEntry(L,N,P1,P2,nc,r)
{
	HexName[Sysix]=N;
	if ( P2 == "UNINHABITED" ){
		printf "%s~%s~~UNINHABITED\n",L,N;
		HexProfile[Sysix]="UNINHABITED";
	}else{
		printf "%s~%s~%s-%s~",L,N,P1,P2;
		HexProfile[Sysix]=sprintf("%s-%s",P1,P2);
		if (nc > 0 )
			for (ix=1;ix<=nc;ix++) printf "%s ",r[ix];
		printf "\n"
	}

	Sysix++;
	return
}

#
#
#
#	Function to start the definition of the hex map macros and such.
############################################################################
function hexmapstrt()
{
	print ".bp"
	print ".nf"
	print ".PS 5 8 "
	print "xmove=0.866"
	print "ymove=0.5"
	print "define Hex X"
	print "cx=$1"
	print "cy=$2"
	print "hexx1=0.577"
	print "hexy1=0"
	print "hexx2=0.289"
	print "hexy2=0.5"
	print "hexx3=-0.289"
	print "hexy3=0.5"
	print "hexx4=-0.577"
	print "hexy4=7.07e-17"
	print "hexx5=-0.289"
	print "hexy5=-0.5"
	print "hexx6=0.289"
	print "hexy6=-0.5"
	print "move to (cx+hexx1,cy+hexy1)"
	print "line to (cx+hexx6,cy+hexy6)"
	print "line to (cx+hexx5,cy+hexy5)"
	print "line to (cx+hexx4,cy+hexy4)"
	print "line to (cx+hexx3,cy+hexy3)"
	print "line to (cx+hexx2,cy+hexy2)"
	print "line to (cx+hexx1,cy+hexy1)"
	print "\"\\s-2$3$4\\s0\" at (cx,hexy3+cy) below"
	print "X"
	print "define MapSystem X"
	print "    cx= $1 - 1 * xmove "
	print "    if ( $1 % 2 == 0 ) then N"
	print "         cy = 11 - ( ymove + $2 )"
	print "    N else N"
	print "         cy= 11- $2"
	print "    N"
	print "    move to (cx,cy)"
        print "    circlerad= 0.1i"
	print "    circle"
	print "    namey=cy+( ( hexy3 - cy ) / 2.0 )"
	print "    \"\\s-2$3\\s0\" at (cx,namey)"
	print "    profy=cy - ( ( cy - hexy5 ) / 2.0 ) "
	print "    \"\\s-2$4\\s0\" at (cx,profy)"
	print "X"
	print "define CreateMap X"
	print "Hex(0,10,01,01)"
	print "Hex(0,9,01,02)"
	print "Hex(0,8,01,03)"
	print "Hex(0,7,01,04)"
	print "Hex(0,6,01,05)"
	print "Hex(0,5,01,06)"
	print "Hex(0,4,01,07)"
	print "Hex(0,3,01,08)"
	print "Hex(0,2,01,09)"
	print "Hex(0,1,01,10)"
	print "Hex(0.866,9.5,02,01)"
	print "Hex(0.866,8.5,02,02)"
	print "Hex(0.866,7.5,02,03)"
	print "Hex(0.866,6.5,02,04)"
	print "Hex(0.866,5.5,02,05)"
	print "Hex(0.866,4.5,02,06)"
	print "Hex(0.866,3.5,02,07)"
	print "Hex(0.866,2.5,02,08)"
	print "Hex(0.866,1.5,02,09)"
	print "Hex(0.866,0.5,02,10)"
	print "Hex(1.73,10,03,01)"
	print "Hex(1.73,9,03,02)"
	print "Hex(1.73,8,03,03)"
	print "Hex(1.73,7,03,04)"
	print "Hex(1.73,6,03,05)"
	print "Hex(1.73,5,03,06)"
	print "Hex(1.73,4,03,07)"
	print "Hex(1.73,3,03,08)"
	print "Hex(1.73,2,03,09)"
	print "Hex(1.73,1,03,10)"
	print "Hex(2.6,9.5,04,01)"
	print "Hex(2.6,8.5,04,02)"
	print "Hex(2.6,7.5,04,03)"
	print "Hex(2.6,6.5,04,04)"
	print "Hex(2.6,5.5,04,05)"
	print "Hex(2.6,4.5,04,06)"
	print "Hex(2.6,3.5,04,07)"
	print "Hex(2.6,2.5,04,08)"
	print "Hex(2.6,1.5,04,09)"
	print "Hex(2.6,0.5,04,10)"
	print "Hex(3.46,10,05,01)"
	print "Hex(3.46,9,05,02)"
	print "Hex(3.46,8,05,03)"
	print "Hex(3.46,7,05,04)"
	print "Hex(3.46,6,05,05)"
	print "Hex(3.46,5,05,06)"
	print "Hex(3.46,4,05,07)"
	print "Hex(3.46,3,05,08)"
	print "Hex(3.46,2,05,09)"
	print "Hex(3.46,1,05,10)"
	print "Hex(4.33,9.5,06,01)"
	print "Hex(4.33,8.5,06,02)"
	print "Hex(4.33,7.5,06,03)"
	print "Hex(4.33,6.5,06,04)"
	print "Hex(4.33,5.5,06,05)"
	print "Hex(4.33,4.5,06,06)"
	print "Hex(4.33,3.5,06,07)"
	print "Hex(4.33,2.5,06,08)"
	print "Hex(4.33,1.5,06,09)"
	print "Hex(4.33,0.5,06,10)"
	print "Hex(5.2,10,07,01)"
	print "Hex(5.2,9,07,02)"
	print "Hex(5.2,8,07,03)"
	print "Hex(5.2,7,07,04)"
	print "Hex(5.2,6,07,05)"
	print "Hex(5.2,5,07,06)"
	print "Hex(5.2,4,07,07)"
	print "Hex(5.2,3,07,08)"
	print "Hex(5.2,2,07,09)"
	print "Hex(5.2,1,07,10)"
	print "Hex(6.06,9.5,08,01)"
	print "Hex(6.06,8.5,08,02)"
	print "Hex(6.06,7.5,08,03)"
	print "Hex(6.06,6.5,08,04)"
	print "Hex(6.06,5.5,08,05)"
	print "Hex(6.06,4.5,08,06)"
	print "Hex(6.06,3.5,08,07)"
	print "Hex(6.06,2.5,08,08)"
	print "Hex(6.06,1.5,08,09)"
	print "Hex(6.06,0.5,08,10)"
	print "X"
	print "CreateMap()"
}

function hexmapend()
{
	print ".PE"
	printf ".FG \"Subsector Map\"\n";
	printf ".fi\n"
}
@EOF
set `sum $sumopt <do_map.awk`; if test $1 -ne 774
then
	echo ERROR: do_map.awk checksum is $1 should be 774
fi
set `wc -lwc <do_map.awk`
if test $1$2$3 != 3588778146
then
	echo ERROR: wc results of do_map.awk are $* should be 358 877 8146
fi

chmod 544 do_map.awk

exit 0

All opinions and material above is the responsibility of the originator.
Submissions: [email removed], or [email removed]
Administrator: [email removed] (James Perkins)
The TML is made possible by facilities provided by Tektronix, Inc.