File: mkdict.py

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 (33 lines) | stat: -rwxr-xr-x 818 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

dict = [
	(ur"słowo", ur"{\b słowo} {[\f1\cf5 wymowa]}\par\pard{\line\cf2\i część mowy\line} ({\i dziedzina}){\f2\cf1 definicja},{\f2\cf1 definicja {\cf2\i rodzaj}}\par\sa100\li300{\cf0 Przykład użycia.}"),
]

import struct

idx = open("dict999.idx", "w")
dat = open("dict999.dat", "w")

idx.write(struct.pack("<LLHHLL236s", 0x8D4E11D5, 0, len(dict), 0, 0, 256, ""))

idx_offset = 1
dat_offset = 0

for i in dict:
	(word, definition) = i

	word = word.encode('windows-1250')
	definition = definition.encode('windows-1250')

	idx.write(struct.pack("<BBHL", len(word) + 1, 2, idx_offset, dat_offset) + word + "\0")

	dat.write(struct.pack("<L", len(definition)) + definition)

	idx_offset = idx_offset + 1
	dat_offset = 4 + len(definition)

idx.close()
dat.close()