| 1 | THIS FILE IS OBSOLETE !!! |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | C<<1: The Programming Language |
| 7 | ============================== |
| 8 | |
| 9 | Feedback: xchaos@arachne.cz |
| 10 | Homepage: http://gpl.arachne.cz |
| 11 | |
| 12 | Copyright (G) 2004 Michael Polak, x@n.cz |
| 13 | C<<1 is available under terms of GNU Lesser Public License (LGPL) |
| 14 | This file is available under terms of GNU Free Documentation License |
| 15 | |
| 16 | 1. Introduction |
| 17 | --------------- |
| 18 | |
| 19 | There are various extensions and definitions of classical C language, |
| 20 | for example object oriented "C++" and "Objective C", minimalistic C--, |
| 21 | proprietary C# used by .Net project, etc. Many other modern languages |
| 22 | |
| 23 | C<<1 is designed to work as "stylesheet" for very classical ANSI C, and |
| 24 | it was specificaly tested to work fine with GNU C Compiler gcc. There is |
| 25 | no special C<<1 compiler or interpreter; instead, you are expected to |
| 26 | include special header file called cll1.h the same way you would include |
| 27 | let's say string or I/O library implemented in standard C library. Except |
| 28 | that you don't need to link your executable with any special library, |
| 29 | neither staticaly nor dynamicaly, and you don't have to configure your gcc |
| 30 | or make to do so. |
| 31 | |
| 32 | #include <cll1.h> |
| 33 | |
| 34 | Or #include "cll1.h", if cll1.h is not installed in your /usr/include |
| 35 | directory. That'it. No linking, no initialization, allocation, or so. |
| 36 | |
| 37 | C<<1 can be used for dummy, structured or object oriented programing, |
| 38 | whatever method you prefere. C<<1 focuses mainly on adding new complex |
| 39 | semantic structures into C, rather than inventing brand new syntax or class |
| 40 | hieararchy, or providing set of pre-defined library functions. To allow |
| 41 | that, most of C<<1 functions are implemented as macros for C preprocessor. |
| 42 | |
| 43 | 2. Getting started |
| 44 | ------------------ |
| 45 | |
| 46 | #include <cll1.h> |
| 47 | |
| 48 | program |
| 49 | { |
| 50 | puts("Hello World!"); |
| 51 | } |
| 52 | |
| 53 | Of course, int main(int argc,void **argv) can be still used. In fact, |
| 54 | macro "program" doesn't do much more than that ! Following program prints |
| 55 | all arguments: |
| 56 | |
| 57 | program |
| 58 | { |
| 59 | char *ptr; |
| 60 | |
| 61 | arguments |
| 62 | { |
| 63 | thisargument(ptr); |
| 64 | puts(ptr); |
| 65 | } |
| 66 | else |
| 67 | puts("Bleeeeh, no arguments supplied... :-("); |
| 68 | } |
| 69 | |
| 70 | Well, don't be surprised with "else" after "arguments". This is not the |
| 71 | last time in C<<1, when you will see C keywords somewhere you don't expect |
| 72 | them. Of course, you would like to use it this way, I guess: |
| 73 | |
| 74 | program |
| 75 | { |
| 76 | char *ptr; |
| 77 | |
| 78 | arguments |
| 79 | { |
| 80 | argument("-?") printf("This is just help!\n"); |
| 81 | else argument("-f") { nextargument(ptr) printf("Forced argument: %s\n",ptr); } |
| 82 | else { thisargument(ptr); printf("Simple argument: %s \n",ptr); } |
| 83 | } |
| 84 | else |
| 85 | puts("Bleeeeh, no arguments supplied... :-("); |
| 86 | } |
| 87 | |
| 88 | 2. Where is my main() funciton ?! |
| 89 | --------------------------------- |
| 90 | |
| 91 | If you want to use int main(int argc,void **argv) { } instead of |
| 92 | program { }, it's ok. Being fan of Basic and not Pascal, I don't |
| 93 | like the program keyword at all. In fact, by avoiding "program" construct |
| 94 | and using standard main() declaration, you would be still able to access |
| 95 | most of C<<1 functionality, but for example not the arguments() structure |
| 96 | mentioned above. |
| 97 | |
| 98 | 3. Ok, let's go on |
| 99 | ------------------ |
| 100 | |
| 101 | This is some code to send e-mail using unix sendmail: |
| 102 | (ok, nothing special, same as "echo .... | sendmail ....") |
| 103 | |
| 104 | program |
| 105 | { |
| 106 | paste("From: me@here\nSubject: Here we go...\n\nblah blah blah") |
| 107 | system("/usr/sbin/sendmail someone@somewhere"); |
| 108 | } |
| 109 | |
| 110 | This program prints exactly 6th column of /etc/passwd file |
| 111 | (ok, nothing special, same as "cut -f 6 -d : /etc/passwd") |
| 112 | |
| 113 | program |
| 114 | { |
| 115 | char *ptr; |
| 116 | parse("/etc/passwd") |
| 117 | { |
| 118 | column(ptr,_,':',6); |
| 119 | if(ptr)puts(ptr); |
| 120 | } |
| 121 | done; |
| 122 | } |
| 123 | |
| 124 | But next program prints 1st and 6th column of /etc/passwd. |
| 125 | (What is equivalent in bash ?) |
| 126 | |
| 127 | program |
| 128 | { |
| 129 | char *ptr; |
| 130 | int i; |
| 131 | parse("/etc/passwd") |
| 132 | { |
| 133 | columns(ptr,_,':',i) switch(i) |
| 134 | { |
| 135 | case 1: printf("%s...",ptr); break; |
| 136 | case 6: puts(ptr); |
| 137 | } |
| 138 | } |
| 139 | done; |
| 140 | } |
| 141 | |
| 142 | |
| 143 | 4. Groups of C<<1 macros |
| 144 | ------------------------ |
| 145 | |
| 146 | ! - macro is available only when using "program" instead of "main()" |
| 147 | |
| 148 | I. Unconditional iterations - without else |
| 149 | |
| 150 | every |
| 151 | iterate |
| 152 | repeat ! |
| 153 | |
| 154 | II. Conditional iterations - else can happen once |
| 155 | |
| 156 | find |
| 157 | arguments ! |
| 158 | argument |
| 159 | nextargument |
| 160 | |
| 161 | III. Conditional iterations - else can happen many times |
| 162 | |
| 163 | search |
| 164 | valid_split |
| 165 | valid_columns |
| 166 | |
| 167 | IV. Weird iterations (with something special) |
| 168 | |
| 169 | parse - [fail] - done |
| 170 | |
| 171 | V. Standalone sequences - they look like function calls, but they are not. |
| 172 | |
| 173 | insert |
| 174 | append |
| 175 | push |
| 176 | remove |
| 177 | sort |
| 178 | shell |
| 179 | paste |
| 180 | column |
| 181 | valid_column |
| 182 | ... |
| 183 | |
| 184 | VI. Well behaved seqences - can be used anywhere where functions can. |
| 185 | |
| 186 | create |
| 187 | string |
| 188 | goto_* |
| 189 | prefix |
| 190 | suffix |
| 191 | ... |
| 192 | |
| 193 | 5. Forbidden namespace |
| 194 | ---------------------- |
| 195 | |
| 196 | Variables starting with _ (underscored) followed by one or more capital |
| 197 | characters (A-Z) are reserved as C<<1 private compile-time namespace. |
| 198 | |
| 199 | 6. Compile time errors |
| 200 | ---------------------- |
| 201 | |
| 202 | - parse error at end of input |
| 203 | |
| 204 | You probably forgot to close some macro which must be obligatory |
| 205 | terminated by another macro - as "parse error" message suggests, |
| 206 | it is likely to be error in macro "parse() { } [ fail ] { } done; " |
| 207 | |
| 208 | :-) |
| 209 | |
| 210 | 7. We apologize for inconvenience |
| 211 | --------------------------------- |
| 212 | |
| 213 | This documentation file is unfortunately incomplete. |
| 214 | HTML online documentation is comming soon ... sooner ... or later... |