summaryrefslogtreecommitdiff
path: root/src/ext/libcharsetdetect/trchardet.c
blob: aba0b97a35395b7eb4740aa10bd8e7f27f579369 (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
#include "charsetdetect.h"
#include "stdio.h"

#define BUFFER_SIZE 100*1024

int main(int argc, const char * argv[]) {
    csd_t csd = csd_open();
    if (csd == (csd_t)-1) {
	printf("csd_open failed\n");
	return 1;
    }
    
    int size;
    char buf[BUFFER_SIZE] = {0};

    while ((size = fread(buf, 1, sizeof(buf), stdin)) != 0) {
	printf("CLIENT SENDING More data\n");
	int result = csd_consider(csd, buf, size);
	if (result < 0) {
	    printf("csd_consider failed\n");
	    return 3;
	} else if (result == 0) {
	    // Already have enough data
	    break;
	}
	// Only send one buffer actually, for testing
	break;
    }
    
    const char *result = csd_close(csd);
    if (result == NULL) {
	printf("Unknown character set\n");
	return 2;
    } else {
	printf("%s\n", result);
	return 0;
    }
}