home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 1: Collection A / 17Bit_Collection_A.iso / files / 223.dms / 223.adf / Source / filereq.c next >
C/C++ Source or Header  |  1988-07-25  |  45KB  |  1,484 lines

  1. /****************************************************************************
  2.  *
  3.  *  FileRequest() - File Name Requester
  4.  *
  5.  *  Version 2.1
  6.  *
  7.  *  This version of FileRequest is considerably modified from the
  8.  *  original by Kevin Clague. It has been fixed to work under DOS 1.2 and new
  9.  *  features have been added (such as the DF buttons, sorting of the
  10.  *  file names, the file filter, the default display of the users
  11.  *  current directory (including the path name builder), and scrolling 
  12.  *  of names.
  13.  *  
  14.  *  Original version of FileRequest
  15.  *  By Kevin Lee Clague
  16.  *     408 Tortolla Way
  17.  *     San Jose, Ca 95033
  18.  *     408-258-9891       work 408-737-5481
  19.  *
  20.  *  Copyright (C) 1986. All rights reserved.
  21.  *
  22.  *  This program is freely distributable as long as this copyright notice
  23.  *  is retained. It intended for personal, non-commercial use.  
  24.  *
  25.  *  This file name requester is modeled after Deluxe Paints file name
  26.  *  requester. The dimensions/locations of all borders, gadgets and text were
  27.  *  arrived at empirically. Besides being a great program, Deluxe Paint is a
  28.  *  trade mark of Electronics Arts.
  29.  *
  30.  *  *    *    *    *    *    *    *    *    *    *    *    *    *    *    *   *
  31.  *
  32.  *  The changes in this version by:
  33.  *       Ray R. Larson
  34.  *       6425 Central Ave. #304
  35.  *       El Cerrito, CA 94530
  36.  *
  37.  *       BitNet  LARSON@UCBCMSA
  38.  *       Well    rrl
  39.  *       CServe  70446,766
  40.  *    
  41.  * This revised version Copyright (c) 1988 by Ray R. Larson
  42.  * 
  43.  * This program may be freely distributed and copied, but may not be sold
  44.  * without the permission of the author. If you modify or enhance it, 
  45.  * please include the above credits (and please send me a copy!).
  46.  *
  47.  ***************************************************************************/
  48.  
  49. #include <exec/types.h>
  50. #include <graphics/gfxbase.h>
  51. #include <libraries/dos.h>
  52. #include <libraries/dosextens.h>
  53. #include <intuition/intuition.h>
  54. #include <intuition/intuitionbase.h>
  55. #include <ctype.h>
  56. #include <stdio.h>
  57. #include <workbench/workbench.h>
  58.  
  59. #define INTUITION_REV      1
  60. #define GRAPHICS_REV      1
  61.  
  62. #define CHARACTER_WIDTH  8
  63. #define CHARACTER_HEIGHT 8
  64.  
  65. /* ========================================================================*/
  66. /* File name requester gadget ids                                          */
  67.  
  68. #define CLASSBITS 8
  69.  
  70. #define UPDOWNCLASS 1
  71. #define CHOICECLASS 2
  72. #define STRINGCLASS 3
  73. #define BUTTONCLASS 4
  74.  
  75. #define GADGETNUM 255
  76.  
  77. #define LOAD   0
  78. #define CANCEL 1
  79. #define TODF0  2 
  80. #define TODF1  3 
  81. #define TODH0  4 
  82. #define TOVD0  5 
  83. #define TORAM  6 
  84. #define PARENT 7
  85.  
  86. #define DRAWER 0
  87.  
  88. #define UP     0
  89. #define DOWN   1
  90. #define POT    2
  91.  
  92. #define FILE0  0
  93. #define FILE1  1
  94. #define FILE2  2
  95. #define FILE3  3
  96. #define FILE4  4
  97. #define FILE5  5
  98. #define FILE6  6
  99. #define FILE7  7
  100.  
  101. #define LOADGADGET   BUTTONCLASS << CLASSBITS | LOAD
  102. #define CANCELGADGET BUTTONCLASS << CLASSBITS | CANCEL
  103. #define DF0GADGET BUTTONCLASS << CLASSBITS | TODF0
  104. #define DF1GADGET BUTTONCLASS << CLASSBITS | TODF1
  105. #define DH0GADGET BUTTONCLASS << CLASSBITS | TODH0
  106. #define VD0GADGET BUTTONCLASS << CLASSBITS | TOVD0
  107. #define RAMGADGET BUTTONCLASS << CLASSBITS | TORAM
  108. #define PARENTGADGET BUTTONCLASS << CLASSBITS | PARENT
  109.  
  110. #define UPGADGET     UPDOWNCLASS << CLASSBITS | UP
  111. #define DOWNGADGET   UPDOWNCLASS << CLASSBITS | DOWN
  112. #define POTGADGET    UPDOWNCLASS << CLASSBITS | POT
  113.  
  114. #define FILE0GADGET  CHOICECLASS << CLASSBITS | FILE0
  115. #define FILE1GADGET  CHOICECLASS << CLASSBITS | FILE1
  116. #define FILE2GADGET  CHOICECLASS << CLASSBITS | FILE2
  117. #define FILE3GADGET  CHOICECLASS << CLASSBITS | FILE3
  118. #define FILE4GADGET  CHOICECLASS << CLASSBITS | FILE4
  119. #define FILE5GADGET  CHOICECLASS << CLASSBITS | FILE5
  120. #define FILE6GADGET  CHOICECLASS << CLASSBITS | FILE6
  121. #define FILE7GADGET  CHOICECLASS << CLASSBITS | FILE7
  122.  
  123. #define DRAWERGADGET STRINGCLASS << CLASSBITS | DRAWER
  124.  
  125. #define MAXFILES 100
  126.  
  127. BOOL IsDir();
  128. BOOL WaitRequester();
  129. extern UBYTE  *rindex();
  130. extern struct IntuiMessage *GetMsg();
  131. struct Requester FileRequester;
  132.  
  133. UBYTE *FullPath;
  134. UBYTE *ExcludeExt;
  135. UBYTE *LimitExt;
  136. UBYTE pathname[100];
  137.  
  138. struct Window       *window;
  139. struct IntuiMessage *message;
  140. struct RastPort *FileReqRP;
  141. struct FileInfoBlock *FileInfo;
  142.  
  143. USHORT FileCount;                     /* Number of files in current dir */
  144. UBYTE  FileListEntry[MAXFILES][40];   /* File (dir) names in current dir */
  145.  
  146. USHORT FirstFile;
  147.  
  148. #define PATHNAMELEN 120
  149.  
  150. /****************************************************************************
  151.  *                The Gadget String
  152.  ***************************************************************************/
  153. /******************************
  154.  * The File Name Gadget stuff *
  155.  *****************************/
  156. struct IntuiText FileText =
  157.   {
  158.   0,1, JAM2,              /* frontpen, packpen, drawmode */
  159.   -46,0,                  /* left,top */
  160.   NULL,                   /* font */
  161.   (UBYTE *)"File:",                /* text */
  162.   NULL                    /* next */
  163.   };
  164.  
  165. UBYTE FileName[40];
  166. UBYTE Backup[100];
  167. struct StringInfo FileString = {
  168.     &FileName[0],               /* input buffer */
  169.     &Backup[0],                 /* undo  buffer */
  170.     0,                       /* Buffer position */
  171.     32,                      /* buffer size  */
  172.     0,                       /* disp position*/
  173.     0,0,0,0,0,NULL,0,NULL    /* undo position*/
  174.   };
  175.  
  176. SHORT DrawerPoints[] = {
  177.     -2, -2,
  178.     185,-2,
  179.     185,10,
  180.     -2, 10,
  181.     -2, -2
  182.     };
  183. struct Border DrawerBorder = {
  184.     0,0,
  185.     0,1,JAM1,
  186.     5,
  187.     &DrawerPoints[0],
  188.     NULL
  189.   };
  190.  
  191. struct Gadget FileGadget =
  192.   { /* File string */
  193.   NULL,                    /* next gadget */
  194.   67,139,                  /* location    */
  195.   185,8,
  196.   GADGHCOMP,               /* flags       */
  197.   0,                       /* activation  */
  198.   STRGADGET|REQGADGET,     /* type        */
  199.   (APTR) &DrawerBorder,    /* rendering   */
  200.   NULL,                    /* rendering   */
  201.   &FileText,               /* text        */
  202.   0,                       /* mutual exlcude */
  203.   (APTR)&FileString,             /* string info */
  204.   NULL,                    /* gadget id   */
  205.   NULL                     /* special info*/
  206.   };
  207.  
  208. /********************************
  209.  * The Drawer Name Gadget stuff *
  210.  *******************************/
  211. struct IntuiText DrawerText = 
  212.   {
  213.   0,1, JAM2,              /* frontpen, packpen, drawmode */
  214.   -62,0,                  /* left,top */
  215.   NULL,                   /* font */
  216.   (UBYTE *)"Drawer:",              /* text */
  217.   NULL                    /* next */
  218.   };
  219.  
  220. UBYTE DrawerName[100];
  221. struct StringInfo DrawerString = {
  222.     &DrawerName[0],             /* input buffer */
  223.     &Backup[0],                 /* undo  buffer */
  224.     0,                       /* Buffer position */
  225.     100,                      /* buffer size  */
  226.     0,                       /* disp position*/
  227.     0,0,0,0,0,NULL,0,NULL    /* undo position*/
  228.   };
  229.  
  230. struct Gadget DrawerGadget =
  231.   { /* Drawer string */
  232.   &FileGadget,             /* next gadget */
  233.   67,124,                   /* location    */
  234.   185,8,
  235.   GADGHCOMP,               /* flags       */
  236.   RELVERIFY,               /* activation  */
  237.   STRGADGET|REQGADGET,     /* type        */
  238.   (APTR) &DrawerBorder,    /* rendering   */
  239.   NULL,                    /* rendering   */
  240.   &DrawerText,             /* text        */
  241.   0,                       /* mutual exlcude */
  242.   (APTR)&DrawerString,           /* string info */
  243.   DRAWERGADGET,            /* gadget id   */
  244.   NULL                     /* special info*/
  245.   };
  246.  
  247. /****************************************
  248.  * The File list selection Gadget stuff *
  249.  ***************************************/
  250. UBYTE PickNames[8][40];
  251. struct IntuiText FileList[] =
  252.   {
  253.     {
  254.     0,1, JAM2,              /* frontpen, packpen, drawmode */
  255.     5,14,                    /* left,top */
  256.     NULL,                   /* font */
  257.     &PickNames[0][0],       /* text */
  258.     &FileList[1]            /* next */
  259.     },
  260.     {
  261.     0,1, JAM2,              /* frontpen, packpen, drawmode */
  262.     5,24,                    /* left,top */
  263.     NULL,                   /* font */
  264.     &PickNames[1][0],       /* text */
  265.     &FileList[2]            /* next */
  266.     },
  267.     {
  268.     0,1, JAM2,              /* frontpen, packpen, drawmode */
  269.     5,34,                    /* left,top */
  270.     NULL,                   /* font */
  271.     &PickNames[2][0],       /* text */
  272.     &FileList[3]            /* next */
  273.     },
  274.     {
  275.     0,1, JAM2,              /* frontpen, packpen, drawmode */
  276.     5,44,                    /* left,top */
  277.     NULL,                   /* font */
  278.     &PickNames[3][0],       /* text */
  279.     &FileList[4]            /* next */
  280.     },
  281.     {
  282.     0,1, JAM2,              /* frontpen, packpen, drawmode */
  283.     5,54,                    /* left,top */
  284.     NULL,                   /* font */
  285.     &PickNames[4][0],       /* text */
  286.     &FileList[5]            /* next */
  287.     },
  288.     {
  289.     0,1, JAM2,              /* frontpen, packpen, drawmode */
  290.     5,64,                    /* left,top */
  291.     NULL,                   /* font */
  292.     &PickNames[5][0],       /* text */
  293.     &FileList[6]            /* next */
  294.     },
  295.     {
  296.     0,1, JAM2,              /* frontpen, packpen, drawmode */
  297.     5,74,                    /* left,top */
  298.     NULL,                   /* font */
  299.     &PickNames[6][0],       /* text */
  300.     &FileList[7]            /* next */
  301.     },
  302.     {
  303.     0,1, JAM2,              /* frontpen, packpen, drawmode */
  304.     5,84,                    /* left,top */
  305.     NULL,                   /* font */
  306.     &PickNames[7][0],       /* text */
  307.     NULL                    /* next */
  308.     }
  309.   };
  310.  
  311. struct Gadget FileListGadget[] =
  312.   {
  313.     { /* File name selection 0 */
  314.     &FileListGadget[1],      /* next gadget */
  315.     5,14,                    /* location    */
  316.     244,8,
  317.     GADGHCOMP,               /* flags       */
  318.     GADGIMMEDIATE,           /* activation  */
  319.     BOOLGADGET|REQGADGET,    /* type        */
  320.     NULL,                    /* rendering   */
  321.     NULL,                    /* rendering   */
  322.     NULL,            /* text        */
  323.     0,                       /* mutual exlcude */
  324.     NULL,                    /* string info */
  325.     FILE0GADGET,             /* gadget id   */
  326.     (APTR)&PickNames[0][0]         /* special info*/
  327.     },
  328.     { /* File name selection 1 */
  329.     &FileListGadget[2],      /* next gadget */
  330.     5,24,                    /* location    */
  331.     244,8,
  332.     GADGHCOMP,               /* flags       */
  333.     GADGIMMEDIATE,           /* activation  */
  334.     BOOLGADGET|REQGADGET,    /* type        */
  335.     NULL,                    /* rendering   */
  336.     NULL,                    /* rendering   */
  337.     NULL,            /* text        */
  338.     0,                       /* mutual exlcude */
  339.     NULL,                    /* string info */
  340.     FILE1GADGET,             /* gadget id   */
  341.     (APTR)&PickNames[1][0]         /* special info*/
  342.     },
  343.     { /* File name selection 2 */
  344.     &FileListGadget[3],      /* next gadget */
  345.     5,34,                    /* location    */
  346.     244,8,
  347.     GADGHCOMP,               /* flags       */
  348.     GADGIMMEDIATE,           /* activation  */
  349.     BOOLGADGET|REQGADGET,    /* type        */
  350.     NULL,                    /* rendering   */
  351.     NULL,                    /* rendering   */
  352.     NULL,            /* text        */
  353.     0,                       /* mutual exlcude */
  354.     NULL,                    /* string info */
  355.     FILE2GADGET,             /* gadget id   */
  356.     (APTR)&PickNames[2][0]         /* special info*/
  357.     },
  358.     { /* File name selection 3 */
  359.     &FileListGadget[4],      /* next gadget */
  360.     5,44,                    /* location    */
  361.     244,8,
  362.     GADGHCOMP,               /* flags       */
  363.     GADGIMMEDIATE,           /* activation  */
  364.     BOOLGADGET|REQGADGET,    /* type        */
  365.     NULL,                    /* rendering   */
  366.     NULL,                    /* rendering   */
  367.     NULL,            /* text        */
  368.     0,                       /* mutual exlcude */
  369.     NULL,                    /* string info */
  370.     FILE3GADGET,             /* gadget id   */
  371.     (APTR)&PickNames[3][0]         /* special info*/
  372.     },
  373.     { /* File name selection 4 */
  374.     &FileListGadget[5],      /* next gadget */
  375.     5,54,                    /* location    */
  376.     244,8,
  377.     GADGHCOMP,               /* flags       */
  378.     GADGIMMEDIATE,           /* activation  */
  379.     BOOLGADGET|REQGADGET,    /* type        */
  380.     NULL,                    /* rendering   */
  381.     NULL,                    /* rendering   */
  382.     NULL,            /* text        */
  383.     0,                       /* mutual exlcude */
  384.     NULL,                    /* string info */
  385.     FILE4GADGET,             /* gadget id   */
  386.     (APTR)&PickNames[4][0]         /* special info*/
  387.     },
  388.     { /* File name selection 5 */
  389.     &FileListGadget[6],      /* next gadget */
  390.     5,64,                    /* location    */
  391.     244,8,
  392.     GADGHCOMP,               /* flags       */
  393.     GADGIMMEDIATE,           /* activation  */
  394.     BOOLGADGET|REQGADGET,    /* type        */
  395.     NULL,                    /* rendering   */
  396.     NULL,                    /* rendering   */
  397.     NULL,            /* text        */
  398.     0,                       /* mutual exlcude */
  399.     NULL,                    /* string info */
  400.     FILE5GADGET,             /* gadget id   */
  401.     (APTR)&PickNames[5][0]         /* special info*/
  402.     },
  403.     { /* File name selection 6 */
  404.     &FileListGadget[7],      /* next gadget */
  405.     5,74,                    /* location    */
  406.     244,8,
  407.     GADGHCOMP,               /* flags       */
  408.     GADGIMMEDIATE,           /* activation  */
  409.     BOOLGADGET|REQGADGET,    /* type        */
  410.     NULL,                    /* rendering   */
  411.     NULL,                    /* rendering   */
  412.     NULL,            /* text        */
  413.     0,                       /* mutual exlcude */
  414.     NULL,                    /* string info */
  415.     FILE6GADGET,             /* gadget id   */
  416.     (APTR)&PickNames[6][0]         /* special info*/
  417.     },
  418.     { /* File name selection 7 */
  419.     &DrawerGadget,           /* next gadget */
  420.     5,84,                    /* location    */
  421.     244,8,
  422.     GADGHCOMP,               /* flags       */
  423.     GADGIMMEDIATE,           /* activation  */
  424.     BOOLGADGET|REQGADGET,    /* type        */
  425.     NULL,                    /* rendering   */
  426.     NULL,                    /* rendering   */
  427.     NULL,            /* text        */
  428.     0,                       /* mutual exlcude */
  429.     NULL,                    /* string info */
  430.     FILE7GADGET,             /* gadget id   */
  431.     (APTR)&PickNames[7][0]         /* special info*/
  432.     }
  433.   };
  434.  
  435.  
  436. /**********************************************************************
  437.  *  Border Definitions for device gadgets
  438.  **********************************************************************/
  439.  
  440. SHORT device_Pairs_1[] = {
  441.   0,     0,   
  442.   34,     0,   
  443.   34,     10,   
  444.   0,     10,   
  445.   0,     0    
  446. };
  447. struct Border device_bord_1 = {
  448.   -1,  -1,       /* LeftEdge, TopEdge */
  449.   0,  1,  JAM2,  /* FrontPen, BackPen, DrawMode*/
  450.   5,             /* Count of XY pairs */  
  451.   (SHORT *)&device_Pairs_1, /* XY pairs */
  452.   NULL           /* Next Border */
  453. };
  454.  
  455.  
  456. /**********************************************************************
  457.  *  IntuiTexts for the DF0GAD gadget.
  458.  **********************************************************************/
  459.  
  460. struct IntuiText DF0GAD_Text_0 = {
  461.    0, 1,     /* FrontPen, BackPen */
  462.    JAM2,       /* DrawMode */
  463.    1, 1,     /* LeftEdge, TopEdge */
  464.    NULL, /* ITextFont Pointer */ 
  465.    /* The IText */
  466.    (UBYTE *)"DF0:",
  467.    NULL
  468.  };
  469.  
  470.  
  471.  
  472. /**********************************************************************
  473.  *  Gadget Structure definition for the DF0GAD gadget.
  474.  **********************************************************************/
  475.  
  476. struct Gadget DF0GAD = {
  477.   &FileListGadget[0],  /* NextGadget pointer */
  478.   20, 97,              /* LeftEdge, TopEdge  */
  479.   33, 9,               /* Width, Height      */
  480.          /* Gadget Flags */
  481.   GADGHCOMP,
  482.        /* Activation Flags */
  483.   GADGIMMEDIATE,
  484.           /* GadgetType */
  485.   BOOLGADGET,
  486.   (APTR)&device_bord_1,/*  GadgetRender      */
  487.   NULL,                /* SelectRender       */
  488.    &DF0GAD_Text_0,     /* GadgetText         */
  489.   0x0,                 /* MutualExclude      */
  490.   NULL,                /* SpecialInfo        */
  491.   DF0GADGET,           /* GadgetID           */
  492.   NULL                 /* UserData Pointer   */
  493. };
  494.  
  495.  
  496. /**********************************************************************
  497.  *  IntuiTexts for the DF1GAD gadget.
  498.  **********************************************************************/
  499.  
  500. struct IntuiText DF1GAD_Text_0 = {
  501.    0, 1,     /* FrontPen, BackPen */
  502.    JAM2,       /* DrawMode */
  503.    1, 1,     /* LeftEdge, TopEdge */
  504.    NULL, /* ITextFont Pointer */ 
  505.    /* The IText */
  506.    (UBYTE *)"DF1:",
  507.    NULL
  508.  };
  509.  
  510.  
  511.  
  512. /**********************************************************************
  513.  *  Gadget Structure definition for the DF1GAD gadget.
  514.  **********************************************************************/
  515.  
  516. struct Gadget DF1GAD = {
  517.   &DF0GAD,                /* NextGadget pointer */
  518.   68, 97,              /* LeftEdge, TopEdge  */
  519.   33, 9,               /* Width, Height      */
  520.          /* Gadget Flags */
  521.   GADGHCOMP,
  522.        /* Activation Flags */
  523.   GADGIMMEDIATE,
  524.           /* GadgetType */
  525.   BOOLGADGET,
  526.   (APTR)&device_bord_1,/*  GadgetRender      */
  527.   NULL,                /* SelectRender       */
  528.    &DF1GAD_Text_0,     /* GadgetText         */
  529.   0x0,                 /* MutualExclude      */
  530.   NULL,                /* SpecialInfo        */
  531.   DF1GADGET,           /* GadgetID           */
  532.   NULL                 /* UserData Pointer   */
  533. };
  534.  
  535.  
  536. /**********************************************************************
  537.  *  IntuiTexts for the DH0GAD gadget.
  538.  **********************************************************************/
  539.  
  540. struct IntuiText DH0GAD_Text_0 = {
  541.    0, 1,     /* FrontPen, BackPen */
  542.    JAM2,       /* DrawMode */
  543.    1, 1,     /* LeftEdge, TopEdge */
  544.    NULL, /* ITextFont Pointer */ 
  545.    /* The IText */
  546.    (UBYTE *)"DH0:",
  547.    NULL
  548.  };
  549.  
  550.  
  551.  
  552. /**********************************************************************
  553.  *  Gadget Structure definition for the DH0GAD gadget.
  554.  **********************************************************************/
  555.  
  556. struct Gadget DH0GAD = {
  557.   &DF1GAD,                /* NextGadget pointer */
  558.   116, 97,              /* LeftEdge, TopEdge  */
  559.   33, 9,               /* Width, Height      */
  560.          /* Gadget Flags */
  561.   GADGHCOMP,
  562.        /* Activation Flags */
  563.   GADGIMMEDIATE,
  564.           /* GadgetType */
  565.   BOOLGADGET,
  566.   (APTR)&device_bord_1,/*  GadgetRender      */
  567.   NULL,                /* SelectRender       */
  568.    &DH0GAD_Text_0,     /* GadgetText         */
  569.   0x0,                 /* MutualExclude      */
  570.   NULL,                /* SpecialInfo        */
  571.   DH0GADGET,           /* GadgetID           */
  572.   NULL                 /* UserData Pointer   */
  573. };
  574.  
  575.  
  576.  
  577. /**********************************************************************
  578.  *  IntuiTexts for the VD0GAD gadget.
  579.  **********************************************************************/
  580.  
  581. struct IntuiText VD0GAD_Text_0 = {
  582.    0, 1,     /* FrontPen, BackPen */
  583.    JAM2,       /* DrawMode */
  584.    1, 1,     /* LeftEdge, TopEdge */
  585.    NULL, /* ITextFont Pointer */ 
  586.    /* The IText */
  587.    (UBYTE *)"VD0:",
  588.    NULL
  589.  };
  590.  
  591.  
  592.  
  593. /**********************************************************************
  594.  *  Gadget Structure definition for the VD0GAD gadget.
  595.  **********************************************************************/
  596.  
  597. struct Gadget VD0GAD = {
  598.   &DH0GAD,                /* NextGadget pointer */
  599.   164, 97,              /* LeftEdge, TopEdge  */
  600.   33, 9,               /* Width, Height      */
  601.          /* Gadget Flags */
  602.   GADGHCOMP,
  603.        /* Activation Flags */
  604.   GADGIMMEDIATE,
  605.           /* GadgetType */
  606.   BOOLGADGET,
  607.   (APTR)&device_bord_1,/*  GadgetRender      */
  608.   NULL,                /* SelectRender       */
  609.    &VD0GAD_Text_0,     /* GadgetText         */
  610.   0x0,                 /* MutualExclude      */
  611.   NULL,                /* SpecialInfo        */
  612.   VD0GADGET,           /* GadgetID           */
  613.   NULL                 /* UserData Pointer   */
  614. };
  615.  
  616.  
  617.  
  618. /**********************************************************************
  619.  *  IntuiTexts for the RAMGAD gadget.
  620.  **********************************************************************/
  621.  
  622. struct IntuiText RAMGAD_Text_0 = {
  623.    0, 1,     /* FrontPen, BackPen */
  624.    JAM2,       /* DrawMode */
  625.    1, 1,     /* LeftEdge, TopEdge */
  626.    NULL, /* ITextFont Pointer */ 
  627.    /* The IText */
  628.    (UBYTE *)"RAM:",
  629.    NULL
  630.  };
  631.  
  632.  
  633.  
  634. /**********************************************************************
  635.  *  Gadget Structure definition for the RAMGAD gadget.
  636.  **********************************************************************/
  637.  
  638. struct Gadget RAMGAD = {
  639.   &VD0GAD,                /* NextGadget pointer */
  640.   212, 97,              /* LeftEdge, TopEdge  */
  641.   33, 9,               /* Width, Height      */
  642.          /* Gadget Flags */
  643.   GADGHCOMP,
  644.        /* Activation Flags */
  645.   GADGIMMEDIATE,
  646.           /* GadgetType */
  647.   BOOLGADGET,
  648.   (APTR)&device_bord_1,/*  GadgetRender      */
  649.   NULL,                /* SelectRender       */
  650.    &RAMGAD_Text_0,     /* GadgetText         */
  651.   0x0,                 /* MutualExclude      */
  652.   NULL,                /* SpecialInfo        */
  653.   RAMGADGET,           /* GadgetID           */
  654.   NULL                 /* UserData Pointer   */
  655. };
  656.  
  657. /**********************************************************************
  658.  *  Border Definitions for Parent gadget
  659.  **********************************************************************/
  660.  
  661. SHORT PARENT_Pairs_1[] = {
  662.   0,     0,   
  663.   68,     0,   
  664.   68,     10,   
  665.   0,     10,   
  666.   0,     0    
  667. };
  668. struct Border PARENT_bord_1 = {
  669.   -1,  -1,       /* LeftEdge, TopEdge */
  670.   0,  1,  JAM2,  /* FrontPen, BackPen, DrawMode*/
  671.   5,             /* Count of XY pairs */  
  672.   (SHORT *)&PARENT_Pairs_1, /* XY pairs */
  673.   NULL           /* Next Border */
  674. };
  675.  
  676.  
  677. /**********************************************************************
  678.  *  IntuiTexts for the PARENTGAD gadget.
  679.  **********************************************************************/
  680.  
  681. struct IntuiText PARENTGAD_Text_0 = {
  682.    0, 1,     /* FrontPen, BackPen */
  683.    JAM2,       /* DrawMode */
  684.    1, 1,     /* LeftEdge, TopEdge */
  685.    NULL, /* ITextFont Pointer */ 
  686.    /* The IText */
  687.    (UBYTE *)" PARENT ",
  688.    NULL
  689.  };
  690.  
  691.  
  692.  
  693. /**********************************************************************
  694.  *  Gadget Structure definition for the PARENTGAD gadget.
  695.  **********************************************************************/
  696.  
  697. struct Gadget PARENTGAD = {
  698.   &RAMGAD,  /* NextGadget pointer */
  699.   100, 110,              /* LeftEdge, TopEdge  */
  700.   67, 9,               /* Width, Height      */
  701.          /* Gadget Flags */
  702.   GADGHCOMP,
  703.        /* Activation Flags */
  704.   GADGIMMEDIATE,
  705.           /* GadgetType */
  706.   BOOLGADGET,
  707.   (APTR)&PARENT_bord_1,/*  GadgetRender      */
  708.   NULL,                /* SelectRender       */
  709.    &PARENTGAD_Text_0,     /* GadgetText         */
  710.   0x0,                 /* MutualExclude      */
  711.   NULL,                /* SpecialInfo        */
  712.   PARENTGADGET,           /* GadgetID           */
  713.   NULL                 /* UserData Pointer   */
  714. };
  715.  
  716.  
  717.  
  718. /********************************
  719.  * The Load FRQButton gadget stuff *
  720.  *******************************/
  721. SHORT FRQButtonPoints1[] =
  722.   {
  723.   -4, -4,
  724.   66, -4,
  725.   66, 12,
  726.   -4, 12,
  727.   -4, -4
  728.   };
  729. struct Border FRQButtonBorder1 =
  730.   {
  731.   0,0,
  732.   2,1,JAM1,
  733.   5,
  734.   &FRQButtonPoints1[0],
  735.   NULL
  736.   };
  737. SHORT FRQButtonPoints0[] =
  738.   {
  739.   -3, -2,
  740.   65, -2,
  741.   65, 10,
  742.   -3, 10,
  743.   -3, -2
  744.   };
  745. struct Border FRQButtonBorder0 =
  746.   {
  747.   0,0,
  748.   0,1,JAM1,
  749.   5,
  750.   &FRQButtonPoints0[0],
  751.   &FRQButtonBorder1
  752.   };
  753.  
  754. struct IntuiText FRQLoadText =
  755.   {
  756.   0,1, JAM2,              /* frontpen, packpen, drawmode */
  757.   0,0,                    /* left,top */
  758.   NULL,                   /* font */
  759.   NULL,                   /* text */
  760.   NULL                    /* next */
  761.   };
  762.  
  763. struct Gadget FRQLoadGadget =
  764.   { /* FRQLoad FRQButton */
  765.   &PARENTGAD,      /* next gadget */
  766.   14,156,                  /* location    */
  767.   64,8,
  768.   GADGHCOMP,               /* flags       */
  769.   GADGIMMEDIATE|ENDGADGET, /* activation  */
  770.   BOOLGADGET|REQGADGET,    /* type        */
  771.   (APTR) &FRQButtonBorder0,   /* rendering   */
  772.   NULL,                    /* rendering   */
  773.   &FRQLoadText,               /* text        */
  774.   0,                       /* mutual exlcude */
  775.   NULL,                    /* string info */
  776.   LOADGADGET,              /* gadget id   */
  777.   NULL                     /* special info*/
  778.   };
  779.  
  780. /**********************************
  781.  * The Cancel FRQButton gadget stuff *
  782.  *********************************/
  783. struct IntuiText FRQCancelText =
  784.   {
  785.   0,1, JAM2,              /* frontpen, packpen, drawmode */
  786.   0,0,                    /* left,top */
  787.   NULL,                   /* font */
  788.   (UBYTE *)"Cancel",               /* text */
  789.   NULL                    /* next */
  790.   };
  791.  
  792. struct Gadget FRQCancelGadget =
  793.   { /* Cancel FRQButton */
  794.   &FRQLoadGadget,             /* next gadget */
  795.   187,156,                 /* location    */
  796.   64,8,
  797.   GADGHCOMP,               /* flags       */
  798.   GADGIMMEDIATE|ENDGADGET, /* activation  */
  799.   BOOLGADGET|REQGADGET,    /* type        */
  800.   (APTR) &FRQButtonBorder0,   /* rendering   */
  801.   NULL,                    /* rendering   */
  802.   &FRQCancelText,             /* text        */
  803.   0,                       /* mutual exlcude */
  804.   NULL,                    /* string info */
  805.   CANCELGADGET,            /* gadget id   */
  806.   NULL                     /* special info*/
  807.   };
  808.  
  809. /***************************************************
  810.  * The Scroll Selection List up (STD arrow) gadget *
  811.  ***************************************************/
  812. extern struct Image UpArrow;
  813. struct Gadget FRQUpGadget =
  814.   { /* Up a file gadget */
  815.   &FRQCancelGadget,           /* next gadget */
  816.   247,13,                     /* location    */
  817.   12,15,
  818.   GADGIMAGE|GADGHNONE,        /* flags       */
  819.   GADGIMMEDIATE | RELVERIFY,  /* activation  */
  820.   BOOLGADGET|REQGADGET,       /* type        */
  821.   (APTR) &UpArrow,            /* rendering   */
  822.   NULL,                       /* rendering   */
  823.   NULL,                       /* text        */
  824.   0,                          /* mutual exlcude */
  825.   NULL,                       /* string info */
  826.   UPGADGET,                   /* gadget id   */
  827.   NULL                        /* special info*/
  828.   };
  829. /*************************************************
  830.  * The Scroll Selection List down (arrow) gadget *
  831.  ************************************************/
  832. extern struct Image DownArrow;
  833. struct Gadget FRQDownGadget =
  834.   { /* Down a file gadget */
  835.   &FRQUpGadget,               /* next gadget */
  836.   247,79,                     /* location    */
  837.   12,15,
  838.   GADGIMAGE|GADGHNONE,        /* flags       */
  839.   GADGIMMEDIATE | RELVERIFY,  /* activation  */
  840.   BOOLGADGET|REQGADGET,       /* type        */
  841.   (APTR) &DownArrow,          /* rendering   */
  842.   NULL,                       /* rendering   */
  843.   NULL,                       /* text        */
  844.   0,                          /* mutual exlcude */
  845.   NULL,                       /* string info */
  846.   DOWNGADGET,                 /* gadget id   */
  847.   NULL                        /* special info*/
  848.   };
  849.  
  850. /***************************************************
  851.  * The Scroll Selection list up down Potentiometer *
  852.  **************************************************/
  853. struct PropInfo FRQKnobInfo =
  854.   {
  855.   AUTOKNOB | FREEVERT | PROPBORDERLESS,
  856.   0,
  857.   0, /* VertPot */
  858.   0,
  859.   0x7fff, /* VertBody */
  860.   0,0,0,0,0,0
  861.   };
  862.  
  863. struct Image FRQKnobImage =
  864.   {
  865.   0,0,
  866.   0,0,0,
  867.   NULL,
  868.   0,0,
  869.   NULL
  870.   };
  871.  
  872. struct Gadget FRQPotGadget =
  873.   { /* Potentiometer file gadget */
  874.   &FRQDownGadget,             /* next gadget */
  875.   247,28,                     /* location    */
  876.   14,50,
  877.   GADGHNONE,                  /* flags       */
  878.   GADGIMMEDIATE | RELVERIFY,  /* activation  */
  879.   PROPGADGET|REQGADGET,       /* type        */
  880.   (APTR) &FRQKnobImage,       /* rendering   */
  881.   NULL,                       /* rendering   */
  882.   NULL,                       /* text        */
  883.   0,                          /* mutual exlcude */
  884.   (APTR)&FRQKnobInfo,         /* string info */
  885.   POTGADGET,                  /* gadget id   */
  886.   NULL                        /* special info*/
  887.   };
  888. /***************************************************************************
  889. *                  Other Requester structures                              *
  890. ***************************************************************************/
  891. struct IntuiText FRQHeadingText =
  892.   {
  893.   2,1, JAM2,              /* frontpen, packpen, drawmode */
  894.   4,3,                    /* left,top */
  895.   NULL,                   /* font */
  896.   NULL,                   /* text */
  897.   NULL                    /* next */
  898.   };
  899.  
  900. SHORT FRQ0Points[] = {
  901.   2,1,
  902.   261,1,
  903.   261,172,
  904.   2,172,
  905.   2,1
  906.   };
  907. struct Border FRQ0Border = {
  908.   0,0,
  909.   0,1,JAM1,
  910.   5,
  911.   &FRQ0Points[0],
  912.   NULL
  913.   };
  914.  
  915. SHORT FRQ1Points[] = {
  916.   2,12,
  917.   261,12
  918.   };
  919. struct Border FRQ1Border = {
  920.   0,0,
  921.   0,1,JAM1,
  922.   2,
  923.   &FRQ1Points[0],
  924.   &FRQ0Border
  925.   };
  926.  
  927. SHORT FRQ2Points[] = {
  928.   2,93,
  929.   261,93
  930.   };
  931. struct Border FRQ2Border = {
  932.   0,0,
  933.   0,1,JAM1,
  934.   2,
  935.   &FRQ2Points[0],
  936.   &FRQ1Border
  937.   };
  938.  
  939. SHORT FRQ3Points[] = {
  940.   246,12,
  941.   246,93,
  942.   246,78,
  943.   261,78,
  944.   261,27,
  945.   247,27
  946.   };
  947. struct Border FRQ3Border = {
  948.   0,0,
  949.   0,1,JAM1,
  950.   6,
  951.   &FRQ3Points[0],
  952.   &FRQ2Border
  953.   };
  954.  
  955. /****************************************************************************
  956.  *                     The Code part of the requester
  957.  ***************************************************************************/
  958. BOOL FileRequest(FileType,Action,FullName,Exclude,Limit,ReqWindow)
  959.   UBYTE *FileType;
  960.   UBYTE *Action;
  961.   UBYTE *FullName;
  962.   UBYTE *Exclude; 
  963.   UBYTE *Limit;
  964.   struct Window *ReqWindow;
  965. {
  966.   UBYTE *StrPtr;
  967.   BOOL   RetCode;
  968.   APTR  AllocMem(); /* have to use memory allocation for FileInfoBlocks */
  969.  
  970.   window = ReqWindow;           /* make pointer to window and name global */
  971.   FullPath = FullName;          /* buffer for returned filename           */
  972.   ExcludeExt = Exclude;         /* exclude files with this extension from */
  973.                                 /* display. eg ".info"                    */
  974.   LimitExt = Limit;             /* Limit display to files with this ext.  */
  975.   
  976.   FRQHeadingText.IText = FileType; /* Center requester title */
  977.   FRQHeadingText.LeftEdge = (256-IntuiTextLength(&FRQHeadingText))/2;
  978.   FRQLoadText.IText = Action;
  979.  
  980.   FileInfo = (struct FileInfoBlock *)
  981.                AllocMem((LONG)sizeof(struct FileInfoBlock),MEMF_PUBLIC);
  982.  
  983.   InitFNR();
  984.  
  985.   /* if the fullname is a NULL string, get the user's current directory */
  986.  
  987.   if (FullName[0] == '\0') 
  988.     {
  989.      GetPath(FullName);
  990.      *FileString.Buffer = '\0';
  991.      strcpy(DrawerString.Buffer,FullName);
  992.     }
  993.   else
  994.     {
  995.      /* Separate the path from the file name. Set the file name in the gadget */
  996.      if (StrPtr = rindex(FullName,'/'))
  997.        {
  998.        strcpy(FileString.Buffer,StrPtr + 1);
  999.        *StrPtr = '\0';
  1000.        }
  1001.      else
  1002.        if (StrPtr = rindex(FullName,':'))
  1003.          {
  1004.          strcpy(FileString.Buffer,StrPtr + 1);
  1005.          *(StrPtr+1) = '\0';
  1006.          }
  1007.        else
  1008.          {
  1009.          *FileString.Buffer   = '\0';
  1010.          *DrawerString.Buffer = '\0';
  1011.          *FullName = '\0';
  1012.          }
  1013.       strcpy(DrawerString.Buffer,FullName);
  1014.      }
  1015.   /* Put up the requester and list the dir into it */ 
  1016.   Request(&FileRequester,window);
  1017.   FileReqRP = FileRequester.ReqLayer->rp; /* the requester's rastport */
  1018.   ListDir(FullName);
  1019.   SetNewFile(&FileGadget,FileString.Buffer); /* why do I have to do this? */
  1020.   SetNewFile(&DrawerGadget,DrawerString.Buffer);
  1021.  
  1022.   RetCode = WaitRequester();         /* do everything till Cancel or Load */
  1023.   
  1024.   FreeMem(FileInfo,(LONG)sizeof(struct FileInfoBlock));
  1025.   
  1026.   /* Put file name and path back together */
  1027.   if (FullName[strlen(FullName)-1] != ':')
  1028.     strcat(FullName,"/");
  1029.   strcat(FullName,FileString.Buffer);
  1030.   return(RetCode);
  1031. } /* LoadRequest */
  1032.  
  1033. /*
  1034.  *  Init the file name requester
  1035.  */
  1036. InitFNR()
  1037. {
  1038.   InitRequester(&FileRequester);
  1039.   FileRequester.Width     = 264;
  1040.   FileRequester.Height    = 174;
  1041.   FileRequester.LeftEdge  = 20;
  1042.   FileRequester.TopEdge   = 12;
  1043.   FileRequester.ReqGadget = &FRQPotGadget;
  1044.   FileRequester.ReqText   = &FRQHeadingText;
  1045.   FileRequester.BackFill  = 1;
  1046.   FileRequester.Flags     = 0;
  1047.   FileRequester.ReqBorder = &FRQ3Border;
  1048. } /* InitFNR */
  1049.  
  1050. /*
  1051.  *  WaitRequester - List dirs, scroll, and set drawer and file strings until
  1052.  *                  one of the LOAD(SAVE) or CANCEL buttons pushed.
  1053.  */
  1054. BOOL WaitRequester()
  1055. {
  1056.   ULONG  class = GADGETDOWN;
  1057.   USHORT choice = CANCELGADGET;
  1058.   struct Gadget *gadget;
  1059.   UBYTE *lastslash;
  1060.   ULONG saveflags;
  1061.   SHORT pauseticks;
  1062.   BOOL watchpot, watchticks, upmove, downmove;
  1063.   
  1064.   saveflags = window->IDCMPFlags;
  1065.     
  1066.   ModifyIDCMP(window, GADGETUP | GADGETDOWN | REQCLEAR | INTUITICKS | MOUSEMOVE);
  1067.  
  1068.   watchpot = upmove = downmove = watchticks = FALSE;
  1069.  
  1070.   while (class != REQCLEAR)
  1071.     {
  1072.     if ((message=GetMsg(window->UserPort)) == 0L)
  1073.       { 
  1074.        Wait(1L<<window->UserPort->mp_SigBit);
  1075.        continue;
  1076.       }
  1077.     class  = message->Class;
  1078.     gadget = (struct Gadget *) message->IAddress;
  1079.     ReplyMsg(message);
  1080.     switch (class)
  1081.       {
  1082.       case GADGETDOWN:
  1083.            switch (gadget->GadgetID >> CLASSBITS)
  1084.              {
  1085.              case UPDOWNCLASS:
  1086.                   switch(choice = (gadget->GadgetID & GADGETNUM))
  1087.                      { 
  1088.                        case UP:   upmove = TRUE; 
  1089.                                   break;
  1090.                        case DOWN: downmove = TRUE; 
  1091.                                   break;
  1092.                        case POT : watchpot = TRUE; 
  1093.                                   break;
  1094.                      }
  1095.                   if (upmove || downmove)
  1096.                      { watchticks = TRUE;
  1097.                        pauseticks = 2;
  1098.                        ScrollFileList(gadget,choice);      /* scroll up/down 1 file */
  1099.                      }
  1100.                   break;
  1101.                   
  1102.              case CHOICECLASS:             /* set the name in string gads */
  1103.                   if (IsDir(gadget->UserData))
  1104.                     SetNewDrawer(&DrawerGadget,gadget->UserData);
  1105.                   else
  1106.                     SetNewFile(&FileGadget,gadget->UserData);
  1107.                   break;
  1108.              case BUTTONCLASS:             /* LOAD or CANCEL */
  1109.                   choice = gadget->GadgetID & GADGETNUM;
  1110.           if (choice < 2) break; /* load or cancel */
  1111.                   switch (choice)
  1112.                     {
  1113.                     case TODF0:
  1114.                          strcpy(FullPath,"DF0:");
  1115.                          strcpy(DrawerString.Buffer,FullPath);
  1116.                          break;
  1117.  
  1118.                     case TODF1:
  1119.                          strcpy(FullPath,"DF1:");
  1120.                          strcpy(DrawerString.Buffer,FullPath);
  1121.                          break;
  1122.  
  1123.                     case TODH0:
  1124.                          strcpy(FullPath,"DH0:");
  1125.                          strcpy(DrawerString.Buffer,FullPath);
  1126.                          break;
  1127.  
  1128.                     case TOVD0:
  1129.                          strcpy(FullPath,"VD0:");
  1130.                          strcpy(DrawerString.Buffer,FullPath);
  1131.                          break;
  1132.  
  1133.                     case TORAM:
  1134.                          strcpy(FullPath,"RAM:");
  1135.                          strcpy(DrawerString.Buffer,FullPath);
  1136.                          break;
  1137.  
  1138.                     case PARENT:
  1139.                          if (FullPath[strlen(FullPath)-1] == ':') break;
  1140.                          lastslash = rindex(FullPath,'/');
  1141.                  if (lastslash == NULL) 
  1142.                    { lastslash = rindex(FullPath,':');
  1143.                  if (lastslash == NULL) break;
  1144.                      lastslash++;
  1145.                            }
  1146.                          *lastslash = '\0';
  1147.                          strcpy(DrawerString.Buffer,FullPath);
  1148.                          break;
  1149.  
  1150.                     }
  1151.                    SetNewFile(&FileGadget,"");
  1152.                    ListDir(DrawerString.Buffer);
  1153.  
  1154.              }
  1155.              break;
  1156.  
  1157.       case GADGETUP:
  1158.            switch (gadget->GadgetID >> CLASSBITS)
  1159.              {
  1160.              case UPDOWNCLASS:             /* Potentiometer scroll */
  1161.                   switch(choice = (gadget->GadgetID & GADGETNUM))
  1162.                      { 
  1163.                        case UP: 
  1164.                               watchticks = FALSE; 
  1165.                               upmove = FALSE;
  1166.                             break;
  1167.  
  1168.                        case DOWN: 
  1169.                                watchticks = FALSE; 
  1170.                                downmove = FALSE;
  1171.                             break;
  1172.  
  1173.                        case POT : 
  1174.                                watchpot = FALSE;
  1175.                             break;
  1176.                      }
  1177.                   if (choice == POT)
  1178.                   PotScrollFileList();
  1179.                   break;
  1180.  
  1181.              case STRINGCLASS:             /* They typed drawer name in */
  1182.                   ThrowTrailing(DrawerString.Buffer);
  1183.                   strcpy(FullPath,DrawerString.Buffer);
  1184.                   SetNewFile(&FileGadget,"");
  1185.                   ListDir(DrawerString.Buffer);
  1186.              }
  1187.              break;
  1188.  
  1189.       case INTUITICKS:
  1190.              /* wait for pauseticks before starting scrolling */
  1191.              if (watchticks) pauseticks--;
  1192.              if (pauseticks == 0) watchticks = FALSE;
  1193.              else break;
  1194.              /* when pauseticks is zero move up or down */
  1195.              if (upmove) ScrollFileList(NULL,UP);      /* scroll up 1 file */
  1196.              if (downmove) ScrollFileList(NULL,DOWN);  /* scroll down 1 file */
  1197.            break;
  1198.  
  1199.       case MOUSEMOVE: 
  1200.              if (watchpot) PotScrollFileList();
  1201.  
  1202.            break;
  1203.       }
  1204.     }
  1205.   /* restore the user's IDCMP flags */ 
  1206.   ModifyIDCMP(window, saveflags);
  1207.   /* Return whether the load or cancel was selected */
  1208.   return(choice==LOAD);
  1209. } /* WaitRequester */
  1210.  
  1211. /*
  1212.  *  SetNewDrawer - Used Mouse to pick directory from selection list gadgets.
  1213.  */ 
  1214. SetNewDrawer(Gadget,Text)
  1215.   struct Gadget *Gadget;
  1216.   UBYTE  *Text;
  1217. {
  1218.   SetNewFile(&FileGadget,"");              /* clear file name string */
  1219.   if (FullPath[strlen(FullPath)-1] != ':') /* make new path */
  1220.     strncat(FullPath,"/",PATHNAMELEN);
  1221.   strncat(FullPath,Text,PATHNAMELEN);
  1222.   SetNewFile(Gadget,FullPath);             /* set new drawer into gadget */
  1223.   ListDir(FullPath);                       /* List new files into Sel List */
  1224. } /* SetNewDrawer */
  1225.  
  1226. /*
  1227.  *  SetNewFile - jams a new filename into the string gadget buffer.
  1228.  *               to be really safe we should remove gadgets,
  1229.  *               change strings and add them again, but this seems to work.
  1230.  *  
  1231.  */
  1232. SetNewFile(Gadget,Text)
  1233.   struct Gadget *Gadget;
  1234.   UBYTE  *Text;
  1235. {
  1236.   USHORT Pos, RemoveGadget();
  1237.   struct StringInfo *si;
  1238.   if (Text[0] != ' ')
  1239.     {
  1240.     ThrowTrailing(Text);                    /* get rid of trailing blanks */
  1241.     si = (struct StringInfo *)Gadget->SpecialInfo;
  1242.     strcpy(si->Buffer,Text);
  1243.     RefreshGList(&DrawerGadget,window,&FileRequester,2L);
  1244.     }
  1245. } /* SetNewFile */
  1246.  
  1247. /*
  1248.  *  ListDir - List the directory into array of string names.
  1249.  */
  1250. ListDir(dir)
  1251.   char *dir;
  1252. {
  1253.   struct FileLock *my_lock, *Lock() ;
  1254.   int sortcompare();
  1255.   UBYTE *ext;
  1256.   BOOL OKtoAdd, limitmatch, excludematch;
  1257.   LONG IoErr();
  1258.   
  1259.   FileCount = 0;
  1260.   FirstFile = 0;
  1261.  
  1262.   if ((my_lock = Lock(dir, ACCESS_READ)) != NULL)
  1263.     {
  1264.     if (Examine(my_lock, FileInfo))
  1265.       { 
  1266.       while ( ExNext(my_lock, FileInfo) && FileCount < MAXFILES)
  1267.         {  
  1268.         if (FileInfo->fib_DirEntryType > 0) /* alway add directories */
  1269.            {
  1270.             strcpy(&FileListEntry[FileCount][0]," (dir) ");
  1271.             strcat(&FileListEntry[FileCount][0], FileInfo->fib_FileName);
  1272.             FileCount++;
  1273.            }
  1274.         else /* not a directory */
  1275.            { 
  1276.              OKtoAdd = TRUE;
  1277.              limitmatch = FALSE;
  1278.              excludematch = FALSE;
  1279.              if (LimitExt || ExcludeExt)  /* do we have limit or exclude parms?*/
  1280.                { 
  1281.                  ext = rindex(FileInfo->fib_FileName,'.');
  1282.          if (LimitExt) OKtoAdd = FALSE;
  1283.                  if (ext && (strcmp(ext,LimitExt) == 0)) /* matches limit */
  1284.                     limitmatch = TRUE;
  1285.                  if (ext && (strcmp(ext,ExcludeExt) == 0)) /* matches exclude*/
  1286.                     excludematch = TRUE;
  1287.                     
  1288.                 }
  1289.              if ((OKtoAdd || limitmatch ) && !excludematch)
  1290.                 {
  1291.                  strcpy(&FileListEntry[FileCount][0], FileInfo->fib_FileName);
  1292.                  FileCount++;
  1293.                 }
  1294.             } /* end of normal file processing (else) */
  1295.         } /* end of exnext while loop */
  1296.       UnLock(my_lock) ;
  1297.       }
  1298.     }
  1299.  
  1300.   /* sort the files */
  1301.   qsort(FileListEntry,FileCount,40,sortcompare);
  1302.   AttachFileList(FirstFile);
  1303.   if (FileCount > 8)
  1304.     NewModifyProp(&FRQPotGadget,window,&FileRequester,
  1305.                   AUTOKNOB|FREEVERT|PROPBORDERLESS,
  1306.                   0L,0L,0L,(LONG)(0xffff/(FileCount-6)*8),1L);
  1307.   else
  1308.     ModifyProp(&FRQPotGadget,window,&FileRequester,
  1309.                AUTOKNOB|FREEVERT|PROPBORDERLESS,
  1310.                 0L,0L,0L,(LONG)0xffff,1L);
  1311. } /* ListDir */
  1312.  
  1313. /**********************************************
  1314.   Comparsion routine for Manx builtin qsort
  1315. ***********************************************/
  1316. sortcompare(a,b)
  1317. char *a,*b;
  1318. {   
  1319.     return(strcmp(a,b));
  1320. }
  1321.  
  1322. /*
  1323.  *  AttachFileList - Attach list of file (directory) names to Selection gadgets
  1324.  */
  1325. AttachFileList(Start)
  1326.   USHORT Start;
  1327. {
  1328.   USHORT Gadget;
  1329.   USHORT Pos;
  1330.  
  1331.   for (Gadget = 0; Gadget <= 7 && Gadget+Start < FileCount; Gadget++)
  1332.     {
  1333.     strcpy(FileList[Gadget].IText,&FileListEntry[Start + Gadget][0]);
  1334.     strncat(FileList[Gadget].IText,"                                ",24-strlen(FileList[Gadget].IText));
  1335.     FileList[Gadget].IText[24] = '\0';
  1336.     }
  1337.   for (; Gadget <= 7; Gadget++)
  1338.     {
  1339.     strncpy(FileList[Gadget].IText,"                                ",24);
  1340.     FileList[Gadget].IText[24] = '\0';
  1341.     }
  1342.   PrintIText(FileReqRP,&FileList[0],0L,0L);
  1343.   /*RefreshGList(&FRQDownGadget,window,&FileRequester,1L);*/
  1344. } /* AttachFileList */
  1345.  
  1346. /*
  1347.  *  ScrollFileList - Scroll the list up or down 1 file if possible
  1348.  */
  1349. ScrollFileList(gadget,direction)
  1350.   struct Gadget *gadget;
  1351.   USHORT direction;
  1352. {
  1353.   ULONG VertPot = 0;
  1354.   
  1355.   if (gadget != NULL) direction = gadget->GadgetID & GADGETNUM;
  1356.  
  1357.   switch(direction)
  1358.     {
  1359.     case DOWN:
  1360.          if (FileCount > FirstFile + 8)
  1361.            ++FirstFile;
  1362.          break;
  1363.     case UP:
  1364.          if (FirstFile > 0)
  1365.            --FirstFile;
  1366.     }
  1367.   if (FileCount > 8)
  1368.     VertPot  = 0xffff/(FileCount-6)*FirstFile;
  1369.   ModifyProp(&FRQPotGadget,window,&FileRequester,
  1370.              AUTOKNOB|FREEVERT|PROPBORDERLESS,
  1371.              0L,(LONG)VertPot,0L,(LONG)FRQKnobInfo.VertBody,1L);
  1372.   AttachFileList(FirstFile);
  1373. } /* ScrollFileList */
  1374.  
  1375. /*
  1376.  *  PotScrollFileList - Calculate the file number from Pot value and attach
  1377.  *                  names to Selector List gadgets.
  1378.  */
  1379. PotScrollFileList()
  1380.   USHORT tempfile;
  1381.  
  1382.          tempfile = (USHORT)((LONG)(FileCount-6)*(LONG)FRQKnobInfo.VertPot >> 16);
  1383.          
  1384.          if (tempfile == FirstFile) return;
  1385.          FirstFile = tempfile;
  1386.          AttachFileList(FirstFile);
  1387.  
  1388. } /* PotScrollFileList */
  1389.  
  1390. /*
  1391.  *  IsDir - Simple minded routine to find " (dir)" in file name 
  1392.  */
  1393. BOOL IsDir(Name)
  1394.   UBYTE *Name;
  1395. {
  1396.   UBYTE *Dir;
  1397.   
  1398.   if (strncmp(Name," (dir) ",7) == 0)
  1399.       {
  1400.       Dir = Name + 7;
  1401.       strcpy(Name,Dir);
  1402.       ThrowTrailing(Name);
  1403.       return(TRUE);
  1404.       }
  1405.     else
  1406.       return(FALSE);
  1407. } /* IsDir */
  1408.  
  1409. /*
  1410.  *  ThrowTrailing - Remove trailing blanks from string
  1411.  */
  1412. ThrowTrailing(String)
  1413.   UBYTE *String;
  1414. {
  1415.   SHORT I;
  1416.  
  1417.   I = strlen(String) - 1;
  1418.   while (String[I] == ' ' && I > 0)
  1419.     String[I--] = '\0';
  1420. } /* ThrowTrailing */
  1421.  
  1422.  
  1423.  
  1424. /* 
  1425.  *  GetPath - retrieve the full path name for a file or directory
  1426.  */
  1427. struct Remember *RemBase; /* global root for allocated list */
  1428.  
  1429.  
  1430. GetPath(Path)
  1431. UBYTE *Path;
  1432. {
  1433.    struct FileLock *FirstDir, *Parent, *release, *Lock(), *ParentDir();
  1434.    struct FileInfoBlock *FBlock;
  1435.    APTR AllocRemember();
  1436.    
  1437.    RemBase = NULL;
  1438.  
  1439.    FirstDir = Lock("",ACCESS_READ);
  1440.    release = NULL;
  1441.  
  1442.    FBlock = (struct FileInfoBlock *) AllocRemember(&RemBase,
  1443.              (LONG)sizeof(struct FileInfoBlock), MEMF_PUBLIC);
  1444.    Examine(FirstDir,FBlock);
  1445.    Parent = ParentDir(FirstDir);
  1446.  
  1447.    while (Parent != NULL)
  1448.       {
  1449.         FBlock = (struct FileInfoBlock *) AllocRemember(&RemBase,
  1450.              (LONG)sizeof(struct FileInfoBlock), MEMF_PUBLIC);
  1451.         Examine(Parent,FBlock);
  1452.         release = Parent;
  1453.         Parent = ParentDir(release);
  1454.         UnLock(release);
  1455.        }
  1456.       
  1457.    getpathname(Path); 
  1458.    FreeRemember(&RemBase,TRUE);
  1459.    UnLock(FirstDir);
  1460.  
  1461. }
  1462.  
  1463.  
  1464. /*
  1465.  *  getpathname - Scan the list built by traverse and create pathnames.
  1466.  */
  1467. getpathname(Path)
  1468. UBYTE *Path;
  1469. {
  1470.   struct Remember *p;
  1471.   struct FileInfoBlock *FBlock;
  1472.   
  1473.   p = RemBase; /* seems the first remember block is garbage */
  1474.   FBlock = (struct FileInfoBlock *)p->Memory;
  1475.   strcpy(Path,FBlock->fib_FileName);
  1476.   strcat(Path,":");
  1477.   while (p = p->NextRemember)
  1478.      {   FBlock = (struct FileInfoBlock *)p->Memory;
  1479.          strcat(Path,FBlock->fib_FileName);
  1480.          if (p->NextRemember != NULL) strcat(Path,"/");
  1481.       }
  1482. }
  1483.