X-Git-Url: https://git.bzium.org/embe/choinka.git/blobdiff_plain/7107640dca11d91726c59920b368e66aa4f2f72e..ce2e37059c21803606557e44fe872174fed3772c:/choinka.c diff --git a/choinka.c b/choinka.c index 26f6c43..b117972 100644 --- a/choinka.c +++ b/choinka.c @@ -5,6 +5,7 @@ #define A_POGRUBIONY (1 << 0) +#define KOLOR_BRAK -1 #define KOLOR_CZARNY 0 #define KOLOR_CZERWONY 1 #define KOLOR_ZIELONY 2 @@ -19,7 +20,7 @@ typedef struct { int kolor; } atrybut; -atrybut const bombki[] = { +static atrybut const bombki[] = { {A_POGRUBIONY, KOLOR_CZERWONY}, {A_POGRUBIONY, KOLOR_NIEBIESKI}, {A_POGRUBIONY, KOLOR_BRAZOWY}, @@ -27,14 +28,15 @@ atrybut const bombki[] = { {A_POGRUBIONY, KOLOR_CYJAN}, {A_POGRUBIONY, KOLOR_BIALY}, }; -int const ile_b = sizeof bombki / sizeof *bombki; +static int const ile_b = sizeof bombki / sizeof *bombki; -atrybut const choinka = {0, KOLOR_ZIELONY}; -atrybut const podstawa = {0, KOLOR_BRAZOWY}; -atrybut const podpis = {A_POGRUBIONY, KOLOR_CZERWONY}; -atrybut const gwiazdka = {A_POGRUBIONY, KOLOR_BRAZOWY}; +static atrybut const spacja = {0, KOLOR_BRAK}; +static atrybut const choinka = {0, KOLOR_ZIELONY}; +static atrybut const podstawa = {0, KOLOR_BRAZOWY}; +static atrybut const podpis = {A_POGRUBIONY, KOLOR_CZERWONY}; +static atrybut const gwiazdka = {A_POGRUBIONY, KOLOR_BRAZOWY}; -void inicjuj_rng() +static void inicjuj_rng() { unsigned ziarno = 0; FILE* f = fopen("/dev/urandom", "rb"); @@ -51,7 +53,7 @@ void inicjuj_rng() srand(ziarno); } -char const rysunek[] = +static char const rysunek[] = " *\n" " /.\\\n" " /..'\\\n" @@ -62,7 +64,7 @@ char const rysunek[] = " jgs ^^^[_]^^^\n" ; -void ustaw(atrybut const* attr) +static void ustaw(atrybut const* attr) { static atrybut ostatni = {-1, -1}; if (ostatni.attr == attr->attr && ostatni.kolor == attr->kolor) return; @@ -71,7 +73,9 @@ void ustaw(atrybut const* attr) if ((attr->attr & A_POGRUBIONY) != 0) { putp(enter_bold_mode); } - putp(tparm(set_a_foreground, attr->kolor)); + if (attr->kolor != KOLOR_BRAK) { + putp(tparm(set_a_foreground, attr->kolor)); + } } int main() @@ -86,6 +90,7 @@ int main() if (c >= 'a' && c <= 'z') akt = &podpis; if (c == '.') akt = &bombki[rand() % ile_b]; if (c == '*') akt = &gwiazdka; + if (c == ' ' || c == '\n') akt = &spacja; if (c == ']') kolor = &choinka; ustaw(akt); putchar(c);