/****   wchar.h for ASCII systems!

        Brought to you by Cima for the ASCII Consortium.


        You have seen that new ANSI "wide character library" in
        "http://www.opengroup.org/onlinepubs/007908799/xsh/wchar.h.html" (or elsewhere)
        and started dreaming what you could do if you had such a cute thing in your
        poor old C compiler?

        Dream no more!

        Using this highly portable implementation of the ANSI wide character library for
        the ASCII Standard, you can now write wide character applications too!
        (Well, 7-bit *wide*, that is :-)

        The ASCII standard (1.0) is the path breaking universal 7-bit encoding for the script
        of the world's principal language.

        If you want to know more about the ASCII standard, please refer to the official web
        site of the ASCII Consortium ("http://www.ecs.soton.ac.uk/~rwb197/ascii").


        Disclaimers and warnings:

        1) The author of this file takes absolutely no responsibility about it.
           If you need it (do you really!?), you can use it: maybe it works.
           I guess that also the ASCII Consortium doesn't want to take any
           responsibility about this.
           Whatever will happen, it is *your* fault!

        2) If what you want to do is to use the 16-bit (or 32-bit) characters library
           provided with your compiler, it is not a good idea to put this file in your
           include path.

        3) If what you want to do is to see how your colleague's 16-bit (or 32-bit) characters
           application behaves after you put this file in his/her include path, you are a
           swine and, if I were your colleague, you would be a swine with a bleeding nose.

****/

#ifndef _WCHAR_H_PARODY_
#define _WCHAR_H_PARODY_


/*** Include the good old stuff, that you don't want to give up. ***/

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <stddef.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <time.h>


/*** "Wide" character types. ***/

#define wchar_t                     char
                                    /* (What else?) */
#define wint_t                      int
#define wctrans_t                   int
#define wctype_t                    int
#define mbstate_t                   int


/*** "Wide" character constants. ***/

#define WCHAR_MIN                   CHAR_MIN
#define WCHAR_MAX                   CHAR_MAX
#define WEOF                        EOF
#define MB_CUR_MAX                  1


/*** "Wide" character classification/conversion functions. ***/

                                    /* The easy ones: */
#define iswalnum(c)                 isalnum(c)
#define iswalpha(c)                 isalpha(c)
#define iswascii(c)                 isascii(c)
#define iswcntrl(c)                 iscntrl(c)
#define iswdigit(c)                 isdigit(c)
#define iswgraph(c)                 isgraph(c)
#define iswlower(c)                 islower(c)
#define iswprint(c)                 isprint(c)
#define iswpunct(c)                 ispunct(c)
#define iswspace(c)                 isspace(c)
#define iswupper(c)                 isupper(c)
#define iswxdigit(c)                isxdigit(c)
#define towlower(c)                 tolower(c)
#define towupper(c)                 toupper(c)

                                    /* The cute ones: */
#define iswctype(c, ct)             (((ct) == (('a' << CHAR_BIT) | 'n')) ? isalnum(c) : \
                                    (((ct) == (('a' << CHAR_BIT) | 'p')) ? isalpha(c) : \
                                    (((ct) == (('a' << CHAR_BIT) | 'c')) ? isascii(c) : \
                                    (((ct) == (('c' << CHAR_BIT) | 't')) ? iscntrl(c) : \
                                    (((ct) == (('d' << CHAR_BIT) | 'g')) ? isdigit(c) : \
                                    (((ct) == (('g' << CHAR_BIT) | 'a')) ? isgraph(c) : \
                                    (((ct) == (('l' << CHAR_BIT) | 'w')) ? islower(c) : \
                                    (((ct) == (('p' << CHAR_BIT) | 'i')) ? isprint(c) : \
                                    (((ct) == (('p' << CHAR_BIT) | 'n')) ? ispunct(c) : \
                                    (((ct) == (('s' << CHAR_BIT) | 'a')) ? isspace(c) : \
                                    (((ct) == (('u' << CHAR_BIT) | 'p')) ? isupper(c) : \
                                    (((ct) == (('x' << CHAR_BIT) | 'i')) ? isxdigit(c) : \
                                    (c)))))))))))))
#define wctype(name)                (((name)[0] << CHAR_BIT) | (name)[2])
#define towctrans(c, ct)            (((ct) == 'l') ?  tolower(c) : (((ct) == 'u') ?  toupper(c) : (c)))
#define wctrans(name)               ((name)[0])


/*** "Wide" string functions. ***/

                                    /* The functions that you use: */
#define wcslen(s)                   strlen(s)
#define wcscmp(s1, s2)              strcmp((s1), (s2))
#define wcscpy(s1, s2)              strcpy((s1), (s2))
#define wcscat(s1, s2)              strcat((s1), (s2))
#define wcsncmp(s1, s2, n)          strncmp((s1), (s2), (n))
#define wcsncpy(s1, s2, n)          strncpy((s1), (s2), (n))
#define wcsncat(s1, s2, n)          strncat((s1), (s2), (n))
#define wmemcmp(s1, s2, n)          memcmp((s1), (s2), (n))
#define wmemcpy(s1, s2, n)          memcpy((s1), (s2), (n))
#define wmemmove(s1, s2, n)         memmove((s1), (s2), (n))
#define wmemset(s, c, n)            memset((s), (c), (n))
#define wmemchr(s, c, n)            memchr((s), (c), (n))

                                    /* The functions that you don't use: */
#define wcschr(s, c)                strchr((s), (c))
#define wcsrchr(s, c)               strrchr((s), (c))
#define wcsstr(s1, s2)              strstr((s1), (s2))
#define wcsspn(s1, s2)              strspn((s1), (s2))
#define wcscspn(s1, s2)             strcspn((s1), (s2))
#define wcspbrk(s1, s2)             strpbrk((s1), (s2))
#define wcstok(s1, s2, p)           strtok((s1), (s2), (p))

                                    /* The functions that you never heard before: */
#define wcstod(np, ep)              strtod((np), (ep))
#define wcstol(np, ep, base)        strtol((np), (ep), (base))
#define wcstoul(np, ep, base)       strtoul((np), (ep), (base))
#define wcsftime(s, n, fmt, t)      strftime((s), (n), (fmt), (t))
#define wcsxfrm(s1, s2, n)          strncpy((s1), (s2), (n))
#define wcscoll(s1, s2)             strcmp((s1), (s2))


/*** "Multi"-byte strings functions: convert between ASCII (7-bit) wide characters
     and the ASCII Transformation Format ATF-8
     (see "http://www.ecs.soton.ac.uk/~rwb197/ascii/ATF8.txt" for details). ***/

#define btowc(c)                    ((char)(c))
#define wctob(c)                    ((char)(c))
#define mbsinit(stat)               1
#define mbrlen(s, n, stat)          MB_CUR_MAX
#define mbrtowc(pc, s, n, stat)     (((pc) != NULL && (s) != NULL && (*(pc) = *(s))), MB_CUR_MAX)
#define wcrtomb(s, c, stat)         (((s) != NULL && (*(s) = (c))), MB_CUR_MAX)
#define mbsrtowcs(s1, s2, n, stat)  (strncpy((s1), (s2), (n)), MB_CUR_MAX * (n))
#define wcsrtombs(s1, s2, n, stat)  (strncpy((s1), (s2), (n)), MB_CUR_MAX * (n))


/*** "Wide" character/string IO functions. ***/

#define getwc(f)                    getc(f)
#define fgetwc(f)                   fgetc(f)
#define getwchar()                  getchar()
#define putwc(c, f)                 putc((c), (f))
#define fputwc(c, f)                fputc((c), (f))
#define putwchar(c)                 putchar(c)
#define ungetwc(c, f)               ungetc((c), (f))
#define fgetws(s, n, f)             fgets((s), (n), (f))
#define fputws(s, f)                fputs((s), (f))
#define fwide(f, mode)              (mode)
                                    /* (Yes: it's whatever you want it to be!) */


/*** "Wide" formatted IO functions. ***/

                                    /* The easy ones (with fixed-length argument lists): */
#define vfwprintf(f, fmt, vl)       vfprintf((f), (fmt), (vl))
#define vswprintf(s, n, fmt, vl)    vsprintf((s), (fmt), (vl))
#define vwprintf(fmt, vl)           vprintf((fmt), (vl))

                                    /* The fastidious ones (with variable-length argument lists): */
#define fwprintf                    fprintf
#define wprintf                     printf
#define swprintf                    sprintf
#define fwscanf                     fscanf
#define wscanf                      scanf
#define swscanf                     sscanf


/*** "Wide" character syntax. ***/

#define L
            /* (Yes: you can now use the new cute L'a' and L"abc" ANSI C syntax!) */


#endif /*** ( _WCHAR_H_PARODY_ :-) ***/



