Source code of Windows XP (NT5)
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.

132 lines
4.3 KiB

  1. /***
  2. *maketabc.c - program to generate printf format specifier lookup table for
  3. * output.c
  4. *
  5. * Copyright (c) 1989-2001, Microsoft Corporation. All rights reserved.
  6. *
  7. *Purpose:
  8. * This program writes to stdout the lookuptable values needed by
  9. * output.c
  10. *
  11. *Revision History:
  12. * 06-01-89 PHG Module created
  13. * 1-16-91 SRW Added extra format codes (_WIN32_)
  14. * 1-16-91 SRW Fixed output loop to put trailing comma on a line
  15. * 03-11-94 GJF Recognize 'I' as size modifier.
  16. * 01-04-95 GJF _WIN32_ -> _WIN32.
  17. * 02-24-95 GJF Don't recognize 'I' for non-Win32 (Mac merge).
  18. * 07-14-96 RDK Allow 'I' for Mac size specifier.
  19. *
  20. *******************************************************************************/
  21. #define TABLESIZE ('x' - ' ' + 1)
  22. /* possible states to be in */
  23. #define NORMAL 0 /* normal character to be output */
  24. #define PERCENT 1 /* just read percent sign */
  25. #define FLAG 2 /* just read a flag character */
  26. #define WIDTH 3 /* just read a width specification character */
  27. #define DOT 4 /* just read a dot between width and precision */
  28. #define PRECIS 5 /* just read a precision specification character */
  29. #define SIZE 6 /* just read a size specification character */
  30. #define TYPE 7 /* just read a conversion specification character */
  31. #define BOGUS 0 /* bogus state - print the character literally */
  32. #define NUMSTATES 8
  33. /* possible types of characters to read */
  34. #define CH_OTHER 0 /* character with no special meaning */
  35. #define CH_PERCENT 1 /* '%' */
  36. #define CH_DOT 2 /* '.' */
  37. #define CH_STAR 3 /* '*' */
  38. #define CH_ZERO 4 /* '0' */
  39. #define CH_DIGIT 5 /* '1'..'9' */
  40. #define CH_FLAG 6 /* ' ', '+', '-', '#' */
  41. #define CH_SIZE 7 /* 'h', 'l', 'L', 'N', 'F' */
  42. #define CH_TYPE 8 /* conversion specified character */
  43. #define NUMCHARS 9
  44. unsigned char table[TABLESIZE]; /* the table we build */
  45. /* this is the state table */
  46. int statetable[NUMSTATES][NUMCHARS] = {
  47. /* state, other % . * 0 digit flag size type */
  48. /* NORMAL */ { NORMAL, PERCENT, NORMAL, NORMAL, NORMAL, NORMAL, NORMAL, NORMAL, NORMAL },
  49. /* PERCENT */ { BOGUS, NORMAL, DOT, WIDTH, FLAG, WIDTH, FLAG, SIZE, TYPE },
  50. /* FLAG */ { BOGUS, BOGUS, DOT, WIDTH, FLAG, WIDTH, FLAG, SIZE, TYPE },
  51. /* WIDTH */ { BOGUS, BOGUS, DOT, BOGUS, WIDTH, WIDTH, BOGUS, SIZE, TYPE },
  52. /* DOT */ { BOGUS, BOGUS, BOGUS, PRECIS, PRECIS, PRECIS, BOGUS, SIZE, TYPE },
  53. /* PRECIS */ { BOGUS, BOGUS, BOGUS, BOGUS, PRECIS, PRECIS, BOGUS, SIZE, TYPE },
  54. /* SIZE */ { BOGUS, BOGUS, BOGUS, BOGUS, BOGUS, BOGUS, BOGUS, SIZE, TYPE },
  55. /* TYPE */ { NORMAL, PERCENT, NORMAL, NORMAL, NORMAL, NORMAL, NORMAL, NORMAL, NORMAL }
  56. };
  57. /* this determines what type of character ch is */
  58. static int chartype (
  59. int ch
  60. )
  61. {
  62. if (ch < ' ' || ch > 'z')
  63. return CH_OTHER;
  64. if (ch == '%')
  65. return CH_PERCENT;
  66. if (ch == '.')
  67. return CH_DOT;
  68. if (ch == '*')
  69. return CH_STAR;
  70. if (ch == '0')
  71. return CH_ZERO;
  72. if (strchr("123456789", ch))
  73. return CH_DIGIT;
  74. if (strchr(" +-#", ch))
  75. return CH_FLAG;
  76. if (strchr("hIlLNF", ch))
  77. return CH_SIZE;
  78. if (strchr("diouxXfeEgGcspn", ch))
  79. return CH_TYPE;
  80. #ifdef _WIN32
  81. /* Win32 supports three additional format codes for debugging purposes */
  82. if (strchr("BCS", ch))
  83. return CH_TYPE;
  84. #endif /* _WIN32 */
  85. return CH_OTHER;
  86. }
  87. main()
  88. {
  89. int ch;
  90. int state, class;
  91. int i;
  92. for (ch = ' '; ch <= 'x'; ++ch) {
  93. table[ch-' '] = chartype(ch);
  94. }
  95. for (state = NORMAL; state <= TYPE; ++state)
  96. for (class = CH_OTHER; class <= CH_TYPE; ++class)
  97. table[class*8+state] |= statetable[state][class]<<4;
  98. for (i = 0; i < TABLESIZE; ++i) {
  99. if (i % 8 == 0) {
  100. if (i != 0)
  101. printf(",");
  102. printf("\n\t 0x%.2X", table[i]);
  103. }
  104. else
  105. printf(", 0x%.2X", table[i]);
  106. }
  107. printf("\n");
  108. return 0;
  109. }