Exemple #1
0
/* Initialize the user-controlled options to their default values, and
 * then parse the command-line options and arguments.
 */
static void initwithcmdline(int argc, char *argv[], startupdata *start)
{
    static char	null[1] = "";
    char const *dir;
    int		ch;

    programname = argv[0];

    datadir = getpathbuffer();
    copypath(datadir, DATADIR);

    savedir = getpathbuffer();
    if ((dir = getenv("BLKSAVEDIR"))) {
	strncpy(savedir, dir, sizeof savedir - 1);
	savedir[sizeof savedir - 1] = '\0';
    } else if ((dir = getenv("HOME")))
	sprintf(savedir, "%.*s/.cblocks", (int)(sizeof savedir - 10), dir);

    start->filename = null;
    start->level = 0;
    start->silence = FALSE;
    start->listseries = FALSE;
    start->writeanswer = FALSE;

    while ((ch = getopt(argc, argv, "0123456789D:S:hlqvw")) != EOF) {
	switch (ch) {
	  case '0': case '1': case '2': case '3': case '4':
	  case '5': case '6': case '7': case '8': case '9':
	    start->level = start->level * 10 + ch - '0';
	    break;
	  case 'D':	copypath(datadir, optarg);			break;
	  case 'S':	copypath(savedir, optarg);			break;
	  case 'q':	start->silence = TRUE;				break;
	  case 'l':	start->listseries = TRUE;			break;
	  case 'w':	start->writeanswer = TRUE;			break;
	  case 'h':	fputs(yowzitch, stdout); exit(EXIT_SUCCESS);
	  case 'v':	fputs(vourzhon, stdout); exit(EXIT_SUCCESS);
	  default:	fputs(yowzitch, stderr); exit(EXIT_FAILURE);
	}
    }

    if (optind < argc)
	start->filename = argv[optind++];
    if (optind < argc) {
	fputs(yowzitch, stderr);
	exit(EXIT_FAILURE);
    }
}
Exemple #2
0
const char *default_zfs_root(void)
{
	char buf[1024], *p;
	FILE *fin;

	if (default_zfsroot)
		return default_zfsroot;

	fin = fopen(LXC_GLOBAL_CONF, "r");
	if (fin) {
		while (fgets(buf, 1024, fin)) {
			if (buf[0] == '#')
				continue;
			p = strstr(buf, "zfsroot");
			if (!p)
				continue;
			p = strchr(p, '=');
			if (!p)
				continue;
			p++;
			while (*p && (*p == ' ' || *p == '\t')) p++;
			if (!*p)
				continue;
			default_zfsroot = copypath(p);
			goto out;
		}
	}
	default_zfsroot = DEFAULT_ZFSROOT;

out:
	if (fin)
		fclose(fin);
	return default_zfsroot;
}
int copypath( const char *source, const char *target )
{
	char newsource[PFS_PATH_MAX];
	char newtarget[PFS_PATH_MAX];
	int nerrors=0;

	int result = copyfile(source,target);

	if(result>=0) {
		/* success: do nothing else */
	} else if(errno==EISDIR) {
		DIR *dir;
		struct dirent *d;

		if(!recursive_mode) {
			fprintf(stderr,"parrot_cp: omitting directory '%s'\n",source);
			return 1;
		}

		if(verbose_mode) {
			printf("'%s' -> '%s'\n",source,target);
		}

		if(mkdir(target,0777)<0) {
			if(errno==EEXIST) {
				/* keep going */
			} else {
				fprintf(stderr,"parrot_cp: cannot mkdir '%s': %s\n",target,strerror(errno));
				return 1;
			}
		}

		dir = opendir(source);
		if(!dir) {
			fprintf(stderr,"parrot_cp: cannot opendir '%s': %s\n",source,strerror(errno));
			return 1;
		}

		while((d=readdir(dir))) {
			if(!strcmp(d->d_name,".")) continue;
			if(!strcmp(d->d_name,"..")) continue;

			sprintf(newsource,"%s/%s",source,d->d_name);
			sprintf(newtarget,"%s/%s",target,d->d_name);

			nerrors += copypath(newsource,newtarget);
		}

		closedir(dir);
	} else {
		nerrors++;
		fprintf(stderr,"parrot_cp: cannot copy %s to %s: %s\n",source,target,strerror(errno));
	}

	return nerrors;
}
Exemple #4
0
const char *default_lxc_path(void)
{
	char buf[1024], *p;
	FILE *fin;

	if (default_lxcpath)
		return default_lxcpath;

	fin = fopen(LXC_GLOBAL_CONF, "r");
	if (fin) {
		while (fgets(buf, 1024, fin)) {
			if (buf[0] == '#')
				continue;
			p = strstr(buf, "lxcpath");
			if (!p)
				continue;
			p = strchr(p, '=');
			if (!p)
				continue;
			p++;
			while (*p && (*p == ' ' || *p == '\t')) p++;
			if (!*p)
				continue;
			default_lxcpath = copypath(p);
			goto out;
		}
	}
	/* we couldn't open the file, or didn't find a lxcpath
	 * entry there.  Return @LXCPATH@ */
	default_lxcpath = LXCPATH;

out:
	if (fin)
		fclose(fin);
	return default_lxcpath;
}
int main( int argc, char *argv[] )
{

	char *target;
	signed char c;
	int i;
	int nerrors = 0;
	int target_is_dir = 0;
	struct stat statbuf;
	char newtarget[PFS_PATH_MAX];

	struct option long_options[] = {
		{"help",  no_argument, 0, 'h'},
		{"verbose", no_argument, 0, 'v'},
		{"force", no_argument, 0, 'f'},
		{"interactive", no_argument, 0, 'i'},
		{"recursive", no_argument, 0, 'r'},
		{"symlinks", no_argument, 0, 's'},
		{"hardlinks", no_argument, 0, 'l'},
		{"update-only", no_argument, 0, 'u'},
        {0,0,0,0}
	};
	
	while((c=getopt_long(argc,argv,"firRsluvh", long_options, NULL)) > -1) {
		switch(c) {
		case 'f':
			force_mode = 1;
			break;
		case 'i':
			interactive_mode = 1;
			break;
		case 'r':
		case 'R':
			recursive_mode = 1;
			break;
		case 's':
			symlink_mode = 1;
			break;
		case 'l':
			hardlink_mode = 1;
			break;
		case 'u':
			update_mode = 1;
			break;
		case 'v':
			verbose_mode = 1;
			break;
		case 'h':
			show_help();
			exit(0);
			break;
		}
	}

	// Check for not enough arguments
	if( (argc-optind)<2 ) {
		printf("Insufficient number of arguments\n");
		show_help();
		return 1;
	}

	// Set and check target
	target = argv[argc-1];
	
	if(stat(target, &statbuf)>=0) {
		if(S_ISDIR(statbuf.st_mode)) {
			target_is_dir=1;
		}
	}

	// Check that we are not moving multiple files into a non-directory
	if( (argc-optind)>2 && !target_is_dir) {
		printf("%s: copying multiple files, but last argument '%s' is not a directory\n", argv[0], target);
		return 1;
	}
	
	for(i=optind; i<=argc-2; i++) {
		if(target_is_dir) {
			char *basename = strrchr(argv[i],'/');
			if(basename) {
				sprintf(newtarget,"%s%s",target,basename);
			} else {
				sprintf(newtarget,"%s/%s",target,argv[i]);
			}
		} else {
			strcpy(newtarget,target);
		}
		nerrors += copypath(argv[i],newtarget);
	}
	
	return nerrors!=0;
}
Exemple #6
0
/**
 * \fn void addVideos(std::string bddName, std::string activity, int nbVideos, std::string* videoPaths, int dim, int maxPts)
 * \brief Adds a new video in the choosen activity of the specified BDD.
 * \param[in] bddName The name of the BDD.
 * \param[in] activity The name of the activity.
 * \param[in] nbVideos The number of videos we want to add.
 * \param[in] videoPaths The different paths to the videos.
 */
void addVideos(std::string bddName, std::string activity, int nbVideos, std::string* videoPaths){
  std::string path2bdd("bdd/" + bddName);
  
  //int desc = getDescID(path2bdd);
  //int dim = getDim(desc);
  
  // Loading the bdd
  IMbdd bdd(bddName,path2bdd);
  bdd.load_bdd_configuration(path2bdd.c_str(),"imconfig.xml");
  
  // Saving its parameters
  int maxPts = bdd.getMaxPts();
  int scale_num = bdd.getScaleNum();
  std::string descriptor = bdd.getDescriptor();
  int dim = bdd.getDim();
    
  // Loading the mapping file to get the video label
  activitiesMap *am;
  int nbActivities = mapActivities(path2bdd,&am);
  int i = 0;
  while(am[i].activity.compare(activity) != 0 && i < nbActivities) i++;
  if(am[i].activity.compare(activity) != 0){
    std::cerr << "Activity not found!\n" << std::endl;
    exit(EXIT_FAILURE);
  }
  int label = am[i].label;
  delete []am;
  
  // Import videos in the selected database
  string strlabel = inttostring(label);
  
  std::string copypath(path2bdd + "/" + strlabel + "/avi");
  int nbFiles = nbOfFiles(copypath);
  int j = nbFiles + 1;
  for(int i=0 ; i<nbVideos ; i++){
    string idFile = inttostring(j);
    string cmd("cp " + videoPaths[i] + " " + copypath + "/" + strlabel + idFile + ".avi");
    system(cmd.c_str());
    j++;
  }
  
  // Extract STIPs from the videos and save them in the repertory /path/to/bdd/label/
  string fpointspath(path2bdd + "/" + strlabel + "/fp");
  j = nbFiles + 1;
  
  for(int i=0 ; i<nbVideos ; i++){
    KMdata dataPts(dim,maxPts);
    string idFile = inttostring(j);
    string videoInput(copypath + "/" + strlabel + idFile + ".avi");
    string fpOutput(fpointspath + "/" + strlabel + "-" + idFile + ".fp");
    int nPts;
    
    nPts = extract_feature_points(videoInput,
				  scale_num, descriptor, dim,
				  maxPts, dataPts);		
    if(nPts != 0){
      dataPts.setNPts(nPts);
      exportSTIPs(fpOutput, dim,dataPts);
    }
    j++;
  }
}