Exemplo n.º 1
0
//***********************************************************
//  DEBUG function: insert filespecs in display list
//***********************************************************
void insert_target_filespec(char *fstr)
   {
   // target[tcount] = new char[PATH_MAX] ;
   target[tcount] = (char *) malloc(PATH_MAX) ;
   if (target[tcount] == NULL)
      error_exit(OUT_OF_MEMORY, NULL) ;
   strcpy(target[tcount], fstr) ;

   unsigned result = qualify(target[tcount], n.lfn_off) ;
   if (result == QUAL_INV_DRIVE)
      error_exit(INV_DRIVE, target[tcount]) ;

   tcount++ ;
   }
Exemplo n.º 2
0
static int
Xls(void)
{
	struct stat sb;
	char *p;
	int fd;

	if (stat(qualify((cmd.argv[1]? cmd.argv[1]: "/.")), &sb) < 0) {
		printf("stat(%s): %s\n", cmd.path, strerror(errno));
		return 0;
	}

	if ((sb.st_mode & S_IFMT) != S_IFDIR)
		ls(cmd.path, &sb);
	else {
		if ((fd = opendir(cmd.path)) < 0) {
			printf("opendir(%s): %s\n", cmd.path,
			    strerror(errno));
			return 0;
		}

		/* no strlen in lib !!! */
		for (p = cmd.path; *p; p++)
			;
		*p++ = '/';
		*p = '\0';

		while (readdir(fd, p) >= 0) {
			if (stat(cmd.path, &sb) < 0)
				printf("stat(%s): %s\n", cmd.path,
				    strerror(errno));
			else
				ls(p, &sb);
		}
		closedir (fd);
	}
	return 0;
}
Exemplo n.º 3
0
int
read_conf(void)
{
#ifndef INSECURE
	struct stat sb;
#endif
	int fd, rc = 0;

	if ((fd = open(qualify(cmd.conf), 0)) < 0) {
		if (errno != ENOENT && errno != ENXIO) {
			printf("open(%s): %s\n", cmd.path, strerror(errno));
			return 0;
		}
		return -1;
	}

#ifndef INSECURE
	(void) fstat(fd, &sb);
	if (sb.st_uid || (sb.st_mode & 2)) {
		printf("non-secure %s, will not proceed\n", cmd.path);
		close(fd);
		return -1;
	}
#endif

	do {
		char *p = cmd_buf;

		cmd.cmd = NULL;
		do {
			rc = read(fd, p, 1);
		} while (rc > 0 && *p++ != '\n' &&
		    (p-cmd_buf) < sizeof(cmd_buf));

		if (rc < 0) {			/* Error from read() */
			printf("%s: %s\n", cmd.path, strerror(errno));
			break;
		}

		if (rc == 0) {			/* eof from read() */
			if (p != cmd_buf) {	/* Line w/o trailing \n */
				*p = '\0';
				rc = docmd();
				break;
			}
		} else {			/* rc > 0, read a char */
			p--;			/* Get back to last character */

			if (*p != '\n') {	/* Line was too long */
				printf("%s: line too long\n", cmd.path);

				/* Don't want to run the truncated command */
				rc = -1;
			}
			*p = '\0';
		}
	} while (rc > 0 && !(rc = docmd()));

	close(fd);
	return rc;
}
Exemplo n.º 4
0
const field_definition& repository_selector::select_field_by_name(
    const std::string& prefix,
    const std::string& simple_field_name) const {
    return select_field_by_name(qualify(prefix, simple_field_name));
}
Exemplo n.º 5
0
boost::optional<const field_definition&> repository_selector::
try_select_field_by_name(const std::string& prefix,
    const std::string& simple_field_name) const {
    return try_select_field_by_name(qualify(prefix, simple_field_name));
}
// ---------------------------------------------------------------------------
// 
// -----------
void bTextLoader::analyse(){
//_bTrace_("bTextLoader::analyse",true);
int		i,k;

	while(true){
		memset(_lb,0,_lbsz);
		if(!get_line()){
			break;
		}
		_lines++;
		hash();
		for(i=0;i<_cols;i++){
			k=qualify(get_text(i));
			if(_lines==1){
				_hsh[i].kfirst=k;
			}
			else{
				switch(_hsh[i].kind){
					case kStringUndef:
						_hsh[i].kind=k;
						break;
					case kStringInt:
						if(k==kStringDouble){
							_hsh[i].kind=k;
						}
						else if((k==kStringInt)		||
								(k==kStringUndef)	){
						}
						else{
							_hsh[i].kind=kStringText;
						}
						break;
					case kStringDouble:
						if(	(k==kStringDouble)	||
							(k==kStringInt)		||
							(k==kStringUndef)	){
						}
						else{
							_hsh[i].kind=kStringText;
						}
						break;
					case kStringText:
						break;
				}
			}
			if(_hsh[i].lmax<_hsh[i].len){
				_hsh[i].lmax=_hsh[i].len;
			}
		}
	}
	if(_lfh){
		for(i=0;i<_cols;i++){
			if(_hsh[i].kind!=_hsh[i].kfirst){
				_hdr=true;
			}
			/**/
			if(_hsh[i].kind==kStringUndef){
				_hsh[i].kind=kStringText;
			}
			/**/
		}
	}
	fseek(_fp,0,SEEK_SET);
}
Exemplo n.º 7
0
/*
 * routine:
 *	main
 *
 * purpose:
 *	argument processing and primary dispatch
 *
 * returns:
 *	error codes per filesync.1 (ERR_* in filesync.h)
 *
 * notes:
 *	read filesync.1 in order to understand the argument processing
 *
 *	most of the command line options just set some opt_ global
 *	variable that is later looked at by the code that actually
 *	implements the features.  Only file names are really processed
 *	in this routine.
 */
int
main(int argc, char **argv)
{	int i;
	int c;
	errmask_t errs = ERR_OK;
	int do_prune = 0;
	char *srcname = 0;
	char *dstname = 0;
	struct base *bp;

	/* keep the error messages simple	*/
	argv[0] = "filesync";

	/* gather together all of the options	*/
	while ((c = getopt(argc, argv, "AaehmnqvyD:E:r:s:d:f:o:")) != EOF)
		switch (c) {
			case 'a':	/* always scan for acls	*/
				opt_acls = TRUE;
				break;
			case 'e':	/* everything agrees	*/
				opt_everything = TRUE;
				break;
			case 'h':	/* halt on error	*/
				opt_halt = TRUE;
				break;
			case 'm':	/* preserve modtimes	*/
				opt_mtime = TRUE;
				break;
			case 'n':	/* notouch		*/
				opt_notouch = TRUE;
				break;
			case 'q':	/* quiet		*/
				opt_quiet = TRUE;
				break;
			case 'v':	/* verbose		*/
				opt_verbose = TRUE;
				break;
			case 'y':	/* yes			*/
				opt_yes = TRUE;
				break;
			case 'D':	/* debug options	*/
				if (!isdigit(optarg[0])) {
					dbg_usage();
					exit(ERR_INVAL);
				}
				opt_debug |= strtol(optarg, (char **)NULL, 0);
				break;

			case 'E':	/* error simulation	*/
				if (dbg_set_error(optarg)) {
					err_usage();
					exit(ERR_INVAL);
				}
				opt_errors = TRUE;
				break;

			case 'f':	/* force conflict resolution	*/
				switch (optarg[0]) {
					case 's':
						opt_force = OPT_SRC;
						break;
					case 'd':
						opt_force = OPT_DST;
						break;
					case 'o':
						opt_force = OPT_OLD;
						break;
					case 'n':
						opt_force = OPT_NEW;
						break;
					default:
						fprintf(stderr,
							gettext(ERR_badopt),
							c, optarg);
						errs |= ERR_INVAL;
						break;
				}
				break;

			case 'o':	/* one way propagation		*/
				switch (optarg[0]) {
					case 's':
						opt_oneway = OPT_SRC;
						break;
					case 'd':
						opt_oneway = OPT_DST;
						break;
					default:
						fprintf(stderr,
							gettext(ERR_badopt),
							c, optarg);
						errs |= ERR_INVAL;
						break;
				}
				break;

			case 'r':	/* restricted reconciliation	*/
				if (num_restrs < MAX_RLIST)
					rlist[ num_restrs++ ] = optarg;
				else {
					fprintf(stderr, gettext(ERR_tomany),
						MAX_RLIST);
					errs |= ERR_INVAL;
				}
				break;

			case 's':
				if ((srcname = qualify(optarg)) == 0)
					errs |= ERR_MISSING;
				break;

			case 'd':
				if ((dstname = qualify(optarg)) == 0)
					errs |= ERR_MISSING;
				break;

			default:
			case '?':
				errs |= ERR_INVAL;
				break;
		}

	if (opt_debug & DBG_MISC)
		fprintf(stderr, "MISC: DBG=%s\n", showflags(dbgmap, opt_debug));

	/* if we have file names, we need a source and destination */
	if (optind < argc) {
		if (srcname == 0) {
			fprintf(stderr, gettext(ERR_nosrc));
			errs |= ERR_INVAL;
		}
		if (dstname == 0) {
			fprintf(stderr, gettext(ERR_nodst));
			errs |= ERR_INVAL;
		}
	}

	/* check for simple usage errors	*/
	if (errs & ERR_INVAL) {
		usage();
		exit(errs);
	}

	/* locate our baseline and rules files	*/
	if (c = findfiles())
		exit(c);

	/* figure out file creation defaults	*/
	whoami();

	/* read in our initial baseline		*/
	if (!new_baseline && (c = read_baseline(file_base)))
		errs |= c;

	/* read in the rules file if we need or have rules	*/
	if (optind >= argc && new_rules) {
		fprintf(stderr, ERR_nonames);
		errs |= ERR_INVAL;
	} else if (!new_rules)
		errs |= read_rules(file_rules);

	/* if anything has failed with our setup, go no further	*/
	if (errs) {
		cleanup(errs);
		exit(errs);
	}

	/*
	 * figure out whether or not we are willing to do a one-sided
	 * analysis (where we don't even look at the other side.  This
	 * is an "I'm just curious what has changed" query, and we are
	 * only willing to do it if:
	 *	we aren't actually going to do anything
	 *	we have a baseline we can compare against
	 * otherwise, we are going to insist on being able to access
	 * both the source and destination.
	 */
	if (opt_notouch && !new_baseline)
		opt_onesided = opt_oneway;

	/*
	 * there are two interested usage scenarios:
	 *	file names specified
	 *		create new rules for the specified files
	 *		evaulate and reconcile only the specified files
	 *	no file names specified
	 *		use already existing rules
	 *		consider restricting them to specified subdirs/files
	 */
	if (optind < argc) {
		/* figure out what base pair we're working on	*/
		bp = add_base(srcname, dstname);

		/* perverse default rules to avoid trouble	*/
		if (new_rules) {
			errs |= add_ignore(0, SUFX_RULES);
			errs |= add_ignore(0, SUFX_BASE);
		}

		/* create include rules for each file/dir arg	*/
		while (optind < argc)
			errs |= add_include(bp, argv[ optind++ ]);

		/*
		 * evaluate the specified base on each side,
		 * being careful to limit evaulation to new rules
		 */
		errs |= evaluate(bp, OPT_SRC, TRUE);
		errs |= evaluate(bp, OPT_DST, TRUE);
	} else {
		/* note any possible evaluation restrictions	*/
		for (i = 0; i < num_restrs; i++)
			errs |= add_restr(rlist[i]);

		/*
		 * we can only prune the baseline file if we have done
		 * a complete (unrestricted) analysis.
		 */
		if (i == 0)
			do_prune = 1;

		/* evaulate each base on each side		*/
		for (bp = bases; bp; bp = bp->b_next) {
			errs |= evaluate(bp, OPT_SRC, FALSE);
			errs |= evaluate(bp, OPT_DST, FALSE);
		}
	}

	/* if anything serious happened, skip reconciliation	*/
	if (errs & ERR_FATAL) {
		cleanup(errs);
		exit(errs);
	}

	/* analyze and deal with the differenecs		*/
	errs |= analyze();

	/* see if there is any dead-wood in the baseline	*/
	if (do_prune) {
		c = prune();

		if (c > 0 && opt_verbose)
			fprintf(stdout, V_prunes, c);
	}

	/* print out a final summary				*/
	summary();

	/* update the rules and baseline files (if needed)	*/
	(void) umask(my_umask);
	errs |= write_baseline(file_base);
	errs |= write_rules(file_rules);

	if (opt_debug & DBG_MISC)
		fprintf(stderr, "MISC: EXIT=%s\n", showflags(errmap, errs));

	/* just returning ERR_RESOLVABLE upsets some people	*/
	if (errs == ERR_RESOLVABLE && !opt_notouch)
		errs = 0;

	/* all done	*/
	cleanup(0);
	return (errs);
}
Exemplo n.º 8
0
Arquivo: walker.c Projeto: hvds/seq
wrhp walker_findnext(whp wh) {
	walker* w = DWP(wh);
	walk_result* next;
	walk_result* split;
	wrhp nexth;
	int limitbit, i;

	while (1) {
		if (mbh_size(w->heap) == 0)
			return (wrhp)0;

		/* pick_arena first, since arena may move */
		w_pick_arena(w, split);
		next = pop_heap(w);
		limitbit = next->nextbit;
		mpx_set(wr_discard_direct(w, split), w->numsize,
				wr_next_discard(w, next), w->numsize);
		split->invsum = next->invsum;
		memcpy(wr_vec_direct(w, split), wr_vec_direct(w, next),
				w->vecsize * sizeof(int));

		if (next->nextbit == w->pp->valsize) {
			/* first */
			--next->nextbit;
			w->adder(wr_next_discard(w, next), wr_discard_direct(w, next),
					ppv_mpx(pp_value_i(w->pp, next->nextbit)));
			if (!qualify(w, next)) {
				w_free_arena(w, next);
			} else {
				push_heap(w, next);
			}
			w_free_arena(w, split);
			goto found_line;
		}

		--next->nextbit;
		if (next->nextbit < 0) {
			w_free_arena(w, next);
		} else if (wr_testbit(w, next, next->nextbit)) {
			w_free_arena(w, next);
		} else {
			w->adder(wr_next_discard(w, next), wr_discard_direct(w, next),
					ppv_mpx(pp_value_i(w->pp, next->nextbit)));
			if (!qualify(w, next)) {
				w_free_arena(w, next);
			} else {
				push_heap(w, next);
			}
		}

		split->invsum = (split->invsum + pp_value_i(w->pp, limitbit)->inv)
				% w->pp->p;
		wr_setbit(w, split, limitbit);

		for (i = w->pp->valsize - 1; i > limitbit; --i) {
			if (!wr_testbit(w, split, i))
				break;
		}
		if (i <= limitbit) {
			w_free_arena(w, split);
		} else {
			split->nextbit = i;
			w->adder(wr_next_discard(w, split), wr_discard_direct(w, split),
					ppv_mpx(pp_value_i(w->pp, i)));
			if (!qualify(w, split)) {
				w_free_arena(w, split);
			} else {
				push_heap(w, split);
			}
		}
		next = split;
	  found_line:
		nexth = WRHP(w, next);
		if (next->invsum != w->invsum)
			continue;
		if (w->have_previous
				&& w->cmper(wr_discard_direct(w, next), w_previous(w)) == 0)
			continue;
		w->have_previous = 1;
		mpx_set(w_previous(w), w->numsize,
				wr_discard_direct(w, next), w->numsize);
		return nexth;
	}
}
Exemplo n.º 9
0
Referen::Referen(Path path)
: absPath(path),
qualifiedName(qualify(absPath)) {
}
Exemplo n.º 10
0
Referen::Referen(Path path, Path context)
: absPath(absolutify(path, context)),
qualifiedName(qualify(absPath)) {
}
Exemplo n.º 11
0
Referen::Referen()
: absPath(pNull),
qualifiedName(qualify(absPath)) {
}