home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d0xx / d034 / requester.lha / Requester / requester.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-09-03  |  26.4 KB  |  931 lines

  1. /****************************************************************************
  2.  *
  3.  *  FileRequest() - File Name Requester
  4.  *
  5.  *  By Kevin Lee Clague
  6.  *     408 Tortolla Way
  7.  *     San Jose, Ca 95033
  8.  *     408-258-9891       work 408-737-5481
  9.  *
  10.  *  Copyright (C) 1986. All rights reserved.
  11.  *
  12.  *  This program is freely distributable as long as this copyright notice
  13.  *  is retained. It intended for personal, non-commercial use.  
  14.  *
  15.  *  This file name requester is modeled after Deluxe Paints file name
  16.  *  requester. The dimensions/locations of all borders, gadgets and text were
  17.  *  arrived at empirically. Besides being a great program, Deluxe Paint is a
  18.  *  trade mark of Electronics Arts.
  19.  *
  20.  *  The knowledge on how to get at the entries in the directories was drawn
  21.  *  from Mike (I'll be melow when I'm dead) Meyer's "Browser".
  22.  *
  23.  ***************************************************************************/
  24.  
  25. /***************************************************************************
  26.  *
  27.  *  Things to do:
  28.  *    1. Dynamically allocate space for file name strings as they are gotten
  29.  *       from the disk, rather than static allocation of them in arrays.
  30.  *    2. Fence off intuition events while getting file names from disk
  31.  *       directory (and put up the zz sleepy cloud in place of the arrow
  32.  *       mouse cursor.)
  33.  *    3. Be a little more diligent with my use of RefreshGadgets.
  34.  *
  35.  ***************************************************************************/
  36.  
  37. #include "Requester.h"
  38.  
  39. BOOL IsDir();
  40. BOOL WaitRequester();
  41.  
  42. struct Requester FileRequester;
  43.  
  44. UBYTE *FullPath;
  45. struct Window       *window;
  46. struct IntuiMessage *message;
  47.  
  48. struct FileInfoBlock FileInfo;
  49. USHORT FileCount;                     /* Number of files in current dir */
  50. UBYTE  FileListEntry[MAXFILES][40];   /* File (dir) names in current dir */
  51.  
  52. USHORT FirstFile;
  53.  
  54. #define PATHNAMELEN 80
  55.  
  56. /****************************************************************************
  57.  *                The Gadget String
  58.  ***************************************************************************/
  59. /******************************
  60.  * The File Name Gadget stuff *
  61.  *****************************/
  62. struct IntuiText FileText =
  63.   {
  64.   0,1, JAM2,              /* frontpen, packpen, drawmode */
  65.   -46,0,                  /* left,top */
  66.   NULL,                   /* font */
  67.   "File:",                /* text */
  68.   NULL                    /* next */
  69.   };
  70.  
  71. UBYTE FileName[40];
  72. UBYTE Backup[40];
  73. struct StringInfo FileString = {
  74.     &FileName,               /* input buffer */
  75.     &Backup,                 /* undo  buffer */
  76.     0,                       /* Buffer position */
  77.     32,                      /* buffer size  */
  78.     0,                       /* disp position*/
  79.     0,0,0,0,0,NULL,0,NULL    /* undo position*/
  80.   };
  81.  
  82. SHORT DrawerPoints[] = {
  83.     -2, -2,
  84.     185,-2,
  85.     185,10,
  86.     -2, 10,
  87.     -2, -2
  88.     };
  89. struct Border DrawerBorder = {
  90.     0,0,
  91.     0,1,JAM1,
  92.     5,
  93.     &DrawerPoints[0],
  94.     NULL
  95.   };
  96.  
  97. struct Gadget FileGadget =
  98.   { /* File string */
  99.   NULL,                    /* next gadget */
  100.   67,113,                  /* location    */
  101.   185,8,
  102.   GADGHCOMP,               /* flags       */
  103.   0,                       /* activation  */
  104.   STRGADGET|REQGADGET,     /* type        */
  105.   (APTR) &DrawerBorder,    /* rendering   */
  106.   NULL,                    /* rendering   */
  107.   &FileText,               /* text        */
  108.   0,                       /* mutual exlcude */
  109.   &FileString,             /* string info */
  110.   NULL,                    /* gadget id   */
  111.   NULL                     /* special info*/
  112.   };
  113.  
  114. /********************************
  115.  * The Drawer Name Gadget stuff *
  116.  *******************************/
  117. struct IntuiText DrawerText = 
  118.   {
  119.   0,1, JAM2,              /* frontpen, packpen, drawmode */
  120.   -62,0,                  /* left,top */
  121.   NULL,                   /* font */
  122.   "Drawer:",              /* text */
  123.   NULL                    /* next */
  124.   };
  125.  
  126. UBYTE DrawerName[40];
  127. struct StringInfo DrawerString = {
  128.     &DrawerName,             /* input buffer */
  129.     &Backup,                 /* undo  buffer */
  130.     0,                       /* Buffer position */
  131.     32,                      /* buffer size  */
  132.     0,                       /* disp position*/
  133.     0,0,0,0,0,NULL,0,NULL    /* undo position*/
  134.   };
  135.  
  136. struct Gadget DrawerGadget =
  137.   { /* Drawer string */
  138.   &FileGadget,             /* next gadget */
  139.   67,98,                   /* location    */
  140.   185,8,
  141.   GADGHCOMP,               /* flags       */
  142.   RELVERIFY,               /* activation  */
  143.   STRGADGET|REQGADGET,     /* type        */
  144.   (APTR) &DrawerBorder,    /* rendering   */
  145.   NULL,                    /* rendering   */
  146.   &DrawerText,             /* text        */
  147.   0,                       /* mutual exlcude */
  148.   &DrawerString,           /* string info */
  149.   DRAWERGADGET,            /* gadget id   */
  150.   NULL                     /* special info*/
  151.   };
  152.  
  153. /****************************************
  154.  * The File list selection Gadget stuff *
  155.  ***************************************/
  156. UBYTE PickNames[8][40];
  157. struct IntuiText FileList[] =
  158.   {
  159.     {
  160.     0,1, JAM2,              /* frontpen, packpen, drawmode */
  161.     0,0,                    /* left,top */
  162.     NULL,                   /* font */
  163.     &PickNames[0][0],       /* text */
  164.     NULL                    /* next */
  165.     },
  166.     {
  167.     0,1, JAM2,              /* frontpen, packpen, drawmode */
  168.     0,0,                    /* left,top */
  169.     NULL,                   /* font */
  170.     &PickNames[1][0],       /* text */
  171.     NULL                    /* next */
  172.     },
  173.     {
  174.     0,1, JAM2,              /* frontpen, packpen, drawmode */
  175.     0,0,                    /* left,top */
  176.     NULL,                   /* font */
  177.     &PickNames[2][0],       /* text */
  178.     NULL                    /* next */
  179.     },
  180.     {
  181.     0,1, JAM2,              /* frontpen, packpen, drawmode */
  182.     0,0,                    /* left,top */
  183.     NULL,                   /* font */
  184.     &PickNames[3][0],       /* text */
  185.     NULL                    /* next */
  186.     },
  187.     {
  188.     0,1, JAM2,              /* frontpen, packpen, drawmode */
  189.     0,0,                    /* left,top */
  190.     NULL,                   /* font */
  191.     &PickNames[4][0],       /* text */
  192.     NULL                    /* next */
  193.     },
  194.     {
  195.     0,1, JAM2,              /* frontpen, packpen, drawmode */
  196.     0,0,                    /* left,top */
  197.     NULL,                   /* font */
  198.     &PickNames[5][0],       /* text */
  199.     NULL                    /* next */
  200.     },
  201.     {
  202.     0,1, JAM2,              /* frontpen, packpen, drawmode */
  203.     0,0,                    /* left,top */
  204.     NULL,                   /* font */
  205.     &PickNames[6][0],       /* text */
  206.     NULL                    /* next */
  207.     },
  208.     {
  209.     0,1, JAM2,              /* frontpen, packpen, drawmode */
  210.     0,0,                    /* left,top */
  211.     NULL,                   /* font */
  212.     &PickNames[7][0],       /* text */
  213.     NULL                    /* next */
  214.     }
  215.   };
  216.  
  217. struct Gadget FileListGadget[] =
  218.   {
  219.     { /* File name selection 0 */
  220.     &FileListGadget[1],      /* next gadget */
  221.     5,14,                    /* location    */
  222.     244,8,
  223.     GADGHNONE,               /* flags       */
  224.     GADGIMMEDIATE,           /* activation  */
  225.     BOOLGADGET|REQGADGET,    /* type        */
  226.     NULL,                    /* rendering   */
  227.     NULL,                    /* rendering   */
  228.     &FileList[0],            /* text        */
  229.     0,                       /* mutual exlcude */
  230.     NULL,                    /* string info */
  231.     FILE0GADGET,             /* gadget id   */
  232.     NULL                     /* special info*/
  233.     },
  234.     { /* File name selection 1 */
  235.     &FileListGadget[2],      /* next gadget */
  236.     5,24,                    /* location    */
  237.     244,8,
  238.     GADGHNONE,               /* flags       */
  239.     GADGIMMEDIATE,           /* activation  */
  240.     BOOLGADGET|REQGADGET,    /* type        */
  241.     NULL,                    /* rendering   */
  242.     NULL,                    /* rendering   */
  243.     &FileList[1],            /* text        */
  244.     0,                       /* mutual exlcude */
  245.     NULL,                    /* string info */
  246.     FILE1GADGET,             /* gadget id   */
  247.     NULL                     /* special info*/
  248.     },
  249.     { /* File name selection 2 */
  250.     &FileListGadget[3],      /* next gadget */
  251.     5,34,                    /* location    */
  252.     244,8,
  253.     GADGHNONE,               /* flags       */
  254.     GADGIMMEDIATE,           /* activation  */
  255.     BOOLGADGET|REQGADGET,    /* type        */
  256.     NULL,                    /* rendering   */
  257.     NULL,                    /* rendering   */
  258.     &FileList[2],            /* text        */
  259.     0,                       /* mutual exlcude */
  260.     NULL,                    /* string info */
  261.     FILE2GADGET,             /* gadget id   */
  262.     NULL                     /* special info*/
  263.     },
  264.     { /* File name selection 3 */
  265.     &FileListGadget[4],      /* next gadget */
  266.     5,44,                    /* location    */
  267.     244,8,
  268.     GADGHNONE,               /* flags       */
  269.     GADGIMMEDIATE,           /* activation  */
  270.     BOOLGADGET|REQGADGET,    /* type        */
  271.     NULL,                    /* rendering   */
  272.     NULL,                    /* rendering   */
  273.     &FileList[3],            /* text        */
  274.     0,                       /* mutual exlcude */
  275.     NULL,                    /* string info */
  276.     FILE3GADGET,             /* gadget id   */
  277.     NULL                     /* special info*/
  278.     },
  279.     { /* File name selection 4 */
  280.     &FileListGadget[5],      /* next gadget */
  281.     5,54,                    /* location    */
  282.     244,8,
  283.     GADGHNONE,               /* flags       */
  284.     GADGIMMEDIATE,           /* activation  */
  285.     BOOLGADGET|REQGADGET,    /* type        */
  286.     NULL,                    /* rendering   */
  287.     NULL,                    /* rendering   */
  288.     &FileList[4],            /* text        */
  289.     0,                       /* mutual exlcude */
  290.     NULL,                    /* string info */
  291.     FILE4GADGET,             /* gadget id   */
  292.     NULL                     /* special info*/
  293.     },
  294.     { /* File name selection 5 */
  295.     &FileListGadget[6],      /* next gadget */
  296.     5,64,                    /* location    */
  297.     244,8,
  298.     GADGHNONE,               /* flags       */
  299.     GADGIMMEDIATE,           /* activation  */
  300.     BOOLGADGET|REQGADGET,    /* type        */
  301.     NULL,                    /* rendering   */
  302.     NULL,                    /* rendering   */
  303.     &FileList[5],            /* text        */
  304.     0,                       /* mutual exlcude */
  305.     NULL,                    /* string info */
  306.     FILE5GADGET,             /* gadget id   */
  307.     NULL                     /* special info*/
  308.     },
  309.     { /* File name selection 6 */
  310.     &FileListGadget[7],      /* next gadget */
  311.     5,74,                    /* location    */
  312.     244,8,
  313.     GADGHNONE,               /* flags       */
  314.     GADGIMMEDIATE,           /* activation  */
  315.     BOOLGADGET|REQGADGET,    /* type        */
  316.     NULL,                    /* rendering   */
  317.     NULL,                    /* rendering   */
  318.     &FileList[6],            /* text        */
  319.     0,                       /* mutual exlcude */
  320.     NULL,                    /* string info */
  321.     FILE6GADGET,             /* gadget id   */
  322.     NULL                     /* special info*/
  323.     },
  324.     { /* File name selection 7 */
  325.     &DrawerGadget,           /* next gadget */
  326.     5,84,                    /* location    */
  327.     244,8,
  328.     GADGHNONE,               /* flags       */
  329.     GADGIMMEDIATE,           /* activation  */
  330.     BOOLGADGET|REQGADGET,    /* type        */
  331.     NULL,                    /* rendering   */
  332.     NULL,                    /* rendering   */
  333.     &FileList[7],            /* text        */
  334.     0,                       /* mutual exlcude */
  335.     NULL,                    /* string info */
  336.     FILE7GADGET,             /* gadget id   */
  337.     NULL                     /* special info*/
  338.     }
  339.   };
  340. /********************************
  341.  * The Load Button gadget stuff *
  342.  *******************************/
  343. SHORT ButtonPoints1[] =
  344.   {
  345.   -4, -4,
  346.   66, -4,
  347.   66, 12,
  348.   -4, 12,
  349.   -4, -4
  350.   };
  351. struct Border ButtonBorder1 =
  352.   {
  353.   0,0,
  354.   2,1,JAM1,
  355.   5,
  356.   &ButtonPoints1[0],
  357.   NULL
  358.   };
  359. SHORT ButtonPoints0[] =
  360.   {
  361.   -3, -2,
  362.   65, -2,
  363.   65, 10,
  364.   -3, 10,
  365.   -3, -2
  366.   };
  367. struct Border ButtonBorder0 =
  368.   {
  369.   0,0,
  370.   0,1,JAM1,
  371.   5,
  372.   &ButtonPoints0[0],
  373.   &ButtonBorder1
  374.   };
  375.  
  376. struct IntuiText LoadText =
  377.   {
  378.   0,1, JAM2,              /* frontpen, packpen, drawmode */
  379.   0,0,                    /* left,top */
  380.   NULL,                   /* font */
  381.   NULL,                   /* text */
  382.   NULL                    /* next */
  383.   };
  384.  
  385. struct Gadget LoadGadget =
  386.   { /* Load button */
  387.   &FileListGadget[0],      /* next gadget */
  388.   14,130,                  /* location    */
  389.   64,8,
  390.   GADGHCOMP,               /* flags       */
  391.   GADGIMMEDIATE|ENDGADGET, /* activation  */
  392.   BOOLGADGET|REQGADGET,    /* type        */
  393.   (APTR) &ButtonBorder0,   /* rendering   */
  394.   NULL,                    /* rendering   */
  395.   &LoadText,               /* text        */
  396.   0,                       /* mutual exlcude */
  397.   NULL,                    /* string info */
  398.   LOADGADGET,              /* gadget id   */
  399.   NULL                     /* special info*/
  400.   };
  401.  
  402. /**********************************
  403.  * The Cancel Button gadget stuff *
  404.  *********************************/
  405. struct IntuiText CancelText =
  406.   {
  407.   0,1, JAM2,              /* frontpen, packpen, drawmode */
  408.   0,0,                    /* left,top */
  409.   NULL,                   /* font */
  410.   "Cancel",               /* text */
  411.   NULL                    /* next */
  412.   };
  413.  
  414. struct Gadget CancelGadget =
  415.   { /* Cancel button */
  416.   &LoadGadget,             /* next gadget */
  417.   187,130,                 /* location    */
  418.   64,8,
  419.   GADGHCOMP,               /* flags       */
  420.   GADGIMMEDIATE|ENDGADGET, /* activation  */
  421.   BOOLGADGET|REQGADGET,    /* type        */
  422.   (APTR) &ButtonBorder0,   /* rendering   */
  423.   NULL,                    /* rendering   */
  424.   &CancelText,             /* text        */
  425.   0,                       /* mutual exlcude */
  426.   NULL,                    /* string info */
  427.   CANCELGADGET,            /* gadget id   */
  428.   NULL                     /* special info*/
  429.   };
  430.  
  431. /***********************************************
  432.  * The Scroll Selection List up (arrow) gadget *
  433.  **********************************************/
  434. UWORD UpArrowData[15] = {
  435.    0xfffc,
  436.    0xfcfc,
  437.    0xf87c,
  438.    0xf03c,
  439.    0xe01c,
  440.    0xc00c,
  441.    0x8004,
  442.    0xfcfc,
  443.    0xfcfc,
  444.    0xfcfc,
  445.    0xfcfc,
  446.    0xfcfc,
  447.    0xfcfc,
  448.    0xfffc
  449. };
  450.  
  451. struct Image UpArrow = 
  452.   {
  453.    0,0,
  454.    14,
  455.    14,
  456.    1,
  457.    &UpArrowData[0],
  458.    0x1, 0x0,
  459.    NULL
  460.    };
  461.  
  462. struct Gadget UpGadget =
  463.   { /* Up a file gadget */
  464.   &CancelGadget,           /* next gadget */
  465.   247,13,                  /* location    */
  466.   12,15,
  467.   GADGIMAGE|GADGHNONE,     /* flags       */
  468.   GADGIMMEDIATE,           /* activation  */
  469.   BOOLGADGET|REQGADGET,    /* type        */
  470.   (APTR) &UpArrow,         /* rendering   */
  471.   NULL,                    /* rendering   */
  472.   NULL,                    /* text        */
  473.   0,                       /* mutual exlcude */
  474.   NULL,                    /* string info */
  475.   UPGADGET,                /* gadget id   */
  476.   NULL                     /* special info*/
  477.   };
  478. /*************************************************
  479.  * The Scroll Selection List down (arrow) gadget *
  480.  ************************************************/
  481. UWORD DownArrowData[15] = {
  482.    0xfffc,
  483.    0xfcfc,
  484.    0xfcfc,
  485.    0xfcfc,
  486.    0xfcfc,
  487.    0xfcfc,
  488.    0xfcfc,
  489.    0x8004,
  490.    0xc00c,
  491.    0xe01c,
  492.    0xf03c,
  493.    0xf87c,
  494.    0xfcfc,
  495.    0xfffc
  496. };
  497.  
  498. struct Image DownArrow = 
  499.   {
  500.    0,0,
  501.    14,
  502.    14,
  503.    1,
  504.    &DownArrowData[0],
  505.    0x1, 0x0,
  506.    NULL
  507.    };
  508.  
  509. struct Gadget DownGadget =
  510.   { /* Down a file gadget */
  511.   &UpGadget,               /* next gadget */
  512.   247,79,                  /* location    */
  513.   12,15,
  514.   GADGIMAGE|GADGHNONE,     /* flags       */
  515.   GADGIMMEDIATE,           /* activation  */
  516.   BOOLGADGET|REQGADGET,    /* type        */
  517.   (APTR) &DownArrow,       /* rendering   */
  518.   NULL,                    /* rendering   */
  519.   NULL,                    /* text        */
  520.   0,                       /* mutual exlcude */
  521.   NULL,                    /* string info */
  522.   DOWNGADGET,              /* gadget id   */
  523.   NULL                     /* special info*/
  524.   };
  525.  
  526. /***************************************************
  527.  * The Scroll Selection list up down Potentiometer *
  528.  **************************************************/
  529. struct PropInfo KnobInfo =
  530.   {
  531.   AUTOKNOB | FREEVERT | PROPBORDERLESS,
  532.   0,
  533.   0, /* VertPot */
  534.   0,
  535.   0x7fff, /* VertBody */
  536.   0,0,0,0,0,0
  537.   };
  538.  
  539. struct Image KnobImage =
  540.   {
  541.   0,0,
  542.   0,0,0,
  543.   NULL,
  544.   0,0,
  545.   NULL
  546.   };
  547.  
  548. struct Gadget PotGadget =
  549.   { /* Potentiometer file gadget */
  550.   &DownGadget,             /* next gadget */
  551.   247,28,                  /* location    */
  552.   14,50,
  553.   GADGHNONE,               /* flags       */
  554.   RELVERIFY,               /* activation  */
  555.   PROPGADGET|REQGADGET,    /* type        */
  556.   (APTR) &KnobImage,       /* rendering   */
  557.   NULL,                    /* rendering   */
  558.   NULL,                    /* text        */
  559.   0,                       /* mutual exlcude */
  560.   &KnobInfo,               /* string info */
  561.   POTGADGET,               /* gadget id   */
  562.   NULL                     /* special info*/
  563.   };
  564. /***************************************************************************
  565. *                  Other Requester structures                              *
  566. ***************************************************************************/
  567. struct IntuiText HeadingText =
  568.   {
  569.   2,1, JAM2,              /* frontpen, packpen, drawmode */
  570.   4,3,                    /* left,top */
  571.   NULL,                   /* font */
  572.   NULL,                   /* text */
  573.   NULL                    /* next */
  574.   };
  575.  
  576. SHORT Requester0Points[] = {
  577.   2,1,
  578.   261,1,
  579.   261,144,
  580.   2,144,
  581.   2,1
  582.   };
  583. struct Border Requester0Border = {
  584.   0,0,
  585.   0,1,JAM1,
  586.   5,
  587.   &Requester0Points[0],
  588.   NULL
  589.   };
  590.  
  591. SHORT Requester1Points[] = {
  592.   2,12,
  593.   261,12
  594.   };
  595. struct Border Requester1Border = {
  596.   0,0,
  597.   0,1,JAM1,
  598.   2,
  599.   &Requester1Points[0],
  600.   &Requester0Border
  601.   };
  602.  
  603. SHORT Requester2Points[] = {
  604.   2,93,
  605.   261,93
  606.   };
  607. struct Border Requester2Border = {
  608.   0,0,
  609.   0,1,JAM1,
  610.   2,
  611.   &Requester2Points[0],
  612.   &Requester1Border
  613.   };
  614.  
  615. SHORT Requester3Points[] = {
  616.   246,12,
  617.   246,93,
  618.   246,78,
  619.   261,78,
  620.   261,27,
  621.   247,27
  622.   };
  623. struct Border Requester3Border = {
  624.   0,0,
  625.   0,1,JAM1,
  626.   6,
  627.   &Requester3Points[0],
  628.   &Requester2Border
  629.   };
  630.  
  631. /****************************************************************************
  632.  *                     The Code part of the requester
  633.  ***************************************************************************/
  634. BOOL FileRequest(FileType,Action,FullName,ReqWindow)
  635.   UBYTE *FileType;
  636.   UBYTE *Action;
  637.   UBYTE *FullName;
  638.   struct Window *ReqWindow;
  639. {
  640.   UBYTE *StrPtr;
  641.   BOOL   RetCode;
  642.  
  643.   window = ReqWindow;           /* make pointer to window and name global */
  644.   FullPath = FullName;
  645.   HeadingText.IText = FileType; /* Center requester title */
  646.   HeadingText.LeftEdge = (256-IntuiTextLength(&HeadingText))/2;
  647.   LoadText.IText = Action;
  648.  
  649.   InitFNR();
  650.  
  651.   /* Separate the path from the file name. Set the file name in the gadget */
  652.   if (StrPtr = rindex(FullName,'/'))
  653.     {
  654.     strcpy(FileString.Buffer,StrPtr + 1);
  655.     *StrPtr = '\0';
  656.     }
  657.   else
  658.     if (StrPtr = rindex(FullName,':'))
  659.       {
  660.       strcpy(FileString.Buffer,StrPtr + 1);
  661.       *(StrPtr+1) = '\0';
  662.       }
  663.     else
  664.       {
  665.       *FileString.Buffer   = '\0';
  666.       *DrawerString.Buffer = '\0';
  667.       *FullName = '\0';
  668.       }
  669.   /* Separate the last dir in path and put it in drawer gadget */
  670.   if (StrPtr = rindex(FullName,'/'))
  671.     strcpy(DrawerString.Buffer,StrPtr + 1);
  672.   else
  673.     if (StrPtr = rindex(FullName,':'))
  674.       if (*(StrPtr+1))
  675.         strcpy(DrawerString.Buffer,StrPtr + 1);
  676.       else
  677.         strcpy(DrawerString.Buffer,FullName);
  678.     else
  679.       *DrawerString.Buffer = '\0';
  680.  
  681.   /* Put up the requester and list the dir into it */ 
  682.   Request(&FileRequester,window);
  683.   ListDir(FullName);
  684.   SetNewFile(&FileGadget,FileString.Buffer); /* why do I have to do this? */
  685.   SetNewFile(&DrawerGadget,DrawerString.Buffer);
  686.  
  687.   RetCode = WaitRequester();         /* do everything till Cancel or Load */
  688.  
  689.   /* Put file name and path back together */
  690.   if (FullName[strlen(FullName)-1] != ':')
  691.     strcat(FullName,"/");
  692.   strcat(FullName,FileString.Buffer);
  693.   return(RetCode);
  694. } /* LoadRequest */
  695.  
  696. /*
  697.  *  Init the file name requester
  698.  */
  699. InitFNR()
  700. {
  701.   InitRequester(&FileRequester);
  702.   FileRequester.LeftEdge  = 6;
  703.   FileRequester.TopEdge   = 12;
  704.   FileRequester.Width     = 264;
  705.   FileRequester.Height    = 146;
  706.   FileRequester.ReqGadget = &PotGadget;
  707.   FileRequester.ReqText   = &HeadingText;
  708.   FileRequester.BackFill  = 1;
  709.   FileRequester.Flags     = 0;
  710.   FileRequester.ReqBorder = &Requester3Border;
  711. } /* InitFNR */
  712.  
  713. /*
  714.  *  WaitRequester - List dirs, scroll, and set drawer and file strings until
  715.  *                  one of the LOAD(SAVE) or CANCEL buttons pushed.
  716.  */
  717. BOOL WaitRequester()
  718. {
  719.   ULONG  class = GADGETDOWN;
  720.   USHORT choice = CANCELGADGET;
  721.   struct Gadget *gadget;
  722.  
  723.   while (class != REQCLEAR)
  724.     {
  725.     if ((message=(struct IntuiMessage *) GetMsg(window->UserPort)) == 0L)
  726.       {
  727.       Wait(1L<<window->UserPort->mp_SigBit);
  728.       continue;
  729.       }
  730.     class  = message->Class;
  731.     gadget = (struct Gadget *) message->IAddress;
  732.     ReplyMsg(message);
  733.     switch (class)
  734.       {
  735.       case GADGETDOWN:
  736.            switch (gadget->GadgetID >> CLASSBITS)
  737.              {
  738.              case UPDOWNCLASS:
  739.                   ScrollList(gadget);      /* scroll up/down 1 file */
  740.                   break;
  741.              case CHOICECLASS:             /* set the name in string gads */
  742.                   if (IsDir(gadget->GadgetText->IText))
  743.                     SetNewDrawer(&DrawerGadget,gadget->GadgetText->IText);
  744.                   else
  745.                     SetNewFile(&FileGadget,gadget->GadgetText->IText);
  746.                   break;
  747.              case BUTTONCLASS:             /* LOAD or CANCEL */
  748.                   choice = gadget->GadgetID & GADGETNUM;
  749.              }
  750.       case GADGETUP:
  751.            switch (gadget->GadgetID >> CLASSBITS)
  752.              {
  753.              case UPDOWNCLASS:             /* Potentiometer scroll */
  754.                   PotScrollList(gadget);
  755.                   break;
  756.              case STRINGCLASS:             /* They typed drawer name in */
  757.                   ThrowTrailing(DrawerString.Buffer);
  758.                   strcpy(FullPath,DrawerString.Buffer);
  759.                   SetNewFile(&FileGadget,"");
  760.                   ListDir(DrawerString.Buffer);
  761.              }
  762.       }
  763.     }
  764.   return(choice==LOAD);
  765. } /* WaitRequester */
  766.  
  767. /*
  768.  *  SetNewDrawer - Used Mouse to pick directory from selection list gadgets.
  769.  */ 
  770. SetNewDrawer(Gadget,Text)
  771.   struct Gadget *Gadget;
  772.   UBYTE  *Text;
  773. {
  774.   SetNewFile(&FileGadget,"");              /* clear file name string */
  775.   SetNewFile(Gadget,Text);                 /* set new drawer into gadget */
  776.   if (FullPath[strlen(FullPath)-1] != ':') /* make new path */
  777.     strncat(FullPath,"/",PATHNAMELEN);
  778.   strncat(FullPath,Text,PATHNAMELEN);
  779.   ListDir(FullPath);                       /* List new files into Sel List */
  780. } /* SetNewDrawer */
  781.  
  782. /*
  783.  *  SetNewFile - Have to remove gadgets change strings and add them */
  784. SetNewFile(Gadget,Text)
  785.   struct Gadget *Gadget;
  786.   UBYTE  *Text;
  787. {
  788.   USHORT Pos, RemoveGadget();
  789.  
  790.   if (Text[0] != ' ')
  791.     {
  792.     Pos = RemoveGadget(window,Gadget);
  793.     ThrowTrailing(Text);                    /* get rid of trailing blanks */
  794.     strcpy(Gadget->SpecialInfo->Buffer,Text);
  795.     AddGadget(window,Gadget,Pos);
  796.     RefreshGadgets(&DownGadget,window,&FileRequester);
  797.     }
  798. } /* SetNewFile */
  799.  
  800. /*
  801.  *  ListDir - List the directory into array of string names.
  802.  */
  803. ListDir(dir)
  804.   char *dir;
  805. {
  806.   struct FileLock *my_lock, *Lock() ;
  807.  
  808.   FileCount = 0;
  809.   FirstFile = 0;
  810.  
  811.   if ((my_lock = Lock(dir, ACCESS_READ)) != NULL)
  812.     {
  813.     if (Examine(my_lock, &FileInfo))
  814.       {
  815.       ExNext(my_lock, &FileInfo);
  816.  
  817.       while (IoErr() != ERROR_NO_MORE_ENTRIES && FileCount < MAXFILES)
  818.         {
  819.         strcpy(&FileListEntry[FileCount][0], FileInfo.fib_FileName);
  820.         if (FileInfo.fib_DirEntryType > 0)
  821.           strcat(&FileListEntry[FileCount][0]," (dir)");
  822.         FileCount++;
  823.         ExNext(my_lock, &FileInfo);
  824.         }
  825.       UnLock(my_lock) ;
  826.       }
  827.     }
  828.   AttachList(FirstFile);
  829.   if (FileCount > 8)
  830.     ModifyProp(&PotGadget,window,&FileRequester,AUTOKNOB|FREEVERT|PROPBORDERLESS,0,0,0,0xffff/(FileCount-6)*8);
  831.   else
  832.     ModifyProp(&PotGadget,window,&FileRequester,AUTOKNOB|FREEVERT|PROPBORDERLESS,0,0,0,0xffff);
  833. } /* ListDir */
  834.  
  835. /*
  836.  *  AttachList - Attach list of file (directory) names to Selection gadgets
  837.  */
  838. AttachList(Start)
  839.   USHORT Start;
  840. {
  841.   USHORT Gadget;
  842.   USHORT Pos, RemoveGadget();
  843.  
  844.   for (Gadget = 0; Gadget <= 7 && Gadget+Start < FileCount; Gadget++)
  845.     {
  846.     Pos = RemoveGadget(window,&FileListGadget[Gadget]);
  847.     strcpy(FileList[Gadget].IText,&FileListEntry[Start + Gadget][0]);
  848.     strncat(FileList[Gadget].IText,"                                ",24-strlen(FileList[Gadget].IText));
  849.     AddGadget(window,&FileListGadget[Gadget],Pos);
  850.     }
  851.   for (; Gadget <= 7; Gadget++)
  852.     {
  853.     Pos = RemoveGadget(window,&FileListGadget[Gadget]);
  854.     strncpy(FileList[Gadget].IText,"                                ",24);
  855.     AddGadget(window,&FileListGadget[Gadget],Pos);
  856.     }
  857.   RefreshGadgets(&DownGadget,window,&FileRequester);
  858. } /* AttachList */
  859.  
  860. /*
  861.  *  ScrollList - Scroll the list up or down 1 file if possible
  862.  */
  863. ScrollList(gadget)
  864.   struct Gadget *gadget;
  865. {
  866.   ULONG VertPot = 0;
  867.  
  868.   switch(gadget->GadgetID & GADGETNUM)
  869.     {
  870.     case DOWN:
  871.          if (FileCount > FirstFile + 8)
  872.            ++FirstFile;
  873.          break;
  874.     case UP:
  875.          if (FirstFile > 0)
  876.            --FirstFile;
  877.     }
  878.   if (FileCount > 8)
  879.     VertPot  = 0xffff/(FileCount-6)*FirstFile;
  880.   ModifyProp(&PotGadget,window,&FileRequester,AUTOKNOB|FREEVERT|PROPBORDERLESS,0,VertPot,0,KnobInfo.VertBody);
  881.   AttachList(FirstFile);
  882. } /* ScrollList */
  883.  
  884. /*
  885.  *  PotScrollList - Calculate the file number from Pot value and attach
  886.  *                  names to Selector List gadgets.
  887.  */
  888. PotScrollList(gadget)
  889.   struct Gadget *gadget;
  890. {
  891.   switch (gadget->GadgetID & GADGETNUM)
  892.     {
  893.     case POT:
  894.          FirstFile = (FileCount-6)*KnobInfo.VertPot >> 16;
  895.          AttachList(FirstFile);
  896.     }
  897. } /* PotScrollList */
  898.  
  899. /*
  900.  *  IsDir - Simple minded routine to find " (dir)" in file name 
  901.  */
  902. BOOL IsDir(Name)
  903.   UBYTE *Name;
  904. {
  905.   UBYTE *Dir;
  906.   if (Dir = rindex(Name,'('))
  907.     if (strcmp(Dir,"(dir)"))
  908.       {
  909.       Dir[0] = '\0';
  910.       ThrowTrailing(Name);
  911.       return(TRUE);
  912.       }
  913.     else
  914.       return(FALSE);
  915.   else
  916.     return(FALSE);
  917. } /* IsDir */
  918.  
  919. /*
  920.  *  ThrowTrailing - Remove trailing blanks from string
  921.  */
  922. ThrowTrailing(String)
  923.   UBYTE *String;
  924. {
  925.   SHORT I;
  926.  
  927.   I = strlen(String) - 1;
  928.   while (String[I] == ' ' && I > 0)
  929.     String[I--] = '\0';
  930. } /* ThrowTrailing */
  931.