From 1559881634f6d07fe21c77ad60ecb845f1ae86f2 Mon Sep 17 00:00:00 2001 From: xchaos Date: Tue, 19 Apr 2011 12:18:37 +0000 Subject: [PATCH] initial crl1h commit git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@132 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- crl1.h | 422 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 422 insertions(+) create mode 100644 crl1.h diff --git a/crl1.h b/crl1.h new file mode 100644 index 0000000..9931b28 --- /dev/null +++ b/crl1.h @@ -0,0 +1,422 @@ + /* .----------------------------------------------------------------------. + / C<<1 header file - C language style sheet - GNU C/ANSI C99 compliant +'----------------------------------------------------------------------- */ +/* + Copyright (c) 2004-2011 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 + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The C<<1 header file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with C<<1 header file; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#ifndef _CRL1_H +#define _CRL1_H +#define _CRL1H_VERSION "0.9.1" +#ifdef __GNUC__ +#if __STDC_VERSION__ >= 199901L +#define _C99 +#endif +#endif +/* .----------------------------------------------------------------------. + / 0. Library definitions not parsed by @CC, updated 2008-01-26 xCh. + '---------------------------------------------------------------------- */ +/* +@define USE_LIBRARY_MYSQL -lmysqlclient +@define USE_LIBRARY_FASTCGI -lfcgi +@define USE_TOOL cake *.html *.xml > _include.c +@define USE_TOOL strip @ +*/ +/* .----------------------------------------------------------------------. + / 1. C<<1 header auto include, updated 2008-01-26 xCh. + '---------------------------------------------------------------------- */ +#ifndef DISABLE_MODULE_AUTOINCLUDE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef USE_FASTCGI +#include +#else +#include +#endif +#endif +#ifdef USE_MYSQL +#include +#endif +/* .----------------------------------------------------------------------. + / 2. C<<1 typedefs and public global variables, updated 2008-02-03 xCh. + '----------------------------------------------------------------------- */ +typedef void * any; +typedef unsigned char * buf; /* this will be always 8-bit usigned char * */ +typedef FILE * file; +typedef int bool; +typedef char * str; +#ifdef USE_MYSQL +typedef MYSQL_ROW row; +#endif +extern str NIL, EOL, OFS, IFS, LANG, errstr; /* used for: perror(errstr) */ +extern unsigned RANDOM_SEED; +#define _EXPORT_GLOBALS \ +str NIL="(null)", EOL="\n", OFS=" ", IFS=" \t\n", LANG=NULL; \ +str ERR="C<<1 0xdead"; \ +unsigned RANDOM_SEED=0; +/* .----------------------------------------------------------------------. + / 3. C<<1 then buddhist section, updated 2008-02-04 xCh. + '----------------------------------------------------------------------- */ +#ifndef DISABLE_MODULE_THEN_BUDDHISM +#define then +#define MAYBE (int)((long)(RANDOM_SEED?random():((RANDOM_SEED=(unsigned)time(NULL)),srandom(RANDOM_SEED),random()))%2) +#define WHOKNOWS (int)(srandom((unsigned)time(NULL)),random()%2) +#define for_samsara(MIND,SOUL) loop for_each(MIND,SOUL) +//#define atob(EXPR) (word_in_stri(YES,(EXPR))?1:0) +//#define _EXPORT_YES str YES="TRUE\nYES\nJA\nOUI\nDA\nANO\nY\n1"; +//#else +#define atob(EXPR) (eqi((EXPR),YES)?TRUE:FALSE) +#define _EXPORT_YES str YES="TRUE"; +#endif +/* .----------------------------------------------------------------------. + / 4. C<<1 almost 'then buddhist' section, updated 2008-02-02 xCh. + '----------------------------------------------------------------------- */ +#define not ! +#define and && +#define or || +#define TRUE 1 +#define FALSE 0 +#define PI 3.141592654 +#define WEIRDINT (1<<(sizeof(int)*8-1)) +#define btoa(EXPR) ((EXPR)?YES:"FALSE") +/* .----------------------------------------------------------------------. + / 5. C<<1 data declaration and allocation, updated 2008-01-31 xCh. + '----------------------------------------------------------------------- */ +#define def_type(TYPE) typedef struct _##TYPE##_struct * TYPE +#define def_mem(TYPE) def_type(TYPE); struct _##TYPE##_struct +#define get_mem(TYPE) _GET_MEM(TYPE) +#define get_array(TYPE,N) (TYPE *)calloc(N,sizeof(TYPE)) /* temporary solution */ +#define get_buf(SIZE) (buf)malloc(SIZE) /* temporary solution */ +//#define size_of_mem(TYPE) sizeof(struct _##TYPE##_struct) +//#define copy_of_mem(TYPE,SRC) _crl1_mem_cpy(sizeof(struct _##TYPE##_struct),SRC) +#define list(TYPE) TYPE __next +#define tree(TYPE) TYPE __next; TYPE __seek +#define dict(TYPE) tree(TYPE); str __key +/* .----------------------------------------------------------------------. + / 5. C<<1 string manipulation, updated 2008-01-26 xCh. + '----------------------------------------------------------------------- */ +#define get_str(...) _crl1_get_str(__VA_ARGS__,NIL) +#define get_strs(...) _crl1_get_strs(__VA_ARGS__,NIL) +#define eq(A,B) (!_crl1_str_cmp(A,B)) +#define eqi(A,B) (!_crl1_str_cmpi(A,B)) +#define str_order(A,B) _crl1_str_coll(A,B) +#define str_ascii(A,B) _crl1_str_cmp(A,B) +#define chars_in_str(...) _crl1_strlen(__VA_ARGS__,NIL) +#define size_of_str(A) mbstowcs(NULL,A,0) +#define str_in(A,B) _crl1_str_str(A,B) +#define word_in(A,B) _crl1_wordinstr(A,B,0) +#define print(...) _crl1_print(__VA_ARGS__,NIL) +#define fprint(...) _crl1_fprint(__VA_ARGS__,NIL) +#define file_print(...) _crl1_fprint(_F,__VA_ARGS__,NIL) +#define echo(...) _crl1_echo(__VA_ARGS__,NIL) +#define fecho(...) _crl1_fecho(__VA_ARGS__,NIL) +#define file_echo(...) _crl1_fecho(_F,__VA_ARGS__,NIL) +#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 tr(STR,B,C) _NEW(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->__next=HEAD),(HEAD=NODE)) : NULL ) +#define pop(NODE,HEAD) ( HEAD ? ((NODE=HEAD->__next),free(HEAD),(HEAD=NODE)) : (NODE=NULL) ) +#define append(NODE,HEAD) { void *_PTR=NODE; if(NODE) NODE->__next=NULL; if(HEAD) { for_selected(NODE,HEAD,!NODE->__next) { NODE->__next=_PTR; break; } } else HEAD=NODE; } +#define remove(NODE,HEAD,EXPR) { void **_D=NULL; /* <-' */ for_selected(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 +#define count(NODE,HEAD,VAR) { _NEW(I,0) for(NODE=HEAD; NODE || ((VAR=_I),0) ; (NODE=NODE->__next)?(_I++):0 ); } +#define order_by_num(K1,K2) (K1>K2) +#define order_by_num_desc(K1,K2) (K10) +#define order_by_str_desc(K1,K2) (str_order(K1,K2)<0) +#define order_by_ascii(K1,K2) (str_ascii(K1,K2)>0) +#define order_by_ascii_desc(K1,K2) (str_ascii(K1,K2)<0) +#define insert(NODE,HEAD,ORDERBY,KEY) { if(HEAD) { void **_L=NULL, *H=HEAD; /* <-' */ for_selected(HEAD,H,ORDERBY(HEAD->KEY,NODE->KEY)) { 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,ORDERBY,KEY) { void *_NEXT; /* <-' */ NODE=HEAD; HEAD=NULL; do { _NEXT=NODE->__next; NODE->__next=NULL; insert(NODE,HEAD,ORDERBY,KEY); NODE=_NEXT; } while(_NEXT); } +/* .----------------------------------------------------------------------. + / 7. C<<1 builtin iterators and conditionals, updated 2008-01-26 xCh. + '----------------------------------------------------------------------- */ +#define loop while(TRUE) +#define repeat(N) for(int _i=0,_j=(N); _i++<_j;) +#define for_each(ONE_T,ONE,ALL_T,...) for(_init_##ONE_T##_##ALL_T(_head_##ONE_T##_##ALL_T(ONE,__VA_ARGS__));_test_##ONE_T##_##ALL_T(ONE,__VA_ARGS__) || _free_##ONE_T##_##ALL_T(ONE,__VA_ARGS__);_next_##ONE_T##_##ALL_T(ONE,__VA_ARGS__)) +#define count(ONE_T,ALL_T,...) _count_##ONE_T##_##ALL_T(__VA_ARGS__) + + + +/* .----------------------------------------------------------------------. + / 8. C<<1 object oriented infrastructure, updated 2008-02-04 + '----------------------------------------------------------------------- */ +#define def_interface(TYPE,INTERFACE) def_type(TYPE); def_mem(INTERFACE) +#define def_obj(TYPE) struct _##TYPE##_struct +#define interface(TYPE) TYPE __interface +#define interface_of(SELF) SELF->__interface +#define method(NAME) (*NAME) +#define construct(TYPE,INTERFACE) TYPE _init_##TYPE(TYPE o,INTERFACE i) { o->__interface=i; return o; } TYPE __init__##TYPE +#define get_obj(TYPE,INTERFACE,...) __init__##TYPE(_init_##TYPE(get_mem(TYPE),INTERFACE),__VA_ARGS__) +#define get_obj_as(COMMUNITY,MEM,INTERFACE,...) (COMMUNITY)get_obj(MEM,INTERFACE,__VA_ARGS__) +#define _(METHOD,...) ((((_ARG1(__VA_ARGS__,)) || /* will not compile if object is not lvalue: */(_ARG1(__VA_ARGS__,)=NULL)) && (_ARG1(__VA_ARGS__,))->__interface->METHOD)?(*( (_ARG1(__VA_ARGS__,))->__interface->METHOD )) ((void *)__VA_ARGS__):0) +//#define __(METHOD,...) ( _ASSERT(ARG1(__VA_ARGS__,)), (*( __crl1_seekmethod(ARG1(__VA_ARGS__,),METHOD) )) ( __VA_ARGS__ ) ) +#define call(OBJTYPE,METHOD,...) { int _N=0; OBJTYPE _OBJ; /* <-' */ while( (_OBJ=(OBJTYPE)_crl1_for_ptrs(_N++,__VA_ARGS__,NIL))!=(OBJTYPE)NIL ) _(_OBJ,METHOD); } +#define def_community(TYPE,INTERFACE) def_obj(TYPE) { INTERFACE __interface; }; +/* ---- variable declarators -------------------------------------------- */ +#define Get_obj(ID,MEM,...) MEM ID=get_obj(MEM,__VA_ARGS__) +#define Get_obj_as(ID,COMMUNITY,MEM,...) MEM ID=get_obj_as(COMMUNITY,MEM,INTERFACE,__VA_ARGS__) +#define I_am(SELF,MEM) MEM SELF=(MEM)community +/* .----------------------------------------------------------------------. + / 9. C<<1 setjmp()/longjmp() based exceptions, updated 2008-09-30 + '----------------------------------------------------------------------- */ +#define FAILED_TO_FAIL -273 +#define SYSTEM_FAILURE -1 +#define LOCAL_FAILURE 13 +#define LIBRARY_FAILURE 23 +#define EVIL_FAILURE 666 +#define die(MSG) longjmp(_EENV,(errstr=(MSG),LOCAL_FAILURE)) +#define try _NEW(E,0) if(!(_E=setjmp(_EENV))) +#define fail(E) longjmp(_EENV,((E)>0?(E):FAILED_TO_FAIL)) +#define pass_failure (_Eatom->__next?longjmp((pop(_Eatom,_Estack),_EENV),_E):_SYSFAIL(FAILED_TO_FAIL)) +#define else_switch_failures else switch(_E) +#define else_catch(E) else if (_E==(E)) +/* .----------------------------------------------------------------------. + / 10. implementation of C<<1 library functions, updated 2008-01-26 xCh. + '----------------------------------------------------------------------- */ +/* later... #define _MALLOC void *_crl1_malloc(size_t size) { return malloc(size); } */ +#define _CRL1_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); } +#define _DECLARE_PRINT void _crl1_print(const char *s,...) +#define _PRINT _DECLARE_PRINT _CRL1_FPRINT(stdout) +#define _DECLARE_FPRINT void _crl1_fprint(FILE *f,const char *s,...) +#define _FPRINT _DECLARE_FPRINT _CRL1_FPRINT(f) +#define _CRL1_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); } +#define _ECHO void _crl1_echo(char *s,...) _CRL1_FECHO(stdout) +#define _FECHO void _crl1_fecho(FILE *f,char *s,...) _CRL1_FECHO(f) +#define _FOR_INTS int _crl1_for_ints(int i, int n, ...) { int j=0;va_list ap; /* <-' */ va_start(ap,n); while(n!=WEIRDINT && j++I) +#define _J (_Iatom->J) +#define _S (_Satom->S) +#define _F (_Fatom->F) +#define _CTX (_CTXatom->CTX) +#define _E (_Eatom->E) +#define _EENV (_Eatom->ENV) +#define _ERRNO (_Eatom->ERRNO) +#define _ARG1(ARG1,...) ARG1 +//#define _ASSERT(EXPR) (expr?expr:fail(CONSISTENCY_FAILURE)) +#define _SYSFAIL(E) longjmp(_EENV,(_ERRNO=errno,(E))) +#define _GET_MEM(TYPE) ((TYPE)malloc(sizeof(struct _##TYPE##_struct))) /* later... ((TYPE)_crl1_malloc(sizeof(struct _##TYPE##_struct))) */ +#define _ANYATOM(NAME,DECL) def_mem(_##NAME##Atom ) { DECL; int c; list( _##NAME##Atom ); } +//#define _FOR_COLUMNS(A,B,C) _NEW(I,0) for( prefix(A,B,C) ; A ; ((A!=B)&&prefix(A,B,C)||(A=NULL) ),_I++ ) +//#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) +#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--) +#define _ANYSTACK(NAME) extern _##NAME##Atom _##NAME##atom, _##NAME##stack; _##NAME##Atom _##NAME##atom,_##NAME##stack=NULL; +#define _EXPORT_STACKS _ANYSTACK(I) _ANYSTACK(S) _ANYSTACK(F) _ANYSTACK(CTX) _ANYSTACK(E) +_ANYATOM(I, int I;int J); +_ANYATOM(S, str S); +_ANYATOM(F, file F); +_ANYATOM(CTX, void *CTX); +_ANYATOM(E, int E;jmp_buf ENV;int ERRNO); +/* .----------------------------------------------------------------------. + / 11. C<<1 memory contexts - alternative to garbage collection + '----------------------------------------------------------------------- */ +typedef _CTXAtom * context; +#define create_context(ID) create_mem(ID,context) +/* .----------------------------------------------------------------------. + / 12. C<<1 CGI and FASTCGI handling, updated 2008-01-16 by xCh. + '----------------------------------------------------------------------- */ +#ifdef USE_LIBRARY_FASTCGI +#define while_fastcgi_accept while(FCGI_Accept()>=0) +#define USE_MODULE_CGI +#endif +#ifdef USE_MODULE_CGI +#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); } +#define _GETCGI char *getcgi(VAR) { } +#define _CGI_GLOBALS def_context(_CGI); struct _CGIVariable { char *V; dict(_CGIVariable); } *_CGIvariable,*_CGIdict; +#else +#define _GETCGI +#define _CGI_GLOBALS +#endif +/* .----------------------------------------------------------------------. + / 13. MySQL wrappers + SQL object interface, updated 2007-12-19 by xCh. + '----------------------------------------------------------------------- */ +#define use_mysql(H,U,P,D) for(MYSQL *_M=mysql_init(NULL);_M && mysql_real_connect(_M,H,U,P,D,0,NULL,0) ;mysql_close(_M),_M=NULL) +#define for_sql_rows(R,Q) for(MYSQL_RES *_MYSQLR = (mysql_query(_M,Q)?NULL:mysql_use_result(_M)); (R=(_MYSQLR?mysql_fetch_row(_MYSQLR):NULL)) || (mysql_free_result(_MYSQLR),0); ) +/* .----------------------------------------------------------------------. + / 14. Obj community with Object interface , updated 2009-01-05 by xCh. + '----------------------------------------------------------------------- */ +#ifdef USE_MODULE_OBJECTS +def_interface(Obj,Object) +{ + void method(out) (Obj self); + void method(len) (Obj self); + void method(head) (Obj self); + void method(next) (Obj self); +}; + +def_community(Obj,Object); + +def_mem(Int) +{ + interface(Object); + long _value; +}; + +def_mem(Str) +{ + interface(Object); + str _value; +}; + +def_mem(Array) +{ + interface(Object); + Obj * _value; +}; + +def_mem(List) +{ + interface(Object); + Obj _value; +}; + +#endif +/* ------------------------------------------------------------------- */ +/* old - from version 0.6 */ +/* =================================================================== */ +/* +obsolete +#define strlwr(A) {char *_S=A; while(_&&*_S){*_S=tolower(*_S);_S++;}} +#define strupr(A) {char *_S=A; while(_&&*_S){*_S=toupper(*_S);_S++;}} +#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 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 goto_alnum(CHAR) if(CHAR)while(*CHAR && !isalnum(*CHAR) && *CHAR!='_')CHAR++ +#define skipalpha(CHAR) if(CHAR)while(*CHAR && isalpha(*CHAR))CHAR++ +#define skip_alpha(CHAR) if(CHAR)while(*CHAR && (isalpha(*CHAR) || *CHAR=='_'))CHAR++ +#define skipalnum(CHAR) if(CHAR)while(*CHAR && isalnum(*CHAR))CHAR++ +#define skip_alnum(CHAR) if(CHAR)while(*CHAR && (isalnum(*CHAR) || *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 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 assign(STR,SETVAR) stroption(STR) SETVAR=_V +*/ +/* I/O iterations, updated 2004-04-19 by xCh. */ + +//#define fparse(S,L,F) for(fgets(S,L,F);*S && !feof(F);fgets(S,L,F)) +//#define input(S,L) fparse(S,L,stdin) +//#define fstring(S,F) { int _C=0,_L=0; fpos_t _P; fgetpos(F,&_P); while(_C!='\n' && !feof(F)){ _C=fgetc(F); _L++; } S=get_buf(L); fsetpos(F,&_P);fgets(S,_L,F);fgetc(F);} +//#define parses(S,F) {FILE *_F=fopen(F,"r"); if(_F) { while(!feof(_F)) { fstring(S,_F); +//obsolete +//#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);} +//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);} + +/* I/O sequences, updated 2003-05-29 by xCh. */ + +#define nullreopen(F) F=freopen("/dev/null","r",F) +#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]);} +#define shell(CMD) stdinredir(system(CMD)) +#define paste(STR) stdinredir(fputs(STR,stdout)) + +/* Useful structures, updated 2003-05-29 by xCh. */ + +//#define date(S) { time_t _T; _T=time(NULL); duplicate(ctime(&_T),S); } + +/* some general ideas, unfinished */ +//bind_exception, unbind_exception +//#define _CRL1_THROW(ERR) +//#define _CRL1_TRY _NEW_E for(bind_exception(0,NULL);;) if () {.... if(_Eatom->SYS) { if(_Eatom->RET) return; else break;} else { } + +/* .----------------------------------------------------------------------. + / 98. We have have done our homework - now let's have some fun: + '----------------------------------------------------------------------- */ +#define _INIT_VARIABLES _EXPORT_GLOBALS _EXPORT_YES _EXPORT_STACKS _CGI_GLOBALS +#define _IMPL_FUNCTIONS /*_MALLOC*/ _EXPORT_OUTS _EXPORT_ARGS _EXPORT_STRS +//#define _IMPL_INTERFACE //_SQL_IFC _CAKE_IFC _STD_IFC _X_IFC +#define _IMPLEMENT_CRL1_LIBRARY _INIT_VARIABLES _IMPL_FUNCTIONS //_IMPL_INTERFACE +//this will be probably accomplished some other way... +#ifndef DISABLE_LIBRARY_CRL1 +_IMPLEMENT_CRL1_LIBRARY +#endif +#ifdef DISABLE_LOCALES +#define _SETLOCALE LANG="C" +#else +#define _SETLOCALE LANG=setlocale(LC_ALL, "") +#endif +#define _DECLARE_PROGRAM void _PROGRAM(int argc, char **argv) +#define _PROGRAM _crl1_program +#define program \ +_DECLARE_PROGRAM; \ +int main(int argc, char **argv) \ +{ \ + _SETLOCALE; \ + try \ + { \ + _PROGRAM(argc,argv); \ + return 0; \ + } \ + else_switch_failures \ + { \ + case SYSTEM_FAILURE: \ + errno=_ERRNO; \ + perror(errstr); /* and return -1 */ \ + default: \ + return -1; \ + } \ +} \ +_DECLARE_PROGRAM +#ifdef USE_PREPROCESSOR +#include "_include.c" +#endif +/* .----------------------------------------------------------------------. + / 99. C<<1 is up and running. It's your turn now to show something new. + '----------------------------------------------------------------------- */ +#endif -- 2.30.2