Category : Printer + Display Graphics
Archive   : BARPCX.ZIP
Filename : BARPCX.C

 
Output of file : BARPCX.C contained in archive : BARPCX.ZIP
#pragma pack(1)
#include
#include
#include /* for FP_SEG */


/*** PCX file structure definitons ***/
#define PCXSIGNATURE 0x0A /* PCX file ID Byte */
#define BYTE unsigned char
#define WORD unsigned int

typedef struct /* format of PCX File */
{
BYTE signature; /* This holds the above signature */
BYTE version;
BYTE encoding;
BYTE bitsPerPixel; /* only one bit per pixel allowed in canvases*/
WORD xMin, yMin;
WORD xMax, yMax;
WORD dispWidth, dispHeight;
BYTE palette [16] [3]; /* palette not used for PAD canvases */
BYTE reserved;
BYTE colorPlanes;
WORD bytesPerLine;
BYTE unused[60]; /* pad to 128 bytes */
BYTE bits[1]; /* beginning of data area */
} PCXHDR;

BYTE *barcode;
WORD totbits;


void SaveCode(char far *fileName,int len, int height)
{
PCXHDR pcx;
register BYTE byte,count; /* work variables */
int i,x,y;
FILE *f;



/* create a PCX header with canvas values */
pcx.signature = PCXSIGNATURE;
pcx.version = 5;
pcx.encoding = 1;
pcx.bitsPerPixel = 1;
pcx.xMin = 0;
pcx.yMin = 0;
pcx.xMax = totbits-1;
pcx.yMax = height-1;
pcx.dispWidth = 75;
pcx.dispHeight = 75;
pcx.reserved = 0;
pcx.colorPlanes = 1;
pcx.bytesPerLine = len;

for (i = 0; i < 16 ; i++) /* fill in unused palette values */
{ pcx.palette [i][0] = 0x01;
pcx.palette [i][1] = 0x1F;
pcx.palette [i][2] = i & 1 ? 0xFF : 0;
}
for (i = 0; i < 60; i++)
pcx.unused [i] = 0;

f = fopen(fileName,"wb");
if (f!=NULL)
{
fwrite(&pcx,sizeof(PCXHDR)-1,1,f);
for (y=0;y<=height;y++)
{
for (x=0;x {
putc(0xC1,f); /* Set the count to 1 with high bits set */
putc(barcode[x],f);
}

}
fclose(f);
}
}

long codeof(char asc)
{
long Lbar;

switch (asc)
{
case '1': Lbar = 0x72127;
break;
case '2': Lbar = 0x4E127;
break;
case '3': Lbar = 0x73849;
break;
case '4': Lbar = 0x48727;
break;
case '5': Lbar = 0x721C9;
break;
case '6': Lbar = 0x4E1C9;
break;
case '7': Lbar = 0x484E7;
break;
case '8': Lbar = 0x72139;
break;
case '9': Lbar = 0x4E139;
break;
case '0': Lbar = 0x48739;
break;
case 'A': Lbar = 0x72427;
break;
case 'B': Lbar = 0x4E427;
break;
case 'C': Lbar = 0x73909;
break;
case 'D': Lbar = 0x49C27;
break;
case 'E': Lbar = 0x72709;
break;
case 'F': Lbar = 0x4E709;
break;
case 'G': Lbar = 0x490E7;
break;
case 'H': Lbar = 0x72439;
break;
case 'I': Lbar = 0x4E439;
break;
case 'J': Lbar = 0x49C39;
break;
case 'K': Lbar = 0x72487;
break;
case 'L': Lbar = 0x4E487;
break;
case 'M': Lbar = 0x73921;
break;
case 'N': Lbar = 0x49C87;
break;
case 'O': Lbar = 0x72721;
break;
case 'P': Lbar = 0x4E721;
break;
case 'Q': Lbar = 0x49387;
break;
case 'R': Lbar = 0x724E1;
break;
case 'S': Lbar = 0x4E4E1;
break;
case 'T': Lbar = 0x49CE1;
break;
case 'U': Lbar = 0x70927;
break;
case 'V': Lbar = 0x43927;
break;
case 'W': Lbar = 0x70E49;
break;
case 'X': Lbar = 0x42727;
break;
case 'Y': Lbar = 0x709C9;
break;
case 'Z': Lbar = 0x439C9;
break;
case '-': Lbar = 0x424E7;
break;
case '.': Lbar = 0x70939;
break;
case ' ': Lbar = 0x43939;
break;
case '*': Lbar = 0x42739;
break;
case '$': Lbar = 0x42109;
break;
case '/': Lbar = 0x42121;
break;
case '+': Lbar = 0x42421;
break;
case '%': Lbar = 0x48421;
break;
}
return(Lbar);
}

encode(char *text,int width,int *bpl)
{
long coded;
int index,bitcount,lcount,bcindex,widthcountdown;
long bar;


barcode=malloc(1);
barcode[0]=0;
bcindex=0;
bitcount=0;
lcount=0;
totbits=0;
for (index=0;index {
coded=codeof(text[index]);
for (lcount=0;lcount<21;lcount++)
{
coded=coded<<1;
widthcountdown=width;
do
{
bar=(coded & 0x80000);
if (bar!=0x80000) /* change this to (bar==0x80000) to invert output */
barcode[bcindex]=barcode[bcindex]|1;
totbits++;
bitcount++;
if (bitcount==8)
{
bcindex++;
barcode=realloc(barcode,bcindex+1);
barcode[bcindex]=0;
bitcount=0;
}
barcode[bcindex]=barcode[bcindex]<<1;
widthcountdown--;
} while (widthcountdown>0);

}
}
while (bitcount<7)
{
barcode[bcindex]=barcode[bcindex]<<1;
bitcount++;
}
*bpl=bcindex+1;
}


main(int argc, char *argv[])
{
BYTE x,y,c;
int width,len,bpl;
char *text;


text=malloc(strlen(argv[1])+5);
text[0]='*';
text[1]='\0';
strcat(text,argv[1]);
strcat(text,"*");
strupr(text);

encode(text,atoi(argv[3]),&bpl);

SaveCode(argv[2],bpl,atoi(argv[4]));

free(barcode);
free(text);

exit(0);
}

/* end of file */



  3 Responses to “Category : Printer + Display Graphics
Archive   : BARPCX.ZIP
Filename : BARPCX.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/