comparison src/kaigo/qtuti/95.go @ 61:49656dc40069

add qtuti.
author pyon@macmini
date Fri, 11 Sep 2020 20:06:27 +0900
parents
children
comparison
equal deleted inserted replaced
60:058fb0a2cda8 61:49656dc40069
1 /*
2 95.go: Qfuhi Tsuchi
3
4 Last Change: 2020-09-11 金 10:42:16.
5 */
6
7 package main
8
9 /*
10 #cgo LDFLAGS: -L. -lxdwapi -static
11 //
12 // 95.cpp: Qfuhi Tsuchi
13 // Last Change: 2020-09-08 火 15:20:43.
14 //
15
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <io.h>
20 #include <windows.h>
21 #include <xdw_api.h>
22 #include <xdwapian.h>
23
24 #define MAXCOL 1024
25 #define MAXLINE 9999
26 #define BLOCKSZ 128
27 #define ATN_N 20
28
29 char* xdw2txt(const char* file) {
30 char in_path[_MAX_PATH];
31 _fullpath(in_path, file, _MAX_PATH);
32
33 XDW_DOCUMENT_HANDLE h = NULL; // 文書ハンドルを開く
34 XDW_OPEN_MODE_EX mode = {sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_READONLY, XDW_AUTH_NODIALOGUE};
35 if (XDW_OpenDocumentHandle(in_path, &h, (XDW_OPEN_MODE*)&mode)) {
36 fprintf(stderr, "Error: cannot open %s\n", file);
37 return NULL;
38 }
39
40 XDW_DOCUMENT_INFO info = {sizeof(XDW_DOCUMENT_INFO), 0, 0, 0}; // 総ページ数を得る
41 XDW_GetDocumentInformation(h, &info);
42 int nPage = info.nPages;
43
44 // メイン処理
45 char *lpszvalue, *all_lpszvalue;
46 long datasize[9999];
47 for (int i=1; i<=nPage; i++) {
48 datasize[i] = XDW_GetPageTextToMemory(h, i, NULL, 0, NULL);
49 datasize[0] += datasize[i];
50 }
51 datasize[0] += nPage - 1; // for "\n"
52 all_lpszvalue = (char*)malloc(sizeof(char)*datasize[0]);
53 all_lpszvalue[0] = '\0';
54 for (int i = 1; i <= nPage; i++) {
55 if (i < nPage) datasize[i]++; // for "\n"
56 lpszvalue = (char*)malloc(sizeof(char)*(datasize[i]));
57 XDW_GetPageTextToMemory(h, i, lpszvalue, datasize[i], NULL);
58 strcat(all_lpszvalue, lpszvalue);
59 if (i < nPage) strcat(all_lpszvalue, "\n");
60 free(lpszvalue);
61 }
62
63 XDW_CloseDocumentHandle(h, NULL); // 文書ハンドルを閉じる
64 return all_lpszvalue;
65 }
66
67 void xdw2txtb(const char* xdwfile, const char* txtfile) {
68 char in_path[_MAX_PATH], out_path[_MAX_PATH];
69 _fullpath(in_path, xdwfile, _MAX_PATH);
70 _fullpath(out_path, txtfile, _MAX_PATH);
71
72 XDW_DOCUMENT_HANDLE h = NULL; // 文書ハンドルを開く
73 XDW_OPEN_MODE_EX mode = {sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_READONLY, XDW_AUTH_NODIALOGUE};
74 if (XDW_OpenDocumentHandle(in_path, &h, (XDW_OPEN_MODE*)&mode)) {
75 fprintf(stderr, "Error: cannot open %s\n", xdwfile);
76 return;
77 }
78
79 XDW_DOCUMENT_INFO info = {sizeof(XDW_DOCUMENT_INFO), 0, 0, 0}; // 総ページ数を得る
80 XDW_GetDocumentInformation(h, &info);
81 int nPage = info.nPages;
82
83 FILE *fp;
84 if ((fp = fopen(out_path, "w")) == NULL) {
85 fprintf(stderr, "Error: cannot open %s\n", out_path);
86 return;
87 }
88
89 long datasize;
90 char* lpszvalue;
91
92 for (int i = 1; i <= nPage; i++) {
93 datasize = XDW_GetPageTextToMemory(h, i, NULL, 0, NULL);
94 lpszvalue = (char*)malloc(sizeof(char)*datasize);
95 XDW_GetPageTextToMemory(h, i, lpszvalue, datasize, NULL);
96 fprintf(fp, "%s\n", lpszvalue);
97 free(lpszvalue);
98 }
99
100 fclose(fp);
101 XDW_CloseDocumentHandle(h, NULL); // 文書ハンドルを閉じる
102 return;
103 }
104
105 int xdwsplit1(const char* file, const char* workdir, const char* prefix) {
106 char file_path[_MAX_PATH];
107 _fullpath(file_path, file, _MAX_PATH);
108
109 XDW_DOCUMENT_HANDLE h = NULL;
110 XDW_OPEN_MODE_EX mode = {sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_READONLY, XDW_AUTH_NODIALOGUE};
111 if (XDW_OpenDocumentHandle(file_path, &h, (XDW_OPEN_MODE*)&mode)) {
112 fprintf(stderr, "Error: cannot open %s\n", file);
113 return -1;
114 }
115
116 XDW_DOCUMENT_INFO info = {sizeof(XDW_DOCUMENT_INFO), 0, 0, 0};
117 XDW_GetDocumentInformation(h, &info);
118 int nPage = info.nPages;
119
120 char buf[_MAX_PATH];
121 for (int i = 1; i <= nPage; i++) {
122 sprintf(buf, "%s/%s%05d.xdw", workdir, prefix, i);
123 //sprintf(buf, "%s_%05d.xdw", prefix, i);
124 _fullpath(file_path, buf, _MAX_PATH);
125
126 int api_result = XDW_GetPage(h, i, file_path, NULL);
127 if (api_result < 0) {
128 fprintf(stderr, "XDW Error: cannot get page (%s p=%d)\n", file, i);
129 return -1;
130 }
131 }
132
133 XDW_CloseDocumentHandle(h, NULL);
134 return 0;
135 }
136
137 int xdwextpage(const char* infile, const int p, const char* outfile) {
138 char file_path[_MAX_PATH];
139 _fullpath(file_path, infile, _MAX_PATH);
140
141 XDW_DOCUMENT_HANDLE h = NULL;
142 XDW_OPEN_MODE_EX mode = {sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_READONLY, XDW_AUTH_NODIALOGUE};
143 if (XDW_OpenDocumentHandle(file_path, &h, (XDW_OPEN_MODE*)&mode)) {
144 fprintf(stderr, "Error: cannot open %s\n", infile);
145 return -1;
146 }
147
148 XDW_DOCUMENT_INFO info = {sizeof(XDW_DOCUMENT_INFO), 0, 0, 0};
149 XDW_GetDocumentInformation(h, &info);
150 int nPage = info.nPages;
151
152 char buf[_MAX_PATH];
153 _fullpath(file_path, outfile, _MAX_PATH);
154
155 int api_result = XDW_GetPage(h, p, file_path, NULL);
156 if (api_result < 0) {
157 fprintf(stderr, "XDW Error: cannot get page (%s p=%d)\n", infile, p);
158 return -1;
159 }
160
161 XDW_CloseDocumentHandle(h, NULL);
162 return 0;
163 }
164
165 void xdwmerge(const char* list, const char* output) {
166 FILE *fp;
167
168 if ((fp = fopen(list, "r")) == NULL) {
169 fprintf(stderr, "XDW Error: can't open file [%s]\n", list);
170 exit(1);
171 }
172
173 char *all_path = (char*)malloc(MAXLINE * sizeof(char) * _MAX_PATH);
174
175 if (all_path == NULL) {
176 fprintf(stderr, "XDW Error: can't allocate memory\n");
177 exit(1);
178 }
179
180 int n = 0;
181 char *q;
182 char buf[_MAX_PATH];
183
184 while (fgets(buf, sizeof buf, fp)) {
185 if ((q = strchr(buf, '\n')) != NULL) {
186 *q = '\0';
187 }
188 _fullpath(buf, buf, _MAX_PATH);
189 strncpy(&all_path[n * _MAX_PATH], buf, _MAX_PATH);
190 n++;
191 }
192 fclose(fp);
193
194 char *blk_path = (char*)malloc(BLOCKSZ * sizeof(char) * _MAX_PATH);
195 const char **blk_path_addr = (const char**)malloc((n / BLOCKSZ + 1) * sizeof(char*) * _MAX_PATH);
196 if (blk_path == NULL || blk_path_addr == NULL) {
197 fprintf(stderr, "XDW Error: can't allocate memory\n");
198 exit(1);
199 }
200
201 // process by block
202 int api_result;
203 int bn = 0;
204 for (int p = 0, m = 0; p < n; p++) {
205 m = p % BLOCKSZ;
206 if (m == 0 && p > 0) {
207 sprintf(buf, "tmp_b%04d.xdw", ++bn);
208 _fullpath(buf, buf, _MAX_PATH);
209 api_result = XDW_MergeXdwFiles(blk_path_addr, BLOCKSZ, buf, NULL);
210 if (api_result < 0) {
211 fprintf(stderr, "XDW Error: can't merge [1] (p = %d, m = %d)\n", p, m);
212 exit(1);
213 }
214 }
215 strncpy(&blk_path[m * _MAX_PATH], &all_path[p * _MAX_PATH], _MAX_PATH);
216 blk_path_addr[m] = &blk_path[m * _MAX_PATH];
217 }
218
219 sprintf(buf, "tmp_b%04d.xdw", ++bn);
220 _fullpath(buf, buf, _MAX_PATH);
221
222 int mod = n % BLOCKSZ;
223 if (mod == 0) mod = BLOCKSZ;
224 api_result = XDW_MergeXdwFiles(blk_path_addr, mod, buf, NULL);
225
226 if (api_result < 0) {
227 fprintf(stderr, "XDW Error: can't merge [2]\n");
228 exit(1);
229 }
230
231 // merge blocks
232 for (int b = 0; b < bn; b++) {
233 sprintf(buf, "tmp_b%04d.xdw", b + 1);
234 _fullpath(buf, buf, _MAX_PATH);
235 strncpy(&blk_path[b * _MAX_PATH], buf, _MAX_PATH);
236 blk_path_addr[b] = &blk_path[b * _MAX_PATH];
237 }
238
239 _fullpath(buf, output, _MAX_PATH );
240 api_result = XDW_MergeXdwFiles(blk_path_addr, bn, buf, NULL);
241
242 if (api_result < 0) {
243 fprintf(stderr, "XDW Error: can't merge [3]\n");
244 exit(1);
245 }
246
247 free(all_path);
248 free(blk_path);
249 free(blk_path_addr);
250
251 for (int b = 0; b < bn; b++) {
252 sprintf(buf, "tmp_b%04d.xdw", b + 1);
253 _fullpath(buf, buf, _MAX_PATH);
254 remove(buf);
255 }
256 }
257
258 int xdwaddatn(const char* xdwfile, const char* atnfile) {
259 FILE *fp;
260 char filepath[_MAX_PATH];
261 _fullpath(filepath, atnfile, _MAX_PATH);
262
263 if ((fp = fopen(filepath, "r")) == NULL) {
264 fprintf(stderr, "Error: cannot open %s\n", filepath);
265 return -1;
266 }
267
268 char keyword[128];
269 char *q;
270 fgets(keyword, sizeof keyword, fp);
271 if ((q = strchr(keyword, '\n')) != NULL) {
272 *q = '\0';
273 }
274
275 char buf[_MAX_PATH];
276 int x[ATN_N], y[ATN_N], sz[ATN_N], tr[ATN_N];
277 char txt[ATN_N][256];
278 int an = 0;
279 while (fgets(buf, sizeof buf, fp)) {
280 if ((q = strchr(buf, '\n')) != NULL) {
281 *q = '\0';
282 }
283
284 x[an] = atoi(strtok(buf, ","));
285 y[an] = atoi(strtok(NULL, ","));
286 sz[an] = atoi(strtok(NULL, ","));
287 tr[an] = atoi(strtok(NULL, ","));
288 strcpy(txt[an], strtok(NULL, ","));
289 an++;
290 //printf("x=%d y=%d txt=%s sz=%d tr=%d\n", x[an], y[an], txt[an], sz[an], tr[an]);
291 }
292 fclose(fp);
293
294
295 XDW_DOCUMENT_HANDLE h = NULL;
296 XDW_OPEN_MODE_EX mode = {sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_UPDATE, XDW_AUTH_NODIALOGUE};
297
298 _fullpath(filepath, xdwfile, _MAX_PATH);
299 int api_result = XDW_OpenDocumentHandle(filepath, &h, (XDW_OPEN_MODE*)&mode);
300 if (api_result < 0) return api_result;
301
302 XDW_DOCUMENT_INFO info = {sizeof(XDW_DOCUMENT_INFO), 0, 0, 0};
303 XDW_GetDocumentInformation(h, &info);
304 XDW_FOUND_HANDLE pFoundHandle = NULL;
305 for (int i = 0; i < info.nPages; i++) {
306 if (keyword[0] != '\0') {
307 api_result = XDW_FindTextInPage(h, i + 1, keyword, NULL, &pFoundHandle, NULL);
308 if (!pFoundHandle) {
309 XDW_CloseFoundHandle(pFoundHandle);
310 continue;
311 }
312 XDW_CloseFoundHandle(pFoundHandle);
313 }
314 for (int j = 0; j < an; j++ ) {
315 XDW_ANNOTATION_HANDLE annoation;
316 int api_result = XDW_AddAnnotation(h, XDW_AID_TEXT, i + 1, x[j], y[j], NULL, &annoation, NULL);
317 if (api_result < 0) return api_result;
318
319 api_result = XDW_SetAnnotationAttribute(h, annoation, XDW_ATN_Text, XDW_ATYPE_STRING, txt[j], 0, NULL);
320 api_result = XDW_SetAnnotationAttribute(h, annoation, XDW_ATN_FontSize, XDW_ATYPE_INT, (char*)&sz[j], 0, NULL);
321
322 int color = XDW_COLOR_WHITE;
323 if (tr[j]) {
324 color = XDW_COLOR_NONE;
325 }
326 api_result = XDW_SetAnnotationAttribute(h, annoation, XDW_ATN_BackColor, XDW_ATYPE_INT, (char*)&color, 0, NULL);
327 }
328 }
329
330 XDW_SaveDocument(h, NULL);
331 XDW_CloseDocumentHandle(h, NULL);
332
333 return 0;
334 }
335
336 int xdwaddatntool(const char* xdwfile, const char* toolfile, int n, int x, int y) {
337 char filepath[_MAX_PATH];
338 _fullpath(filepath, xdwfile, _MAX_PATH);
339
340 XDW_DOCUMENT_HANDLE h = NULL;
341 XDW_OPEN_MODE_EX mode = {sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_UPDATE, XDW_AUTH_NODIALOGUE};
342
343 int api_result = XDW_OpenDocumentHandle(filepath, &h, (XDW_OPEN_MODE*)&mode);
344 if (api_result < 0) return api_result;
345
346 XDW_DOCUMENT_INFO info = {sizeof(XDW_DOCUMENT_INFO), 0, 0, 0};
347 XDW_GetDocumentInformation(h, &info);
348
349 _fullpath(filepath, toolfile, _MAX_PATH);
350 for (int i = 0; i < info.nPages; i++) {
351 XDW_ANNOTATION_HANDLE annoation;
352 int api_result = XDW_AddAnnotationFromAnnFile(h, filepath, n, i + 1, NULL, x, y, &annoation, NULL);
353 }
354
355 XDW_SaveDocument(h, NULL);
356 XDW_CloseDocumentHandle(h, NULL);
357
358 return 0;
359 }
360
361
362 */
363 import "C"
364
365 import (
366 "bufio"
367 "regexp"
368 "encoding/json"
369 "flag"
370 "fmt"
371 "io/ioutil"
372 "log"
373 "os"
374 "path/filepath"
375 "sort"
376 "strings"
377
378 "golang.org/x/text/encoding/japanese"
379 "golang.org/x/text/transform"
380 )
381
382 type Hhs struct {
383 No string
384 Name string
385 Page int // sinsei page
386 Tsuchi bool
387 Kaigo string
388 Xdw []string
389 }
390
391 func(h *Hhs) AppendXdw(xdw string) {
392 h.Xdw = append(h.Xdw, xdw)
393 }
394
395 func(h *Hhs) CsvString() string {
396 q := ""
397 if h.Tsuchi {
398 q = "○"
399 }
400 k := strings.Split(h.Kaigo, "")
401 return strings.Join([]string{h.No, h.Name, q, k[1] + k[3]}, ",")
402 }
403
404 func(h *Hhs) Dump() string {
405 q := "false"
406 if h.Tsuchi {
407 q = "true"
408 }
409 p := fmt.Sprintf("%05d", h.Page)
410 x := strings.Join(h.Xdw, ",")
411 return strings.Join([]string{h.No, h.Name, q, h.Kaigo, p, x}, ",")
412 }
413
414 type Config struct {
415 Indir string
416 Outdir string
417 Workdir string
418 Hhsdb string
419 Atnfile[] string
420 }
421
422 var (
423 ver = "0.1"
424 conf Config
425 confjson = "95.json"
426 logfile = "95.log"
427 osirase = "KBPA316G.xdw"
428 sinsei = "KBPA406G.xdw"
429 rule_s = "rules.ann"
430
431 out_o = "o.xdw"
432 out_s = "s.xdw"
433 out_q = "q.xdw"
434 out_l = "l.csv"
435
436 re_hhsno, re_name, re_kaigo *regexp.Regexp
437
438 // option parameters
439 version bool
440 )
441
442 func init() {
443 /* コンフィグファイルは JSON */
444 content, err := ioutil.ReadFile(confjson)
445 if err != nil {
446 log.Fatal(err)
447 }
448 if err := json.Unmarshal(content, &conf); err != nil {
449 log.Fatal(err)
450 }
451
452 osirase = filepath.Join(conf.Indir, osirase)
453 sinsei = filepath.Join(conf.Indir, sinsei)
454
455 out_o = filepath.Join(conf.Outdir, out_o)
456 out_s = filepath.Join(conf.Outdir, out_s)
457 out_q = filepath.Join(conf.Outdir, out_q)
458 out_l = filepath.Join(conf.Outdir, out_l)
459
460 logfile = filepath.Join(conf.Workdir, logfile)
461
462 /* 一時ファイル消去 */
463 os.RemoveAll(conf.Outdir)
464 os.RemoveAll(conf.Workdir)
465 os.Mkdir(conf.Outdir, 0755)
466 os.Mkdir(conf.Workdir, 0755)
467
468 /* 変数初期化 */
469 re_hhsno = regexp.MustCompile(`0[1238]00\d{6}`)
470 re_name = regexp.MustCompile(`日.{30}`)
471 re_kaigo = regexp.MustCompile(`要((介護)|(支援)).`)
472
473 flag.BoolVar(&version, "v", false, "print version")
474 }
475
476 func main() {
477 flag.Parse()
478
479 if version {
480 fmt.Println("95 - version", ver)
481 os.Exit(0)
482 }
483
484 hash_Hhs := make(map[string]Hhs)
485
486 /* 申請書を漁り,構造体を初期化 */
487 for p, t := range xdw2txt(sinsei) {
488 hno := re_hhsno.FindString(t)
489 name := re_name.FindString(t)
490 name = strings.Replace(name, "日", "", 1)
491 kaigo := re_kaigo.FindString(t)
492 o := fmt.Sprintf("o_%05d.xdw", p + 1)
493 s := fmt.Sprintf("s_%05d.xdw", p + 1)
494 h := Hhs{No: hno, Name: name, Kaigo: kaigo, Page:p + 1, Xdw: []string{o, s}}
495 hash_Hhs[hno] = h
496 }
497
498 /* バックグラウンドで給付費通知から勧奨対象者を抽出 */
499 ch := make(chan int)
500 go func() {
501 files, err := ioutil.ReadDir(conf.Indir)
502 if err != nil {
503 log.Fatal(err)
504 }
505
506 qn := 1
507 for _, file := range files {
508 if !strings.HasSuffix(file.Name(), ".xdw") {
509 continue
510 }
511 if strings.HasPrefix(file.Name(), "KDPK016G") || strings.HasPrefix(file.Name(), "KDPK126G") {
512 qtsuchi := filepath.Join(conf.Indir, file.Name())
513 tmptxt := filepath.Join(conf.Workdir, "tmp95.txt")
514 for p, t := range xdw2txtb(qtsuchi, tmptxt) {
515 hno := re_hhsno.FindString(t)
516 if h, ok := hash_Hhs[hno]; ok {
517 h.Tsuchi = true
518 q := fmt.Sprintf("q_%05d.xdw", qn)
519 h.AppendXdw(q)
520 hash_Hhs[hno] = h
521 q = filepath.Join(conf.Workdir, q)
522 C.xdwextpage(C.CString(qtsuchi), C.int(p + 1), C.CString(q))
523 qn++
524 //fmt.Println(qtsuchi, p, hno, h.Kaigo, h.Xdw)
525 }
526 }
527 }
528 }
529
530 ch <- 1
531 }()
532
533 /* そのあいだにバラす */
534 C.xdwsplit1(C.CString(osirase), C.CString(conf.Workdir), C.CString("o_"))
535 C.xdwsplit1(C.CString(sinsei), C.CString(conf.Workdir), C.CString("s_"))
536 <-ch
537
538 /* ソート & マージ */
539 var slice_Hhs []Hhs
540 for _, h := range hash_Hhs {
541 slice_Hhs = append(slice_Hhs, h)
542 }
543 sort.Slice(slice_Hhs, func(i, j int) bool {
544 if slice_Hhs[i].Tsuchi != slice_Hhs[j].Tsuchi {
545 return slice_Hhs[i].Tsuchi
546 }
547 if slice_Hhs[i].Kaigo != slice_Hhs[j].Kaigo {
548 return slice_Hhs[i].Kaigo < slice_Hhs[j].Kaigo
549 }
550 if slice_Hhs[i].Page != slice_Hhs[j].Page {
551 return slice_Hhs[i].Page < slice_Hhs[j].Page
552 }
553 return false
554 })
555
556 var list_o, list_s, list_q []string
557 for _, h := range slice_Hhs {
558 list_o = append(list_o, filepath.Join(conf.Workdir, h.Xdw[0]))
559 list_s = append(list_s, filepath.Join(conf.Workdir, h.Xdw[1]))
560 if h.Tsuchi {
561 for i, x := range h.Xdw {
562 if i > 1 {
563 buf := filepath.Join(conf.Workdir, x)
564 list_q = append(list_q, buf)
565 }
566 }
567 }
568 }
569 xdwmerge(list_o, out_o)
570 xdwmerge(list_s, out_s)
571 xdwmerge(list_q, out_q)
572
573 /* リスト出力 & ログダンプ */
574 csvtxt := ""
575 logtxt := ""
576 for _, h := range slice_Hhs {
577 csvtxt += h.CsvString() + "\n"
578 logtxt += h.Dump() + "\n"
579 }
580 csvtxt, _, _ = transform.String(japanese.ShiftJIS.NewEncoder(), csvtxt)
581 if err := ioutil.WriteFile(out_l, []byte(csvtxt), 0644); err != nil {
582 log.Fatal(err)
583 }
584 if err := ioutil.WriteFile(logfile, []byte(logtxt), 0644); err != nil {
585 log.Fatal(err)
586 }
587
588 /* バックグラウンドで給付費通知を校正 */
589 ch2 := make(chan int)
590 go func() {
591 for _, a := range conf.Atnfile {
592 xdwaddatn(out_q, a)
593 }
594 ch2 <- 1
595 } ()
596
597 /* そのあいだに申請書に枠付け */
598 xdwaddatntool(out_s, rule_s, 2, 1497, 803)
599 <-ch2
600 }
601
602 func xdw2txt(file string) (txt []string) {
603 s := C.GoString(C.xdw2txt(C.CString(file)))
604 r := strings.NewReader(s)
605 tr := transform.NewReader(r, japanese.ShiftJIS.NewDecoder())
606 buf := bufio.NewScanner(tr)
607 for buf.Scan() {
608 txt = append(txt, buf.Text())
609 }
610 return
611 }
612
613 func xdw2txtb(xdwfile, txtfile string) (txt []string) {
614 if _, err := os.Stat(txtfile); os.IsExist(err) {
615 os.Remove(txtfile)
616 }
617
618 C.xdw2txtb(C.CString(xdwfile), C.CString(txtfile))
619 content, err := ioutil.ReadFile(txtfile)
620 if err != nil {
621 return nil
622 }
623
624 r := strings.NewReader(string(content))
625 tr := transform.NewReader(r, japanese.ShiftJIS.NewDecoder())
626 buf := bufio.NewScanner(tr)
627 for buf.Scan() {
628 txt = append(txt, buf.Text())
629 }
630 return
631 }
632
633 func xdwmerge(list []string, outfile string) (err error) {
634 order := strings.Join(list, "\n")
635 order, _, _ = transform.String(japanese.ShiftJIS.NewEncoder(), order)
636 orderfile := filepath.Join(conf.Workdir, "order95.txt")
637 if err := ioutil.WriteFile(orderfile, []byte(order), 0644); err != nil {
638 return err
639 }
640 C.xdwmerge(C.CString(orderfile), C.CString(outfile))
641 return nil
642 }
643
644 func xdwaddatn(xdwfile, atnfile string) (err error) {
645 C.xdwaddatn(C.CString(xdwfile), C.CString(atnfile))
646 return nil
647 }
648
649 func xdwaddatntool(xdwfile, toolfile string, n, x, y int) (err error) {
650 C.xdwaddatntool(C.CString(xdwfile), C.CString(toolfile), C.int(n), C.int(x), C.int(y))
651 return nil
652 }
653