commands.cc
/*
** copy_file - copy current file to destination. Update window appropriately.
*/
copy current file to destination. Update window appropriately.
copy current file to destination . Update window appropriately .
static void copy_file(DirList *dl, const char *src, const char *dest)
{
    const char *cp = "cp";
    const char *args[4];
    args[0] = cp; args[1] = src; args[2] = dest; args[3] = 0;
    if (is_regular_file(dest))
    {
        String msg = String("overwrite '") + dest + "'? (y|n) ";
        if (yes_or_no(msg))
            if (execute(cp, args))
            {
                message("`copy' was successful");
                if (in_same_directory(dl, dest))
                {
                     `dest\' is in our current directory.
                     It may contain /\'s due to .. or ~ funny business.
                    int pos = 0;
                    const char *slash = strrchr(dest, '/');
                    if (slash) dest   = slash + 1;
                    DirLine *found    = search(dl->firstLine(), dest, &pos);
                    if (found && pos < rows() - 2)
                    {
                         And it\'s also in our current window.
                        String cmd = String(ls_cmd[the_sort_order()]) + dest;
                        FILE *fp = popen(cmd, "r");
                        if (fp == 0)
                            error("File %s, line %d: popen(%s) failed",
                                  __FILE__, __LINE__, (const char *)cmd);
                        char *new_line = fgetline(fp);
                        if (new_line == 0)
                            error("File %s, line %d: fgetline() failed",
                                  __FILE__, __LINE__);
                        (void)pclose(fp);
                        update_screen_line(found->line(), new_line, pos);
                        found->update(&new_line);
                    }
                }
            }
            else
                message("`copy' failed");
        move_cursor(dl->savedYPos(), dl->savedXPos());
    }
    else if (is_directory(dest))
    {
        String file(dest);
        if (dest[strlen(dest) - 1] != '/') file += "/";
        file += src;
        if (is_regular_file(file))
        {
            String msg = String("overwrite `") + file + "'? (y|n) ";
            if (yes_or_no(msg))
                if (execute(cp, args))
                    message("`copy' was successful");
                else
                    message("`copy' failed");
        }
        else
        {
             Just do the `cp\'.
            if (execute(cp, args))
                message("`copy' was successful");
            else
                message("`copy' failed");
        }
        move_cursor(dl->savedYPos(), dl->savedXPos());
    }
    else
    {
         `dest\' doesn\'t already exist
        if (execute(cp, args))
        {
            message("`copy' was successful");
             Is `dest\' in our current directory?
            if (in_same_directory(dl, dest))
                insert_into_dirlist(dl, dest, dl->savedYPos());
            else
                move_cursor(dl->savedYPos(), dl->savedXPos());
        }
        else
        {
            message("`copy' failed");
            move_cursor(dl->savedYPos(), dl->savedXPos());
        }
    }
}
static void copy_file ( DirList * dl , const char * src , const char * dest ) { const char * cp = " " ; const char * args [ 4 ] ; args [ 0 ] = cp ; args [ 1 ] = src ; args [ 2 ] = dest ; args [ 3 ] = 0 ; if ( is_regular_file ( dest ) ) { String msg = String ( " " ) + dest + " " ; if ( yes_or_no ( msg ) ) if ( execute ( cp , args ) ) { message ( " " ) ; if ( in_same_directory ( dl , dest ) ) { int pos = 0 ; const char * slash = strrchr ( dest , ' ' ) ; if ( slash ) dest = slash + 1 ; DirLine * found = search ( dl -> firstLine ( ) , dest , & pos ) ; if ( found && pos < rows ( ) - 2 ) { String cmd = String ( ls_cmd [ the_sort_order ( ) ] ) + dest ; FILE * fp = popen ( cmd , " " ) ; if ( fp == 0 ) error ( " " , __FILE__ , __LINE__ , ( const char * ) cmd ) ; char * new_line = fgetline ( fp ) ; if ( new_line == 0 ) error ( " " , __FILE__ , __LINE__ ) ; ( void ) pclose ( fp ) ; update_screen_line ( found -> line ( ) , new_line , pos ) ; found -> update ( & new_line ) ; } } } else message ( " " ) ; move_cursor ( dl -> savedYPos ( ) , dl -> savedXPos ( ) ) ; } else if ( is_directory ( dest ) ) { String file ( dest ) ; if ( dest [ strlen ( dest ) - 1 ] != ' ' ) file += " " ; file += src ; if ( is_regular_file ( file ) ) { String msg = String ( " " ) + file + " " ; if ( yes_or_no ( msg ) ) if ( execute ( cp , args ) ) message ( " " ) ; else message ( " " ) ; } else { if ( execute ( cp , args ) ) message ( " " ) ; else message ( " " ) ; } move_cursor ( dl -> savedYPos ( ) , dl -> savedXPos ( ) ) ; } else { if ( execute ( cp , args ) ) { message ( " " ) ; if ( in_same_directory ( dl , dest ) ) insert_into_dirlist ( dl , dest , dl -> savedYPos ( ) ) ; else move_cursor ( dl -> savedYPos ( ) , dl -> savedXPos ( ) ) ; } else { message ( " " ) ; move_cursor ( dl -> savedYPos ( ) , dl -> savedXPos ( ) ) ; } } }
copy_file - copy current file to destination.
copy_file - copy current file to destination .
// // `dest\' is in our current directory. // It may contain /\'s due to .. or ~ funny business. // // // And it\'s also in our current window. // // // Just do the `cp\'. // // `dest\' doesn\'t already exist // // Is `dest\' in our current directory? //