mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Added support for 'X' in Telepen Numeric and changed errno for error_number
This commit is contained in:
parent
eaf7cf1d3e
commit
b79399a5cc
@ -19,6 +19,8 @@
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define NASET "0123456789X"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -51,10 +53,10 @@ int telepen(struct zint_symbol *symbol, unsigned char source[])
|
|||||||
{
|
{
|
||||||
unsigned int i, count, check_digit;
|
unsigned int i, count, check_digit;
|
||||||
int ascii_value;
|
int ascii_value;
|
||||||
int errno;
|
int error_number;
|
||||||
char dest[1000];
|
char dest[1000];
|
||||||
|
|
||||||
errno = 0;
|
error_number = 0;
|
||||||
strcpy(dest, "");
|
strcpy(dest, "");
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
@ -90,56 +92,68 @@ int telepen(struct zint_symbol *symbol, unsigned char source[])
|
|||||||
|
|
||||||
expand(symbol, dest);
|
expand(symbol, dest);
|
||||||
strcpy(symbol->text, source);
|
strcpy(symbol->text, source);
|
||||||
return errno;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
int telepen_num(struct zint_symbol *symbol, unsigned char source[])
|
int telepen_num(struct zint_symbol *symbol, unsigned char source[])
|
||||||
{
|
{
|
||||||
unsigned int i, count, check_digit, glyph;
|
unsigned int i, count, check_digit, glyph;
|
||||||
int errno;
|
int error_number, input_length;
|
||||||
char dest[1000];
|
char dest[1000];
|
||||||
|
char local_source[100];
|
||||||
|
|
||||||
errno = 0;
|
error_number = 0;
|
||||||
strcpy(dest, "");
|
strcpy(dest, "");
|
||||||
|
strcpy(local_source, source);
|
||||||
|
input_length = strlen(source);
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
if(strlen(source) > 60) {
|
if(input_length > 60) {
|
||||||
strcpy(symbol->errtxt, "error: input too long");
|
strcpy(symbol->errtxt, "error: input too long");
|
||||||
return ERROR_TOO_LONG;
|
return ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
errno = is_sane(NESET, source);
|
to_upper(local_source);
|
||||||
if(errno == ERROR_INVALID_DATA) {
|
error_number = is_sane(NASET, local_source);
|
||||||
|
if(error_number == ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "error: invalid characters in data");
|
strcpy(symbol->errtxt, "error: invalid characters in data");
|
||||||
return errno;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add a leading zero if required */
|
/* Add a leading zero if required */
|
||||||
if ((strlen(source)%2) != 0)
|
if ((input_length % 2) != 0)
|
||||||
{
|
{
|
||||||
unsigned int length;
|
|
||||||
char temp[200];
|
char temp[200];
|
||||||
|
|
||||||
length = strlen(source);
|
strcpy(temp, local_source);
|
||||||
|
local_source[0] = '0';
|
||||||
|
|
||||||
strcpy(temp, source);
|
for(i = 0; i <= input_length; i++)
|
||||||
source[0] = '0';
|
|
||||||
|
|
||||||
for(i = 0; i <= length; i++)
|
|
||||||
{
|
{
|
||||||
source[i + 1] = temp[i];
|
local_source[i + 1] = temp[i];
|
||||||
}
|
}
|
||||||
|
input_length++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start character */
|
/* Start character */
|
||||||
concat(dest, TeleTable['_']);
|
concat(dest, TeleTable['_']);
|
||||||
|
|
||||||
for (i=0; i < strlen(source); i+=2)
|
for (i=0; i < input_length; i+=2)
|
||||||
{
|
{
|
||||||
glyph = (10 * ctoi(source[i])) + ctoi(source[i + 1]);
|
if(local_source[i] == 'X') {
|
||||||
glyph += 27;
|
strcpy(symbol->errtxt, "Invalid position of X in Telepen data");
|
||||||
concat(dest, TeleTable[glyph]);
|
return ERROR_INVALID_DATA;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(local_source[i + 1] == 'X') {
|
||||||
|
glyph = ctoi(local_source[i]) + 17;
|
||||||
count += glyph;
|
count += glyph;
|
||||||
|
} else {
|
||||||
|
glyph = (10 * ctoi(local_source[i])) + ctoi(local_source[i + 1]);
|
||||||
|
glyph += 27;
|
||||||
|
count += glyph;
|
||||||
|
}
|
||||||
|
concat(dest, TeleTable[glyph]);
|
||||||
}
|
}
|
||||||
|
|
||||||
check_digit = 127 - (count % 127);
|
check_digit = 127 - (count % 127);
|
||||||
@ -149,7 +163,7 @@ int telepen_num(struct zint_symbol *symbol, unsigned char source[])
|
|||||||
concat(dest, TeleTable['z']);
|
concat(dest, TeleTable['z']);
|
||||||
|
|
||||||
expand(symbol, dest);
|
expand(symbol, dest);
|
||||||
strcpy(symbol->text, source);
|
strcpy(symbol->text, local_source);
|
||||||
return errno;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user