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.

101 lines
3.1 KiB

  1. /* make the lookup table for output.asm */
  2. #define TABLESIZE ('x' - ' ' + 1)
  3. /* possible states to be in */
  4. #define NORMAL 0 /* normal character to be output */
  5. #define PERCENT 1 /* just read percent sign */
  6. #define FLAG 2 /* just read a flag character */
  7. #define WIDTH 3 /* just read a width specification character */
  8. #define DOT 4 /* just read a dot between width and precision */
  9. #define PRECIS 5 /* just read a precision specification character */
  10. #define SIZE 6 /* just read a size specification character */
  11. #define TYPE 7 /* just read a conversion specification character */
  12. #define BOGUS 0 /* bogus state - print the character literally */
  13. #define NUMSTATES 8
  14. /* possible types of characters to read */
  15. #define CH_OTHER 0 /* character with no special meaning */
  16. #define CH_PERCENT 1 /* '%' */
  17. #define CH_DOT 2 /* '.' */
  18. #define CH_STAR 3 /* '*' */
  19. #define CH_ZERO 4 /* '0' */
  20. #define CH_DIGIT 5 /* '1'..'9' */
  21. #define CH_FLAG 6 /* ' ', '+', '-', '#' */
  22. #define CH_SIZE 7 /* 'h', 'l', 'L', 'N', 'F', 'w' */
  23. #define CH_TYPE 8 /* conversion specified character */
  24. #define NUMCHARS 9
  25. unsigned char table[TABLESIZE]; /* the table we build */
  26. /* this is the state table */
  27. int statetable[NUMSTATES][NUMCHARS] = {
  28. /* state, other % . * 0 digit flag size type */
  29. /* NORMAL */ { NORMAL, PERCENT, NORMAL, NORMAL, NORMAL, NORMAL, NORMAL, NORMAL, NORMAL },
  30. /* PERCENT */ { BOGUS, NORMAL, DOT, WIDTH, FLAG, WIDTH, FLAG, SIZE, TYPE },
  31. /* FLAG */ { BOGUS, BOGUS, DOT, WIDTH, FLAG, WIDTH, FLAG, SIZE, TYPE },
  32. /* WIDTH */ { BOGUS, BOGUS, DOT, BOGUS, WIDTH, WIDTH, BOGUS, SIZE, TYPE },
  33. /* DOT */ { BOGUS, BOGUS, BOGUS, PRECIS, PRECIS, PRECIS, BOGUS, SIZE, TYPE },
  34. /* PRECIS */ { BOGUS, BOGUS, BOGUS, BOGUS, PRECIS, PRECIS, BOGUS, SIZE, TYPE },
  35. /* SIZE */ { BOGUS, BOGUS, BOGUS, BOGUS, BOGUS, BOGUS, BOGUS, SIZE, TYPE },
  36. /* TYPE */ { NORMAL, PERCENT, NORMAL, NORMAL, NORMAL, NORMAL, NORMAL, NORMAL, NORMAL }
  37. };
  38. /* this determines what type of character ch is */
  39. static int chartype (
  40. int ch
  41. )
  42. {
  43. if (ch < ' ' || ch > 'z')
  44. return CH_OTHER;
  45. if (ch == '%')
  46. return CH_PERCENT;
  47. if (ch == '.')
  48. return CH_DOT;
  49. if (ch == '*')
  50. return CH_STAR;
  51. if (ch == '0')
  52. return CH_ZERO;
  53. if (strchr("123456789", ch))
  54. return CH_DIGIT;
  55. if (strchr(" +-#", ch))
  56. return CH_FLAG;
  57. if (strchr("hlLNFw", ch))
  58. return CH_SIZE;
  59. if (strchr("diouxXfeEgGcspnCSZ", ch))
  60. return CH_TYPE;
  61. return CH_OTHER;
  62. }
  63. main()
  64. {
  65. int ch;
  66. int state, class;
  67. int i;
  68. for (ch = ' '; ch <= 'x'; ++ch) {
  69. table[ch-' '] = chartype(ch);
  70. }
  71. for (state = NORMAL; state <= TYPE; ++state)
  72. for (class = CH_OTHER; class <= CH_TYPE; ++class)
  73. table[class*8+state] |= statetable[state][class]<<4;
  74. for (i = 0; i < TABLESIZE; ++i) {
  75. if (i % 8 == 0)
  76. printf("\ndb\t %.2xh", table[i]);
  77. else
  78. printf(", %.2xh", table[i]);
  79. }
  80. return 0;
  81. }