2008-07-14 09:15:55 +12:00
|
|
|
/* main.c - Command line handling routines for Zint */
|
|
|
|
|
|
|
|
/*
|
|
|
|
libzint - the open source barcode library
|
2008-11-17 21:47:42 +13:00
|
|
|
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
|
2008-07-14 09:15:55 +12:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-06-03 08:23:38 +12:00
|
|
|
#ifndef _MSC_VER
|
2008-07-14 09:15:55 +12:00
|
|
|
#include <getopt.h>
|
|
|
|
#include <zint.h>
|
2009-06-03 08:23:38 +12:00
|
|
|
#else
|
|
|
|
#include "getopt.h"
|
|
|
|
#include "zint.h"
|
|
|
|
#endif
|
2008-07-14 09:15:55 +12:00
|
|
|
#define NESET "0123456789"
|
|
|
|
|
2010-06-13 23:03:40 +12:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#include <malloc.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-09-27 06:01:20 +12:00
|
|
|
void types(void) {
|
2010-01-29 06:55:59 +13:00
|
|
|
printf( " 1: Code 11 51: Pharma One-Track 90: KIX Code\n"
|
|
|
|
" 2: Standard 2of5 52: PZN 92: Aztec Code\n"
|
|
|
|
" 3: Interleaved 2of5 53: Pharma Two-Track 93: DAFT Code\n"
|
|
|
|
" 4: IATA 2of5 55: PDF417 97: Micro QR Code\n"
|
|
|
|
" 6: Data Logic 56: PDF417 Trunc 98: HIBC Code 128\n"
|
|
|
|
" 7: Industrial 2of5 57: Maxicode 99: HIBC Code 39\n"
|
|
|
|
" 8: Code 39 58: QR Code 102: HIBC Data Matrix\n"
|
|
|
|
" 9: Extended Code 39 60: Code 128-B 104: HIBC QR Code\n"
|
|
|
|
"13: EAN 63: AP Standard Customer 106: HIBC PDF417\n"
|
|
|
|
"16: GS1-128 66: AP Reply Paid 108: HIBC MicroPDF417\n"
|
|
|
|
"18: Codabar 67: AP Routing 112: HIBC Aztec Code\n"
|
|
|
|
"20: Code 128 68: AP Redirection 128: Aztec Runes\n"
|
|
|
|
"21: Leitcode 69: ISBN 129: Code 23\n"
|
|
|
|
"22: Identcode 70: RM4SCC 130: Comp EAN\n"
|
|
|
|
"23: Code 16k 71: Data Matrix 131: Comp GS1-128\n"
|
|
|
|
"24: Code 49 72: EAN-14 132: Comp Databar-14\n"
|
|
|
|
"25: Code 93 75: NVE-18 133: Comp Databar Ltd\n"
|
|
|
|
"28: Flattermarken 76: Japanese Post 134: Comp Databar Ext\n"
|
|
|
|
"29: Databar-14 77: Korea Post 135: Comp UPC-A\n"
|
|
|
|
"30: Databar Limited 79: Databar-14 Stack 136: Comp UPC-E\n"
|
|
|
|
"31: Databar Extended 80: Databar-14 Stack Omni 137: Comp Databar-14 Stack\n"
|
|
|
|
"32: Telepen Alpha 81: Databar Extended Stack 138: Comp Databar Stack Omni\n"
|
|
|
|
"34: UPC-A 82: Planet 139: Comp Databar Ext Stack\n"
|
|
|
|
"37: UPC-E 84: MicroPDF 140: Channel Code\n"
|
|
|
|
"40: Postnet 85: USPS OneCode 141: Code One\n"
|
|
|
|
"47: MSI Plessey 86: UK Plessey 142: Grid Matrix\n"
|
|
|
|
"49: FIM 87: Telepen Numeric\n"
|
|
|
|
"50: Logmars 89: ITF-14\n"
|
2008-12-08 09:12:57 +13:00
|
|
|
);
|
2008-09-27 06:01:20 +12:00
|
|
|
}
|
|
|
|
|
2008-07-14 09:15:55 +12:00
|
|
|
void usage(void)
|
|
|
|
{
|
|
|
|
printf(
|
|
|
|
"Zint version %s\n"
|
2009-06-20 06:30:47 +12:00
|
|
|
"Encode input data in a barcode and save as a PNG, EPS or SVG file.\n\n"
|
2008-07-14 09:15:55 +12:00
|
|
|
" -h, --help Display this message.\n"
|
2008-09-27 06:01:20 +12:00
|
|
|
" -t, --types Display table of barcode types\n"
|
2009-08-21 01:20:59 +12:00
|
|
|
" -i, --input=FILE Read data from FILE.\n"
|
2008-07-14 09:15:55 +12:00
|
|
|
" -o, --output=FILE Write image to FILE. (default is out.png)\n"
|
|
|
|
" -d, --data=DATA Barcode content.\n"
|
|
|
|
" -b, --barcode=NUMBER Number of barcode type (default is 20 (=Code128)).\n"
|
2008-12-25 10:31:07 +13:00
|
|
|
" --height=NUMBER Height of symbol in multiples of x-dimension.\n"
|
|
|
|
" -w, --whitesp=NUMBER Width of whitespace in multiples of x-dimension.\n"
|
|
|
|
" --border=NUMBER Width of border in multiples of x-dimension.\n"
|
2008-07-14 09:15:55 +12:00
|
|
|
" --box Add a box.\n"
|
|
|
|
" --bind Add boundary bars.\n"
|
|
|
|
" -r, --reverse Reverse colours (white on black).\n"
|
|
|
|
" --fg=COLOUR Specify a foreground colour.\n"
|
|
|
|
" --bg=COLOUR Specify a background colour.\n"
|
2008-12-22 01:17:14 +13:00
|
|
|
" --scale=NUMBER Adjust size of output image.\n"
|
|
|
|
" --directpng Send PNG output to stdout\n"
|
|
|
|
" --directeps Send EPS output to stdout\n"
|
2009-07-14 07:44:50 +12:00
|
|
|
" --directsvg Send SVG output to stdout\n"
|
2010-09-13 01:52:44 +12:00
|
|
|
" --dump Dump binary data to stdout\n"
|
2008-09-03 08:22:39 +12:00
|
|
|
" --rotate=NUMBER Rotate symbol (PNG output only).\n"
|
2008-07-14 09:15:55 +12:00
|
|
|
" --cols=NUMBER (PDF417) Number of columns.\n"
|
|
|
|
" --vers=NUMBER (QR Code) Version\n"
|
|
|
|
" --secure=NUMBER (PDF417 and QR Code) Error correction level.\n"
|
|
|
|
" --primary=STRING (Maxicode and Composite) Structured primary message.\n"
|
|
|
|
" --mode=NUMBER (Maxicode and Composite) Set encoding mode.\n"
|
2009-01-25 11:01:41 +13:00
|
|
|
" --gs1 Treat input as GS1 data\n"
|
2009-08-21 01:20:59 +12:00
|
|
|
" --binary Treat input as Binary data\n"
|
2010-02-27 22:58:15 +13:00
|
|
|
" --notext Remove human readable text\n"
|
2010-05-17 09:58:18 +12:00
|
|
|
" --square Force Data Matrix symbols to be square\n"
|
2010-10-19 09:08:29 +13:00
|
|
|
" --init Create reader initialisation symbol (Code 128)\n"
|
2010-12-20 11:23:59 +13:00
|
|
|
" --smalltext Use half-size text in PNG images\n"
|
2010-12-24 23:55:08 +13:00
|
|
|
" --batch Treat each line of input as a separate data set\n"
|
2010-10-19 09:08:29 +13:00
|
|
|
, ZINT_VERSION);
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
|
2008-10-01 04:13:35 +13:00
|
|
|
int validator(char test_string[], char source[])
|
|
|
|
{ /* Verifies that a string only uses valid characters */
|
|
|
|
unsigned int i, j, latch;
|
|
|
|
|
|
|
|
for(i = 0; i < strlen(source); i++) {
|
|
|
|
latch = 0;
|
|
|
|
for(j = 0; j < strlen(test_string); j++) {
|
|
|
|
if (source[i] == test_string[j]) { latch = 1; } }
|
|
|
|
if (!(latch)) {
|
|
|
|
return ERROR_INVALID_DATA; }
|
|
|
|
}
|
2012-12-31 02:55:05 +13:00
|
|
|
|
2008-10-01 04:13:35 +13:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-13 23:03:40 +12:00
|
|
|
int escape_char_process(struct zint_symbol *my_symbol, unsigned char input_string[], int length)
|
|
|
|
{
|
|
|
|
int error_number;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
#ifndef _MSC_VER
|
|
|
|
unsigned char escaped_string[length + 1];
|
|
|
|
#else
|
|
|
|
unsigned char* escaped_string = (unsigned char*)_alloca(length + 1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
j = 0;
|
2012-12-31 02:55:05 +13:00
|
|
|
|
2010-06-13 23:03:40 +12:00
|
|
|
do {
|
|
|
|
if(input_string[i] == '\\') {
|
|
|
|
switch(input_string[i + 1]) {
|
|
|
|
case '0': escaped_string[j] = 0x00; i += 2; break; /* Null */
|
|
|
|
case 'E': escaped_string[j] = 0x04; i += 2; break; /* End of Transmission */
|
|
|
|
case 'a': escaped_string[j] = 0x07; i += 2; break; /* Bell */
|
|
|
|
case 'b': escaped_string[j] = 0x08; i += 2; break; /* Backspace */
|
|
|
|
case 't': escaped_string[j] = 0x09; i += 2; break; /* Horizontal tab */
|
|
|
|
case 'n': escaped_string[j] = 0x0a; i += 2; break; /* Line feed */
|
|
|
|
case 'v': escaped_string[j] = 0x0b; i += 2; break; /* Vertical tab */
|
|
|
|
case 'f': escaped_string[j] = 0x0c; i += 2; break; /* Form feed */
|
|
|
|
case 'r': escaped_string[j] = 0x0d; i += 2; break; /* Carriage return */
|
|
|
|
case 'e': escaped_string[j] = 0x1b; i += 2; break; /* Escape */
|
|
|
|
case 'G': escaped_string[j] = 0x1d; i += 2; break; /* Group Separator */
|
|
|
|
case 'R': escaped_string[j] = 0x1e; i += 2; break; /* Record Separator */
|
|
|
|
case '\\': escaped_string[j] = '\\'; i += 2; break;
|
|
|
|
default: escaped_string[j] = input_string[i]; i++; break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
escaped_string[j] = input_string[i];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
j++;
|
|
|
|
} while (i < length);
|
|
|
|
escaped_string[j] = '\0';
|
2012-12-31 02:55:05 +13:00
|
|
|
|
2010-06-13 23:03:40 +12:00
|
|
|
error_number = ZBarcode_Encode(my_symbol, escaped_string, j);
|
2012-12-31 02:55:05 +13:00
|
|
|
|
2010-06-13 23:03:40 +12:00
|
|
|
return error_number;
|
|
|
|
}
|
|
|
|
|
2013-01-11 02:49:04 +13:00
|
|
|
static char itoc(int source)
|
2010-12-24 23:55:08 +13:00
|
|
|
{ /* Converts an integer value to its hexadecimal character */
|
|
|
|
if ((source >= 0) && (source <= 9)) {
|
|
|
|
return ('0' + source); }
|
|
|
|
else {
|
|
|
|
return ('A' + (source - 10)); }
|
|
|
|
}
|
|
|
|
|
2013-01-11 02:49:04 +13:00
|
|
|
static void concat(char dest[], char source[])
|
2010-12-24 23:55:08 +13:00
|
|
|
{ /* Concatinates dest[] with the contents of source[], copying /0 as well */
|
|
|
|
unsigned int i, j, n;
|
|
|
|
|
|
|
|
j = strlen(dest);
|
|
|
|
n = strlen(source);
|
|
|
|
for(i = 0; i <= n; i++) {
|
|
|
|
dest[i + j] = source[i]; }
|
|
|
|
}
|
|
|
|
|
|
|
|
int batch_process(struct zint_symbol *symbol, char *filename)
|
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
unsigned char buffer[7100];
|
2016-01-06 00:29:39 +13:00
|
|
|
unsigned char character = 0;
|
2010-12-24 23:55:08 +13:00
|
|
|
int posn = 0, error_number = 0, line_count = 1;
|
|
|
|
char output_file[127];
|
2010-12-25 11:09:40 +13:00
|
|
|
char number[12], reverse_number[12];
|
|
|
|
int inpos, local_line_count;
|
|
|
|
char format_string[127], reversed_string[127], format_char;
|
|
|
|
int format_len, i;
|
|
|
|
char adjusted[2];
|
2010-12-24 23:55:08 +13:00
|
|
|
|
|
|
|
memset(buffer, 0, sizeof(unsigned char) * 7100);
|
2010-12-27 06:09:18 +13:00
|
|
|
if(symbol->outfile[0] == '\0') {
|
2011-03-09 00:36:10 +13:00
|
|
|
strcpy(format_string, "~~~~~.png");
|
2010-12-25 11:09:40 +13:00
|
|
|
} else {
|
2010-12-27 06:09:18 +13:00
|
|
|
if(strlen(format_string) < 127) {
|
|
|
|
strcpy(format_string, symbol->outfile);
|
|
|
|
} else {
|
|
|
|
strcpy(symbol->errtxt, "Format string too long");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2010-12-25 11:09:40 +13:00
|
|
|
}
|
|
|
|
memset(adjusted, 0, sizeof(char) * 2);
|
2010-12-24 23:55:08 +13:00
|
|
|
|
|
|
|
if(!strcmp(filename, "-")) {
|
|
|
|
file = stdin;
|
|
|
|
} else {
|
|
|
|
file = fopen(filename, "rb");
|
|
|
|
if (!file) {
|
|
|
|
strcpy(symbol->errtxt, "Unable to read input file");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2015-08-19 00:17:59 +12:00
|
|
|
int intChar;
|
|
|
|
intChar = fgetc(file);
|
|
|
|
if (intChar == EOF) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
character = (unsigned char) intChar;
|
2010-12-24 23:55:08 +13:00
|
|
|
if(character == '\n') {
|
2010-12-27 06:09:18 +13:00
|
|
|
if(buffer[posn - 1] == '\r') {
|
|
|
|
/* CR+LF - assume Windows formatting and remove CR */
|
|
|
|
posn--;
|
|
|
|
buffer[posn] = '\0';
|
|
|
|
}
|
2010-12-25 11:09:40 +13:00
|
|
|
inpos = 0;
|
|
|
|
local_line_count = line_count;
|
|
|
|
memset(number, 0, sizeof(char) * 12);
|
|
|
|
memset(reverse_number, 0, sizeof(char) * 12);
|
|
|
|
memset(reversed_string, 0, sizeof(char) * 127);
|
|
|
|
memset(output_file, 0, sizeof(char) * 127);
|
|
|
|
do {
|
|
|
|
number[inpos] = itoc(local_line_count % 10);
|
|
|
|
local_line_count /= 10;
|
|
|
|
inpos++;
|
|
|
|
} while (local_line_count > 0);
|
2011-03-09 00:36:10 +13:00
|
|
|
number[inpos] = '\0';
|
2010-12-25 11:09:40 +13:00
|
|
|
|
|
|
|
for(i = 0; i < inpos; i++) {
|
|
|
|
reverse_number[i] = number[inpos - i - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
format_len = strlen(format_string);
|
|
|
|
for(i = format_len; i > 0; i--) {
|
|
|
|
format_char = format_string[i - 1];
|
|
|
|
|
|
|
|
switch(format_char) {
|
|
|
|
case '#':
|
|
|
|
if (inpos > 0) {
|
|
|
|
adjusted[0] = reverse_number[inpos - 1];
|
|
|
|
inpos--;
|
|
|
|
} else {
|
|
|
|
adjusted[0] = ' ';
|
|
|
|
}
|
|
|
|
break;
|
2011-03-09 00:36:10 +13:00
|
|
|
case '~':
|
2010-12-25 11:09:40 +13:00
|
|
|
if (inpos > 0) {
|
|
|
|
adjusted[0] = reverse_number[inpos - 1];
|
|
|
|
inpos--;
|
|
|
|
} else {
|
|
|
|
adjusted[0] = '0';
|
|
|
|
}
|
|
|
|
break;
|
2011-03-09 00:36:10 +13:00
|
|
|
case '@':
|
2010-12-25 11:09:40 +13:00
|
|
|
if (inpos > 0) {
|
|
|
|
adjusted[0] = reverse_number[inpos - 1];
|
|
|
|
inpos--;
|
|
|
|
} else {
|
|
|
|
adjusted[0] = '*';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
adjusted[0] = format_string[i - 1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
concat(reversed_string, adjusted);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < format_len; i++) {
|
|
|
|
output_file[i] = reversed_string[format_len - i - 1];
|
|
|
|
}
|
|
|
|
|
2010-12-24 23:55:08 +13:00
|
|
|
strcpy(symbol->outfile, output_file);
|
|
|
|
error_number = ZBarcode_Encode_and_Print(symbol, buffer, posn, 0);
|
|
|
|
if(error_number != 0) {
|
2010-12-25 11:09:40 +13:00
|
|
|
fprintf(stderr, "On line %d: %s\n", line_count, symbol->errtxt);
|
2012-12-31 02:55:05 +13:00
|
|
|
fflush(stderr);
|
2010-12-24 23:55:08 +13:00
|
|
|
}
|
|
|
|
ZBarcode_Clear(symbol);
|
|
|
|
memset(buffer, 0, sizeof(unsigned char) * 7100);
|
|
|
|
posn = 0;
|
|
|
|
line_count++;
|
|
|
|
} else {
|
|
|
|
buffer[posn] = character;
|
|
|
|
posn++;
|
|
|
|
}
|
2010-12-27 06:09:18 +13:00
|
|
|
if(posn > 7090) {
|
|
|
|
fprintf(stderr, "On line %d: Input data too long\n", line_count);
|
2012-12-31 02:55:05 +13:00
|
|
|
fflush(stderr);
|
2010-12-27 06:09:18 +13:00
|
|
|
do {
|
|
|
|
character = fgetc(file);
|
|
|
|
} while((!feof(file)) && (character != '\n'));
|
|
|
|
}
|
|
|
|
} while ((!feof(file)) && (line_count < 2000000000));
|
|
|
|
|
|
|
|
if(character != '\n') {
|
|
|
|
fprintf(stderr, "Warning: No newline at end of file\n");
|
2012-12-31 02:55:05 +13:00
|
|
|
fflush(stderr);
|
2010-12-27 06:09:18 +13:00
|
|
|
}
|
2010-12-24 23:55:08 +13:00
|
|
|
|
|
|
|
fclose(file);
|
|
|
|
return error_number;
|
|
|
|
}
|
|
|
|
|
2008-07-14 09:15:55 +12:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct zint_symbol *my_symbol;
|
|
|
|
int c;
|
2008-09-27 06:01:20 +12:00
|
|
|
int error_number;
|
2008-09-03 08:22:39 +12:00
|
|
|
int rotate_angle;
|
2008-10-05 18:51:58 +13:00
|
|
|
int generated;
|
2010-12-24 23:55:08 +13:00
|
|
|
int batch_mode;
|
2008-07-14 09:15:55 +12:00
|
|
|
|
2008-09-27 06:01:20 +12:00
|
|
|
error_number = 0;
|
2008-09-03 08:22:39 +12:00
|
|
|
rotate_angle = 0;
|
2008-10-05 18:51:58 +13:00
|
|
|
generated = 0;
|
2008-07-14 09:15:55 +12:00
|
|
|
my_symbol = ZBarcode_Create();
|
2009-01-16 07:35:03 +13:00
|
|
|
my_symbol->input_mode = UNICODE_MODE;
|
2010-12-24 23:55:08 +13:00
|
|
|
batch_mode = 0;
|
2008-07-14 09:15:55 +12:00
|
|
|
|
|
|
|
if(argc == 1) {
|
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
int option_index = 0;
|
|
|
|
static struct option long_options[] = {
|
|
|
|
{"help", 0, 0, 'h'},
|
2008-09-27 06:01:20 +12:00
|
|
|
{"types", 0, 0, 't'},
|
2008-07-14 09:15:55 +12:00
|
|
|
{"bind", 0, 0, 0},
|
|
|
|
{"box", 0, 0, 0},
|
2008-12-22 01:17:14 +13:00
|
|
|
{"directeps", 0, 0, 0},
|
|
|
|
{"directpng", 0, 0, 0},
|
2009-02-23 06:21:11 +13:00
|
|
|
{"directsvg", 0, 0, 0},
|
2010-09-13 01:52:44 +12:00
|
|
|
{"dump", 0, 0, 0},
|
2009-06-03 08:23:38 +12:00
|
|
|
{"barcode", 1, 0, 'b'},
|
|
|
|
{"height", 1, 0, 0},
|
|
|
|
{"whitesp", 1, 0, 'w'},
|
|
|
|
{"border", 1, 0, 0},
|
|
|
|
{"data", 1, 0, 'd'},
|
|
|
|
{"output", 1, 0, 'o'},
|
2009-08-21 01:20:59 +12:00
|
|
|
{"input", 1, 0, 'i'},
|
2009-06-03 08:23:38 +12:00
|
|
|
{"fg", 1, 0, 0},
|
|
|
|
{"bg", 1, 0, 0},
|
|
|
|
{"cols", 1, 0, 0},
|
|
|
|
{"vers", 1, 0, 0},
|
|
|
|
{"rotate", 1, 0, 0},
|
|
|
|
{"secure", 1, 0, 0},
|
2008-07-14 09:15:55 +12:00
|
|
|
{"reverse", 1, 0, 'r'},
|
2009-06-03 08:23:38 +12:00
|
|
|
{"mode", 1, 0, 0},
|
|
|
|
{"primary", 1, 0, 0},
|
|
|
|
{"scale", 1, 0, 0},
|
2009-01-16 07:35:03 +13:00
|
|
|
{"gs1", 0, 0, 0},
|
2009-01-25 11:01:41 +13:00
|
|
|
{"kanji", 0, 0, 0},
|
2009-02-23 03:13:32 +13:00
|
|
|
{"sjis", 0, 0, 0},
|
2009-08-21 01:20:59 +12:00
|
|
|
{"binary", 0, 0, 0},
|
2010-02-27 22:58:15 +13:00
|
|
|
{"notext", 0, 0, 0},
|
2010-05-17 09:58:18 +12:00
|
|
|
{"square", 0, 0, 0},
|
2010-10-19 09:08:29 +13:00
|
|
|
{"init", 0, 0, 0},
|
2010-12-20 11:23:59 +13:00
|
|
|
{"smalltext", 0, 0, 0},
|
2010-12-24 23:55:08 +13:00
|
|
|
{"batch", 0, 0, 0},
|
2008-07-14 09:15:55 +12:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
2008-09-27 06:01:20 +12:00
|
|
|
c = getopt_long(argc, argv, "htb:w:d:o:i:rcmp", long_options, &option_index);
|
2008-07-14 09:15:55 +12:00
|
|
|
if(c == -1) break;
|
|
|
|
|
|
|
|
switch(c) {
|
|
|
|
case 0:
|
|
|
|
if(!strcmp(long_options[option_index].name, "bind")) {
|
2008-12-22 01:17:14 +13:00
|
|
|
my_symbol->output_options += BARCODE_BIND;
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
if(!strcmp(long_options[option_index].name, "box")) {
|
2008-12-22 01:17:14 +13:00
|
|
|
my_symbol->output_options += BARCODE_BOX;
|
|
|
|
}
|
2010-10-19 09:08:29 +13:00
|
|
|
if(!strcmp(long_options[option_index].name, "init")) {
|
|
|
|
my_symbol->output_options += READER_INIT;
|
|
|
|
}
|
2010-12-20 11:23:59 +13:00
|
|
|
if(!strcmp(long_options[option_index].name, "smalltext")) {
|
|
|
|
my_symbol->output_options += SMALL_TEXT;
|
|
|
|
}
|
2008-12-22 01:17:14 +13:00
|
|
|
if(!strcmp(long_options[option_index].name, "directeps")) {
|
|
|
|
my_symbol->output_options += BARCODE_STDOUT;
|
|
|
|
strncpy(my_symbol->outfile, "dummy.eps", 10);
|
|
|
|
}
|
|
|
|
if(!strcmp(long_options[option_index].name, "directpng")) {
|
|
|
|
my_symbol->output_options += BARCODE_STDOUT;
|
|
|
|
strncpy(my_symbol->outfile, "dummy.png", 10);
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
2009-02-23 06:21:11 +13:00
|
|
|
if(!strcmp(long_options[option_index].name, "directsvg")) {
|
|
|
|
my_symbol->output_options += BARCODE_STDOUT;
|
|
|
|
strncpy(my_symbol->outfile, "dummy.svg", 10);
|
|
|
|
}
|
2010-09-13 01:52:44 +12:00
|
|
|
if(!strcmp(long_options[option_index].name, "dump")) {
|
|
|
|
my_symbol->output_options += BARCODE_STDOUT;
|
|
|
|
strncpy(my_symbol->outfile, "dummy.txt", 10);
|
|
|
|
}
|
2009-01-16 07:35:03 +13:00
|
|
|
if(!strcmp(long_options[option_index].name, "gs1")) {
|
|
|
|
my_symbol->input_mode = GS1_MODE;
|
|
|
|
}
|
2009-01-25 11:01:41 +13:00
|
|
|
if(!strcmp(long_options[option_index].name, "kanji")) {
|
|
|
|
my_symbol->input_mode = KANJI_MODE;
|
|
|
|
}
|
2009-02-23 03:13:32 +13:00
|
|
|
if(!strcmp(long_options[option_index].name, "sjis")) {
|
|
|
|
my_symbol->input_mode = SJIS_MODE;
|
|
|
|
}
|
2009-08-21 01:20:59 +12:00
|
|
|
if(!strcmp(long_options[option_index].name, "binary")) {
|
|
|
|
my_symbol->input_mode = DATA_MODE;
|
|
|
|
}
|
2009-06-03 08:23:38 +12:00
|
|
|
if(!strcmp(long_options[option_index].name, "fg")) {
|
2008-07-14 09:15:55 +12:00
|
|
|
strncpy(my_symbol->fgcolour, optarg, 7);
|
|
|
|
}
|
2009-06-03 08:23:38 +12:00
|
|
|
if(!strcmp(long_options[option_index].name, "bg")) {
|
2008-07-14 09:15:55 +12:00
|
|
|
strncpy(my_symbol->bgcolour, optarg, 7);
|
|
|
|
}
|
2010-02-27 22:58:15 +13:00
|
|
|
if(!strcmp(long_options[option_index].name, "notext")) {
|
2010-05-17 09:58:18 +12:00
|
|
|
my_symbol->show_hrt = 0;
|
|
|
|
}
|
|
|
|
if(!strcmp(long_options[option_index].name, "square")) {
|
|
|
|
my_symbol->option_3 = DM_SQUARE;
|
2010-02-27 22:58:15 +13:00
|
|
|
}
|
2009-06-03 08:23:38 +12:00
|
|
|
if(!strcmp(long_options[option_index].name, "scale")) {
|
2008-12-22 00:29:15 +13:00
|
|
|
my_symbol->scale = (float)(atof(optarg));
|
|
|
|
if(my_symbol->scale < 0.01) {
|
|
|
|
/* Zero and negative values are not permitted */
|
|
|
|
fprintf(stderr, "Invalid scale value\n");
|
2012-12-31 02:55:05 +13:00
|
|
|
fflush(stderr);
|
2008-12-22 00:29:15 +13:00
|
|
|
my_symbol->scale = 1.0;
|
|
|
|
}
|
|
|
|
}
|
2009-06-03 08:23:38 +12:00
|
|
|
if(!strcmp(long_options[option_index].name, "border")) {
|
2008-10-01 04:13:35 +13:00
|
|
|
error_number = validator(NESET, optarg);
|
2008-09-27 06:01:20 +12:00
|
|
|
if(error_number == ERROR_INVALID_DATA) {
|
2008-07-14 09:15:55 +12:00
|
|
|
fprintf(stderr, "Invalid border width\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if((atoi(optarg) >= 0) && (atoi(optarg) <= 1000)) {
|
|
|
|
my_symbol->border_width = atoi(optarg);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Border width out of range\n");
|
2012-12-31 02:55:05 +13:00
|
|
|
fflush(stderr);
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
}
|
2009-06-03 08:23:38 +12:00
|
|
|
if(!strcmp(long_options[option_index].name, "height")) {
|
2008-10-01 04:13:35 +13:00
|
|
|
error_number = validator(NESET, optarg);
|
2008-09-27 06:01:20 +12:00
|
|
|
if(error_number == ERROR_INVALID_DATA) {
|
2008-07-14 09:15:55 +12:00
|
|
|
fprintf(stderr, "Invalid symbol height\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if((atoi(optarg) >= 1) && (atoi(optarg) <= 1000)) {
|
|
|
|
my_symbol->height = atoi(optarg);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Symbol height out of range\n");
|
2012-12-31 02:55:05 +13:00
|
|
|
fflush(stderr);
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-03 08:23:38 +12:00
|
|
|
if(!strcmp(long_options[option_index].name, "cols")) {
|
2008-07-14 09:15:55 +12:00
|
|
|
if((atoi(optarg) >= 1) && (atoi(optarg) <= 30)) {
|
|
|
|
my_symbol->option_2 = atoi(optarg);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Number of columns out of range\n");
|
2012-12-31 02:55:05 +13:00
|
|
|
fflush(stderr);
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
}
|
2009-06-03 08:23:38 +12:00
|
|
|
if(!strcmp(long_options[option_index].name, "vers")) {
|
2015-08-18 23:53:55 +12:00
|
|
|
if((atoi(optarg) >= 1) && (atoi(optarg) <= 47)) {
|
2008-07-14 09:15:55 +12:00
|
|
|
my_symbol->option_2 = atoi(optarg);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Invalid QR Code version\n");
|
2012-12-31 02:55:05 +13:00
|
|
|
fflush(stderr);
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
}
|
2009-06-03 08:23:38 +12:00
|
|
|
if(!strcmp(long_options[option_index].name, "secure")) {
|
2008-07-14 09:15:55 +12:00
|
|
|
if((atoi(optarg) >= 1) && (atoi(optarg) <= 8)) {
|
|
|
|
my_symbol->option_1 = atoi(optarg);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "ECC level out of range\n");
|
2012-12-31 02:55:05 +13:00
|
|
|
fflush(stderr);
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
}
|
2009-06-03 08:23:38 +12:00
|
|
|
if(!strcmp(long_options[option_index].name, "primary")) {
|
2008-07-14 09:15:55 +12:00
|
|
|
if(strlen(optarg) <= 90) {
|
|
|
|
strcpy(my_symbol->primary, optarg);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Primary data string too long");
|
2012-12-31 02:55:05 +13:00
|
|
|
fflush(stderr);
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
}
|
2009-06-03 08:23:38 +12:00
|
|
|
if(!strcmp(long_options[option_index].name, "mode")) {
|
2008-07-14 09:15:55 +12:00
|
|
|
if((optarg[0] >= '0') && (optarg[0] <= '6')) {
|
|
|
|
my_symbol->option_1 = optarg[0] - '0';
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Invalid mode\n");
|
2012-12-31 02:55:05 +13:00
|
|
|
fflush(stderr);
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
}
|
2009-06-03 08:23:38 +12:00
|
|
|
if(!strcmp(long_options[option_index].name, "rotate")) {
|
2008-09-03 08:22:39 +12:00
|
|
|
/* Only certain inputs allowed */
|
2008-10-01 04:13:35 +13:00
|
|
|
error_number = validator(NESET, optarg);
|
2008-09-27 06:01:20 +12:00
|
|
|
if(error_number == ERROR_INVALID_DATA) {
|
2008-09-03 08:22:39 +12:00
|
|
|
fprintf(stderr, "Invalid rotation parameter\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
switch(atoi(optarg)) {
|
|
|
|
case 90: rotate_angle = 90; break;
|
|
|
|
case 180: rotate_angle = 180; break;
|
|
|
|
case 270: rotate_angle = 270; break;
|
|
|
|
default: rotate_angle = 0; break;
|
|
|
|
}
|
|
|
|
}
|
2010-12-24 23:55:08 +13:00
|
|
|
if(!strcmp(long_options[option_index].name, "batch")) {
|
|
|
|
/* Switch to batch processing mode */
|
|
|
|
batch_mode = 1;
|
|
|
|
}
|
2008-07-14 09:15:55 +12:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'h':
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
|
2008-09-27 06:01:20 +12:00
|
|
|
case 't':
|
|
|
|
types();
|
|
|
|
break;
|
|
|
|
|
2008-07-14 09:15:55 +12:00
|
|
|
case 'b':
|
2008-10-01 04:13:35 +13:00
|
|
|
error_number = validator(NESET, optarg);
|
2008-09-27 06:01:20 +12:00
|
|
|
if(error_number == ERROR_INVALID_DATA) {
|
2008-10-05 18:51:58 +13:00
|
|
|
fprintf(stderr, "Invalid barcode type\n");
|
2008-07-14 09:15:55 +12:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
my_symbol->symbology = atoi(optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'w':
|
2008-10-01 04:13:35 +13:00
|
|
|
error_number = validator(NESET, optarg);
|
2008-09-27 06:01:20 +12:00
|
|
|
if(error_number == ERROR_INVALID_DATA) {
|
2008-10-05 18:51:58 +13:00
|
|
|
fprintf(stderr, "Invalid whitespace value\n");
|
2008-07-14 09:15:55 +12:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if((atoi(optarg) >= 0) && (atoi(optarg) <= 1000)) {
|
|
|
|
my_symbol->whitespace_width = atoi(optarg);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Whitespace value out of range");
|
2012-12-31 02:55:05 +13:00
|
|
|
fflush(stderr);
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd': /* we have some data! */
|
2010-12-24 23:55:08 +13:00
|
|
|
if(batch_mode == 0) {
|
|
|
|
error_number = escape_char_process(my_symbol, (unsigned char*)optarg, strlen(optarg));
|
|
|
|
if(error_number == 0) {
|
|
|
|
error_number = ZBarcode_Print(my_symbol, rotate_angle);
|
|
|
|
}
|
|
|
|
generated = 1;
|
|
|
|
if(error_number != 0) {
|
|
|
|
fprintf(stderr, "%s\n", my_symbol->errtxt);
|
2012-12-31 02:55:05 +13:00
|
|
|
fflush(stderr);
|
2010-12-24 23:55:08 +13:00
|
|
|
ZBarcode_Delete(my_symbol);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Cannot define data in batch mode");
|
2012-12-31 02:55:05 +13:00
|
|
|
fflush(stderr);
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-08-21 01:20:59 +12:00
|
|
|
case 'i': /* Take data from file */
|
2010-12-24 23:55:08 +13:00
|
|
|
if(batch_mode == 0) {
|
|
|
|
error_number = ZBarcode_Encode_File(my_symbol, optarg);
|
|
|
|
if(error_number == 0) {
|
|
|
|
error_number = ZBarcode_Print(my_symbol, rotate_angle);
|
|
|
|
}
|
|
|
|
generated = 1;
|
|
|
|
if(error_number != 0) {
|
|
|
|
fprintf(stderr, "%s\n", my_symbol->errtxt);
|
2012-12-31 02:55:05 +13:00
|
|
|
fflush(stderr);
|
2010-12-24 23:55:08 +13:00
|
|
|
ZBarcode_Delete(my_symbol);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Take each line of text as a separate data set */
|
|
|
|
error_number = batch_process(my_symbol, optarg);
|
|
|
|
generated = 1;
|
|
|
|
if(error_number != 0) {
|
|
|
|
fprintf(stderr, "%s\n", my_symbol->errtxt);
|
2012-12-31 02:55:05 +13:00
|
|
|
fflush(stderr);
|
2010-12-24 23:55:08 +13:00
|
|
|
ZBarcode_Delete(my_symbol);
|
|
|
|
return 1;
|
|
|
|
}
|
2009-08-21 01:20:59 +12:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-07-14 09:15:55 +12:00
|
|
|
case 'o':
|
|
|
|
strncpy(my_symbol->outfile, optarg, 250);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'r':
|
|
|
|
strcpy(my_symbol->fgcolour, "ffffff");
|
|
|
|
strcpy(my_symbol->bgcolour, "000000");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-10-05 18:51:58 +13:00
|
|
|
fprintf(stderr, "?? getopt error 0%o\n", c);
|
2012-12-31 02:55:05 +13:00
|
|
|
fflush(stderr);
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-31 02:55:05 +13:00
|
|
|
if (optind < argc) {
|
2008-10-05 18:51:58 +13:00
|
|
|
fprintf(stderr, "Invalid option ");
|
2008-07-14 09:15:55 +12:00
|
|
|
while (optind < argc)
|
2008-10-05 18:51:58 +13:00
|
|
|
fprintf(stderr, "%s", argv[optind++]);
|
|
|
|
fprintf(stderr, "\n");
|
2012-12-31 02:55:05 +13:00
|
|
|
fflush(stderr);
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
|
2008-10-05 18:51:58 +13:00
|
|
|
if(generated == 0) {
|
|
|
|
fprintf(stderr, "error: No data received, no symbol generated\n");
|
2012-12-31 02:55:05 +13:00
|
|
|
fflush(stderr);
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
2008-10-05 18:51:58 +13:00
|
|
|
|
2008-07-14 09:15:55 +12:00
|
|
|
ZBarcode_Delete(my_symbol);
|
|
|
|
|
2008-09-27 06:01:20 +12:00
|
|
|
return error_number;
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|