preliminary work on version 0.7.1 - WARNING, HIGHLY UNSTABLE !
[svn/Cll1h/.git] / cll1.h
diff --git a/cll1.h b/cll1.h
index 3e09887de7d725552e52a795d7e3f99ac3fc7454..597a76adcbb260f32fbe04ddf127ae84fb3904f4 100644 (file)
--- a/cll1.h
+++ b/cll1.h
@@ -1,8 +1,8 @@
-
-/* C<<1 header file v0.7 - style sheet for ANSI C  */
-/* Please pronounce as "cee-shift-left-by-one" :)  */
-
-/* Copyright (G) 2004-2007 Michael xChaos Polak, x(at)n.cz
+/* ------------------------------------------------------------------- */
+/* 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
 
    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
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, write to 
-   Michael Polak, Svojsikova 7, 169 00 Praha 6 Czech Republic */
-
-
+   Michael Polak, Svojsikova 7, 169 00 Praha 6 Czech Republic          */
+/* ------------------------------------------------------------------- */
 #ifndef __CLL1H__
 #define __CLL1H__
 
-#include <stdio.h>
 #include <string.h>
+#include <malloc.h>
 #include <time.h>
-#include <malloc.h> 
-#include <stdlib.h> 
-
-/* Section For Dummies part 1, updated 2004-05-07 by xCh. */
-
+#include <stdlib.h>
+#include <unistd.h>
+#ifdef USE_LIBRARY_MYSQL
+#include <mysql/mysql.h>
+#endif
+#ifdef USE_LIBRARY_FASTCGI
+#include <fcgi_stdio.h>
+#else
+#include <stdio.h>
+#endif
+/* ------------------------------------------------------------------- */
+/* 1. C<<1 constants and optional keywords, updated 2008-01-07 by xCh. */
+/* ------------------------------------------------------------------- */
+#define then
 #define not !
 #define and &&
 #define or ||
 #define TRUE 1
 #define FALSE 0
-#define loop while(1)
-//#define iterate(VAR,FROM,TO) for(VAR=FROM; VAR <= TO; VAR++)
-//#define repeat(N) iterate(_i,1,N)
-#define repeat(N) _NEW_I for range(_I,1,N)
-
-/* Dynamic list macros & sequences, updated 2003-05-29 by xCh. */
-
-#define list(T) struct T *_next 
-#define create(A,T) (A=(struct T *)malloc(sizeof(struct T)),A->_next=NULL)
+/* ------------------------------------------------------------------- */
+/* 2. C<<1 data types - updated 2008-01-07 by xCh.                     */
+/* ------------------------------------------------------------------- */
+#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; search(A,B,!A->_next) {A->_next=N; break;}} else push(A,B);
-#define remove(A,B,C) { void **_D=NULL; for each(A,B) if(C) { if(_D)*_D=A->_next; else B=A->_next; free(A);} else _D=(void *)&(A->_next); }
+#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); A=NULL;} else _D=(void *)&(A->_next); }
 #define drop(A,B) for( A=B; A || (B=NULL); B=A, A=A->_next, free(B) )
-
-/* Dynamic list iterations and sequences, updated 2003-05-29 by xCh. */
-
-#define every(A,B) for( A=B; A; A=A->_next)
-#define search(A,B,C) every(A,B) if(C)
-#define find(A,B,C) search(A,B,C) break; if(A)
-
-/* Enlightened iterations usable in for() , updated 2007-12-11 by xCh. */
-
-#define range(VAR,FROM,TO) (VAR=FROM; VAR <= TO; VAR++)
-#define each(A,B) ( A=B; A; A=A->_next)
-#define lines(STR,F) ()
-
+/* ------------------------------------------------------------------- */
+/* 3. C<<1 iterators - updated 2008-01-07 by xCh.                      */
+/* ------------------------------------------------------------------- */
+#define loop while(TRUE)
+#define repeat(N) _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)
+/*to do: #define for_file_lines(STR,F) _NEW_F for() */
+#ifdef USE_LIBRARY_MYSQL
+#define for_mysql_query_results(ROW,QUERY) _NEW_(_Ratom,_Rstack,_RStack)for(_Ratom->R=(mysql_query(_Matom->M,QUERY)?NULL:mysql_use_result(_Matom->M)),ROW=(_Ratom->R?mysql_fetch_row(_Ratom->R):NULL);ROW;ROW=mysql_fetch_row(_Ratom->R))
+#endif
+#ifdef USE_LIBRARY_FASTCGI
+#define while_fastcgi_accept while(FCGI_Accept()>=0)
+#endif
+/*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 if_exists(A,B,C) for_search(A,B,C) break; if(A)
+
+/* ------------------------------------------------------------------- */
+/* old - from version 0.6 */
+/* ------------------------------------------------------------------- */
 /* EXP macros for Dummysort sequences, updated 2003-05-29 by xCh. */
 
 #define order_by(K1,K2) (K1>K2)
@@ -73,7 +92,7 @@
 
 /* Dummysort sequences, updated 2003-05-29 by xCh. */
 
-#define insert(A,B,EXP,K) { if(B) { void **_L=NULL, *H=B; search(B,H,EXP(B->K,A->K)) { if(_L) {*_L=A; A->_next=B; } else push(A,H); break; } else _L=(void *)&(B->_next); if(!B)*_L=A; B=H; } else push(A,B); }
+#define insert(A,B,EXP,K) { if(B) { void **_L=NULL, *H=B; for_search(B,H,EXP(B->K,A->K)) { if(_L) {*_L=A; A->_next=B; } else push(A,H); break; } else _L=(void *)&(B->_next); if(!B)*_L=A; B=H; } else push(A,B); }
 #define sort(A,B,EXP,K) { void *_C; A=B; B=NULL; do { _C=A->_next; A->_next=NULL; insert(A,B,EXP,K); A=_C; } while(_C); }
 
 /* String macros & sequences, updated 2004-04-19 by xCh. */
 #define stroption(STR) if(eq(STR,_K))
 #define match(KEY,VAL) {char *_K=KEY, *_V=VAL; FILE *_F=NULL; {{ 
 #define assign(STR,SETVAR) stroption(STR) SETVAR=_V
-
-/* Section For Dummies part 2, updated 2004-05-07 by xCh. */
-
-#define program int _I; int main(int argc, char **argv)
+/* ------------------------------------------------------------------- */
+/* Infrastructure, updated 2008-01-08 by xCh.                          */
+/* ------------------------------------------------------------------- */
+/* old #define program int _I; int main(int argc, char **argv) */
 #define _ISTACK struct _IStack { int I; int _23; list(_IStack); } *_Iatom,*_Istack=NULL;
 #define _SSTACK struct _SStack { char *S; int _23; list(_SSTACK); } *_Satom,*_Sstack=NULL;
 #define _FSTACK struct _FStack { FILE *F; int _23; list(_FSTACK); } *_Fatom,*_Fstack=NULL;
-#define program2 _ISTACK _SSTACK _FSTACK int main(int argc, char **argv)
-#define _NEW_I for(create(_Iatom,_IStack),_Iatom->_23=1,push(_Iatom,_Istack);_Iatom->_23||pop(_Iatom,_Istack)&&0;_Iatom->_23--)
+#ifdef USE_LIBRARY_MYSQL
+#define _MSTACK struct _MStack { MYSQL *M; int _23; list(_MStack); } *_Matom,*_Mstack=NULL;
+#define _RSTACK struct _RStack { MYSQL_RES *R; int _23; list(_RStack); } *_Ratom,*_Rstack=NULL;
+#else
+#define _MSTACK
+#define _RSTACK
+#endif
+#define program _ISTACK _SSTACK _FSTACK _MSTACK _RSTACK int main(int argc, char **argv)
+
+#define _NEW_(ATOM,STACK,TYPE) (create(ATOM,TYPE),ATOM->_23=1,push(ATOM,STACK);ATOM->_23||pop(ATOM,STACK)&&0;ATOM->_23--)
+#define _NEW_I for _NEW_(_Iatom,_Istack,_IStack)
+//#define _NEW_I for(create(_Iatom,_IStack),_Iatom->_23=1,push(_Iatom,_Istack);_Iatom->_23||pop(_Iatom,_Istack)&&0;_Iatom->_23--)
 #define _NEW_S for(create(_Satom,_SStack),_Satom->_23=1,push(_Satom,_Sstack);_Satom->_23||pop(_Satom,_Sstack)&&0;_Satom->_23--)
 #define _I _Iatom->I
 #define _S _Satom->I
+
+/* Section For Dummies part 2, updated 2004-05-07 by xCh. */
+
 #define arguments if(argc>1) for(_I=1;_I<argc;_I++) 
 #define argument(A) if(eq(argv[_I],A))
 #define thisargument(S) (S=argv[_I])
 
 /* Dynamic list advanced I/O, updated 2003-05-30 by xCh. */
 
-#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;}
-#define save(A,B,F,K) {FILE *_F=fopen(F,"w"); if(_F) { every(A,B) {fputs(A->K,_F); if(A->_eoln) fputc('\n',_F);} fclose(_F);}}
+/* 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 textfile(TYPE,LINE) struct TYPE { char *LINE; char _eoln; list(TYPE); }
 #define date(S) { time_t _T; _T=time(NULL); duplicate(ctime(&_T),S); }
 
+#ifdef USE_LIBRARY_MYSQL
+/* ------------------------------------------------------------------- */
+/* MySQL Infrastructure and basic macros -  updated 2007-12-19 by xCh. */
+/* ------------------------------------------------------------------- */
+#define mysql_connect(S,U,P,D) (create(_Matom,_MStack) && push(_Matom,_Mstack) && (_Matom->M=mysql_init(NULL)),(_Matom->M && mysql_real_connect(_Matom->M,S,U,P,D,0,NULL,0)?_Matom->M:NULL))
+#endif
+
 #endif
This page took 0.153354 seconds and 4 git commands to generate.