1 /* trans.c */
2 /*****************************************************************************
3 					�ԣ�������У���������أԣ�
4 
5 							�Υƥ������Ѵ�������
6 *****************************************************************************/
7 
8 #include "xtr.h"
9 
10 /****************************************************************************/
11 
12 
13 /* aimode ���ͤȡ����������׷����Υ���ǥ�ȡ����楤��ǥ�ȡˤˤ����� */
14 
15 #define AI_SIMPLE		1			/* ���楤��ǥ�Ȥʤ� */
16 #define AI_HT			2			/* ���֤Τ����楤��ǥ�� */
17 #define AI_SP3			3			/* ����ζ�������楤��ǥ�� */
18 #define AI_NORMAL	4	/* (�����Ͱʾ�) ����ζ�������楤��ǥ�� */
19 
20 
21 /* fillmode ���ͤ�����Ƚ�� */
22 
23 #define FI_II			1		/* ����ǥ�ȤǤϿ�����ˤ��ʤ� */
24 #define FI_IND			2		/* ����ǥ�Ȥ�����п�����	*/
25 #define FI_AI			3		/* ����ǥ�Ȥ�������п����� */
26 #define FI_AF			4		/* ����ǥ�Ȥ��Ѥ��п����� */
27 #define FI_AUTO		5	  /* (�����Ͱʾ�) aimode �ʤɤǼ�ưŪ�˾����Ѥ��� */
28 
29 
30 /* ignorelinespmode */
31 #define IL_PAR		1		/* ����Ƚ��Ϥ��� */
32 
33 /* ignoreindentmode */
34 #define II_PAR		1		/* ����Ƚ��Ϥ��� */
35 
36 
37 /****************************************************************************/
38 /*						�ƥ������Ѵ�������									*/
39 /****************************** Trans ***************************************/
40 
41 #define IsPostSpAdjChr(c)	(Jiskigou(c) && Member(c, postspadjchrs))
42 #define IsPostSpAdjChr2(c)	(IsHanSp(c) || c == ZENSP || IsPostSpAdjChr(c))
43 #define IsPreSpAdjChr(c)	(Jiskigou(c) && Member(c, prespadjchrs))
44 #define IsPreSpAdjChr2(c)	(Isspace(c) || IsPreSpAdjChr(c))
45 
46 #define _ignoreindentmode	(ignoreindentmode || \
47 			!snmode && (centeradjmode || rightadjmode || bothadjmode) )
48 
49 void
Trans(void)50 Trans(void)
51 /*
52 * �ҤȤĤ����ϥե�������Ф��ƣ���ƤФ�롣
53 */
54 {
55 	ilineno = 1;		/* ���Ϲ��ֹ����� */
56 	nlcount = 0;		/* ���ϥƥ����Ȥβ���ʸ������������� */
57 	InitLine();			/* �饤��Хåե������ */
58 	InitParag();		/* ����Ϥν���� */
59 	cc = prevc = '\f';	/*  ����ʸ��������ʸ�������� */
60 	nevflag = OFF;
61 
62 	if (setjmp(errorjb)) {
63 		/* ���顼���������餳��������Ǥ��� */
64 		nevflag = OFF;
65 		ILineNoCount();
66 	}
67 
68 	solflag = sol2flag = ON;	/* ��Ƭ�ե饰����� */
69 
70 	Trans1();
71 
72 	/* ���Ԥʤ��ˣţϣƤˤʤäƤ��ƺǽ��Ԥ�ޤ����Ϥ��Ƥʤ��ʤ餽������ */
73 	if (!binarymode && !snmode)
74 		DelSpaces();
75 	if (!mada_start_of_line) {
76 		if (nountermlinemode) {
77 			/* ����̵���ǽ���äƤϤ����ʤ��⡼�ɤʤ� */
78 			NewLine();
79 		} else {
80 			WriteLineNCol(x);
81 			InitLine();
82 		}
83 	} else {
84 		/* �Ǹ�β��Ԥ� EOF �ʤ� */
85 		/* �ä˲��⤷�ʤ� */
86 	}
87 }
88 
89 static int
SpAdj1(void)90 SpAdj1(void)
91 /* ���ڡ���Ĵ�������� */
92 /* sjmode �ΤȤ��Υ��ڡ���Ĵ�� */
93 {
94 	unsigned c1;
95 	int x1, x2;
96 
97 	if (IsPreSpAdjChr(cc) &&
98 			(x2 = PrevCol(x1 = PrevCol(x))) >= bindent) {
99 		/* sjmode �ǡ�����ʸ����������Ĵ����ǽʸ���ΤȤ� */
100 		c1 = Moji(lbv[x1]);
101 		if (IsHanSp(c1) && (lbv[x1] + (Is1B(c1) ? 1 : 2)
102 								 == lbv[NextCol(x1)])) {
103 			/* ����������ʸ�������ڡ��������楳���ɤʤ�
104 			   �դ��Ƥ��ʤ���� */
105 			x = x1;			/* ���������� */
106 			prevc = Moji(lbv[x2]);
107 		}
108 		return 1;						/* �����Ѥߤΰ� */
109 	} else if (kemode && IsNewSentence(cc)) {
110 		/* ��ʸ�⡼�ɤǿ�����ʸ�λϤޤ�Ǥ���� */
111 		PutChr1(SP);		/* ���ڡ������Ĥˤ��� */
112 		return 1;						/* �����Ѥߤΰ� */
113 	}
114 	return 0;
115 }
116 
117 
118 static int
SpAdj2(void)119 SpAdj2(void)
120 /* ���ڡ���Ĵ�������� */
121 /* ssmode �ΤȤ����²�ʸ�֥��ڡ��������� */
122 {
123 	unsigned c1, c2;
124 	int x1, x2;
125 
126 	if ((x2 = PrevCol(x1 = PrevCol(x))) >= bindent) {
127 		c2 = Moji(lbv[x2]);
128 		if (!IsXSpace(c2) && (IsHan(cc) ? IsWabunmoji(c2) :
129 								IsHan(c2) && IsWabunmoji(cc))) {
130 			/* �²�ʸ�֤ʤ� */
131 			c1 = Moji(lbv[x1]);
132 			if (IsHanSp(c1) && (lbv[x1] + (Is1B(c1) ? 1 : 2)
133 									 == lbv[NextCol(x1)])) {
134 				/* ����������ʸ�������ڡ��������楳���ɤʤ�
135 				   �դ��Ƥ��ʤ���� */
136 				x = x1;			/* ���������� */
137 				prevc = c2;
138 			}
139 			return 1;
140 		}
141 	}
142 	return 0;
143 }
144 
145 
146 static int
HanZenConv(void)147 HanZenConv(void)
148 /* Ⱦ�ѡ������Ѵ� */
149 {
150 	unsigned c2, c3;
151 
152 	switch (hanzenconv) {
153 	case -1:
154 		cc = ZentoASC(cc);
155 		break;
156 	case -2:
157 		cc = ZentoANK2(cc, &c2);
158 		if (c2) {
159 			UngetChr(c2);
160 			textescapeflag = ON;
161 		}
162 		break;
163 	case -3:
164 		cc = ZentoANK(cc);
165 		break;
166 	case 1:
167 		cc = ASCtoZen(cc);
168 		break;
169 	case 2:
170 		if (Is1B(cc) && iskana(cc)) {
171 			c2 = GetChr();
172 			cc = ANKtoZen2(cc, c2, &c3);
173 			if (!c3) {
174 				UngetChr(c2);
175 			}
176 		} else {
177 			cc = ANKtoZen(cc);
178 		}
179 		break;
180 	case 3:
181 		cc = ANKtoZen(cc);
182 		break;
183 	default:
184 		;
185 	}
186 	return FALSE;			/* �ּ��ԡפ����뤳�ȤǼ��ν����˿ʤ�� */
187 }
188 
189 static void
GetSkipLineSpace(void)190 GetSkipLineSpace(void)
191 /* ����Ԥ��ɤ����Ф� */
192 {
193 	while (IsSpLine()) {
194 		GetSkipSpace();
195 		ILineNoCount();
196 		if (GetChr()==EOF2)
197 			break;
198 	}
199 }
200 
201 
202 void
Trans1(void)203 Trans1(void)
204 {
205 	static unsigned prevc2 = '\f';
206 	static int prev_adjmode = OFF;
207 
208 	/* ���ܥ롼�� */
209 	for ( ;
210 		 (cc = GetChr()) != EOF2;
211 		 cc && (prevc2 = prevc, prevc = cc) ) {
212 
213 		if (rplmode && (Replace() || hanzenconv && HanZenConv())) {
214 			/* �ִ��Ǥ����� */
215 			if (cc == EOF2)
216 				cc = '\f';
217 			if (cc && !IsXSpace(cc)) {
218 				/* �ִ���̤κǸ��ʸ���������ʸ���ʤ� */
219 				inindentflag = OFF;
220 			}
221 			if (ignorelinespmode && ignorelinespmode != IL_PAR && solflag) {
222 				GetSkipLineSpace();
223 			}
224 		} else {
225 			switch (cc) {
226 			case '\n':
227 				if (ignorelinespmode == IL_PAR) {
228 					if (sol2flag)
229 						break;
230 				} else if (ignorelinespmode) {
231 					GetSkipLineSpace();
232 				}
233 				solflag = sol2flag = ON;
234 				ILineNoCount();
235 
236 				if (chrexpflag) {
237 					linebreak = 0;
238 					aindent = bindent;
239 					WriteLine();
240 					InitParag();
241 				} else {
242 					if (fillmode &&  !madaindentflag && !IsParagEnd()) {
243 						/* �Ԥ�Ĥʤ��� */
244 						Fill();
245 					} else {
246 						/* ���Ԥ��ƿ���������� */
247 						NewParag();
248 					}
249 				}
250 				break;
251 			case '\t':
252 				solflag = OFF;
253 				if (madaindentflag
254 						&& (_ignoreindentmode || pindentmode && !aimode)
255 						&& !chrexpflag)
256 					break;
257 
258 				PutChr('\t');
259 				if (!indentsetflag && !linebreak
260 						&& (inindentflag || (aimode && aimode != AI_SIMPLE))
261 						&& x < width - 2) {
262 					if (hindentmode && madaindentflag) {
263 						aindent = x + hindent;
264 					} else if (pindentmode) {
265 						aindent = max(aindent, x - pindent);
266 					} else {
267 						aindent = x;	/* ���֤θ�ΰ��֤˥���ǥ�ȥ��å� */
268 					}
269 					inindentflag = ON;
270 					if (!indentchar)
271 						indentchar = cc;
272 				}
273 				break;
274 
275 			case SP:
276 			case HWSP:
277 				solflag = OFF;
278 				if (madaindentflag
279 						&& (_ignoreindentmode || pindentmode && !aimode)
280 						&& !chrexpflag)
281 					break;
282 
283 				if (sjmode && !inindentflag
284 					&& (IsHSpace(prevc) || IsPostSpAdjChr(prevc)) ) {
285 					/* ;ʬ�ʶ����̵�� */
286 				} else {
287 					PutChr1(cc);
288 				}
289 				if (!indentsetflag && !linebreak
290 					/* ���߰��֤���ǥ�Ȱ��֤ˤ��Ƥ����� */
291 					&& (inindentflag || !sjmode
292 							&& (aimode == AI_SP3 || aimode >= AI_NORMAL)
293 							&& IsHSpace(prevc)
294 							&& (prevc == ZENSP || aimode != AI_SP3 ||
295 									IsHSpace(prevc2)) )
296 					&& x < width - 2) {
297 
298 					if (hindentmode && madaindentflag) {
299 						aindent = x + hindent;
300 					} else if (pindentmode) {
301 						aindent = max(aindent, x - pindent);
302 					} else {
303 						/* ���ڡ����θ�ΰ��֤˥���ǥ�ȥ��å� */
304 						aindent = x;
305 					}
306 					inindentflag = ON;
307 					if (!indentchar)
308 						indentchar = cc;
309 				}
310 				break;
311 			case ZENSP:				/* ���ѥ��ڡ��� */
312 				solflag = OFF;
313 				if (madaindentflag
314 						&& (_ignoreindentmode || pindentmode && !aimode)
315 						&& !chrexpflag)
316 					break;
317 
318 				if (hindentmode || pindentmode) {
319 					if (shmode) {
320 						PutChr1(SP);
321 						PutChr1(SP);
322 					} else {
323 						PutChr1(cc);
324 					}
325 				}
326 				if (!indentsetflag && !linebreak
327 							&& (inindentflag ||
328 								(aimode == AI_SP3 || aimode >= AI_NORMAL)
329 								&& IsXSpace(prevc))
330 							&& x < width - 2) {
331 					if (hindentmode && madaindentflag) {
332 						aindent = x + hindent;
333 					} else if (pindentmode) {
334 						aindent = max(aindent, x - pindent);
335 					} else {
336 						/* ���ѥ��ڡ����ΰ��֤˥���ǥ�ȥ��å� */
337 						aindent = x;
338 					}
339 					inindentflag = ON;
340 					if (!indentchar)
341 						indentchar = (shmode ? SP : cc);
342 				}
343 				if (!hindentmode && !pindentmode) {
344 					if (shmode) {
345 						PutChr1(SP);
346 						PutChr1(SP);
347 					} else {
348 						PutChr1(cc);
349 					}
350 				}
351 				break;
352 
353 			case '\f':
354 			case '\v':
355 			case '\r':
356 				solflag = sol2flag = ON;
357 				PutChr(cc);
358 				break;
359 
360 			default:
361 
362 				solflag = sol2flag = OFF;
363 				if (madaindentflag)
364 					MkIndentEnd();
365 				if (IsHanSp(prevc)) {
366 					/* ����ʸ����Ⱦ�ѥ��ڡ����ξ�� */
367 					if (!inindentflag) {
368 						if (sjmode && SpAdj1() ||
369 							ssmode && SpAdj2()) {
370 						}
371 					}
372 
373 				} else if (asmode && !inindentflag
374 							&& (IsHan(prevc) ?
375 									IsWabunmoji(cc)
376 									&& !IsXSpace(prevc)
377 									&& !Member(prevc, gmkinsoku) :
378 								IsHan(cc) ?
379 									IsWabunmoji(prevc)
380 									&& !IsXSpace(prevc)
381 									&& !Member(cc, gtkinsoku) :
382 								FALSE ) ) {
383 					/* �²�ʸ�֥��ڡ����������⡼�ɤ��²�ʸ�֥��ڡ�����
384 					   ɬ�פʤ顢Ⱦ�ѥ��ڡ������Ĥ������ */
385 					if (!ssmode)
386 						PutChr1(SP);
387 					/* asmode �� ssmode �ξ�硢�����Ǥϥ��ڡ���������ʤ�����
388 					 * ��·���Τ���Υ��ڡ����ʤ��²�ʸ�֤��������롣
389 					 */
390 					prevc = SP;
391 				}
392 
393 				if (!inindentflag &&
394 						(prev_adjmode || normadjmode || bothadjmode) &&
395 						(IsPostSpAdjChr2(prevc) ? !IsPostSpAdjChr(cc) :
396 						 IsPreSpAdjChr(cc) && !IsPreSpAdjChr2(prevc))) {
397 					/* ���ΰ��֤��·���Υ��ڡ�����������֤Ȥ��Ƶ��� */
398 					SetSpAdjPos(x);
399 				}
400 				prev_adjmode = normadjmode || bothadjmode;
401 
402 				PutChr1(cc);
403 				if (inindentflag) {
404 					if (!indentsetflag && aimode && Member(cc, itemmark) &&
405 							(IsXSpace(prevc) || Member(prevc, itemmark))
406 							&& x < width - 2) {
407 
408 						/* ���ܵ���ǡ�����ʸ�����������ܵ���ʤ� */
409 
410 						if (!IsXSpace(prevc) || !IsHan(cc)) {
411 							/* ���ܵ���Τ��Ȥΰ��֤˥���ǥ�ȥ��å� */
412 							aindent = max(aindent, x);
413 						}
414 						/* ���ڡ����Τ��Ȥ�Ⱦ�Ѥε���Ȥ������ϡ��ޤ�
415 						   ���åȤ��ʤ� */
416 
417 					} else {
418 						inindentflag = OFF;
419 					}
420 				}
421 			}
422 		}
423 		if (textescapeflag) {
424 			if (rplmode) {
425 				rplmode = OFF;
426 			} else {
427 				rplmode = ON;
428 				textescapeflag = OFF;
429 			}
430 		}
431 	}
432 }
433 
434 
435 
436 
437 /************************** MkIndentEnd ***************************/
438 
439 void
MkIndentEnd(void)440 MkIndentEnd(void)
441 /*
442 * ����ǥ�Ȥ����ä��Ȥ���ǸƤФ�롣
443 * �������Ƥ���ʸ�����������楳���ɤ�����Ф������Ϥ���
444 */
445 {
446 	PutCntrl(c_attr);
447 	PutCntrl(c_wide);
448 	PutCntrl(c_vexpand);
449 	PutCntrl(c_qexpand);
450 	PutCntrl(c_half);
451 
452 	vexpflag = (c_vexpand || c_qexpand);
453 	wexpflag = (c_wide || c_qexpand || c_half);
454 
455 	madaindentflag = OFF;
456 
457 	if (!linebreak)
458 		first_indent = x;		/* ����������ܥ���ǥ�ȵ��� */
459 
460 }
461 
462 
463 
464 /****************************** NewParag ************************************/
465 
466 void
NewParag(void)467 NewParag(void)
468 /* ����Ǹ�ιԤ���Ϥ��ƿ���������˿ʤ� */
469 {
470 	int asplflag;
471 
472 	if (!binarymode && (!snmode || mada_start_of_line))
473 		DelSpaces();		/* ������;ʬ�ʥ��ڡ����Ϻ�� */
474 	asplflag = almode && !mada_start_of_line &&
475 					(ignorelinespmode || !IsSpLine());
476 	linebreak = 0;
477 	WriteLine();
478 	if (asplflag) {
479 		WriteLine();			/* ���Ԥ������ */
480 	}
481 	InitParag();				/* ����������ʥե饰��������*/
482 }
483 
484 void
NewLine(void)485 NewLine(void)
486 {
487 	if (!binarymode && (!snmode || mada_start_of_line))
488 		DelSpaces();		/* ������;ʬ�ʥ��ڡ����Ϻ�� */
489 	linebreak = 0;
490 	WriteLine();
491 	InitParag();				/* ����������ʥե饰��������*/
492 }
493 
494 void
FreshLine(void)495 FreshLine(void)
496 {
497 	DelSpaces();
498 	if (!mada_start_of_line) {
499 		int linebreak0 = linebreak;
500 		linebreak = 0;
501 		WriteLine();
502 		linebreak = linebreak0+1;			/* ����������ȤϤ��ʤ� */
503 		MkIndent();
504 	}
505 }
506 
507 int
IsSpLine(void)508 IsSpLine(void)
509 /* ���ɤߤ��ƶ���Ԥ��ɤ���Ĵ�٤� */
510 {
511 	unsigned c;
512 
513 	while ((c = LookChr()) != EOF2 && IsHSpace(c));
514 										/* ���ڡ���������Ф��Ƥߤ� */
515 	UnlookChrs();						/* ���ɤߤ����Τ��᤹ */
516 	if (c == '\n' || c == EOF2)
517 		return TRUE;
518 	else
519 		return FALSE;
520 }
521 
522 
523 
524 /****************************** InitParag ***********************************/
525 
526 void
InitParag(void)527 InitParag(void)
528 /* ����λϤ�ν���� */
529 {
530 	inindentflag = ON;
531 	nonewlineflag = linebreak = lineoverflag = indentsetflag = OFF;
532 	indentchar = 0;
533 
534 	if (pmmode) {
535 		/* ����ν����ʸ��������������⡼�ɤʤ� */
536 		ResetCntrl(&c_attr);
537 		ResetCntrl(&c_wide);
538 		ResetCntrl(&c_vexpand);
539 		ResetCntrl(&c_qexpand);
540 		ResetCntrl(&c_half);
541 	}
542 	MkIndent();
543 }
544 
545 
546 
547 /****************************** MkIndent ************************************/
548 
549 void
MkIndent(void)550 MkIndent(void)
551 /* �ԤΥ���ǥ����ʬ��������� */
552 {
553 	int i, q, bi, ai;
554 	static uchar *qstr = NULL;
555 	static int prev_lineno = 0;
556 	static uchar *prev_quotestr = NULL;
557 
558 	ResCntrlPosVects();		/* ���楳���������߰��ֵ����٥�������� */
559 	ResChrExp();
560 
561 	InitLine();
562 	nobreakpos = 0;
563 
564 	vexpflag = (c_vexpand || c_qexpand);
565 	wexpflag = (c_wide || c_qexpand || c_half);
566 
567 	madaindentflag = ON;
568 	if (quotemode) {
569 		static int recurflag = 0;
570 		int recurflag0 = recurflag;
571 		if (!recurflag) {
572 			int pageno0 = pageno;
573 			int abspageno0 = abspageno;
574 			unsigned lineno0 = lineno;
575 
576 			if (((long)lineno > pagelines) && pageendflag && pagemode) {
577 				/* �⤷�����ڡ����ιԿ���ã���Ʋ��ڡ�������Ȥ���ʤ� */
578 				pageno++;
579 				abspageno++;
580 				lineno = 1;
581 			}
582 			recurflag = 1;
583 
584 			if (!qstr || (long)lineno != prev_lineno || quotestr != prev_quotestr) {
585 				XFree((voidstar)qstr);
586 				qstr = AEvalString((int *)NULL, quotestr);
587 				InitLine();
588 			}
589 			prev_lineno = lineno;
590 			prev_quotestr = quotestr;
591 			if (qstr)
592 				PutStr(qstr);
593 			pageno = pageno0;
594 			abspageno = abspageno0;
595 			lineno = lineno0;
596 		}
597 		recurflag = recurflag0;
598 	} else {
599 		XFree((voidstar)qstr);
600 		qstr = NULL;
601 	}
602 	q = x;
603 
604 	bi = indent;					/* ���ܥ���ǥ�� */
605 	if (q > bi)
606 		bi = q;
607 	if (!linebreak && !aimode && pindentmode && !hindentmode)
608 		bi += pindent;
609 
610 	if (indentsetflag || linebreak && aimode) {
611 		/* �Ԥ��ޤä��Ȥ���ǥ����ȥ���ǥ�Ȥʤ�*/
612 		ai = aindent - bi;			/* �����ȥ���ǥ�� */
613 	} else if (linebreak && hindentmode) {
614 		ai = hindent;
615 	} else {
616 		ai = 0;
617 	}
618 
619 	PutChrN(SP, bi - q);
620 	bindentp = lbv[bindent = x];	/* ����ǥ�ȴ����֥��å� */
621 
622 	if (!linebreak)
623 		first_indent = x;
624 
625 	if (ai == 0) {
626 	} else if (!indentchar) {
627 		PutChrN(SP, ai);
628 	} else if (indentchar == '\t') {
629 		if (tabtospmode) {
630 			PutChrN(SP, ai);
631 		} else {
632 			i = aindent - (x / itabstop) * itabstop;
633 			PutChrN('\t', i / itabstop);
634 			PutChrN(SP, i % itabstop);
635 		}
636 	} else if (IsHan(indentchar)) {
637 		PutChrN(indentchar, ai);
638 	} else {
639 		PutChrN(indentchar, ai / 2);
640 		if (ai % 2)
641 			PutChr1(SP);
642 	}
643 
644 	if (hindentmode && !linebreak) {
645 		aindent = x + hindent;
646 	} else {
647 		aindent = x;
648 	}
649 
650 	if (linebreak) {		/* �Ԥ��ޤä���³�Ԥʤ� */
651 		MkIndentEnd();			/* ʸ������������ʤ餽�����楳���ɤ������ */
652 	}
653 
654 	if (x + 2 > width) {			/* ����ǥ�Ȥ����ǣ��Ԥη����ۤ����� */
655 		InitLine();					/* ����ǥ�Ȥ���Ƥ��ޤ� */
656 		aindent = bindent = x = 0;
657 	}
658 	bindentp = lbv[bindent];
659 }
660 
661 
662 /****************************** IsParagEnd **********************************/
663 
664 int
IsParagEnd(void)665 IsParagEnd(void)
666 /* ���ɤߤ�Ԥ�������ν���꤫�ɤ��������å����� */
667 {
668 	register unsigned c = 0;
669 	register int i;
670 	unsigned c2 = 0;
671 	int ignoreindent_par = ignoreindentmode && ignoreindentmode != II_PAR ||
672 			!snmode && (centeradjmode || rightadjmode || bothadjmode);
673 
674 	if (IsSpLine()) {
675 		return TRUE;
676 	}
677 	for (i = 0; 							/* ���ԤΥ���ǥ�Ȥ������ */
678 		 c = LookChr(),
679 			 ( (c == SP || c == ZENSP || c == '\t') &&
680 			   ((fillmode>=FI_AUTO && (aimode||afmode) ||
681 			   			fillmode==FI_AI || fillmode==FI_AF) &&
682 			 	!ignoreindent_par || i == 0) );
683 		 i += (c == SP ? 1 :
684 		 	   c == ZENSP ? 2 :
685 		 	   c == '\t' ? itabstop - i % itabstop : 0 ) );
686 
687 	c2 = LookChr();
688 
689 	UnlookChrs();
690 
691 	if (i == 0 && ((int)c == cmddot_mchar || cmddot_char && (int)c == cmddot_char))
692 		/* �����ߥ��ޥ��ͭ�����ϡ�������Ƭ���ɥåȤʤ�����ν���� */
693 		return TRUE;
694 
695 	if ((fillmode>=FI_AUTO && (aimode||afmode) || fillmode==FI_AI
696 											 || fillmode==FI_AF) &&
697 			Member(c, itemmark) &&
698 				(!Is1B(c) || IsXSpace(c2) || Member(c2, itemmark)))
699 		return TRUE;
700 
701 	if (fillmode==FI_II || ignoreindent_par)
702 		/* ���Υ⡼��(����������䱦���Ǥ�)�Ǥϡ���ȤΥ���ǥ��
703 		   ��̵�뤹�� */
704 		return FALSE;
705 
706 	if (fillmode>=FI_AUTO && afmode || fillmode==FI_AF)
707 		/* ���Υ⡼�ɤǤϤ�ȤΥ���ǥ�Ȥȥ����ȥ���ǥ��������֤�
708 		   �������ʤ���С������������Ƚ�� */
709 		return (i != aindent - bindent);
710 	else if (fillmode>=FI_AUTO && aimode || fillmode==FI_AI)
711 		/* �̾索���ȥ���ǥ�ȥ⡼�ɤǤϡ���ȤΥ���ǥ�Ȥ������ȥ���ǥ��
712 		   ������֤�꿼�����˿����������Ƚ�� */
713 		return (i > aindent - bindent);
714 	else if (hindentmode)
715 		/* �����ȥ���ǥ�ȥ⡼�ɤǤʤ��ơ�hanging indent �⡼�ɤʤ鎤
716 		   ��ȤΥ���ǥ�Ȥ� 0 �ʤ鿷���������Ƚ�� */
717 		return (i == 0);
718 	else
719 		/* ����¾�ξ��ϡ���ȤΥ���ǥ�Ȥ������Ǥ⤢��п����������Ƚ�� */
720 		return (i > 0);
721 }
722 
723 
724 
725 
726 /************************** Fill ************************************/
727 
728 void
Fill(void)729 Fill(void)
730 /* �Ԥ�Ĥʤ��� */
731 {
732 	int col;
733 	unsigned pc, nc;			/* ����ʸ���ȼ���ʸ�� */
734 
735 	if (!snmode && !jtexmode && !sol2flag)
736 		DelSpaces();			/* ������;ʬ�ʥ��ڡ������� */
737 
738 	if (x <= 0) {
739 		/* �Ԥ�Ĺ������������Ϥ��Ƥ����� */
740 		pc = prevc;
741 	} else {
742 		col = PrevCol(x);
743 		pc = Moji(lbv[col]);		/* ����ʸ�� */
744 	}
745 	UngetChr(nc = GetChr());		/* ����ʸ������ */
746 	if (nc == EOF2)
747 		return;
748 
749 	if (IsHSpace(nc)) {
750 		GetSkipSpace();			/* ��Ƭ���ڡ������� */
751 		UngetChr(nc = GetChr());		/* ����ʸ������ */
752 		if (nc == EOF2)
753 			return;
754 		solflag = OFF;	/* ��Ƭ���ڡ������åȤ����ʤ��Ƭ�ե饰���ꥢ */
755 	}
756 
757 	if (kfmode) {
758 		; /* �ͤ���ߤǶ��������ʤ��⡼�� */
759 	} else if (jtexmode) {
760 		/* ���ܸ�TeX�⡼�ɤʤ� */
761 		if (IsHan(pc))
762 			/* ���Ԥ�����ʸ����Ⱦ�Ѥʤ� */
763 			PutChr1(cc = SP);			/* Ⱦ�Ѷ���������� */
764 	} else if (IsXSpace(pc)) {
765 	} else if (IsHan(pc) && IsHan(nc)) {
766 		/* ����ʸ���⼡��ʸ����Ⱦ�Ѥξ�� */
767 		if (!IsXSpace(pc)) {
768 			PutChr1(cc = SP);			/* Ⱦ�Ѷ���������� */
769 		}
770 		if (kemode && IsNewSentence(nc)) {
771 			/* ��ʸ�⡼�ɤ�ʸ���ʤ�Ⱦ�Ѷ�����Ĥˤ��� */
772 			PutChr1(cc = SP);
773 		}
774 	} else if (IsHan(pc)) {
775 		if (!ssmode && IsWabunmoji(nc) || IsXAlnum(nc))
776 			/* ����ʸ����Ⱦ�ѤǸ��ʸ������ʸʸ���ޤ��ϱѿ����ʤ� */
777 			PutChr1(cc = SP);			/* Ⱦ�Ѷ���������� */
778 	} else if (IsHan(nc)) {
779 		if (!ssmode && IsWabunmoji(pc) || IsXAlnum(pc))
780 			/* ���ʸ����Ⱦ�Ѥ�����ʸ������ʸʸ���ޤ��ϱѿ����ʤ� */
781 			PutChr1(cc = SP);			/* Ⱦ�Ѷ���������� */
782 	} else if (IsXAlnum(pc) && IsXAlnum(nc)) {
783 		/* ξ�����Ѥαѿ����ʤ� */
784 		PutChr1(cc = shmode ? SP : ZENSP);		/* ���Ѷ��������� */
785 	}
786 	if (IsVSpace(cc))
787 		/* ���������Ƥ��ʤ��ʤ� */
788 		cc = 0;
789 }
790 
791 
792 
793 int
IsNewSentence(unsigned c)794 IsNewSentence(unsigned c)
795 /* ��ʸ��ʸƬ���ɤ���Ĵ�٤� */
796 /* ��c ��Ⱦ�ѱ���ʸ���ǡ�
797  *       ���������ʸ����')', '\'', '"' �ΤȤ��Ϥ���ˤ������ˤ�
798  *       '.', '!', '?' �ʤ鿿��
799  *       '.' �ξ��ϡ����줬��ά����Υԥꥪ�ɤʤ鵶��
800  */
801 {
802 	int col;
803 	unsigned pc;		/* ����ʸ�� */
804 	unsigned c2;
805 	int n;
806 
807 	if (!Isupper(c))
808 		return FALSE;				/* c ��Ⱦ�ѱ���ʸ���Ǥʤ��ʤ鵶���֤� */
809 
810 	if ((col = PrevCol(x)) <= bindent)
811 		return FALSE;				/* ��Ƭ��ʬ����ʤ����鵶���֤� */
812 
813 	if (HWtoANK(Moji(lbv[col])) != SP)
814 		return FALSE;				/* ����Ⱦ�ѥ��ڡ����Ǥʤ���е����֤� */
815 
816 	if ((col = PrevCol(col)) <= bindent)
817 		return FALSE;				/* ��Ƭ��ʬ����ʤ����鵶���֤� */
818 
819 	pc = HWtoANK(Moji(lbv[col]));
820 	if (pc == ')' || pc == '\'' || pc == '"') {
821 		/* �����Ĥ������ʤ餽������ߤ� */
822 		if ((col = PrevCol(col)) <= bindent)
823 			return FALSE;			/* ��Ƭ��ʬ����ʤ����鵶���֤� */
824 
825 		pc = HWtoANK(Moji(lbv[col]));
826 	}
827 
828 	if (pc != '.' && pc != '!' && pc != '?')
829 		return FALSE;				/* ���� '.', '!', '?' �Ǥʤ���е����֤� */
830 
831 	for (n = 0, c2 = 0;
832 			((col = PrevCol(col)) >= bindent) &&
833 				(c = HWtoANK(Moji(lbv[col])), Isalpha(c));
834 			n++, c2 = c) {
835 
836 		if (pc != '.' || n >= 4 || isupper(c2)) {
837 			/* ������ '.' �ʳ��ʤ鿿 */
838 			/* ���Ǥˣ�ʸ��������Ȥ��Ƥ����鿿 */
839 			/* ��ʸ���κ�¦���ä��鿿 */
840 			return TRUE;
841 		}
842 	}
843 	if (n == 0)
844 		return col >= bindent && Is1B(c);
845 	else
846 		return (n >= 5 || islower(c2));
847 }
848 
849 /*
850  * Local variables:
851  * mode: c
852  * c-indent-level: 4
853  * c-continued-statement-offset: 4
854  * c-brace-offset: -4
855  * c-argdecl-indent: 4
856  * c-label-offset: -4
857  * tab-width: 4
858  * tab-stop-list: (4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80)
859  * End:
860  */
861