-/* ,-----------------------------------------------------------------------
- / 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
#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_PREPROCESSOR cake *.html *.xml > _include.c
@define USE_POSTPROCESSOR strip @
*/
-/* ,-----------------------------------------------------------------------
+/* .----------------------------------------------------------------------.
/ 1. C<<1 header auto include, updated 2008-01-26 xCh.
'---------------------------------------------------------------------- */
#include <string.h>
#else
#include <stdio.h>
#endif
-/* ,-----------------------------------------------------------------------
+/* .----------------------------------------------------------------------.
/ 2. C<<1 then buddhist section, updated 2008-01-26 xCh.
'----------------------------------------------------------------------- */
#ifndef DISABLE_MODULE_THEN_BUDDHISM
#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 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
#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)
#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) (K1<K2)
#define sort_by(K1,K2) (strcasecmp(K1, K2)>0)
#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)
#define this_arg argv[_I]
#define next_arg ((_I+1<argc)?argv[_I]:NULL)
#define skip_next _I++
-/* ,-----------------------------------------------------------------------
+/* .----------------------------------------------------------------------.
/ 8. C<<1 va_list based library functions, updated 2008-01-26 xCh.
'----------------------------------------------------------------------- */
#define _ARG1(ARG1,...) ARG1
#define _FECHO void _cll1_fecho(FILE *f,char *s,...) _CLL1_FECHO(f,(void *)&_cll1_fecho)
#define _IT_INTS int _cll1_it_ints(int i, int n, ...) { int j=0;va_list ap; /**/ va_start(ap,n); while(n>=0 && j++<i) n=va_arg(ap,int); return n; }
#define _IT_STRS char *_cll1_it_strs(int i, char *s, ...) { int j=0;va_list ap; /**/ va_start(ap,s); while(s!=(void *)&_cll1_it_strs && j++<i) s=va_arg(ap,char *); return s; }
-/* ,-----------------------------------------------------------------------
+/* .----------------------------------------------------------------------.
/ 9. C<<1 hidden stack infrastructure, updated 2008-01-26 by xCh.
'----------------------------------------------------------------------- */
#define _ISTACK struct _IStack { int I; int _23; list(_IStack); } *_Iatom,*_Istack=NULL;
#define _I (_Iatom->I)
#define _S (_Satom->I)
#define _F (_Satom->F)
-/* ,-----------------------------------------------------------------------
+#define _FOR_COLUMNS(A,B,C) _NEW_I for(_I=0,prefix(A,B,C);A;((A!=B)&&prefix(A,B,C)||(A=NULL)),_I++)
+#define _FOR_VALID_COLUMNS(A,B,C) _NEW_I for(_I=0,prefix(A,B,C);A;((A!=B)&&prefix(A,B,C))||(A=NULL)) if(*A&&++_I)
+/* .----------------------------------------------------------------------.
/ 10. C<<1 CGI and FASTCGI handling, updated 2008-01-16 by xCh.
'----------------------------------------------------------------------- */
#ifdef USE_LIBRARY_FASTCGI
//todo define_init_cgi
//todo #define _QSTACK struct _QStack { char *Q; int _23; list(_QStack); } *_Qatom,*_Qstack=NULL;
#endif
-/* ,-----------------------------------------------------------------------
+/* .----------------------------------------------------------------------.
/ 11. MySQL infrastructure and wrappers - updated 2007-12-19 by xCh.
'----------------------------------------------------------------------- */
#ifdef USE_LIBRARY_MYSQL
#define string(S,L) (S=(char *)malloc(L),*S=0)
#define duplicate(A,B) if(A) { string(B,strlen(A)+1); strcpy(B,A); }
#define concatenate(A,B,C) if (A && B) { string(C,strlen(A)+strlen(B)+1); strcpy(C,A); strcat(C,B); }
-#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 gotoalpha(CHAR) if(CHAR)while(*CHAR && !isalpha(*CHAR))CHAR++
#define goto_alpha(CHAR) if(CHAR)while(*CHAR && !isalpha(*CHAR) && *CHAR!='_')CHAR++
#define gotoalnum(CHAR) if(CHAR)while(*CHAR && !isalnum(*CHAR))CHAR++
#define skipspaces(CHAR) if(CHAR)while(*CHAR==' ')CHAR++
#define cutspaces(CHAR) if(CHAR){int _L=strlen(CHAR); while(--_L>0 && CHAR[_L]==' ')CHAR[_L]=0;}
#define gotochr(CHAR,C) if(CHAR)while(*CHAR && *CHAR!=C)CHAR++
-#define tr(CHAR,B,C) {char *_S=CHAR; while(*_S){ if(*_S==B)*_S=C; _S++; }}
#define strswitch(CHAR) {char *_K=CHAR; FILE *_F=NULL; {{
#define stroption(STR) if(eq(STR,_K))
#define match(KEY,VAL) {char *_K=KEY, *_V=VAL; FILE *_F=NULL; {{
//#define parse(F) {char *_; FILE *_F=fopen(F,"r"); if(_F) { while(!feof(_F)) { fstring(_,_F);
//#define fail }} else {{
//#define done }} if(_F)fclose(_F);}
-#define option(STR,SETVAR) if(_){char *_K,*_V,*_O,*_Q; duplicate(_,_Q); _O=_Q; tr(_O,'\t',' '); prefix(_K,_O,' '); if(eq(STR,_K)) {skipspaces(_O); prefix(_V,_O,'#'); cutspaces(_V); SETVAR=_V; _=NULL;} else free(_Q);}
-#define ioption(STR,SETVAR) if(_){char *_K,*_V,*_O,*_Q; duplicate(_,_Q); _O=_Q; tr(_O,'\t',' '); prefix(_K,_O,' '); if(eq(STR,_K)) {skipspaces(_O); prefix(_V,_O,'#'); cutspaces(_V); SETVAR=atoi(_V); _=NULL;} free(_Q);}
-#define loption(STR,SETVAR) if(_){char *_K,*_V,*_O,*_Q; duplicate(_,_Q); _O=_Q; tr(_O,'\t',' '); prefix(_K,_O,' '); if(eq(STR,_K)) {skipspaces(_O); prefix(_V,_O,'#'); cutspaces(_V); SETVAR=atol(_V); _=NULL;} free(_Q);}
-
-/* Dynamic list advanced I/O, updated 2003-05-30 by xCh. */
+//to do #define option(STR,SETVAR) if(_){char *_K,*_V,*_O,*_Q; duplicate(_,_Q); _O=_Q; tr(_O,'\t',' '); prefix(_K,_O,' '); if(eq(STR,_K)) {skipspaces(_O); prefix(_V,_O,'#'); cutspaces(_V); SETVAR=_V; _=NULL;} else free(_Q);}
+//to do #define ioption(STR,SETVAR) if(_){char *_K,*_V,*_O,*_Q; duplicate(_,_Q); _O=_Q; tr(_O,'\t',' '); prefix(_K,_O,' '); if(eq(STR,_K)) {skipspaces(_O); prefix(_V,_O,'#'); cutspaces(_V); SETVAR=atoi(_V); _=NULL;} free(_Q);}
+//to do #define loption(STR,SETVAR) if(_){char *_K,*_V,*_O,*_Q; duplicate(_,_Q); _O=_Q; tr(_O,'\t',' '); prefix(_K,_O,' '); if(eq(STR,_K)) {skipspaces(_O); prefix(_V,_O,'#'); cutspaces(_V); SETVAR=atol(_V); _=NULL;} free(_Q);}
-/* obsolete #define load(A,B,F,T,K) {char *_S; parses(_S,F) { create(A,T); A->K=_S; A->_eoln=TRUE; append(A,B);} done; A->_eoln=FALSE;} */
-/* obsolete #define save(A,B,F,K) {FILE *_F=fopen(F,"w"); if(_F) { for_each(A,B) {fputs(A->K,_F); if(A->_eoln) fputc('\n',_F);} fclose(_F);}} */
-
/* I/O sequences, updated 2003-05-29 by xCh. */
#define nullreopen(F) F=freopen("/dev/null","r",F)
#define shell(CMD) stdinredir(system(CMD))
#define paste(STR) stdinredir(fputs(STR,stdout))
-/* String iterations, updated 2003-06-19 by xCh. */
-
-#define split(A,B,C) for(prefix(A,B,C);A;(A!=B)&&prefix(A,B,C)||(A=NULL))
-#define valid_split(A,B,C) split(A,B,C) if(*A)
-#define columns(A,B,C,V) for(V=0,prefix(A,B,C);A;((A!=B)&&prefix(A,B,C)||(A=NULL)),V++)
-#define valid_columns(A,B,C,V) for(V=0,prefix(A,B,C);A;((A!=B)&&prefix(A,B,C))||(A=NULL)) if(*A&&++V)
-#define column(A,B,C,V) { int _V; columns(A,B,C,_V) if(_V==V) break; }
-#define valid_column(A,B,C,V) { int _V; valid_columns(A,B,C,_V) if(_V==V) break; }
-
/* Useful structures, updated 2003-05-29 by xCh. */
-//#define hashtable(TYPE,NAME,VALUE) struct TYPE { char *NAME; char *VALUE; list(TYPE); }
-//#define textfile(TYPE,LINE) struct TYPE { char *LINE; char _eoln; list(TYPE); }
//#define date(S) { time_t _T; _T=time(NULL); duplicate(ctime(&_T),S); }
/* ------------------------------------------------------------------- */
-/* ,-----------------------------------------------------------------------
+/* .----------------------------------------------------------------------.
/ 99. We have have done our homework - now let's have some fun:
'----------------------------------------------------------------------- */
#define _DEF_VARIABLES _GLOBALS _ISTACK _SSTACK _FSTACK _MSTACK _RSTACK //_QSTACK
program
{
Define_mems(zaznam,zaznamy,Zaznam);
-//Define_mem(zaznam,Zaznam); Define_mem(zaznamy,Zaznam);
print("4x insert(zaznam,zaznamy,order_by,i);");
zaznam=get_mem(Zaznam);
zaznam->j="bbbbb";
insert(zaznam,zaznamy,order_by,i);
zaznam=get_mem(Zaznam);
- zaznam->i=0;
+ zaznam->i=4;
zaznam->j="e";
insert(zaznam,zaznamy,order_by,i);
zaznam=get_mem(Zaznam);
zaznam->i=2;
- zaznam->j="cc";
+ zaznam->j="aaaa";
insert(zaznam,zaznamy,order_by,i);
- for_each(zaznam,zaznamy) print("i=",zaznam->i,"j=",zaznam->j);
+ for_each(zaznam,zaznamy) printf("i=%d, j=%s\n",zaznam->i,zaznam->j);
- puts("1x append(zaznam,zaznamy);");
+ print("1x append(zaznam,zaznamy);");
zaznam=get_mem(Zaznam);
- zaznam->i=4;
- zaznam->j="aaa";
+ zaznam->i=0;
+ zaznam->j="ccc";
append(zaznam,zaznamy);
- for_each(zaznam,zaznamy)printf("i=%d, j=%s\n",zaznam->i,zaznam->j);
+ for_each(zaznam,zaznamy) printf("i=%d, j=%s\n",zaznam->i,zaznam->j);
- puts("sort(zaznam,zaznamy,desc_order_by,i);");
+ print("sort(zaznam,zaznamy,desc_order_by,i);");
sort(zaznam,zaznamy,desc_order_by,i);
- for_each(zaznam,zaznamy)printf("i=%d, j=%s\n",zaznam->i,zaznam->j);
+ for_each(zaznam,zaznamy) printf("i=%d, j=%s\n",zaznam->i,zaznam->j);
- puts("sort(zaznam,zaznamy,desc_sort_by,j);");
- sort(zaznam,zaznamy,desc_sort_by,j);
- for_each(zaznam,zaznamy)printf("i=%d, j=%s\n",zaznam->i,zaznam->j);
+ print("sort(zaznam,zaznamy,sort_by,j);");
+ sort(zaznam,zaznamy,sort_by,j);
+ for_each(zaznam,zaznamy) printf("i=%d, j=%s\n",zaznam->i,zaznam->j);
- puts("remove(zaznam,zaznamy,zaznam->i==1);");
+ print("remove(zaznam,zaznamy,zaznam->i==1);");
remove(zaznam,zaznamy,zaznam->i==1);
- for_each(zaznam,zaznamy)printf("i=%d, j=%s\n",zaznam->i,zaznam->j);
+ for_each(zaznam,zaznamy) printf("i=%d, j=%s\n",zaznam->i,zaznam->j);
- puts("drop(zaznam,zaznamy);");
+ print("drop(zaznam,zaznamy);");
drop(zaznam,zaznamy);
- for_each(zaznam,zaznamy)printf("i=%d, j=%s\n",zaznam->i,zaznam->j);
+ for_each(zaznam,zaznamy) printf("i=%d, j=%s\n",zaznam->i,zaznam->j);
}