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.

99 lines
2.0 KiB

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