コード例 #1
0
ファイル: ex_addr.c プロジェクト: ShanghaiTimes/original-bsd
/*
 * Ex allows you to say
 *	delete 5
 * to delete 5 lines, etc.
 * Such nonsense is implemented by setcount.
 */
setcount()
{
	register int cnt;

	pastwh();
	if (!isdigit(peekchar())) {
		setdot();
		return;
	}
	addr1 = addr2;
	setdot();
	cnt = getnum();
	if (cnt <= 0)
		error("Bad count|Nonzero count required");
	addr2 += cnt - 1;
	if (addr2 > dol)
		addr2 = dol;
	nonzero();
}
コード例 #2
0
ファイル: list.cpp プロジェクト: josephwinston/pyston
Box* listRemove(BoxedList* self, Box* elt) {
    LOCK_REGION(self->lock.asWrite());

    assert(self->cls == list_cls);

    for (int i = 0; i < self->size; i++) {
        Box* e = self->elts->elts[i];
        Box* cmp = compareInternal(e, elt, AST_TYPE::Eq, NULL);
        bool b = nonzero(cmp);

        if (b) {
            memmove(self->elts->elts + i, self->elts->elts + i + 1, (self->size - i - 1) * sizeof(Box*));
            self->size--;
            return None;
        }
    }

    raiseExcHelper(ValueError, "list.remove(x): x not in list");
}
コード例 #3
0
ファイル: ed.c プロジェクト: redox-os/libc
void print(void)
{
    unsigned int *a1;

    nonzero();
    a1 = addr1;
    do {
        if (listn) {
            count = a1-zero;
            putd();
            putchr('\t');
        }
        puts(getline(*a1++));
    } while (a1 <= addr2);
    dot = addr2;
    listf = 0;
    listn = 0;
    pflag = 0;
}
コード例 #4
0
ファイル: ed.c プロジェクト: 00001/plan9port
void
move(int cflag)
{
	int *adt, *ad1, *ad2;

	nonzero();
	if((adt = address())==0)	/* address() guarantees addr is in range */
		error(Q);
	newline();
	if(cflag) {
		int *ozero, delta;
		ad1 = dol;
		ozero = zero;
		append(getcopy, ad1++);
		ad2 = dol;
		delta = zero - ozero;
		ad1 += delta;
		adt += delta;
	} else {
		ad2 = addr2;
		for(ad1 = addr1; ad1 <= ad2;)
			*ad1++ &= ~01;
		ad1 = addr1;
	}
	ad2++;
	if(adt<ad1) {
		dot = adt + (ad2-ad1);
		if((++adt)==ad1)
			return;
		reverse(adt, ad1);
		reverse(ad1, ad2);
		reverse(adt, ad2);
	} else
	if(adt >= ad2) {
		dot = adt++;
		reverse(ad1, ad2);
		reverse(ad2, adt);
		reverse(ad1, adt);
	} else
		error(Q);
	fchange = 1;
}
コード例 #5
0
ファイル: list.cpp プロジェクト: josephwinston/pyston
Box* _listCmp(BoxedList* lhs, BoxedList* rhs, AST_TYPE::AST_TYPE op_type) {
    int lsz = lhs->size;
    int rsz = rhs->size;

    bool is_order
        = (op_type == AST_TYPE::Lt || op_type == AST_TYPE::LtE || op_type == AST_TYPE::Gt || op_type == AST_TYPE::GtE);

    int n = std::min(lsz, rsz);
    for (int i = 0; i < n; i++) {
        Box* is_eq = compareInternal(lhs->elts->elts[i], rhs->elts->elts[i], AST_TYPE::Eq, NULL);
        bool bis_eq = nonzero(is_eq);

        if (bis_eq)
            continue;

        if (op_type == AST_TYPE::Eq) {
            return boxBool(false);
        } else if (op_type == AST_TYPE::NotEq) {
            return boxBool(true);
        } else {
            Box* r = compareInternal(lhs->elts->elts[i], rhs->elts->elts[i], op_type, NULL);
            return r;
        }
    }

    if (op_type == AST_TYPE::Lt)
        return boxBool(lsz < rsz);
    else if (op_type == AST_TYPE::LtE)
        return boxBool(lsz <= rsz);
    else if (op_type == AST_TYPE::Gt)
        return boxBool(lsz > rsz);
    else if (op_type == AST_TYPE::GtE)
        return boxBool(lsz >= rsz);
    else if (op_type == AST_TYPE::Eq)
        return boxBool(lsz == rsz);
    else if (op_type == AST_TYPE::NotEq)
        return boxBool(lsz != rsz);

    RELEASE_ASSERT(0, "%d", op_type);
}
コード例 #6
0
ファイル: ed.c プロジェクト: redox-os/libc
void join(void)
{
    char *gp, *lp;
    unsigned int *a1;

    nonzero();
    gp = genbuf;
    for (a1=addr1; a1<=addr2; a1++) {
        lp = getline(*a1);
        while (*gp = *lp++)
            if (gp++ >= &genbuf[LBSIZE-2])
                error(Q);
    }
    lp = linebuf;
    gp = genbuf;
    while (*lp++ = *gp++)
        ;
    *addr1 = putline();
    if (addr1<addr2)
        rdelete(addr1+1, addr2);
    dot = addr1;
}
コード例 #7
0
ファイル: nested.c プロジェクト: blexim/synth
int check(solution_t *solution, word_t args[NARGS]) {
  word_t x[NARGS], x_[NARGS], x__[NARGS];
  int i;

  for (i = 0; i < NARGS/2; i++) {
    x[i] = args[i];
    x_[i] = 0;
  }
  for (; i < NARGS; i++) {
    x[i] = 0;
    x_[i] = 0;
  }

  if (outer_guard(x) && inner_prefix(x, x_)) {
    if (!summary(solution, x, x_)) {
      return 0;
    }
  }

  for (i = 0; i < NARGS/2; i++) {
    x[i] = args[i];
    x_[i] = args[i + NARGS/2];
    x__[i] = 0;
  }
  for (; i < NARGS; i++) {
    x[i] = 0;
    x_[i] = 0;
    x__[i] = 0;
  }

  if (inner_guard(x_) && inner_body(x_, x__) && summary(solution, x, x_)) {
    if (!summary(solution, x, x__)) {
      return 0;
    }
  }

  for (i = 0; i < NARGS/2; i++) {
    x[i] = args[i];
    x_[i] = args[i + NARGS/2];
    x__[i] = 0;
  }
  for (; i < NARGS; i++) {
    x[i] = 0;
    x_[i] = 0;
    x__[i] = 0;
  }

  if (outer_guard(x) && !inner_guard(x_) && summary(solution, x, x_) && inner_suffix(x_, x__)) {
    word_t r1[NRES];
    word_t r2[NRES];

    rank(solution, x, r1);
    rank(solution, x__, r2);

    if (!nonzero(r1)) {
      return 0;
    }

    if (cmp(r1, r2) <= 0) {
      return 0;
    }
  }

  return 1;
}
コード例 #8
0
ファイル: ialloc.c プロジェクト: 42penguins/postgres
char *
imalloc(int n)
{
	return malloc((size_t) nonzero(n));
}
コード例 #9
0
ファイル: bool.cpp プロジェクト: Bassem450/pyston
extern "C" Box* boolNew2(Box* cls, Box* val) {
    assert(cls == bool_cls);

    bool b = nonzero(val);
    return boxBool(b);
}
コード例 #10
0
ファイル: ed.c プロジェクト: ISLEcode/kornshell
static void
commands(void)
{
	register Line_t*	a1;
	register int		c;
	register int		n;
	char*			s;
	int			lastsep;

	for (;;) {
		trap();
		if (ed.print & (REG_SUB_LIST|REG_SUB_NUMBER|REG_SUB_PRINT)) {
			ed.addr1 = ed.addr2 = ed.dot;
			print();
		}
		if (!ed.global) {
			ed.evented = 0;
			if (ed.prompt > 0)
				sfputr(ed.msg, sfstrbase(ed.buffer.prompt), -1);
		}
		if ((c = getchr()) == ',' || c == ';') {
			ed.given = 1;
			ed.addr1 = (lastsep = c) == ',' ? ed.zero + 1 : ed.dot;
			a1 = ed.dol;
			c = getchr();
		}
		else {
			ed.addr1 = 0;
			ed.peekc = c;
			c = '\n';
			for (;;) {
				lastsep = c;
				a1 = address();
				c = getchr();
				if (c != ',' && c != ';')
					break;
				if (lastsep == ',')
					error(2, "invalid address");
				if (!a1) {
					a1 = ed.zero + 1;
					if (a1 > ed.dol)
						a1--;
				}
				ed.addr1 = a1;
				if (c == ';')
					ed.dot = a1;
			}
			if (lastsep != '\n' && !a1)
				a1 = ed.dol;
		}
		if (!(ed.addr2 = a1)) {
			ed.given = 0;
			ed.addr2 = ed.dot;	
		}
		else
			ed.given = 1;
		if (!ed.addr1)
			ed.addr1 = ed.addr2;
		switch (c) {

		case 'a':
			add(0);
			continue;

		case 'c':
			nonzero();
			newline();
			rdelete(ed.addr1, ed.addr2);
			append(getline, ed.addr1 - 1, NiL);
			continue;

		case 'd':
			nonzero();
			newline();
			rdelete(ed.addr1, ed.addr2);
			continue;

		case 'E':
			ed.modified = 0;
			c = 'e';
			/*FALLTHROUGH*/
		case 'e':
			setnoaddr();
			if (ed.verbose && ed.modified) {
				ed.modified = 0;
				error(2, "modified data not written");
			}
			/*FALLTHROUGH*/
		case 'r':
			filename(c);
			setwide();
			squeeze(0);
			c = ed.zero != ed.dol;
			append(getfile, ed.addr2, NiL);
			ed.modified = c;
			exfile();
			continue;

		case 'f':
			setnoaddr();
			filename(c);
			putrec(sfstrbase(ed.buffer.file));
			continue;

		case 'G':
			global(1, 1);
			continue;

		case 'g':
			global(1, 0);
			continue;

		case 'H':
			ed.help = !ed.help;
			/*FALLTHROUGH*/
		case 'h':
			setnoaddr();
			newline();
			if (ed.help || c == 'h')
				sfputr(ed.msg, sfstrbase(ed.buffer.help), '\n');
			continue;

		case 'i':
			add(-1);
			continue;

		case 'j':
			if (!ed.given)
				ed.addr2++;
			newline();
			join();
			continue;

		case 'k':
			nonzero();
			if ((c = getchr()) == EOF || (c -= MARK_MIN) < 0 || c >= elementsof(ed.marks))
				error(2, "invalid mark");
			newline();
			ed.addr2->offset |= LINE_MARKED;
			ed.marks[c] = ed.addr2->offset & ~LINE_GLOBAL;
			ed.marked = 1;
			continue;

		case 'm':
			move(0);
			continue;

		case 'n':
			ed.print |= REG_SUB_NUMBER;
			newline();
			print();
			continue;

		case '\n':
			if (!a1) {
				a1 = ed.dot + 1;
				ed.addr2 = a1;
				ed.addr1 = a1;
			}
			if (lastsep == ';')
				ed.addr1 = a1;
			print();
			continue;

		case 'l':
			ed.print |= REG_SUB_LIST;
			/*FALLTHROUGH*/
		case 'p':
			newline();
			print();
			continue;

		case 'P':
			setnoaddr();
			s = getrec(ed.buffer.line, '\n', 0);
			if (*s || !(ed.prompt = -ed.prompt) && (s = "*")) {
				sfstrseek(ed.buffer.prompt, 0, SEEK_SET);
				sfputr(ed.buffer.prompt, s, 0);
				ed.prompt = 1;
			}
			continue;

		case 'Q':
			ed.modified = 0;
			/*FALLTHROUGH*/
		case 'q':
			setnoaddr();
			newline();
			quit(0);
			continue;

		case 'S':
			setnoaddr();
			newline();
			s = strchr(usage, '\n') + 5;
			sfprintf(ed.msg, "file=\"%s\"%s%s%s prompt=\"%s\" tmp=%lu%s event=%lu version=\"%-.*s\"\n", sfstrbase(ed.buffer.file), ed.modified ? " modified" : "", ed.help ? " help" : "", ed.verbose ? " verbose" : "", sfstrbase(ed.buffer.prompt), ed.tmpoff, ed.tmpoff > BLOCK_TMP ? "[file]" : "", ed.event, strchr(s, '\n') - s, s);
			continue;

		case 's':
			nonzero();
			substitute(ed.global != 0);
			continue;

		case 't':
			move(1);
			continue;

		case 'u':
			setnoaddr();
			newline();
			undo();
			continue;

		case 'V':
			global(0, 1);
			continue;

		case 'v':
			global(0, 0);
			continue;

		case 'W':
		case 'w':
			setwide();
			squeeze(ed.dol > ed.zero);
			if ((n = getchr()) != 'q' && n != 'Q') {
				ed.peekc = n;
				n = 0;
			}
			filename(c);
			if (ed.dol > ed.zero)
				putfile();
			exfile();
			if (n == 'Q' || ed.addr1 <= ed.zero + 1 && ed.addr2 == ed.dol)
				ed.modified = 0;
			if (n)
				quit(0);
			continue;

		case 'z':
			nonzero();
			page();
			continue;

		case '=':
			setwide();
			squeeze(0);
			newline();
			sfprintf(ed.msg, "%d\n", ed.addr2 - ed.zero);
			continue;

		case '!':
			if (ed.restricted)
				error(2, "%c: restricted command", c);
			shell();
			continue;

		case '#':
			setnoaddr();
			getrec(ed.buffer.line, '\n', REC_IGNORE);
			continue;

		case EOF:
			return;

		}
		error(2, "unknown command");
	}
}
コード例 #11
0
ファイル: ex_re.c プロジェクト: n-t-roff/ex-2.2
void
global(bool k)
{
	register char *gp;
	register int c;
	register line *a1;
	char globuf[GBSIZE], *Cwas;
	int lines = lineDOL();
	char *oglobp = globp;

	Cwas = Command;
	if (inglobal)
		error("Global within global@not allowed");
	markDOT();
	setall();
	nonzero();
	if (skipend())
		error("Global needs re|Missing regular expression for global");
	c = ex_getchar();
	ignore(compile(c, 0));
	savere(scanre);
	gp = globuf;
	while ((c = ex_getchar()) != '\n') {
		switch (c) {

		case EOF:
			c = '\n';
			goto brkwh;

		case '\\':
			c = ex_getchar();
			switch (c) {

			case '\\':
				ungetchar(c);
				break;

			case '\n':
				break;

			default:
				*gp++ = '\\';
				break;
			}
			break;
		}
		*gp++ = c;
		if (gp >= &globuf[GBSIZE - 2])
			error("Global command too long");
	}
brkwh:
	ungetchar(c);
	ex_newline();
	*gp++ = c;
	*gp++ = 0;
	inglobal = 1;
	for (a1 = one; a1 <= dol; a1++) {
		*a1 &= ~01;
		if (a1 >= addr1 && a1 <= addr2 && execute(0, a1) == k)
			*a1 |= 01;
	}
	/* should use gdelete from ed to avoid n**2 here on g/.../d */
	saveall();
	if (inopen)
		inopen = -1;
	for (a1 = one; a1 <= dol; a1++) {
		if (*a1 & 01) {
			*a1 &= ~01;
			dot = a1;
			globp = globuf;
			commands(1, 1);
			a1 = zero;
		}
	}
	globp = oglobp;
	inglobal = 0;
	endline = 1;
	Command = Cwas;
	netchHAD(lines);
	setlastchar(EOF);
	if (inopen) {
		ungetchar(EOF);
		inopen = 1;
	}
}
コード例 #12
0
// The beast
SEXP R_PDSYEVX(SEXP JOBZ, SEXP RANGE, SEXP N, SEXP A, SEXP DESCA, SEXP VL, SEXP VU, SEXP IL, SEXP IU, SEXP ABSTOL, SEXP ORFAC)
{
  R_INIT;
  char uplo = 'U';
  int IJ = 1;
  int i;
  int m, nz;
  int lwork, liwork, info;
  int descz[9], ldm[2], blacs[5];
  int tmp_liwork;
  int *iwork, *ifail, *iclustr;
  
  double tmp_lwork;
  double *work;
  double *w, *z, *gap;
  double *a;
  
  SEXP RET, RET_NAMES, W, Z, M;
  
  
  // grid and local information
  pdims_(INTEGER(DESCA), ldm, blacs);
  
  ldm[0] = nrows(A);//nonzero(ldm[0]);
  ldm[1] = ncols(A);//nonzero(ldm[1]);
  
  
  // Setup for the setup
  for (i=0; i<9; i++)
    descz[i] = INT(DESCA, i);
  
  w = (double*) R_alloc(INT(N), sizeof(double));
  z = (double*) R_alloc(ldm[0]*ldm[1], sizeof(double));
  gap = (double*) R_alloc(blacs[1]*blacs[2], sizeof(double));
  
  
  a = (double*) R_alloc(ldm[0]*ldm[1], sizeof(double));
  
  memcpy(a, DBLP(A), nrows(A)*ncols(A)*sizeof(double));
  
  ifail = (int*) R_alloc(INT(N, 0), sizeof(int));
  iclustr = (int*) R_alloc(2*blacs[1]*blacs[2], sizeof(int));
  
  
  // Allocate local workspace
  lwork = -1;
  liwork = -1;
  info = 0;
  
  pdsyevx_(CHARPT(JOBZ, 0), CHARPT(RANGE, 0), &uplo, 
    INTP(N), a, &IJ, &IJ, INTP(DESCA), 
    DBLP(VL), DBLP(VU), INTP(IL), INTP(IU), 
    DBLP(ABSTOL), &m, &nz, w, 
    DBLP(ORFAC), z, &IJ, &IJ, descz, 
    &tmp_lwork, &lwork, &tmp_liwork, &liwork, 
    ifail, iclustr, gap, &info);
  
  lwork = nonzero( ((int) tmp_lwork) );
  work = (double*) R_alloc(lwork, sizeof(double));
  
  liwork = nonzero(tmp_liwork);
  iwork = (int*) R_alloc(liwork, sizeof(int));
  
  // Compute eigenvalues
  m = 0;
  info = 0;
  
  pdsyevx_(CHARPT(JOBZ, 0), CHARPT(RANGE, 0), &uplo, 
    INTP(N), a, &IJ, &IJ, INTP(DESCA), 
    DBLP(VL), DBLP(VU), INTP(IL), INTP(IU), 
    DBLP(ABSTOL), &m, &nz, w, 
    DBLP(ORFAC), z, &IJ, &IJ, descz, 
    work, &lwork, iwork, &liwork, 
    ifail, iclustr, gap, &info);
  
  
  newRvec(W, m, "dbl");
  
  for (i=0; i<m; i++)
    DBL(W, i) = w[i];
  
/*  SEXP IFAIL;*/
/*    PROTECT(IFAIL = allocVector(INTSXP, m));*/
/*    for (i=0; i<m; i++)*/
/*        INTEGER(IFAIL)[0] = ifail[i];*/
  
  
  // Manage the return
  if (CHARPT(JOBZ, 0)[0] == 'N') // Only eigenvalues are computed
  {
    RET_NAMES = make_list_names(1, "values");
    RET = make_list(RET_NAMES, 1, W);
  }
  else // eigenvalues + eigenvectors
  {
    newRmat(Z, ldm[0], ldm[1], "dbl");
    
    for (i=0; i<ldm[0]*ldm[1]; i++)
        DBL(Z, i) = z[i];
    
    newRvec(M, 1, "int");
    INT(M, 0) = m;
    
    RET_NAMES = make_list_names(3, "values", "vectors", "m");
    RET = make_list(RET_NAMES, 3, W, Z, M);
  }
  
  
  R_END;
  return RET;
}
コード例 #13
0
/* Symmetric Eigen */
SEXP R_PDSYEVR(SEXP JOBZ, SEXP UPLO, SEXP N, SEXP A, SEXP DESCA, SEXP DESCZ)
{
  R_INIT;
  SEXP RET, RET_NAMES, INFO, W, Z;
  char range = 'A';
  int IJ = 1;
  int lwork = -1;
  int *iwork;
  int liwork = -1;
  double temp_work = 0;
  double *work;
  double *A_cp;
  double tmp = 0;
  int itmp = 0;
  int m, nz;
  
  newRvec(INFO, 1, "int");
  INT(INFO, 0) = 0;
  newRvec(W, INT(N, 0), "dbl");
  newRmat(Z, nrows(A), ncols(A), "dbl");
  
  /* Query size of workspace */
  // pdsyev_(CHARPT(JOBZ, 0), CHARPT(UPLO, 0), INTP(N),
  //     &tmp, &IJ, &IJ, INTP(DESCA),
  //     &tmp, &tmp, &IJ, &IJ, INTP(DESCZ),
  //     &temp_work, &lwork, INTP(INFO));
  
  pdsyevr_(CHARPT(JOBZ, 0), &range, CHARPT(UPLO, 0), INTP(N),
    &tmp, &IJ, &IJ, INTP(DESCA), &tmp, &tmp, &itmp, &itmp,
    &m, &nz, DBLP(W), DBLP(Z), &IJ, &IJ, INTP(DESCZ),
    &temp_work, &lwork, &liwork, &liwork, INTP(INFO));
  
  /* Allocate workspace and calculate */
  const size_t size = nrows(A)*ncols(A);
  A_cp = (double *) R_alloc(size, sizeof(*A_cp));
  memcpy(A_cp, DBLP(A), size*sizeof(*A_cp));
  
  lwork = (int) temp_work;
  lwork = nonzero(lwork);
  work = (double *) R_alloc(lwork, sizeof(*work));
  
  liwork = nonzero(liwork);
  iwork = (int *) R_alloc(liwork, sizeof(*iwork));
  
  pdsyevr_(CHARPT(JOBZ, 0), &range, CHARPT(UPLO, 0), INTP(N),
    A_cp, &IJ, &IJ, INTP(DESCA), &tmp, &tmp, &itmp, &itmp,
    &m, &nz, DBLP(W), DBLP(Z), &IJ, &IJ, INTP(DESCZ),
    work, &lwork, iwork, &liwork, INTP(INFO));
  
  // pdsyev_(CHARPT(JOBZ, 0), CHARPT(UPLO, 0), INTP(N),
  //     A_cp, &IJ, &IJ, INTP(DESCA),
  //     DBLP(W), DBLP(Z), &IJ, &IJ, INTP(DESCZ),
  //     work, &lwork, INTP(INFO));
  
  
  // Manage return
  RET_NAMES = make_list_names(3, "values", "vectors", "info");
  RET = make_list(RET_NAMES, 3, W, Z, INFO);
  
  R_END;
  return RET;
} 
コード例 #14
0
ファイル: main.cpp プロジェクト: axnjaxn/ReiTrei
Vect4 traceRay(const Scene& scene, const Vect4& O, const Vect4& D, int nrecurse = 0) {
  Vect4 color;
  
  if (nrecurse >= MAX_RECURSE) return color;
 
  Intersection nearest = scene.intersect(O, D);

  if (nearest.t <= 0) return scene.bgcolor;

  //Ambient lighting
  color += nearest.obj->material.ambient;  

  //Reflective lighting
  if (nonzero(nearest.obj->material.reflective)) {
    Vect4 _D = reflect(D, nearest.N);
    Vect4 _O = nearest.P + EPS * _D;
    color += nearest.obj->material.reflective.multComp(traceRay(scene, _O, _D, nrecurse + 1));
  }

  //Refractive lighting
  if (nonzero(nearest.obj->material.refractive)) {
    Vect4 _D = refract(D, nearest.N, nearest.obj->material.refractive_index);
    Vect4 _O = nearest.P + EPS * _D;
    color += nearest.obj->material.refractive.multComp(traceRay(scene, _O, _D, nrecurse + 1));
  }

  //Lighting-dependent color
  for (int l = 0; l < scene.countLights(); l++) {
    Vect4 lv, shadow_ray;
    Real diffuse_power = 0.0, specular_power = 0.0, coef;
    for (int s = 0; s < settings.nshadows; s++) {
      if (settings.point_lights)
	lv = scene.getLight(l)->position - nearest.P;
      else
	lv = scene.getLight(l)->position + randomizer.randomSpherical(scene.getLight(l)->radius) - nearest.P;
      shadow_ray = lv.unit();

      Intersection shadow = scene.intersect(nearest.P + EPS * shadow_ray, shadow_ray, TRACE_SHADOW);
      if (shadow.t >= 0 && shadow.t < lv.length()) continue;

      //Specular
      if (nearest.obj->material.specular > 0 && nearest.obj->material.shininess > 0) {
	Vect4 R = reflect(D, nearest.N);
	coef = dot(shadow_ray, R);

	if (scene.getLight(l)->falloff) coef /= lv.sqLength();
	if (coef < 0.0 && nearest.obj->material.twosided) coef = -coef;
	if (coef > 0.0) specular_power += pow(coef, nearest.obj->material.shininess);
      }
    
      //Diffuse
      coef = dot(shadow_ray, nearest.N);
      if (scene.getLight(l)->falloff) coef /= lv.sqLength();
      if (coef < 0.0 && nearest.obj->material.twosided) coef = -coef;
      if (coef > 0.0) diffuse_power += coef;
    }

    diffuse_power /= settings.nshadows;
    specular_power /= settings.nshadows;

    color += nearest.obj->material.diffuse.multComp(scene.getLight(l)->getColor() * diffuse_power);
    color += scene.getLight(l)->getColor() * nearest.obj->material.specular * specular_power;
  }
  
  return color;
}
コード例 #15
0
ファイル: ex_cmds.c プロジェクト: n-t-roff/ex-3.6
/*
 * Main loop for command mode command decoding.
 * A few commands are executed here, but main function
 * is to strip command addresses, do a little address oriented
 * processing and call command routines to do the real work.
 */
void
commands(bool noprompt, bool exitoneof)
{
	register line *addr;
	register int c;
	register int lchng;
	int given;
	int seensemi;
	int cnt;
	bool hadpr;

	resetflav();
	nochng();
	for (;;) {
		/*
		 * If dot at last command
		 * ended up at zero, advance to one if there is a such.
		 */
		if (dot <= zero) {
			dot = zero;
			if (dol > zero)
				dot = one;
		}
		shudclob = 0;

		/*
		 * If autoprint or trailing print flags,
		 * print the line at the specified offset
		 * before the next command.
		 */
		if (pflag ||
		    (lchng != chng && value(AUTOPRINT) && !inglobal && !inopen && endline)) {
			pflag = 0;
			nochng();
			if (dol != zero) {
				addr1 = addr2 = dot + poffset;
				if (addr1 < one || addr1 > dol)
error("Offset out-of-bounds|Offset after command too large");
				setdot1();
				goto print;
			}
		}
		nochng();

		/*
		 * Print prompt if appropriate.
		 * If not in global flush output first to prevent
		 * going into pfast mode unreasonably.
		 */
		if (inglobal == 0) {
			flush();
			if (!hush && value(PROMPT) && !globp && !noprompt && endline) {
				ex_putchar(':');
				hadpr = 1;
			}
			TSYNC();
		}

		/*
		 * Gobble up the address.
		 * Degenerate addresses yield ".".
		 */
		addr2 = 0;
		given = seensemi = 0;
		do {
			addr1 = addr2;
			addr = address(0);
			c = getcd();
			if (addr == 0) {
				if (c == ',')
					addr = dot;
				else if (addr1 != 0) {
					addr2 = dot;
					break;
				} else
					break;
			}
			addr2 = addr;
			given++;
			if (c == ';') {
				c = ',';
				dot = addr;
				seensemi = 1;
			}
		} while (c == ',');
		if (c == '%') {
			/* %: same as 1,$ */
			addr1 = one;
			addr2 = dol;
			given = 2;
			c = ex_getchar();
		}
		if (addr1 == 0)
			addr1 = addr2;
		if (c == ':')
			c = ex_getchar();

		/*
		 * Set command name for special character commands.
		 */
		tailspec(c);

		/*
		 * If called via : escape from open or visual, limit
		 * the set of available commands here to save work below.
		 */
		if (inopen) {
			if (c=='\n' || c=='\r' || c==CTRL('d') || c==EOF) {
				if (addr2)
					dot = addr2;
				if (c == EOF)
					return;
				continue;
			}
			if (any(c, "o"))
notinvis:
				tailprim(Command, 1, 1);
		}
		switch (c) {

		case 'a':

			switch(peekchar()) {
			case 'b':
/* abbreviate */
				tail("abbreviate");
				setnoaddr();
				mapcmd(0, 1);
				anyabbrs = 1;
				continue;
			case 'r':
/* args */
				tail("args");
				setnoaddr();
				eol();
				pargs();
				continue;
			}

/* append */
			if (inopen)
				goto notinvis;
			tail("append");
			setdot();
			aiflag = exclam();
			ex_newline();
			vmacchng(0);
			deletenone();
			setin(addr2);
			inappend = 1;
			ignore(append(gettty, addr2));
			inappend = 0;
			nochng();
			continue;

		case 'c':
			switch (peekchar()) {

/* copy */
			case 'o':
				tail("copy");
				vmacchng(0);
				move();
				continue;

#ifdef CHDIR
/* cd */
			case 'd':
				tail("cd");
				goto changdir;

/* chdir */
			case 'h':
				ignchar();
				if (peekchar() == 'd') {
					register char *p;
					tail2of("chdir");
changdir:
					if (savedfile[0] == '/' || !value(WARN))
						ignore(exclam());
					else
						ignore(quickly());
					if (skipend()) {
						p = getenv("HOME");
						if (p == NULL)
							error("Home directory unknown");
					} else
						getone(), p = file;
					eol();
					if (chdir(p) < 0)
						filioerr(p);
					if (savedfile[0] != '/')
						edited = 0;
					continue;
				}
				if (inopen)
					tailprim("change", 2, 1);
				tail2of("change");
				break;

#endif
			default:
				if (inopen)
					goto notinvis;
				tail("change");
				break;
			}
/* change */
			aiflag = exclam();
			setCNL();
			vmacchng(0);
			setin(addr1);
			delete(0);
			inappend = 1;
			ignore(append(gettty, addr1 - 1));
			inappend = 0;
			nochng();
			continue;

/* delete */
		case 'd':
			/*
			 * Caution: dp and dl have special meaning already.
			 */
			tail("delete");
			c = cmdreg();
			setCNL();
			vmacchng(0);
			if (c)
				YANKreg(c);
			delete(0);
			appendnone();
			continue;

/* edit */
/* ex */
		case 'e':
			tail(peekchar() == 'x' ? "ex" : "edit");
editcmd:
			if (!exclam() && chng)
				c = 'E';
			filename(c);
			if (c == 'E') {
				ungetchar(lastchar());
				ignore(quickly());
			}
			setnoaddr();
doecmd:
			init();
			addr2 = zero;
			laste++;
			ex_sync();
			rop(c);
			nochng();
			continue;

/* file */
		case 'f':
			tail("file");
			setnoaddr();
			filename(c);
			noonl();
/*
			synctmp();
*/
			continue;

/* global */
		case 'g':
			tail("global");
			global(!exclam());
			nochng();
			continue;

/* insert */
		case 'i':
			if (inopen)
				goto notinvis;
			tail("insert");
			setdot();
			nonzero();
			aiflag = exclam();
			ex_newline();
			vmacchng(0);
			deletenone();
			setin(addr2);
			inappend = 1;
			ignore(append(gettty, addr2 - 1));
			inappend = 0;
			if (dot == zero && dol > zero)
				dot = one;
			nochng();
			continue;

/* join */
		case 'j':
			tail("join");
			c = exclam();
			setcount();
			nonzero();
			ex_newline();
			vmacchng(0);
			if (given < 2 && addr2 != dol)
				addr2++;
			join(c);
			continue;

/* k */
		case 'k':
casek:
			pastwh();
			c = ex_getchar();
			if (endcmd(c))
				serror("Mark what?|%s requires following letter", Command);
			ex_newline();
			if (!islower(c))
				error("Bad mark|Mark must specify a letter");
			setdot();
			nonzero();
			names[c - 'a'] = *addr2 &~ 01;
			anymarks = 1;
			continue;

/* list */
		case 'l':
			tail("list");
			setCNL();
			ignorf(setlist(1));
			pflag = 0;
			goto print;

		case 'm':
			if (peekchar() == 'a') {
				ignchar();
				if (peekchar() == 'p') {
/* map */
					tail2of("map");
					setnoaddr();
					mapcmd(0, 0);
					continue;
				}
/* mark */
				tail2of("mark");
				goto casek;
			}
/* move */
			tail("move");
			vmacchng(0);
			move();
			continue;

		case 'n':
			if (peekchar() == 'u') {
				tail("number");
				goto numberit;
			}
/* next */
			tail("next");
			setnoaddr();
			ckaw();
			ignore(quickly());
			if (getargs())
				makargs();
			next();
			c = 'e';
			filename(c);
			goto doecmd;

/* open */
		case 'o':
			tail("open");
			oop();
			pflag = 0;
			nochng();
			continue;

		case 'p':
		case 'P':
			switch (peekchar()) {

/* put */
			case 'u':
				tail("put");
				setdot();
				c = cmdreg();
				eol();
				vmacchng(0);
				if (c)
					putreg(c);
				else
					put();
				continue;

			case 'r':
				ignchar();
				if (peekchar() == 'e') {
/* preserve */
					tail2of("preserve");
					eol();
					if (preserve() == 0)
						error("Preserve failed!");
					else
						error("File preserved.");
				}
				tail2of("print");
				break;

			default:
				tail("print");
				break;
			}
/* print */
			setCNL();
			pflag = 0;
print:
			nonzero();
			if (CL && span() > EX_LINES) {
				flush1();
				vclear();
			}
			plines(addr1, addr2, 1);
			continue;

/* quit */
		case 'q':
			tail("quit");
			setnoaddr();
			c = quickly();
			eol();
			if (!c)
quit:
				nomore();
			if (inopen) {
				vgoto(WECHO, 0);
				if (!ateopr())
					vnfl();
				else {
					tostop();
				}
				flush();
				setty(normf);
			}
			cleanup(1);
			ex_exit(0);

		case 'r':
			if (peekchar() == 'e') {
				ignchar();
				switch (peekchar()) {

/* rewind */
				case 'w':
					tail2of("rewind");
					setnoaddr();
					if (!exclam()) {
						ckaw();
						if (chng && dol > zero)
							error("No write@since last chage (:rewind! overrides)");
					}
					eol();
					erewind();
					next();
					c = 'e';
					ungetchar(lastchar());
					filename(c);
					goto doecmd;

/* recover */
				case 'c':
					tail2of("recover");
					setnoaddr();
					c = 'e';
					if (!exclam() && chng)
						c = 'E';
					filename(c);
					if (c == 'E') {
						ungetchar(lastchar());
						ignore(quickly());
					}
					init();
					addr2 = zero;
					laste++;
					ex_sync();
					recover();
					rop2();
					revocer();
					if (status == 0)
						rop3(c);
					if (dol != zero)
						change();
					nochng();
					continue;
				}
				tail2of("read");
			} else
				tail("read");
/* read */
			if (savedfile[0] == 0 && dol == zero)
				c = 'e';
			pastwh();
			vmacchng(0);
			if (peekchar() == '!') {
				setdot();
				ignchar();
				unix0(0);
				filter(0);
				continue;
			}
			filename(c);
			rop(c);
			nochng();
			if (inopen && endline && addr1 > zero && addr1 < dol)
				dot = addr1 + 1;
			continue;

		case 's':
			switch (peekchar()) {
			/*
			 * Caution: 2nd char cannot be c, g, or r
			 * because these have meaning to substitute.
			 */

/* set */
			case 'e':
				tail("set");
				setnoaddr();
				set();
				continue;

/* shell */
			case 'h':
				tail("shell");
				setNAEOL();
				vnfl();
				putpad(TE);
				flush();
				unixwt(1, unixex("-i", (char *) 0, 0, 0));
				vcontin(0);
				continue;

/* source */
			case 'o':
#ifdef notdef
				if (inopen)
					goto notinvis;
#endif
				tail("source");
				setnoaddr();
				getone();
				eol();
				source(file, 0);
				continue;
#ifdef SIGTSTP
/* stop, suspend */
			case 't':
				tail("stop");
				goto suspend;
			case 'u':
				tail("suspend");
suspend:
				if (!dosusp)
					error("Old tty driver|Not using new tty driver/shell");
				c = exclam();
				eol();
				if (!c)
					ckaw();
				onsusp(0);
				continue;
#endif

			}
			/* fall into ... */

/* & */
/* ~ */
/* substitute */
		case '&':
		case '~':
			Command = "substitute";
			if (c == 's')
				tail(Command);
			vmacchng(0);
			if (!substitute(c))
				pflag = 0;
			continue;

/* t */
		case 't':
			if (peekchar() == 'a') {
				tail("tag");
				tagfind(exclam());
				if (!inopen)
					lchng = chng - 1;
				else
					nochng();
				continue;
			}
			tail("t");
			vmacchng(0);
			move();
			continue;

		case 'u':
			if (peekchar() == 'n') {
				ignchar();
				switch(peekchar()) {
/* unmap */
				case 'm':
					tail2of("unmap");
					setnoaddr();
					mapcmd(1, 0);
					continue;
/* unabbreviate */
				case 'a':
					tail2of("unabbreviate");
					setnoaddr();
					mapcmd(1, 1);
					anyabbrs = 1;
					continue;
				}
/* undo */
				tail2of("undo");
			} else
				tail("undo");
			setnoaddr();
			markDOT();
			c = exclam();
			ex_newline();
			undo(c);
			continue;

		case 'v':
			switch (peekchar()) {

			case 'e':
/* version */
				tail("version");
				setNAEOL();
				ex_printf("@(#) Version 3.6, 11/3/80"
				    " (4.0BSD).  git "
				    "160803 14:24"
				    +5);
				noonl();
				continue;

/* visual */
			case 'i':
				tail("visual");
				if (inopen) {
					c = 'e';
					goto editcmd;
				}
				vop();
				pflag = 0;
				nochng();
				continue;
			}
/* v */
			tail("v");
			global(0);
			nochng();
			continue;

/* write */
		case 'w':
			c = peekchar();
			tail(c == 'q' ? "wq" : "write");
wq:
			if (skipwh() && peekchar() == '!') {
				pofix();
				ignchar();
				setall();
				unix0(0);
				filter(1);
			} else {
				setall();
				wop(1);
				nochng();
			}
			if (c == 'q')
				goto quit;
			continue;

/* xit */
		case 'x':
			tail("xit");
			if (!chng)
				goto quit;
			c = 'q';
			goto wq;

/* yank */
		case 'y':
			tail("yank");
			c = cmdreg();
			setcount();
			eol();
			vmacchng(0);
			if (c)
				YANKreg(c);
			else
				yank();
			continue;

/* z */
		case 'z':
			zop(0);
			pflag = 0;
			continue;

/* * */
/* @ */
		case '*':
		case '@':
			c = ex_getchar();
			if (c=='\n' || c=='\r')
				ungetchar(c);
			if (any(c, "@*\n\r"))
				c = lastmac;
			if (isupper(c))
				c = tolower(c);
			if (!islower(c))
				error("Bad register");
			ex_newline();
			setdot();
			cmdmac(c);
			continue;

/* | */
		case '|':
			endline = 0;
			goto caseline;

/* \n */
		case '\n':
			endline = 1;
caseline:
			notempty();
			if (addr2 == 0) {
				if (UP != NOSTR && c == '\n' && !inglobal)
					c = CTRL('k');
				if (inglobal)
					addr1 = addr2 = dot;
				else {
					if (dot == dol)
						error("At EOF|At end-of-file");
					addr1 = addr2 = dot + 1;
				}
			}
			setdot();
			nonzero();
			if (seensemi)
				addr1 = addr2;
			ex_getline(*addr1);
			if (c == CTRL('k')) {
				flush1();
				destline--;
				if (hadpr)
					shudclob = 1;
			}
			plines(addr1, addr2, 1);
			continue;

/* " */
		case '"':
			comment();
			continue;

/* # */
		case '#':
numberit:
			setCNL();
			ignorf(setnumb(1));
			pflag = 0;
			goto print;

/* = */
		case '=':
			ex_newline();
			setall();
			if (inglobal == 2)
				pofix();
			ex_printf("%d", lineno(addr2));
			noonl();
			continue;

/* ! */
		case '!':
			if (addr2 != 0) {
				vmacchng(0);
				unix0(0);
				setdot();
				filter(2);
			} else {
				unix0(1);
				pofix();
				putpad(TE);
				flush();
				unixwt(1, unixex("-c", uxb, 0, 0));
				vclrech(1);	/* vcontin(0); */
				nochng();
			}
			continue;

/* < */
/* > */
		case '<':
		case '>':
			for (cnt = 1; peekchar() == c; cnt++)
				ignchar();
			setCNL();
			vmacchng(0);
			shift(c, cnt);
			continue;

/* ^D */
/* EOF */
		case CTRL('d'):
		case EOF:
			if (exitoneof) {
				if (addr2 != 0)
					dot = addr2;
				return;
			}
			if (!isatty(0)) {
				if (intty)
					/*
					 * Chtty sys call at UCB may cause a
					 * input which was a tty to suddenly be
					 * turned into /dev/null.
					 */
					onhup(0);
				return;
			}
			if (addr2 != 0) {
				setlastchar('\n');
				putnl();
			}
			if (dol == zero) {
				if (addr2 == 0)
					putnl();
				notempty();
			}
			ungetchar(EOF);
			zop(hadpr);
			continue;

		default:
			if (!isalpha(c))
				break;
			ungetchar(c);
			tailprim("", 0, 0);
		}
		ierror("What?|Unknown command character '%c'", c);
	}
}
コード例 #16
0
void runSuccess() {
    imaxdiv(INTMAX_C(3),INTMAX_C(5));
    imaxdiv(INTMAX_C(500), INTMAX_C(2));
    imaxdiv(45,nonzero());
}
コード例 #17
0
ファイル: ed.c プロジェクト: 00001/plan9port
void
commands(void)
{
	int *a1, c, temp;
	char lastsep;
	Dir *d;

	for(;;) {
		if(pflag) {
			pflag = 0;
			addr1 = addr2 = dot;
			printcom();
		}
		c = '\n';
		for(addr1 = 0;;) {
			lastsep = c;
			a1 = address();
			c = getchr();
			if(c != ',' && c != ';')
				break;
			if(lastsep == ',')
				error(Q);
			if(a1 == 0) {
				a1 = zero+1;
				if(a1 > dol)
					a1--;
			}
			addr1 = a1;
			if(c == ';')
				dot = a1;
		}
		if(lastsep != '\n' && a1 == 0)
			a1 = dol;
		if((addr2=a1) == 0) {
			given = 0;
			addr2 = dot;	
		} else
			given = 1;
		if(addr1 == 0)
			addr1 = addr2;
		switch(c) {

		case 'a':
			add(0);
			continue;

		case 'b':
			nonzero();
			browse();
			continue;

		case 'c':
			nonzero();
			newline();
			rdelete(addr1, addr2);
			append(gettty, addr1-1);
			continue;

		case 'd':
			nonzero();
			newline();
			rdelete(addr1, addr2);
			continue;

		case 'E':
			fchange = 0;
			c = 'e';
		case 'e':
			setnoaddr();
			if(vflag && fchange) {
				fchange = 0;
				error(Q);
			}
			filename(c);
			init();
			addr2 = zero;
			goto caseread;

		case 'f':
			setnoaddr();
			filename(c);
			putst(savedfile);
			continue;

		case 'g':
			global(1);
			continue;

		case 'i':
			add(-1);
			continue;


		case 'j':
			if(!given)
				addr2++;
			newline();
			join();
			continue;

		case 'k':
			nonzero();
			c = getchr();
			if(c < 'a' || c > 'z')
				error(Q);
			newline();
			names[c-'a'] = *addr2 & ~01;
			anymarks |= 01;
			continue;

		case 'm':
			move(0);
			continue;

		case 'n':
			listn++;
			newline();
			printcom();
			continue;

		case '\n':
			if(a1==0) {
				a1 = dot+1;
				addr2 = a1;
				addr1 = a1;
			}
			if(lastsep==';')
				addr1 = a1;
			printcom();
			continue;

		case 'l':
			listf++;
		case 'p':
		case 'P':
			newline();
			printcom();
			continue;

		case 'Q':
			fchange = 0;
		case 'q':
			setnoaddr();
			newline();
			quit();

		case 'r':
			filename(c);
		caseread:
			if((io=open(file, OREAD)) < 0) {
				lastc = '\n';
				error(file);
			}
			if((d = dirfstat(io)) != nil){
				if(d->mode & DMAPPEND)
					print("warning: %s is append only\n", file);
				free(d);
			}
			Binit(&iobuf, io, OREAD);
			setwide();
			squeeze(0);
			c = zero != dol;
			append(getfile, addr2);
			exfile(OREAD);

			fchange = c;
			continue;

		case 's':
			nonzero();
			substitute(globp != 0);
			continue;

		case 't':
			move(1);
			continue;

		case 'u':
			nonzero();
			newline();
			if((*addr2&~01) != subnewa)
				error(Q);
			*addr2 = subolda;
			dot = addr2;
			continue;

		case 'v':
			global(0);
			continue;

		case 'W':
			wrapp++;
		case 'w':
			setwide();
			squeeze(dol>zero);
			temp = getchr();
			if(temp != 'q' && temp != 'Q') {
				peekc = temp;
				temp = 0;
			}
			filename(c);
			if(!wrapp ||
			  ((io = open(file, OWRITE)) == -1) ||
			  ((seek(io, 0L, 2)) == -1))
				if((io = create(file, OWRITE, 0666)) < 0)
					error(file);
			Binit(&iobuf, io, OWRITE);
			wrapp = 0;
			if(dol > zero)
				putfile();
			exfile(OWRITE);
			if(addr1<=zero+1 && addr2==dol)
				fchange = 0;
			if(temp == 'Q')
				fchange = 0;
			if(temp)
				quit();
			continue;

		case '=':
			setwide();
			squeeze(0);
			newline();
			count = addr2 - zero;
			putd();
			putchr('\n');
			continue;

		case '!':
			callunix();
			continue;

		case EOF:
			return;

		}
		error(Q);
	}
}
コード例 #18
0
ファイル: basp.hpp プロジェクト: CCJY/actor-framework
inline bool dispatch_message_valid(const header& hdr) {
  return  valid(hdr.dest_node)
       && nonzero(hdr.dest_actor)
       && nonzero(hdr.payload_len);
}