home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 402.lha / IconTools / arp / ArpBase.j.aa < prev    next >
Text File  |  1990-07-27  |  41KB  |  801 lines

  1. \ ArpBase.j
  2. \ AMIGA JForth Include file.
  3. \
  4. \ converted 11/24/89 by R. Mazzarisi using the H2J program by Phil Burke from
  5. \    the JForth Goodies #1 package
  6. \ lines which were unconvertable by the program, which I attempted to
  7. \    convert are marked "correct below? -RM"
  8. \
  9. \ 11/24/89 the only parts tested are the data structures for opening the
  10. \        library and for the functions ArpAllocFreq and FileRequest
  11. \
  12. include? :struct ju:c_struct
  13. decimal
  14. EXISTS? LIBRARIES_ARPBASE_H NOT .IF
  15. 1   constant LIBRARIES_ARPBASE_H
  16. .THEN    \ %? Forced .THEN to prevent nesting!!!
  17.  
  18. ( )
  19. (  ************************************************************************)
  20. (  *                                                                    *)
  21. (  * 5/3/89     ARPbase.h       by MKSoft from ARPbase.i by SDB         *)
  22. (  *                                                                    *)
  23. (  ************************************************************************)
  24. (  *                                                                    *)
  25. (  *    AmigaDOS Resource Project -- Library Include File               *)
  26. (  *                                 for Lattice C 5.x or Manx C 3.6    *)
  27. (  *                                                                    *)
  28. (  ************************************************************************)
  29. (  *                                                                    *)
  30. (  *    Copyright [c] 1987/1988/1989 by Scott Ballantyne                *)
  31. (  *                                                                    *)
  32. (  *    The arp.library, and related code and files may be freely used  *)
  33. (  *    by supporters of ARP.  Modules in the arp.library may not be    *)
  34. (  *    extracted for use in independent code, but you are welcome to   *)
  35. (  *    provide the arp.library with your work and call on it freely.   *)
  36. (  *                                                                    *)
  37. (  *    You are equally welcome to add new functions, improve the ones  *)
  38. (  *    within, or suggest additions.                                   *)
  39. (  *                                                                    *)
  40. (  *    BCPL programs are not welcome to call on the arp.library.       *)
  41. (  *    The welcome mat is out to all others.                           *)
  42. (  *                                                                    *)
  43. (  ************************************************************************)
  44. (  *                                                                    *)
  45. (  * N O T E !  You MUST! have IoErr[] defined as LONG to use LastTracker *)
  46. (  *          If your compiler has other defines for this, you may wish *)
  47. (  *          to remove the prototype for IoErr[] from this file.       *)
  48. (  *                                                                    *)
  49. (  ************************************************************************)
  50. (  )
  51.  
  52. ( )
  53. (  ************************************************************************)
  54. (  *    First we need to include the Amiga Standard Include files...    *)
  55. (  ************************************************************************)
  56. (  )
  57.  
  58. EXISTS? EXEC_TYPES_H NOT .IF
  59. include ji:EXEC/Types.j
  60. .THEN
  61.  
  62. EXISTS? EXEC_LISTS_H NOT .IF
  63. include ji:EXEC/Lists.j
  64. .THEN
  65.  
  66. EXISTS? EXEC_ALERTS_H NOT .IF
  67. include ji:EXEC/Alerts.j
  68. .THEN
  69.  
  70. EXISTS? EXEC_LIBRARIES_H NOT .IF
  71. include ji:EXEC/Libraries.j
  72. .THEN
  73.  
  74. EXISTS? EXEC_SEMAPHORES_H NOT .IF
  75. include ji:EXEC/Semaphores.j
  76. .THEN
  77.  
  78. EXISTS? LIBRARIES_DOS_H NOT .IF
  79. include ji:Libraries/DOS.j
  80. .THEN
  81.  
  82. ( )
  83. (  ************************************************************************)
  84. (  *    Standard definitions for arp library information                *)
  85. (  ************************************************************************)
  86. (  )
  87. 0" arp.library"  0string ArpName  ( Name of library... )
  88. 39   constant ArpVersion (  Current version... )
  89.  
  90. ( )
  91. (  ************************************************************************)
  92. (  *    The current ARP library node...                                 *)
  93. (  ************************************************************************)
  94. (  )
  95.  
  96. :STRUCT ArpBase
  97.       STRUCT Library    ab_LibNode     (  Standard library node               )
  98.           APTR ab_DosRootNode     (  Copy of dl_Root                     )
  99.           UBYTE ab_Flags         (  See bitdefs below                   )
  100.           UBYTE ab_ESCChar     (  Character to be used for escaping   )
  101.           LONG ab_ArpReserved1     (  ArpLib's use only!!                 )
  102.       APTR ab_EnvBase     (  Dummy library for MANX compatibility)
  103.       APTR ab_DosBase     (  Cached DosBase                      )
  104.       APTR ab_GfxBase     (  Cached GfxBase                      )
  105.       APTR ab_IntuiBase     (  Cached IntuitionBase                )
  106.       STRUCT MinList    ab_ResLists     (  Resource trackers                   )
  107.       APTR ab_ResidentPrgList     (  Resident Programs.                  )
  108.       STRUCT SignalSemaphore    ab_ResPrgProtection (  protection for above              )
  109.           LONG ab_SegList     (  Pointer to loaded libcode [a BPTR]. )
  110.         ;STRUCT
  111.  
  112.  
  113. ( )
  114. (  ************************************************************************)
  115. (  *    The following is here *ONLY* for information and for            *)
  116. (  *    compatibility with MANX.  DO NOT use in new code!               *)
  117. (  ************************************************************************)
  118. (  )
  119. EXISTS? ARP_PRIVATE .IF
  120.  
  121. :STRUCT EnvBase
  122.       STRUCT Library    eb_LibNode    (  Standard library node for linkage    )
  123.           APTR eb_EnvSpace    (  Access only when Forbidden!          )
  124.           ULONG eb_EnvSize    (  Total allocated mem for EnvSpace     )
  125.       APTR eb_ArpBase    (  Added in V32 for Resource Tracking   )
  126.         ;STRUCT
  127.  
  128. .THEN
  129.  
  130. ( )
  131. (  ************************************************************************)
  132. (  *    These are used in release 33.4 but not by the library code.     *)
  133. (  *    Instead, individual programs check for these flags.             *)
  134. (  ************************************************************************)
  135. (  )
  136. 0   constant ARPB_WILD_WORLD    ( Mixed BCPL/Normal wildcards. )
  137. 1   constant ARPB_WILD_BCPL    ( Pure BCPL wildcards. )
  138.  
  139. 1  ARPB_WILD_WORLD <<  constant ARPF_WILD_WORLD
  140. 1  ARPB_WILD_BCPL <<  constant ARPF_WILD_BCPL
  141.  
  142. ( )
  143. (  ************************************************************************)
  144. (  * The alert object is what you use if you really must return an alert        *)
  145. (  * to the user. You would normally OR this with another alert number  *)
  146. (  * from the alerts.h file. Generally, should be NON deadend alerts.   *)
  147. (  *                                                                    *)
  148. (  * For example, if you can't open ArpLibrary:                         *)
  149. (  *    Alert[ [AG_OpenLib|AO_ArpLib], 0L];                             *)
  150. (  ************************************************************************)
  151. (  )
  152. $ 00008036   constant AO_ArpLib (  Alert object )
  153.  
  154. ( )
  155. (  ************************************************************************)
  156. (  *    Alerts that arp.library may return...                           *)
  157. (  ************************************************************************)
  158. (  )
  159. $ 03600000   constant AN_ArpLib (  Alert number                              )
  160. $ 03610000   constant AN_ArpNoMem (  No more memory                  )
  161. $ 03610002   constant AN_ArpInputMem (  No memory for input buffer           )
  162. $ 83610003   constant AN_ArpNoMakeEnv (  No memory to make EnvLib            )
  163.  
  164. $ 83630001   constant AN_ArpNoDOS (  Can't open dos.library          )
  165. $ 83630002   constant AN_ArpNoGfx (  Can't open graphics.library             )
  166. $ 83630003   constant AN_ArpNoIntuit (  Can't open intuition                 )
  167. $ 83640000   constant AN_BadPackBlues (  Bad packet returned to SendPacket[] )
  168. $ 83600003   constant AN_Zombie (  Zombie roaming around system              )
  169.  
  170. $ 83600002   constant AN_ArpScattered (  Scatter loading not allowed for arp )
  171.  
  172.  
  173. ( )
  174. (  ************************************************************************)
  175. (  *    Return codes you can get from calling ARP Assign[]...           *)
  176. (  ************************************************************************)
  177. (  )
  178. 0   constant ASSIGN_OK (  Everything is cool and groovey                     )
  179. 1   constant ASSIGN_NODEV (  "Physical" is not valid for assignment          )
  180. 2   constant ASSIGN_FATAL (  Something really icky happened                  )
  181. 3   constant ASSIGN_CANCEL (  Tried to cancel something but it won't cancel  )
  182.  
  183. ( )
  184. (  ************************************************************************)
  185. (  *    Size of buffer you need if you are going to call ReadLine[]     *)
  186. (  ************************************************************************)
  187. (  )
  188. 256   constant MaxInputBuf
  189.  
  190. ( )
  191. (  ************************************************************************)
  192. (  *    The ARP file requester data structure...                        *)
  193. (  ************************************************************************)
  194. (  )
  195.  
  196. :STRUCT FileRequester
  197.               APTR fr_Hail             (  Hailing text                 )
  198.               APTR fr_File             (  Filename array [FCHARS + 1]  )
  199.               APTR fr_Dir             (  Directory array [DSIZE + 1]  )
  200.               APTR fr_Window         (  Window requesting or NULL    )
  201.               UBYTE fr_FuncFlags         (  Set bitdef's below           )
  202.               UBYTE fr_Flags2         (  New flags...                 )
  203. \ %? correct below? -RM   VOID      (*fr_Function)();       /* Your function, see bitdef's  */
  204.               APTR    fr_Function()        (  Your function, see bitdef's  )
  205.               SHORT fr_LeftEdge         (  To be used later...          )
  206.               SHORT fr_TopEdge
  207.             ;STRUCT
  208.  
  209.  
  210. ( )
  211. (  ************************************************************************)
  212. (  * The following are the defines for fr_FuncFlags.  These bits tell   *)
  213. (  * FileRequest[] what your fr_UserFunc is expecting, and what         *)
  214. (  * FileRequest[] should call it for.                                  *)
  215. (  *                                                                    *)
  216. (  * You are called like so:                                            *)
  217. (  * fr_Function[Mask, Object]                                          *)
  218. (  * ULONG      Mask;                                                   *)
  219. (  * CPTR               *Object;                                                *)
  220. (  *                                                                    *)
  221. (  * The Mask is a copy of the flag value that caused FileRequest[] to  *)
  222. (  * call your function. You can use this to determine what action you  *)
  223. (  * need to perform, and exactly what Object is, so you know what to do        *)
  224. (  * and what to return.                                                        *)
  225. (  ************************************************************************)
  226. (  )
  227. 7   constant FRB_DoWildFunc (  Call me with a FIB and a name, ZERO return accepts.   )
  228. 6   constant FRB_DoMsgFunc (  You get all IDCMP messages not for FileRequest[]               )
  229. 5   constant FRB_DoColor (  Set this bit for that new and different look             )
  230. 4   constant FRB_NewIDCMP (  Force a new IDCMP [only if fr_Window != NULL]           )
  231. 3   constant FRB_NewWindFunc (  You get to modify the newwindow structure.           )
  232. 2   constant FRB_AddGadFunc (  You get to add gadgets.                                       )
  233. 1   constant FRB_GEventFunc (  Function to call if one of your gadgets is selected.  )
  234. 0   constant FRB_ListFunc (  Not implemented yet.                                    )
  235.  
  236. 1  FRB_DoWildFunc <<  constant FRF_DoWildFunc
  237. 1  FRB_DoMsgFunc <<  constant FRF_DoMsgFunc
  238. 1  FRB_DoColor <<  constant FRF_DoColor
  239. 1  FRB_NewIDCMP <<  constant FRF_NewIDCMP
  240. 1  FRB_NewWindFunc <<  constant FRF_NewWindFunc
  241. 1  FRB_AddGadFunc <<  constant FRF_AddGadFunc
  242. 1  FRB_GEventFunc <<  constant FRF_GEventFunc
  243. 1  FRB_ListFunc <<  constant FRF_ListFunc
  244.  
  245. ( )
  246. (  ************************************************************************)
  247. (  * The FR2B_ bits are for fr_Flags2 in the file requester structure   *)
  248. (  ************************************************************************)
  249. (  )
  250. 0   constant FR2B_LongPath (  Specify the fr_Dir buffer is 256 bytes long )
  251.  
  252. 1  FR2B_LongPath <<  constant FR2F_LongPath
  253.  
  254. ( )
  255. (  ************************************************************************)
  256. (  *    The sizes of the different buffers...                           *)
  257. (  ************************************************************************)
  258. (  )
  259. 32   constant FCHARS (  Filename size                                )
  260. 33   constant DSIZE (  Directory name size if not FR2B_LongPath      )
  261.  
  262. 254   constant LONG_DSIZE (  If FR2B_LongPath is set, use LONG_DSIZE )
  263. 126   constant LONG_FSIZE (  For compatibility with ARPbase.i                )
  264.  
  265. $ 7680     constant FR_FIRST_GADGET (  User gadgetID's must be less than this value    )
  266.  
  267. ( )
  268. (  ************************************************************************)
  269. (  * Structure expected by FindFirst[]/FindNext[]                               *)
  270. (  *                                                                    *)
  271. (  * You need to allocate this structure and initialize it as follows:  *)
  272. (  *                                                                    *)
  273. (  * Set ap_BreakBits to the signal bits [CDEF] that you want to take a *)
  274. (  * break on, or NULL, if you don't want to convenience the user.      *)
  275. (  *                                                                    *)
  276. (  * if you want to have the FULL PATH NAME of the files you found,     *)
  277. (  * allocate a buffer at the END of this structure, and put the size of        *)
  278. (  * it into ap_StrLen.  If you don't want the full path name, make sure        *)
  279. (  * you set ap_StrLen to zero.  In this case, the name of the file, and        *)
  280. (  * stats are available in the ap_Info, as per usual.                  *)
  281. (  *                                                                    *)
  282. (  * Then call FindFirst[] and then afterwards, FindNext[] with this    *)
  283. (  * structure.  You should check the return value each time [see below]        *)
  284. (  * and take the appropriate action, ultimately calling                        *)
  285. (  * FreeAnchorChain[] when there are no more files and you are done.   *)
  286. (  * You can tell when you are done by checking for the normal AmigaDOS *)
  287. (  * return code ERROR_NO_MORE_ENTRIES.                                 *)
  288. (  *                                                                    *)
  289. (  * You will also have to check the DirEntryType variable in the ap_Info       *)
  290. (  * structure to determine what exactly you have received.             *)
  291. (  ************************************************************************)
  292. (  )
  293.  
  294. :STRUCT AnchorPath
  295.           APTR ap_Base         (  Pointer to first anchor                      )
  296.           APTR ap_Last         (  Pointer to last anchor                       )
  297.               LONG ap_BreakBits  (  Bits to break on                             )
  298.               LONG ap_FoundBreak (  Bits we broke on. Also returns ERROR_BREAK   )
  299.               BYTE ap_Flags      (  New use for the extra word...                )
  300.               BYTE ap_Reserved   (  To fill it out...                            )
  301.               SHORT ap_StrLen    (  This is what used to be ap_Length            )
  302.           STRUCT FileInfoBlock    ap_Info
  303.             ( %?)   1 BYTES ap_Buf       (  Allocate a buffer here, if desired           )
  304.             ;STRUCT
  305.  
  306.  
  307. ( )
  308. (  ************************************************************************)
  309. (  *    Bit definitions for the new ap_Flags...                         *)
  310. (  ************************************************************************)
  311. (  )
  312. 0   constant APB_DoWild (  User option ALL                           )
  313. 1   constant APB_ItsWild (  Set by FindFirst, used by FindNext               )
  314. 2   constant APB_DoDir (  Bit is SET if a DIR node should be entered )
  315.                 (  Application can RESET this bit to AVOID      )
  316.                 (  entering a dir.                              )
  317. 3   constant APB_DidDir (  Bit is set for an "expired" dir node              )
  318. 4   constant APB_NoMemErr (  Set if there was not enough memory              )
  319. 5   constant APB_DoDot (  If set, '.' [DOT] will convert to CurrentDir       )
  320.  
  321. 1  APB_DoWild <<  constant APF_DoWild
  322. 1  APB_ItsWild <<  constant APF_ItsWild
  323. 1  APB_DoDir <<  constant APF_DoDir
  324. 1  APB_DidDir <<  constant APF_DidDir
  325. 1  APB_NoMemErr <<  constant APF_NoMemErr
  326. 1  APB_DoDot <<  constant APF_DoDot
  327.  
  328. ( )
  329. (  ************************************************************************)
  330. (  * Structure used by the pattern matching functions, no need to obtain,       *)
  331. (  * diddle or allocate this yourself.                                  *)
  332. (  *                                                                    *)
  333. (  * Note:  If you did, you will now break as it has changed...         *)
  334. (  ************************************************************************)
  335. (  )
  336. EXISTS? ARP_PRIVATE .IF
  337.  
  338. :STRUCT AChain
  339.       APTR an_Child
  340.       APTR an_Parent
  341.       APTR an_Lock
  342.       APTR an_Info
  343.           BYTE an_Flags
  344.         ( %?)   1 BYTES an_String       (  Just as is .i file   )
  345.         ;STRUCT
  346.                 (  ???  Don't use this! )
  347. .THEN
  348.  
  349. 0   constant DDB_PatternBit
  350. 1   constant DDB_ExaminedBit
  351. 2   constant DDB_Completed
  352. 3   constant DDB_AllBit
  353.  
  354. 1  DDB_PatternBit <<  constant DDF_PatternBit
  355. 1  DDB_ExaminedBit <<  constant DDF_ExaminedBit
  356. 1  DDB_Completed <<  constant DDF_Completed
  357. 1  DDB_AllBit <<  constant DDF_AllBit
  358.  
  359. ( )
  360. (  ************************************************************************)
  361. (  * This structure takes a pointer, and returns FALSE if wildcard was  *)
  362. (  * not found by FindFirst[]                                           *)
  363. (  ************************************************************************)
  364. (  )
  365. \ %? #define    IsWild( ptr )           ( *((LONG *)(ptr)) ): IsWild ;
  366.  
  367. ( )
  368. (  ************************************************************************)
  369. (  * Constants used by wildcard routines                                        *)
  370. (  *                                                                    *)
  371. (  * These are the pre-parsed tokens referred to by pattern match.  It  *)
  372. (  * is not necessary for you to do anything about these, FindFirst[]   *)
  373. (  * FindNext[] handle all these for you.                                       *)
  374. (  ************************************************************************)
  375. (  )
  376. $ 80   constant P_ANY (  Token for '*' | '#?'        )
  377. $ 81   constant P_SINGLE (  Token for '?'    )
  378.  
  379. ( )
  380. (  ************************************************************************)
  381. (  * No need to muck with these as they may change...                   *)
  382. (  ************************************************************************)
  383. (  )
  384. EXISTS? ARP_PRIVATE .IF
  385. $ 82   constant P_ORSTART (  Token for '['   )
  386. $ 83   constant P_ORNEXT (  Token for '|'    )
  387. $ 84   constant P_OREND (  Token for ']'     )
  388. $ 85   constant P_NOT (  Token for '~'       )
  389. $ 87   constant P_NOTCLASS (  Token for '^'  )
  390. $ 88   constant P_CLASS (  Token for '[]'    )
  391. $ 89   constant P_REPBEG (  Token for '['    )
  392. $ 8A   constant P_REPEND (  Token for ']'    )
  393. .THEN
  394.  
  395. ( )
  396. (  ************************************************************************)
  397. (  * Structure used by AddDANode[], AddDADevs[], FreeDAList[].          *)
  398. (  *                                                                    *)
  399. (  * This structure is used to create lists of names, which normally    *)
  400. (  * are devices, assigns, volumes, files, or directories.              *)
  401. (  ************************************************************************)
  402. (  )
  403.  
  404. :STRUCT DirectoryEntry
  405.           APTR de_Next    (  Next in list                         )
  406.               BYTE de_Type    (  DLX_mumble                           )
  407.               BYTE de_Flags (  For future expansion, DO NOT USE!    )
  408.             ( %?)   1 BYTES de_Name (  The name of the thing found          )
  409.             ;STRUCT
  410.  
  411.  
  412. ( )
  413. (  ************************************************************************)
  414. (  * Defines you use to get a list of the devices you want to look at.  *)
  415. (  * For example, to get a list of all directories and volumes, do:     *)
  416. (  *                                                                    *)
  417. (  *    AddDADevs[ mydalist, [DLF_DIRS | DLF_VOLUMES] ]                 *)
  418. (  *                                                                    *)
  419. (  * After this, you can examine the de_type field of the elements added        *)
  420. (  * to your list [if any] to discover specifics about the objects added.       *)
  421. (  *                                                                    *)
  422. (  * Note that if you want only devices which are also disks, you must  *)
  423. (  * [DLF_DEVICES | DLF_DISKONLY].                                      *)
  424. (  ************************************************************************)
  425. (  )
  426. 0   constant DLB_DEVICES (  Return devices                           )
  427. 1   constant DLB_DISKONLY (  Modifier for above: Return disk devices only    )
  428. 2   constant DLB_VOLUMES (  Return volumes only                              )
  429. 3   constant DLB_DIRS (  Return assigned devices only                        )
  430.  
  431. 1  DLB_DEVICES <<  constant DLF_DEVICES
  432. 1  DLB_DISKONLY <<  constant DLF_DISKONLY
  433. 1  DLB_VOLUMES <<  constant DLF_VOLUMES
  434. 1  DLB_DIRS <<    constant DLF_DIRS
  435.  
  436. ( )
  437. (  ************************************************************************)
  438. (  * Legal de_Type values, check for these after a call to AddDADevs[], *)
  439. (  * or use on your own as the ID values in AddDANode[].                        *)
  440. (  ************************************************************************)
  441. (  )
  442. 0   constant DLX_FILE (  AddDADevs[] can't determine this    )
  443. 8   constant DLX_DIR (  AddDADevs[] can't determine this     )
  444. 16   constant DLX_DEVICE (  It's a resident device           )
  445.  
  446. 24   constant DLX_VOLUME (  Device is a volume                       )
  447. 32   constant DLX_UNMOUNTED (  Device is not resident                )
  448.  
  449. 40   constant DLX_ASSIGN (  Device is a logical assignment   )
  450.  
  451. ( )
  452. (  ************************************************************************)
  453. (  *    This macro is to check for an error return from the Atol[]      *)
  454. (  *    routine.  If Errno is ERRBADINT, then there was an error...     *)
  455. (  *    This was done to try to remain as close to source compatible    *)
  456. (  *    as possible with the older [rel 1.1] ARPbase.h                  *)
  457. (  ************************************************************************)
  458. (  )
  459. 1   constant ERRBADINT
  460. \ %? #define Errno         (IoErr() ? ERRBADINT : 0)
  461.  
  462. ( )
  463. (  ************************************************************************)
  464. (  *    Resource Tracking stuff...                                      *)
  465. (  ************************************************************************)
  466. (  *                                                                    *)
  467. (  * There are a few things in arp.library that are only directly               *)
  468. (  * acessable from assembler.  The glue routines provided by us for    *)
  469. (  * all 'C' compilers use the following conventions to make these      *)
  470. (  * available to C programs.  The glue for other language's should use *)
  471. (  * as similar a mechanism as possible, so that no matter what language        *)
  472. (  * or compiler we speak, when talk about arp, we will know what the   *)
  473. (  * other guy is saying.                                                       *)
  474. (  *                                                                    *)
  475. (  * Here are the cases:                                                        *)
  476. (  *                                                                    *)
  477. (  * Tracker calls...                                                   *)
  478. (  *            These calls return the Tracker pointer as a secondary   *)
  479. (  *            result in the register A1.  For C, there is no clean    *)
  480. (  *            way to return more than one result so the tracker       *)
  481. (  *            pointer is returned in IoErr[].  For ease of use,       *)
  482. (  *            there is a define that typecasts IoErr[] to the correct *)
  483. (  *            pointer type.  This is called LastTracker and should    *)
  484. (  *            be source compatible with the earlier method of storing *)
  485. (  *            the secondary result.                                   *)
  486. (  *                                                                    *)
  487. (  * GetTracker[] -                                                     *)
  488. (  *            Syntax is a bit different for C than the assembly call  *)
  489. (  *            The C syntax is GetTracker[ID].  The binding routines   *)
  490. (  *            will store the ID into the tracker on return.  Also,    *)
  491. (  *            in an effort to remain consistant, the tracker will     *)
  492. (  *            also be stored in LastTracker.                          *)
  493. (  *                                                                    *)
  494. (  * In cases where you have allocated a tracker before you have obtained       *)
  495. (  * a resource [usually the most efficient method], and the resource has       *)
  496. (  * not been obtained, you will need to clear the tracker id.  The macro       *)
  497. (  * CLEAR_ID[] has been provided for that purpose.  It expects a pointer       *)
  498. (  * to a DefaultTracker sort of struct.                                        *)
  499. (  ************************************************************************)
  500. (  )
  501. \ %? #define    CLEAR_ID(t)     ((SHORT *) t)[-1]=NULL: CLEAR_ID ;
  502.  
  503. ( )
  504. (  ************************************************************************)
  505. (  * You MUST prototype IoErr[] to prevent the possible error in defining       *)
  506. (  * IoErr[] and thus causing LastTracker to give you trash...          *)
  507. (  *                                                                    *)
  508. (  * N O T E !  You MUST! have IoErr[] defined as LONG to use LastTracker *)
  509. (  *          If your compiler has other defines for this, you may wish *)
  510. (  *          to remove the prototype for IoErr[].                      *)
  511. (  ************************************************************************)
  512. (  )
  513. \ %? #define LastTracker     ((struct DefaultTracker *)IoErr())
  514.  
  515. ( )
  516. (  ************************************************************************)
  517. (  * The rl_FirstItem list [ResList] is a list of TrackedResource [below]       *)
  518. (  * It is very important that nothing in this list depend on the task  *)
  519. (  * existing at resource freeing time [i.e., RemTask[0L] type stuff,   *)
  520. (  * DeletePort[] and the rest].                                                *)
  521. (  *                                                                    *)
  522. (  * The tracking functions return a struct Tracker *Tracker to you, this       *)
  523. (  * is a pointer to whatever follows the tr_ID variable.                       *)
  524. (  * The default case is reflected below, and you get it if you call    *)
  525. (  * GetTracker[] [ see DefaultTracker below].                          *)
  526. (  *                                                                    *)
  527. (  * NOTE: The two user variables mentioned in an earlier version don't *)
  528. (  * exist, and never did. Sorry about that [SDB].                      *)
  529. (  *                                                                    *)
  530. (  * However, you can still use ArpAlloc[] to allocate your own tracking        *)
  531. (  * nodes and they can be any size or shape you like, as long as the   *)
  532. (  * base structure is preserved. They will be freed automagically just *)
  533. (  * like the default trackers.                                         *)
  534. (  ************************************************************************)
  535. (  )
  536.  
  537. :STRUCT TrackedResource
  538.           STRUCT MinNode    tr_Node (  Double linked pointer                )
  539.               BYTE tr_Flags (  Don't touch                          )
  540.               BYTE tr_Lock    (  Don't touch, for Get/FreeAccess[]    )
  541.               SHORT tr_ID        (  Item's ID                            )
  542.  
  543. ( )
  544. (  ************************************************************************)
  545. (  * The struct DefaultTracker *Tracker portion of the structure.               *)
  546. (  * The stuff below this point can conceivably vary, depending         *)
  547. (  * on user needs, etc.  This reflects the default.                    *)
  548. (  ************************************************************************)
  549. (  )
  550.             union{
  551. \ %? correct below? -RM     CPTR    tr_Resource;    /* Whatever                */
  552.                 APTR    tr_Resource    (  Whatever                             )
  553.             }union{
  554.                   LONG tg_Verify    (  For use during TRAK_GENERIC          )
  555.                 }union    \ tr_Object;      /* The thing being tracked          */
  556.             union{
  557. \ %? correct below? -RM     VOID    (*tg_Function)();/* Function to call for TRAK_GENERIC   */
  558.                 APTR    tg_Function()  ( Function to call for TRAK_GENERIC   )
  559.             }union{
  560.               APTR tr_Window2    (  For TRAK_WINDOW                      )
  561.                 }union    \ tr_Extra;      /* Only needed sometimes         */
  562.             ;STRUCT
  563.  
  564.  
  565. \ %? #define tg_Value tg_Verify      /* Ancient compatibility only!  Do NOT use in new CODE!!! */
  566.  
  567. ( )
  568. (  ************************************************************************)
  569. (  * You get a pointer to a struct of the following type when you call  *)
  570. (  * GetTracker[].  You can change this, and use ArpAlloc[] instead of  *)
  571. (  * GetTracker[] to do tracking. Of course, you have to take a wee bit *)
  572. (  * more responsibility if you do, as well as if you use TRAK_GENERIC  *)
  573. (  * stuff.                                                             *)
  574. (  *                                                                    *)
  575. (  * TRAK_GENERIC folks need to set up a task function to be called when        *)
  576. (  * an item is freed.  Some care is required to set this up properly.  *)
  577. (  *                                                                    *)
  578. (  * Some special cases are indicated by the unions below, for          *)
  579. (  * TRAK_WINDOW, if you have more than one window opened, and don't    *)
  580. (  * want the IDCMP closed particularly, you need to set a ptr to the   *)
  581. (  * other window in dt_Window2.  See CloseWindowSafely[] for more info.        *)
  582. (  * If only one window, set this to NULL.                              *)
  583. (  ************************************************************************)
  584. (  )
  585.  
  586. :STRUCT DefaultTracker
  587.             union{
  588. \ %? correct below? -RM     CPTR    dt_Resource;    /* Whatever                */
  589.                 APTR    dt_Resource    (  Whatever                             )
  590.             }union{
  591.                   LONG tg_Verify    (  For use during TRAK_GENERIC          )
  592.                 }union    \ dt_Object;      /* The object being tracked          */
  593.             union{
  594. \ %? correct below? -RM     VOID    (*tg_Function)();/* Function to call for TRAK_GENERIC   */
  595.                 APTR    tg_Function()  ( Function to call for TRAK_GENERIC    )
  596.             }union{
  597.               APTR dt_Window2    (  For TRAK_WINDOW                      )
  598.                 }union    \ dt_Extra;
  599.             ;STRUCT
  600.  
  601.  
  602. ( )
  603. (  ************************************************************************)
  604. (  *    Items the tracker knows what to do about                        *)
  605. (  ************************************************************************)
  606. (  )
  607. 0   constant TRAK_AAMEM (  Default [ArpAlloc] element                )
  608. 1   constant TRAK_LOCK (  File lock                          )
  609. 2   constant TRAK_FILE (  Opened file                                )
  610. 3   constant TRAK_WINDOW (  Window -- see docs                       )
  611. 4   constant TRAK_SCREEN (  Screen                           )
  612. 5   constant TRAK_LIBRARY (  Opened library                  )
  613. 6   constant TRAK_DAMEM (  Pointer to DosAllocMem block              )
  614. 7   constant TRAK_MEMNODE (  AllocEntry[] node                       )
  615. 8   constant TRAK_SEGLIST (  Program segment                 )
  616. 9   constant TRAK_RESLIST (  ARP [nested] ResList                    )
  617. 10   constant TRAK_MEM (  Memory ptr/length                  )
  618. 11   constant TRAK_GENERIC (  Generic Element, your choice           )
  619. 12   constant TRAK_DALIST (  DAlist [ aka file request ]             )
  620. 13   constant TRAK_ANCHOR (  Anchor chain [pattern matching] )
  621. 14   constant TRAK_FREQ (  FileRequest struct                        )
  622. 15   constant TRAK_FONT (  GfxBase CloseFont[]                       )
  623. 15   constant TRAK_MAX (  Poof, anything higher is tossed    )
  624.  
  625. 7   constant TRB_UNLINK (  Free node bit                     )
  626. 6   constant TRB_RELOC (  This may be relocated [not used yet]       )
  627. 5   constant TRB_MOVED (  Item moved                         )
  628.  
  629. 1  TRB_UNLINK <<  constant TRF_UNLINK
  630. 1  TRB_RELOC <<  constant TRF_RELOC
  631. 1  TRB_MOVED <<  constant TRF_MOVED
  632.  
  633. ( )
  634. (  ************************************************************************)
  635. (  * Note: ResList MUST be a DosAllocMem'ed list!, this is done for     *)
  636. (  * you when you call CreateTaskResList[], typically, you won't need   *)
  637. (  * to access/allocate this structure.                                 *)
  638. (  ************************************************************************)
  639. (  )
  640.  
  641. :STRUCT ResList
  642.       STRUCT MinNode    rl_Node (  Used by arplib to link reslists      )
  643.       APTR rl_TaskID    (  Owner of this list                   )
  644.       STRUCT MinList    rl_FirstItem    (  List of Tracked Resources            )
  645.       APTR rl_Link    (  SyncRun's use - hide list here       )
  646.         ;STRUCT
  647.  
  648.  
  649. ( )
  650. (  ************************************************************************)
  651. (  *    Returns from CompareLock[]                                      *)
  652. (  ************************************************************************)
  653. (  )
  654. 0   constant LCK_EQUAL (  The two locks refer to the same object     )
  655. 1   constant LCK_VOLUME (  Locks are on the same volume                      )
  656. 2   constant LCK_DIFVOL1 (  Locks are on different volumes           )
  657. 3   constant LCK_DIFVOL2 (  Locks are on different volumes           )
  658.  
  659. ( )
  660. (  ************************************************************************)
  661. (  *    ASyncRun[] stuff...                                             *)
  662. (  ************************************************************************)
  663. (  * Message sent back on your request by an exiting process.           *)
  664. (  * You request this by putting the address of your message in         *)
  665. (  * pcb_LastGasp, and initializing the ReplyPort variable of your      *)
  666. (  * ZombieMsg to the port you wish the message posted to.              *)
  667. (  ************************************************************************)
  668. (  )
  669.  
  670. :STRUCT ZombieMsg
  671.           STRUCT Message    zm_ExecMessage
  672.               ULONG zm_TaskNum    (  Task ID                      )
  673.               LONG zm_ReturnCode    (  Process's return code        )
  674.               ULONG zm_Result2    (  System return code           )
  675.           STRUCT DateStamp    zm_ExitTime    (  Date stamp at time of exit   )
  676.               ULONG zm_UserInfo    (  For whatever you wish        )
  677.             ;STRUCT
  678.  
  679.  
  680. ( )
  681. (  ************************************************************************)
  682. (  * Structure required by ASyncRun[] -- see docs for more info.                *)
  683. (  ************************************************************************)
  684. (  )
  685.  
  686. :STRUCT ProcessControlBlock
  687.                   ULONG pcb_StackSize    (  Stacksize for new process                    )
  688.                   BYTE pcb_Pri    (  Priority of new task                         )
  689.                   UBYTE pcb_Control    (  Control bits, see defines below              )
  690.                   APTR pcb_TrapCode    (  Optional Trap Code                           )
  691.                   LONG pcb_Input
  692.                   LONG pcb_Output    (  Optional stdin, stdout                       )
  693.                 union{
  694.                       LONG pcb_SplatFile    (  File to use for Open["*"]                    )
  695.                 }union{
  696.                       APTR pcb_ConName    (  CON: filename                                )
  697.                     }union    \ pcb_Console;
  698. \ %?                CPTR        pcb_LoadedCode; /* If not null, will not load/unload code    */
  699.                 APTR        pcb_LoadedCode    (  If not null, will not load/unload code       )
  700.               APTR pcb_LastGasp    (  ReplyMsg[] to be filled in by exit           )
  701.               APTR pcb_WBProcess    (  Valid only when PRB_NOCLI                    )
  702.                 ;STRUCT
  703.  
  704.  
  705. ( )
  706. (  ************************************************************************)
  707. (  * Formerly needed to pass NULLCMD to a child.  No longer needed.     *)
  708. (  * It is being kept here for compatibility only...                    *)
  709. (  ************************************************************************)
  710. (  )
  711. \ %? #define    NOCMD    "\n"
  712.  
  713. ( )
  714. (  ************************************************************************)
  715. (  * The following control bits determine what ASyncRun[] does on               *)
  716. (  * Abnormal Exits and on background process termination.              *)
  717. (  ************************************************************************)
  718. (  )
  719. 0   constant PRB_SAVEIO (  Don't free/check file handles on exit     )
  720. 1   constant PRB_CLOSESPLAT (  Close Splat file, must request explicitly     )
  721. 2   constant PRB_NOCLI (  Don't create a CLI process                 )
  722. (       PRB_INTERACTIVE 3L         This is now obsolete...                      )
  723. 4   constant PRB_CODE (  Dangerous yet enticing                      )
  724. 5   constant PRB_STDIO (  Do the stdio thing, splat = CON:Filename   )
  725.  
  726. 1  PRB_SAVEIO <<  constant PRF_SAVEIO
  727. 1  PRB_CLOSESPLAT <<  constant PRF_CLOSESPLAT
  728. 1  PRB_NOCLI <<  constant PRF_NOCLI
  729. 1  PRB_CODE <<    constant PRF_CODE
  730. 1  PRB_STDIO <<  constant PRF_STDIO
  731.  
  732. ( )
  733. (  ************************************************************************)
  734. (  *    Error returns from SyncRun[] and ASyncRun[]                     *)
  735. (  ************************************************************************)
  736. (  )
  737. -1   constant PR_NOFILE (  Could not LoadSeg[] the file                      )
  738. -2   constant PR_NOMEM (  No memory for something                    )
  739. (       PR_NOCLI        -3L        This is now obsolete                         )
  740. -4   constant PR_NOSLOT (  No room in TaskArray                              )
  741. -5   constant PR_NOINPUT (  Could not open input file                        )
  742. -6   constant PR_NOOUTPUT (  Could not get output file                       )
  743. (       PR_NOLOCK       -7L        This is now obsolete                         )
  744. (       PR_ARGERR       -8L        This is now obsolete                         )
  745. (       PR_NOBCPL       -9L        This is now obsolete                         )
  746. (       PR_BADLIB       -10L       This is now obsolete                         )
  747. -11   constant PR_NOSTDIO (  Couldn't get stdio handles                      )
  748.  
  749. ( )
  750. (  ************************************************************************)
  751. (  *    Added V35 of arp.library                                        *)
  752. (  ************************************************************************)
  753. (  )
  754. -12   constant PR_WANTSMESSAGE (  Child wants you to report IoErr[] to user  )
  755.                 (  for SyncRun[] only...                        )
  756. -13   constant PR_NOSHELLPROC (  Can't create a shell/cli process            )
  757. -14   constant PR_NOEXEC (  'E' bit is clear                         )
  758. -15   constant PR_SCRIPT (  S and E are set, IoErr[] contains directory      )
  759.  
  760. ( )
  761. (  ************************************************************************)
  762. (  * Version 35 ASyncRun[] allows you to create an independent          *)
  763. (  * interactive or background Shell/CLI. You need this variant of the  *)
  764. (  * pcb structure to do it, and you also have new values for nsh_Control,*)
  765. (  * see below.                                                         *)
  766. (  *                                                                    *)
  767. (  * Syntax for Interactive shell is:                                   *)
  768. (  *                                                                    *)
  769. (  * rc=ASyncRun["Optional Window Name","Optional From File",&NewShell];        *)
  770. (  *                                                                    *)
  771. (  * Syntax for a background shell is:                                  *)
  772. (  *                                                                    *)
  773. (  * rc=ASyncRun["Command line",0L,&NewShell];                          *)
  774. (  *                                                                    *)
  775. (  * Same syntax for an Execute style call, but you have to be on drugs *)
  776. (  * if you want to do that.                                            *)
  777. (  ************************************************************************)
  778. (  )
  779.  
  780. :STRUCT NewShell
  781.               ULONG nsh_StackSize    (  stacksize shell will use for children        )
  782.               BYTE nsh_Pri    (  ignored by interactive shells                )
  783.               UBYTE nsh_Control    (  bits/values: see above                       )
  784. \ %? correct below? -RM CPTR    nsh_LogMsg;    /* Optional login message, if null, use default */
  785.               APTR nsh_LogMsg    (  Optional login message, if null, use default )
  786.               LONG nsh_Input    (  ignored by interactive shells, but           )
  787.               LONG nsh_Output    (  used by background and execute options.      )
  788.             ( %?)   5 4 *  BYTES nsh_RESERVED
  789.             ;STRUCT
  790.  
  791.  
  792. ( )
  793. (  ************************************************************************)
  794. (  * Bit Values for nsh_Control, you should use them as shown below, or *)
  795. (  * just use the actual values indicated.                              *)
  796. (  ************************************************************************)
  797. (  )
  798. 0   constant PRB_CLI (  Do a CLI, not a shell        )
  799. 1   constant PRB_BACKGROUND (  Background shell              )
  800. 2   constant PRB_EXECUTE (  Do as EXECUTE...         )
  801.