예제 #1
0
int main(void)
{
	put1("If I'd as much money");
	put1(" as I could spend, \n");
	printf("I count %d characters.\n",put2("I never would cry old chairs to mend. "));

	return 0;
}
예제 #2
0
int main(void)
{
    put1("if I'd as much money");
    put1("as I could spend,\n");
    printf("I count %s characters.\n",
            "I never would cry old chairs to mend.");
    //后面字符串要不要括号都可以
    return 0;
}
예제 #3
0
// read/modify/write
void testCommitRMW(void) {

    //save new test data
    int ret = put1(0, OESTORE_UNLOCKED, "three");
    assert(ret == 0);

    //start a txn
    OESTORE_TXN oetxn;
    ret = OeStore_start_txn(store, 10000, &oetxn, arena);
    assert(ret == 0);

    //take the new data
    OeStoreHolder holder;
    ret = take1(oetxn.tid, &holder, "three");
    DataObject data = OeStoreHolder_get_data(holder);
    assert(!ret);
    Iterator iter = DataObject_iterator(data, true);
    assert(strcmp(Iterator_next( iter ), "key") == 0);
    assert(strcmp(Iterator_next( iter ), "three") == 0);
    assert(strcmp(DataObject_get_bytes( data ), "txn_nonesense") == 0);

    //make sure it isn't visible anymore
    OeStoreHolder holder2 = NULL;
    ret = get1( &holder2, "three");
    assert(ret == OE_STORE_ITEM_NOTFOUND);

    //put the replacement item into the space
    ret = put1(oetxn.tid, OESTORE_WRITE_LOCK, "four");
    assert(!ret);

    //commit the txn
    ret = OeStore_update_txn(store, oetxn.tid, 0,
                             OESTORE_TXN_COMMITTED, arena, 1); //wrong enlisted count
    assert(ret);
    ret = OeStore_update_txn(store, oetxn.tid, 0,
                             OESTORE_TXN_COMMITTED, arena, 2);//right enlisted count
    assert(!ret);

    //make sure four IS visible after commit
    OeStoreHolder holder3;
    OeStore_start_txn(store, 10000, &oetxn, arena);
    ret = take1(oetxn.tid, &holder3, "four"); //and clean up for next tests...
    DataObject data3 = OeStoreHolder_get_data(holder3);
    OeStore_update_txn(store, oetxn.tid, 0, OESTORE_TXN_COMMITTED, arena, -1);
    assert(!ret);
    iter = DataObject_iterator(data3, true);
    assert(strcmp(Iterator_next( iter ), "key") == 0);
    assert(strcmp(Iterator_next( iter ), "four") == 0);
    assert(strcmp(DataObject_get_bytes( data3 ), "txn_nonesense") == 0);

    //make sure three is NOT visible
    OeStoreHolder holder4;
    ret = get1(&holder4, "three");
    assert(ret == OE_STORE_ITEM_NOTFOUND);
}
int win(int a[]){
	int b[11];
	int i=0 ;
	int ret= 0;
	set(b);

	for(i=0 ; i< 11 ; i++){
		if ( valid1(i,a) ){
			copy(b,a);
			put1(i,b);
			ret|= !win(b);
		}
		if ( valid2(i,a) ){
			copy(b,a);
			put2(i,b);
			ret|= !win(b);
		}
		if ( valid3(i,a) ){
			copy(b,a);
			put3(i,b);
			ret|= !win(b);
		}
	}
	return ret;
}
예제 #5
0
void testTxnCommitPut(void) {

    //start a txn
    OESTORE_TXN oetxn;
    int ret = OeStore_start_txn(store, 10000, &oetxn, arena);
    assert(ret == 0);
    assert(oetxn.tid > 0);

    ret = put1(oetxn.tid, OESTORE_WRITE_LOCK, "txn_one");
    if (ret) {
        OE_ERR(NULL, "put1 failed: %s\n", db_strerror(ret));
    }
    assert(ret == 0);

    //make sure it isn't visible yet
    OeStoreHolder holder2;
    ret = get1(&holder2, "txn_one");
    assert(ret == OE_STORE_ITEM_NOTFOUND);

    //commit the txn
    ret = OeStore_update_txn(store, oetxn.tid, 0, OESTORE_TXN_COMMITTED, arena, -1);
    OE_ERR(NULL, "upt failed: %s\n", db_strerror(ret));
    assert(ret == 0);

    //make sure it IS visible now
    OeStoreHolder holder3;
    ret = get1(&holder3, "txn_one");
    DataObject data3 = OeStoreHolder_get_data(holder3);
    OE_ERR(NULL, "get1 failed: %s\n", db_strerror(ret));
    assert(!ret);
    Iterator iter = DataObject_iterator(data3, true);
    Iterator_next(iter);//0
    assert(strcmp(Iterator_next( iter), "txn_one") == 0);
}
예제 #6
0
void put1(struct node *p, int key, int value) {
  if (p->key == key)
    p->value = value;
  else if (p->key > key) {
    if (p->left == NULL)
      p->left = make_node(key, value);
    else
      put1(p->left, key, value);
  }
  else {
    if (p->right == NULL)
      p->right = make_node(key, value);
    else
      put1(p->right, key, value);
  }
}
예제 #7
0
//delete holder and object (take)
void testRollback(void) {

    //save new test data
    int ret = put1(0, OESTORE_UNLOCKED, "txn_two");
    assert(ret == 0);

    //start a txn
    OESTORE_TXN oetxn;
    ret = OeStore_start_txn(store, 10000, &oetxn, arena);
    assert(ret == 0);

    OeStoreHolder holder;
    ret = take1(oetxn.tid, &holder, "txn_two");
    DataObject data = OeStoreHolder_get_data(holder);
    assert(!ret);
    assert(holder);
    assert(strcmp(DataObject_get_bytes( data ), "txn_nonesense") == 0);
    Iterator iter = DataObject_iterator(data, true);
    Iterator_next(iter); //0
    assert(strcmp(Iterator_next( iter ), "txn_two") == 0);

    //make sure it isn't visible anymore
    OeStoreHolder holder2;
    ret = get1(&holder2, "txn_two");
    OE_ERR(NULL, "get1: %s\n", db_strerror(ret));
    assert(ret == OE_STORE_ITEM_NOTFOUND);
    ret = take1(0, &holder2, "txn_two");
    OE_ERR(NULL, "take1: %s\n", db_strerror(ret));
    assert(ret == OE_STORE_ITEM_NOTFOUND);

    //rollback the txn
    ret = OeStore_update_txn(store, oetxn.tid, 0, OESTORE_TXN_ROLLED_BACK, arena, -1);
    OE_ERR(NULL, "updatetxn: %s\n", db_strerror(ret));
    assert(ret == 0);

    //make sure it IS visible again after rollback of take
    OeStoreHolder holder4;
    ret = get1(&holder4, "txn_two");
    DataObject data4 = OeStoreHolder_get_data(holder4);
    OE_ERR(NULL, "get1: %s\n", db_strerror(ret));
    assert(!ret);
    iter = DataObject_iterator(data4, true);
    Iterator_next(iter); //0
    assert(strcmp(Iterator_next( iter ), "txn_two") == 0);
    OeStoreHolder holder3 = NULL;
    OeStore_start_txn(store, 10000, &oetxn, arena);
    ret = take1(oetxn.tid, &holder3, "txn_two"); //and clean up for next tests...
    DataObject data3 = OeStoreHolder_get_data(holder3);
    OE_ERR(NULL, "take1: %s\n", db_strerror(ret));
    assert(!ret);
    iter = DataObject_iterator(data3, true);
    Iterator_next(iter); //0
    assert(strcmp(Iterator_next( iter ), "txn_two") == 0);

    OeStore_update_txn(store, oetxn.tid, 0, OESTORE_TXN_COMMITTED, arena, 1);
}
예제 #8
0
void testBogusTxnPut(void) {

    //start a txn
    OESTORE_TXN oetxn;
    oetxn.tid = 98765;
    //int ret = OeStore_start_txn(store, 10000, &oetxn, arena);

    int ret = put1(oetxn.tid, OESTORE_WRITE_LOCK, "wouldacoulda");
    assert(ret == OESTORE_INACTIVE_TXN);
}
예제 #9
0
파일: puts1.c 프로젝트: run100/c
int main()
{
  char line[81];
  scanf("%s", line);
  int cnt = 0;
  cnt = put1(line);
  printf("line cnt is %d\n", cnt);
  /* while ( fgets(line, 81, stdin) ) {
    fputs(line, stdout);
  }
  return 0;*/
}
예제 #10
0
파일: draw.c 프로젝트: aksr/heirloom
void
drawwig(char *s)	/* draw wiggly line */
{
	int x[50], y[50], xp, yp, pxp, pyp;
	float t1, t2, t3, w;
	int i, j, numdots, N;
	int osize;
	char temp[50], *p;

	osize = size;
	setsize(t_size(pstab[osize-1] / drawsize));
	p = s;
	for (N = 2; (p=getstr(p,temp)) != NULL && N < sizeof(x)/sizeof(x[0]); N++) {
		x[N] = atoi(temp);
		p = getstr(p, temp);
		y[N] = atoi(temp);
	}
	x[0] = x[1] = hpos;
	y[0] = y[1] = vpos;
	for (i = 1; i < N; i++) {
		x[i+1] += x[i];
		y[i+1] += y[i];
	}
	x[N] = x[N-1];
	y[N] = y[N-1];
	pxp = pyp = -9999;
	for (i = 0; i < N-1; i++) {	/* interval */
		numdots = (dist(x[i],y[i], x[i+1],y[i+1]) + dist(x[i+1],y[i+1], x[i+2],y[i+2])) / 2;
		numdots /= DX;
		numdots = min(numdots, maxdots);
		for (j = 0; j < numdots; j++) {	/* points within */
			w = (float) j / numdots;
			t1 = 0.5 * w * w;
			w = w - 0.5;
			t2 = 0.75 - w * w;
			w = w - 0.5;
			t3 = 0.5 * w * w;
			xp = t1 * x[i+2] + t2 * x[i+1] + t3 * x[i] + 0.5;
			yp = t1 * y[i+2] + t2 * y[i+1] + t3 * y[i] + 0.5;
			if (xp != pxp || yp != pyp) {
				hgoto(xp);
				vgoto(yp);
				put1(drawdot);
				pxp = xp;
				pyp = yp;
			}
		}
	}
	setsize(osize);
}
예제 #11
0
void
bkput(BKPT *bp, int install)
{
	char buf[256];
	ADDR loc;
	int ret;

	errstr(buf, sizeof buf);
	if(machdata->bpfix)
		loc = (*machdata->bpfix)(bp->loc);
	else
		loc = bp->loc;
	if(install){
		ret = get1(cormap, loc, bp->save, machdata->bpsize);
		if (ret > 0)
			ret = put1(cormap, loc, machdata->bpinst, machdata->bpsize);
	}else
		ret = put1(cormap, loc, bp->save, machdata->bpsize);
	if(ret < 0){
		sprint(buf, "can't set breakpoint at %#llux: %r", bp->loc);
		print(buf);
		read(0, buf, 100);
	}
}
예제 #12
0
파일: pdp1.c 프로젝트: qeedquan/spacewar
void
savestate(Mach *m, void *buf)
{
	size_t i;

	u8 *p;

	p = buf;
	p += put4(p, m->ac);
	p += put4(p, m->io);
	p += put4(p, m->pc);
	p += put4(p, m->ov);
	for (i = 0; i < nelem(m->mem); i++)
		p += put4(p, m->mem[i]);
	p += putm(p, m->flag, sizeof(m->flag));
	p += putm(p, m->sense, sizeof(m->sense));
	p += put1(p, m->halt);
	for (i = 0; i < nelem(m->sym); i++)
		p += put4(p, m->sym[i]);
}
예제 #13
0
파일: gnotfix.c 프로젝트: kahrs/cda
void
call_host(char *machine)
{
	char buf[100];
	fprint(errfd, "call_host %s.exec\n", machine);
	if(Connect(machine, "/bin/cda/aux/hplace")) {
		dup(remotefd0, 0);
		dup(remotefd1, 1);
		close(remotefd0);
		close(remotefd1);
		put1(MYDIR);
		putstr(mydir);
		while(rcv());
		return;
	}
	fprint(errfd,"can't open %s on %s", "/bin/cda/aux/hplace", machine);
	hosterr(buf, 0);
	close(remotefd0);
	close(remotefd1);
	remotefd0 = remotefd1 = 0;
}
예제 #14
0
파일: draw.c 프로젝트: aksr/heirloom
void
putdot(int x, int y)
{
	arcmove(x, y);
	put1(drawdot);
}
예제 #15
0
void put(int key, int value) {
  if (root == NULL)
    root = make_node(key, value);
  else
    put1(root, key, value);
}
예제 #16
0
파일: sdiff.c 프로젝트: andreiw/polaris
int
main(int argc, char **argv)
{
	int	com;
	int	n1, n2, n;
	char	*bp;
	int	lfd = -1;
	int	rfd = -1;

	if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
		(void) signal((int)SIGHUP, (void (*)(int))onintr);
	if (signal(SIGINT, SIG_IGN) != SIG_IGN)
		(void) signal((int)SIGINT, (void (*)(int))onintr);
	if (signal(SIGPIPE, SIG_IGN) != SIG_IGN)
		(void) signal((int)SIGPIPE, (void (*)(int))onintr);
	if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
		(void) signal((int)SIGTERM, (void (*)(int))onintr);

	(void) setlocale(LC_ALL, "");
#if	!defined(TEXT_DOMAIN)
#define	TEXT_DOMAIN	"SYS_TEST"
#endif
	(void) textdomain(TEXT_DOMAIN);

	while (--argc > 1 && **++argv == '-') {
		switch (*++*argv) {

		case 'w':
			/* -w# instead of -w # */
			if (*++*argv)
				llen = atoi(*argv);
			else {
				argc--;
				llen = atoi(*++argv);
			}
			if (llen < WLEN)
				error(gettext("Wrong line length %s"), *argv);
			if (llen > LMAX)
				llen = LMAX;
			break;

		case 'l':
			leftonly++;
			break;

		case 's':
			silent++;
			break;
		case 'o':
			oflag++;
			argc--;
			ofile = *++argv;
			break;
		default:
			error(gettext("Illegal argument: %s"), *argv);
		}
	}
	if (argc != 2) {
		(void) fprintf(stderr, gettext(
		"Usage: sdiff [-l] [-s] [-o output] [-w #] file1 file2\n"));
		return (2);
	}

	file1 = *argv++;
	file2 = *argv;
	file1 = filename(file1, file2);
	file2 = filename(file2, file1);
	hlen = (llen - WGUTTER +1)/2;

	if ((fdes1 = fopen(file1, "r")) == NULL)
		error(gettext("Cannot open: %s"), file1);

	if ((fdes2 = fopen(file2, "r")) == NULL)
		error(gettext("Cannot open: %s"), file2);

	if (oflag) {
		if (tempfd == -1) {
			temp = strdup("/tmp/sdiffXXXXXX");
			tempfd = mkstemp(temp);
			if (tempfd == -1) {
				error(gettext(
					"Cannot open/create temp %s"), temp);
				free(temp);
				temp = 0;
			}
		}
		ltemp = strdup("/tmp/sdifflXXXXXX");
		if ((lfd = mkstemp(ltemp)) == -1 ||
			(left = fdopen(lfd, "w")) == NULL)
				error(gettext(
					"Cannot open/create temp %s"),
					ltemp);
		rtemp = strdup("/tmp/sdiffrXXXXXX");
		if ((rfd = mkstemp(rtemp)) == -1 ||
			(right = fdopen(rfd, "w")) == NULL)
				error(gettext(
					"Cannot open/create temp file %s"),
					rtemp);
		if ((odes = fopen(ofile, "w")) == NULL)
			error(gettext("Cannot open output %s"), ofile);
	}
	/* Call DIFF command */
	(void) strcpy(diffcmd, DIFF);
	(void) strcat(diffcmd, file1);
	(void) strcat(diffcmd, " ");
	(void) strcat(diffcmd, file2);
	diffdes = popen(diffcmd, "r");

	num1 = num2 = 0;

	/*
	 * Read in diff output and decode commands
	 * "change" is used to determine character to put in gutter
	 *  num1 and num2 counts the number of lines in file1 and 2
	 */

	n = 0;
	while ((bp = fgetline(diffdes)) != NULL) {
		change = ' ';
		com = cmd(bp);

	/*
	 * handles all diff output that is not cmd
	 * lines starting with <, >, ., ---
	 */
		if (com == 0)
			continue;

	/* Catch up to from1 and from2 */
		rcode = 1;
		n1 = from1 - num1;
		n2 = from2 - num2;
		n = n1 > n2 ? n2 : n1;
		if (com == 'c' && n > 0)
			n--;
		if (silent)
			(void) fputs(bp, stdout);
		while (n-- > 0) {
			(void) put1();
			(void) put2();
			if (!silent)
				(void) putc('\n', stdout);
			midflg = 0;
		}

	/* Process diff cmd */
		switch (com) {

		case 'a':
			change = '>';
			while (num2 < to2) {
				(void) put2();
				(void) putc('\n', stdout);
				midflg = 0;
			}
			break;

		case 'd':
			change = '<';
			while (num1 < to1) {
				(void) put1();
				(void) putc('\n', stdout);
				midflg = 0;
			}
			break;

		case 'c':
			n1 = to1 - from1;
			n2 = to2 - from2;
			n = n1 > n2 ? n2 : n1;
			change = '|';
			do {
				(void) put1();
				(void) put2();
				(void) putc('\n', stdout);
				midflg = 0;
			} while (n--);

			change = '<';
			while (num1 < to1) {
				(void) put1();
				(void) putc('\n', stdout);
				midflg = 0;
			}

			change = '>';
			while (num2 < to2) {
				(void) put2();
				(void) putc('\n', stdout);
				midflg = 0;
			}
			break;

		default:
			(void) fprintf(stderr, gettext(
				"%c: cmd not found\n"), cmd);
			break;
		}

		if (oflag == 1 && com != 0) {
			cmdin();
			if ((left = fopen(ltemp, "w")) == NULL)
				error(gettext(
					"main: Cannot open temp %s"), ltemp);
			if ((right = fopen(rtemp, "w")) == NULL)
				error(gettext(
					"main: Cannot open temp %s"), rtemp);
		}
	}
	/* put out remainder of input files */

	while (put1()) {
		(void) put2();
		if (!silent)
			(void) putc('\n', stdout);
		midflg = 0;
	}
	if (odes)
		(void) fclose(odes);
	sremove();
	return (rcode);
}
예제 #17
0
파일: mouse.c 프로젝트: tengben/yyy
int main(void)
{
	fb_info_t fb;
	mevent_t mevent;
	
	int fd, mfd;

	int m_x, m_y;
	if((fd = open("/dev/fb0", O_RDWR)) < 0)
	{
		perror("open /dev/fb0 error:");
		exit(1);
	}
	if(-1L == ioctl(fd, FBIOGET_VSCREENINFO, &(fb.fb_var)))
	{
		printf("ioctl FBIOGET_VSCREENINFO\n");
		exit(1);
	}
	fb.w = fb.fb_var.xres;
	fb.h = fb.fb_var.yres;
	fb.bpp = fb.fb_var.bits_per_pixel;
	fb.fd = fd;
	fb.fb_mem = mmap(NULL, fb.w*fb.h*fb.bpp/8, PROT_READ|PROT_WRITE, MAP_SHARED, fb.fd,0);
	if(MAP_FAILED == fb.fb_mem)
	{
		printf("mmap error!");
		exit(1);
	}

	m_x = fb.w / 2;
	m_y = fb.h / 2;

	put1(&fb,0xFFFF);
	put2(&fb,0xFFFF);
	put3(&fb,0xFFFF);

	//Step 1	
	mouse_save(&fb, m_x, m_y);

	//Step 2
	mouse_draw_take(&fb, m_x, m_y);

	mfd = open("/dev/input/mice", O_RDWR | O_NONBLOCK);
	if(mfd < 0)
	{
		perror("open /dev/input/mice error:");
		exit(1);
	}


	while(1)
	{
		if(mouse_parse(mfd, &mevent) == 0)
		{
			//Step 3
			mouse_restore(&fb, m_x, m_y);

			m_x += mevent.dx;
			m_y += mevent.dy;
			
			if(m_x < 0)
				m_x = 0;
			if(m_x > (fb.w-C_WIDTH-1))
				m_x = fb.w - C_WIDTH-1;
			if(m_y < 0)
				m_y = 0;
			if(m_y > (fb.h-C_HEIGHT-1))
				m_y = fb.h-C_HEIGHT-1;
			if((m_x > x_start_l)&&(m_x < x_start_r)&&(m_y > y_start_l)&&(m_y < y_start_r))
			{
				mouse_save(&fb, m_x, m_y);
				mouse_draw_load(&fb, m_x, m_y);
				if(mevent.button == 1)
				{
				/*开始*/
				printf("star\n");
			//	exit(1);
				}
			}
			else if((m_x > x_list_l)&&(m_x < x_list_r)&&(m_y > y_list_l)&&(m_y < y_list_r))
			{
				mouse_save(&fb, m_x, m_y);
				mouse_draw_load(&fb, m_x, m_y);
				if(mevent.button == 1)
				{
				/*列表*/
				printf("list\n");
			//	exit(1);
				}	
			}
			else if((m_x > x_quit_l)&&(m_x < x_quit_r)&&(m_y > y_quit_l)&&(m_y < y_quit_r))
			{
				mouse_save(&fb, m_x, m_y);
				mouse_draw_load(&fb, m_x, m_y);
				if(mevent.button == 1)
				{
				/*退出*/
				printf("exit\n");
			//	exit(1);
				}
			}
			else
			{	
				mouse_save(&fb, m_x, m_y);	
				mouse_draw_take(&fb, m_x, m_y);
			}
		}
	}
	close(fb.fd);
	munmap(fb.fb_mem,fb.w*fb.h*fb.bpp/8);
	return 0;	

}	
예제 #18
0
void
conv(register FILE *fp)
{
	register int c, k;
	int m, n, n1, m1;
	char str[4096], buf[4096];

	while ((c = getc(fp)) != EOF) {
		switch (c) {
		case '\n':	/* when input is text */
		case ' ':
		case 0:		/* occasional noise creeps in */
			break;
		case '{':	/* push down current environment */
			t_push();
			break;
		case '}':
			t_pop();
			break;
		case '0': case '1': case '2': case '3': case '4':
		case '5': case '6': case '7': case '8': case '9':
			/* two motion digits plus a character */
			hmot((c-'0')*10 + getc(fp)-'0');
			put1(getc(fp));
			break;
		case 'c':	/* single ascii character */
			put1(getc(fp));
			break;
		case 'C':
			sget(str, sizeof str, fp);
			put1s(str);
			break;
		case 't':	/* straight text */
			fgets(buf, sizeof(buf), fp);
			t_text(buf);
			break;
		case 'D':	/* draw function */
			fgets(buf, sizeof(buf), fp);
			switch (buf[0]) {
			case 'l':	/* draw a line */
				sscanf(buf+1, "%d %d", &n, &m);
				drawline(n, m, ".");
				break;
			case 'c':	/* circle */
				sscanf(buf+1, "%d", &n);
				drawcirc(n);
				break;
			case 'e':	/* ellipse */
				sscanf(buf+1, "%d %d", &m, &n);
				drawellip(m, n);
				break;
			case 'a':	/* arc */
				sscanf(buf+1, "%d %d %d %d", &n, &m, &n1, &m1);
				drawarc(n, m, n1, m1);
				break;
			case '~':	/* wiggly line */
				drawwig(buf+1);
				break;
			default:
				error(FATAL, "unknown drawing function %s\n", buf);
				break;
			}
			break;
		case 's':
			fscanf(fp, "%d", &n);
			if (n == -23) {
				float	f;
				fscanf(fp, "%f", &f);
				setsize(f);
			} else
				setsize(t_size(n));/* ignore fractional sizes */
			break;
		case 'f':
			sget(str, sizeof str, fp);
			setfont(t_font(str));
			break;
		case 'H':	/* absolute horizontal motion */
			/* fscanf(fp, "%d", &n); */
			while ((c = getc(fp)) == ' ')
				;
			k = 0;
			do {
				k = 10 * k + c - '0';
			} while (isdigit(c = getc(fp)));
			ungetc(c, fp);
			hgoto(k);
			break;
		case 'h':	/* relative horizontal motion */
			/* fscanf(fp, "%d", &n); */
			while ((c = getc(fp)) == ' ')
				;
			k = 0;
			do {
				k = 10 * k + c - '0';
			} while (isdigit(c = getc(fp)));
			ungetc(c, fp);
			hmot(k);
			break;
		case 'w':	/* word space */
			putc(' ', stdout);
			break;
		case 'V':
			fscanf(fp, "%d", &n);
			vgoto(n);
			break;
		case 'v':
			fscanf(fp, "%d", &n);
			vmot(n);
			break;
		case 'p':	/* new page */
			fscanf(fp, "%d", &n);
			t_page(n);
			break;
		case 'n':	/* end of line */
			while (getc(fp) != '\n')
				;
			t_newline();
			break;
		case '#':	/* comment */
			while (getc(fp) != '\n')
				;
			break;
		case 'x':	/* device control */
			devcntrl(fp);
			break;
		default:
			error(!FATAL, "unknown input character %o %c\n", c, c);
			done();
		}
	}
}
예제 #19
0
void put2( byte *c )
{
    put1( c );
    put1( c+1 );
}
예제 #20
0
void put2( unsigned char *c )
{
    put1( c );
    put1( c+1 );
}
예제 #21
0
파일: draw.c 프로젝트: aksr/heirloom
void
drawline(int dx, int dy, char *s) /* draw line from here to dx, dy using s */
{
	int xd, yd;
	float val, slope;
	int i, numdots;
	int dirmot, perp;
	int motincr, perpincr;
	int ohpos, ovpos, osize;
	float incrway;

	int itemp; /*temp. storage for value returned byint function sgn*/
	osize = size;
	setsize(t_size(pstab[osize-1] / drawsize));
	ohpos = hpos;
	ovpos = vpos;
	xd = dx / DX;
	yd = dy / DX;
	if (xd == 0) {
		numdots = abs (yd);
		numdots = min(numdots, maxdots);
		motincr = DX * sgn (yd);
		for (i = 0; i < numdots; i++) {
			vmot(motincr);
			put1(drawdot);
		}
		vgoto(ovpos + dy);
		setsize(osize);
		return;
	}
	if (yd == 0) {
		numdots = abs (xd);
		motincr = DX * sgn (xd);
		for (i = 0; i < numdots; i++) {
			hmot(motincr);
			put1(drawdot);
		}
		hgoto(ohpos + dx);
		setsize(osize);
		return;
	}
	if (abs (xd) > abs (yd)) {
		val = slope = (float) xd/yd;
		numdots = abs (xd);
		numdots = min(numdots, maxdots);
		dirmot = 'h';
		perp = 'v';
		motincr = DX * sgn (xd);
		perpincr = DX * sgn (yd);
	}
	else {
		val = slope = (float) yd/xd;
		numdots = abs (yd);
		numdots = min(numdots, maxdots);
		dirmot = 'v';
		perp = 'h';
		motincr = DX * sgn (yd);
		perpincr = DX * sgn (xd);
	}
	incrway = itemp = sgn ((int) slope);
	for (i = 0; i < numdots; i++) {
		val -= incrway;
		if (dirmot == 'h')
			hmot(motincr);
		else
			vmot(motincr);
		if (val * slope < 0) {
			if (perp == 'h')
				hmot(perpincr);
			else
				vmot(perpincr);
			val += slope;
		}
		put1(drawdot);
	}
	hgoto(ohpos + dx);
	vgoto(ovpos + dy);
	setsize(osize);
}