From: xchaos Date: Mon, 7 Jan 2008 01:38:42 +0000 (+0000) Subject: preliminary work on version 0.7.1 - WARNING, HIGHLY UNSTABLE ! X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=04a13a6fec5593523e15bd3567c573b7749b2609;p=svn%2FCll1h%2F.git preliminary work on version 0.7.1 - WARNING, HIGHLY UNSTABLE ! git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@4 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- diff --git a/ABOUT b/ABOUT index 013639e..6aed118 100644 --- a/ABOUT +++ b/ABOUT @@ -1,3 +1,6 @@ +THIS FILE IS UNFINISHED !!!! + + This file is called ABOUT, because it is, well... README, INSTALL, HOWTO, FAWQ, RTFM and maybe even manual, all in one file. So why not calling it ABOUT. diff --git a/cll1.h b/cll1.h index 3e09887..597a76a 100644 --- a/cll1.h +++ b/cll1.h @@ -1,8 +1,8 @@ - -/* C<<1 header file v0.7 - style sheet for ANSI C */ -/* Please pronounce as "cee-shift-left-by-one" :) */ - -/* Copyright (G) 2004-2007 Michael xChaos Polak, x(at)n.cz +/* ------------------------------------------------------------------- */ +/* C<<1 header file v0.7.1 - style sheet for ANSI C */ +/* CERL - Cumbersome Extraction and Report Language */ +/* ------------------------------------------------------------------- */ +/* 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 @@ -16,52 +16,71 @@ You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, write to - Michael Polak, Svojsikova 7, 169 00 Praha 6 Czech Republic */ - - + Michael Polak, Svojsikova 7, 169 00 Praha 6 Czech Republic */ +/* ------------------------------------------------------------------- */ #ifndef __CLL1H__ #define __CLL1H__ -#include #include +#include #include -#include -#include - -/* Section For Dummies part 1, updated 2004-05-07 by xCh. */ - +#include +#include +#ifdef USE_LIBRARY_MYSQL +#include +#endif +#ifdef USE_LIBRARY_FASTCGI +#include +#else +#include +#endif +/* ------------------------------------------------------------------- */ +/* 1. C<<1 constants and optional keywords, updated 2008-01-07 by xCh. */ +/* ------------------------------------------------------------------- */ +#define then #define not ! #define and && #define or || #define TRUE 1 #define FALSE 0 -#define loop while(1) -//#define iterate(VAR,FROM,TO) for(VAR=FROM; VAR <= TO; VAR++) -//#define repeat(N) iterate(_i,1,N) -#define repeat(N) _NEW_I for range(_I,1,N) - -/* Dynamic list macros & sequences, updated 2003-05-29 by xCh. */ - -#define list(T) struct T *_next -#define create(A,T) (A=(struct T *)malloc(sizeof(struct T)),A->_next=NULL) +/* ------------------------------------------------------------------- */ +/* 2. C<<1 data types - updated 2008-01-07 by xCh. */ +/* ------------------------------------------------------------------- */ +#define list(T) struct T *_next +#define tree(T) struct T *_next;struct T *_seek +#define create(A,T) (A=(struct T *)malloc(sizeof(struct T)),A->_next=NULL,A) #define push(A,B) ((A && A!=B)?A->_next=B:0,B=A) #define pop(A,B) (B?((A?free(A):0),A=B=B->_next):(A=NULL)) -#define append(A,B) if(B) { void *N=A; A->_next=NULL; search(A,B,!A->_next) {A->_next=N; break;}} else push(A,B); -#define remove(A,B,C) { void **_D=NULL; for each(A,B) if(C) { if(_D)*_D=A->_next; else B=A->_next; free(A);} else _D=(void *)&(A->_next); } +#define append(A,B) if(B) { void *N=A; A->_next=NULL; for_search(A,B,!A->_next) {A->_next=N; break;}} else push(A,B); +#define remove(A,B,C) { void **_D=NULL; for_search(A,B,C) { if(_D)*_D=A->_next; else B=A->_next; free(A); A=NULL;} else _D=(void *)&(A->_next); } #define drop(A,B) for( A=B; A || (B=NULL); B=A, A=A->_next, free(B) ) - -/* Dynamic list iterations and sequences, updated 2003-05-29 by xCh. */ - -#define every(A,B) for( A=B; A; A=A->_next) -#define search(A,B,C) every(A,B) if(C) -#define find(A,B,C) search(A,B,C) break; if(A) - -/* Enlightened iterations usable in for() , updated 2007-12-11 by xCh. */ - -#define range(VAR,FROM,TO) (VAR=FROM; VAR <= TO; VAR++) -#define each(A,B) ( A=B; A; A=A->_next) -#define lines(STR,F) () - +/* ------------------------------------------------------------------- */ +/* 3. C<<1 iterators - updated 2008-01-07 by xCh. */ +/* ------------------------------------------------------------------- */ +#define loop while(TRUE) +#define repeat(N) _NEW_I for_range(_I,1,N) +#define for_range(VAR,FROM,TO) for(VAR=FROM; FROM<=TO?VAR<=TO:VAR>=TO; FROM<=TO?VAR++:VAR--) +#define for_each(A,B) for(A=B; A; A=A->_next) +#define for_search(A,B,C) for_each(A,B) if(C) +/*to do: #define for_file_lines(STR,F) _NEW_F for() */ +#ifdef USE_LIBRARY_MYSQL +#define for_mysql_query_results(ROW,QUERY) _NEW_(_Ratom,_Rstack,_RStack)for(_Ratom->R=(mysql_query(_Matom->M,QUERY)?NULL:mysql_use_result(_Matom->M)),ROW=(_Ratom->R?mysql_fetch_row(_Ratom->R):NULL);ROW;ROW=mysql_fetch_row(_Ratom->R)) +#endif +#ifdef USE_LIBRARY_FASTCGI +#define while_fastcgi_accept while(FCGI_Accept()>=0) +#endif +/*obsolete #define every(A,B) for( A=B; A; A=A->_next) */ +/*obsolete #define search(A,B,C) every(A,B) if(C) */ +/*obsolete #define find(A,B,C) search(A,B,C) break; if(A) */ + +/* ------------------------------------------------------------------- */ +/* 4.C<<1 conditionals - updated 2008-01-07 by xCh. */ +/* ------------------------------------------------------------------- */ +#define if_exists(A,B,C) for_search(A,B,C) break; if(A) + +/* ------------------------------------------------------------------- */ +/* old - from version 0.6 */ +/* ------------------------------------------------------------------- */ /* EXP macros for Dummysort sequences, updated 2003-05-29 by xCh. */ #define order_by(K1,K2) (K1>K2) @@ -73,7 +92,7 @@ /* Dummysort sequences, updated 2003-05-29 by xCh. */ -#define insert(A,B,EXP,K) { if(B) { void **_L=NULL, *H=B; search(B,H,EXP(B->K,A->K)) { if(_L) {*_L=A; A->_next=B; } else push(A,H); break; } else _L=(void *)&(B->_next); if(!B)*_L=A; B=H; } else push(A,B); } +#define insert(A,B,EXP,K) { if(B) { void **_L=NULL, *H=B; for_search(B,H,EXP(B->K,A->K)) { if(_L) {*_L=A; A->_next=B; } else push(A,H); break; } else _L=(void *)&(B->_next); if(!B)*_L=A; B=H; } else push(A,B); } #define sort(A,B,EXP,K) { void *_C; A=B; B=NULL; do { _C=A->_next; A->_next=NULL; insert(A,B,EXP,K); A=_C; } while(_C); } /* String macros & sequences, updated 2004-04-19 by xCh. */ @@ -103,18 +122,31 @@ #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 - -/* Section For Dummies part 2, updated 2004-05-07 by xCh. */ - -#define program int _I; int main(int argc, char **argv) +/* ------------------------------------------------------------------- */ +/* Infrastructure, updated 2008-01-08 by xCh. */ +/* ------------------------------------------------------------------- */ +/* old #define program int _I; int main(int argc, char **argv) */ #define _ISTACK struct _IStack { int I; int _23; list(_IStack); } *_Iatom,*_Istack=NULL; #define _SSTACK struct _SStack { char *S; int _23; list(_SSTACK); } *_Satom,*_Sstack=NULL; #define _FSTACK struct _FStack { FILE *F; int _23; list(_FSTACK); } *_Fatom,*_Fstack=NULL; -#define program2 _ISTACK _SSTACK _FSTACK int main(int argc, char **argv) -#define _NEW_I for(create(_Iatom,_IStack),_Iatom->_23=1,push(_Iatom,_Istack);_Iatom->_23||pop(_Iatom,_Istack)&&0;_Iatom->_23--) +#ifdef USE_LIBRARY_MYSQL +#define _MSTACK struct _MStack { MYSQL *M; int _23; list(_MStack); } *_Matom,*_Mstack=NULL; +#define _RSTACK struct _RStack { MYSQL_RES *R; int _23; list(_RStack); } *_Ratom,*_Rstack=NULL; +#else +#define _MSTACK +#define _RSTACK +#endif +#define program _ISTACK _SSTACK _FSTACK _MSTACK _RSTACK int main(int argc, char **argv) + +#define _NEW_(ATOM,STACK,TYPE) (create(ATOM,TYPE),ATOM->_23=1,push(ATOM,STACK);ATOM->_23||pop(ATOM,STACK)&&0;ATOM->_23--) +#define _NEW_I for _NEW_(_Iatom,_Istack,_IStack) +//#define _NEW_I for(create(_Iatom,_IStack),_Iatom->_23=1,push(_Iatom,_Istack);_Iatom->_23||pop(_Iatom,_Istack)&&0;_Iatom->_23--) #define _NEW_S for(create(_Satom,_SStack),_Satom->_23=1,push(_Satom,_Sstack);_Satom->_23||pop(_Satom,_Sstack)&&0;_Satom->_23--) #define _I _Iatom->I #define _S _Satom->I + +/* Section For Dummies part 2, updated 2004-05-07 by xCh. */ + #define arguments if(argc>1) for(_I=1;_IK=_S; A->_eoln=TRUE; append(A,B);} done; A->_eoln=FALSE;} -#define save(A,B,F,K) {FILE *_F=fopen(F,"w"); if(_F) { every(A,B) {fputs(A->K,_F); if(A->_eoln) fputc('\n',_F);} fclose(_F);}} +/* obsolete #define load(A,B,F,T,K) {char *_S; parses(_S,F) { create(A,T); A->K=_S; A->_eoln=TRUE; append(A,B);} done; A->_eoln=FALSE;} */ +/* obsolete #define save(A,B,F,K) {FILE *_F=fopen(F,"w"); if(_F) { for_each(A,B) {fputs(A->K,_F); if(A->_eoln) fputc('\n',_F);} fclose(_F);}} */ /* I/O sequences, updated 2003-05-29 by xCh. */ @@ -160,4 +192,11 @@ #define textfile(TYPE,LINE) struct TYPE { char *LINE; char _eoln; list(TYPE); } #define date(S) { time_t _T; _T=time(NULL); duplicate(ctime(&_T),S); } +#ifdef USE_LIBRARY_MYSQL +/* ------------------------------------------------------------------- */ +/* MySQL Infrastructure and basic macros - updated 2007-12-19 by xCh. */ +/* ------------------------------------------------------------------- */ +#define mysql_connect(S,U,P,D) (create(_Matom,_MStack) && push(_Matom,_Mstack) && (_Matom->M=mysql_init(NULL)),(_Matom->M && mysql_real_connect(_Matom->M,S,U,P,D,0,NULL,0)?_Matom->M:NULL)) +#endif + #endif diff --git a/cll1.txt b/cll1.txt index cc1610c..5a37cc1 100644 --- a/cll1.txt +++ b/cll1.txt @@ -1,3 +1,7 @@ +THIS FILE IS OBSOLETE !!! + + + C<<1: The Programming Language ============================== diff --git a/demo.c b/demo.c deleted file mode 100644 index bbb8e0d..0000000 --- a/demo.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "cll1.h" - -program2 -{ - repeat(2) - { - printf("Tohle cele delam 2x:\n"); - repeat(3) printf("Tohle delam 3x...\n"); - } -/* - for(create(_Iatom,_IStack),_Iatom->_23=1,push(_Iatom,_Istack);_Iatom->_23||pop(_Iatom,_Istack)&&0;_Iatom->_23--) - { - printf("_Iatom->_23=[%d] _Iatom->I=[%d]\n",_Iatom->_23,_Iatom->I); - for range(_Iatom->I,1,2) - { - printf("Tohle cele delam 2x:\n"); - for(create(_Iatom,_IStack),_Iatom->_23=1,push(_Iatom,_Istack);_Iatom->_23||pop(_Iatom,_Istack)&&0;_Iatom->_23--) - { - printf("_Iatom->_23=[%d] _Iatom->I=[%d]\n",_Iatom->_23,_Iatom->I); - for range(_Iatom->I,1,3) - { - printf("Tohle delam 3x...\n"); - } - } - } - } -*/ -} diff --git a/demos/arguments1.c b/demos/arguments1.c index accd50d..6cd7bed 100644 --- a/demos/arguments1.c +++ b/demos/arguments1.c @@ -10,7 +10,7 @@ program arguments { thisargument(ptr); - if(*ptr=='-') + if(*ptr=='-') then { printf("Command line switch: -%c ",ptr[1]); nextargument(ptr); diff --git a/demos/hello.c b/demos/hello.c new file mode 100644 index 0000000..50a595d --- /dev/null +++ b/demos/hello.c @@ -0,0 +1,6 @@ +#include "cll1.h" + +program +{ + print("Hello ","world"," !\n"); +} diff --git a/demos/idmap.c b/demos/idmap.c index b9a8704..ff96319 100644 --- a/demos/idmap.c +++ b/demos/idmap.c @@ -45,10 +45,10 @@ program if(*ptr) { - find(id,ids,eq(id->str,ptr)) + if_exists(id,ids,eq(id->str,ptr)) { id->count++; - find(line,id->lines,line->n==l); + if_exists(line,id->lines,line->n==l); else { create(line,Line); @@ -85,10 +85,10 @@ program if(c) sort(id,ids,desc_order_by,count); - every(id,ids) + for_each(id,ids) { printf("%3dx %s",id->count,id->str); - every(line,id->lines) printf(" [%d]",line->n); + for_each(line,id->lines) printf(" [%d]",line->n); printf("\n"); } } diff --git a/demos/lists.c b/demos/lists.c index 33230c9..008e13b 100644 --- a/demos/lists.c +++ b/demos/lists.c @@ -8,56 +8,47 @@ struct Zaznam list(Zaznam); } *zaznam,*zaznamy=NULL; -program2 +program { puts("4x insert(zaznam,zaznamy,order_by,i);"); create(zaznam, Zaznam); zaznam->i=1; zaznam->j="ddd"; insert(zaznam,zaznamy,order_by,i); - create(zaznam, Zaznam); zaznam->i=3; zaznam->j="bbbbb"; insert(zaznam,zaznamy,order_by,i); - create(zaznam, Zaznam); zaznam->i=0; zaznam->j="e"; insert(zaznam,zaznamy,order_by,i); - create(zaznam, Zaznam); zaznam->i=2; zaznam->j="cc"; insert(zaznam,zaznamy,order_by,i); - - for each(zaznam,zaznamy) printf("i=%d, j=%s\n",zaznam->i,zaznam->j); + for_each(zaznam,zaznamy)printf("i=%d, j=%s\n",zaznam->i,zaznam->j); puts("1x append(zaznam,zaznamy);"); create(zaznam, Zaznam); zaznam->i=4; zaznam->j="aaa"; append(zaznam,zaznamy); - - for each(zaznam,zaznamy)printf("i=%d, j=%s\n",zaznam->i,zaznam->j); + for_each(zaznam,zaznamy)printf("i=%d, j=%s\n",zaznam->i,zaznam->j); puts("sort(zaznam,zaznamy,desc_order_by,i);"); sort(zaznam,zaznamy,desc_order_by,i); - - for each(zaznam,zaznamy)printf("i=%d, j=%s\n",zaznam->i,zaznam->j); + for_each(zaznam,zaznamy)printf("i=%d, j=%s\n",zaznam->i,zaznam->j); puts("sort(zaznam,zaznamy,desc_sort_by,j);"); sort(zaznam,zaznamy,desc_sort_by,j); - - for each(zaznam,zaznamy)printf("i=%d, j=%s\n",zaznam->i,zaznam->j); + for_each(zaznam,zaznamy)printf("i=%d, j=%s\n",zaznam->i,zaznam->j); puts("remove(zaznam,zaznamy,zaznam->i==1);"); remove(zaznam,zaznamy,zaznam->i==1); - - for each(zaznam,zaznamy)printf("i=%d, j=%s\n",zaznam->i,zaznam->j); + for_each(zaznam,zaznamy)printf("i=%d, j=%s\n",zaznam->i,zaznam->j); puts("drop(zaznam,zaznamy);"); drop(zaznam,zaznamy); - - for each(zaznam,zaznamy)printf("i=%d, j=%s\n",zaznam->i,zaznam->j); + for_each(zaznam,zaznamy)printf("i=%d, j=%s\n",zaznam->i,zaznam->j); } diff --git a/demos/repeat.c b/demos/repeat.c new file mode 100644 index 0000000..7e8622e --- /dev/null +++ b/demos/repeat.c @@ -0,0 +1,10 @@ +#include "cll1.h" + +program +{ + repeat(2) + { + printf("Tohle cele delam 2x:\n"); + repeat(3) printf("Tohle delam 3x...\n"); + } +} diff --git a/demos/strings.c b/demos/strings.c new file mode 100644 index 0000000..e2a479a --- /dev/null +++ b/demos/strings.c @@ -0,0 +1,13 @@ +#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)); + +} diff --git a/fastcgi/cll1.h b/fastcgi/cll1.h new file mode 120000 index 0000000..a4cde1a --- /dev/null +++ b/fastcgi/cll1.h @@ -0,0 +1 @@ +../cll1.h \ No newline at end of file diff --git a/fastcgi/fastcgi.c b/fastcgi/fastcgi.c new file mode 100644 index 0000000..2d141d8 --- /dev/null +++ b/fastcgi/fastcgi.c @@ -0,0 +1,16 @@ +#define USE_LIBRARY_FASTCGI +#include "cll1.h" + +program +{ + int count = 0; + while_fastcgi_accept + { + printf("Content-type: text/html\r\n" + "\r\n" + "FastCGI Hello!" + "

FastCGI Hello!

" + "Request number %d running on host %s\n", + ++count, getenv("SERVER_NAME")); + } +} diff --git a/mysql/cll1.h b/mysql/cll1.h new file mode 120000 index 0000000..a4cde1a --- /dev/null +++ b/mysql/cll1.h @@ -0,0 +1 @@ +../cll1.h \ No newline at end of file diff --git a/mysql/mysql.c b/mysql/mysql.c new file mode 100644 index 0000000..b314bbf --- /dev/null +++ b/mysql/mysql.c @@ -0,0 +1,15 @@ +#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!"); +} diff --git a/tools/bake b/tools/bake new file mode 100755 index 0000000..3b15bcd --- /dev/null +++ b/tools/bake @@ -0,0 +1,48 @@ +#!/bin/bash +CONF=/etc/bake.conf +CLL1CC=`which gcc` +EXE=`basename $1 .c` +DEBUG=n + +function debugecho +{ + if [ $DEBUG == y ] + then + echo $1 + fi +} + +if [ "$1" == "" ] || [ "$EXE" == "$1" ] +then + echo "Usage: bake filename.c" + exit +else + debugecho "Filename: $1" +fi + +LIBNAMES=`grep "^#define" $1|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" $1|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 $1 -o $EXE $LIBS" +echo "$CMD" +$CMD diff --git a/tools/bake.conf b/tools/bake.conf new file mode 100644 index 0000000..0dd65aa --- /dev/null +++ b/tools/bake.conf @@ -0,0 +1,5 @@ +#/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