home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 073.lha / FileIO / FileIO.doc < prev    next >
Encoding:
Text File  |  1987-06-02  |  37.8 KB  |  1,001 lines

  1.  
  2. FileIO Requester
  3. User and Programmer Manual
  4. From the Amiga Programmer's Suite Book 1, by RJ Mical
  5. Copyright (C) 1987, Robert J. Mical
  6.  
  7.  
  8.  
  9.  
  10. This document describes the FileIO Requester, both for users of
  11. the requester and for programmers who will create the requester.
  12. The main sections of this document are:
  13.  
  14.     o  FROM THE USER'S POINT OF VIEW
  15.  
  16.     o  PROGRAMMER'S REFERENCE
  17.  
  18.     o  DEMO PROGRAM NOTES
  19.  
  20.     o  TECHNICAL REFERENCE
  21.  
  22.     o  USING THE AMIGA PROGRAMMER'S SUITE
  23.  
  24.     o  APPENDIX A:  FileIO Function Calls
  25.  
  26.  
  27.  
  28.  
  29. ============================================================================
  30. === FROM THE USER'S POINT OF VIEW ==========================================
  31. ============================================================================
  32.  
  33. This section presents the FileIO Requester from the user's point of view.  
  34. This is a rough example of the sort of documentation that might be supplied 
  35. to the end user of this FileIO Requester.  
  36.  
  37.  
  38.  
  39. === Welcome to the FileIO Requester ========================================
  40.  
  41. The FileIO Requester allows you an easy way to select which file you want 
  42. to use for input or output.  This section describes how you go about using 
  43. the FileIO Requester.  
  44.  
  45. The FileIO Requester consists of several parts:  
  46.  
  47.     o  the "Select a Name" gadgets which allow you to choose a file name
  48.        simply by scrolling through a list of names until you find the one
  49.        you want, pointing at the name and clicking the left mouse button
  50.  
  51.     o  the OK! gadget which you use to acknowledge that the name you've 
  52.        chosen is the one you wanted
  53.  
  54.     o  3 string gadgets which allow you to type in the name directly 
  55.        rather than using the "Select a Name" gadgets to find the file you 
  56.        want 
  57.  
  58.     o  a NEXT DISK gadget which allows you to examine one disk after 
  59.        another 
  60.  
  61.     o  the CANCEL gadget, which you use to when you've decided you don't 
  62.        want to select a file after all
  63.  
  64.  
  65. The "Select a Name" gadgets present you with a list of file names and allow 
  66. you to use the mouse to scan easily through the list and select one of 
  67. the filenames simply by pointing at it and clicking.  
  68.  
  69. The "Select a Name" gadgets consist of:  
  70.  
  71.     o  a box of where some of the list of file names are displayed
  72.  
  73.     o  a slider which lets you scan quickly through the list of files
  74.  
  75.     o  an up gadget and a down gadget which allow you to move through the
  76.        file list one name at a time
  77.  
  78.  
  79. There are 3 types of entries in the list of file names.
  80.  
  81. At the top of the list are the file names that you can choose.  These 
  82. names are listed in alphabetical order.  
  83.  
  84. At the bottom of the list there are special entries which allow you to move 
  85. around through the drawers of a disk, much like you move around through 
  86. drawers on the Workbench display.  
  87.  
  88. The entries that start with the ">>>>" characters allow you to "open" a 
  89. drawer and examine the names of the files in that drawer.  For example, 
  90. when examining a Workbench disk, at the bottom of the list you would find 
  91. an entry that looked like ">>>> Demos" which means that you can go into 
  92. the drawer named "Demos".  If you selected ">>>> Demos" you would see, 
  93. after a short pause, a new list of file names:  the names of the files 
  94. that are in the "Demos" drawer.  
  95.  
  96. In the "Demos" drawer you would also find a special entry, 
  97. "<<<< PRIOR DRAWER".  If you select this entry, you will move back to 
  98. the drawer that contained your current drawer.  
  99.  
  100. An alternate way to change drawers is to type the name of the drawer you 
  101. want in the string gadget labelled "Drawer" and located to the right of 
  102. the "Select a Name" gadgets.  You select the gadget, type in the name, 
  103. and hit return. 
  104.  
  105. Once you have a list of file names to choose from in the file name box, 
  106. there's a slider gadget to help you scroll around through the names.  
  107. The slider is to the right of the file names.  It has a knob which you 
  108. move to scroll through the names.  The knob will be different sizes 
  109. depending on the number of names in the file list.  If the knob is small, 
  110. this means that you can see only a small number of the total file names.  
  111. The smaller the knob, the more names there are to see.  On the other hand, 
  112. if you can see all the names in the list, the knob will fill up the 
  113. entire slider and you won't be able to move it.  
  114.  
  115. To view the file names, you "grab" the slider's knob and move it up and down.  
  116. You grab the knob by pointing at it and pressing and holding the left mouse 
  117. button.  When you have grabbed the knob, you can move the pointer and 
  118. scan quickly through the list of file names.  
  119.  
  120. Also, you can view the list of names one page at a time by clicking in the 
  121. area of the slider outside of the knob.  If you want fine control of your 
  122. movement through the file list, the up and down gadgets let you adjust 
  123. the list of names one name at a time.  
  124.  
  125. Once you have found the file name that you want to choose, you select it 
  126. by pointing at it and clicking.  When you do this, the name will be 
  127. highlighted and it will appear in a box to the right of the "Select a Name" 
  128. gadgets.  When you've decided that this is really the name you wanted 
  129. to choose, pick the OK! gadget.  Another way to tell the program that 
  130. you're sure you want to select a certain file name is by double-clicking 
  131. on the file name in the same way that you double-click on a Workbench 
  132. icon.  Double-clicking is exactly the same as selecting a name and 
  133. then OK!  
  134.  
  135. If you don't want to use the "Select a Name" gadgets, you can select a 
  136. name by typing the name into the string gadget labelled "Or Type a Name" 
  137. and then hitting return or clicking on the OK! gadget.  Hitting return 
  138. after typing the name you want is the same as selecting OK!  
  139.  
  140. If you know what file name you want and you intend on typing it into 
  141. the string gadget, you can start typing as soon as the requester 
  142. appears.  You don't have to select the string gadget before you start 
  143. typing, and you don't have to wait for the wait pointer to change before 
  144. you hit return!  
  145.  
  146. To view the files of a different disk, select the NEXT DISK gadget.  
  147. When you do, the name of the next disk is displayed in the Disk 
  148. string gadget and the disk is then searched.  If this disk isn't the 
  149. one you wanted, you can press NEXT DISK again even though you may be 
  150. seeing the wait pointer.  You can press NEXT DISK as many times as 
  151. you want until you see the name of the disk you want in the Disk gadget.  
  152. You can also type the name of the disk you want directly into the 
  153. Disk string gadget if you like.  
  154.  
  155. You might notice that the ZZZ-cloud wait pointer looks a little different 
  156. from ones you're used to on the Amiga.  The File IO Requester's ZZZ-cloud 
  157. pointer has a small tab at the top left which allows you to continue 
  158. pointing and making selections even though the ZZZ-cloud is displayed.  
  159. The File IO Requester's ZZZ-cloud tells you that it's working, but it 
  160. doesn't make you wait.  
  161.  
  162. You might notice also that the file names start appearing one by one 
  163. in the Select a Name gadget.  You can select one of these names even 
  164. before all of the names have been added to the list, though this can be 
  165. a bit tricky as they move around a lot.  While the list is being built 
  166. you can use the slider to look at what names have already been added.  
  167. If you see the name that you want to select, you can stop the building 
  168. of the file name list by clicking on a spot inside the requester but 
  169. outside of all the gadgets; for instance, if you click between the 
  170. OK! and CANCEL gadgets this will stop the list from being constructed.  
  171. Then you can select the name you want as usual.  To restart the building 
  172. of the file name list, click on either the Drawer or Disk string gadget 
  173. and hit return.  
  174.  
  175.  
  176.  
  177.  
  178. =============================================================================
  179. === PROGRAMMER'S REFERENCE ==================================================
  180. =============================================================================
  181.  
  182. This section is for the programmer who wants to use the FileIO Requester 
  183. routines in her or his program.  Also, it's an introduction for those who 
  184. intend in delving into the guts of these routines.  For an overview of the 
  185. FileIO Requester routines, refer to the TECHNICAL REFERENCE section.  
  186.  
  187. The Workbench names for DOS objects have been used in the FileIO Requester, 
  188. and are used throughout this document for simplicity.  For your reference, 
  189. a directory is referred to as a "drawer" and volumes, or DOS filesystem 
  190. devices, are referred to as "disks".  
  191.  
  192. The phraseology on the requester itself was left vague intentionally 
  193. so that the same requester could be used to select names for both 
  194. input and output.  
  195.  
  196. These are the subsections of this section:
  197.  
  198.     o  Basic Operation
  199.  
  200.     o  Multiple FileIOSupport Structures
  201.  
  202.     o  Workbench-style Filename Operations
  203.  
  204.     o  If You Don't Want Workbench-style Filename Operations
  205.  
  206.     o  FileIOSupport Flags
  207.  
  208.     o  GetFileIOName() is non-reentrant
  209.  
  210.     o  Procedure for Adding the FileIO Requester to Your Program
  211.  
  212.  
  213.  
  214.  
  215. === Basic Operation ========================================================
  216.  
  217. The FileIO routines base all of their work on a data structure called 
  218. the FileIOSupport structure.  You are allocated one of these structures 
  219. when you call the GetFileIOSupport() routine.  The structure is 
  220. initialized with reasonable default values for you.
  221.  
  222.  
  223. The FileIOSupport structure is used when calling the GetFileIOName() 
  224. routine, which is the routine that actually presents the requester to 
  225. the user and gets the user's filename selection.  
  226.  
  227. There are several flags and data fields in the FileIOSupport structure 
  228. that you may choose to initialize before calling GetFileIOName().  
  229. By setting or clearing these flags, you define how information is 
  230. to be presented to the user of your requester.  These flags are 
  231. described below in "FileIOSupport Flags".  
  232.  
  233. Also, you may choose to give a title to your FileIO requester, which 
  234. title can illuminate the function of the requester.  For instance, 
  235. you may want to have one FileIOSupport structure used for input and 
  236. another for output.  You could give one the title "- SELECT INPUT FILE -" 
  237. and the other "- SELECT OUTPUT FILE -".  The title you supply is 
  238. centered at the top of the requester.  You supply a title by setting 
  239. the ReqTitle field of your FileIOSupport structure to point to 
  240. a null-terminated text string.  You can also set this field to NULL, 
  241. which is the default.  If this field is NULL, a default title is 
  242. displayed.
  243.  
  244. The GetFileIOName() function returns a BOOL value of TRUE or FALSE, 
  245. depending on whether the user completed or cancelled the filename 
  246. selection process.  If the return value is TRUE, you can find the 
  247. filename selected by the user in the FileName[] field of your 
  248. FileIOSupport structure.  The pathname to the file can be constructed 
  249. by calling the BuildFileIOPathname() function or by using the DiskName[] 
  250. and DrawerName[] fields.  
  251.  
  252. You can call GetFileIOName() any number of times with the same FileIOSupport 
  253. structure.  The data in the FileIOSupport structure usually remains 
  254. valid between calls to GetFileIOName(), so with subsequent calls the 
  255. filename list doesn't have to be constructed anew.  This allows the 
  256. requester to appear very quickly because the usually-lengthy process 
  257. of accessing the disk is avoided.  
  258.  
  259. The GetFileIOName() routine uses the GOOD_FILENAMES flag to discern 
  260. whether the data contained in your FileIOSupport structure is valid.  
  261. If GetFileIOName() sees that the flag is not set it builds the filename 
  262. list from scratch.  If the GOOD_FILENAMES is set, the list is not 
  263. recreated.  
  264.  
  265. When GetFileIOSupport() creates a support structure for you, this flag 
  266. is cleared to specify that the support structure doesn't contain good 
  267. filenames.  Thus the first call to GetFileIOName() causes the filename 
  268. list to be constructed.  The GetFileIOName() function normally sets this 
  269. flag (unless the user has done something unusual or if GetFileIOName() 
  270. failed for some reason such as "out of memory"), so that subsequent 
  271. calls to GetFileIOName() work much more efficiently.  
  272.  
  273. But you must do a bit work to support this efficiency.  You are obliged 
  274. to watch for IDCMP events of class DISKINSERTED and to clear the 
  275. GOOD_FILENAMES flag in any of your FileIOSupport structures whenever 
  276. you see this event.  The DISKINSERTED event occurs when the user has 
  277. switched around the disks.  When the user has changed disks you can't 
  278. be sure that your FileIO filename list is still valid, so as a courtesy 
  279. to the user you must cause the filename list to be reconstructed.  
  280.  
  281. You can use the FileIO Requester to get the name of a file to be used 
  282. for output.  If you do and the specified file doesn't currently 
  283. exist, AmigaDOS will create it anew when you open it.  From the 
  284. FileIO Requester point of view, this means that a file now exists 
  285. that isn't in your FileIOSupport list.  To get the name in the list, 
  286. you can use the AddFileIOName() routine.  This routine adds a file 
  287. name to the list of file names currently in the specified 
  288. FileIOSupport structure.  The next time the FileIOSupport structure 
  289. is used for a call to GetFileIOName(), the new file name will apppear 
  290. alphabetized in with the other file names.  If the name is already in 
  291. the list when you call AddFileIOName() then nothing happens.  
  292. This allows you to call AddFileIOName() without worrying about 
  293. duplicate name redundancy, so you can skip checking whether or not 
  294. AmigaDOS has created a new file.  
  295.  
  296. Finally, when you're finished with your FileIOSupport structure (usually 
  297. not until your program is terminating) then you call ReleaseFileIO() to 
  298. deallocate the structure and all the resources that it's accumulated.  
  299.  
  300.  
  301.  
  302. === Multiple FileIOSupport Structures =======================================
  303.  
  304. Your program can have more than one FileIOSupport structure at a time.  
  305. An example of why you would want more than one FileIOSupport structure:  
  306. you might want to have separate structures for getting input filenames 
  307. and output filenames from the user.  Another example:  you might have 
  308. one structure for letting the user select text files and another for 
  309. the selection of graphics files.  
  310.  
  311. If you have more than one FileIOSupport structure, remember that you must 
  312. clear the GOOD_FILENAMES flag in all of them whenever you see Intuition's 
  313. DISKINSERTED IDCMP event class.  
  314.  
  315. Also, regarding new disks, there's an extra procedure that you must follow.  
  316. If the user changes the disk while you've called GetFileIOName(), you 
  317. won't actually see a DISKINSERTED event (as the event will have been 
  318. processed by GetFileIOName() before control is returned to you).  
  319. So how will you know to clear the GOOD_FILENAMES flag in your other 
  320. structures?   Well, GetFileIOName() records the fact that a DISKINSERTED 
  321. event was handled by setting the DISK_HAS_CHANGED flag in your 
  322. FileIOSupport structure.  So on return from a call to GetFileIOName() 
  323. you should check to see whether your FileIOSupport structure has the 
  324. DISK_HAS_CHANGED flag set.  If it does, you should clear the 
  325. DISK_HAS_CHANGED flag in the structure and then clear the GOOD_FILENAMES 
  326. flag in all of your other FileIOSupport structures.  This assures that 
  327. when you call GetFileIOName() with any of your other support structures, 
  328. the filename lists will be reconstructed, as they should.  
  329.  
  330.  
  331.  
  332. === Workbench-style Filename Operations =====================================
  333.  
  334. You can have file names appear in the FileIO Requester using the same 
  335. rules that govern how files appear on the Workbench display, by using 
  336. the Workbench .info file mechanism.  
  337.  
  338. If you intend on using Workbench pattern matching (or if you are going 
  339. to give the user the option) you must make sure that the constant 
  340. WBENCH_CODE is defined in the fileio.h file.  This includes the Workbench 
  341. code in the FileIO files when they are being compiled.  To attempt to 
  342. match Workbench patterns at run time, you must set the WBENCH_MATCH flag 
  343. in your FileIOSupport structure, as described below.  
  344.  
  345. (By the way, if you don't intend on using Workbench-style pattern 
  346. matching and are interested in saving about 500 bytes of code size, 
  347. make sure you comment out the WBENCH_CODE definition.)
  348.  
  349. The Workbench .info file mechanism is a detailed topic that will not be 
  350. delved into here.  Please read the Amiga ROM Kernel Manual for a 
  351. description of the Workbench operation and data types.  What follows is a 
  352. cursory description of the Workbench technique, which is described only 
  353. well enough to explain how you can interact with it via your FileIOSupport 
  354. structure.  
  355.  
  356. The Workbench program examines the directory of a disk and displays 
  357. icons for the files it finds that end with a ".info" suffix (hereafter 
  358. referred to as .info files).  The file names displayed beneath the 
  359. icons have the ".info" suffix removed.  The Workbench .info files 
  360. contain information regarding what type of data is contained in the 
  361. file (executable program, project data, et cetera).  
  362.  
  363. You can choose to have only .info files displayed to the user (with 
  364. the ".info" suffix removed) in the same way that the Workbench does.  
  365. You get this by setting the WBENCH_MATCH flag.  
  366.  
  367. You can further filter the names that appear if you wish.  There are 
  368. two techniques that you can employ for filtering which file names will 
  369. be added to the list:  you can ask for only those files that match a 
  370. particular Workbench object type and only those files that match a 
  371. particular tool type.  
  372.  
  373. You elect to match the object type by setting the MATCH_OBJECTTYPE flag 
  374. in your FIleIOSupport structure.  The object types typically of interest 
  375. are WBTOOL and WBPROJECT.  By selecting one of these types, your 
  376. filename list will consist only of executable files or data files 
  377. respectively (except that all .info drawer names are always displayed).  
  378. If this is confusing, refer to the ROM Kernel manual for a discussion 
  379. of object types.  
  380.  
  381. You can also request to match a Workbench tool type.  By matching tool 
  382. types, you can, for instance, have your file list display only those 
  383. data files that were created by a specific application.  See the section 
  384. entitled "The ToolTypes Array" in the Workbench chapter of the 
  385. ROM Kernel manual for a description of how tool types work.  You elect 
  386. to match tool types by setting the MATCH_TOOLTYPES flag in your 
  387. FileIOSupport structure.  The ToolTypes text that you must supply 
  388. should be written into the ToolTypes[] field of your FileIOSupport 
  389. structure.  
  390.  
  391.  
  392.  
  393. === If You Don't Want Workbench-style Filename Operations ===================
  394.  
  395. If you don't intend on using the Workbench-style pattern matching as
  396. described above, then make sure you comment out the WBENCH_CODE definition.
  397. This will result in a savings of about 500 bytes of code size.
  398.  
  399. If you comment out the WBENCH_CODE definition, then setting the WBENCH_MATCH
  400. flag in your FileIOSupport structure will have no effect.
  401.  
  402.  
  403.  
  404. === FileIOSupport Flags =====================================================
  405.  
  406. GOOD_FILENAMES
  407.     This flag designates whether the filename data contained in the 
  408.     FileIOSupport is valid.  The flag is cleared by the 
  409.     GetFileIOSupport() function, and is usually set by the 
  410.     GetFileIOName() function.  When GetFileIOName() is called, this 
  411.     flag is checked and if it's set then the disk isn't reexamined for 
  412.     file names.  You should clear this flag in your FileIOSupport 
  413.     structures in two instances.  First, when you receive an Intuition 
  414.     IDCMP event of DISKINSERTED you should clear this flag in all of 
  415.     your FileIOSupport structures.  Second, if you have more than 
  416.     one FileIOSupport structure then on return from a call to 
  417.     GetFileIOName() you should check whether your support structure 
  418.     has the DISK_HAS_CHANGED flag set and if so you should clear 
  419.     the DISK_HAS_CHANGED flag in the structure and clear the 
  420.     GOOD_FILENAMES flag in all of your other FileIOSupport structures.  
  421.  
  422.  
  423. USE_VOLUME_NAMES
  424.     When you leave this flag set, the AmigaDOS volume names will 
  425.     be used for the disk names in the requester.  If you clear 
  426.     this flag, the device names will be used instead.  What's a 
  427.     volume name and what's a device name?  Well, if you have your 
  428.     Workbench disk in the Amiga's internal drive, then the volume 
  429.     name of that disk is "Workbench:" and the device name is "DF0:".  
  430.     Which you choose to use is up to you.  Programmers are more 
  431.     familiar with device names.  The typical end-user is more 
  432.     familiar with volume names.  The default is to follow the 
  433.     Workbench convention and use volume names.  
  434.  
  435.  
  436. DISK_HAS_CHANGED
  437.     If the user changes the disk while the FileIO Requester is 
  438.     being displayed, this flag is set in the FileIOSupport 
  439.     structure.  The only time you must pay attention to this 
  440.     flag is when you have multiple FileIOSupport structures.  
  441.     If you find that this flag has been set, you must clear 
  442.     this flag in your FileIOSupport structure and then clear 
  443.     the GOOD_FILENAMES flag in all of your other FileIOSupport 
  444.     structures.  
  445.  
  446.  
  447. DOUBLECLICK_OFF
  448.     Normally, the user can double-click on a filename to select it.  
  449.     You may choose to disable this feature, for instance, 
  450.     when you want the user to be very certain about the 
  451.     filename selection (perhaps if the file is about to 
  452.     be destroyed, or something equally drastic).  
  453.     To disable double-clicking, set the DOUBLECLICK_OFF flag.  
  454.     Then the user will have to explicitly select OK! or type 
  455.     and filename and hit return for the selection to be made.
  456.  
  457.  
  458. WBENCH_MATCH
  459.     You set this flag to specify that you want Workbench-style 
  460.     .info file logic to be used when constructing the filename list.  
  461.     If you set this flag, only directory names and file names that 
  462.     pass the .info file tests will be displayed in the file name 
  463.     list.  See the "Workbench-style Filename Operations" section 
  464.     above for complete information.  This flag is cleared when 
  465.     your FileIOSupport structure is first created.
  466.  
  467.  
  468. MATCH_OBJECTTYPE
  469.     When you set this flag (and the WBENCH_MATCH flag), the 
  470.     DiskObjectType field of your FileIOSupport structure will 
  471.     be compared with the do_Type field of the .info file's 
  472.     DiskObject structure.  If they match, the file will be 
  473.     displayed.  Both the MATCH_TOOLTYPE and the MATCH_OBJECTTYPE 
  474.     flags can be set at the same time.  See the "Workbench-style 
  475.     Filename Operations" section above for complete information.  
  476.  
  477.  
  478. MATCH_TOOLTYPE
  479.     If you set this flag (and the WBENCH_MATCH flag), then 
  480.     Workbench-style ToolType pattern matching will be performed 
  481.     and must be successful before the filename will be included 
  482.     in the list.  You specify your selection of ToolType in the 
  483.     FileIOSupport structure's ToolType[] field.  Both the 
  484.     MATCH_TOOLTYPE and the MATCH_OBJECTTYPE flags can be set at 
  485.     the same time.  See the "Workbench-style Filename Operations" 
  486.     section above for complete information.  
  487.  
  488.  
  489.  
  490. === GetFileIOName() is non-reentrant =======================================
  491.  
  492. If your program doesn't create tasks, or if you have multiple tasks 
  493. but only one of your tasks will call GetFileIOName() (which is almost 
  494. always the case), you can ignore the following information.  
  495.  
  496. The GetFileIOName() routine is non-reentrant.  For the sake of memory 
  497. efficiency, it uses global data and variables rather than creating local 
  498. copies of these for each caller.  
  499.  
  500. What this means is that if you have created a program that has more 
  501. than one task, GetFileIOName() cannot be called by more than one task 
  502. at a time.  This is not a problem for the grand majority of programs.  
  503.  
  504. But if you have some application that would require calling this routine 
  505. asynchronously from multiple tasks, you'll have to implement some 
  506. quick semaphore arrangement to avoid collisions.  No big deal, actually.  
  507. See Exec semaphores for everything you need.  
  508.  
  509.  
  510.  
  511.  
  512. === Procedure for Adding the FileIO Requester to Your Program ===============
  513.  
  514. This section presents a step-by-step procedure for incorporating
  515. the FileIO Requester code into your own program.
  516.  
  517.  
  518.  
  519. Copy these FileIO files into your directory (and include them in your 
  520. makefile):
  521.     alerts.c chipdata.c fileio.c filename.c filesupp.c global.c 
  522.     opendata.c pointers.c reqsupp.c strings.c volname.c
  523.     fileio.h eglobal.c
  524.  
  525.  
  526.  
  527. You have to include fileio.h in every file that refers to your
  528. FileIOSupport structure.  
  529.  
  530.     #include "fileio.h"
  531.  
  532.  
  533.  
  534. Are you going to provide your users with Workbench-style .info file
  535. pattern matching?  If so, then go into fileio.h and make sure that 
  536. WBENCH_CODE is defined.  
  537.  
  538.     #define WBENCH_CODE
  539.  
  540. If you're not going to provide Workbench .info file pattern matching, 
  541. verify that WBENCH_CODE isn't defined.  This make the FileIO code
  542. about 500 bytes smaller.
  543.  
  544.     /* #define WBENCH_CODE */
  545.  
  546.  
  547.  
  548. Declare a pointer to a FileIOSupport structure, and then fill that 
  549. pointer with the address of one of the structures.
  550.  
  551.     struct FileIOSupport *FileIOSupp;
  552.  
  553.     FileIOSupp = GetFileIOSupport();
  554.  
  555.  
  556.  
  557. Your NewWindow structure should have the DISKINSERTED flag set along with 
  558. your other IDCMP flags.  Whenever you receive a DISKINSERTED event, you 
  559. should clear the GOOD_FILENAMES flag in every FileIOSupport structure you 
  560. control.  The following code could be added to the case switch where you 
  561. handle IDCMP events.
  562.  
  563.     switch (imessageclass)
  564.         {
  565.         case DISKINSERTED:
  566.             /* You should clear the GOOD_FILENAMES flag 
  567.              * whenever you detect that a new disk was 
  568.              * inserted.
  569.              */
  570.             if (FileIOSupp)
  571.                 ClearFlag(FileIOSupp->Flags, GOOD_FILENAMES);
  572.             break;
  573.         }
  574.  
  575.  
  576.  
  577. When you want to present the FileIO Requester to the user, call 
  578. GetFileIOName().  If this routine returns TRUE, the user did not cancel the
  579. operation.  The following code is an example of presenting the FileIO
  580. Requester to the user and then reacting to the result.
  581.  
  582.     if (FileIOSupp)
  583.         if (GetFileIOName(FileIOSupp, window))
  584.             {
  585.             UBYTE name[128];
  586.  
  587.             BuildFileIOPathname(FileIOSupp, &name[0]);
  588.  
  589.             /* Here do something like read or write the file.
  590.              * If you write the file, you should call 
  591.              * AddFileIOName() if you've created a new file 
  592.              * or if you don't want to bother checking 
  593.              * whether or not it was a newly-created file.
  594.              */
  595.             if (writefile) AddFileIOName(FileIOSupp, &name[0]);
  596.             }
  597.  
  598.  
  599.  
  600.  
  601. Finally, when you're done with your FileIOSupport structure (usually when 
  602. you're program is exiting), you can free up the structure and its resources 
  603. with a simple call to ReleaseFileIO(), like this:
  604.  
  605.     if (FileIOSupp) ReleaseFileIO(FileIOSupp);
  606.  
  607.  
  608.  
  609.  
  610. =============================================================================
  611. === DEMO PROGRAM NOTES ======================================================
  612. =============================================================================
  613.  
  614. This section briefly describes the demo program that drives some of 
  615. the FileIO Requester's features.  
  616.  
  617. If you invoke the program without a second argument, a window will be 
  618. opened in the Workbench screen.  If you invoke the program with any 
  619. second argument, a low-res screen will be opened for the requester window.  
  620.  
  621. The program uses two FileIOSupport structures to demonstrate the 
  622. techniques that you should use when managing multiple FileIOSupports.  
  623. These techniques include processing DISKINSERTED events and discovering 
  624. on return from GetFileIOName() that the DISK_HAS_CHANGED flag is set.  
  625.  
  626. The first support structure, fileio1, is used in its vanilla state 
  627. as created by GetFileIOSupport().  The other support structure, fileio2, 
  628. is initialized to do Workbench-style .info file handling where the 
  629. filename list will consist of only .info objects of type WBPROJECT.  
  630.  
  631. Also, every time you insert a disk, the USE_VOLUME_NAMES flag in the 
  632. support structures is toggled, so that first you see volume names and 
  633. then you see device names.  This is for demonstration only; it's not 
  634. suggested that you use this technique in a real program.  
  635.  
  636. Finally, when you do any of the selection techniques where you accept 
  637. your selection, the pathname to your selection is displayed in an 
  638. autorequester.  If you choose CANCEL to end the requester, nothing happens.  
  639.  
  640. To stop the program, click in the window close gadget.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646. =============================================================================
  647. === TECHNICAL REFERENCE =====================================================
  648. =============================================================================
  649.  
  650. This section gives you a brief outline of the FileIO software system files, 
  651. plus some scanty supplementary information.  
  652. Please refer to the source code itself.  The routines are commented 
  653. and, hopefully, reasonably laid out.  
  654.  
  655.  
  656. The FileIO files include:
  657.  
  658.     alerts.c
  659.         Autorequester alert routines for emergency
  660.         and shortcut communications
  661.  
  662.     chipdata.c
  663.         Data for the Open requester that must be in chip memory
  664.  
  665.     eglobal.c 
  666.         External global variable declarations
  667.  
  668.     fileio.c
  669.         FileIO interface routines:  GetFileIOSupport(), 
  670.         GetFileIOName(), BuildFileIOPathname(), AddFileIOName(), 
  671.         and ReleaseFileIO()
  672.  
  673.     fileio.h 
  674.         The FileIO structure and constants definitions
  675.  
  676.     filename.c
  677.         Routines that build the filename list
  678.  
  679.     filesupp.c
  680.         Routines that create and manage the Open Requester
  681.  
  682.     global.c
  683.         Global variable declarations
  684.  
  685.     main.c
  686.         Demonstration program
  687.  
  688.     opendata.c
  689.         Open Requester declarations
  690.  
  691.     pointers.c
  692.         Pointer routines of the Amiga Programmer's Suite
  693.  
  694.     reqsupp.c
  695.         DoRequest() routine of the Amiga Programmer's Suite
  696.  
  697.     strings.c
  698.         RJ's general crude string manipulation routines
  699.  
  700.     volname.c 
  701.         Routines that build the volume list
  702.  
  703.  
  704.  
  705.  
  706.  
  707. === USING THE AMIGA PROGRAMMER'S SUITE ======================================
  708.  
  709. The Amiga Programmer's Suite Book 1 is copyrighted but freely distributable.
  710. All copyright notices and all file headers must be retained intact.
  711. The Amiga Programmer's Suite Book 1 may be compiled and assembled, and the 
  712. resultant object code may be included in any software product.  However, no 
  713. portion of the source listings or documentation of the Amiga Programmer's 
  714. Suite Book 1 may be distributed or sold for profit or in a for-profit 
  715. product without the written authorization of the author, RJ Mical.
  716.  
  717. If you use the Amiga Programmer's Suite, I wouldn't mind if you gave me 
  718. some mention somewhere.
  719. Good luck!  Program hard, program well.    -RJ Mical
  720.  
  721.  
  722.  
  723.  
  724. === APPENDIX A:  FileIO Function Calls ======================================
  725.  
  726. CONTENTS:
  727.    AddFileIOName()
  728.    BuildFileIOPathname()
  729.    GetFileIOSupport()
  730.    GetFileIOName()
  731.    ReleaseFileIO()
  732.  
  733.  
  734.  
  735.  
  736.  
  737. *** AddFileIOName() ******************************************************
  738.  
  739. NAME
  740.     AddFileIOName  --  Add a file name to the names in a FileIOSupport
  741.  
  742.  
  743. SYNOPSIS
  744.     AddFileIOName(FileIOSupport, FileName);
  745.  
  746.  
  747. FUNCTION
  748.     This routine adds a file name to the list of file names currently 
  749.     in the specified FileIOSupport structure.  The next time the 
  750.     FileIOSupport structure is used for a call to GetFileIOName(), the 
  751.     new file name will apppear alphabetized in with the other file names.  
  752.     
  753.     This routine will most often be used after a call to GetFileIOName() 
  754.     or some other routine where the user is allowed to specify the name 
  755.     of a file to be opened for output.  If the file is opened 
  756.     successfully, this routine will make sure that the name of the file 
  757.     is in the FileIOSupport structure.  This is important if the output 
  758.     file has been newly created; otherwise, without calling this 
  759.     routine, the next time the FileIOSupport structure is used the new 
  760.     file name would not appear even though the file exists.  If the name 
  761.     is already in the list when you call AddFileIOName() then nothing 
  762.     happens.  This allows you to call AddFileIOName() without worrying 
  763.     about duplicate name redundancy.
  764.     
  765.     Here's a typical sequence of events leading up to a call to 
  766.     AddFileIOName():
  767.     
  768.         First, get a FileIOSupport structure:
  769.             fileio = GetFileIOSupport(...);
  770.     
  771.         When the user wants to write data, use GetFileIOName()
  772.         to provide a convenient and consistent interface to
  773.         the filesystem:
  774.             goodfile = GetFileIOName(...);
  775.     
  776.         If the user has selected a name for output (in this example,
  777.         goodfile will equal TRUE if the user selected a name), then
  778.         open the file (possibly creating it) and then call 
  779.         AddFileIOName() to make sure the name is in the FileIOSupport
  780.         structure's list:
  781.             if (goodfile)
  782.                 {
  783.                 UBYTE filename[80];
  784.                 
  785.                 BuildFileIOPathname(fileio, &filename[0]);
  786.                 ... open filename, write it, close it ...
  787.                 if (filename opened successfully)
  788.                     AddFileIOName(fileio, &filename[0]);
  789.                 }
  790.  
  791.  
  792. INPUTS
  793.     FileIOSupport = the address of a FileIOSupport structure
  794.     FileName = the address of null-terminated text that is
  795.         either a simple file name or a valid AmigaDOS pathname.
  796.  
  797.  
  798. RESULT
  799.     None
  800.  
  801.  
  802. SEE ALSO
  803.     GetFileIOName()
  804.     GetFileIOSupport()
  805.  
  806.  
  807.  
  808.  
  809.  
  810. *** BuildFileIOPathname() ************************************************
  811.  
  812. NAME
  813.     BuildFileIOPathname  --  Build a file pathname using a FileIO struct
  814.  
  815.  
  816. SYNOPSIS
  817.     BuildFileIOPathname(FileIOSupport, Buffer);
  818.  
  819.  
  820. FUNCTION
  821.     Builds the text for a pathname using the FileName[], DrawerName[] and
  822.     DiskName[] fields of the specified FileIOSupport structure
  823.     after the support structure has been used in a successful call
  824.     to GetFileIOName().  Writes the text into the Buffer.
  825.  
  826.  
  827. INPUTS
  828.     FileIOSupport = the address of a FileIOSupport structure
  829.  
  830.     Buffer = address of the buffer to receive the file pathname
  831.  
  832.  
  833. RESULT
  834.     None
  835.  
  836.  
  837. SEE ALSO
  838.     GetFileIOName()
  839.  
  840.  
  841.  
  842.  
  843.  
  844. *** GetFileIOSupport() ***************************************************
  845.  
  846. NAME
  847.     GetFileIO  --  Allocate and initialize a FileIOSupport structure
  848.  
  849.  
  850. SYNOPSIS
  851.     struct FileIOSupport *GetFileIOSupport();
  852.  
  853.  
  854. FUNCTION
  855.     Allocates and initializes a FileIOSupport structure for use with
  856.     calls to GetFileIOName().
  857.  
  858.     You may want to further initialize the structure before calling
  859.     GetFileIOName().  Refer to the FileIO documentation for more
  860.     information.
  861.  
  862.     When you're done with the structure, call ReleaseFileIO().
  863.  
  864.  
  865. INPUTS
  866.     None
  867.  
  868.  
  869. RESULT
  870.     If all goes well, returns the address of a FileIOSupport structure.
  871.     If anything goes wrong (usually out of memory), returns NULL.
  872.  
  873.  
  874. EXAMPLE
  875.     struct FileIOSupport *fileio;
  876.     fileio = GetFileIOSupport();
  877.     GetFileIOName(fileio, window);
  878.     ReleaseFileIO(fileio);
  879.  
  880.  
  881. BUGS
  882.     None known
  883.  
  884.  
  885. SEE ALSO
  886.     GetFileIOName(), ReleaseFileIO()
  887.  
  888.  
  889.  
  890.  
  891.  
  892. *** GetFileIOName() ******************************************************
  893.  
  894. NAME
  895.     GetFileIOName  --  Gets a file name for input/output from the user
  896.  
  897.  
  898. SYNOPSIS
  899.     BOOL GetFileIOName(FileIO, Window);
  900.  
  901.  
  902. FUNCTION
  903.     This routine creates a filename requester which allows the user
  904.     to browse through the AmigaDOS filesystem and select one of
  905.     the filenames found there.
  906.  
  907.     The FileIO argument is a pointer to a FileIOSupport structure,
  908.     which is allocated and initialized for you via a call to 
  909.     GetFileIOSupport().
  910.     You may preset the FileIO parameters before calling this routine, 
  911.     or you may leave them set at their default values.  See the FileIO
  912.     documentation for complete details.
  913.  
  914.     The Window argument is the pointer to the window structure returned
  915.     by a call to Intuition's OpenWindow() function.  As this routine
  916.     opens a requester and requesters open in windows, you must have
  917.     already opened a window before calling this routine, even if it's
  918.     a window opened for no other purpose than to call this routine.
  919.  
  920.     This routine returns a BOOL value of TRUE or FALSE, depending on
  921.     whether the user chose to accept or cancel the filename selection 
  922.     operation.  If TRUE, the filename selected by the user can be
  923.     found in the FileIO structure FileName[] field.  This filename
  924.     will have all leading and trailing blanks removed (in case the
  925.     user typed in a filename with extraneous spaces).  Likewise,
  926.     the pathname to the disk and drawer can be found in the text
  927.     fields DiskName[] and DrawerName[].  You can construct 
  928.     the pathname using these text strings.  Also, you can call 
  929.     BuildFileIOPathname() to build the pathname automatically.
  930.  
  931.     There's a *lot* more to be said about this function.  Please 
  932.     read the documentation.
  933.  
  934.     NOTE:  This routine is not re-entrant.  What this means 
  935.     is that if you have created a program that has more than one task,
  936.     this routine cannot be called by more than one task at a time.
  937.     This is not a problem for the grand majority of programs.
  938.     But if you have some application that would require calling this 
  939.     routine asynchronously from multiple tasks, you'll have to 
  940.     implement some quick semaphore arrangement to avoid collisions.
  941.     No big deal, actually.  See Exec semaphores for everything you need.
  942.  
  943.  
  944. INPUTS
  945.     FileIO = pointer to a FileIOSupport structure, as allocated
  946.         via a call to GetFileIOSupport()
  947.  
  948.     Window = pointer to a Window structure, as created via a call
  949.         to Intuition's OpenWindow()
  950.  
  951.  
  952. RESULT
  953.     TRUE if the user decided that the filename selection was successful,
  954.     FALSE if the user chose to cancel the operation
  955.  
  956.  
  957. EXAMPLE
  958.     if (GetFileIOName(fileio, window))
  959.         ProcessFileName(&fileio->FileName[0]);
  960.  
  961.  
  962. BUGS
  963.     None known, though there could be some, and the disk selection
  964.     subsystem logic is not perfectly polished (though it's believed 
  965.     to be bug-free).
  966.  
  967.  
  968. SEE ALSO
  969.     BuildFileIOPathname(), GetFileIOSupport(), ReleaseFileIO()
  970.  
  971.  
  972.  
  973.  
  974.  
  975. *** ReleaseFileIO() ******************************************************
  976.  
  977. NAME
  978.     ReleaseFileIO  --  Release the FileIO structure and all local memory
  979.  
  980.  
  981. SYNOPSIS
  982.     ReleaseFileIO(FileIO);
  983.  
  984.  
  985. FUNCTION
  986.     Releases the FileIO structure by freeing all local memory attached
  987.     to the structure and then freeing the structure itself.
  988.  
  989.  
  990. INPUTS
  991.     FileIO = the address of a FileIO structure
  992.  
  993.  
  994. RESULT
  995.     None
  996.  
  997.  
  998. SEE ALSO
  999.     GetFileIOSupport()
  1000.  
  1001.