WEIRDINT constant added -> for_ints() interator now accepts negative integers
[svn/Cll1h/.git] / cll1.h
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/
4 '---------------------------------------------------------------------- */
5 /*
6 Copyright (c) 2004-2008 Michael xChaos Polak - x(at)n.cz
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
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
22 */
23 #ifndef _CLL1_H
24 #define _CLL1_H
25 #define CLL1H_VERSION "0.7.1"
26 /* .----------------------------------------------------------------------.
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 */
35 /* .----------------------------------------------------------------------.
36 / 1. C<<1 header auto include, updated 2008-01-26 xCh.
37 '---------------------------------------------------------------------- */
38 #ifndef DISABLE_LIBRARY_LIBC
39 #include <string.h>
40 #include <strings.h>
41 #include <malloc.h>
42 #include <time.h>
43 #include <stdlib.h>
44 #include <stdarg.h>
45 #include <unistd.h>
46 #ifdef USE_LIBRARY_FASTCGI
47 #include <fcgi_stdio.h>
48 #else
49 #include <stdio.h>
50 #endif
51 #endif
52 #ifdef USE_LIBRARY_MYSQL
53 #include <mysql/mysql.h>
54 #endif
55 /* .----------------------------------------------------------------------.
56 / 2. C<<1 then buddhist section, updated 2008-01-26 xCh.
57 '----------------------------------------------------------------------- */
58 #ifndef DISABLE_MODULE_THEN_BUDDHISM
59 #define then
60 #define MAYBE (int)((long)(RANDOM_SEED?random():((RANDOM_SEED=(unsigned)time(NULL)),srandom(RANDOM_SEED),random()))%2)
61 #define WHOKNOWS (int)(srandom((unsigned)time(NULL)),random()%2)
62 #define create_var(ID,TYPE,EXPR) TYPE ID=(EXPR)
63 #define def_var(ID,TYPE) TYPE ID
64 //#define _CLL1_YES char *YES="TRUE\nYES\nJA\nOUI\nDA\nANO\nY\n1";
65 //#define atob(EXPR) (word_in_stri(YES,(EXPR))?1:0)
66 //#else
67 #define _CLL1_YES char *YES="TRUE";
68 #define atob(EXPR) (eqi((EXPR),YES)?1:0)
69 #endif
70 /* .----------------------------------------------------------------------.
71 / 1. C<<1 almost then buddhist section, updated 2008-01-26 xCh.
72 '----------------------------------------------------------------------- */
73 #define not !
74 #define and &&
75 #define or ||
76 #define bool int
77 #define TRUE 1
78 #define FALSE 0
79 #define WEIRDINT (1<<(sizeof(int)*8-1))
80 #define btoa(EXPR) ((EXPR)?"TRUE":"FALSE")
81 #define coalesce(VAR,EXPR) (VAR?VAR:(EXPR))
82 #define _CLL1_GLOBALS char *NIL="NULL", *EOL="\n", *OFS=" ", *IFS=" \t\n"; unsigned RANDOM_SEED=0;
83 /* .----------------------------------------------------------------------.
84 / 4. C<<1 data declaration and allocation, updated 2008-01-31 xCh.
85 '----------------------------------------------------------------------- */
86 #define mem struct
87 #define this_is(TYPE) struct *TYPE this
88 #define create_mem(ID,...) struct _ARG1(__VA_ARGS__,) *ID=get_mem(__VA_ARGS__)
89 #define new_mem(ID,...) struct _ARG1(__VA_ARGS__,) *ID=init_mem(__VA_ARGS__)
90 #define def_mem(ID,TYPE) struct TYPE *ID=NULL
91 #define def_mems(ID1,ID2,TYPE) struct TYPE *ID1=NULL, *ID2=NULL
92 #define get_mem(...) (struct _ARG1(__VA_ARGS__,)*)_cll1_malloc(sizeof(struct _ARG1(__VA_ARGS__,)), _ARG2(__VA_ARGS__,,) - 0 )
93 #define init_mem(...) _mem_##TYPE##_( _ARG2(__VA_ARGS__,,) - 0 )
94 #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))
95 #define create_list(ID1,I2,TYPE) create_mem(ID1,TYPE); struct TYPE *ID2=((ID1->__next=NULL),ID1)
96 #define create_str(ID,EXPR) char *ID=(EXPR)
97 #define new_str(ID,...) char *ID=_cll1_get_str(__VA_ARGS__,NIL)
98 #define def_str(ID) char *ID=NULL
99 #define get_str(...) _cll1_get_str(__VA_ARGS__,NIL)
100 #define create_context(ID) create_mem(ID,_CTXAtom)
101 #define def_context(ID) def_mem(ID,_CTXAtom)
102 #define list(TYPE) struct TYPE *__next
103 #define tree(TYPE) struct TYPE *__next; struct TYPE *__seek
104 #define dictionary(TYPE) struct TYPE *__next; struct TYPE *__seek; char *__key
105 #define array(TYPE) struct TYPE *__next; struct TYPE *__seek; int __key
106 #define interface(TYPE) struct TYPE *__interface
107 /* .----------------------------------------------------------------------.
108 / 5. C<<1 string manipulation, updated 2008-01-26 xCh.
109 '----------------------------------------------------------------------- */
110 #define eq(A,B) !_cll1_strcmp(A,B)
111 #define eqi(A,B) !_cll1_strcmpi(A,B)
112 #define in_str(A,B) _cll1_strstr(A,B)
113 #define word_in_str(A,B) _cll1_wordinstr(A,B,0)
114 #define print(...) _cll1_print(__VA_ARGS__,NIL)
115 #define fprint(...) _cll1_fprint(__VA_ARGS__,NIL)
116 #define file_print(...) _cll1_fprint(_F,__VA_ARGS__,NIL)
117 #define echo(...) _cll1_echo(__VA_ARGS__,NIL)
118 #define fecho(...) _cll1_fecho(__VA_ARGS__,NIL)
119 #define file_echo(...) _cll1_fecho(_F,__VA_ARGS__,NIL)
120 #define suffix(A,B,C) (((A=strrchr(B,C))&&!(*(A++)=0))||(A=B))
121 #define prefix(A,B,C) ((A=B),((B=strchr(B,C))&&!(*(B++)=0)||(B=A)))
122 #define tr(STR,B,C) _NEW(S,STR) while(S && *_S) { if(*_S==B)*_S=C; /* <-' */ _S++; }
123 /* .----------------------------------------------------------------------.
124 / 6. C<<1 data container manipulation, updated 2008-01-26 xCh.
125 '----------------------------------------------------------------------- */
126 #define push(NODE,HEAD) ( NODE ? ((NODE->__next=HEAD),(HEAD=NODE)) : NULL )
127 #define pop(NODE,HEAD) ( HEAD ? ((NODE=HEAD->__next),free(HEAD),(HEAD=NODE)) : (NODE=NULL) )
128 #define append(NODE,HEAD) { void *N=NODE; /* <-' */ NODE->__next=NULL; for_search(NODE,HEAD,!NODE->__next) { NODE->__next=N; break; } }
129 #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); }
130 #define drop(NODE,HEAD) for( NODE=HEAD; NODE || (HEAD=NULL); HEAD=NODE, NODE=NODE->__next, free(HEAD) )
131 //to do: seek
132 //to do: store
133 #define order_by(K1,K2) (K1>K2)
134 #define desc_order_by(K1,K2) (K1<K2)
135 #define sort_by(K1,K2) (_cll1_strcmpi(K1,K2)>0)
136 #define desc_sort_by(K1,K2) (_cll1_strcmpi(K1,K2)<0)
137 #define ascii_by(K1,K2) (_cll1_strcmp(K1,K2)>0)
138 #define desc_ascii_by(K1,K2) (_cll1_strcmp(K1,K2)<0)
139 #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; } }
140 #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); }
141 /* .----------------------------------------------------------------------.
142 / 7. C<<1 builtin iterators and conditionals, updated 2008-01-26 xCh.
143 '----------------------------------------------------------------------- */
144 #define loop while(TRUE)
145 #define repeat(N) if(N>0) _NEW(I,0) while(_I++<N)
146 #define for_range(VAR,FROM,TO) for( VAR=FROM ; FROM<=TO?VAR<=TO:VAR>=TO ; FROM<=TO?VAR++:VAR--)
147 #define for_each(NODE,HEAD) for(NODE=HEAD; NODE; NODE=NODE->__next)
148 #define for_search(NODE,HEAD,EXPR) for_each(NODE,HEAD) if(EXPR)
149 #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 */
150 #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 */
151 #define for_ints(VAR,...) _NEW(I,0) while( (VAR=_cll1_for_ints(_I++,__VA_ARGS__,WEIRDINT))!=WEIRDINT )
152 #define for_strs(VAR,...) _NEW(I,0) while( (VAR=(char *)_cll1_for_ptrs(_I++,__VA_ARGS__,NIL))!=NIL )
153 #define for_args _NEW(I,1) while(_I++<argc)
154 #define this_arg argv[_I]
155 #define next_arg ((_I+1<argc)?argv[_I]:NULL)
156 #define skip_next _I++
157 #define if_exists(A,B,C) for_search(A,B,C) break; if(A)
158 #define if_args if(argc>1)
159 #define switch_for_args for_args switch_str(this_arg)
160 #define switch_str(STR) _NEW(S,STR)
161 #define if_case(VAL) if(eq(argv[_I],VAL))
162 #define for_fields(FIELD,STR) for_valid_split(FIELD,STR,*OFS)
163 #define for_split_str(A,B,C) for(prefix(A,B,C);A;(A!=B)&&prefix(A,B,C)||(A=NULL))
164 #define for_valid_split(A,B,C) for_split_str(A,B,C) if(*A)
165 #define switch_for_columns(A,B,C) _FOR_COLUMNS(A,B,C) switch(__I)
166 #define switch_for_valid_columns(A,B,C) _FOR_VALID_COLUMNS(A,B,C) switch (_I)
167 #define if_column_number(A,B,C,V) _FOR_COLUMNS(A,B,C) if(_I==V)
168 #define if_valid_column_number(A,B,C,V) _FOR_VALID_COLUMNS(A,B,C) if(_I==V)
169 /* .----------------------------------------------------------------------.
170 / 8. C<<1 object oriented infrastructure, updated 2008-01-31
171 '----------------------------------------------------------------------- */
172 #define my_self(TYPE) struct *TYPE self, void *_method
173 #define we_are(TYPE) struct *TYPE _self, void *_method
174 #define anonymous void *_self, void *_method
175 #define I_am(TYPE) struct TYPE *self=(struct TYPE *)_self
176 #define def_community(METATYPE,ITYPE) struct METATYPE { struct ITYPE *__interface; };
177 #define construct_interface(MTYPE,ITYPE) struct ITYPE *_interface_##MTYPE##ITYPE(void *dummy, ...) { def_mem(_FACE,ITYPE); va_list(ap); _bind_##MTYPE##ITYPE(_FACE); return _FACE; } void _bind_##MTYPE##ITYPE(struct IFACE *_FACE)
178 #define bind_method(METHOD,FUNCTION) _FACE->METHOD=FUNCTION
179 #define new_interface(ID,MTYPE,...) struct _ARG1(__VA_ARGS__,) *ID=_interface_##MTYPE##_ARG1(__VA_ARGS__,) ((void *)__get_##TYPE##__VA_ARGS__,)
180 #define init_interface(TYPE,...)
181 #define construct_object(TYPE,...) (struct _ARG2(__VA_ARGS__,TYPE,) *)_object_##TYPE##_()
182 #define init_object(TYPE,...) (struct TYPE *)_object_##TYPE##_(__VA_ARGS__)
183 #define init_polymorph(TYPE,...) _object_##TYPE##_(__VA_ARGS__)
184 #define _(OBJECT,...) ( _ASSERT(OBJECT), (*( OBJECT->interface->_ARG1(__VA_ARGS__,) )) ( OBJECT,OBJECT->interface->__VA_ARGS__ ) )
185 #define __(OBJECT,...) ( _ASSERT(OBJECT), (*( __cll1_seekmethod(OBJECT->interface,_ARG1(__VA_ARGS__,)) )) ( OBJECT,OBJECT->interface->__VA_ARGS__ ) )
186 #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); }
187 /* .----------------------------------------------------------------------.
188 / 9. implementation of C<<1 library functions, updated 2008-01-26 xCh.
189 '----------------------------------------------------------------------- */
190 #define _MALLOC void *_cll1_malloc(size_t size,...) { /*temporary solution*/ return malloc(size); }
191 #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); }
192 #define _PRINT void _cll1_print(char *s,...) _CLL1_FPRINT(stdout)
193 #define _FPRINT void _cll1_fprint(FILE *f,char *s,...) _CLL1_FPRINT(f)
194 #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); }
195 #define _ECHO void _cll1_echo(char *s,...) _CLL1_FECHO(stdout)
196 #define _FECHO void _cll1_fecho(FILE *f,char *s,...) _CLL1_FECHO(f)
197 #define _CLL1_OUT _PRINT _FPRINT _ECHO _FECHO
198 #define _FOR_INTS int _cll1_for_ints(int i, int n, ...) { int j=0;va_list ap; /* <-' */ va_start(ap,n); while(n!=WEIRDINT && j++<i) n=va_arg(ap,int); return n; }
199 #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; }
200 #define _CLL1_ARGS _FOR_INTS _FOR_PTRS
201 #define _STRCMP int _cll1_strcmp(char *a,char *b) { if(a && b) return strcmp(a,b); else return (int)(a-b); }
202 #define _STRCMPI int _cll1_strcmpi(char *a,char *b) { if(a && b) return strcasecmp(a,b); else return (int)(a-b); }
203 #define _STRSTR char *_cll1_strstr(char *h,char *n) { if(h && n) return strstr(h,n); else return NULL; }
204 //#define _WORDINSTR char *_cll1_wordinstr(char *a,char *b,int ign) { char *IFS=a; for(;a&&*a;a++) for(;*ifs||ifs=IFS;ifs++) if(*a=b);) for return strcasestr(a,b); else return NULL; }
205 #define _CLL1_STRS _STRCMP _STRCMPI _STRSTR //_WORDINSTR
206 /* .----------------------------------------------------------------------.
207 / 10. C<<1 globals and private macros, updated 2008-01-27 by xCh.
208 '----------------------------------------------------------------------- */
209 #define _ARG1(ARG1,...) ARG1
210 #define _ARG2(ARG1,ARG2,...) ARG2
211 #define _ANYSTACK(TYPE,NAME) struct _##NAME##Atom { TYPE NAME; int C; list(_##NAME##Atom); } *_##NAME##atom,*_##NAME##stack=NULL;
212 #define _CLL1_STACKS _ANYSTACK(int,I) _ANYSTACK(char *,S) _ANYSTACK(FILE *,F) _ANYSTACK(void *,CTX)
213 #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--)
214 #define _I (_Iatom->I)
215 #define _S (_Satom->S)
216 #define _F (_Satom->F)
217 #define _CTX (_CTXatom->CTX)
218 #define _FOR_COLUMNS(A,B,C) _NEW(I,0) for( prefix(A,B,C) ; A ; ((A!=B)&&prefix(A,B,C)||(A=NULL) ),_I++ )
219 #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)
220 /* .----------------------------------------------------------------------.
221 / 11. C<<1 CGI and FASTCGI handling, updated 2008-01-16 by xCh.
222 '----------------------------------------------------------------------- */
223 #ifdef USE_LIBRARY_FASTCGI
224 #define while_fastcgi_accept while(FCGI_Accept()>=0)
225 #define USE_MODULE_CGI
226 #endif
227 #ifdef USE_MODULE_CGI
228 #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); }
229 #define _GETCGI char *getcgi(VAR) { }
230 #define _CGI_GLOBALS def_context(_CGI); struct _CGIVariable { char *V; dictionary(_CGIVariable); } *_CGIvariable,*_CGIdict;
231 #else
232 #define _GETCGI
233 #define _CGI_GLOBALS
234 #endif
235 /* .----------------------------------------------------------------------.
236 / 12. MySQL wrappers + SQL object interface, updated 2007-12-19 by xCh.
237 '----------------------------------------------------------------------- */
238 #ifdef USE_LIBRARY_MYSQL
239 #define def_sql(CONN) MYSQL *CONN
240 #define create_sql(CONN) MYSQL *ID=mysql_init(NULL)
241 #define sql_connect(CONN,S,U,P,D) mysql_real_connect(CONN,S,U,P,D,0,NULL,0)
242 //todo sql_query
243 //todo sql_queryf
244 //todo for_sql_query_results(ROW,CONN,QUERY)
245 //todo for_sql_queryf_results
246 #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)
247 #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) )
248 //todo db_query
249 //todo for_db_results
250 //todo for_db_queryf_results(ROW,...)
251 //todo db_queryf
252 #define _MYSQLC (_MYSQLCatom->MYSQLC)
253 #define _MYSQLR (_MYSQLRatom->MYSQLR)
254 #define _SQL_GLOBALS _ANYSTACK(MYSQL,MYSQLC) _ANYSTACK(MYSQL_RES,MYSQLR)
255 #else
256 #define _SQL_GLOBALS
257 #endif
258 //#ifdef USE_INTERFACE_SQL
259 //todo #define _SQL_OBJECT mem Sql { interface(SqlInterface); char *hostname; char *username; char *password; char *database; }
260 //todo #define _SQL_CONSTRUCT def_construct(Sql) { self->hostname="localhost"; }
261 //#endif
262 /* ------------------------------------------------------------------- */
263 /* old - from version 0.6 */
264 /* =================================================================== */
265 /*
266 obsolete
267 #define strlwr(A) {char *_S=A; while(_&&*_S){*_S=tolower(*_S);_S++;}}
268 #define strupr(A) {char *_S=A; while(_&&*_S){*_S=toupper(*_S);_S++;}}
269 #define string(S,L) (S=(char *)malloc(L),*S=0)
270 #define duplicate(A,B) if(A) { string(B,strlen(A)+1); strcpy(B,A); }
271 #define concatenate(A,B,C) if (A && B) { string(C,strlen(A)+strlen(B)+1); strcpy(C,A); strcat(C,B); }
272 #define gotoalpha(CHAR) if(CHAR)while(*CHAR && !isalpha(*CHAR))CHAR++
273 #define goto_alpha(CHAR) if(CHAR)while(*CHAR && !isalpha(*CHAR) && *CHAR!='_')CHAR++
274 #define gotoalnum(CHAR) if(CHAR)while(*CHAR && !isalnum(*CHAR))CHAR++
275 #define goto_alnum(CHAR) if(CHAR)while(*CHAR && !isalnum(*CHAR) && *CHAR!='_')CHAR++
276 #define skipalpha(CHAR) if(CHAR)while(*CHAR && isalpha(*CHAR))CHAR++
277 #define skip_alpha(CHAR) if(CHAR)while(*CHAR && (isalpha(*CHAR) || *CHAR=='_'))CHAR++
278 #define skipalnum(CHAR) if(CHAR)while(*CHAR && isalnum(*CHAR))CHAR++
279 #define skip_alnum(CHAR) if(CHAR)while(*CHAR && (isalnum(*CHAR) || *CHAR=='_'))CHAR++
280 #define skipspaces(CHAR) if(CHAR)while(*CHAR==' ')CHAR++
281 #define cutspaces(CHAR) if(CHAR){int _L=strlen(CHAR); while(--_L>0 && CHAR[_L]==' ')CHAR[_L]=0;}
282 #define gotochr(CHAR,C) if(CHAR)while(*CHAR && *CHAR!=C)CHAR++
283 #define strswitch(CHAR) {char *_K=CHAR; FILE *_F=NULL; {{
284 #define stroption(STR) if(eq(STR,_K))
285 #define match(KEY,VAL) {char *_K=KEY, *_V=VAL; FILE *_F=NULL; {{
286 #define assign(STR,SETVAR) stroption(STR) SETVAR=_V
287 */
288 /* I/O iterations, updated 2004-04-19 by xCh. */
289
290 //#define fparse(S,L,F) for(fgets(S,L,F);*S && !feof(F);fgets(S,L,F))
291 //#define input(S,L) fparse(S,L,stdin)
292 //#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);}
293 //#define parses(S,F) {FILE *_F=fopen(F,"r"); if(_F) { while(!feof(_F)) { fstring(S,_F);
294 //obsolete
295 //#define parse(F) {char *_; FILE *_F=fopen(F,"r"); if(_F) { while(!feof(_F)) { fstring(_,_F);
296 //#define fail }} else {{
297 //#define done }} if(_F)fclose(_F);}
298 //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);}
299 //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);}
300 //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);}
301
302 /* I/O sequences, updated 2003-05-29 by xCh. */
303
304 #define nullreopen(F) F=freopen("/dev/null","r",F)
305 #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]);}
306 #define shell(CMD) stdinredir(system(CMD))
307 #define paste(STR) stdinredir(fputs(STR,stdout))
308
309 /* Useful structures, updated 2003-05-29 by xCh. */
310
311 //#define date(S) { time_t _T; _T=time(NULL); duplicate(ctime(&_T),S); }
312 /* ------------------------------------------------------------------- */
313 /* some general ideas, unfinished */
314 //bind_exception, unbind_exception
315 //#define _CLL1_THROW(ERR)
316 //#define _CLL1_TRY _NEW_E for(bind_exception(0,NULL);;) if () {.... if(_Eatom->SYS) { if(_Eatom->RET) return; else break;} else { }
317 //#define _ASSERT(EXPR) assert(EXPR)
318 /* =================================================================== */
319
320 /* .----------------------------------------------------------------------.
321 / 99. We have have done our homework - now let's have some fun:
322 '----------------------------------------------------------------------- */
323 #define _DEF_VARIABLES _CLL1_GLOBALS _CLL1_YES _CLL1_STACKS _SQL_GLOBALS _CGI_GLOBALS
324 #define _DEF_FUNCTIONS _MALLOC _CLL1_OUT _CLL1_ARGS _CLL1_STRS // _GET_MEM
325 #define _DEF_INTERFACE //_SQL_IFC _CAKE_IFC _STD_IFC _X_IFC
326 #define _IMPLEMENT_CLL1_LIBRARY _DEF_VARIABLES _DEF_FUNCTIONS _DEF_INTERFACE
327 #ifdef USE_PREPROCESSOR
328 #include "_include.c"
329 #endif
330 #define program _IMPLEMENT_CLL1_LIBRARY int main(int argc, char **argv)
331 /* #ifndef _CLL1_H */
332 #endif
This page took 0.619732 seconds and 5 git commands to generate.