summaryrefslogtreecommitdiff
path: root/libuxre/regerror.c
blob: 397e3e53fdb639a46f94b96d9fd6ca7a0a57b81f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * Changes by Gunnar Ritter, Freiburg i. Br., Germany, November 2002.
 *
 * Sccsid @(#)regerror.c	1.4 (gritter) 3/29/03
 */
/*  UNIX(R) Regular Expresssion Library
 *
 *  Note: Code is released under the GNU LGPL
 *
 *  Copyright (C) 2001 Caldera International, Inc.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This 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
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to:
 *        Free Software Foundation, Inc.
 *        59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*	#include "synonyms.h"	*/
#include <string.h>
#include "re.h"
/*	include "_locale.h"	*/

/*	#pragma weak regerror = _regerror	*/

size_t
regerror(int err, const regex_t *ep, char *str, size_t max)
{
	const struct
	{
		int		index;
		const char	*str;
	} unk = 
	{
			88,  "unknown regular expression error"
	}, msgs[] =
	{
	/*ENOSYS*/	{ 89,  "feature not implemented" },
	/*0*/		{ 0,   "" },
	/*NOMATCH*/	{ 90,  "regular expression failed to match" },
	/*BADPAT*/	{ 91,  "invalid regular expression" },
	/*ECOLLATE*/	{ 92,  "invalid collating element construct" },
	/*ECTYPE*/	{ 93,  "invalid character class construct" },
	/*EEQUIV*/	{ 94,  "invalid equivalence class construct" },
	/*EBKTCHAR*/	{ 95,  "invalid character in '[ ]' construct" },
	/*EESCAPE*/	{ 96,  "trailing \\ in pattern" },
	/*ESUBREG*/	{ 97,  "'\\digit' out of range" },
	/*EBRACK*/	{ 98,  "'[ ]' imbalance" },
	/*EMPTYSUBBKT*/	{ 99,  "empty nested '[ ]' construct" },
	/*EMPTYPAREN*/	{ 100, "empty '\\( \\)' or '( )'" },
	/*NOPAT*/	{ 101, "empty pattern" },
	/*EPAREN*/	{ 102, "'\\( \\)' or '( )' imbalance" },
	/*EBRACE*/	{ 103, "'\\{ \\} or '{ }' imbalance" },
	/*BADBR*/	{ 104, "invalid '\\{ \\}' or '{ }'" },
	/*ERANGE*/	{ 105, "invalid endpoint in range" },
	/*ESPACE*/	{ 106, "out of regular expression memory" },
	/*BADRPT*/	{ 107, "invalid *, +, ?, \\{\\} or {} operator" },
	/*BADESC*/	{ 108, "invalid escape sequence (e.g. \\0)" },
	/*ILLSEQ*/	{ 109, "illegal byte sequence"}
	};
	const char *p;
	size_t len;
	int i;

	if (err < REG_ENOSYS || REG_ILLSEQ < err)
	{
		i = unk.index;
		p = unk.str;
	}
	else
	{
		i = msgs[err - REG_ENOSYS].index;
		p = msgs[err - REG_ENOSYS].str;
	}
/*	p = __gtxt(_str_uxlibc, i, p);	*/
	len = strlen(p) + 1;
	if (max != 0)
	{
		if (max > len)
			max = len;
		else if (max < len)
			str[--max] = '\0';
		memcpy(str, p, max);
	}
	return len;
}