1
by NOKUBI Takatsugu
Import upstream version 2.2.9 |
1 |
/*
|
1.1.1
by NOKUBI Takatsugu
Import upstream version 2.3.3 |
2 |
* Copyright (c) 2003 Nara Institute of Science and Technology
|
1
by NOKUBI Takatsugu
Import upstream version 2.2.9 |
3 |
* All rights reserved.
|
4 |
*
|
|
5 |
* Redistribution and use in source and binary forms, with or without
|
|
6 |
* modification, are permitted provided that the following conditions
|
|
7 |
* are met:
|
|
1.1.1
by NOKUBI Takatsugu
Import upstream version 2.3.3 |
8 |
*
|
1
by NOKUBI Takatsugu
Import upstream version 2.2.9 |
9 |
* 1. Redistributions of source code must retain the above copyright
|
1.1.1
by NOKUBI Takatsugu
Import upstream version 2.3.3 |
10 |
* notice, this list of conditions and the following disclaimer.
|
1
by NOKUBI Takatsugu
Import upstream version 2.2.9 |
11 |
* 2. Redistributions in binary form must reproduce the above copyright
|
12 |
* notice, this list of conditions and the following disclaimer in the
|
|
13 |
* documentation and/or other materials provided with the distribution.
|
|
1.1.1
by NOKUBI Takatsugu
Import upstream version 2.3.3 |
14 |
* 3. The name Nara Institute of Science and Technology may not be used to
|
15 |
* endorse or promote products derived from this software without
|
|
16 |
* specific prior written permission.
|
|
1
by NOKUBI Takatsugu
Import upstream version 2.2.9 |
17 |
*
|
18 |
* THIS SOFTWARE IS PROVIDED BY Nara Institute of Science and Technology
|
|
19 |
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
20 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
21 |
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE Nara Institute
|
|
22 |
* of Science and Technology BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
23 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
24 |
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
25 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
26 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
27 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
1.1.1
by NOKUBI Takatsugu
Import upstream version 2.3.3 |
28 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1
by NOKUBI Takatsugu
Import upstream version 2.2.9 |
29 |
*
|
1.1.1
by NOKUBI Takatsugu
Import upstream version 2.3.3 |
30 |
* $Id: katuyou.c,v 1.14 2003/07/08 17:08:49 kazuma-t Exp $
|
1
by NOKUBI Takatsugu
Import upstream version 2.2.9 |
31 |
*/
|
32 |
||
33 |
#include "chadic.h" |
|
1.1.1
by NOKUBI Takatsugu
Import upstream version 2.3.3 |
34 |
#include "literal.h" |
1
by NOKUBI Takatsugu
Import upstream version 2.2.9 |
35 |
|
36 |
ktype_t Cha_type[TYPE_NUM]; |
|
37 |
kform_t Cha_form[TYPE_NUM][FORM_NUM]; |
|
38 |
char *Cha_base_form_str = NULL; |
|
39 |
||
40 |
/*
|
|
41 |
* read_type_form
|
|
42 |
*/
|
|
43 |
static void |
|
44 |
read_type_form(FILE * fp) |
|
45 |
{
|
|
46 |
chasen_cell_t *cell1, *cell2; |
|
47 |
int i, j; |
|
48 |
char *s; |
|
49 |
||
50 |
for (i = 1; !cha_s_feof(fp); i++) { |
|
51 |
cell1 = cha_s_read(fp); |
|
52 |
Cha_type[i].name = cha_strdup(cha_s_atom(cha_car(cell1))); |
|
53 |
Cha_type[i].basic = 0; |
|
54 |
cell1 = cha_car(cha_cdr(cell1)); |
|
55 |
||
56 |
/* base form string */
|
|
1.1.1
by NOKUBI Takatsugu
Import upstream version 2.3.3 |
57 |
if (cha_litmatch(Cha_type[i].name, 2, |
58 |
STR_BASE_FORM_STR1, STR_BASE_FORM_STR2)) { |
|
1
by NOKUBI Takatsugu
Import upstream version 2.2.9 |
59 |
Cha_base_form_str = cha_strdup(cha_s_atom(cell1)); |
60 |
i--; |
|
61 |
continue; |
|
62 |
}
|
|
63 |
||
64 |
for (j = 1; !nullp(cell2 = cha_car(cell1)); |
|
65 |
cell1 = cha_cdr(cell1), j++) { |
|
66 |
/*
|
|
67 |
* name
|
|
68 |
*/
|
|
69 |
Cha_form[i][j].name = cha_strdup(cha_s_atom(cha_car(cell2))); |
|
70 |
if (!Cha_type[i].basic && |
|
71 |
(Cha_base_form_str |
|
72 |
? !strcmp(Cha_form[i][j].name, Cha_base_form_str) |
|
1.1.1
by NOKUBI Takatsugu
Import upstream version 2.3.3 |
73 |
: cha_litmatch(Cha_form[i][j].name, 2, |
74 |
STR_BASE_FORM1, STR_BASE_FORM2))) |
|
1
by NOKUBI Takatsugu
Import upstream version 2.2.9 |
75 |
Cha_type[i].basic = j; |
76 |
/*
|
|
77 |
* gobi
|
|
78 |
*/
|
|
79 |
if (strcmp |
|
80 |
(s = |
|
81 |
cha_s_atom(cha_car(cell2 = cha_cdr(cell2))), "*") == 0) |
|
82 |
Cha_form[i][j].gobi = ""; |
|
83 |
else { |
|
84 |
Cha_form[i][j].gobi = cha_strdup(s); |
|
85 |
Cha_form[i][j].gobi_len = strlen(s); |
|
86 |
}
|
|
87 |
/*
|
|
88 |
* ygobi
|
|
89 |
*/
|
|
90 |
if (nullp(cha_car(cell2 = cha_cdr(cell2)))) |
|
91 |
Cha_form[i][j].ygobi = Cha_form[i][j].gobi; |
|
92 |
else if (strcmp(s = cha_s_atom(cha_car(cell2)), "*") == 0) |
|
93 |
Cha_form[i][j].ygobi = ""; |
|
94 |
else { |
|
95 |
Cha_form[i][j].ygobi = cha_strdup(s); |
|
96 |
}
|
|
97 |
/*
|
|
98 |
* pgobi
|
|
99 |
*/
|
|
100 |
if (nullp(cha_car(cell2 = cha_cdr(cell2)))) |
|
101 |
Cha_form[i][j].pgobi = Cha_form[i][j].ygobi; |
|
102 |
else if (strcmp(s = cha_s_atom(cha_car(cell2)), "*") == 0) |
|
103 |
Cha_form[i][j].pgobi = ""; |
|
104 |
else { |
|
105 |
Cha_form[i][j].pgobi = cha_strdup(s); |
|
106 |
}
|
|
107 |
}
|
|
108 |
if (!Cha_type[i].basic) |
|
109 |
cha_exit_file(1, "no basic form"); |
|
110 |
}
|
|
111 |
}
|
|
112 |
||
113 |
/*
|
|
114 |
* cha_read_katuyou - read CFORM_FILE and set Cha_form[][]
|
|
115 |
*
|
|
116 |
* inputs:
|
|
117 |
* dir - 0: read from current directory
|
|
118 |
* 1: read from grammar directory
|
|
119 |
* 2: read from current directory or grammar directory
|
|
120 |
*/
|
|
121 |
void
|
|
122 |
cha_read_katuyou(FILE * fp_out, int dir) |
|
123 |
{
|
|
124 |
FILE *fp; |
|
125 |
char *filepath; |
|
126 |
||
127 |
fp = cha_fopen_grammar(CFORM_FILE, "r", 1, dir, &filepath); |
|
128 |
if (fp_out != NULL) |
|
129 |
fprintf(fp_out, "parsing %s\n", filepath); |
|
130 |
||
131 |
read_type_form(fp); |
|
132 |
||
133 |
fclose(fp); |
|
134 |
}
|