home *** CD-ROM | disk | FTP | other *** search
- From: djm@eng.umd.edu (David J. MacKenzie)
- Newsgroups: alt.sources,comp.lang.perl
- Subject: tcsort -- sort termcap files for comparison
- Message-ID: <DJM.91Feb24013149@egypt.eng.umd.edu>
- Date: 24 Feb 91 06:31:49 GMT
-
- 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@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@eng.umd.edu> <djm@ai.mit.edu>
-