home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 122.lha / Arp_v1.1 / Libraries / arpbase.h < prev    next >
C/C++ Source or Header  |  1986-11-20  |  26KB  |  663 lines

  1. #ifndef LIBRARIES_ARPBASE_H
  2. #define LIBRARIES_ARPBASE_H
  3. /**********************************************************************
  4.  *
  5.  *    AmigaDOS Replacement Project (ARP) -- Library Include File 'C'
  6.  *
  7.  **********************************************************************
  8.  *
  9.  *    History:
  10.  *
  11.  *    Version:    arpbase.h,v 34.00 02/27/88
  12.  *
  13.  *    Created by:    SDB
  14.  *    Revised:    SDB -- Just bag earlier versions, since didn't have
  15.  *                   time to maintain C header during 'the last days'.
  16.  *                   Created this file mainly from arpbase.i.
  17.  *
  18.  *    Revised:    SDB -- Added stuff for version 32, ASyncRun()
  19.  *                   returns and data structures.
  20.  *            SDB -- Added ERROR_NO_CLI
  21.  *            SDB -- Added final resident data structures,
  22.  *                   final ASyncRun() data structures, and
  23.  *                   date. Final edits for V33.4 release.
  24.  **********************************************************************
  25.  *
  26.  *
  27.  *    Copyright (c) 1987, by Scott Ballantyne
  28.  *
  29.  *    The arp.library, and related code and files may be freely used
  30.  *    by supporters of ARP.  Modules in the arp.library may not be
  31.  *    extracted for us in independent code, but you are welcome to provide
  32.  *    the arp.library with your work and call on it freely.
  33.  *
  34.  *    You are equally welcome to contribute new functions, improve the
  35.  *    ones within, or suggest additions.
  36.  *
  37.  *    BCPL programs are not welcome to call on the arp.library.
  38.  *    The welcome mat is out to all others.
  39.  *
  40.  *********************************************************************/
  41.  
  42. #ifndef EXEC_TYPES_H
  43. #include <exec/types.h>
  44. #endif  !EXEC_TYPES_H
  45.  
  46. #ifndef EXEC_LIBRARIES_H
  47. #include <exec/libraries.h>
  48. #endif  !EXEC_LIBRARIES_H
  49.  
  50. #ifndef EXEC_LISTS_H
  51. #include <exec/lists.h>
  52. #endif  !EXEC_LISTS_H
  53.  
  54. #ifndef EXEC_SEMAPHORES_H
  55. #include <exec/semaphores.h>
  56. #endif  !EXEC_SEMAPHORES_H
  57.  
  58. #ifndef LIBRARIES_DOS_H
  59. #include <libraries/dos.h>
  60. #endif  !LIBRARIES_DOS_H
  61.  
  62. /* arp.library's node structure, not too hefty even now. */
  63.  
  64. struct ArpBase {
  65.     struct Library    LibNode;    /* Standard library node    */
  66.     BPTR        SegList;    /* Pointer to loaded libcode    */
  67.     UBYTE        Flags;        /* Not used, yet!        */
  68.     UBYTE        ESCChar;    /* Character used for escaping    */
  69.     LONG        ArpReserved1;    /* ArpLib's use only!        */
  70.     struct Library    *EnvBase;    /* Dummy library for MANX compatibility */
  71.     struct Library    *DosBase;    /* Dos library pointer        */
  72.     struct Library    *GfxBase;    /* Graphics lib pointer        */
  73.     struct Library    *IntuiBase;    /* Intuition lib pointer    */
  74.     struct MinList    ResLists;    /* Resource trackers        */
  75.     struct ResidentPrgNode *ResidentPrgList; /* Installed programs */
  76.     struct SignalSemaphore ResPrgProtection; /* Protection for above */
  77. };
  78.  
  79. /* Following is here *only* for information and for compatibility
  80.  * with MANX, don't use in new code!
  81.  */
  82.  
  83. struct EnvBase {
  84.     struct Library    LibNode;    /* Standard library node for linkage */
  85.     BYTE        *EnvSpace;    /* Access only when Forbidden! */
  86.     ULONG        EnvSize;    /* Total allocated mem for EnvSpace */
  87.     struct ArpBase    *ArpBase;    /* Added in V32 for Resource Tracking */
  88. };
  89.  
  90. /* These are used in release 33.4, but not by the library code. Instead,
  91.  * individual programs check for these flags. Not ideal, but such is life.
  92.  *
  93.  */
  94.  
  95. #define ARPB_WILD_WORLD 0L        ; Mixed BCPL/Normal wildcards.
  96. #define ARPB_WILD_BCPL  1L        ; Pure BCPL wildcards.
  97.  
  98. #define ARPF_WILD_WORLD (1L << 0)
  99. #define ARPF_WILD_BCPL  (1L << 1)
  100.  
  101. /*************** C SPECIFIC STUFF *************************************/
  102. /* There are a few things in arp.library that are only directly acessable
  103.  * from assembler.  The glue routines provided by us for all 'C' compilers
  104.  * use the following conventions to make these available to C programs.
  105.  * The glue for other language's should use as similar a mechanism as
  106.  * possible, so that no matter what language or compiler we speak, when
  107.  * talk about arp, we will know what the other guy is saying.
  108.  *
  109.  * Here are the cases:
  110.  *    Atol() - if a bad digit is encountered, will store a ERRBADINT in
  111.  *         Errno, the return from Atol() will be the bad character
  112.  *         encountered.  Note: Atol() will not clear Errno if return
  113.  *         is successful.
  114.  *    Trackers: All tracking calls return the Tracker pointer in A1 as a
  115.  *          secondary result, you can obtain this from the global
  116.  *          variable LastTracker immediately after the call.
  117.  * Finally, GetTracker() syntax is differnt for C and assembler, for 'C'
  118.  * the Syntax is GetTraker( ID ), the binding routine will store the ID
  119.  * into the tracker on return.
  120.  *
  121.  * In cases where you have allocated a tracker before you have obtained a
  122.  * resource (usually the most efficient method), and the resource has not
  123.  * been obtained, you will need to clear the tracker id.  The macro CLEAR_ID()
  124.  * has been provided for that purpose.  It expects a pointer to a DefaultTracker
  125.  * sort of struct.
  126.  *
  127.  */
  128.  
  129. extern LONG Errno;    /* Error returns not reportable by functions */
  130. extern struct DefaultTracker *LastTracker;    /* Look here after a tracking call */
  131. #define ERRBADINT    1L    /* Atol() could not convert string to number */
  132.  
  133. #define CLEAR_ID( t )    ((SHORT *) t)[-1] = NULL
  134.  
  135. /*
  136.  * Non controversial, normal library style stuff
  137.  */
  138.  
  139. #define ArpName        "arp.library"        /* Name to use when opening */
  140. #define ArpVersion    34L            /* Current version of arplib */
  141.  
  142.  
  143. /*
  144.  * The alert object is what you use if you really must return an 
  145.  * alert to the user. You would normally OR this with another alert number
  146.  * from the alerts.h file, generally, these 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. #define AO_ArpLib    0x00008036L        /* Alert object */
  153.  
  154. /*
  155.  * Alerts that arp.library can return.
  156.  */
  157.  
  158. #define AN_ArpLib    0x03600000L    /* Alert number            */
  159. #define AN_ArpNoMem    0x03610000L    /* No more memory        */
  160. #define AN_ArpInputMem    0x03610002L    /* No memory for input buffer    */
  161. #define AN_ArpNoMakeEnv    0x83610003L    /* No memory to make EnvLib    */
  162.  
  163. #define AN_ArpNoDOS    0x83630001L    /* Can't open DOS        */
  164. #define AN_ArpNoGfx    0x83630002L    /* Can't open graphics.library    */
  165. #define AN_ArpNoIntuit    0x83630003L    /* Can't open intuition        */
  166. #define AN_BadPackBlues    0x83640000L    /* Bad packet returned to SendPacket()    */
  167. #define AN_Zombie    0x83600003L    /* Zombie roaming around system */
  168.  
  169. #define AN_ArpScattered    0x83600002L    /* Scatter loading not allowed for arp */
  170.  
  171. /* Return codes you can get from calling arp.library's Assign() function */
  172.  
  173. #define ASSIGN_OK    0L    /* Everything is cool and groovey */
  174. #define ASSIGN_NODEV    1L    /* "Physical" is not valid for assignment */
  175. #define ASSIGN_FATAL    2L    /* Something really icky happened */
  176. #define ASSIGN_CANCEL    3L    /* Tried to cancel something but it won't cancel */
  177.  
  178. /* Size of buffer you need if you are going to call ReadLine() */
  179.  
  180. #define MaxInputBuf    256L
  181.  
  182. /************************** File Requester ****************************/
  183. /***************** Submit the following to FileRequest() **************/
  184. /**********************************************************************/
  185.  
  186. struct FileRequester {
  187.     BYTE    *fr_Hail;        /* Hailing text            */
  188.     BYTE    *fr_File;        /* Filename array (FCHARS * N)    */
  189.     BYTE    *fr_Dir;        /* Directory array (DSIZE + 1)    */
  190.     struct Window *fr_Window;    /* Window requesting files or NULL*/
  191.     UBYTE    fr_FuncFlags;        /* Set bitdef's below        */
  192.     UBYTE    fr_reserved1;        /* Set to NULL            */
  193.     VOID    (*fr_Function)();    /* Your function, see bitdef's    */
  194.     LONG    fr_reserved2;        /* RESERVED            */
  195. };
  196.  
  197. /* The following are the defines for fr_FuncFlags.  These bits tell
  198.  * FileRequest() what your fr_UserFunc is expecting, and what FileRequest()
  199.  * should call it for.
  200.  *
  201.  * You are called like so:
  202.  * fr_Function(Mask, Object)
  203.  * ULONG    Mask;
  204.  * CPTR        *Object;
  205.  *
  206.  * The Mask is a copy of the flag value that caused FileRequest() to call
  207.  * your function. You can use this to determine what action you need to
  208.  * perform, and exactly what Object is, so you know what to do and
  209.  * what to return.
  210.  */
  211.  
  212. #define FRB_DoWildFunc    7L /* Call me with a FIB and a name, ZERO return accepts. */
  213. #define FRB_DoMsgFunc    6L /* You get all IDCMP messages not for FileRequest() */
  214. #define FRB_DoColor    5L /* Set this bit for that new and different look */
  215. #define FRB_NewIDCMP    4L /* Force a new IDCMP (only if fr_Window != NULL) */
  216. #define FRB_NewWindFunc    3L /* You get to modify the newwindow structure. */
  217. #define FRB_AddGadFunc    2L /* You get to add gadgets. */
  218. #define FRB_GEventFunc    1L /* Function to call if one of your gadgets is selected. */
  219. #define    FRB_ListFunc    0L /* Not implemented yet. */
  220.  
  221. #define FRF_DoWildFunc    (1L << 7)
  222. #define FRF_DoMsgFunc    (1L << 6)
  223. #define    FRF_DoColor    (1L << 5)
  224. #define FRF_NewIDCMP    (1L << 4)
  225. #define FRF_NewWindFunc    (1L << 3)
  226. #define FRF_AddGadFunc    (1L << 2)
  227. #define FRF_GEventFunc    (1L << 1)
  228. #define FRF_ListFunc    (1L << 0)
  229.  
  230. #define FCHARS    32L            /* Filename size */
  231. #define DSIZE    33L            /* Directory name size */
  232.  
  233. #define FR_FIRST_GADGET    0x7680L    /* User gadgetID's must be less than this value */
  234.  
  235. /*************************************************************************/
  236. /********************** PATTERN MATCHING *********************************/
  237. /*************************************************************************/
  238.  
  239. /* Structure expected by FindFirst(), FindNext() */
  240. /*
  241.  * You need to allocate this structure and initialize it as follows:
  242.  *
  243.  * Set ap_BreakBits to the signal bits (CDEF) that you want to take a
  244.  * break on, or NULL, if you don't want to convenience the user.
  245.  *
  246.  * if you want to have the FULL PATH NAME of the files you found, allocate
  247.  * a buffer at the END of this structure, and put the size of it into
  248.  * ap_Length.  If you don't want the full path name, make sure you set
  249.  * ap_Length to zero.  In this case, the name of the file, and stats are
  250.  * available in the ap_Info, as per usual.
  251.  *
  252.  * Then call FindFirst() and then afterwards, FindNext() with this structure.
  253.  * You should check the return value each time (see below) and take the
  254.  * appropriate action, ultimately calling FreeAnchorChain() when there
  255.  * are no more files and you are done.  You can tell when you are done by
  256.  * checking for the normal AmigaDOS return code ERROR_NO_MORE_ENTRIES.
  257.  *
  258.  * You will also have to check the DirEntryType variable in the ap_Info
  259.  * structure to determine what exactly you have received.
  260.  */
  261.  
  262. struct AnchorPath {
  263.     struct Anchor    *ap_Base;    /* Pointer to first anchor */
  264.     struct Anchor    *ap_Last;    /* Pointer to last anchor */
  265.     LONG    ap_BreakBits;    /* Bits to break on */
  266.     LONG    ap_FoundBreak;    /* Bits we broke on. Also returns ERROR_BREAK */
  267.     ULONG    ap_Length;    /* Actual size of ap_Buf, set to 0 if no ap_Buf */
  268.     struct    FileInfoBlock    ap_Info;
  269.     BYTE    ap_Buf[1];    /* Allocate a buffer here, if desired */
  270. };
  271. /*
  272.  * structure used by the pattern matching functions, no need to obtain, diddle
  273.  * or allocate this yourself.
  274.  */
  275.  
  276. struct Anchor {
  277.     struct Anchor        *an_Next;
  278.     struct Anchor        *an_Pred;
  279.     struct FileLock        *an_Lock;
  280.     struct FileInfoBlock    *an_Info;
  281.     LONG    an_Status;        /* Type of this anchor node */
  282.     union {
  283.         WORD    an_Text;    /* Actual instance of a BSTRing */
  284.         BYTE    an_Actual[2];    /* more memory allocated as required */
  285.     } an_BSTR;
  286. };
  287. /* This structure takes a pointer, and returns FALSE if wildcard was not
  288.  * found by FindFirst()
  289.  */
  290. #define IsWild( ptr )        ( *((LONG *)(ptr)) )
  291.  
  292. /* Constants used by wildcard routines */
  293. /* These are the pre-parsed tokens referred to by pattern match.  It is not
  294.  * necessary for you to do anything about these, FindFirst() FindNext()
  295.  * handle all these for you.
  296.  */
  297.  
  298. #define P_ANY        0x80L    /* Token for '*' or '#?' */
  299. #define P_SINGLE    0x81L    /* Token for '?' */
  300. #define P_ORSTART    0x82L    /* Token for '(' */
  301. #define P_ORNEXT    0x83L    /* Token for '|' */
  302. #define P_OREND        0x84L    /* Token for ')' */
  303. #define P_TAG        0x85L    /* Token for '{' */
  304. #define P_TAGEND    0x86L    /* Token for '}' */
  305. #define P_NOTCLASS    0x87L    /* Token for '^' */
  306. #define P_CLASS        0x88L    /* Token for '[]' */
  307. #define P_REPBEG    0x89L    /* Token for '[' */
  308. #define P_REPEND    0x8AL    /* Token for ']' */
  309.  
  310. /* Values for an_Status, NOTE: these are the actual bit numbers. */
  311. #define COMPLEX_BIT    1L    /* Parsing complex pattern */
  312. #define EXAMINE_BIT    2L    /* Searching directory */
  313.  
  314. /* Returns from FindFirst() FindNext() */
  315. /* Note that you can also get return codes as defined in dos.h,
  316.  * particularly you can get ERROR_NO_MORE_ENTRIES.
  317.  */
  318.  
  319. #define ERROR_BUFFER_OVERFLOW    303L    /* User or internal buffer overflow */
  320. #define ERROR_BREAK        304L    /* A break character was received */
  321.  
  322. /* Structure used by AddDANode(), AddDADevs(), FreeDAList().
  323.  *
  324.  * This structure is used to create lists of names, which normally
  325.  * are devices, assigns, volumes, files, or directories.
  326.  */
  327.  
  328. struct DirectoryEntry {
  329.     struct DirectoryEntry    *de_Next;    /* Next in list */
  330.     BYTE    de_Type;            /* DLX_mumble */
  331.     BYTE    de_Flags;        /* For future expansion, DO NOT USE! */
  332.     BYTE    de_Name[1];        /* The name of the thing found */
  333. };
  334.  
  335. /* Defines you use to get a list of the devices you want to look at.
  336.  * For example, to get a list of all directories and volumes, do:
  337.  *
  338.  *    AddDADevs( mydalist, (DLF_DIRS | DLF_VOLUMES) )
  339.  *
  340.  * After this, you can examine the de_type field of the elements added to
  341.  * your list (if any) to discover specifics about the objects added.
  342.  *
  343.  * Note that if you want only devices which are also disks, you must request
  344.  * (DLF_DEVICES | DLF_DISKONLY).
  345.  */
  346.  
  347. #define DLB_DEVICES    0L    /* Return devices */
  348. #define DLB_DISKONLY    1L    /* Modifier for above: Return disk devices only */
  349. #define DLB_VOLUMES    2L    /* Return volumes only */
  350. #define DLB_DIRS    3L    /* Return assigned devices only */
  351.  
  352. #define DLF_DEVICES    (1L << 0)
  353. #define DLF_DISKONLY    (1L << 1)
  354. #define DLF_VOLUMES    (1L << 2)
  355. #define DLF_DIRS    (1L << 3)
  356.  
  357. /* Legal de_Type values, check for these after a call to AddDADevs(), or use
  358.  * on your own as the ID values in AddDANode().
  359.  */
  360.  
  361. #define DLX_FILE    0L    /* AddDADevs() can't determine this */
  362. #define DLX_DIR        8L    /* AddDADevs() can't determine this */
  363. #define DLX_DEVICE    16L    /* It's a resident device */
  364.  
  365. #define DLX_VOLUME    24L    /* Device is a volume */
  366. #define DLX_UNMOUNTED    32L    /* Device is not resident */
  367.  
  368. #define DLX_ASSIGN    40L    /* Device is a logical assignment */
  369.  
  370. /*********************************************************************/
  371. /********************** RESOURCE TRACKING ****************************/
  372. /*********************************************************************/
  373.  
  374. /* Note: ResList MUST be a DosAllocMem'ed list!, this is done for
  375.  * you when you call CreateTaskResList(), typically, you won't need
  376.  * to access/allocate this structure.
  377.  */
  378.  
  379. struct ResList {
  380.     struct MinNode    rl_Node;    /* Used by arplib to link reslist's */
  381.     struct Task    *rl_TaskID;    /* Owner of this list */
  382.     struct MinList    rl_FirstItem;    /* List of TrackedResource's */
  383.     struct ArpResList *rl_Link;    /* SyncRun's use - hide list here */
  384. };
  385. /*
  386.  * The rl_FirstItem list (above) is a list of TrackedResource (below).
  387.  * It is very important that nothing in this list depend on the task
  388.  * existing at resource freeing time (i.e., RemTask(0L) type stuff,
  389.  * DeletePort() and the rest).
  390.  *
  391.  * The tracking functions return a struct Tracker *Tracker to you, this
  392.  * is a pointer to whatever follows the tr_ID variable.
  393.  * The default case is reflected below, and you get it if you call
  394.  * GetTracker() ( see DefaultTracker below).
  395.  *
  396.  * NOTE: The two user variables mentioned in an earlier version don't
  397.  * exist, and never did. Sorry about that (SDB).
  398.  *
  399.  * However, you can still use ArpAlloc() to allocate your own tracking nodes
  400.  * and they can be any size or shape you like, as long as the base structure
  401.  * is preserved. They will be freed automagically just like the default trackers.
  402.  */
  403.  
  404. struct TrackedResource {
  405.     struct MinNode    tr_Node;    /* Double linked pointer */
  406.     BYTE        tr_Flags;    /* Don't touch */
  407.     BYTE        tr_Lock;    /* Don't touch, for Get/FreeAccess() */
  408.     SHORT        tr_ID;        /* Item's ID */
  409.     /*
  410.      * The struct DefaultTracker *Tracker portion of the structure.
  411.      * The stuff below this point can conceivably vary, depending
  412.      * on user needs, etc.  This reflects the default.
  413.      */
  414.     union {
  415.         CPTR    tr_Resource;    /* Whatever */
  416.                 LONG    tg_Verify;    /* For use during TRAK_GENERIC */
  417.     } tr_Object;            /* The thing being tracked */
  418.     union {
  419.         VOID    (*tg_Function)(); /* Function to call for TRAK_GENERIC */
  420.         struct    Window    *tr_Window2;    /* For TRAK_WINDOW */
  421.     } tr_Extra;                /* Only needed sometimes */
  422. };
  423.  
  424. #define tg_Value tg_Verify    /* Ancient compatibility */
  425.  
  426. /* You get a pointer to a struct of the following type when you call
  427.  * GetTracker().  You can change this, and use ArpAlloc() instead of
  428.  * GetTracker() to do tracking. Of course, you have to take a wee bit
  429.  * more responsibility if you do, as well as if you use TRAK_GENERIC
  430.  * stuff.
  431.  *
  432.  * TRAK_GENERIC folks need to set up a task function to be called when an
  433.  * item is freed.  Some care is required to set this up properly.
  434.  *
  435.  * Some special cases are indicated by the unions below, for TRAK_WINDOW,
  436.  * if you have more than one window opened, and don't want the IDCMP closed
  437.  * particularly, you need to set a ptr to the other window in dt_Window2.
  438.  * See CloseWindowSafely() for more info.  If only one window, set this to NULL.
  439.  *
  440.  */
  441.  
  442. struct DefaultTracker {
  443.     union {
  444.         CPTR    dt_Resource;    /* Whatever */
  445.         LONG    tg_Verify;    /* For use during TRAK_GENERIC */
  446.     } dt_Object;            /* The object being tracked */
  447.     union {
  448.         VOID    (*tg_Function)();  /* Function to call for TRAK_GENERIC */
  449.         struct Window *dt_Window2;    /* For TRAK_WINDOW */
  450.     } dt_Extra;
  451. };
  452.  
  453. /* Items the tracker knows what to do about */
  454.  
  455. #define TRAK_AAMEM    0L    /* Default (ArpAlloc) element */
  456. #define TRAK_LOCK    1L    /* File lock */
  457. #define TRAK_FILE    2L    /* Opened file */
  458. #define TRAK_WINDOW    3L    /* Window -- see docs */
  459. #define TRAK_SCREEN    4L    /* Screen */
  460. #define TRAK_LIBRARY    5L    /* Opened library */
  461. #define TRAK_DAMEM    6L    /* Pointer to DosAllocMem block */
  462. #define TRAK_MEMNODE    7L    /* AllocEntry() node */
  463. #define TRAK_SEGLIST    8L    /* Program segment */
  464. #define TRAK_RESLIST    9L    /* ARP (nested) ResList */
  465. #define TRAK_MEM    10L    /* Memory ptr/length */
  466. #define TRAK_GENERIC    11L    /* Generic Element, your choice */
  467. #define TRAK_DALIST    12L    /* DAlist ( aka file request ) */
  468. #define TRAK_ANCHOR    13L    /* Anchor chain (pattern matching) */
  469. #define TRAK_MAX    13L    /* Poof, anything higher is tossed */   
  470.  
  471. #define TRB_UNLINK    7L    /* Free node bit */
  472. #define TRB_RELOC    6L    /* This may be relocated (not used yet) */
  473. #define TRB_MOVED    5L    /* Item moved */
  474.  
  475. #define TRF_UNLINK    (1L << 7)
  476. #define TRF_RELOC    (1L << 6)
  477. #define TRF_MOVED    (1L << 5)
  478.  
  479. /* Returns from CompareLock() */
  480. #define LCK_EQUAL    0L    /* The two locks refer to the same object */
  481. #define LCK_VOLUME    1L    /* Locks are on the same volume */
  482. #define LCK_DIFVOL1    2L    /* Locks are on different volumes */
  483. #define LCK_DIFVOL2    3L    /* Locks are on different volumes */
  484.  
  485. /****************************** ASyncRun() ***************************/
  486. /*
  487.  * Message sent back on your request by an exiting process.
  488.  * You request this by putting the address of your message in pcb_LastGasp,
  489.  * and initializing the ReplyPort variable of your ZombieMsg to the
  490.  * port you wish the message posted to.
  491.  */
  492.  
  493. struct ZombieMsg {
  494.     struct Message    zm_ExecMessage;
  495.     ULONG    zm_TaskNum;        /* Task ID */
  496.     ULONG    zm_ReturnCode;        /* Process's return code */
  497.     ULONG    zm_Result2;        /* System return code */
  498.     struct    DateStamp zm_ExitTime;    /* Date stamp at time of exit */
  499.     ULONG    zm_UserInfo;        /* For whatever you wish. */
  500. };
  501.  
  502. /* Structure required by ASyncRun() -- see docs for more info. */
  503.  
  504. struct ProcessControlBlock {
  505.     ULONG    pcb_StackSize;        /* Stacksize for new process */
  506.     BYTE    pcb_Pri;        /* Priority of new task */
  507.     BYTE    pcb_Control;        /* Control bits, see defines below */
  508.     APTR    pcb_TrapCode;        /* Optional Trap Code */
  509.     ULONG    pcb_Input,p_Output;    /* Optional stdin, stdout */
  510.     union {
  511.         ULONG    pcb_SplatFile;    /* File to use for Open("*") */
  512.         BYTE    *pcb_ConName;    /* CON: filename */
  513.     } pcb_Console;
  514.     ULONG    pcb_SplatFile;        /* File to use for Open("*") */
  515.     CPTR    pcb_LoadedCode;     /* If not null, will not load/unload code */
  516.     struct ZombieMsg *pcb_LastGasp;     /* ReplyMsg() to be filled in by exit */
  517.     struct MsgPort    *pcb_WBProcess;    /* Valid only when PRB_NOCLI */
  518. };
  519.  
  520. /* Some programs appear to have bugs in the startup code that does not handle
  521.  * well a zero length command line (lattice startup has this, but is probably
  522.  * not unique).  Use this macro to pass a null cmd line to a process using
  523.  * either ASyncRun() or SyncRun()
  524.  */
  525.  
  526. #define NOCMD    "\n"
  527.  
  528. /* The following control bits determine what ASyncRun() does on Abnormal Exits
  529.  * and on background process termination. 
  530.  */
  531.  
  532. #define    PRB_SAVEIO    0L    /* Don't free/check file handles on exit */
  533. #define PRB_CLOSESPLAT    1L    /* Close Splat file, must request explicitly */
  534. #define PRB_NOCLI    2L    /* Don't create a CLI process */
  535. #define PRB_INTERACTIVE    3L    /* This should be interactive */
  536. #define PRB_CODE    4L    /* Dangerous yet enticing */
  537. #define PRB_STDIO    5L    /* Do the stdio thing, splat = CON:Filename */
  538.  
  539. #define PRF_SAVEIO    (1L << 0)
  540. #define PRF_CLOSESPLAT    (1L << 1)
  541. #define PRF_NOCLI    (1L << 2)
  542. #define PRF_INTERACTIVE    (1L << 3)
  543. #define PRF_CODE    (1L << 4)
  544. #define PRF_STDIO    (1L << 5)
  545.  
  546. /* Error returns from SyncRun() and ASyncRun() */
  547. #define PR_NOFILE    -1L    /* Could not LoadSeg() the file */
  548. #define    PR_NOMEM    -2L    /* No memory for something */
  549. #define PR_NOCLI    -3L    /* Only SyncRun() will fail if call not cli */
  550. #define PR_NOSLOT    -4L    /* No room in TaskArray */
  551. #define PR_NOINPUT    -5L    /* Could not open input file */
  552. #define PR_NOOUTPUT    -6L    /* Could not get output file */
  553. #define PR_NOLOCK    -7L    /* Could not get a lock */
  554. #define PR_ARGERR    -8L    /* Bad argument to ASyncRun() */
  555. #define PR_NOBCPL    -9L    /* Bad program passed to ASyncRun() */
  556. #define PR_BADLIB    -10    /* Bad library version */
  557. #define PR_NOSTDIO    -11    /* Couldn't get stdio handles */
  558.  
  559. /* Programs should return this as result2 if need a cli and don't have one. */
  560.  
  561. #define ERROR_NOT_CLI    400L        /* Program/function neeeds to be cli */
  562.  
  563. /******************** Resident Program Support *****************************/
  564. /*
  565.  * This is the kind of node allocated for you when yhou AddResidentPrg() a code
  566.  * segment.  They are stored as a single linked list with the root in
  567.  * ArpBase.  If you absolutely *must* wander through this list instead of
  568.  * using the supplied functions, then you must first obtain the semaphore
  569.  * which protects this list, and then release it afterwards.
  570.  * Do not use Forbid() and Permit() to gain exclusive access!
  571.  * Note that the supplied functions handle this locking protocol for you.
  572.  */
  573.  
  574. struct ResidentPrgNode {
  575.     struct ResidentPrgNode         *rpn_Next;    /* next or NULL */
  576.     LONG                rpn_Usage;    /* Number of current users */
  577.     ULONG                rpn_CheckSum;    /* Checksum of code */
  578.     BPTR                rpn_Segment;    /* Actual segment */
  579.     BYTE                rpn_Name[1];    /* Allocated as needed */
  580. };
  581.  
  582.  
  583. /* If your program starts with this structure, ASyncRun() and SyncRun() will
  584.  * override a users stack request with the value in rpt_StackSize.
  585.  * Furthermore, if you are actually attached to the resident list, a memory
  586.  * block of size rpt_DataSize will be allocated for you, and
  587.  * a pointer to this data passed to you in register A4.  You may use this
  588.  * block to clone the data segment of programs, thus resulting in one
  589.  * copy of text, but multiple copies of data/bss for each process
  590.  * invocation.  If you are resident, your program will start at
  591.  * rpt_Instruction, otherwise, it will be launched from the initial branch.
  592.  */
  593.  
  594. struct ResidentProgramTag {
  595.     BPTR    rpt_NextSeg;    /* Provided by DOS at LoadSeg time. */
  596.     UWORD    rpt_BRA;    /* Short branch to executable */
  597.     UWORD    rpt_Magic;    /* Resident majik value */
  598.     ULONG    rpt_StackSize;    /* min stack for this process */
  599.     ULONG    rpt_DataSize;    /* Data size to allocate if resident */
  600.     /*     rpt_Instruction; /* Start here if resident */
  601. };
  602. /*
  603.  * The form of the ARP allocated node in your tasks memlist when launched
  604.  * as a resident program. Note that the data portion of the node will only
  605.  * exist if you have specified a nonzero value for rpt_DataSize. Note also
  606.  * that this structure is READ ONLY, modify values in this at your own
  607.  * risk.  The stack stuff is for tracking, if you need actual addresses
  608.  * or stack size, check the normal places for it in your process/task struct.
  609.  */
  610. struct ProcessMemory {
  611.     struct Node    pm_Node;
  612.     UWORD        pm_Num;        /* This is 1 if no data, two if data */
  613.     CPTR        pm_Stack;
  614.     ULONG        pm_StackSize;
  615.     CPTR        pm_Data;    /* Only here if pm_Num == 2 */
  616.     ULONG        pm_DataSize;
  617. };
  618.  
  619. /* To find the above on your memlist, search for the following name.
  620.  * We guarantee this will be the only arp.library allocated node on
  621.  * your memlist with this name, i.e. FindName(task->tcb_MemEntry, PMEM_NAME);
  622.  */
  623. #define PMEM_NAME    "ARP_MEM"
  624.  
  625. #define RESIDENT_MAGIC        0x4AFC        /* same as RTC_MATCHWORD (trapf) */
  626.  
  627. /* The initial branch destination and rpt_Instruction do not have to be the same.
  628.  * This allows different actions to be taken if you are diskloaded or
  629.  * resident. DataSize memory will be allocated only if you are resident,
  630.  * but StackSize will override all user stack requests.
  631.  */
  632.  
  633. /*********************** String/Data structures *************************/
  634.  
  635. struct DateTime {
  636.     struct    DateStamp dat_Stamp;    /* DOS Datestamp */
  637.     UBYTE        dat_Format;    /* controls appearance ot dat_StrDate */
  638.     UBYTE        dat_Flags;    /* See BITDEF's below */
  639.     BYTE        *dat_StrDay;    /* day of the week string */
  640.     BYTE        *dat_StrDate;    /* date string */
  641.     BYTE        *dat_StrTime;    /* time string */
  642. };
  643.  
  644. /* Size of buffer you need for each DateTime strings: */
  645. #define LEN_DATSTRING    10L
  646.  
  647. /* For dat_Flags */
  648.  
  649. #define DTB_SUBST    0L    /* Substitute "Today" "Tomorrow" where appropriate */
  650. #define DTB_FUTURE    1L    /* Day of the week is in future */
  651.  
  652. #define DTF_SUBST    (1L << 0)
  653. #define DTF_FUTURE    (1L << 1)
  654.  
  655. /* For dat_Format */
  656. #define FORMAT_DOS    0L        /* dd-mmm-yy AmigaDOS's own, unique style */
  657. #define FORMAT_INT    1L        /* yy-mm-dd International format */
  658. #define FORMAT_USA    2L        /* mm-dd-yy The good'ol'USA.    */
  659. #define FORMAT_CDN    3L        /* dd-mm-yy Our brothers and sisters to the north */
  660. #define FORMAT_MAX    FORMAT_CDN    /* Larger than this? Defaults to AmigaDOS */
  661.  
  662. #endif !LIBRARIES_ARPBASE_H
  663.