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
|
/* Test driver for thbrk
*/
#define MAXLINELENGTH 1000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <thai/thbrk.h>
/* run with "-i" argument to get the interactive version
otherwise it will run the self test and exit */
int main (int argc, char* argv[])
{
thchar_t str[MAXLINELENGTH];
thchar_t out[MAXLINELENGTH*6+1];
int pos[MAXLINELENGTH];
int outputLength;
int numCut, i;
int interactive = 0;
if (argc >= 2) {
if (0 == strcmp (argv[1], "-i"))
interactive = 1;
}
if (interactive) {
while (!feof (stdin)) {
printf ("Please enter thai words/sentences: ");
fgets ((char *)str, MAXLINELENGTH-1, stdin);
if (!feof (stdin)) {
numCut = th_brk (str, pos, MAXLINELENGTH);
printf ("Total %d cut points.", numCut);
if (numCut > 0) {
printf ("Cut points list: %d", pos[0]);
for (i = 1; i < numCut; i++) {
printf(", %d", pos[i]);
}
}
printf("\n");
outputLength = th_brk_line (str, out, sizeof out, "<WBR>");
printf ("Output string length is %d\n", outputLength-1); /* the penultimate is \n */
printf ("Output string is %s", out);
printf("***********************************************************************\n");
}
}
} else {
strcpy ((char *)str, "ʴդѺ 繡÷ͺͧ");
printf ("Testing with string: %s\n", str);
numCut = th_brk (str, pos, MAXLINELENGTH);
printf ("Total %d cut points.", numCut);
if (numCut != 6) {
printf("Error! should be 6.. test th_brk() failed...\n");
exit (-1);
}
printf("Cut points list: %d", pos[0]);
for (i = 1; i < numCut; i++) {
printf(", %d", pos[i]);
}
printf("\n");
outputLength = th_brk_line (str, out, sizeof out, "<WBR>");
printf ("Output string is %s\n", out);
printf ("Output string length is %d\n", outputLength);
if (outputLength != 62) {
printf ("Error! should be 62.. test th_brk_line() failed...\n");
exit (-1);
}
printf ("*** End of thbrk self test ******\n");
}
return 0;
}
|