コード例 #1
0
ファイル: qftp.c プロジェクト: AlekseyGerbyn/FTPKit
int main(int argc, char *argv[])
{
    int files_processed = 0;
    int opt;

    invocation = argv[0];
    optind = 1;
    if (strstr(argv[0],"send") != NULL)
	action = FTP_SEND;
    else if (strstr(argv[0],"get") != NULL)
	action = FTP_GET;
    else if (strstr(argv[0],"dir") != NULL)
	action = FTP_DIR;
    else if (strstr(argv[0],"list") != NULL)
	action = FTP_LIST;
    else if (strstr(argv[0],"rm") != NULL)
	action = FTP_RM;
    if ((action == 0) && (argc > 2))
    {
	if ( argc < 3 )		/* command + site */
	{
	    usage();
	    exit( EX_SYNTAX );
	}
	if (strcmp(argv[1],"send") == 0)
	    action = FTP_SEND;
    	else if (strcmp(argv[1],"get") == 0)
	    action = FTP_GET;
    	else if (strcmp(argv[1],"dir") == 0)
	    action = FTP_DIR;
	else if (strcmp(argv[1],"list") == 0)
	    action = FTP_LIST;
    	else if (strcmp(argv[1],"rm") == 0)
	    action = FTP_RM;
	if (action)
	    optind++;
    }
    if (action == 0)
    {
	usage();
	exit(EX_SYNTAX);
    }

    FtpInit();

    //    while (argv[optind] != NULL)
    while ( optind < argc )
    {
	if (argv[optind][0] != '-')
	{
	    if (host == NULL)
		host = argv[optind++];
	    else
	    {
		process_file(argv[optind++]);
		files_processed++;
	    }
	    continue;
	}
	opt = getopt(argc,argv,"abil:m:p:r:s:v:w");
	switch (opt)
	{
	  case '?' :
	    fprintf(stderr,"Invalid option: %c\n", opt);
	    usage();
	    exit(EX_SYNTAX);
	  case ':' :
	    usage();
	    exit(EX_SYNTAX);
	  case 'a' : mode = 'A'; break;
	  case 'b' : strippath = !strippath; break;
	  case 'i' : mode = 'I'; break;
	  case 'l' : user = optarg; break;
	  case 'm' : set_umask(optarg); break;
	  case 'p' : pass = optarg; break;
	  case 'r' : change_directory(optarg); break;
	  case 's' : site_cmd(optarg); break;
	  case 'v' :
	    if (opt == ':')
		ftplib_debug++;
	    else
		ftplib_debug = atoi(optarg);
	    break;
	  case 'w' : wildcard = !wildcard; break;
	  default :
	    usage();
	    exit(EX_SYNTAX);
	}
    }

    if (files_processed == 0)
    {
	ftp_connect();
	if ((action == FTP_DIR) || (action == FTP_LIST))
	    process_file(NULL);
	else
	{
	    char fnm[256];
	    do
	    {
	        char *nl;
		if (isatty(fileno(stdin)))
		    printf("file> ");
		if (fgets(fnm, sizeof(fnm), stdin) == NULL)
		    break;
		if ((nl = strchr(fnm,'\n')) != NULL)
		    *nl = '\0';
		process_file(fnm);
	    }
	    while (1);
	}
    }
    if (conn)
	FtpClose(conn);
    return 0;
}
コード例 #2
0
ファイル: run-parts.c プロジェクト: adragomir/dotfiles
/* Process options */
int main(int argc, char *argv[])
{
  umask(022);
  add_argument(0);

  for (;;) {
    int c;
    int option_index = 0;

    static struct option long_options[] = {
      {"test", 0, &test_mode, 1},
      {"list", 0, &list_mode, 1},
      {"verbose", 0, 0, 'v'},
      {"report", 0, &report_mode, 1},
      {"reverse", 0, &reverse_mode, 1},
      {"umask", 1, 0, 'u'},
      {"arg", 1, 0, 'a'},
      {"help", 0, 0, 'h'},
      {"version", 0, 0, 'V'},
      {"lsbsysinit", 0, &lsbsysinit_mode, 1},
      {"exit-on-error", 0, &exit_on_error_mode, 1},
      {0, 0, 0, 0}
    };

    c = getopt_long(argc, argv, "u:ha:vV", long_options, &option_index);
    if (c == EOF)
      break;
    switch (c) {
    case 0:
      break;
    case 'u':
      set_umask();
      break;
    case 'a':
      add_argument(optarg);
      break;
    case 'h':
      usage();
      break;
    case 'v':
      verbose_mode = 1;
      break;
    case 'V':
      version();
      break;
    default:
      fprintf(stderr, "Try `run-parts --help' for more information.\n");
      exit(1);
    }
  }

  /* We require exactly one argument: the directory name */
  if (optind != (argc - 1)) {
    error("missing operand");
    fprintf(stderr, "Try run-parts --help' for more information.\n");
    exit(1);
  }

  if (list_mode && test_mode) {
    error("--list and --test can not be used together");
    fprintf(stderr, "Try run-parts --help' for more information.\n");
    exit(1);
  }

  run_parts(argv[optind]);

  return exitstatus;
}