tcsort -- sort termcap files for comparison

David J. MacKenzie djm at eng.umd.edu
Sun Feb 24 17:31:49 AEST 1991


I use this program to prepare termcap files so that `diff' gives
meaningful results when comparing them.

The program alphabetizes the entries in the file by their canonical
names (the first name following the two-letter Unix V6 name), and
sorts the capabilities within each entry, moving them each onto their
own line.  This makes it easy to see the differences between two entries.

#!/usr/local/bin/perl
# -*- C -*-
# tcsort -- reorder a termcap file so it is easier to compare two of them.
#
# Read a termcap file.
# Sort the capabilities in each entry and move them so there is
# one per line, in the format `cap:\'.
# Sort the entries by the second name (the first long name).
# Write the resulting file to standard out.
#
# David MacKenzie <djm at eng.umd.edu>
# Public domain.

while (<>)
{
  if (/^[ 	]*#/ || /^[ 	]*$/)
    {
      $comments = $comments . $_;
    }
  else
    {
      chop;
      if (substr ($_, length ($_) - 1) eq "\\")
	{
	  chop;
	  $ent = $ent . $_;
	}
      else
	{
	  $ent = $ent . $_;
	  # Remove empty cap fields.
	  $ent =~ s/:[ 	]*:/:/g;
	  @caps = split (/:/, $ent);
	  # Don't sort the terminal names with the caps.
	  $termname = shift (@caps) . ":\\\n";
	  @caps = sort (@caps);
	  $ent = join (":\\\n", @caps) . ":\n";
	  $entries[$nentries++] = $comments . $termname . $ent;
	  $comments = "";
	  $ent = "";
	}
    }
}

@entries = sort (cmpent @entries);

for ($i = 0; $i < $nentries; $i++)
{
  print $entries[$i], "\n";
}

# Compare the canonical names.
sub cmpent
{
  substr ($a, index ($a, '|') + 1) cmp substr ($b, index ($b, '|') + 1);
}
--
David J. MacKenzie <djm at eng.umd.edu> <djm at ai.mit.edu>



More information about the Alt.sources mailing list