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.

112 lines
1.9 KiB

  1. //
  2. // format.c
  3. //
  4. // simple minded printf replacement
  5. //
  6. // only supports %s and %d but it is *small*
  7. //
  8. #include <string.h>
  9. #if defined(OS2)
  10. #define INCL_NOCOMMON
  11. #define INCL_DOSPROCESS
  12. #define INCL_DOSSEMAPHORES
  13. #define INCL_DOSFILEMGR
  14. #define INCL_DOSERRORS
  15. #define INCL_DOSMISC
  16. #include <os2.h>
  17. #else
  18. #include <windows.h>
  19. #endif
  20. #include <dos.h>
  21. #include "hungary.h"
  22. #include "bsc.h"
  23. #include "bscsup.h"
  24. VOID static near pascal _ultoa(DWORD, LSZ);
  25. VOID BSC_API
  26. BSCFormat(LPCH lpchOut, LSZ lszFormat, va_list va)
  27. // format to lpchOut as specified byh format
  28. //
  29. // this is a very simple minded formatter
  30. {
  31. LPCH lpch;
  32. WORD i;
  33. DWORD l;
  34. lpch = lpchOut;
  35. while (*lszFormat) {
  36. if (*lszFormat == '%') {
  37. switch (lszFormat[1]) {
  38. case '%':
  39. *lpch++ = '%';
  40. break;
  41. case 's':
  42. strcpy(lpch, va_arg(va, LSZ));
  43. lpch += strlen(lpch);
  44. break;
  45. case 'd':
  46. i = va_arg(va, WORD);
  47. _ultoa((DWORD)i, lpch);
  48. lpch += strlen(lpch);
  49. break;
  50. case 'l':
  51. l = va_arg(va, DWORD);
  52. _ultoa(l, lpch);
  53. lpch += strlen(lpch);
  54. break;
  55. default:
  56. lpch[0] = '%';
  57. lpch[1] = lszFormat[1];
  58. lpch += 2;
  59. break;
  60. }
  61. lszFormat += 2;
  62. }
  63. else
  64. *lpch++ = *lszFormat++;
  65. }
  66. *lpch = 0;
  67. }
  68. VOID BSC_API
  69. BSCSprintf(LPCH lpchOut, LSZ lszFormat, ...)
  70. // sprintf replacement
  71. //
  72. {
  73. va_list va;
  74. va_start(va, lszFormat);
  75. BSCFormat(lpchOut, lszFormat, va);
  76. }
  77. static DWORD pow10[8] = {
  78. 10L, 100L, 1000L, 10000L,
  79. 100000L , 1000000L, 10000000L, 100000000L
  80. };
  81. VOID static near pascal
  82. _ultoa(DWORD dw, LSZ lsz)
  83. {
  84. int log;
  85. for (log = 0; log < 8; log++)
  86. if (dw < pow10[log])
  87. break;
  88. lsz[++log] = 0;
  89. while (--log >= 0) {
  90. lsz[log] = (char)(((int)(dw%10)) + '0');
  91. dw/=10;
  92. }
  93. }