PageRenderTime 47ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/cmd/error.c

http://nativecmd.googlecode.com/
C | 169 lines | 106 code | 40 blank | 23 comment | 7 complexity | f1a109a3ba068edcefb30a3c34752a67 MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. * ERROR.C - error reporting functions.
  3. *
  4. *
  5. * History:
  6. *
  7. * 07/12/98 (Rob Lake)
  8. * started
  9. *
  10. * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
  11. * added config.h include
  12. *
  13. * 24-Jan-1999 (Eric Kohl)
  14. * Redirection safe!
  15. *
  16. * 02-Feb-1999 (Eric Kohl)
  17. * Use FormatMessage() for error reports.
  18. *
  19. * 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
  20. * Remove all hardcode string to En.rc
  21. */
  22. #include <precomp.h>
  23. VOID ErrorMessage (DWORD dwErrorCode, LPTSTR szFormat, ...)
  24. {
  25. TCHAR szMsg[RC_STRING_MAX_SIZE];
  26. TCHAR szMessage[1024];
  27. LPTSTR szError;
  28. va_list arg_ptr;
  29. if (dwErrorCode == ERROR_SUCCESS)
  30. return;
  31. nErrorLevel = 1;
  32. if (szFormat)
  33. {
  34. va_start (arg_ptr, szFormat);
  35. _vstprintf (szMessage, szFormat, arg_ptr);
  36. va_end (arg_ptr);
  37. }
  38. if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
  39. NULL, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  40. (LPTSTR)&szError, 0, NULL))
  41. {
  42. ConErrPrintf (_T("%s %s\n"), szError, szMessage);
  43. if(szError)
  44. LocalFree (szError);
  45. return;
  46. }
  47. /* Fall back just in case the error is not defined */
  48. if (szFormat)
  49. ConErrPrintf (_T("%s -- %s\n"), szMsg, szMessage);
  50. else
  51. ConErrPrintf (_T("%s\n"), szMsg);
  52. }
  53. VOID error_parameter_format(TCHAR ch)
  54. {
  55. ConErrResPrintf(STRING_ERROR_PARAMETERF_ERROR, ch);
  56. nErrorLevel = 1;
  57. }
  58. VOID error_invalid_switch (TCHAR ch)
  59. {
  60. ConErrResPrintf(STRING_ERROR_INVALID_SWITCH, ch);
  61. nErrorLevel = 1;
  62. }
  63. VOID error_too_many_parameters (LPTSTR s)
  64. {
  65. ConErrResPrintf(STRING_ERROR_TOO_MANY_PARAMETERS, s);
  66. nErrorLevel = 1;
  67. }
  68. VOID error_path_not_found (VOID)
  69. {
  70. ConErrResPuts(STRING_ERROR_PATH_NOT_FOUND);
  71. nErrorLevel = 1;
  72. }
  73. VOID error_file_not_found (VOID)
  74. {
  75. ConErrResPuts(STRING_ERROR_FILE_NOT_FOUND);
  76. nErrorLevel = 1;
  77. }
  78. VOID error_sfile_not_found (LPTSTR f)
  79. {
  80. TCHAR szMsg[RC_STRING_MAX_SIZE];
  81. LoadString(CMD_ModuleHandle, STRING_ERROR_FILE_NOT_FOUND, szMsg, RC_STRING_MAX_SIZE);
  82. ConErrPrintf(_T("%s - %s\n"), szMsg, f);
  83. nErrorLevel = 1;
  84. }
  85. VOID error_req_param_missing (VOID)
  86. {
  87. ConErrResPuts(STRING_ERROR_REQ_PARAM_MISSING);
  88. nErrorLevel = 1;
  89. }
  90. VOID error_invalid_drive (VOID)
  91. {
  92. ConErrResPuts(STRING_ERROR_INVALID_DRIVE);
  93. nErrorLevel = 1;
  94. }
  95. VOID error_bad_command (LPTSTR s)
  96. {
  97. ConErrResPrintf(STRING_ERROR_BADCOMMAND, s);
  98. nErrorLevel = 9009;
  99. }
  100. VOID error_no_pipe (VOID)
  101. {
  102. ConErrResPuts(STRING_ERROR_CANNOTPIPE);
  103. nErrorLevel = 1;
  104. }
  105. VOID error_out_of_memory (VOID)
  106. {
  107. ConErrResPuts(STRING_ERROR_OUT_OF_MEMORY);
  108. nErrorLevel = 1;
  109. }
  110. VOID error_invalid_parameter_format (LPTSTR s)
  111. {
  112. ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, s);
  113. nErrorLevel = 1;
  114. }
  115. VOID error_syntax (LPTSTR s)
  116. {
  117. TCHAR szMsg[RC_STRING_MAX_SIZE];
  118. LoadString(CMD_ModuleHandle, STRING_ERROR_ERROR2, szMsg, RC_STRING_MAX_SIZE);
  119. if (s)
  120. ConErrPrintf(_T("%s - %s\n"), szMsg, s);
  121. else
  122. ConErrPrintf(_T("%s.\n"), szMsg);
  123. nErrorLevel = 1;
  124. }
  125. VOID msg_pause (VOID)
  126. {
  127. ConOutResPuts(STRING_ERROR_D_PAUSEMSG);
  128. }
  129. /* EOF */