verze 0.6 - obsolete
authorxchaos <xchaos@4bb87942-c103-4e5a-b51c-0ebff58f8515>
Thu, 13 Dec 2007 01:53:47 +0000 (01:53 +0000)
committerxchaos <xchaos@4bb87942-c103-4e5a-b51c-0ebff58f8515>
Thu, 13 Dec 2007 01:53:47 +0000 (01:53 +0000)
git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@1 4bb87942-c103-4e5a-b51c-0ebff58f8515

12 files changed:
cll1.h [new file with mode: 0644]
cll1.txt [new file with mode: 0644]
demos/arguments1.c [new file with mode: 0644]
demos/arguments2.c [new file with mode: 0644]
demos/cll1.h [new symlink]
demos/column.c [new file with mode: 0644]
demos/columns.c [new file with mode: 0644]
demos/idmap.c [new file with mode: 0644]
demos/lists.c [new file with mode: 0644]
demos/shell.c [new file with mode: 0644]
demos/split.c [new file with mode: 0644]
install [new file with mode: 0755]

diff --git a/cll1.h b/cll1.h
new file mode 100644 (file)
index 0000000..10fe58c
--- /dev/null
+++ b/cll1.h
@@ -0,0 +1,143 @@
+
+/* C<<1 header file v0.6 - style sheet for ANSI C  */
+/* Please pronounce as "cee-shift-left-by-one" :)  */
+
+/* Copyright (G) 2004 Michael xChaos Polak, x@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 the GNU C Library; if not, write to 
+   Michael Polak, Svojsikova 7, 169 00 Praha 6 Czech Republic */
+
+
+#ifndef __CLL1H__
+#define __CLL1H__
+
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+/* Section For Dummies part 1, updated 2004-05-07 by xCh. */
+
+#define not !
+#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)
+
+/* 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; }
+
+/* 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)
+
+/* EXP macros for Dummysort sequences, updated 2003-05-29 by xCh. */
+
+#define order_by(K1,K2) (K1>K2)
+#define desc_order_by(K1,K2) (K1<K2)
+#define sort_by(K1,K2) (strcasecmp(K1, K2)>0)
+#define desc_sort_by(K1,K2) (strcasecmp(K1, K2)<0)
+#define ascii_by(K1,K2) (strcmp(K1, K2)>0)
+#define desc_ascii_by(K1,K2) (strcmp(K1, K2)<0)
+
+/* 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 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. */
+
+#define eq(A,B) !strcmp(A,B)
+#define strcmpi(A,B) strcasecmp(A,B)
+#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 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 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 tr(CHAR,B,C) {char *_S=CHAR; while(*_S){ if(*_S==B)*_S=C; _S++; }}
+#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
+
+/* Section For Dummies part 2, updated 2004-05-07 by xCh. */
+
+#define program int _I; int main(int argc, char **argv)
+#define arguments if(argc>1) for(_I=1;_I<argc;_I++) 
+#define argument(A) if(eq(argv[_I],A))
+#define thisargument(S) (S=argv[_I])
+#define nextargument(S) if(_I+1<argc && (S=argv[++_I]))
+
+/* 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);  
+#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);}
+#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);}
+#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);}
+#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);}
+
+/* Dynamic list advanced I/O, updated 2003-05-30 by xCh. */
+
+#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;}
+#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);}}
+     
+/* 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))
+
+/* String iterations, updated 2003-06-19 by xCh. */
+
+#define split(A,B,C) for(prefix(A,B,C);A;(A!=B)&&prefix(A,B,C)||(A=NULL))
+#define valid_split(A,B,C) split(A,B,C) if(*A)
+#define columns(A,B,C,V) for(V=0,prefix(A,B,C);A;((A!=B)&&prefix(A,B,C)||(A=NULL)),V++)
+#define valid_columns(A,B,C,V) for(V=0,prefix(A,B,C);A;((A!=B)&&prefix(A,B,C))||(A=NULL)) if(*A&&++V)
+#define column(A,B,C,V) { int _V; columns(A,B,C,_V) if(_V==V) break; }
+#define valid_column(A,B,C,V) { int _V; valid_columns(A,B,C,_V) if(_V==V) break; }
+
+/* Useful structures, updated 2003-05-29 by xCh. */
+
+#define hashtable(TYPE,NAME,VALUE) struct TYPE { char *NAME; char *VALUE; list(TYPE); }
+#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); }
+
+#endif
diff --git a/cll1.txt b/cll1.txt
new file mode 100644 (file)
index 0000000..cc1610c
--- /dev/null
+++ b/cll1.txt
@@ -0,0 +1,210 @@
+
+C<<1: The Programming Language
+==============================
+
+Feedback: xchaos@arachne.cz
+Homepage: http://gpl.arachne.cz
+
+Copyright (G) 2004 Michael Polak, x@n.cz
+C<<1 is available under terms of GNU Lesser Public License (LGPL)
+This file is available under terms of GNU Free Documentation License
+
+1. Introduction
+---------------
+
+There are various extensions and definitions of classical C language,
+for example object oriented "C++" and "Objective C", minimalistic C--,
+proprietary C# used by .Net project, etc. Many other modern languages
+
+C<<1 is designed to work as "stylesheet" for very classical ANSI C, and
+it was specificaly tested to work fine with GNU C Compiler gcc. There is
+no special C<<1 compiler or interpreter; instead, you are expected to 
+include special header file called cll1.h the same way you would include
+let's say string or I/O library implemented in standard C library. Except
+that you don't need to link your executable with any special library,
+neither staticaly nor dynamicaly, and you don't have to configure your gcc
+or make to do so.
+
+#include <cll1.h>
+
+Or #include "cll1.h", if cll1.h is not installed in your /usr/include
+directory. That'it. No linking, no initialization, allocation, or so.
+
+C<<1 can be used for dummy, structured or object oriented programing,
+whatever method you prefere. C<<1 focuses mainly on adding new complex
+semantic structures into C, rather than inventing brand new syntax or class
+hieararchy, or providing set of pre-defined library functions. To allow
+that, most of C<<1 functions are implemented as macros for C preprocessor.
+
+2. Getting started
+------------------
+
+#include <cll1.h>
+
+program
+{
+ puts("Hello World!"); 
+}
+
+Of course, int main(int argc,void **argv) can be still used. In fact,
+macro "program" doesn't do much more than that ! Following program prints 
+all arguments:
+
+program
+{
+ char *ptr;
+ arguments
+ {
+  thisargument(ptr);
+  puts(ptr); 
+ }
+ else
+  puts("Bleeeeh, no arguments supplied... :-(");
+}
+
+Well, don't be surprised with "else" after "arguments". This is not the 
+last time in C<<1, when you will see C keywords somewhere you don't expect
+them. Of course, you would like to use it this way, I guess: 
+
+program
+{
+ char *ptr;
+ arguments
+ {
+  argument("-?") printf("This is just help!\n");
+  else argument("-f") { nextargument(ptr) printf("Forced argument: %s\n",ptr); }
+  else { thisargument(ptr); printf("Simple argument: %s \n",ptr); }
+ }
+ else
+  puts("Bleeeeh, no arguments supplied... :-(");
+}
+
+2. Where is my main() funciton ?!  
+---------------------------------
+
+If you want to use int main(int argc,void **argv) { } instead of 
+program { }, it's ok. Being fan of Basic and not Pascal, I don't
+like the program keyword at all. In fact, by avoiding "program" construct
+and using standard main() declaration, you would be still able to access 
+most of C<<1 functionality, but for example not the arguments() structure
+mentioned above.
+
+3. Ok, let's go on
+------------------
+
+This is some code to send e-mail using unix sendmail:
+(ok, nothing special, same as "echo .... | sendmail ....")
+
+program
+{
+ paste("From: me@here\nSubject: Here we go...\n\nblah blah blah")
+ system("/usr/sbin/sendmail someone@somewhere");
+}
+
+This program prints exactly 6th column of /etc/passwd file 
+(ok, nothing special, same as "cut -f 6 -d : /etc/passwd")
+
+program
+{
+ char *ptr;
+ parse("/etc/passwd")
+ {
+  column(ptr,_,':',6);
+  if(ptr)puts(ptr);
+ }
+ done;
+}
+
+But next program prints 1st and 6th column of /etc/passwd.
+(What is equivalent in bash ?)
+
+program
+{
+ char *ptr;
+ int i;
+ parse("/etc/passwd")
+ {
+  columns(ptr,_,':',i) switch(i)
+  {
+   case 1: printf("%s...",ptr); break;
+   case 6: puts(ptr);
+  }
+ }
+ done;
+}
+
+
+4. Groups of C<<1 macros 
+------------------------
+
+! - macro is available only when using "program" instead of "main()"
+
+I. Unconditional iterations - without else
+
+every
+iterate
+repeat !
+
+II. Conditional iterations - else can happen once
+
+find
+arguments !
+argument
+nextargument
+
+III. Conditional iterations - else can happen many times
+
+search
+valid_split
+valid_columns
+
+IV. Weird iterations (with something special)
+
+parse - [fail] - done
+
+V. Standalone sequences - they look like function calls, but they are not.
+
+insert
+append
+push
+remove
+sort
+shell
+paste
+column
+valid_column
+...
+
+VI. Well behaved seqences - can be used anywhere where functions can.
+
+create
+string
+goto_*
+prefix
+suffix
+...
+
+5. Forbidden namespace
+----------------------
+
+Variables starting with _ (underscored) followed by one or more capital
+characters (A-Z) are reserved as C<<1 private compile-time namespace.
+
+6. Compile time errors
+----------------------
+
+- parse error at end of input 
+
+You probably forgot to close some macro which must be obligatory
+terminated by another macro - as "parse error" message suggests, 
+it is likely to be error in macro "parse() { } [ fail ] { } done; "
+
+:-)
+
+7. We apologize for inconvenience
+---------------------------------
+
+This documentation file is unfortunately incomplete.
+HTML online documentation is comming soon ... sooner ... or later...
diff --git a/demos/arguments1.c b/demos/arguments1.c
new file mode 100644 (file)
index 0000000..accd50d
--- /dev/null
@@ -0,0 +1,24 @@
+#include "cll1.h"
+
+//try$ make arguments1
+//try$ ./arguments1 -x xxx yyyy -c cccc
+
+program
+{
+ char *ptr;
+ arguments
+ {
+  thisargument(ptr);
+  if(*ptr=='-')
+  {
+   printf("Command line switch: -%c ",ptr[1]);
+   nextargument(ptr);   
+   printf("followed by: %s\n",ptr);
+  }
+  else
+   printf("Simple argument: %s \n",ptr); 
+ }
+ else
+  puts("Bleeeeh, no arguments supplied... :-(");
+}
diff --git a/demos/arguments2.c b/demos/arguments2.c
new file mode 100644 (file)
index 0000000..3982e16
--- /dev/null
@@ -0,0 +1,18 @@
+#include "cll1.h"
+
+//try$ make arguments2
+//try$ ./arguments2 -f xxx yyyy -?
+
+program
+{
+ char *ptr;
+ arguments
+ {
+  argument("-?") printf("This is just help!\n");
+  else argument("-f") { nextargument(ptr) printf("Forced argument: %s\n",ptr); }
+  else { thisargument(ptr); printf("Simple argument: %s \n",ptr); }
+ }
+ else
+  puts("Bleeeeh, no arguments supplied... :-(");
+}
diff --git a/demos/cll1.h b/demos/cll1.h
new file mode 120000 (symlink)
index 0000000..a4cde1a
--- /dev/null
@@ -0,0 +1 @@
+../cll1.h
\ No newline at end of file
diff --git a/demos/column.c b/demos/column.c
new file mode 100644 (file)
index 0000000..764c635
--- /dev/null
@@ -0,0 +1,12 @@
+#include "cll1.h"
+
+program
+{
+ char *ptr;
+ parse("/etc/passwd")
+ {
+  column(ptr,_,':',6);
+  if(ptr)puts(ptr);
+ }
+ done;
+}
diff --git a/demos/columns.c b/demos/columns.c
new file mode 100644 (file)
index 0000000..9c6d9ce
--- /dev/null
@@ -0,0 +1,16 @@
+#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;
+}
diff --git a/demos/idmap.c b/demos/idmap.c
new file mode 100644 (file)
index 0000000..b9a8704
--- /dev/null
@@ -0,0 +1,94 @@
+#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)
+   {
+    find(id,ids,eq(id->str,ptr))
+    {
+     id->count++;
+     find(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);
+  
+ every(id,ids)
+ { 
+  printf("%3dx %s",id->count,id->str);
+  every(line,id->lines) printf(" [%d]",line->n);
+  printf("\n"); 
+ }
+}
diff --git a/demos/lists.c b/demos/lists.c
new file mode 100644 (file)
index 0000000..2c4218d
--- /dev/null
@@ -0,0 +1,54 @@
+
+#include "cll1.h"
+
+struct Zaznam
+{
+ int i;
+ char *j; 
+ list(Zaznam);
+} *zaznam,*zaznamy=NULL;
+
+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);
+ every(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);
+ every(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);
+ every(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);
+ every(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);
+ every(zaznam,zaznamy)printf("i=%d, j=%s\n",zaznam->i,zaznam->j);
+
+ puts("drop(zaznam,zaznamy);");
+ drop(zaznam,zaznamy);
+ every(zaznam,zaznamy)printf("i=%d, j=%s\n",zaznam->i,zaznam->j);
+}
diff --git a/demos/shell.c b/demos/shell.c
new file mode 100644 (file)
index 0000000..ee6accf
--- /dev/null
@@ -0,0 +1,26 @@
+#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]");
+
+}
diff --git a/demos/split.c b/demos/split.c
new file mode 100644 (file)
index 0000000..b79e3ca
--- /dev/null
@@ -0,0 +1,37 @@
+#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);
+}
diff --git a/install b/install
new file mode 100755 (executable)
index 0000000..1d208f1
--- /dev/null
+++ b/install
@@ -0,0 +1,3 @@
+#!/bin/bash
+echo Brute force install: copying cll1.h to /usr/include ...
+cp cll1.h /usr/include
This page took 0.284804 seconds and 4 git commands to generate.