~ubuntu-branches/ubuntu/trusty/fcitx/trusty-proposed

« back to all changes in this revision

Viewing changes to tools/readPYBase.c

  • Committer: Package Import Robot
  • Author(s): Aron Xu
  • Date: 2013-02-10 17:03:56 UTC
  • mfrom: (1.3.18) (33.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20130210170356-2yuv6xy3ed378kn0
Tags: 1:4.2.7-1
* New upstream release.
* New binary packages:
  - fcitx-libs-gclient: D-Bus client library for Glib
  - fcitx-libs-qt: D-Bus client library for Qt
  - fcitx-module-quickphrase-editor: Quick Phrase editor module

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2002~2005 by Yuking                                     *
3
 
 *   yuking_net@sohu.com                                                   *
4
 
 *                                                                         *
5
 
 *   This program is free software; you can redistribute it and/or modify  *
6
 
 *   it under the terms of the GNU General Public License as published by  *
7
 
 *   the Free Software Foundation; either version 2 of the License, or     *
8
 
 *   (at your option) any later version.                                   *
9
 
 *                                                                         *
10
 
 *   This program is distributed in the hope that it will be useful,       *
11
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13
 
 *   GNU General Public License for more details.                          *
14
 
 *                                                                         *
15
 
 *   You should have received a copy of the GNU General Public License     *
16
 
 *   along with this program; if not, write to the                         *
17
 
 *   Free Software Foundation, Inc.,                                       *
18
 
 *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.              *
19
 
 ***************************************************************************/
20
 
 
21
 
#include <stdio.h>
22
 
#include <getopt.h>
23
 
#include <string.h>
24
 
 
25
 
#include "im/pinyin/py.h"
26
 
#include "pyTools.h"
27
 
#include "fcitx-config/xdg.h"
28
 
 
29
 
void usage();
30
 
 
31
 
int main(int argc, char **argv)
32
 
{
33
 
    FILE *fi;
34
 
    int i, PYFACount;
35
 
    char *pybase_mb = NULL;
36
 
 
37
 
    struct _HZMap *HZMap;
38
 
    char c;
39
 
 
40
 
    while ((c = getopt(argc, argv, "b:h")) != -1) {
41
 
        switch (c) {
42
 
 
43
 
        case 'b':
44
 
            pybase_mb = strdup(optarg);
45
 
            break;
46
 
 
47
 
        case 'h':
48
 
 
49
 
        default:
50
 
            usage();
51
 
        }
52
 
    }
53
 
 
54
 
    if (pybase_mb)
55
 
        fi = fopen(pybase_mb , "r");
56
 
    else
57
 
        fi = FcitxXDGGetFileWithPrefix("pinyin", PY_BASE_FILE, "r", &pybase_mb);
58
 
 
59
 
    if (!fi) {
60
 
        perror("fopen");
61
 
        fprintf(stderr, "Can't open file `%s' for reading\n", pybase_mb);
62
 
        exit(1);
63
 
    }
64
 
 
65
 
    free(pybase_mb);
66
 
 
67
 
    PYFACount = LoadPYBase(fi, &HZMap);
68
 
 
69
 
    if (PYFACount > 0) {
70
 
#if 0
71
 
 
72
 
        for (i = 0; i < PYFACount; ++i) {
73
 
            printf("%s: ", HZMap[i].Map);
74
 
            fwrite(HZMap[i].HZ, 2, HZMap[i].BaseCount, stdout);
75
 
            printf("\n\n");
76
 
        }
77
 
 
78
 
#else
79
 
        for (i = 0; i < PYFACount; ++i) {
80
 
            int j;
81
 
            printf("%s: HZ Index\n", HZMap[i].Map);
82
 
 
83
 
            for (j = 0; j < HZMap[i].BaseCount; ++j) {
84
 
                printf("\t%s %5d", HZMap[i].HZ[j], HZMap[i].Index[j]);
85
 
            }
86
 
 
87
 
            printf("\n");
88
 
        }
89
 
 
90
 
#endif
91
 
    }
92
 
 
93
 
    return 0;
94
 
}
95
 
 
96
 
void usage()
97
 
{
98
 
    char* pkgdatadir = fcitx_utils_get_fcitx_path("pkgdatadir");
99
 
    printf(
100
 
        "readPYBase - read pybase.mb file and display its contents\n"
101
 
        "\n"
102
 
        "  usage: readPYBase [OPTION]\n"
103
 
        "\n"
104
 
        "  -b <pybase.mb> full path to the file, usually\n"
105
 
        "                 %s/pinyin/" PY_BASE_FILE "\n"
106
 
        "                 if not specified, defaults to\n"
107
 
        "                 %s/pinyin/" PY_BASE_FILE "\n"
108
 
        "  -h             display this help\n"
109
 
        "\n",
110
 
        pkgdatadir, pkgdatadir
111
 
    );
112
 
    free(pkgdatadir);
113
 
    exit(1);
114
 
    return;
115
 
}
116
 
 
117
 
 
118
 
// kate: indent-mode cstyle; space-indent on; indent-width 4;