Advertisement
NovaYoshi

Goldick

Jul 30th, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <ctype.h>
  5. #include <time.h>
  6.  
  7. //http://gnuwin32.sourceforge.net/packages/wget.htm
  8.  
  9. static int Goldick(const char *Name, char *Link) {
  10.   FILE *HTMLFile = fopen(Name,"rb");
  11.   if(HTMLFile == NULL) {
  12.     fputs("Goldick Couldn't open file",stderr); return 0;
  13.   }
  14.   fseek(HTMLFile, 0, SEEK_END);
  15.   long FileSize = ftell(HTMLFile);
  16.   rewind(HTMLFile);
  17.   char *Buffer = (char*)malloc(sizeof(char)*FileSize);
  18.   if(Buffer == NULL) {
  19.     fclose(HTMLFile);
  20.     fputs("Goldick Memory error",stderr); return 0;
  21.   }
  22.   if(FileSize != fread(Buffer,1,FileSize,HTMLFile)) {
  23.     fclose(HTMLFile);
  24.     fputs("Goldick Reading error",stderr); return 0;
  25.   }
  26.   fclose(HTMLFile);
  27.  
  28.   int PokedexNum = -1, HP = 0, ATK = 0, DEF = 0, SpATK = 0, SpDEF = 0, SPD = 85;
  29.   char PokeName[64]="???";
  30.   char Type[64]="Gay";
  31.   char Kind[64]="Dick"; // dick
  32.   char URL[200] = "http://novasquirrel.com";
  33.  
  34.   char *Ptr;
  35.   Ptr = strstr(Buffer, "line-height:2.28;\"><b><a href=\"/wiki/List_of_Pok%C3%A9mon_by_National_Pok%C3%A9dex_number\" title=\"List of Pok\xc3\xa9mon by National Pok\xc3\xa9dex number");
  36.   if(Ptr != NULL) {
  37.     Ptr = strstr(Ptr, "</span>");
  38.     if(Ptr != NULL) {
  39.       while(*Ptr != '#') Ptr--;
  40.       PokedexNum = strtol(Ptr+1, NULL, 10);
  41.     }
  42.   }
  43.  
  44.   int GetStat(char *Base, char *SeekMe) {
  45.     char *Peek;
  46.     if((Peek = strstr(Base, SeekMe)) == NULL) return 0;
  47.     if((Peek = strstr(Peek, "</th>")) == NULL) return 0;
  48.     if((Peek = strstr(Peek+1, "</th>")) == NULL) return 0;
  49.     while(!isdigit(*Peek)) Peek--;
  50.     while(isdigit(*Peek)) Peek--;
  51.     return strtol(Peek+1, NULL, 10);
  52.   }
  53.  
  54.   char *BaseStats = strstr(Buffer, "<h4> <span class=\"mw-headline\" id=\"Base_stats\">Base stats</span></h4>");
  55.   if(BaseStats != NULL) {
  56.     HP = GetStat(BaseStats, "/wiki/Stats#Hit_Points");
  57.     ATK = GetStat(BaseStats, "/wiki/Stats#Attack");
  58.     DEF = GetStat(BaseStats, "/wiki/Stats#Defense");
  59.     SpATK = GetStat(BaseStats, "/wiki/Stats#Special_Attack");
  60.     SpDEF = GetStat(BaseStats, "/wiki/Stats#Special_Defense");
  61.     SPD = GetStat(BaseStats, "/wiki/Stats#Speed");
  62.   }
  63.  
  64.   int NumType = 0;
  65.   void TryType(char *LookFor, char *Name) {
  66.     if(NULL==strstr(Buffer, LookFor)) return;
  67.     if(NumType == 0) {
  68.       strcpy(Type, Name);
  69.       NumType++;
  70.     } else if(NumType == 1) {
  71.       strcat(Type, "/");
  72.       strcat(Type, Name);
  73.     }
  74.   }
  75.  
  76.   TryType("\"Normal-type Pok\xc3\xa9mon\"","Normal");
  77.   TryType("\"Ghost-type Pok\xc3\xa9mon\"","Ghost");
  78.   TryType("\"Fighting-type Pok\xc3\xa9mon\"","Fighting");
  79.   TryType("\"Electric-type Pok\xc3\xa9mon\"","Electric");
  80.   TryType("\"Grass-type Pok\xc3\xa9mon\"","Grass");
  81.   TryType("\"Psychic-type Pok\xc3\xa9mon\"","Psychic");
  82.   TryType("\"Bug-type Pok\xc3\xa9mon\"","Bug");
  83.   TryType("\"Dragon-type Pok\xc3\xa9mon\"","Dragon");
  84.   TryType("\"Ice-type Pok\xc3\xa9mon\"","Ice");
  85.   TryType("\"Dark-type Pok\xc3\xa9mon\"","Dark");
  86.   TryType("\"Steel-type Pok\xc3\xa9mon\"","Steel");
  87.   TryType("\"Poison-type Pok\xc3\xa9mon\"","Poison");
  88.   TryType("\"Fire-type Pok\xc3\xa9mon\"","Fire");
  89.   TryType("\"Water-type Pok\xc3\xa9mon\"","Water");
  90.   TryType("\"Rock-type Pok\xc3\xa9mon\"","Rock");
  91.   TryType("\"Ground-type Pok\xc3\xa9mon\"","Ground");
  92.   TryType("\"Flying-type Pok\xc3\xa9mon\"","Flying");
  93.   TryType("\"Fairy-type Pok\xc3\xa9mon\"","Fairy");
  94.  
  95.   Ptr = strstr(Buffer, "<title>");
  96.   if(Ptr != NULL) {
  97.     Ptr += 7;
  98.     char *Poke = PokeName;
  99.     while(*Ptr != '(')
  100.       *(Poke++) = *(Ptr++);
  101.     while(*Poke != ' ')
  102.       Poke--;
  103.     *Poke = 0;
  104.   }
  105.   sprintf(URL, "http://bulbapedia.bulbagarden.net/wiki/%s", PokeName);
  106.   for(Ptr = URL;*Ptr;Ptr++)
  107.     if(*Ptr == ' ')
  108.       *Ptr = '_';
  109.  
  110.   Ptr = strstr(Buffer, "<td> <b><a href=\"/wiki/Species\" title=\"Species\"><span style=\"color:#000;\">Species</span></a></b>");
  111.   if(Ptr != NULL) {
  112.     Ptr = strstr(Ptr, "</td></tr></table>");
  113.     if(Ptr != NULL) {
  114.       while(*Ptr != '>') Ptr--;
  115.       Ptr+=2;
  116.       char *Poke = Kind;
  117.       while(!(Ptr[1]=='P'&&Ptr[2]=='o'&&Ptr[3]=='k'))
  118.         *(Poke++) = *(Ptr++);
  119.       *Poke = 0;
  120.       if(!strcasecmp(Kind, "Duck"))
  121.         strcpy(Kind, "Dick");
  122.     }
  123.   }
  124.  
  125.   if(HP !=  0)
  126.     printf("#%.3i %s, the %s Pokemon. %s type. Base stats: HP %i, ATK %i, DEF %i, SpATK %i, SpDEF %i, SPD %i, TOTAL %i. %s", PokedexNum, PokeName, Kind, Type, HP, ATK, DEF, SpATK, SpDEF, SPD, HP+ATK+DEF+SpATK+SpDEF+SPD, URL);
  127.   else
  128.     printf("Are you sure that's a Pokemon?");
  129.  
  130.   free(Buffer);
  131.   return 1;
  132. }
  133.  
  134. int main(int argc, char *argv[]) {
  135.   srand((unsigned)time(NULL));
  136.   if(argc < 2){puts(":("); return -1;}
  137.   remove("pokeymans.html");
  138.   char Buff[768];
  139.  
  140.   if(!strcasecmp(argv[1],"NovaSquirrel")) {
  141.     printf("#??? NovaSquirrel, the Dickgirl Pokemon. Electric type. Base stats: HP 100, ATK 100, DEF 100, SpATK 100, SpDEF 100, SPD 100, Total 600.");
  142.   } else if(!strcasecmp(argv[1],"penis")) {
  143.     printf("#??? My Penis, the Phallic Pokemon. Normal type. Base stats: HP 1, ATK 1, DEF 1, SpATK 1, SpDEF 1, SPD 100, Total 105.");
  144.   } else if(!strcasecmp(argv[1],"fisher_price")) {
  145.     printf("#??? Fisher Price, the Go Eat Shit Fuckers Pokemon. Nuclear type. Base stats: HP -1, ATK -1, DEF -1, SpATK -1, SpDEF -1, SPD -1, Total -6.");
  146.   } else if(argv[1][0]=='.') {
  147.     char *TypeNames[] = {"Normal","Ghost","Fighting","Electric","Grass","Psychic","Bug","Dragon","Ice","Dark","Steel","Poison","Fire","Water","Rock","Ground","Flying","Nuclear",NULL};
  148.     char *Kinds[] = {"Fake","Cool","Dick","Illegal","President","Drugs","Epic","Rad"};
  149.     char *StuffNames;
  150.     int HP = 1+(rand()&255);
  151.     int ATK = 1+(rand()&255);
  152.     int DEF = 1+(rand()&255);
  153.     int SpATK = 1+(rand()&255);
  154.     int SpDEF = 1+(rand()&255);
  155.     int SPD = 1+(rand()&255);
  156.     char PokeName[100];
  157.     int i;
  158.  
  159.     for(i=0;i<strlen(argv[1]);i++)
  160.       if(argv[1][1+i]=='_')
  161.         PokeName[i] = ' ';
  162.       else
  163.         PokeName[i] = argv[1][1+i];
  164.     PokeName[i]=0;
  165.  
  166.     if(rand()&1)
  167.       printf("#??? %s, the %s Pokemon. %s type. Base stats: HP %i, ATK %i, DEF %i, SpATK %i, SpDEF %i, SPD %i, TOTAL %i.", PokeName, Kinds[(rand()>>7)&7], TypeNames[rand()%18], HP, ATK, DEF, SpATK, SpDEF, SPD, HP+ATK+DEF+SpATK+SpDEF+SPD);
  168.     else
  169.       printf("#??? %s, the %s Pokemon. %s/%s type. Base stats: HP %i, ATK %i, DEF %i, SpATK %i, SpDEF %i, SPD %i, TOTAL %i.", PokeName, Kinds[(rand()>>7)&7], TypeNames[rand()%18], TypeNames[rand()%18], HP, ATK, DEF, SpATK, SpDEF, SPD, HP+ATK+DEF+SpATK+SpDEF+SPD);
  170.   } else {
  171.     sprintf(Buff, "wget \"http://bulbapedia.bulbagarden.net/wiki/%s_(Pok%%C3%%A9mon)\" -q -O pokeymans.html", argv[1]);
  172.     system(Buff);
  173.  
  174.     char Link[1024]="";
  175.     Goldick("pokeymans.html", Link);
  176.     remove("pokeymans.html");
  177.   }
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement