Mercurial > hg > octave-shane > gnulib-hg
annotate lib/wcwidth.h @ 7560:046e511d4faf
Fix compilation error on platforms without 'wint_t' type.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Tue, 24 Oct 2006 20:19:49 +0000 |
parents | cae41cb69541 |
children | ea1da95d3579 |
rev | line source |
---|---|
6877
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
1 /* Determine the number of screen columns needed for a character. |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
2 Copyright (C) 2006 Free Software Foundation, Inc. |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
3 |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
4 This program is free software; you can redistribute it and/or modify |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 2, or (at your option) |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
7 any later version. |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
8 |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
13 |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
15 along with this program; if not, write to the Free Software Foundation, |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
17 |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
18 #ifndef _gl_WCWIDTH_H |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
19 #define _gl_WCWIDTH_H |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
20 |
6882
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
21 #if HAVE_WCHAR_T |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
22 |
6877
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
23 /* Get wcwidth if available, along with wchar_t. */ |
6882
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
24 # if HAVE_WCHAR_H |
6877
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
25 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
26 <wchar.h>. |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
27 BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
28 <wchar.h>. */ |
6882
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
29 # include <stdio.h> |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
30 # include <time.h> |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
31 # include <wchar.h> |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
32 # endif |
6877
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
33 |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
34 /* Get iswprint. */ |
6882
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
35 # if HAVE_WCTYPE_H |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
36 # include <wctype.h> |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
37 # endif |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
38 # if !defined iswprint && !HAVE_ISWPRINT |
7065
cae41cb69541
Oops, weird typos in last patch.
Bruno Haible <bruno@clisp.org>
parents:
7059
diff
changeset
|
39 static inline int |
7560
046e511d4faf
Fix compilation error on platforms without 'wint_t' type.
Bruno Haible <bruno@clisp.org>
parents:
7065
diff
changeset
|
40 # if HAVE_WINT_T |
7058
35f0e7415e65
Assume an ASCII compatible wide character encoding.
Bruno Haible <bruno@clisp.org>
parents:
6882
diff
changeset
|
41 iswprint (wint_t wc) |
7560
046e511d4faf
Fix compilation error on platforms without 'wint_t' type.
Bruno Haible <bruno@clisp.org>
parents:
7065
diff
changeset
|
42 # else |
046e511d4faf
Fix compilation error on platforms without 'wint_t' type.
Bruno Haible <bruno@clisp.org>
parents:
7065
diff
changeset
|
43 iswprint (int wc) |
046e511d4faf
Fix compilation error on platforms without 'wint_t' type.
Bruno Haible <bruno@clisp.org>
parents:
7065
diff
changeset
|
44 # endif |
7058
35f0e7415e65
Assume an ASCII compatible wide character encoding.
Bruno Haible <bruno@clisp.org>
parents:
6882
diff
changeset
|
45 { |
35f0e7415e65
Assume an ASCII compatible wide character encoding.
Bruno Haible <bruno@clisp.org>
parents:
6882
diff
changeset
|
46 return (wc >= 0 && wc < 128 |
35f0e7415e65
Assume an ASCII compatible wide character encoding.
Bruno Haible <bruno@clisp.org>
parents:
6882
diff
changeset
|
47 ? wc >= ' ' && wc <= '~' |
35f0e7415e65
Assume an ASCII compatible wide character encoding.
Bruno Haible <bruno@clisp.org>
parents:
6882
diff
changeset
|
48 : 1); |
35f0e7415e65
Assume an ASCII compatible wide character encoding.
Bruno Haible <bruno@clisp.org>
parents:
6882
diff
changeset
|
49 } |
7059
0fca2a1a6835
Avoid defining a substitute for the same function twice.
Bruno Haible <bruno@clisp.org>
parents:
7058
diff
changeset
|
50 # define iswprint iswprint |
6882
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
51 # endif |
6877
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
52 |
6882
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
53 # ifndef HAVE_DECL_WCWIDTH |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
54 "this configure-time declaration test was not run" |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
55 # endif |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
56 # ifndef wcwidth |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
57 # if !HAVE_WCWIDTH |
6877
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
58 |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
59 /* wcwidth doesn't exist, so assume all printable characters have |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
60 width 1. */ |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
61 static inline int |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
62 wcwidth (wchar_t wc) |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
63 { |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
64 return wc == 0 ? 0 : iswprint (wc) ? 1 : -1; |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
65 } |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
66 |
6882
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
67 # elif !HAVE_DECL_WCWIDTH |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
68 |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
69 /* wcwidth exists but is not declared. */ |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
70 extern |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
71 # ifdef __cplusplus |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
72 "C" |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
73 # endif |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
74 int wcwidth (int /* actually wchar_t */); |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
75 |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
76 # endif |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
77 # endif |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
78 |
6f91a91ac710
Fixes after wcwidth module creation.
Bruno Haible <bruno@clisp.org>
parents:
6877
diff
changeset
|
79 #endif /* HAVE_WCHAR_H */ |
6877
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
80 |
8a1cdc7197a8
* mbchar.h (wcwidth): Include wcwidth.h.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
81 #endif /* _gl_WCWIDTH_H */ |