some updates
[svn/Cll1h/.git] / cll1.h
CommitLineData
005431b8 1/* .----------------------------------------------------------------------.
2 / C<<1 header file - C language style sheet - GNU C/ANSI C99 compliant
3 / Cumbersome Extraction and Report Language - http://cll1h.arachne.cz/
f5725936 4'---------------------------------------------------------------------- */
5/*
6 Copyright (c) 2004-2008 Michael xChaos Polak - x(at)n.cz
30628092 7
8 The C<<1 header file is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 The C<<1 header file is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
ceb7f88d 18 You should have received a copy of the GNU Lesser General Public License
19 along with C<<1 header file; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
097bac9a 22*/
097bac9a 23#ifndef _CLL1_H
24#define _CLL1_H
f5725936 25#define CLL1H_VERSION "0.7.1"
005431b8 26/* .----------------------------------------------------------------------.
f5725936 27 / 0. Library definitions not parsed by @CC, updated 2008-01-26 xCh.
28 '---------------------------------------------------------------------- */
29/*
30@define USE_LIBRARY_MYSQL -lmysqlclient
31@define USE_LIBRARY_FASTCGI -lfcgi
32@define USE_PREPROCESSOR cake *.html *.xml > _include.c
33@define USE_POSTPROCESSOR strip @
34*/
005431b8 35/* .----------------------------------------------------------------------.
f5725936 36 / 1. C<<1 header auto include, updated 2008-01-26 xCh.
37 '---------------------------------------------------------------------- */
bce4b05d 38#ifndef DISABLE_LIBRARY_LIBC
30628092 39#include <string.h>
04a13a6f 40#include <malloc.h>
30628092 41#include <time.h>
04a13a6f 42#include <stdlib.h>
420bb771 43#include <stdarg.h>
04a13a6f 44#include <unistd.h>
04a13a6f 45#ifdef USE_LIBRARY_FASTCGI
46#include <fcgi_stdio.h>
47#else
48#include <stdio.h>
49#endif
bce4b05d 50#endif
51#ifdef USE_LIBRARY_MYSQL
52#include <mysql/mysql.h>
53#endif
005431b8 54/* .----------------------------------------------------------------------.
f5725936 55 / 2. C<<1 then buddhist section, updated 2008-01-26 xCh.
56 '----------------------------------------------------------------------- */
57#ifndef DISABLE_MODULE_THEN_BUDDHISM
04a13a6f 58#define then
bce4b05d 59#define boolean int
60#define MAYBE (int)((RANDOM_SEED?random():(srandom(RANDOM_SEED=time(NULL)),random()))%2)
f5725936 61#define WHOKNOWS (int)(srandom(time(NULL)),random()%2)
b3674906 62#define create_var(ID,TYPE,INIT) TYPE ID=INIT
63#define define_var(ID,TYPE) TYPE ID
f5725936 64#endif
005431b8 65/* .----------------------------------------------------------------------.
bce4b05d 66 / 3. C<<1 almost then buddhist section, updated 2008-01-26 xCh.
f5725936 67 '----------------------------------------------------------------------- */
30628092 68#define not !
4a48705a 69#define and &&
70#define or ||
30628092 71#define TRUE 1
72#define FALSE 0
bce4b05d 73#define coalesce(VAR,NOTNULLNORFALSE) (VAR?VAR:(NOTNULLNORFALSE))
74#define bool_str(VALUE) ((VALUE)?"TRUE":"FALSE")
75#define _CLL1_GLOBALS char *NIL="NULL", *EOL="\n", *OFS=" ", *IFS=" \t\n"; time_t RANDOM_SEED=0;
005431b8 76/* .----------------------------------------------------------------------.
547332b7 77 / 4. C<<1 data declaration and allocation, updated 2008-01-31 xCh.
f5725936 78 '----------------------------------------------------------------------- */
bce4b05d 79#define mem struct
547332b7 80#define this_is(TYPE) struct *TYPE this
b3674906 81#define create_mem(ID,...) struct _ARG1(__VA_ARGS__,) *ID=get_mem(__VA_ARGS__)
bce4b05d 82#define new_mem(ID,...) struct _ARG1(__VA_ARGS__,) *ID=init_mem(__VA_ARGS__)
b3674906 83#define define_mem(ID,TYPE) struct TYPE *ID=NULL
84#define define_mems(ID1,ID2,TYPE) define_mem(ID1,TYPE); define_mem(ID2,TYPE)
bce4b05d 85#define get_mem(...) (struct _ARG1(__VA_ARGS__,)*)_cll1_malloc(sizeof(struct _ARG1(__VA_ARGS__,)), _ARG2(__VA_ARGS__,,) - 0 )
86#define init_mem(...) _mem_##TYPE##_( _ARG2(__VA_ARGS__,,) - 0 )
547332b7 87#define construct_mem(TYPE) (struct TYPE *)_mem_##TYPE##_(void) { create_mem(this,TYPE);/* <-' */ _init_mem_##TYPE##_(this); return this; } _init_mem_##TYPE##_(this_is(TYPE))
b3674906 88#define create_list(ID1,I2,TYPE) create_mem(ID1,TYPE); struct TYPE *ID2=((ID1->__next=NULL),ID1)
bce4b05d 89#define create_str(ID,INIT) char *ID=INIT
547332b7 90#define new_str(ID,...) char *ID=_cll1_get_str(__VA_ARGS__,NIL)
bce4b05d 91#define define_str(ID) char *ID=NULL
547332b7 92#define get_str(...) _cll1_get_str(__VA_ARGS__,NIL)
bce4b05d 93#define create_context(ID) create_mem(ID,_CTXAtom)
94#define define_context(ID) define_mem(ID,_CTXAtom)
f5725936 95#define list(TYPE) struct TYPE *__next
8db501a0 96#define tree(TYPE) struct TYPE *__next; struct TYPE *__seek
547332b7 97#define dictionary(TYPE) struct TYPE *__next; struct TYPE *__seek; char *__key
98#define array(TYPE) struct TYPE *__next; struct TYPE *__seek; int __key
f5725936 99#define interface(TYPE) struct TYPE *__interface
005431b8 100/* .----------------------------------------------------------------------.
f5725936 101 / 5. C<<1 string manipulation, updated 2008-01-26 xCh.
102 '----------------------------------------------------------------------- */
103#define eq(A,B) !strcmp(A,B)
104#define eqi(A,B) !strcasecmp(A,B)
bce4b05d 105#define print(...) _cll1_print(__VA_ARGS__,NIL)
106#define fprint(...) _cll1_fprint(__VA_ARGS__,NIL)
107#define file_print(...) _cll1_fprint(_F,__VA_ARGS__,NIL)
108#define echo(...) _cll1_echo(__VA_ARGS__,NIL)
109#define fecho(...) _cll1_fecho(__VA_ARGS__,NIL)
110#define file_echo(...) _cll1_fecho(_F,__VA_ARGS__,NIL)
005431b8 111#define suffix(A,B,C) (((A=strrchr(B,C))&&!(*(A++)=0))||(A=B))
112#define prefix(A,B,C) ((A=B),((B=strchr(B,C))&&!(*(B++)=0)||(B=A)))
547332b7 113#define tr(STR,B,C) _NEW(S,STR) while(S && *_S) { if(*_S==B)*_S=C; /* <-' */ _S++; }
005431b8 114/* .----------------------------------------------------------------------.
f5725936 115 / 6. C<<1 data container manipulation, updated 2008-01-26 xCh.
116 '----------------------------------------------------------------------- */
005431b8 117#define push(NODE,HEAD) ( NODE ? ((NODE->__next=HEAD),(HEAD=NODE)) : NULL )
118#define pop(NODE,HEAD) ( HEAD ? ((NODE=HEAD->__next),free(HEAD),(HEAD=NODE)) : (NODE=NULL) )
06ab91f0 119#define append(NODE,HEAD) { void *N=NODE; /* <-' */ NODE->__next=NULL; for_search(NODE,HEAD,!NODE->__next) { NODE->__next=N; break; } }
120#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); }
f5725936 121#define drop(NODE,HEAD) for( NODE=HEAD; NODE || (HEAD=NULL); HEAD=NODE, NODE=NODE->__next, free(HEAD) )
005431b8 122//to do: seek
123//to do: store
f5725936 124#define order_by(K1,K2) (K1>K2)
125#define desc_order_by(K1,K2) (K1<K2)
126#define sort_by(K1,K2) (strcasecmp(K1, K2)>0)
127#define desc_sort_by(K1,K2) (strcasecmp(K1, K2)<0)
128#define ascii_by(K1,K2) (strcmp(K1, K2)>0)
129#define desc_ascii_by(K1,K2) (strcmp(K1, K2)<0)
06ab91f0 130#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; } }
131#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); }
005431b8 132/* .----------------------------------------------------------------------.
f5725936 133 / 7. C<<1 builtin iterators and conditionals, updated 2008-01-26 xCh.
134 '----------------------------------------------------------------------- */
04a13a6f 135#define loop while(TRUE)
bce4b05d 136#define repeat(N) if(N>0) _NEW(I,0) while(_I++<N)
086367cd 137#define for_range(VAR,FROM,TO) for( VAR=FROM ; FROM<=TO?VAR<=TO:VAR>=TO ; FROM<=TO?VAR++:VAR--)
f5725936 138#define for_each(NODE,HEAD) for(NODE=HEAD; NODE; NODE=NODE->__next)
139#define for_search(NODE,HEAD,EXPR) for_each(NODE,HEAD) if(EXPR)
bce4b05d 140#define for_file_lines(STR,FNAME) /* _NEW(CTX,get_context()) file_read(FNAME) for(use_context(_CTX),STR=file_line(_F);release_context(_M),(*S && !feof(_F));STR=file_line(_F),end_context()) _CATCH */
141#define for_input_lines(S,L) /* _NEW(CTX,get_context()) for(use_context(_CTX),STR=file_get_line(stdin);release_context(_M),(*S && !feof(stdin));STR=file_get_line(stdin)) _CATCH */
142#define for_ints(VAR,...) _NEW(I,0) while((VAR=_cll1_for_ints(_I++,__VA_ARGS__,-1))>=0)
143#define for_strs(VAR,...) _NEW(I,0) while((VAR=(char *)_cll1_for_ptrs(_I++,__VA_ARGS__,NIL))!=NIL)
144#define for_args _NEW(I,1) while(_I++<argc)
8a93c4ed 145#define this_arg argv[_I]
420bb771 146#define next_arg ((_I+1<argc)?argv[_I]:NULL)
f5725936 147#define skip_next _I++
bce4b05d 148#define if_exists(A,B,C) for_search(A,B,C) break; if(A)
149#define if_args if(argc>1)
150#define switch_for_args for_args switch_str(this_arg)
151#define switch_str(STR) _NEW(S,STR)
152#define if_case(VAL) if(eq(argv[_I],VAL))
153#define for_fields(FIELD,STR) for_valid_split(FIELD,STR,OFS)
154#define for_split_str(A,B,C) for(prefix(A,B,C);A;(A!=B)&&prefix(A,B,C)||(A=NULL))
155#define for_valid_split(A,B,C) for_split_str(A,B,C) if(*A)
156#define switch_for_columns(A,B,C) _FOR_COLUMNS(A,B,C) switch(__I)
157#define switch_for_valid_columns(A,B,C) _FOR_VALID_COLUMNS(A,B,C) switch (_I)
158#define if_column_number(A,B,C,V) _FOR_COLUMNS(A,B,C) if(_I==V)
159#define if_valid_column_number(A,B,C,V) _FOR_VALID_COLUMNS(A,B,C) if(_I==V)
005431b8 160/* .----------------------------------------------------------------------.
547332b7 161 / 8. C<<1 object oriented infrastructure, updated 2008-01-31
8db501a0 162 '----------------------------------------------------------------------- */
547332b7 163#define my_self(TYPE) struct *TYPE self, void *_method
164#define we_are(TYPE) struct *TYPE _self, void *_method
165#define anonymous void *_self, void *_method
bce4b05d 166#define I_am(TYPE) struct TYPE *self=(struct TYPE *)_self
547332b7 167#define define_polymorph(METATYPE,ITYPE) struct METATYPE { struct ITYPE *__interface; };
168#define construct_interface(MTYPE,ITYPE) struct ITYPE *_interface_##MTYPE##ITYPE(void *dummy, ...) { define_mem(_FACE,ITYPE); va_list(ap); _bind_##MTYPE##ITYPE(_FACE); return _FACE; } void _bind_##MTYPE##ITYPE(struct IFACE *_FACE)
8db501a0 169#define bind_method(METHOD,FUNCTION) _FACE->METHOD=FUNCTION
547332b7 170#define new_interface(ID,MTYPE,...) struct _ARG1(__VA_ARGS__,) *ID=_interface_##MTYPE##_ARG1(__VA_ARGS__,) ((void *)__get_##TYPE##__VA_ARGS__,)
171#define init_interface(TYPE,...)
172#define construct_object(TYPE,...) (struct _ARG2(__VA_ARGS__,TYPE,) *)_object_##TYPE##_()
173#define init_object(TYPE,...) (struct TYPE *)_object_##TYPE##_(__VA_ARGS__)
174#define init_polymorph(TYPE,...) _object_##TYPE##_(__VA_ARGS__)
175#define _(OBJECT,...) ( _ASSERT(OBJECT), (*( OBJECT->interface->_ARG1(__VA_ARGS__,) )) ( OBJECT,OBJECT->interface->__VA_ARGS__ ) )
176#define __(OBJECT,...) ( _ASSERT(OBJECT), (*( __cll1_seekmethod(OBJECT->interface,_ARG1(__VA_ARGS__,)) )) ( OBJECT,OBJECT->interface->__VA_ARGS__ ) )
bce4b05d 177#define call(OBJTYPE,METHOD,...) { int _N=0; struct OBJTYPE *_OBJ; /* <-' */ while( (_OBJ=(struct OBJTYPE *)_cll1_for_ptrs(_N++,__VA_ARGS__,NIL))!=(struct OBJTYPE *)NIL ) _(_OBJ,METHOD); }
8db501a0 178/* .----------------------------------------------------------------------.
179 / 9. implementation of C<<1 library functions, updated 2008-01-26 xCh.
f5725936 180 '----------------------------------------------------------------------- */
f5725936 181#define _MALLOC void *_cll1_malloc(size_t size,...) { /*temporary solution*/ return malloc(size); }
bce4b05d 182#define _CLL1_FPRINT(IOSTREAM) { int ofs=0; va_list ap; /* <-' */ for(va_start(ap,s);s!=NIL;s=va_arg(ap,char *)) { if(ofs)fputs(OFS,IOSTREAM);else ofs=1;/**/fputs(coalesce(s,NIL),IOSTREAM); } va_end(ap); fputs(EOL,IOSTREAM); }
183#define _PRINT void _cll1_print(char *s,...) _CLL1_FPRINT(stdout)
184#define _FPRINT void _cll1_fprint(FILE *f,char *s,...) _CLL1_FPRINT(f)
185#define _CLL1_FECHO(IOSTREAM) { va_list ap; /* <-' */ for(va_start(ap,s);s!=NIL;s=va_arg(ap,char *)) fputs(coalesce(s,NIL),IOSTREAM); va_end(ap); }
186#define _ECHO void _cll1_echo(char *s,...) _CLL1_FECHO(stdout)
187#define _FECHO void _cll1_fecho(FILE *f,char *s,...) _CLL1_FECHO(f)
188#define _FOR_INTS int _cll1_for_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; }
189#define _FOR_PTRS void *_cll1_for_ptrs(int i, void *v, ...) { int j=0;va_list ap; /* <-' */ va_start(ap,v); while(v!=(void *)NIL && j++<i) v=va_arg(ap,void *); return v; }
005431b8 190/* .----------------------------------------------------------------------.
8db501a0 191 / 10. C<<1 globals and private macros, updated 2008-01-27 by xCh.
f5725936 192 '----------------------------------------------------------------------- */
8db501a0 193#define _ARG1(ARG1,...) ARG1
b3674906 194#define _ARG2(ARG1,ARG2,...) ARG2
bce4b05d 195#define _ANYSTACK(TYPE,NAME) struct _##NAME##Atom { TYPE NAME; int C; list(_##NAME##Atom); } *_##NAME##atom,*_##NAME##stack=NULL;
bce4b05d 196#define _CLL1_STACKS _ANYSTACK(int,I) _ANYSTACK(char *,S) _ANYSTACK(FILE *,F) _ANYSTACK(void *,CTX)
bce4b05d 197#define _NEW(NAME,VALUE) for(_##NAME##atom=get_mem(_##NAME##Atom),_##NAME##atom->NAME=(VALUE),_##NAME##atom->C=1,push(_##NAME##atom,_##NAME##stack);_##NAME##atom->C||(pop(_##NAME##atom,_##NAME##stack),0);_##NAME##atom->C--)
bce4b05d 198#define _I (_Iatom->I)
199#define _S (_Satom->S)
f5725936 200#define _F (_Satom->F)
bce4b05d 201#define _CTX (_CTXatom->CTX)
202#define _FOR_COLUMNS(A,B,C) _NEW(I,0) for( prefix(A,B,C) ; A ; ((A!=B)&&prefix(A,B,C)||(A=NULL) ),_I++ )
203#define _FOR_VALID_COLUMNS(A,B,C) _NEW(I,0) for( prefix(A,B,C) ; A ; ((A!=B)&&prefix(A,B,C))||(A=NULL) ) if(*A&&++_I)
005431b8 204/* .----------------------------------------------------------------------.
b194148d 205 / 11. C<<1 CGI and FASTCGI handling, updated 2008-01-16 by xCh.
f5725936 206 '----------------------------------------------------------------------- */
04a13a6f 207#ifdef USE_LIBRARY_FASTCGI
208#define while_fastcgi_accept while(FCGI_Accept()>=0)
7f13bdad 209#define USE_MODULE_CGI
210#endif
211#ifdef USE_MODULE_CGI
bce4b05d 212#define cgi(MIME) { char *PTR; /* <-' */ recycle_context(_CGI); _CGIdict=NULL; for_split_str(PTR,getenv("QUERY_STRING"),'&') /* _init_cgi */ if(MIME) printf("Content-type: %s\r\n\r\n",MIME); }
547332b7 213#define _GETCGI char *getcgi(VAR) { }
bce4b05d 214#define _CGI_GLOBALS define_context(_CGI); struct _CGIVariable { char *V; dictionary(_CGIVariable); } *_CGIvariable,*_CGIdict;
8db501a0 215#else
547332b7 216#define _GETCGI
bce4b05d 217#define _CGI_GLOBALS
04a13a6f 218#endif
005431b8 219/* .----------------------------------------------------------------------.
bce4b05d 220 / 12. MySQL wrappers + SQL object interface, updated 2007-12-19 by xCh.
f5725936 221 '----------------------------------------------------------------------- */
7f13bdad 222#ifdef USE_LIBRARY_MYSQL
bce4b05d 223#define define_sql(CONN) MYSQL *CONN
224#define create_sql(CONN) MYSQL *ID=mysql_init(NULL)
225#define sql_connect(CONN,S,U,P,D) mysql_real_connect(CONN,S,U,P,D,0,NULL,0)
226//todo sql_query
227//todo sql_queryf
228//todo for_sql_query_results(ROW,CONN,QUERY)
229//todo for_sql_queryf_results
230#define if_db_connect(U,P,D) _NEW(SQLC,mysql_init(NULL)) for(;_SQLC && mysql_real_connect(_SQLC,"localhost",U,P,D,0,NULL,0);mysql_close(SQLC),SQLC=NULL)
231#define for_db_query_results(ROW,QUERY) _NEW(MYSQLR,mysql_query(_MYSQLC,QUERY)) for( (_SQLR=(_MYSQLR?0:mysql_use_result(_MYSQLC))),(ROW=(_MYSQLR?mysql_fetch_row(_MYSQLR):NULL)) ; ROW ; ROW=mysql_fetch_row(_MYSQLR) )
232//todo db_query
233//todo for_db_results
234//todo for_db_queryf_results(ROW,...)
235//todo db_queryf
236#define _MYSQLC (_MYSQLCatom->MYSQLC)
237#define _MYSQLR (_MYSQLRatom->MYSQLR)
238#define _SQL_GLOBALS _ANYSTACK(MYSQL,MYSQLC) _ANYSTACK(MYSQL_RES,MYSQLR)
7f13bdad 239#else
bce4b05d 240#define _SQL_GLOBALS
7f13bdad 241#endif
bce4b05d 242//#ifdef USE_INTERFACE_SQL
243//todo #define _SQL_OBJECT mem Sql { interface(SqlInterface); char *hostname; char *username; char *password; char *database; }
244//todo #define _SQL_CONSTRUCT define_construct(Sql) { self->hostname="localhost"; }
245//#endif
04a13a6f 246/* ------------------------------------------------------------------- */
7f13bdad 247/* old - from version 0.6 */
f5725936 248/* =================================================================== */
7f13bdad 249/*
250obsolete
30628092 251#define strlwr(A) {char *_S=A; while(_&&*_S){*_S=tolower(*_S);_S++;}}
252#define strupr(A) {char *_S=A; while(_&&*_S){*_S=toupper(*_S);_S++;}}
253#define string(S,L) (S=(char *)malloc(L),*S=0)
254#define duplicate(A,B) if(A) { string(B,strlen(A)+1); strcpy(B,A); }
255#define concatenate(A,B,C) if (A && B) { string(C,strlen(A)+strlen(B)+1); strcpy(C,A); strcat(C,B); }
30628092 256#define gotoalpha(CHAR) if(CHAR)while(*CHAR && !isalpha(*CHAR))CHAR++
257#define goto_alpha(CHAR) if(CHAR)while(*CHAR && !isalpha(*CHAR) && *CHAR!='_')CHAR++
258#define gotoalnum(CHAR) if(CHAR)while(*CHAR && !isalnum(*CHAR))CHAR++
259#define goto_alnum(CHAR) if(CHAR)while(*CHAR && !isalnum(*CHAR) && *CHAR!='_')CHAR++
260#define skipalpha(CHAR) if(CHAR)while(*CHAR && isalpha(*CHAR))CHAR++
261#define skip_alpha(CHAR) if(CHAR)while(*CHAR && (isalpha(*CHAR) || *CHAR=='_'))CHAR++
262#define skipalnum(CHAR) if(CHAR)while(*CHAR && isalnum(*CHAR))CHAR++
263#define skip_alnum(CHAR) if(CHAR)while(*CHAR && (isalnum(*CHAR) || *CHAR=='_'))CHAR++
264#define skipspaces(CHAR) if(CHAR)while(*CHAR==' ')CHAR++
265#define cutspaces(CHAR) if(CHAR){int _L=strlen(CHAR); while(--_L>0 && CHAR[_L]==' ')CHAR[_L]=0;}
266#define gotochr(CHAR,C) if(CHAR)while(*CHAR && *CHAR!=C)CHAR++
30628092 267#define strswitch(CHAR) {char *_K=CHAR; FILE *_F=NULL; {{
268#define stroption(STR) if(eq(STR,_K))
269#define match(KEY,VAL) {char *_K=KEY, *_V=VAL; FILE *_F=NULL; {{
270#define assign(STR,SETVAR) stroption(STR) SETVAR=_V
7f13bdad 271*/
30628092 272/* I/O iterations, updated 2004-04-19 by xCh. */
273
bce4b05d 274//#define fparse(S,L,F) for(fgets(S,L,F);*S && !feof(F);fgets(S,L,F))
275//#define input(S,L) fparse(S,L,stdin)
276//#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);}
277//#define parses(S,F) {FILE *_F=fopen(F,"r"); if(_F) { while(!feof(_F)) { fstring(S,_F);
f5725936 278//obsolete
279//#define parse(F) {char *_; FILE *_F=fopen(F,"r"); if(_F) { while(!feof(_F)) { fstring(_,_F);
280//#define fail }} else {{
281//#define done }} if(_F)fclose(_F);}
005431b8 282//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);}
283//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);}
284//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);}
30628092 285
30628092 286/* I/O sequences, updated 2003-05-29 by xCh. */
287
288#define nullreopen(F) F=freopen("/dev/null","r",F)
289#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]);}
290#define shell(CMD) stdinredir(system(CMD))
291#define paste(STR) stdinredir(fputs(STR,stdout))
292
30628092 293/* Useful structures, updated 2003-05-29 by xCh. */
294
f5725936 295//#define date(S) { time_t _T; _T=time(NULL); duplicate(ctime(&_T),S); }
097bac9a 296/* ------------------------------------------------------------------- */
297/* some general ideas, unfinished */
f5725936 298//bind_exception, unbind_exception
7f13bdad 299//#define _CLL1_THROW(ERR)
f5725936 300//#define _CLL1_TRY _NEW_E for(bind_exception(0,NULL);;) if () {.... if(_Eatom->SYS) { if(_Eatom->RET) return; else break;} else { }
420bb771 301//#define _ASSERT(EXPR) assert(EXPR)
f5725936 302/* =================================================================== */
420bb771 303
005431b8 304/* .----------------------------------------------------------------------.
f5725936 305 / 99. We have have done our homework - now let's have some fun:
306 '----------------------------------------------------------------------- */
bce4b05d 307#define _DEF_VARIABLES _CLL1_GLOBALS _CLL1_STACKS _SQL_GLOBALS _CGI_GLOBALS
308#define _DEF_FUNCTIONS _MALLOC _ECHO _PRINT _FECHO _FPRINT _FOR_INTS _FOR_PTRS //_GET_STR _GET_MEM
309#define _DEF_INTERFACE //_SQL_IFC _CAKE_IFC _STD_IFC _X_IFC
f5725936 310#define implement_cll1_library _DEF_VARIABLES _DEF_FUNCTIONS _DEF_INTERFACE
311#ifdef USE_PREPROCESSOR
312#include "_include.c"
313#endif
420bb771 314#define program implement_cll1_library int main(int argc, char **argv)
f5725936 315/* #ifndef _CLL1_H */
420bb771 316#endif
This page took 0.586319 seconds and 4 git commands to generate.