LC_NUMERIC locale will be set to "C" by default
authorxchaos <xchaos@4bb87942-c103-4e5a-b51c-0ebff58f8515>
Thu, 9 Oct 2008 15:17:08 +0000 (15:17 +0000)
committerxchaos <xchaos@4bb87942-c103-4e5a-b51c-0ebff58f8515>
Thu, 9 Oct 2008 15:17:08 +0000 (15:17 +0000)
git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@99 4bb87942-c103-4e5a-b51c-0ebff58f8515

cll1.h
demos/locale.c

diff --git a/cll1.h b/cll1.h
index 535d933e447161ffde7cf5efa95d8445ab818ce1..78642ffbb627fe54a8afeedd91d470e9ed194746 100644 (file)
--- a/cll1.h
+++ b/cll1.h
@@ -43,6 +43,7 @@
 #include <stdarg.h>
 #include <unistd.h>
 #include <setjmp.h>
+#include <errno.h>
 #include <locale.h>
 #ifdef USE_LIBRARY_FASTCGI
 #include <fcgi_stdio.h>
@@ -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;                          \
index c170c137b5ed8cd54a01684c93cf902a56a4aa5e..0f7d5af4a19853d0c2cd10a916f3da1797f62742 100644 (file)
@@ -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);
  }
 }
This page took 0.170434 seconds and 4 git commands to generate.