File: ydptest.c

package info (click to toggle)
libydpdict 1.0.4-3
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm, bullseye, buster, forky, sid, stretch, trixie
  • size: 200 kB
  • ctags: 73
  • sloc: ansic: 848; makefile: 30; python: 19; sh: 12
file content (67 lines) | stat: -rw-r--r-- 1,242 bytes parent folder | download | duplicates (3)
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
#include <stdio.h>
#include <stdlib.h>

#include "ydpdict.h"

#define DICT_PATH "/usr/local/share/ydpdict"

int main(int argc, char **argv)
{
	char dat[128], idx[128];
	ydpdict_t *dict;
	FILE *f;
	int i, dictno;
	const char *word;

	if (argc == 1) {
		dictno = 100;
		word = "0";
	} else if (argc == 2) {
		dictno = atoi(argv[1]);
		word = "0";
	} else if (argc == 3) {
		dictno = atoi(argv[1]);
		word = argv[2];
	} else {
		fprintf(stderr, "usage: %s [dict] [word]\n", argv[0]);
		return 1;
	}
	
	snprintf(dat, sizeof(dat), "%s/dict%03d.dat", DICT_PATH, dictno);
	snprintf(idx, sizeof(idx), "%s/dict%03d.idx", DICT_PATH, dictno);

	if (!(dict = ydpdict_open(dat, idx, YDPDICT_ENCODING_UTF8))) {
		perror("ydpdict_open");
		return 1;
	}

	if (!(i = atoi(word)))
		i = ydpdict_find_word(dict, word);

	printf("ydpdict_find_word() = %d\n", i);
	
	if (i != -1) {
		char *rtf, *xhtml;
		
		rtf = ydpdict_read_rtf(dict, i);
		xhtml = ydpdict_read_xhtml(dict, i);
		
		printf("-----\n%s\n-----\n%s\n-----\n", rtf, xhtml);
		
		f = fopen("ydptest.rtf", "w");
		fprintf(f, "%s\n", rtf);
		fclose(f);

		f = fopen("ydptest.html", "w");
		fprintf(f, "%s\n", xhtml);
		fclose(f);
		
		free(rtf);
		free(xhtml);
	}

	ydpdict_close(dict);

	return 0;
}