1 | %{ |
---|
2 | |
---|
3 | #define PICT_TOPSEP 3 |
---|
4 | #define PICT_BOTSEP 3 |
---|
5 | #define PICT_LEFTSEP 3 |
---|
6 | #define PICT_RIGHTSEP 3 |
---|
7 | #define PICT_VSEP 2 |
---|
8 | #define PICT_HSEP 2 |
---|
9 | |
---|
10 | #define PICT_MONTHHEIGHT 5 // police height |
---|
11 | #define PICT_MONTHWIDTH (10./3.) |
---|
12 | |
---|
13 | #define TASK_VSEP 2 |
---|
14 | #define TASK_BGC0 "red" |
---|
15 | #define TASK_BGC1 "yellow" |
---|
16 | |
---|
17 | #define DELIVRABLE_VSEP 1 |
---|
18 | #define DELIVRABLE_HEIGHT 3 |
---|
19 | #define DELIVRABLE_LABELWIDTH 15 |
---|
20 | #define DELIVRABLE_LABELHEIGHT DELIVRABLE_HEIGHT |
---|
21 | #define DELIVRABLE_TITLEWIDTH 25 |
---|
22 | #define DELIVRABLE_TITLEHEIGHT DELIVRABLE_HEIGHT |
---|
23 | #define DELIVRABLE_BOXHEIGHT (DELIVRABLE_HEIGHT-2) |
---|
24 | |
---|
25 | typedef struct _Tlivrable { |
---|
26 | int tn,stn,dn; // task, sub-task, number |
---|
27 | char v; // 0, 1, 2, ..., F |
---|
28 | char* title; |
---|
29 | int bm,em; // mois de bebut et de fin |
---|
30 | // this fields are filled by the program for data[tn][0][0][0] |
---|
31 | int task_line; |
---|
32 | double task_y; // top of task |
---|
33 | double task_dy; // bot of task is task_y+task_dy |
---|
34 | // this fields are filled by the program for data[tn][stn][dn][0] |
---|
35 | int del_bm,del_em; // mois de bebut et de fin cummule |
---|
36 | } Tlivrable; |
---|
37 | |
---|
38 | #define T_MAX 10 |
---|
39 | #define S_MAX 10 |
---|
40 | #define D_MAX 10 |
---|
41 | #define V_MAX 10 |
---|
42 | Tlivrable* data[T_MAX][S_MAX][D_MAX][V_MAX]; |
---|
43 | %} |
---|
44 | |
---|
45 | %option noyywrap |
---|
46 | |
---|
47 | %% |
---|
48 | int tn,stn,dn,v,bm,em; char* title; |
---|
49 | #.*\n ; |
---|
50 | T=[0-9]+ { tn=atoi(yytext+2); } |
---|
51 | T=D[0-9]+ { tn=atoi(yytext+3); } |
---|
52 | S=[0-9]+ { stn=atoi(yytext+2); } |
---|
53 | D=[0-9]+ { dn=atoi(yytext+2); } |
---|
54 | V=V. { v=yytext[3]; } |
---|
55 | DV=-VF { dn=0; v='F'; } |
---|
56 | DV= { dn=0; v='F'; } |
---|
57 | DV=-[0-9]-VF { dn=yytext[4]-'0'; v=yytext[yyleng-1]; } |
---|
58 | DV=-[0-9]-V[0-9] { dn=yytext[4]-'0'; v=yytext[yyleng-1]; } |
---|
59 | |
---|
60 | BM=[0-9]+ { bm=atoi(yytext+3); } |
---|
61 | EM=[0-9]+ { em=atoi(yytext+3); } |
---|
62 | TITLE=.*\n { |
---|
63 | char* pc=yytext+6; |
---|
64 | while ( *pc==' ' || *pc=='\t' ) pc+=1; |
---|
65 | title=strdup(pc); |
---|
66 | Tlivrable* p= (Tlivrable*) calloc(sizeof(*p),1); |
---|
67 | p->tn = tn; |
---|
68 | p->stn = stn; |
---|
69 | p->dn = dn; |
---|
70 | p->v = v; |
---|
71 | p->title = title; |
---|
72 | p->bm = bm; |
---|
73 | p->em = em; |
---|
74 | |
---|
75 | for (v=0; data[tn][stn][dn][v]!=0 ; v++); |
---|
76 | data[tn][stn][dn][v] = p; |
---|
77 | fprintf(stderr,"ADDED: %d %d %d %d\n",tn,stn,dn,v); |
---|
78 | {int i,tn=0; fprintf(stderr,"CURR:t=%d:: ",tn); for (i=0; i<S_MAX ; i++) fprintf(stderr,"%d:%p ",i,data[tn][i][0][0]); fprintf(stderr,"\n"); } |
---|
79 | } |
---|
80 | .|\n ; |
---|
81 | %% |
---|
82 | |
---|
83 | void prepare0() |
---|
84 | { |
---|
85 | int tn,stn,dn,v; |
---|
86 | int i0,i1,i; |
---|
87 | for (tn=0 ; tn<T_MAX ; tn++) |
---|
88 | for (stn=0; stn<S_MAX; stn++) { |
---|
89 | fprintf(stderr,"AVANT:t=%d:%d:: ",tn,stn); for (i=0; i<D_MAX ; i++) |
---|
90 | fprintf(stderr,"%d:%p ",i,data[tn][stn][i][0]); fprintf(stderr,"\n"); |
---|
91 | while (1) { |
---|
92 | for (i0=0 ; i0<D_MAX ; i0++) |
---|
93 | if (data[tn][stn][i0][0] == 0) break; |
---|
94 | for (i1=i0+1 ; i1<D_MAX ; i1++) |
---|
95 | if (data[tn][stn][i1][0] != 0) break; |
---|
96 | if (i1>=D_MAX) break; |
---|
97 | // shift |
---|
98 | for (i=0 ; (i1+i)<D_MAX ; i++) |
---|
99 | for (v=0;v<V_MAX;v+=1) { |
---|
100 | data[tn][stn][i0+i][v] = data[tn][stn][i1+i][v]; |
---|
101 | data[tn][stn][i1+i][v] = 0; |
---|
102 | } |
---|
103 | } |
---|
104 | fprintf(stderr,"AVANT:t=%d:%d:: ",tn,stn); for (i=0; i<D_MAX ; i++) |
---|
105 | fprintf(stderr,"%d:%p ",i,data[tn][stn][i][0]); fprintf(stderr,"\n"); |
---|
106 | } |
---|
107 | } |
---|
108 | void prepare1() |
---|
109 | { |
---|
110 | int tn,stn,dn,v; |
---|
111 | int i0,i1,i; |
---|
112 | for (tn=0 ; tn<T_MAX ; tn++) { |
---|
113 | fprintf(stderr,"AVANT:t=%d:: ",tn,i0,i1); for (i=0; i<S_MAX ; i++) fprintf(stderr,"%d:%p ",i,data[tn][i][0][0]); fprintf(stderr,"\n"); |
---|
114 | while (1) { |
---|
115 | for (i0=0 ; i0<S_MAX ; i0++) |
---|
116 | if (data[tn][i0][0][0] == 0) break; |
---|
117 | for (i1=i0+1 ; i1<S_MAX ; i1++) |
---|
118 | if (data[tn][i1][0][0] != 0) break; |
---|
119 | fprintf(stderr,"%d %d %d\n",tn,i0,i1); |
---|
120 | if (i1>=S_MAX) break; |
---|
121 | // shift |
---|
122 | for (i=0 ; (i1+i)<S_MAX ; i++) |
---|
123 | for (dn=0;dn<D_MAX;dn+=1) |
---|
124 | for (v=0;v<V_MAX;v+=1) { |
---|
125 | data[tn][i0+i][dn][v] = data[tn][i1+i][dn][v]; |
---|
126 | data[tn][i1+i][dn][v] = 0; |
---|
127 | } |
---|
128 | } |
---|
129 | fprintf(stderr,"APRES:t=%d:: ",tn,i0,i1); for (i=0; i<S_MAX ; i++) fprintf(stderr,"%d:%p ",i,data[tn][i][0][0]); fprintf(stderr,"\n"); |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | int task_line(int tn) |
---|
134 | { |
---|
135 | int stn,dn,v; |
---|
136 | int nblignes=0; |
---|
137 | for (stn=0 ; data[tn][stn][0][0]!=0 ; stn++) |
---|
138 | for (dn=0 ; data[tn][stn][dn][0]!=0 ; dn++) |
---|
139 | for (v=0 ; data[tn][stn][dn][v]!=0 ; v++) |
---|
140 | nblignes+=1; |
---|
141 | return nblignes; |
---|
142 | } |
---|
143 | |
---|
144 | void task_box(double pictwidth) |
---|
145 | { |
---|
146 | int tn; |
---|
147 | for ( tn=0 ; data[tn][0][0][0]!=0 ; tn++ ) { |
---|
148 | const char* color= (tn%2)!=0 ? TASK_BGC1 : TASK_BGC0 ; |
---|
149 | printf( |
---|
150 | "\\put(%.1f,%.1f){\\fcolorbox{black}{%s}{\\makebox(%5.1f,%5.1f){}}}\n", |
---|
151 | 0.0,data[tn][0][0][0]->task_y, |
---|
152 | color, |
---|
153 | pictwidth,data[tn][0][0][0]->task_dy |
---|
154 | ); |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|
158 | void month_grid(double x, double y, double dx, double dy) |
---|
159 | { |
---|
160 | int i; |
---|
161 | for (i=0 ; i<=36 ; i+=1,x+=PICT_MONTHWIDTH) { |
---|
162 | if ( (i%3)!=0 ) continue; |
---|
163 | printf( |
---|
164 | "\\put(%5.1f,%5.1f){\\line(0,1){%5.1f}}\\put(%5.1f,%5.1f){%d}\n", |
---|
165 | x,y,dy-PICT_MONTHWIDTH-PICT_VSEP, |
---|
166 | x-2,y+dy-PICT_MONTHHEIGHT, |
---|
167 | i |
---|
168 | ); |
---|
169 | } |
---|
170 | } |
---|
171 | |
---|
172 | double delivrable( |
---|
173 | double label_x, double box_x, double title_x, |
---|
174 | double y, |
---|
175 | int tn, int stn, int dn) |
---|
176 | { |
---|
177 | double y0; |
---|
178 | int v; |
---|
179 | double label_dx = DELIVRABLE_LABELWIDTH ; |
---|
180 | double label_dy = DELIVRABLE_LABELHEIGHT ; |
---|
181 | double boxx,box_dx; |
---|
182 | double box_dy = DELIVRABLE_BOXHEIGHT ; |
---|
183 | double title_dx = DELIVRABLE_LABELWIDTH ; |
---|
184 | double title_dy = DELIVRABLE_TITLEHEIGHT ; |
---|
185 | for (v=0 ; data[tn][stn][dn][v]!=0 ; v++) { |
---|
186 | Tlivrable* l=data[tn][stn][dn][v] ; |
---|
187 | y -= DELIVRABLE_HEIGHT; |
---|
188 | char label[100]; sprintf(label,"D%d-%d-%d-V%c",tn,stn,dn,l->v); |
---|
189 | printf("% Delivrable %d %d %d\n",tn,stn,dn); |
---|
190 | y0 = (DELIVRABLE_HEIGHT-DELIVRABLE_LABELHEIGHT)/2; |
---|
191 | printf("\\put(%.1f,%.1f)",label_x,y+y0); |
---|
192 | printf("{\\makebox(%.1f,%.1f)[l]{\\ganttlabelstyle{%s}}}\n", |
---|
193 | label_dx,label_dy,label); |
---|
194 | y0 = (DELIVRABLE_HEIGHT-DELIVRABLE_BOXHEIGHT)/2; |
---|
195 | boxx = box_x + l->bm*PICT_MONTHWIDTH ; |
---|
196 | box_dx = (l->em - l->bm) * PICT_MONTHWIDTH; |
---|
197 | printf("\\put(%.1f,%.1f)",boxx,y+y0); |
---|
198 | printf("{\\fcolorbox{black}{blue}{\\makebox(%.1f,%.1f){}}}\n", |
---|
199 | box_dx-2,box_dy); |
---|
200 | y0 = (DELIVRABLE_HEIGHT-DELIVRABLE_TITLEHEIGHT)/2; |
---|
201 | printf("\\put(%.1f,%.1f)",title_x,y+y0); |
---|
202 | printf("{\\makebox(%.1f,%.1f)[l]{\\gantttitlestyle{%s}}}\n", |
---|
203 | title_dx,title_dy,l->title); |
---|
204 | y -= DELIVRABLE_VSEP; |
---|
205 | } |
---|
206 | return y; |
---|
207 | } |
---|
208 | |
---|
209 | void task_delivrable(double label_x, double box_x, double title_x, int tn) |
---|
210 | { |
---|
211 | int stn,dn; |
---|
212 | double y = data[tn][0][0][0]->task_y+data[tn][0][0][0]->task_dy; |
---|
213 | for (stn=0 ; data[tn][stn][0][0]!=0 ; stn++) |
---|
214 | for (dn=0 ; data[tn][stn][dn][0]!=0 ; dn++) { |
---|
215 | y=delivrable(label_x,box_x,title_x,y,tn,stn,dn); |
---|
216 | } |
---|
217 | } |
---|
218 | |
---|
219 | int main() |
---|
220 | { |
---|
221 | int tn; |
---|
222 | double pictwidth, pictheight; |
---|
223 | double gantt_x,gantt_y; |
---|
224 | double gantt_dx,gantt_dy; |
---|
225 | |
---|
226 | double label_x,title_x; |
---|
227 | |
---|
228 | yylex(); |
---|
229 | prepare0(); |
---|
230 | prepare1(); |
---|
231 | |
---|
232 | pictheight=0 ; |
---|
233 | pictheight += PICT_BOTSEP ; |
---|
234 | for ( tn=0 ; data[tn][0][0][0]!=0 ; tn++ ); |
---|
235 | for ( tn=tn-1 ; tn>=0 ; tn-- ) { |
---|
236 | int nblines= task_line(tn); |
---|
237 | data[tn][0][0][0]->task_y = pictheight; |
---|
238 | data[tn][0][0][0]->task_line = nblines; |
---|
239 | data[tn][0][0][0]->task_dy = 0; |
---|
240 | data[tn][0][0][0]->task_dy += nblines*DELIVRABLE_HEIGHT; |
---|
241 | data[tn][0][0][0]->task_dy += (nblines-1)*DELIVRABLE_VSEP; |
---|
242 | pictheight += data[tn][0][0][0]->task_dy; |
---|
243 | pictheight += TASK_VSEP; |
---|
244 | } |
---|
245 | pictheight += PICT_MONTHHEIGHT; |
---|
246 | pictheight += PICT_TOPSEP ; |
---|
247 | gantt_y = PICT_BOTSEP ; |
---|
248 | gantt_dy = pictheight-PICT_TOPSEP-PICT_BOTSEP ; |
---|
249 | |
---|
250 | pictwidth=0; |
---|
251 | pictwidth += PICT_LEFTSEP; |
---|
252 | label_x = pictwidth; |
---|
253 | pictwidth += DELIVRABLE_LABELWIDTH; |
---|
254 | pictwidth += PICT_HSEP; |
---|
255 | gantt_x = pictwidth ; |
---|
256 | gantt_dx = 36*PICT_MONTHWIDTH ; |
---|
257 | pictwidth += gantt_dx ; |
---|
258 | pictwidth += PICT_HSEP; |
---|
259 | title_x = pictwidth; |
---|
260 | pictwidth += DELIVRABLE_TITLEWIDTH; |
---|
261 | pictwidth += PICT_RIGHTSEP; |
---|
262 | |
---|
263 | printf("\\setlength{\\unitlength}{1.0mm}\n"); |
---|
264 | printf("\\begin{picture}(%.1f,%.1f)\n",pictwidth,pictheight); |
---|
265 | task_box(pictwidth); |
---|
266 | month_grid(gantt_x,gantt_y,gantt_dx,gantt_dy); |
---|
267 | for ( tn=0 ; data[tn][0][0][0]!=0 ; tn++ ) { |
---|
268 | task_delivrable(label_x,gantt_x,title_x,tn); |
---|
269 | } |
---|
270 | printf("\\end{picture}\n"); |
---|
271 | |
---|
272 | return 0; |
---|
273 | } |
---|