]> git.bzium.org - embe/choinka.git/blobdiff - choinka.c
Dodanie atrybutu „static” do funkcji i zmiennych.
[embe/choinka.git] / choinka.c
index b10f073e25bcfa9df85a303995af0708041d4b9c..c02dc72d5069fd15b88f3c13820c736796ea0c08 100644 (file)
--- a/choinka.c
+++ b/choinka.c
@@ -1,30 +1,40 @@
-#include <ncurses.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <term.h>
 #include <time.h>
 
+#define A_POGRUBIONY (1 << 0)
+
+#define KOLOR_CZARNY 0
+#define KOLOR_CZERWONY 1
+#define KOLOR_ZIELONY 2
+#define KOLOR_BRAZOWY 3
+#define KOLOR_NIEBIESKI 4
+#define KOLOR_MAGENTA 5
+#define KOLOR_CYJAN 6
+#define KOLOR_BIALY 7
+
 typedef struct {
   int attr;
   int kolor;
 } atrybut;
 
-atrybut const bombki[] = {
-  {A_BOLD, COLOR_RED},
-  {A_BOLD, COLOR_BLUE},
-  {A_BOLD, COLOR_YELLOW},
-  {A_BOLD, COLOR_MAGENTA},
-  {A_BOLD, COLOR_CYAN},
-  {A_BOLD, COLOR_WHITE},
+static atrybut const bombki[] = {
+  {A_POGRUBIONY, KOLOR_CZERWONY},
+  {A_POGRUBIONY, KOLOR_NIEBIESKI},
+  {A_POGRUBIONY, KOLOR_BRAZOWY},
+  {A_POGRUBIONY, KOLOR_MAGENTA},
+  {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, COLOR_GREEN};
-atrybut const podstawa = {0, COLOR_YELLOW};
-atrybut const podpis = {A_BOLD, COLOR_RED};
-atrybut const gwiazdka = {A_BOLD, COLOR_YELLOW};
+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");
@@ -41,7 +51,7 @@ void inicjuj_rng()
   srand(ziarno);
 }
 
-char const rysunek[] =
+static char const rysunek[] =
 "           *\n"
 "          /.\\\n"
 "         /..'\\\n"
@@ -52,15 +62,14 @@ 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;
   ostatni = *attr;
-  if (attr->attr & A_BOLD) {
+  putp(exit_attribute_mode);
+  if ((attr->attr & A_POGRUBIONY) != 0) {
     putp(enter_bold_mode);
-  } else {
-    putp(exit_attribute_mode);
   }
   putp(tparm(set_a_foreground, attr->kolor));
 }