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 / oldicon.icn < prev    next >
Text File  |  2000-07-29  |  2KB  |  69 lines

  1. ############################################################################
  2. #
  3. #    File:     oldicon.icn
  4. #
  5. #    Subject:  Program to update the date in an Icon program header
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     September 23, 1996
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program updates the date line in a standard Icon program header.
  18. #  The old file is saved with the suffix ".bak".
  19. #
  20. #  The file then is brought up in the vi editor unless the -f option
  21. #  is specified.
  22. #
  23. ############################################################################
  24. #
  25. #  Requires:  system(), vi(1), UNIX
  26. #
  27. ############################################################################
  28. #
  29. #  Links:  datetime, options
  30. #
  31. ############################################################################
  32.  
  33. link datetime
  34. link options
  35.  
  36. procedure main(args)
  37.    local name, input, output, line, opts
  38.  
  39.    opts := options(args, "f")
  40.  
  41.    name := (args[1] | "foo")
  42.    if (*name < 4) | (name[-4:0] ~== ".icn") then name ||:= ".icn"
  43.  
  44.    if system("cp " || name || " " || name || ".bak >/dev/null") ~= 0 then {
  45.       if /opts["f"] then system("vi " || name)    # if file didn't exist
  46.       exit()
  47.       }
  48.  
  49.    input := open(name || ".bak") | stop("*** cannot open backup file")
  50.  
  51.    output := open(name, "w") | stop("*** cannot open ", name, " for writing")
  52.  
  53.    repeat {                # to provide a way out ...
  54.       every 1 to 8 do write(output, read(input)) | break
  55.       line := read(input) | break
  56.       line ? {
  57.          write(output, ="#    Date:     ", date()) | write(output, tab(0))
  58.          }
  59.       break
  60.       }
  61.  
  62.    while write(output, read(input))
  63.  
  64.    close(output)
  65.  
  66.    if /opts["f"] then system("vi " || name)
  67.  
  68. end
  69.