#include #include /** * * ZFOOBAR - Generates ZEBRA printer output; recognizes in stream indicators * adapted by Jorge Rimblas 26-MAY-2004 * * Based on foobar * Copyright (C) 1999 Frederik MJ Sauer * * 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 2 * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * You can contact the author via email: * fred@allen-sauer.com * * UNIX command line example to print a 3-of-9 barcode for "123AC": * echo "A pretty [ZFOOBAR;DATA=123AC] example" | zfoobar | lp -d myprinter * * For a New Label, use [ZFOOBAR;CMD=NEWLABEL] * echo "A pretty [ZFOOBAR;DATA=123AC] example [ZFOOBAR;CMD=NEWLABEL] Label 2" | zfoobar | lp -d myprinter * * $Log: /var/opt/pvcs/vm/common/glpdb/archives/star/src/zfoobar.c-arc $ * * Rev 1.2 20 Mar 2005 20:34:16 rimblasj * Added support for skipping labels. Use command: * [ZFOOBAR;CMD=NEWLABEL] * * Rev 1.0 May 26 2004 15:54:04 rimblasj * Initial revision. * */ #define START_TAG "[ZFOOBAR" #define END_TAG_CHAR ']' #define MAX_DATA_LENGTH 100 #define MAX_TAG_LENGTH 1000 #define NARROW_BAR_DOTS "2" #define WIDE_BAR_DOTS "7" #define INTERCHAR_SPACING_DOTS "5" #define HEIGHT_DOTS 60 #define DOC_BEGIN "^XA" #define DOC_END "^XZ" #define DEFAULT_FONT "^CFD,25,15" #define BAR_CTRL_BEGIN "^BY2^B3N,N," #define BAR_CTRL_END ",N,N" #define DATA_BEGIN "^FD" #define DATA_END "^FS" #define LINE_BEGIN1 "^FO" #define LINE_FONT "^AD,28,10" #define NEWLINE_CHAR 13 char data[MAX_DATA_LENGTH]; int xpos=0, ypos=20, width, height=HEIGHT_DOTS, y_index=13; int newline = 1; void increase_ypos() { ypos += y_index; } void out_bar_data() { // fprintf(stdout,"out_bar_data DATA(%s)", data); /* Barcode Line Format "^FO10,100^BY2^B3N,N,120,N,N^FD%s^FS\n" */ /* Barcode Delimiter Start and Position */ fprintf(stdout,"%s%d%s", BAR_CTRL_BEGIN, height, BAR_CTRL_END); fprintf(stdout,"%s%s%s", DATA_BEGIN, data, DATA_END ); ypos += height; } void begin_line() { /* Line Delimiter Start and Position */ fprintf(stdout,"%s%02d,%d%s%s",LINE_BEGIN1, xpos, ypos, LINE_FONT, DATA_BEGIN); } void end_line() { /* Line Delimiter for EOL */ fprintf(stdout,"%s", DATA_END); } void skip_line() { fprintf(stdout,"\n"); } void begin_doc() { fprintf(stdout,"%s\n",DOC_BEGIN); // Set the font for the whole label fprintf(stdout,"%s\n",DEFAULT_FONT); } void end_doc() { fprintf(stdout,"%s\n", DOC_END); } int main(argc, argv) int argc; char *argv[]; { int recog_pos=0; int recog_len=strlen(START_TAG); size_t count; char t[MAX_TAG_LENGTH], name[MAX_DATA_LENGTH], value[MAX_DATA_LENGTH], t2[MAX_DATA_LENGTH]; begin_doc(); // Initialize the Zebra printer newline = 1; while (!feof(stdin) && fread(t, sizeof(char), 1, stdin)>0) { if (newline) { begin_line(); newline = 0; } if (t[0]==10) { end_line(); newline = 1; increase_ypos(); } if (t[0]==START_TAG[recog_pos]) { if (fread(t+1, sizeof(char), recog_len-1, stdin)==recog_len-1) { if (!strncmp(t, START_TAG, recog_len)) { /* we found START_TAG */ int tpos=recog_len; while (!feof(stdin) && t[tpos-1]!=END_TAG_CHAR) { fread(t+tpos++, sizeof(char), 1, stdin); } t[tpos]=0; /* fprintf(stdout," t(%s)\n",t); */ sscanf(t,START_TAG "%s",t2); strcpy(t,t2); while (t[0]!=END_TAG_CHAR && sscanf(t,";%[A-Z]=%[ A-Z0-9.*$/+%-]%s", name, value, t2)==3) { /* fprintf(stdout," Count(%d) Name(%s) Value(%s) t2(%s)\n",count,name,value,t2); */ /* fprintf(stdout," Name(%s) Value(%s) t2(%s)\n",name,value,t2); */ strcpy(t,t2); if (!strcmp(name,"DATA")) strcpy(data,value); else if (!strcmp(name,"CMD")) { end_line(); skip_line(); end_doc(); begin_doc(); data[0]=0; newline = 1; ypos=20; } else if (!strcmp(name,"HEIGHT")) sscanf(value,"%i",&height); /* else if (!strcmp(name,"XPOS")) sscanf(value,"%i",&xpos); else if (!strcmp(name,"YPOS")) sscanf(value,"%i",&ypos); else if (!strcmp(name,"WIDTH")) sscanf(value,"%i",&width); */ } /* do not print Barcode if we found CMD=NEWLABEL */ if (strcmp(value,"NEWLABEL")) out_bar_data(); } else { /* we did not find START_TAG */ /* Still need to take care of "[FOO[FOOBAR...]" and stuff like that here */ fwrite(t,sizeof(char),recog_len,stdout); } } } else { fwrite(t,sizeof(char),1,stdout); } } end_doc(); // End the Zebra printer document }