Exemple #1
0
void myStrcat(char *first, char *second){

    while(*first){
        first ++;
    }

    myStrcpy(first, second);
}
Exemple #2
0
void tests()
{
	char a[] = {"String."};
	printf("%d\n", myStrlen(a));

	char b[20] = {0};
	myStrcpy(b, a);
	printf("%s\n", b);

	char c[20] = {0};
	myStrcpy(c, a);
	myStrcat(c, b);
	printf("%s\n", c);

	printf("%d\n", myStrcmp(a, b));
	printf("%d\n", myStrcmp(b, c));
}
int main()
{
	char* myString2;
	myString2 = (char*) malloc(20*sizeof(char));
	myString2 = myStrcpy(myString2, myString);
	printf("myString:%s \n",myString);
	printf("myString2:%s \n",myString2);
	myString2 = strI
	printf("myString2:%s \n",myString2);
	return 0;
}
Exemple #4
0
void test_cpy_nte()
{
	clear_all();
	//copy non-empty string to empty
	int n=12;
	a[0]='\0';
	b[0]='1';
	int f = myStrcpy(a,b,n);
	assert(strlen(a)==1);
	assert(f == 0);
	//accepted
}
Exemple #5
0
void test_cpy_over()
{
	clear_all();
	//copy a long string to a smaller one
	int n=70;
	strcpy(e,"ajajajajaj");
	strcpy(d,"1234567890123456789012345678901234567890123456789012345678901234567890aaaaaaaaaaa");
	int f=myStrcpy(e,d,n);
	assert(f==-1);
	assert(strlen(e)==10);
	//accepted
}
Exemple #6
0
void test_cpy_etn()
{
	clear_all();
	//copy empty string to non-empty
	int n=12;
	a[0]='\0';
	b[0]='1';
	int f=myStrcpy(b,a,n);
	assert(strlen(b)==0);
	assert(f==0);
	//accepted
}
Exemple #7
0
void test_cpy_empty()
{
	clear_all();
	//empty string to empty string with n>0
	int n=12;
	a[0]='\0';
	b[0]='\0';
	int f=myStrcpy(a,b,n);
	assert(strlen(a)==strlen(b));
	assert(strlen(a)==0);
	assert(f==0);
	//accepted
}
int main(){
  char stra[50] = {0};
  char strb[50] = {0};
  char strc[50] = {0};
  sprintf(stra,"bbeeffABABcdfe");
  sprintf(strb,"AB");
  sprintf(strc,"ab");
  const char * str;
  //strstr
  if(NULL != (str = myStrstr(stra,strb))){
	printf("The str of %s in %s is %s\n",strb,stra,str);
  }else{
	printf("The %s is not in %s\n",strb,stra);
  }
  if(NULL != (str = myStrstr(stra,strc))){
	printf("The str of %s in %s is %s\n",strc,stra,str);
  }else{
	printf("The %s is not in %s\n",strc,stra);
  }

  //firstSingleChar
  printf("The firstSingleChar of %s is %c\n",stra,firstSingleChar(stra));

  //myStrcpy
  printf("The copy of %s is %s\n",stra,myStrcpy(strb,stra));

  //myStrtok
  char strd[] = "now # is the time for all # good men to come to the # aid of their country";
  char delims[] = "#";
  char *result = NULL;
  result = myStrtok( strd, delims );
  while( result != NULL ) {
	printf( "result is \"%s\"\n", result );
	result = myStrtok( NULL, delims );
  }
  printf("After myStrtok the str is %s \n",strd);
  char stre[] = "abcdefghijklmn";
  printf("Before the str is %s \n",stre);
  myMemmove(stre,stre + 3,8);
  printf("After memmove the str is %s \n",stre);
  return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
	int c[10] = { 1,2,3,4,5,6,7,8,9,10 };
	int d[10];

	myMemcpy( d, c, sizeof( int )*10 );
	outputArray( c, 10 );
	outputArray( d, 10 );

	printf( "%d\n", myMemcmp( c, d, sizeof( int )*10 ) );

	myMemmove( c, &c[2], sizeof( int )*8 );
	outputArray( c, 10 );

	myMemmove( &c[2], c, sizeof( int )*8 );
	outputArray( c, 10 );

	myMemset( d, 0, sizeof( int )*10 );
	outputArray( d, 10 );

	char a[100] = "123456789";
	char b[100] = "abcdefghijklmn";

	printf( "%d\n", myStrlen( a ) );
	printf( "%d\n", myStrlen( b ) );

	printf( "%s\n", myStrcat( b, a ) );
	//printf( "%s\n", myStrcat( a, &a[2] ) );
	//printf( "%s\n", myStrcat( &a[2], a ) );
	printf( "%s\n", a );
	printf( "%d\n", myStrcmp( b, a ) );
	printf( "%s\n", myStrcpy( b, a ) );
	printf( "%s\n", myStrmove( a, &a[3] ) );
	printf( "%s\n", myStrmove( &a[4], a ) );
	printf( "%s\n", a );
	
	return 0;
}
Exemple #10
0
// WARNING mxSize is the matrixSize here
NORMAL_API DSP_STATUS helloDSP_Execute(IN Uint32 mxSize, Uint8 processorId, Uint32* matrixA, Uint32* matrixB, Uint32* matrixC)
{
	DSP_STATUS status = DSP_SOK;
	Uint16 sequenceNumber = 0;
	Uint16 msgId = 0;
	Uint32 i, j;
	ControlMsg *msg;
	Uint8 flag = 0;

	Uint32 matrixD[mxSize * mxSize];

	Uint32 numElements, numMessages, elementCount, messageCount;
	Uint32 sizeElements, numProdMessages, matrixCount, prodElements;
	Char8 ascii_string[STRING_SIZE + 1];
	Char8 null_string[STRING_SIZE + 1] = {'\0','\0','\0','\0','\0','\0'};

	myStrcpy(ascii_string, null_string);

	SYSTEM_0Print("Entered helloDSP_Execute ()\n");

	// Wait for the first DSP is awake message
	status = MSGQ_get(SampleGppMsgq, WAIT_FOREVER, (MsgqMsg *) &msg);
	if (DSP_FAILED(status))
	{
		SYSTEM_1Print("MSGQ_get () failed. Status = [0x%x]\n", status);
	}

	// TODO possibly verify the data?

	SYSTEM_1Print("Received message: %s\n", (Uint32) msg->arg1);

	SYSTEM_0Print("Generated matrices:\n");
	// Generate the matrices after the DSPLink is established
	matrixGen(mxSize, matrixA, matrixB);

	// Have to translate the Int32 matrix elements to string elements
	// or the communication protocol
	prodElements = (mxSize * mxSize);
	numElements = (mxSize * mxSize * 2);
	sizeElements = numElements * STRING_SIZE;
	numMessages = ((sizeElements - 1) / ARG_MSG) + 1;
	numProdMessages = (((sizeElements / 2) - 1) / ARG_MSG) + 1;

	//SYSTEM_2Print("NumElements: %d, NumMessages: %d\n", numElements, numMessages);

	// WARNING Sending 5 Char8 each for loop
	// Start sending the matrices to the DSP which is not waiting
	for (messageCount = 0, elementCount = 0; messageCount < numMessages; messageCount++)
	{
		// First send a message, then receive
		//for ( ; (((elementCount - (messageCount * ARG_MSG)) * STRING_SIZE) < ARG_MSG ) && elementCount < numElements; elementCount++)

#if defined (PROFILE)
		SYSTEM_GetStartTimeDspEnc();
#endif
		for (; (elementCount - (messageCount * ARG_MSG)) < ARG_MSG && elementCount < numElements; elementCount++)
		{
			//SYSTEM_0Print("Putting element in a message\n");
			//itoa
			if(elementCount < prodElements)
			{
				SYSTEM_itoa(matrixA[elementCount], ascii_string, 10);
				//SYSTEM_1Print("Looping through string: %s in MatrixA\n", (Uint32) ascii_string);
			}
			else
			{
				SYSTEM_itoa(matrixB[elementCount - prodElements], ascii_string, 10);
				//SYSTEM_1Print("Looping through string: %s in MatrixB\n", (Uint32) ascii_string);
			}
			//SYSTEM_0Print("After SYSTEM_itoa\n");

			// loop through characters of the string
			for (i = 0; i < STRING_SIZE; i++)
			{
				msg->arg1[((elementCount * STRING_SIZE) - (messageCount * ARG_MSG)) + i] = ascii_string[i];
				//SYSTEM_sprintf(msg->arg1[(elementCount - (messageCount * ARG_MSG)) + i] = ascii_string[i];
			}
			// clean the string
			myStrcpy(ascii_string, null_string);
		}

#if defined (PROFILE)
		SYSTEM_GetEndTimeDspEnc();
#endif

		//SYSTEM_0Print("Filled a single message\n");

		// After filling a single message, should send it to the DSP and wait for a reply 
		// unless it is the last one
		if (DSP_SUCCEEDED(status))
		{
			//SYSTEM_0Print("DSP succeeded after filling\n");

#if defined (PROFILE)
			SYSTEM_GetStartTimeDspMes();
#endif
			msgId = MSGQ_getMsgId(msg);
			MSGQ_setMsgId(msg, msgId);
			// TODO set the command flag of the msg to distinguish
			status = MSGQ_put(SampleDspMsgq, (MsgqMsg) msg);
			if (DSP_FAILED(status))
			{
				MSGQ_free((MsgqMsg) msg);
				SYSTEM_1Print("MSGQ_put () failed. Status = [0x%x]\n", status);
			}
#if defined (PROFILE)
			else {
				SYSTEM_GetEndTimeDspMes();
				SYSTEM_GetStartTimeDspCalc();
			}
#endif
		}

		//SYSTEM_0Print("Message send\n");

		sequenceNumber++;
		// Make sure that the sequenceNumber stays within the permitted
		// range for applications. 
		if (sequenceNumber == MSGQ_INTERNALIDSSTART)
		{
			//SYSTEM_0Print("Something with sequences\n");
			sequenceNumber = 0;
		}
		// If it is the last message, don't wait for an acknowledge
		if (messageCount + 1 < numMessages)
		{
			// Wait for a response of the DSP before sending a reply
			status = MSGQ_get(SampleGppMsgq, WAIT_FOREVER, (MsgqMsg *) &msg);
			if (DSP_FAILED(status))
			{
				SYSTEM_1Print("MSGQ_get () failed. Status = [0x%x]\n", status);
			}

			//SYSTEM_1Print("Received: %s\n", (Uint32) msg->arg1);
		}
	}

	//SYSTEM_0Print("Sending completed..\n");

	// TODO start receiving the product matrix 
	// WARNING wait and acknowledge except for last loop
	for (messageCount = 0, elementCount = 0, matrixCount = 0; messageCount < numProdMessages; messageCount++)
	{
		status = MSGQ_get(SampleGppMsgq, WAIT_FOREVER, (MsgqMsg *) &msg);

		if (messageCount == 0) {
#if defined (PROFILE)
			SYSTEM_GetEndTimeDspCalc();
#endif
			SYSTEM_0Print("\nProduct matrix on DSP:\n");
		}
		//SYSTEM_1Print("Message received: %s\n", (Uint32) msg->arg1);
		if (DSP_FAILED(status))
		{
			SYSTEM_1Print("MSGQ_get () failed. Status = [0x%x]\n", status);
		}
		// Put the received message in the matrixC
		for (; matrixCount < prodElements && (elementCount - (messageCount * ARG_MSG)) < ARG_MSG && elementCount < (prodElements * STRING_SIZE); matrixCount++, elementCount += STRING_SIZE)
		{
			// atoi
			for (i = 0; i < STRING_SIZE; i++)
			{
				ascii_string[i] = msg->arg1[elementCount + i];
			}
			ascii_string[5] = '\0';
			/*
			 if (matrixCount >= 72)
			 {
			 SYSTEM_1Print("Ascii string received: %s\n", ascii_string);
			 }
			 */
			// Put it in the matrixC
			matrixC[matrixCount] = atoi(ascii_string);
			// print the string
			if (matrixCount % mxSize == 0)
			{
				SYSTEM_0Print("\n");
			}
			SYSTEM_1Print("%d ", matrixC[matrixCount]);

			// Clean the string
			myStrcpy(ascii_string, null_string);
		}

		// If this is not the last message, send an acknowledge
		if (messageCount + 1 < numProdMessages)
		{
			// Send the same message received in earlier MSGQ_get () call. 
			if (DSP_SUCCEEDED(status))
			{
				msgId = MSGQ_getMsgId(msg);
				MSGQ_setMsgId(msg, msgId);
				status = MSGQ_put(SampleDspMsgq, (MsgqMsg) msg);
				if (DSP_FAILED(status))
				{
					MSGQ_free((MsgqMsg) msg);
					SYSTEM_1Print("MSGQ_put () failed. Status = [0x%x]\n", status);
				}
			}

			sequenceNumber++;
			// Make sure that the sequenceNumber stays within the permitted
			// range for applications. 
			if (sequenceNumber == MSGQ_INTERNALIDSSTART)
			{
				sequenceNumber = 0;
			}
		}
	}

	SYSTEM_0Print("\n");

	MSGQ_free((MsgqMsg) msg);
	//SYSTEM_0Print("After freeing the message..\n");

	SYSTEM_0Print("\nProduct matrix on GPP:\n");

#if defined (PROFILE)
	SYSTEM_GetStartTimeGpp();
#endif

	matMult(matrixA, matrixB, matrixD, mxSize);

#if defined (PROFILE)
	SYSTEM_GetEndTimeGpp();
#endif

	// compare the matrices
	for(i=0; i<mxSize; i++)
	{
		for(j=0; j<mxSize; j++)
		{
			if(matrixC[i * mxSize + j] != matrixD[i * mxSize + j])
			{
				SYSTEM_2Print("Matrices are not equal row: %d, column: %d\n", i, j);
				flag = 1;
				break;
			}
		}
	}
	if (flag == 0)
	{
		SYSTEM_0Print("\nMatrix products are equal\n");
	}

	SYSTEM_0Print("Leaving helloDSP_Execute ()\n");

#if defined (PROFILE)
	if (DSP_SUCCEEDED(status))
	{
		SYSTEM_GetProfileInfoGpp();
		SYSTEM_GetProfileInfoDsp(numMessages); //is numProdMessages interesting?
	}
#endif

	return status;
}