#!/usr/bin/perl # # new: # generate a template for a particular file # # Copyright (c) 2001 Chris Lightfoot. All rights reserved. # # $Id: new,v 1.18 2004/11/18 18:03:51 chris Exp $ # @pwe = getpwuid($>); $copyright_author = $ENV{FULLNAME}; $copyright_author ||= $pwe[6]; @tim = gmtime(); $year = $tim[5] + 1900; $copyright = "Copyright (c) $year $copyright_author. All rights reserved."; $contact = undef; if (defined($ENV{MAILADDRESS})) { $contact = "Email: $ENV{MAILADDRESS}"; } if (defined($ENV{WEBADDRESS})) { $contact .= "; " if ($contact); $contact .= "WWW: $ENV{WEBADDRESS}"; } # search for a .newblurb file my $path = ''; for (my $i = 0; $i < 25; ++$i) { if (-e "${path}.newblurb") { if (open(BLURB, "${path}.newblurb")) { $copyright = ; chomp($copyright); $contact = ; $contact ||= ''; chomp($contact); close(BLURB); last; } } $path = "../$path"; } if (@ARGV == 1) { # only argument is the file name if ($ARGV[0] =~ /\.(cpp|C|cxx|cc)$/) { $type = "c++"; } elsif ($ARGV[0] =~ /\.(java|j)$/) { $type = "java"; } elsif ($ARGV[0] =~ /\.c$/) { $type = "c"; } elsif ($ARGV[0] =~ /\.h$/) { $type = "h"; } elsif ($ARGV[0] =~ /\.pm$/) { $type = "pm"; } elsif ($ARGV[0] =~ /\.html$/) { $type = "html"; } elsif ($ARGV[0] =~ /\.tex$/) { $type = "latex"; } elsif ($ARGV[0] =~ /^Makefile/) { $type = "make"; } elsif ($ARGV[0] =~ /\.sql$/) { $type = "sql"; } elsif ($ARGV[0] =~ /\.php$/) { $type = "php"; } else { print STDERR "Couldn't guess type for file $ARGV[0]\n"; exit(1); } print STDERR "Guessed type $type\n"; } elsif (@ARGV > 1) { # assume first argument is type, remainder are filenames $type = shift(@ARGV); } else { # oops print STDERR < creates files of type type or new guess type of file and create it EOF exit(1); } # supported file types: # c C language file # c++ C++ language file # h /C++ header file # pl Perl program # pm Perl module # sh Shell script # html HTML file # latex LaTeX document # make Makefile foreach $file (@ARGV) { if (-e $file) { # don't clobber files print STDERR "$file exists, not overwriting it\n"; } else { if (!open(FILE, ">$file")) { print STDERR "$file: $!\n"; next; } if ($type eq "c" or $type eq "c++") { print FILE < $file

Copyright (c) $year $copyright_author. All rights reserved.

EOF } elsif ($type eq "latex") { print FILE < EOF } else { print STDERR "Type $type unknown, creating empty $file\n"; print FILE "\n"; } close(FILE); } }