summaryrefslogtreecommitdiff
path: root/7seg.c
blob: 941fae85313b8a6b0520cce14520cb31671da81b (plain)
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
/* $Id$ */
/*
 * Copyright (c) 2005 Dimitri Sokolyuk <sokolyuk@gmail.com>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

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

/*
 *  _	 a
 * |_|	bcd
 * |_|	efg
 * 
 * 	~abcdefg		~gfedcba
 * 0	01101111	0x6F	01111011	0x7B
 * 1	00001001	0x09	01001000	0x48
 * 2	01011110	0x5E	00111101	0x3D
 * 3	01011011	0x5B	01101101	0x6D
 * 4	00111001	0x39	01001110	0x4E
 * 5	01110011	0x73	01100111	0x67
 * 6	01110111	0x77	01110111	0x77
 * 7	01001001	0x49	01001001	0x49
 * 8	01111111	0x7F	01111111	0x7F
 * 9	01111011	0x7B	01101111	0x6F
 * 
 */

const char seg[] = {
	0x7B, 0x48, 0x3D, 0x6D, 0x4E,
	0x67, 0x77, 0x49, 0x7F, 0x6F
};

const char sym[] = "_|_||_|";

int
main(int argc, char **argv)
{
	int	i, j;
	char	*c;
	char	*p;
	char	*s[4];
	size_t	len;

	if ((c = argv[1]) == NULL)
		return(-1);

	len = strlen(argv[1]);
	s[3] = malloc(1);
	*s[3] = '\0';

	for (i = 0; i < 3; i++) {
		p = malloc(len + 1);
		s[i] = p;
		do {
			if (*c < '0' || *c > '9')
				continue;
			if (i == 0)
				*p++ = ' ';
			for (j = 0; j < 3; j++) {
				*p++ = seg[*c - '0'] & 1 << i * i + j ?
					sym[i * i + j] : ' ';
				if (i == 0) {
					*p++ = ' ';
					break;
				}
			}
		} while (*++c);
		*p = '\0';
		c = argv[1];
	}

	for (i = 0; i < 4; i++) {
		puts(s[i]);
		free(s[i]);
	}

	return(0);
}