1 /* # skkinput (Simple Kana-Kanji Input)
2  * HistMgr.c
3  * This file is part of skkinput.
4  * Copyright (C) 1997
5  * Takashi SAKAMOTO (sakamoto@yajima.kuis.kyoto-u.ac.jp)
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with skkinput; see the file COPYING.  If not, write to
19  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <sys/types.h>
24 #include <X11/Xlib.h>
25 #include <X11/IntrinsicP.h>
26 
27 #include "commondef.h"
28 #include "HistMgr.h"
29 #include "resrcs.h"
30 
31 /*
32  * �ҥ��ȥ�˻Ĥ�������( eggnl �ڤ� chatadapter )�ν���͡�
33  */
34 extern int skk_egg_like_newline ;
35 extern int skkinput_chatadaptermode ;
36 extern int skkinput_rjj_like_input ;
37 
38 /*
39  * �ҥ��ȥ��Ͽ���Ƥ���ꥹ�ȡ�
40  */
41 static HistoryListNode *unmanagedHistoryListTop = NULL ;
42 
43 /*
44  * ���Υ�������������Υץ饤�١��Ȥʴؿ�ã��
45  */
create_newHistoryNode(Window client)46 static HistoryListNode *create_newHistoryNode( Window client )
47 {
48   HistoryListNode *node ;
49   /* malloc ���Ѥ��ƥ������ݤ��롣*/
50   if( ( node = malloc( sizeof( HistoryListNode ) ) ) == NULL ){
51     /* ��Ϥ�������ݤǤ��ʤ��ä���硣*/
52     fprintf( stderr, "Memory fault...\n" ) ;
53     exit( 1 ) ;
54   }
55   /* ǰ�Τ���ˤ��餫�����������Ƥ�������������ʤ��Ƥ�ɬ�פʻ��˾� */
56   /* ��˽��������Ĥ��ǤϤ���Τ����ġ�*/
57   node->mask            = 0 ;
58   node->next            = NULL ;
59   node->client          = client ;
60   node->history_start   = node->history_end = 0 ;
61   MYCHAR_SET_END_OF_STRING( node->history[ 0 ] ) ;
62   MYCHAR_SET_END_OF_STRING( node->histcurbak[ 0 ] ) ;
63   node->egg_nl          = skk_egg_like_newline ;
64   node->chat_adapter    = skkinput_chatadaptermode ;
65   node->j_mode          = True ;
66   node->j_zenkaku       = False ;
67   node->j_katakana_mode = False ;
68   /* RJJ �������꤬���줢��С�������ʳ���ɬ�� True �ˤ��롣*/
69   node->overthespot_like_input = ( skkinput_rjj_like_input )? True : (-1) ;
70   return node ;
71 }
72 
73 /*
74  * ���Υ������γ����黲�Ȥ����ѥ֥�å��ʴؿ�ã��
75  */
76 
77 /*
78  * �ҥ��ȥ�ν�����������ӥ��γ��Ϥ�Ԥ��ؿ���
79  */
history_setup(Widget gw,Window client_window)80 HistoryListNode *history_setup( Widget gw, Window client_window )
81 {
82   HistoryListNode *node, *pNode ;
83 
84   pNode = node = unmanagedHistoryListTop ;
85   while( node != NULL ){
86     if( node->client == client_window )
87       break ;
88     pNode = node ;
89     node  = node->next ;
90   }
91   if( node == NULL ){
92     node = create_newHistoryNode( client_window ) ;
93     node->mask = HISTORY_BUFFER_MASK ;
94   } else {
95     if( pNode == node ){
96       unmanagedHistoryListTop = node->next ;
97     } else {
98       pNode->next = node->next ;
99     }
100   }
101   return node ;
102 }
103 
104 /*
105  * �ҥ��ȥ��ҥ��ȥ�ꥹ�Ȥؤ��᤹�ؿ���
106  *---
107  * �˴������櫓�ǤϤʤ����ꥹ�Ȥؤ��ᤵ�������Ǥ��롣
108  */
history_close(Display * disp,caddr_t caller)109 void history_close( Display *disp, caddr_t caller )
110 {
111   HistoryListNode *node = ( HistoryListNode *)caller ;
112   /* �ҥ��ȥ�Υꥹ�ȤˤĤʤ�ľ����*/
113   node->next = unmanagedHistoryListTop ;
114   unmanagedHistoryListTop = node ;
115   return ;
116 }
117 
118 /*
119  * ���ꤵ�줿�Ѵ����饤����Ȥ��Ф���ҥ��ȥ���˴�����ؿ���
120  *----
121  * ���ν����������ޤǡ����ٺ��줿�Ѵ����饤����Ȥ��Ф���
122  * SelectInput �ϼ��ä����Ȥ��Ǥ��ʤ������θ塢client_window �ˤ�
123  * NoEventMask �����뤳�Ȥˤʤ롣
124  */
history_destroy(Window client_window)125 void history_destroy( Window client_window )
126 {
127   HistoryListNode *node = unmanagedHistoryListTop, *pNode ;
128   pNode = node ;
129   while( node != NULL ){
130     /* ���饤����ȥ�����ɥ���¸�ߤ��뤫�ɤ�����Ĵ�٤롣*/
131     if( node->client == client_window ){
132       /* ����¸�ߤ��ʤ��ʤäƤ���Τʤ顢�ҥ��ȥ�����ä��롣*/
133       if( node == pNode ){
134 	unmanagedHistoryListTop = node->next ;
135 	free( node ) ;
136 	pNode = node = unmanagedHistoryListTop ;
137       } else {
138 	pNode->next = node->next ;
139 	free( node ) ;
140 	node = pNode->next ;
141       }
142     } else {
143       pNode = node ;
144       node = node->next ;
145     }
146   }
147   return ;
148 }
149