Example #1
0
int dos_char_to_printable(char **p, unsigned char c)
{
    char in[1] = { c };
    char *pin = in;
    size_t bytes_in = 1;
    size_t bytes_out = 4;
    if (!init_conversion(-1))
	return 0;
    return iconv(dos_to_local, &pin, &bytes_in, p, &bytes_out) != -1;
}
Example #2
0
void TalkRes::player_reply(int talkMsgRecno)
{
	//------- set the reply choices --------//

	err_when( is_talk_msg_deleted(talkMsgRecno) );

	TalkMsg* talkMsg = get_talk_msg(talkMsgRecno);

	if( nation_array.is_deleted(talkMsg->from_nation_recno) )
		return;

	init_conversion(talkMsg->from_nation_recno);

	talk_choice_count    = 0;
	cur_choice_id 		   = 0;
	reply_talk_msg_recno = talkMsgRecno;

	//--------- add talk choices ---------//

	static String msgStr, msgStr2;

	msgStr = talkMsg->msg_str(nation_array.player_recno);		// make a static copy of it.
	choice_question = msgStr;

	//---- see if this message has a second line -----//

	msgStr2 = talkMsg->msg_str(nation_array.player_recno, 0, 1);		// 1-display the second line of the question

	if( msgStr!=msgStr2 )
		choice_question_second_line = msgStr2;
	else
		choice_question_second_line = NULL;

	//--------- add choices to the question ---------//

	if( talkMsg->can_accept() )			// whether the replier can accept the request or demand of the message
		add_talk_choice( text_talk.str_accept_(), 1 ); // "Accept.", 1 );

	add_talk_choice( text_talk.str_reject_(), 0 ); // "Reject.", 0 );

	//--- switch to the nation report mode and go to the diplomacy mode ---//

	info.init_player_reply( talkMsg->from_nation_recno );

	save_view_mode = sys.view_mode;

	sys.set_view_mode(MODE_NATION);
}
Example #3
0
int local_string_to_dos_string(char *out, char *in, unsigned int out_size)
{
    char *pin = in;
    char *pout = out;
    size_t bytes_in = strlen(in);
    size_t bytes_out = out_size-1;
    size_t ret;
    if (!init_conversion(-1))
        return 0;
    ret = iconv(local_to_dos, &pin, &bytes_in, &pout, &bytes_out);
    if (ret == (size_t)-1) {
        fprintf(stderr, "Cannot convert input sequence '\\x%.02hhX' from codeset '%s' to 'CP%d': %s\n",
                *pin, nl_langinfo(CODESET), used_codepage, strerror(errno));
        return 0;
    }
    if (bytes_in != 0) {
        fprintf(stderr, "Cannot convert input string '%s' to 'CP%d': String is too long\n",
                in, used_codepage);
        return 0;
    }
    out[out_size-1-bytes_out] = 0;
    return 1;
}
static dnnError_t simple_net(int want_groups_conv)
{
    dnnError_t err;
    size_t outputSize[dimension] = {(N - K_X + 2 * P_X) / S_X + 1, (N - K_Y + 2 * P_Y) / S_Y + 1, FIn, BATCH_SIZE};
    size_t outputStrides[dimension] = {1, (N - K_X + 2 * P_X) / S_X + 1,
                                       ((N - K_X + 2 * P_X) / S_X + 1) * ((N - K_Y + 2 * P_Y) / S_Y + 1),
                                       ((N - K_X + 2 * P_X) / S_X + 1) * ((N - K_Y + 2 * P_Y) / S_Y + 1) * FIn};

    size_t inputSize[dimension] = {N, N, FIn, BATCH_SIZE};
    size_t inputStrides[dimension] = {1, N, N * N, N * N * FIn};

    int inputOffset[dimension - 2] = {-P_X, -P_Y};

    dnnLayout_t lt_user_input = NULL,
                lt_user_output = NULL;
    dnnPrimitive_t cv_user_to_pool1_input = NULL;
    size_t kernelSize[2] = {K_X, K_Y};
    size_t kernelStride[2] = {S_X, S_Y};
    dnnLayout_t lt_pool1_input = NULL;
    dnnPrimitive_t pool1 = NULL;
    void *resPool1[dnnResourceNumber] = {0};
    dnnLayout_t lt_pool1_output = NULL,
                lt_pool1_workspace = NULL;
    dnnPrimitive_t cv_pool1_to_user_output = NULL;
    dnnPrimitiveAttributes_t attributes = NULL;

    double *user_i = NULL,
           *user_o = NULL;

    /*** data allocation ***/
    user_i = (double *)malloc(sizeof(double) * (inputSize[0] * inputSize[1] * inputSize[2] * inputSize[3]));

    if (user_i == NULL)
    {
        err = E_MEMORY_ERROR;
        goto bail_out;
    }

    /*** User's data description ***/
    CHECK_ERR(dnnLayoutCreate_F64(&lt_user_input, dimension, inputSize, inputStrides), err);
    CHECK_ERR(dnnLayoutCreate_F64(&lt_user_output, dimension, outputSize, outputStrides), err);

    /* Initialize attributes */
    CHECK_ERR(dnnPrimitiveAttributesCreate_F64(&attributes), err);

    /*** Pooling section ***/
    CHECK_ERR(dnnPoolingCreateForward_F64(&pool1, attributes, dnnAlgorithmPoolingMax,
                                          lt_user_input, kernelSize, kernelStride, inputOffset, dnnBorderZeros),
              err);

    CHECK_ERR(dnnLayoutCreateFromPrimitive_F64(&lt_pool1_input, pool1, dnnResourceSrc), err);
    CHECK_ERR(dnnLayoutCreateFromPrimitive_F64(&lt_pool1_output, pool1, dnnResourceDst), err);
    CHECK_ERR(dnnLayoutCreateFromPrimitive_F64(&lt_pool1_workspace, pool1, dnnResourceWorkspace), err);
    CHECK_ERR(init_conversion(&cv_user_to_pool1_input, &resPool1[dnnResourceSrc], lt_pool1_input, lt_user_input, user_i), err);

    CHECK_ERR(dnnAllocateBuffer_F64(&resPool1[dnnResourceDst], lt_pool1_output), err);
    CHECK_ERR(dnnAllocateBuffer_F64(&resPool1[dnnResourceWorkspace], lt_pool1_workspace), err);

    CHECK_ERR(init_conversion(&cv_pool1_to_user_output, &user_o, lt_user_output, lt_pool1_output, resPool1[dnnResourceDst]), err);

    srand(1);
    for (int i = 0; i < inputSize[0] * inputSize[1] * inputSize[2] * inputSize[3]; i++)
        user_i[i] = rand() % 10;

    /*** Execution ***/

    if (cv_user_to_pool1_input)
        CHECK_ERR(dnnConversionExecute_F64(cv_user_to_pool1_input, user_i, resPool1[dnnResourceSrc]), err);

    double times[NB_TESTS];
    clock_t start, end;
    for (int i = 0; i < NB_TESTS; i++)
    {
        start = clock();
        CHECK_ERR(dnnExecute_F64(pool1, (void *)resPool1), err);
        end = clock();
        double time_taken = ((double)(end - start) / CLOCKS_PER_SEC) * 1000;
        times[i] = time_taken;
    }
    printf("Pool time: %f.\n", median(NB_TESTS, times));

    if (cv_pool1_to_user_output)
        CHECK_ERR(dnnConversionExecute_F64(cv_pool1_to_user_output, resPool1[dnnResourceDst], user_o), err);
    FILE *f = fopen("mkl_result.txt", "w");
    if (f == NULL)
    {
        printf("Error opening file!\n");
        exit(1);
    }
    for (int n = 0; n < BATCH_SIZE; ++n)
        for (int z = 0; z < FIn; ++z)
            for (int y = 0; y < outputSize[1]; ++y)
                for (int x = 0; x < outputSize[0]; ++x)
                    fprintf(f, "%.0f", user_o[x + y * outputSize[0] + z * outputSize[0] * outputSize[1] + n * outputSize[0] * outputSize[1] * FIn]);

    fclose(f);

bail_out:

    dnnDelete_F64(pool1);
    dnnDelete_F64(cv_user_to_pool1_input);
    dnnDelete_F64(cv_pool1_to_user_output);
    dnnLayoutDelete_F64(lt_user_input);
    dnnLayoutDelete_F64(lt_user_output);
    dnnLayoutDelete_F64(lt_pool1_input);
    dnnLayoutDelete_F64(lt_pool1_output);
    dnnLayoutDelete_F64(lt_pool1_workspace);
    dnnPrimitiveAttributesDestroy_F64(attributes);
    dnnReleaseBuffer_F64(resPool1[dnnResourceDst]);
    dnnReleaseBuffer_F64(resPool1[dnnResourceWorkspace]);
    if ((void *)user_o != resPool1[dnnResourceDst])
        dnnReleaseBuffer_F64((void *)user_o);

    free(user_i);

    return err;
}
Example #5
0
int set_dos_codepage(int codepage)
{
    return init_conversion(codepage);
}
Example #6
0
//------- Begin of function TalkRes::detect_talk --------//
//
int TalkRes::detect_talk()
{
	//----- if the message which player is reply is deleted (this can only happen when the player stays on the reply message screen for almost 1 year without doing anything and then the message is automatically deleted after having being kept for 1 year ---//

	if( reply_talk_msg_recno &&
		 is_talk_msg_deleted(reply_talk_msg_recno) )		// the message may become invalid during the replying period
	{
		sys.set_view_mode(save_view_mode);

		if( save_view_mode == MODE_NATION )
		{
			cur_talk_msg.talk_id = 0;
			init_conversion(cur_talk_msg.to_nation_recno);
		}

		return 0;
	}

	//------------------------------------------//

	int choiceId = detect_talk_choices();

	if( !choiceId )
		return 0;

	int choicePara  = talk_choice_array[choiceId-1].para;
	int choicePara2 = talk_choice_array[choiceId-1].para2;

	//---- if the player is replying message from other nation ----//

	if( reply_talk_msg_recno )
	{
		if( !is_talk_msg_deleted(reply_talk_msg_recno) )		// the message may become invalid during the replying period
		{
			if( choicePara==1 )
				reply_talk_msg(reply_talk_msg_recno, REPLY_ACCEPT, COMMAND_PLAYER);
			else
				reply_talk_msg(reply_talk_msg_recno, REPLY_REJECT, COMMAND_PLAYER);
		}

		sys.set_view_mode(save_view_mode);

		if( save_view_mode == MODE_NATION )
		{
			cur_talk_msg.talk_id = 0;
			init_conversion(cur_talk_msg.to_nation_recno);
		}

		return 1;
	}

	//---------------------------------------//

	// if( strcmp( talk_choice_array[choiceId-1].str, "Cancel." ) == 0 ||
	if( strcmp( talk_choice_array[choiceId-1].str, text_talk.str_cancel_() ) == 0 ||
		 (choice_question && strcmp( choice_question, MESSAGE_SENT_STR )==0) )
	{
		cur_talk_msg.talk_id = 0;
		init_conversion(cur_talk_msg.to_nation_recno);
		return 1;
	}

	//------ set the current choice to cur_talk_msg -------//

	if( cur_talk_msg.talk_id == 0 )
	{
		cur_talk_msg.talk_id = choicePara;
		tutor.detect_talk_message_id = choicePara;
	}
	else if( cur_talk_msg.talk_para1 == 0 )
	{
		cur_talk_msg.talk_para1 = choicePara;
		cur_talk_msg.talk_para3 = choicePara2;		// if the talk is Exchange Tech, choicePara2 is the version
	}
	else if( cur_talk_msg.talk_para2 == 0 )
	{
		cur_talk_msg.talk_para2 = choicePara;
		cur_talk_msg.talk_para4 = choicePara2;
	}
	else
		err_here();

	//------ prepare the next available choices ------//

	if( !set_talk_choices() )		// the talk is complete
	{
		send_talk_msg( &cur_talk_msg, COMMAND_PLAYER );

		//--- the message has been sent, display notification message ---//

		choice_question = MESSAGE_SENT_STR;
		choice_question_second_line = NULL;

		talk_choice_count = 0;
		add_talk_choice( text_talk.str_continue(), 0 ); //"Continue", 0 );
	}

	return 1;
}