Xref: utzoo alt.sources:3299 comp.lang.perl:4231 Path: utzoo!utgpu!cs.utexas.edu!samsung!emory!att!linac!midway!mimsy!mojo!mojo!djm From: djm@eng.umd.edu (David J. MacKenzie) Newsgroups: alt.sources,comp.lang.perl Subject: tcsort -- sort termcap files for comparison Message-ID: Date: 24 Feb 91 06:31:49 GMT Sender: news@eng.umd.edu (C-News) Organization: Project GLUE, University of Maryland Lines: 66 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 # 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 Brought to you by Super Global Mega Corp .com