From 844dfdebef1564a32c9dd9d03e9031f8cf35b437 Mon Sep 17 00:00:00 2001 From: hooper114 Date: Sun, 5 Oct 2008 05:51:58 +0000 Subject: [PATCH] Updated error handling --- backend/auspost.c | 12 +-- backend/aztec.c | 10 +-- backend/blockf.c | 6 +- backend/code.c | 22 ++--- backend/code128.c | 20 ++--- backend/code16k.c | 4 +- backend/composite.c | 18 ++-- backend/dm200.c | 215 ++++++++++++-------------------------------- backend/dmatrix.c | 28 +++--- backend/imail.c | 8 +- backend/library.c | 63 +++++++++---- backend/maxicode.c | 8 +- backend/medical.c | 24 ++--- backend/pdf417.c | 24 ++--- backend/plessey.c | 24 ++--- backend/png.c | 20 ++--- backend/postal.c | 26 +++--- backend/ps.c | 10 +-- backend/qr.c | 4 +- backend/rss.c | 20 ++--- backend/telepen.c | 10 +-- backend/upcean.c | 36 ++++---- frontend/main.c | 27 +++--- 23 files changed, 286 insertions(+), 353 deletions(-) diff --git a/backend/auspost.c b/backend/auspost.c index 8a63ea41..4be9f356 100644 --- a/backend/auspost.c +++ b/backend/auspost.c @@ -89,7 +89,7 @@ void rs_error(char data_pattern[]) for(reader = 4; reader > 0; reader--) { - concat(data_pattern, AusBarTable[result[reader - 1]]); + concat(data_pattern, AusBarTable[(int)result[reader - 1]]); } } @@ -125,17 +125,17 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[]) case 16: strcpy(fcc, "59"); errno = is_sane(NESET, source); break; case 18: strcpy(fcc, "62"); break; case 23: strcpy(fcc, "62"); errno = is_sane(NESET, source); break; - default: strcpy(symbol->errtxt, "error: auspost input is wrong length"); + default: strcpy(symbol->errtxt, "Auspost input is wrong length [631]"); return ERROR_TOO_LONG; break; } if(errno == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [632]"); return errno; } } else { if(ustrlen(source) != 8) { - strcpy(symbol->errtxt, "error: auspost input is wrong length"); + strcpy(symbol->errtxt, "Auspost input is wrong length [633]"); return ERROR_TOO_LONG; } switch(symbol->symbology) { @@ -148,7 +148,7 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[]) errno = is_sane(GDSET, source); if(errno == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [634]"); return errno; } @@ -159,7 +159,7 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[]) dpid[8] = '\0'; errno = is_sane(NESET, (unsigned char*)dpid); if(errno == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in DPID"); + strcpy(symbol->errtxt, "Invalid characters in DPID [635]"); return errno; } diff --git a/backend/aztec.c b/backend/aztec.c index 2763c97e..b7cfa83b 100644 --- a/backend/aztec.c +++ b/backend/aztec.c @@ -556,12 +556,12 @@ int aztec(struct zint_symbol *symbol, unsigned char source[]) err_code = aztec_text_process(source, binary_string); if(err_code != 0) { - strcpy(symbol->errtxt, "Input too long or too many extended ASCII characters"); + strcpy(symbol->errtxt, "Input too long or too many extended ASCII characters [921]"); return err_code; } if(!((symbol->option_1 >= -1) && (symbol->option_1 <= 4))) { - strcpy(symbol->errtxt, "Invalid error correction level - using default instead"); + strcpy(symbol->errtxt, "Invalid error correction level - using default instead [922]"); err_code = WARN_INVALID_OPTION; symbol->option_1 = -1; } @@ -644,7 +644,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[]) } if(layers == 0) { /* Couldn't find a symbol which fits the data */ - strcpy(symbol->errtxt, "Input too long (too many bits for selected ECC)"); + strcpy(symbol->errtxt, "Input too long (too many bits for selected ECC) [923]"); return ERROR_TOO_LONG; } @@ -694,7 +694,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[]) layers = symbol->option_2 - 4; } if((symbol->option_2 < 0) || (symbol->option_2 > 36)) { - strcpy(symbol->errtxt, "Invalid Aztec Code size"); + strcpy(symbol->errtxt, "Invalid Aztec Code size [924]"); return ERROR_INVALID_OPTION; } @@ -736,7 +736,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[]) } if(adjusted_length > data_maxsize) { - strcpy(symbol->errtxt, "Data too long for specified Aztec Code symbol size"); + strcpy(symbol->errtxt, "Data too long for specified Aztec Code symbol size [925]"); return ERROR_TOO_LONG; } } diff --git a/backend/blockf.c b/backend/blockf.c index fc47688e..173069ba 100644 --- a/backend/blockf.c +++ b/backend/blockf.c @@ -537,7 +537,7 @@ int codablock(struct zint_symbol *symbol, unsigned char source[]) final_mode = MODEA; if(input_length > 5450) { - strcpy(symbol->errtxt, "Input data too long"); + strcpy(symbol->errtxt, "Input data too long [741]"); return ERROR_TOO_LONG; } @@ -567,7 +567,7 @@ int codablock(struct zint_symbol *symbol, unsigned char source[]) columns_needed = (estimate_codelength + 2) / rows_needed; if(columns_needed < 4) { columns_needed = 4; } if(columns_needed > 62) { - strcpy(symbol->errtxt, "Input data too long"); + strcpy(symbol->errtxt, "Input data too long [742]"); return ERROR_TOO_LONG; } @@ -575,7 +575,7 @@ int codablock(struct zint_symbol *symbol, unsigned char source[]) error_number = data_encode_blockf(source, subset_selector, blockmatrix, &columns_needed, &rows_needed, &final_mode); if(error_number > 0) { if(error_number == ERROR_TOO_LONG) { - strcpy(symbol->errtxt, "Input data too long"); + strcpy(symbol->errtxt, "Input data too long [743]"); } return error_number; } diff --git a/backend/code.c b/backend/code.c index 1bcb91f8..ba522fa6 100644 --- a/backend/code.c +++ b/backend/code.c @@ -87,12 +87,12 @@ int code_11(struct zint_symbol *symbol, unsigned char source[]) strcpy(dest, ""); if(ustrlen(source) > 80) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [011]"); return ERROR_TOO_LONG; } error_number = is_sane(NASET, source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [012]"); return error_number; } c_weight = 1; @@ -168,12 +168,12 @@ int c39(struct zint_symbol *symbol, unsigned char source[]) to_upper(source); if(ustrlen(source) > 45) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [081]"); return ERROR_TOO_LONG; } error_number = is_sane(TCSET , source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [082]"); return error_number; } @@ -252,12 +252,12 @@ int pharmazentral(struct zint_symbol *symbol, unsigned char source[]) count = 0; h = ustrlen(source); if(h != 6) { - strcpy(symbol->errtxt, "error: input wrong length"); + strcpy(symbol->errtxt, "Input wrong length [521]"); return ERROR_TOO_LONG; } error_number = is_sane(NESET, source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [522]"); return error_number; } @@ -299,7 +299,7 @@ int ec39(struct zint_symbol *symbol, unsigned char source[]) /* only stops strings which are far too long - actual length of the barcode depends on the type of data being encoded - if it's too long it's picked up by c39() */ - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [091]"); return ERROR_TOO_LONG; } @@ -307,7 +307,7 @@ int ec39(struct zint_symbol *symbol, unsigned char source[]) for(i = 0; i < ustrlen(source); i++) { if(source[i] > 127) { /* Cannot encode extended ASCII */ - strcpy(symbol->errtxt, "error: invalid characters in input data"); + strcpy(symbol->errtxt, "Invalid characters in input data [092]"); return ERROR_INVALID_DATA; } } @@ -348,14 +348,14 @@ int c93(struct zint_symbol *symbol, unsigned char source[]) if(ustrlen(source) > 45) { /* This stops rediculously long input - the actual length of the barcode depends on the type of data */ - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [251]"); return ERROR_TOO_LONG; } for(i = 0; i < ustrlen(source); i++) { if(source[i] > 127) { /* Cannot encode extended ASCII */ - strcpy(symbol->errtxt, "error: invalid characters in input data"); + strcpy(symbol->errtxt, "Invalid characters in input data [252]"); return ERROR_INVALID_DATA; } } @@ -371,7 +371,7 @@ int c93(struct zint_symbol *symbol, unsigned char source[]) /* Now we can check the true length of the barcode */ if(strlen(buffer) > 45) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [253]"); return ERROR_TOO_LONG; } diff --git a/backend/code128.c b/backend/code128.c index 934a8953..e0b3e90a 100644 --- a/backend/code128.c +++ b/backend/code128.c @@ -210,7 +210,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[]) if(sourcelen > 160) { /* This only blocks rediculously long input - the actual length of the resulting barcode depends on the type of data, so this is trapped later */ - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [201]"); return ERROR_TOO_LONG; } @@ -218,11 +218,11 @@ int code_128(struct zint_symbol *symbol, unsigned char source[]) if(symbol->symbology == BARCODE_NVE18) { errornum = is_sane(NESET, source); if(errornum == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [202]"); return errornum; } if(sourcelen != 17) { - strcpy(symbol->errtxt, "error: input wrong length"); + strcpy(symbol->errtxt, "Input wrong length [203]"); return ERROR_TOO_LONG; } for(i = sourcelen + 2; i > 1; i--) { @@ -400,7 +400,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[]) } } if(glyph_count > 80.0) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [204]"); return ERROR_TOO_LONG; } @@ -597,20 +597,20 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[]) if(sourcelen > 160) { /* This only blocks rediculously long input - the actual length of the resulting barcode depends on the type of data, so this is trapped later */ - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [161]"); return ERROR_TOO_LONG; } /* Detect extended ASCII characters */ for(i = 0; i < sourcelen; i++) { if(source[i] >=128) { - strcpy(symbol->errtxt, "error: extended ASCII characters not supported by GS1-128"); + strcpy(symbol->errtxt, "Extended ASCII characters not supported by GS1-128 [162]"); return ERROR_INVALID_DATA; } } if(source[0] != '[') { - strcpy(symbol->errtxt, "error: input string doesn't start with AI"); + strcpy(symbol->errtxt, "Input string doesn't start with AI [163]"); return ERROR_INVALID_DATA; } @@ -750,7 +750,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[]) } } if(glyph_count > 80.0) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [164]"); return ERROR_TOO_LONG; } @@ -910,13 +910,13 @@ int ean_14(struct zint_symbol *symbol, unsigned char source[]) input_length = ustrlen(source); if(input_length != 13) { - strcpy(symbol->errtxt, "error: input wrong length"); + strcpy(symbol->errtxt, "Input wrong length [721]"); return ERROR_TOO_LONG; } error_number = is_sane(NESET, source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid character in data"); + strcpy(symbol->errtxt, "Invalid character in data [722]"); return error_number; } concat((char*)ean128_equiv, "[01]"); diff --git a/backend/code16k.c b/backend/code16k.c index 9bcf2469..75469481 100644 --- a/backend/code16k.c +++ b/backend/code16k.c @@ -124,7 +124,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[]) input_length = ustrlen(source); if(input_length > 157) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [231]"); return ERROR_TOO_LONG; } @@ -265,7 +265,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[]) } } if(glyph_count > 77.0) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [232]"); return ERROR_TOO_LONG; } diff --git a/backend/composite.c b/backend/composite.c index 3a3e3b2c..809140f3 100644 --- a/backend/composite.c +++ b/backend/composite.c @@ -826,7 +826,7 @@ int cc_binary_string(struct zint_symbol *symbol, unsigned char source[], char bi if (!(((ninety[i] >= '0') && (ninety[i] <= '9')) || ((ninety[i] >= 'A') && (ninety[i] <= 'Z')))) { if((ninety[i] != '*') && (ninety[i] != ',') && (ninety[i] != '-') && (ninety[i] != '.') && (ninety[i] != '/')) { /* An Invalid AI 90 character */ - strcpy(symbol->errtxt, "error: invalid AI 90 data"); + strcpy(symbol->errtxt, "Invalid AI 90 data [A1]"); return ERROR_INVALID_DATA; } } @@ -1151,7 +1151,7 @@ int cc_binary_string(struct zint_symbol *symbol, unsigned char source[], char bi if(latch == 1) { /* Invalid characters in input data */ - strcpy(symbol->errtxt, "Invalid characters in input data"); + strcpy(symbol->errtxt, "Invalid characters in input data [A2]"); return ERROR_INVALID_DATA; } @@ -1510,7 +1510,7 @@ int cc_binary_string(struct zint_symbol *symbol, unsigned char source[], char bi } if(strlen(binary_string) > 11805) { /* (2361 * 5) */ - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [A3]"); return ERROR_TOO_LONG; } @@ -1682,24 +1682,24 @@ int composite(struct zint_symbol *symbol, unsigned char source[]) separator_row = 0; if(strlen(symbol->primary) == 0) { - strcpy(symbol->errtxt, "error: No primary (linear) message in 2D composite"); + strcpy(symbol->errtxt, "No primary (linear) message in 2D composite [A4]"); return ERROR_INVALID_OPTION; } if(ustrlen(source) > 2990) { - strcpy(symbol->errtxt, "error: 2D component input data too long"); + strcpy(symbol->errtxt, "2D component input data too long [A5]"); return ERROR_TOO_LONG; } if(source[0] != '[') { - strcpy(symbol->errtxt, "Data does not start with an AI"); + strcpy(symbol->errtxt, "Data does not start with an AI [A6]"); return ERROR_INVALID_DATA; } for(i = 0; i < ustrlen(source) - 1; i++) { if((source[i] == '[') && (source[i + 1] == '[')) { /* Can't have nested brackets - Quit */ - strcpy(symbol->errtxt, "Nested AI detected (two or more open brackets)"); + strcpy(symbol->errtxt, "Nested AI detected (two or more open brackets) [A7]"); return ERROR_INVALID_DATA; } } @@ -1707,7 +1707,7 @@ int composite(struct zint_symbol *symbol, unsigned char source[]) for(i = 0; i < ustrlen(source) - 1; i++) { if((source[i] == ']') && (source[i + 1] == ']')) { /* Can't have nested brackets - Quit */ - strcpy(symbol->errtxt, "Nested AI detected (two or more close brackets)"); + strcpy(symbol->errtxt, "Nested AI detected (two or more close brackets) [A8]"); return ERROR_INVALID_DATA; } } @@ -1754,7 +1754,7 @@ int composite(struct zint_symbol *symbol, unsigned char source[]) if((cc_mode == 3) && (symbol->symbology != BARCODE_EAN128_CC)) { /* CC-C can only be used with a GS1-128 linear part */ - strcpy(symbol->errtxt, "Invalid mode (CC-C only valid with GS1-128 linear component)"); + strcpy(symbol->errtxt, "Invalid mode (CC-C only valid with GS1-128 linear component) [A9]"); return ERROR_INVALID_OPTION; } diff --git a/backend/dm200.c b/backend/dm200.c index 99a56e0f..302f09ca 100644 --- a/backend/dm200.c +++ b/backend/dm200.c @@ -81,8 +81,7 @@ static void *safemalloc(int n) } // Annex M placement alorithm low level -static void ecc200placementbit(int *array, int NR, int NC, int r, int c, - int p, char b) +static void ecc200placementbit(int *array, int NR, int NC, int r, int c, int p, char b) { if (r < 0) { r += NR; @@ -229,8 +228,7 @@ static void ecc200(unsigned char *binary, int bytes, int datablock, int rsblock) * necessary padding to tl */ -char ecc200encode(unsigned char *t, int tl, unsigned char *s, int sl, - char *encoding, int *lenp) +char ecc200encode(unsigned char *t, int tl, unsigned char *s, int sl, char *encoding, int *lenp) { char enc = 'a'; // start in ASCII encoding mode int tp = 0, sp = 0; @@ -272,65 +270,49 @@ char ecc200encode(unsigned char *t, int tl, unsigned char *s, int sl, char *w; if (c & 0x80) { if (newenc == 'x') { - fprintf(stderr, - "Cannot encode char 0x%02X in X12\n", - c); + fprintf(stderr, "Cannot encode char 0x%02X in X12\n", c); return 0; } c &= 0x7f; - out[p++] = 1; - out[p++] = 30; + out[(int)p++] = 1; + out[(int)p++] = 30; } w = strchr(e, c); if (w) - out[p++] = ((w - e) + 3) % 40; + out[(int)p++] = ((w - e) + 3) % 40; else { if (newenc == 'x') { - fprintf(stderr, - "Cannot encode char 0x%02X in X12\n", - c); + fprintf(stderr, "Cannot encode char 0x%02X in X12\n", c); return 0; } if (c < 32) { // shift 1 - out[p++] = 0; - out[p++] = c; + out[(int)p++] = 0; + out[(int)p++] = c; } else { w = strchr(s2, c); if (w) { // shift 2 - out[p++] = 1; - out[p++] = - (w - s2); + out[(int)p++] = 1; + out[(int)p++] = (w - s2); } else { - w = strchr(s3, - c); + w = strchr(s3, c); if (w) { - out[p++] - = 2; - out[p++] - = - (w - - s3); + out[(int)p++] = 2; + out[(int)p++] = (w - s3); } else { - fprintf - (stderr, - "Could not encode 0x%02X, should \ - not happen\n", c); - return - 0; + fprintf (stderr, "Could not encode 0x%02X, should not happen\n", c); + return 0; } } } } if (p == 2 && tp + 2 <= tl && sp == sl) - out[p++] = 0; // shift 1 pad at end + out[(int)p++] = 0; // shift 1 pad at end while (p >= 3) { int v = out[0] * 1600 + out[1] * 40 + out[2] + 1; if (enc != newenc) { - if (enc == 'c' - || enc == 't' - || enc == 'x') + if (enc == 'c' || enc == 't' || enc == 'x') t[tp++] = 254; // escape C40/text/X12 else if (enc == 'x') t[tp++] = 0x7C; // escape EDIFACT @@ -360,8 +342,7 @@ char ecc200encode(unsigned char *t, int tl, unsigned char *s, int sl, t[tp++] = 254; enc = 'a'; } - while (sp < sl && tolower(encoding[sp]) == 'e' - && p < 4) + while (sp < sl && tolower(encoding[sp]) == 'e' && p < 4) out[p++] = s[sp++]; if (p < 4) { out[p++] = 0x1F; @@ -387,10 +368,8 @@ char ecc200encode(unsigned char *t, int tl, unsigned char *s, int sl, t[tp++] = 0x7C; // escape EDIFACT } enc = 'a'; - if (sl - sp >= 2 && isdigit(s[sp]) - && isdigit(s[sp + 1])) { - t[tp++] = - (s[sp] - '0') * 10 + s[sp + 1] - '0' + 130; + if (sl - sp >= 2 && isdigit(s[sp]) && isdigit(s[sp + 1])) { + t[tp++] = (s[sp] - '0') * 10 + s[sp + 1] - '0' + 130; sp += 2; } else if (s[sp] > 127) { t[tp++] = 235; @@ -403,10 +382,7 @@ char ecc200encode(unsigned char *t, int tl, unsigned char *s, int sl, int l = 0; // how much to encode if (encoding) { int p; - for (p = sp; - p < sl - && tolower(encoding[p]) == 'b'; - p++) + for (p = sp; p < sl && tolower(encoding[p]) == 'b'; p++) l++; } t[tp++] = 231; // base256 @@ -523,16 +499,14 @@ static char *encmake(int l, unsigned char *s, int *lenp, char exact) bl = 0; if (p + sl < l) for (e = 0; e < E_MAX; e++) - if (enc[p + sl][e].t && ((t = enc[p + sl][e].t + - switchcost[E_ASCII] - [e]) < bl || !bl)) { + if (enc[p + sl][(int)e].t && ((t = enc[p + sl][(int)e].t + switchcost[E_ASCII][(int)e]) < bl || !bl)) { bl = t; b = e; } enc[p][E_ASCII].t = tl + bl; enc[p][E_ASCII].s = sl; if (bl && b == E_ASCII) - enc[p][b].s += enc[p + sl][b].s; + enc[p][(int)b].s += enc[p + sl][(int)b].s; // C40 sub = tl = sl = 0; do { @@ -559,12 +533,7 @@ static char *encmake(int l, unsigned char *s, int *lenp, char exact) bl = 0; if (p + sl < l) for (e = 0; e < E_MAX; e++) - if (enc[p + sl][e].t - && - ((t = - enc[p + sl][e].t + - switchcost[E_C40][e]) < bl - || !bl)) { + if (enc[p + sl][(int)e].t && ((t = enc[p + sl][(int)e].t + switchcost[E_C40][(int)e]) < bl || !bl)) { bl = t; b = e; } @@ -576,7 +545,7 @@ static char *encmake(int l, unsigned char *s, int *lenp, char exact) enc[p][E_C40].t = tl + bl; enc[p][E_C40].s = sl; if (bl && b == E_C40) - enc[p][b].s += enc[p + sl][b].s; + enc[p][(int)b].s += enc[p + sl][(int)b].s; } // Text sub = tl = sl = 0; @@ -604,12 +573,7 @@ static char *encmake(int l, unsigned char *s, int *lenp, char exact) bl = 0; if (p + sl < l) for (e = 0; e < E_MAX; e++) - if (enc[p + sl][e].t - && - ((t = - enc[p + sl][e].t + - switchcost[E_TEXT][e]) < bl - || !bl)) { + if (enc[p + sl][(int)e].t && ((t = enc[p + sl][(int)e].t + switchcost[E_TEXT][(int)e]) < bl || !bl)) { bl = t; b = e; } @@ -620,14 +584,13 @@ static char *encmake(int l, unsigned char *s, int *lenp, char exact) enc[p][E_TEXT].t = tl + bl; enc[p][E_TEXT].s = sl; if (bl && b == E_TEXT) - enc[p][b].s += enc[p + sl][b].s; + enc[p][(int)b].s += enc[p + sl][(int)b].s; } // X12 sub = tl = sl = 0; do { unsigned char c = s[p + sl++]; - if (c != 13 && c != '*' && c != '>' && c != ' ' - && !isdigit(c) && !isupper(c)) { + if (c != 13 && c != '*' && c != '>' && c != ' ' && !isdigit(c) && !isupper(c)) { sl = 0; break; } @@ -641,12 +604,7 @@ static char *encmake(int l, unsigned char *s, int *lenp, char exact) bl = 0; if (p + sl < l) for (e = 0; e < E_MAX; e++) - if (enc[p + sl][e].t - && - ((t = - enc[p + sl][e].t + - switchcost[E_X12][e]) < bl - || !bl)) { + if (enc[p + sl][(int)e].t && ((t = enc[p + sl][(int)e].t + switchcost[E_X12][(int)e]) < bl || !bl)) { bl = t; b = e; } @@ -658,7 +616,7 @@ static char *encmake(int l, unsigned char *s, int *lenp, char exact) enc[p][E_X12].t = tl + bl; enc[p][E_X12].s = sl; if (bl && b == E_X12) - enc[p][b].s += enc[p + sl][b].s; + enc[p][(int)b].s += enc[p + sl][(int)b].s; } // EDIFACT sl = bl = 0; @@ -669,12 +627,8 @@ static char *encmake(int l, unsigned char *s, int *lenp, char exact) bs = 1; } else for (e = 0; e < E_MAX; e++) - if (e != E_EDIFACT && enc[p + 1][e].t - && - ((t = - 2 + enc[p + 1][e].t + - switchcost[E_ASCII][e]) - < bl || !bl)) // E_ASCII as allowed for unlatch + if (e != E_EDIFACT && enc[p + 1][(int)e].t && ((t = 2 + enc[p + 1][(int)e].t + switchcost[E_ASCII][(int)e]) < bl || !bl)) + // E_ASCII as allowed for unlatch { bs = 1; bl = t; @@ -686,13 +640,8 @@ static char *encmake(int l, unsigned char *s, int *lenp, char exact) bs = 2; } else for (e = 0; e < E_MAX; e++) - if (e != E_EDIFACT - && enc[p + 2][e].t - && - ((t = - 3 + enc[p + 2][e].t + - switchcost[E_ASCII][e]) - < bl || !bl)) // E_ASCII as allowed for unlatch + if (e != E_EDIFACT && enc[p + 2][(int)e].t && ((t = 3 + enc[p + 2][(int)e].t + switchcost[E_ASCII][(int)e]) < bl || !bl)) + // E_ASCII as allowed for unlatch { bs = 2; bl = t; @@ -704,55 +653,25 @@ static char *encmake(int l, unsigned char *s, int *lenp, char exact) bs = 3; } else for (e = 0; e < E_MAX; e++) - if (e != E_EDIFACT - && enc[p + 3][e].t - && - ((t = - 3 + enc[p + - 3][e].t + - switchcost - [E_ASCII][e]) - < bl || !bl)) // E_ASCII as allowed for unlatch + if (e != E_EDIFACT && enc[p + 3][(int)e].t && ((t = 3 + enc[p + 3][(int)e].t + switchcost [E_ASCII][(int)e]) < bl || !bl)) + // E_ASCII as allowed for unlatch { bs = 3; bl = t; b = e; } if (p + 4 < l && s[p + 3] >= 32 && s[p + 3] <= 94) { // can encode 4 - if (p + 4 == l - && (!bl || bl < 3)) { + if (p + 4 == l && (!bl || bl < 3)) { bl = 3; bs = 4; } else { - for (e = 0; e < E_MAX; - e++) - if (enc[p + 4] - [e].t - && - ((t = - 3 + - enc[p + - 4][e]. - t + - switchcost - [E_EDIFACT] - [e]) < bl - || !bl)) { + for (e = 0; e < E_MAX; e++) + if (enc[p + 4][(int)e].t && ((t = 3 + enc[p + 4][(int)e].t + switchcost [E_EDIFACT][(int)e]) < bl || !bl)) { bs = 4; bl = t; b = e; } - if (exact - && enc[p + - 4][E_ASCII].t - && enc[p + - 4][E_ASCII]. - t <= 2 - && (t = - 3 + enc[p + - 4] - [E_ASCII].t) < - bl) { + if (exact && enc[p + 4][E_ASCII].t && enc[p + 4][E_ASCII].t <= 2 && (t = 3 + enc[p + 4][E_ASCII].t) < bl) { // special case, switch to ASCII for last 1 ot two bytes bs = 4; bl = t; @@ -765,25 +684,19 @@ static char *encmake(int l, unsigned char *s, int *lenp, char exact) enc[p][E_EDIFACT].t = bl; enc[p][E_EDIFACT].s = bs; if (bl && b == E_EDIFACT) - enc[p][b].s += enc[p + bs][b].s; + enc[p][(int)b].s += enc[p + bs][(int)b].s; } // Binary bl = 0; for (e = 0; e < E_MAX; e++) - if (enc[p + 1][e].t - && - ((t = - enc[p + 1][e].t + switchcost[E_BINARY][e] + - ((e == E_BINARY - && enc[p + 1][e].t == 249) ? 1 : 0)) - < bl || !bl)) { + if (enc[p + 1][(int)e].t && ((t = enc[p + 1][(int)e].t + switchcost[E_BINARY][(int)e] + ((e == E_BINARY && enc[p + 1][(int)e].t == 249) ? 1 : 0)) < bl || !bl)) { bl = t; b = e; } enc[p][E_BINARY].t = 1 + bl; enc[p][E_BINARY].s = 1; if (bl && b == E_BINARY) - enc[p][b].s += enc[p + 1][b].s; + enc[p][(int)b].s += enc[p + 1][(int)b].s; /* * fprintf (stderr, "%d:", p); for (e = 0; e < E_MAX; e++) fprintf \ * (stderr, " %c*%d/%d", encchr[e], enc[p][e].s, enc[p][e].t); \ @@ -797,18 +710,16 @@ static char *encmake(int l, unsigned char *s, int *lenp, char exact) while (p < l) { int t, m = 0, b = 0; for (e = 0; e < E_MAX; e++) - if (enc[p][e].t - && ((t = enc[p][e].t + switchcost[cur][e]) < - m || t == m && e == cur || !m)) { + if (enc[p][(int)e].t && ((t = enc[p][(int)e].t + switchcost[(int)cur][(int)e]) < m || t == m && e == cur || !m)) { b = e; m = t; } cur = b; - m = enc[p][b].s; + m = enc[p][(int)b].s; if (!p && lenp) - *lenp = enc[p][b].t; + *lenp = enc[p][(int)b].t; while (p < l && m--) - encoding[p++] = encchr[b]; + encoding[p++] = encchr[(int)b]; } } encoding[p] = 0; @@ -830,9 +741,7 @@ static char *encmake(int l, unsigned char *s, int *lenp, char exact) * Returns 0 on error (writes to stderr with details). */ -unsigned char *iec16022ecc200(int *Wptr, int *Hptr, char **encodingptr, - int barcodelen, unsigned char *barcode, - int *lenp, int *maxp, int *eccp) +unsigned char *iec16022ecc200(int *Wptr, int *Hptr, char **encodingptr, int barcodelen, unsigned char *barcode, int *lenp, int *maxp, int *eccp) { unsigned char binary[3000]; // encoded raw data and ecc to place in barcode int W = 0, H = 0; @@ -849,9 +758,7 @@ unsigned char *iec16022ecc200(int *Wptr, int *Hptr, char **encodingptr, // encoding if (W) { // known size - for (matrix = ecc200matrix; matrix->W && (matrix->W != W || - matrix->H != H); - matrix++) ; + for (matrix = ecc200matrix; matrix->W && (matrix->W != W || matrix->H != H); matrix++) ; if (!matrix->W) { fprintf(stderr, "Invalid size %dx%d\n", W, H); return 0; @@ -878,9 +785,7 @@ unsigned char *iec16022ecc200(int *Wptr, int *Hptr, char **encodingptr, if (encoding) { // find one that fits chosen encoding for (matrix = ecc200matrix; matrix->W; matrix++) - if (ecc200encode - (binary, matrix->bytes, barcode, barcodelen, - encoding, 0)) + if (ecc200encode(binary, matrix->bytes, barcode, barcodelen, encoding, 0)) break; } else { int len; @@ -891,22 +796,18 @@ unsigned char *iec16022ecc200(int *Wptr, int *Hptr, char **encodingptr, if (e && !matrix->W) { // try for non exact fit free(e); e = encmake(barcodelen, barcode, &len, 0); - for (matrix = ecc200matrix; - matrix->W && matrix->bytes < len; - matrix++) ; + for (matrix = ecc200matrix; matrix->W && matrix->bytes < len; matrix++) ; } encoding = e; } if (!matrix->W) { - fprintf(stderr, - "Cannot find suitable size, barcode too long\n"); + fprintf(stderr, "Cannot find suitable size, barcode too long\n"); return 0; } W = matrix->W; H = matrix->H; } - if (!ecc200encode(binary, matrix->bytes, barcode, barcodelen, - encoding, lenp)) { + if (!ecc200encode(binary, matrix->bytes, barcode, barcodelen, encoding, lenp)) { fprintf(stderr, "Barcode too long for %dx%d\n", W, H); return 0; } @@ -936,12 +837,8 @@ unsigned char *iec16022ecc200(int *Wptr, int *Hptr, char **encodingptr, for (x = 0; x < NC; x++) { int v = places[(NR - y - 1) * NC + x]; //fprintf (stderr, "%4d", v); - if (v == 1 || v > 7 - && (binary[(v >> 3) - 1] & (1 << (v & 7)))) - grid[(1 + y + - 2 * (y / (matrix->FH - 2))) * W + - 1 + x + - 2 * (x / (matrix->FW - 2))] = 1; + if (v == 1 || v > 7 && (binary[(v >> 3) - 1] & (1 << (v & 7)))) + grid[(1 + y + 2 * (y / (matrix->FH - 2))) * W + 1 + x + 2 * (x / (matrix->FW - 2))] = 1; } //fprintf (stderr, "\n"); } diff --git a/backend/dmatrix.c b/backend/dmatrix.c index a7440bae..5e1a9f83 100644 --- a/backend/dmatrix.c +++ b/backend/dmatrix.c @@ -81,7 +81,7 @@ int dmatrix(struct zint_symbol *symbol, unsigned char source[]) } else */ barcodelen = ustrlen(source); if(barcodelen > 780) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [711]"); return ERROR_TOO_LONG; } // check parameters @@ -93,9 +93,13 @@ int dmatrix(struct zint_symbol *symbol, unsigned char source[]) if (!H) W = H; } - if (eccstr) +/* if (eccstr) */ ecc = atoi(eccstr); - if (W & 1) { // odd size + + /* Yes I _have_ commented out large blocks of code! - odd size Data Matrix support + may be included in a later release but the code for it isn't needed here */ + +/* if (W & 1) { // odd size if (W != H || W < 9 || W > 49) { strcpy(symbol->errtxt, "error: invalid Data Matrix size"); return ERROR_INVALID_OPTION; @@ -117,7 +121,7 @@ int dmatrix(struct zint_symbol *symbol, unsigned char source[]) return ERROR_INVALID_OPTION; } - } else if (W) { // even size + } else if (W) { // even size if (W < H) { int t = W; W = H; @@ -129,28 +133,26 @@ int dmatrix(struct zint_symbol *symbol, unsigned char source[]) strcpy(symbol->errtxt, "error: invalid size for ecc 200"); return ERROR_INVALID_OPTION; } - } + } else { // auto size if (!eccstr) // default is even sizes only unless explicit ecc set to force odd // sizes ecc = 200; - } + } */ // processing stamps - if ((W & 1) || ecc < 200) { // odd sizes + /*if ((W & 1) || ecc < 200) { // odd sizes strcpy(symbol->errtxt, "error: odd sizes not supported"); return ERROR_INVALID_OPTION; - } else { // even sizes - grid = - iec16022ecc200(&W, &H, &encoding, barcodelen, source, &len, - &maxlen, &ecclen); - } + } else { */ // even sizes + grid = iec16022ecc200(&W, &H, &encoding, barcodelen, source, &len, &maxlen, &ecclen); + /*} */ // output if (!grid || !W) { - strcpy(symbol->errtxt, "error: Data Matrix encoding error"); + strcpy(symbol->errtxt, "Data Matrix encoding error [722]"); return ERROR_ENCODING_PROBLEM; } int y; diff --git a/backend/imail.c b/backend/imail.c index 7facb746..4c4c2bba 100644 --- a/backend/imail.c +++ b/backend/imail.c @@ -313,12 +313,12 @@ int imail(struct zint_symbol *symbol, unsigned char source[]) errno = 0; if(ustrlen(source) > 32) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [851]"); return ERROR_TOO_LONG; } errno = is_sane(NASET, source); if(errno == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [852]"); return errno; } @@ -361,11 +361,11 @@ int imail(struct zint_symbol *symbol, unsigned char source[]) } if(strlen(tracker) != 20) { - strcpy(symbol->errtxt, "error: invalid length tracking code"); + strcpy(symbol->errtxt, "Invalid length tracking code [853]"); return ERROR_INVALID_DATA; } if(strlen(zip) > 11) { - strcpy(symbol->errtxt, "error: invalid ZIP code"); + strcpy(symbol->errtxt, "Invalid ZIP code [854]"); return ERROR_INVALID_DATA; } diff --git a/backend/library.c b/backend/library.c index 6c3fb41f..ee18f6e9 100644 --- a/backend/library.c +++ b/backend/library.c @@ -115,49 +115,69 @@ int png_handle(struct zint_symbol *symbol, int rotate_angle); extern int ps_plot(struct zint_symbol *symbol); +void error_tag(char error_string[], int error_number) +{ + char error_buffer[100]; + + if(error_number != 0) { + strcpy(error_buffer, error_string); + + if(error_number > 4) { + strcpy(error_string, "error: "); + } else { + strcpy(error_string, "warning: "); + } + + concat(error_string, error_buffer); + } +} + int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *input) { - int error_number; + int error_number, error_buffer; error_number = 0; /* First check the symbology field */ - if(symbol->symbology < 1) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } + if(symbol->symbology < 1) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128 [Z01]"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } /* symbol->symbologys 1 to 86 are defined by tbarcode */ if(symbol->symbology == 5) { symbol->symbology = BARCODE_C25MATRIX; } if((symbol->symbology >= 10) && (symbol->symbology <= 12)) { symbol->symbology = BARCODE_EANX; } if((symbol->symbology == 14) || (symbol->symbology == 15)) { symbol->symbology = BARCODE_EANX; } if(symbol->symbology == 17) { symbol->symbology = BARCODE_UPCA; } - if(symbol->symbology == 19) { strcpy(symbol->errtxt, "Codabar 18 not supported, using Codabar"); symbol->symbology = BARCODE_CODABAR; error_number = WARN_INVALID_OPTION; } - if(symbol->symbology == 24) { strcpy(symbol->errtxt, "Code 49 not supported, using Code 93"); symbol->symbology = BARCODE_CODE93; error_number = WARN_INVALID_OPTION; } + if(symbol->symbology == 19) { strcpy(symbol->errtxt, "Codabar 18 not supported, using Codabar [Z02]"); symbol->symbology = BARCODE_CODABAR; error_number = WARN_INVALID_OPTION; } + if(symbol->symbology == 24) { strcpy(symbol->errtxt, "Code 49 not supported, using Code 93 [Z03]"); symbol->symbology = BARCODE_CODE93; error_number = WARN_INVALID_OPTION; } if(symbol->symbology == 26) { symbol->symbology = BARCODE_UPCA; } - if(symbol->symbology == 27) { strcpy(symbol->errtxt, "UPCD1 not supported"); error_number = ERROR_INVALID_OPTION; } + if(symbol->symbology == 27) { strcpy(symbol->errtxt, "UPCD1 not supported [Z04]"); error_number = ERROR_INVALID_OPTION; } if(symbol->symbology == 33) { symbol->symbology = BARCODE_EAN128; } if((symbol->symbology == 35) || (symbol->symbology == 36)) { symbol->symbology = BARCODE_UPCA; } if((symbol->symbology == 38) || (symbol->symbology == 39)) { symbol->symbology = BARCODE_UPCE; } if((symbol->symbology >= 41) && (symbol->symbology <= 45)) { symbol->symbology = BARCODE_POSTNET; } if(symbol->symbology == 46) { symbol->symbology = BARCODE_PLESSEY; } if(symbol->symbology == 48) { symbol->symbology = BARCODE_NVE18; } - if(symbol->symbology == 54) { strcpy(symbol->errtxt, "General Parcel Code not supported, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } + if(symbol->symbology == 54) { strcpy(symbol->errtxt, "General Parcel Code not supported, using Code 128 [Z05]"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } if((symbol->symbology == 59) || (symbol->symbology == 61)) { symbol->symbology = BARCODE_CODE128; } if(symbol->symbology == 62) { symbol->symbology = BARCODE_CODE93; } if((symbol->symbology == 64) || (symbol->symbology == 65)) { symbol->symbology = BARCODE_AUSPOST; } - if(symbol->symbology == 73) { strcpy(symbol->errtxt, "Codablock E not supported"); error_number = ERROR_INVALID_OPTION; } - if(symbol->symbology == 76) { strcpy(symbol->errtxt, "Japanese Postal Code not supported"); error_number = ERROR_INVALID_OPTION; } - if(symbol->symbology == 77) { strcpy(symbol->errtxt, "Korean Postal Code not supported"); error_number = ERROR_INVALID_OPTION; } + if(symbol->symbology == 73) { strcpy(symbol->errtxt, "Codablock E not supported [Z06]"); error_number = ERROR_INVALID_OPTION; } + if(symbol->symbology == 76) { strcpy(symbol->errtxt, "Japanese Postal Code not supported [Z07]"); error_number = ERROR_INVALID_OPTION; } + if(symbol->symbology == 77) { strcpy(symbol->errtxt, "Korean Postal Code not supported [Z08]"); error_number = ERROR_INVALID_OPTION; } if(symbol->symbology == 78) { symbol->symbology = BARCODE_RSS14; } if(symbol->symbology == 83) { symbol->symbology = BARCODE_PLANET; } /* NOTE: Tbarcode v8 needs sorting out */ if(symbol->symbology == 88) { symbol->symbology = BARCODE_EAN128; } - if(symbol->symbology == 91) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128\n"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } + if(symbol->symbology == 91) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128 [Z09]"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } /* leave a gap for future expansion of tbarcode */ - if((symbol->symbology >= 94) && (symbol->symbology <= 128)) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128\n"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } + if((symbol->symbology >= 94) && (symbol->symbology <= 128)) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128 [Z10]"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } /* Everything from 100 up is Zint-specific */ - if(symbol->symbology >= 140) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } + if(symbol->symbology >= 140) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128 [Z11]"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } if(error_number > 4) { + error_tag(symbol->errtxt, error_number); return error_number; + } else { + error_buffer = error_number; } if(symbol->symbology == BARCODE_CODE16K) { @@ -243,6 +263,11 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *input) case BARCODE_EAN14: error_number = ean_14(symbol, input); break; } + if(error_number == 0) { + error_number = error_buffer; + } + + error_tag(symbol->errtxt, error_number); return error_number; } @@ -265,17 +290,20 @@ int ZBarcode_Print(struct zint_symbol *symbol) if(!(strcmp(output, "EPS"))) { error_number = ps_plot(symbol); } else { - strcpy(symbol->errtxt, "error: unknown output format"); + strcpy(symbol->errtxt, "Unknown output format [Z20]"); + error_tag(symbol->errtxt, ERROR_INVALID_OPTION); return ERROR_INVALID_OPTION; } #ifndef NO_PNG } #endif } else { - strcpy(symbol->errtxt, "error: unknown output format"); + strcpy(symbol->errtxt, "Unknown output format [Z21]"); + error_tag(symbol->errtxt, ERROR_INVALID_OPTION); return ERROR_INVALID_OPTION; } + error_tag(symbol->errtxt, error_number); return error_number; } @@ -298,17 +326,20 @@ int ZBarcode_Print_Rotated(struct zint_symbol *symbol, int rotate_angle) if(!(strcmp(output, "EPS"))) { error_number = ps_plot(symbol); } else { - strcpy(symbol->errtxt, "error: unknown output format"); + strcpy(symbol->errtxt, "Unknown output format [Z23]"); + error_tag(symbol->errtxt, ERROR_INVALID_OPTION); return ERROR_INVALID_OPTION; } #ifndef NO_PNG } #endif } else { - strcpy(symbol->errtxt, "error: unknown output format"); + strcpy(symbol->errtxt, "Unknown output format [Z24]"); + error_tag(symbol->errtxt, ERROR_INVALID_OPTION); return ERROR_INVALID_OPTION; } + error_tag(symbol->errtxt, error_number); return error_number; } diff --git a/backend/maxicode.c b/backend/maxicode.c index c5d03e3d..9646cc96 100644 --- a/backend/maxicode.c +++ b/backend/maxicode.c @@ -571,19 +571,19 @@ int maxicode(struct zint_symbol *symbol, unsigned char source[]) } if((mode < 2) || (mode > 6)) { /* Only codes 2 to 6 supported */ - strcpy(symbol->errtxt, "Error: Invalid Maxicode Mode"); + strcpy(symbol->errtxt, "Invalid Maxicode Mode [571]"); return ERROR_INVALID_OPTION; } if((mode == 2) || (mode == 3)) { /* Modes 2 and 3 need data in symbol->primary */ if(strlen(symbol->primary) != 15) { - strcpy(symbol->errtxt, "Error: Invalid Primary String"); + strcpy(symbol->errtxt, "Invalid Primary String [572]"); return ERROR_INVALID_DATA; } for(i = 9; i < 15; i++) { /* check that country code and service are numeric */ if((symbol->primary[i] < 48) || (symbol->primary[i] > 57)) { - strcpy(symbol->errtxt, "Error: Invalid Primary String"); + strcpy(symbol->errtxt, "Invalid Primary String [573]"); return ERROR_INVALID_DATA; } } @@ -622,7 +622,7 @@ int maxicode(struct zint_symbol *symbol, unsigned char source[]) i = maxi_text_process(mode, source); if(i == ERROR_TOO_LONG ) { - strcpy(symbol->errtxt, "Error: Input data too long"); + strcpy(symbol->errtxt, "Input data too long [574]"); return i; } diff --git a/backend/medical.c b/backend/medical.c index 589f992a..28b453e9 100644 --- a/backend/medical.c +++ b/backend/medical.c @@ -58,12 +58,12 @@ int pharma_one(struct zint_symbol *symbol, unsigned char source[]) strcpy(dest, ""); if(ustrlen(source) > 6) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [511]"); return ERROR_TOO_LONG; } error_number = is_sane(NESET, source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [512]"); return error_number; } @@ -71,7 +71,7 @@ int pharma_one(struct zint_symbol *symbol, unsigned char source[]) tester = atoi((char*)source); if((tester < 3) || (tester > 131070)) { - strcpy(symbol->errtxt, "error: data out of range"); + strcpy(symbol->errtxt, "Data out of range [513]"); return ERROR_INVALID_DATA; } @@ -120,7 +120,7 @@ int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char des if((tester < 4) || (tester > 64570080)) { - strcpy(symbol->errtxt, "error: data out of range"); + strcpy(symbol->errtxt, "Data out of range [533]"); return ERROR_INVALID_DATA; } do @@ -161,12 +161,12 @@ int pharma_two(struct zint_symbol *symbol, unsigned char source[]) strcpy(height_pattern, ""); if(ustrlen(source) > 8) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [531]"); return ERROR_TOO_LONG; } error_number = is_sane(NESET, source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [532]"); return error_number; } error_number = pharma_two_calc(symbol, source, height_pattern); @@ -204,13 +204,13 @@ int codabar(struct zint_symbol *symbol, unsigned char source[]) strcpy(dest, ""); if(ustrlen(source) > 60) { /* No stack smashing please */ - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [181]"); return ERROR_TOO_LONG; } to_upper(source); error_number = is_sane(CASET, source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [182]"); return error_number; } @@ -218,14 +218,14 @@ int codabar(struct zint_symbol *symbol, unsigned char source[]) if(((source[0] != 'A') && (source[0] != 'B')) && ((source[0] != 'C') && (source[0] != 'D'))) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [183]"); return 6; } if(((source[ustrlen(source) - 1] != 'A') && (source[ustrlen(source) - 1] != 'B')) && ((source[ustrlen(source) - 1] != 'C') && (source[ustrlen(source) - 1] != 'D'))) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [184]"); return 6; } @@ -249,12 +249,12 @@ int code32(struct zint_symbol *symbol, unsigned char source[]) /* Validate the input */ if(ustrlen(source) > 8) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [C91]"); return ERROR_TOO_LONG; } error_number = is_sane(NESET, source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [C92]"); return error_number; } diff --git a/backend/pdf417.c b/backend/pdf417.c index bdc95a36..c6cb9645 100644 --- a/backend/pdf417.c +++ b/backend/pdf417.c @@ -706,12 +706,12 @@ int pdf417enc(struct zint_symbol *symbol, unsigned char source[]) errno = 0; if((symbol->option_1 < -1) || (symbol->option_1 > 8)) { - strcpy(symbol->errtxt, "warning: security value out of range"); + strcpy(symbol->errtxt, "Security value out of range [551]"); symbol->option_1 = -1; errno = WARN_INVALID_OPTION; } if((symbol->option_2 < 0) || (symbol->option_2 > 30)) { - strcpy(symbol->errtxt, "warning: number of columns out of range"); + strcpy(symbol->errtxt, "Number of columns out of range [552]"); symbol->option_2 = 0; errno = WARN_INVALID_OPTION; } @@ -723,23 +723,23 @@ int pdf417enc(struct zint_symbol *symbol, unsigned char source[]) if(codeerr != 0) { switch(codeerr) { case 1: - strcpy(symbol->errtxt, "error: no such file or file unreadable (PDF error 1)"); + strcpy(symbol->errtxt, "No such file or file unreadable [553]"); errno = ERROR_INVALID_OPTION; break; case 2: - strcpy(symbol->errtxt, "error: input string too long (PDF error 2)"); + strcpy(symbol->errtxt, "Input string too long [554]"); errno = ERROR_TOO_LONG; break; case 3: - strcpy(symbol->errtxt, "error: number of codewords per row too small (PDF error 3)"); + strcpy(symbol->errtxt, "Number of codewords per row too small [555]"); errno = WARN_INVALID_OPTION; break; case 4: - strcpy(symbol->errtxt, "error: data too long for specified number of columns (PDF error 4)"); + strcpy(symbol->errtxt, "Data too long for specified number of columns [556]"); errno = ERROR_TOO_LONG; break; default: - strcpy(symbol->errtxt, "error: something strange happened"); + strcpy(symbol->errtxt, "Something strange happened [557]"); errno = ERROR_ENCODING_PROBLEM; break; } @@ -807,11 +807,11 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[]) /* This is where it all changes! */ if(mclength > 126) { - strcpy(symbol->errtxt, "error: input data too long"); + strcpy(symbol->errtxt, "Input data too long [841]"); return ERROR_TOO_LONG; } if(symbol->option_2 > 4) { - strcpy(symbol->errtxt, "warning: specified width out of range"); + strcpy(symbol->errtxt, "Specified width out of range [842]"); symbol->option_2 = 0; codeerr = WARN_INVALID_OPTION; } @@ -823,21 +823,21 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[]) if((symbol->option_2 == 1) && (mclength > 20)) { /* the user specified 1 column but the data doesn't fit - go to automatic */ symbol->option_2 = 0; - strcpy(symbol->errtxt, "warning: specified symbol size too small for data"); + strcpy(symbol->errtxt, "Specified symbol size too small for data [843]"); codeerr = WARN_INVALID_OPTION; } if((symbol->option_2 == 2) && (mclength > 37)) { /* the user specified 2 columns but the data doesn't fit - go to automatic */ symbol->option_2 = 0; - strcpy(symbol->errtxt, "warning: specified symbol size too small for data"); + strcpy(symbol->errtxt, "Specified symbol size too small for data [844]"); codeerr = WARN_INVALID_OPTION; } if((symbol->option_2 == 3) && (mclength > 82)) { /* the user specified 3 columns but the data doesn't fit - go to automatic */ symbol->option_2 = 0; - strcpy(symbol->errtxt, "warning: specified symbol size too small for data"); + strcpy(symbol->errtxt, "Specified symbol size too small for data [845]"); codeerr = WARN_INVALID_OPTION; } diff --git a/backend/plessey.c b/backend/plessey.c index a41c22ae..bb79bc52 100644 --- a/backend/plessey.c +++ b/backend/plessey.c @@ -47,12 +47,12 @@ int plessey(struct zint_symbol *symbol, unsigned char source[]) strcpy(dest, ""); if(ustrlen(source) > 65) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [861]"); return ERROR_TOO_LONG; } error_number = is_sane(SSET, source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [862]"); return error_number; } checkptr = calloc (1, ustrlen(source) * 4 + 8); @@ -108,12 +108,12 @@ int msi_plessey(struct zint_symbol *symbol, unsigned char source[]) strcpy(dest, ""); if(ustrlen(source) > 55) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [471]"); return ERROR_TOO_LONG; } error_number = is_sane(NESET, source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [472]"); return error_number; } @@ -146,12 +146,12 @@ int msi_plessey_mod10(struct zint_symbol *symbol, unsigned char source[]) strcpy(dest, ""); if(ustrlen(source) > 55) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [473]"); return ERROR_TOO_LONG; } error_number = is_sane(NESET, source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [474]"); return error_number; } @@ -244,12 +244,12 @@ int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[]) strcpy(dest, ""); if(ustrlen(source) > 55) { /* No Entry Stack Smashers! */ - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [475]"); return ERROR_TOO_LONG; } error_number = is_sane(NESET, source); if (error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [476]"); return error_number; } @@ -401,12 +401,12 @@ int msi_plessey_mod11(struct zint_symbol *symbol, unsigned char source[]) strcpy(dest, ""); if(ustrlen(source) > 55) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [477]"); return ERROR_TOO_LONG; } error_number = is_sane(NESET, source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [478]"); return error_number; } @@ -471,12 +471,12 @@ int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[]) strcpy(dest, ""); if(ustrlen(source) > 55) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [479]"); return ERROR_TOO_LONG; } error_number = is_sane(NESET, source); if (error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [47A]"); return error_number; } diff --git a/backend/png.c b/backend/png.c index 4941258e..a5008808 100644 --- a/backend/png.c +++ b/backend/png.c @@ -84,21 +84,21 @@ int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, c to_upper((unsigned char*)symbol->bgcolour); if(strlen(symbol->fgcolour) != 6) { - strcpy(symbol->errtxt, "error: malformed foreground colour target"); + strcpy(symbol->errtxt, "Malformed foreground colour target [B1]"); return ERROR_INVALID_OPTION; } if(strlen(symbol->bgcolour) != 6) { - strcpy(symbol->errtxt, "error: malformed background colour target"); + strcpy(symbol->errtxt, "Malformed background colour target [B2]"); return ERROR_INVALID_OPTION; } errno = is_sane(SSET, (unsigned char*)symbol->fgcolour); if (errno == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: malformed foreground colour target"); + strcpy(symbol->errtxt, "Malformed foreground colour target [B3]"); return ERROR_INVALID_OPTION; } errno = is_sane(SSET, (unsigned char*)symbol->bgcolour); if (errno == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: malformed background colour target"); + strcpy(symbol->errtxt, "Malformed background colour target [B4]"); return ERROR_INVALID_OPTION; } @@ -111,7 +111,7 @@ int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, c /* Open output file in binary mode */ if (!(graphic->outfile = fopen(symbol->outfile, "wb"))) { - strcpy(symbol->errtxt, "error: can't open output file"); + strcpy(symbol->errtxt, "Can't open output file [B5]"); return ERROR_FILE_ACCESS; } @@ -119,21 +119,21 @@ int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, c png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, graphic, writepng_error_handler, NULL); if (!png_ptr) { - strcpy(symbol->errtxt, "error: out of memory"); + strcpy(symbol->errtxt, "Out of memory [B6]"); return ERROR_MEMORY; } info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_write_struct(&png_ptr, NULL); - strcpy(symbol->errtxt, "error: out of memory"); + strcpy(symbol->errtxt, "Out of memory [B7]"); return ERROR_MEMORY; } /* catch jumping here */ if (setjmp(graphic->jmpbuf)) { png_destroy_write_struct(&png_ptr, &info_ptr); - strcpy(symbol->errtxt, "error: libpng error occurred"); + strcpy(symbol->errtxt, "libpng error occurred [B8]"); return ERROR_MEMORY; } @@ -375,7 +375,7 @@ int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle) image_height = 300; if (!(pixelbuf = (char *) malloc(image_width * image_height))) { - printf("Insifficient memory for pixel buffer"); + printf("Insifficient memory for pixel buffer [B9]"); return ERROR_ENCODING_PROBLEM; } else { for(i = 0; i < (image_width * image_height); i++) { @@ -503,7 +503,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle) image_height = 2 * (symbol->height + textoffset + yoffset + yoffset); if (!(pixelbuf = (char *) malloc(image_width * image_height))) { - printf("Insifficient memory for pixel buffer"); + printf("Insifficient memory for pixel buffer [BA]"); return ERROR_ENCODING_PROBLEM; } else { for(i = 0; i < (image_width * image_height); i++) { diff --git a/backend/postal.c b/backend/postal.c index 14dbafe0..9b046c5a 100644 --- a/backend/postal.c +++ b/backend/postal.c @@ -57,12 +57,12 @@ int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[]) error_number = 0; if(ustrlen(source) > 90) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [401]"); return ERROR_TOO_LONG; } error_number = is_sane(NESET, source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [402]"); return error_number; } sum = 0; @@ -133,12 +133,12 @@ int planet(struct zint_symbol *symbol, unsigned char source[], char dest[]) error_number = 0; if(ustrlen(source) > 90) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [821]"); return ERROR_TOO_LONG; } error_number = is_sane(NESET, source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [822]"); return error_number; } sum = 0; @@ -212,12 +212,12 @@ int fim(struct zint_symbol *symbol, unsigned char source[]) to_upper(source); if(ustrlen(source) > 1) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [491]"); return ERROR_TOO_LONG; } error_number = is_sane(BESET, source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [492]"); return error_number; } lookup(BESET, FIMTable, source[0], dest); @@ -275,12 +275,12 @@ int royal_plot(struct zint_symbol *symbol, unsigned char source[]) to_upper(source); if(ustrlen(source) > 120) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [701]"); return ERROR_TOO_LONG; } error_number = is_sane(KRSET, source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [702]"); return error_number; } check = rm4scc((char*)source, (unsigned char*)height_pattern); @@ -329,12 +329,12 @@ int kix_code(struct zint_symbol *symbol, unsigned char source[]) to_upper(source); if(ustrlen(source) != 11) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [901]"); return ERROR_TOO_LONG; } error_number = is_sane(KRSET, source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [902]"); return error_number; } for (i = 0; i < ustrlen(source); i++) { @@ -380,7 +380,7 @@ int daft_code(struct zint_symbol *symbol, unsigned char source[]) input_length = ustrlen(source); strcpy(local_source, (char*)source); if(input_length > 50) { - strcpy(symbol->errtxt, "Input too long"); + strcpy(symbol->errtxt, "Input too long [931]"); return ERROR_TOO_LONG; } to_upper((unsigned char*)local_source); @@ -428,12 +428,12 @@ int flattermarken(struct zint_symbol *symbol, unsigned char source[]) strcpy(dest, ""); if(ustrlen(source) > 90) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [281]"); return ERROR_TOO_LONG; } error_number = is_sane(NESET, source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [282]"); return error_number; } diff --git a/backend/ps.c b/backend/ps.c index 0aca6cb7..d38ad171 100644 --- a/backend/ps.c +++ b/backend/ps.c @@ -52,7 +52,7 @@ int ps_plot(struct zint_symbol *symbol) feps = fopen(symbol->outfile, "w"); if(feps == NULL) { - strcpy(symbol->errtxt, "error: could not open output file"); + strcpy(symbol->errtxt, "Could not open output file [C1]"); return ERROR_FILE_ACCESS; } @@ -61,21 +61,21 @@ int ps_plot(struct zint_symbol *symbol) to_upper((unsigned char*)symbol->bgcolour); if(strlen(symbol->fgcolour) != 6) { - strcpy(symbol->errtxt, "error: malformed foreground colour target"); + strcpy(symbol->errtxt, "Malformed foreground colour target [C2]"); return ERROR_INVALID_OPTION; } if(strlen(symbol->bgcolour) != 6) { - strcpy(symbol->errtxt, "error: malformed background colour target"); + strcpy(symbol->errtxt, "Malformed background colour target [C3]"); return ERROR_INVALID_OPTION; } error_number = is_sane(SSET, (unsigned char*)symbol->fgcolour); if (error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: malformed foreground colour target"); + strcpy(symbol->errtxt, "Malformed foreground colour target [C4]"); return ERROR_INVALID_OPTION; } error_number = is_sane(SSET, (unsigned char*)symbol->bgcolour); if (error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: malformed background colour target"); + strcpy(symbol->errtxt, "Malformed background colour target [C5]"); return ERROR_INVALID_OPTION; } diff --git a/backend/qr.c b/backend/qr.c index 071ec417..1193b6a1 100644 --- a/backend/qr.c +++ b/backend/qr.c @@ -73,7 +73,7 @@ int qr_code(struct zint_symbol *symbol, unsigned char source[]) code = encode(symbol->option_1, symbol->option_2, source); if(code == NULL) { - strcpy(symbol->errtxt, "error: libqrencode failed to encode the input data"); + strcpy(symbol->errtxt, "libqrencode failed to encode the input data [581]"); return ERROR_ENCODING_PROBLEM; } @@ -100,7 +100,7 @@ int qr_code(struct zint_symbol *symbol, unsigned char source[]) /* Handler if no QR Encode library is available */ int qr_code(struct zint_symbol *symbol, unsigned char source[]) { - strcpy(symbol->errtxt, "error: QR Code library not available"); + strcpy(symbol->errtxt, "QR Code library not available [580]"); return ERROR_INVALID_OPTION; } #endif diff --git a/backend/rss.c b/backend/rss.c index 5fc8ea30..c560dd4a 100644 --- a/backend/rss.c +++ b/backend/rss.c @@ -150,12 +150,12 @@ int rss14(struct zint_symbol *symbol, unsigned char source[]) separator_row = 0; if(ustrlen(source) > 13) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [291]"); return ERROR_TOO_LONG; } error_number = is_sane(NESET, source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [292]"); return error_number; } @@ -647,12 +647,12 @@ int rsslimited(struct zint_symbol *symbol, unsigned char source[]) separator_row = 0; if(ustrlen(source) > 13) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [301]"); return ERROR_TOO_LONG; } error_number = is_sane(NESET, source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [302]"); return error_number; } @@ -1189,7 +1189,7 @@ int rss_binary_string(struct zint_symbol *symbol, unsigned char source[], char b if((source[i] < '0') || (source[i] > '9')) { if((source[i] != '[') && (source[i] != ']')) { /* Something is wrong */ - strcpy(symbol->errtxt, "Invalid characters in input data"); + strcpy(symbol->errtxt, "Invalid characters in input data [314]"); return ERROR_INVALID_DATA; } } @@ -1560,7 +1560,7 @@ int rss_binary_string(struct zint_symbol *symbol, unsigned char source[], char b if(latch == 1) { /* Invalid characters in input data */ - strcpy(symbol->errtxt, "Invalid characters in input data"); + strcpy(symbol->errtxt, "Invalid characters in input data [315]"); return ERROR_INVALID_DATA; } @@ -1793,7 +1793,7 @@ int rss_binary_string(struct zint_symbol *symbol, unsigned char source[], char b } if(strlen(binary_string) > 252) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [316]"); return ERROR_TOO_LONG; } @@ -1841,14 +1841,14 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[]) reader=0; if(source[0] != '[') { - strcpy(symbol->errtxt, "Data does not start with an AI"); + strcpy(symbol->errtxt, "Data does not start with an AI [311]"); return ERROR_INVALID_DATA; } for(i = 0; i < ustrlen(source) - 1; i++) { if((source[i] == '[') && (source[i + 1] == '[')) { /* Can't have nested brackets - Quit */ - strcpy(symbol->errtxt, "Nested AI detected (two or more open brackets)"); + strcpy(symbol->errtxt, "Nested AI detected (two or more open brackets) [312]"); return ERROR_INVALID_DATA; } } @@ -1856,7 +1856,7 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[]) for(i = 0; i < ustrlen(source) - 1; i++) { if((source[i] == ']') && (source[i + 1] == ']')) { /* Can't have nested brackets - Quit */ - strcpy(symbol->errtxt, "Nested AI detected (two or more close brackets)"); + strcpy(symbol->errtxt, "Nested AI detected (two or more close brackets) [313]"); return ERROR_INVALID_DATA; } } diff --git a/backend/telepen.c b/backend/telepen.c index dc1f36b2..f254becf 100644 --- a/backend/telepen.c +++ b/backend/telepen.c @@ -62,14 +62,14 @@ int telepen(struct zint_symbol *symbol, unsigned char source[]) count = 0; if(ustrlen(source) > 30) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [321]"); return ERROR_TOO_LONG; } for(i = 0; i < ustrlen(source); i++) { if(source[i] > 127) { /* Cannot encode extended ASCII */ - strcpy(symbol->errtxt, "error: invalid characters in input data"); + strcpy(symbol->errtxt, "Invalid characters in input data [322]"); return ERROR_INVALID_DATA; } } @@ -111,13 +111,13 @@ int telepen_num(struct zint_symbol *symbol, unsigned char source[]) count = 0; if(input_length > 60) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [871]"); return ERROR_TOO_LONG; } to_upper(local_source); error_number = is_sane(NASET, local_source); if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [872]"); return error_number; } @@ -142,7 +142,7 @@ int telepen_num(struct zint_symbol *symbol, unsigned char source[]) for (i=0; i < input_length; i+=2) { if(local_source[i] == 'X') { - strcpy(symbol->errtxt, "Invalid position of X in Telepen data"); + strcpy(symbol->errtxt, "Invalid position of X in Telepen data [873]"); return ERROR_INVALID_DATA; } diff --git a/backend/upcean.c b/backend/upcean.c index cb5b4fee..42c6d62f 100644 --- a/backend/upcean.c +++ b/backend/upcean.c @@ -151,7 +151,7 @@ void upce(struct zint_symbol *symbol, unsigned char source[], char dest[]) equivalent[10] = source[4]; if(((source[2] == '0') || (source[2] == '1')) || (source[2] == '2')) { /* Note 1 - "X3 shall not be equal to 0, 1 or 2" */ - strcpy(symbol->errtxt, "warning: invalid UPC-E data"); + strcpy(symbol->errtxt, "Invalid UPC-E data [371]"); } break; case '4': @@ -160,7 +160,7 @@ void upce(struct zint_symbol *symbol, unsigned char source[], char dest[]) equivalent[10] = source[4]; if(source[3] == '0') { /* Note 2 - "X4 shall not be equal to 0" */ - strcpy(symbol->errtxt, "warning: invalid UPC-E data"); + strcpy(symbol->errtxt, "Invalid UPC-E data [372]"); } break; case '5': @@ -174,7 +174,7 @@ void upce(struct zint_symbol *symbol, unsigned char source[], char dest[]) equivalent[10] = emode; if(source[4] == '0') { /* Note 3 - "X5 shall not be equal to 0" */ - strcpy(symbol->errtxt, "warning: invalid UPC-E data"); + strcpy(symbol->errtxt, "Invalid UPC-E data [373]"); } break; } @@ -403,14 +403,14 @@ int isbn(struct zint_symbol *symbol, unsigned char source[], char dest[]) /* Mak to_upper(source); errno = is_sane("0123456789X", source); if(errno == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in input"); + strcpy(symbol->errtxt, "Invalid characters in input [691]"); return errno; } /* Input must be 9, 10 or 13 characters */ if(((ustrlen(source) < 9) || (ustrlen(source) > 13)) || ((ustrlen(source) > 10) && (ustrlen(source) < 13))) { - strcpy(symbol->errtxt, "error: input wrong length"); + strcpy(symbol->errtxt, "Input wrong length [692]"); return ERROR_TOO_LONG; } @@ -419,14 +419,14 @@ int isbn(struct zint_symbol *symbol, unsigned char source[], char dest[]) /* Mak if(!(((source[0] == '9') && (source[1] == '7')) && ((source[2] == '8') || (source[2] == '9')))) { - strcpy(symbol->errtxt, "error: invalid ISBN"); + strcpy(symbol->errtxt, "Invalid ISBN [693]"); return ERROR_INVALID_DATA; } check_digit = isbn13_check(source); if (source[ustrlen(source) - 1] != check_digit) { - strcpy(symbol->errtxt, "error: incorrect ISBN check"); + strcpy(symbol->errtxt, "Incorrect ISBN check [694]"); return ERROR_INVALID_CHECK; } source[12] = '\0'; @@ -439,7 +439,7 @@ int isbn(struct zint_symbol *symbol, unsigned char source[], char dest[]) /* Mak check_digit = isbn_check(source); if(check_digit != source[ustrlen(source) - 1]) { - strcpy(symbol->errtxt, "error: incorrect ISBN check"); + strcpy(symbol->errtxt, "Incorrect ISBN check [695]"); return ERROR_INVALID_CHECK; } for(i = 13; i > 0; i--) @@ -467,7 +467,7 @@ int isbn(struct zint_symbol *symbol, unsigned char source[], char dest[]) /* Mak check_digit = isbn_check(source); if(check_digit != source[ustrlen(source) - 1]) { - strcpy(symbol->errtxt, "error: incorrect SBN check"); + strcpy(symbol->errtxt, "Incorrect SBN check [696]"); return ERROR_INVALID_CHECK; } @@ -504,14 +504,14 @@ int eanx(struct zint_symbol *symbol, unsigned char source[]) writer = 0; if(ustrlen(source) > 19) { - strcpy(symbol->errtxt, "error: input too long"); + strcpy(symbol->errtxt, "Input too long [131]"); return ERROR_TOO_LONG; } if(symbol->symbology != BARCODE_ISBNX) { /* ISBN has it's own checking routine */ errno = is_sane(NASET, source); if(errno == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "error: invalid characters in data"); + strcpy(symbol->errtxt, "Invalid characters in data [132]"); return errno; } } @@ -555,7 +555,7 @@ int eanx(struct zint_symbol *symbol, unsigned char source[]) case 5: add_on(first_part, (char*)dest, 0); strcpy(symbol->text, (char*)first_part); break; case 7: ean8(symbol, first_part, (char*)dest); break; case 12: ean13(symbol, first_part, (char*)dest); break; - default: strcpy(symbol->errtxt, "error: invalid length input"); return ERROR_TOO_LONG; break; + default: strcpy(symbol->errtxt, "Invalid length input [133]"); return ERROR_TOO_LONG; break; } break; case BARCODE_EANX_CC: @@ -583,14 +583,14 @@ int eanx(struct zint_symbol *symbol, unsigned char source[]) symbol->row_height[symbol->rows + 2] = 2; symbol->rows += 3; ean13(symbol, first_part, (char*)dest); break; - default: strcpy(symbol->errtxt, "error: invalid length EAN input"); return ERROR_TOO_LONG; break; + default: strcpy(symbol->errtxt, "Invalid length EAN input [134]"); return ERROR_TOO_LONG; break; } break; case BARCODE_UPCA: if(ustrlen(first_part) == 11) { upca(symbol, first_part, (char*)dest); } else { - strcpy(symbol->errtxt, "error: input wrong length"); + strcpy(symbol->errtxt, "Input wrong length [135]"); return ERROR_TOO_LONG; } break; @@ -608,7 +608,7 @@ int eanx(struct zint_symbol *symbol, unsigned char source[]) symbol->rows += 3; upca(symbol, first_part, (char*)dest); } else { - strcpy(symbol->errtxt, "error: UPCA input wrong length"); + strcpy(symbol->errtxt, "UPCA input wrong length [136]"); return ERROR_TOO_LONG; } break; @@ -616,7 +616,7 @@ int eanx(struct zint_symbol *symbol, unsigned char source[]) if((ustrlen(first_part) >= 6) && (ustrlen(first_part) <= 7)) { upce(symbol, first_part, (char*)dest); } else { - strcpy(symbol->errtxt, "error: input wrong length"); + strcpy(symbol->errtxt, "Input wrong length [137]"); return ERROR_TOO_LONG; } break; @@ -634,7 +634,7 @@ int eanx(struct zint_symbol *symbol, unsigned char source[]) symbol->rows += 3; upce(symbol, first_part, (char*)dest); } else { - strcpy(symbol->errtxt, "error: UPCE input wrong length"); + strcpy(symbol->errtxt, "UPCE input wrong length [138]"); return ERROR_TOO_LONG; } break; @@ -659,7 +659,7 @@ int eanx(struct zint_symbol *symbol, unsigned char source[]) concat(symbol->text, (char*)second_part); break; default: - strcpy(symbol->errtxt, "error: invalid length input"); + strcpy(symbol->errtxt, "Invalid length input [139]"); return ERROR_TOO_LONG; break; } diff --git a/frontend/main.c b/frontend/main.c index 407b6499..eaa5ee94 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -122,8 +122,8 @@ int data_process(struct zint_symbol *symbol, unsigned char source[], int rotate_ } } if(next == -1) { - strcpy(symbol->errtxt, "Invalid character in input string (only Latin-1 characters supported)"); - error_number = WARN_INVALID_OPTION; + strcpy(symbol->errtxt, "error: Invalid character in input string (only Latin-1 characters supported)"); + error_number = ERROR_INVALID_DATA; return error_number; } i = next; @@ -160,9 +160,11 @@ int main(int argc, char **argv) int c; int error_number; int rotate_angle; + int generated; error_number = 0; rotate_angle = 0; + generated = 0; my_symbol = ZBarcode_Create(); if(argc == 1) { @@ -301,7 +303,7 @@ int main(int argc, char **argv) case 'b': error_number = validator(NESET, optarg); if(error_number == ERROR_INVALID_DATA) { - printf("Invalid barcode type\n"); + fprintf(stderr, "Invalid barcode type\n"); exit(1); } my_symbol->symbology = atoi(optarg); @@ -310,7 +312,7 @@ int main(int argc, char **argv) case 'w': error_number = validator(NESET, optarg); if(error_number == ERROR_INVALID_DATA) { - printf("Invalid whitespace value\n"); + fprintf(stderr, "Invalid whitespace value\n"); exit(1); } if((atoi(optarg) >= 0) && (atoi(optarg) <= 1000)) { @@ -322,8 +324,9 @@ int main(int argc, char **argv) case 'd': /* we have some data! */ error_number = data_process(my_symbol, (unsigned char*)optarg, rotate_angle); + generated = 1; if(error_number != 0) { - printf("%s\n", my_symbol->errtxt); + fprintf(stderr, "%s\n", my_symbol->errtxt); ZBarcode_Delete(my_symbol); return 1; } @@ -342,21 +345,21 @@ int main(int argc, char **argv) break; default: - printf("?? getopt error 0%o\n", c); + fprintf(stderr, "?? getopt error 0%o\n", c); } } if (optind < argc) { - printf("Invalid option "); + fprintf(stderr, "Invalid option "); while (optind < argc) - printf("%s", argv[optind++]); - printf("\n"); + fprintf(stderr, "%s", argv[optind++]); + fprintf(stderr, "\n"); } - if(strcmp(my_symbol->errtxt, "")) { - printf(my_symbol->errtxt); - printf("\n"); + if(generated == 0) { + fprintf(stderr, "error: No data received, no symbol generated\n"); } + ZBarcode_Delete(my_symbol); return error_number;