-C<<1 header file v - style sheet for ANSI C
+C<<1 header file v 0.9 - JQuery-style library for ANSI C99
-Copyright (c)2004-2008 Michael xChaos Polak, Arachne Labs, x(at)n.cz
+Copyright (c)2004-2011 Michael xChaos Polak, Arachne Labs, x(at)n.cz
See https://dev.arachne.cz/svn/cll1.h for details, documentation and FAQ
-(or https://orion.stresovice.czf/svn/cll1h when inside CZFree.Net).
See http://www.arachne.cz/ for Arachne Labs contact and product information.
+++ /dev/null
- /* .---------------------------------------------------------------------.
- / C<<1 header file - C language style sheet - GNU C/ANSI C99 compliant
- / Cumbersome Extraction and Report Language - http://cll1h.arachne.cz/
-'---------------------------------------------------------------------- */
-/*
- 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
- 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 _CLL1_H
-#define _CLL1_H
-#define CLL1H_VERSION "0.7.1"
-/* .----------------------------------------------------------------------.
- / 0. Library definitions not parsed by @CC, updated 2008-01-26 xCh.
- '---------------------------------------------------------------------- */
-/*
-@define USE_LIBRARY_MYSQL -lmysqlclient
-@define USE_LIBRARY_FASTCGI -lfcgi
-@define USE_PREPROCESSOR cake *.html *.xml > _include.c
-@define USE_POSTPROCESSOR strip @
-*/
-/* .----------------------------------------------------------------------.
- / 1. C<<1 header auto include, updated 2008-01-26 xCh.
- '---------------------------------------------------------------------- */
-#ifndef DISABLE_MODULE_AUTOINCLUDE
-#include <string.h>
-#include <strings.h>
-#include <malloc.h>
-#include <time.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <unistd.h>
-#include <setjmp.h>
-#include <errno.h>
-#include <locale.h>
-#ifdef USE_LIBRARY_FASTCGI
-#include <fcgi_stdio.h>
-#else
-#include <stdio.h>
-#endif
-#endif
-#ifdef USE_LIBRARY_MYSQL
-#include <mysql/mysql.h>
-#endif
-/* .----------------------------------------------------------------------.
- / 0. 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;
-#ifdef USE_WCHAR_T
-typedef wchar_t * str;
-#else
-typedef char * str; /* Warning: full wchar_t support not yet implemented! */
-#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 errstr="C<<1 0xdead"; \
-unsigned RANDOM_SEED=0;
-/* .----------------------------------------------------------------------.
- / 1. 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) for(MIND=SOUL; MIND || ((MIND->__next=SOUL),0) ; MIND=MIND->__next)
-#define samsara(MIND,SOUL) for(MIND=SOUL; MIND || ((MIND->__next=SOUL),0) ; MIND=MIND->__next)
-//#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
-/* .----------------------------------------------------------------------.
- / 2. 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)?"TRUE":"FALSE")
-#define coalesce(VAR,EXPR) (VAR?VAR:(VAR=0,(EXPR)))
-#define coalesce_str(VAR,EXPR) (VAR && *VAR?VAR:((VAR=NULL),(EXPR)))
-/* .----------------------------------------------------------------------.
- / 4. 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_buf(SIZE) (buf)malloc(SIZE) /* temporary solution */
-#define size_of_mem(TYPE) sizeof(struct _##TYPE##_struct)
-#define copy_of_mem(TYPE,SRC) _cll1_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
-#define array(TYPE) tree(TYPE); int __key
-/* ---- variable declarators -------------------------------------------- */
-#define Get_mem(ID,TYPE) TYPE ID=get_mem(TYPE)
-#define Get_buf(ID,SIZE) buf ID=get_buf(SIZE)
-/* .----------------------------------------------------------------------.
- / 5. C<<1 string manipulation, updated 2008-01-26 xCh.
- '----------------------------------------------------------------------- */
-#define get_str(...) _cll1_get_str(__VA_ARGS__,NIL)
-#define eq(A,B) (!_cll1_str_cmp(A,B))
-#define eqi(A,B) (!_cll1_str_cmpi(A,B))
-#define str_order(A,B) _cll1_str_coll(A,B)
-#define str_ascii(A,B) _cll1_str_cmp(A,B)
-#define chars_in_str(...) _cll1_strlen(__VA_ARGS__,NIL)
-#define size_of_str(A) mbstowcs(NULL,A,0)
-#define str_in(A,B) _cll1_str_str(A,B)
-#define word_in(A,B) _cll1_wordinstr(A,B,0)
-#define print(...) _cll1_print(__VA_ARGS__,NIL)
-#define fprint(...) _cll1_fprint(__VA_ARGS__,NIL)
-#define file_print(...) _cll1_fprint(_F,__VA_ARGS__,NIL)
-#define echo(...) _cll1_echo(__VA_ARGS__,NIL)
-#define fecho(...) _cll1_fecho(__VA_ARGS__,NIL)
-#define file_echo(...) _cll1_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++; }
-/* ---- variable declarators -------------------------------------------- */
-#define Get_str(ID,...) str ID=get_str(__VA_ARGS__)
-/* .----------------------------------------------------------------------.
- / 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_search(NODE,HEAD,!NODE->__next) { NODE->__next=_PTR; break; } } else HEAD=NODE; }
-#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); }
-#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) (K1<K2)
-#define order_by_str(K1,K2) (str_order(K1,K2)>0)
-#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_search(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) _NEW(I,(_J=(N),0)) while(_I++<_J) /* C99 version would be: for(int _i=0,_j=(N);_i++<_j;) */
-#define for_range(VAR,FROM,TO) _NEW(I,((_J=(TO)),FROM)) for( VAR=_I ; _I<=_J?VAR<=_J:VAR>=_J ; _I<=_J?VAR++:VAR--)
-#define for_each(NODE,HEAD) for(NODE=HEAD; NODE; NODE=NODE->__next)
-#define for_search(NODE,HEAD,EXPR) for_each(NODE,HEAD) if(EXPR)
-#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 */
-#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 */
-#define for_ints(VAR,...) _NEW(I,0) while( (VAR=_cll1_for_ints(_I++,__VA_ARGS__,WEIRDINT))!=WEIRDINT )
-#define for_strs(VAR,...) _NEW(I,0) while( (VAR=(char *)_cll1_for_ptrs(_I++,__VA_ARGS__,NIL))!=NIL )
-#define for_args(STR) _NEW(I,1) while(_I++<argc)
-#define this_arg argv[_I]
-#define next_arg ((_I+1<argc)?argv[_I]:NULL)
-#define continue_args _I++
-#define if_exists(NODE,HEAD,EXPR) for_search(NODE,HEAD,EXPR) break; if(NODE)
-#define if_args if(argc>1)
-#define switch_for_args for_args with_str(this_arg)
-#define with_str(STR) _NEW(S,STR)
-#define if_case(VAL) if(eq(_S,VAL))
-#define for_fields(FIELD,STR) for_valid_split(FIELD,STR,*OFS)
-#define for_split_str(A,B,C) for(prefix(A,B,C);A;(A!=B)&&prefix(A,B,C)||(A=NULL))
-#define for_valid_split(A,B,C) for_split_str(A,B,C) if(*A)
-#define switch_for_columns(A,B,C) _FOR_COLUMNS(A,B,C) switch(__I)
-#define switch_for_valid_columns(A,B,C) _FOR_VALID_COLUMNS(A,B,C) switch (_I)
-#define if_column_number(A,B,C,V) _FOR_COLUMNS(A,B,C) if(_I==V)
-#define if_valid_column_number(A,B,C,V) _FOR_VALID_COLUMNS(A,B,C) if(_I==V)
-/* .----------------------------------------------------------------------.
- / 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__,)), (*( __cll1_seekmethod(ARG1(__VA_ARGS__,),METHOD) )) ( __VA_ARGS__ ) )
-#define call(OBJTYPE,METHOD,...) { int _N=0; OBJTYPE _OBJ; /* <-' */ while( (_OBJ=(OBJTYPE)_cll1_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 *_cll1_malloc(size_t size) { return malloc(size); } */
-#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); }
-#define _DECLARE_PRINT void _cll1_print(const char *s,...)
-#define _PRINT _DECLARE_PRINT _CLL1_FPRINT(stdout)
-#define _DECLARE_FPRINT void _cll1_fprint(FILE *f,const char *s,...)
-#define _FPRINT _DECLARE_FPRINT _CLL1_FPRINT(f)
-#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); }
-#define _ECHO void _cll1_echo(char *s,...) _CLL1_FECHO(stdout)
-#define _FECHO void _cll1_fecho(FILE *f,char *s,...) _CLL1_FECHO(f)
-#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; }
-#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; }
-#define _DECLARE_STRCOLL int _cll1_str_coll(str a, str b)
-#define _STRCOLL _DECLARE_STRCOLL { if(a && b) return strcoll(a,b); else return (int)(a-b); }
-#define _DECLARE_STRCMP int _cll1_str_cmp(str a, str b)
-#define _STRCMP _DECLARE_STRCMP { if(a && b) return strcmp(a,b); else return (int)(a-b); }
-#define _DECLARE_STRCMPI int _cll1_str_cmpi(str a, str b)
-#define _STRCMPI _DECLARE_STRCMPI { if(a && b) return strcasecmp(a,b); else return (int)(a-b); }
-#define _DECLARE_STRSTR str _cll1_str_str(str h, str n)
-#define _STRSTR _DECLARE_STRSTR { if(h && n) return strstr(h,n); else return NULL; }
-// later... #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; }
-extern _DECLARE_PRINT;
-extern _DECLARE_FPRINT;
-extern _DECLARE_STRCOLL;
-extern _DECLARE_STRCMP;
-extern _DECLARE_STRCMPI;
-extern _DECLARE_STRSTR;
-#define _EXPORT_OUTS _PRINT _FPRINT _ECHO _FECHO
-#define _EXPORT_STRS _STRCOLL _STRCMP _STRCMPI _STRSTR //_WORDINSTR
-#define _EXPORT_ARGS _FOR_INTS _FOR_PTRS
-/* .----------------------------------------------------------------------.
- / 10. C<<1 private infrastructure, updated 2008-02-03 by xCh.
- '----------------------------------------------------------------------- */
-#define _I (_Iatom->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)_cll1_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.
- '----------------------------------------------------------------------- */
-#ifdef USE_LIBRARY_MYSQL
-#define def_sql(CONN) MYSQL *CONN
-#define create_sql(CONN) MYSQL *ID=mysql_init(NULL)
-#define sql_connect(CONN,S,U,P,D) mysql_real_connect(CONN,S,U,P,D,0,NULL,0)
-//todo sql_query
-//todo sql_queryf
-//todo for_sql_query_results(ROW,CONN,QUERY)
-//todo for_sql_queryf_results
-#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)
-#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) )
-//todo db_query
-//todo for_db_results
-//todo for_db_queryf_results(ROW,...)
-//todo db_queryf
-#define _MYSQLC (_MYSQLCatom->MYSQLC)
-#define _MYSQLR (_MYSQLRatom->MYSQLR)
-#define _SQL_GLOBALS _ANYSTACK(MYSQL,MYSQLC) _ANYSTACK(MYSQL_RES,MYSQLR)
-#else
-#define _SQL_GLOBALS
-#endif
-//#ifdef USE_INTERFACE_SQL
-//todo #define _SQL_OBJECT mem Sql { interface(SqlInterface); char *hostname; char *username; char *password; char *database; }
-//todo #define _SQL_CONSTRUCT def_construct(Sql) { self->hostname="localhost"; }
-//#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++; } string(S,_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 _CLL1_THROW(ERR)
-//#define _CLL1_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 _SQL_GLOBALS _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_CLL1_LIBRARY _INIT_VARIABLES _IMPL_FUNCTIONS _IMPL_INTERFACE
-//this will be probably accomplished some other way...
-#ifndef DISABLE_LIBRARY_CLL1
-_IMPLEMENT_CLL1_LIBRARY
-#endif
-#ifdef USE_LC_ALL
-#define _UNSET_LC_NUMERIC setlocale(LC_NUMERIC, "C"); /* LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, LC_TIME */
-#else
-#define _UNSET_LC_NUMERIC
-#endif
-#define _DECLARE_PROGRAM void _PROGRAM(int argc, char **argv)
-#define _PROGRAM _cll1_program
-#define program \
-_DECLARE_PROGRAM; \
-int main(int argc, char **argv) \
-{ \
- LANG=setlocale(LC_ALL, ""); \
- _UNSET_LC_NUMERIC \
- 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
+++ /dev/null
-#include "cll1.h"
-
-program
-{
- print("* echo()");
- echo("Hello"," ","world"," !\n");
- print("* print()");
- print("Hello","world","!");
- print("* NIL");
- print("We can print", NULL, "safely.");
- NIL="(hic sunt crocodiles)";
- print("We can print", NULL, "safely.");
-
- {
- str p = "print", a = NULL;
- print("* coalesce():");
- print("We can", coalesce(p, "everything"), "almost", coalesce(a, "anything"), "safely.");
- }
-
- echo("Surprisingly ->",NIL," (you can't see this)");
- print("<- nothing special here.");
- print("* OFS");
- OFS="";
- EOL="";
- print("We","Can","Print","Without","Spaces","BetweenArgs.");
- OFS=":";
- print("We","can","customize","print.");
- OFS="...";
- EOL="<--\n";
- print("");
- print("* MAYBE ?");
- repeat(4) print((MAYBE ? "Hello" : "Hi"), (MAYBE ? "world" : "friend"), (MAYBE ? "!" : "?"));
- print("* WHOKNOWS ?");
- repeat(4) print((WHOKNOWS ? "Hello" : "Hi"), (WHOKNOWS ? "world" : "friend"), (WHOKNOWS ? "!" : "?"));
-}
+++ /dev/null
-#include <stdio.h>\r
-#include <stdlib.h>\r
-\r
-\r
-struct Node \r
-{\r
- float f;\r
- struct Node* next;\r
-};\r
-\r
-void IterateList (struct Node* HeadList);\r
-struct Node* makelist(struct Node** Head, struct Node** Tail);\r
-\r
-struct Node* makelist(struct Node** Head, struct Node** Tail)\r
-{\r
- struct Node* new = (struct Node *)malloc(sizeof (struct Node));\r
- new->next = NULL;\r
-\r
- if (*Head == NULL)\r
- {\r
- *Head = new;\r
- *Tail = *Head;\r
- }\r
- else\r
- {\r
- (*Tail)->next = new;\r
- *Tail = new;\r
- }\r
- return (new);\r
-}\r
-void IterateList (struct Node* HeadList)\r
-{\r
- struct Node* current = HeadList;\r
-\r
- while (current != NULL)\r
- {\r
- printf("The float you entered is %f\n",current->f);\r
- current = current->next;\r
- }\r
-}\r
-int main(void)\r
-{\r
- struct Node* head = NULL;\r
- struct Node* tail = NULL;\r
- struct Node* curr = NULL;\r
- int i;\r
-\r
- for(i=0; i < 20; i++)\r
- {\r
- /* create node */\r
- curr = makelist(&head,&tail);\r
- printf("Enter float :\n");\r
- scanf("%f", &(curr->f));\r
- }\r
-\r
- /* now iterate the list */\r
- IterateList(head);\r
-\r
- return 0;\r
-}\r
+++ /dev/null
-#include <stdio.h>
-#include <malloc.h>
-
-#define CONFEDERATION(IFACE,TYPE) struct IFACE *interface;struct TYPE *next
-#define CREATE(TYPE) (struct TYPE *)malloc(sizeof(struct TYPE))
-#define APPEND(TYPE,MEMBER,LIST) (MEMBER?MEMBER->next=(struct TYPE *)LIST:0,LIST=(struct TYPE *)MEMBER)
-
-struct Drawable_data
-{
- CONFEDERATION(Drawable_interface,Drawable_data);
-};
-
-struct Drawable_interface
-{
- void (*draw)(void *self);
-};
-
-struct Tri
-{
- CONFEDERATION(Drawable_interface,Drawable_data);
- int x1; int y1; int x2; int y2; int x3; int y3;
-};
-
-struct Rect
-{
- CONFEDERATION(Drawable_interface,Drawable_data);
- int x1; int y1; int x2; int y2;
-};
-
-void draw_tri(void *_self)
-{
- struct Tri *self=(struct Tri *)_self;
- printf("%d,%d - %d,%d - %d,%d\n",self->x1,self->y1,self->x2,self->y2,self->x3,self->y3);
-};
-
-void draw_rect(void *self)
-{
- struct Rect *r=(struct Rect *)self;
- printf("%d,%d - %d,%d\n",r->x1,r->y1,r->x2,r->y2);
-};
-
-struct Drawable_interface *init_tri_interface(void)
-{
- struct Drawable_interface *i=CREATE(Drawable_interface);
- /* vsechny metody je bohuzel potreba bindnout rucne, neda se svitit... */
- if(i) i->draw=draw_tri;
- return i;
-}
-
-struct Drawable_interface *init_rect_interface(void)
-{
- struct Drawable_interface *i=CREATE(Drawable_interface);
- /* vsechny metody je bohuzel potreba bindnout rucne, neda se svitit... */
- if(i) i->draw=draw_rect;
- return i;
-}
-
-struct Tri *create_tri(struct Drawable_interface *i, int x1, int y1, int x2, int y2, int x3, int y3)
-{
- struct Tri *t=CREATE(Tri);
- if(i && t)
- {
- t->interface=i;
- t->x1=x1;t->y1=y1;t->x2=x2;t->y2=y2;t->x3=x3;t->y3=y3;
- }
- return t;
-}
-
-struct Rect *create_rect(struct Drawable_interface *i, int x1, int y1, int x2, int y2)
-{
- struct Rect *r=CREATE(Rect);
- if(i && r)
- {
- r->interface=i;
- r->x1=x1;r->y1=y1;r->x2=x2;r->y2=y2;
- }
- return r;
-}
-
-int main(void)
-{
- struct Drawable_interface *tri_interface=init_tri_interface();
- struct Drawable_interface *rect_interface=init_rect_interface();
- struct Drawable_data *all=NULL,*one;
- struct Tri *t;
- struct Rect *r;
-
- r=create_rect(rect_interface,0,10,1,11);
- APPEND(Drawable_data,r,all);
- t=create_tri(tri_interface,0,0,0,4,3,0);
- APPEND(Drawable_data,t,all);
- r=create_rect(rect_interface,10,0,11,1);
- APPEND(Drawable_data,r,all);
-
- /* a nyni ... bylo to hodne prace, ale povedlo se ... ! */
-
- for(one=all;one;one=one->next) (*(one->interface->draw))(one);
-
- /* a nyni pro efekt jeste instatni nudlovy kod s kanci prichuti: */
-
-#define _(OBJECT,METHOD) OBJECT==NULL)?0:(*(OBJECT->interface->METHOD))(OBJECT
-#define FOR_EACH(ONE,ALL) for(ONE=ALL;ONE;ONE=ONE->next)
-
- FOR_EACH(one,all) (_(one,draw));
-
- return 0;
-}
+++ /dev/null
-#include <stdio.h>
-#include <malloc.h>
-#include <assert.h>
-
-#define CONFEDERATION(IFACE,TYPE) struct IFACE *interface;struct TYPE *next
-#define CREATE(TYPE) (struct TYPE *)malloc(sizeof(struct TYPE))
-#define APPEND(TYPE,MEMBER,LIST) (MEMBER?MEMBER->next=(struct TYPE *)LIST:0,LIST=(struct TYPE *)MEMBER)
-#define SELF void *_self, void *_dummy
-#define I_AM(TYPE) struct TYPE *self=(struct TYPE *)_self;
-
-struct Drawable_data
-{
- CONFEDERATION(Drawable_interface,Drawable_data);
-};
-
-struct Drawable_interface
-{
- void (*draw)(SELF);
- int (*desc)(SELF, int something);
-};
-
-struct Tri
-{
- CONFEDERATION(Drawable_interface,Drawable_data);
- int x1; int y1; int x2; int y2; int x3; int y3;
-};
-
-struct Rect
-{
- CONFEDERATION(Drawable_interface,Drawable_data);
- int x1; int y1; int x2; int y2;
-};
-
-void draw_tri(SELF)
-{
- I_AM(Tri);
- printf("imagine I am drawing %d,%d - %d,%d - %d,%d\n",self->x1,self->y1,self->x2,self->y2,self->x3,self->y3);
-};
-
-void draw_rect(SELF)
-{
- I_AM(Rect);
- printf("imagine I am drawing %d,%d - %d,%d\n",self->x1,self->y1,self->x2,self->y2);
-};
-
-int desc_tri(SELF, int something)
-{
- I_AM(Tri);
- printf("I am triangle %d,%d - %d,%d - %d,%d, method draw called with argument: %d\n",self->x1,self->y1,self->x2,self->y2,self->x3,self->y3, something);
- return something;
-};
-
-int desc_rect(SELF, int something)
-{
- I_AM(Rect);
- printf("I am rectangle %d,%d - %d,%d, method draw called with argument: %d\n",self->x1,self->y1,self->x2,self->y2, something);
- return something;
-};
-
-struct Drawable_interface *init_tri_interface(void)
-{
- struct Drawable_interface *i=CREATE(Drawable_interface);
- /* vsechny metody je bohuzel potreba bindnout rucne, neda se svitit... */
- if(i) { i->draw=draw_tri; i->desc=desc_tri; }
- return i;
-}
-
-struct Drawable_interface *init_rect_interface(void)
-{
- struct Drawable_interface *i=CREATE(Drawable_interface);
- /* vsechny metody je bohuzel potreba bindnout rucne, neda se svitit... */
- if(i) { i->draw=draw_rect; i->desc=desc_rect; }
- return i;
-}
-
-struct Tri *create_tri(struct Drawable_interface *i, int x1, int y1, int x2, int y2, int x3, int y3)
-{
- struct Tri *t=CREATE(Tri);
- if(i && t)
- {
- t->interface=i;
- t->x1=x1;t->y1=y1;t->x2=x2;t->y2=y2;t->x3=x3;t->y3=y3;
- }
- return t;
-}
-
-struct Rect *create_rect(struct Drawable_interface *i, int x1, int y1, int x2, int y2)
-{
- struct Rect *r=CREATE(Rect);
- if(i && r)
- {
- r->interface=i;
- r->x1=x1;r->y1=y1;r->x2=x2;r->y2=y2;
- }
- return r;
-}
-
-int main(void)
-{
- struct Drawable_interface *tri_interface=init_tri_interface();
- struct Drawable_interface *rect_interface=init_rect_interface();
- struct Drawable_data *all=NULL,*one;
- struct Tri *t;
- struct Rect *r;
-
- r=create_rect(rect_interface,0,10,1,11);
- APPEND(Drawable_data,r,all);
- t=create_tri(tri_interface,0,0,0,4,3,0);
- APPEND(Drawable_data,t,all);
- r=create_rect(rect_interface,10,0,11,1);
- APPEND(Drawable_data,r,all);
-
- /* a nyni ... bylo to hodne prace, ale povedlo se ... ! */
-
- for(one=all;one;one=one->next)
- {
- printf("(return value %d)\n",(*(one->interface->desc)) (one,NULL,0));
- (*(one->interface->draw)) (one,NULL);
- }
-
- /* ...a nakonec pro efekt jeste instatni nudlovy kod s kanci prichuti dle ANSI C99: */
-
-#define _ARG1(ARG1,...) ARG1
-#define _(OBJECT,...) (assert(OBJECT),/**/(*(OBJECT->interface->_ARG1(__VA_ARGS__,)))/**/(OBJECT,OBJECT->interface->__VA_ARGS__)/**/)
-#define FOR_EACH(ONE,ALL) for(ONE=ALL;ONE;ONE=ONE->next)
-
- FOR_EACH(one,all)
- {
- printf("(return value %d)\n",_(one,desc,1));
- _(one,draw);
- }
-
- return 0;
-}
+++ /dev/null
-#include <stdarg.h>
-#include <stdio.h>
-
-void _echo(char *s, ... ) { va_list ap; for(va_start(ap,s);s;s=va_arg(ap,char *)) fputs(s,stdout); va_end(ap); }
-#define print(...) _echo(__VA_ARGS__,"\n",NULL)
-#define echo(...) _echo(__VA_ARGS__,NULL)
-
-int main(void)
-{
- echo("Hello ","world","! ");
- print("Hello ","world","! ");
-}
+++ /dev/null
-#include "cll1.h"
-
-/* try to run: ./arguments1 -x xxx yyyy -c cccc */
-
-program
-{
- if_args
- {
- for_args
- {
- if this_arg[0] == '-')
- {
- printf("Command line switch: -%c ",ptr[1]);
- if (next_arg) then
- {
- echo("followed by: ",next_arg);
- skip_next;
- }
- print("");
- }
- else
- print("Standalone argument: ",ptr);
- }
- }
- else
- print("Bleeeeh, no arguments supplied... :-(");
-}
+++ /dev/null
-#include "cll1.h"
-
-//try to run: ./arguments2 -f reload yyyy -?
-
-program
-{
- if_args then
- {
- for_args
- {
- if_arg ("-?") then
- print("This is just help!");
- else if_arg ("-f") then
- {
- if (next_arg) then
- {
- print("Forced argument: ",next_arg);
- skip_one;
- }
- }
- else
- print("Normal argument: ",this_arg);
- }
- }
- else
- print("Bleeeeh, no arguments supplied... :-(");
-}
+++ /dev/null
-#include "cll1.h"
-
-program
-{
- const bool t = TRUE, f = FALSE;
- bool l, m = MAYBE;
- str s;
-
- print("TRUE and FALSE =", btoa(t and f) );
- print("TRUE or FALSE =", btoa(t or f) );
- print("TRUE and MAYBE =", btoa(t and m) );
- print("FALSE or MAYBE =", btoa(t or m) );
- print("not FALSE =", btoa(not f) );
- print("not TRUE =", btoa(not t) );
- print("not MAYBE =", btoa(not m) );
-
- for_strs(s, "TRUE","false","yes","NO","True","FALSE","YES","no","Yes","No","1","0","abc","xyz","Eyes","Ears","rue","alse","oui","no","ano","ne"," ","NULL",NULL,EOL,"","ano","ne")
- {
- l = atob(s);
- echo("\"", s, "\"\tmeans ", btoa(l), EOL);
- }
-}
+++ /dev/null
-../cll1.h
\ No newline at end of file
+++ /dev/null
-#include "cll1.h"
-
-program
-{
- char *ptr;
- parse("/etc/passwd")
- {
- column(ptr,_,':',6);
- if(ptr)puts(ptr);
- }
- done;
-}
+++ /dev/null
-#include "cll1.h"
-
-program
-{
- char *ptr;
- int i;
- parse("/etc/passwd")
- {
- columns(ptr,_,':',i) switch(i)
- {
- case 0: printf("%s...",ptr); break;
- case 6: puts(ptr);
- }
- }
- done;
-}
+++ /dev/null
-#include "cll1.h"
-
-program
-{
- str a,b;
-
- print("Local language (enviroment) is set to:", LANG);
- a="¾luklý";
- b="®LUKLÝ";
- printf("str_order(\"%s\",\"%s\") = %d\n",a,b,str_order(a,b));
- printf("eq(\"%s\",\"%s\") = %s\n",a,b,btoa(eq(a,b)));
- printf("eq(\"%s\",\"%s\") = %s\n",a,a,btoa(eq(a,a)));
- printf("eqi(\"%s\",\"%s\") = %s\n",a,b,btoa(eqi(a,b)));
- a="aabc";
- b="axyz";
- printf("str_order(\"%s\",\"%s\") = %d\n",a,b,str_order(a,b));
- printf("eq(\"%s\",\"%s\") = %s\n",a,b,btoa(eq(a,b)));
- printf("eqi(\"%s\",\"%s\") = %s\n",a,b,btoa(eqi(a,b)));
- a="ABC";
- b="abc";
- printf("str_order(\"%s\",\"%s\") = %d\n",a,b,str_order(a,b));
- printf("eq(\"%s\",\"%s\") = %s\n",a,b,btoa(eq(a,b)));
- printf("eqi(\"%s\",\"%s\") = %s\n",a,b,btoa(eqi(a,b)));
- a="abc";
- b="abc";
- printf("str_order(\"%s\",\"%s\") = %d\n",a,b,str_order(a,b));
- printf("eq(\"%s\",\"%s\") = %s\n",a,b,btoa(eq(a,b)));
- printf("eqi(\"%s\",\"%s\") = %s\n",a,b,btoa(eqi(a,b)));
- a="";
- b="";
- printf("str_order(\"%s\",\"%s\") = %d\n",a,b,str_order(a,b));
- printf("eq(\"%s\",\"%s\") = %s\n",a,b,btoa(eq(a,b)));
- printf("eqi(\"%s\",\"%s\") = %s\n",a,b,btoa(eqi(a,b)));
- a=NULL;
- b="abc";
- printf("str_order( %s ,\"%s\") = %d\n",a,b,str_order(a,b));
- printf("eq( %s ,\"%s\") = %s\n",a,b,btoa(eq(a,b)));
- printf("eqi( %s ,\"%s\") = %s\n",a,b,btoa(eqi(a,b)));
- a=NULL;
- b="";
- printf("str_order( %s ,\"%s\") = %d\n",a,b,str_order(a,b));
- printf("eq( %s ,\"%s\") = %s\n",a,b,btoa(eq(a,b)));
- printf("eqi( %s ,\"%s\") = %s\n",a,b,btoa(eqi(a,b)));
- a=NULL;
- b=NULL;
- printf("str_order( %s , %s ) = %d\n",a,b,str_order(a,b));
- printf("eq( %s ,%s ) = %s\n",a,b,btoa(eq(a,b)));
- printf("eqi( %s , %s ) = %s\n",a,b,btoa(eqi(a,b)));
-}
+++ /dev/null
-#include "cll1.h"
-
-void private_method(int i)
-{
- if(i==2)
- {
- fail(LOCAL_FAILURE);
- }
- else if(i==6)
- {
- fail(EVIL_FAILURE);
- }
- else
- {
- printf("nuda #%d\n",i);
- }
-}
-
-void some_job(int i)
-{
- try
- {
- private_method(i);
- private_method(i+1);
- private_method(i+2);
- }
- else_switch_failures
- {
- case EVIL_FAILURE: puts("[serious error]"); pass_failure;
- case LOCAL_FAILURE: puts("[non-fatal error detected]"); break;
- default : puts("[sorry, vole, error]");
- }
-}
-
-program
-{
-
- try
- {
- some_job(1);
- some_job(3);
- some_job(6);
- some_job(2);
- some_job(7);
- }
- else
- {
- puts("sorry, vole, error!");
- }
-
- try
- {
- some_job(1);
- some_job(2);
- some_job(4);
- some_job(7);
- }
- else_catch(EVIL_FAILURE)
- {
- puts("totaly screwed.");
- }
- else
- {
- puts("ahem... something went wrong.");
- }
-}
+++ /dev/null
-#include "cll1.h"
-
-void some_function(int i)
-{
- if(i==2)
- {
- fail(EVIL_FAILURE);
- }
- if(i==7)
- {
- some_function(2);
- }
- if(i==6)
- {
- fail(LOCAL_FAILURE);
- }
- printf("nuda #%d\n",i);
-}
-
-program
-{
- try
- {
- some_function(1);
- some_function(2);
- some_function(6);
- }
- else_switch_failures
- {
- case EVIL_FAILURE: puts("serious failure detected!"); break;
- default: puts("sorry, vole, error!");
- }
-
- try
- {
- some_function(1);
- some_function(3);
- some_function(6);
- some_function(2);
- }
- else
- {
- puts("sorry, vole, error!");
- }
-
- try
- {
- some_function(1);
- some_function(6);
- }
- else_catch(EVIL_FAILURE)
- {
- puts("Totally screwed.");
- exit(-1);
- }
- else
- {
- puts("We survived this failure.");
- }
-
- try
- {
- some_function(3);
- some_function(7);
- }
- else_catch(EVIL_FAILURE)
- {
- puts("totally screwed.");
- exit(-1);
- }
- else
- {
- puts("we survived this failure.");
- }
-}
+++ /dev/null
-#define USE_LIBRARY_FASTCGI
-#include "cll1.h"
-
-program
-{
- int count = 0;
- while_fastcgi_accept
- {
- printf("Content-type: text/html\r\n"
- "\r\n"
- "<title>FastCGI Hello!</title>"
- "<h1>FastCGI Hello!</h1>"
- "Request number %d running on host <i>%s</i>\n",
- ++count, getenv("SERVER_NAME"));
- }
-}
+++ /dev/null
-#include "cll1.h"
-
-program
-{
- int i;
- str s;
-
- echo("for_ints(i, 8,1,-2,745,-32,-64,27,4) ): ");
- for_ints(i, 8,1,-2,745,-32,-64,27,4 ) printf(" [%d]",i);
- print("");
-
- echo("for_strs(s, \"aasd\",\"snres\",\"sdfrm\",\"ojffgt\",\"wweqwe\" )): ");
- for_strs(s, "aasd","snres","sdfrm","ojffgt","wweqwe" ) echo(" [",s,"]");
- print("");
-}
+++ /dev/null
-#include "cll1.h"
-
-program
-{
- int i,j=1;
-
- echo("Just plain vanilla auto-increment:\tfor_range(i,1,5)");
- for_range(i,1,5)
- {
- printf(" [%d]",i);
- }
- print("");
-
- echo("Single-evaluation of macro argument:\tj=1; for_range(i,0,j++)");
- for_range(i,0,j++)
- {
- printf(" [%d]",i);
- }
- print("");
-
- echo("Just plain vanilla auto-decrement:\tfor_range(i,1,0)");
- for_range(i,1,0)
- {
- printf(" [%d]",i);
- }
- print("");
-
- echo("Single iteration is possible too:\tfor_range(i,1,1)");
- for_range(i,1,1)
- {
- printf(" [%d]",i);
- }
- print("");
-
- echo("Yet another example of macro safety:\tj=2; for_range(i,5,--j)");
- for_range(i,5,--j)
- {
- printf(" [%d]",i);
- }
- print("");
-
- echo("Nesting of this macro seems to be safe:\tfor_range(i,1,3) for_range(j,3,1)");
- for_range(i,1,3)
- {
- for_range(j,3,1)
- {
- printf(" [%d,%d]",i,j);
- }
- }
- print("");
-}
+++ /dev/null
-#include "cll1.h"
-
-program
-{
- print("Vale Mundum!");
-}
+++ /dev/null
-#include "cll1.h"
-
-struct Line
-{
- int n;
- list(Line);
-} *line;
-
-struct Id
-{
- char *str;
- int count;
- struct Line *lines;
- list(Id);
-} *id,*ids=NULL;
-
-program
-{
- char *ptr;
- char *fname;
- char *c=NULL;
- int l=0;
-
- arguments
- {
- thisargument(fname);
- nextargument(c);
- }
- else
- {
- puts("Usage: idmap file [c]");
- return 1;
- }
-
- parse(fname)
- {
- l++;
- while(*_)
- {
- goto_alpha(_);
- ptr=_;
- skip_alnum(_);
- *_=0;
- _++;
-
- if(*ptr)
- {
- if_exists(id,ids,eq(id->str,ptr))
- {
- id->count++;
- if_exists(line,id->lines,line->n==l);
- else
- {
- create(line,Line);
- line->n=l;
- push(line,id->lines);
- }
- }
- else
- {
- create(id,Id);
- create(line,Line);
- id->str=ptr;
- id->count=1;
- id->lines=line;
- line->n=l;
- insert(id,ids,sort_by,str);
- }
- }
- if(*_=='"' || *_=='\'' )
- {
- char c=*_;
- _++;
- gotochr(_,c);
- }
- }
- }
- fail
- {
- perror(argv[1]);
- exit(-1);
- }
- done;
-
- if(c)
- sort(id,ids,desc_order_by,count);
-
- for_each(id,ids)
- {
- printf("%3dx %s",id->count,id->str);
- for_each(line,id->lines) printf(" [%d]",line->n);
- printf("\n");
- }
-}
+++ /dev/null
-../cll1.h
\ No newline at end of file
+++ /dev/null
-#include "cll1.h"
-
-def_mem(Node)
-{
- float f;
- list(Node);
-};
-
-program
-{
- Node one,all=NULL;
-
- repeat(20)
- {
- one=get_mem(Node);
- printf("Enter float: \n");
- scanf("%f", &(one->f));
- insert(one,all,order_by_num,f);
- }
-
- for_each(one,all)
- {
- printf("The float you entered is %f\n",one->f);
- }
-}
+++ /dev/null
-#include "cll1.h"
-
-def_mem(Node)
-{
- float f;
- list(Node);
-};
-
-program
-{
- Node one,all=NULL,last=NULL;
-
- repeat(20)
- {
- one=get_mem(Node);
- printf("Enter float: \n");
- scanf("%f", &(one->f));
- append(one,last);
- if(not all)
- {
- all=last;
- }
- }
-
- for_each(one,all)
- {
- printf("The float you entered is %f\n",one->f);
- }
-}
+++ /dev/null
-#include "cll1.h"
-
-def_mem(Record)
-{
- int i;
- str s;
- list(Record);
-};
-
-program
-{
- Record record, records = NULL;
-
- print("4x insert(record,records,order_by_num,i);");
-
- record = get_mem(Record);
- record->i = 1;
- record->s = "ddd";
- insert(record, records, order_by_num, i);
-
- record = get_mem(Record);
- record->i = 3;
- record->s = "BBBB";
- insert(record, records, order_by_num, i);
-
- record = get_mem(Record);
- record->i = 4;
- record->s = "e";
- insert(record, records, order_by_num, i);
-
- record = get_mem(Record);
- record->i = 2;
- record->s = "aaaa";
- insert(record, records, order_by_num, i);
-
- for_each(record, records)
- {
- printf("i=%d, s=%s\n", record->i, record->s);
- }
-
- print("1x append(record,records);");
-
- record = get_mem(Record);
- record->i = 0;
- record->s = "ccc";
- append(record, records);
-
- for_each(record, records)
- {
- printf("i=%d, s=%s\n", record->i, record->s);
- }
-
- print("sort(record,records,order_by_num_desc,i);");
-
- sort(record, records, order_by_num_desc, i);
-
- for_each(record, records)
- {
- printf("i=%d, s=%s\n", record->i, record->s);
- }
-
- print("sort(record,records,order_by_str,s);");
-
- sort(record, records, order_by_str, s);
-
- for_each(record, records)
- {
- printf("i=%d, s=%s\n",record->i,record->s);
- }
-
- print("sort(record, records, order_by_ascii_desc, s);");
-
- sort(record, records, order_by_ascii_desc, s);
-
- for_each(record,records)
- {
- printf("i=%d, s=%s\n", record->i, record->s);
- }
-
- print("remove(record,records,record->i==1);");
- remove(record, records, record->i == 1);
-
- for_each(record,records)
- {
- printf("i=%d, s=%s\n", record->i, record->s);
- }
-
- print("drop(record,records);");
- drop(record, records);
-
- for_each(record, records)
- {
- printf("i=%d, s=%s\n", record->i, record->s);
- }
-}
+++ /dev/null
-#include "cll1.h"
-
-program
-{
- str a,b;
- time_t t = time(NULL);
- file f;
- str filename = "blabla.txt";
-
- print("Local language (enviroment) is set to:", LANG);
- print("C<<1 automatically activates locales LC_COLLATE|LC_CTYPE|LC_MESSAGES|LC_MONETARY|LC_TIME but not LC_NUMERIC:");
- a = "¾luklý kùò";
- b = "®LUKLÝ KÙÒ";
- printf("str_order(\"%s\",\"%s\") = %d\n",a,b,str_order(a,b));
- printf("eq(\"%s\",\"%s\") = %s\n",a,b,btoa(eq(a,b)));
- printf("eq(\"%s\",\"%s\") = %s\n",a,a,btoa(eq(a,a)));
- printf("eqi(\"%s\",\"%s\") = %s\n",a,b,btoa(eqi(a,b)));
- printf("PI will be displayed as: %f\n",PI);
- echo("Time will be displayed as: ", ctime(&t));
- print("Error mesages will be displayed as: ");
- f = fopen(filename,"r");
- if(not f)
- {
- errstr = filename;
- _SYSFAIL(SYSTEM_FAILURE);
- }
-}
+++ /dev/null
-#define USE_LIBRARY_MYSQL
-#include "cll1.h"
-
-program
-{
- MYSQL_ROW row;
-
- if(mysql_connect("localhost","root","","pokus"))
- {
- for_mysql_query_results(row,"SELECT id,str FROM pokus")
- printf("id=%s str=%s\n", row[0], row[1]);
- }
- else
- puts("Can't connect to database!");
-}
+++ /dev/null
-#include "cll1.h"
-
-/* This is example of advanced C<<1 object oriented features... */
-
-def_interface(Shape, Interface)
-{
- void method(draw) (Shape self);
- void method(move) (Shape self, int x, int y);
- str method(desc) (Shape self);
- void method(rename) (Shape self, str name);
- void method(reset) (Shape self, int x1, int y1, int x2, int y2, int x3, int y3);
- float method(area) (Shape self);
- int count;
-};
-
-/* We intentionaly define heterogenous objects, which share only the interface
- binding. Not only we can use different order of variables, and different
- names - but we can even store these data on remote systems, etc. */
-
-def_mem(Tri)
-{
- interface(Interface);
- int x1, y1, x2, y2, x3, y3;
- str name;
-};
-
-def_mem(Rect)
-{
- interface(Interface);
- str desc;
- int x1, y1, x2, y2;
-};
-
-def_mem(Circ)
-{
- interface(Interface);
- int x1, y1;
- str comment;
- int r;
-};
-
-def_community(Shape, Interface);
-
-/* Note: interface(Interface); has to be at first position in all objects asociated in community */
-
-def_mem(Object_list)
-{
- Shape object;
- list(Object_list);
-};
-
-
-/* implementation of methods */
-
-void drawTri(Shape community)
-{
- I_am(self, Tri);
-
- printf("Drawing %s: %d,%d - %d,%d - %d,%d .\n",
- self->name, self->x1, self->y1, self->x2, self->y2, self->x3, self->y3);
-};
-
-void drawRect(Shape community)
-{
- I_am(self, Rect);
-
- printf("Drawing %s: %d,%d - %d,%d .\n",
- self->desc, self->x1, self->y1, self->x2, self->y2);
-};
-
-void drawCirc(Shape community)
-{
- I_am(self, Circ);
-
- printf("Drawing %s: %d,%d - r=%d .\n",
- self->comment, self->x1, self->y1, self->r);
-};
-
-void moveTri(Shape community, int x, int y)
-{
- I_am(self, Tri);
-
- self->x1 += x;
- self->y1 += y;
- self->x2 += x;
- self->y2 += y;
- self->x3 += x;
- self->y3 += y;
-};
-
-void moveRect(Shape community, int x, int y)
-{
- I_am(self, Rect);
-
- self->x1 += x;
- self->y1 += y;
- self->x2 += x;
- self->y2 += y;
-};
-
-void moveCirc(Shape community, int x, int y)
-{
- I_am(self, Circ);
-
- self->x1 += x;
- self->y1 += y;
-};
-
-str descTri(Shape community)
-{
- I_am(self, Tri);
-
- return self->name;
-}
-
-str descRect(Shape community)
-{
- I_am(self, Rect);
-
- return self->desc;
-}
-
-str descCirc(Shape community)
-{
- I_am(self, Circ);
-
- return self->comment;
-}
-
-float calcAreaTri(Shape community)
-{
- I_am(self, Tri);
-
- return 0;
-}
-
-float calcAreaRect(Shape community)
-{
- I_am(self, Rect);
-
- return (self->x2 - self->x1)*(self->y2 - self->y1);
-}
-
-float calcAreaCirc(Shape community)
-{
- I_am(self, Circ);
-
- return PI * self->r * self->r;
-}
-
-void setTri(Shape community, int x1, int y1, int x2, int y2, int x3, int y3)
-{
- I_am(self, Tri);
-
- self->x1 = x1;
- self->y1 = y1;
- self->x2 = x2;
- self->y2 = y2;
- self->x3 = x3;
- self->y3 = y3;
-}
-
-void setRect(Shape community, int x1, int y1, int x2, int y2, int dummy1, int dummy2)
-{
- I_am(self, Rect);
-
- self->x1 = x1;
- self->y1 = y1;
- self->x2 = x2;
- self->y2 = y2;
-}
-
-void setCirc(Shape community, int x1, int y1, int r, int dummy1, int dummy2, int dummy3)
-{
- I_am(self, Circ);
-
- self->x1 = x1;
- self->y1 = y1;
- self->r = r;
-}
-
-void nameRect(Shape community, str name)
-{
- I_am(self, Rect);
-
- self->desc = name;
-}
-
-/* Example of using object interface methods from inside constructor methods */
-
-construct(Tri,Interface) (Tri self, int x1, int y1, int x2, int y2, int x3, int y3)
-{
- self->name = "TRIANGLE";
- interface_of(self)->count++;
- _(reset, self, x1, y1, x2, y2, x3, y3);
-
- return self;
-}
-
-construct(Rect,Interface) (Rect self, int x1, int y1, int x2, int y2)
-{
- self->desc = "rectangle";
- interface_of(self)->count++;
- _(reset, self, x1, y1, x2, y2, 0, 0);
-
- return self;
-}
-
-construct(Circ,Interface) (Circ self, int x1, int y1, int r)
-{
- self->comment = "Circle";
- interface_of(self)->count++;
- _(reset, self, x1, y1, r, 0, 0, 0);
-
- return self;
-}
-
-/* registration of implemented methods to three interfaces of the same type */
-
-Interface triInterface(void)
-{
- Get_mem(this, Interface);
-
- this->draw = drawTri;
- this->move = moveTri;
- this->desc = descTri;
- this->rename = NULL;
- this->reset = setTri;
- this->area = calcAreaTri;
- this->count = 0;
-
- return this;
-}
-
-Interface rectInterface(void)
-{
- Get_mem(this, Interface);
-
- this->draw = drawRect;
- this->move = moveRect;
- this->desc = descRect;
- this->rename = nameRect;
- this->reset = setRect;
- this->area = calcAreaRect;
- this->count = 0;
-
- return this;
-}
-
-Interface circInterface(void)
-{
- Get_mem(this, Interface);
-
- this->draw = drawCirc;
- this->move = moveCirc;
- this->desc = descCirc;
- this->rename = NULL;
- this->reset = setCirc;
- this->area = calcAreaCirc;
- this->count = 0;
-
- return this;
-}
-
-/* usage of object community inside C<<1 program */
-
-program
-{
- Interface triangles = triInterface();
- Interface rectangles = rectInterface();
- Interface circles = circInterface();
- Object_list all = NULL, one;
-
- one = get_mem(Object_list);
- one->object = get_obj_as(Shape, Rect, rectangles, 0, 10, 1, 11);
- append(one, all);
-
- one = get_mem(Object_list);
- one->object = get_obj_as(Shape, Tri, triangles, 0, 0, 0, 4, 3, 0);
- append(one, all);
-
- one = get_mem(Object_list);
- one->object = get_obj_as(Shape, Rect, rectangles, 10, 0, 11, 1);
- append(one, all);
-
- one = get_mem(Object_list);
- one->object = get_obj_as(Shape, Circ, circles, 0, 10, 1);
- append(one, all);
-
- printf("We have created %d triangles, %d rectangles and %d circles:\n",
- triangles->count, rectangles->count, circles->count);
-
- for_each(one, all)
- {
- _(draw, one->object);
- printf("Area of this %s is %f (square pixels).\n", _(desc, one->object), _(area, one->object));
- printf("We have created %d instances of this type of object.\n", interface_of(one->object)->count);
-
- if(interface_of(one->object) == rectangles)
- {
- _(reset, one->object, 0, 0, 1, 1, 0, 0);
- _(rename, one->object, "Renamed rectangle");
- }
- else
- {
- _(move, one->object, 10, 10);
- }
- }
-
- print("Rectangles were reset to new size and renamed, other objects were moved:");
- for_each(one, all)
- {
- _(draw, one->object);
- }
-}
+++ /dev/null
-#include "cll1.h"
-
-/* This is example of advanced C<<1 object oriented features... */
-
-def_interface(Point, PointInterface)
-{
- void method(move) (Shape self, int x, int y);
- str method(desc) (Shape self);
- void method(rename) (Shape self, str name);
- int count;
-};
-
-def_interface(Shape, ShapeInterface)
-{
- federation(Point);
- void method(draw) (Shape self);
- void method(reset) (Shape self, int x1, int y1, int x2, int y2, int x3, int y3);
- float method(area) (Shape self);
- int count;
-};
-
-/* This is example of non-hierarchical object federation architecture in C<<1 */
-
-def_obj(Point)
-{
- interface(PointInterface);
- shape Shape; /* this is optional, but we will use it do demonstrate power of C<<1 */
- int x1, y1;
- str desc;
-}
-
-def_mem(Tri)
-{
- interface(ShapeInterface);
- Point point;
- int x2, y2, x3, y3;
-};
-
-def_mem(Rect)
-{
- interface(ShapeInterface);
- Point point;
- int x2, y2;
-};
-
-def_mem(Circ)
-{
- interface(ShapeInterface);
- Point point;
- int r;
-};
-
-def_community(Shape, ShapeInterface);
-
-/* Note: interface(ShapeInterface); has to be at first position in all objects asociated in community */
-
-def_mem(Object_list)
-{
- Shape object;
- list(Object_list);
-};
-
-/* implementation of methods */
-
-void drawTri(Shape community)
-{
- I_am(self, Tri);
-
- printf("Drawing %s: %d,%d - %d,%d - %d,%d .\n",
- self->point->desc, self->point->x, self->point->y, self->x2, self->y2, self->x3, self->y3);
-};
-
-void drawRect(Shape community)
-{
- I_am(self, Rect);
-
- printf("Drawing %s: %d,%d - %d,%d .\n",
- self->point->desc, self->x1, self->y1, self->x2, self->y2);
-};
-
-void drawCirc(Shape community)
-{
- I_am(self, Circ);
-
- printf("Drawing %s: %d,%d - r=%d .\n",
- self->comment, self->x1, self->y1, self->r);
-};
-
-void moveTri(Shape community, int x, int y)
-{
- I_am(self, Tri);
-
- self->x1 += x;
- self->y1 += y;
- self->x2 += x;
- self->y2 += y;
- self->x3 += x;
- self->y3 += y;
-};
-
-void moveRect(Shape community, int x, int y)
-{
- I_am(self, Rect);
-
- self->x1 += x;
- self->y1 += y;
- self->x2 += x;
- self->y2 += y;
-};
-
-void moveCirc(Shape community, int x, int y)
-{
- I_am(self, Circ);
-
- self->x1 += x;
- self->y1 += y;
-};
-
-str descTri(Shape community)
-{
- I_am(self, Tri);
-
- return _(desc, self->point);
-}
-
-str descRect(Shape community)
-{
- I_am(self, Rect);
-
- return _(desc, self->point);
-}
-
-str descCirc(Shape community)
-{
- I_am(self, Circ);
-
- return _(desc, self->point);
-}
-
-float calcAreaTri(Shape community)
-{
- I_am(self, Tri);
-
- return 0;
-}
-
-float calcAreaRect(Shape community)
-{
- I_am(self, Rect);
-
- return (self->x2 - self->x1)*(self->y2 - self->y1);
-}
-
-float calcAreaCirc(Shape community)
-{
- I_am(self, Circ);
-
- return PI * self->r * self->r;
-}
-
-void setTri(Shape community, int x1, int y1, int x2, int y2, int x3, int y3)
-{
- I_am(self, Tri);
-
- self->x1 = x1;
- self->y1 = y1;
- self->x2 = x2;
- self->y2 = y2;
- self->x3 = x3;
- self->y3 = y3;
-}
-
-void setRect(Shape community, int x1, int y1, int x2, int y2, int dummy1, int dummy2)
-{
- I_am(self, Rect);
-
- self->x1 = x1;
- self->y1 = y1;
- self->x2 = x2;
- self->y2 = y2;
-}
-
-void setCirc(Shape community, int x1, int y1, int r, int dummy1, int dummy2, int dummy3)
-{
- I_am(self, Circ);
-
- self->x1 = x1;
- self->y1 = y1;
- self->r = r;
-}
-
-void nameRect(Shape community, str newname)
-{
- I_am(self, Rect);
-
- _(name, self->point, newname);
-}
-
-/* Example of using object interface methods from inside constructor methods */
-
-construct(Tri,ShapeInterface) (Tri self, int x1, int y1, int x2, int y2, int x3, int y3)
-{
- self->point = get_federation(Point);
- _(move, self->point, x1, x2);
- self->name = "TRIANGLE";
- interface_of(self)->count++;
- _(reset, self, x2, y2, x3, y3);
-
- return self;
-}
-
-construct(Rect,ShapeInterface) (Rect self, int x1, int y1, int x2, int y2)
-{
- self->desc = "rectangle";
- interface_of(self)->count++;
- _(reset, self, x1, y1, x2, y2, 0, 0);
-
- return self;
-}
-
-construct(Circ,ShapeInterface) (Circ self, int x1, int y1, int r)
-{
- self->comment = "Circle";
- interface_of(self)->count++;
- _(reset, self, x1, y1, r, 0, 0, 0);
-
- return self;
-}
-
-/* registration of implemented methods to three interfaces of the same type */
-
-PointInterface pointInterface(void)
-{
- Get_mem(this, PointInterface);
-
- this->draw = NULL;
- this->move = movePoint;
- this->desc = descPoint;
- this->rename = NULL;
- this->reset = setTri;
- this->area = calcAreaTri;
- this->count = 0;
-
- return this;
-}
-
-ShapeInterface triInterface(void)
-{
- Get_mem(this, ShapeInterface);
-
- this->draw = drawTri;
- this->move = moveTri;
- this->desc = descTri;
- this->rename = NULL;
- this->reset = setTri;
- this->area = calcAreaTri;
- this->count = 0;
-
- return this;
-}
-
-ShapeInterface rectInterface(void)
-{
- Get_mem(this, ShapeInterface);
-
- this->draw = drawRect;
- this->move = moveRect;
- this->desc = descRect;
- this->rename = nameRect;
- this->reset = setRect;
- this->area = calcAreaRect;
- this->count = 0;
-
- return this;
-}
-
-ShapeInterface circInterface(void)
-{
- Get_mem(this, ShapeInterface);
-
- this->draw = drawCirc;
- this->move = moveCirc;
- this->desc = descCirc;
- this->rename = NULL;
- this->reset = setCirc;
- this->area = calcAreaCirc;
- this->count = 0;
-
- return this;
-}
-
-/* usage of objects inside C<<1 program */
-
-program
-{
- ShapeInterface triangles = triInterface();
- ShapeInterface rectangles = rectInterface();
- ShapeInterface circles = circInterface();
- Object_list all = NULL, one;
-
- one = get_mem(Object_list);
- one->object = get_obj_as(Shape, Rect, rectangles, 0, 10, 1, 11);
- append(one, all);
-
- one = get_mem(Object_list);
- one->object = get_obj_as(Shape, Tri, triangles, 0, 0, 0, 4, 3, 0);
- append(one, all);
-
- one = get_mem(Object_list);
- one->object = get_obj_as(Shape, Rect, rectangles, 10, 0, 11, 1);
- append(one, all);
-
- one = get_mem(Object_list);
- one->object = get_obj_as(Shape, Circ, circles, 0, 10, 1);
- append(one, all);
-
- printf("We have created %d triangles, %d rectangles and %d circles:\n",
- triangles->count, rectangles->count, circles->count);
-
- for_each(one, all)
- {
- _(draw, one->object);
- printf("Area of this %s is %f (square pixels).\n", _(desc, one->object), _(area, one->object));
- printf("We have created %d instances of this type of object.\n", interface_of(one->object)->count);
-
- if(interface_of(one->object) == rectangles)
- {
- _(reset, one->object, 0, 0, 1, 1, 0, 0);
- _(rename, one->object, "Renamed rectangle");
- }
- else
- {
- _(move, one->object, 10, 10);
- }
- }
-
- print("Rectangles were reset to new size and renamed, other objects were moved:");
- for_each(one, all)
- {
- _(draw, one->object);
- }
-}
+++ /dev/null
-#include "cll1.h"
-
-/* This is C<<1 rewrite of object polymorphism from
- http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming
-
- Of course there are easier ways to do the same thing... :-)
- (G)2008 xChas */
-
-def_interface(Animal,Actions)
-{
- str method(talk) (Animal self);
-};
-
-def_obj(Animal)
-{
- interface(Actions);
- str name;
-};
-
-construct(Animal,Actions) (Animal self, str name)
-{
- self->name = name;
- return self;
-}
-
-/* implementation of methods */
-
-str catTalk(Animal self)
-{
- return "Meow!";
-}
-
-str dogTalk(Animal self)
-{
- return "Arf! Arf!";
-}
-
-/* registration of methods to object interface */
-
-Actions catActions(void)
-{
- Get_mem(this, Actions);
-
- this->talk = catTalk;
- return this;
-}
-
-Actions dogActions(void)
-{
- Get_mem(this, Actions);
-
- this->talk = dogTalk;
- return this;
-}
-
-/* usage of objects inside C<<1 program */
-
-program
-{
- int i;
- Animal animal[3];
- Actions cat = catActions();
- Actions dog = dogActions();
-
- animal[0] = get_obj(Animal, cat, "Missy");
- animal[1] = get_obj(Animal, cat, "Mr. Bojangles");
- animal[2] = get_obj(Animal, dog, "Lassie");
-
- for_range(i, 0, 2)
- {
- print(animal[i]->name, ":", _(talk, animal[i]));
- }
-
-}
+++ /dev/null
-#include "cll1.h"
-
-program
-{
- unsigned long i;
- for_range(i,1,10000000)
- echo("stuff\n");
-}
+++ /dev/null
-#include "cll1.h"
-
-program
-{
- repeat(10000000)
- print("stuff");
-}
+++ /dev/null
-#include "cll1.h"
-
-program
-{
- repeat(10000000)
- print("stuff1","stuff2");
-}
+++ /dev/null
-../../cll1.h
\ No newline at end of file
+++ /dev/null
-#include <iostream>
-
-#define RUNS 10000000UL
-int main()
-{
- unsigned long i;
- for (i=0;i<RUNS;i++)
- {
- std::cout << "stuff\n";
- }
- return 0;
-}
+++ /dev/null
-#include <iostream>
-
-#define RUNS 10000000UL
-int main()
-{
- unsigned long i;
- for (i=0;i<RUNS;i++) {
- std::cout << "stuff1" << " " << "stuff2" << std::endl;
- }
- return 0;
-}
+++ /dev/null
-#!/usr/bin/php5 -q
-<?php
-for ( $i=0; $i<10000000; $i++ )
-{
- echo "stuff1\n";
-}
-?>
+++ /dev/null
-#!/usr/bin/php5 -q
-<?php
-for ( $i=0; $i<10000000; $i++ )
-{
- echo "stuff1"." "."stuff2"."\n";
-}
-?>
+++ /dev/null
-#include <stdio.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- for (i=0;i<RUNS;i++)
- {
- fputs("stuff\n",stdout);
- }
- return 0;
-}
+++ /dev/null
-#include <stdio.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- for (i=0;i<RUNS;i++) {
- fputs("stuff1",stdout);
- fputs(" ",stdout);
- fputs("stuff2",stdout);
- fputs("\n",stdout);
- }
- return 0;
-}
+++ /dev/null
-#include <stdio.h>
-#include <string.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- char *s1="stuff\n";
- int l1=strlen(s1);
-
- for (i=0;i<RUNS;i++)
- {
- fwrite(s1,l1,1,stdout);
- }
- return 0;
-}
+++ /dev/null
-#include <stdio.h>
-#include <string.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- char *s1="stuff1";
- char *s2="stuff2";
- int l1=strlen(s1);
- int l2=strlen(s2);
-
- for (i=0;i<RUNS;i++)
- {
- fwrite(s1,l1,1,stdout);
- fwrite(" ",1,1,stdout);
- fwrite(s2,l2,1,stdout);
- fwrite("\n",1,1,stdout);
- }
- return 0;
-}
+++ /dev/null
-#!/usr/bin/perl
-
-my $i=0;
-for ($i=0;$i<10000000;$i++)
-{
- print ("stuff\n");
-}
-
+++ /dev/null
-#!/usr/bin/python
-
-for i in range(1,10000000):
- print "stuff"
-
+++ /dev/null
-#!/usr/bin/ruby
-
-10000000.times { print "stuff","\n" }
-
+++ /dev/null
-#!/usr/bin/perl
-
-my $i=0;
-for ($i=0;$i<10000000;$i++)
-{
- print ("stuff1"," ","stuff2","\n");
-}
+++ /dev/null
-#!/usr/bin/python
-
-for i in range(1,10000000):
- print "stuff1","stuff2"
-
+++ /dev/null
-#!/usr/bin/ruby
-
-10000000.times { print "stuff1"," ","stuff2","\n" }
-
+++ /dev/null
-#include <stdio.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- for (i=0;i<RUNS;i++)
- {
- printf("stuff\n");
- }
- return 0;
-}
+++ /dev/null
-#include <stdio.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- for (i=0;i<RUNS;i++)
- {
- printf("%s %s\n","stuff2","stuff2");
- }
- return 0;
-}
+++ /dev/null
-#include <stdio.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- for (i=0;i<RUNS;i++)
- {
- puts("stuff");
- }
- return 0;
-}
+++ /dev/null
-#!/bin/bash
-./test-performance.sh all > test-results 2>&1
-./test-performance2.sh all > test-results2 2>&1
+++ /dev/null
-#!/bin/bash
-echo `grep "model name" /proc/cpuinfo |cut -f 2 -d :` `grep "cpu MHz" /proc/cpuinfo |cut -f 2 -d :` Mhz ` grep "bogomips" /proc/cpuinfo |cut -f 2 -d :` bogomips
-
-if [ "$1" == "all" ]
-then
- echo "------------------------------------------------------------- Ruby"
- cat print.rb
- echo -n "Running..."
- time ./print.rb > /dev/null
-
- echo "--------------------------------------------------- Python - range"
- cat print.py
- echo -n "Running..."
- time ./print.py > /dev/null
-
- echo "-------------------------------------------------- Python - xrange"
- cat xrange.py
- echo -n "Running..."
- time ./xrange.py > /dev/null
-
- echo "------------------------------------------------------------ PHP 5"
- cat echo.php
- echo -n "Running..."
- time ./echo.php > /dev/null
-fi
-
-echo "-------------------------------------------------- C - gcc - write"
-cat write.c
-echo -n "Compiling..."
-time gcc -O2 write.c -o write
-echo -n "Running..."
-time ./write > /dev/null
-
-echo "------------------------------------------------------------- Perl"
-cat print.pl
-echo -n "Running..."
-time ./print.pl > /dev/null
-
-echo "----------------------------------------------- C<<1 - gcc - print"
-cat cll1-print.c
-echo -n "Compiling..."
-time gcc -O2 cll1-print.c -o cll1-print
-echo -n "Running..."
-time ./cll1-print > /dev/null
-
-echo "---------------------------------------------- C - g++ - std::cout"
-cat cout.cpp
-echo -n "Compiling..."
-time g++ -O2 cout.cpp -o cout
-echo -n "Running..."
-time ./cout > /dev/null
-
-echo "----------------------------------------------- C<<1 - tcc - print"
-cat cll1-print.c
-echo -n "Compiling..."
-time tcc cll1-print.c -o cll1-print
-echo -n "Running..."
-time ./cll1-print > /dev/null
-
-echo "------------------------------------------------- C - tcc - printf"
-cat printf.c
-echo -n "Compiling..."
-time tcc printf.c -o printf
-echo -n "Running..."
-time ./printf > /dev/null
-
-echo "------------------------------------------------ C<<1 - tcc - echo"
-cat cll1-echo.c
-echo -n "Compiling..."
-time tcc cll1-echo.c -o cll1-echo
-echo -n "Running..."
-time ./cll1-echo > /dev/null
-
-echo "--------------------------------------------------- C - tcc - puts"
-cat puts.c
-echo -n "Compiling..."
-time tcc puts.c -o puts
-echo -n "Running..."
-time ./puts > /dev/null
-
-echo "------------------------------------------------- C - tcc - fwrite"
-cat fwrite.c
-echo -n "Compiling..."
-time tcc fwrite.c -o fwrite
-echo -n "Running..."
-time ./fwrite > /dev/null
-
-echo "-------------------------------------------------- C - tcc - fputs"
-cat fputs.c
-echo -n "Compiling..."
-time tcc fputs.c -o fputs
-echo -n "Running..."
-time ./fputs > /dev/null
-
-echo "------------------------------------------------ C<<1 - gcc - echo"
-cat cll1-echo.c
-echo -n "Compiling..."
-time gcc -O2 cll1-echo.c -o cll1-echo
-echo -n "Running..."
-time ./cll1-echo > /dev/null
-
-echo "------------------------------------------------- C - gcc - printf"
-cat printf.c
-echo -n "Compiling..."
-time gcc -O2 printf.c -o printf
-echo -n "Running..."
-time ./printf > /dev/null
-
-echo "--------------------------------------------------- C - gcc - puts"
-cat puts.c
-echo -n "Compiling..."
-time gcc -O2 puts.c -o puts
-echo -n "Running..."
-time ./puts > /dev/null
-
-echo "------------------------------------------------- C - gcc - fwrite"
-cat fwrite.c
-echo -n "Compiling..."
-time gcc -O2 fwrite.c -o fwrite
-echo -n "Running..."
-time ./fwrite > /dev/null
-
-echo "-------------------------------------------------- C - gcc - fputs"
-cat fputs.c
-echo -n "Compiling..."
-time gcc -O2 fputs.c -o fputs
-echo -n "Running..."
-time ./fputs > /dev/null
-
+++ /dev/null
-#!/bin/bash
-echo `grep "model name" /proc/cpuinfo |cut -f 2 -d :` `grep "cpu MHz" /proc/cpuinfo |cut -f 2 -d :` Mhz ` grep "bogomips" /proc/cpuinfo |cut -f 2 -d :` bogomips
-
-if [ "$1" == "all" ]
-then
- echo "------------------------------------------------------------- Ruby"
- cat print2.rb
- echo -n "Running..."
- time ./print2.rb > /dev/null
- echo
-
- echo "--------------------------------------------------- Python - range"
- cat print2.py
- echo -n "Running..."
- time ./print2.py > /dev/null
- echo
-
- echo "-------------------------------------------------- Python - xrange"
- cat xrange2.py
- echo -n "Running..."
- time ./xrange2.py > /dev/null
- echo
-
- echo "------------------------------------------------------------ PHP 5"
- cat echo2.php
- echo -n "Running..."
- time ./echo2.php > /dev/null
- echo
-fi
-
-echo "-------------------------------------------------- C - gcc - write"
-cat write2.c
-echo -n "Compiling..."
-time gcc -O2 write2.c -o write2
-echo -n "Running..."
-time ./write2 > /dev/null
-echo
-
-echo "---------------------------------------------- C - g++ - std::cout"
-cat cout2.cpp
-echo -n "Compiling..."
-time g++ -O2 cout2.cpp -o cout2
-echo -n "Running..."
-time ./cout2 > /dev/null
-echo
-
-echo "------------------------------------------------------------- Perl"
-cat print2.pl
-echo -n "Running..."
-time ./print2.pl > /dev/null
-echo
-
-echo "------------------------------------------------- C - tcc - printf"
-cat printf2.c
-echo -n "Compiling..."
-time tcc printf2.c -o printf2
-echo -n "Running..."
-time ./printf2 > /dev/null
-echo
-
-echo "------------------------------------------------- C - tcc - fwrite"
-cat fwrite2.c
-echo -n "Compiling..."
-time tcc fwrite2.c -o fwrite2
-echo -n "Running..."
-time ./fwrite2 > /dev/null
-echo
-
-echo "----------------------------------------------- C<<1 - tcc - print"
-cat cll1-print2.c
-echo -n "Compiling..."
-time tcc cll1-print2.c -o cll1-print2
-echo -n "Running..."
-time ./cll1-print2 > /dev/null
-echo
-
-echo "-------------------------------------------------- C - tcc - fputs"
-cat fputs2.c
-echo -n "Compiling..."
-time tcc fputs2.c -o fputs2
-echo -n "Running..."
-time ./fputs2 > /dev/null
-echo
-
-echo "------------------------------------------------- C - gcc - printf"
-cat printf2.c
-echo -n "Compiling..."
-time gcc -O2 printf2.c -o printf2
-echo -n "Running..."
-time ./printf2 > /dev/null
-echo
-
-echo "------------------------------------------------- C - gcc - fwrite"
-cat fwrite2.c
-echo -n "Compiling..."
-time gcc -O2 fwrite2.c -o fwrite2
-echo -n "Running..."
-time ./fwrite2 > /dev/null
-echo
-
-echo "----------------------------------------------- C<<1 - gcc - print"
-cat cll1-print2.c
-echo -n "Compiling..."
-time gcc -O2 cll1-print2.c -o cll1-print2
-echo -n "Running..."
-time ./cll1-print2 > /dev/null
-echo
-
-echo "-------------------------------------------------- C - gcc - fputs"
-cat fputs2.c
-echo -n "Compiling..."
-time gcc -O2 fputs2.c -o fputs2
-echo -n "Running..."
-time ./fputs2 > /dev/null
+++ /dev/null
-AMD Athlon(tm) XP 1259.392 Mhz 2520.58 bogomips
-------------------------------------------------------------- Ruby
-#!/usr/bin/ruby
-
-10000000.times { print "stuff","\n" }
-
-Running...
-real 0m31.160s
-user 0m29.546s
-sys 0m1.548s
---------------------------------------------------- Python - range
-#!/usr/bin/python
-
-for i in range(1,10000000):
- print "stuff"
-
-Running...
-real 0m18.386s
-user 0m17.757s
-sys 0m0.308s
--------------------------------------------------- Python - xrange
-#!/usr/bin/python
-
-for i in xrange(1,10000000):
- print "stuff"
-
-Running...
-real 0m18.832s
-user 0m18.805s
-sys 0m0.024s
------------------------------------------------------------- PHP 5
-#!/usr/bin/php5 -q
-<?php
-for ( $i=0; $i<10000000; $i++ )
-{
- echo "stuff1\n";
-}
-?>
-Running...
-real 0m10.832s
-user 0m7.696s
-sys 0m2.544s
--------------------------------------------------- C - gcc - write
-#include <string.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- char *s1="stuff\n";
- int l1=strlen(s1);
-
- for (i=0;i<RUNS;i++)
- {
- write(1,s1,l1);
- }
- return 0;
-}
-Compiling...
-real 0m0.911s
-user 0m0.148s
-sys 0m0.036s
-Running...
-real 0m5.809s
-user 0m2.164s
-sys 0m3.648s
-------------------------------------------------------------- Perl
-#!/usr/bin/perl
-
-my $i=0;
-for ($i=0;$i<10000000;$i++)
-{
- print ("stuff\n");
-}
-
-Running...
-real 0m7.095s
-user 0m6.836s
-sys 0m0.004s
------------------------------------------------ C<<1 - gcc - print
-#include "cll1.h"
-
-program
-{
- repeat(10000000)
- print("stuff");
-}
-Compiling...
-real 0m0.521s
-user 0m0.304s
-sys 0m0.068s
-Running...
-real 0m2.108s
-user 0m2.104s
-sys 0m0.004s
----------------------------------------------- C - g++ - std::cout
-#include <iostream>
-
-#define RUNS 10000000UL
-int main()
-{
- unsigned long i;
- for (i=0;i<RUNS;i++)
- {
- std::cout << "stuff\n";
- }
- return 0;
-}
-Compiling...
-real 0m1.917s
-user 0m0.896s
-sys 0m0.084s
-Running...
-real 0m1.694s
-user 0m1.680s
-sys 0m0.016s
------------------------------------------------ C<<1 - tcc - print
-#include "cll1.h"
-
-program
-{
- repeat(10000000)
- print("stuff");
-}
-Compiling...
-real 0m0.125s
-user 0m0.016s
-sys 0m0.008s
-Running...
-real 0m2.884s
-user 0m2.884s
-sys 0m0.000s
-------------------------------------------------- C - tcc - printf
-#include <stdio.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- for (i=0;i<RUNS;i++)
- {
- printf("stuff\n");
- }
- return 0;
-}
-Compiling...
-real 0m0.011s
-user 0m0.004s
-sys 0m0.004s
-Running...
-real 0m1.734s
-user 0m1.732s
-sys 0m0.004s
------------------------------------------------- C<<1 - tcc - echo
-#include "cll1.h"
-
-program
-{
- unsigned long i;
- for_range(i,1,10000000)
- echo("stuff\n");
-}
-Compiling...
-real 0m0.021s
-user 0m0.016s
-sys 0m0.004s
-Running...
-real 0m1.365s
-user 0m1.360s
-sys 0m0.004s
---------------------------------------------------- C - tcc - puts
-#include <stdio.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- for (i=0;i<RUNS;i++)
- {
- puts("stuff");
- }
- return 0;
-}
-Compiling...
-real 0m0.016s
-user 0m0.012s
-sys 0m0.000s
-Running...
-real 0m1.115s
-user 0m1.108s
-sys 0m0.008s
-------------------------------------------------- C - tcc - fwrite
-#include <stdio.h>
-#include <string.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- char *s1="stuff\n";
- int l1=strlen(s1);
-
- for (i=0;i<RUNS;i++)
- {
- fwrite(s1,l1,1,stdout);
- }
- return 0;
-}
-Compiling...
-real 0m0.029s
-user 0m0.004s
-sys 0m0.008s
-Running...
-real 0m1.025s
-user 0m1.020s
-sys 0m0.004s
--------------------------------------------------- C - tcc - fputs
-#include <stdio.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- for (i=0;i<RUNS;i++)
- {
- fputs("stuff\n",stdout);
- }
- return 0;
-}
-Compiling...
-real 0m0.012s
-user 0m0.004s
-sys 0m0.008s
-Running...
-real 0m1.104s
-user 0m1.092s
-sys 0m0.012s
------------------------------------------------- C<<1 - gcc - echo
-#include "cll1.h"
-
-program
-{
- unsigned long i;
- for_range(i,1,10000000)
- echo("stuff\n");
-}
-Compiling...
-real 0m0.362s
-user 0m0.320s
-sys 0m0.040s
-Running...
-real 0m1.230s
-user 0m1.228s
-sys 0m0.004s
-------------------------------------------------- C - gcc - printf
-#include <stdio.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- for (i=0;i<RUNS;i++)
- {
- printf("stuff\n");
- }
- return 0;
-}
-Compiling...
-real 0m0.184s
-user 0m0.148s
-sys 0m0.036s
-Running...
-real 0m1.072s
-user 0m1.060s
-sys 0m0.012s
---------------------------------------------------- C - gcc - puts
-#include <stdio.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- for (i=0;i<RUNS;i++)
- {
- puts("stuff");
- }
- return 0;
-}
-Compiling...
-real 0m0.182s
-user 0m0.152s
-sys 0m0.032s
-Running...
-real 0m1.075s
-user 0m1.072s
-sys 0m0.000s
-------------------------------------------------- C - gcc - fwrite
-#include <stdio.h>
-#include <string.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- char *s1="stuff\n";
- int l1=strlen(s1);
-
- for (i=0;i<RUNS;i++)
- {
- fwrite(s1,l1,1,stdout);
- }
- return 0;
-}
-Compiling...
-real 0m0.197s
-user 0m0.164s
-sys 0m0.032s
-Running...
-real 0m0.968s
-user 0m0.956s
-sys 0m0.012s
--------------------------------------------------- C - gcc - fputs
-#include <stdio.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- for (i=0;i<RUNS;i++)
- {
- fputs("stuff\n",stdout);
- }
- return 0;
-}
-Compiling...
-real 0m0.183s
-user 0m0.156s
-sys 0m0.028s
-Running...
-real 0m0.970s
-user 0m0.964s
-sys 0m0.008s
+++ /dev/null
-AMD Athlon(tm) XP 1259.392 Mhz 2520.58 bogomips
-------------------------------------------------------------- Ruby
-#!/usr/bin/ruby
-
-10000000.times { print "stuff1"," ","stuff2","\n" }
-
-Running...
-real 0m50.940s
-user 0m49.107s
-sys 0m1.836s
-
---------------------------------------------------- Python - range
-#!/usr/bin/python
-
-for i in range(1,10000000):
- print "stuff1","stuff2"
-
-Running...
-real 0m25.547s
-user 0m25.230s
-sys 0m0.320s
-
--------------------------------------------------- Python - xrange
-#!/usr/bin/python
-
-for i in xrange(1,10000000):
- print "stuff1","stuff2"
-
-Running...
-real 0m26.269s
-user 0m26.254s
-sys 0m0.016s
-
------------------------------------------------------------- PHP 5
-#!/usr/bin/php5 -q
-<?php
-for ( $i=0; $i<10000000; $i++ )
-{
- echo "stuff1"." "."stuff2"."\n";
-}
-?>
-Running...
-real 0m18.649s
-user 0m14.449s
-sys 0m4.200s
-
--------------------------------------------------- C - gcc - write
-#include <string.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- char *s1="stuff1";
- char *s2="stuff2";
- int l1=strlen(s1);
- int l2=strlen(s2);
-
- for (i=0;i<RUNS;i++)
- {
- write(1,s1,l1);
- write(1," ",1);
- write(1,s2,l2);
- write(1,"\n",1);
- }
- return 0;
-}
-Compiling...
-real 0m0.188s
-user 0m0.164s
-sys 0m0.024s
-Running...
-real 0m21.353s
-user 0m7.572s
-sys 0m13.781s
-
----------------------------------------------- C - g++ - std::cout
-#include <iostream>
-
-#define RUNS 10000000UL
-int main()
-{
- unsigned long i;
- for (i=0;i<RUNS;i++) {
- std::cout << "stuff1" << " " << "stuff2" << std::endl;
- }
- return 0;
-}
-Compiling...
-real 0m0.986s
-user 0m0.904s
-sys 0m0.080s
-Running...
-real 0m14.836s
-user 0m10.425s
-sys 0m4.416s
-
-------------------------------------------------------------- Perl
-#!/usr/bin/perl
-
-my $i=0;
-for ($i=0;$i<10000000;$i++)
-{
- print ("stuff1"," ","stuff2","\n");
-}
-Running...
-real 0m14.115s
-user 0m13.005s
-sys 0m0.012s
-
-------------------------------------------------- C - tcc - printf
-#include <stdio.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- for (i=0;i<RUNS;i++)
- {
- printf("%s %s\n","stuff2","stuff2");
- }
- return 0;
-}
-Compiling...
-real 0m0.012s
-user 0m0.008s
-sys 0m0.004s
-Running...
-real 0m4.987s
-user 0m4.856s
-sys 0m0.032s
-
-------------------------------------------------- C - tcc - fwrite
-#include <stdio.h>
-#include <string.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- char *s1="stuff1";
- char *s2="stuff2";
- int l1=strlen(s1);
- int l2=strlen(s2);
-
- for (i=0;i<RUNS;i++)
- {
- fwrite(s1,l1,1,stdout);
- fwrite(" ",1,1,stdout);
- fwrite(s2,l2,1,stdout);
- fwrite("\n",1,1,stdout);
- }
- return 0;
-}
-Compiling...
-real 0m0.017s
-user 0m0.012s
-sys 0m0.004s
-Running...
-real 0m3.678s
-user 0m3.672s
-sys 0m0.004s
-
------------------------------------------------ C<<1 - tcc - print
-#include "cll1.h"
-
-program
-{
- repeat(10000000)
- print("stuff1","stuff2");
-}
-Compiling...
-real 0m0.022s
-user 0m0.016s
-sys 0m0.004s
-Running...
-real 0m4.853s
-user 0m4.836s
-sys 0m0.016s
-
--------------------------------------------------- C - tcc - fputs
-#include <stdio.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- for (i=0;i<RUNS;i++) {
- fputs("stuff1",stdout);
- fputs(" ",stdout);
- fputs("stuff2",stdout);
- fputs("\n",stdout);
- }
- return 0;
-}
-Compiling...
-real 0m0.012s
-user 0m0.008s
-sys 0m0.004s
-Running...
-real 0m4.065s
-user 0m4.040s
-sys 0m0.024s
-
-------------------------------------------------- C - gcc - printf
-#include <stdio.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- for (i=0;i<RUNS;i++)
- {
- printf("%s %s\n","stuff2","stuff2");
- }
- return 0;
-}
-Compiling...
-real 0m0.180s
-user 0m0.152s
-sys 0m0.028s
-Running...
-real 0m4.877s
-user 0m4.860s
-sys 0m0.020s
-
-------------------------------------------------- C - gcc - fwrite
-#include <stdio.h>
-#include <string.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- char *s1="stuff1";
- char *s2="stuff2";
- int l1=strlen(s1);
- int l2=strlen(s2);
-
- for (i=0;i<RUNS;i++)
- {
- fwrite(s1,l1,1,stdout);
- fwrite(" ",1,1,stdout);
- fwrite(s2,l2,1,stdout);
- fwrite("\n",1,1,stdout);
- }
- return 0;
-}
-Compiling...
-real 0m0.205s
-user 0m0.156s
-sys 0m0.048s
-Running...
-real 0m3.640s
-user 0m3.620s
-sys 0m0.020s
-
------------------------------------------------ C<<1 - gcc - print
-#include "cll1.h"
-
-program
-{
- repeat(10000000)
- print("stuff1","stuff2");
-}
-Compiling...
-real 0m0.378s
-user 0m0.336s
-sys 0m0.040s
-Running...
-real 0m4.457s
-user 0m4.448s
-sys 0m0.012s
-
--------------------------------------------------- C - gcc - fputs
-#include <stdio.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- for (i=0;i<RUNS;i++) {
- fputs("stuff1",stdout);
- fputs(" ",stdout);
- fputs("stuff2",stdout);
- fputs("\n",stdout);
- }
- return 0;
-}
-Compiling...
-real 0m0.190s
-user 0m0.172s
-sys 0m0.020s
-Running...
-real 0m2.556s
-user 0m2.544s
-sys 0m0.012s
+++ /dev/null
-#include <string.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- char *s1="stuff\n";
- int l1=strlen(s1);
-
- for (i=0;i<RUNS;i++)
- {
- write(1,s1,l1);
- }
- return 0;
-}
+++ /dev/null
-#include <string.h>
-
-#define RUNS 10000000UL
-int main (void)
-{
- unsigned long i;
- char *s1="stuff1";
- char *s2="stuff2";
- int l1=strlen(s1);
- int l2=strlen(s2);
-
- for (i=0;i<RUNS;i++)
- {
- write(1,s1,l1);
- write(1," ",1);
- write(1,s2,l2);
- write(1,"\n",1);
- }
- return 0;
-}
+++ /dev/null
-#!/usr/bin/python
-
-for i in xrange(1,10000000):
- print "stuff"
-
+++ /dev/null
-#!/usr/bin/python
-
-for i in xrange(1,10000000):
- print "stuff1","stuff2"
-
+++ /dev/null
-#include "cll1.h"
-
-program
-{
- int i=2;
-
- repeat(1)
- {
- print("This is demonstration, that nesting of C<<1 repeat(N) { ... } flow-control macro is completely safe:");
- repeat(i++)
- {
- echo("This loop is supposed to be repeated twice: ");
- repeat(i)
- {
- printf("[doing this %d times] ",i);
- }
- repeat(0)
- {
- printf("[doing this 0 times] ",i);
- }
- repeat(-1)
- {
- printf("[doing this -1 times] ",i);
- }
- repeat(1)
- {
- printf("[doing this 1 times] ",i);
- }
- print("... finished.");
- }
- }
- repeat(--i)
- {
- print("This loop is not nested and it is supposed to be repeated again just twice.");
- }
-}
+++ /dev/null
-#include "cll1.h"
-
-def_mem(Zaznam)
-{
- int i;
- str s;
- list(Zaznam);
-};
-
-program
-{
- Zaznam zaznam,zaznamy=NULL;
-
- print("5x insert(zaznam,zaznamy,order_by_int,i);");
- zaznam=get_mem(Zaznam);
- zaznam->i=1;
- zaznam->s="¾lu»ouèký kùò";
- insert(zaznam,zaznamy,order_by_int,i);
- zaznam=get_mem(Zaznam);
- zaznam->i=3;
- zaznam->s="Úpìl Ïábelské";
- insert(zaznam,zaznamy,order_by_int,i);
- zaznam=get_mem(Zaznam);
- zaznam->i=4;
- zaznam->s="ódy";
- insert(zaznam,zaznamy,order_by_int,i);
- zaznam=get_mem(Zaznam);
- zaznam->i=2;
- zaznam->s="Hlavono¾ec - H je pøed Ch";
- insert(zaznam,zaznamy,order_by_int,i);
- zaznam=get_mem(Zaznam);
- zaznam->i=5;
- zaznam->s="hurá - malé h";
- insert(zaznam,zaznamy,order_by_int,i);
- for_each(zaznam,zaznamy) printf("i=%d, s=%s\n",zaznam->i,zaznam->s);
-
- print("1x append(zaznam,zaznamy);");
- zaznam=get_mem(Zaznam);
- zaznam->i=0;
- zaznam->s="Chleba - písmeno Ch";
- append(zaznam,zaznamy);
- for_each(zaznam,zaznamy) printf("i=%d, s=%s\n",zaznam->i,zaznam->s);
-
- print("sort(zaznam,zaznamy,order_by_int_desc,i);");
- sort(zaznam,zaznamy,order_by_int_desc,i);
- for_each(zaznam,zaznamy) printf("i=%d, s=%s\n",zaznam->i,zaznam->s);
-
- print("sort(zaznam,zaznamy,order_by_str,s);");
- sort(zaznam,zaznamy,order_by_str,s);
- for_each(zaznam,zaznamy) printf("i=%d, s=%s\n",zaznam->i,zaznam->s);
-
- print("sort(zaznam,zaznamy,order_by_ascii,s);");
- sort(zaznam,zaznamy,order_by_ascii,s);
- for_each(zaznam,zaznamy) printf("i=%d, s=%s\n",zaznam->i,zaznam->s);
-
- print("remove(zaznam,zaznamy,zaznam->i==0);");
- remove(zaznam,zaznamy,zaznam->i==0);
- for_each(zaznam,zaznamy) printf("i=%d, s=%s\n",zaznam->i,zaznam->s);
-
- print("drop(zaznam,zaznamy);");
- drop(zaznam,zaznamy);
- for_each(zaznam,zaznamy) printf("i=%d, s=%s\n",zaznam->i,zaznam->s);
-}
+++ /dev/null
-#include "cll1.h"
-#define STRLEN 1024
-
-program
-{
- char *str;
- int i=0;
- string(str,STRLEN);
-
- shell("echo \"XXX\nYYY\nZZZ\"");
- input(str,STRLEN) printf("---> %s",str);
- puts("[EOF]");
-
- paste("A\nB\nC");
- input(str,STRLEN) printf("---> %s",str);
- puts("[EOF]");
-
- shell("ls");
- input(str,STRLEN) printf("%d ---> %s",i++,str);
- puts("[EOF]");
-
- shell("ls");
- system("wc -l");
- puts("[EOF]");
-
-}
+++ /dev/null
-#include "cll1.h"
-
-struct Passwd
-{
- char *username, *home, *shell;
- int uid, gid;
- list(Passwd);
-} *etcpasswd,*passwd;
-
-program
-{
- char *ptr;
- FILE *f;
- int col;
-
- parse("/etc/passwd")
- {
- col=1;
- suffix(ptr,_,'\n');
- split(ptr,_,':') switch(col++)
- {
- case 1: create(passwd,Passwd);passwd->username=ptr;break;
- case 3: passwd->uid=atoi(ptr);break;
- case 4: passwd->gid=atoi(ptr);break;
- case 6: passwd->home=ptr;break;
- case 7: passwd->shell=ptr;insert(passwd,etcpasswd,sort_by,username);break;
- }
- }
- done;
-
- puts("--------- /etc/passwd sorted by username ---------------");
- every(passwd,etcpasswd) printf("#%03d: %s\n",passwd->uid,passwd->username);
-
- puts("--------- /etc/passwd sorted by uid --------------------");
- sort(passwd,etcpasswd,order_by,uid);
- every(passwd,etcpasswd) printf("#%03d: %s\n",passwd->uid,passwd->username);
-}
+++ /dev/null
-#include "cll1.h"
-
-program
-{
- char *ptr;
-
- asprintf(&ptr,"%ld",123456789);
- printf("strlen(\"%s\")=%d\n",ptr,strlen(ptr));
-
- ptr=catf("%ld",123456789);
- printf("strlen(\"%s\")=%d\n",ptr,strlen(ptr));
-
-}
+++ /dev/null
-#include "cll1.h"
-
-program
-{
- const int kmen=28;
- int jehlici=0,vetev=0,stromecek=2;
-
- while(jehlici<=kmen)
- {
- repeat(kmen-jehlici) echo(" ");
- echo("/");
- repeat(jehlici<<1) if (jehlici<kmen && vetev<stromecek-1) then echo(" "); else echo("_");
- print("\\");
- if(++vetev<stromecek) then jehlici++; else jehlici-=vetev>>1,vetev=0,stromecek++;
- }
- repeat(kmen) echo(" ");
- print("||");
-}
+++ /dev/null
-#include "cll1.h"
-
-def_mem(Leaf)
-{
- int seq;
- array(Leaf);
-};
-
-program
-{
- Leaf leaf,root=NULL;
- int newkey;
- int seq=0;
- int odd=1;
-
- print("Input values:");
- for_ints(newkey, 8,1,-2,745,-32,-64,27,4,-300,0,300,40,-30,-40,400, 200 )
- {
- printf("%d. [%d]\n",seq,newkey);
-
- leaf=get_mem(Leaf);
- leaf->seq=seq++;
-
- //store(leaf,root,newkey) is declared as:
-
- //init
- leaf->__next=NULL;
- leaf->__seek=NULL;
- leaf->__key=newkey;
-
- //store new node without indexing, first
- insert(leaf,root,order_by_num,__key);
-
- //reindex B+ tree
- for(leaf=root;leaf->__next;leaf=leaf->__next)
- {
- //auto seek
- if(!leaf->__seek && leaf->__next)
- leaf->__seek=leaf->__next->__next;
-
- if(leaf->__key<=newkey)
- {
- if(leaf->__seek && leaf->__seek->__key>newkey) leaf->__seek=leaf->__seek->__next;
- }
- else
- {
- if(odd && leaf->__seek)
- {
- leaf->__seek==leaf->__seek->__next;
- }
- else
- {
- leaf->__seek=leaf->__next->__seek;
- leaf->__next->__seek=NULL;
- }
- odd=1-odd;
- }
- }
- }
-
- print("Values were stored as:");
- for_each(leaf,root)
- {
- printf("%d. [%d]",leaf->seq,leaf->__key);
- if (leaf->__seek)
- printf("-> %d. [%d]\n",leaf->__seek->seq,leaf->__seek->__key);
- else
- print("");
- }
-}
+++ /dev/null
-#!/bin/bash
-CONF="/etc/bake.conf"
-CLL1CC=`which gcc`
-CFLAGS="-std=c99 -Wall"
-DEBUG=n
-
-function debugecho
-{
- if [ $DEBUG == y ]
- then
- echo $1
- fi
-}
-
-if [ "$1" == "" ] || [ "$EXE" == "$1" ]
-then
- echo "Usage: bake source.c or bake target"
- exit
-else
- while [ "$1" != "" ]
- do
- EXE=`basename $1 .c`
- if [ $1 == $EXE ]
- then
- SRC=$EXE.c
- else
- SRC=$1
- fi
- debugecho "Filename: $SRC"
-
- LIBNAMES=`grep "^#define" $SRC|grep USE_LIBRARY_|cut -f 2 -d " "`
- if ! [ -z "$LIBNAMES" ]
- then
- debugecho "Libraries: $LIBNAMES"
- LIBS=""
- for F in $LIBNAMES
- do
- LIBS="$LIBS `grep $F $CONF|cut -f 2 -d \ `"
- done
- fi
-
- PRENAMES=`grep "^#define" $SRC|grep USE_PREPROCESSOR_|cut -f 2 -d " "`
- if ! [ -z "$PRENAMES" ]
- then
- debugecho "Precompilers: $PRENAMES"
- for F in $PRENAMES
- do
- CMD=`grep $F $CONF|cut -f 2 -d " "`
- gecho "$CMD"
- $CMD
- done
- fi
-
- CMD="$CLL1CC $SRC -o $EXE $CFLAGS $LIBS"
- echo "$CMD"
- $CMD
- shift
- done
-fi
+++ /dev/null
-#/usr/bin/bake is simple and powerful replacement for make
-USE_LIBRARY_MYSQL -lmysqlclient
-USE_LIBRARY_FASTCGI -lfcgi
-USE_PREPROCESSOR_CAKE /usr/bin/cake
-USE_POSTPROCESSOR_STRIP /usr/bin/strip
+++ /dev/null
-#include "cll1.h"
-
-program
-{
- int state = 0;
- string filename = NULL,line = NULL;
- file f = NULL;
-
-
- try
- {
- f = file_write("_cake.c");
- for_directory_filenames(filename,"./")
- {
- for_file_lines(line,filename)
- {
- for_chars(znak,line)
- {
- switch(znak)
- {
- case '<': state
- case '>':
- case '?':
- case 'C':
- case '%':
- case '{':
- case '}':
- default:
- }
- }
- }
- }
- }
-
- if_exception_switch
- {
- case ERROR_FILE:
-
- }
-}