home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk463.lzh / FileIO / C / FileIO.h < prev    next >
C/C++ Source or Header  |  1991-03-09  |  15KB  |  316 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.B ******************************************
  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 Nov 90, 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 code
  42.     4). Improved and debugged error handling and error returns, including
  43.          a better method of recovering from illegal/non-existant path names
  44.     5). Ability to add custom routines and gadgets in a logical manner
  45.     6). Returns information about the selected file such as whether it exists,
  46.          and what its size is
  47.     7). Returns free disk space on the selected disk
  48.     8). Automatic handling of filename selection when the requester can't open
  49.     9). Routines for displaying text in the title bar, and getting user input
  50.          via the window title bar
  51.     10). Improved method of maintaining mounted device and volume names, inc
  52.           the ability to display logical assigns
  53.     11). A function to parse filenames from AmigaDOS as passed into a program's
  54.           main() function
  55.     12). Improved graphic representation for the requester, including
  56.             larger display for filenames and repeat auto-scroll arrows
  57.     13). Faster text rendering and directory list construction
  58.     14). Ability to choose the disk name from a list of mounted devices using
  59.             the mouse
  60.     15). Ability to display custom lists instead of filenames, with all of the
  61.             display features of the requester
  62.     16). Ability to select multiple filenames
  63.     17). C, assembly, and Basic examples with support files (INCLUDES).
  64.     18). Smaller size than the original code
  65.     19). A quick way to save image, PROJECT icons without needing the icon
  66.             library
  67.     20). Routines for constructing complete paths based upon a name or lock
  68.  
  69.    The current version of the library is 1.B 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. #include <libraries/dosextens.h>
  77. #include <intuition/intuition.h>
  78.  
  79. #define    MAX_NAME_LENGTH    30
  80. #define    MAX_DRAWER_LENGTH    132
  81. #define    MAX_BUFFER_LENGTH    204
  82. #define    SetFlag(v,f)        ((v)|=(f))
  83. #define    ClearFlag(v,f)        ((v)&=~(f))
  84. #define    ToggleFlag(v,f)    ((v)^=(f))
  85. #define    FlagIsSet(v,f)        ((BOOL)(((v)&(f))!=0))
  86.  
  87. struct HandlerBlock {
  88.     APTR  StartUpCode;
  89.     APTR  DiskInsertedCode;
  90.     APTR  GadgetCode;
  91.     APTR  KeyCode;
  92.     APTR  MouseMoveCode;
  93.     };
  94.  
  95. /* === FileIO Structure ========================================== */
  96.  
  97. struct FileIO {
  98.     USHORT    Flags;
  99.     /* After a successful call to DoFileIO(), these fields will have
  100.     * the names selected by the user.  You should never have to initialize
  101.     * these fields, only read from them, though initializing them won't hurt.
  102.     */
  103.     UBYTE FileName[MAX_NAME_LENGTH];
  104.     UBYTE Drawer[MAX_DRAWER_LENGTH];
  105.     UBYTE Disk[MAX_NAME_LENGTH];
  106.     /* If a Lock on a disk/dir was obtained, it can be found here. */
  107.     struct DOSLock *Lock;
  108.     /* These next 4 variables are 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.     UBYTE    *FileIOText;    /* for SPECIAL_REQ */
  115.     APTR    FileIORoutine;    /* for SPECIAL_REQ */
  116.     SHORT MatchType;        /* DiskObject Type to match */
  117.     UBYTE *ToolTypes;        /* If NULL, no string to match */
  118.     UBYTE *Extension;
  119.     USHORT ExtSize;        /* Don't count the terminating NULL */
  120.     struct HandlerBlock *Custom;
  121.     USHORT X;                /* where the req opens when using DoFileIO() */
  122.     USHORT Y;
  123.     ULONG  FreeBytes;        /* on the disk */
  124.     ULONG  FileSize;        /* of the selected file. ID if SPECIAL_REQ */
  125.     UBYTE  *Title;            /* hailing string for DoFileIO or DoFileIOWindow */
  126.     UBYTE  *Buffer;        /* Where to put the complete DOS path */
  127.     APTR   RawCode;        /* for DoRawkey, PromptUserInput */
  128.     struct DOSLock  *OriginalLock;
  129.     BYTE    Errno;            /* See ERRNO numbers */
  130.     UBYTE  DrawMode;        /* for title bar input */
  131.     UBYTE  PenA;
  132.     UBYTE  PenB;
  133.     };
  134.  
  135. /* === User FileIO Flag Definitions === */
  136. #define NO_CARE_REDRAW     0x0001  /* Clear if reconstructing display */
  137. #define USE_DEVICE_NAMES   0x0002  /* Set for device instead of volume names */
  138. #define EXTENSION_MATCH    0x0004  /* Only display those that end with
  139.                                       a specified string */
  140. #define DOUBLECLICK_OFF    0x0008  /* Inhibit double-clicking if set */
  141. #define WBENCH_MATCH       0x0010  /* If set check .info files only */
  142. #define MATCH_OBJECTTYPE   0x0020  /* If set with .info also check MatchType */
  143. #define MULTIPLE_FILES     0x0040  /* If set, allow multiple file selection */
  144. #define INFO_SUPPRESS      0x0080  /* No info files listed */
  145. #define CUSTOM_HANDLERS    0x0200  /* Implement custom handlers */
  146. #define NO_ALPHA           0x1000  /* No alphabetize filenames or lists */
  147. #define EXCLUDE_ASSIGNS    0x2000  /* Logical assignments are excluded from the device list */
  148. #define SHOW_DISK_NAMES    0x4000  /* Show disk names instead of filenames */
  149. #define SPECIAL_REQ        0x8000  /* For displaying lists of strings */
  150.  
  151. /* === System FileIO Flags (Don't alter these) === */
  152. #define ALLOCATED_FILEIO   0x0100  /* Not a pre-initialized FileIO struct */
  153. #define WINDOW_OPENED      0x0400  /* DoFileIOWindow() was called */
  154. #define TITLE_CHANGED      0x0800  /* SetTitle() called without ResetTitle() */
  155.  
  156. /* If adding any gadgets to the requester, here's a good place to put it */
  157. #define REQGADG_HEIGHT        13
  158. #define REQGADG_TOP            71
  159. #define REQGADG_LEFT            8
  160.  
  161.  /* ======= ERRNO numbers returned in FileIO error field ========= */
  162.  
  163. #define ERR_MANUAL    1    /* the path was entered manually via the title bar
  164.                                     with no errors or cancellation. */
  165. #define ERR_SUCCESS    0    /* everything went OK */
  166. #define ERR_CANCEL    -1    /* the filename procedure was CANCELED by the user */
  167. #define ERR_INUSE        -2    /* for SPECIAL_REQ, the requester is in use by another task */
  168. #define ERR_APPGADG    -3    /* the requester was CANCELED by an application gadget
  169.                            (via an installed CUSTOM gadget handler returning TRUE) */
  170. #define ERR_WINDOW    -4    /* the window couldn't open (in DoFileIOWindow()) */
  171.  
  172. /* =============== AutoFileMessage() Numbers =========== */
  173. #define ALERT_OUTOFMEM                0
  174. #define ALERT_BAD_DIRECTORY        1
  175. #define READ_WRITE_ERROR            2    /* Error in reading or writing file */
  176.     /* The next 3 display "YES" and "NO" prompts,
  177.         returning d0=1 for yes, 0 for no */
  178. #define FILE_EXISTS                    3    /* File already exists. Overwrite? */
  179. #define SAVE_CHANGES                    4    /* Changes have been made. Save them? */
  180. #define REALLY_QUIT                    5    /* Do you really want to quit? */
  181.  
  182. /* ====================== Entry Structure ====================== */
  183. /* Don't use sizeof on these structures. The library makes them for you when
  184.    you call AddEntry. The 3rd field of the Entry structure is a variable length
  185.    string. This structure has been defined simply so that you can get access to
  186.    the EntryID EntryFlags, and EntryString. This structure is used by
  187.    SPECIAL_REQ, and also for the list of filenames. For filenames, each has a
  188.    FileEntry structure. Its EntryID is the filesize. Bit #7 of the EntryFlags
  189.    is set if the filename was selected by the user. The EntryString is the
  190.    NULL-terminated filename (separated from its dir). When the SPECIAL_REQ
  191.    flag is set, the Entry's EntryID is your passed ID to AddEntry().
  192.    All the FileEntry structures are linked together, and the FileIO's
  193.    FileList field points to the first FileEntry in the list. */
  194.  
  195. struct Entry {
  196.     LONG  EntryID;
  197.     UBYTE EntryFlags;
  198.     UBYTE EntryString[1]; /* size is actually length of null-terminated string */
  199.     };
  200.  
  201. struct FileEntry {
  202.     struct FileEntry  *nextEntry;
  203.     ULONG  EntrySize;
  204.     struct Entry     *filePart;
  205.     };
  206.  
  207. /* ============= Requester Library Function Declarations ============= */
  208.  
  209. #ifndef __ARGS
  210. #ifdef NARGS
  211. #define __ARGS(a) ()
  212. #else
  213. #define __ARGS(a) a
  214. #endif
  215. #endif
  216.  
  217. extern VOID  SetFileIOHandlers __ARGS(( struct HandlerBlock * ));
  218.  
  219. extern struct FileIO *GetFileIO __ARGS(( void )); 
  220. extern UBYTE  *DoFileIOWindow __ARGS(( struct FileIO *, struct Screen * )); 
  221.     /* address = DoFileIOWindow( myFileIO, myScreen );
  222.         If myScreen is NULL, then use WB screen */
  223. extern UBYTE  *DoFileIO __ARGS(( struct FileIO *, struct Window * )); 
  224.  
  225. extern BOOL   AutoFileMessage __ARGS(( ULONG, struct Window * ));
  226.     /* result = AutoFileMessage( 3L, myWindow ); */
  227. extern BOOL   AutoMessage __ARGS(( UBYTE *, struct Window * ));
  228. extern BOOL   AutoMessageLen __ARGS(( UBYTE *, struct Window *, ULONG )); 
  229. extern BOOL   AutoPrompt3 __ARGS(( UBYTE *, UBYTE *,UBYTE *, struct Window * )); 
  230.  
  231. extern void   ReleaseFileIO __ARGS(( struct FileIO * ));
  232. extern void   SetWaitPointer __ARGS(( struct Window * ));  /* SetWaitPointer( myWindow ); */
  233. extern void   ResetBuffer __ARGS(( struct StringInfo *, ULONG )); 
  234.                 /* ResetBuffer( StringInfo, nullFlag ); resets the cursor back to 
  235.                 the first char in the stringinfo's buffer. If nullFlag is TRUE, 
  236.                 then NULLS the buffer as well. */
  237.  
  238. extern UBYTE  *UserEntry __ARGS(( ULONG, UBYTE *, struct FileIO *, struct Window * )); 
  239. extern UBYTE  *PromptUserEntry __ARGS(( ULONG, UBYTE *, UBYTE *, struct FileIO *, struct Window * ));
  240. extern UBYTE  *GetFullPathname __ARGS(( struct FileIO *, UBYTE * ));
  241. extern UBYTE  *TypeFilename __ARGS(( struct FileIO *, struct Window * ));
  242. extern UBYTE  *ParseString __ARGS(( struct FileIO *, UBYTE * ));
  243.  
  244. extern UWORD  GetRawkey __ARGS(( struct Window * ));
  245. extern UWORD  DecodeRawkey __ARGS(( USHORT, USHORT ));
  246. extern void   SetTitle __ARGS(( UBYTE *, UBYTE *, struct FileIO *, struct Window * ));
  247. extern void   ResetTitle __ARGS(( struct FileIO *, struct Window * ));
  248.  
  249. extern WORD   NewEntryList __ARGS(( struct FileIO * ));
  250. extern WORD   AddEntry __ARGS(( LONG, UBYTE *, struct FileIO * ));
  251. extern WORD   IsEntryThere __ARGS(( UBYTE *, struct FileIO * ));
  252. extern struct FileEntry  *RetrieveEntry __ARGS(( struct FileEntry *, struct FileIO * ));
  253. extern void   ClearEntries __ARGS(( struct FileIO * ));
  254.  
  255. extern LONG   PutProjIcon __ARGS(( UBYTE *, struct DiskObject * )); 
  256.     /* Just like icon lib's PutIcon(), but for image PROJECT icons only. 
  257.         Returns 0 if success. */
  258.  
  259. extern void        ParentPath __ARGS(( struct FileIO *, UBYTE * ));
  260. extern void        ParentLock __ARGS(( struct FileIO *, struct FileLock * ));
  261. extern void        FindName __ARGS(( UBYTE *, UBYTE * ));
  262. extern ULONG    Window_BW __ARGS(( struct Window * ));
  263. extern void        BW_Restore __ARGS(( ULONG, struct Window * ));
  264.  
  265.  
  266. /* **************************************************************************
  267.  
  268.     It is recommended that pragmas not be used with the FileIO routines. This
  269.     is because certain calls do a bit more than just fiddle with the stack
  270.     arguments. For the adventurous, it is possible to edit FileInterface.asm
  271.     using only those elements which are somewhat 'funky', and use pragmas for
  272.     the remainder. Since you've got to include the interface anyway, is the pain
  273.     worth the few bytes you'll save? That's up to you...
  274.  
  275. #ifndef NO_PRAGMAS
  276.  
  277. #pragma libcall RequesterBase DoFileIOWindow     1e 9802
  278. #pragma libcall RequesterBase GetFileIO             24 0
  279. #pragma libcall RequesterBase DoFileIO             2a 9802
  280. #pragma libcall RequesterBase GetFullPathname     30 9802
  281. #pragma libcall RequesterBase AutoFileMessage     36 8102
  282. #pragma libcall RequesterBase ReleaseFileIO         3c 901
  283. #pragma libcall RequesterBase AutoMessage         42 8002
  284. #pragma libcall RequesterBase SetWaitPointer     48 801
  285. #pragma libcall RequesterBase ResetBuffer         4e 802
  286. #pragma libcall RequesterBase AutoMessageLen     54 18003
  287. #pragma libcall RequesterBase AutoPrompt3         5a 8ba904
  288. #pragma libcall RequesterBase UserEntry             60 ba8004
  289. #pragma libcall RequesterBase PromptUserEntry     66 ba98005
  290. #pragma libcall RequesterBase GetRawkey             6c b01
  291. #pragma libcall RequesterBase DecodeRawkey         72 902
  292. #pragma libcall RequesterBase TypeFilename         78 9802
  293. #pragma libcall RequesterBase SetTitle             7e ba9804
  294. #pragma libcall RequesterBase ResetTitle             84 ba02
  295. #pragma libcall RequesterBase ParseString         8a 9802
  296. #pragma libcall RequesterBase NewEntryList         90 901
  297. #pragma libcall RequesterBase AddEntry             96 98103
  298. #pragma libcall RequesterBase IsEntryThere         9c 9802
  299. #pragma libcall RequesterBase RetrieveEntry         a2 9802
  300. #pragma libcall RequesterBase ClearEntries         a8 9802
  301. #pragma libcall RequesterBase PutProjIcon         ae 9802
  302. #pragma libcall RequesterBase FindDeleteEntry    b4 9813
  303. #pragma libcall RequesterBase DeleteEntry         ba 982
  304. #pragma libcall RequesterBase AddFileGadgs         c0 db83
  305. #pragma libcall RequesterBase Window_BW             c6 801
  306. #pragma libcall RequesterBase BW_Restore             cc 802
  307. #pragma libcall RequesterBase ParentPath            d2 9802
  308. #pragma libcall RequesterBase ParentLock            d8 9802
  309. #pragma libcall RequesterBase FindName                de 9802
  310.  
  311. #endif
  312. ********************************************************************** */
  313.  
  314. #endif /* of FILEIO_H */
  315.  
  316.