serious bug fixed
[svn/Prometheus-QoS/.git] / cll1-0.6.2.h
1
2 /* C<<1 header file v0.6.2 - style sheet for ANSI C */
3 /* Please pronounce as "cee-shift-left-by-one" :) */
4
5 /* Copyright (G) 2004-2008 Michael xChaos Polak, x(at)n.cz
6
7 The C<<1 header file is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 The C<<1 header file is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to
19 Michael Polak, Svojsikova 7, 169 00 Praha 6 Czech Republic */
20
21
22 #ifndef __CLL1H__
23 #define __CLL1H__
24
25 #include <stdio.h>
26 #include <string.h>
27 #include <strings.h>
28 #include <malloc.h>
29 #include <stdlib.h>
30 #include <time.h>
31 #include <unistd.h>
32 #include <ctype.h>
33
34 /* Section For Dummies part 1, updated 2004-05-07 by xCh. */
35
36 #define not !
37 #define and &&
38 #define or ||
39 #define TRUE 1
40 #define FALSE 0
41 #define loop while(1)
42 #define iterate(VAR,FROM,TO) for(VAR=FROM; VAR <= TO; VAR++)
43 #define repeat(N) iterate(_i,1,N)
44
45 /* Dynamic list macros & sequences, updated 2003-05-29 by xCh. */
46
47 #define list(T) struct T *_next
48 #define create(A,T) (A=(struct T *)malloc(sizeof(struct T)),A->_next=NULL)
49 #define push(A,B) { if(A && A!=B) A->_next=B; B=A; }
50 #define append(A,B) { if(B) { void *N=A; A->_next=NULL; for_selected(A,B,!A->_next) {A->_next=N; break;}} else push(A,B); }
51 #define remove(A,B,C) { void **_D=NULL; for_selected(A,B,C) { if(_D)*_D=A->_next; else B=A->_next; free(A); } else _D=(void *)&(A->_next); }
52 #define drop(A,B) { for( A=B; A ; B=A, A=A->_next, free(B)); B=NULL; }
53
54 /* Dynamic list iterations and sequences, updated 2003-05-29 by xCh. */
55
56 #define for_each(A,B) for( A=B; A; A=A->_next)
57 #define for_selected(A,B,C) for_each(A,B) if(C)
58 #define if_exists(A,B,C) for_selected(A,B,C) break; if(A)
59
60 /* EXP macros for Dummysort sequences, updated 2003-05-29 by xCh. */
61
62 #define order_by(K1,K2) (K1>K2)
63 #define desc_order_by(K1,K2) (K1<K2)
64 #define sort_by(K1,K2) (strcasecmp(K1, K2)>0)
65 #define desc_sort_by(K1,K2) (strcasecmp(K1, K2)<0)
66 #define ascii_by(K1,K2) (strcmp(K1, K2)>0)
67 #define desc_ascii_by(K1,K2) (strcmp(K1, K2)<0)
68
69 /* Dummysort sequences, updated 2003-05-29 by xCh. */
70
71 #define insert(A,B,EXP,K) { if(B) { void **_L=NULL, *H=B; for_selected(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); }
72 #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); }
73
74 /* String macros & sequences, updated 2004-04-19 by xCh. */
75
76 #define eq(A,B) ((A) && (B) && !strcmp(A,B))
77 #define strcmpi(A,B) strcasecmp(A,B)
78 #define strlwr(A) {char *_S=A; while(_&&*_S){*_S=tolower(*_S);_S++;}}
79 #define strupr(A) {char *_S=A; while(_&&*_S){*_S=toupper(*_S);_S++;}}
80 #define string(S,L) (S=(char *)malloc(L),*S=0)
81 #define duplicate(A,B) if(A) { string(B,strlen(A)+1); strcpy(B,A); }
82 #define concatenate(A,B,C) if (A && B) { string(C,strlen(A)+strlen(B)+1); strcpy(C,A); strcat(C,B); }
83 #define suffix(A,B,C) (((A=strrchr(B,C))&&!(*(A++)=0))||(A=B))
84 #define prefix(A,B,C) ((A=B)&&(((B=strchr(B,C))&&!(*(B++)=0))||(B=A)))
85 #define gotoalpha(CHAR) if(CHAR)while(*CHAR && !isalpha(*CHAR))CHAR++
86 #define goto_alpha(CHAR) if(CHAR)while(*CHAR && !isalpha(*CHAR) && *CHAR!='_')CHAR++
87 #define gotoalnum(CHAR) if(CHAR)while(*CHAR && !isalnum(*CHAR))CHAR++
88 #define goto_alnum(CHAR) if(CHAR)while(*CHAR && !isalnum(*CHAR) && *CHAR!='_')CHAR++
89 #define skipalpha(CHAR) if(CHAR)while(*CHAR && isalpha(*CHAR))CHAR++
90 #define skip_alpha(CHAR) if(CHAR)while(*CHAR && (isalpha(*CHAR) || *CHAR=='_'))CHAR++
91 #define skipalnum(CHAR) if(CHAR)while(*CHAR && isalnum(*CHAR))CHAR++
92 #define skip_alnum(CHAR) if(CHAR)while(*CHAR && (isalnum(*CHAR) || *CHAR=='_'))CHAR++
93 #define skipspaces(CHAR) if(CHAR)while(*CHAR==' ')CHAR++
94 #define cutspaces(CHAR) if(CHAR){int _L=strlen(CHAR); while(--_L>0 && CHAR[_L]==' ')CHAR[_L]=0;}
95 #define gotochr(CHAR,C) if(CHAR)while(*CHAR && *CHAR!=C)CHAR++
96 #define tr(CHAR,B,C) {char *_S=CHAR; while(*_S){ if(*_S==B)*_S=C; _S++; }}
97 #define strswitch(CHAR) {char *_K=CHAR; FILE *_F=NULL; {{
98 #define stroption(STR) if(eq(STR,_K))
99 #define match(KEY,VAL) {char *_K=KEY, *_V=VAL; FILE *_F=NULL; {{
100 #define assign(STR,SETVAR) stroption(STR) SETVAR=_V
101
102 /* Section For Dummies part 2, updated 2004-05-07 by xCh. */
103
104 #define program int _I; int main(int argc, char **argv)
105 #define arguments if(argc>1) for(_I=1;_I<argc;_I++)
106 #define argument(A) if(eq(argv[_I],A))
107 #define thisargument(S) (S=argv[_I])
108 #define nextargument(S) if(_I+1<argc && (S=argv[++_I]))
109
110 /* I/O iterations, updated 2004-04-19 by xCh. */
111
112 #define fparse(S,L,F) for(fgets(S,L,F);*S && !feof(F);fgets(S,L,F))
113 #define input(S,L) fparse(S,L,stdin)
114 #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);}
115 #define parses(S,F) {FILE *_F=fopen(F,"r"); if(_F) { while(!feof(_F)) { fstring(S,_F);
116 #define parse(F) {char *_; FILE *_F=fopen(F,"r"); if(_F) { while(!feof(_F)) { fstring(_,_F);
117 #define fail }} else {{
118 #define done }} if(_F)fclose(_F);}
119 #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);}
120 #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);}
121 #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);}
122 #define lloption(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=atoll(_V); _=NULL;} free(_Q);}
123
124 /* Dynamic list advanced I/O, updated 2003-05-30 by xCh. */
125
126 #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;}
127 #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);}}
128
129 /* I/O sequences, updated 2003-05-29 by xCh. */
130
131 #define nullreopen(F) F=freopen("/dev/null","r",F)
132 #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]);}
133 #define shell(CMD) stdinredir(system(CMD))
134 #define paste(STR) stdinredir(fputs(STR,stdout))
135
136 /* String iterations, updated 2003-06-19 by xCh. */
137
138 #define split(A,B,C) for(prefix(A,B,C);A;(A!=B)&&prefix(A,B,C)||(A=NULL))
139 #define valid_split(A,B,C) split(A,B,C) if(*A)
140 #define columns(A,B,C,V) for(V=0,prefix(A,B,C);A;((A!=B)&&prefix(A,B,C)||(A=NULL)),V++)
141 #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)
142 #define column(A,B,C,V) { int _V; columns(A,B,C,_V) if(_V==V) break; }
143 #define valid_column(A,B,C,V) { int _V; valid_columns(A,B,C,_V) if(_V==V) break; }
144
145 /* Useful structures, updated 2003-05-29 by xCh. */
146
147 #define hashtable(TYPE,NAME,VALUE) struct TYPE { char *NAME; char *VALUE; list(TYPE); }
148 #define textfile(TYPE,LINE) struct TYPE { char *LINE; char _eoln; list(TYPE); }
149 #define date(S) { time_t _T; _T=time(NULL); duplicate(ctime(&_T),S); }
150
151 #endif
This page took 0.481955 seconds and 4 git commands to generate.