1 /*
2  * Copyright (c) 2004 Iwata <iwata@quasiquote.org>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef SJ3_H
18 #define SJ3_H
19 
20 #include "wchar16.h"
21 #include "conversion.h"
22 #include "inkey.h"
23 #include "rk.h"
24 #include "sjcompat.h"
25 #include "sj3rkcv.h"
26 
27 /* code.c */
28 void codeconv(wchar16_t, u_int *);
29 u_short CheckCcode(wchar16_t);
30 u_short strtocode();
31 void ChangeCode();
32 void SetCode(int);
33 int GetCcode();
34 
35 /* common.c */
36 extern int allways_buff;
37 extern int no_flush;
38 extern int HHlevel;
39 extern int Hlevel;
40 extern int oasys;
41 extern int flush_conversion;
42 extern Conversion *current_conversion;
43 extern Conversion *default_conversion;
44 
45 void FreeConversion(Conversion *);
46 void SetConversion(Conversion *);
47 void PushConversion(Conversion *);
48 void PopConversion();
49 Conversion *GetConversion();
50 void InitConversion();
51 void DefaultConversion();
52 void EndConversion();
53 int wcbyte(wchar16_t *);
54 
55 /* conv.c */
56 extern int keyvalue;
57 extern char *funckey[];
58 extern int funcvalue[];
59 extern int keynumber;
60 extern wchar16_t ibuf[KEYBUFSIZ];
61 extern wchar16_t pars_seq[KEYBUFSIZ];
62 extern int buf_count;
63 extern int pars_n;
64 
65 void convert_stat();
66 void inputprocess();
67 int inkey();
68 int sequence(wchar16_t *, int *);
69 int parse_escape(wchar16_t *, int *, int);
70 int write_pseq (int);
71 
72 /* display.c */
73 extern char bp[TCBUFSIZE];
74 extern char bpwork[AREASIZE];
75 extern char cmove[SHORTLENGTH];
76 extern int status_line;
77 extern char *CM, *US, *UE, *SO, *SE, *CE, *CS, *BEL, *RP, *AP, *TS, *FS, *DS, *I2;
78 extern char *SC, *RC, *SR, *DO;
79 extern int master_flush_flag;
80 
81 void checkterm();
82 void outc(char);
83 void erroutc(int);
84 void start_guideline();
85 void end_guideline();
86 void put_space(int);
87 void Backspace();
88 int master_flush();
89 int ThroughIntr();
90 void under_in();
91 void under_out();
92 void reverse_in();
93 void reverse_out();
94 void CursorSet(u_short, u_short);
95 void RegionSet(int, int);
96 void CursorRead(u_short *, u_short *);
97 int CRP(int *, int *);
98 void unget_inkey2(wchar16_t *, int);
99 void unget_key(int);
100 int CRI();
101 void Clear_EOL();
102 void StartGuide(u_short *, u_short *);
103 void EndGuide(u_short, u_short);
104 void Flush();
105 int Cscroll();
106 
107 /* douon.c */
108 extern struct studyrec Gdata[BUFFLENGTH];
109 
110 int SJ_getdouon(wchar16_t *, struct douon_sj3 *, int, int, int);
111 void exec_douon();
112 void wrap_douon(int);
113 int Cdouon(wchar16_t *, int);
114 int Dselect(int);
115 void Gdouon(wchar16_t *, int, int, int);
116 int Sdouon(int);
117 int Rdouon(int);
118 int Bkanji(wchar16_t *);
119 void PushGD(int, struct studyrec *);
120 void cl_gakusyuu();
121 void check_and_gakusyuu(int, int);
122 void go_gakusyuu(int);
123 
124 /* edit.c */
125 void push_obj(int, int);
126 void pop_obj(int, int);
127 int Bbig();
128 int Bsmall(int);
129 void Bdelete();
130 void Chain(int, int);
131 int exec_edit();
132 int getnum(wchar16_t *, int *);
133 int Replace(wchar16_t *, wchar16_t *, u_short *, int, int);
134 int Substitute(wchar16_t *, wchar16_t *, u_short *, int *, int);
135 int Insert(wchar16_t *, wchar16_t *, u_short *, int);
136 int EditDel(wchar16_t *, wchar16_t *, u_short *, int, int);
137 int chhstr(wchar16_t *, wchar16_t *, u_short *, int);
138 void Print_EOL(wchar16_t *);
139 void backspace(int);
140 
141 /* etc.c */
142 /*
143  * FIXME:
144  *  These functions may introduce to format string valn (see argument of snprintf).
145  *  Take care for value of WcMessages's "%s", ...
146  */
147 int exec_etc(int);
148 void Ssbun(int);
149 int etc_map(int);
150 void helplevel();
151 void disp_version(int);
152 void exec_sjrc();
153 void change_weight();
154 int UsecWeight(int);
155 int dconnect(int);
156 int IsDcflag();
157 int reconnect();
158 int guide_print_pause(wchar16_t *, wchar16_t *);
159 
160 /* eucmessage.c */
161 
162 extern unsigned char *EucMessages[];
163 #define CURMESSAGES 182
164 extern wchar16_t *WcMessages[CURMESSAGES];
165 #define CURWCVTKEY 29
166 extern struct wcvtkey wcvtkeytbl[CURWCVTKEY];
167 extern wchar16_t *comstr[KEY_OTHER];
168 extern struct valtbl hin_val[5];
169 #define CURFUNCS 29
170 extern struct functbl funcs[CURFUNCS];
171 extern struct valtbl mode_val[5];
172 extern struct valtbl code_val[8];
173 
174 int init_wcvtkey();
175 int init_comstr();
176 int init_hin_val();
177 int init_funcs();
178 int init_mode_val();
179 int init_code_val();
180 int init_messages();
181 
182 /* funckey.c */
183 extern struct cvtkey {
184 	char *key_word;
185 	char key_seq[SEQLEN];
186 } cvtkeytbl[];
187 extern int Uvalue[UKEYNUM];
188 extern wchar16_t Ukey[UKEYNUM][SEQLEN + 1];
189 extern int Unumber;
190 extern int comvalue[COMNUM];
191 extern wchar16_t comkey[COMNUM];
192 extern int comnumber;
193 #define ETCKEYS	10
194 extern int u_etckeys;
195 extern int Uetckey[ETCKEYS];
196 extern int Uetcval[ETCKEYS];
197 extern int comstrvalue[KEY_OTHER];
198 
199 void mk_cvtkey(char *);
200 char *getkey2(char *, char *);
201 void clear_ukeys();
202 int set_func(struct wordent *);
203 int eval_keys(wchar16_t *, wchar16_t *);
204 void clear_key();
205 void clear_commkeys();
206 int eval_key(wchar16_t *);
207 void clear_etckeys();
208 int set_etckeys(struct wordent *);
209 
210 /* henkan.c */
211 extern int i_point;
212 void exec_henkan();
213 void addBun(int, int);
214 void delspan(int);
215 void delBun(int, int);
216 int IsHex(wchar16_t);
217 void Getcode(wchar16_t *, wchar16_t *);
218 int load_bun(int, wchar16_t *, u_char);
219 int load_bun2(int, wchar16_t *, wchar16_t *, u_short *);
220 int getistr(wchar16_t *, wchar16_t *, int);
221 void exec_muhenkan(int);
222 int Bstr(int, wchar16_t *);
223 int mode_muhenkan(int, int);
224 void Bchange(int);
225 void Bdisp(int);
226 void Rdisp();
227 void AfterAllPrint(int, int);
228 void Bright();
229 void Bleft();
230 void Blast();
231 void Btop();
232 
233 /* henkan.c */
234 int kigou();
235 int IsRedraw(int);
236 int IsCKey(int);
237 void guide_kigou(int, int, int);
238 void pkigou(int);
239 int input_kigou(int, int, int);
240 
241 /* libif.c */
242 extern int (*len_func[3])();
243 
244 int SJ2_henkan(wchar16_t *, struct bunsetu_sj3 *, wchar16_t *, int);
245 int sjislen(unsigned char *, int);
246 int euclen(unsigned char *, int);
247 int SJ2_getdouon (wchar16_t *, struct douon_sj3 *, int, int, int);
248 void SJ2_study(struct studyrec *);
249 int SJ2_toroku(wchar16_t *, wchar16_t *, int);
250 int SJ2_syoukyo(wchar16_t *, wchar16_t *, int);
251 void sj_check_error(int);
252 int SJ2_reconnect();
253 void SJ2_henkan_end();
254 int SJ2_henkan_init();
255 int sj3_autocon();
256 
257 /* nmttyslot.c */
258 int nmttyslot(char *);
259 
260 /* romaji.c */
261 int exec_romaji(wchar16_t);
262 void move_cur(int);
263 int addten(u_short, u_short);
264 int getipos(u_short);
265 int getipos2(u_short *, u_short);
266 int sj_rkconv(wchar16_t *, wchar16_t *, int);
267 int sj_rkconv2(wchar16_t *, wchar16_t *, u_short *, int);
268 
269 /* screen.c */
270 #define LINE_LENGTH	80
271 extern wchar16_t Mguide[LINE_LENGTH + 1];
272 
273 void vbackchar(int);
274 void wrap_off();
275 void wrap_on();
276 void Vput_space();
277 void VBackspace();
278 void master_out(wchar16_t *, int);
279 void master_write(wchar16_t *, int);
280 void vprintU(wchar16_t *, char);
281 void vprintR(wchar16_t *, char);
282 void IprintU(wchar16_t *, int);
283 void IprintR(wchar16_t *, int);
284 void printU(wchar16_t *);
285 void printR(wchar16_t *);
286 void Csave();
287 void SetVcol(int);
288 void Cload();
289 void Cclear(int);
290 void Cgoto(int);
291 void Cgoto(int);
292 void ClearToMax();
293 void Ccheck();
294 void spaceR(wchar16_t *);
295 void clear_guide_line();
296 void print_guide_line();
297 void set_guide_line(int);
298 void disp_mode();
299 void TopGuide();
300 void guide_print(wchar16_t *, wchar16_t *);
301 
302 /* sjgetchar.c */
303 wchar16_t SJ_getchar();
304 void output_master();
305 void set_eucmode();
306 int SJ_write(wchar16_t *, int);
307 void write_stdout(u_char *, int);
308 int SJ_read(wchar16_t *, int );
309 void SJ_warnning(wchar16_t *);
310 void SJ_print(wchar16_t *);
311 void SJ_through(wchar16_t *, int);
312 
313 /* sj3.c */
314 extern int Lflag0;
315 extern int shell_flag;
316 extern char progname[LONGLENGTH];
317 extern char shellname[LONGLENGTH];
318 extern char home[LONGLENGTH];
319 extern char user_name[SHORTLENGTH];
320 extern char term_name[SHORTLENGTH];
321 extern char shellprog[LONGLENGTH];
322 extern char tty_name[SHORTLENGTH];
323 #ifdef SVR4
324 extern char *slave_name;
325 #else
326 extern char slave_name[SHORTLENGTH];
327 #endif
328 extern char *shellargs[SHORTLENGTH];
329 #ifdef SVR4
330 extern char *mptname;
331 extern char *ptsname();
332 #endif
333 extern char *cur_serv;
334 extern char my_hname[MAXHOSTNAMELEN];
335 extern char **serv_list;
336 #ifdef SYSV_TERMIOS
337 extern struct winsize Ttysize;
338 #define ts_lines ws_row
339 #define ts_cols ws_col
340 #else
341 extern int Ttyslot;
342 extern struct ttysize Ttysize;
343 #endif
344 extern int master;
345 extern int slave;
346 #ifdef SYSV_TERMIOS
347 extern struct termios b;
348 #else
349 extern struct sgttyb b;
350 extern struct tchars tc, tc1;
351 extern struct ltchars lc, lc1;
352 extern int lb;
353 extern int l;
354 #endif
355 #ifdef __sony_news
356 extern int jmode, jmode2;
357 extern struct jtchars jtc;
358 #endif
359 extern int erase_char;
360 extern wchar16_t erase_str[2];
361 #ifdef SIGTYPE_VOID
362 extern void (*sigpipe)();
363 #else
364 extern int (*sigpipe)();
365 #endif
366 extern int Pid_shell;
367 extern int current_locale;
368 
369 void makecore();
370 void init(char **);
371 void init_env();
372 void parsearg(int, char **);
373 void usage();
374 void sjinit();
375 void setshellname();
376 void getfixtty();
377 void get_ttymode();
378 void getmaster();
379 void set_jmode(int);
380 void fixtty();
381 void setdev();
382 void forkshell();
383 void sj3_setenv(char *, char *, char *, int);
384 void shellprocess();
385 void getslave();
386 void execcmd(char *, char **);
387 void fail();
388 void done();
389 void done2();
390 void done3();
391 void exitprocess();
392 void suspend();
393 void clearutmpentry();
394 void onwinch();
395 void SetRegion();
396 void set_tty_size();
397 void setsjserv(char *);
398 char *chmyhname(char *);
399 
400 /* sj3ver.c */
401 void print_version();
402 
403 /* sjrc.c */
404 extern int vflag;
405 extern char RCfile[LONGLENGTH];
406 #define GUIDELEN 80
407 extern wchar16_t guide_sj2[GUIDELEN];
408 extern wchar16_t guide_buffer[GUIDELEN];
409 extern wchar16_t guide_unbuffer[GUIDELEN];
410 extern wchar16_t guide_hira[GUIDELEN];
411 extern wchar16_t guide_zkata[GUIDELEN];
412 extern wchar16_t guide_hkata[GUIDELEN];
413 extern wchar16_t guide_halpha[GUIDELEN];
414 extern wchar16_t guide_zalpha[GUIDELEN];
415 extern wchar16_t guide_shift[GUIDELEN];
416 extern wchar16_t guide_jis[GUIDELEN];
417 extern wchar16_t guide_kuten[GUIDELEN];
418 extern wchar16_t guide_etc[GUIDELEN];
419 extern wchar16_t guide_etcfunc[GUIDELEN];
420 extern wchar16_t guide_function[GUIDELEN];
421 extern wchar16_t guide_euc[GUIDELEN];
422 extern wchar16_t guide_euc2[GUIDELEN];
423 extern wchar16_t guide_jis2[GUIDELEN];
424 extern wchar16_t guide_kuten2[GUIDELEN];
425 extern char **dict_list;
426 extern int dict_num;
427 extern int Direct;
428 
429 void sjset_code();
430 void sjrc_init();
431 void getsjrc();
432 int setrc(char *);
433 void getsjrk(int);
434 int getword(u_char *, struct wordent *);
435 int IsTerminator(u_char);
436 int isTerminator(u_char);
437 int IsEscape(u_char);
438 int IsDelimitor(u_char);
439 int set_forkshell(struct wordent *);
440 int set_intr(struct wordent *);
441 int set_delkey(struct wordent *);
442 int isintr(u_char);
443 int set_goto(struct wordent *);
444 int IsGoto(u_char);
445 int set_trap(struct wordent *);
446 int IsTrap(u_char);
447 int mode_key(int);
448 int set_init_mode(struct wordent *);
449 int set_helpmenu(struct wordent *);
450 int set_defcode(struct wordent *);
451 int set_muhenkan(struct wordent *);
452 int set_muedit(struct wordent *);
453 int set_m_toggle(struct wordent *);
454 int set_silent(struct wordent *);
455 int set_bstudy(struct wordent *);
456 int is_bstudy();
457 int eval_muhenkan();
458 int value_muhenkan();
459 int set_guide(struct wordent *);
460 int set_flush_conversion(struct wordent *);
461 int set_server(struct wordent *);
462 int set_dict(struct wordent *);
463 
464 /* stat_conv.c */
465 extern int rkerrbell;
466 void save_span(int);
467 void save_span_p();
468 int isspaned();
469 void buffers_clear();
470 void pointer_clear();
471 void StoreSaveSet();
472 void StoreSaveSet();
473 int history_empty();
474 void History();
475 void ClearBuffer();
476 void SetCflag();
477 void ClearCflag();
478 int IsCflag();
479 void exec_kettei();
480 int set_rkebell(struct wordent *);
481 void ChangeBuffMode();
482 int BuffYes();
483 int IsHenkan();
484 int IsMuhenkan();
485 void SetMuhenkan();
486 void SetHenkan();
487 void ResetHenkan();
488 void all_set_up();
489 void stat_conv_on();
490 void stat_init();
491 int get_pseq();
492 int get_pseq();
493 void stat_conv();
494 void save_obuf();
495 void restore_obuf();
496 void exec_ctrl(int);
497 void exec_mode(int);
498 int toggle_mode(int);
499 int eval_mode(int);
500 int IsESC(wchar16_t);
501 void Strncpy(wchar16_t *, wchar16_t *, int);
502 int is_bsdel(int);
503 void clear_del();
504 void set_bs(int);
505 void set_del(int);
506 int is_bs(int);
507 int is_del(int);
508 void SaveConversion();
509 int AnotherConversion();
510 
511 /* term.c */
512 void set_news();
513 
514 /* toroku.c */
515 /*
516  * FIXME:
517  *  These functions may introduce to format string valn (see argument of snprintf).
518  *  Take care for value of WcMessages's "%s", ...
519  */
520 int exec_toroku();
521 int getyomi(wchar16_t *, int, wchar16_t *, wchar16_t *);
522 int gethinshi();
523 int getcheck(wchar16_t *, wchar16_t *, wchar16_t *, wchar16_t *);
524 int getbunsetu(wchar16_t *, wchar16_t *);
525 int exec_syoukyo();
526 
527 /* version.c */
528 extern char *Version;
529 extern char *version;
530 extern char *Copyright;
531 extern char *Allrights;
532 extern char *Date;
533 
534 
535 #endif
536 
537