home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 400-499 / ff464.lzh / FileWindow / FileWindow2.c < prev    next >
C/C++ Source or Header  |  1991-03-09  |  60KB  |  1,843 lines

  1. /**********************************************************************/
  2. /*      FileWindow2              A.Bjerin/B.Schied          (FF336)   */
  3. /*                                                                    */
  4. /**********************************************************************/
  5.  
  6. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  7.        operation = FileWindow2(title, ext, x, y, my_screen, file);
  8.        operation:      USHORT operation;
  9.        title    :      UBYTE  title[ANY_LENGTH];
  10.        ext      :      UBYTE  ext[7];
  11.        x, y     :      SHORT  x, y;
  12.        my_screen:      struct Screen *my_screen;
  13.        file     :      UBYTE  file[TOTAL_LENGTH];
  14. ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  15.  
  16. #include <proto/all.h>
  17. #include <string.h>
  18. #include <exec/types.h>
  19. #include <exec/nodes.h>
  20. #include <exec/lists.h>
  21. #include <exec/libraries.h>
  22. #include <exec/ports.h>
  23. #include <exec/interrupts.h>
  24. #include <exec/io.h>
  25. #include <exec/memory.h>
  26. #include <libraries/dos.h>
  27. #include <libraries/dosextens.h>
  28.  
  29. #define  CLEAR           0
  30. #define  TAKE          500      /*    FileWindow2() return value    */
  31. #define  RENAME        600
  32. #define  DELETE        700
  33. #define  ABORT         900      /*    FileWindow2() return value    */
  34. #define  PANIC        1000      /*    FileWindow2() return value    */
  35.                                 /* The minimum size of the strings: */
  36. #define  DRAWER_LENGTH  100     /*    100 characters including NULL */
  37. #define  FILE_LENGTH     30     /*     30 characters including NULL */
  38. #define  TOTAL_LENGTH   130     /*    130 characters including NULL */
  39.  
  40. struct   Window            *file_window;
  41. struct   IntuiMessage      *my_gadget_message;
  42. struct   FileInfoBlock     *file_info;
  43. BPTR     lock;
  44.  
  45. USHORT  FileWindow2(STRPTR,STRPTR,int,int,struct Screen *,STRPTR);
  46. USHORT  clear_gadgets(STRPTR);
  47. STRPTR  right_pos(STRPTR, char);
  48. APTR    save_file_info(struct FileInfoBlock *);
  49. BOOL    file_comp(struct file_info *, struct file_info *);
  50. BOOL    directory(struct FileInfoBlock *);
  51. BOOL    pick_file(int),   new_drawer(void),   last_check(STRPTR);
  52. void    put_in(struct file_info *, struct file_info *);
  53. void    change_device(STRPTR),             parent(void);
  54. void    request_ok(STRPTR),                request_ask(STRPTR);
  55. void    display_list(int),                 adjust_string_gadgets(void);
  56. void    connect_dir_file(STRPTR),          delete_file_dir(STRPTR);
  57. void    rename_file_dir(STRPTR),           deallocate_file_info(void);
  58. STRPTR  right_pos(STRPTR, char);
  59. BPTR    Lock(char *, long);
  60.  
  61.  
  62. BOOL    file_lock,        first_file,      more_files;
  63. USHORT  ren=0;                               /* Rename-Flag = 0,1,2,3 */
  64. USHORT  gadget_flag=CLEAR;                   /* Gadget selected ? */
  65. STRPTR  total_file_name1;
  66. UBYTE   total_file[TOTAL_LENGTH],   display_text[8][34];
  67. UBYTE   file_name[FILE_LENGTH],     extension_name[7];
  68. UBYTE   name_backup[DRAWER_LENGTH];  /* UndoBuffer for string gadgets: */
  69. UBYTE   drawer_name[DRAWER_LENGTH];
  70. UBYTE   *errors[]=
  71.         {
  72.            " OKAY = delete dir       ABORT = abort ",  /*  0 */
  73.            " OKAY = delete file      ABORT = abort ",  /*  1 */
  74.            " 1.type new dir name      2.OKAY/ABORT ",  /*  2 */
  75.            " 1.type new file name     2.OKAY/ABORT ",  /*  3 */
  76.            "NOT enough memory available !",            /*  4 */
  77.            "File name is too long!",                   /*  5 */
  78.            "Device NOT found!",                        /*  6 */
  79.            "Directory NOT found!",                     /*  7 */
  80.            "NO item has been selected!",               /*  8 */
  81.            "You can NOT delete a device!",             /*  9 */
  82.            "You can NOT rename a device!",             /* 10 */
  83.            "Could NOT delete this file!",              /* 11 */
  84.            "Could NOT delete this directory!",         /* 12 */
  85.            "Could NOT rename this file!",              /* 13 */
  86.            "Could NOT rename this directory!",         /* 14 */
  87.            "NOT a valid directory name!",              /* 15 */
  88.            "Drawer string is too long",                /* 16 */
  89.            "Directory name is too long!",              /* 17 */
  90.            "ERROR reading file/directory!",            /* 18 */
  91.         };
  92.  
  93. /* We will allocate memory, using this structure, for every file/     */
  94. /* directory we find. They will be linked to each otherer, in such a  */
  95. /* way that all directories will come first (sorted alphabetically),  */
  96. /* and after them will the files come (also sorted alphabetically).   */
  97. struct file_info
  98. {
  99.    BYTE name[28];           /* Name of the file/directory, 27 chars   */
  100.    BOOL directory;          /* If it is a directory.                  */
  101.    struct file_info *next;  /* Pointer to the next file_info structur */
  102. };
  103. struct  file_info         *first_pointer;
  104.  
  105.  
  106. /*   The program will use a ROM-font, 80 characters wide (40 LOWRES). */
  107. /*   This is to make sure that all the text will fit in nicely in the */
  108. /*   window, even if the calling program is using another font.       */
  109. struct TextAttr my_font=
  110. {
  111.    "topaz.font",                              /* Font Name            */
  112.    TOPAZ_EIGHTY,                              /* Font Height          */
  113.    FS_NORMAL,                                 /* Style                */
  114.    FPF_ROMFONT                                /* Preferences          */
  115. };
  116.  
  117. /*
  118.   extern struct GfxBase       *GfxBase=NULL;
  119.   extern struct IntuitionBase *IntuitionBase;
  120. */
  121. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  122. /*   IntuiText structures for the requesters                          */
  123. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  124. struct IntuiText text_request=
  125. {
  126.   3, 2,                        /* FrontPen, BackPen */
  127.   JAM1,                        /* DrawMode */
  128.   15, 15,                      /* LewftEdge, TopEdge */
  129.   &my_font,                    /* *ITextFont */
  130.   NULL,                        /* *IText */
  131.   NULL                         /* *NextText */
  132. };
  133.  
  134. struct IntuiText ok_request=
  135. {
  136.   3, 2,
  137.   JAM2,
  138.   6, 3,
  139.   &my_font,
  140. "         C O N T I N U E        ",
  141.   NULL
  142. };
  143.  
  144. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  145. SHORT points4[]=               /* Values for a 4-letter box: */
  146. {
  147.    0,  0,
  148.   44,  0,
  149.   44, 14,
  150.    0, 14,
  151.    0,  0
  152. };
  153. SHORT points6[]=               /* Values for a 6-letter box: */
  154. {
  155.    0, 0,
  156.   52, 0,
  157.   52,10,
  158.    0,10,
  159.    0, 0
  160. };
  161. SHORT points9b []=             /* Values for a 9-letter box: */
  162. {
  163.    0,  0,
  164.   76,  0,
  165.   76, 11,
  166.    0, 11,
  167.    0,  0
  168. };
  169. SHORT points9[]=               /* Values for a 9-letter box: */
  170. {
  171.    0,  0,
  172.   80,  0,
  173.   80, 15,
  174.    0, 15,
  175.    0,  0
  176. };
  177. struct Border border_text4=    /* A border for a 4-letter box: */
  178. {
  179.   0, 0,                        /* LeftEdge, TopEdge */
  180.   1, 2, JAM1,                  /* FrontPen, BackPen, DrawMode */
  181.   5,                           /* Count */
  182.   points4,                     /* *XY */
  183.   NULL                         /* *NextBorder */
  184. };
  185. struct Border border_text6=    /* A border for a 6-letter box: */
  186. {
  187.   -2,-2,
  188.   1, 0, JAM2,
  189.   5,         
  190.   points6,   
  191.   NULL       
  192. };
  193. struct Border border_text9b=   /* An inner border for 9-letter box: */
  194. {
  195.   0, 0,      
  196.   3, 0, JAM1,
  197.   5,         
  198.   points9b,  
  199.   NULL       
  200. };
  201. struct Border border_text9=    /* A outer border for a 9-letter box: */
  202. {
  203.  -2, -2,     
  204.   3, 0, JAM1,
  205.   5,         
  206.   points9,   
  207.   &border_text9b
  208. };
  209.  
  210. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  211. /*   Information for the proportional gadget                          */
  212. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  213. /*
  214.   Since we are using the auto-knob we set GadgetRender to point to an
  215.   Image. In this case we do not need to initialize the Image structure:
  216. */
  217. struct Image image_prop;
  218. struct PropInfo prop_info=
  219. {
  220.   AUTOKNOB|          /* We want to use the auto-knob. */
  221.   FREEVERT,          /* The knob should move vertically. */
  222.   0,0,               /* HorizPot, VertPot: will be initialized later. */
  223.   0,                 /* HorizBody                 -"-                 */
  224.   0xFFFF,            /* VertBody: No data to show, maximum. */
  225.   0,0,0,0,0,0        /* Intuition sets and maintains these variables. */
  226. };
  227.  
  228. struct Gadget gadget_proportional=
  229. {
  230.   NULL,                     /* *NextGadget */
  231.   290, 68, 21, 72,          /* LeftEdge, TopEdge, Width, Height */
  232.   GADGHCOMP,                                      /* Flags      */
  233.   GADGIMMEDIATE|FOLLOWMOUSE|RELVERIFY,            /* Activation */
  234.   PROPGADGET,                                     /* GadgetType */
  235.   (APTR) &image_prop,       /* GadgetRender */
  236.   NULL,                     /* SelectRender */
  237.   NULL,                     /* *GadgetText */
  238.   NULL,                     /* MutualExclude */
  239.   (APTR) &prop_info,        /* SpecialInfo */
  240.   NULL,                     /* GadgetID */
  241.   NULL                      /* UserData */
  242. };
  243.  
  244. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  245. /*   Information for the string gadget "Drawer:"                      */
  246. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  247. SHORT points28s[]=              /* Values for a 28-letter string box: */
  248. {
  249.    -7, -3,
  250.   200, -3,
  251.   200, 10,
  252.    -7, 10,
  253.    -7, -3,
  254. };
  255. struct Border border_text28s=   /* Border for 28-letter string box: */
  256. {
  257.   0, 0,                     /* LeftEdge, TopEdge */
  258.   1, 2, JAM1,               /* FrontPen, BackPen, DrawMode */
  259.   5,                        /* Count */
  260.   points28s,                /* *XY   */
  261.   NULL                      /* *NextBorder */
  262. };
  263.  
  264.  
  265. struct IntuiText text_drawer=
  266. {
  267.   1, 2,                     /* FrontPen, BackPen  */
  268.   JAM1,                     /* DrawMode           */
  269.   -67, 0,                   /* LewftEdge, TopEdge */
  270.   &my_font,                 /* *ITextFont */
  271.   "Drawer:",                /* *IText */
  272.   NULL                      /* *NextText */
  273. };
  274.  
  275. struct StringInfo string_drawer=
  276. {
  277.   drawer_name,              /* *Buffer */
  278.   name_backup,              /* *UndoBuffer */
  279.   0,                        /* BufferPos */
  280.   70,                       /* MaxChars (Including NULL) */
  281.   0,                        /* DispPos */
  282.   0,                        /* UndoPos */
  283.   0, 0,                     /* CLeft, CTop */
  284.   NULL,                     /* *LayerPtr */
  285.   NULL,                     /* LongInt */
  286.   NULL,                     /* *AltKeyMap */
  287. };
  288.  
  289. struct Gadget gadget_drawer =
  290. {
  291.   &gadget_proportional,     /* *NextGadget */
  292.   83, 53, 198, 8,           /* LeftEdge, TopEdge, Width, Height */
  293.   GADGHCOMP,                /* Flags */
  294.   RELVERIFY,                /* Activation */
  295.   STRGADGET,                /* GadgetType */
  296.   (APTR) &border_text28s,   /* GadgetRender */
  297.   NULL,                     /* SelectRender */
  298.   &text_drawer,             /* *GadgetText */
  299.   NULL,                     /* MutualExclude */
  300.   (APTR) &string_drawer,    /* SpecialInfo */
  301.   NULL,                     /* GadgetID */
  302.   NULL                      /* UserData */
  303. };
  304.  
  305. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  306. /*  Information for the string gadget "File:"                         */
  307. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  308. SHORT points30s[]=                /* Values for 30-letter string box: */
  309. {
  310.    -7, -3,
  311.   244, -3,
  312.   244, 10,
  313.    -7, 10,
  314.    -7, -3 
  315. };
  316. struct Border border_text30s=     /* Border for 30-letter string box: */
  317. {
  318.   0, 0,              /* LeftEdge, TopEdge */
  319.   1, 0, JAM1,        /* FrontPen, BackPen, DrawMode */
  320.   5,                 /* Count */
  321.   points30s,         /* *XY */
  322.   NULL               /* *NextBorder */
  323. };
  324. struct IntuiText text_file=
  325. {
  326.   1, 0,              /* FrontPen, BackPen */
  327.   JAM1,              /* DrawMode */
  328.   -53, 0,            /* LewftEdge, TopEdge */
  329.   &my_font,          /* *ITextFont */
  330.   "File:",           /* *IText */
  331.   NULL               /* *NextText */
  332. };
  333. struct StringInfo string_file=
  334. {
  335.   file_name,         /* *Buffer */
  336.   name_backup,       /* *UndoBuffer */
  337.   0,                 /* BufferPos */
  338.   40,                /* MaxChars (Including NULL) */
  339.   0,                 /* DispPos */
  340.   0,                 /* UndoPos */
  341.   0, 0,              /* CLeft, CTop */
  342.   NULL,              /* *LayerPtr */
  343.   NULL,              /* LongInt */
  344.   NULL,              /* *AltKeyMap */
  345. };
  346. struct Gadget gadget_file=
  347. {
  348.   &gadget_drawer,         /* *NextGadget */
  349.   66,  147, 240, 7,       /* LeftEdge, TopEdge, Width, Height */
  350.   GADGHCOMP,              /* Flags */
  351.   RELVERIFY,              /* Activation */
  352.   STRGADGET,              /* GadgetType */
  353.   (APTR) &border_text30s, /* GadgetRender */
  354.   NULL,                   /* SelectRender */
  355.   &text_file,             /* *GadgetText */
  356.   NULL,                   /* MutualExclude */
  357.   (APTR) &string_file,    /* SpecialInfo */
  358.   NULL,                   /* GadgetID */
  359.   NULL                    /* UserData */
  360. };
  361.  
  362. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  363. /* * Information for the string gadget "Extension"                     * */
  364. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  365. SHORT points6s[]=           /* Values for a 6-letter string box: */
  366. {
  367.   -7, -3,
  368.   57, -3,
  369.   57, 10,
  370.   -7, 10,
  371.   -7, -3
  372. };
  373. struct Border border_text6s=  /* Border for 6-letter string box: */
  374. {
  375.   0, 0,                     /* LeftEdge, TopEdge */
  376.   1, 2, JAM1,               /* FrontPen, BackPen, DrawMode */
  377.   5,                        /* Count */
  378.   points6s,                 /* *XY */
  379.   NULL                      /* *NextBorder */
  380. };
  381. struct IntuiText text_extension=
  382. {
  383.   1, 2,                     /* FrontPen, BackPen */
  384.   JAM1,                     /* DrawMode */
  385.   -43, 0,                   /* LewftEdge, TopEdge */
  386.   &my_font,                 /* *ITextFont */
  387.   "Ext:",                   /* *IText */
  388.   NULL                      /* *NextText */
  389. };
  390. struct StringInfo string_extension=
  391. {
  392.   extension_name,           /* *Buffer */
  393.   name_backup,              /* *UndoBuffer */
  394.   0,                        /* BufferPos */
  395.   7,                        /* MaxChars (Including NULL) */
  396.   0,0,                      /* DispPos, UndoPos */
  397.   0, 0,                     /* CLeft, CTop */
  398.   NULL,NULL,NULL,           /* *LayerPtr, LongInt, *AltKeyMap */
  399. };
  400. struct Gadget gadget_extension=
  401. {
  402.   &gadget_file,             /* *NextGadget */
  403.   253, 35, 59, 8,           /* LeftEdge, TopEdge, Width, Height */
  404.   GADGHCOMP,                /* Flags */
  405.   RELVERIFY,                /* Activation */
  406.   STRGADGET,                /* GadgetType */
  407.   (APTR) &border_text6s,    /* GadgetRender */
  408.   NULL,                     /* SelectRender */
  409.   &text_extension,          /* *GadgetText */
  410.   NULL,                     /* MutualExclude */
  411.   (APTR) &string_extension, /* SpecialInfo */
  412.   NULL,                     /* GadgetID */
  413.   NULL                      /* UserData */
  414. };
  415.  
  416. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  417. /*   Information for the boolean gadget parent "<"                    */
  418. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  419. SHORT points1[]=            /* Values for a 1-letter box: */
  420. {
  421.    0,  0,
  422.   20,  0,
  423.   20, 15,
  424.    0, 15,
  425.    0,  0
  426. };
  427. struct Border border_text1= /* A border for a 1-letter box: */
  428. {
  429.   0, 0,                     /* LeftEdge, TopEdge */
  430.   1, 2, JAM1,               /* FrontPen, BackPen, DrawMode */
  431.   5,                        /* Count */
  432.   points1,                  /* *XY */
  433.   NULL                      /* *NextBorder */
  434. };
  435. struct IntuiText text_parent=
  436. {
  437.   1, 2,                     /* FrontPen, BackPen */
  438.   JAM1,                     /* DrawMode */
  439.   7,4,                      /* LeftEdge, TopEdge */
  440.   &my_font,                 /* *ITextFont, (Topaz, 80) */
  441.   "<",                      /* *IText */
  442.   NULL                      /* *NextText */
  443. };
  444. struct Gadget gadget_parent=
  445. {
  446.   &gadget_extension,        /* *NextGadget */
  447.   290, 49, 21, 16,          /* LeftEdge, TopEdge, Width, Height */
  448.   GADGHCOMP,                /* Flags */
  449.   RELVERIFY,                /* Activation */
  450.   BOOLGADGET,               /* GadgetType */
  451.   (APTR) &border_text1,     /* GadgetRender */
  452.   NULL,                     /* SelectRender */
  453.   &text_parent,             /* *GadgetText */
  454.   NULL, NULL, NULL, NULL
  455. };
  456.  
  457. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  458. /*   Information for the boolean gadget "df1:"                        */
  459. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  460. struct IntuiText text_df1=
  461. {
  462.   1, 2,    
  463.   JAM1,    
  464.   7,4,     
  465.   &my_font,
  466.   "df1:",  
  467.   NULL     
  468. };
  469. struct Gadget gadget_df1=
  470. {
  471.   &gadget_parent, 
  472.   110, 13, 45, 15,
  473.   GADGHCOMP,      
  474.   RELVERIFY,      
  475.   BOOLGADGET,     
  476.   (APTR) &border_text4,
  477.   NULL,           
  478.   &text_df1,      
  479.   NULL, NULL, NULL, NULL
  480. };
  481.  
  482. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  483. /*   Information for the boolean gadget "df0:"                        */
  484. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  485. struct IntuiText text_df0=
  486. {
  487.   1, 2,                     /* FrontPen, BackPen */
  488.   JAM1,                     /* DrawMode */
  489.   7,4,                      /* LeftEdge, TopEdge */
  490.   &my_font,                 /* *ITextFont, (Topaz, 80) */
  491.   "df0:",                   /* *IText */
  492.   NULL                      /* *NextText */
  493. };
  494. struct Gadget gadget_df0=
  495. {
  496.   &gadget_df1,              /* *NextGadget */
  497.   59, 13, 45, 15,           /* LeftEdge, TopEdge, Width, Height */
  498.   GADGHCOMP,                /* Flags */
  499.   RELVERIFY,                /* Activation */
  500.   BOOLGADGET,               /* GadgetType */
  501.   (APTR) &border_text4,     /* GadgetRender */
  502.   NULL,                     /* SelectRender */
  503.   &text_df0,                /* *GadgetText */
  504.   NULL, NULL, NULL, NULL
  505. };
  506.  
  507. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  508. /*   Information for the boolean gadget "ram:"                        */
  509. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  510. struct IntuiText text_ram=
  511. {
  512.   1, 2,    
  513.   JAM1,    
  514.   7,4,     
  515.   &my_font,
  516.   "ram:",  
  517.   NULL     
  518. };
  519. struct Gadget gadget_ram=
  520. {
  521.   &gadget_df0,  
  522.   8, 13, 45, 15,
  523.   GADGHCOMP,    
  524.   RELVERIFY,    
  525.   BOOLGADGET,   
  526.   (APTR) &border_text4,
  527.   NULL,     
  528.   &text_ram,
  529.   NULL, NULL, NULL, NULL
  530. };
  531.  
  532. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  533. /*  Information for the boolean gadget "dh2:"                         */
  534. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  535. struct IntuiText text_dh2=
  536. {
  537.   1, 2,
  538.   JAM1,
  539.   7,4, 
  540.   &my_font,
  541.   "dh2:",
  542.   NULL 
  543. };
  544. struct Gadget gadget_dh2=
  545. {
  546.   &gadget_ram,
  547.   110, 31, 45, 15,
  548.   GADGHCOMP, 
  549.   RELVERIFY, 
  550.   BOOLGADGET,
  551.   (APTR) &border_text4,
  552.   NULL,     
  553.   &text_dh2,
  554.   NULL, NULL, NULL, NULL
  555. };
  556.  
  557. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  558. /*   Information for the boolean gadget "dh1:"                        */
  559. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  560. struct IntuiText text_dh1=
  561. {
  562.   1, 2,
  563.   JAM1,
  564.   7,4, 
  565.   &my_font,
  566.   "dh1:",  
  567.   NULL     
  568. };
  569. struct Gadget gadget_dh1=
  570. {
  571.   &gadget_dh2,
  572.   59, 31, 45, 15,
  573.   GADGHCOMP, 
  574.   RELVERIFY, 
  575.   BOOLGADGET,
  576.   (APTR) &border_text4,
  577.   NULL,     
  578.   &text_dh1,
  579.   NULL, NULL, NULL, NULL
  580. };
  581.  
  582. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  583. /*   Information for the boolean gadget "dh0:"                        */
  584. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  585. struct IntuiText text_dh0=
  586. {
  587.   1, 2,
  588.   JAM1,
  589.   7,4, 
  590.   &my_font,
  591.   "dh0:",
  592.   NULL   
  593. };
  594. struct Gadget gadget_dh0=
  595. {
  596.   &gadget_dh1,
  597.   8, 31, 45, 15,
  598.   GADGHCOMP,
  599.   RELVERIFY,
  600.   BOOLGADGET,
  601.   (APTR) &border_text4,
  602.   NULL,
  603.   &text_dh0,
  604.   NULL, NULL, NULL, NULL
  605. };
  606.  
  607. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  608. /*   Information for the boolean gadget "ABORT"                       */
  609. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  610. struct IntuiText text_abort=
  611. {
  612.   1, 2,
  613.   INVERSVID,
  614.   3,2, 
  615.   &my_font,
  616.   "- ABORT -",
  617.   NULL
  618. };
  619. struct Gadget gadget_abort=
  620. {
  621.   &gadget_dh0,
  622.    95, 162, 77, 12,
  623.   GADGHCOMP,
  624.   RELVERIFY,
  625.   BOOLGADGET,
  626.   (APTR) &border_text9b,
  627.   NULL,
  628.   &text_abort,
  629.   NULL, NULL, NULL, NULL
  630. };
  631.  
  632. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  633. /*   Information for the boolean gadget "DELETE"                      */
  634. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  635. struct IntuiText text_delete=
  636. {
  637.   1, 0,
  638.   JAM2,
  639.   0,0, 
  640.   &my_font,
  641.   "DELETE",
  642.   NULL 
  643. };
  644. struct Gadget gadget_delete=
  645. {
  646.   &gadget_abort,
  647.   196, 168, 49, 8,
  648.   GADGHCOMP,
  649.   RELVERIFY,
  650.   BOOLGADGET,
  651.   (APTR) &border_text6,
  652.   NULL,
  653.   &text_delete,
  654.   NULL, NULL, NULL, NULL
  655. };
  656.  
  657. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  658. /*   Information for the boolean gadget "RENAME"                        */
  659. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  660. struct IntuiText text_rename=
  661. {
  662.   1, 0,
  663.   JAM2,
  664.   0,0, 
  665.   &my_font,
  666.   "RENAME",
  667.   NULL
  668. };
  669. struct Gadget gadget_rename=
  670. {
  671.   &gadget_delete,
  672.   259, 168, 48, 8,
  673.   GADGHCOMP,
  674.   RELVERIFY,
  675.   BOOLGADGET,
  676.   (APTR) &border_text6,
  677.   NULL,
  678.   &text_rename,
  679.   NULL, NULL, NULL, NULL
  680. };
  681.  
  682. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  683. /*   Information for the boolean gadget "TAKE"                        */
  684. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  685. struct IntuiText text_take=
  686. {
  687.   1, 2,     
  688.   INVERSVID,
  689.   3,2,      
  690.   &my_font, 
  691.   " O K A Y ",
  692.   NULL
  693. };
  694. struct Gadget gadget_take=
  695. {
  696.   &gadget_rename,
  697.   8, 162, 77, 12,         /* LeftEdge, TopEdge, Width, Height */
  698.   GADGHCOMP,              /* Flags */
  699.   RELVERIFY,              /* Activation */
  700.   BOOLGADGET,             /* GadgetType */
  701.   (APTR) &border_text9,   /* GadgetRender */
  702.   NULL,                   /* SelectRender */
  703.   &text_take,             /* *GadgetText */
  704.   NULL, NULL, NULL, NULL
  705. };
  706. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  707. /*   Information for the boolean gadgets "gadget_display"             */
  708. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  709. struct IntuiText text_list[8]=
  710. {
  711.   {
  712.     1, 0,            /* FrontPen, BackPen */
  713.     JAM2,            /* DrawMode */
  714.     0,18,            /* LeftEdge, TopEdge */
  715.     &my_font,        /* *ITextFont */
  716.     display_text[0], /* IText */
  717.     &text_list[1]    /* *NextText */
  718.   },
  719.   {
  720.     1, 0,            
  721.     JAM2,            
  722.     0,26,            
  723.     &my_font,        
  724.     display_text[1], 
  725.     &text_list[2]    
  726.   },
  727.   {
  728.     1, 0,            
  729.     JAM2,            
  730.     0,34,            
  731.     &my_font,        
  732.     display_text[2], 
  733.     &text_list[3]    
  734.   },
  735.   {
  736.     1, 0,            
  737.     JAM2,            
  738.     0,42,            
  739.     &my_font,        
  740.     display_text[3], 
  741.     &text_list[4]    
  742.   },
  743.   {
  744.     1, 0,            
  745.     JAM2,            
  746.     0,50,            
  747.     &my_font,        
  748.     display_text[4], 
  749.     &text_list[5]    
  750.   },
  751.   {
  752.     1, 0,            
  753.     JAM2,            
  754.     0,58,            
  755.     &my_font,        
  756.     display_text[5], 
  757.     &text_list[6]    
  758.   },
  759.   {
  760.     1, 0,            
  761.     JAM2,            
  762.     0,66,            
  763.     &my_font,        
  764.     display_text[6], 
  765.     &text_list[7]    
  766.   },
  767.   {
  768.     1, 0,            
  769.     JAM2,            
  770.     0,74,            
  771.     &my_font,        
  772.     display_text[7], 
  773.     NULL             
  774.   }
  775. };
  776.  
  777. struct Gadget gadget_display[8]=
  778. {
  779.   {
  780.     &gadget_display[1],      /* *NextGadget */
  781.     8, 68, 276, 12,          /* LeftEdge, TopEdge, Width, Height */
  782.     GADGHCOMP,               /* Flags */
  783.     RELVERIFY|GADGIMMEDIATE, /* Activation */
  784.     BOOLGADGET,              /* GadgetType */
  785.     NULL, NULL, NULL, NULL, NULL, NULL, NULL
  786.   },
  787.   {
  788.     &gadget_display[2],
  789.     8, 80, 276, 8,
  790.     GADGHCOMP,
  791.     RELVERIFY|GADGIMMEDIATE,
  792.     BOOLGADGET,
  793.     NULL, NULL, NULL, NULL, NULL, NULL, NULL
  794.   },
  795.   {
  796.     &gadget_display[3],
  797.     8, 88, 276, 8,  
  798.     GADGHCOMP,
  799.     RELVERIFY|GADGIMMEDIATE,
  800.     BOOLGADGET, 
  801.     NULL, NULL, NULL, NULL, NULL, NULL, NULL
  802.   },
  803.   {
  804.     &gadget_display[4],
  805.     8, 96, 276, 8,
  806.     GADGHCOMP,
  807.     RELVERIFY|GADGIMMEDIATE,
  808.     BOOLGADGET,
  809.     NULL, NULL, NULL, NULL, NULL, NULL, NULL
  810.   },
  811.   {
  812.     &gadget_display[5],
  813.     8, 104, 276, 8,
  814.     GADGHCOMP,
  815.     RELVERIFY|GADGIMMEDIATE,
  816.     BOOLGADGET,
  817.     NULL, NULL, NULL, NULL, NULL, NULL, NULL
  818.   },
  819.   {
  820.     &gadget_display[6],
  821.     8, 112, 276, 8,  
  822.     GADGHCOMP,
  823.     RELVERIFY|GADGIMMEDIATE,
  824.     BOOLGADGET, 
  825.     NULL, NULL, NULL, NULL, NULL, NULL, NULL
  826.   },
  827.   {
  828.     &gadget_display[7],
  829.     8, 120, 276, 8, 
  830.     GADGHCOMP,
  831.     RELVERIFY|GADGIMMEDIATE,
  832.     BOOLGADGET,
  833.     NULL, NULL, NULL, NULL, NULL, NULL, NULL
  834.   },
  835.   {
  836.     &gadget_take,
  837.     8, 128, 276, 12,
  838.     GADGHCOMP,
  839.     RELVERIFY|GADGIMMEDIATE,
  840.     BOOLGADGET,
  841.     NULL, NULL, NULL, NULL, NULL, NULL, NULL
  842.   }
  843. };
  844.  
  845. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  846. /*   BIG BOX                                                          */
  847. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  848. SHORT points_big_box[]=
  849. {
  850.    8, 68,
  851.  283, 68,
  852.  283,139,
  853.    8,139,
  854.    8, 68 
  855. };
  856. struct Border border_big_box=             /* Border for 1-letter box: */
  857. {
  858.   0, 0,
  859.   1, 2, JAM1,
  860.   5,
  861.   points_big_box,
  862.   NULL
  863. };
  864.  
  865. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  866. /*   Information for the window                                       */
  867. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  868. struct NewWindow new_file_window=
  869. {
  870.   0,0,                    /* LeftEdge, TopEdge   */
  871.   320, 180,               /* Width, Height       */
  872.   0,1,                    /* DetailPen, BlockPen */
  873.   GADGETUP|VANILLAKEY|    /* IDCMPFlags          */
  874.   GADGETDOWN|MOUSEMOVE,
  875.   ACTIVATE|SMART_REFRESH| /* Flags */
  876.   WINDOWDRAG,
  877.   &gadget_display[0],     /* *FirstGadget        */
  878.   NULL, NULL,             /* *CheckMark, *Title  */
  879.   NULL, NULL,             /* *Screen, *BitMap    */
  880.   40,20,640,256,          /* MinWidth, MinHeight, MaxWidth, MaxHeight */
  881.   WBENCHSCREEN            /* Type  */
  882. };
  883.  
  884. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  885. USHORT  FileWindow2(STRPTR title,STRPTR extension,int x,int y,struct Screen *screen,STRPTR total_file_name)
  886. {
  887.   int temp1;                  /* Variable used for loops etc.       */
  888.   int file_count;             /* Number of files/directories        */
  889.   ULONG   class;              /* Saved IntuiMessage: IDCMP flags.   */
  890.   USHORT  code;               /*                     key flags.     */
  891.   APTR    address;            /*                     Object-Address */
  892.   int     position;           /* Number of first file in display    */
  893.   BOOL    working;            /* Wants the user to abort?           */
  894.   BOOL    fix_display;        /* Should we update the file-display? */
  895.   STRPTR  string_pointer;     /* Pointer to a string.               */
  896.   struct  file_info *pointer; /* Pointer to a file_info structure   */
  897.   struct  RastPort *rp;       /* Pointer to FileWindow2-rastport    */
  898.   USHORT  operation=0;        /* user action returned by FileWindow2 */
  899.   file_lock =FALSE;           /* No file/directory has been locked  */
  900.   more_files=FALSE;           /* Do not list any files yet          */
  901.   prop_info.VertBody =0xFFFF; /* Make sure the proportional gadget  */
  902.   prop_info.HorizBody=0;      /* is at the top, showing 100%        */
  903.   prop_info.VertPot  =0;
  904.   prop_info.HorizPot =0;
  905.   new_file_window.LeftEdge=x;
  906.   new_file_window.TopEdge =y;
  907.   new_file_window.Title   =title;
  908.   strcpy(extension_name, extension);
  909.   if(*extension_name != '\0')   text_extension.FrontPen=3;
  910.   else                          text_extension.FrontPen=1;
  911.  
  912.   if(screen)                  /* Does user want to use an own screen? */
  913.   {
  914.     new_file_window.Screen=screen;
  915.     new_file_window.Type=CUSTOMSCREEN;
  916.   }
  917.  
  918. /*­­­­­­­­­­­­­­­­­­   Library-Initialisierung   ­­­­­­­­­­­­­­­­­­­­­*/
  919.   if(!GfxBase)
  920.   {
  921.      GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0);
  922.      if(!GfxBase)          return(PANIC);
  923.   }
  924.   if(!IntuitionBase)
  925.   {
  926.      IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0);
  927.      if(!IntuitionBase)    return(PANIC);
  928.   }
  929.   file_window=(struct Window *)OpenWindow(&new_file_window);
  930.   if(file_window==NULL)    return(PANIC);
  931.   rp=file_window->RPort;
  932. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  933.   DrawBorder(rp, &border_big_box, 0, 0);
  934.   if((file_info=(struct FileInfoBlock *)
  935.     AllocMem(sizeof(struct FileInfoBlock),MEMF_PUBLIC|MEMF_CLEAR))==NULL)
  936.   { request_ok(errors[4]);    return(PANIC); }
  937.   if(*total_file_name != '\0')
  938.   {
  939.     if((lock=Lock(total_file_name, ACCESS_READ))==NULL)
  940.     { /* PROBLEMS!  File/directory/device did NOT exist! */ }
  941.     else
  942.     {
  943.       file_lock=TRUE;              /* Could lock the file/directory! */
  944.       if((Examine(lock, file_info))==NULL)   request_ok(errors[18]);
  945.       else
  946.       {
  947.         if(directory(file_info))                /* It is a directory! */
  948.         {
  949.           *file_name='\0';                 /* Clear file_name string. */
  950.           strcpy(drawer_name, total_file_name);
  951.           more_files=TRUE;
  952.         }
  953.         else                                         /* It is a file! */
  954.         {
  955.           /* Separate the file name from the path: */
  956.           if(string_pointer=right_pos(total_file_name, '/'))
  957.           {
  958.             /* Copy the file name into file_name string: */
  959.             strcpy(file_name, string_pointer+1);
  960.             *string_pointer='\0';
  961.           }
  962.           else
  963.           {
  964.             if(string_pointer=right_pos(total_file_name, ':'))
  965.             {
  966.               /* Copy the file name into file_name string: */
  967.               strcpy(file_name, string_pointer+1);
  968.               *(string_pointer+1)='\0';
  969.             }
  970.             else
  971.             {
  972.               strcpy(file_name, total_file_name);
  973.               *drawer_name='\0';
  974.               *total_file_name='\0';
  975.             }
  976.           }
  977.           strcpy(drawer_name, total_file_name);
  978.               /* Since it is a file, we will NOT look for more files: */
  979.               /* However, more_files is already FALSE. */
  980.         }     /* Is it a directory? */
  981.       }       /* Could we examine the object? */
  982.     }         /* Could we "lock" the file/directory? */
  983.   }           /* Anything in the total_file_name string? */
  984.  
  985.   /* Since we have messed around with the string gadgets it is best */
  986.   /* to adjust them so the user can see them clearly:               */
  987.   adjust_string_gadgets();
  988.   new_drawer();           /* Start to show us the files             */
  989.   position=0;             /* The display will show the first file.  */
  990.   fix_display=FALSE;      /* We do not need to fix the display      */
  991.   first_file=TRUE;        /* No files saved. */
  992.   file_count=0;           /* No files saved. */
  993.   working=TRUE;
  994.   do
  995.   {
  996.     /* If we have shown all files in the directory, we put our task */
  997.     /* to sleep. That will speed up other programs, and we will not */
  998.     /* use unnecessary processing time:                             */
  999.     if(more_files==FALSE)   Wait(1<<file_window->UserPort->mp_SigBit);
  1000.     /* Has something happened with the gadgets in the file_window?  */
  1001.     while(my_gadget_message = (struct IntuiMessage *)
  1002.       GetMsg(file_window->UserPort))
  1003.     {
  1004.       /* As long as something is happening with the gadgets we will     */
  1005.       /* stay in the while loop. This is very handy since we can        */
  1006.       /* recieve hundereds of messages if the mouse is moving, and      */
  1007.       /* we only want to update the display when the mouse has stopped: */
  1008.       class   = my_gadget_message->Class;
  1009.       code    = my_gadget_message->Code; 
  1010.       address = my_gadget_message->IAddress;
  1011.  
  1012.       /* We have now saved some important values, and can now reply: */
  1013.       ReplyMsg((struct Message *)my_gadget_message);
  1014.       if(code==13||code==27)   class=GADGETUP;
  1015.                                    /* RETURN key used instead of TAKE */
  1016.                                    /* ESC key used instead of ABORT */
  1017.       switch(class)
  1018.       {
  1019.         case MOUSEMOVE:
  1020.           /* The proportional gadget is selected, and the mouse is  */ 
  1021.           /* moving; we must update the file_display when the mouse */
  1022.           /* has stopped: */
  1023.           fix_display=TRUE;   break;
  1024.  
  1025.         case GADGETDOWN:
  1026.            /* A gadget has been pressed down. Which one? */
  1027.            /* DISPLAY */
  1028.            /* Is the user clicking inside the file display? */
  1029.            for(temp1=0; temp1<8; temp1++)
  1030.            {
  1031.              if(address == (APTR)&gadget_display[temp1])
  1032.              { pick_file(temp1+position); }      /* File/dir selected */
  1033.            }
  1034.            break;
  1035.  
  1036.         case GADGETUP:            /* Which gadget has been selected ? */
  1037. /* TAKE */
  1038.            if(address == (APTR)&gadget_take || code==13)
  1039.            {
  1040.              if(operation==DELETE||operation==RENAME)   gadget_flag=TAKE;
  1041.              else
  1042.              {
  1043.                 if(last_check(total_file_name))
  1044.                   { working=FALSE;   operation=TAKE;  break; }
  1045.              }
  1046.            }
  1047.  
  1048. /* ABORT */
  1049.            if(address==(APTR)&gadget_abort||operation==ABORT||code==27)
  1050.            {
  1051.              if(operation==DELETE||operation==RENAME)   gadget_flag=ABORT;
  1052.              else
  1053.              {
  1054.                 connect_dir_file(total_file_name);
  1055.                 clear_gadgets(title);   operation=ABORT;
  1056.                 working=FALSE;    break;
  1057.              }
  1058.            }
  1059.  
  1060. /* DELETE */
  1061.            if(address==(APTR)&gadget_delete || operation==DELETE)
  1062.            {
  1063.              if(!(gadget_flag==ABORT||gadget_flag==TAKE))
  1064.              {
  1065.                  delete_file_dir(total_file_name);
  1066.                  operation=DELETE;
  1067.              }
  1068.              if(gadget_flag==TAKE)
  1069.              {
  1070.                  delete_file_dir(total_file_name);
  1071.                  operation=clear_gadgets(title);     break;
  1072.              }
  1073.              if(gadget_flag==ABORT)
  1074.                { operation=clear_gadgets(title);     break; }
  1075.            }
  1076.  
  1077. /* RENAME */
  1078.            if(address==(APTR)&gadget_rename||operation==RENAME)
  1079.            {
  1080.            if(ren==1)
  1081.              {
  1082.                 if(gadget_flag==ABORT)
  1083.                   { operation=clear_gadgets(title);  break; }
  1084.  
  1085.                 else   ren=2;
  1086.              }
  1087.              if(ren==0)   { operation=RENAME;   ren=1; }
  1088.              rename_file_dir(total_file_name);
  1089.  
  1090.              if(ren==2)   { operation=clear_gadgets(title);   break; }
  1091.            }
  1092.  
  1093.            if(address == (APTR)&gadget_ram)           /* ram: */
  1094.              { change_device("ram:");   break; }
  1095.            if(address == (APTR)&gadget_df0)           /* df0: */
  1096.              { change_device("df0:");   break; }
  1097.            if(address == (APTR)&gadget_df1)           /* df1: */
  1098.              { change_device("df1:");   break; }
  1099.            if(address == (APTR)&gadget_dh0)           /* dh0: */
  1100.              { change_device("dh0:");   break; }
  1101.            if(address == (APTR)&gadget_dh1)           /* dh1: */
  1102.              { change_device("dh1:");   break; }
  1103.            if(address == (APTR)&gadget_dh2)           /* dh2: */
  1104.              { change_device("dh2:");   break; }
  1105.  
  1106.            /* DRAWER: */
  1107.            if(address == (APTR)&gadget_drawer)
  1108.            {
  1109.              /* The user has entered something new in the drawer: */
  1110.              new_drawer();   break;
  1111.            }
  1112.  
  1113.            /* EXTENSION: */
  1114.            if(address == (APTR)&gadget_extension)
  1115.            {
  1116.              new_drawer();   break;
  1117.            }
  1118.  
  1119.            /* PARENT: "<" */
  1120.            if(address == (APTR)&gadget_parent)    { parent();   break; }
  1121.  
  1122.            /* PROPORTIONAL */
  1123.            if(address == (APTR)&gadget_proportional)
  1124.            {
  1125.              /* User has released the prop-gadget, update display: */
  1126.              fix_display=TRUE;   break;
  1127.            }
  1128.       }
  1129.     }
  1130.     if(fix_display)         /* Do we need to update the file display? */
  1131.     {
  1132.       fix_display=FALSE;
  1133.       if(file_count>8)          /* Which file should be shown */
  1134.         position=(int) prop_info.VertPot/(float)0xFFFF*(file_count-8);
  1135.       else   position=0;
  1136.       display_list(position);   /* List files: (Starts with position) */
  1137.     }
  1138.     if(more_files)              /* Are there more files/dirs? */
  1139.     {
  1140.       if(ExNext(lock, file_info))
  1141.       {
  1142.                           /* List the file/directory if it is: */
  1143.                           /* 1. A file which has the right extension. */
  1144.                           /* 2. A directory. */
  1145.         if(stricmp(extension_name, (file_info->fib_FileName+
  1146.            strlen(file_info->fib_FileName)-strlen(extension_name)))==0 ||
  1147.            directory(file_info) )
  1148.         {
  1149.           if(first_file)  /* Is this the first file/directory? */
  1150.           {
  1151.             /* first_pointer will point at the first file in our list: */
  1152.             first_pointer=(struct file_info *) save_file_info(file_info);
  1153.             if(first_pointer != NULL)
  1154.             {
  1155.               /* No more elements (for the moment) in the list: */ 
  1156.               first_pointer->next=NULL; 
  1157.               first_file=FALSE;
  1158.             }
  1159.             file_count=1;   position=1;
  1160.           }
  1161.           else
  1162.           {
  1163.             /* save_file_info will return a pointer to the allocated */
  1164.             /* structure: */
  1165.             pointer=(struct file_info *) save_file_info(file_info);
  1166.             
  1167.             /* If we have been able to allocate space for the file we */
  1168.             /* put it into our list: */
  1169.             if(pointer!=NULL)         /* Put new structure into list: */
  1170.             {
  1171.               put_in(first_pointer, pointer);
  1172.               file_count++;
  1173.             }
  1174.           }
  1175.           /* If there are more than eight files/directories we modify */
  1176.           /* the proportional gadget: */
  1177.           if(file_count > 8)
  1178.           {
  1179.             ModifyProp
  1180.             (
  1181.               &gadget_proportional,       /* PropGadget */
  1182.               file_window,                /* Pointer */
  1183.               NULL,                       /* Requester */
  1184.               prop_info.Flags,            /* Flags */
  1185.               0,                          /* HorizPot */
  1186.               prop_info.VertPot,          /* VertPot */
  1187.               0,                          /* HorizBody */
  1188.               (ULONG) 0xFFFF*8/file_count /* VerBody */
  1189.             );            
  1190.             position=(int) prop_info.VertPot/(float) 0xFFFF*(file_count-8);
  1191.           }
  1192.           else
  1193.            position=0;
  1194.           display_list(position);         /* List all the files: */
  1195.         }
  1196.       }
  1197.       else                                /* ExNext() failed: */
  1198.       {
  1199.         more_files=FALSE;                 /* Don't list any more files */
  1200.         /* Check what went wrong: */
  1201.         /* If error message is NOT "ERROR_NO_MORE_ENTRIES" something */
  1202.         /* went terrible wrong while reading: */
  1203.         if(IoErr() != ERROR_NO_MORE_ENTRIES)   request_ok(errors[18]);
  1204.       }
  1205.     }
  1206.   } while(working);                       /* Clean up and leave: */
  1207.                               /* This will clear the IDCMP port: */
  1208.   while( (my_gadget_message = (struct IntuiMessage *)
  1209.            GetMsg(file_window->UserPort)) )
  1210.   {
  1211.     ReplyMsg((struct Message *)my_gadget_message);
  1212.   }
  1213.   /* Deallocate the memory we have dynamically allocated: */ 
  1214.   deallocate_file_info();
  1215.   if(file_lock)       /* If we have "locked" a file/dir, "unlock" it: */
  1216.   {
  1217.     UnLock(lock);   file_lock=FALSE;
  1218.   }
  1219.   if(file_info) FreeMem(file_info, sizeof(struct FileInfoBlock));
  1220.   /* If we have successfully opened the file_window, we close it: */
  1221.   if(file_window)
  1222.   {
  1223.      if(GfxBase)         CloseLibrary((struct Library *) GfxBase);
  1224.      if(IntuitionBase)   CloseLibrary((struct Library *) IntuitionBase);
  1225.      CloseWindow(file_window);
  1226.   }
  1227.   return(operation);
  1228. }
  1229.  
  1230. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1231. void deallocate_file_info(void)
  1232. {
  1233.   struct file_info *pointer, *temp_pointer;
  1234.  
  1235.   /* Does the first pointer point to an allocated structure? */
  1236.   if(first_pointer)
  1237.   {
  1238.     /* Save the address of the next structure: */
  1239.     pointer=first_pointer->next;
  1240.     
  1241.     /* Deallocate the first structure: */
  1242.     FreeMem( first_pointer, sizeof(struct file_info));
  1243.  
  1244.     /* As long as pointer points to an allocated structure: */
  1245.     while(pointer)
  1246.     {
  1247.       /* Save the address of the next structure: */
  1248.       temp_pointer=pointer->next;
  1249.       
  1250.       FreeMem( pointer, sizeof(struct file_info));
  1251.       pointer=temp_pointer;
  1252.     }
  1253.   }
  1254.   first_pointer=NULL;                         /* Clear first_pointer: */
  1255.  
  1256.   /* Next time we try to list the files, we start with the first_file: */
  1257.   first_file=TRUE;
  1258. }
  1259.  
  1260. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1261. /* Allocate memory for the new file/directory, and fills the structure */
  1262. /* with information. (name of the object, and if it is a directory.)   */
  1263. /* Returns a memory pointer to the allocated structure, or NULL.       */
  1264. APTR save_file_info(struct FileInfoBlock *info)
  1265. {
  1266.   struct file_info *pointer;
  1267.  
  1268.   if((pointer=(struct file_info *)
  1269.     AllocMem(sizeof(struct file_info), MEMF_PUBLIC|MEMF_CLEAR))==NULL)
  1270.   {
  1271.     request_ok(errors[4]);
  1272.     more_files=FALSE;              /* Do not list any more files/dirs */
  1273.     return(NULL);
  1274.   }
  1275.   else
  1276.   {
  1277.     /* If file/dirname is not too long, we copy it into new stucture: */
  1278.     if(strlen(info->fib_FileName) < 28)
  1279.       strcpy(pointer->name, info->fib_FileName);
  1280.     else
  1281.     {
  1282.       /* The file/directory name is too long! */
  1283.       if( directory(info))   request_ok(errors[17]);   /* It's a dir  */
  1284.       else                   request_ok(errors[5]);    /* It's a file */
  1285.       FreeMem( pointer, sizeof(struct file_info));
  1286.       return(NULL);
  1287.     }
  1288.     if( directory(info))        /* Is it a file or a directory? */
  1289.       pointer->directory=TRUE;  /* It is a directory. */
  1290.     else    
  1291.       pointer->directory=FALSE; /* It is a file. */
  1292.   }
  1293.   return( (APTR) pointer);
  1294. }
  1295.  
  1296. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1297. /* Will check a FileInfoBlock if it is a file or a directory. */
  1298. /* Return TRUE if it is a directory, FALSE if it is a file.   */
  1299. BOOL directory(struct FileInfoBlock *info)
  1300. {
  1301.   if(info->fib_DirEntryType<0)   return(FALSE);
  1302.   else                           return(TRUE);
  1303. }
  1304.  
  1305. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1306. /* Put the new structure into the dynamically allocated list at the */
  1307. /* right place (sorted alphabetically, directories first):          */
  1308. void put_in(struct file_info *a_pointer, struct file_info *pointer)
  1309. {
  1310.   struct file_info *old_pointer=NULL;
  1311.  
  1312.   /* Move slowly down the list and try to fit in the structure: */
  1313.   while(a_pointer && file_comp(a_pointer, pointer))   /* ->name */
  1314.   {
  1315.     old_pointer=a_pointer;   a_pointer=a_pointer->next;
  1316.   }
  1317.   if(a_pointer)
  1318.   {
  1319.     if(old_pointer)
  1320.     {
  1321.       /* Put the structure into the list: */
  1322.       pointer->next=old_pointer->next;    old_pointer->next=pointer;
  1323.     }
  1324.     else
  1325.     {
  1326.       pointer->next=first_pointer;   first_pointer=pointer;
  1327.     }
  1328.   }
  1329.   else
  1330.   {
  1331.     /* Last int the list: */
  1332.     old_pointer->next=pointer;   pointer->next=NULL;
  1333.   }
  1334. }
  1335.  
  1336. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1337. /* This function will return TRUE if the first pointer (a_pointer) */
  1338. /* points to a file structure which should come before the second  */
  1339. /* pointers file structure.                                        */
  1340. /* ORDER:   1. DIRECTORIES sorted alphabetically. */
  1341. /*          2. FILES       sorted alphabetically. */
  1342.  
  1343. BOOL file_comp(struct file_info *a_pointer, struct file_info *pointer)
  1344. {
  1345.   if(a_pointer->directory == FALSE && pointer->directory)
  1346.     return(FALSE);
  1347.     
  1348.   if(a_pointer->directory == pointer->directory)
  1349.   {
  1350.     if(stricmp(a_pointer->name, pointer->name) <= 0 )   return(TRUE);
  1351.     else                                                return(FALSE);
  1352.   } 
  1353.   return(TRUE);
  1354. }
  1355.  
  1356. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1357. /* Give this function a string and a character, and it will return a */
  1358. /* pointer to the right most occurance character in you string which */
  1359. /* match your character.                                             */
  1360. STRPTR right_pos(STRPTR string, char sign)
  1361. {
  1362.   STRPTR start_pos;
  1363.   
  1364.   start_pos=string;
  1365.   while(*string != '\0')                         string++;
  1366.   /* Start to go backwards and check teh string: */
  1367.   while(*string != sign && string > start_pos)   string--;
  1368.   if(*string==sign)
  1369.     return(string);        /* We have found a matching character. */
  1370.   return(NULL);            /* We could not find a matching character. */
  1371. }
  1372.  
  1373. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1374. /* This function will change to a new device, for example df0:. */
  1375. /* Does not return anything.                                    */
  1376. void change_device(STRPTR device)
  1377. {
  1378.   strcpy(drawer_name, device);  /* Change the drawer string.  */
  1379.   adjust_string_gadgets();      /* Adjust the string gadgets. */
  1380.   new_drawer();                 /* Showing the new files/directories */
  1381. }
  1382.  
  1383. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1384. /* When the user or the program has changet the drawer string, this      */
  1385. /* function is called, and will do what is necessary to start to collect */
  1386. /* the new files/directories from the disk.                              */
  1387. /* Returns TRUE if everything is OK, and FALSE if something went wrong   */
  1388. BOOL new_drawer(void)
  1389. {
  1390.   STRPTR string_pointer;
  1391.  
  1392.   if(file_lock)   { UnLock(lock);   file_lock=FALSE; }
  1393.   deallocate_file_info();
  1394.  
  1395.   ModifyProp
  1396.   (
  1397.     &gadget_proportional, /* PropGadget */
  1398.     file_window,          /* Pointer */
  1399.     NULL,                 /* Requester */
  1400.     prop_info.Flags,      /* Flags */
  1401.     0,                    /* HorizPot */
  1402.     0,                    /* VertPot */
  1403.     0,                    /* HorizBody */
  1404.     (ULONG) 0xFFFF        /* VerBody */
  1405.   );
  1406.   display_list(0);        /* Clear the display: */
  1407.   more_files=FALSE;
  1408.   if((lock=Lock(drawer_name, ACCESS_READ))==NULL)
  1409.   {
  1410.     /* We could NOT lock the file/dir/device!  Inform the user: */
  1411.     string_pointer=drawer_name+strlen(drawer_name)-1;
  1412.     if(*string_pointer==':')  request_ok(errors[6]);
  1413.     else                      request_ok(errors[7]);
  1414.     return(FALSE);        /* ERROR */
  1415.   }
  1416.   else
  1417.   {
  1418.     file_lock=TRUE;          /* We "locked" the file/directory! */
  1419.   }
  1420.  
  1421.   /* Now try to get some information from the file/directory: */
  1422.   if((Examine(lock, file_info))==NULL)
  1423.     { request_ok(errors[18]);   return(FALSE); }
  1424.  
  1425.   if(directory(file_info))   /* Is it a directory or a file? */
  1426.   {
  1427.     /* It is a directory:    We will look for more files: */
  1428.     more_files=TRUE;
  1429.   }
  1430.   else   { request_ok(errors[15]);   return(FALSE);  } /* It's a file! */
  1431.   return(TRUE);
  1432. }
  1433. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1434. /* The function parent() will try to go backwards one step in the     */
  1435. /* directory path.    Does not return anything.                       */
  1436. void parent(void)
  1437. {
  1438.   STRPTR string_pointer;
  1439.  
  1440.   /* Separate the last directory from the path: */
  1441.   if(string_pointer=right_pos(drawer_name, '/'))
  1442.   {
  1443.     *string_pointer='\0';    /* Take away the last directory: */
  1444.   }
  1445.   else
  1446.   {
  1447.     if(string_pointer=right_pos(drawer_name, ':'))
  1448.     {
  1449.       /* Take away the last directory: */
  1450.       /* Only the device ("df0:" for example) left: */
  1451.       *(string_pointer+1)='\0';
  1452.     }
  1453.     else
  1454.     {
  1455.       *drawer_name='\0';
  1456.     }
  1457.   }
  1458.  
  1459.   adjust_string_gadgets();
  1460.   new_drawer();              /* Show user files etc in the new dir: */
  1461. }
  1462.  
  1463. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1464. /* You give this function a pointer to an error string and it'll open */
  1465. /* a simple requester displaying the message. Requester will go away  */
  1466. /* first when user has selected the button "OK".                      */
  1467. void request_ok(STRPTR message)
  1468. {
  1469.   text_request.IText=message;
  1470.   AutoRequest
  1471.   (
  1472.     file_window,   /* Window */
  1473.     &text_request, /* BodyText */
  1474.     NULL,          /* PositiveText nothing */
  1475.     &ok_request,   /* NegativeText OK */
  1476.     NULL, NULL,    /* PositiveFlags, NegativeFlags */
  1477.     320, 65        /* Width, Height*/
  1478.   );
  1479.   gadget_flag=ABORT;
  1480. }
  1481.  
  1482. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1483. /* This function will give user advices on the drag bar how to go on  */
  1484. void request_ask(STRPTR message)
  1485. {
  1486.   SetAPen(file_window->RPort,2);      SetBPen(file_window->RPort,3);
  1487.   SetDrMd(file_window->RPort,JAM2);   Move(file_window->RPort,6,7);
  1488.   Text(file_window->RPort, message, strlen(message));
  1489.   OffGadget(&gadget_rename, file_window, NULL);
  1490.   OffGadget(&gadget_delete, file_window, NULL);
  1491. }
  1492. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1493. /* This function displays files etc which are inside the dir, starting */
  1494. /* with the file number start_pos.   Does not return anything.         */
  1495. void display_list(int start_pos)
  1496. {
  1497.   struct file_info *pointer;
  1498.   int    pos, temp1;
  1499.                     /* 123456789012345678901234567890123 */
  1500.   char   empty_name[]="                                 ";
  1501.   STRPTR string_pointer;
  1502.   BOOL   clear;
  1503.   
  1504.   pos=0;
  1505.   if(first_pointer)          /* Does it exist any files at all? */
  1506.   {
  1507.     pointer=first_pointer;
  1508.  
  1509.     /* Go through the list until you have found the file/directory */
  1510.     /* which should be shown first:                                */
  1511.     while(pointer && pos < start_pos)
  1512.     {
  1513.       pos++;
  1514.       pointer=pointer->next;
  1515.     }
  1516.     pos=0;
  1517.     while(pointer && pos<8)  /* Try to show the eight files: */
  1518.     {
  1519.       strcpy(display_text[pos], pointer->name);
  1520.       clear=FALSE;   temp1=0;
  1521.       string_pointer=display_text[pos];
  1522.       if(pointer->directory)                    /* It is a directory: */
  1523.       {
  1524.         text_list[pos].FrontPen=3;              /* Highlight it. */
  1525.  
  1526.         /* Clear everything after the name, and add string "(Dir)" */
  1527.         while(temp1 < 28)
  1528.         {
  1529.           if(*string_pointer=='\0')   clear=TRUE;
  1530.           if(clear)                   *string_pointer=' ';
  1531.           string_pointer++;  temp1++;
  1532.         }
  1533.         *string_pointer='\0';  strcat(display_text[pos], "(Dir)");
  1534.       }
  1535.       else   text_list[pos].FrontPen=1;         /* It is a file: */
  1536.       {
  1537.  
  1538.         /* Clear everything after the name: */
  1539.         while(temp1 < 33)
  1540.         {
  1541.           if(*string_pointer=='\0')   clear=TRUE;
  1542.           if(clear)                   *string_pointer=' ';
  1543.           string_pointer++;   temp1++;
  1544.         }
  1545.         *string_pointer='\0';
  1546.       }
  1547.       pos++;   pointer=pointer->next;           /* Next. */
  1548.     }
  1549.   }
  1550.  
  1551.   /* If there are less than 8 files, show clear rest of the display: */
  1552.   while(pos < 8)
  1553.   {
  1554.     strcpy(display_text[pos], empty_name);   pos++;
  1555.   }
  1556.   
  1557.   /* Show the user the new display: */
  1558.   PrintIText(file_window->RPort, text_list, 16, 54);
  1559. }
  1560.  
  1561. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1562. /* User has selected a file or a directory.  If it is a file put it   */
  1563. /* into the file string, otherwise put it into the drawer string.     */
  1564. /* Returns TRUE if everything went OK, FALSE if there was a problem.  */
  1565. BOOL pick_file(int file_pos)
  1566. {
  1567.   struct file_info  *pointer=NULL;
  1568.   STRPTR            string_pointer;
  1569.   int               pos=0;
  1570.   
  1571.   /* Go through the allocated list untill we find the file/directory: */
  1572.   if(first_pointer)
  1573.   {
  1574.     pointer=first_pointer;
  1575.     
  1576.     while(pointer && pos < file_pos)
  1577.     {
  1578.       pos++;   pointer=pointer->next;
  1579.     }
  1580.   }
  1581.   if(pointer)                /* Have we found the file/directory? */
  1582.   {
  1583.     if(pointer->directory)   /* It's a directory! */
  1584.     {
  1585.       /* Is the drawer_name string long enough? */
  1586.       /* (+2: 1 for the NULL ('\0') character, 1 for the '\' char) */
  1587.       if((strlen(pointer->name)+strlen(drawer_name)+2) <= DRAWER_LENGTH)
  1588.       {
  1589.         /* YES!, there is enough room for it. */
  1590.         string_pointer=drawer_name+strlen(drawer_name)-1;
  1591.         if(*string_pointer==':' || *string_pointer=='\0' )
  1592.           strcat(drawer_name, pointer->name);
  1593.         else
  1594.         {
  1595.           /* We need to add a '/' before we can add the directory. */
  1596.           strcat(drawer_name, "/");
  1597.           strcat(drawer_name, pointer->name);
  1598.         }
  1599.         adjust_string_gadgets();
  1600.       }
  1601.       else   { request_ok(errors[16]);   return(FALSE); }
  1602.       new_drawer();
  1603.       return(TRUE);          /* OK */
  1604.     }
  1605.     else
  1606.     {
  1607.       /* It is a File! */
  1608.       /* Is the file_name string long enough? */
  1609.       /* (+1 for the NULL ('\0') character.) */
  1610.       if((strlen(pointer->name)+1) <= FILE_LENGTH)
  1611.       {
  1612.         strcpy(file_name, pointer->name);
  1613.         adjust_string_gadgets();
  1614.       }
  1615.       else         /* The file_name is NOT big enough! */
  1616.       {
  1617.         request_ok(errors[5]);   return(FALSE);
  1618.       }
  1619.       return(TRUE);
  1620.     }
  1621.   }
  1622. }
  1623.  
  1624. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1625. /* Adjust the string gadgets, so user can  at least see the last      */
  1626. /* 28/22 characters.   Does not return anything.                      */
  1627. void adjust_string_gadgets(void)
  1628. {
  1629.   int length;
  1630.  
  1631.   length=strlen(file_name);
  1632.   if(length>28)   string_file.DispPos=length-28;
  1633.   else            string_file.DispPos=0;
  1634.   string_file.BufferPos=string_file.DispPos;
  1635.   length=strlen(drawer_name);
  1636.  
  1637.   if(length>22)   string_drawer.DispPos=length-22;
  1638.   else            string_drawer.DispPos=0;
  1639.   string_drawer.BufferPos=string_drawer.DispPos;
  1640.   RefreshGadgets(&gadget_file, file_window, NULL);
  1641. }
  1642.  
  1643. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1644. /* Returns TRUE if there exist a file name, otherwise FALSE.          */
  1645. BOOL last_check(STRPTR name)
  1646. {
  1647.   if(*file_name=='\0')
  1648.   {
  1649.     request_ok(errors[8]);   return(FALSE);     /* No file name! */
  1650.   }
  1651.   else
  1652.   {
  1653.     connect_dir_file(name);  /* Change total_file_name. Drawer + File */
  1654.   }
  1655.   return(TRUE);
  1656. }
  1657.  
  1658. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1659. /* This function will connect the drawer string with the file string. */
  1660. /* Does not return anything.                                          */
  1661. void connect_dir_file(STRPTR name)
  1662. {
  1663.   STRPTR string_pointer;
  1664.  
  1665.   strcpy(name, drawer_name);
  1666.   if(*file_name!='\0')       /* Does it exist a file name? */
  1667.   {
  1668.     string_pointer=drawer_name+strlen(drawer_name)-1;
  1669.     if(*string_pointer==':'||*string_pointer=='\0' )
  1670.     {
  1671.       strcat(name, file_name);
  1672.     }
  1673.     else   { strcat(name, "/");   strcat(name, file_name); }
  1674.   }
  1675. }
  1676.  
  1677. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1678. void delete_file_dir(STRPTR total_file_name)
  1679. {
  1680.  
  1681.   if(*file_name=='\0' && *drawer_name!='\0')
  1682.   {
  1683.     /* There is no filename string, but there is something in  */
  1684.     /* the drawer string. The user wants to delete a directory */
  1685.  
  1686.     /* Is it a device or a directory? */
  1687.     if( *(drawer_name+strlen(drawer_name)-1) ==':')
  1688.     {
  1689.       /* The user wants to delete a device: */
  1690.       /* Not a very good idea! */
  1691.       request_ok(errors[9]);
  1692.     }
  1693.     else           /* The user wants to delete a dir:    */
  1694.     {
  1695.       /* However, it is important to check that the user */
  1696.       /* realy wants to delete it:                       */
  1697.       request_ask(errors[0]);
  1698.       if(gadget_flag==TAKE)
  1699.       {
  1700.         /* YES! The user wanted to delete the directory.  */
  1701.         /* Before we try to delete it we must "unlock" it */
  1702.         if(file_lock)
  1703.         {
  1704.           UnLock(lock);   file_lock=FALSE;
  1705.         }
  1706.       }
  1707.     }
  1708.   }
  1709.   else
  1710.   {
  1711.     if(*file_name!='\0')
  1712.     {
  1713.       /* There is something in the file_name string. */
  1714.       /* The user wants to delete a file:            */
  1715.       
  1716.       /* We will here again give the user a last */
  1717.       /* chance to  make up his mind:            */
  1718.       request_ask(errors[1]);
  1719.       }
  1720.     else
  1721.     {
  1722.       /* Nothing in the drawer string, nor in the file string. */
  1723.       /* The user wants to delete something, but has NOT       */
  1724.       /* declared which file/directory he/she wants to delete: */
  1725.       request_ok(errors[8]);
  1726.     }
  1727.   }
  1728.   if(gadget_flag==TAKE)              /* Should we delete the file/dir? */
  1729.   {
  1730.     /* Put the drawer name together with the file name: */
  1731.     connect_dir_file(total_file_name);
  1732.     if(DeleteFile(total_file_name))
  1733.     {
  1734.       if(*file_name!='\0')   /* A file was deleted sucessfully: */
  1735.       {
  1736.         *file_name='\0';     /* Take away the file name */
  1737.         adjust_string_gadgets();
  1738.         new_drawer();        /* Show remaining files to user */
  1739.       }
  1740.       else                   /* A directory was deleted: */
  1741.       {
  1742.         parent();            /* Go back one directory */
  1743.       }
  1744.     }
  1745.     else                     /* Something went wrong: */
  1746.     {
  1747.       if(*file_name != '\0')   request_ok(errors[11]);
  1748.       else                     request_ok(errors[12]);
  1749.       
  1750.       /* Since we have unlocked the directory/file we have */
  1751.       /* to lock it again, and clean up the display:       */
  1752.       new_drawer();
  1753.     }
  1754.   }
  1755. }
  1756. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1757. void rename_file_dir(STRPTR total_file_name)
  1758. {
  1759.   /* Presume the user do not want to rename file/dir: */
  1760.   if(ren==1)
  1761.   {
  1762.      if(*file_name=='\0' && *drawer_name!='\0')
  1763.      {
  1764.         /* There is no filename string, but there is something in  */
  1765.         /* the drawer string. The user wants to rename a directory */
  1766.  
  1767.         /* Is it a device or a directory? */
  1768.         if( *(drawer_name+strlen(drawer_name)-1) ==':')
  1769.         {
  1770.            /* The user wants to rename a device: */
  1771.            /* Not a very good idea! */
  1772.            request_ok(errors[10]);
  1773.         }
  1774.         else                 /* The user wants to rename a directory: */
  1775.         {
  1776.            request_ask(errors[2]);
  1777.            strcpy(total_file, drawer_name);
  1778.            total_file_name1=(STRPTR)(&total_file);
  1779.            /* YES! The user wanted to rename the directory.  */
  1780.            /* Before we try to rename it we must "unlock" it */
  1781.            if(file_lock)    { UnLock(lock);   file_lock=FALSE; }
  1782.         }
  1783.      }
  1784.      else
  1785.      {
  1786.         if(*file_name!='\0')    /*File selected */
  1787.         {
  1788.            /* There is something in the file_name string. */
  1789.            /* The user wants to rename a file:            */
  1790.  
  1791.            request_ask(errors[3]);
  1792.            connect_dir_file(total_file_name);
  1793.            strcpy(total_file,total_file_name);
  1794.            total_file_name1=(STRPTR)(&total_file);
  1795.         }
  1796.         else          /* Nothing in drawer string, nor in file string */
  1797.         {
  1798.                request_ok(errors[8]);
  1799.         }
  1800.      }
  1801.   }
  1802. /*­­­*****­­­­­­­*****­­­­­­­­­*****­­­­­­­­­­*****­­­­­­­­­*****­­­­­*/
  1803.   if(ren==2) 
  1804.   {
  1805.      connect_dir_file(total_file_name);
  1806.      if(Rename(total_file_name1, total_file_name))
  1807.      {
  1808.         if(*file_name!='\0') /* File was renamed succecfully: */
  1809.         {
  1810.            adjust_string_gadgets();
  1811.            new_drawer();     /* Show user the remaining files. */
  1812.         }
  1813.         else                 /* A directory was renamed: */
  1814.         {
  1815.            parent();         /* Go back one directory.   */
  1816.         }
  1817.      }
  1818.      else                    /* Something went wrong:    */
  1819.      {
  1820.         if(*file_name!='\0')   request_ok(errors[13]);
  1821.         else                   request_ok(errors[14]);
  1822.  
  1823.         /* Since we have unlocked the directory/file we have */
  1824.         /* to lock it again, and clean up the display:       */
  1825.         new_drawer();
  1826.      }
  1827.   }
  1828. }
  1829. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1830. USHORT clear_gadgets(STRPTR title)
  1831. {
  1832.      OnGadget(&gadget_rename, file_window, NULL);
  1833.      OnGadget(&gadget_delete, file_window, NULL);
  1834.      SetWindowTitles(file_window, title, (char *)(-1));
  1835.      ren=0;   gadget_flag=CLEAR;   return(CLEAR);
  1836. }
  1837. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1838. /*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
  1839.  
  1840.  
  1841.  
  1842.  
  1843.