#include <stdarg.h>
#include <unistd.h>
#include <setjmp.h>
+#include <errno.h>
#include <locale.h>
#ifdef USE_LIBRARY_FASTCGI
#include <fcgi_stdio.h>
#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))
#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++ )
_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
'----------------------------------------------------------------------- */
#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
_DECLARE_PROGRAM; \
int main(int argc, char **argv) \
{ \
- LANG=setlocale(_LC_ALL, ""); \
+ LANG=setlocale(LC_ALL, ""); \
+ _UNSET_LC_NUMERIC \
try \
{ \
_PROGRAM(argc,argv); \
else_switch_failures \
{ \
case SYSTEM_FAILURE: \
+ errno=_ERRNO; \
perror(errstr); /* and return -1 */ \
default: \
return -1; \
{
str a,b;
time_t t = time(NULL);
- int f;
+ file f;
str filename = "blabla.txt";
print("Local language (enviroment) is set to:", LANG);
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);
}
}