 ListLineAddresses.awk  combines map file line number listing with source 
                          files

 List Line Addresses
   Map file
   Output file
   [Modules]

BEGIN { 
	if (ARGC == 1 || ARGV[1] == ) {
		printf(Specify map file.\n)
		exit
	}

	if (ARGC == 2 || ARGV[2] == ) {
		printf(Specify output file or queue.\n)
		exit
	}
	outfile = ARGV[2]
	ARGV[2] = 
	printf(Writing to s ... , outfile)
	if (match(outfile, [Vv][Ii][Dd]))
		printf(\n\n)
	fPrintDone = 1

	 get list of specific modules to print
	if (ARGV[3] = )
		for (i = 3; i <= ARGC; i++) {
			mods[++nModules] = tolower(ARGV[i])
			ARGV[i] = 
		}
	UpperStr = ABCDEFGHIJKLMNOPQRSTUVWXYZ
	LowerStr = abcdefghijklmnopqrstuvwxyz
}

 remember selectors for code segments
$4  \([09AF]+h\)  $6  Code { 
	selectors[$5] = substr($4, 2, 4)	 strip off parentheses
}

Line numbers for	{
	module = tolower($4)
	getline								 read in blank line


	 check whether to print this module
	if (nModules > 0) {
		for (i = 1; i <= nModules; i++)
			if (mods[i] == module) {
				mods[i] = 
				break
			}
		if (i > nModules)
			next
	}

	 read in line numbers and convert linear segments to selectors
	while (getline) {
		 check for end of line numbers for module
		if (NF == 0 || $1 == 0)
			break
		for (i = 1; i <= NF; i += 2) {
			gsub(^...., selectors[module], $(i+1))
			addrs[$i] = $(i+1)
		}
	}

	 determine module name from code segment name
	if ((i = index(module, _CODE)) > 0) {
		module = substr(module, 1, i1)
		listfile = module .lst
		file = module .plm
		type = PLM
	}
	else {
		if ((i = index(module, _code)) > 0) {
			type = MWC						 CTOS C (MarkWilliams)
			module = substr(module, 1, i1)
		}
		else if ((i = index(module, C_)) == 1) {
			type = WIZC						 BTOS C (Wizard)
			module = substr(module, 3)
		}
		else
			type = HighC
		file = module .c
	}
		

	 print out source module with line number information
	if ((getline l <file) <= 0) {
		printf(cannot access s\n, file)
		next
	} else {
		 print banner
		print **************************************** >outfile
		printf * 36s *\n, file >outfile
		printf ****************************************\f >outfile
		foutput = 1
	}
		
	if (type == PLM)
		nline = 0
	else
		nline = 1
	do {
		printf(10s\ts\n, addrs[nline], l) >outfile
		addrs[nline] = 				 erase contents for next file
	} while (getsource(file) > 0)
	printf(\f) >outfile
}

END	{ 
	if (fPrintDone) 
		if (foutput)
			print done. 
		else
			print no modules found.

	 check for any unreferenced modules
	for (i = 1; i <= nModules; i++)
		if (mods[i] = )
			printf(Module s not found.\n, mods[i])
}


function getsource(f,     n, listline, len, i, j, c)
{
	if (length(listfile) > 0) {				 if Plm file
		 get source file line
		if ((n = getline l <f) <= 0)
			return n

		 expand tabs in source line to match PLM list output
		if (index(l, \t)) {
			len = length(l)
			expandedl = 
			for(i = j = 1; i <= len; i++) {
				c = substr(l, i, 1)
				if (c == \t) {
					expandedl = expandedl  
					while ((j  4) = 0) {
						expandedl = expandedl  
						j++
					}
				}
				else
					expandedl = expandedl c
				j++
			}
		}
		else
			expandedl = l

		 search list file for same line
		while ((n = getline listline <listfile) > 0) {
			if (length(listline) >= 15) {
				numstr = substr(listline, 1, 4)
				listline = substr(listline, 15, length(listline)15)

				if (listline == expandedl) {
					 found line  if it has a line number, update nline
					if (match(numstr, [09]+) > 0) {
						split(numstr, a)
						nline = a[1]
					}
					return n
				}
			}
		}
		return n
	}
	else {
		nline++
		return getline l <f
	}
}

function tolower(s)
{
	gsub(A, a, s); gsub(B, b, s); gsub(C, c, s); gsub(D, d, s)
	gsub(E, e, s); gsub(F, f, s); gsub(G, g, s); gsub(H, h, s)
	gsub(I, i, s); gsub(J, j, s); gsub(K, k, s); gsub(L, l, s)
	gsub(M, m, s); gsub(N, n, s); gsub(O, o, s); gsub(P, p, s)
	gsub(Q, q, s); gsub(R, r, s); gsub(S, s, s); gsub(T, t, s)
	gsub(U, u, s); gsub(V, v, s); gsub(W, w, s); gsub(X, x, s)
	gsub(Y, y, s); gsub(Z, z, s)
	return s
}
