1 /* ###--------------------------------------------------------------------### */
2 /* #                                                                        # */
3 /* # file : vel_vect.c                                                      # */
4 /* | date : Jun 03 1997                                                     | */
5 /* | version : 1.00                                                         | */
6 /* | author : Denis Hommais                                                 | */
7 /* |                                                                        | */
8 /* # contents : losig vectorization functions                               # */
9 /* #                                                                        # */
10 /* ###--------------------------------------------------------------------### */
11 /*
12  * $Log: vel_vect.c,v $
13  * Revision 1.1  2002/04/26 09:51:07  ludo
14  * Initial revision
15  *
16  * Revision 1.1.1.1  2002/04/11 08:54:53  fred
17  * Importing mbkvhdlg into the new Alliance CVS tree
18  *
19  * Revision 1.1.1.1  2002/02/28 12:58:31  disydent
20  * Creation of Disydent CVS Tree
21  *
22  * Revision 1.1.1.1  2001/11/19 16:55:27  pwet
23  * Changing the CVS tree structure of disydent
24  *
25  * Revision 1.1.1.1  2001/07/24 13:31:42  pwet
26  * cvs tree of part of disydent
27  *
28  * Revision 1.1.1.1  2001/07/19 14:32:20  pwet
29  * New cvs tree
30  *
31  * Revision 1.5  1998/11/12 10:39:27  pwet
32  * add makevelofig function.
33  *
34  * Revision 1.4  1998/01/06 09:54:50  denis
35  * rewrite vectlosig function. The new function take care of
36  * the good sequenciality of the vector.
37  *
38  * Revision 1.3  1997/12/17 16:41:33  denys
39  * ..
40  *
41  * Revision 1.2  1997/09/23  09:43:38  denys
42  * *** empty log message ***
43  *
44  * Revision 1.2  1997/09/23  09:43:38  denys
45  * *** empty log message ***
46  *
47  */
48 
49 #ident "$Id: vel_vect.c,v 1.1 2002/04/26 09:51:07 ludo Exp $"
50 
51 
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <string.h>
55 #include <mut.h>
56 #include <mlo.h>
57 #include <mlu.h>
58 
59 extern void sortlosigv();
60 
61 static char buffer[BUFSIZ];
62 
63 #define Signame(sig) ((sig)->NAMECHAIN->DATA)
64 #define Delvectorname(s) (s)->NAMECHAIN=delchain((s)->NAMECHAIN,(s)->NAMECHAIN)
65 
66 
67 /* ###--------------------------------------------------------------------### */
68 /* #   Function addvectorname                                               # */
69 /* ###--------------------------------------------------------------------### */
70 
addvectorname(losig_list * s)71 static void addvectorname(losig_list *s)
72 {
73 char *sn, *en, *name;
74    while (s) {
75       name=getsigname(s);
76       if ((sn=strrchr(name, '_'))) {
77          strtol(sn+1, &en, 10);
78          if (*en=='\0') {
79             strcpy(buffer, name);
80             buffer[sn-name]=' ';
81             name=namealloc(buffer);
82          }
83       }
84       s->NAMECHAIN=addchain(s->NAMECHAIN, name);
85       s=s->NEXT;
86    }
87 }
88 
89 /* ###--------------------------------------------------------------------### */
90 /* #   Function delvectnames                                                # */
91 /* ###--------------------------------------------------------------------### */
92 
delvectnames(chain_list * ch)93 static void delvectnames(chain_list *ch)
94 {
95    losig_list *s;
96 
97    while (ch) {
98       s=(losig_list *)ch->DATA;
99       s->NAMECHAIN=delchain(s->NAMECHAIN, s->NAMECHAIN);
100       ch=ch->NEXT;
101    }
102    freechain(ch);
103 }
104 
105 /* ###--------------------------------------------------------------------### */
106 /* #   Function vectorelm                                                   # */
107 /* ###--------------------------------------------------------------------### */
108 
vectorelm(char * name,long * idx)109 static char *vectorelm(char *name, long *idx)
110 {
111    char *sn;
112    if ((sn=strchr(name, ' '))) {
113       *idx=atoi(sn+1);
114       strncpy(buffer, name, sn-name);
115       buffer[sn-name]='\0';
116       return namealloc(buffer);
117    }
118    *idx=-2;
119    return name;
120 }
121 
122 
123 /* ###--------------------------------------------------------------------### */
124 /* #   Function chkvectors                                                  # */
125 /* ###--------------------------------------------------------------------### */
126 
chkvectors(losig_list * s)127 static void chkvectors(losig_list *s)
128 {
129    chain_list *vchain=NULL;
130    char *cur_name=NULL, *new_name;
131    long cur_index, new_index;
132 
133    while(s) {
134       new_name=vectorelm(Signame(s), &new_index);
135       if (s->TYPE=='E') {
136          if (new_name==cur_name)            /* the vector has the same name */
137             delvectnames(vchain);           /* than an external signal      */
138          else {
139             if (vchain && vchain->NEXT)
140                freechain(vchain);
141             else
142                delvectnames(vchain);
143             cur_name=new_name;
144          }
145          Delvectorname(s);
146          vchain=NULL;
147       } else
148          if (!vchain)
149             if (new_name==cur_name)
150                Delvectorname(s);
151             else {
152                cur_name=new_name;
153                cur_index=new_index;
154                vchain=addchain(NULL, s);
155             }
156          else {
157             if (new_name==cur_name) {
158                if (new_index-cur_index!=1) { /* the name are the same but    */
159                   delvectnames(vchain);      /* the index aren't consecutive */
160                   vchain=NULL;
161                   Delvectorname(s);
162                } else {                      /* good vector element          */
163                   cur_index=new_index;
164                   vchain=addchain(vchain, s);
165                }
166             } else {                         /* next vector name, if the     */
167                if (vchain && vchain->NEXT)   /* previous is valid and the    */
168                   freechain(vchain);         /* vector have more than one    */
169                else                          /* element, a vector is found.  */
170                   delvectnames(vchain);
171                cur_name=new_name;
172                cur_index=new_index;
173                vchain=addchain(NULL, s);
174             }
175          }
176       s=s->NEXT;
177    }
178    if (vchain && vchain->NEXT)
179       freechain(vchain);
180    else
181       delvectnames(vchain);
182 }
183 
184 /* ###--------------------------------------------------------------------### */
185 /* #   Function vectlosig                                                   # */
186 /* ###--------------------------------------------------------------------### */
187 
vectlosig(losig_list ** s)188 void vectlosig(losig_list **s)
189 {
190    addvectorname(*s);
191    sortlosigv(s);
192    chkvectors(*s);
193 }
194 
195 
196