Add ctype.h, some reorg

This commit is contained in:
bumbread 2022-06-03 00:08:59 +11:00
parent 7611f8bda4
commit 712e116741
6 changed files with 108 additions and 7 deletions

View File

@ -1,9 +1,11 @@
#include<_platform.h> #include<_platform.h>
#include<locale.h>
extern int main(); extern int main();
int mainCRTStartup() int mainCRTStartup()
{ {
setlocale(LC_ALL, "C");
return main(); return main();
} }

59
code/locale.c Normal file
View File

@ -0,0 +1,59 @@
// TODO: X-macros
// TODO: data race possible (see 7.11.1.1 p. 5)
// TODO: something about restoring locales (see 7.11.1.1 p. 8)
#include<stddef.h>
#define _LC_FIRST 0
#define _LC_LAST 5
static struct lconv _locale;
static char *_locale_str;
char *setlocale(int category, const char *locale)
{
assert(_LC_FIRST <= category && category <= _LC_LAST);
if(locale == NULL) {
return _locale_str;
}
if(strcmp(locale, "C") == 0) {
if(category == LC_ALL) {
_locale.decimal_point = ".";
_locale.thousands_sep = "";
_locale.grouping = "";
_locale.mon_decimal_point = "";
_locale.mon_thousands_sep = "";
_locale.mon_grouping = "";
_locale.positive_sign = "";
_locale.negative_sign = "";
_locale.currency_symbol = "";
_locale.frac_digits = CHAR_MAX;
_locale.p_cs_precedes = CHAR_MAX;
_locale.n_cs_precedes = CHAR_MAX;
_locale.p_sep_by_space = CHAR_MAX;
_locale.n_sep_by_space = CHAR_MAX;
_locale.p_sign_posn = CHAR_MAX;
_locale.n_sign_posn = CHAR_MAX;
_locale.int_curr_symbol = "";
_locale.int_frac_digits = CHAR_MAX;
_locale.int_p_cs_precedes = CHAR_MAX;
_locale.int_n_cs_precedes = CHAR_MAX;
_locale.int_p_sep_by_space = CHAR_MAX;
_locale.int_n_sep_by_space = CHAR_MAX;
_locale.int_p_sign_posn = CHAR_MAX;
_locale.int_n_sign_posn = CHAR_MAX;
}
}
else {
return NULL;
}
_locale_str = locale;
return locale;
}
struct lconv *localeconv(void)
{
}

10
code/string.c Normal file
View File

@ -0,0 +1,10 @@
int strcmp(const char *s1, const char *s2)
{
while(*s1 != 0 && *s2 != 0) {
if(*s1 != *s2) break;
}
if(*s1 > *s2) return 1;
if(*s1 < *s2) return -1;
return 0;
}

View File

@ -1,6 +1,15 @@
@echo off @echo off
cl /c /I ..\inc /nologo /Gm- /GR- /EHa- /Oi /W4 /Z7 test.c pushd %~dp0
clang -c -Wall test.c -otest1.obj
cl /nologo inctoarg.c
inctoarg > temp
set /P includes=<temp
del temp
cl /Z7 /X /c /I ..\inc %includes% /nologo /GS- /Gm- /GR- /EHa- /Oi /W4 test.c
::clang -c -Wall test.c -otest1.obj
link /nologo test.obj /nodefaultlib user32.lib kernel32.lib ..\lib\ciabatta.lib -subsystem:console link /nologo test.obj /nodefaultlib user32.lib kernel32.lib ..\lib\ciabatta.lib -subsystem:console
link /nologo test1.obj /nodefaultlib user32.lib kernel32.lib ..\lib\ciabatta.lib -subsystem:console ::link /nologo test1.obj /nodefaultlib user32.lib kernel32.lib ..\lib\ciabatta.lib -subsystem:console
popd

19
test/inctoarg.c Normal file
View File

@ -0,0 +1,19 @@
#include<stdio.h>
#include<stdlib.h>
int main()
{
char *include = getenv("INCLUDE");
printf(" ");
while(*include != 0) {
printf("-I \"");
while(*include != ';' && *include != 0) {
printf("%c", *include);
*include ++;
}
if(*include == ';') {
++include;
}
printf("\" ");
}
}

View File

@ -1,8 +1,10 @@
// MSVC won't use my <assert.h> unless i provide path explicitly
// idk #include <assert.h>
#include"..\inc\assert.h" #include <ctype.h>
int main() int main()
{ {
assert(0); for(char c = 'a'; c != 'z'; ++c) {
assert(isupper(toupper(c)));
}
return 0; return 0;
} }