'---------------------------------------------------------------------- */
#ifndef DISABLE_LIBRARY_LIBC
#include <string.h>
+#include <strings.h>
#include <malloc.h>
#include <time.h>
#include <stdlib.h>
'----------------------------------------------------------------------- */
#ifndef DISABLE_MODULE_THEN_BUDDHISM
#define then
-#define boolean int
-#define MAYBE (int)((RANDOM_SEED?random():(srandom(RANDOM_SEED=time(NULL)),random()))%2)
-#define WHOKNOWS (int)(srandom(time(NULL)),random()%2)
-#define create_var(ID,TYPE,INIT) TYPE ID=INIT
-#define define_var(ID,TYPE) TYPE ID
+#define MAYBE (int)((long)(RANDOM_SEED?random():((RANDOM_SEED=(unsigned)time(NULL)),srandom(RANDOM_SEED),random()))%2)
+#define WHOKNOWS (int)(srandom((unsigned)time(NULL)),random()%2)
+#define create_var(ID,TYPE,EXPR) TYPE ID=(EXPR)
+#define def_var(ID,TYPE) TYPE ID
+//#define _CLL1_YES char *YES="TRUE\nYES\nJA\nOUI\nDA\nANO\nY\n1";
+//#define atob(EXPR) (word_in_stri(YES,(EXPR))?1:0)
+//#else
+#define _CLL1_YES char *YES="TRUE";
+#define atob(EXPR) (eqi((EXPR),YES)?1:0)
#endif
/* .----------------------------------------------------------------------.
- / 3. C<<1 almost then buddhist section, updated 2008-01-26 xCh.
+ / 1. C<<1 almost then buddhist section, updated 2008-01-26 xCh.
'----------------------------------------------------------------------- */
#define not !
#define and &&
#define or ||
+#define bool int
#define TRUE 1
#define FALSE 0
-#define coalesce(VAR,NOTNULLNORFALSE) (VAR?VAR:(NOTNULLNORFALSE))
-#define bool_str(VALUE) ((VALUE)?"TRUE":"FALSE")
-#define _CLL1_GLOBALS char *NIL="NULL", *EOL="\n", *OFS=" ", *IFS=" \t\n"; time_t RANDOM_SEED=0;
+#define btoa(EXPR) ((EXPR)?"TRUE":"FALSE")
+#define coalesce(VAR,EXPR) (VAR?VAR:(EXPR))
+#define _CLL1_GLOBALS char *NIL="NULL", *EOL="\n", *OFS=" ", *IFS=" \t\n"; unsigned RANDOM_SEED=0;
/* .----------------------------------------------------------------------.
/ 4. C<<1 data declaration and allocation, updated 2008-01-31 xCh.
'----------------------------------------------------------------------- */
#define this_is(TYPE) struct *TYPE this
#define create_mem(ID,...) struct _ARG1(__VA_ARGS__,) *ID=get_mem(__VA_ARGS__)
#define new_mem(ID,...) struct _ARG1(__VA_ARGS__,) *ID=init_mem(__VA_ARGS__)
-#define define_mem(ID,TYPE) struct TYPE *ID=NULL
-#define define_mems(ID1,ID2,TYPE) define_mem(ID1,TYPE); define_mem(ID2,TYPE)
+#define def_mem(ID,TYPE) struct TYPE *ID=NULL
+#define def_mems(ID1,ID2,TYPE) struct TYPE *ID1=NULL, *ID2=NULL
#define get_mem(...) (struct _ARG1(__VA_ARGS__,)*)_cll1_malloc(sizeof(struct _ARG1(__VA_ARGS__,)), _ARG2(__VA_ARGS__,,) - 0 )
#define init_mem(...) _mem_##TYPE##_( _ARG2(__VA_ARGS__,,) - 0 )
#define construct_mem(TYPE) (struct TYPE *)_mem_##TYPE##_(void) { create_mem(this,TYPE);/* <-' */ _init_mem_##TYPE##_(this); return this; } _init_mem_##TYPE##_(this_is(TYPE))
#define create_list(ID1,I2,TYPE) create_mem(ID1,TYPE); struct TYPE *ID2=((ID1->__next=NULL),ID1)
-#define create_str(ID,INIT) char *ID=INIT
+#define create_str(ID,EXPR) char *ID=(EXPR)
#define new_str(ID,...) char *ID=_cll1_get_str(__VA_ARGS__,NIL)
-#define define_str(ID) char *ID=NULL
+#define def_str(ID) char *ID=NULL
#define get_str(...) _cll1_get_str(__VA_ARGS__,NIL)
#define create_context(ID) create_mem(ID,_CTXAtom)
-#define define_context(ID) define_mem(ID,_CTXAtom)
+#define def_context(ID) def_mem(ID,_CTXAtom)
#define list(TYPE) struct TYPE *__next
#define tree(TYPE) struct TYPE *__next; struct TYPE *__seek
#define dictionary(TYPE) struct TYPE *__next; struct TYPE *__seek; char *__key
/* .----------------------------------------------------------------------.
/ 5. C<<1 string manipulation, updated 2008-01-26 xCh.
'----------------------------------------------------------------------- */
-#define eq(A,B) !strcmp(A,B)
-#define eqi(A,B) !strcasecmp(A,B)
+#define eq(A,B) !_cll1_strcmp(A,B)
+#define eqi(A,B) !_cll1_strcmpi(A,B)
+#define in_str(A,B) _cll1_strstr(A,B)
+#define word_in_str(A,B) _cll1_wordinstr(A,B,0)
#define print(...) _cll1_print(__VA_ARGS__,NIL)
#define fprint(...) _cll1_fprint(__VA_ARGS__,NIL)
#define file_print(...) _cll1_fprint(_F,__VA_ARGS__,NIL)
//to do: store
#define order_by(K1,K2) (K1>K2)
#define desc_order_by(K1,K2) (K1<K2)
-#define sort_by(K1,K2) (strcasecmp(K1, K2)>0)
-#define desc_sort_by(K1,K2) (strcasecmp(K1, K2)<0)
-#define ascii_by(K1,K2) (strcmp(K1, K2)>0)
-#define desc_ascii_by(K1,K2) (strcmp(K1, K2)<0)
+#define sort_by(K1,K2) (_cll1_strcmpi(K1,K2)>0)
+#define desc_sort_by(K1,K2) (_cll1_strcmpi(K1,K2)<0)
+#define ascii_by(K1,K2) (_cll1_strcmp(K1,K2)>0)
+#define desc_ascii_by(K1,K2) (_cll1_strcmp(K1,K2)<0)
#define insert(NODE,HEAD,EXP,K) { if(HEAD) { void **_L=NULL, *H=HEAD; /* <-' */ for_search(HEAD,H,EXP(HEAD->K,NODE->K)) { if(_L) {*_L=NODE; NODE->__next=HEAD; } else push(NODE,H); break; } else _L=(void *)&(HEAD->__next); if(!HEAD)*_L=NODE; HEAD=H; } else if (NODE) { push(NODE,HEAD); HEAD->__next=NULL; } }
#define sort(NODE,HEAD,EXP,K) { void *_NEXT; /* <-' */ NODE=HEAD; HEAD=NULL; do { _NEXT=NODE->__next; NODE->__next=NULL; insert(NODE,HEAD,EXP,K); NODE=_NEXT; } while(_NEXT); }
/* .----------------------------------------------------------------------.
#define for_search(NODE,HEAD,EXPR) for_each(NODE,HEAD) if(EXPR)
#define for_file_lines(STR,FNAME) /* _NEW(CTX,get_context()) file_read(FNAME) for(use_context(_CTX),STR=file_line(_F);release_context(_M),(*S && !feof(_F));STR=file_line(_F),end_context()) _CATCH */
#define for_input_lines(S,L) /* _NEW(CTX,get_context()) for(use_context(_CTX),STR=file_get_line(stdin);release_context(_M),(*S && !feof(stdin));STR=file_get_line(stdin)) _CATCH */
-#define for_ints(VAR,...) _NEW(I,0) while((VAR=_cll1_for_ints(_I++,__VA_ARGS__,-1))>=0)
-#define for_strs(VAR,...) _NEW(I,0) while((VAR=(char *)_cll1_for_ptrs(_I++,__VA_ARGS__,NIL))!=NIL)
+#define for_ints(VAR,...) _NEW(I,0) while( (VAR=_cll1_for_ints(_I++,__VA_ARGS__,-1))>=0 )
+#define for_strs(VAR,...) _NEW(I,0) while( (VAR=(char *)_cll1_for_ptrs(_I++,__VA_ARGS__,NIL))!=NIL )
#define for_args _NEW(I,1) while(_I++<argc)
#define this_arg argv[_I]
#define next_arg ((_I+1<argc)?argv[_I]:NULL)
#define switch_for_args for_args switch_str(this_arg)
#define switch_str(STR) _NEW(S,STR)
#define if_case(VAL) if(eq(argv[_I],VAL))
-#define for_fields(FIELD,STR) for_valid_split(FIELD,STR,OFS)
+#define for_fields(FIELD,STR) for_valid_split(FIELD,STR,*OFS)
#define for_split_str(A,B,C) for(prefix(A,B,C);A;(A!=B)&&prefix(A,B,C)||(A=NULL))
#define for_valid_split(A,B,C) for_split_str(A,B,C) if(*A)
#define switch_for_columns(A,B,C) _FOR_COLUMNS(A,B,C) switch(__I)
#define we_are(TYPE) struct *TYPE _self, void *_method
#define anonymous void *_self, void *_method
#define I_am(TYPE) struct TYPE *self=(struct TYPE *)_self
-#define define_polymorph(METATYPE,ITYPE) struct METATYPE { struct ITYPE *__interface; };
-#define construct_interface(MTYPE,ITYPE) struct ITYPE *_interface_##MTYPE##ITYPE(void *dummy, ...) { define_mem(_FACE,ITYPE); va_list(ap); _bind_##MTYPE##ITYPE(_FACE); return _FACE; } void _bind_##MTYPE##ITYPE(struct IFACE *_FACE)
+#define def_community(METATYPE,ITYPE) struct METATYPE { struct ITYPE *__interface; };
+#define construct_interface(MTYPE,ITYPE) struct ITYPE *_interface_##MTYPE##ITYPE(void *dummy, ...) { def_mem(_FACE,ITYPE); va_list(ap); _bind_##MTYPE##ITYPE(_FACE); return _FACE; } void _bind_##MTYPE##ITYPE(struct IFACE *_FACE)
#define bind_method(METHOD,FUNCTION) _FACE->METHOD=FUNCTION
#define new_interface(ID,MTYPE,...) struct _ARG1(__VA_ARGS__,) *ID=_interface_##MTYPE##_ARG1(__VA_ARGS__,) ((void *)__get_##TYPE##__VA_ARGS__,)
#define init_interface(TYPE,...)
#define _CLL1_FECHO(IOSTREAM) { va_list ap; /* <-' */ for(va_start(ap,s);s!=NIL;s=va_arg(ap,char *)) fputs(coalesce(s,NIL),IOSTREAM); va_end(ap); }
#define _ECHO void _cll1_echo(char *s,...) _CLL1_FECHO(stdout)
#define _FECHO void _cll1_fecho(FILE *f,char *s,...) _CLL1_FECHO(f)
+#define _CLL1_OUT _PRINT _FPRINT _ECHO _FECHO
#define _FOR_INTS int _cll1_for_ints(int i, int n, ...) { int j=0;va_list ap; /* <-' */ va_start(ap,n); while(n>=0 && j++<i) n=va_arg(ap,int); return n; }
#define _FOR_PTRS void *_cll1_for_ptrs(int i, void *v, ...) { int j=0;va_list ap; /* <-' */ va_start(ap,v); while(v!=(void *)NIL && j++<i) v=va_arg(ap,void *); return v; }
+#define _CLL1_ARGS _FOR_INTS _FOR_PTRS
+#define _STRCMP int _cll1_strcmp(char *a,char *b) { if(a && b) return strcmp(a,b); else return (int)(a-b); }
+#define _STRCMPI int _cll1_strcmpi(char *a,char *b) { if(a && b) return strcasecmp(a,b); else return (int)(a-b); }
+#define _STRSTR char *_cll1_strstr(char *h,char *n) { if(h && n) return strstr(h,n); else return NULL; }
+//#define _WORDINSTR char *_cll1_wordinstr(char *a,char *b,int ign) { char *IFS=a; for(;a&&*a;a++) for(;*ifs||ifs=IFS;ifs++) if(*a=b);) for return strcasestr(a,b); else return NULL; }
+#define _CLL1_STRS _STRCMP _STRCMPI _STRSTR //_WORDINSTR
/* .----------------------------------------------------------------------.
/ 10. C<<1 globals and private macros, updated 2008-01-27 by xCh.
'----------------------------------------------------------------------- */
#ifdef USE_MODULE_CGI
#define cgi(MIME) { char *PTR; /* <-' */ recycle_context(_CGI); _CGIdict=NULL; for_split_str(PTR,getenv("QUERY_STRING"),'&') /* _init_cgi */ if(MIME) printf("Content-type: %s\r\n\r\n",MIME); }
#define _GETCGI char *getcgi(VAR) { }
-#define _CGI_GLOBALS define_context(_CGI); struct _CGIVariable { char *V; dictionary(_CGIVariable); } *_CGIvariable,*_CGIdict;
+#define _CGI_GLOBALS def_context(_CGI); struct _CGIVariable { char *V; dictionary(_CGIVariable); } *_CGIvariable,*_CGIdict;
#else
#define _GETCGI
#define _CGI_GLOBALS
/ 12. MySQL wrappers + SQL object interface, updated 2007-12-19 by xCh.
'----------------------------------------------------------------------- */
#ifdef USE_LIBRARY_MYSQL
-#define define_sql(CONN) MYSQL *CONN
+#define def_sql(CONN) MYSQL *CONN
#define create_sql(CONN) MYSQL *ID=mysql_init(NULL)
#define sql_connect(CONN,S,U,P,D) mysql_real_connect(CONN,S,U,P,D,0,NULL,0)
//todo sql_query
#endif
//#ifdef USE_INTERFACE_SQL
//todo #define _SQL_OBJECT mem Sql { interface(SqlInterface); char *hostname; char *username; char *password; char *database; }
-//todo #define _SQL_CONSTRUCT define_construct(Sql) { self->hostname="localhost"; }
+//todo #define _SQL_CONSTRUCT def_construct(Sql) { self->hostname="localhost"; }
//#endif
/* ------------------------------------------------------------------- */
/* old - from version 0.6 */
/* .----------------------------------------------------------------------.
/ 99. We have have done our homework - now let's have some fun:
'----------------------------------------------------------------------- */
-#define _DEF_VARIABLES _CLL1_GLOBALS _CLL1_STACKS _SQL_GLOBALS _CGI_GLOBALS
-#define _DEF_FUNCTIONS _MALLOC _ECHO _PRINT _FECHO _FPRINT _FOR_INTS _FOR_PTRS //_GET_STR _GET_MEM
+#define _DEF_VARIABLES _CLL1_GLOBALS _CLL1_YES _CLL1_STACKS _SQL_GLOBALS _CGI_GLOBALS
+#define _DEF_FUNCTIONS _MALLOC _CLL1_OUT _CLL1_ARGS _CLL1_STRS // _GET_MEM
#define _DEF_INTERFACE //_SQL_IFC _CAKE_IFC _STD_IFC _X_IFC
-#define implement_cll1_library _DEF_VARIABLES _DEF_FUNCTIONS _DEF_INTERFACE
+#define _IMPLEMENT_CLL1_LIBRARY _DEF_VARIABLES _DEF_FUNCTIONS _DEF_INTERFACE
#ifdef USE_PREPROCESSOR
#include "_include.c"
#endif
-#define program implement_cll1_library int main(int argc, char **argv)
+#define program _IMPLEMENT_CLL1_LIBRARY int main(int argc, char **argv)
/* #ifndef _CLL1_H */
#endif