예제 #1
0
파일: logger.c 프로젝트: tubav/impd4e
void logger_set_filter( char* s_filter ) {
   char* token;
   // prevent segmentation fault when there is no string
   s_filter = s_filter?s_filter:"";

   // read all filter values
   token = strtok( s_filter, "," );
   if( NULL != token ) {
      do {
         if( '-' == token[0] ) {
            // add to exclude list
            exclude_list = push_filter( exclude_list, ++token );
         }
         else {
            // add to include list
            include_list = push_filter( include_list, token );
         }
      }
      while( NULL != (token = strtok( NULL, "," )) );
   }
}
예제 #2
0
파일: logger.c 프로젝트: tubav/impd4e
filter_list_t* push_filter( filter_list_t* list, char* value ){
   if( NULL == list ) {
      list = (filter_list_t*) malloc( sizeof(filter_list_t) );
      list->next = NULL;
      list->value = value;
      // fprintf( stderr, "%s\n", list->value); // todo: remove when finish
   }
   else {
      // fprintf( stderr, "%s->", list->value); // todo: remove when finish
      list->next = push_filter( list->next, value );
   }
   return list;
}
예제 #3
0
파일: options.c 프로젝트: tdestro/psync
void
parseopts(int argc, char **argv)
{
	int c;

	/* initialize default option values */
	psc_dynarray_init(&opts.exclude);
	psc_dynarray_init(&opts.files);
	psc_dynarray_init(&opts.filter);
	psc_dynarray_init(&opts.include);
	opts.progress = 1;
	opts.psync_path = "psync";
	opts.rsh = "ssh "
	    "-oControlPath=none "
	    "-oCompression=no "
	    "-oKbdInteractiveAuthentication=no "
	    "-oNumberOfPasswordPrompts=1";
	opts.streams = getnstreams(getnprocessors());

	while ((c = getopt_long(argc, argv,
	    "0468aB:bCcDdEEe:f:gHhIiKkLlmN:nOoPpqRrST:tuVvWxyz", longopts,
	    NULL)) != -1) {
		switch (c) {
		case '0':		opts.from0 = 1;			break;
		case '4':		opts.ipv4 = 1;			break;
		case '6':		opts.ipv6 = 1;			break;
		case '8':		opts._8_bit_output = 1;		break;
		case 'a':		opts.devices = 1;
					opts.group = 1;
					opts.links = 1;
					opts.owner = 1;
					opts.perms = 1;
					opts.recursive = 1;
					opts.specials = 1;
					opts.times = 1;			break;
		case 'B':
			if (!parsesize(&opts.block_size, optarg, 1))
				err(1, "-B %s", optarg);
			break;
		case 'b':		opts.backup = 1;		break;
		case 'C':		opts.cvs_exclude = 1;		break;
		case 'c':		opts.checksum = 1;		break;
		case 'D':		opts.devices = 1;
					opts.specials = 1;		break;
		case 'd':		opts.dirs = 1;			break;
		case 'E':		opts.extended_attributes = 1;	break;
		case 'e':		opts.rsh = optarg;		break;
		case 'f':
			push_filter(&opts.filter, optarg, FPT_INCL);	break;
		case 'g':		opts.group = 1;			break;
		case 'H':		opts.hard_links = 1;		break;
		case 'h':		opts.human_readable = 1;	break;
		case 'I':		opts.ignore_times = 1;		break;
		case 'i':		opts.itemize_changes = 1;	break;
		case 'K':		opts.keep_dirlinks = 1;		break;
		case 'k':		opts.copy_dirlinks = 1;		break;
		case 'L':		opts.copy_links = 1;		break;
		case 'l':		opts.links = 1;			break;
		case 'm':		opts.prune_empty_dirs = 1;	break;
		case 'N':
			if (!parsenum(&opts.streams, optarg, 0, MAX_STREAMS))
				err(1, "streams: %s", optarg);
			break;
		case 'n':		opts.dry_run = 1;		break;
		case 'O':		opts.omit_dir_times = 1;	break;
		case 'o':		opts.owner = 1;			break;
		case 'P':		opts.progress = 1;
					opts.partial = 1;		break;
		case 'p':		opts.perms = 1;			break;
		case 'q':		opts.quiet = 1;			break;
		case 'R':		opts.relative = 1;		break;
		case 'r':		opts.recursive = 1;		break;
		case 'S':		opts.sparse = 1;		break;
		case 'T':		opts.temp_dir = optarg;		break;
		case 't':		opts.times = 1;			break;
		case 'u':		opts.update = 1;		break;
		case 'V':
			fprintf(stderr, "psync version %d\n", PSYNC_VERSION);
			exit(0);
			break;
		case 'v':		opts.verbose = 1;		break;
		case 'W':		opts.whole_file = 1;		break;
		case 'x':		opts.one_file_system = 1;	break;
		case 'y':		opts.fuzzy = 1;			break;
		case 'z':		opts.compress = 1;		break;
		case OPT_ADDRESS:	opts.address = optarg;		break;
		case OPT_BWLIMIT:
			if (!parsesize(&opts.bwlimit, optarg, 1024))
				err(1, "--bwlimit=%s", optarg);
			break;
		case OPT_CHMOD:		opts.chmod = optarg;		break;
		case OPT_COMPARE_DEST:	opts.compare_dest = optarg;	break;
		case OPT_COMPRESS_LEVEL:
			if (!parsenum(&opts.compress_level, optarg, 0, 10))
				err(1, "--compress-level=%s", optarg);
			break;
		case OPT_COPY_DEST:	opts.copy_dest = optarg;	break;
		case OPT_EXCLUDE:
			push_filter(&opts.filter, optarg, FPT_EXCL);	break;
		case OPT_EXCLUDE_FROM:
			pushfile(&opts.filter, optarg, push_filter,
			    FPT_EXCL);					break;
		case OPT_FILES_FROM:
			pushfile(&opts.files, optarg, push_files_from,
			    FPT_INCL);					break;
		case OPT_INCLUDE:
			push_filter(&opts.filter, optarg, FPT_INCL);	break;
		case OPT_INCLUDE_FROM:
			pushfile(&opts.filter, optarg, push_filter,
			    FPT_INCL);					break;
		case OPT_LINK_DEST:	opts.link_dest = optarg;	break;
		case OPT_LOG_FILE:	opts.log_file = optarg;		break;
		case OPT_LOG_FILE_FORMAT:
					opts.log_file_format = optarg;	break;
		case OPT_MAX_DELETE:
			if (!parsenum(&opts.max_delete, optarg, 0, INT_MAX))
				err(1, "--max-delete=%s", optarg);
			break;
		case OPT_MAX_SIZE:
			if (!parsesize(&opts.max_size, optarg, 1))
				err(1, "--max-size=%s", optarg);
			break;
		case OPT_MIN_SIZE:
			if (!parsesize(&opts.min_size, optarg, 1))
				err(1, "--min-size=%s", optarg);
			break;
		case OPT_MODIFY_WINDOW:
			if (!parsenum(&opts.modify_window, optarg, 0, INT_MAX))
				err(1, "--modify-window=%s", optarg);
			break;
		case OPT_ONLY_WRITE_BATCH:opts.write_batch = optarg;	break;
		case OPT_OUT_FORMAT:	opts.out_format = optarg;	break;
		case OPT_PORT:
			if (!parsenum(&opts.port, optarg, 0, 65535))
				err(1, "--port=%s", optarg);
			break;
		case OPT_PARTIAL_DIR:	opts.partial_dir = optarg;	break;
		case OPT_PASSWORD_FILE:	opts.password_file = optarg;	break;
		case OPT_PSYNC_PATH:	opts.psync_path = optarg;	break;
		case OPT_READ_BATCH:	opts.read_batch = optarg;	break;
		case OPT_SOCKOPTS:	opts.sockopts = optarg;		break;
		case OPT_SUFFIX:	opts.suffix = optarg;		break;
		case OPT_TIMEOUT:
			if (!parsenum(&opts.timeout, optarg, 0, INT_MAX))
				err(1, "--timeout=%s", optarg);
			break;
		case OPT_WRITE_BATCH:	opts.write_batch = optarg;	break;

		/* psync specific options */
		case OPT_DSTDIR:	opts.dstdir = optarg;		break;
		case OPT_PUPPET:
			if (!parsenum(&opts.puppet, optarg, 0, 1000000))
				err(1, "--PUPPET=%s", optarg);
			break;

		case 0:
			break;
		default:
			warn("invalid option: -%c", c);
			usage();
		}
	}
}