vsig.c
1.51 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* vsig.c -- Print vertical signals names as comments in tab file
*
*/
#define MAIN
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include "vsig.h"
extern FILE *yyin;
extern int EverynVecs;
#ifdef __linux__
FILE *Vecfp = 0; /* vector output file */
#else
FILE *Vecfp = stderr; /* vector output file */
#endif
#define OPTSTR "uo:n:"
int main(int argc, char **argv) /* Main entry */
{
FILE *txtin = NULL;
char *fname, *outfilename;
int c;
extern char *optarg;
extern int optind, opterr;
/*
* Parser Args
*/
if(argc < 2)
{
printf("Usage: %s [-o outfile] [-n nvecs] infile\n", argv[0]);
return (0);
}
while ((c = getopt(argc, argv, OPTSTR)) != -1)
{
switch(c) {
case 'o':
if((Vecfp = fopen(optarg, "w")) == NULL)
{
perror(optarg);
return (1);
}
outfilename = optarg;
break;
case 'n':
EverynVecs = atoi(optarg);
break;
case 'u':
printf("Usage: %s [-o outfile] [-n nvecs] infile\n", argv[0]);
return (0);
break;
}
}
#ifdef __linux__
if (!Vecfp) Vecfp = stderr;
#endif
if (optind < argc)
{
if ((txtin = fopen(argv[optind], "r")) == NULL)
{
perror(argv[optind]);
return (1);
}
}
yyin = txtin;
/* create signal list and convert vectors */
yyparse();
/*
* cleanup
*/
if (txtin) (void) fclose(txtin);
if (Vecfp) (void) fclose(Vecfp);
exit(0);
}
#undef MAIN