1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
#define max_size 1000000
#define half_size 500000
char Buffer[max_size];
short Count[half_size];
TStringList *List;
char Ok[256];
//-----
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
List = new TStringList;
char j;
//Initialisation du filtre
for(j = 'A'; j <= 'Z'; j++) Ok[j]=j;
for(j = 'a'; j <= 'z'; j++) Ok[j]=j;
}
//-----
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
if(OpenDialog1->Execute())
{
FILE *htm = fopen(OpenDialog1->FileName.c_str(), "rb");
fseek(htm, 0, SEEK_END);
int max = ftell(htm);
if(max > max_size)
{
fclose(htm);
return;
}
fseek(htm, 0, SEEK_SET);
fread(Buffer, 1, max, htm);
fclose(htm);
// On purge ...
List->Clear();
RichEdit1->Lines->Clear();
// Et on traite...
int n;
char *p = Buffer;
char *s = p;
char *e = p + max;
short *count;
// Une première passe pour supprimer les caractères "parasites"
while(s < e)
{
*s = Ok[*s];
s++;
}
// La deuxième passe ... sans commentaires ...
s = Buffer;
while(s < e)
{
if(*s != 0)
{
s++;
}
else
{
if(strlen(p) == 0)
{
s++;
p = s;
}
else
{
n = List->IndexOf(p);
if(n == -1)
{
n = List->Count;
Count[n] = 1;
List->AddObject(p, (TObject*)&Count[n]);
}
else
{
count = (short*)List->Objects[n];
(*count)++;
}
p = s;
}
}
}
for(int j = 0; j < List->Count; j++)
{
RichEdit1->Lines->Add(List->Strings[j] +
" = " +
IntToStr( *(short*)List->Objects[j] ) );
}
}
}
//-----
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
List->Clear();
delete List;
} |
Partager