Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / sources / mbkal / alc_pars_l6.c
1 /*
2 * This file is part of the Alliance CAD System
3 * Copyright (C) Laboratoire LIP6 - Département ASIM
4 * Universite Pierre et Marie Curie
5 *
6 * Home page : http://www-asim.lip6.fr/alliance/
7 * E-mail support : mailto:alliance-support@asim.lip6.fr
8 *
9 * This library is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Library General Public License as published
11 * by the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
13 *
14 * Alliance VLSI CAD System is distributed in the hope that it will be
15 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17 * Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with the GNU C Library; see the file COPYING. If not, write to the Free
21 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 /*******************************************************************************
25 * *
26 * Tool : Parser al *
27 * Author(s) : Gregoire AVOT *
28 * Updates : June, 12th 1998 *
29 * Updates : June, 30th 1998 Create unique name on losig where no one *
30 * is provided. *
31 * *
32 *******************************************************************************/
33
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <string.h>
37 #include <unistd.h>
38 #include <stdarg.h>
39 #include <math.h>
40
41 #include MUT_H
42 #include MLO_H
43 #include RCN_H
44 #include MLU_H
45
46 /******************************************************************************/
47
48 #define MAL_CON 0x00000001
49 #define MAL_INS 0x00000002
50 #define MAL_TRS 0x00000004
51 #define MAL_WIR 0x00000008
52 #define MAL_CAP 0x00000010
53 #define MAL_CTC 0x00000020
54 #define MAL_SIG 0x00000040
55 #define MAL_EOF 0x00000080
56 #define MAL_HEA 0x00000100
57
58 /* Tampon de lecture */
59 #define MALBUFMAX 524288
60
61 /* ptype sur losig -> verification unicite du signal */
62 #define MALDEFINED 11223344
63
64 /* ptype sur losig -> nom unique */
65 #define SIGHT 199806301
66
67 typedef struct
68 {
69 char *name;
70 char type;
71 char dir;
72 losig_list *ptsig;
73 num_list *phcon;
74 } data_locon;
75
76 typedef struct
77 {
78 char *insname; /* namealloc */
79 char *modelename; /* namealloc */
80 chain_list *interface;
81 } data_loins;
82
83 /******************************************************************************/
84
85 int nbitem __P(( chain_list* ));
86 char decode_dir __P(( char*, char*, int ));
87 char decode_type __P(( char*, char*, int ));
88 losig_list* decode_sig __P(( lofig_list*, chain_list*, char*, int,
89 int
90 ));
91 lotrs_list* decode_trs __P(( lofig_list*, chain_list*, char*, int,
92 int
93 ));
94 int decode_int __P(( char*, char*, int ));
95 double decode_float __P(( char*, char*, int ));
96 data_locon* decode_locon __P(( lofig_list*, chain_list*, char*, int ));
97 lowire_list* decode_lowire __P(( losig_list*, chain_list*, char*, int ));
98 loctc_list* decode_loctc __P(( lofig_list*, chain_list*, char*, int ));
99 float decode_capa __P(( losig_list*, chain_list*, char*, int ));
100 int type_line __P(( chain_list*, char*, int ));
101 chain_list* read_line __P(( FILE*, char*, int ));
102 void free_line __P(( chain_list* ));
103 void mal_error __P((char *,...));
104 void chk_header __P(( chain_list*, char*, int ));
105 unsigned char decode_layer __P(( char*, char*, int ));
106 data_loins* decode_ins __P(( chain_list*, char*, int ));
107 loins_list* end_ins __P(( lofig_list*, lofig_list**, data_loins*,
108 char*, int
109 ));
110 void complete_ins __P(( lofig_list*, data_loins*, chain_list*,
111 char*, int
112 ));
113
114 /*** Macro and function for debug *********************************************/
115
116 /* Set the define 'ALDEBUG' will ENABLE debug mode */
117 /*
118 #define ALDEBUG
119 */
120
121 #ifdef ALDEBUG
122
123 chain_list* al_dbg_addchain
124 __P(( chain_list*, void*, int ));
125 void al_dbg_freechain
126 __P(( chain_list* ));
127 void al_dbg_chkchain
128 __P(( void ));
129 void al_dbg_init __P(( void ));
130
131 #define ALMAXCHAIN 1024
132
133 chain_list* al_chain_pt[ALMAXCHAIN];
134 int al_chain_lg[ALMAXCHAIN];
135
136 #define al_addchain( a, b ) al_dbg_addchain( a, b, __LINE__ )
137 #define al_freechain( a ) al_dbg_freechain( a )
138
139 #else
140
141 #define al_addchain( a, b ) addchain( a, b )
142 #define al_freechain( a ) freechain( a )
143
144 #endif
145
146 /******************************************************************************/
147
148 int nbitem( head )
149 chain_list *head;
150 {
151 chain_list *scan;
152 int count;
153
154 for( scan = head, count = 0 ; scan ; scan = scan->NEXT, count++ );
155 return( count );
156 }
157
158 /******************************************************************************/
159
160 char decode_dir( elem, fname, mal_line )
161 char *elem;
162 char *fname;
163 int mal_line;
164 {
165 if( strcasecmp( elem, "IN" ) == 0 ) return( 'I' );
166 if( strcasecmp( elem, "OUT" ) == 0 ) return( 'O' );
167 if( strcasecmp( elem, "INOUT" ) == 0 ) return( 'B' );
168 if( strcasecmp( elem, "UNKNOWN" ) == 0 ) return( 'X' );
169 if( strcasecmp( elem, "TRISTATE" ) == 0 ) return( 'Z' );
170 if( strcasecmp( elem, "TRANSCV" ) == 0 ) return( 'T' );
171
172 mal_error( fname, mal_line, "Bad direction [%s] for connector.\n", elem );
173
174 /* Never reach */
175 return 0;
176 }
177
178 /******************************************************************************/
179
180 char decode_type( elem, fname, mal_line )
181 char *elem;
182 char *fname;
183 int mal_line;
184 {
185 if( strcasecmp( elem, "INTERNAL" ) == 0 ) return( 'I' );
186 if( strcasecmp( elem, "EXTERNAL" ) == 0 ) return( 'E' );
187
188 mal_error( fname, mal_line, "Bad type [%s] for connector.\n", elem );
189
190 /* Never reach */
191 return 0;
192 }
193
194 /******************************************************************************/
195
196 float decode_capa( ptsig, line, fname, mal_line )
197 losig_list *ptsig;
198 chain_list *line;
199 char *fname;
200 int mal_line;
201 {
202 float capa;
203
204 if( nbitem( line ) != 1 )
205 mal_error( fname, mal_line, "Bad number of argument.\n");
206
207 if(!ptsig->PRCN)
208 addlorcnet( ptsig );
209
210 capa = (float)decode_float( (char*) line->DATA, fname, mal_line );
211 rcn_addcapa( ptsig, capa );
212
213 return capa;
214 }
215
216 /******************************************************************************/
217
218 data_loins* decode_ins( line, fname, mal_line )
219 chain_list *line;
220 char *fname;
221 int mal_line;
222 {
223 data_loins *newins;
224
225 if( nbitem( line ) != 2 )
226 mal_error( fname, mal_line, "Bad number of argument.\n");
227
228 newins = (data_loins*) mbkalloc( sizeof( data_loins ) );
229 newins->modelename = namealloc( (char*) line->DATA );
230 newins->insname = namealloc( (char*) line->NEXT->DATA );
231 newins->interface = NULL;
232
233 return( newins );
234 }
235
236 /******************************************************************************/
237
238 lotrs_list* decode_trs( ptfig, line, fname, mal_line, version )
239 lofig_list *ptfig;
240 chain_list *line;
241 char *fname;
242 int mal_line;
243 int version;
244 {
245 char type;
246 long w;
247 long l;
248 losig_list *drain;
249 losig_list *grid;
250 losig_list *source;
251 losig_list *bulk;
252 long xs;
253 long xd;
254 long ps;
255 long pd;
256 long x;
257 long y;
258 int phsource;
259 int phdrain;
260 int phgrid;
261 int phbulk;
262 lotrs_list *pttrs;
263 int n;
264 char *name;
265
266 n = nbitem( line );
267
268 /* Version 4 : type L W D G S XS XD PS PD X Y
269 * Version 5 : type L W D G S XS XD PS PD X Y [ nd ng ns ]
270 * Version 6 : type L W D G S B XS XD PS PD X Y [ nd ng ns nb ] nom
271 */
272
273 if( ( version == 6 && n != 14 && n != 18 ) ||
274 ( version == 5 && n != 12 && n != 15 ) ||
275 ( version == 4 && n != 12 ) )
276 mal_error( fname, mal_line, "Bad number of element (%d).\n", n );
277
278 type = -1;
279 if( strcasecmp( (char*)line->DATA, "P" ) == 0 ) type = TRANSP;
280 if( strcasecmp( (char*)line->DATA, "N" ) == 0 ) type = TRANSN;
281 if( type == -1 )
282 mal_error( fname,
283 mal_line,
284 "Unknown transistor type [%s].\n",
285 (char*)line->DATA
286 );
287 line = line->NEXT;
288
289 l = decode_float( (char*)line->DATA, fname, mal_line ) * (double)SCALE_X ;
290 line = line->NEXT;
291
292 w = decode_float( (char*)line->DATA, fname, mal_line ) * (double)SCALE_X ;
293 line = line->NEXT;
294
295 drain = givelosig( ptfig, decode_int( (char*)line->DATA, fname, mal_line ) );
296 line = line->NEXT;
297
298 grid = givelosig( ptfig, decode_int( (char*)line->DATA, fname, mal_line ) );
299 line = line->NEXT;
300
301 source = givelosig( ptfig, decode_int( (char*)line->DATA, fname, mal_line ) );
302 line = line->NEXT;
303
304 bulk = NULL;
305
306 if( version == 6 )
307 {
308 n = decode_int( (char*)line->DATA, fname, mal_line );
309 if( n )
310 bulk = givelosig( ptfig, n );
311
312 line = line->NEXT;
313 }
314
315 xs = decode_float( (char*)line->DATA, fname, mal_line ) * (double)SCALE_X ;
316 line = line->NEXT;
317
318 xd = decode_float( (char*)line->DATA, fname, mal_line ) * (double)SCALE_X ;
319 line = line->NEXT;
320
321 ps = decode_float( (char*)line->DATA, fname, mal_line ) * (double)SCALE_X ;
322 line = line->NEXT;
323
324 pd = decode_float( (char*)line->DATA, fname, mal_line ) * (double)SCALE_X ;
325 line = line->NEXT;
326
327 x = decode_float( (char*)line->DATA, fname, mal_line ) * (double)SCALE_X ;
328 line = line->NEXT;
329
330 y = decode_float( (char*)line->DATA, fname, mal_line ) * (double)SCALE_X ;
331 line = line->NEXT;
332
333 phdrain = 0;
334 phgrid = 0;
335 phsource = 0;
336 phbulk = 0;
337
338 if( version == 5 || version == 6 )
339 {
340 if( line && line->NEXT ) /* 3 or 4 physicals node are coming */
341 {
342 phdrain = decode_int( (char*)line->DATA, fname, mal_line );
343 line = line->NEXT;
344
345 phgrid = decode_int( (char*)line->DATA, fname, mal_line );
346 line = line->NEXT;
347
348 phsource = decode_int( (char*)line->DATA, fname, mal_line );
349 line = line->NEXT;
350
351 if( version == 6 )
352 {
353 phbulk = decode_int( (char*)line->DATA, fname, mal_line );
354 line = line->NEXT;
355 }
356 }
357 }
358
359 name = NULL;
360 if( version == 6 )
361 {
362 name = namealloc( (char*)line->DATA );
363 line = line->NEXT;
364 }
365
366 pttrs = addlotrs( ptfig, type, x, y, w, l, ps, pd, xs, xd,
367 grid, source, drain, bulk,
368 name
369 );
370
371 if( phdrain )
372 {
373 if( !pttrs->DRAIN->SIG->PRCN )
374 addlorcnet( pttrs->DRAIN->SIG );
375
376 setloconnode( pttrs->DRAIN, phdrain );
377 }
378
379 if( phgrid )
380 {
381 if( !pttrs->GRID->SIG->PRCN )
382 addlorcnet( pttrs->GRID->SIG );
383
384 setloconnode( pttrs->GRID, phgrid );
385 }
386
387 if( phsource )
388 {
389 if( !pttrs->SOURCE->SIG->PRCN )
390 addlorcnet( pttrs->SOURCE->SIG );
391
392 setloconnode( pttrs->SOURCE, phsource );
393 }
394
395 if( phbulk )
396 {
397 if( !pttrs->BULK->SIG->PRCN )
398 addlorcnet( pttrs->BULK->SIG );
399
400 setloconnode( pttrs->BULK, phbulk );
401 }
402
403 return( pttrs );
404 }
405
406 /******************************************************************************/
407
408 void complete_ins( ptfig, ins, line, fname, mal_line )
409 lofig_list *ptfig;
410 data_loins *ins;
411 chain_list *line;
412 char *fname;
413 int mal_line;
414 {
415 data_locon *ptcon;
416
417 ptcon = decode_locon( ptfig, line, fname, mal_line );
418 ptcon->name = namealloc( ptcon->name );
419
420 ins->interface = al_addchain( ins->interface, ptcon );
421 }
422
423 /******************************************************************************/
424
425 loctc_list* decode_loctc( ptfig, line, fname, mal_line )
426 lofig_list *ptfig;
427 chain_list *line;
428 char *fname;
429 int mal_line;
430 {
431 float capa;
432 int idxsig1;
433 int idxsig2;
434 losig_list *ptsig1;
435 losig_list *ptsig2;
436 int node1;
437 int node2;
438
439 if( nbitem( line ) != 5 )
440 mal_error( fname, mal_line, "Bad number of argument.\n");
441
442 capa = (float)decode_float( (char*)line->DATA, fname, mal_line );
443 line = line->NEXT;
444
445 idxsig1 = decode_int( (char*)line->DATA, fname, mal_line );
446 line = line->NEXT;
447
448 node1 = decode_int( (char*)line->DATA, fname, mal_line );
449 line = line->NEXT;
450
451 idxsig2 = decode_int( (char*)line->DATA, fname, mal_line );
452 line = line->NEXT;
453
454 node2 = decode_int( (char*)line->DATA, fname, mal_line );
455 line = line->NEXT;
456
457 ptsig1 = givelosig( ptfig, idxsig1 );
458 ptsig2 = givelosig( ptfig, idxsig2 );
459
460 if( !ptsig1->PRCN )
461 addlorcnet( ptsig1 );
462
463 if( !ptsig2->PRCN )
464 addlorcnet( ptsig2 );
465
466 return( addloctc( ptsig1, node1, ptsig2, node2, capa ) );
467 }
468
469 /******************************************************************************/
470
471 lowire_list* decode_lowire( ptsig, line, fname, mal_line )
472 losig_list *ptsig;
473 chain_list *line;
474 char *fname;
475 int mal_line;
476 {
477 int n1;
478 int n2;
479 int layer;
480 float r;
481 float c;
482 float x;
483 float y;
484 float dx;
485 float dy;
486 long lx;
487 long ly;
488 long ldx;
489 long ldy;
490
491 if( nbitem( line ) != 9 )
492 mal_error( fname, mal_line, "Bad number of argument.\n" );
493
494 if( !ptsig->PRCN )
495 addlorcnet( ptsig );
496
497 n1 = decode_int( line->DATA, fname, mal_line );
498 line = line->NEXT;
499
500 n2 = decode_int( line->DATA, fname, mal_line );
501 line = line->NEXT;
502
503 layer = 0;
504 line = line->NEXT;
505
506 r = (float)decode_float( line->DATA, fname, mal_line );
507 line = line->NEXT;
508
509 c = (float)decode_float( line->DATA, fname, mal_line );
510 line = line->NEXT;
511
512 x = (float)decode_float( line->DATA, fname, mal_line );
513 line = line->NEXT;
514
515 y = (float)decode_float( line->DATA, fname, mal_line );
516 line = line->NEXT;
517
518 dx = (float)decode_float( line->DATA, fname, mal_line );
519 line = line->NEXT;
520
521 dy = (float)decode_float( line->DATA, fname, mal_line );
522 line = line->NEXT;
523
524 lx = x * SCALE_X;
525 ly = y * SCALE_X;
526 ldx = dx * SCALE_X;
527 ldy = dy * SCALE_X;
528
529 return( addlowire( ptsig, 0, r, c, n1, n2 ) );
530 }
531
532 /******************************************************************************/
533
534 losig_list* decode_sig( ptfig, line, fname, mal_line, version )
535 lofig_list *ptfig;
536 chain_list *line;
537 char *fname;
538 int mal_line;
539 int version;
540 {
541 int idx;
542 losig_list *ptsig;
543 char type;
544 float capa;
545 char signame[256];
546 ht *htsigname;
547 long index;
548 char *ptallocsigname;
549 long i;
550 long j;
551 long k;
552
553 if( ( nbitem( line ) < 2 && version == 6 ) ||
554 ( nbitem( line ) < 3 && version == 5 ) ||
555 ( nbitem( line ) < 3 && version == 4 )
556 )
557 mal_error( fname, mal_line, "Incomplete line.\n" );
558
559 idx = decode_int( (char*)line->DATA, fname, mal_line );
560 line = line->NEXT;
561 ptsig = givelosig( ptfig, idx );
562
563 if( getptype( ptsig->USER, MALDEFINED ) )
564 mal_error( fname, mal_line, "Signal %d yet defined.\n", idx );
565
566 type = decode_type( (char*)line->DATA, fname, mal_line );
567 line = line->NEXT;
568
569 ptsig->TYPE = type;
570
571 if( version == 5 || version == 4 )
572 {
573 if(!ptsig->PRCN)
574 addlorcnet( ptsig );
575
576 capa = (float)decode_float( (char*) line->DATA, fname, mal_line );
577 rcn_addcapa( ptsig, capa );
578
579 line = line->NEXT;
580 }
581
582 htsigname = (ht*) ( getptype( ptfig->USER, SIGHT )->DATA );
583
584 if( line )
585 {
586 for( ; line ; line = line->NEXT )
587 {
588 ptsig->NAMECHAIN = addchain( ptsig->NAMECHAIN,
589 namealloc( (char*) line->DATA )
590 );
591 addhtitem( htsigname, ptsig->NAMECHAIN->DATA, 1 );
592 }
593 }
594 else
595 {
596 /* Le parser al ajoute un nom si le signal n'en possede pas deja.
597 * Bizare : ce n'est pas au parser de faire ce boulot.
598 */
599
600 sprintf( signame, "mbk_sig%ld", ptsig->INDEX );
601 ptallocsigname = namealloc( signame ) ;
602
603 if( gethtitem( htsigname, ptallocsigname ) != EMPTYHT )
604 {
605 /* En theorie, sur 11 caracteres, on arrive a 3E15 pour index.
606 * En pratique, on s'en fout.
607 */
608
609 index = 0;
610
611 do
612 {
613 sprintf( signame, "mbk_sig012345" );
614 j = 26*26*26*26*26 ;
615 k = index;
616 for( i = 5 ; i >= 0 ; i-- )
617 {
618 signame[12-i] = k / j + 'a' ;
619 k = k - ( ( k / j ) * j ) ;
620 j = j / 26 ;
621 }
622 ptallocsigname = namealloc( signame ) ;
623 index++;
624 }
625 while( gethtitem( htsigname, ptallocsigname ) != EMPTYHT );
626 }
627
628 ptsig->NAMECHAIN = addchain( ptsig->NAMECHAIN, ptallocsigname );
629 addhtitem( htsigname, ptsig->NAMECHAIN->DATA, 1 );
630 }
631
632 ptsig->USER = addptype( ptsig->USER, MALDEFINED, (void*)1 );
633 return( ptsig );
634 }
635
636 /******************************************************************************/
637
638 int decode_int( elem, fname, mal_line )
639 char *elem;
640 char *fname;
641 int mal_line;
642 {
643 long v;
644 char *stop;
645
646 v = strtol( elem, &stop, 10 );
647
648 if( *stop != '\0' )
649 mal_error( fname, mal_line, "Not an integer [%s].\n", elem );
650
651 return( (int) v );
652 }
653
654 /******************************************************************************/
655
656 double decode_float( elem, fname, mal_line )
657 char *elem;
658 char *fname;
659 int mal_line;
660 {
661 double v;
662 char *stop;
663
664 v = strtod( elem, &stop );
665
666 if( *stop != '\0' )
667 mal_error( fname, mal_line, "Not a float [%s].\n", elem );
668
669 return( v );
670 }
671
672 /******************************************************************************/
673
674 data_locon* decode_locon( ptfig, line, fname, mal_line )
675 lofig_list *ptfig;
676 chain_list *line;
677 char *fname;
678 int mal_line;
679 {
680 data_locon *newcon;
681
682 newcon = (data_locon*) mbkalloc( sizeof( data_locon ) );
683
684 if( nbitem( line ) < 4 )
685 mal_error( fname, mal_line, "Bad description of connector.\n" );
686
687 newcon->name = (char*) line->DATA;
688 line = line->NEXT;
689
690 newcon->dir = decode_dir( (char*) line->DATA, fname, mal_line );
691 line = line->NEXT;
692
693 newcon->type = decode_type( (char*) line->DATA, fname, mal_line );
694 line = line->NEXT;
695
696 /*
697 if( ptfig->MODE != 'C' )
698 {
699 */
700 newcon->ptsig = givelosig( ptfig, decode_int( (char*) line->DATA,
701 fname,
702 mal_line
703 )
704 );
705
706 newcon->ptsig->TYPE = 'E';
707 /*
708 }
709 */
710
711 line = line->NEXT;
712
713 newcon->phcon = NULL;
714 for( ; line ; line = line->NEXT )
715 newcon->phcon = addnum( newcon->phcon,
716 decode_int( (char*) line->DATA, fname, mal_line )
717 );
718
719 return( newcon );
720 }
721
722 /******************************************************************************/
723
724 int type_line( head, fname, mal_line )
725 chain_list *head;
726 char *fname;
727 int mal_line;
728 {
729 char *type;
730
731 type = (char*) head->DATA;
732
733 if( strcasecmp( type, "H" ) == 0 ) return ( MAL_HEA );
734 if( strcasecmp( type, "S" ) == 0 ) return ( MAL_SIG );
735 if( strcasecmp( type, "I" ) == 0 ) return ( MAL_INS );
736 if( strcasecmp( type, "C" ) == 0 ) return ( MAL_CON );
737 if( strcasecmp( type, "W" ) == 0 ) return ( MAL_WIR );
738 if( strcasecmp( type, "Q" ) == 0 ) return ( MAL_CAP );
739 if( strcasecmp( type, "K" ) == 0 ) return ( MAL_CTC );
740 if( strcasecmp( type, "T" ) == 0 ) return ( MAL_TRS );
741 if( strcasecmp( type, "EOF" ) == 0 ) return ( MAL_EOF );
742
743 mal_error( fname, mal_line, "Unknown element [%s].\n", type );
744
745 /* Never reach */
746 return 0;
747 }
748
749 /******************************************************************************/
750
751 chain_list* read_line( df, fname, mal_line )
752 FILE *df;
753 char *fname;
754 int mal_line;
755 {
756 char buffer[MALBUFMAX];
757 char word[MALBUFMAX];
758 int lg;
759 int onword;
760 int i;
761 int j=0;
762 char *elem;
763 chain_list *decomp;
764
765 decomp = NULL;
766
767 if( fgets( buffer, MALBUFMAX, df ) == NULL )
768 mal_error( fname, mal_line, "Error when reading input file.\n" );
769
770 if( feof(df) )
771 mal_error( fname, mal_line, "End of file before end of parsing.\n" );
772
773 lg = strlen( buffer );
774
775 if( lg == MALBUFMAX-1 )
776 mal_error( fname, mal_line, "Line exceed %d characters.\n", MALBUFMAX );
777
778 if( lg > 0 )
779 {
780 if( buffer[lg-1] != '\n' )
781 {
782 fflush( stdout );
783 fprintf( stderr, "Ligne non terminee par '\\n'.\n" );
784 fprintf( stderr, "\"%s\"\n", buffer );
785 }
786 }
787
788 onword = 0;
789
790 /* En tete de ligne : soit 'EOF', soit 'X '. L'espace apres le X est le
791 * seul qui doit etre pris en compte comme separateur. */
792 if( lg == 4 && strcmp( "EOF\n", buffer )==0 )
793 {
794 elem = (char*)mbkalloc( sizeof(char) * 4 );
795 strncpy( elem, buffer, 3 );
796 elem[3] = 0;
797 decomp = al_addchain( decomp, elem );
798 return( decomp );
799 }
800
801 /* decode le premier argument de type 'X ' */
802 if( buffer[1] != ' ' )
803 mal_error( fname, mal_line, "Bad type of line.\n" );
804
805 elem = (char*)mbkalloc( sizeof(char) * 2 );
806 elem[0] = buffer[0];
807 elem[1] = 0;
808 decomp = al_addchain( decomp, elem );
809
810 /* Decode le reste de la ligne */
811
812 for( i=2; i<lg; i++ )
813 {
814 if( ( buffer[i] >= 'A' && buffer[i] <= 'Z' ) ||
815 ( buffer[i] >= 'a' && buffer[i] <= 'z' ) ||
816 ( buffer[i] >= '0' && buffer[i] <= '9' ) ||
817 strchr( " <>[]._-|/", buffer[i] ) )
818 {
819 if( !onword )
820 {
821 onword = 1;
822 j = 0;
823 }
824 word[j++] = buffer[i];
825 }
826 else
827 {
828 if( onword ) /* On vient de terminer un mot */
829 {
830 word[j++] = 0;
831
832 elem = (char*)mbkalloc( j * sizeof(char) );
833 memcpy( elem, word, j );
834 decomp = al_addchain( decomp, elem );
835
836 onword = 0;
837 }
838
839 /* Ici si des symbols sont considérés comme des mots à part entière */
840 }
841 }
842
843 if( decomp == NULL )
844 mal_error( fname, mal_line, "Blank line.\n" );
845
846 return( reverse( decomp ) );
847 }
848
849 /******************************************************************************/
850
851 void free_line( head )
852 chain_list *head;
853 {
854 chain_list *trashing;
855
856 for( trashing = head ; trashing ; trashing = trashing->NEXT )
857 mbkfree( trashing->DATA );
858
859 al_freechain( head );
860 }
861
862 /******************************************************************************/
863
864 void mal_error( char *fname, ... )
865 {
866 va_list index;
867 char *fmt;
868 int line;
869
870 va_start( index, fname );
871 // fname = va_arg( index, char* );
872 line = va_arg( index, int );
873 fmt = va_arg( index, char* );
874
875 fflush( stdout );
876
877 fprintf( stderr,
878 "*** mbk error in loadlofig ( al ) file %s line %d ***\n",
879 fname,
880 line
881 );
882 vfprintf( stderr, fmt, index );
883
884 EXIT(1);
885 }
886
887 /******************************************************************************/
888
889 void chk_header( line, fname, mal_line )
890 chain_list *line;
891 char *fname;
892 int mal_line;
893 {
894 int type;
895
896 type = type_line( line, fname, mal_line );
897
898 if( type != MAL_HEA )
899 mal_error( fname, mal_line, "Can't find header.\n" );
900
901 if( ! line->NEXT || ! line->NEXT->NEXT )
902 mal_error( fname, mal_line, "Incomplete header.\n" );
903
904 if( strcasecmp( (char*) line->NEXT->DATA, fname ) != 0 )
905 mal_error( fname,
906 mal_line,
907 "Bad circuit name : %s insteated of %s.\n",
908 (char*) line->NEXT->DATA,
909 fname
910 );
911
912 if( strcasecmp( (char*) line->NEXT->NEXT->DATA, "L" ) != 0 )
913 mal_error( fname, mal_line, "Bad type of view (not logical).\n" );
914 }
915
916 /******************************************************************************/
917
918 loins_list* end_ins( ptfig, tetemodele, newins, fname, mal_line )
919 lofig_list *ptfig;
920 lofig_list **tetemodele;
921 data_loins *newins;
922 char *fname;
923 int mal_line;
924 {
925 lofig_list *ptmodele;
926 chain_list *scan;
927 chain_list *headsig;
928 locon_list *scancon;
929 num_list *scannum;
930 loins_list *ins;
931 data_locon *dtcon;
932 ht *htcon;
933 int nb;
934
935 ptmodele = getlomodel( *tetemodele, newins->modelename );
936 if( !ptmodele )
937 {
938 *tetemodele = addlomodel( *tetemodele, newins->modelename );
939 ptmodele = *tetemodele;
940
941 /* Building connectors for new model */
942 for( scan = newins->interface ; scan ; scan = scan->NEXT )
943 addlocon( *tetemodele, ((data_locon*)scan->DATA)->name, NULL, 'X');
944 }
945
946 headsig = NULL;
947 /* Create losig in the same order of the locon in the model */
948
949 for( scancon = ptmodele->LOCON, nb = 0 ;
950 scancon ;
951 scancon = scancon->NEXT, nb++
952 );
953
954 htcon = addht( nb/10+1 );
955
956 for( scan = newins->interface; scan ; scan = scan->NEXT )
957 addhtitem( htcon, ((data_locon*)scan->DATA)->name, (long)(scan) );
958
959 for( scancon = ptmodele->LOCON ; scancon ; scancon = scancon->NEXT )
960 {
961 scan = (chain_list*)gethtitem( htcon, scancon->NAME );
962 if( ((long)(scan)) != EMPTYHT )
963 headsig = al_addchain( headsig, ((data_locon*)scan->DATA)->ptsig );
964 else
965 {
966 mal_error( fname,
967 mal_line,
968 "Bad interface for instance %s of model %s.\n",
969 newins->insname,
970 newins->modelename
971 );
972
973 }
974 }
975
976 delht( htcon );
977
978 headsig = reverse( headsig );
979
980 ins = addloins( ptfig, newins->insname, ptmodele, headsig );
981
982 newins->interface = reverse( newins->interface );
983 for( scan = newins->interface, scancon = ins->LOCON ;
984 scan ;
985 scan = scan->NEXT, scancon = scancon->NEXT
986 )
987 {
988 dtcon = (data_locon*)scan->DATA;
989 scancon->DIRECTION = dtcon->dir;
990
991 if( dtcon->phcon && !scancon->SIG->PRCN )
992 addlorcnet( scancon->SIG );
993
994
995 for( scannum = dtcon->phcon ; scannum ; scannum = scannum->NEXT )
996 setloconnode( scancon, scannum->DATA );
997 }
998
999 al_freechain( headsig );
1000
1001 for( scan = newins->interface; scan ; scan = scan->NEXT )
1002 {
1003 freenum( ((data_locon*)(scan->DATA))->phcon );
1004 mbkfree( scan->DATA );
1005 }
1006
1007 al_freechain( newins->interface );
1008
1009 mbkfree( newins );
1010
1011 return( ins );
1012 }
1013
1014 /******************************************************************************/
1015
1016 void alcloadlofig6( ptfig, fname, mode, in, version )
1017 lofig_list *ptfig;
1018 char *fname;
1019 char mode;
1020 FILE *in;
1021 int version;
1022 {
1023 chain_list *line; /* line read from file */
1024 int type; /* type of line */
1025 int mal_line; /* line number in file */
1026 data_locon *newcon; /* data extract from object 'C' */
1027 locon_list *newlocon; /* new locon */
1028 losig_list *newlosig; /* new losig */
1029 num_list *scannum; /* to scan phcon */
1030 int compose=0; /* Valid elements for currents object */
1031 lofig_list *tetemodele; /* model list used */
1032 data_loins *newins; /* new instance */
1033 losig_list *scansig; /* to clean the USER field of losig */
1034 locon_list *figcon; /* for mode c : connector of lofig */
1035 ht *htsigname; /* create an unique name on losig */
1036
1037 #ifdef ALDEBUG
1038 al_dbg_init();
1039 #endif
1040
1041 mal_line = 1;
1042 line = NULL;
1043 tetemodele = NULL;
1044
1045
1046 ptfig->MODE = mode;
1047 htsigname = addht( 1024 );
1048 ptfig->USER = addptype( ptfig->USER, SIGHT, htsigname );
1049
1050
1051 /* check the name */
1052
1053 mal_line++;
1054 line = read_line( in, fname, mal_line );
1055 chk_header( line, fname, mal_line );
1056 free_line( line );
1057
1058 /* externals connectors */
1059
1060 figcon = ptfig->LOCON;
1061
1062 do
1063 {
1064 mal_line++;
1065 line = read_line( in, fname, mal_line );
1066 type = type_line( line, fname, mal_line );
1067
1068 if( type == MAL_CON )
1069 {
1070 newcon = decode_locon( ptfig, line->NEXT, fname, mal_line );
1071
1072 if( mode != 'C' )
1073 newlocon = addlocon( ptfig, newcon->name, newcon->ptsig, newcon->dir );
1074 else
1075 {
1076 newlocon = figcon;
1077 /*newlocon->SIG = newcon->ptsig;*/
1078 figcon = figcon->NEXT;
1079 }
1080
1081 if( mode != 'C' && newcon->phcon )
1082 {
1083 if( !newcon->ptsig->PRCN )
1084 addlorcnet( newcon->ptsig );
1085
1086 for( scannum = newcon->phcon ; scannum ; scannum = scannum->NEXT )
1087 setloconnode( newlocon, scannum->DATA );
1088 }
1089
1090 /* del the newcon */
1091 freenum( newcon->phcon );
1092 mbkfree( newcon );
1093
1094 free_line( line );
1095
1096 }
1097 }
1098 while( type == MAL_CON );
1099
1100
1101 /* Internal description of figure */
1102
1103 if( mode != 'P' )
1104 {
1105 while( type != MAL_EOF && type != MAL_CTC )
1106 {
1107 newlosig = NULL;
1108 newins = NULL;
1109
1110 switch( type )
1111 {
1112 case MAL_INS :
1113 compose = MAL_CON;
1114 newins = decode_ins( line->NEXT, fname, mal_line );
1115 break;
1116
1117 case MAL_TRS :
1118 compose = 0;
1119 decode_trs( ptfig, line->NEXT, fname, mal_line, version );
1120 break;
1121
1122 case MAL_SIG:
1123 if( version == 6 )
1124 compose = MAL_WIR | MAL_CAP ;
1125 else
1126 if( version == 5 )
1127 compose = MAL_WIR ;
1128 else
1129 compose = 0;
1130 newlosig = decode_sig( ptfig, line->NEXT, fname, mal_line, version );
1131 break;
1132
1133 default:
1134 /* erreur : element non reconnu. */
1135 mal_error( fname, mal_line, "Incorrect file structure.\n" );
1136 }
1137
1138 free_line( line );
1139
1140 mal_line++;
1141 line = read_line( in, fname, mal_line );
1142 type = type_line( line, fname, mal_line );
1143
1144 while ( type & compose )
1145 {
1146 if( newins )
1147 {
1148 complete_ins( ptfig, newins, line->NEXT, fname, mal_line );
1149 }
1150 else
1151 if( newlosig )
1152 {
1153 switch( type )
1154 {
1155 case MAL_WIR:
1156 decode_lowire( newlosig, line->NEXT, fname, mal_line );
1157 break;
1158 case MAL_CAP:
1159 decode_capa( newlosig, line->NEXT, fname, mal_line );
1160 break;
1161 }
1162 }
1163
1164 free_line( line );
1165 mal_line++;
1166 line = read_line( in, fname, mal_line );
1167 type = type_line( line, fname, mal_line );
1168 }
1169
1170 /* terminate current element */
1171 if( newins )
1172 end_ins( ptfig, &tetemodele, newins, fname, mal_line );
1173 }
1174
1175 if( version == 6 )
1176 {
1177 while( type == MAL_CTC )
1178 {
1179 decode_loctc( ptfig, line->NEXT, fname, mal_line );
1180
1181 free_line( line );
1182 mal_line++;
1183 line = read_line( in, fname, mal_line );
1184 type = type_line( line, fname, mal_line );
1185 }
1186 }
1187
1188 if( type != MAL_EOF )
1189 mal_error( fname, mal_line, "Incorrect file structure.\n" );
1190
1191 freelomodel( tetemodele );
1192 for( scansig = ptfig->LOSIG ; scansig ; scansig = scansig->NEXT )
1193 scansig->USER = delptype( scansig->USER, MALDEFINED );
1194 }
1195
1196 free_line( line );
1197
1198 delht( htsigname );
1199 ptfig->USER = delptype( ptfig->USER, SIGHT );
1200
1201 #ifdef ALDEBUG
1202 al_dbg_chkchain();
1203 #endif
1204
1205 lofigchain( ptfig );
1206 }
1207
1208
1209 /******* Function for debug ***************************************************/
1210
1211 #ifdef ALDEBUG
1212
1213 chain_list* al_dbg_addchain( head, data, ligne )
1214 chain_list *head;
1215 void *data;
1216 int ligne;
1217 {
1218 int i;
1219
1220 for( i=0 ; i < ALMAXCHAIN ; i++ )
1221 if( al_chain_lg[i] == 0 )
1222 break;
1223
1224 if( i == ALMAXCHAIN )
1225 {
1226 printf( "\n*** Debuggage AL : tableau al_chain plein.\n" );
1227 EXIT(1);
1228 }
1229
1230 al_chain_lg[i] = ligne;
1231 al_chain_pt[i] = addchain( head, data );
1232
1233 return( al_chain_pt[i] );
1234 }
1235
1236 void al_freechain( head )
1237 chain_list *head;
1238 {
1239 int i;
1240 chain_list *scan;
1241
1242 for( scan = head ; scan ; scan = scan->NEXT )
1243 {
1244 for( i = 0 ; i < ALMAXCHAIN ; i++ )
1245 if( al_chain_pt[i] == scan )
1246 break;
1247 if( i == ALMAXCHAIN )
1248 {
1249 printf( "\n*** Debuggage AL : chain_list a liberer non trouvee.\n" );
1250 EXIT(1);
1251 }
1252 al_chain_lg[i] = 0;
1253 }
1254 freechain( head );
1255 }
1256
1257 void al_dbg_chkchain( void )
1258 {
1259 int i;
1260
1261 for( i=0 ; i < ALMAXCHAIN ; i++ )
1262 {
1263 if( al_chain_lg[i] )
1264 printf( "*** Debuggage AL : Element alloue ligne %d non libere.\n",
1265 al_chain_lg[i]
1266 );
1267 }
1268 }
1269
1270 void al_dbg_init( void )
1271 {
1272 int i;
1273
1274 printf( "*** Parser al v6.03. Debug\n" );
1275 for( i=0 ; i<ALMAXCHAIN ; i++ )
1276 al_chain_lg[i]=0;
1277 }
1278 #endif