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.

114 lines
1.9 KiB

  1. //
  2. // printf.c
  3. //
  4. // simple minded printf replacement
  5. //
  6. // only supports %s and %d but it is *small*
  7. //
  8. #include <string.h>
  9. #include <io.h>
  10. #include <stdlib.h>
  11. #if defined(OS2)
  12. #define INCL_NOCOMMON
  13. #define INCL_DOSPROCESS
  14. #define INCL_DOSSEMAPHORES
  15. #define INCL_DOSFILEMGR
  16. #define INCL_DOSERRORS
  17. #define INCL_DOSMISC
  18. #include <os2.h>
  19. #else
  20. #include <windows.h>
  21. #endif
  22. #include <dos.h>
  23. #include "hungary.h"
  24. #include "bsc.h"
  25. #include "bscsup.h"
  26. static char lpchBuf[1024];
  27. static LPCH lpchPos = NULL;
  28. VOID BSC_API
  29. BSCPrintf(LSZ lszFormat, ...)
  30. // printf replacement
  31. //
  32. {
  33. va_list va;
  34. LPCH lpch;
  35. char ch;
  36. if (!lpchPos) {
  37. lpchPos = lpchBuf;
  38. }
  39. va_start(va, lszFormat);
  40. BSCFormat(lpchPos, lszFormat, va);
  41. // write out a line at a time
  42. //
  43. for (;;) {
  44. lpch = strchr(lpchPos, '\n');
  45. if (!lpch) {
  46. lpchPos += strlen(lpchPos);
  47. return;
  48. }
  49. ch = *++lpch;
  50. *lpch = 0;
  51. BSCOutput(lpchBuf);
  52. *lpch = ch;
  53. strcpy(lpchBuf, lpch);
  54. if (!ch)
  55. lpchPos = lpchBuf;
  56. else
  57. lpchPos = lpchBuf + strlen(lpchBuf);
  58. }
  59. }
  60. #ifdef DEBUG
  61. static char lpchDBuf[256];
  62. static LPCH lpchDPos = NULL;
  63. VOID BSC_API
  64. BSCDebug(LSZ lszFormat, ...)
  65. // printf clone for debug output
  66. //
  67. {
  68. va_list va;
  69. LPCH lpch;
  70. char ch;
  71. if (!lpchDPos) {
  72. lpchDPos = lpchDBuf;
  73. }
  74. va_start(va, lszFormat);
  75. BSCFormat(lpchDPos, lszFormat, va);
  76. // write out a line at a time
  77. //
  78. for (;;) {
  79. lpch = strchr(lpchDPos, '\n');
  80. if (!lpch) {
  81. lpchDPos += strlen(lpchDPos);
  82. return;
  83. }
  84. ch = *++lpch;
  85. *lpch = 0;
  86. BSCDebugOut(lpchDBuf);
  87. *lpch = ch;
  88. strcpy(lpchDBuf, lpch);
  89. if (!ch)
  90. lpchDPos = lpchDBuf;
  91. else
  92. lpchDPos = lpchDBuf + strlen(lpchDBuf);
  93. }
  94. }
  95. #endif