From: xchaos Date: Thu, 13 Dec 2007 01:55:16 +0000 (+0000) Subject: vyvojova verze 0.7alfa (dema ted nejsou funkci) X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=4a48705a32280d90f6f1005003e3d1f4abeb9de0;p=svn%2FCll1h%2F.git vyvojova verze 0.7alfa (dema ted nejsou funkci) git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@2 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- diff --git a/ABOUT b/ABOUT new file mode 100644 index 0000000..013639e --- /dev/null +++ b/ABOUT @@ -0,0 +1,105 @@ +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. + +============================================================================== +Your outside is in: +============================================================================== + +Well, if you are outside cll1.h... first, forget about all previouse versions of +cll1.h. First of all: the source code should look familiar and readable to +anyone, who have seen anything written in any sane programming language (which +means basicaly anything like Bash, Basic, C, Java, Javascript, Pascal, Perl, +PHP and Python and perhaps lot more). + +Let's see what we have and what you can use: + +1. This Is The Program - forget int main(...)! +---------------------- + +#include "cll1.h" + +program {...} + +2. This Is The String Pointer - just use it. +----------------------------- + +You don't have to declare "char *_;" - because we have done this for you +automagicaly. In C<<1, this is generic temporary character pointer, which +can be used to anything you need to do with strings. + +3. This Is The Ouput Statement - no comment :-) +------------------------------ + +print(string1, string2, ...); + +3. Dynamic lists - their declaration is complex, but their usage not. +---------------- + +struct ListType +{ + ... + list(ListType); +} *listmemeber,*listhead=NULL; + +create(listmember,ListType); +append(listmember,listhead); +find(listmember,listhead,expression); +remove(listmember,listhead,expression); +sort(listmember,listhead,key,) + +3. Iterations (cycles) without control variable - can be nested, of course +----------------------------------------------- + +do {...} loop; +repeat (const int howmanytimes) {...} + +4. New cool iterators (iteration expresions) for good old FOR cycle +------------------------------------------------------------------- + +for range (int controlvariable, const int from, const int to) {...} +for each (ListType *controlvariable, ListType *listhead) {...} +for chars (char controlvariable, const char *string) {...} +for lines (char *controlvariable, char *filename) {...} +for flines (char *controlvariable, FILE *filehandle) {...} + +5. - 6. Undefined - reserved for future use +----------------- + +7. Toys - everybody likes toys +------- + +spam (const int howmanytimes, const char *string); + +8. Obsolete - but still backwards compatible with previous versions... +----------- + +every (A,B) {...} -> for each(A,B) {...} +search (A,B,C) {...} -> for each(A,B) if (C) {...} + +9. Then Buddhism - you can use then, and, or, not and TRUE/FALSE constants. +---------------- + +if (expression) then {...} else {...} +if (not expression or expression and expression) then {...} else {...} + +...if you wish, THEN you can. Forget about C, if you don't like it. + +if (expression) {...} else {...} +if (! expression || expression && expression) {...} else {...} + +...if you don't wish, you don't have to. Go back to the C, if you want. + +============================================================================== +Your inside is out: +============================================================================== + +If you are inside l1.h... first, forget about all previouse versions of +cll1.h. I have changed lot of things dramaticaly. First of all, I found out, +that I really have to learn C basics first, before I can attempt to write +set of C language macros. C<<1 until version cca 0.6 seemed like a good +idea, until I have encoutered Python. Then I become enlightened: we don't +need thousand different iterators (eg. every,search,find, and so on). We +already have one very nice iterator, called for. We can just stick with this +meta-iterator like Python does, and we can have just different iteration macros +for different data types and structers... so this is the way diff --git a/cll1.h b/cll1.h index 10fe58c..4e01a9f 100644 --- a/cll1.h +++ b/cll1.h @@ -25,24 +25,30 @@ #include #include #include +#include +#include /* Section For Dummies part 1, updated 2004-05-07 by xCh. */ #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 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) -#define push(A,B) { if(A && A!=B) A->_next=B; B=A; } -#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; search(A,B,C) { if(_D)*_D=A->_next; else B=A->_next; free(A); } else _D=(void *)&(A->_next); } -#define drop(A,B) { for( A=B; A ; B=A, A=A->_next, free(B)); B=NULL; } +#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; 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. */ @@ -50,6 +56,12 @@ #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) () + /* EXP macros for Dummysort sequences, updated 2003-05-29 by xCh. */ #define order_by(K1,K2) (K1>K2) @@ -95,6 +107,14 @@ /* Section For Dummies part 2, updated 2004-05-07 by xCh. */ #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--) +#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 #define arguments if(argc>1) for(_I=1;_I_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"); + } + } + } + } +*/ +}