Ejemplo n.º 1
0
int exec_cmd(char *str,int len)
{
	if(db)printf("\nexec cmd called for %s, l=%d",str,len);
	printf("\n");
	trunc_str(&str,&len);
	if(len>0)
	{
		char *p=strchr(str,':'),*tmp,**args=(char **)malloc(8*sizeof(char *));
		char *s=str;
		if(p!=strrchr(str,':'))
		{
			printf("\nERROR\n multiple occurances of ':' found");
			return 0;
		}
		if(p!=0)
		{
			int l=p-s,arg_c;
			int (*cmd_mtch)(char *, int);
			trunc_str(&s,&l);
			tmp=(char *)malloc(l*sizeof(char));
			void *cmd_search;
			strncpy(tmp,s,l);
			arg_c=parse_ssv(tmp,args);
			cmd_search=search_node(cmd_tree,args[0]);
			cmd_mtch = cmd_search ? (int(*)(char *, int))cmd_search : 0;
			if(cmd_mtch)
			{
				if(db)printf("\nfn matched");
				cmd_mtch(p+1,len-(p-str)-1);
			}
			else if(arg_c==1)
			{
				var *var_tmp=add_var(args[0]);
				if(!var_tmp->addr)var_tmp->addr=( node *)malloc(sizeof( node));
				store_fn(p+1,len-(p-str)-1,var_tmp->addr);
			}
			return 1;
		}
		else
		{
			store_fn( str, len, fnc );
			printf("\n-----------------------------------------------\n");
				printf("\nThe soln is %lf",fnc->method->eval_v(fnc));
			printf("\n-----------------------------------------------\n");
			return 1;
		}
	}
	return 0;
}
Ejemplo n.º 2
0
char	*subs_dollar(char *cmd, t_history *list)
{
  if (list)
    cmd = trunc_str(list->command);
  else
    return (NULL);
  return (cmd);
}
Ejemplo n.º 3
0
int exec_cmd_eval(char *t,int l_t)
{
	trunc_str(&t,&l_t);
	char *tmp=(char*)malloc(l_t*sizeof(char));
	strcpy(tmp,t);
	 var *var_ptr=add_var(tmp);
	printf("\n\t-----\n%s = %lf\n\t-----\n",tmp,var_ptr->addr->method->eval_v(var_ptr->addr));
	return 0;
}
Ejemplo n.º 4
0
Archivo: order.c Proyecto: 41px/pkgin
/**
 * \fn order_install
 *
 * order the install list according to dependency level
 * here we only rely on basic level given by pkg_summary, the only drawback
 * is that pkg_add will install direct dependencies, giving a "failed,
 * package already installed"
 */
Plisthead *
order_install(Plisthead *impacthead)
{
	Plisthead	*ordtreehead;
	Pkglist		*pimpact, *pdp, *pi_dp = NULL;
	int			i, maxlevel = 0;
	char		tmpcheck[BUFSIZ];

	/* record higher dependency level on impact list */
	SLIST_FOREACH(pimpact, impacthead, next) {
		if ((pimpact->action == TOUPGRADE ||
			pimpact->action == TOINSTALL) &&
			pimpact->level > maxlevel)
			maxlevel = pimpact->level;
	}

	ordtreehead = init_head();

	for (i = 0; i <= maxlevel; i++) {
		SLIST_FOREACH(pimpact, impacthead, next) {
			if ((pimpact->action == TOUPGRADE ||
				pimpact->action == TOINSTALL) &&
				pimpact->level == i) {

				if (pkg_in_impact(ordtreehead, pimpact->full))
					continue;

				pdp = malloc_pkglist(DEPTREE);

				pdp->computed = pimpact->action; /* XXX: ugly*/
				XSTRDUP(pdp->depend, pimpact->full);
				pdp->name = NULL; /* safety */
				pdp->level = pimpact->level;
				/* record package size for download check */
				pdp->file_size = pimpact->file_size;

				/* check for pkg_install upgrade */
				strcpy(tmpcheck, pimpact->full);
				trunc_str(tmpcheck, '-', STR_BACKWARD);
				/* match on pkg_install */
				if (strcmp(tmpcheck, PKG_INSTALL) == 0) {
					pi_upgrade = 1;
					/* backup pdp for future insertion */
					pi_dp = pdp;
				} else					
					SLIST_INSERT_HEAD(ordtreehead,
						pdp, next);
			} /* action == TOINSTALL */
		} /* SLIST_FOREACH pimpact */
	} /* for i < maxlevel */

	/* pkg_install is to be upgraded, make it first */
	if (pi_upgrade && pi_dp != NULL)
		SLIST_INSERT_HEAD(ordtreehead, pi_dp, next);

	return ordtreehead;
}
Ejemplo n.º 5
0
int exec_cmd_mat(char *t,int l_t)
{
	node n,n1;
	trunc_str(&t,&l_t);
	store_fn(t,l_t,&n);
	n.method->eval_n(&n,&n1);
	if(n1.node_type==ar_mat)
	{
		printf("\n-----------------------------------------------\n");
			print_mat(n1.d.mat_ptr);
		printf("\n-----------------------------------------------\n");
	}
	return 0;
}
Ejemplo n.º 6
0
int exec_cmd_plot(char *t,int l_t)
{
	char **args=(char **)malloc(8*sizeof(char *));
	int c;
	trunc_str(&t,&l_t);
	parse_args(t,l_t,args,&c);
	node n,a,b;
	store_fn(args[0],strlen(args[0]),&n);
	store_fn(args[2],strlen(args[2]),&a);
	store_fn(args[3],strlen(args[3]),&b);
	plot(&n,add_var(args[1]),a.method->eval_v(&a),b.method->eval_v(&b),atoi(args[4]));
	//printf("\n-----------------------------------------------\n");
	//printf("%s=%f",args[1],result);
	//printf("\n-----------------------------------------------\n");
	return 0;
}
Ejemplo n.º 7
0
int exec_cmd_newton(char *t,int l_t)
{
	//nwt
	char **args=(char **)malloc(8*sizeof(char *));
	int c;
	trunc_str(&t,&l_t);
	parse_args(t,l_t,args,&c);
	node n,z;
	store_fn(args[0],strlen(args[0]),&n);
	store_fn(args[2],strlen(args[2]),&z);
	double result = newton(&n,add_var(args[1]),z.method->eval_v(&z));
	printf("\n-----------------------------------------------\n");
	printf("%s=%f",args[1],result);
	printf("\n-----------------------------------------------\n");
	return 0;
}
Ejemplo n.º 8
0
int exec_cmd_simpson3(char *t,int l_t)
{
	//sm3
	char **args=(char **)malloc(8*sizeof(char *));
	int c;
	trunc_str(&t,&l_t);
	parse_args(t,l_t,args,&c);
	printf(
		"\nIntegrating (%s)d%s using simpson 3/8th rule from %s to %s using %s nodes:\n-\t-\t-\n"
		,args[0],args[1],args[2],args[3],args[4]
		);
	node n,a,b;
	store_fn(args[0],strlen(args[0]),&n);
	store_fn(args[2],strlen(args[2]),&a);
	store_fn(args[3],strlen(args[3]),&b);
	double result = simpson3(&n,add_var(args[1]),a.method->eval_v(&a),b.method->eval_v(&b),atoi(args[4]));
	if(v)printf("\nInteration (%s)d%s (%lf-%lf)=%lf",args[0],args[1],a.method->eval_v(&a),b.method->eval_v(&b),result);
	printf("\n-\t-\t-\n");
	return 0;
}
Ejemplo n.º 9
0
Archivo: order.c Proyecto: 41px/pkgin
/**
 * find dependency deepness for package removal and record it to pdp->level
 */
static void
remove_dep_deepness(Plisthead *deptreehead)
{
	char		*depname;
	Pkglist		*pdp;
	Plisthead	*lvldeptree;

	/* get higher recursion level */
	SLIST_FOREACH(pdp, deptreehead, next) {
		if (pdp->level == -1) { /* unique package, just return */
			pdp->level = 0;
			return;
		}

		pdp->level = 1;
		
		if (pdp->depend == NULL)
			/* there's something wrong with database's record,
			 * probably a mistaken dependency
			 */
			continue;

		/* depname received from deptreehead is in package format */
		XSTRDUP(depname, pdp->depend);

		trunc_str(depname, '-', STR_BACKWARD);

		lvldeptree = init_head();
		full_dep_tree(depname, LOCAL_REVERSE_DEPS, lvldeptree);

		if (!SLIST_EMPTY(lvldeptree))
		    	pdp->level = SLIST_FIRST(lvldeptree)->level + 1;

		XFREE(depname);
		free_pkglist(&lvldeptree, DEPTREE);

#if 0
		printf("%s -> %d\n", pdp->depend, pdp->level);
#endif
	}
}
Ejemplo n.º 10
0
int exec_cmd_RK(char *t,int l_t)
{
	//RK
	char **args=(char **)malloc(8*sizeof(char *));
	int c;
	trunc_str(&t,&l_t);
	parse_args(t,l_t,args,&c);
	printf("solving initial value problem\n-\t-\t-\n");
	node f,x0,y0,x1;
	store_fn(args[0],strlen(args[0]),&f);
	store_fn(args[3],strlen(args[3]),&x0);
	store_fn(args[4],strlen(args[4]),&y0);
	store_fn(args[5],strlen(args[5]),&x1);
	double result = RK	(
		&f, add_var(args[1]), add_var(args[2]),x0.method->eval_v(&x0),
		y0.method->eval_v(&y0),x1.method->eval_v(&x1),atoi(args[6])
		);
	printf("\n%s(%f)=%f",args[2],x1.method->eval_v(&x1),result);
	printf("\n-\t-\t-\n");
	return 0;
}
Ejemplo n.º 11
0
Archivo: order.c Proyecto: 41px/pkgin
/* find dependency deepness for upgrade and record it to pimpact->level */
static void
upgrade_dep_deepness(Plisthead *impacthead)
{
	char		*pkgname;
	Pkglist		*pimpact;
	Plisthead	*lvldeptree;

	/* get higher recursion level */
	SLIST_FOREACH(pimpact, impacthead, next) {
		if (pimpact->level == -1) { /* unique package, just return */
			pimpact->level = 0;
			return;
		}

		/* only deal with TOUPGRADE and TOREMOVE */
		if (pimpact->action == TOINSTALL)
			continue;

		pimpact->level = 1;

		/* depname received from impact is in full package format */
		XSTRDUP(pkgname, pimpact->full);

		trunc_str(pkgname, '-', STR_BACKWARD);

		lvldeptree = init_head();
		full_dep_tree(pkgname, LOCAL_REVERSE_DEPS, lvldeptree);

		if (!SLIST_EMPTY(lvldeptree))
		    	pimpact->level = SLIST_FIRST(lvldeptree)->level + 1;

#if 0
		printf("%s (%s) -> %d\n",
			pimpact->full, pkgname, pimpact->level);
#endif

		XFREE(pkgname);
		free_pkglist(&lvldeptree, DEPTREE);
	}
}
Ejemplo n.º 12
0
static void
break_depends(Plisthead *impacthead)
{
	Pkglist	   	*rmimpact, *pimpact;
	Plisthead	*rdphead, *fdphead;
	Pkglist	   	*rdp, *fdp;
	char		*pkgname, *rpkg;
	int			dep_break, exists;

	SLIST_FOREACH(pimpact, impacthead, next) {

		if (pimpact->old == NULL) /* DONOTHING or TOINSTALL  */
			continue;

		rdphead = init_head();

		XSTRDUP(pkgname, pimpact->old);
		trunc_str(pkgname, '-', STR_BACKWARD);

		/* fetch old package reverse dependencies */
		full_dep_tree(pkgname, LOCAL_REVERSE_DEPS, rdphead);

		XFREE(pkgname);

		/* browse reverse dependencies */
		SLIST_FOREACH(rdp, rdphead, next) {

			exists = 0;
			/* check if rdp was already on impact list */
			SLIST_FOREACH(rmimpact, impacthead, next)
				if (strcmp(rmimpact->depend, rdp->depend) == 0) {
					exists = 1;
					break;
				}
			if (exists)
				continue;

			fdphead = init_head();

			/*
			 * reverse dependency is a full package name,
			 * use it and strip it
			 */
			XSTRDUP(rpkg, rdp->depend);
			trunc_str(rpkg, '-', STR_BACKWARD);

			/* fetch dependencies for rdp */
			full_dep_tree(rpkg, DIRECT_DEPS, fdphead);

			/* initialize to broken dependency */
			dep_break = 1;

			/* empty full dep tree, this can't happen in normal situation.
			 * If it does, that means that the reverse dependency we're
			 * analyzing has no direct dependency.
			 * Such a situation could occur if the reverse dependency is not on
			 * the repository anymore, leading to no information regarding this
			 * package.
			 * So we will check if local package dependencies are satisfied by
			 * our newly upgraded packages.
			 */
			if (SLIST_EMPTY(fdphead)) {
				free_pkglist(&fdphead, DEPTREE);
				fdphead = init_head();
				full_dep_tree(rpkg, LOCAL_DIRECT_DEPS, fdphead);
			}
			XFREE(rpkg);

			/*
			 * browse dependencies for rdp and see if
			 * new package to be installed matches
			 */
			SLIST_FOREACH(fdp, fdphead, next) {
				if (pkg_match(fdp->depend, pimpact->full)) {
					dep_break = 0;
					break;
				}
			}

			free_pkglist(&fdphead, DEPTREE);

			if (!dep_break)
				continue;

			/* dependency break, insert rdp in remove-list */
			rmimpact = malloc_pkglist(IMPACT);
			XSTRDUP(rmimpact->depend, rdp->depend);
			XSTRDUP(rmimpact->full, rdp->depend);
			XSTRDUP(rmimpact->old, rdp->depend);
			rmimpact->action = TOREMOVE;
			rmimpact->level = 0;

			SLIST_INSERT_HEAD(impacthead, rmimpact, next);
		}
		free_pkglist(&rdphead, DEPTREE);
	}