Created
June 3, 2016 21:36
-
-
Save duskborn/bc115b7606814db561990c4f9fb86d6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ncurses> | |
#include <stdio.h> | |
#include <stdlib.h> | |
int color[20]; | |
int position[20]; | |
bool flag; | |
int cursor; | |
WINDOW *wnd; | |
WINDOW *submask; | |
WINDOW *subfile; | |
WINDOW *submessage; | |
void check(char s1[], char s2[]); | |
void movescan(int count, char s1[], char s2[]); | |
int main(int args, char **argv){ | |
initscr(); | |
cbreak(); | |
char file[20]; | |
char mask[20]; | |
printw("Enter the mask\n"); | |
scanw("%s", mask); | |
printw("Enter the file name\n"); | |
scanw("%s", file); | |
ckear(); | |
cursor = 3; | |
start_color(); | |
refresh(); | |
noecho(); | |
init_pair(1, COLOR_WHITE, COLOR_GREEN); | |
init_pair(2, COLOR_WHITE, COLOR_RED); | |
init_pair(3, COLOR_WHITE, COLOR_BLACK); | |
init_pair(4, COLOR_WHITE, COLOR_BLUE); | |
wbkgd(stdscr, COLOR_PAIR(4)); | |
refresh(); | |
wnd = newwin(20, 40, 2, 4); | |
box(wnd, '|', '-'); | |
submask = derwin(wnd, 8, 19, 1, 1); | |
subfile = derwin(wnd, 8, 19, 10, 1); | |
submessage = derwin(wnd, 18, 19, 1, 20); | |
wbkgd(submask, COLOR_PAIR(3) | A_BOLD); | |
wbkgd(subfile, COLOR_PAIR(3) | A_BOLD); | |
wbkgd(submessage, COLOR_PAIR(1) | A_BOLD); | |
wprintw(submask, mask); | |
wprintw(subfile, file); | |
check(mask, file); | |
if (flag == false){ | |
wbkgd(submessage, COLOR_PAIR(2) | A_BLOD); | |
wprintw(submessage, "File does not satisfy the mask"); | |
} | |
wprintw(submessage, "File satisfies the mask"); | |
wrefresh(submask); | |
wrefresh(subfile); | |
wrefresh(submessage); | |
wrefresh(wnd); | |
int ch; | |
keypad(stdscr, true); | |
printw("Press F1 for exit.."); | |
move(3, 5); | |
while ((ch = getch()) != KEY_F(1)){ | |
switch (ch){ | |
case KEY_LEFT: | |
movescan(-1, mask, file); | |
break; | |
case KEY_RIGHT: | |
movescan(1, mask, file); | |
break; | |
} | |
} | |
delwin(submask); | |
delwin(subfile); | |
delwin(submessage); | |
delwin(wnd); | |
endwin(); | |
return 0; | |
} | |
void check(char s1[], char s2[]){ | |
flag = true; | |
bool star = false; | |
int j = 0; | |
bool pfl = false; | |
for (int i = 0; i<sizeof(s1); i++){ | |
if (s1[i] == '?'){ position[j] = i; color[j] = 1; pfl = true; j++; } | |
else{ | |
if (s1[i] == '*'){ star = true; } | |
else{ | |
if (start){ | |
bool fl = false; | |
while (j<sizeof(s2) && !fl){ | |
if (s2[j] == s1[i]){ fl = true; star = false; position[j] = i; } | |
else{ position[j] = i - 1; } | |
j++; | |
} | |
if (fl){ star = false; color[j] = 1; } | |
else{ flag = false; color[j] = 2; } | |
} | |
else{ | |
if (s2[j] != s1[i]){ | |
flag = false; color[j] = 2; | |
if (pfl){ | |
bool fl = false; | |
while (j<sizeof(s2) && !fl){ | |
if (s2[j] == s1[i]){ fl = true; } | |
else{ | |
position[j] = i - 1; | |
j++; | |
} | |
if (fl){ j--; color[j] = 1; } | |
else{ color[j] = 2; } | |
pfl = false; | |
} | |
} | |
else{ color[j] = 1; } | |
position[j] = 1; | |
j++; | |
} | |
} | |
} | |
} | |
int count = 0; | |
for (int i = 0; i<sizeof(s2); i++){ | |
if (color[i] != 1 && color[i] != 2){ | |
int k = i; | |
while (count == 0 && k<sizeof(s2)){ | |
k++; | |
if (color[k] == 1){ count = 1; } | |
if (color[k] == 2){ count = 2; } | |
} | |
if (count == 0){ count = 2; } | |
color[j] = count; | |
} | |
} | |
} | |
void movescan(int count, char s1[], char s2[]){ | |
cursor += count; | |
if (cursor - 5<0){ cursor = 5; } | |
if (cursor - 5>sizeof(s1) - 1){ sursor = 5 + sizeof(s1) - 1; } | |
move(3, cursor); | |
wclean(cubfile); | |
wclean(submessage); | |
waddch(submessage, s1[cursor - 5]); | |
for (int i = 0; i<sizeof(s2); i++){ | |
if (position[i] == cursor - 5){ | |
wattron(subfile, COLOR_PAIR(color[i])); | |
waddch(subfile, s2[i]); | |
watroff(subfile, COLOR_PAIR(color[i])); | |
if (color[i] == 1){ waddstr(submessage, " satisfy "); waddch(submessage, s2[i]); } | |
else{ waddstr(submessage, " not satisfy "); waddch(submessage, s2[i]); } | |
} | |
} | |
else{ | |
waddch(subfile, s2[i]); | |
} | |
} | |
wrefresh(submessage); | |
wrefresh(subfile); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment