1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
26 * the ast catalogs are checked first
27 * the ast mc* and native cat* routines do all the work
28 * catalogs found by mcfind() are converted from utf to ucs
30 * nl_catd is cast to void*
31 * this is either an Mc_t* (Mc_t.set != 0)
32 * or a Cc_t* where Cc_t.cat is the native nl_catd
61 #define _ast_nl_catd nl_catd
62 #define _ast_catopen catopen
63 #define _ast_catgets catgets
64 #define _ast_catclose catclose
69 _ast_catopen(const char* name
, int flag
)
77 * first try the ast catalogs
81 sfprintf(sfstderr
, "AHA#%d:%s %s\n", __LINE__
, __FILE__
, name
);
83 if ((s
= mcfind(path
, NiL
, name
, LC_MESSAGES
, flag
)) && (ip
= sfopen(NiL
, s
, "r")))
86 sfprintf(sfstderr
, "AHA#%d:%s %s\n", __LINE__
, __FILE__
, s
);
91 return (_ast_nl_catd
)mc
;
94 if (strcmp(setlocale(LC_MESSAGES
, NiL
), "debug"))
100 * now the native catalogs
103 if (s
&& (d
= catopen(s
, flag
)) != (nl_catd
)(-1) || !(s
= 0) && (d
= catopen(name
, flag
)) != (nl_catd
)(-1))
105 if (!(cc
= newof(0, Cc_t
, 1, 0)))
108 return (_ast_nl_catd
)(-1);
111 if ((s
|| *name
== '/') && (ast
.locale
.set
& (1<<AST_LC_MESSAGES
)))
113 if ((cc
->cvt
= iconv_open("", "utf")) == (iconv_t
)(-1) || !(cc
->tmp
= sfstropen()))
116 return (_ast_nl_catd
)(-1);
120 cc
->cvt
= (iconv_t
)(-1);
122 sfprintf(sfstderr
, "AHA#%d:%s %s %s native %p\n", __LINE__
, __FILE__
, s
, name
, cc
->cat
);
124 return (_ast_nl_catd
)cc
;
133 return (_ast_nl_catd
)(-1);
137 _ast_catgets(_ast_nl_catd cat
, int set
, int num
, const char* msg
)
139 if (cat
== (_ast_nl_catd
)(-1))
142 if (!((Cc_t
*)cat
)->set
)
147 msg
= (char*)catgets(((Cc_t
*)cat
)->cat
, set
, num
, msg
);
148 if (((Cc_t
*)cat
)->cvt
!= (iconv_t
)(-1))
152 iconv_write(((Cc_t
*)cat
)->cvt
, ((Cc_t
*)cat
)->tmp
, &s
, &n
, NiL
);
153 if (s
= sfstruse(((Cc_t
*)cat
)->tmp
))
159 return mcget((Mc_t
*)cat
, set
, num
, msg
);
163 _ast_catclose(_ast_nl_catd cat
)
165 if (cat
== (_ast_nl_catd
)(-1))
168 if (!((Cc_t
*)cat
)->set
)
170 if (((Cc_t
*)cat
)->cvt
!= (iconv_t
)(-1))
171 iconv_close(((Cc_t
*)cat
)->cvt
);
172 if (((Cc_t
*)cat
)->tmp
)
173 sfclose(((Cc_t
*)cat
)->tmp
);
174 return catclose(((Cc_t
*)cat
)->cat
);
177 return mcclose((Mc_t
*)cat
);