-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathargs.c
122 lines (117 loc) · 3.88 KB
/
args.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* args.c - (C) David Riesz 2022
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "rigsync.h"
void usage(int argc, char **argv);
void read_args(int argc, char **argv)
{
int ii;
struct rs_rig *rig = NULL;
for(ii=1 ; ii<argc ; ii++)
{
if(!(strcmp(argv[ii], "-m")))
{
if((++ii)>=argc) { fprintf(stderr, "Argument error.\n"); exit(1); }
rig = add_rig(atoi(argv[ii]));
}
else if(!(strcmp(argv[ii], "-s")))
{
if(rig == NULL)
{
fprintf(stderr, "Rig definition must begin with a \"-m\" argument.\n");
exit(1);
}
if((++ii)>=argc) { fprintf(stderr, "Argument error.\n"); exit(1); }
set_rig_speed(rig, atoi(argv[ii]));
}
else if(!(strcmp(argv[ii], "-r")))
{
if(rig == NULL)
{
fprintf(stderr, "Rig definition must begin with a \"-m\" argument.\n");
exit(1);
}
if((++ii)>=argc) { fprintf(stderr, "Argument error.\n"); exit(1); }
set_rig_port(rig, argv[ii]);
}
else if(!(strcmp(argv[ii], "-n")))
{
if((++ii)>=argc) { fprintf(stderr, "Argument error.\n"); exit(1); }
set_rig_sync_init(atoi(argv[ii])-1);
if(get_rig_sync_init() >= rig_count())
{
fprintf(stderr, "Sync startup argument error.\n");
exit(1);
}
}
#ifdef DEBUG
else if(!(strcmp(argv[ii], "-d")))
{
if((++ii)>=argc) { fprintf(stderr, "Argument error.\n"); exit(1); }
set_debug_level(atoi(argv[ii]));
}
#endif
else if(!(strcmp(argv[ii], "-h")))
{
usage(argc, argv);
}
else { usage(argc, argv); }
}
if(rig_count() < 2)
{
fprintf(stderr, "At least two rigs must be defined.\n");
exit(1);
}
gprintf(1, "rig count = %d\n", rig_count());
}
void usage(int argc, char **argv)
{
fprintf(stderr, "usage:\n");
fprintf(stderr, "\n");
fprintf(stderr, " %s <rig definition> <rig definition> ...\n", argv[0]);
fprintf(stderr, " [-n <rig number>]\n");
#ifdef DEBUG
fprintf(stderr, " [-d <debug level>]\n");
#endif
fprintf(stderr, "\n");
fprintf(stderr, " Keep defined rigs in sync.\n");
fprintf(stderr, " Each <rig definition> entry must start with:\n");
fprintf(stderr, "\n");
fprintf(stderr, " -m <model number>\n");
fprintf(stderr, "\n");
fprintf(stderr, " and be followed optionally by (depending on the rig):\n");
fprintf(stderr, "\n");
fprintf(stderr, " -r <port/connection>\n");
fprintf(stderr, " -s <baud rate>\n");
fprintf(stderr, "\n");
fprintf(stderr, " The \"-n <rig number>\" argument defines which rig in the list\n");
fprintf(stderr, " the others are synched to on startup. The default is the\n");
fprintf(stderr, " first (1).\n");
#ifdef DEBUG
fprintf(stderr, "\n");
fprintf(stderr, " The \"-d <debug level>\" argument will cause various debug\n");
fprintf(stderr, " statements to be printed depending on the debug level.\n");
#endif
fprintf(stderr, "\n");
fprintf(stderr, " %s -h\n", argv[0]);
fprintf(stderr, " Print this help message.\n");
fprintf(stderr, "\n");
exit(1);
}