Rewrite from scratch, as print-copyr.c.

This commit is contained in:
Paul Eggert
2001-09-21 22:19:09 +00:00
parent 7a1b6cfa67
commit 4b5d60ef38

View File

@@ -1,4 +1,4 @@
/* copysym.c -- Return a copyright symbol suitable for the current locale. /* Print a copyright notice suitable for the current locale.
Copyright (C) 2001 Free Software Foundation, Inc. Copyright (C) 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
@@ -21,65 +21,32 @@
# include <config.h> # include <config.h>
#endif #endif
#include <stddef.h> #include "unicodeio.h"
#include "print-copyr.h"
#if HAVE_ICONV #include <stdio.h>
# include <iconv.h>
# if ! USE_INCLUDED_LIBINTL && HAVE_LANGINFO_CODESET #define COPYRIGHT_SIGN 0x00A9
# include <langinfo.h>
# endif
# if HAVE_STDLIB_H /* Print "(C)". */
# include <stdlib.h>
# endif
#endif
#include "copysym.h" static int
print_parenthesized_c (unsigned int code, void *callback_arg)
/* Store into BUF (of size BUFSIZE) a representation of the copyright
symbol (C-in-a-circle) that is a valid text string for the current
locale. Return BUF if successful, and a pointer to some other
string otherwise. */
char const *
copyright_symbol (char *buf, size_t bufsize)
{ {
#if HAVE_ICONV FILE *stream = callback_arg;
char const *outcharset = getenv ("OUTPUT_CHARSET"); return fputs ("(C)", stream);
}
if (! (outcharset && *outcharset))
{ /* Print "Copyright (C) " followed by NOTICE and then a newline,
#if USE_INCLUDED_LIBINTL transliterating "(C)" to an actual copyright sign (C-in-a-circle)
extern char const *locale_charset (void); if possible. */
outcharset = locale_charset ();
#else void
# if HAVE_LANGINFO_CODESET print_copyright (char const *notice)
outcharset = nl_langinfo (CODESET); {
# endif fputs ("Copyright ", stdout);
#endif unicode_to_mb (COPYRIGHT_SIGN, print_unicode_success, print_parenthesized_c,
} stdout);
fputc (' ', stdout);
if (*outcharset) puts (notice);
{
iconv_t conv = iconv_open (outcharset, "UTF-8");
if (conv != (iconv_t) -1)
{
static char const copyright_utf_8[] = "\302\251";
char ICONV_CONST *inptr = (char ICONV_CONST *) &copyright_utf_8;
size_t inleft = sizeof copyright_utf_8;
char *outptr = buf;
size_t chars = iconv (conv, &inptr, &inleft, &outptr, &bufsize);
iconv_close (conv);
if (chars != (size_t) -1)
return buf;
}
}
#endif
/* "(C)" is the best we can do in ASCII. */
return "(C)";
} }