STATUS FunctionList_AddLocalFunction(FunctionList fl, const char *func_name, const unsigned int address)
{
	FunctionList f ;
	FunctionList tmp = fl;

	if(IS_NULL(func_name) || (strlen(func_name) == 0))
	{
		LOG_ERROR("local function name is NULL");
		return STATUS_FAILURE;
	}
	while(tmp->next != NULL)
	{
		if(!IS_NULL(tmp->func_name) && strcasecmp(tmp->func_name, func_name) == 0)
		{
			LOG_ERROR("function name '%s' already exists", func_name);
			return STATUS_FAILURE;
		}
		tmp = tmp->next;
	}

	f = FunctionList_Create();
	if(!IS_NULL(f))
	{
		f->func_name = (char*)Malloc(strlen(func_name)+1);
		strcpy(f->func_name, func_name);
		f->type = FUNCTION_TYPE_LOCAL;
		f->u.address = address;
		tmp->next = f;
		return STATUS_SUCCESS;
	}
	LOG_ERROR("FunctionList_Create() failed");
	return STATUS_FAILURE;
}
Exemple #2
0
/**
 *	init_link_slot_tab - 初始化LINK槽表
 *
 *	@nr_links:		总的连接数
 *
 *	return
 *		0			成功
 *		!0			失败
 */
static int
init_link_slot_tab(IN unsigned short nr_links)
{
	int						i;
	size_t					size;
	struct link_slot_tab	*obj = lnktable_object();
	struct link_slot		*slot;
	struct link_buff		*buff;

	memset(obj, 0, sizeof(struct link_slot_tab));
	obj->nr_links = nr_links;

	size = nr_links * sizeof(struct link_slot);
	obj->slot = zmalloc(size);
	if(IS_NULL(obj->slot))
		return gen_errno(0, GCENOMEM);
	else
		slot = obj->slot;

	size = nr_links * 2 * sizeof(struct link_buff);
	obj->buff = zmalloc(size);
	if(IS_NULL(obj->buff))
		return gen_errno(0, GCENOMEM);
	else
		buff = obj->buff;

	for(i = 0; i < nr_links*2; i++)
		init_link_buff(buff++);
	
	for(i = 0; i < nr_links; i++)
		init_link_slot(slot++);

	return 0;
}
Exemple #3
0
static METHOD knh__String_substring(Ctx *ctx, knh_sfp_t *sfp)
{
	knh_bytes_t base = knh_String_tobytes(sfp[0].s);
	knh_bytes_t sub;
	if(knh_String_isASCII(sfp[0].s)) {
		size_t offset = IS_NULL(sfp[1].o) ? 0 : knh_array_index(ctx, sfp[1].ivalue, base.len);
		sub = knh_bytes_last(base, offset);
		if(IS_NOTNULL(sfp[2].o)) {
			size_t len = (size_t)sfp[2].ivalue;
			if(len < sub.len) sub = knh_bytes_first(sub, len);
		}
	}
	else { // multibytes
		size_t mlen = knh_bytes_mlen(base);
		size_t offset = IS_NULL(sfp[1].o) ? 0 : knh_array_index(ctx, sfp[1].ivalue, mlen);
		size_t length = IS_NULL(sfp[2].o) ? (mlen - offset) : (size_t)sfp[2].ivalue;
		sub = knh_bytes_mofflen(base, offset, length);
	}

	String *s;
	if(sub.len == 0) {
		s = TS_EMPTY;
	}
	else if(sub.len == base.len) {
		s = sfp[0].s;
	}
	else {
		s = new_String(ctx, sub, sfp[0].s);
	}
	KNH_RETURN(ctx, sfp, s);
}
Exemple #4
0
static BOOL _str_perform_match(CSTR pattern, CSTR string, BOOL caseSensitive) {

	CHAR	ch;

	if (IS_NULL(pattern) || IS_NULL(string))
		return FALSE;

	for (;;) {
		switch (ch = *pattern++) {

			case '\0':
				return (*string == c_NULL);

			case '?':
				if (*string == c_NULL)
					return FALSE;

				++string;
				break;

			case '*': {

				CSTR	str;

				while (*pattern == '?') {

					/* Skip a character for each '?'. */

					if (*string == c_NULL)
						return FALSE;

					++string;
					++pattern;
				}


				if (*pattern == c_NULL) /* a trailing '*' matches everything else */
					return TRUE;

				str = string;
				while (*str != c_NULL) {

					if ( (caseSensitive ? *str == *pattern : str_char_tolower(*str) == str_char_tolower(*pattern)) &&
						 _str_perform_match(pattern, str, caseSensitive) )
						return TRUE;

					++str;
				}

				break;
			}

			default:
				if (caseSensitive ? *string++ != ch : str_char_tolower(*string++) != str_char_tolower(ch))
					return FALSE;

				break;
		}
	}
}
Exemple #5
0
int IFSEXPORT
FS_OPENCREATE(
   struct cdfsi far * pcdfsi,
   struct cdfsd far * pcdfsd,
   char far * pszName,
   unsigned short iCurDirEnd,
   struct sffsi far * psffsi,
   struct sffsd far * psffsd,
   unsigned long flOpenMode,
   unsigned short fsOpenFlag,
   unsigned short far * pusAction,
   unsigned short fsAttr,
   PEAOP pEABuf,
   unsigned short far * pfsGenFlag
   )
{
   int rc;
   struct opencreate far * p = &pRequest->data.opencreate;

   if (rc = requestExchangeXS()) return rc;

   pRequest->rq = FSRQ_OPENCREATE;

   COPYPTR(&p->pVolData, queryVPFSD(pcdfsi->cdi_hVPB));
   p->cdfsi = *pcdfsi;
   p->cdfsd = *pcdfsd;

   if (strlen(pszName) >= CCHMAXPATH)
      RELEASE_AND_EXIT(ERROR_INVALID_PARAMETER);
   strcpy(p->szName, pszName);
   p->iCurDirEnd = iCurDirEnd;

   p->sffsi = *psffsi;
   p->flOpenMode = flOpenMode;
   p->fsOpenFlag = fsOpenFlag;
   p->fsAttr = fsAttr;

   if (!IS_NULL(pEABuf)) {
      rc = copyEAOP(pEABuf, CEA_FEAS_TO_BUF, 0);
      if (rc) RELEASE_AND_EXIT(rc);
      p->fHasEAs = 1;
   }
   else p->fHasEAs = 0;

   if (rc = signalDaemonAndWait()) RELEASE_AND_EXIT(rc);

   *psffsi = p->sffsi;
   if (psffsi->sfi_type == STYPE_FILE)
      COPYPTR(psffsd, &p->pOpenFileData);

   *pusAction = p->usAction;
   *pfsGenFlag = p->fsGenFlag;

   if (!IS_NULL(pEABuf)) {
      rc = copyEAOP(pEABuf, CEA_SET_OERROR, p->oError);
      if (rc) RELEASE_AND_EXIT(rc);
   }

   RELEASE_AND_EXIT(pRequest->rc);
}
STATUS FunctionList_AddNativeFunction(FunctionList fl, const char *func_name, NativeFunction func)
{
	FunctionList f ;
	FunctionList tmp = fl;

	if(IS_NULL(func_name) || (strlen(func_name) == 0))
	{
		LOG_ERROR("native function name is NULL");
		return STATUS_FAILURE;
	}
	while(tmp->next != NULL)
	{
		if(!IS_NULL(tmp->func_name) && strcasecmp(tmp->func_name, func_name) == 0)
		{
			LOG_ERROR("function name '%s' already exists", func_name);
			return STATUS_FAILURE;
		}
		tmp = tmp->next;
	}

	f = FunctionList_Create();
	if(!IS_NULL(f))
	{
		f->func_name = (char*)Malloc(strlen(func_name)+1);
		strcpy(f->func_name, func_name);
		f->type = FUNCTION_TYPE_NATIVE;
		f->u.nFunc = func;
		tmp->next = f;
		return STATUS_SUCCESS;
	}
	LOG_ERROR("FunctionList_Create() failed");
	return STATUS_FAILURE;
}
int putGV(JNIEnv* env, jint gmask, jint baseIndex, jobject gvdata, const LayoutEngine* engine, int glyphCount) {
    int count = env->GetIntField(gvdata, gvdCountFID);

    jarray glyphArray = (jarray)env->GetObjectField(gvdata, gvdGlyphsFID);
    if (IS_NULL(glyphArray)) {
      JNU_ThrowInternalError(env, "glypharray null");
      return 0;
    }
    jint capacity = env->GetArrayLength(glyphArray);
    if (count + glyphCount > capacity) {
      JNU_ThrowArrayIndexOutOfBoundsException(env, "");
      return 0;
    }

    jarray posArray = (jarray)env->GetObjectField(gvdata, gvdPositionsFID);
    if (IS_NULL(glyphArray)) {
      JNU_ThrowInternalError(env, "positions array null");
      return 0;
    }
    jarray inxArray = (jarray)env->GetObjectField(gvdata, gvdIndicesFID);
    if (IS_NULL(inxArray)) {
      JNU_ThrowInternalError(env, "indices array null");
      return 0;
    }

    int countDelta = 0;

    // le_uint32 is the same size as jint... forever, we hope
    le_uint32* glyphs = (le_uint32*)env->GetPrimitiveArrayCritical(glyphArray, NULL);
    if (glyphs) {
      jfloat* positions = (jfloat*)env->GetPrimitiveArrayCritical(posArray, NULL);
      if (positions) {
        jint* indices = (jint*)env->GetPrimitiveArrayCritical(inxArray, NULL);
        if (indices) {
          LEErrorCode status = (LEErrorCode)0;
          engine->getGlyphs(glyphs + count, gmask, status);
          engine->getGlyphPositions(positions + (count * 2), status);
          engine->getCharIndices((le_int32*)(indices + count), baseIndex, status);

          countDelta = glyphCount;

          // !!! need engine->getFlags to signal positions, indices data
          /* "0" arg used instead of JNI_COMMIT as we want the carray
           * to be freed by any VM that actually passes us a copy.
           */
          env->ReleasePrimitiveArrayCritical(inxArray, indices, 0);
        }
        env->ReleasePrimitiveArrayCritical(posArray, positions, 0);
      }
      env->ReleasePrimitiveArrayCritical(glyphArray, glyphs, 0);
    }

    if (countDelta) {
      count += countDelta;
      env->SetIntField(gvdata, gvdCountFID, count);
    }

  return 1;
}
Exemple #8
0
int memq(SCM key, SCM list) {
    SCM l = list;
    while (!IS_NULL(l)) {
        if (!(IS_PAIR(l) || IS_NULL(l))) wta_error ("memq", 2);
        if EQ(key, CAR(l)) return 1;
        l = CDR(l);
    }
    return 0;
}
Exemple #9
0
void _do_insert(List *L, ListNode *node)
{
    node->next = L->head;
    if (!IS_NULL(L->head))
        L->head->prev = node;
    L->head = node;
    node->prev = NULL;
    ++L->length;
    if (IS_NULL(L->head->next))
        L->tail = node;
}
Exemple #10
0
void *_do_delete(List *L, ListNode *del_node)
{
    void *val = del_node->value;
    if (!IS_NULL(del_node->prev))
        del_node->prev->next = del_node->next;
    else
        L->head = del_node->next;

    if (!IS_NULL(del_node->next))
        del_node->next->prev = del_node->prev;
    free(del_node);
    return val;
}
Exemple #11
0
BOOL str_creationinfo_set(CreationInfo *info, CSTR creator, CSTR reason, time_t time_set) {

	if (IS_NULL(info) || IS_NULL(creator) || IS_NULL(reason))
		return FALSE;

	str_creator_set(&(info->creator), creator, time_set);

	if (IS_NOT_NULL(info->reason))
		mem_free(info->reason);

	info->reason = str_duplicate(reason);

	return TRUE;
}
Exemple #12
0
void test_module_load(CTX)
{
    module_load(_ctx, (kcontext_t*)_ctx, BUILD_DIR "mod_sample.dylib", "ksample");
    ksampleshare_t *sharemod = (ksampleshare_t*) _ctx->modshare[MOD_SAMPLE];
    assert(sharemod);

    sharemod->h.setup(_ctx, (kmodshare_t*)sharemod);
    ksamplemod_t *mod = (ksamplemod_t*) _ctx->mod[MOD_SAMPLE];

    assert(mod);
    assert(IS_NULL(mod->array) == 0);
    MODGC_gc_invoke(_ctx, 0);
    assert(IS_NULL(mod->array) == 0);
}
Exemple #13
0
/**
 * @brief
 * try to readdir a directory opened by another user. should fail.
 * @return 1 if successful, 0 otherwise
 */
error_t readdirTest8(){
	user_id uid1 = 1, uid2 = 2;
	NANDFS_DIR* ds;
	uint8_t *dir = "/";

	SET_CURRENT_USER(uid1);
	ds = opendir(dir);
	VERIFY(!IS_NULL(ds));

	SET_CURRENT_USER(uid2);
	VERIFY(IS_NULL(readdir(ds)));

	return 1;
}
Exemple #14
0
static RIOTC_RTN do_service_release_process(RIOTC_MASTER_CTX * ctx)
{
    if (IS_NULL(ctx))
        return RIOTC_RTN_FAIL_IS_NULL;

    if (!IS_NULL(ctx->evhr))
        riotc_event_handler_release(ctx->evhr);

    if (!IS_NULL(ctx->scm))
        riotc_master_scm_release(ctx->scm);

    free(ctx);

    return RIOTC_RTN_SUCCESS;
}
Exemple #15
0
int check_nargs(char *fname, SCM args, int min, int max) {
    if (!(IS_PAIR(args) || IS_NULL(args)))
        error0("wrong arguments");

    int i;
    for (i = 0; IS_PAIR(args); i++)
        args = CDR(args);

    if (!IS_NULL(args))
        error0("wrong arguments");
    if (!((min <= i) && (i <= max)))
        wna_error(fname, i);

    return i;
}
Exemple #16
0
int GameEnd(int amPlayers)
{
    int iwinner;
    int iPairs = 0;
    for (int i = 0; i < amPlayers; i++)
        if (pairs[i] > iPairs)
        {
            iwinner = i;
            iPairs = pairs[iwinner];
        }

    int i = 0;
    while (!IS_NULL(objects[i++]));
    i--;

    char c[100];

    char *c2 = (char *)malloc(sizeof(char));
    sprintf(c2, "%d", iPairs);
    concat("The Winner with ", c2);
    if (iPairs == 1)
        concat(c, " pair is Player ");
    else
        concat(c, " pairs is Player ");

    sprintf(c2, "%d", iwinner);
    concat(c, c2);

    objects[i] = O_New_Label(objects[i], c, 300, 300);

    i++;
    objects[i] = O_New_Button(objects[i], "Continue", BContinue, 300, 400);
}
Exemple #17
0
/**
 *	init_linkno_pool - 初始化LINKNO池
 *
 *	@nr_links:		总的LINKNO数
 *
 *	return
 *		0			成功
 *		!0			失败
 */
static int
init_linkno_pool(IN unsigned short nr_links)
{
	int						i;
	size_t					size;
	struct linkno_s_pool	*obj = lnk_pool_object();
	struct linkno_s			*ptr;

	memset(obj, 0, sizeof(struct linkno_s_pool));

	obj->cur_using	= 0;
	INIT_LIST_HEAD(&(obj->free_head));
	pthread_mutex_init(&(obj->lock), NULL);
	obj->nr_links = nr_links;
	memset(obj->bitmap, 0, sizeof(obj->bitmap));

	size = nr_links * sizeof(struct linkno_s);
	obj->base = zmalloc(size);
	if(IS_NULL(obj->base))
		return gen_errno(0, GCENOMEM);
	
	ptr = obj->base;
	for(i = 0; i < nr_links; i++, ptr++)
		list_add_tail(&(ptr->list), &(obj->free_head));

	return 0;
}
void DataTableColumnType::createDefaultCell()
{
	std::string value;

	IS_NULL(m_defaultCell);

	// If mangleValue does not update the input value string,
	//   then the default cell will have a value of 0 for floats and ints
	//     and a value of empty string for strings.
	IGNORE_RETURN(mangleValue(value));

	switch(m_basicType)
	{
	case DT_Int:
		m_defaultCell = new DataTableCell(static_cast<int>(strtol(value.c_str(), NULL, 0)));
		break;
	case DT_Float:
		m_defaultCell = new DataTableCell(static_cast<float>(atof(value.c_str())));
		break;
	case DT_String:
	case DT_Comment:
	case DT_Unknown:
	default:
		m_defaultCell = new DataTableCell(value.c_str());
		break;
	}
}
Exemple #19
0
/* Read from STDIN and base32 encode the data as A records */
void
sdt_loop_A(SDT_STATE *ss)
{
    ssize_t n = 0;
    char *buf = NULL;

    int flags = 0;

    flags = fcntl(ss->fd_in, F_GETFL, 0);
    flags |= O_NONBLOCK;
    (void)fcntl(ss->fd_in, F_SETFL, flags);

    IS_NULL(buf = calloc(ss->bufsz, 1));

    while ( (n = sdt_read(ss, buf, ss->bufsz)) > 0) {
        VERBOSE(3, "Sending A record: %d of %u bytes\n", (int32_t)n, (u_int32_t)ss->bufsz);
        sdt_send_A(ss, buf, n);
        ss->sum_up += n;
        if (woken != 0)
            break;
        VERBOSE(3, "A record: res timeout = %d, sleep = %f seconds\n",
                ss->backoff, (float)(ss->sleep * ss->backoff)/1000000);
        usleep(ss->sleep);
    }

    free(buf);
    VERBOSE (1, "*** Exiting from A record read loop\n");
}
Exemple #20
0
/**
 * @brief
 * try to read from an illegal dirstream. should fail
 * @return 1 if successful, 0 otherwise
 */
error_t readdirTest7(){
	NANDFS_DIR* ds = NULL;

	VERIFY(IS_NULL(readdir(ds)));

	return 1;
}
Exemple #21
0
STR str_compact(STR string) {

    char *ptr = string, *s, *t;

	if (IS_NULL(string))
		return string;

    for (; *ptr; ptr++) {

		if (*ptr == '*') {

			if (*(t = s = ptr + 1) == '*') {

				while (*t == '*')
					t++;
			}
			else if (*t == '?') {

				for (t++, s++; *t == '*' || *t == '?'; t++) {

					if (*t == '?')
						*s++ = *t;
				}
			}

			while ((*s++ = *t++));
		}
	}

	return string;
}
Exemple #22
0
// Transfer execution to [fiber] coming from the current fiber whose stack has
// [args].
//
// [isCall] is true if [fiber] is being called and not transferred.
//
// [hasValue] is true if a value in [args] is being passed to the new fiber.
// Otherwise, `null` is implicitly being passed.
static bool runFiber(WrenVM* vm, ObjFiber* fiber, Value* args, bool isCall,
                     bool hasValue, const char* verb)
{
  if (isCall)
  {
    if (fiber->caller != NULL) RETURN_ERROR("Fiber has already been called.");

    // Remember who ran it.
    fiber->caller = vm->fiber;
  }

  if (fiber->numFrames == 0)
  {
    RETURN_ERROR_FMT("Cannot $ a finished fiber.", verb);
  }

  if (!IS_NULL(fiber->error))
  {
    RETURN_ERROR_FMT("Cannot $ an aborted fiber.", verb);
  }

  // When the calling fiber resumes, we'll store the result of the call in its
  // stack. If the call has two arguments (the fiber and the value), we only
  // need one slot for the result, so discard the other slot now.
  if (hasValue) vm->fiber->stackTop--;

  // If the fiber was paused, make yield() or transfer() return the result.
  if (fiber->stackTop > fiber->stack)
  {
    fiber->stackTop[-1] = hasValue ? args[1] : NULL_VAL;
  }

  vm->fiber = fiber;
  return false;
}
Exemple #23
0
    void
sds_sock_loop(SDS_STATE *ss)
{
    SDS_PKT *pkt = NULL;

    IS_NULL(pkt = calloc(1, sizeof(SDS_PKT)));

    (void)sds_sock_init(ss);

    for ( ; ; ) {
        (void)memset(pkt, 0, sizeof(SDS_PKT));

        if (docleanup == 1) {
            ss->cleanup(ss);
            docleanup = 0;
        }

        (void)alarm(ss->maxtimeout*2);
        if (sds_sock_recv(ss, pkt) < 0)
            continue;

        if (ss->handler(ss, pkt) < 0)
            continue;

        (void)sds_sock_send(ss, pkt); /* XXX need to re-send if failed */
    }
}
Exemple #24
0
void *list_delete(List *L, const void *value)
{
    ListNode *del_node = list_search(L, value);
    if (!IS_NULL(del_node))
        return _do_delete(L, del_node);
    return NULL;
}
Exemple #25
0
void list_retraversal(List *L, void (*visit_func)(void *))
{
    ListNode *p = L->tail;
    while (!IS_NULL(p)) {
        visit_func(p->value);
        p = p->prev;
    }
}
Exemple #26
0
void list_traversal(List *L, void (*visit_func)(void *))
{
    ListNode *p = L->head;
    while (!IS_NULL(p)) {
        visit_func(p->value);
        p = p->next;
    }
}
Exemple #27
0
int str_compare(CSTR string1, CSTR string2) {

	register const unsigned char	*str1 = (const unsigned char *) string1;
	register const unsigned char	*str2 = (const unsigned char *) string2;
	register unsigned char		ch1, ch2;

	if (IS_NULL(str1) || IS_NULL(str2))
		return (int)(str1 - str2);

	do {
		ch1 = (unsigned char) *str1++;
		ch2 = (unsigned char) *str2++;

	} while ((ch1 != c_NULL) && (ch1 == ch2));

	return ch1 - ch2;
}
Exemple #28
0
static METHOD knh__String_opSubsete(Ctx *ctx, knh_sfp_t *sfp)
{
  if(IS_NOTNULL(sfp[2].o)) {
	  size_t offset = IS_NULL(sfp[1].o) ? 0 : (size_t)sfp[1].ivalue;
	  sfp[2].ivalue = sfp[2].ivalue - offset + 1;
  }
  knh__String_substring(ctx, sfp);
}
Exemple #29
0
//## Node Node.AppendParsedNode(Token[] tokenList, int beginIdx, int endIdx, String requiredTokenText);
static KMETHOD Node_AppendParsedNode(KonohaContext *kctx, KonohaStack *sfp)
{
	kNode *node = sfp[0].asNode;
	kArray *tokenList = sfp[1].asArray;
	int beginIdx = sfp[2].intValue;
	int endIdx = sfp[3].intValue;
	const char *requiredTokenText = IS_NULL(sfp[4].asString) ? NULL : kString_text(sfp[4].asString);
	KReturn(SUGAR AppendParsedNode(kctx, node, tokenList, beginIdx, endIdx, NULL, ParseExpressionOption, requiredTokenText));
}
Exemple #30
0
extern int
onig_set_default_syntax(OnigSyntaxType* syntax)
{
  if (IS_NULL(syntax))
    syntax = ONIG_SYNTAX_RUBY;

  OnigDefaultSyntax = syntax;
  return 0;
}