Patch from Marc Nijdam <marc_nijdam@hp.com>
> First (of many more) patch of cp_mv to getopt use. I'm using the most > simplistic approach, just get getopt used, then worry about a cleaner > option parsing style using getopt later. > > Marc
This commit is contained in:
parent
55380700d8
commit
f4c022649b
20
cp_mv.c
20
cp_mv.c
@ -41,6 +41,7 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#define is_cp 0
|
||||
#define is_mv 1
|
||||
@ -189,21 +190,21 @@ rm_Action(const char *fileName, struct stat *statbuf, void* junk)
|
||||
|
||||
extern int cp_mv_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char c;
|
||||
|
||||
if (*applet_name == 'c' && *(applet_name + 1) == 'p')
|
||||
dz_i = is_cp;
|
||||
else
|
||||
dz_i = is_mv;
|
||||
if (argc < 3)
|
||||
usage(cp_mv_usage[dz_i]);
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
if (dz_i == is_cp) {
|
||||
recursiveFlag = preserveFlag = forceFlag = FALSE;
|
||||
followLinks = TRUE;
|
||||
while (*argv && **argv == '-') {
|
||||
while (*++(*argv)) {
|
||||
switch (**argv) {
|
||||
while ((c = getopt(argc, argv, "adpRf")) != EOF) {
|
||||
switch (c) {
|
||||
case 'a':
|
||||
followLinks = FALSE;
|
||||
preserveFlag = TRUE;
|
||||
@ -224,11 +225,8 @@ extern int cp_mv_main(int argc, char **argv)
|
||||
default:
|
||||
usage(cp_mv_usage[is_cp]);
|
||||
}
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
if (argc < 2) {
|
||||
if ((argc - optind) < 2) {
|
||||
usage(cp_mv_usage[dz_i]);
|
||||
}
|
||||
} else { /* (dz_i == is_mv) */
|
||||
@ -252,12 +250,12 @@ extern int cp_mv_main(int argc, char **argv)
|
||||
goto exit_false;
|
||||
}
|
||||
|
||||
while (argc-- > 1) {
|
||||
for (i = optind; i < (argc-1); i++) {
|
||||
size_t srcLen;
|
||||
volatile int flags_memo;
|
||||
int status;
|
||||
|
||||
baseSrcName = *(argv++);
|
||||
baseSrcName=argv[i];
|
||||
|
||||
if ((srcLen = strlen(baseSrcName)) > BUFSIZ)
|
||||
name_too_long__exit();
|
||||
|
Loading…
x
Reference in New Issue
Block a user