summaryrefslogtreecommitdiffstats
path: root/statgen/test.c
blob: 936b491512b083d6c52711ec75a74fa49c24f825 (plain)
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
#include <stdio.h>
#include "charset_auto_russian.h"

main(int argc, char *argv[]) {
    FILE *f;
    int len,st;
    char word[256],phrase[8192];
    unsigned long a[4]={0,0,0,0};
    int i,max,mw;


    if ((argc!=2)&&(argc!=3)) {
	printf("Usage: %s <file name> [<max words>]\n",argv[0]);
	exit(0);
    }

    if (argc==3) mw=atoi(argv[2]);
    else mw=1;
    
    f=fopen(argv[1],"r");
    if (!f) {
	printf("Failed to open specified file. Check permissions!\n");
	exit(1);
    }
    
    while(!feof(f)) {
	strcpy(phrase,"");
	for (i=0;i<mw;i++) {
	    if (i) strcat(phrase," ");
	    fscanf(f,"%s",&word);
	    for(st=0;word[st]=='"'||word[st]=='\''||word[st]=='(';st++);
	    if (strlen(word)<1) continue;
	    for(len=strlen(word)-1;word[len]==','||word[len]=='.'||word[len]=='!'||word[len]=='?'||word[len]==';'||word[len]=='-'||word[len]==':'||word[len]=='"'||word[len]=='\''||word[len]==')';len--);
	    if (strlen(word)<1) continue;
	    else word[len+1]=0;
	    strcat(phrase,word+st);
	}
	if (strlen(phrase)<5) continue;

	a[autocharset_russian_uc(phrase,strlen(phrase))]++;
//	a[autocharset_russian(phrase,strlen(phrase))]++;

//	a[autocharset_russian(word+st,len+1-st)]++;
//	puts(word);
    }

    printf("Win: %lu, Koi: %lu, Alt: %lu, UTF: %lu\n",a[0],a[1],a[3],a[2]);
    fclose(f);
    if (a[0]>a[1]) {
	if (a[0]>a[2]) max=0;
	else max=2;
    } else {
	if (a[1]>a[2]) max=1;
	else max=2;
    }
    if (a[3]>max) max=3;

    f=fopen(argv[1],"r");
    while(!feof(f)) {
	strcpy(phrase,"");
	for (i=0;i<mw;i++) {
	    if (i) strcat(phrase," ");
	    fscanf(f,"%s",&word);
	    for(st=0;word[st]=='"'||word[st]=='\''||word[st]=='(';st++);
	    if (strlen(word)<1) continue;
	    for(len=strlen(word)-1;word[len]==','||word[len]=='.'||word[len]=='!'||word[len]=='?'||word[len]==';'||word[len]=='-'||word[len]==':'||word[len]=='"'||word[len]=='\''||word[len]==')';len--);
	    if (strlen(word)<1) continue;
	    else word[len+1]=0;
	    strcat(phrase,word+st);
	}
	if (strlen(phrase)<5) continue;

	i=autocharset_russian_uc(phrase,strlen(phrase));
//	i=autocharset_russian(phrase,strlen(phrase));
//	i=autocharset_russian(word+st,len+1-st);
	if (i!=max) {
	    if (i==0) printf("Win: %s\n",phrase);
	    else if (i==1) printf("Koi: %s\n",phrase);
	    else if (i==2) printf("UTF: %s\n",phrase);
	    else if (i==3) printf("ALT: %s\n",phrase);
	}
    }
    fclose(f);
}