From: xchaos Date: Sat, 26 Jan 2008 21:20:27 +0000 (+0000) Subject: lists work again X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=005431b86f12649bcb4e2dd230c8ef4d4347cd35;p=svn%2FCll1h%2F.git lists work again git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@41 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- diff --git a/cll1.h b/cll1.h index c32debd..48066c5 100644 --- a/cll1.h +++ b/cll1.h @@ -1,6 +1,6 @@ -/* ,----------------------------------------------------------------------- - / C<<1 header file - C language style sheet - GNU C/ANSI C99 compliant - / Cumbersome Extraction and Report Language - http://cll1h.arachne.cz/ / +/* .----------------------------------------------------------------------. + / C<<1 header file - C language style sheet - GNU C/ANSI C99 compliant + / Cumbersome Extraction and Report Language - http://cll1h.arachne.cz/ '---------------------------------------------------------------------- */ /* Copyright (c) 2004-2008 Michael xChaos Polak - x(at)n.cz @@ -24,7 +24,7 @@ #ifndef _CLL1_H #define _CLL1_H #define CLL1H_VERSION "0.7.1" -/* ,----------------------------------------------------------------------- +/* .----------------------------------------------------------------------. / 0. Library definitions not parsed by @CC, updated 2008-01-26 xCh. '---------------------------------------------------------------------- */ /* @@ -33,7 +33,7 @@ @define USE_PREPROCESSOR cake *.html *.xml > _include.c @define USE_POSTPROCESSOR strip @ */ -/* ,----------------------------------------------------------------------- +/* .----------------------------------------------------------------------. / 1. C<<1 header auto include, updated 2008-01-26 xCh. '---------------------------------------------------------------------- */ #include @@ -50,7 +50,7 @@ #else #include #endif -/* ,----------------------------------------------------------------------- +/* .----------------------------------------------------------------------. / 2. C<<1 then buddhist section, updated 2008-01-26 xCh. '----------------------------------------------------------------------- */ #ifndef DISABLE_MODULE_THEN_BUDDHISM @@ -60,7 +60,7 @@ #define Create_var(ID,TYPE,INIT) TYPE ID=INIT #define Define_var(ID,TYPE) TYPE ID #endif -/* ,----------------------------------------------------------------------- +/* .----------------------------------------------------------------------. / 3. C<<1 constants and optional keywords, updated 2008-01-26 xCh. '----------------------------------------------------------------------- */ #define not ! @@ -74,7 +74,7 @@ #define mem struct #define construct struct #define _GLOBALS time_t RANDOM_SEED=0; char *EOL="\n", *OFS=" ", *IFS=" \t\n", *NIL="NULL"; -/* ,----------------------------------------------------------------------- +/* .----------------------------------------------------------------------. / 4. C<<1 data declaration and allocation, updated 2008-01-07 xCh. '----------------------------------------------------------------------- */ #define Create_str(ID,INIT) char *ID=INIT @@ -87,11 +87,11 @@ #define list(TYPE) struct TYPE *__next #define tree(TYPE) struct TYPE *__next;struct TYPE *__seek #define dictionary(TYPE) tree(TYPE);char *__key -#define array(TYPE) tree(TYPE);char *__key +#define array(TYPE) tree(TYPE);int __key #define interface(TYPE) struct TYPE *__interface #define get_mem(...) (struct _ARG1(__VA_ARGS__,)*)_cll1_malloc(sizeof(struct _ARG1(__VA_ARGS__,)),NULL) #define get_str(...) (char *)_cll1_get_str(__VA_ARGS__,(void *)&_cll1_get_str) -/* ,----------------------------------------------------------------------- +/* .----------------------------------------------------------------------. / 5. C<<1 string manipulation, updated 2008-01-26 xCh. '----------------------------------------------------------------------- */ #define eq(A,B) !strcmp(A,B) @@ -102,25 +102,34 @@ #define echo(...) _cll1_echo(__VA_ARGS__,(void *)&_cll1_echo) #define fecho(...) _cll1_fecho(__VA_ARGS__,(void *)&_cll1_fecho) #define file_echo(...) _cll1_fecho(_F,__VA_ARGS__,(void *)&_cll1_fecho) -/* ,----------------------------------------------------------------------- +#define suffix(A,B,C) (((A=strrchr(B,C))&&!(*(A++)=0))||(A=B)) +#define prefix(A,B,C) ((A=B),((B=strchr(B,C))&&!(*(B++)=0)||(B=A))) +#define for_split(A,B,C) for(prefix(A,B,C);A;(A!=B)&&prefix(A,B,C)||(A=NULL)) +#define for_valid_split(A,B,C) for_split_str(A,B,C) if(*A) +#define switch_for_columns(A,B,C) _FOR_COLUMNS(A,B,C) switch(__I) +#define switch_for_valid_columns(A,B,C) _FOR_VALID_COLUMNS(A,B,C) switch (_I) +#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) +#define tr(STR,B,C) {char *_S=STR; /***/ while(S && *_S) {if(*_S==B)*_S=C; _S++;} } +/* .----------------------------------------------------------------------. / 6. C<<1 data container manipulation, updated 2008-01-26 xCh. '----------------------------------------------------------------------- */ -#define push(NODE,HEAD) ((NODE && NODE!=HEAD)?((NODE->__next=HEAD),(HEAD=NODE)):(HEAD=NODE)) -#define pop(NODE,HEAD) (HEAD?((NODE=HEAD->__next),free(HEAD),(HEAD=NODE)):(NODE=NULL)) -#define append(NODE,HEAD) if(HEAD) { void *N=NODE; /**/ NODE->__next=NULL; for_search(NODE,HEAD,!NODE->__next) {NODE->__next=N; break;} else push(NODE,HEAD); } +#define push(NODE,HEAD) ( NODE ? ((NODE->__next=HEAD),(HEAD=NODE)) : NULL ) +#define pop(NODE,HEAD) ( HEAD ? ((NODE=HEAD->__next),free(HEAD),(HEAD=NODE)) : (NODE=NULL) ) +#define append(NODE,HEAD) { void *N=NODE; /**/ NODE->__next=NULL; for_search(NODE,HEAD,!NODE->__next) { NODE->__next=N; break; } } #define remove(NODE,HEAD,EXPR) { void **_D=NULL; /**/ for_search(NODE,HEAD,EXPR) { if(_D)*_D=NODE->__next; else HEAD=NODE->__next; free(NODE); } else _D=(void *)&(NODE->__next); } #define drop(NODE,HEAD) for( NODE=HEAD; NODE || (HEAD=NULL); HEAD=NODE, NODE=NODE->__next, free(HEAD) ) -//to do seek -//to do store +//to do: seek +//to do: store #define order_by(K1,K2) (K1>K2) #define desc_order_by(K1,K2) (K10) #define desc_sort_by(K1,K2) (strcasecmp(K1, K2)<0) #define ascii_by(K1,K2) (strcmp(K1, K2)>0) #define desc_ascii_by(K1,K2) (strcmp(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)->__next=NULL; } +#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); } -/* ,----------------------------------------------------------------------- +/* .----------------------------------------------------------------------. / 7. C<<1 builtin iterators and conditionals, updated 2008-01-26 xCh. '----------------------------------------------------------------------- */ #define loop while(TRUE) @@ -138,7 +147,7 @@ #define this_arg argv[_I] #define next_arg ((_I+1=0 && j++