From 25a3f4304e39dce85a217fd3166df867a5d75b96 Mon Sep 17 00:00:00 2001 From: xchaos Date: Fri, 1 Feb 2008 22:07:16 +0000 Subject: [PATCH] another major rewrite - define_ -> def_, etc. (and it will get worse !) git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@52 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- cll1.h | 79 +++++++++++++++++++++++++------------------ demos/arguments1.c | 2 +- demos/boolean.c | 24 ++++++++----- demos/for_ints_strs.c | 8 ++--- demos/lists.c | 2 +- demos/stromecek.c | 12 +++---- tools/bake | 5 +-- 7 files changed, 78 insertions(+), 54 deletions(-) diff --git a/cll1.h b/cll1.h index dbef96d..08a9a8e 100644 --- a/cll1.h +++ b/cll1.h @@ -37,6 +37,7 @@ '---------------------------------------------------------------------- */ #ifndef DISABLE_LIBRARY_LIBC #include +#include #include #include #include @@ -56,23 +57,28 @@ '----------------------------------------------------------------------- */ #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. '----------------------------------------------------------------------- */ @@ -80,18 +86,18 @@ #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 @@ -100,8 +106,10 @@ /* .----------------------------------------------------------------------. / 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) @@ -123,10 +131,10 @@ //to do: store #define order_by(K1,K2) (K1>K2) #define desc_order_by(K1,K2) (K10) -#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); } /* .----------------------------------------------------------------------. @@ -139,8 +147,8 @@ #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++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,...) @@ -185,8 +193,15 @@ #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++hostname="localhost"; } +//todo #define _SQL_CONSTRUCT def_construct(Sql) { self->hostname="localhost"; } //#endif /* ------------------------------------------------------------------- */ /* old - from version 0.6 */ @@ -304,13 +319,13 @@ obsolete /* .----------------------------------------------------------------------. / 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 diff --git a/demos/arguments1.c b/demos/arguments1.c index f863b64..609dcdd 100644 --- a/demos/arguments1.c +++ b/demos/arguments1.c @@ -4,7 +4,7 @@ program { - define_str(ptr); + def_str(ptr); if_args then { diff --git a/demos/boolean.c b/demos/boolean.c index aee578c..ed44988 100644 --- a/demos/boolean.c +++ b/demos/boolean.c @@ -2,13 +2,21 @@ program { - boolean t = TRUE, f = FALSE, m = MAYBE; + const bool t = TRUE, f = FALSE; + bool l, m = MAYBE; + def_str(s); - print("TRUE and FALSE = ", bool_str(t and f) ); - print("TRUE or FALSE = ", bool_str(t or f) ); - print("TRUE and MAYBE = ", bool_str(t and m) ); - print("FALSE or MAYBE = ", bool_str(t or m) ); - print("not FALSE = ", bool_str(not f) ); - print("not TRUE = ", bool_str(not t) ); - print("not MAYBE = ", bool_str(not m) ); + print("TRUE and FALSE =", btoa(t and f) ); + print("TRUE or FALSE =", btoa(t or f) ); + print("TRUE and MAYBE =", btoa(t and m) ); + print("FALSE or MAYBE =", btoa(t or m) ); + print("not FALSE =", btoa(not f) ); + print("not TRUE =", btoa(not t) ); + print("not MAYBE =", btoa(not m) ); + + for_strs(s, "TRUE","false","yes","NO","True","FALSE","YES","no","Yes","No","1","0","abc","xyz","Eyes","Ears","rue","alse","oui","no","ano","ne"," ","NULL",NULL,EOL,"","ano","ne") + { + l = atob(s); + echo("\"", s, "\"\tmeans ", btoa(l),EOL); + } } diff --git a/demos/for_ints_strs.c b/demos/for_ints_strs.c index f77d818..a58e970 100644 --- a/demos/for_ints_strs.c +++ b/demos/for_ints_strs.c @@ -5,11 +5,11 @@ program int i; char *s; - echo("for_ints(i, 8,1,2,745,32,64,27,4): "); - for_ints(i, 8,1,2,745,32,64,27,4) printf(" [%d]",i); + echo("for_ints(i in(8,1,2,745,32,64,27,4) ): "); + for_ints(i, 8,1,2,745,32,64,27,4 ) printf(" [%d]",i); print(""); - echo("for_strs(s, \"aasd\",\"snres\",\"sdfrm\",\"ojffgt\",\"wweqwe\"): "); - for_strs(s, "aasd","snres","sdfrm","ojffgt","wweqwe") echo(" [",s,"]"); + echo("for_strs(s in( \"aasd\",\"snres\",\"sdfrm\",\"ojffgt\",\"wweqwe\" )): "); + for_strs(s, "aasd","snres","sdfrm","ojffgt","wweqwe" ) echo(" [",s,"]"); print(""); } diff --git a/demos/lists.c b/demos/lists.c index 5daf1fa..e31102e 100644 --- a/demos/lists.c +++ b/demos/lists.c @@ -9,7 +9,7 @@ mem Zaznam program { - define_mems(zaznam,zaznamy,Zaznam); + def_mems(zaznam,zaznamy,Zaznam); print("4x insert(zaznam,zaznamy,order_by,i);"); zaznam=get_mem(Zaznam); diff --git a/demos/stromecek.c b/demos/stromecek.c index a2d867a..40153a4 100644 --- a/demos/stromecek.c +++ b/demos/stromecek.c @@ -7,12 +7,12 @@ program while(jehlici<=kmen) { - repeat(kmen-jehlici) printf(" "); - printf("/"); - repeat(jehlici<<1) if (jehlici>1,vetev=0,stromecek++; } - repeat(kmen) printf(" "); - printf("||\n"); + repeat(kmen) echo(" "); + print("||"); } diff --git a/tools/bake b/tools/bake index 3b15bcd..77ea78d 100755 --- a/tools/bake +++ b/tools/bake @@ -1,6 +1,7 @@ #!/bin/bash -CONF=/etc/bake.conf +CONF="/etc/bake.conf" CLL1CC=`which gcc` +CFLAGS="-std=c99 -Wall" EXE=`basename $1 .c` DEBUG=n @@ -43,6 +44,6 @@ then done fi -CMD="$CLL1CC $1 -o $EXE $LIBS" +CMD="$CLL1CC $1 -o $EXE $CFLAGS $LIBS" echo "$CMD" $CMD -- 2.30.2