From 956a4c051a02b9c65d81e644c848e4e2f098da7e Mon Sep 17 00:00:00 2001 From: xchaos Date: Tue, 8 Jan 2008 01:58:58 +0000 Subject: [PATCH] bugfix repeat,for_range + 2 new demos git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@6 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- cll1.h | 4 ++-- demos/for_range.c | 23 +++++++++++++++++++++++ demos/stromecek.c | 18 ++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 demos/for_range.c create mode 100644 demos/stromecek.c diff --git a/cll1.h b/cll1.h index 47e7024..cb66f6f 100644 --- a/cll1.h +++ b/cll1.h @@ -58,8 +58,8 @@ /* 3. C<<1 iterators - updated 2008-01-07 by xCh. */ /* ------------------------------------------------------------------- */ #define loop while(TRUE) -#define repeat(N) _NEW_I for_range(_I,1,N) -#define for_range(VAR,FROM,TO) for(VAR=FROM; FROM<=TO?VAR<=TO:VAR>=TO; FROM<=TO?VAR++:VAR--) +#define repeat(N) if(N>0) _NEW_I for_range(_I,1,N) +#define for_range(VAR,FROM,TO) for( VAR=FROM ; FROM<=TO?(VAR<=TO):(VAR>=TO) ; FROM<=TO?(VAR++):(VAR--)) #define for_each(A,B) for(A=B; A; A=A->_next) #define for_search(A,B,C) for_each(A,B) if(C) /*to do: #define for_file_lines(STR,F) _NEW_F for() */ diff --git a/demos/for_range.c b/demos/for_range.c new file mode 100644 index 0000000..6aedae7 --- /dev/null +++ b/demos/for_range.c @@ -0,0 +1,23 @@ +#include "cll1.h" + +program +{ + int i; + + printf("for_range(i,0,1)"); + for_range(i,0,1) printf(" [%d]",i); + + printf("\nfor_range(i,1,0)"); + for_range(i,1,0) printf(" [%d]",i); + + printf("\nfor_range(i,1,1)"); + for_range(i,1,1) printf(" [%d]",i); + + printf("\nfor_range(i,1,5)"); + for_range(i,1,5) printf(" [%d]",i); + + printf("\nfor_range(i,5,1)"); + for_range(i,5,1) printf(" [%d]",i); + + printf("\n"); +} diff --git a/demos/stromecek.c b/demos/stromecek.c new file mode 100644 index 0000000..a2d867a --- /dev/null +++ b/demos/stromecek.c @@ -0,0 +1,18 @@ +#include "cll1.h" + +program +{ + const int kmen=28; + int jehlici=0,vetev=0,stromecek=2; + + while(jehlici<=kmen) + { + repeat(kmen-jehlici) printf(" "); + printf("/"); + repeat(jehlici<<1) if (jehlici>1,vetev=0,stromecek++; + } + repeat(kmen) printf(" "); + printf("||\n"); +} -- 2.30.2