|
Packit Service |
bd74e6 |
/**********************************************************************
|
|
Packit Service |
bd74e6 |
regposerr.c - Oniguruma (regular expression library)
|
|
Packit Service |
bd74e6 |
**********************************************************************/
|
|
Packit Service |
bd74e6 |
/*-
|
|
Packit Service |
bd74e6 |
* Copyright (c) 2002-2018 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
|
|
Packit Service |
bd74e6 |
* All rights reserved.
|
|
Packit Service |
bd74e6 |
*
|
|
Packit Service |
bd74e6 |
* Redistribution and use in source and binary forms, with or without
|
|
Packit Service |
bd74e6 |
* modification, are permitted provided that the following conditions
|
|
Packit Service |
bd74e6 |
* are met:
|
|
Packit Service |
bd74e6 |
* 1. Redistributions of source code must retain the above copyright
|
|
Packit Service |
bd74e6 |
* notice, this list of conditions and the following disclaimer.
|
|
Packit Service |
bd74e6 |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
Packit Service |
bd74e6 |
* notice, this list of conditions and the following disclaimer in the
|
|
Packit Service |
bd74e6 |
* documentation and/or other materials provided with the distribution.
|
|
Packit Service |
bd74e6 |
*
|
|
Packit Service |
bd74e6 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
Packit Service |
bd74e6 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit Service |
bd74e6 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit Service |
bd74e6 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
Packit Service |
bd74e6 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
Packit Service |
bd74e6 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
Packit Service |
bd74e6 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
Packit Service |
bd74e6 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
Packit Service |
bd74e6 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
Packit Service |
bd74e6 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
Packit Service |
bd74e6 |
* SUCH DAMAGE.
|
|
Packit Service |
bd74e6 |
*/
|
|
Packit Service |
bd74e6 |
|
|
Packit Service |
bd74e6 |
/* Can't include regint.h etc.. for conflict of regex_t.
|
|
Packit Service |
bd74e6 |
Define ONIGURUMA_EXPORT here for onigposix.h.
|
|
Packit Service |
bd74e6 |
*/
|
|
Packit Service |
bd74e6 |
#ifndef ONIGURUMA_EXPORT
|
|
Packit Service |
bd74e6 |
#define ONIGURUMA_EXPORT
|
|
Packit Service |
bd74e6 |
#endif
|
|
Packit Service |
bd74e6 |
|
|
Packit Service |
bd74e6 |
#include "config.h"
|
|
Packit Service |
bd74e6 |
#include "onigposix.h"
|
|
Packit Service |
bd74e6 |
|
|
Packit Service |
bd74e6 |
#ifdef HAVE_STRING_H
|
|
Packit Service |
bd74e6 |
# include <string.h>
|
|
Packit Service |
bd74e6 |
#else
|
|
Packit Service |
bd74e6 |
# include <strings.h>
|
|
Packit Service |
bd74e6 |
#endif
|
|
Packit Service |
bd74e6 |
|
|
Packit Service |
bd74e6 |
#if defined(__GNUC__)
|
|
Packit Service |
bd74e6 |
# define ARG_UNUSED __attribute__ ((unused))
|
|
Packit Service |
bd74e6 |
#else
|
|
Packit Service |
bd74e6 |
# define ARG_UNUSED
|
|
Packit Service |
bd74e6 |
#endif
|
|
Packit Service |
bd74e6 |
|
|
Packit Service |
bd74e6 |
#if defined(_WIN32) && !defined(__GNUC__)
|
|
Packit Service |
bd74e6 |
#define xsnprintf sprintf_s
|
|
Packit Service |
bd74e6 |
#define xstrncpy(dest,src,size) strncpy_s(dest,size,src,_TRUNCATE)
|
|
Packit Service |
bd74e6 |
#else
|
|
Packit Service |
bd74e6 |
#define xsnprintf snprintf
|
|
Packit Service |
bd74e6 |
#define xstrncpy strncpy
|
|
Packit Service |
bd74e6 |
#endif
|
|
Packit Service |
bd74e6 |
|
|
Packit Service |
bd74e6 |
static char* ESTRING[] = {
|
|
Packit Service |
bd74e6 |
NULL,
|
|
Packit Service |
bd74e6 |
"failed to match", /* REG_NOMATCH */
|
|
Packit Service |
bd74e6 |
"Invalid regular expression", /* REG_BADPAT */
|
|
Packit Service |
bd74e6 |
"invalid collating element referenced", /* REG_ECOLLATE */
|
|
Packit Service |
bd74e6 |
"invalid character class type referenced", /* REG_ECTYPE */
|
|
Packit Service |
bd74e6 |
"bad backslash-escape sequence", /* REG_EESCAPE */
|
|
Packit Service |
bd74e6 |
"invalid back reference number", /* REG_ESUBREG */
|
|
Packit Service |
bd74e6 |
"imbalanced [ and ]", /* REG_EBRACK */
|
|
Packit Service |
bd74e6 |
"imbalanced ( and )", /* REG_EPAREN */
|
|
Packit Service |
bd74e6 |
"imbalanced { and }", /* REG_EBRACE */
|
|
Packit Service |
bd74e6 |
"invalid repeat range {n,m}", /* REG_BADBR */
|
|
Packit Service |
bd74e6 |
"invalid range", /* REG_ERANGE */
|
|
Packit Service |
bd74e6 |
"Out of memory", /* REG_ESPACE */
|
|
Packit Service |
bd74e6 |
"? * + not preceded by valid regular expression", /* REG_BADRPT */
|
|
Packit Service |
bd74e6 |
|
|
Packit Service |
bd74e6 |
/* Extended errors */
|
|
Packit Service |
bd74e6 |
"internal error", /* REG_EONIG_INTERNAL */
|
|
Packit Service |
bd74e6 |
"invalid wide char value", /* REG_EONIG_BADWC */
|
|
Packit Service |
bd74e6 |
"invalid argument" /* REG_EONIG_BADARG */
|
|
Packit Service |
bd74e6 |
};
|
|
Packit Service |
bd74e6 |
|
|
Packit Service |
bd74e6 |
#include <stdio.h>
|
|
Packit Service |
bd74e6 |
|
|
Packit Service |
bd74e6 |
|
|
Packit Service |
bd74e6 |
extern size_t
|
|
Packit Service |
bd74e6 |
regerror(int posix_ecode, const regex_t* reg ARG_UNUSED, char* buf,
|
|
Packit Service |
bd74e6 |
size_t size)
|
|
Packit Service |
bd74e6 |
{
|
|
Packit Service |
bd74e6 |
char* s;
|
|
Packit Service |
bd74e6 |
char tbuf[35];
|
|
Packit Service |
bd74e6 |
size_t len;
|
|
Packit Service |
bd74e6 |
|
|
Packit Service |
bd74e6 |
if (posix_ecode > 0
|
|
Packit Service |
bd74e6 |
&& posix_ecode < (int )(sizeof(ESTRING) / sizeof(ESTRING[0]))) {
|
|
Packit Service |
bd74e6 |
s = ESTRING[posix_ecode];
|
|
Packit Service |
bd74e6 |
}
|
|
Packit Service |
bd74e6 |
else if (posix_ecode == 0) {
|
|
Packit Service |
bd74e6 |
s = "";
|
|
Packit Service |
bd74e6 |
}
|
|
Packit Service |
bd74e6 |
else {
|
|
Packit Service |
bd74e6 |
xsnprintf(tbuf, sizeof(tbuf), "undefined error code (%d)", posix_ecode);
|
|
Packit Service |
bd74e6 |
s = tbuf;
|
|
Packit Service |
bd74e6 |
}
|
|
Packit Service |
bd74e6 |
|
|
Packit Service |
bd74e6 |
len = strlen(s) + 1; /* use strlen() because s is ascii encoding. */
|
|
Packit Service |
bd74e6 |
|
|
Packit Service |
bd74e6 |
if (buf != NULL && size > 0) {
|
|
Packit Service |
bd74e6 |
xstrncpy(buf, s, size - 1);
|
|
Packit Service |
bd74e6 |
buf[size - 1] = '\0';
|
|
Packit Service |
bd74e6 |
}
|
|
Packit Service |
bd74e6 |
return len;
|
|
Packit Service |
bd74e6 |
}
|