summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2009-10-26 02:39:10 +0000
committerDimitri Sokolyuk <demon@dim13.org>2009-10-26 02:39:10 +0000
commit46671692abb78f943d5493168a7f69849b5b1d26 (patch)
tree239c6160dfa74886ecc80ef4ece28ccdd8bf131c
parenteffaa1fbe4600f8800500545c6092135d549227a (diff)
let compiler to its job
-rw-r--r--7seg.c90
1 files changed, 37 insertions, 53 deletions
diff --git a/7seg.c b/7seg.c
index 3eaa40e..bc7a01c 100644
--- a/7seg.c
+++ b/7seg.c
@@ -18,73 +18,57 @@
#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
+char *seg[][3] = {
+ [0] = { " _ ", "| |", "|_|" },
+ [1] = { " ", " |", " |" },
+ [2] = { " _ ", " _|", "|_ " },
+ [3] = { " _ ", " _|", " _|" },
+ [4] = { " ", "|_|", " |" },
+ [5] = { " _ ", "|_ ", " _|" },
+ [6] = { " _ ", "|_ ", "|_|" },
+ [7] = { " _ ", " |", " |" },
+ [8] = { " _ ", "|_|", "|_|" },
+ [9] = { " _ ", "|_|", " _|" }
};
-const char sym[] = "_|_||_|";
+char **
+sevenseg(char *s)
+{
+ size_t sz;
+ char **t, *p;
+ int i;
+ 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++) {
+ if (*p < '0' || *p > '9')
+ continue;
+ strlcat(t[i], seg[*p - '0'][i], sz);
+ }
+ }
+
+ return t;
+}
+
int
main(int argc, char **argv)
{
- int i, j;
- char *c;
- char *p;
- char *s[4];
- size_t len;
+ int i;
+ char **s;
- if ((c = argv[1]) == NULL)
+ if (argc < 2)
return(-1);
- len = strlen(argv[1]);
- s[3] = malloc(1);
- *s[3] = '\0';
+ s = sevenseg(argv[1]);
for (i = 0; i < 3; i++) {
- p = malloc(3 * 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]);
}
+ puts("");
return(0);
}