1
/* $Xorg: atobm.c,v 1.4 2001/02/09 02:05:28 xorgcvs Exp $ */
4
Copyright 1988, 1993, 1998 The Open Group
6
Permission to use, copy, modify, distribute, and sell this software and its
7
documentation for any purpose is hereby granted without fee, provided that
8
the above copyright notice appear in all copies and that both that
9
copyright notice and this permission notice appear in supporting
12
The above copyright notice and this permission notice shall be included
13
in all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
19
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21
OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of The Open Group shall
24
not be used in advertising or otherwise to promote the sale, use or
25
other dealings in this Software without prior written authorization
29
/* $XFree86: xc/programs/bitmap/atobm.c,v 3.4 2001/07/25 15:05:12 dawes Exp $ */
32
* atobm - ascii to bitmap filter
33
* Author: Jim Fulton, MIT X Consortium
43
static void doit(FILE *fp, char *filename, char *chars,
44
int xhot, int yhot, char *name);
49
fprintf (stderr, "usage: %s [-options ...] [filename]\n\n",
52
"where options include:\n");
54
" -chars cc chars to use for 0 and 1 bits, respectively\n");
56
" -name variable name to use in bitmap file\n");
58
" -xhot number x position of hotspot\n");
60
" -yhot number y position of hotspot\n");
61
fprintf (stderr, "\n");
67
cify_name (char *name)
69
int length = name ? strlen (name) : 0;
72
for (i = 0; i < length; i++) { /* strncpy (result, begin, length); */
74
if (!((isascii(c) && isalnum(c)) || c == '_')) name[i] = '_';
82
char *begin = strrchr(name, '/');
86
begin = (begin ? begin+1 : name);
87
end = strchr(begin, '.'); /* change to strrchr to allow longer names */
88
length = (end ? (end - begin) : strlen (begin));
89
result = (char *) malloc (length + 1);
90
strncpy (result, begin, length);
91
result [length] = '\0';
96
main (int argc, char *argv[])
99
int xhot = -1, yhot = -1;
100
char *filename = NULL;
105
ProgramName = argv[0];
107
for (i = 1; i < argc; i++) {
116
if (++i >= argc) usage ();
120
if (++i >= argc) usage ();
124
if (++i >= argc) usage ();
125
xhot = atoi (argv[i]);
128
if (++i >= argc) usage ();
129
yhot = atoi (argv[i]);
139
if (strlen (chars) != 2) {
141
"%s: bad character list \"%s\", must have exactly 2 characters\n",
147
fp = fopen (filename, "r");
149
fprintf (stderr, "%s: unable to open file \"%s\".\n",
150
ProgramName, filename);
157
if (!name) name = filename ? StripName (filename) : "";
159
doit (fp, filename, chars, xhot, yhot, name);
161
if (filename) (void) fclose (fp);
177
int width = 0, height = 0;
179
int removespace = (((isascii(chars[0]) && isspace(chars[0])) ||
180
(isascii(chars[1]) && isspace(chars[1]))) ? 0 : 1);
182
int bytes_per_scanline = 0;
186
unsigned char *scanlines;
187
struct _scan_list *next;
188
} *head = NULL, *slist = NULL;
189
static unsigned char masktable[] = {
190
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
195
slist = (struct _scan_list *) calloc (1, sizeof *slist); \
197
fprintf (stderr, "%s: unable to allocate scan list\n", \
201
slist->allocated = NTOALLOC * bytes_per_scanline; \
202
slist->scanlines = (unsigned char *) calloc(slist->allocated, 1); \
203
if (!slist->scanlines) { \
204
fprintf (stderr, "%s: unable to allocate char array\n", \
214
if (fgets (buf, sizeof buf, fp) == NULL) break;
218
for (cp = buf; *cp && isascii(*cp) && isspace(*cp); cp++) ;
220
if (*cp == '\n' || !*cp) continue; /* empty line */
222
newline = strchr(cp, '\n');
224
fprintf (stderr, "%s: line %d too long.\n",
225
ProgramName, lineno);
230
for (; --newline > cp && isascii(*newline) && isspace(*newline); );
234
if (newline == cp + 1) continue;
241
padded = ((width & 7) != 0);
242
bytes_per_scanline = (len + 7) / 8;
245
} else if (width != len) {
247
"%s: line %d is %d characters wide instead of %d\n",
248
ProgramName, lineno, len, width);
252
if (slist->used + 1 >= slist->allocated) {
253
struct _scan_list *old = slist;
258
/* okay, parse the line and stick values into the scanline array */
259
for (i = 0; i < width; i++) {
263
if (cp[i] == chars[1]) {
265
} else if (cp[i] != chars[0]) {
266
fprintf (stderr, "%s: bad character '%c' on line %d\n",
267
ProgramName, cp[i], lineno);
270
if (on) slist->scanlines[slist->used] |= masktable[ind];
271
if (ind == 7) slist->used++;
273
if (padded) slist->used++;
277
printf ("#define %s_width %d\n", name, width);
278
printf ("#define %s_height %d\n", name, height);
279
if (xhot >= 0) printf ("#define %s_x_hot %d\n", name, xhot);
280
if (yhot >= 0) printf ("#define %s_y_hot %d\n", name, yhot);
282
printf ("static unsigned char %s_bits[] = {\n", name);
285
last_character = height * bytes_per_scanline - 1;
286
for (slist = head; slist; slist = slist->next) {
287
for (i = 0; i < slist->used; i++) {
288
printf (" 0x%02x", slist->scanlines[i]);
289
if (j != last_character) putchar (',');
290
if ((j % 12) == 11) putchar ('\n');