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

  1. ############################################################################
  2. #
  3. #    File:     headicon.icn
  4. #
  5. #    Subject:  Program to add header to Icon program
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     November 20, 1997
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program prepends a standard header to an Icon program.  It does not
  18. #  check to see if the program already has a header.
  19. #
  20. #  The first command-line argument is taken as the base
  21. #  name of the file; default "foo".  The second command-line argument is
  22. #  taken as the author; the default is "Ralph E. Griswold" -- with minor
  23. #  apologies, I use this program a lot; personalize it for your own
  24. #  use.
  25. #
  26. #  The new file is brought up in the vi editor.
  27. #
  28. #  The file skeleton.icn must be accessible via dopen().
  29. #
  30. ############################################################################
  31. #
  32. #  Requires:  system(), vi(1)
  33. #
  34. ############################################################################
  35. #
  36. #  Links:  datetime, io
  37. #
  38. ############################################################################
  39.  
  40. link datetime
  41. link io
  42.  
  43. procedure main(args)
  44.    local name, author, input, output, line
  45.  
  46.    name := (args[1] | "foo")
  47.    if (*name < 4) | (name[-4:0] ~== ".icn") then name ||:= ".icn"
  48.  
  49.    author := args[2] | "Ralph E. Griswold"
  50.  
  51.    output := tempfile("head", , "/tmp") |
  52.       stop("*** cannot open temporary file")
  53.  
  54.    input := dopen("skeleton.icn") | stop("*** cannot open skeleton file")
  55.  
  56.    every 1 to 2 do
  57.       write(output, read(input)) | stop("*** short skeleton file")
  58.    write(output, read(input), name) | stop("*** short skeleton file")
  59.    every 1 to 3 do
  60.       write(output, read(input)) | stop("*** short skeleton file")
  61.    write(output, read(input), author) | stop("*** short skeleton file")
  62.    write(output, read(input)) | stop("*** short skeleton file")
  63.    write(output, read(input), date()) | stop("*** short skeleton file")
  64.    every 1 to 14 do
  65.       write(output, read(input)) | stop("*** short skeleton file")
  66.  
  67.    close(input)
  68.  
  69.    input := open(name) | stop("*** cannot open input file")
  70.  
  71.    while write(output, read(input))
  72.  
  73.    close(output)
  74.  
  75.    image(output) ? {
  76.       ="file("
  77.       output := tab(upto(')'))
  78.       }
  79.  
  80.    system("cp " || output || " " || name)
  81.  
  82.    system("vi " || name)
  83.  
  84. end
  85.