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.

111 lines
3.1 KiB

  1. /*+*******************************************************************************************
  2. Project : StringCheck
  3. File : ProgramArgs.c
  4. Summary : Responsible for managing program configuration and command line parsing
  5. Classes / Fcns : public class ProgramArgs
  6. Notes / Revisions :
  7. *******************************************************************************************+*/
  8. using System;
  9. /*C+C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++
  10. public class ProgramArgs
  11. Summary:
  12. C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C-C*/
  13. public class ProgramArgs
  14. {
  15. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++
  16. Method: public ProgramArgs(string[] args)
  17. Summary:
  18. Args:
  19. Modifies:
  20. Returns:
  21. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  22. static public int CommandLine(string[] args)
  23. {
  24. // call default constructor
  25. // ProgramArgs(); // this does not work, why?
  26. if (args == null)
  27. {
  28. return 0;
  29. }
  30. if ( args.GetLength(0) < 4)
  31. {
  32. ProgramArgs.ArgsHelp();
  33. return 0;
  34. }
  35. foreach(string s in args)
  36. {
  37. // directory
  38. if ( s.StartsWith("-d") && 2 < s.Length )
  39. {
  40. Directory = s.Substring(2);
  41. }
  42. // filter
  43. else if ( s.StartsWith("-f") && 2 < s.Length )
  44. {
  45. FileFilter = s.Substring(2);
  46. }
  47. // search string
  48. else if ( s.StartsWith("-s") && 2 < s.Length)
  49. {
  50. SearchString = s.Substring(2);
  51. }
  52. // output file
  53. else if ( s.StartsWith("-o") && 2 < s.Length)
  54. {
  55. OutputFile = s.Substring(2);
  56. }
  57. else if ( s.StartsWith("-?") || s.StartsWith("/?") || s.StartsWith("-h") )
  58. {
  59. ArgsHelp();
  60. return 0;
  61. }
  62. else
  63. {
  64. Console.WriteLine("Invalid parameter!!");
  65. ArgsHelp();
  66. }
  67. } // foreach
  68. return 1;
  69. } // public int ProgramArgs(string[] args)
  70. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++
  71. Method: public void ArgsHelp()
  72. Summary:
  73. Args:
  74. Modifies:
  75. Returns:
  76. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  77. static private void ArgsHelp()
  78. {
  79. Console.WriteLine("StringCheck -d<Directory> -f<File Filter> -s<Search String> -o<Output file>");
  80. Console.WriteLine("Directory = Full path to directory that will be scanned.");
  81. Console.WriteLine("File Filter = *, *.cs, etc..");
  82. Console.WriteLine("Search String = Regex expression describing text to search for.");
  83. Console.WriteLine("Output File = Search results will be written to this file.");
  84. }
  85. /*---------------------------------------------------------
  86. Member Variables
  87. ----------------------------------------------------------*/
  88. // Directory to scan.
  89. static public string Directory = "..";
  90. // Files to scan.
  91. static public string FileFilter = "*";
  92. // Search string using regex
  93. static public string SearchString = "*";
  94. // Write results to this file
  95. static public string OutputFile = "out.txt";
  96. } // public class ProgramArgs