From 61ad8a2bf9aa7260d047255ed2bc0d79c67b8078 Mon Sep 17 00:00:00 2001 From: xchaos Date: Sat, 2 Feb 2008 02:01:16 +0000 Subject: [PATCH] ok, let's start making sense now: typdef char * str; git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@54 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- cll1.h | 21 ++++++++++----------- demos/boolean.c | 4 ++-- demos/for_ints_strs.c | 2 +- demos/lists.c | 28 ++++++++++++++-------------- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/cll1.h b/cll1.h index b3c65a4..1d95db2 100644 --- a/cll1.h +++ b/cll1.h @@ -53,7 +53,7 @@ #include #endif /* .----------------------------------------------------------------------. - / 2. C<<1 then buddhist section, updated 2008-01-26 xCh. + / 1. C<<1 then buddhist section, updated 2008-02-01 xCh. '----------------------------------------------------------------------- */ #ifndef DISABLE_MODULE_THEN_BUDDHISM #define then @@ -61,25 +61,27 @@ #define WHOKNOWS (int)(srandom((unsigned)time(NULL)),random()%2) #define create_var(ID,TYPE,EXPR) TYPE ID=(EXPR) #define def_var(ID,TYPE) TYPE ID -//#define _CLL1_YES char *YES="TRUE\nYES\nJA\nOUI\nDA\nANO\nY\n1"; +//#define _CLL1_YES str YES="TRUE\nYES\nJA\nOUI\nDA\nANO\nY\n1"; //#define atob(EXPR) (word_in_stri(YES,(EXPR))?1:0) //#else -#define _CLL1_YES char *YES="TRUE"; +#define _CLL1_YES str YES="TRUE"; #define atob(EXPR) (eqi((EXPR),YES)?1:0) #endif /* .----------------------------------------------------------------------. - / 1. C<<1 almost then buddhist section, updated 2008-01-26 xCh. + / 2. C<<1 almost then buddhist section, updated 2008-02-02 xCh. '----------------------------------------------------------------------- */ +typedef char * str; +typedef FILE * file; +typedef int bool; #define not ! #define and && #define or || -#define bool int #define TRUE 1 #define FALSE 0 #define WEIRDINT (1<<(sizeof(int)*8-1)) #define btoa(EXPR) ((EXPR)?"TRUE":"FALSE") #define coalesce(VAR,EXPR) (VAR?VAR:(EXPR)) -#define _CLL1_GLOBALS char *NIL="NULL", *EOL="\n", *OFS=" ", *IFS=" \t\n"; unsigned RANDOM_SEED=0; +#define _CLL1_GLOBALS str NIL="NULL", EOL="\n", OFS=" ", IFS=" \t\n"; unsigned RANDOM_SEED=0; /* .----------------------------------------------------------------------. / 4. C<<1 data declaration and allocation, updated 2008-01-31 xCh. '----------------------------------------------------------------------- */ @@ -93,10 +95,6 @@ #define init_mem(...) _mem_##TYPE##_( _ARG2(__VA_ARGS__,,) - 0 ) #define construct_mem(TYPE) (struct TYPE *)_mem_##TYPE##_(void) { create_mem(this,TYPE);/* <-' */ _init_mem_##TYPE##_(this); return this; } _init_mem_##TYPE##_(this_is(TYPE)) #define create_list(ID1,I2,TYPE) create_mem(ID1,TYPE); struct TYPE *ID2=((ID1->__next=NULL),ID1) -#define create_str(ID,EXPR) char *ID=(EXPR) -#define new_str(ID,...) char *ID=_cll1_get_str(__VA_ARGS__,NIL) -#define def_str(ID) char *ID=NULL -#define get_str(...) _cll1_get_str(__VA_ARGS__,NIL) #define create_context(ID) create_mem(ID,_CTXAtom) #define def_context(ID) def_mem(ID,_CTXAtom) #define list(TYPE) struct TYPE *__next @@ -107,6 +105,7 @@ /* .----------------------------------------------------------------------. / 5. C<<1 string manipulation, updated 2008-01-26 xCh. '----------------------------------------------------------------------- */ +#define get_str(...) _cll1_get_str(__VA_ARGS__,NIL) #define eq(A,B) !_cll1_strcmp(A,B) #define eqi(A,B) !_cll1_strcmpi(A,B) #define in_str(A,B) _cll1_strstr(A,B) @@ -154,7 +153,7 @@ #define this_arg argv[_I] #define next_arg ((_I+11) #define switch_for_args for_args switch_str(this_arg) #define switch_str(STR) _NEW(S,STR) diff --git a/demos/boolean.c b/demos/boolean.c index ed44988..77d1967 100644 --- a/demos/boolean.c +++ b/demos/boolean.c @@ -4,7 +4,7 @@ program { const bool t = TRUE, f = FALSE; bool l, m = MAYBE; - def_str(s); + str s; print("TRUE and FALSE =", btoa(t and f) ); print("TRUE or FALSE =", btoa(t or f) ); @@ -17,6 +17,6 @@ program 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); + echo("\"", s, "\"\tmeans ", btoa(l), EOL); } } diff --git a/demos/for_ints_strs.c b/demos/for_ints_strs.c index e21987a..dbcc3d7 100644 --- a/demos/for_ints_strs.c +++ b/demos/for_ints_strs.c @@ -3,7 +3,7 @@ program { int i; - char *s; + 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); diff --git a/demos/lists.c b/demos/lists.c index e31102e..2cc0c52 100644 --- a/demos/lists.c +++ b/demos/lists.c @@ -3,7 +3,7 @@ mem Zaznam { int i; - char *j; + str s; list(Zaznam); }; @@ -14,42 +14,42 @@ program print("4x insert(zaznam,zaznamy,order_by,i);"); zaznam=get_mem(Zaznam); zaznam->i=1; - zaznam->j="ddd"; + zaznam->s="ddd"; insert(zaznam,zaznamy,order_by,i); zaznam=get_mem(Zaznam); zaznam->i=3; - zaznam->j="bbbbb"; + zaznam->s="bbbbb"; insert(zaznam,zaznamy,order_by,i); zaznam=get_mem(Zaznam); zaznam->i=4; - zaznam->j="e"; + zaznam->s="e"; insert(zaznam,zaznamy,order_by,i); zaznam=get_mem(Zaznam); zaznam->i=2; - zaznam->j="aaaa"; + zaznam->s="aaaa"; 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, s=%s\n",zaznam->i,zaznam->s); print("1x append(zaznam,zaznamy);"); zaznam=get_mem(Zaznam); zaznam->i=0; - zaznam->j="ccc"; + zaznam->s="ccc"; append(zaznam,zaznamy); - for_each(zaznam,zaznamy) printf("i=%d, j=%s\n",zaznam->i,zaznam->j); + for_each(zaznam,zaznamy) printf("i=%d, s=%s\n",zaznam->i,zaznam->s); print("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, s=%s\n",zaznam->i,zaznam->s); - print("sort(zaznam,zaznamy,sort_by,j);"); - sort(zaznam,zaznamy,sort_by,j); - for_each(zaznam,zaznamy) printf("i=%d, j=%s\n",zaznam->i,zaznam->j); + print("sort(zaznam,zaznamy,sort_by,s);"); + sort(zaznam,zaznamy,sort_by,s); + for_each(zaznam,zaznamy) printf("i=%d, s=%s\n",zaznam->i,zaznam->s); print("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, s=%s\n",zaznam->i,zaznam->s); print("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, s=%s\n",zaznam->i,zaznam->s); } -- 2.30.2