diff --git a/src/nms.c b/src/nms.c index b3c0aef..d161b80 100644 --- a/src/nms.c +++ b/src/nms.c @@ -7,15 +7,15 @@ #include "nms.h" #include -#include #include #include #include #include #include #include +#include +#include -#define TAB_SIZE 4 #define TYPE_EFFECT_SPEED 4 // miliseconds per char #define JUMBLE_SECONDS 2 // number of seconds for jumble effect #define JUMBLE_LOOP_SPEED 35 // miliseconds between each jumble @@ -24,12 +24,13 @@ #define SPACE 32 #define NEWLINE 10 #define TAB 9 +#define TAB_SIZE 4 // Window position structure, linked list. Keeps track of every // character's position on the terminal, as well as other attributes. struct winpos { char source; - char mask; + char *mask; int row; int col; int s1_time; @@ -38,7 +39,7 @@ struct winpos { }; // Function prototypes (internal) -char getMaskChar(void); +char *getMaskChar(void); int getColorByName(char *); /* @@ -76,6 +77,9 @@ char nms_exec(NmsArgs *args) { return 0; } + // Seems to be needed for utf-8 support + setlocale(LC_ALL, ""); + // Start and initialize curses mode initscr(); cbreak(); @@ -144,7 +148,7 @@ char nms_exec(NmsArgs *args) { // Initially display the characters in the terminal with a 'type effect'. list_pointer = start; while (list_pointer != NULL && list_pointer->row <= termSizeRows) { - mvaddch(list_pointer->row, list_pointer->col, list_pointer->mask); + mvaddstr(list_pointer->row, list_pointer->col, list_pointer->mask); refresh(); list_pointer->mask = getMaskChar(); list_pointer = list_pointer->next; @@ -166,7 +170,7 @@ char nms_exec(NmsArgs *args) { while (x < (JUMBLE_SECONDS * 1000) / JUMBLE_LOOP_SPEED) { list_pointer = start; while (list_pointer != NULL && list_pointer->row <= termSizeRows) { - mvaddch(list_pointer->row, list_pointer->col, list_pointer->mask); + mvaddstr(list_pointer->row, list_pointer->col, list_pointer->mask); refresh(); list_pointer->mask = getMaskChar(); list_pointer = list_pointer->next; @@ -194,13 +198,16 @@ char nms_exec(NmsArgs *args) { list_pointer->s2_time -= REVEAL_LOOP_SPEED; list_pointer->mask = getMaskChar(); } else { - list_pointer->mask = list_pointer->source; + list_pointer->mask = NULL; + list_pointer->mask = malloc(sizeof(list_pointer->source) + 1); + sprintf(list_pointer->mask, "%c", list_pointer->source); attron(A_BOLD); if (has_colors()) attron(COLOR_PAIR(1)); } - mvaddch(list_pointer->row, list_pointer->col, list_pointer->mask); + mvaddstr(list_pointer->row, list_pointer->col, list_pointer->mask); refresh(); + list_pointer = list_pointer->next; attroff(A_BOLD); @@ -264,6 +271,7 @@ char nms_exec(NmsArgs *args) { while (list_pointer != NULL) { temp = list_pointer; list_pointer = list_pointer->next; + free(temp->mask); free(temp); } @@ -271,19 +279,51 @@ char nms_exec(NmsArgs *args) { } /* - * char getMaskChar(void) + * char *getMaskChar(void) * * DESCR: * Returns a random character from the maskChars string. * */ -char getMaskChar(void) { - char *maskChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "1234567890" - "!@#$%^&*()-_=+{}[]:;|\\\"'<>,.?/"; +char *getMaskChar(void) { + char *maskChars[] = { + "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", "~", + ".", "/", ":", ";", "<", "=", ">", "?", "[", "\\", "]", "_", "{", "}", + "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", + "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", + "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", + "\xc3\x87", "\xc3\xbc", "\xc3\xa9", "\xc3\xa2", "\xc3\xa4", "\xc3\xa0", + "\xc3\xa5", "\xc3\xa7", "\xc3\xaa", "\xc3\xab", "\xc3\xa8", "\xc3\xaf", + "\xc3\xae", "\xc3\xac", "\xc3\x84", "\xc3\x85", "\xc3\x89", "\xc3\xa6", + "\xc3\x86", "\xc3\xb4", "\xc3\xb6", "\xc3\xb2", "\xc3\xbb", "\xc3\xb9", + "\xc3\xbf", "\xc3\x96", "\xc3\x9c", "\xc2\xa2", "\xc2\xa3", "\xc2\xa5", + "\xc6\x92", "\xc3\xa1", "\xc3\xad", "\xc3\xb3", "\xc3\xba", "\xc3\xb1", + "\xc3\x91", "\xc2\xaa", "\xc2\xba", "\xc2\xbf", "\xc2\xac", "\xc2\xbd", + "\xc2\xbc", "\xc2\xa1", "\xc2\xab", "\xc2\xbb", "\xce\xb1", "\xc3\x9f", + "\xce\x93", "\xcf\x80", "\xce\xa3", "\xcf\x83", "\xc2\xb5", "\xcf\x84", + "\xce\xa6", "\xce\x98", "\xce\xa9", "\xce\xb4", "\xcf\x86", "\xce\xb5", + "\xc2\xb1", "\xc3\xb7", "\xc2\xb0", "\xc2\xb7", "\xc2\xb2", "\xc2\xb6", + "\xe2\x8c\x90", "\xe2\x82\xa7", "\xe2\x96\x91", "\xe2\x96\x92", + "\xe2\x96\x93", "\xe2\x94\x82", "\xe2\x94\xa4", "\xe2\x95\xa1", + "\xe2\x95\xa2", "\xe2\x95\x96", "\xe2\x95\x95", "\xe2\x95\xa3", + "\xe2\x95\x91", "\xe2\x95\x97", "\xe2\x95\x9d", "\xe2\x95\x9c", + "\xe2\x95\x9b", "\xe2\x94\x90", "\xe2\x94\x94", "\xe2\x94\xb4", + "\xe2\x94\xac", "\xe2\x94\x9c", "\xe2\x94\x80", "\xe2\x94\xbc", + "\xe2\x95\x9e", "\xe2\x95\x9f", "\xe2\x95\x9a", "\xe2\x95\x94", + "\xe2\x95\xa9", "\xe2\x95\xa6", "\xe2\x95\xa0", "\xe2\x95\x90", + "\xe2\x95\xac", "\xe2\x95\xa7", "\xe2\x95\xa8", "\xe2\x95\xa4", + "\xe2\x95\xa7", "\xe2\x95\x99", "\xe2\x95\x98", "\xe2\x95\x92", + "\xe2\x95\x93", "\xe2\x95\xab", "\xe2\x95\xaa", "\xe2\x94\x98", + "\xe2\x94\x8c", "\xe2\x96\x88", "\xe2\x96\x84", "\xe2\x96\x8c", + "\xe2\x96\x90", "\xe2\x96\x80", "\xe2\x88\x9e", "\xe2\x88\xa9", + "\xe2\x89\xa1", "\xe2\x89\xa5", "\xe2\x89\xa4", "\xe2\x8c\xa0", + "\xe2\x8c\xa1", "\xe2\x89\x88", "\xe2\x88\x99", "\xe2\x88\x9a", + "\xe2\x81\xbf", "\xe2\x96\xa0" + }; - return maskChars[rand() % strlen(maskChars)]; + return maskChars[rand() % 218]; } /*