Ejemplo n.º 1
0
void* malloc(size_t size) {
	mythread* thread = getById(pthread_self());
	if (size >= N) {
		mybucket* b = bfind(thread->big_list, size);
		if (b == 0) {
			b = bfind(glob_list, size);
			if (b == 0) {
				b = bcreate(size);
				return b->mem;
			}
			pthread_mutex_lock(&glob_mutex);
			bdelete(&glob_list, &glob_list_end, b);
			glob_size--;
			pthread_mutex_unlock(&glob_mutex);
			return b->mem;
		}
		pthread_mutex_lock(&thread->thread_mutex);
		bdelete(&thread->big_list, &thread->big_list_end, b);
		thread->bigsize--;
		pthread_mutex_unlock(&thread->thread_mutex);
		return b->mem;
	} else {
		mybucket* b = bfind(thread->small_list, size);
		if (b == 0) {
			b = bcreate(size);
			return b->mem;
		}
		pthread_mutex_lock(&thread->thread_mutex);
		bdelete(&thread->small_list, &thread->small_list_end, b);
		thread->smallsize--;
		pthread_mutex_unlock(&thread->thread_mutex);
		return b->mem;
	}
}
Ejemplo n.º 2
0
//spell9「左右&上下拘束弾」
void shot_E8(){
	int t = spcount;

	if(t>=120){
		if(t<1200){
			if((t-120)%80==0){
				E8_1(38,1.5,0);
				E8_1(38,1.5,1);
				se_flag[0]=1;
			}
		}
		else{
			if(t==1200){
				bdelete();
				se_flag[8]=1;
			}

			if((t-1200)%60==0){
				E8_0(43,2,0);
				E8_0(43,2,1);
				se_flag[0]=1;
			}
		}
	}
}
Ejemplo n.º 3
0
void free(void* ptr) {
	if (ptr == 0) return;
	mybucket* b = (mybucket*)(ptr - sizeof(mybucket));
	if (b->size >= N) {
		mythread* th = getById(pthread_self());
		pthread_mutex_lock(&th->thread_mutex);
		badd(&th->big_list, &th->big_list_end,b);
		th->bigsize++;
		pthread_mutex_unlock(&th->thread_mutex);
		if (th->bigsize > MAX_BIG_SIZE) {
			mybucket* moving = th->big_list;
			pthread_mutex_lock(&th->thread_mutex);
			bdelete(&th->big_list, &th->big_list_end, moving);
			th->bigsize--;
			pthread_mutex_unlock(&th->thread_mutex);
			pthread_mutex_lock(&glob_mutex);
			badd(&glob_list, &glob_list_end, moving);
			glob_size++;
			pthread_mutex_unlock(&glob_mutex);
			if (glob_size > MAX_GLOB_SIZE) {
				mybucket* d = glob_list;
				pthread_mutex_lock(&glob_mutex);
				bdelete(&glob_list, &glob_list_end, d);
				glob_size--;
				pthread_mutex_unlock(&glob_mutex);
				bdestroy(d);
			}
		}
	} else {
		mythread* th = getById(b->id);
		pthread_mutex_lock(&th->thread_mutex);
		badd(&th->small_list, &th->small_list_end, b);
		th->smallsize++;
		pthread_mutex_unlock(&th->thread_mutex);
		if (th->smallsize > MAX_SMALL_SIZE) {
			mybucket* d = th->small_list;
			pthread_mutex_lock(&th->thread_mutex);
			bdelete(&th->small_list, &th->small_list_end,d);
			th->smallsize--;
			pthread_mutex_unlock(&th->thread_mutex);
			bdestroy(d);
		}
	}
}
Ejemplo n.º 4
0
/* {{{ _php_bbcode_callback_handler
   Common code for content and parameter handlers */
static int _php_bbcode_callback_handler(int cb_type, bstring content, bstring param, zval *func_name)
{
	zval *retval = NULL;
	zval ***zargs = NULL;
	char *callable = NULL;
	int i, res;
	bstring target;
	char *cb_name = "";
	TSRMLS_FETCH();

	switch (cb_type) {
		case PHP_BBCODE_CONTENT_CB:
			target = content;
			break;

		case PHP_BBCODE_PARAM_CB:
			target = param;
			break;
	}

	zargs = (zval ***) emalloc(sizeof(zval **) * 2);
	zargs[0] = emalloc(sizeof(zval *));
	MAKE_STD_ZVAL(*zargs[0]);
	ZVAL_STRINGL(*zargs[0], bdata(content), blength(content), 1);
	zargs[1] = emalloc(sizeof(zval *));
	MAKE_STD_ZVAL(*zargs[1]);
	ZVAL_STRINGL(*zargs[1], bdata(param), blength(param), 1);

	res = call_user_function_ex(EG(function_table), NULL, func_name, &retval, 2, zargs, 1, NULL TSRMLS_CC);
	
	if (res != SUCCESS) {
		if (!zend_is_callable(func_name, 0, &callable TSRMLS_CC)) {
			php_error_docref(NULL TSRMLS_CC, E_WARNING, "function `%s' is not callable", callable);
		} else {
			php_error_docref(NULL TSRMLS_CC, E_WARNING, "callback function %s() failed", callable);
		}
		efree(callable);
	} else if (&retval != NULL) {
		convert_to_string_ex(&retval);
		if (Z_STRLEN_P(retval)) {
			bassignblk(target, Z_STRVAL_P(retval), Z_STRLEN_P(retval));
		} else {
			bdelete(target, 0, blength(target));
		}
		zval_ptr_dtor(&retval);
	}

	/* Free zargs */
	for (i = 0; i < 2; i++) {
		zval_ptr_dtor(zargs[i]);
		efree(zargs[i]);
	}
	efree(zargs);

	return 0;
}
Ejemplo n.º 5
0
Archivo: Reader.c Proyecto: denji/mdr
bstring getContentFromLine(bstring line, int formatPaddingLen, int * leadingSpaces)
{
    // Remove padding from front of string.
    bstring content = bmidstr(line, formatPaddingLen, line->slen);
    *leadingSpaces = 0;
    // Remove and count leading whitespace.
    while (content->slen > 0 && content->data[0] == ' ')
    {
        bdelete(content, 0, 1);
        (*leadingSpaces)++;
    }
    return content;
}
Ejemplo n.º 6
0
//弾丸の描画
void graph_bullet(){
	int j;
	double disp_angle;
	SetDrawMode( DX_DRAWMODE_BILINEAR );//線形補完描画
	for(j=0;j<BULLET_MAX;j++){//その弾幕が持つ弾の最大数分ループ
		if(bullet[j].flag!=0){//弾データがオンなら
			disp_angle=bullet[j].angle+PI/2;

			DrawRotaGraphF(bullet[j].x, bullet[j].y, 1.0, disp_angle,
				img_bullet[bullet[j].knd][bullet[j].col],TRUE);
		}
	}
	if(ch.bcnt){
		bdelete();
	}
}
Ejemplo n.º 7
0
SkObject *sk_bytecode_parse_message(SkVM *vm, FILE *stream) {
    SkObject *self = sk_object_clone(sk_vm_get_proto(vm, "Message"));
    bstring name = bgets(&_fgetc, stream, '\0');
    /* cut the trailing \0 */
    bdelete(name, name->slen - 1, 1);
    /* set the message's name and read the argument count */
    sk_message_set_name(self, sk_string_from_bstring(vm, name));
    ArgCount argcount, i;
    if(fread(&argcount, sizeof(ArgCount), 1, stream) != 1) {
        abort();
    }
    for(i = 0; i < argcount; i++) {
        SkObject *arg = sk_bytecode_parse_avalanche(vm, stream);
        sk_message_append_argument(self, arg); 
    }
    return self;
}
Ejemplo n.º 8
0
static void normalize_space(bstring str) {
	int i=0;
	while(i<blength(str)) {
		int spaceStart = bstrchrp(str,' ',i);
		if (spaceStart == BSTR_ERR)
			break;
		//we found it, now look for the end of this space sequence
		int spaceLen = 1; //exclusive
		while(str->data[spaceStart+spaceLen] == ' ')
			spaceLen++;
		if (spaceLen > 1) {
			//multiple spaces
			bdelete(str,spaceStart+1,spaceLen-1);
		}

		i = spaceStart+1;
	}
}
Ejemplo n.º 9
0
/* ----------------------------------------------------------
 * FUNCTION	: brtrim
 * DESCRIPTION	: This function will trim the whitespace from
 *		: the right side of a string.
 * INPUT	: 0 - String
 * ---------------------------------------------------------- */
int brtrim (bstring string)
{
    int i;
    int len = 0;

    /* Find Whitespace */
    for (i = (string->slen - 1); i > 0; i--) {
	if (string->data[i] == ' ' || string->data[i] == '\t')
	    len++;
	else
	    break;
    }

    /* Remove Whitespace */
    if (len > 0)
	bdelete(string, i + 1, len);

    return 0;
}
Ejemplo n.º 10
0
/* ----------------------------------------------------------
 * FUNCTION	: bltrim
 * DESCRIPTION	: This function will trim the whitespace from
 *		: the left side of a string.
 * INPUT	: 0 - String
 * ---------------------------------------------------------- */
int bltrim (bstring string)
{
    int i;
    int len = 0;

    /* Find Whitespace */
    for (i = 0; i < string->slen; i++) {
	if (string->data[i] == ' ' || string->data[i] == '\t')
	    len++;
	else
	    break;
    }

    /* Remove Whitespace */
    if (len > 0)
	bdelete(string, 0, len);

    return 0;
}
Ejemplo n.º 11
0
/*
 * hfs_bdelete()
 *
 * Delete the requested record from a B-tree.
 */
int hfs_bdelete(struct hfs_btree *tree, const struct hfs_bkey *key)
{ 
	struct hfs_belem *belem;
	struct hfs_bnode *bnode;
	struct hfs_brec brec;
	int retval;

	if (!tree || (tree->magic != HFS_BTREE_MAGIC) || !key) {
		hfs_warn("hfs_bdelete: invalid arguments.\n");
		return -EINVAL;
	}

	retval = hfs_bfind(&brec, tree, key, HFS_BFIND_DELETE);
	if (!retval) {
		belem = brec.bottom;
		bnode = belem->bnr.bn;

		belem->flags = 0;
        	if ((bnode->ndNRecs * sizeof(hfs_u16) + bnode_end(bnode) -
		     bnode_rsize(bnode, belem->record)) < FULL/2) {
			belem->flags |= HFS_BPATH_UNDERFLOW;
		}
		if (belem->record == 1) {
			belem->flags |= HFS_BPATH_FIRST;
		}

		if (!belem->flags) {
			hfs_brec_lock(&brec, brec.bottom);
		} else {
			hfs_brec_lock(&brec, NULL);
		}

		retval = bdelete(&brec);
		if (!retval) {
			--brec.tree->bthNRecs;
			brec.tree->dirt = 1;
		}
		hfs_brec_relse(&brec, NULL);
	}
	return retval;
}
Ejemplo n.º 12
0
void calc_percent(){
	if(ch.percent > 100.0)//ゲージは100%を超えない
		ch.percent = 100.0;
	if(ch.percent < 0){//ゲージが尽きた場合の処理
		ch.percent = 0;

		bdelete();//全ての弾を消す
		ch.flag=0;//自機を消す
		enemy.flag=0;//敵を消す

		se_flag[7] = 1;
		scount = count;
		count = 0;

		//リプレイ再生なら、演出スキップ
		if(replay_flag == 1){
			count = 300;
		}
		func_state = 4;//ゲームオーバー画面へ
	}
}
Ejemplo n.º 13
0
static void crfixup(void)
{
	char *p = (char *)memchr(Bbuff->curpage->pdata + 1, '\n', curplen(Bbuff) - 1);
	if (!p)
		return;

	if (*(p - 1) != '\r')
		return;

	if (raw_mode)
		return;

	Curbuff->bmode |= FILE_CRLF;

	while (bcsearch(Bbuff, '\r'))
		if (Buff() == '\n') {
			bmove(Bbuff, -1);
			bdelete(Bbuff, 1);
		}

	btostart(Bbuff);
}
Ejemplo n.º 14
0
void main()
{
	int n,num,num1,flag=0;

	while(1)
	{
		clrscr();
		printf("\n\t\t****** DOUBLY LINKED LIST OPERATION  ******\n");
		printf("\t\t......______________________________......\n");

		printf("\nWELCOME,WHAT YOU WANT TO DO ?::");
		printf("\n_____________________________\n\n");

		printf("\nINSERTION   --PRESS 1\n");
		printf("\nDELETION    --PRESS 2\n");
		printf("\nSEARCH      --PRESS 3\n");
		printf("\nCOUNT       --PRESS 4\n");
		printf("\nDISPLAY(F)  --PRESS 5\n");
		printf("\nDISPLAY(R)  --PRESS 6\n");
		printf("\nEXIT        --PRESS 7\n");
		printf("\n\nENTER YOUR CHOICE::\n");
		scanf("%d",&n);

		switch(n)
		{
			case 1:
					while(1)
					{
						flag=0;
						clrscr();
						printf("INSERT A NODE ::\n");

						printf("\t\tAT FIRST      -PRESS 1.\n");
						printf("\t\tAFTER A NODE  -PRESS 2.\n");
						printf("\t\tBEFORE A NODE -PRESS 3.\n");
						printf("\t\tAT LAST       -PRESS 4.\n");
						printf("\t\tEXIT FROM HERE-PRESS 5.\n");
						printf("\n\nENTER YOUR CHOICE::\n");
						scanf("%d",&n);
						switch(n)
						{
							case 1:
									printf("\nENTER A ELEMENT FOR INSERTION\n");
									scanf("%d",&num);
									finsert(num);
									printf("\n%d IS INSERT AT FIRST PROPERLY\n",num);
									break;
							case 2:
									printf("\nENTER A ELEMENT FOR INSERTION\n");
									scanf("%d",&num);
									printf("AFTER WHICH ELEMENT YOU WANT TO INSERT\n");
									scanf("%d",&num1);
									ainsert(num,num1);
									break;
							case 3:
									printf("ENTER A ELEMENT FOR INSERTION\n");
									scanf("%d",&num);
									printf("BEFORE WHICH ELEMENT YOU WANT TO INSERT\n");
									scanf("%d",&num1);
									binsert(num,num1);
									break;
							case 4:
									printf("ENTER  AN ELEMENT FOR INSERT IN LAST\n");
									scanf("%d",&num);
									linsert(num);
									break;
							case 5:
									printf("\nTHANK YOU FOR USING INSERT OPERETION\n");
									flag=1;
									break;

						}
						getch();
						if(flag==1)
							break;
					}
					break;
			case 2:
					while(1)
					{
						flag=0;
						clrscr();
						printf("DELETE A NODE ::\n");

						printf("\t\tAT FIRST      -PRESS 1.\n");
						printf("\t\tAFTER A NODE  -PRESS 2.\n");
						printf("\t\tBEFORE A NODE -PRESS 3.\n");
						printf("\t\tAT LAST       -PRESS 4.\n");
						printf("\t\tEXACT A NODE  -PRESS 5.\n");
						printf("\t\tEXIT FROM HERE-PRESS 6.\n");
						printf("\n\nENTER YOUR CHOICE::\n");
						scanf("%d",&n);
						switch(n)
						{
							case 1:
									fdelete();
									break;
							case 2:
									printf("\nENTER AFTER WHICH ELEMENT YOU WANT TO DELETE A NODE\n");
									scanf("%d",&num);
									adelete(num);
									break;
							case 3:
									printf("\nENTER BEFORE WHICH ELEMENT YOU WANT TO DELETE A NODE\n");
									scanf("%d",&num);
									bdelete(num);
									break;
							case 4:
									ldelete();
									break;
							case 5:
									printf("WHICH ELEMENT CONTAIN NODE YOU WANT TO DELETE:\n");
									scanf("%d",&num);
									edelete(num);
									break;
							case 6:
									printf("THANK YOU FOR USING DELETE OPERETION");
									flag=1;
									break;
						}
						getch();
						if(flag==1)
							break;
					}
					break;
			case 3:
					printf("WHICH ELEMENT YOU WANT TO SEARCH ?");
					scanf("%d",&num);
					search(num);
					break;
			case 4:
					num=count();
					printf("AT PRESENT LINKLIST CONTAIN %d NODES\n",num);
					break;

			case 5:
					fdisplay();
					break;
			case 6:
					rdisplay();
					break;
			case 7:
					printf("\n\nTHANK YOU FOR USING THIS PROGRAM\n");
					getch();
					exit(0);
		}
		getch();
	}
}
Ejemplo n.º 15
0
static void define_handle(state_t* state, match_t* match, bool* reprocess)
{
    // We need to parse this manually because we're interested in getting
    // the first word and then all of the content until a line that doesn't end
    // with "\".
    bstring name = bfromcstr("");
    bstring word = bfromcstr("");
    bstring definition = bfromcstr("");
    bool getting_word = true;
    bool getting_definition = true;
    bool is_macro = false;
    match_t* new_match;
    struct replace_info* info;

    // Get the first word.
    while (getting_word)
    {
        char c = ppimpl_get_input(state);
        bconchar(word, c);
        if (!is_macro && c != '(')
            bconchar(name, c);
        bltrimws(word);

        // Handle termination.
        if (blength(word) > 0 && (c == ' ' || c == '\t') && !is_macro)
        {
            // End of word.
            btrimws(word);
            btrimws(name);
            getting_word = false;
        }
        else if (blength(word) > 0 && c == '(' && !is_macro)
        {
            // Start of macro.
            is_macro = true;
        }
        else if (blength(word) > 0 && c == '(' && is_macro)
        {
            // Second ( in a macro; error.
            dhalt(ERR_PP_MACRO_MALFORMED, ppimpl_get_location(state));
        }
        else if (blength(word) > 0 && c == ')' && is_macro)
        {
            // End of macro name.
            btrimws(word);
            btrimws(name);
            getting_word = false;
        }
        else if (blength(word) == 0 && c == '\n')
            dhalt(ERR_PP_C_DEFINE_PARAMETERS_INCORRECT, ppimpl_get_location(state));
        else if (blength(word) > 0 && c == '\n')
        {
            // End of word.
            btrimws(word);
            btrimws(name);
            getting_word = false;
            getting_definition = false;
            ppimpl_printf(state, "\n");
        }
    }

    // Get the definition.
    while (getting_definition)
    {
        char c = ppimpl_get_input(state);
        bconchar(definition, c);
        bltrimws(definition);
        
        if (c == '\n')
        {
            if (blength(definition) > 1 && definition->data[blength(definition) - 2] == '\\')
            {
                // Remove the new slash.
                bdelete(definition, blength(definition) - 2, 1);
                ppimpl_oprintf(state, "\n");
            }
            else
            {
                btrimws(definition);
                getting_definition = false;
                ppimpl_printf(state, "\n");
            }
        }
        else if (c == '/' || c == '*')
        {
            if (blength(definition) > 1 && definition->data[blength(definition) - 2] == '/')
            {
                // a line or block comment
                ppimpl_iprintf(state, "/%c", c);
                // remove the slashes
                bdelete(definition, blength(definition) - 2, 2);
                btrimws(definition);
                getting_definition = false;
            }
        }
    }
    
    if (blength(definition) == 0 && !is_macro)
        bassigncstr(definition, "1");
        

    // Create the new replacement handler.
    info = malloc(sizeof(struct replace_info));
    info->full = word;
    info->replacement = definition;
    if (biseq(info->full, info->replacement))
    {
        free(info);
        return;
    }
    new_match = malloc(sizeof(match_t));
    new_match->text = bautofree(name);
    if (is_macro)
        new_match->handler = macro_handle;
    else
        new_match->handler = replace_handle;
    new_match->line_start_only = false;
    new_match->identifier_only = true;
    new_match->userdata = info;
    new_match->case_insensitive = false;
    ppimpl_register(state, new_match);
    *reprocess = true;
}