⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stdiol.c

📁 ISO 8583 with c++ for financial transaction standard
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * IT24 ASAP S.L.
 * Standard I/O Library Extension (STDIOL)
 *
 * Tarea		Fecha			Autor	Observaciones
 * (Inicial)	1998.06.30		mdc		Base: numnzpad()
 * (Inicial)	1998.11.19		mdc		Base: day_of_year()
 * (Inicial)	1999.01.12		mdc		Base: antoi()
 * (Inicial)	1999.03.22		mdc		Base: hexcharbinary() e inversa, desde Crypto Library.
 * (Inicial)	1999.04.07		mdc		hexcharbinary() e inversa, corregidas para DES, Intel x86.
 * (Inicial)	1999.04.09		mdc		_LITTLE_ENDIAN_BIT_ o _BIG_ENDIAN_BIT_
 * (Inicial)	1999.04.21		mdc		long antol(char *pchAsciiNum, int iLen);
 * (Inicial)	1999.06.30		mdc		open_file,close_file
 * (Inicial)	1999.07.07		mdc		ftp_send_file(...)
 * (Inicial)	1999.07.13		mdc		DoFileTransfering() acepta hosts opcionales, y
 *										            chequear si es Guardian-Tandem el FileSystem de destino.
 * (Alfa)   	1999.09.23		mdc		DoFileTransfering() acepta booleano de reemplazo de "."
 * (Alfa)   	1999.09.29		mdc		Agregada move_file();
 * (Alfa)   	1999.10.06		mdc		Excepciones x FIID en file-tranfer-protocol.
 * (Alfa)   	1999.11.09		mdc		DoFileTransfering agrega notificacion a usuario ante fallos
 * 				    1999.11.15		GDG		open_file con append, solo p/iAccessMode 1(write)
 * 				    1999.11.15		MDC		Ajuste en condicion de terminacion de lectura por CRLF
 * (Alfa)     1999.11.16    mdc   get_file_size();
 * (Alfa)     2000.01.06    mdc   Asumir FIID no formateable en path si no hay mascara, en UNIX-Style.
 * (Alfa)   	2000.01.19		mdc		ftp_api_send_file() como alternativa a ftp_send_file().
 * (Alfa)   	2000.02.03		mdc		DoFileTransfering_Ext()
 * (Alfa)   	2000.02.09		mdc		DoFileTransfering() mapea a DoFileTransfering_Ext().
 * (Alfa)   	2000.02.21		mdc		hexcharbinary() tambien acepta minusculas en hexadecimal
 * (Alfa)   	2000.03.06    mdc   Agregado host "MLINKRPT".
 * (Beta)   	2002.03.27    mdc   double EXPORT_ATTR antofix(char *pchAsciiNum, int iLen)
 * (Beta)   	2003.01.21    mdc   short EXPORT_ATTR  strnumlen( char *pszValue , const short nMax )
*/ 

/* ANSI C/C++ Standard Library functions */
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <time.h> 
#include <errno.h>
#include <math.h>
/* Header propio */
#include <qusrinc/stdiol.h>
/* Header de aliases */
#include <qusrinc/alias.h>
/* Header de tipos de datos */
#include <qusrinc/typedefs.h>


/********************************************************************************/
/* Macro de control de uso de API de FTP en vez de comando al Sistema Operativo */
#define	_USE_FTP_API_

/* Macro de Longitud de buffer de mensajes predefinida */
#define MSG_DEFAULT_LEN   3072
/* Longitud default de FIID como string */
#define FIID_DEFAULT_LEN  4
/*******************************************************************************/


/********************************************************************************
 * Prototipos de funciones locales a este modulo unicamente 
 ********************************************************************************/
int check_ftp_logger(char *szLoggerText, boolean_t bIsFilename,
					 char *szHost, char *szFileFrom, char *szFileTo);
int PrintFile(const char *lpszFileName);
           
/********************************************************************************
 * Number-no-Zero-Padded:
 * (Cadena Numerica no precedida de Ceros)
 * Input: Puntero a Caracter y Longitud de Cadena de Caracteres Numericos.
 * Output: Cantidad de caracteres '0' reemplazados por ' ' en la Cadena Numerica.
 *
 *******************************************************************************/
size_t EXPORT_ATTR numnzpad(char *lpszData, size_t nLimit)
	{
	/* Contador de ceros '0' hasta el fin del string o nCount */
	size_t    nZeroes,
		        nCount;
	boolean_t bSign;
	char      chSign = '+';

	/* Precondicion: Puntero y limites validos */
	if((lpszData == NULL) && (nLimit > 0))
		return (-1);

	/* Ciclo de reemplazo de ceros '0' x blancos, y verificacion de negativo */
	for (nCount = 0,
		 nZeroes = 0,
		 bSign = is_false;

		 /* Condicion mientras... */
		 (nCount < nLimit) &&
		 (nZeroes < nLimit) &&
		 ((*lpszData) == '0' || (*lpszData) == ' ' ||
		  (*lpszData) == '-' || (*lpszData) == '+' || (*lpszData) == 0);

		 /* Incremento de indexadores */
		 lpszData++,
		 nCount++)
	     if((*lpszData) == '0')
			{
			/* Reemplazo del cero ('0') x blanco (' ') */
			(*lpszData) = ' ';
			/* Contador de ceros reemplazados */
			nZeroes++;
			}
		 else if ((*lpszData) == '-')
			{
			/* Reemplazo del negativo ('-') x blanco (' ') */
			(*lpszData) = ' ';
			/* TRUE al booleano del signo reemplazado */
			bSign  = is_true;
			chSign = '-';
			}
		 else if ((*lpszData) == '+')
			{
			/* Reemplazo del positivo ('+') x blanco (' ') */
			(*lpszData) = ' ';
			/* TRUE al booleano del signo reemplazado */
			bSign  = is_true;
			chSign = '+';
			};/*end-if-and-end-for */

	/* A la salida, (*lpszData) es un caracter distinto de '0',' ','-' y '+'... */
	/* y en el caracter anterior debe ir el signo, si es que fue reemplazado... */
	if(bSign)
		 if(*(--lpszData) == ' ')
			 (*lpszData) = chSign;

	/* Retorna los ceros ('0') reemplazados */
	return (nZeroes);
  } /*end-numnzpad */

/*******************************************************************************
* day_of_year
* (dia del ano)
* Input  : Puntero a Caracter y Longitud de Cadena de Caracteres Numericos.
* Output : Cantidad de caracteres del dia juliano en el ano
* Return : Day-Of-Year
* (ANSI C-UNIX compliant version)
*******************************************************************************/
size_t EXPORT_ATTR day_of_year(	char *pchInput , size_t nInSize ,
							char *pchOutput, size_t nOutSize,
							int   bStrWithZero )
	{
	struct tm	tmDOY;        /* Day-Of-Year */
	time_t		tiTime;       /* Time of day */
	char        chBuffer[10]; /* Temporary conversion buffer */

	tmDOY.tm_sec   = 0; /* Seconds after minute (0 - 59) */
	tmDOY.tm_min   = 0; /* Minutes after hour (0 - 59) */
	tmDOY.tm_hour  = 0; /* Hours since midnight (0 - 23) */
	tmDOY.tm_mday  = 0; /* Day of month (1 - 31) */
	tmDOY.tm_mon   = 0; /* Month (0 - 11; January = 0) */
	tmDOY.tm_year  = 0; /* Year (current year minus 1900) */
	tmDOY.tm_wday  = 0; /* Day of week (0 - 6; Sunday = 0) */
	tmDOY.tm_yday  = 0; /* Day of year (0 - 365; January 1 = 0) */
	tmDOY.tm_isdst = 0; /* Always 0 for gmtime */

	/* Convert from ASCII time string */
	/* Assume ISO YYYYMMDD format? */
	if(nInSize == 8)
	{
		strncpy(chBuffer, pchInput, 4);
		chBuffer[4] = 0x00;
		tmDOY.tm_year = atoi(chBuffer) - 1900;
		strncpy(chBuffer, pchInput+4, 2);
		chBuffer[2] = 0x00;
		tmDOY.tm_mon = atoi(chBuffer) - 1;
		strncpy(chBuffer, pchInput+6, 2);
		chBuffer[2] = 0x00;
		tmDOY.tm_mday = atoi(chBuffer);
	}
	/* Assume ISO YYMMDD format? */
	else if(nInSize == 6)
	{
		strncpy(chBuffer, pchInput, 2);
		chBuffer[2] = 0x00;
		tmDOY.tm_year = atoi(chBuffer);
		/* begin-Y2K-fix : assume 75 as the base year */
		if( tmDOY.tm_year <= 75)
			tmDOY.tm_year += 100;
		/* end-Y2K-fix */
		strncpy(chBuffer, pchInput+2, 2);
		chBuffer[2] = 0x00;
		tmDOY.tm_mon = atoi(chBuffer) - 1;
		strncpy(chBuffer, pchInput+4, 2);
		chBuffer[2] = 0x00;
		tmDOY.tm_mday = atoi(chBuffer);
	}
	else
		return (0);

	/* Make time */
	tiTime = mktime( &tmDOY );
	if(tiTime == (time_t)(-1))
		return (0);

	/* Day of year (0 - 365; January 1 = 0) */
	tmDOY.tm_yday++;

	/* Convert to ASCII time string */
	/* checking parameters and string-ended-with-zero */
	if(pchOutput && nOutSize > 0)
		if(bStrWithZero && pchOutput && nOutSize > 0)
			sprintf(pchOutput,"%0*i", min(sizeof(chBuffer), nOutSize), tmDOY.tm_yday);
		else
			{
			sprintf(chBuffer,"%i", tmDOY.tm_yday);
			strncpy(pchOutput, chBuffer, min(sizeof(chBuffer), nOutSize));
			}
	else
		/* Return DOY */
		return ( tmDOY.tm_yday );

	/* Return DOY */
	return ( tmDOY.tm_yday );

	} /*end-day_of_year */

/********************************************************************
* ascii-n-to-integer
* Input: Puntero a Caracter y Longitud de Cadena de Caracteres Numericos.
* Output : Numero binario convertido
* Return : Numero binario convertido
********************************************************************/
int EXPORT_ATTR antoi(char *pchAsciiNum, int iLen)
{
	char szNumber[32];
	/* Precondicion */
	if(iLen >= (sizeof(szNumber)-1))
		return -1;
	/* Copia interna */
	strncpy(szNumber, pchAsciiNum, iLen);
	szNumber[iLen] = 0x00;
	/* Retorno estandard */
	return atoi(szNumber);
}

/********************************************************************
* ascii-n-to-long-integer
* Input: Puntero a Caracter y Longitud de Cadena de Caracteres Numericos.
* Output : Numero binario convertido
* Return : Numero binario convertido
********************************************************************/
long EXPORT_ATTR antol(char *pchAsciiNum, int iLen)
{
	char szNumber[32];
	/* Precondicion */
	if(iLen >= (sizeof(szNumber)-1))
		return -1;
	/* Copia interna */
	strncpy(szNumber, pchAsciiNum, iLen);
	szNumber[iLen] = 0x00;
	/* Retorno estandard */
	return atol(szNumber);
}

/********************************************************************
* ascii-n-to-fixed-integer
* Input: Puntero a Caracter y Longitud de Cadena de Caracteres Numericos.
* Output : Numero binario convertido
* Return : Numero binario convertido
********************************************************************/
FIXEDINTEGER EXPORT_ATTR antofix(char *pchAsciiNum, int iLen)
{
	char szNumber[64];
	/* Precondicion */
	if(iLen >= (sizeof(szNumber)-1))
		return -1;
	/* Copia interna */
	strncpy(szNumber, pchAsciiNum, iLen);
	szNumber[iLen] = 0x00;
	/* Retorno propietario */
	return atofix(szNumber);
}

/********************************************************************
* ascii-n-to-float / double
* Input: Puntero a Caracter y Longitud de Cadena de Caracteres Numericos.
* Output : Numero binario convertido (FLOAT / DOUBLE)
* Return : Numero binario convertido (FLOAT / DOUBLE)
********************************************************************/
double EXPORT_ATTR antof(char *pchAsciiNum, int iLen, int iDecPlaces)
{
	char szNumber[64];
	/* Precondicion */
	if(iLen >= (sizeof(szNumber)-1) || iDecPlaces < 0 || iDecPlaces > iLen)
		return -1;
	/* Punto decimal forzado ? */
	if(iDecPlaces > 0 && iDecPlaces < iLen)
		sprintf(szNumber,"%*.*s.%*.*s", iLen-iDecPlaces,iLen-iDecPlaces,
										pchAsciiNum,
										iDecPlaces,iDecPlaces,
										pchAsciiNum + (iLen-iDecPlaces));
	else /* O copia directa ? */
	{
		strncpy(szNumber, pchAsciiNum, iLen);
		szNumber[iLen] = 0x00;
	}
	/* Retorno propietario */
	return atof(szNumber);
}

/********************************************************************
* de hexa a binario
* short *: buffer binario
* char * : buffer hexadecimal
* int    : longitud de buffer hexadecimal
*******************************************************************/
int EXPORT_ATTR hexcharbinary(short *dst_bin, char *src, int len)
{
	int		i, j, n;
	char	c;
	char    *dst = (char *)dst_bin;

	if(len < 0 || (len % 2) != 0 )
		return (0);

	for (i = 0; i < len/2; i++)
		{
		n = 0;
		for (j = 0; j < 2; j++)
			{
			n <<= 4;
			c = *(src + 2 * i + j);
			if (c >= '0' && c <= '9')
				n |= c - '0';
			/************************************************************/
			/* Acepta tambien minusculas en hexadecimal, 2000.02.21,mdc */
			else if (c >= 'A' && c <= 'F')
				n |= c - 'A' + 10;
			else if (c >= 'a' && c <= 'f')
				n |= c - 'a' + 10;
			/************************************************************/
			else
				return (0);
			};
		*(dst + i) = n;
		};

	return (len);
}

/**************************************************************************/
/* Segun sea _LITTLE_ENDIAN_BIT_ o _BIG_ENDIAN_BIT_, deben compilarse     */
/* distintos procedimientos de conversion Hexadecimal a Binario e inversa */
/* Little-endian para Intel x86 y similares                               */
/* Big-endian para Motorola, Alpha, MIPS y similares                      */
#define	_LITTLE_ENDIAN_BIT_
/**************************************************************************/

/********************************/
#if defined( _LITTLE_ENDIAN_BIT_ )
/********************************/

/*******************************************************************
* de binario a hexa
* char * : buffer hexadecimal
* int    : longitud de buffer hexadecimal
* short *: buffer binario
*******************************************************************/
int EXPORT_ATTR binaryhexchar(char *dst, int len, short *src_bin)
{
	int		i, j, n;
	char	c;
	char    *src = (char *)src_bin;

	if(len < 0 || (len % 2) != 0 )
		return (0);

	j = 0;
	for (i = 0; i < len/2; i++)
		{
		c = *(src + i);

		n = (c >> 4) & 0x0F;
		n += (n < 10) ? '0' : 'A' - 10;
		*(dst + j) = n;
		j++;

		n = c & 0x0F;
		n += (n < 10) ? '0' : 'A' - 10;
		*(dst + j) = n;
		j++;
		};

	return (len);
}

/*******************************************************************
* de binario a hexa decimalizado
* char * : buffer hexadecimal
* int    : longitud de buffer hexadecimal
* short *: buffer binario
* short  : opcion de reemplazo de 0-9 (0), solo A-B (1) o ambos (3)
* short  : inicio de reemplazo en posicion indicada
*******************************************************************/
int EXPORT_ATTR binaryhexchardec(char *dst, int len, short *src_bin, short option, short start)
{
	int		i, j, n;
	char	c;
	char    *src = (char *)src_bin;

	if(len < 0 || (len % 2) != 0 || start < 0)
		return (0);

	j = start;
	for (i = 0; i < len/2; i++)
		{
		c = *(src + i);

		n = (c >> 4) & 0x0F;
		if((option == 0) && (n<10))
			{
			n += '0';
			*(dst + j) = n;
			j++;
			}
		else if((option == 1) && (n>10))
			{
			n += '0' - 10;
			*(dst + j) = n;
			j++;
			}
		else if(option == 3)
			{
			n += (n < 10) ? '0' : '0' - 10;
			*(dst + j) = n;
			j++;
			}

		n = c & 0x0F;
		if((option == 0) && (n<10))
			{
			n += '0';
			*(dst + j) = n;
			j++;
			}
		else if((option == 1) && (n>10))
			{
			n += '0' - 10;
			*(dst + j) = n;
			j++;
			}
		else if(option == 3)
			{
			n += (n < 10) ? '0' : '0' - 10;
			*(dst + j) = n;
			j++;
			}
		};

	return (j);
}


/*****************************/
#else /* _LITTLE_ENDIAN_BIT_ */
/*****************************/


/********************************************************************************/
/* Estructuras de mapeo de campos para tomar de a 4 bits un entero              */
/********************************************************************************/

/* ANSI-C Standard Bit-datatype Alignement (16 bits integer) */
typedef unsigned short bit_basetype;

⌨️ 快捷键说明

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