home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / fileio_393.lzh / FileIO / Includes / FileIO.h < prev    next >
C/C++ Source or Header  |  1990-10-28  |  15KB  |  345 lines

  1. #ifndef FILEIO_H
  2. #define FILEIO_H
  3.  
  4. #ifdef AZTEC_C
  5. #define NARGS
  6. #endif
  7.  
  8. /* *** fileio.h  Version 1.9 ******************************************
  9.  *
  10.  * Amiga Programmers' Suite  --  File IO Include File
  11.  *     from Book 1 of the Amiga Programmers' Suite by RJ Mical
  12.  *
  13.  * Copyright (C) 1986, =Robert J. Mical=
  14.  * All Rights Reserved.
  15.  *
  16.  * Created for Amiga developers.
  17.  * Any or all of this code can be used in any program as long as this
  18.  * entire notice is retained, ok?  Thanks.
  19.  *
  20.  * The Amiga Programmer's Suite Book 1 is copyrighted but freely distributable.
  21.  * All copyright notices and all file headers must be retained intact.
  22.  * The Amiga Programmer's Suite Book 1 may be compiled and assembled, and the 
  23.  * resultant object code may be included in any software product.  However, no 
  24.  * portion of the source listings or documentation of the Amiga Programmer's 
  25.  * Suite Book 1 may be distributed or sold for profit or in a for-profit 
  26.  * product without the written authorization of the author, RJ Mical.
  27.  *
  28.  * HISTORY      NAME            DESCRIPTION
  29.  * -----------  --------------  --------------------------------------------
  30.  * 20 Oct 87    - RJ            Added RENAME_RAMDISK to fix what seems to 
  31.  *                              be a bug in AmigaDOS.
  32.  * 27 Sep 87    RJ              Removed reference to alerts.h, brought 
  33.  *                              declarations into this file
  34.  * 12 Aug 86    RJ              Prepare (clean house) for release
  35.  * 14 Feb 86    =RJ Mical=      Created this file.
  36.  
  37.  From Sept 87 to Dec 89, the original code was rewritten entirely in assembly,
  38.  converted to a disk-based library, and numerous features were added such as:
  39.     1). Filename pattern matching
  40.     2). Support for applications without a window, including BASIC programs
  41.     3). Various string manipulation routines added to replace original
  42.         code.
  43.     4). Improved and debugged error handling and error returns, including
  44.         a better method of recovering from illegal/non-existant path names
  45.     5). Ability to add custom routines in a logical manner
  46.     6). Returns information about the selected file such as whether it exists,
  47.         and what its size is.
  48.     7). Returns free disk space on the selected disk
  49.     8). Automatic handling of filename selection when the requester can't
  50.         open.
  51.     9). Routines for displaying text in the title bar, and getting user input
  52.         via the window title bar.
  53.    10). Improved method of maintaining mounted device and volume names.
  54.    11). A function to parse filenames from AmigaDOS as passed into a program's
  55.         main() function. 
  56.    12). Improved graphic representation for the requester, including
  57.         larger display for filenames and repeat auto-scroll arrows.
  58.    13). Faster text rendering and directory list construction.
  59.    14). Ability to choose the disk name from a list of mounted devices using
  60.         the mouse.
  61.    15). Ability to display custom lists instead of filenames, with all of the
  62.         display features of the requester.
  63.    16). Ability to select multiple filenames.
  64.    17). C, assembly, and Basic examples with support files (INCLUDES).
  65.    18). Smaller size than the original code.
  66.    19). A quick way to save image, PROJECT icons without needing the icon
  67.         library.
  68.  
  69.    The current version of the library is 1.6 and was created by the programmers
  70. at dissidents. The library is such a significant departure from the original
  71. code that virtually every line of code differs from the original. It really is
  72. a different piece of code than R.J.s, but since he started the ball rolling...
  73.  
  74.  * *********************************************************************** */
  75.  
  76.  
  77. #define MAX_NAME_LENGTH 30
  78. #define MAX_DRAWER_LENGTH 132
  79. #define SetFlag(v,f)      ((v)|=(f))
  80. #define ClearFlag(v,f)    ((v)&=~(f))
  81. #define ToggleFlag(v,f)   ((v)^=(f))
  82. #define FlagIsSet(v,f)    ((BOOL)(((v)&(f))!=0))
  83.  
  84. struct HandlerBlock {
  85.     APTR  StartUpCode;
  86.     APTR  DiskInsertedCode;
  87.     APTR  GadgetCode;
  88.     APTR  KeyCode;
  89.     APTR  MouseMoveCode;
  90.     };
  91.  
  92. /* === FileIO Structure ========================================== */
  93.  
  94. struct FileIO {
  95.     USHORT    Flags;
  96.  
  97.     /* After a successful call to DoFileIO(), these fields will have
  98.     * the names selected by the user.  You should never have to initialize
  99.     * these fields, only read from them, though initializing them won't hurt.
  100.     */
  101.     UBYTE FileName[MAX_NAME_LENGTH];
  102.     UBYTE Drawer[MAX_DRAWER_LENGTH];
  103.     UBYTE Disk[MAX_NAME_LENGTH];
  104.  
  105.     /* If a Lock on a disk/dir was obtained, it can be found here. */
  106.     struct DOSLock *Lock;
  107.  
  108.     /* These are the variables associated with the list of filenames. Also,
  109.         any custom list of strings */
  110.     USHORT NameCount;        /* # of items */
  111.     USHORT NameStart;        /* The number of the first item visible in the req */
  112.     SHORT  CurrPick;        /* The number of the selected item starting at 0. If -1, none selected */
  113.     struct Remember *FileList;
  114.  
  115.     UBYTE *FileIOText;    /* for SPECIAL_REQ */
  116.     APTR FileIORoutine;    /* for SPECIAL_REQ */
  117.  
  118.     SHORT MatchType;        /* DiskObject Type to match */
  119.     UBYTE *ToolTypes;        /* If NULL, no string to match */
  120.  
  121.     UBYTE *Extension;
  122.     USHORT ExtSize;        /* Don't count the terminating NULL */
  123.  
  124.     struct HandlerBlock *Custom;
  125.  
  126.     USHORT X;                /* where the req opens when using DoFileIO() */
  127.     USHORT Y;
  128.  
  129.     ULONG  FreeBytes;        /* on the disk */
  130.     ULONG  FileSize;        /* of the selected file. ID if SPECIAL_REQ */
  131.  
  132.     UBYTE  *Title;            /* for DoFileIOWindow */
  133.  
  134.     UBYTE  *Buffer;        /* Where to put the complete DOS path */
  135.  
  136.     APTR   RawCode;        /* for DoRawkey, PromptUserInput */
  137.  
  138.     struct DOSLock  *OriginalLock;
  139.  
  140.     BYTE    Errno;            /* See ERRNO numbers */
  141.  
  142.     UBYTE  DrawMode;        /* for title bar input */
  143.     UBYTE  PenA;
  144.     UBYTE  PenB;
  145.     };
  146.  
  147. /* === User FileIO Flag Definitions === */
  148. #define NO_CARE_REDRAW     0x0001  /* Clear if reconstructing display */
  149. #define USE_DEVICE_NAMES   0x0002  /* Set for device instead of volume names */
  150. #define EXTENSION_MATCH    0x0004  /* Only display those that end with
  151.                                       a specified string */
  152. #define DOUBLECLICK_OFF    0x0008  /* Inhibit double-clicking if set */
  153. #define WBENCH_MATCH       0x0010  /* If set check .info files only */
  154. #define MATCH_OBJECTTYPE   0x0020  /* If set with .info also check MatchType */
  155. #define MULTIPLE_FILES     0x0040  /* If set, allow multiple file selection */
  156. #define INFO_SUPPRESS      0x0080  /* No info files listed */
  157. #define CUSTOM_HANDLERS    0x0200  /* Implement custom handlers */
  158. #define NO_ALPHA           0x1000  /* No alphabetize filenames or lists */
  159. #define DISK_HAS_CHANGED   0x2000  /* Disk changed during file selection */
  160. #define SHOW_DISK_NAMES    0x4000  /* Show disk names instead of filenames */
  161. #define SPECIAL_REQ        0x8000  /* For displaying lists of strings */
  162.  
  163. /* === System FileIO Flags (Don't alter these) === */
  164. #define ALLOCATED_FILEIO   0x0100  /* Not a pre-initialized FileIO struct */
  165. #define WINDOW_OPENED      0x0400  /* DoFileIOWindow() was called */
  166. #define TITLE_CHANGED      0x0800  /* SetTitle() called without ResetTitle() */
  167.  
  168.  
  169. /*  FileRequester GadgetIDs - Do not use these IDs for your own gadgets */
  170. #define FILEIO_CANCEL      0x7FA0
  171. #define FILEIO_OK          0x7FA1
  172. #define FILEIO_NAMETEXT    0x7FA2
  173. #define FILEIO_DRAWERTEXT  0x7FA3
  174. #define FILEIO_DISKTEXT    0x7FA4
  175. #define FILEIO_SELECTNAME  0x7FA5
  176. #define FILEIO_UPGADGET    0x7FA6
  177. #define FILEIO_DOWNGADGET  0x7FA7
  178. #define FILEIO_PROPGADGET  0x7FA8
  179. #define FILEIO_NEXTDISK    0x7FA9
  180. #define FILEIO_BACKDROP    0x7FAA
  181.  
  182. #define NAME_ENTRY_COUNT   7   /* These many names in the SelectName box */
  183.  
  184. #define REQTITLE_HEIGHT    8
  185.  
  186. #define REQ_LEFT          8
  187. #define REQ_TOP           15
  188. #define REQ_WIDTH         286
  189. #define REQ_HEIGHT        (110 + REQTITLE_HEIGHT)
  190. #define REQ_LINEHEIGHT    8
  191.  
  192. #define SELECTNAMES_LEFT    8
  193. #define SELECTNAMES_TOP     (15 + REQTITLE_HEIGHT)
  194. #define SELECTNAMES_WIDTH   122
  195. #define SELECTNAMES_HEIGHT  60
  196.  
  197.  
  198.  /* ======= ERRNO numbers returned in FileIO error field ========= */
  199.  
  200. #define ERR_MANUAL  1   /* the path was entered manually via the title bar
  201.                            with no errors or cancellation. */
  202. #define ERR_SUCCESS 0   /* everything went OK */
  203. #define ERR_CANCEL  -1  /* the filename procedure was CANCELED by the user */
  204. #define ERR_INUSE   -2  /* for SPECIAL_REQ, the requester is in use by another task */
  205. #define ERR_APPGADG -3  /* the requester was CANCELED by an application gadget
  206.                            (via an installed CUSTOM gadget handler returning TRUE) */
  207. #define ERR_WINDOW  -4  /* the window couldn't open (in DoFileIOWindow()) */
  208.  
  209. /* =============== AutoFileMessage() Numbers =========== */
  210. #define ALERT_OUTOFMEM            0
  211. #define ALERT_BAD_DIRECTORY       1
  212. #define READ_WRITE_ERROR          2 /* Error in reading or writing file */
  213.  /* The next 3 display "YES" and "NO" prompts,
  214.     returning d0=1 for yes, 0 for no */
  215. #define FILE_EXISTS               3 /* File already exists. Overwrite? */
  216. #define SAVE_CHANGES              4 /* Changes have been made. Save them? */
  217. #define REALLY_QUIT               5 /* Do you really want to quit? */
  218.  
  219. /* ====================== Entry Structure ====================== */
  220. /* Don't use sizeof on these structures. The library makes them for you when
  221.    you call AddEntry. The 3rd field of the Entry structure is a variable length
  222.    string. This structure has been defined simply so that you can get access to
  223.    the EntryID EntryFlags, and EntryString. This structure is used by
  224.    SPECIAL_REQ, and also for the list of filenames. For filenames, each has a
  225.    FileEntry structure. Its EntryID is the filesize. Bit #7 of the EntryFlags
  226.    is set if the filename was selected by the user. The EntryString is the
  227.    NULL-terminated filename (separated from its dir). When the SPECIAL_REQ
  228.    flag is set, the Entry's EntryID is your passed ID to AddEntry().
  229.    All the FileEntry structures are linked together, and the FileIO's
  230.    FileList field points to the first FileEntry in the list. */
  231.  
  232. struct Entry {
  233.    LONG  EntryID;
  234.    UBYTE EntryFlags;
  235.    UBYTE EntryString[1]; /* size is actually length of null-terminated string */
  236.    };
  237.  
  238. struct FileEntry {
  239.     struct FileEntry  *nextEntry;
  240.    ULONG  EntrySize;
  241.    struct Entry     *filePart;
  242.    };
  243.  
  244. /* ============= Requester Library Function Declarations ============= */
  245.  
  246.  
  247. #ifndef __ARGS
  248. #ifdef NARGS
  249. #define __ARGS(a) ()
  250. #else
  251. #define __ARGS(a) a
  252. #endif
  253. #endif
  254.  
  255. extern VOID  SetFileIOHandlers __ARGS(( struct HandlerBlock * ));
  256.  
  257. extern struct FileIO *GetFileIO __ARGS(( void )); 
  258. extern UBYTE  *DoFileIOWindow __ARGS(( struct FileIO *, struct Screen * )); 
  259.   /* address = DoFileIOWindow( myFileIO, myScreen );
  260.      If myScreen is NULL, then use WB screen */
  261. extern UBYTE  *DoFileIO __ARGS(( struct FileIO *, struct Window * )); 
  262.  
  263. extern BOOL   AutoFileMessage __ARGS(( ULONG, struct Window * ));
  264.     /* result = AutoFileMessage( 3L, myWindow ); */
  265. extern BOOL   AutoMessage __ARGS(( UBYTE *, struct Window * ));
  266. extern BOOL   AutoMessageLen __ARGS(( UBYTE *, struct Window *, ULONG )); 
  267. extern BOOL   AutoPrompt3 __ARGS(( UBYTE *, UBYTE *,UBYTE *, struct Window * )); 
  268.  
  269. extern void   ReleaseFileIO __ARGS(( struct FileIO * ));
  270. extern void   SetWaitPointer __ARGS(( struct Window * ));  /* SetWaitPointer( myWindow ); */
  271. extern void   ResetBuffer __ARGS(( struct StringInfo *, ULONG )); 
  272.                 /* ResetBuffer( StringInfo, nullFlag ); resets the cursor back to 
  273.                 the first char in the stringinfo's buffer. If nullFlag is TRUE, 
  274.                 then NULLS the buffer as well. */
  275.  
  276. extern UBYTE  *UserEntry __ARGS(( ULONG, UBYTE *, struct FileIO *, struct Window * )); 
  277. extern UBYTE  *PromptUserEntry __ARGS(( ULONG, UBYTE *, UBYTE *, struct FileIO *, struct Window * ));
  278. extern UBYTE  *GetFullPathname __ARGS(( struct FileIO *, UBYTE * ));
  279. extern UBYTE  *TypeFilename __ARGS(( struct FileIO *, struct Window * ));
  280. extern UBYTE  *ParseString __ARGS(( struct FileIO *, UBYTE * ));
  281.  
  282. extern UWORD  GetRawkey __ARGS(( struct Window * ));
  283. extern UWORD  DecodeRawkey __ARGS(( USHORT, USHORT ));
  284. extern void   SetTitle __ARGS(( UBYTE *, UBYTE *, struct FileIO *, struct Window * ));
  285. extern void   ResetTitle __ARGS(( struct FileIO *, struct Window * ));
  286.  
  287. extern WORD   NewEntryList __ARGS(( struct FileIO * ));
  288. extern WORD   AddEntry __ARGS(( LONG, UBYTE *, struct FileIO * ));
  289. extern WORD   IsEntryThere __ARGS(( UBYTE *, struct FileIO * ));
  290. extern struct FileEntry  *RetrieveEntry __ARGS(( struct FileEntry *, struct FileIO * ));
  291. extern void   ClearEntries __ARGS(( struct FileIO * ));
  292.  
  293. extern LONG   PutProjIcon __ARGS(( UBYTE *, struct DiskObject * )); 
  294.     /* Just like icon lib's PutIcon(), but for image PROJECT icons only. 
  295.         Returns 0 if success. */
  296.  
  297.  
  298. /* **************************************************************************
  299.  
  300.     It is recommended that pragmas not be used with the FileIO routines. This
  301.     is because certain calls do a bit more than just fiddle with the stack
  302.     arguments. For the adventurous, it is possible to edit FileInterface.asm
  303.     using only those elements which are somewhat 'funky', and use pragmas for
  304.     the remainder. Since you've got to include the interface anyway, is the pain
  305.     worth the few bytes you'll save? That's up to you...
  306.  
  307. #ifndef NO_PRAGMAS
  308.  
  309. #pragma libcall RequesterBase DoFileIOWindow     1e 9802
  310. #pragma libcall RequesterBase GetFileIO             24 0
  311. #pragma libcall RequesterBase DoFileIO             2a 9802
  312. #pragma libcall RequesterBase GetFullPathname     30 9802
  313. #pragma libcall RequesterBase AutoFileMessage     36 8102
  314. #pragma libcall RequesterBase ReleaseFileIO         3c 901
  315. #pragma libcall RequesterBase AutoMessage         42 8002
  316. #pragma libcall RequesterBase SetWaitPointer     48 801
  317. #pragma libcall RequesterBase ResetBuffer         4e 802
  318. #pragma libcall RequesterBase AutoMessageLen     54 18003
  319. #pragma libcall RequesterBase AutoPrompt3         5a 8ba904
  320. #pragma libcall RequesterBase UserEntry             60 ba8004
  321. #pragma libcall RequesterBase PromptUserEntry     66 ba98005
  322. #pragma libcall RequesterBase GetRawkey             6c b01
  323. #pragma libcall RequesterBase DecodeRawkey         72 902
  324. #pragma libcall RequesterBase TypeFilename         78 9802
  325. #pragma libcall RequesterBase SetTitle             7e ba9804
  326. #pragma libcall RequesterBase ResetTitle             84 ba02
  327. #pragma libcall RequesterBase ParseString         8a 9802
  328. #pragma libcall RequesterBase NewEntryList         90 901
  329. #pragma libcall RequesterBase AddEntry             96 98103
  330. #pragma libcall RequesterBase IsEntryThere         9c 9802
  331. #pragma libcall RequesterBase RetrieveEntry         a2 9802
  332. #pragma libcall RequesterBase ClearEntries         a8 9802
  333. #pragma libcall RequesterBase PutProjIcon         ae 9802
  334. #pragma libcall RequesterBase FindDeleteEntry    b4 9813
  335. #pragma libcall RequesterBase DeleteEntry         ba 982
  336. #pragma libcall RequesterBase AddFileGadgs         c0 db83
  337. #pragma libcall RequesterBase Window_BW             c6 801
  338. #pragma libcall RequesterBase BW_Restore             cc 802
  339.  
  340. #endif
  341. ********************************************************************** */
  342.  
  343. #endif /* of FILEIO_H */
  344.  
  345.