예제 #1
0
파일: tap.change.cpp 프로젝트: tap/TapTools
// INPUT: LIST/SYMBOL
void change_anything(t_change *x, t_symbol *msg, long argc, t_atom *argv)
{	
	short 	i;
	bool	match = false;
	bool	mismatch = false;
	long	inlet = proxy_getinlet((t_object *)x);
											
	if(inlet == 0){
		if (x->last_input_type != msg_list)		// didn't receive a list/symbol last time
			mismatch = true;
		else if (msg != x->last_input_symbol)	// last list/symbol received didn't start with the same symbol
			mismatch = true;
		else if (argc != x->last_argc)			// last list/symbol was not the same length
			mismatch = true;
		else {									// check to see if the args are the same...
			for(i=0; i<argc; i++){
				match = atom_compare(&(x->last_input_list[i]), argv+i);			
				if(!match) mismatch = true;
			}
		}
			
		if(mismatch)							// output the input
			outlet_anything(x->change_Out[0], msg, argc, argv);		
		else									// All elements are the same, send a bang
			outlet_bang(x->change_Out[1]);		
	}		
	x->last_input_symbol = msg;					// Make copies of the input for the next time
	x->last_input_type = msg_list;
	x->last_argc = argc;
	memcpy(argv, x->last_input_list, sizeof(t_atom) * argc);
}
예제 #2
0
int qatom_main(int argc, char **argv)
{
	enum qatom_atom { _EXPLODE=0, _COMPARE, _PRINT } action = _EXPLODE;
	const char *format = QATOM_FORMAT;
	depend_atom *atom;
	depend_atom *atomc;
	int i;

	while ((i = GETOPT_LONG(QATOM, qatom, "")) != -1) {
		switch (i) {
		case 'F': format = optarg; break;
		case 'c': action = _COMPARE; break;
		case 'p': action = _PRINT; break;
		COMMON_GETOPTS_CASES(qatom)
		}
	}

	if (argc == optind)
		qatom_usage(EXIT_FAILURE);

	if (action == _COMPARE && (argc - optind) % 2)
		err("compare needs even number of arguments");

	for (i = optind; i < argc; ++i) {
		atom = atom_explode(argv[i]);
		if (atom == NULL) {
			warnf("invalid atom: %s\n", argv[i]);
			continue;
		}

		switch (action) {
		case _COMPARE:
			i++;
			atomc = atom_explode(argv[i]);
			if (atomc == NULL) {
				warnf("invalid atom: %s\n", argv[i]);
				break;
			}
			printf("%s %s ",
					atom_to_string(atom),
					booga[atom_compare(atom, atomc)]);
			printf("%s\n",
					atom_to_string(atomc));
			atom_implode(atomc);
			break;
		case _EXPLODE:
			qatom_printf(format, atom, verbose);
			putchar('\n');
			break;
		case _PRINT:
			printf("%s\n", atom_to_string(atom));
			break;
		}

		atom_implode(atom);
	}

	return EXIT_SUCCESS;
}
예제 #3
0
static int
qgrep_cache_cb(cache_pkg_ctx *pkg_ctx, void *priv)
{
	struct qgrep_grepargs *data = (struct qgrep_grepargs *)priv;
	char buf[_Q_PATH_MAX];
	char name[_Q_PATH_MAX];
	char *label;
	depend_atom *patom = NULL;
	cache_ctx *cctx;
	int ret;
	int pfd;

	snprintf(buf, sizeof(buf), "%s/%s",
			pkg_ctx->cat_ctx->name, pkg_ctx->name);
	patom = atom_explode(buf);
	if (patom == NULL)
		return EXIT_FAILURE;

	if (data->include_atoms != NULL) {
		depend_atom **d;
		for (d = data->include_atoms; *d != NULL; d++) {
			if (atom_compare(patom, *d) == EQUAL)
				break;
		}
		if (*d == NULL) {
			atom_implode(patom);
			return EXIT_FAILURE;
		}
	}

	/* need to construct path in portdir to ebuild, pass it to grep */
	cctx = (cache_ctx *)(pkg_ctx->cat_ctx->ctx);
	if (cctx->cachetype == CACHE_EBUILD) {
		pfd = cctx->vdb_fd;
	} else {
		pfd = openat(cctx->vdb_fd, "../..", O_RDONLY|O_CLOEXEC);
	}

	/* cat/pkg/pkg-ver.ebuild */
	snprintf(buf, sizeof(buf), "%s/%s/%s.ebuild",
			patom->CATEGORY, patom->PN, patom->P);

	label = NULL;
	if (data->show_name) {
		char *repo = data->show_repo ? cctx->repo : NULL;
		snprintf(name, sizeof(name), "%s%s/%s%s%s%s%s%s",
				BOLD, patom->CATEGORY, BLUE, patom->P, GREEN,
				repo ? "::" : "", repo ? repo : "", NORM);
		label = name;
	} else if (data->show_filename) {
		label = buf;
	}

	ret = qgrep_grepat(pfd, buf, label, data);

	atom_implode(patom);

	return ret;
}
예제 #4
0
파일: match.c 프로젝트: Cycling74/max5-sdk
void match_atom(t_match *x, t_atom *a)
{
	long i;
	
	for (i = 0; i < x->m_size-1; i++)
		x->m_seen[i] = x->m_seen[i+1];
	x->m_seen[x->m_size-1] = *a;
	atom_compare(x);
}
예제 #5
0
static int
qgrep_vdb_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
{
	struct qgrep_grepargs *data = (struct qgrep_grepargs *)priv;
	char buf[_Q_PATH_MAX];
	char name[_Q_PATH_MAX];
	char *label;
	depend_atom *patom = NULL;
	int ret;
	int pfd;

	snprintf(buf, sizeof(buf), "%s/%s",
			pkg_ctx->cat_ctx->name, pkg_ctx->name);
	patom = atom_explode(buf);
	if (patom == NULL)
		return EXIT_FAILURE;

	if (data->include_atoms != NULL) {
		depend_atom **d;
		for (d = data->include_atoms; *d != NULL; d++) {
			if (atom_compare(patom, *d) == EQUAL)
				break;
		}
		if (*d == NULL) {
			atom_implode(patom);
			return EXIT_FAILURE;
		}
	}

	/* get path to portdir */
	pfd = openat(pkg_ctx->cat_ctx->ctx->portroot_fd,
			data->portdir, O_RDONLY|O_CLOEXEC);

	/* cat/pkg/pkg-ver.ebuild */
	snprintf(buf, sizeof(buf), "%s/%s/%s.ebuild",
			patom->CATEGORY, patom->PN, patom->P);

	label = NULL;
	if (data->show_name) {
		snprintf(name, sizeof(name), "%s%s/%s%s%s",
				BOLD, patom->CATEGORY, BLUE, patom->P, NORM);
		label = name;
	} else if (data->show_filename) {
		label = buf;
	}

	ret = qgrep_grepat(pfd, buf, label, data);

	atom_implode(patom);

	return ret;
}
예제 #6
0
파일: list.c 프로젝트: shouya/clisp
int list_compare(const List* l1, const List* l2) {
  Atom* const* iter1, * const* iter2;
  
  if (l1->n_items != l2->n_items) return 2;
  if (l1->is_quoted != l2->is_quoted) return 2;

  iter1 = l1->items;
  iter2 = l2->items;

  while (iter1 != l1->items + l1->n_items) {
    if (atom_compare(*iter1, *iter2) != 0) {
      return 2;
    }
  }

  return 0;
}