updated changelog
[platform/upstream/evolution-data-server.git] / addressbook / libebook-contacts / gen-western-table.py
1 #! /usr/bin/env python
2
3 # Copyright (C) 2006 Intel Corporation
4 #
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 # for more details.
13
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this program; if not, see <http://www.gnu.org/licenses/>.
16 #
17 # Author: Ross Burton <ross@openedhand.com>
18
19 import sys
20
21 if sys.version_info[0] >= 3:
22     stdin = sys.stdin.buffer
23     stdout = sys.stdout.buffer
24 else:
25     stdin = sys.stdin
26     stdout = sys.stdout
27
28 var = None
29 strings = []
30
31 def output():
32     stdout.write(b"static const gchar " + var + b"_table[] = {\n")
33     for s in strings:
34         stdout.write(b"  \"" + s + b"\\0\"\n")
35     stdout.write(b"};\n")
36
37     stdout.write(b"static const guint " + var + b"_index[] = {\n")
38     index = 0
39     for s in strings:
40         stdout.write(b"  " + str(index).encode() + b",\n")
41         index += len(s) + 1
42     stdout.write(b"};\n\n")
43     
44 (S_VAR, S_STRING) = range(0, 2)
45 state = S_VAR
46
47 stdout.write(b"/* This file is generated by gen-western-table.py. DO NOT EDIT */\n")
48
49 for l in stdin.readlines():
50     l = l.strip()
51     if l == b"":
52         state = S_VAR
53         output()
54         var = None
55         strings = []
56     elif state == S_VAR:
57         var = l
58         state = S_STRING
59     elif state == S_STRING:
60         strings.append(l)
61
62 output()