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.

213 lines
4.4 KiB

  1. /**********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1987-1999 **/
  4. /**********************************************************************/
  5. /*
  6. lextable.cxx
  7. MIDL Compiler Lexeme Table Implementation
  8. This class centralizes access to allocated strings throughout the
  9. compiler.
  10. */
  11. /*
  12. FILE HISTORY :
  13. DonnaLi 08-23-1990 Created.
  14. */
  15. #pragma warning ( disable : 4514 )
  16. #include "nulldefs.h"
  17. extern "C" {
  18. #include <stdio.h>
  19. #include <malloc.h>
  20. #include <string.h>
  21. }
  22. #include "common.hxx"
  23. #include "lextable.hxx"
  24. /**********************************************************************\
  25. NAME: PrintLexeme
  26. SYNOPSIS: Prints out the name of a lexeme table entry.
  27. ENTRY: key - the key to lexeme table entry to be printed.
  28. EXIT:
  29. NOTES:
  30. HISTORY:
  31. Donnali 08-06-1991 Move to LM/90 UI Coding Style
  32. \**********************************************************************/
  33. void
  34. PrintLexeme(
  35. void * key
  36. )
  37. {
  38. printf ("%s", ((LexKey *)key)->sz);
  39. }
  40. /**********************************************************************\
  41. NAME: CompareLexeme
  42. SYNOPSIS: Compares keys to two lexeme table entries.
  43. ENTRY: key1 - the key to 1st lexeme table entry to be compared.
  44. key2 - the key to 2nd lexeme table entry to be compared.
  45. EXIT: Returns a positive number if key1 > key2.
  46. Returns a negative number if key1 < key2.
  47. Returns 0 if key1 = key2.
  48. NOTES:
  49. HISTORY:
  50. Donnali 08-06-1991 Move to LM/90 UI Coding Style
  51. \**********************************************************************/
  52. int
  53. CompareLexeme(
  54. void * key1,
  55. void * key2
  56. )
  57. {
  58. return(strcmp(((LexKey *)key1)->sz, ((LexKey *)key2)->sz));
  59. }
  60. /**********************************************************************\
  61. NAME: LexTable::LexTable
  62. SYNOPSIS: Constructor.
  63. ENTRY: Allocates memory according to Size.
  64. Passes the compare and print functions to base class.
  65. EXIT:
  66. NOTES:
  67. HISTORY:
  68. Donnali 08-06-1991 Move to LM/90 UI Coding Style
  69. \**********************************************************************/
  70. LexTable::LexTable(
  71. size_t Size,
  72. int (* )(void *, void *),
  73. void (* )(void *)
  74. )
  75. #ifdef unique_lextable
  76. : Dictionary(pfnCompare, pfnPrint)
  77. #endif // unique_lextable
  78. {
  79. BufferSize = Size;
  80. BufferNext = 0;
  81. pBuffer = new char[BufferSize];
  82. }
  83. /**********************************************************************\
  84. NAME: LexTable::LexInsert
  85. SYNOPSIS: Inserts a lexeme into the lexeme table.
  86. ENTRY: psz - the string to be inserted.
  87. EXIT: Returns the string.
  88. NOTES:
  89. HISTORY:
  90. Donnali 08-06-1991 Move to LM/90 UI Coding Style
  91. \**********************************************************************/
  92. char *
  93. LexTable::LexInsert(
  94. char * psz
  95. )
  96. {
  97. char * NewString;
  98. #ifdef unique_lextable
  99. LexKey * NewLexeme;
  100. Dict_Status Status;
  101. SearchKey.SetString(psz);
  102. Status = Dict_Find(&SearchKey);
  103. switch (Status)
  104. {
  105. case EMPTY_DICTIONARY:
  106. case ITEM_NOT_FOUND:
  107. #endif // unique_lextable
  108. if ((BufferSize - BufferNext) <= strlen(psz))
  109. {
  110. BufferSize *= 2;
  111. if ( BufferSize > 32700 )
  112. BufferSize = 32700;
  113. BufferNext = 0;
  114. pBuffer = new char[BufferSize];
  115. }
  116. NewString = (char *)(pBuffer + BufferNext);
  117. (void) strcpy(NewString, psz);
  118. BufferNext += strlen(psz) + 1;
  119. #ifdef unique_lextable
  120. NewLexeme = new LexKey (NewString);
  121. Status = Dict_Insert(NewLexeme);
  122. #endif // unique_lextable
  123. return NewString;
  124. #ifdef unique_lextable
  125. default:
  126. return ((LexKey *)Dict_Curr_Item())->GetString();
  127. }
  128. #endif // unique_lextable
  129. }
  130. /**********************************************************************\
  131. NAME: LexSearch
  132. SYNOPSIS: Searches the lexeme table for a lexeme.
  133. ENTRY: psz - the string to be searched.
  134. EXIT: Returns the string.
  135. NOTES:
  136. HISTORY:
  137. Donnali 08-06-1991 Move to LM/90 UI Coding Style
  138. \**********************************************************************/
  139. char *
  140. LexTable::LexSearch(
  141. char *
  142. )
  143. {
  144. #ifdef unique_lextable
  145. Dict_Status Status;
  146. SearchKey.SetString(psz);
  147. Status = Dict_Find(&SearchKey);
  148. if (Status == SUCCESS)
  149. return ((LexKey *)Dict_Curr_Item())->GetString();
  150. else
  151. #endif // unique_lextable
  152. return (char *)0;
  153. }