ctmkelem 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/local/bin/perl
  2. sub CTMkElemUsage {
  3. print STDERR "Usage: ctmkelem [-c \"comment\"] [-nc] [-eltype type] element-name [...]\n" ;
  4. print STDERR "Options:\n" ;
  5. print STDERR " -c \"comment\" : provide a comment about this action\n" ;
  6. print STDERR " -nc : expect no comment on this action\n" ;
  7. print STDERR " -eltype type : element type\n" ;
  8. exit ;
  9. }
  10. if ( $#ARGV < 0 ) {
  11. &CTMkElemUsage ;
  12. }
  13. $tool = $ENV{"DTOOL"} ;
  14. if ( $tool eq "" ) {
  15. die "Environment not configured for CTtools" ;
  16. }
  17. require "$tool/include/ctutils.pl" ;
  18. require "$tool/include/ctvspec.pl" ;
  19. require "$tool/include/ctquery.pl" ;
  20. require "$tool/include/ctproj.pl" ;
  21. require "$tool/include/ctcm.pl" ;
  22. $comment = "" ;
  23. $eltype = "" ;
  24. $done = 0 ;
  25. while ( ! $done ) {
  26. $done = 1 ;
  27. if ( $ARGV[0] eq "-nc" ) {
  28. shift( @ARGV ) ;
  29. &CTUDebug( "-nc processed\n" ) ;
  30. $done = 0 ;
  31. }
  32. if ( $ARGV[0] eq "-c" ) {
  33. shift( @ARGV ) ;
  34. $comment = $ARGV[0] ;
  35. shift( @ARGV ) ;
  36. &CTUDebug( "setting comment to '" . $comment . "'\n" ) ;
  37. $done = 0 ;
  38. }
  39. if ( $ARGV[0] eq "-eltype" ) {
  40. shift( @ARGV ) ;
  41. $eltype = $ARGV[0] ;
  42. shift( @ARGV ) ;
  43. &CTUDebug( "setting eltype to '" . $eltype . "'\n" ) ;
  44. $done = 0 ;
  45. }
  46. }
  47. if ( $#ARGV < 0 ) {
  48. &CTMkElemUsage ;
  49. }
  50. $projname = &CTProj ;
  51. $projname =~ tr/A-Z/a-z/ ;
  52. $flav = &CTQueryProj( $projname ) ;
  53. $spec = &CTResolveSpec( $projname, $flav ) ;
  54. foreach $item ( @ARGV ) {
  55. if ( -e $item ) {
  56. if ( -d $item ) {
  57. print STDERR "Cannot mkelem on an existing directory." .
  58. " Ctmkdir it first.\n" ;
  59. } else {
  60. if ( ! &CTCMMkelem( $item, $projname, $spec, $comment, $eltype )) {
  61. print STDERR "Could not make a versioned element of '" .
  62. $item . "'\n" ;
  63. }
  64. }
  65. } else {
  66. print STDERR "No such file '$item'.\n" ;
  67. }
  68. }