2016-04-04 19:07:35 -07:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <stdio.h>
|
2016-04-08 12:34:07 -07:00
|
|
|
#include <string.h>
|
2016-04-04 19:36:00 -07:00
|
|
|
#include <stdlib.h>
|
2016-04-04 19:07:35 -07:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <ctype.h>
|
2016-04-06 17:28:18 -07:00
|
|
|
#include <stdbool.h>
|
2016-04-08 12:34:07 -07:00
|
|
|
#include <time.h>
|
2016-04-04 19:07:35 -07:00
|
|
|
|
2016-04-07 11:12:30 -07:00
|
|
|
#define SPACE 32
|
|
|
|
#define NEWLINE 10
|
2016-04-04 19:07:35 -07:00
|
|
|
|
|
|
|
int getTermSizeRows(void);
|
|
|
|
int getTermSizeCols(void);
|
|
|
|
void clearTermWindow(int, int);
|
2016-04-08 12:34:07 -07:00
|
|
|
char getMaskChar(void);
|
2016-04-04 19:07:35 -07:00
|
|
|
|
|
|
|
int main(void) {
|
2016-04-06 17:28:18 -07:00
|
|
|
struct winpos {
|
|
|
|
char source;
|
2016-04-08 12:34:07 -07:00
|
|
|
char mask;
|
2016-04-06 17:28:18 -07:00
|
|
|
int row;
|
|
|
|
int col;
|
|
|
|
struct winpos *next;
|
|
|
|
};
|
2016-04-07 11:49:47 -07:00
|
|
|
struct winpos *list_pointer = NULL;
|
|
|
|
struct winpos *start; // Always points to start of list
|
|
|
|
struct winpos *temp; // Used for free()ing the list
|
2016-04-04 19:07:35 -07:00
|
|
|
int termSizeRows = getTermSizeRows();
|
|
|
|
int termSizeCols = getTermSizeCols();
|
2016-04-10 12:51:05 -07:00
|
|
|
int c, x = 1, y = 1;
|
|
|
|
int ms, ls;
|
|
|
|
bool first = true;
|
2016-04-04 19:07:35 -07:00
|
|
|
|
2016-04-08 12:34:07 -07:00
|
|
|
// Seed my random number generator with the current time
|
|
|
|
srand(time(NULL));
|
|
|
|
|
2016-04-04 19:07:35 -07:00
|
|
|
// Geting input
|
|
|
|
while ((c = getchar()) != EOF) {
|
2016-04-07 11:27:27 -07:00
|
|
|
if (c == NEWLINE) {
|
|
|
|
++y;
|
|
|
|
x = 1;
|
|
|
|
} else if (isspace(c)) {
|
|
|
|
++x;
|
|
|
|
} else {
|
2016-04-07 11:49:47 -07:00
|
|
|
if (first) {
|
|
|
|
list_pointer = malloc(sizeof(struct winpos));
|
|
|
|
start = list_pointer;
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
list_pointer->next = malloc(sizeof(struct winpos));
|
|
|
|
list_pointer = list_pointer->next;
|
|
|
|
}
|
2016-04-06 17:28:18 -07:00
|
|
|
|
2016-04-07 11:27:27 -07:00
|
|
|
list_pointer->source = c;
|
2016-04-08 12:34:07 -07:00
|
|
|
list_pointer->mask = getMaskChar();
|
2016-04-07 11:27:27 -07:00
|
|
|
list_pointer->row = y;
|
|
|
|
list_pointer->col = x;
|
2016-04-08 12:34:07 -07:00
|
|
|
list_pointer->next = NULL;
|
2016-04-06 17:28:18 -07:00
|
|
|
|
2016-04-07 11:27:27 -07:00
|
|
|
++x;
|
2016-04-06 17:28:18 -07:00
|
|
|
}
|
2016-04-04 19:07:35 -07:00
|
|
|
}
|
2016-04-04 19:36:00 -07:00
|
|
|
|
2016-04-06 17:28:18 -07:00
|
|
|
clearTermWindow(termSizeRows, termSizeCols);
|
|
|
|
|
2016-04-10 12:51:05 -07:00
|
|
|
// TODO: pause with getchar() - something about the input stream being redirected
|
|
|
|
// to a file is causing getchar() to immediately return here.
|
|
|
|
|
|
|
|
// Jumble loop
|
|
|
|
ms = 35; // miliseconds, used for usleep()
|
|
|
|
ls = 2; // loop seconds, number of seconds to loop
|
|
|
|
x = 0;
|
|
|
|
while (x < (ls * 1000) / ms) {
|
|
|
|
list_pointer = start;
|
|
|
|
while (list_pointer != NULL) {
|
|
|
|
printf("\033[%i;%iH%c", list_pointer->row, list_pointer->col, list_pointer->mask);
|
|
|
|
list_pointer->mask = getMaskChar();
|
|
|
|
list_pointer = list_pointer->next;
|
|
|
|
}
|
|
|
|
usleep(ms * 1000);
|
|
|
|
++x;
|
2016-04-06 17:28:18 -07:00
|
|
|
}
|
2016-04-10 12:51:05 -07:00
|
|
|
|
2016-04-08 12:34:07 -07:00
|
|
|
printf("\n");
|
2016-04-04 19:36:00 -07:00
|
|
|
|
2016-04-10 12:51:05 -07:00
|
|
|
/*
|
|
|
|
// Reveal loop
|
|
|
|
x = 0;
|
|
|
|
while (x < 50) {
|
|
|
|
++x;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2016-04-07 11:49:47 -07:00
|
|
|
// Freeing the list.
|
|
|
|
list_pointer = start;
|
2016-04-08 12:34:07 -07:00
|
|
|
while (list_pointer != NULL) {
|
2016-04-06 17:28:18 -07:00
|
|
|
temp = list_pointer;
|
|
|
|
list_pointer = list_pointer->next;
|
|
|
|
free(temp);
|
|
|
|
}
|
|
|
|
|
2016-04-04 19:07:35 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getTermSizeRows(void) {
|
|
|
|
struct winsize w;
|
|
|
|
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
|
|
|
|
|
|
|
return w.ws_row;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getTermSizeCols(void) {
|
|
|
|
struct winsize w;
|
|
|
|
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
|
|
|
|
|
|
|
return w.ws_col;
|
|
|
|
}
|
|
|
|
|
|
|
|
void clearTermWindow(int pRows, int pCols) {
|
|
|
|
int row, col;
|
|
|
|
|
|
|
|
// Clearing window
|
|
|
|
for (row = 1; row <= pRows; ++row) {
|
|
|
|
for (col = 1; col <= pCols; ++col)
|
|
|
|
printf("\033[%i;%iH%c", row, col, SPACE);
|
|
|
|
printf("\033[%i;%iH%c", row, col, NEWLINE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Position cursor at the top
|
|
|
|
printf("\033[%i;%iH", 1, 1);
|
|
|
|
}
|
2016-04-08 12:34:07 -07:00
|
|
|
|
|
|
|
char getMaskChar(void) {
|
|
|
|
char *maskChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
"abcdefghijklmnopqrstuvwxyz"
|
|
|
|
"1234567890";
|
|
|
|
|
|
|
|
return maskChars[rand() % strlen(maskChars)];
|
|
|
|
}
|