home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff284.lzh / Dme / src / filereq.c < prev    next >
C/C++ Source or Header  |  1989-11-27  |  2KB  |  126 lines

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