Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <windows.h>
- #include <ctype.h>
- #include <string.h>
- int main(int argc, char *argv[]) {
- int Bold = 0;
- int KeepColor = 0;
- const char *ColorNames[] = {"red","orange","yellow","green","blue","purple"};
- int DelayBy = 1;
- char *Peek;
- long CurColor = 0;
- // enable flags if found
- if(argc>1) {
- for(Peek=argv[1];*Peek;Peek++)
- if(tolower(*Peek) == 'b')
- Bold = 1;
- else if(tolower(*Peek) == 'd')
- DelayBy = strtol(Peek+1, NULL, 10);
- else if(tolower(*Peek) == 'k')
- KeepColor = 1;
- }
- while(1) {
- char Input[2048], Rainbow[0x10000]="", Temp[64];
- if(Bold) strcpy(Rainbow, "[b]");
- fgets(Input, sizeof(Input), stdin);
- int ColorActive = 0, FirstIsGraph=1;
- if(!KeepColor)
- CurColor = 0;
- for(Peek=Input;*Peek;Peek++) {
- if(*Peek == '\n' || *Peek == '\r') continue;
- if(isgraph(*Peek)) {
- if(DelayBy == 1) {
- sprintf(Temp, "[color=%s]%c[/color]", ColorNames[CurColor%6], *Peek);
- } else {
- if(CurColor%DelayBy == 0) {
- sprintf(Temp, "[color=%s]%c", ColorNames[(CurColor/DelayBy)%6], *Peek);
- ColorActive = 1;
- } else {
- if(FirstIsGraph) {
- sprintf(Temp, "[color=%s]", ColorNames[(CurColor/DelayBy)%6]);
- strcat(Rainbow, Temp);
- }
- if(CurColor%DelayBy == (DelayBy-1)) {
- sprintf(Temp, "%c[/color]", *Peek);
- ColorActive = 0;
- } else
- sprintf(Temp, "%c", *Peek);
- }
- }
- FirstIsGraph = 0;
- strcat(Rainbow, Temp);
- CurColor++;
- } else {
- Temp[0]=*Peek;
- Temp[1]=0;
- strcat(Rainbow, Temp);
- }
- }
- if(ColorActive) strcat(Rainbow, "[/color]");
- if(Bold) strcat(Rainbow, "[/b]");
- if(!strcasecmp(Rainbow, "") || !strcasecmp(Rainbow, "[b][/b]")) continue;
- const char* output = Rainbow;
- const size_t len = strlen(output) + 1;
- HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len);
- memcpy(GlobalLock(hMem), output, len);
- GlobalUnlock(hMem);
- OpenClipboard(0);
- EmptyClipboard();
- SetClipboardData(CF_TEXT, hMem);
- CloseClipboard();
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement