Beispiel #1
0
Datei: eval.c Projekt: gvlx/gawk
int
cmp_nodes(NODE *t1, NODE *t2)
{
    int ret = 0;
    size_t len1, len2;
    int l, ldiff;

    if (t1 == t2)
        return 0;

    if (t1->flags & MAYBE_NUM)
        (void) force_number(t1);
    if (t2->flags & MAYBE_NUM)
        (void) force_number(t2);
    if (t1->flags & INTIND)
        t1 = force_string(t1);
    if (t2->flags & INTIND)
        t2 = force_string(t2);

    if ((t1->flags & NUMBER) && (t2->flags & NUMBER))
        return cmp_numbers(t1, t2);

    (void) force_string(t1);
    (void) force_string(t2);
    len1 = t1->stlen;
    len2 = t2->stlen;
    ldiff = len1 - len2;
    if (len1 == 0 || len2 == 0)
        return ldiff;

    if (do_posix)
        return posix_compare(t1, t2);

    l = (ldiff <= 0 ? len1 : len2);
    if (IGNORECASE) {
        const unsigned char *cp1 = (const unsigned char *) t1->stptr;
        const unsigned char *cp2 = (const unsigned char *) t2->stptr;

#if MBS_SUPPORT
        if (gawk_mb_cur_max > 1) {
            ret = strncasecmpmbs((const unsigned char *) cp1,
                                 (const unsigned char *) cp2, l);
        } else
#endif
            /* Could use tolower() here; see discussion above. */
            for (ret = 0; l-- > 0 && ret == 0; cp1++, cp2++)
                ret = casetable[*cp1] - casetable[*cp2];
    } else
        ret = memcmp(t1->stptr, t2->stptr, l);

    ret = ret == 0 ? ldiff : ret;
    return ret;
}
Beispiel #2
0
static NODE *
do_waitpid(int nargs)
{
	NODE *pidnode;
	int ret = -1;
	double pidval;
	pid_t pid;
	int options = 0;

	if  (do_lint && get_curfunc_arg_count() > 1)
		lintwarn("waitpid: called with too many arguments");

	pidnode = get_scalar_argument(0, FALSE);
	if (pidnode != NULL) {
		pidval = force_number(pidnode);
		pid = (int) pidval;
		options = WNOHANG|WUNTRACED;
		ret = waitpid(pid, NULL, options);
		if (ret < 0)
			update_ERRNO();
	} else if (do_lint)
		lintwarn("wait: called with no arguments");

	/* Set the return value */
	return make_number((AWKNUM) ret);
}
Beispiel #3
0
NODE *
do_Color(int nargs)
{
	NODE *tmp;
	GLdouble red, green, blue;

	tmp    = (NODE*) get_actual_argument(0, FALSE, FALSE);
	red    = (GLdouble) (force_number(tmp) / 255);
	tmp    = (NODE*) get_actual_argument(1, FALSE, FALSE);
	green  = (GLdouble) (force_number(tmp) / 255);
	tmp    = (NODE*) get_actual_argument(2, FALSE, FALSE);
	blue   = (GLdouble) (force_number(tmp) / 255);

	glColor3d(red, green, blue);
	return make_number((AWKNUM) 0);
}
Beispiel #4
0
// 材質
NODE *
do_Material(int nargs)
{
	NODE *tmp;
	GLenum face;
	GLenum pname;
	float params[8];
	int param_num;
	int i;

	tmp = (NODE*) get_actual_argument(0, FALSE, FALSE);
	force_string(tmp);
	face = material_face(tmp->stptr);

	tmp = (NODE*) get_actual_argument(1, FALSE, FALSE);
	force_string(tmp);
	pname = material_pname(tmp->stptr);

	switch (pname) {
		case GL_SHININESS:
			param_num = 1;
			break;
		case GL_COLOR_INDEXES:
			param_num = 3;
			break;
		case GL_AMBIENT_AND_DIFFUSE:
			param_num = 8;
			break;
		default:
			param_num = 4;
			break;
	}

	for (i = 0; i < param_num; i++) {
		tmp = (NODE*) get_actual_argument(i + 2, FALSE, FALSE);
		params[i] = (GLfloat) force_number(tmp);
	}

	// OpenGLで質感を設定するときは、通常glMaterialfv()を使います。
	// いままで使ってきた、glColor3fv()と同様に、図形を描く前に質感を設定するという手順をとります。
	// OpenGLのポリゴンには、表と裏という概念があって、faceはそのどちらの面の質感を設定するかを指定する。
	// GL_FRONT(表)、GL_BACK(裏)、GL_FRONT_AND_BACK(両方)のうちのいずれか。
	// 今回は、ひとまずGL_FRONT_AND_BACKを指定しておいた。
	// ポリゴンの表裏に関しては、他の機会に説明する。
	// pnameは、質感のどのパラメタを設定するかを指定する。
	// GL_AMBIENT、GL_DIFFUSE、GL_SPECULAR、GL_EMISSION、GL_SHININESSなどがあり、このうちの1つを選んで設定する。
	// それぞれ、質感についてで解説した通り。
	// paramsには、実際に設定する値の入った配列を渡す。
	// GL_AMBIENT、GL_DIFFUSE、GL_SPECULAR、GL_EMISSIONの場合は、RGBA形式である。
	// それぞれ、─1から1の範囲の値を入れる。
	// GL_SHININESSの場合は、渡す値は1つで、0から128の範囲の値である。
	// GL_SHINESSを設定するだけなら、glMaterialf()を使うこともできる。
	//
	//void glMaterialfv(GLenum face, GLenum pname, const GLfloat *params)

	glMaterialfv(face, pname, params);
	return make_number((AWKNUM) 0);
}
Beispiel #5
0
// 光源
NODE *
do_Light(int nargs)
{
	NODE *tmp;
	GLenum light;
	GLenum pname;
	float params[4];
	int param_num;
	int i;

	//tmp = (NODE*) get_actual_argument(0, FALSE, FALSE);
	//force_string(tmp);
	//light = light_light_s(tmp->stptr);

	tmp = (NODE*) get_actual_argument(0, FALSE, FALSE);
	light = light_light_n((int) force_number(tmp));

	tmp = (NODE*) get_actual_argument(1, FALSE, FALSE);
	force_string(tmp);
	pname = light_pname(tmp->stptr);

	switch (pname) {
		case GL_AMBIENT:
		case GL_DIFFUSE:
		case GL_SPECULAR:
		case GL_POSITION:
			param_num = 4;
			break;
		case GL_SPOT_DIRECTION:
			param_num = 3;
			break;
		default:
			param_num = 1;
			break;
	}

	for (i = 0; i < param_num; i++) {
		tmp = (NODE*) get_actual_argument(i + 2, FALSE, FALSE);
		params[i] = (GLfloat) force_number(tmp);
	}

	// void glLightfv( GLenum light , GLenum pname , const GLfloat *params );
	glLightfv(light, pname , params);
	return make_number((AWKNUM) 0);
}
Beispiel #6
0
// 法線ベクトル
NODE *
do_Normal(int nargs)
{
	NODE *tmp;
	GLdouble nx;
	GLdouble ny;
	GLdouble nz;

	tmp = (NODE*) get_actual_argument(0, FALSE, FALSE);
	nx  = (GLdouble) force_number(tmp);
	tmp = (NODE*) get_actual_argument(1, FALSE, FALSE);
	ny  = (GLdouble) force_number(tmp);
	tmp = (NODE*) get_actual_argument(2, FALSE, FALSE);
	nz  = (GLdouble) force_number(tmp);

	glNormal3d(nx, ny, nz);
	return make_number((AWKNUM) 0);
}
Beispiel #7
0
NODE *
do_ClearColor(int nargs)
{
	NODE *tmp;
	GLclampf red, green, blue;

	tmp   = (NODE*) get_actual_argument(0, FALSE, FALSE);
	red   = (GLclampf) (force_number(tmp) / 255);

	tmp   = (NODE*) get_actual_argument(1, FALSE, FALSE);
	green = (GLclampf) (force_number(tmp) / 255);

	tmp   = (NODE*) get_actual_argument(2, FALSE, FALSE);
	blue  = (GLclampf) (force_number(tmp) / 255);

	//printf("Red = %d;   Green = %d;   Blue = %d;\n",
	//	(int)(red * 255), (int)(green * 255), (int)(blue * 255));

	glClearColor(red, green, blue, 1.0);
	return make_number((AWKNUM) 0);
}
Beispiel #8
0
static NODE *
do_alarm(int nargs)
{
	NODE *tmp;
	unsigned int second;

	if (do_lint && get_curfunc_arg_count() > 1)
		lintwarn("alarm: called with too many arguments");

	tmp = (NODE *) get_scalar_argument(0, FALSE);
	second = (unsigned int) force_number(tmp);

	return make_number((AWKNUM) alarm(second));
}
Beispiel #9
0
static NODE *
kill_killpg(int (*func)(int, int))
{
	NODE *tmp;
	pid_t pid_prg;
	int sig;

	tmp = (NODE *) get_scalar_argument(0, FALSE);
	pid_prg = (pid_t) force_number(tmp);

	tmp = (NODE *) get_scalar_argument(1, FALSE);
	sig = get_signo(tmp);

	return make_number((AWKNUM) func(pid_prg, sig));
}
Beispiel #10
0
static NODE *
do_usleep(int nags)
{
	NODE *tmp;
	struct timeval timeout;

	if (do_lint && get_curfunc_arg_count() > 1)
		lintwarn("usleep: called with too many arguments");

	timeout.tv_sec = 0;

	tmp = (NODE *) get_actual_argument(0, FALSE, FALSE);
	timeout.tv_usec = (suseconds_t) force_number(tmp);

	select(0, NULL, NULL, NULL, &timeout);
	return make_number((AWKNUM) 0);
}
Beispiel #11
0
static int
get_signo(NODE *tmp)
{
	int sig;

	force_string(tmp);
	sig = str2sig(tmp->stptr);

	if (sig == 0) {
		sig = num2sig((int) force_number(tmp));
	}

	if (sig == 0) {
		force_string(tmp);
		fatal(_("Signal `%s' is not defined"), tmp->stptr);
	}

	return sig;
}
Beispiel #12
0
static NODE *
do_sleep(int nags)
{
	NODE *tmp;
	struct timeval timeout;
	double integer,  point;

	if (do_lint && get_curfunc_arg_count() > 1)
		lintwarn("sleep: called with too many arguments");

	tmp = (NODE *) get_actual_argument(0, FALSE, FALSE);

	point = modf(force_number(tmp), &integer);

	timeout.tv_sec = (time_t) integer;
	timeout.tv_usec = (suseconds_t) (point * 1000000);

	select(0, NULL, NULL, NULL, &timeout);
	return make_number((AWKNUM) 0);
}
Beispiel #13
0
static NODE *
do_select(int nags)
{
	NODE *tmp, *array, *elm, *value;
	int nfds;
	fd_set rfds, wfds, efds;
	struct timeval timeout;
	struct timeval *timeout_ptr;
	int retval;
	struct redirect *rp;
	double integer, point;
	int i, j;
	int fp;

	if (do_lint && get_curfunc_arg_count() > 4)
		lintwarn("select: called with too many arguments");


	/*** Analyse File-descriptors ***/

	nfds = -1;
	FD_ZERO(&rfds);
	FD_ZERO(&wfds);
	FD_ZERO(&efds);

	for (i = 0; i < 3; i++ ) {
		array = (NODE *) get_array_argument(i, FALSE);
		if ( array == NULL ) { continue; }

		for (j = 0; j < array->array_size; j++) {

			for (elm = array->var_array[j]; elm != NULL; elm = elm->ahnext) {
				value = elm->hvalue;
				force_string(value);

				rp = getredirect(value->stptr, value->stlen);
				if (rp == NULL) {
					if (do_lint) {
						lintwarn("select: `%.*s' is not an open file, pipe or co-process",
								(int) value->stlen, value->stptr);
					}
				}

				fp = fileno(rp->fp);

				switch (i) {
				case 0:
					FD_SET(fp, &rfds);
					break;
				case 1:
					FD_SET(fp, &wfds);
					break;
				case 2:
					FD_SET(fp, &efds);
					break;
				}
				if (fp + 1 > nfds ) { nfds = fp + 1; }
			}
		}
	}


	/*** Analyse Timeout ***/
	/* timeout specified as milli-seconds */

	tmp = (NODE *) get_actual_argument(3, FALSE, FALSE);
	point = modf(force_number(tmp), &integer);
	if (integer < 0) {
		timeout_ptr = NULL;
	} else {
		timeout.tv_sec = (time_t) (integer / 1000);
		timeout.tv_usec = (suseconds_t) (point * 1000);
		timeout_ptr = &timeout;
	}


	retval = select(nfds, &rfds, &wfds, &efds, timeout_ptr);

	if (retval == -1) {
		perror("select()");
	} else if (retval != 0) {
		/* TODO */
	}

	return make_number((AWKNUM) retval);

}
Beispiel #14
0
static NODE *
can_sub(int mode)
{
	NODE *tmp;
	int nfds;
	fd_set fds;
	struct timeval timeout;
	struct timeval *timeout_ptr;
	int retval;
	struct redirect *rp;
	double integer, point;


	/*** Analyse File-descriptor ***/

	tmp = (NODE *) get_actual_argument(0, FALSE, FALSE);
	force_string(tmp);

	rp = getredirect(tmp->stptr, tmp->stlen);

	if (rp == NULL) {	/* no match, return -1 */
		if (do_lint) {
			const char *fn;

			switch (mode) {
			case CAN_READ:
				fn = "can_read";
				break;
			case CAN_WRITE:
				fn = "can_write";
				break;
			case HAS_EXCEPTION:
				fn = "has_excepstion";
				break;
			}
			lintwarn("%s: `%.*s' is not an open file, pipe or co-process",
				fn, (int) tmp->stlen, tmp->stptr);
		}
		return make_number((AWKNUM) 0);
	}

	nfds = fileno(rp->fp) + 1;

	FD_ZERO(&fds);
	FD_SET(fileno(rp->fp), &fds);


	/*** Analyse Timeout ***/
	/* timeout specified as milli-seconds */

	tmp = (NODE *) get_actual_argument(1, FALSE, FALSE);
	point = modf(force_number(tmp), &integer);
	if (integer < 0) {
		timeout_ptr = NULL;
	} else {
		timeout.tv_sec = (time_t) (integer / 1000);
		timeout.tv_usec = (suseconds_t) (point * 1000);
		timeout_ptr = &timeout;
	}


	switch (mode) {
	case CAN_READ:
		retval = select(nfds, &fds, NULL, NULL, timeout_ptr);
		break;
	case CAN_WRITE:
		retval = select(nfds, NULL, &fds, NULL, timeout_ptr);
		break;
	case HAS_EXCEPTION:
		retval = select(nfds, NULL, NULL, &fds, timeout_ptr);
		break;
	}

	if (retval == -1)
		perror("select()");

	return make_number((AWKNUM) retval);
}