#ifndef LIBRARIES_OPENUTIL_H
#define LIBRARIES_OPENUTIL_H TRUE

/*
**
**  $VER: OpenUtil.h 1.0
**
**  Standard C definitions for OpenUtil.library
**
**  (C) Copyright 1998 Oliver "Bloodrock" Lange
**      All Rights Reserved
**
*/

#ifndef EXEC_LIBRARIES_H
#include <exec/libraries.h>
#endif

#ifndef DOS_DOS_H
#include <dos/dos.h>
#endif

#ifndef UTILITY_TAGITEM_H
#include <utility/tagitem.h>
#endif

#ifndef DEVICES_TIMER_H
#include <devices/timer.h>
#endif

#ifndef GRAPHICS_TEXT_H
#include <graphics/text.h>
#endif


/* Basic Library defines */

#define OPENUTILNAME      "OpenUtil.library"

#define OPENUTILVERSION   1


/* (String justification): mode defines */

#define OU_LEFT   0
#define OU_RIGHT  1
#define OU_CENTER 2


/* oCutList() Flags */

#define oCLSF_EXCLUSIVE (1L << 0)   /* exclude <StartRecord> from being deleted */
#define oCLSF_UP        (1L << 1)   /* cut in upward direction (else downward)  */


/* oFCopyMove() Flags */

#define oFCMF_MOVE      (1L << 0)   /* move instead of copying */
#define oFCMF_KEEPINFO  (1L << 1)   /* keep Source comment & protection bits */
#define oFCMF_REPLACE   (1L << 2)   /* replace existing file/dir */
#define oFCMF_FORCE     (1L << 3)   /* force operation (override source protection bits) */


/* oFormatVarStrA() Tags; not for use with oFormatVarStrRDFA() */

#define oFVS_VarBuffer_0       (TAG_USER+48)
#define oFVS_VarBuffer_1       (TAG_USER+49)
#define oFVS_VarBuffer_2       (TAG_USER+50)
#define oFVS_VarBuffer_3       (TAG_USER+51)
#define oFVS_VarBuffer_4       (TAG_USER+52)
#define oFVS_VarBuffer_5       (TAG_USER+53)
#define oFVS_VarBuffer_6       (TAG_USER+54)
#define oFVS_VarBuffer_7       (TAG_USER+55)
#define oFVS_VarBuffer_8       (TAG_USER+56)
#define oFVS_VarBuffer_9       (TAG_USER+57)

/* oFormatVarStrA() & oFormatVarStrRDFA() Tags */

#define oFVS_KeepVar           (TAG_USER+256)

#define oFVS_VarBuffer_A       (TAG_USER+65)
#define oFVS_VarBuffer_B       (TAG_USER+66)
#define oFVS_VarBuffer_C       (TAG_USER+67)
#define oFVS_VarBuffer_D       (TAG_USER+68)
#define oFVS_VarBuffer_E       (TAG_USER+69)
#define oFVS_VarBuffer_F       (TAG_USER+70)
#define oFVS_VarBuffer_G       (TAG_USER+71)
#define oFVS_VarBuffer_H       (TAG_USER+72)
#define oFVS_VarBuffer_I       (TAG_USER+73)
#define oFVS_VarBuffer_J       (TAG_USER+74)
#define oFVS_VarBuffer_K       (TAG_USER+75)
#define oFVS_VarBuffer_L       (TAG_USER+76)
#define oFVS_VarBuffer_M       (TAG_USER+77)
#define oFVS_VarBuffer_N       (TAG_USER+78)
#define oFVS_VarBuffer_O       (TAG_USER+79)
#define oFVS_VarBuffer_P       (TAG_USER+80)
#define oFVS_VarBuffer_Q       (TAG_USER+81)
#define oFVS_VarBuffer_R       (TAG_USER+82)
#define oFVS_VarBuffer_S       (TAG_USER+83)
#define oFVS_VarBuffer_T       (TAG_USER+84)
#define oFVS_VarBuffer_U       (TAG_USER+85)
#define oFVS_VarBuffer_V       (TAG_USER+86)
#define oFVS_VarBuffer_W       (TAG_USER+87)
#define oFVS_VarBuffer_X       (TAG_USER+88)
#define oFVS_VarBuffer_Y       (TAG_USER+89)
#define oFVS_VarBuffer_Z       (TAG_USER+90)
#define oFVS_VarBuffer_a       (TAG_USER+97)
#define oFVS_VarBuffer_b       (TAG_USER+98)
#define oFVS_VarBuffer_c       (TAG_USER+99)
#define oFVS_VarBuffer_d       (TAG_USER+100)
#define oFVS_VarBuffer_e       (TAG_USER+101)
#define oFVS_VarBuffer_f       (TAG_USER+102)
#define oFVS_VarBuffer_g       (TAG_USER+103)
#define oFVS_VarBuffer_h       (TAG_USER+104)
#define oFVS_VarBuffer_i       (TAG_USER+105)
#define oFVS_VarBuffer_j       (TAG_USER+106)
#define oFVS_VarBuffer_k       (TAG_USER+107)
#define oFVS_VarBuffer_l       (TAG_USER+108)
#define oFVS_VarBuffer_m       (TAG_USER+109)
#define oFVS_VarBuffer_n       (TAG_USER+110)
#define oFVS_VarBuffer_o       (TAG_USER+111)
#define oFVS_VarBuffer_p       (TAG_USER+112)
#define oFVS_VarBuffer_q       (TAG_USER+113)
#define oFVS_VarBuffer_r       (TAG_USER+114)
#define oFVS_VarBuffer_s       (TAG_USER+115)
#define oFVS_VarBuffer_t       (TAG_USER+116)
#define oFVS_VarBuffer_u       (TAG_USER+117)
#define oFVS_VarBuffer_v       (TAG_USER+118)
#define oFVS_VarBuffer_w       (TAG_USER+119)
#define oFVS_VarBuffer_x       (TAG_USER+120)
#define oFVS_VarBuffer_y       (TAG_USER+121)
#define oFVS_VarBuffer_z       (TAG_USER+122)


/* oFileToList() Tags */

#define oFTL_Buffer         (TAG_USER+1)
#define oFTL_BufSize        (TAG_USER+2)
#define oFTL_MsgWait        (TAG_USER+3)
#define oFTL_NodeNameOffset (TAG_USER+4)


/* oGetFile() Tags */

#define oGFI_Pattern        (TAG_USER+1)
#define oGFI_PubScreenName  (TAG_USER+2)
#define oGFI_NoIcons        (TAG_USER+3)
#define oGFI_DirsOnly       (TAG_USER+4)


/* oGetFont() Flags */

#define oGFO_FRONTPEN       (1L<<0)
#define oGFO_BACKPEN        (1L<<1)
#define oGFO_DRAWMODE       (1L<<2)
#define oGFO_STYLES         (1L<<3)


/* oListToFile() Tags */

#define oLTF_Buffer         (TAG_USER+1)
#define oLTF_BufSize        (TAG_USER+2)
#define oLTF_MsgWait        (TAG_USER+3)


/* oMatch() defines, as used with:

     oBuildDirInfoA()
     oSearchRecordA()

   If you're going to call a function which uses oMatch(), please also read the
   documentation of that function. It states which of the following match modes 
   and other defines are supported by the desired function, and about how to
   use it (maybe using special Tag defines).
*/

#define oMATCHMODE_Byte       1
#define oMATCHMODE_Word       2
#define oMATCHMODE_Long       3
#define oMATCHMODE_QuadPtr    4
#define oMATCHMODE_StrBegin   5
#define oMATCHMODE_StrEnd     6
#define oMATCHMODE_StrAny     7
#define oMATCHMODE_StrExact   8
#define oMATCHMODE_StrPattern 9


/* oBuildDirInfoA() Tags */

#define oBDI_BuildDirTree  (TAG_USER+1)
#define oBDI_MatchAny      (TAG_USER+1000+oMATCHMODE_StrAny)
#define oBDI_MatchBegin    (TAG_USER+1000+oMATCHMODE_StrBegin)
#define oBDI_MatchEnd      (TAG_USER+1000+oMATCHMODE_StrEnd)
#define oBDI_MatchExact    (TAG_USER+1000+oMATCHMODE_StrExact)
#define oBDI_MatchPattern  (TAG_USER+1000+oMATCHMODE_StrPattern)
#define oBDI_CaseSensitive (TAG_USER+7)
#define oBDI_Recursive     (TAG_USER+8)
#define oBDI_ScanInfoHook  (TAG_USER+9)
#define oBDI_ErrorHook     (TAG_USER+10)
#define oBDI_SortOrder     (TAG_USER+11)
#define oBDI_NoDirs        (TAG_USER+12)
#define oBDI_NoFiles       (TAG_USER+13)
#define oBDI_OnError       (TAG_USER+14)

/* oBuildDirInfoA() oBDI_SortOrder defines */

#define oBDISO_Mixed       0
#define oBDISO_DirsFirst   1
#define oBDISO_FilesFirst  2

/* oBuildDirInfoA() oBDI_OnError defines */

#define oBDION_Abort       0
#define oBDION_Break       1
#define oBDION_Continue    2

/*
  struct oDirInfo & struct oDirEntry, as created by oBuildDirInfoA(); this
  structure comes filled with information which depends on the passed Tags.
  For example, if you specify a file pattern, ByteCount holds the overall
  byte count of all matching files instead of the whole path.
*/

struct oDirInfo
{
  ULONG  ByteCount;           /* Overall byte size of all files stored in this
                                 directory. If oBDI_Recursive is set, all files
                                 in all sub-directories get added, too. */

  ULONG  FileCount;           /* Number of files stored in this directory.
                                 If oBDI_Recursive is set, all files in all
                                 sub-directories get added, too. */

  ULONG  DirCount;            /* Number of directories in this directory.
                                 If oBDI_Recursive is set, all directories in
                                 all sub-directories get added, too. */

  long   ErrorCode;           /* AmigaDOS ErrorCode. This is what you get when
                                 calling IoErr() after oBuildDirInfoA(). */

  struct oDirEntry * DirTree; /* If oBDI_BuildDirTree is set, oBuildDirInfoA()
                                 builds up a directory tree using Nodes of
                                 struct oDirEntry type.
                                 If oBDI_Recursive is set, this List comes back
                                 in two dimensions, as explained below. Else,
                                 this field will be NULL. If you have specified
                                 a pattern, DirTree only contains matching entries. */

  void * DirTreePool;         /* An Exec memory Pool, created by oBuildDirInfoA()
                                 if oBDI_BuildDirTree or oBDI_Recursive is set,
                                 else NULL. */

  char   ActualDir[256];      /* This string contains the path which is currently
                                 being examined. If you're using a ScanInfo and/or
                                 Error Hook, it'll receive this string in A2. */

  /* The following fields hold copies of the passed Tag data and other internal
     data used to save some Stack space when scanning recursively. You may refer
     to these fields after calling oBuildDirInfoA(), if you want.
  */

  ULONG  BuildDirTree;
  STRPTR Pattern;
  STRPTR PatternToken;        /* (516 bytes) for pattern strings of max. 255+1 bytes */
  ULONG  MatchType;           /* oMatch() compatible oMATCHMODE_Xxx value for file name matching */
  ULONG  MatchCase;
  ULONG  Recursive;
  struct Hook * ScanInfoHook;
  struct Hook * ErrorHook;
  ULONG  SortOrder;
  ULONG  NoDirs;
  ULONG  NoFiles;
  ULONG  OnError;
  BPTR   BaseDirLock;
  ULONG  RLevel;              /* tmp. recursion count */
};

/* struct oDirEntry: the DirTree structure */

struct oDirEntry
{
  struct Node ListNode;        /* ln_Succ & ln_Pred point to the next/previous
                                  directory entries, while ln_Name points to
                                  fib_FileName. */

  struct oDirEntry * Contents; /* This will be NULL if the current entry is a
                                  file. If it's a directory, Contents points one
                                  level down to it's contents. If the directory
                                  is empty, Contents is set to NULL.
                                  If oBDI_Recursive isn't set, Contents is
                                  always NULL. */

  struct oDirEntry * Parent;   /* This pointer is the counterpart to the Contents
                                  pointer, which holds the parent directory entry.
                                  If Parent is NULL, you have reached the topmost
                                  instance of the whole directory tree.
                                  If oBDI_Recursive isn't set, this field is
                                  always NULL. */

  struct FileInfoBlock FIB;    /* Full FileInfoBlock copy of the current entry
                                  providing all available information. */
};


/* oGetMouse() Tags */

#define oGetMouse_X        (TAG_USER+1)
#define oGetMouse_Y        (TAG_USER+2)
#define oGetMouse_Screen   (TAG_USER+3)
#define oGetMouse_Window   (TAG_USER+4)
#define oGetMouse_LMB      (TAG_USER+5)
#define oGetMouse_RMB      (TAG_USER+6)
#define oGetMouse_MMB      (TAG_USER+7)


/* Random Seed */

struct oRndSeed
  {
    ULONG RndSeed;      // current RndSeed value
    ULONG RenewRate;    // RndSeed renew rate (see autodoc description)
    ULONG RenewCount;   // If RenewCount reaches RenewRate, RenewCount gets
                        // reset and RndSeed gets renewed by adding the new
                        // system time (micro seconds).
    ULONG Add;          // Random Seed Add Value
    UWORD Mult;         // Random Seed Multiply Value
  };


/* oCreateStatusBarA() Tags */

#define oSTB_MaxValue    (TAG_USER+1)
#define oSTB_DrawBorder  (TAG_USER+2)

/* oDeleteStatusBar() Erase values */

#define oSTB_ERASEBAR 1
#define oSTB_ERASEALL 2

/* oStatusBar structure (read only) */

struct oStatusBar
  {
    struct RastPort * RPort;        /* Window RastPort          */
               void * VisualInfo;   /* Screen VisualInfo        */
               WORD   Left;         /* Left edge in RastPort    */
               WORD   Top;          /* Top edge in RastPort     */
               WORD   Width;        /* Width                    */
               WORD   Height;       /* Height                   */
               ULONG  MaxValue;     /* Maximum value (for 100%) */
               ULONG  LastWidth;    /* Last (current) value     */
               WORD   HasBorder;    /* TRUE or FALSE            */
  };


/* Flags for oNumToStr() and oNum64ToStr() */
/* Note: flags marked with "(-)" are not available for oNum64ToStr(). */

#define oNTSF_HEX           (1L<<0)  /* (-) Output hex string */
#define oNTSF_BIN           (1L<<1)  /* (-) Output binary string */
#define oNTSF_WORD          (1L<<2)  /* (-) Output size WORD */
#define oNTSF_BYTE          (1L<<3)  /* (-) Output size BYTE */
#define oNTSF_LEADINGZEROES (1L<<4)  /* (+) Output leading zeros */
#define oNTSF_LEADINGSIGN   (1L<<5)  /* (+) Add leading numeric system sign */
#define oNTSF_RIGHTFORMAT   (1L<<6)  /* (+) Right formatted output */
#define oNTSF_LEFTFORMAT    (1L<<7)  /* (+) Left formatted output */
#define oNTSF_CENTERFORMAT  (1L<<8)  /* (+) Center formatted output */
#define oNTSF_TENDLEFT      (1L<<9)  /* (+) Left tendence center formatting */
#define oNTSF_LOWERCASE     (1L<<10) /* (-) Hex characters lowercase */
#define oNTSF_GROUPING      (1L<<11) /* (+) Separate digit groups */
#define oNTSF_NUMLOCALE     (1L<<12) /* (+) Use numeric Locale group separator */
#define oNTSF_MONLOCALE     (1L<<13) /* (+) Use monetary Locale group separator */
#define oNTSF_SIGNED        (1L<<14) /* (+) Handle value as signed number */
#define oNTSF_PLUSSIGN      (1L<<15) /* (+) Use "+" char for signed pos. values */
#define oNTSF_SWAPSIGNS     (1L<<16) /* (+) Swap "-/+/ " and "#/$/%" positions */


/* oSearchRecordA() Tags */

#define oSR_CaseSensitive  (TAG_USER+1)
#define oSR_Pointer        (TAG_USER+2)
#define oSR_StartNode      (TAG_USER+3)
#define oSR_Exclusive      (TAG_USER+4)
#define oSR_Up             (TAG_USER+5)


/* oSetFileExtension() Flags */

#define oSFEF_REPLACELAST (1L << 0)  /* replace rightmost extension with new extension */
#define oSFEF_REPLACEALL  (1L << 1)  /* replace all extensions with new extension */
#define oSFEF_RENAME      (1L << 2)  /* rename file on disk */


/* oSortList() */

/* Size for oSL_Buffer */

#define oSORTBUFFER_SIZE 2048

/* oSortList() Modes */

#define oSORTMODE_STRING   1
#define oSORTMODE_BYTE     2
#define oSORTMODE_WORD     3
#define oSORTMODE_LONG     4
#define oSORTMODE_QUAD     5

/* oSortList() Tags */

#define oSL_Padout   (TAG_USER+1)
#define oSL_Table    (TAG_USER+2)
#define oSL_Signed   (TAG_USER+3)
#define oSL_Downward (TAG_USER+4)
#define oSL_Pointer  (TAG_USER+5)
#define oSL_Buffer   (TAG_USER+6)


/* oSuggestWindowPos() Tags */

#define oSWP_MouseGadget (TAG_USER+1)


/* oMsgWait structure (read only) */

struct oMsgWait
{
  struct Window *     Window;
  void *              VisualInfo;
  struct Gadget *     GList;
  struct oStatusBar * StatusBar;
  struct IntuiText *  BodyText;
  struct TextAttr     GadgetFont;
  UWORD               IECode;
};


/* oLockWindow() Window Lock structure */

struct oWindowLock
{
  struct Window * Window;
  ULONG  OldIDCMPFlags;
  long   MinWidth;
  long   MinHeight;
  long   MaxWidth;
  long   MaxHeight;
  UBYTE  SizeFix;
};


/* Library base */

/* Fields declared as private ARE private. Do not use 'em. */

struct OpenUtilLibrary
{
  struct Library         OU_LibNode;       /* Standard library node */

  /* LIBRARY PRIVATE */

  UBYTE  OU_Flags;       /* see also: */
  UBYTE  OU_pad;         /* "sample.library.asm", documented in the */
  BPTR   OU_SegList;     /* Amiga ROM Kernel Reference Manual: Libraries */

  /* PUBLIC FIELDS */    /* may be READ from your program */

  struct ExecBase *      OU_SysBase;        /* exec.library Base          V39+  */
  struct DosLibrary *    OU_DOSBase;        /* dos.library Base           V39+  */
  struct GfxBase *       OU_GfxBase;        /* graphics.library Base      V39+  */
  struct Library *       OU_LocaleBase;     /* locale.library Base        V38+  */
  struct Library *       OU_AslBase;        /* asl.library Base           V38+  */
  struct Library *       OU_TimerBase;      /* timer.device Library Base (V39+) */
  struct Library *       OU_IconBase;       /* icon.library Base          V39+  */
  struct Library *       OU_InputBase;      /* input.device Library Base (V39+) */
  struct IntuitionBase * OU_IntuitionBase;  /* intuition.library Base     V39+  */
  struct Library *       OU_UtilityBase;    /* utility.library Base       V39+  */
  struct Library *       OU_GadToolsBase;   /* gadtools.library Base      V39+  */
  UBYTE *                OU_LowerCaseTable; /* standard string to lower-case translation table */
  UBYTE *                OU_UpperCaseTable; /* standard string to upper-case translation table */
  void                 (*OU_PutChProc)();   /* PutChProc() for RawDoFmt() */
  struct TextAttr *      OU_Topaz8;         /* Standard TextAttr structure for topaz.font 8 */

  /* PRIVATE FIELDS */

  struct timerequest *   OU_InputIO;        /* unused IORequest for input.library functions */
  struct timerequest *   OU_TimerIO;        /* unused IORequest for timer.library functions */
};

#endif /* LIBRARIES_OPENUTIL_H */
