From: xchaos Date: Mon, 4 Feb 2008 23:36:34 +0000 (+0000) Subject: new bake, new str_order, minor changes X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=bc44f2cc0aa5c38e6dd90b3cb1bc0d68464fff10;p=svn%2FCll1h%2F.git new bake, new str_order, minor changes git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@58 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- diff --git a/cll1.h b/cll1.h index eaff9a1..7192150 100644 --- a/cll1.h +++ b/cll1.h @@ -34,7 +34,7 @@ /* .----------------------------------------------------------------------. / 1. C<<1 header auto include, updated 2008-01-26 xCh. '---------------------------------------------------------------------- */ -#ifndef DISABLE_LIBRARY_LIBC +#ifndef DISABLE_MODULE_AUTOINCLUDE #include #include #include @@ -55,22 +55,21 @@ /* .----------------------------------------------------------------------. / 0. C<<1 typedefs and public gloabl variables, updated 2008-02-03 xCh. '----------------------------------------------------------------------- */ -typedef char * str; -/* Note: we may later #ifdef USE_MODULE_UNICODE .. typedef wchar_t * str; */ -typedef char * buffer; -/* Note: this could be buf instead of buffer, like str instead of string. */ +typedef char * str; /* #ifdef USE_MODULE_UNICODE...typedef wchar_t * str; */ +typedef unsigned char * buf; /* this will be always 8-bit usigned char * */ typedef FILE * file; typedef int bool; extern str NIL,EOL,OFS,IFS; extern unsigned RANDOM_SEED; #define _EXPORT_GLOBALS str NIL="NULL", EOL="\n", OFS=" ", IFS=" \t\n"; unsigned RANDOM_SEED=0; /* .----------------------------------------------------------------------. - / 1. C<<1 then buddhist section, updated 2008-02-03 xCh. + / 1. C<<1 then buddhist section, updated 2008-02-04 xCh. '----------------------------------------------------------------------- */ #ifndef DISABLE_MODULE_THEN_BUDDHISM #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) for(MIND=SOUL; MIND || ((MIND->__next=SOUL),0) ; MIND=MIND->__next) #define samsara(MIND,SOUL) for(MIND=SOUL; MIND || ((MIND->__next=SOUL),0) ; MIND=MIND->__next) //#define atob(EXPR) (word_in_stri(YES,(EXPR))?1:0) //#define _EXPORT_YES str YES="TRUE\nYES\nJA\nOUI\nDA\nANO\nY\n1"; @@ -93,25 +92,27 @@ extern unsigned RANDOM_SEED; / 4. C<<1 data declaration and allocation, updated 2008-01-31 xCh. '----------------------------------------------------------------------- */ #define def_mem(TYPE) typedef struct _##TYPE##_t * TYPE; struct _##TYPE##_t +#define construct_mem(TYPE) TYPE _init_##TYPE(void) { create_mem(this,TYPE); /* <-' */ _init_##TYPE(this); return this; } _init_##TYPE(TYPE this) #define get_mem(...) _GET_MEM(__VA_ARGS__,NULL) +#define init_mem(...) _init_##_ARG1(__VA_ARGS__,)( _ARG2(__VA_ARGS__,,) - 0 ) #define create_mem(ID,...) _ARG1(__VA_ARGS__,) ID=_GET_MEM(__VA_ARGS__,NULL) #define new_mem(ID,...) _ARG1(__VA_ARGS__,) ID=init_mem(__VA_ARGS__) -#define init_mem(...) _ARG1(__VA_ARGS__,)_construct( _ARG2(__VA_ARGS__,,) - 0 ) -#define construct_mem(TYPE) TYPE TYPE##_init(void) { create_mem(this,TYPE); /* <-' */ _##TYPE##_init(this); return this; } _##TYPE##_init(TYPE this) #define list(TYPE) TYPE __next #define tree(TYPE) TYPE __next; TYPE __seek #define dictionary(TYPE) TYPE __next; TYPE __seek; str __key -#define array(TYPE) struct TYPE __next; TYPE __seek; int __key -#define interface(TYPE) struct TYPE *__interface +#define array(TYPE) TYPE __next; TYPE __seek; int __key +#define interface(TYPE) TYPE __interface #define this_must_be(TYPE) TYPE this /* .----------------------------------------------------------------------. / 5. C<<1 string manipulation, updated 2008-01-26 xCh. '----------------------------------------------------------------------- */ #define get_str(...) _cll1_get_str(__VA_ARGS__,NIL) -#define len(...) __cll1__strlen(__VA_ARGS__,NIL) -#define eq(A,B) (A && ((B && !strcmp(A,B)) || !B)) -#define eqi(A,B) (A && ((B && !strcasecmp(A,B)) || !B)) -#define in_str(A,B) _cll1_str_str(A,B) +#define eq(A,B) (!_cll1_str_cmp(A,B)) +#define eqi(A,B) (!_cll1_str_cmpi(A,B)) +#define str_order(A,B) _cll1_str_coll(A,B) +#define str_ascii(A,B) _cll1_str_cmp(A,B) +#define str_len(...) _cll1__strlen(__VA_ARGS__,NIL) +#define str_in(A,B) _cll1_str_str(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) @@ -135,10 +136,10 @@ extern unsigned RANDOM_SEED; #define count(NODE,HEAD,VAR) { _NEW(I,0) for(NODE=HEAD; NODE || ((VAR=_I),0) ; (NODE=NODE->__next)?(_I++):0 ); } #define order_by(K1,K2) (K1>K2) #define desc_order_by(K1,K2) (K10) -#define desc_sort_by(K1,K2) (_cll1_str_cmp(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) (str_order(K1,K2)>0) +#define desc_sort_by(K1,K2) (str_order(K1,K2)<0) +#define ascii_by(K1,K2) (str_ascii(K1,K2)>0) +#define desc_ascii_by(K1,K2) (str_ascii(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); } /* .----------------------------------------------------------------------. @@ -170,23 +171,24 @@ extern unsigned RANDOM_SEED; #define if_column_number(A,B,C,V) _FOR_COLUMNS(A,B,C) if(_I==V) #define if_valid_column_number(A,B,C,V) _FOR_VALID_COLUMNS(A,B,C) if(_I==V) /* .----------------------------------------------------------------------. - / 8. C<<1 object oriented infrastructure, updated 2008-01-31 + / 8. C<<1 object oriented infrastructure, updated 2008-02-04 '----------------------------------------------------------------------- */ #define I_must_be(TYPE) TYPE self, void *_method #define we_can_be(TYPE) TYPE _we, void *_method #define we_can_be_whatever void *_we, void *_method #define I_am(TYPE) TYPE self=(TYPE)_we #define def_community(METATYPE,ITYPE) def_mem(METATYPE) { ITYPE __interface; }; -#define construct_interface(MTYPE,ITYPE) ITYPE _init_##MTYPE##ITYPE(void *dummy, ...) { new_mem(_FACE,ITYPE); va_list(ap); _##MTYPE##ITYPE##_init(_FACE); return _FACE; } void _##MTYPE##ITYPE##_init(struct IFACE *_FACE) +#define def_method(RET,NAME,...) RET (*NAME)(__VA_ARGS__) +#define construct_interface(MTYPE,ITYPE) ITYPE _init,_##MTYPE##ITYPE(void *dummy, ...) { new_mem(_FACE,ITYPE); va_list(ap); _##MTYPE##ITYPE##_init(_FACE); return _FACE; } void _##MTYPE##ITYPE##_init(IFACE _FACE) #define bind_method(METHOD,FUNCTION) _FACE->METHOD=FUNCTION #define new_interface(ID,MTYPE,...) _ARG1(__VA_ARGS__,) ID=_init_##MTYPE##_ARG1(__VA_ARGS__,) ((void *)init_##MTYPE##__VA_ARGS__,) #define init_interface(TYPE,...) -#define construct_object(TYPE,...) (struct _ARG2(__VA_ARGS__,TYPE,) *)_init_##TYPE##_() +#define construct_object(MTYPE,...) (void *)_init_##TYPE##_() #define init_object(TYPE,...) (TYPE)_init_##TYPE##_(__VA_ARGS__) -#define init_polymorph(TYPE,...) _init_##TYPE##_(__VA_ARGS__) +#define init_polymorph(TYPE,COMMUNITY,...) (COMMUNITY)_init_##TYPE##_(__VA_ARGS__) #define _(OBJECT,...) ( _ASSERT(OBJECT), (*( OBJECT->interface->_ARG1(__VA_ARGS__,) )) ( OBJECT,OBJECT->interface->__VA_ARGS__ ) ) #define __(OBJECT,...) ( _ASSERT(OBJECT), (*( __cll1_seekmethod(OBJECT->interface,_ARG1(__VA_ARGS__,)) )) ( OBJECT,OBJECT->interface->__VA_ARGS__ ) ) -#define call(OBJTYPE,METHOD,...) { int _N=0; struct OBJTYPE *_OBJ; /* <-' */ while( (_OBJ=(struct OBJTYPE *)_cll1_for_ptrs(_N++,__VA_ARGS__,NIL))!=(struct OBJTYPE *)NIL ) _(_OBJ,METHOD); } +#define call(OBJTYPE,METHOD,...) { int _N=0; OBJTYPE _OBJ; /* <-' */ while( (_OBJ=(OBJTYPE)_cll1_for_ptrs(_N++,__VA_ARGS__,NIL))!=(struct OBJTYPE *)NIL ) _(_OBJ,METHOD); } /* .----------------------------------------------------------------------. / 9. implementation of C<<1 library functions, updated 2008-01-26 xCh. '----------------------------------------------------------------------- */ @@ -201,14 +203,23 @@ extern unsigned RANDOM_SEED; #define _FECHO void _cll1_fecho(FILE *f,char *s,...) _CLL1_FECHO(f) #define _FOR_INTS int _cll1_for_ints(int i, int n, ...) { int j=0;va_list ap; /* <-' */ va_start(ap,n); while(n!=WEIRDINT && j++