1 /*
2  *  $Id: sstrings.c,v 1.4 2002/07/14 04:26:57 hiroo Exp $
3  */
4 
5 /*
6  * FreeWnn is a network-extensible Kana-to-Kanji conversion system.
7  * This file is part of FreeWnn.
8  *
9  * Copyright Kyoto University Research Institute for Mathematical Sciences
10  *                 1987, 1988, 1989, 1990, 1991, 1992
11  * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999
12  * Copyright ASTEC, Inc. 1987, 1988, 1989, 1990, 1991, 1992
13  * Copyright FreeWnn Project 1999, 2000, 2002
14  *
15  * Maintainer:  FreeWnn Project   <freewnn@tomo.gr.jp>
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 2 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
30  */
31 
32 #ifdef HAVE_CONFIG_H
33 #  include <config.h>
34 #endif
35 
36 #include "commonhd.h"
37 #include <stdio.h>
38 #if STDC_HEADERS
39 #  include <string.h>
40 #else
41 #  if HAVE_STRINGS_H
42 #    include <strings.h>
43 #  endif
44 #endif /* STDC_HEADERS */
45 #include "wnn_os.h"
46 #include "wnn_string.h"
47 
48 extern int eeuc_to_ieuc ();
49 extern int ieuc_to_eeuc ();
50 
51 int
wnn_sStrcpy(register char * c,register w_char * w)52 wnn_sStrcpy(register char *c,
53 	    register w_char *w)
54 {
55 	register int ret;
56 
57 	ret = ieuc_to_eeuc(c, w, -1);
58 	c[ret] = '\0';
59 
60 	return (ret);
61 }
62 
63 int
wnn_Sstrcpy(w_char * w,unsigned char * c)64 wnn_Sstrcpy(w_char *w,
65 	    unsigned char *c)
66 {
67 	register int ret;
68 
69 	ret = eeuc_to_ieuc(w, c, -1) / sizeof(w_char);
70 	w[ret] = (w_char)0;
71 
72 	return (ret);
73 }
74 
75 #ifdef nodef
76 char *
wnn_Stos(cw_char * c)77 wnn_Stos(cw_char *c)
78 {
79 	char *c1 = (char *)c;
80 
81 	for (; *c; c++) {
82 		if (ASCIIP(*c))
83 			*c1++ = *c;
84 		else {
85 			*c1++ = (*c << 8);
86 			*c1++ = *c;
87 		}
88 	}
89 
90 	return ((char *) c);
91 }
92 #endif
93 
94 char *
wnn_sStrncpy(register char * s1,register char * s2,register int n)95 wnn_sStrncpy(register char *s1,
96 	     register char *s2,
97 	     register int n)
98 {
99 	eeuc_to_ieuc(s1, s2, n / sizeof(w_char));
100 
101 	return s1;
102 }
103 
104 #ifdef CHINESE
105 int
wnn_Sstrcat(w_char * w,unsigned char * c)106 wnn_Sstrcat(w_char *w,
107 	    unsigned char *c)
108 {
109 	w_char *w0 = w;
110 	register int ret;
111 
112 	if (!c || !*c)
113 		return (0);
114 
115 	for (; *w; w++);
116 
117 	ret = eeuc_to_ieuc(w, c, strlen (c)) / sizeof(w_char);
118 	w[ret] = (w_char)0;
119 	ret += (w - w0);
120 
121 	return (ret);
122 }
123 #endif
124