File: ean13.include-3

package info (click to toggle)
ean13 0.4-8.1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 140 kB
  • ctags: 19
  • sloc: makefile: 96; ansic: 67; sh: 58
file content (234 lines) | stat: -rw-r--r-- 8,064 bytes parent folder | download | duplicates (3)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/* ------------------------------------------------------------------------- */
/* ean13.include-3                                                                 
   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 SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
   EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
   ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   SUCH DAMAGE.

                                                                           */
/* ------------------------------------------------------------------------- */
/*                                                                           */
/* define includes                                                           */
/*                                                                           */
/* ------------------------------------------------------------------------- */

void printUsage ()
{
printf(" \n");
printf("EAN13   %s  \n",version);
printf("This program will generate an EAN13 barcode in xbm file format.\n");
printf(" \n");
printf("- usage:  ean13 12-digits [> outfile] \n");
printf("          the check-bit will be automatically calculated\n");
printf(" \n");
printf(" \n");
}

void drawEAN (int x, int y1, int y2, char n, int rightHalf, int position)
{                                                                               
    unsigned int bitsA = eanBitsA[n - '0'];                                     
    unsigned int bitsB = eanBitsB[n - '0'];                                     
    unsigned int bits;                                     
    int i = 6;                                                                  
    unsigned int row_code = 0;
                                                                                
    /* country_code * position = bar set to use */  
    if (!rightHalf )
    {
      row_code = country_code -'0';
    
      row_code = (row_code *6) + position;

    if ( what_bit_table[row_code] == 'a' )
      bits = eanBitsA[n - '0'];                                     
	
    if ( what_bit_table[row_code] == 'b' )
      bits = eanBitsB[n - '0'];                                     
    }

    if (rightHalf)
    {                                                              
      bits = eanBitsA[n - '0'];                                     
      bits = ~bits;
    }
    while (i >= 0)                                                              
    {                                                                           
        if (bits & (1 << i))                                                   
            vertical_line (x, y1, y2);                                          
        x++;                                                                    
        i--;                                                                    
    }                                                                           
}




void drawchar (int x, int y, char c)
{
    char *cfound = strchr (clist, c);
    char **tab;
    int xx;
    char *t;

    if (! cfound)
        return;

    tab = ctables[cfound - clist];
    
    while (*tab != NULL)
    {
        t = *tab;
        xx = x;
        while (*t)
        {
            if (*t != ' ')
                plot (xx, y);
            t++;
            xx++;
        }
        y++;
        tab++;
    }
}



void printEAN (stringx)
{
    int x, y;
    char *staringx;

    printf ("#define upc_width %d\n"
            "#define upc_height %d\n"
            "/* ean13 barcode...by: LCS, Issaquah, WA, 98027,USA */\n"
            "/* input string = %s  */\n"
            "static char upc_bits[] = {\n",
            WIDTH, HEIGHT, stringx);

    for (y = 0; y < HEIGHT; y++)
    {
        printf ("   ");
        for (x = 0; x < WIDTH_BYTES; x++)
        {
            printf ("0x%02x, ", buf[y][x]);
        }
        printf ("\n");
    }
    printf ("};\n");
}



void processEAN (char *str)
{
    char s2[13] = "000000000000-";
    int x;
    unsigned int mul = 3;
    unsigned int sum = 0;
    unsigned int xeven = 0;
    unsigned int xodd  = 0;
/*
	Lets copy the character string into a working area, and
	calculate the check sum at the same time.

	The first character IS NOT used, just displayed 
*/

   country_code = *str;
   
   x = 0;
 
   while (x < 13 && *str)			/* calculate the check digit*/ 
    {						/* if only 11 digits	*/
        if (*str >= '0' && *str <= '9')		/* move to working location */
        {
            s2[x++] = *str;
        }
        str++;
    }

    /* compute checksum via hp.com example */
    x = 0;

	xeven += (s2[x] - '0');
        x++;
        xodd  +=  (s2[x] - '0');
	x++;
        xeven += (s2[x] - '0');                                                 
        x++;                                                                    
        xodd  +=  (s2[x] - '0');                                                
        x++;
        xeven += (s2[x] - '0');                                                 
        x++;                                                                    
        xodd  +=  (s2[x] - '0');                                                
        x++;
        xeven += (s2[x] - '0');                                                 
        x++;                                                                    
        xodd  +=  (s2[x] - '0');                                                
        x++;
        xeven += (s2[x] - '0');                                                 
        x++;                                                                    
        xodd  +=  (s2[x] - '0');                                                
        x++;
        xeven += (s2[x] - '0');                                                 
        x++;                                                                    
        xodd  +=  (s2[x] - '0'); 
    xodd = xodd * 3;                                               
    sum = xeven + xodd;


    if (s2[12] == '-')			/* if - then ignore and cal checksum */
        s2[12] = ((10 - (sum % 10)) % 10) + '0';

    s2[13] = 0;


    /* header start mark */
    vertical_line (6, 0, HEIGHT - 4);
    vertical_line (8, 0, HEIGHT - 4);

    for (x = 0; x < 6; x++)                                                     
    {   /* height of bars in company number field */                            
        drawEAN (9 + x*7, 0, HEIGHT - 11, s2[x+1], 0, x);                          
    }

    /* center mark */
    vertical_line (52, 0, HEIGHT - 4);
    vertical_line (54, 0, HEIGHT - 4);

    for (x = 0; x < 6; x++)                                                     
    {   /* height of bars in part number field */                               
        drawEAN (56 + x*7, 0, HEIGHT - 11, s2[x+7], 1, x);                         
    } 

    /* trailer start mark*/
    vertical_line (98, 0, HEIGHT - 4);
    vertical_line (100, 0, HEIGHT - 4);

    /* first readable number */
    drawchar (0, HEIGHT -14, country_code);

    for (x = 0; x < 6; x++)
    {	/* position of numbers in company field */
        drawchar (11 + x*7, HEIGHT - 7, s2[x+1]);
    }

    for (x = 0; x < 6; x++)
    {	/* position of numbers in part number field */
        drawchar (57 + x*7, HEIGHT - 7, s2[x+7]);
    }
}