]>
git.saurik.com Git - apple/icu.git/blob - icuSources/samples/csdet/csdet.c
2 ********************************************************************************
3 * Copyright (C) 2005-2006, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ********************************************************************************
8 #include "unicode/utypes.h"
9 #include "unicode/ucsdet.h"
14 #define BUFFER_SIZE 8192
16 int main(int argc
, char *argv
[])
18 static char buffer
[BUFFER_SIZE
];
22 printf("Usage: %s [filename]...\n", argv
[0]);
26 for(arg
= 1; arg
< argc
; arg
+= 1) {
28 char *filename
= argv
[arg
];
29 int32_t inputLength
, match
, matchCount
= 0;
30 UCharsetDetector
* csd
;
31 const UCharsetMatch
**csm
;
32 UErrorCode status
= U_ZERO_ERROR
;
38 file
= fopen(filename
, "rb");
41 printf("Cannot open file \"%s\"\n\n", filename
);
45 printf("%s:\n", filename
);
47 inputLength
= (int32_t) fread(buffer
, 1, BUFFER_SIZE
, file
);
51 csd
= ucsdet_open(&status
);
52 ucsdet_setText(csd
, buffer
, inputLength
, &status
);
54 csm
= ucsdet_detectAll(csd
, &matchCount
, &status
);
56 for(match
= 0; match
< matchCount
; match
+= 1) {
57 const char *name
= ucsdet_getName(csm
[match
], &status
);
58 const char *lang
= ucsdet_getLanguage(csm
[match
], &status
);
59 int32_t confidence
= ucsdet_getConfidence(csm
[match
], &status
);
61 if (lang
== NULL
|| strlen(lang
) == 0) {
65 printf("%s (%s) %d\n", name
, lang
, confidence
);