示例#1
0
文件: eval.c 项目: doly/femtoutil
void setarg(cons_t * cell)
{
	int i = 0;
	if (cell == NULL)
	return;
	switch (cell->type) {
	case START:
	if (cell->car->type == SYMBOL) {
		cell->car->type = FUNC;
	}
	setarg(cell->car);
	setarg(cell->cdr);
	break;
	case SYMBOL:
	for (i = 0; i < argsize; i++) {
		if (ftable[hash(func_name_tmp)]->arg_name[i] != '\0'
		&& strncmp(cell->symbol,
			   ftable[hash(func_name_tmp)]->arg_name[i],
			   sizeof(cell->symbol)) == 0) {
		cell->type = ARG;
		}
	}
	setarg(cell->cdr);
	break;
	default:
	setarg(cell->cdr);
	break;
	}
}
示例#2
0
文件: simp.cpp 项目: nixz/covise
HlExprList *HlExprList::simp()
{
    for (int i = 0; i < Length(); i++)
        setarg(i, arg(i)->simp());

    switch (typeOfHead())
    {

    case PLUS:
        return simp_plus();
    case TIMES:
        return simp_times();
    case POWER:
        return simp_power();
    case SQRT:
        return simp_sqrt();
    case SIN:
        return simp_sin();
    case COS:
        return simp_cos();
    case TAN:
        return simp_tan();
    case ABS:
        return simp_betrag();
    case SIGN:
        return simp_signum();
    default:
        return this;
    }
}
示例#3
0
文件: winacl.c 项目: Arcko/freenas
/* create directory and file ACL's */
static void
make_acls(struct windows_acl_info *w)
{
	char *ptr;
	char buf[8192];
	acl_t acl;

	/* set defaults if none specified */
	if (w->flags & WA_RESET) {
		if (w->owner_entry == NULL)
			setarg(&w->owner_entry, WA_ENTRY_OWNER);
		if (w->group_entry == NULL)
			setarg(&w->group_entry, WA_ENTRY_GROUP);
		if (w->everyone_entry == NULL)
			setarg(&w->everyone_entry, WA_ENTRY_EVERYONE);
	}

	/* create an acl string */
	ptr = &buf[0];
	if (w->owner_entry != NULL)
		copyarg(&ptr, w->owner_entry);
	if (w->group_entry != NULL)
		copyarg(&ptr, w->group_entry);
	if (w->everyone_entry != NULL)
		copyarg(&ptr, w->everyone_entry);

	/* turn our acl string into an acl */
	if ((acl = acl_from_text(buf)) == NULL)
		err(EX_OSERR, "acl_from_text() failed");

	/* create a directory acl */
	if (w->flags & WA_DIRECTORIES) {
		if ((w->dacl = acl_dup(acl)) == NULL)
			err(EX_OSERR, "acl_dup() failed");
	}

	/* create a file acl */
	if (w->flags & WA_FILES) {
		if ((w->facl = acl_dup(acl)) == NULL)
			err(EX_OSERR, "acl_dup() failed");
		remove_inherit_flags(&w->facl);
	}

	acl_free(acl);
}
示例#4
0
文件: eval.c 项目: doly/femtoutil
cons_t defun_eval(cons_t * cell, cons_t result)
{
	cons_t *tmp = cell;
	cons_t *tmp_o;
	result.type = DEFUN;
	cell = cell->cdr;
	func_name_tmp = cell->symbol;
	result.symbol = cell->symbol;
	cell = cell->cdr;
	argset(cell->car);
	tmp_o = cell->cdr;
	fhash(tmp);
	setarg(tmp_o);
	return result;
}
示例#5
0
    static void set(const temporary<T, Tag, Expr> &term,
            backend::kernel &kernel, unsigned part, size_t index_offset,
            detail::kernel_generator_state_ptr state)
    {
        auto s = state->find("tmp_args");

        if (s == state->end()) {
            s = state->insert(std::make_pair(
                        std::string("tmp_args"),
                        boost::any(std::set<size_t>())
                        )).first;
        }

        auto &pos = boost::any_cast< std::set<size_t>& >(s->second);
        auto p = pos.find(Tag);

        if (p == pos.end()) {
            pos.insert(Tag);

            detail::set_expression_argument setarg(kernel, part, index_offset, state);
            detail::extract_terminals()( boost::proto::as_child(term.expr),  setarg);
        }
    }
示例#6
0
int parseopts(qMailOpts *popts, int &argc, char **&argv)
{
// arg init
	setarg(&argc, argv);

	char *popt;
	char *pend;

	if ((popt = getopt("ti*meout"))) {
		popts->timeout = (float) strtod(popt, &pend);
		if (popts->timeout < Q_MINTIMEOUT) 
			popts->timeout = Q_MINTIMEOUT;
	}

	if (popts->host) {
		pend = 0;
		parse_email(popts->host.GetBuffer(), popts->user, pend, popts->port, popts->desc);
		if (pend) 
			popts->smtp = pend;
		else
			popts->smtp = popts->host;
	}

 	if ((popt = getopt("u*sername"))) {
		pend = 0; popts->user = 0;
		parse_email(popt, popts->user, pend, popts->port, popts->desc);
		if (pend) popts->smtp = pend;
		if (!popts->user) 
			popts->user = popt;
	}

	if (((popt = getopt("h*ost")))) {
		pend = 0;
		popts->host = popt;
		parse_email(popt, popts->user, pend, popts->port, popts->desc);
		popts->smtp = pend ? pend : popt;

	}
	
	if (popts->smtp) {
		if ((popt = getopt("p*assword")))
			popts->pass = popt;

		if ((popt = getopt("to")))
			popts->to = popt;

		if ((popt = getopt("f*rom")))
			popts->from = popt;
		
		if ((popt = getopt("r*eply")))
			popts->reply = popt;

		int o = 0;
		while ((o < 7) && (popt = getopt("o*ther")))
			popts->other.SetAt(o++,popt);
		popts->other.SetAt(o++,0);


		int i = 0;
		while ((i < 7) && (popt = getopt("b*ody")))
			popts->body.SetAt(i++,popt);
		
		char *p = getarg(3);
		if (p && *p) {
			p = strtok(p, ";");
			while (p) {
				popts->body.SetAt(i++,p);
				p = strtok(NULL, ";");
			}
		}

		popts->body.SetAt(i++,0);

		popts->subj = getarg(2);

		popt = getarg(1);

		if (popt) {
			popts->rcpt = popt;
			if (!popts->from) 
				popts->from = "";
			if (!popts->to && !strchr((const char *) popts->rcpt,';'))
				popts->to = popts->rcpt;
			if (!popts->helo) 
				popts->helo = popts->smtp;
		}
	}
 
	popts->save = getoptbool("s*ave");

	if (argc > 1) {
		fprintf(stderr, QM_ERR_UNK_OPT_RC, argv[1]);
		fprintf(stderr, "\n");
		return QM_ERR_UNK_OPT;
	} else if (!popts->smtp) {
		fprintf(stderr, QM_ERR_NEED_HOST_RC);
		fprintf(stderr, "\n");
		return QM_ERR_NEED_HOST;
	} else if (!popts->rcpt && !popts->save) {
		fprintf(stderr, QM_ERR_NEED_RCPT_RC);
		fprintf(stderr, "\n");
		return QM_ERR_NEED_RCPT;
	}

	return 0;
}
示例#7
0
文件: winacl.c 项目: Arcko/freenas
int
main(int argc, char **argv)
{
	int ch;
	struct windows_acl_info *w;

	if (argc < 2)
		usage(argv[0]);

	w = new_windows_acl_info();
	w->flags = (WA_FILES|WA_DIRECTORIES);

	while ((ch = getopt(argc, argv, "a:o:g:e:O:G:p:i:fdrvx")) != -1) {
		switch (ch) {
			case 'a': {
				int action = get_action(optarg);
				if (action == WA_NULL)
					errx(EX_USAGE, "invalid action");
				if (WA_OP_CHECK(w->flags, action))
					errx(EX_USAGE, "only one action can be specified");
				w->flags |= action;
				break;
			}

			case 'o':
				setarg(&w->owner_entry, optarg);
				break;

			case 'g':
				setarg(&w->group_entry, optarg);
				break;

			case 'e':
				setarg(&w->everyone_entry, optarg);
				break;

			case 'O': {
				struct passwd *p = getpwnam(optarg);
				if (p == NULL)
					errx(EX_OSERR, "getpwnam() failed");
				w->uid = p->pw_uid;
				break;
			}

			case 'G': {
				struct group *g = getgrnam(optarg);
				if (g == NULL)
					errx(EX_OSERR, "getgrnam() failed");
				w->gid = g->gr_gid;
				break;
			}

			case 'p':
				setarg(&w->path, optarg);
				break;

			case 'i':
				w->index = strtol(optarg, NULL, 10);
				break;

			case 'f':
				w->flags &= ~WA_DIRECTORIES;
				break;

			case 'd':
				w->flags &= ~WA_FILES;
				break;

			case 'r':
				w->flags |= WA_RECURSIVE;
				break;

			case 'v':
				w->flags |= WA_VERBOSE;
				break;

			case 'x':
				w->flags |= WA_DOSATTRIB;
				break;

			case '?':
			default:
				usage(argv[0]);
		}
	}

	make_acls(w);
	usage_check(w);
	set_windows_acls(w);

	free_windows_acl_info(w);
	return (0);
}
示例#8
0
int main(int argc, char ** argv)
{

	int i;
	int n = 0;
	int unordered = 0;

	/*
		Command-line arguments.
	*/
	int _f = 0;
	int _q = 0;

	int valid_argc = 1;

	char valid_options[][3] = {"-f","-q"};
	int * valid_options_var[] = {&_f, &_q};

	//Check if specified options are valid
	for(i=1; i<argc; i++)
	{
		if(argv[i][0]=='-')
		{
			if( !checkArg(argv[i], sizeof(valid_options) / sizeof(valid_options[0]), valid_options) )
			{
				printf("quotes: Invalid option %s.\n",argv[i]);
				return 0;
			}
		}
	}

	for(i=0; i<sizeof(valid_options)/sizeof(valid_options[0]); i++)
		setarg(valid_options[i], valid_options_var[i], argc, argv, &valid_argc);

	if(argc != valid_argc)
	{
		help_message
	}


	/*
	if(argc == 3)
	{
		if(!strcmp(argv[1], "-f"))
		{
			_f = 1;
		}
		else if (!strcmp(argv[1], "-q"))
		{
			_q = 1;
		}
		else
		{
			printf("quotes: Unrecognized option '%s'\n",argv[1]);
			help_message
		}
	}*/


	FILE * fp; 

	if(_f)
		fp = fopen(argv[_f+1],"r");
	else
		fp = fopen("/home/jddantes/Dropbox/Git/Scripts/quotes","r");
	


	if(!fp)
	{
		printf("Error. Could not open file.\n");
		return 0;
	}

	char ** quotes_list = 0;

	int num_quotes = 0;
	int quote_id = 0;
	while(fscanf(fp,"%d",&quote_id)!=EOF)
	{

		if(quote_id -1 != num_quotes )
		{
			unordered = num_quotes;

			//printf("%s: Quote %d out of order. Previous quote is numbered %d.\n",argv[0],num_quotes);
			//return 0;
		}

		num_quotes++;
		quotes_list = (char **)realloc(quotes_list, sizeof(char *) * num_quotes);
		quotes_list[num_quotes-1] = (char *)malloc(sizeof(char) * quote_max_size + 1);
		quotes_list[num_quotes-1][0] = 0;

		char c;

		/* 
			Scan until quote_start
		*/

		int quote_start_matched = 0;

		while(fscanf(fp,"%c",&c)==1)
		{
			if(c==quote_start[quote_start_matched])
			{	
				quote_start_matched++;
				if(quote_start_matched == quote_start_size)
					break;
			}
			else
			{
				quote_start_matched = 0;
			}
		}

		/*
			Scan quote_start END
		*/

		/*
			Scan and print (or store into quotes_list) until quote_end
		*/

		int quote_end_matched = 0;
		char buffer[quote_end_size+1];
		buffer[0] = 0;

		char char_buffer[2]="";

		while(fscanf(fp,"%c",&c)==1)
		{

			if(c==quote_end[quote_end_matched])
			{
				buffer[quote_end_matched] = c;
				buffer[quote_end_matched + 1] = 0;

				quote_end_matched++;

				if(quote_end_matched == quote_end_size)
				{
					buffer[0] = 0;
					break;
				}
			}
			else
			{
				quote_end_matched = 0;

				if(strlen(buffer))
				{
					strapp(quotes_list[num_quotes-1],buffer);
					buffer[0] = 0;
				}
				
				
				char_buffer[0]=c;
				char_buffer[1]=0;

				strapp(quotes_list[num_quotes-1],char_buffer);
				
			}
		}

		/*
			Scan and print until quote_end END
		*/
	}

	fclose(fp);

	//Print quotes_list
	/*
	printf("Printing quotes list...\n");
	for(i=0; i<num_quotes; i++)
	{
		printf("Quote %d: %s\n",i+1, quotes_list[i]);
	}
	printf("End of list.\n");
	*/

	if(_q) //Quote id specified
	{
		if(unordered)
		{
			printf("quotes: warning: The entry after quote %d is numbered incorrectly.\n",unordered);
		}

		int q;
		sscanf(argv[_q+1],"%d",&q);

		if(!q)
		{
			printf("Indices start at either 1 or -1. If the value exceeds the number of quotes, the modulo value will be used.\n");
			return 0;
		}

		if(abs(q) >  num_quotes)
			q = q % num_quotes;

		if(q>0)
			n = q-1;
		else
			n = num_quotes + q;

		
	}
	else //Produce random quote.
	{
		srand(time(NULL));
		n = rand() % num_quotes;
	}

	printf("%s\n",quotes_list[n]);

	for(i=0; i<num_quotes; i++)
		free(quotes_list[i]);
	free(quotes_list);

	return 0;
}
示例#9
0
int main(int argc, char *argv[]) {
    setarg(argv[0]);
    pause();
}