Ejemplo n.º 1
0
/* Used to calculate an array index for global()/local().  Sets *arrayp to
 * non-zero if this is an array, sets *valp to the array index, returns
 * the basename of the array.
 */
const char *
array_index_calc(const char *n, bool_t *arrayp, int *valp)
{
	const char *p;
	int len;

	*arrayp = FALSE;
	p = skip_varname(n, FALSE);
	if (p != n && *p == '[' && (len = array_ref_len(p))) {
		char *sub, *tmp;
		long rval;

		/* Calculate the value of the subscript */
		*arrayp = TRUE;
		tmp = str_nsave(p+1, len-2, ATEMP);
		sub = substitute(tmp, 0);
		afree(tmp, ATEMP);
		n = str_nsave(n, p - n, ATEMP);
		evaluate(sub, &rval, KSH_UNWIND_ERROR);
		if (rval < 0 || rval > ARRAYMAX)
			errorf("%s: subscript out of range", n);
		*valp = rval;
		afree(sub, ATEMP);
	}
	return n;
}
Ejemplo n.º 2
0
static void
texpand(struct table *tp, int nsize)
{
	int i;
	struct tbl *tblp, **p;
	struct tbl **ntblp, **otblp = tp->tbls;
	int osize = tp->size;

	ntblp = areallocarray(NULL, nsize, sizeof(struct tbl *), tp->areap);
	for (i = 0; i < nsize; i++)
		ntblp[i] = NULL;
	tp->size = nsize;
	tp->nfree = 7*nsize/10;	/* table can get 70% full */
	tp->tbls = ntblp;
	if (otblp == NULL)
		return;
	for (i = 0; i < osize; i++)
		if ((tblp = otblp[i]) != NULL) {
			if ((tblp->flag&DEFINED)) {
				for (p = &ntblp[hash(tblp->name) &
				    (tp->size-1)]; *p != NULL; p--)
					if (p == ntblp) /* wrap */
						p += tp->size;
				*p = tblp;
				tp->nfree--;
			} else if (!(tblp->flag & FINUSE)) {
				afree(tblp, tp->areap);
			}
		}
	afree(otblp, tp->areap);
}
Ejemplo n.º 3
0
sexpr read_directory    (const char *p)
{
    sexpr r = sx_end_of_list;
    unsigned int l = 0, s = 0, map_s, mapd_l;

    while (p[l]) {
        if (p[l] == '/') s++;

        l++;
    }

    s++;
    l++;

    map_s  = sizeof (char *) * s;
    mapd_l = l;

    if (map_s < STACK_BUFFER_SIZE)
    {
        char buf_map [STACK_BUFFER_SIZE];

        if (mapd_l < STACK_BUFFER_SIZE)
        {
            char buf_mapd [STACK_BUFFER_SIZE];

            r = read_directory_w (p, (char **)buf_map, buf_mapd);
        }
        else
        {
            char *mapd = aalloc (mapd_l);

            r = read_directory_w (p, (char **)buf_map, mapd);

            afree (mapd_l, mapd);
        }
    }
    else
    {
        char **map = aalloc (map_s);

        if (mapd_l < STACK_BUFFER_SIZE)
        {
            char buf_mapd [STACK_BUFFER_SIZE];

            r = read_directory_w (p, map, buf_mapd);
        }
        else
        {
            char *mapd = aalloc (mapd_l);

            r = read_directory_w (p, map, mapd);

            afree (mapd_l, mapd);
        }

        afree (map_s, map);
    }

    return r;
}
Ejemplo n.º 4
0
Archivo: var.c Proyecto: camomiles/eou
/* Used to calculate an array index for global()/local().  Sets *arrayp to
 * non-zero if this is an array, sets *valp to the array index, returns
 * the basename of the array.
 */
static const char *
array_index_calc(const char *n, bool *arrayp, int *valp)
{
	const char *p;
	int len;

	*arrayp = false;
	p = skip_varname(n, false);
	if (p != n && *p == '[' && (len = array_ref_len(p))) {
		char *sub, *tmp;
		long rval;

		/* Calculate the value of the subscript */
		*arrayp = true;
		tmp = str_nsave(p+1, len-2, ATEMP);
		sub = substitute(tmp, 0);
		afree(tmp, ATEMP);
		n = str_nsave(n, p - n, ATEMP);
		evaluate(sub, &rval, KSH_UNWIND_ERROR, true);
		if (rval < 0 || rval > INT_MAX)
			errorf("%s: subscript %ld out of range", n, rval);
		*valp = rval;
		afree(sub, ATEMP);
	}
	return n;
}
Ejemplo n.º 5
0
Archivo: var.c Proyecto: tomgrean/mksh
/**
 * Unset a variable. The flags can be:
 * |1	= tear down entire array
 * |2	= keep attributes, only unset content
 */
void
unset(struct tbl *vp, int flags)
{
	if (vp->flag & ALLOC)
		afree(vp->val.s, vp->areap);
	if ((vp->flag & ARRAY) && (flags & 1)) {
		struct tbl *a, *tmp;

		/* free up entire array */
		for (a = vp->u.array; a; ) {
			tmp = a;
			a = a->u.array;
			if (tmp->flag & ALLOC)
				afree(tmp->val.s, tmp->areap);
			afree(tmp, tmp->areap);
		}
		vp->u.array = NULL;
	}
	if (flags & 2) {
		vp->flag &= ~(ALLOC|ISSET);
		return;
	}
	/* if foo[0] is being unset, the remainder of the array is kept... */
	vp->flag &= SPECIAL | ((flags & 1) ? 0 : ARRAY|DEFINED);
	if (vp->flag & SPECIAL)
		/* responsible for 'unspecial'ing var */
		unsetspec(vp);
}
Ejemplo n.º 6
0
int
qname_indexer(const void *vp)
{
    qnameobj *obj;
    const dns_message *m = vp;
    if (m->malformed)
	return -1;
    if (NULL == theHash) {
        theHash = hash_create(MAX_ARRAY_SZ, qname_hashfunc, qname_cmpfunc,
	    1, afree, afree);
	if (NULL == theHash)
	    return -1;
    }
    if ((obj = hash_find(m->qname, theHash)))
        return obj->index;
    obj = acalloc(1, sizeof(*obj));
    if (NULL == obj)
	return -1;
    obj->qname = astrdup(m->qname);
    if (NULL == obj->qname) {
	afree(obj);
	return -1;
    }
    obj->index = next_idx;
    if (0 != hash_add(obj->qname, obj, theHash)) {
	afree(obj->qname);
	afree(obj);
	return -1;
    }
    next_idx++;
    return obj->index;

}
main(int argc, char *argv[])
{
	char buf[1000];
	FILE *fp;
	int i, j, k;

	if (argc > 1)
		fp = fopen(argv[1], "r");
	else
		fp = stdin;
	while (fgets(buf, sizeof(buf), fp) != NULL) {
		for (i = 0; i < 5; i++) {
			q[i] = (char *) alloc((k = rand() % 23));
			for (j = 0; j < k; j++)
				q[i][j] = 'x';
		}
		p = (char *) alloc(strlen(buf)+1);
		strcpy(p, buf);
		for (i = 5; i < 10; i++) {
			q[i] = (char *) malloc((k = rand() % 23));
			for (j = 0; j < k; j++)
				q[i][j] = 'y';
		}
		printf("%s", p);
		for (i = 9; i >= 5; i--)
			afree(q[i]);
		afree(p);
		for (; i >= 0; i--)
			afree(q[i]);
	}
	return 0;
}
Ejemplo n.º 8
0
local int var_free_enum(const char *key, void *val, void *clos)
{
	FormulaVariable *var = val;
	if (var->name) 
		afree(var->name);
	afree(var);
	return TRUE;
}
Ejemplo n.º 9
0
void
x_free_words(int nwords, char **words)
{
	int i;

	for (i = 0; i < nwords; i++)
		afree(words[i], ATEMP);
	afree(words, ATEMP);
}
Ejemplo n.º 10
0
local void msg_cleanup(void *v)
{
	int i;
	periodic_msgs *pm = (periodic_msgs*)v;

	for (i = 0; i < MAXMSGS; i++)
		afree(pm->msgs[i].msg);
	afree(pm);
}
Ejemplo n.º 11
0
Archivo: var.c Proyecto: tomgrean/mksh
static void
unsetspec(struct tbl *vp)
{
	/*
	 * AT&T ksh man page says OPTIND, OPTARG and _ lose special
	 * meaning, but OPTARG does not (still set by getopts) and _ is
	 * also still set in various places. Don't know what AT&T does
	 * for HISTSIZE, HISTFILE. Unsetting these in AT&T ksh does not
	 * loose the 'specialness': IFS, COLUMNS, PATH, TMPDIR
	 */

	switch (special(vp->name)) {
#ifdef __OS2__
	case V_BEGINLIBPATH:
	case V_ENDLIBPATH:
	case V_LIBPATHSTRICT:
		setextlibpath(vp->name, "");
		return;
#endif
#if HAVE_PERSISTENT_HISTORY
	case V_HISTFILE:
		sethistfile(NULL);
		return;
#endif
	case V_IFS:
		set_ifs(TC_IFSWS);
		break;
	case V_PATH:
		afree(path, APERM);
		strdupx(path, def_path, APERM);
		/* clear tracked aliases */
		flushcom(true);
		break;
#ifndef MKSH_NO_CMDLINE_EDITING
	case V_TERM:
		x_initterm(null);
		return;
#endif
	case V_TMPDIR:
		/* should not become unspecial */
		if (tmpdir) {
			afree(tmpdir, APERM);
			tmpdir = NULL;
		}
		break;
	case V_LINENO:
	case V_RANDOM:
	case V_SECONDS:
	case V_TMOUT:
		/* AT&T ksh leaves previous value in place */
		unspecial(vp->name);
		break;
	}
}
Ejemplo n.º 12
0
Archivo: cd.c Proyecto: rdavid42/ft_p
int						cd(char *root, int *cs, char *cmd, int *id)
{
	char				**arg;
	char const			*cur = get_cwd();

	(void)id;
	arg = ssplit(cmd, ' ');
	if (scmp(root, cur, slen(root)) != 0)
		return (afree(arg), sc(cs, -2), error(CWD_DENIED), 0);
	go_dir(cs, root, cur, arg[1]);
	return (afree(arg), 1);
}
Ejemplo n.º 13
0
Archivo: mail.c Proyecto: 0xMF/oksh
static void
munset(mbox_t *mlist)
{
	mbox_t	*mbp;

	while (mlist != NULL) {
		mbp = mlist;
		mlist = mbp->mb_next;
		if (!mlist)
			afree((void *)mbp->mb_path, APERM);
		afree((void *)mbp, APERM);
	}
}
Ejemplo n.º 14
0
Archivo: put.c Proyecto: rdavid42/ft_p
static int			receive_file_header(int *sock, char **cmd_args, int *len)
{
	int				r;

	r = recv(*sock, (void *)len, sizeof(uint32_t), 0);
	if (r == -1)
		afree(cmd_args), close(*sock), error(REC_ERR);
	else if (!r)
		afree(cmd_args), close(*sock), error(CO_CLOSED);
	if (*len == -1)
		return (err_msg(FILE_NOT_FOUND), 0);
	if (*len == -2)
		return (err_msg(PERM_DENIED), 0);
	return (1);
}
Ejemplo n.º 15
0
void
set_current_wd(const char *nwd)
{
	char *allocd = NULL;

	if (nwd == NULL) {
		allocd = ksh_get_wd();
		nwd = allocd ? allocd : null;
	}

	afree(current_wd, APERM);
	strdupx(current_wd, nwd, APERM);

	afree(allocd, ATEMP);
}
Ejemplo n.º 16
0
Archivo: mail.c Proyecto: aalm/obsd-src
void
mbset(char *p)
{
	struct stat	stbuf;

	afree(mbox.mb_msg, APERM);
	afree(mbox.mb_path, APERM);
	/* Save a copy to protect from export (which munges the string) */
	mbox.mb_path = str_save(p, APERM);
	mbox.mb_msg = NULL;
	if (p && stat(p, &stbuf) == 0 && S_ISREG(stbuf.st_mode))
		mbox.mb_mtime = stbuf.st_mtime;
	else
		mbox.mb_mtime = 0;
}
Ejemplo n.º 17
0
/* set variable to string value */
int
setstr(struct tbl *vq, const char *s, int error_ok)
{
	char *salloc = NULL;
	bool no_ro_check = tobool(error_ok & 0x4);

	error_ok &= ~0x4;
	if ((vq->flag & RDONLY) && !no_ro_check) {
		warningf(true, "read-only: %s", vq->name);
		if (!error_ok)
			errorfxz(2);
		return (0);
	}
	if (!(vq->flag&INTEGER)) {
		/* string dest */
		if ((vq->flag&ALLOC)) {
#ifndef MKSH_SMALL
			/* debugging */
			if (s >= vq->val.s &&
			    s <= vq->val.s + strlen(vq->val.s)) {
				internal_errorf(
				    "setstr: %s=%s: assigning to self",
				    vq->name, s);
			}
#endif
			afree(vq->val.s, vq->areap);
		}
		vq->flag &= ~(ISSET|ALLOC);
		vq->type = 0;
		if (s && (vq->flag & (UCASEV_AL|LCASEV|LJUST|RJUST)))
			s = salloc = formatstr(vq, s);
		if ((vq->flag&EXPORT))
			exportprep(vq, s);
		else {
			strdupx(vq->val.s, s, vq->areap);
			vq->flag |= ALLOC;
		}
	} else {
		/* integer dest */
		if (!v_evaluate(vq, s, error_ok, true))
			return (0);
	}
	vq->flag |= ISSET;
	if ((vq->flag&SPECIAL))
		setspec(vq);
	afree(salloc, ATEMP);
	return (1);
}
Ejemplo n.º 18
0
void *visualise(void *shedule) {
    struct jsp **model = shedule;

    if (init_SDL())
        pthread_exit(NULL);

    int running = 1;
    SDL_Event event;

    while (running) {
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT) {
                running = 0;
            }
        }
        pthread_mutex_lock(&mutex);
        if (*model != NULL) {
            draw_model(*model);
        }
        pthread_mutex_unlock(&mutex);
    }

    if (colors) {
        afree(colors);
    }
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
    pthread_exit(NULL);
}
Ejemplo n.º 19
0
void
timex_hook(struct op *t, char **volatile *app)
{
	char **wp = *app;
	int optc;
	int i, j;
	Getopt opt;

	ksh_getopt_reset(&opt, 0);
	opt.optind = 0;	/* start at the start */
	while ((optc = ksh_getopt(wp, &opt, ":p")) != -1)
		switch (optc) {
		case 'p':
			t->str[0] |= TF_POSIX;
			break;
		case '?':
			errorf("time: -%s unknown option", opt.optarg);
		case ':':
			errorf("time: -%s requires an argument",
			    opt.optarg);
		}
	/* Copy command words down over options. */
	if (opt.optind != 0) {
		for (i = 0; i < opt.optind; i++)
			afree(wp[i], ATEMP);
		for (i = 0, j = opt.optind; (wp[i] = wp[j]); i++, j++)
			;
	}
	if (!wp[0])
		t->str[0] |= TF_NOARGS;
	*app = wp;
}
Ejemplo n.º 20
0
/* Called after a fork to cleanup stuff left over from parents environment */
void
cleanup_parents_env(void)
{
	struct env *ep;
	int fd;

	/*
	 * Don't clean up temporary files - parent will probably need them.
	 * Also, can't easily reclaim memory since variables, etc. could be
	 * anywhere.
	 */

	/* close all file descriptors hiding in savefd */
	for (ep = e; ep; ep = ep->oenv) {
		if (ep->savefd) {
			for (fd = 0; fd < NUFILE; fd++)
				if (ep->savefd[fd] > 0)
					close(ep->savefd[fd]);
			afree(ep->savefd, &ep->area);
			ep->savefd = NULL;
		}
#ifdef DEBUG_LEAKS
		if (ep->type != E_NONE)
			ep->type = E_GONE;
#endif
	}
#ifndef DEBUG_LEAKS
	e->oenv = NULL;
#endif
}
Ejemplo n.º 21
0
void  CNewPredEncoder::endNEWPREDcnt( NEWPREDcnt* newpredCnt )
{
	{
		int		i, j;

		for (i= 0; (i < m_iNumSlice) && (*(m_piSlicePoint + i) >= 0); i++) {
		
			for (j= 0; j<m_iNumBuffEnc; j++) {
				delete newpredCnt->NPRefBuf[i][j]->pdata.pchY;
				delete newpredCnt->NPRefBuf[i][j]->pdata.pchU;
				delete newpredCnt->NPRefBuf[i][j]->pdata.pchV;
				delete newpredCnt->NPRefBuf[i][j];
			}
		}

		delete []newpredCnt->ref;

		if (newpredCnt->NPRefBuf != NULL) {
			afree((int**)(newpredCnt->NPRefBuf));
		}
	}
	delete []m_iHMBNum;

	free(newpredCnt);
}
Ejemplo n.º 22
0
int arcp_region_init_weakref(struct arcp_region *region) {
	struct arcp_weakref *stub;
	struct arcp_weakref *nostub;

	if (region == NULL) {
		return 0;
	}
	/* load current weakref */
	nostub =
		(struct arcp_weakref *) ak_load(&region->weakref, mo_consume);
	if (nostub != NULL) {
		/* weakref has already been initialized */
		return 0;
	}
	/* allocate a new weakref */
	stub = amalloc(sizeof(struct arcp_weakref));
	if (stub == NULL) {
		return -1;
	}
	/* initialize the weakref */
	ak_init(&stub->target, region);
	/* storecount 1 (the region), usecount 0 */
	ak_init(&stub->refcount, __ARCP_REFCOUNT_INIT(1, 0));
	stub->destroy = (arcp_destroy_f) __arcp_destroy_weakref;
	ak_init(&stub->weakref, NULL);
	if (unlikely(!ak_cas(&region->weakref, &nostub, stub,
			     mo_acq_rel, mo_relaxed))) {
		/* someone else set the weakref */
		afree(stub, sizeof(struct arcp_weakref));
	}
	return 0;
}
Ejemplo n.º 23
0
void CNewPredDecoder::endNEWPREDcnt(NEWPREDcnt	*newpredCnt)
{
	int		i, j;
	for (i= 0; (i < m_iNumSlice) && (*(m_piSlicePoint + i) >= 0); i++) {
		
		for (j= 0; j<m_iNumBuffDec; j++) {

			if (newpredCnt->NPRefBuf[i][j]->pdata.pchY != NULL)
				delete newpredCnt->NPRefBuf[i][j]->pdata.pchY;
			if (newpredCnt->NPRefBuf[i][j]->pdata.pchU != NULL)
				delete newpredCnt->NPRefBuf[i][j]->pdata.pchU;
			if (newpredCnt->NPRefBuf[i][j]->pdata.pchV != NULL)
				delete newpredCnt->NPRefBuf[i][j]->pdata.pchV;

			delete newpredCnt->NPRefBuf[i][j];
		}
	}

	if (m_iNumSlice) {
		if (newpredCnt->ref != NULL)  delete []newpredCnt->ref;
		if (newpredCnt->NPRefBuf != NULL) {
			afree((int**)newpredCnt->NPRefBuf);
		}
	
		free(newpredCnt);

		if (m_iHMBNum != NULL) delete []m_iHMBNum;
	}

	if (m_pDecbufY != NULL) delete []m_pDecbufY; 
	if (m_pDecbufU != NULL) delete []m_pDecbufU; 
	if (m_pDecbufV != NULL) delete []m_pDecbufV; 

	return;
}
Ejemplo n.º 24
0
/* set variable to string value */
int
setstr(struct tbl *vq, const char *s, int error_ok)
{
	const char *fs = NULL;
	int no_ro_check = error_ok & 0x4;
	error_ok &= ~0x4;
	if ((vq->flag & RDONLY) && !no_ro_check) {
		warningf(true, "%s: is read only", vq->name);
		if (!error_ok)
			errorf(null);
		return 0;
	}
	if (!(vq->flag&INTEGER)) { /* string dest */
		if ((vq->flag&ALLOC)) {
			/* debugging */
			if (s >= vq->val.s &&
			    s <= vq->val.s + strlen(vq->val.s))
				internal_errorf(true,
				    "setstr: %s=%s: assigning to self",
				    vq->name, s);
			afree((void*)vq->val.s, vq->areap);
		}
		vq->flag &= ~(ISSET|ALLOC);
		vq->type = 0;
		if (s && (vq->flag & (UCASEV_AL|LCASEV|LJUST|RJUST)))
			fs = s = formatstr(vq, s);
		if ((vq->flag&EXPORT))
			export(vq, s);
		else {
			vq->val.s = str_save(s, vq->areap);
			vq->flag |= ALLOC;
		}
	} else {		/* integer dest */
Ejemplo n.º 25
0
/*
 *  Do file globbing:
 *	- appends * to (copy of) str if no globbing chars found
 *	- does expansion, checks for no match, etc.
 *	- sets *wordsp to array of matching strings
 *	- returns number of matching strings
 */
static int
x_file_glob(int flags, const char *str, int slen, char ***wordsp)
{
	char *toglob;
	char **words;
	int nwords;
	XPtrV w;
	struct source *s, *sold;

	if (slen < 0)
		return 0;

	toglob = add_glob(str, slen);

	/*
	 * Convert "foo*" (toglob) to an array of strings (words)
	 */
	sold = source;
	s = pushs(SWSTR, ATEMP);
	s->start = s->str = toglob;
	source = s;
	if (yylex(ONEWORD|UNESCAPE) != LWORD) {
		source = sold;
		internal_errorf(0, "fileglob: substitute error");
		return 0;
	}
	source = sold;
	XPinit(w, 32);
	expand(yylval.cp, &w, DOGLOB|DOTILDE|DOMARKDIRS);
	XPput(w, NULL);
	words = (char **) XPclose(w);

	for (nwords = 0; words[nwords]; nwords++)
		;
	if (nwords == 1) {
		struct stat statb;

		/* Check if file exists, also, check for empty
		 * result - happens if we tried to glob something
		 * which evaluated to an empty string (e.g.,
		 * "$FOO" when there is no FOO, etc).
		 */
		 if ((lstat(words[0], &statb) < 0) ||
		    words[0][0] == '\0') {
			x_free_words(nwords, words);
			words = NULL;
			nwords = 0;
		}
	}
	afree(toglob, ATEMP);

	if (nwords) {
		*wordsp = words;
	} else if (words) {
		x_free_words(nwords, words);
		*wordsp = NULL;
	}

	return nwords;
}
Ejemplo n.º 26
0
local void FlagGain(Arena *a, Player *p, int fid, int how)
{
	DEF_AD(a);
	BDEF_PD(p);

	if(how == FLAGGAIN_PICKUP)
	{
		FlagOwner *owner = ad->FlagOwners[fid];
		if(owner)
		{
			FlagTeam *team = GetFlagTeam(a, owner->Freq);
			team->DroppedFlags--;

			Player *ownerp = pd->FindPlayer(owner->Name);
			if(ownerp)
			{
				pdat = BPD(ownerp);
				if(pdat->DroppedFlags > 0) //could be left over from when they were on another team
				{
					pdat->DroppedFlags--;
				}
			}

			MYGLOCK;
			ad->FlagOwners[fid] = NULL;
			afree(owner);
			MYGUNLOCK;
		}
	}
}
Ejemplo n.º 27
0
static void su3_appl_twist(su3_dble *u,double phase){
   double c,s;
   su3_dble *r;
   r=amalloc(sizeof(su3_dble),3);
   c = (double)cos(phase);
   s = (double)sin(phase);
   (*(r)).c11.re=c*(*(u)).c11.re-s*(*(u)).c11.im; 
   (*(r)).c11.im=s*(*(u)).c11.re+c*(*(u)).c11.im; 
   (*(r)).c12.re=c*(*(u)).c12.re-s*(*(u)).c12.im; 
   (*(r)).c12.im=s*(*(u)).c12.re+c*(*(u)).c12.im; 
   (*(r)).c13.re=c*(*(u)).c13.re-s*(*(u)).c13.im; 
   (*(r)).c13.im=s*(*(u)).c13.re+c*(*(u)).c13.im; 
   (*(r)).c21.re=c*(*(u)).c21.re-s*(*(u)).c21.im; 
   (*(r)).c21.im=s*(*(u)).c21.re+c*(*(u)).c21.im; 
   (*(r)).c22.re=c*(*(u)).c22.re-s*(*(u)).c22.im; 
   (*(r)).c22.im=s*(*(u)).c22.re+c*(*(u)).c22.im; 
   (*(r)).c23.re=c*(*(u)).c23.re-s*(*(u)).c23.im; 
   (*(r)).c23.im=s*(*(u)).c23.re+c*(*(u)).c23.im; 
   (*(r)).c31.re=c*(*(u)).c31.re-s*(*(u)).c31.im; 
   (*(r)).c31.im=s*(*(u)).c31.re+c*(*(u)).c31.im; 
   (*(r)).c32.re=c*(*(u)).c32.re-s*(*(u)).c32.im; 
   (*(r)).c32.im=s*(*(u)).c32.re+c*(*(u)).c32.im; 
   (*(r)).c33.re=c*(*(u)).c33.re-s*(*(u)).c33.im; 
   (*(r)).c33.im=s*(*(u)).c33.re+c*(*(u)).c33.im;
   *u=*r;
   afree(r);
}
Ejemplo n.º 28
0
Archivo: misc.c Proyecto: adtools/abcsh
/* Like getcwd(), except bsize is ignored if buf is 0 (PATH_MAX is used) */
char *
ksh_get_wd(char *buf, int bsize)
{
        char *b;
        char *ret;

        /* Note: we could just use plain getcwd(), but then we'd had to
         * inject possibly allocated space into the ATEMP area. */
        /* Assume getcwd() available */
        if (!buf) {
                bsize = MAXPATHLEN;
                b = alloc(MAXPATHLEN + 1, ATEMP);
        } else
                b = buf;

        ret = getcwd(b, bsize);

        if (!buf) {
                if (ret)
                        ret = aresize(b, strlen(b) + 1, ATEMP);
                else
                        afree(b, ATEMP);
        }

        return ret;
}
Ejemplo n.º 29
0
void
settrap(Trap *p, char *s)
{
	sig_t f;

	if (p->trap)
		afree(p->trap, APERM);
	p->trap = str_save(s, APERM); /* handles s == 0 */
	p->flags |= TF_CHANGED;
	f = !s ? SIG_DFL : s[0] ? trapsig : SIG_IGN;

	p->flags |= TF_USER_SET;
	if ((p->flags & (TF_DFL_INTR|TF_FATAL)) && f == SIG_DFL)
		f = trapsig;
	else if (p->flags & TF_SHELL_USES) {
		if (!(p->flags & TF_ORIG_IGN) || Flag(FTALKING)) {
			/* do what user wants at exec time */
			p->flags &= ~(TF_EXEC_IGN|TF_EXEC_DFL);
			if (f == SIG_IGN)
				p->flags |= TF_EXEC_IGN;
			else
				p->flags |= TF_EXEC_DFL;
		}

		/* assumes handler already set to what shell wants it
		 * (normally trapsig, but could be j_sigchld() or SIG_IGN)
		 */
		return;
	}

	/* todo: should we let user know signal is ignored? how? */
	setsig(p, f, SS_RESTORE_CURR|SS_USER);
}
Ejemplo n.º 30
0
local void ClearFlagTeam(FlagTeam *team)
{
	MYGLOCK;
	HashFree(team->Breakdown);
	afree(team);
	MYGUNLOCK;
}