utilities.c

来自「在嵌入式系统中对Lattice CPLD软件升级时所需的VME文件生成所需源代码」· C语言 代码 · 共 77 行

C
77
字号
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <malloc.h>

void TrimRight( char * a_pszLine )
{
	int iIndex;

	if (!a_pszLine) {
		return;
	}

	for ( iIndex = strlen( a_pszLine ); iIndex >= 0; iIndex-- ) {
		if ( ( a_pszLine[ iIndex ] < 0x21 ) || ( a_pszLine[ iIndex ] > 0x7E ) ) {
			a_pszLine[ iIndex ] = '\0';
		}
		else {
			break;
		}
	}
}

void TrimLeft( char * a_pszLine )
{
	int iTemp;
	char * pszTempLine;

	if ( !a_pszLine ) {
		return;
	}

	pszTempLine = ( char * ) malloc( strlen( a_pszLine ) + 1 );
	strcpy( pszTempLine, a_pszLine );
	
	for ( iTemp = 0; iTemp < ( int ) strlen( a_pszLine ); iTemp++ ) {
		if ( ( a_pszLine[ iTemp ] >= 0x21 ) && ( a_pszLine[ iTemp ] <= 0x7E ) ) {
			break;
		}
	}

	strcpy( a_pszLine, pszTempLine + iTemp );
	free( pszTempLine );
	pszTempLine = NULL;
}

int stricmp( const char * a_szFirst, const char * a_szSecond )
{
	int iRetCode;
	char * pszFirst = NULL;
	char * pszSecond = NULL;

	if ( !a_szFirst || !a_szSecond ) {
		return -1;
	}

	pszFirst = ( char * ) malloc( strlen( a_szFirst ) + 1 );
	pszSecond = ( char * ) malloc( strlen( a_szSecond ) + 1 );
	
	if ( !pszFirst || !pszSecond ) {
		return -1;
	}

	strcpy( pszFirst, a_szFirst );
	strcpy( pszSecond, a_szSecond );
	strlwr( pszFirst );
	strlwr( pszSecond );

	iRetCode = strcmp( pszFirst, pszSecond );

	free( pszFirst );
	free( pszSecond );
	pszFirst = NULL;
	pszSecond = NULL;
	return ( iRetCode );
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?