/*
* Copyright (c) 2005-2006 Institute for System Programming
* Russian Academy of Sciences
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Portions of this text are reprinted and reproduced in electronic form
* from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology
* -- Portable Operating System Interface (POSIX), The Open Group Base
* Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of
* Electrical and Electronics Engineers, Inc and The Open Group. In the
* event of any discrepancy between this version and the original IEEE and
* The Open Group Standard, the original IEEE and The Open Group Standard
* is the referee document. The original Standard can be obtained online at
* http://www.opengroup.org/unix/online.html.
*/
#include "locale/ctrans/ctrans_model.seh"
#include "locale/locale/locale_model.seh"
#pragma SEC subsystem ctrans "locale.ctrans"
/*
The group of functions 'locale.ctrans' consists of:
__ctype_tolower_loc(GLIBC_2.3) [1]
__ctype_toupper_loc(GLIBC_2.3) [1]
_tolower [2]
_toupper [2]
tolower [2]
toupper [2]
*/
/********************************************************************/
/** Interface Functions **/
/********************************************************************/
/*
Linux Standard Base Core Specification 3.1
Copyright (c) 2004, 2005 Free Standards Group
__ctype_tolower_loc
NAME
__ctype_tolower_loc -- accessor function for __ctype_b_tolower array for
ctype tolower() function
SYNOPSIS
#include <ctype.h>
int32_t * * __ctype_tolower_loc(void);
DESCRIPTION
The __ctype_tolower_loc() function shall return a pointer into an array of
characters in the current locale that contains lower case equivalents for
each character in the current character set. The array shall contain a total
of 384 characters, and can be indexed with any signed or unsigned char (i.e.
with an index value between -128 and 255). If the application is
multithreaded, the array shall be local to the current thread.
This interface is not in the source standard; it is only in the binary
standard.
RETURN VALUE
The __ctype_tolower_loc() function shall return a pointer to the array of
characters to be used for the ctype() family of functions (see <ctype.h>).
*/
specification
LocChars* __ctype_tolower_loc_spec(CallContext context)
{
pre
{
return true;
}
coverage C
{
return { ReturnPointerToArrayForCtypeFamily,
"Return a pointer to the array of characters to be used for the ctype() family of functions"
};
}
/* TODO: coverage LocaleSelector; */
post
{
CString* locName = getLocale_Locale(context, SUT_LC_CTYPE);
LocaleInfo* li = getLocaleInfo_Locale(context, locName);
bool res = equals(li->CTypeToLower, __ctype_tolower_loc_spec);
if(li->CTypeToLower != NULL)
{
/*
* The __ctype_tolower_loc() function shall return a pointer into an array of
* characters in the current locale that contains lower case equivalents for each
* character in the current character set.
*/
REQ("__ctype_tolower_loc.01", "function shall return an tolower array", res);
if(whereIs_LocaleSelector(context, SUT_LC_CTYPE) == ThreadSelector)
/*
* If the application is multithreaded, the array shall be local to the current
* thread.
*/
REQ("__ctype_tolower_loc.04", "locale selector is in thread data", res);
}
return true;
}
}
void onCTypeToLowerLoc(CallContext context, LocChars* res)
{
CString* locName;
LocaleInfo* li;
assertion(res != NULL, "onCTypeToLower: res is NULL!");
locName = getLocale_Locale(context, SUT_LC_CTYPE);
li = getLocaleInfo_Locale(context, locName);
if(li->CTypeToLower == NULL) li->CTypeToLower = clone(res);
}
/*
Linux Standard Base Core Specification 3.1
Copyright (c) 2004, 2005 Free Standards Group
__ctype_toupper_loc
NAME
__ctype_toupper_loc -- accessor function for __ctype_b_toupper() array for
ctype toupper() function
SYNOPSIS
#include <ctype.h>
int32_t * * __ctype_toupper_loc(void);
DESCRIPTION
The __ctype_toupper_loc() function shall return a pointer into an array of
characters in the current locale that contains upper case equivalents for
each character in the current character set. The array shall contain a total
of 384 characters, and can be indexed with any signed or unsigned char (i.e.
with an index value between -128 and 255). If the application is
multithreaded, the array shall be local to the current thread.
This interface is not in the source standard; it is only in the binary
standard.
RETURN VALUE
The __ctype_toupper_loc() function shall return a pointer to the array of
characters to be used for the ctype() family of functions (see <ctype.h>).
*/
specification
LocChars* __ctype_toupper_loc_spec(CallContext context)
{
pre
{
return true;
}
coverage C
{
return { ReturnPointerToArrayForCtypeFamily,
"Return a pointer to the array of characters to be used for the ctype() family of functions"
};
}
/* TODO: coverage LocaleSelector; */
post
{
CString* locName = getLocale_Locale(context, SUT_LC_CTYPE);
LocaleInfo* li = getLocaleInfo_Locale(context, locName);
bool res = equals(li->CTypeToUpper, __ctype_toupper_loc_spec);
if(li->CTypeToUpper != NULL)
{
/*
* The __ctype_toupper_loc() function shall return a pointer into an array of
* characters in the current locale that contains upper case equivalents for each
* character in the current character set.
*/
REQ("__ctype_toupper_loc.01", "function shall return an toupper array", res);
if(whereIs_LocaleSelector(context, SUT_LC_CTYPE) == ThreadSelector)
/*
* If the application is multithreaded, the array shall be local to the current
* thread.
*/
REQ("__ctype_toupper_loc.04", "locale selector is in thread data", res);
}
return true;
}
}
void onCTypeToUpperLoc(CallContext context, LocChars* res)
{
CString* locName;
LocaleInfo* li;
assertion(res != NULL, "onCTypeToUpper: res is NULL!");
locName = getLocale_Locale(context, SUT_LC_CTYPE);
li = getLocaleInfo_Locale(context, locName);
if(li->CTypeToUpper == NULL) li->CTypeToUpper = clone(res);
}
/*
Linux Standard Base Core Specification 3.1
Copyright (c) 2004, 2005 Free Standards Group
refers
The Open Group Base Specifications Issue 6
IEEE Std 1003.1, 2004 Edition
Copyright (c) 2001-2004 The IEEE and The Open Group, All Rights reserved.
NAME
_tolower - transliterate uppercase characters to lowercase
SYNOPSIS
#include <ctype.h>
int _tolower(int c);
DESCRIPTION
The _tolower() macro shall be equivalent to tolower(c) except that the
application shall ensure that the argument c is an uppercase letter.
RETURN VALUE
Upon successful completion, _tolower() shall return the lowercase letter
corresponding to the argument passed.
ERRORS
No errors are defined.
*/
specification
IntT _tolower_spec(CallContext context, IntT c)
{
pre
{
/*
* except that the application shall ensure that the argument c is an uppercase
* letter.
*/
REQ("app._tolower.02", "c should be an uppercase letter", isUpperCase(context, c));
return true;
}
post
{
/*
* Upon successful completion, _tolower() shall return the lowercase letter
* corresponding to the argument passed.
*/
REQ("_tolower.03", "shall return the lowercase letter", _tolower_spec == getLowerCase(context, c));
return true;
}
}
/*
Linux Standard Base Core Specification 3.1
Copyright (c) 2004, 2005 Free Standards Group
refers
The Open Group Base Specifications Issue 6
IEEE Std 1003.1, 2004 Edition
Copyright (c) 2001-2004 The IEEE and The Open Group, All Rights reserved.
NAME
_toupper - transliterate lowercase characters to uppercase
SYNOPSIS
#include <ctype.h>
int _toupper(int c);
DESCRIPTION
The _toupper() macro shall be equivalent to toupper() except that the
application shall ensure that the argument c is a lowercase letter.
RETURN VALUE
Upon successful completion, _toupper() shall return the uppercase letter
corresponding to the argument passed.
ERRORS
No errors are defined.
*/
specification
IntT _toupper_spec(CallContext context, IntT c)
{
pre
{
/*
* except that the application shall ensure that the argument c is a lowercase
* letter.
*/
REQ("app._toupper.02", "c should be a lowercase letter", isLowerCase(context, c));
return true;
}
post
{
/*
* Upon successful completion, _toupper() shall return the uppercase letter
* corresponding to the argument passed.
*/
REQ("_toupper.03", "shall return the uppercase letter", _toupper_spec == getUpperCase(context, c));
return true;
}
}
/*
Linux Standard Base Core Specification 3.1
Copyright (c) 2004, 2005 Free Standards Group
refers
The Open Group Base Specifications Issue 6
IEEE Std 1003.1, 2004 Edition
Copyright (c) 2001-2004 The IEEE and The Open Group, All Rights reserved.
NAME
tolower - transliterate uppercase characters to lowercase
SYNOPSIS
#include <ctype.h>
int tolower(int c);
DESCRIPTION
The functionality described on this reference page is aligned with the ISO
C standard. Any conflict between the requirements described here and the ISO
C standard is unintentional. This volume of IEEE Std 1003.1-2001 defers to
the ISO C standard.
The tolower() function has as a domain a type int, the value of which is
representable as an unsigned char or the value of EOF. If the argument has
any other value, the behavior is undefined. If the argument of tolower()
represents an uppercase letter, and there exists a corresponding lowercase
letter (as defined by character type information in the program locale
category LC_CTYPE ), the result shall be the corresponding lowercase letter.
All other arguments in the domain are returned unchanged.
RETURN VALUE
Upon successful completion, tolower() shall return the lowercase letter
corresponding to the argument passed; otherwise, it shall return the
argument unchanged.
ERRORS
No errors are defined.
*/
specification
IntT tolower_spec(CallContext context, IntT c)
{
pre
{
/*
* The tolower() function has as a domain a type int, the value of which is
* representable as an unsigned char or the value of EOF. If the argument has any
* other value, the behavior is undefined.
*/
REQ("app.tolower.01", "c should be an unsigned char or EOF",
((c >= 0) && (c <= max_UCharT)) || (c == SUT_EOF)
);
return true;
}
post
{
IntT model_res = getLowerCase(context, c);
traceExtraProperty("expected return value", create_IntTObj(model_res));
if(isUpperCase(context, c))
{
/*
* If the argument of tolower() represents an uppercase letter, and there exists
* a corresponding lowercase letter (as defined by character type
* information in the program locale category LC_CTYPE ), the result shall be
* the corresponding lowercase letter.
*
* Upon successful completion, tolower() shall return the lowercase letter
* corresponding to the argument passed;
*/
REQ("tolower.02.01", "tolower should return the lowercase letter from c",
tolower_spec == model_res);
}
else
{
/*
* All other arguments in the domain are returned unchanged.
*
* otherwise, it shall return the argument unchanged.
*/
REQ("tolower.03.01", "c should remain unchanged", tolower_spec == c);
}
return true;
}
}
/*
Linux Standard Base Core Specification 3.1
Copyright (c) 2004, 2005 Free Standards Group
refers
The Open Group Base Specifications Issue 6
IEEE Std 1003.1, 2004 Edition
Copyright (c) 2001-2004 The IEEE and The Open Group, All Rights reserved.
NAME
toupper - transliterate lowercase characters to uppercase
SYNOPSIS
#include <ctype.h>
int toupper(int c);
DESCRIPTION
The functionality described on this reference page is aligned with the ISO
C standard. Any conflict between the requirements described here and the ISO
C standard is unintentional. This volume of IEEE Std 1003.1-2001 defers to
the ISO C standard.
The toupper() function has as a domain a type int, the value of which is
representable as an unsigned char or the value of EOF. If the argument has
any other value, the behavior is undefined. If the argument of toupper()
represents a lowercase letter, and there exists a corresponding uppercase
letter (as defined by character type information in the program locale
category LC_CTYPE ), the result shall be the corresponding uppercase letter.
All other arguments in the domain are returned unchanged.
RETURN VALUE
Upon successful completion, toupper() shall return the uppercase letter
corresponding to the argument passed.
ERRORS
No errors are defined.
*/
specification
IntT toupper_spec(CallContext context, IntT c)
{
pre
{
/*
* The toupper() function has as a domain a type int, the value of which is
* representable as an unsigned char or the value of EOF. If the argument has any
* other value, the behavior is undefined.
*/
REQ("app.toupper.01", "c should be an unsigned char or EOF",
((c >= 0) && (c <= max_UCharT)) || (c == SUT_EOF)
);
return true;
}
post
{
if (isLowerCase(context, c))
{
/*
* If the argument of toupper() represents a lowercase letter, and there exists a
* corresponding uppercase letter (as defined by character type information
* in the program locale category LC_CTYPE ), the result shall be the
* corresponding uppercase letter.
*
* Upon successful completion, toupper() shall return the uppercase letter
* corresponding to the argument passed.
*/
REQ("toupper.02.01", "toupper should return the uppercase letter from c",
toupper_spec == getUpperCase(context, c));
}
else
{
/*
* All other arguments in the domain are returned unchanged.
*/
REQ("toupper.03", "c should remain unchanged", toupper_spec == c);
}
return true;
}
}
/********************************************************************/
/** Helper Functions **/
/********************************************************************/
LocChars* create_LocChars()
{
return create_List(&type_IntTObj);
}