/* .----------------------------------------------------------------------.
/ 1. C<<1 header auto include, updated 2008-01-26 xCh.
'---------------------------------------------------------------------- */
-#ifndef DISABLE_LIBRARY_LIBC
+#ifndef DISABLE_MODULE_AUTOINCLUDE
#include <string.h>
#include <strings.h>
#include <malloc.h>
/* .----------------------------------------------------------------------.
/ 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";
/ 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)
#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) (K1<K2)
-#define sort_by(K1,K2) (_cll1_str_cmp(K1,K2)>0)
-#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); }
/* .----------------------------------------------------------------------.
#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.
'----------------------------------------------------------------------- */
#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++<i) n=va_arg(ap,int); return n; }
#define _FOR_PTRS void *_cll1_for_ptrs(int i, void *v, ...) { int j=0;va_list ap; /* <-' */ va_start(ap,v); while(v!=(void *)NIL && j++<i) v=va_arg(ap,void *); return v; }
-#define _STRCMP int _cll1_str_cmp(char *a,char *b) { if(a && b) return strcoll(a,b); else return (int)(a-b); }
-//#define _STRCMPI int _cll1_str_cmpi(char *a,char *b) { if(a && b) return strcasecmp(a,b); else return (int)(a-b); }
-#define _STRSTR char *_cll1_str_str(char *h,char *n) { if(h && n) return strstr(h,n); else return NULL; }
+#define _DECLARE_STRCOLL int _cll1_str_coll(str a, str b)
+#define _STRCOLL _DECLARE_STRCOLL { if(a && b) return strcoll(a,b); else return (int)(a-b); }
+#define _DECLARE_STRCMP int _cll1_str_cmp(str a, str b)
+#define _STRCMP _DECLARE_STRCMP { if(a && b) return strcmp(a,b); else return (int)(a-b); }
+#define _DECLARE_STRCMPI int _cll1_str_cmpi(str a, str b)
+#define _STRCMPI _DECLARE_STRCMPI { if(a && b) return strcasecmp(a,b); else return (int)(a-b); }
+#define _DECLARE_STRSTR str _cll1_str_str(str h, str n)
+#define _STRSTR _DECLARE_STRSTR { if(h && n) return strstr(h,n); else return NULL; }
//#define _WORDINSTR char *_cll1_wordinstr(char *a,char *b,int ign) { char *IFS=a; for(;a&&*a;a++) for(;*ifs||ifs=IFS;ifs++) if(*a=b);) for return strcasestr(a,b); else return NULL; }
extern _DECLARE_PRINT;
extern _DECLARE_FPRINT;
+extern _DECLARE_STRCOLL;
+extern _DECLARE_STRCMP;
+extern _DECLARE_STRCMPI;
+extern _DECLARE_STRSTR;
#define _EXPORT_OUTS _PRINT _FPRINT _ECHO _FECHO
-#define _EXPORT_STRS _STRCMP /*_STRCMPI*/ _STRSTR //_WORDINSTR
+#define _EXPORT_STRS _STRCOLL _STRCMP _STRCMPI _STRSTR //_WORDINSTR
#define _EXPORT_ARGS _FOR_INTS _FOR_PTRS
/* .----------------------------------------------------------------------.
/ 10. C<<1 private infrastructure, updated 2008-02-03 by xCh.
a="¾luklý";
b="®LUKLÝ";
- printf("strcoll(\"%s\",\"%s\")=%d\n",a,b,strcoll(a,b));
+ printf("str_order(\"%s\",\"%s\")=%d\n",a,b,str_order(a,b));
printf("eq(\"%s\",\"%s\")=%s\n",a,b,btoa(eq(a,b)));
printf("eqi(\"%s\",\"%s\")=%s\n",a,b,btoa(eqi(a,b)));
a="aabc";
b="axyz";
- printf("strcoll(\"%s\",\"%s\")=%d\n",a,b,strcoll(a,b));
+ printf("str_order(\"%s\",\"%s\")=%d\n",a,b,str_order(a,b));
printf("eq(\"%s\",\"%s\")=%s\n",a,b,btoa(eq(a,b)));
printf("eqi(\"%s\",\"%s\")=%s\n",a,b,btoa(eqi(a,b)));
a="ABC";
b="abc";
- printf("strcoll(\"%s\",\"%s\")=%d\n",a,b,strcoll(a,b));
+ printf("str_order(\"%s\",\"%s\")=%d\n",a,b,str_order(a,b));
printf("eq(\"%s\",\"%s\")=%s\n",a,b,btoa(eq(a,b)));
printf("eqi(\"%s\",\"%s\")=%s\n",a,b,btoa(eqi(a,b)));
a="abc";
b="abc";
- printf("strcoll(\"%s\",\"%s\")=%d\n",a,b,strcoll(a,b));
+ printf("str_order(\"%s\",\"%s\")=%d\n",a,b,str_order(a,b));
+ printf("eq(\"%s\",\"%s\")=%s\n",a,b,btoa(eq(a,b)));
+ printf("eqi(\"%s\",\"%s\")=%s\n",a,b,btoa(eqi(a,b)));
+ a=NULL;
+ b="abc";
+ printf("str_order(\"%s\",\"%s\")=%d\n",a,b,str_order(a,b));
+ printf("eq(\"%s\",\"%s\")=%s\n",a,b,btoa(eq(a,b)));
+ printf("eqi(\"%s\",\"%s\")=%s\n",a,b,btoa(eqi(a,b)));
+ a=NULL;
+ b=NULL;
+ printf("str_order(\"%s\",\"%s\")=%d\n",a,b,str_order(a,b));
printf("eq(\"%s\",\"%s\")=%s\n",a,b,btoa(eq(a,b)));
printf("eqi(\"%s\",\"%s\")=%s\n",a,b,btoa(eqi(a,b)));
}