sbase/cp.c
FRIGN 8dc92fbd6c Refactor enmasse() and recurse() to reflect depth
The HLP-changes to sbase have been a great addition of functionality,
but they kind of "polluted" the enmasse() and recurse() prototypes.
As this will come in handy in the future, knowing at which "depth"
you are inside a recursing function is an important functionality.

Instead of having a special HLP-flag passed to enmasse, each sub-
function needs to provide it on its own and can calculate results
based on the current depth (for instance, 'H' implies 'P' at
depth > 0).
A special case is recurse(), because it actually depends on the
follow-type. A new flag "recurse_follow" brings consistency into
what used to be spread across different naming conventions (fflag,
HLP_flag, ...).

This also fixes numerous bugs with the behaviour of HLP in the
tools using it.
2015-03-02 22:50:38 +01:00

58 lines
870 B
C

/* See LICENSE file for copyright and license details. */
#include <sys/stat.h>
#include "fs.h"
#include "util.h"
static void
usage(void)
{
eprintf("usage: %s [-afpv] [-R [-H | -L | -P]] source ... dest\n", argv0);
}
int
main(int argc, char *argv[])
{
struct stat st;
ARGBEGIN {
case 'a':
cp_HLPflag = 'P';
cp_aflag = cp_pflag = cp_rflag = 1;
break;
case 'f':
cp_fflag = 1;
break;
case 'p':
cp_pflag = 1;
break;
case 'r':
case 'R':
cp_rflag = 1;
break;
case 'v':
cp_vflag = 1;
break;
case 'H':
case 'L':
case 'P':
cp_HLPflag = ARGC();
break;
default:
usage();
} ARGEND;
if (argc < 2)
usage();
if (argc > 2) {
if (stat(argv[argc - 1], &st) < 0)
eprintf("stat %s:", argv[argc - 1]);
if (!S_ISDIR(st.st_mode))
eprintf("%s: not a directory\n", argv[argc - 1]);
}
enmasse(argc, argv, cp);
return cp_status;
}