Team Fortress 2 Source Code as on 22/4/2020
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.

579 lines
14 KiB

  1. /*
  2. File: AEHelpers.h
  3. Contains: AEPrint, AEBuild and AEStream for Carbon
  4. Version: QuickTime 7.3
  5. Copyright: (c) 2007 (c) 1999-2001 by Apple Computer, Inc., all rights reserved.
  6. Bugs?: For bug reports, consult the following page on
  7. the World Wide Web:
  8. http://developer.apple.com/bugreporter/
  9. */
  10. /*
  11. * Originally from AEGIzmos by Jens Alfke, circa 1992.
  12. */
  13. #ifndef __AEHELPERS__
  14. #define __AEHELPERS__
  15. #ifndef __APPLEEVENTS__
  16. #include <AppleEvents.h>
  17. #endif
  18. #ifndef __AEDATAMODEL__
  19. #include <AEDataModel.h>
  20. #endif
  21. #include <stdarg.h>
  22. #if PRAGMA_ONCE
  23. #pragma once
  24. #endif
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. #if PRAGMA_IMPORT
  29. #pragma import on
  30. #endif
  31. #if PRAGMA_STRUCT_ALIGN
  32. #pragma options align=mac68k
  33. #elif PRAGMA_STRUCT_PACKPUSH
  34. #pragma pack(push, 2)
  35. #elif PRAGMA_STRUCT_PACK
  36. #pragma pack(2)
  37. #endif
  38. /*
  39. * AEBuild:
  40. *
  41. * AEBuild provides a very high level abstraction for building
  42. * complete AppleEvents and complex ObjectSpeciers. Using AEBuild it
  43. * is easy to produce a textual representation of an AEDesc. The
  44. * format is similar to the stdio printf call, where meta data is
  45. * extracted from a format string and used to build the final
  46. * representation.
  47. *
  48. * The structure of the format string is described here:
  49. *
  50. * < describe it >
  51. */
  52. /* Syntax Error Codes: */
  53. typedef UInt32 AEBuildErrorCode;
  54. enum {
  55. aeBuildSyntaxNoErr = 0, /* (No error) */
  56. aeBuildSyntaxBadToken = 1, /* Illegal character */
  57. aeBuildSyntaxBadEOF = 2, /* Unexpected end of format string */
  58. aeBuildSyntaxNoEOF = 3, /* Unexpected extra stuff past end */
  59. aeBuildSyntaxBadNegative = 4, /* "-" not followed by digits */
  60. aeBuildSyntaxMissingQuote = 5, /* Missing close "'" */
  61. aeBuildSyntaxBadHex = 6, /* Non-digit in hex string */
  62. aeBuildSyntaxOddHex = 7, /* Odd # of hex digits */
  63. aeBuildSyntaxNoCloseHex = 8, /* Missing "." */
  64. aeBuildSyntaxUncoercedHex = 9, /* Hex string must be coerced to a type */
  65. aeBuildSyntaxNoCloseString = 10, /* Missing """ */
  66. aeBuildSyntaxBadDesc = 11, /* Illegal descriptor */
  67. aeBuildSyntaxBadData = 12, /* Bad data value inside (...) */
  68. aeBuildSyntaxNoCloseParen = 13, /* Missing ")" after data value */
  69. aeBuildSyntaxNoCloseBracket = 14, /* Expected "," or "]" */
  70. aeBuildSyntaxNoCloseBrace = 15, /* Expected "," or "}" */
  71. aeBuildSyntaxNoKey = 16, /* Missing keyword in record */
  72. aeBuildSyntaxNoColon = 17, /* Missing ":" after keyword in record */
  73. aeBuildSyntaxCoercedList = 18, /* Cannot coerce a list */
  74. aeBuildSyntaxUncoercedDoubleAt = 19 /* "@@" substitution must be coerced */
  75. };
  76. /* A structure containing error state.*/
  77. struct AEBuildError {
  78. AEBuildErrorCode fError;
  79. UInt32 fErrorPos;
  80. };
  81. typedef struct AEBuildError AEBuildError;
  82. /*
  83. Create an AEDesc from the format string. AEBuildError can be NULL, in which case
  84. no explicit error information will be returned.
  85. */
  86. /*
  87. * AEBuildDesc()
  88. *
  89. * Availability:
  90. * Non-Carbon CFM: not available
  91. * CarbonLib: in CarbonLib 1.1 and later
  92. * Mac OS X: in version 10.0 and later
  93. */
  94. EXTERN_API_C( OSStatus )
  95. AEBuildDesc(
  96. AEDesc * dst,
  97. AEBuildError * error, /* can be NULL */
  98. const char * src,
  99. ...);
  100. /* varargs version of AEBuildDesc*/
  101. /*
  102. * vAEBuildDesc()
  103. *
  104. * Availability:
  105. * Non-Carbon CFM: not available
  106. * CarbonLib: in CarbonLib 1.1 and later
  107. * Mac OS X: in version 10.0 and later
  108. */
  109. EXTERN_API_C( OSStatus )
  110. vAEBuildDesc(
  111. AEDesc * dst,
  112. AEBuildError * error, /* can be NULL */
  113. const char * src,
  114. va_list args);
  115. /* Append parameters to an existing AppleEvent*/
  116. /*
  117. * AEBuildParameters()
  118. *
  119. * Availability:
  120. * Non-Carbon CFM: not available
  121. * CarbonLib: in CarbonLib 1.1 and later
  122. * Mac OS X: in version 10.0 and later
  123. */
  124. EXTERN_API_C( OSStatus )
  125. AEBuildParameters(
  126. AppleEvent * event,
  127. AEBuildError * error, /* can be NULL */
  128. const char * format,
  129. ...);
  130. /* varargs version of AEBuildParameters*/
  131. /*
  132. * vAEBuildParameters()
  133. *
  134. * Availability:
  135. * Non-Carbon CFM: not available
  136. * CarbonLib: in CarbonLib 1.1 and later
  137. * Mac OS X: in version 10.0 and later
  138. */
  139. EXTERN_API_C( OSStatus )
  140. vAEBuildParameters(
  141. AppleEvent * event,
  142. AEBuildError * error, /* can be NULL */
  143. const char * format,
  144. va_list args);
  145. /* Building an entire Apple event:*/
  146. /*
  147. * AEBuildAppleEvent()
  148. *
  149. * Availability:
  150. * Non-Carbon CFM: not available
  151. * CarbonLib: in CarbonLib 1.1 and later
  152. * Mac OS X: in version 10.0 and later
  153. */
  154. EXTERN_API_C( OSStatus )
  155. AEBuildAppleEvent(
  156. AEEventClass theClass,
  157. AEEventID theID,
  158. DescType addressType,
  159. const void * addressData,
  160. long addressLength,
  161. short returnID,
  162. long transactionID,
  163. AppleEvent * result,
  164. AEBuildError * error, /* can be NULL */
  165. const char * paramsFmt,
  166. ...);
  167. /* varargs version of AEBuildAppleEvent*/
  168. /*
  169. * vAEBuildAppleEvent()
  170. *
  171. * Availability:
  172. * Non-Carbon CFM: not available
  173. * CarbonLib: in CarbonLib 1.1 and later
  174. * Mac OS X: in version 10.0 and later
  175. */
  176. EXTERN_API_C( OSStatus )
  177. vAEBuildAppleEvent(
  178. AEEventClass theClass,
  179. AEEventID theID,
  180. DescType addressType,
  181. const void * addressData,
  182. long addressLength,
  183. short returnID,
  184. long transactionID,
  185. AppleEvent * resultEvt,
  186. AEBuildError * error, /* can be NULL */
  187. const char * paramsFmt,
  188. va_list args);
  189. /*
  190. * AEPrintDescToHandle
  191. *
  192. * AEPrintDescToHandle provides a way to turn an AEDesc into a textual
  193. * representation. This is most useful for debugging calls to
  194. * AEBuildDesc and friends. The Handle returned should be disposed by
  195. * the caller. The size of the handle is the actual number of
  196. * characters in the string.
  197. */
  198. /*
  199. * AEPrintDescToHandle()
  200. *
  201. * Availability:
  202. * Non-Carbon CFM: not available
  203. * CarbonLib: in CarbonLib 1.1 and later
  204. * Mac OS X: in version 10.0 and later
  205. */
  206. EXTERN_API_C( OSStatus )
  207. AEPrintDescToHandle(
  208. const AEDesc * desc,
  209. Handle * result);
  210. /*
  211. * AEStream:
  212. *
  213. * The AEStream interface allows you to build AppleEvents by appending
  214. * to an opaque structure (an AEStreamRef) and then turning this
  215. * structure into an AppleEvent. The basic idea is to open the
  216. * stream, write data, and then close it - closing it produces an
  217. * AEDesc, which may be partially complete, or may be a complete
  218. * AppleEvent.
  219. */
  220. typedef struct OpaqueAEStreamRef* AEStreamRef;
  221. /*
  222. Create and return an AEStreamRef
  223. Returns NULL on memory allocation failure
  224. */
  225. /*
  226. * AEStreamOpen()
  227. *
  228. * Availability:
  229. * Non-Carbon CFM: not available
  230. * CarbonLib: in CarbonLib 1.1 and later
  231. * Mac OS X: in version 10.0 and later
  232. */
  233. EXTERN_API_C( AEStreamRef )
  234. AEStreamOpen(void);
  235. /*
  236. Closes and disposes of an AEStreamRef, producing
  237. results in the desc. You must dispose of the desc yourself.
  238. If you just want to dispose of the AEStreamRef, you can pass NULL for desc.
  239. */
  240. /*
  241. * AEStreamClose()
  242. *
  243. * Availability:
  244. * Non-Carbon CFM: not available
  245. * CarbonLib: in CarbonLib 1.1 and later
  246. * Mac OS X: in version 10.0 and later
  247. */
  248. EXTERN_API_C( OSStatus )
  249. AEStreamClose(
  250. AEStreamRef ref,
  251. AEDesc * desc);
  252. /*
  253. Prepares an AEStreamRef for appending data to a newly created desc.
  254. You append data with AEStreamWriteData
  255. */
  256. /*
  257. * AEStreamOpenDesc()
  258. *
  259. * Availability:
  260. * Non-Carbon CFM: not available
  261. * CarbonLib: in CarbonLib 1.1 and later
  262. * Mac OS X: in version 10.0 and later
  263. */
  264. EXTERN_API_C( OSStatus )
  265. AEStreamOpenDesc(
  266. AEStreamRef ref,
  267. DescType newType);
  268. /* Append data to the previously opened desc.*/
  269. /*
  270. * AEStreamWriteData()
  271. *
  272. * Availability:
  273. * Non-Carbon CFM: not available
  274. * CarbonLib: in CarbonLib 1.1 and later
  275. * Mac OS X: in version 10.0 and later
  276. */
  277. EXTERN_API_C( OSStatus )
  278. AEStreamWriteData(
  279. AEStreamRef ref,
  280. const void * data,
  281. Size length);
  282. /*
  283. Finish a desc. After this, you can close the stream, or adding new
  284. descs, if you're assembling a list.
  285. */
  286. /*
  287. * AEStreamCloseDesc()
  288. *
  289. * Availability:
  290. * Non-Carbon CFM: not available
  291. * CarbonLib: in CarbonLib 1.1 and later
  292. * Mac OS X: in version 10.0 and later
  293. */
  294. EXTERN_API_C( OSStatus )
  295. AEStreamCloseDesc(AEStreamRef ref);
  296. /* Write data as a desc to the stream*/
  297. /*
  298. * AEStreamWriteDesc()
  299. *
  300. * Availability:
  301. * Non-Carbon CFM: not available
  302. * CarbonLib: in CarbonLib 1.1 and later
  303. * Mac OS X: in version 10.0 and later
  304. */
  305. EXTERN_API_C( OSStatus )
  306. AEStreamWriteDesc(
  307. AEStreamRef ref,
  308. DescType newType,
  309. const void * data,
  310. Size length);
  311. /* Write an entire desc to the stream*/
  312. /*
  313. * AEStreamWriteAEDesc()
  314. *
  315. * Availability:
  316. * Non-Carbon CFM: not available
  317. * CarbonLib: in CarbonLib 1.1 and later
  318. * Mac OS X: in version 10.0 and later
  319. */
  320. EXTERN_API_C( OSStatus )
  321. AEStreamWriteAEDesc(
  322. AEStreamRef ref,
  323. const AEDesc * desc);
  324. /*
  325. Begin a list. You can then append to the list by doing
  326. AEStreamOpenDesc, or AEStreamWriteDesc.
  327. */
  328. /*
  329. * AEStreamOpenList()
  330. *
  331. * Availability:
  332. * Non-Carbon CFM: not available
  333. * CarbonLib: in CarbonLib 1.1 and later
  334. * Mac OS X: in version 10.0 and later
  335. */
  336. EXTERN_API_C( OSStatus )
  337. AEStreamOpenList(AEStreamRef ref);
  338. /* Finish a list.*/
  339. /*
  340. * AEStreamCloseList()
  341. *
  342. * Availability:
  343. * Non-Carbon CFM: not available
  344. * CarbonLib: in CarbonLib 1.1 and later
  345. * Mac OS X: in version 10.0 and later
  346. */
  347. EXTERN_API_C( OSStatus )
  348. AEStreamCloseList(AEStreamRef ref);
  349. /*
  350. Begin a record. A record usually has type 'reco', however, this is
  351. rather generic, and frequently a different type is used.
  352. */
  353. /*
  354. * AEStreamOpenRecord()
  355. *
  356. * Availability:
  357. * Non-Carbon CFM: not available
  358. * CarbonLib: in CarbonLib 1.1 and later
  359. * Mac OS X: in version 10.0 and later
  360. */
  361. EXTERN_API_C( OSStatus )
  362. AEStreamOpenRecord(
  363. AEStreamRef ref,
  364. DescType newType);
  365. /* Change the type of a record.*/
  366. /*
  367. * AEStreamSetRecordType()
  368. *
  369. * Availability:
  370. * Non-Carbon CFM: not available
  371. * CarbonLib: in CarbonLib 1.1 and later
  372. * Mac OS X: in version 10.0 and later
  373. */
  374. EXTERN_API_C( OSStatus )
  375. AEStreamSetRecordType(
  376. AEStreamRef ref,
  377. DescType newType);
  378. /* Finish a record*/
  379. /*
  380. * AEStreamCloseRecord()
  381. *
  382. * Availability:
  383. * Non-Carbon CFM: not available
  384. * CarbonLib: in CarbonLib 1.1 and later
  385. * Mac OS X: in version 10.0 and later
  386. */
  387. EXTERN_API_C( OSStatus )
  388. AEStreamCloseRecord(AEStreamRef ref);
  389. /*
  390. Add a keyed descriptor to a record. This is analogous to AEPutParamDesc.
  391. it can only be used when writing to a record.
  392. */
  393. /*
  394. * AEStreamWriteKeyDesc()
  395. *
  396. * Availability:
  397. * Non-Carbon CFM: not available
  398. * CarbonLib: in CarbonLib 1.1 and later
  399. * Mac OS X: in version 10.0 and later
  400. */
  401. EXTERN_API_C( OSStatus )
  402. AEStreamWriteKeyDesc(
  403. AEStreamRef ref,
  404. AEKeyword key,
  405. DescType newType,
  406. const void * data,
  407. Size length);
  408. /*
  409. OpenDesc for a keyed record entry. You can use AEStreamWriteData
  410. after opening a keyed desc.
  411. */
  412. /*
  413. * AEStreamOpenKeyDesc()
  414. *
  415. * Availability:
  416. * Non-Carbon CFM: not available
  417. * CarbonLib: in CarbonLib 1.1 and later
  418. * Mac OS X: in version 10.0 and later
  419. */
  420. EXTERN_API_C( OSStatus )
  421. AEStreamOpenKeyDesc(
  422. AEStreamRef ref,
  423. AEKeyword key,
  424. DescType newType);
  425. /* Write a key to the stream - you can follow this with an AEWriteDesc.*/
  426. /*
  427. * AEStreamWriteKey()
  428. *
  429. * Availability:
  430. * Non-Carbon CFM: not available
  431. * CarbonLib: in CarbonLib 1.1 and later
  432. * Mac OS X: in version 10.0 and later
  433. */
  434. EXTERN_API_C( OSStatus )
  435. AEStreamWriteKey(
  436. AEStreamRef ref,
  437. AEKeyword key);
  438. /*
  439. Create a complete AppleEvent. This creates and returns a new stream.
  440. Use this call to populate the meta fields in an AppleEvent record.
  441. After this, you can add your records, lists and other parameters.
  442. */
  443. /*
  444. * AEStreamCreateEvent()
  445. *
  446. * Availability:
  447. * Non-Carbon CFM: not available
  448. * CarbonLib: in CarbonLib 1.1 and later
  449. * Mac OS X: in version 10.0 and later
  450. */
  451. EXTERN_API_C( AEStreamRef )
  452. AEStreamCreateEvent(
  453. AEEventClass clazz,
  454. AEEventID id,
  455. DescType targetType,
  456. const void * targetData,
  457. long targetLength,
  458. short returnID,
  459. long transactionID);
  460. /*
  461. This call lets you augment an existing AppleEvent using the stream
  462. APIs. This would be useful, for example, in constructing the reply
  463. record in an AppleEvent handler. Note that AEStreamOpenEvent will
  464. consume the AppleEvent passed in - you can't access it again until the
  465. stream is closed. When you're done building the event, AEStreamCloseStream
  466. will reconstitute it.
  467. */
  468. /*
  469. * AEStreamOpenEvent()
  470. *
  471. * Availability:
  472. * Non-Carbon CFM: not available
  473. * CarbonLib: in CarbonLib 1.1 and later
  474. * Mac OS X: in version 10.0 and later
  475. */
  476. EXTERN_API_C( AEStreamRef )
  477. AEStreamOpenEvent(AppleEvent * event);
  478. /* Mark a keyword as being an optional parameter.*/
  479. /*
  480. * AEStreamOptionalParam()
  481. *
  482. * Availability:
  483. * Non-Carbon CFM: not available
  484. * CarbonLib: in CarbonLib 1.1 and later
  485. * Mac OS X: in version 10.0 and later
  486. */
  487. EXTERN_API_C( OSStatus )
  488. AEStreamOptionalParam(
  489. AEStreamRef ref,
  490. AEKeyword key);
  491. #if PRAGMA_STRUCT_ALIGN
  492. #pragma options align=reset
  493. #elif PRAGMA_STRUCT_PACKPUSH
  494. #pragma pack(pop)
  495. #elif PRAGMA_STRUCT_PACK
  496. #pragma pack()
  497. #endif
  498. #ifdef PRAGMA_IMPORT_OFF
  499. #pragma import off
  500. #elif PRAGMA_IMPORT
  501. #pragma import reset
  502. #endif
  503. #ifdef __cplusplus
  504. }
  505. #endif
  506. #endif /* __AEHELPERS__ */