home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / flistfrontend / src / flcopy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-06  |  3.9 KB  |  137 lines

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: flcopy.c,v 1.4 1995/06/06 00:38:10 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    flcopy.c
  7.  * Author:    Thomas E. Dickey
  8.  * Created:    11 Jul 1984
  9.  * Last update:
  10.  *        18 Mar 1995, prototypes
  11.  *        24 Aug 1985, use 'dds_add2' instead of 'dirdata_one'
  12.  *        19 Jul 1985, use 'dirdata_one', corrected "COPY / ;" results for
  13.  *                 /NOVERSION (file appears to have been in list already).
  14.  *        03 Jul 1985, cleanup 'filelist' definition
  15.  *        11 Jun 1985, added cli-argument to dds_spawn
  16.  *        14 Dec 1984, added nam-argument to 'dirent_chop'
  17.  *        03 Sep 1984, use "import"
  18.  *        25 Aug 1984
  19.  *        26 Jul 1984, modified 'dirseek()'
  20.  *        25 Jul 1984, amended REPLACE-clause
  21.  *        18 Jul 1984
  22.  *
  23.  * Function:    Spawn an external process (COPY or APPEND).  This references
  24.  *        multiple input files, and a single (for simplicity) output
  25.  *        file.  Update the output file on the screen on completion of
  26.  *        the command.
  27.  *
  28.  *        The inputs need not be members of 'filelist[]', since they
  29.  *        are not modified.
  30.  *
  31.  * Patch:    The version-defaulting of COPY differs slightly from other VMS
  32.  *        commands.  If the files X and Y exist (same version numbers),
  33.  *        then the commands
  34.  *
  35.  *            COPY X Y
  36.  *            COPY X; Y
  37.  *
  38.  *        are treated differently.  The first command creates a new
  39.  *        version (Y;"+1") with no complaint.  The second complains about
  40.  *        conflicting version numbers and does not do the copy.
  41.  *
  42.  * Patch:    Another problem is equally annoying, but could be fixed:
  43.  *        Suppose there are two files X.C;1 and Y.C;2, and that I issue
  44.  *        the command
  45.  *
  46.  *            COPY / Y  (implicitly "COPY X.C;1 Y" => Y.C;)
  47.  *
  48.  *        Then I get an error message from COPY about a higher version,
  49.  *        but (since I am basically checking only for new highest
  50.  *        version), my code doesn't see the new lower version.
  51.  */
  52.  
  53. #include    <string.h>
  54.  
  55. #include    "flist.h"
  56. #include    "dirent.h"
  57. #include    "dircmd.h"
  58. #include    "dirseek.h"
  59. #include    "dds.h"
  60.  
  61. import(filelist);
  62. import(V_opt);
  63.  
  64. tDIRCMD(flcopy)
  65. {
  66.     FILENT    znew,    *z = &znew;
  67.     char    *out_    = dclinx (xdcl_, 2, 0),
  68.         filespec[MAX_PATH];
  69.     int    oldinx    = dirent_old (out_, 0),    /* is >= 0 if in 'filelist[]'    */
  70.         newinx,
  71.         cp_cmd    = (strcmp ("COPY", xdcl_->dcl_text) == 0);
  72.  
  73.     /*
  74.      * Verify that all of the inputs exist, and that the output's
  75.      * directory is writeable:
  76.      */
  77.     dds_while (nullC);    /* there may be a wait on the seek */
  78.     if (! dirseek (xcmd_, xdcl_, 1, TRUE))    return;
  79.  
  80.     /*
  81.      * Parse the output name, to obtain a full (or maximum) specification.
  82.      * At the very least, this will give the name of the directory of the
  83.      * output file, permitting me to verify that I can write in that
  84.      * directory before attempting the COPY.  Note that if no version is
  85.      * given, the chop'd form will be 0.
  86.      */
  87.     dirent_chop (&znew, out_, 0);
  88.     if (! diropen (zPATHOF(z)))        return;
  89.  
  90.     /*
  91.      * If all parameters are ok, perform the copy:
  92.      */
  93.     dds_spawn (0, *curfile_, xcmd_, 0, FALSE, 1);
  94.  
  95.     /*
  96.      * Now, update the directory display.  Unlike EDIT and RENAME, put
  97.      * the new entry elsewhere on the list (unless a REPLACE option was
  98.      * used, causing the old and new entries to be coincident).
  99.      */
  100.  
  101.     if (oldinx >= 0)    /* (Check for changes if COPY/REPLACE)    */
  102.     {
  103.         dirent_glue (filespec, FK_(oldinx));
  104.         dirent_chk (FK_(oldinx), filespec);
  105.         dds_line (oldinx);
  106.  
  107.                 /* Check further for new version    */
  108.         if ((newinx = dirent_old_any (&znew, out_, 0)) >= -1)
  109.         {
  110.             if (newinx == -1)
  111.             {
  112.                 if (V_opt)    dds_add (&znew);
  113.                 else        dirhigh (filespec);
  114.             }
  115.             else if (newinx != oldinx)
  116.                 dds_add2 (&znew, newinx);
  117.         }
  118.         /* (else, COPY failed) */
  119.     }
  120.     /*
  121.      * If I can find something here, I did indeed create a new file.
  122.      * However, if /NOVERSION is selected, display this only if there
  123.      * are no higher versions around.  If there is a lower version,
  124.      * overwrite the corresponding 'filelist[]' entry.
  125.      */
  126.     else if (dirent_chk (&znew, out_))
  127.     {
  128.         if ((oldinx = dirent_old (out_, 0)) < 0)
  129.         {
  130.             if (V_opt)    dds_add (&znew);
  131.             else        dirhigh (out_);
  132.         }
  133.         else
  134.             dds_add2 (&znew, oldinx);
  135.     }
  136. }
  137.