Skip to content
Merged

Ctype #283

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ build/
clib4/

.idea
.vscode
.vscode

Makefile
2 changes: 1 addition & 1 deletion GNUmakefile.os4
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ DPKG_LIB ?= clib4_1.0_amd64
WARNINGS := \
-Wall -W -Wextra -Wpointer-arith -Wsign-compare -Wmissing-prototypes \
-Wundef -Wmissing-declarations -Wunused -Wwrite-strings -Wno-unused-value -Wno-comment -Wno-missing-braces \
-Wno-deprecated-declarations -Wno-sign-compare -Wno-unused-variable -Wno-parentheses -Wno-missing-prototypes \
-Wno-deprecated-declarations -Wno-unused-variable -Wno-parentheses -Wno-missing-prototypes \
-Wstrict-aliasing -Wno-shadow -Wno-discarded-qualifiers -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing \
-Wno-type-limits -Wno-cast-function-type -Wno-frame-address -Wno-error=unused-but-set-variable -Wno-stringop-overflow -Werror \
# -Wbad-function-cast -Wconversion -Wformat
Expand Down
3 changes: 3 additions & 0 deletions libc.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ C_BYTESWAP := \
byteswap/swab64.o

C_CTYPE := \
ctype/ctype_.o \
ctype/isalnum.o \
ctype/isalpha.o \
ctype/isascii.o \
Expand Down Expand Up @@ -1010,11 +1011,13 @@ SHARED_LIB_STUBS := \
C_LIB := \
c.lib_rev.o \
$(SHARED_LIB_STUBS) \
ctype/ctype_.o \
unistd/getopt.o \
unistd/getopt_long.o \
socket/in6addr_any.o \
socket/in6addr_loopback.o


SOURCES_SHARED = $(addprefix $(OUT_SHARED)/, $(C_LIB))
SOURCES_STATIC = $(addprefix $(OUT_STATIC)/, $(C_LIB))

Expand Down
2 changes: 1 addition & 1 deletion library/argz/replace.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ _buf_findstr(const char *str, char **buf, size_t *buf_len) {
size_t i = 0;
size_t j = 0;

for (i = 0; i < *buf_len; i++) {
for (i = 0; i < (size_t) *buf_len; i++) {
if (str[0] == (*buf)[i]) {
j = i;
while (str[j - i] && (str[j - i] == (*buf)[j]))
Expand Down
6 changes: 3 additions & 3 deletions library/crypt/crypt_blowfish.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,11 +626,11 @@ static char *BF_crypt(const char *key, const char *setting,

if (setting[0] != '$' ||
setting[1] != '2' ||
setting[2] - 'a' > 25U ||
setting[2] - 'a' > 25 ||
!flags_by_subtype[setting[2] - 'a'] ||
setting[3] != '$' ||
setting[4] - '0' > 1U ||
setting[5] - '0' > 9U ||
setting[4] - '0' > 1 ||
setting[5] - '0' > 9 ||
setting[6] != '$') {
return NULL;
}
Expand Down
4 changes: 2 additions & 2 deletions library/crypt/crypt_sha256.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static const uint32_t K[64] = {

static void processblock(struct sha256 *s, const uint8_t *buf) {
uint32_t W[64], t1, t2, a, b, c, d, e, f, g, h;
int i;
size_t i;

for (i = 0; i < 16; i++) {
W[i] = (uint32_t) buf[4 * i] << 24;
Expand Down Expand Up @@ -276,7 +276,7 @@ static char *sha256crypt(const char *key, const char *setting, char *output) {

/* DS = sha(repeat-salt) */
sha256_init(&ctx);
for (i = 0; i < 16 + md[0]; i++)
for (i = 0; i < 16U + md[0]; i++)
sha256_update(&ctx, salt, slen);
sha256_sum(&ctx, smd);

Expand Down
2 changes: 1 addition & 1 deletion library/crypt/crypt_sha512.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ static char *sha512crypt(const char *key, const char *setting, char *output) {

/* DS = sha(repeat-salt) */
sha512_init(&ctx);
for (i = 0; i < 16 + md[0]; i++)
for (i = 0; i < 16U + md[0]; i++)
sha512_update(&ctx, salt, slen);
sha512_sum(&ctx, smd);

Expand Down
80 changes: 80 additions & 0 deletions library/ctype/ctype_.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

#include <ctype.h>

#define _CTYPE_DATA_0_127 \
_C, _C, _C, _C, _C, _C, _C, _C, \
_C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C, \
_C, _C, _C, _C, _C, _C, _C, _C, \
_C, _C, _C, _C, _C, _C, _C, _C, \
_S|_B, _P, _P, _P, _P, _P, _P, _P, \
_P, _P, _P, _P, _P, _P, _P, _P, \
_N, _N, _N, _N, _N, _N, _N, _N, \
_N, _N, _P, _P, _P, _P, _P, _P, \
_P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, \
_U, _U, _U, _U, _U, _U, _U, _U, \
_U, _U, _U, _U, _U, _U, _U, _U, \
_U, _U, _U, _P, _P, _P, _P, _P, \
_P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, \
_L, _L, _L, _L, _L, _L, _L, _L, \
_L, _L, _L, _L, _L, _L, _L, _L, \
_L, _L, _L, _P, _P, _P, _P, _C

#define _CTYPE_DATA_128_256 \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0

static const char _ctype_b[128 + 256] = {
_CTYPE_DATA_128_256,
_CTYPE_DATA_0_127,
_CTYPE_DATA_128_256
};

const char *__ctype_ptr = _ctype_b + 128;

const char _ctype_[1 + 256] = {
0,
_CTYPE_DATA_0_127,
_CTYPE_DATA_128_256
};
37 changes: 21 additions & 16 deletions library/ctype/ctype_headers.h
Original file line number Diff line number Diff line change
@@ -1,42 +1,47 @@
/*
* $Id: ctype_headers.h,v 1.6 2006-01-08 12:04:22 clib4devs Exp $
*/

#ifndef _CTYPE_HEADERS_H
#define _CTYPE_HEADERS_H

/****************************************************************************/

#ifndef _LOCALE_HEADERS_H
#include "locale_headers.h"
#endif /* _LOCALE_HEADERS_H */

/****************************************************************************/

#ifndef _STDLIB_LOCALEBASE_H
#include "stdlib_localebase.h"
#endif /* _STDLIB_LOCALEBASE_H */

#ifndef _STDLIB_UTILITYBASE_H
#include "stdlib_utilitybase.h"
#endif /* _STDLIB_UTILITYBASE_H */

/****************************************************************************/

#ifndef _MACROS_H
#include "macros.h"
#endif /* _MACROS_H */

/****************************************************************************/

#include <locale.h>
#include <assert.h>
#include <limits.h>
#include <ctype.h>

/****************************************************************************/
struct __locale_t {
char categories[__LC_LAST][ENCODING_LEN + 1];
char locale_string[__LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1)];

int (* wctomb)(struct _clib4 *, char *, wchar_t, mbstate_t *);

int (* mbtowc)(struct _clib4 *, wchar_t *, const char *, size_t, mbstate_t *);

int cjk_lang;
char *ctype_ptr;
struct lconv lconv;
char mb_cur_max[2];
char ctype_codeset[ENCODING_LEN + 1];
char message_codeset[ENCODING_LEN + 1];
};

int __iso_8859_val_index(int val);

int __iso_8859_index(const char *charset_ext);

extern int __isdigit_r(struct _clib4 *__clib4, int c);
extern int __isspace_r(struct _clib4 *__clib4, int c);
int __cp_val_index(int val);

int __cp_index(const char *charset_ext);
#endif /* _CTYPE_HEADERS_H */
36 changes: 3 additions & 33 deletions library/ctype/isalnum.c
Original file line number Diff line number Diff line change
@@ -1,42 +1,12 @@
/*
* $Id: ctype_isalnum.c,v 1.5 2006-01-08 12:04:22 clib4devs Exp $
* $Id: ctype_isalnum.c,v 1.6 2025-06-30 12:04:22 clib4devs Exp $
*/

#ifndef _CTYPE_HEADERS_H
#include "ctype_headers.h"
#endif /* _CTYPE_HEADERS_H */
#include <ctype.h>

#undef isalnum
#undef isalpha
#undef isdigit

int
isalnum(int c) {
int result;
struct _clib4 *__clib4 = __CLIB4;
DECLARE_LOCALEBASE_R(__clib4);

ENTER();
SHOWVALUE(c);

__locale_lock(__clib4);

if (__clib4->__locale_table[LC_CTYPE] != NULL) {
assert(LocaleBase != NULL);

/* The parameter must be either EOF or in the range of an
'unsigned char'. If it's not, then the behaviour is
undefined. */
if (c != EOF && ((0 <= c && c <= UCHAR_MAX) || ((c + 256) <= UCHAR_MAX)))
result = IsAlNum(__clib4->__locale_table[LC_CTYPE], (ULONG)(c & 255));
else
result = FALSE;
} else {
result = isalpha(c) || isdigit(c);
}

__locale_unlock(__clib4);

RETURN(result);
return (result);
return ((_ctype_ + 1)[c] & (_U | _L | _N));
}
36 changes: 3 additions & 33 deletions library/ctype/isalpha.c
Original file line number Diff line number Diff line change
@@ -1,42 +1,12 @@
/*
* $Id: ctype_isalpha.c,v 1.5 2006-01-08 12:04:22 clib4devs Exp $
* $Id: ctype_isalpha.c,v 1.6 2025-06-30 12:04:22 clib4devs Exp $
*/

#ifndef _CTYPE_HEADERS_H
#include "ctype_headers.h"
#endif /* _CTYPE_HEADERS_H */
#include <ctype.h>

#undef isalpha


int
isalpha(int c) {
int result;
struct _clib4 *__clib4 = __CLIB4;
DECLARE_LOCALEBASE_R(__clib4);

ENTER();
SHOWVALUE(c);

__locale_lock(__clib4);

if (__clib4->__locale_table[LC_CTYPE] != NULL) {
assert(LocaleBase != NULL);

/* The parameter must be either EOF or in the range of an
'unsigned char'. If it's not, then the behaviour is
undefined. */
if (c != EOF && ((0 <= c && c <= UCHAR_MAX) || ((c + 256) <= UCHAR_MAX)))
result = IsAlpha(__clib4->__locale_table[LC_CTYPE], (ULONG)(c & 255));
else
result = FALSE;
} else {
result = (('a' <= c && c <= 'z') ||
('A' <= c && c <= 'Z'));
}

__locale_unlock(__clib4);

RETURN(result);
return (result);
return ((_ctype_ + 1)[c] & (_U | _L));
}
19 changes: 6 additions & 13 deletions library/ctype/isascii.c
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
/*
* $Id: ctype_isascii.c,v 1.4 2021-02-10 23:46:22 clib4devs Exp $
* $Id: ctype_isascii.c,v 1.6 2025-06-30 12:04:22 clib4devs Exp $
*/

#ifndef _CTYPE_HEADERS_H
#include "ctype_headers.h"
#endif /* _CTYPE_HEADERS_H */
#include <ctype.h>

int
isascii(int c)
{
ENTER();
SHOWVALUE(c);
#undef isascii

int result = c >= 0 && c < 128;

RETURN(result);
return result;
int
isascii(int c) {
return c >= 0 && c < 128;
}
16 changes: 3 additions & 13 deletions library/ctype/isblank.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
/*
* $Id: ctype_isblank.c,v 1.3 2006-01-08 12:04:22 clib4devs Exp $
* $Id: ctype_isblank.c,v 1.6 2025-06-30 12:04:22 clib4devs Exp $
*/

#ifndef _CTYPE_HEADERS_H
#include "ctype_headers.h"
#endif /* _CTYPE_HEADERS_H */
#include <ctype.h>

#undef isblank

int
isblank(int c) {
int result;

ENTER();
SHOWVALUE(c);

result = (c == '\t' || c == ' ');

RETURN(result);
return (result);
return (c == ' ' || c == '\t');
}
Loading