home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / progs / newsrc.icn < prev    next >
Text File  |  2000-07-29  |  3KB  |  89 lines

  1. ############################################################################
  2. #
  3. #    File:     newsrc.icn
  4. #
  5. #    Subject:  Program to organize UNIX .newsrc file
  6. #
  7. #    Author:   Alan D. Corre
  8. #
  9. #    Date:     April 1, 1993
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program takes the .newsrc file, moves active groups to the beginning
  18. #  then appends inactive groups with the numbers omitted, then anything else.
  19. #  the groups are alphabetized.
  20. #
  21. #  The user may retain a set of groups at the top of the file by specifying how
  22. #  many groups on the command line. If not specified, it will be prompted for.
  23. #  the new file is called newnewsrc. The user can replace .newsrc with it if it
  24. #  is satisfactory.
  25. #
  26. ############################################################################
  27.  
  28. procedure main(times)
  29.     process(times)
  30. end
  31.  
  32. procedure process(times)
  33. local active, inactive, defective, invar, outvar, line, newline
  34.  
  35. #create three empty lists
  36.     active := []
  37.     inactive := []
  38.     defective := []
  39.  
  40. #open old and new files
  41.     if not (invar := open(".newsrc")) then stop("Unable to open .newsrc")
  42.     outvar := open("newnewsrc","w")
  43.  
  44. #get saved lines
  45. if *times = 0 then put(times,ask()) else {
  46.     if not integer(times[1]) then stop("Bye")
  47.     if times[1] = 1 then write("The following line has been saved:") else
  48.     if times[1] > 1 then
  49.            write("The following ",times[1]," lines have been saved:")}
  50.     every 1 to times[1] do
  51.         write(write(outvar,read(invar)))
  52. #place the lines in appropriate lists
  53.     while line := read(invar) do {
  54.         newline := line
  55.         line    ?    {if find(":") then
  56.                     put(active,newline) else
  57.                  if newline := (tab(find("!")) || "!") then
  58.                     put(inactive,newline) else
  59.                  put(defective,newline)}}
  60.     close(invar)
  61. #sort the lists
  62.     active := sort(active)
  63.     inactive := sort(inactive)
  64.     defective := sort(defective)
  65. #create the new file
  66.     every line := !active do
  67.         write(outvar,line)
  68.     every line := !inactive do
  69.         write(outvar,line)
  70.     every line := !defective do
  71.         write(outvar,line)
  72. #notify user
  73.     write("File newnewsrc has been created.  If it is satisfactory, use")
  74.     write("mv newnewsrc .newsrc to replace old file.")
  75.     close(outvar)
  76. end
  77.  
  78.  
  79. procedure ask()
  80. local number,n
  81.     n := 0
  82.     write("You may save any number of lines at the top of the file.")
  83.     writes("Enter a whole number, 0 or greater.> ")
  84.     while not integer(number := read()) do  {
  85.         if (n +:= 1) > 3 then stop("Bye.")
  86.         writes("You must enter a whole number.> ")}
  87.         return number
  88. end
  89.