void mmd(int argc, char **argv, int type) { Arg_t arg; int c; /* get command line options */ init_clash_handling(& arg.ch); /* get command line options */ if(helpFlag(argc, argv)) usage(0); while ((c = getopt(argc, argv, "i:D:oh")) != EOF) { switch (c) { case 'i': set_cmd_line_image(optarg); break; case '?': usage(1); case 'o': handle_clash_options(&arg.ch, c); break; case 'D': if(handle_clash_options(&arg.ch, *optarg)) usage(1); break; case 'h': usage(0); default: usage(1); break; } } if (argc - optind < 1) usage(1); init_mp(&arg.mp); arg.mp.arg = (void *) &arg; arg.mp.openflags = O_RDWR; arg.mp.callback = createDirCallback; arg.mp.lookupflags = OPEN_PARENT | DO_OPEN_DIRS; exit(main_loop(&arg.mp, argv + optind, argc - optind)); }
void mcopy(int argc, char **argv, int mtype) { Arg_t arg; int c, ret, fastquit; int todir; /* get command line options */ init_clash_handling(& arg.ch); /* get command line options */ todir = 0; arg.recursive = 0; #ifdef OS_Minix arg.preserveTime = 1; /* Copy file time as DOS does. */ #else arg.preserveTime = 0; #endif arg.preserveAttributes = 0; arg.nowarn = 0; arg.textmode = 0; arg.verbose = 0; arg.type = mtype; fastquit = 0; while ((c = getopt(argc, argv, "abB/sptnmvQD:o")) != EOF) { switch (c) { case 's': case '/': arg.recursive = 1; break; case 'p': arg.preserveAttributes = 1; break; case 'a': case 't': arg.textmode = 1; break; case 'n': arg.nowarn = 1; break; case 'm': arg.preserveTime = 1; break; case 'v': arg.verbose = 1; break; case 'Q': fastquit = 1; break; case 'B': case 'b': batchmode = 1; break; case 'o': handle_clash_options(&arg.ch, c); break; case 'D': if(handle_clash_options(&arg.ch, *optarg)) usage(); break; case '?': usage(); default: break; } } if (argc - optind < 1) usage(); init_mp(&arg.mp); arg.mp.lookupflags = ACCEPT_PLAIN | ACCEPT_DIR | DO_OPEN | NO_DOTS; arg.mp.fast_quit = fastquit; arg.mp.arg = (void *) &arg; arg.mp.openflags = O_RDONLY; /* last parameter is "-", use mtype mode */ if(!mtype && !strcmp(argv[argc-1], "-")) { arg.type = mtype = 1; argc--; } if(mtype){ /* Mtype = copying to stdout */ arg.mp.targetName = strdup("-"); arg.mp.unixTarget = strdup(""); arg.mp.callback = dos_to_unix; arg.mp.dirCallback = unix_copydir; arg.mp.unixcallback = unix_to_unix; } else { char *target; if (argc - optind == 1) { /* copying to the current directory */ target = "."; } else { /* target is the last item mentioned */ argc--; target = argv[argc]; } ret = target_lookup(&arg.mp, target); if(!arg.mp.targetDir && !arg.mp.unixTarget) { fprintf(stderr,"Bad target %s\n", target); exit(1); } /* callback functions */ if(arg.mp.unixTarget) { arg.mp.callback = dos_to_unix; arg.mp.dirCallback = directory_dos_to_unix; arg.mp.unixcallback = unix_to_unix; } else { arg.mp.dirCallback = dos_copydir; arg.mp.callback = dos_to_dos; arg.mp.unixcallback = unix_to_dos; } } exit(main_loop(&arg.mp, argv + optind, argc - optind)); }