Advertisement
NovaYoshi

Rainbow F-Chat

Mar 16th, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.26 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <windows.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. int main(int argc, char *argv[]) {
  7.   int Bold = 0;
  8.   int KeepColor = 0;
  9.  
  10.   const char *ColorNames[] = {"red","orange","yellow","green","blue","purple"};
  11.   int DelayBy = 1;
  12.   char *Peek;
  13.   long CurColor = 0;
  14.  
  15.   // enable flags if found
  16.   if(argc>1) {
  17.     for(Peek=argv[1];*Peek;Peek++)
  18.       if(tolower(*Peek) == 'b')
  19.         Bold = 1;
  20.       else if(tolower(*Peek) == 'd')
  21.         DelayBy = strtol(Peek+1, NULL, 10);
  22.       else if(tolower(*Peek) == 'k')
  23.         KeepColor = 1;
  24.   }
  25.  
  26.   while(1) {
  27.     char Input[2048], Rainbow[0x10000]="", Temp[64];
  28.     if(Bold) strcpy(Rainbow, "[b]");
  29.     fgets(Input, sizeof(Input), stdin);
  30.     int ColorActive = 0, FirstIsGraph=1;
  31.     if(!KeepColor)
  32.       CurColor = 0;
  33.  
  34.     for(Peek=Input;*Peek;Peek++) {
  35.       if(*Peek == '\n' || *Peek == '\r') continue;
  36.  
  37.       if(isgraph(*Peek)) {
  38.         if(DelayBy == 1) {
  39.           sprintf(Temp, "[color=%s]%c[/color]", ColorNames[CurColor%6], *Peek);
  40.         } else {
  41.           if(CurColor%DelayBy == 0) {
  42.             sprintf(Temp, "[color=%s]%c", ColorNames[(CurColor/DelayBy)%6], *Peek);
  43.             ColorActive = 1;
  44.           } else {
  45.             if(FirstIsGraph) {
  46.               sprintf(Temp, "[color=%s]", ColorNames[(CurColor/DelayBy)%6]);
  47.               strcat(Rainbow, Temp);
  48.             }
  49.  
  50.             if(CurColor%DelayBy == (DelayBy-1)) {
  51.               sprintf(Temp, "%c[/color]", *Peek);
  52.               ColorActive = 0;
  53.             } else
  54.               sprintf(Temp, "%c", *Peek);
  55.           }
  56.         }
  57.         FirstIsGraph = 0;
  58.         strcat(Rainbow, Temp);
  59.         CurColor++;
  60.       } else {
  61.         Temp[0]=*Peek;
  62.         Temp[1]=0;
  63.         strcat(Rainbow, Temp);
  64.       }
  65.     }
  66.     if(ColorActive) strcat(Rainbow, "[/color]");
  67.     if(Bold) strcat(Rainbow, "[/b]");
  68.  
  69.     if(!strcasecmp(Rainbow, "") || !strcasecmp(Rainbow, "[b][/b]")) continue;
  70.     const char* output = Rainbow;
  71.     const size_t len = strlen(output) + 1;
  72.     HGLOBAL hMem =  GlobalAlloc(GMEM_MOVEABLE, len);
  73.     memcpy(GlobalLock(hMem), output, len);
  74.     GlobalUnlock(hMem);
  75.     OpenClipboard(0);
  76.     EmptyClipboard();
  77.     SetClipboardData(CF_TEXT, hMem);
  78.     CloseClipboard();
  79.   }
  80.   return 1;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement