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.

368 lines
14 KiB

  1. pushdef(_prediv,divnum)divert(-1)dnl Redirect output to /dev/null for now
  2. changecom(`|')
  3. |------------------------------------------------------------------
  4. | _upcase: Convert argument to upper case
  5. | $1: String to convert to upcase
  6. define(`_upcase',
  7. `translit(`$1', `abcdefghijklmnopqrstuvwxyz',
  8. `ABCDEFGHIJKLMNOPQRSTUVWXYZ')')dnl
  9. |------------------------------------------------------------------
  10. | For loop definitions, stolen from m4 doc page
  11. | forloop(`i', 1, 8, `i ') =>1 2 3 4 5 6 7 8
  12. |
  13. define(`forloop',`ifelse(eval($2>$3),1,,`pushdef(`$1', `$2')_forloop(`$1', `$2', `$3', `$4')popdef(`$1')')')
  14. define(`_forloop',`$4`'ifelse($1, `$3', ,`define(`$1', incr($1))_forloop(`$1', `$2', `$3', `$4')')')
  15. |------------------------------------------------------------------
  16. | _Next(`a', a) increments `a' by 1.
  17. |
  18. define(`_Next', `define(`$1',`eval($2+1)')')
  19. |------------------------------------------------------------------
  20. | _Ws: Adds l1 characters of white space.
  21. | _Ws(l1) => " ",
  22. | where len(" ")=l1.
  23. |
  24. define(`_Ws1',`forloop(`i',0,$1,` ')')
  25. define(`_Ws', `_Ws1(eval(($1)*eval(($1)>1)))') dnl
  26. |------------------------------------------------------------------
  27. | _Cntr Center a string
  28. | _Cntr(String, Length) => " String "
  29. |
  30. define(`_Cntr', `_Ws(($2-len($1))/2)' `$1' `_Ws(($2-len($1))/2)')dnl
  31. |------------------------------------------------------------------
  32. | _fmt(X) => "X " where len=45
  33. |
  34. define(`_fmt', ``$1'_Ws(45-len($1))')dnl
  35. |------------------------------------------------------------------
  36. | Spit out hex formatted variable
  37. | This implementation of M4 insists on giving me -ve numbers if the MSB is set to 1.
  38. | Spit out the hi and low word with appropriate shifts and masks
  39. |
  40. define(`_msw', `eval((`$1'>>16)&0xffff,16,4)')
  41. define(`_lsw', `eval(`$1'&0xffff,16,4)')
  42. define(`_hexout',`0x`'_msw(eval(`$1'))`'_lsw(eval(`$1'))')
  43. |------------------------------------------------------------------
  44. | Capitalize a string
  45. |
  46. define(`_Capitalize',`_upcase(substr($1,0,1))`'substr($1,1,len($1)-1)')dnl
  47. |------------------------------------------------------------------
  48. | Spit out a C macro #define
  49. |
  50. define(`_CMacroDef',``#'_fmt(define $1) $2')
  51. |------------------------------------------------------------------
  52. | Spit out a C value define
  53. |
  54. define(`_C1Define',``#'_fmt(define $1) $2')
  55. define(`_C2Define',``#'_fmt(define $1) $2 /* $3 */')
  56. |
  57. | $1: Text
  58. | $2: Value
  59. | $3: Comment
  60. define(`_CDefine',`ifelse($3,`',_C1Define($1,$2), _C2Define($1,$2,$3))')
  61. |
  62. | $1: Text
  63. | $2: Value
  64. | $3: Comment
  65. | $4: Additional Flags that need to be ORed in with the value.
  66. |
  67. define(`_CPDefine',`ifelse($4,`',_C1Define($1,$2,$3), _C2Define($1,`($2 |$4)',$3))')
  68. |
  69. |------------------------------------------------------------------
  70. | Formatted C Comment from string
  71. |
  72. define(`_CComment', `/*--- _fmt($1) ---*/')
  73. |------------------------------------------------------------------
  74. | _CDefGenre: Format the genre defines for C
  75. | $1: Genre text name
  76. | $2: Genre code
  77. | $3: Short Name
  78. | $4: Description
  79. |
  80. define(`_CDefGenre', `_CDefine($1, $2,`' )'
  81. `;begin_internal'
  82. `/* @doc EXTERNAL '
  83. ` * @Semantics $3 | '
  84. ` * @normal Genre: <c eval(_THISGENRE,10,2) >'
  85. ` */ '
  86. `;end_internal'
  87. )
  88. |------------------------------------------------------------------
  89. | _CDefAxs
  90. | $1: Text: DIAXIS_
  91. | $2: Semantic name
  92. | $3: Text description
  93. | $4: Axis Index
  94. | $5: Semantic
  95. define(`_CDefAxs', `_CDefine($1_$2,$5,$3)'
  96. ` /* @normal <c $1_$2>:$5 ;internal'
  97. ` * $3 */;internal')
  98. |------------------------------------------------------------------
  99. | _CDefBtn
  100. | $1: Text DIBUTTON
  101. | $2: Semantic name
  102. | $3: Text description
  103. | $4: Axis Index
  104. | $5: Semantic
  105. define(`_CDefBtn', `_CDefine($1_$2,$5,$3)'
  106. ` /* @normal <c $1_$2>:$5 ;internal'
  107. ` * $3 */;internal')
  108. |------------------------------------------------------------------
  109. | _CDefPov
  110. | $1: Text DIPOV
  111. | $2: Semantic name
  112. | $3: Text description
  113. | $4: Axis Index
  114. | $5: Semantic
  115. define(`_CDefPov', `_CDefine($1_$2,$5,$3)'
  116. ` /* @normal <c $1_$2>:$5 ;internal'
  117. ` * $3 */;internal')
  118. |------------------------------------------------------------------
  119. |
  120. | _Mask: Create a mask, by specifying bitsz and offset.
  121. | $1: Number of bits
  122. | $2: Where does it start
  123. define(`_Mask',`_hexout(eval((2**(`$1')-1)<<`$2'))') dnl
  124. |
  125. |------------------------------------------------------------------
  126. | _Bits1 helper for _Bits
  127. | $1: Name
  128. | $2: Starts at bit offset
  129. | $3: Bitmask
  130. | Define m4 and C macros in order to get and set values
  131. | and C defines for each bitmask and shift value
  132. |
  133. define(`_1Bits',
  134. `_CMacroDef(DISEM_$1_SET(x), ( ( (BYTE)(x)<<$2 ) & $3 ))' dnl
  135. `pushdef(`_Set$1',`ifelse( eval((_$1<<$2 ) & $3 ),eval(_$1<<$2),_hexout((_$1<<$2) & $3 ), ($1:_$1<<$2)&$3)')'
  136. `_CMacroDef(DISEM_$1_GET(x), ((BYTE)( ( (x) & $3 )>>$2 )))' dnl
  137. `pushdef(`_Get$1', `eval( (_$1 & $3 ) >>$2 ) ')'
  138. `_CMacroDef(DISEM_$1_MASK, ( $3 ))'
  139. `_CMacroDef(DISEM_$1_SHIFT, ( $2 ))' )
  140. |
  141. |------------------------------------------------------------------
  142. | _Bits Define a bitfield
  143. | $1: Name
  144. | $2: Starts at bit offset
  145. | $3: Bitmask
  146. define(`_Bits', `_1Bits(_upcase($1), $2, $3)')
  147. |
  148. |------------------------------------------------------------------
  149. | _Value1: helper for Value()
  150. | $1: Type1
  151. | $2: Type2
  152. | $3: Value
  153. define(`_1Value',`define(`_$1_$2', `$3')'dnl
  154. `define(`_$1',$3)'dnl
  155. `_CDefine(DISEM_$1_$2, _Set$1,`')')dnl
  156. |------------------------------------------------------------------
  157. | _Value: Define a value dependent on "_Bits()" already defined
  158. | $1: Type1
  159. | $2: Type2
  160. | $3: Value
  161. |define(`_Value', `_1Value(_upcase($1),_upcase($2),$3)')dnl
  162. |------------------------------------------------------------------
  163. | _Semantic() Define a semantic value
  164. | $1: Genre#
  165. | $2: Control priority
  166. | $3: Flags (xaxis, etc ..)
  167. | $4: Control type (button, axis, pov)
  168. | $5: Group#
  169. | $6: Control Index
  170. define(`_Semantic',`define(`_GENRE', `eval($1)')'dnl
  171. `define(`_PRI', `eval($2)')'dnl
  172. `define(`_FLAGS', `eval($3)')'dnl
  173. `define(`_TYPE', `eval($4)')'dnl
  174. `define(`_GROUP', `eval($5)')'dnl
  175. `define(`_INDEX', `eval($6)')'dnl
  176. `_hexout( _SetPHYSICAL | _SetGENRE | _SetFLAGS | _SetPRI | _SetREL | _SetTYPE | _SetGROUP | _SetINDEX )')dnl
  177. |
  178. |------------------------------------------------------------------
  179. | _Axis1: Axis semantic helper
  180. | $1: Flags defining which axis
  181. | $2: Semantic longer name
  182. | $3: Group#
  183. | $4: Text desciption
  184. define(`_1Axis', `_CDefAxs(DIAXIS,$2,$4,_NAXS,
  185. _Semantic(`_THISGENRE', `_THISPRI', $1, `_TYPE_AXIS',$3, _NAXS))' )dnl
  186. |
  187. |------------------------------------------------------------------
  188. | _Axis Define next available axis semantic
  189. | $1: Which axis (X,Y,Z,R,U,V,A,B,C,S) ?
  190. | $2: Semantic short name
  191. | $3: Group#
  192. | $4: Text description
  193. define(`_Axis', `_Next(`_NAXS',_NAXS)'dnl
  194. `_1Axis(_FLAGS_$1,_upcase(_SzSub`_$2'), $3, $4)' )dnl
  195. |------------------------------------------------------------------
  196. | _PAxis: Define axis for a physical device
  197. | $1: Which axis (X,Y,Z,R,U,V,A,B,C,S) ?
  198. | $2: Semantic short name
  199. | $3: Group#
  200. | $4: Text description
  201. | $5: Offset ( DIMOFS_*)
  202. define(`_PAxis',`_CPDefine(`DI'_upcase(_SzSub`_$2'),_Semantic(`_THISGENRE', `_THISPRI', 0x0, `_TYPE_AXIS',$3, 0x0),$4,$5)')
  203. |
  204. |------------------------------------------------------------------
  205. | _1Button: Button semantic helper
  206. | $1: Control Index #
  207. | $2: Semantic Long name
  208. | $3: Group#
  209. | $4: Text description
  210. | $5: Flags to control fallback axis/pov type
  211. define(`_1Button', `_CDefBtn(DIBUTTON,$2,$4,_NBTN,
  212. _Semantic(`_THISGENRE', `_THISPRI', $5, `_TYPE_BUTTON',$3, $1))')
  213. |
  214. |------------------------------------------------------------------
  215. | _Button: Define next available button semantic
  216. | $1: Semantic short Name
  217. | $2: Group#
  218. | $3: Text description
  219. define(`_Button',`_Next(`_NBTN',_NBTN)'dnl
  220. `_1Button(_NBTN,_upcase(_SzSub`_$1'), $2, $3, 0x0)' )dnl
  221. |
  222. |------------------------------------------------------------------
  223. | _ButtonN: Defines a numbered button
  224. | $1: Control Index # ( Use predefined values BUTTON_*)
  225. | $2: Semantic short name
  226. | $3: Group#
  227. | $4: Text description
  228. define(`_ButtonN',`_1Button($1,_upcase(_SzSub`_$2'), $3, $4, 0x0)' )
  229. |------------------------------------------------------------------
  230. | _ButtonF Fallback buttons for axes and povs
  231. | $1: Flags to define fallback type axis(X,Y,Z,...) or pov(P)
  232. | $2: Control Index # ( use defines value BUTTON_*)
  233. | $3: Semantic short name
  234. | $4: Group#
  235. | $5: Text description
  236. define(`_ButtonF',`_1Button($2,_upcase(_SzSub`_$3')`_LINK', $4, $5, _FLAGS_$1)' )
  237. |
  238. |------------------------------------------------------------------
  239. | _PButtonN: Defines a numbered button for a physical device
  240. | $1: Control Index #
  241. | $2: Semantic short name
  242. | $3: Group#
  243. | $4: Text description
  244. | $5: Offset (DIMOFS_* )
  245. define(`_PButtonN',`_CPDefine(`DI'_upcase(_SzSub`_$2'),_Semantic(`_THISGENRE', `_THISPRI', 0x0, `_TYPE_BUTTON',$3, $1),$4,$5)')dnl
  246. |------------------------------------------------------------------
  247. | _1Pov: hatswitch semantic helper
  248. | $1: Control Index #
  249. | $2: Semantic long Name
  250. | $3: Group#
  251. | $4: Text description
  252. define(`_1Pov', `_CDefPov(DIHATSWITCH,$2,$4, _NPOV,
  253. _Semantic(_THISGENRE, _THISPRI, 0x0, _TYPE_POV,$3, $1))') dnl
  254. |
  255. |------------------------------------------------------------------
  256. | _Pov: Defines a hatswitch semantic
  257. | $1: Semantic short Name
  258. | $2: Group#
  259. | $3: Text description
  260. |
  261. define(`_Pov',`_Next(`_NPOV',_NPOV)'dnl
  262. `_1Pov(_NPOV,_upcase(_SzSub`_$1'), $2, $3)' )dnl
  263. |
  264. |------------------------------------------------------------------
  265. | _BeginPhysical: Physical device defination
  266. | $1: Genre text name
  267. | $2: Shortcut genre text name
  268. | $3: Short description of genre
  269. | $4: Verbose desciption of genre
  270. define(`_BeginPhysical',`_Next(`_PGENRE', _PGENRE)'dnl
  271. `define(`_PHYSICAL',1)'dnl
  272. `define(`_THISPRI',0)'dnl
  273. `define(`_SzSub',`$2')'dnl
  274. `define(`_NAXS',0x0)'dnl
  275. `define(`_NBTN',0x0)'dnl
  276. `define(`_NPOV',0x0)'dnl
  277. `_CComment($3
  278. $4,40)'
  279. `define(`_THISGENRE',_PGENRE)'
  280. `;begin_internal'
  281. `_CDefGenre(DIPHYSICAL_$1, `_Semantic(_THISGENRE,0,0,0,0,0)', $3, $4)'
  282. `;end_internal')dnl
  283. |------------------------------------------------------------------
  284. | _BeginGenre: Start a new genre
  285. | $1: Genre text name
  286. | $2: Shortcut genre text name
  287. | $3: Short description of genre
  288. | $4: Verbose desciption of genre
  289. define(`_BeginGenre',`_Next(`_VGENRE', _VGENRE)'dnl
  290. `define(`_PHYSICAL',0)'dnl
  291. `define(`_THISPRI',0)'dnl
  292. `define(`_SzSub',`$2')'dnl
  293. `define(`_NAXS',0x0)'dnl
  294. `define(`_NBTN',0x0)'dnl
  295. `define(`_NPOV',0x0)'dnl
  296. `_CComment($3
  297. $4,40)'
  298. `define(`_THISGENRE',_VGENRE)'dnl
  299. `_CDefGenre(DIVIRTUAL_$1, `_Semantic(_THISGENRE,0,0,0,0,0)', $3, $4)' )dnl
  300. |------------------------------------------------------------------
  301. | _Priority2 semantics
  302. |
  303. define(`_Priority2',`_ButtonN(BUTTON_MENU,MENU, 0, Show menu options)'
  304. `_CComment(Priority 2 controls)'
  305. `;begin_internal'
  306. `_CComment(@normal <c Priority2 Commands>)'
  307. `;end_internal'
  308. `define(`_THISPRI',1)'dnl
  309. )
  310. |
  311. |------------------------------------------------------------------
  312. | _EndGenre: End of a genre.
  313. |
  314. define(`_EndGenre',`_ButtonN(BUTTON_DEVICE, DEVICE, 0, Show input device and controls)'
  315. `_ButtonN(BUTTON_PAUSE,PAUSE, 0, Start / Pause / Restart game)')dnl
  316. |
  317. |------------------------------------------------------------------
  318. | _EndPhysical: End of a genre.
  319. |
  320. define(`_EndPhysical',`')dnl
  321. |
  322. |------------------------------------------------------------------
  323. | _devType: Given a string for the abbreviated device type "Wheel, Joystick",
  324. | generate the string "DI8DEVTYPE_WHEEL, DI8DEVTYPE_JOYSTICK"
  325. |
  326. define(`_devType', `DI8DEVTYPE_`'_upcase($1),' `ifelse($#, 1, , `_devType(shift($*))')')
  327. |
  328. |------------------------------------------------------------------
  329. | _Device: List the best devices for each genre.
  330. |
  331. define(`_Device', `;begin_internal'
  332. ``#'define DISEM_DEFAULTDEVICE_`'_THISGENRE {' dnl
  333. `_devType($*)' `}'
  334. `;end_internal')
  335. |
  336. |------------------------------------------------------------------
  337. | _EndFile: Once all genres are defined, need to generate an array of
  338. | "best" devices for each genre. This is a part of dinputp.h
  339. | and is appropriately marked as internal.
  340. |
  341. define(`_EndFile',`;begin_internal'
  342. ``#'if (DIRECTINPUT_VERSION >= 0x0800)'
  343. ``#'define DISEM_MAX_GENRE _THISGENRE'
  344. `static const BYTE DiGenreDeviceOrder[DISEM_MAX_GENRE][DI8DEVTYPE_MAX-DI8DEVTYPE_MIN]={'
  345. `forloop(i,1,_THISGENRE,`DISEM_DEFAULTDEVICE_`'i,
  346. ')'
  347. `};'
  348. ``#'endif'
  349. `;end_internal')
  350. |
  351. |------------------------------------------------------------------
  352. | _InitSemantics: Initialize global m4 variables.
  353. |
  354. define(`_InitSemantics', `define(`_THISGENRE', 0)' dnl
  355. `define(`_THISPRI', 0)' dnl
  356. `define(`_NAXS', 0)' dnl
  357. `define(`_NBTN', 0)' dnl
  358. `define(`_NPOV', 0)' dnl
  359. `define(`_PGENRE', 0)' dnl
  360. `define(`_PHYSICAL', 1)' dnl
  361. `define(`_VGENRE', 0)' dnl
  362. `define(`_REL', 0)' dnl
  363. )
  364. _InitSemantics
  365. changecom()
  366. divert(_prediv)popdef(`_prediv')dnl End of macro header file