Пример #1
0
int flattermarken(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Flattermarken - Not really a barcode symbology and (in my opinion) probably not much use
	but it's supported by TBarCode so it's supported by Zint! */
	int loop, error_number;
	char dest[512]; /* 90 * 4 + 1 ~ */

	error_number = 0;

	if(length > 90) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
	if(error_number == ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	*dest = '\0';
	for(loop = 0; loop < length; loop++) {
		lookup(NEON, FlatTable, source[loop], dest);
	}
	
	expand(symbol, dest);	
	return error_number;
}
Пример #2
0
int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Code 2 of 5 Industrial */

	int i, error_number;
	char dest[512]; /* 6 + 40 * 10 + 6 + 1 */

	error_number = 0;

	if(length > 45) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
	if(error_number == ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid character in data");
		return error_number;
	}

	/* start character */
	strcpy(dest, "313111");

	for(i = 0; i < length; i++) {
		lookup(NEON, C25IndustTable, source[i], dest);
	}

	/* Stop character */
	concat (dest, "31113");

	expand(symbol, dest);
	ustrcpy(symbol->text, source);
	return error_number;
}
/* Vasicek: value zero coupon bond */
extern double VasicekBondPrice(
	double t1,
	double T,
	double r,
	double Theta,
	double kappa,
	double v) 
{
	double BtT, AtT, PtT;

	assert_valid_time(T);
	assert_valid_interest_rate(r);
	assert_valid_volatility(v);

    BtT = (1 - exp(-kappa * (T - t1))) / kappa;
    AtT = exp(
		(BtT - T + t1) * (pow2(kappa) * Theta - pow2(v) / 2.0) / pow2(kappa) 
		- pow2(v) * pow2(BtT) / (4.0 * kappa)
	);

    PtT = AtT * exp(-BtT * r);

	assert(is_sane(PtT));
	return PtT;
}
Пример #4
0
int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Code 2 of 5 Standard (Code 2 of 5 Matrix) */
	
	int i, error_number;
	char dest[512]; /* 6 + 80 * 6 + 6 + 1 ~ 512*/

	error_number = 0;

	if(length > 80) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
	if(error_number == ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}

	/* start character */
	strcpy(dest, "411111");

	for(i = 0; i < length; i++) {
		lookup(NEON, C25MatrixTable, source[i], dest);
	}

	/* Stop character */
	concat (dest, "41111");

	expand(symbol, dest);
	ustrcpy(symbol->text, source);
	return error_number;
}
Пример #5
0
int planet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length)
{
	/* Handles the PLANET  system used for item tracking in the US */
    unsigned int sum, check_digit;
    int i, error_number;
	
	error_number = 0;
	
	if(length > 38) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
    if(error_number == ERROR_INVALID_DATA1) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	sum = 0;

	/* start character */
	strcpy(dest, "L");

    for (i=0; i < length; i++) {
		lookup(NEON, PLTable, source[i], dest);
		sum += ctoi(source[i]);
	}

	check_digit = (10 - (sum % 10)) % 10;
	concat(dest, PLTable[check_digit]);

	/* stop character */
	concat (dest, "L");

	return error_number;
}
Пример #6
0
/* Merton (1973) Options on stock indices, page 4. */
double merton73(
	int fCall,
	double S,
	double X,
	double T,
	double r,
	double q,
	double v) 
{
	double d1, d2, result;

	assert_valid_price(S);
	assert_valid_strike(X);
	assert_valid_time(T);
	assert_valid_interest_rate(r);
	assert_valid_volatility(v);

    d1 = (log(S / X) + (r - q + pow2(v) / 2.0) * T) / (v * sqrt(T));
    d2 = d1 - v * sqrt(T);

    if(fCall)
        result = S * exp(-q * T) * cnd(d1) - X * exp(-r * T) * cnd(d2);
    else 
        result = X * exp(-r * T) * cnd(-d2) - S * exp(-q * T) * cnd(-d1);

	assert(is_sane(result));
	return result;
}
Пример #7
0
Файл: 2of5.c Проект: ahippo/zint
int logic_two_of_five(struct zint_symbol *symbol, uint8_t source[], int length)
{ /* Code 2 of 5 Data Logic */

	int error_number;
	char dest[512]; /* 4 + 80 * 6 + 3 + 1 */

	error_number = 0;

	if(length > 80) {
		strcpy(symbol->errtxt, "Input too long");
		return ZERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
	if(error_number == ZERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}

	/* start character */
	strcpy(dest, "1111");

	for(int i = 0; i < length; i++) {
		lookup(NEON, C25MatrixTable, source[i], dest);
	}

	/* Stop character */
	concat (dest, "311");

	expand(symbol, dest);
	ustrcpy(symbol->text, source);
	return error_number;
}
Пример #8
0
/* Fixed exchange rate foreign equity options-- Quantos */
double Quanto(
	int fCall,
	double Ep,
	double S,
	double X,
	double T,
	double r,
	double rf,
	double q,
	double vS,
	double vE,
	double Rho) 
{
	double d1, d2, result;

	assert_valid_price(S);
	assert_valid_strike(X);
	assert_valid_time(T);
	assert_valid_interest_rate(r);


    d1 = (log(S / X) + (rf - q - Rho * vS * vE + pow2(vS) / 2.0) * T) / (vS * sqrt(T));
    d2 = d1 - vS * sqrt(T);
   
    if(fCall)
        result = Ep * (S * exp((rf - r - q - Rho * vS * vE) * T) * cnd(d1) - X * exp(-r * T) * cnd(d2));
	else 
        result = Ep * (X * exp(-r * T) * cnd(-d2) - S * exp((rf - r - q - Rho * vS * vE) * T) * cnd(-d1));
    
	assert(is_sane(result));
	return result;
}
Пример #9
0
int kix_code(struct zint_symbol *symbol, unsigned char source[], int length)
{
	/* Handles Dutch Post TNT KIX symbols */
	/* The same as RM4SCC but without check digit */
	/* Specification at http://www.tntpost.nl/zakelijk/klantenservice/downloads/kIX_code/download.aspx */
	char height_pattern[50], localstr[20];
	unsigned int loopey;
	int writer, i, h;
	int error_number; /* zeroes; */
	strcpy(height_pattern, "");

	error_number = 0;

	if(length > 18) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	to_upper(source);
	error_number = is_sane(KRSET, source, length);
	if(error_number == ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}

	/* Add leading zeroes */
	/* zeroes = 11 - length;
	memset(localstr, '0', zeroes);
	strcpy(localstr + zeroes, (char *)source);*/
	strcpy(localstr, (char *)source);

	/* Encode data */
	for (i = 0; i < 18; i++) {
		lookup(KRSET, RoyalTable, localstr[i], height_pattern);
	}

	writer = 0;
	h = strlen(height_pattern);
	for(loopey = 0; loopey < h; loopey++)
	{
		if((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0'))
		{
			set_module(symbol, 0, writer);
		}
		set_module(symbol, 1, writer);
		if((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0'))
		{
			set_module(symbol, 2, writer);
		}
		writer += 2;
	}

	symbol->row_height[0] = 3;
	symbol->row_height[1] = 2;
	symbol->row_height[2] = 3;
	symbol->rows = 3;
	symbol->width = writer - 1;

	return error_number;
}
Пример #10
0
static double sign(double d)
{
	assert(is_sane(d));

	if(d < +0.0)
		return -1.0;
	else
		return 1.0;
}
Пример #11
0
Файл: 2of5.c Проект: ahippo/zint
int interleaved_two_of_five(struct zint_symbol *symbol, uint8_t source[], int length)
{ /* Code 2 of 5 Interleaved */

	int error_number;
	char bars[7], spaces[7], mixed[14], dest[1000];
	uint8_t temp[length + 2];

	error_number = 0;

	if(length > 89) {
		strcpy(symbol->errtxt, "Input too long");
		return ZERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
	if (error_number == ZERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}

	ustrcpy(temp, (uint8_t *) "");
	/* Input must be an even number of characters for Interlaced 2 of 5 to work:
	   if an odd number of characters has been entered then add a leading zero */
	if (length & 1) {
		ustrcpy(temp, (uint8_t *) "0");
		length++;
	}
	uconcat(temp, source);

	/* start character */
	strcpy(dest, "1111");

	for(int i = 0; i < length; i+=2) {
		/* look up the bars and the spaces and put them in two strings */
		strcpy(bars, "");
		lookup(NEON, C25InterTable, temp[i], bars);
		strcpy(spaces, "");
		lookup(NEON, C25InterTable, temp[i + 1], spaces);

		/* then merge (interlace) the strings together */
		int k = 0;
		for(int j = 0; j <= 4; j++)
		{
			mixed[k] = bars[j]; k++;
			mixed[k] = spaces[j]; k++;
		}
		mixed[k] = '\0';
		concat (dest, mixed);
	}

	/* Stop character */
	concat (dest, "311");

	expand(symbol, dest);
	ustrcpy(symbol->text, temp);
	return error_number;

}
Пример #12
0
int channel_code(struct zint_symbol *symbol, unsigned char source[], int length) {
	/* Channel Code - According to ANSI/AIM BC12-1998 */
	
	int channels, i;
	int error_number = 0, range = 0, zeroes;
	char hrt[9];

	target_value = 0;
	
	if(length > 7) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
    if(error_number == ERROR_INVALID_DATA1) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	
	if((symbol->option_2 < 3) || (symbol->option_2 > 8)) { channels = 0; } else { channels = symbol->option_2; }
	if(channels == 0) { channels = length + 1; }
	if(channels == 2) { channels = 3; }
	
	for(i = 0; i < length; i++) {
		target_value *= 10;
		target_value += ctoi((char) source[i]);
	}
	
	switch(channels) {
		case 3: if(target_value > 26) { range = 1; } break;
		case 4: if(target_value > 292) { range = 1; } break;
		case 5: if(target_value > 3493) { range = 1; } break;
		case 6: if(target_value > 44072) { range = 1; } break;
		case 7: if(target_value > 576688) { range = 1; } break;
		case 8: if(target_value > 7742862) { range = 1; } break;
	}
	if(range) {
		strcpy(symbol->errtxt, "Value out of range");
        return ERROR_INVALID_DATA1;
	}
	
	for(i = 0; i < 11; i++) { B[i] = 0; S[i] = 0; }
	
	B[0] = S[1] = B[1] = S[2] = B[2] = 1;
	value = 0;
	NextS(channels,3,channels,channels);
	
	zeroes = channels - 1 - length;
	memset(hrt, '0', zeroes);
	strcpy(hrt + zeroes, (char *)source);
	ustrcpy(symbol->text, (unsigned char *)hrt);
	
	expand(symbol, pattern);
	
	return error_number;
}
Пример #13
0
/** \brief Constructor
 */
router_lident_t::router_lident_t(const router_peerid_t &m_peerid, const x509_privkey_t &m_privkey
			, const x509_cert_t &m_cert, const router_name_t &m_dnsname)	throw()
{
	// copy the parameter
	this->m_peerid	= m_peerid;
	this->m_privkey	= m_privkey;
	this->m_cert	= m_cert;
	this->m_dnsname	= m_dnsname;
	
	// sanity check - the object MUST be sane
	DBG_ASSERT( is_sane() );
}
Пример #14
0
int daft_code(struct zint_symbol *symbol, unsigned char source[], int length)
{
	/* Handles DAFT Code symbols */
	/* Presumably 'daft' doesn't mean the same thing in Germany as it does in the UK! */
	char height_pattern[100];
	unsigned int loopey, h;
	int writer, i, error_number;
	strcpy(height_pattern, "");

	error_number = 0;
	if(length > 50) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	to_upper((unsigned char*)source);
	error_number = is_sane(DAFTSET, (unsigned char*)source, length);

	if(error_number == ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}

	for (i = 0; i < length; i++) {
		if(source[i] == 'D') { concat(height_pattern, "2"); }
		if(source[i] == 'A') { concat(height_pattern, "1"); }
		if(source[i] == 'F') { concat(height_pattern, "0"); }
		if(source[i] == 'T') { concat(height_pattern, "3"); }
	}

	writer = 0;
	h = strlen(height_pattern);
	for(loopey = 0; loopey < h; loopey++)
	{
		if((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0'))
		{
			set_module(symbol, 0, writer);
		}
		set_module(symbol, 1, writer);
		if((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0'))
		{
			set_module(symbol, 2, writer);
		}
		writer += 2;
	}

	symbol->row_height[0] = 3;
	symbol->row_height[1] = 2;
	symbol->row_height[2] = 3;
	symbol->rows = 3;
	symbol->width = writer - 1;

	return error_number;
}
Пример #15
0
int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length)
{
	/* Puts RM4SCC into the data matrix */
	char height_pattern[200];
	unsigned int loopey, h;
	int writer;
	int error_number;
	strcpy(height_pattern, "");

	error_number = 0;

	if(length > 120) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	to_upper(source);
	error_number = is_sane(KRSET, source, length);
	if(error_number == ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	/*check = */rm4scc((char*)source, (unsigned char*)height_pattern, length);
	
	writer = 0;
	h = strlen(height_pattern);
	for(loopey = 0; loopey < h; loopey++)
	{
		if((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0'))
		{
			set_module(symbol, 0, writer);
		}
		set_module(symbol, 1, writer);
		if((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0'))
		{
			set_module(symbol, 2, writer);
		}
		writer += 2;
	}

	symbol->row_height[0] = 3;
	symbol->row_height[1] = 2;
	symbol->row_height[2] = 3;
	symbol->rows = 3;
	symbol->width = writer - 1;

	return error_number;
}
/* Two asset correlation options */
double TwoAssetCorrelation(
	int fCall,
	double S1,
	double S2,
	double X1,
	double X2,
	double T,
	double b1,
	double b2,
	double r,
	double v1,
	double v2,
	double Rho)
{
	double sT, d1, d2, result;

	assert_valid_price(S1);
	assert_valid_price(S2);
	assert_valid_strike(X1);
	assert_valid_strike(X2);
	assert_valid_time(T);
	assert_valid_interest_rate(r);
	assert_valid_cost_of_carry(b1);
	assert_valid_cost_of_carry(b2);
	assert_valid_volatility(v1);
	assert_valid_volatility(v2);

	sT = sqrt(T);
    d1 = (log(S1 / X1) + (b1 - pow2(v1) / 2.0) * T) / (v1 * sT);
    d2 = (log(S2 / X2) + (b2 - pow2(v2) / 2.0) * T) / (v2 * sT);
    
    if (fCall) {
        result 
			= S2 * exp((b2 - r) * T) * cbnd(d2 + v2 * sT, d1 + Rho * v2 * sT, Rho) 
			- X2 * exp(-r * T)       * cbnd(d2, d1, Rho);
    }
	else {
		result 
			= X2 * exp(-r * T)       * cbnd(-d2, -d1, Rho) 
			- S2 * exp((b2 - r) * T) * cbnd(-d2 - v2 * sT, -d1 - Rho * v2 * sT, Rho);
    }

	assert(is_sane(result));
	return result;
}
Пример #17
0
Файл: 2of5.c Проект: ahippo/zint
int itf14(struct zint_symbol *symbol, uint8_t source[], int length)
{
	int error_number, zeroes;
	unsigned int count;
	char localstr[16];

	error_number = 0;

	count = 0;

	if(length > 13) {
		strcpy(symbol->errtxt, "Input too long");
		return ZERROR_TOO_LONG;
	}

	error_number = is_sane(NEON, source, length);
	if(error_number == ZERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid character in data");
		return error_number;
	}

	/* Add leading zeros as required */
	zeroes = 13 - length;
	for(int i = 0; i < zeroes; i++) {
		localstr[i] = '0';
	}
	strcpy(localstr + zeroes, (char *)source);

	/* Calculate the check digit - the same method used for EAN-13 */

	for (int i = 12; i >= 0; i--) {
		count += ctoi(localstr[i]);

		if (!(i & 1)) {
			count += 2 * ctoi(localstr[i]);
		}
	}

	localstr[13] = check_digit(count);
	localstr[14] = '\0';
	error_number = interleaved_two_of_five(symbol, (uint8_t *)localstr, strlen(localstr));
	ustrcpy(symbol->text, (uint8_t*)localstr);
	return error_number;
}
Пример #18
0
int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Pharmazentral Nummer (PZN) */
	
	int i, error_number, zeroes;
	unsigned int count, check_digit;
	char localstr[10];
	
	error_number = 0;

	count = 0;
	if(length > 6) {
		strcpy(symbol->errtxt, "Input wrong length");
		return ERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
    if(error_number == ERROR_INVALID_DATA1) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	
	localstr[0] = '-';
	zeroes = 6 - length + 1;
	for(i = 1; i < zeroes; i++)
		localstr[i] = '0';
	strcpy(localstr + zeroes, (char *)source);
	
	for (i = 1; i < 7; i++) {
		count += (i + 1) * ctoi(localstr[i]);
	}
	
	check_digit = count%11;
	if (check_digit == 11) { check_digit = 0; }
	localstr[7] = itoc(check_digit);
	localstr[8] = '\0';
	if(localstr[7] == 'A') { 
		strcpy(symbol->errtxt, "Invalid PZN Data");
        return ERROR_INVALID_DATA1;
	}
	error_number = c39(symbol, (unsigned char *)localstr, strlen(localstr));
	ustrcpy(symbol->text, (unsigned char *)"PZN");
	uconcat(symbol->text, (unsigned char *)localstr);
	return error_number;
}
int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length)
{
    /* Draws the patterns for two track pharmacode */
    char height_pattern[200];
    unsigned int loopey, h;
    int writer;
    int error_number = 0;
    strcpy(height_pattern, "");

    if(length > 8) {
        strcpy(symbol->errtxt, "Input too long");
        return ERROR_TOO_LONG;
    }
    error_number = is_sane(NEON, source, length);
    if(error_number == ERROR_INVALID_DATA1) {
        strcpy(symbol->errtxt, "Invalid characters in data");
        return error_number;
    }
    error_number = pharma_two_calc(symbol, source, height_pattern);
    if(error_number != 0) {
        return error_number;
    }

    writer = 0;
    h = strlen(height_pattern);
    for(loopey = 0; loopey < h; loopey++)
    {
        if((height_pattern[loopey] == '2') || (height_pattern[loopey] == '3'))
        {
            set_module(symbol, 0, writer);
        }
        if((height_pattern[loopey] == '1') || (height_pattern[loopey] == '3'))
        {
            set_module(symbol, 1, writer);
        }
        writer += 2;
    }
    symbol->rows = 2;
    symbol->width = writer - 1;


    return error_number;
}
Пример #20
0
int nve_18(struct zint_symbol *symbol, unsigned char source[], int length)
{
	/* Add check digit if encoding an NVE18 symbol */
	int error_number, zeroes, i, nve_check, total_sum, sourcelen;
	unsigned char ean128_equiv[25];

	memset(ean128_equiv, 0, 25);
	sourcelen = length;

	if(sourcelen > 17) {
		strcpy(symbol->errtxt, "Input too long");
		return ZINT_ERROR_TOO_LONG;
	}

	error_number = is_sane(NEON, source, length);
	if(error_number == ZINT_ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	zeroes = 17 - sourcelen;
	strcpy((char *)ean128_equiv, "[00]");
	memset(ean128_equiv + 4, '0', zeroes);
	strcpy((char*)ean128_equiv + 4 + zeroes, (char*)source);

	total_sum = 0;
	for(i = sourcelen - 1; i >= 0; i--)
	{
		total_sum += ctoi(source[i]);

		if(!(i & 1)) {
			total_sum += 2 * ctoi(source[i]);
		}
	}
	nve_check = 10 - total_sum % 10;
	if(nve_check == 10) { nve_check = 0; }
	ean128_equiv[21] = itoc(nve_check);
	ean128_equiv[22] = '\0';

	error_number = ean_128(symbol, ean128_equiv, ustrlen(ean128_equiv));

	return error_number;
}
int codabar(struct zint_symbol *symbol, unsigned char source[], int length)
{   /* The Codabar system consisting of simple substitution */

    int i, error_number;
    char dest[512];

    error_number = 0;
    strcpy(dest, "");

    if(length > 60) { /* No stack smashing please */
        strcpy(symbol->errtxt, "Input too long");
        return ERROR_TOO_LONG;
    }
    to_upper(source);
    error_number = is_sane(CALCIUM, source, length);
    if(error_number == ERROR_INVALID_DATA1) {
        strcpy(symbol->errtxt, "Invalid characters in data");
        return error_number;
    }
    /* Codabar must begin and end with the characters A, B, C or D */
    if((source[0] != 'A') && (source[0] != 'B') && (source[0] != 'C') && (source[0] != 'D'))
    {
        strcpy(symbol->errtxt, "Invalid characters in data");
        return ERROR_INVALID_DATA1;
    }

    if((source[length - 1] != 'A') && (source[length - 1] != 'B') &&
            (source[length - 1] != 'C') && (source[length - 1] != 'D'))
    {
        strcpy(symbol->errtxt, "Invalid characters in data");
        return ERROR_INVALID_DATA1;
    }

    for(i = 0; i < length; i++)
    {
        lookup(CALCIUM, CodaTable, source[i], dest);
    }

    expand(symbol, dest);
    ustrcpy(symbol->text, source);
    return error_number;
}
Пример #22
0
int ean_14(struct zint_symbol *symbol, unsigned char source[], int length)
{
	/* EAN-14 - A version of EAN-128 */
	int i, count, check_digit;
	int error_number, zeroes;
	unsigned char ean128_equiv[20];

	if(length > 13) {
		strcpy(symbol->errtxt, "Input wrong length");
		return ZINT_ERROR_TOO_LONG;
	}

	error_number = is_sane(NEON, source, length);
	if(error_number == ZINT_ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid character in data");
		return error_number;
	}

	zeroes = 13 - length;
	strcpy((char*)ean128_equiv, "[01]");
	memset(ean128_equiv + 4, '0', zeroes);
	ustrcpy(ean128_equiv + 4 + zeroes, source);

	count = 0;
	for (i = length - 1; i >= 0; i--) {
		count += ctoi(source[i]);

		if (!(i & 1)) {
			count += 2 * ctoi(source[i]);
		}
	}
	check_digit = 10 - (count % 10);
	if (check_digit == 10) { check_digit = 0; }
	ean128_equiv[17] = itoc(check_digit);
	ean128_equiv[18] = '\0';

	error_number = ean_128(symbol, ean128_equiv, ustrlen(ean128_equiv));

	return error_number;
}
Пример #23
0
Файл: 2of5.c Проект: ahippo/zint
int dpleit(struct zint_symbol *symbol, uint8_t source[], int length)
{ /* Deutshe Post Leitcode */
	int error_number;
	unsigned int count;
	char localstr[16];
	int zeroes;

	error_number = 0;
	count = 0;
	if(length > 13) {
		strcpy(symbol->errtxt, "Input wrong length");
		return ZERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
	if(error_number == ZERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}

	zeroes = 13 - length;
	for(int i = 0; i < zeroes; i++)
		localstr[i] = '0';
	strcpy(localstr + zeroes, (char *)source);

	for (int i = 12; i >= 0; i--)
	{
		count += 4 * ctoi(localstr[i]);

		if (i & 1) {
			count += 5 * ctoi(localstr[i]);
		}
	}

	localstr[13] = check_digit(count);
	localstr[14] = '\0';
	error_number = interleaved_two_of_five(symbol, (uint8_t *)localstr, strlen(localstr));
	ustrcpy(symbol->text, (uint8_t*)localstr);
	return error_number;
}
Пример #24
0
  void swap_node(Node * old, Node * _new){
    nodes.remove(old);
    sched_list[old->grp]->nodes.remove(old);
    nodes.push_back(_new);
    sched_list[_new->grp]->nodes.push_back(_new);
    std::list<ConnectionInfo> new_connections;
    for(auto it = connections.begin();it != connections.end();it++){
      if(it->out_node == old){
	it->out_node = _new;
	
	if(it->outlet >= 0 && it->outlet < _new->outputs.size()){
	  _new->outputs[it->outlet].push_back(it->in_node->inputs[it->inlet]);
	}
      }
      if(it->in_node == old){
	std::vector<_input *> &vec = it->out_node->outputs[it->outlet];
	_input * removethis = it->in_node->inputs[it->inlet];
	for(auto it2 = vec.begin(); it2 != vec.end();it2++){
	  if(removethis == *it2){
	    if(it->inlet < _new->inputs.size()){
	      *it2 = _new->inputs[it->inlet];
	    }else{
	      vec.erase(it2);
	    }
	    break;
	  }
	}

	it->in_node = _new;
      }
      if(it->is_sane()){
	new_connections.push_back(*it);
      }
    }

    connections = new_connections;

  }
Пример #25
0
int korea_post(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Korean Postal Authority */

	int total, loop, check, zeroes, error_number;
	char localstr[8], dest[80];

	error_number = 0;
	if(length > 6) { 
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
	if(error_number == ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	zeroes = 6 - length;
	memset(localstr, '0', zeroes);
	strcpy(localstr + zeroes, (char *)source);

	total = 0;
	for(loop = 0; loop < 6; loop++) {
		total += ctoi(localstr[loop]);
	}
	check = 10 - (total % 10);
	if(check == 10) { check = 0; }
	localstr[6] = itoc(check);
	localstr[7] = '\0';
	*dest = '\0';
	for(loop = 5; loop >= 0; loop--) {
		lookup(NEON, KoreaTable, localstr[loop], dest);
	}
	lookup(NEON, KoreaTable, localstr[6], dest);
	expand(symbol, dest);
	ustrcpy(symbol->text, (unsigned char*)localstr);
	return error_number;
}
Пример #26
0
int dpident(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Deutsche Post Identcode */
	int i, error_number, zeroes;
	unsigned int count;
	char localstr[16];

	count = 0;
	if(length > 11) {
		strcpy(symbol->errtxt, "Input wrong length");
		return ERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
    if(error_number == ERROR_INVALID_DATA1) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}

	zeroes = 11 - length;
	for(i = 0; i < zeroes; i++)
		localstr[i] = '0';
	strcpy(localstr + zeroes, (char *)source);
	
	for (i = 10; i >= 0; i--)
	{
		count += 4 * ctoi(localstr[i]);

		if (i & 1) {
			count += 5 * ctoi(localstr[i]);
		}
	}
	localstr[11] = check_digit(count);
	localstr[12] = '\0';
	error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr, strlen(localstr));
	ustrcpy(symbol->text, (unsigned char*)localstr);
	return error_number;
}
Пример #27
0
int code_one(struct zint_symbol *symbol, unsigned char source[], int length)
{
	int size = 1, i, j, data_blocks;

	char datagrid[136][120];
	int row, col;
	int sub_version = 0;
	
	if((symbol->option_2 < 0) || (symbol->option_2 > 10)) {
		strcpy(symbol->errtxt, "Invalid symbol size");
		return ERROR_INVALID_OPTION;
	}
	
	if(symbol->option_2 == 9) {
		/* Version S */
		int codewords;
		short int elreg[112];
		unsigned int data[15], ecc[15];
		int stream[30];
		int block_width;
		
		if(length > 18) {
			strcpy(symbol->errtxt, "Input data too long");
			return ERROR_TOO_LONG;
		}
		if(is_sane(NEON, source, length) == ERROR_INVALID_DATA) {
			strcpy(symbol->errtxt, "Invalid input data (Version S encodes numeric input only)");
			return ERROR_INVALID_DATA;
		}
		
		sub_version = 3; codewords = 12; block_width = 6; /* Version S-30 */
		if(length <= 12) { sub_version = 2; codewords = 8; block_width = 4; } /* Version S-20 */
		if(length <= 6) { sub_version = 1; codewords = 4; block_width = 2; } /* Version S-10 */
		
		binary_load(elreg, (char *)source, length);
		hex_dump(elreg);
		
		for(i = 0; i < 15; i++) {
			data[i] = 0;
			ecc[i] = 0;
		}
		
		for(i = 0; i < codewords; i++) {
			data[codewords - i - 1] += 1 * elreg[(i * 5)];
			data[codewords - i - 1] += 2 * elreg[(i * 5) + 1];
			data[codewords - i - 1] += 4 * elreg[(i * 5) + 2];
			data[codewords - i - 1] += 8 * elreg[(i * 5) + 3];
			data[codewords - i - 1] += 16 * elreg[(i * 5) + 4];
		}
		
		rs_init_gf(0x25);
		rs_init_code(codewords, 1);
		rs_encode_long(codewords, data, ecc);
		rs_free();
		
		for(i = 0; i < codewords; i++) {
			stream[i] = data[i];
			stream[i + codewords] = ecc[codewords - i - 1];
		}
		
		for(i = 0; i < 136; i++) {
			for(j = 0; j < 120; j++) {
				datagrid[i][j] = '0';
			}
		}
		
		i = 0;
		for(row = 0; row < 2; row++) {
			for(col = 0; col < block_width; col++) {
				if(stream[i] & 0x10) { datagrid[row * 2][col * 5] = '1'; }
				if(stream[i] & 0x08) { datagrid[row * 2][(col * 5) + 1] = '1'; }
				if(stream[i] & 0x04) { datagrid[row * 2][(col * 5) + 2] = '1'; }
				if(stream[i] & 0x02) { datagrid[(row * 2) + 1][col * 5] = '1'; }
				if(stream[i] & 0x01) { datagrid[(row * 2) + 1][(col * 5) + 1] = '1'; }
				if(stream[i + 1] & 0x10) { datagrid[row * 2][(col * 5) + 3] = '1'; }
				if(stream[i + 1] & 0x08) { datagrid[row * 2][(col * 5) + 4] = '1'; }
				if(stream[i + 1] & 0x04) { datagrid[(row * 2) + 1][(col * 5) + 2] = '1'; }
				if(stream[i + 1] & 0x02) { datagrid[(row * 2) + 1][(col * 5) + 3] = '1'; }
				if(stream[i + 1] & 0x01) { datagrid[(row * 2) + 1][(col * 5) + 4] = '1'; }
				i += 2;
			}
		}
		
		size = 9;	
		symbol->rows = 8;
		symbol->width = 10 * sub_version + 1;
	}
	
	if(symbol->option_2 == 10) {
		/* Version T */
		unsigned int data[40], ecc[25];
		unsigned int stream[65];
		int data_length;
		int data_cw, ecc_cw, block_width;
		
		for(i = 0; i < 40; i++) { data[i] = 0; }
		data_length = c1_encode(symbol, source, data, length);
		
		if(data_length == 0) {
			return ERROR_TOO_LONG;
		}
		
		if(data_length > 38) {
			strcpy(symbol->errtxt, "Input data too long");
			return ERROR_TOO_LONG;
		}
		
		size = 10;
		sub_version = 3; data_cw = 38; ecc_cw = 22; block_width = 12;
		if(data_length <= 24) { sub_version = 2; data_cw = 24; ecc_cw = 16; block_width = 8; }
		if(data_length <= 10) { sub_version = 1; data_cw = 10; ecc_cw = 10; block_width = 4; }
		
		for(i = data_length; i < data_cw; i++) {
			data[i] = 129; /* Pad */
		}
		
		/* Calculate error correction data */
		rs_init_gf(0x12d);
		rs_init_code(ecc_cw, 1);	
		rs_encode_long(data_cw, data, ecc);
		rs_free();
		
		/* "Stream" combines data and error correction data */
		for(i = 0; i < data_cw; i++) {
			stream[i] = data[i];
		}
		for(i = 0; i < ecc_cw; i++) {
			stream[data_cw + i] = ecc[ecc_cw - i - 1];
		}
	
		for(i = 0; i < 136; i++) {
			for(j = 0; j < 120; j++) {
				datagrid[i][j] = '0';
			}
		}
		
		i = 0;
		for(row = 0; row < 5; row++) {
			for(col = 0; col < block_width; col++) {
				if(stream[i] & 0x80) { datagrid[row * 2][col * 4] = '1'; }
				if(stream[i] & 0x40) { datagrid[row * 2][(col * 4) + 1] = '1'; }
				if(stream[i] & 0x20) { datagrid[row * 2][(col * 4) + 2] = '1'; }
				if(stream[i] & 0x10) { datagrid[row * 2][(col * 4) + 3] = '1'; }
				if(stream[i] & 0x08) { datagrid[(row * 2) + 1][col * 4] = '1'; }
				if(stream[i] & 0x04) { datagrid[(row * 2) + 1][(col * 4) + 1] = '1'; }
				if(stream[i] & 0x02) { datagrid[(row * 2) + 1][(col * 4) + 2] = '1'; }
				if(stream[i] & 0x01) { datagrid[(row * 2) + 1][(col * 4) + 3] = '1'; }
				i++;
			}
		}
		
		symbol->rows = 16;
		symbol->width = (sub_version * 16) + 1;
	}
		
	if((symbol->option_2 != 9) && (symbol->option_2 != 10)) {
		/* Version A to H */
		unsigned int data[1500], ecc[600];
		unsigned int sub_data[190], sub_ecc[75];
		unsigned int stream[2100];
		int data_length;
				
		for(i = 0; i < 1500; i++) { data[i] = 0; }
		data_length = c1_encode(symbol, source, data, length);
		
		if(data_length == 0) {
			return ERROR_TOO_LONG;
		}
		
		for(i = 7; i >= 0; i--) {
			if(c1_data_length[i] >= data_length) {
				size = i + 1;
			}
		}
		
		if(symbol->option_2 > size) {
			size = symbol->option_2;
		}
		
		for(i = data_length; i < c1_data_length[size - 1]; i++) {
			data[i] = 129; /* Pad */
		}
		
		/* Calculate error correction data */
		data_length = c1_data_length[size - 1];
		for(i = 0; i < 190; i++) { sub_data[i] = 0; }
		for(i = 0; i < 75; i++) { sub_ecc[i] = 0; }
		
		data_blocks = c1_blocks[size - 1];
		
		rs_init_gf(0x12d);
		rs_init_code(c1_ecc_blocks[size - 1], 0);	
		for(i = 0; i < data_blocks; i++) {
			for(j = 0; j < c1_data_blocks[size - 1]; j++) {
				
				sub_data[j] = data[j * data_blocks + i];
			}
			rs_encode_long(c1_data_blocks[size - 1], sub_data, sub_ecc);
			for(j = 0; j < c1_ecc_blocks[size - 1]; j++) {
				ecc[c1_ecc_length[size - 1] - (j * data_blocks + i) - 1] = sub_ecc[j];
			}
		}
		rs_free();
		
		/* "Stream" combines data and error correction data */
		for(i = 0; i < data_length; i++) {
			stream[i] = data[i];
		}
		for(i = 0; i < c1_ecc_length[size - 1]; i++) {
			stream[data_length + i] = ecc[i];
		}
	
		for(i = 0; i < 136; i++) {
			for(j = 0; j < 120; j++) {
				datagrid[i][j] = '0';
			}
		}
		
		i = 0;
		for(row = 0; row < c1_grid_height[size - 1]; row++) {
			for(col = 0; col < c1_grid_width[size - 1]; col++) {
				if(stream[i] & 0x80) { datagrid[row * 2][col * 4] = '1'; }
				if(stream[i] & 0x40) { datagrid[row * 2][(col * 4) + 1] = '1'; }
				if(stream[i] & 0x20) { datagrid[row * 2][(col * 4) + 2] = '1'; }
				if(stream[i] & 0x10) { datagrid[row * 2][(col * 4) + 3] = '1'; }
				if(stream[i] & 0x08) { datagrid[(row * 2) + 1][col * 4] = '1'; }
				if(stream[i] & 0x04) { datagrid[(row * 2) + 1][(col * 4) + 1] = '1'; }
				if(stream[i] & 0x02) { datagrid[(row * 2) + 1][(col * 4) + 2] = '1'; }
				if(stream[i] & 0x01) { datagrid[(row * 2) + 1][(col * 4) + 3] = '1'; }
				i++;
			}
		}
		
		/* for(i = 0; i < (c1_grid_height[size - 1] * 2); i++) {
			for(j = 0; j < (c1_grid_width[size - 1] * 4); j++) {
				printf("%c", datagrid[i][j]);
			}
			printf("\n");
		} */
		
		symbol->rows = c1_height[size - 1];
		symbol->width = c1_width[size - 1];
	}
	
	switch(size) {
		case 1: /* Version A */
			central_finder(symbol, 6, 3, 1);
			vert(symbol, 4, 6, 1);
			vert(symbol, 12, 5, 0); 
			set_module(symbol, 5, 12);
			spigot(symbol, 0);
			spigot(symbol, 15);
			block_copy(symbol, datagrid, 0, 0, 5, 4, 0, 0);
			block_copy(symbol, datagrid, 0, 4, 5, 12, 0, 2);
			block_copy(symbol, datagrid, 5, 0, 5, 12, 6, 0);
			block_copy(symbol, datagrid, 5, 12, 5, 4, 6, 2);
			break;
		case 2: /* Version B */
			central_finder(symbol, 8, 4, 1);
			vert(symbol, 4, 8, 1);
			vert(symbol, 16, 7, 0); 
			set_module(symbol, 7, 16);
			spigot(symbol, 0);
			spigot(symbol, 21);
			block_copy(symbol, datagrid, 0, 0, 7, 4, 0, 0);
			block_copy(symbol, datagrid, 0, 4, 7, 16, 0, 2);
			block_copy(symbol, datagrid, 7, 0, 7, 16, 8, 0);
			block_copy(symbol, datagrid, 7, 16, 7, 4, 8, 2);
			break;
		case 3: /* Version C */
			central_finder(symbol, 11, 4, 2);
			vert(symbol, 4, 11, 1);
			vert(symbol, 26, 13, 1);
			vert(symbol, 4, 10, 0);
			vert(symbol, 26, 10, 0); 
			spigot(symbol, 0);
			spigot(symbol, 27);
			block_copy(symbol, datagrid, 0, 0, 10, 4, 0, 0);
			block_copy(symbol, datagrid, 0, 4, 10, 20, 0, 2);
			block_copy(symbol, datagrid, 0, 24, 10, 4, 0, 4);
			block_copy(symbol, datagrid, 10, 0, 10, 4, 8, 0);
			block_copy(symbol, datagrid, 10, 4, 10, 20, 8, 2);
			block_copy(symbol, datagrid, 10, 24, 10, 4, 8, 4);
			break;
		case 4: /* Version D */
			central_finder(symbol, 16, 5, 1); 
			vert(symbol, 4, 16, 1);
			vert(symbol, 20, 16, 1);
			vert(symbol, 36, 16, 1);
			vert(symbol, 4, 15, 0);
			vert(symbol, 20, 15, 0);
			vert(symbol, 36, 15, 0);
			spigot(symbol, 0);
			spigot(symbol, 12);
			spigot(symbol, 27);
			spigot(symbol, 39);
			block_copy(symbol, datagrid, 0, 0, 15, 4, 0, 0);
			block_copy(symbol, datagrid, 0, 4, 15, 14, 0, 2);
			block_copy(symbol, datagrid, 0, 18, 15, 14, 0, 4);
			block_copy(symbol, datagrid, 0, 32, 15, 4, 0, 6);
			block_copy(symbol, datagrid, 15, 0, 15, 4, 10, 0);
			block_copy(symbol, datagrid, 15, 4, 15, 14, 10, 2);
			block_copy(symbol, datagrid, 15, 18, 15, 14, 10, 4);
			block_copy(symbol, datagrid, 15, 32, 15, 4, 10, 6);
			break;
		case 5: /* Version E */
			central_finder(symbol, 22, 5, 2); 
			vert(symbol, 4, 22, 1);
			vert(symbol, 26, 24, 1);
			vert(symbol, 48, 22, 1);
			vert(symbol, 4, 21, 0);
			vert(symbol, 26, 21, 0);
			vert(symbol, 48, 21, 0);
			spigot(symbol, 0);
			spigot(symbol, 12);
			spigot(symbol, 39);
			spigot(symbol, 51);
			block_copy(symbol, datagrid, 0, 0, 21, 4, 0, 0);
			block_copy(symbol, datagrid, 0, 4, 21, 20, 0, 2);
			block_copy(symbol, datagrid, 0, 24, 21, 20, 0, 4);
			block_copy(symbol, datagrid, 0, 44, 21, 4, 0, 6);
			block_copy(symbol, datagrid, 21, 0, 21, 4, 10, 0);
			block_copy(symbol, datagrid, 21, 4, 21, 20, 10, 2);
			block_copy(symbol, datagrid, 21, 24, 21, 20, 10, 4);
			block_copy(symbol, datagrid, 21, 44, 21, 4, 10, 6);
			break;
		case 6: /* Version F */
			central_finder(symbol, 31, 5, 3); 
			vert(symbol, 4, 31, 1);
			vert(symbol, 26, 35, 1);
			vert(symbol, 48, 31, 1);
			vert(symbol, 70, 35, 1);
			vert(symbol, 4, 30, 0);
			vert(symbol, 26, 30, 0);
			vert(symbol, 48, 30, 0);
			vert(symbol, 70, 30, 0);
			spigot(symbol, 0);
			spigot(symbol, 12);
			spigot(symbol, 24);
			spigot(symbol, 45);
			spigot(symbol, 57);
			spigot(symbol, 69);
			block_copy(symbol, datagrid, 0, 0, 30, 4, 0, 0);
			block_copy(symbol, datagrid, 0, 4, 30, 20, 0, 2);
			block_copy(symbol, datagrid, 0, 24, 30, 20, 0, 4);
			block_copy(symbol, datagrid, 0, 44, 30, 20, 0, 6);
			block_copy(symbol, datagrid, 0, 64, 30, 4, 0, 8);
			block_copy(symbol, datagrid, 30, 0, 30, 4, 10, 0);
			block_copy(symbol, datagrid, 30, 4, 30, 20, 10, 2);
			block_copy(symbol, datagrid, 30, 24, 30, 20, 10, 4);
			block_copy(symbol, datagrid, 30, 44, 30, 20, 10, 6);
			block_copy(symbol, datagrid, 30, 64, 30, 4, 10, 8);
			break;
		case 7: /* Version G */
			central_finder(symbol, 47, 6, 2); 
			vert(symbol, 6, 47, 1);
			vert(symbol, 27, 49, 1);
			vert(symbol, 48, 47, 1);
			vert(symbol, 69, 49, 1);
			vert(symbol, 90, 47, 1);
			vert(symbol, 6, 46, 0);
			vert(symbol, 27, 46, 0);
			vert(symbol, 48, 46, 0);
			vert(symbol, 69, 46, 0);
			vert(symbol, 90, 46, 0);
			spigot(symbol, 0);
			spigot(symbol, 12);
			spigot(symbol, 24);
			spigot(symbol, 36);
			spigot(symbol, 67);
			spigot(symbol, 79);
			spigot(symbol, 91);
			spigot(symbol, 103);
			block_copy(symbol, datagrid, 0, 0, 46, 6, 0, 0);
			block_copy(symbol, datagrid, 0, 6, 46, 19, 0, 2);
			block_copy(symbol, datagrid, 0, 25, 46, 19, 0, 4);
			block_copy(symbol, datagrid, 0, 44, 46, 19, 0, 6);
			block_copy(symbol, datagrid, 0, 63, 46, 19, 0, 8);
			block_copy(symbol, datagrid, 0, 82, 46, 6, 0, 10);
			block_copy(symbol, datagrid, 46, 0, 46, 6, 12, 0);
			block_copy(symbol, datagrid, 46, 6, 46, 19, 12, 2);
			block_copy(symbol, datagrid, 46, 25, 46, 19, 12, 4);
			block_copy(symbol, datagrid, 46, 44, 46, 19, 12, 6);
			block_copy(symbol, datagrid, 46, 63, 46, 19, 12, 8);
			block_copy(symbol, datagrid, 46, 82, 46, 6, 12, 10);
			break;
		case 8: /* Version H */
			central_finder(symbol, 69, 6, 3);
			vert(symbol, 6, 69, 1);
			vert(symbol, 26, 73, 1);
			vert(symbol, 46, 69, 1);
			vert(symbol, 66, 73, 1);
			vert(symbol, 86, 69, 1);
			vert(symbol, 106, 73, 1);
			vert(symbol, 126, 69, 1);
			vert(symbol, 6, 68, 0);
			vert(symbol, 26, 68, 0);
			vert(symbol, 46, 68, 0);
			vert(symbol, 66, 68, 0);
			vert(symbol, 86, 68, 0);
			vert(symbol, 106, 68, 0);
			vert(symbol, 126, 68, 0); 
			spigot(symbol, 0);
			spigot(symbol, 12);
			spigot(symbol, 24);
			spigot(symbol, 36);
			spigot(symbol, 48);
			spigot(symbol, 60);
			spigot(symbol, 87);
			spigot(symbol, 99);
			spigot(symbol, 111);
			spigot(symbol, 123);
			spigot(symbol, 135);
			spigot(symbol, 147);
			block_copy(symbol, datagrid, 0, 0, 68, 6, 0, 0);
			block_copy(symbol, datagrid, 0, 6, 68, 18, 0, 2);
			block_copy(symbol, datagrid, 0, 24, 68, 18, 0, 4);
			block_copy(symbol, datagrid, 0, 42, 68, 18, 0, 6);
			block_copy(symbol, datagrid, 0, 60, 68, 18, 0, 8);
			block_copy(symbol, datagrid, 0, 78, 68, 18, 0, 10);
			block_copy(symbol, datagrid, 0, 96, 68, 18, 0, 12);
			block_copy(symbol, datagrid, 0, 114, 68, 6, 0, 14);
			block_copy(symbol, datagrid, 68, 0, 68, 6, 12, 0);
			block_copy(symbol, datagrid, 68, 6, 68, 18, 12, 2);
			block_copy(symbol, datagrid, 68, 24, 68, 18, 12, 4);
			block_copy(symbol, datagrid, 68, 42, 68, 18, 12, 6);
			block_copy(symbol, datagrid, 68, 60, 68, 18, 12, 8);
			block_copy(symbol, datagrid, 68, 78, 68, 18, 12, 10);
			block_copy(symbol, datagrid, 68, 96, 68, 18, 12, 12);
			block_copy(symbol, datagrid, 68, 114, 68, 6, 12, 14);
			break;
		case 9: /* Version S */
			horiz(symbol, 5, 1);
			horiz(symbol, 7, 1);
			set_module(symbol, 6, 0);
			set_module(symbol, 6, symbol->width - 1);
			unset_module(symbol, 7, 1);
			unset_module(symbol, 7, symbol->width - 2);
			switch(sub_version) {
				case 1: /* Version S-10 */
					set_module(symbol, 0, 5);
					block_copy(symbol, datagrid, 0, 0, 4, 5, 0, 0);
					block_copy(symbol, datagrid, 0, 5, 4, 5, 0, 1);
					break;
				case 2: /* Version S-20 */
					set_module(symbol, 0, 10);
					set_module(symbol, 4, 10);
					block_copy(symbol, datagrid, 0, 0, 4, 10, 0, 0);
					block_copy(symbol, datagrid, 0, 10, 4, 10, 0, 1);
					break;
				case 3: /* Version S-30 */
					set_module(symbol, 0, 15);
					set_module(symbol, 4, 15);
					set_module(symbol, 6, 15);
					block_copy(symbol, datagrid, 0, 0, 4, 15, 0, 0);
					block_copy(symbol, datagrid, 0, 15, 4, 15, 0, 1);
					break;
			}
			break;
		case 10: /* Version T */
			horiz(symbol, 11, 1);
			horiz(symbol, 13, 1);
			horiz(symbol, 15, 1);
			set_module(symbol, 12, 0);
			set_module(symbol, 12, symbol->width - 1);
			set_module(symbol, 14, 0);
			set_module(symbol, 14, symbol->width - 1);
			unset_module(symbol, 13, 1);
			unset_module(symbol, 13, symbol->width - 2);
			unset_module(symbol, 15, 1);
			unset_module(symbol, 15, symbol->width - 2);
			switch(sub_version) {
				case 1: /* Version T-16 */
					set_module(symbol, 0, 8);
					set_module(symbol, 10, 8);
					block_copy(symbol, datagrid, 0, 0, 10, 8, 0, 0);
					block_copy(symbol, datagrid, 0, 8, 10, 8, 0, 1);
					break;
				case 2: /* Version T-32 */
					set_module(symbol, 0, 16);
					set_module(symbol, 10, 16);
					set_module(symbol, 12, 16);
					block_copy(symbol, datagrid, 0, 0, 10, 16, 0, 0);
					block_copy(symbol, datagrid, 0, 16, 10, 16, 0, 1);
					break;
				case 3: /* Verion T-48 */
					set_module(symbol, 0, 24);
					set_module(symbol, 10, 24);
					set_module(symbol, 12, 24);
					set_module(symbol, 14, 24);
					block_copy(symbol, datagrid, 0, 0, 10, 24, 0, 0);
					block_copy(symbol, datagrid, 0, 24, 10, 24, 0, 1);
					break;
			}
			break;
	}
	
	for(i = 0; i < symbol->rows; i++) {
		symbol->row_height[i] = 1;
	}
	
	return 0;
}
int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length)
{
    /* "Pharmacode can represent only a single integer from 3 to 131070. Unlike other
       commonly used one-dimensional barcode schemes, pharmacode does not store the data in a
       form corresponding to the human-readable digits; the number is encoded in binary, rather
       than decimal. Pharmacode is read from right to left: with n as the bar position starting
       at 0 on the right, each narrow bar adds 2n to the value and each wide bar adds 2(2^n).
       The minimum barcode is 2 bars and the maximum 16, so the smallest number that could
       be encoded is 3 (2 narrow bars) and the biggest is 131070 (16 wide bars)."
       - http://en.wikipedia.org/wiki/Pharmacode */

    /* This code uses the One Track Pharamacode calculating algorithm as recommended by
       the specification at http://www.laetus.com/laetus.php?request=file&id=69 */

    unsigned long int tester;
    int counter, error_number, h;
    char inter[18] = { 0 }; /* 131070 -> 17 bits */
    char dest[64]; /* 17 * 2 + 1 */

    error_number = 0;

    if(length > 6) {
        strcpy(symbol->errtxt, "Input too long");
        return ERROR_TOO_LONG;
    }
    error_number = is_sane(NEON, source, length);
    if(error_number == ERROR_INVALID_DATA1) {
        strcpy(symbol->errtxt, "Invalid characters in data");
        return error_number;
    }

    tester = atoi((char*)source);

    if((tester < 3) || (tester > 131070)) {
        strcpy(symbol->errtxt, "Data out of range");
        return ERROR_INVALID_DATA1;
    }

    do
    {
        if(!(tester & 1)) {
            concat(inter, "W");
            tester = (tester - 2) / 2;
        } else {
            concat(inter, "N");
            tester = (tester - 1) / 2;
        }
    }
    while(tester != 0);

    h = strlen(inter) - 1;
    *dest = '\0';
    for(counter = h; counter >= 0; counter--) {
        if(inter[counter] == 'W') {
            concat(dest, "32");
        } else {
            concat(dest, "12");
        }
    }

    expand(symbol, dest);

    return error_number;
}
int code32(struct zint_symbol *symbol, unsigned char source[], int length)
{   /* Italian Pharmacode */
    int i, zeroes, error_number, checksum, checkpart, checkdigit;
    char localstr[10], risultante[7];
    long int pharmacode, remainder, devisor;
    int codeword[6];
    char tabella[34];

    /* Validate the input */
    if(length > 8) {
        strcpy(symbol->errtxt, "Input too long");
        return ERROR_TOO_LONG;
    }
    error_number = is_sane(NEON, source, length);
    if(error_number == ERROR_INVALID_DATA1) {
        strcpy(symbol->errtxt, "Invalid characters in data");
        return error_number;
    }

    /* Add leading zeros as required */
    zeroes = 8 - length;
    memset(localstr, '0', zeroes);
    strcpy(localstr + zeroes, (char*)source);

    /* Calculate the check digit */
    checksum = 0;
    checkpart = 0;
    for(i = 0; i < 4; i++) {
        checkpart = ctoi(localstr[i * 2]);
        checksum += checkpart;
        checkpart = 2 * (ctoi(localstr[(i * 2) + 1]));
        if(checkpart >= 10) {
            checksum += (checkpart - 10) + 1;
        } else {
            checksum += checkpart;
        }
    }

    /* Add check digit to data string */
    checkdigit = checksum % 10;
    localstr[8] = itoc(checkdigit);
    localstr[9] = '\0';

    /* Convert string into an integer value */
    pharmacode = atoi(localstr);

    /* Convert from decimal to base-32 */
    devisor = 33554432;
    for(i = 5; i >= 0; i--) {
        codeword[i] = pharmacode / devisor;
        remainder = pharmacode % devisor;
        pharmacode = remainder;
        devisor /= 32;
    }

    /* Look up values in 'Tabella di conversione' */
    strcpy(tabella, "0123456789BCDFGHJKLMNPQRSTUVWXYZ");
    for(i = 5; i >= 0; i--) {
        risultante[5 - i] = tabella[codeword[i]];
    }
    risultante[6] = '\0';
    /* Plot the barcode using Code 39 */
    error_number = c39(symbol, (unsigned char*)risultante, strlen(risultante));
    if(error_number != 0) {
        return error_number;
    }

    /* Override the normal text output with the Pharmacode number */
    ustrcpy(symbol->text, (unsigned char*)"A");
    uconcat(symbol->text, (unsigned char*)localstr);

    return error_number;
}
Пример #30
0
int hibc(struct zint_symbol *symbol, uint8_t source[], int length)
{
	int counter, error_number, i;
	char to_process[40], temp[2], check_digit;

	if(length > 36) {
		strcpy(symbol->errtxt, "Data too long for HIBC LIC");
		return ZERROR_TOO_LONG;
	}
	to_upper(source);
	error_number = is_sane(TECHNETIUM , source, length);
	if(error_number == ZERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}

	strcpy(to_process, "+");
	counter = 41;
	for(i = 0; i < length; i++) {
		counter += posn(TECHNETIUM, source[i]);
	}
	counter = counter % 43;

	if(counter < 10) {
		check_digit = itoc(counter);
	} else {
		if(counter < 36) {
			check_digit = (counter - 10) + 'A';
		} else {
			switch(counter) {
				case 36: check_digit = '-'; break;
				case 37: check_digit = '.'; break;
				case 38: check_digit = ' '; break;
				case 39: check_digit = '$'; break;
				case 40: check_digit = '/'; break;
				case 41: check_digit = '+'; break;
				case 42: check_digit = '%'; break;
				default: check_digit = ' '; break; /* Keep compiler happy */
			}
		}
	}

	temp[0] = check_digit;
	temp[1] = '\0';

	concat(to_process, (char *)source);
	concat(to_process, temp);
	length = strlen(to_process);

	switch(symbol->symbology) {
		case BARCODE_HIBC_QR:
			error_number = qr_code(symbol, (uint8_t *)to_process, length);
			break;
		case BARCODE_HIBC_PDF:
			error_number = pdf417enc(symbol, (uint8_t *)to_process, length);
			break;
		case BARCODE_HIBC_MICPDF:
			error_number = micro_pdf417(symbol, (uint8_t *)to_process, length);
			break;
	}

	return error_number;
}