From 6e567bcce620b5312125f920e88c68a1404e71bf Mon Sep 17 00:00:00 2001 From: xchaos Date: Fri, 25 Jan 2008 14:41:11 +0000 Subject: [PATCH] NIL, OFS, EOL, coalesce() git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@39 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- cll1.h | 14 ++++++++------ demos/advanced-hello-world.c | 16 +++++++++++++--- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/cll1.h b/cll1.h index e3911e1..be5797b 100644 --- a/cll1.h +++ b/cll1.h @@ -44,12 +44,14 @@ #define not ! #define and && #define or || +#define boolean int +#define bool_str(VALUE) (VALUE?"TRUE":"FALSE") #define TRUE 1 #define FALSE 0 -#define MAYBE (int)((_srtime?random():(_srtime=time(NULL),srandom(_srtime),random()))%2) +#define MAYBE (int)((RANDOM_SEED?random():(RANDOM_SEED=time(NULL),srandom(RANDOM_SEED),random()))%2) #define WHOKNOWS (int)(srandom(time(NULL)),random()%2) -#define bool_str(I) (I?"TRUE":"FALSE") -#define boolean int +#define _GLOBALS time_t RANDOM_SEED=0; char *EOL="\n", *OFS=" ", *IFS=" \t\n", *NIL="NULL"; +#define coalesce(VALUE,NOTNULL) ((VALUE)?(VALUE):(NOTNULL)) #define mem struct #define construct struct /* ------------------------------------------------------------------- */ @@ -103,7 +105,7 @@ /* ------------------------------------------------------------------- */ /* 6. C<<1 va_list based library functions, updated 2008-01-22 by xCh. */ /* ------------------------------------------------------------------- */ -#define _ECHO void _cll1_print(int p,char *s, ... ) { int p2=0; va_list ap; for(va_start(ap,s);s!=(void *)&_cll1_print;s=va_arg(ap,char *)) { if(p) {if(p2) putchar(' '); else p2=1;} fputs(s?s:"",stdout); } va_end(ap); if(p) putchar('\n');} +#define _ECHO void _cll1_print(int p,char *s, ... ) { int p2=0; va_list ap; for(va_start(ap,s);s!=(void *)&_cll1_print;s=va_arg(ap,char *)) { if(p) {if(p2) putchar(*OFS); else p2=1;} fputs(coalesce(s,NIL),stdout); } va_end(ap); if(p) putchar(*EOL);} #define print(...) _cll1_print(1,__VA_ARGS__,(void *)&_cll1_print) #define echo(...) _cll1_print(0,__VA_ARGS__,(void *)&_cll1_print) /* ------------------------------------------------------------------- */ @@ -190,7 +192,7 @@ obsolete #define _ISTACK struct _IStack { int I; int _23; list(_IStack); } *_Iatom,*_Istack=NULL; #define _SSTACK struct _SStack { char *S; int _23; list(_SSTACK); } *_Satom,*_Sstack=NULL; #define _FSTACK struct _FStack { FILE *F; int _23; list(_FSTACK); } *_Fatom,*_Fstack=NULL; -#define _SRTIME time_t _srtime=0; + #define _NEW_(ATOM,STACK,TYPE) (create(ATOM,TYPE),ATOM->_23=1,push(ATOM,STACK);ATOM->_23||pop(ATOM,STACK)&&0;ATOM->_23--) #define _NEW_I for _NEW_(_Iatom,_Istack,_IStack) @@ -262,7 +264,7 @@ obsolete /* ------------------------------------------------------------------- */ /* Voila - here we go ! */ /* ------------------------------------------------------------------- */ -#define define_cll1_globals _SRTIME _ISTACK _SSTACK _FSTACK _MSTACK _RSTACK //_QSTACK +#define define_cll1_globals _GLOBALS _ISTACK _SSTACK _FSTACK _MSTACK _RSTACK //_QSTACK #define implement_cll1_functions _ECHO // _GET_STR _GET_MEM #define define_cll1_interfaces //_CAKE #define implement_cll1_library define_cll1_globals implement_cll1_functions define_cll1_interfaces diff --git a/demos/advanced-hello-world.c b/demos/advanced-hello-world.c index e855e5e..7117279 100644 --- a/demos/advanced-hello-world.c +++ b/demos/advanced-hello-world.c @@ -2,9 +2,19 @@ program { - echo("Hello ",NULL," ","world"," ! "); - print("Hello", "world",NULL,"!"); - + print("* echo()"); + echo("Hello"," ","world"," !\n"); + print("* print()"); + print("Hello","world","!"); + print("* MAYBE ?"); repeat(4) print((MAYBE ? "Hello" : "Hi"), (MAYBE ? "world" : "friend"), (MAYBE ? "!" : "?")); + print("* WHOKNOWS ?"); repeat(4) print((WHOKNOWS ? "Hello" : "Hi"), (WHOKNOWS ? "world" : "friend"), (WHOKNOWS ? "!" : "?")); + print("* NIL"); + print("We can print",NULL,"safely."); + print("* coalesce():"); + print("We can",coalesce("print","anything"),coalesce(NULL,"anything"),"safely."); + print("* OFS"); + OFS=":"; + print("We","can","customize","print"); } -- 2.30.2