Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
3.6 KiB

  1. # __________________________________________________________________________________
  2. #
  3. # Purpose:
  4. # PERL Script to emulate SLM's 'addfile' command
  5. #
  6. # Parameters:
  7. # See Usage below
  8. #
  9. # Output:
  10. # Perforce output or the appropriate error message or usage statement
  11. #
  12. # __________________________________________________________________________________
  13. #
  14. # Load common SLM wrapper subroutine module
  15. #
  16. use SlmSubs;
  17. #
  18. # Parse command line arguments
  19. #
  20. SlmSubs::ParseArgs(@ARGV);
  21. #
  22. # Call usage and exit if ParseArgs has set the Usage or InvalidFlag flags or there
  23. # were no arguments given
  24. #
  25. if ($Usage or $InvalidFlag or $NoArgumentsGiven)
  26. {
  27. print $ErrorMessage;
  28. &Usage;
  29. exit 1;
  30. }
  31. #
  32. # Need to have a file list
  33. #
  34. if ((!@FileList) and (!@DirList))
  35. {
  36. print "\n";
  37. print "Error: No files specified\n";
  38. print "\n";
  39. &Usage;
  40. exit 1;
  41. }
  42. #
  43. # Get lists of dirs and files in the current directory
  44. #
  45. opendir CurrentDir, ".";
  46. @LocalFiles = grep -f, readdir CurrentDir;
  47. closedir CurrentDir;
  48. opendir CurrentDir, ".";
  49. @LocalDirs = grep -d, readdir CurrentDir;
  50. closedir CurrentDir;
  51. #
  52. # Initialize lists
  53. #
  54. @AddFilesFileList = ();
  55. @AddFilesDirList = ();
  56. #
  57. # Check for every local file if it is in @OriginalFileList
  58. #
  59. foreach $FileName (@LocalFiles)
  60. {
  61. if (SlmSubs::InList($FileName, \@OriginalFileList))
  62. {
  63. push @AddFilesFileList, qq/"$FileName"/;
  64. }
  65. }
  66. #
  67. # Check for every local directory if it is in @OriginalFileList
  68. #
  69. foreach $DirName (@LocalDirs)
  70. {
  71. if (SlmSubs::InList($DirName, \@OriginalFileList))
  72. {
  73. push @AddFilesDirList, qq/"$DirName"/;
  74. }
  75. }
  76. #
  77. # Get Perforce ready to add files from $AddFilesFileList and subdirectories from
  78. # $AddFilesDirList
  79. #
  80. if (@AddFilesFileList)
  81. {
  82. system "$SourceControlClient add @AddFilesFileList | findstr can't";
  83. }
  84. if ($Recursive and @AddFilesDirList)
  85. {
  86. system "del $ENV{tmp}\\TmpListFile >nul 2>&1";
  87. foreach $Dir (@AddFilesDirList)
  88. {
  89. if (($Dir ne qq/"."/) and ($Dir ne qq/".."/))
  90. {
  91. system "dir /b /a-d /s $Dir >> $ENV{tmp}\\TmpListFile";
  92. }
  93. }
  94. system "$SourceControlClient -x $ENV{tmp}\\TmpListFile add | findstr can't";
  95. system "del $ENV{tmp}\\TmpListFile >nul 2>&1";
  96. }
  97. #
  98. # Initialize lists
  99. #
  100. @AddFilesList = ();
  101. SlmSubs::CreateSubmitList("add", \@AddFilesList);
  102. if (@AddFilesList)
  103. {
  104. @SubmitOutput = SlmSubs::PerforceRequest("submit", \@AddFilesList);
  105. print "@SubmitOutput";
  106. }
  107. else
  108. {
  109. print "There are no valid files to add\n";
  110. }
  111. sub Usage
  112. # __________________________________________________________________________________
  113. #
  114. # Prints out a usage statement for this script. In this case usurped from SLM's
  115. # 'addfile' usage statement
  116. #
  117. # Parameters:
  118. # None
  119. #
  120. # Output:
  121. # The usage statement
  122. #
  123. # __________________________________________________________________________________
  124. {
  125. print q/addfile - adds file(s) to a project
  126. Usage: addfile [-?fhr] [-c comment] [file1] [file2... ]
  127. Arguments:
  128. -h prints out this message.
  129. -r (recursive) adds to the project all files in a given directory, and
  130. every subdirectory under that directory, along with the files in those
  131. subdirectories. If no directory is specified in the file argument, the
  132. current directory is assumed. If a pattern is included in the file
  133. argument, only adds files that match the pattern.
  134. -c supplies the same comment for all files (otherwise, you are prompted
  135. for one).
  136. /;
  137. }