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.

176 lines
4.8 KiB

  1. /* A little program to combinatorialy generate some .idl */
  2. #include "windows.h"
  3. #include <stdio.h>
  4. #undef INTERFACE
  5. #undef UuidToString
  6. #define NUMBER_OF(x) (sizeof(x)/sizeof((x)[0]))
  7. #define DUAL (0x001)
  8. #define OBJECT (0x002)
  9. #define OLEAUTOMATION (0x004)
  10. #define BRACES (0x008)
  11. #define DISPINTERFACE (0x010)
  12. #define BASE_NONE (0x020)
  13. #define BASE_IUNKNOWN (0x040)
  14. #define BASE_IDISPATCH (0x080)
  15. #define FUNCTION (0x100)
  16. #define NUM (0x200)
  17. void UuidToString(const UUID * Uuid, char * s)
  18. {
  19. sprintf(s, "%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", Uuid->Data1, Uuid->Data2, Uuid->Data3, Uuid->Data4[0], Uuid->Data4[1], Uuid->Data4[2], Uuid->Data4[3], Uuid->Data4[4], Uuid->Data4[5], Uuid->Data4[6], Uuid->Data4[7]);
  20. }
  21. typedef struct INTERFACE
  22. {
  23. UUID InterfaceId;
  24. CLSID ClassId;
  25. } INTERFACE;
  26. void strcatf(char * s, const char * format, ...)
  27. {
  28. va_list args;
  29. va_start(args, format);
  30. s += strlen(s);
  31. vsprintf(s, format, args);
  32. va_end(args);
  33. }
  34. void Identifierize(char * s)
  35. {
  36. int ch;
  37. for ( ; ch = *s ; ++s )
  38. {
  39. if (ch >= 'a' && ch <= 'z')
  40. continue;
  41. if (ch >= 'A' && ch <= 'Z')
  42. continue;
  43. if (ch >= '0' && ch <= '9')
  44. continue;
  45. if (ch == '_')
  46. continue;
  47. *s = '_';
  48. }
  49. }
  50. BOOL IsValid(ULONG i)
  51. {
  52. switch (i & (BASE_NONE | BASE_IUNKNOWN | BASE_IDISPATCH))
  53. {
  54. case BASE_NONE:
  55. case BASE_IUNKNOWN:
  56. case BASE_IDISPATCH:
  57. break;
  58. default:
  59. return FALSE;
  60. }
  61. if ((i & FUNCTION) && (i & BRACES) == 0)
  62. return FALSE;
  63. //if (i & (BASE_IUNKNOWN|BASE_IDISPATCH))
  64. // return FALSE;
  65. if ((i & BASE_IUNKNOWN) && (i & DISPINTERFACE))
  66. return FALSE;
  67. if ((i & BASE_IDISPATCH) && (i & DISPINTERFACE))
  68. return FALSE;
  69. if ((i & BASE_NONE) && (i & OBJECT))
  70. return FALSE;
  71. if ((i & DUAL) && (i & DISPINTERFACE))
  72. return FALSE;
  73. if ((i & OLEAUTOMATION) && (i & DISPINTERFACE))
  74. return FALSE;
  75. // unsatisfied forward declaration
  76. if ((i & BRACES) == 0)
  77. return FALSE;
  78. return TRUE;
  79. }
  80. void IdlGen()
  81. {
  82. ULONG i;
  83. char IdlBuffer[1UL<<16];
  84. INTERFACE Interfaces[NUM];
  85. INTERFACE * Interface;
  86. char UuidStringBuffer[64];
  87. UUID LibraryId;
  88. char LibraryIdStringBuffer[64];
  89. char IdentifierizedLibraryIdStringBuffer[64];
  90. IdlBuffer[0] = 0;
  91. strcatf(IdlBuffer,
  92. "import \"oaidl.idl\";\n"
  93. );
  94. UuidCreate(&LibraryId);
  95. UuidToString(&LibraryId, LibraryIdStringBuffer);
  96. strcpy(IdentifierizedLibraryIdStringBuffer, LibraryIdStringBuffer);
  97. Identifierize(IdentifierizedLibraryIdStringBuffer);
  98. for ( i = 0 ; i != NUMBER_OF(Interfaces) ; ++i)
  99. {
  100. char Function[1024];
  101. if (!IsValid(i))
  102. continue;
  103. UuidCreate(&Interfaces[i].InterfaceId);
  104. UuidCreate(&Interfaces[i].ClassId);
  105. UuidToString(&Interfaces[i].InterfaceId, UuidStringBuffer);
  106. Function[0] = 0;
  107. if (i & FUNCTION)
  108. sprintf(
  109. Function,
  110. "%sHRESULT Foo_0x%x([in] const char * s, [out] int * i);",
  111. (i & DISPINTERFACE) ? "properties: methods:[id(0)]" : "",
  112. i
  113. );
  114. strcatf(IdlBuffer, "[ %s%s%suuid(%s)] %sinterface ISxsTest_IdlGen_0x%x%s%s%s%s;\n",
  115. (i & DUAL) ? "dual," : " ",
  116. (i & OBJECT) ? "object,": " ",
  117. (i & OLEAUTOMATION) ? "oleautomation," : " ",
  118. UuidStringBuffer,
  119. (i & DISPINTERFACE) ? "disp" : " ",
  120. i,
  121. (i & BASE_IUNKNOWN) ? ":IUnknown" : (i & BASE_IDISPATCH) ? ":IDispatch" : "",
  122. (i & BRACES) ? "{" : "",
  123. Function,
  124. (i & BRACES) ? "}" : ""
  125. );
  126. }
  127. strcatf(IdlBuffer,
  128. "[uuid(%s)]library SxsTest_IdlGen_%s\n{\n"
  129. "importlib(\"stdole32.tlb\");\n"
  130. "importlib(\"stdole2.tlb\");\n",
  131. LibraryIdStringBuffer,
  132. IdentifierizedLibraryIdStringBuffer
  133. );
  134. for ( i = 0 ; i != NUMBER_OF(Interfaces) ; ++i)
  135. {
  136. if (!IsValid(i))
  137. continue;
  138. UuidToString(&Interfaces[i].ClassId, UuidStringBuffer);
  139. strcatf(IdlBuffer, "[uuid(%s)]coclass CSxsTest_IdlGen_0x%x {[default] interface ISxsTest_IdlGen_0x%x;};\n",
  140. UuidStringBuffer, i, i);
  141. }
  142. strcatf(IdlBuffer, "};\n");
  143. printf("%s\n", IdlBuffer);
  144. }
  145. int __cdecl main()
  146. {
  147. IdlGen();
  148. return 0;
  149. }