/rusxmms/librcd

To get this branch, use:
bzr branch http://suren.me/webbzr/rusxmms/librcd

« back to all changes in this revision

Viewing changes to statgen/test.c

  • Committer: Suren A. Chilingaryan
  • Date: 2005-06-16 23:19:27 UTC
  • Revision ID: Arch-1:ds@dside.dyndns.org--darksoft-2004%librcd--main--0.1--base-0
initial import

(automatically generated log message)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include "charset_auto_russian.h"
 
3
 
 
4
main(int argc, char *argv[]) {
 
5
    FILE *f;
 
6
    int len,st;
 
7
    char word[256],phrase[8192];
 
8
    unsigned long a[4]={0,0,0,0};
 
9
    int i,max,mw;
 
10
 
 
11
 
 
12
    if ((argc!=2)&&(argc!=3)) {
 
13
        printf("Usage: %s <file name> [<max words>]\n",argv[0]);
 
14
        exit(0);
 
15
    }
 
16
 
 
17
    if (argc==3) mw=atoi(argv[2]);
 
18
    else mw=1;
 
19
    
 
20
    f=fopen(argv[1],"r");
 
21
    if (!f) {
 
22
        printf("Failed to open specified file. Check permissions!\n");
 
23
        exit(1);
 
24
    }
 
25
    
 
26
    while(!feof(f)) {
 
27
        strcpy(phrase,"");
 
28
        for (i=0;i<mw;i++) {
 
29
            if (i) strcat(phrase," ");
 
30
            fscanf(f,"%s",&word);
 
31
            for(st=0;word[st]=='"'||word[st]=='\''||word[st]=='(';st++);
 
32
            if (strlen(word)<1) continue;
 
33
            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--);
 
34
            if (strlen(word)<1) continue;
 
35
            else word[len+1]=0;
 
36
            strcat(phrase,word+st);
 
37
        }
 
38
        if (strlen(phrase)<5) continue;
 
39
 
 
40
        a[autocharset_russian_uc(phrase,strlen(phrase))]++;
 
41
//      a[autocharset_russian(phrase,strlen(phrase))]++;
 
42
 
 
43
//      a[autocharset_russian(word+st,len+1-st)]++;
 
44
//      puts(word);
 
45
    }
 
46
 
 
47
    printf("Win: %lu, Koi: %lu, Alt: %lu, UTF: %lu\n",a[0],a[1],a[3],a[2]);
 
48
    fclose(f);
 
49
    if (a[0]>a[1]) {
 
50
        if (a[0]>a[2]) max=0;
 
51
        else max=2;
 
52
    } else {
 
53
        if (a[1]>a[2]) max=1;
 
54
        else max=2;
 
55
    }
 
56
    if (a[3]>max) max=3;
 
57
 
 
58
    f=fopen(argv[1],"r");
 
59
    while(!feof(f)) {
 
60
        strcpy(phrase,"");
 
61
        for (i=0;i<mw;i++) {
 
62
            if (i) strcat(phrase," ");
 
63
            fscanf(f,"%s",&word);
 
64
            for(st=0;word[st]=='"'||word[st]=='\''||word[st]=='(';st++);
 
65
            if (strlen(word)<1) continue;
 
66
            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--);
 
67
            if (strlen(word)<1) continue;
 
68
            else word[len+1]=0;
 
69
            strcat(phrase,word+st);
 
70
        }
 
71
        if (strlen(phrase)<5) continue;
 
72
 
 
73
        i=autocharset_russian_uc(phrase,strlen(phrase));
 
74
//      i=autocharset_russian(phrase,strlen(phrase));
 
75
//      i=autocharset_russian(word+st,len+1-st);
 
76
        if (i!=max) {
 
77
            if (i==0) printf("Win: %s\n",phrase);
 
78
            else if (i==1) printf("Koi: %s\n",phrase);
 
79
            else if (i==2) printf("UTF: %s\n",phrase);
 
80
            else if (i==3) printf("ALT: %s\n",phrase);
 
81
        }
 
82
    }
 
83
    fclose(f);
 
84
}