Tue Apr 2 21:27:01 1996 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>

* posix/glob.c (glob_pattern_p): Avoid scanning past eos if
	the pattern ends with a backslash and quoting is enabled.
	* posix/fnmatch.c (fnmatch): Likewise; return FNM_NOMATCH for such
 	patterns.
This commit is contained in:
Roland McGrath 1996-04-03 16:31:49 +00:00
parent 30de3b18a5
commit 299a95b9f0
49 changed files with 1525 additions and 1913 deletions

View file

@ -1,3 +1,10 @@
Tue Apr 2 21:27:01 1996 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* posix/glob.c (glob_pattern_p): Avoid scanning past eos if
the pattern ends with a backslash and quoting is enabled.
* posix/fnmatch.c (fnmatch): Likewise; return FNM_NOMATCH for such
patterns.
Mon Apr 1 13:34:55 1996 Roland McGrath <roland@whiz-bang.gnu.ai.mit.edu>
* stdio-common/tst-printf.c (main): Add new test case.

View file

@ -165,7 +165,9 @@ $P/subdirs.pot: $(subdirs:%=$P/%.pot)
# Combine all the messages into the final sorted template translation file.
$P/SYS_libc.pot: $(all-pot)
@rm -f $@.new
$(XGETTEXT) -d - -n -s --omit-header $^ > $@.new
sed -e 's/VERSION/$(version)/' -e "s/DATE/`date +'%Y-%m-%d %k:%M'`" \
po/header.pot > $@.new
$(XGETTEXT) -d - -n -s --omit-header $^ >> $@.new
mv -f $@.new $@
test ! -d CVS || cvs ci -m'Regenerated from source files' $@

View file

@ -610,8 +610,12 @@ cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) $(<:$(common-objpfx)%=%) -o $(@F)
endef
# We always want to use configuration definitions.
ifdef objdir
# This is always used in $(common-objdir), so we use no directory name.
BUILD_CFLAGS = -include config.h
else
BUILD_CFLAGS = -include $(..)config.h
endif
# Support the GNU standard name for this target.
.PHONY: check

View file

@ -31,8 +31,8 @@ distribute = localeinfo.h categories.def \
routines = setlocale loadlocale localeconv nl_langinfo
categories = ctype messages monetary numeric time collate
aux = $(categories:%=lc-%) $(categories:%=C-%) SYS_libc
others = localedef# locale
install-bin = localedef# locale
others = localedef locale
install-bin = localedef locale
extra-objs = $(localedef-modules:=.o) $(locale-modules:=.o) \
$(lib-modules:=.o)
@ -41,7 +41,6 @@ vpath %.h programs
localedef-modules := $(categories:%=ld-%) charmap charset linereader \
locfile stringtrans
locale-modules := ctypedump
lib-modules := simple-hash xmalloc xstrdup

View file

@ -27,7 +27,6 @@ typedef int wint_t;
typedef unsigned short int u16_t;
int euidaccess (__const char *__name, int __type);
#include_next <config.h>
#endif

View file

@ -1,163 +0,0 @@
/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ctype.h>
#include <endian.h>
#include <stdlib.h>
#include <stdio.h>
#include <netinet/in.h> /* Just for htons() */
/*#include "localedef.h"*/
#include "localeinfo.h"
/* FIXME: these values should be part of the LC_CTYPE information. */
#define mb_cur_max 1
#define mb_cur_min 1
#define SWAP32(v) \
((u32_t) (((((u32_t) (v)) & 0x000000ff) << 24) \
| ((((u32_t) (v)) & 0x0000ff00) << 8) \
| ((((u32_t) (v)) & 0x00ff0000) >> 8) \
| ((((u32_t) (v)) & 0xff000000) >> 24)))
static inline void
print_short_in_char (unsigned short val)
{
const unsigned char *p = (const unsigned char *) &val;
printf ("\"\\%03o\\%03o\"", p[0], p[1]);
}
static inline void
print_int_in_char (unsigned int val)
{
const unsigned char *p = (const unsigned char *) &val;
printf ("\"\\%03o\\%03o\\%03o\\%03o\"", p[0], p[1], p[2], p[3]);
}
int
ctype_output (void)
{
int ch;
int result = 0;
const char *locname = (getenv ("LC_ALL") ?: getenv ("LC_CTYPE") ?:
getenv ("LANG") ?: "POSIX");
puts ("#include <endian.h>\n");
if (mb_cur_max == 1)
{
printf ("const char _nl_%s_LC_CTYPE_class[] = \n", locname);
for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
{
if (((ch + 128) % 6) == 0)
printf (" /* 0x%02x */ ", ch < 0 ? 256 + ch : ch);
print_short_in_char (htons (__ctype_b [ch < 0 ? 256 + ch : ch]));
fputc (((ch + 128) % 6) == 5 ? '\n' : ' ', stdout);
}
puts (";");
}
printf ("#if BYTE_ORDER == %s\n",
BYTE_ORDER == LITTLE_ENDIAN ? "LITTLE_ENDIAN" : "BIG_ENDIAN");
if (mb_cur_max == 1)
{
printf ("const char _nl_%s_LC_CTYPE_toupper[] = \n", locname);
for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
{
if (((ch + 128) % 3) == 0)
printf (" /* 0x%02x */ ", ch < 0 ? 256 + ch : ch);
print_int_in_char (__ctype_toupper[ch < 0 ? 256 + ch : ch]);
fputc (((ch + 128) % 3) == 2 ? '\n' : ' ', stdout);
}
puts (";");
printf ("const char _nl_%s_LC_CTYPE_tolower[] = \n", locname);
for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
{
if (((ch + 128) % 3) == 0)
printf (" /* 0x%02x */ ", ch < 0 ? 256 + ch : ch);
print_int_in_char (__ctype_tolower[ch < 0 ? 256 + ch : ch]);
fputc (((ch + 128) % 3) == 2 ? '\n' : ' ', stdout);
}
puts (";");
}
else
/* not implemented */;
printf ("#elif BYTE_ORDER == %s\n",
BYTE_ORDER == LITTLE_ENDIAN ? "BIG_ENDIAN" : "LITTLE_ENDIAN");
if (mb_cur_max == 1)
{
printf ("const char _nl_%s_LC_CTYPE_toupper[] = \n", locname);
for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
{
if (((ch + 128) % 3) == 0)
printf (" /* 0x%02x */ ", ch < 0 ? 256 + ch : ch);
print_int_in_char (SWAP32 (__ctype_toupper[ch < 0 ? 256 + ch : ch]));
fputc (((ch + 128) % 3) == 2 ? '\n' : ' ', stdout);
}
puts (";");
printf ("const char _nl_%s_LC_CTYPE_tolower[] = \n", locname);
for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
{
if (((ch + 128) % 3) == 0)
printf (" /* 0x%02x */ ", ch < 0 ? 256 + ch : ch);
print_int_in_char (SWAP32 (__ctype_tolower[ch < 0 ? 256 + ch : ch]));
fputc (((ch + 128) % 3) == 2 ? '\n' : ' ', stdout);
}
puts (";");
}
else
/* not implemented */;
puts ("#else\n#error \"BYTE_ORDER\" BYTE_ORDER \" not handled.\"\n#endif\n");
printf("const struct locale_data _nl_%s_LC_CTYPE = \n\
{\n\
NULL, 0, /* no file mapped */\n\
5,\n\
{\n\
_nl_C_LC_CTYPE_class,\n\
#ifdef BYTE_ORDER == LITTLE_ENDIAN\n\
NULL, NULL,\n\
#endif\n\
_nl_C_LC_CTYPE_toupper,\n\
_nl_C_LC_CTYPE_tolower,\n\
#ifdef BYTE_ORDER == BIG_ENDIAN\n\
NULL, NULL,\n\
#endif\n\
}\n\
};\n", locname);
return result;
}
/*
* Local Variables:
* mode:c
* c-basic-offset:2
* End:
*/

View file

@ -15,7 +15,12 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <dirent.h>
#include <error.h>
#include <getopt.h>
#include <langinfo.h>
#include <libintl.h>
@ -26,13 +31,9 @@ Cambridge, MA 02139, USA. */
#include <unistd.h>
#include <errno.h>
/*#include "localedef.h"*/
#include "localeinfo.h"
/* If set dump C code describing the current locale. */
static int do_dump;
/* If set print the name of the category. */
static int show_category_name;
@ -45,7 +46,6 @@ static const struct option long_options[] =
{ "all-locales", no_argument, NULL, 'a' },
{ "category-name", no_argument, &show_category_name, 1 },
{ "charmaps", no_argument, NULL, 'm' },
{ "dump", no_argument, &do_dump, 1 },
{ "help", no_argument, NULL, 'h' },
{ "keyword-name", no_argument, &show_keyword_name, 1 },
{ "version", no_argument, NULL, 'v' },
@ -65,35 +65,48 @@ static const struct option long_options[] =
#define CTYPE_TOUPPER_EL 0
#define CTYPE_TOLOWER_EL 0
/* XXX Hack */
struct cat_item
/* Definition of the data structure which represents a category and its
items. */
struct category
{
int item_id;
int cat_id;
const char *name;
enum { std, opt } status;
enum value_type value_type;
int min;
int max;
size_t number;
struct cat_item
{
int item_id;
const char *name;
enum { std, opt } status;
enum value_type value_type;
int min;
int max;
} *item_desc;
};
/* Simple helper macro. */
#define NELEMS(arr) ((sizeof (arr)) / (sizeof (arr[0])))
/* For some tricky stuff. */
#define NO_PAREN(Item, More...) Item, ## More
/* We have all categories defined in `categories.def'. Now construct
the description and data structure used for all categories. */
#define DEFINE_ELEMENT(Item, More...) { Item, ## More },
#define DEFINE_CATEGORY(category, name, items, postload, in, check, out) \
static struct cat_item category##_desc[] = \
{ \
NO_PAREN items \
};
#include "locale/aux/categories.def"
#include "categories.def"
#undef DEFINE_CATEGORY
static struct category category[] =
{
#define DEFINE_CATEGORY(category, name, items, postload, in, check, out) \
{ _NL_NUM_##category, name, NELEMS (category##_desc) - 1, \
category##_desc, NULL, NULL, NULL, out },
#include "locale/aux/categories.def"
category##_desc },
#include "categories.def"
#undef DEFINE_CATEGORY
};
#define NCATEGORIES NELEMS (category)
@ -105,7 +118,6 @@ static void write_locales (void);
static void write_charmaps (void);
static void show_locale_vars (void);
static void show_info (const char *name);
static void dump_category (const char *name);
int
@ -118,7 +130,6 @@ main (int argc, char *argv[])
int do_charmaps = 0;
/* Set initial values for global varaibles. */
do_dump = 0;
show_category_name = 0;
show_keyword_name = 0;
@ -170,20 +181,6 @@ main (int argc, char *argv[])
if (do_help)
usage (EXIT_SUCCESS);
/* Dump C code. */
if (do_dump)
{
printf ("\
/* Generated by GNU %s %s. */\n\
\n\
#include \"localeinfo.h\"\n", program_invocation_name, VERSION);
while (optind < argc)
dump_category (argv[optind++]);
exit (EXIT_SUCCESS);
}
/* `-a' requests the names of all available locales. */
if (do_all != 0)
{
@ -235,8 +232,6 @@ Mandatory arguments to long options are mandatory for short options too.\n\
-c, --category-name write names of selected categories\n\
-k, --keyword-name write names of selected keywords\n\
\n\
--dump dump C code describing the current locale\n\
(this code can be used in the C library)\n\
"), program_invocation_name);
exit (status);
@ -389,6 +384,12 @@ show_info (const char *name)
printf ("%d", cnt == 0 || *val == CHAR_MAX ? -1 : *val);
}
break;
case word:
{
unsigned int val = (unsigned int) nl_langinfo (item->item_id);
printf ("%d", val);
}
break;
default:
}
putchar ('\n');
@ -398,13 +399,6 @@ show_info (const char *name)
{
size_t item_no;
if (category[cat_no].outfct != NULL)
/* Categories which need special handling of the output are
not written. This is especially for LC_CTYPE and LC_COLLATE.
It does not make sense to have this large number of cryptic
characters displayed. */
continue;
if (strcmp (name, category[cat_no].name) == 0)
/* Print the whole category. */
{
@ -428,117 +422,3 @@ show_info (const char *name)
}
}
}
static void
dump_category (const char *name)
{
char *locname;
size_t cat_no, item_no, nstrings;
for (cat_no = 0; cat_no < NCATEGORIES; ++cat_no)
if (strcmp (name, category[cat_no].name) == 0)
break;
if (cat_no >= NCATEGORIES)
return;
/* The NAME specifies a correct locale category. */
if (category[cat_no].outfct != NULL)
{
category[cat_no].outfct ();
return;
}
locname = (getenv ("LC_ALL") ?: getenv (name) ?:
getenv ("LANG") ?: (char *) "POSIX");
/* Determine the number of strings in advance. */
nstrings = 0;
for (item_no = 0; item_no < category[cat_no].number; ++item_no)
switch (category[cat_no].item_desc[item_no].value_type)
{
case string:
case byte:
case bytearray:
++nstrings;
break;
case stringarray:
nstrings += category[cat_no].item_desc[item_no].max;
default:
}
printf ("\nconst struct locale_data _nl_%s_%s =\n{\n"
" NULL, 0, /* no file mapped */\n %Zu,\n {\n",
locname, name, nstrings);
for (item_no = 0; item_no < category[cat_no].number; ++item_no)
switch (category[cat_no].item_desc[item_no].value_type)
{
case string:
{
const char *val = nl_langinfo (
category[cat_no].item_desc[item_no].item_id);
if (val != NULL)
printf (" \"%s\",\n", val);
else
puts (" NULL,");
}
break;
case stringarray:
{
const char *val;
int cnt;
for (cnt = 0; cnt < category[cat_no].item_desc[item_no].max; ++cnt)
{
val = nl_langinfo (
category[cat_no].item_desc[item_no].item_id + cnt);
if (val != NULL)
printf (" \"%s\",\n", val);
else
puts (" NULL,");
}
}
break;
case byte:
{
const char *val = nl_langinfo (
category[cat_no].item_desc[item_no].item_id);
if (val != NULL)
printf (" \"\\%o\",\n",
*(unsigned char *) val ? : UCHAR_MAX);
else
puts (" NULL,");
}
break;
case bytearray:
{
const char *bytes = nl_langinfo (
category[cat_no].item_desc[item_no].item_id);
if (bytes != NULL)
{
fputs (" \"", stdout);
if (*bytes != '\0')
do
printf ("\\%o", *(unsigned char *) bytes++);
while (*bytes != '\0');
else
printf ("\\%o", UCHAR_MAX);
puts ("\",");
}
else
puts (" NULL,");
}
break;
default:
break;
}
puts (" }\n};");
}

14
po/header.pot Normal file
View file

@ -0,0 +1,14 @@
# GNU libc message catalog of translations
# Copyright (C) 1996 Free Software Foundation, Inc.
# Automatically generated; contact <bug-glibc@prep.ai.mit.edu>
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: libc VERSION\n"
"PO-Revision-Date: DATE\n"
"Last-Translator: GNU libc maintainers <bug-glibc@prep.ai.mit.edu>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=ISO-8859-1\n"
"Content-Transfer-Encoding: 8-bit\n"

View file

@ -78,6 +78,9 @@ fnmatch (pattern, string, flags)
if (!(flags & FNM_NOESCAPE))
{
c = *p++;
if (c == '\0')
/* Trailing \ loses. */
return FNM_NOMATCH;
c = FOLD (c);
}
if (FOLD (*n) != c)
@ -129,7 +132,11 @@ fnmatch (pattern, string, flags)
register char cstart = c, cend = c;
if (!(flags & FNM_NOESCAPE) && c == '\\')
cstart = cend = *p++;
{
if (*p == '\0')
return FNM_NOMATCH;
cstart = cend = *p++;
}
cstart = cend = FOLD (cstart);
@ -176,8 +183,12 @@ fnmatch (pattern, string, flags)
c = *p++;
if (!(flags & FNM_NOESCAPE) && c == '\\')
/* XXX 1003.2d11 is unclear if this is right. */
++p;
{
if (*p == '\0')
return FNM_NOMATCH;
/* XXX 1003.2d11 is unclear if this is right. */
++p;
}
}
if (not)
return FNM_NOMATCH;

View file

@ -699,7 +699,7 @@ glob_pattern_p (pattern, quote)
return 1;
case '\\':
if (quote)
if (quote && p[1] != '\0')
++p;
break;

View file

@ -32,7 +32,7 @@ __BEGIN_DECLS
#include <sigset.h> /* Get `__sigset_t'. */
/* Calling environment, plus possibly a saved signal mask. */
typedef struct __jmp_buf /* C++ doesn't like tagless structs. */
typedef struct __jmp_buf_tag /* C++ doesn't like tagless structs. */
{
/* NOTE: The machine-dependent definitions of `__sigsetjmp'
assume that a `jmp_buf' begins with a `__jmp_buf'.

View file

@ -1,5 +1,5 @@
/* Internal function for converting integers to ASCII.
Copyright (C) 1994, 1995 Free Software Foundation, Inc.
Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Torbjorn Granlund <tege@matematik.su.se>
and Ulrich Drepper <drepper@gnu.ai.mit.edu>.
@ -159,10 +159,10 @@ static const struct base_table_t base_table[] =
};
/* Lower-case digits. */
static const char _itoa_lower_digits[]
const char _itoa_lower_digits[]
= "0123456789abcdefghijklmnopqrstuvwxyz";
/* Upper-case digits. */
static const char _itoa_upper_digits[]
const char _itoa_upper_digits[]
= "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

View file

@ -1,5 +1,5 @@
/* Internal function for converting integers to ASCII.
Copyright (C) 1994, 1995 Free Software Foundation, Inc.
Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -29,4 +29,31 @@ Cambridge, MA 02139, USA. */
extern char *_itoa __P ((unsigned long long int value, char *buflim,
unsigned int base, int upper_case));
static inline char *_itoa_word (unsigned long value, char *buflim,
unsigned int base, int upper_case)
{
extern const char _itoa_upper_digits[], _itoa_lower_digits[];
const char *digits = upper_case ? _itoa_upper_digits : _itoa_lower_digits;
char *bp = buflim;
switch (base)
{
#define SPECIAL(Base) \
case Base: \
do \
*--bp = digits[value % Base]; \
while ((value /= Base) != 0); \
break
SPECIAL (10);
SPECIAL (16);
SPECIAL (8);
default:
do
*--bp = digits[value % base];
while ((value /= base) != 0);
}
return bp;
}
#endif /* itoa.h */

View file

@ -1,5 +1,5 @@
/* Internal header for parsing printf format strings.
Copyright (C) 1995 Free Software Foundation, Inc.
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
This file is part of th GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -73,14 +73,14 @@ union printf_arg
/* Read a simple integer from a string and update the string pointer.
It is assumed that the first character is a digit. */
static inline unsigned int
read_int (const char * *pstr)
read_int (const UCHAR_T * *pstr)
{
unsigned int retval = **pstr - '0';
unsigned int retval = **pstr - L_('0');
while (isdigit (*++(*pstr)))
while (ISDIGIT (*++(*pstr)))
{
retval *= 10;
retval += **pstr - '0';
retval += **pstr - L_('0');
}
return retval;
@ -91,13 +91,13 @@ read_int (const char * *pstr)
/* Find the next spec in FORMAT, or the end of the string. Returns
a pointer into FORMAT, to a '%' or a '\0'. */
static inline const char *
find_spec (const char *format)
find_spec (const char *format, mbstate_t *ps)
{
while (*format != '\0' && *format != '%')
{
int len;
if (isascii (*format) || (len = mblen (format, MB_CUR_MAX)) <= 0)
if (isascii (*format) || (len = mbrlen (format, MB_CUR_MAX, ps)) <= 0)
++format;
else
format += len;
@ -116,8 +116,8 @@ extern printf_arginfo_function **__printf_arginfo_table;
the number of args consumed by this spec; *MAX_REF_ARG is updated so it
remains the highest argument index used. */
static inline size_t
parse_one_spec (const char *format, size_t posn, struct printf_spec *spec,
size_t *max_ref_arg)
parse_one_spec (const UCHAR_T *format, size_t posn, struct printf_spec *spec,
size_t *max_ref_arg, mbstate_t *ps)
{
unsigned int n;
size_t nargs = 0;
@ -135,13 +135,13 @@ parse_one_spec (const char *format, size_t posn, struct printf_spec *spec,
spec->info.pad = ' ';
/* Test for positional argument. */
if (isdigit (*format))
if (ISDIGIT (*format))
{
const char *begin = format;
const UCHAR_T *begin = format;
n = read_int (&format);
if (n > 0 && *format == '$')
if (n > 0 && *format == L_('$'))
/* Is positional parameter. */
{
++format; /* Skip the '$'. */
@ -155,32 +155,32 @@ parse_one_spec (const char *format, size_t posn, struct printf_spec *spec,
}
/* Check for spec modifiers. */
while (*format == ' ' || *format == '+' || *format == '-' ||
*format == '#' || *format == '0' || *format == '\'')
while (*format == L_(' ') || *format == L_('+') || *format == L_('-') ||
*format == L_('#') || *format == L_('0') || *format == L_('\''))
switch (*format++)
{
case ' ':
case L_(' '):
/* Output a space in place of a sign, when there is no sign. */
spec->info.space = 1;
break;
case '+':
case L_('+'):
/* Always output + or - for numbers. */
spec->info.showsign = 1;
break;
case '-':
case L_('-'):
/* Left-justify things. */
spec->info.left = 1;
break;
case '#':
case L_('#'):
/* Use the "alternate form":
Hex has 0x or 0X, FP always has a decimal point. */
spec->info.alt = 1;
break;
case '0':
case L_('0'):
/* Pad with 0s. */
spec->info.pad = '0';
break;
case '\'':
case L_('\''):
/* Show grouping in numbers if the locale information
indicates any. */
spec->info.group = 1;
@ -192,18 +192,18 @@ parse_one_spec (const char *format, size_t posn, struct printf_spec *spec,
/* Get the field width. */
spec->width_arg = -1;
spec->info.width = 0;
if (*format == '*')
if (*format == L_('*'))
{
/* The field width is given in an argument.
A negative field width indicates left justification. */
const char *begin = ++format;
const UCHAR_T *begin = ++format;
if (isdigit (*format))
if (ISDIGIT (*format))
{
/* The width argument might be found in a positional parameter. */
n = read_int (&format);
if (n > 0 && *format == '$')
if (n > 0 && *format == L_('$'))
{
spec->width_arg = n - 1;
*max_ref_arg = MAX (*max_ref_arg, n);
@ -219,7 +219,7 @@ parse_one_spec (const char *format, size_t posn, struct printf_spec *spec,
format = begin; /* Step back and reread. */
}
}
else if (isdigit (*format))
else if (ISDIGIT (*format))
/* Constant width specification. */
spec->info.width = read_int (&format);
@ -227,19 +227,19 @@ parse_one_spec (const char *format, size_t posn, struct printf_spec *spec,
spec->prec_arg = -1;
/* -1 means none given; 0 means explicit 0. */
spec->info.prec = -1;
if (*format == '.')
if (*format == L_('.'))
{
++format;
if (*format == '*')
if (*format == L_('*'))
{
/* The precision is given in an argument. */
const char *begin = ++format;
const UCHAR_T *begin = ++format;
if (isdigit (*format))
if (ISDIGIT (*format))
{
n = read_int (&format);
if (n > 0 && *format == '$')
if (n > 0 && *format == L_('$'))
{
spec->prec_arg = n - 1;
*max_ref_arg = MAX (*max_ref_arg, n);
@ -255,7 +255,7 @@ parse_one_spec (const char *format, size_t posn, struct printf_spec *spec,
format = begin;
}
}
else if (isdigit (*format))
else if (ISDIGIT (*format))
spec->info.prec = read_int (&format);
else
/* "%.?" is treated like "%.0?". */
@ -268,40 +268,41 @@ parse_one_spec (const char *format, size_t posn, struct printf_spec *spec,
spec->info.is_short = 0;
spec->info.is_long = 0;
while (*format == 'h' || *format == 'l' || *format == 'L' ||
*format == 'Z' || *format == 'q')
if (*format == L_('h') || *format == L_('l') || *format == L_('L') ||
*format == L_('Z') || *format == L_('q'))
switch (*format++)
{
case 'h':
case L_('h'):
/* int's are short int's. */
spec->info.is_short = 1;
break;
case 'l':
if (spec->info.is_long)
/* A double `l' is equivalent to an `L'. */
spec->info.is_longlong = 1;
else
/* int's are long int's. */
spec->info.is_long = 1;
break;
case 'L':
case L_('l'):
/* int's are long int's. */
spec->info.is_long = 1;
if (*format != L_('l'))
break;
++format;
/* FALLTHROUGH */
case L_('L'):
/* double's are long double's, and int's are long long int's. */
case L_('q'):
/* 4.4 uses this for long long. */
spec->info.is_long_double = 1;
break;
case 'Z':
case L_('Z'):
/* int's are size_t's. */
assert (sizeof(size_t) <= sizeof(unsigned long long int));
spec->info.is_longlong = sizeof(size_t) > sizeof(unsigned long int);
spec->info.is_long = sizeof(size_t) > sizeof(unsigned int);
break;
case 'q':
/* 4.4 uses this for long long. */
spec->info.is_longlong = 1;
break;
}
/* Get the format specification. */
spec->info.spec = *format++;
#ifdef THIS_IS_INCOMPATIBLE_WITH_LINUX_LIBC
spec->info.spec = (wchar_t) *format++;
#else
spec->info.spec = (char) *format++;
#endif
if (__printf_arginfo_table != NULL &&
__printf_arginfo_table[spec->info.spec] != NULL)
/* We don't try to get the types for all arguments if the format
@ -315,12 +316,12 @@ parse_one_spec (const char *format, size_t posn, struct printf_spec *spec,
switch (spec->info.spec)
{
case 'i':
case 'd':
case 'u':
case 'o':
case 'X':
case 'x':
case L'i':
case L'd':
case L'u':
case L'o':
case L'X':
case L'x':
if (spec->info.is_longlong)
spec->data_arg_type = PA_INT|PA_FLAG_LONG_LONG;
else if (spec->info.is_long)
@ -330,30 +331,30 @@ parse_one_spec (const char *format, size_t posn, struct printf_spec *spec,
else
spec->data_arg_type = PA_INT;
break;
case 'e':
case 'E':
case 'f':
case 'g':
case 'G':
case L'e':
case L'E':
case L'f':
case L'g':
case L'G':
if (spec->info.is_long_double)
spec->data_arg_type = PA_DOUBLE|PA_FLAG_LONG_DOUBLE;
else
spec->data_arg_type = PA_DOUBLE;
break;
case 'c':
case L'c':
spec->data_arg_type = PA_CHAR;
break;
case 's':
case L's':
spec->data_arg_type = PA_STRING;
break;
case 'p':
case L'p':
spec->data_arg_type = PA_POINTER;
break;
case 'n':
case L'n':
spec->data_arg_type = PA_INT|PA_FLAG_PTR;
break;
case 'm':
case L'm':
default:
/* An unknown spec will consume no args. */
spec->ndata_args = 0;
@ -370,14 +371,14 @@ parse_one_spec (const char *format, size_t posn, struct printf_spec *spec,
}
}
if (spec->info.spec == '\0')
if (spec->info.spec == L'\0')
/* Format ended before this spec was complete. */
spec->end_of_fmt = spec->next_fmt = format - 1;
else
{
/* Find the next format spec. */
spec->end_of_fmt = format;
spec->next_fmt = find_spec (format);
spec->next_fmt = find_spec (format, ps);
}
return nargs;

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1991, 1992, 1995 Free Software Foundation, Inc.
/* Copyright (C) 1991, 1992, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -20,6 +20,50 @@ Cambridge, MA 02139, USA. */
#include <printf.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#ifndef COMPILE_WPRINTF
# define CHAR_T char
# define UCHAR_T unsigned char
# define INT_T int
# define L_(Str) Str
# define ISDIGIT(Ch) isdigit (Ch)
# ifdef USE_IN_LIBIO
# define PUT(F, S, N) _IO_sputn (F, S, N)
# define PAD(Padchar) \
if (width > 0) \
done += _IO_padn (s, Padchar, width)
# else
# define PUTC(C, F) putc (C, F)
ssize_t __printf_pad __P ((FILE *, char pad, size_t n));
# define PAD(Padchar) \
if (width > 0) \
{ if (__printf_pad (s, Padchar, width) == -1) \
return -1; else done += width; }
# endif
#else
# define vfprintf vfwprintf
# define CHAR_T wchar_t
# define UCHAR_T uwchar_t
# define INT_T wint_t
# define L_(Str) L##Str
# define ISDIGIT(Ch) iswdigit (Ch)
# ifdef USE_IN_LIBIO
# define PUT(F, S, N) _IO_sputn (F, S, N)
# define PAD(Padchar) \
if (width > 0) \
done += _IO_wpadn (s, Padchar, width)
# else
# define PUTC(C, F) wputc (C, F)
ssize_t __wprintf_pad __P ((FILE *, wchar_t pad, size_t n));
# define PAD(Padchar) \
if (width > 0) \
{ if (__wprintf_pad (s, Padchar, width) == -1) \
return -1; else done += width; }
# endif
#endif
#include "printf-parse.h"
@ -33,15 +77,17 @@ parse_printf_format (fmt, n, argtypes)
size_t nargs; /* Number of arguments. */
size_t max_ref_arg; /* Highest index used in a positional arg. */
struct printf_spec spec;
mbstate_t mbstate;
nargs = 0;
max_ref_arg = 0;
mbstate = 0;
/* Search for format specifications. */
for (fmt = find_spec (fmt); *fmt != '\0'; fmt = spec.next_fmt)
for (fmt = find_spec (fmt, &mbstate); *fmt != '\0'; fmt = spec.next_fmt)
{
/* Parse this spec. */
nargs += parse_one_spec (fmt, nargs, &spec, &max_ref_arg);
nargs += parse_one_spec (fmt, nargs, &spec, &max_ref_arg, &mbstate);
/* If the width is determined by an argument this is an int. */
if (spec.width_arg != -1 && spec.width_arg < n)

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1991, 1992, 1993, 1995 Free Software Foundation, Inc.
/* Copyright (C) 1991, 92, 93, 95, 96 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -26,6 +26,7 @@ __BEGIN_DECLS
#define __need_FILE
#include <stdio.h>
#define __need_size_t
#define __need_wchar_t
#include <stddef.h>
@ -33,7 +34,11 @@ struct printf_info
{
int prec; /* Precision. */
int width; /* Width. */
unsigned char spec; /* Format letter. */
#ifdef THIS_IS_INCOMPATIBLE_WITH_LINUX_LIBC
wchar_t spec; /* Format letter. */
#else
char spec; /* Format letter. */
#endif
unsigned int is_long_double:1;/* L flag. */
unsigned int is_short:1; /* h flag. */
unsigned int is_long:1; /* l flag. */

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1991, 1992, 1993, 1995 Free Software Foundation, Inc.
/* Copyright (C) 1991, 1992, 1993, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -188,7 +188,7 @@ I am ready for my first lesson today.";
{
double d = FLT_MIN;
int niter = 17;
while (niter-- != 0)
printf ("%.17e\n", d / 2);
fflush (stdout);
@ -233,7 +233,18 @@ I am ready for my first lesson today.";
rfg1 ();
rfg2 ();
exit(EXIT_SUCCESS);
{
char buf[200];
int result;
sprintf(buf,"%*s%*s%*s",-1,"one",-20,"two",-30,"three");
result = strcmp (buf,
"onetwo three ");
puts (result != 0 ? "Test failed!" : "Test ok.");
return result != 0;
}
}
rfg1 ()

File diff suppressed because it is too large Load diff

View file

@ -481,20 +481,12 @@ INTERNAL (STRTOF) (nptr, endptr, group)
/* Read the fractional digits. A special case are the 'american style'
numbers like `16.' i.e. with decimal but without trailing digits. */
if (c == decimal)
{
if (isdigit (cp[1]))
{
c = *++cp;
do
{
if (c != '0' && lead_zero == -1)
lead_zero = dig_no - int_no;
++dig_no;
c = *++cp;
}
while (isdigit (c));
}
}
while (isdigit (c = *++cp))
{
if (c != '0' && lead_zero == -1)
lead_zero = dig_no - int_no;
++dig_no;
}
/* Remember start of exponent (if any). */
expp = cp;

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1992, 1995 Free Software Foundation, Inc.
/* Copyright (C) 1992, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -108,7 +108,8 @@ setenv (name, value, replace)
}
void
unsetenv (const char *name)
unsetenv (name)
const char *name;
{
const size_t len = strlen (name);
char **ep;

View file

@ -21,11 +21,12 @@
#
subdir := wcsmbs
headers := wcstr.h mbstr.h
headers := wchar.h
routines := mbsadvance mbscat mbschr mbscmp mbscpy mbsdup mbslen \
mbsncat mbsncmp mbsncpy mbsrchr mbstomb wcscat wcschr wcscmp\
wcscpy wcscspn wcsdup wcslen wcsncat wcsncmp wcsncpy wcspbrk\
wcsrchr wcsspn wcstok wcswcs
routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \
wcsncmp wcsncpy wcspbrk wcsrchr wcsspn wcstok wcsstr wmemchr \
wmemcmp wmemcpy wmemmove wmemset \
btowc wctob mbsinit \
mbrlen mbrtowc wcrtomb mbsrtowcs wcsrtombs
include ../Rules

View file

@ -1,38 +0,0 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <mbstr.h>
#include <stdlib.h>
/* Advance pointer to multibyte string by one character. */
char *
mbsadvance (mbs)
const char *mbs;
{
int clen;
/* Reset multibyte characters to their initial state. */
(void) mblen ((char *) NULL, 0);
clen = mblen (mbs, MB_CUR_MAX);
/* FIXME: when current character is illegal return same character. */
return clen <= 0 ? (char *) mbs : (char *) (mbs + clen);
}

View file

@ -1,56 +0,0 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <mbstr.h>
#include <stdlib.h>
/* Append SRC onto DEST. */
char *
mbscat (dest, src)
char *dest;
const char *src;
{
const char * const d = dest;
size_t len = 0;
int clen = 0;
/* Reset multibyte characters to their initial state. */
(void) mblen ((char *) NULL, 0);
do
{
dest += clen;
clen = mblen (dest, MB_CUR_MAX);
}
while (clen > 0);
clen = 0;
do
{
len += clen;
clen = mblen (&src[len], MB_CUR_MAX);
}
while (clen > 0);
(void) memcpy ((void *) dest, (void *) src, len);
dest[len] = '\0'; /* '\0' is the multibyte representation of L'\0' */
return (char *) d;
}

View file

@ -1,60 +0,0 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <mbstr.h>
#include <stdlib.h>
#define __need_wchar_t
#include <stddef.h>
/* Find the first occurence of MBC in MBS. */
char *
mbschr (mbs, mbc)
const char *mbs;
mbchar_t mbc;
{
int clen;
wchar_t wc;
wchar_t c;
/* Reset multibyte characters to their initial state. */
(void) mblen ((char *) NULL, 0);
clen = mbtowc (&wc, (char *) &mbc, MB_CUR_MAX);
if (clen < 0)
/* FIXME: search character is illegal. */
return NULL;
else if (clen == 0)
wc = L'\0';
clen = 0;
do
{
mbs += clen;
clen = mbtowc (&c, mbs, MB_CUR_MAX);
}
while (clen > 0 && c != wc);
if (clen < 0 || (clen == 0 && wc != L'\0'))
/* FIXME: clen < 0 means illegal character in string. */
return NULL;
return (char *) mbs;
}

View file

@ -1,47 +0,0 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <mbstr.h>
#include <stdlib.h>
/* Copy SRC to DEST. */
char *
mbscpy (dest, src)
char *dest;
const char *src;
{
size_t len = 0;
int clen = 0;
/* Reset multibyte characters to their initial state. */
(void) mblen ((char *) NULL, 0);
do
{
len += clen;
clen = mblen (&src[len], MB_CUR_MAX);
}
while (clen > 0);
(void) memcpy ((void *) dest, (void *) src, len);
dest[len] = '\0'; /* '\0' is the multibyte representation of L'\0' */
return dest;
}

View file

@ -1,51 +0,0 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <mbstr.h>
#include <stdlib.h>
/* Duplicate MBS, returning an identical malloc'd string. */
char *
mbsdup (mbs)
const char *mbs;
{
size_t len = 0;
int clen = 0;
char *retval;
/* Reset multibyte characters to their initial state. */
(void) mblen ((char *) NULL, 0);
do
{
len += clen;
clen = mblen (&mbs[len], MB_CUR_MAX);
}
while (clen > 0);
retval = (char *) malloc (len + 1);
if (retval != NULL)
{
(void) memcpy ((void *) retval, (void *) mbs, len);
retval[len] = '\0'; /* '\0' is the multibyte representation of L'\0' */
}
return retval;
}

View file

@ -1,45 +0,0 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <mbstr.h>
#include <stdlib.h>
/* Return the length of MBS. */
size_t
mbslen (mbs)
const char *mbs;
{
size_t len = 0;
int clen = 0;
/* Reset multibyte characters to their initial state. */
(void) mblen ((char *) NULL, 0);
do
{
len += clen;
clen = mblen (&mbs[len], MB_CUR_MAX);
}
while (clen > 0);
/* FIXME: if string contains an illegal character the length upto this
character is returned. */
return len;
}

View file

@ -1,61 +0,0 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <mbstr.h>
#include <stdlib.h>
/* Append no more than N multi-byte characters from SRC onto DEST. */
char *
mbsncat (dest, src, n)
char *dest;
const char *src;
size_t n;
{
const char * const d = dest;
const char * const s = src;
size_t len = 0;
int clen = 0;
if (n == 0)
return (char *) d;
/* Reset multibyte characters to their initial state. */
(void) mblen ((char *) NULL, 0);
do
{
dest += clen;
clen = mblen (dest, MB_CUR_MAX);
}
while (clen > 0);
clen = 0;
do
{
src += clen;
clen = mblen (src, MB_CUR_MAX);
}
while (clen > 0 && ++len < n);
(void) memcpy ((void *) dest, (void *) s, src - s);
dest[src - s] = '\0'; /* '\0' is the multibyte representation of L'\0' */
return (char *) d;
}

View file

@ -1,68 +0,0 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <mbstr.h>
#include <stdlib.h>
#define __need_wchar_t
/* FIXME: should be defined in stddef.h.
!!! #define __need_uwchar_t */
typedef unsigned int uwchar_t;
#include <stddef.h>
/* Compare N characters of MBS1 and MBS2. */
int
mbsncmp (mbs1, mbs2, n)
const char *mbs1;
const char *mbs2;
size_t n;
{
size_t len = 0;
int clen1 = 0;
int clen2 = 0;
uwchar_t c1;
uwchar_t c2;
if (n == 0)
return 0;
/* Reset multibyte characters to their initial state. */
(void) mblen ((char *) NULL, 0);
do
{
clen1 = mbtowc ((wchar_t *) &c1, mbs1, MB_CUR_MAX);
clen2 = mbtowc ((wchar_t *) &c2, mbs2, MB_CUR_MAX);
if (clen1 == 0)
return clen2 == 0 ? 0 : -1;
if (clen2 == 0)
return 1;
if (clen1 < 0 || clen2 < 0)
/* FIXME: an illegal character appears. What to do? */
return c1 - c2;
mbs1 += clen1;
mbs2 += clen2;
}
while (c1 == c2 && ++len < n);
return len < n ? c1 - c2 : 0;
}

View file

@ -1,55 +0,0 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <mbstr.h>
#include <stdlib.h>
/* Copy no more than N characters of SRC to DEST. */
char *
mbsncpy (dest, src, n)
char *dest;
const char *src;
size_t n;
{
const char * const s = src;
size_t len = 0;
int clen = 0;
if (n == 0)
{
dest[0] = '\0'; /* '\0' is the multibyte representation of L'\0' */
return dest;
}
/* Reset multibyte characters to their initial state. */
(void) mblen ((char *) NULL, 0);
do
{
src += clen;
clen = mblen (src, MB_CUR_MAX);
}
while (clen > 0 && ++len < n);
(void) memcpy ((void *) dest, (void *) s, src - s);
dest[src - s] = '\0'; /* '\0' is the multibyte representation of L'\0' */
return dest;
}

View file

@ -1,61 +0,0 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <mbstr.h>
#include <stdlib.h>
#define __need_wchar_t
#include <stddef.h>
/* Find the last occurence of MBC in MBS. */
char *
mbsrchr (mbs, mbc)
const char *mbs;
mbchar_t mbc;
{
const char * retval = NULL;
int clen;
wchar_t wc;
wchar_t c;
/* Reset multibyte characters to their initial state. */
(void) mblen ((char *) NULL, 0);
clen = mbtowc (&wc, (char *) &mbc, MB_CUR_MAX);
if (clen < 0)
/* FIXME: search character MBC is illegal. */
return NULL;
else if (clen == 0)
wc = L'\0';
clen = 0;
do
{
mbs += clen;
clen = mbtowc (&c, mbs, MB_CUR_MAX);
}
while (clen > 0 && c != wc);
if (clen < 0)
/* FIXME: clen < 0 means illegal character in string. */
return NULL;
return (char *) (clen > 0 || (clen == 0 && wc == L'\0') ? mbs : retval);
}

View file

@ -1,42 +0,0 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <mbstr.h>
#include <stdlib.h>
/* Advance pointer to multibyte string by one character. */
mbchar_t
mbstomb (mbs)
const char *mbs;
{
mbchar_t retval = 0;
int clen;
/* Reset multibyte characters to their initial state. */
(void) mblen ((char *) NULL, 0);
clen = mblen (mbs, MB_CUR_MAX);
if (clen > 0)
(void) memcpy (&retval, mbs, clen);
/* FIXME: when current character is illegal return '\0'. */
return retval;
}

View file

@ -1,69 +0,0 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the, Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifndef _MBSTRING_H
#define _MBSTRING_H 1
#include <features.h>
#include <limits.h>
#define __need_size_t
#include <stddef.h>
__BEGIN_DECLS
/* This data type should be large enough to contain MB_CUR_MAX bytes. */
typedef unsigned int mbchar_t;
/* Copy SRC to DEST. */
extern char *mbscpy __P ((char *__dest, __const char *__src));
/* Copy no more than N multi-byte characters of SRC to DEST. */
extern char *mbsncpy __P ((char *__dest, __const char *__src, size_t __n));
/* Append SRC onto DEST. */
extern char *mbscat __P ((char *__dest, __const char *__src));
/* Append no more than N characters from SRC onto DEST. */
extern char *mbsncat __P ((char *__dest, __const char *__src, size_t __n));
/* Compare S1 and S2. */
extern int mbscmp __P ((__const char *__s1, __const char *__s2));
/* Compare N characters of S1 and S2. */
extern int mbsncmp __P ((__const char *__s1, __const char *__s2, size_t __n));
/* Duplicate MBS, returning an identical malloc'd string. */
extern char *mbsdup __P ((__const char *__s));
/* Find the first occurence of MBC in MBS. */
extern char *mbschr __P ((__const char *__mbs, mbchar_t mbc));
/* Find the last occurence of MBC in MBS. */
extern char *mbsrchr __P ((__const char *__mbs, mbchar_t mbc));
/* Return the length of MBS. */
extern size_t mbslen __P ((__const char *__mbs));
/* Advance pointer to multibyte string by one character. */
extern char *mbsadvance __P ((__const char *__mbs));
/* Return first character in MBS. */
extern mbchar_t mbstomb __P ((__const char *__mbs));
__END_DECLS
#endif /* mbstring.h */

View file

@ -1,5 +1,6 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@ -16,14 +17,14 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <wcstr.h>
#include <wchar.h>
/* Append SRC on the end of DEST. */
wchar_t *
wcscat (dest, src)
wchar_t *dest;
const wchar_t *src;
wchar_t *dest;
const wchar_t *src;
{
register wchar_t *s1 = dest;
register const wchar_t *s2 = src;

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -16,14 +16,14 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <wcstr.h>
#include <wchar.h>
/* Find the first ocurrence of WC in WCS. */
wchar_t *
wcschr (wcs, wc)
register const wchar_t *wcs;
register const wchar_t wc;
register const wchar_t *wcs;
register const wchar_t wc;
{
while (*wcs != L'\0')
if (*wcs == wc)

View file

@ -1,5 +1,6 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@ -16,16 +17,16 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <wcstr.h>
#include <wchar.h>
/* Compare S1 and S2, returning less than, equal to or
greater than zero if S1 is lexiographically less than,
greater than zero if S1 is lexicographically less than,
equal to or greater than S2. */
int
wcscmp (s1, s2)
const wchar_t *s1;
const wchar_t *s2;
const wchar_t *s1;
const wchar_t *s2;
{
uwchar_t c1, c2;

View file

@ -1,5 +1,6 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@ -16,7 +17,7 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <wcstr.h>
#include <wchar.h>
#define __need_ptrdiff_t
#include <stddef.h>
@ -25,8 +26,8 @@ Cambridge, MA 02139, USA. */
/* Copy SRC to DEST. */
wchar_t *
wcscpy (dest, src)
wchar_t *dest;
const wchar_t *src;
wchar_t *dest;
const wchar_t *src;
{
wchar_t *wcp = (wchar_t *) src;
wchar_t c;

View file

@ -1,5 +1,6 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@ -16,15 +17,15 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <wcstr.h>
#include <wchar.h>
/* Return the length of the maximum initial segment
of WCS which contains only wide-characters not in REJECT. */
size_t
wcscspn (wcs, reject)
const wchar_t *wcs;
const wchar_t *reject;
const wchar_t *wcs;
const wchar_t *reject;
{
register size_t count = 0;

View file

@ -1,5 +1,6 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@ -16,7 +17,7 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <wcstr.h>
#include <wchar.h>
#include <string.h>
#include <stdlib.h>
@ -24,7 +25,7 @@ Cambridge, MA 02139, USA. */
/* Duplicate S, returning an identical malloc'd string. */
wchar_t *
wcsdup (s)
const wchar_t *s;
const wchar_t *s;
{
size_t len = (wcslen (s) + 1) * sizeof (wchar_t);
void *new = malloc (len);

View file

@ -1,5 +1,6 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@ -16,13 +17,13 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <wcstr.h>
#include <wchar.h>
/* Copy SRC to DEST. */
size_t
wcslen (s)
const wchar_t *s;
const wchar_t *s;
{
size_t len = 0;

View file

@ -1,5 +1,6 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@ -16,15 +17,15 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <wcstr.h>
#include <wchar.h>
/* Append no more than N wide-character of SRC onto DEST. */
wchar_t *
wcsncat (dest, src, n)
wchar_t *dest;
const wchar_t *src;
size_t n;
wchar_t *dest;
const wchar_t *src;
size_t n;
{
wchar_t c;
wchar_t * const s = dest;

View file

@ -1,5 +1,6 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@ -16,7 +17,7 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <wcstr.h>
#include <wchar.h>
/* Compare no more than N characters of S1 and S2,
@ -25,9 +26,9 @@ Cambridge, MA 02139, USA. */
greater than S2. */
int
wcsncmp (s1, s2, n)
const wchar_t *s1;
const wchar_t *s2;
size_t n;
const wchar_t *s1;
const wchar_t *s2;
size_t n;
{
uwchar_t c1 = L'\0';
uwchar_t c2 = L'\0';

View file

@ -1,5 +1,6 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@ -16,18 +17,18 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <wcstr.h>
#include <wchar.h>
/* Copy no more than N wide-characters of SRC to DEST. */
wchar_t *
wcsncpy (dest, src, n)
wchar_t *dest;
const wchar_t *src;
size_t n;
wchar_t *dest;
const wchar_t *src;
size_t n;
{
wchar_t c;
wchar_t * const s = dest;
wchar_t *const s = dest;
--dest;

View file

@ -1,5 +1,6 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@ -16,14 +17,14 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <wcstr.h>
#include <wchar.h>
/* Find the first ocurrence in WCS of any wide-character in ACCEPT. */
wchar_t *
wcspbrk (wcs, accept)
register const wchar_t *wcs;
register const wchar_t *accept;
register const wchar_t *wcs;
register const wchar_t *accept;
{
while (*wcs != L'\0')
if (wcschr (accept, *wcs) == NULL)

View file

@ -1,5 +1,6 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@ -16,14 +17,14 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <wcstr.h>
#include <wchar.h>
/* Find the last ocurrence of WC in WCS. */
wchar_t *
wcsrchr (wcs, wc)
register const wchar_t *wcs;
register const wchar_t wc;
register const wchar_t *wcs;
register const wchar_t wc;
{
const wchar_t *retval = NULL;

View file

@ -1,5 +1,6 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@ -16,15 +17,15 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <wcstr.h>
#include <wchar.h>
/* Return the length of the maximum initial segment
of WCS which contains only wide-characters in ACCEPT. */
size_t
wcsspn (wcs, accept)
const wchar_t *wcs;
const wchar_t *accept;
const wchar_t *wcs;
const wchar_t *accept;
{
register const wchar_t *p;
register const wchar_t *a;

View file

@ -1,5 +1,6 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@ -16,52 +17,42 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <wcstr.h>
#include <wchar.h>
#include <errno.h>
static wchar_t *olds = NULL;
/* Parse WCS into tokens separated by characters in DELIM.
If WCS is NULL, the last string wcstok() was called with is
used. */
/* Parse WCS into tokens separated by characters in DELIM. If WCS is
NULL, the last string wcstok() was called with is used. */
wchar_t *
wcstok (wcs, delim)
register wchar_t *wcs;
register const wchar_t *delim;
wcstok (wcs, delim, ptr)
register wchar_t *wcs;
register const wchar_t *delim;
register wchar_t **ptr;
{
wchar_t *token;
wchar_t *result;
if (wcs == NULL)
{
if (olds == NULL)
{
errno = EINVAL;
return NULL;
}
else
wcs = olds;
}
wcs = *ptr;
/* Scan leading delimiters. */
wcs += wcsspn (wcs, delim);
if (*wcs == L'\0')
{
olds = NULL;
*ptr = NULL;
return NULL;
}
/* Find the end of the token. */
token = wcs;
wcs = wcspbrk (token, delim);
result = wcs;
wcs = wcspbrk (result, delim);
if (wcs == NULL)
/* This token finishes the string. */
olds = NULL;
*ptr = NULL;
else
{
/* Terminate the token and make OLDS point past it. */
*wcs = L'\0';
olds = wcs + 1;
*ptr = wcs + 1;
}
return token;
return result;
}

View file

@ -1,84 +0,0 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifndef _WCSTRING_H
#define _WCSTRING_H 1
#include <features.h>
__BEGIN_DECLS
/* Get size_t, wchar_t, uwchar_t and NULL from <stddef.h>. */
#define __need_size_t
#define __need_wchar_t
/* #define __need_uwchar_t */
#define __need_NULL
#include <stddef.h>
/* FIXME: Should go with this or another name in stddef.h. */
typedef unsigned int uwchar_t;
/* Copy SRC to DEST. */
extern wchar_t *wcscpy __P ((wchar_t *__dest, __const wchar_t *__src));
/* Copy no more than N wide-characters of SRC to DEST. */
extern wchar_t *wcsncpy __P ((wchar_t *__dest, __const wchar_t *__src,
size_t __n));
/* Append SRC onto DEST. */
extern wchar_t *wcscat __P ((wchar_t *__dest, __const wchar_t *__src));
/* Append no more than N wide-characters of SRC onto DEST. */
extern wchar_t *wcsncat __P ((wchar_t *__dest, __const wchar_t *__src,
size_t __n));
/* Compare S1 and S2. */
extern int wcscmp __P ((__const wchar_t *__s1, __const wchar_t *__s2));
/* Compare N wide-characters of S1 and S2. */
extern int wcsncmp __P ((__const wchar_t *__s1, __const wchar_t *__s2,
size_t __n));
/* Duplicate S, returning an identical malloc'd string. */
extern wchar_t *wcsdup __P ((__const wchar_t *__s));
/* Find the first occurence of WC in WCS. */
extern wchar_t *wcschr __P ((__const wchar_t *__wcs, wchar_t __wc));
/* Find the last occurence of WC in WCS. */
extern wchar_t *wcsrchr __P ((__const wchar_t *__wcs, wchar_t __wc));
/* Return the length of the initial segmet of WCS which
consists entirely of wide-characters not in REJECT. */
extern size_t wcscspn __P ((__const wchar_t *__wcs,
__const wchar_t *__reject));
/* Return the length of the initial segmet of WCS which
consists entirely of wide-characters in ACCEPT. */
extern size_t wcsspn __P ((__const wchar_t *__wcs, __const wchar_t *__accept));
/* Find the first occurence in WCS of any character in ACCEPT. */
extern wchar_t *wcspbrk __P ((__const wchar_t *__wcs,
__const wchar_t *__accept));
/* Find the first occurence of NEEDLE in HAYSTACK. */
extern wchar_t *wcswcs __P ((__const wchar_t *__haystack,
__const wchar_t *__needle));
/* Divide WCS into tokens separated by characters in DELIM. */
extern wchar_t *wcstok __P ((wchar_t *__s, __const wchar_t *__delim));
/* Return the number of wide-characters in S. */
extern size_t wcslen __P ((__const wchar_t *__s));
__END_DECLS
#endif /* wcstring.h */

View file

@ -1,97 +0,0 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
/*
* The original strstr() file contains the following comment:
*
* My personal strstr() implementation that beats most other algorithms.
* Until someone tells me otherwise, I assume that this is the
* fastest implementation of strstr() in C.
* I deliberately chose not to comment it. You should have at least
* as much fun trying to understand it, as I had to write it :-).
*
* Stephen R. van den Berg, berg@pool.informatik.rwth-aachen.de */
#include <wcstr.h>
wchar_t *
wcswcs (haystack, needle)
const wchar_t *haystack;
const wchar_t *needle;
{
register wchar_t b, c;
if ((b = *needle) != L'\0')
{
haystack--; /* possible ANSI violation */
do
if ((c = *++haystack) == L'\0')
goto ret0;
while (c != b);
if (!(c = *++needle))
goto foundneedle;
++needle;
goto jin;
for (;;)
{
register wchar_t a;
register const wchar_t *rhaystack, *rneedle;
do
{
if (!(a = *++haystack))
goto ret0;
if (a == b)
break;
if ((a = *++haystack) == L'\0')
goto ret0;
shloop: ;
}
while (a != b);
jin: if (!(a = *++haystack))
goto ret0;
if (a != c)
goto shloop;
if (*(rhaystack = haystack-- + 1) == (a = *(rneedle = needle)))
do
{
if (a == L'\0')
goto foundneedle;
if (*++rhaystack != (a = *++needle))
break;
if (a == L'\0')
goto foundneedle;
}
while (*++rhaystack == (a = *++needle));
needle=rneedle; /* took the register-poor approach */
if (a == L'\0')
break;
}
}
foundneedle:
return (wchar_t*)haystack;
ret0:
return NULL;
}