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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
$NetBSD: patch-ag,v 1.1.1.1 2002/05/31 12:59:58 seb Exp $
--- jisyo-tools/skkdic-expr.c.orig Tue Dec 17 14:51:28 1996
+++ jisyo-tools/skkdic-expr.c Mon Nov 6 01:34:22 2000
@@ -78,59 +78,86 @@
}
}
+#if !defined(dbm_pagfno) || defined(DBM_SUFFIX)
+#define NEW_DB
+#endif
+
/* 作業用データベースファイルを削除
file_name には content が格納される */
static void db_remove_files()
{
- char pag_name[256];
- char dir_name[256];
+ char db_name[256];
db_remove_file(file_name);
- sprintf(pag_name, "%s.pag", file_name);
- db_remove_file(pag_name);
- sprintf(dir_name, "%s.dir", file_name);
- db_remove_file(dir_name);
+#ifdef NEW_DB
+ sprintf(db_name, "%s.db", file_name);
+ db_remove_file(db_name);
+#else
+ sprintf(db_name, "%s.pag", file_name);
+ db_remove_file(db_name);
+ sprintf(db_name, "%s.dir", file_name);
+ db_remove_file(db_name);
+#endif
if (okurigana_flag) {
db_remove_file(okuri_head_name);
- sprintf(pag_name, "%s.pag", okuri_head_name);
- db_remove_file(pag_name);
- sprintf(dir_name, "%s.dir", okuri_head_name);
- db_remove_file(dir_name);
+#ifdef NEW_DB
+ sprintf(db_name, "%s.db", okuri_head_name);
+ db_remove_file(db_name);
+#else
+ sprintf(db_name, "%s.pag", okuri_head_name);
+ db_remove_file(db_name);
+ sprintf(db_name, "%s.dir", okuri_head_name);
+ db_remove_file(db_name);
+#endif
db_remove_file(okuri_tail_name);
- sprintf(pag_name, "%s.pag", okuri_tail_name);
- db_remove_file(pag_name);
- sprintf(dir_name, "%s.dir", okuri_tail_name);
- db_remove_file(dir_name);
+#ifdef NEW_DB
+ sprintf(db_name, "%s.db", okuri_tail_name);
+ db_remove_file(db_name);
+#else
+ sprintf(db_name, "%s.pag", okuri_tail_name);
+ db_remove_file(db_name);
+ sprintf(db_name, "%s.dir", okuri_tail_name);
+ db_remove_file(db_name);
+#endif
}
}
+#ifndef O_EXCL
+#define O_EXCL 0
+#endif
+
/* データベースファイルを作成 */
-static void db_make_files()
+static void db_make_files(tmpdir)
+ char *tmpdir;
{
- sprintf(file_name, "/tmp/skkjisyo.%d", getpid());
+ int pid = getpid();
+ int fd;
+
+ sprintf(file_name, "%s/skkjisyo.%d", tmpdir, pid);
if (okurigana_flag) {
- sprintf(okuri_head_name, "/tmp/skkhead.%d", getpid());
- sprintf(okuri_tail_name, "/tmp/skktail.%d", getpid());
+ sprintf(okuri_head_name, "%s/skkhead.%d", tmpdir, pid);
+ sprintf(okuri_tail_name, "%s/skktail.%d", tmpdir, pid);
}
db_remove_files();
- if ((db = dbm_open(file_name, O_RDWR|O_CREAT, 0600)) == NULL){
+ if ((db = dbm_open(file_name, O_RDWR|O_CREAT|O_EXCL, 0600)) == NULL){
perror(file_name);
exit(1);
}
- if ((dbcontent = fopen(file_name, "w+")) == NULL){
+ if ((fd = open(file_name, O_RDWR|O_CREAT|O_EXCL, 0600)) < 0 ||
+ (dbcontent = fdopen(fd, "w+")) == NULL){
perror(file_name);
exit(1);
}
if (okurigana_flag) {
- if ((okuriheaddb = dbm_open(okuri_head_name, O_RDWR|O_CREAT, 0600))
+ if ((okuriheaddb = dbm_open(okuri_head_name, O_RDWR|O_CREAT|O_EXCL, 0600))
== NULL){
perror(okuri_head_name);
exit(1);
}
- if ((okuritaildb = dbm_open(okuri_tail_name, O_RDWR|O_CREAT, 0600))
+ if ((okuritaildb = dbm_open(okuri_tail_name, O_RDWR|O_CREAT|O_EXCL, 0600))
== NULL){
perror(okuri_tail_name);
exit(1);
@@ -698,7 +725,7 @@
for (key = dbm_firstkey(db); key.dptr != NULL; key = dbm_nextkey(db)) {
content = dbm_fetch(db, key);
for(i = 0; i < key.dsize; ++ i)
- putc((key.dptr)[i], output);
+ putc(((char *) key.dptr)[i], output);
putc(' ', output);
fseek(dbcontent, getpos(content.dptr), 0);
db_gets(kanji, BLEN, dbcontent);
@@ -716,7 +743,7 @@
if (entry.dptr != NULL) continue;
for(i = 0; i < key.dsize; ++ i)
- putc((key.dptr)[i], output);
+ putc(((char *) key.dptr)[i], output);
putc(' ', output);
putc('/', output);
okuri_type_out(&key, output);
@@ -775,9 +802,8 @@
exit(1);
}
- sprintf(file_name, "%s/skkjisyo.%d", tmpdir, getpid());
set_signal_handler();
- db_make_files();
+ db_make_files(tmpdir);
negate = 0;
for (; i < argc; ++ i) {
|