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.

116 lines
2.4 KiB

  1. #ifndef _CMDLINE_H
  2. #define _CMDLINE_H
  3. inline LPCTSTR _FindOneOf(LPCTSTR p1, LPCTSTR p2)
  4. {
  5. while (p1 != NULL && *p1 != NULL)
  6. {
  7. LPCTSTR p = p2;
  8. while (p != NULL && *p != NULL)
  9. {
  10. if (*p1 == *p)
  11. return CharNext(p1);
  12. p = CharNext(p);
  13. }
  14. p1 = CharNext(p1);
  15. }
  16. return NULL;
  17. }
  18. inline LPCTSTR _FindOption(LPCTSTR p1)
  19. {
  20. if (p1 == NULL)
  21. return NULL;
  22. // loop until end of string
  23. while (*p1)
  24. {
  25. // if space then check next char for option (- or /)
  26. if (*p1 == _T(' '))
  27. {
  28. p1 = CharNext(p1);
  29. if (*p1 == _T('-') || *p1 == _T('/'))
  30. return CharNext(p1);
  31. }
  32. // if quote then skip over quoted string
  33. else if (*p1 == _T('"'))
  34. {
  35. // loop until single quote or end of string found
  36. p1 = CharNext(p1);
  37. while (*p1)
  38. {
  39. if (*p1 == _T('"'))
  40. {
  41. p1 = CharNext(p1);
  42. if (*p1 != _T('"'))
  43. break;
  44. }
  45. p1 = CharNext(p1);
  46. }
  47. }
  48. else
  49. {
  50. p1 = CharNext(p1);
  51. }
  52. }
  53. return NULL;
  54. }
  55. inline BOOL _ReadParam(/*in,out*/TCHAR* &pszIn, /*out*/TCHAR* pszOut)
  56. {
  57. ATLASSERT(pszIn && pszOut);
  58. if (!pszIn || !pszOut) {
  59. return FALSE;
  60. }
  61. // skip the switch
  62. pszIn = CharNext(pszIn);
  63. // skip leading spaces
  64. while (*pszIn == _T(' '))
  65. pszIn = CharNext(pszIn);
  66. // deal with parameters enclosed in quotes to allow embedded spaces
  67. BOOL fQuoted = FALSE;
  68. if (*pszIn == _T('"')) {
  69. pszIn = CharNext(pszIn);
  70. fQuoted = TRUE;
  71. }
  72. // get the next arg (delimited by space or null or end quote)
  73. int nPos = 0;
  74. while (*pszIn && nPos < MAX_PATH) {
  75. if (fQuoted) {
  76. if (*pszIn == _T('"')) {
  77. // don't break on double quotes
  78. if (pszIn[1] == _T('"')) {
  79. pszOut[nPos++] = *pszIn;
  80. pszIn = CharNext(pszIn);
  81. pszIn = CharNext(pszIn);
  82. continue;
  83. }
  84. else {
  85. pszIn = CharNext(pszIn);
  86. break;
  87. }
  88. }
  89. }
  90. else {
  91. if(*pszIn == _T(' '))
  92. break;
  93. }
  94. pszOut[nPos++] = *pszIn;
  95. pszIn = CharNext(pszIn);
  96. }
  97. pszOut[nPos] = 0;
  98. return TRUE;
  99. }
  100. #endif