home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 4 / CDPD_IV.bin / e / mailinglists / binaries / arpbase.lha / arpbase.i next >
Text File  |  1993-06-15  |  32KB  |  924 lines

  1.     IFND LIBRARIES_ARPBASE_I
  2. LIBRARIES_ARPBASE_I    SET    1
  3. ***********************************************************************
  4. *
  5. *    AmigaDOS Resource Project -- Library Include File (Assembler)
  6. *
  7. ***********************************************************************
  8. *
  9. *    History:
  10. *
  11. *    Version:    arpbase.i,v 34.00 02/27/88
  12. *
  13. *    Created by:    SDB
  14. *    Revised:    SDB (v 5.00 05/31/87)
  15. *            *---- Added meaningful alert numbers, revised macros,
  16. *            *---- updated ArpBase structure to reflect current state.
  17. *            *---- Added cheath's ASSIGN return codes as equates.
  18. *            *---- plus usual grunt work (revisions, lvo's, etc.)
  19. *            SDB (v6.04)
  20. *            cdh V7.0
  21. *            *---- added IntuiBase and GfxBase to ArpBase
  22. *            sdb V7.2
  23. *            *---- rearranged for more efficient lib code (ouch).
  24. *            *---- DosBase IntuiBase and GfxBase have *all* changed!
  25. *            *---- Few more alert #'s now get returned,
  26. *            *---- new GURU macro replaces provincial MYALERT.
  27. *            sdb v12 newstuff, see docs
  28. *            cdh V14 Added dos.library offsets, everybody moves!
  29. *            cdh V15 Added (volatile!) FindFirst etc offsets
  30. *            cdh V19 Added structs and constants for wildcards
  31. *            cdh V31 Final edit for V1.0 ARP 10/7/87
  32. *            sdb V31.00
  33. *                Final edits for release of developers materials.
  34. *                Massive changes to make this file correspond
  35. *                more closely with 'C' File.
  36. *
  37. *            SDB V32.00 Add Stuff for version 32, ASyncRun()
  38. *                Returns and data structures.
  39. *            SDB V32.01 Add ERROR_NO_CLI
  40. *            SDB V32.3 Add ResidentPrg stuff
  41. *            SDB V33.4 Final edits for release.
  42. *            SDB V35.0 PR_WANTSMESSAGE
  43. *            SDB Changes now tracked in arpheaders.log
  44. ***********************************************************************
  45. *
  46. *    Copyright (c) 1987/1988/1989, by Scott Ballantyne
  47. *
  48. *    The arp.library, and related code and files may be freely used
  49. *    by supporters of ARP.  Modules in the arp.library may not be
  50. *    extracted for use in independent code, but you are welcome to
  51. *    provide the arp.library with your work and call on it freely.
  52. *
  53. *    You are equally welcome to add new functions, improve the ones
  54. *    within, or suggest additions.
  55. *
  56. *    BCPL programs are not welcome to call on the arp.library.
  57. *    The welcome mat is out to all others.
  58. ***********************************************************************
  59.  
  60.     IFND EXEC_TYPES_I
  61.     INCLUDE "exec/types.i"
  62.     ENDC
  63.  
  64.     IFND EXEC_LIBRARIES_I
  65.     INCLUDE "exec/libraries.i"
  66.     ENDC
  67.  
  68.     IFND EXEC_LISTS_I
  69.     INCLUDE "exec/lists.i"
  70.     ENDC
  71.  
  72.     IFND EXEC_SEMAPHORES_I
  73.     INCLUDE "exec/semaphores.i"
  74.     ENDC
  75.  
  76.     IFND LIBRARIES_DOS_I
  77.     INCLUDE "libraries/dos.i"
  78.     ENDC
  79.  
  80.     IFND LIBRARIES_DOS_LIB_I
  81.     INCLUDE "libraries/dos_lib.i"
  82.     ENDC
  83.  
  84.  
  85.     STRUCTURE ArpBase,LIB_SIZE    ; Standard library node
  86.         APTR    DosRootNode    ; Copy of dl_Root
  87.         UBYTE    Flags        ; Not used, yet!
  88.         UBYTE    ESCChar     ; Character to be used for escaping
  89.         LONG    ArpReserved1    ; ArpLib's use only!!
  90.         CPTR    EnvBase     ; Dummy library for MANX compatibility
  91.         CPTR    DosBase     ; Cached DosBase
  92.         CPTR    GfxBase     ; Cached GfxBase
  93.         CPTR    IntuiBase    ; Cached IntuitionBase
  94.         STRUCT    ResLists,MLH_SIZE ; Resource trackers
  95.         ULONG    ResidentPrgList ; Resident Programs.
  96.         STRUCT    ResPrgProtection,SS_SIZE    ; protection for above
  97.         ULONG    SegList     ; Pointer to loaded libcode (a BPTR).
  98.         LABEL    ArpLib_SIZEOF
  99.  
  100. *--------------- Following is here only for compatibility with MANX,
  101. *--------------- don't use in new code!
  102.  
  103.     STRUCTURE EnvLib,LIB_SIZE    ; fake library for MANX
  104.         CPTR    EnvSpace    ; access only when Forbidden!
  105.         ULONG    EnvSize     ; size of environment
  106.         ULONG    EnvArpBase    ; for EXPUNGE
  107.         LABEL    EnvLib_SIZEOF
  108.  
  109. *---------- Flags bit definitions
  110. *
  111. * These are used in release 33.4, but not by the library code, instead,
  112. * individual programs which are affected check for these. Not ideal, but
  113. * such is life.
  114. *
  115. *-------------------------------------------------------
  116.  
  117.     BITDEF    ARP,WILD_WORLD,0    ; Mixed BCPL/Normal wildcards.
  118.     BITDEF    ARP,WILD_BCPL,1     ; Pure bcpl.
  119.  
  120. *----------- Rest of library style stuff
  121.  
  122. ArpName MACRO
  123.     dc.b    'arp.library',0
  124.     ds.w    0
  125.     ENDM
  126.  
  127. *---------- Current arp.library version.
  128.  
  129. ArpVersion EQU    39
  130.  
  131. *-------- Alert Object
  132. * The alert object is what you use if you really must return an alert
  133. * to the user.    You would normally OR this with another alert number from
  134. * the alerts.h file.  Generally, these should be NON deadend alerts.
  135. *
  136. * For example, if you can't open ArpLibrary:
  137. *
  138. *    GURU    AG_OpenLib!AO_ArpLib
  139. *----------------------------------------
  140.  
  141. AO_ArpLib    EQU    $00008036    ; alert object
  142.  
  143. *-------- Specific Alerts you can get from ArpLib. -----------*
  144.  
  145. AN_ArpLib    EQU    $03600000    ; alert number
  146. AN_ArpNoMem    EQU    $03610000    ; Arplibrary out of memory.
  147. AN_ArpInputMem    EQU    $03610002    ; No memory for input buffer.
  148. AN_ArpNoMakeEnv EQU    $83610003    ; No memory to make EnvLib
  149.  
  150. AN_ArpNoDOS    EQU    $83630001    ; Can't open DOS library
  151. AN_ArpNoGfx    EQU    $83630002    ; Can't open graphics
  152. AN_ArpNoIntuit    EQU    $83630003    ; Can't open intuition
  153. AN_BadPackBlues EQU    $83640000    ; Bad packet returned to SendPacket()
  154.  
  155. AN_Zombie    EQU    $83600003    ; AsyncRun() Exit code didn't.
  156.  
  157. AN_ArpScattered EQU    $83600002    ; Scatter loading not allowed for lib.
  158.  
  159. *---------- Tiny ALERT macro, assumes ExecBase is already in A6, also that you
  160. *---------- have nothing important in d7, also that you want to return immediately.
  161.  
  162. GURU    MACRO    * optional alert number
  163.     IFNC    '\1',''
  164.     move.l    #\1,D7
  165.     ENDC
  166.     jmp    _LVOAlert(a6)
  167.     ENDM
  168.  
  169. MYALERT MACRO * ancient compatibility
  170.     GURU    \1
  171.     ENDM
  172.  
  173. *------------- Library Vector Offsets.
  174.  
  175.  
  176. *
  177. * This macro is used to define the DOS offsets without redefining the symbols-
  178. *    To get the DOS symbols, INCLUDE dos_lib.i
  179. *
  180. LIBSKP    MACRO
  181. COUNT_LIB   SET     COUNT_LIB-LIB_VECTSIZE
  182.     ENDM
  183.  
  184.     LIBINIT
  185.  
  186. ***
  187.     LIBDEF    _LVOPrintf        ; Print formatted data on current output.
  188.     LIBDEF    _LVOFPrintf        ; Print formatted data on file.
  189.     LIBDEF    _LVOPuts        ; Print string\n on stdout.
  190.     LIBDEF    _LVOReadLine        ; Get a line from stdin.
  191.     LIBDEF    _LVOGADS        ; Get args using template
  192.     LIBDEF    _LVOAtol        ; Convert Ascii to long int.
  193.     LIBDEF    _LVOEscapeString    ; Handle escapes in string.
  194.     LIBDEF    _LVOCheckAbort        ; Check for CNTRL-C
  195.     LIBDEF    _LVOCheckBreak        ; Check for CNTRL c d e or f
  196.     LIBDEF    _LVOGetenv        ; Get value of environment variable
  197.     LIBDEF    _LVOSetenv        ; Set value of environment variable
  198.     LIBDEF    _LVOFileRequest     ; Filename Requester
  199.     LIBDEF    _LVOCloseWindowSafely    ; Closes shared IDCMP window w/o GURU
  200.     LIBDEF    _LVOCreatePort        ; Create a message port
  201.     LIBDEF    _LVODeletePort        ; Delete a message port
  202.     LIBDEF    _LVOSendPacket        ; Send a dos packet
  203.     LIBDEF    _LVOInitStdPacket    ; initialize a standard packet
  204.     LIBDEF    _LVOPathName        ; Return Complete pathname of file/directory.
  205.     LIBDEF    _LVOAssign        ; Assign a logical device name
  206.     LIBDEF    _LVODosAllocMem     ; DOS compatible memory allocator
  207.     LIBDEF    _LVODosFreeMem        ; DOS compatible memory free-er
  208.     LIBDEF    _LVOBtoCStr        ; Copy a BCPL string to C string
  209.     LIBDEF    _LVOCtoBStr        ; Copy a C string to BCPL string
  210.     LIBDEF    _LVOGetDevInfo        ; Get pointer to head of DevInfo
  211.     LIBDEF    _LVOFreeTaskResList    ; Free Tracked resources for this task
  212.     LIBDEF    _LVOArpExit        ; Exit, freeing tracked resources.
  213.     LIBDEF    _LVOArpAlloc        ; Allocate memory with tracking
  214.     LIBDEF    _LVOArpAllocMem     ; Track AllocMem allocation
  215.     LIBDEF    _LVOArpOpen        ; Track open files
  216.     LIBDEF    _LVOArpDupLock        ; Track duped locks
  217.     LIBDEF    _LVOArpLock        ; Track allocated locks
  218.     LIBDEF    _LVORListAlloc        ; Like ArpAlloc for free reslist
  219.     LIBDEF    _LVOFindCLI        ; Get a process given a task number
  220.     LIBDEF    _LVOQSort        ; Quick Sort
  221.  
  222.     LIBDEF    _LVOPatternMatch    ; Match a string with a pattern (wildcards!)
  223.     LIBDEF    _LVOFindFirst        ; Search directory w/wildcards
  224.     LIBDEF    _LVOFindNext        ; Continue search w/wildcards
  225.     LIBDEF    _LVOFreeAnchorChain    ; Free mem from FindFirst/Next
  226.  
  227.     LIBDEF    _LVOCompareLock     ; Compare two disk locks
  228.  
  229.     LIBDEF    _LVOFindTaskResList    ; Find resource list for this task
  230.     LIBDEF    _LVOCreateTaskResList    ; Create a new nested task reslist
  231.     LIBDEF    _LVOFreeResList     ; Free an un-attached reslist
  232.     LIBDEF    _LVOFreeTrackedItem    ; Free a tracked item
  233.     LIBDEF    _LVOGetTracker        ; Get a tracker node
  234.  
  235.     LIBDEF    _LVOGetAccess        ; Lock access to a node
  236.     LIBDEF    _LVOFreeAccess        ; Allow resource to flush if lowmem
  237.  
  238.     LIBDEF    _LVOFreeDAList        ; Free a DosAllocmem list
  239.     LIBDEF    _LVOAddDANode        ; Add a node to a DA list
  240.     LIBDEF    _LVOAddDADevs        ; Add devices to a DA list
  241.  
  242.     LIBDEF    _LVOStrcmp        ; Compare two null-terminated strs
  243.     LIBDEF    _LVOStrncmp        ; Compare up to N chars
  244.     LIBDEF    _LVOToupper        ; Convert to UC
  245.     LIBDEF    _LVOSyncRun        ; Run program as subroutine
  246. * Added V32 of arp.library
  247.     LIBDEF    _LVOASyncRun        ; Run program in background
  248.     LIBDEF    _LVOLoadPrg        ; As for LoadSeg(), but searches Res&Path
  249.     LIBDEF    _LVOPreParse        ; Create tokenized PatternMatch string
  250. * V33
  251.     LIBDEF    _LVOStamptoStr        ; Date stamp to string
  252.     LIBDEF    _LVOStrtoStamp        ; Date string to stamp
  253.  
  254.     LIBDEF    _LVOObtainResidentPrg    ; Get a resident program
  255.     LIBDEF    _LVOAddResidentPrg    ; Add it
  256.     LIBDEF    _LVORemResidentPrg    ; Remove it
  257.     LIBDEF    _LVOUnLoadPrg        ; Check Sum code
  258.     LIBDEF    _LVOLMult        ; long mult
  259.     LIBDEF    _LVOLDiv        ; long division, signed
  260.     LIBDEF    _LVOLMod        ; long %
  261.  
  262.     LIBDEF    _LVOCheckSumPrg     ; Refresh checksum for resident code
  263.     LIBDEF    _LVOTackOn        ; Add A1 onto directory string A0
  264.     LIBDEF    _LVOBaseName        ; Get Filename from complete dir string
  265.     LIBDEF    _LVOReleaseResidentPrg    ; True if code is resident and was released.
  266.  
  267. * V36
  268.     LIBDEF    _LVOSPrintf
  269.     LIBDEF    _LVOGetKeywordIndex
  270.     LIBDEF    _LVOArpOpenLibrary
  271. ***
  272.     LIBDEF    _LVOArpAllocFreq
  273.  
  274. *---------- Return codes you can get from calling Assign:
  275.  
  276. ASSIGN_OK    EQU    0    ; Everything is cool and groovey
  277. ASSIGN_NODEV    EQU    1    ; "Physical" is not valid for assignment
  278. ASSIGN_FATAL    EQU    2    ; Something really icky happened
  279. ASSIGN_CANCEL    EQU    3    ; Tried to cancel something that won't cancel.
  280.  
  281. *--------- Size of buffer you need for ReadLine
  282.  
  283. MaxInputBuf    EQU    256
  284.  
  285. * Macro to declare things as unions:
  286.  
  287. UNION    MACRO    *name,maxsize
  288. UOFFSET SET    SOFFSET
  289. \1    EQU    SOFFSET
  290. SOFFSET SET    SOFFSET+\2
  291.     ENDM
  292. * member of union
  293.  
  294. UMEMB MACRO    * name
  295. \1    EQU    UOFFSET
  296.     ENDM
  297.  
  298. ******************************* File Requester *******************************
  299. ********************** Submit the following to FileRequest() *****************
  300. ******************************************************************************
  301.  
  302.     STRUCTURE FileRequester,0
  303.         CPTR    fr_Hail         ; Hailing text
  304.         CPTR    fr_File         ; *Filename array (FCHARS+1)
  305.         CPTR    fr_Dir            ; *Directory array (DSIZE+1)
  306.         CPTR    fr_Window        ; Window requesting or NULL
  307.         UBYTE    fr_FuncFlags        ; Set bitdef's below
  308.         UBYTE    fr_reserved1        ; Set to NULL
  309.         APTR    fr_Function        ; Func to call for wildcards
  310.         LONG    fr_reserved2        ; RESERVED
  311.         LABEL    fr_SIZEOF
  312.  
  313. *****************************************************************
  314. * The following are the equates for fr_FuncFlags. These bits tell
  315. * FileRequest() what your fr_UserFunc is expecting, and what FileRequest()
  316. * should call it for.
  317. *
  318. * You are called like so
  319. * fr_Function(Mask, Object)
  320. * ULONG Mask
  321. * CPTR    *Object
  322. *
  323. * The Mask is a copy of the flag value that caused FileRequest() to call
  324. * your function. You can use this to determine what action you need to
  325. * perform, and exactly what Object is, so you know what to do and
  326. * what to return.
  327. *
  328.     BITDEF    FR,DoWildFunc,7 ; Call me with a FIB and a name, ZERO return accepts.
  329.     BITDEF    FR,DoMsgFunc,6    ; You get all IDCMP message not for FileRequest()
  330.     BITDEF    FR,DoColor,5    ; Set this bit for that new and differnt look
  331.     BITDEF    FR,NewIDCMP,4    ; Force a new IDCMP (only if fr_Window != NULL)
  332.     BITDEF    FR,NewWindFunc,3 ; You get to modify the NewWindow struct.
  333.     BITDEF    FR,AddGadFunc,2 ; You get to add gadgets
  334.     BITDEF    FR,GEventFunc,1 ; Function to call if one of your gads is selected
  335.     BITDEF    FR,ListFunc,0    ; not implemented.
  336.  
  337. FCHARS    EQU    32            ; Directory name sizes
  338. DSIZE    EQU    33
  339.  
  340. * The bits FR2Bxxx are in the fr_reserved1 byte.
  341.     BITDEF    FR2,LongPath,0    ; Specify that fr_Dir buffer is 256
  342.                 ;  bytes long
  343. LONG_DSIZE    EQU    254    ; If FRB_LongPath, you must allocate
  344.                 ; LONG_DSIZE+1 rather than DSIZE+1 for
  345.                 ; fr_Dir buffer
  346. LONG_FSIZE    EQU    126
  347.  
  348. FR_FIRST_GADGET EQU    $7680        ; User gadgetID's must be less than this.
  349. ************************************************************************
  350. ************************ PATTERN MATCHING ******************************
  351. ************************************************************************
  352.  
  353. * structure expected by FindFirst, FindNext.
  354. * Allocate this structure and initialize it as follows:
  355. *
  356. * Set ap_BreakBits to the signal bits (CDEF) that you want to take a
  357. * break on, or NULL, if you don't want to convenience the user.
  358. *
  359. * If you want to have the FULL PATH NAME of the files you found,
  360. * allocate a buffer at the END of this structure, and put the size of
  361. * it into ap_Length.  If you don't want the full path name, make sure
  362. * you set ap_Length to zero.  In this case, the name of the file, and stats
  363. * are available in the ap_Info, as per usual.
  364. *
  365. * Then call FindFirst() and then afterwards, FindNext() with this structure.
  366. * You should check the return value each time (see below) and take the
  367. * appropriate action, ultimately calling FreeAnchorChain() when there are
  368. * no more files and you are done.  You can tell when you are done by
  369. * checking for the normal AmigaDOS return code ERROR_NO_MORE_ENTRIES.
  370. *
  371.  
  372.     STRUCTURE AnchorPath,0
  373.         LABEL    ap_First
  374.         CPTR    ap_Base     ; pointer to first anchor
  375.         LABEL    ap_Current
  376.         CPTR    ap_Last     ; pointer to last anchor
  377.         LONG    ap_BreakBits    ; Bits we want to break on
  378.         LONG    ap_FoundBreak    ; Bits we broke on. Also returns ERROR_BREAK
  379.         LABEL    ap_Length    ; Old compatability for LONGWORD ap_Length
  380.         BYTE    ap_Flags    ; New use for extra word.
  381.         BYTE    ap_Reservred
  382.         WORD    ap_Strlen    ; This is what ap_Length used to be
  383.         STRUCT    ap_Info,fib_SIZEOF    ; FileInfoBlock
  384.         LABEL    ap_Buf        ; Buffer for path name, allocated by user
  385.         LABEL    ap_SIZEOF
  386.  
  387.  
  388.     BITDEF    AP,DOWILD,0        ; User option ALL
  389.     BITDEF    AP,ITSWILD,1        ; Set by FindFirst, used by FindNext
  390.                     ; Application can test APB_ITSWILD, too.
  391.     BITDEF    AP,DODIR,2        ; Bit is SET if a DIR node should be
  392.                     ; entered. Application can RESET this
  393.                     ; bit after FindFirst/FindNext to AVOID
  394.                     ; entering a dir.
  395.     BITDEF    AP,DIDDIR,3        ; Bit is SET for an "expired" dir node.
  396.     BITDEF    AP,NOMEMERR,4        ; Set on memory error
  397.     BITDEF    AP,DODOT,5        ; If set, allow conversion of '.' to CurrentDir
  398.  
  399.     STRUCTURE    AChain,0
  400.         CPTR    an_Child
  401.         CPTR    an_Parent
  402.         LONG    an_Lock
  403.         STRUCT    an_Info,fib_SIZEOF    ; FileInfoBlock
  404.         BYTE    an_Flags
  405.         LABEL    an_String
  406.         LABEL    an_SIZEOF
  407.  
  408.     BITDEF    DD,PatternBit,0
  409.     BITDEF    DD,ExaminedBit,1
  410.     BITDEF    DD,Completed,2
  411.     BITDEF    DD,AllBit,3
  412.  
  413.  
  414. * Constants used by wildcard routines, these are the pre-parsed tokens
  415. * referred to by pattern match.  It is not necessary for you to do
  416. * anything about these, FindFirst() FindNext() handle all these for you.
  417.  
  418. P_ANY        EQU    $80    ; Token for '*' or '#?
  419. P_SINGLE    EQU    $81    ; Token for '?'
  420. P_ORSTART    EQU    $82    ; Token for '('
  421. P_ORNEXT    EQU    $83    ; Token for '|'
  422. P_OREND     EQU    $84    ; Token for ')'
  423. P_TAG        EQU    $85    ; Token for '{'
  424. P_TAGEND    EQU    $86    ; Token for '}'
  425. P_NOTCLASS    EQU    $87    ; Token for '^'
  426. P_CLASS     EQU    $88    ; Token for '[]'
  427. P_REPBEG    EQU    $89    ; Token for '['
  428. P_REPEND    EQU    $8A    ; Token for ']'
  429.  
  430. * Values for an_Status, NOTE: These are the actual bit numbers
  431.  
  432. COMPLEX_BIT    EQU    1    ; Parsing complex pattern
  433. EXAMINE_BIT    EQU    2    ; Searching directory
  434.  
  435. * Returns from FindFirst(), FindNext()
  436. * You can also get dos error returns, such as ERROR_NO_MORE_ENTRIES,
  437. * these are in the dos.h file.
  438. *
  439. ERROR_BUFFER_OVERFLOW    EQU    303    ; User or internal buffer overflow
  440. ERROR_BREAK        EQU    304    ; A break character was received
  441. ERROR_NOT_EXECUTABLE    EQU    305    ; A file has E bit cleared
  442.  
  443.  
  444. * Structure used by AddDANode, AddDADevs, FreeDAList
  445. *
  446. * This structure is used to create lists of names,
  447. * which normally are devices, assigns, volumes, files, or directories.
  448.  
  449.     STRUCTURE DirectoryEntry,0
  450.         CPTR    de_Next         ; Next in list
  451.         BYTE    de_Type         ; DLX_mumble
  452.         BYTE    de_Flags        ; For future expansion, do not use!
  453.         LABEL    de_Name         ; name of thing found
  454.         LABEL    de_SIZEOF
  455.  
  456. * Defines you use to get a list of the devices you want to look at.
  457. * For example, to get a list of all directories and volumes, do
  458. *
  459. *    move.l    #DLF_DIRS!DLF_VOLUMES,d0
  460. *    move.l    myDalist(pc),a0
  461. *    SYSCALL AddDADevs        ; ArpBase already in A6, of course
  462. *
  463. * After this, you can examine the de_Type field of the elements added
  464. * to your list (if any) to discover specifics about the objects added.
  465. *
  466. * Note that if you want only devices which are also disks, you must
  467. * request DLF_DEVICES!DLF_DISKONLY
  468. *
  469.  
  470.     BITDEF    DL,DEVICES,0    ; Return devices
  471.     BITDEF    DL,DISKONLY,1    ; Modifier for above: Return disk devices only
  472.     BITDEF    DL,VOLUMES,2    ; Return volumes only
  473.     BITDEF    DL,DIRS,3    ; Return assigned devices only
  474.  
  475. * Legal de_Type values, check for these after a call to AddDADevs(), or
  476. * use on your own as the ID values in AddDANode()
  477.  
  478. DLX_FILE    EQU    0    ; AddDADevs() can't determine this
  479. DLX_DIR     EQU    8    ; AddDADevs() can't determine this
  480. DLX_DEVICE    EQU    16    ; It's a resident device
  481.  
  482. DLX_VOLUME    EQU    24    ; Device is a volume
  483. DLX_UNMOUNTED    EQU    32    ; Device is not resident
  484.  
  485. DLX_ASSIGN    EQU    40    ; Device is a logical assignment
  486.  
  487. ************************************************************************
  488. ************************** RESOURCE TRACKING ***************************
  489. ************************************************************************
  490.  
  491. *
  492. * NOTE: This is a DosAllocMem'd list, this is done for you when you
  493. * call CreateTaskResList(), typically, you won't need to access/allocate
  494. * this structure.
  495. *
  496.     STRUCTURE ResList,0
  497.         STRUCT    rl_Node,MLN_SIZE  ; Used by arplib to link reslist's
  498.         CPTR    rl_TaskID       ; Owner of this list
  499.         STRUCT    rl_FirstItem,MLH_SIZE    ; List of TrackedResource's
  500.         CPTR    rl_Link     ; For temp removal from task rlist
  501.         LABEL    RL_SIZEOF
  502.  
  503. * The rl_FirstItem list (above) is a list of TrackedResource (below).
  504. * It is very important that nothing in this list depend on the task
  505. * existing at resource freeing time (i.e., RemTask(0L) type stuff,
  506. * DeletePort() and the rest).
  507. *
  508. * The tracking functions return a struct Tracker *Tracker to you, this
  509. * is a pointer to whatever follows the tr_ID variable.
  510. * The default case is reflected below, and you get it if you call
  511. * GetTracker() ( see DefaultTracker below).
  512. *
  513. * NOTE: The two user variables mentioned in an earlier version don't
  514. * exist, and never did. Sorry about that (SDB).
  515. *
  516. * However, you can still use ArpAlloc to allocate your own tracking
  517. * nodes and they can be any size or shape you like, as long as the
  518. * base structure is preserved.    They will be freed automagically
  519. * just like the default trackers.
  520.  
  521.     STRUCTURE TrackedObject,0
  522.         CPTR  tr_Resource        ; whatever
  523.         LONG  tg_Verify            ; for use during TRAK_GENERIC
  524.         LABEL TrackedObject_SIZEOF
  525.  
  526.     STRUCTURE TrackedExtra,0
  527.         APTR  tg_Function        ; function to call for TRAK_GENERIC
  528.         CPTR  tr_Window2        ; for TRAK_WINDOW
  529.         LABEL TrackedExtra_SIZEOF
  530.  
  531.     STRUCTURE TrackedResource,0
  532.         STRUCT    tr_Node,MLN_SIZE    ; Double linked pointer
  533.         BYTE    tr_Flags        ; Don't touch
  534.         BYTE    tr_Lock         ; Don't touch, for Get/FreeAcess
  535.         SHORT    tr_ID            ; ID for this item class
  536. * The struct DefaultTrackter portion of the structure
  537. * The stuff below this point can conceivably vary, depending
  538. * on user needs, etc.  This reflects the default.
  539.         STRUCT    tr_Object,TrackedObject_SIZEOF    ; The thing being tracked
  540.         STRUCT    tr_Extra,TrackedExtra_SIZEOF    ; only needed sometimes
  541.         LABEL    trk_SIZEOF        ; trk_ fixes COLLISION WITH TMPRAS...
  542.  
  543. tg_Value EQU tg_Verify
  544.  
  545. * You get a pointer to a struct of the following type when you call
  546. * GetTracker().  You can change this, and use ArpAlloc() instead of
  547. * GetTracker() to do tracking. Of course, you have to take a wee bit
  548. * more responsibility if you do, as well as if you use TRAK_GENERIC
  549. * stuff.
  550. *
  551. * TRAK_GENERIC folks need to set up a task function to be called when an
  552. * item is freed.  Some care is required to set this up properly.
  553. *
  554. * Some special cases are indicated by the unions below, for TRAK_WINDOW,
  555. * if you have more than one window opened, and don't want the IDCMP closed
  556. * particularly, you need to set a ptr to the other window in dt_Window2.
  557. * See CloseWindowSafely() for more info.  If only one window, set this to NULL.
  558.  
  559.     STRUCTURE DefaultTracker,-2
  560.         SHORT    dt_ID            ; Different from C file, but it's ok.
  561.         STRUCT  dt_Object,TrackedObject_SIZEOF    ; the object being tracked
  562.         STRUCT    dt_Extra,TrackedExtra_SIZEOF
  563.         LABEL    dt_SIZEOF
  564.  
  565. * Tracked Item Types
  566. *    The id types below show the types of resources which may
  567. * be tracked in a resource list.
  568. *
  569. TRAK_AAMEM    EQU    0        ; Default generic (ArpAlloc) element
  570. TRAK_LOCK    EQU    1        ; File Lock
  571. TRAK_FILE    EQU    2        ; Opened File
  572. TRAK_WINDOW    EQU    3        ; Window (see discussion)
  573. TRAK_SCREEN    EQU    4        ; Screen
  574. TRAK_LIBRARY    EQU    5        ; Opened library
  575. TRAK_DAMEM    EQU    6        ; Pointer to DosAllocMem block
  576. TRAK_MEMNODE    EQU    7        ; AllocEntry() node.
  577. TRAK_SEGLIST    EQU    8        ; Program Segment List
  578. TRAK_RESLIST    EQU    9        ; ARP (nested) ResList
  579. TRAK_MEM    EQU    10        ; Memory ptr/length
  580. TRAK_GENERIC    EQU    11        ; Generic Element
  581. TRAK_DALIST    EQU    12        ; DAlist ( as used by file request )
  582. TRAK_ANCHOR    EQU    13        ; Anchor chain
  583. TRAK_FREQ    EQU    14        ; FileRequest struct
  584. TRAK_FONT    EQU    15        ; GfxBase CloseFont()
  585. TRACK_MAX    EQU    15        ; Anything else is tossed.
  586.  
  587.     BITDEF    TR,UNLINK,7        ; Bit for freeing the node
  588.     BITDEF    TR,RELOC,6        ; This element may be relocated (not used yet
  589.     BITDEF    TR,MOVED,5        ; Item moved
  590.  
  591. *--- Returns from CompareLock()
  592.  
  593. LCK_EQUAL    EQU    0    ; Locks refer to the same object
  594. LCK_VOLUME    EQU    1    ; Locks are on the same volume
  595. LCK_DIFVOL1    EQU    2    ; Locks are on different volumes
  596. LCK_DIFVOL2    EQU    3    ; Locks are on different volumes
  597.  
  598. *----------- Stuff For ASyncRun() and friends
  599. *---------- Message sent back on request by an exiting process.
  600. *---------- You request this by putting the address of your
  601. *---------- message in pcb_LastGasp, and initializing the
  602. *---------- ReplyPort variable of the zombiemsg to the port you wish
  603. *---------- the message posted to.
  604.  
  605.     STRUCTURE ZombieMsg,MN_SIZE
  606.         ULONG    zm_TaskNum        ; task ID
  607.         ULONG    zm_ReturnCode        ; Process's return code
  608.         ULONG    zm_Result2        ; System return
  609.         STRUCT    zm_ExitTime,ds_SIZEOF    ; Date stamp at time of exit
  610.         ULONG    zm_UserInfo        ; for whatever you like
  611.         LABEL    zm_SIZEOF
  612.  
  613. *------------ Structure required by ASyncRun() -- see docs for more info.
  614. *------------
  615.     STRUCTURE pcbConsole,0
  616.         BPTR pcb_SplatFile     ; file to use for Open("*")
  617.         BYTE pcb_ConName     ; CON: filename
  618.         LABEL pcbConsole_SIZEOF
  619.  
  620.     STRUCTURE ProcessControlBlock,0
  621.         ULONG    pcb_StackSize    ; Stacksize for new process
  622.         BYTE    pcb_Pri     ; Priority of new process
  623.         BYTE    pcb_Control    ; Control bits, see BITDEF's below.
  624.         APTR    pcb_TrapCode    ; Optional trapcode vector
  625.         ULONG    pcb_Input    ; Optional default input
  626.         ULONG    pcb_Output    ; Optional default output
  627.         STRUCT    pcb_Console,pcbConsole_SIZEOF
  628.         ULONG    pcb_LoadedCode    ; If not null, use this code
  629.         CPTR    pcb_LastGasp    ; ReplyMsg to be filled in by exit code
  630.         CPTR    pcb_WBProcess    ; Valid only when PRB_NOCLI.
  631.         LABEL    pcb_SIZEOF
  632.  
  633. *---- bits to set in pcb_Control
  634.  
  635.     BITDEF    PR,SAVEIO,0        ; don't release/check file handles
  636.     BITDEF    PR,CLOSESPLAT,1     ; close splat, must request explicitly
  637.     BITDEF    PR,NOCLI,2        ; Don't want a CLI
  638.     BITDEF    PR,CODE,4        ; Actual code address. Be Careful!
  639.     BITDEF    PR,STDIO,5        ; Do the stdio thing, splat = CON:filename
  640.  
  641.  
  642. *----- Error returns
  643.  
  644. PR_NOFILE    EQU    -1    ; Can't find or LoadSeg file.
  645. PR_NOMEM    EQU    -2    ; No memory for one thing or another
  646. PR_NOSLOT    EQU    -4    ; No slot in task array
  647. PR_NOINPUT    EQU    -5    ; Can't get input file
  648. PR_NOOUTPUT    EQU    -6    ; Can't get output file
  649. PR_NOSTDIO    EQU    -11    ; Couldn't get stdio handles.
  650.  
  651. *---- The following error returns are obsolete in versions 35+
  652. *---- will not be returned.
  653. PR_NOCLI    EQU    -3    ; Caller must be CLI (SyncRun() only).
  654. PR_NOLOCK    EQU    -7    ; Problem obtaining locks
  655. PR_ARGERR    EQU    -8    ; Bad Argument
  656. PR_NOBCPL    EQU    -9    ; Bad program passed to ASyncRun
  657. PR_BADLIB    EQU    -10    ; Bad library version
  658. *
  659. * Version 35 adds the following error messages.
  660. *
  661. PR_WANTSMESSAGE EQU    -12    ; Child wants you to report IoErr() to user.
  662. PR_NOSHELLPROC    EQU    -13    ; Can't create a shell/cli process
  663. *
  664. PR_NOEXEC    EQU    -14
  665. PR_SCRIPT    EQU    -15
  666.  
  667. * Version 35 ASyncRun () allows you to create an independent interactive or
  668. * background Shell/CLI. You need this variant of the pcb structure to
  669. * do it, and you also have new values for nsh_Control, see below.
  670. *
  671. * Syntax for Interactive shell is:
  672. *
  673. * rc = ASyncRun ("Optional Window Name", "Optional From File", &NewShell);
  674. *
  675. * Syntax for a background shell is:
  676. * rc = ASyncRun ("Command line", 0L, &NewShell);
  677. *
  678. * Same syntax for an Execute style call, but you have to be on drugs
  679. * if you want to do that.
  680. *
  681.     STRUCTURE NewShell,0
  682.     ULONG nsh_StackSize     ; stacksize shell will use for children
  683.     BYTE  nsh_Pri         ; ignored by interactive shells
  684.     UBYTE nsh_Control     ; bits/values: see above
  685.     CPTR  nsh_LogMsg     ; Optional login message, if null, use default.
  686.     CPTR  nsh_Input      ; ignored by interactive shells, but
  687.     CPTR  nsh_Output     ; used by background and execute options.
  688.     STRUCT nsh_RESERVED,(5*4)
  689.     LABEL nsh_SIZEOF
  690.  
  691. *-- Bit Values for nsh_Control, you should use them as shown below, or
  692. *-- just use the actual values indicated: the bits don't really combine
  693. *-- otherwise.
  694.  
  695.     BITDEF    PR,FB,7     ; alt function bit
  696.     BITDEF    PR,CLI,0    ; Do a CLI, not a shell.
  697.     BITDEF    PR,BACKGROUND,1 ; Background shell.
  698.     BITDEF    PR,EXECUTE,2    ; Do as for Execute
  699.     BITDEF    PR,INTERACTIVE,3 ; run an interactive shell
  700. *-- Actual values to stuff into nsh_Control.
  701.  
  702. INTERACTIVE_SHELL EQU (PRF_FB!PRF_INTERACTIVE)    ; Gimme a newshell!
  703. INTERACTIVE_CLI  EQU (PRF_FB!PRF_INTERACTIVE!PRF_CLI) ; Gimme that ol newcli!
  704. BACKGROUND_SHELL EQU (PRF_FB!PRF_BACKGROUND) ; gimme a background shell
  705. EXECUTE_ME     EQU (PRF_FB!PRF_BACKGROUND!PRF_EXECUTE) ; aptly named, doncha think?
  706.  
  707.     IFND ERROR_BAD_STREAM_NAME
  708. ERROR_BAD_STREAM_NAME    EQU    206 ; not defined in dos.i - imagine that.
  709.    ENDC
  710.  
  711. *---------- Programs should return this as result2 if no CLI:
  712.  
  713. ERROR_NOT_CLI    EQU    400    ; Program/function needed a CLI
  714.  
  715. *-------------------------------- Resident Program support -------*
  716. *--- This node is allocated for you when you AddResidentPrg() a segment.
  717. *--- They are stored as a single linked list with the root in ArpBase,
  718. *--- if you absolutely *must* wander through this list instead of
  719. *--- using the supplied functions, then you must first obtain the
  720. *--- the semaphore which protects this list, and then release it afterwards.
  721. *--- Do not use Forbid() and Permit() to gain exclusive access!
  722. *------------------------------------------------------------------*
  723.  
  724.         STRUCTURE ResidentProgramNode,0
  725.                 CPTR    rpn_Next        ; next node, or NULL
  726.                 WORD    rpn_Usage       ; current number of simultaneous users
  727.                 UWORD   rpn_AccessCnt   ; total times used
  728.                 ULONG   rpn_CheckSum    ; checksum for this code
  729.                 BPTR    rpn_Segment     ; the segment
  730.         UWORD    rpn_Flags    ; See flag bit definitions below.
  731.                 LABEL   rpn_Name        ; the name of the program.
  732.                 LABEL   rpn_SIZEOF
  733.  
  734.     BITDEF    RPN,NOCHECK,0        ; Set in rpn_Flags for no checksumming.
  735.     BITDEF    RPN,CACHE,1        ; Private usage in V1.3.
  736.  
  737. *--- If your program starts with this structure, ASyncRun() and SyncRun()
  738. *--- will override a users stack request with the value in rpt_StackSize.
  739. *--- Furthermore, if you are actually attached to the resident list,
  740. *--- a memory block of size rpt_DataSize will be allocated for you, and
  741. *--- a pointer to this data passed to you in register A4.  You may use this
  742. *--- block to clone the data segment of programs, thus resulting in
  743. *--- one copy of text, but multiple copies of data/bss for each process
  744. *--- invocation.  If you are resident, your program will start at rpt_Instruction,
  745. *--- otherwise, it will be launched from the initial branch.
  746.  
  747.  
  748.     STRUCTURE    ResidentProgramTag,0
  749.         BPTR    rpt_NextSeg    ; provided by DOS at LoadSeg time.
  750.         UWORD    rpt_BRA     ; Short branch to executable
  751.         UWORD    rpt_Magic    ; resident majik value
  752.         ULONG    rpt_StackSize    ; min stack for this process
  753.         ULONG    rpt_DataSize    ; Size of data allocation (may be zero)
  754.         LABEL    rpt_Instruction ; start here if resident
  755.  
  756. ************* The form of the ARP allocated node in your tasks memlist when
  757. ************* launched as a resident program, note that the data portion
  758. ************* of the node will only exist if you have specified a nonzero
  759. ************* value for rpt_DataSize. Note also that this structure is READ ONLY,
  760. ************* modify values in this at your own risk. The stack stuff is for
  761. ************* tracking, if you need actual addresses or stacksize, check the
  762. ************* normal places for it in your process/task structure.
  763.  
  764.     STRUCTURE ProcessMemory,LN_SIZE
  765.         UWORD    pm_Num        ; number of entries, 1 if no data 2 if data
  766.         CPTR    pm_Stack
  767.         ULONG    pm_StackSize
  768.         CPTR    pm_Data     ; pointer to data
  769.         ULONG    pm_DataSize
  770.         LABEL    pm_Sizeof
  771. * Search for the name below on your TC_MEMENTRY list if you need to
  772. * get the above node.  Remember, you modify the above at your own
  773. * risk!
  774. *
  775. PMEM_NAME    MACRO
  776.     dc.b    'ARP_PMEM',0    ; memlist node for stack and/or data
  777.     ds.w    0
  778.     ENDM
  779.  
  780. RESIDENT_MAGIC        EQU    $4AFC        ; same as RTC_MATCHWORD (trapf)
  781.  
  782. ********** Note that the initial branch and the rpt_Instruction do not
  783. ********** have to be the same.  This allows different actions to be taken
  784. ********** if you are diskloaded or resident.  DataSize memory will be allocated
  785. ********** only if you are resident, but stacksize will override all user
  786. ********** stack requests.
  787. **********
  788. ********** Macro to facilitate initialization of this structure, place at start
  789. ********** of code.
  790. ********** Usage is RESIDENT STACKSIZE [ optional  DATASIZE LABEL ]
  791.  
  792. RESIDENT MACRO
  793.  IFEQ NARG
  794.     FAIL
  795.  ENDC
  796.  IFC '\3',''
  797.     bra.s    resident_start\@    ; branch to rp_instruction
  798.  ENDC
  799.  IFNC '\3',''
  800.     bra.s    \3        ; branch to user label
  801.  ENDC
  802.     dc.w    RESIDENT_MAGIC        ; our magic value
  803.     dc.l    \1            ; stacksize
  804.  IFNC '\2',''
  805.     dc.l    \2            ; datasize
  806.  ENDC
  807.  IFC '\2',''
  808.     dc.l    0            ; of zero
  809.  ENDC
  810. resident_start\@
  811.     ENDM
  812.  
  813. *--------- String/Date structures etc
  814.     STRUCTURE    DateTime,0
  815.     STRUCT    dat_Stamp,ds_SIZEOF    ;DOS DateStamp
  816.     UBYTE    dat_Format        ;controls appearance of dat_StrDate
  817.     UBYTE    dat_Flags        ;see BITDEF's below
  818.     CPTR    dat_StrDay        ;day of the week string
  819.     CPTR    dat_StrDate        ;date string
  820.     CPTR    dat_StrTime        ;time string
  821.     LABEL    dat_SIZEOF
  822. *
  823. * You need this much room for each of the DateTime strings:
  824. LEN_DATSTRING    EQU    10
  825.  
  826. *    flags for dat_Flags
  827. *
  828.     BITDEF    DT,SUBST,0        ;substitute Today, Tomorrow, etc.
  829.     BITDEF    DT,FUTURE,1        ;day of the week is in future
  830. *
  831. *    date format values
  832. *
  833. FORMAT_DOS    equ    0
  834. FORMAT_INT    equ    1
  835. FORMAT_USA    equ    2
  836. FORMAT_CDN    equ    3
  837. FORMAT_MAX    equ    FORMAT_CDN
  838.  
  839. *---------- handy macros
  840.  
  841. LINKEXE MACRO
  842.     LINKLIB _LVO\1,4
  843.     ENDM
  844.  
  845. * LINKDOS now uses ArpBase
  846. * CALLDOS was nuked, to reduce confusion
  847.  
  848. LINKDOS MACRO
  849.     jsr    _LVO\1(a6)
  850.     ENDM
  851.  
  852.  
  853. CALLEXE MACRO
  854.     move.l    4,a6
  855.     jsr    _LVO\1(a6)
  856.     ENDM
  857.  
  858. * SYSCALL re-revised for only one arg
  859. *    DosBase should always use ArpBase, or DosBase, in A6
  860.  
  861. SYSCALL MACRO
  862.     jsr    _LVO\1(A6)
  863.     ENDM
  864.  
  865. * Use this macro if arp.library can't be found.
  866. *    Note the assumption that stack is offset by 8 from return addr.
  867. *    After the macro, register A6 is ARPBASE
  868. *
  869.  
  870. * Use this macro to open arp.library and avoid recoverable alerts.
  871. * Saves D0/A0 on stack.
  872. * After executing, A6 = ARPBASE and stack points at D0/A0
  873. *
  874. OPENARP MACRO
  875.     IFC    '\1',''
  876.     RESIDENT    4000,0
  877.     ENDC
  878.     movem.l d0/a0,-(sp)
  879.     move.l    4,A6
  880.     lea.l    ARPNAME(pc),a1        ; Get ArpBase
  881.     moveq.l #ArpVersion,d0
  882.     SYSCALL OpenLibrary
  883.     tst.l    d0
  884.     bne.s    okgo
  885.     lea    dname,A1
  886.     SYSCALL OpenLibrary
  887.     tst.l    D0
  888.     beq.s    1$
  889.     move.l    D0,A6
  890.     SYSCALL Output            ;standard output file handle
  891.     move.l    d0,d1
  892.     beq.s    1$            ; No output. Phoey.
  893.     lea.l    alibmsg(pc),a0        ;tell user he needs to find library
  894.     move.l    a0,d2
  895. aliblng    equ    28            ; SEE BELOW
  896.     moveq.l    #aliblng,d3
  897.     SYSCALL Write
  898. 1$:    addq    #8,sp
  899.     rts
  900.  
  901. *    IFGE ArpVersion-100
  902. *     FAIL "You lose: Time to bump version report to 3 digits!"
  903. *    ENDC
  904.  
  905. TEM    SET    ArpVersion/10
  906. dname    dc.b    'dos.library',0
  907. alibmsg dc.b    'you need '
  908. ARPNAME: ArpName
  909.     dc.b    ' V',TEM+'0',(ArpVersion-(TEM*10))+'0','+',10
  910.     ds.w    0
  911. okgo:    move.l    D0,A6
  912.     ENDM
  913.  
  914.  
  915. ***       INCLUDE "libraries/arpcompat.i"
  916.  
  917.     ENDC    !LIBRARIES_ARPBASE_I
  918.  
  919. *Local Variables:
  920. *mode:indented-text
  921. *eval:(setq last-change-log "arpheaders.log")
  922. *End:
  923.  
  924.