示例#1
0
文件: strpbrk.c 项目: Henauxg/minix
char *
strpbrk(const char *s, const char *charset)
{
#ifdef FAST_STRPBRK
	uint8_t set[256], inv[256], idx = 0;
#else
	static const size_t idx[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
	uint8_t set[32];

	(void)memset(set, 0, sizeof(set));
#endif

	_DIAGASSERT(s != NULL);
	_DIAGASSERT(charset != NULL);

	if (charset[0] == '\0')
		return NULL;
	if (charset[1] == '\0')
		return strchr(s, charset[0]);

	for (; *charset != '\0'; ++charset)
		ADD_TO_SET(UC(*charset));

	for (; *s != '\0'; ++s)
		if (IS_IN_SET(UC(*s)))
			return __UNCONST(s);
	return NULL;
}
示例#2
0
static void main1(TInput *v) {
    Tform *t;
    UC(tform_ini(&t));
    UC(input2form(v, /**/ &t));
    UC(process(t));
    tform_fin(t);
}
SgObject Sg_MakePseudoRandom(SgString *name, SgObject seed)
{
  const char *cname = Sg_Utf32sToUtf8s(name);
  int wprng = find_prng(cname), err;
  SgBuiltinPrng *prng;
  
  if (wprng == -1) {
    Sg_Error(UC("%A is not supported"), name);
    return SG_UNDEF;
  }

  prng = make_prng(name);
  SG_BUILTIN_PRNG(prng)->wprng = wprng;
  err = prng_descriptor[wprng].start(&prng->prng);
  if (err != CRYPT_OK) goto err;

  if (!SG_FALSEP(seed)) {
    if (SG_BVECTORP(seed)) {
      err = prng_descriptor[wprng]
	.add_entropy(SG_BVECTOR_ELEMENTS(seed), 
		     SG_BVECTOR_SIZE(seed), &prng->prng);
      if (err != CRYPT_OK) goto err;
    } else { goto err; }
  }

  err = prng_descriptor[wprng].ready(&prng->prng);
  if (err != CRYPT_OK) goto err;

  Sg_RegisterFinalizer(prng, finalize_prng, NULL);
  return SG_OBJ(prng);
 err:
  Sg_Error(UC("Failed to initialize pseudo random: %A"),
	   Sg_MakeStringC(error_to_string(err)));
  return SG_UNDEF;
}
示例#4
0
void main0(int n) {
    int i;
    RNDunif *r;
    UC(rnd_ini(42, 42, 42, 42, /**/ &r));
    for (i = 0; i < n; i++)
        printf("%10.6e\n", rnd_get(r));
    UC(rnd_fin(r));
}
示例#5
0
static void comparator_print(SgObject o, SgPort *port, SgWriteContext *ctx)
{
  SgComparator *c = SG_COMPARATOR(o);
  if (SG_FALSEP(c->name)) {
    Sg_Printf(port, UC("#<comparator %p>"), c);
  } else {
    Sg_Printf(port, UC("#<comparator %S>"), c->name);
  }
}
示例#6
0
文件: inetLib.c 项目: phoboz/vmx
void inet_ntoa_b(struct in_addr addr, char *str)
{
    char *p;

    /* Setup locals */
    p = (char *) &addr;

    sprintf(str, "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3]));
}
示例#7
0
char *inet_ntoa_r(struct in_addr in, char *buf, int bufsize)
{
	register char *p;

	p = (char *)&in;
#define	UC(b)	(((int)b)&0xff)
	(void)snprintf(buf, bufsize,
				   "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3]));
	return (buf);
}
char * _inet_ntoa(struct in_addr in)
{
	static char b[18];
	register char *p;

	p = (char *)&in;
#define	UC(b)	(((int)b)&0xff)
	(void)snprintf(b, sizeof(b),
	    "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3]));
	return (b);
}
示例#9
0
/*
 * Convert an Internet host address given in network byte order
 * to string in standard numbers and dots notation.
 */
PJ_DEF(char*) pj_inet_ntoa(pj_in_addr in)
{
#define	UC(b)	(((int)b)&0xff)
    static char b[18];
    char *p;

    p = (char *)&in;
    pj_snprintf(b, sizeof(b), "%d.%d.%d.%d", 
	       UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3]));

    return b;
}
示例#10
0
int main(int argc, char **argv) {
    Sim *sim;
    Config *cfg;
    int rank, size, dims[3];
    MPI_Comm cart;
    int restart;

    m::ini(&argc, &argv);

    m::get_dims(&argc, &argv, dims);
    m::get_cart(MPI_COMM_WORLD, dims, &cart);

    MC(m::Comm_rank(cart, &rank));
    MC(m::Comm_size(cart, &size));
    msg_ini(rank);
    msg_print("mpi rank/size: %d/%d", rank, size);
    UC(conf_ini(&cfg));
    UC(conf_read(argc, argv, cfg));

    UC(sim_ini(cfg, cart, &sim));
    UC(conf_lookup_bool(cfg, "glb.restart", &restart));
    msg_print("read restart: %s", restart ? "YES" : "NO" );
    if (restart) UC(sim_strt(sim));
    else         UC(sim_gen(sim));
    UC(sim_fin(sim));

    UC(conf_fin(cfg));

    MC(m::Barrier(cart));
    m::fin();
    msg_print("end");
}
示例#11
0
static void chain(TInput *v, Tform **pt) {
    Tform *t, *t1, *t2;
    t = *pt;

    UC(tform_ini(&t1));
    UC(tform_ini(&t2));
    UC(tform_vector(v->u.a0, v->u.a1,
                    v->u.b0, v->u.b1, /**/ t1));
    UC(tform_chain(t, t1, /**/ t2));
    tform_fin(t1);
    tform_fin(t);
    tform_log(t2);

    *pt = t2;
}
示例#12
0
文件: imp.cpp 项目: uDeviceX/uDeviceX
void io_com_dump(MPI_Comm comm, const Coords *coords, const char *name, long id, int n, const int *ii, const float3 *rr) {
    char fname[FILENAME_MAX] = {0}, *data;
    long nchar = 0;
    
    EMALLOC(MAX_CHAR_PER_LINE * n, &data);

    if (m::is_master(comm))
        UC(os_mkdir(BASE));

    gen_fname(name, id, fname);
    
    UC(nchar = swrite(coords, n, ii, rr, /**/ data));
    write_mpi(comm, fname, nchar, data);
    
    EFREE(data);
}
示例#13
0
void Sg__InitIdentifier()
{
  /* For future we might want to make identifier <object> to use slot-ref
     but for now.*/
  SgLibrary *clib = Sg_FindLibrary(SG_INTERN("(sagittarius clos)"), TRUE);
  Sg_InitStaticClass(SG_CLASS_IDENTIFIER, UC("<identifier>"), clib, NULL, 0);
}
示例#14
0
size_t
strcspn(const char *s, const char *charset)
{
	static const uint8_t idx[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
	const char *t;
	uint8_t set[32];
#define UC(a) ((unsigned int)(unsigned char)(a))

	if (charset[0] == '\0')
		return strlen(s);
	if (charset[1] == '\0') {
		for (t = s; *t != '\0'; ++t)
			if (*t == *charset)
				break;
		return t - s;
	}

	(void)memset(set, 0, sizeof(set));

	for (; *charset != '\0'; ++charset)
		set[UC(*charset) >> 3] |= idx[UC(*charset) & 7];

	for (t = s; *t != '\0'; ++t)
		if (set[UC(*t) >> 3] & idx[UC(*t) & 7])
			break;
	return t - s;
}
示例#15
0
int main(int argc, char **argv) {
    int dims[3];
    m::ini(&argc, &argv);
    m::get_dims(&argc, &argv, dims); /* eat arguments */
    UC(main1(argc, argv));
    m::fin();
}
示例#16
0
static void termios_print(SgObject o, SgPort *p, SgWriteContext *ctx)
{
  Sg_Printf(p, UC("#<termios iflag:%x, oflag:%x, cflag:%x, lflag:%x>"),
	    SG_TERMIOS_TERMIOS(o)->c_iflag,
	    SG_TERMIOS_TERMIOS(o)->c_oflag,
	    SG_TERMIOS_TERMIOS(o)->c_cflag,
	    SG_TERMIOS_TERMIOS(o)->c_lflag);
}
示例#17
0
SgObject Sg_MakeFileFromFD(uintptr_t handle)
{
  SgFile *f = SG_NEW(SgFile);
  init_file(f, (int)handle);
  f->name = UC("fd");
  SG_FILE_VTABLE(f) = &vtable;
  return SG_OBJ(f);
}
示例#18
0
SgObject Sg_StandardError()
{
  if (!stdError) {
    stdError = Sg_MakeFileFromFD(2);
    stdError->name = UC("stderr");
  }
  return SG_OBJ(stdError);
}
示例#19
0
SgObject Sg_StandardIn()
{
  if (!stdIn) {
    stdIn = Sg_MakeFileFromFD(0);
    stdIn->name = UC("stdin");
  }
  return SG_OBJ(stdIn);
}
示例#20
0
SgObject Sg_StandardOut()
{
  if (!stdOut) {
    stdOut = Sg_MakeFileFromFD(1);
    stdOut->name = UC("stdout");
  }
  return SG_OBJ(stdOut);
}
SG_EXTENSION_ENTRY void CDECL Sg_Init_sagittarius__zlib()
{
  SgLibrary *lib;
  SG_INIT_EXTENSION(sagittarius__zlib);

  lib = SG_LIBRARY(Sg_FindLibrary(SG_SYMBOL(SG_INTERN("(rfc zlib)")),
				  FALSE));
  Sg__Init_zlib_stub(lib);

#define insert_binding_rec(n, v)					\
  Sg_MakeBinding(lib, SG_SYMBOL(SG_INTERN(#n)), SG_MAKE_INT(v), TRUE)
#define insert_binding(v)						\
Sg_MakeBinding(lib, SG_SYMBOL(SG_INTERN(#v)), SG_MAKE_INT(v), TRUE)

insert_binding(Z_NO_FLUSH     );
insert_binding(Z_PARTIAL_FLUSH);
insert_binding(Z_SYNC_FLUSH   );
insert_binding(Z_FULL_FLUSH   );
insert_binding(Z_FINISH       );
insert_binding(Z_BLOCK        );
/* as far as I know this is after 1.2.3
   and some platform (say OpenBSD) is using 1.2.3
   so check it.*/
#ifdef Z_TREES
 insert_binding(Z_TREES        );
#else
 /* ok not sure if this should be default... */
 insert_binding_rec(Z_TREES,  Z_NO_FLUSH);
#endif
insert_binding(Z_OK           );
insert_binding(Z_STREAM_END   );
insert_binding(Z_NEED_DICT    );
insert_binding(Z_ERRNO        );
insert_binding(Z_STREAM_ERROR );
insert_binding(Z_DATA_ERROR   );
insert_binding(Z_MEM_ERROR    );
insert_binding(Z_BUF_ERROR    );
insert_binding(Z_VERSION_ERROR);
insert_binding(Z_NO_COMPRESSION     );
insert_binding(Z_BEST_SPEED         );
insert_binding(Z_BEST_COMPRESSION   );
insert_binding(Z_DEFAULT_COMPRESSION);
insert_binding(Z_FILTERED        );
insert_binding(Z_HUFFMAN_ONLY    );
insert_binding(Z_RLE             );
insert_binding(Z_FIXED           );
insert_binding(Z_DEFAULT_STRATEGY);
insert_binding(Z_BINARY );
insert_binding(Z_TEXT   );
insert_binding(Z_ASCII  );
insert_binding(Z_UNKNOWN);

#undef insert_binding
 z_version = SG_MAKE_STRING(ZLIB_VERSION);
 /* well this class should not be used, but for consistancy */
 Sg_InitStaticClassWithMeta(SG_CLASS_ZSTREAM, UC("<z-stream>"), lib, NULL,
			    SG_FALSE, NULL, 0);
}
示例#22
0
static void compound_printer(SgObject o, SgPort *p, SgWriteContext *ctx)
{
  SgObject components = SG_COMPOUND_CONDITION(o)->components, cp;
  Sg_Putuz(p, UC("#<condition\n"));
  SG_FOR_EACH(cp, components) {
    Sg_Putc(p, ' ');
    Sg_Write(SG_CAR(cp), p, SG_WRITE_WRITE);
    Sg_Putc(p, '\n');
  }
示例#23
0
void Sg_FileTruncate(SgObject file, int64_t size)
{
  int fd = SG_FD(file)->fd;
  if (ftruncate(fd, size) != 0) {
    const char *msg = strerror(errno);
    Sg_SystemError(errno, UC("failed to ftruncate: %A"),
		   Sg_Utf8sToUtf32s(msg, strlen(msg)));
  }
}
示例#24
0
SgObject Sg_MakeThread(SgProcedure *thunk, SgObject name)
{
  SgVM *current = Sg_VM(), *vm;
  if (SG_PROCEDURE_REQUIRED(thunk) != 0) {
    Sg_Error(UC("thunk required, but got %S"), thunk);
  }
  vm = Sg_NewVM(current, name);
  vm->thunk = thunk;
  return SG_OBJ(vm);
}
示例#25
0
SgObject Sg_ReadSysRandom(int bits)
{
  SgObject buf;
  bits = (bits/8)+((bits%8)!=0?1:0);
  buf = Sg_MakeByteVector(bits, 0);
  if (rng_get_bytes(SG_BVECTOR_ELEMENTS(buf), (unsigned long)bits, NULL) != 
      (unsigned long)bits) {
    Sg_Error(UC("failed to read system prng"));
  }
  return buf;
}
示例#26
0
static void main0(const char *cell, Out *out) {
    int nv, nm;
    MeshVertArea *vert_area;
    Vectors  *pos;
    double *vert_areas;
    UC(mesh_read_ini_off(cell, /**/ &out->mesh));
    UC(mesh_vert_area_ini(out->mesh, &vert_area));
    nv = mesh_read_get_nv(out->mesh);
    UC(vectors_float_ini(nv, mesh_read_get_vert(out->mesh), /**/ &pos));

    nm = 1;
    EMALLOC(nv, &vert_areas);
    mesh_vert_area_apply(vert_area, nm, pos, /**/ vert_areas);
    dump(nv, nm, vert_areas, pos, out);

    mesh_vert_area_fin(vert_area);
    UC(vectors_fin(pos));
    UC(mesh_read_fin(out->mesh));
    EFREE(vert_areas);
}
示例#27
0
bool AttackTask::onValidate() {
	CGroup *group = firstGroup();

	if (targetAlt >= 0) {
		if (ai->cbc->IsUnitCloaked(targetAlt) || !group->canAttack(targetAlt)) {
			group->stop();
		}
	}

	const UnitDef *eud = ai->cbc->GetUnitDef(target);
	if (eud == NULL)
		return false;

	if (!isMoving) {
		if (ai->cbc->IsUnitCloaked(target))
			return false;
		return true;
	}

	if (!group->canAttack(target))
		return false;

	// don't chase scout groups too long if they are out of base...
	bool scoutGroup = (group->cats&SCOUTER).any();
	if (!scoutGroup && lifeTime() > 20.0f) {
		const unitCategory ecats = UC(eud->id);
		if ((ecats&SCOUTER).any() && !ai->defensematrix->isPosInBounds(pos))
			return false;
	}

	float targetDistance = pos.distance2D(group->pos());
	if (targetDistance > 1000.0f)
		return true; // too far to panic

	if (ai->cbc->IsUnitCloaked(target))
		return false;

	bool isBaseThreat = ai->defensematrix->isPosInBounds(pos);

	// if there is no threat to our base then prevent useless attack for groups
	// which are not too cheap
	if (!isBaseThreat && (group->costMetal / group->units.size()) >= 100.0f) {
		float threatRange;
		if (scoutGroup)
			threatRange = 300.0f;
		else
			threatRange = 0.0f;

		if (group->getThreat(pos, threatRange) > group->strength)
			return false;
	}

	return true;
}
示例#28
0
文件: bas5.c 项目: LGTMCU/f32c
static	int
in1line(void)
{
	int	c;

	if(pushback >= 0){
		c = pushback;
		pushback = -1;
		return(c);
	}
	return(UC(*in1iline++));
}
示例#29
0
文件: os.cpp 项目: uDeviceX/uDeviceX
void os_mkdir(const char *path0) {
    char path[FILENAME_MAX] = {'\0'};
    unsigned int len;
    char *p;

    len = snprintf(path, sizeof(path), "%s", path0);

    if (len >= sizeof(path)) ERR("Path is too long: %s", path0);
    if (len == 0) ERR("empty path");

    if (path[len-1] == SEP) path[len-1] = END;

    for (p = path; *p != END; ++p) {
        if (*p == SEP) {
            *p = END;
            UC(safe_mkdir(path));
            *p = SEP;
        }
    }
    UC(safe_mkdir(path));
}
示例#30
0
int main(int argc, char **argv) {
    const char *arg;
    char **v;
    int rank, c, dims[3];
    const char delim[] = " \t";
    Config *cfg;
    MPI_Comm cart;
    
    m::ini(&argc, &argv);
    m::get_dims(&argc, &argv, dims);
    m::get_cart(MPI_COMM_WORLD, dims, &cart);

    MC(m::Comm_rank(cart, &rank));
    msg_ini(rank);
    UC(conf_ini(&cfg));
    UC(conf_read(argc, argv, /**/ cfg));
    UC(coords_ini_conf(cart, cfg, /**/ &coords));
    UC(conf_lookup_string(cfg, "a", &arg));
    tok_ini(arg, delim, /**/ &c, &v);

    main3(c, v);

    tok_fin(c, v);
    UC(coords_fin(coords));
    UC(conf_fin(cfg));

    MC(m::Barrier(cart));
    m::fin();
}