From 99cd47b15d13ea0126dab46bcbec912a2f920f24 Mon Sep 17 00:00:00 2001 From: xchaos Date: Sun, 5 Oct 2008 16:54:45 +0000 Subject: [PATCH] some locale related experiments git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@98 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- cll1.h | 43 ++++++++++++++++++++++++++++++------------- demos/locale.c | 27 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 demos/locale.c diff --git a/cll1.h b/cll1.h index f6f0235..535d933 100644 --- a/cll1.h +++ b/cll1.h @@ -54,15 +54,23 @@ #include #endif /* .----------------------------------------------------------------------. - / 0. C<<1 typedefs and public gloabl variables, updated 2008-02-03 xCh. + / 0. C<<1 typedefs and public global variables, updated 2008-02-03 xCh. '----------------------------------------------------------------------- */ -typedef char * str; /* #ifdef USE_MODULE_UNICODE...typedef wchar_t * str; */ +typedef void * any; typedef unsigned char * buf; /* this will be always 8-bit usigned char * */ typedef FILE * file; typedef int bool; -extern str NIL,EOL,OFS,IFS; +#ifdef USE_WCHAR_T +typedef wchar_t * str; +#else +typedef char * str; /* Warning: full wchar_t support not yet implemented! */ +#endif +extern str NIL, EOL, OFS, IFS, LANG, errstr; /* used for: perror(errstr) */ extern unsigned RANDOM_SEED; -#define _EXPORT_GLOBALS str NIL="(null)", EOL="\n", OFS=" ", IFS=" \t\n", LANG=NULL; unsigned RANDOM_SEED=0; +#define _EXPORT_GLOBALS \ +str NIL="(null)", EOL="\n", OFS=" ", IFS=" \t\n", LANG=NULL; \ +str errstr="C<<1 0xdead"; \ +unsigned RANDOM_SEED=0; /* .----------------------------------------------------------------------. / 1. C<<1 then buddhist section, updated 2008-02-04 xCh. '----------------------------------------------------------------------- */ @@ -192,7 +200,6 @@ extern unsigned RANDOM_SEED; //#define __(METHOD,...) ( _ASSERT(ARG1(__VA_ARGS__,)), (*( __cll1_seekmethod(ARG1(__VA_ARGS__,),METHOD) )) ( __VA_ARGS__ ) ) #define call(OBJTYPE,METHOD,...) { int _N=0; OBJTYPE _OBJ; /* <-' */ while( (_OBJ=(OBJTYPE)_cll1_for_ptrs(_N++,__VA_ARGS__,NIL))!=(OBJTYPE)NIL ) _(_OBJ,METHOD); } #define def_community(TYPE,INTERFACE) def_obj(TYPE) { INTERFACE __interface; }; -#define anonymous void * /* ---- variable declarators -------------------------------------------- */ #define Get_obj(ID,MEM,...) MEM ID=get_obj(MEM,__VA_ARGS__) #define Get_obj_as(ID,COMMUNITY,MEM,...) MEM ID=get_obj_as(COMMUNITY,MEM,INTERFACE,__VA_ARGS__) @@ -260,7 +267,7 @@ extern _DECLARE_STRSTR; //#define _FOR_COLUMNS(A,B,C) _NEW(I,0) for( prefix(A,B,C) ; A ; ((A!=B)&&prefix(A,B,C)||(A=NULL) ),_I++ ) //#define _FOR_VALID_COLUMNS(A,B,C) _NEW(I,0) for( prefix(A,B,C) ; A ; ((A!=B)&&prefix(A,B,C))||(A=NULL) ) if(*A&&++_I) #define _NEW(NAME,VALUE) for(_##NAME##atom=get_mem(_##NAME##Atom),_##NAME##atom->NAME=(VALUE),_##NAME##atom->c=1,push(_##NAME##atom,_##NAME##stack);_##NAME##atom->c||(pop(_##NAME##atom,_##NAME##stack),0);_##NAME##atom->c--) -#define _ANYSTACK(NAME) _##NAME##Atom _##NAME##atom,_##NAME##stack=NULL; +#define _ANYSTACK(NAME) extern _##NAME##Atom _##NAME##atom, _##NAME##stack; _##NAME##Atom _##NAME##atom,_##NAME##stack=NULL; #define _EXPORT_STACKS _ANYSTACK(I) _ANYSTACK(S) _ANYSTACK(F) _ANYSTACK(CTX) _ANYSTACK(E) _ANYATOM(I, int I;int J); _ANYATOM(S, str S); @@ -371,7 +378,6 @@ obsolete //#define _CLL1_THROW(ERR) //#define _CLL1_TRY _NEW_E for(bind_exception(0,NULL);;) if () {.... if(_Eatom->SYS) { if(_Eatom->RET) return; else break;} else { } - /* .----------------------------------------------------------------------. / 98. We have have done our homework - now let's have some fun: '----------------------------------------------------------------------- */ @@ -380,23 +386,34 @@ obsolete #define _IMPL_INTERFACE //_SQL_IFC _CAKE_IFC _STD_IFC _X_IFC #define _IMPLEMENT_CLL1_LIBRARY _INIT_VARIABLES _IMPL_FUNCTIONS _IMPL_INTERFACE //this will be probably accomplished some other way... -//#ifndef DISABLE_CLL1_LIBRARY_IMPLEMENTATION +#ifndef DISABLE_LIBRARY_CLL1 _IMPLEMENT_CLL1_LIBRARY -//#endif -#define _PROGRAM _cll1_program +#endif +#ifdef USE_LC_NUMERIC +#define _LC_ALL LC_ALL +#else +//#define _LC_ALL LC_COLLATE|LC_CTYPE|LC_MESSAGES|LC_MONETARY|LC_TIME +#define _LC_ALL LC_TIME +#endif #define _DECLARE_PROGRAM void _PROGRAM(int argc, char **argv) +#define _PROGRAM _cll1_program #define program \ _DECLARE_PROGRAM; \ int main(int argc, char **argv) \ { \ - LANG=setlocale(LC_ALL, ""); \ + LANG=setlocale(_LC_ALL, ""); \ try \ { \ _PROGRAM(argc,argv); \ return 0; \ } \ - else \ - return -1; \ + else_switch_failures \ + { \ + case SYSTEM_FAILURE: \ + perror(errstr); /* and return -1 */ \ + default: \ + return -1; \ + } \ } \ _DECLARE_PROGRAM #ifdef USE_PREPROCESSOR diff --git a/demos/locale.c b/demos/locale.c new file mode 100644 index 0000000..c170c13 --- /dev/null +++ b/demos/locale.c @@ -0,0 +1,27 @@ +#include "cll1.h" + +program +{ + str a,b; + time_t t = time(NULL); + int f; + str filename = "blabla.txt"; + + print("Local language (enviroment) is set to:", LANG); + print("C<<1 automatically activates locales LC_COLLATE|LC_CTYPE|LC_MESSAGES|LC_MONETARY|LC_TIME but not LC_NUMERIC:"); + a = "¾luklý kùò"; + b = "®LUKLÝ KÙÒ"; + printf("str_order(\"%s\",\"%s\") = %d\n",a,b,str_order(a,b)); + printf("eq(\"%s\",\"%s\") = %s\n",a,b,btoa(eq(a,b))); + printf("eq(\"%s\",\"%s\") = %s\n",a,a,btoa(eq(a,a))); + printf("eqi(\"%s\",\"%s\") = %s\n",a,b,btoa(eqi(a,b))); + printf("PI will be displayed as: %f\n",PI); + print("Time will be displayed as: ", ctime(&t)); + print("Error mesages will be displayed as: "); + f = open(filename,"r"); + if(f<0) + { + errstr = filename; + fail(SYSTEM_FAILURE); + } +} -- 2.30.2