summaryrefslogtreecommitdiff
path: root/7seg.c
blob: 8c0eb498643b4c5474ff639296b767d988049191 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* $Id$ */
/*
 * Copyright (c) 2005 Dimitri Sokolyuk <demon@dim13.org>
 *
 * 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 <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char allowed[] = " 0123456789:;.,-ABCDEFGHIJKLMNOPQRSTUVWXYZ";

char *seg[][3] = {
	[' '] = { "   ", "   ", "   " },
	['0'] = { " _ ", "| |", "|_|" },
	['1'] = { "   ", "  |", "  |" },
	['2'] = { " _ ", " _|", "|_ " },
	['3'] = { " _ ", " _|", " _|" },
	['4'] = { "   ", "|_|", "  |" },
	['5'] = { " _ ", "|_ ", " _|" },
	['6'] = { " _ ", "|_ ", "|_|" },
	['7'] = { " _ ", "  |", "  |" },
	['8'] = { " _ ", "|_|", "|_|" },
	['9'] = { " _ ", "|_|", " _|" },
	[':'] = { "   ", " * ", " * " },
	[';'] = { "   ", " * ", " / " },
	['.'] = { "   ", "   ", " * " },
	[','] = { "   ", "   ", " / " },
	['-'] = { "   ", " _ ", "   " },
	['A'] = { " _ ", "|_|", "| |" },
	['B'] = { "   ", "|_ ", "|_|" },
	['C'] = { " _ ", "|  ", "|_ " },
	['D'] = { "   ", " _|", "|_|" },
	['E'] = { " _ ", "|_ ", "|_ " },
	['F'] = { " _ ", "|_ ", "|  " },
	['G'] = { " _ ", "|  ", "|_|" },
	['H'] = { "   ", "|_ ", "| |" },
	['I'] = { "   ", "   ", "  |" },
	['J'] = { "   ", "  |", "|_|" },
	['K'] = { " _ ", "|_ ", "| |" },
	['L'] = { "   ", "|  ", "|_ " },
	['M'] = { " _ ", "| |", "| |" },
	['N'] = { "   ", " _ ", "| |" },
	['O'] = { "   ", " _ ", "|_|" },
	['P'] = { " _ ", "|_|", "|  " },
	['Q'] = { " _ ", "|_|", "  |" },
	['R'] = { "   ", " _ ", "|  " },
	['S'] = { "   ", "|_ ", " _|" },
	['T'] = { "   ", "|_ ", "|_ " },
	['U'] = { "   ", "   ", "|_|" },
	['V'] = { "   ", "| |", "|_|" },
	['W'] = { "   ", "| |", " _ " },
	['X'] = { "   ", "|_|", "| |" },
	['Y'] = { "   ", "|_|", " _|" },
	['Z'] = { " _ ", "  |", "|_ " },
};

char **
sevenseg(char *s)
{
	size_t sz;
	char **t, *p;
	int i, c;

	sz = 3 * strlen(s) + 1;

	t = calloc(3, sizeof(char *));
	for (i = 0; i < 3; i++) {
		t[i] = calloc(sz, sizeof(char));
		for (p = s; *p; p++) {
			c = toupper(*p);
			if (strchr(allowed, c) != NULL)
				strlcat(t[i], seg[c][i], sz);
		}
	}

	return t;
}
	
int
main(int argc, char **argv)
{
	int	i;
	char	**s;

	if (argc < 2)
		return(-1);

	s = sevenseg(argv[1]);

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

	return(0);
}