awkfilter.sh #3

  • //
  • guest/
  • michael_shields/
  • src/
  • p4jrep/
  • awkfilter.sh
  • View
  • Commits
  • Open Download .zip Download (2 KB)
#!/bin/sh

# Replicate only the changelists.

awk '

# Parse through journal entries that may span multiple records for
# only either named or unnamed tables.

{

	# Indicate whether to print journal entries for the named tables:
	#     printnamed = 1: print journal entries for only named tables
	#     printnamed = 0: print journal entries for only unnamed tables

	printnamed = 1

	# Named tables:

	if( $3 == "@db.change@" )
	    ParsePrint( printnamed )

	else if( $3 == "@db.changex@" )
	    ParsePrint( printnamed )

	else if( $3 == "@db.counters@" )
	    ParsePrint( printnamed )

	else if( $3 == "@db.desc@" )
	    ParsePrint( printnamed )

	else if( $3 == "@db.rev@" )
	    ParsePrint( printnamed )

	else if( $3 == "@db.revcx@" )
	    ParsePrint( printnamed )

	else if( $3 == "@db.revdx@" )
	    ParsePrint( printnamed )

	else if( $3 == "@db.revhx@" )
	    ParsePrint( printnamed )

	# Unnamed tables:

	else
	    ParsePrint( !printnamed )
}

# Function to parse through a journal entry that may span multiple records,
# and optionally print as we parse. We know we are done with a journal entry
# when the number of "@" characters seen at the end of a record is even.

function ParsePrint( printrecs )
{
	n = 0	# number of "@" characters in journal entry

	# Iterate over records until the number of "@" characters seen
	# at the end of a record is even.

	do
	{
	    if( printrecs )
	    {

		# We desire to print this (potentially multi-line) journal
		# entry, so print this record.

		print $0
	    }

	    i = 1	# starting index for locating the next "@" character

	    # Iterate over "@" characters in this record.

	    while( j = index( substr( $0, i ), "@" ) )
	    {
		i = i + j	# move starting index over "@" character found
		n++		# increment number of "@" characters seen
	    }

	    if( neednext = n % 2 )
	    {

		# Number of "@" characters is odd, which means that we are
		# in the middle of a field that contains an embedded newline.
		# We need the next record as it is part of this journal entry.

		getline
	    }
	}
	while( neednext )
}
' $1 | p4d -r /p4roots/target -f -jr -
# Change User Description Committed
#3 6256 Michael Shields Additional tidbits to bring these current as of the 2007.3 release.
#2 3621 Michael Shields p4jrep Version 0.80 (beta) and cpipe Version 0.76 (beta)
for solaris26sparc (shucks).
#1 2443 Michael Shields beta p4jrep and cpipe.
See jrepnotes.txt for details.