Improvements from Oxy patch

Original email reads...
It does not contain any fundamental changes or new functions but a lot of improvements which I have done over time (added several const/static specifiers, replaced repeated if-conditions by if-else, removed some warnings).
This commit is contained in:
Robin Stuart 2016-02-29 19:42:32 +00:00
parent 922ee489a9
commit 5d9ce6f684
20 changed files with 244 additions and 236 deletions

View file

@ -109,7 +109,7 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
unsigned int loopey, reader, h;
char data_pattern[200];
char fcc[3] = {0, 0}, dpid[10];
char fcc[3] = {0, 0, 0}, dpid[10];
char localstr[30];
error_number = 0;

View file

@ -52,7 +52,7 @@ void mapshorten(int *charmap, int *typemap, int start, int length) {
* Insert a character into the middle of a string at position posn
*/
void insert(char binary_string[], int posn, char newbit) {
int i, end;
size_t i, end;
end = strlen(binary_string);
for (i = end; i > posn; i--) {
@ -81,7 +81,7 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
maplength = 0;
debug = 0;
for (i = 0; i < src_len; i++) {
for (i = 0; i < (int) src_len; i++) {
if (gs1 && (i == 0)) {
/* Add FNC1 to beginning of GS1 messages */
charmap[maplength] = 0;
@ -109,7 +109,7 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
/* Look for double character encoding possibilities */
i = 0;
do {
if (((charmap[i] == 300) && (charmap[i + 1] == 11))
if (((charmap[i] == 300) && (charmap[i + 1] == 11))
&& ((typemap[i] == PUNC) && (typemap[i + 1] == PUNC))) {
/* CR LF combination */
charmap[i] = 2;
@ -118,7 +118,7 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
maplength--;
}
if (((charmap[i] == 302) && (charmap[i + 1] == 1))
if (((charmap[i] == 302) && (charmap[i + 1] == 1))
&& ((typemap[i] == 24) && (typemap[i + 1] == 23))) {
/* . SP combination */
charmap[i] = 3;
@ -127,7 +127,7 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
maplength--;
}
if (((charmap[i] == 301) && (charmap[i + 1] == 1))
if (((charmap[i] == 301) && (charmap[i + 1] == 1))
&& ((typemap[i] == 24) && (typemap[i + 1] == 23))) {
/* , SP combination */
charmap[i] = 4;
@ -136,7 +136,7 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
maplength--;
}
if (((charmap[i] == 21) && (charmap[i + 1] == 1))
if (((charmap[i] == 21) && (charmap[i + 1] == 1))
&& ((typemap[i] == PUNC) && (typemap[i + 1] == 23))) {
/* : SP combination */
charmap[i] = 5;
@ -629,7 +629,7 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
if (bytes > 31) {
/* Put 00000 followed by 11-bit number of bytes less 31 */
concat(binary_string, "00000");
for (p = 0; p < 11; p++) {
if ((bytes - 31) & (0x400 >> p)) {
concat(binary_string, "1");
@ -1000,8 +1000,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length) {
break;
}
if (layers == 0) {
/* Couldn't find a symbol which fits the data */
if (layers == 0) { /* Couldn't find a symbol which fits the data */
strcpy(symbol->errtxt, "Input too long (too many bits for selected ECC)");
return ZINT_ERROR_TOO_LONG;
}
@ -1299,7 +1298,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length) {
break;
case 10:
for (i = 0; i < data_blocks; i++) {
for(p = 0; p < 10; p++) {
for (p = 0; p < 10; p++) {
if (adjusted_string[i * codeword_size + p] == '1') {
data_part[i] += (0x200 >> p);
}

View file

@ -132,7 +132,7 @@ int code_11(struct zint_symbol *symbol, unsigned char source[], int length) { /*
strcpy(dest, "112211");
/* Draw main body of barcode */
for (i = 0; i < length; i++) {
for (i = 0; i < (unsigned int) length; i++) {
lookup(SODIUM, C11Table, source[i], dest);
if (source[i] == '-')
weight[i] = 10;
@ -187,7 +187,7 @@ int code_11(struct zint_symbol *symbol, unsigned char source[], int length) { /*
}
/* Code 39 */
int c39(struct zint_symbol *symbol, unsigned char source[], int length) {
int c39(struct zint_symbol *symbol, unsigned char source[], int length) {
unsigned int i;
unsigned int counter;
char check_digit;
@ -219,7 +219,7 @@ int c39(struct zint_symbol *symbol, unsigned char source[], int length) {
/* Start character */
strcpy(dest, "1211212111");
for (i = 0; i < length; i++) {
for (i = 0; i < (unsigned int) length; i++) {
lookup(SILVER, C39Table, source[i], dest);
counter += posn(SILVER, source[i]);
}
@ -292,7 +292,7 @@ int c39(struct zint_symbol *symbol, unsigned char source[], int length) {
}
/* Pharmazentral Nummer (PZN) */
int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length) {
int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number, zeroes;
unsigned int count, check_digit;
@ -338,7 +338,7 @@ int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length
}
/* Extended Code 39 - ISO/IEC 16388:2007 Annex A */
int ec39(struct zint_symbol *symbol, unsigned char source[], int length) {
int ec39(struct zint_symbol *symbol, unsigned char source[], int length) {
unsigned char buffer[150] = {0};
unsigned int i;
@ -352,7 +352,7 @@ int ec39(struct zint_symbol *symbol, unsigned char source[], int length) {
}
/* Creates a buffer string and places control characters into it */
for (i = 0; i < length; i++) {
for (i = 0; i < (unsigned int) length; i++) {
if (source[i] > 127) {
/* Cannot encode extended ASCII */
strcpy(symbol->errtxt, "Invalid characters in input data");
@ -364,7 +364,7 @@ int ec39(struct zint_symbol *symbol, unsigned char source[], int length) {
/* Then sends the buffer to the C39 function */
error_number = c39(symbol, buffer, ustrlen(buffer));
for (i = 0; i < length; i++)
for (i = 0; i < (unsigned int) length; i++)
symbol->text[i] = source[i] ? source[i] : ' ';
symbol->text[length] = '\0';
@ -372,7 +372,7 @@ int ec39(struct zint_symbol *symbol, unsigned char source[], int length) {
}
/* Code 93 is an advancement on Code 39 and the definition is a lot tighter */
int c93(struct zint_symbol *symbol, unsigned char source[], int length) {
int c93(struct zint_symbol *symbol, unsigned char source[], int length) {
/* SILVER includes the extra characters a, b, c and d to represent Code 93 specific
shift characters 1, 2, 3 and 4 respectively. These characters are never used by

View file

@ -289,25 +289,25 @@ int c1_look_ahead_test(unsigned char source[], int sourcelen, int position, int
if (sp == sourcelen) {
/* Step K */
best_count = edi_count;
best_count = (int)edi_count;
if (text_count <= best_count) {
best_count = text_count;
best_count = (int)text_count;
best_scheme = C1_TEXT;
}
if (c40_count <= best_count) {
best_count = c40_count;
best_count = (int)c40_count;
best_scheme = C1_C40;
}
if (ascii_count <= best_count) {
best_count = ascii_count;
best_count = (int)ascii_count;
best_scheme = C1_ASCII;
}
if (byte_count <= best_count) {
best_count = byte_count;
best_count = (int)byte_count;
best_scheme = C1_BYTE;
}
} else {
@ -1052,7 +1052,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
strcpy(temp_binary, "");
if (strlen(decimal_binary) > 24) {
for (i = 0; i <= (strlen(decimal_binary) - 24); i++) {
for(i = 0; i <= (int)(strlen(decimal_binary) - 24); i++) {
temp_binary[i] = decimal_binary[i + 24];
}
strcpy(decimal_binary, temp_binary);

View file

@ -75,7 +75,7 @@ static const char *C128Table[107] = {
};
/* Determine appropriate mode for a given character */
int parunmodd(unsigned char llyth) {
int parunmodd(const unsigned char llyth) {
int modd;
modd = 0;
@ -281,7 +281,7 @@ void c128_set_b(unsigned char source, char dest[], int values[], int *bar_chars)
/* Translate Code 128 Set C characters into barcodes
* This set handles numbers in a compressed form
*/
void c128_set_c(unsigned char source_a, unsigned char source_b, char dest[], int values[], int *bar_chars) {
void c128_set_c(unsigned char source_a, unsigned char source_b, char dest[], int values[], int *bar_chars) {
int weight;
weight = (10 * ctoi(source_a)) + ctoi(source_b);
@ -291,7 +291,7 @@ void c128_set_c(unsigned char source_a, unsigned char source_b, char dest[], int
}
/* Handle Code 128 and NVE-18 */
int code_128(struct zint_symbol *symbol, unsigned char source[], int length) {
int code_128(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, j, k, values[170] = {0}, bar_characters, read, total_sum;
int error_number, indexchaine, indexliste, sourcelen, f_state;
char set[170] = {' '}, fset[170] = {' '}, mode, last_set, current_set = ' ';
@ -681,7 +681,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length) {
}
/* Handle EAN-128 (Now known as GS1-128) */
int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) {
int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, j, values[170], bar_characters, read, total_sum;
int error_number, indexchaine, indexliste;
char set[170], mode, last_set;
@ -748,7 +748,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) {
do {
list[1][indexliste] = mode;
while ((list[1][indexliste] == mode) && (indexchaine < strlen(reduced))) {
while ((list[1][indexliste] == mode) && (indexchaine < (int) strlen(reduced))) {
list[0][indexliste]++;
indexchaine++;
mode = parunmodd(reduced[indexchaine]);
@ -757,7 +757,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) {
}
}
indexliste++;
} while (indexchaine < strlen(reduced));
} while (indexchaine < (int) strlen(reduced));
dxsmooth(&indexliste);
@ -825,7 +825,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) {
being too long */
last_set = ' ';
glyph_count = 0.0;
for (i = 0; i < strlen(reduced); i++) {
for (i = 0; i < (int) strlen(reduced); i++) {
if ((set[i] == 'a') || (set[i] == 'b')) {
glyph_count = glyph_count + 1.0;
}
@ -919,7 +919,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) {
bar_characters++;
read++;
}
} while (read < strlen(reduced));
} while (read < (int) strlen(reduced));
/* "...note that the linkage flag is an extra code set character between
the last data character and the Symbol Check Character" (GS1 Specification) */

View file

@ -113,7 +113,7 @@ void grwp16(int *indexliste) {
}
/* Implements rules from ISO 15417 Annex E */
void dxsmooth16(int *indexliste) {
void dxsmooth16(int *indexliste) {
int i, current, last, next, length;
for (i = 0; i < *(indexliste); i++) {
@ -285,7 +285,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) {
bar_characters = 0;
/* Detect extended ASCII characters */
for (i = 0; i < input_length; i++) {
for (i = 0; i < (unsigned int) input_length; i++) {
if (source[i] >= 128) {
fset[i] = 'f';
}
@ -293,7 +293,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) {
fset[i] = '\0';
/* Decide when to latch to extended mode */
for (i = 0; i < input_length; i++) {
for (i = 0; i < (unsigned int) input_length; i++) {
j = 0;
if (fset[i] == 'f') {
do {
@ -309,10 +309,10 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) {
/* Decide if it is worth reverting to 646 encodation for a few characters */
if (input_length > 1) {
for (i = 1; i < input_length; i++) {
for (i = 1; i < (unsigned int) input_length; i++) {
if ((fset[i - 1] == 'F') && (fset[i] == ' ')) {
/* Detected a change from 8859-1 to 646 - count how long for */
for (j = 0; (fset[i + j] == ' ') && ((i + j) < input_length); j++);
for (j = 0; (fset[i + j] == ' ') && ((i + j) < (unsigned int) input_length); j++);
if ((j < 5) || ((j < 3) && ((i + j) == (input_length - 1)))) {
/* Change to shifting back rather than latching back */
for (k = 0; k < j; k++) {
@ -543,7 +543,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) {
current_set = set[0];
f_state = 0;
/* f_state remembers if we are in Extended ASCII mode (value 1) or
in ISO/IEC 646 mode (value 0) */
in ISO/IEC 646 mode (value 0) */
if (fset[0] == 'F') {
switch (current_set) {
case 'A':

View file

@ -42,7 +42,7 @@
int code_49(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, j, rows, M, x_count, y_count, z_count, posn_val, local_value, h;
char intermediate[170];
char intermediate[170] = "";
int codewords[170], codeword_count;
int c_grid[8][8]; /* Refers to table 3 */
int w_grid[8][4]; /* Refets to table 2 */
@ -195,7 +195,7 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length) {
} while (i < h);
switch (codewords[0]) {
/* Set starting mode value */
/* Set starting mode value */
case 48: M = 2;
break;
case 43: M = 4;

View file

@ -54,8 +54,8 @@ void ustrcpy(unsigned char target[], const unsigned char source[]) {
}
/* Concatinates dest[] with the contents of source[], copying /0 as well */
void concat(char dest[], const char source[]) {
unsigned int i, j, n;
void concat(char dest[], const char source[]) {
size_t i, j, n;
j = strlen(dest);
n = strlen(source);
@ -65,7 +65,7 @@ void concat(char dest[], const char source[]) {
}
/* Concatinates dest[] with the contents of source[], copying /0 as well */
void uconcat(unsigned char dest[], const unsigned char source[]) {
void uconcat(unsigned char dest[], const unsigned char source[]) {
unsigned int i, j;
j = ustrlen(dest);
@ -75,14 +75,14 @@ void uconcat(unsigned char dest[], const unsigned char source[]) {
}
/* Converts a character 0-9 to its equivalent integer value */
int ctoi(char source) {
int ctoi(const char source) {
if ((source >= '0') && (source <= '9'))
return (source - '0');
return (source - 'A' + 10);
}
/* Converts an integer value to its hexadecimal character */
char itoc(int source) {
char itoc(const int source) {
if ((source >= 0) && (source <= 9)) {
return ('0' + source);
} else {
@ -91,7 +91,7 @@ char itoc(int source) {
}
/* Converts lower case characters to upper case in a string source[] */
void to_upper(unsigned char source[]) {
void to_upper(unsigned char source[]) {
unsigned int i, src_len = ustrlen(source);
for (i = 0; i < src_len; i++) {
@ -102,7 +102,7 @@ void to_upper(unsigned char source[]) {
}
/* Verifies that a string only uses valid characters */
int is_sane(char test_string[], unsigned char source[], int length) {
int is_sane(char test_string[], const unsigned char source[], const int length) {
unsigned int i, j, latch;
unsigned int lt = strlen(test_string);
@ -123,7 +123,7 @@ int is_sane(char test_string[], unsigned char source[], int length) {
}
/* Returns the position of data in set_string */
int posn(char set_string[], char data) {
int posn(char set_string[], const char data) {
unsigned int i, n = strlen(set_string);
for (i = 0; i < n; i++) {
@ -135,7 +135,7 @@ int posn(char set_string[], char data) {
}
/* Replaces huge switch statements for looking up in tables */
void lookup(char set_string[], const char *table[], char data, char dest[]) {
void lookup(char set_string[], const char *table[], const char data, char dest[]) {
unsigned int i, n = strlen(set_string);
for (i = 0; i < n; i++) {
@ -146,22 +146,22 @@ void lookup(char set_string[], const char *table[], char data, char dest[]) {
}
/* Return true (1) if a module is dark/black, orherwise false (0) */
int module_is_set(struct zint_symbol *symbol, int y_coord, int x_coord) {
int module_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord) {
return (symbol->encoded_data[y_coord][x_coord / 7] >> (x_coord % 7)) & 1;
}
/* Set a module to dark/black */
void set_module(struct zint_symbol *symbol, int y_coord, int x_coord) {
void set_module(struct zint_symbol *symbol, const int y_coord, const int x_coord) {
symbol->encoded_data[y_coord][x_coord / 7] |= 1 << (x_coord % 7);
}
/* Set (or unset) a module to white */
void unset_module(struct zint_symbol *symbol, int y_coord, int x_coord) {
void unset_module(struct zint_symbol *symbol, const int y_coord, const int x_coord) {
symbol->encoded_data[y_coord][x_coord / 7] &= ~(1 << (x_coord % 7));
}
/* Expands from a width pattern to a bit pattern */
void expand(struct zint_symbol *symbol, char data[]) {
void expand(struct zint_symbol *symbol, char data[]) {
unsigned int reader, n = strlen(data);
int writer, i;
@ -231,7 +231,7 @@ int is_stackable(int symbology) {
}
/* Indicates which symbols can have addon (EAN-2 and EAN-5) */
int is_extendable(int symbology) {
int is_extendable(const int symbology) {
if (symbology == BARCODE_EANX) {
return 1;
}
@ -257,21 +257,21 @@ int is_extendable(int symbology) {
return 0;
}
int roundup(float input) {
int roundup(const float input) {
float remainder;
int integer_part;
integer_part = (int) input;
remainder = input - integer_part;
if (remainder > 0.1) {
if (remainder > 0.1F) {
integer_part++;
}
return integer_part;
}
int istwodigits(unsigned char source[], int position) {
int istwodigits(const unsigned char source[], const int position) {
if ((source[position] >= '0') && (source[position] <= '9')) {
if ((source[position + 1] >= '0') && (source[position + 1] <= '9')) {
return 1;
@ -281,8 +281,8 @@ int istwodigits(unsigned char source[], int position) {
return 0;
}
float froundup(float input) {
float fraction, output = 0.0;
double froundup(const double input) {
double fraction, output = 0.0;
fraction = input - (int) input;
if (fraction > 0.01) {
@ -295,7 +295,7 @@ float froundup(float input) {
}
/* Convert Unicode to Latin-1 for those symbologies which only support Latin-1 */
int latin1_process(struct zint_symbol *symbol, unsigned char source[], unsigned char preprocessed[], int *length) {
int latin1_process(struct zint_symbol *symbol, const unsigned char source[], unsigned char preprocessed[], int *length) {
int j, i, next;
j = 0;
@ -330,7 +330,7 @@ int latin1_process(struct zint_symbol *symbol, unsigned char source[], unsigned
return 0;
}
int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[], int *length) {
int utf8toutf16(struct zint_symbol *symbol, const unsigned char source[], int vals[], int *length) {
int bpos, jpos, error_number;
int next;

View file

@ -55,24 +55,24 @@ extern "C" {
extern void ustrcpy(unsigned char target[], const unsigned char source[]);
extern void concat(char dest[], const char source[]);
extern void uconcat(unsigned char dest[], const unsigned char source[]);
extern int ctoi(char source);
extern char itoc(int source);
extern int ctoi(const char source);
extern char itoc(const int source);
extern void to_upper(unsigned char source[]);
extern int is_sane(char test_string[], unsigned char source[], int length);
extern void lookup(char set_string[], const char *table[], char data, char dest[]);
extern int posn(char set_string[], char data);
extern int is_sane(char test_string[], const unsigned char source[], const int length);
extern void lookup(char set_string[], const char *table[], const char data, char dest[]);
extern int posn(char set_string[], const char data);
extern void expand(struct zint_symbol *symbol, char data[]);
extern int is_stackable(int symbology);
extern int is_extendable(int symbology);
extern int roundup(float input);
extern int module_is_set(struct zint_symbol *symbol, int y_coord, int x_coord);
extern void set_module(struct zint_symbol *symbol, int y_coord, int x_coord);
extern void unset_module(struct zint_symbol *symbol, int y_coord, int x_coord);
extern int istwodigits(unsigned char source[], int position);
extern float froundup(float input);
extern int parunmodd(unsigned char llyth);
extern int latin1_process(struct zint_symbol *symbol, unsigned char source[], unsigned char preprocessed[], int *length);
extern int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[], int *length);
extern int is_stackable(const int symbology);
extern int is_extendable(const int symbology);
extern int roundup(const float input);
extern int module_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord);
extern void set_module(struct zint_symbol *symbol, const int y_coord, const int x_coord);
extern void unset_module(struct zint_symbol *symbol, const int y_coord, const int x_coord);
extern int istwodigits(const unsigned char source[], const int position);
extern double froundup(const double input);
extern int parunmodd(const unsigned char llyth);
extern int latin1_process(struct zint_symbol *symbol, const unsigned char source[], unsigned char preprocessed[], int *length);
extern int utf8toutf16(struct zint_symbol *symbol, const unsigned char source[], int vals[], int *length);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View file

@ -129,7 +129,7 @@ int encode928(UINT bitString[], UINT codeWords[], int bitLng) {
}
/* CC-A 2D component */
int cc_a(struct zint_symbol *symbol, char source[], int cc_width) {
int cc_a(struct zint_symbol *symbol, char source[], int cc_width) {
int i, strpos, segment, bitlen, cwCnt, variant, rows;
int k, offset, j, total, rsCodeWords[8];
int LeftRAPStart, RightRAPStart, CentreRAPStart, StartCluster;
@ -307,7 +307,7 @@ int cc_a(struct zint_symbol *symbol, char source[], int cc_width) {
writer = 0;
flip = 1;
strcpy(pattern, "");
for (loop = 0; loop < strlen(codebarre); loop++) {
for (loop = 0; loop < (int) strlen(codebarre); loop++) {
if ((codebarre[loop] >= '0') && (codebarre[loop] <= '9')) {
for (k = 0; k < ctoi(codebarre[loop]); k++) {
if (flip == 0) {
@ -331,7 +331,7 @@ int cc_a(struct zint_symbol *symbol, char source[], int cc_width) {
symbol->width = writer;
/* so now pattern[] holds the string of '1's and '0's. - copy this to the symbol */
for (loop = 0; loop < strlen(pattern); loop++) {
for (loop = 0; loop < (int) strlen(pattern); loop++) {
if (pattern[loop] == '1') {
set_module(symbol, i, loop);
}
@ -363,7 +363,7 @@ int cc_a(struct zint_symbol *symbol, char source[], int cc_width) {
}
/* CC-B 2D component */
int cc_b(struct zint_symbol *symbol, char source[], int cc_width) {
int cc_b(struct zint_symbol *symbol, char source[], int cc_width) {
int length, i, binloc;
#ifndef _MSC_VER
unsigned char data_string[(strlen(source) / 8) + 3];
@ -591,7 +591,7 @@ int cc_b(struct zint_symbol *symbol, char source[], int cc_width) {
writer = 0;
flip = 1;
strcpy(pattern, "");
for (loop = 0; loop < strlen(codebarre); loop++) {
for (loop = 0; loop < (int) strlen(codebarre); loop++) {
if ((codebarre[loop] >= '0') && (codebarre[loop] <= '9')) {
for (k = 0; k < ctoi(codebarre[loop]); k++) {
if (flip == 0) {
@ -615,7 +615,7 @@ int cc_b(struct zint_symbol *symbol, char source[], int cc_width) {
symbol->width = writer;
/* so now pattern[] holds the string of '1's and '0's. - copy this to the symbol */
for (loop = 0; loop < strlen(pattern); loop++) {
for (loop = 0; loop < (int) strlen(pattern); loop++) {
if (pattern[loop] == '1') {
set_module(symbol, i, loop);
}
@ -646,7 +646,7 @@ int cc_b(struct zint_symbol *symbol, char source[], int cc_width) {
}
/* CC-C 2D component - byte compressed PDF417 */
int cc_c(struct zint_symbol *symbol, char source[], int cc_width, int ecc_level) {
int cc_c(struct zint_symbol *symbol, char source[], int cc_width, int ecc_level) {
int length, i, p, binloc;
#ifndef _MSC_VER
unsigned char data_string[(strlen(source) / 8) + 4];
@ -765,12 +765,12 @@ int cc_c(struct zint_symbol *symbol, char source[], int cc_width, int ecc_level)
for (j = 0; j <= cc_width + 1; j++) {
switch (i % 3) {
case 1: offset = 929; /* cluster(3) */
case 1: offset = 929; /* cluster(3) */
break;
case 2: offset = 1858; /* cluster(6) */
case 2: offset = 1858; /* cluster(6) */
break;
default: offset = 0; /* cluster(0) */
break;
break;
}
concat(codebarre, codagemc[offset + dummy[j]]);
concat(codebarre, "*");
@ -778,10 +778,10 @@ int cc_c(struct zint_symbol *symbol, char source[], int cc_width, int ecc_level)
concat(codebarre, "-");
strcpy(pattern, "");
for (loop = 0; loop < strlen(codebarre); loop++) {
for (loop = 0; loop < (int) strlen(codebarre); loop++) {
lookup(BRSET, PDFttf, codebarre[loop], pattern);
}
for (loop = 0; loop < strlen(pattern); loop++) {
for (loop = 0; loop < (int) strlen(pattern); loop++) {
if (pattern[loop] == '1') {
set_module(symbol, i, loop);
}
@ -914,7 +914,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar
alphanum = 0;
numeric = 0;
for (i = 0; i < strlen(ninety); i++) {
for (i = 0; i < (int) strlen(ninety); i++) {
if ((ninety[i] >= 'A') && (ninety[i] <= 'Z')) {
/* Character is alphabetic */
@ -1217,7 +1217,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar
j++;
}
for (i = read_posn; i < strlen(source); i++) {
for (i = read_posn; i < (int) strlen(source); i++) {
general_field[j] = source[i];
j++;
}
@ -1228,7 +1228,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar
}
latch = 0;
for (i = 0; i < strlen(general_field); i++) {
for (i = 0; i < (int) strlen(general_field); i++) {
/* Table 13 - ISO/IEC 646 encodation */
if ((general_field[i] < ' ') || (general_field[i] > 'z')) {
general_field_type[i] = INVALID_CHAR;
@ -1301,13 +1301,13 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar
return ZINT_ERROR_INVALID_DATA;
}
for (i = 0; i < strlen(general_field); i++) {
for (i = 0; i < (int) strlen(general_field); i++) {
if ((general_field_type[i] == ISOIEC) && (general_field[i + 1] == '[')) {
general_field_type[i + 1] = ISOIEC;
}
}
for (i = 0; i < strlen(general_field); i++) {
for (i = 0; i < (int) strlen(general_field); i++) {
if ((general_field_type[i] == ALPHA_OR_ISO) && (general_field[i + 1] == '[')) {
general_field_type[i + 1] = ALPHA_OR_ISO;
}
@ -1487,7 +1487,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar
i++;
break;
}
} while (i + latch < strlen(general_field));
} while (i + latch < (int) strlen(general_field));
binary_length = strlen(binary_string);
if (cc_mode == 1) {
@ -2031,11 +2031,11 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar
concat(binary_string, "0000");
}
while (strlen(binary_string) < target_bitsize) {
while (strlen(binary_string) < (unsigned int) target_bitsize) {
concat(binary_string, "00100");
}
if (strlen(binary_string) > target_bitsize) {
if (strlen(binary_string) > (unsigned int) target_bitsize) {
binary_string[target_bitsize] = '\0';
}
}
@ -2244,7 +2244,7 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length) {
}
switch (cc_mode) {
/* Note that ecc_level is only relevant to CC-C */
/* Note that ecc_level is only relevant to CC-C */
case 1: error_number = cc_a(symbol, binary_string, cc_width);
break;
case 2: error_number = cc_b(symbol, binary_string, cc_width);

View file

@ -51,8 +51,8 @@
#include "common.h"
#include "dmatrix.h"
// Annex M placement alorithm low level
static void ecc200placementbit(int *array, int NR, int NC, int r, int c, int p, char b) {
/* Annex M placement alorithm low level */
static void ecc200placementbit(int *array, const int NR, const int NC, int r, int c, const int p, const char b) {
if (r < 0) {
r += NR;
c += 4 - ((NR + 4) % 8);
@ -86,7 +86,8 @@ static void ecc200placementbit(int *array, int NR, int NC, int r, int c, int p,
array[r * NC + c] = (p << 3) + b;
}
static void ecc200placementblock(int *array, int NR, int NC, int r, int c, int p) {
static void ecc200placementblock(int *array, const int NR, const int NC, const int r,
const int c, const int p) {
ecc200placementbit(array, NR, NC, r - 2, c - 2, p, 7);
ecc200placementbit(array, NR, NC, r - 2, c - 1, p, 6);
ecc200placementbit(array, NR, NC, r - 1, c - 2, p, 5);
@ -97,7 +98,7 @@ static void ecc200placementblock(int *array, int NR, int NC, int r, int c, int p
ecc200placementbit(array, NR, NC, r - 0, c - 0, p, 0);
}
static void ecc200placementcornerA(int *array, int NR, int NC, int p) {
static void ecc200placementcornerA(int *array, const int NR, const int NC, const int p) {
ecc200placementbit(array, NR, NC, NR - 1, 0, p, 7);
ecc200placementbit(array, NR, NC, NR - 1, 1, p, 6);
ecc200placementbit(array, NR, NC, NR - 1, 2, p, 5);
@ -108,7 +109,7 @@ static void ecc200placementcornerA(int *array, int NR, int NC, int p) {
ecc200placementbit(array, NR, NC, 3, NC - 1, p, 0);
}
static void ecc200placementcornerB(int *array, int NR, int NC, int p) {
static void ecc200placementcornerB(int *array, const int NR, const int NC, const int p) {
ecc200placementbit(array, NR, NC, NR - 3, 0, p, 7);
ecc200placementbit(array, NR, NC, NR - 2, 0, p, 6);
ecc200placementbit(array, NR, NC, NR - 1, 0, p, 5);
@ -119,7 +120,7 @@ static void ecc200placementcornerB(int *array, int NR, int NC, int p) {
ecc200placementbit(array, NR, NC, 1, NC - 1, p, 0);
}
static void ecc200placementcornerC(int *array, int NR, int NC, int p) {
static void ecc200placementcornerC(int *array, const int NR, const int NC, const int p) {
ecc200placementbit(array, NR, NC, NR - 3, 0, p, 7);
ecc200placementbit(array, NR, NC, NR - 2, 0, p, 6);
ecc200placementbit(array, NR, NC, NR - 1, 0, p, 5);
@ -130,7 +131,7 @@ static void ecc200placementcornerC(int *array, int NR, int NC, int p) {
ecc200placementbit(array, NR, NC, 3, NC - 1, p, 0);
}
static void ecc200placementcornerD(int *array, int NR, int NC, int p) {
static void ecc200placementcornerD(int *array, const int NR, const int NC, const int p) {
ecc200placementbit(array, NR, NC, NR - 1, 0, p, 7);
ecc200placementbit(array, NR, NC, NR - 1, NC - 1, p, 6);
ecc200placementbit(array, NR, NC, 0, NC - 3, p, 5);
@ -141,8 +142,8 @@ static void ecc200placementcornerD(int *array, int NR, int NC, int p) {
ecc200placementbit(array, NR, NC, 1, NC - 1, p, 0);
}
// Annex M placement alorithm main function
static void ecc200placement(int *array, int NR, int NC) {
/* Annex M placement alorithm main function */
static void ecc200placement(int *array, const int NR, const int NC) {
int r, c, p;
// invalidate
for (r = 0; r < NR; r++)
@ -186,8 +187,8 @@ static void ecc200placement(int *array, int NR, int NC) {
array[NR * NC - 1] = array[NR * NC - NC - 2] = 1;
}
// calculate and append ecc code, and if necessary interleave
static void ecc200(unsigned char *binary, int bytes, int datablock, int rsblock, int skew) {
/* calculate and append ecc code, and if necessary interleave */
static void ecc200(unsigned char *binary, const int bytes, const int datablock, const int rsblock, const int skew) {
int blocks = (bytes + 2) / datablock, b;
int n, p;
rs_init_gf(0x12d);
@ -217,7 +218,7 @@ static void ecc200(unsigned char *binary, int bytes, int datablock, int rsblock,
}
/* Return true (1) if a character is valid in X12 set */
int isX12(unsigned char source) {
static int isX12(const int source) {
if (source == 13) {
return 1;
}
@ -241,17 +242,17 @@ int isX12(unsigned char source) {
}
/* Insert a character into the middle of a string at position posn */
void dminsert(char binary_string[], int posn, char newbit) {
static void dminsert(char binary_string[], const int posn, const char newbit) {
int i, end;
end = strlen(binary_string);
end = (int) strlen(binary_string);
for (i = end; i > posn; i--) {
binary_string[i] = binary_string[i - 1];
}
binary_string[posn] = newbit;
}
void insert_value(unsigned char binary_stream[], int posn, int streamlen, char newbit) {
static void insert_value(unsigned char binary_stream[], const int posn, const int streamlen, const int newbit) {
int i;
for (i = streamlen; i > posn; i--) {
@ -260,7 +261,7 @@ void insert_value(unsigned char binary_stream[], int posn, int streamlen, char n
binary_stream[posn] = newbit;
}
int p_r_6_2_1(unsigned char inputData[], int position, int sourcelen) {
int p_r_6_2_1(const unsigned char inputData[], int position, const int sourcelen) {
/* Annex P section (r)(6)(ii)(I)
"If one of the three X12 terminator/separator characters first
occurs in the yet to be processed data before a non-X12 character..."
@ -297,7 +298,7 @@ int p_r_6_2_1(unsigned char inputData[], int position, int sourcelen) {
}
/* 'look ahead test' from Annex P */
int look_ahead_test(unsigned char inputData[], int sourcelen, int position, int current_mode, int gs1) {
static int look_ahead_test(const unsigned char inputData[], const int sourcelen, const int position, const int current_mode, const int gs1) {
float ascii_count, c40_count, text_count, x12_count, edf_count, b256_count, best_count;
int sp, best_scheme;
@ -338,12 +339,12 @@ int look_ahead_test(unsigned char inputData[], int sourcelen, int position, int
do {
if (sp == (sourcelen - 1)) {
/* At the end of data ... step (k) */
ascii_count = ceil(ascii_count);
b256_count = ceil(b256_count);
edf_count = ceil(edf_count);
text_count = ceil(text_count);
x12_count = ceil(x12_count);
c40_count = ceil(c40_count);
ascii_count = ceilf(ascii_count);
b256_count = ceilf(b256_count);
edf_count = ceilf(edf_count);
text_count = ceilf(text_count);
x12_count = ceilf(x12_count);
c40_count = ceilf(c40_count);
best_count = c40_count;
best_scheme = DM_C40; // (k)(7)
@ -375,12 +376,12 @@ int look_ahead_test(unsigned char inputData[], int sourcelen, int position, int
/* ascii ... step (l) */
if ((inputData[sp] >= '0') && (inputData[sp] <= '9')) {
ascii_count += 0.5; // (l)(1)
ascii_count += 0.5F; // (l)(1)
} else {
if (inputData[sp] > 127) {
ascii_count = ceil(ascii_count) + 2.0; // (l)(2)
ascii_count = ceilf(ascii_count) + 2.0F; // (l)(2)
} else {
ascii_count = ceil(ascii_count) + 1.0; // (l)(3)
ascii_count = ceilf(ascii_count) + 1.0F; // (l)(3)
}
}
@ -388,12 +389,12 @@ int look_ahead_test(unsigned char inputData[], int sourcelen, int position, int
if ((inputData[sp] == ' ') ||
(((inputData[sp] >= '0') && (inputData[sp] <= '9')) ||
((inputData[sp] >= 'A') && (inputData[sp] <= 'Z')))) {
c40_count += (2.0 / 3.0); // (m)(1)
c40_count += (2.0F / 3.0F); // (m)(1)
} else {
if (inputData[sp] > 127) {
c40_count += (8.0 / 3.0); // (m)(2)
c40_count += (8.0F / 3.0F); // (m)(2)
} else {
c40_count += (4.0 / 3.0); // (m)(3)
c40_count += (4.0F / 3.0F); // (m)(3)
}
}
@ -401,45 +402,45 @@ int look_ahead_test(unsigned char inputData[], int sourcelen, int position, int
if ((inputData[sp] == ' ') ||
(((inputData[sp] >= '0') && (inputData[sp] <= '9')) ||
((inputData[sp] >= 'a') && (inputData[sp] <= 'z')))) {
text_count += (2.0 / 3.0); // (n)(1)
text_count += (2.0F / 3.0F); // (n)(1)
} else {
if (inputData[sp] > 127) {
text_count += (8.0 / 3.0); // (n)(2)
text_count += (8.0F / 3.0F); // (n)(2)
} else {
text_count += (4.0 / 3.0); // (n)(3)
text_count += (4.0F / 3.0F); // (n)(3)
}
}
/* x12 ... step (o) */
if (isX12(inputData[sp])) {
x12_count += (2.0 / 3.0); // (o)(1)
x12_count += (2.0F / 3.0F); // (o)(1)
} else {
if (inputData[sp] > 127) {
x12_count += (13.0 / 3.0); // (o)(2)
x12_count += (13.0F / 3.0F); // (o)(2)
} else {
x12_count += (10.0 / 3.0); // (o)(3)
x12_count += (10.0F / 3.0F); // (o)(3)
}
}
/* edifact ... step (p) */
if ((inputData[sp] >= ' ') && (inputData[sp] <= '^')) {
edf_count += (3.0 / 4.0); // (p)(1)
edf_count += (3.0F / 4.0F); // (p)(1)
} else {
if (inputData[sp] > 127) {
edf_count += (17.0 / 4.0); // (p)(2)
edf_count += (17.0F / 4.0F); // (p)(2)
} else {
edf_count += (13.0 / 4.0); // (p)(3)
edf_count += (13.0F / 4.0F); // (p)(3)
}
}
if ((gs1 == 1) && (inputData[sp] == '[')) {
edf_count += 6.0;
edf_count += 6.0F;
}
/* base 256 ... step (q) */
if ((gs1 == 1) && (inputData[sp] == '[')) {
b256_count += 4.0; // (q)(1)
b256_count += 4.0F; // (q)(1)
} else {
b256_count += 1.0; // (q)(2)
b256_count += 1.0F; // (q)(2)
}
}
@ -448,10 +449,10 @@ int look_ahead_test(unsigned char inputData[], int sourcelen, int position, int
/* 4 data characters processed ... step (r) */
/* step (r)(6) */
if (((c40_count + 1.0) < ascii_count) &&
((c40_count + 1.0) < b256_count) &&
((c40_count + 1.0) < edf_count) &&
((c40_count + 1.0) < text_count)) {
if (((c40_count + 1.0F) < ascii_count) &&
((c40_count + 1.0F) < b256_count) &&
((c40_count + 1.0F) < edf_count) &&
((c40_count + 1.0F) < text_count)) {
if (c40_count < x12_count) {
best_scheme = DM_C40;
@ -468,47 +469,47 @@ int look_ahead_test(unsigned char inputData[], int sourcelen, int position, int
}
/* step (r)(5) */
if (((x12_count + 1.0) < ascii_count) &&
((x12_count + 1.0) < b256_count) &&
((x12_count + 1.0) < edf_count) &&
((x12_count + 1.0) < text_count) &&
((x12_count + 1.0) < c40_count)) {
if (((x12_count + 1.0F) < ascii_count) &&
((x12_count + 1.0F) < b256_count) &&
((x12_count + 1.0F) < edf_count) &&
((x12_count + 1.0F) < text_count) &&
((x12_count + 1.0F) < c40_count)) {
best_scheme = DM_X12;
}
/* step (r)(4) */
if (((text_count + 1.0) < ascii_count) &&
((text_count + 1.0) < b256_count) &&
((text_count + 1.0) < edf_count) &&
((text_count + 1.0) < x12_count) &&
((text_count + 1.0) < c40_count)) {
if (((text_count + 1.0F) < ascii_count) &&
((text_count + 1.0F) < b256_count) &&
((text_count + 1.0F) < edf_count) &&
((text_count + 1.0F) < x12_count) &&
((text_count + 1.0F) < c40_count)) {
best_scheme = DM_TEXT;
}
/* step (r)(3) */
if (((edf_count + 1.0) < ascii_count) &&
((edf_count + 1.0) < b256_count) &&
((edf_count + 1.0) < text_count) &&
((edf_count + 1.0) < x12_count) &&
((edf_count + 1.0) < c40_count)) {
if (((edf_count + 1.0F) < ascii_count) &&
((edf_count + 1.0F) < b256_count) &&
((edf_count + 1.0F) < text_count) &&
((edf_count + 1.0F) < x12_count) &&
((edf_count + 1.0F) < c40_count)) {
best_scheme = DM_EDIFACT;
}
/* step (r)(2) */
if (((b256_count + 1.0) <= ascii_count) ||
(((b256_count + 1.0) < edf_count) &&
((b256_count + 1.0) < text_count) &&
((b256_count + 1.0) < x12_count) &&
((b256_count + 1.0) < c40_count))) {
if (((b256_count + 1.0F) <= ascii_count) ||
(((b256_count + 1.0F) < edf_count) &&
((b256_count + 1.0F) < text_count) &&
((b256_count + 1.0F) < x12_count) &&
((b256_count + 1.0F) < c40_count))) {
best_scheme = DM_BASE256;
}
/* step (r)(1) */
if (((ascii_count + 1.0) <= b256_count) &&
((ascii_count + 1.0) <= edf_count) &&
((ascii_count + 1.0) <= text_count) &&
((ascii_count + 1.0) <= x12_count) &&
((ascii_count + 1.0) <= c40_count)) {
if (((ascii_count + 1.0F) <= b256_count) &&
((ascii_count + 1.0F) <= edf_count) &&
((ascii_count + 1.0F) <= text_count) &&
((ascii_count + 1.0F) <= x12_count) &&
((ascii_count + 1.0F) <= c40_count)) {
best_scheme = DM_ASCII;
}
}
@ -1001,8 +1002,7 @@ int dm200encode_remainder(unsigned char target[], int target_length, unsigned ch
{
target[target_length] = source[inputlen - 1] + 1;
target_length++;
}
else if (process_p == 2) {
} else if (process_p == 2) {
target[target_length] = source[inputlen - 2] + 1;
target_length++;
target[target_length] = source[inputlen - 1] + 1;
@ -1079,8 +1079,7 @@ int dm200encode_remainder(unsigned char target[], int target_length, unsigned ch
if (symbols_left < 3) {
target[target_length] = 31;
target_length++;
}
else
} else
target[target_length] = (31 << 2);
target_length++;
@ -1179,17 +1178,17 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int leng
}
if (symbol->option_3 == DM_SQUARE) {
/* Skip rectangular symbols in square only mode */
/* Skip rectangular symbols in square only mode */
while (matrixH[calcsize] != matrixW[calcsize]) {
calcsize++;
}
}
} else if (symbol->option_3 != DM_DMRE) {
/* Skip DMRE symbols */
while (isDMRE[calcsize]) {
calcsize++;
}
}
/* Skip DMRE symbols */
while (isDMRE[calcsize]) {
calcsize++;
}
}
symbolsize = optionsize;
if (calcsize > optionsize) {
symbolsize = calcsize;
@ -1297,7 +1296,7 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int leng
return error_number;
}
int dmatrix(struct zint_symbol *symbol, unsigned char source[], int length) {
int dmatrix(struct zint_symbol *symbol, unsigned char source[], const int length) {
int error_number;
if (symbol->option_1 <= 1) {

View file

@ -312,9 +312,9 @@ int seek_forward(int gbdata[], int length, int position, int current_mode) {
}
/* Add the length indicator for byte encoded blocks */
void add_byte_count(char binary[], int byte_count_posn, int byte_count) {
static void add_byte_count(char binary[], const size_t byte_count_posn, const int byte_count) {
int p;
for (p = 0; p < 8; p++) {
if (byte_count & (0x100 >> p)) {
binary[byte_count_posn + p] = '0';
@ -352,13 +352,13 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) {
/* Create a binary stream representation of the input data.
7 sets are defined - Chinese characters, Numerals, Lower case letters, Upper case letters,
Mixed numerals and latters, Control characters and 8-bit binary data */
int sp, current_mode, next_mode, last_mode, glyph = 0;
int sp, current_mode, next_mode, last_mode, glyph = 0, q;
int c1, c2, done;
int p = 0, ppos;
int numbuf[3], punt = 0;
int number_pad_posn, debug = 0;
int byte_count_posn = 0, byte_count = 0;
int shift, i, q;
size_t number_pad_posn, byte_count_posn = 0;
int byte_count = 0, debug = 0;
int shift, i;
strcpy(binary, "");
@ -830,7 +830,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) {
return 0;
}
void gm_add_ecc(char binary[], int data_posn, int layers, int ecc_level, int word[]) {
static void gm_add_ecc(const char binary[], const size_t data_posn, const int layers, const int ecc_level, int word[]) {
int data_cw, i, j, wp, p;
int n1, b1, n2, b2, e1, b3, e2;
int block_size, data_size, ecc_size;
@ -854,7 +854,7 @@ void gm_add_ecc(char binary[], int data_posn, int layers, int ecc_level, int wor
/* Add padding codewords */
data[data_posn] = 0x00;
for (i = (data_posn + 1); i < data_cw; i++) {
for (i = (int) (data_posn + 1); i < data_cw; i++) {
if (i & 1) {
data[i] = 0x7e;
} else {
@ -1032,7 +1032,7 @@ void place_layer_id(char* grid, int size, int layers, int modules, int ecc_level
}
}
int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length) {
int grid_matrix(struct zint_symbol *symbol, const unsigned char source[], int length) {
int size, modules, dark, error_number;
int auto_layers, min_layers, layers, auto_ecc_level, min_ecc_level, ecc_level;
int x, y, i, j, glyph;

View file

@ -69,7 +69,7 @@ void itostr(char ai_string[], int ai_value) {
concat(ai_string, ")");
}
int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, char reduced[]) {
int gs1_verify(struct zint_symbol *symbol, const unsigned char source[], const unsigned int src_len, char reduced[]) {
int i, j, last_ai, ai_latch;
char ai_string[6];
int bracket_level, max_bracket_level, ai_length, max_ai_length, min_ai_length;
@ -335,7 +335,7 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne
return 0;
}
int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, unsigned char reduced[]) {
int ugs1_verify(struct zint_symbol *symbol, const unsigned char source[], const unsigned int src_len, unsigned char reduced[]) {
/* Only to keep the compiler happy */
#ifndef _MSC_VER
char temp[src_len + 5];

View file

@ -36,8 +36,8 @@
extern "C" {
#endif /* __cplusplus */
extern int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, char reduced[]);
extern int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, unsigned char reduced[]);
extern int gs1_verify(struct zint_symbol *symbol, const unsigned char source[], const unsigned int src_len, char reduced[]);
extern int ugs1_verify(struct zint_symbol *symbol, const unsigned char source[], const unsigned int src_len, unsigned char reduced[]);
#ifdef __cplusplus
}

View file

@ -160,7 +160,7 @@ extern int australia_post(struct zint_symbol *symbol, unsigned char source[], in
extern int code16k(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 16k */
extern int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int length); /* PDF417 */
extern int dmatrix(struct zint_symbol *symbol, unsigned char source[], int length); /* Data Matrix (IEC16022) */
extern int qr_code(struct zint_symbol *symbol, unsigned char source[], int length); /* QR Code */
extern int qr_code(struct zint_symbol *symbol, const unsigned char source[], int length); /* QR Code */
extern int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length); /* Micro PDF417 */
extern int maxicode(struct zint_symbol *symbol, unsigned char source[], int length); /* Maxicode */
extern int rss14(struct zint_symbol *symbol, unsigned char source[], int length); /* RSS-14 */
@ -173,14 +173,14 @@ extern int code32(struct zint_symbol *symbol, unsigned char source[], int length
extern int daft_code(struct zint_symbol *symbol, unsigned char source[], int length); /* DAFT Code */
extern int ean_14(struct zint_symbol *symbol, unsigned char source[], int length); /* EAN-14 */
extern int nve_18(struct zint_symbol *symbol, unsigned char source[], int length); /* NVE-18 */
extern int microqr(struct zint_symbol *symbol, unsigned char source[], int length); /* Micro QR Code */
extern int microqr(struct zint_symbol *symbol, const unsigned char source[], int length); /* Micro QR Code */
extern int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int length); /* Aztec Runes */
extern int korea_post(struct zint_symbol *symbol, unsigned char source[], int length); /* Korea Post */
extern int japan_post(struct zint_symbol *symbol, unsigned char source[], int length); /* Japanese Post */
extern int code_49(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 49 */
extern int code_49(struct zint_symbol *symbol, unsigned char source[], const int length); /* Code 49 */
extern int channel_code(struct zint_symbol *symbol, unsigned char source[], int length); /* Channel Code */
extern int code_one(struct zint_symbol *symbol, unsigned char source[], int length); /* Code One */
extern int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length); /* Grid Matrix */
extern int grid_matrix(struct zint_symbol *symbol, const unsigned char source[], int length); /* Grid Matrix */
#ifndef NO_PNG
extern int png_handle(struct zint_symbol *symbol, int rotate_angle);
@ -353,7 +353,7 @@ int hibc(struct zint_symbol *symbol, unsigned char source[], int length) {
return error_number;
}
int gs1_compliant(int symbology) {
static int gs1_compliant(const int symbology) {
/* Returns 1 if symbology supports GS1 data */
int result = 0;
@ -480,7 +480,7 @@ int ZBarcode_ValidID(int symbol_id) {
return result;
}
int extended_charset(struct zint_symbol *symbol, unsigned char *source, int length) {
static int extended_charset(struct zint_symbol *symbol, const unsigned char *source, const int length) {
int error_number = 0;
/* These are the "elite" standards which can support multiple character sets */
@ -496,7 +496,7 @@ int extended_charset(struct zint_symbol *symbol, unsigned char *source, int leng
return error_number;
}
int reduced_charset(struct zint_symbol *symbol, unsigned char *source, int length) {
static int reduced_charset(struct zint_symbol *symbol, const unsigned char *source, int length) {
/* These are the "norm" standards which only support Latin-1 at most */
int error_number = 0;

View file

@ -40,6 +40,7 @@
#include "qr.h"
#include "reedsol.h"
#include <stdlib.h> /* abs */
#include <assert.h>
/* Returns true if input glyph is in the Alphanumeric set */
int in_alpha(int glyph) {
@ -1297,16 +1298,12 @@ int tribus(int version, int a, int b, int c) {
void applyOptimisation(int version, char inputMode[], int inputLength) {
int blockCount = 0;
int blockCount = 0, block;
int i, j;
char currentMode = ' '; // Null
int block;
int *blockLength;
char *blockMode;
#ifdef _MSC_VER
int* blockLength;
int* blockMode;
#endif
for (i = 0; i < inputLength; i++) {
if (inputMode[i] != currentMode) {
currentMode = inputMode[i];
@ -1314,13 +1311,16 @@ void applyOptimisation(int version, char inputMode[], int inputLength) {
}
}
#ifndef _MSC_VER
int blockLength[blockCount];
char blockMode[blockCount];
#else
blockLength = (int *) _alloca(blockCount * sizeof (int));
blockMode = (int *) _alloca(blockCount * sizeof(int));
#endif
blockLength=(int*)malloc(sizeof(int)*blockCount);
assert(blockLength);
if (!blockLength) return;
blockMode=(char*)malloc(sizeof(char)*blockCount);
assert(blockMode);
if (!blockMode)
{
free(blockLength);
return;
}
j = -1;
currentMode = ' '; // Null
@ -1405,6 +1405,9 @@ void applyOptimisation(int version, char inputMode[], int inputLength) {
j++;
}
}
free(blockLength);
free(blockMode);
}
int blockLength(int start, char inputMode[], int inputLength) {
@ -1490,7 +1493,7 @@ int getBinaryLength(int version, char inputMode[], int inputData[], int inputLen
return count;
}
int qr_code(struct zint_symbol *symbol, unsigned char source[], int length) {
int qr_code(struct zint_symbol *symbol, const unsigned char source[], int length) {
int error_number, i, j, glyph, est_binlen;
int ecc_level, autosize, version, max_cw, target_binlen, blocks, size;
int bitmask, gs1;
@ -2757,7 +2760,7 @@ int micro_apply_bitmask(unsigned char *grid, int size) {
return best_pattern;
}
int microqr(struct zint_symbol *symbol, unsigned char source[], int length) {
int microqr(struct zint_symbol *symbol, const unsigned char source[], int length) {
int i, j, glyph, size;
char binary_stream[200];
char full_stream[200];

View file

@ -68,7 +68,7 @@ static int *logt = NULL, *alog = NULL, *rspoly = NULL;
// polynomial. e.g. for ECC200 (8-bit symbols) the polynomial is
// a**8 + a**5 + a**3 + a**2 + 1, which translates to 0x12d.
void rs_init_gf(int poly) {
void rs_init_gf(const int poly) {
int m, b, p, v;
// Find the top bit, and hence the symbol size
@ -100,7 +100,7 @@ void rs_init_gf(int poly) {
// (x + 2**i)*(x + 2**(i+1))*... [nsym terms]
// For ECC200, index is 1.
void rs_init_code(int nsym, int index) {
void rs_init_code(const int nsym,int index) {
int i, k;
rspoly = (int *) malloc(sizeof (int) * (nsym + 1));
@ -120,7 +120,7 @@ void rs_init_code(int nsym, int index) {
}
}
void rs_encode(int len, unsigned char *data, unsigned char *res) {
void rs_encode(const int len,const unsigned char *data, unsigned char *res) {
int i, k, m;
for (i = 0; i < rlen; i++)
res[i] = 0;
@ -140,7 +140,7 @@ void rs_encode(int len, unsigned char *data, unsigned char *res) {
}
/* The same as above but for larger bitlengths - Aztec code compatible */
void rs_encode_long(int len, unsigned int *data, unsigned int *res) {
void rs_encode_long(const int len,const unsigned int *data, unsigned int *res) {
int i, k, m;
for (i = 0; i < rlen; i++)
res[i] = 0;

View file

@ -37,10 +37,10 @@
extern "C" {
#endif /* __cplusplus */
extern void rs_init_gf(int poly);
extern void rs_init_code(int nsym, int index);
extern void rs_encode(int len, unsigned char *data, unsigned char *res);
extern void rs_encode_long(int len, unsigned int *data, unsigned int *res);
extern void rs_init_gf(const int poly);
extern void rs_init_code(const int nsym,int index);
extern void rs_encode(const int len,const unsigned char *data, unsigned char *res);
extern void rs_encode_long(const int len,const unsigned int *data, unsigned int *res);
extern void rs_free(void);
#ifdef __cplusplus

View file

@ -56,7 +56,7 @@ int render_plot_add_hexagon(struct zint_symbol *symbol, struct zint_render_hexag
int render_plot_add_string(struct zint_symbol *symbol, unsigned char *text, float x, float y, float fsize, float width, struct zint_render_string **last_string);
int render_plot(struct zint_symbol *symbol, float width, float height) {
int render_plot(struct zint_symbol *symbol,const float width,const float height) {
struct zint_render *render;
struct zint_render_line *line, *last_line = NULL;
struct zint_render_string *last_string = NULL;
@ -173,7 +173,7 @@ int render_plot(struct zint_symbol *symbol, float width, float height) {
}
}
if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) {
else if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) {
upceanflag = 12;
if (symbol->whitespace_width < 10) {
symbol->whitespace_width = 10;
@ -191,7 +191,7 @@ int render_plot(struct zint_symbol *symbol, float width, float height) {
}
}
if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
else if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
upceanflag = 6;
if (symbol->whitespace_width == 0) {
symbol->whitespace_width = 10;
@ -228,7 +228,7 @@ int render_plot(struct zint_symbol *symbol, float width, float height) {
if (large_bar_count == 0) {
required_aspect = width / height;
symbol_aspect = (total_symbol_width_x + (2 * xoffset)) / (preset_height + (2 * yoffset) + text_offset + text_height);
symbol->height = preset_height;
symbol->height = (int)preset_height;
if (required_aspect > symbol_aspect) {
/* the area is too wide */
scaler = height / (preset_height + (2 * yoffset) + text_offset + text_height);
@ -242,7 +242,7 @@ int render_plot(struct zint_symbol *symbol, float width, float height) {
}
} else {
scaler = width / (total_symbol_width_x + (2 * xoffset));
symbol->height = (height / scaler) - ((2 * yoffset) + text_offset + text_height);
symbol->height = (int)((height / scaler) - ((2 * yoffset) + text_offset + text_height));
render->width = width;
render->height = height;
@ -277,7 +277,7 @@ int render_plot(struct zint_symbol *symbol, float width, float height) {
}
}
if (symbol->symbology == BARCODE_CODE49) {
else if(symbol->symbology == BARCODE_CODE49) {
/* The minimum X-dimension of Code 49 is 0.191mm */
if (x_dimension < 0.191) {
render->width = 0.191 * GL_CONST * total_area_width_x;
@ -316,20 +316,20 @@ int render_plot(struct zint_symbol *symbol, float width, float height) {
render->height = 4.064 * GL_CONST;
}
if ((symbol->symbology == BARCODE_POSTNET) || (symbol->symbology == BARCODE_PLANET)) {
else if((symbol->symbology == BARCODE_POSTNET) || (symbol->symbology == BARCODE_PLANET)) {
/* The size of PostNet and PLANET are fized */
render->width = 0.508 * GL_CONST * total_area_width_x;
render->height = 2.921 * GL_CONST;
}
if (((symbol->symbology == BARCODE_AUSPOST) || (symbol->symbology == BARCODE_AUSREPLY)) ||
else if(((symbol->symbology == BARCODE_AUSPOST) || (symbol->symbology == BARCODE_AUSREPLY)) ||
((symbol->symbology == BARCODE_AUSROUTE) || (symbol->symbology == BARCODE_AUSREDIRECT))) {
/* Australia Post use the same sizes as USPS */
render->width = 0.508 * GL_CONST * total_area_width_x;
render->height = 4.064 * GL_CONST;
}
if ((symbol->symbology == BARCODE_RM4SCC) || (symbol->symbology == BARCODE_KIX)) {
else if((symbol->symbology == BARCODE_RM4SCC) || (symbol->symbology == BARCODE_KIX)) {
/* Royal Mail and KIX Code uses 22 bars per inch */
render->width = 0.577 * GL_CONST * total_area_width_x;
render->height = 5.22 * GL_CONST;
@ -680,6 +680,8 @@ struct zint_render_line *render_plot_create_line(float x, float y, float width,
struct zint_render_line *line;
line = (struct zint_render_line*) malloc(sizeof (struct zint_render_line));
if (!line) return NULL;
line->next = NULL;
line->x = x;
line->y = y;
@ -694,6 +696,7 @@ struct zint_render_line *render_plot_create_line(float x, float y, float width,
* next value.
*/
int render_plot_add_line(struct zint_symbol *symbol, struct zint_render_line *line, struct zint_render_line **last_line) {
if (!line) return ZINT_ERROR_MEMORY;
if (*last_line)
(*last_line)->next = line;
else
@ -707,6 +710,7 @@ struct zint_render_ring *render_plot_create_ring(float x, float y, float radius,
struct zint_render_ring *ring;
ring = (struct zint_render_ring *) malloc(sizeof (struct zint_render_ring));
if (!ring) return NULL;
ring->next = NULL;
ring->x = x;
ring->y = y;
@ -717,6 +721,7 @@ struct zint_render_ring *render_plot_create_ring(float x, float y, float radius,
}
int render_plot_add_ring(struct zint_symbol *symbol, struct zint_render_ring *ring, struct zint_render_ring **last_ring) {
if (!ring) return ZINT_ERROR_MEMORY;
if (*last_ring)
(*last_ring)->next = ring;
else
@ -730,6 +735,7 @@ struct zint_render_hexagon *render_plot_create_hexagon(float x, float y) {
struct zint_render_hexagon *hexagon;
hexagon = (struct zint_render_hexagon*) malloc(sizeof (struct zint_render_hexagon));
if (!hexagon) return NULL;
hexagon->next = NULL;
hexagon->x = x;
hexagon->y = y;
@ -738,6 +744,7 @@ struct zint_render_hexagon *render_plot_create_hexagon(float x, float y) {
}
int render_plot_add_hexagon(struct zint_symbol *symbol, struct zint_render_hexagon *hexagon, struct zint_render_hexagon **last_hexagon) {
if (!hexagon) return ZINT_ERROR_MEMORY;
if (*last_hexagon)
(*last_hexagon)->next = hexagon;
else

View file

@ -235,7 +235,7 @@ extern "C" {
ZINT_EXTERN int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle);
ZINT_EXTERN int ZBarcode_Encode_File_and_Print(struct zint_symbol *symbol, char *filename, int rotate_angle);
ZINT_EXTERN int ZBarcode_Render(struct zint_symbol *symbol, float width, float height);
ZINT_EXTERN int ZBarcode_Render(struct zint_symbol *symbol, const float width, const float height);
ZINT_EXTERN int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle);
ZINT_EXTERN int ZBarcode_Encode_and_Buffer(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle);