-
Notifications
You must be signed in to change notification settings - Fork 0
/
vars_first.c
55 lines (44 loc) · 1.26 KB
/
vars_first.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "vars_first.h"
int vars_first(FILE* src, FILE* dest, int nvars, unsigned short* bits)
{
rewind(src);
int i = 0;
int j = 0;
//work array
char* line = malloc(LINE_SIZE);
//get third line of source file to array
fgets(line, LINE_SIZE, src);
fgets(line, LINE_SIZE, src);
fgets(line, LINE_SIZE, src);
//check if first value is multi-bit
if(*(bits+j) > 1)
fprintf(dest, "b");
for(i = 0; *(line+i); i++)
{
if(*(line+i) == '\t')
{
//if device is multibit, add space before ident
//GTKwave does not read input properly without it
if(*(bits+j) > 1)
fprintf(dest, " ");
//print device identification mark
fprintf(dest, "%c", '!' + j);
//avoid unnecesary LF
if(*(line+i+1) != '\n')
fprintf(dest, "\n");
//increment device number
j++;
//if device is multi-bit, add 'b' before state values
if(*(bits+j) > 1)
fprintf(dest, "b");
}
else
{
//prints next char value from string
fprintf(dest, "%c", *(line+i));
}
}
fprintf(dest, "$end\n");
free(line);
return 0;
}