Esempio n. 1
0
void memswap(void *p, void *q, size_t n)
{
	void *bottom;
	char temporary;

	bottom = ptradd(p, n);
	while (p != bottom) {
		temporary = *(char *)p;
		*(char *)p = *(char *)q;
		*(char *)q = temporary;

		p = ptradd(p, sizeof(char));
		q = ptradd(q, sizeof(char));
	}
}
Esempio n. 2
0
int main(void)
{
   textmode(2);       /* Call textmode function in conio.h for BW80 */
   window(1,1,80,25); /* Call window function in conio.h for full screen */
   initialize();      /* Call initialize function above to set values to 0 */

   printf("Enter hex. integers for x,y and z with comma between values ");
   scanf("%X,%X,%X",&x,&y,&z);     /* Read data from keyboard */
   ptx = &x;                       /* Address of x is assigned to ptx */
   pty = &y;                       /*  ........  y  ............. pty */
   ptz = &z;                       /*  ........  z  ............. ptz */

   pseudovar();       /* Call pseudo variable function  */
   ptradd();          /* Call pointer, address-of and indirection function */

   printf("Press any key to continue");
   getch();   /* Call function getch in conio.h to get char. from keyboard */
   textmode(3);  /* Call textmode function in conio.h to revert to colour  */
   clrscr();  /* Call function clrscr in conio.h to clear screen           */
   return 0;  /* To indicate to DOS that the program terminated normally   */
}
Esempio n. 3
0
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stddef.h>
#include "ssearch.h"
#include "ptr.h"

void *ssearch(const void * restrict key, void * restrict base,
	size_t number, size_t size, int (* cmp)(const void *, const void *))
{
	while (number > 0) {
		number--;
		base = ptradd(base, size);
		if (cmp(base, key) == 0)
			return base;
	}

	return NULL;
}
Esempio n. 4
0
File: emit.c Progetto: a8m/c
static void
expr(Node *n)
{
	switch(n->t){
	case NCOMMA:
		comma(n);
		break;
	case NCAST:
		cast(n);
		break;
	case NSTR:
		str(n);
		break;
	case NSIZEOF:
		outi("movq $%lld, %%rax\n", n->Sizeof.type->size);
		break;
	case NNUM:
		outi("movq $%lld, %%rax\n", n->Num.v);
		break;
	case NIDENT:
		ident(n);
		break;
	case NUNOP:
		unop(n);
		break;
	case NASSIGN:
		assign(n);
		break;
	case NBINOP:
		binop(n);
		break;
	case NIDX:
		idx(n);
		break;
	case NSEL:
		sel(n);
		break;
	case NCOND:
		cond(n);
		break;
	case NCALL:
		call(n);
		break;
	case NPTRADD:
		ptradd(n);
		break;
	case NINCDEC:
		incdec(n);
		break;
	case NBUILTIN:
		switch(n->Builtin.t) {
		case BUILTIN_VASTART:
			vastart(n);
			break;
		default:
			errorposf(&n->pos, "unimplemented builtin");
		}
		break;
	default:
		errorf("unimplemented emit expr %d\n", n->t);
	}
}
Esempio n. 5
0
File: devsrv.c Progetto: 8l/inferno
static long
srvwrite(Chan *c, void *va, long count, vlong offset)
{
	long l;
	Heap * volatile h;
	SrvFile *sp;
	Channel *wc;
	Channel *wr;
	Pending wait;
	Sys_Rwrite * volatile w;
	Sys_FileIO_write req;

	if(c->qid.type & QTDIR)
		error(Eperm);

	acquire();
	if(waserror()){
		release();
		nexterror();
	}

	sp = c->aux;
	wr = sp->write;
	if(wr == H)
		error(Ehungup);

	wc = cnewc(dev.Rwrite, movtmp, 1);
	ptradd(D2H(wc));
	if(waserror()){
		ptrdel(D2H(wc));
		destroy(wc);
		nexterror();
	}

	req.t0 = offset;
	req.t1 = mem2array(va, count);
	req.t2 = c->fid;
	req.t3 = wc;

	ptradd(D2H(req.t1));

	if(waserror()){
		ptrdel(D2H(req.t1));
		destroy(req.t1);
		nexterror();
	}

	csend(wr, &req);

	poperror();
	ptrdel(D2H(req.t1));
	destroy(req.t1);

	h = heap(dev.Rwrite);
	w = H2D(Sys_Rwrite *, h);
	ptradd(h);

	if(waserror()){
		ptrdel(h);
		destroy(w);
		nexterror();
	}

	wait.fid = c->fid;
	wait.rc = nil;
	wait.wc = wc;
	addwaiting(sp, &wait);
	if(waserror()){
		delwaiting(&wait);
		nexterror();
	}
	crecv(wc, w);
	poperror();
	delwaiting(&wait);

	if(w->t1 != H)
		error(string2c(w->t1));
	poperror();
	ptrdel(h);
	l = w->t0;
	destroy(w);

	poperror();
	ptrdel(D2H(wc));
	destroy(wc);

	poperror();
	release();
	if(l < 0)
		l = 0;
	return l;
}
Esempio n. 6
0
File: devsrv.c Progetto: 8l/inferno
static long
srvread(Chan *c, void *va, long count, vlong offset)
{
	int l;
	Heap * volatile h;
	Array *a;
	SrvFile *sp;
	Channel *rc;
	Channel *rd;
	Pending wait;
	Sys_Rread * volatile r;
	Sys_FileIO_read req;

	if(c->qid.type & QTDIR){
		qlock(&dev.l);
		if(waserror()){
			qunlock(&dev.l);
			nexterror();
		}
		l = devdirread(c, va, count, 0, 0, srvgen);
		poperror();
		qunlock(&dev.l);
		return l;
	}

	sp = c->aux;

	acquire();
	if(waserror()){
		release();
		nexterror();
	}

	rd = sp->read;
	if(rd == H)
		error(Ehungup);

	rc = cnewc(dev.Rread, movtmp, 1);
	ptradd(D2H(rc));
	if(waserror()){
		ptrdel(D2H(rc));
		destroy(rc);
		nexterror();
	}

	req.t0 = offset;
	req.t1 = count;
	req.t2 = c->fid;
	req.t3 = rc;
	csend(rd, &req);

	h = heap(dev.Rread);
	r = H2D(Sys_Rread *, h);
	ptradd(h);
	if(waserror()){
		ptrdel(h);
		destroy(r);
		nexterror();
	}

	wait.fid = c->fid;
	wait.rc = rc;
	wait.wc = nil;
	addwaiting(sp, &wait);
	if(waserror()){
		delwaiting(&wait);
		nexterror();
	}
	crecv(rc, r);
	poperror();
	delwaiting(&wait);

	if(r->t1 != H)
		error(string2c(r->t1));

	a = r->t0;
	l = 0;
	if(a != H){
		l = a->len;
		if(l > count)
			l = count;
		memmove(va, a->data, l);
	}

	poperror();
	ptrdel(h);
	destroy(r);

	poperror();
	ptrdel(D2H(rc));
	destroy(rc);

	poperror();
	release();

	return l;
}