OpenCores
URL https://opencores.org/ocsvn/jtag_stapl_player/jtag_stapl_player/trunk

Subversion Repositories jtag_stapl_player

[/] [jtag_stapl_player/] [trunk/] [jamnote.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sukhanov
/****************************************************************************/
2
/*                                                                                                                                                      */
3
/*      Module:                 jamnote.c                                                                                               */
4
/*                                                                                                                                                      */
5
/*                                      Copyright (C) Altera Corporation 1997                                   */
6
/*                                                                                                                                                      */
7
/*      Description:    Functions to extract NOTE fields from an JAM program    */
8
/*                                                                                                                                                      */
9
/****************************************************************************/
10
 
11
/****************************************************************************/
12
/*                                                                                                                                                      */
13
/*      Actel version 1.1             May 2003                                                                  */
14
/*                                                                                                                                                      */
15
/****************************************************************************/
16
 
17
#include "jamexprt.h"
18
#include "jamdefs.h"
19
#include "jamexec.h"
20
#include "jamutil.h"
21
 
22
/****************************************************************************/
23
/*                                                                                                                                                      */
24
 
25
BOOL jam_get_note_key
26
(
27
        char *statement_buffer,
28
        long *key_begin,
29
        long *key_end
30
)
31
 
32
/*                                                                                                                                                      */
33
/*      Description:    This function finds the note key name in the statement  */
34
/*                                      buffer and returns the start and end offsets                    */
35
/*                                                                                                                                                      */
36
/*      Returns:                TRUE for success, FALSE if key not found                                */
37
/*                                                                                                                                                      */
38
/****************************************************************************/
39
{
40
        int index = 0;
41
        BOOL quoted_string = FALSE;
42
 
43
        index = jam_skip_instruction_name(statement_buffer);
44
 
45
        /*
46
        *       Check if key string has quotes
47
        */
48
        if ((statement_buffer[index] == JAMC_QUOTE_CHAR) &&
49
                (index < JAMC_MAX_STATEMENT_LENGTH))
50
        {
51
                quoted_string = TRUE;
52
                ++index;
53
        }
54
 
55
        /*
56
        *       Mark the beginning of the key string
57
        */
58
        *key_begin = index;
59
 
60
        /*
61
        *       Now find the end of the key string
62
        */
63
        if (quoted_string)
64
        {
65
                /* look for matching quote */
66
                while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
67
                        (statement_buffer[index] != JAMC_QUOTE_CHAR) &&
68
                        (index < JAMC_MAX_STATEMENT_LENGTH))
69
                {
70
                        ++index;
71
                }
72
 
73
                if (statement_buffer[index] == JAMC_QUOTE_CHAR)
74
                {
75
                        *key_end = index;
76
                }
77
        }
78
        else
79
        {
80
                /* look for white space */
81
                while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
82
                        (!jam_isspace(statement_buffer[index])) &&
83
                        (index < JAMC_MAX_STATEMENT_LENGTH))
84
                {
85
                        ++index;        /* skip over white space */
86
                }
87
 
88
                if (jam_isspace(statement_buffer[index]))
89
                {
90
                        *key_end = index;
91
                }
92
        }
93
 
94
        return ((*key_end > *key_begin) ? TRUE : FALSE);
95
}
96
 
97
/****************************************************************************/
98
/*                                                                                                                                                      */
99
 
100
BOOL jam_get_note_value
101
(
102
        char *statement_buffer,
103
        long *value_begin,
104
        long *value_end
105
)
106
 
107
/*                                                                                                                                                      */
108
/*      Description:    Finds the value field of a NOTE.  Could be enclosed in  */
109
/*                                      quotation marks, or could not be.  Must be followed by  */
110
/*                                      a semicolon.                                                                                    */
111
/*                                                                                                                                                      */
112
/*      Returns:                TRUE for success, FALSE for failure                                             */
113
/*                                                                                                                                                      */
114
/****************************************************************************/
115
{
116
        int index = 0;
117
        BOOL quoted_string = FALSE;
118
        BOOL status = FALSE;
119
 
120
        /* skip over white space */
121
        while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
122
                (jam_isspace(statement_buffer[index])) &&
123
                (index < JAMC_MAX_STATEMENT_LENGTH))
124
        {
125
                ++index;
126
        }
127
 
128
        /*
129
        *       Check if value string has quotes
130
        */
131
        if ((statement_buffer[index] == JAMC_QUOTE_CHAR) &&
132
                (index < JAMC_MAX_STATEMENT_LENGTH))
133
        {
134
                quoted_string = TRUE;
135
                ++index;
136
        }
137
 
138
        /*
139
        *       Mark the beginning of the value string
140
        */
141
        *value_begin = index;
142
 
143
        /*
144
        *       Now find the end of the value string
145
        */
146
        if (quoted_string)
147
        {
148
                /* look for matching quote */
149
                while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
150
                        (statement_buffer[index] != JAMC_QUOTE_CHAR) &&
151
                        (index < JAMC_MAX_STATEMENT_LENGTH))
152
                {
153
                        ++index;
154
                }
155
 
156
                if (statement_buffer[index] == JAMC_QUOTE_CHAR)
157
                {
158
                        *value_end = index;
159
                        status = TRUE;
160
                        ++index;
161
                }
162
        }
163
        else
164
        {
165
                /* look for white space or semicolon */
166
                while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
167
                        (statement_buffer[index] != JAMC_SEMICOLON_CHAR) &&
168
                        (!jam_isspace(statement_buffer[index])) &&
169
                        (index < JAMC_MAX_STATEMENT_LENGTH))
170
                {
171
                        ++index;        /* skip over non-white space */
172
                }
173
 
174
                if ((statement_buffer[index] == JAMC_SEMICOLON_CHAR) ||
175
                        (jam_isspace(statement_buffer[index])))
176
                {
177
                        *value_end = index;
178
                        status = TRUE;
179
                }
180
        }
181
 
182
        if (status)
183
        {
184
                while ((statement_buffer[index] != JAMC_NULL_CHAR) &&
185
                        (jam_isspace(statement_buffer[index])) &&
186
                        (index < JAMC_MAX_STATEMENT_LENGTH))
187
                {
188
                        ++index;        /* skip over white space */
189
                }
190
 
191
                /*
192
                *       Next character must be semicolon
193
                */
194
                if (statement_buffer[index] != JAMC_SEMICOLON_CHAR)
195
                {
196
                        status = FALSE;
197
                }
198
        }
199
 
200
        return (status);
201
}
202
 
203
/****************************************************************************/
204
/*                                                                                                                                                      */
205
 
206
JAM_RETURN_TYPE jam_get_note
207
(
208
        char *program,
209
        long program_size,
210
        long *offset,
211
        char *key,
212
        char *value,
213
        int length
214
)
215
 
216
/*                                                                                                                                                      */
217
/*      Description:    Gets key and value of NOTE fields in the JAM file.              */
218
/*                                      Can be called in two modes:  if offset pointer is NULL, */
219
/*                                      then the function searches for note fields which match  */
220
/*                                      the key string provided.  If offset is not NULL, then   */
221
/*                                      the function finds the next note field of any key,              */
222
/*                                      starting at the offset specified by the offset pointer. */
223
/*                                                                                                                                                      */
224
/*      Returns:                JAMC_SUCCESS for success, else appropriate error code   */
225
/*                                                                                                                                                      */
226
/****************************************************************************/
227
{
228
        JAM_RETURN_TYPE status = JAMC_SUCCESS;
229
        char statement_buffer[JAMC_MAX_STATEMENT_LENGTH + 1];
230
        char label_buffer[JAMC_MAX_NAME_LENGTH + 1];
231
        JAME_INSTRUCTION instruction = JAM_ILLEGAL_INSTR;
232
        long key_begin = 0L;
233
        long key_end = 0L;
234
        long value_begin = 0L;
235
        long value_end = 0L;
236
        BOOL done = FALSE;
237
        char *tmp_program = jam_program;
238
        long tmp_program_size = jam_program_size;
239
        long tmp_current_file_position = jam_current_file_position;
240
        long tmp_current_statement_position = jam_current_statement_position;
241
        long tmp_next_statement_position = jam_next_statement_position;
242
 
243
        jam_program = program;
244
        jam_program_size = program_size;
245
 
246
        jam_current_statement_position = 0L;
247
        jam_next_statement_position = 0L;
248
 
249
        if (offset == NULL)
250
        {
251
                /*
252
                *       We will search for the first note with a specific key, and
253
                *       return only the value
254
                */
255
                status = jam_seek(0L);
256
                jam_current_file_position = 0L;
257
        }
258
        else
259
        {
260
                /*
261
                *       We will search for the next note, regardless of the key, and
262
                *       return both the value and the key
263
                */
264
                status = jam_seek(*offset);
265
                jam_current_file_position = *offset;
266
        }
267
 
268
        /*
269
        *       Get program statements and look for NOTE statements
270
        */
271
        while ((!done) && (status == JAMC_SUCCESS))
272
        {
273
                status = jam_get_statement(statement_buffer, label_buffer);
274
 
275
                if (status == JAMC_SUCCESS)
276
                {
277
                        instruction = jam_get_instruction(statement_buffer);
278
 
279
                        if (instruction == JAM_NOTE_INSTR)
280
                        {
281
                                if (jam_get_note_key(statement_buffer, &key_begin, &key_end))
282
                                {
283
                                        statement_buffer[key_end] = JAMC_NULL_CHAR;
284
 
285
                                        if ((offset != NULL) || (jam_stricmp(
286
                                                key, &statement_buffer[key_begin]) == 0))
287
                                        {
288
                                                if (jam_get_note_value(&statement_buffer[key_end + 1],
289
                                                        &value_begin, &value_end))
290
                                                {
291
                                                        done = TRUE;
292
                                                        value_begin += (key_end + 1);
293
                                                        value_end += (key_end + 1);
294
                                                        statement_buffer[value_end] = JAMC_NULL_CHAR;
295
 
296
                                                        if (offset != NULL)
297
                                                        {
298
                                                                *offset = jam_current_file_position;
299
                                                        }
300
                                                }
301
                                                else
302
                                                {
303
                                                        status = JAMC_SYNTAX_ERROR;
304
                                                }
305
                                        }
306
                                }
307
                                else
308
                                {
309
                                        status = JAMC_SYNTAX_ERROR;
310
                                }
311
                        }
312
                }
313
        }
314
 
315
        /*
316
        *       Copy the key and value strings into buffers provided
317
        */
318
        if (done && (status == JAMC_SUCCESS))
319
        {
320
                if (offset != NULL)
321
                {
322
                        /* only copy the key string if we were looking for all NOTEs */
323
                        jam_strncpy(
324
                                key, &statement_buffer[key_begin], JAMC_MAX_NAME_LENGTH);
325
                }
326
                jam_strncpy(value, &statement_buffer[value_begin], length);
327
        }
328
 
329
        jam_program = tmp_program;
330
        jam_program_size = tmp_program_size;
331
        jam_current_file_position = tmp_current_file_position;
332
        jam_current_statement_position = tmp_current_statement_position;
333
        jam_next_statement_position = tmp_next_statement_position;
334
 
335
        return (status);
336
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.