Mercurial > mercurial > hgweb_golang.cgi
comparison src/kaigo/qtuti/95y/95y_tmpl.cpp @ 65:0369656be06c default tip
many changes.
author | pyon@macmini |
---|---|
date | Fri, 20 May 2022 06:30:34 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
64:ad5c30ee5cf1 | 65:0369656be06c |
---|---|
1 // | |
2 // 95.cpp: Qfuhi Tsuchi | |
3 // Last Change: 2020-09-08 火 15:20:43. | |
4 // | |
5 | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <io.h> | |
10 #include <windows.h> | |
11 #include <xdw_api.h> | |
12 #include <xdwapian.h> | |
13 | |
14 #define MAXCOL 1024 | |
15 #define MAXLINE 9999 | |
16 #define BLOCKSZ 128 | |
17 #define ATN_N 20 | |
18 | |
19 char* xdw2txt(const char* file) { | |
20 char in_path[_MAX_PATH]; | |
21 _fullpath(in_path, file, _MAX_PATH); | |
22 | |
23 XDW_DOCUMENT_HANDLE h = NULL; // 文書ハンドルを開く | |
24 XDW_OPEN_MODE_EX mode = {sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_READONLY, XDW_AUTH_NODIALOGUE}; | |
25 if (XDW_OpenDocumentHandle(in_path, &h, (XDW_OPEN_MODE*)&mode)) { | |
26 fprintf(stderr, "Error: cannot open %s\n", file); | |
27 return NULL; | |
28 } | |
29 | |
30 XDW_DOCUMENT_INFO info = {sizeof(XDW_DOCUMENT_INFO), 0, 0, 0}; // 総ページ数を得る | |
31 XDW_GetDocumentInformation(h, &info); | |
32 int nPage = info.nPages; | |
33 | |
34 // メイン処理 | |
35 char *lpszvalue, *all_lpszvalue; | |
36 long datasize[9999]; | |
37 for (int i=1; i<=nPage; i++) { | |
38 datasize[i] = XDW_GetPageTextToMemory(h, i, NULL, 0, NULL); | |
39 datasize[0] += datasize[i]; | |
40 } | |
41 datasize[0] += nPage - 1; // for "\n" | |
42 all_lpszvalue = (char*)malloc(sizeof(char)*datasize[0]); | |
43 all_lpszvalue[0] = '\0'; | |
44 for (int i = 1; i <= nPage; i++) { | |
45 if (i < nPage) datasize[i]++; // for "\n" | |
46 lpszvalue = (char*)malloc(sizeof(char)*(datasize[i])); | |
47 XDW_GetPageTextToMemory(h, i, lpszvalue, datasize[i], NULL); | |
48 strcat(all_lpszvalue, lpszvalue); | |
49 if (i < nPage) strcat(all_lpszvalue, "\n"); | |
50 free(lpszvalue); | |
51 } | |
52 | |
53 XDW_CloseDocumentHandle(h, NULL); // 文書ハンドルを閉じる | |
54 return all_lpszvalue; | |
55 } | |
56 | |
57 void xdw2txtb(const char* xdwfile, const char* txtfile) { | |
58 char in_path[_MAX_PATH], out_path[_MAX_PATH]; | |
59 _fullpath(in_path, xdwfile, _MAX_PATH); | |
60 _fullpath(out_path, txtfile, _MAX_PATH); | |
61 | |
62 XDW_DOCUMENT_HANDLE h = NULL; // 文書ハンドルを開く | |
63 XDW_OPEN_MODE_EX mode = {sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_READONLY, XDW_AUTH_NODIALOGUE}; | |
64 if (XDW_OpenDocumentHandle(in_path, &h, (XDW_OPEN_MODE*)&mode)) { | |
65 fprintf(stderr, "Error: cannot open %s\n", xdwfile); | |
66 return; | |
67 } | |
68 | |
69 XDW_DOCUMENT_INFO info = {sizeof(XDW_DOCUMENT_INFO), 0, 0, 0}; // 総ページ数を得る | |
70 XDW_GetDocumentInformation(h, &info); | |
71 int nPage = info.nPages; | |
72 | |
73 FILE *fp; | |
74 if ((fp = fopen(out_path, "w")) == NULL) { | |
75 fprintf(stderr, "Error: cannot open %s\n", out_path); | |
76 return; | |
77 } | |
78 | |
79 long datasize; | |
80 char* lpszvalue; | |
81 | |
82 for (int i = 1; i <= nPage; i++) { | |
83 datasize = XDW_GetPageTextToMemory(h, i, NULL, 0, NULL); | |
84 lpszvalue = (char*)malloc(sizeof(char)*datasize); | |
85 XDW_GetPageTextToMemory(h, i, lpszvalue, datasize, NULL); | |
86 fprintf(fp, "%s\n", lpszvalue); | |
87 free(lpszvalue); | |
88 } | |
89 | |
90 fclose(fp); | |
91 XDW_CloseDocumentHandle(h, NULL); // 文書ハンドルを閉じる | |
92 return; | |
93 } | |
94 | |
95 int xdwsplit1(const char* file, const char* workdir, const char* prefix) { | |
96 char file_path[_MAX_PATH]; | |
97 _fullpath(file_path, file, _MAX_PATH); | |
98 | |
99 XDW_DOCUMENT_HANDLE h = NULL; | |
100 XDW_OPEN_MODE_EX mode = {sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_READONLY, XDW_AUTH_NODIALOGUE}; | |
101 if (XDW_OpenDocumentHandle(file_path, &h, (XDW_OPEN_MODE*)&mode)) { | |
102 fprintf(stderr, "Error: cannot open %s\n", file); | |
103 return -1; | |
104 } | |
105 | |
106 XDW_DOCUMENT_INFO info = {sizeof(XDW_DOCUMENT_INFO), 0, 0, 0}; | |
107 XDW_GetDocumentInformation(h, &info); | |
108 int nPage = info.nPages; | |
109 | |
110 char buf[_MAX_PATH]; | |
111 for (int i = 1; i <= nPage; i++) { | |
112 sprintf(buf, "%s/%s%05d.xdw", workdir, prefix, i); | |
113 //sprintf(buf, "%s_%05d.xdw", prefix, i); | |
114 _fullpath(file_path, buf, _MAX_PATH); | |
115 | |
116 int api_result = XDW_GetPage(h, i, file_path, NULL); | |
117 if (api_result < 0) { | |
118 fprintf(stderr, "XDW Error: cannot get page (%s p=%d)\n", file, i); | |
119 return -1; | |
120 } | |
121 } | |
122 | |
123 XDW_CloseDocumentHandle(h, NULL); | |
124 return 0; | |
125 } | |
126 | |
127 int xdwextpage(const char* infile, const int p, const char* outfile) { | |
128 char file_path[_MAX_PATH]; | |
129 _fullpath(file_path, infile, _MAX_PATH); | |
130 | |
131 XDW_DOCUMENT_HANDLE h = NULL; | |
132 XDW_OPEN_MODE_EX mode = {sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_READONLY, XDW_AUTH_NODIALOGUE}; | |
133 if (XDW_OpenDocumentHandle(file_path, &h, (XDW_OPEN_MODE*)&mode)) { | |
134 fprintf(stderr, "Error: cannot open %s\n", infile); | |
135 return -1; | |
136 } | |
137 | |
138 XDW_DOCUMENT_INFO info = {sizeof(XDW_DOCUMENT_INFO), 0, 0, 0}; | |
139 XDW_GetDocumentInformation(h, &info); | |
140 int nPage = info.nPages; | |
141 | |
142 char buf[_MAX_PATH]; | |
143 _fullpath(file_path, outfile, _MAX_PATH); | |
144 | |
145 int api_result = XDW_GetPage(h, p, file_path, NULL); | |
146 if (api_result < 0) { | |
147 fprintf(stderr, "XDW Error: cannot get page (%s p=%d)\n", infile, p); | |
148 return -1; | |
149 } | |
150 | |
151 XDW_CloseDocumentHandle(h, NULL); | |
152 return 0; | |
153 } | |
154 | |
155 void xdwmerge(const char* list, const char* output) { | |
156 FILE *fp; | |
157 | |
158 if ((fp = fopen(list, "r")) == NULL) { | |
159 fprintf(stderr, "XDW Error: can't open file [%s]\n", list); | |
160 exit(1); | |
161 } | |
162 | |
163 char *all_path = (char*)malloc(MAXLINE * sizeof(char) * _MAX_PATH); | |
164 | |
165 if (all_path == NULL) { | |
166 fprintf(stderr, "XDW Error: can't allocate memory\n"); | |
167 exit(1); | |
168 } | |
169 | |
170 int n = 0; | |
171 char *q; | |
172 char buf[_MAX_PATH]; | |
173 | |
174 while (fgets(buf, sizeof buf, fp)) { | |
175 if ((q = strchr(buf, '\n')) != NULL) { | |
176 *q = '\0'; | |
177 } | |
178 _fullpath(buf, buf, _MAX_PATH); | |
179 strncpy(&all_path[n * _MAX_PATH], buf, _MAX_PATH); | |
180 n++; | |
181 } | |
182 fclose(fp); | |
183 | |
184 char *blk_path = (char*)malloc(BLOCKSZ * sizeof(char) * _MAX_PATH); | |
185 const char **blk_path_addr = (const char**)malloc((n / BLOCKSZ + 1) * sizeof(char*) * _MAX_PATH); | |
186 if (blk_path == NULL || blk_path_addr == NULL) { | |
187 fprintf(stderr, "XDW Error: can't allocate memory\n"); | |
188 exit(1); | |
189 } | |
190 | |
191 // process by block | |
192 int api_result; | |
193 int bn = 0; | |
194 for (int p = 0, m = 0; p < n; p++) { | |
195 m = p % BLOCKSZ; | |
196 if (m == 0 && p > 0) { | |
197 sprintf(buf, "tmp_b%04d.xdw", ++bn); | |
198 _fullpath(buf, buf, _MAX_PATH); | |
199 api_result = XDW_MergeXdwFiles(blk_path_addr, BLOCKSZ, buf, NULL); | |
200 if (api_result < 0) { | |
201 fprintf(stderr, "XDW Error: can't merge [1] (p = %d, m = %d)\n", p, m); | |
202 exit(1); | |
203 } | |
204 } | |
205 strncpy(&blk_path[m * _MAX_PATH], &all_path[p * _MAX_PATH], _MAX_PATH); | |
206 blk_path_addr[m] = &blk_path[m * _MAX_PATH]; | |
207 } | |
208 | |
209 sprintf(buf, "tmp_b%04d.xdw", ++bn); | |
210 _fullpath(buf, buf, _MAX_PATH); | |
211 | |
212 int mod = n % BLOCKSZ; | |
213 if (mod == 0) mod = BLOCKSZ; | |
214 api_result = XDW_MergeXdwFiles(blk_path_addr, mod, buf, NULL); | |
215 | |
216 if (api_result < 0) { | |
217 fprintf(stderr, "XDW Error: can't merge [2]\n"); | |
218 exit(1); | |
219 } | |
220 | |
221 // merge blocks | |
222 for (int b = 0; b < bn; b++) { | |
223 sprintf(buf, "tmp_b%04d.xdw", b + 1); | |
224 _fullpath(buf, buf, _MAX_PATH); | |
225 strncpy(&blk_path[b * _MAX_PATH], buf, _MAX_PATH); | |
226 blk_path_addr[b] = &blk_path[b * _MAX_PATH]; | |
227 } | |
228 | |
229 _fullpath(buf, output, _MAX_PATH ); | |
230 api_result = XDW_MergeXdwFiles(blk_path_addr, bn, buf, NULL); | |
231 | |
232 if (api_result < 0) { | |
233 fprintf(stderr, "XDW Error: can't merge [3]\n"); | |
234 exit(1); | |
235 } | |
236 | |
237 free(all_path); | |
238 free(blk_path); | |
239 free(blk_path_addr); | |
240 | |
241 for (int b = 0; b < bn; b++) { | |
242 sprintf(buf, "tmp_b%04d.xdw", b + 1); | |
243 _fullpath(buf, buf, _MAX_PATH); | |
244 remove(buf); | |
245 } | |
246 } | |
247 | |
248 int xdwaddatn(const char* xdwfile, const char* atnfile) { | |
249 FILE *fp; | |
250 char filepath[_MAX_PATH]; | |
251 _fullpath(filepath, atnfile, _MAX_PATH); | |
252 | |
253 if ((fp = fopen(filepath, "r")) == NULL) { | |
254 fprintf(stderr, "Error: cannot open %s\n", filepath); | |
255 return -1; | |
256 } | |
257 | |
258 char keyword[128]; | |
259 char *q; | |
260 fgets(keyword, sizeof keyword, fp); | |
261 if ((q = strchr(keyword, '\n')) != NULL) { | |
262 *q = '\0'; | |
263 } | |
264 | |
265 char buf[_MAX_PATH]; | |
266 int x[ATN_N], y[ATN_N], sz[ATN_N], tr[ATN_N]; | |
267 char txt[ATN_N][256]; | |
268 int an = 0; | |
269 while (fgets(buf, sizeof buf, fp)) { | |
270 if ((q = strchr(buf, '\n')) != NULL) { | |
271 *q = '\0'; | |
272 } | |
273 | |
274 x[an] = atoi(strtok(buf, ",")); | |
275 y[an] = atoi(strtok(NULL, ",")); | |
276 sz[an] = atoi(strtok(NULL, ",")); | |
277 tr[an] = atoi(strtok(NULL, ",")); | |
278 strcpy(txt[an], strtok(NULL, ",")); | |
279 an++; | |
280 //printf("x=%d y=%d txt=%s sz=%d tr=%d\n", x[an], y[an], txt[an], sz[an], tr[an]); | |
281 } | |
282 fclose(fp); | |
283 | |
284 | |
285 XDW_DOCUMENT_HANDLE h = NULL; | |
286 XDW_OPEN_MODE_EX mode = {sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_UPDATE, XDW_AUTH_NODIALOGUE}; | |
287 | |
288 _fullpath(filepath, xdwfile, _MAX_PATH); | |
289 int api_result = XDW_OpenDocumentHandle(filepath, &h, (XDW_OPEN_MODE*)&mode); | |
290 if (api_result < 0) return api_result; | |
291 | |
292 XDW_DOCUMENT_INFO info = {sizeof(XDW_DOCUMENT_INFO), 0, 0, 0}; | |
293 XDW_GetDocumentInformation(h, &info); | |
294 XDW_FOUND_HANDLE pFoundHandle = NULL; | |
295 for (int i = 0; i < info.nPages; i++) { | |
296 if (keyword[0] != '\0') { | |
297 api_result = XDW_FindTextInPage(h, i + 1, keyword, NULL, &pFoundHandle, NULL); | |
298 if (!pFoundHandle) { | |
299 XDW_CloseFoundHandle(pFoundHandle); | |
300 continue; | |
301 } | |
302 XDW_CloseFoundHandle(pFoundHandle); | |
303 } | |
304 for (int j = 0; j < an; j++ ) { | |
305 XDW_ANNOTATION_HANDLE annoation; | |
306 int api_result = XDW_AddAnnotation(h, XDW_AID_TEXT, i + 1, x[j], y[j], NULL, &annoation, NULL); | |
307 if (api_result < 0) return api_result; | |
308 | |
309 api_result = XDW_SetAnnotationAttribute(h, annoation, XDW_ATN_Text, XDW_ATYPE_STRING, txt[j], 0, NULL); | |
310 api_result = XDW_SetAnnotationAttribute(h, annoation, XDW_ATN_FontSize, XDW_ATYPE_INT, (char*)&sz[j], 0, NULL); | |
311 | |
312 int color = XDW_COLOR_WHITE; | |
313 if (tr[j]) { | |
314 color = XDW_COLOR_NONE; | |
315 } | |
316 api_result = XDW_SetAnnotationAttribute(h, annoation, XDW_ATN_BackColor, XDW_ATYPE_INT, (char*)&color, 0, NULL); | |
317 } | |
318 } | |
319 | |
320 XDW_SaveDocument(h, NULL); | |
321 XDW_CloseDocumentHandle(h, NULL); | |
322 | |
323 return 0; | |
324 } | |
325 | |
326 int xdwaddatntool(const char* xdwfile, const char* toolfile, int n, int x, int y) { | |
327 char filepath[_MAX_PATH]; | |
328 _fullpath(filepath, xdwfile, _MAX_PATH); | |
329 | |
330 XDW_DOCUMENT_HANDLE h = NULL; | |
331 XDW_OPEN_MODE_EX mode = {sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_UPDATE, XDW_AUTH_NODIALOGUE}; | |
332 | |
333 int api_result = XDW_OpenDocumentHandle(filepath, &h, (XDW_OPEN_MODE*)&mode); | |
334 if (api_result < 0) return api_result; | |
335 | |
336 XDW_DOCUMENT_INFO info = {sizeof(XDW_DOCUMENT_INFO), 0, 0, 0}; | |
337 XDW_GetDocumentInformation(h, &info); | |
338 | |
339 _fullpath(filepath, toolfile, _MAX_PATH); | |
340 for (int i = 0; i < info.nPages; i++) { | |
341 XDW_ANNOTATION_HANDLE annoation; | |
342 int api_result = XDW_AddAnnotationFromAnnFile(h, filepath, n, i + 1, NULL, x, y, &annoation, NULL); | |
343 } | |
344 | |
345 XDW_SaveDocument(h, NULL); | |
346 XDW_CloseDocumentHandle(h, NULL); | |
347 | |
348 return 0; | |
349 } | |
350 |