示例#1
0
int     main(void)
{
    VSTRING *buf = vstring_alloc(100);
    SERVER_ACL *argv;
    int     ret;
    int     have_tty = isatty(0);
    char   *bufp;
    char   *cmd;
    char   *value;
    const NAME_CODE acl_map[] = {
	SERVER_ACL_NAME_ERROR, SERVER_ACL_ACT_ERROR,
	SERVER_ACL_NAME_PERMIT, SERVER_ACL_ACT_PERMIT,
	SERVER_ACL_NAME_REJECT, SERVER_ACL_ACT_REJECT,
	SERVER_ACL_NAME_DUNNO, SERVER_ACL_ACT_DUNNO,
	0,
    };

#define VAR_SERVER_ACL "server_acl"

    while (vstring_get_nonl(buf, VSTREAM_IN) != VSTREAM_EOF) {
	bufp = STR(buf);
	if (have_tty == 0) {
	    vstream_printf("> %s\n", bufp);
	    vstream_fflush(VSTREAM_OUT);
	}
	if (*bufp == '#')
	    continue;
	if ((cmd = mystrtok(&bufp, " =")) == 0 || STREQ(cmd, "?")) {
	    vstream_printf("usage: %s=value|%s=value|address=value\n",
			   VAR_MYNETWORKS, VAR_SERVER_ACL);
	} else if ((value = mystrtok(&bufp, " =")) == 0) {
	    vstream_printf("missing value\n");
	} else if (STREQ(cmd, VAR_MYNETWORKS)) {
	    UPDATE_VAR(var_mynetworks, value);
	} else if (STREQ(cmd, VAR_SERVER_ACL)) {
	    UPDATE_VAR(var_server_acl, value);
	} else if (STREQ(cmd, "address")) {
	    server_acl_pre_jail_init(var_mynetworks, VAR_SERVER_ACL);
	    argv = server_acl_parse(var_server_acl, VAR_SERVER_ACL);
	    ret = server_acl_eval(value, argv, VAR_SERVER_ACL);
	    argv_free(argv);
	    vstream_printf("%s: %s\n", value, str_name_code(acl_map, ret));
	} else {
	    vstream_printf("unknown command: \"%s\"\n", cmd);
	}
	vstream_fflush(VSTREAM_OUT);
    }
    vstring_free(buf);
    exit(0);
}
void Graphics::PlotFlatBottomTriangle(HDC hdc, ScreenPoint p1, ScreenPoint p2, ScreenPoint p3, const Texture& texture) {
	AssertEx(Approximately(p1.y, p2.y) && p1.y >= p3.y, "invalid flat bottom triangle");

	if (p1.x > p2.x) std::swap(p1, p2);
	float dy = -float(p3.y - p1.y);

	float dxdyl = float(p1.x - p3.x) / dy;
	float dxdyr = float(p2.x - p3.x) / dy;

	ColorDiff dcdyl = (p1.color - p3.color) / dy;
	ColorDiff dcdyr = (p2.color - p3.color) / dy;

	float dzdyl = float(1.f / p1.z - 1.f / p3.z) / dy;
	float dzdyr = float(1.f / p2.z - 1.f / p3.z) / dy;

	float dudyl = float(p1.u / p1.z - p3.u / p3.z) / dy;
	float dudyr = float(p2.u / p2.z - p3.u / p3.z) / dy;
	float dvdyl = float(p1.v / p1.z - p3.v / p3.z) / dy;
	float dvdyr = float(p2.v / p2.z - p3.v / p3.z) / dy;

	float xl = (float)p3.x, xr = (float)p3.x;
	float zl = 1.f / p3.z, zr = 1.f / p3.z;

	Color cl = p3.color;
	Color cr = p3.color;

	float ul = (float)p3.u / p3.z;
	float vl = (float)p3.v / p3.z;
	float ur = (float)p3.u / p3.z;
	float vr = (float)p3.v / p3.z;

	int iy1 = 0, iy3 = 0;

	if (p3.y < ymin) {
		UPDATE_VAR(ymin - p3.y);

		p3.y = ymin;
		iy3 = p3.y;
	}
	else {
		iy3 = (int)ceilf(p3.y);
		UPDATE_VAR(iy3 - p3.y);
	}

	if (p1.y > ymax) {
		p1.y = ymax;
		iy1 = p1.y - 1;
	}
	else {
		iy1 = ceilf(p1.y) - 1;
	}

	if (Between(p1.x, xmin, xmax) && Between(p2.x, xmin, xmax) && Between(p3.x, xmin, xmax)) {
		for (int y = iy3; y <= iy1; ++y) {
			PlotGradientLine(hdc, cl, cr, zl, zr, ul, ur, vl, vr, xl, xr, y, texture);
			UPDATE_VAR(1.f);
		}
	}
	else {
		for (int y = iy3; y <= iy1; ++y) {
			float left = xl, right = xr;
			Color tcl = cl;
			float tzl = zl, tul = ul, tvl = vl;
			if(right >= xmin && left <= xmax) {
				if (left < xmin) {
					SHIFT_RIGHT_SCALE((xmin - left) / (right - left));
					left = xmin;
				}
				right = Min(right, xmax);
				PlotGradientLine(hdc, tcl, cr, tzl, zr, tul, ur, tvl, vr, left, right, y, texture);
			}

			UPDATE_VAR(1.f);
		}
	}
}