From: xchaos Date: Sat, 26 Jan 2008 19:58:48 +0000 (+0000) Subject: lot of work has been done, but lists are currently broken X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=f57259369784a5df46b75488d50e431ed1741235;p=svn%2FCll1h%2F.git lot of work has been done, but lists are currently broken git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@40 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- diff --git a/cll1.h b/cll1.h index be5797b..c32debd 100644 --- a/cll1.h +++ b/cll1.h @@ -1,8 +1,9 @@ -/* ------------------------------------------------------------------- */ -/* C<<1 header file v0.7.1 - style sheet for ANSI C */ -/* CERL - Cumbersome Extraction and Report Language */ -/* ------------------------------------------------------------------- */ -/* Copyright (c) 2004-2008 Michael xChaos Polak, x(at)n.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 The C<<1 header file is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -22,7 +23,19 @@ #ifndef _CLL1_H #define _CLL1_H - +#define CLL1H_VERSION "0.7.1" +/* ,----------------------------------------------------------------------- + / 0. Library definitions not parsed by @CC, updated 2008-01-26 xCh. + '---------------------------------------------------------------------- */ +/* +@define USE_LIBRARY_MYSQL -lmysqlclient +@define USE_LIBRARY_FASTCGI -lfcgi +@define USE_PREPROCESSOR cake *.html *.xml > _include.c +@define USE_POSTPROCESSOR strip @ +*/ +/* ,----------------------------------------------------------------------- + / 1. C<<1 header auto include, updated 2008-01-26 xCh. + '---------------------------------------------------------------------- */ #include #include #include @@ -37,80 +50,123 @@ #else #include #endif -/* ------------------------------------------------------------------- */ -/* 1. C<<1 constants and optional keywords, updated 2008-01-07 by xCh. */ -/* ------------------------------------------------------------------- */ +/* ,----------------------------------------------------------------------- + / 2. C<<1 then buddhist section, updated 2008-01-26 xCh. + '----------------------------------------------------------------------- */ +#ifndef DISABLE_MODULE_THEN_BUDDHISM #define then +#define MAYBE (int)((RANDOM_SEED?random():(RANDOM_SEED=time(NULL),srandom(RANDOM_SEED),random()))%2) +#define WHOKNOWS (int)(srandom(time(NULL)),random()%2) +#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 ! #define and && #define or || #define boolean int -#define bool_str(VALUE) (VALUE?"TRUE":"FALSE") +#define bool_str(VALUE) ((VALUE)?"TRUE":"FALSE") #define TRUE 1 #define FALSE 0 -#define MAYBE (int)((RANDOM_SEED?random():(RANDOM_SEED=time(NULL),srandom(RANDOM_SEED),random()))%2) -#define WHOKNOWS (int)(srandom(time(NULL)),random()%2) -#define _GLOBALS time_t RANDOM_SEED=0; char *EOL="\n", *OFS=" ", *IFS=" \t\n", *NIL="NULL"; -#define coalesce(VALUE,NOTNULL) ((VALUE)?(VALUE):(NOTNULL)) +#define coalesce(VAR,NOTNULL) (VAR?VAR:(NOTNULL)) #define mem struct #define construct struct -/* ------------------------------------------------------------------- */ -/* 2. C<<1 basic data types - updated 2008-01-07 by xCh. */ -/* ------------------------------------------------------------------- */ +#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 #define Define_str(ID) char *ID=NULL -#define Create_mem(ID,TYPE) struct TYPE *ID=get_mem(TYPE) -#define Create_mem_in_context(ID,TYPE,CONTEXT) struct TYPE *ID=get_mem_in_context(TYPE,CONTEXT) +#define Create_mem(ID,...) struct _ARG1(__VA_ARGS__,) *ID=get_mem(__VA_ARGS__) #define Define_mem(ID,TYPE) struct TYPE *ID=NULL -#define Define_mems(ID1,I2,TYPE) Define_mem(ID1,TYPE);Define_mem(ID2,TYPE) - -/* .... well....ehm...not very useful... :-) */ -#define Create_var(ID,TYPE,INIT) TYPE ID=INIT +#define Define_mems(ID1,ID2,TYPE) Define_mem(ID1,TYPE); Define_mem(ID2,TYPE) +#define Create_list(ID1,I2,TYPE) Create_mem(ID1,TYPE); struct TYPE *ID2=((ID1->__next=NULL),ID1) #define Define_var(ID,TYPE) TYPE ID -/* ------------------------------------------------------------------- */ -#define list(T) struct T *_next -#define tree(T) struct T *_next;struct T *_seek -#define create(A,T) (A=(struct T *)malloc(sizeof(struct T)),A->_next=NULL,A) -#define push(A,B) ((A && A!=B)?A->_next=B:0,B=A) -#define pop(A,B) (B?((A?free(A):0),A=B=B->_next):(A=NULL)) -#define append(A,B) if(B) { void *N=A; A->_next=NULL; for_search(A,B,!A->_next) {A->_next=N; break;}} else push(A,B); -#define remove(A,B,C) { void **_D=NULL; for_search(A,B,C) { if(_D)*_D=A->_next; else B=A->_next; free(A); } else _D=(void *)&(A->_next); } -#define drop(A,B) for( A=B; A || (B=NULL); B=A, A=A->_next, free(B) ) -/* ------------------------------------------------------------------- */ -/* 3. C<<1 general iterators - updated 2008-01-07 by xCh. */ -/* ------------------------------------------------------------------- */ +#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 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) +#define eqi(A,B) !strcasecmp(A,B) +#define print(...) _cll1_print(__VA_ARGS__,(void *)&_cll1_print) +#define fprint(...) _cll1_fprint(__VA_ARGS__,(void *)&_cll1_fprint) +#define file_print(...) _cll1_fprint(_F,__VA_ARGS__,(void *)&_cll1_fprint) +#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) +/* ,----------------------------------------------------------------------- + / 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 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 +#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 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) #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) +#define for_each(NODE,HEAD) for(NODE=HEAD; NODE; NODE=NODE->__next) +#define for_search(NODE,HEAD,EXPR) for_each(NODE,HEAD) if(EXPR) #define for_file_lines(STR,F) /* _NEW_F for() */ -#define for_ints(VAR,...) _NEW_I while(_iterate_ints(&VAR,_I,__VA_LIST) ) -#define for_strs(VAR,...) _NEW_S -/* obsolete #define every(A,B) for( A=B; A; A=A->_next) */ -/* obsolete #define search(A,B,C) every(A,B) if(C) */ -/* obsolete #define find(A,B,C) search(A,B,C) break; if(A) */ -/* ------------------------------------------------------------------- */ -/* 4.C<<1 conditionals - updated 2008-01-07 by xCh. */ -/* ------------------------------------------------------------------- */ +#define for_ints(VAR,...) _NEW_I for( _I=0 ; (VAR=_cll1_it_ints(_I,__VA_ARGS__,-1))>=0 ; _I++) +#define for_strs(VAR,...) _NEW_I for( _I=0 ; (VAR=_cll1_it_strs(_I,__VA_ARGS__,(void *)&_cll1_it_strs))!=(void *)&_cll1_it_strs ; _I++) #define if_exists(A,B,C) for_search(A,B,C) break; if(A) -/* ------------------------------------------------------------------- */ -/* 5. C<<1 argument handling, updated 2008-01-16 by xCh. */ -/* ------------------------------------------------------------------- */ #define for_args _NEW_I for(_I=1;_I1) #define if_arg(VAL) if(eq(argv[_I],VAL)) #define this_arg argv[_I] #define next_arg ((_I+1=0 && j++