home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff348.lzh / FileIO / FileIO.h < prev    next >
C/C++ Source or Header  |  1990-04-15  |  12KB  |  272 lines

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