home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 411b.lha / dme_1.42 / src.LZH / src / filereq.c < prev    next >
C/C++ Source or Header  |  1990-08-20  |  2KB  |  125 lines

  1.  
  2. /*
  3.  *  ARP interface (ARPLOAD, ARPSAVE)
  4.  */
  5.  
  6. #include "defs.h"
  7. #include <libraries/dos.h>
  8.  
  9. void
  10. do_arpinsfile()
  11. {
  12.     char file[64];
  13.     char dir[64];
  14.     BPTR oldlock = CurrentDir((BPTR)Ep->dirlock);
  15.  
  16.     splitpath(Ep->Name, file, dir);
  17.     if (arpreq("Insert File", file, dir, NULL)) {
  18.     CurrentDir(oldlock);
  19.     fixfile(file, dir);
  20.     av[0] = (ubyte *)"i";
  21.     av[1] = (ubyte *)file;
  22.     do_edit();
  23.     return;
  24.     }
  25.     CurrentDir(oldlock);
  26. }
  27.  
  28. void
  29. do_arpload()
  30. {
  31.     char file[64];
  32.     char dir[64];
  33.     BPTR oldlock = CurrentDir((BPTR)Ep->dirlock);
  34.  
  35.     splitpath(Ep->Name, file, dir);
  36.     if (arpreq("New File", file, dir, NULL)) {
  37.     BPTR newlock;
  38.     if (newlock = Lock(dir, SHARED_LOCK)) {
  39.         UnLock(CurrentDir(oldlock));
  40.         Ep->dirlock = (long)newlock;
  41.         /*
  42.         fixfile(file,dir);
  43.         */
  44.         av[0] = (ubyte *)"n";
  45.         av[1] = (ubyte *)file;
  46.         do_edit();
  47.         return;
  48.     }
  49.     }
  50.     CurrentDir(oldlock);
  51. }
  52.  
  53. void
  54. do_arpsave()
  55. {
  56.     char file[64];
  57.     char dir[64];
  58.     BPTR oldlock = CurrentDir((BPTR)Ep->dirlock);
  59.  
  60.     splitpath(Ep->Name, file, dir);
  61.     if (arpreq("Save File", file, dir, NULL)) {
  62.     CurrentDir(oldlock);
  63.     fixfile(file,dir);
  64.     av[1] = (ubyte *)file;
  65.     do_saveas();
  66.     } else {
  67.     CurrentDir(oldlock);
  68.     }
  69. }
  70.  
  71. void
  72. fixfile(file,dir)
  73. char *file,*dir;
  74. {
  75.     char *ptr;
  76.     short len = strlen(dir);
  77.     char hasdev = 0;
  78.  
  79.     /*
  80.      *    do we need to add a slash to the directory spec?
  81.      */
  82.  
  83.     if (len && dir[len-1] != '/' && dir[len-1] != ':') {
  84.     dir[len++] = '/';
  85.     dir[len] = 0;
  86.     }
  87.  
  88.     /*
  89.      *    Is file spec really a full path spec?
  90.      */
  91.  
  92.     for (ptr = file; *ptr; ++ptr) {
  93.     if (ptr[0] == ':')
  94.         hasdev = 1;
  95.     }
  96.     if (!hasdev) {
  97.     movmem(file,file+len,strlen(file)+1);
  98.     movmem(dir,file,len);
  99.     }
  100. }
  101.  
  102. /*
  103.  *  Search backwards for first ':' or '/' and split path there.
  104.  *  This subroutine may appear to be coded incorrectly to a novice
  105.  *  programmer.  It isn't [now].
  106.  */
  107.  
  108. void
  109. splitpath(name, file, dir)
  110. char *name;
  111. char *file, *dir;
  112. {
  113.     short i;
  114.  
  115.     for (i = strlen(name); i >= 0; --i) {       /* was (incorrectly) "i > 0" */
  116.     if (name[i] == ':' || name[i] == '/')
  117.         break;
  118.     }
  119.     ++i;
  120.     strcpy(file, name + i);
  121.     movmem(name, dir, i);
  122.     dir[i] = 0;
  123. }
  124.  
  125.