home *** CD-ROM | disk | FTP | other *** search
/ Graphics 16,000 / graphics-16000.iso / amiga / fractal / mak / source.lzh / Source / FileManager.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-29  |  36.5 KB  |  2,018 lines

  1. /*************************************************************************
  2.  
  3.                             F I L E M A N A G E R
  4.  
  5. **************************************************************************
  6.  
  7. **************************************************************************
  8.  
  9.  Hacked from File Window (a public domain program)...
  10.  
  11. *************************************************************************/
  12.  
  13. #include <exec/types.h>
  14. #include <exec/nodes.h>
  15. #include <exec/lists.h>
  16. #include <exec/libraries.h>
  17. #include <exec/ports.h>
  18. #include <exec/interrupts.h>
  19. #include <exec/io.h>
  20. #include <exec/memory.h>
  21. #include <libraries/dos.h>
  22. #include <libraries/dosextens.h>
  23. #include <intuition/intuition.h>
  24. #include <string.h>
  25.  
  26. #define LOAD 500
  27. #define SAVE 600
  28. #define DELETE 700
  29. #define CANCEL 800
  30. #define QUIT 900
  31. #define PANIC 1000
  32.  
  33. #define DRAWER_LENGTH 100
  34. #define FILE_LENGTH 30
  35. #define TOTAL_LENGTH 130
  36.  
  37. #define MAK_PIC 0
  38.  
  39. USHORT File_Man();
  40. STRPTR right_pos();
  41. APTR save_file_info();
  42. BOOL file_comp();
  43. BOOL directory();
  44. BOOL last_check();
  45. BOOL new_drawer();
  46. BOOL pick_file();
  47. BOOL request_ask();
  48. void put_in();
  49. void deallocate_file_info();
  50. void change_device();
  51. void parent();
  52. void request_ok();
  53. void display_list();
  54. void connect_dir_file();
  55. void adjust_string_gadgets();
  56. void delete_file_dir();
  57.  
  58.  
  59. extern struct TextAttr Font;
  60. extern struct Screen *FirstScreen;
  61. extern struct IntuiMessage *message;
  62. extern struct Window *FirstWindow;
  63. extern struct IntuitionBase *IntuitionBase;
  64. extern USHORT *Pointer,*Sleepy;
  65. extern SHORT op_code;
  66.  
  67. struct Window *file_window;
  68. struct IntuiMessage *my_gadget_message;
  69.  
  70. struct file_info
  71. {
  72.   BYTE name[28];        
  73.   BOOL directory;      
  74.   struct file_info *next; 
  75. };
  76.  
  77.  
  78. struct FileInfoBlock *file_info;
  79. struct FileLock *lock, *Lock();
  80.  
  81.  
  82. BOOL file_lock; 
  83. BOOL more_files; 
  84. BOOL first_file;
  85.  
  86.  
  87. struct file_info *first_pointer;
  88.  
  89. /* ********************************************************************* */
  90. /* * IntuiText structures for the requesters                           * */
  91. /* ********************************************************************* */
  92.  
  93.  
  94. struct IntuiText text_request=
  95. {
  96.   0, 2,                 
  97.   JAM1,                 
  98.   15, 5,  
  99.   &Font,
  100.   NULL,    
  101.   NULL     
  102. };
  103.  
  104.  
  105. struct IntuiText ok_request=
  106. {
  107.   0, 2,    
  108.   JAM1,    
  109.   6, 3,    
  110.   &Font,
  111.   "OK",    
  112.   NULL     
  113. };
  114.  
  115.  
  116. struct IntuiText option1_request=
  117. {
  118.   0, 2,    
  119.   JAM1,    
  120.   6, 3,     
  121.   &Font, 
  122.   NULL,    
  123.   NULL  
  124. };
  125.  
  126.  
  127. struct IntuiText option2_request=
  128. {
  129.   0, 2,   
  130.   JAM1,   
  131.   6, 3,   
  132.   &Font, 
  133.   NULL,     
  134.   NULL     
  135. };
  136.  
  137.  
  138. SHORT points4[]=
  139. {
  140.    0,  0,
  141.   44,  0,
  142.   44, 14,
  143.    0, 14,
  144.    0,  0
  145. };
  146.  
  147.  
  148.  
  149. SHORT points6[]=
  150. {
  151.    0,  0,
  152.   60,  0,
  153.   60, 14,
  154.    0, 14,
  155.    0,  0
  156. };
  157.  
  158.  
  159. struct Border border_text4=
  160. {
  161.   0, 0,        
  162.   1, 2, JAM1,  
  163.   5,           
  164.   points4,     
  165.   NULL         
  166. };
  167.  
  168.  
  169.  
  170. struct Border border_text6=
  171. {
  172.   0, 0,        
  173.   1, 2, JAM1,  
  174.   5,           
  175.   points6,     
  176.   NULL        
  177. };
  178.  
  179.  
  180.  
  181. /* ********************************************************************* */
  182. /* * Information for the proportional gadget                           * */
  183. /* ********************************************************************* */
  184.  
  185. struct Image image_prop;
  186.  
  187. struct PropInfo prop_info=
  188. {
  189.   AUTOKNOB|
  190.   FREEVERT, 
  191.   0,0,     
  192.   0,       
  193.   0xFFFF,   
  194.   0,0,0,0,0,0 
  195. };
  196.  
  197. struct Gadget gadget_proportional=
  198. {
  199.   NULL,                   
  200.   290, 50, 21, 72,         
  201.   GADGHCOMP,               
  202.   GADGIMMEDIATE|FOLLOWMOUSE|RELVERIFY,
  203.   PROPGADGET,              
  204.   (APTR) &image_prop,      
  205.   NULL,                    
  206.   NULL,                    
  207.   NULL,                    
  208.   (APTR) &prop_info,      
  209.   NULL,                    
  210.   NULL                    
  211. };
  212.  
  213.  
  214.  
  215. /* UndoBuffer for the string gadgets: */
  216. UBYTE name_backup[DRAWER_LENGTH];
  217.  
  218.  
  219.  
  220. /* ********************************************************************* */
  221. /* * Information for the string gadget "Drawer:"                       * */
  222. /* ********************************************************************* */
  223.  
  224. UBYTE drawer_name[DRAWER_LENGTH];
  225.  
  226.  
  227. SHORT points28s[]=
  228. {
  229.    -7, -4,
  230.   200, -4,
  231.   200, 11,
  232.    -7, 11,
  233.    -7, -4
  234. };
  235.  
  236.  
  237.  
  238. struct Border border_text28s=
  239. {
  240.   0, 0,       
  241.   1, 2, JAM1,  
  242.   5,           
  243.   points28s,   
  244.   NULL         
  245. };
  246.  
  247.  
  248. struct IntuiText text_drawer=
  249. {
  250.   1, 2,      
  251.   JAM1,     
  252.   -69, 0,    
  253.   &Font,  
  254.   "Drawer:", 
  255.   NULL       
  256. };
  257.  
  258.  
  259. struct StringInfo string_drawer=
  260. {
  261.   drawer_name,       
  262.   name_backup,       
  263.   0,                 
  264.   70,                
  265.   0,                 
  266.   0,               
  267.   0, 0,            
  268.   NULL,            
  269.   NULL,            
  270.   NULL,            
  271. };
  272.  
  273.  
  274. struct Gadget gadget_drawer=
  275. {
  276.   &gadget_proportional,   
  277.   83, 35, 198, 8,         
  278.   GADGHCOMP,              
  279.   RELVERIFY,           
  280.   STRGADGET,             
  281.   (APTR) &border_text28s, 
  282.   NULL,                 
  283.   &text_drawer,         
  284.   NULL,                 
  285.   (APTR) &string_drawer, 
  286.   NULL,                  
  287.   NULL                    
  288. };
  289.  
  290.  
  291.  
  292. /* ********************************************************************* */
  293. /* * Information for the string gadget "File:"                         * */
  294. /* ********************************************************************* */
  295.  
  296.  
  297. UBYTE file_name[FILE_LENGTH];
  298.  
  299.  
  300. SHORT points30s[]=
  301. {
  302.    -7, -4,
  303.   244, -4,
  304.   244, 11,
  305.    -7, 11,
  306.    -7, -4
  307. };
  308.  
  309.  
  310. struct Border border_text30s=
  311. {
  312.   0, 0,        
  313.   1, 2, JAM1, 
  314.   5,           
  315.   points30s,
  316.   NULL       
  317. };
  318.  
  319.  
  320. struct IntuiText text_file=
  321. {
  322.   1, 2,    
  323.   JAM1,   
  324.   -53, 0, 
  325.   &Font, 
  326.   "File:",  
  327.   NULL    
  328. };
  329.  
  330.  
  331. struct StringInfo string_file=
  332. {
  333.   file_name,        
  334.   name_backup,    
  335.   0,                
  336.   40,              
  337.   0,              
  338.   0,             
  339.   0, 0,           
  340.   NULL,           
  341.   NULL,            
  342.   NULL,            
  343. };
  344.  
  345.  
  346. struct Gadget gadget_file=
  347. {
  348.   &gadget_drawer,      
  349.   66, 129, 240, 8,     
  350.   GADGHCOMP,             
  351.   NULL,                 
  352.   STRGADGET,           
  353.   (APTR) &border_text30s,
  354.   NULL,                  
  355.   &text_file,         
  356.   NULL,                 
  357.   (APTR) &string_file, 
  358.   NULL,                 
  359.   NULL                 
  360. };
  361.  
  362.  
  363.  
  364. /* ********************************************************************* */
  365. /* * Information for the string gadget "Extension"                     * */
  366. /* ********************************************************************* */
  367.  
  368.  
  369. UBYTE extension_name[7];
  370.  
  371.  
  372. SHORT points6s[]=
  373. {
  374.   -7, -4,
  375.   57, -4,
  376.   57, 10,
  377.   -7, 10,
  378.   -7, -4
  379. };
  380.  
  381.  
  382. struct Border border_text6s=
  383. {
  384.   0, 0,        
  385.   1, 2, JAM1,  
  386.   5,            
  387.   points6s,   
  388.   NULL        
  389. };
  390.  
  391.  
  392. struct IntuiText text_extension=
  393. {
  394.   1, 2,    
  395.   JAM1,   
  396.   -45, 0,  
  397.   &Font,
  398.   "Ext:",
  399.   NULL    
  400. };
  401.  
  402.  
  403. struct StringInfo string_extension=
  404. {
  405.   extension_name,  
  406.   name_backup,       
  407.   0,               
  408.   7,                
  409.   0,               
  410.   0,                
  411.   0, 0,            
  412.   NULL,            
  413.   NULL,           
  414.   NULL,           
  415. };
  416.  
  417.  
  418. struct Gadget gadget_extension=
  419. {
  420.   &gadget_file,          
  421.   253, 17, 59, 8,          
  422.   GADGHCOMP,              
  423.   RELVERIFY,              
  424.   STRGADGET,               
  425.   (APTR) &border_text6s,   
  426.   NULL,                   
  427.   &text_extension,         
  428.   NULL,                    
  429.   (APTR) &string_extension, 
  430.   NULL,                 
  431.   NULL                  
  432. };
  433.  
  434.  
  435.  
  436. /* ********************************************************************* */
  437. /* * Information for the boolean gadget parent "<"                     * */
  438. /* ********************************************************************* */
  439.  
  440.  
  441.  
  442. SHORT points1[]=
  443. {
  444.    0,  0,
  445.   20,  0,
  446.   20, 15,
  447.    0, 15,
  448.    0,  0
  449. };
  450.  
  451.  
  452.  
  453. struct Border border_text1=
  454. {
  455.   0, 0,       
  456.   1, 2, JAM1,  
  457.   5,          
  458.   points1,   
  459.   NULL         
  460. };
  461.  
  462.  
  463. struct IntuiText text_parent=
  464. {
  465.   1, 2,    
  466.   JAM1,     
  467.   7,4,    
  468.   &Font,
  469.   "<",     
  470.   NULL    
  471. };
  472.  
  473.  
  474. struct Gadget gadget_parent=
  475. {
  476.   &gadget_extension,   
  477.   290, 31, 21, 16,       
  478.   GADGHCOMP,            
  479.   RELVERIFY,            
  480.   BOOLGADGET,          
  481.   (APTR) &border_text1,  
  482.   NULL,                
  483.   &text_parent,      
  484.   NULL,                 
  485.   NULL,               
  486.   NULL,             
  487.   NULL                 
  488. };
  489.  
  490.  
  491.  
  492. /* ********************************************************************* */
  493. /* * Information for the boolean gadget "dh0:"                         * */
  494. /* ********************************************************************* */
  495.  
  496.  
  497. struct IntuiText text_dh0=
  498. {
  499.   1, 2,    
  500.   JAM1,   
  501.   7,4,    
  502.   &Font, 
  503.   "dh0:", 
  504.   NULL   
  505. };
  506.  
  507.  
  508. struct Gadget gadget_dh0=
  509. {
  510.   &gadget_parent,      
  511.   110, 13, 45, 15,      
  512.   GADGHCOMP,           
  513.   RELVERIFY,          
  514.   BOOLGADGET,            
  515.   (APTR) &border_text4, 
  516.   NULL,                
  517.   &text_dh0,            
  518.   NULL,                 
  519.   NULL,                
  520.   NULL,              
  521.   NULL                 
  522. };
  523.  
  524.  
  525.  
  526. /* ********************************************************************* */
  527. /* * Information for the boolean gadget "df1:"                         * */
  528. /* ********************************************************************* */
  529.  
  530.  
  531. struct IntuiText text_df1=
  532. {
  533.   1, 2,    
  534.   JAM1,   
  535.   7,4,     
  536.   &Font, 
  537.   "df1:",  
  538.   NULL   
  539. };
  540.  
  541.  
  542. struct Gadget gadget_df1=
  543. {
  544.   &gadget_dh0,          
  545.   59, 13, 45, 15,    
  546.   GADGHCOMP,           
  547.   RELVERIFY,            
  548.   BOOLGADGET,            
  549.   (APTR) &border_text4, 
  550.   NULL,                
  551.   &text_df1,          
  552.   NULL,               
  553.   NULL,              
  554.   NULL,              
  555.   NULL               
  556. };
  557.  
  558.  
  559.  
  560. /* ********************************************************************* */
  561. /* * Information for the boolean gadget "df0:"                         * */
  562. /* ********************************************************************* */
  563.  
  564.  
  565. struct IntuiText text_df0=
  566. {
  567.   1, 2,   
  568.   JAM1,  
  569.   7,4,      
  570.   &Font, 
  571.   "df0:",
  572.   NULL     
  573. };
  574.  
  575.  
  576. struct Gadget gadget_df0=
  577. {
  578.   &gadget_df1,          
  579.   8, 13, 45, 15,         
  580.   GADGHCOMP,           
  581.   RELVERIFY,           
  582.   BOOLGADGET,           
  583.   (APTR) &border_text4,  
  584.   NULL,                 
  585.   &text_df0,         
  586.   NULL,               
  587.   NULL,              
  588.   NULL,               
  589.   NULL                 
  590. };
  591.  
  592.  
  593.  
  594. /* ********************************************************************* */
  595. /* * Information for the boolean gadget "CANCEL"                       * */
  596. /* ********************************************************************* */
  597.  
  598.  
  599. struct IntuiText text_cancel=
  600. {
  601.   1, 2,     
  602.   JAM1,     
  603.   7,4,     
  604.   &Font, 
  605.   "CANCEL",
  606.   NULL    
  607. };
  608.  
  609.  
  610. struct Gadget gadget_cancel=
  611. {
  612.   &gadget_df0,         
  613.   177, 144, 61, 15,      
  614.   GADGHCOMP,        
  615.   RELVERIFY,            
  616.   BOOLGADGET,            
  617.   (APTR) &border_text6,  
  618.   NULL,               
  619.   &text_cancel,        
  620.   NULL,                 
  621.   NULL,               
  622.   NULL,               
  623.   NULL                 
  624. };
  625.  
  626.  
  627.  
  628. /* ********************************************************************* */
  629. /* * Information for the boolean gadget "DELETE"                       * */
  630. /* ********************************************************************* */
  631.  
  632.  
  633. struct IntuiText text_delete=
  634. {
  635.   1, 2,    
  636.   JAM1,    
  637.   7,4,    
  638.   &Font, 
  639.   "DELETE", 
  640.   NULL    
  641. };
  642.  
  643.  
  644. struct Gadget gadget_delete=
  645. {
  646.   &gadget_cancel,       
  647.   110, 144, 61, 15,    
  648.   GADGHCOMP,            
  649.   RELVERIFY,             
  650.   BOOLGADGET,           
  651.   (APTR) &border_text6,   
  652.   NULL,                
  653.   &text_delete,        
  654.   NULL,                
  655.   NULL,               
  656.   NULL,               
  657.   NULL                
  658. };
  659.  
  660.  
  661.  
  662. /* ********************************************************************* */
  663. /* * Information for the boolean gadget "SAVE"                         * */
  664. /* ********************************************************************* */
  665.  
  666.  
  667. struct IntuiText text_save=
  668. {
  669.   1, 2,   
  670.   JAM1,  
  671.   7,4,     
  672.   &Font, 
  673.   "SAVE",  
  674.   NULL    
  675. };
  676.  
  677.  
  678. struct Gadget gadget_save=
  679. {
  680.   &gadget_delete,     
  681.   59, 144, 45, 15,    
  682.   GADGHCOMP,            
  683.   RELVERIFY,            
  684.   BOOLGADGET,           
  685.   (APTR) &border_text4, 
  686.   NULL,              
  687.   &text_save,          
  688.   NULL,                 
  689.   NULL,              
  690.   NULL,               
  691.   NULL                
  692. };
  693.  
  694.  
  695.  
  696. /* ********************************************************************* */
  697. /* * Information for the boolean gadget "LOAD"                         * */
  698. /* ********************************************************************* */
  699.  
  700.  
  701. struct IntuiText text_load=
  702. {
  703.   1, 2,    
  704.   JAM1,   
  705.   7,4,     
  706.   &Font, 
  707.   "LOAD", 
  708.   NULL   
  709. };
  710.  
  711.  
  712. struct Gadget gadget_load=
  713. {
  714.   &gadget_save,        
  715.   8, 144, 45, 15,       
  716.   GADGHCOMP,            
  717.   RELVERIFY,            
  718.   BOOLGADGET,            
  719.   (APTR) &border_text4,   
  720.   NULL,                
  721.   &text_load,        
  722.   NULL,               
  723.   NULL,                
  724.   NULL,                
  725.   NULL             
  726. };
  727.  
  728.  
  729.  
  730. UBYTE display_text[8][34];
  731.  
  732. struct IntuiText text_list[8]=
  733. {
  734.   {
  735.     1, 0,         
  736.     JAM2,        
  737.     0,0,           
  738.     &Font,       
  739.     display_text[0], 
  740.     &text_list[1]  
  741.   },
  742.   {
  743.     1, 0,           
  744.     JAM2,          
  745.     0,8,           
  746.     &Font,       
  747.     display_text[1], 
  748.     &text_list[2]   
  749.   },
  750.   {
  751.     1, 0,          
  752.     JAM2,           
  753.     0,16,          
  754.     &Font,       
  755.     display_text[2], 
  756.     &text_list[3]   
  757.   },
  758.   {
  759.     1, 0,        
  760.     JAM2,            
  761.     0,24,          
  762.     &Font,        
  763.     display_text[3],
  764.     &text_list[4]  
  765.   },
  766.   {
  767.     1, 0,           
  768.     JAM2,          
  769.     0,32,            
  770.     &Font,       
  771.     display_text[4], 
  772.     &text_list[5]  
  773.   },
  774.   {
  775.     1, 0,           
  776.     JAM2,        
  777.     0,40,           
  778.     &Font,        
  779.     display_text[5], 
  780.     &text_list[6]  
  781.   },
  782.   {
  783.     1, 0,          
  784.     JAM2,        
  785.     0,48,        
  786.     &Font,    
  787.     display_text[6], 
  788.     &text_list[7]  
  789.   },
  790.   {
  791.     1, 0,         
  792.     JAM2,           
  793.     0,56,          
  794.     &Font,      
  795.     display_text[7],
  796.     NULL           
  797.   }
  798. };
  799.  
  800.  
  801.  
  802. struct Gadget gadget_display[8]=
  803. {
  804.   {
  805.     &gadget_display[1], 
  806.     8, 50, 276, 12,     
  807.     GADGHNONE,       
  808.     GADGIMMEDIATE,    
  809.     BOOLGADGET,        
  810.     NULL,            
  811.     NULL,           
  812.     NULL,            
  813.     NULL,           
  814.     NULL,              
  815.     NULL,             
  816.     NULL             
  817.   },
  818.   {
  819.     &gadget_display[2],
  820.     8, 62, 276, 8,     
  821.     GADGHNONE,        
  822.     GADGIMMEDIATE,    
  823.     BOOLGADGET,        
  824.     NULL,             
  825.     NULL,            
  826.     NULL,            
  827.     NULL,             
  828.     NULL,           
  829.     NULL,           
  830.     NULL              
  831.   },
  832.   {
  833.     &gadget_display[3], 
  834.     8, 70, 276, 8,     
  835.     GADGHNONE,         
  836.     GADGIMMEDIATE,    
  837.     BOOLGADGET,      
  838.     NULL,            
  839.     NULL,            
  840.     NULL,             
  841.     NULL,            
  842.     NULL,            
  843.     NULL,             
  844.     NULL            
  845.   },
  846.   {
  847.     &gadget_display[4], 
  848.     8, 78, 276, 8,    
  849.     GADGHNONE,        
  850.     GADGIMMEDIATE,    
  851.     BOOLGADGET,       
  852.     NULL,             
  853.     NULL,           
  854.     NULL,             
  855.     NULL,             
  856.     NULL,           
  857.     NULL,           
  858.     NULL           
  859.   },
  860.   {
  861.     &gadget_display[5], 
  862.     8, 86, 276, 8,      
  863.     GADGHNONE,       
  864.     GADGIMMEDIATE,   
  865.     BOOLGADGET,       
  866.     NULL,           
  867.     NULL,           
  868.     NULL,           
  869.     NULL,            
  870.     NULL,           
  871.     NULL,            
  872.     NULL            
  873.   },
  874.   {
  875.     &gadget_display[6],
  876.     8, 94, 276, 8,     
  877.     GADGHNONE,          
  878.     GADGIMMEDIATE,     
  879.     BOOLGADGET,       
  880.     NULL,              
  881.     NULL,            
  882.     NULL,             
  883.     NULL,             
  884.     NULL,            
  885.     NULL,              
  886.     NULL             
  887.   },
  888.   {
  889.     &gadget_display[7], 
  890.     8, 102, 276, 8,      
  891.     GADGHNONE,         
  892.     GADGIMMEDIATE,   
  893.     BOOLGADGET,         
  894.     NULL,             
  895.     NULL,             
  896.     NULL,           
  897.     NULL,            
  898.     NULL,             
  899.     NULL,              
  900.     NULL              
  901.   },
  902.   {
  903.     &gadget_load,       
  904.     8, 110, 276, 12,   
  905.     GADGHNONE,         
  906.     GADGIMMEDIATE,     
  907.     BOOLGADGET,         
  908.     NULL,               
  909.     NULL,               
  910.     NULL,             
  911.     NULL,             
  912.     NULL,            
  913.     NULL,            
  914.     NULL              
  915.   }
  916. };
  917.  
  918.  
  919.  
  920. /* ********************************************************************* */
  921. /* * BIG BOX                                                           * */
  922. /* ********************************************************************* */
  923.  
  924.  
  925. SHORT points_big_box[]=
  926. {
  927.    8, 50,
  928.  283, 50,
  929.  283, 121,
  930.    8, 121,
  931.    8, 50
  932. };
  933.  
  934.  
  935. struct Border border_big_box=
  936. {
  937.   0, 0,          
  938.   1, 2, JAM1,    
  939.   5,             
  940.   points_big_box, 
  941.   NULL          
  942. };
  943.  
  944.  
  945.  
  946. /* ********************************************************************* */
  947. /* * Information for the window                                          */
  948. /* ********************************************************************* */
  949.  
  950. struct NewWindow new_file_window=
  951. {
  952.   0,0,             
  953.   320, 163,       
  954.   0,1,           
  955.   CLOSEWINDOW|    
  956.   GADGETDOWN|
  957.   MOUSEMOVE|
  958.   GADGETUP,
  959.   ACTIVATE|        
  960.   WINDOWDEPTH|
  961.   WINDOWDRAG|
  962.   WINDOWCLOSE|
  963.   SMART_REFRESH,
  964.   &gadget_display[0], 
  965.   NULL,              
  966.   NULL,            
  967.   NULL,              
  968.   NULL,            
  969.   0,0,               
  970.   0,0,             
  971.   CUSTOMSCREEN
  972. };
  973.  
  974.  
  975. file_manager(FirstWindow,Pointer,op_code)
  976. struct Window *FirstWindow;
  977. USHORT *Pointer;
  978. SHORT op_code;
  979.   {
  980.     USHORT operation;
  981.     UBYTE file[TOTAL_LENGTH];    
  982.     strcpy(file, "df1:");
  983.     operation=File_Man("File Manager  V1.0 ",
  984.                         NULL,
  985.                        0,0,
  986.                            file,
  987.                         op_code);
  988.                         
  989.     do_Sleepy(FirstWindow);
  990.     ClearPointer(file_window);
  991.     SetPointer(file_window,Sleepy,25,16,0,0);
  992.                         
  993.     switch(operation)
  994.       {
  995.    case SAVE: if( op_code == 1)
  996.                 {
  997.                   WindowToFront(FirstWindow);   
  998.                   SaveIt(file);
  999.                 }
  1000.               if( op_code == 2)
  1001.                 {
  1002.                   SaveParms(file);
  1003.                 }  
  1004.                break;      
  1005.          
  1006.     case LOAD: if( op_code == 3)
  1007.                 {
  1008.                   LoadIt(file, MAK_PIC);
  1009.                 }
  1010.    
  1011.               if( op_code == 4)
  1012.                 {
  1013.                   LoadParms(file);
  1014.                 }
  1015.     
  1016.                break;
  1017.            
  1018.     case CANCEL:
  1019.     
  1020.                  break;
  1021.              
  1022.     case QUIT: 
  1023.     
  1024.                break;
  1025.            
  1026.     case PANIC:
  1027.     
  1028.                 break;
  1029.       }
  1030.  
  1031.  
  1032.     do_Pointer(FirstWindow);
  1033.     ClearPointer(file_window);
  1034.     SetPointer(file_window,Pointer,16,16,0,0);
  1035.  
  1036.     if(op_code == 1 || op_code == 2)
  1037.     {
  1038.       OnGadget(&gadget_load,file_window,NULL);
  1039.       OnGadget(&gadget_delete,file_window,NULL);
  1040.     }
  1041.     
  1042.     if(op_code == 3 || op_code == 4)
  1043.     {
  1044.       OnGadget(&gadget_save,file_window,NULL);
  1045.       OnGadget(&gadget_delete,file_window,NULL);
  1046.     }
  1047.     
  1048.     if(op_code == 5 || op_code == 6)
  1049.     {
  1050.       OnGadget(&gadget_save,file_window,NULL);
  1051.       OnGadget(&gadget_load,file_window,NULL);
  1052.     } 
  1053.     
  1054.     if(file_window)
  1055.     CloseWindow(file_window);
  1056.         
  1057.     return(TRUE);
  1058.  
  1059.   } /**** Close off file_manager ****/
  1060.   
  1061.   
  1062.  
  1063. USHORT File_Man( title, extension, x, y, total_file_name, op_code )
  1064. STRPTR title;
  1065. STRPTR extension;
  1066. SHORT  x, y;
  1067. STRPTR total_file_name;
  1068. SHORT op_code;
  1069. {
  1070.   int temp1;
  1071.   int file_count;
  1072.  
  1073.   ULONG class; 
  1074.   USHORT code; 
  1075.   APTR address;
  1076.  
  1077.   int position;
  1078.  
  1079.   BOOL working;     
  1080.   BOOL fix_display;
  1081.  
  1082.   STRPTR string_pointer; 
  1083.   struct file_info *pointer;
  1084.  
  1085.   USHORT operation; 
  1086.   
  1087.  
  1088.   file_lock=FALSE; 
  1089.   more_files=FALSE; 
  1090.  
  1091.  
  1092.   
  1093.   prop_info.VertBody=0xFFFF;
  1094.   prop_info.HorizBody=0;
  1095.   prop_info.VertPot=0;
  1096.   prop_info.HorizPot=0;
  1097.   
  1098.  
  1099.   strcpy(extension_name, extension);
  1100.  
  1101.  
  1102.   if(*extension_name != '\0')
  1103.     text_extension.FrontPen=3; 
  1104.   else
  1105.     text_extension.FrontPen=1;
  1106.  
  1107.  
  1108.  
  1109.   new_file_window.LeftEdge=x;
  1110.   new_file_window.TopEdge=y;
  1111.   new_file_window.Title=title;
  1112.   new_file_window.Screen=FirstScreen;  
  1113.   
  1114.   if((file_window=(struct Window *)OpenWindow(&new_file_window)) == NULL)
  1115.   {
  1116.    
  1117.     return(PANIC);
  1118.   }
  1119.    DrawBorder(file_window->RPort, &border_big_box, 0, 0);
  1120.    ClearPointer(file_window);
  1121.    SetPointer(file_window,Pointer,16,16,0,0);
  1122.  
  1123.   
  1124.   if((file_info=(struct FileInfoBlock *)
  1125.     AllocMem(sizeof(struct FileInfoBlock), MEMF_PUBLIC|MEMF_CLEAR))==NULL)
  1126.   {
  1127.     /* Could not allocate memory for the FileInfoBlock! */
  1128.     /* Inform the user about the problem, and leave. */
  1129.     request_ok("NOT enough memory!");
  1130.     return(PANIC);
  1131.   }
  1132.  
  1133.   if(op_code == 1 || op_code == 2)
  1134.     {
  1135.       OffGadget(&gadget_load,file_window,NULL);
  1136.       OffGadget(&gadget_delete,file_window,NULL);
  1137.     }
  1138.     
  1139.   if(op_code == 3 || op_code == 4)
  1140.     {
  1141.       OffGadget(&gadget_save,file_window,NULL);
  1142.       OffGadget(&gadget_delete,file_window,NULL);
  1143.     }
  1144.     
  1145.   if(op_code == 5 || op_code == 6)
  1146.     {
  1147.       OffGadget(&gadget_save,file_window,NULL);
  1148.       OffGadget(&gadget_load,file_window,NULL);
  1149.     } 
  1150.     
  1151.   if(*total_file_name != '\0')
  1152.   {
  1153.     
  1154.     if((lock=Lock(total_file_name, ACCESS_READ))==NULL)
  1155.     {
  1156.       /* If it falls through to this there are problems */
  1157.       /* File/directory/device did NOT exist! */
  1158.     }
  1159.     else
  1160.     {
  1161.       
  1162.       file_lock=TRUE;
  1163.   
  1164.       if((Examine(lock, file_info))==NULL)
  1165.       {
  1166.        
  1167.         request_ok("ERROR reading file/directory!");
  1168.       }
  1169.       else
  1170.       {
  1171.         
  1172.         if(directory(file_info))
  1173.         {
  1174.           /* It is a directory! */
  1175.  
  1176.           *file_name='\0'; /* Clear file_name string. */
  1177.           /* Copy total_file_name into drawer_name string: */
  1178.           strcpy(drawer_name, total_file_name);
  1179.  
  1180.           /* Since it is a directory, we will look for more files: */
  1181.           more_files=TRUE;
  1182.         }
  1183.         else
  1184.         {
  1185.           /* It is a file! */
  1186.           
  1187.           /* Separate the file name from the path: */
  1188.           if(string_pointer=right_pos(total_file_name, '/'))
  1189.           {
  1190.             /* Copy the file name into file_name string: */
  1191.             strcpy(file_name, string_pointer+1);
  1192.             *string_pointer='\0';
  1193.           }
  1194.           else
  1195.           {
  1196.             if(string_pointer=right_pos(total_file_name, ':'))
  1197.             {
  1198.               /* Copy the file name into file_name string: */
  1199.               strcpy(file_name, string_pointer+1);
  1200.               *(string_pointer+1)='\0';
  1201.             }
  1202.             else
  1203.             {
  1204.               strcpy(file_name, total_file_name);        
  1205.               *drawer_name='\0';
  1206.               *total_file_name='\0';
  1207.             }
  1208.           }
  1209.           strcpy(drawer_name, total_file_name);
  1210.          
  1211.  
  1212.         } /* directory? */
  1213.  
  1214.       } /* examine object */
  1215.  
  1216.     } /* "lock" file/directory? */
  1217.  
  1218.   } /* Anything in total_file_name string? */
  1219.  
  1220.   adjust_string_gadgets();
  1221.  
  1222.  
  1223.   new_drawer(); 
  1224.  
  1225.   position=0;       
  1226.   fix_display=FALSE;
  1227.   first_file=TRUE;  
  1228.   file_count=0;    
  1229.  
  1230.  
  1231.   working=TRUE;
  1232.   do
  1233.   {
  1234.    
  1235.     if(more_files==FALSE)
  1236.       Wait(1 << file_window->UserPort->mp_SigBit);
  1237.  
  1238.     while(my_gadget_message = (struct IntuiMessage *)
  1239.       GetMsg(file_window->UserPort))
  1240.     {
  1241.       class = my_gadget_message->Class;
  1242.       code = my_gadget_message->Code;
  1243.       address = my_gadget_message->IAddress;
  1244.  
  1245.       ReplyMsg((struct Message *)my_gadget_message);
  1246.  
  1247.       switch(class)
  1248.       {
  1249.         case MOUSEMOVE:
  1250.          
  1251.           fix_display=TRUE;
  1252.           break;
  1253.  
  1254.         case CLOSEWINDOW:
  1255.          
  1256.           connect_dir_file(total_file_name);
  1257.           working=FALSE;
  1258.           operation=QUIT;
  1259.           break;
  1260.  
  1261.         case GADGETDOWN:
  1262.            
  1263.            for(temp1=0; temp1 < 8; temp1++)
  1264.            {
  1265.              if(address == (APTR)&gadget_display[temp1])
  1266.              {
  1267.               
  1268.                pick_file(temp1+position);
  1269.              }
  1270.            }
  1271.            break;
  1272.  
  1273.  
  1274.  
  1275.         case GADGETUP:
  1276.           
  1277.            if(address == (APTR)&gadget_load)
  1278.            {
  1279.              if(last_check(total_file_name))
  1280.              {
  1281.                working=FALSE;
  1282.                operation=LOAD;
  1283.              }
  1284.              break;
  1285.            }
  1286.  
  1287.  
  1288.            /* SAVE */
  1289.            if(address == (APTR)&gadget_save)
  1290.            {
  1291.              if(last_check(total_file_name))
  1292.              {
  1293.                working=FALSE;
  1294.                operation=SAVE;
  1295.              }
  1296.              break;
  1297.            }
  1298.  
  1299.  
  1300.            /* DELETE */
  1301.            if(address == (APTR)&gadget_delete)
  1302.            {
  1303.              delete_file_dir(total_file_name);
  1304.              break;
  1305.            }
  1306.  
  1307.  
  1308.            /* CANCEL */
  1309.            if(address == (APTR)&gadget_cancel)
  1310.            {
  1311.              connect_dir_file(total_file_name);
  1312.              working=FALSE;
  1313.              operation=CANCEL;
  1314.              break;
  1315.            }
  1316.  
  1317.  
  1318.            /* df0: */
  1319.            if(address == (APTR)&gadget_df0)
  1320.            {
  1321.              change_device("df0:");
  1322.              break;
  1323.            }
  1324.  
  1325.  
  1326.            /* df1: */
  1327.            if(address == (APTR)&gadget_df1)
  1328.            {
  1329.              change_device("df1:");
  1330.              break;
  1331.            }
  1332.  
  1333.  
  1334.            /* dh0: */
  1335.            if(address == (APTR)&gadget_dh0)
  1336.            {
  1337.              change_device("dh0:");
  1338.              break;
  1339.            }
  1340.  
  1341.  
  1342.            /* DRAWER: */
  1343.            if(address == (APTR)&gadget_drawer)
  1344.            {
  1345.              new_drawer();
  1346.              break;
  1347.            }
  1348.  
  1349.  
  1350.            /* EXTENSION: */
  1351.            if(address == (APTR)&gadget_extension)
  1352.            {
  1353.             
  1354.              if(*extension_name != '\0')
  1355.                text_extension.FrontPen=3; 
  1356.              else
  1357.                text_extension.FrontPen=1; 
  1358.  
  1359.              RefreshGadgets(&gadget_extension, file_window, NULL);
  1360.              new_drawer();
  1361.              break;
  1362.            }
  1363.  
  1364.  
  1365.            /* PARENT: "<" */
  1366.            if(address == (APTR)&gadget_parent)
  1367.            {
  1368.              parent();
  1369.              break;
  1370.            }
  1371.  
  1372.  
  1373.            /* PROPORTIONAL */
  1374.            if(address == (APTR)&gadget_proportional)
  1375.            {
  1376.              fix_display=TRUE;
  1377.              break;
  1378.            }
  1379.       }
  1380.     }
  1381.  
  1382.     if(fix_display)
  1383.     {
  1384.       fix_display=FALSE;
  1385.       if(file_count > 8)
  1386.         position=(int) prop_info.VertPot/(float) 0xFFFF*(file_count-8);
  1387.       else
  1388.         position=0;
  1389.       display_list(position);
  1390.     }
  1391.  
  1392.  
  1393.     if(more_files)
  1394.     {   
  1395.       if(ExNext(lock, file_info))
  1396.       {
  1397.        
  1398.         if(stricmp(extension_name, (file_info->fib_FileName+
  1399.            strlen(file_info->fib_FileName)-strlen(extension_name)))==0 ||
  1400.            directory(file_info) )
  1401.         {
  1402.           if(first_file)
  1403.           {
  1404.             first_pointer=(struct file_info *) save_file_info(file_info);
  1405.             
  1406.             if(first_pointer != NULL)
  1407.             { 
  1408.               first_pointer->next=NULL; 
  1409.               first_file=FALSE;
  1410.             }
  1411.             file_count=1;
  1412.             position=1;
  1413.           }
  1414.           else
  1415.           {
  1416.            pointer=(struct file_info *) save_file_info(file_info);
  1417.            
  1418.             if(pointer !=NULL)
  1419.             {
  1420.               put_in(first_pointer, pointer);       
  1421.               file_count++;
  1422.             }
  1423.           }
  1424.         
  1425.           if(file_count > 8)
  1426.           {
  1427.             ModifyProp
  1428.             (
  1429.               &gadget_proportional,      
  1430.               file_window,              
  1431.               NULL,                     
  1432.               prop_info.Flags,          
  1433.               0,                        
  1434.               prop_info.VertPot,        
  1435.               0,                         
  1436.               (ULONG) 0xFFFF*8/file_count
  1437.             );            
  1438.             position=(int) prop_info.VertPot/(float) 0xFFFF*(file_count-8);
  1439.           }
  1440.           else
  1441.            position=0;
  1442.           display_list(position);
  1443.         }
  1444.       }
  1445.       else
  1446.       {       
  1447.         more_files=FALSE; 
  1448.         if(IoErr() != ERROR_NO_MORE_ENTRIES)
  1449.     {
  1450.           request_ok("ERROR reading file/directory!");
  1451.         }
  1452.       }
  1453.     }
  1454.   } while(working);
  1455.  
  1456.   while( (my_gadget_message = (struct IntuiMessage *)
  1457.            GetMsg(file_window->UserPort)) )
  1458.   {
  1459.     ReplyMsg((struct Message *)my_gadget_message);
  1460.   }
  1461.  
  1462.   deallocate_file_info();
  1463.  
  1464.   if(file_lock)
  1465.   {
  1466.     UnLock(lock);
  1467.     file_lock=FALSE;
  1468.   }
  1469.   
  1470.   if(file_info) FreeMem(file_info, sizeof(struct FileInfoBlock));
  1471.  
  1472.   
  1473.   
  1474.   return(operation);
  1475. }
  1476.  
  1477. void deallocate_file_info()
  1478. {
  1479.   struct file_info *pointer, *temp_pointer;
  1480.    
  1481.   if(first_pointer)
  1482.   {
  1483.     pointer=first_pointer->next;
  1484.     
  1485.     FreeMem( first_pointer, sizeof(struct file_info));
  1486.  
  1487.     while(pointer)
  1488.     {    
  1489.       temp_pointer=pointer->next;
  1490.       
  1491.       FreeMem( pointer, sizeof(struct file_info));
  1492.       pointer=temp_pointer;
  1493.     }
  1494.   }
  1495.   
  1496.   first_pointer=NULL;
  1497.  
  1498.   first_file=TRUE;
  1499. }
  1500.  
  1501. APTR save_file_info(info)
  1502. struct FileInfoBlock *info;
  1503. {
  1504.   struct file_info *pointer;
  1505.  
  1506.   if((pointer=(struct file_info *)
  1507.     AllocMem(sizeof(struct file_info), MEMF_PUBLIC|MEMF_CLEAR))==NULL)
  1508.   {
  1509.     request_ok("NOT enough memory!"); 
  1510.     more_files=FALSE;
  1511.     return(NULL);
  1512.   }
  1513.   else
  1514.   {
  1515.     if(strlen(info->fib_FileName) < 28)
  1516.       strcpy(pointer->name, info->fib_FileName);
  1517.     else
  1518.     {
  1519.       if( directory(info))
  1520.         request_ok("Directory name too long!");
  1521.       else    
  1522.         request_ok("File name too long!"); 
  1523.  
  1524.       FreeMem( pointer, sizeof(struct file_info));
  1525.       return(NULL);
  1526.     }
  1527.  
  1528.     if( directory(info))
  1529.       pointer->directory=TRUE; /* It is a directory. */
  1530.     else    
  1531.       pointer->directory=FALSE; /* It is a file. */
  1532.   }
  1533.   
  1534.   return( (APTR) pointer);
  1535. }
  1536.  
  1537. BOOL directory(info)
  1538. struct FileInfoBlock *info;
  1539. {
  1540.   if(info->fib_DirEntryType < 0)
  1541.     return(FALSE);
  1542.   else
  1543.     return(TRUE);
  1544. }
  1545.  
  1546. void put_in(a_pointer, pointer)
  1547. struct file_info *a_pointer, *pointer;
  1548. {
  1549.   struct file_info *old_pointer=NULL;
  1550.  
  1551.   while( a_pointer && file_comp(a_pointer->name, pointer->name) )
  1552.   {
  1553.     old_pointer=a_pointer;
  1554.     a_pointer=a_pointer->next;
  1555.   }
  1556.  
  1557.   if(a_pointer)
  1558.   {
  1559.     if(old_pointer)
  1560.     {
  1561.       pointer->next=old_pointer->next;
  1562.       old_pointer->next=pointer;
  1563.     }
  1564.     else
  1565.     {
  1566.       pointer->next=first_pointer;
  1567.       first_pointer=pointer;
  1568.     }
  1569.   }
  1570.   else
  1571.   {
  1572.     old_pointer->next=pointer;
  1573.     pointer->next=NULL;
  1574.   }
  1575. }
  1576.  
  1577. BOOL file_comp(a_pointer, pointer)
  1578. struct file_info *a_pointer, *pointer;
  1579. {
  1580.   if(a_pointer->directory == FALSE && pointer->directory)
  1581.     return(FALSE);
  1582.     
  1583.   if(a_pointer->directory == pointer->directory)
  1584.   {
  1585.     if(stricmp(a_pointer->name, pointer->name) <= 0 )
  1586.       return(TRUE);
  1587.     else
  1588.       return(FALSE);
  1589.   } 
  1590.   return(TRUE);
  1591. }
  1592.  
  1593. STRPTR right_pos(string, sign)
  1594. STRPTR string;
  1595. char sign;
  1596. {
  1597.   STRPTR start_pos;
  1598.   
  1599.   start_pos=string;
  1600.   
  1601.   while(*string != '\0')
  1602.     string++;
  1603.  
  1604.   while(*string != sign && string > start_pos)
  1605.     string--;
  1606.     
  1607.   if(*string==sign)
  1608.     return(string);
  1609.  
  1610.   return(NULL);
  1611. }
  1612.  
  1613. void change_device(device)
  1614. STRPTR device;
  1615. {
  1616.   strcpy(drawer_name, device);
  1617.  
  1618.   adjust_string_gadgets(); 
  1619.  
  1620.   new_drawer();
  1621. }
  1622.  
  1623. BOOL new_drawer()
  1624. {
  1625.   STRPTR string_pointer;
  1626.  
  1627.   /* Unlock: */
  1628.   if(file_lock)
  1629.   {
  1630.     UnLock(lock);
  1631.     file_lock=FALSE;
  1632.   }
  1633.    
  1634.   deallocate_file_info();
  1635.  
  1636.   ModifyProp
  1637.   (
  1638.     &gadget_proportional, 
  1639.     file_window,         
  1640.     NULL,               
  1641.     prop_info.Flags,   
  1642.     0,                  
  1643.     0,                  
  1644.     0,                   
  1645.     (ULONG) 0xFFFF     
  1646.   );
  1647.  
  1648.   display_list(0);
  1649.  
  1650.   more_files=FALSE;
  1651.  
  1652.   if((lock=Lock(drawer_name, ACCESS_READ))==NULL)
  1653.   {
  1654.     string_pointer=drawer_name+strlen(drawer_name)-1;
  1655.     if(*string_pointer==':')
  1656.       request_ok("Device NOT found!");
  1657.     else
  1658.       request_ok("Device/Directory NOT found!");
  1659.  
  1660.     return(FALSE); /* ERROR */
  1661.   }
  1662.   else
  1663.   {
  1664.     file_lock=TRUE;
  1665.   }
  1666.  
  1667.   if((Examine(lock, file_info))==NULL)
  1668.   {
  1669.     request_ok("ERROR reading file/directory!"); 
  1670.  
  1671.     return(FALSE); 
  1672.   }
  1673.  
  1674.   if(directory(file_info))
  1675.   {
  1676.     more_files=TRUE;
  1677.   }
  1678.   else
  1679.   {
  1680.     request_ok("NOT a valid directory name!"); 
  1681.     return(FALSE);
  1682.   }  
  1683.   return(TRUE);
  1684. }
  1685.  
  1686. void parent()
  1687. {
  1688.   STRPTR string_pointer;
  1689.  
  1690.   if(string_pointer=right_pos(drawer_name, '/'))
  1691.   {
  1692.     *string_pointer='\0';
  1693.   }
  1694.   else
  1695.   {
  1696.     if(string_pointer=right_pos(drawer_name, ':'))
  1697.     {
  1698.       *(string_pointer+1)='\0';
  1699.     }
  1700.     else
  1701.     {
  1702.       *drawer_name='\0';
  1703.     }
  1704.   }
  1705.   
  1706.   adjust_string_gadgets();
  1707.   
  1708.  
  1709.   new_drawer();
  1710. }
  1711.  
  1712. void request_ok(message)
  1713. STRPTR message;
  1714. {
  1715.   text_request.IText=message;
  1716.   
  1717.   AutoRequest
  1718.   (
  1719.     file_window,  
  1720.     &text_request,
  1721.     NULL,        
  1722.     &ok_request, 
  1723.     NULL,         
  1724.     NULL,        
  1725.     320,        
  1726.     72         
  1727.   );
  1728. }
  1729.  
  1730. BOOL request_ask(message, option1, option2)
  1731. STRPTR message, option1, option2;
  1732. {
  1733.   text_request.IText=message;
  1734.   option1_request.IText=option1;
  1735.   option2_request.IText=option2;
  1736.   
  1737.   
  1738.   return( (BOOL) AutoRequest
  1739.   (
  1740.     file_window,     
  1741.     &text_request,   
  1742.     &option1_request, 
  1743.     &option2_request, 
  1744.     NULL,             
  1745.     NULL,           
  1746.     320,            
  1747.     72         
  1748.   ));
  1749. }
  1750.  
  1751. void display_list(start_pos)
  1752. int start_pos;
  1753. {
  1754.   struct file_info *pointer;
  1755.   int pos, temp1;
  1756.   char empty_name[]= "                                 ";
  1757.   
  1758.   STRPTR string_pointer;
  1759.   BOOL clear;
  1760.   
  1761.   pos=0;
  1762.  
  1763.   if(first_pointer)
  1764.   {
  1765.     pointer=first_pointer;
  1766.  
  1767.     while(pointer && pos < start_pos)
  1768.     {
  1769.       pos++;
  1770.       pointer=pointer->next;
  1771.     }
  1772.     
  1773.     pos=0;
  1774.     while(pointer && pos < 8)
  1775.     {
  1776.       strcpy(display_text[pos], pointer->name);
  1777.       
  1778.       clear=FALSE;
  1779.       temp1=0;
  1780.       string_pointer=display_text[pos];
  1781.  
  1782.       if(pointer->directory)
  1783.       {
  1784.         text_list[pos].FrontPen=3; 
  1785.         while(temp1á< 28)
  1786.         {
  1787.           if(*string_pointer=='\0')
  1788.             clear=TRUE;
  1789.           if(clear)
  1790.             *string_pointer=' ';
  1791.           string_pointer++;
  1792.           temp1++;
  1793.         }
  1794.         *string_pointer='\0';
  1795.         strcat(display_text[pos], "(Dir)");
  1796.       }
  1797.       else
  1798.       {
  1799.         text_list[pos].FrontPen=1;
  1800.         while(temp1á< 33)
  1801.         {
  1802.           if(*string_pointer=='\0')
  1803.             clear=TRUE;
  1804.           if(clear)
  1805.             *string_pointer=' ';
  1806.           string_pointer++;
  1807.           temp1++;
  1808.         }
  1809.         *string_pointer='\0';
  1810.       }      
  1811.       pos++;
  1812.       pointer=pointer->next; 
  1813.     }
  1814.   }
  1815.  
  1816.   while(pos < 8)
  1817.   {
  1818.     strcpy(display_text[pos], empty_name);
  1819.     pos++;
  1820.   }
  1821.   
  1822.   PrintIText(file_window->RPort, text_list, 13+3, 53+1);
  1823. }
  1824.  
  1825. BOOL pick_file(file_pos)
  1826. int file_pos;
  1827. {
  1828.   struct file_info *pointer=NULL;
  1829.   STRPTR string_pointer;
  1830.   int pos=0;
  1831.   
  1832.   if(first_pointer)
  1833.   {
  1834.     pointer=first_pointer;
  1835.     
  1836.     while(pointer && pos < file_pos)
  1837.     {
  1838.       pos++;
  1839.       pointer=pointer->next;
  1840.     }
  1841.   }
  1842.  
  1843.   if(pointer)
  1844.   {
  1845.     if(pointer->directory)
  1846.     {
  1847.       if((strlen(pointer->name)+strlen(drawer_name)+2) <= DRAWER_LENGTH)
  1848.       {
  1849.         string_pointer=drawer_name+strlen(drawer_name)-1;
  1850.         if(*string_pointer==':'  || *string_pointer=='\0' )
  1851.           strcat(drawer_name, pointer->name);
  1852.         else
  1853.         {
  1854.           strcat(drawer_name, "/");
  1855.           strcat(drawer_name, pointer->name);
  1856.         }
  1857.    
  1858.         adjust_string_gadgets();
  1859.       }
  1860.       else
  1861.       {
  1862.         request_ok("Too long drawer string");
  1863.         return(FALSE); 
  1864.       }
  1865.       new_drawer();
  1866.       return(TRUE);
  1867.     }
  1868.     else
  1869.     {
  1870.       if((strlen(pointer->name)+1) <= FILE_LENGTH)
  1871.       {
  1872.         strcpy(file_name, pointer->name);
  1873.         adjust_string_gadgets();
  1874.       }
  1875.       else
  1876.       {
  1877.      
  1878.         request_ok("File name too long!"); 
  1879.         return(FALSE);
  1880.       }
  1881.       return(TRUE);
  1882.     }
  1883.   }
  1884. }
  1885.  
  1886. void adjust_string_gadgets()
  1887. {
  1888.   int length;
  1889.  
  1890.   length=strlen(file_name);        
  1891.  
  1892.   if(length > 28)
  1893.     string_file.DispPos=length-28;
  1894.   else
  1895.     string_file.DispPos=0;
  1896.  
  1897.   string_file.BufferPos=string_file.DispPos;
  1898.   
  1899.  
  1900.   length=strlen(drawer_name);        
  1901.  
  1902.   if(length > 22)
  1903.     string_drawer.DispPos=length-22;
  1904.   else
  1905.     string_drawer.DispPos=0;
  1906.  
  1907.   string_drawer.BufferPos=string_drawer.DispPos;
  1908.  
  1909.   RefreshGadgets(&gadget_file, file_window, NULL);
  1910. }
  1911.  
  1912. BOOL last_check(name)
  1913. STRPTR name;
  1914. {
  1915.   if(*file_name == '\0')
  1916.   {
  1917.     request_ok("NO filename selected!");
  1918.     return(FALSE);
  1919.   }
  1920.   else
  1921.   {
  1922.     connect_dir_file(name);
  1923.   }
  1924.   return(TRUE);
  1925. }
  1926.  
  1927. void connect_dir_file(name)
  1928. STRPTR name;
  1929. {
  1930.   STRPTR string_pointer;
  1931.          
  1932.   strcpy(name, drawer_name);
  1933.  
  1934.   if(*file_name != '\0')
  1935.   {
  1936.     string_pointer=drawer_name+strlen(drawer_name)-1;
  1937.     if(*string_pointer==':'  || *string_pointer=='\0' )
  1938.     {
  1939.       strcat(name, file_name); 
  1940.     }
  1941.     else
  1942.     {
  1943.       strcat(name, "/"); 
  1944.       strcat(name, file_name);
  1945.     }
  1946.   }
  1947. }
  1948.  
  1949. void delete_file_dir(total_file_name)
  1950. STRPTR total_file_name;
  1951. {
  1952.   BOOL delete_it;
  1953.  
  1954.   delete_it=FALSE;
  1955.   
  1956.   if(*file_name == '\0' && *drawer_name != '\0')
  1957.   {
  1958.    
  1959.     if( *(drawer_name+strlen(drawer_name)-1) ==':')
  1960.     {
  1961.       request_ok("You can NOT delete a device!");
  1962.     }
  1963.     else
  1964.     {
  1965.       delete_it=request_ask("OK to delete directory?","DELETE","CANCEL");
  1966.                    
  1967.       if(delete_it)
  1968.       {
  1969.         if(file_lock)
  1970.         {
  1971.           UnLock(lock);
  1972.           file_lock=FALSE;
  1973.         }
  1974.       }
  1975.     }
  1976.   }
  1977.   else
  1978.   {
  1979.     if(*file_name != '\0')
  1980.     {
  1981.       delete_it=request_ask("OK to delete file?","DELETE","CANCEL");
  1982.     }
  1983.     else
  1984.     {
  1985.       request_ok("NO file/directory selected!");
  1986.     }
  1987.   }
  1988.   
  1989.   if(delete_it)
  1990.   {
  1991.     connect_dir_file(total_file_name);
  1992.   
  1993.     if(DeleteFile(total_file_name))
  1994.     {
  1995.      if(*file_name != '\0')
  1996.       {
  1997.         *file_name='\0'; 
  1998.         adjust_string_gadgets();
  1999.         new_drawer(); 
  2000.       }
  2001.       else
  2002.       {
  2003.         parent(); 
  2004.       }
  2005.     }
  2006.     else
  2007.     {
  2008.       if(*file_name != '\0')
  2009.         request_ok("Could NOT delete the file!");
  2010.       else
  2011.         request_ok("Could NOT delete directory!");
  2012.       new_drawer();
  2013.     }
  2014.   }
  2015. }
  2016.  
  2017.  
  2018.