From: xchaos Date: Wed, 22 Jun 2011 15:13:24 +0000 (+0000) Subject: preliminary merge of new 4-argument for_each() iterators and counters X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=9ca7f90d80df810e91d006b23bd9717136cf4e22;p=svn%2FCll1h%2F.git preliminary merge of new 4-argument for_each() iterators and counters git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@133 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- diff --git a/crl1.h b/crl1.h index 9931b28..e97d0ff 100644 --- a/crl1.h +++ b/crl1.h @@ -82,13 +82,6 @@ unsigned RANDOM_SEED=0; #define then #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 for_samsara(MIND,SOUL) loop for_each(MIND,SOUL) -//#define atob(EXPR) (word_in_stri(YES,(EXPR))?1:0) -//#define _EXPORT_YES str YES="TRUE\nYES\nJA\nOUI\nDA\nANO\nY\n1"; -//#else -#define atob(EXPR) (eqi((EXPR),YES)?TRUE:FALSE) -#define _EXPORT_YES str YES="TRUE"; -#endif /* .----------------------------------------------------------------------. / 4. C<<1 almost 'then buddhist' section, updated 2008-02-02 xCh. '----------------------------------------------------------------------- */ @@ -99,7 +92,7 @@ unsigned RANDOM_SEED=0; #define FALSE 0 #define PI 3.141592654 #define WEIRDINT (1<<(sizeof(int)*8-1)) -#define btoa(EXPR) ((EXPR)?YES:"FALSE") +#define btoa(EXPR) ((EXPR)?"TRUE":"FALSE") /* .----------------------------------------------------------------------. / 5. C<<1 data declaration and allocation, updated 2008-01-31 xCh. '----------------------------------------------------------------------- */ @@ -161,9 +154,43 @@ unsigned RANDOM_SEED=0; #define repeat(N) for(int _i=0,_j=(N); _i++<_j;) #define for_each(ONE_T,ONE,ALL_T,...) for(_init_##ONE_T##_##ALL_T(_head_##ONE_T##_##ALL_T(ONE,__VA_ARGS__));_test_##ONE_T##_##ALL_T(ONE,__VA_ARGS__) || _free_##ONE_T##_##ALL_T(ONE,__VA_ARGS__);_next_##ONE_T##_##ALL_T(ONE,__VA_ARGS__)) #define count(ONE_T,ALL_T,...) _count_##ONE_T##_##ALL_T(__VA_ARGS__) - - - +#define _init_char_str(...) str _s=(__VA_ARGS__) +#define _head_char_str(ONE,ALL) ONE=(ALL?*ALL:0),ALL +#define _test_char_str(ONE,...) ONE +#define _free_char_str(...) FALSE +#define _next_char_str(ONE,...) ONE=*(++_s) +#define _count_char_str(S) strlen(S) +#define _init_str_str(...) str _s=(__VA_ARGS__) +#define _head_str_str(ONE,ALL) ONE=utf8_copy(ONE,ALL),ALL +#define _test_str_str(ONE,...) *ONE +#define _free_str_str(...) FALSE +#define _next_str_str(ONE,...) ONE=utf8_copy(ONE,(_s+=strlen(ONE))) +#define _COUNT_STR_STR int _count_str_str(str S) { int l=0; str X=""; for_each2(str,X,str,S){l++;} return l; } +#define _init_void_array(...) int _i=(__VA_ARGS__) +#define _head_void_array(ONE,ALL,LEN) ONE=*ALL,0 +#define _test_void_array(ONE,ALL,LEN) _i < LEN +#define _free_void_array(...) FALSE +#define _next_void_array(ONE,ALL,LEN) ONE=ALL[++_i] +//_count_void_array not defined +#define _init_str_array(...) int _i=(__VA_ARGS__) +#define _head_str_array(ONE,ALL,LEN) ONE=(str)*ALL,0 +#define _test_str_array(ONE,ALL,LEN) _i < LEN +#define _free_str_array(...) FALSE +#define _next_str_array(ONE,ALL,LEN) ONE=(str)ALL[++_i] +//_count_str_array not defined +#define _init_str_file(ALL) file _f=fopen(ALL,"r") +#define _head_str_file(ONE,ALL) ALL +#define _test_str_file(ONE,...) (!feof(_f)&&(ONE=fget_str(_f))) +#define _free_str_file(...) fclose(_f) +#define _next_str_file(...) +#define _COUNT_STR_FILE int _count_str_file(str F) { int l=0; str X; for_each2(str,X,file,F){l++;} return l; } +#define _init_str_stream(...) (__VA_ARGS__) +#define _head_str_stream(ONE,ALL,LEN) (ONE=(str)get_buf(LEN)) && fgets(ONE,LEN,ALL) && strrchr(ONE,'\n') && (ONE[strlen(ONE)-1]=0) +#define _test_str_stream(ONE,ALL,LEN) !feof(ALL) +#define _free_str_stream(...) FALSE +#define _next_str_stream(ONE,ALL,LEN) ((ONE=(str)get_buf(LEN)) && fgets(ONE,LEN,ALL) && strrchr(ONE,'\n') && (ONE[strlen(ONE)-1]=0)) +//_count_str_stream not defined +#define _EXPORT_COUNTERS _COUNT_STR_STR _COUNT_STR_FILE /* .----------------------------------------------------------------------. / 8. C<<1 object oriented infrastructure, updated 2008-02-04 '----------------------------------------------------------------------- */ @@ -379,9 +406,9 @@ obsolete / 98. We have have done our homework - now let's have some fun: '----------------------------------------------------------------------- */ #define _INIT_VARIABLES _EXPORT_GLOBALS _EXPORT_YES _EXPORT_STACKS _CGI_GLOBALS -#define _IMPL_FUNCTIONS /*_MALLOC*/ _EXPORT_OUTS _EXPORT_ARGS _EXPORT_STRS +#define _IMPLEMENT_FUNCTIONS /*_MALLOC*/ _EXPORT_OUTS _EXPORT_ARGS _EXPORT_STRS _EXPORT_COUNTERS //#define _IMPL_INTERFACE //_SQL_IFC _CAKE_IFC _STD_IFC _X_IFC -#define _IMPLEMENT_CRL1_LIBRARY _INIT_VARIABLES _IMPL_FUNCTIONS //_IMPL_INTERFACE +#define _IMPLEMENT_CRL1_LIBRARY _INIT_VARIABLES _IMPLEMENT_FUNCTIONS //_IMPL_INTERFACE //this will be probably accomplished some other way... #ifndef DISABLE_LIBRARY_CRL1 _IMPLEMENT_CRL1_LIBRARY