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 / newicon.icn < prev    next >
Text File  |  2002-03-26  |  3KB  |  107 lines

  1. ############################################################################
  2. #
  3. #    File:     newicon.icn
  4. #
  5. #    Subject:  Program to produce new Icon program file
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     March 26, 2002
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program creates a new file with a standard Icon program
  18. #  header and a skeleton mail procedure.
  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.  The same comment applies to the skeleton file mentioned below.
  25. #
  26. #  The new file is brought up in the vi editor.
  27. #
  28. #  The supported options are:
  29. #
  30. #    -f    overwrite and existing file
  31. #    -p    produce a procedure file instead of a program
  32. #    -o    provide program skeleton with options()
  33. #
  34. #  The files skeleton.icn, skelproc.icn, and skelopt.icn must be accessible
  35. #  via dopen().
  36. #
  37. ############################################################################
  38. #
  39. #  Requires:  system(), vi(1)
  40. #
  41. ############################################################################
  42. #
  43. #  Links:  basename, datetime, io, options
  44. #
  45. ############################################################################
  46.  
  47. link basename
  48. link datetime
  49. link io
  50. link options
  51.  
  52. procedure main(args)
  53.    local opts, overwrite, name, author, input, output, file
  54.  
  55.    opts := options(args, "fpo")
  56.    if \opts["f"] then overwrite := 1
  57.  
  58.    name := (args[1] | "foo")
  59.    if (*name < 4) | (name[-4:0] ~== ".icn") then name ||:= ".icn"
  60.  
  61.    author := args[2] | "Ralph E. Griswold"
  62.  
  63.    if /overwrite then {                # check to see if file exists
  64.        if input := open(name) then {
  65.           close(input)
  66.           system("vi " || name)
  67.           exit()
  68.           }
  69.       }
  70.  
  71.    output := open(name, "w") |
  72.       stop("*** cannot open ", name, " for writing")
  73.  
  74.    input := dopen(
  75.       if \opts["o"] then file := "skelopt.icn"
  76.       else if \opts["p"] then "skelproc.icn"
  77.       else "skeleton.icn"
  78.       ) | stop("*** cannot open skeleton file")
  79.  
  80.    every 1 to 2 do write(output, read(input)) |
  81.       stop("*** short skeleton file")
  82.    write(output, read(input), name) |
  83.       stop("*** short skeleton file")
  84.    every 1 to 3 do write(output, read(input)) |
  85.       stop("*** short skeleton file")
  86.    write(output, read(input), author) |
  87.       stop("*** short skeleton file")
  88.    write(output, read(input)) |
  89.       stop("*** short skeleton file")
  90.    write(output, read(input), date()) |
  91.       stop("*** short skeleton file")
  92.    write(output, read(input)) |
  93.       stop("*** short skeleton file")
  94.    while write(output, read(input))
  95.  
  96.    if \opts["p"] then {
  97.       write(output, "procedure ", basename(name, ".icn"), "()")
  98.       write(output)
  99.       write(output, "end")
  100.       }
  101.  
  102.    close(output)
  103.  
  104.    system("vi " || name)
  105.  
  106. end
  107.