File: sample.c

package info (click to toggle)
barcode 0.99-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 4,648 kB
  • sloc: ansic: 21,507; sh: 11,815; makefile: 24; sed: 16
file content (106 lines) | stat: -rw-r--r-- 3,149 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "barcode.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
    int pcl = 0, oflags;
    if (argc == 2 && !strcmp(argv[1],"-P")) {
	pcl = 1; argc=1;
    }
    if (argc>2) {
	fprintf(stderr, _("%s: use \"%s\" for postscript or \"%s -P\" for PCL\n"),
		argv[0], argv[0], argv[0]);
	exit(1);
    }
    if (pcl) {
	oflags = BARCODE_OUT_PCL;
    } else {
	oflags = BARCODE_OUT_PS | BARCODE_OUT_NOHEADERS;
	printf("%%!PS-Adobe-2.0\n");
	printf("%%%%Creator: barcode sample program\n");
	printf("%%%%EndComments\n");
	printf("%%%%EndProlog\n\n");
	printf("%%%%Page: 1 1\n\n");
    }
    /* Print a few barcodes in several places in the page */

    /* default size, bottom left */
    Barcode_Encode_and_Print("800894002700",stdout, 0, 0, 40, 40, 
                      BARCODE_EAN | oflags);

    /* smaller */
    Barcode_Encode_and_Print("800894002700",stdout, 70, 50, 160, 55, 
                      BARCODE_EAN | oflags);

    /* smallest */
    Barcode_Encode_and_Print("800894002700",stdout, 40, 30, 270, 70, 
                      BARCODE_EAN | oflags);

    /* A bigger all-0 */
    Barcode_Encode_and_Print("000000000000",stdout, 170, 0, 40, 160, 
                      BARCODE_EAN | oflags);

    /* Still bigger all-0 (but UPC, this time) */
    Barcode_Encode_and_Print("00000000000",stdout, 250, 0, 270, 160, 
                      BARCODE_UPC | oflags);

    /* A few code-39 ones */
    Barcode_Encode_and_Print("silly code",stdout, 0, 0, 40, 320, 
                      BARCODE_39 | oflags);
    Barcode_Encode_and_Print("SAMPLE CODES",stdout, 100, 30, 400, 80, 
                      BARCODE_39 | oflags);

    /* ISBN with add-5 */
    Barcode_Encode_and_Print("1-56592-292-1 90000",stdout, 0, 0, 40, 430, 
                      BARCODE_ISBN | oflags);

    /* UPC with add-2 */
    Barcode_Encode_and_Print("07447084452 07",stdout, 0, 0, 300, 410, 
                      BARCODE_UPC | oflags);

    /* code 128-C */
    Barcode_Encode_and_Print("12345678900123456789",stdout, 0, 0, 40, 530, 
                      BARCODE_128C | oflags);

    /* and my data as code-128B autodetected */
    Barcode_Encode_and_Print("RBNLSN68T11E897W",stdout, 0, 60, 240, 510, 
                oflags);
    /* same as code-39, forced */
    Barcode_Encode_and_Print("RBNLSN68T11E897W",stdout, 0, 60, 240, 590, 
                BARCODE_NO_CHECKSUM | BARCODE_39 | oflags);

    /* one interleaved 2 of 5 */
    Barcode_Encode_and_Print("0123456789",stdout, 0, 0, 40, 620, 
                BARCODE_I25 | oflags);

    /* upc-e and ean-8 (autotected based on code size) */
    Barcode_Encode_and_Print("012345",stdout, 0, 0, 50, 720, oflags);
    Barcode_Encode_and_Print("0123456",stdout, 0, 0, 160, 720, oflags);

	/* code-93 */
	Barcode_Encode_and_Print("sample codes",stdout, 100, 30, 280, 720,
                      BARCODE_93 | oflags);

	/* code-11 */
	Barcode_Encode_and_Print("01234-56789",stdout, 100, 30, 400, 720,
                      BARCODE_11 | oflags);

    
    if (pcl) {
	printf("\f");
    } else {
	printf("\nshowpage\n");
	printf("%%%%Trailer\n\n");
    }
    return 0;
}