/* Auteur: Ti-R-4 */ /* Plateforme: Win32/Linux */ /* Compilateur/version:gcc(mingw-special)/? */ /*-------------------------------------------------------------------*/ /* Auteur: Renan Lavarec (nickname: Ti-R) */ /* This is free to use and modify provided my name is included. */ /*-------------------------------------------------------------------*/ #include <stdio.h> #include <stdlib.h> #include <time.h> typedef unsigned int UINT; typedef unsigned char UCHAR; typedef int bool; #define false 0 #define true 1 /* clock_t begin_quantify; void StartQuantify() { begin_quantify=clock(); } void StopQuantifyWindows(char *_string) { printf("\n\n%s: %f ms\n",_string,((clock()-begin_quantify)/(float)CLOCKS_PER_SEC)*1000); } */ bool tr_strincmp_first(char *_s1,char *_s2,int _size) { static char g_dif_a=('A'-'a'); while(_size--) { if(*_s1!=*_s2 && *_s1!=((*_s2)-g_dif_a)) return false; ++_s1; ++_s2; } return true; } char *buffer; char *pt_buffer; char *pt_current_link; int nb_link=0; inline void ParseLink(char **_s, char* _low_case_name, int _size_name) { static tmp_i; static count_max_link_size; while(1) { // Try to find '=' while(1) { if((**_s)=='>' || !(**_s)) return; if(**_s=='=') break; ++(*_s); } // Compare if it is href/img and so on in from of the '=' if(tr_strincmp_first(_low_case_name, (*_s)-_size_name,_size_name)) { ++(*_s); if((**_s)=='"') { // Get the link pt_current_link=++(*_s); while(--count_max_link_size) { if((**_s)=='>' || !(**_s)) return; if(**_s=='"') { **_s='\0'; break; } ++(*_s); } // Display the link puts(pt_current_link); // ++nb_link; // After finding the link, jump to the end > while(1) { if(*(++*_s)=='>' || !(**_s)) return; } } } ++(*_s); } } void GetLink(char **_s) { ParseLink(_s, "href", 4); } void GetImg(char **_s) { ParseLink(_s, "src", 3); } void Parse() { // Get the size of file fseek(stdin, 0, SEEK_END); UINT buffer_size = ftell(stdin); rewind(stdin); // Allocate memory buffer = malloc(buffer_size+1); // Copy all file in the memory pt_buffer = buffer; while(fread(pt_buffer, 1, 4096, stdin)) pt_buffer+=4096; // Limite la fin du buffer buffer[buffer_size]='\0'; void (*pt_functions[256])(char **); memset(pt_functions,0,sizeof(void (*)(char **))*256); pt_functions['a']=GetLink; pt_functions['A']=GetLink; pt_functions['i']=GetImg; pt_functions['I']=GetImg; pt_buffer = buffer; char **_s = &pt_buffer; while(**_s) { if((**_s)=='<') { ++(*_s); if(pt_functions[(UCHAR)**_s]) pt_functions[(UCHAR)**_s](_s); } else ++(*_s); } free(buffer); // printf("\nnb liens: %i",nb_link); } int main(int argc, char *argv[]) { // StartQuantify(); Parse(); // StopQuantifyWindows("time: "); return EXIT_SUCCESS; }