Ejemplo n.º 1
0
int
shader_set_param_mat(const struct ShaderParam *p, size_t count, Mat *m)
{
	assert(p != NULL);
	assert(m != NULL);

#ifdef DEBUG
	if (p->type != GL_FLOAT_MAT4) {
		errf("shader param %s is not of matrix type", p->name);
		return 0;
	} else if (count > p->size) {
		errf("shader param %s value size too big", p->name);
		return 0;
	}
#endif

	glUniformMatrix4fv(p->loc, count, GL_TRUE, (float*)m);

	HANDLE_GL_ERROR(p->name);
}
Ejemplo n.º 2
0
int
shader_set_param_int(const struct ShaderParam *p, size_t count, int *i)
{
	assert(p != NULL);
	assert(i != NULL);

#ifdef DEBUG
	if (p->type != GL_INT && p->type != GL_SAMPLER_2D) {
		errf("shader param %s is not of integer type", p->name);
		return 0;
	} else if (count > p->size) {
		errf("shader param %s value size too big", p->name);
		return 0;
	}
#endif

	glUniform1iv(p->loc, count, i);

	HANDLE_GL_ERROR(p->name);
}
Ejemplo n.º 3
0
static void
add_charmap_impl(const char *sym, wchar_t wc, int nodups)
{
	charmap_t	srch;
	charmap_t	*n = NULL;
	avl_index_t	where;

	srch.wc = wc;
	srch.name = sym;

	/*
	 * also possibly insert the wide mapping, although note that there
	 * can only be one of these per wide character code.
	 */
	if ((wc != (wchar_t)-1) &&
	    ((avl_find(&cmap_wc, &srch, &where)) == NULL)) {
		if ((n = calloc(1, sizeof (*n))) == NULL) {
			errf(_("out of memory"));
			return;
		}
		n->wc = wc;
		avl_insert(&cmap_wc, n, where);
	}

	if (sym) {
		if (avl_find(&cmap_sym, &srch, &where) != NULL) {
			if (nodups) {
				errf(_("duplicate character definition"));
			}
			return;
		}
		if ((n == NULL) && ((n = calloc(1, sizeof (*n))) == NULL)) {
			errf(_("out of memory"));
			return;
		}
		n->wc = wc;
		n->name = sym;

		avl_insert(&cmap_sym, n, where);
	}
}
Ejemplo n.º 4
0
int
wr_category(void *buf, size_t sz, FILE *f)
{
	if (!sz) {
		return (0);
	}
	if (fwrite(buf, sz, 1, f) < 1) {
		errf(strerror(errno));
		return (EOF);
	}
	return (0);
}
Ejemplo n.º 5
0
int
to_mb(char *mb, wchar_t wc)
{
	int	rv;

	if ((rv = _tomb(mb, wc)) < 0) {
		errf(widemsg);
		free(widemsg);
		widemsg = NULL;
	}
	return (rv);
}
Ejemplo n.º 6
0
static void
add_list(const char *ptr[], char *str, int limit)
{
	int	i;
	for (i = 0; i < limit; i++) {
		if (ptr[i] == NULL) {
			ptr[i] = str;
			return;
		}
	}
	errf(_("too many list elements"));
}
Ejemplo n.º 7
0
void
define_collelem(char *name, wchar_t *wcs)
{
	collelem_t	*e;
	avl_index_t	where1;
	avl_index_t	where2;
	int		i;

	if (wcslen(wcs) >= COLLATE_STR_LEN) {
		errf(_("expanded collation element too long"));
		return;
	}

	if ((e = calloc(sizeof (*e), 1)) == NULL) {
		errf(_("out of memory"));
		return;
	}
	e->expand = wcs;
	e->symbol = name;

	/*
	 * This is executed before the order statement, so we don't
	 * know how many priorities we *really* need.  We allocate one
	 * for each possible weight.  Not a big deal, as collating-elements
	 * prove to be quite rare.
	 */
	for (i = 0; i < COLL_WEIGHTS_MAX; i++) {
		e->ref[i] = new_pri();
	}

	/* A character sequence can only reduce to one element. */
	if ((avl_find(&elem_by_symbol, e, &where1) != NULL) ||
	    (avl_find(&elem_by_expand, e, &where2) != NULL)) {
		errf(_("duplicate collating element definition"));
		free(e);
		return;
	}
	avl_insert(&elem_by_symbol, e, where1);
	avl_insert(&elem_by_expand, e, where2);
}
Ejemplo n.º 8
0
void
close_category(FILE *f)
{
	if (fchmod(fileno(f), 0644) < 0 ||
	    fclose(f) != 0) {
		errf(strerror(errno));
		delete_category(f);
	}
	if (verbose) {
		(void) fprintf(stdout, _("done.\n"));
		(void) fflush(stdout);
	}
}
Ejemplo n.º 9
0
void
scan_to_eol(void)
{
	int	c;
	while ((c = scanc()) != '\n') {
		if (c == EOF) {
			/* end of file without newline! */
			errf("missing newline");
			return;
		}
	}
	assert(c == '\n');
}
Ejemplo n.º 10
0
oram_bucket* read_bucket_from_file(int bucket_id) {
    char filename[50];
    sprintf(filename, ORAM_FILE_BUCKET_FORMAT, bucket_id);
    oram_bucket *bucket = malloc(sizeof(oram_bucket));
    int fd = open(filename, O_RDONLY);
    if (fd < 0) {
        errf("Error Reading File to Mem");
        return NULL;
    }
    read(fd, bucket, sizeof(oram_bucket));
    close(fd);
    return bucket;
}
Ejemplo n.º 11
0
void
start_order_char(wchar_t wc)
{
	collchar_t	*cc;
	int32_t		ref;

	start_order(T_CHAR);

	/*
	 * If we last saw an ellipsis, then we need to close the range.
	 * Handle that here.  Note that we have to be careful because the
	 * items *inside* the range are treated exclusiveley to the items
	 * outside of the range.  The ends of the range can have quite
	 * different weights than the range members.
	 */
	if (lastorder == T_ELLIPSIS) {
		int		i;

		if (wc < ellipsis_start) {
			errf(_("malformed range!"));
			return;
		}
		while (ellipsis_start < wc) {
			/*
			 * pick all of the saved weights for the
			 * ellipsis.  note that -1 encodes for the
			 * ellipsis itself, which means to take the
			 * current relative priority.
			 */
			if ((cc = get_collchar(ellipsis_start, 1)) == NULL) {
				INTERR;
				return;
			}
			for (i = 0; i < NUM_WT; i++) {
				collpri_t *p;
				if (((ref = ellipsis_weights[i]) == -1) ||
				    ((p = get_pri(ref)) == NULL) ||
				    (p->pri == -1)) {
					set_pri(cc->ref[i], nextpri, RESOLVED);
				} else {
					set_pri(cc->ref[i], ref, REFER);
				}
				ellipsis_weights[i] = 0;
			}
			ellipsis_start++;
			nextpri++;
		}
	}

	currchar = get_collchar(wc, 1);
}
Ejemplo n.º 12
0
void
add_charmap_range(char *s, char *e, int wc)
{
	int	ls, le;
	int	si;
	int	sn, en;
	int	i;

	static const char *digits = "0123456789";

	ls = strlen(s);
	le = strlen(e);

	if (((si = strcspn(s, digits)) == 0) || (si == ls) ||
	    (strncmp(s, e, si) != 0) ||
	    (strspn(s + si, digits) != (ls - si)) ||
	    (strspn(e + si, digits) != (le - si)) ||
	    ((sn = atoi(s + si)) > ((en = atoi(e + si))))) {
		errf(_("malformed charmap range"));
		return;
	}

	s[si] = 0;

	for (i = sn; i <= en; i++) {
		char *nn;
		(void) asprintf(&nn, "%s%0*u", s, ls - si, i);
		if (nn == NULL) {
			errf(_("out of memory"));
			return;
		}

		add_charmap_impl(nn, wc, 1);
		wc++;
	}
	free(s);
	free(e);
}
Ejemplo n.º 13
0
/*
 * This function is used when copying the category from another
 * locale.  Note that the copy is actually performed using a hard
 * link for efficiency.
 */
void
copy_category(char *src)
{
	char	srcpath[PATH_MAX];
	int	rv;

	(void) snprintf(srcpath, sizeof (srcpath), "%s/%s/LCL_DATA",
	    src, category_name());
	rv = access(srcpath, R_OK);
	if ((rv != 0) && (strchr(srcpath, '/') == NULL)) {
		/* Maybe we should try the system locale */
		(void) snprintf(srcpath, sizeof (srcpath),
		    "/usr/lib/locale/%s/%s/LCL_DATA", src, category_name());
		rv = access(srcpath, R_OK);
	}

	if (rv != 0) {
		errf(_("source locale data unavailable"), src);
		return;
	}

	if (verbose > 1) {
		(void) printf(_("Copying category %s from %s: "),
		    category_name(), src);
		(void) fflush(stdout);
	}

	/* make the parent directory */
	(void) mkdirp(dirname(category_file()), 0755);

	if (link(srcpath, category_file()) != 0) {
		errf(_("unable to copy locale data: %s"), strerror(errno));
		return;
	}
	if (verbose > 1) {
		(void) printf(_("done.\n"));
	}
}
Ejemplo n.º 14
0
int
wr_category(void *buf, size_t sz, FILE *f)
{
	if (!sz) {
		return (0);
	}
	if (fwrite(buf, sz, 1, f) < 1) {
		(void) fclose(f);
		(void) unlink(category_file());
		errf(strerror(errno));
		return (EOF);
	}
	return (0);
}
Ejemplo n.º 15
0
int gread (char *imgt, size_t bytes, int n, FILE *fp, int isbig) {
	int	i, swab_flag;

	swab_flag = (CPU_is_bigendian() != 0) != (isbig != 0);
	if (0) printf ("gread swab_flag=%d\n", swab_flag);

	if (fread (imgt, bytes, n, fp) != n) return -1;
	if (swab_flag) for (i = 0; i < n; i++) switch (bytes) {
		case 2: swab2 (imgt + 2*i); break;
		case 4: swab4 (imgt + 4*i); break;
		default: errf ("gread");
	}
	return 0;
}
Ejemplo n.º 16
0
    virtual int copy_file(const entry_t& source, const path_t& target) {
        entry_t& entry = target_entry_;
        const char_t* chars = 0;
        int err = 1;

        if ((entry.exists(chars = target.chars()))) {
            if ((write_overwrite != write_) && (write_append != write_)) {
                errf("target file \"%s\" already exists\n", chars);
            } else {
                fs::entry_type type = fs::entry_type_none;

                switch (type = entry.type()) {
                case fs::entry_type_file:
                    err = copy_file_to_file(source, entry);
                    break;
                default:
                    break;
                }
            }
        } else {
            if (!(err = make_directory(entry, target))) {
                entry.set_path(chars);
                err = copy_file_to_file(source, entry);
            } else {
                errf("failed to make directory \"%s\"\n", target.directory().chars());
            }
        }
        if (!(err) && (!(to_same != to_) || !(target_modified_))) {
            if ((entry.set_times_to_set(source))) {
                if ((entry.set_times_set())) {
                } else {
                }
            }
        }
        return err;
    }
Ejemplo n.º 17
0
INT benchmark_errf(FLOAT input[]){
    
    FLOAT var_xx=input[0],var_yy=input[1],var_wx=1,var_wy=1,wx=input[2],wy=input[3];
    
    // printf("%-6s %23.16e\n%-6s %23.16e\n","real", input[0], "imag", input[1]);
    // printf("%-6s %23.16e\n%-6s %23.16e\n","real", var_xx, "imag", var_yy);
    
    // wofz(&var_wx, &var_wy, var_xx, var_yy);
    errf(&var_xx, &var_yy, &var_wx, &var_wy);
    
    // printf("%-6s %23.16e\n%-6s %23.16e\n",
    //     "real", var_wx, "imag", var_wy);
    printf("%-6s %23.16e %23.16e %23.16e\n%-6s %23.16e %23.16e %23.16e\n\n",
        "real", sqrt(pow((wx-var_wx),2)), var_wx, wx, "imag", sqrt(pow((wy-var_wy),2)), var_wy, wy);
    return 1;
}
Ejemplo n.º 18
0
void
add_numeric_group(int n)
{
	char *s;

	if (numeric.grouping == NULL) {
		(void) asprintf(&s, "%d", n);
	} else {
		(void) asprintf(&s, "%s;%d", numeric.grouping, n);
	}
	if (s == NULL)
		errf(_("out of memory"));

	free((char *)numeric.grouping);
	numeric.grouping = s;
}
Ejemplo n.º 19
0
void
start_order_ellipsis(void)
{
	int	i;

	start_order(T_ELLIPSIS);

	if (lastorder != T_CHAR) {
		errf(_("illegal starting point for range"));
		return;
	}

	for (i = 0; i < NUM_WT; i++) {
		ellipsis_weights[i] = order_weights[i];
	}
}
Ejemplo n.º 20
0
static void
start_order(int type)
{
	int	i;

	lastorder = currorder;
	currorder = type;

	/* this is used to protect ELLIPSIS processing */
	if ((lastorder == T_ELLIPSIS) && (type != T_CHAR)) {
		errf(_("character value expected"));
	}

	for (i = 0; i < COLL_WEIGHTS_MAX; i++) {
		order_weights[i] = -1;
	}
	curr_weight = 0;
}
Ejemplo n.º 21
0
void
add_time_list(wchar_t *wcs)
{
	char *str;

	if ((str = to_mb_string(wcs)) == NULL) {
		INTERR;
		return;
	}
	free(wcs);

	switch (last_kw) {
	case T_ABMON:
		add_list(tm.mon, str, 12);
		break;
	case T_MON:
		add_list(tm.month, str, 12);
		break;
	case T_ABDAY:
		add_list(tm.wday, str, 7);
		break;
	case T_DAY:
		add_list(tm.weekday, str, 7);
		break;
	case T_AM_PM:
		if (tm.am == NULL) {
			tm.am = str;
		} else if (tm.pm == NULL) {
			tm.pm = str;
		} else {
			errf(_("too many list elements"));
		}
		break;
	case T_ALT_DIGITS:
	case T_ERA:
		free(str);
		break;
	default:
		free(str);
		INTERR;
		break;
	}
}
Ejemplo n.º 22
0
static ctype_node_t *
get_ctype(wchar_t wc)
{
	ctype_node_t	srch;
	ctype_node_t	*ctn;
	avl_index_t	where;

	srch.wc = wc;
	if ((ctn = avl_find(&ctypes, &srch, &where)) == NULL) {
		if ((ctn = calloc(1, sizeof (*ctn))) == NULL) {
			errf(_("out of memory"));
			return (NULL);
		}
		ctn->wc = wc;

		avl_insert(&ctypes, ctn, where);
	}
	return (ctn);
}
Ejemplo n.º 23
0
static int32_t
new_pri(void)
{
	int i;

	if (numpri >= maxpri) {
		maxpri = maxpri ? maxpri * 2 : 1024;
		prilist = realloc(prilist, sizeof (collpri_t) * maxpri);
		if (prilist == NULL) {
			errf(_("out of memory"));
			return (-1);
		}
		for (i = numpri; i < maxpri; i++) {
			prilist[i].res = UNKNOWN;
			prilist[i].pri = 0;
			prilist[i].pass = 0;
		}
	}
	return (numpri++);
}
Ejemplo n.º 24
0
int
shader_use(struct Shader *s)
{
	assert(s != NULL);

	glUseProgram(s->prog);

#ifdef DEBUG
	GLenum gl_err;
	if ((gl_err = glGetError()) != GL_NO_ERROR) {
		errf(
			"failed to make shader %d active (OpenGL error %d)",
			s->prog,
			gl_err
		);
		return 0;
	}
#endif

	return 1;
}
Ejemplo n.º 25
0
    virtual int copy(const path_t& source, const path_t& target) {
        entry_t& entry = source_entry_;
        const char_t* chars = 0;
        int err = 0;

        if ((entry.exists(chars = source.chars()))) {
            fs::entry_type type = fs::entry_type_none;

            switch (type = entry.type()) {
            case fs::entry_type_file:
                err = copy_file(entry, target);
                break;
            default:
                break;
            }
        } else {
            errf("source file \"%s\" does not exist\n", chars);
            err = 1;
        }
        return err;
    }
Ejemplo n.º 26
0
void
add_ctype_range(int end)
{
	ctype_node_t	*ctn;
	wchar_t		cur;

	if (end < last_ctype) {
		errf(_("malformed character range (%u ... %u))"),
		    last_ctype, end);
		return;
	}
	for (cur = last_ctype + 1; cur <= end; cur++) {
		if ((ctn = get_ctype(cur)) == NULL) {
			INTERR;
			return;
		}
		add_ctype_impl(ctn);
	}
	last_ctype = end;

}
Ejemplo n.º 27
0
jint Java_org_shadowvpn_shadowvpn_ShadowVPN_nativeInitVPN(JNIEnv* env, jobject thiz,
                                                jint tun_fd, jstring password,
                                                jstring server, jint port,
                                                jint mtu, jint concurrency) {
  bzero(&args, sizeof(args));
  if (!initialized) {
    crypto_init();
    initialized = 1;
  }
  const char *c_password = (*env)->GetStringUTFChars(env, password, NULL);
  if (0 != crypto_set_password(c_password, strlen(c_password))) {
    return -1;
  }
  args.password = c_password;
  args.server = (*env)->GetStringUTFChars(env, server, NULL);
  args.port = port;
  args.mtu = mtu;
  args.concurrency = concurrency;
  args.mode = SHADOWVPN_MODE_CLIENT;
  vpn_ctx_t *ctx = &vpn_ctx;
  bzero(ctx, sizeof(vpn_ctx_t));
  ctx->remote_addrp = (struct sockaddr *)&ctx->remote_addr;
  if (-1 == pipe(ctx->control_pipe)) {
    err("pipe");
    return -1;
  }
  ctx->tun = tun_fd;
  ctx->socks = &sock;
  ctx->nsock = 1;
  if (-1 == (sock = vpn_udp_alloc(args.mode == SHADOWVPN_MODE_SERVER,
                                  args.server, args.port,
                                  ctx->remote_addrp,
                                  &ctx->remote_addrlen))) {
    errf("failed to create UDP socket");
    close(ctx->tun);
    return -1;
  }
  ctx->args = &args;
  return 0;
}
Ejemplo n.º 28
0
static collchar_t *
get_collchar(wchar_t wc, int create)
{
	collchar_t	srch;
	collchar_t	*cc;
	avl_index_t	where;
	int		i;

	srch.wc = wc;
	cc = avl_find(&collchars, &srch, &where);
	if ((cc == NULL) && create) {
		if ((cc = calloc(sizeof (*cc), 1)) == NULL) {
			errf(_("out of memory"));
			return (NULL);
		}
		for (i = 0; i < NUM_WT; i++) {
			cc->ref[i] = new_pri();
		}
		cc->wc = wc;
		avl_insert(&collchars, cc, where);
	}
	return (cc);
}
Ejemplo n.º 29
0
/*-----------------------------------------------------------------------------------*/
void
tcp_abort(struct tcp_pcb *pcb)
{
  u32_t seqno, ackno;
  u16_t remote_port, local_port;
  struct ip_addr remote_ip, local_ip;
  void (* errf)(void *arg, err_t err);
  void *errf_arg;

  
  /* Figure out on which TCP PCB list we are, and remove us. If we
     are in an active state, call the receive function associated with
     the PCB with a NULL argument, and send an RST to the remote end. */
  if(pcb->state == TIME_WAIT) {
    tcp_pcb_remove(TCP_LIST_TW, pcb);
    memp_free(MEMP_TCP_PCB, pcb);
  } else if(pcb->state == LISTEN) {
    tcp_pcb_remove(TCP_LIST_LISTEN, pcb);
    memp_free(MEMP_TCP_PCB_LISTEN, pcb);
  } else {
    seqno = pcb->snd_nxt;
    ackno = pcb->rcv_nxt;
    ip_addr_set(&local_ip, &(pcb->local_ip));
    ip_addr_set(&remote_ip, &(pcb->remote_ip));
    local_port = pcb->local_port;
    remote_port = pcb->remote_port;
    errf = pcb->errf;
    errf_arg = pcb->callback_arg;
    tcp_pcb_remove(TCP_LIST_ACTIVE, pcb);
    memp_free(MEMP_TCP_PCB, pcb);
    if(errf != NULL) {
      errf(errf_arg, ERR_ABRT);
    }
    DEBUGF(TCP_RST_DEBUG, ("tcp_abort: sending RST\n"));
    tcp_rst(seqno, ackno, &local_ip, &remote_ip, local_port, remote_port);
  }
}
Ejemplo n.º 30
0
FILE *
open_category(void)
{
	FILE *file;

	if (verbose) {
		(void) printf(_("Writing category %s: "), category_name());
		(void) fflush(stdout);
	}

	/* make the parent directory */
	(void) mkdirp(dirname(category_file()), 0755);

	/*
	 * note that we have to regenerate the file name, as dirname
	 * clobbered it.
	 */
	file = fopen(category_file(), "w");
	if (file == NULL) {
		errf(strerror(errno));
		return (NULL);
	}
	return (file);
}