GPL virus attached
[svn/Cll1h/.git] / cll1.h
CommitLineData
04a13a6f 1/* ------------------------------------------------------------------- */
2/* C<<1 header file v0.7.1 - style sheet for ANSI C */
3/* CERL - Cumbersome Extraction and Report Language */
4/* ------------------------------------------------------------------- */
5/* Copyright (c) 2004-2008 Michael xChaos Polak, x(at)n.cz
30628092 6
7 The C<<1 header file is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 The C<<1 header file is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to
04a13a6f 19 Michael Polak, Svojsikova 7, 169 00 Praha 6 Czech Republic */
20/* ------------------------------------------------------------------- */
30628092 21#ifndef __CLL1H__
22#define __CLL1H__
23
30628092 24#include <string.h>
04a13a6f 25#include <malloc.h>
30628092 26#include <time.h>
04a13a6f 27#include <stdlib.h>
28#include <unistd.h>
29#ifdef USE_LIBRARY_MYSQL
30#include <mysql/mysql.h>
31#endif
32#ifdef USE_LIBRARY_FASTCGI
33#include <fcgi_stdio.h>
34#else
35#include <stdio.h>
36#endif
37/* ------------------------------------------------------------------- */
38/* 1. C<<1 constants and optional keywords, updated 2008-01-07 by xCh. */
39/* ------------------------------------------------------------------- */
40#define then
30628092 41#define not !
4a48705a 42#define and &&
43#define or ||
30628092 44#define TRUE 1
45#define FALSE 0
04a13a6f 46/* ------------------------------------------------------------------- */
47/* 2. C<<1 data types - updated 2008-01-07 by xCh. */
48/* ------------------------------------------------------------------- */
49#define list(T) struct T *_next
50#define tree(T) struct T *_next;struct T *_seek
51#define create(A,T) (A=(struct T *)malloc(sizeof(struct T)),A->_next=NULL,A)
4a48705a 52#define push(A,B) ((A && A!=B)?A->_next=B:0,B=A)
53#define pop(A,B) (B?((A?free(A):0),A=B=B->_next):(A=NULL))
04a13a6f 54#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);
79c1af4b 55#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); }
4a48705a 56#define drop(A,B) for( A=B; A || (B=NULL); B=A, A=A->_next, free(B) )
04a13a6f 57/* ------------------------------------------------------------------- */
58/* 3. C<<1 iterators - updated 2008-01-07 by xCh. */
59/* ------------------------------------------------------------------- */
60#define loop while(TRUE)
956a4c05 61#define repeat(N) if(N>0) _NEW_I for_range(_I,1,N)
086367cd 62#define for_range(VAR,FROM,TO) for( VAR=FROM ; FROM<=TO?VAR<=TO:VAR>=TO ; FROM<=TO?VAR++:VAR--)
04a13a6f 63#define for_each(A,B) for(A=B; A; A=A->_next)
64#define for_search(A,B,C) for_each(A,B) if(C)
65/*to do: #define for_file_lines(STR,F) _NEW_F for() */
66#ifdef USE_LIBRARY_MYSQL
67#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))
68#endif
69#ifdef USE_LIBRARY_FASTCGI
70#define while_fastcgi_accept while(FCGI_Accept()>=0)
71#endif
72/*obsolete #define every(A,B) for( A=B; A; A=A->_next) */
73/*obsolete #define search(A,B,C) every(A,B) if(C) */
74/*obsolete #define find(A,B,C) search(A,B,C) break; if(A) */
75
76/* ------------------------------------------------------------------- */
77/* 4.C<<1 conditionals - updated 2008-01-07 by xCh. */
78/* ------------------------------------------------------------------- */
79#define if_exists(A,B,C) for_search(A,B,C) break; if(A)
80
81/* ------------------------------------------------------------------- */
82/* old - from version 0.6 */
83/* ------------------------------------------------------------------- */
30628092 84/* EXP macros for Dummysort sequences, updated 2003-05-29 by xCh. */
85
86#define order_by(K1,K2) (K1>K2)
87#define desc_order_by(K1,K2) (K1<K2)
88#define sort_by(K1,K2) (strcasecmp(K1, K2)>0)
89#define desc_sort_by(K1,K2) (strcasecmp(K1, K2)<0)
90#define ascii_by(K1,K2) (strcmp(K1, K2)>0)
91#define desc_ascii_by(K1,K2) (strcmp(K1, K2)<0)
92
93/* Dummysort sequences, updated 2003-05-29 by xCh. */
94
04a13a6f 95#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); }
30628092 96#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); }
97
98/* String macros & sequences, updated 2004-04-19 by xCh. */
99
100#define eq(A,B) !strcmp(A,B)
101#define strcmpi(A,B) strcasecmp(A,B)
102#define strlwr(A) {char *_S=A; while(_&&*_S){*_S=tolower(*_S);_S++;}}
103#define strupr(A) {char *_S=A; while(_&&*_S){*_S=toupper(*_S);_S++;}}
104#define string(S,L) (S=(char *)malloc(L),*S=0)
105#define duplicate(A,B) if(A) { string(B,strlen(A)+1); strcpy(B,A); }
106#define concatenate(A,B,C) if (A && B) { string(C,strlen(A)+strlen(B)+1); strcpy(C,A); strcat(C,B); }
107#define suffix(A,B,C) (((A=strrchr(B,C))&&!(*(A++)=0))||(A=B))
108#define prefix(A,B,C) ((A=B)&&((B=strchr(B,C))&&!(*(B++)=0)||(B=A)))
109#define gotoalpha(CHAR) if(CHAR)while(*CHAR && !isalpha(*CHAR))CHAR++
110#define goto_alpha(CHAR) if(CHAR)while(*CHAR && !isalpha(*CHAR) && *CHAR!='_')CHAR++
111#define gotoalnum(CHAR) if(CHAR)while(*CHAR && !isalnum(*CHAR))CHAR++
112#define goto_alnum(CHAR) if(CHAR)while(*CHAR && !isalnum(*CHAR) && *CHAR!='_')CHAR++
113#define skipalpha(CHAR) if(CHAR)while(*CHAR && isalpha(*CHAR))CHAR++
114#define skip_alpha(CHAR) if(CHAR)while(*CHAR && (isalpha(*CHAR) || *CHAR=='_'))CHAR++
115#define skipalnum(CHAR) if(CHAR)while(*CHAR && isalnum(*CHAR))CHAR++
116#define skip_alnum(CHAR) if(CHAR)while(*CHAR && (isalnum(*CHAR) || *CHAR=='_'))CHAR++
117#define skipspaces(CHAR) if(CHAR)while(*CHAR==' ')CHAR++
118#define cutspaces(CHAR) if(CHAR){int _L=strlen(CHAR); while(--_L>0 && CHAR[_L]==' ')CHAR[_L]=0;}
119#define gotochr(CHAR,C) if(CHAR)while(*CHAR && *CHAR!=C)CHAR++
120#define tr(CHAR,B,C) {char *_S=CHAR; while(*_S){ if(*_S==B)*_S=C; _S++; }}
121#define strswitch(CHAR) {char *_K=CHAR; FILE *_F=NULL; {{
122#define stroption(STR) if(eq(STR,_K))
123#define match(KEY,VAL) {char *_K=KEY, *_V=VAL; FILE *_F=NULL; {{
124#define assign(STR,SETVAR) stroption(STR) SETVAR=_V
04a13a6f 125/* ------------------------------------------------------------------- */
126/* Infrastructure, updated 2008-01-08 by xCh. */
127/* ------------------------------------------------------------------- */
128/* old #define program int _I; int main(int argc, char **argv) */
4a48705a 129#define _ISTACK struct _IStack { int I; int _23; list(_IStack); } *_Iatom,*_Istack=NULL;
130#define _SSTACK struct _SStack { char *S; int _23; list(_SSTACK); } *_Satom,*_Sstack=NULL;
131#define _FSTACK struct _FStack { FILE *F; int _23; list(_FSTACK); } *_Fatom,*_Fstack=NULL;
04a13a6f 132#ifdef USE_LIBRARY_MYSQL
133#define _MSTACK struct _MStack { MYSQL *M; int _23; list(_MStack); } *_Matom,*_Mstack=NULL;
134#define _RSTACK struct _RStack { MYSQL_RES *R; int _23; list(_RStack); } *_Ratom,*_Rstack=NULL;
135#else
136#define _MSTACK
137#define _RSTACK
138#endif
139#define program _ISTACK _SSTACK _FSTACK _MSTACK _RSTACK int main(int argc, char **argv)
140
141#define _NEW_(ATOM,STACK,TYPE) (create(ATOM,TYPE),ATOM->_23=1,push(ATOM,STACK);ATOM->_23||pop(ATOM,STACK)&&0;ATOM->_23--)
142#define _NEW_I for _NEW_(_Iatom,_Istack,_IStack)
143//#define _NEW_I for(create(_Iatom,_IStack),_Iatom->_23=1,push(_Iatom,_Istack);_Iatom->_23||pop(_Iatom,_Istack)&&0;_Iatom->_23--)
4a48705a 144#define _NEW_S for(create(_Satom,_SStack),_Satom->_23=1,push(_Satom,_Sstack);_Satom->_23||pop(_Satom,_Sstack)&&0;_Satom->_23--)
145#define _I _Iatom->I
146#define _S _Satom->I
04a13a6f 147
148/* Section For Dummies part 2, updated 2004-05-07 by xCh. */
149
30628092 150#define arguments if(argc>1) for(_I=1;_I<argc;_I++)
151#define argument(A) if(eq(argv[_I],A))
152#define thisargument(S) (S=argv[_I])
153#define nextargument(S) if(_I+1<argc && (S=argv[++_I]))
154
155/* I/O iterations, updated 2004-04-19 by xCh. */
156
157#define fparse(S,L,F) for(fgets(S,L,F);*S && !feof(F);fgets(S,L,F))
158#define input(S,L) fparse(S,L,stdin)
159#define fstring(S,F) { int _C=0,_L=0; fpos_t _P; fgetpos(F,&_P); while(_C!='\n' && !feof(F)){ _C=fgetc(F); _L++; } string(S,_L); fsetpos(F,&_P);fgets(S,_L,F);fgetc(F);}
160#define parses(S,F) {FILE *_F=fopen(F,"r"); if(_F) { while(!feof(_F)) { fstring(S,_F);
161#define parse(F) {char *_; FILE *_F=fopen(F,"r"); if(_F) { while(!feof(_F)) { fstring(_,_F);
162#define fail }} else {{
163#define done }} if(_F)fclose(_F);}
164#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);}
165#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);}
166#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);}
167
168/* Dynamic list advanced I/O, updated 2003-05-30 by xCh. */
169
04a13a6f 170/* 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;} */
171/* 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);}} */
30628092 172
173/* I/O sequences, updated 2003-05-29 by xCh. */
174
175#define nullreopen(F) F=freopen("/dev/null","r",F)
176#define stdinredir(CMD) {int _r[2];pipe(_r);if(fork()==0){dup2(_r[1],1);close(_r[0]);CMD;exit(0);}nullreopen(stdin);dup2(_r[0],0);close(_r[1]);}
177#define shell(CMD) stdinredir(system(CMD))
178#define paste(STR) stdinredir(fputs(STR,stdout))
179
180/* String iterations, updated 2003-06-19 by xCh. */
181
182#define split(A,B,C) for(prefix(A,B,C);A;(A!=B)&&prefix(A,B,C)||(A=NULL))
183#define valid_split(A,B,C) split(A,B,C) if(*A)
184#define columns(A,B,C,V) for(V=0,prefix(A,B,C);A;((A!=B)&&prefix(A,B,C)||(A=NULL)),V++)
185#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)
186#define column(A,B,C,V) { int _V; columns(A,B,C,_V) if(_V==V) break; }
187#define valid_column(A,B,C,V) { int _V; valid_columns(A,B,C,_V) if(_V==V) break; }
188
189/* Useful structures, updated 2003-05-29 by xCh. */
190
191#define hashtable(TYPE,NAME,VALUE) struct TYPE { char *NAME; char *VALUE; list(TYPE); }
192#define textfile(TYPE,LINE) struct TYPE { char *LINE; char _eoln; list(TYPE); }
193#define date(S) { time_t _T; _T=time(NULL); duplicate(ctime(&_T),S); }
194
04a13a6f 195#ifdef USE_LIBRARY_MYSQL
196/* ------------------------------------------------------------------- */
197/* MySQL Infrastructure and basic macros - updated 2007-12-19 by xCh. */
198/* ------------------------------------------------------------------- */
199#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))
200#endif
201
30628092 202#endif
This page took 0.223327 seconds and 4 git commands to generate.