Subversion Repositories Vertical

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 11
Line 20... Line 20...
20
 *
20
 *
21
 * Revision 1.4  2001/10/31 22:20:08  mjames
21
 * Revision 1.4  2001/10/31 22:20:08  mjames
22
 * Tidying up problematical comments caused by CVS
22
 * Tidying up problematical comments caused by CVS
23
 * 'intelligent' comment guessing
23
 * 'intelligent' comment guessing
24
 *
24
 *
25
 *
25
 *
26
 */
26
 */
27
#include "lx_support.h"
27
#include <stdio.h>
-
 
28
#include <string.h>
-
 
29
#include <stdlib.h>
28
 
30
 
29
#include "acf_yacc.h"
-
 
30
#include "cmdexec.h"
-
 
31
#include "cmdlog.h"
-
 
32
#include "cmdparse.h"
-
 
33
#include "cmdutil.h"
-
 
34
#include "database.h"
-
 
35
#include "expression.h"
31
#include "expression.h"
36
#include "generic.h"
32
#include "generic.h"
-
 
33
#include "database.h"
-
 
34
 
-
 
35
 
37
#include "vertcl_main.h"
36
#include "vertcl_main.h"
-
 
37
#include "lx_support.h"
-
 
38
 
-
 
39
 
-
 
40
 
-
 
41
#include "cmdparse.h"
-
 
42
#include "cmdlog.h"
-
 
43
#include "cmdutil.h"
-
 
44
#include "cmdexec.h"
-
 
45
 
-
 
46
#include "acf_yacc.h"
38
 
47
 
39
#include <stdio.h>
-
 
40
#include <stdlib.h>
-
 
41
#include <string.h>
-
 
42
 
48
 
43
/* purpose to queue lex tokens until all have been used on a line or in a statement */
49
/* purpose to queue lex tokens until all have been used on a line or in a statement */
44
 
50
 
45
int yyval; /* propose to confuse LEX ... */
51
int yyval; /* propose to confuse LEX ... */
46
int yy_nArgs;
52
int     yy_nArgs;
47
char **yy_Args;
53
char ** yy_Args;
48
 
54
 
49
#ident                                                                                        \
-
 
50
    "@(#)$Header: c:\\cygwin\\cvsroot/Vert03/vertlib/lx_support.c,v 1.1.1.1 2003/11/04 23:34:57 mjames Exp $"
55
#ident "@(#)$Header: c:\\cygwin\\cvsroot/Vert03/vertlib/lx_support.c,v 1.1.1.1 2003/11/04 23:34:57 mjames Exp $"
51
 
56
 
52
__declspec(dllexport) struct str *lx_first = NULL;
57
__declspec (dllexport)struct str  * lx_first = NULL;
53
__declspec(dllexport) struct str *lx_last = NULL;
58
__declspec (dllexport)struct str  * lx_last  = NULL;
54
 
59
 
55
/* the Args values are for the current argc/argv context */
-
 
56
void expand_string (char *source, char *dest, int nArgs, char *Args[])
-
 
57
{
-
 
58
        char num_buff[LINELEN];
-
 
59
 
60
 
60
        char *Ptr = source;
-
 
61
        char *Optr = dest;
-
 
62
        generic_info_t **chip_generics = NULL;
-
 
63
 
-
 
64
        /*   printf("IN ='%s'\n",source);  */
-
 
65
 
-
 
66
        if (!source || !dest)
-
 
67
                return;
-
 
68
 
-
 
69
        dest[0] = 0;
-
 
70
        while (*Ptr && (Optr - dest) < LINELEN - 1)
-
 
71
        {
-
 
72
                if (*Ptr == '\\')
-
 
73
                {
-
 
74
                        Ptr++;
-
 
75
                        if (*Ptr)
-
 
76
                        {
-
 
77
                                *Optr++ = *Ptr++;
-
 
78
                                *Optr = 0;
-
 
79
                        };
-
 
80
                        continue;
-
 
81
                };
-
 
82
 
-
 
83
                if (*Ptr == '$')
-
 
84
                { /* variable expansion */
-
 
85
 
-
 
86
                        /* pattern 1 : $n - lookup argv[n] */
-
 
87
                        if (Ptr[1] >= '0' && Ptr[1] <= '9')
-
 
88
                        {
-
 
89
                                int n = Ptr[1] - '0';
-
 
90
                                if (n < nArgs)
-
 
91
                                {
-
 
92
                                        /* space to place new word ? */
-
 
93
                                        if ((Optr + strlen (Args[n]) - dest) < LINELEN)
-
 
94
                                        {
-
 
95
                                                strcpy (Optr, Args[n]);
-
 
96
                                                Optr += strlen (Args[n]);
-
 
97
                                                *Optr = 0;
-
 
98
                                        };
-
 
99
 
-
 
100
                                        Ptr += 2;
-
 
101
                                        continue;
-
 
102
                                }
-
 
103
                        }
-
 
104
                        /* pattern 2 : look up a generic SYSVAR */
-
 
105
                        else if (Ptr[1] == '(')
-
 
106
                        {
-
 
107
                                char var_name[WORDWIDTH], *env_val;
-
 
108
                                int c = 0;
-
 
109
                                generic_info_t generic[1];
-
 
110
                                generic_type_t gen_type;
-
 
111
                                Ptr += 2; /* skip '$(' */
-
 
112
                                var_name[0] = '\0';
-
 
113
                                while (*Ptr && *Ptr != ')')
-
 
114
                                {
-
 
115
                                        if (c < WORDWIDTH - 1)
-
 
116
                                        {
-
 
117
                                                var_name[c++] = *Ptr;
-
 
118
                                                var_name[c] = '\0';
-
 
119
                                        }
-
 
120
                                        Ptr++;
-
 
121
                                }
-
 
122
                                if (*Ptr)
-
 
123
                                        Ptr++;
-
 
124
                                /* now lookup result */
-
 
125
 
-
 
126
                                env_val = NULL;
-
 
127
                                /* try generic lookup first */
-
 
128
 
-
 
129
                                gen_type =
-
 
130
                                    get_generic_value (&global_generics, var_name, generic);
-
 
131
                                if (!gen_type)
-
 
132
                                        gen_type = get_generic_value (
-
 
133
                                            &partition_generics, var_name, generic);
-
 
134
                                /* accept a string */
-
 
135
                                if (gen_type == IS_STRING || gen_type == IS_ENV_VAL)
-
 
136
                                {
-
 
137
                                        if (generic->expr)
-
 
138
                                                env_val = generic->expr->left.s;
-
 
139
                                };
-
 
140
                                if (gen_type == IS_INTEGER)
-
 
141
                                {
-
 
142
                                        if (generic->expr)
-
 
143
                                        {
-
 
144
                                                sprintf (
-
 
145
                                                    num_buff,
-
 
146
                                                    "%d",
-
 
147
                                                    eval_expression (
-
 
148
                                                        generic->expr, chip_generics));
-
 
149
                                                env_val = num_buff;
-
 
150
                                        }
-
 
151
                                }
-
 
152
                                if (gen_type == TO)
-
 
153
                                {
-
 
154
                                        if (generic->expr)
-
 
155
                                        {
-
 
156
                                                sprintf (
-
 
157
                                                    num_buff,
-
 
158
                                                    "%d TO %d",
-
 
159
                                                    eval_expression (
-
 
160
                                                        generic->expr->left.e, chip_generics),
-
 
161
                                                    eval_expression (
-
 
162
                                                        generic->expr->right.e,
-
 
163
                                                        chip_generics));
-
 
164
                                                env_val = num_buff;
-
 
165
                                        }
-
 
166
                                }
-
 
167
                                if (gen_type == DOWNTO)
-
 
168
                                {
-
 
169
                                        if (generic->expr)
-
 
170
                                        {
-
 
171
                                                sprintf (
-
 
172
                                                    num_buff,
-
 
173
                                                    "%d DOWNTO %d",
-
 
174
                                                    eval_expression (
-
 
175
                                                        generic->expr->left.e, chip_generics),
-
 
176
                                                    eval_expression (
-
 
177
                                                        generic->expr->right.e,
-
 
178
                                                        chip_generics));
-
 
179
                                                env_val = num_buff;
-
 
180
                                        }
-
 
181
                                }
-
 
182
 
-
 
183
                                /* try OS environment variables */
-
 
184
                                if (!env_val)
-
 
185
                                        env_val = getenv (var_name);
-
 
186
                                if (env_val && (Optr + strlen (env_val) - dest) < LINELEN)
-
 
187
                                {
-
 
188
                                        strcpy (Optr, env_val);
-
 
189
                                        Optr += strlen (env_val);
-
 
190
                                        *Optr = 0;
-
 
191
                                        continue;
-
 
192
                                };
-
 
193
                                if ((Optr + strlen (var_name) - dest) < LINELEN)
-
 
194
                                {
-
 
195
                                        sprintf (Optr, "$(%s)", var_name);
-
 
196
                                        Optr += strlen (var_name) + 3;
-
 
197
                                        *Optr = 0;
-
 
198
                                }
-
 
199
                        }
-
 
200
                }
-
 
201
                if (*Ptr != '\r' && *Ptr != '\n')
-
 
202
                {
-
 
203
                        *Optr++ = *Ptr;
-
 
204
                        *Optr = 0;
-
 
205
                }
-
 
206
                Ptr++;
-
 
207
        }
-
 
208
        /*  printf("OUT='%s'\n",dest);  */
-
 
209
}
-
 
210
 
61
 
211
char *make_string (char *token, struct str **pfirst, struct str **plast)
-
 
212
{
-
 
213
        char *t;
-
 
214
        struct str *s;
-
 
215
        int l;
-
 
216
        char workbuff[LINELEN];
-
 
217
        /* perform checks in the right order 18-02-2000 */
-
 
218
        if (!token)
-
 
219
                return NULL;
-
 
220
        l = strlen (token);
-
 
221
        s = calloc (1, sizeof (struct str));
-
 
222
        if (!s)
-
 
223
                return NULL;
-
 
224
 
-
 
225
        /* eliminate quotes from the string :
-
 
226
         * !! ASSUMES string is in Read/Write memory  */
-
 
227
        if (l >= 2 && token[0] == '\"' && token[l - 1] == '\"')
-
 
228
        {
-
 
229
                strncpy (token, token + 1, l - 2); /* chuck quotes off string */
-
 
230
                token[l - 2] = '\0';               /* null terminate */
-
 
231
        }
-
 
232
 
-
 
233
        /* the values yy_nArgs and yy_Args were filled
-
 
234
           in just before calling yyparse */
-
 
235
        expand_string (token, workbuff, yy_nArgs, yy_Args);
-
 
236
        l = strlen (workbuff);
-
 
237
 
-
 
238
        t = malloc (l + 1);
-
 
239
        if (!t)
-
 
240
                return NULL;
-
 
241
 
-
 
242
        strcpy (t, workbuff); /* copy string , join to structure */
-
 
243
        s->dat = t;
-
 
244
        s->next = NULL;
-
 
245
 
-
 
246
        if (!*pfirst)
-
 
247
                *pfirst = s;
-
 
248
 
62
 
249
        if (*plast)
63
/* the Args values are for the current argc/argv context */
-
 
64
void expand_string( char * source , char * dest, int nArgs, char * Args[]) {
250
                (*plast)->next = s;
65
   char num_buff[LINELEN];
251
 
66
 
-
 
67
   char * Ptr = source;
-
 
68
   char * Optr= dest;
-
 
69
   generic_info_t ** chip_generics = NULL;
-
 
70
   
-
 
71
/*   printf("IN ='%s'\n",source);  */
-
 
72
   
-
 
73
   if(!source || !dest)
-
 
74
     return;
-
 
75
 
-
 
76
 
-
 
77
   dest[0] = 0;
-
 
78
   while(*Ptr && (Optr-dest)<LINELEN-1) {
-
 
79
           
-
 
80
     if(*Ptr=='\\') {
-
 
81
       Ptr++;
-
 
82
       if (*Ptr) {
-
 
83
         *Optr++ = *Ptr++;
-
 
84
         *Optr = 0;
-
 
85
         };
-
 
86
       continue;
-
 
87
       };
-
 
88
 
-
 
89
     if(*Ptr=='$') { /* variable expansion */
-
 
90
           
-
 
91
       /* pattern 1 : $n - lookup argv[n] */
-
 
92
       if(Ptr[1] >='0' && Ptr[1] <='9') {
-
 
93
         int n = Ptr[1]-'0';
-
 
94
         if (n < nArgs ) {
-
 
95
   
-
 
96
           /* space to place new word ? */
-
 
97
           if((Optr+strlen(Args[n])-dest)<LINELEN ) {
-
 
98
             strcpy(Optr, Args[n]);
-
 
99
             Optr+= strlen(Args[n]);
-
 
100
             *Optr = 0;
-
 
101
             };
-
 
102
   
-
 
103
           Ptr+=2;
-
 
104
           continue;
-
 
105
           }
-
 
106
         }
-
 
107
        /* pattern 2 : look up a generic SYSVAR */
-
 
108
       else if (Ptr[1]=='(') {
-
 
109
         char var_name[WORDWIDTH], * env_val;
-
 
110
          int c = 0;
-
 
111
          generic_info_t generic[1];
-
 
112
          generic_type_t gen_type;
-
 
113
          Ptr+=2; /* skip '$(' */
-
 
114
          var_name[0] = '\0';
-
 
115
          while(*Ptr && *Ptr != ')') {
-
 
116
            if(c<WORDWIDTH-1) {
-
 
117
              var_name[c++] = *Ptr;
-
 
118
              var_name[c]   = '\0';
-
 
119
              }
-
 
120
            Ptr++;
-
 
121
            }
-
 
122
          if(*Ptr) Ptr++;
-
 
123
          /* now lookup result */
-
 
124
         
-
 
125
          env_val = NULL;
-
 
126
          /* try generic lookup first */
-
 
127
 
-
 
128
          gen_type = get_generic_value(&global_generics,var_name,generic);
-
 
129
          if(!gen_type)
-
 
130
            gen_type = get_generic_value(&partition_generics,var_name,generic);
-
 
131
          /* accept a string */
-
 
132
          if (gen_type==IS_STRING || gen_type == IS_ENV_VAL) {
-
 
133
             if(generic->expr)
-
 
134
               env_val = generic->expr->left.s;
-
 
135
             };
-
 
136
          if (gen_type==IS_INTEGER)
-
 
137
             {
-
 
138
             if(generic->expr)
-
 
139
               {
-
 
140
               sprintf(num_buff,"%d",eval_expression(generic->expr,chip_generics));
-
 
141
               env_val = num_buff;
-
 
142
               }
-
 
143
             }  
-
 
144
          if (gen_type==TO)
-
 
145
             {
-
 
146
             if(generic->expr)
-
 
147
               {
-
 
148
               sprintf(num_buff,"%d TO %d",eval_expression(generic->expr->left.e,chip_generics),eval_expression(generic->expr->right.e,chip_generics));
-
 
149
               env_val = num_buff;
-
 
150
               }
-
 
151
             }  
-
 
152
          if (gen_type==DOWNTO)
-
 
153
             {
-
 
154
             if(generic->expr)
-
 
155
               {
-
 
156
               sprintf(num_buff,"%d DOWNTO %d",eval_expression(generic->expr->left.e,chip_generics),eval_expression(generic->expr->right.e,chip_generics));
-
 
157
               env_val = num_buff;
-
 
158
               }
-
 
159
             }  
-
 
160
 
-
 
161
 
-
 
162
           /* try OS environment variables */
-
 
163
          if (!env_val)
-
 
164
             env_val = getenv(var_name);
-
 
165
          if (env_val && (Optr+strlen(env_val)-dest)<LINELEN ) {
-
 
166
             strcpy(Optr,env_val );
-
 
167
             Optr+= strlen(env_val);
-
 
168
             *Optr = 0;
-
 
169
             continue;
-
 
170
            };
-
 
171
          if ((Optr+strlen(var_name)-dest)<LINELEN ) {
-
 
172
            sprintf(Optr,"$(%s)",var_name);
-
 
173
            Optr+= strlen(var_name)+3;
-
 
174
            *Optr = 0;
-
 
175
            }
-
 
176
                         
-
 
177
         }
-
 
178
       }
-
 
179
     if(*Ptr != '\r' && *Ptr != '\n')
-
 
180
       {
-
 
181
       *Optr++ = *Ptr;
-
 
182
       *Optr = 0;
-
 
183
       }
-
 
184
     Ptr++;
-
 
185
     }
-
 
186
 /*  printf("OUT='%s'\n",dest);  */
-
 
187
 }
-
 
188
 
-
 
189
char * make_string(char * token ,struct str ** pfirst,struct str ** plast )
-
 
190
  {
-
 
191
  char       * t;
-
 
192
  struct str * s;
-
 
193
  int l;
-
 
194
  char workbuff[LINELEN];
-
 
195
  /* perform checks in the right order 18-02-2000 */
-
 
196
  if(!token)
-
 
197
    return NULL;
-
 
198
  l = strlen(token);
-
 
199
  s = calloc(1,sizeof(struct str ));
-
 
200
  if (!s)
-
 
201
    return NULL;
-
 
202
 
-
 
203
  /* eliminate quotes from the string :
-
 
204
   * !! ASSUMES string is in Read/Write memory  */
-
 
205
  if (l>=2 && token[0]=='\"' && token[l-1]=='\"')
-
 
206
    {
-
 
207
    strncpy (token,token+1,l-2); /* chuck quotes off string */
-
 
208
    token[l-2] = '\0';           /* null terminate */
-
 
209
    }
-
 
210
   
-
 
211
 
-
 
212
  /* the values yy_nArgs and yy_Args were filled
-
 
213
     in just before calling yyparse */
-
 
214
  expand_string(token,workbuff,yy_nArgs,yy_Args);
-
 
215
  l = strlen(workbuff);
-
 
216
   
-
 
217
  t = malloc(l+1);
-
 
218
  if (!t)
-
 
219
    return NULL;
-
 
220
 
-
 
221
  strcpy(t,workbuff);       /* copy string , join to structure */
-
 
222
  s->dat = t;
-
 
223
  s->next = NULL;
-
 
224
 
-
 
225
 
-
 
226
 
-
 
227
 
-
 
228
  if (!*pfirst)
-
 
229
    *pfirst = s;
-
 
230
 
-
 
231
  if(*plast)
-
 
232
    (*plast)->next = s;
-
 
233
 
252
        *plast = s;
234
  *plast = s;
253
        /*  printf("MADE\n"); */
235
/*  printf("MADE\n"); */
-
 
236
 
-
 
237
 
-
 
238
  return (t);  /* pointer to the string that can be later tidily freed */
-
 
239
 
-
 
240
 
-
 
241
 
-
 
242
  }
-
 
243
 
-
 
244
 
-
 
245
void free_strings( struct str ** pfirst, struct str ** plast)
-
 
246
  {
-
 
247
  struct str * s,* t;
-
 
248
  s = *pfirst;
-
 
249
  while(s)       /* run down the list, freeing entries */
-
 
250
    {
-
 
251
    if (s->dat)
-
 
252
      free(s->dat);
-
 
253
    t = s;
-
 
254
    s= s->next;
-
 
255
    free(t);
-
 
256
    }
-
 
257
  *pfirst = NULL;
-
 
258
  *plast = NULL;
254
 
259
 
255
        return (t); /* pointer to the string that can be later tidily freed */
-
 
256
}
260
  }
257
 
261
 
258
void free_strings (struct str **pfirst, struct str **plast)
-
 
259
{
-
 
260
        struct str *s, *t;
-
 
261
        s = *pfirst;
-
 
262
        while (s) /* run down the list, freeing entries */
-
 
263
        {
-
 
264
                if (s->dat)
-
 
265
                        free (s->dat);
-
 
266
                t = s;
-
 
267
                s = s->next;
-
 
268
                free (t);
-
 
269
        }
-
 
270
        *pfirst = NULL;
-
 
271
        *plast = NULL;
-
 
272
}
-
 
273
 
262
 
274
/* called from YACC to deallocate memory structures cleanly */
263
/* called from YACC to deallocate memory structures cleanly */
275
void free_lex_strings (void)
264
void free_lex_strings(void) {
276
{
-
 
277
        free_strings (&lx_first, &lx_last);
265
  free_strings(&lx_first,&lx_last);
278
};
266
  };
279
 
267
 
280
#define to_lower(c) ((c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c)
268
#define to_lower(c) ((c>='A' && c<='Z') ? c-'A'+'a':c)
281
 
269
 
-
 
270
 
282
int streq (char *s1, char *s2)
271
int streq(char    *s1,char    *s2)
283
{
272
{
284
        while (*s1 != '\0')
273
    while (*s1 != '\0') {
285
        {
-
 
286
                if (to_lower (*s2) != to_lower (*s1))
274
        if (to_lower(*s2) != to_lower(*s1))
287
                        return (0);
275
            return( 0 );
288
                s1++;
276
        s1++;
289
                s2++;
277
        s2++;
290
        }
278
    }
291
        return (*s2 == '\0');
279
    return( *s2 == '\0' );
292
}
280
}
293
 
281
 
-
 
282
 
294
int strneq (char *s1, char *s2, int n)
283
int strneq(char    *s1,char    *s2,int n)
295
{
284
{
296
        while (n && *s1 != '\0')
285
    while (n && *s1 != '\0' ) {
297
        {
-
 
298
                if (to_lower (*s2) != to_lower (*s1))
286
        if (to_lower(*s2) != to_lower(*s1))
299
                        return (0);
287
            return( 0 );
300
                s1++;
288
        s1++;
301
                s2++;
289
        s2++;
302
                --n;
290
        --n;
303
        }
291
    }
304
        return (n == 0 || *s2 == '\0');
292
    return( n==0 || *s2 == '\0' );
305
}
293
}