From 49df11dfb79a408ff31ebadd42c16cd5d71d6a7f Mon Sep 17 00:00:00 2001 From: xchaos Date: Thu, 9 Oct 2008 15:17:08 +0000 Subject: [PATCH] LC_NUMERIC locale will be set to "C" by default git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@99 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- cll1.h | 18 +++++++++++------- demos/locale.c | 10 +++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/cll1.h b/cll1.h index 535d933..78642ff 100644 --- a/cll1.h +++ b/cll1.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #ifdef USE_LIBRARY_FASTCGI #include @@ -212,6 +213,7 @@ unsigned RANDOM_SEED=0; #define LOCAL_FAILURE 13 #define LIBRARY_FAILURE 23 #define EVIL_FAILURE 666 +#define die(MSG) longjmp(_EENV,(errstr=MSG,LOCAL_FAILURE)) #define try _NEW(E,0) if(!(_E=setjmp(_EENV))) #define fail(E) longjmp(_EENV,((E)>0?(E):FAILED_TO_FAIL)) #define pass_failure (_Eatom->__next?longjmp((pop(_Eatom,_Estack),_EENV),_E):_SYSFAIL(FAILED_TO_FAIL)) @@ -259,9 +261,10 @@ extern _DECLARE_STRSTR; #define _CTX (_CTXatom->CTX) #define _E (_Eatom->E) #define _EENV (_Eatom->ENV) +#define _ERRNO (_Eatom->ERRNO) #define _ARG1(ARG1,...) ARG1 //#define _ASSERT(EXPR) (expr?expr:fail(CONSISTENCY_FAILURE)) -#define _SYSFAIL(E) longjmp(_EENV,(E)) +#define _SYSFAIL(E) longjmp(_EENV,(_ERRNO=errno,(E))) #define _GET_MEM(TYPE) ((TYPE)malloc(sizeof(struct _##TYPE##_struct))) /* later... ((TYPE)_cll1_malloc(sizeof(struct _##TYPE##_struct))) */ #define _ANYATOM(NAME,DECL) def_mem(_##NAME##Atom ) { DECL; int c; list( _##NAME##Atom ); } //#define _FOR_COLUMNS(A,B,C) _NEW(I,0) for( prefix(A,B,C) ; A ; ((A!=B)&&prefix(A,B,C)||(A=NULL) ),_I++ ) @@ -273,7 +276,7 @@ _ANYATOM(I, int I;int J); _ANYATOM(S, str S); _ANYATOM(F, file F); _ANYATOM(CTX, void *CTX); -_ANYATOM(E, int E;jmp_buf ENV); +_ANYATOM(E, int E;jmp_buf ENV;int ERRNO); /* .----------------------------------------------------------------------. / 11. C<<1 memory contexts - alternative to garbage collection '----------------------------------------------------------------------- */ @@ -389,11 +392,10 @@ obsolete #ifndef DISABLE_LIBRARY_CLL1 _IMPLEMENT_CLL1_LIBRARY #endif -#ifdef USE_LC_NUMERIC -#define _LC_ALL LC_ALL +#ifdef USE_LC_ALL +#define _UNSET_LC_NUMERIC setlocale(LC_NUMERIC, "C"); /* LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, LC_TIME */ #else -//#define _LC_ALL LC_COLLATE|LC_CTYPE|LC_MESSAGES|LC_MONETARY|LC_TIME -#define _LC_ALL LC_TIME +#define _UNSET_LC_NUMERIC #endif #define _DECLARE_PROGRAM void _PROGRAM(int argc, char **argv) #define _PROGRAM _cll1_program @@ -401,7 +403,8 @@ _IMPLEMENT_CLL1_LIBRARY _DECLARE_PROGRAM; \ int main(int argc, char **argv) \ { \ - LANG=setlocale(_LC_ALL, ""); \ + LANG=setlocale(LC_ALL, ""); \ + _UNSET_LC_NUMERIC \ try \ { \ _PROGRAM(argc,argv); \ @@ -410,6 +413,7 @@ int main(int argc, char **argv) \ else_switch_failures \ { \ case SYSTEM_FAILURE: \ + errno=_ERRNO; \ perror(errstr); /* and return -1 */ \ default: \ return -1; \ diff --git a/demos/locale.c b/demos/locale.c index c170c13..0f7d5af 100644 --- a/demos/locale.c +++ b/demos/locale.c @@ -4,7 +4,7 @@ program { str a,b; time_t t = time(NULL); - int f; + file f; str filename = "blabla.txt"; print("Local language (enviroment) is set to:", LANG); @@ -16,12 +16,12 @@ program 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)); + echo("Time will be displayed as: ", ctime(&t)); print("Error mesages will be displayed as: "); - f = open(filename,"r"); - if(f<0) + f = fopen(filename,"r"); + if(not f) { errstr = filename; - fail(SYSTEM_FAILURE); + _SYSFAIL(SYSTEM_FAILURE); } } -- 2.30.2