home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2853 < prev    next >
Internet Message Format  |  1991-02-23  |  2KB

  1. From: djm@eng.umd.edu (David J. MacKenzie)
  2. Newsgroups: alt.sources,comp.lang.perl
  3. Subject: tcsort -- sort termcap files for comparison
  4. Message-ID: <DJM.91Feb24013149@egypt.eng.umd.edu>
  5. Date: 24 Feb 91 06:31:49 GMT
  6.  
  7. I use this program to prepare termcap files so that `diff' gives
  8. meaningful results when comparing them.
  9.  
  10. The program alphabetizes the entries in the file by their canonical
  11. names (the first name following the two-letter Unix V6 name), and
  12. sorts the capabilities within each entry, moving them each onto their
  13. own line.  This makes it easy to see the differences between two entries.
  14.  
  15. #!/usr/local/bin/perl
  16. # -*- C -*-
  17. # tcsort -- reorder a termcap file so it is easier to compare two of them.
  18. #
  19. # Read a termcap file.
  20. # Sort the capabilities in each entry and move them so there is
  21. # one per line, in the format `cap:\'.
  22. # Sort the entries by the second name (the first long name).
  23. # Write the resulting file to standard out.
  24. #
  25. # David MacKenzie <djm@eng.umd.edu>
  26. # Public domain.
  27.  
  28. while (<>)
  29. {
  30.   if (/^[     ]*#/ || /^[     ]*$/)
  31.     {
  32.       $comments = $comments . $_;
  33.     }
  34.   else
  35.     {
  36.       chop;
  37.       if (substr ($_, length ($_) - 1) eq "\\")
  38.     {
  39.       chop;
  40.       $ent = $ent . $_;
  41.     }
  42.       else
  43.     {
  44.       $ent = $ent . $_;
  45.       # Remove empty cap fields.
  46.       $ent =~ s/:[     ]*:/:/g;
  47.       @caps = split (/:/, $ent);
  48.       # Don't sort the terminal names with the caps.
  49.       $termname = shift (@caps) . ":\\\n";
  50.       @caps = sort (@caps);
  51.       $ent = join (":\\\n", @caps) . ":\n";
  52.       $entries[$nentries++] = $comments . $termname . $ent;
  53.       $comments = "";
  54.       $ent = "";
  55.     }
  56.     }
  57. }
  58.  
  59. @entries = sort (cmpent @entries);
  60.  
  61. for ($i = 0; $i < $nentries; $i++)
  62. {
  63.   print $entries[$i], "\n";
  64. }
  65.  
  66. # Compare the canonical names.
  67. sub cmpent
  68. {
  69.   substr ($a, index ($a, '|') + 1) cmp substr ($b, index ($b, '|') + 1);
  70. }
  71. --
  72. David J. MacKenzie <djm@eng.umd.edu> <djm@ai.mit.edu>
  73.